Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

pull/4819/head
Yannick Warnier 2 years ago
commit 10ee6774f7
  1. 2
      main/inc/lib/sessionmanager.lib.php
  2. 45
      main/session/session_import.php

@ -6701,6 +6701,8 @@ class SessionManager
* @param int $courseId * @param int $courseId
* *
* @return bool * @return bool
*
* @deprecated
*/ */
public static function installCourse($sessionId, $courseId) public static function installCourse($sessionId, $courseId)
{ {

@ -32,16 +32,17 @@ set_time_limit(0);
$purification_option_for_usernames = false; $purification_option_for_usernames = false;
$inserted_in_course = []; $inserted_in_course = [];
$error_message = '';
$warn = null; $warn = null;
if (isset($_POST['formSent']) && $_POST['formSent']) { if (isset($_POST['formSent']) && $_POST['formSent']) {
if (isset($_FILES['import_file']['tmp_name']) && if (!empty($_FILES['import_file']['tmp_name'])
!empty($_FILES['import_file']['tmp_name'])
) { ) {
$form_sent = $_POST['formSent']; $form_sent = $_POST['formSent'];
$file_type = isset($_POST['file_type']) ? $_POST['file_type'] : null; $file_type = $_POST['file_type'] ?? null;
$send_mail = isset($_POST['sendMail']) && $_POST['sendMail'] ? 1 : 0; $send_mail = isset($_POST['sendMail']) && $_POST['sendMail'] ? 1 : 0;
$isOverwrite = isset($_POST['overwrite']) && $_POST['overwrite'] ? true : false; $isOverwrite = isset($_POST['overwrite']) && $_POST['overwrite'];
$deleteUsersNotInList = isset($_POST['delete_users_not_in_list']) ? true : false; $deleteUsersNotInList = isset($_POST['delete_users_not_in_list']);
$sessions = []; $sessions = [];
$session_counter = 0; $session_counter = 0;
@ -168,9 +169,14 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
// Looking up for the teacher. // Looking up for the teacher.
$username = trim(api_utf8_decode($courseNode->CourseTeacher)); $username = trim(api_utf8_decode($courseNode->CourseTeacher));
$sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username='$username'"; $rs = Database::select(
$rs = Database::query($sql); ['user_id', 'lastname', 'firstname'],
list($user_id, $lastname, $firstname) = Database::fetch_array($rs); $tbl_user,
['where' => ['username = ?' => $username]],
'first',
'NUM'
);
list($user_id, $lastname, $firstname) = $rs;
$params['teachers'] = $user_id; $params['teachers'] = $user_id;
CourseManager::create_course($params); CourseManager::create_course($params);
@ -364,13 +370,13 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$coach_id = UserManager::get_user_id_from_username($course_coach); $coach_id = UserManager::get_user_id_from_username($course_coach);
if ($coach_id !== false) { if ($coach_id !== false) {
$sql = "INSERT IGNORE INTO $tbl_session_course_user SET $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
user_id='$coach_id', user_id = '$coach_id',
c_id = '$courseId', c_id = '$courseId',
session_id = '$session_id', session_id = '$session_id',
status = 2 "; status = 2 ";
$rs_coachs = Database::query($sql); $rs_coachs = Database::query($sql);
} else { } else {
$error_message .= get_lang('UserDoesNotExist').' : '.$user.'<br />'; $error_message .= get_lang('UserDoesNotExist').' : '.$course_coach.'<br />';
} }
} }
@ -415,8 +421,8 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
} }
} else { } else {
// CSV // CSV
$updateCourseCoaches = isset($_POST['update_course_coaches']) ? true : false; $updateCourseCoaches = isset($_POST['update_course_coaches']);
$addOriginalCourseTeachersAsCourseSessionCoaches = isset($_POST['add_me_as_coach']) ? true : false; $addOriginalCourseTeachersAsCourseSessionCoaches = isset($_POST['add_me_as_coach']);
$result = SessionManager::importCSV( $result = SessionManager::importCSV(
$_FILES['import_file']['tmp_name'], $_FILES['import_file']['tmp_name'],
@ -444,7 +450,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$error_message = get_lang('ButProblemsOccured').' :<br />'.$error_message; $error_message = get_lang('ButProblemsOccured').' :<br />'.$error_message;
} }
if (count($inserted_in_course) > 1) { if (!empty($inserted_in_course)) {
$warn = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': '; $warn = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
foreach ($inserted_in_course as $code => $title) { foreach ($inserted_in_course as $code => $title) {
$warn .= ' '.$title.' ('.$code.'),'; $warn .= ' '.$title.' ('.$code.'),';
@ -457,12 +463,11 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
} }
Display::addFlash(Display::return_message($warn)); Display::addFlash(Display::return_message($warn));
header('Location: resume_session.php?id_session='.$session_id); header('Location: resume_session.php?id_session='.$session_id);
exit;
} else { } else {
Display::addFlash(Display::return_message(get_lang('FileImported').' '.$error_message, 'normal', false)); Display::addFlash(Display::return_message(get_lang('FileImported').' '.$error_message, 'normal', false));
header('Location: session_list.php'); header('Location: session_list.php');
exit;
} }
exit;
} else { } else {
$error_message = get_lang('NoInputFile'); $error_message = get_lang('NoInputFile');
} }
@ -471,7 +476,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
// Display the header. // Display the header.
Display::display_header($tool_name); Display::display_header($tool_name);
if (count($inserted_in_course) > 1) { if (!empty($inserted_in_course)) {
$msg = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': '; $msg = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
foreach ($inserted_in_course as $code => $title) { foreach ($inserted_in_course as $code => $title) {
$msg .= ' '.$title.' ('.$title.'),'; $msg .= ' '.$title.' ('.$title.'),';
@ -546,15 +551,15 @@ Display::return_message(get_lang('TheXMLImportLetYouAddMoreInfoAndCreateResource
$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>
<strong>SessionName</strong>;Coach;<strong>DateStart</strong>;<strong>DateEnd</strong>;Users;Courses;VisibilityAfterExpiration;DisplayStartDate;DisplayEndDate;CoachStartDate;CoachEndDate;Classes <strong>SessionName</strong>;Coach;<strong>DateStart</strong>;<strong>DateEnd</strong>;Users;Courses;VisibilityAfterExpiration;DisplayStartDate;DisplayEndDate;CoachStartDate;CoachEndDate;Classes
<strong>Example 1</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];read_only;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class1|class2 <strong>Example 1</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];read_only;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class1|class2
<strong>Example 2</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];accessible;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class3|class4 <strong>Example 2</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];accessible;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class3|class4
<strong>Example 3</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];not_accessible;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class5|class6 <strong>Example 3</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,...]|course2[coach1][username1,...];not_accessible;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;yyyy/mm/dd;class5|class6
</pre> </pre>
<p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p> <p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
<pre> <pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Sessions&gt; &lt;Sessions&gt;
&lt;Users&gt; &lt;Users&gt;

Loading…
Cancel
Save