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