058cddade033c248d50af03d5d406aaf4aedeaf7
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 // Get Configuration for Mysql database Server
224 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
225 $s_parameter ="";
227 // Connect to DB server
228 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
230 // Check if we are connected correctly
231 if(!$r_con){
232 gosa_log(mysql_error());
233 return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
234 $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
235 }
237 // Select database for Extensions
238 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
240 // Test if we have the database selected correctly
241 if(!$db){
242 gosa_log(mysql_error());
243 return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
244 }
246 if($save){
247 $i = 0;
248 $prio = 11;
250 $delete = array();
251 if(!empty($this->parent->by_object['ogroup'])){
252 $new_cn = $this->parent->by_object['ogroup']->cn;
253 }
254 $old_cn = $this->cn;
256 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$new_cn."';\n";
257 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name='".$new_cn."'; \n";
258 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$new_cn."';\n";
259 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$old_cn."';\n";
260 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name='".$old_cn."'; \n";
261 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$old_cn."';\n";
263 // Delete old Entries
264 if(is_array($this->old_phone_numbers)){
265 foreach($this->old_phone_numbers as $phone){
266 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
267 }
268 }
270 /* Perform queries to delte old entries */
271 foreach($delete as $query){
272 if(!mysql_query($query)){
273 gosa_log(mysql_error());
274 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
275 }
276 }
278 $this->attrs['cn'][0] = $new_cn;
280 /* Append new Member for this queue */
281 $i = 0;
282 $queueuser =array();
283 foreach($this->parent->by_object['ogroup']->memberList as $member){
284 if(in_array("goFonAccount",$member['objectClass'])){
285 $i ++ ;
286 $queueuser[$i]['queue_name'] = $this->attrs['cn'][0];
287 $queueuser[$i]['interface'] = "SIP/".$member['uid'][0];
288 $queueuser[$i]['penalty'] = 1;
289 }
290 }
292 /* Parse and Add members to query Array */
293 if(is_array($queueuser)){
294 foreach($queueuser as $user){
295 $entries = "";
296 $values = "";
297 foreach($user as $attr => $val){
298 $entries.= "`".$attr."`,";
299 $values .= "'".$val."',";
300 }
301 $values = preg_replace("/,$/","",$values);
302 $entries = preg_replace("/,$/","",$entries );
304 $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")";
305 }
306 }
308 /* generate Extension entries, with priority */
310 $queueusers=0;
311 foreach($this->parent->by_object['ogroup']->memberList as $member){
312 if(in_array("goFonAccount",$member['objectClass'])){
313 $queueusers++;
314 }
315 }
318 $i = 0;
319 foreach($this->telephoneNumber as $num){
321 // If there are no member in a Queue
322 // Play sound an quit
324 // A Queue is not deleted directly, it is stored until the o group is deleted
326 $a_ext[$i]['context'] = 'GOsa';
327 $a_ext[$i]['exten'] = $this->attrs['cn'][0];
328 $a_ext[$i]['priority'] = 1;
329 $a_ext[$i]['app'] = "Goto";
330 $a_ext[$i]['appdata'] = $num."|1";
331 $i ++ ;
333 if($queueusers == 0){
334 $a_ext[$i]['context'] = 'GOsa';
335 $a_ext[$i]['exten'] = $num;
336 $a_ext[$i]['priority'] = 1;
337 $a_ext[$i]['app'] = "SetLanguage";
338 $a_ext[$i]['appdata'] = "de";
339 $i ++ ;
341 $a_ext[$i]['context'] = 'GOsa';
342 $a_ext[$i]['exten'] = $num;
343 $a_ext[$i]['priority'] = 2;
344 $a_ext[$i]['app'] = "Playback";
345 $a_ext[$i]['appdata'] = "ss-noservice";
346 $i ++ ;
348 $a_ext[$i]['context'] = 'GOsa';
349 $a_ext[$i]['exten'] = $num;
350 $a_ext[$i]['priority'] = 3;
351 $a_ext[$i]['app'] = "Goto";
352 $a_ext[$i]['appdata'] = "default";
353 $i ++ ;
354 }else{
355 $prio --;
356 $a_ext[$i]['context'] = 'GOsa';
357 $a_ext[$i]['exten'] = $num;
358 $a_ext[$i]['priority'] = 1;
359 $a_ext[$i]['app'] = "Wait";
360 $a_ext[$i]['appdata'] = "2";
361 $i ++ ;
362 $a_ext[$i]['context'] = 'GOsa';
363 $a_ext[$i]['exten'] = $num;
364 $a_ext[$i]['priority'] = 2;
365 $a_ext[$i]['app'] = "SetLanguage";
366 $a_ext[$i]['appdata'] = $this->goFonQueueLanguage;
367 $i ++ ;
368 $a_ext[$i]['context'] = 'GOsa';
369 $a_ext[$i]['exten'] = $num;
370 $a_ext[$i]['priority'] = 3;
371 $a_ext[$i]['app'] = "Playback";
372 $a_ext[$i]['appdata'] = $this->goFonWelcomeMusic;
373 $i ++ ;
374 $a_ext[$i]['context'] = 'GOsa';
375 $a_ext[$i]['exten'] = $num;
376 $a_ext[$i]['priority'] = 4;
377 $a_ext[$i]['app'] = "SetCIDName";
378 if(!empty($this->parent->by_object['ogroup']->description)){
379 $a_ext[$i]['appdata'] = $this->parent->by_object['ogroup']->description;
380 }else{
381 $a_ext[$i]['appdata'] = $this->attrs['cn'][0]." - ".$num;
382 }
383 $i ++ ;
384 $a_ext[$i]['context'] = 'GOsa';
385 $a_ext[$i]['exten'] = $num;
386 $a_ext[$i]['priority'] = 5;
387 $a_ext[$i]['app'] = "SetVar";
388 $a_ext[$i]['appdata'] = "QUEUE_PRIO=".$prio;
389 $i ++ ;
390 $a_ext[$i]['context'] = 'GOsa';
391 $a_ext[$i]['exten'] = $num;
392 $a_ext[$i]['priority'] = 6;
393 $a_ext[$i]['app'] = "Queue";
394 $a_ext[$i]['appdata'] = $this->attrs['cn'][0].
395 "|".
396 $this->goFonDialOption_t.
397 $this->goFonDialOption_T.
398 $this->goFonDialOption_h.
399 $this->goFonDialOption_H.
400 $this->goFonDialOption_r;
401 }
403 if($this->goFonQueueAnnounceHoldtime != false) {
404 $this->goFonQueueAnnounceHoldtime = "yes";
405 }else{
406 $this->goFonQueueAnnounceHoldtime = "no";
407 }
410 /* Generate Priority Entry */
411 $queue["announce"] = "";
412 $queue["monitor_join"] = "";
413 $queue["monitor_format"] = "";
414 $queue["queue_holdtime"] = $this->goFonQueueAnnounce;
415 $queue["queue_lessthan"] = $this->goFonQueueLessThan;
416 $queue["announce_round_seconds"]= "";
417 $queue["retry"] = $this->goFonQueueRetry;
418 $queue["wrapuptime"] = "";
419 $queue["servicelevel"] = "";
420 $queue["joinempty"] = "no";
421 $queue["leavewhenempty"] = "yes";
422 $queue["eventmemberstatus"] = "";
423 $queue["eventwhencalled"] = "";
424 $queue["reportholdtime"] = "yes";
425 $queue["memberdelay"] = "";
426 $queue["weight"] = "";
427 $queue["timeoutrestart"] = "";
429 $queue["context"] = "default";
430 $queue["name"] = $this->attrs['cn'][0];
431 $queue["timeout"] = $this->goFonTimeOut;
432 $queue["maxlen"] = $this->goFonMaxLen;
433 $queue["strategy" ] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
434 $queue["queue_thankyou"] = $this->goFonQueueThankYou;
435 $queue["queue_reporthold"] = $this->goFonQueueReportHold;
436 $queue["announce_frequency"] = $this->goFonAnnounceFrequency;
437 $queue["queue_youarenext"] = $this->goFonQueueYouAreNext;
438 $queue["queue_thereare"] = $this->goFonQueueThereAre;
439 $queue["queue_callswaiting"] = $this->goFonQueueCallsWaiting;
440 $queue["queue_minutes"] = $this->goFonQueueMinutes;
441 $queue["queue_seconds"] = $this->goFonQueueSeconds;
442 $queue["announce_holdtime"] = $this->goFonQueueAnnounceHoldtime;
443 $queue["musiconhold"] = $this->goFonMusiconHold;
445 $i++;
446 }
448 /* Parse and Add Extension entries */
449 foreach($a_ext as $ext){
450 $entries = "";
451 $values = "";
452 foreach($ext as $attr => $val){
453 $entries.= "`".$attr."`,";
454 $values .= "'".$val."',";
455 }
456 $values = preg_replace("/,$/","",$values);
457 $entries = preg_replace("/,$/","",$entries );
458 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
459 }
462 /* Parse and Add Queue */
463 $entries = "";
464 $values = "";
465 foreach($queue as $attr=>$val){
466 if($val == "") continue;
467 $entries.= "`".$attr."`,";
468 $values .= "'".$val."',";
469 }
470 $values = preg_replace("/,$/","",$values);
471 $entries = preg_replace("/,$/","",$entries );
472 $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
474 foreach($SQL as $query){
475 if(!mysql_query($query)){
476 gosa_log(mysql_error());
477 print_red(mysql_error());
478 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
479 }
480 }
482 }
483 @mysql_close($r_con);
484 return(false);
485 }
489 /* This function checks if the given phonenumbers are available or already in use*/
491 function is_number_used()
492 {
493 $ldap= $this->config->get_ldap_link();
494 $ldap->cd($this->config->current['BASE']);
495 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
496 while($attrs = $ldap->fetch()) {
497 unset($attrs['telephoneNumber']['count']);
498 foreach($attrs['telephoneNumber'] as $tele){
499 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
500 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
501 $numbers[$tele]=$attrs;
502 }
503 }
505 foreach($this->telephoneNumber as $num){
506 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!= $this->attrs['cn'][0]))){
507 if(isset($numbers[$num]['uid'][0])){
508 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
509 }else{
510 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
511 }
512 }
513 }
514 }
520 function save_object()
521 {
522 plugin::save_object();
523 if(isset($_POST['phonenumber'])){
524 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_r","goFonDialOption_H","goFonMusiconHold") as $val){
525 if(isset($_POST[$val])){
526 $this->$val = $_POST[$val];
527 }else{
528 $this->$val = false;
529 }
530 }
531 if(isset($_POST['goFonQueueAnnounceHoldtime'])){
532 $this->goFonQueueAnnounceHoldtime = "yes";
533 }else{
534 $this->goFonQueueAnnounceHoldtime = false;
535 }
537 }
539 }
541 function save()
542 {
543 #fixme workaround : Tab is not initialised correct
544 if(!$this->is_account) return;
545 $ldap= $this->config->get_ldap_link();
547 $this->generate_mysql_table_entries(true);
549 plugin::save();
550 $this->attrs['goFonDialOption'] = "";
551 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
552 $this->attrs['goFonDialOption'].=$this->$val;
553 unset($this->attrs[$val]);
554 }
555 if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
557 if($this->goFonQueueAnnounceHoldtime != "no" ){
558 $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
559 }else{
560 $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
561 }
563 $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
565 /* Save data to LDAP */
566 $ldap->cd($this->dn);
567 $ldap->modify($this->attrs);
569 show_ldap_error($ldap->get_error());
571 /* Optionally execute a command after we're done */
572 if ($this->initially_was_account == $this->is_account){
573 if ($this->is_modified){
574 $this->handle_post_events("mofify");
575 }
576 } else {
577 $this->handle_post_events("add");
578 }
579 }
582 /* remove object from parent */
583 function remove_from_parent()
584 {
585 $SQL = array();
587 // Get Configuration for Mysql database Server
588 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
589 $s_parameter ="";
591 // Connect to DB server
592 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
594 // Check if we are connected correctly
595 if(!$r_con){
596 gosa_log(mysql_error());
597 return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
598 $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
599 }
601 // Select database for Extensions
602 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
604 // Test if we have the database selected correctly
605 if(!$db){
606 gosa_log(mysql_error());
607 return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
608 }
610 /* Remove all temporary attributes */
611 $tmp = array_flip($this->attributes);
612 foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
613 unset($this->$val);
614 unset($this->attrs[$val]);
615 unset($tmp[$val]);
616 }
617 foreach(array_flip($tmp) as $key => $val){
618 $tmp2[]=$val;
619 }
620 $this->attributes = $tmp2;
622 $i = 0;
623 $prio = 11;
625 if(empty($this->cn)){
626 $this->cn = $this->parent->by_object['ogroup']->cn;
627 $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
628 }
630 // Delete old Entries
631 $delete = array();
632 foreach($this->old_phone_numbers as $phone){
633 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
634 }
635 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$this->attrs['cn'][0]."';\n";
636 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
637 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
639 /* Perform queries to delte old entries */
640 foreach($delete as $query){
641 if(!mysql_query($query)){
642 gosa_log(mysql_error());
643 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
644 }
645 }
649 /* Cancel if there's nothing to do here */
650 if (!$this->initially_was_account){
651 return;
652 }
654 /* include global link_info */
655 $ldap= $this->config->get_ldap_link();
657 /* Remove and write to LDAP */
658 plugin::remove_from_parent();
660 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
661 $this->attributes, "Save");
662 $ldap->cd($this->dn);
663 $ldap->modify($this->attrs);
664 show_ldap_error($ldap->get_error());
665 }
667 }
669 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
670 ?>