[svn r18641] Add XML/CSV subscription to courses with corresponding visual code

skala
Yannick Warnier 16 years ago
parent 1dd3a2f01e
commit a41d0f07db
  1. 2
      documentation/changelog.html
  2. 66
      main/admin/user_import.php
  3. 17
      main/inc/lib/course.lib.php

@ -87,6 +87,7 @@
<li>Added social tool - (partial FS#3383)</li> <li>Added social tool - (partial FS#3383)</li>
<li>Added introduction section to blog and course description (FS#3165)</li> <li>Added introduction section to blog and course description (FS#3165)</li>
<li>Added import/export (CSV/XML) of extra user fields</li> <li>Added import/export (CSV/XML) of extra user fields</li>
<li>Added ability to import users in XML and subscribe to visual code (FS#3552)</li>
</ul> </ul>
<br /> <br />
<h3>Debugging</h3> <h3>Debugging</h3>
@ -171,6 +172,7 @@
<li>allow show results with floating point,in exercice tool - (partial FS#3630) - SVN#18367</li> <li>allow show results with floating point,in exercice tool - (partial FS#3630) - SVN#18367</li>
<li>Fixed event into agenda when it's sent from assignment and Improved display form when you create an assignment - see FS#3583</li> <li>Fixed event into agenda when it's sent from assignment and Improved display form when you create an assignment - see FS#3583</li>
<li>Fixed difficulty of the question lost - see FS#3659</li> <li>Fixed difficulty of the question lost - see FS#3659</li>
<li>Fixed XML user import for single courses import (related to FS#3552)</li>
</ul> </ul>
<br /> <br />
<h3>CSS changes</h3> <h3>CSS changes</h3>

@ -1,4 +1,4 @@
<?php // $Id: user_import.php 18595 2009-02-19 21:17:17Z juliomontoya $ <?php // $Id: user_import.php 18641 2009-02-24 00:49:03Z yannoo $
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -144,29 +144,49 @@ function complete_missing_data($user)
} }
/** /**
* Save the imported data * Save the imported data
* @param array List of users
* @return void
* @uses global variable $inserted_in_course, which returns the list of courses the user was inserted in
*/ */
function save_data($users) function save_data($users) {
{ global $inserted_in_course;
// not all scripts declare the $inserted_in_course array (although they should)
if (!isset($inserted_in_course)) { $inserted_in_course = array(); }
require_once(api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php'); require_once(api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php');
$user_table = Database :: get_main_table(TABLE_MAIN_USER); $user_table = Database :: get_main_table(TABLE_MAIN_USER);
$sendMail = $_POST['sendMail'] ? 1 : 0; $sendMail = $_POST['sendMail'] ? 1 : 0;
if (is_array($users)) { if (is_array($users)) {
foreach ($users as $index => $user) foreach ($users as $index => $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'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']); $user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']);
if (!is_array($user['Courses']) && !empty($user['Courses'])) {
$user['Courses'] = array($user['Courses']);
}
if (is_array($user['Courses'])) { if (is_array($user['Courses'])) {
foreach ($user['Courses'] as $index => $course) foreach ($user['Courses'] as $index => $course) {
{ if(CourseManager :: course_exists($course)) {
if(CourseManager :: course_exists($course))
CourseManager :: subscribe_user($user_id, $course,$user['Status']); CourseManager :: subscribe_user($user_id, $course,$user['Status']);
$c_info = CourseManager::get_course_information($course);
$inserted_in_course[$course] = $c_info['title'];
} }
if (CourseManager :: course_exists($course,true)) {
// also subscribe to virtual courses through check on visual code
$list = CourseManager :: get_courses_info_from_visual_code($course);
foreach ($list as $vcourse) {
if ($vcourse['code'] == $course) {
//ignore, this has already been inserted
} else {
CourseManager :: subscribe_user($user_id, $vcourse['code'],$user['Status']);
$inserted_in_course[$vcourse['code']] = $vcourse['title'];
} }
if (strlen($user['ClassName']) > 0) }
{ }
}
}
if (strlen($user['ClassName']) > 0) {
$class_id = ClassManager :: get_class_id($user['ClassName']); $class_id = ClassManager :: get_class_id($user['ClassName']);
ClassManager :: add_user($user_id, $class_id); ClassManager :: add_user($user_id, $class_id);
} }
@ -183,8 +203,7 @@ function save_data($users)
} }
} }
if ($sendMail) if ($sendMail) {
{
$recipient_name = $user['FirstName'].' '.$user['LastName']; $recipient_name = $user['FirstName'].' '.$user['LastName'];
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName'); $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$emailbody = get_lang('Dear').$user['FirstName'].' '.$user['LastName'].",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('Settings')." $user[UserName]\n".get_lang('Pass')." : $user[Password]\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".api_get_path('WEB_PATH')." \n\n".get_lang('Problem')."\n\n".get_lang('Formula').",\n\n".api_get_setting('administratorName')." ".api_get_setting('administratorSurname')."\n".get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator').""; $emailbody = get_lang('Dear').$user['FirstName'].' '.$user['LastName'].",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('Settings')." $user[UserName]\n".get_lang('Pass')." : $user[Password]\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".api_get_path('WEB_PATH')." \n\n".get_lang('Problem')."\n\n".get_lang('Formula').",\n\n".api_get_setting('administratorName')." ".api_get_setting('administratorSurname')."\n".get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator')."";
@ -201,13 +220,10 @@ function save_data($users)
* @param string $file Path to the CSV-file * @param string $file Path to the CSV-file
* @return array All userinformation read from the file * @return array All userinformation read from the file
*/ */
function parse_csv_data($file) function parse_csv_data($file) {
{
$users = Import :: csv_to_array($file); $users = Import :: csv_to_array($file);
foreach ($users as $index => $user) foreach ($users as $index => $user) {
{ if (isset ($user['Courses'])) {
if (isset ($user['Courses']))
{
$user['Courses'] = explode('|', trim($user['Courses'])); $user['Courses'] = explode('|', trim($user['Courses']));
} }
$users[$index] = $user; $users[$index] = $user;
@ -325,8 +341,20 @@ if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0)
$errors = validate_data($users); $errors = validate_data($users);
if (count($errors) == 0) if (count($errors) == 0)
{ {
$inserted_in_course = array();
save_data($users); save_data($users);
header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('FileImported'))); $msg = ' (';
if (count($inserted_in_course)>1) {
$msg .= get_lang('UsersSubscribedToSeveralCoursesBecauseOfVirtualCourses').':';
foreach ($inserted_in_course as $course) {
$msg .= ' '.$course.',';
}
$msg = substr($msg,0,-1);
$msg .=')';
}
Security::clear_token();
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('FileImported').$msg).'&sec_token='.$tok);
exit (); exit ();
} }
} }

@ -1907,5 +1907,22 @@ class CourseManager
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
return $row['code']; return $row['code'];
} }
/**
* Get course code(s) from visual code
* @param string Visual code
* @return array List of codes for the given visual code
*/
function get_courses_info_from_visual_code ($code) {
$table = Database :: get_main_table(TABLE_MAIN_COURSE);
$code = Database::escape_string($code);
$sql_query = "SELECT * FROM $table WHERE visual_code = '$code'";
$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
$result = array ();
while ($virtual_course = Database::fetch_array($sql_result))
{
$result[] = $virtual_course;
}
return $result;
}
} //end class CourseManager } //end class CourseManager
Loading…
Cancel
Save