Copyright (C) 2008-2019 All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('extension_add') || permission_exists('extension_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //set the action as an add or an update if (is_uuid($_REQUEST["id"])) { $action = "update"; $extension_uuid = $_REQUEST["id"]; $page = $_REQUEST['page']; } else { $action = "add"; } //get total extension count from the database, check limit, if defined if ($action == 'add') { if ($_SESSION['limit']['extensions']['numeric'] != '') { $sql = "select count(*) "; $sql .= "from v_extensions "; $sql .= "where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $database = new database; $total_extensions = $database->select($sql, $parameters, 'column'); unset($sql, $parameters); if ($total_extensions >= $_SESSION['limit']['extensions']['numeric']) { message::add($text['message-maximum_extensions'].' '.$_SESSION['limit']['extensions']['numeric'], 'negative'); header('Location: extensions.php'.(is_numeric($page) ? '?page='.$page : null)); exit; } } } //get the http values and set them as php variables if (count($_POST) > 0) { //get the values from the HTTP POST and save them as PHP variables $extension = str_replace(' ','-',$_POST["extension"]); $number_alias = $_POST["number_alias"]; $password = $_POST["password"]; // server verification on account code $accountcode = $_POST["accountcode"]; $effective_caller_id_name = $_POST["effective_caller_id_name"]; $effective_caller_id_number = $_POST["effective_caller_id_number"]; $outbound_caller_id_name = $_POST["outbound_caller_id_name"]; $outbound_caller_id_number = $_POST["outbound_caller_id_number"]; $emergency_caller_id_name = $_POST["emergency_caller_id_name"]; $emergency_caller_id_number = $_POST["emergency_caller_id_number"]; $directory_first_name = $_POST["directory_first_name"]; $directory_last_name = $_POST["directory_last_name"]; $directory_visible = $_POST["directory_visible"]; $directory_exten_visible = $_POST["directory_exten_visible"]; $limit_max = $_POST["limit_max"]; $limit_destination = $_POST["limit_destination"]; $device_uuid = $_POST["device_uuid"]; $device_line = $_POST["device_line"]; $voicemail_password = $_POST["voicemail_password"]; $voicemail_enabled = $_POST["voicemail_enabled"]; $voicemail_mail_to = $_POST["voicemail_mail_to"]; $voicemail_file = $_POST["voicemail_file"]; $voicemail_local_after_email = $_POST["voicemail_local_after_email"]; $user_context = $_POST["user_context"]; $range = $_POST["range"]; $autogen_users = $_POST["autogen_users"]; $missed_call_app = $_POST["missed_call_app"]; $missed_call_data = $_POST["missed_call_data"]; $toll_allow = $_POST["toll_allow"]; $call_timeout = $_POST["call_timeout"]; $call_group = $_POST["call_group"]; $call_screen_enabled = $_POST["call_screen_enabled"]; $user_record = $_POST["user_record"]; $hold_music = $_POST["hold_music"]; $auth_acl = $_POST["auth_acl"]; $cidr = $_POST["cidr"]; $sip_force_contact = $_POST["sip_force_contact"]; $sip_force_expires = $_POST["sip_force_expires"]; $nibble_account = $_POST["nibble_account"]; $mwi_account = $_POST["mwi_account"]; $sip_bypass_media = $_POST["sip_bypass_media"]; $absolute_codec_string = $_POST["absolute_codec_string"]; $force_ping = $_POST["force_ping"]; $dial_string = $_POST["dial_string"]; $enabled = $_POST["enabled"]; $description = $_POST["description"]; $voicemail_id = $extension; if (permission_exists('number_alias') && strlen($number_alias) > 0) { $voicemail_id = $number_alias; } if (!is_numeric($voicemail_id)) { $voicemail_id = null; } //change toll allow delimiter $toll_allow = str_replace(',',':', $toll_allow); } //delete the user from the v_extension_users if ($_REQUEST["delete_type"] == "user" && is_uuid($_REQUEST["delete_uuid"]) && permission_exists("extension_delete")) { //set the variables $extension_uuid = $_REQUEST["id"]; $user_uuid = $_REQUEST["delete_uuid"]; //delete the group from the users $array['extension_users'][0]['extension_uuid'] = $extension_uuid; $array['extension_users'][0]['user_uuid'] = $user_uuid; $p = new permissions; $p->add('extension_user_delete', 'temp'); $database = new database; $database->app_name = 'extensions'; $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; $database->delete($array); unset($array); $p->delete('extension_user_delete', 'temp'); } //delete the line from the v_device_lines if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/devices')) { if ($_REQUEST["delete_type"] == "device_line" && is_uuid($_REQUEST["delete_uuid"]) && permission_exists("extension_delete")) { //set the variables $device_line_uuid = $_REQUEST["delete_uuid"]; //delete device_line $array['device_lines'][0]['device_line_uuid'] = $device_line_uuid; $p = new permissions; $p->add('device_line_delete', 'temp'); $database = new database; $database->app_name = 'extensions'; $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; $database->delete($array); unset($array); $p->delete('device_line_delete', 'temp'); } } //process the user data and save it to the database if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //set the domain_uuid $domain_uuid = permission_exists('extension_domain') ? $_POST["domain_uuid"] : $_SESSION['domain_uuid']; //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: extensions.php'); exit; } //check for all required data $msg = ''; if (strlen($extension) == 0) { $msg .= $text['message-required'].$text['label-extension']."
\n"; } if (permission_exists('extension_enabled')) { if (strlen($enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."
\n"; } } //if (strlen($description) == 0) { $msg .= $text['message-required']."Description
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //set the default user context if (permission_exists("extension_user_context")) { //allow a user assigned to super admin to change the user_context } else { //if the user_context was not set then set the default value $user_context = $_SESSION['domain_name']; } //prevent users from bypassing extension limit by using range if ($_SESSION['limit']['extensions']['numeric'] != '') { if ($total_extensions + $range > $_SESSION['limit']['extensions']['numeric']){ $range = $_SESSION['limit']['extensions']['numeric'] - $total_extensions; } } //add or update the database if ($_POST["persistformvar"] != "true") { //prep missed call values for db insert/update switch ($missed_call_app) { case 'email': $missed_call_data = str_replace(';',',',$missed_call_data); $missed_call_data = str_replace(' ','',$missed_call_data); if (substr_count($missed_call_data, ',') > 0) { $missed_call_data_array = explode(',', $missed_call_data); foreach ($missed_call_data_array as $array_index => $email_address) { if (!valid_email($email_address)) { unset($missed_call_data_array[$array_index]); } } //echo "
".print_r($missed_call_data_array, true)."


"; if (sizeof($missed_call_data_array) > 0) { $missed_call_data = implode(',', $missed_call_data_array); } else { unset($missed_call_app, $missed_call_data); } //echo "Multiple Emails = ".$missed_call_data; } else { //echo "Single Email = ".$missed_call_data."
"; if (!valid_email($missed_call_data)) { //echo "Invalid Email

"; unset($missed_call_app, $missed_call_data); } } break; case 'text': $missed_call_data = str_replace('-','',$missed_call_data); $missed_call_data = str_replace('.','',$missed_call_data); $missed_call_data = str_replace('(','',$missed_call_data); $missed_call_data = str_replace(')','',$missed_call_data); $missed_call_data = str_replace(' ','',$missed_call_data); if (!is_numeric($missed_call_data)) { unset($missed_call_app, $missed_call_data); } break; } //add the user to the database $user_email = ''; if ($_SESSION["users"]["unique"]["text"] != "global") { if ($autogen_users == "true") { $auto_user = $extension; for ($i=1; $i<=$range; $i++) { $user_last_name = $auto_user; $user_password = generate_password(); user_add($auto_user, $user_password, $user_email); $generated_users[$i]['username'] = $auto_user; $generated_users[$i]['password'] = $user_password; $auto_user++; } unset($auto_user); } } //build the data array if (!isset($range)) { $range = 1; } for ($i=0; $i<$range; $i++) { //check if the extension exists if ($action == "add" && extension_exists($extension)) { //extension exists } else { //extension does not exist add it if ($action == "add" || $range > 1) { $extension_uuid = uuid(); $voicemail_uuid = uuid(); $password = generate_password(); } //prepare the values //mwi account if (strlen($mwi_account) > 0) { if (strpos($mwi_account, '@') === false) { if (count($_SESSION["domains"]) > 1) { $mwi_account .= "@".$_SESSION['domain_name']; } else { $mwi_account .= "@\$\${domain}"; } } } //enabled if (!permission_exists('extension_enabled')) { $enabled = "true"; } //generate a password if ($action == "add" && strlen($password) == 0) { $password = generate_password(); } if ($action == "update" && permission_exists('extension_password') && strlen($password) == 0) { $password = generate_password(); } //create the data array $array["extensions"][$i]["domain_uuid"] = $domain_uuid; $array["extensions"][$i]["extension_uuid"] = $extension_uuid; $array["extensions"][$i]["extension"] = $extension; if (permission_exists('number_alias')) { $array["extensions"][$i]["number_alias"] = $number_alias; } if (strlen($password) > 0) { $array["extensions"][$i]["password"] = $password; } if (permission_exists('extension_accountcode')) { $array["extensions"][$i]["accountcode"] = $accountcode; } if (permission_exists("effective_caller_id_name")) { $array["extensions"][$i]["effective_caller_id_name"] = $effective_caller_id_name; } if (permission_exists("effective_caller_id_number")) { $array["extensions"][$i]["effective_caller_id_number"] = $effective_caller_id_number; } if (permission_exists("outbound_caller_id_name")) { $array["extensions"][$i]["outbound_caller_id_name"] = $outbound_caller_id_name; } if (permission_exists("outbound_caller_id_number")) { $array["extensions"][$i]["outbound_caller_id_number"] = $outbound_caller_id_number; } if (permission_exists("emergency_caller_id_name")) { $array["extensions"][$i]["emergency_caller_id_name"] = $emergency_caller_id_name; } if (permission_exists("emergency_caller_id_number")) { $array["extensions"][$i]["emergency_caller_id_number"] = $emergency_caller_id_number; } $array["extensions"][$i]["directory_first_name"] = $directory_first_name; $array["extensions"][$i]["directory_last_name"] = $directory_last_name; $array["extensions"][$i]["directory_visible"] = $directory_visible; $array["extensions"][$i]["directory_exten_visible"] = $directory_exten_visible; $array["extensions"][$i]["limit_max"] = $limit_max; $array["extensions"][$i]["limit_destination"] = $limit_destination; $array["extensions"][$i]["user_context"] = $user_context; if (permission_exists('extension_missed_call')) { $array["extensions"][$i]["missed_call_app"] = $missed_call_app; $array["extensions"][$i]["missed_call_data"] = $missed_call_data; } if (permission_exists('extension_toll')) { $array["extensions"][$i]["toll_allow"] = $toll_allow; } if (strlen($call_timeout) > 0) { $array["extensions"][$i]["call_timeout"] = $call_timeout; } $array["extensions"][$i]["call_group"] = $call_group; $array["extensions"][$i]["call_screen_enabled"] = $call_screen_enabled; if (permission_exists('extension_user_record')) { $array["extensions"][$i]["user_record"] = $user_record; } $array["extensions"][$i]["hold_music"] = $hold_music; $array["extensions"][$i]["auth_acl"] = $auth_acl; if (permission_exists("extension_cidr")) { $array["extensions"][$i]["cidr"] = $cidr; } $array["extensions"][$i]["sip_force_contact"] = $sip_force_contact; $array["extensions"][$i]["sip_force_expires"] = $sip_force_expires; if (permission_exists('extension_nibble_account')) { if (strlen($nibble_account) > 0) { $array["extensions"][$i]["nibble_account"] = $nibble_account; } } if (strlen($mwi_account) > 0) { $array["extensions"][$i]["mwi_account"] = $mwi_account; } $array["extensions"][$i]["sip_bypass_media"] = $sip_bypass_media; if (permission_exists('extension_absolute_codec_string')) { $array["extensions"][$i]["absolute_codec_string"] = $absolute_codec_string; } if (permission_exists('extension_force_ping')) { $array["extensions"][$i]["force_ping"] = $force_ping; } if (permission_exists('extension_dial_string')) { $array["extensions"][$i]["dial_string"] = $dial_string; } $array["extensions"][$i]["enabled"] = $enabled; $array["extensions"][$i]["description"] = $description; } //add or update voicemail if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/voicemails')) { //set the voicemail password if (strlen($voicemail_password) == 0) { $voicemail_password = generate_password($_SESSION['voicemail']['password_length']['numeric'], 1); } // build voicemail if ($voicemail_id !== NULL) { //get the voicemail_uuid $sql = "select voicemail_uuid from v_voicemails "; $sql .= "where voicemail_id = :voicemail_id "; $sql .= "and domain_uuid = :domain_uuid "; $parameters['voicemail_id'] = $voicemail_id; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $voicemail_uuid = $row["voicemail_uuid"]; } unset($sql, $parameters, $row); //if voicemail_uuid does not exist then get a new uuid if (!is_uuid($voicemail_uuid)) { $voicemail_uuid = uuid(); $voicemail_tutorial = 'true'; } //add the voicemail $array["voicemails"][$i]["domain_uuid"] = $domain_uuid; $array["voicemails"][$i]["voicemail_uuid"] = $voicemail_uuid; $array["voicemails"][$i]["voicemail_id"] = $voicemail_id; $array["voicemails"][$i]["voicemail_password"] = $voicemail_password; //$array["voicemails"][$i]["greeting_id"] = $greeting_id; //$array["voicemails"][$i]["voicemail_alternate_greet_id"] = $alternate_greet_id; $array["voicemails"][$i]["voicemail_mail_to"] = $voicemail_mail_to; //$array["voicemails"][$i]["voicemail_attach_file"] = $voicemail_attach_file; $array["voicemails"][$i]["voicemail_file"] = $voicemail_file; if (permission_exists('voicemail_local_after_email')) { $array["voicemails"][$i]["voicemail_local_after_email"] = $voicemail_local_after_email; } $array["voicemails"][$i]["voicemail_enabled"] = $voicemail_enabled; $array["voicemails"][$i]["voicemail_description"] = $description; $array["voicemails"][$i]["voicemail_tutorial"] = $voicemail_tutorial; } } //increment the extension number if ($action != "update") { $extension++; $voicemail_id = $extension; if (strlen($number_alias) > 0) { $number_alias++; $voicemail_id = $number_alias; } if (strlen($mwi_account) > 0) { $mwi_account_array = explode('@', $mwi_account); $mwi_account_array[0]++; $mwi_account = implode('@', $mwi_account_array); unset($mwi_account_array); } } } //update devices having extension assigned to line(s) with new password if ($action == "update" && $range == 1 && permission_exists('extension_password')) { $sql = "update v_device_lines set "; $sql .= "password = :password "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and server_address = :server_address "; $sql .= "and user_id = :user_id "; $parameters['password'] = $password; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['server_address'] = $_SESSION['domain_name']; $parameters['user_id'] = $extension; $database = new database; $database->execute($sql, $parameters); unset($sql, $parameters); } //update device key label if (strlen($effective_caller_id_name) > 0) { $sql = "update v_device_keys set "; $sql .= "device_key_label = :device_key_label "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and device_key_value = :device_key_value "; $parameters['device_key_label'] = $effective_caller_id_name; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['device_key_value'] = $extension; $database = new database; $database->execute($sql, $parameters); unset($sql, $parameters); } //assign the user to the extension if ($action == "update" && is_uuid($_POST["extension_users"][0]["user_uuid"])) { $array["extension_users"][0]["extension_user_uuid"] = uuid(); $array["extension_users"][0]["domain_uuid"] = $_SESSION['domain_uuid']; $array["extension_users"][0]["user_uuid"] = $_POST["extension_users"][0]["user_uuid"]; $array["extension_users"][0]["extension_uuid"] = $extension_uuid; } //assign the device to the extension if ($action == "update" && strlen($_POST["devices"][0]["device_mac_address"]) > 0) { //set the variables $device_uuid = uuid(); $device_line_uuid = uuid(); $device_mac_address = $_POST["devices"][0]["device_mac_address"]; $device_template = $_POST["devices"][0]["device_template"]; $line_number = $_POST["devices"][0]["line_number"]; //normalize the mac address $device_mac_address = strtolower($device_mac_address); $device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address); //get the device_uuid $sql = "select device_uuid from v_devices "; $sql .= "where device_mac_address = :device_mac_address "; $sql .= "and domain_uuid = :domain_uuid "; $parameters['device_mac_address'] = $device_mac_address; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_uuid($row['device_uuid'])) { $device_uuid = $row['device_uuid']; } unset($sql, $parameters); //set a default line number if (strlen($line_number) == 0) { $line_number = '1'; } //add the device and device lines to the array $array["devices"][0]["device_uuid"] = $device_uuid; $array["devices"][0]["domain_uuid"] = $_SESSION['domain_uuid']; $array["devices"][0]["device_mac_address"] = $device_mac_address; $array["devices"][0]["device_label"] = $extension; if (strlen($device_template) > 0) { $array["devices"][0]["device_template"] = $device_template; } $array["devices"][0]["device_enabled"] = "true"; $array["devices"][0]["device_lines"][0]["device_uuid"] = $device_uuid; $array["devices"][0]["device_lines"][0]["device_line_uuid"] = $device_line_uuid; $array["devices"][0]["device_lines"][0]["domain_uuid"] = $_SESSION['domain_uuid']; $array["devices"][0]["device_lines"][0]["server_address"] = $_SESSION['domain_name']; $array["devices"][0]["device_lines"][0]["outbound_proxy_primary"] = $_SESSION['provision']['outbound_proxy_primary']['text']; $array["devices"][0]["device_lines"][0]["outbound_proxy_secondary"] = $_SESSION['provision']['outbound_proxy_secondary']['text']; $array["devices"][0]["device_lines"][0]["display_name"] = strlen($effective_caller_id_name) > 0 ? $effective_caller_id_name : $extension; $array["devices"][0]["device_lines"][0]["user_id"] = $extension; $array["devices"][0]["device_lines"][0]["auth_id"] = $extension; $array["devices"][0]["device_lines"][0]["password"] = $password; $array["devices"][0]["device_lines"][0]["line_number"] = $line_number; $array["devices"][0]["device_lines"][0]["sip_port"] = $_SESSION['provision']['line_sip_port']['numeric']; $array["devices"][0]["device_lines"][0]["sip_transport"] = $_SESSION['provision']['line_sip_transport']['text']; $array["devices"][0]["device_lines"][0]["register_expires"] = $_SESSION['provision']['line_register_expires']['numeric']; $array["devices"][0]["device_lines"][0]["enabled"] = "true"; } //save to the data $database = new database; $database->app_name = 'extensions'; $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; $database->save($array); $message = $database->message; unset($array); // reload ACL if allowed if (permission_exists("extension_cidr")) { $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { event_socket_request($fp, "api reloadacl"); } } //check the permissions if (permission_exists('extension_add') || permission_exists('extension_edit')) { //synchronize configuration if (is_writable($_SESSION['switch']['extensions']['dir'])) { require_once "app/extensions/resources/classes/extension.php"; $ext = new extension; $ext->xml(); unset($ext); } //write the provision files if (strlen($_SESSION['provision']['path']['text']) > 0) { if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) { $prov = new provision; $prov->domain_uuid = $domain_uuid; $response = $prov->write(); } } //clear the cache $cache = new cache; $cache->delete("directory:".$extension."@".$user_context); if (permission_exists('number_alias') && strlen($number_alias) > 0) { $cache->delete("directory:".$number_alias."@".$user_context); } } //show the action and redirect the user if ($action == "add") { message::add($text['message-add']); //prepare for alternating the row style $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; //show the action and redirect the user if (count($generated_users) == 0) { //action add header("Location: extension_edit.php?id=".$extension_uuid); } else { //auto-generate user with extension as login name require_once "resources/header.php"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; foreach ($generated_users as $tmp_user) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; } $c = $c ? 0 : 1; echo "
New User Accounts
UsernamePassword
".$tmp_user['username']."".$tmp_user['password']."
"; echo "
\n"; require_once "resources/footer.php"; } exit; } if ($action == "update") { message::add($text['message-update']); header("Location: extension_edit.php?id=".$extension_uuid.(is_numeric($page) ? '&page='.$page : null)); return; } } } //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $extension_uuid = $_GET["id"]; $sql = "select * from v_extensions "; $sql .= "where extension_uuid = :extension_uuid "; $parameters['extension_uuid'] = $extension_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $domain_uuid = $row["domain_uuid"]; $extension = $row["extension"]; $number_alias = $row["number_alias"]; $password = $row["password"]; $accountcode = $row["accountcode"]; $effective_caller_id_name = $row["effective_caller_id_name"]; $effective_caller_id_number = $row["effective_caller_id_number"]; $outbound_caller_id_name = $row["outbound_caller_id_name"]; $outbound_caller_id_number = $row["outbound_caller_id_number"]; $emergency_caller_id_name = $row["emergency_caller_id_name"]; $emergency_caller_id_number = $row["emergency_caller_id_number"]; $directory_first_name = $row["directory_first_name"]; $directory_last_name = $row["directory_last_name"]; $directory_visible = $row["directory_visible"]; $directory_exten_visible = $row["directory_exten_visible"]; $limit_max = $row["limit_max"]; $limit_destination = $row["limit_destination"]; $user_context = $row["user_context"]; $missed_call_app = $row["missed_call_app"]; $missed_call_data = $row["missed_call_data"]; $toll_allow = $row["toll_allow"]; $call_timeout = $row["call_timeout"]; $call_group = $row["call_group"]; $call_screen_enabled = $row["call_screen_enabled"]; $user_record = $row["user_record"]; $hold_music = $row["hold_music"]; $auth_acl = $row["auth_acl"]; $cidr = $row["cidr"]; $sip_force_contact = $row["sip_force_contact"]; $sip_force_expires = $row["sip_force_expires"]; $nibble_account = $row["nibble_account"]; $mwi_account = $row["mwi_account"]; $sip_bypass_media = $row["sip_bypass_media"]; $absolute_codec_string = $row["absolute_codec_string"]; $force_ping = $row["force_ping"]; $dial_string = $row["dial_string"]; $enabled = $row["enabled"]; $description = $row["description"]; } unset($sql, $parameters, $row); //get the voicemail data if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/voicemails')) { //get the voicemails $sql = "select * from v_voicemails "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and voicemail_id = :voicemail_id "; $parameters['domain_uuid'] = $domain_uuid; $parameters['voicemail_id'] = is_numeric($number_alias) ? $number_alias : $extension; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $voicemail_password = str_replace("#", "", $row["voicemail_password"]); $voicemail_mail_to = str_replace(" ", "", $row["voicemail_mail_to"]); $voicemail_file = $row["voicemail_file"]; $voicemail_local_after_email = $row["voicemail_local_after_email"]; $voicemail_enabled = $row["voicemail_enabled"]; $voicemail_tutorial = $row["voicemail_tutorial"]; } unset($sql, $parameters, $row); } } else { $voicemail_file = $_SESSION['voicemail']['voicemail_file']['text']; $voicemail_local_after_email = $_SESSION['voicemail']['keep_local']['boolean']; } //get the device lines $sql = "select d.device_mac_address, d.device_template, d.device_description, l.device_line_uuid, l.device_uuid, l.line_number "; $sql .= "from v_device_lines as l, v_devices as d "; $sql .= "where (l.user_id = :user_id_1 or l.user_id = :user_id_2)"; $sql .= "and l.domain_uuid = :domain_uuid "; $sql .= "and l.device_uuid = d.device_uuid "; $sql .= "order by l.line_number, d.device_mac_address asc "; $parameters['user_id_1'] = $extension; $parameters['user_id_2'] = $number_alias; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $device_lines = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //get the devices $sql = "select * from v_devices "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "order by device_mac_address asc "; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $devices = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //get the device vendors $sql = "select name "; $sql .= "from v_device_vendors "; $sql .= "where enabled = 'true' "; $sql .= "order by name asc "; $database = new database; $device_vendors = $database->select($sql, null, 'all'); unset($sql); //get assigned users if (is_uuid($extension_uuid)) { $sql = "select u.username, e.user_uuid "; $sql .= "from v_extension_users as e, v_users as u "; $sql .= "where e.user_uuid = u.user_uuid "; $sql .= "and u.user_enabled = 'true' "; $sql .= "and e.domain_uuid = :domain_uuid "; $sql .= "and e.extension_uuid = :extension_uuid "; $sql .= "order by u.username asc "; $parameters['domain_uuid'] = $domain_uuid; $parameters['extension_uuid'] = $extension_uuid; $database = new database; $assigned_users = $database->select($sql, $parameters, 'all'); if (is_array($assigned_users) && @sizeof($assigned_users) != 0) { foreach($assigned_users as $row) { $assigned_user_uuids[] = $row['user_uuid']; } } unset($sql, $parameters, $row); } //get the users $sql = "select * from v_users "; $sql .= "where domain_uuid = :domain_uuid "; if (is_array($assigned_user_uuids) && @sizeof($assigned_user_uuids) != 0) { foreach ($assigned_user_uuids as $index => $assigned_user_uuid) { $sql .= "and user_uuid <> :user_uuid_".$index." "; $parameters['user_uuid_'.$index] = $assigned_user_uuid; } } $sql .= "and user_enabled = 'true' "; $sql .= "order by username asc "; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $users = $database->select($sql, $parameters, 'all'); unset($sql, $parameters, $assigned_user_uuids, $assigned_user_uuid); //get the destinations $sql = "select * from v_destinations "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and destination_type = 'inbound' "; $sql .= "order by destination_number asc "; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $destinations = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //change toll allow delimiter $toll_allow = str_replace(':',',', $toll_allow); //set the defaults if (strlen($user_context) == 0) { $user_context = $_SESSION['domain_name']; } if (strlen($limit_max) == 0) { $limit_max = '5'; } if (strlen($limit_destination) == 0) { $limit_destination = 'error/user_busy'; } if (strlen($call_timeout) == 0) { $call_timeout = '30'; } if (strlen($call_screen_enabled) == 0) { $call_screen_enabled = 'false'; } //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //begin the page content require_once "resources/header.php"; if ($action == "update") { $document['title'] = $text['title-extension-edit']; } elseif ($action == "add") { $document['title'] = $text['title-extension-add']; } echo ""; echo "
\n"; if (is_numeric($page)) { echo "\n"; } echo "\n"; echo "\n"; if ($action == "add") { echo "\n"; } if ($action == "update") { echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('number_alias')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('extension_password') && $action == "update") { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if ($action == "add") { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('extension_user_edit') && $action == "update") { echo " "; echo " "; echo " "; echo " "; } if (permission_exists('voicemail_edit') && is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/voicemails')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('extension_accountcode')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('device_edit') && $action == "update") { if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/devices')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } } if (permission_exists("effective_caller_id_name")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists("effective_caller_id_number")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists("outbound_caller_id_name")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists("outbound_caller_id_number")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists("emergency_caller_id_name")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists("emergency_caller_id_number")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('voicemail_edit') && is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/voicemails')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('voicemail_local_after_email')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } } if (permission_exists('extension_missed_call')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('extension_toll')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('extension_call_screen')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('extension_user_record')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/music_on_hold')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists("extension_user_context")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } //--- begin: show_advanced ----------------------- echo "\n"; echo "\n"; echo "\n"; //--- end: show_advanced ----------------------- if (permission_exists('extension_enabled')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " "; echo "
".$text['header-extension-add']."".$text['header-extension-edit']."\n"; echo " \n"; if ($action == 'update' && permission_exists('xml_cdr_view')) { echo " \n"; } if ($action == 'update' && (permission_exists('follow_me') || permission_exists('call_forward') || permission_exists('do_not_disturb'))) { echo " \n"; } if ($action == "update" && permission_exists('extension_copy')) { echo " \n"; } echo " \n"; echo "

