Portions created by the Initial Developer are Copyright (C) 2018-2024 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('destination_import')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher if(!function_exists('str_getcsv')) { function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { $fp = fopen("php://memory", 'r+'); fputs($fp, $input); rewind($fp); $data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0 fclose($fp); return $data; } } //get the http get values and set them as php variables $action = $_POST["action"] ?? null; $from_row = $_POST["from_row"] ?? null; $delimiter = $_POST["data_delimiter"] ?? null; $enclosure = $_POST["data_enclosure"] ?? null; $destination_type = $_POST["destination_type"] ?? null; $destination_action = $_POST["destination_action"] ?? null; $destination_context = $_POST["destination_context"] ?? null; $destination_record = $_POST["destination_record"] ?? null; //set the defaults if (empty($destination_type)) { $destination_type = 'inbound'; } if (empty($destination_context)) { $destination_context = 'public'; } if ($destination_type =="outbound" && $destination_context == "public") { $destination_context = $_SESSION['domain_name']; } if ($destination_type =="outbound" && empty($destination_context)) { $destination_context = $_SESSION['domain_name']; } if (empty($from_row)) { $from_row = '2'; } //save the data to the csv file if (isset($_POST['data'])) { $file = $_SESSION['server']['temp']['dir']."/destinations-".$_SESSION['domain_name'].".csv"; file_put_contents($file, $_POST['data']); $_SESSION['file'] = $file; $_SESSION['file_name'] = $_FILES['ulfile']['name']; } //copy the csv file //$_POST['submit'] == "Upload" && if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('destination_upload')) { if ($_POST['type'] == 'csv') { move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']); $save_msg = "Uploaded file to ".$_SESSION['server']['temp']['dir']."/". htmlentities($_FILES['ulfile']['name']); //system('chmod -R 744 '.$_SESSION['server']['temp']['dir'].'*'); unset($_POST['txtCommand']); $file = $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']; $_SESSION['file'] = $file; } } //get the schema if (!empty($delimiter)) { //get the first line $line = fgets(fopen($_SESSION['file'], 'r')); $line_fields = explode($delimiter, $line); //get the schema $x = 0; include "app/destinations/app_config.php"; $i = 0; foreach ($apps[0]['db'] as $table) { //get the table name and parent name $table_name = $table["table"]['name']; $parent_name = $table["table"]['parent']; //remove the v_ table prefix if (substr($table_name, 0, 2) == 'v_') { $table_name = substr($table_name, 2); } if (substr($parent_name, 0, 2) == 'v_') { $parent_name = substr($parent_name, 2); } //filter for specific tables and build the schema array if ($table_name == "destinations") { $schema[$i]['table'] = $table_name; $schema[$i]['parent'] = $parent_name; foreach ($table['fields'] as $row) { if (empty($row['deprecated']) || (!empty($row['deprecated']) && $row['deprecated'] !== 'true')) { if (is_array($row['name'])) { $field_name = $row['name']['text']; } else { $field_name = $row['name']; } $schema[$i]['fields'][] = $field_name; } } $i++; } } } //get the parent table function get_parent($schema,$table_name) { foreach ($schema as $row) { if ($row['table'] == $table_name) { return $row['parent']; } } } //upload the destination csv if (file_exists($_SESSION['file'] ?? '') && $action == 'add') { //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: destination_imports.php'); exit; } //user selected fields $fields = $_POST['fields']; $domain_uuid = $_POST['domain_uuid']; $destination_record = $_POST['destination_record']; $destination_type = $_POST['destination_type']; $destination_context = $_POST['destination_context']; $destination_enabled = $_POST['destination_enabled']; //set the domain_uuid $domain_uuid = $_SESSION['domain_uuid']; //get the contents of the csv file and convert them into an array $handle = @fopen($_SESSION['file'], "r"); if ($handle) { //pre-set the numbers $row_id = 0; $row_number = 1; //loop through the array while (($line = fgets($handle, 4096)) !== false) { if ($from_row <= $row_number) { //format the data $y = 0; foreach ($fields as $key => $value) { //get the line $result = str_getcsv($line, $delimiter, $enclosure); //get the table and field name $field_array = explode(".",$value); $table_name = $field_array[0] ?? null; $field_name = $field_array[1] ?? null; //get the parent table name $parent = get_parent($schema, $table_name); //remove formatting from the phone number if ($field_name == "phone_number") { $result[$key] = preg_replace('{\D}', '', $result[$key]); } //build the data array if (!empty($table_name)) { if (empty($parent)) { $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; $array[$table_name][$row_id][$field_name] = $result[$key]; } else { $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; } } //get the destination_number if ($key === 'destination_number') { $destination_number = $result[$key]; } if ($key === 'destination_description') { $destination_description = $result[$key]; } if ($key === 'destination_app') { $destination_app = $result[$key]; echo "destination_app $destination_app\n"; } if ($key === 'destination_data') { $destination_data = $result[$key]; echo "destination_data $destination_data\n"; } } //add the actions foreach ($array['destinations'] as $row) { //build the array if (!empty($row['destination_actions']) && is_json($row['destination_actions'])) { $destination_actions = $row['destination_actions']; // use json actions $temp = json_decode($row['destination_actions'], true); $row['destination_app'] = $temp[array_key_last($temp)]['destination_app']; $row['destination_data'] = $temp[array_key_last($temp)]['destination_data']; unset($temp); } else if (!empty($row['destination_app']) && !empty($row['destination_data'])) { $actions[0]['destination_app'] = $row['destination_app']; $actions[0]['destination_data'] = $row['destination_data']; $destination_actions = json_encode($actions); unset($actions); } //get the values $destination_number = $row['destination_number']; $destination_app = $row['destination_app']; $destination_data = $row['destination_data']; $destination_prefix = $row['destination_prefix']; $destination_accountcode = $row['destination_accountcode']; $destination_cid_name_prefix = $row['destination_cid_name_prefix']; $destination_description = $row['destination_description']; //convert the number to a regular expression if (isset($destination_prefix) && !empty($destination_prefix)) { $destination_number_regex = string_to_regex($destination_number, $destination_prefix); } else { $destination_number_regex = string_to_regex($destination_number); } //add the additional fields $dialplan_uuid = uuid(); $array["destinations"][$row_id]['destination_actions'] = $destination_actions; $array["destinations"][$row_id]['destination_app'] = $destination_app; $array["destinations"][$row_id]['destination_data'] = $destination_data; $array["destinations"][$row_id]['destination_type'] = $destination_type; $array["destinations"][$row_id]['destination_record'] = $destination_record; $array["destinations"][$row_id]['destination_context'] = $destination_context; $array["destinations"][$row_id]['destination_number_regex'] = $destination_number_regex; $array["destinations"][$row_id]['destination_enabled'] = $destination_enabled; $array["destinations"][$row_id]['dialplan_uuid'] = $dialplan_uuid; //build the dialplan array $array["dialplans"][$row_id]["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4"; $array["dialplans"][$row_id]["dialplan_uuid"] = $dialplan_uuid; $array["dialplans"][$row_id]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_name"] = !empty($dialplan_name) ? $dialplan_name : format_phone($destination_number); $array["dialplans"][$row_id]["dialplan_number"] = $destination_number; $array["dialplans"][$row_id]["dialplan_context"] = $destination_context; $array["dialplans"][$row_id]["dialplan_continue"] = "false"; $array["dialplans"][$row_id]["dialplan_order"] = "100"; $array["dialplans"][$row_id]["dialplan_enabled"] = $destination_enabled; $array["dialplans"][$row_id]["dialplan_description"] = $destination_description; $dialplan_detail_order = 10; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; //set the dialplan detail type if (!empty($_SESSION['dialplan']['destination']['text'])) { $dialplan_detail_type = $_SESSION['dialplan']['destination']['text']; } else { $dialplan_detail_type = "destination_number"; } //authorized specific dialplan_detail_type that are safe, sanitize all other values switch ($dialplan_detail_type) { case 'destination_number': break; case '${sip_to_user}': break; case '${sip_req_user}': break; default: $dialplan_detail_type = xml::sanitize($dialplan_detail_type); } //build the xml dialplan $array["dialplans"][$row_id]["dialplan_xml"] = "\n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; if (!empty($destination_cid_name_prefix)) { $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; } if (!empty($destination_record)) { $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; } if (!empty($destination_accountcode)) { $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; } if (!empty($destination_carrier)) { $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; } if (!empty($fax_uuid)) { $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; } if (!empty($destination_data) && $destination_app == 'bridge') { $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; } $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; $array["dialplans"][$row_id]["dialplan_xml"] .= "\n"; //dialplan details if (filter_var($_SESSION['destinations']['dialplan_details']['boolean'] ?? false, FILTER_VALIDATE_BOOL)) { //check the destination number $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; if (!empty($_SESSION['dialplan']['destination']['text'])) { $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = $_SESSION['dialplan']['destination']['text']; } else { $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number"; } $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = $destination_number_regex; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; //set the caller id name prefix if (!empty($destination_cid_name_prefix)) { $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "effective_caller_id_name=".$destination_cid_name_prefix."#\${caller_id_name}"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; } //enable call recordings if ($destination_record == "true") { $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "answer"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = ""; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "record_path=\${recordings_dir}/\${domain_name}/archive/\${strftime(%Y)}/\${strftime(%b)}/\${strftime(%d)}"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "record_name=\${uuid}.\${record_ext}"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; //add a variable $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "recording_follow_transfer=true"; $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "record_session"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "\${record_path}/\${record_name}"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "false"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; } //set the call accountcode if (!empty($destination_accountcode)) { $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "accountcode=".$destination_accountcode; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; } //add hangup_after_bridge and continue_on_fail if (!empty($destination_data) && $destination_app == 'bridge') { $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "hangup_after_bridge=true"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "continue_on_fail=true"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; } //set the destination app and data if (strlen($destination_app) > 0 && !empty($destination_data)) { $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = $destination_app; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = $destination_data; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; //set inline to true if (!empty($action_app) && ($action_app == 'set' || $action_app == 'export')) { $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; } //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; } //set the detail id back to 0 $y = 0; } //end if } //foreach //process a chunk of the array if ($row_id === 1000) { //save to the data $database = new database; $database->app_name = 'destinations'; $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; $database->save($array); //$message = $database->message; //clear the array unset($array); //set the row id back to 0 $row_id = 0; } } $row_number++; $row_id++; } fclose($handle); //save to the data if (!empty($array) && is_array($array)) { $database = new database; $database->app_name = 'destinations'; $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; $database->save($array); $message = $database->message; } } //send the redirect header header("Location: destinations.php?type=".$destination_type); exit; } //upload the destination csv if (file_exists($_SESSION['file'] ?? '') && $action == 'delete') { //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: destination_imports.php'); exit; } //user selected fields $fields = $_POST['fields']; $domain_uuid = $_POST['domain_uuid']; $destination_type = $_POST['destination_type']; $destination_context = $_POST['destination_context']; $destination_enabled = $_POST['destination_enabled']; //set the domain_uuid $domain_uuid = $_SESSION['domain_uuid']; //get the contents of the csv file and convert them into an array $handle = @fopen($_SESSION['file'], "r"); if ($handle) { //set the starting identifiers $row_id = 0; $dialplan_id = 0; $row_number = 1; //loop through the array while (($line = fgets($handle, 4096)) !== false) { if ($from_row <= $row_number) { //format the data $y = 0; foreach ($fields as $key => $value) { //get the line $result = str_getcsv($line, $delimiter, $enclosure); //get the table and field name $field_array = explode(".",$value); $table_name = $field_array[0]; $field_name = $field_array[1]; //get the parent table name $parent = get_parent($schema, $table_name); //remove formatting from the phone number if ($field_name == "phone_number") { $result[$key] = preg_replace('{\D}', '', $result[$key]); } //build the data array if (!empty($table_name)) { if (empty($parent)) { $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; $array[$table_name][$row_id][$field_name] = $result[$key]; } else { $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; } } //get the destination_number if ($key === 'destination_number') { $destination_number = $result[$key]; } if ($key === 'destination_uuid') { $destination_uuid = $result[$key]; } if ($key === 'dialplan_uuid') { $destination_uuid = $result[$key]; } } //delete the destinations foreach ($array['destinations'] as $row) { //get the values $domain_uuid = $row['domain_uuid']; $destination_number = $row['destination_number']; //get the dialplan uuid if (empty($row['destination_number']) || !is_uuid($row['dialplan_uuid'])) { $sql = "select * from v_destinations "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and destination_number = :destination_number; "; $parameters['domain_uuid'] = $domain_uuid; $parameters['destination_number'] = $destination_number; $database = new database; $destinations = $database->select($sql, $parameters, 'all'); $row = $destinations[0]; unset($sql, $parameters); //add to the array //$array['destinations'][$row_id] = $destinations[0]; $array['destinations'][$row_id]['destination_uuid'] = $destinations[0]['destination_uuid']; if (!empty($row['dialplan_uuid'])) { $array['destinations'][$row_id]['dialplan_uuid'] = $destinations[0]['dialplan_uuid']; //$array['dialplans'][$row_id]['dialplan_uuid'] = $destinations[0]['dialplan_uuid']; } } } } $row_number++; //process a chunk of the array if ($row_id === 1000) { //delete the destinations $row_number = 0; foreach ($array['destinations'] as $row) { //delete the dialplan if (is_uuid($row['dialplan_uuid'])) { $sql = "delete from v_dialplan_details "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $parameters['dialplan_uuid'] = $row['dialplan_uuid']; $database = new database; $database->execute($sql, $parameters); unset($sql, $parameters); $sql = "delete from v_dialplans "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $parameters['dialplan_uuid'] = $row['dialplan_uuid']; $database = new database; $database->execute($sql, $parameters); unset($sql, $parameters); } //delete the destinations if (is_uuid($row['destination_uuid'])) { $sql = "delete from v_destinations "; $sql .= "where destination_uuid = :destination_uuid "; $parameters['destination_uuid'] = $row['destination_uuid']; $database = new database; $database->execute($sql, $parameters); unset($sql, $parameters); } } //clear the array unset($array); //set the row id back to 0 $row_id = 0; } //increment row id $row_id++; } fclose($handle); //delete the remaining destinations if ($row_id < 1000) { foreach ($array['destinations'] as $row) { //delete the dialplan if (is_uuid($row['dialplan_uuid'])) { $sql = "delete from v_dialplan_details "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $parameters['dialplan_uuid'] = $row['dialplan_uuid']; $database = new database; $database->execute($sql, $parameters); unset($sql, $parameters); $sql = "delete from v_dialplans "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $parameters['dialplan_uuid'] = $row['dialplan_uuid']; $database = new database; $database->execute($sql, $parameters); unset($sql, $parameters); } //delete the destinations if (is_uuid($row['destination_uuid'])) { $sql = "delete from v_destinations "; $sql .= "where destination_uuid = :destination_uuid "; $parameters['destination_uuid'] = $row['destination_uuid']; $database = new database; $database->execute($sql, $parameters); unset($sql, $parameters); } } } //set response message::add($text['message-delete'], 'positive'); //send the redirect header header("Location: /app/destinations/destinations.php?type=".$destination_type); exit; } } //match the column names to the field names if (!empty($delimiter) && file_exists($_SESSION['file']) && ($action !== 'add' or $action !== 'delete')) { //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-destination_import']; require_once "resources/header.php"; //form to match the fields to the column names echo "
\n"; echo "
\n"; echo "
".$text['header-destination_import']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'destination_imports.php']); echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']); echo "
\n"; echo "
\n"; echo "
\n"; echo $text['description-destination_import']."\n"; echo "

