Code

ae7fca4f0bdb39192486d454336bfbb001962de5
[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();
223     if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
224       return(_("There is currently no asterisk server defined. Possibly you are missing a server that handles the asterisk management (goFonServer). \n  Your Settings can't be saved to asterisk Database. "));
225       return(false);
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(in_array("goFonAccount",$member['objectClass'])){
290           $i ++ ;
291           $queueuser[$i]['queue_name']  = $this->attrs['cn'][0]; 
292           $queueuser[$i]['interface']   = "SIP/".$member['uid'][0]; 
293           $queueuser[$i]['penalty']     = 1; 
294         }
295       }
297       /* Parse and Add members to query Array */
298       if(is_array($queueuser)){
299         foreach($queueuser as $user){
300           $entries = "";
301           $values  = "";
302           foreach($user as $attr => $val){
303             $entries.= "`".$attr."`,"; 
304             $values .= "'".$val."',";
305           }
306           $values  = preg_replace("/,$/","",$values);
307           $entries = preg_replace("/,$/","",$entries );
309           $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")"; 
310         }
311       }
312       
313       /* generate Extension entries, with priority  */
315       $queueusers=0;
316       foreach($this->parent->by_object['ogroup']->memberList as $member){
317         if(in_array("goFonAccount",$member['objectClass'])){
318           $queueusers++;
319         }
320       }
323       $i = 0;
324       foreach($this->telephoneNumber as $num){
325        
326         // If there are no member in a Queue
327         // Play sound an quit
329         // A Queue is not deleted directly, it is stored until the o group is deleted
330         
331         $a_ext[$i]['context']  = 'GOsa';
332         $a_ext[$i]['exten']    = $this->attrs['cn'][0];
333         $a_ext[$i]['priority'] = 1;
334         $a_ext[$i]['app']      = "Goto";
335         $a_ext[$i]['appdata']  = $num."|1";
336         $i ++ ; 
337     
338         if($queueusers == 0){
339           $a_ext[$i]['context']  = 'GOsa';
340           $a_ext[$i]['exten']    = $num;
341           $a_ext[$i]['priority'] = 1;
342           $a_ext[$i]['app']      = "SetLanguage";
343           $a_ext[$i]['appdata']  = "de";
344           $i ++ ; 
345           
346           $a_ext[$i]['context']  = 'GOsa';
347           $a_ext[$i]['exten']    = $num;
348           $a_ext[$i]['priority'] = 2;
349           $a_ext[$i]['app']      = "Playback";
350           $a_ext[$i]['appdata']  = "ss-noservice";
351           $i ++ ; 
352           
353           $a_ext[$i]['context']  = 'GOsa';
354           $a_ext[$i]['exten']    = $num;
355           $a_ext[$i]['priority'] = 3;
356           $a_ext[$i]['app']      = "Goto";
357           $a_ext[$i]['appdata']  = "default";
358           $i ++ ; 
359         }else{
360           $prio --;
361           $a_ext[$i]['context']  = 'GOsa';
362           $a_ext[$i]['exten']    = $num;
363           $a_ext[$i]['priority'] = 1;
364           $a_ext[$i]['app']      = "Wait";
365           $a_ext[$i]['appdata']  = "2";
366           $i ++ ; 
367           $a_ext[$i]['context']  = 'GOsa';
368           $a_ext[$i]['exten']    = $num;
369           $a_ext[$i]['priority'] = 2;
370           $a_ext[$i]['app']      = "SetLanguage";
371           $a_ext[$i]['appdata']  = $this->goFonQueueLanguage;
372           $i ++ ; 
373           $a_ext[$i]['context']  = 'GOsa';
374           $a_ext[$i]['exten']    = $num;
375           $a_ext[$i]['priority'] = 3;
376           $a_ext[$i]['app']      = "Playback";
377           $a_ext[$i]['appdata']  = $this->goFonWelcomeMusic;
378           $i ++ ; 
379           $a_ext[$i]['context']  = 'GOsa';
380           $a_ext[$i]['exten']    = $num;
381           $a_ext[$i]['priority'] = 4;
382           $a_ext[$i]['app']      = "SetCIDName";
383           if(!empty($this->parent->by_object['ogroup']->description)){
384             $a_ext[$i]['appdata']  = $this->parent->by_object['ogroup']->description;
385           }else{
386             $a_ext[$i]['appdata']  = $this->attrs['cn'][0]." - ".$num;
387           }
388           $i ++ ; 
389           $a_ext[$i]['context']  = 'GOsa';
390           $a_ext[$i]['exten']    = $num;
391           $a_ext[$i]['priority'] = 5;
392           $a_ext[$i]['app']      = "SetVar";
393           $a_ext[$i]['appdata']  = "QUEUE_PRIO=".$prio;
394           $i ++ ; 
395           $a_ext[$i]['context']  = 'GOsa';
396           $a_ext[$i]['exten']    = $num;
397           $a_ext[$i]['priority'] = 6;
398           $a_ext[$i]['app']      = "Queue";
399           $a_ext[$i]['appdata']  =  $this->attrs['cn'][0].
400             "|".
401             $this->goFonDialOption_t.
402             $this->goFonDialOption_T.
403             $this->goFonDialOption_h.
404             $this->goFonDialOption_H.
405             $this->goFonDialOption_r;
406         }
408         if($this->goFonQueueAnnounceHoldtime != false) {
409           $this->goFonQueueAnnounceHoldtime = "yes";
410         }else{
411           $this->goFonQueueAnnounceHoldtime = "no";
412         }
415         /* Generate Priority Entry */
416         $queue["announce"]              = "";
417         $queue["monitor_join"]          = "";
418         $queue["monitor_format"]        = "";
419         $queue["queue_holdtime"]        = $this->goFonQueueAnnounce;
420         $queue["queue_lessthan"]        = $this->goFonQueueLessThan;   
421         $queue["announce_round_seconds"]= "";   
422         $queue["retry"]                 = $this->goFonQueueRetry;
423         $queue["wrapuptime"]            = "";
424         $queue["servicelevel"]          = "";
425         $queue["joinempty"]             = "no";
426         $queue["leavewhenempty"]        = "yes";   
427         $queue["eventmemberstatus"]     = "";
428         $queue["eventwhencalled"]       = "";
429         $queue["reportholdtime"]        = "yes";
430         $queue["memberdelay"]           = "";
431         $queue["weight"]                = "";
432         $queue["timeoutrestart"]        = "";
434         $queue["context"]               = "default";
435         $queue["name"]                  = $this->attrs['cn'][0];  
436         $queue["timeout"]               = $this->goFonTimeOut; 
437         $queue["maxlen"]                = $this->goFonMaxLen;
438         $queue["strategy" ]             = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
439         $queue["queue_thankyou"]        = $this->goFonQueueThankYou;   
440         $queue["queue_reporthold"]      = $this->goFonQueueReportHold; 
441         $queue["announce_frequency"]    = $this->goFonAnnounceFrequency;
442         $queue["queue_youarenext"]      = $this->goFonQueueYouAreNext;   
443         $queue["queue_thereare"]        = $this->goFonQueueThereAre;   
444         $queue["queue_callswaiting"]    = $this->goFonQueueCallsWaiting;
445         $queue["queue_minutes"]         = $this->goFonQueueMinutes;
446         $queue["queue_seconds"]         = $this->goFonQueueSeconds;   
447         $queue["announce_holdtime"]     = $this->goFonQueueAnnounceHoldtime;   
448         $queue["musiconhold"]           = $this->goFonMusiconHold;
450         $i++;
451       }
453       /* Parse and Add Extension entries */
454       foreach($a_ext as $ext){
455         $entries = "";
456         $values  = "";
457         foreach($ext as $attr => $val){
458           $entries.= "`".$attr."`,";
459           $values .= "'".$val."',";
460         }
461         $values  = preg_replace("/,$/","",$values);
462         $entries = preg_replace("/,$/","",$entries );
463         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
464       }
467       /* Parse and Add Queue */
468       $entries = "";
469       $values  = "";
470       foreach($queue as $attr=>$val){
471         if($val == "") continue;
472         $entries.= "`".$attr."`,";
473         $values .= "'".$val."',";
474       }
475       $values  = preg_replace("/,$/","",$values);
476       $entries = preg_replace("/,$/","",$entries );
477       $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
479       foreach($SQL as $query){
480          if(!mysql_query($query)){
481           gosa_log(mysql_error());
482           print_red(mysql_error());
483           return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
484         }
485       }
487     }
488     @mysql_close($r_con);
489     return(false);
490   }
494  /* This function checks if the given phonenumbers are available or already in use*/
496   function is_number_used()
497   {
498     $ldap= $this->config->get_ldap_link();
499     $ldap->cd($this->config->current['BASE']);
500     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
501     while($attrs = $ldap->fetch()) {
502       unset($attrs['telephoneNumber']['count']);
503       foreach($attrs['telephoneNumber'] as $tele){
504         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
505         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
506         $numbers[$tele]=$attrs;
507       }
508     }
510     foreach($this->telephoneNumber as $num){
511       if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!= $this->attrs['cn'][0]))){
512         if(isset($numbers[$num]['uid'][0])){
513           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
514         }else{
515           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
516         }
517       }
518     }
519   }
525   function save_object()
526   {
527     plugin::save_object();  
528     if(isset($_POST['phonenumber'])){
529       foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_r","goFonDialOption_H","goFonMusiconHold") as $val){
530         if(isset($_POST[$val])){
531           $this->$val = $_POST[$val];
532         }else{
533           $this->$val = false;
534         }
535       }
536       if(isset($_POST['goFonQueueAnnounceHoldtime'])){
537         $this->goFonQueueAnnounceHoldtime = "yes";
538       }else{
539         $this->goFonQueueAnnounceHoldtime = false;
540       }
541       
542     }
544   }
546   function save()
547   {
548   #fixme workaround : Tab is not initialised correct
549         if(!$this->is_account) return;
550     $ldap= $this->config->get_ldap_link();
552     $this->generate_mysql_table_entries(true);
554     plugin::save();
555     $this->attrs['goFonDialOption'] = "";
556     foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
557       $this->attrs['goFonDialOption'].=$this->$val; 
558       unset($this->attrs[$val]); 
559     }
560     if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
561   
562     if($this->goFonQueueAnnounceHoldtime != "no" ){
563       $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
564     }else{
565       $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
566     }
568     $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
570     /* Save data to LDAP */
571     $ldap->cd($this->dn);
572     $ldap->modify($this->attrs);
574     show_ldap_error($ldap->get_error());
576     /* Optionally execute a command after we're done */
577     if ($this->initially_was_account == $this->is_account){
578       if ($this->is_modified){
579         $this->handle_post_events("mofify");
580       }
581     } else {
582       $this->handle_post_events("add");
583     }
584   }
587   /* remove object from parent */
588   function remove_from_parent()
589   {
590     $SQL = array();
592     // Get Configuration for Mysql database Server
593     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
594     $s_parameter  ="";
596     // Connect to DB server
597     $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
599     // Check if we are  connected correctly
600     if(!$r_con){
601       gosa_log(mysql_error());
602       return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
603             $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
604     }
606     // Select database for Extensions
607     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
609     // Test if we have the database selected correctly
610     if(!$db){
611       gosa_log(mysql_error());
612       return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
613     }
615     /* Remove all temporary attributes */
616     $tmp = array_flip($this->attributes);
617     foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
618       unset($this->$val);
619       unset($this->attrs[$val]);
620       unset($tmp[$val]);
621     }   
622     foreach(array_flip($tmp) as $key => $val){
623       $tmp2[]=$val;
624     } 
625     $this->attributes = $tmp2;
627     $i = 0;
628     $prio = 11;
630     if(empty($this->cn)){
631       $this->cn = $this->parent->by_object['ogroup']->cn;
632       $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
633     }
635     // Delete old Entries
636     $delete = array();
637     foreach($this->old_phone_numbers as $phone){
638       $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
639     }
640     $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$this->attrs['cn'][0]."';\n";
641     $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
642     $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
644     /* Perform queries to delte old entries */
645     foreach($delete as $query){
646       if(!mysql_query($query)){
647         gosa_log(mysql_error());
648         return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
649       }
650     }
654     /* Cancel if there's nothing to do here */
655     if (!$this->initially_was_account){
656       return;
657     }
659     /* include global link_info */
660     $ldap= $this->config->get_ldap_link();
662     /* Remove and write to LDAP */
663     plugin::remove_from_parent();
665     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
666         $this->attributes, "Save");
667     $ldap->cd($this->dn);
668     $ldap->modify($this->attrs);
669     show_ldap_error($ldap->get_error());
670   }
674 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
675 ?>