[svn r19080] logic changes - added restriction of a csv or xml file when you import users - (partial FS#3805)

skala
Isaac Flores 17 years ago
parent 437cd0a41c
commit 6ac011b9f9
  1. 4
      main/admin/class_user_import.php
  2. 43
      main/admin/user_import.php
  3. 5
      main/inc/lib/usermanager.lib.php

@ -55,9 +55,9 @@ function validate_data($user_classes)
{
//2.1.1 check if code exists in DB
$class_table = Database :: get_main_table(TABLE_MAIN_CLASS);
$sql = "SELECT * FROM $class_table WHERE name = '".mysql_real_escape_string($user_class['ClassName'])."'";
$sql = "SELECT * FROM $class_table WHERE name = '".Database::escape_string($user_class['ClassName'])."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
if (Database::num_rows($res) == 0)
{
$user_class['error'] = get_lang('CodeDoesNotExists');
$errors[] = $user_class;

@ -1,4 +1,4 @@
<?php // $Id: user_import.php 18648 2009-02-24 05:35:43Z yannoo $
<?php // $Id: user_import.php 19080 2009-03-16 20:18:03Z iflorespaz $
/* For licensing terms, see /dokeos_license.txt */
/**
==============================================================================
@ -277,16 +277,42 @@ $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAd
set_time_limit(0);
$extra_fields = Usermanager::get_extra_fields(0, 0, 5, 'ASC',false);
$user_id_error=array();
if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) {
$file_type = $_POST['file_type'];
if ($file_type == 'csv') {
if (strcmp($file_type,'csv')===0 && strcmp($_FILES['import_file']['type'],'text/'.$file_type.'')===0) {
$users = parse_csv_data($_FILES['import_file']['tmp_name']);
} else {
$errors = validate_data($users);
$error_kind_file=false;
} elseif (strcmp($file_type,'xml')===0 && strcmp($_FILES['import_file']['type'],'text/'.$file_type.'')===0) {
$users = parse_xml_data($_FILES['import_file']['tmp_name']);
$errors = validate_data($users);
$error_kind_file=false;
} else {
$error_kind_file=true;
}
//list user id whith error
if (is_array($errors) && is_array($users)) {
foreach ($errors as $my_errors) {
$user_id_error[]=$my_errors['UserId'];
}
foreach ($users as $my_user) {
if (!in_array($my_user['UserId'],$user_id_error)) {
$users_to_insert[]=$my_user;
}
}
}
if ( count($users_to_insert)>0 && $error_kind_file===false ) {
$errors=array();
$users=$users_to_insert;
$see_message_import=get_lang('FileImportedJustUsersThatAreNotRegistered');
} else {
$see_message_import=get_lang('FileImported');
}
$errors = validate_data($users);
if (count($errors) == 0) {
if ( count($errors) == 0 && $error_kind_file===false ) {
$inserted_in_course = array();
save_data($users);
$msg2 = '';
@ -299,7 +325,7 @@ if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) {
}
Security::clear_token();
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('FileImported')).'&warn='.urlencode($msg2).'&sec_token='.$tok);
header('Location: user_list.php?action=show_message&message='.urlencode($see_message_import).'&warn='.urlencode($msg2).'&sec_token='.$tok);
exit ();
}
}
@ -320,6 +346,9 @@ if (count($errors) != 0) {
$error_message .= '</ul>';
Display :: display_error_message($error_message, false);
}
if ($error_kind_file===true) {
Display :: display_error_message(get_lang('YouMustImportAFileAccordingToSelectedOption'));
}
$form = new FormValidator('user_import');
$form->addElement('hidden', 'formSent');
$form->addElement('file', 'import_file', get_lang('ImportFileLocation'));

@ -1,4 +1,4 @@
<?php // $Id: usermanager.lib.php 19078 2009-03-16 16:28:37Z yannoo $
<?php // $Id: usermanager.lib.php 19080 2009-03-16 20:18:03Z iflorespaz $
/*
==============================================================================
Dokeos - elearning and course management software
@ -97,6 +97,7 @@ class UserManager
//$password = "PLACEHOLDER";
$password = api_get_encrypted_password($password);
//$password = ($userPasswordCrypted ? md5($password) : $password);
$current_date=date('Y-m-d H:i:s',time());
$sql = "INSERT INTO $table_user
SET lastname = '".Database::escape_string(trim($lastName))."',
firstname = '".Database::escape_string(trim($firstName))."',
@ -110,7 +111,7 @@ class UserManager
auth_source = '".Database::escape_string($auth_source)."',
phone = '".Database::escape_string($phone)."',
language = '".Database::escape_string($language)."',
registration_date = now(),
registration_date = '".$current_date."',
expiration_date = '".Database::escape_string($expiration_date)."',
hr_dept_id = '".Database::escape_string($hr_dept_id)."',
active = '".Database::escape_string($active)."'";

Loading…
Cancel
Save