fixed call center agent save

This commit is contained in:
FusionPBX 2024-10-07 13:07:03 -06:00 committed by GitHub
parent 7ecfe96381
commit ab8108e3b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 91 deletions

View File

@ -42,36 +42,14 @@
$language = new text;
$text = $language->get();
//connect to the database
$database = new database;
//set the defaults
$agent_id = '';
$agent_name = '';
$agent_password = '';
//check for duplicates
if (!empty($_GET["check"]) && $_GET["check"] == 'duplicate') {
//agent id
if (!empty($_GET["agent_id"])) {
$sql = "select agent_name ";
$sql .= "from v_call_center_agents ";
$sql .= "where agent_id = :agent_id ";
$sql .= "and domain_uuid = :domain_uuid ";
if (!empty($_GET["agent_uuid"]) && is_uuid($_GET["agent_uuid"])) {
$sql .= " and call_center_agent_uuid <> :call_center_agent_uuid ";
$parameters['call_center_agent_uuid'] = $_GET["agent_uuid"];
}
$parameters['agent_id'] = $_GET["agent_id"];
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (!empty($row) && !empty($row['agent_name'])) {
echo $text['message-duplicate_agent_id'].(if_group("superadmin") ? ": ".$row["agent_name"] : null);
}
unset($sql, $parameters);
}
exit;
}
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
@ -81,6 +59,14 @@
$action = "add";
}
//get the users array
$sql = "select * from v_users ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "order by username asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$users = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//get http post variables and set them to php variables
if (!empty($_POST)) {
$call_center_agent_uuid = $_POST["call_center_agent_uuid"] ?? null;
@ -151,15 +137,6 @@
$call_center_agent_uuid = uuid();
}
//get the users array
$sql = "select * from v_users ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "order by username asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$users = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//change the contact string to loopback - Not recommended added for backwards comptability causes multiple problems
if ($_SESSION['call_center']['agent_contact_method']['text'] == 'loopback') {
$agent_contact = str_replace("user/", "loopback/", $agent_contact);
@ -193,11 +170,9 @@
}
//save to the data
$database = new database;
$database->app_name = 'call_center';
$database->app_uuid = '95788e50-9500-079e-2807-fd530b0ea370';
$database->save($array);
//$message = $database->message;
//syncrhonize configuration
save_call_center_xml();
@ -295,7 +270,6 @@
$sql .= "and call_center_agent_uuid = :call_center_agent_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['call_center_agent_uuid'] = $call_center_agent_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (!empty($row)) {
$call_center_agent_uuid = $row["call_center_agent_uuid"];
@ -338,47 +312,12 @@
if ($action == "update") {
$document['title'] = $text['title-call_center_agent_edit'];
}
//include the header
require_once "resources/header.php";
//get the list of users for this domain
$sql = "select * from v_users ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and user_enabled = 'true' ";
$sql .= "order by username asc ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$users = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//javascript to check for duplicates
?>
<script language="javascript">
function check_duplicates() {
//check agent id
var agent_id = document.getElementById('agent_id').value;
$("#duplicate_agent_id_response").load("call_center_agent_edit.php?check=duplicate&agent_id="+agent_id+"&agent_uuid=<?php echo escape($call_center_agent_uuid ?? ''); ?>", function() {
var duplicate_agent_id = false;
if ($("#duplicate_agent_id_response").html() != '') {
$('#agent_id').addClass('formfld_highlight_bad');
display_message($("#duplicate_agent_id_response").html(), 'negative'<?php if (if_group("superadmin")) { echo ', 3000'; } ?>);
duplicate_agent_id = true;
}
else {
$("#duplicate_agent_id_response").html('');
$('#agent_id').removeClass('formfld_highlight_bad');
duplicate_agent_id = false;
}
if (duplicate_agent_id == false) {
document.getElementById('frm').submit();
}
});
}
</script>
<?php
//show the content
echo "<form method='post' name='frm' id='frm' onsubmit='check_duplicates(); return false;'>\n";
echo "<form method='post' name='frm' id='frm' onsubmit=''>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'>";
@ -404,21 +343,6 @@
echo "</td>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='agent_name' maxlength='255' value=\"".escape($agent_name)."\" />\n";
/*
echo "<select id=\"agent_name\" name=\"agent_name\" class='formfld'>\n";
echo "<option value=\"\"></option>\n";
if (is_array($users)) {
foreach($users as $field) {
if ($field[username] == $agent_name) {
echo "<option value='".escape($field[username])."' selected='selected'>".escape($field[username])."</option>\n";
}
else {
echo "<option value='".escape($field[username])."'>".escape($field[username])."</option>\n";
}
}
}
echo "</select>";
*/
echo "<br />\n";
echo $text['description-agent_name']."\n";
echo "</td>\n";
@ -467,7 +391,6 @@
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='number' name='agent_id' id='agent_id' maxlength='255' min='1' step='1' value='".escape($agent_id)."'>\n";
echo " <div style='display: none;' id='duplicate_agent_id_response'></div>\n";
echo "<br />\n";
echo $text['description-agent_id']."\n";
echo "</td>\n";