* @copyright Deakin University 2007,2008 * @package queXS * @subpackage admin * @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 ("../config.inc.php"); /** * Database file */ include ("../db.inc.php"); /** * Authentication file */ require ("auth-admin.php"); /** * XHTML functions */ include ("../functions/functions.xhtml.php"); global $db; $a = false; if (isset($_POST['operator']) && isset($_POST['adduser'])) { $operator = $db->qstr($_POST['operator'],get_magic_quotes_gpc()); $email= $db->qstr($_POST['email'],get_magic_quotes_gpc()); $password = $db->qstr($_POST['password'],get_magic_quotes_gpc()); $firstname = $db->qstr($_POST['firstname'],get_magic_quotes_gpc()); $lastname = $db->qstr($_POST['lastname'],get_magic_quotes_gpc()); $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 = ""; if (FREEPBX_PATH != false) { //Generate new extension from last one in database and random password $sql = "SELECT SUBSTRING_INDEX(extension, '/', -1) as ext FROM extension ORDER BY ext DESC LIMIT 1"; $laste = $db->GetRow($sql); $extensionn = "1000"; $extension = "'IAX2/1000'"; //increment if exists if (!empty($laste)) { $extensionn = $laste['ext'] + 1; $extension = "'IAX2/$extensionn'"; } //generate random 8 length password $extensionnp = ""; $length = 25; $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; for ($i = 0; $i < $length; $i++) $extensionnp .= $chars[(mt_rand() % strlen($chars))]; //quote for SQL $extensionp = "'$extensionnp'"; } $admin = 0; $voip = 0; $chat = 0; if (isset($_POST['admin']) && $_POST['admin'] == "on") $admin = 1; if (isset($_POST['voip']) && $_POST['voip'] == "on") $voip = 1; if (isset($_POST['chat_enable']) && $_POST['chat_enable'] == "on") $chat = 1; if (!empty($_POST['operator'])) { $sql = "INSERT INTO operator (`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(); include_once("../include/limesurvey/admin/classes/core/sha256.php"); //Insert into lime_users $sql = "INSERT INTO " . LIME_PREFIX . "users (`users_name`,`password`,`full_name`,`parent_id`,`superadmin`,`create_survey`,`configurator`,`manage_template`,`manage_label`,`email`,`lang`) VALUES ($operator, '" . SHA256::hashing($_POST['password']) . "',$firstname,1,$admin,$admin,$admin,$admin,$admin,$email,'auto')"; $db->Execute($sql); if (FREEPBX_PATH !== false) { //add extension $sql = "INSERT INTO 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); } $a = "

" . T_("Added operator :") . " " . $operator . "

"; if (FREEPBX_PATH !== false) $a .= "
" . T_("FreePBX needs to be reloaded for the new VoIP extension to take effect") . ""; $a .= "
"; // set default skills = 1 and 5 for all new operators $db->Execute(" INSERT INTO operator_skill (operator_id,outcome_type_id) VALUES ('$oid','1')"); $db->Execute(" INSERT INTO operator_skill (operator_id,outcome_type_id) VALUES ('$oid','5')"); //and appointment } else { $a = T_("Could not add operator. There may already be an operator of this name:") . " $operator "; } } } xhtml_head(T_("Add an operator"),true,array("../include/bootstrap/css/bootstrap.min.css","../include/bootstrap-toggle/css/bootstrap-toggle.min.css", "../css/custom.css"), array("../include/jquery/jquery.min.js", "../include/bootstrap/js/bootstrap.min.js","../include/bootstrap-toggle/js/bootstrap-toggle.min.js")); if ($a) { echo $a; } else { echo "
"; //echo "

" . T_("Adding an operator here will give the user the ability to call cases") . "" . T_("Assign Operator to Questionnaire") . "" . T_("tool") . ".

"; //echo "

" . T_("Use this form to enter the username of a user based on your directory security system. For example, if you have secured the base directory of queXS using Apache file based security, enter the usernames of the users here.") . "

"; echo "

" . T_("The username and extension must be unique for each operator.") . "

"; echo "
"; } $sql = "SELECT Time_zone_name as value, Time_zone_name as description FROM timezone_template"; $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); ?>
" class="btn btn-default fa" /> 
" data-off="" />
" data-off="" />
" data-off="" data-onstyle="danger"/>

" />