From 5d87591ecd920369fa2eea3c70107beb0ec85add Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Fri, 22 Nov 2013 14:54:21 +1100 Subject: [PATCH 1/9] Updated database for separate extension to operator --- CHANGELOG | 24 ++++++++++++++++++++++++ database/quexs.sql | 21 +++++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d6479f19..b195329e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,27 @@ +New Feature: Operators can choose extension + +ALTER TABLE `operator` CHANGE `extension` `extension` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL; + +CREATE TABLE IF NOT EXISTS `extension` ( + `extension_id` int(11) NOT NULL AUTO_INCREMENT, + `extension` char(10) COLLATE utf8_unicode_ci NOT NULL, + `password` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `status` tinyint(1) NOT NULL DEFAULT '0', + `current_operator_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`extension_id`), + UNIQUE KEY `extension` (`extension`), + UNIQUE KEY `current_operator_id` (`current_operator_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; + +INSERT INTO `extension` (extension,password,current_operator_id,status) +SELECT extension,extension_password,operator_id,voip_status +FROM operator; + + ALTER TABLE `operator` + DROP `extension`, + DROP `extension_password`, + DROP `voip_status`; + queXS 1.9.1 - Changes since 1.9.0 New Feature: Add caseid to SPSS output diff --git a/database/quexs.sql b/database/quexs.sql index 851ad231..d5962156 100644 --- a/database/quexs.sql +++ b/database/quexs.sql @@ -391,6 +391,23 @@ INSERT INTO `day_of_week` (`day_of_week`) VALUES(7); -- -------------------------------------------------------- +-- +-- Table structure for table `extension` +-- + +CREATE TABLE IF NOT EXISTS `extension` ( + `extension_id` int(11) NOT NULL AUTO_INCREMENT, + `extension` char(10) COLLATE utf8_unicode_ci NOT NULL, + `password` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `status` tinyint(1) NOT NULL DEFAULT '0', + `current_operator_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`extension_id`), + UNIQUE KEY `extension` (`extension`), + UNIQUE KEY `current_operator_id` (`current_operator_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; + +-- -------------------------------------------------------- + -- -- Table structure for table `lime_answers` -- @@ -1170,19 +1187,15 @@ CREATE TABLE `operator` ( `username` varchar(255) collate utf8_unicode_ci NOT NULL, `firstName` varchar(255) collate utf8_unicode_ci NOT NULL, `lastName` varchar(255) collate utf8_unicode_ci NOT NULL, - `extension` varchar(10) collate utf8_unicode_ci NOT NULL, - `extension_password` varchar(255) collate utf8_unicode_ci default NULL, `Time_zone_name` char(64) collate utf8_unicode_ci NOT NULL, `enabled` tinyint(1) NOT NULL default '1', `voip` tinyint(1) NOT NULL default '1', - `voip_status` tinyint(1) NOT NULL default '0', `next_case_id` bigint(20) default NULL, `chat_enable` tinyint(1) default '0', `chat_user` varchar(255) collate utf8_unicode_ci default NULL, `chat_password` varchar(255) collate utf8_unicode_ci default NULL, PRIMARY KEY (`operator_id`), UNIQUE KEY `username` (`username`), - UNIQUE KEY `extension` (`extension`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- From e907af9f5f9cdd3318ca0a79a9ac590454c0ab76 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Fri, 22 Nov 2013 16:04:22 +1100 Subject: [PATCH 2/9] Convert use of operator table for extensions to extension table --- admin/extensionstatus.php | 14 ++++----- admin/operatorlist.php | 39 ++++++++++++++++++------- admin/operators.php | 50 ++++++++++++++++++++------------ functions/functions.operator.php | 42 ++++++++++++++------------- functions/functions.voip.php | 20 ++++++------- 5 files changed, 98 insertions(+), 67 deletions(-) diff --git a/admin/extensionstatus.php b/admin/extensionstatus.php index d0c7a297..ba2800ea 100644 --- a/admin/extensionstatus.php +++ b/admin/extensionstatus.php @@ -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('' , c.case_id, '') 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('',o.firstName,'') 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('' , c.case_id, '') 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 "

" . T_("No operators") . "

"; - + print "

" . T_("No extensions") . "

"; + xhtml_foot(); ?> diff --git a/admin/operatorlist.php b/admin/operatorlist.php index 8b3c195d..7468b311 100644 --- a/admin/operatorlist.php +++ b/admin/operatorlist.php @@ -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 "

" . T_("Go back") . "

"; if (!empty($msg)) print "

$msg

"; + $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); + ?>
@@ -130,9 +150,8 @@ if (isset($_GET['edit'])) ?>
-
-
-
+
+
value="1" />
@@ -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); diff --git a/admin/operators.php b/admin/operators.php index 40c35d0f..e14bfd96 100644 --- a/admin/operators.php +++ b/admin/operators.php @@ -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 .= "
" . 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); + ?>

.

@@ -200,8 +213,7 @@ $rs = $db->GetAll($sql);

"; display_chooser($rs,"Time_zone_name","Time_zone_name",false,false,false,false,array("value",DEFAULT_TIME_ZONE)); ?>

-

-

+

"; display_chooser($ers,"extension_id","extension_id",true,false,false,false); ?>

:

diff --git a/functions/functions.operator.php b/functions/functions.operator.php index b3448b8d..88b5cdb9 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -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']; diff --git a/functions/functions.voip.php b/functions/functions.voip.php index 029574c6..511cd0a5 100644 --- a/functions/functions.voip.php +++ b/functions/functions.voip.php @@ -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); From d5f4ce65b31e91ac455a9ad63d249bbde7e1b8c0 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Mon, 25 Nov 2013 14:18:44 +1100 Subject: [PATCH 3/9] Add extension to operator list --- admin/operatorlist.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/admin/operatorlist.php b/admin/operatorlist.php index 7468b311..d337dedf 100644 --- a/admin/operatorlist.php +++ b/admin/operatorlist.php @@ -251,7 +251,8 @@ if (isset($_GET['operator_id'])) if ($display) { $sql = "SELECT - CONCAT(firstName, ' ', lastName) as name, + CONCAT(firstName, ' ', lastName) as name, + e.extension, CONCAT('
" . T_("Windows bat file") . "') as winbat, CONCAT('" . T_("*nix script file") . "') as sh, CASE WHEN enabled = 0 THEN @@ -267,14 +268,15 @@ if ($display) END as voipenabledisable, CONCAT('" . T_("Edit") . "') 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) { From 70b594853d7895bf9b8f58046183fb1ef7372b0f Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Mon, 25 Nov 2013 16:16:53 +1100 Subject: [PATCH 4/9] Allowed for returning as a string instead of printing chooser --- functions/functions.xhtml.php | 42 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/functions/functions.xhtml.php b/functions/functions.xhtml.php index 77fbffb0..cf647f3a 100644 --- a/functions/functions.xhtml.php +++ b/functions/functions.xhtml.php @@ -161,48 +161,54 @@ function xhtml_table($content,$fields,$head = false,$class = "tclass",$highlight * @param bool $js Whether to use JS or not * @param bool $indiv Whether to display in a div or not * @param array|bool $select The element to select manually (element,string) (not using selected=\'selected\' in array) + * @param bool $print Default is true, print the chooser otherwise return as a string * */ -function display_chooser($elements, $selectid, $var, $useblank = true, $pass = false, $js = true, $indiv = true, $selected = false) +function display_chooser($elements, $selectid, $var, $useblank = true, $pass = false, $js = true, $indiv = true, $selected = false, $print = true) { - if ($indiv) print "
"; - print ""; + $out .= $pass; + $out .= "'>"; } foreach($elements as $e) { if ($js) { - print ""; + $out .= ">".strip_tags($e['description']).""; } - print ""; - if ($indiv) print "
"; + $out .= ""; + if ($indiv) $out .= ""; + if ($print) + print $out; + else + return $out; } function xhtml_object($data, $id, $class="embeddedobject") From 7de149df5d35487b48e211fd9fa5b09803908fe8 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Mon, 25 Nov 2013 16:17:33 +1100 Subject: [PATCH 5/9] Allow for adding and assigning/unassigning of extensions --- admin/extensionstatus.php | 181 ++++++++++++++++++++++++++++++++++---- 1 file changed, 166 insertions(+), 15 deletions(-) diff --git a/admin/extensionstatus.php b/admin/extensionstatus.php index ba2800ea..38a2b09e 100644 --- a/admin/extensionstatus.php +++ b/admin/extensionstatus.php @@ -43,25 +43,176 @@ include ("../db.inc.php"); */ include ("../functions/functions.xhtml.php"); -xhtml_head(T_("Display extension status"),true,array("../css/table.css")); - -$sql= "SELECT CONCAT('',o.firstName,'') 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('' , c.case_id, '') 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) - ORDER BY e.extension_id ASC"; +$msg = ""; -$rs = $db->GetAll($sql); - - -if (!empty($rs)) +if (isset($_GET)) { - 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")); + 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 "

