Update from 1.9.x

1.10.x
Julio 10 years ago
parent cf94e16f00
commit bad3197391
  1. 570
      main/cron/import_csv.php
  2. 30
      main/inc/lib/course.lib.php
  3. 152
      main/inc/lib/sessionmanager.lib.php

@ -78,6 +78,10 @@ class ImportCsv
*/ */
public function run() public function run()
{ {
/*
global $_configuration;
$_configuration['access_url'] = 2;
*/
$path = api_get_path(SYS_CODE_PATH).'cron/incoming/'; $path = api_get_path(SYS_CODE_PATH).'cron/incoming/';
if (!is_dir($path)) { if (!is_dir($path)) {
echo "The folder! $path does not exits"; echo "The folder! $path does not exits";
@ -94,6 +98,8 @@ class ImportCsv
$files = scandir($path); $files = scandir($path);
$fileToProcess = array(); $fileToProcess = array();
$fileToProcessStatic = array(); $fileToProcessStatic = array();
$teacherBackup = array();
$groupBackup = array();
if (!empty($files)) { if (!empty($files)) {
foreach ($files as $file) { foreach ($files as $file) {
@ -109,7 +115,7 @@ class ImportCsv
if (method_exists($this, $method)) { if (method_exists($this, $method)) {
if (($method == 'importUnsubscribeStatic' || if (($method == 'importUnsubscribeStatic' ||
$method == 'importSubscribeStatic') || $method == 'importSubscribeStatic') ||
empty($isStatic) empty($isStatic)
) { ) {
$fileToProcess[$parts[1]][] = array( $fileToProcess[$parts[1]][] = array(
@ -149,7 +155,6 @@ class ImportCsv
'subscribe-static', 'subscribe-static',
'unsubscribe-static' 'unsubscribe-static'
); );
foreach ($sections as $section) { foreach ($sections as $section) {
$this->logger->addInfo("-- Import $section --"); $this->logger->addInfo("-- Import $section --");
@ -161,7 +166,11 @@ class ImportCsv
echo 'File: '.$file.PHP_EOL; echo 'File: '.$file.PHP_EOL;
$this->logger->addInfo("Reading file: $file"); $this->logger->addInfo("Reading file: $file");
$this->$method($file, true); if ($method == 'importSessions') {
$this->$method($file, true, $teacherBackup, $groupBackup);
} else {
$this->$method($file, true);
}
} }
} }
} }
@ -186,7 +195,7 @@ class ImportCsv
$file = $fileInfo['file']; $file = $fileInfo['file'];
echo 'Static file: '.$file.PHP_EOL; echo 'Static file: '.$file.PHP_EOL;
$this->logger->addInfo("Reading static file: $file"); $this->logger->addInfo("Reading static file: $file");
$this->$method($file, true); $this->$method($file, true, $teacherBackup, $groupBackup);
} }
} }
} }
@ -224,8 +233,8 @@ class ImportCsv
$extraField = new ExtraField('calendar_event'); $extraField = new ExtraField('calendar_event');
$extraField->save(array( $extraField->save(array(
'field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_type' => ExtraField::FIELD_TYPE_TEXT,
'variable' => $this->extraFieldIdNameList['calendar_event'], 'field_variable' => $this->extraFieldIdNameList['calendar_event'],
'display_text' => 'External calendar event id' 'field_display_text' => 'External calendar event id'
)); ));
} }
@ -261,7 +270,7 @@ class ImportCsv
$row['email'] = $row['Email']; $row['email'] = $row['Email'];
$row['username'] = $row['UserName']; $row['username'] = $row['UserName'];
$row['password'] = $row['Password']; $row['password'] = $row['Password'];
$row['auth_source'] = $row['AuthSource']; $row['auth_source'] = isset($row['AuthSource']) ? $row['AuthSource'] : PLATFORM_AUTH_SOURCE;
$row['official_code'] = $row['OfficialCode']; $row['official_code'] = $row['OfficialCode'];
$row['phone'] = $row['PhoneNumber']; $row['phone'] = $row['PhoneNumber'];
@ -326,7 +335,7 @@ class ImportCsv
*/ */
private function importTeachers($file, $moveFile = true) private function importTeachers($file, $moveFile = true)
{ {
$data = Import::csvToArray($file); $data = Import::csv_to_array($file);
/* Unique identifier: official-code username. /* Unique identifier: official-code username.
Email address and password should never get updated. *ok Email address and password should never get updated. *ok
@ -370,7 +379,7 @@ class ImportCsv
$language, //$row['language'], $language, //$row['language'],
$row['phone'], $row['phone'],
null, //$row['picture'], //picture null, //$row['picture'], //picture
PLATFORM_AUTH_SOURCE, // ? $row['auth_source'], // ?
$expirationDate, //'0000-00-00 00:00:00', //$row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00', $expirationDate, //'0000-00-00 00:00:00', //$row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00',
1, //active 1, //active
0, 0,
@ -405,7 +414,7 @@ class ImportCsv
$row['lastname'], // <<-- changed $row['lastname'], // <<-- changed
$userInfo['username'], $userInfo['username'],
null, //$password = null, null, //$password = null,
PLATFORM_AUTH_SOURCE, $row['auth_source'],
$userInfo['email'], $userInfo['email'],
COURSEMANAGER, COURSEMANAGER,
$userInfo['official_code'], $userInfo['official_code'],
@ -446,7 +455,6 @@ class ImportCsv
} }
} }
/** /**
* @param string $file * @param string $file
*/ */
@ -461,9 +469,7 @@ class ImportCsv
*/ */
private function importStudents($file, $moveFile = true) private function importStudents($file, $moveFile = true)
{ {
$data = Import::csvToArray($file); $data = Import::csv_to_array($file);
$userRepository = UserManager::getRepository();
/* /*
* Another users import. * Another users import.
@ -474,7 +480,8 @@ class ImportCsv
All other fields should be updateable, though passwords should of course not get updated. ok All other fields should be updateable, though passwords should of course not get updated. ok
If a user gets deleted (not there anymore), If a user gets deleted (not there anymore),
He should be set inactive one year after the current date. He should be set inactive one year after the current date.
So I presume you’ll just update the expiration date. We want to grant access to courses up to a year after deletion. So I presume you’ll just update the expiration date.
We want to grant access to courses up to a year after deletion.
*/ */
if (!empty($data)) { if (!empty($data)) {
@ -509,7 +516,7 @@ class ImportCsv
$language, //$row['language'], $language, //$row['language'],
$row['phone'], $row['phone'],
null, //$row['picture'], //picture null, //$row['picture'], //picture
PLATFORM_AUTH_SOURCE, // ? $row['auth_source'], // ?
$expirationDate, //'0000-00-00 00:00:00', //$row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00', $expirationDate, //'0000-00-00 00:00:00', //$row['expiration_date'], //$expiration_date = '0000-00-00 00:00:00',
1, //active 1, //active
0, 0,
@ -530,6 +537,7 @@ class ImportCsv
$this->logger->addError("Students - User NOT created: ".$row['username']." ".$row['firstname']." ".$row['lastname']); $this->logger->addError("Students - User NOT created: ".$row['username']." ".$row['firstname']." ".$row['lastname']);
} }
} else { } else {
if (empty($userInfo)) { if (empty($userInfo)) {
$this->logger->addError("Students - Can't update user :".$row['username']); $this->logger->addError("Students - Can't update user :".$row['username']);
continue; continue;
@ -560,27 +568,19 @@ class ImportCsv
} }
// 2. Condition // 2. Condition
if (!in_array($userInfo['email'], $avoidUsersWithEmail) && if (!in_array($userInfo['email'], $avoidUsersWithEmail) && !in_array($row['email'], $avoidUsersWithEmail)) {
!in_array($row['email'], $avoidUsersWithEmail)
) {
$email = $userInfo['email']; $email = $userInfo['email'];
} }
// 3. Condition // 3. Condition
if (in_array($userInfo['email'], $avoidUsersWithEmail) && if (in_array($userInfo['email'], $avoidUsersWithEmail) && !in_array($row['email'], $avoidUsersWithEmail)) {
!in_array($row['email'], $avoidUsersWithEmail)
) {
$email = $row['email']; $email = $row['email'];
} }
// Blocking password update // Blocking password update
$avoidUsersWithPassword = $this->conditions['importStudents']['update']['avoid']['password']; $avoidUsersWithPassword = $this->conditions['importStudents']['update']['avoid']['password'];
$user = $userRepository->find($userInfo['user_id']); if ($userInfo['password'] != api_get_encrypted_password($row['password']) && in_array($row['password'], $avoidUsersWithPassword)) {
if ($userInfo['password'] != UserManager::encryptPassword($row['password'], $user) &&
in_array($row['password'], $avoidUsersWithPassword)
) {
$this->logger->addInfo("Students - User password is not updated: ".$row['username']." because the avoid conditions (password)."); $this->logger->addInfo("Students - User password is not updated: ".$row['username']." because the avoid conditions (password).");
$password = null; $password = null;
$resetPassword = 0; // disallow password change $resetPassword = 0; // disallow password change
@ -597,7 +597,7 @@ class ImportCsv
$row['lastname'], // <<-- changed $row['lastname'], // <<-- changed
$row['username'], // <<-- changed $row['username'], // <<-- changed
$password, //$password = null, $password, //$password = null,
PLATFORM_AUTH_SOURCE, $row['auth_source'],
$email, $email,
STUDENT, STUDENT,
$userInfo['official_code'], $userInfo['official_code'],
@ -615,6 +615,7 @@ class ImportCsv
); );
if ($result) { if ($result) {
if ($row['username'] != $userInfo['username']) { if ($row['username'] != $userInfo['username']) {
$this->logger->addInfo("Students - Username was changes from '".$userInfo['username']."' to '".$row['username']."' "); $this->logger->addInfo("Students - Username was changes from '".$userInfo['username']."' to '".$row['username']."' ");
} }
@ -645,9 +646,9 @@ class ImportCsv
/** /**
* @param string $file * @param string $file
*/ */
private function importCoursesStatic($file) private function importCoursesStatic($file, $moveFile, &$teacherBackup = array(), &$groupBackup = array())
{ {
$this->importCourses($file, false); $this->importCourses($file, false, $teacherBackup, $groupBackup);
} }
/** /**
@ -658,29 +659,7 @@ class ImportCsv
*/ */
private function importCalendarStatic($file, $moveFile = true) private function importCalendarStatic($file, $moveFile = true)
{ {
$data = Import::csvToArray($file); $data = Import::csv_to_array($file);
if ($this->getDumpValues()) {
// Remove all calendar items
$truncateTables = array(
Database::get_course_table(TABLE_AGENDA),
Database::get_course_table(TABLE_AGENDA_ATTACHMENT),
Database::get_course_table(TABLE_AGENDA_REPEAT),
Database::get_course_table(TABLE_AGENDA_REPEAT_NOT),
Database::get_main_table(TABLE_PERSONAL_AGENDA),
Database::get_main_table(TABLE_PERSONAL_AGENDA_REPEAT_NOT),
Database::get_main_table(TABLE_PERSONAL_AGENDA_REPEAT)
);
foreach ($truncateTables as $table) {
$sql = "TRUNCATE $table";
Database::query($sql);
}
$table = Database::get_course_table(TABLE_ITEM_PROPERTY);
$sql = "DELETE FROM $table WHERE tool = 'calendar_event'";
Database::query($sql);
}
if (!empty($data)) { if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found."); $this->logger->addInfo(count($data) . " records found.");
@ -691,7 +670,7 @@ class ImportCsv
$externalSessionId = null; $externalSessionId = null;
if (isset($row['external_sessionID'])) { if (isset($row['external_sessionID'])) {
$externalSessionId = $row['external_sessionID']; $externalSessionId = $row['external_sessionID'];
$sessionId = SessionManager::getSessionIdFromOriginalId( $sessionId = SessionManager::get_session_id_from_original_id(
$externalSessionId, $externalSessionId,
$this->extraFieldIdNameList['session'] $this->extraFieldIdNameList['session']
); );
@ -715,7 +694,7 @@ class ImportCsv
if (!empty($sessionId) && !empty($courseInfo)) { if (!empty($sessionId) && !empty($courseInfo)) {
$courseIncluded = SessionManager::relation_session_course_exist( $courseIncluded = SessionManager::relation_session_course_exist(
$sessionId, $sessionId,
$courseInfo['real_id'] $courseInfo['code']
); );
if ($courseIncluded == false) { if ($courseIncluded == false) {
@ -754,6 +733,8 @@ class ImportCsv
$startTime = $row['time_start']; $startTime = $row['time_start'];
$endTime = $row['time_end']; $endTime = $row['time_end'];
$title = $row['title']; $title = $row['title'];
$comment = $row['comment'];
$color = isset($row['color']) ? $row['color'] : '';
$startDateYear = substr($date, 0, 4); $startDateYear = substr($date, 0, 4);
$startDateMonth = substr($date, 4, 2); $startDateMonth = substr($date, 4, 2);
@ -762,13 +743,18 @@ class ImportCsv
$startDate = $startDateYear.'-'.$startDateMonth.'-'.$startDateDay.' '.$startTime.":00"; $startDate = $startDateYear.'-'.$startDateMonth.'-'.$startDateDay.' '.$startTime.":00";
$endDate = $startDateYear.'-'.$startDateMonth.'-'.$startDateDay.' '.$endTime.":00"; $endDate = $startDateYear.'-'.$startDateMonth.'-'.$startDateDay.' '.$endTime.":00";
if (!api_is_valid_date($startDate) OR !api_is_valid_date($endDate)) { if (!api_is_valid_date($startDate) || !api_is_valid_date($endDate)) {
$this->logger->addInfo( $this->logger->addInfo(
"Verify your dates: '$startDate' : '$endDate' " "Verify your dates: '$startDate' : '$endDate' "
); );
$errorFound = true; $errorFound = true;
} }
// If old events do nothing.
/*if (api_strtotime($startDate) < time()) {
continue;
}*/
if ($errorFound == false) { if ($errorFound == false) {
$eventsToCreate[] = array( $eventsToCreate[] = array(
'start' => $startDate, 'start' => $startDate,
@ -777,6 +763,8 @@ class ImportCsv
'sender_id' => $teacherId, 'sender_id' => $teacherId,
'course_id' => $courseInfo['real_id'], 'course_id' => $courseInfo['real_id'],
'session_id' => $sessionId, 'session_id' => $sessionId,
'comment' => $comment,
'color' => $color,
$this->extraFieldIdNameList['calendar_event'] => $row['external_calendar_itemID'] $this->extraFieldIdNameList['calendar_event'] => $row['external_calendar_itemID']
); );
} }
@ -794,7 +782,6 @@ class ImportCsv
"Ready to insert events" "Ready to insert events"
); );
$content = null;
$agenda = new Agenda(); $agenda = new Agenda();
$extraFieldValue = new ExtraFieldValue('calendar_event'); $extraFieldValue = new ExtraFieldValue('calendar_event');
@ -813,6 +800,8 @@ class ImportCsv
} }
foreach ($eventsToCreate as $event) { foreach ($eventsToCreate as $event) {
$update = false;
$item = null;
if (!isset($event[$extraFieldName])) { if (!isset($event[$extraFieldName])) {
$this->logger->addInfo( $this->logger->addInfo(
"No external_calendar_itemID found. Skipping ..." "No external_calendar_itemID found. Skipping ..."
@ -820,16 +809,34 @@ class ImportCsv
continue; continue;
} else { } else {
$externalEventId = $event[$extraFieldName]; $externalEventId = $event[$extraFieldName];
$item = $extraFieldValue->get_item_id_from_field_variable_and_field_value( if (empty($externalEventId)) {
$this->logger->addInfo(
"external_calendar_itemID was set but empty. Skipping ..."
);
continue;
}
$items = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
$extraFieldName, $extraFieldName,
$externalEventId $externalEventId,
false,
false,
true
); );
if (!empty($item) || empty($externalEventId)) { $item = null;
foreach ($items as $tempItem) {
if ($tempItem['c_id'] == $event['course_id']) {
$item = $tempItem;
}
}
if (!empty($item)) {
$this->logger->addInfo( $this->logger->addInfo(
"Event #$externalEventId was already added . Skipping ..." "Event #$externalEventId was already added. Updating ..."
); );
continue; $update = true;
//continue;
} }
} }
@ -841,6 +848,11 @@ class ImportCsv
$agenda->setIsAllowedToEdit(true); $agenda->setIsAllowedToEdit(true);
$eventComment = $event['comment']; $eventComment = $event['comment'];
$color = $event['color'];
// To use the event comment you need
// ALTER TABLE c_calendar_event ADD COLUMN comment TEXT;
// add in configuration.php allow_agenda_event_comment = true
if (empty($courseInfo)) { if (empty($courseInfo)) {
$this->logger->addInfo( $this->logger->addInfo(
@ -856,35 +868,66 @@ class ImportCsv
continue; continue;
} }
$eventId = $agenda->addEvent( $content = '';
$event['start'],
$event['end'], if ($update && isset($item['calendar_event_id'])) {
false, //the event already exists, just update
$event['title'], $eventId = $agenda->edit_event(
$content, $item['calendar_event_id'],
array('everyone'), // send to $event['start'],
false, //$addAsAnnouncement = false $event['end'],
null, // $parentEventId false,
array(), //$attachmentArray = array(), $event['title'],
null, //$attachmentComment = null, $content,
$eventComment array('everyone'), // send to
); array(), //$attachmentArray = array(),
null, //$attachmentComment = null,
if (!empty($eventId)) { $eventComment,
$extraFieldValue->save( $color
array(
'value' => $externalEventId,
'field_id' => $extraFieldInfo['id'],
'item_id' => $eventId
)
);
$this->logger->addInfo(
"Event added: #$eventId"
); );
if ($eventId !== false) {
$this->logger->addInfo(
"Event updated: #$eventId"
);
} else {
$this->logger->addInfo(
"Error while updating event."
);
}
} else { } else {
$this->logger->addInfo( // New event. Create it.
"Error while creating event." $eventId = $agenda->add_event(
$event['start'],
$event['end'],
false,
$event['title'],
$content,
array('everyone'), // send to
false, //$addAsAnnouncement = false
null, // $parentEventId
array(), //$attachmentArray = array(),
null, //$attachmentComment = null,
$eventComment,
$color
); );
if (!empty($eventId)) {
$extraFieldValue->is_course_model = true;
$extraFieldValue->save(
array(
'field_value' => $externalEventId,
'field_id' => $extraFieldInfo['id'],
'calendar_event_id' => $eventId,
'c_id' => $event['course_id']
)
);
$this->logger->addInfo(
"Event added: #$eventId"
);
} else {
$this->logger->addInfo(
"Error while creating event."
);
}
} }
} }
} }
@ -897,10 +940,12 @@ class ImportCsv
/** /**
* @param string $file * @param string $file
* @param bool $moveFile * @param bool $moveFile
* @param array $teacherBackup
* @param array $groupBackup
*/ */
private function importCourses($file, $moveFile = true) private function importCourses($file, $moveFile = true, &$teacherBackup = array(), &$groupBackup = array())
{ {
$data = Import::csvToArray($file); $data = Import::csv_to_array($file);
if (!empty($data)) { if (!empty($data)) {
$this->logger->addInfo(count($data)." records found."); $this->logger->addInfo(count($data)." records found.");
@ -908,12 +953,12 @@ class ImportCsv
foreach ($data as $row) { foreach ($data as $row) {
$row = $this->cleanCourseRow($row); $row = $this->cleanCourseRow($row);
$courseId = CourseManager::getCourseInfoFromOriginalId( $courseCode = CourseManager::get_course_id_from_original_id(
$row['extra_' . $this->extraFieldIdNameList['course']], $row['extra_' . $this->extraFieldIdNameList['course']],
$this->extraFieldIdNameList['course'] $this->extraFieldIdNameList['course']
); );
$courseInfo = api_get_course_info_by_id($courseId); $courseInfo = api_get_course_info($courseCode);
if (empty($courseInfo)) { if (empty($courseInfo)) {
// Create // Create
@ -942,16 +987,66 @@ class ImportCsv
// Update // Update
$params = array( $params = array(
'title' => $row['title'], 'title' => $row['title'],
'category_code' => $row['course_category']
); );
$result = CourseManager::update_attributes($courseInfo['real_id'], $params); $result = CourseManager::update_attributes(
$courseInfo['real_id'],
$params
);
$addTeacherToSession = isset($courseInfo['add_teachers_to_sessions_courses']) && !empty($courseInfo['add_teachers_to_sessions_courses']) ? true : false; $addTeacherToSession = isset($courseInfo['add_teachers_to_sessions_courses']) && !empty($courseInfo['add_teachers_to_sessions_courses']) ? true : false;
$teachers = $row['teachers'];
if (!is_array($teachers)) {
$teachers = array($teachers);
}
if ($addTeacherToSession) { if ($addTeacherToSession) {
CourseManager::updateTeachers($courseInfo['real_id'], $row['teachers'], false, true, false); CourseManager::updateTeachers(
$courseInfo['id'],
$row['teachers'],
false,
true,
false,
$teacherBackup
);
} else { } else {
CourseManager::updateTeachers($courseInfo['real_id'], $row['teachers'], false, false); CourseManager::updateTeachers(
$courseInfo['id'],
$row['teachers'],
false,
false,
false,
$teacherBackup
);
}
foreach ($teachers as $teacherId) {
if (isset($groupBackup['tutor'][$teacherId]) &&
isset($groupBackup['tutor'][$teacherId][$courseInfo['code']])
) {
foreach ($groupBackup['tutor'][$teacherId][$courseInfo['code']] as $data) {
GroupManager::subscribe_tutors(
array($teacherId),
$data['group_id'],
$data['c_id']
);
}
}
if (isset($groupBackup['user'][$teacherId]) &&
isset($groupBackup['user'][$teacherId][$courseInfo['code']]) &&
!empty($groupBackup['user'][$teacherId][$courseInfo['code']])
) {
foreach ($groupBackup['user'][$teacherId][$courseInfo['code']] as $data) {
GroupManager::subscribe_users(
array($teacherId),
$data['group_id'],
$data['c_id']
);
}
}
} }
if ($result) { if ($result) {
@ -1012,7 +1107,7 @@ class ImportCsv
// Looping the sessions. // Looping the sessions.
foreach ($sessions as $session) { foreach ($sessions as $session) {
if (!empty($session['SessionID'])) { if (!empty($session['SessionID'])) {
$sessionId = SessionManager::getSessionIdFromOriginalId( $sessionId = SessionManager::get_session_id_from_original_id(
$session['SessionID'], $session['SessionID'],
$this->extraFieldIdNameList['session'] $this->extraFieldIdNameList['session']
); );
@ -1021,8 +1116,8 @@ class ImportCsv
$categoryId = isset($session['category_id']) ? $session['category_id'] : null; $categoryId = isset($session['category_id']) ? $session['category_id'] : null;
// 2014-06-30 // 2014-06-30
$dateStart = str_replace('/', '-', $session['DateStart']); $dateStart = explode('/', $session['DateStart']);
$dateEnd = str_replace('/', '-', $session['DateEnd']); $dateEnd = explode('/', $session['DateEnd']);
$visibility = $this->defaultSessionVisibility; $visibility = $this->defaultSessionVisibility;
$coachId = null; $coachId = null;
@ -1031,30 +1126,22 @@ class ImportCsv
$coachId = $coachInfo['user_id']; $coachId = $coachInfo['user_id'];
} }
$coachStartDate = null;
if (!empty($this->daysCoachAccessBeforeBeginning)) {
$day = intval($this->daysCoachAccessBeforeBeginning);
$coachStartDate = date('Y-m-d ', strtotime($dateStart. ' + '.$day.' days'));
}
$coachEndDate = null;
if (!empty($this->daysCoachAccessAfterBeginning)) {
$day = intval($this->daysCoachAccessAfterBeginning);
$coachEndDate = date('Y-m-d ', strtotime($dateEnd. ' + '.$day.' days'));
}
if (empty($sessionId)) { if (empty($sessionId)) {
$result = SessionManager::create_session( $result = SessionManager::create_session(
$session['SessionName'], $session['SessionName'],
$dateStart, $dateStart[0],
$dateEnd, $dateStart[1],
$dateStart, $dateStart[2],
$dateEnd, $dateEnd[0],
$coachStartDate, $dateEnd[1],
$coachEndDate, $dateEnd[2],
$coachId, $this->daysCoachAccessBeforeBeginning,
$this->daysCoachAccessAfterBeginning,
null,
$coachUserName,
$categoryId, $categoryId,
$visibility $visibility,
1
); );
if (is_numeric($result)) { if (is_numeric($result)) {
@ -1068,21 +1155,43 @@ class ImportCsv
} else { } else {
$sessionInfo = api_get_session_info($sessionId); $sessionInfo = api_get_session_info($sessionId);
$accessBefore = null;
$accessAfter = null;
if (empty($sessionInfo['nb_days_access_before_beginning']) ||
(!empty($sessionInfo['nb_days_access_before_beginning']) &&
$sessionInfo['nb_days_access_before_beginning'] < $this->daysCoachAccessBeforeBeginning)
) {
$accessBefore = intval($this->daysCoachAccessBeforeBeginning);
}
$accessAfter = null;
if (empty($sessionInfo['nb_days_access_after_end']) ||
(!empty($sessionInfo['nb_days_access_after_end']) &&
$sessionInfo['nb_days_access_after_end'] < $this->daysCoachAccessAfterBeginning)
) {
$accessAfter = intval($this->daysCoachAccessAfterBeginning);
}
$showDescription = isset($sessionInfo['show_description']) ? $sessionInfo['show_description'] : 1; $showDescription = isset($sessionInfo['show_description']) ? $sessionInfo['show_description'] : 1;
$result = SessionManager::edit_session( $result = SessionManager::edit_session(
$sessionId, $sessionId,
$session['SessionName'], $session['SessionName'],
$dateStart, $dateStart[0],
$dateEnd, $dateStart[1],
$dateStart, $dateStart[2],
$dateEnd, $dateEnd[0],
$sessionInfo['coach_access_start_date'], $dateEnd[1],
$sessionInfo['coach_access_end_date'], $dateEnd[2],
$accessBefore,
$accessAfter,
null,
$coachId, $coachId,
$categoryId, $categoryId,
$visibility, $visibility,
true, //$start_limit =
true, //$end_limit =
null, //$description null, //$description
$showDescription // $showDescription = null, $showDescription // $showDescription = null,
); );
@ -1101,7 +1210,6 @@ class ImportCsv
} }
// Courses // Courses
$courses = explode('|', $session['Courses']); $courses = explode('|', $session['Courses']);
$courseList = array(); $courseList = array();
foreach ($courses as $course) { foreach ($courses as $course) {
@ -1123,8 +1231,6 @@ class ImportCsv
foreach ($courses as $course) { foreach ($courses as $course) {
$courseArray = bracketsToArray($course); $courseArray = bracketsToArray($course);
$courseCode = $courseArray[0]; $courseCode = $courseArray[0];
$courseInfo = api_get_course_info($courseCode);
if (CourseManager::course_exists($courseCode)) { if (CourseManager::course_exists($courseCode)) {
// Coaches // Coaches
$courseCoaches = isset($courseArray[1]) ? $courseArray[1] : null; $courseCoaches = isset($courseArray[1]) ? $courseArray[1] : null;
@ -1141,7 +1247,7 @@ class ImportCsv
} }
SessionManager::updateCoaches( SessionManager::updateCoaches(
$sessionId, $sessionId,
$courseInfo['real_id'], $courseCode,
$coachList, $coachList,
true true
); );
@ -1150,7 +1256,6 @@ class ImportCsv
// Students // Students
$courseUsers = isset($courseArray[2]) ? $courseArray[2] : null; $courseUsers = isset($courseArray[2]) ? $courseArray[2] : null;
$courseUsers = explode(',', $courseUsers); $courseUsers = explode(',', $courseUsers);
if (!empty($courseUsers)) { if (!empty($courseUsers)) {
$userList = array(); $userList = array();
foreach ($courseUsers as $username) { foreach ($courseUsers as $username) {
@ -1189,8 +1294,10 @@ class ImportCsv
/** /**
* @param string $file * @param string $file
* @param bool $moveFile * @param bool $moveFile
* @param array $teacherBackup
* @param array $groupBackup
*/ */
private function importSessions($file, $moveFile = true) private function importSessions($file, $moveFile = true, &$teacherBackup = array(), &$groupBackup = array())
{ {
$avoid = null; $avoid = null;
if (isset($this->conditions['importSessions']) && if (isset($this->conditions['importSessions']) &&
@ -1214,7 +1321,9 @@ class ImportCsv
true, // sessionWithCoursesModifier true, // sessionWithCoursesModifier
true, //$addOriginalCourseTeachersAsCourseSessionCoaches true, //$addOriginalCourseTeachersAsCourseSessionCoaches
true, //$removeAllTeachersFromCourse true, //$removeAllTeachersFromCourse
1 // $showDescription 1, // $showDescription,
$teacherBackup,
$groupBackup
); );
if (!empty($result['error_message'])) { if (!empty($result['error_message'])) {
@ -1255,7 +1364,7 @@ class ImportCsv
continue; continue;
} }
$userId = UserManager::get_user_id_from_username($chamiloUserName); $userId = Usermanager::get_user_id_from_username($chamiloUserName);
if (empty($userId)) { if (empty($userId)) {
$this->logger->addError('User does not exists: '.$chamiloUserName); $this->logger->addError('User does not exists: '.$chamiloUserName);
@ -1276,7 +1385,7 @@ class ImportCsv
SessionManager::set_coach_to_course_session( SessionManager::set_coach_to_course_session(
$userId, $userId,
$chamiloSessionId, $chamiloSessionId,
$courseInfo['real_id'] $courseInfo['code']
); );
break; break;
} }
@ -1291,7 +1400,7 @@ class ImportCsv
/** /**
* @param string $file * @param string $file
*/ */
private function importUnsubscribeStatic($file) private function importUnsubscribeStatic($file, $moveFile = false, &$teacherBackup = array(), &$groupBackup = array())
{ {
$data = Import::csv_reader($file); $data = Import::csv_reader($file);
@ -1315,14 +1424,50 @@ class ImportCsv
continue; continue;
} }
$userId = UserManager::get_user_id_from_username($chamiloUserName); $userId = Usermanager::get_user_id_from_username($chamiloUserName);
if (empty($userId)) { if (empty($userId)) {
$this->logger->addError('User does not exists: '.$chamiloUserName); $this->logger->addError('User does not exists: '.$chamiloUserName);
continue; continue;
} }
CourseManager::unsubscribe_user($userId, $courseInfo['code'], $chamiloSessionId); $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
WHERE
user_id = ".$userId." AND
course_code = '".$courseInfo['code']."'
";
$result = Database::query($sql);
$userCourseData = Database::fetch_array($result, 'ASSOC');
$teacherBackup[$userId][$courseInfo['code']] = $userCourseData;
$sql = "SELECT * FROM ".Database::get_course_table(TABLE_GROUP_USER)."
WHERE
user_id = ".$userId." AND
c_id = '".$courseInfo['real_id']."'
";
$result = Database::query($sql);
while ($groupData = Database::fetch_array($result, 'ASSOC')) {
$groupBackup['user'][$userId][$courseInfo['code']][$groupData['group_id']] = $groupData;
}
$sql = "SELECT * FROM ".Database::get_course_table(TABLE_GROUP_TUTOR)."
WHERE
user_id = ".$userId." AND
c_id = '".$courseInfo['real_id']."'
";
$result = Database::query($sql);
while ($groupData = Database::fetch_array($result, 'ASSOC')) {
$groupBackup['tutor'][$userId][$courseInfo['code']][$groupData['group_id']] = $groupData;
}
CourseManager::unsubscribe_user(
$userId,
$courseInfo['code'],
$chamiloSessionId
);
$this->logger->addError( $this->logger->addError(
"User '$chamiloUserName' was removed from session: #$chamiloSessionId, Course: ".$courseInfo['code'] "User '$chamiloUserName' was removed from session: #$chamiloSessionId, Course: ".$courseInfo['code']
); );
@ -1345,65 +1490,108 @@ class ImportCsv
Database::query($sql); Database::query($sql);
echo $sql.PHP_EOL; echo $sql.PHP_EOL;
// Course // Truncate tables
$table = Database::get_main_table(TABLE_MAIN_COURSE); $truncateTables = array(
$sql = "DELETE FROM $table"; Database::get_main_table(TABLE_MAIN_COURSE),
Database::query($sql); Database::get_main_table(TABLE_MAIN_COURSE_USER),
echo $sql.PHP_EOL; Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE),
Database::get_main_table(TABLE_MAIN_CATEGORY),
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); Database::get_main_table(TABLE_MAIN_COURSE_MODULE),
$sql = "DELETE FROM $table"; Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER),
Database::query($sql); Database::get_main_table(TABLE_MAIN_SESSION),
echo $sql.PHP_EOL; Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY),
Database::get_main_table(TABLE_MAIN_SESSION_COURSE),
$table = Database::get_main_table(TABLE_MAIN_COURSE_USER); Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER),
$sql = "DELETE FROM $table"; Database::get_main_table(TABLE_MAIN_SESSION_USER),
Database::query($sql); Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION),
echo $sql.PHP_EOL; Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES),
Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES),
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES),
$sql = "DELETE FROM $table"; Database::get_main_table(TABLE_MAIN_USER_FIELD),
Database::query($sql); Database::get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS),
echo $sql.PHP_EOL; Database::get_main_table(TABLE_MAIN_COURSE_FIELD),
Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES),
// Sessions Database::get_main_table(TABLE_MAIN_SESSION_FIELD),
$table = Database::get_main_table(TABLE_MAIN_SESSION); Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES),
$sql = "DELETE FROM $table"; Database::get_course_table(TABLE_AGENDA),
Database::query($sql); Database::get_course_table(TABLE_AGENDA_ATTACHMENT),
echo $sql.PHP_EOL; Database::get_course_table(TABLE_AGENDA_REPEAT),
Database::get_course_table(TABLE_AGENDA_REPEAT_NOT),
$table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY); Database::get_main_table(TABLE_PERSONAL_AGENDA),
$sql = "DELETE FROM $table"; Database::get_main_table(TABLE_PERSONAL_AGENDA_REPEAT_NOT),
Database::query($sql); Database::get_main_table(TABLE_PERSONAL_AGENDA_REPEAT),
echo $sql.PHP_EOL; Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_VALUES),
Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS),
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS),
$sql = "DELETE FROM $table"; Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN),
Database::query($sql); Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS),
echo $sql.PHP_EOL; Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES),
Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT),
$table = Database::get_main_table(TABLE_MAIN_SESSION_USER); Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING),
$sql = "DELETE FROM $table"; Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT),
Database::query($sql); Database::get_main_table(TABLE_STATISTIC_TRACK_E_UPLOADS),
echo $sql.PHP_EOL; Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT),
Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY),
$table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY),
$sql = "DELETE FROM $table"; Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION),
Database::query($sql); Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG),
echo $sql.PHP_EOL; Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT),
Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT_LOG),
Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK),
Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY),
Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE),
Database::get_course_table(TABLE_STUDENT_PUBLICATION),
Database::get_course_table(TABLE_QUIZ_QUESTION),
Database::get_course_table(TABLE_QUIZ_TEST),
Database::get_course_table(TABLE_QUIZ_ORDER),
Database::get_course_table(TABLE_QUIZ_ANSWER),
Database::get_course_table(TABLE_QUIZ_TEST_QUESTION),
Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION),
Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY),
Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY),
Database::get_course_table(TABLE_LP_MAIN),
Database::get_course_table(TABLE_LP_ITEM),
Database::get_course_table(TABLE_LP_VIEW),
Database::get_course_table(TABLE_LP_ITEM_VIEW),
Database::get_course_table(TABLE_DOCUMENT),
Database::get_course_table(TABLE_ITEM_PROPERTY),
Database::get_course_table(TABLE_TOOL_LIST),
Database::get_course_table(TABLE_TOOL_INTRO),
Database::get_course_table(TABLE_COURSE_SETTING),
Database::get_course_table(TABLE_SURVEY),
Database::get_course_table(TABLE_SURVEY_QUESTION),
Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION),
Database::get_course_table(TABLE_SURVEY_INVITATION),
Database::get_course_table(TABLE_SURVEY_ANSWER),
Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP),
Database::get_course_table(TABLE_SURVEY_REPORT),
Database::get_course_table(TABLE_GLOSSARY),
Database::get_course_table(TABLE_LINK),
Database::get_course_table(TABLE_LINK_CATEGORY),
Database::get_course_table(TABLE_GROUP),
Database::get_course_table(TABLE_GROUP_USER),
Database::get_course_table(TABLE_GROUP_TUTOR),
Database::get_course_table(TABLE_GROUP_CATEGORY),
Database::get_course_table(TABLE_DROPBOX_CATEGORY),
Database::get_course_table(TABLE_DROPBOX_FEEDBACK),
Database::get_course_table(TABLE_DROPBOX_POST),
Database::get_course_table(TABLE_DROPBOX_FILE),
Database::get_course_table(TABLE_DROPBOX_PERSON)
);
// Extra fields foreach ($truncateTables as $table) {
$table = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); $sql = "TRUNCATE $table";
$sql = "DELETE FROM $table"; Database::query($sql);
Database::query($sql); echo $sql.PHP_EOL;
echo $sql.PHP_EOL; }
} }
} }
use Monolog\Handler\BufferHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\NativeMailerHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\BufferHandler;
$logger = new Logger('cron'); $logger = new Logger('cron');
$emails = isset($_configuration['cron_notification_mails']) ? $_configuration['cron_notification_mails'] : null; $emails = isset($_configuration['cron_notification_mails']) ? $_configuration['cron_notification_mails'] : null;
@ -1467,7 +1655,7 @@ if (isset($_configuration['import_csv_fix_permissions']) &&
echo "Executing: ".$command.PHP_EOL; echo "Executing: ".$command.PHP_EOL;
system($command); system($command);
$command = "sudo find ".api_get_path(SYS_UPLOAD_PATH)."users -type d -exec chmod 777 {} \;"; $command = "sudo find ".api_get_path(SYS_CODE_PATH)."upload/users -type d -exec chmod 777 {} \;";
echo "Executing: ".$command.PHP_EOL; echo "Executing: ".$command.PHP_EOL;
system($command); system($command);
} }

