Copyright (C) 2008-2013 All Rights Reserved. Contributor(s): Mark J Crane */ include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists('extension_add') || permission_exists('extension_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //set the action as an add or an update if (isset($_REQUEST["id"])) { $action = "update"; $extension_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //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 = check_str($_POST["extension"]); $number_alias = check_str($_POST["number_alias"]); $password = check_str($_POST["password"]); //get the values from the HTTP POST and save them as PHP variables $accountcode = check_str($_POST["accountcode"]); $effective_caller_id_name = check_str($_POST["effective_caller_id_name"]); $effective_caller_id_number = check_str($_POST["effective_caller_id_number"]); $outbound_caller_id_name = check_str($_POST["outbound_caller_id_name"]); $outbound_caller_id_number = check_str($_POST["outbound_caller_id_number"]); $emergency_caller_id_number = check_str($_POST["emergency_caller_id_number"]); $directory_full_name = check_str($_POST["directory_full_name"]); $directory_visible = check_str($_POST["directory_visible"]); $directory_exten_visible = check_str($_POST["directory_exten_visible"]); $limit_max = check_str($_POST["limit_max"]); $limit_destination = check_str($_POST["limit_destination"]); $device_uuid = check_str($_POST["device_uuid"]); $device_line = check_str($_POST["device_line"]); $vm_password = check_str($_POST["vm_password"]); $vm_enabled = check_str($_POST["vm_enabled"]); $vm_mailto = check_str($_POST["vm_mailto"]); $vm_attach_file = check_str($_POST["vm_attach_file"]); $vm_keep_local_after_email = check_str($_POST["vm_keep_local_after_email"]); $user_context = check_str($_POST["user_context"]); $range = check_str($_POST["range"]); $autogen_users = check_str($_POST["autogen_users"]); $toll_allow = check_str($_POST["toll_allow"]); $call_timeout = check_str($_POST["call_timeout"]); $call_group = check_str($_POST["call_group"]); $hold_music = check_str($_POST["hold_music"]); $auth_acl = check_str($_POST["auth_acl"]); $cidr = check_str($_POST["cidr"]); $sip_force_contact = check_str($_POST["sip_force_contact"]); $sip_force_expires = check_str($_POST["sip_force_expires"]); $nibble_account = check_str($_POST["nibble_account"]); $mwi_account = check_str($_POST["mwi_account"]); $sip_bypass_media = check_str($_POST["sip_bypass_media"]); $dial_string = check_str($_POST["dial_string"]); $enabled = check_str($_POST["enabled"]); $description = check_str($_POST["description"]); } //delete the user from the v_extension_users if ($_GET["a"] == "delete" && strlen($_REQUEST["user_uuid"]) > 0 && permission_exists("extension_delete")) { //set the variables $user_uuid = check_str($_REQUEST["user_uuid"]); $extension_uuid = check_str($_REQUEST["id"]); //delete the group from the users $sql = "delete from v_extension_users "; $sql .= "where domain_uuid = '".$domain_uuid."' "; $sql .= "and extension_uuid = '".$extension_uuid."' "; $sql .= "and user_uuid = '".$user_uuid."' "; $db->exec(check_sql($sql)); //redirect the browser $_SESSION["message"] = $text['message-delete']; header("Location: extension_edit.php?id=".$extension_uuid); return; } //delete the line from the v_device_lines if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/devices')) { if ($_GET["a"] == "delete" && strlen($_REQUEST["device_line_uuid"]) > 0 && permission_exists("extension_delete")) { //set the variables $extension_uuid = check_str($_REQUEST["id"]); $device_line_uuid = check_str($_REQUEST["device_line_uuid"]); //delete device_line $sql = "delete from v_device_lines "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and device_line_uuid = '$device_line_uuid' "; $db->exec(check_sql($sql)); unset($sql); //redirect the browser $_SESSION["message"] = $text['message-delete']; header("Location: extension_edit.php?id=".$extension_uuid); return; } } //assign the extension to the user if (strlen($_REQUEST["user_uuid"]) > 0 && strlen($_REQUEST["id"]) > 0 && $_GET["a"] != "delete") { //set the variables $user_uuid = check_str($_REQUEST["user_uuid"]); $extension_uuid = check_str($_REQUEST["id"]); //assign the user to the extension $sql_insert = "insert into v_extension_users "; $sql_insert .= "("; $sql_insert .= "extension_user_uuid, "; $sql_insert .= "domain_uuid, "; $sql_insert .= "extension_uuid, "; $sql_insert .= "user_uuid "; $sql_insert .= ")"; $sql_insert .= "values "; $sql_insert .= "("; $sql_insert .= "'".uuid()."', "; $sql_insert .= "'$domain_uuid', "; $sql_insert .= "'".$extension_uuid."', "; $sql_insert .= "'".$user_uuid."' "; $sql_insert .= ")"; $db->exec($sql_insert); //redirect the browser $_SESSION["message"] = $text['message-add']; header("Location: extension_edit.php?id=".$extension_uuid); return; } //assign the line to the device if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/devices')) { if (strlen($_REQUEST["device_mac_address"]) > 0 && strlen($_REQUEST["id"]) > 0 && $_GET["a"] != "delete") { //set the variables $extension_uuid = check_str($_REQUEST["id"]); $device_uuid= uuid(); $device_line_uuid = uuid(); $device_template = check_str($_REQUEST["device_template"]); $line_number = check_str($_REQUEST["line_number"]); $device_mac_address = check_str($_REQUEST["device_mac_address"]); $device_mac_address = strtolower($device_mac_address); $device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address); //add the device if it doesn't exist, if it does exist get the device_uuid $sql = "select device_uuid from v_devices "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and device_mac_address = '$device_mac_address' "; if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } $prep_statement = $db->prepare($sql); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if (strlen($row['device_uuid']) > 0) { //device found $device_uuid = $row['device_uuid']; } else { //device not found $sql_insert = "insert into v_devices "; $sql_insert .= "("; $sql_insert .= "device_uuid, "; $sql_insert .= "domain_uuid, "; $sql_insert .= "device_mac_address, "; $sql_insert .= "device_template, "; $sql_insert .= "device_provision_enable "; $sql_insert .= ") "; $sql_insert .= "values "; $sql_insert .= "("; $sql_insert .= "'".$device_uuid."', "; $sql_insert .= "'".$_SESSION['domain_uuid']."', "; $sql_insert .= "'".$device_mac_address."', "; $sql_insert .= "'".$device_template."', "; $sql_insert .= "'true' "; $sql_insert .= ")"; //echo $sql_insert."
\n"; $db->exec($sql_insert); } } //assign the line to the device $sql_insert = "insert into v_device_lines "; $sql_insert .= "("; $sql_insert .= "device_uuid, "; $sql_insert .= "device_line_uuid, "; $sql_insert .= "domain_uuid, "; $sql_insert .= "server_address, "; $sql_insert .= "user_id, "; $sql_insert .= "auth_id, "; $sql_insert .= "password, "; $sql_insert .= "line_number "; $sql_insert .= ") "; $sql_insert .= "values "; $sql_insert .= "("; $sql_insert .= "'".$device_uuid."', "; $sql_insert .= "'".$device_line_uuid."', "; $sql_insert .= "'".$_SESSION['domain_uuid']."', "; $sql_insert .= "'".$_SESSION['domain_name']."', "; $sql_insert .= "'".$extension."', "; $sql_insert .= "'".$extension."', "; $sql_insert .= "'".$password."', "; $sql_insert .= "'".$line_number."' "; $sql_insert .= ")"; //echo $sql_insert."
\n"; $db->exec($sql_insert); //redirect the browser $_SESSION["message"] = $text['message-add']; header("Location: extension_edit.php?id=".$extension_uuid); return; } } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $extension_uuid = check_str($_POST["extension_uuid"]); } //check for all required data //if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']."domain_uuid
\n"; } if (strlen($extension) == 0) { $msg .= $text['message-required'].$text['label-extension']."
\n"; } //if (strlen($number_alias) == 0) { $msg .= $text['message-required']."Number Alias
\n"; } //if (strlen($vm_password) == 0) { $msg .= $text['message-required']."Voicemail Password
\n"; } //if (strlen($accountcode) == 0) { $msg .= $text['message-required']."Account Code
\n"; } //if (strlen($effective_caller_id_name) == 0) { $msg .= $text['message-required']."Effective Caller ID Name
\n"; } //if (strlen($effective_caller_id_number) == 0) { $msg .= $text['message-required']."Effective Caller ID Number
\n"; } //if (strlen($outbound_caller_id_name) == 0) { $msg .= $text['message-required']."Outbound Caller ID Name
\n"; } //if (strlen($outbound_caller_id_number) == 0) { $msg .= $text['message-required']."Outbound Caller ID Number
\n"; } //if (strlen($emergency_caller_id_number) == 0) { $msg .= $text['message-required']."Emergency Caller ID Number
\n"; } //if (strlen($directory_full_name) == 0) { $msg .= $text['message-required']."Directory Full Name
\n"; } //if (strlen($directory_visible) == 0) { $msg .= $text['message-required']."Directory Visible
\n"; } //if (strlen($directory_exten_visible) == 0) { $msg .= $text['message-required']."Directory Extension Visible
\n"; } //if (strlen($limit_max) == 0) { $msg .= $text['message-required']."Max Callsr
\n"; } //if (strlen($limit_destination) == 0) { $msg .= $text['message-required']."Transfer Destination Number
\n"; } //if (strlen($vm_mailto) == 0) { $msg .= $text['message-required']."Voicemail Mail To
\n"; } //if (strlen($vm_attach_file) == 0) { $msg .= $text['message-required']."Voicemail Attach File
\n"; } //if (strlen($vm_keep_local_after_email) == 0) { $msg .= $text['message-required']."VM Keep Local After Email
\n"; } //if (strlen($user_context) == 0) { $msg .= $text['message-required']."User Context
\n"; } //if (strlen($toll_allow) == 0) { $msg .= $text['message-required']."Toll Allow
\n"; } //if (strlen($call_group) == 0) { $msg .= $text['message-required']."Call Group
\n"; } //if (strlen($hold_music) == 0) { $msg .= $text['message-required']."Hold Music
\n"; } //if (strlen($auth_acl) == 0) { $msg .= $text['message-required']."Auth ACL
\n"; } //if (strlen($cidr) == 0) { $msg .= $text['message-required']."CIDR
\n"; } //if (strlen($sip_force_contact) == 0) { $msg .= $text['message-required']."SIP Force Contact
\n"; } //if (strlen($dial_string) == 0) { $msg .= $text['message-required']."Dial String
\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 (if_group("superadmin")) { //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 if (strlen($user_context) == 0) { if (count($_SESSION["domains"]) > 1) { $user_context = $_SESSION['domain_name']; } else { $user_context = "default"; } } } //add or update the database if ($_POST["persistformvar"] != "true") { //add the extension to the database if ($action == "add" && permission_exists('extension_add')) { $user_email = ''; if ($_SESSION["user"]["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); } } for ($i=1; $i<=$range; $i++) { if (extension_exists($extension)) { //extension exists } else { //extension does not exist add it $extension_uuid = uuid(); $password = generate_password(); $sql = "insert into v_extensions "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "extension_uuid, "; $sql .= "extension, "; $sql .= "number_alias, "; $sql .= "password, "; //$sql .= "vm_password, "; $sql .= "accountcode, "; $sql .= "effective_caller_id_name, "; $sql .= "effective_caller_id_number, "; $sql .= "outbound_caller_id_name, "; $sql .= "outbound_caller_id_number, "; $sql .= "emergency_caller_id_number, "; $sql .= "directory_full_name, "; $sql .= "directory_visible, "; $sql .= "directory_exten_visible, "; $sql .= "limit_max, "; $sql .= "limit_destination, "; //$sql .= "vm_enabled, "; //$sql .= "vm_mailto, "; //$sql .= "vm_attach_file, "; //$sql .= "vm_keep_local_after_email, "; $sql .= "user_context, "; if (permission_exists('extension_toll')) { $sql .= "toll_allow, "; } if (strlen($call_timeout) > 0) { $sql .= "call_timeout, "; } $sql .= "call_group, "; $sql .= "hold_music, "; $sql .= "auth_acl, "; $sql .= "cidr, "; $sql .= "sip_force_contact, "; if (strlen($sip_force_expires) > 0) { $sql .= "sip_force_expires, "; } if (strlen($nibble_account) > 0) { $sql .= "nibble_account, "; } if (strlen($mwi_account) > 0) { $sql .= "mwi_account, "; } $sql .= "sip_bypass_media, "; $sql .= "dial_string, "; $sql .= "enabled, "; $sql .= "description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$extension_uuid', "; $sql .= "'$extension', "; $sql .= "'$number_alias', "; $sql .= "'$password', "; //$sql .= "'user-choose', "; $sql .= "'$accountcode', "; $sql .= "'$effective_caller_id_name', "; $sql .= "'$effective_caller_id_number', "; $sql .= "'$outbound_caller_id_name', "; $sql .= "'$outbound_caller_id_number', "; $sql .= "'$emergency_caller_id_number', "; $sql .= "'$directory_full_name', "; $sql .= "'$directory_visible', "; $sql .= "'$directory_exten_visible', "; $sql .= "'$limit_max', "; $sql .= "'$limit_destination', "; //$sql .= "'$vm_enabled', "; //$sql .= "'$vm_mailto', "; //$sql .= "'$vm_attach_file', "; //$sql .= "'$vm_keep_local_after_email', "; $sql .= "'$user_context', "; if (permission_exists('extension_toll')) { $sql .= "'$toll_allow', "; } if (strlen($call_timeout) > 0) { $sql .= "'$call_timeout', "; } $sql .= "'$call_group', "; $sql .= "'$hold_music', "; $sql .= "'$auth_acl', "; $sql .= "'$cidr', "; $sql .= "'$sip_force_contact', "; if (strlen($sip_force_expires) > 0) { $sql .= "'$sip_force_expires', "; } if (strlen($nibble_account) > 0) { $sql .= "'$nibble_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}"; } } $sql .= "'$mwi_account', "; } $sql .= "'$sip_bypass_media', "; $sql .= "'$dial_string', "; if (permission_exists('extension_enabled')) { $sql .= "'$enabled', "; } else { $sql .= "'true', "; } $sql .= "'$description' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //add or update voicemail if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/voicemails')) { //set the voicemail password if (strlen($vm_password) == 0) { $vm_password = generate_password(9, 1); } //voicemail class require_once "app/extensions/resources/classes/extension.php"; $ext = new extension; $ext->db = $db; $ext->domain_uuid = $domain_uuid; $ext->extension = $extension; $ext->number_alias = $number_alias; $ext->vm_password = $vm_password; $ext->vm_mailto = $vm_mailto; $ext->vm_attach_file = $vm_attach_file; $ext->vm_keep_local_after_email = $vm_keep_local_after_email; $ext->vm_enabled = $vm_enabled; $ext->description = $description; $ext->voicemail(); unset($ext); } //increment the extension number $extension++; } } //if ($action == "add") //update the database if ($action == "update" && permission_exists('extension_edit')) { //generate a password if (strlen($password) == 0) { $password = generate_password(); } //set the voicemail password if (strlen($vm_password) == 0) { $vm_password = generate_password(9, 1); } //update extensions $sql = "update v_extensions set "; $sql .= "extension = '$extension', "; $sql .= "number_alias = '$number_alias', "; $sql .= "password = '$password', "; //$sql .= "vm_password = '$vm_password', "; $sql .= "accountcode = '$accountcode', "; $sql .= "effective_caller_id_name = '$effective_caller_id_name', "; $sql .= "effective_caller_id_number = '$effective_caller_id_number', "; $sql .= "outbound_caller_id_name = '$outbound_caller_id_name', "; $sql .= "outbound_caller_id_number = '$outbound_caller_id_number', "; $sql .= "emergency_caller_id_number = '$emergency_caller_id_number', "; $sql .= "directory_full_name = '$directory_full_name', "; $sql .= "directory_visible = '$directory_visible', "; $sql .= "directory_exten_visible = '$directory_exten_visible', "; $sql .= "limit_max = '$limit_max', "; $sql .= "limit_destination = '$limit_destination', "; //$sql .= "vm_enabled = '$vm_enabled', "; //$sql .= "vm_mailto = '$vm_mailto', "; //$sql .= "vm_attach_file = '$vm_attach_file', "; //$sql .= "vm_keep_local_after_email = '$vm_keep_local_after_email', "; $sql .= "user_context = '$user_context', "; if (permission_exists('extension_toll')) { $sql .= "toll_allow = '$toll_allow', "; } if (strlen($call_timeout) > 0) { $sql .= "call_timeout = '$call_timeout', "; } $sql .= "call_group = '$call_group', "; $sql .= "hold_music = '$hold_music', "; $sql .= "auth_acl = '$auth_acl', "; $sql .= "cidr = '$cidr', "; $sql .= "sip_force_contact = '$sip_force_contact', "; if (strlen($sip_force_expires) == 0) { $sql .= "sip_force_expires = null, "; } else { $sql .= "sip_force_expires = '$sip_force_expires', "; } if (strlen($nibble_account) == 0) { $sql .= "nibble_account = null, "; } else { $sql .= "nibble_account = '$nibble_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}"; } } } $sql .= "mwi_account = '$mwi_account', "; $sql .= "sip_bypass_media = '$sip_bypass_media', "; $sql .= "dial_string = '$dial_string', "; if (permission_exists('extension_enabled')) { $sql .= "enabled = '$enabled', "; } $sql .= "description = '$description' "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and extension_uuid = '$extension_uuid'"; $db->exec(check_sql($sql)); unset($sql); //add or update voicemail if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/voicemails')) { require_once "app/extensions/resources/classes/extension.php"; $ext = new extension; $ext->db = $db; $ext->domain_uuid = $domain_uuid; $ext->extension = $extension; $ext->number_alias = $number_alias; $ext->vm_password = $vm_password; $ext->vm_mailto = $vm_mailto; $ext->vm_attach_file = $vm_attach_file; $ext->vm_keep_local_after_email = $vm_keep_local_after_email; $ext->vm_enabled = $vm_enabled; $ext->description = $description; $ext->voicemail(); unset($ext); } } //if ($action == "update") //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 (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/provision')) { require_once "app/provision/provision_write.php"; $ext = new extension; } //delete extension from memcache $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $switch_cmd = "memcache delete directory:".$extension."@".$user_context; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); } } //show the action and redirect the user if ($action == "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 $_SESSION["message"] = $text['message-add']; header("Location: extensions.php"); } 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"; } if ($c==0) { $c=1; } else { $c=0; } echo "
New User Accounts
UsernamePassword
".$tmp_user['username']."".$tmp_user['password']."
"; echo "
\n"; require_once "resources/footer.php"; } return; } if ($action == "update") { if ($action == "update") { $_SESSION["message"] = $text['message-update']; } else { $_SESSION["message"] = $text['message-add']; } header("Location: extensions.php"); return; } } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $extension_uuid = $_GET["id"]; $sql = "select * from v_extensions "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and extension_uuid = '$extension_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $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_number = $row["emergency_caller_id_number"]; $directory_full_name = $row["directory_full_name"]; $directory_visible = $row["directory_visible"]; $directory_exten_visible = $row["directory_exten_visible"]; $limit_max = $row["limit_max"]; $limit_destination = $row["limit_destination"]; //$vm_password = $row["vm_password"]; //$vm_enabled = $row["vm_enabled"]; //$vm_mailto = $row["vm_mailto"]; //$vm_attach_file = $row["vm_attach_file"]; //$vm_keep_local_after_email = $row["vm_keep_local_after_email"]; $user_context = $row["user_context"]; $toll_allow = $row["toll_allow"]; $call_timeout = $row["call_timeout"]; $call_group = $row["call_group"]; $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"]; $dial_string = $row["dial_string"]; $enabled = $row["enabled"]; $description = $row["description"]; } unset ($prep_statement); } //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' "; if (is_numeric($extension)) { $sql .= "and voicemail_id = '$extension' "; } else { $sql .= "and voicemail_id = '$number_alias' "; } $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $vm_password = $row["voicemail_password"]; //$greeting_id = $row["greeting_id"]; $vm_mailto = $row["voicemail_mail_to"]; $vm_mailto = str_replace(" ", "", $vm_mailto); $vm_attach_file = $row["voicemail_attach_file"]; $vm_keep_local_after_email = $row["voicemail_local_after_email"]; $vm_enabled = $row["voicemail_enabled"]; } unset ($prep_statement); //clean the variables $vm_password = str_replace("#", "", $vm_password); $vm_mailto = str_replace(" ", "", $vm_mailto); } //set the defaults if (strlen($limit_max) == 0) { $limit_max = '5'; } if (strlen($call_timeout) == 0) { $call_timeout = '30'; } //begin the page content require_once "resources/header.php"; if ($action == "update") { $page["title"] = $text['title-extension-edit']; } else if ($action == "add") { $page["title"] = $text['title-extension-add']; } echo ""; echo "
"; echo "\n"; echo "\n"; echo " "; echo " "; echo "
\n"; echo "
"; echo "
\n"; 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"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($action == "update") { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if ($action == "add") { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if ($action == "update") { echo " "; echo " "; echo " "; echo " "; } if (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"; 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"; 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 ($action == "update") { if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/devices')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } } if (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"; 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 (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/music_on_hold')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (if_group("superadmin")) { if (strlen($user_context) == 0) { if (count($_SESSION["domains"]) > 1) { $user_context = $_SESSION['domain_name']; } else { $user_context = "default"; } } 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 != "add") { 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-user_list'].":"; echo " \n"; $sql = "SELECT u.username, e.user_uuid 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 = '".$_SESSION['domain_uuid']."' "; $sql .= "and e.extension_uuid = '".$extension_uuid."' "; $sql .= "order by u.username asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); foreach($result as $field) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; } echo "
".$field['username']."\n"; echo " $v_link_label_delete\n"; echo "
\n"; echo "
\n"; $sql = "SELECT * FROM v_users "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and user_enabled = 'true' "; $sql .= "order by username asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); echo " "; echo " \n"; unset($sql, $result); echo "
\n"; echo " ".$text['description-user_list']."\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-vm_password'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo " ".$text['description-vm_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-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')) { $sql = "select * from v_destinations "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and destination_type = 'inbound' "; $sql .= "order by destination_number asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); if (count($result) > 0) { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_name-select']."\n"; } else { echo " \n"; } unset ($prep_statement); } 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')) { $sql = "select * from v_destinations "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and destination_type = 'inbound' "; $sql .= "order by destination_number asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); if (count($result) > 0) { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_number-select']."\n"; } else { echo " \n"; } unset ($prep_statement); } else { echo " \n"; echo "
\n"; echo $text['description-outbound_caller_id_number-custom']."\n"; } echo "
\n"; echo " ".$text['label-emergency_caller_id_number'].":\n"; echo "\n"; 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 $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-provisioning'].":\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $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 = '".$extension."' "; $sql .= "AND l.domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "AND l.device_uuid = d.device_uuid "; $sql .= "ORDER BY l.line_number, d.device_mac_address asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); foreach($result 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_edit')) { // echo " $v_link_label_edit\n"; //} //if (permission_exists('device_delete')) { // echo " $v_link_label_delete\n"; //} echo "
".$row['line_number']."".$device_mac_address."".$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"; ?> prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); 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-vm_enabled'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-vm_enabled']."\n"; echo "
\n"; echo " ".$text['label-vm_mailto'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-vm_mailto']."\n"; echo "
\n"; echo " ".$text['label-vm_attach_file'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-vm_attach_file']."\n"; echo "
\n"; echo " ".$text['label-vm_keep_local_after_email'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-vm_keep_local_after_email']."\n"; echo "
\n"; echo " ".$text['label-toll_allow'].":\n"; echo "\n"; 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"; echo " \n"; echo "
\n"; echo $text['description-call_group']."\n"; echo "
\n"; echo " ".$text['label-hold_music'].":\n"; echo "\n"; require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php"; $moh= new switch_music_on_hold; $moh->select_name = "hold_music"; $moh->select_value = $hold_music; echo $moh->select(); 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 "
".$text['label-show_advanced']."\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"; 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 " ".$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-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 " \n"; echo "
"; echo ""; echo "
"; echo "
"; require_once "resources/footer.php"; ?>