Copyright (C) 2013 All Rights Reserved. Contributor(s): Mark J Crane */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists('device_add') || permission_exists('device_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //action add or update if (is_uuid($_REQUEST["id"])) { $action = "update"; $device_line_uuid = $_REQUEST["id"]; } else { $action = "add"; } //set the parent uuid if (is_uuid($_GET["device_uuid"])) { $device_uuid = $_GET["device_uuid"]; } //get http post variables and set them to php variables if (count($_POST)>0) { $line_number = $_POST["line_number"]; $server_address = $_POST["server_address"]; $outbound_proxy = $_POST["outbound_proxy"]; $sip_port = $_POST["sip_port"]; $sip_transport = $_POST["sip_transport"]; $register_expires = $_POST["register_expires"]; $display_name = $_POST["display_name"]; $user_id = $_POST["user_id"]; $auth_id = $_POST["auth_id"]; $password = $_POST["password"]; } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $device_line_uuid = $_POST["device_line_uuid"]; } //check for all required data //if (strlen($line_number) == 0) { $msg .= $text['message-required']." ".$text['label-line_number']."
\n"; } //if (strlen($server_address) == 0) { $msg .= $text['message-required']." ".$text['label-server_address']."
\n"; } //if (strlen($outbound_proxy) == 0) { $msg .= $text['message-required']." ".$text['label-outbound_proxy']."
\n"; } //if (strlen($display_name) == 0) { $msg .= $text['message-required']." ".$text['label-display_name']."
\n"; } //if (strlen($user_id) == 0) { $msg .= $text['message-required']." ".$text['label-user_id']."
\n"; } //if (strlen($auth_id) == 0) { $msg .= $text['message-required']." ".$text['label-auth_id']."
\n"; } //if (strlen($password) == 0) { $msg .= $text['message-required']." ".$text['label-password']."
\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; } //add or update the database if ($_POST["persistformvar"] != "true") { //add the line if ($action == "add" && permission_exists('device_add')) { $array['device_lines'][0]['device_line_uuid'] = uuid(); $array['device_lines'][0]['sip_port'] = $sip_port; $array['device_lines'][0]['register_expires'] = $register_expires; message::add($text['message-add']); } //update the line if ($action == "update" && permission_exists('device_edit')) { $array['device_lines'][0]['device_line_uuid'] = $device_line_uuid; $array['device_lines'][0]['sip_port'] = $sip_port != '' ? $sip_port : null; $array['device_lines'][0]['register_expires'] = $register_expires != '' ? $register_expires : null; message::add($text['message-update']); } //execute if (is_array($array) && @sizeof($array) != 0) { $array['device_lines'][0]['domain_uuid'] = $domain_uuid; $array['device_lines'][0]['device_uuid'] = $device_uuid; $array['device_lines'][0]['line_number'] = $line_number; $array['device_lines'][0]['server_address'] = $server_address; $array['device_lines'][0]['outbound_proxy'] = $outbound_proxy; $array['device_lines'][0]['sip_transport'] = $sip_transport; $array['device_lines'][0]['display_name'] = $display_name; $array['device_lines'][0]['user_id'] = $user_id; $array['device_lines'][0]['auth_id'] = $auth_id; $array['device_lines'][0]['password'] = $password; $database = new database; $database->app_name = 'devices'; $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; $database->save($array); unset($array); } header("Location: device_edit.php?id=".$device_uuid); exit; } } //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $device_line_uuid = $_GET["id"]; $sql = "select * from v_device_lines "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and device_line_uuid = :device_line_uuid "; $parameters['domain_uuid'] = $domain_uuid; $parameters['device_line_uuid'] = $device_line_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $line_number = $row["line_number"]; $server_address = $row["server_address"]; $outbound_proxy = $row["outbound_proxy"]; $sip_port = $row["sip_port"]; $sip_transport = $row["sip_transport"]; $register_expires = $row["register_expires"]; $display_name = $row["display_name"]; $user_id = $row["user_id"]; $auth_id = $row["auth_id"]; $password = $row["password"]; } unset($sql, $parameters, $row); } //show the header require_once "resources/header.php"; //show the content 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"; echo " "; echo "
".$text['title-device_line']."
\n"; echo " ".$text['label-line_number']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-line_number']."\n"; echo "
\n"; echo " ".$text['label-server_address']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-server_address']."\n"; echo "
\n"; echo " ".$text['label-outbound_proxy']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-outbound_proxy']."\n"; echo "
\n"; echo " ".$text['label-display_name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-display_name']."\n"; echo "
\n"; echo " ".$text['label-user_id']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-user_id']."\n"; echo "
\n"; echo " ".$text['label-auth_id']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-auth_id']."\n"; echo "
\n"; echo " ".$text['label-password']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-password']."\n"; echo "
\n"; echo " ".$text['label-sip_port']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-sip_port']."\n"; echo "
\n"; echo " ".$text['label-sip_transport']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-sip_transport']."\n"; echo "
\n"; echo " ".$text['label-register_expires']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-register_expires']."\n"; echo "
\n"; echo " \n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo "
"; echo "

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