Minor cosmetic changes

skala
Julio Montoya 12 years ago
parent 88eaf5d211
commit e700799597
  1. 39
      main/admin/usergroup_import.php
  2. 13
      main/admin/usergroup_user_import.php

@ -1,20 +1,20 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* @package chamilo.admin * @package chamilo.admin
*/ */
/** /**
* Code * Code
* This tool allows platform admins to add classes by uploading a CSV file * This tool allows platform admins to add classes by uploading a CSV file
* @todo Add some langvars to DLTT * @todo Add some langvars to DLTT
*/ */
/** /**
* Validates imported data. * Validates imported data.
*/ */
function validate_data($classes) { function validate_data($classes) {
$errors = array(); $errors = array();
$usergroup = new UserGroup(); $usergroup = new UserGroup();
foreach ($classes as $index => $class) { foreach ($classes as $index => $class) {
// 1. Check wheter ClassName is available. // 1. Check wheter ClassName is available.
if (!isset($class['name']) || strlen(trim($class['name'])) == 0) { if (!isset($class['name']) || strlen(trim($class['name'])) == 0) {
@ -23,10 +23,10 @@ function validate_data($classes) {
$errors[] = $class; $errors[] = $class;
} }
// 2. Check whether class doesn't exist yet. // 2. Check whether class doesn't exist yet.
else { else {
if ($usergroup->usergroup_exists($class['name'])) { if ($usergroup->usergroup_exists($class['name'])) {
$class['line'] = $index + 2; $class['line'] = $index + 2;
$class['error'] = get_lang('ClassNameExists').' <strong>'.$class['ClassName'].'</strong>'; $class['error'] = get_lang('ClassNameExists') . ' <strong>' . $class['ClassName'] . '</strong>';
$errors[] = $class; $errors[] = $class;
} }
} }
@ -39,7 +39,7 @@ function validate_data($classes) {
*/ */
function save_data($classes) { function save_data($classes) {
$number_of_added_classes = 0; $number_of_added_classes = 0;
$usergroup = new UserGroup(); $usergroup = new UserGroup();
foreach ($classes as $index => $class) { foreach ($classes as $index => $class) {
$id = $usergroup->save($class); $id = $usergroup->save($class);
if ($id) { if ($id) {
@ -50,15 +50,15 @@ function save_data($classes) {
} }
// Language files that should be included. // Language files that should be included.
$language_file = array ('admin', 'registration'); $language_file = array('admin', 'registration');
// Resetting the course id. // Resetting the course id.
$cidReset = true; $cidReset = true;
// Including some necessary dokeos files. // Including some necessary dokeos files.
include '../inc/global.inc.php'; include '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'import.lib.php'; require_once api_get_path(LIBRARY_PATH) . 'import.lib.php';
// Setting the section (for the tabs). // Setting the section (for the tabs).
$this_section = SECTION_PLATFORM_ADMIN; $this_section = SECTION_PLATFORM_ADMIN;
@ -67,11 +67,10 @@ $this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(); api_protect_admin_script();
// setting breadcrumbs // setting breadcrumbs
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ('url' => 'usergroups.php', 'name' => get_lang('Classes')); $interbreadcrumb[] = array('url' => 'usergroups.php', 'name' => get_lang('Classes'));
// Database Table Definitions // Database Table Definitions
// Setting the name of the tool. // Setting the name of the tool.
$tool_name = get_lang('ImportClassListCSV'); $tool_name = get_lang('ImportClassListCSV');
@ -83,8 +82,7 @@ set_time_limit(0);
$form = new FormValidator('import_classes'); $form = new FormValidator('import_classes');
$form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation')); $form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
$group = array(); $group = array();
$group[] = $form->createElement('radio', 'file_type', '', 'CSV (<a href="example_class.csv" target="_blank">'.get_lang('ExampleCSVFile').'</a>)', 'csv'); $group[] = $form->createElement('radio', 'file_type', '', 'CSV (<a href="example_class.csv" target="_blank">' . get_lang('ExampleCSVFile') . '</a>)', 'csv');
//$group[] = $form->createElement('radio', 'file_type', null, 'XML (<a href="example.xml" target="_blank">'.get_lang('ExampleXMLFile').'</a>)', 'xml');
$form->addGroup($group, '', get_lang('FileType'), '<br/>'); $form->addGroup($group, '', get_lang('FileType'), '<br/>');
$form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="save"'); $form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="save"');
@ -93,12 +91,12 @@ if ($form->validate()) {
$errors = validate_data($classes); $errors = validate_data($classes);
if (count($errors) == 0) { if (count($errors) == 0) {
$number_of_added_classes = save_data($classes); $number_of_added_classes = save_data($classes);
Display::display_normal_message($number_of_added_classes.' '.get_lang('Added')); Display::display_normal_message($number_of_added_classes . ' ' . get_lang('Added'));
} else { } else {
$error_message = get_lang('ErrorsWhenImportingFile'); $error_message = get_lang('ErrorsWhenImportingFile');
$error_message .= '<ul>'; $error_message .= '<ul>';
foreach ($errors as $index => $error_class) { foreach ($errors as $index => $error_class) {
$error_message .= '<li>'.$error_class['error'].' ('.get_lang('Line').' '.$error_class['line'].')'; $error_message .= '<li>' . $error_class['error'] . ' (' . get_lang('Line') . ' ' . $error_class['line'] . ')';
$error_message .= '</li>'; $error_message .= '</li>';
} }
$error_message .= '</ul>'; $error_message .= '</ul>';
@ -109,13 +107,12 @@ if ($form->validate()) {
$form->display(); $form->display();
?> ?>
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p> <p><?php echo get_lang('CSVMustLookLike') . ' (' . get_lang('MandatoryFields') . ')'; ?> :</p>
<pre> <pre>
<b>name;description</b> <b>name;description</b>
"User group 1";"Description" "User group 1";"Description"
</pre> </pre>
<?php <?php
// Displaying the footer. // Displaying the footer.
Display :: display_footer(); Display :: display_footer();

@ -16,13 +16,6 @@ function validate_data($user_classes) {
global $purification_option_for_usernames; global $purification_option_for_usernames;
$errors = array(); $errors = array();
$classcodes = array(); $classcodes = array();
/* if (!isset($_POST['subscribe']) && !isset($_POST['subscribe'])) {
$user_class['error'] = get_lang('SelectAnAction');
$errors[] = $user_class;
return $errors;
} */
$usergroup = new UserGroup(); $usergroup = new UserGroup();
foreach ($user_classes as $index => $user_class) { foreach ($user_classes as $index => $user_class) {
@ -86,7 +79,7 @@ function save_data($users_classes) {
// Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id) // Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id)
$csv_data = array(); $csv_data = array();
if (!empty($users_classes)) { if (!empty($users_classes)) {
foreach ($users_classes as $user_class) { foreach ($users_classes as $user_class) {
$sql1 = "SELECT user_id FROM $user_table WHERE username = '" . Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames)) . "'"; $sql1 = "SELECT user_id FROM $user_table WHERE username = '" . Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames)) . "'";
$res1 = Database::query($sql1); $res1 = Database::query($sql1);
@ -105,7 +98,7 @@ function save_data($users_classes) {
// Logic for processing the request (data + UI options). // Logic for processing the request (data + UI options).
$message = null; $message = null;
if (!empty($csv_data)) { if (!empty($csv_data)) {
foreach ($csv_data as $class_id => $user_data) { foreach ($csv_data as $class_id => $user_data) {
$user_list = $user_data['user_list']; $user_list = $user_data['user_list'];
$class_name = $user_data['class_name']; $class_name = $user_data['class_name'];
@ -114,7 +107,7 @@ function save_data($users_classes) {
$message .= Display::return_message(get_lang('Class') . ': ' . $class_name . '<br />', 'normal', false); $message .= Display::return_message(get_lang('Class') . ': ' . $class_name . '<br />', 'normal', false);
$message .= Display::return_message(get_lang('Users') . ': ' . implode(', ', $user_list_name)); $message .= Display::return_message(get_lang('Users') . ': ' . implode(', ', $user_list_name));
} }
} }
return $message; return $message;
} }

Loading…
Cancel
Save