Code

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