Portions created by the Initial Developer are Copyright (C) 2008-2023 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 3) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('operator_panel_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(null,'app/basic_operator_panel'); //get the call activity $operator_panel = new basic_operator_panel; $activity = $operator_panel->call_activity(); if (is_array($activity)) { foreach ($activity as $extension => $fields) { if (!empty($fields['call_group']) && substr_count($fields['call_group'], ',')) { $tmp = explode(',', $fields['call_group']); if (is_array($tmp)) foreach ($tmp as $tmp_index => $tmp_value) { if (trim($tmp_value) == '') { unset($tmp[$tmp_index]); } else { $groups[] = $tmp_value; } } } else if ($fields['call_group'] != '') { $groups[] = $fields['call_group']; } } } if (!empty($groups)) { $groups = array_unique($groups); sort($groups); } //get the valet info $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $valet_info = event_socket_request($fp, 'api valet_info park@'.$_SESSION['domain_name']); //get an array of the valet call uuid and park numbers if (isset($valet_info)) { preg_match_all('/(.*?)<\/extension>/s', $valet_info, $valet_matches, PREG_SET_ORDER); //view_array($valet_matches, false); } //view_array($valet_matches, false); //unset($_SESSION['valet']); foreach($valet_matches as $row) { if (!isset($_SESSION['valet']['uuid']['caller_id_name'])) { $_SESSION['valet'][$row[1]]['caller_id_name'] = event_socket_request($fp, 'api uuid_getvar '.$row[1].' caller_id_name'); } if (!isset($_SESSION['valet']['uuid']['caller_id_number'])) { $_SESSION['valet'][$row[1]]['caller_id_number'] = event_socket_request($fp, 'api uuid_getvar '.$row[1].' caller_id_number'); } } //unset the array //view_array($_SESSION['valet']); //reformat the array and add the caller ID name and numbers $x = 0; foreach($valet_matches as $row) { $valet_array[$x]['uuid'] = $row[1]; $valet_array[$x]['extension'] = $row[2]; if (isset($_SESSION['valet'][$row[1]]['caller_id_name'])) { $valet_array[$x]['caller_id_name'] = $_SESSION['valet'][$row[1]]['caller_id_name']; } if (isset($_SESSION['valet'][$row[1]]['caller_id_number'])) { $valet_array[$x]['caller_id_number'] = $_SESSION['valet'][$row[1]]['caller_id_number']; } $x++; } //view_array($valet, false); } //prevent warnings if (empty($_SESSION['user']['extensions'])) { $_SESSION['user']['extensions'] = array(); } //get registrations -- All SIP profiles $obj = new registrations; $registrations = $obj->get("all"); //set the onhover paush refresh $onhover_pause_refresh = " onmouseover='refresh_stop();' onmouseout='refresh_start();'"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['title-operator_panel']."\n"; echo " \n"; if (permission_exists("user_setting_edit") && sizeof($_SESSION['user']['extensions']) > 0) { $status_options[1]['status'] = "Available"; $status_options[1]['label'] = $text['label-status_available']; $status_options[1]['style'] = "op_btn_status_available"; if (permission_exists('operator_panel_on_demand')) { $status_options[2]['status'] = "Available (On Demand)"; $status_options[2]['label'] = $text['label-status_on_demand']; $status_options[2]['style'] = "op_btn_status_available_on_demand"; } $status_options[3]['status'] = "On Break"; $status_options[3]['label'] = $text['label-status_on_break']; $status_options[3]['style'] = "op_btn_status_on_break"; $status_options[4]['status'] = "Do Not Disturb"; $status_options[4]['label'] = $text['label-status_do_not_disturb']; $status_options[4]['style'] = "op_btn_status_do_not_disturb"; $status_options[5]['status'] = "Logged Out"; $status_options[5]['label'] = $text['label-status_logged_out']; $status_options[5]['style'] = "op_btn_status_logged_out"; if (is_array($status_options)) foreach ($status_options as $status_option) { echo " \n"; } } echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('operator_panel_eavesdrop')) { echo " \n"; } if (!empty($groups)) { echo " \n"; } echo " \n"; echo " \n"; echo "
\n"; echo " \"".$text['label-refresh_pause']."\"\n"; echo " \n"; if (sizeof($_SESSION['user']['extensions']) > 1) { echo " \n"; echo " \n"; echo " \n"; } else if (sizeof($_SESSION['user']['extensions']) == 1) { echo " \n"; } echo " \n"; echo " \n"; if (sizeof($groups) > 5) { //show select box echo " \n"; } else { //show buttons echo " \n"; if (is_array($groups)) { foreach ($groups as $group) { echo " \n"; } } } echo " \n"; echo " \n"; if (!empty($_REQUEST['filter'])) { echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','style'=>(empty($_REQUEST['filter']) ? 'display: none;' : null),'onclick'=>"document.getElementById('search').value = '';",'onmouseover'=>'refresh_stop();','onmouseout'=>'refresh_start();']); } echo "
\n"; echo "
\n"; echo "
\n"; //define the arrays to ensure no errors are omitted below with the sizeof operators $user_extensions = array(); $grouped_extensions = array(); $other_extensions = array(); //loop through the array if (is_array($activity)) { foreach ($activity as $extension => $ext) { unset($block); //filter by group, if defined if ($_REQUEST['group'] != '' && substr_count($ext['call_group'], $_REQUEST['group']) == 0 && !in_array($extension, $_SESSION['user']['extensions'])) { continue; } //filter by extension or name, if defined if (!empty($_REQUEST['filter'])) { if ( !in_array($extension, $_SESSION['user']['extensions']) && ( substr_count($ext['extension'], $_REQUEST['filter']) == 0 && substr_count(strtolower($ext['description'] ?? ''), strtolower($_REQUEST['filter'])) == 0 && substr_count(strtolower($ext['effective_caller_id_name'] ?? ''), strtolower($_REQUEST['filter'])) == 0 ) ) { continue; } } //check if feature code being called $format_number = (!empty($ext['dest']) && substr($ext['dest'], 0, 1) == '*') ? false : true; //determine extension state, direction icon, and displayed name/number for caller/callee if ($ext['state'] == 'CS_EXECUTE') { if (($ext['callstate'] == 'RINGING' || $ext['callstate'] == 'EARLY' || $ext['callstate'] == 'RING_WAIT') && $ext['direction'] == 'inbound') { $ext_state = 'ringing'; } else if ($ext['callstate'] == 'ACTIVE' && $ext['direction'] == 'outbound') { $ext_state = 'active'; } else if ($ext['callstate'] == 'HELD' && $ext['direction'] == 'outbound') { $ext_state = 'held'; } else if ($ext['callstate'] == 'RING_WAIT' && $ext['direction'] == 'outbound') { $ext_state = 'ringing'; } else if ($ext['callstate'] == 'ACTIVE' && $ext['direction'] == 'inbound') { $ext_state = 'active'; } else if ($ext['callstate'] == 'HELD' && $ext['direction'] == 'inbound') { $ext_state = 'held'; } if (!$format_number) { $call_name = 'System'; $call_number = $ext['dest']; } else { $call_name = $activity[$ext['dest']]['effective_caller_id_name'] ?? null; $call_number = format_phone($ext['dest']); } $dir_icon = 'outbound'; } else if ($ext['state'] == 'CS_HIBERNATE') { if ($ext['callstate'] == 'ACTIVE') { $ext_state = 'active'; if ($ext['direction'] == 'inbound') { $call_name = $activity[$ext['dest']]['effective_caller_id_name']; $call_number = format_phone($ext['dest']); $dir_icon = 'outbound'; } else if ($ext['direction'] == 'outbound') { $call_name = $activity[$ext['cid_num']]['effective_caller_id_name']; $call_number = format_phone($ext['cid_num']); $dir_icon = 'inbound'; } } } else if ($ext['state'] == 'CS_EXCHANGE_MEDIA' && $ext['callstate'] == 'ACTIVE' && $ext['direction'] == 'inbound') { //valet park $ext_state = 'active'; $call_name = $activity[$ext['dest']]['effective_caller_id_name']; $call_number = format_phone($ext['dest']); } else if ($ext['state'] == 'CS_SOFT_EXECUTE' && $ext['callstate'] == 'ACTIVE' && $ext['direction'] == 'outbound') { //valet park $ext_state = 'active'; $call_name = $activity[$ext['dest']]['effective_caller_id_name']; $call_number = format_phone($ext['dest']); } else if ($ext['state'] == 'CS_CONSUME_MEDIA' || $ext['state'] == 'CS_EXCHANGE_MEDIA') { if ($ext['state'] == 'CS_CONSUME_MEDIA' && $ext['callstate'] == 'RINGING' && $ext['direction'] == 'outbound') { $ext_state = 'ringing'; } else if ($ext['state'] == 'CS_EXCHANGE_MEDIA' && $ext['callstate'] == 'ACTIVE' && $ext['direction'] == 'outbound') { $ext_state = 'active'; } else if ($ext['state'] == 'CS_EXCHANGE_MEDIA' && $ext['callstate'] == 'ACTIVE' && $ext['direction'] == 'outbound') { $ext_state = 'active'; } else if ($ext['state'] == 'CS_CONSUME_MEDIA' && $ext['callstate'] == 'HELD' && $ext['direction'] == 'outbound') { $ext_state = 'held'; } else if ($ext['state'] == 'CS_EXCHANGE_MEDIA' && $ext['callstate'] == 'HELD' && $ext['direction'] == 'outbound') { $ext_state = 'held'; } $dir_icon = 'inbound'; $call_name = $activity[$ext['cid_num']]['effective_caller_id_name']; $call_number = format_phone($ext['cid_num']); } else { unset($ext_state, $dir_icon, $call_name, $call_number); } //determin extension register status $extension_number = $extension.'@'.$_SESSION['domain_name']; $found_count = 0; if (is_array($registrations)) { foreach ($registrations as $array) { if ($extension_number == $array['user']) { $found_count++; } } } if ($found_count > 0) { //determine block style by state (if any) and register status $style = !empty($ext_state) ? "op_ext op_state_".$ext_state : "op_ext"; } else { $style = "off_ext"; } unset($extension_number, $found_count, $array); //determine the call identifier passed on drop if ($ext['uuid'] == $ext['call_uuid'] && empty($ext['variable_bridge_uuid'])) { // transfer an outbound internal call $call_identifier = $activity[$call_number ?? null]['uuid'] ?? null; } else if (($ext['variable_call_direction'] == 'outbound' || $ext['variable_call_direction'] == 'local') && $ext['variable_bridge_uuid'] != '') { // transfer an outbound external call $call_identifier = $ext['variable_bridge_uuid']; } else { if( $ext['call_uuid'] ) { $call_identifier = $ext['call_uuid']; // transfer all other call types } else { $call_identifier = $ext['uuid']; // e.g. voice menus } } //determine extension draggable state if (permission_exists('operator_panel_manage')) { if (!in_array($extension, $_SESSION['user']['extensions'])) { //other extension if (!empty($ext_state) && $ext_state == "ringing") { if ($_GET['vd_ext_from'] == '' && $dir_icon == 'inbound') { $draggable = true; // selectable - is ringing and not outbound so can transfer away the call (can set as vd_ext_from) } else { $draggable = false; // unselectable - is ringing so can't send a call to the ext (can't set as vd_ext_to) } } else if (!empty($ext_state) && $ext_state == 'active') { $draggable = false; // unselectable - on a call already so can't transfer or send a call to the ext (can't set as vd_ext_from or vd_ext_to) } else { // idle if ($_GET['vd_ext_from'] == '') { $draggable = false; // unselectable - is idle, but can't initiate a call from the ext as is not assigned to user (can't set as vd_ext_from) } else { $draggable = true; // selectable - is idle, so can transfer a call in to ext (can set as vd_ext_to). } } } else { //user extension if ($ext['uuid'] != '' && $ext['uuid'] == $ext['call_uuid'] && empty($ext['variable_bridge_uuid'])) { $draggable = false; } else if (!empty($ext_state) && $ext_state == 'ringing' && $ext['variable_call_direction'] == 'local') { $draggable = false; } else if (!empty($ext_state) && !$format_number) { $draggable = false; } else { $draggable = true; } } } else { $draggable = false; } //determine extension (user) status $ext_status = (in_array($extension, $_SESSION['user']['extensions'])) ? $ext_user_status[$_SESSION['user_uuid']] : $ext_user_status[$ext['user_uuid']] ?? ''; switch ($ext_status) { case "Available" : $status_icon = "available"; $status_hover = $text['label-status_available']; break; case "Available (On Demand)" : $status_icon = "available_on_demand"; $status_hover = $text['label-status_available_on_demand']; break; case "On Break" : $status_icon = "on_break"; $status_hover = $text['label-status_on_break']; break; case "Do Not Disturb" : $status_icon = "do_not_disturb"; $status_hover = $text['label-status_do_not_disturb']; break; default : $status_icon = "logged_out"; $status_hover = $text['label-status_logged_out_or_unknown']; } //build the list of extensions $block = "
"; // DRAG TO $block .= "\n"; $block .= " \n"; $block .= " \n"; $block .= " \n"; $block .= " \n"; $block .= "
\n"; $block .= " \n"; // DRAG FROM $block .= "\n"; $block .= "\n"; $block .= " \n"; if ($dir_icon ?? '') { $block .= " \"".$text['label-call_direction']."\"\n"; } $block .= "
\n"; if ($ext_state ?? '') { $block .= " \n"; $block .= "
\n"; $block .= " ".escape($ext['call_length'])."
\n"; $block .= " \n"; //record if (permission_exists('operator_panel_record') && $ext_state == 'active') { $call_identifier_record = $ext['call_uuid']; $rec_file = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d")."/".escape($call_identifier_record).".wav"; if (file_exists($rec_file)) { $block .= "\n"; } else { $block .= "\n"; } } //eavesdrop if (permission_exists('operator_panel_eavesdrop') && $ext_state == 'active' && sizeof($_SESSION['user']['extensions']) > 0 && !in_array($extension, $_SESSION['user']['extensions'])) { $block .= "\n"; } //hangup if (permission_exists('operator_panel_hangup') || in_array($extension, $_SESSION['user']['extensions'])) { if (empty($ext['variable_bridge_uuid']) && $ext_state == 'ringing') { $call_identifier_hangup_uuid = $ext['uuid']; } else if ($dir_icon == 'outbound') { $call_identifier_hangup_uuid = $ext['uuid']; } else { $call_identifier_hangup_uuid = $call_identifier; } $block .= "\n"; } $block .= "\n"; //transfer if (in_array($extension, $_SESSION['user']['extensions']) && $ext_state == 'active') { $block .= "\n"; } $block .= "
\n"; if (permission_exists('operator_panel_call_details')) { $block .= " ".escape($call_name)."
".escape($call_number)."
\n"; } $block .= "
\n"; //transfer if (in_array($extension, $_SESSION['user']['extensions']) && $ext_state == 'active') { $call_identifier_transfer = $ext['variable_bridge_uuid']; $block .= "
\n"; $block .= " \n"; $block .= "
\n"; } } else { //call if (in_array($extension, $_SESSION['user']['extensions'])) { $block .= " \n"; $block .= "
\n"; $block .= " \n"; $block .= "
\n"; } } $block .= "
\n"; if (if_group("superadmin") && isset($_GET['debug'])) { $block .= "\n"; $block .= "From ID
    ".escape($extension)."
