Portions created by the Initial Developer are Copyright (C) 2008-2016 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('call_center_agent_add') || permission_exists('call_center_agent_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //check for duplicates if ($_GET["check"] == 'duplicate') { //agent id if ($_GET["agent_id"] != '') { $sql = "select "; $sql .= "agent_name "; $sql .= "from "; $sql .= "v_call_center_agents "; $sql .= "where "; $sql .= "agent_id = '".check_str($_GET["agent_id"])."' "; $sql .= "and domain_uuid = '".$domain_uuid."' "; if ($_GET["agent_uuid"] != '') { $sql .= " and call_center_agent_uuid <> '".check_str($_GET["agent_uuid"])."' "; } $prep_statement = $db->prepare($sql); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if ($row['agent_name'] != '') { echo $text['message-duplicate_agent_id'].((if_group("superadmin")) ? ": ".$row["agent_name"] : null); } } unset($prep_statement); } exit; } //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $call_center_agent_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //get http post variables and set them to php variables if (is_array($_POST)) { $call_center_agent_uuid = check_str($_POST["call_center_agent_uuid"]); $user_uuid = check_str($_POST["user_uuid"]); $agent_name = check_str($_POST["agent_name"]); $agent_type = check_str($_POST["agent_type"]); $agent_call_timeout = check_str($_POST["agent_call_timeout"]); $agent_id = check_str($_POST["agent_id"]); $agent_password = check_str($_POST["agent_password"]); $agent_status = check_str($_POST["agent_status"]); $agent_contact = check_str($_POST["agent_contact"]); $agent_no_answer_delay_time = check_str($_POST["agent_no_answer_delay_time"]); $agent_max_no_answer = check_str($_POST["agent_max_no_answer"]); $agent_wrap_up_time = check_str($_POST["agent_wrap_up_time"]); $agent_reject_delay_time = check_str($_POST["agent_reject_delay_time"]); $agent_busy_delay_time = check_str($_POST["agent_busy_delay_time"]); //$agent_logout = check_str($_POST["agent_logout"]); } //process the user data and save it to the database if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //get the uuid from the POST if ($action == "update") { $call_center_agent_uuid = check_str($_POST["call_center_agent_uuid"]); } //check for all required data $msg = ''; //if (strlen($call_center_agent_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-call_center_agent_uuid']."
\n"; } //if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; } //if (strlen($user_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-user_uuid']."
\n"; } if (strlen($agent_name) == 0) { $msg .= $text['message-required']." ".$text['label-agent_name']."
\n"; } if (strlen($agent_type) == 0) { $msg .= $text['message-required']." ".$text['label-agent_type']."
\n"; } if (strlen($agent_call_timeout) == 0) { $msg .= $text['message-required']." ".$text['label-agent_call_timeout']."
\n"; } //if (strlen($agent_id) == 0) { $msg .= $text['message-required']." ".$text['label-agent_id']."
\n"; } //if (strlen($agent_password) == 0) { $msg .= $text['message-required']." ".$text['label-agent_password']."
\n"; } if (strlen($agent_status) == 0) { $msg .= $text['message-required']." ".$text['label-agent_status']."
\n"; } if (strlen($agent_contact) == 0) { $msg .= $text['message-required']." ".$text['label-agent_contact']."
\n"; } if (strlen($agent_no_answer_delay_time) == 0) { $msg .= $text['message-required']." ".$text['label-agent_no_answer_delay_time']."
\n"; } if (strlen($agent_max_no_answer) == 0) { $msg .= $text['message-required']." ".$text['label-agent_max_no_answer']."
\n"; } if (strlen($agent_wrap_up_time) == 0) { $msg .= $text['message-required']." ".$text['label-agent_wrap_up_time']."
\n"; } if (strlen($agent_reject_delay_time) == 0) { $msg .= $text['message-required']." ".$text['label-agent_reject_delay_time']."
\n"; } if (strlen($agent_busy_delay_time) == 0) { $msg .= $text['message-required']." ".$text['label-agent_busy_delay_time']."
\n"; } //if (strlen($agent_logout) == 0) { $msg .= $text['message-required']." ".$text['label-agent_logout']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //get and then set the complete agent_contact with the call_timeout and when necessary confirm //if you change this variable, also change resources/switch.php $confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1,group_confirm_read_timeout=2000,leg_timeout=".$agent_call_timeout; if(strstr($agent_contact, '}') === FALSE) { //not found if(stristr($agent_contact, 'sofia/gateway') === FALSE) { //add the call_timeout $agent_contact = "{call_timeout=".$agent_call_timeout.",sip_invite_domain=".$_SESSION['domain_name']."}".$agent_contact; } else { //add the call_timeout and confirm $agent_contact = $first.',call_timeout='.$agent_call_timeout.$last; $agent_contact = "{".$confirm.",call_timeout=".$agent_call_timeout.",sip_invite_domain=".$_SESSION['domain_name']."}".$agent_contact; } } else { $position = strrpos($agent_contact, "}"); $first = substr($agent_contact, 0, $position); $last = substr($agent_contact, $position); //add call_timeout and sip_invite_domain, only if missing $call_timeout = (stristr($agent_contact, 'call_timeout') === FALSE) ? ',call_timeout='.$agent_call_timeout : null; $sip_invite_domain = (stristr($agent_contact, 'sip_invite_domain') === FALSE) ? ',sip_invite_domain='.$_SESSION['domain_name'] : null; //compose if(stristr($agent_contact, 'sofia/gateway') === FALSE) { $agent_contact = $first.$sip_invite_domain.$call_timeout.$last; } else { $agent_contact = $first.','.$confirm.$sip_invite_domain.$call_timeout.$last; } } //add the agent //setup the event socket connection $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); //add the agent using event socket if ($fp) { //add the agent $cmd = "api callcenter_config agent add ".$call_center_agent_uuid." ".$agent_type; $response = event_socket_request($fp, $cmd); usleep(200); //agent set contact $cmd = "api callcenter_config agent set contact ".$call_center_agent_uuid." ".$agent_contact; $response = event_socket_request($fp, $cmd); usleep(200); //agent set status $cmd = "api callcenter_config agent set status ".$call_center_agent_uuid." '".$agent_status."'"; $response = event_socket_request($fp, $cmd); usleep(200); //agent set reject_delay_time $cmd = "api callcenter_config agent set reject_delay_time ".$call_center_agent_uuid." ".$agent_reject_delay_time; $response = event_socket_request($fp, $cmd); usleep(200); //agent set busy_delay_time $cmd = "api callcenter_config agent set busy_delay_time ".$call_center_agent_uuid." ".$agent_busy_delay_time; $response = event_socket_request($fp, $cmd); //agent set no_answer_delay_time $cmd = "api callcenter_config agent set no_answer_delay_time ".$call_center_agent_uuid." ".$agent_no_answer_delay_time; $response = event_socket_request($fp, $cmd); //agent set max_no_answer $cmd = "api callcenter_config agent set max_no_answer ".$call_center_agent_uuid." ".$agent_max_no_answer; $response = event_socket_request($fp, $cmd); //agent set wrap_up_time $cmd = "api callcenter_config agent set wrap_up_time ".$call_center_agent_uuid." ".$agent_wrap_up_time; $response = event_socket_request($fp, $cmd); } //set the domain_uuid $_POST["domain_uuid"] = $_SESSION["domain_uuid"]; //add the call_center_agent_uuid if (strlen($_POST["call_center_agent_uuid"]) == 0) { $call_center_agent_uuid = uuid(); $_POST["call_center_agent_uuid"] = $call_center_agent_uuid; } //get the users array $sql = "SELECT * FROM v_users "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "order by username asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $users = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset($prep_statement, $sql); //prepare the array $array['call_center_agents'][] = $_POST; if (isset($user_uuid) && strlen($user_uuid) > 0) { $array['users'][0]['domain_uuid'] = $_SESSION['domain_uuid']; $array['users'][0]['user_uuid'] = $user_uuid; $array['users'][0]['user_status'] = $agent_status; } //save to the data $database = new database; $database->app_name = 'call_center'; $database->app_uuid = '95788e50-9500-079e-2807-fd530b0ea370'; if (strlen($call_center_agent_uuid) > 0) { $database->uuid($call_center_agent_uuid); } $database->save($array); $message = $database->message; //syncrhonize configuration save_call_center_xml(); //clear the cache remove_config_from_cache('configuration:callcenter.conf'); //redirect the user if (isset($action)) { if ($action == "add") { message::add($text['message-add']); } if ($action == "update") { message::add($text['message-update']); } header("Location: call_center_agents.php"); return; } } //(is_array($_POST) && strlen($_POST["persistformvar"]) == 0) //initialize the destinations object $destination = new destinations; //pre-populate the form if (is_array($_GET) && $_POST["persistformvar"] != "true") { $call_center_agent_uuid = check_str($_GET["id"]); $sql = "select * from v_call_center_agents "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and call_center_agent_uuid = '$call_center_agent_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $call_center_agent_uuid = $row["call_center_agent_uuid"]; $user_uuid = $row["user_uuid"]; $agent_name = $row["agent_name"]; $agent_type = $row["agent_type"]; $agent_call_timeout = $row["agent_call_timeout"]; $agent_id = $row["agent_id"]; $agent_password = $row["agent_password"]; $agent_status = $row["agent_status"]; $agent_contact = $row["agent_contact"]; $agent_no_answer_delay_time = $row["agent_no_answer_delay_time"]; $agent_max_no_answer = $row["agent_max_no_answer"]; $agent_wrap_up_time = $row["agent_wrap_up_time"]; $agent_reject_delay_time = $row["agent_reject_delay_time"]; $agent_busy_delay_time = $row["agent_busy_delay_time"]; //$agent_logout = $row["agent_logout"]; } unset ($prep_statement); } //set default values if (strlen($agent_type) == 0) { $agent_type = "callback"; } if (strlen($agent_call_timeout) == 0) { $agent_call_timeout = "20"; } if (strlen($agent_max_no_answer) == 0) { $agent_max_no_answer = "0"; } if (strlen($agent_wrap_up_time) == 0) { $agent_wrap_up_time = "10"; } if (strlen($agent_no_answer_delay_time) == 0) { $agent_no_answer_delay_time = "30"; } if (strlen($agent_reject_delay_time) == 0) { $agent_reject_delay_time = "90"; } if (strlen($agent_busy_delay_time) == 0) { $agent_busy_delay_time = "90"; } //show the header require_once "resources/header.php"; if ($action == "add") { $document['title'] = $text['title-call_center_agent_add']; } if ($action == "update") { $document['title'] = $text['title-call_center_agent_edit']; } //get the list of users for this domain $sql = "SELECT * FROM v_users "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and user_enabled = 'true' "; $sql .= "order by username asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $users = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset($sql); //javascript to check for duplicates ?> \n"; echo "\n"; echo "\n"; if ($action == "add") { echo "\n"; } if ($action == "update") { echo "\n"; } echo "\n"; echo "\n"; echo "
".$text['header-call_center_agent_add']."".$text['header-call_center_agent_edit'].""; echo " "; echo " \n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " "; echo " "; echo " "; echo " "; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; /* echo "\n"; echo "\n"; echo "\n"; echo "\n"; */ echo " \n"; echo " \n"; echo " "; echo "
\n"; echo " ".$text['label-agent_name']."\n"; echo "\n"; echo " \n"; /* echo ""; */ echo "
\n"; echo $text['description-agent_name']."\n"; echo "
\n"; echo " ".$text['label-type']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-type']."\n"; echo "
\n"; echo " ".$text['label-call_timeout']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_timeout']."\n"; echo "
".$text['label-username'].""; echo " "; unset($users); echo "
\n"; echo " ".$text['description-users']."\n"; echo "
\n"; echo " ".$text['label-agent_id']."\n"; echo "\n"; echo " \n"; echo " \n"; echo "
\n"; echo $text['description-agent_id']."\n"; echo "
\n"; echo " ".$text['label-agent_password']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-agent_password']."\n"; echo "
\n"; echo " ".$text['label-contact']."\n"; echo "\n"; echo $destination->select('user_contact', 'agent_contact', $agent_contact); echo "
\n"; echo $text['description-contact']."\n"; echo "
\n"; echo " ".$text['label-status']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-status']."\n"; echo "
\n"; echo " ".$text['label-no_answer_delay_time']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-no_answer_delay_time']."\n"; echo "
\n"; echo " ".$text['label-max_no_answer']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-max_no_answer']."\n"; echo "
\n"; echo " ".$text['label-wrap_up_time']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-wrap_up_time']."\n"; echo "
\n"; echo " ".$text['label-reject_delay_time']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-reject_delay_time']."\n"; echo "
\n"; echo " ".$text['label-busy_delay_time']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-busy_delay_time']."\n"; echo "
\n"; echo " ".$text['label-agent_logout']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-agent_logout']."\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo "
"; echo ""; echo "

"; //include the footer require_once "resources/footer.php"; ?>