root/modules/branches/2.6/queues/functions.inc.php

Revision 7690, 23.9 kB (checked in by p_lindheimer, 4 years ago)

Merged revisions 7687-7689 via svnmerge from
http://svn.freepbx.org/modules/branches/2.5

........

r7687 | p_lindheimer | 2009-05-07 16:08:12 -0700 (Thu, 07 May 2009) | 1 line


fixes #3664 reset CWIGNORE before going to destination, also CFIGNORE reset to from-internal in ringgroups and this fix is also being applied to ringgroups

........

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $id:$ */
2
3 class queues_conf {
4
5     var $_queues_general    = array();
6
7     // return an array of filenames to write
8     // files named like pinset_N
9     function get_filename() {
10         $files = array(
11             'queues_additional.conf',
12             'queues_general_additional.conf',
13             );
14         return $files;
15     }
16     
17     // return the output that goes in each of the files
18     function generateConf($file) {
19         global $version;
20
21         switch ($file) {
22             case 'queues_additional.conf':
23                 return $this->generate_queues_additional($version);
24                 break;
25             case 'queues_general_additional.conf':
26                 return $this->generate_queues_general_additional($version);
27                 break;
28         }
29     }
30
31     function addQueuesGeneral($key, $value) {
32         $this->_queues_general[] = array('key' => $key, 'value' => $value);
33     }
34
35     function generate_queues_additional($ast_version) {
36
37         global $db;
38
39         $additional = "";
40         $output = "";
41         // Asterisk 1.4 does not like blank assignments so just don't put them there
42         //
43         $ver12 = version_compare($ast_version, '1.4', 'lt');
44         $ver16 = version_compare($ast_version, '1.6', 'ge');
45         
46         // legacy but in case someone was using this we will leave it
47         //
48         $sql = "SELECT keyword,data FROM queues_details WHERE id='-1' AND keyword <> 'account'";
49         $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
50         if(DB::IsError($results)) {
51            die($results->getMessage());
52         }
53         foreach ($results as $result) {
54             if (!$ver12 && trim($result['data']) == '') {
55                 continue;
56             }
57             $additional .= $result['keyword']."=".$result['data']."\n";
58         }
59
60         $results = queues_list(true);
61         foreach ($results as $result) {
62             $output .= "[".$result[0]."]\n";
63
64             // passing 2nd param 'true' tells queues_get to send back only queue_conf required params
65             // and nothing else
66             //
67             $results2 = queues_get($result[0], true);
68
69             // memebers is an array of members so we set it asside and remove it
70             // and then generate each later
71             //
72             $members = $results2['member'];
73             unset($results2['member']);
74
75             foreach ($results2 as $keyword => $data) {
76                 if ($ver12){
77                     switch($keyword){
78                         case 'ringinuse':
79                         case 'autofill':
80                             break;
81                         case 'retry':
82                             if ($data == 'none') {
83                                 $data = 0;
84                             }
85                             // no break, fallthrough to default
86                         default:
87                             $output .= $keyword."=".$data."\n";
88                             break;
89                     }
90                 }else{
91                     switch($keyword){
92                         case (trim($data) == ''):
93                         case 'monitor-join':
94                             break;
95                         case 'monitor-format':
96                             if (strtolower($data) != 'no'){
97                                 $output .= "monitor-type=mixmonitor\n";
98                                 $output .= $keyword."=".$data."\n";
99                             }
100                             break;
101                         case 'ringinuse':
102                             break;
103                         case 'announce-position':
104                             if ($ver16) {
105                                 $output .= $keyword."=".$data."\n";
106                             }
107                             break;
108                         case 'retry':
109                             if ($data == 'none') {
110                                 $data = 0;
111                             }
112                             // no break, fallthrough to default
113                         default:
114                             $output .= $keyword."=".$data."\n";
115                             break;
116                     }
117                 }
118             }
119
120             // Now pull out all the memebers, one line for each
121             //
122             foreach ($members as $member) {
123                 $output .= "member=".$member."\n";
124             }
125             $output .= $additional."\n";
126         }
127
128         // Before returning the results, do an integrity check to see
129         // if there are any truncated compound recrodings and if so
130         // crate a noticication.
131         //
132         $nt = notifications::create($db);
133
134         $compound_recordings = queues_check_compoundrecordings();
135         if (empty($compound_recordings)) {
136             $nt->delete('queues', 'COMPOUNDREC');
137         } else {
138             $str = _("Warning, there are compound recordings configured in one or more Queue configurations. Queues can not play these so they have been truncated to the first sound file. You should correct this problem.<br />Details:<br /><br />");
139             foreach ($compound_recordings as $item) {
140                 $str .= sprintf(_("Queue - %s (%s): %s<br />"), $item['extension'], $item['descr'], $item['error']);
141             }
142             $nt->add_error('queues', 'COMPOUNDREC', _("Compound Recordings in Queues Detected"), $str);
143         }
144         return $output;
145     }
146
147     function generate_queues_general_additional($ast_version) {
148         $output = '';
149
150         if (isset($this->_queues_general) && is_array($this->_queues_general)) {
151             foreach ($this->_queues_general as $values) {
152                 $output .= $values['key']."=".$values['value']."\n";
153             }
154         }
155         return $output;
156     }
157
158
159
160 }
161
162 // The destinations this module provides
163 // returns a associative arrays with keys 'destination' and 'description'
164 function queues_destinations() {
165     //get the list of all exisiting
166     $results = queues_list(true);
167     
168     //return an associative array with destination and description
169     if (isset($results)) {
170         foreach($results as $result){
171                 $extens[] = array('destination' => 'ext-queues,'.$result['0'].',1', 'description' => $result['1'].' <'.$result['0'].'>');
172         }
173     }
174     
175     if (isset($extens))
176         return $extens;
177     else
178         return null;
179 }
180
181 function queues_getdest($exten) {
182     return array('ext-queues,'.$exten.',1');
183 }
184
185 function queues_getdestinfo($dest) {
186     global $active_modules;
187
188     if (substr(trim($dest),0,11) == 'ext-queues,') {
189         $exten = explode(',',$dest);
190         $exten = $exten[1];
191         $thisexten = queues_get($exten);
192         if (empty($thisexten)) {
193             return array();
194         } else {
195             //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
196             return array('description' => sprintf(_("Queue %s : %s"),$exten,$thisexten['name']),
197                          'edit_url' => 'config.php?display=queues&extdisplay='.urlencode($exten),
198                                   );
199         }
200     } else {
201         return false;
202     }
203 }
204
205 function queues_recordings_usage($recording_id) {
206     global $active_modules;
207
208     $results = sql("SELECT `extension`, `descr` FROM `queues_config` WHERE `agentannounce_id` = '$recording_id' OR `joinannounce_id` = '$recording_id'","getAll",DB_FETCHMODE_ASSOC);
209     if (empty($results)) {
210         return array();
211     } else {
212         //$type = isset($active_modules['queues']['type'])?$active_modules['queues']['type']:'setup';
213         foreach ($results as $result) {
214             $usage_arr[] = array(
215               'url_query' => 'config.php?display=queues&extdisplay='.urlencode($result['extension']),
216                 'description' => sprintf(_("Queue: %s"),$result['descr']),
217             );
218         }
219         return $usage_arr;
220     }
221 }
222
223 function queues_ivr_usage($ivr_id) {
224     global $active_modules;
225
226     $results = sql("SELECT `extension`, `descr` FROM `queues_config` WHERE `ivr_id` = '$ivr_id'","getAll",DB_FETCHMODE_ASSOC);
227     if (empty($results)) {
228         return array();
229     } else {
230         foreach ($results as $result) {
231             $usage_arr[] = array(
232               'url_query' => 'config.php?display=queues&extdisplay='.urlencode($result['extension']),
233                 'description' => sprintf(_("Queue: %s"),$result['descr']),
234             );
235         }
236         return $usage_arr;
237     }
238 }
239
240 /*     Generates dialplan for "queues" components (extensions & inbound routing)
241     We call this with retrieve_conf
242 */
243 function queues_get_config($engine) {
244     global $ext// is this the best way to pass this?
245     global $queues_conf;
246
247     switch($engine) {
248         case "asterisk":
249
250             if (isset($queues_conf) && is_a($queues_conf, "queues_conf")) {
251                 $queues_conf->addQueuesGeneral('persistentmembers','yes');
252             }
253
254             /* queue extensions */
255             $ext->addInclude('from-internal-additional','ext-queues');
256             $qlist = queues_list(true);
257             if (is_array($qlist)) {
258                 foreach($qlist as $item) {
259                     
260                     $exten = $item[0];
261                     $q = queues_get($exten);
262
263                     $grppre = (isset($q['prefix'])?$q['prefix']:'');
264                     $alertinfo = (isset($q['alertinfo'])?$q['alertinfo']:'');
265
266                     // Not sure why someone would ever have a ; in the regex, but since Asterisk has problems with them
267                     // it would need to be escaped
268                     //
269                     $qregex = (isset($q['qregex'])?$q['qregex']:'');
270                     str_replace(';','\;',$qregex);
271                     
272                     $ext->add('ext-queues', $exten, '', new ext_macro('user-callerid'));
273                     $ext->add('ext-queues', $exten, '', new ext_answer(''));
274
275                     // block voicemail until phone is answered at which point a macro should be called on the answering
276                     // line to clear this flag so that subsequent transfers can occur.
277                     //
278                     if ($q['queuewait']) {
279                         $ext->add('ext-queues', $exten, '', new ext_execif('$["${QUEUEWAIT}" = ""]', 'Set', '__QUEUEWAIT=${EPOCH}'));
280                     }
281                     $ext->add('ext-queues', $exten, '', new ext_setvar('__BLKVM_OVERRIDE', 'BLKVM/${EXTEN}/${CHANNEL}'));
282                     $ext->add('ext-queues', $exten, '', new ext_setvar('__BLKVM_BASE', '${EXTEN}'));
283                     $ext->add('ext-queues', $exten, '', new ext_setvar('DB(${BLKVM_OVERRIDE})', 'TRUE'));
284                     $ext->add('ext-queues', $exten, '', new ext_execif('$["${REGEX("(M[(]auto-blkvm[)])" ${DIAL_OPTIONS})}" != "1"]', 'Set', '_DIAL_OPTIONS=${DIAL_OPTIONS}M(auto-blkvm)'));
285
286                     // Inform all the children NOT to send calls to destinations or voicemail
287                     //
288                     $ext->add('ext-queues', $exten, '', new ext_setvar('__NODEST', '${EXTEN}'));
289
290                     // deal with group CID prefix
291                     // Use the same variable as ringgroups/followme so that we can manage chaines of calls
292                     // but strip only if you plan on setting a new one
293                     //
294                     if ($grppre != '') {
295                         $ext->add('ext-queues', $exten, '', new ext_gotoif('$["foo${RGPREFIX}" = "foo"]', 'REPCID'));
296                         $ext->add('ext-queues', $exten, '', new ext_gotoif('$["${RGPREFIX}" != "${CALLERID(name):0:${LEN(${RGPREFIX})}}"]', 'REPCID'));
297                         $ext->add('ext-queues', $exten, '', new ext_noop('Current RGPREFIX is ${RGPREFIX}....stripping from Caller ID'));
298                         $ext->add('ext-queues', $exten, '', new ext_setvar('CALLERID(name)', '${CALLERID(name):${LEN(${RGPREFIX})}}'));
299                         $ext->add('ext-queues', $exten, '', new ext_setvar('_RGPREFIX', ''));
300                         $ext->add('ext-queues', $exten, 'REPCID', new ext_noop('CALLERID(name) is ${CALLERID(name)}'));
301                         $ext->add('ext-queues', $exten, '', new ext_setvar('_RGPREFIX', $grppre));
302                         $ext->add('ext-queues', $exten, '', new ext_setvar('CALLERID(name)','${RGPREFIX}${CALLERID(name)}'));
303                     }
304
305                     // Set Alert_Info
306                     if ($alertinfo != '') {
307                         $ext->add('ext-queues', $exten, '', new ext_setvar('__ALERT_INFO', str_replace(';', '\;', $alertinfo)));
308                     }
309
310                     $ext->add('ext-queues', $exten, '', new ext_setvar('MONITOR_FILENAME','/var/spool/asterisk/monitor/q${EXTEN}-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${UNIQUEID}'));
311                     $joinannounce_id = (isset($q['joinannounce_id'])?$q['joinannounce_id']:'');
312                     if($joinannounce_id) {
313                         $joinannounce = recordings_get_file($joinannounce_id);
314                         $ext->add('ext-queues', $exten, '', new ext_playback($joinannounce));
315                     }
316                     $options = 't';
317                     if ($q['rtone'] == 1) {
318                         $options .= 'r';
319                     }
320                     if ($q['retry'] == 'none'){
321                         $options .= 'n';
322                     }
323                     if (isset($q['music'])) {
324                          $ext->add('ext-queues', $exten, '', new ext_setvar('__MOHCLASS', $q['music']));
325                     }
326                     // Set CWIGNORE  if enabled so that busy agents don't have another line key ringing and
327                     // stalling the ACD.
328                     if ($q['cwignore']) {
329                          $ext->add('ext-queues', $exten, '', new ext_setvar('__CWIGNORE', 'TRUE'));
330                     }
331                     $agentannounce_id = (isset($q['agentannounce_id'])?$q['agentannounce_id']:'');
332                     if ($agentannounce_id) {
333                         $agentannounce = recordings_get_file($agentannounce_id);
334                     } else {
335                         $agentannounce = '';
336                     }
337                     $ext->add('ext-queues', $exten, '', new ext_queue($exten,$options,'',$agentannounce,$q['maxwait']));
338  
339                     $ext->add('ext-queues', $exten, '', new ext_dbdel('${BLKVM_OVERRIDE}'));
340                      // If we are here, disable the NODEST as we want things to resume as normal
341                      //
342                      $ext->add('ext-queues', $exten, '', new ext_setvar('__NODEST', ''));
343                     if ($q['cwignore']) {
344                         $ext->add('ext-queues', $exten, '', new ext_setvar('__CWIGNORE', ''));
345                     }
346     
347                     // destination field in 'incoming' database is backwards from what ext_goto expects
348                     $goto_context = strtok($q['goto'],',');
349                     $goto_exten = strtok(',');
350                     $goto_pri = strtok(',');
351                     
352                     $ext->add('ext-queues', $exten, '', new ext_goto($goto_pri,$goto_exten,$goto_context));
353                     
354                     //dynamic agent login/logout
355                     if (trim($qregex) != '') {
356                          $ext->add('ext-queues', $exten."*", '', new ext_setvar('QREGEX', $qregex));
357                     }
358                     $ext->add('ext-queues', $exten."*", '', new ext_macro('agent-add',$exten.",".$q['password']));
359                     $ext->add('ext-queues', $exten."**", '', new ext_macro('agent-del',$exten.",".$exten));
360                 }
361             }
362         break;
363     }
364 }
365
366 function queues_timeString($seconds, $full = false) {
367     if ($seconds == 0) {
368         return "0 ".($full ? _("seconds") : "s");
369     }
370
371     $minutes = floor($seconds / 60);
372     $seconds = $seconds % 60;
373
374     $hours = floor($minutes / 60);
375     $minutes = $minutes % 60;
376
377     $days = floor($hours / 24);
378     $hours = $hours % 24;
379
380     if ($full) {
381          return substr(
382                       ($days ? $days." "._("day").(($days == 1) ? "" : "s").", " : "").
383                       ($hours ? $hours." ".(($hours == 1) ? _("hour") : _("hours")).", " : "").
384                       ($minutes ? $minutes." ".(($minutes == 1) ? _("minute") : _("minutes")).", " : "").
385                       ($seconds ? $seconds." ".(($seconds == 1) ? _("second") : _("seconds")).", " : ""),
386                       0, -2);
387     } else {
388         return substr(($days ? $days."d, " : "").($hours ? $hours."h, " : "").($minutes ? $minutes."m, " : "").($seconds ? $seconds."s, " : ""), 0, -2);
389     }
390 }
391
392 function queues_add($account,$name,$password,$prefix,$goto,$agentannounce_id,$members,$joinannounce_id,$maxwait,$alertinfo='',$cwignore='no',$qregex='',$queuewait='no') {
393     global $db;
394
395     if (trim($account) == '') {
396         echo "<script>javascript:alert('"._("Bad Queue Number, can not be blank")."');</script>";
397         return false;
398     }
399
400     //add to extensions table
401     if (empty($agentannounce_id)) {
402         $agentannounce_id="";
403     }
404
405 $fields = array(
406     array($account,'maxlen',($_REQUEST['maxlen'])?$_REQUEST['maxlen']:'0',0),
407     array($account,'joinempty',($_REQUEST['joinempty'])?$_REQUEST['joinempty']:'yes',0),
408     array($account,'leavewhenempty',($_REQUEST['leavewhenempty'])?$_REQUEST['leavewhenempty']:'no',0),
409     array($account,'strategy',($_REQUEST['strategy'])?$_REQUEST['strategy']:'ringall',0),
410     array($account,'timeout',(isset($_REQUEST['timeout']))?$_REQUEST['timeout']:'15',0),
411     array($account,'retry',(isset($_REQUEST['retry']) && $_REQUEST['retry'] != '')?$_REQUEST['retry']:'5',0),
412     array($account,'wrapuptime',($_REQUEST['wrapuptime'])?$_REQUEST['wrapuptime']:'0',0),
413     array($account,'announce-frequency',($_REQUEST['announcefreq'])?$_REQUEST['announcefreq']:'0',0),
414     array($account,'announce-holdtime',($_REQUEST['announceholdtime'])?$_REQUEST['announceholdtime']:'no',0),
415     array($account,'announce-position',($_REQUEST['announceposition'])?$_REQUEST['announceposition']:'no',0),
416     array($account,'queue-youarenext',($_REQUEST['announceposition']=='no')?'silence/1':'queue-youarenext',0),  //if no, play no sound
417     array($account,'queue-thereare',($_REQUEST['announceposition']=='no')?'silence/1':'queue-thereare',0),  //if no, play no sound
418     array($account,'queue-callswaiting',($_REQUEST['announceposition']=='no')?'silence/1':'queue-callswaiting',0),  //if no, play no sound
419     array($account,'queue-thankyou',($_REQUEST['announceposition']=='no')?'':'queue-thankyou',0),  //if no, play no sound
420     array($account,'periodic-announce-frequency',($_REQUEST['pannouncefreq'])?$_REQUEST['pannouncefreq']:'0',0),
421     array($account,'monitor-format',($_REQUEST['monitor-format'])?$_REQUEST['monitor-format']:'',0),
422     array($account,'monitor-join','yes',0),
423     array($account,'eventwhencalled',($_REQUEST['eventwhencalled'])?$_REQUEST['eventwhencalled']:'no',0),
424     array($account,'eventmemberstatus',($_REQUEST['eventmemberstatus'])?$_REQUEST['eventmemberstatus']:'no',0),
425     array($account,'weight',(isset($_REQUEST['weight']))?$_REQUEST['weight']:'0',0),
426     array($account,'autofill',(isset($_REQUEST['autofill']))?'yes':'no',0),
427 );
428
429     if ($_REQUEST['music'] != 'inherit') {
430         $fields[] = array($account,'music',($_REQUEST['music'])?$_REQUEST['music']:'default',0);
431     }
432
433     //there can be multiple members
434     if (isset($members)) {
435         $count = 0;
436         $members = array_unique($members);
437         foreach ($members as $member) {
438             $fields[] = array($account,'member',$member,$count);
439             $count++;
440         }
441     }
442
443     $compiled = $db->prepare('INSERT INTO queues_details (id, keyword, data, flags) values (?,?,?,?)');
444     $result = $db->executeMultiple($compiled,$fields);
445     if(DB::IsError($result)) {
446         die_freepbx($result->getMessage()."<br><br>error adding to queues_details table");   
447     }
448     $extension        = $account;
449     $descr         = isset($name) ? $db->escapeSimple($name):'';
450     $grppre        = isset($prefix) ? $db->escapeSimple($prefix):'';
451     $alertinfo     = isset($alertinfo) ? $db->escapeSimple($alertinfo):'';
452     //$joinannounce_id  = $joinannounce_id;
453     $ringing       = isset($_REQUEST['rtone']) ? $_REQUEST['rtone']:'';
454     //$agentannounce_id = $agentannounce_id;
455     $maxwait       = isset($maxwait) ? $maxwait:'';
456     $password      = isset($password) ? $password:'';
457     $ivr_id        = isset($_REQUEST['announcemenu']) ? $_REQUEST['announcemenu']:'none';
458     $dest          = isset($goto) ? $goto:'';
459     $cwignore      = isset($cwignore) ? $cwignore:'0';
460     $queuewait     = isset($queuewait) ? $queuewait:'0';
461     $qregex        = isset($qregex) ? $db->escapeSimple($qregex):'';
462
463     // Assumes it has just been deleted
464     $sql = "INSERT INTO queues_config (extension, descr, grppre, alertinfo, joinannounce_id, ringing, agentannounce_id, maxwait, password, ivr_id, dest, cwignore, qregex, queuewait)
465              VALUES ('$extension', '$descr', '$grppre', '$alertinfo', '$joinannounce_id', '$ringing', '$agentannounce_id', '$maxwait', '$password', '$ivr_id', '$dest', '$cwignore', '$qregex', '$queuewait')    ";
466     $results = sql($sql);
467     return true;
468 }
469
470 function queues_del($account) {
471     global $db;
472     
473     $sql = "DELETE FROM queues_details WHERE id = '$account'";
474     $result = $db->query($sql);
475     if(DB::IsError($result)) {
476         die_freepbx($result->getMessage().$sql);
477     }
478     $sql = "DELETE FROM queues_config WHERE extension = '$account'";
479     $result = $db->query($sql);
480     if(DB::IsError($result)) {
481         die_freepbx($result->getMessage().$sql);
482     }
483
484 }
485
486 //get the existing queue extensions
487 //
488 function queues_list($listall=false) {
489     global $db;
490     $sql = "SELECT extension, descr FROM queues_config ORDER BY extension";
491     $results = $db->getAll($sql);
492     if(DB::IsError($results)) {
493         $results = array();
494     }
495
496     foreach($results as $result){
497         if ($listall || checkRange($result[0])){
498             $extens[] = array($result[0],$result[1]);
499         }
500     }
501     if (isset($extens)) {
502         return $extens;
503     } else {
504         return array();
505     }
506 }
507
508 function queues_check_extensions($exten=true) {
509     global $active_modules;
510
511     $extenlist = array();
512     if (is_array($exten) && empty($exten)) {
513         return $extenlist;
514     }
515     $sql = "SELECT extension, descr FROM queues_config ";
516     if (is_array($exten)) {
517         $sql .= "WHERE extension in ('".implode("','",$exten)."')";
518     }
519     $sql .= " ORDER BY extension";
520     $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
521
522     //$type = isset($active_modules['queues']['type'])?$active_modules['queues']['type']:'setup';
523     foreach ($results as $result) {
524         $thisexten = $result['extension'];
525         $extenlist[$thisexten]['description'] = sprintf(_("Queue: %s"),$result['descr']);
526         $extenlist[$thisexten]['status'] = _('INUSE');
527         $extenlist[$thisexten]['edit_url'] = 'config.php?display=queues&extdisplay='.urlencode($thisexten);
528     }
529     return $extenlist;
530 }
531
532 function queues_check_destinations($dest=true) {
533     global $active_modules;
534
535     $destlist = array();
536     if (is_array($dest) && empty($dest)) {
537         return $destlist;
538     }
539     $sql = "SELECT extension, descr, dest FROM queues_config";
540     if ($dest !== true) {
541         $sql .= " WHERE dest in ('".implode("','",$dest)."')";
542     }
543     $sql .= " ORDER BY extension";
544
545     $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
546
547     //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
548
549     foreach ($results as $result) {
550         $thisdest = $result['dest'];
551         $thisid   = $result['extension'];
552         $destlist[] = array(
553             'dest' => $thisdest,
554             'description' => sprintf(_("Queue: %s (%s)"),$result['descr'],$thisid),
555             'edit_url' => 'config.php?display=queues&extdisplay='.urlencode($thisid),
556         );
557     }
558     return $destlist;
559 }
560
561 function queues_check_compoundrecordings() {
562     global $db;
563
564     $compound_recordings = array();
565     $sql = "SELECT extension, descr, agentannounce_id, ivr_id FROM queues_config WHERE (ivr_id != 'none' AND ivr_id != '') OR agentannounce_id != ''";
566     $results = sql($sql, "getAll",DB_FETCHMODE_ASSOC);
567
568     if (function_exists('ivr_list')) {
569         $ivr_details = ivr_list();
570         foreach ($ivr_details as $item) {
571             $ivr_hash[$item['ivr_id']] = $item;
572         }
573         $check_ivr = true;
574     } else {
575         $check_ivr = false;
576     }
577
578     foreach ($results as $result) {
579         $agentannounce = $result['agentannounce_id'] ? recordings_get_file($result['agentannounce_id']):'';
580         if (strpos($agentannounce,"&") !== false) {
581             $compound_recordings[] = array(
582                                            'extension' => $result['extension'],
583                                                                  'descr' => $result['descr'],
584                                                                  'error' => _("Agent Announce Msg"),
585                                                              );
586         }
587         if ($result['ivr_id'] != 'none' && $result['ivr_id'] != '' && $check_ivr) {
588             $id = $ivr_hash[$result['ivr_id']]['announcement_id'];
589             $announce = $id ? recordings_get_file($id) : '';
590             if (strpos($announce,"&") !== false) {
591                 $compound_recordings[] = array(
592                                                'extension' => $result['extension'],
593                                                                      'descr' => $result['descr'],
594                                                                      'error' => sprintf(_("IVR Announce: %s"),$ivr_hash[$result['ivr_id']]['displayname']),
595                                                                  );
596             }
597         }
598     }
599     return $compound_recordings;
600 }
601
602
603 function queues_get($account, $queues_conf_only=false) {
604     global $db;
605     
606     if ($account == "")
607     {
608         return array();
609     }
610
611     $account = q($account);
612     //get all the variables for the queue
613     $sql = "SELECT keyword,data FROM queues_details WHERE id = $account";
614     $results = $db->getAssoc($sql);
615     if (empty($results)) {
616         return array();
617     }
618
619     //okay, but there can be multiple member variables ... do another select for them
620     $sql = "SELECT data FROM queues_details WHERE id = $account AND keyword = 'member' order by flags";
621     $results['member'] = $db->getCol($sql);
622     
623     //if 'queue-youarenext=queue-youarenext', then assume we want to announce position
624     if (!$queues_conf_only) {
625         if(isset($results['queue-youarenext']) && $results['queue-youarenext'] == 'queue-youarenext') {
626             $results['announce-position'] = 'yes';
627         } else {
628             $results['announce-position'] = 'no';
629         }
630     }
631     
632     //if 'eventmemberstatusoff=Yes', then assume we want to 'eventmemberstatus=no'
633     if(isset($results['eventmemberstatusoff'])) {
634         if (strtolower($results['eventmemberstatusoff']) == 'yes') {
635             $results['eventmemberstatus'] = 'no';
636         } else {
637             $results['eventmemberstatus'] = 'yes';
638         }
639     } elseif (!isset($results['eventmemberstatus'])){
640         $results['eventmemberstatus'] = 'no';
641     }
642
643     if ($queues_conf_only) {
644         $sql = "SELECT ivr_id FROM queues_config WHERE extension = $account";
645         $config = sql($sql, "getRow",DB_FETCHMODE_ASSOC);
646
647         // We need to strip off all but the first sound file of any compound sound files
648         //
649         $results['agentannounce_id'] = $agentannounce_id_arr[0];
650     } else {
651         $sql = "SELECT * FROM queues_config WHERE extension = $account";
652         $config = sql($sql, "getRow",DB_FETCHMODE_ASSOC);
653
654         $results['prefix']        = $config['grppre'];
655         $results['alertinfo']     = $config['alertinfo'];
656         $results['agentannounce_id'] = $config['agentannounce_id'];
657         $results['maxwait']       = $config['maxwait'];
658         $results['name']          = $config['descr'];
659         $results['joinannounce_id']  = $config['joinannounce_id'];
660         $results['password']      = $config['password'];
661         $results['goto']          = $config['dest'];
662         $results['announcemenu']  = $config['ivr_id'];
663         $results['rtone']         = $config['ringing'];
664         $results['cwignore']      = $config['cwignore'];
665         $results['qregex']        = $config['qregex'];
666         $results['queuewait']     = $config['queuewait'];
667     }
668
669     $results['context'] = '';
670     $results['periodic-announce'] = '';
671
672     if ($config['ivr_id'] != 'none' && $config['ivr_id'] != '') {
673         if (function_exists('ivr_get_details')) {
674             $results['context'] = "ivr-".$config['ivr_id'];
675             $arr = ivr_get_details($config['ivr_id']);
676             if( isset($arr['announcement_id']) && $arr['announcement_id'] != '') {
677                 $periodic = recordings_get_file($arr['announcement_id']);
678                 // We need to strip off all but the first sound file of any compound sound files
679                 //
680                 $periodic_arr = explode("&", $periodic);
681                 $results['periodic-announce'] = $periodic_arr[0];
682             }
683         }
684     }
685
686     return $results;
687 }
688 ?>
689
Note: See TracBrowser for help on using the browser.