Code

Fixed /var/www/gosa/plugins/admin/groups/class_groupAcl.inc (Line 173) Undefined...
[gosa.git] / plugins / admin / ogroups / class_phonequeue.inc
1 <?php
3 class phonequeue extends plugin
4 {
5   /* plugin specific values */
6   var $mail= "";
7   var $cn= "";
10   var $goFonTimeOut             ="20"; 
11   var $goFonMaxLen              ="20"; // 
12   var $goFonAnnounceFrequency   ="60"; // Annouce Frequency in seconds
13   var $goFonDialOption_t        ="";
14   var $goFonDialOption_T        ="";
15   var $goFonDialOption_h        ="";
16   var $goFonDialOption_r        ="";
17   var $goFonQueueAnnounce       ="gonicus-berlin-welcome";
18   var $goFonDialOption_H        ="";
19   var $goFonMusiconHold         ="default";
20   var $goFonWelcomeMusic        ="gonicus-berlin-welcome";
21   var $goFonQueueReportHold     ="yes";
22   var $goFonQueueYouAreNext     ="queue-youarenext";
23   var $goFonQueueThereAre       ="queue-thereare";
24   var $goFonQueueCallsWaiting   ="queue-callswaiting";
25   var $goFonQueueThankYou       ="queue-thankyou";
26   var $goFonQueueMinutes        ="queue-minutes"; 
27   var $goFonQueueSeconds        ="queue-seconds";
28   var $goFonQueueLessThan       ="queue-lessthan";
29   var $goFonQueueLanguage       ="queue-holdtime";
30   var $goFonQueueStrategy       ="ringall";
31   var $goFonQueueAnnounceHoldtime="yes";
32   var $telephoneNumber          =array();
33   var $goFonQueueMember         =array(); 
34   var $goFonDialOption          ="";
35   var $goFonQueueRetry          =5;
37   var $goFonQueueStrategyOptions=array();
38   var $goFonQueueStrategyOptionsR=array();
39   
41   var $old_phone_numbers        =array();
43   /* attribute list for save action */
44   var $attributes= array( "goFonTimeOut","goFonMaxLen","goFonAnnounceFrequency","goFonDialOption_t","goFonDialOption_T",
45       "goFonDialOption_h","goFonDialOption_r","cn",
46       "goFonDialOption_H","goFonMusiconHold","goFonWelcomeMusic","goFonQueueReportHold","goFonQueueYouAreNext",
47       "goFonQueueThereAre","goFonQueueCallsWaiting","goFonQueueThankYou","goFonQueueMinutes","goFonQueueSeconds","goFonQueueLessThan",
48       "telephoneNumber","goFonQueueLanguage","goFonQueueStrategy","goFonQueueAnnounceHoldtime","goFonQueueAnnounce","goFonDialOption","goFonQueueRetry");
49   /* ObjectClass */
50   var $objectclasses= array("goFonQueue");
52   function phonequeue ($config, $dn= NULL)
53   {
54     plugin::plugin($config, $dn);
56     /* Include config object */
57     $this->config= $config;
59     /* Save initial account state */
60     $this->initially_was_account= $this->is_account;
62     if($this->is_account){
63       if(isset($this->attrs['telephoneNumber'])){
64         $this->telephoneNumber=$this->attrs['telephoneNumber'];
65         unset($this->telephoneNumber['count']); 
66       }
68       for($i = 0; $i < strlen($this->goFonDialOption); $i++){
69         $name = "goFonDialOption_".$this->goFonDialOption[$i];
70         $this->$name=$this->goFonDialOption[$i];
71       }
72     }
74     if($this->goFonQueueAnnounceHoldtime == "no"){
75       $this->goFonQueueAnnounceHoldtime=false;
76     }
77     $this->old_phone_numbers = $this->telephoneNumber;
79    $types= array('ringall'    =>_("ring all"),
80           'roundrobin' =>_("round robin"),
81           'leastrecent'=>_("least recently called"),
82           'fewestcalls'=>_("fewest completed calls"),
83           'random'     =>_("random"),
84           'rrmemory'   =>_("round robin with memory"));
86    $i = 0;
87    foreach($types as $type => $name){
88      $i++;
89      $this->goFonQueueStrategyOptions[$i]    =$name;
90      $this->goFonQueueStrategyOptionsR[$i]   =$type;
91      $tmp[$type] = $i; 
92    }
93   
94   $this->goFonQueueStrategy= $tmp[$this->goFonQueueStrategy];
95   
97   }
100   function execute()
101   {
102         /* Call parent execute */
103         plugin::execute();
105     /* Do we need to flip is_account state? */
106     if (isset($_POST['modify_state'])){
107       $this->is_account= !$this->is_account;
108     }
110     /* Show tab dialog headers */
111     if ($this->parent != NULL){
112       if ($this->is_account){
113         $display= $this->show_header(_("Remove the phone queue from this Account"),
114             _("Phone queue is enabled for this group. You can disable it by clicking below."));
115       } else {
116         $display= $this->show_header(_("Create phone queue"), 
117                   _("For this group the phone queues are disabled. You can enable them by clicking below."));
118         return ($display);
119       }
120     }
122     /* Add queue number */ 
123     if(isset($_POST['add_phonenumber'])&&(isset($_POST['phonenumber']))&&(!empty($_POST['phonenumber']))){
124       if((!in_array($_POST['phonenumber'],$this->telephoneNumber))&&(is_numeric($_POST['phonenumber']))){
125         $this->telephoneNumber[]=$_POST['phonenumber'];
126       }
127     }
129     /* Delete queue number */ 
130     if(isset($_POST['delete_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
131       unset($this->telephoneNumber[$_POST['goFonQueueNumber_List']]);
132     }
133   
134     $tmp = array();
135     foreach($this->telephoneNumber as $val){
136       if(!empty($val)){
137         $tmp[]= $val;
138       }
139     }  
140     $this->telephoneNumber=$tmp;
142     /* queue number up */ 
143     if(isset($_POST['up_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
144       if($_POST['goFonQueueNumber_List']>0){
145         $up   = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
146         $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1];
147         $this->telephoneNumber[$_POST['goFonQueueNumber_List']]    = $down; 
148         $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1]  = $up;
149       }
150     }
152     /* Queuenumber down */ 
153     if(isset($_POST['down_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
154       if(isset($this->telephoneNumber[($_POST['goFonQueueNumber_List']+1)])){
155         $up   = $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1];
156         $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
157         $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1]    = $down; 
158         $this->telephoneNumber[$_POST['goFonQueueNumber_List']]  = $up;
159       }
160     }
162     $smarty= get_smarty();
164     $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German')));
165     $smarty->assign("goFonQueueStrategyOptions", $this->goFonQueueStrategyOptions);
167     foreach($this->attributes as $key => $val){
168       $smarty->assign($val,$this->$val);  
170       if($this->$val == false){
171         $smarty->assign($val."CHK","");
172       }else{
173         $smarty->assign($val."CHK"," checked ");
174       }
176       if(chkacl($this->acl,$key)==""){
177         $smarty->assign($val."ACL","");
178       }else{
179         $smarty->assign($val."ACL"," disabled ");
180       }
181     }
182     return ($display.$smarty->fetch (get_template_path('phonequeue.tpl', TRUE)));
183   }
186   /* Check formular input */
187   function check()
188   {
189     $message= array();
190     if($this->is_number_used()){
191       $message[] = $this->is_number_used();
192     }
194     if($this->generate_mysql_table_entries()){
195       $message[] = $this->generate_mysql_table_entries();
196     }
198     if(!((is_numeric($this->goFonTimeOut))||(empty($this->goFonTimeOut)))){
199       $message[] = _("Timeout must be numeric");
200     }
201     if(!((is_numeric($this->goFonQueueRetry))||(empty($this->goFonQueueRetry)))){
202       $message[] = _("Retry must be numeric");
203     }
204     if(!((is_numeric($this->goFonMaxLen))||(empty($this->goFonMaxLen)))){
205       $message[] = _("Max queue length must be numeric");
206     }
207     if(!((is_numeric($this->goFonAnnounceFrequency))||(empty($this->goFonAnnounceFrequency)))){
208       $message[] = _("Announce frequency must be numeric");
209     }
210     if(count($this->telephoneNumber)==0){
211       $message[] = _("There must be least one queue number defined.");
212     }
214     return $message;
215   }
219   function generate_mysql_table_entries($save = false)
220   {
222     $SQL = array();
224     if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
225       return(_("There is currently no asterisk server defined. Your settings can't be saved."));
226     }
228     // Get Configuration for Mysql database Server
229     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
230     $s_parameter  ="";
232     // Connect to DB server
233     $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
235     // Check if we are  connected correctly
236     if(!$r_con){
237       gosa_log(mysql_error());
238       return (sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
239           $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
240     }
242     // Select database for Extensions
243     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
245     // Test if we have the database selected correctly
246     if(!$db){
247       gosa_log(mysql_error());
248       return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
249     }
251     if($save){
252       $i = 0;
253       $prio = 11; 
255       $delete = array();
256       if(!empty($this->parent->by_object['ogroup'])){
257         $new_cn = $this->parent->by_object['ogroup']->cn;
258       }
259       $old_cn = $this->cn;
261       $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$new_cn."';\n";
262       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']."  WHERE name='".$new_cn."'; \n";
263       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$new_cn."';\n";
264       $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$old_cn."';\n";
265       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']."  WHERE name='".$old_cn."'; \n";
266       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$old_cn."';\n";
268       // Delete old Entries 
269       if(is_array($this->old_phone_numbers)){
270         foreach($this->old_phone_numbers as $phone){
271           $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
272         }
273       }
275       /* Perform queries to delte old entries */
276       foreach($delete as $query){
277         if(!mysql_query($query)){
278           gosa_log(mysql_error());
279           return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
280         }
281       }
283       $this->attrs['cn'][0] = $new_cn;
285       /* Append new Member for this queue */ 
286       $i = 0;
287       $queueuser =array();
288       foreach($this->parent->by_object['ogroup']->memberList as $member){
289         if(isset($member['objectClass'])){
290           if(in_array("goFonAccount",$member['objectClass'])){
291             $i ++ ;
292             $queueuser[$i]['queue_name']  = $this->attrs['cn'][0]; 
293             $queueuser[$i]['interface']   = "SIP/".$member['uid'][0]; 
294             $queueuser[$i]['penalty']     = 1; 
295           }
296         }
297       }
299       /* Parse and Add members to query Array */
300       if(is_array($queueuser)){
301         foreach($queueuser as $user){
302           $entries = "";
303           $values  = "";
304           foreach($user as $attr => $val){
305             $entries.= "`".$attr."`,"; 
306             $values .= "'".$val."',";
307           }
308           $values  = preg_replace("/,$/","",$values);
309           $entries = preg_replace("/,$/","",$entries );
311           $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")"; 
312         }
313       }
314       
315       /* generate Extension entries, with priority  */
317       $queueusers=0;
318       foreach($this->parent->by_object['ogroup']->memberList as $member){
319         if(isset($member['objectClass'])){
320           if(in_array("goFonAccount",$member['objectClass'])){
321             $queueusers++;
322           }
323         }
324       }
327       $i = 0;
329       $i_insert_only_once = false;
330       
331       foreach($this->telephoneNumber as $num){
332        
333         // If there are no member in a Queue
334         // Play sound an quit
336         // A Queue is not deleted directly, it is stored until the o group is deleted
337         
338         if($i_insert_only_once == false){
339           $i_insert_only_once = true;
340           $a_ext[$i]['context']  = 'GOsa';
341           $a_ext[$i]['exten']    = $this->attrs['cn'][0];
342           $a_ext[$i]['priority'] = 1;
343           $a_ext[$i]['app']      = "Goto";
344           $a_ext[$i]['appdata']  = $num."|1";
345           $i ++ ; 
346         }
347     
348         if($queueusers == 0){
349           $a_ext[$i]['context']  = 'GOsa';
350           $a_ext[$i]['exten']    = $num;
351           $a_ext[$i]['priority'] = 1;
352           $a_ext[$i]['app']      = "SetLanguage";
353           $a_ext[$i]['appdata']  = "de";
354           $i ++ ; 
355           
356           $a_ext[$i]['context']  = 'GOsa';
357           $a_ext[$i]['exten']    = $num;
358           $a_ext[$i]['priority'] = 2;
359           $a_ext[$i]['app']      = "Playback";
360           $a_ext[$i]['appdata']  = "ss-noservice";
361           $i ++ ; 
362           
363           $a_ext[$i]['context']  = 'GOsa';
364           $a_ext[$i]['exten']    = $num;
365           $a_ext[$i]['priority'] = 3;
366           $a_ext[$i]['app']      = "Goto";
367           $a_ext[$i]['appdata']  = "default";
368           $i ++ ; 
369         }else{
370           $prio --;
371           $a_ext[$i]['context']  = 'GOsa';
372           $a_ext[$i]['exten']    = $num;
373           $a_ext[$i]['priority'] = 1;
374           $a_ext[$i]['app']      = "Wait";
375           $a_ext[$i]['appdata']  = "2";
376           $i ++ ; 
377           $a_ext[$i]['context']  = 'GOsa';
378           $a_ext[$i]['exten']    = $num;
379           $a_ext[$i]['priority'] = 2;
380           $a_ext[$i]['app']      = "SetLanguage";
381           $a_ext[$i]['appdata']  = $this->goFonQueueLanguage;
382           $i ++ ; 
383           $a_ext[$i]['context']  = 'GOsa';
384           $a_ext[$i]['exten']    = $num;
385           $a_ext[$i]['priority'] = 3;
386           $a_ext[$i]['app']      = "Playback";
387           $a_ext[$i]['appdata']  = $this->goFonWelcomeMusic;
388           $i ++ ; 
389           $a_ext[$i]['context']  = 'GOsa';
390           $a_ext[$i]['exten']    = $num;
391           $a_ext[$i]['priority'] = 4;
392           $a_ext[$i]['app']      = "SetCIDName";
393           if(!empty($this->parent->by_object['ogroup']->description)){
394             $a_ext[$i]['appdata']  = $this->parent->by_object['ogroup']->description;
395           }else{
396             $a_ext[$i]['appdata']  = $this->attrs['cn'][0]." - ".$num;
397           }
398           $i ++ ; 
399           $a_ext[$i]['context']  = 'GOsa';
400           $a_ext[$i]['exten']    = $num;
401           $a_ext[$i]['priority'] = 5;
402           $a_ext[$i]['app']      = "SetVar";
403           $a_ext[$i]['appdata']  = "QUEUE_PRIO=".$prio;
404           $i ++ ; 
405           $a_ext[$i]['context']  = 'GOsa';
406           $a_ext[$i]['exten']    = $num;
407           $a_ext[$i]['priority'] = 6;
408           $a_ext[$i]['app']      = "Queue";
409           $a_ext[$i]['appdata']  =  $this->attrs['cn'][0].
410             "|".
411             $this->goFonDialOption_t.
412             $this->goFonDialOption_T.
413             $this->goFonDialOption_h.
414             $this->goFonDialOption_H.
415             $this->goFonDialOption_r;
416         }
418         if($this->goFonQueueAnnounceHoldtime != false) {
419           $this->goFonQueueAnnounceHoldtime = "yes";
420         }else{
421           $this->goFonQueueAnnounceHoldtime = "no";
422         }
425         /* Generate Priority Entry */
426         $queue["announce"]              = "";
427         $queue["monitor_join"]          = "";
428         $queue["monitor_format"]        = "";
429         $queue["queue_holdtime"]        = $this->goFonQueueAnnounce;
430         $queue["queue_lessthan"]        = $this->goFonQueueLessThan;   
431         $queue["announce_round_seconds"]= "";   
432         $queue["retry"]                 = $this->goFonQueueRetry;
433         $queue["wrapuptime"]            = "";
434         $queue["servicelevel"]          = "";
435         $queue["joinempty"]             = "no";
436         $queue["leavewhenempty"]        = "yes";   
437         $queue["eventmemberstatus"]     = "";
438         $queue["eventwhencalled"]       = "";
439         $queue["reportholdtime"]        = "yes";
440         $queue["memberdelay"]           = "";
441         $queue["weight"]                = "";
442         $queue["timeoutrestart"]        = "";
444         $queue["context"]               = "default";
445         $queue["name"]                  = $this->attrs['cn'][0];  
446         $queue["timeout"]               = $this->goFonTimeOut; 
447         $queue["maxlen"]                = $this->goFonMaxLen;
448         $queue["strategy" ]             = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
449         $queue["queue_thankyou"]        = $this->goFonQueueThankYou;   
450         $queue["queue_reporthold"]      = $this->goFonQueueReportHold; 
451         $queue["announce_frequency"]    = $this->goFonAnnounceFrequency;
452         $queue["queue_youarenext"]      = $this->goFonQueueYouAreNext;   
453         $queue["queue_thereare"]        = $this->goFonQueueThereAre;   
454         $queue["queue_callswaiting"]    = $this->goFonQueueCallsWaiting;
455         $queue["queue_minutes"]         = $this->goFonQueueMinutes;
456         $queue["queue_seconds"]         = $this->goFonQueueSeconds;   
457         $queue["announce_holdtime"]     = $this->goFonQueueAnnounceHoldtime;   
458         $queue["musiconhold"]           = $this->goFonMusiconHold;
460         $i++;
461       }
463       /* Parse and Add Extension entries */
464       foreach($a_ext as $ext){
465         $entries = "";
466         $values  = "";
467         foreach($ext as $attr => $val){
468           $entries.= "`".$attr."`,";
469           $values .= "'".$val."',";
470         }
471         $values  = preg_replace("/,$/","",$values);
472         $entries = preg_replace("/,$/","",$entries );
473         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
474       }
477       /* Parse and Add Queue */
478       $entries = "";
479       $values  = "";
480       foreach($queue as $attr=>$val){
481         if($val == "") continue;
482         $entries.= "`".$attr."`,";
483         $values .= "'".$val."',";
484       }
485       $values  = preg_replace("/,$/","",$values);
486       $entries = preg_replace("/,$/","",$entries );
487       $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
489       foreach($SQL as $query){
490          if(!mysql_query($query)){
491           gosa_log(mysql_error());
492           print_red(mysql_error());
493           return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
494         }
495       }
497     }
498     @mysql_close($r_con);
499     return(false);
500   }
504  /* This function checks if the given phonenumbers are available or already in use*/
506   function is_number_used()
507   {
508     $ldap= $this->config->get_ldap_link();
509     $ldap->cd($this->config->current['BASE']);
510     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
511     while($attrs = $ldap->fetch()) {
512       unset($attrs['telephoneNumber']['count']);
513       foreach($attrs['telephoneNumber'] as $tele){
514         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
515         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
516         $numbers[$tele]=$attrs;
517       }
518     }
520     foreach($this->telephoneNumber as $num){
521       if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!= $this->attrs['cn'][0]))){
522         if(isset($numbers[$num]['uid'][0])){
523           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
524         }else{
525           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
526         }
527       }
528     }
529   }
535   function save_object()
536   {
537     plugin::save_object();  
538     if(isset($_POST['phonenumber'])){
539       foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_r","goFonDialOption_H","goFonMusiconHold") as $val){
540         if(isset($_POST[$val])){
541           $this->$val = $_POST[$val];
542         }else{
543           $this->$val = false;
544         }
545       }
546       if(isset($_POST['goFonQueueAnnounceHoldtime'])){
547         $this->goFonQueueAnnounceHoldtime = "yes";
548       }else{
549         $this->goFonQueueAnnounceHoldtime = false;
550       }
551       
552     }
554   }
556   function save()
557   {
558   #fixme workaround : Tab is not initialised correct
559         if(!$this->is_account) return;
560     $ldap= $this->config->get_ldap_link();
562     $this->generate_mysql_table_entries(true);
564     plugin::save();
565     $this->attrs['goFonDialOption'] = "";
566     foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
567       $this->attrs['goFonDialOption'].=$this->$val; 
568       unset($this->attrs[$val]); 
569     }
570     if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
571   
572     if($this->goFonQueueAnnounceHoldtime != "no" ){
573       $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
574     }else{
575       $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
576     }
578     $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
580     /* Save data to LDAP */
581     $ldap->cd($this->dn);
582     $this->cleanup();
583 $ldap->modify ($this->attrs); 
586     show_ldap_error($ldap->get_error());
588     /* Optionally execute a command after we're done */
589     if ($this->initially_was_account == $this->is_account){
590       if ($this->is_modified){
591         $this->handle_post_events("mofify");
592       }
593     } else {
594       $this->handle_post_events("add");
595     }
596   }
599   /* remove object from parent */
600   function remove_from_parent()
601   {
602     $SQL = array();
604     // Get Configuration for Mysql database Server
605     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
606     $s_parameter  ="";
608     // Connect to DB server
609     $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
611     // Check if we are  connected correctly
612     if(!$r_con){
613       gosa_log(mysql_error());
614       return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
615             $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
616     }
618     // Select database for Extensions
619     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
621     // Test if we have the database selected correctly
622     if(!$db){
623       gosa_log(mysql_error());
624       return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
625     }
627     /* Remove all temporary attributes */
628     $tmp = array_flip($this->attributes);
629     foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
630       unset($this->$val);
631       unset($this->attrs[$val]);
632       unset($tmp[$val]);
633     }   
634     foreach(array_flip($tmp) as $key => $val){
635       $tmp2[]=$val;
636     } 
637     $this->attributes = $tmp2;
639     $i = 0;
640     $prio = 11;
642     if(empty($this->cn)){
643       $this->cn = $this->parent->by_object['ogroup']->cn;
644       $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
645     }
647     // Delete old Entries
648     $delete = array();
649     foreach($this->old_phone_numbers as $phone){
650       $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
651     }
652     $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$this->attrs['cn'][0]."';\n";
653     $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
654     $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
656     /* Perform queries to delte old entries */
657     foreach($delete as $query){
658       if(!mysql_query($query)){
659         gosa_log(mysql_error());
660         return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
661       }
662     }
666     /* Cancel if there's nothing to do here */
667     if (!$this->initially_was_account){
668       return;
669     }
671     /* include global link_info */
672     $ldap= $this->config->get_ldap_link();
674     /* Remove and write to LDAP */
675     plugin::remove_from_parent();
677     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
678         $this->attributes, "Save");
679     $ldap->cd($this->dn);
680     $this->cleanup();
681 $ldap->modify ($this->attrs); 
683     show_ldap_error($ldap->get_error());
684   }
688 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
689 ?>