960647288773089fad6fe98e9fe1fe31f0ef6d4f
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"),
114 _("For this group the phone queues are disabled. You can enable them by clicking below."));
115 return ($display);
116 }
117 }
119 /* Add queue number */
120 if(isset($_POST['add_phonenumber'])&&(isset($_POST['phonenumber']))&&(!empty($_POST['phonenumber']))){
121 if((!in_array($_POST['phonenumber'],$this->telephoneNumber))&&(is_numeric($_POST['phonenumber']))){
122 $this->telephoneNumber[]=$_POST['phonenumber'];
123 }
124 }
126 /* Delete queue number */
127 if(isset($_POST['delete_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
128 unset($this->telephoneNumber[$_POST['goFonQueueNumber_List']]);
129 }
131 $tmp = array();
132 foreach($this->telephoneNumber as $val){
133 if(!empty($val)){
134 $tmp[]= $val;
135 }
136 }
137 $this->telephoneNumber=$tmp;
139 /* queue number up */
140 if(isset($_POST['up_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
141 if($_POST['goFonQueueNumber_List']>0){
142 $up = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
143 $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1];
144 $this->telephoneNumber[$_POST['goFonQueueNumber_List']] = $down;
145 $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1] = $up;
146 }
147 }
149 /* Queuenumber down */
150 if(isset($_POST['down_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
151 if(isset($this->telephoneNumber[($_POST['goFonQueueNumber_List']+1)])){
152 $up = $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1];
153 $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
154 $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1] = $down;
155 $this->telephoneNumber[$_POST['goFonQueueNumber_List']] = $up;
156 }
157 }
159 $smarty= get_smarty();
161 $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German')));
162 $smarty->assign("goFonQueueStrategyOptions", $this->goFonQueueStrategyOptions);
164 foreach($this->attributes as $key => $val){
165 $smarty->assign($val,$this->$val);
167 if($this->$val == false){
168 $smarty->assign($val."CHK","");
169 }else{
170 $smarty->assign($val."CHK"," checked ");
171 }
173 if(chkacl($this->acl,$key)==""){
174 $smarty->assign($val."ACL","");
175 }else{
176 $smarty->assign($val."ACL"," disabled ");
177 }
178 }
179 return ($display.$smarty->fetch (get_template_path('phonequeue.tpl', TRUE)));
180 }
183 /* Check formular input */
184 function check()
185 {
186 $message= array();
187 #fixme workaround : Tab is not initialised correct
188 if(!$this->is_account) return($message);
190 if($this->is_number_used()){
191 $message[] = $this->is_number_used();
192 }
194 if($this->generate_mysql_table_entries()){
195 $message[] = $this->generate_mysql_table_entries();
196 }
198 if(!((is_numeric($this->goFonTimeOut))||(empty($this->goFonTimeOut)))){
199 $message[] = _("Timeout must be numeric");
200 }
201 if(!((is_numeric($this->goFonQueueRetry))||(empty($this->goFonQueueRetry)))){
202 $message[] = _("Retry must be numeric");
203 }
204 if(!((is_numeric($this->goFonMaxLen))||(empty($this->goFonMaxLen)))){
205 $message[] = _("Max queue length must be numeric");
206 }
207 if(!((is_numeric($this->goFonAnnounceFrequency))||(empty($this->goFonAnnounceFrequency)))){
208 $message[] = _("Announce frequency must be numeric");
209 }
210 if(count($this->telephoneNumber)==0){
211 $message[] = _("There must be least one queue number defined.");
212 }
214 return $message;
215 }
219 function generate_mysql_table_entries($save = false)
220 {
222 $SQL = array();
224 if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
225 return(_("There is currently no asterisk server defined. Your settings can't be saved."));
226 return(false);
227 }
229 // Get Configuration for Mysql database Server
230 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
231 $s_parameter ="";
233 // Connect to DB server
234 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
236 // Check if we are connected correctly
237 if(!$r_con){
238 gosa_log(mysql_error());
239 return (sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
240 $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
241 }
243 // Select database for Extensions
244 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
246 // Test if we have the database selected correctly
247 if(!$db){
248 gosa_log(mysql_error());
249 return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
250 }
252 if($save){
253 $i = 0;
254 $prio = 11;
256 $delete = array();
257 if(!empty($this->parent->by_object['ogroup'])){
258 $new_cn = $this->parent->by_object['ogroup']->cn;
259 }
260 $old_cn = $this->cn;
262 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$new_cn."';\n";
263 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name='".$new_cn."'; \n";
264 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$new_cn."';\n";
265 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$old_cn."';\n";
266 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name='".$old_cn."'; \n";
267 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$old_cn."';\n";
269 // Delete old Entries
270 if(is_array($this->old_phone_numbers)){
271 foreach($this->old_phone_numbers as $phone){
272 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
273 }
274 }
276 /* Perform queries to delte old entries */
277 foreach($delete as $query){
278 if(!mysql_query($query)){
279 gosa_log(mysql_error());
280 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
281 }
282 }
284 $this->attrs['cn'][0] = $new_cn;
286 /* Append new Member for this queue */
287 $i = 0;
288 $queueuser =array();
289 foreach($this->parent->by_object['ogroup']->memberList as $member){
290 if(isset($member['objectClass'])){
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 }
298 }
300 /* Parse and Add members to query Array */
301 if(is_array($queueuser)){
302 foreach($queueuser as $user){
303 $entries = "";
304 $values = "";
305 foreach($user as $attr => $val){
306 $entries.= "`".$attr."`,";
307 $values .= "'".$val."',";
308 }
309 $values = preg_replace("/,$/","",$values);
310 $entries = preg_replace("/,$/","",$entries );
312 $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")";
313 }
314 }
316 /* generate Extension entries, with priority */
318 $queueusers=0;
319 foreach($this->parent->by_object['ogroup']->memberList as $member){
320 if(isset($member['objectClass'])){
321 if(in_array("goFonAccount",$member['objectClass'])){
322 $queueusers++;
323 }
324 }
325 }
328 $i = 0;
330 $i_insert_only_once = false;
332 foreach($this->telephoneNumber as $num){
334 // If there are no member in a Queue
335 // Play sound an quit
337 // A Queue is not deleted directly, it is stored until the o group is deleted
339 if($i_insert_only_once == false){
340 $i_insert_only_once = true;
341 $a_ext[$i]['context'] = 'GOsa';
342 $a_ext[$i]['exten'] = $this->attrs['cn'][0];
343 $a_ext[$i]['priority'] = 1;
344 $a_ext[$i]['app'] = "Goto";
345 $a_ext[$i]['appdata'] = $num."|1";
346 $i ++ ;
347 }
349 if($queueusers == 0){
350 $a_ext[$i]['context'] = 'GOsa';
351 $a_ext[$i]['exten'] = $num;
352 $a_ext[$i]['priority'] = 1;
353 $a_ext[$i]['app'] = "SetLanguage";
354 $a_ext[$i]['appdata'] = "de";
355 $i ++ ;
357 $a_ext[$i]['context'] = 'GOsa';
358 $a_ext[$i]['exten'] = $num;
359 $a_ext[$i]['priority'] = 2;
360 $a_ext[$i]['app'] = "Playback";
361 $a_ext[$i]['appdata'] = "ss-noservice";
362 $i ++ ;
364 $a_ext[$i]['context'] = 'GOsa';
365 $a_ext[$i]['exten'] = $num;
366 $a_ext[$i]['priority'] = 3;
367 $a_ext[$i]['app'] = "Goto";
368 $a_ext[$i]['appdata'] = "default";
369 $i ++ ;
370 }else{
371 $prio --;
372 $a_ext[$i]['context'] = 'GOsa';
373 $a_ext[$i]['exten'] = $num;
374 $a_ext[$i]['priority'] = 1;
375 $a_ext[$i]['app'] = "Wait";
376 $a_ext[$i]['appdata'] = "2";
377 $i ++ ;
378 $a_ext[$i]['context'] = 'GOsa';
379 $a_ext[$i]['exten'] = $num;
380 $a_ext[$i]['priority'] = 2;
381 $a_ext[$i]['app'] = "SetLanguage";
382 $a_ext[$i]['appdata'] = $this->goFonQueueLanguage;
383 $i ++ ;
384 $a_ext[$i]['context'] = 'GOsa';
385 $a_ext[$i]['exten'] = $num;
386 $a_ext[$i]['priority'] = 3;
387 $a_ext[$i]['app'] = "Playback";
388 $a_ext[$i]['appdata'] = $this->goFonWelcomeMusic;
389 $i ++ ;
390 $a_ext[$i]['context'] = 'GOsa';
391 $a_ext[$i]['exten'] = $num;
392 $a_ext[$i]['priority'] = 4;
393 $a_ext[$i]['app'] = "SetCIDName";
394 if(!empty($this->parent->by_object['ogroup']->description)){
395 $a_ext[$i]['appdata'] = $this->parent->by_object['ogroup']->description;
396 }else{
397 $a_ext[$i]['appdata'] = $this->attrs['cn'][0]." - ".$num;
398 }
399 $i ++ ;
400 $a_ext[$i]['context'] = 'GOsa';
401 $a_ext[$i]['exten'] = $num;
402 $a_ext[$i]['priority'] = 5;
403 $a_ext[$i]['app'] = "SetVar";
404 $a_ext[$i]['appdata'] = "QUEUE_PRIO=".$prio;
405 $i ++ ;
406 $a_ext[$i]['context'] = 'GOsa';
407 $a_ext[$i]['exten'] = $num;
408 $a_ext[$i]['priority'] = 6;
409 $a_ext[$i]['app'] = "Queue";
410 $a_ext[$i]['appdata'] = $this->attrs['cn'][0].
411 "|".
412 $this->goFonDialOption_t.
413 $this->goFonDialOption_T.
414 $this->goFonDialOption_h.
415 $this->goFonDialOption_H.
416 $this->goFonDialOption_r;
417 }
419 if($this->goFonQueueAnnounceHoldtime != false) {
420 $this->goFonQueueAnnounceHoldtime = "yes";
421 }else{
422 $this->goFonQueueAnnounceHoldtime = "no";
423 }
426 /* Generate Priority Entry */
427 $queue["announce"] = "";
428 $queue["monitor_join"] = "";
429 $queue["monitor_format"] = "";
430 $queue["queue_holdtime"] = $this->goFonQueueAnnounce;
431 $queue["queue_lessthan"] = $this->goFonQueueLessThan;
432 $queue["announce_round_seconds"]= "";
433 $queue["retry"] = $this->goFonQueueRetry;
434 $queue["wrapuptime"] = "";
435 $queue["servicelevel"] = "";
436 $queue["joinempty"] = "no";
437 $queue["leavewhenempty"] = "yes";
438 $queue["eventmemberstatus"] = "";
439 $queue["eventwhencalled"] = "";
440 $queue["reportholdtime"] = "yes";
441 $queue["memberdelay"] = "";
442 $queue["weight"] = "";
443 $queue["timeoutrestart"] = "";
445 $queue["context"] = "default";
446 $queue["name"] = $this->attrs['cn'][0];
447 $queue["timeout"] = $this->goFonTimeOut;
448 $queue["maxlen"] = $this->goFonMaxLen;
449 $queue["strategy" ] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
450 $queue["queue_thankyou"] = $this->goFonQueueThankYou;
451 $queue["queue_reporthold"] = $this->goFonQueueReportHold;
452 $queue["announce_frequency"] = $this->goFonAnnounceFrequency;
453 $queue["queue_youarenext"] = $this->goFonQueueYouAreNext;
454 $queue["queue_thereare"] = $this->goFonQueueThereAre;
455 $queue["queue_callswaiting"] = $this->goFonQueueCallsWaiting;
456 $queue["queue_minutes"] = $this->goFonQueueMinutes;
457 $queue["queue_seconds"] = $this->goFonQueueSeconds;
458 $queue["announce_holdtime"] = $this->goFonQueueAnnounceHoldtime;
459 $queue["musiconhold"] = $this->goFonMusiconHold;
461 $i++;
462 }
464 /* Parse and Add Extension entries */
465 foreach($a_ext as $ext){
466 $entries = "";
467 $values = "";
468 foreach($ext as $attr => $val){
469 $entries.= "`".$attr."`,";
470 $values .= "'".$val."',";
471 }
472 $values = preg_replace("/,$/","",$values);
473 $entries = preg_replace("/,$/","",$entries );
474 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
475 }
478 /* Parse and Add Queue */
479 $entries = "";
480 $values = "";
481 foreach($queue as $attr=>$val){
482 if($val == "") continue;
483 $entries.= "`".$attr."`,";
484 $values .= "'".$val."',";
485 }
486 $values = preg_replace("/,$/","",$values);
487 $entries = preg_replace("/,$/","",$entries );
488 $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
490 foreach($SQL as $query){
491 if(!mysql_query($query)){
492 gosa_log(mysql_error());
493 print_red(mysql_error());
494 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
495 }
496 }
498 }
499 @mysql_close($r_con);
500 return(false);
501 }
505 /* This function checks if the given phonenumbers are available or already in use*/
507 function is_number_used()
508 {
509 $ldap= $this->config->get_ldap_link();
510 $ldap->cd($this->config->current['BASE']);
511 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
512 while($attrs = $ldap->fetch()) {
513 unset($attrs['telephoneNumber']['count']);
514 foreach($attrs['telephoneNumber'] as $tele){
515 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
516 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
517 $numbers[$tele]=$attrs;
518 }
519 }
521 foreach($this->telephoneNumber as $num){
522 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!= $this->attrs['cn'][0]))){
523 if(isset($numbers[$num]['uid'][0])){
524 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
525 }else{
526 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
527 }
528 }
529 }
530 }
536 function save_object()
537 {
538 plugin::save_object();
539 if(isset($_POST['phonenumber'])){
540 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_r","goFonDialOption_H","goFonMusiconHold") as $val){
541 if(isset($_POST[$val])){
542 $this->$val = $_POST[$val];
543 }else{
544 $this->$val = false;
545 }
546 }
547 if(isset($_POST['goFonQueueAnnounceHoldtime'])){
548 $this->goFonQueueAnnounceHoldtime = "yes";
549 }else{
550 $this->goFonQueueAnnounceHoldtime = false;
551 }
553 }
555 }
557 function save()
558 {
559 #fixme workaround : Tab is not initialised correct
560 if(!$this->is_account) return;
561 $ldap= $this->config->get_ldap_link();
563 $this->generate_mysql_table_entries(true);
565 plugin::save();
566 $this->attrs['goFonDialOption'] = "";
567 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
568 $this->attrs['goFonDialOption'].=$this->$val;
569 unset($this->attrs[$val]);
570 }
571 if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
573 if($this->goFonQueueAnnounceHoldtime != "no" ){
574 $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
575 }else{
576 $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
577 }
579 $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
581 /* Save data to LDAP */
582 $ldap->cd($this->dn);
583 $ldap->modify($this->attrs);
585 show_ldap_error($ldap->get_error());
587 /* Optionally execute a command after we're done */
588 if ($this->initially_was_account == $this->is_account){
589 if ($this->is_modified){
590 $this->handle_post_events("mofify");
591 }
592 } else {
593 $this->handle_post_events("add");
594 }
595 }
598 /* remove object from parent */
599 function remove_from_parent()
600 {
601 $SQL = array();
603 // Get Configuration for Mysql database Server
604 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
605 $s_parameter ="";
607 // Connect to DB server
608 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
610 // Check if we are connected correctly
611 if(!$r_con){
612 gosa_log(mysql_error());
613 return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
614 $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
615 }
617 // Select database for Extensions
618 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
620 // Test if we have the database selected correctly
621 if(!$db){
622 gosa_log(mysql_error());
623 return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
624 }
626 /* Remove all temporary attributes */
627 $tmp = array_flip($this->attributes);
628 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
629 unset($this->$val);
630 unset($this->attrs[$val]);
631 unset($tmp[$val]);
632 }
633 foreach(array_flip($tmp) as $key => $val){
634 $tmp2[]=$val;
635 }
636 $this->attributes = $tmp2;
638 $i = 0;
639 $prio = 11;
641 if(empty($this->cn)){
642 $this->cn = $this->parent->by_object['ogroup']->cn;
643 $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
644 }
646 // Delete old Entries
647 $delete = array();
648 foreach($this->old_phone_numbers as $phone){
649 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
650 }
651 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$this->attrs['cn'][0]."';\n";
652 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
653 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
655 /* Perform queries to delte old entries */
656 foreach($delete as $query){
657 if(!mysql_query($query)){
658 gosa_log(mysql_error());
659 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
660 }
661 }
665 /* Cancel if there's nothing to do here */
666 if (!$this->initially_was_account){
667 return;
668 }
670 /* include global link_info */
671 $ldap= $this->config->get_ldap_link();
673 /* Remove and write to LDAP */
674 plugin::remove_from_parent();
676 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
677 $this->attributes, "Save");
678 $ldap->cd($this->dn);
679 $ldap->modify($this->attrs);
680 show_ldap_error($ldap->get_error());
681 }
683 }
685 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
686 ?>