\n"; echo "
\n"; echo " ".$text['label-extension']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-extension']."\n"; echo "
\n"; echo " ".$text['label-number_alias']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-number_alias']."\n"; echo "
\n"; echo " ".$text['label-password']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo " ".$text['description-password']."\n"; echo "
\n"; echo " ".$text['label-range']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-range']."
\n"; if ($_SESSION["user"]["unique"]["text"] != "global") { echo " ".$text['checkbox-range']."
\n"; } echo "
".$text['label-users'].""; if (count($assigned_users) > 0) { echo " \n"; foreach($assigned_users as $field) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; } echo "
".escape($field['username'])."\n"; echo " $v_link_label_delete\n"; //echo " $v_link_label_delete\n"; echo "
\n"; echo "
\n"; } echo " "; echo " \n"; echo "
\n"; echo " ".$text['description-user_list']."\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-voicemail_password']."\n"; echo "\n"; echo " \n"; //help defeat browser auto-fill echo " \n"; echo "
\n"; echo " ".$text['description-voicemail_password']."\n"; echo "
\n"; echo " ".$text['label-accountcode']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo " ".$text['description-accountcode']."\n"; echo "
\n"; echo " ".$text['label-provisioning']."\n"; echo "\n"; echo " "; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; foreach($device_lines as $row) { $device_mac_address = $row['device_mac_address']; $device_mac_address = substr($device_mac_address, 0,2).'-'.substr($device_mac_address, 2,2).'-'.substr($device_mac_address, 4,2).'-'.substr($device_mac_address, 6,2).'-'.substr($device_mac_address, 8,2).'-'.substr($device_mac_address, 10,2); echo " \n"; echo " \n"; echo " \n"; echo " \n"; //echo " \n"; echo " \n"; echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-line']." \n"; echo " \n"; echo " ".$text['label-device_mac_address']." \n"; echo " \n"; echo " ".$text['label-device_template']." \n"; echo " \n"; //if (permission_exists('device_delete')) { // echo " $v_link_label_delete\n"; //} echo "
".escape($row['line_number'])."".escape($device_mac_address)."".escape($row['device_template'])." ".$row['device_description']." \n"; echo " $v_link_label_delete\n"; echo "
"; echo " \n"; echo " "; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; ?> \n"; echo " \n"; if (count($devices) > 0) { foreach($devices as $field) { if (strlen($field["device_mac_address"]) > 0) { if ($field_current_value == $field["device_mac_address"]) { echo " \n"; } else { echo " \n"; } } } } echo " \n"; echo " \n"; echo "
\n"; echo "
"; $device = new device; $template_dir = $device->get_template_dir(); echo "\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo $text['description-provisioning']."\n"; echo "
\n"; echo " ".$text['label-effective_caller_id_name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-effective_caller_id_name']."\n"; echo "
\n"; echo " ".$text['label-effective_caller_id_number']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-effective_caller_id_number']."\n"; echo "
\n"; echo " ".$text['label-outbound_caller_id_name']."\n"; echo "\n"; if (permission_exists('outbound_caller_id_select')) { if (count($destinations) > 0) { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_name-select']."\n"; } else { echo " \n"; } } else { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_name-custom']."\n"; } echo "
\n"; echo " ".$text['label-outbound_caller_id_number']."\n"; echo "\n"; if (permission_exists('outbound_caller_id_select')) { if (count($destinations) > 0) { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_number-select']."\n"; } else { echo " \n"; } } else { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_number-custom']."\n"; } echo "
\n"; echo " ".$text['label-emergency_caller_id_name']."\n"; echo "\n"; if (permission_exists('outbound_caller_id_select')) { if (count($destinations) > 0) { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_name-select']."\n"; } else { echo " \n"; } } else { echo " \n"; } echo "
\n"; echo $text['description-emergency_caller_id_name']."\n"; echo "
\n"; echo " ".$text['label-emergency_caller_id_number']."\n"; echo "\n"; if (permission_exists('outbound_caller_id_select')) { if (count($destinations) > 0) { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_name-select']."\n"; } else { echo " \n"; } } else { echo " \n"; } echo "
\n"; echo $text['description-emergency_caller_id_number']."\n"; echo "
\n"; echo " ".$text['label-directory_full_name']."\n"; echo "\n"; echo " \n"; echo " \n"; echo "
\n"; echo $text['description-directory_full_name']."\n"; echo "
\n"; echo " ".$text['label-directory_visible']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; echo $text['description-directory_visible']."\n"; echo "
\n"; echo " ".$text['label-directory_exten_visible']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; echo $text['description-directory_exten_visible']."\n"; echo "
\n"; echo " ".$text['label-limit_max']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-limit_max']."\n"; echo "
\n"; echo " ".$text['label-limit_destination']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-limit_destination']."\n"; echo "
\n"; echo " ".$text['label-voicemail_enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_enabled']."\n"; echo "
\n"; echo " ".$text['label-voicemail_mail_to']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_mail_to']."\n"; echo "
\n"; echo " ".$text['label-voicemail_file']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_file']."\n"; echo "
\n"; echo " ".$text['label-voicemail_local_after_email']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_local_after_email']."\n"; echo "
\n"; echo " ".$text['label-missed_call']."\n"; echo "\n"; echo " \n"; $missed_call_data = ($missed_call_app == 'text') ? format_phone($missed_call_data) : $missed_call_data; echo " \n"; echo "
\n"; echo $text['description-missed_call']."\n"; echo "
\n"; echo " ".$text['label-toll_allow']."\n"; echo "\n"; if (is_array($_SESSION['toll allow']['name'])) { echo " \n"; } else { echo " \n"; } echo "
\n"; echo $text['description-toll_allow']."\n"; echo "
\n"; echo " ".$text['label-call_timeout']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_timeout']."\n"; echo "
\n"; echo " ".$text['label-call_group']."\n"; echo "\n"; if (is_array($_SESSION['call group']['name'])) { echo " \n"; } else { echo " \n"; } echo "
\n"; echo $text['description-call_group']."\n"; echo "
\n"; echo " ".$text['label-call_screen_enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-call_screen_enabled']."\n"; echo "
\n"; echo " ".$text['label-user_record']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-user_record']."\n"; echo "
\n"; echo " ".$text['label-hold_music']."\n"; echo "\n"; require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php"; $options = ''; $moh = new switch_music_on_hold; echo $moh->select('hold_music', $hold_music, $options); echo "
\n"; echo $text['description-hold_music']."\n"; echo "
\n"; echo " ".$text['label-user_context']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-user_context']."\n"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
 \n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists("extension_cidr")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('extension_nibble_account')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('extension_absolute_codec_string')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('extension_force_ping')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('extension_domain')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('extension_dial_string')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "
