Changeset 13401
- Timestamp:
- 02/07/12 19:44:19 (1 year ago)
- Files:
-
- modules/branches/2.10/core/agi-bin/user_login_out.agi (modified) (9 diffs)
- modules/branches/2.10/queues/bin (added)
- modules/branches/2.10/queues/bin/generate_queue_hints.php (copied) (copied from freepbx/branches/2.10/amp_conf/bin/generate_hints.php) (3 diffs)
- modules/branches/2.10/queues/functions.inc/dialplan.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.10/core/agi-bin/user_login_out.agi
r11663 r13401 51 51 $fm_devstate = get_var( "FMDEVSTATE" ) == "TRUE" ? true : false; 52 52 $que_devstate = get_var( "QUEDEVSTATE" ) == "TRUE" ? true : false; 53 $queue_toggle = get_var( "QUEUETOGGLE" ); 53 54 $intercom_code = get_var( "INTERCOMCODE" ); 54 55 $campon_toggle = get_var( "CAMPONTOGGLE" ); … … 58 59 $DEVSTATE = version_compare($ast_version, "1.6", "ge") ? "DEVICE_STATE" : "DEVSTATE"; 59 60 60 /*61 $ampmgruser = 'admin';62 $ampmgrpass = 'amp111';63 */64 61 $astman = new AGI_AsteriskManager( ); 65 62 if (!$astman->connect("127.0.0.1", $ampmgruser , $ampmgrpass)) { … … 221 218 global $cf_devstate; 222 219 global $que_devstate; 220 global $queue_toggle; 223 221 global $DEVSTATE; 224 222 … … 249 247 } 250 248 if ($que_devstate) { 251 debug("remove_user: Setting queue DEVSTATES for device $device and user $user",5);249 debug("remove_user: Setting queue DEVSTATES for device $device and user $user",5); 252 250 set_queue_states($user,$device,'off'); 253 } 251 if ($queue_toggle) { 252 remove_queue_hint($device); 253 } 254 } 254 255 if ($dnd_devstate) { 255 256 debug("Setting device $device DND state to INVALID before deleting",5); … … 271 272 } 272 273 274 function set_queue_hint($user, $devices) { 275 global $astman; 276 global $ast_version14; 277 global $queue_toggle; 278 $dp_pre = ($ast_version14) ? 'dialplan ' : ''; 279 280 debug("entering set_queue_hint user: $user and devices: $devices",6); 281 if (trim($devices) == '') { 282 // don't do anything in this case, handle elsewhere 283 return true; 284 } 285 $queues = get_user_queue_assignments($user); 286 if (!empty($queues)) { 287 $device_array = explode( '&', $devices); 288 foreach ($device_array as $device) { 289 $hlist = 'Custom:QUEUE' . $device . '*' . implode('&Custom:QUEUE' . $device . '*', $queues); 290 debug("Hint for device: $device user: $user hint to $hlist",1); 291 $response = $astman->send_request('Command',array('Command'=>$dp_pre."add extension {$queue_toggle}*{$device},hint,{$hlist} into ext-queues replace")); 292 } 293 } 294 } 295 296 function remove_queue_hint($device) { 297 global $astman; 298 global $ast_version14; 299 global $queue_toggle; 300 $dp_pre = ($ast_version14) ? 'dialplan ' : ''; 301 debug("entering remove_queue_hint with device: $device",6); 302 if ($device != '') { 303 debug("removing $queue_toggle*$device@ext-queues hint",1); 304 $response = $astman->send_request('Command',array('Command'=>$dp_pre."remove extension {$queue_toggle}*{$device}@ext-queues hint")); 305 } 306 } 307 273 308 // Set the hint for a user based on the devices in their AMPUSER object 274 309 // … … 278 313 global $agi; 279 314 global $dnd_devstate; 315 global $que_devstate; 316 global $queue_toggle; 280 317 global $intercom_code; 281 318 global $campon_toggle; … … 292 329 $hint_val = 'ccss:'.implode('&ccss:',$dev_arr); 293 330 $response = $astman->send_request('Command',array('Command'=>$dp_pre."add extension {$campon_toggle}{$user},hint,{$hint_val} into ext-local replace")); 331 } 332 if ($que_devstate && $queue_toggle) { 333 set_queue_hint($user, $devices); 294 334 } 295 335 if ($dnd_devstate) { … … 491 531 debug("set_user_devices: user: $user, devices: $devices", 8); 492 532 global $agi; 493 if ( empty($devices)) {533 if (trim($devices) == '') { 494 534 debug("No more devices associated with $user, deletting /device key", 8); 495 535 $agi->database_del('AMPUSER',$user.'/device'); … … 592 632 } 593 633 } 594 634 635 function get_user_queue_assignments($user) { 636 global $astman; 637 static $qc; 638 639 if (empty($qc)) { 640 $qpenalty=$astman->database_show('QPENALTY'); 641 $qc = array(); 642 foreach(array_keys($qpenalty) as $key) { 643 $key = explode('/', $key); 644 if ($key[3] == 'agents') { 645 $qc[$key[4]][] = $key[2]; 646 } 647 } 648 } 649 file_put_contents('/tmp/freepbx_dbug',print_r($qc,true)); 650 if (isset($qc[$user])) { 651 return $qc[$user]; 652 } else { 653 return null; 654 } 655 } modules/branches/2.10/queues/bin/generate_queue_hints.php
r12167 r13401 8 8 } 9 9 10 // If set to nointercom then don't generate any hints 11 // 12 $intercom_code = isset($argv[1]) ? $argv[1] : ''; 13 $campon_toggle = isset($argv[2]) ? $argv[2] : ''; 14 $dnd_mode = isset($argv[3]) ? $argv[3] : ''; 15 16 $ast_with_dahdi = ast_with_dahdi(); 10 $queue_toggle_code = isset($argv[1]) ? $argv[1] : '*45'; 17 11 18 12 $var = $astman->database_show('AMPUSER'); … … 23 17 24 18 foreach (array_keys($user_hash) as $user) { 25 if ($user != 'none' && $user != '') { 26 $devices = get_devices($user); 27 debug("Set hints for user: $user for devices: ".$devices,5); 28 set_hint($user, $devices); 19 if ($user == '') { 20 unset($user_hash[$user]); 21 continue; 22 } 23 $user_hash[$user] = get_devices($user); 24 } 25 26 $qpenalty=$astman->database_show('QPENALTY'); 27 $qc = array(); 28 foreach(array_keys($qpenalty) as $key) { 29 $key = explode('/', $key); 30 if ($key[3] == 'agents') { 31 $qc[$key[4]][] = $key[2]; 32 } 33 } 34 35 foreach ($user_hash as $user => $devices) { 36 if (!isset($qc[$user])) { 37 continue; 38 } 39 $device_list = explode('&',$devices); 40 foreach ($device_list as $device) { 41 set_hint($device, $qc[$user]); 29 42 } 30 43 } … … 34 47 // Set the hint for a user based on the devices in their AMPUSER object 35 48 // 36 function set_hint($user, $devices) { 37 debug("set_hint: user: $user, devices: $devices",8); 38 global $astman; 39 global $dnd_mode; 40 global $intercom_code; 41 global $campon_toggle; 49 function set_hint($device, $queues) { 50 global $queue_toggle_code; 42 51 43 $dnd_string = ($dnd_mode == 'dnd')?"&Custom:DND$user":''; 44 45 if ($devices) { 46 $dial_string = get_dial_string($devices); 47 echo "exten => $user,hint,$dial_string"."$dnd_string\n"; 48 if ($intercom_code != 'nointercom' && $intercom_code != '') { 49 echo "exten => $intercom_code"."$user,hint,$dial_string"."$dnd_string\n"; 50 } 51 if ($campon_toggle != 'nocampon' && $campon_toggle != '') { 52 53 $dev_arr = explode('&',$dial_string); 54 $hint_val = 'ccss:'.implode('&ccss:',$dev_arr); 55 echo "exten => $campon_toggle"."$user,hint,$hint_val"."\n"; 56 } 57 } else if ($dnd_mode == 'dnd') { 58 echo "exten => $user,hint,Custom:DND$user\n"; 59 if ($intercom_code != 'nointercom' && $intercom_code != '') { 60 echo "exten => $intercom_code"."$user,hint,Custom:DND$user\n"; 61 } 52 if (trim($device) == '') { 53 return; 62 54 } 55 $hlist = 'Custom:QUEUE' . $device . '*' . implode('&Custom:QUEUE' . $device . '*', $queues); 56 out("exten => $queue_toggle_code*$device,hint,$hlist"); 63 57 } 64 58 65 // Get the actual technology dialstrings from the DEVICE objects (used66 // to create proper hints)67 //68 function get_dial_string($devices) {69 debug("get_dial_string: devices: $devices",8);70 global $astman;71 global $ast_with_dahdi;72 73 $device_array = explode( '&', $devices );74 $dialstring = '';75 foreach ($device_array as $adevice) {76 $dds = $astman->database_get('DEVICE',$adevice.'/dial');77 $dialstring .= $dds.'&';78 }79 if ($ast_with_dahdi) {80 $dialstring = str_replace('ZAP/', 'DAHDI/', $dialstring);81 }82 return trim($dialstring," &");83 }84 59 85 60 // Get the list of current devices for this user 86 61 // 87 62 function get_devices($user) { 88 debug("get_devices: user: $user", 8);89 63 global $astman; 90 64 modules/branches/2.10/queues/functions.inc/dialplan.php
r13275 r13401 54 54 queue_agent_del_toggle(); 55 55 queue_agent_add_toggle(); 56 $ext->addGlobal('QUEUETOGGLE',$que_code); 56 57 } 57 58 $qlist = queues_list(true); … … 293 294 if ($que_code != '') { 294 295 $ext->add($c, $que_code, '', new ext_goto('start','s','app-all-queue-toggle')); 295 } 296 296 297 // create a generic one for any phones that don't get a specific one created since we only 298 // create them for phones we know have queues but who knows what is provisioned on the phones 299 // 300 $ext->add($c, '_' . $que_code . '*X.', '', new ext_goto('start','s','app-all-queue-toggle')); 301 302 // generate with #exec if we are using dynamic hints 303 // 304 if ($amp_conf['DYNAMICHINTS']) { 305 $ext->addExec($c,$amp_conf['AMPBIN'].'/generate_queue_hints.php '.$que_code); 306 } else { 307 // Create hash of which queues each user is in 308 // 309 $qpenalty=$astman->database_show('QPENALTY'); 310 $qc = array(); 311 foreach(array_keys($qpenalty) as $key) { 312 $key = explode('/', $key); 313 if ($key[3] == 'agents') { 314 $qc[$key[4]][] = $key[2]; 315 } 316 } 317 318 // Make sure we have all the devices 319 // 320 if (!isset($device_list)) { 321 $device_list = core_devices_list("all", 'full', true); 322 } 323 324 foreach ($device_list as $device) { 325 if ($device['tech'] == 'sip' || $device['tech'] == 'iax2') { 326 $ext->add($c, $que_code . '*' . $device['id'], '', new ext_goto('start','s','app-all-queue-toggle')); 327 if ($device['user'] != '' && isset($qc[$device['user']])) { 328 $hlist = 'Custom:QUEUE' . $device['id'] . '*' . implode('&Custom:QUEUE' . $device['id'] . '*', $qc[$device['user']]); 329 $ext->addHint($c, $que_code . '*' . $device['id'], $hlist); 330 } 331 } 332 } 333 } 334 } 335 297 336 // We need to have a hangup here, if call is ended by the caller during Playback it will end in the 298 337 // h context and do a proper hangup and clean the blkvm if set, see #4671
