diff --git a/app/extensions/extension_edit.php b/app/extensions/extension_edit.php
index ef1dcf6e8c..ebf3e27a23 100644
--- a/app/extensions/extension_edit.php
+++ b/app/extensions/extension_edit.php
@@ -123,6 +123,14 @@
$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;
+ }
}
//delete the user from the v_extension_users
@@ -243,19 +251,19 @@
//add the user to the database
$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++;
+ 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);
}
- unset($auto_user);
}
- }
//build the data array
if (!isset($range)) { $range = 1; }
@@ -371,40 +379,43 @@
$voicemail_password = generate_password($_SESSION['voicemail']['password_length']['numeric'], 1);
}
- //get the voicemail_uuid
- $sql = "select voicemail_uuid from v_voicemails ";
- $sql .= "where voicemail_id = '".check_str($extension)."' ";
- $sql .= "and domain_uuid = '".check_str($_SESSION["domain_uuid"])."' ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- foreach ($result as &$row) {
- $voicemail_uuid = $row["voicemail_uuid"];
- }
+ // build voicemail
+ if ($voicemail_id !== NULL) {
+ //get the voicemail_uuid
+ $sql = "select voicemail_uuid from v_voicemails ";
+ $sql .= "where voicemail_id = '".check_str($voicemail_id)."' ";
+ $sql .= "and domain_uuid = '".check_str($_SESSION["domain_uuid"])."' ";
+ $prep_statement = $db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+ foreach ($result as &$row) {
+ $voicemail_uuid = $row["voicemail_uuid"];
+ }
- //if voicemail_uuid does not exist then get a new uuid
- if (!isset($voicemail_uuid)) {
- $voicemail_uuid = uuid();
- $voicemail_tutorial = 'true';
- }
+ //if voicemail_uuid does not exist then get a new uuid
+ if (!isset($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"] = $extension;
- $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;
- $array["voicemails"][$i]["voicemail_local_after_email"] = $voicemail_local_after_email;
- $array["voicemails"][$i]["voicemail_enabled"] = $voicemail_enabled;
- if ( empty($voicemail_description)){
- $voicemail_description = $description;
+ //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;
+ $array["voicemails"][$i]["voicemail_local_after_email"] = $voicemail_local_after_email;
+ $array["voicemails"][$i]["voicemail_enabled"] = $voicemail_enabled;
+ if ( empty($voicemail_description)){
+ $voicemail_description = $description;
+ }
+ $array["voicemails"][$i]["voicemail_description"] = $voicemail_description;
+ $array["voicemails"][$i]["voicemail_tutorial"] = $voicemail_tutorial;
}
- $array["voicemails"][$i]["voicemail_description"] = $voicemail_description;
- $array["voicemails"][$i]["voicemail_tutorial"] = $voicemail_tutorial;
}
//increment the extension number
@@ -424,165 +435,166 @@
}
}
- //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 = '".check_str($password)."' ";
- $sql .= "where domain_uuid = '".check_str($_SESSION['domain_uuid'])."' ";
- $sql .= "and server_address = '".check_str($_SESSION['domain_name'])."' ";
- $sql .= "and user_id = '".check_str($extension)."' ";
- $sql .= "and password = '".check_str($extension)."' ";
- $db->exec(check_sql($sql));
- unset($sql);
- }
+ //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 = '".check_str($password)."' ";
+ $sql .= "where domain_uuid = '".check_str($_SESSION['domain_uuid'])."' ";
+ $sql .= "and server_address = '".check_str($_SESSION['domain_name'])."' ";
+ $sql .= "and user_id = '".check_str($extension)."' ";
+ $sql .= "and password = '".check_str($extension)."' ";
+ $db->exec(check_sql($sql));
+ unset($sql);
+ }
- //assign the user to the extension
- if ($action == "update" && strlen($_POST["extension_users"][0]["user_uuid"]) > 0) {
- $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 user to the extension
+ if ($action == "update" && strlen($_POST["extension_users"][0]["user_uuid"]) > 0) {
+ $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) {
+ //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"];
+ //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);
+ //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 = '".check_str($device_mac_address)."' ";
- $sql .= "AND domain_uuid = '".check_str($domain_uuid)."' ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- foreach($result as $field) {
- $device_uuid = $field['device_uuid'];
- }
- unset($sql, $prep_statement);
-
- //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;
- 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]["display_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 = null;
- $database->save($array);
- $message = $database->message;
- //echo "
".print_r($message, true)."\n";
- //exit;
-
- //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();
+ //get the device_uuid
+ $sql = "SELECT device_uuid FROM v_devices ";
+ $sql .= "WHERE device_mac_address = '".check_str($device_mac_address)."' ";
+ $sql .= "AND domain_uuid = '".check_str($domain_uuid)."' ";
+ $prep_statement = $db->prepare(check_sql($sql));
+ $prep_statement->execute();
+ $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+ foreach($result as $field) {
+ $device_uuid = $field['device_uuid'];
}
- }
+ unset($sql, $prep_statement);
- //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);
- }
- }
+ //set a default line number
+ if (strlen($line_number) == 0) { $line_number = '1'; }
- //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";
+ //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;
+ 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]["display_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";
- //show the action and redirect the user
- if (count($generated_users) == 0) {
- //action add
- $_SESSION["message"] = $text['message-add'];
- header("Location: extension_edit.php?id=".$extension_uuid);
+ }
+
+ //save to the data
+ $database = new database;
+ $database->app_name = 'extensions';
+ $database->app_uuid = null;
+ $database->save($array);
+ $message = $database->message;
+ // echo "".print_r($array, true)."\n";
+ // echo "".print_r($message, true)."\n";
+ // die();
+
+ //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") {
+ //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: 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 " | New User Accounts | \n";
+ echo "
\n";
+ echo " \n";
+ echo " | Username | \n";
+ echo " Password | \n";
+ echo "
\n";
+ foreach($generated_users as $tmp_user){
+ echo " \n";
+ echo " | ".$tmp_user['username']." | \n";
+ echo " ".$tmp_user['password']." | \n";
+ echo "
\n";
+ }
+ if ($c==0) { $c=1; } else { $c=0; }
+ echo "
";
+ echo "
\n";
+ require_once "resources/footer.php";
+ }
+ return;
+ }
+ if ($action == "update") {
+ if ($action == "update") {
+ $_SESSION["message"] = $text['message-update'];
}
else {
- //auto-generate user with extension as login name
- require_once "resources/header.php";
- echo "
\n";
- echo "\n";
- echo "
\n";
- echo " \n";
- echo " | New User Accounts | \n";
- echo "
\n";
- echo " \n";
- echo " | Username | \n";
- echo " Password | \n";
- echo "
\n";
- foreach($generated_users as $tmp_user){
- echo " \n";
- echo " | ".$tmp_user['username']." | \n";
- echo " ".$tmp_user['password']." | \n";
- echo "
\n";
- }
- if ($c==0) { $c=1; } else { $c=0; }
- echo "
";
- echo "
\n";
- require_once "resources/footer.php";
+ $_SESSION["message"] = $text['message-add'];
}
+ header("Location: extension_edit.php?id=".$extension_uuid);
return;
- }
- if ($action == "update") {
- if ($action == "update") {
- $_SESSION["message"] = $text['message-update'];
}
- else {
- $_SESSION["message"] = $text['message-add'];
- }
- header("Location: extension_edit.php?id=".$extension_uuid);
- return;
- }
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)