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 $goFonDialOptiont ="";
14 var $goFonDialOptionT ="";
15 var $goFonDialOptionh ="";
16 var $goFonDialOptionr ="";
17 var $goFonQueueAnnounce ="gonicus-berlin-welcome";
18 var $goFonDialOptionH ="";
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","goFonDialOptiont","goFonDialOptionT",
45 "goFonDialOptionh","goFonDialOptionr","cn",
46 "goFonDialOptionH","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 if($this->is_account && $this->acl_is_removeable()){
108 $this->is_account= FALSE;
109 }elseif(!$this->is_account && $this->acl_is_createable()){
110 $this->is_account= TRUE;
111 }
112 }
114 /* Show tab dialog headers */
115 if ($this->parent != NULL){
116 if ($this->is_account){
117 $display= $this->show_disable_header(_("Remove the phone queue from this Account"),
118 _("Phone queue is enabled for this group. You can disable it by clicking below."));
119 } else {
120 $display= $this->show_enable_header(_("Create phone queue"),
121 _("For this group the phone queues are disabled. You can enable them by clicking below."));
122 return ($display);
123 }
124 }
126 /* Add queue number */
127 if($this->acl_is_writeable("telephoneNumber")){
128 if(isset($_POST['add_phonenumber'])&&(isset($_POST['phonenumber']))&&(!empty($_POST['phonenumber']))){
129 if((!in_array($_POST['phonenumber'],$this->telephoneNumber))&&(is_numeric($_POST['phonenumber']))){
130 $this->telephoneNumber[]=$_POST['phonenumber'];
131 }
132 }
133 }
135 /* Delete queue number */
136 if($this->acl_is_writeable("telephoneNumber")){
137 if(isset($_POST['delete_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
138 unset($this->telephoneNumber[$_POST['goFonQueueNumber_List']]);
139 }
140 }
142 $tmp = array();
143 foreach($this->telephoneNumber as $val){
144 if(!empty($val)){
145 $tmp[]= $val;
146 }
147 }
148 $this->telephoneNumber=$tmp;
150 /* queue number up */
151 if($this->acl_is_writeable("telephoneNumber")){
152 if(isset($_POST['up_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
153 if($_POST['goFonQueueNumber_List']>0){
154 $up = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
155 $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1];
156 $this->telephoneNumber[$_POST['goFonQueueNumber_List']] = $down;
157 $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1] = $up;
158 }
159 }
161 /* Queuenumber down */
162 if(isset($_POST['down_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
163 if(isset($this->telephoneNumber[($_POST['goFonQueueNumber_List']+1)])){
164 $up = $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1];
165 $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
166 $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1] = $down;
167 $this->telephoneNumber[$_POST['goFonQueueNumber_List']] = $up;
168 }
169 }
170 }
172 $smarty= get_smarty();
174 /* Set acls */
175 $tmp = $this->plInfo();
176 foreach($tmp['plProvidedAcls'] as $name => $translated){
177 $smarty->assign($name."ACL",$this->getacl($name));
178 }
180 $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German')));
181 $smarty->assign("goFonQueueStrategyOptions", $this->goFonQueueStrategyOptions);
183 foreach($this->attributes as $key => $val){
184 $smarty->assign($val,$this->$val);
186 if($this->$val == false){
187 $smarty->assign($val."CHK","");
188 }else{
189 $smarty->assign($val."CHK"," checked ");
190 }
191 }
192 return ($display.$smarty->fetch (get_template_path('phonequeue.tpl', TRUE)));
193 }
196 /* Check formular input */
197 function check()
198 {
199 /* Call common method to give check the hook */
200 $message= plugin::check();
202 if($this->is_number_used()){
203 $message[] = $this->is_number_used();
204 }
206 if($this->generate_mysql_table_entries()){
207 $message[] = $this->generate_mysql_table_entries();
208 }
210 if(!((is_numeric($this->goFonTimeOut))||(empty($this->goFonTimeOut)))){
211 $message[] = _("Timeout must be numeric");
212 }
213 if(!((is_numeric($this->goFonQueueRetry))||(empty($this->goFonQueueRetry)))){
214 $message[] = _("Retry must be numeric");
215 }
216 if(!((is_numeric($this->goFonMaxLen))||(empty($this->goFonMaxLen)))){
217 $message[] = _("Max queue length must be numeric");
218 }
219 if(!((is_numeric($this->goFonAnnounceFrequency))||(empty($this->goFonAnnounceFrequency)))){
220 $message[] = _("Announce frequency must be numeric");
221 }
222 if(count($this->telephoneNumber)==0){
223 $message[] = _("There must be least one queue number defined.");
224 }
226 return $message;
227 }
231 function generate_mysql_table_entries($save = false)
232 {
234 $SQL = array();
236 if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
237 return(_("There is currently no asterisk server defined. Your settings can't be saved."));
238 }
240 // Get Configuration for Mysql database Server
241 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
242 $s_parameter ="";
244 // Connect to DB server
245 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
247 // Check if we are connected correctly
248 if(!$r_con){
249 gosa_log(mysql_error());
250 return (sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
251 $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
252 }
254 // Select database for Extensions
255 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
257 // Test if we have the database selected correctly
258 if(!$db){
259 gosa_log(mysql_error());
260 return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
261 }
263 if($save){
264 $i = 0;
265 $prio = 11;
267 $delete = array();
268 if(!empty($this->parent->by_object['ogroup'])){
269 $new_cn = $this->parent->by_object['ogroup']->cn;
270 }
271 $old_cn = $this->cn;
273 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$new_cn."';\n";
274 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name='".$new_cn."'; \n";
275 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$new_cn."';\n";
276 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$old_cn."';\n";
277 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name='".$old_cn."'; \n";
278 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$old_cn."';\n";
280 // Delete old Entries
281 if(is_array($this->old_phone_numbers)){
282 foreach($this->old_phone_numbers as $phone){
283 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
284 }
285 }
287 /* Perform queries to delte old entries */
288 foreach($delete as $query){
289 if(!mysql_query($query)){
290 gosa_log(mysql_error());
291 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
292 }
293 }
295 $this->attrs['cn'][0] = $new_cn;
297 /* Append new Member for this queue */
298 $i = 0;
299 $queueuser =array();
300 foreach($this->parent->by_object['ogroup']->memberList as $member){
301 if(isset($member['objectClass'])){
302 if(in_array("goFonAccount",$member['objectClass'])){
303 $i ++ ;
304 $queueuser[$i]['queue_name'] = $this->attrs['cn'][0];
305 $queueuser[$i]['interface'] = "SIP/".$member['uid'][0];
306 $queueuser[$i]['penalty'] = 1;
307 }
308 }
309 }
311 /* Parse and Add members to query Array */
312 if(is_array($queueuser)){
313 foreach($queueuser as $user){
314 $entries = "";
315 $values = "";
316 foreach($user as $attr => $val){
317 $entries.= "`".$attr."`,";
318 $values .= "'".$val."',";
319 }
320 $values = preg_replace("/,$/","",$values);
321 $entries = preg_replace("/,$/","",$entries );
323 $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")";
324 }
325 }
327 /* generate Extension entries, with priority */
329 $queueusers=0;
330 foreach($this->parent->by_object['ogroup']->memberList as $member){
331 if(isset($member['objectClass'])){
332 if(in_array("goFonAccount",$member['objectClass'])){
333 $queueusers++;
334 }
335 }
336 }
339 $i = 0;
341 $i_insert_only_once = false;
343 foreach($this->telephoneNumber as $num){
345 // If there are no member in a Queue
346 // Play sound an quit
348 // A Queue is not deleted directly, it is stored until the o group is deleted
350 if($i_insert_only_once == false){
351 $i_insert_only_once = true;
352 $a_ext[$i]['context'] = 'GOsa';
353 $a_ext[$i]['exten'] = $this->attrs['cn'][0];
354 $a_ext[$i]['priority'] = 1;
355 $a_ext[$i]['app'] = "Goto";
356 $a_ext[$i]['appdata'] = $num."|1";
357 $i ++ ;
358 }
360 if($queueusers == 0){
361 $a_ext[$i]['context'] = 'GOsa';
362 $a_ext[$i]['exten'] = $num;
363 $a_ext[$i]['priority'] = 1;
364 $a_ext[$i]['app'] = "SetLanguage";
365 $a_ext[$i]['appdata'] = "de";
366 $i ++ ;
368 $a_ext[$i]['context'] = 'GOsa';
369 $a_ext[$i]['exten'] = $num;
370 $a_ext[$i]['priority'] = 2;
371 $a_ext[$i]['app'] = "Playback";
372 $a_ext[$i]['appdata'] = "ss-noservice";
373 $i ++ ;
375 $a_ext[$i]['context'] = 'GOsa';
376 $a_ext[$i]['exten'] = $num;
377 $a_ext[$i]['priority'] = 3;
378 $a_ext[$i]['app'] = "Goto";
379 $a_ext[$i]['appdata'] = "default";
380 $i ++ ;
381 }else{
382 $prio --;
383 $a_ext[$i]['context'] = 'GOsa';
384 $a_ext[$i]['exten'] = $num;
385 $a_ext[$i]['priority'] = 1;
386 $a_ext[$i]['app'] = "Wait";
387 $a_ext[$i]['appdata'] = "2";
388 $i ++ ;
389 $a_ext[$i]['context'] = 'GOsa';
390 $a_ext[$i]['exten'] = $num;
391 $a_ext[$i]['priority'] = 2;
392 $a_ext[$i]['app'] = "SetLanguage";
393 $a_ext[$i]['appdata'] = $this->goFonQueueLanguage;
394 $i ++ ;
395 $a_ext[$i]['context'] = 'GOsa';
396 $a_ext[$i]['exten'] = $num;
397 $a_ext[$i]['priority'] = 3;
398 $a_ext[$i]['app'] = "Playback";
399 $a_ext[$i]['appdata'] = $this->goFonWelcomeMusic;
400 $i ++ ;
401 $a_ext[$i]['context'] = 'GOsa';
402 $a_ext[$i]['exten'] = $num;
403 $a_ext[$i]['priority'] = 4;
404 $a_ext[$i]['app'] = "SetCIDName";
405 if(!empty($this->parent->by_object['ogroup']->description)){
406 $a_ext[$i]['appdata'] = $this->parent->by_object['ogroup']->description;
407 }else{
408 $a_ext[$i]['appdata'] = $this->attrs['cn'][0]." - ".$num;
409 }
410 $i ++ ;
411 $a_ext[$i]['context'] = 'GOsa';
412 $a_ext[$i]['exten'] = $num;
413 $a_ext[$i]['priority'] = 5;
414 $a_ext[$i]['app'] = "SetVar";
415 $a_ext[$i]['appdata'] = "QUEUE_PRIO=".$prio;
416 $i ++ ;
417 $a_ext[$i]['context'] = 'GOsa';
418 $a_ext[$i]['exten'] = $num;
419 $a_ext[$i]['priority'] = 6;
420 $a_ext[$i]['app'] = "Queue";
421 $a_ext[$i]['appdata'] = $this->attrs['cn'][0].
422 "|".
423 $this->goFonDialOptiont.
424 $this->goFonDialOptionT.
425 $this->goFonDialOptionh.
426 $this->goFonDialOptionH.
427 $this->goFonDialOptionr;
428 }
430 if($this->goFonQueueAnnounceHoldtime != false) {
431 $this->goFonQueueAnnounceHoldtime = "yes";
432 }else{
433 $this->goFonQueueAnnounceHoldtime = "no";
434 }
437 /* Generate Priority Entry */
438 $queue["announce"] = "";
439 $queue["monitor_join"] = "";
440 $queue["monitor_format"] = "";
441 $queue["queue_holdtime"] = $this->goFonQueueAnnounce;
442 $queue["queue_lessthan"] = $this->goFonQueueLessThan;
443 $queue["announce_round_seconds"]= "";
444 $queue["retry"] = $this->goFonQueueRetry;
445 $queue["wrapuptime"] = "";
446 $queue["servicelevel"] = "";
447 $queue["joinempty"] = "no";
448 $queue["leavewhenempty"] = "yes";
449 $queue["eventmemberstatus"] = "";
450 $queue["eventwhencalled"] = "";
451 $queue["reportholdtime"] = "yes";
452 $queue["memberdelay"] = "";
453 $queue["weight"] = "";
454 $queue["timeoutrestart"] = "";
456 $queue["context"] = "default";
457 $queue["name"] = $this->attrs['cn'][0];
458 $queue["timeout"] = $this->goFonTimeOut;
459 $queue["maxlen"] = $this->goFonMaxLen;
460 $queue["strategy" ] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
461 $queue["queue_thankyou"] = $this->goFonQueueThankYou;
462 $queue["queue_reporthold"] = $this->goFonQueueReportHold;
463 $queue["announce_frequency"] = $this->goFonAnnounceFrequency;
464 $queue["queue_youarenext"] = $this->goFonQueueYouAreNext;
465 $queue["queue_thereare"] = $this->goFonQueueThereAre;
466 $queue["queue_callswaiting"] = $this->goFonQueueCallsWaiting;
467 $queue["queue_minutes"] = $this->goFonQueueMinutes;
468 $queue["queue_seconds"] = $this->goFonQueueSeconds;
469 $queue["announce_holdtime"] = $this->goFonQueueAnnounceHoldtime;
470 $queue["musiconhold"] = $this->goFonMusiconHold;
472 $i++;
473 }
475 /* Parse and Add Extension entries */
476 foreach($a_ext as $ext){
477 $entries = "";
478 $values = "";
479 foreach($ext as $attr => $val){
480 $entries.= "`".$attr."`,";
481 $values .= "'".$val."',";
482 }
483 $values = preg_replace("/,$/","",$values);
484 $entries = preg_replace("/,$/","",$entries );
485 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
486 }
489 /* Parse and Add Queue */
490 $entries = "";
491 $values = "";
492 foreach($queue as $attr=>$val){
493 if($val == "") continue;
494 $entries.= "`".$attr."`,";
495 $values .= "'".$val."',";
496 }
497 $values = preg_replace("/,$/","",$values);
498 $entries = preg_replace("/,$/","",$entries );
499 $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
501 foreach($SQL as $query){
502 if(!mysql_query($query)){
503 gosa_log(mysql_error());
504 print_red(mysql_error());
505 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
506 }
507 }
509 }
510 @mysql_close($r_con);
511 return(false);
512 }
516 /* This function checks if the given phonenumbers are available or already in use*/
518 function is_number_used()
519 {
520 $ldap= $this->config->get_ldap_link();
521 $ldap->cd($this->config->current['BASE']);
522 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
523 while($attrs = $ldap->fetch()) {
524 unset($attrs['telephoneNumber']['count']);
525 foreach($attrs['telephoneNumber'] as $tele){
526 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
527 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
528 $numbers[$tele]=$attrs;
529 }
530 }
532 foreach($this->telephoneNumber as $num){
533 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!= $this->attrs['cn'][0]))){
534 if(isset($numbers[$num]['uid'][0])){
535 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
536 }else{
537 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
538 }
539 }
540 }
541 }
547 function save_object()
548 {
549 plugin::save_object();
550 if(isset($_POST['phonenumber'])){
551 foreach(array("goFonDialOptiont","goFonDialOptionT","goFonDialOptionh","goFonDialOptionr","goFonDialOptionH","goFonMusiconHold") as $val){
552 if(isset($_POST[$val])){
553 $this->$val = $_POST[$val];
554 }else{
555 $this->$val = false;
556 }
557 }
558 if(isset($_POST['goFonQueueAnnounceHoldtime'])){
559 $this->goFonQueueAnnounceHoldtime = "yes";
560 }else{
561 $this->goFonQueueAnnounceHoldtime = false;
562 }
564 }
566 }
568 function save()
569 {
570 #fixme workaround : Tab is not initialised correct
571 if(!$this->is_account) return;
572 $ldap= $this->config->get_ldap_link();
574 $this->generate_mysql_table_entries(true);
576 plugin::save();
577 $this->attrs['goFonDialOption'] = "";
578 foreach(array("goFonDialOptiont","goFonDialOptionT","goFonDialOptionr","goFonDialOptionh","goFonDialOptionH","cn") as $val){
579 $this->attrs['goFonDialOption'].=$this->$val;
580 unset($this->attrs[$val]);
581 }
582 if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
584 if($this->goFonQueueAnnounceHoldtime != "no" ){
585 $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
586 }else{
587 $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
588 }
590 $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
592 /* Save data to LDAP */
593 $ldap->cd($this->dn);
594 $this->cleanup();
595 $ldap->modify ($this->attrs);
597 show_ldap_error($ldap->get_error(), sprintf(_("Saving of object group/phone queue with dn '%s' failed."),$this->dn));
599 /* Optionally execute a command after we're done */
600 if ($this->initially_was_account == $this->is_account){
601 if ($this->is_modified){
602 $this->handle_post_events("mofify");
603 }
604 } else {
605 $this->handle_post_events("add");
606 }
607 }
610 /* remove object from parent */
611 function remove_from_parent()
612 {
613 $SQL = array();
615 // Get Configuration for Mysql database Server
616 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
617 $s_parameter ="";
619 // Connect to DB server
620 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
622 // Check if we are connected correctly
623 if(!$r_con){
624 gosa_log(mysql_error());
625 return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
626 $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
627 }
629 // Select database for Extensions
630 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
632 // Test if we have the database selected correctly
633 if(!$db){
634 gosa_log(mysql_error());
635 return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
636 }
638 /* Remove all temporary attributes */
639 $tmp = array_flip($this->attributes);
640 foreach(array("goFonDialOptiont","goFonDialOptionT","goFonDialOptionr","goFonDialOptionh","goFonDialOptionH","cn") as $val){
641 unset($this->$val);
642 unset($this->attrs[$val]);
643 unset($tmp[$val]);
644 }
645 foreach(array_flip($tmp) as $key => $val){
646 $tmp2[]=$val;
647 }
648 $this->attributes = $tmp2;
650 $i = 0;
651 $prio = 11;
653 if(empty($this->cn)){
654 $this->cn = $this->parent->by_object['ogroup']->cn;
655 $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
656 }
658 // Delete old Entries
659 $delete = array();
660 foreach($this->old_phone_numbers as $phone){
661 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
662 }
663 $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$this->attrs['cn'][0]."';\n";
664 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
665 $delete[]= "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
667 /* Perform queries to delte old entries */
668 foreach($delete as $query){
669 if(!mysql_query($query)){
670 gosa_log(mysql_error());
671 return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
672 }
673 }
677 /* Cancel if there's nothing to do here */
678 if (!$this->initially_was_account){
679 return;
680 }
682 /* include global link_info */
683 $ldap= $this->config->get_ldap_link();
685 /* Remove and write to LDAP */
686 plugin::remove_from_parent();
688 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
689 $this->attributes, "Save");
690 $ldap->cd($this->dn);
691 $this->cleanup();
692 $ldap->modify ($this->attrs);
694 show_ldap_error($ldap->get_error(), sprintf(_("Removing of object group/phone queue with dn '%s' failed."),$this->dn));
695 }
698 function getCopyDialog()
699 {
700 $str = "";
701 $str .= _("Phone number");
702 $str .= " <input type='text' name='telephoneNumber' value='".$this->telephoneNumber."'>";
703 return($str);
704 }
707 function saveCopyDialog()
708 {
709 if(isset($_POST['telephoneNumber'])){
710 $this->telephoneNumber = $_POST['telephoneNumber'];
711 }
712 }
715 function plInfo()
716 {
717 return (array(
718 "plShortName" => _("Phone"),
719 "plDescription" => _("Phone group"),
720 "plSelfModify" => FALSE,
721 "plDepends" => array(),
722 "plPriority" => 0,
723 "plSection" => array("administration"),
724 "plCategory" => array("ogroups"),
725 "plProvidedAcls"=> array(
727 "goFonTimeOut" => _("Timeout"),
728 "goFonMaxLen" => _("Max queue length"),
729 "goFonAnnounceFrequency" => _("Announce frequency"),
730 "goFonDialOptiont" => _("Allow the called user to transfer his call"),
731 "goFonDialOptionT" => _("Allows calling user to transfer call"),
732 "goFonDialOptionh" => _("Allow the called to hangup by pressing *"),
733 "goFonDialOptionr" => _("Ring instead of playing background music"),
734 "goFonDialOptionH" => _("Allows calling to hangup by pressing *"),
736 "goFonMusiconHold" => _("Music on hold"),
737 "goFonWelcomeMusic" => _("Welcome music"),
738 "goFonQueueReportHold" => _("Report hold time"),
739 "goFonQueueYouAreNext" => _("'You are next' sound"),
740 "goFonQueueThereAre" => _("'There are' sound"),
741 "goFonQueueCallsWaiting" => _("'Call waiting' sound"),
742 "goFonQueueThankYou" => _("'Thank you' sound"),
743 "goFonQueueMinutes" => _("'Minutes' sound"),
744 "goFonQueueSeconds" => _("'Seconds' sound"),
745 "goFonQueueLessThan" => _("'Less than' sound"),
746 "telephoneNumber" => _("Queue phone number"),
747 "goFonQueueLanguage" => _("Language"),
748 "goFonQueueStrategy" => _("Method"),
749 "goFonQueueAnnounceHoldtime"=> _("Announce holdtime"),
750 "goFonQueueAnnounce" => _("Announce"),
751 "goFonQueueRetry" => _("Retry"))
752 ));
753 }
757 }
759 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
760 ?>