Session: Fix csv and xml import with same session name - refs BT#19147

pull/4182/head
Christian 3 years ago
parent b4449fa23f
commit 4945c9c4bc
  1. 2
      public/main/inc/lib/add_course.lib.inc.php
  2. 32
      public/main/inc/lib/sessionmanager.lib.php
  3. 4
      public/main/inc/lib/usermanager.lib.php
  4. 49
      public/main/session/session_import.php

@ -756,7 +756,7 @@ class AddCourse
->setShowScore(1)
->setDiskQuota($disk_quota)
->setExpirationDate(new \DateTime($expiration_date))
->setDepartmentName($department_name)
->setDepartmentName((string) $department_name)
->setDepartmentUrl($department_url)
->setSubscribe($subscribe)
->setSticky(1 === (int) ($params['sticky'] ?? 0))

@ -5075,7 +5075,7 @@ class SessionManager
if ($i > 1) {
$suffix = ' - '.$i;
}
$sql = 'SELECT 1 FROM '.$tbl_session.'
$sql = 'SELECT id FROM '.$tbl_session.'
WHERE name="'.Database::escape_string($session_name).$suffix.'"';
$rs = Database::query($sql);
if (Database::result($rs, 0, 0)) {
@ -5095,6 +5095,11 @@ class SessionManager
'coach_access_start_date' => $coachAccessStartDate,
'coach_access_end_date' => $coachAccessEndDate,
'visibility' => $visibilityAfterExpirationPerSession,
'nbr_users' => 0,
'nbr_courses' => 0,
'nbr_classes' => 0,
'status' => 0,
'duration' => 0,
];
if (!empty($extraParams)) {
@ -5173,6 +5178,11 @@ class SessionManager
'coach_access_start_date' => $coachAccessStartDate,
'coach_access_end_date' => $coachAccessEndDate,
'visibility' => $visibilityAfterExpirationPerSession,
'nbr_users' => 0,
'nbr_courses' => 0,
'nbr_classes' => 0,
'status' => 0,
'duration' => 0,
];
if (!empty($extraParams)) {
@ -5389,15 +5399,17 @@ class SessionManager
$extraFieldValueCareer = new ExtraFieldValue('career');
$careerList = isset($enreg['extra_careerid']) && !empty($enreg['extra_careerid']) ? $enreg['extra_careerid'] : [];
$careerList = str_replace(['[', ']'], '', $careerList);
$careerList = explode(',', $careerList);
$finalCareerIdList = [];
foreach ($careerList as $careerId) {
$realCareerIdList = $extraFieldValueCareer->get_item_id_from_field_variable_and_field_value(
'external_career_id',
$careerId
);
if (isset($realCareerIdList['item_id'])) {
$finalCareerIdList[] = $realCareerIdList['item_id'];
if (!empty($careerList)) {
$careerList = explode(',', $careerList);
$finalCareerIdList = [];
foreach ($careerList as $careerId) {
$realCareerIdList = $extraFieldValueCareer->get_item_id_from_field_variable_and_field_value(
'external_career_id',
$careerId
);
if (isset($realCareerIdList['item_id'])) {
$finalCareerIdList[] = $realCareerIdList['item_id'];
}
}
}

@ -1077,8 +1077,8 @@ class UserManager
->setPhone($phone)
->setAddress($address)
->setExpirationDate($expiration_date)
->setActive($active)
->setEnabled($active)
->setActive((bool) $active)
->setEnabled((bool) $active)
->setHrDeptId((int) $hr_dept_id)
;

@ -173,11 +173,14 @@ 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 id, lastname, firstname FROM $tbl_user WHERE username='$username'";
$rs = Database::query($sql);
[$userId, $lastname, $firstname] = Database::fetch_array($rs);
$params['teachers'] = $userId;
if (Database::num_rows($rs) > 0) {
[$userId, $lastname, $firstname] = Database::fetch_array($rs);
$params['teachers'] = $userId;
} else {
$params['teachers'] = api_get_user_id();
}
CourseManager::create_course($params);
}
}
@ -233,19 +236,35 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
}
}
$visibility = trim(api_utf8_decode($node_session->Visibility));
// Default visibility
$visibilityAfterExpirationPerSession = 1;
if (isset($node_session->VisibilityAfterExpiration)) {
$visibility = trim(api_utf8_decode($node_session->VisibilityAfterExpiration));
switch ($visibility) {
case 'read_only':
$visibilityAfterExpirationPerSession = SESSION_VISIBLE_READ_ONLY;
break;
case 'accessible':
$visibilityAfterExpirationPerSession = SESSION_VISIBLE;
break;
case 'not_accessible':
$visibilityAfterExpirationPerSession = SESSION_INVISIBLE;
break;
}
}
$sessionCategoryId = trim(api_utf8_decode($node_session->SessionCategory));
if (!$updatesession) {
if (!$isOverwrite) {
// Always create a session.
$unique_name = false; // This MUST be initializead.
$i = 0;
$suffix = '';
// Change session name, verify that session doesn't exist.
while (!$unique_name) {
if ($i > 1) {
$suffix = ' - '.$i;
}
$sql = 'SELECT 1 FROM '.$tbl_session.'
$sql = 'SELECT id FROM '.$tbl_session.'
WHERE name="'.Database::escape_string($session_name.$suffix).'"';
$rs = Database::query($sql);
if (Database::result($rs, 0, 0)) {
@ -261,7 +280,12 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
name = '".Database::escape_string($session_name)."',
access_start_date = '$date_start',
access_end_date = '$dateEnd',
visibility = '$visibility',
visibility = '$visibilityAfterExpirationPerSession',
nbr_users = 0,
nbr_courses = 0,
nbr_classes = 0,
status = 0,
duration = 0,
session_category_id = '$sessionCategoryId'";
$rs_session = Database::query($sql_session);
$sessionId = Database::insert_id();
@ -295,7 +319,12 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
name = '".Database::escape_string($session_name)."',
access_start_date = '$date_start',
access_end_date = '$dateEnd',
visibility = '$visibility',
visibility = '$visibilityAfterExpirationPerSession',
nbr_users = 0,
nbr_courses = 0,
nbr_classes = 0,
status = 0,
duration = 0,
session_category_id = '$sessionCategoryId'";
$rs_session = Database::query($sql_session);
$sessionId = Database::insert_id();
@ -325,7 +354,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$sql_session = "UPDATE $tbl_session SET
access_start_date = '$date_start',
access_end_date = '$dateEnd',
visibility = '$visibility',
visibility = '$visibilityAfterExpirationPerSession',
session_category_id = '$sessionCategoryId'
WHERE name = '$session_name'";
$rs_session = Database::query($sql_session);

Loading…
Cancel
Save