Code

Added support for general check hooks
[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     /* Call common method to give check the hook */
190     $message= plugin::check();
192     if($this->is_number_used()){
193       $message[] = $this->is_number_used();
194     }
196     if($this->generate_mysql_table_entries()){
197       $message[] = $this->generate_mysql_table_entries();
198     }
200     if(!((is_numeric($this->goFonTimeOut))||(empty($this->goFonTimeOut)))){
201       $message[] = _("Timeout must be numeric");
202     }
203     if(!((is_numeric($this->goFonQueueRetry))||(empty($this->goFonQueueRetry)))){
204       $message[] = _("Retry must be numeric");
205     }
206     if(!((is_numeric($this->goFonMaxLen))||(empty($this->goFonMaxLen)))){
207       $message[] = _("Max queue length must be numeric");
208     }
209     if(!((is_numeric($this->goFonAnnounceFrequency))||(empty($this->goFonAnnounceFrequency)))){
210       $message[] = _("Announce frequency must be numeric");
211     }
212     if(count($this->telephoneNumber)==0){
213       $message[] = _("There must be least one queue number defined.");
214     }
216     return $message;
217   }
221   function generate_mysql_table_entries($save = false)
222   {
224     $SQL = array();
226     if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
227       return(_("There is currently no asterisk server defined. Your settings can't be saved."));
228     }
230     // Get Configuration for Mysql database Server
231     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
232     $s_parameter  ="";
234     // Connect to DB server
235     $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
237     // Check if we are  connected correctly
238     if(!$r_con){
239       gosa_log(mysql_error());
240       return (sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
241           $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
242     }
244     // Select database for Extensions
245     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
247     // Test if we have the database selected correctly
248     if(!$db){
249       gosa_log(mysql_error());
250       return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
251     }
253     if($save){
254       $i = 0;
255       $prio = 11; 
257       $delete = array();
258       if(!empty($this->parent->by_object['ogroup'])){
259         $new_cn = $this->parent->by_object['ogroup']->cn;
260       }
261       $old_cn = $this->cn;
263       $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$new_cn."';\n";
264       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']."  WHERE name='".$new_cn."'; \n";
265       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$new_cn."';\n";
266       $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$old_cn."';\n";
267       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']."  WHERE name='".$old_cn."'; \n";
268       $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$old_cn."';\n";
270       // Delete old Entries 
271       if(is_array($this->old_phone_numbers)){
272         foreach($this->old_phone_numbers as $phone){
273           $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
274         }
275       }
277       /* Perform queries to delte old entries */
278       foreach($delete as $query){
279         if(!mysql_query($query)){
280           gosa_log(mysql_error());
281           return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
282         }
283       }
285       $this->attrs['cn'][0] = $new_cn;
287       /* Append new Member for this queue */ 
288       $i = 0;
289       $queueuser =array();
290       foreach($this->parent->by_object['ogroup']->memberList as $member){
291         if(isset($member['objectClass'])){
292           if(in_array("goFonAccount",$member['objectClass'])){
293             $i ++ ;
294             $queueuser[$i]['queue_name']  = $this->attrs['cn'][0]; 
295             $queueuser[$i]['interface']   = "SIP/".$member['uid'][0]; 
296             $queueuser[$i]['penalty']     = 1; 
297           }
298         }
299       }
301       /* Parse and Add members to query Array */
302       if(is_array($queueuser)){
303         foreach($queueuser as $user){
304           $entries = "";
305           $values  = "";
306           foreach($user as $attr => $val){
307             $entries.= "`".$attr."`,"; 
308             $values .= "'".$val."',";
309           }
310           $values  = preg_replace("/,$/","",$values);
311           $entries = preg_replace("/,$/","",$entries );
313           $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")"; 
314         }
315       }
316       
317       /* generate Extension entries, with priority  */
319       $queueusers=0;
320       foreach($this->parent->by_object['ogroup']->memberList as $member){
321         if(isset($member['objectClass'])){
322           if(in_array("goFonAccount",$member['objectClass'])){
323             $queueusers++;
324           }
325         }
326       }
329       $i = 0;
331       $i_insert_only_once = false;
332       
333       foreach($this->telephoneNumber as $num){
334        
335         // If there are no member in a Queue
336         // Play sound an quit
338         // A Queue is not deleted directly, it is stored until the o group is deleted
339         
340         if($i_insert_only_once == false){
341           $i_insert_only_once = true;
342           $a_ext[$i]['context']  = 'GOsa';
343           $a_ext[$i]['exten']    = $this->attrs['cn'][0];
344           $a_ext[$i]['priority'] = 1;
345           $a_ext[$i]['app']      = "Goto";
346           $a_ext[$i]['appdata']  = $num."|1";
347           $i ++ ; 
348         }
349     
350         if($queueusers == 0){
351           $a_ext[$i]['context']  = 'GOsa';
352           $a_ext[$i]['exten']    = $num;
353           $a_ext[$i]['priority'] = 1;
354           $a_ext[$i]['app']      = "SetLanguage";
355           $a_ext[$i]['appdata']  = "de";
356           $i ++ ; 
357           
358           $a_ext[$i]['context']  = 'GOsa';
359           $a_ext[$i]['exten']    = $num;
360           $a_ext[$i]['priority'] = 2;
361           $a_ext[$i]['app']      = "Playback";
362           $a_ext[$i]['appdata']  = "ss-noservice";
363           $i ++ ; 
364           
365           $a_ext[$i]['context']  = 'GOsa';
366           $a_ext[$i]['exten']    = $num;
367           $a_ext[$i]['priority'] = 3;
368           $a_ext[$i]['app']      = "Goto";
369           $a_ext[$i]['appdata']  = "default";
370           $i ++ ; 
371         }else{
372           $prio --;
373           $a_ext[$i]['context']  = 'GOsa';
374           $a_ext[$i]['exten']    = $num;
375           $a_ext[$i]['priority'] = 1;
376           $a_ext[$i]['app']      = "Wait";
377           $a_ext[$i]['appdata']  = "2";
378           $i ++ ; 
379           $a_ext[$i]['context']  = 'GOsa';
380           $a_ext[$i]['exten']    = $num;
381           $a_ext[$i]['priority'] = 2;
382           $a_ext[$i]['app']      = "SetLanguage";
383           $a_ext[$i]['appdata']  = $this->goFonQueueLanguage;
384           $i ++ ; 
385           $a_ext[$i]['context']  = 'GOsa';
386           $a_ext[$i]['exten']    = $num;
387           $a_ext[$i]['priority'] = 3;
388           $a_ext[$i]['app']      = "Playback";
389           $a_ext[$i]['appdata']  = $this->goFonWelcomeMusic;
390           $i ++ ; 
391           $a_ext[$i]['context']  = 'GOsa';
392           $a_ext[$i]['exten']    = $num;
393           $a_ext[$i]['priority'] = 4;
394           $a_ext[$i]['app']      = "SetCIDName";
395           if(!empty($this->parent->by_object['ogroup']->description)){
396             $a_ext[$i]['appdata']  = $this->parent->by_object['ogroup']->description;
397           }else{
398             $a_ext[$i]['appdata']  = $this->attrs['cn'][0]." - ".$num;
399           }
400           $i ++ ; 
401           $a_ext[$i]['context']  = 'GOsa';
402           $a_ext[$i]['exten']    = $num;
403           $a_ext[$i]['priority'] = 5;
404           $a_ext[$i]['app']      = "SetVar";
405           $a_ext[$i]['appdata']  = "QUEUE_PRIO=".$prio;
406           $i ++ ; 
407           $a_ext[$i]['context']  = 'GOsa';
408           $a_ext[$i]['exten']    = $num;
409           $a_ext[$i]['priority'] = 6;
410           $a_ext[$i]['app']      = "Queue";
411           $a_ext[$i]['appdata']  =  $this->attrs['cn'][0].
412             "|".
413             $this->goFonDialOption_t.
414             $this->goFonDialOption_T.
415             $this->goFonDialOption_h.
416             $this->goFonDialOption_H.
417             $this->goFonDialOption_r;
418         }
420         if($this->goFonQueueAnnounceHoldtime != false) {
421           $this->goFonQueueAnnounceHoldtime = "yes";
422         }else{
423           $this->goFonQueueAnnounceHoldtime = "no";
424         }
427         /* Generate Priority Entry */
428         $queue["announce"]              = "";
429         $queue["monitor_join"]          = "";
430         $queue["monitor_format"]        = "";
431         $queue["queue_holdtime"]        = $this->goFonQueueAnnounce;
432         $queue["queue_lessthan"]        = $this->goFonQueueLessThan;   
433         $queue["announce_round_seconds"]= "";   
434         $queue["retry"]                 = $this->goFonQueueRetry;
435         $queue["wrapuptime"]            = "";
436         $queue["servicelevel"]          = "";
437         $queue["joinempty"]             = "no";
438         $queue["leavewhenempty"]        = "yes";   
439         $queue["eventmemberstatus"]     = "";
440         $queue["eventwhencalled"]       = "";
441         $queue["reportholdtime"]        = "yes";
442         $queue["memberdelay"]           = "";
443         $queue["weight"]                = "";
444         $queue["timeoutrestart"]        = "";
446         $queue["context"]               = "default";
447         $queue["name"]                  = $this->attrs['cn'][0];  
448         $queue["timeout"]               = $this->goFonTimeOut; 
449         $queue["maxlen"]                = $this->goFonMaxLen;
450         $queue["strategy" ]             = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
451         $queue["queue_thankyou"]        = $this->goFonQueueThankYou;   
452         $queue["queue_reporthold"]      = $this->goFonQueueReportHold; 
453         $queue["announce_frequency"]    = $this->goFonAnnounceFrequency;
454         $queue["queue_youarenext"]      = $this->goFonQueueYouAreNext;   
455         $queue["queue_thereare"]        = $this->goFonQueueThereAre;   
456         $queue["queue_callswaiting"]    = $this->goFonQueueCallsWaiting;
457         $queue["queue_minutes"]         = $this->goFonQueueMinutes;
458         $queue["queue_seconds"]         = $this->goFonQueueSeconds;   
459         $queue["announce_holdtime"]     = $this->goFonQueueAnnounceHoldtime;   
460         $queue["musiconhold"]           = $this->goFonMusiconHold;
462         $i++;
463       }
465       /* Parse and Add Extension entries */
466       foreach($a_ext as $ext){
467         $entries = "";
468         $values  = "";
469         foreach($ext as $attr => $val){
470           $entries.= "`".$attr."`,";
471           $values .= "'".$val."',";
472         }
473         $values  = preg_replace("/,$/","",$values);
474         $entries = preg_replace("/,$/","",$entries );
475         $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
476       }
479       /* Parse and Add Queue */
480       $entries = "";
481       $values  = "";
482       foreach($queue as $attr=>$val){
483         if($val == "") continue;
484         $entries.= "`".$attr."`,";
485         $values .= "'".$val."',";
486       }
487       $values  = preg_replace("/,$/","",$values);
488       $entries = preg_replace("/,$/","",$entries );
489       $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
491       foreach($SQL as $query){
492          if(!mysql_query($query)){
493           gosa_log(mysql_error());
494           print_red(mysql_error());
495           return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
496         }
497       }
499     }
500     @mysql_close($r_con);
501     return(false);
502   }
506  /* This function checks if the given phonenumbers are available or already in use*/
508   function is_number_used()
509   {
510     $ldap= $this->config->get_ldap_link();
511     $ldap->cd($this->config->current['BASE']);
512     $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
513     while($attrs = $ldap->fetch()) {
514       unset($attrs['telephoneNumber']['count']);
515       foreach($attrs['telephoneNumber'] as $tele){
516         if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
517         if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
518         $numbers[$tele]=$attrs;
519       }
520     }
522     foreach($this->telephoneNumber as $num){
523       if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!= $this->attrs['cn'][0]))){
524         if(isset($numbers[$num]['uid'][0])){
525           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
526         }else{
527           return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
528         }
529       }
530     }
531   }
537   function save_object()
538   {
539     plugin::save_object();  
540     if(isset($_POST['phonenumber'])){
541       foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_r","goFonDialOption_H","goFonMusiconHold") as $val){
542         if(isset($_POST[$val])){
543           $this->$val = $_POST[$val];
544         }else{
545           $this->$val = false;
546         }
547       }
548       if(isset($_POST['goFonQueueAnnounceHoldtime'])){
549         $this->goFonQueueAnnounceHoldtime = "yes";
550       }else{
551         $this->goFonQueueAnnounceHoldtime = false;
552       }
553       
554     }
556   }
558   function save()
559   {
560   #fixme workaround : Tab is not initialised correct
561         if(!$this->is_account) return;
562     $ldap= $this->config->get_ldap_link();
564     $this->generate_mysql_table_entries(true);
566     plugin::save();
567     $this->attrs['goFonDialOption'] = "";
568     foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
569       $this->attrs['goFonDialOption'].=$this->$val; 
570       unset($this->attrs[$val]); 
571     }
572     if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
573   
574     if($this->goFonQueueAnnounceHoldtime != "no" ){
575       $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
576     }else{
577       $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
578     }
580     $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
582     /* Save data to LDAP */
583     $ldap->cd($this->dn);
584     $this->cleanup();
585 $ldap->modify ($this->attrs); 
588     show_ldap_error($ldap->get_error());
590     /* Optionally execute a command after we're done */
591     if ($this->initially_was_account == $this->is_account){
592       if ($this->is_modified){
593         $this->handle_post_events("mofify");
594       }
595     } else {
596       $this->handle_post_events("add");
597     }
598   }
601   /* remove object from parent */
602   function remove_from_parent()
603   {
604     $SQL = array();
606     // Get Configuration for Mysql database Server
607     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
608     $s_parameter  ="";
610     // Connect to DB server
611     $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
613     // Check if we are  connected correctly
614     if(!$r_con){
615       gosa_log(mysql_error());
616       return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
617             $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
618     }
620     // Select database for Extensions
621     $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
623     // Test if we have the database selected correctly
624     if(!$db){
625       gosa_log(mysql_error());
626       return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
627     }
629     /* Remove all temporary attributes */
630     $tmp = array_flip($this->attributes);
631     foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
632       unset($this->$val);
633       unset($this->attrs[$val]);
634       unset($tmp[$val]);
635     }   
636     foreach(array_flip($tmp) as $key => $val){
637       $tmp2[]=$val;
638     } 
639     $this->attributes = $tmp2;
641     $i = 0;
642     $prio = 11;
644     if(empty($this->cn)){
645       $this->cn = $this->parent->by_object['ogroup']->cn;
646       $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
647     }
649     // Delete old Entries
650     $delete = array();
651     foreach($this->old_phone_numbers as $phone){
652       $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
653     }
654     $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$this->attrs['cn'][0]."';\n";
655     $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
656     $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
658     /* Perform queries to delte old entries */
659     foreach($delete as $query){
660       if(!mysql_query($query)){
661         gosa_log(mysql_error());
662         return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
663       }
664     }
668     /* Cancel if there's nothing to do here */
669     if (!$this->initially_was_account){
670       return;
671     }
673     /* include global link_info */
674     $ldap= $this->config->get_ldap_link();
676     /* Remove and write to LDAP */
677     plugin::remove_from_parent();
679     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
680         $this->attributes, "Save");
681     $ldap->cd($this->dn);
682     $this->cleanup();
683 $ldap->modify ($this->attrs); 
685     show_ldap_error($ldap->get_error());
686   }
688   
689   function getCopyDialog()
690   {
691     $str  = "";
692     $str .= _("Phone number");
693     $str .= "&nbsp;<input type='text' name='telephoneNumber' value='".$this->telephoneNumber."'>";
694     return($str);
695   }
698   function saveCopyDialog()
699   {
700     if(isset($_POST['telephoneNumber'])){
701       $this->telephoneNumber = $_POST['telephoneNumber'];
702     }
703   }
708 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
709 ?>