| 1 |
<?php |
|---|
| 2 |
// The destinations this module provides |
|---|
| 3 |
// returns a associative arrays with keys 'destination' and 'description' |
|---|
| 4 |
function queues_destinations() { |
|---|
| 5 |
|
|---|
| 6 |
$results = queues_list(); |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
if (isset($results)) { |
|---|
| 10 |
foreach($results as $result){ |
|---|
| 11 |
$extens[] = array('destination' => 'ext-queues,'.$result['0'].',1', 'description' => $result['1'].' <'.$result['0'].'>'); |
|---|
| 12 |
} |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
if (isset($extens)) |
|---|
| 16 |
return $extens; |
|---|
| 17 |
else |
|---|
| 18 |
return null; |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
function queues_get_config($engine) { |
|---|
| 25 |
global $ext; |
|---|
| 26 |
switch($engine) { |
|---|
| 27 |
case "asterisk": |
|---|
| 28 |
|
|---|
| 29 |
$ext->addInclude('from-internal-additional','ext-queues'); |
|---|
| 30 |
$qlist = queues_list(); |
|---|
| 31 |
if (is_array($qlist)) { |
|---|
| 32 |
foreach($qlist as $item) { |
|---|
| 33 |
|
|---|
| 34 |
$exten = $item[0]; |
|---|
| 35 |
$q = queues_get($exten); |
|---|
| 36 |
|
|---|
| 37 |
$ext->add('ext-queues', $exten, '', new ext_answer('')); |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
// |
|---|
| 41 |
$ext->add('ext-queues', $exten, '', new ext_setvar('_NODEST', '${EXTEN}')); |
|---|
| 42 |
|
|---|
| 43 |
$ext->add('ext-queues', $exten, '', new ext_gotoif('$["${CONTEXT}"="from-internal"]','USERCID','SETCID')); |
|---|
| 44 |
$ext->add('ext-queues', $exten, 'USERCID', new ext_macro('user-callerid')); |
|---|
| 45 |
$ext->add('ext-queues', $exten, 'SETCID', new ext_setcidname($q['prefix'].'${CALLERIDNAME}')); |
|---|
| 46 |
$ext->add('ext-queues', $exten, '', new ext_setvar('MONITOR_FILENAME','/var/spool/asterisk/monitor/q${EXTEN}-${TIMESTAMP}-${UNIQUEID}')); |
|---|
| 47 |
$joinannounce = (isset($q['joinannounce'])?$q['joinannounce']:''); |
|---|
| 48 |
if($joinannounce != "") { |
|---|
| 49 |
$ext->add('ext-queues', $exten, '', new ext_playback($joinannounce)); |
|---|
| 50 |
} |
|---|
| 51 |
$options = 't'; |
|---|
| 52 |
if ($q['rtone'] == 1) |
|---|
| 53 |
$options .= 'r'; |
|---|
| 54 |
$agentannounce = (isset($q['agentannounce'])?$q['agentannounce']:''); |
|---|
| 55 |
$ext->add('ext-queues', $exten, '', new ext_queue($exten,$options,'',$agentannounce,$q['maxwait'])); |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
// |
|---|
| 59 |
$ext->add('ext-queues', $exten, '', new ext_setvar('_NODEST', '')); |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
$goto_context = strtok($q['goto'],','); |
|---|
| 63 |
$goto_exten = strtok(','); |
|---|
| 64 |
$goto_pri = strtok(','); |
|---|
| 65 |
|
|---|
| 66 |
$ext->add('ext-queues', $exten, '', new ext_goto($goto_pri,$goto_exten,$goto_context)); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
$ext->add('ext-queues', $exten."*", '', new ext_macro('agent-add',$exten.",".$q['password'])); |
|---|
| 70 |
$ext->add('ext-queues', $exten."**", '', new ext_macro('agent-del',$exten.",".$exten)); |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
break; |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
function queues_timeString($seconds, $full = false) { |
|---|
| 78 |
if ($seconds == 0) { |
|---|
| 79 |
return "0 ".($full ? "seconds" : "s"); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
$minutes = floor($seconds / 60); |
|---|
| 83 |
$seconds = $seconds % 60; |
|---|
| 84 |
|
|---|
| 85 |
$hours = floor($minutes / 60); |
|---|
| 86 |
$minutes = $minutes % 60; |
|---|
| 87 |
|
|---|
| 88 |
$days = floor($hours / 24); |
|---|
| 89 |
$hours = $hours % 24; |
|---|
| 90 |
|
|---|
| 91 |
if ($full) { |
|---|
| 92 |
return substr( |
|---|
| 93 |
($days ? $days." day".(($days == 1) ? "" : "s").", " : ""). |
|---|
| 94 |
($hours ? $hours." hour".(($hours == 1) ? "" : "s").", " : ""). |
|---|
| 95 |
($minutes ? $minutes." minute".(($minutes == 1) ? "" : "s").", " : ""). |
|---|
| 96 |
($seconds ? $seconds." second".(($seconds == 1) ? "" : "s").", " : ""), |
|---|
| 97 |
0, -2); |
|---|
| 98 |
} else { |
|---|
| 99 |
return substr(($days ? $days."d, " : "").($hours ? $hours."h, " : "").($minutes ? $minutes."m, " : "").($seconds ? $seconds."s, " : ""), 0, -2); |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
function queues_add($account,$name,$password,$prefix,$goto,$agentannounce,$members,$joinannounce,$maxwait) { |
|---|
| 108 |
global $db; |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
if (!empty($agentannounce) && $agentannounce != 'None') |
|---|
| 112 |
$agentannounce="$agentannounce"; |
|---|
| 113 |
else |
|---|
| 114 |
$agentannounce=""; |
|---|
| 115 |
|
|---|
| 116 |
$addarray = array('ext-queues',$account,'1','Answer',''.'','','0'); |
|---|
| 117 |
legacy_extensions_add($addarray); |
|---|
| 118 |
$addarray = array('ext-queues',$account,'2','SetCIDName',$prefix.'${CALLERIDNAME}','','0'); |
|---|
| 119 |
legacy_extensions_add($addarray); |
|---|
| 120 |
$addarray = array('ext-queues',$account,'3','SetVar','MONITOR_FILENAME=/var/spool/asterisk/monitor/q${EXTEN}-${TIMESTAMP}-${UNIQUEID}','','0'); |
|---|
| 121 |
legacy_extensions_add($addarray); |
|---|
| 122 |
if ($joinannounce != 'None') { |
|---|
| 123 |
$addarray = array('ext-queues',$account,'4','Playback',$joinannounce,'','0'); |
|---|
| 124 |
legacy_extensions_add($addarray); |
|---|
| 125 |
} |
|---|
| 126 |
$addarray = array('ext-queues',$account,'5','Queue',$account.'|t||'.$agentannounce.'|'.$maxwait,$name,'0'); |
|---|
| 127 |
legacy_extensions_add($addarray); |
|---|
| 128 |
$addarray = array('ext-queues',$account.'*','1','Macro','agent-add,'.$account.','.$password,'','0'); |
|---|
| 129 |
legacy_extensions_add($addarray); |
|---|
| 130 |
$addarray = array('ext-queues',$account.'**','1','Macro','agent-del,'.$account,'','0'); |
|---|
| 131 |
legacy_extensions_add($addarray); |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
$addarray = array('ext-queues',$account,'6','Goto',$goto,'jump','0'); |
|---|
| 135 |
legacy_extensions_add($addarray); |
|---|
| 136 |
|
|---|
| 137 |
// Announce Menu? |
|---|
| 138 |
if ($_REQUEST['announcemenu']=='none') { |
|---|
| 139 |
$qthanku = 'queue-thankyou'; |
|---|
| 140 |
$context = ''; |
|---|
| 141 |
} else { |
|---|
| 142 |
$arr = (ivr_get_details($_REQUEST['announcemenu'])); |
|---|
| 143 |
if( isset($arr['announcement']) && !empty($arr['announcement']) ) { |
|---|
| 144 |
$qthanku = $arr['announcement']; |
|---|
| 145 |
} else { |
|---|
| 146 |
$qthanku = ''; |
|---|
| 147 |
} |
|---|
| 148 |
$context = "ivr-".$_REQUEST['announcemenu']; |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
$fields = array( |
|---|
| 154 |
array($account,'account',$account,0), |
|---|
| 155 |
array($account,'maxlen',($_REQUEST['maxlen'])?$_REQUEST['maxlen']:'0',0), |
|---|
| 156 |
array($account,'joinempty',($_REQUEST['joinempty'])?$_REQUEST['joinempty']:'yes',0), |
|---|
| 157 |
array($account,'leavewhenempty',($_REQUEST['leavewhenempty'])?$_REQUEST['leavewhenempty']:'no',0), |
|---|
| 158 |
array($account,'strategy',($_REQUEST['strategy'])?$_REQUEST['strategy']:'ringall',0), |
|---|
| 159 |
array($account,'timeout',($_REQUEST['timeout'])?$_REQUEST['timeout']:'15',0), |
|---|
| 160 |
array($account,'retry',($_REQUEST['retry'])?$_REQUEST['retry']:'5',0), |
|---|
| 161 |
array($account,'wrapuptime',($_REQUEST['wrapuptime'])?$_REQUEST['wrapuptime']:'0',0), |
|---|
| 162 |
|
|---|
| 163 |
array($account,'announce-frequency',($_REQUEST['announcefreq'])?$_REQUEST['announcefreq']:'0',0), |
|---|
| 164 |
array($account,'announce-holdtime',($_REQUEST['announceholdtime'])?$_REQUEST['announceholdtime']:'no',0), |
|---|
| 165 |
array($account,'queue-youarenext',($_REQUEST['announceposition']=='no')?'':'queue-youarenext',0), |
|---|
| 166 |
array($account,'queue-thereare',($_REQUEST['announceposition']=='no')?'':'queue-thereare',0), |
|---|
| 167 |
array($account,'queue-callswaiting',($_REQUEST['announceposition']=='no')?'':'queue-callswaiting',0), |
|---|
| 168 |
array($account,'queue-thankyou',$qthanku,0), |
|---|
| 169 |
array($account,'context',$context,0), |
|---|
| 170 |
array($account,'monitor-format',($_REQUEST['monitor-format'])?$_REQUEST['monitor-format']:'',0), |
|---|
| 171 |
array($account,'monitor-join','yes',0), |
|---|
| 172 |
array($account,'music',($_REQUEST['music'])?$_REQUEST['music']:'default',0), |
|---|
| 173 |
array($account,'rtone',($_REQUEST['rtone'])?$_REQUEST['rtone']:0,0), |
|---|
| 174 |
array($account,'eventwhencalled',($_REQUEST['eventwhencalled'])?$_REQUEST['eventwhencalled']:'no',0), |
|---|
| 175 |
array($account,'eventmemberstatusoff',($_REQUEST['eventmemberstatusoff'])?$_REQUEST['eventmemberstatusoff']:'yes',0)); |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
if (isset($members)) { |
|---|
| 180 |
$count = 0; |
|---|
| 181 |
foreach ($members as $member) { |
|---|
| 182 |
$fields[] = array($account,'member',$member,$count); |
|---|
| 183 |
$count++; |
|---|
| 184 |
} |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
$compiled = $db->prepare('INSERT INTO queues (id, keyword, data, flags) values (?,?,?,?)'); |
|---|
| 188 |
$result = $db->executeMultiple($compiled,$fields); |
|---|
| 189 |
if(DB::IsError($result)) { |
|---|
| 190 |
die($result->getMessage()."<br><br>error adding to queues table"); |
|---|
| 191 |
} |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
function queues_del($account) { |
|---|
| 195 |
global $db; |
|---|
| 196 |
|
|---|
| 197 |
legacy_extensions_del('ext-queues',$account); |
|---|
| 198 |
legacy_extensions_del('ext-queues',$account.'*'); |
|---|
| 199 |
legacy_extensions_del('ext-queues',$account.'**'); |
|---|
| 200 |
|
|---|
| 201 |
$sql = "DELETE FROM queues WHERE id = '$account'"; |
|---|
| 202 |
$result = $db->query($sql); |
|---|
| 203 |
if(DB::IsError($result)) { |
|---|
| 204 |
die($result->getMessage().$sql); |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
function queues_list() { |
|---|
| 211 |
global $db; |
|---|
| 212 |
$sql = "SELECT extension,descr FROM extensions WHERE application = 'Queue' ORDER BY extension"; |
|---|
| 213 |
$results = $db->getAll($sql); |
|---|
| 214 |
if(DB::IsError($results)) { |
|---|
| 215 |
$results = null; |
|---|
| 216 |
} |
|---|
| 217 |
foreach($results as $result){ |
|---|
| 218 |
if (checkRange($result[0])){ |
|---|
| 219 |
$extens[] = array($result[0],$result[1]); |
|---|
| 220 |
} |
|---|
| 221 |
} |
|---|
| 222 |
if (isset($extens)) { |
|---|
| 223 |
return $extens; |
|---|
| 224 |
} else { |
|---|
| 225 |
return null; |
|---|
| 226 |
} |
|---|
| 227 |
} |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
function queues_get($account) { |
|---|
| 231 |
global $db; |
|---|
| 232 |
|
|---|
| 233 |
if ($account == "") |
|---|
| 234 |
{ |
|---|
| 235 |
return array(); |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
$sql = "SELECT keyword,data FROM queues WHERE id = '$account'"; |
|---|
| 240 |
$results = $db->getAssoc($sql); |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
$sql = "SELECT data FROM queues WHERE id = '$account' AND keyword = 'member' order by flags"; |
|---|
| 244 |
$results['member'] = $db->getCol($sql); |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
$results['announcemenu'] = $results['context']; |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
if($results['queue-youarenext'] == 'queue-youarenext') |
|---|
| 251 |
$results['announce-position'] = 'yes'; |
|---|
| 252 |
else |
|---|
| 253 |
$results['announce-position'] = 'no'; |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
$sql = "SELECT args FROM extensions WHERE extension = '$account' AND context = 'ext-queues' AND application = 'SetCIDName'"; |
|---|
| 257 |
list($args) = $db->getRow($sql); |
|---|
| 258 |
$prefix = explode('$',$args); |
|---|
| 259 |
$results['prefix'] = $prefix[0]; |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
$sql = "SELECT args,descr FROM extensions WHERE extension = '$account' AND context = 'ext-queues' AND application = 'Queue'"; |
|---|
| 263 |
list($args, $descr) = $db->getRow($sql); |
|---|
| 264 |
$maxwait = explode('|',$args); |
|---|
| 265 |
$results['agentannounce'] = $maxwait[3]; |
|---|
| 266 |
$results['maxwait'] = $maxwait[4]; |
|---|
| 267 |
$results['name'] = $descr; |
|---|
| 268 |
|
|---|
| 269 |
$sql = "SELECT args FROM extensions WHERE extension = '$account' AND context = 'ext-queues' and application = 'Playback'"; |
|---|
| 270 |
list($args) = $db->getRow($sql); |
|---|
| 271 |
$results['joinannounce'] = $args; |
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
$sql = "SELECT args FROM extensions WHERE extension = '$account*' AND context = 'ext-queues'"; |
|---|
| 275 |
list($args) = $db->getRow($sql); |
|---|
| 276 |
$password = explode(',',$args); |
|---|
| 277 |
$results['password'] = $password[2]; |
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
$sql = "SELECT args FROM extensions WHERE extension = '".$account."' AND descr = 'jump'"; |
|---|
| 281 |
list($args) = $db->getRow($sql); |
|---|
| 282 |
$results['goto'] = $args; |
|---|
| 283 |
|
|---|
| 284 |
return $results; |
|---|
| 285 |
} |
|---|
| 286 |
?> |
|---|
| 287 |
|
|---|