Implemented - option to export the trainings list to CSV file in Administration>Trainings - DT#4256

skala
Cristian Fasanando 15 years ago
parent 17f39713b5
commit d669a3ba32
  1. 3
      documentation/changelog.html
  2. 123
      main/admin/course_export.php
  3. 40
      main/admin/course_import.php
  4. 3
      main/admin/index.php
  5. 2
      main/inc/lib/course.lib.php

@ -41,7 +41,8 @@
<li>Wiki: Posibility to definition of wiki pages as tasks for students. Add feedback to student wiki pages, sincronized with their progress in the task. Posibility to establish a time limit for each wiki page. Posibility to establish a max number of words into each wiki page. Posibility to establish a max number versions for each page. Improve control of concurrent users. Improvements in the use of wiki pages such as portfolios of student (individual task)</li>
<li>Added when a user is enrolled only in one course, go directly to the course after the login (defined by the platform administrator through platform administration > configuration setting > training)- DT#3466</li>
<li>Added user' photo into user list interface - DT#5496</li>
<li>Disabled field trainers(tutor name) in create course form from user portal, by default is current user's name, you can modify this field into setting course - DT#5496 </li>
<li>Disabled field trainers(tutor name) in create course form from user portal, by default is current user's name, you can modify this field into setting course - DT#5496 </li>
<li>Added option to export the trainings list to CSV file in Administration>Trainings - DT#4256</li>
</ul>
<h3>Debugging</h3>
<ul>

@ -0,0 +1,123 @@
<?php
/* For licensing terms, see /dokeos_license.txt */
/**
==============================================================================
* This tool allows platform admins to export courses to CSV file
* @package dokeos.admin
==============================================================================
*/
$language_file = array ('admin', 'registration','create_course', 'document');
$cidReset = true;
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'course.lib.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$tool_name = get_lang('ExportCourses').' CSV';
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
set_time_limit(0);
Display :: display_header($tool_name);
$archivePath=api_get_path(SYS_PATH).$archiveDirName.'/';
$archiveURL=api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
$course_list = CourseManager::get_courses_list();
if($_POST['formSent'])
{
$formSent =$_POST['formSent'];
$select_type=intval($_POST['select_type']);
$file_type = 'csv';
$courses = $selected_courses = array();
if ($select_type == 2) {
// Get selected courses from courses list in form sent
$selected_courses = $_POST['course_code'];
if (is_array($selected_courses)) {
foreach ($course_list as $course) {
if (!in_array($course['code'],$selected_courses)) continue;
$courses[] = $course;
}
}
} else {
// Get all courses
$courses = $course_list;
}
if (!empty($courses)) {
if(!file_exists($archivePath)) {
mkpath($archivePath);
}
$archiveFile='export_courses_list_'.date('Y-m-d_H-i-s').'.'.$file_type;
$fp=fopen($archivePath.$archiveFile,'w');
if ($file_type == 'csv') {
$add = "Code;Title;CourseCategory;Teacher;Language;".PHP_EOL;
foreach($courses as $course) {
$course['code'] = str_replace(';',',',$course['code']);
$course['title'] = str_replace(';',',',$course['title']);
$course['category_code'] = str_replace(';',',',$course['category_code']);
$course['tutor_name'] = str_replace(';',',',$course['tutor_name']);
$course['course_language'] = str_replace(';',',',$course['course_language']);
$add.= $course['code'].';'.$course['title'].';'.$course['category_code'].';'.$course['tutor_name'].';'.$course['course_language'].';'.PHP_EOL;
}
fputs($fp, $add);
}
fclose($fp);
$msg=get_lang('CoursesListHasBeenExported').'<br/><a href="'.$archiveURL.$archiveFile.'">'.get_lang('ClickHereToDownloadTheFile').'</a>';
} else {
$msg=get_lang('ThereAreNotSelectedCoursesOrCoursesListIsEmpty');
}
}
if (!empty($msg)) {
Display::display_normal_message($msg, false);
}
?>
<form method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
<input type="hidden" name="formSent" value="1">
<div class="row"><div class="form_header"><?php echo $tool_name; ?></div></div>
<br />
<?php if (!empty($course_list)) { ?>
<div>
<input id="all-courses" class="checkbox" type="radio" value="1" name="select_type" <?php if(!$formSent || ($formSent && $select_type == 1)) echo 'checked="checked"'; ?> onclick="if(this.checked==true){document.getElementById('div-course-list').style.display='none';}"/>
<label for="all-courses"><?php echo get_lang('ExportAllCoursesList')?></label>
<br/>
<input id="select-courses" class="checkbox" type="radio" value="2" name="select_type" <?php if($formSent && $select_type == 2) echo 'checked="checked"'; ?> onclick="if(this.checked==true){document.getElementById('div-course-list').style.display='block';}"/>
<label for="select-courses"><?php echo get_lang('ExportSelectedCoursesFromCoursesList')?></label>
</div>
<br />
<div id="div-course-list" style="<?php echo (!$formSent || ($formSent && $select_type == 1))?'display:none':'display:block';?>">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top"><?php echo get_lang('WhichCoursesToExport'); ?> :</td>
<td><select name="course_code[]" multiple="multiple" size="10">
<?php
foreach($course_list as $course) {
?>
<option value="<?php echo $course['code']; ?>" <?php if(is_array($selected_courses) && in_array($course['code'],$selected_courses)) echo 'selected="selected"'; ?>><?php echo $course['code'].'-'.$course['title']; ?></option>
<?php
}
?>
</select></td>
</tr>
</table>
</div>
<br />
<div id="actions">
<button class="save" type="submit" name="name" value="<?php echo get_lang('ExportCourses') ?>"><?php echo get_lang('ExportCourses') ?></button>
</div>
<?php } else { echo get_lang('ThereAreNotCreatedCourses'); }?>
</form>
<?php
Display :: display_footer();
?>