\n"; $block .= "uuid
    ".escape($ext['uuid'])."
\n"; $block .= "call_uuid
    ".escape($ext['call_uuid'])."
\n"; $block .= "variable_bridge_uuid
    ".escape($ext['variable_bridge_uuid'])."
\n"; $block .= "direction
    ".escape($ext['direction'])."
\n"; $block .= "variable_call_direction
    ".escape($ext['variable_call_direction'])."
\n"; $block .= "state
    ".escape($ext['state'])."
\n"; $block .= "cid_num
    ".escape($ext['cid_num'])."
\n"; $block .= "dest
    ".escape($ext['dest'])."
\n"; $block .= "context
    ".escape($ext['context'])."
\n"; $block .= "presence_id
    ".escape($ext['presence_id'])."
\n"; $block .= "callstate
    ".escape($ext['callstate'])."
\n"; $block .= "
\n"; } $block .= "
\n"; if (in_array($extension, $_SESSION['user']['extensions'])) { $user_extensions[] = $block; } elseif (!empty($ext['call_group']) && filter_var($_SESSION['operator_panel']['group_extensions']['boolean'], FILTER_VALIDATE_BOOLEAN)) { $grouped_extensions[$ext['call_group']][] = $block; } else { $other_extensions[] = $block; } } } if (sizeof($user_extensions) > 0) { echo "
\n"; if (is_array($user_extensions)) { foreach ($user_extensions as $ext_block) { echo $ext_block; } } if (!empty($valet_array) && is_array($valet_array) && @sizeof($valet_array) != 0) { foreach ($valet_array as $row) { $extension = $row['extension']; $ext_state = 'active'; $style = "op_ext op_valet_park_active"; $draggable = false; //build the list of park extensions $valet_block .= "
\n"; // DRAG TO $valet_block .= "\n"; $valet_block .= " \n"; $valet_block .= " \n"; $valet_block .= " \n"; $valet_block .= " \n"; $valet_block .= "
\n"; $valet_block .= " "; // DRAG FROM $valet_block .= "\n"; $valet_block .= "\n"; $valet_block .= " \n"; if ($dir_icon != '') { $valet_block .= " \"".$text['label-call_direction']."\"\n"; } $valet_block .= "
\n"; //if ($ext_state != '') { $valet_block .= " \n"; $valet_block .= "
\n"; $valet_block .= " ".escape($ext['call_length'])."
\n"; $valet_block .= " \n"; $call_identifier_record = $ext['call_uuid']; $valet_block .= "\n"; //transfer //if (in_array($extension, $_SESSION['user']['extensions']) && $ext_state == 'active') { // $valet_block .= ""; //} $valet_block .= "
\n"; if (permission_exists('operator_panel_call_details')) { $valet_block .= " ".escape($row['caller_id_name'])."
".escape($row['caller_id_number'])."
\n"; } $valet_block .= "
\n"; //transfer //if (in_array($extension, $_SESSION['user']['extensions']) && $ext_state == 'active') { $call_identifier_transfer = $ext['variable_bridge_uuid']; $valet_block .= "
\n"; $valet_block .= " \n"; $valet_block .= "
\n"; //} //} //else { // //call // if (in_array($extension, $_SESSION['user']['extensions'])) { // $valet_block .= " "; // $valet_block .= "
"; // $valet_block .= " "; // $valet_block .= "
\n"; // } //} $valet_block .= "
\n"; if (if_group("superadmin") && isset($_GET['debug'])) { $valet_block .= "\n"; $valet_block .= "From ID
    ".escape($extension)."
