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= "";
580 var $uid ="";
582 function oxchangeAccount ($config, $dn= NULL)
583 {
584 plugin::plugin ($config, $dn);
585 for ($i=0;$i<count($this->config->data['TABS']['CONNECTIVITY']);$i++){
586 if($this->config->data['TABS']['CONNECTIVITY'][$i]['CLASS']=='oxchangeAccount') {
587 $this->oxconf=$this->config->data['TABS']['CONNECTIVITY'][$i];
588 break;
589 }
590 }
592 /* Setting uid to default */
593 if(isset($this->attrs['uid'][0])){
594 $this->uid = $this->attrs['uid'][0];
595 }
597 $this->dnmode= $this->config->current['DNMODE'];
598 if(isset($this->attrs[$this->dnmode][0])){
599 $this->dnModeValue = $this->attrs[$this->dnmode][0];
600 }
601 }
603 function execute()
604 {
605 /* Call parent execute */
606 //plugin::execute();
609 $display="";
611 /* Show main page */
612 $smarty= get_smarty();
614 if (function_exists("pg_connect")){
615 $smarty->assign("pg", true);
616 }else{
617 $smarty->assign("pg", false);
618 }
620 /* Load attributes */
621 foreach($this->attributes as $val){
622 $smarty->assign("$val", $this->$val);
623 }
624 if ($this->is_account){
625 $smarty->assign("oxchangeState", "checked");
626 $smarty->assign("oxState", "");
627 } else {
628 $smarty->assign("oxchangeState", "");
629 $smarty->assign("oxState", "disabled");
630 }
632 $tmp = $this->plInfo();
633 foreach($tmp['plProvidedAcls'] as $key => $desc){
634 $smarty->assign($key."ACL",$this->getacl($key,$this->ReadOnly));
635 $smarty->assign($key."_W",$this->acl_is_writeable($key));
636 }
638 if((!$this->ReadOnly) && (($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) ){
639 $smarty->assign('oxchangeAccountACL', "");
640 }else{
641 $smarty->assign('oxchangeAccountACL', " disabled ");
642 }
644 $smarty->assign("timezones", $this->timezones);
647 if ($this->parent != NULL){
648 $smarty->assign("tabbed", 1);
649 }else{
650 $smarty->assign("tabbed", 0);
651 }
653 /* Trying to open a Postgresql Database Server */
654 if (function_exists("pg_connect")){
655 if(isset($this->oxconf["PGUSER"]) and isset($this->oxconf["PGHOST"]) and isset($this->oxconf["PGDBNAME"]) and isset($this->oxconf["PGPASSWD"])){
656 $pgcon = @pg_connect("host=".$this->oxconf["PGHOST"]." user=".$this->oxconf["PGUSER"]." password=".$this->oxconf["PGPASSWD"]." dbname=".$this->oxconf["PGDBNAME"]);
657 if (! $pgcon){
658 $smarty->assign("pg", false);
659 }
660 }else{
661 $smarty->assign("pg", false);
662 }
663 }else{
664 $smarty->assign("pg", false);
665 }
667 $display.= $smarty->fetch (get_template_path('oxchange.tpl', TRUE, dirname(__FILE__)));
668 return ($display);
669 }
671 function remove_from_parent()
672 {
673 if(!$this->acl_is_removeable()) return;
674 $this->attrs[$this->dnmode][0] = $this->dnModeValue;
675 $sqldeluser=array(
676 "delete from prg_notes where (user_right like '".$this->attrs[$this->dnmode][0]."') and (group_right like 's')",
677 "delete from prg_documents_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
678 "delete from prg_documents_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
679 "delete from prg_docufolders_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
680 "delete from prg_docufolders_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
681 "delete from prg_date_rights where (user_right like '".$this->attrs[$this->dnmode][0]."')",
682 "delete from prg_date_notification where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
683 "delete from prg_dates_members where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
684 "delete from prg_knowledge_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
685 "delete from prg_knowledge_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
686 "delete from prg_knowledge_folder_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
687 "delete from prg_knowledge_folder_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
688 "delete from prg_pin_board_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
689 "delete from prg_pin_board_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
690 "delete from prg_bookmarks_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
691 "delete from prg_bookmarks_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
692 "delete from prg_bookmarks_folder_read where (user_right like '".$this->attrs[$this->dnmode][0]."')",
693 "delete from prg_bookmarks_folder_mod where (user_right like '".$this->attrs[$this->dnmode][0]."')",
694 "delete from prg_tasks_rights where (user_right like '".$this->attrs[$this->dnmode][0]."')",
695 "delete from prg_tasks_notification where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
696 "delete from prg_tasks_members where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
697 "delete from prg_projects_rights where (user_right like '".$this->attrs[$this->dnmode][0]."')",
698 "delete from prg_projects_notification where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
699 "delete from prg_projects_members where (member_uid like '".$this->attrs[$this->dnmode][0]."')",
700 "delete from oxfolder_permissions where (entity like '".$this->attrs[$this->dnmode][0]."') AND ((role = 256) OR (role = 1024))",
701 "delete from oxfolder_standardfolders where owner like '".$this->attrs[$this->dnmode][0]."'",
702 "delete from prg_forum_read where user_right = '".$this->attrs[$this->dnmode][0]."'",
703 "delete from prg_forum_mod where user_right = '".$this->attrs[$this->dnmode][0]."'",
704 "delete from prg_forum_abo where user_right = '".$this->attrs[$this->dnmode][0]."'",
705 "delete from prg_forum_seen where username = '".$this->attrs[$this->dnmode][0]."'",
706 "delete from sys_holiday where (userid like '".$this->attrs[$this->dnmode][0]."')",
707 "delete from usr_holiday where (userid like '".$this->attrs[$this->dnmode][0]."')");
709 /* Trying to open a Postgresql Database Server */
710 if (function_exists("pg_connect")){
711 if(isset($this->oxconf["PGUSER"]) and
712 isset($this->oxconf["PGHOST"]) and
713 isset($this->oxconf["PGDBNAME"]) and
714 isset($this->oxconf["PGPASSWD"])){
715 $pgcon = @pg_connect("host=".$this->oxconf["PGHOST"]." user=".$this->oxconf["PGUSER"]." password=".$this->oxconf["PGPASSWD"]." dbname=".$this->oxconf["PGDBNAME"]);
716 if (! $pgcon){
717 print_red(_("Couldn't connect to postgresql database!"));
718 return;
719 }
720 }else{
721 print_red(_("Needed parameters for openexchange connectivity plugin are missing!"));
722 return;
723 }
724 }else{
725 print_red(_("PHP4 module for postgresql database is missing!"));
726 return;
727 }
729 plugin::remove_from_parent();
730 $ldap= $this->config->get_ldap_link();
732 if($ldap->dn_exists("ou=addr,".$this->dn)){
733 $ldap->rmdir_recursive("ou=addr,".$this->dn);
734 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/oxchange addressbook account with dn '%s' failed."),$this->dn));
735 }
737 $ldap->cd($this->dn);
738 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
739 $this->attributes, "Save");
740 $this->cleanup();
741 $ldap->modify ($this->attrs);
742 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/oxchange addressbook account with dn '%s' failed."),$this->dn));
744 /* Optionally execute a command after we're done */
745 $this->postremove(array("uid" => $this->uid));
747 /* Finally remove data from postgresql server */
748 foreach ($sqldeluser as $sqls){
749 @pg_exec($pgcon,$sqls);
750 }
751 pg_close();
752 }
754 /* Save data to object */
755 function save_object()
756 {
757 /* Do we need to flip is_account state? */
758 if (isset($_POST['connectivityTab'])){
759 if (isset($_POST['oxchange'])){
760 if (!$this->is_account && $_POST['oxchange'] == "B") {
761 if($this->acl_is_createable()){
762 $this->is_account= TRUE;
763 }
764 }
765 } else {
766 if($this->acl_is_removeable()){
767 $this->is_account= FALSE;
768 }
769 }
770 }
772 /* Get objects */
773 foreach(array("OXTimeZone","OXTaskDays","OXAppointmentDays") as $name) {
774 if($this->acl_is_writeable($name) && isset($_POST[$name])){
775 $this->$name = $_POST[$name];
776 }
777 }
779 // plugin::save_object();
780 if (isset($_POST["oxchangeStatus"])){
781 $this->oxchangeStatus = "disabled";
782 } else {
783 $this->oxchangeStatus = "enabled";
784 }
785 }
788 /* Save to LDAP */
789 function save()
790 {
792 $needupdate=TRUE;
793 $istemplate=FALSE;
796 /* print "<pre>".print_r($this->attrs, true)."</pre>";*/
799 /*First at all, we must check if this is new or is updated */
800 /*Also check is we have a template, if is a template, is a new user */
801 if (isset($this->attrs['objectClass'])){
802 foreach ($this->attrs['objectClass'] as $object){
803 if($object=="OXUserObject") $needupdate=FALSE;
804 if($object=="gosaUserTemplate") $istemplate=TRUE;
805 }
806 }
808 $uidarray=array();
809 preg_match("/^(\w+(?=\=))=((\w|\s|\.)+(?=\,)),.*/",$this->dn,$uidarray);
810 $uid=$uidarray[2];
811 if (trim($uid) == "") {
812 print_red(_("The Open-Xchange accountname is empty and thus invalid! Check to make sure that ".
813 "you are not using any strange characters in the loginname."));
814 return;
815 }
817 if ($istemplate) $needupdate=TRUE;
819 if($needupdate){
820 /* Trying to open a Postgresql Database Server */
821 if (function_exists("pg_connect")){
822 if(isset($this->oxconf["PGUSER"]) and isset($this->oxconf["PGHOST"]) and isset($this->oxconf["PGDBNAME"]) and isset($this->oxconf["PGPASSWD"])){
823 $pgcon = @pg_connect("host=".$this->oxconf["PGHOST"]." user=".$this->oxconf["PGUSER"]." password=".$this->oxconf["PGPASSWD"]." dbname=".$this->oxconf["PGDBNAME"]);
824 if (! $pgcon){
825 print_red(_("Couldn't connect to postgresql database!"));
826 return;
827 }
828 }else{
829 print_red(_("Needed parameters for openexchange connectivity plugin are missing!"));
830 return;
831 }
832 }else{
833 print_red(_("PHP4 module for postgresql database is missing!"));
834 return;
835 }
836 }
838 plugin::save();
840 /* Write back to ldap */
841 $ldap= $this->config->get_ldap_link();
842 $ldap->cd($this->dn);
843 $this->cleanup();
844 $ldap->modify ($this->attrs);
846 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/oxchange account with dn '%s' failed."),$this->dn));
848 /* Optionally execute a command after we're done */
849 $this->postcreate(array("uid" => $this->uid));
851 if($needupdate){
852 $ldap->create_missing_trees("ou=addr,".$this->dn);
853 show_ldap_error($ldap->get_error(), sprintf(_("Creating of user/oxchange account with dn '%s' failed."),$this->dn));
854 /* Finally save data to postgresql server */
855 pg_set_client_encoding ("UNICODE");
856 $nv = "SELECT nextval ('serial_id')";
857 $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')";
858 $op = "INSERT INTO oxfolder_permissions (puid, pid, role, entity, sealed, fp, orp, owp, odp) VALUES (%d, %d, 32768, '%s', 0, 128, 128, 128, 128)";
859 $os = "insert into oxfolder_standardfolders (owner,module_calendar,module_contact,module_task) VALUES ('%s',%d,%d,%d)";
860 $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'";
862 $error = FALSE;
863 $res=@pg_exec($pgcon,$nv);
865 if(!$res){
866 $error = TRUE;
867 }else{
868 $calendarid=pg_fetch_row($res);
869 pg_freeresult($res);
871 $q=sprintf($ot,$calendarid[0],'My Appointments','calendar',$uid,$uid);
872 @pg_exec($pgcon,$q);
873 }
875 $res=@pg_exec($pgcon,$nv);
877 if(!$res){
878 $error = TRUE;
879 }else{
880 $nid=pg_fetch_row($res);
881 pg_freeresult($res);
883 $q=sprintf($op,$nid[0],$calendarid[0],$uid);
884 @pg_exec($pgcon,$q);
885 }
887 $res=@pg_exec($pgcon,$nv);
888 if(!$res){
889 $error = TRUE;
890 }else{
891 $contactsid=pg_fetch_row($res);
892 pg_freeresult($res);
894 $q=sprintf($ot,$contactsid[0],'My Contacts','contact',$uid,$uid);
895 @pg_exec($pgcon,$q);
896 }
898 $res=@pg_exec($pgcon,$nv);
899 if(!$res){
900 $error = TRUE;
901 }else{
902 $nid=pg_fetch_row($res);
903 pg_freeresult($res);
905 $q=sprintf($op,$nid[0],$contactsid[0],$uid);
906 @pg_exec($pgcon,$q);
907 }
909 $res=@pg_exec($pgcon,$nv);
910 if(!$res){
911 $error = TRUE;
912 }else{
913 $tasksid=pg_fetch_row($res);
914 pg_freeresult($res);
916 $q=sprintf($ot,$tasksid[0],'My Tasks','task',$uid,$uid);
917 @pg_exec($pgcon,$q);
918 }
920 $res=@pg_exec($pgcon,$nv);
921 if(!$res){
922 $error = TRUE;
923 }else{
924 $nid=pg_fetch_row($res);
925 pg_freeresult($res);
927 $q=sprintf($op,$nid[0],$tasksid[0],$uid);
928 @pg_exec($pgcon,$q);
930 $q=sprintf($os,$uid,$calendarid[0],$contactsid[0],$tasksid[0]);
931 @pg_exec($pgcon,$q);
933 $q=sprintf($ugr,$uid);
934 @pg_exec($pgcon,$q);
935 }
937 @pg_close($pgcon);
939 if($error){
940 print_red(_("Something went wrong while saving oxchange account. Please check the error log file."));
941 }
942 }
943 }
946 /* Return plugin informations for acl handling */
947 function plInfo()
948 {
949 return (array(
950 "plShortName" => _("Open xchange"),
951 "plDescription" => _("Open xchange account settings")." : <u>"._("Connectivity addon")."</u>",
952 "plSelfModify" => TRUE,
953 "plDepends" => array("user"),
954 "plPriority" => 27, // Position in tabs
955 "plSection" => "personal", // This belongs to personal
956 "plCategory" => array("users"),
957 "plOptions" => array(),
959 "plProvidedAcls" => array(
960 "OXAppointmentDays" => _("OXAppointmentDays"),
961 "OXTaskDays" => _("OXTaskDays"),
962 "OXTimeZone" => _("OXTimeZone"))
963 ));
964 }
965 }
966 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
967 ?>