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