@ -72,7 +72,8 @@ function validate_data($courses) {
}
}
$coursecodes[$course['Code']] = 1;
}
}
/*
// 3. Check whether teacher exists.
if (!UserManager::is_username_empty($course['Teacher'])) {
$teacher = UserManager::purify_username($course['Teacher'], $purification_option_for_usernames);
@ -81,6 +82,7 @@ function validate_data($courses) {
$errors[] = $course;
}
}
*/
// 4. Check whether course category exists.
if (isset ($course['CourseCategory']) && strlen($course['CourseCategory']) != 0) {
$category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
@ -102,14 +104,40 @@ function validate_data($courses) {
function save_data($courses) {
global $_configuration, $firstExpirationDelay;
global $purification_option_for_usernames;
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$msg = '';
foreach ($courses as $index => $course) {
$course_language = api_get_valid_language($course['Language']);
$keys = define_course_keys($course['Code'], '', $_configuration['db_prefix']);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT user_id, ".(api_is_western_name_order(null, $course_language) ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." AS name FROM $user_table WHERE username = '".Database::escape_string(UserManager::purify_username($course['Teacher'], $purification_option_for_usernames))."'";
$res = Database::query($sql,__FILE__,__LINE__);
$teacher = Database::fetch_object($res);
$titular = $uidCreator = $username = '';
// get username from name (firstname lastname)
if (!UserManager::is_username_empty($course['Teacher'])) {
$teacher = UserManager::purify_username($course['Teacher'], $purification_option_for_usernames);
if (UserManager::is_username_available($teacher)) {
$sql = "SELECT username FROM $user_table WHERE ".(api_is_western_name_order(null, $course_language) ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." = '{$course['Teacher']}' LIMIT 1";
$rs = Database::query($sql,__FILE__,__LINE__);
$user = Database::fetch_object($rs);
$username = $user->username;
} else {
$username = $teacher;
}
}
// get name and uid creator from username
if (!empty($username)) {
$sql = "SELECT user_id, ".(api_is_western_name_order(null, $course_language) ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." AS name FROM $user_table WHERE username = '".Database::escape_string(UserManager::purify_username($username, $purification_option_for_usernames))."'";
$res = Database::query($sql,__FILE__,__LINE__);
$teacher = Database::fetch_object($res);
$titular = $teacher->name;
$uidCreator = $teacher->user_id;
} else {
$titular = $course['Teacher'];
$uidCreator = 1;
}
$visual_code = $keys['currentCourseCode'];
$code = $keys['currentCourseId'];
$db_name = $keys['currentCourseDbName'];
@ -119,7 +147,7 @@ function save_data($courses) {
update_Db_course($db_name);
fill_course_repository($directory);
fill_Db_course($db_name, $directory, $course_language, array());
register_course($code, $visual_code, $directory, $db_name, $teacher->name, $course['CourseCategory'], $course['Title'], $course_language, $teacher->user_id, $expiration_date);
register_course($code, $visual_code, $directory, $db_name, $titular, $course['CourseCategory'], $course['Title'], $course_language, $uidCreator, $expiration_date);
$msg .= '<a href="'.api_get_path(WEB_COURSE_PATH).$directory.'/">'.$code.'</a> '.get_lang('Created').'<br />';
}
if (!empty($msg)) {

@ -140,7 +140,8 @@ if(api_is_platform_admin()) {
</li>
<li><a href="course_list.php"><?php echo get_lang('CourseList') ?></a></li>
<li><a href="course_add.php"><?php echo get_lang('AddCourse') ?></a></li>
<li><a href="course_import.php"><?php echo get_lang('ImportCourses'); ?></a></li>
<li><a href="course_export.php"><?php echo get_lang('ExportCourses'); ?></a></li>
<li><a href="course_import.php"><?php echo get_lang('ImportCourses'); ?></a></li>
<!--<li><a href="course_virtual.php"><?php //echo get_lang('AdminManageVirtualCourses') ?></a></li>-->
<li><a href="course_category.php"><?php echo get_lang('AdminCategories'); ?></a></li>
<li><a href="subscribe_user2course.php"><?php echo get_lang('AddUsersToACourse'); ?></a></li>

@ -170,7 +170,7 @@ class CourseManager {
*/
public static function get_courses_list($from = 0, $howmany = 0, $orderby = 1, $orderdirection = 'ASC', $visibility = -1, $startwith = '') {
$sql = "SELECT code, title FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." ";
$sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." ";
if (!empty($startwith)) {
$sql .= "WHERE LIKE title '".Database::escape_string($startwith)."%' ";
if ($visibility !== -1 && $visibility == strval(intval($visibility))) {

Loading…
Cancel
Save