9cefb8574b3283e19ce12fcb5ffbb70706ebe028
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();
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 }
94 $this->goFonQueueStrategy= $tmp[$this->goFonQueueStrategy];
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 unset($_SESSION['config']->data['SERVERS']['FON']);
109 /* Show tab dialog headers */
110 if ($this->parent != NULL){
111 if ($this->is_account){
112 $display= $this->show_header(_("Remove the phone queue from this Account"),
113 _("Phone queue is enabled for this group. You can disable it by clicking below."));
114 } else {
115 $display= $this->show_header(_("Create phone queue"), _("For this group the phone queues are disabled. You can enable them by clicking below."));
116 return ($display);
117 }
118 }
120 /* Add queue number */
121 if(isset($_POST['add_phonenumber'])&&(isset($_POST['phonenumber']))&&(!empty($_POST['phonenumber']))){
122 if((!in_array($_POST['phonenumber'],$this->telephoneNumber))&&(is_numeric($_POST['phonenumber']))){
123 $this->telephoneNumber[]=$_POST['phonenumber'];
124 }
125 }
127 /* Delete queue number */
128 if(isset($_POST['delete_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
129 unset($this->telephoneNumber[$_POST['goFonQueueNumber_List']]);
130 }
132 $tmp = array();
133 foreach($this->telephoneNumber as $val){
134 if(!empty($val)){
135 $tmp[]= $val;
136 }
137 }
138 $this->telephoneNumber=$tmp;
140 /* queue number up */
141 if(isset($_POST['up_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
142 if($_POST['goFonQueueNumber_List']>0){
143 $up = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
144 $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1];
145 $this->telephoneNumber[$_POST['goFonQueueNumber_List']] = $down;
146 $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1] = $up;
147 }
148 }
150 /* Queuenumber down */
151 if(isset($_POST['down_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
152 if(isset($this->telephoneNumber[($_POST['goFonQueueNumber_List']+1)])){
153 $up = $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1];
154 $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
155 $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1] = $down;
156 $this->telephoneNumber[$_POST['goFonQueueNumber_List']] = $up;
157 }
158 }
160 $smarty= get_smarty();
162 $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German'),'ur'=>_('Uruguai')));
163 $smarty->assign("goFonQueueStrategyOptions", $this->goFonQueueStrategyOptions);
165 foreach($this->attributes as $key => $val){
166 $smarty->assign($val,$this->$val);
168 if($this->$val == false){
169 $smarty->assign($val."CHK","");
170 }else{
171 $smarty->assign($val."CHK"," checked ");
172 }
174 if(chkacl($this->acl,$key)==""){
175 $smarty->assign($val."ACL","");
176 }else{
177 $smarty->assign($val."ACL"," disabled ");
178 }
179 }
180 return ($display.$smarty->fetch (get_template_path('phonequeue.tpl', TRUE)));
181 }
184 /* Check formular input */
185 function check()
186 {
187 $message= array();
188 #fixme workaround : Tab is not initialised correct
189 if(!$this->is_account) return($message);
191 if($this->is_number_used()){
192 $message[] = $this->is_number_used();
193 }
195 if($this->generate_mysql_table_entries()){
196 $message[] = $this->generate_mysql_table_entries();
197 }
199 if(!((is_numeric($this->goFonTimeOut))||(empty($this->goFonTimeOut)))){
200 $message[] = _("Timeout must be numeric");
201 }
202 if(!((is_numeric($this->goFonQueueRetry))||(empty($this->goFonQueueRetry)))){
203 $message[] = _("Retry must be numeric");
204 }
205 if(!((is_numeric($this->goFonMaxLen))||(empty($this->goFonMaxLen)))){
206 $message[] = _("Max queue length must be numeric");
207 }
208 if(!((is_numeric($this->goFonAnnounceFrequency))||(empty($this->goFonAnnounceFrequency)))){
209 $message[] = _("Announce frequency must be numeric");
210 }
211 if(count($this->telephoneNumber)==0){
212 $message[] = _("There must be least one queue number defined.");
213 }
215 return $message;
216 }
220 function generate_mysql_table_entries($save = false)
221 {
223 $SQL = array();
225 if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
226 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. "));
227 return(false);
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(in_array("goFonAccount",$member['objectClass'])){
292 $i ++ ;
293 $queueuser[$i]['queue_name'] = $this->attrs['cn'][0];
294 $queueuser[$i]['interface'] = "SIP/".$member['uid'][0];
295 $queueuser[$i]['penalty'] = 1;
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 }
315 /* generate Extension entries, with priority */
317 $queueusers=0;
318 foreach($this->parent->by_object['ogroup']->memberList as $member){
319 if(in_array("goFonAccount",$member['objectClass'])){
320 $queueusers++;
321 }
322 }
325 $i = 0;
326 foreach($this->telephoneNumber as $num){
328 // If there are no member in a Queue
329 // Play sound an quit
331 // A Queue is not deleted directly, it is stored until the o group is deleted
333 $a_ext[$i]['context'] = 'GOsa';
334 $a_ext[$i]['exten'] = $this->attrs['cn'][0];
335 $a_ext[$i]['priority'] = 1;
336 $a_ext[$i]['app'] = "Goto";
337 $a_ext[$i]['appdata'] = $num."|1";
338 $i ++ ;
340 if($queueusers == 0){
341 $a_ext[$i]['context'] = 'GOsa';
342 $a_ext[$i]['exten'] = $num;
343 $a_ext[$i]['priority'] = 1;
344 $a_ext[$i]['app'] = "SetLanguage";
345 $a_ext[$i]['appdata'] = "de";
346 $i ++ ;
348 $a_ext[$i]['context'] = 'GOsa';
349 $a_ext[$i]['exten'] = $num;
350 $a_ext[$i]['priority'] = 2;
351 $a_ext[$i]['app'] = "Playback";
352 $a_ext[$i]['appdata'] = "ss-noservice";
353 $i ++ ;
355 $a_ext[$i]['context'] = 'GOsa';
356 $a_ext[$i]['exten'] = $num;
357 $a_ext[$i]['priority'] = 3;
358 $a_ext[$i]['app'] = "Goto";
359 $a_ext[$i]['appdata'] = "default";
360 $i ++ ;
361 }else{
362 $prio --;
363 $a_ext[$i]['context'] = 'GOsa';
364 $a_ext[$i]['exten'] = $num;
365 $a_ext[$i]['priority'] = 1;
366 $a_ext[$i]['app'] = "Wait";
367 $a_ext[$i]['appdata'] = "2";
368 $i ++ ;
369 $a_ext[$i]['context'] = 'GOsa';
370 $a_ext[$i]['exten'] = $num;
371 $a_ext[$i]['priority'] = 2;
372 $a_ext[$i]['app'] = "SetLanguage";
373 $a_ext[$i]['appdata'] = $this->goFonQueueLanguage;
374 $i ++ ;
375 $a_ext[$i]['context'] = 'GOsa';
376 $a_ext[$i]['exten'] = $num;
377 $a_ext[$i]['priority'] = 3;
378 $a_ext[$i]['app'] = "Playback";
379 $a_ext[$i]['appdata'] = $this->goFonWelcomeMusic;
380 $i ++ ;
381 $a_ext[$i]['context'] = 'GOsa';
382 $a_ext[$i]['exten'] = $num;
383 $a_ext[$i]['priority'] = 4;
384 $a_ext[$i]['app'] = "SetCIDName";
385 if(!empty($this->parent->by_object['ogroup']->description)){
386 $a_ext[$i]['appdata'] = $this->parent->by_object['ogroup']->description;
387 }else{
388 $a_ext[$i]['appdata'] = $this->attrs['cn'][0]." - ".$num;
389 }
390 $i ++ ;
391 $a_ext[$i]['context'] = 'GOsa';
392 $a_ext[$i]['exten'] = $num;
393 $a_ext[$i]['priority'] = 5;
394 $a_ext[$i]['app'] = "SetVar";
395 $a_ext[$i]['appdata'] = "QUEUE_PRIO=".$prio;
396 $i ++ ;
397 $a_ext[$i]['context'] = 'GOsa';
398 $a_ext[$i]['exten'] = $num;
399 $a_ext[$i]['priority'] = 6;
400 $a_ext[$i]['app'] = "Queue";
401 $a_ext[$i]['appdata'] = $this->attrs['cn'][0].
402 "|".
403 $this->goFonDialOption_t.
404 $this->goFonDialOption_T.
405 $this->goFonDialOption_h.
406 $this->goFonDialOption_H.
407 $this->goFonDialOption_r;
408 }
410 if($this->goFonQueueAnnounceHoldtime != false) {
411 $this->goFonQueueAnnounceHoldtime = "yes";
412 }else{
413 $this->goFonQueueAnnounceHoldtime = "no";
414 }
417 /* Generate Priority Entry */
418 $queue["announce"] = "";
419 $queue["monitor_join"] = "";
420 $queue["monitor_format"] = "";
421 $queue["queue_holdtime"] = $this->goFonQueueAnnounce;
422 $queue["queue_lessthan"] = $this->goFonQueueLessThan;
423 $queue["announce_round_seconds"]= "";
424 $queue["retry"] = $this->goFonQueueRetry;
425 $queue["wrapuptime"] = "";
426 $queue["servicelevel"] = "";
427 $queue["joinempty"] = "no";
428 $queue["leavewhenempty"] = "yes";
429 $queue["eventmemberstatus"] = "";
430 $queue["eventwhencalled"] = "";
431 $queue["reportholdtime"] = "yes";
432 $queue["memberdelay"] = "";
433 $queue["weight"] = "";
434 $queue["timeoutrestart"] = "";
436 $queue["context"] = "default";
437 $queue["name"] = $this->attrs['cn'][0];
438 $queue["timeout"] = $this->goFonTimeOut;
439 $queue["maxlen"] = $this->goFonMaxLen;
440 $queue["strategy" ] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
441 $queue["queue_thankyou"] = $this->goFonQueueThankYou;
442 $queue["queue_reporthold"] = $this->goFonQueueReportHold;
443 $queue["announce_frequency"] = $this->goFonAnnounceFrequency;
444 $queue["queue_youarenext"] = $this->goFonQueueYouAreNext;
445 $queue["queue_thereare"] = $this->goFonQueueThereAre;
446 $queue["queue_callswaiting"] = $this->goFonQueueCallsWaiting;
447 $queue["queue_minutes"] = $this->goFonQueueMinutes;
448 $queue["queue_seconds"] = $this->goFonQueueSeconds;
449 $queue["announce_holdtime"] = $this->goFonQueueAnnounceHoldtime;
450 $queue["musiconhold"] = $this->goFonMusiconHold;
452 $i++;
453 }
455 /* Parse and Add Extension entries */
456 foreach($a_ext as $ext){
457 $entries = "";
458 $values = "";
459 foreach($ext as $attr => $val){
460 $entries.= "`".$attr."`,";
461 $values .= "'".$val."',";
462 }
463 $values = preg_replace("/,$/","",$values);
464 $entries = preg_replace("/,$/","",$entries );
465 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
466 }
469 /* Parse and Add Queue */
470 $entries = "";
471 $values = "";
472 foreach($queue as $attr=>$val){
473 if($val == "") continue;
474 $entries.= "`".$attr."`,";
475 $values .= "'".$val."',";
476 }
477 $values = preg_replace("/,$/","",$values);
478 $entries = preg_replace("/,$/","",$entries );
479 $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
481 foreach($SQL as $query){
482 if(!mysql_query($query)){
483 gosa_log(mysql_error());
484 print_red(mysql_error());
485 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
486 }
487 }
489 }
490 @mysql_close($r_con);
491 return(false);
492 }
496 /* This function checks if the given phonenumbers are available or already in use*/
498 function is_number_used()
499 {
500 $ldap= $this->config->get_ldap_link();
501 $ldap->cd($this->config->current['BASE']);
502 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
503 while($attrs = $ldap->fetch()) {
504 unset($attrs['telephoneNumber']['count']);
505 foreach($attrs['telephoneNumber'] as $tele){
506 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
507 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
508 $numbers[$tele]=$attrs;
509 }
510 }
512 foreach($this->telephoneNumber as $num){
513 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!= $this->attrs['cn'][0]))){
514 if(isset($numbers[$num]['uid'][0])){
515 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
516 }else{
517 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
518 }
519 }
520 }
521 }
527 function save_object()
528 {
529 plugin::save_object();
530 if(isset($_POST['phonenumber'])){
531 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_r","goFonDialOption_H","goFonMusiconHold") as $val){
532 if(isset($_POST[$val])){
533 $this->$val = $_POST[$val];
534 }else{
535 $this->$val = false;
536 }
537 }
538 if(isset($_POST['goFonQueueAnnounceHoldtime'])){
539 $this->goFonQueueAnnounceHoldtime = "yes";
540 }else{
541 $this->goFonQueueAnnounceHoldtime = false;
542 }
544 }
546 }
548 function save()
549 {
550 #fixme workaround : Tab is not initialised correct
551 if(!$this->is_account) return;
552 $ldap= $this->config->get_ldap_link();
554 $this->generate_mysql_table_entries(true);
556 plugin::save();
557 $this->attrs['goFonDialOption'] = "";
558 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
559 $this->attrs['goFonDialOption'].=$this->$val;
560 unset($this->attrs[$val]);
561 }
562 if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
564 if($this->goFonQueueAnnounceHoldtime != "no" ){
565 $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
566 }else{
567 $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
568 }
570 $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
572 /* Save data to LDAP */
573 $ldap->cd($this->dn);
574 $ldap->modify($this->attrs);
576 show_ldap_error($ldap->get_error());
578 /* Optionally execute a command after we're done */
579 if ($this->initially_was_account == $this->is_account){
580 if ($this->is_modified){
581 $this->handle_post_events("mofify");
582 }
583 } else {
584 $this->handle_post_events("add");
585 }
586 }
589 /* remove object from parent */
590 function remove_from_parent()
591 {
592 $SQL = array();
594 // Get Configuration for Mysql database Server
595 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
596 $s_parameter ="";
598 // Connect to DB server
599 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
601 // Check if we are connected correctly
602 if(!$r_con){
603 gosa_log(mysql_error());
604 return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
605 $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
606 }
608 // Select database for Extensions
609 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
611 // Test if we have the database selected correctly
612 if(!$db){
613 gosa_log(mysql_error());
614 return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
615 }
617 /* Remove all temporary attributes */
618 $tmp = array_flip($this->attributes);
619 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
620 unset($this->$val);
621 unset($this->attrs[$val]);
622 unset($tmp[$val]);
623 }
624 foreach(array_flip($tmp) as $key => $val){
625 $tmp2[]=$val;
626 }
627 $this->attributes = $tmp2;
629 $i = 0;
630 $prio = 11;
632 if(empty($this->cn)){
633 $this->cn = $this->parent->by_object['ogroup']->cn;
634 $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
635 }
637 // Delete old Entries
638 $delete = array();
639 foreach($this->old_phone_numbers as $phone){
640 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
641 }
642 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$this->attrs['cn'][0]."';\n";
643 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
644 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
646 /* Perform queries to delte old entries */
647 foreach($delete as $query){
648 if(!mysql_query($query)){
649 gosa_log(mysql_error());
650 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
651 }
652 }
656 /* Cancel if there's nothing to do here */
657 if (!$this->initially_was_account){
658 return;
659 }
661 /* include global link_info */
662 $ldap= $this->config->get_ldap_link();
664 /* Remove and write to LDAP */
665 plugin::remove_from_parent();
667 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
668 $this->attributes, "Save");
669 $ldap->cd($this->dn);
670 $ldap->modify($this->attrs);
671 show_ldap_error($ldap->get_error());
672 }
674 }
676 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
677 ?>