$lang["ok"],"text" => $lang["csv_upload_upload_config_set"]); } else { $onload_message = array("title" => $lang["error"],"text" => str_replace("%EXTENSIONS", ".json", $lang["invalidextension_mustbe-extensions"])); $csv_saved_options = ""; } } if (getval("getconfig", "") != "") { header('Content-Type: text/json'); header("Content-Disposition: attachment; filename=csv_upload.json"); echo $csv_saved_options; exit(); } $default_status = get_default_archive_state(); $csv_default_settings = array( "add_to_collection" => 0, "csv_update_col" => 0, "csv_update_col_id" => 0, "update_existing" => 0, "id_column" => "", "id_field" => 0, "id_column_match" => 0, "multiple_match" => 0, "resource_type_column" => "", "resource_type_default" => 0, "status_column" => "", "status_default" => $default_status, "access_column" => "", "access_default" => 0, "fieldmapping" => array(), "csvchecksum" => "", "csv_filename" => "" ); if ($csv_saved_options != "" && getval("resetconfig", "") == "") { $csv_set_options = json_decode($csv_saved_options, true); $existing_config = true; } foreach ($csv_default_settings as $csv_setting => $csv_setting_default) { $setoption = isset($_POST[$csv_setting]) ? $_POST[$csv_setting] : ""; if ($setoption != "") { $csv_set_options[$csv_setting] = $setoption; } elseif (!isset($csv_set_options[$csv_setting])) { $csv_set_options[$csv_setting] = $csv_setting_default; } } $selected_columns = array(); $selected_columns[] = $csv_set_options["resource_type_column"]; $selected_columns[] = $csv_set_options["id_column"]; $selected_columns[] = $csv_set_options["status_column"]; $selected_columns[] = $csv_set_options["access_column"]; $selected_columns = array_filter($selected_columns, "emptyiszero"); $usehash = $session_hash ?? get_rs_session_id(true); $csvdir = get_temp_dir() . DIRECTORY_SEPARATOR . "csv_upload" . DIRECTORY_SEPARATOR . md5($usehash); if (!file_exists($csvdir)) { mkdir($csvdir, 0777, true); } $csvfile = $csvdir . DIRECTORY_SEPARATOR . "csv_upload.csv"; if (isset($_FILES[$fd]) && $_FILES[$fd]['error'] == 0) { $process_file_upload = process_file_upload( $_FILES[$fd], new SplFileInfo($csvfile), [ 'allow_extensions' => ['csv'], 'mime_file_based_detection' => false, ] ); if ($process_file_upload['success']) { // Check if file is valid UTF-8, remove BOM if present $csv_utf_check = csv_check_utf8($csvfile); if ($csv_utf_check['success']) { $csv_set_options['csvchecksum'] = get_checksum($csvfile, true); $csv_set_options['csv_filename'] = $_FILES[$fd]['name']; } else { // File is not valid to process - remove the CSV and the directory created earlier try_unlink($csvfile); rmdir($csvdir); $onload_message = [ 'title' => $lang['error'], 'text' => $csv_utf_check['message'], ]; } } else { $onload_message = [ 'title' => $lang['error'], 'text' => match ($process_file_upload['error']) { ProcessFileUploadErrorCondition::InvalidExtension => str_replace( '%EXTENSIONS', 'csv', $lang['invalidextension_mustbe-extensions'] ), default => $process_file_upload['error']->i18n($lang), }, ]; } } rs_setcookie("saved_csv_options", json_encode($csv_set_options)); $csvuploaded = file_exists($csvfile); $csvstep = $csvuploaded ? getval("csvstep", 1, true) : 1; if ($csvuploaded) { $messages = array(); $csv_info = csv_upload_get_info($csvdir . DIRECTORY_SEPARATOR . "csv_upload.csv", $messages); $offline_limit = $csv_info["row_count"] > 1000; $force_offline = $offline_limit && $offline_job_queue; $offline_text = $force_offline ? $lang["csv_upload_force_offline"] : $lang["csv_upload_recommend_offline"]; unset($csv_info["row_count"]); // No longer needed } include __DIR__ . "/../../../include/header.php"; if (!checkperm("c")) { echo "
" . $lang['csv_upload_error_no_permission'] . "
"; include __DIR__ . "/../../../include/footer.php"; return; } ?>

" . strip_tags_and_attributes($lang["csv_upload_intro"]) . "

"; echo ""; ?>
" id="upload_csv_form" method="post" enctype="multipart/form-data">

" id="upload_csv_config_form" method="post" enctype="multipart/form-data" >
" . $offline_text . "
"; } echo "

" . $lang["csv_upload_create_new_title"] . "

"; echo "

" . $lang["csv_upload_create_new_notes"] . "

"; ?>
" id="upload_csv_form" method="post" enctype="multipart/form-data" onSubmit="return CentralSpacePost(this,true);">
>
" onClick="CentralSpaceLoad(' $csvstep - 1)); ?>',true);return false;" > ">
" . $offline_text . ""; } echo "

" . $lang["csv_upload_update_existing_title"] . "

"; echo "

" . $lang["csv_upload_update_existing_notes"] . "

"; ?>
" id="upload_csv_form" method="post" enctype="multipart/form-data" onSubmit="return CentralSpacePost(this,true);" >
"> >
>
" onClick="CentralSpaceLoad(' $csvstep - 1)); ?>',true);return false;"> ">
" . $offline_text . ""; } if (is_array($csv_info)) { echo "

" . $lang["csv_upload_map_fields_notes"] . "

"; echo "

" . $lang["csv_upload_map_fields_auto_notes"] . "

"; // Render each header with an option to map to a field ?>
" id="upload_csv_form" method="post" enctype="multipart/form-data" onSubmit="return CentralSpacePost(this,true);">
$csv_field_data) { // Used to stop selection process if a mapping found for particular resource type version of field $csv_set_options_found = false; if (in_array($csv_column, $selected_columns)) { continue; } echo ""; echo "\n"; echo ""; echo ""; } echo ""; echo ""; } ?>
" . escape($csv_field_data["header"]) . "
"; if (count($csv_field_data["values"]) > 0) { echo "
" . implode("
", array_slice(array_map("htmlspecialchars", $csv_field_data["values"]), 0, 5)) . "
" onclick="CentralSpaceLoad(' $csvstep - 1)); ?>',true);return false;" > ">
" . $offline_text . ""; } echo "

" . $lang["csv_upload_validation_notes"] . "

"; if (count($messages) > 1000) { $messages = array_slice($messages, 0, 1000); echo "

" . str_replace("[log_url]", $prelog_url, $lang["csv_upload_full_messages_link"]) . "

"; } ?>
" id="upload_csv_form" method="post" enctype="multipart/form-data" onSubmit="return CentralSpacePost(this,true);">
" . $lang["offline_processing_disabled"] . "
"; } ?>
" onClick="CentralSpaceLoad(' $csvstep - 1)); ?>',true);return false;" > " >
$offlinecsv, 'csv_set_options' => $csv_set_options ); $csvjob = job_queue_add( 'csv_upload', $csv_upload_job_data, $userref, '', $lang["csv_upload_oj_complete"], $lang["csv_upload_oj_failed"], $csv_set_options["csvchecksum"] ); if ($csvjob) { echo str_replace("[jobref]", $csvjob, $lang["csv_upload_oj_created"]); } elseif (is_string($csvjob)) { echo "
" . $lang["error"] . $csvjob . "
"; } } else { $messages = array(); // Processing immediately. Ensure connection does not get dropped set_time_limit(0); $log_time = date("Ymd-H:i:s", time()); $log_file = get_temp_dir(false, 'user_downloads') . "/" . $userref . "_" . md5($username . md5($csv_set_options["csvchecksum"] . $log_time) . $scramble_key) . ".log"; $log_url = $baseurl . "/pages/download.php?userfile=" . $userref . "_" . md5($csv_set_options["csvchecksum"] . $log_time) . ".log&filename=csv_upload_" . $log_time; $csv_set_options["log_file"] = $log_file; csv_upload_process($csvfile, $meta, $resource_types, $messages, $csv_set_options, 0, true); } if (count($messages) > 0) { // If this is a very large CSV we need to limit the output displayed or it may crash the browser if (count($messages) > 1000) { $messages = array_slice($messages, 0, 1000); echo "

" . str_replace("[log_url]", $log_url, $lang["csv_upload_full_messages_link"]) . "

"; } ?>