\n"; $valet_block .= "uuid
    ".escape($ext['uuid'])."
\n"; $valet_block .= "call_uuid
    ".escape($ext['call_uuid'])."
\n"; $valet_block .= "variable_bridge_uuid
    ".escape($ext['variable_bridge_uuid'])."
\n"; $valet_block .= "direction
    ".escape($ext['direction'])."
\n"; $valet_block .= "variable_call_direction
    ".escape($ext['variable_call_direction'])."
\n"; $valet_block .= "state
    ".escape($ext['state'])."
\n"; $valet_block .= "cid_num
    ".escape($ext['cid_num'])."
\n"; $valet_block .= "dest
    ".escape($ext['dest'])."
\n"; $valet_block .= "context
    ".escape($ext['context'])."
\n"; $valet_block .= "presence_id
    ".escape($ext['presence_id'])."
\n"; $valet_block .= "callstate
    ".escape($ext['callstate'])."
\n"; $valet_block .= "
\n"; } $valet_block .= "
\n"; echo $valet_block; unset($valet_block); } } echo "

\n"; } //loop throug each group if (sizeof($grouped_extensions) > 0) { //alphabetical order ksort($grouped_extensions); //loop through the groups foreach ($grouped_extensions as $group => $extensions) { echo "
".ucwords(escape($group))."
\n"; echo "

\n"; echo "
\n"; foreach ($extensions as $ext_block) { echo $ext_block; } echo "

\n"; } } //show the other extensions if (sizeof($other_extensions) > 0) { echo "
".$text['label-other_extensions']."
\n"; echo "

\n"; echo "
\n"; foreach ($other_extensions as $ext_block) { echo $ext_block; } echo "
\n"; } //no extensions found if (sizeof($other_extensions) + sizeof($grouped_extensions) < 1) { echo $text['label-no_extensions_found']; } echo "

\n"; /* if (if_group("superadmin") && isset($_GET['debug'])) { echo '$activity
'; echo ""; echo "

"; echo '$_SESSION
'; echo ""; } */ ?>