Update devices to provide customizable line information.

This commit is contained in:
Mark Crane
2013-06-09 20:46:14 +00:00
parent a48f2b442b
commit 6f1afcab78
5 changed files with 727 additions and 57 deletions

View File

@@ -37,27 +37,27 @@
$apps[$x]['menu'][0]['groups'][] = 'superadmin';
//permission details
$apps[$x]['permissions'][0]['name'] = 'device_view';
$apps[$x]['permissions'][0]['groups'][] = 'admin';
$apps[$x]['permissions'][0]['groups'][] = 'superadmin';
$apps[$x]['permissions'][1]['name'] = 'device_add';
$apps[$x]['permissions'][1]['groups'][] = 'admin';
$apps[$x]['permissions'][1]['groups'][] = 'superadmin';
$apps[$x]['permissions'][2]['name'] = 'device_edit';
$apps[$x]['permissions'][2]['groups'][] = 'admin';
$apps[$x]['permissions'][2]['groups'][] = 'superadmin';
$apps[$x]['permissions'][3]['name'] = 'device_delete';
$apps[$x]['permissions'][3]['groups'][] = 'admin';
$apps[$x]['permissions'][3]['groups'][] = 'superadmin';
$y = 0;
$apps[$x]['permissions'][$y]['name'] = 'device_view';
$apps[$x]['permissions'][$y]['groups'][] = 'admin';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
$y++;
$apps[$x]['permissions'][$y]['name'] = 'device_add';
$apps[$x]['permissions'][$y]['groups'][] = 'admin';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
$y++;
$apps[$x]['permissions'][$y]['name'] = 'device_edit';
$apps[$x]['permissions'][$y]['groups'][] = 'admin';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
$y++;
$apps[$x]['permissions'][$y]['name'] = 'device_delete';
$apps[$x]['permissions'][$y]['groups'][] = 'admin';
$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
//schema details
$y = 0; //table array index
$z = 0; //field array index
$apps[$x]['db'][$y]['table'] = 'v_devices';
//$apps[$x]['db'][$y]['table']['deprecated'] = 'v_hardware_phones';
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = 'id';
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = 'hardware_device_id';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'serial';
@@ -184,4 +184,53 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = '';
$y = 2; //table array index
$z = 0; //field array index
$apps[$x]['db'][$y]['table'] = 'v_device_lines';
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'domain_uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
$apps[$x]['db'][$y]['fields'][$z]['key'] = 'foreign';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'device_line_uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
$apps[$x]['db'][$y]['fields'][$z]['key'] = 'primary';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'device_uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
$apps[$x]['db'][$y]['fields'][$z]['key'] = 'foreign';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'line_number';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Select the line number.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'server_address';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the sip server address.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'outbound_proxy';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the outbound proxy.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'display_name';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the display name.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'user_id';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the user id.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'auth_id';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the auth ID.';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'password';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = 'Enter the password.';
$z++;
?>

View File

@@ -64,6 +64,60 @@
$text['description-device_template']['en-us'] = 'Select a template.';
$text['description-device_template']['pt-pt'] = '';
$text['label-lines']['en-us'] = 'Lines';
$text['label-lines']['pt-pt'] = '';
$text['label-line']['en-us'] = 'Line';
$text['label-line']['pt-pt'] = '';
$text['label-line_number']['en-us'] = 'Line Number';
$text['label-line_number']['pt-pt'] = '';
$text['description-line_number']['en-us'] = 'Select a line number.';
$text['description-line_number']['pt-pt'] = '';
$text['label-server_address']['en-us'] = 'Server Address';
$text['label-server_address']['pt-pt'] = '';
$text['description-server_address']['en-us'] = 'Select a server address.';
$text['description-server_address']['pt-pt'] = '';
$text['label-server_address']['en-us'] = 'Server Address';
$text['label-server_address']['pt-pt'] = '';
$text['description-server_address']['en-us'] = 'Select a server address.';
$text['description-server_address']['pt-pt'] = '';
$text['label-outbound_proxy']['en-us'] = 'Outbound Proxy';
$text['label-outbound_proxy']['pt-pt'] = '';
$text['description-outbound_proxy']['en-us'] = 'Enter the outbound proxy.';
$text['description-outbound_proxy']['pt-pt'] = '';
$text['label-display_name']['en-us'] = 'Display Name';
$text['label-display_name']['pt-pt'] = '';
$text['description-display_name']['en-us'] = 'Enter the display name.';
$text['description-display_name']['pt-pt'] = '';
$text['label-user_id']['en-us'] = 'User ID';
$text['label-user_id']['pt-pt'] = '';
$text['description-user_id']['en-us'] = 'Enter the user ID.';
$text['description-user_id']['pt-pt'] = '';
$text['label-auth_id']['en-us'] = 'Auth ID';
$text['label-auth_id']['pt-pt'] = '';
$text['description-auth_id']['en-us'] = 'Enter the auth ID.';
$text['description-auth_id']['pt-pt'] = '';
$text['label-password']['en-us'] = 'Password';
$text['label-password']['pt-pt'] = '';
$text['description-password']['en-us'] = 'Enter the password.';
$text['description-password']['pt-pt'] = '';
//$text['label-device_username']['en-us'] = 'Username';
//$text['label-device_username']['pt-pt'] = '';