\n"; echo "
\n"; echo "\n"; if (isset($_SESSION['file_name']) && !empty($_SESSION['file_name'])) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } //loop through user columns $x = 0; foreach ($line_fields as $line_field) { $line_field = preg_replace('#[^a-zA-Z0-9_]#', '', $line_field); echo "\n"; echo " \n"; echo " \n"; echo "\n"; $x++; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; //if (permission_exists('destination_context')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; //} echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('destination_domain')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } else { echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-file_name']."\n"; echo "\n"; echo " ".$_SESSION['file_name']."\n"; echo "
\n"; //echo $text['description-file_name']."\n"; echo "
\n"; echo $line_field; echo " \n"; echo " \n"; //echo "
\n"; //echo $text['description-zzz']."\n"; echo "
\n"; echo " ".$text['label-destination_type']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-destination_type']."\n"; echo "
\n"; echo " ".$text['label-destination_record']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo ($text['description-destination_record'] ?? null)."\n"; echo "
\n"; echo " ".$text['label-destination_context']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-destination_context']."\n"; echo "
\n"; echo " ".$text['label-actions']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo ($text['description-actions'] ?? null)."\n"; echo "
\n"; echo " ".$text['label-domain']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-domain_name']."\n"; echo "
\n"; echo " ".$text['label-destination_enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo ($text['description-destination_enabled'] ?? null)."\n"; echo "
\n"; echo "
\n"; echo "

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; require_once "resources/footer.php"; //normalize the column names //$line = strtolower($line); //$line = str_replace("-", "_", $line); //$line = str_replace($delimiter."title".$delimiter, $delimiter."destination_title".$delimiter, $line); //$line = str_replace("firstname", "name_given", $line); //$line = str_replace("lastname", "name_family", $line); //$line = str_replace("company", "organization", $line); //$line = str_replace("company", "destination_email", $line); //end the script exit; } //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-destination_import']; require_once "resources/header.php"; //show the content echo "
\n"; echo "
\n"; echo "
".$text['header-destination_import']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'destinations.php']); echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']); echo "
\n"; echo "
\n"; echo "
\n"; echo $text['description-destination_import']."\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 (permission_exists('destination_upload')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "
\n"; echo " ".$text['label-import_data']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-import_data']."\n"; echo "
\n"; echo " ".$text['label-from_row']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-from_row']."\n"; echo "
\n"; echo " ".$text['label-import_delimiter']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-import_delimiter']."\n"; echo "
\n"; echo " ".$text['label-import_enclosure']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-import_enclosure']."\n"; echo "
\n"; echo " ".$text['label-import_file_upload']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo ($text['description-import_file_upload'] ?? null)."\n"; echo "
\n"; echo "
\n"; echo "

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