Internal: Format code + add undefined variables + code readability

pull/4819/head
Angel Fernando Quiroz Campos 2 years ago
parent 209d4f1dc9
commit 43dedbc7c8
  1. 36
      main/session/session_import.php

@ -32,16 +32,17 @@ set_time_limit(0);
$purification_option_for_usernames = false;
$inserted_in_course = [];
$error_message = '';
$warn = null;
if (isset($_POST['formSent']) && $_POST['formSent']) {
if (isset($_FILES['import_file']['tmp_name']) &&
!empty($_FILES['import_file']['tmp_name'])
if (!empty($_FILES['import_file']['tmp_name'])
) {
$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;
$isOverwrite = isset($_POST['overwrite']) && $_POST['overwrite'] ? true : false;
$deleteUsersNotInList = isset($_POST['delete_users_not_in_list']) ? true : false;
$isOverwrite = isset($_POST['overwrite']) && $_POST['overwrite'];
$deleteUsersNotInList = isset($_POST['delete_users_not_in_list']);
$sessions = [];
$session_counter = 0;
@ -168,7 +169,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
// Looking up for the teacher.
$username = trim(api_utf8_decode($courseNode->CourseTeacher));
$sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username='$username'";
$sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username = '$username'";
$rs = Database::query($sql);
list($user_id, $lastname, $firstname) = Database::fetch_array($rs);
@ -364,13 +365,13 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$coach_id = UserManager::get_user_id_from_username($course_coach);
if ($coach_id !== false) {
$sql = "INSERT IGNORE INTO $tbl_session_course_user SET
user_id='$coach_id',
user_id = '$coach_id',
c_id = '$courseId',
session_id = '$session_id',
status = 2 ";
$rs_coachs = Database::query($sql);
} else {
$error_message .= get_lang('UserDoesNotExist').' : '.$user.'<br />';
$error_message .= get_lang('UserDoesNotExist').' : '.$course_coach.'<br />';
}
}
@ -415,8 +416,8 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
}
} else {
// CSV
$updateCourseCoaches = isset($_POST['update_course_coaches']) ? true : false;
$addOriginalCourseTeachersAsCourseSessionCoaches = isset($_POST['add_me_as_coach']) ? true : false;
$updateCourseCoaches = isset($_POST['update_course_coaches']);
$addOriginalCourseTeachersAsCourseSessionCoaches = isset($_POST['add_me_as_coach']);
$result = SessionManager::importCSV(
$_FILES['import_file']['tmp_name'],
@ -444,7 +445,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$error_message = get_lang('ButProblemsOccured').' :<br />'.$error_message;
}
if (count($inserted_in_course) > 1) {
if (!empty($inserted_in_course)) {
$warn = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
foreach ($inserted_in_course as $code => $title) {
$warn .= ' '.$title.' ('.$code.'),';
@ -457,12 +458,11 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
}
Display::addFlash(Display::return_message($warn));
header('Location: resume_session.php?id_session='.$session_id);
exit;
} else {
Display::addFlash(Display::return_message(get_lang('FileImported').' '.$error_message, 'normal', false));
header('Location: session_list.php');
exit;
}
exit;
} else {
$error_message = get_lang('NoInputFile');
}
@ -471,7 +471,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
// Display the header.
Display::display_header($tool_name);
if (count($inserted_in_course) > 1) {
if (!empty($inserted_in_course)) {
$msg = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
foreach ($inserted_in_course as $code => $title) {
$msg .= ' '.$title.' ('.$title.'),';
@ -546,15 +546,15 @@ Display::return_message(get_lang('TheXMLImportLetYouAddMoreInfoAndCreateResource
$form->display();
?>
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
<pre>
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
<pre>
<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 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
</pre>
<p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
<pre>
<p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Sessions&gt;
&lt;Users&gt;

Loading…
Cancel
Save