View File

@@ -52,19 +52,28 @@ require_once "includes/require.php";
//get http post variables and set them to php variables
if (count($_POST) > 0) {
$device_mac_address = check_str($_POST["device_mac_address"]);
$device_mac_address = strtolower($device_mac_address);
$device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address);
$device_label = check_str($_POST["device_label"]);
$device_vendor = check_str($_POST["device_vendor"]);
$device_model = check_str($_POST["device_model"]);
$device_firmware_version = check_str($_POST["device_firmware_version"]);
$device_provision_enable = check_str($_POST["device_provision_enable"]);
$device_template = check_str($_POST["device_template"]);
$device_username = check_str($_POST["device_username"]);
$device_password = check_str($_POST["device_password"]);
$device_time_zone = check_str($_POST["device_time_zone"]);
$device_description = check_str($_POST["device_description"]);
//devices
$device_mac_address = check_str($_POST["device_mac_address"]);
$device_mac_address = strtolower($device_mac_address);
$device_mac_address = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address);
$device_label = check_str($_POST["device_label"]);
$device_vendor = check_str($_POST["device_vendor"]);
$device_model = check_str($_POST["device_model"]);
$device_firmware_version = check_str($_POST["device_firmware_version"]);
$device_provision_enable = check_str($_POST["device_provision_enable"]);
$device_template = check_str($_POST["device_template"]);
$device_username = check_str($_POST["device_username"]);
$device_password = check_str($_POST["device_password"]);
$device_time_zone = check_str($_POST["device_time_zone"]);
$device_description = check_str($_POST["device_description"]);
//lines
$line_number = check_str($_POST["line_number"]);
$server_address = check_str($_POST["server_address"]);
$outbound_proxy = check_str($_POST["outbound_proxy"]);
$display_name = check_str($_POST["display_name"]);
$user_id = check_str($_POST["user_id"]);
$auth_id = check_str($_POST["auth_id"]);
$password = check_str($_POST["password"]);
}
//use the mac address to find the vendor
@@ -121,7 +130,7 @@ require_once "includes/require.php";
//if (strlen($device_password) == 0) { $msg .= "Please provide: Password<br>\n"; }
//if (strlen($device_time_zone) == 0) { $msg .= "Please provide: Time Zone<br>\n"; }
//if (strlen($device_description) == 0) { $msg .= "Please provide: Description<br>\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
if (strlen($msg) > 0) {
require_once "includes/header.php";
require_once "includes/persistformvar.php";
echo "<div align='center'>\n";
@@ -137,8 +146,10 @@ require_once "includes/require.php";
//add or update the database
if ($_POST["persistformvar"] != "true") {
if ($action == "add" && permission_exists('device_add')) {
//sql add
//set the device_uuid
$device_uuid = uuid();
//add device
$sql = "insert into v_devices ";
$sql .= "(";
$sql .= "domain_uuid, ";
@@ -173,22 +184,10 @@ require_once "includes/require.php";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
//write the provision files
require_once "app/provision/provision_write.php";
//redirect the user
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=devices.php\">\n";
echo "<div align='center'>\n";
echo $text['message-add']."\n";
echo "</div>\n";
require_once "includes/footer.php";
return;
} //if ($action == "add")
if ($action == "update" && permission_exists('device_edit')) {
//sql update
//update the device
if ($action == "update" && permission_exists('device_edit')) {
$sql = "update v_devices set ";
$sql .= "device_mac_address = '$device_mac_address', ";
$sql .= "device_label = '$device_label', ";
@@ -205,19 +204,51 @@ require_once "includes/require.php";
$sql .= "and device_uuid = '$device_uuid'";
$db->exec(check_sql($sql));
unset($sql);
}
//write the provision files
require_once "app/provision/provision_write.php";
//add line to the device
if (strlen($user_id) > 0 && permission_exists('device_add')) {
$sql = "insert into v_device_lines ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "device_line_uuid, ";
$sql .= "device_uuid, ";
$sql .= "line_number, ";
$sql .= "server_address, ";
$sql .= "outbound_proxy, ";
$sql .= "display_name, ";
$sql .= "user_id, ";
$sql .= "auth_id, ";
$sql .= "password ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$domain_uuid', ";
$sql .= "'".uuid()."', ";
$sql .= "'$device_uuid', ";
$sql .= "'$line_number', ";
$sql .= "'$server_address', ";
$sql .= "'$outbound_proxy', ";
$sql .= "'$display_name', ";
$sql .= "'$user_id', ";
$sql .= "'$auth_id', ";
$sql .= "'$password' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
//redirect the user
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=devices.php\">\n";
echo "<div align='center'>\n";
echo $text['message-update']."\n";
echo "</div>\n";
require_once "includes/footer.php";
return;
}
//write the provision files
require_once "app/provision/provision_write.php";
//redirect the user
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=devices.php\">\n";
echo "<div align='center'>\n";
echo $text['message-add']."\n";
echo "</div>\n";
require_once "includes/footer.php";
return;
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
@@ -293,6 +324,161 @@ require_once "includes/require.php";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-device_template'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo "<select id='device_template' name='device_template' class='formfld'>\n";
echo "<option value=''></option>\n";
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/".$_SESSION["domain_name"])) {
$temp_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/".$_SESSION["domain_name"];
} else {
$temp_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
}
if($dh = opendir($temp_dir)) {
while($dir = readdir($dh)) {
if($file != "." && $dir != ".." && $dir[0] != '.') {
if(is_dir($temp_dir . "/" . $dir)) {
echo "<optgroup label='$dir'>";
if($dh_sub = opendir($temp_dir.'/'.$dir)) {
while($dir_sub = readdir($dh_sub)) {
if($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') {
if(is_dir($temp_dir . '/' . $dir .'/'. $dir_sub)) {
if ($device_template == $dir."/".$dir_sub) {
echo "<option value='".$dir."/".$dir_sub."' selected='selected'>".$dir."/".$dir_sub."</option>\n";
}
else {
echo "<option value='".$dir."/".$dir_sub."'>".$dir."/".$dir_sub."</option>\n";
}
}
}
}
closedir($dh_sub);
}
echo "</optgroup>";
}
}
}
closedir($dh);
}
echo "</select>\n";
echo "<br />\n";
echo $text['description-device_template']."\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>";
echo " <td class='vncell' valign='top'>".$text['label-lines'].":</td>";
echo " <td class='vtable' align='left'>";
if ($action == "update") {
echo " <table width='52%' border='0' cellpadding='0' cellspacing='0'>\n";
$sql = "SELECT * FROM v_device_lines ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "order by line_number asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
echo "<tr>\n";
echo " <td class='vtable'>".$text['label-line']."</td>\n";
echo " <td class='vtable'>".$text['label-server_address']."</td>\n";
echo " <td class='vtable'>".$text['label-outbound_proxy']."</td>\n";
echo " <td class='vtable'>".$text['label-display_name']."</td>\n";
echo " <td class='vtable'>".$text['label-user_id']."</td>\n";
echo " <td class='vtable'>".$text['label-auth_id']."</td>\n";
echo " <td class='vtable'>".$text['label-password']."</td>\n";
echo " <td></td>\n";
echo "</tr>\n";
foreach($result as $row) {
//if (strlen($row['line_number']) == 0) { $row['line_number'] = "1"; }
echo " <tr>\n";
echo " <td class='vtable'>\n";
echo " ".$row['line_number']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['server_address']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['outbound_proxy']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['display_name']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['user_id']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['auth_id']."&nbsp;\n";
echo " </td>\n";
echo " <td class='vtable'>\n";
echo " ".$row['password']."&nbsp;\n";
echo " </td>\n";
echo " <td>\n";
if (permission_exists('device_edit')) {
echo " <a href='device_line_edit.php?device_uuid=".$row['device_uuid']."&id=".$row['device_line_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>\n";
}
if (permission_exists('device_delete')) {
echo " <a href='device_line_delete.php?device_uuid=".$row['device_uuid']."&id=".$row['device_line_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>\n";
} echo " </td>\n";
echo " </tr>\n";
}
echo " <tr>\n";
echo " <td class='vtable' valign='top' align='left' nowrap='nowrap'>\n";
echo " <select class='formfld' style='width: 45px;' name='line_number'>\n";
echo " <option value=''></option>\n";
echo " <option value='1'>1</option>\n";
echo " <option value='2'>2</option>\n";
echo " <option value='3'>3</option>\n";
echo " <option value='4'>4</option>\n";
echo " <option value='5'>5</option>\n";
echo " <option value='6'>6</option>\n";
echo " <option value='7'>7</option>\n";
echo " <option value='8'>8</option>\n";
echo " <option value='9'>9</option>\n";
echo " <option value='10'>10</option>\n";
echo " <option value='11'>11</option>\n";
echo " <option value='12'>12</option>\n";
echo " </select>\n";
echo " </td>\n";
echo " <td class='vtable' valign='top' align='left' nowrap='nowrap'>\n";
echo " <input class='formfld' style='width: 125px;' type='text' name='server_address' maxlength='255' value=\"$server_address\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 125px;' type='text' name='outbound_proxy' maxlength='255' value=\"$outbound_proxy\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 95px;' type='text' name='display_name' maxlength='255' value=\"$display_name\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 75px;' type='text' name='user_id' maxlength='255' value=\"$user_id\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 75px;' type='text' name='auth_id' maxlength='255' value=\"$auth_id\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input class='formfld' style='width: 90px;' type='text' name='password' maxlength='255' value=\"$password\">\n";
echo " </td>\n";
echo " <td class='vtable' align='left'>\n";
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
}
echo " <br>\n";
echo " ".$text['description-extensions']."\n";
echo " <br />\n";
echo " </td>";
echo " </tr>";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-extension'].":\n";
@@ -436,7 +622,6 @@ require_once "includes/require.php";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-device_vendor'].":\n";

View File

@@ -0,0 +1,67 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2013 All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
require_once "root.php";
require_once "includes/require.php";
require_once "includes/checkauth.php";
if (permission_exists('device_delete')) {
//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']];
}
//get the id
if (count($_GET)>0) {
$id = check_str($_GET["id"]);
$device_uuid = check_str($_GET["device_uuid"]);
}
if (strlen($id)>0) {
//delete device_line
$sql = "delete from v_device_lines ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and device_line_uuid = '$id' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
unset($sql);
}
//redirect the user
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=device_edit.php?id=$device_uuid\">\n";
echo "<div align='center'>\n";
echo $text['message-delete']."\n";
echo "</div>\n";
require_once "includes/footer.php";
return;
?>

View File

@@ -0,0 +1,315 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2013 All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
require_once "root.php";
require_once "includes/require.php";
require_once "includes/checkauth.php";
if (permission_exists('device_add') || permission_exists('device_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']];
}
//action add or update
if (isset($_REQUEST["id"])) {
$action = "update";
$device_line_uuid = check_str($_REQUEST["id"]);
}
else {
$action = "add";
}
//set the parent uuid
if (strlen($_GET["device_uuid"]) > 0) {
$device_uuid = check_str($_GET["device_uuid"]);
}
//get http post variables and set them to php variables
if (count($_POST)>0) {
$line_number = check_str($_POST["line_number"]);
$server_address = check_str($_POST["server_address"]);
$outbound_proxy = check_str($_POST["outbound_proxy"]);
$display_name = check_str($_POST["display_name"]);
$user_id = check_str($_POST["user_id"]);
$auth_id = check_str($_POST["auth_id"]);
$password = check_str($_POST["password"]);
}
if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$msg = '';
if ($action == "update") {
$device_line_uuid = check_str($_POST["device_line_uuid"]);
}
//check for all required data
//if (strlen($line_number) == 0) { $msg .= $text['message-required']." ".$text['label-line_number']."<br>\n"; }
//if (strlen($server_address) == 0) { $msg .= $text['message-required']." ".$text['label-server_address']."<br>\n"; }
//if (strlen($outbound_proxy) == 0) { $msg .= $text['message-required']." ".$text['label-outbound_proxy']."<br>\n"; }
//if (strlen($display_name) == 0) { $msg .= $text['message-required']." ".$text['label-display_name']."<br>\n"; }
//if (strlen($user_id) == 0) { $msg .= $text['message-required']." ".$text['label-user_id']."<br>\n"; }
//if (strlen($auth_id) == 0) { $msg .= $text['message-required']." ".$text['label-auth_id']."<br>\n"; }
//if (strlen($password) == 0) { $msg .= $text['message-required']." ".$text['label-password']."<br>\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "includes/header.php";
require_once "includes/persistformvar.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\n";
require_once "includes/footer.php";
return;
}
//add or update the database
if ($_POST["persistformvar"] != "true") {
//add the line
if ($action == "add" && permission_exists('device_add')) {
$sql = "insert into v_device_lines ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "device_line_uuid, ";
$sql .= "device_uuid, ";
$sql .= "line_number, ";
$sql .= "server_address, ";
$sql .= "outbound_proxy, ";
$sql .= "display_name, ";
$sql .= "user_id, ";
$sql .= "auth_id, ";
$sql .= "password ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$domain_uuid', ";
$sql .= "'".uuid()."', ";
$sql .= "'$device_uuid', ";
$sql .= "'$line_number', ";
$sql .= "'$server_address', ";
$sql .= "'$outbound_proxy', ";
$sql .= "'$display_name', ";
$sql .= "'$user_id', ";
$sql .= "'$auth_id', ";
$sql .= "'$password' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
} //if ($action == "add")
//update the line
if ($action == "update" && permission_exists('device_edit')) {
$sql = "update v_device_lines set ";
$sql .= "device_uuid = '$device_uuid', ";
$sql .= "line_number = '$line_number', ";
$sql .= "server_address = '$server_address', ";
$sql .= "outbound_proxy = '$outbound_proxy', ";
$sql .= "display_name = '$display_name', ";
$sql .= "user_id = '$user_id', ";
$sql .= "auth_id = '$auth_id', ";
$sql .= "password = '$password' ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and device_line_uuid = '$device_line_uuid' ";
$db->exec(check_sql($sql));
unset($sql);
} //if ($action == "update")
//redirect the browser
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=device_edit.php?id=$device_uuid\">\n";
echo "<div align='center'>\n";
if ($action == "add") {
echo " ".$text['message-add']."\n";
}
if ($action == "update") {
echo " ".$text['message-update']."\n";
}
echo "</div>\n";
require_once "includes/footer.php";
return;
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
//pre-populate the form
if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
$device_line_uuid = check_str($_GET["id"]);
$sql = "select * from v_device_lines ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and device_line_uuid = '$device_line_uuid' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$line_number = $row["line_number"];
$server_address = $row["server_address"];
$outbound_proxy = $row["outbound_proxy"];
$display_name = $row["display_name"];
$user_id = $row["user_id"];
$auth_id = $row["auth_id"];
$password = $row["password"];
}
unset ($prep_statement);
}
//show the header
require_once "includes/header.php";
//show the content
echo "<div align='center'>";
echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
echo "<tr class='border'>\n";
echo " <td align=\"left\">\n";
echo " <br>";
echo "<form method='post' name='frm' action=''>\n";
echo "<div align='center'>\n";
echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td align='left' width='30%' nowrap='nowrap'><b>".$text['title-device_line']."</b></td>\n";
echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='device_edit.php?id=$device_uuid'\" value='".$text['button-back']."'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-line_number'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' style='width: 45px;' name='line_number'>\n";
echo " <option value='$line_number' SELECTED='SELECTED'>$line_number</option>\n";
echo " <option value=''></option>\n";
echo " <option value='1'>1</option>\n";
echo " <option value='2'>2</option>\n";
echo " <option value='3'>3</option>\n";
echo " <option value='4'>4</option>\n";
echo " <option value='5'>5</option>\n";
echo " <option value='6'>6</option>\n";
echo " <option value='7'>7</option>\n";
echo " <option value='8'>8</option>\n";
echo " <option value='9'>9</option>\n";
echo " <option value='10'>10</option>\n";
echo " <option value='11'>11</option>\n";
echo " <option value='12'>12</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-line_number']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-server_address'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='server_address' maxlength='255' value=\"$server_address\">\n";
echo "<br />\n";
echo $text['description-server_address']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-outbound_proxy'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='outbound_proxy' maxlength='255' value=\"$outbound_proxy\">\n";
echo "<br />\n";
echo $text['description-outbound_proxy']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-display_name'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='display_name' maxlength='255' value=\"$display_name\">\n";
echo "<br />\n";
echo $text['description-display_name']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-user_id'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='user_id' maxlength='255' value=\"$user_id\">\n";
echo "<br />\n";
echo $text['description-user_id']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-auth_id'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='auth_id' maxlength='255' value=\"$auth_id\">\n";
echo "<br />\n";
echo $text['description-auth_id']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-password'].":\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='password' maxlength='255' value=\"$password\">\n";
echo "<br />\n";
echo $text['description-password']."\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
echo " <input type='hidden' name='device_uuid' value='$device_uuid'>\n";
if ($action == "update") {
echo " <input type='hidden' name='device_line_uuid' value='$device_line_uuid'>\n";
}
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo " </td>\n";
echo " </tr>";
echo "</table>";
echo "</form>";
//if ($action == "update") {
// require "device_keys.php";
//}
echo " </td>";
echo " </tr>";
echo "</table>";
echo "</div>";
//include the footer
require_once "includes/footer.php";
?>