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