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