mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Convert use of operator table for extensions to extension table
This commit is contained in:
@@ -45,24 +45,24 @@ include ("../functions/functions.xhtml.php");
|
||||
|
||||
xhtml_head(T_("Display extension status"),true,array("../css/table.css"));
|
||||
|
||||
$sql= "SELECT o.firstName, o.extension, CASE o.voip_status WHEN 0 THEN '" . T_("VoIP Offline") . "' ELSE '" . T_("VoIP Online") . "' END as voip_status, CASE ca.state WHEN 0 THEN '" . T_("Not called") . "' WHEN 1 THEN '" . T_("Requesting call") . "' WHEN 2 THEN '" . T_("Ringing") . "' WHEN 3 THEN '" . T_("Answered") . "' WHEN 4 THEN '" . T_("Requires coding") . "' ELSE '" . T_("Done") . "' END as state, CONCAT('<a href=\'supervisor.php?case_id=', c.case_id , '\'>' , c.case_id, '</a>') as case_id, SEC_TO_TIME(TIMESTAMPDIFF(SECOND,cal.start,CONVERT_TZ(NOW(),'SYSTEM','UTC'))) as calltime, voip_status as vs
|
||||
FROM operator as o
|
||||
$sql= "SELECT CONCAT('<a href=\'operatorlist.php?edit=',o.operator_id,'\'>',o.firstName,'</a>') as firstName, e.extension, CASE e.status WHEN 0 THEN '" . T_("VoIP Offline") . "' ELSE '" . T_("VoIP Online") . "' END as status, CASE ca.state WHEN 0 THEN '" . T_("Not called") . "' WHEN 1 THEN '" . T_("Requesting call") . "' WHEN 2 THEN '" . T_("Ringing") . "' WHEN 3 THEN '" . T_("Answered") . "' WHEN 4 THEN '" . T_("Requires coding") . "' ELSE '" . T_("Done") . "' END as state, CONCAT('<a href=\'supervisor.php?case_id=', c.case_id , '\'>' , c.case_id, '</a>') as case_id, SEC_TO_TIME(TIMESTAMPDIFF(SECOND,cal.start,CONVERT_TZ(NOW(),'SYSTEM','UTC'))) as calltime, e.status as vs
|
||||
FROM extension as e
|
||||
LEFT JOIN `operator` as o ON (o.operator_id = e.current_operator_id)
|
||||
LEFT JOIN `case` as c ON (c.current_operator_id = o.operator_id)
|
||||
LEFT JOIN `call_attempt` as cal ON (cal.operator_id = o.operator_id AND cal.end IS NULL and cal.case_id = c.case_id)
|
||||
LEFT JOIN `call` as ca ON (ca.case_id = c.case_id AND ca.operator_id = o.operator_id AND ca.outcome_id= 0 AND ca.call_attempt_id = cal.call_attempt_id)
|
||||
WHERE o.voip = 1
|
||||
ORDER BY o.operator_id ASC";
|
||||
ORDER BY e.extension_id ASC";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
|
||||
if (!empty($rs))
|
||||
{
|
||||
xhtml_table($rs,array("extension","firstName","voip_status","case_id","state","calltime"),array(T_("Extension"),T_("Operator"),T_("VoIP Status"),T_("Case ID"),T_("Call state"),T_("Time on call")),"tclass",array("vs" => "1"));
|
||||
xhtml_table($rs,array("extension","firstName","firstName","status","case_id","state","calltime"),array(T_("Extension"),T_("Operator"),T_("Assignment"),T_("VoIP Status"),T_("Case ID"),T_("Call state"),T_("Time on call")),"tclass",array("vs" => "1"));
|
||||
}
|
||||
else
|
||||
print "<p>" . T_("No operators") . "</p>";
|
||||
|
||||
print "<p>" . T_("No extensions") . "</p>";
|
||||
|
||||
xhtml_foot();
|
||||
|
||||
?>
|
||||
|
||||
@@ -67,8 +67,6 @@ if (isset($_POST['submit']))
|
||||
firstName = " . $db->qstr($_POST['firstName']) . ",
|
||||
chat_user = " . $db->qstr($_POST['chat_user']) . ",
|
||||
chat_password = " . $db->qstr($_POST['chat_password']) . ",
|
||||
extension = " . $db->qstr($_POST['extension']) . ",
|
||||
extension_password = " . $db->qstr($_POST['extension_password']) . ",
|
||||
Time_zone_name = " . $db->qstr($_POST['timezone']) . ",
|
||||
voip = $voip, enabled = $enabled, chat_enable = $chat_enable
|
||||
WHERE operator_id = $operator_id";
|
||||
@@ -76,7 +74,21 @@ if (isset($_POST['submit']))
|
||||
$rs = $db->Execute($sql);
|
||||
|
||||
if (!empty($rs))
|
||||
{
|
||||
{
|
||||
$sql = "UPDATE extension
|
||||
SET current_operator_id = NULL
|
||||
WHERE current_operator_id= $operator_id";
|
||||
$db->Execute($sql);
|
||||
|
||||
if (!empty($_POST['extension_id']))
|
||||
{
|
||||
$sql = "UPDATE extension
|
||||
SET current_operator_id = $operator_id
|
||||
WHERE extension_id = " . intval($_POST['extension_id']);
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
if (HTPASSWD_PATH !== false && !empty($_POST['password']))
|
||||
{
|
||||
//update password in htaccess
|
||||
@@ -91,7 +103,7 @@ if (isset($_POST['submit']))
|
||||
}
|
||||
else
|
||||
{
|
||||
$msg = T_("Failed to update user. Please make sure the username and extension are unique");
|
||||
$msg = T_("Failed to update user. Please make sure the username is unique");
|
||||
}
|
||||
}
|
||||
$_GET['edit'] = $operator_id;
|
||||
@@ -119,6 +131,14 @@ if (isset($_GET['edit']))
|
||||
echo "<p><a href='?'>" . T_("Go back") . "</a></p>";
|
||||
if (!empty($msg)) print "<h3>$msg</h3>";
|
||||
|
||||
$sql = "SELECT extension_id as value, extension as description,
|
||||
CASE WHEN current_operator_id = $operator_id THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
FROM extension
|
||||
WHERE current_operator_id IS NULL
|
||||
OR current_operator_id = $operator_id";
|
||||
|
||||
$ers = $db->GetAll($sql);
|
||||
|
||||
?>
|
||||
<form action="?" method="post">
|
||||
<div><label for="username"><?php echo T_("Username") . ": "; ?></label><input type='text' name='username' value="<?php echo $rs['username'];?>"/></div>
|
||||
@@ -130,9 +150,8 @@ if (isset($_GET['edit']))
|
||||
?>
|
||||
<div><label for="firstName"><?php echo T_("First name") . ": "; ?></label><input type='text' name='firstName' value="<?php echo $rs['firstName'];?>"/></div>
|
||||
<div><label for="lastName"><?php echo T_("Last name") . ": "; ?></label><input type='text' name='lastName' value="<?php echo $rs['lastName'];?>"/></div>
|
||||
<div><label for="extension"><?php echo T_("Extension") . ": "; ?></label><input type='text' name='extension' value="<?php echo $rs['extension'];?>"/></div>
|
||||
<div><label for="extension_password"><?php echo T_("Extension Password") . ": "; ?></label><input type='text' name='extension_password' value="<?php echo $rs['extension_password'];?>"/></div>
|
||||
<div><label for="chat_user"><?php echo T_("Jabber/XMPP chat user") . ": "; ?></label><input type='text' name='chat_user' value="<?php echo $rs['chat_user'];?>"/></div>
|
||||
<div><label for="extension_id"><?php echo T_("Extension"); echo "</label>"; display_chooser($ers,"extension_id","extension_id",true,false,false,false); ?> </div>
|
||||
<div><label for="chat_user"><?php echo T_("Jabber/XMPP chat user") . ": "; ?></label><input type='text' name='chat_user' value="<?php echo $rs['chat_user'];?>"/></div>
|
||||
<div><label for="chat_password"><?php echo T_("Jabber/XMPP chat password") . ": "; ?></label><input type='text' name='chat_password' value="<?php echo $rs['chat_password'];?>"/></div>
|
||||
<div><label for="chat_enable"><?php echo T_("Uses chat") . "? ";?></label><input type="checkbox" name="chat_enable" <?php if ($rs['chat_enable'] == 1) echo "checked=\"checked\"";?> value="1" /></div>
|
||||
<div><label for="timezone"><?php echo T_("Timezone") . ": ";?></label><?php display_chooser($tz,"timezone","timezone",false,false,false,false,array("value",$rs['Time_zone_name'])); ?></div>
|
||||
@@ -200,9 +219,9 @@ if (isset($_GET['operator_id']))
|
||||
{
|
||||
$operator_id = intval($_GET['operator_id']);
|
||||
|
||||
$sql = "SELECT *,SUBSTRING_INDEX(extension, '/', -1) as ext
|
||||
FROM operator
|
||||
WHERE operator_id = $operator_id";
|
||||
$sql = "SELECT *,SUBSTRING_INDEX(e.extension, '/', -1) as ext
|
||||
FROM extension as e
|
||||
WHERE e.current_operator_id = $operator_id";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
|
||||
@@ -57,19 +57,12 @@ if (isset($_POST['operator']))
|
||||
$chat_user = $db->qstr($_POST['chat_user'],get_magic_quotes_gpc());
|
||||
$chat_password = $db->qstr($_POST['chat_password'],get_magic_quotes_gpc());
|
||||
$time_zone_name = $db->qstr($_POST['Time_zone_name'],get_magic_quotes_gpc());
|
||||
$extension = 1000;
|
||||
$extensionp = "";
|
||||
if (FREEPBX_PATH == false)
|
||||
{
|
||||
//Manually add extension information
|
||||
$extension = $db->qstr($_POST['extension'],get_magic_quotes_gpc());
|
||||
$extensionp = $db->qstr($_POST['extensionp'],get_magic_quotes_gpc());
|
||||
}
|
||||
else
|
||||
$extension = "";
|
||||
if (FREEPBX_PATH != false)
|
||||
{
|
||||
//Generate new extension from last one in database and random password
|
||||
$sql = "SELECT SUBSTRING_INDEX(extension, '/', -1) as ext
|
||||
FROM operator
|
||||
FROM extension
|
||||
ORDER BY ext DESC
|
||||
LIMIT 1";
|
||||
|
||||
@@ -110,17 +103,32 @@ if (isset($_POST['operator']))
|
||||
if (!empty($_POST['operator']))
|
||||
{
|
||||
$sql = "INSERT INTO operator
|
||||
(`operator_id` ,`username` ,`firstName` ,`lastName`, `extension`,`extension_password`, `Time_zone_name`,`voip`,`chat_enable`,`chat_user`,`chat_password`)
|
||||
VALUES (NULL , $operator, $firstname , $lastname, $extension, $extensionp, $time_zone_name, $voip, $chat, $chat_user, $chat_password);";
|
||||
(`operator_id` ,`username` ,`firstName` ,`lastName`, `Time_zone_name`,`voip`,`chat_enable`,`chat_user`,`chat_password`)
|
||||
VALUES (NULL , $operator, $firstname , $lastname, $time_zone_name, $voip, $chat, $chat_user, $chat_password);";
|
||||
|
||||
if ($db->Execute($sql))
|
||||
{
|
||||
{
|
||||
$oid = $db->Insert_ID();
|
||||
|
||||
if (FREEPBX_PATH !== false)
|
||||
{
|
||||
{
|
||||
//add extension
|
||||
$sql = "INSERT INTO extension (`extension`,`extension_password`,`current_operator_id`)
|
||||
VALUES ($extension, $extensionp, $oid)";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
//Generate new extension in freepbx
|
||||
include_once("../functions/functions.freepbx.php");
|
||||
freepbx_add_extension($extensionn, $_POST["firstname"] . " " . $_POST["lastname"], $extensionnp);
|
||||
}
|
||||
}
|
||||
else if (!empty($_POST['extension_id']))
|
||||
{
|
||||
$sql = "UPDATE extension
|
||||
SET current_operator_id = $oid
|
||||
WHERE extension_id = " . intval($_POST['extension_id']);
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
if (HTPASSWD_PATH !== false && HTGROUP_PATH !== false)
|
||||
{
|
||||
@@ -141,7 +149,6 @@ if (isset($_POST['operator']))
|
||||
if (FREEPBX_PATH !== false)
|
||||
$a .= "<br/>" . T_("FreePBX has been reloaded for the new VoIP extension to take effect");
|
||||
|
||||
$oid = $db->Insert_ID();
|
||||
|
||||
if ($temporary)
|
||||
{
|
||||
@@ -164,7 +171,7 @@ if (isset($_POST['operator']))
|
||||
}
|
||||
else
|
||||
{
|
||||
$a = T_("Could not add operator. There may already be an operator of this name:") . " $operator " . T_("Or there may already be an telephone extension number") . ":$extension" ;
|
||||
$a = T_("Could not add operator. There may already be an operator of this name:") . " $operator ";
|
||||
}
|
||||
|
||||
|
||||
@@ -186,6 +193,12 @@ $sql = "SELECT Time_zone_name as value, Time_zone_name as description
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
$sql = "SELECT extension_id as value, extension as description
|
||||
FROM extension
|
||||
WHERE current_operator_id IS NULL";
|
||||
|
||||
$ers = $db->GetAll($sql);
|
||||
|
||||
?>
|
||||
<h1><?php echo T_("Add an operator"); ?></h1>
|
||||
<p><?php echo T_("Adding an operator here will give the user the ability to call cases"); ?> <a href="operatorquestionnaire.php"><?php echo T_("Assign Operator to Questionnaire"); ?></a> <?php echo T_("tool"); ?>.</p>
|
||||
@@ -200,8 +213,7 @@ $rs = $db->GetAll($sql);
|
||||
<p><?php echo T_("Enter the surname of an operator to add:"); ?> <input name="lastname" type="text"/></p>
|
||||
<p><a href='timezonetemplate.php'><?php echo T_("Enter the Time Zone of an operator to add:"); echo "</a>"; display_chooser($rs,"Time_zone_name","Time_zone_name",false,false,false,false,array("value",DEFAULT_TIME_ZONE)); ?> </p>
|
||||
<?php if (FREEPBX_PATH == false) { ?>
|
||||
<p><?php echo T_("Enter the telephone extension number:"); ?> <input name="extension" type="text"/></p>
|
||||
<p><?php echo T_("Enter the telephone extension password:"); ?> <input name="extensionp" type="text"/></p>
|
||||
<p><a href='extensionstatus.php'><?php echo T_("Select an extension for this operator:"); echo "</a>"; display_chooser($ers,"extension_id","extension_id",true,false,false,false); ?> </p>
|
||||
<?php } ?>
|
||||
<p><?php echo T_("Will this operator be using VoIP?"); ?> <input name="voip" type="checkbox" checked="checked"/></p>
|
||||
<p><?php echo T_("Jabber/XMPP chat user"); ?>: <input name="chat_user" type="text"/></p>
|
||||
|
||||
@@ -130,13 +130,14 @@ function is_voip_enabled($operator_id)
|
||||
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT voip
|
||||
FROM operator
|
||||
WHERE operator_id = '$operator_id'";
|
||||
$sql = "SELECT o.voip
|
||||
FROM `operator` as o, `extension` as e
|
||||
WHERE o.operator_id = '$operator_id'
|
||||
AND e.current_operator_id = o.operator_id";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
if ($rs['voip'] == '1')
|
||||
if (isset($rs['voip']) && $rs['voip'] == '1')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -617,9 +618,10 @@ function get_case_id($operator_id, $create = false)
|
||||
$db->Execute("SET @row := 0");
|
||||
|
||||
$sql = "INSERT INTO contact_phone (case_id,priority,phone,description)
|
||||
SELECT $case_id as case_id,@row := @row + 1 AS priority,SUBSTRING_INDEX(extension,'/',-1) as phone, CONCAT(firstName, ' ', lastName)
|
||||
FROM operator
|
||||
WHERE enabled = 1";
|
||||
SELECT $case_id as case_id,@row := @row + 1 AS priority,SUBSTRING_INDEX(o.extension,'/',-1) as phone, CONCAT(o.firstName, ' ', o.lastName)
|
||||
FROM operator as o, `extension` as e
|
||||
WHERE o.enabled = 1
|
||||
AND e.current_operator_id = o.operator_id";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
@@ -796,9 +798,9 @@ function set_extension_status($operator_id,$online = true)
|
||||
|
||||
if ($online) $s = 1;
|
||||
|
||||
$sql = "UPDATE `operator`
|
||||
SET voip_status = '$s'
|
||||
WHERE operator_id = '$operator_id'";
|
||||
$sql = "UPDATE `extension`
|
||||
SET status = '$s'
|
||||
WHERE current_operator_id = '$operator_id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
@@ -814,12 +816,12 @@ function get_extension_status($operator_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.voip_status
|
||||
FROM `operator` as o
|
||||
WHERE o.operator_id = '$operator_id'";
|
||||
$sql = "SELECT e.status
|
||||
FROM `extension` as e
|
||||
WHERE e.current_operator_id = '$operator_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
if (!empty($rs) && $rs['voip_status'] == 1 ) return true;
|
||||
if (!empty($rs) && $rs['status'] == 1 ) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -834,9 +836,9 @@ function get_extension_password($operator_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.extension_password
|
||||
FROM `operator` as o
|
||||
WHERE o.operator_id = '$operator_id'";
|
||||
$sql = "SELECT e.extension_password
|
||||
FROM `extension` as e
|
||||
WHERE e.current_operator_id = '$operator_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
if (!empty($rs) && isset($rs['extension_password'])) return $rs['extension_password'];
|
||||
@@ -854,9 +856,9 @@ function get_extension($operator_id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT o.extension
|
||||
FROM `operator` as o
|
||||
WHERE o.operator_id = '$operator_id'";
|
||||
$sql = "SELECT e.extension
|
||||
FROM `extension` as e
|
||||
WHERE e.current_operator_id = '$operator_id'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
if (!empty($rs) && isset($rs['extension'])) return $rs['extension'];
|
||||
|
||||
@@ -417,15 +417,15 @@ class voipWatch extends voip {
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT l.call_id, c.case_id
|
||||
FROM operator AS o
|
||||
FROM `extension` AS e
|
||||
JOIN (`case` AS c, `call_attempt` AS ca, `call` AS l) ON
|
||||
( c.current_operator_id = o.operator_id
|
||||
( c.current_operator_id = e.current_operator_id
|
||||
AND c.case_id = ca.case_id
|
||||
AND ca.operator_id = o.operator_id
|
||||
AND ca.operator_id = e.current_operator_id
|
||||
AND ca.end IS NULL
|
||||
AND l.call_attempt_id = ca.call_attempt_id
|
||||
AND l.outcome_id =0 )
|
||||
WHERE o.extension = '$ext'";
|
||||
WHERE e.extension = '$ext'";
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
$call_id =0;
|
||||
@@ -448,8 +448,8 @@ class voipWatch extends voip {
|
||||
|
||||
if ($msg) print(T_("Extension") . " $ext " . ($online ? T_("online") : T_("offline")) . "\n");
|
||||
|
||||
$sql = "UPDATE operator
|
||||
SET voip_status = '$s'
|
||||
$sql = "UPDATE `extension`
|
||||
SET status = '$s'
|
||||
WHERE extension = '$ext'";
|
||||
|
||||
$db->Execute($sql);
|
||||
@@ -470,21 +470,19 @@ class voipWatch extends voip {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the extension status for all extensions
|
||||
* Update the extension status for all extensions
|
||||
*/
|
||||
function updateAllExtensionStatus()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = "SELECT extension,operator_id
|
||||
FROM operator
|
||||
WHERE voip = 1 AND enabled = 1";
|
||||
$sql = "SELECT e.extension
|
||||
FROM `extension` as e";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
foreach($rs as $r)
|
||||
{
|
||||
$o = $r['operator_id'];
|
||||
$e = $r['extension'];
|
||||
|
||||
$s = $this->getExtensionStatus($e);
|
||||
|
||||
Reference in New Issue
Block a user