PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/doceboLms/lib/lib.preoperation.php

https://github.com/yourenglishsolution/YES-ML
PHP | 443 lines | 289 code | 85 blank | 69 comment | 98 complexity | f802c647a5da8dba816311f03a680b71 MD5 | raw file
  1. <?php defined("IN_DOCEBO") or die('Direct access is forbidden.');
  2. /* ======================================================================== \
  3. | DOCEBO - The E-Learning Suite |
  4. | |
  5. | Copyright (c) 2010 (Docebo) |
  6. | http://www.docebo.com |
  7. | License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
  8. \ ======================================================================== */
  9. // redirection
  10. if( !isset($_GET['no_redirect']) && !isset($_POST['no_redirect']) ) {
  11. if(Docebo::user()->isAnonymous()
  12. && (!isset($GLOBALS['modname']) || ($GLOBALS['modname'] != 'login'))
  13. && !isset($_GET['login_user']) && !isset($_POST['login_user']) ) {
  14. require_once(_base_.'/lib/lib.platform.php');
  15. $pl_man =& PlatformManager::CreateInstance();
  16. $pl = $pl_man->getHomePlatform();
  17. if($pl != 'cms') {
  18. // Added by Claudio Redaelli
  19. $_SESSION['login_requestedURL'] = "?" . $_SERVER['QUERY_STRING'];
  20. $GLOBALS['op'] = 'login';
  21. $GLOBALS['modname'] = 'login';
  22. Util::jump_to('../index.php');
  23. }
  24. }
  25. }
  26. if(Get::sett('stop_concurrent_user') == 'on') {
  27. if(!Docebo::user()->isAnonymous() && isset($_SESSION['idCourse'])) {
  28. //two user logged at the same time
  29. if(!TrackUser::checkSession(getLogUserId())) {
  30. TrackUser::resetUserSession(getLogUserId());
  31. $_SESSION = array();
  32. session_destroy();
  33. Util::jump_to(Get::rel_path('lms').'/index.php?modname=login&op=logout&msg=102');
  34. }
  35. }
  36. }
  37. if(isset($_SESSION['must_renew_pwd']) && $_SESSION['must_renew_pwd'] == 1) {
  38. $GLOBALS['modname'] = '';
  39. $GLOBALS['op'] = '';
  40. if(strpos($GLOBALS['req'], 'lms/profile') === false) {
  41. $GLOBALS['req'] = 'lms/profile/renewalpwd';
  42. }
  43. }
  44. if($GLOBALS['modname'] == '' && $GLOBALS['op'] == '' && $GLOBALS['req'] == '' && !Docebo::user()->isAnonymous()) {
  45. if(!isset($_SESSION['idCourse'])) {
  46. // the user isn't into a course, redirect it to the mycourses area
  47. $_SESSION['current_main_menu'] = '1';
  48. $_SESSION['sel_module_id'] = '1';
  49. $GLOBALS['req'] = _after_login_;
  50. } else {
  51. //redirect the user in the leaved module of the course
  52. if($_SESSION['sel_module_id'] !=0) {
  53. $query = "SELECT module_name, default_op, mvc_path"
  54. ." FROM %lms_module"
  55. ." WHERE idModule = ".(int)$_SESSION['sel_module_id'];
  56. list($modname, $op, $mvc_path) = sql_fetch_row(sql_query($query));
  57. if($mvc_path !== '') $GLOBALS['req'] = $mvc_path;
  58. $GLOBALS['modname'] = $modname;
  59. $GLOBALS['op'] = $op;
  60. }
  61. }
  62. }
  63. /**
  64. * SSO
  65. * operation that is needed before loading grafiphs element, menu and so on
  66. * index.php?login_user=staff&time=200812101752&token=5D93BCEDF500E9759E4870492AF32E7A
  67. */
  68. $login_user = Get::req('login_user', DOTY_MIXED, '');
  69. if($login_user != '' && Get::sett('sso_token', 'off') == 'on') {
  70. $time = Get::req('time', DOTY_MIXED, '');
  71. $secret = Get::sett('sso_secret', '8ca0f69afeacc7022d1e589221072d6bcf87e39c');
  72. $token = strtoupper(Get::req('token', DOTY_MIXED, ''));
  73. $recalc_token = strtoupper(md5(strtolower($login_user).','.$time.','.$secret));
  74. if($recalc_token == $token) {
  75. //login
  76. $username = '/'.$login_user;
  77. $user_manager =& $GLOBALS['current_user']->getAclManager();
  78. $user_info = $user_manager->getUser(false, $username);
  79. if($user_info != false) {
  80. $du = new DoceboUser( $username, 'public_area' );
  81. $du->setLastEnter(date("Y-m-d H:i:s"));
  82. $_SESSION['user_enter_mark'] = time();
  83. $du->loadUserSectionST();
  84. $du->SaveInSession();
  85. $GLOBALS['current_user'] = $du;
  86. $id_course = Get::req('id_course', DOTY_INT, 0);
  87. $next_action = Get::req('act', DOTY_STRING, 'none');
  88. $id_item = Get::req('id_item', DOTY_INT, '');
  89. $chapter = Get::req('chapter', DOTY_MIXED, false);
  90. if($id_course) {
  91. // if we have a id_course setted we will log the user into the course,
  92. // if no specific action are required we will redirect the user into the first page
  93. // otherwise we will continue to another option
  94. require_once(_lms_.'/lib/lib.course.php');
  95. logIntoCourse($id_course, ( $next_action == false || $next_action == 'none' ? true : false ));
  96. // specific action required
  97. switch($next_action) {
  98. case "playsco" : {
  99. $linkto = 'index.php?modname=organization&op=custom_playitem&id_course='.$id_course.'&courseid='.$id_course.'&id_item='.$id_item.'&start_from_chapter='.$chapter.'&collapse_menu=1';
  100. Util::jump_to($linkto);
  101. };break;
  102. }
  103. }
  104. Util::jump_to( 'index.php?r='. _after_login_ );
  105. } else {
  106. Util::jump_to('../index.php?access_fail=1');
  107. }
  108. } else {
  109. Util::jump_to('../index.php?access_fail=1');
  110. }
  111. }
  112. $next_action = Get::req('act', DOTY_STRING, false);
  113. if($next_action != false && Get::sett('sco_direct_play', 'off') == 'on') {
  114. $id_course = Get::req('id_course', DOTY_INT, 0);
  115. $id_item = Get::req('id_item', DOTY_INT, '');
  116. $chapter = Get::req('chapter', DOTY_MIXED, false);
  117. if($id_course) {
  118. // if we have a id_course setted we will log the user into the course,
  119. // if no specific action are required we will redirect the user into the first page
  120. // otherwise we will continue to another option
  121. require_once(_lms_.'/lib/lib.course.php');
  122. logIntoCourse($id_course, ( $next_action == false || $next_action == 'none' ? true : false ));
  123. // specific action required
  124. switch($next_action) {
  125. case "playsco" : {
  126. $linkto = 'index.php?modname=organization&op=custom_playitem&id_item='.$id_item.'&start_from_chapter='.$chapter.'&collapse_menu=1';
  127. Util::jump_to($linkto);
  128. };break;
  129. }
  130. }
  131. }
  132. //operation that is needed before loading grafiphs element, menu and so on
  133. switch($GLOBALS['op']) {
  134. //login control
  135. case "confirm" : {
  136. if($GLOBALS['modname'] == 'login') {
  137. require_once(_base_.'/lib/lib.usermanager.php');
  138. $manager = new UserManager();
  139. $login_data = $manager->getLoginInfo();
  140. $manager->saveUserLoginData();
  141. if($login_data['userid'] != ''){
  142. if(Get::sett('ldap_used') !== 'on')
  143. {
  144. require_once(_base_.'/lib/lib.acl.php' );
  145. $acl = new DoceboACL();
  146. $acl_man =& $acl->getACLManager();
  147. }
  148. $GLOBALS['current_user'] =& DoceboUser::createDoceboUserFromLogin( $login_data['userid'],
  149. $login_data['password'],
  150. 'public_area',
  151. $login_data['lang'] );
  152. if( $GLOBALS['current_user'] === FALSE ) {
  153. $GLOBALS['current_user'] =& DoceboUser::createDoceboUserFromSession('public_area');
  154. $GLOBALS['access_fail'] = true;
  155. $GLOBALS['op'] = 'login';
  156. Util::jump_to('../index.php?access_fail=1');
  157. } else {
  158. //loading related ST
  159. Docebo::user()->loadUserSectionST('/lms/course/public/');
  160. $pwd_elapsed = Docebo::user()->isPasswordElapsed();
  161. if($pwd_elapsed > 0) {
  162. //$GLOBALS['modname'] = 'profile';
  163. //$GLOBALS['op'] = 'renewalpwd';
  164. $GLOBALS['modname'] = '';
  165. $GLOBALS['op'] = '';
  166. $GLOBALS['req'] = 'lms/profile/renewalpwd';
  167. //Util::jump_to('index.php?r=lms/profile/renewalpwd');
  168. } else {
  169. $_SESSION['current_main_menu'] = '1';
  170. $_SESSION['sel_module_id'] = '1';
  171. }
  172. // perform other platforms login operation
  173. require_once(_base_.'/lib/lib.platform.php');
  174. $pm =& PlatformManager::createInstance();
  175. $pm->doCommonOperations("login");
  176. Docebo::user()->SaveInSession();
  177. /**********************************
  178. *
  179. * YES SAS - Your English Solution
  180. * Author : Polo
  181. * Created Date : 28/04/11
  182. * Modified Date : 28/04/11
  183. * Version : 1.0
  184. * Description : Modification du formulaire
  185. *
  186. **********************************/
  187. if(isset($_POST['remember']))
  188. {
  189. $user = Docebo::user();
  190. $sql = "SELECT * FROM %adm_user WHERE idst='".$user->idst."' LIMIT 1";
  191. $row = sql_fetch_object(sql_query($sql));
  192. // Création du cookie avec cryptage des données
  193. $key = $row->idst.'.'.$row->pass;
  194. setcookie("yes_autoident", $key, time()+(60*60*24*30), '/', '.yesmicrolearning.fr'); // 30 jours
  195. }
  196. // reset user template:
  197. resetTemplate();
  198. // end of normal login operation
  199. // check for policy and mandatory fields
  200. if (Get::sett('request_mandatory_fields_compilation', 'off') == 'on') {
  201. //if there are field that must be compiled or the privacy policy must be accepted
  202. $pcm = new PrecompileLms();
  203. if($pcm->compileRequired()) {
  204. Util::jump_to('index.php?r=lms/precompile/show');
  205. }
  206. }
  207. // the user must be redirected to a specific use
  208. if(isset($_SESSION['login_requestedURL'])
  209. && !empty($_SESSION['login_requestedURL'])
  210. && strcmp('id_course', $_SESSION['login_requestedURL'])) {
  211. $url = $_SESSION['login_requestedURL'];
  212. unset($_SESSION['login_requestedURL']);
  213. $str = parse_url($url);
  214. parse_str($str['query'], $vars );
  215. if(isset($vars['id_course'])) {
  216. require_once($GLOBALS['where_lms'].'/lib/lib.course.php');
  217. if(logIntoCourse($vars['id_course'], false)) Util::jump_to($url);
  218. }
  219. }
  220. //goto welcome page
  221. $_SESSION['current_main_menu'] = '1';
  222. $_SESSION['sel_module_id'] = '1';
  223. if ($pwd_elapsed <= 0) {
  224. if(Get::sett('first_catalogue') == 'on') Util::jump_to('index.php?r=lms/catalog/show');
  225. Util::jump_to( 'index.php?r='._after_login_ );
  226. }
  227. // end login
  228. }
  229. } else {
  230. Util::jump_to('../index.php');
  231. }
  232. }
  233. };break;
  234. case "logout" : {
  235. require_once($GLOBALS['where_lms'].'/lib/lib.track_user.php');
  236. if(!Docebo::user()->isAnonymous() && isset($_SESSION['idCourse'])) {
  237. TrackUser::setActionTrack(getLogUserId(), $_SESSION['idCourse'], '', '');
  238. }
  239. //i need to save the language of the user in order to use it again after logout
  240. $language = Lang::get();
  241. if(!Docebo::user()->isAnonymous()) {
  242. /**********************************
  243. *
  244. * YES SAS - Your English Solution
  245. * Author : Polo
  246. * Created Date : 28/04/11
  247. * Modified Date : 28/04/11
  248. * Version : 1.0
  249. * Description : Auto login via le cookie
  250. *
  251. **********************************/
  252. setcookie('yes_autoident', '', -1, '/', '.yesmicrolearning.fr');
  253. TrackUser::logoutSessionCourseTrack();
  254. $_SESSION = array();
  255. session_destroy();
  256. // load standard language module and put it global
  257. $glang =& DoceboLanguage::createInstance( 'standard', 'framework');
  258. // Recreate Anonymous user
  259. $GLOBALS['current_user'] =& DoceboUser::createDoceboUserFromSession('public_area');
  260. $GLOBALS['logout'] = true;
  261. require_once(_base_.'/lib/lib.platform.php');
  262. $pm =& PlatformManager::createInstance();
  263. $pm->doCommonOperations("logout");
  264. }
  265. $GLOBALS['op'] = 'login';
  266. $GLOBALS['modname'] = 'login';
  267. $query = 'logout=1&special=changelang&new_lang='.$language;
  268. if (isset($_GET['msg']) && !empty($_GET['msg'])) {
  269. $query ='msg='.(int)$_GET['msg'];
  270. }
  271. Util::jump_to('../index.php?'.$query);
  272. };break;
  273. case "aula" : {
  274. require_once($GLOBALS['where_lms'].'/lib/lib.course.php');
  275. if(!logIntoCourse($_GET['idCourse'], true)) {
  276. $_SESSION['current_main_menu'] = '1';
  277. $_SESSION['sel_module_id'] = '1';
  278. $GLOBALS['modname'] = 'middlearea';
  279. $GLOBALS['op'] = 'show';
  280. }
  281. };break;
  282. //registering menu information
  283. case "unregistercourse" : {
  284. //if a course is selected the selection is deleted
  285. if (isset($_SESSION['idCourse'])) {
  286. TrackUser::closeSessionCourseTrack();
  287. unset($_SESSION['idCourse']);
  288. unset($_SESSION['idEdition']);
  289. }
  290. if(isset($_SESSION['test_assessment'])) unset($_SESSION['test_assessment']);
  291. if(isset($_SESSION['direct_play'])) unset($_SESSION['direct_play']);
  292. if(isset($_SESSION['cp_assessment_effect'])) unset($_SESSION['cp_assessment_effect']);
  293. $_SESSION['current_main_menu'] = '1';
  294. $_SESSION['sel_module_id'] = '1';
  295. $_SESSION['is_ghost'] = false;
  296. $GLOBALS['modname'] = 'middlearea';
  297. $GLOBALS['op'] = 'show';
  298. };break;
  299. case "selectMain" : {
  300. $_SESSION['current_main_menu'] = (int)$_GET['idMain'];
  301. $first_page = firstPage( $_SESSION['current_main_menu'] );
  302. if($first_page['modulename'] != '')
  303. Util::jump_to( 'index.php?modname='.$first_page['modulename'].'&op='.$first_page['op'].'&sel_module='.$first_page['idModule']);
  304. };break;
  305. //change language for register user
  306. case "registerconfirm" : {
  307. setLanguage($_POST['language']);
  308. };break;
  309. case "registerme" : {
  310. list($language_reg) = sql_fetch_row(sql_query("
  311. SELECT language
  312. FROM ".$GLOBALS['prefix_lms']."_user_temp
  313. WHERE random_code = '".$_GET['random_code']."'"));
  314. if($language_reg != '') setLanguage($language_reg);
  315. };break;
  316. }
  317. // special operation
  318. $sop = importVar('sop', false, '');
  319. if($sop) {
  320. if(is_array($sop)) $sop = key($sop);
  321. switch($sop) {
  322. case "setcourse" : {
  323. $id_c = Get::req('sop_idc', DOTY_INT, 0);
  324. if (isset($_SESSION['idCourse']) && $_SESSION['idCourse'] != $id_c) {
  325. TrackUser::closeSessionCourseTrack();
  326. unset($_SESSION['idCourse']);
  327. unset($_SESSION['idEdition']);
  328. require_once($GLOBALS['where_lms'].'/lib/lib.course.php');
  329. logIntoCourse($id_c, false);
  330. } elseif(!isset($_SESSION['idCourse'])) {
  331. require_once($GLOBALS['where_lms'].'/lib/lib.course.php');
  332. logIntoCourse($id_c, false);
  333. }
  334. if(isset($_SESSION['cp_assessment_effect'])) unset($_SESSION['cp_assessment_effect']);
  335. };break;
  336. case "resetselmodule" : {
  337. unset($_SESSION['sel_module_id']);
  338. };break;
  339. case "unregistercourse" : {
  340. if (isset($_SESSION['idCourse'])) {
  341. TrackUser::closeSessionCourseTrack();
  342. unset($_SESSION['idCourse']);
  343. unset($_SESSION['idEdition']);
  344. }
  345. if(isset($_SESSION['cp_assessment_effect'])) unset($_SESSION['cp_assessment_effect']);
  346. };break;
  347. case "changelang" : {
  348. Lang::set(Get::req('new_lang', DOTY_MIXED));
  349. $_SESSION['changed_lang'] = true;
  350. };break;
  351. }
  352. }
  353. // istance the course description class
  354. if(isset($_SESSION['idCourse']) && !isset($GLOBALS['course_descriptor'])) {
  355. require_once(_lms_.'/lib/lib.course.php');
  356. $GLOBALS['course_descriptor'] = new DoceboCourse($_SESSION['idCourse']);
  357. }
  358. ?>