Changeset 13401

Show
Ignore:
Timestamp:
02/07/12 19:44:19 (1 year ago)
Author:
p_lindheimer
Message:

adds a hint for all devices for the all queue toggle, some testing done needs more but checking in to preserve code changes re #5456

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/core/agi-bin/user_login_out.agi

    r11663 r13401  
    5151  $fm_devstate  = get_var( "FMDEVSTATE" ) == "TRUE" ? true : false; 
    5252  $que_devstate = get_var( "QUEDEVSTATE" ) == "TRUE" ? true : false; 
     53  $queue_toggle = get_var( "QUEUETOGGLE" ); 
    5354  $intercom_code = get_var( "INTERCOMCODE" ); 
    5455  $campon_toggle = get_var( "CAMPONTOGGLE" ); 
     
    5859  $DEVSTATE = version_compare($ast_version, "1.6", "ge") ? "DEVICE_STATE" : "DEVSTATE"; 
    5960 
    60   /* 
    61   $ampmgruser  = 'admin'; 
    62   $ampmgrpass  = 'amp111'; 
    63   */ 
    6461  $astman = new AGI_AsteriskManager( );  
    6562  if (!$astman->connect("127.0.0.1", $ampmgruser , $ampmgrpass)) { 
     
    221218    global $cf_devstate; 
    222219    global $que_devstate; 
     220    global $queue_toggle; 
    223221    global $DEVSTATE; 
    224222 
     
    249247      } 
    250248      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); 
    252250        set_queue_states($user,$device,'off'); 
    253                   } 
     251        if ($queue_toggle) { 
     252          remove_queue_hint($device); 
     253        } 
     254      } 
    254255      if ($dnd_devstate) { 
    255256        debug("Setting device $device DND state to INVALID before deleting",5); 
     
    271272  } 
    272273 
     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 
    273308  // Set the hint for a user based on the devices in their AMPUSER object 
    274309  // 
     
    278313    global $agi; 
    279314    global $dnd_devstate; 
     315    global $que_devstate; 
     316    global $queue_toggle; 
    280317    global $intercom_code; 
    281318    global $campon_toggle; 
     
    292329        $hint_val = 'ccss:'.implode('&ccss:',$dev_arr); 
    293330        $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); 
    294334      } 
    295335      if ($dnd_devstate) { 
     
    491531    debug("set_user_devices: user: $user,  devices: $devices", 8); 
    492532    global $agi; 
    493     if (empty($devices)) { 
     533    if (trim($devices) == '') { 
    494534      debug("No more devices associated with $user, deletting /device key", 8); 
    495535      $agi->database_del('AMPUSER',$user.'/device'); 
     
    592632    } 
    593633  } 
    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  
    88} 
    99 
    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'; 
    1711 
    1812$var = $astman->database_show('AMPUSER'); 
     
    2317 
    2418foreach (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(); 
     28foreach(array_keys($qpenalty) as $key) { 
     29  $key = explode('/', $key); 
     30  if ($key[3] == 'agents') { 
     31    $qc[$key[4]][] = $key[2]; 
     32  } 
     33
     34 
     35foreach ($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]); 
    2942  } 
    3043} 
     
    3447// Set the hint for a user based on the devices in their AMPUSER object 
    3548// 
    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; 
     49function set_hint($device, $queues) { 
     50  global $queue_toggle_code; 
    4251 
    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; 
    6254  } 
     55  $hlist = 'Custom:QUEUE' . $device . '*' . implode('&Custom:QUEUE' . $device . '*', $queues); 
     56  out("exten => $queue_toggle_code*$device,hint,$hlist"); 
    6357} 
    6458 
    65 // Get the actual technology dialstrings from the DEVICE objects (used 
    66 // 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 } 
    8459 
    8560// Get the list of current devices for this user 
    8661// 
    8762function get_devices($user) { 
    88   debug("get_devices: user: $user", 8); 
    8963  global $astman; 
    9064 
  • modules/branches/2.10/queues/functions.inc/dialplan.php

    r13275 r13401  
    5454        queue_agent_del_toggle(); 
    5555        queue_agent_add_toggle(); 
     56        $ext->addGlobal('QUEUETOGGLE',$que_code); 
    5657      } 
    5758      $qlist = queues_list(true); 
     
    293294      if ($que_code != '') { 
    294295        $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 
    297336      // We need to have a hangup here, if call is ended by the caller during Playback it will end in the 
    298337      // h context and do a proper hangup and clean the blkvm if set, see #4671