1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2005 Alejandro Escanero Blanco
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class oxchangeAccount extends plugin
22 {
23 /* Definitions */
24 var $plHeadline= "Open-Xchange";
25 var $plDescription= "This does something";
27 /* GW attributes */
28 var $OXAppointmentDays="500";
29 var $OXTaskDays="5";
30 var $OXTimeZone="GMT";
31 var $mailEnabled="OK";
32 var $dnModeValue = "";
34 /* attribute list for save action */
35 var $attributes= array("OXAppointmentDays", "OXTaskDays", "OXTimeZone","mailEnabled");
36 var $objectclasses= array("OXUserObject");
37 var $ReadOnly =false;
38 var $oxconf = array();
39 var $timezones=array(
40 "Africa/Abidjan",
41 "Africa/Accra",
42 "Africa/Addis_Ababa",
43 "Africa/Algiers",
44 "Africa/Asmera",
45 "Africa/Bamako",
46 "Africa/Bangui",
47 "Africa/Banjul",
48 "Africa/Bissau",
49 "Africa/Blantyre",
50 "Africa/Brazzaville",
51 "Africa/Bujumbura",
52 "Africa/Cairo",
53 "Africa/Casablanca",
54 "Africa/Ceuta",
55 "Africa/Conakry",
56 "Africa/Dakar",
57 "Africa/Dar_es_Salaam",
58 "Africa/Djibouti",
59 "Africa/Douala",
60 "Africa/El_Aaiun",
61 "Africa/Freetown",
62 "Africa/Gaborone",
63 "Africa/Harare",
64 "Africa/Johannesburg",
65 "Africa/Kampala",
66 "Africa/Khartoum",
67 "Africa/Kigali",
68 "Africa/Kinshasa",
69 "Africa/Lagos",
70 "Africa/Libreville",
71 "Africa/Lome",
72 "Africa/Luanda",
73 "Africa/Lubumbashi",
74 "Africa/Lusaka",
75 "Africa/Malabo",
76 "Africa/Maputo",
77 "Africa/Maseru",
78 "Africa/Mbabane",
79 "Africa/Mogadishu",
80 "Africa/Monrovia",
81 "Africa/Nairobi",
82 "Africa/Ndjamena",
83 "Africa/Niamey",
84 "Africa/Nouakchott",
85 "Africa/Ouagadougou",
86 "Africa/Porto-Novo",
87 "Africa/Sao_Tome",
88 "Africa/Timbuktu",
89 "Africa/Tripoli",
90 "Africa/Tunis",
91 "Africa/Windhoek",
92 "America/Adak",
93 "America/Anchorage",
94 "America/Anguilla",
95 "America/Antigua",
96 "America/Araguaina",
97 "America/Aruba",
98 "America/Asuncion",
99 "America/Atka",
100 "America/Barbados",
101 "America/Belem",
102 "America/Belize",
103 "America/Boa_Vista",
104 "America/Bogota",
105 "America/Boise",
106 "America/Buenos_Aires",
107 "America/Cambridge_Bay",
108 "America/Cancun",
109 "America/Caracas",
110 "America/Catamarca",
111 "America/Cayenne",
112 "America/Cayman",
113 "America/Chicago",
114 "America/Chihuahua",
115 "America/Cordoba",
116 "America/Costa_Rica",
117 "America/Cuiaba",
118 "America/Curacao",
119 "America/Danmarkshavn",
120 "America/Dawson",
121 "America/Dawson_Creek",
122 "America/Denver",
123 "America/Detroit",
124 "America/Dominica",
125 "America/Edmonton",
126 "America/Eirunepe",
127 "America/El_Salvador",
128 "America/Ensenada",
129 "America/Fortaleza",
130 "America/Fort_Wayne",
131 "America/Glace_Bay",
132 "America/Godthab",
133 "America/Goose_Bay",
134 "America/Grand_Turk",
135 "America/Grenada",
136 "America/Guadeloupe",
137 "America/Guatemala",
138 "America/Guayaquil",
139 "America/Guyana",
140 "America/Halifax",
141 "America/Havana",
142 "America/Hermosillo",
143 "America/Indiana",
144 "America/Indiana/Indianapolis",
145 "America/Indiana/Knox",
146 "America/Indiana/Marengo",
147 "America/Indiana/Vevay",
148 "America/Indianapolis",
149 "America/Inuvik",
150 "America/Iqaluit",
151 "America/Jamaica",
152 "America/Jujuy",
153 "America/Juneau",
154 "America/Kentucky",
155 "America/Kentucky/Louisville",
156 "America/Kentucky/Monticello",
157 "America/Knox_IN",
158 "America/La_Paz",
159 "America/Lima",
160 "America/Los_Angeles",
161 "America/Louisville",
162 "America/Maceio",
163 "America/Managua",
164 "America/Manaus",
165 "America/Martinique",
166 "America/Mazatlan",
167 "America/Mendoza",
168 "America/Menominee",
169 "America/Merida",
170 "America/Mexico_City",
171 "America/Miquelon",
172 "America/Monterrey",
173 "America/Montevideo",
174 "America/Montreal",
175 "America/Montserrat",
176 "America/Nassau",
177 "America/New_York",
178 "America/Nipigon",
179 "America/Nome",
180 "America/Noronha",
181 "America/North_Dakota",
182 "America/North_Dakota/Center",
183 "America/Panama",
184 "America/Pangnirtung",
185 "America/Paramaribo",
186 "America/Phoenix",
187 "America/Port-au-Prince",
188 "America/Porto_Acre",
189 "America/Porto_Velho",
190 "America/Port_of_Spain",
191 "America/Puerto_Rico",
192 "America/Rainy_River",
193 "America/Rankin_Inlet",
194 "America/Recife",
195 "America/Regina",
196 "America/Rio_Branco",
197 "America/Rosario",
198 "America/Santiago",
199 "America/Santo_Domingo",
200 "America/Sao_Paulo",
201 "America/Scoresbysund",
202 "America/Shiprock",
203 "America/St_Johns",
204 "America/St_Kitts",
205 "America/St_Lucia",
206 "America/St_Thomas",
207 "America/St_Vincent",
208 "America/Swift_Current",
209 "America/Tegucigalpa",
210 "America/Thule",
211 "America/Thunder_Bay",
212 "America/Tijuana",
213 "America/Tortola",
214 "America/Vancouver",
215 "America/Virgin",
216 "America/Whitehorse",
217 "America/Winnipeg",
218 "America/Yakutat",
219 "America/Yellowknife",
220 "Antarctica/Casey",
221 "Antarctica/Davis",
222 "Antarctica/DumontDUrville",
223 "Antarctica/Mawson",
224 "Antarctica/McMurdo",
225 "Antarctica/Palmer",
226 "Antarctica/South_Pole",
227 "Antarctica/Syowa",
228 "Antarctica/Vostok",
229 "Arctic/Longyearbyen",
230 "Asia/Aden",
231 "Asia/Almaty",
232 "Asia/Amman",
233 "Asia/Anadyr",
234 "Asia/Aqtau",
235 "Asia/Aqtobe",
236 "Asia/Ashgabat",
237 "Asia/Ashkhabad",
238 "Asia/Baghdad",
239 "Asia/Bahrain",
240 "Asia/Baku",
241 "Asia/Bangkok",
242 "Asia/Beirut",
243 "Asia/Bishkek",
244 "Asia/Brunei",
245 "Asia/Calcutta",
246 "Asia/Choibalsan",
247 "Asia/Chongqing",
248 "Asia/Chungking",
249 "Asia/Colombo",
250 "Asia/Dacca",
251 "Asia/Damascus",
252 "Asia/Dhaka",
253 "Asia/Dili",
254 "Asia/Dubai",
255 "Asia/Dushanbe",
256 "Asia/Gaza",
257 "Asia/Harbin",
258 "Asia/Hong_Kong",
259 "Asia/Hovd",
260 "Asia/Irkutsk",
261 "Asia/Istanbul",
262 "Asia/Jakarta",
263 "Asia/Jayapura",
264 "Asia/Jerusalem",
265 "Asia/Kabul",
266 "Asia/Kamchatka",
267 "Asia/Karachi",
268 "Asia/Kashgar",
269 "Asia/Katmandu",
270 "Asia/Krasnoyarsk",
271 "Asia/Kuala_Lumpur",
272 "Asia/Kuching",
273 "Asia/Kuwait",
274 "Asia/Macao",
275 "Asia/Macau",
276 "Asia/Magadan",
277 "Asia/Manila",
278 "Asia/Muscat",
279 "Asia/Nicosia",
280 "Asia/Novosibirsk",
281 "Asia/Omsk",
282 "Asia/Oral",
283 "Asia/Phnom_Penh",
284 "Asia/Pontianak",
285 "Asia/Pyongyang",
286 "Asia/Qatar",
287 "Asia/Qyzylorda",
288 "Asia/Rangoon",
289 "Asia/Riyadh",
290 "Asia/Riyadh87",
291 "Asia/Riyadh88",
292 "Asia/Riyadh89",
293 "Asia/Saigon",
294 "Asia/Sakhalin",
295 "Asia/Samarkand",
296 "Asia/Seoul",
297 "Asia/Shanghai",
298 "Asia/Singapore",
299 "Asia/Taipei",
300 "Asia/Tashkent",
301 "Asia/Tbilisi",
302 "Asia/Tehran",
303 "Asia/Tel_Aviv",
304 "Asia/Thimbu",
305 "Asia/Thimphu",
306 "Asia/Tokyo",
307 "Asia/Ujung_Pandang",
308 "Asia/Ulaanbaatar",
309 "Asia/Ulan_Bator",
310 "Asia/Urumqi",
311 "Asia/Vientiane",
312 "Asia/Vladivostok",
313 "Asia/Yakutsk",
314 "Asia/Yekaterinburg",
315 "Asia/Yerevan",
316 "Atlantic/Azores",
317 "Atlantic/Bermuda",
318 "Atlantic/Canary",
319 "Atlantic/Cape_Verde",
320 "Atlantic/Faeroe",
321 "Atlantic/Jan_Mayen",
322 "Atlantic/Madeira",
323 "Atlantic/Reykjavik",
324 "Atlantic/South_Georgia",
325 "Atlantic/Stanley",
326 "Atlantic/St_Helena",
327 "Australia/ACT",
328 "Australia/Adelaide",
329 "Australia/Brisbane",
330 "Australia/Broken_Hill",
331 "Australia/Canberra",
332 "Australia/Darwin",
333 "Australia/Hobart",
334 "Australia/LHI",
335 "Australia/Lindeman",
336 "Australia/Lord_Howe",
337 "Australia/Melbourne",
338 "Australia/North",
339 "Australia/NSW",
340 "Australia/Perth",
341 "Australia/Queensland",
342 "Australia/South",
343 "Australia/Sydney",
344 "Australia/Tasmania",
345 "Australia/Victoria",
346 "Australia/West",
347 "Australia/Yancowinna",
348 "Brazil/Acre",
349 "Brazil/DeNoronha",
350 "Brazil/East",
351 "Brazil/West",
352 "Canada/Atlantic",
353 "Canada/Central",
354 "Canada/East-Saskatchewan",
355 "Canada/Eastern",
356 "Canada/Mountain",
357 "Canada/Newfoundland",
358 "Canada/Pacific",
359 "Canada/Saskatchewan",
360 "Canada/Yukon",
361 "CET",
362 "Chile/Continental",
363 "Chile/EasterIsland",
364 "CST6CDT",
365 "Cuba",
366 "EET",
367 "Egypt",
368 "Eire",
369 "EST",
370 "EST5EDT",
371 "Etc/GMT",
372 "Etc/GMT+0",
373 "Etc/GMT+1",
374 "Etc/GMT+10",
375 "Etc/GMT+11",
376 "Etc/GMT+12",
377 "Etc/GMT+2",
378 "Etc/GMT+3",
379 "Etc/GMT+4",
380 "Etc/GMT+5",
381 "Etc/GMT+6",
382 "Etc/GMT+7",
383 "Etc/GMT+8",
384 "Etc/GMT+9",
385 "Etc/GMT-0",
386 "Etc/GMT-1",
387 "Etc/GMT-10",
388 "Etc/GMT-11",
389 "Etc/GMT-12",
390 "Etc/GMT-13",
391 "Etc/GMT-14",
392 "Etc/GMT-2",
393 "Etc/GMT-3",
394 "Etc/GMT-4",
395 "Etc/GMT-5",
396 "Etc/GMT-6",
397 "Etc/GMT-7",
398 "Etc/GMT-8",
399 "Etc/GMT-9",
400 "Etc/GMT0",
401 "Etc/Greenwich",
402 "Etc/UCT",
403 "Etc/Universal",
404 "Etc/UTC",
405 "Etc/Zulu",
406 "Europe/Amsterdam",
407 "Europe/Andorra",
408 "Europe/Athens",
409 "Europe/Belfast",
410 "Europe/Belgrade",
411 "Europe/Berlin",
412 "Europe/Bratislava",
413 "Europe/Brussels",
414 "Europe/Bucharest",
415 "Europe/Budapest",
416 "Europe/Chisinau",
417 "Europe/Copenhagen",
418 "Europe/Dublin",
419 "Europe/Gibraltar",
420 "Europe/Helsinki",
421 "Europe/Istanbul",
422 "Europe/Kaliningrad",
423 "Europe/Kiev",
424 "Europe/Lisbon",
425 "Europe/Ljubljana",
426 "Europe/London",
427 "Europe/Luxembourg",
428 "Europe/Madrid",
429 "Europe/Malta",
430 "Europe/Minsk",
431 "Europe/Monaco",
432 "Europe/Moscow",
433 "Europe/Nicosia",
434 "Europe/Oslo",
435 "Europe/Paris",
436 "Europe/Prague",
437 "Europe/Riga",
438 "Europe/Rome",
439 "Europe/Samara",
440 "Europe/San_Marino",
441 "Europe/Sarajevo",
442 "Europe/Simferopol",
443 "Europe/Skopje",
444 "Europe/Sofia",
445 "Europe/Stockholm",
446 "Europe/Tallinn",
447 "Europe/Tirane",
448 "Europe/Tiraspol",
449 "Europe/Uzhgorod",
450 "Europe/Vaduz",
451 "Europe/Vatican",
452 "Europe/Vienna",
453 "Europe/Vilnius",
454 "Europe/Warsaw",
455 "Europe/Zagreb",
456 "Europe/Zaporozhye",
457 "Europe/Zurich",
458 "Factory",
459 "GB",
460 "GB-Eire",
461 "GMT",
462 "GMT+0",
463 "GMT-0",
464 "GMT0",
465 "Greenwich",
466 "Hongkong",
467 "HST",
468 "Iceland",
469 "Indian/Antananarivo",
470 "Indian/Chagos",
471 "Indian/Christmas",
472 "Indian/Cocos",
473 "Indian/Comoro",
474 "Indian/Kerguelen",
475 "Indian/Mahe",
476 "Indian/Maldives",
477 "Indian/Mauritius",
478 "Indian/Mayotte",
479 "Indian/Reunion",
480 "Iran",
481 "Israel",
482 "Jamaica",
483 "Japan",
484 "Kwajalein",
485 "Libya",
486 "MET",
487 "Mexico/BajaNorte",
488 "Mexico/BajaSur",
489 "Mexico/General",
490 "Mideast/Riyadh87",
491 "Mideast/Riyadh88",
492 "Mideast/Riyadh89",
493 "MST",
494 "MST7MDT",
495 "Navajo",
496 "NZ",
497 "NZ-CHAT",
498 "Pacific/Apia",
499 "Pacific/Auckland",
500 "Pacific/Chatham",
501 "Pacific/Easter",
502 "Pacific/Efate",
503 "Pacific/Enderbury",
504 "Pacific/Fakaofo",
505 "Pacific/Fiji",
506 "Pacific/Funafuti",
507 "Pacific/Galapagos",
508 "Pacific/Gambier",
509 "Pacific/Guadalcanal",
510 "Pacific/Guam",
511 "Pacific/Honolulu",
512 "Pacific/Johnston",
513 "Pacific/Kiritimati",
514 "Pacific/Kosrae",
515 "Pacific/Kwajalein",
516 "Pacific/Majuro",
517 "Pacific/Marquesas",
518 "Pacific/Midway",
519 "Pacific/Nauru",
520 "Pacific/Niue",
521 "Pacific/Norfolk",
522 "Pacific/Noumea",
523 "Pacific/Pago_Pago",
524 "Pacific/Palau",
525 "Pacific/Pitcairn",
526 "Pacific/Ponape",
527 "Pacific/Port_Moresby",
528 "Pacific/Rarotonga",
529 "Pacific/Saipan",
530 "Pacific/Samoa",
531 "Pacific/Tahiti",
532 "Pacific/Tarawa",
533 "Pacific/Tongatapu",
534 "Pacific/Truk",
535 "Pacific/Wake",
536 "Pacific/Wallis",
537 "Pacific/Yap",
538 "Poland",
539 "Portugal",
540 "PRC",
541 "PST8PDT",
542 "ROC",
543 "ROK",
544 "Singapore",
545 "SystemV/AST4",
546 "SystemV/AST4ADT",
547 "SystemV/CST6",
548 "SystemV/CST6CDT",
549 "SystemV/EST5",
550 "SystemV/EST5EDT",
551 "SystemV/HST10",
552 "SystemV/MST7",
553 "SystemV/MST7MDT",
554 "SystemV/PST8",
555 "SystemV/PST8PDT",
556 "SystemV/YST9",
557 "SystemV/YST9YDT",
558 "Turkey",
559 "UCT",
560 "Universal",
561 "US/Alaska",
562 "US/Aleutian",
563 "US/Arizona",
564 "US/Central",
565 "US/East-Indiana",
566 "US/Eastern",
567 "US/Hawaii",
568 "US/Indiana-Starke",
569 "US/Michigan",
570 "US/Mountain",
571 "US/Pacific",
572 "US/Samoa",
573 "UTC",
574 "W-SU",
575 "WET",
576 "Zulu"
577 );
579 var $dnmode= "";
581 function oxchangeAccount ($config, $dn= NULL)
582 {
583 plugin::plugin ($config, $dn);
584 for ($i=0;$i<count($this->config->data['TABS']['CONNECTIVITY']);$i++){
585 if($this->config->data['TABS']['CONNECTIVITY'][$i]['CLASS']=='oxchangeAccount') {
586 $this->oxconf=$this->config->data['TABS']['CONNECTIVITY'][$i];
587 break;
588 }
589 }
591 $this->dnmode= $this->config->current['DNMODE'];
592 if(isset($this->attrs[$this->dnmode][0])){
593 $this->dnModeValue = $this->attrs[$this->dnmode][0];
594 }
595 }
597 function execute()
598 {
599 /* Call parent execute */
600 //plugin::execute();
603 $display="";
605 /* Show main page */
606 $smarty= get_smarty();
608 if (function_exists("pg_connect")){
609 $smarty->assign("pg", true);
610 }else{
611 $smarty->assign("pg", false);
612 }
614 /* Load attributes */
615 foreach($this->attributes as $val){
616 $smarty->assign("$val", $this->$val);
617 }
618 if ($this->is_account){
619 $smarty->assign("oxchangeState", "checked");
620 $smarty->assign("oxState", "");
621 } else {
622 $smarty->assign("oxchangeState", "");
623 $smarty->assign("oxState", "disabled");
624 }
626 $tmp = $this->plInfo();
627 foreach($tmp['plProvidedAcls'] as $key => $desc){
628 $smarty->assign($key."ACL",$this->getacl($key,$this->ReadOnly));
629 $smarty->assign($key."_W",$this->acl_is_writeable($key));
630 }
632 if((!$this->ReadOnly) && (($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) ){
633 $smarty->assign('oxchangeAccountACL', "");
634 }else{
635 $smarty->assign('oxchangeAccountACL', " disabled ");
636 }
638 $smarty->assign("timezones", $this->timezones);
641 if ($this->parent != NULL){
642 $smarty->assign("tabbed", 1);
643 }else{
644 $smarty->assign("tabbed", 0);
645 }
647 /* Trying to open a Postgresql Database Server */
648 if (function_exists("pg_connect")){
649 if(isset($this->oxconf["PGUSER"]) and isset($this->oxconf["PGHOST"]) and isset($this->oxconf["PGDBNAME"]) and isset($this->oxconf["PGPASSWD"])){
650 $pgcon = @pg_connect("host=".$this->oxconf["PGHOST"]." user=".$this->oxconf["PGUSER"]." password=".$this->oxconf["PGPASSWD"]." dbname=".$this->oxconf["PGDBNAME"]);
651 if (! $pgcon){
652 $smarty->assign("pg", false);
653 }
654 }else{
655 $smarty->assign("pg", false);
656 }
657 }else{
658 $smarty->assign("pg", false);
659 }
661 $display.= $smarty->fetch (get_template_path('oxchange.tpl', TRUE, dirname(__FILE__)));
662 return ($display);
663 }
665 function remove_from_parent()
666 {
667 if(!$this->acl_is_removeable()) return;
668 $this->attrs[$this->dnmode][0] = $this->dnModeValue;
669 $sqldeluser=array(
670 "delete from prg_notes where (user_right like '".$this->attrs[$this->dnmode][0]."') and (group_right like 's')",
671 "delete from prg_documents_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
672 "delete from prg_documents_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
673 "delete from prg_docufolders_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
674 "delete from prg_docufolders_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
675 "delete from prg_date_rights where (user_right like '".$this->attrs[$this->dnmode][0]."')",
676 "delete from prg_date_notification where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
677 "delete from prg_dates_members where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
678 "delete from prg_knowledge_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
679 "delete from prg_knowledge_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
680 "delete from prg_knowledge_folder_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
681 "delete from prg_knowledge_folder_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
682 "delete from prg_pin_board_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
683 "delete from prg_pin_board_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
684 "delete from prg_bookmarks_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
685 "delete from prg_bookmarks_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
686 "delete from prg_bookmarks_folder_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
687 "delete from prg_bookmarks_folder_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
688 "delete from prg_tasks_rights where (user_right like '".$this->attrs[$this->dnmode][0]."')",
689 "delete from prg_tasks_notification where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
690 "delete from prg_tasks_members where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
691 "delete from prg_projects_rights where (user_right like '".$this->attrs[$this->dnmode][0]."')",
692 "delete from prg_projects_notification where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
693 "delete from prg_projects_members where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
694 "delete from oxfolder_permissions where (entity like '".$this->attrs[$this->dnmode][0]."') AND ((role = 256) OR (role = 1024))",
695 "delete from oxfolder_standardfolders where owner like '".$this->attrs[$this->dnmode][0]."'",
696 "delete from prg_forum_read where user_right = '".$this->attrs[$this->dnmode][0]."'",
697 "delete from prg_forum_mod where user_right = '".$this->attrs[$this->dnmode][0]."'",
698 "delete from prg_forum_abo where user_right = '".$this->attrs[$this->dnmode][0]."'",
699 "delete from prg_forum_seen where username = '".$this->attrs[$this->dnmode][0]."'",
700 "delete from sys_holiday where (userid like '".$this->attrs[$this->dnmode][0]."')",
701 "delete from usr_holiday where (userid like '".$this->attrs[$this->dnmode][0]."')");
703 /* Trying to open a Postgresql Database Server */
704 if (function_exists("pg_connect")){
705 if(isset($this->oxconf["PGUSER"]) and
706 isset($this->oxconf["PGHOST"]) and
707 isset($this->oxconf["PGDBNAME"]) and
708 isset($this->oxconf["PGPASSWD"])){
709 $pgcon = @pg_connect("host=".$this->oxconf["PGHOST"]." user=".$this->oxconf["PGUSER"]." password=".$this->oxconf["PGPASSWD"]." dbname=".$this->oxconf["PGDBNAME"]);
710 if (! $pgcon){
711 print_red(_("Couldn't connect to postgresql database!"));
712 return;
713 }
714 }else{
715 print_red(_("Needed parameters for openexchange connectivity plugin are missing!"));
716 return;
717 }
718 }else{
719 print_red(_("PHP4 module for postgresql database is missing!"));
720 return;
721 }
723 plugin::remove_from_parent();
724 $ldap= $this->config->get_ldap_link();
726 if($ldap->dn_exists("ou=addr,".$this->dn)){
727 $ldap->rmdir_recursive("ou=addr,".$this->dn);
728 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/oxchange addressbook account with dn '%s' failed."),$this->dn));
729 }
731 $ldap->cd($this->dn);
732 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
733 $this->attributes, "Save");
734 $this->cleanup();
735 $ldap->modify ($this->attrs);
736 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/oxchange addressbook account with dn '%s' failed."),$this->dn));
738 /* Optionally execute a command after we're done */
739 $this->postremove();
741 /* Finally remove data from postgresql server */
742 foreach ($sqldeluser as $sqls){
743 @pg_exec($pgcon,$sqls);
744 }
745 pg_close();
746 }
748 /* Save data to object */
749 function save_object()
750 {
751 /* Do we need to flip is_account state? */
752 if (isset($_POST['connectivityTab'])){
753 if (isset($_POST['oxchange'])){
754 if (!$this->is_account && $_POST['oxchange'] == "B") {
755 if($this->acl_is_createable()){
756 $this->is_account= TRUE;
757 }
758 }
759 } else {
760 if($this->acl_is_removeable()){
761 $this->is_account= FALSE;
762 }
763 }
764 }
766 /* Get objects */
767 foreach(array("OXTimeZone","OXTaskDays","OXAppointmentDays") as $name) {
768 if($this->acl_is_writeable($name) && isset($_POST[$name])){
769 $this->$name = $_POST[$name];
770 }
771 }
773 // plugin::save_object();
774 if (isset($_POST["oxchangeStatus"])){
775 $this->oxchangeStatus = "disabled";
776 } else {
777 $this->oxchangeStatus = "enabled";
778 }
779 }
782 /* Save to LDAP */
783 function save()
784 {
786 $needupdate=TRUE;
787 $istemplate=FALSE;
790 /* print "<pre>".print_r($this->attrs, true)."</pre>";*/
793 /*First at all, we must check if this is new or is updated */
794 /*Also check is we have a template, if is a template, is a new user */
795 if (isset($this->attrs['objectClass'])){
796 foreach ($this->attrs['objectClass'] as $object){
797 if($object=="OXUserObject") $needupdate=FALSE;
798 if($object=="gosaUserTemplate") $istemplate=TRUE;
799 }
800 }
802 $uidarray=array();
803 preg_match("/^(\w+(?=\=))=((\w|\s|\.)+(?=\,)),.*/",$this->dn,$uidarray);
804 $uid=$uidarray[2];
805 if (trim($uid) == "") {
806 print_red(_("The Open-Xchange accountname is empty and thus invalid! Check to make sure that ".
807 "you are not using any strange characters in the loginname."));
808 return;
809 }
811 if ($istemplate) $needupdate=TRUE;
813 if($needupdate){
814 /* Trying to open a Postgresql Database Server */
815 if (function_exists("pg_connect")){
816 if(isset($this->oxconf["PGUSER"]) and isset($this->oxconf["PGHOST"]) and isset($this->oxconf["PGDBNAME"]) and isset($this->oxconf["PGPASSWD"])){
817 $pgcon = @pg_connect("host=".$this->oxconf["PGHOST"]." user=".$this->oxconf["PGUSER"]." password=".$this->oxconf["PGPASSWD"]." dbname=".$this->oxconf["PGDBNAME"]);
818 if (! $pgcon){
819 print_red(_("Couldn't connect to postgresql database!"));
820 return;
821 }
822 }else{
823 print_red(_("Needed parameters for openexchange connectivity plugin are missing!"));
824 return;
825 }
826 }else{
827 print_red(_("PHP4 module for postgresql database is missing!"));
828 return;
829 }
830 }
832 plugin::save();
834 /* Write back to ldap */
835 $ldap= $this->config->get_ldap_link();
836 $ldap->cd($this->dn);
837 $this->cleanup();
838 $ldap->modify ($this->attrs);
840 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/oxchange account with dn '%s' failed."),$this->dn));
842 /* Optionally execute a command after we're done */
843 $this->postcreate();
845 if($needupdate){
846 $ldap->create_missing_trees("ou=addr,".$this->dn);
847 show_ldap_error($ldap->get_error(), sprintf(_("Creating of user/oxchange account with dn '%s' failed."),$this->dn));
848 /* Finally save data to postgresql server */
849 pg_set_client_encoding ("UNICODE");
850 $nv = "SELECT nextval ('serial_id')";
851 $ot = "insert into oxfolder_tree (fuid, parent, fname, module, type, owner, creator, creating_date, created_from, changing_date, changed_from) VALUES (%d, 1, '%s', '%s', 'private', '%s', '%s', 'now', 'System', 'now', 'System')";
852 $op = "INSERT INTO oxfolder_permissions (puid, pid, role, entity, sealed, fp, orp, owp, odp) VALUES (%d, %d, 32768, '%s', 0, 128, 128, 128, 128)";
853 $os = "insert into oxfolder_standardfolders (owner,module_calendar,module_contact,module_task) VALUES ('%s',%d,%d,%d)";
854 $ugr= "INSERT INTO usr_general_rights SELECT creating_date, created_from, changing_date, changed_from,text('%s'), addr_u, addr_r, addr_d, cont_u, cont_r, cont_d, data_u, data_r, data_d, serie_u, serie_r, serie_d, task_u, task_r, task_d, refer, proj_u, proj_r, proj_d, dfolder_u, dfolder_r, dfolder_d, doc_u, doc_r, doc_d, knowl_u, knowl_r, knowl_d, bfolder_u, bfolder_r, bfolder_d, bookm_u, bookm_r, bookm_d, pin_u, pin_r, pin_d, forum_n, fentrie_n, setup, pin_public, internal, int_groups, kfolder_u, kfolder_r, kfolder_d, webmail FROM sys_gen_rights_template WHERE login LIKE 'default_template'";
856 $error = FALSE;
857 $res=@pg_exec($pgcon,$nv);
859 if(!$res){
860 $error = TRUE;
861 }else{
862 $calendarid=pg_fetch_row($res);
863 pg_freeresult($res);
865 $q=sprintf($ot,$calendarid[0],'My Appointments','calendar',$uid,$uid);
866 @pg_exec($pgcon,$q);
867 }
869 $res=@pg_exec($pgcon,$nv);
871 if(!$res){
872 $error = TRUE;
873 }else{
874 $nid=pg_fetch_row($res);
875 pg_freeresult($res);
877 $q=sprintf($op,$nid[0],$calendarid[0],$uid);
878 @pg_exec($pgcon,$q);
879 }
881 $res=@pg_exec($pgcon,$nv);
882 if(!$res){
883 $error = TRUE;
884 }else{
885 $contactsid=pg_fetch_row($res);
886 pg_freeresult($res);
888 $q=sprintf($ot,$contactsid[0],'My Contacts','contact',$uid,$uid);
889 @pg_exec($pgcon,$q);
890 }
892 $res=@pg_exec($pgcon,$nv);
893 if(!$res){
894 $error = TRUE;
895 }else{
896 $nid=pg_fetch_row($res);
897 pg_freeresult($res);
899 $q=sprintf($op,$nid[0],$contactsid[0],$uid);
900 @pg_exec($pgcon,$q);
901 }
903 $res=@pg_exec($pgcon,$nv);
904 if(!$res){
905 $error = TRUE;
906 }else{
907 $tasksid=pg_fetch_row($res);
908 pg_freeresult($res);
910 $q=sprintf($ot,$tasksid[0],'My Tasks','task',$uid,$uid);
911 @pg_exec($pgcon,$q);
912 }
914 $res=@pg_exec($pgcon,$nv);
915 if(!$res){
916 $error = TRUE;
917 }else{
918 $nid=pg_fetch_row($res);
919 pg_freeresult($res);
921 $q=sprintf($op,$nid[0],$tasksid[0],$uid);
922 @pg_exec($pgcon,$q);
924 $q=sprintf($os,$uid,$calendarid[0],$contactsid[0],$tasksid[0]);
925 @pg_exec($pgcon,$q);
927 $q=sprintf($ugr,$uid);
928 @pg_exec($pgcon,$q);
929 }
931 @pg_close($pgcon);
933 if($error){
934 print_red(_("Something went wrong while saving oxchange account. Please check the error log file."));
935 }
936 }
937 }
940 /* Return plugin informations for acl handling */
941 function plInfo()
942 {
943 return (array(
944 "plShortName" => _("Open xchange"),
945 "plDescription" => _("Open xchange account settings"),
946 "plSelfModify" => TRUE,
947 "plDepends" => array("user"),
948 "plPriority" => 4, // Position in tabs
949 "plSection" => "personal", // This belongs to personal
950 "plCategory" => array("users"),
951 "plOptions" => array(),
953 "plProvidedAcls" => array(
954 "OXAppointmentDays" => _("OXAppointmentDays"),
955 "OXTaskDays" => _("OXTaskDays"),
956 "OXTimeZone" => _("OXTimeZone"))
957 ));
958 }
959 }
960 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
961 ?>