Code

c5fb59f7e3ff720560ef8297eea19773daefac64
[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     /* Do we need to flip is_account state? */
103     if (isset($_POST['modify_state'])){
104       $this->is_account= !$this->is_account;
105     }
107     /* Show tab dialog headers */
108     if ($this->parent != NULL){
109       if ($this->is_account){
110         $display= $this->show_header(_("Remove the phone queue from this Account"),
111             _("Phone queue is enabled for this group. You can disable it by clicking below."));
112       } else {
113         $display= $this->show_header(_("Create phone queue"), _("For this group the phone queues are disabled. You can enable them by clicking below."));
114         return ($display);
115       }
116     }
118     /* Add queue number */ 
119     if(isset($_POST['add_phonenumber'])&&(isset($_POST['phonenumber']))&&(!empty($_POST['phonenumber']))){
120       if((!in_array($_POST['phonenumber'],$this->telephoneNumber))&&(is_numeric($_POST['phonenumber']))){
121         $this->telephoneNumber[]=$_POST['phonenumber'];
122       }
123     }
125     /* Delete queue number */ 
126     if(isset($_POST['delete_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
127       unset($this->telephoneNumber[$_POST['goFonQueueNumber_List']]);
128     }
129   
130     $tmp = array();
131     foreach($this->telephoneNumber as $val){
132       if(!empty($val)){
133         $tmp[]= $val;
134       }
135     }  
136     $this->telephoneNumber=$tmp;
138     /* queue number up */ 
139     if(isset($_POST['up_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
140       if($_POST['goFonQueueNumber_List']>0){
141         $up   = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
142         $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1];
143         $this->telephoneNumber[$_POST['goFonQueueNumber_List']]    = $down; 
144         $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1]  = $up;
145       }
146     }
148     /* Queuenumber down */ 
149     if(isset($_POST['down_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
150       if(isset($this->telephoneNumber[($_POST['goFonQueueNumber_List']+1)])){
151         $up   = $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1];
152         $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
153         $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1]    = $down; 
154         $this->telephoneNumber[$_POST['goFonQueueNumber_List']]  = $up;
155       }
156     }
158     $smarty= get_smarty();
160     $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German'),'ur'=>_('Uruguai')));
161     $smarty->assign("goFonQueueStrategyOptions", $this->goFonQueueStrategyOptions);
163     foreach($this->attributes as $key => $val){
164       $smarty->assign($val,$this->$val);  
166       if($this->$val == false){
167         $smarty->assign($val."CHK","");
168       }else{
169         $smarty->assign($val."CHK"," checked ");
170       }
172       if(chkacl($this->acl,$key)==""){
173         $smarty->assign($val."ACL","");
174       }else{
175         $smarty->assign($val."ACL"," disabled ");
176       }
177     }
178     return ($display.$smarty->fetch (get_template_path('phonequeue.tpl', TRUE)));
179   }
182   /* Check formular input */
183   function check()
184   {
185     $message= array();
186   #fixme workaround : Tab is not initialised correct
187           if(!$this->is_account) return($message);
189     if($this->is_number_used()){
190       $message[] = $this->is_number_used();
191     }
193     if($this->generate_mysql_table_entries()){
194       $message[] = $this->generate_mysql_table_entries();
195     }
197     if(!((is_numeric($this->goFonTimeOut))||(empty($this->goFonTimeOut)))){
198       $message[] = _("Timeout must be numeric");
199     }
200     if(!((is_numeric($this->goFonQueueRetry))||(empty($this->goFonQueueRetry)))){
201       $message[] = _("Retry must be numeric");
202     }
203     if(!((is_numeric($this->goFonMaxLen))||(empty($this->goFonMaxLen)))){
204       $message[] = _("Max queue length must be numeric");
205     }
206     if(!((is_numeric($this->goFonAnnounceFrequency))||(empty($this->goFonAnnounceFrequency)))){
207       $message[] = _("Announce frequency must be numeric");
208     }
209     if(count($this->telephoneNumber)==0){
210       $message[] = _("There must be least one queue number defined.");
211     }
213     return $message;
214   }
218   function generate_mysql_table_entries($save = false)
219   {
221     $SQL = array();
222  
223     // Get Configuration for Mysql database Server
224     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
225     $s_parameter  ="";
227     // Connect to DB server
228     $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
230     // Check if we are  connected correctly
231     if(!$r_con){
232       gosa_log(mysql_error());
233       return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
234           $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
235     }
237     // Select database for Extensions
238     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
240     // Test if we have the database selected correctly
241     if(!$db){
242       gosa_log(mysql_error());
243       return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
244     }
246     if($save){
247       $i = 0;
248       $prio = 11; 
250       $delete = array();
251       if(!empty($this->parent->by_object['ogroup'])){
252         $new_cn = $this->parent->by_object['ogroup']->cn;
253       }
254       $old_cn = $this->cn;
256       $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$new_cn."';\n";
257       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']."  WHERE name='".$new_cn."'; \n";
258       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$new_cn."';\n";
259       $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$old_cn."';\n";
260       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']."  WHERE name='".$old_cn."'; \n";
261       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$old_cn."';\n";
263       // Delete old Entries 
264       if(is_array($this->old_phone_numbers)){
265         foreach($this->old_phone_numbers as $phone){
266           $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
267         }
268       }
270       /* Perform queries to delte old entries */
271       foreach($delete as $query){
272         if(!mysql_query($query)){
273           gosa_log(mysql_error());
274           return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
275         }
276       }
278       $this->attrs['cn'][0] = $new_cn;
280       /* Append new Member for this queue */ 
281       $i = 0;
282       $queueuser =array();
283       foreach($this->parent->by_object['ogroup']->memberList as $member){
284         if(in_array("goFonAccount",$member['objectClass'])){
285           $i ++ ;
286           $queueuser[$i]['queue_name']  = $this->attrs['cn'][0]; 
287           $queueuser[$i]['interface']   = "SIP/".$member['uid'][0]; 
288           $queueuser[$i]['penalty']     = 1; 
289         }
290       }
292       /* Parse and Add members to query Array */
293       if(is_array($queueuser)){
294         foreach($queueuser as $user){
295           $entries = "";
296           $values  = "";
297           foreach($user as $attr => $val){
298             $entries.= "`".$attr."`,"; 
299             $values .= "'".$val."',";
300           }
301           $values  = preg_replace("/,$/","",$values);
302           $entries = preg_replace("/,$/","",$entries );
304           $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")"; 
305         }
306       }
307       
308       /* generate Extension entries, with priority  */
310       $queueusers=0;
311       foreach($this->parent->by_object['ogroup']->memberList as $member){
312         if(in_array("goFonAccount",$member['objectClass'])){
313           $queueusers++;
314         }
315       }
318       $i = 0;
319       foreach($this->telephoneNumber as $num){
320        
321         // If there are no member in a Queue
322         // Play sound an quit
324         // A Queue is not deleted directly, it is stored until the o group is deleted
325         
326         $a_ext[$i]['context']  = 'GOsa';
327         $a_ext[$i]['exten']    = $this->attrs['cn'][0];
328         $a_ext[$i]['priority'] = 1;
329         $a_ext[$i]['app']      = "Goto";
330         $a_ext[$i]['appdata']  = $num."|1";
331         $i ++ ; 
332     
333         if($queueusers == 0){
334           $a_ext[$i]['context']  = 'GOsa';
335           $a_ext[$i]['exten']    = $num;
336           $a_ext[$i]['priority'] = 1;
337           $a_ext[$i]['app']      = "SetLanguage";
338           $a_ext[$i]['appdata']  = "de";
339           $i ++ ; 
340           
341           $a_ext[$i]['context']  = 'GOsa';
342           $a_ext[$i]['exten']    = $num;
343           $a_ext[$i]['priority'] = 2;
344           $a_ext[$i]['app']      = "Playback";
345           $a_ext[$i]['appdata']  = "ss-noservice";
346           $i ++ ; 
347           
348           $a_ext[$i]['context']  = 'GOsa';
349           $a_ext[$i]['exten']    = $num;
350           $a_ext[$i]['priority'] = 3;
351           $a_ext[$i]['app']      = "Goto";
352           $a_ext[$i]['appdata']  = "default";
353           $i ++ ; 
354         }else{
355           $prio --;
356           $a_ext[$i]['context']  = 'GOsa';
357           $a_ext[$i]['exten']    = $num;
358           $a_ext[$i]['priority'] = 1;
359           $a_ext[$i]['app']      = "Wait";
360           $a_ext[$i]['appdata']  = "2";
361           $i ++ ; 
362           $a_ext[$i]['context']  = 'GOsa';
363           $a_ext[$i]['exten']    = $num;
364           $a_ext[$i]['priority'] = 2;
365           $a_ext[$i]['app']      = "SetLanguage";
366           $a_ext[$i]['appdata']  = $this->goFonQueueLanguage;
367           $i ++ ; 
368           $a_ext[$i]['context']  = 'GOsa';
369           $a_ext[$i]['exten']    = $num;
370           $a_ext[$i]['priority'] = 3;
371           $a_ext[$i]['app']      = "Playback";
372           $a_ext[$i]['appdata']  = $this->goFonWelcomeMusic;
373           $i ++ ; 
374           $a_ext[$i]['context']  = 'GOsa';
375           $a_ext[$i]['exten']    = $num;
376           $a_ext[$i]['priority'] = 4;
377           $a_ext[$i]['app']      = "SetCIDName";
378           if(!empty($this->parent->by_object['ogroup']->description)){
379             $a_ext[$i]['appdata']  = $this->parent->by_object['ogroup']->description;
380           }else{
381             $a_ext[$i]['appdata']  = $this->attrs['cn'][0]." - ".$num;
382           }
383           $i ++ ; 
384           $a_ext[$i]['context']  = 'GOsa';
385           $a_ext[$i]['exten']    = $num;
386           $a_ext[$i]['priority'] = 5;
387           $a_ext[$i]['app']      = "SetVar";
388           $a_ext[$i]['appdata']  = "QUEUE_PRIO=".$prio;
389           $i ++ ; 
390           $a_ext[$i]['context']  = 'GOsa';
391           $a_ext[$i]['exten']    = $num;
392           $a_ext[$i]['priority'] = 6;
393           $a_ext[$i]['app']      = "Queue";
394           $a_ext[$i]['appdata']  =  $this->attrs['cn'][0].
395             "|".
396             $this->goFonDialOption_t.
397             $this->goFonDialOption_T.
398             $this->goFonDialOption_h.
399             $this->goFonDialOption_H.
400             $this->goFonDialOption_r;
401         }
403         if($this->goFonQueueAnnounceHoldtime != false) {
404           $this->goFonQueueAnnounceHoldtime = "yes";
405         }else{
406           $this->goFonQueueAnnounceHoldtime = "no";
407         }
410         /* Generate Priority Entry */
411         $queue["announce"]              = "";
412         $queue["monitor_join"]          = "";
413         $queue["monitor_format"]        = "";
414         $queue["queue_holdtime"]        = $this->goFonQueueAnnounce;
415         $queue["queue_lessthan"]        = $this->goFonQueueLessThan;   
416         $queue["announce_round_seconds"]= "";   
417         $queue["retry"]                 = $this->goFonQueueRetry;
418         $queue["wrapuptime"]            = "";
419         $queue["servicelevel"]          = "";
420         $queue["joinempty"]             = "no";
421         $queue["leavewhenempty"]        = "yes";   
422         $queue["eventmemberstatus"]     = "";
423         $queue["eventwhencalled"]       = "";
424         $queue["reportholdtime"]        = "yes";
425         $queue["memberdelay"]           = "";
426         $queue["weight"]                = "";
427         $queue["timeoutrestart"]        = "";
429         $queue["context"]               = "default";
430         $queue["name"]                  = $this->attrs['cn'][0];  
431         $queue["timeout"]               = $this->goFonTimeOut; 
432         $queue["maxlen"]                = $this->goFonMaxLen;
433         $queue["strategy" ]             = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
434         $queue["queue_thankyou"]        = $this->goFonQueueThankYou;   
435         $queue["queue_reporthold"]      = $this->goFonQueueReportHold; 
436         $queue["announce_frequency"]    = $this->goFonAnnounceFrequency;
437         $queue["queue_youarenext"]      = $this->goFonQueueYouAreNext;   
438         $queue["queue_thereare"]        = $this->goFonQueueThereAre;   
439         $queue["queue_callswaiting"]    = $this->goFonQueueCallsWaiting;
440         $queue["queue_minutes"]         = $this->goFonQueueMinutes;
441         $queue["queue_seconds"]         = $this->goFonQueueSeconds;   
442         $queue["announce_holdtime"]     = $this->goFonQueueAnnounceHoldtime;   
443         $queue["musiconhold"]           = $this->goFonMusiconHold;
445         $i++;
446       }
448       /* Parse and Add Extension entries */
449       foreach($a_ext as $ext){
450         $entries = "";
451         $values  = "";
452         foreach($ext as $attr => $val){
453           $entries.= "`".$attr."`,";
454           $values .= "'".$val."',";
455         }
456         $values  = preg_replace("/,$/","",$values);
457         $entries = preg_replace("/,$/","",$entries );
458         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
459       }
462       /* Parse and Add Queue */
463       $entries = "";
464       $values  = "";
465       foreach($queue as $attr=>$val){
466         if($val == "") continue;
467         $entries.= "`".$attr."`,";
468         $values .= "'".$val."',";
469       }
470       $values  = preg_replace("/,$/","",$values);
471       $entries = preg_replace("/,$/","",$entries );
472       $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
474       foreach($SQL as $query){
475          if(!mysql_query($query)){
476           gosa_log(mysql_error());
477           print_red(mysql_error());
478           return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
479         }
480       }
482     }
483     return(false);
484   }
488  /* This function checks if the given phonenumbers are available or already in use*/
490   function is_number_used()
491   {
492     $ldap= $this->config->get_ldap_link();
493     $ldap->cd($this->config->current['BASE']);
494     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
495     while($attrs = $ldap->fetch()) {
496       unset($attrs['telephoneNumber']['count']);
497       foreach($attrs['telephoneNumber'] as $tele){
498         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
499         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
500         $numbers[$tele]=$attrs;
501       }
502     }
504     foreach($this->telephoneNumber as $num){
505       if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!= $this->attrs['cn'][0]))){
506         if(isset($numbers[$num]['uid'][0])){
507           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
508         }else{
509           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
510         }
511       }
512     }
513   }
519   function save_object()
520   {
521     plugin::save_object();  
522     if(isset($_POST['phonenumber'])){
523       foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_r","goFonDialOption_H","goFonMusiconHold") as $val){
524         if(isset($_POST[$val])){
525           $this->$val = $_POST[$val];
526         }else{
527           $this->$val = false;
528         }
529       }
530       if(isset($_POST['goFonQueueAnnounceHoldtime'])){
531         $this->goFonQueueAnnounceHoldtime = "yes";
532       }else{
533         $this->goFonQueueAnnounceHoldtime = false;
534       }
535       
536     }
538   }
540   function save()
541   {
542   #fixme workaround : Tab is not initialised correct
543         if(!$this->is_account) return;
544     $ldap= $this->config->get_ldap_link();
546     $this->generate_mysql_table_entries(true);
548     plugin::save();
549     $this->attrs['goFonDialOption'] = "";
550     foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
551       $this->attrs['goFonDialOption'].=$this->$val; 
552       unset($this->attrs[$val]); 
553     }
554     if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
555   
556     if($this->goFonQueueAnnounceHoldtime != "no" ){
557       $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
558     }else{
559       $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
560     }
562     $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
564     /* Save data to LDAP */
565     $ldap->cd($this->dn);
566     $ldap->modify($this->attrs);
568     show_ldap_error($ldap->get_error());
570     /* Optionally execute a command after we're done */
571     if ($this->initially_was_account == $this->is_account){
572       if ($this->is_modified){
573         $this->handle_post_events("mofify");
574       }
575     } else {
576       $this->handle_post_events("add");
577     }
578   }
581   /* remove object from parent */
582   function remove_from_parent()
583   {
584     $SQL = array();
586     // Get Configuration for Mysql database Server
587     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
588     $s_parameter  ="";
590     // Connect to DB server
591     $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
593     // Check if we are  connected correctly
594     if(!$r_con){
595       gosa_log(mysql_error());
596       return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
597             $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
598     }
600     // Select database for Extensions
601     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
603     // Test if we have the database selected correctly
604     if(!$db){
605       gosa_log(mysql_error());
606       return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
607     }
609     /* Remove all temporary attributes */
610     $tmp = array_flip($this->attributes);
611     foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
612       unset($this->$val);
613       unset($this->attrs[$val]);
614       unset($tmp[$val]);
615     }   
616     foreach(array_flip($tmp) as $key => $val){
617       $tmp2[]=$val;
618     } 
619     $this->attributes = $tmp2;
621     $i = 0;
622     $prio = 11;
624     if(empty($this->cn)){
625       $this->cn = $this->parent->by_object['ogroup']->cn;
626       $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
627     }
629     // Delete old Entries
630     $delete = array();
631     foreach($this->old_phone_numbers as $phone){
632       $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
633     }
634     $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$this->attrs['cn'][0]."';\n";
635     $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
636     $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
638     /* Perform queries to delte old entries */
639     foreach($delete as $query){
640       if(!mysql_query($query)){
641         gosa_log(mysql_error());
642         return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
643       }
644     }
648     /* Cancel if there's nothing to do here */
649     if (!$this->initially_was_account){
650       return;
651     }
653     /* include global link_info */
654     $ldap= $this->config->get_ldap_link();
656     /* Remove and write to LDAP */
657     plugin::remove_from_parent();
659     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
660         $this->attributes, "Save");
661     $ldap->cd($this->dn);
662     $ldap->modify($this->attrs);
663     show_ldap_error($ldap->get_error());
664   }
668 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
669 ?>