local.inc.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) 2003-2005 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Hugues Peeters
  9. Copyright (c) Roan Embrechts (Vrije Universiteit Brussel)
  10. Copyright (c) Patrick Cool
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  19. Mail: info@dokeos.com
  20. ==============================================================================
  21. */
  22. /**
  23. ==============================================================================
  24. *
  25. * SCRIPT PURPOSE
  26. *
  27. * This script initializes and manages Dokeos session information. It
  28. * keeps available session information up to date.
  29. *
  30. * You can request a course id. It will check if the course Id requested is the
  31. * same as the current one. If it isn't it will update session information from
  32. * the database. You can also force the course reset if you want ($cidReset).
  33. *
  34. * All the course information is stored in the $_course array.
  35. *
  36. * You can request a group id. The script will check if the group id requested is the
  37. * same as the current one. If it isn't it will update session information from
  38. * the database. You can also force the course reset if you want ($gidReset).
  39. *
  40. The course id is stored in $_cid session variable.
  41. * The group id is stored in $_gid session variable.
  42. *
  43. *
  44. * VARIABLES AFFECTING THE SCRIPT BEHAVIOR
  45. *
  46. * string $login
  47. * string $password
  48. * boolean $logout
  49. *
  50. * string $cidReq : course id requested
  51. * boolean $cidReset : ask for a course Reset, if no $cidReq is provided in the
  52. * same time, all course informations is removed from the
  53. * current session
  54. *
  55. * int $gidReq : group Id requested
  56. * boolean $gidReset : ask for a group Reset, if no $gidReq is provided in the
  57. * same time, all group informations is removed from the
  58. * current session
  59. *
  60. *
  61. * VARIABLES SET AND RETURNED BY THE SCRIPT
  62. *
  63. * All the variables below are set and returned by this script.
  64. *
  65. * USER VARIABLES
  66. *
  67. * int $_uid (the user id)
  68. *
  69. * string $_user ['firstName' ]
  70. * string $_user ['lastName' ]
  71. * string $_user ['mail' ]
  72. * string $_user ['lastLogin' ]
  73. * $_user ['official_code']
  74. * $_user ['picture_uri' ]
  75. *
  76. * boolean $is_platformAdmin
  77. * boolean $is_allowedCreateCourse
  78. *
  79. * COURSE VARIABLES
  80. *
  81. * string $_cid (the course id)
  82. *
  83. * int $_course['id' ] - auto-assigned integer
  84. * string $_course['name' ] - the title of the course
  85. * string $_course['official_code'] - the visual / fake / official code
  86. * string $_course['sysCode' ]
  87. * string $_course['path' ]
  88. * string $_course['dbName' ]
  89. * string $_course['dbNameGlu' ]
  90. * string $_course['titular' ]
  91. * string $_course['language' ]
  92. * string $_course['extLink' ]['url' ]
  93. * string $_course['extLink' ]['name']
  94. * string $_course['categoryCode']
  95. * string $_course['categoryName']
  96. * boolean $is_courseMember
  97. * boolean $is_courseTutor
  98. * boolean $is_courseAdmin
  99. *
  100. *
  101. * GROUP VARIABLES
  102. *
  103. * int $_gid (the group id)
  104. *
  105. *
  106. * IMPORTANT ADVICE FOR DEVELOPERS
  107. *
  108. * We strongly encourage developers to use a connection layer at the top of
  109. * their scripts rather than use these variables, as they are, inside the core
  110. * of their scripts. It will make code maintenance much easier.
  111. *
  112. * Many if the functions you need you can already find in the
  113. * main_api.lib.php
  114. *
  115. * We encourage you to use functions to access these global "kernel" variables.
  116. * You can add them to e.g. the main API library.
  117. *
  118. *
  119. * SCRIPT STRUCTURE
  120. *
  121. * 1. The script determines if there is an authentication attempt. This part
  122. * only chek if the login name and password are valid. Afterwards, it set the
  123. * $_uid (user id) and the $uidReset flag. Other user informations are retrieved
  124. * later. It's also in this section that optional external authentication
  125. * devices step in.
  126. *
  127. * 2. The script determines what other session informations have to be set or
  128. * reset, setting correctly $cidReset (for course) and $gidReset (for group).
  129. *
  130. * 3. If needed, the script retrieves the other user informations (first name,
  131. * last name, ...) and stores them in session.
  132. *
  133. * 4. If needed, the script retrieves the course information and stores them
  134. * in session
  135. *
  136. * 5. The script initializes the user permission status and permission for the
  137. * course level
  138. *
  139. * 6. If needed, the script retrieves group informations an store them in
  140. * session.
  141. *
  142. * 7. The script initializes the user status and permission for the group level.
  143. *
  144. * @package dokeos.include
  145. ==============================================================================
  146. */
  147. /*
  148. ==============================================================================
  149. INIT SECTION
  150. variables should be initialised here
  151. ==============================================================================
  152. */
  153. // parameters passed via GET
  154. $logout = isset($_GET["logout"]) ? $_GET["logout"] : '';
  155. $gidReq = isset($_GET["gidReq"]) ? $_GET["gidReq"] : '';
  156. //this fixes some problems with generic functionalities like
  157. //My Agenda & What's New icons linking to courses
  158. // $cidReq can be set in the index.php file of a course-area
  159. $cidReq = isset($cidReq) ? $cidReq : '';
  160. // $cidReq can be set in URL-parameter
  161. $cidReq = isset($_GET["cidReq"]) ? $_GET["cidReq"] : $cidReq;
  162. $cidReset = isset($cidReset) ? $cidReset : '';
  163. // $cidReset can be set in URL-parameter
  164. $cidReset = isset($_GET["cidReq"]) ? $_GET["cidReq"] : $cidReset;
  165. $gidReset = isset($gidReset) ? $gidReset : '';
  166. // $gidReset can be set in URL-parameter
  167. $gidReset = isset($_GET["cidReq"]) ? $_GET["cidReq"] : $gidReset;
  168. // parameters passed via POST
  169. $login = isset($_POST["login"]) ? $_POST["login"] : '';
  170. // passed through other means
  171. //$cidReq -- passed from course folder index.php
  172. /*
  173. ==============================================================================
  174. MAIN CODE
  175. ==============================================================================
  176. */
  177. if (isset($_SESSION['_uid']) && $_SESSION['_uid'] && ! ($login || $logout))
  178. {
  179. // uid is in session => login already done, continue with this value
  180. $_uid = $_SESSION['_uid'];
  181. }
  182. else
  183. {
  184. unset($_uid); // uid not in session ? prevent any hacking
  185. if(isset($_POST['login']) && isset($_POST['password'])) // $login && $password are given to log in
  186. {
  187. $login = $_POST['login'];
  188. $password = $_POST['password'];
  189. //lookup the user in the main database
  190. $user_table = Database::get_main_table(MAIN_USER_TABLE);
  191. $sql = "SELECT user_id, username, password, auth_source, active, expiration_date
  192. FROM $user_table
  193. WHERE username = '".trim(addslashes($login))."'";
  194. $result = api_sql_query($sql,__FILE__,__LINE__);
  195. if (mysql_num_rows($result) > 0)
  196. {
  197. $uData = mysql_fetch_array($result);
  198. if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE)
  199. {
  200. //the authentification of this user is managed by Dokeos itself
  201. $password = trim(stripslashes($password));
  202. // determine if the password needs to be encrypted before checking
  203. // $userPasswordCrypted is set in an external configuration file
  204. if ($userPasswordCrypted)
  205. {
  206. $password = md5($password);
  207. }
  208. // check the user's password
  209. if ($password == $uData['password'] AND (trim($login) == $uData['username']))
  210. {
  211. // check if the account is active (not locked)
  212. if ($uData['active']=='1')
  213. {
  214. // check if the expiration date has not been reached
  215. if ($uData['expiration_date']>date('Y-m-d H:i:s') OR $uData['expiration_date']=='0000-00-00 00:00:00')
  216. {
  217. $_uid = $uData['user_id'];
  218. api_session_register('_uid');
  219. }
  220. else
  221. {
  222. $loginFailed = true;
  223. api_session_unregister('_uid');
  224. header('Location: index.php?loginFailed=1&error=account_expired');
  225. exit;
  226. }
  227. }
  228. else
  229. {
  230. $loginFailed = true;
  231. api_session_unregister('_uid');
  232. header('Location: index.php?loginFailed=1&error=account_inactive');
  233. exit;
  234. }
  235. }
  236. else // login failed: username or password incorrect
  237. {
  238. $loginFailed = true;
  239. api_session_unregister('_uid');
  240. header('Location: index.php?loginFailed=1&error=user_password_incorrect');
  241. exit;
  242. }
  243. if (isset($uData['creator_id']) && $_uid != $uData['creator_id'])
  244. {
  245. //first login for a not self registred
  246. //e.g. registered by a teacher
  247. //do nothing (code may be added later)
  248. }
  249. }
  250. else // no standard Dokeos login - try external authentification
  251. {
  252. /*
  253. * Process external authentication
  254. * on the basis of the given login name
  255. */
  256. $loginFailed = true; // Default initialisation. It could
  257. // change after the external authentication
  258. $key = $uData['auth_source'];
  259. /* >>>>>>>>>>>>>>>> External authentication modules <<<<<<<<<<<<<<<< */
  260. // see claro_main.conf.php to define these
  261. include_once($extAuthSource[$key]['login']);
  262. /* >>>>>>>>>>>>>>>> External authentication modules <<<<<<<<<<<<<<<<<< */
  263. }
  264. if(!empty($_SESSION['request_uri']))
  265. {
  266. $req = $_SESSION['request_uri'];
  267. unset($_SESSION['request_uri']);
  268. header('location: '.$req);
  269. }
  270. else
  271. {
  272. header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param);
  273. }
  274. }
  275. else // login failed, mysql_num_rows($result) <= 0
  276. {
  277. $loginFailed = true; // Default initialisation. It could
  278. // change after the external authentication
  279. /*
  280. * In this section:
  281. * there is no entry for the $login user in the Dokeos
  282. * database. This also means there is no auth_source for the user.
  283. * We let all external procedures attempt to add him/her
  284. * to the system.
  285. *
  286. * Process external login on the basis
  287. * of the authentication source list
  288. * provided by the configuration settings.
  289. * If the login succeeds, for going further,
  290. * Dokeos needs the $_uid variable to be
  291. * set and registered in the session. It's the
  292. * responsability of the external login script
  293. * to provide this $_uid.
  294. */
  295. if (is_array($extAuthSource))
  296. {
  297. foreach($extAuthSource as $thisAuthSource)
  298. {
  299. include_once($thisAuthSource['newUser']);
  300. }
  301. } //end if is_array($extAuthSource)
  302. } //end else login failed
  303. }
  304. // else {} => continue as anonymous user
  305. $uidReset = true;
  306. // $cidReset = true;
  307. // $gidReset = true;
  308. }
  309. // if the requested course is different from the course in session
  310. if (!empty($cidReq) && (!isset($_SESSION['_cid']) or (isset($_SESSION['_cid']) && $cidReq != $_SESSION['_cid'])))
  311. {
  312. $cidReset = true;
  313. $gidReset = true; // As groups depend from courses, group id is reset
  314. }
  315. // if the requested group is different from the group in session
  316. if ($gidReq && $gidReq != $_SESSION['_gid'])
  317. {
  318. $gidReset = true;
  319. }
  320. //////////////////////////////////////////////////////////////////////////////
  321. // USER INIT
  322. //////////////////////////////////////////////////////////////////////////////
  323. if (isset($uidReset) && $uidReset) // session data refresh requested
  324. {
  325. $is_platformAdmin = false; $is_allowedCreateCourse = false;
  326. if (isset($_uid) && $_uid) // a uid is given (log in succeeded)
  327. {
  328. $user_table = Database::get_main_table(MAIN_USER_TABLE);
  329. $admin_table = Database::get_main_table(MAIN_ADMIN_TABLE);
  330. if ($is_trackingEnabled)
  331. {
  332. $sql = "SELECT `user`.*, `a`.`user_id` `is_admin`,
  333. UNIX_TIMESTAMP(`login`.`login_date`) `login_date`
  334. FROM $user_table
  335. LEFT JOIN $admin_table `a`
  336. ON `user`.`user_id` = `a`.`user_id`
  337. LEFT JOIN `".$statsDbName."`.`track_e_login` `login`
  338. ON `user`.`user_id` = `login`.`login_user_id`
  339. WHERE `user`.`user_id` = '".$_uid."'
  340. ORDER BY `login`.`login_date` DESC LIMIT 1";
  341. }
  342. else
  343. {
  344. $sql = "SELECT `user`.*, `a`.`user_id` `is_admin`
  345. FROM $user_table
  346. LEFT JOIN $admin_table `a`
  347. ON `user`.`user_id` = `a`.`user_id`
  348. WHERE `user`.`user_id` = '".$_uid."'";
  349. }
  350. $result = api_sql_query($sql,__FILE__,__LINE__);
  351. if (mysql_num_rows($result) > 0)
  352. {
  353. // Extracting the user data
  354. $uData = mysql_fetch_array($result);
  355. $_user ['firstName'] = $uData ['firstname' ];
  356. $_user ['lastName' ] = $uData ['lastname' ];
  357. $_user ['mail' ] = $uData ['email' ];
  358. $_user ['lastLogin'] = $uData ['login_date'];
  359. $_user ['official_code'] = $uData ['official_code'];
  360. $_user ['picture_uri'] = $uData ['picture_uri'];
  361. $_user ['user_id'] = $uData ['user_id'];
  362. $_user ['language'] = $uData ['language'];
  363. $is_platformAdmin = (bool) (! is_null( $uData['is_admin']));
  364. $is_allowedCreateCourse = (bool) ($uData ['status'] == 1);
  365. api_session_register('_user');
  366. }
  367. else
  368. {
  369. exit("WARNING UNDEFINED UID !! ");
  370. }
  371. }
  372. else // no uid => logout or Anonymous
  373. {
  374. api_session_unregister('_user');
  375. api_session_unregister('_uid');
  376. }
  377. api_session_register('is_platformAdmin');
  378. api_session_register('is_allowedCreateCourse');
  379. }
  380. else // continue with the previous values
  381. {
  382. $_user = $_SESSION['_user'];
  383. $is_platformAdmin = $_SESSION['is_platformAdmin'];
  384. $is_allowedCreateCourse = $_SESSION['is_allowedCreateCourse'];
  385. }
  386. //////////////////////////////////////////////////////////////////////////////
  387. // COURSE INIT
  388. //////////////////////////////////////////////////////////////////////////////
  389. if (isset($cidReset) && $cidReset) // course session data refresh requested or empty data
  390. {
  391. if ($cidReq)
  392. {
  393. $course_table = Database::get_main_table(MAIN_COURSE_TABLE);
  394. $course_cat_table = Database::get_main_table(MAIN_CATEGORY_TABLE);
  395. $sql = "SELECT `course`.*, `course_category`.`code` `faCode`, `course_category`.`name` `faName`
  396. FROM $course_table
  397. LEFT JOIN $course_cat_table
  398. ON `course`.`category_code` = `course_category`.`code`
  399. WHERE `course`.`code` = '$cidReq'";
  400. $result = api_sql_query($sql,__FILE__,__LINE__);
  401. if (mysql_num_rows($result)>0)
  402. {
  403. $cData = mysql_fetch_array($result);
  404. $_cid = $cData['code' ];
  405. $_course['id' ] = $cData['code' ]; //auto-assigned integer
  406. $_course['name' ] = $cData['title' ];
  407. $_course['official_code'] = $cData['visual_code' ]; // use in echo
  408. $_course['sysCode' ] = $cData['code' ]; // use as key in db
  409. $_course['path' ] = $cData['directory' ]; // use as key in path
  410. $_course['dbName' ] = $cData['db_name' ]; // use as key in db list
  411. $_course['dbNameGlu' ] = $courseTablePrefix . $cData['db_name'] . $dbGlu; // use in all queries
  412. $_course['titular' ] = $cData['tutor_name' ];
  413. $_course['language' ] = $cData['course_language' ];
  414. $_course['extLink' ]['url' ] = $cData['department_url' ];
  415. $_course['extLink' ]['name'] = $cData['department_name'];
  416. $_course['categoryCode'] = $cData['faCode' ];
  417. $_course['categoryName'] = $cData['faName' ];
  418. $_course['visibility' ] = $cData['visibility'];
  419. $_course['subscribe_allowed'] = $cData['subscribe'];
  420. $_course['unubscribe_allowed'] = $cData['unsubscribe'];
  421. api_session_register('_cid');
  422. api_session_register('_course');
  423. }
  424. else
  425. {
  426. exit("WARNING UNDEFINED CID !! ");
  427. }
  428. }
  429. else
  430. {
  431. api_session_unregister('_cid');
  432. api_session_unregister('_course');
  433. }
  434. }
  435. else // continue with the previous values
  436. {
  437. if(empty($_SESSION['_course']) OR empty($_SESSION['_cid'])){ //no previous values...
  438. $_cid = -1; //set default values that will be caracteristic of being unset
  439. $_course = -1;
  440. }else{
  441. $_cid = $_SESSION['_cid' ];
  442. $_course = $_SESSION['_course'];
  443. }
  444. }
  445. //////////////////////////////////////////////////////////////////////////////
  446. // COURSE / USER REL. INIT
  447. //////////////////////////////////////////////////////////////////////////////
  448. if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) // session data refresh requested
  449. {
  450. if (isset($_uid) && $_uid && isset($_cid) && $_cid) // have keys to search data
  451. {
  452. if(api_get_setting('use_session_mode') != 'true')
  453. {
  454. $course_user_table = Database::get_main_table(MAIN_COURSE_USER_TABLE);
  455. $sql = "SELECT * FROM $course_user_table
  456. WHERE `user_id` = '$_uid'
  457. AND `course_code` = '$cidReq'";
  458. $result = api_sql_query($sql,__FILE__,__LINE__);
  459. if (mysql_num_rows($result) > 0) // this user have a recorded state for this course
  460. {
  461. $cuData = mysql_fetch_array($result);
  462. $is_courseMember = true;
  463. $is_courseTutor = (bool) ($cuData['tutor_id' ] == 1 );
  464. $is_courseAdmin = (bool) ($cuData['status'] == 1 );
  465. api_session_register('_courseUser');
  466. }
  467. else // this user has no status related to this course
  468. {
  469. $is_courseMember = false;
  470. $is_courseAdmin = false;
  471. $is_courseTutor = false;
  472. }
  473. $is_courseAdmin = (bool) ($is_courseAdmin || $is_platformAdmin);
  474. }
  475. else
  476. {
  477. // is it the session coach ?
  478. $sql = "SELECT 1
  479. FROM `".$mainDbName."`.`session`
  480. INNER JOIN `".$mainDbName."`.`session_rel_course`
  481. ON session_rel_course.id_session = session.id
  482. AND session_rel_course.course_code='$_cid'
  483. WHERE session.id_coach = $_uid";
  484. $result = api_sql_query($sql,__FILE__,__LINE__);
  485. if($row = mysql_fetch_array($result)){
  486. $_courseUser['role'] = 'Professor';
  487. $is_courseMember = true;
  488. $is_courseTutor = true;
  489. $is_courseAdmin = true;
  490. api_session_register('_courseUser');
  491. }
  492. else {
  493. // vérifier que c pas le coach du cours
  494. $sql = "SELECT 1
  495. FROM `".$mainDbName."`.`session_rel_course`
  496. WHERE session_rel_course.course_code='$_cid'
  497. AND session_rel_course.id_coach = $_uid";
  498. $result = api_sql_query($sql,__FILE__,__LINE__);
  499. if($row = mysql_fetch_array($result)){
  500. $_courseUser['role'] = 'Professor';
  501. $is_courseMember = true;
  502. $is_courseTutor = true;
  503. $is_courseAdmin = true;
  504. api_session_register('_courseUser');
  505. }
  506. else {
  507. // vérifier que c pas un élève de la session
  508. $sql = "SELECT * FROM `".$mainDbName."`.`session_rel_course_rel_user`
  509. WHERE `id_user` = '$_uid'
  510. AND `course_code` = '$cidReq'";
  511. $result = api_sql_query($sql,__FILE__,__LINE__);
  512. if (mysql_num_rows($result) > 0) // this user have a recorded state for this course
  513. {
  514. while($row = mysql_fetch_array($result)){
  515. $is_courseMember = true;
  516. $is_courseTutor = false;
  517. $is_courseAdmin = false;
  518. api_session_register('_courseUser');
  519. }
  520. }
  521. else
  522. {
  523. $sql = "SELECT * FROM `".$mainDbName."`.`course_rel_user`
  524. WHERE `user_id` = '$_uid'
  525. AND `course_code` = '$cidReq'";
  526. $result = api_sql_query($sql,__FILE__,__LINE__);
  527. if (mysql_num_rows($result) > 0) // this user have a recorded state for this course
  528. {
  529. $cuData = mysql_fetch_array($result);
  530. $_courseUser['role'] = $cuData['role' ];
  531. $is_courseMember = true;
  532. $is_courseTutor = (bool) ($cuData['tutor_id' ] == 1 );
  533. $is_courseAdmin = (bool) ($cuData['status'] == 1 );
  534. api_session_register('_courseUser');
  535. }
  536. else // this user has no status related to this course
  537. {
  538. $is_courseMember = false;
  539. $is_courseAdmin = false;
  540. $is_courseTutor = false;
  541. }
  542. }
  543. }
  544. }
  545. }
  546. }
  547. else // keys missing => not anymore in the course - user relation
  548. {
  549. //// course
  550. $is_courseMember = false;
  551. $is_courseAdmin = false;
  552. $is_courseTutor = false;
  553. api_session_unregister('_courseUser');
  554. }
  555. //DEPRECATED
  556. //$is_courseAllowed=($_cid && ($_course['visibility'] || $is_courseMember || $is_platformAdmin))?true:false;
  557. //NEW
  558. if (isset($_course))
  559. {
  560. if ($_course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
  561. $is_allowed_in_course = true;
  562. elseif ($_course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && isset($_uid) )
  563. $is_allowed_in_course = true;
  564. elseif ($_course['visibility'] == COURSE_VISIBILITY_REGISTERED && ($is_platformAdmin || $is_courseMember))
  565. $is_allowed_in_course = true;
  566. elseif ($_course['visibility'] == COURSE_VISIBILITY_CLOSED && ($is_platformAdmin || $is_courseAdmin))
  567. $is_allowed_in_course = true;
  568. else $is_allowed_in_course = false;
  569. }
  570. // save the states
  571. api_session_register('is_courseMember');
  572. api_session_register('is_courseAdmin');
  573. //api_session_register('is_courseAllowed'); //deprecated old permission var
  574. api_session_register('is_courseTutor');
  575. api_session_register('is_allowed_in_course'); //new permission var
  576. }
  577. else // continue with the previous values
  578. {
  579. $_courseUser = $_SESSION ['_courseUser' ];
  580. $is_courseMember = $_SESSION ['is_courseMember' ];
  581. $is_courseAdmin = $_SESSION ['is_courseAdmin' ];
  582. //$is_courseAllowed = $_SESSION ['is_courseAllowed']; //deprecated
  583. $is_allowed_in_course = $_SESSION ['is_allowed_in_course'];
  584. $is_courseTutor = $_SESSION ['is_courseTutor' ];
  585. }
  586. //////////////////////////////////////////////////////////////////////////////
  587. // GROUP INIT
  588. //////////////////////////////////////////////////////////////////////////////
  589. if ((isset($gidReset) && $gidReset) || (isset($cidReset) && $cidReset)) // session data refresh requested
  590. {
  591. if ($gidReq && $_cid ) // have keys to search data
  592. {
  593. $group_table = Database::get_course_table(GROUP_TABLE);
  594. $sql = "SELECT * FROM $group_table WHERE `id` = '$gidReq'";
  595. $result = api_sql_query($sql,__FILE__,__LINE__);
  596. if (mysql_num_rows($result) > 0) // This group has recorded status related to this course
  597. {
  598. $gpData = mysql_fetch_array($result);
  599. $_gid = $gpData ['id' ];
  600. api_session_register('_gid');
  601. }
  602. else
  603. {
  604. exit("WARNING UNDEFINED GID !! ");
  605. }
  606. }
  607. elseif(isset($_SESSION['_gid']) or isset($_gid)) // Keys missing => not anymore in the group - course relation
  608. {
  609. api_session_unregister('_gid');
  610. }
  611. }
  612. elseif(isset($_SESSION['_gid'])) // continue with the previous values
  613. {
  614. $_gid = $_SESSION ['_gid' ];
  615. }else{ //if no previous value, assign caracteristic undefined value
  616. $_gid = -1;
  617. }
  618. if(isset($_cid))
  619. {
  620. $tbl_course = Database::get_main_table(MAIN_COURSE_TABLE);
  621. $sql="UPDATE $tbl_course SET last_visit=NOW() WHERE code='$_cid'";
  622. api_sql_query($sql,__FILE__,__LINE__);
  623. }
  624. ?>