" . T_("Go back") . "

"; +?> + +

+

+

+

" />

+ +
+

" />

+ +" . T_("Unassign the operator from this extension to be able to delete it") . "

"; + } else - print "

" . T_("No extensions") . "

"; +{ + $sql= "SELECT CONCAT('',o.firstName,'') as firstName, + CONCAT('',e.extension,'') as extension, + IF(c.case_id IS NULL,IF(e.current_operator_id IS NULL,'list' + ,CONCAT('". T_("Unassign") ."')),'". T_("End case to change assignment")."') as assignment, + 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('' , c.case_id, '') 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 "

$msg

"; + + 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 "

" . T_("No extensions") . "

"; + + print "

" . T_("Add an extension") . "

"; + ?> + +
+

+

+

" />

+
+ + Date: Mon, 25 Nov 2013 16:31:08 +1100 Subject: [PATCH 6/9] Only allow extension changes when not on a case --- admin/operatorlist.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/admin/operatorlist.php b/admin/operatorlist.php index d337dedf..b74ad0c7 100644 --- a/admin/operatorlist.php +++ b/admin/operatorlist.php @@ -75,18 +75,29 @@ if (isset($_POST['submit'])) if (!empty($rs)) { - $sql = "UPDATE extension - SET current_operator_id = NULL - WHERE current_operator_id= $operator_id"; - $db->Execute($sql); + //only update extension if we aren't on a case + $sql = "SELECT case_id + FROM `case` + WHERE current_operator_id = $operator_id"; - if (!empty($_POST['extension_id'])) + $cc= $db->GetOne($sql); + + if (empty($cc)) { $sql = "UPDATE extension - SET current_operator_id = $operator_id - WHERE extension_id = " . intval($_POST['extension_id']); + 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'])) From 5d812fa968ed8ac6518fd20c14075d5e68277087 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Tue, 26 Nov 2013 11:49:06 +1100 Subject: [PATCH 7/9] Added extension to status screen --- status.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/status.php b/status.php index 08246e19..30781bc7 100644 --- a/status.php +++ b/status.php @@ -84,7 +84,7 @@ print "
" . get_operator_time($operator_id,DATE_TIME_FORMAT) ." if (is_voip_enabled($operator_id)) { - $ext = get_extension($operator_id); + $ext = get_extension($operator_id); $exta = $ext; //Get just the start of the extension for auto dial out $exts = explode('/', $ext, 2); @@ -94,7 +94,9 @@ if (is_voip_enabled($operator_id)) if (get_extension_status($operator_id)) print "
" . T_("VoIP On") . "
"; else - print ""; + print ""; + + print "
" . T_("Extension") . ": $ext
"; } else print "
" . T_("No VoIP") . "
"; From 6d81384378586b31f2001cf486c9105266076392 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Tue, 26 Nov 2013 11:49:38 +1100 Subject: [PATCH 8/9] Added featue for allowing operators to choose their own extension if not assigned one already --- config.default.php | 5 ++ endwork.php | 21 ++++++++ index.php | 15 ++++++ selectextension.php | 114 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 selectextension.php diff --git a/config.default.php b/config.default.php index 38a9c5a7..c6f0166b 100644 --- a/config.default.php +++ b/config.default.php @@ -69,6 +69,11 @@ if (!defined('TIME_FORMAT')) define('TIME_FORMAT','%I:%i%p'); */ if (!defined('VOIP_ENABLED')) define('VOIP_ENABLED',false); +/** + * Allow operators to choose their extension? + */ +if (!defined('ALLOW_OPERATOR_EXTENSION_SELECT')) define('ALLOW_OPERATOR_EXTENSION_SELECT',false); + /** * The Asterisk server address */ diff --git a/endwork.php b/endwork.php index 59ab7f20..47145bb6 100644 --- a/endwork.php +++ b/endwork.php @@ -51,6 +51,27 @@ if (isset($_GET['auto'])) print "

" . T_("Work has ended. That is it") . "

"; +if (ALLOW_OPERATOR_EXTENSION_SELECT && VOIP_ENABLED) +{ + //unassign extension + include_once("functions/functions.operator.php"); + $operator_id = get_operator_id(); + + if (get_case_id($operator_id) == false && is_voip_enabled($operator_id)) + { + $sql = "UPDATE `extension` + SET current_operator_id = NULL + WHERE current_operator_id = $operator_id"; + + $rs = $db->Execute($sql); + + if ($rs) + { + print "

" . T_("You have been unassigned from your extension") ."

"; + } + } +} + print "

" . T_("Go back to work") . "

"; xhtml_foot(); diff --git a/index.php b/index.php index 2eaf544b..0f488633 100644 --- a/index.php +++ b/index.php @@ -52,6 +52,21 @@ if (ALTERNATE_INTERFACE && !is_voip_enabled($operator_id)) include_once("waitnextcase_interface2.php"); die(); } +else if (ALLOW_OPERATOR_EXTENSION_SELECT && VOIP_ENABLED) +{ + $sql = "SELECT o.voip,e.extension_id + FROM `operator` as o + LEFT JOIN `extension` as e ON (e.current_operator_id = o.operator_id) + WHERE o.operator_id = $operator_id"; + + $ve = $db->GetRow($sql); + + if ($ve['voip'] == 1 && empty($ve['extension_id'])) + { + include_once("selectextension.php"); + die(); + } +} $db->StartTrans(); diff --git a/selectextension.php b/selectextension.php new file mode 100644 index 00000000..42487bbb --- /dev/null +++ b/selectextension.php @@ -0,0 +1,114 @@ + + * @copyright Deakin University 2007,2008 + * @package queXS + * @subpackage user + * @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility + * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2 + * + * + */ + +/** + * Configuration file + */ +include_once("config.inc.php"); + +/** + * XHTML functions + */ +include_once("functions/functions.xhtml.php"); + +/** + * Operator functions + */ +include_once("functions/functions.operator.php"); + +$operator_id = get_operator_id(); + +if (!$operator_id) + die(); + +//if already assigned just get straight to it +$sql = "SELECT extension + FROM `extension` + WHERE current_operator_id = '$operator_id'"; + +$e = $db->GetOne($sql); + +if (!empty($e)) +{ + header('Location: index.php'); + die(); +} + +if (isset($_POST['extension_id']) && !empty($_POST['extension_id'])) +{ + if ($operator_id) + { + $e = intval($_POST['extension_id']); + + $sql = "UPDATE `extension` + SET current_operator_id = $operator_id + WHERE current_operator_id IS NULL + AND extension_id = $e"; + + $r = $db->Execute($sql); + + if ($r) + { + header('Location: index.php'); + die(); + } + } +} + + +xhtml_head(T_("queXS")); + + +$sql = "SELECT e.extension_id as value, e.extension as description + FROM `extension` as e + WHERE e.current_operator_id IS NULL"; + +$ers = $db->GetAll($sql); + +if (empty($ers)) +{ + print "

" . T_("There are no extensions available, please contact the supervisor or click below to try again for an available extension") . "

"; + print "

" . T_("Try again") . "

"; +} +else +{ + print "

" . T_("Select extension") . "

"; + print "

" . T_("Please select your extension from the list below then click on 'Choose extension'") . "

"; + + print "
"; + print ""; + display_chooser($ers,"extension_id","extension_id",false,false,false,false); + print "

"; +} +xhtml_foot(); + +?> From dedf58992ea0b25c76ef3ed0247f755f65483bf5 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Tue, 26 Nov 2013 12:08:38 +1100 Subject: [PATCH 9/9] Removed unnecessary SQL statement --- CHANGELOG | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b195329e..28a1193a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,5 @@ New Feature: Operators can choose extension -ALTER TABLE `operator` CHANGE `extension` `extension` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL; - CREATE TABLE IF NOT EXISTS `extension` ( `extension_id` int(11) NOT NULL AUTO_INCREMENT, `extension` char(10) COLLATE utf8_unicode_ci NOT NULL,