From a41d0f07db873a7eafef5c660771b8f072b2fb62 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Tue, 24 Feb 2009 01:49:03 +0100 Subject: [PATCH] [svn r18641] Add XML/CSV subscription to courses with corresponding visual code --- documentation/changelog.html | 4 ++- main/admin/user_import.php | 66 +++++++++++++++++++++++++----------- main/inc/lib/course.lib.php | 17 ++++++++++ 3 files changed, 67 insertions(+), 20 deletions(-) diff --git a/documentation/changelog.html b/documentation/changelog.html index 9a8b9acd4c..6b2e6ccab7 100644 --- a/documentation/changelog.html +++ b/documentation/changelog.html @@ -87,6 +87,7 @@
  • Added social tool - (partial FS#3383)
  • Added introduction section to blog and course description (FS#3165)
  • Added import/export (CSV/XML) of extra user fields
  • +
  • Added ability to import users in XML and subscribe to visual code (FS#3552)

  • Debugging

    @@ -170,7 +171,8 @@
  • Fixed qualification of themes into forum tool - see FS#3609
  • allow show results with floating point,in exercice tool - (partial FS#3630) - SVN#18367
  • Fixed event into agenda when it's sent from assignment and Improved display form when you create an assignment - see FS#3583
  • -
  • Fixed difficulty of the question lost - see FS#3659
  • +
  • Fixed difficulty of the question lost - see FS#3659
  • +
  • Fixed XML user import for single courses import (related to FS#3552)

  • CSS changes

    diff --git a/main/admin/user_import.php b/main/admin/user_import.php index f6711a5570..dff94e5575 100644 --- a/main/admin/user_import.php +++ b/main/admin/user_import.php @@ -1,4 +1,4 @@ - $user) - { + foreach ($users as $index => $user) { $user = complete_missing_data($user); $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']); + if (!is_array($user['Courses']) && !empty($user['Courses'])) { + $user['Courses'] = array($user['Courses']); + } if (is_array($user['Courses'])) { - foreach ($user['Courses'] as $index => $course) - { - if(CourseManager :: course_exists($course)) + foreach ($user['Courses'] as $index => $course) { + if(CourseManager :: course_exists($course)) { 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']); 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']; $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').""; @@ -201,13 +220,10 @@ function save_data($users) * @param string $file Path to the CSV-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); - foreach ($users as $index => $user) - { - if (isset ($user['Courses'])) - { + foreach ($users as $index => $user) { + if (isset ($user['Courses'])) { $user['Courses'] = explode('|', trim($user['Courses'])); } $users[$index] = $user; @@ -325,8 +341,20 @@ if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0) $errors = validate_data($users); if (count($errors) == 0) { + $inserted_in_course = array(); 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 (); } } diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 58bd70a013..952ee82e74 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -1907,5 +1907,22 @@ class CourseManager $row = Database::fetch_array($res); 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 \ No newline at end of file