\n"; echo " ".$text['label-auth_acl']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-auth_acl']."\n"; echo "
\n"; echo " ".$text['label-cidr']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-cidr']."\n"; echo "
\n"; echo " ".$text['label-sip_force_contact']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-sip_force_contact']."\n"; echo "
\n"; echo " ".$text['label-sip_force_expires']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-sip_force_expires']."\n"; echo "
\n"; echo " ".$text['label-nibble_account']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-nibble_account']."\n"; echo "
\n"; echo " ".$text['label-mwi_account']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-mwi_account']."\n"; echo "
\n"; echo " ".$text['label-sip_bypass_media']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-sip_bypass_media']."\n"; echo "
\n"; echo " ".$text['label-absolute_codec_string']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-absolute_codec_string']."\n"; echo "
\n"; echo " ".$text['label-force_ping']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-force_ping']."\n"; echo "
\n"; echo " ".$text['label-domain']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-domain_name']."\n"; echo "
\n"; echo " ".$text['label-dial_string']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-dial_string']."\n"; echo "
\n"; echo "
"; echo "
\n"; echo " ".$text['label-enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-enabled']."\n"; echo "
\n"; echo " ".$text['label-description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-description']."\n"; echo "
\n"; if ($action == "update") { echo " \n"; echo " "; if (!permission_exists('extension_domain')) { echo " "; } echo " "; echo " "; } echo " \n"; echo "
"; echo " \n"; echo "
"; echo "

"; echo "
"; //include the footer require_once "resources/footer.php"; ?>