'index.php',"name" => get_lang('PlatformAdmin')); $interbreadcrumb[]=array('url' => "session_list.php","name" => "Liste des sessions"); // Database Table Definitions $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS); $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); $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); $tbl_class = Database::get_main_table(TABLE_MAIN_CLASS); $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER); // setting the name of the tool $tool_name=get_lang('SubscribeUsersToSession'); $id_session=intval($_GET['id_session']); $formSent=0; $errorMsg=$firstLetterUser=$firstLetterSession=''; $UserList=$SessionList=array(); $users=$sessions=array(); $noPHP_SELF=true; if($_POST['formSent']) { $formSent=$_POST['formSent']; $firstLetterUser=$_POST['firstLetterUser']; $firstLetterSession=$_POST['firstLetterSession']; $UserList=$_POST['sessionUsersList']; $ClassList=$_POST['sessionClassesList']; if(!is_array($UserList)) { $UserList=array(); } if($formSent == 1) { $result = api_sql_query("SELECT id_user FROM $tbl_session_rel_user WHERE id_session='$id_session'"); $existingUsers = array(); while($row = mysql_fetch_array($result)){ $existingUsers[] = $row['id_user']; } $result=api_sql_query("SELECT course_code FROM $tbl_session_rel_course WHERE id_session='$id_session'",__FILE__,__LINE__); $CourseList=array(); while($row=mysql_fetch_array($result)) { $CourseList[]=$row['course_code']; } foreach($CourseList as $enreg_course) { $nbr_users=0; foreach($UserList as $enreg_user) { if(!in_array($enreg_user, $existingUsers)){ api_sql_query("INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$enreg_user')",__FILE__,__LINE__); if(mysql_affected_rows()) { $nbr_users++; } } } foreach($existingUsers as $existing_user){ if(!in_array($existing_user, $UserList)){ $sql = "DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='$enreg_course' AND id_user='$existing_user'"; api_sql_query($sql); if(mysql_affected_rows()) { $nbr_users--; } } } $sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='$enreg_course'"; $rs = api_sql_query($sql, __FILE__, __LINE__); list($nbr_users) = mysql_fetch_array($rs); api_sql_query("UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$id_session' AND course_code='$enreg_course'",__FILE__,__LINE__); } api_sql_query("DELETE FROM $tbl_session_rel_user WHERE id_session = $id_session"); $nbr_users = 0; foreach($UserList as $enreg_user){ $nbr_users++; api_sql_query("INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user) VALUES('$id_session','$enreg_user')",__FILE__,__LINE__); } $nbr_users = count($UserList); api_sql_query("UPDATE $tbl_session SET nbr_users= $nbr_users WHERE id='$id_session' ",__FILE__,__LINE__); //if(empty($_GET['add'])) //header('Location: '.$_GET['page'].'?id_session='.$id_session); //else header('Location: resume_session.php?id_session='.$id_session); } } Display::display_header($tool_name); api_display_tool_title($tool_name); $nosessionUsersList = $sessionUsersList = $nosessionClassesList = $sessionClassesList = array(); //classes $sql="SELECT id, name FROM $tbl_class ORDER BY name"; $result=api_sql_query($sql,__FILE__,__LINE__); $Classes=api_store_result($result); foreach($Classes as $classe) if($classe['id_session'] == $id_session) $sessionClassesList[$classe['id']] = $classe ; foreach($Classes as $classe) if(empty($sessionClassesList[$classe['user_id']]) && empty($nosessionClassesList[$classe['user_id']])) $nosessionClassesList[$classe['id']] = $classe ; //users $sql="SELECT user_id, lastname, firstname, username, id_session FROM $tbl_user LEFT JOIN $tbl_session_rel_user ON $tbl_session_rel_user.id_user = $tbl_user.user_id ORDER BY lastname,firstname,username"; $result=api_sql_query($sql,__FILE__,__LINE__); $Users=api_store_result($result); foreach($Users as $user) if($user['id_session'] == $id_session) $sessionUsersList[$user['user_id']] = $user ; foreach($Users as $user) if(empty($sessionUsersList[$user['user_id']]) && empty($nosessionUsersList[$user['user_id']])) $nosessionUsersList[$user['user_id']] = $user ; ?>