From 64b73f2843421e42a7356de9ce8c5ce1c57c4848 Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Tue, 8 Oct 2013 12:44:59 -0400 Subject: [PATCH 1/6] show add course link in admin when course_validation is active -refs #6741 --- main/admin/index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main/admin/index.php b/main/admin/index.php index b9585ccd41..1538ab7210 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -106,10 +106,10 @@ if (api_is_platform_admin()) { $items = array(); $items[] = array('url'=>'course_list.php', 'label' => get_lang('CourseList')); - - if (api_get_setting('course_validation') != 'true') { - $items[] = array('url'=>'course_add.php', 'label' => get_lang('AddCourse')); - } else { + $items[] = array('url'=>'course_add.php', 'label' => get_lang('AddCourse')); + + if (api_get_setting('course_validation') == 'true') { + $items[] = array('url'=>'course_request_review.php', 'label' => get_lang('ReviewCourseRequests')); $items[] = array('url'=>'course_request_accepted.php', 'label' => get_lang('AcceptedCourseRequests')); $items[] = array('url'=>'course_request_rejected.php', 'label' => get_lang('RejectedCourseRequests')); From 1621f00dcc3b485b916d7fb72da7c34b4423f388 Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Tue, 8 Oct 2013 12:49:46 -0400 Subject: [PATCH 2/6] show add course link in admin when course_validation is active -refs #6741 --- main/admin/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/admin/index.php b/main/admin/index.php index 1538ab7210..f2cc60f319 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -108,7 +108,7 @@ if (api_is_platform_admin()) { $items[] = array('url'=>'course_list.php', 'label' => get_lang('CourseList')); $items[] = array('url'=>'course_add.php', 'label' => get_lang('AddCourse')); - if (api_get_setting('course_validation') == 'true') { + if (api_get_setting('course_validation') == 'true') { $items[] = array('url'=>'course_request_review.php', 'label' => get_lang('ReviewCourseRequests')); $items[] = array('url'=>'course_request_accepted.php', 'label' => get_lang('AcceptedCourseRequests')); From f86db28ddbe861b61e01b894266cec61a23165af Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Tue, 8 Oct 2013 12:51:23 -0400 Subject: [PATCH 3/6] show add course link in admin when course_validation is active -refs #6741 --- main/admin/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/admin/index.php b/main/admin/index.php index f2cc60f319..ee671dcd45 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -106,7 +106,7 @@ if (api_is_platform_admin()) { $items = array(); $items[] = array('url'=>'course_list.php', 'label' => get_lang('CourseList')); - $items[] = array('url'=>'course_add.php', 'label' => get_lang('AddCourse')); + $items[] = array('url'=>'course_add.php', 'label' => get_lang('AddCourse')); if (api_get_setting('course_validation') == 'true') { From 2afd97e9bb2935e2ee49887c675f670d7cb64b6b Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 9 Oct 2013 11:56:18 +0200 Subject: [PATCH 4/6] Minor - removing whitespaces --- main/cron/import_csv.php | 2 -- main/inc/lib/course.lib.php | 1 - main/inc/lib/pear/HTML/QuickForm.php | 1 - main/inc/lib/sessionmanager.lib.php | 7 ++++--- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/main/cron/import_csv.php b/main/cron/import_csv.php index 8eecb172aa..57fb6dc3fb 100644 --- a/main/cron/import_csv.php +++ b/main/cron/import_csv.php @@ -528,8 +528,6 @@ class ImportCsv foreach ($data as $row) { $row = $this->cleanCourseRow($row); $courseCode = CourseManager::get_course_id_from_original_id($row['extra_'.$this->extraFieldIdNameList['course']], $this->extraFieldIdNameList['course']); - - //$courseInfo = api_get_course_info($row['course_code']); $courseInfo = api_get_course_info($courseCode); if (empty($courseInfo)) { // Create diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 86b9fdc0c2..62dee3be88 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -4016,7 +4016,6 @@ class CourseManager { } $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER); - $alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code); if ($deleteTeachersNotInList) { diff --git a/main/inc/lib/pear/HTML/QuickForm.php b/main/inc/lib/pear/HTML/QuickForm.php index 36f3d5f7b6..d053af5bb5 100644 --- a/main/inc/lib/pear/HTML/QuickForm.php +++ b/main/inc/lib/pear/HTML/QuickForm.php @@ -1549,7 +1549,6 @@ class HTML_QuickForm extends HTML_Common foreach ($this->_rules as $target => $rules) { $submitValue = $this->getSubmitValue($target); - foreach ($rules as $rule) { if ((isset($rule['group']) && isset($this->_errors[$rule['group']])) || isset($this->_errors[$target])) { diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 5a649d49df..0492a12132 100644 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -2393,9 +2393,10 @@ class SessionManager } /** - * @param $sessionId - * @param $coachList - * @param $deleteCoachesNotInList + * @param int $sessionId + * @param string $courseCode + * @param array $coachList + * @param bool $deleteCoachesNotInList */ public static function updateCoaches($sessionId, $courseCode, $coachList, $deleteCoachesNotInList = false) { From 64b36adaf9b9f24cd7ae3cac5892a612e1dc3d7b Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Wed, 9 Oct 2013 09:40:33 -0400 Subject: [PATCH 5/6] create a new attendance sheet if there is none -refs 6743 --- main/attendance/attendance_list.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main/attendance/attendance_list.php b/main/attendance/attendance_list.php index 146a66c266..efda3ea646 100644 --- a/main/attendance/attendance_list.php +++ b/main/attendance/attendance_list.php @@ -19,7 +19,12 @@ if (api_is_allowed_to_edit(null, true)) { echo ''.Display::return_icon('new_attendance_list.png',get_lang('CreateANewAttendance'),'',ICON_SIZE_MEDIUM).''; echo ''; } - +$attendance = new Attendance(); +if ($attendance->get_number_of_attendances() == 0) { + $attendance->set_name(get_lang('Attendances')); + $attendance->set_description(get_lang('Attendances')); + $attendance->attendance_add(); +} $table = new SortableTable('attendance_list', array('Attendance', 'get_number_of_attendances'), array('Attendance', 'get_attendance_data'), $default_column); $table->set_additional_parameters($parameters); $table->set_header(0, '', false, array('style'=>'width:20px;')); From c3246ed4b4e90b40a50794dbfc0c3aa2622e5b4b Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 9 Oct 2013 15:43:55 +0200 Subject: [PATCH 6/6] Fixing session issues see BT#6449 --- main/inc/lib/sessionmanager.lib.php | 140 +++++++++++++++++++--------- 1 file changed, 97 insertions(+), 43 deletions(-) diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 0492a12132..2742f1f46f 100644 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -785,7 +785,20 @@ class SessionManager } } - function subscribe_users_to_session_course($user_list, $session_id, $course_code, $session_visibility = SESSION_VISIBLE_READ_ONLY ) { + /** + * @param array $user_list + * @param int $session_id + * @param string $course_code + * @param int $session_visibility + * @return bool + */ + public static function subscribe_users_to_session_course( + $user_list, + $session_id, + $course_code, + $session_visibility = SESSION_VISIBLE_READ_ONLY + ) + { $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); @@ -798,24 +811,41 @@ class SessionManager $session_visibility = intval($session_visibility); $nbr_users = 0; + /*AND + visibility = $session_visibility*/ foreach ($user_list as $enreg_user) { - //if (!in_array($enreg_user, $existingUsers)) { - $enreg_user = intval($enreg_user); + $enreg_user = intval($enreg_user); + $sql = "SELECT count(id_user) as count + FROM $tbl_session_rel_course_rel_user + WHERE id_session = $session_id AND + course_code = '$course_code' and + id_user = $enreg_user "; + $result = Database::query($sql); + $count = 0; + + if (Database::num_rows($result) > 0) { + $row = Database::fetch_array($result, 'ASSOC'); + $count = $row['count']; + } + + if ($count == 0) { $insert_sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user,visibility) VALUES ('$session_id','$course_code','$enreg_user','$session_visibility')"; Database::query($insert_sql); if (Database::affected_rows()) { $nbr_users++; } - //} + } } // count users in this session-course relation - $sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$session_id' AND course_code='$course_code' AND status<>2"; + $sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user + WHERE id_session='$session_id' AND course_code='$course_code' AND status<>2"; $rs = Database::query($sql); list($nbr_users) = Database::fetch_array($rs); // update the session-course relation to add the users total - $update_sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$session_id' AND course_code='$course_code'"; + $update_sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users + WHERE id_session='$session_id' AND course_code='$course_code'"; Database::query($update_sql); } @@ -2159,6 +2189,7 @@ class SessionManager } } else { + // Updating the session. $params = array( 'id_coach' => $coach_id, 'date_start' => $date_start, @@ -2178,7 +2209,6 @@ class SessionManager } if (isset($sessionId) && !empty($sessionId)) { - // The session already exists, update it then. Database::update($tbl_session, $params, array('id = ?' => $sessionId)); $session_id = $sessionId; } else { @@ -2196,7 +2226,9 @@ class SessionManager Database::query("DELETE FROM $tbl_session_user WHERE id_session='$session_id'"); Database::query("DELETE FROM $tbl_session_course WHERE id_session='$session_id'"); - Database::query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id'"); + + // Delete session course user relation ships *only* for students + Database::query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id' AND status <> 2"); } $session_counter++; } @@ -2228,6 +2260,8 @@ class SessionManager if (CourseManager::course_exists($course_code)) { + $courseInfo = api_get_course_info($course_code); + // Adding the course to a session. $sql_course = "INSERT IGNORE INTO $tbl_session_course SET course_code = '$course_code', id_session='$session_id'"; @@ -2250,66 +2284,79 @@ class SessionManager $course_users = explode(',', $course_users); $course_coaches = explode(',', $course_coaches); + // Checking if the flag is set TeachersWillBeAddedAsCoachInAllCourseSessions (course_edit.php) + $addTeachersToSession = true; + if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) { + $addTeachersToSession = $courseInfo['add_teachers_to_sessions_courses']; + } + // Adding coaches to session course user if (!empty($course_coaches)) { - $savedCoaches = array(); - // Adding course teachers as course session teachers - $alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code); - - if (!empty($alreadyAddedTeachers)) { - $teachersToAdd = array(); - foreach ($alreadyAddedTeachers as $user) { - $teachersToAdd[] = $user['username']; + // only edit if add_teachers_to_sessions_courses is set. + if ($addTeachersToSession) { + // Adding course teachers as course session teachers + $alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code); + + if (!empty($alreadyAddedTeachers)) { + $teachersToAdd = array(); + foreach ($alreadyAddedTeachers as $user) { + $teachersToAdd[] = $user['username']; + } + $course_coaches = array_merge($course_coaches, $teachersToAdd); } - $course_coaches = array_merge($course_coaches, $teachersToAdd); - } - foreach ($course_coaches as $course_coach) { - $course_coach = trim($course_coach); - $coach_id = UserManager::get_user_id_from_username($course_coach); - if ($coach_id !== false) { - $sql = "INSERT IGNORE INTO $tbl_session_course_user SET - id_user = '$coach_id', - course_code = '$course_code', - id_session = '$session_id', - status = 2 "; - Database::query($sql); - if ($debug) { - $logger->addInfo("Sessions - Adding course coach: user #$coach_id ($course_coach) to course: '$course_code' and session #$session_id"); + + foreach ($course_coaches as $course_coach) { + $course_coach = trim($course_coach); + $coach_id = UserManager::get_user_id_from_username($course_coach); + if ($coach_id !== false) { + // Just insert new coaches + SessionManager::updateCoaches($session_id, $course_code, array($coach_id), false); + /*$sql = "INSERT IGNORE INTO $tbl_session_course_user SET + id_user = '$coach_id', + course_code = '$course_code', + id_session = '$session_id', + status = 2 "; + Database::query($sql);*/ + + if ($debug) { + $logger->addInfo("Sessions - Adding course coach: user #$coach_id ($course_coach) to course: '$course_code' and session #$session_id"); + } + $savedCoaches[] = $coach_id; + } else { + $error_message .= get_lang('UserDoesNotExist').' : '.$course_coach.$eol; } - $savedCoaches[] = $coach_id; - } else { - $error_message .= get_lang('UserDoesNotExist').' : '.$course_coach.$eol; } } } - $users_in_course_counter = 0; + //$users_in_course_counter = 0; - // Adding the relationship "Session - Course - User". + // Adding Students, updating relationship "Session - Course - User". foreach ($course_users as $user) { $user = trim($user); $user_id = UserManager::get_user_id_from_username($user); if ($user_id !== false) { - $sql = "INSERT IGNORE INTO $tbl_session_course_user SET + SessionManager::subscribe_users_to_session_course(array($user_id), $session_id, $course_code); + /*$sql = "INSERT IGNORE INTO $tbl_session_course_user SET id_user='$user_id', course_code='$course_code', id_session = '$session_id'"; - Database::query($sql); + Database::query($sql);*/ if ($debug) { $logger->addInfo("Sessions - Adding student: user #$user_id ($user) to course: '$course_code' and session #$session_id"); } - $users_in_course_counter++; + //$users_in_course_counter++; } else { $error_message .= get_lang('UserDoesNotExist').': '.$user.$eol; } } - $sql = "UPDATE $tbl_session_course SET nbr_users = '$users_in_course_counter' WHERE course_code = '$course_code'"; - Database::query($sql); + /*$sql = "UPDATE $tbl_session_course SET nbr_users = '$users_in_course_counter' WHERE course_code = '$course_code'"; + Database::query($sql);*/ $course_info = CourseManager::get_course_information($course_code); $inserted_in_course[$course_code] = $course_info['title']; @@ -2402,12 +2449,19 @@ class SessionManager { $currentCoaches = SessionManager::getCoachesByCourseSession($sessionId, $courseCode); - foreach ($coachList as $userId) { - SessionManager::set_coach_to_course_session($userId, $sessionId, $courseCode); + if (!empty($coachList)) { + foreach ($coachList as $userId) { + SessionManager::set_coach_to_course_session($userId, $sessionId, $courseCode); + } } if ($deleteCoachesNotInList) { - $coachesToDelete = array_diff($currentCoaches, $coachList); + if (!empty($coachList)) { + $coachesToDelete = array_diff($currentCoaches, $coachList); + } else { + $coachesToDelete = $currentCoaches; + } + if (!empty($coachesToDelete)) { foreach ($coachesToDelete as $userId) { SessionManager::set_coach_to_course_session($userId, $sessionId, $courseCode, true);