| 3 | | |
|---|
| 4 | | class queues_conf { |
|---|
| 5 | | |
|---|
| 6 | | var $_queues_general = array(); |
|---|
| 7 | | |
|---|
| 8 | | // return an array of filenames to write |
|---|
| 9 | | // files named like pinset_N |
|---|
| 10 | | function get_filename() { |
|---|
| 11 | | $files = array( |
|---|
| 12 | | 'queues_additional.conf', |
|---|
| 13 | | 'queues_general_additional.conf', |
|---|
| 14 | | ); |
|---|
| 15 | | return $files; |
|---|
| 16 | | } |
|---|
| 17 | | |
|---|
| 18 | | // return the output that goes in each of the files |
|---|
| 19 | | function generateConf($file) { |
|---|
| 20 | | global $version; |
|---|
| 21 | | |
|---|
| 22 | | switch ($file) { |
|---|
| 23 | | case 'queues_additional.conf': |
|---|
| 24 | | return $this->generate_queues_additional($version); |
|---|
| 25 | | break; |
|---|
| 26 | | case 'queues_general_additional.conf': |
|---|
| 27 | | return $this->generate_queues_general_additional($version); |
|---|
| 28 | | break; |
|---|
| 29 | | } |
|---|
| 30 | | } |
|---|
| 31 | | |
|---|
| 32 | | function addQueuesGeneral($key, $value) { |
|---|
| 33 | | $this->_queues_general[] = array('key' => $key, 'value' => $value); |
|---|
| 34 | | } |
|---|
| 35 | | |
|---|
| 36 | | function generate_queues_additional($ast_version) { |
|---|
| 37 | | |
|---|
| 38 | | global $db; |
|---|
| 39 | | global $amp_conf; |
|---|
| 40 | | |
|---|
| 41 | | $additional = ""; |
|---|
| 42 | | $output = ""; |
|---|
| 43 | | // Asterisk 1.4 does not like blank assignments so just don't put them there |
|---|
| 44 | | // |
|---|
| 45 | | $ver12 = version_compare($ast_version, '1.4', 'lt'); |
|---|
| 46 | | $ver16 = version_compare($ast_version, '1.6', 'ge'); |
|---|
| 47 | | $ast_ge_14_25 = version_compare($ast_version,'1.4.25','ge'); |
|---|
| 48 | | $ast_ge_18 = version_compare($ast_version,'1.8','ge'); |
|---|
| 49 | | |
|---|
| 50 | | // legacy but in case someone was using this we will leave it |
|---|
| 51 | | // |
|---|
| 52 | | $sql = "SELECT keyword,data FROM queues_details WHERE id='-1' AND keyword <> 'account'"; |
|---|
| 53 | | $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); |
|---|
| 54 | | if(DB::IsError($results)) { |
|---|
| 55 | | die($results->getMessage()); |
|---|
| 56 | | } |
|---|
| 57 | | foreach ($results as $result) { |
|---|
| 58 | | if (!$ver12 && trim($result['data']) == '') { |
|---|
| 59 | | continue; |
|---|
| 60 | | } |
|---|
| 61 | | $additional .= $result['keyword']."=".$result['data']."\n"; |
|---|
| 62 | | } |
|---|
| 63 | | |
|---|
| 64 | | if ($ast_ge_14_25) { |
|---|
| 65 | | $devices = array(); |
|---|
| 66 | | $device_results = core_devices_list('all','full',true); |
|---|
| 67 | | if (is_array($device_results)) { |
|---|
| 68 | | foreach ($device_results as $device) { |
|---|
| 69 | | if (!isset($devices[$device['user']]) && $device['devicetype'] == 'fixed') { |
|---|
| 70 | | $devices[$device['user']] = $device['dial']; |
|---|
| 71 | | } |
|---|
| 72 | | } |
|---|
| 73 | | unset($device_results); |
|---|
| 74 | | } |
|---|
| 75 | | } |
|---|
| 76 | | if ($amp_conf['USEQUEUESTATE'] || $ast_ge_14_25) { |
|---|
| 77 | | $users = array(); |
|---|
| 78 | | $user_results = core_users_list(); |
|---|
| 79 | | if (is_array($user_results)) { |
|---|
| 80 | | foreach ($user_results as $user) { |
|---|
| 81 | | $users[$user[0]] = $user[1]; |
|---|
| 82 | | } |
|---|
| 83 | | unset($user_results); |
|---|
| 84 | | } |
|---|
| 85 | | } |
|---|
| 86 | | $results = queues_list(true); |
|---|
| 87 | | foreach ($results as $result) { |
|---|
| 88 | | $output .= "[".$result[0]."]\n"; |
|---|
| 89 | | |
|---|
| 90 | | // passing 2nd param 'true' tells queues_get to send back only queue_conf required params |
|---|
| 91 | | // and nothing else |
|---|
| 92 | | // |
|---|
| 93 | | $results2 = queues_get($result[0], true); |
|---|
| 94 | | |
|---|
| 95 | | // memebers is an array of members so we set it asside and remove it |
|---|
| 96 | | // and then generate each later |
|---|
| 97 | | // |
|---|
| 98 | | $members = $results2['member']; |
|---|
| 99 | | unset($results2['member']); |
|---|
| 100 | | |
|---|
| 101 | | foreach ($results2 as $keyword => $data) { |
|---|
| 102 | | if ($ver12){ |
|---|
| 103 | | switch($keyword){ |
|---|
| 104 | | case 'ringinuse': |
|---|
| 105 | | case 'autofill': |
|---|
| 106 | | break; |
|---|
| 107 | | case 'retry': |
|---|
| 108 | | if ($data == 'none') { |
|---|
| 109 | | $data = 0; |
|---|
| 110 | | } |
|---|
| 111 | | // no break, fallthrough to default |
|---|
| 112 | | default: |
|---|
| 113 | | $output .= $keyword."=".$data."\n"; |
|---|
| 114 | | break; |
|---|
| 115 | | } |
|---|
| 116 | | }else{ |
|---|
| 117 | | switch($keyword){ |
|---|
| 118 | | case (trim($data) == ''): |
|---|
| 119 | | case 'monitor-join': |
|---|
| 120 | | break; |
|---|
| 121 | | case 'monitor-format': |
|---|
| 122 | | if (strtolower($data) != 'no'){ |
|---|
| 123 | | $output .= "monitor-type=mixmonitor\n"; |
|---|
| 124 | | $output .= $keyword."=".$data."\n"; |
|---|
| 125 | | } |
|---|
| 126 | | break; |
|---|
| 127 | | case 'announce-position': |
|---|
| 128 | | if ($ver16) { |
|---|
| 129 | | $output .= $keyword."=".$data."\n"; |
|---|
| 130 | | } |
|---|
| 131 | | break; |
|---|
| 132 | | case 'retry': |
|---|
| 133 | | if ($data == 'none') { |
|---|
| 134 | | $data = 0; |
|---|
| 135 | | } |
|---|
| 136 | | // no break, fallthrough to default |
|---|
| 137 | | default: |
|---|
| 138 | | $output .= $keyword."=".$data."\n"; |
|---|
| 139 | | break; |
|---|
| 140 | | } |
|---|
| 141 | | } |
|---|
| 142 | | } |
|---|
| 143 | | |
|---|
| 144 | | // Now pull out all the memebers, one line for each |
|---|
| 145 | | // |
|---|
| 146 | | if ($ast_ge_18 || $amp_conf['USEQUEUESTATE']) { |
|---|
| 147 | | foreach ($members as $member) { |
|---|
| 148 | | preg_match("/^Local\/([\d]+)\@*/",$member,$matches); |
|---|
| 149 | | if (isset($matches[1]) && isset($users[$matches[1]])) { |
|---|
| 150 | | $name = $users[$matches[1]]; |
|---|
| 151 | | str_replace(',','\,',$name); |
|---|
| 152 | | |
|---|
| 153 | | $qnostate = queues_get_qnostate($matches[1]); |
|---|
| 154 | | if ($qnostate == 'ignorestate') { |
|---|
| 155 | | freepbx_log(FPBX_LOG_NOTICE,"Ignoring State information for Queue Member: ".$matches[1]); |
|---|
| 156 | | $output .= "member=$member,$name\n"; |
|---|
| 157 | | } else { |
|---|
| 158 | | $output .= "member=$member,$name,hint:".$matches[1]."@ext-local\n"; |
|---|
| 159 | | } |
|---|
| 160 | | } else { |
|---|
| 161 | | $output .= "member=".$member."\n"; |
|---|
| 162 | | } |
|---|
| 163 | | } |
|---|
| 164 | | } else if ($ast_ge_14_25) { |
|---|
| 165 | | foreach ($members as $member) { |
|---|
| 166 | | preg_match("/^Local\/([\d]+)\@*/",$member,$matches); |
|---|
| 167 | | if (isset($matches[1]) && isset($devices[$matches[1]])) { |
|---|
| 168 | | $name = $users[$matches[1]]; |
|---|
| 169 | | str_replace(',','\,',$name); |
|---|
| 170 | | $qnostate = queues_get_qnostate($matches[1]); |
|---|
| 171 | | if ($qnostate == 'ignorestate') { |
|---|
| 172 | | freepbx_log(FPBX_LOG_NOTICE,"Ignoring State information for Queue Member: ".$matches[1]); |
|---|
| 173 | | $output .= "member=$member,$name\n"; |
|---|
| 174 | | } else { |
|---|
| 175 | | $output .= "member=$member,$name,".$devices[$matches[1]]."\n"; |
|---|
| 176 | | } |
|---|
| 177 | | } else { |
|---|
| 178 | | $output .= "member=".$member."\n"; |
|---|
| 179 | | } |
|---|
| 180 | | } |
|---|
| 181 | | } else { |
|---|
| 182 | | foreach ($members as $member) { |
|---|
| 183 | | $output .= "member=".$member."\n"; |
|---|
| 184 | | } |
|---|
| 185 | | } |
|---|
| 186 | | $output .= $additional."\n"; |
|---|
| 187 | | } |
|---|
| 188 | | |
|---|
| 189 | | // Before returning the results, do an integrity check to see |
|---|
| 190 | | // if there are any truncated compound recrodings and if so |
|---|
| 191 | | // crate a noticication. |
|---|
| 192 | | // |
|---|
| 193 | | $nt = notifications::create($db); |
|---|
| 194 | | |
|---|
| 195 | | $compound_recordings = queues_check_compoundrecordings(); |
|---|
| 196 | | if (empty($compound_recordings)) { |
|---|
| 197 | | $nt->delete('queues', 'COMPOUNDREC'); |
|---|
| 198 | | } else { |
|---|
| 199 | | $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 />"); |
|---|
| 200 | | foreach ($compound_recordings as $item) { |
|---|
| 201 | | $str .= sprintf(_("Queue - %s (%s): %s<br />"), $item['extension'], $item['descr'], $item['error']); |
|---|
| 202 | | } |
|---|
| 203 | | $nt->add_error('queues', 'COMPOUNDREC', _("Compound Recordings in Queues Detected"), $str); |
|---|
| 204 | | } |
|---|
| 205 | | return $output; |
|---|
| 206 | | } |
|---|
| 207 | | |
|---|
| 208 | | function generate_queues_general_additional($ast_version) { |
|---|
| 209 | | $output = ''; |
|---|
| 210 | | |
|---|
| 211 | | if (isset($this->_queues_general) && is_array($this->_queues_general)) { |
|---|
| 212 | | foreach ($this->_queues_general as $values) { |
|---|
| 213 | | $output .= $values['key']."=".$values['value']."\n"; |
|---|
| 214 | | } |
|---|
| 215 | | } |
|---|
| 216 | | return $output; |
|---|
| 217 | | } |
|---|
| 218 | | } |
|---|
| 219 | | |
|---|
| 220 | | // The destinations this module provides |
|---|
| 221 | | // returns a associative arrays with keys 'destination' and 'description' |
|---|
| 222 | | function queues_destinations() { |
|---|
| 223 | | //get the list of all exisiting |
|---|
| 224 | | $results = queues_list(true); |
|---|
| 225 | | |
|---|
| 226 | | //return an associative array with destination and description |
|---|
| 227 | | if (isset($results)) { |
|---|
| 228 | | foreach($results as $result){ |
|---|
| 229 | | $extens[] = array('destination' => 'ext-queues,'.$result['0'].',1', 'description' => $result['1'].' <'.$result['0'].'>'); |
|---|
| 230 | | } |
|---|
| 231 | | } |
|---|
| 232 | | |
|---|
| 233 | | if (isset($extens)) |
|---|
| 234 | | return $extens; |
|---|
| 235 | | else |
|---|
| 236 | | return null; |
|---|
| 237 | | } |
|---|
| 238 | | |
|---|
| 239 | | function queues_getdest($exten) { |
|---|
| 240 | | return array('ext-queues,'.$exten.',1'); |
|---|
| 241 | | } |
|---|
| 242 | | |
|---|
| 243 | | function queues_getdestinfo($dest) { |
|---|
| 244 | | global $active_modules; |
|---|
| 245 | | |
|---|
| 246 | | if (substr(trim($dest),0,11) == 'ext-queues,') { |
|---|
| 247 | | $exten = explode(',',$dest); |
|---|
| 248 | | $exten = $exten[1]; |
|---|
| 249 | | $thisexten = queues_get($exten); |
|---|
| 250 | | if (empty($thisexten)) { |
|---|
| 251 | | return array(); |
|---|
| 252 | | } else { |
|---|
| 253 | | //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup'; |
|---|
| 254 | | return array('description' => sprintf(_("Queue %s : %s"),$exten,$thisexten['name']), |
|---|
| 255 | | 'edit_url' => 'config.php?display=queues&extdisplay='.urlencode($exten), |
|---|
| 256 | | ); |
|---|
| 257 | | } |
|---|
| 258 | | } else { |
|---|
| 259 | | return false; |
|---|
| 260 | | } |
|---|
| 261 | | } |
|---|
| 262 | | |
|---|
| 263 | | function queues_recordings_usage($recording_id) { |
|---|
| 264 | | global $active_modules; |
|---|
| 265 | | |
|---|
| 266 | | $results = sql("SELECT `extension`, `descr` FROM `queues_config` WHERE `agentannounce_id` = '$recording_id' OR `joinannounce_id` = '$recording_id'","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 267 | | if (empty($results)) { |
|---|
| 268 | | return array(); |
|---|
| 269 | | } else { |
|---|
| 270 | | //$type = isset($active_modules['queues']['type'])?$active_modules['queues']['type']:'setup'; |
|---|
| 271 | | foreach ($results as $result) { |
|---|
| 272 | | $usage_arr[] = array( |
|---|
| 273 | | 'url_query' => 'config.php?display=queues&extdisplay='.urlencode($result['extension']), |
|---|
| 274 | | 'description' => sprintf(_("Queue: %s"),$result['descr']), |
|---|
| 275 | | ); |
|---|
| 276 | | } |
|---|
| 277 | | return $usage_arr; |
|---|
| 278 | | } |
|---|
| 279 | | } |
|---|
| 280 | | |
|---|
| 281 | | function queues_ivr_usage($ivr_id) { |
|---|
| 282 | | global $active_modules; |
|---|
| 283 | | |
|---|
| 284 | | $results = sql("SELECT `extension`, `descr` FROM `queues_config` WHERE `ivr_id` = '$ivr_id'","getAll",DB_FETCHMODE_ASSOC); |
|---|
| 285 | | if (empty($results)) { |
|---|
| 286 | | return array(); |
|---|
| 287 | | } else { |
|---|
| 288 | | foreach ($results as $result) { |
|---|
| 289 | | $usage_arr[] = array( |
|---|
| 290 | | 'url_query' => 'config.php?display=queues&extdisplay='.urlencode($result['extension']), |
|---|
| 291 | | 'description' => sprintf(_("Queue: %s"),$result['descr']), |
|---|
| 292 | | ); |
|---|
| 293 | | } |
|---|
| 294 | | return $usage_arr; |
|---|
| 295 | | } |
|---|
| 296 | | } |
|---|
| 297 | | |
|---|
| 298 | | /* Generates dialplan for "queues" components (extensions & inbound routing) |
|---|
| 299 | | We call this with retrieve_conf |
|---|
| 300 | | */ |
|---|
| 301 | | function queues_get_config($engine) { |
|---|
| 302 | | global $ext; // is this the best way to pass this? |
|---|
| 303 | | global $queues_conf; |
|---|
| 304 | | global $amp_conf; |
|---|
| 305 | | global $version; |
|---|
| 306 | | |
|---|
| 307 | | switch($engine) { |
|---|
| 308 | | case "asterisk": |
|---|
| 309 | | global $astman; |
|---|
| 310 | | |
|---|
| 311 | | $ast_ge_14 = version_compare($version,'1.4','ge'); |
|---|
| 312 | | $ast_ge_16 = version_compare($version,'1.6','ge'); |
|---|
| 313 | | $ast_ge_14_25 = version_compare($version,'1.4.25','ge'); |
|---|
| 314 | | $ast_ge_18 = version_compare($version,'1.8','ge'); |
|---|
| 315 | | |
|---|
| 316 | | $has_extension_state = $ast_ge_16; |
|---|
| 317 | | if ($ast_ge_14 && !$ast_ge_16) { |
|---|
| 318 | | $response = $astman->send_request('Command', array('Command' => 'module show like func_extstate')); |
|---|
| 319 | | if (preg_match('/1 modules loaded/', $response['data'])) { |
|---|
| 320 | | $has_extension_state = true; |
|---|
| 321 | | } |
|---|
| 322 | | } |
|---|
| 323 | | |
|---|
| 324 | | if (isset($queues_conf) && is_a($queues_conf, "queues_conf")) { |
|---|
| 325 | | $queues_conf->addQueuesGeneral('persistentmembers',$amp_conf['QUEUES_PESISTENTMEMBERS'] ? 'yes' : 'no'); |
|---|
| 326 | | if ($ast_ge_16) { |
|---|
| 327 | | $queues_conf->addQueuesGeneral('shared_lastcall',$amp_conf['QUEUES_SHARED_LASTCALL'] ? 'yes' : 'no'); |
|---|
| 328 | | $queues_conf->addQueuesGeneral('updatecdr',$amp_conf['QUEUES_UPDATECDR'] ? 'yes' : 'no'); |
|---|
| 329 | | } |
|---|
| 330 | | if ($amp_conf['QUEUES_MIX_MONITOR']) { |
|---|
| 331 | | $queues_conf->addQueuesGeneral('monitor-type', 'MixMonitor'); |
|---|
| 332 | | } |
|---|
| 333 | | } |
|---|
| 334 | | |
|---|
| 335 | | /* queue extensions */ |
|---|
| 336 | | $ext->addInclude('from-internal-additional','ext-queues'); |
|---|
| 337 | | /* Trial DEVSTATE */ |
|---|
| 338 | | if ($amp_conf['USEDEVSTATE']) { |
|---|
| 339 | | $ext->addGlobal('QUEDEVSTATE','TRUE'); |
|---|
| 340 | | } |
|---|
| 341 | | // $que_code = '*45'; |
|---|
| 342 | | $fcc = new featurecode('queues', 'que_toggle'); |
|---|
| 343 | | $que_code = $fcc->getCodeActive(); |
|---|
| 344 | | unset($fcc); |
|---|
| 345 | | if ($que_code != '') { |
|---|
| 346 | | queue_app_toggle($que_code); |
|---|
| 347 | | queue_app_all_toggle(); |
|---|
| 348 | | queue_agent_del_toggle(); |
|---|
| 349 | | queue_agent_add_toggle(); |
|---|
| 350 | | } |
|---|
| 351 | | $qlist = queues_list(true); |
|---|
| 352 | | |
|---|
| 353 | | $from_queue_exten_only = 'from-queue-exten-only'; |
|---|
| 354 | | $from_queue_exten_internal = 'from-queue-exten-internal'; |
|---|
| 355 | | |
|---|
| 356 | | if (!empty($qlist)) { |
|---|
| 357 | | foreach($qlist as $item) { |
|---|
| 358 | | |
|---|
| 359 | | $exten = $item[0]; |
|---|
| 360 | | $q = queues_get($exten); |
|---|
| 361 | | |
|---|
| 362 | | $grppre = (isset($q['prefix'])?$q['prefix']:''); |
|---|
| 363 | | $alertinfo = (isset($q['alertinfo'])?$q['alertinfo']:''); |
|---|
| 364 | | |
|---|
| 365 | | // Not sure why someone would ever have a ; in the regex, but since Asterisk has problems with them |
|---|
| 366 | | // it would need to be escaped |
|---|
| 367 | | // |
|---|
| 368 | | $qregex = (isset($q['qregex'])?$q['qregex']:''); |
|---|
| 369 | | str_replace(';','\;',$qregex); |
|---|
| 370 | | |
|---|
| 371 | | $ext->add('ext-queues', $exten, '', new ext_macro('user-callerid')); |
|---|
| 372 | | |
|---|
| 373 | | if (isset($q['qnoanswer']) && $q['qnoanswer'] == FALSE) { |
|---|
| 374 | | $ext->add('ext-queues', $exten, '', new ext_answer('')); |
|---|
| 375 | | } else { |
|---|
| 376 | | // TODO: should this only be set if noanswer + (!ringtones || joinannounce)??? |
|---|
| 377 | | $ext->add('ext-queues', $exten, '', new ext_progress()); |
|---|
| 378 | | } |
|---|
| 379 | | |
|---|
| 380 | | // block voicemail until phone is answered at which point a macro should be called on the answering |
|---|
| 381 | | // line to clear this flag so that subsequent transfers can occur. |
|---|
| 382 | | // |
|---|
| 383 | | if ($q['queuewait']) { |
|---|
| 384 | | $ext->add('ext-queues', $exten, '', new ext_execif('$["${QUEUEWAIT}" = ""]', 'Set', '__QUEUEWAIT=${EPOCH}')); |
|---|
| 385 | | } |
|---|
| 386 | | // If extension_only don't do this and CFIGNORE |
|---|
| 387 | | if($q['use_queue_context'] != '2') { |
|---|
| 388 | | $ext->add('ext-queues', $exten, '', new ext_macro('blkvm-set', 'reset')); |
|---|
| 389 | | $ext->add('ext-queues', $exten, '', new ext_execif('$["${REGEX("(M[(]auto-blkvm[)])" ${DIAL_OPTIONS})}" != "1"]', 'Set', '_DIAL_OPTIONS=${DIAL_OPTIONS}M(auto-blkvm)')); |
|---|
| 390 | | } |
|---|
| 391 | | |
|---|
| 392 | | // Inform all the children NOT to send calls to destinations or voicemail |
|---|
| 393 | | // |
|---|
| 394 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__NODEST', '${EXTEN}')); |
|---|
| 395 | | |
|---|
| 396 | | // deal with group CID prefix |
|---|
| 397 | | if ($grppre != '') { |
|---|
| 398 | | $ext->add('ext-queues', $exten, '', new ext_macro('prepend-cid', $grppre)); |
|---|
| 399 | | } |
|---|
| 400 | | |
|---|
| 401 | | // Set Alert_Info |
|---|
| 402 | | if ($alertinfo != '') { |
|---|
| 403 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__ALERT_INFO', str_replace(';', '\;', $alertinfo))); |
|---|
| 404 | | } |
|---|
| 405 | | $record_mode = $q['monitor-format'] ? 'always' : 'dontcare'; |
|---|
| 406 | | if ($q['monitor-format']) { |
|---|
| 407 | | $ext->add('ext-queues', $exten, '', new ext_set('__MIXMON_FORMAT', $q['monitor-format'])); |
|---|
| 408 | | } |
|---|
| 409 | | $ext->add('ext-queues', $exten, '', new ext_gosub('1','s','sub-record-check',"q,$exten,$record_mode")); |
|---|
| 410 | | |
|---|
| 411 | | if ($amp_conf['QUEUES_MIX_MONITOR']) { |
|---|
| 412 | | $monitor_options = ''; |
|---|
| 413 | | if (isset($q['monitor_type']) && $q['monitor_type'] != '') { |
|---|
| 414 | | $monitor_options .= 'b'; |
|---|
| 415 | | } |
|---|
| 416 | | if (isset($q['monitor_spoken']) && $q['monitor_spoken'] != 0) { |
|---|
| 417 | | $monitor_options .= 'V('.$q['monitor_spoken'].')'; |
|---|
| 418 | | } |
|---|
| 419 | | if (isset($q['monitor_heard']) && $q['monitor_heard'] != 0) { |
|---|
| 420 | | $monitor_options .= 'v('.$q['monitor_heard'].')'; |
|---|
| 421 | | } |
|---|
| 422 | | if ($monitor_options != '') { |
|---|
| 423 | | $ext->add('ext-queues', $exten, '', new ext_setvar('MONITOR_OPTIONS', $monitor_options )); |
|---|
| 424 | | } |
|---|
| 425 | | } |
|---|
| 426 | | $joinannounce_id = (isset($q['joinannounce_id'])?$q['joinannounce_id']:''); |
|---|
| 427 | | if($joinannounce_id) { |
|---|
| 428 | | $joinannounce = recordings_get_file($joinannounce_id); |
|---|
| 429 | | |
|---|
| 430 | | if (isset($q['qnoanswer']) && $q['qnoanswer'] == TRUE) { |
|---|
| 431 | | $joinannounce = $joinannounce.', noanswer'; |
|---|
| 432 | | } |
|---|
| 433 | | |
|---|
| 434 | | $ext->add('ext-queues', $exten, '', new ext_playback($joinannounce)); |
|---|
| 435 | | } |
|---|
| 436 | | $options = 't'; |
|---|
| 437 | | if ($ast_ge_18) { |
|---|
| 438 | | if (isset($q['answered_elsewhere']) && $q['answered_elsewhere'] == '1'){ |
|---|
| 439 | | $options .= 'C'; |
|---|
| 440 | | } |
|---|
| 441 | | } |
|---|
| 442 | | if ($q['rtone'] == 1) { |
|---|
| 443 | | $options .= 'r'; |
|---|
| 444 | | } |
|---|
| 445 | | if ($q['retry'] == 'none'){ |
|---|
| 446 | | $options .= 'n'; |
|---|
| 447 | | } |
|---|
| 448 | | if (isset($q['music'])) { |
|---|
| 449 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__MOHCLASS', $q['music'])); |
|---|
| 450 | | } |
|---|
| 451 | | // Set CWIGNORE if enabled so that busy agents don't have another line key ringing and |
|---|
| 452 | | // stalling the ACD. |
|---|
| 453 | | if ($q['cwignore'] == 1 || $q['cwignore'] == 2 ) { |
|---|
| 454 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__CWIGNORE', 'TRUE')); |
|---|
| 455 | | } |
|---|
| 456 | | if ($q['use_queue_context']) { |
|---|
| 457 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__CFIGNORE', 'TRUE')); |
|---|
| 458 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__FORWARD_CONTEXT', 'block-cf')); |
|---|
| 459 | | } |
|---|
| 460 | | $agentannounce_id = (isset($q['agentannounce_id'])?$q['agentannounce_id']:''); |
|---|
| 461 | | if ($agentannounce_id) { |
|---|
| 462 | | $agentannounce = recordings_get_file($agentannounce_id); |
|---|
| 463 | | } else { |
|---|
| 464 | | $agentannounce = ''; |
|---|
| 465 | | } |
|---|
| 466 | | |
|---|
| 467 | | if ($q['callconfirm'] == 1) { |
|---|
| 468 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__FORCE_CONFIRM', '${CHANNEL}')); |
|---|
| 469 | | if ($amp_conf['AST_FUNC_SHARED']) { |
|---|
| 470 | | $ext->add('ext-queues', $exten, '', new ext_setvar('SHARED(ANSWER_STATUS)','NOANSWER')); |
|---|
| 471 | | } |
|---|
| 472 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__CALLCONFIRMCID', '${CALLERID(number)}')); |
|---|
| 473 | | $callconfirm_id = (isset($q['callconfirm_id']))?$q['callconfirm_id']:''; |
|---|
| 474 | | if ($callconfirm_id) { |
|---|
| 475 | | $callconfirm = recordings_get_file($callconfirm_id); |
|---|
| 476 | | } else { |
|---|
| 477 | | $callconfirm = ''; |
|---|
| 478 | | } |
|---|
| 479 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__ALT_CONFIRM_MSG', $callconfirm)); |
|---|
| 480 | | } |
|---|
| 481 | | $ext->add('ext-queues', $exten, '', new ext_queuelog($exten,'${UNIQUEID}','NONE','DID', '${FROM_DID}')); |
|---|
| 482 | | $ext->add('ext-queues', $exten, '', new ext_queue($exten,$options,'',$agentannounce,$q['maxwait'])); |
|---|
| 483 | | |
|---|
| 484 | | if($q['use_queue_context'] != '2') { |
|---|
| 485 | | $ext->add('ext-queues', $exten, '', new ext_macro('blkvm-clr')); |
|---|
| 486 | | } |
|---|
| 487 | | // cancel any recording previously requested |
|---|
| 488 | | // |
|---|
| 489 | | $ext->add('ext-queues', $exten, '', new ext_gosub('1','s','sub-record-cancel')); |
|---|
| 490 | | // If we are here, disable the NODEST as we want things to resume as normal |
|---|
| 491 | | // |
|---|
| 492 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__NODEST', '')); |
|---|
| 493 | | |
|---|
| 494 | | if ($q['callconfirm'] == 1) { |
|---|
| 495 | | if ($amp_conf['AST_FUNC_SHARED']) { |
|---|
| 496 | | $ext->add('ext-queues', $exten, '', new ext_setvar('SHARED(ANSWER_STATUS)', '')); |
|---|
| 497 | | } |
|---|
| 498 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__FORCE_CONFIRM', '')); |
|---|
| 499 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__ALT_CONFIRM_MSG', '')); |
|---|
| 500 | | } |
|---|
| 501 | | |
|---|
| 502 | | if($monitor_options != '') { |
|---|
| 503 | | $ext->add('ext-queues', $exten, '', new ext_setvar('MONITOR_OPTIONS', '')); |
|---|
| 504 | | } |
|---|
| 505 | | if ($q['cwignore'] == 1 || $q['cwignore'] == 2 ) { |
|---|
| 506 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__CWIGNORE', '')); |
|---|
| 507 | | } |
|---|
| 508 | | if ($q['use_queue_context']) { |
|---|
| 509 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__CFIGNORE', '')); |
|---|
| 510 | | $ext->add('ext-queues', $exten, '', new ext_setvar('__FORWARD_CONTEXT', 'from-internal')); |
|---|
| 511 | | } |
|---|
| 512 | | |
|---|
| 513 | | // destination field in 'incoming' database is backwards from what ext_goto expects |
|---|
| 514 | | $goto_context = strtok($q['goto'],','); |
|---|
| 515 | | $goto_exten = strtok(','); |
|---|
| 516 | | $goto_pri = strtok(','); |
|---|
| 517 | | |
|---|
| 518 | | $ext->add('ext-queues', $exten, '', new ext_goto($goto_pri,$goto_exten,$goto_context)); |
|---|
| 519 | | |
|---|
| 520 | | //dynamic agent login/logout |
|---|
| 521 | | if (trim($qregex) != '') { |
|---|
| 522 | | $ext->add('ext-queues', $exten."*", '', new ext_setvar('QREGEX', $qregex)); |
|---|
| 523 | | } |
|---|
| 524 | | if($q['use_queue_context'] == '2') { |
|---|
| 525 | | $ext->add('ext-queues', $exten."*", '', new ext_macro('agent-add',$exten.",".$q['password'].",EXTEN")); |
|---|
| 526 | | } else { |
|---|
| 527 | | $ext->add('ext-queues', $exten."*", '', new ext_macro('agent-add',$exten.",".$q['password'])); |
|---|
| 528 | | } |
|---|
| 529 | | $ext->add('ext-queues', $exten."**", '', new ext_macro('agent-del',"$exten")); |
|---|
| 530 | | if ($que_code != '') { |
|---|
| 531 | | $ext->add('ext-queues', $que_code.$exten, '', new ext_setvar('QUEUENO',$exten)); |
|---|
| 532 | | $ext->add('ext-queues', $que_code.$exten, '', new ext_goto('start','s','app-queue-toggle')); |
|---|
| 533 | | } |
|---|
| 534 | | /* Trial Devstate */ |
|---|
| 535 | | // Create Hints for Devices and Add Astentries for Users |
|---|
| 536 | | // Clean up the Members array |
|---|
| 537 | | if ($q['togglehint'] && $amp_conf['USEDEVSTATE'] && $que_code != '') { |
|---|
| 538 | | if (!isset($device_list)) { |
|---|
| 539 | | $device_list = core_devices_list("all", 'full', true); |
|---|
| 540 | | } |
|---|
| 541 | | if ($astman) { |
|---|
| 542 | | if (($dynmemberonly = strtolower($astman->database_get('QPENALTY/'.$exten,'dynmemberonly')) == 'yes') == true) { |
|---|
| 543 | | $get=$astman->database_show('QPENALTY/'.$exten.'/agents'); |
|---|
| 544 | | if($get){ |
|---|
| 545 | | $mem = array(); |
|---|
| 546 | | foreach($get as $key => $value){ |
|---|
| 547 | | $key=explode('/',$key); |
|---|
| 548 | | $mem[$key[4]]=$value; |
|---|
| 549 | | } |
|---|
| 550 | | } |
|---|
| 551 | | } |
|---|
| 552 | | } else { |
|---|
| 553 | | fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 554 | | } |
|---|
| 555 | | foreach ($device_list as $device) { |
|---|
| 556 | | if ((!$dynmemberonly||$device['devicetype']=='adhoc'||isset($mem[$device['user']]))&&($device['tech']=='sip'||$device['tech']=='iax2')) { |
|---|
| 557 | | $ext->add('ext-queues', $que_code.$device['id'].'*'.$exten, '', new ext_setvar('QUEUENO',$exten)); |
|---|
| 558 | | $ext->add('ext-queues', $que_code.$device['id'].'*'.$exten, '', new ext_goto('start','s','app-queue-toggle')); |
|---|
| 559 | | $ext->addHint('ext-queues', $que_code.$device['id'].'*'.$exten, "Custom:QUEUE".$device['id'].'*'.$exten); |
|---|
| 560 | | } |
|---|
| 561 | | } |
|---|
| 562 | | } |
|---|
| 563 | | |
|---|
| 564 | | // Add routing vector to direct which context call should go |
|---|
| 565 | | // |
|---|
| 566 | | $agent_context = isset($q['use_queue_context']) && $q['use_queue_context'] && isset($queue_context) ? $queue_context : 'from-internal'; |
|---|
| 567 | | switch ($q['use_queue_context']) { |
|---|
| 568 | | case 1: |
|---|
| 569 | | $agent_context = $from_queue_exten_internal; |
|---|
| 570 | | break; |
|---|
| 571 | | case 2: |
|---|
| 572 | | $agent_context = $from_queue_exten_only; |
|---|
| 573 | | break; |
|---|
| 574 | | case 0: |
|---|
| 575 | | default: |
|---|
| 576 | | $agent_context = 'from-internal'; |
|---|
| 577 | | break; |
|---|
| 578 | | } |
|---|
| 579 | | $ext->add('from-queue', $exten, '', new ext_goto('1','${QAGENT}',$agent_context)); |
|---|
| 580 | | } |
|---|
| 581 | | // Create *45 all queue toggle |
|---|
| 582 | | // |
|---|
| 583 | | if ($que_code != '') { |
|---|
| 584 | | $ext->add('ext-queues', $que_code, '', new ext_goto('start','s','app-all-queue-toggle')); |
|---|
| 585 | | } |
|---|
| 586 | | } |
|---|
| 587 | | // We need to have a hangup here, if call is ended by the caller during Playback it will end in the |
|---|
| 588 | | // h context and do a proper hangup and clean the blkvm if set, see #4671 |
|---|
| 589 | | $ext->add('ext-queues', 'h', '', new ext_macro('hangupcall')); |
|---|
| 590 | | // NODEST will be the queue that this came from, so we will vector though an entry to determine the context the |
|---|
| 591 | | // agent should be delivered to. All queue calls come here, this decides if the should go direct to from-internal |
|---|
| 592 | | // or indirectly through from-queue-exten-only to trap extension calls and avoid their follow-me, etc. |
|---|
| 593 | | // |
|---|
| 594 | | $ext->add('from-queue', '_.', '', new ext_setvar('QAGENT','${EXTEN}')); |
|---|
| 595 | | $ext->add('from-queue', '_.', '', new ext_goto('1','${NODEST}')); |
|---|
| 596 | | |
|---|
| 597 | | $ext->addInclude($from_queue_exten_internal,$from_queue_exten_only); |
|---|
| 598 | | $ext->addInclude($from_queue_exten_internal,'from-internal'); |
|---|
| 599 | | $ext->add($from_queue_exten_internal, 'foo', '', new ext_noop('bar')); |
|---|
| 600 | | |
|---|
| 601 | | /* create a context, from-queue-exten-only, that can be used for queues that want behavir similar to |
|---|
| 602 | | * ringgroup where only the agent's phone will be rung, no follow-me will be pursued. |
|---|
| 603 | | */ |
|---|
| 604 | | $userlist = core_users_list(); |
|---|
| 605 | | if (is_array($userlist)) { |
|---|
| 606 | | foreach($userlist as $item) { |
|---|
| 607 | | $ext->add($from_queue_exten_only, $item[0], '', new ext_setvar('RingGroupMethod', 'none')); |
|---|
| 608 | | $ext->add($from_queue_exten_only, $item[0], 'checkrecord', new ext_gosub('1','s','sub-record-check',"exten," . $item[0])); |
|---|
| 609 | | if ($has_extension_state) { |
|---|
| 610 | | $ext->add($from_queue_exten_only, $item[0], '', new ext_macro('dial-one',',${DIAL_OPTIONS},'.$item[0])); |
|---|
| 611 | | } else { |
|---|
| 612 | | $ext->add($from_queue_exten_only, $item[0], '', new ext_macro('dial',',${DIAL_OPTIONS},'.$item[0])); |
|---|
| 613 | | } |
|---|
| 614 | | $ext->add($from_queue_exten_only, $item[0], '', new ext_hangup()); |
|---|
| 615 | | } |
|---|
| 616 | | $ext->add($from_queue_exten_only, 'h', '', new ext_macro('hangupcall')); |
|---|
| 617 | | } |
|---|
| 618 | | |
|---|
| 619 | | /* |
|---|
| 620 | | * Adds a dynamic agent/member to a Queue |
|---|
| 621 | | * Prompts for call-back number - in not entered, uses CIDNum |
|---|
| 622 | | */ |
|---|
| 623 | | |
|---|
| 624 | | $context = 'macro-agent-add'; |
|---|
| 625 | | $exten = 's'; |
|---|
| 626 | | |
|---|
| 627 | | $ext->add($context, $exten, '', new ext_wait(1)); |
|---|
| 628 | | $ext->add($context, $exten, '', new ext_macro('user-callerid', 'SKIPTTL')); |
|---|
| 629 | | $ext->add($context, $exten, 'a3', new ext_read('CALLBACKNUM', 'agent-login')); // get callback number from user |
|---|
| 630 | | $ext->add($context, $exten, '', new ext_gotoif('$[${LEN(${CALLBACKNUM})}=0]','a5','a7')); // if user just pressed # or timed out, use cidnum |
|---|
| 631 | | $ext->add($context, $exten, 'a5', new ext_set('CALLBACKNUM', '${IF($[${LEN(${AMPUSER})}=0]?${CALLERID(number)}:${AMPUSER})}')); |
|---|
| 632 | | |
|---|
| 633 | | if ($ast_ge_14_25) { |
|---|
| 634 | | $ext->add($context, $exten, '', new ext_set('THISDEVICE', '${DB(DEVICE/${REALCALLERIDNUM}/dial)}')); |
|---|
| 635 | | } |
|---|
| 636 | | $ext->add($context, $exten, '', new ext_gotoif('$["${CALLBACKNUM}" = ""]', 'a3')); // if still no number, start over |
|---|
| 637 | | $ext->add($context, $exten, 'a7', new ext_gotoif('$["${CALLBACKNUM}" = "${ARG1}"]', 'invalid')); // Error, they put in the queue number |
|---|
| 638 | | |
|---|
| 639 | | // If this is an extension only queue then EXTEN is passed as ARG3 and we make sure this is a valid extension being entered |
|---|
| 640 | | // |
|---|
| 641 | | $ext->add($context, $exten, '', new ext_gotoif('$["${ARG3}" = "EXTEN" & ${DB_EXISTS(AMPUSER/${CALLBACKNUM}/cidname)} = 0]', 'invalid')); |
|---|
| 642 | | |
|---|
| 643 | | // If this is a restricted dynamic agent queue then check to make sure they are allowed |
|---|
| 644 | | // |
|---|
| 645 | | $ext->add($context, $exten, '', new ext_gotoif('$["${DB(QPENALTY/${ARG1}/dynmemberonly)}" = "yes" & ${DB_EXISTS(QPENALTY/${ARG1}/agents/${CALLBACKNUM})} != 1]', 'invalid')); |
|---|
| 646 | | |
|---|
| 647 | | $ext->add($context, $exten, '', new ext_execif('$["${QREGEX}" != ""]', 'GotoIf', '$["${REGEX("${QREGEX}" ${CALLBACKNUM})}" = "0"]?invalid')); |
|---|
| 648 | | $ext->add($context, $exten, '', new ext_execif('$["${ARG2}" != ""]', 'Authenticate', '${ARG2}')); |
|---|
| | 3 | include_once(dirname(__FILE__) . '/destination_registry.php'); |
|---|
| | 4 | include_once(dirname(__FILE__) . '/dialplan.php'); |
|---|
| | 5 | include_once(dirname(__FILE__) . '/hook_core.php'); |
|---|
| | 6 | include_once(dirname(__FILE__) . '/hook_ivr.php'); |
|---|
| | 7 | include_once(dirname(__FILE__) . '/geters_seters.php'); |
|---|
| | 8 | include_once(dirname(__FILE__) . '/queue_conf.php'); |
|---|
| 723 | | function queues_add($account,$name,$password,$prefix,$goto,$agentannounce_id,$members,$joinannounce_id,$maxwait,$alertinfo='',$cwignore='0',$qregex='',$queuewait='0', $use_queue_context='0', $dynmembers = '', $dynmemberonly = 'no', $togglehint = '0', $qnoanswer = '0', $callconfirm = '0', $callconfirm_id, $monitor_type = '', $monitor_heard = '0', $monitor_spoken = '0', $answered_elsewhere = '0') { |
|---|
| 724 | | global $db,$astman,$amp_conf; |
|---|
| 725 | | |
|---|
| 726 | | $ast_ge_16 = version_compare($amp_conf['ASTVERSION'] , '1.6', 'ge'); |
|---|
| 727 | | $ast_ge_18 = version_compare($amp_conf['ASTVERSION'] , '1.8', 'ge'); |
|---|
| 728 | | |
|---|
| 729 | | if (trim($account) == '') { |
|---|
| 730 | | echo "<script>javascript:alert('"._("Bad Queue Number, can not be blank")."');</script>"; |
|---|
| 731 | | return false; |
|---|
| 732 | | } |
|---|
| 733 | | |
|---|
| 734 | | //add to extensions table |
|---|
| 735 | | if (empty($agentannounce_id)) { |
|---|
| 736 | | $agentannounce_id=""; |
|---|
| 737 | | } |
|---|
| 738 | | |
|---|
| 739 | | $fields = array( |
|---|
| 740 | | array($account,'maxlen',($_REQUEST['maxlen'])?$_REQUEST['maxlen']:'0',0), |
|---|
| 741 | | array($account,'joinempty',($_REQUEST['joinempty'])?$_REQUEST['joinempty']:'yes',0), |
|---|
| 742 | | array($account,'leavewhenempty',($_REQUEST['leavewhenempty'])?$_REQUEST['leavewhenempty']:'no',0), |
|---|
| 743 | | array($account,'strategy',($_REQUEST['strategy'])?$_REQUEST['strategy']:'ringall',0), |
|---|
| 744 | | array($account,'timeout',(isset($_REQUEST['timeout']))?$_REQUEST['timeout']:'15',0), |
|---|
| 745 | | array($account,'retry',(isset($_REQUEST['retry']) && $_REQUEST['retry'] != '')?$_REQUEST['retry']:'5',0), |
|---|
| 746 | | array($account,'wrapuptime',($_REQUEST['wrapuptime'])?$_REQUEST['wrapuptime']:'0',0), |
|---|
| 747 | | array($account,'announce-frequency',($_REQUEST['announcefreq'])?$_REQUEST['announcefreq']:'0',0), |
|---|
| 748 | | array($account,'announce-holdtime',($_REQUEST['announceholdtime'])?$_REQUEST['announceholdtime']:'no',0), |
|---|
| 749 | | array($account,'announce-position',($_REQUEST['announceposition'])?$_REQUEST['announceposition']:'no',0), |
|---|
| 750 | | array($account,'queue-youarenext',($_REQUEST['announceposition']=='no')?'silence/1':'queue-youarenext',0), //if no, play no sound |
|---|
| 751 | | array($account,'queue-thereare',($_REQUEST['announceposition']=='no')?'silence/1':'queue-thereare',0), //if no, play no sound |
|---|
| 752 | | array($account,'queue-callswaiting',($_REQUEST['announceposition']=='no')?'silence/1':'queue-callswaiting',0), //if no, play no sound |
|---|
| 753 | | array($account,'queue-thankyou',($_REQUEST['announceposition']=='no')?'':'queue-thankyou',0), //if no, play no sound |
|---|
| 754 | | array($account,'periodic-announce-frequency',($_REQUEST['pannouncefreq'])?$_REQUEST['pannouncefreq']:'0',0), |
|---|
| 755 | | array($account,'monitor-format',($_REQUEST['monitor-format'])?$_REQUEST['monitor-format']:'',0), |
|---|
| 756 | | array($account,'monitor-join','yes',0), |
|---|
| 757 | | array($account,'eventwhencalled',($_REQUEST['eventwhencalled'])?$_REQUEST['eventwhencalled']:'no',0), |
|---|
| 758 | | array($account,'eventmemberstatus',($_REQUEST['eventmemberstatus'])?$_REQUEST['eventmemberstatus']:'no',0), |
|---|
| 759 | | array($account,'weight',(isset($_REQUEST['weight']))?$_REQUEST['weight']:'0',0), |
|---|
| 760 | | array($account,'autofill',(isset($_REQUEST['autofill']))?'yes':'no',0), |
|---|
| 761 | | array($account,'ringinuse',($cwignore == 2 || $cwignore == 3)?'no':'yes',0), |
|---|
| 762 | | array($account,'reportholdtime',(isset($_REQUEST['reportholdtime']))?$_REQUEST['reportholdtime']:'no',0), |
|---|
| 763 | | array($account,'servicelevel',(isset($_REQUEST['servicelevel']))?$_REQUEST['servicelevel']:60,0), |
|---|
| 764 | | array($account,'memberdelay',(isset($_REQUEST['memberdelay']))?$_REQUEST['memberdelay']:'0',0), |
|---|
| 765 | | array($account,'timeoutrestart',(isset($_REQUEST['timeoutrestart']))?$_REQUEST['timeoutrestart']:'no',0), |
|---|
| 766 | | ); |
|---|
| 767 | | |
|---|
| 768 | | if($ast_ge_16) { |
|---|
| 769 | | $fields[] = array($account, 'timeoutpriority',(isset($_REQUEST['timeoutpriority']))?$_REQUEST['timeoutpriority']:'app',0); |
|---|
| 770 | | $fields[] = array($account, 'penaltymemberslimit',(isset($_REQUEST['penaltymemberslimit']))?$_REQUEST['penaltymemberslimit']:'0',0); |
|---|
| 771 | | } |
|---|
| 772 | | if($ast_ge_18) { |
|---|
| 773 | | $fields[] = array($account,'answered_elsewhere',(isset($_REQUEST['answered_elsewhere']))?$_REQUEST['answered_elsewhere']:'0',0); |
|---|
| 774 | | } |
|---|
| 775 | | |
|---|
| 776 | | if ($_REQUEST['music'] != 'inherit') { |
|---|
| 777 | | $fields[] = array($account,'music',($_REQUEST['music'])?$_REQUEST['music']:'default',0); |
|---|
| 778 | | } |
|---|
| 779 | | |
|---|
| 780 | | //there can be multiple members |
|---|
| 781 | | if (isset($members)) { |
|---|
| 782 | | $count = 0; |
|---|
| 783 | | $members = array_unique($members); |
|---|
| 784 | | foreach ($members as $member) { |
|---|
| 785 | | $fields[] = array($account,'member',$member,$count); |
|---|
| 786 | | $count++; |
|---|
| 787 | | } |
|---|
| 788 | | } |
|---|
| 789 | | |
|---|
| 790 | | $compiled = $db->prepare('INSERT INTO queues_details (id, keyword, data, flags) values (?,?,?,?)'); |
|---|
| 791 | | $result = $db->executeMultiple($compiled,$fields); |
|---|
| 792 | | if(DB::IsError($result)) { |
|---|
| 793 | | die_freepbx($result->getMessage()."<br><br>error adding to queues_details table"); |
|---|
| 794 | | } |
|---|
| 795 | | $extension = $account; |
|---|
| 796 | | $descr = isset($name) ? $db->escapeSimple($name):''; |
|---|
| 797 | | $grppre = isset($prefix) ? $db->escapeSimple($prefix):''; |
|---|
| 798 | | $alertinfo = isset($alertinfo) ? $db->escapeSimple($alertinfo):''; |
|---|
| 799 | | //$joinannounce_id = $joinannounce_id; |
|---|
| 800 | | $ringing = isset($_REQUEST['rtone']) ? $_REQUEST['rtone']:''; |
|---|
| 801 | | //$agentannounce_id = $agentannounce_id; |
|---|
| 802 | | $maxwait = isset($maxwait) ? $maxwait:''; |
|---|
| 803 | | $password = isset($password) ? $password:''; |
|---|
| 804 | | $ivr_id = isset($_REQUEST['announcemenu']) ? $_REQUEST['announcemenu']:'none'; |
|---|
| 805 | | $dest = isset($goto) ? $goto:''; |
|---|
| 806 | | $cwignore = isset($cwignore) ? $cwignore:'0'; |
|---|
| 807 | | $queuewait = isset($queuewait) ? $queuewait:'0'; |
|---|
| 808 | | $qregex = isset($qregex) ? $db->escapeSimple($qregex):''; |
|---|
| 809 | | $use_queue_context = isset($use_queue_context) ? $use_queue_context:'0'; |
|---|
| 810 | | $togglehint = isset($togglehint) ? $togglehint:'0'; |
|---|
| 811 | | $qnoanswer = isset($qnoanswer) ? $qnoanswer:'0'; |
|---|
| 812 | | $callconfirm = isset($callconfirm) ? $callconfirm:'0'; |
|---|
| 813 | | $monitor_type = isset($monitor_type) ? $monitor_type:''; |
|---|
| 814 | | $monitor_heard = isset($monitor_heard) ? $monitor_heard:'0'; |
|---|
| 815 | | $monitor_spoken = isset($monitor_spoken) ? $monitor_spoken:'0'; |
|---|
| 816 | | // Assumes it has just been deleted |
|---|
| 817 | | $sql = "INSERT INTO queues_config (extension, descr, grppre, alertinfo, joinannounce_id, ringing, agentannounce_id, maxwait, password, ivr_id, dest, cwignore, qregex, queuewait, use_queue_context, togglehint, qnoanswer, callconfirm, callconfirm_id, monitor_type, monitor_heard, monitor_spoken) |
|---|
| 818 | | VALUES ('$extension', '$descr', '$grppre', '$alertinfo', '$joinannounce_id', '$ringing', '$agentannounce_id', '$maxwait', '$password', '$ivr_id', '$dest', '$cwignore', '$qregex', '$queuewait', '$use_queue_context', '$togglehint', '$qnoanswer', '$callconfirm', '$callconfirm_id', '$monitor_type', '$monitor_heard', '$monitor_spoken') "; |
|---|
| 819 | | $results = sql($sql); |
|---|
| 820 | | |
|---|
| 821 | | // store dynamic member data in astDB |
|---|
| 822 | | if ($astman) { |
|---|
| 823 | | $dynmembers = array_unique($dynmembers); |
|---|
| 824 | | foreach($dynmembers as $member){ |
|---|
| 825 | | $mem=explode(',',$member); |
|---|
| 826 | | if (isset($mem[0]) && trim($mem[0]) != '') { |
|---|
| 827 | | $penalty = isset($mem[1]) && ctype_digit(trim($mem[1])) ? $mem[1] : 0; |
|---|
| 828 | | $astman->database_put('QPENALTY/'.$account.'/agents',trim($mem[0]),trim($penalty)); |
|---|
| 829 | | } |
|---|
| 830 | | } |
|---|
| 831 | | $astman->database_put('QPENALTY/'.$account,'dynmemberonly',$dynmemberonly); |
|---|
| 832 | | } else { |
|---|
| 833 | | fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 834 | | } |
|---|
| 835 | | |
|---|
| 836 | | return true; |
|---|
| 837 | | } |
|---|
| 838 | | |
|---|
| 839 | | function queues_del($account) { |
|---|
| 840 | | global $db,$astman,$amp_conf; |
|---|
| 841 | | |
|---|
| 842 | | $sql = "DELETE FROM queues_details WHERE id = '$account'"; |
|---|
| 843 | | $result = $db->query($sql); |
|---|
| 844 | | if(DB::IsError($result)) { |
|---|
| 845 | | die_freepbx($result->getMessage().$sql); |
|---|
| 846 | | } |
|---|
| 847 | | $sql = "DELETE FROM queues_config WHERE extension = '$account'"; |
|---|
| 848 | | $result = $db->query($sql); |
|---|
| 849 | | if(DB::IsError($result)) { |
|---|
| 850 | | die_freepbx($result->getMessage().$sql); |
|---|
| 851 | | } |
|---|
| 852 | | |
|---|
| 853 | | //remove dynamic memebers from astDB |
|---|
| 854 | | if ($astman) { |
|---|
| 855 | | $astman->database_deltree('QPENALTY/'.$account); |
|---|
| 856 | | } else { |
|---|
| 857 | | fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 858 | | } |
|---|
| 859 | | } |
|---|
| 860 | | |
|---|
| 861 | | //get the existing queue extensions |
|---|
| 862 | | // |
|---|
| 863 | | function queues_list($listall=false) { |
|---|
| 864 | | global $db; |
|---|
| 865 | | $sql = "SELECT extension, descr FROM queues_config ORDER BY extension"; |
|---|
| 866 | | $results = $db->getAll($sql); |
|---|
| 867 | | if(DB::IsError($results)) { |
|---|
| 868 | | $results = array(); |
|---|
| 869 | | } |
|---|
| 870 | | |
|---|
| 871 | | foreach($results as $result){ |
|---|
| 872 | | if ($listall || checkRange($result[0])){ |
|---|
| 873 | | $extens[] = array($result[0],$result[1]); |
|---|
| 874 | | } |
|---|
| 875 | | } |
|---|
| 876 | | if (isset($extens)) { |
|---|
| 877 | | return $extens; |
|---|
| 878 | | } else { |
|---|
| 879 | | return array(); |
|---|
| 880 | | } |
|---|
| 881 | | } |
|---|
| 882 | | |
|---|
| 883 | | function queues_check_extensions($exten=true) { |
|---|
| 884 | | global $active_modules; |
|---|
| 885 | | |
|---|
| 886 | | $extenlist = array(); |
|---|
| 887 | | if (is_array($exten) && empty($exten)) { |
|---|
| 888 | | return $extenlist; |
|---|
| 889 | | } |
|---|
| 890 | | $sql = "SELECT extension, descr FROM queues_config "; |
|---|
| 891 | | if (is_array($exten)) { |
|---|
| 892 | | $sql .= "WHERE extension in ('".implode("','",$exten)."')"; |
|---|
| 893 | | } |
|---|
| 894 | | $sql .= " ORDER BY extension"; |
|---|
| 895 | | $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 896 | | |
|---|
| 897 | | //$type = isset($active_modules['queues']['type'])?$active_modules['queues']['type']:'setup'; |
|---|
| 898 | | foreach ($results as $result) { |
|---|
| 899 | | $thisexten = $result['extension']; |
|---|
| 900 | | $extenlist[$thisexten]['description'] = sprintf(_("Queue: %s"),$result['descr']); |
|---|
| 901 | | $extenlist[$thisexten]['status'] = _('INUSE'); |
|---|
| 902 | | $extenlist[$thisexten]['edit_url'] = 'config.php?display=queues&extdisplay='.urlencode($thisexten); |
|---|
| 903 | | } |
|---|
| 904 | | return $extenlist; |
|---|
| 905 | | } |
|---|
| 906 | | |
|---|
| 907 | | function queues_check_destinations($dest=true) { |
|---|
| 908 | | global $active_modules; |
|---|
| 909 | | |
|---|
| 910 | | $destlist = array(); |
|---|
| 911 | | if (is_array($dest) && empty($dest)) { |
|---|
| 912 | | return $destlist; |
|---|
| 913 | | } |
|---|
| 914 | | $sql = "SELECT extension, descr, dest FROM queues_config"; |
|---|
| 915 | | if ($dest !== true) { |
|---|
| 916 | | $sql .= " WHERE dest in ('".implode("','",$dest)."')"; |
|---|
| 917 | | } |
|---|
| 918 | | $sql .= " ORDER BY extension"; |
|---|
| 919 | | |
|---|
| 920 | | $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 921 | | |
|---|
| 922 | | //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup'; |
|---|
| 923 | | |
|---|
| 924 | | foreach ($results as $result) { |
|---|
| 925 | | $thisdest = $result['dest']; |
|---|
| 926 | | $thisid = $result['extension']; |
|---|
| 927 | | $destlist[] = array( |
|---|
| 928 | | 'dest' => $thisdest, |
|---|
| 929 | | 'description' => sprintf(_("Queue: %s (%s)"),$result['descr'],$thisid), |
|---|
| 930 | | 'edit_url' => 'config.php?display=queues&extdisplay='.urlencode($thisid), |
|---|
| 931 | | ); |
|---|
| 932 | | } |
|---|
| 933 | | return $destlist; |
|---|
| 934 | | } |
|---|
| 935 | | |
|---|
| 936 | | function queue_change_destination($old_dest, $new_dest) { |
|---|
| 937 | | $sql = 'UPDATE queues_config SET dest = "' . $new_dest . '" WHERE dest = "' . $old_dest . '"'; |
|---|
| 938 | | sql($sql, "query"); |
|---|
| 939 | | } |
|---|
| 983 | | function queues_get($account, $queues_conf_only=false) { |
|---|
| 984 | | global $db,$astman,$amp_conf; |
|---|
| 985 | | |
|---|
| 986 | | if ($account == "") |
|---|
| 987 | | { |
|---|
| 988 | | return array(); |
|---|
| 989 | | } |
|---|
| 990 | | |
|---|
| 991 | | $account = q($account); |
|---|
| 992 | | //get all the variables for the queue |
|---|
| 993 | | $sql = "SELECT keyword,data FROM queues_details WHERE id = $account"; |
|---|
| 994 | | $results = $db->getAssoc($sql); |
|---|
| 995 | | if (empty($results)) { |
|---|
| 996 | | return array(); |
|---|
| 997 | | } |
|---|
| 998 | | |
|---|
| 999 | | //okay, but there can be multiple member variables ... do another select for them |
|---|
| 1000 | | $sql = "SELECT data FROM queues_details WHERE id = $account AND keyword = 'member' order by flags"; |
|---|
| 1001 | | $results['member'] = $db->getCol($sql); |
|---|
| 1002 | | |
|---|
| 1003 | | //if 'queue-youarenext=queue-youarenext', then assume we want to announce position |
|---|
| 1004 | | if (!$queues_conf_only) { |
|---|
| 1005 | | if(isset($results['queue-youarenext']) && $results['queue-youarenext'] == 'queue-youarenext') { |
|---|
| 1006 | | $results['announce-position'] = 'yes'; |
|---|
| 1007 | | } else { |
|---|
| 1008 | | $results['announce-position'] = 'no'; |
|---|
| 1009 | | } |
|---|
| 1010 | | } |
|---|
| 1011 | | |
|---|
| 1012 | | //if 'eventmemberstatusoff=Yes', then assume we want to 'eventmemberstatus=no' |
|---|
| 1013 | | if(isset($results['eventmemberstatusoff'])) { |
|---|
| 1014 | | if (strtolower($results['eventmemberstatusoff']) == 'yes') { |
|---|
| 1015 | | $results['eventmemberstatus'] = 'no'; |
|---|
| 1016 | | } else { |
|---|
| 1017 | | $results['eventmemberstatus'] = 'yes'; |
|---|
| 1018 | | } |
|---|
| 1019 | | } elseif (!isset($results['eventmemberstatus'])){ |
|---|
| 1020 | | $results['eventmemberstatus'] = 'no'; |
|---|
| 1021 | | } |
|---|
| 1022 | | |
|---|
| 1023 | | if ($queues_conf_only) { |
|---|
| 1024 | | $sql = "SELECT ivr_id FROM queues_config WHERE extension = $account"; |
|---|
| 1025 | | $config = sql($sql, "getRow",DB_FETCHMODE_ASSOC); |
|---|
| 1026 | | } else { |
|---|
| 1027 | | $sql = "SELECT * FROM queues_config WHERE extension = $account"; |
|---|
| 1028 | | $config = sql($sql, "getRow",DB_FETCHMODE_ASSOC); |
|---|
| 1029 | | |
|---|
| 1030 | | $results['prefix'] = $config['grppre']; |
|---|
| 1031 | | $results['alertinfo'] = $config['alertinfo']; |
|---|
| 1032 | | $results['agentannounce_id'] = $config['agentannounce_id']; |
|---|
| 1033 | | $results['maxwait'] = $config['maxwait']; |
|---|
| 1034 | | $results['name'] = $config['descr']; |
|---|
| 1035 | | $results['joinannounce_id'] = $config['joinannounce_id']; |
|---|
| 1036 | | $results['password'] = $config['password']; |
|---|
| 1037 | | $results['goto'] = $config['dest']; |
|---|
| 1038 | | $results['announcemenu'] = $config['ivr_id']; |
|---|
| 1039 | | $results['rtone'] = $config['ringing']; |
|---|
| 1040 | | $results['cwignore'] = $config['cwignore']; |
|---|
| 1041 | | $results['qregex'] = $config['qregex']; |
|---|
| 1042 | | $results['queuewait'] = $config['queuewait']; |
|---|
| 1043 | | $results['use_queue_context'] = $config['use_queue_context']; |
|---|
| 1044 | | $results['togglehint'] = $config['togglehint']; |
|---|
| 1045 | | $results['qnoanswer'] = $config['qnoanswer']; |
|---|
| 1046 | | $results['callconfirm'] = $config['callconfirm']; |
|---|
| 1047 | | $results['callconfirm_id'] = $config['callconfirm_id']; |
|---|
| 1048 | | $results['monitor_type'] = $config['monitor_type']; |
|---|
| 1049 | | $results['monitor_heard'] = $config['monitor_heard']; |
|---|
| 1050 | | $results['monitor_spoken'] = $config['monitor_spoken']; |
|---|
| 1051 | | |
|---|
| 1052 | | // TODO: why the str_replace? |
|---|
| 1053 | | // |
|---|
| 1054 | | if ($astman) { |
|---|
| 1055 | | $account=str_replace("'",'',$account); |
|---|
| 1056 | | //get dynamic members priority from astDB |
|---|
| 1057 | | $get=$astman->database_show('QPENALTY/'.$account.'/agents'); |
|---|
| 1058 | | if($get){ |
|---|
| 1059 | | foreach($get as $key => $value){ |
|---|
| 1060 | | $key=explode('/',$key); |
|---|
| 1061 | | $mem[$key[4]]=$value; |
|---|
| 1062 | | } |
|---|
| 1063 | | foreach($mem as $mem => $pnlty){ |
|---|
| 1064 | | $dynmem[]=$mem.','.$pnlty; |
|---|
| 1065 | | } |
|---|
| 1066 | | $results['dynmembers']=implode("\n",$dynmem); |
|---|
| 1067 | | } else { |
|---|
| 1068 | | $results['dynmembers']=''; |
|---|
| 1069 | | } |
|---|
| 1070 | | $results['dynmemberonly'] = $astman->database_get('QPENALTY/'.$account,'dynmemberonly'); |
|---|
| 1071 | | } else { |
|---|
| 1072 | | fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 1073 | | } |
|---|
| 1074 | | } |
|---|
| 1075 | | |
|---|
| 1076 | | $results['context'] = ''; |
|---|
| 1077 | | $results['periodic-announce'] = ''; |
|---|
| 1078 | | |
|---|
| 1079 | | if ($config['ivr_id'] != 'none' && $config['ivr_id'] != '') { |
|---|
| 1080 | | if (function_exists('ivr_get_details')) { |
|---|
| 1081 | | $results['context'] = "ivr-".$config['ivr_id']; |
|---|
| 1082 | | $arr = ivr_get_details($config['ivr_id']); |
|---|
| 1083 | | if( isset($arr['announcement_id']) && $arr['announcement_id'] != '') { |
|---|
| 1084 | | $periodic = recordings_get_file($arr['announcement_id']); |
|---|
| 1085 | | // We need to strip off all but the first sound file of any compound sound files |
|---|
| 1086 | | // |
|---|
| 1087 | | $periodic_arr = explode("&", $periodic); |
|---|
| 1088 | | $results['periodic-announce'] = $periodic_arr[0]; |
|---|
| 1089 | | } |
|---|
| 1090 | | } |
|---|
| 1091 | | } |
|---|
| 1092 | | return $results; |
|---|
| 1093 | | } |
|---|
| 1094 | | |
|---|
| 1095 | | function queue_app_all_toggle() { |
|---|
| 1096 | | global $ext; |
|---|
| 1097 | | global $amp_conf; |
|---|
| 1098 | | |
|---|
| 1099 | | $id = "app-all-queue-toggle"; // The context to be included |
|---|
| 1100 | | $c = 's'; |
|---|
| 1101 | | |
|---|
| 1102 | | $ext->add($id, $c, 'start', new ext_answer('')); |
|---|
| 1103 | | $ext->add($id, $c, '', new ext_wait('1')); |
|---|
| 1104 | | $ext->add($id, $c, '', new ext_macro('user-callerid')); |
|---|
| 1105 | | $ext->add($id, $c, '', new ext_agi('queue_devstate.agi,getall,${AMPUSER}')); |
|---|
| 1106 | | $ext->add($id, $c, '', new ext_gotoif('$["${QUEUESTAT}" = "NOQUEUES"]', 'skip')); |
|---|
| 1107 | | $ext->add($id, $c, '', new ext_set('TOGGLE_MACRO', '${IF($["${QUEUESTAT}"="LOGGEDOUT"]?toggle-add-agent:toggle-del-agent)}')); |
|---|
| 1108 | | if ($amp_conf['USEDEVSTATE']) { |
|---|
| 1109 | | $ext->add($id, $c, '', new ext_set('STATE', '${IF($["${QUEUESTAT}"="LOGGEDOUT"]?INUSE:NOT_INUSE)}')); |
|---|
| 1110 | | } |
|---|
| 1111 | | $ext->add($id, $c, '', new ext_set('LOOPCNTALL', '${FIELDQTY(USERQUEUES,-)}')); |
|---|
| 1112 | | $ext->add($id, $c, '', new ext_set('ITERALL', '1')); |
|---|
| 1113 | | $ext->add($id, $c, 'begin', new ext_set('QUEUENO', '${CUT(USERQUEUES,-,${ITERALL})}')); |
|---|
| 1114 | | $ext->add($id, $c, '', new ext_set('ITERALL', '$[${ITERALL}+1]')); |
|---|
| 1115 | | $ext->add($id, $c, '', new ext_macro('${TOGGLE_MACRO}')); |
|---|
| 1116 | | if ($amp_conf['USEDEVSTATE']) { |
|---|
| 1117 | | $ext->add($id, $c, '', new ext_gosub('1', 'sstate', 'app-queue-toggle')); |
|---|
| 1118 | | } |
|---|
| 1119 | | $ext->add($id, $c, '', new ext_gotoif('$[${ITERALL} <= ${LOOPCNTALL}]', 'begin')); |
|---|
| 1120 | | $ext->add($id, $c, 'skip', new ext_execif('$["${QUEUESTAT}"="LOGGEDIN" | "${QUEUESTAT}"="NOQUEUES"]', 'Playback', 'agent-loggedoff')); |
|---|
| 1121 | | $ext->add($id, $c, '', new ext_execif('$["${QUEUESTAT}"="LOGGEDOUT"]', 'Playback', 'agent-loginok')); |
|---|
| 1122 | | $ext->add($id, $c, '', new ext_execif('$["${QUEUESTAT}"="LOGGEDOUT"]', 'SayDigits', '${AMPUSER}')); |
|---|
| 1123 | | $ext->add($id, $c, '', new ext_macro('hangupcall')); |
|---|
| 1124 | | } |
|---|
| 1125 | | |
|---|
| 1126 | | |
|---|
| 1127 | | /* Trial DEVSTATE */ |
|---|
| 1128 | | function queue_app_toggle($c) { |
|---|
| 1129 | | global $ext; |
|---|
| 1130 | | global $amp_conf; |
|---|
| 1131 | | global $version; |
|---|
| 1132 | | |
|---|
| 1133 | | $id = "app-queue-toggle"; // The context to be included |
|---|
| 1134 | | $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal |
|---|
| 1135 | | |
|---|
| 1136 | | $c = 's'; |
|---|
| 1137 | | |
|---|
| 1138 | | $ext->add($id, $c, 'start', new ext_answer('')); |
|---|
| 1139 | | $ext->add($id, $c, '', new ext_wait('1')); |
|---|
| 1140 | | $ext->add($id, $c, '', new ext_macro('user-callerid')); |
|---|
| 1141 | | $ext->add($id, $c, '', new ext_setvar('QUEUESTAT', 'LOGGEDOUT')); |
|---|
| 1142 | | $ext->add($id, $c, '', new ext_agi('queue_devstate.agi,getqueues,${AMPUSER}')); |
|---|
| 1143 | | |
|---|
| 1144 | | $ext->add($id, $c, '', new ext_gotoif('$["${QUEUESTAT}" = "LOGGEDOUT"]', 'activate')); |
|---|
| 1145 | | $ext->add($id, $c, '', new ext_gotoif('$["${QUEUESTAT}" = "LOGGEDIN"]', 'deactivate')); |
|---|
| 1146 | | $ext->add($id, $c, '', new ext_gotoif('$["${QUEUESTAT}" = "STATIC"]', 'static','end')); |
|---|
| 1147 | | $ext->add($id, $c, 'deactivate', new ext_noop('Agent Logged out')); |
|---|
| 1148 | | $ext->add($id, $c, '', new ext_macro('toggle-del-agent')); |
|---|
| 1149 | | if ($amp_conf['USEDEVSTATE']) { |
|---|
| 1150 | | $ext->add($id, $c, '', new ext_setvar('STATE', 'NOT_INUSE')); |
|---|
| 1151 | | $ext->add($id, $c, '', new ext_gosub('1', 'sstate')); |
|---|
| 1152 | | } |
|---|
| 1153 | | $ext->add($id, $c, '', new ext_playback('agent-loggedoff')); |
|---|
| 1154 | | $ext->add($id, $c, '', new ext_macro('hangupcall')); |
|---|
| 1155 | | |
|---|
| 1156 | | $ext->add($id, $c, 'activate', new ext_noop('Agent Logged In')); |
|---|
| 1157 | | $ext->add($id, $c, '', new ext_macro('toggle-add-agent')); |
|---|
| 1158 | | if ($amp_conf['USEDEVSTATE']) { |
|---|
| 1159 | | $ext->add($id, $c, '', new ext_setvar('STATE', 'INUSE')); |
|---|
| 1160 | | $ext->add($id, $c, '', new ext_gosub('1', 'sstate')); |
|---|
| 1161 | | } |
|---|
| 1162 | | $ext->add($id, $c, '', new ext_playback('agent-loginok')); |
|---|
| 1163 | | $ext->add($id, $c, '', new ext_saydigits('${CALLBACKNUM}')); |
|---|
| 1164 | | $ext->add($id, $c, '', new ext_macro('hangupcall')); |
|---|
| 1165 | | |
|---|
| 1166 | | $ext->add($id, $c, 'static', new ext_noop('User is a Static Agent')); |
|---|
| 1167 | | if ($amp_conf['USEDEVSTATE']) { |
|---|
| 1168 | | $ext->add($id, $c, '', new ext_setvar('STATE', 'INUSE')); |
|---|
| 1169 | | $ext->add($id, $c, '', new ext_gosub('1', 'sstate')); |
|---|
| 1170 | | } |
|---|
| 1171 | | $ext->add($id, $c, '', new ext_playback('agent-loginok')); |
|---|
| 1172 | | $ext->add($id, $c, '', new ext_macro('hangupcall')); |
|---|
| 1173 | | |
|---|
| 1174 | | if ($amp_conf['USEDEVSTATE']) { |
|---|
| 1175 | | $c = 'sstate'; |
|---|
| 1176 | | $ext->add($id, $c, '', new ext_dbget('DEVICES','AMPUSER/${AMPUSER}/device')); |
|---|
| 1177 | | $ext->add($id, $c, '', new ext_gotoif('$["${DEVICES}" = "" ]', 'return')); |
|---|
| 1178 | | $ext->add($id, $c, '', new ext_setvar('LOOPCNT', '${FIELDQTY(DEVICES,&)}')); |
|---|
| 1179 | | $ext->add($id, $c, '', new ext_setvar('ITER', '1')); |
|---|
| 1180 | | $ext->add($id, $c, 'begin', new ext_setvar($amp_conf['AST_FUNC_DEVICE_STATE'].'(Custom:QUEUE${CUT(DEVICES,&,${ITER})}*${QUEUENO})','${STATE}')); |
|---|
| 1181 | | $ext->add($id, $c, '', new ext_setvar('ITER', '$[${ITER} + 1]')); |
|---|
| 1182 | | $ext->add($id, $c, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin')); |
|---|
| 1183 | | $ext->add($id, $c, 'return', new ext_return()); |
|---|
| 1184 | | } |
|---|
| 1185 | | } |
|---|
| 1186 | | function queue_agent_add_toggle() { |
|---|
| 1187 | | global $ext; |
|---|
| 1188 | | global $amp_conf; |
|---|
| 1189 | | global $version; |
|---|
| 1190 | | |
|---|
| 1191 | | $ast_ge_14_25 = version_compare($version,'1.4.25','ge'); |
|---|
| 1192 | | $ast_ge_18 = version_compare($version,'1.8','ge'); |
|---|
| 1193 | | $id = "macro-toggle-add-agent"; // The context to be included |
|---|
| 1194 | | |
|---|
| 1195 | | $c = 's'; |
|---|
| 1196 | | |
|---|
| 1197 | | $ext->add($id, $c, '', new ext_wait('1')); |
|---|
| 1198 | | $ext->add($id, $c, '', new ext_macro('user-callerid,SKIPTTL')); |
|---|
| 1199 | | $ext->add($id, $c, '', new ext_setvar('CALLBACKNUM','${AMPUSER}')); |
|---|
| 1200 | | //TODO: check if it's not a user for some reason and abort? |
|---|
| 1201 | | $ext->add($id, $c, '', new ext_gotoif('$["${DB(QPENALTY/${QUEUENO}/dynmemberonly)}" = "yes" & ${DB_EXISTS(QPENALTY/${QUEUENO}/agents/${CALLBACKNUM})} != 1]', 'invalid')); |
|---|
| 1202 | | if ($ast_ge_18 || $amp_conf['USEQUEUESTATE']) { |
|---|
| 1203 | | $ext->add($id, $c, '', new ext_execif('$["${DB(AMPUSER/${CALLBACKNUM}/queues/qnostate)}" != "ignorestate"]', 'AddQueueMember', '${QUEUENO},Local/${CALLBACKNUM}@from-queue/n,${DB(QPENALTY/${QUEUENO}/agents/${CALLBACKNUM})},,${DB(AMPUSER/${CALLBACKNUM}/cidname)},hint:${CALLBACKNUM}@ext-local')); |
|---|
| 1204 | | $ext->add($id, $c, '', new ext_execif('$["${DB(AMPUSER/${CALLBACKNUM}/queues/qnostate)}" = "ignorestate"]', 'AddQueueMember', '${QUEUENO},Local/${CALLBACKNUM}@from-queue/n,${DB(QPENALTY/${QUEUENO}/agents/${CALLBACKNUM})},,${DB(AMPUSER/${CALLBACKNUM}/cidname)}')); |
|---|
| 1205 | | |
|---|
| 1206 | | } else if ($ast_ge_14_25) { |
|---|
| 1207 | | $ext->add($id, $c, '', new ext_execif('$["${DB(AMPUSER/${CALLBACKNUM}/queues/qnostate)}" != "ignorestate"]', 'AddQueueMember', '${QUEUENO},Local/${CALLBACKNUM}@from-queue/n,${DB(QPENALTY/${QUEUENO}/agents/${CALLBACKNUM})},,${DB(AMPUSER/${CALLBACKNUM}/cidname)},${DB(DEVICE/${REALCALLERIDNUM}/dial)}')); |
|---|
| 1208 | | $ext->add($id, $c, '', new ext_execif('$["${DB(AMPUSER/${CALLBACKNUM}/queues/qnostate)}" = "ignorestate"]', 'AddQueueMember', '${QUEUENO},Local/${CALLBACKNUM}@from-queue/n,${DB(QPENALTY/${QUEUENO}/agents/${CALLBACKNUM})},,${DB(AMPUSER/${CALLBACKNUM}/cidname)}')); |
|---|
| 1209 | | } else { |
|---|
| 1210 | | $ext->add($id, $c, '', new ext_addqueuemember('${QUEUENO}','Local/${CALLBACKNUM}@from-queue/n,${DB(QPENALTY/${QUEUENO}/agents/${CALLBACKNUM})}')); |
|---|
| 1211 | | } |
|---|
| 1212 | | |
|---|
| 1213 | | $ext->add($id, $c, '', new ext_userevent('AgentLogin','Agent: ${CALLBACKNUM}')); |
|---|
| 1214 | | $ext->add($id, $c, '', new ext_macroexit()); |
|---|
| 1215 | | $ext->add($id, $c, 'invalid', new ext_playback('pbx-invalid')); |
|---|
| 1216 | | $ext->add($id, $c, '', new ext_macroexit()); |
|---|
| 1217 | | } |
|---|
| 1218 | | |
|---|
| 1219 | | function queue_agent_del_toggle() { |
|---|
| 1220 | | global $ext; |
|---|
| 1221 | | global $amp_conf; |
|---|
| 1222 | | |
|---|
| 1223 | | $id = "macro-toggle-del-agent"; // The context to be included |
|---|
| 1224 | | |
|---|
| 1225 | | $c = 's'; |
|---|
| 1226 | | |
|---|
| 1227 | | $ext->add($id, $c, '', new ext_wait('1')); |
|---|
| 1228 | | $ext->add($id, $c, '', new ext_macro('user-callerid,SKIPTTL')); |
|---|
| 1229 | | $ext->add($id, $c, '', new ext_setvar('CALLBACKNUM','${AMPUSER}')); |
|---|
| 1230 | | $ext->add($id, $c, '', new ext_removequeuemember('${QUEUENO}','Local/${CALLBACKNUM}@from-queue/n')); |
|---|
| 1231 | | $ext->add($id, $c, '', new ext_removequeuemember('${QUEUENO}','Local/${CALLBACKNUM}@from-internal/n')); |
|---|
| 1232 | | $ext->add($id, $c, '', new ext_userevent('RefreshQueue')); |
|---|
| 1233 | | $ext->add($id, $c, '', new ext_macroexit()); |
|---|
| 1234 | | } |
|---|
| 1235 | | |
|---|
| 1236 | | /************************************************************************************************************ |
|---|
| 1237 | | * Hook Exentions/Users to allow an extension to indicate if the Queue should ignore it's state information |
|---|
| 1238 | | * when it is acting as a Queue Member (Agent). |
|---|
| 1239 | | */ |
|---|
| 1240 | | function queues_get_qnostate($exten) { |
|---|
| 1241 | | global $astman; |
|---|
| 1242 | | |
|---|
| 1243 | | // Retrieve the qnostate configuraiton from this user from ASTDB |
|---|
| 1244 | | if ($astman) { |
|---|
| 1245 | | $qnostate = $astman->database_get("AMPUSER",$exten."/queues/qnostate"); |
|---|
| 1246 | | } else { |
|---|
| 1247 | | fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 1248 | | } |
|---|
| 1249 | | // If it's blank, set it to 'usestate' |
|---|
| 1250 | | // |
|---|
| 1251 | | return ($qnostate == 'ignorestate' ? $qnostate : 'usestate'); |
|---|
| 1252 | | } |
|---|
| 1253 | | |
|---|
| 1254 | | function queues_set_qnostate($exten,$qnostate) { |
|---|
| 1255 | | global $astman; |
|---|
| 1256 | | |
|---|
| 1257 | | // Update the settings in ASTDB |
|---|
| 1258 | | if ($astman) { |
|---|
| 1259 | | $astman->database_put("AMPUSER",$exten."/queues/qnostate",$qnostate); |
|---|
| 1260 | | } else { |
|---|
| 1261 | | fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); |
|---|
| 1262 | | } |
|---|
| 1263 | | } |
|---|
| 1264 | | |
|---|
| 1265 | | function queues_applyhooks() { |
|---|
| 1266 | | global $currentcomponent; |
|---|
| 1267 | | |
|---|
| 1268 | | $currentcomponent->addoptlistitem('qnostate', 'usestate', _('Use State')); |
|---|
| 1269 | | $currentcomponent->addoptlistitem('qnostate', 'ignorestate',_('Ignore State')); |
|---|
| 1270 | | $currentcomponent->setoptlistopts('qnostate', 'sort', false); |
|---|
| 1271 | | |
|---|
| 1272 | | // Add the 'process' function - this gets called when the page is loaded, to hook into |
|---|
| 1273 | | // displaying stuff on the page. |
|---|
| 1274 | | $currentcomponent->addguifunc('queues_configpageload',9); |
|---|
| 1275 | | |
|---|
| 1276 | | } |
|---|
| 1277 | | |
|---|
| | 82 | //attach hooks |
|---|