@ -1843,8 +1843,8 @@ class CourseManager
$course_code, $course_code,
$separator = self::USER_SEPARATOR, $separator = self::USER_SEPARATOR,
$add_link_to_profile = false, $add_link_to_profile = false,
$orderList = false $orderList = false
) { ) {
$teacher_list = self::get_teacher_list_from_course_code($course_code); $teacher_list = self::get_teacher_list_from_course_code($course_code);
$teacher_string = ''; $teacher_string = '';
$html = ''; $html = '';
@ -1868,7 +1868,7 @@ class CourseManager
} }
$list[] = $teacher_name; $list[] = $teacher_name;
} }
if (!empty($list)) { if (!empty($list)) {
if ($orderList === true){ if ($orderList === true){
$html .= '<ul class="user-teacher">'; $html .= '<ul class="user-teacher">';
@ -1881,7 +1881,7 @@ class CourseManager
} }
} }
} }
return $html; return $html;
} }
@ -1946,7 +1946,7 @@ class CourseManager
$courseId = null, $courseId = null,
$separator = self::USER_SEPARATOR, $separator = self::USER_SEPARATOR,
$add_link_to_profile = false, $add_link_to_profile = false,
$orderList = false $orderList = false
) { ) {
$coachs_course = self::get_coachs_from_course($session_id, $courseId); $coachs_course = self::get_coachs_from_course($session_id, $courseId);
$course_coachs = array(); $course_coachs = array();
@ -1969,7 +1969,7 @@ class CourseManager
} }
} }
$coaches_to_string = null; $coaches_to_string = null;
if (!empty($course_coachs)) { if (!empty($course_coachs)) {
if ($orderList === true){ if ($orderList === true){
$html .= '<ul class="user-coachs">'; $html .= '<ul class="user-coachs">';
@ -1980,9 +1980,9 @@ class CourseManager
} else { } else {
$coaches_to_string = array_to_string($course_coachs, $separator); $coaches_to_string = array_to_string($course_coachs, $separator);
} }
} }
return $html; return $html;
} }
@ -4846,7 +4846,8 @@ class CourseManager
$teachers, $teachers,
$deleteTeachersNotInList = true, $deleteTeachersNotInList = true,
$editTeacherInSessions = false, $editTeacherInSessions = false,
$deleteSessionTeacherNotInList = false $deleteSessionTeacherNotInList = false,
$teacherBackup = array()
) { ) {
if (empty($teachers)) { if (empty($teachers)) {
return false; return false;
@ -4888,6 +4889,14 @@ class CourseManager
$sql = 'UPDATE ' . $course_user_table . ' SET status = "1" $sql = 'UPDATE ' . $course_user_table . ' SET status = "1"
WHERE c_id = "' . $courseId . '" AND user_id = "' . $userId . '" '; WHERE c_id = "' . $courseId . '" AND user_id = "' . $userId . '" ';
} else { } else {
$userCourseCategory = '0';
if (isset($teacherBackup[$userId]) &&
isset($teacherBackup[$userId][$course_code])
) {
$courseUserData = $teacherBackup[$userId][$course_code];
$userCourseCategory = $courseUserData['user_course_cat'];
}
$sql = "INSERT INTO " . $course_user_table . " SET $sql = "INSERT INTO " . $course_user_table . " SET
c_id = " . $courseId . ", c_id = " . $courseId . ",
user_id = " . $userId . ", user_id = " . $userId . ",
@ -4895,7 +4904,8 @@ class CourseManager
is_tutor = '0', is_tutor = '0',
sort = '0', sort = '0',
relation_type = '0', relation_type = '0',
user_course_cat='0'"; user_course_cat = '$userCourseCategory'
";
} }
Database::query($sql); Database::query($sql);
} }

