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