mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Merged Separate extensions from operators and allow reassigning and selection of extensions feature
This commit is contained in:
@@ -43,26 +43,177 @@ include ("../db.inc.php");
|
||||
*/
|
||||
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 '" . TQ_("VoIP Offline") . "' ELSE '" . TQ_("VoIP Online") . "' END as voip_status, CASE ca.state WHEN 0 THEN '" . TQ_("Not called") . "' WHEN 1 THEN '" . TQ_("Requesting call") . "' WHEN 2 THEN '" . TQ_("Ringing") . "' WHEN 3 THEN '" . TQ_("Answered") . "' WHEN 4 THEN '" . TQ_("Requires coding") . "' ELSE '" . TQ_("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
|
||||
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";
|
||||
$msg = "";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
|
||||
if (!empty($rs))
|
||||
if (isset($_GET))
|
||||
{
|
||||
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"));
|
||||
foreach($_GET as $key=>$val)
|
||||
{
|
||||
if (substr($key,0,12) == "operator_id_")
|
||||
{
|
||||
if (isset($_GET['extension_id']))
|
||||
{
|
||||
$ex = intval($_GET['extension_id']);
|
||||
$op = intval($val);
|
||||
|
||||
$sql = "UPDATE `extension`
|
||||
SET current_operator_id = $op
|
||||
WHERE extension_id = $ex
|
||||
AND current_operator_id IS NULL";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['extension']))
|
||||
{
|
||||
$extension = $db->qstr($_POST['extension']);
|
||||
$password = $db->qstr($_POST['password']);
|
||||
$extension_id = "NULL";
|
||||
|
||||
if (isset($_POST['extensionid']))
|
||||
$extension_id = intval($_POST['extensionid']);
|
||||
|
||||
if (isset($_POST['delete']))
|
||||
{
|
||||
$sql = "DELETE FROM `extension`
|
||||
WHERE current_operator_id IS NULL
|
||||
AND extension_id = $extension_id";
|
||||
|
||||
$rs = $db->Execute($sql);
|
||||
|
||||
if (!$rs)
|
||||
$msg = ("Failed to delete extension. There may be an operator currently assigned to it");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!empty($_POST['extension']))
|
||||
{
|
||||
$sql = "INSERT INTO `extension` (extension_id,extension,password)
|
||||
VALUES ($extension_id,$extension,$password)
|
||||
ON DUPLICATE KEY UPDATE extension=$extension,password=$password";
|
||||
|
||||
$rs = $db->Execute($sql);
|
||||
|
||||
if (!$rs)
|
||||
$msg = T_("Failed to add extension. There already may be an extension of this name");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['unassign']))
|
||||
{
|
||||
$e = intval($_GET['unassign']);
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
$sql = "SELECT e.current_operator_id
|
||||
FROM `extension` as e
|
||||
LEFT JOIN `case` as c ON (c.current_operator_id = e.current_operator_id)
|
||||
WHERE e.extension_id = $e
|
||||
AND c.case_id IS NULL";
|
||||
|
||||
$cid = $db->GetOne($sql);
|
||||
|
||||
if (!empty($cid))
|
||||
{
|
||||
$sql = "UPDATE `extension` as e
|
||||
SET current_operator_id = NULL
|
||||
WHERE extension_id = $e
|
||||
AND current_operator_id = $cid";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
xhtml_head(T_("Display extension status"),true,array("../css/table.css"),array("../js/window.js"));
|
||||
|
||||
if (isset($_GET['edit']))
|
||||
{
|
||||
$sql = "SELECT extension,password,current_operator_id
|
||||
FROM extension
|
||||
WHERE extension_id = " . intval($_GET['edit']);
|
||||
|
||||
$rs = $db->GetRow($sql);
|
||||
|
||||
print "<p><a href='?'>" . T_("Go back") . "</a></p>";
|
||||
?>
|
||||
<form enctype="multipart/form-data" action="?" method="post">
|
||||
<p><?php echo T_("Extension name (such as SIP/1000):"); ?> <input name="extension" type="text" value="<?php echo $rs['extension'];?>"/></p>
|
||||
<p><?php echo T_("Extension password:"); ?> <input name="password" type="text" value="<?php echo $rs['password'];?>"/></p>
|
||||
<input name="extensionid" type="hidden" value="<?php echo intval($_GET['edit']);?>"/></p>
|
||||
<p><input type="submit" value="<?php echo T_("Edit extension"); ?>" /></p>
|
||||
<?php
|
||||
if (empty($rs['current_operator_id']))
|
||||
{
|
||||
?>
|
||||
<br/>
|
||||
<p><input type="submit" name="delete" value="<?php echo T_("Delete extension"); ?>" /></p>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
print "<p>" . T_("Unassign the operator from this extension to be able to delete it") . "</p>";
|
||||
|
||||
}
|
||||
else
|
||||
print "<p>" . T_("No operators") . "</p>";
|
||||
|
||||
{
|
||||
$sql= "SELECT CONCAT('<a href=\'operatorlist.php?edit=',o.operator_id,'\'>',o.firstName,'</a>') as firstName,
|
||||
CONCAT('<a href=\'?edit=',e.extension_id,'\'>',e.extension,'</a>') as extension,
|
||||
IF(c.case_id IS NULL,IF(e.current_operator_id IS NULL,'list'
|
||||
,CONCAT('<a href=\'?unassign=',e.extension_id,'\'>". TQ_("Unassign") ."</a>')),'". TQ_("End case to change assignment")."') as assignment,
|
||||
CASE e.status WHEN 0 THEN '" . TQ_("VoIP Offline") . "' ELSE '" . TQ_("VoIP Online") . "' END as status,
|
||||
CASE ca.state WHEN 0 THEN '" . TQ_("Not called") . "' WHEN 1 THEN '" . TQ_("Requesting call") . "' WHEN 2 THEN '" . TQ_("Ringing") . "' WHEN 3 THEN '" . TQ_("Answered") . "' WHEN 4 THEN '" . TQ_("Requires coding") . "' ELSE '" . TQ_("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,
|
||||
e.extension_id
|
||||
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)
|
||||
ORDER BY e.extension_id ASC";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
if ($msg != "")
|
||||
print "<p>$msg</p>";
|
||||
|
||||
if (!empty($rs))
|
||||
{
|
||||
$sql = "SELECT o.operator_id as value, o.firstName as description
|
||||
FROM `operator` as o
|
||||
LEFT JOIN `extension` as e ON (e.current_operator_id = o.operator_id)
|
||||
WHERE e.extension_id IS NULL";
|
||||
|
||||
$ers = $db->GetAll($sql);
|
||||
|
||||
for ($i = 0; $i < count($rs); $i++)
|
||||
{
|
||||
if ($rs[$i]['assignment'] == "list")
|
||||
$rs[$i]['assignment'] = display_chooser($ers,"operator_id_" . $rs[$i]["extension_id"],"operator_id_" . $rs[$i]["extension_id"],true,"extension_id=".$rs[$i]["extension_id"],true,false,false,false);
|
||||
}
|
||||
xhtml_table($rs,array("extension","firstName","assignment","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 extensions") . "</p>";
|
||||
|
||||
print "<h2>" . T_("Add an extension") . "</h2>";
|
||||
?>
|
||||
|
||||
<form enctype="multipart/form-data" action="" method="post">
|
||||
<p><?php echo T_("Extension name (such as SIP/1000):"); ?> <input name="extension" type="text"/></p>
|
||||
<p><?php echo T_("Extension password:"); ?> <input name="password" type="text"/></p>
|
||||
<p><input type="submit" value="<?php echo T_("Add extension"); ?>" /></p>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
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,32 @@ if (isset($_POST['submit']))
|
||||
$rs = $db->Execute($sql);
|
||||
|
||||
if (!empty($rs))
|
||||
{
|
||||
{
|
||||
//only update extension if we aren't on a case
|
||||
$sql = "SELECT case_id
|
||||
FROM `case`
|
||||
WHERE current_operator_id = $operator_id";
|
||||
|
||||
$cc= $db->GetOne($sql);
|
||||
|
||||
if (empty($cc))
|
||||
{
|
||||
$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 +114,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 +142,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 +161,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 +230,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);
|
||||
|
||||
@@ -232,7 +262,8 @@ if (isset($_GET['operator_id']))
|
||||
if ($display)
|
||||
{
|
||||
$sql = "SELECT
|
||||
CONCAT(firstName, ' ', lastName) as name,
|
||||
CONCAT(firstName, ' ', lastName) as name,
|
||||
e.extension,
|
||||
CONCAT('<a href=\'?winbat=winbat&operator_id=',operator_id,'\'>" . TQ_("Windows bat file") . "</a>') as winbat,
|
||||
CONCAT('<a href=\'?sh=sh&operator_id=',operator_id,'\'>" . TQ_("*nix script file") . "</a>') as sh,
|
||||
CASE WHEN enabled = 0 THEN
|
||||
@@ -248,14 +279,15 @@ if ($display)
|
||||
END as voipenabledisable,
|
||||
CONCAT('<a href=\'?edit=',operator_id,'\'>" . TQ_("Edit") . "</a>') as edit,
|
||||
username
|
||||
FROM operator";
|
||||
FROM operator
|
||||
LEFT JOIN `extension` as e ON (e.current_operator_id = operator_id)";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
xhtml_head(T_("Operator list"),true,array("../css/table.css"));
|
||||
|
||||
$columns = array("name","username","enabledisable","edit");
|
||||
$titles = array(T_("Operator"),T_("Username"),T_("Enable/Disable"),T_("Edit"));
|
||||
$columns = array("name","username","extension","enabledisable","edit");
|
||||
$titles = array(T_("Operator"),T_("Username"),T_("Extension"),T_("Enable/Disable"),T_("Edit"));
|
||||
|
||||
if (VOIP_ENABLED)
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user