$result = Database::fetch_array(Database::query("SELECT COUNT(*) as count FROM ".Database::get_main_table(TABLE_MAIN_SESSION)." WHERE name = '$session_name' "));
return $result['count'] > 0;
@ -680,12 +682,24 @@ class SessionManager
* @param bool Whether to unsubscribe existing users (true, default) or not (false)
* @return void Nothing, or false on error
**/
public static function suscribe_users_to_session($id_session, $user_list, $session_visibility = SESSION_VISIBLE_READ_ONLY, $empty_users = true, $send_email = false) {
public static function suscribe_users_to_session(
$id_session,
$user_list,
$session_visibility = SESSION_VISIBLE_READ_ONLY,
$empty_users = true,
$send_email = false
) {
if ($id_session!= strval(intval($id_session))) return false;
foreach($user_list as $intUser){
if ($intUser!= strval(intval($intUser))) return false;
$session_visibility = $session_info['visibility']; //loaded from DB
//default status loaded if empty
@ -721,7 +735,7 @@ class SessionManager
}
if ($send_email) {
//sending emails only
// Sending emails only
if (is_array($user_list) && count($user_list)>0) {
foreach ($user_list as $user_id) {
if (!in_array($user_id, $existingUsers)) {
@ -751,8 +765,7 @@ class SessionManager
}
}
//Replace with this new function
//
// Replace with this new function
// insert new users into session_rel_course_rel_user and ignore if they already exist
foreach ($user_list as $enreg_user) {
if(!in_array($enreg_user, $existingUsers)) {
@ -764,7 +777,7 @@ class SessionManager
}
}
}
// count users in this session-course relation
// Count users in this session-course relation
$sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='$enreg_course' AND status<>2";
$sql= "SELECT course_code FROM $tbl_session_course WHERE id_session = ".Database::escape_string($session_id)." AND course_code = '".Database::escape_string($course_id)."'";
@ -1185,7 +1202,8 @@ class SessionManager
* @param integer day_end
* @return $id_session;
**/
public static function create_category_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end, $sday_end){
public static function create_category_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end, $sday_end)
$sql = 'SELECT * FROM '.$tbl_session_category.' WHERE access_url_id ="'.$id.'" ORDER BY name ASC';
@ -1434,7 +1457,8 @@ class SessionManager
* @param bool - optional, if is true the user don't be a coach now, otherwise it'll assign a coach
* @return bool true if there are affected rows, otherwise false
*/
public static function set_coach_to_course_session($user_id, $session_id = 0, $course_code = '', $nocoach = false) {
public static function set_coach_to_course_session($user_id, $session_id = 0, $course_code = '', $nocoach = false)
{
// Definition of variables
$user_id = intval($user_id);
@ -1470,13 +1494,13 @@ class SessionManager
if (Database::num_rows($res) > 0) {
// The user don't be a coach now
$sql = "UPDATE $tbl_session_rel_course_rel_user SET status = 0 WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id' ";
$rs_update = Database::query($sql);
Database::query($sql);
if (Database::affected_rows() > 0) return true;
else return false;
} else {
// The user don't be a coach now
$sql = "DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id' ";
$rs_delete = Database::query($sql);
Database::query($sql);
if (Database::affected_rows() > 0) return true;
else return false;
}
@ -1489,14 +1513,17 @@ class SessionManager
//Then update or insert
if (Database::num_rows($rs_check) > 0) {
$sql = "UPDATE $tbl_session_rel_course_rel_user SET status = 2 WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id' ";
$sql = "SELECT id_session FROM $tbl_session_rel_user s INNER JOIN $tbl_session_rel_access_url a ON (a.session_id = s.id_session) WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH." AND access_url_id = ".api_get_current_access_url_id()."";
} else {
$sql = "SELECT id_session FROM $tbl_session_rel_user s WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH."";
@ -1535,6 +1560,7 @@ class SessionManager
Database::query($sql);
}
}
// inserting new sessions list
if (is_array($sessions_list)) {
foreach ($sessions_list as $session_id) {
@ -1592,7 +1618,8 @@ class SessionManager
* @param int session id
* @return array list of courses
*/
public static function get_course_list_by_session_id($session_id) {
public static function get_course_list_by_session_id($session_id)
$sql_session = "SELECT session_id FROM $table_field sf INNER JOIN $t_sfv sfv ON sfv.field_id=sf.id WHERE field_variable='$original_session_id_name' AND field_value='$original_session_id_value'";
$sql_session = "SELECT session_id FROM $table_field sf INNER JOIN $t_sfv sfv ON sfv.field_id=sf.id
WHERE field_variable='$original_session_id_name' AND field_value='$original_session_id_value'";
$res_session = Database::query($sql_session);
$row = Database::fetch_object($res_session);
if ($row) {
@ -1662,10 +1691,11 @@ class SessionManager
return $return_array;
}
/**
* The general coach (field: session.id_coach)
* @param int user id
*/
/**
* The general coach (field: session.id_coach)
* @param int user id
* @return array
*/
public static function get_sessions_by_general_coach($user_id) {