@ -2024,7 +2024,6 @@ class SessionManager
// Get the list of courses related to this session // Get the list of courses related to this session
$course_list = SessionManager::get_course_list_by_session_id($session_id); $course_list = SessionManager::get_course_list_by_session_id($session_id);
if (!empty($course_list)) { if (!empty($course_list)) {
foreach ($course_list as $course) { foreach ($course_list as $course) {
$courseId = $course['id']; $courseId = $course['id'];
@ -3986,6 +3985,8 @@ class SessionManager
* @param bool $updateCourseCoaches * @param bool $updateCourseCoaches
* @param bool $sessionWithCoursesModifier * @param bool $sessionWithCoursesModifier
* @param int $showDescription * @param int $showDescription
* @param array $teacherBackupList
* @param array $groupBackup
* @return array * @return array
*/ */
static function importCSV( static function importCSV(
@ -4004,7 +4005,9 @@ class SessionManager
$sessionWithCoursesModifier = false, $sessionWithCoursesModifier = false,
$addOriginalCourseTeachersAsCourseSessionCoaches = true, $addOriginalCourseTeachersAsCourseSessionCoaches = true,
$removeAllTeachersFromCourse = true, $removeAllTeachersFromCourse = true,
$showDescription = null $showDescription = null,
&$teacherBackupList = array(),
&$groupBackup = array()
) { ) {
$content = file($file); $content = file($file);
@ -4501,6 +4504,39 @@ class SessionManager
if (!empty($teacherList)) { if (!empty($teacherList)) {
foreach ($teacherList as $teacher) { foreach ($teacherList as $teacher) {
if ($teacherToAdd != $teacher['user_id']) { if ($teacherToAdd != $teacher['user_id']) {
$sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
WHERE
user_id = ".$teacher['user_id']." AND
course_code = '".$course_code."'
";
$result = Database::query($sql);
$userCourseData = Database::fetch_array($result, 'ASSOC');
$teacherBackupList[$teacher['user_id']][$course_code] = $userCourseData;
$sql = "SELECT * FROM ".Database::get_course_table(TABLE_GROUP_USER)."
WHERE
user_id = ".$teacher['user_id']." AND
c_id = '".$courseInfo['real_id']."'
";
$result = Database::query($sql);
while ($groupData = Database::fetch_array($result, 'ASSOC')) {
$groupBackup['user'][$teacher['user_id']][$course_code][$groupData['group_id']] = $groupData;
}
$sql = "SELECT * FROM ".Database::get_course_table(TABLE_GROUP_TUTOR)."
WHERE
user_id = ".$teacher['user_id']." AND
c_id = '".$courseInfo['real_id']."'
";
$result = Database::query($sql);
while ($groupData = Database::fetch_array($result, 'ASSOC')) {
$groupBackup['tutor'][$teacher['user_id']][$course_code][$groupData['group_id']] = $groupData;
}
CourseManager::unsubscribe_user( CourseManager::unsubscribe_user(
$teacher['user_id'], $teacher['user_id'],
$course_code $course_code
@ -4511,11 +4547,48 @@ class SessionManager
if (!empty($teacherToAdd)) { if (!empty($teacherToAdd)) {
SessionManager::updateCoaches($session_id, $courseId, array($teacherToAdd), true); SessionManager::updateCoaches($session_id, $courseId, array($teacherToAdd), true);
$userCourseCategory = '';
if (isset($teacherBackupList[$teacherToAdd]) &&
isset($teacherBackupList[$teacherToAdd][$course_code])
) {
$courseUserData = $teacherBackupList[$teacherToAdd][$course_code];
$userCourseCategory = $courseUserData['user_course_cat'];
}
CourseManager::subscribe_user( CourseManager::subscribe_user(
$teacherToAdd, $teacherToAdd,
$course_code, $course_code,
COURSEMANAGER COURSEMANAGER,
0,
$userCourseCategory
); );
if (isset($groupBackup['user'][$teacherToAdd]) &&
isset($groupBackup['user'][$teacherToAdd][$course_code]) &&
!empty($groupBackup['user'][$teacherToAdd][$course_code])
) {
foreach ($groupBackup['user'][$teacherToAdd][$course_code] as $data) {
GroupManager::subscribe_users(
$teacherToAdd,
$data['group_id'],
$data['c_id']
);
}
}
if (isset($groupBackup['tutor'][$teacherToAdd]) &&
isset($groupBackup['tutor'][$teacherToAdd][$course_code]) &&
!empty($groupBackup['tutor'][$teacherToAdd][$course_code])
) {
foreach ($groupBackup['tutor'][$teacherToAdd][$course_code] as $data) {
GroupManager::subscribe_tutors(
$teacherToAdd,
$data['group_id'],
$data['c_id']
);
}
}
} }
} }
@ -4539,6 +4612,39 @@ class SessionManager
if (!empty($teacherList)) { if (!empty($teacherList)) {
foreach ($teacherList as $teacher) { foreach ($teacherList as $teacher) {
if (!in_array($teacher['user_id'], $teacherToAdd)) { if (!in_array($teacher['user_id'], $teacherToAdd)) {
$sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
WHERE
user_id = ".$teacher['user_id']." AND
course_code = '".$course_code."'
";
$result = Database::query($sql);
$userCourseData = Database::fetch_array($result, 'ASSOC');
$teacherBackupList[$teacher['user_id']][$course_code] = $userCourseData;
$sql = "SELECT * FROM ".Database::get_course_table(TABLE_GROUP_USER)."
WHERE
user_id = ".$teacher['user_id']." AND
c_id = '".$courseInfo['real_id']."'
";
$result = Database::query($sql);
while ($groupData = Database::fetch_array($result, 'ASSOC')) {
$groupBackup['user'][$teacher['user_id']][$course_code][$groupData['group_id']] = $groupData;
}
$sql = "SELECT * FROM ".Database::get_course_table(TABLE_GROUP_TUTOR)."
WHERE
user_id = ".$teacher['user_id']." AND
c_id = '".$courseInfo['real_id']."'
";
$result = Database::query($sql);
while ($groupData = Database::fetch_array($result, 'ASSOC')) {
$groupBackup['tutor'][$teacher['user_id']][$course_code][$groupData['group_id']] = $groupData;
}
CourseManager::unsubscribe_user( CourseManager::unsubscribe_user(
$teacher['user_id'], $teacher['user_id'],
$course_code $course_code
@ -4548,11 +4654,47 @@ class SessionManager
} }
foreach ($teacherToAdd as $teacherId) { foreach ($teacherToAdd as $teacherId) {
$userCourseCategory = '';
if (isset($teacherBackupList[$teacherId]) &&
isset($teacherBackupList[$teacherId][$course_code])
) {
$courseUserData = $teacherBackupList[$teacherId][$course_code];
$userCourseCategory = $courseUserData['user_course_cat'];
}
CourseManager::subscribe_user( CourseManager::subscribe_user(
$teacherId, $teacherId,
$course_code, $course_code,
COURSEMANAGER COURSEMANAGER,
0,
$userCourseCategory
); );
if (isset($groupBackup['user'][$teacherId]) &&
isset($groupBackup['user'][$teacherId][$course_code]) &&
!empty($groupBackup['user'][$teacherId][$course_code])
) {
foreach ($groupBackup['user'][$teacherId][$course_code] as $data) {
GroupManager::subscribe_users(
$teacherId,
$data['group_id'],
$data['c_id']
);
}
}
if (isset($groupBackup['tutor'][$teacherId]) &&
isset($groupBackup['tutor'][$teacherId][$course_code]) &&
!empty($groupBackup['tutor'][$teacherId][$course_code])
) {
foreach ($groupBackup['tutor'][$teacherId][$course_code] as $data) {
GroupManager::subscribe_tutors(
$teacherId,
$data['group_id'],
$data['c_id']
);
}
}
} }
} }
} }
@ -7639,6 +7781,8 @@ class SessionManager
$htmlRes .= $htmlCourse.'<div style="display:none" id="course-'.$courseCode.'">'.$htmlCatSessions.'</div></div>'; $htmlRes .= $htmlCourse.'<div style="display:none" id="course-'.$courseCode.'">'.$htmlCatSessions.'</div></div>';
} }
return $htmlRes; return $htmlRes;
} }
} }

Loading…
Cancel
Save