diff --git a/app/extensions/extension_edit.php b/app/extensions/extension_edit.php index 1db5eeab16..e55d5c7ead 100644 --- a/app/extensions/extension_edit.php +++ b/app/extensions/extension_edit.php @@ -79,7 +79,7 @@ $number_alias = $_POST["number_alias"]; $password = $_POST["password"]; - // server verification on account code + //server verification on account code $accountcode = $_POST["accountcode"]; $effective_caller_id_name = $_POST["effective_caller_id_name"]; @@ -94,8 +94,8 @@ $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"]; + //$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"]; @@ -132,8 +132,38 @@ $voicemail_id = null; } - //change toll allow delimiter + //change toll allow delimiter $toll_allow = str_replace(',',':', $toll_allow); + + //set assigned user variables + $user_uuid = $_POST["extension_users"][0]["user_uuid"]; + + //device provisioning variables + if (is_array($_POST["devices"]) && @sizeof($_POST["devices"]) != 0) { + foreach ($_POST["devices"] as $d => $device) { + $line_numbers[$d] = $device["line_number"]; + $device_mac_addresses[$d] = format_mac($device["device_mac_address"],''); + $device_templates[$d] = $device["device_template"]; + } + } + + //get or set the device_uuid + if (is_array($device_mac_addresses) && @sizeof($device_mac_addresses) != 0) { + foreach ($device_mac_addresses as $d => $device_mac_address) { + if (is_mac($device_mac_address)) { + $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; + $device_uuid = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + } + $device_uuids[$d] = is_uuid($device_uuid) ? $device_uuid : uuid(); + } + } + } //delete the user from the v_extension_users @@ -152,9 +182,14 @@ $database->app_name = 'extensions'; $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; $database->delete($array); + view_array($array, false); + view_array($database->message, false); unset($array); $p->delete('extension_user_delete', 'temp'); + //redirect + header("Location: extension_edit.php?id=".$extension_uuid); + exit; } //delete the line from the v_device_lines @@ -175,6 +210,9 @@ unset($array); $p->delete('device_line_delete', 'temp'); + //redirect + header("Location: extension_edit.php?id=".$extension_uuid); + exit; } } @@ -270,6 +308,7 @@ //build the data array if (!isset($range)) { $range = 1; } + $j = 0; for ($i=0; $i<$range; $i++) { //check if the extension exists @@ -390,13 +429,45 @@ $array["extensions"][$i]["description"] = $description; //assign the user to the extension - if (is_uuid($_POST["extension_users"][0]["user_uuid"])) { + if (is_uuid($user_uuid)) { $array["extension_users"][$i]["extension_user_uuid"] = uuid(); $array["extension_users"][$i]["domain_uuid"] = $_SESSION['domain_uuid']; - $array["extension_users"][$i]["user_uuid"] = $_POST["extension_users"][0]["user_uuid"]; + $array["extension_users"][$i]["user_uuid"] = $user_uuid; $array["extension_users"][$i]["extension_uuid"] = $extension_uuid; } + //assign the device to the extension(s) + if (is_array($device_mac_addresses) && @sizeof($device_mac_addresses) != 0) { + foreach ($device_mac_addresses as $d => $device_mac_address) { + if (is_mac($device_mac_address)) { + $array["devices"][$j]["device_uuid"] = $device_uuids[$d]; + $array["devices"][$j]["domain_uuid"] = $_SESSION['domain_uuid']; + $array["devices"][$j]["device_mac_address"] = $device_mac_address; + $array["devices"][$j]["device_label"] = $extension; + if (strlen($device_templates[$d]) > 0) { + $array["devices"][$j]["device_template"] = $device_templates[$d]; + } + $array["devices"][$j]["device_enabled"] = "true"; + $array["devices"][$j]["device_lines"][0]["device_uuid"] = $device_uuids[$d]; + $array["devices"][$j]["device_lines"][0]["device_line_uuid"] = uuid(); + $array["devices"][$j]["device_lines"][0]["domain_uuid"] = $_SESSION['domain_uuid']; + $array["devices"][$j]["device_lines"][0]["server_address"] = $_SESSION['domain_name']; + $array["devices"][$j]["device_lines"][0]["outbound_proxy_primary"] = $_SESSION['provision']['outbound_proxy_primary']['text']; + $array["devices"][$j]["device_lines"][0]["outbound_proxy_secondary"] = $_SESSION['provision']['outbound_proxy_secondary']['text']; + $array["devices"][$j]["device_lines"][0]["display_name"] = strlen($effective_caller_id_name) > 0 ? $effective_caller_id_name : $extension; + $array["devices"][$j]["device_lines"][0]["user_id"] = $extension; + $array["devices"][$j]["device_lines"][0]["auth_id"] = $extension; + $array["devices"][$j]["device_lines"][0]["password"] = $password; + $array["devices"][$j]["device_lines"][0]["line_number"] = is_numeric($line_numbers[$d]) ? $line_numbers[$d] : '1'; + $array["devices"][$j]["device_lines"][0]["sip_port"] = $_SESSION['provision']['line_sip_port']['numeric']; + $array["devices"][$j]["device_lines"][0]["sip_transport"] = $_SESSION['provision']['line_sip_transport']['text']; + $array["devices"][$j]["device_lines"][0]["register_expires"] = $_SESSION['provision']['line_register_expires']['numeric']; + $array["devices"][$j]["device_lines"][0]["enabled"] = "true"; + $j++; + } + } + } + } //add or update voicemail @@ -496,70 +567,6 @@ unset($sql, $parameters); } - //assign the user to an existing 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'; @@ -908,7 +915,7 @@ if ($action == "add") { echo "\n"; - echo "\n"; + echo "\n"; echo " ".$text['label-range']."\n"; echo "\n"; echo "\n"; @@ -1008,7 +1015,7 @@ echo "\n"; } - if (permission_exists('device_edit') && $action == "update") { + if (permission_exists('device_edit')) { if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/devices')) { echo "\n"; echo "\n"; @@ -1016,7 +1023,7 @@ echo "\n"; echo "\n"; echo " "; - echo " \n"; + echo "
\n"; echo " \n"; echo " \n"; - echo " \n"; + if ($action == 'update') { + 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 " \n"; + if (is_array($device_lines) && @sizeof($device_lines) != 0) { + echo " \n"; + } + echo " \n"; + + if (is_array($device_lines) && @sizeof($device_lines) != 0) { break; } //show one row when editing extension and no device assigned } - echo "\n"; - echo " \n"; - echo " \n"; echo "
\n"; echo " ".$text['label-line']." \n"; @@ -1027,120 +1034,123 @@ echo " \n"; echo " ".$text['label-device_template']." \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"; + echo " \n"; + //echo " \n"; + echo " \n"; + echo " \n"; } } } - 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"; - } + if ($action == 'update') { + if (is_array($device_lines) && @sizeof($device_lines) != 0) { + foreach ($device_lines as $row) { + $device_mac_address = format_mac($row['device_mac_address']); + echo "
".escape($row['line_number'])."".escape($device_mac_address)."".escape($row['device_template'])." ".$row['device_description']." \n"; + echo " $v_link_label_delete\n"; + echo "
\n"; + for ($d = 0; $d <= 4; $d++) { + echo "
"; + echo " \n"; + echo " "; - $device = new device; - $template_dir = $device->get_template_dir(); - echo ""; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + ?> + + \n"; + echo " \n"; + if (is_array($devices) && @sizeof($devices) != 0) { + foreach ($devices as $field) { + if (strlen($field["device_mac_address"]) > 0) { + $selected = $field_current_value == $field["device_mac_address"] ? "selected='selected'" : null; + echo " \n"; + } + } + } + echo " \n"; + echo " \n"; + echo "
\n"; + + echo "
"; + $device = new device; + $template_dir = $device->get_template_dir(); + echo " \n"; + echo " \n"; + echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add']]); + echo "
\n"; - echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add']]); - echo "
\n"; echo "
\n"; echo $text['description-provisioning']."\n";