Fixing field id_coach doesn't exists in session_rel_course table - partial DT#5496

skala
Cristian Fasanando 15 years ago
parent 519781a9e8
commit 7eb4159f59
  1. 2
      main/admin/add_courses_to_session.php
  2. 13
      main/admin/resume_session.php
  3. 8
      main/admin/session_import.php
  4. 21
      main/inc/lib/course.lib.php
  5. 2
      main/inc/lib/sessionmanager.lib.php
  6. 41
      main/inc/lib/usermanager.lib.php
  7. 2
      main/webservices/registration.soap.php

@ -228,7 +228,7 @@ if ($_POST['formSent']) {
}
}
if(!$exists) {
$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course(id_session,course_code, id_coach) VALUES('$id_session','$enreg_course','$id_coach')";
$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course(id_session,course_code) VALUES('$id_session','$enreg_course')";
Database::query($sql_insert_rel_course ,__FILE__,__LINE__);
//We add in the existing courses table the current course, to not try to add another time the current course
$existingCourses[]=array('course_code'=>$enreg_course);

@ -93,7 +93,7 @@ if($_GET['action'] == 'delete')
}
if(!empty($_GET['user'])){
if (!empty($_GET['user'])) {
Database::query("DELETE FROM $tbl_session_rel_user WHERE id_session='$id_session' AND id_user=".intval($_GET['user']),__FILE__,__LINE__);
$nbr_affected_rows=Database::affected_rows();
Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'",__FILE__,__LINE__);
@ -202,13 +202,12 @@ if($session['nbr_courses']==0){
}
else {
// select the courses
$sql = "SELECT code,title,visual_code, nbr_users, lastname, firstname, username
FROM $tbl_course,$tbl_session_rel_course
LEFT JOIN $tbl_user
ON $tbl_session_rel_course.id_coach = $tbl_user.user_id
WHERE course_code=code
AND id_session='$id_session'
$sql = "SELECT code,title,visual_code, nbr_users
FROM $tbl_course,$tbl_session_rel_course
WHERE course_code = code
AND id_session='$id_session'
ORDER BY title";
$result=Database::query($sql,__FILE__,__LINE__);
$courses=Database::store_result($result);
foreach($courses as $course){

@ -392,8 +392,7 @@ if ($_POST['formSent']) {
$session_course_relation = SessionManager::relation_session_course_exist($session_id, $course_code);
if (!$session_course_relation) {
$sql_course = "INSERT INTO $tbl_session_course SET
course_code = '$course_code',
id_coach='$coach_id',
course_code = '$course_code',
id_session='$session_id'";
$rs_course = Database::query($sql_course, __FILE__, __LINE__);
}
@ -448,7 +447,6 @@ if ($_POST['formSent']) {
$sql_course = "INSERT INTO $tbl_session_course SET
course_code = '".$vcourse['code']."',
id_coach='$coach_id',
id_session='$session_id'";
$rs_course = Database::query($sql_course, __FILE__, __LINE__);
if (Database::affected_rows()) {
@ -646,8 +644,7 @@ if ($_POST['formSent']) {
}
// Adding the course to a session
$sql_course = "INSERT IGNORE INTO $tbl_session_course SET
course_code = '$course_code',
id_coach='$coach_id',
course_code = '$course_code',
id_session='$session_id'";
$rs_course = Database::query($sql_course, __FILE__, __LINE__);
$course_counter++;
@ -697,7 +694,6 @@ if ($_POST['formSent']) {
// Adding the relationship "Session - Course".
$sql_course = "INSERT IGNORE INTO $tbl_session_course SET
course_code = '".$vcourse['code']."',
id_coach='$coach',
id_session='$session_id'";
$rs_course = Database::query($sql_course, __FILE__, __LINE__);

@ -827,9 +827,9 @@ class CourseManager {
// A course coach?
if (Database::num_rows(Database::query("SELECT id_coach
FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)." AS session_course
FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
WHERE id_session='".$_SESSION['id_session']."'
AND id_coach = '$user_id'
AND id_user = '$user_id' AND status = 2
AND course_code='$course_code'", __FILE__, __LINE__))) {
return true;
}
@ -920,15 +920,15 @@ class CourseManager {
$users = array();
// We get the coach for the given course in a given session.
$rs = Database::query('SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE).
' WHERE id_session="'.$session_id.'" AND course_code="'.$course_code.'"', __FILE__, __LINE__);
$rs = Database::query('SELECT id_user FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).
' WHERE id_session="'.$session_id.'" AND course_code="'.$course_code.'" AND status = 2', __FILE__, __LINE__);
while ($user = Database::fetch_array($rs)) {
$user_info = Database::get_user_info_from_id($user['id_coach']);
$user_info = Database::get_user_info_from_id($user['id_user']);
$user_info['status'] = $user['status'];
$user_info['role'] = $user['role'];
$user_info['tutor_id'] = $user['tutor_id'];
$user_info['email'] = $user['email'];
$users[$user['id_coach']] = $user_info;
$users[$user['id_user']] = $user_info;
}
// We get the session coach.
@ -1727,14 +1727,17 @@ class CourseManager {
* @author @author Carlos Vargas <carlos.vargas@dokeos.com>, Dokeos Latino
*/
public static function get_email_of_tutor_to_session($session) {
$row_email = Database::fetch_array(Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE)."
WHERE id_session='".Database::escape_string($session)."'", __FILE__, __LINE__));
$row_email = Database::fetch_array(Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
WHERE id_session='".Database::escape_string($session)."' AND status = 2", __FILE__, __LINE__));
$result_user = Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_USER)."
WHERE user_id=".$row_email['id_coach'], __FILE__, __LINE__);
WHERE user_id=".$row_email['id_user'], __FILE__, __LINE__);
while ($row_emails = Database::fetch_array($result_user)) {
$name_tutor = api_get_person_name($row_emails['firstname'], $row_emails['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
$mail_tutor = array($row_emails['email'] => $name_tutor);
}
return $mail_tutor;
}

@ -496,7 +496,7 @@ class SessionManager {
}
if (!$exists) {
//if the course isn't subscribed yet
$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course (id_session,course_code, id_coach) VALUES ('$id_session','$enreg_course','$id_coach')";
$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course (id_session,course_code) VALUES ('$id_session','$enreg_course')";
Database::query($sql_insert_rel_course ,__FILE__,__LINE__);
//We add the current course in the existing courses array, to avoid adding another time the current course
$existingCourses[]=array('course_code'=>$enreg_course);

@ -1707,9 +1707,9 @@ class UserManager
// get the list of sessions where the user is subscribed as coach in a course
$sessions_sql = "SELECT DISTINCT id, name, date_start, date_end, DATE_SUB(date_start, INTERVAL nb_days_access_before_beginning DAY), ADDDATE(date_end, INTERVAL nb_days_access_after_end DAY)
FROM $tbl_session as session
INNER JOIN $tbl_session_course as session_rel_course
ON session_rel_course.id_session = session.id
AND session_rel_course.id_coach = $user_id
INNER JOIN $tbl_session_course_user as session_rel_course_user
ON session_rel_course_user.id_session = session.id
AND session_rel_course_user.id_user = $user_id AND session_rel_course_user.status = 2
WHERE (CURDATE() >= DATE_SUB(date_start, INTERVAL nb_days_access_before_beginning DAY)
AND CURDATE() <= ADDDATE(date_end, INTERVAL nb_days_access_after_end DAY)
OR date_start='0000-00-00')
@ -1737,16 +1737,16 @@ class UserManager
foreach($sessions as $enreg) {
$id_session = $enreg['id'];
$personal_course_list_sql = "SELECT DISTINCT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, ".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." t, email, course.course_language l, 1 sort, category_code user_course_cat, date_start, date_end, session.id as id_session, session.name as session_name
FROM $tbl_session_course as session_course
FROM $tbl_session_course_user as session_course_user
INNER JOIN $tbl_course AS course
ON course.code = session_course.course_code
ON course.code = session_course_user.course_code
INNER JOIN $tbl_session as session
ON session.id = session_course.id_session
ON session.id = session_course_user.id_session
LEFT JOIN $tbl_user as user
ON user.user_id = session_course.id_coach
WHERE session_course.id_session = $id_session
AND (session_course.id_coach=$user_id OR session.id_coach=$user_id)
ORDER BY i";
ON user.user_id = session_course_user.id_user
WHERE session_course_user.id_session = $id_session
AND ((session_course_user.id_user=$user_id AND session_course_user.status = 2) OR session.id_coach=$user_id)
ORDER BY i";
$course_list_sql_result = Database::query($personal_course_list_sql, __FILE__, __LINE__);
@ -1775,11 +1775,12 @@ class UserManager
ORDER BY i";
*/
// this query is very similar to the above query, but it will check the session_rel_course_user table if there are courses registered to our user or not
$personal_course_list_sql = "SELECT distinct course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, CONCAT(user.lastname,' ',user.firstname) t, email, course.course_language l, 1 sort, category_code user_course_cat, date_start, date_end, session.id as id_session, session.name as session_name, IF(session_course.id_coach = 3,'2', '5')
FROM $tbl_session_course_user as session_course_user INNER JOIN $tbl_course AS course
ON course.code = session_course_user.course_code AND session_course_user.id_session = $id_session INNER JOIN $tbl_session as session ON session_course_user.id_session = session.id
INNER JOIN $tbl_session_course as session_course
LEFT JOIN $tbl_user as user ON user.user_id = session_course.id_coach
$personal_course_list_sql = "SELECT distinct course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, CONCAT(user.lastname,' ',user.firstname) t, email, course.course_language l, 1 sort, category_code user_course_cat, date_start, date_end, session.id as id_session, session.name as session_name, IF((session_course_user.id_user = 3 AND session_course_user.status=2),'2', '5')
FROM $tbl_session_course_user as session_course_user
INNER JOIN $tbl_course AS course
ON course.code = session_course_user.course_code AND session_course_user.id_session = $id_session
INNER JOIN $tbl_session as session ON session_course_user.id_session = session.id
LEFT JOIN $tbl_user as user ON user.user_id = session_course_user.id_user
WHERE session_course_user.id_user = $user_id ORDER BY i";
$course_list_sql_result = Database::query($personal_course_list_sql, __FILE__, __LINE__);
@ -1848,15 +1849,17 @@ class UserManager
}
if(api_is_allowed_to_create_course()) {
$personal_course_list_sql = "SELECT DISTINCT sc.course_code as code
FROM $tbl_session_course as sc, $tbl_session as s
$personal_course_list_sql = "SELECT DISTINCT scu.course_code as code
FROM $tbl_session_course_user as scu, $tbl_session as s
$join_access_url
WHERE s.id = $session_id
AND sc.id_session = s.id
AND (sc.id_coach=$user_id OR s.id_coach=$user_id)
AND scu.id_session = s.id
AND ((scu.id_user=$user_id AND scu.status=2) OR s.id_coach=$user_id)
$where_access_url
ORDER BY code";
$course_list_sql_result = Database::query($personal_course_list_sql, __FILE__, __LINE__);
if (Database::num_rows($course_list_sql_result)>0) {

@ -4578,7 +4578,7 @@ function DokeosWSSuscribeCoursesToSession($params) {
if (!$exists) {
// if the course isn't subscribed yet
$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course (id_session,course_code, id_coach) VALUES ('$id_session','$enreg_course','$id_coach')";
$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course (id_session,course_code) VALUES ('$id_session','$enreg_course')";
Database::query($sql_insert_rel_course, __FILE__, __LINE__);
// We add the current course in the existing courses array, to avoid adding another time the current course

Loading…
Cancel
Save