Code

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