Fixing PHP import errors see BT#6719

1.9.x
Julio Montoya 12 years ago
parent a58bd1c7e4
commit e584cddffd
  1. 30
      main/admin/user_import.php
  2. 11
      main/admin/user_list.php

@ -123,7 +123,7 @@ function save_data($users) {
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
$send_mail = $_POST['sendMail'] ? 1 : 0; $send_mail = $_POST['sendMail'] ? 1 : 0;
if (is_array($users)) { if (is_array($users)) {
foreach ($users as $index => $user) { foreach ($users as $user) {
$user = complete_missing_data($user); $user = complete_missing_data($user);
$user['Status'] = api_status_key($user['Status']); $user['Status'] = api_status_key($user['Status']);
$user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], $user['language'], $user['PhoneNumber'], '', $user['AuthSource'], null, 1, 0, null, null, $send_mail); $user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], $user['language'], $user['PhoneNumber'], '', $user['AuthSource'], null, 1, 0, null, null, $send_mail);
@ -276,12 +276,13 @@ if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) {
$file_type = $_POST['file_type']; $file_type = $_POST['file_type'];
Security::clear_token(); Security::clear_token();
$tok = Security::get_token(); $tok = Security::get_token();
$allowed_file_mimetype = array('csv','xml'); $allowed_file_mimetype = array('csv', 'xml');
$error_kind_file = false; $error_kind_file = false;
$ext_import_file = substr($_FILES['import_file']['name'],(strrpos($_FILES['import_file']['name'],'.')+1)); $uploadInfo = pathinfo($_FILES['import_file']['name']);
$ext_import_file = $uploadInfo['extension'];
if (in_array($ext_import_file,$allowed_file_mimetype)) { if (in_array($ext_import_file, $allowed_file_mimetype)) {
if (strcmp($file_type, 'csv') === 0 && $ext_import_file == $allowed_file_mimetype[0]) { if (strcmp($file_type, 'csv') === 0 && $ext_import_file == $allowed_file_mimetype[0]) {
$users = parse_csv_data($_FILES['import_file']['tmp_name']); $users = parse_csv_data($_FILES['import_file']['tmp_name']);
$errors = validate_data($users); $errors = validate_data($users);
@ -297,8 +298,9 @@ if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) {
$error_kind_file = true; $error_kind_file = true;
} }
// List user id whith error. // List user id with error.
$users_to_insert = $user_id_error = array(); $users_to_insert = $user_id_error = array();
if (is_array($errors)) { if (is_array($errors)) {
foreach ($errors as $my_errors) { foreach ($errors as $my_errors) {
$user_id_error[] = $my_errors['UserName']; $user_id_error[] = $my_errors['UserName'];
@ -327,17 +329,6 @@ if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) {
} else { } else {
$see_message_import = get_lang('FileImported'); $see_message_import = get_lang('FileImported');
} }
/*
$msg2 = '';
if (count($inserted_in_course) > 1) {
$msg2 .= '<br>'.get_lang('UsersSubscribedToSeveralCoursesBecauseOfVirtualCourses').':';
foreach ($inserted_in_course as $course) {
$msg2 .= ' '.$course.',';
}
$msg2 = substr($msg2, 0, -1);
$msg2 .= '</br>';
}
*/
if (count($errors) != 0) { if (count($errors) != 0) {
$warning_message = '<ul>'; $warning_message = '<ul>';
@ -350,10 +341,9 @@ if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) {
} }
// if the warning message is too long then we display the warning message trough a session // if the warning message is too long then we display the warning message trough a session
if (api_strlen($warning_message) > 150) {
$_SESSION['session_message_import_users'] = $warning_message; $_SESSION['session_message_import_users'] = $warning_message;
$warning_message = 'session_message'; $warning_message = 'session_message';
}
if ($error_kind_file) { if ($error_kind_file) {
$error_message = get_lang('YouMustImportAFileAccordingToSelectedOption'); $error_message = get_lang('YouMustImportAFileAccordingToSelectedOption');

@ -706,16 +706,18 @@ if (!empty($action)) {
} }
break; break;
case 'show_message' : case 'show_message' :
if (!empty($_GET['message'])) {
$message = Display :: return_message(stripslashes($_GET['message']), 'confirmation');
}
if (!empty($_GET['warn'])) { if (!empty($_GET['warn'])) {
// to prevent too long messages // to prevent too long messages
if ($_GET['warn'] == 'session_message'){ if ($_GET['warn'] == 'session_message'){
$_GET['warn'] = $_SESSION['session_message_import_users']; $_GET['warn'] = $_SESSION['session_message_import_users'];
} }
$message = Display::return_message(urldecode($_GET['warn']),'warning', false); $message = Display::return_message(urldecode($_GET['warn']),'warning', false);
} }
if (!empty($_GET['message'])) {
$message = Display :: return_message(stripslashes($_GET['message']), 'confirmation');
}
break; break;
case 'delete_user' : case 'delete_user' :
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
@ -969,7 +971,6 @@ if ($table->get_total_number_of_items() == 0) {
} }
$tpl = new Template($tool_name); $tpl = new Template($tool_name);
$tpl->assign('actions', $actions); $tpl->assign('actions', $actions);
$tpl->assign('message', $message); $tpl->assign('message', $message);
$tpl->assign('content', $form.$table_result.$extra_search_options); $tpl->assign('content', $form.$table_result.$extra_search_options);

Loading…
Cancel
Save