PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/community/www/index.php

https://github.com/svn2github/efront-lms
PHP | 963 lines | 881 code | 9 blank | 73 comment | 296 complexity | 7d5e965c49e58904ad47a1ca6ceffce6 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Platform index page
  4. *
  5. * This is the index page, allowing for logging in, registering new users,
  6. * contacting and resetting password
  7. *
  8. * @package eFront
  9. * @version 3.6.0
  10. */
  11. session_cache_limiter('nocache');
  12. session_start(); //This causes the double-login problem, where the user needs to login twice when already logged in with the same browser
  13. if (!isset($_SESSION['s_login'])) {
  14. session_regenerate_id();
  15. setcookie("PHPSESSID", session_id(), 0, false, false, false, true);
  16. }
  17. $path = "../libraries/";
  18. //Automatically redirect to installation page if configuration file is missing
  19. if (!is_file($path."configuration.php")) { //If the configuration file does not exist, this is a fresh installation, so redirect to installation page
  20. is_file("install/index.php") ? header("location:install/index.php") : print('Failed locating configuration file <br/> Failed locating installation directory <br/> Please execute installation script manually <br/>');
  21. exit;
  22. } else {
  23. /** Configuration file */
  24. require_once $path."configuration.php";
  25. }
  26. if ($GLOBALS['configuration']['webserver_auth']) {
  27. eval('$usernameVar='.$GLOBALS['configuration']['username_variable'].';');
  28. $currentUser = EfrontUser :: checkWebserverAuthentication();
  29. $currentUser -> login($currentUser -> user['password'], true);
  30. }
  31. //@todo:temporary here, should leave
  32. $cacheId = null;
  33. $message = $message_type = '';
  34. $benchmark = new EfrontBenchmark($debug_TimeStart);
  35. $benchmark -> set('init');
  36. //Set headers in order to eliminate browser cache (especially IE's)
  37. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  38. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  39. //Delete installation directory after install/upgrade
  40. if (is_dir("install") && isset($_GET['delete_install'])) {
  41. try {
  42. $dir = new EfrontDirectory('install');
  43. $dir -> delete();
  44. } catch (Exception $e) {
  45. echo "The installation directory could not be deleted. Please delete it manually or your system security is at risk.";
  46. }
  47. }
  48. if (!$smarty -> is_cached('index.tpl', $cacheId) || !$GLOBALS['configuration']['smarty_caching']) {
  49. //Get available languages
  50. $languages = array();
  51. foreach (EfrontSystem :: getLanguages() as $key => $value) {
  52. if ($value['active']) {
  53. $languages[$key] = $value['translation'];
  54. }
  55. }
  56. //ksort($languages);
  57. $smarty -> assign("T_LANGUAGES", $languages);
  58. $debug_InitTime = microtime(true) - $debug_TimeStart;
  59. if ($configuration['cms_page'] != "" && sizeof($_GET) == 0 && file_exists(G_CURRENTTHEMEPATH."external/".$GLOBALS['configuration']['cms_page'].".php")){ //if there is cms page and no get parameter defined
  60. eF_redirect(G_SERVERNAME.G_CURRENTTHEMEURL."external/".$configuration['cms_page'].".php");
  61. }
  62. if (isset($_GET['logout']) && !isset($_POST['submit_login'])) { //If user wants to log out
  63. if (isset($_SESSION['s_login']) && $_SESSION['s_login']) {
  64. try {
  65. $user = EfrontUserFactory :: factory($_SESSION['s_login']);
  66. $user -> logout(session_id());
  67. if ($GLOBALS['configuration']['logout_redirect']) {
  68. strpos($GLOBALS['configuration']['logout_redirect'], 'https://') === 0 || strpos($GLOBALS['configuration']['logout_redirect'], 'http://') === 0 ? header("location:".$GLOBALS['configuration']['logout_redirect']) : header("location:http://".$GLOBALS['configuration']['logout_redirect']);
  69. }
  70. } catch (EfrontUserException $e) {
  71. unset($_SESSION);
  72. session_destroy();
  73. $message = $e -> getMessage();
  74. }
  75. }
  76. if (isset($_GET['reason']) && $_GET['reason']=='timeout') {
  77. $message = _YOUHAVELOGGEDOUTBECAUSEYOURSESSIONHASTIMEDOUT;
  78. $message_type = 'failure';
  79. }
  80. }
  81. //Show information in the selected language
  82. if (isset($_GET['bypass_language']) && in_array($_GET['bypass_language'], array_keys($languages))) {
  83. $_SESSION['s_language'] = $_GET['bypass_language'];
  84. }
  85. //Keep persisted language across page calls
  86. if (isset($_SESSION['s_language'])) {
  87. $smarty -> assign("T_LANGUAGE", $_SESSION['s_language']);
  88. } else {
  89. $smarty -> assign("T_LANGUAGE", $GLOBALS['configuration']['default_language']);
  90. }
  91. }
  92. /*
  93. * Check if you should input the JS code to
  94. * trigger sending the next notificatoin emails
  95. * Since 3.6.0
  96. */
  97. if (EfrontNotification::shouldSendNextNotifications()) {
  98. $smarty -> assign("T_TRIGGER_NEXT_NOTIFICATIONS_SEND", 1);
  99. $_SESSION['send_next_notifications_now'] = 0; // the msg that triggered the immediate send should be sent now
  100. }
  101. //if there is cms page and no get parameter defined, redirect to the cms page
  102. if ($configuration['cms_page'] != "" && sizeof($_GET) == 0 && file_exists(G_CURRENTTHEMEPATH."external/".$GLOBALS['configuration']['cms_page'].".php")) { //check also if file exists to prevent from broken link
  103. //eF_redirect("".G_RELATIVEADMINLINK.$GLOBALS['configuration']['cms_page'].".php");
  104. eF_redirect("".G_SERVERNAME.G_CURRENTTHEMEURL."external/".$configuration['cms_page'].".php");
  105. }
  106. //The user logged out
  107. if (isset($_GET['logout']) && !isset($_POST['submit_login'])) {
  108. //session_start(); //Isn't needed here if the head session_start() is in place
  109. if (isset($_SESSION['s_login']) && $_SESSION['s_login']) {
  110. try {
  111. $user = EfrontUserFactory :: factory($_SESSION['s_login']);
  112. $user -> logout(session_id());
  113. //Redirect user to another page, if such a configuration setting exists
  114. if ($GLOBALS['configuration']['logout_redirect']) {
  115. if ($GLOBALS['configuration']['logout_redirect'] == 'close') {
  116. echo "<script>window.close();</script>";
  117. } else {
  118. strpos($GLOBALS['configuration']['logout_redirect'], 'http://') === 0 ? eF_redirect("".$GLOBALS['configuration']['logout_redirect']) : header("location:http://".$GLOBALS['configuration']['logout_redirect']);
  119. }
  120. }
  121. } catch (EfrontUserException $e) {
  122. $message = $e -> getMessage();
  123. $message_type = 'failure';
  124. }
  125. }
  126. }
  127. if (!$smarty -> is_cached('index.tpl', $cacheId) || !$GLOBALS['configuration']['smarty_caching']) {
  128. $blocks = array('login' => array('title' => _LOGINENTRANCE, 'image' => '32x32/keys.png'),
  129. 'online' => array('title' => _USERSONLINE, 'image' => '32x32/users.png'),
  130. 'lessons' => array('title' => _COURSES, 'image' => '32x32/theory.png'),
  131. 'selectedLessons' => array('title' => _SELECTEDCOURSES, 'image' => '32x32/shopping_basket.png'),
  132. 'checker' => array('title' => _OPTIONSCHECKER, 'image' => '32x32/success.png'),
  133. 'news' => array('title' => _SYSTEMNEWS, 'image' => '32x32/announcements.png'));
  134. if (!empty($GLOBALS['currentTheme'] -> layout['positions']['enabled'])) {
  135. $blocks['links'] = array('title' => _LINKS, 'image' => '32x32/generic.png');
  136. }
  137. //$customBlocks = unserialize($GLOBALS['configuration']['custom_blocks']);
  138. if (isset($currentTheme -> layout['custom_blocks']) && is_array($currentTheme -> layout['custom_blocks'])) {
  139. $customBlocks = $currentTheme -> layout['custom_blocks'];
  140. } else {
  141. $customBlocks = array();
  142. }
  143. //Uncomment the line below if you want custom blocks to be sorted alphabetically in Links block
  144. //$customBlocks = eF_multiSort($customBlocks, 'title');
  145. foreach ($customBlocks as $key => $block) {
  146. $blocks[$key] = array('title' => $block['title'], 'image' => '32x32/generic.png');
  147. }
  148. if ($GLOBALS['configuration']['disable_online_users'] == 1) {
  149. unset($blocks['online']);
  150. }
  151. $smarty -> assign("T_CUSTOM_BLOCKS", $customBlocks);
  152. $smarty -> assign("T_BLOCKS", $blocks);
  153. $smarty -> assign("T_POSITIONS", $GLOBALS['currentTheme'] -> layout['positions']);
  154. if (isset($_SESSION['s_current_branch'])) {
  155. $branch = new EfrontBranch($_SESSION['s_current_branch']);
  156. $constraints = array('active' => true, 'archive' => false, 'instance' => false, 'sort' => 'name');
  157. $courses = $branch->getBranchCourses($constraints);
  158. $lessons = array();
  159. }
  160. $directionsTree = new EfrontDirectionsTree();
  161. $options = array('lessons_link' => basename($_SERVER['PHP_SELF']).'?ctg=lesson_info&lessons_ID=',
  162. 'courses_link' => basename($_SERVER['PHP_SELF']).'?ctg=lesson_info&courses_ID=',
  163. 'search' => true,
  164. 'catalog' => true,
  165. 'url' => $_SERVER['PHP_SELF'],
  166. 'collapse' => $GLOBALS['configuration']['collapse_catalog'],
  167. 'buy_link' => true,
  168. 'course_lessons' => false);
  169. include("directions_tree.php");
  170. }
  171. /* -------------------------------------------------------Login part-------------------------------------------------------------------*/
  172. if (isset($_GET['autologin']) && eF_checkParameter($_GET['autologin'], 'hex')) {
  173. try {
  174. $result = eF_getTableDataFlat("users", "login,autologin,password,user_type", "active=1 and autologin !=''");
  175. $autolinks = $result['autologin'];
  176. $key = array_search($_GET['autologin'], $autolinks);
  177. if ($key !== false) {
  178. //pr($result['login'][$key]);
  179. $user = EfrontUserFactory :: factory($result['login'][$key]);
  180. $pattern = $user -> user['login']."_".$user -> user['timestamp'];
  181. $pattern = md5($pattern.G_MD5KEY);
  182. if (strcmp($pattern, $_GET['autologin']) == 0) {
  183. $user -> login($user -> user['password'], true);
  184. if (isset($_GET['lessons_ID']) && eF_checkParameter($_GET['lessons_ID'], 'id')) {
  185. //check for valid lesson
  186. setcookie('c_request', $user -> user['user_type'].'.php?lessons_ID='.$_GET['lessons_ID'], time() + 86400, false, false, false, true);
  187. }
  188. if (isset($_GET['view_unit']) && eF_checkParameter($_GET['view_unit'], 'id')) {
  189. //check for valid lesson
  190. setcookie('c_request', $user -> user['user_type'].'.php?view_unit='.$_GET['view_unit'], time() + 86400, false, false, false, true);
  191. }
  192. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_VISITED, "users_LOGIN" => $user -> user['login'], "users_name" => $user -> user['name'], "users_surname" => $user -> user['surname']));
  193. loginRedirect($user -> user['user_type']);
  194. exit;
  195. }
  196. }
  197. } catch (EfrontUserException $e) {}
  198. }
  199. if (isset($_GET['ctg']) && $_GET['ctg'] == "expired") {
  200. if (isset($_SESSION['s_login'])) {
  201. $currentUser = EfrontUserFactory :: factory($_SESSION['s_login']);
  202. $currentUser -> logout(session_id());
  203. }
  204. eF_redirect(basename($_SERVER['PHP_SELF'])."?ctg=login&message=".urlencode(_YOURSESSIONHASEXPIREDPLEASELOGINAGAIN));
  205. }
  206. if (isset($_COOKIE['cookie_login']) && isset($_COOKIE['cookie_password']) && eF_checkParameter($_COOKIE['cookie_login'], 'login') && $_GET['ctg'] != 'agreement') {
  207. try {
  208. $user = EfrontUserFactory :: factory($_COOKIE['cookie_login']);
  209. $user -> login($_COOKIE['cookie_password'], true);
  210. if ($GLOBALS['configuration']['show_license_note'] && $user -> user['viewed_license'] == 0) {
  211. eF_redirect("index.php?ctg=agreement");
  212. } else {
  213. // Check if the mobile version of eFront is required - if so set a session variable accordingly
  214. //eF_setMobile();
  215. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_VISITED, "users_LOGIN" => $user -> user['login'], "users_name" => $user -> user['name'], "users_surname" => $user -> user['surname']));
  216. loginRedirect($user -> user['user_type']);
  217. }
  218. exit;
  219. } catch (EfrontUserException $e) {}
  220. }
  221. /*
  222. * Make sure that if a user has registered lessons without being logged in,
  223. * after he logs in he will be redirected to the "complete registration" page
  224. * In addition, set "login_mode" to 1, meaning that the user pressed the "continue"
  225. * button in his cart, so the next step should be loging in
  226. */
  227. if (isset($_GET['register_lessons'])) {
  228. if (!$_SESSION['s_login']) {
  229. $message = _PLEASELOGINTOCOMPLETEREGISTRATION;
  230. if ($GLOBALS['configuration']['signup']) {
  231. $message .= _OTHERWISEPLEASEREGISTER;
  232. }
  233. $message_type = 'success';
  234. }
  235. // setcookie('c_request', 'index.php?register_lessons=1&checkout=1', time() + 300);
  236. $_SESSION['login_mode'] = '1';
  237. } elseif (!isset($_GET['ctg']) || $_GET['ctg'] == 'lessons') {
  238. // setcookie('c_request', '', time() - 86400);
  239. $_SESSION['login_mode'] = '0';
  240. }
  241. isset($_GET['ctg']) && $_GET['ctg'] == 'login' ? $postTarget = basename($_SERVER['PHP_SELF'])."?ctg=login" : $postTarget = basename($_SERVER['PHP_SELF'])."?index_page";
  242. //isset($_GET['ctg']) && $_GET['ctg'] == 'login' ? $postTarget = ($_SERVER['SCRIPT_NAME'])."?ctg=login" : $postTarget = ($_SERVER['SCRIPT_NAME'])."?index_page";
  243. $form = new HTML_QuickForm("login_form", "post", $postTarget, "", "class = 'indexForm'", true);
  244. $form -> removeAttribute('name');
  245. $form -> registerRule('checkParameter', 'callback', 'eF_checkParameter'); //Register this rule for checking user input with our function, eF_checkParameter
  246. $form -> addElement('text', 'login', _LOGIN, 'class = "inputText" id = "login_box"');
  247. $form -> addRule('login', _THEFIELD.' "'._LOGIN.'" '._ISMANDATORY, 'required', null, 'client');
  248. $form -> addRule('login', _INVALIDLOGIN, 'checkParameter', 'login');
  249. $form -> addElement('password', 'password', _PASSWORD, 'class = "inputText" tabindex = "0"');
  250. $form -> addRule('password', _THEFIELD.' "'._PASSWORD.'" '._ISMANDATORY, 'required', null, 'client');
  251. $form -> addElement('checkbox', 'remember', _KEEPMELOGGEDIN, null, 'class = "inputCheckbox" style = "vertical-align:middle"');
  252. $form -> addElement('submit', 'submit_login', _ENTER, 'class = "flatButton"');
  253. $form->disable_csrf = true;
  254. if ($form -> isSubmitted() && $form -> validate()) {
  255. try {
  256. $user = EfrontUserFactory :: factory(trim($form -> exportValue('login')));
  257. if ($GLOBALS['configuration']['lock_down'] && $user -> user['user_type'] != 'administrator') {
  258. eF_redirect("index.php?message=".urlencode(_LOCKDOWNONLYADMINISTRATORSCANLOGIN)."&message_type=failure");
  259. exit;
  260. }
  261. if ($_SESSION['s_current_branch']) {
  262. $branch = new EfrontBranch($_SESSION['s_current_branch']);
  263. $branchUsers = $branch -> getBranchTreeUsers();
  264. if ($user->user['user_type'] != 'administrator' && (empty($branchUsers) || in_array($user -> user['login'], array_keys($branchUsers)) === false)) {
  265. eF_redirect("index.php?message=".urlencode(_YOUARENOTAMEMBEROFTHISBRANCH));
  266. }
  267. } else if ($user->user['user_type'] != 'administrator' && !$GLOBALS['configuration']['allow_direct_login']) {
  268. eF_redirect("index.php?message=".urlencode(_YOUCANONLYLOGINFROMYOURBRANCHURL));
  269. }
  270. $user -> login($form -> exportValue('password'));
  271. //Check whether there are any fields that must be filled in by the user
  272. $result = eF_getTableData("user_profile", "name", "active=1 and mandatory = 2");
  273. foreach ($result as $value) {
  274. if ($user -> user[$value['name']] == '' || is_null($user -> user[$value['name']])) {
  275. $_SESSION['missing_fields'] = 1;
  276. }
  277. }
  278. if ($form -> exportValue('remember')) { //The user asked to remember login (it is implemented with cookies)
  279. $expire = time() + 30 * 86400; //1 month
  280. setcookie("cookie_login", $_SESSION['s_login'], $expire, false, false, false, true);
  281. setcookie("cookie_password", $_SESSION['s_password'], $expire, false, false, false, true);
  282. } else {
  283. setcookie("cookie_login", '', time() - 3600);
  284. setcookie("cookie_password", '', time() - 3600);
  285. }
  286. // Check if the mobile version of eFront is required - if so set a session variable accordingly
  287. //eF_setMobile();
  288. if ($GLOBALS['configuration']['force_change_password'] && !$user -> isLdapUser && $user -> user['need_pwd_change']) {
  289. eF_redirect("index.php?ctg=password_change");
  290. } else if ($GLOBALS['configuration']['show_license_note'] && $user -> user['viewed_license'] == 0) {
  291. eF_redirect("index.php?ctg=agreement");
  292. } elseif ($_SESSION['login_mode']) {
  293. eF_redirect("index.php?ctg=checkout&checkout=1");
  294. } else {
  295. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_VISITED, "users_LOGIN" => $user -> user['login'], "users_name" => $user -> user['name'], "users_surname" => $user -> user['surname']));
  296. loginRedirect($user -> user['user_type']);
  297. }
  298. exit;
  299. } catch (EfrontUserException $e) {
  300. if ($GLOBALS['configuration']['activate_ldap']) {
  301. if (!extension_loaded('ldap')) {
  302. $message = $e -> getMessage().'<br/>'._LDAPEXTENSIONNOTLOADED;
  303. $message_type = 'failure';
  304. } else {
  305. $result = eF_checkUserLdap($form -> exportValue('login'), $form -> exportValue('password'));
  306. if ($result) { //The user exists in the LDAP server
  307. $_SESSION['ldap_user_pwd'] = $form -> exportValue('password'); //Keep the password temporarily in the session, it will be used in the next step
  308. eF_redirect("index.php?ctg=signup&ldap=1&login=".$form -> exportValue('login'));
  309. } else {
  310. $message = _LOGINERRORPLEASEMAKESURECAPSLOCKISOFF;
  311. $message_type = 'failure';
  312. }
  313. }
  314. } elseif ($e -> getCode() == EfrontUserException :: USER_PENDING) {
  315. $message = $e -> getMessage();
  316. $message_type = 'failure';
  317. } elseif ($e -> getCode() == EfrontUserException :: USER_INACTIVE) {
  318. $message = $e -> getMessage();
  319. $message_type = 'failure';
  320. }
  321. else {
  322. if ($GLOBALS['configuration']['ban_failed_logins'] && $user -> user['login'] != '') {
  323. $fields_insert = array('users_LOGIN' => $user -> user['login'],
  324. 'timestamp' => time(),
  325. 'action' => 'failed_login',
  326. 'session_ip' => eF_encodeIP($_SERVER['REMOTE_ADDR']));
  327. eF_insertTableData("logs", $fields_insert);
  328. $res_ban = eF_getTableData("logs", "count(id) as ct", "users_LOGIN='".$user -> user['login']."' and action='failed_login'");
  329. if ($res_ban[0]['ct'] >= 5 && $user -> user['user_type'] != 'administrator') {
  330. $user -> deactivate();
  331. }
  332. }
  333. $message = _LOGINERRORPLEASEMAKESURECAPSLOCKISOFF;
  334. $message_type = 'failure';
  335. }
  336. $form -> setConstants(array("login" => $values['login'], "password" => ""));
  337. } catch (Exception $e) {
  338. $smarty -> assign("T_EXCEPTION_TRACE", $e -> getTraceAsString());
  339. $message = $e -> getMessage().' &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(\''._ERRORDETAILS.'\', 2, \'error_details\')">'._MOREINFO.'</a>';
  340. $message_type = failure;
  341. }
  342. }
  343. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
  344. $form -> setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
  345. $form -> setRequiredNote(_REQUIREDNOTE);
  346. $form -> accept($renderer);
  347. $smarty -> assign('T_LOGIN_FORM', $renderer -> toArray());
  348. /* -----------------End of Login part-----------------------------*/
  349. if (isset($_GET['ctg']) && $_GET['ctg'] == 'agreement' && $_SESSION['s_login']) { //Display license agreement
  350. try {
  351. $_SESSION['s_index_comply'] = 'agreement';
  352. $user = EfrontUserFactory :: factory($_SESSION['s_login']);
  353. $agreementForm = new HTML_QuickForm("agreement_form", "post", basename($_SERVER['PHP_SELF'])."?ctg=agreement", "", "class = 'indexForm'", true);
  354. $agreementForm -> addElement('submit', 'submit_decline', _NOTACCEPTANDEXIT, 'class = "flatButton"');
  355. $agreementForm -> addElement('submit', 'submit_accept', _ACCEPTANDCONTINUE, 'class = "flatButton"');
  356. if ($agreementForm -> isSubmitted() && $agreementForm -> validate()) {
  357. $values = $agreementForm -> exportValues();
  358. if ($values['submit_accept']) {
  359. $user -> user['viewed_license'] = 1;
  360. $user -> persist();
  361. unset($_SESSION['s_index_comply']);
  362. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_VISITED, "users_LOGIN" => $user -> user['login'], "users_name" => $user -> user['name'], "users_surname" => $user -> user['surname']));
  363. if ($_SESSION['login_mode']) {
  364. eF_redirect("index.php?ctg=checkout&checkout=1");
  365. }
  366. loginRedirect($user -> user['user_type']);
  367. } else {
  368. $user -> logout(session_id());
  369. eF_redirect("index.php");
  370. }
  371. }
  372. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
  373. $agreementForm -> accept($renderer);
  374. $smarty -> assign('T_AGREEMENT_FORM', $renderer -> toArray());
  375. } catch (Exception $e) {
  376. eF_redirect("index.php?message=".urlencode($e -> getMessage()." (".$e -> getCode().")")."&message_type=failure");
  377. }
  378. } else if (isset($_GET['ctg']) && $_GET['ctg'] == 'password_change' && $_SESSION['s_login']) {
  379. try {
  380. $_SESSION['s_index_comply'] = 'password_change';
  381. $user = EfrontUserFactory :: factory($_SESSION['s_login']);
  382. $changePasswordForm = new HTML_QuickForm("change_password_form", "post", basename($_SERVER['PHP_SELF'])."?ctg=password_change", "", "class = 'indexForm'", true);
  383. $changePasswordForm -> addElement('password', 'old_password', _OLDPASSWORD, 'class = "inputText"');
  384. $changePasswordForm -> addElement('password', 'password', _NEWPASSWORD, 'class = "inputText"');
  385. $changePasswordForm -> addElement('password', 'passrepeat', _REPEATPASSWORD, 'class = "inputText"');
  386. $changePasswordForm -> addRule('password', _THEFIELD.' '._PASSWORD.' '._ISMANDATORY, 'required', null, 'client');
  387. $changePasswordForm -> addRule('passrepeat', _THEFIELD.' '._REPEATPASSWORD.' '._ISMANDATORY, 'required', null, 'client');
  388. $changePasswordForm -> addRule(array('password', 'passrepeat'), _PASSWORDSDONOTMATCH, 'compare', null, 'client');
  389. $changePasswordForm -> addRule('passrepeat', str_replace("%x", $GLOBALS['configuration']['password_length'], _PASSWORDMUSTBE6CHARACTERS), 'minlength', $GLOBALS['configuration']['password_length'], 'client');
  390. $changePasswordForm -> addElement('submit', 'submit', _SUBMIT, 'class = "flatButton"');
  391. if ($changePasswordForm -> isSubmitted() && $changePasswordForm -> validate()) {
  392. $newPassword = $changePasswordForm -> exportValue('password');
  393. $newPassword = EfrontUser :: createPassword($newPassword);
  394. if ($user -> user['password'] != EfrontUser :: createPassword($changePasswordForm -> exportValue('old_password'))) {
  395. $message = _OLDPASSWORDWRONG;
  396. $message_type = 'failure';
  397. }else if ($user -> user['password'] == $newPassword) {
  398. $message = _PASSWORDISTHESAME;
  399. $message_type = 'failure';
  400. } else {
  401. $user -> user['password'] = $newPassword;
  402. $user -> user['need_pwd_change'] = 0;
  403. $user -> persist();
  404. unset($_SESSION['s_index_comply']);
  405. if ($GLOBALS['configuration']['show_license_note'] && $user -> user['viewed_license'] == 0) {
  406. eF_redirect("index.php?ctg=agreement");
  407. } else {
  408. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_VISITED, "users_LOGIN" => $user -> user['login'], "users_name" => $user -> user['name'], "users_surname" => $user -> user['surname']));
  409. loginRedirect($user -> user['user_type']);
  410. }
  411. }
  412. }
  413. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
  414. $changePasswordForm -> setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
  415. $changePasswordForm -> setRequiredNote(_REQUIREDNOTE);
  416. $changePasswordForm -> accept($renderer);
  417. $smarty -> assign('T_CHANGE_PASSWORD_FORM', $changePasswordForm -> toArray());
  418. } catch (Exception $e) {
  419. eF_redirect("index.php?message=".urlencode($e -> getMessage()." (".$e -> getCode().")")."&message_type=failure");
  420. }
  421. }
  422. /* ---------------------------------------------------------Activation by email part--------------------------------------------------------- */
  423. if (isset($_GET['account']) && isset($_GET['key']) && eF_checkParameter($_GET['account'], 'login') && eF_checkParameter($_GET['key'], 'timestamp')) {
  424. if (($configuration['activation'] == 0 && $configuration['mail_activation'] == 1) || $configuration['supervisor_mail_activation'] == 1) {
  425. $result = eF_getTableData("users", "timestamp, active", "login='".$_GET['account']."'");
  426. if ($result[0]['active'] == 0 && $result[0]['timestamp'] == $_GET['key']) {
  427. try {
  428. $user = EfrontUserFactory :: factory($_GET['account']);//new EfrontUser($_GET['login']);
  429. $user -> activate();
  430. if ($_GET['activatedBy']) {
  431. $message = _EMPLOYEEACCOUNTSUCCESSFULLYACTIVATED;
  432. } else {
  433. $message = _ACCOUNTSUCCESSFULLYACTIVATED;
  434. }
  435. $message_type = 'success';
  436. eF_redirect(''.basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type=success');
  437. } catch (EfrontException $e) {
  438. $message = _PROBLEMACTIVATINGACCOUNT.': '.$e -> getMessage().' ('.$e -> getCode().')';
  439. $message_type = 'failure';
  440. }
  441. }
  442. } else {
  443. $message = _YOUCANNOTACCESSTHISPAGE;
  444. eF_redirect(''.basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type=failure');
  445. }
  446. }
  447. /* ---------------------------------------------------------Reset Password part--------------------------------------------------------- */
  448. if (isset($_GET['ctg']) && $_GET['ctg'] == 'reset_pwd' && $GLOBALS['configuration']['password_reminder'] && !$GLOBALS['configuration']['only_ldap']) { //The user asked to display the contact form
  449. if (eF_checkSpam() == true) {
  450. $message = _SPAMDETECTION;
  451. $message_type = 'failure';
  452. eF_redirect(basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type='.$message_type);
  453. }
  454. $smarty -> assign('T_CTG', 'reset_pwd');
  455. $form = new HTML_QuickForm("reset_password_form", "post", basename($_SERVER['PHP_SELF'])."?ctg=reset_pwd", "", "class = 'indexForm'", true);
  456. $form -> removeAttribute('name');
  457. $form -> registerRule('checkParameter', 'callback', 'eF_checkParameter'); //Register this rule for checking user input with our function, eF_checkParameter
  458. $form -> addElement('text', 'login_or_pwd', _LOGINOREMAIL, 'class = "inputText"');
  459. $form -> addRule('login_or_pwd', _THEFIELD.' '._ISMANDATORY, 'required', null, 'client');
  460. $form -> addRule('login_or_pwd', _INVALIDFIELDDATA, 'checkParameter', 'text');
  461. $form -> addElement('submit', 'submit_reset_password', _SUBMIT, 'class="flatButton"');
  462. if ($form -> isSubmitted() && $form -> validate()) {
  463. $input = $form -> exportValue("login_or_pwd");
  464. $fields_insert = array('users_LOGIN' => 'visitor',
  465. 'timestamp' => time(),
  466. 'action' => 'forms',
  467. 'comments' => 'reset_password',
  468. 'session_ip' => eF_encodeIP($_SERVER['REMOTE_ADDR']));
  469. eF_insertTableData("logs", $fields_insert);
  470. try {
  471. if (eF_checkParameter($input, 'email')) { //The user entered an email address
  472. $result = eF_getTableData("users", "login", "email='".$input."'"); //Get the user stored login
  473. if (sizeof($result) > 1) {
  474. $message = _MORETHANONEUSERWITHSAMEMAILENTERLOGIN;
  475. $message_type = 'failure';
  476. eF_redirect(''.basename($_SERVER['PHP_SELF']).'?ctg=reset_pwd&message='.urlencode($message).'&message_type='.$message_type);
  477. exit;
  478. } else {
  479. $user = EfrontUserFactory :: factory($result[0]['login']);
  480. }
  481. } elseif (eF_checkParameter($input, 'login')) { //The user entered his login name
  482. $user = EfrontUserFactory :: factory($input);
  483. }
  484. if ($user -> isLdapUser) {
  485. eF_redirect(''.basename($_SERVER['PHP_SELF']).'?message='.urlencode(_LDAPUSERMUSTCONTACTADMIN.$GLOBALS['configuration']['system_email']).'&message_type=failure');
  486. } else {
  487. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_FORGOTTEN_PASSWORD, "users_LOGIN" => $user->user['login'], "users_name" => $user->user['name'], "users_surname" => $user->user['surname']));
  488. $message = _ANEMAILHASBEENSENT;
  489. $message_type = 'success';
  490. if ($_SESSION['login_mode'] != 1) {
  491. eF_redirect(''.basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type='.$message_type);
  492. }
  493. }
  494. } catch (Exception $e) {
  495. $message = _NONEXISTINGMAIL;
  496. $message_type = 'failure';
  497. eF_redirect(''.basename($_SERVER['PHP_SELF']).'?ctg=reset_pwd&message='.urlencode($message).'&message_type='.$message_type);
  498. }
  499. } elseif (isset($_GET['id']) && isset($_GET['login'])) { //Second stage, user received the email and clicked on the link
  500. $login = $_GET['login'];
  501. if (!eF_checkParameter($login, 'login')) { //Possible hacking attempt: malformed user
  502. $message = _INVALIDUSER;
  503. $message_type = 'failure';
  504. } else {
  505. $user = eF_getTableData("users", "email, name", "login='".$login."'");
  506. if (strcmp($_GET['id'], EfrontUser::createPassword($login)) == 0 && sizeof($user) > 0) {
  507. $password = implode("", array_map(create_function('$v', 'return chr($v);'), array_rand(array_flip(array_merge(range(48, 57), range(64, 90), range(97, 122))), 10)));
  508. $password_encrypted = EfrontUser::createPassword($password);
  509. eF_updateTableData("users", array('password' => $password_encrypted), "login='$login'");
  510. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_NEW_PASSWORD_REQUEST, "users_LOGIN" => $login, "entity_name" => $password));
  511. $message = _EMAILWITHPASSWORDSENT;
  512. eF_redirect(''.basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type=success');
  513. } else {
  514. $message = _INVALIDUSER;
  515. $message_type = 'failure';
  516. }
  517. }
  518. }
  519. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
  520. $renderer -> setRequiredTemplate(
  521. '{$html}{if $required}
  522. &nbsp;<span class = "formRequired">*</span>
  523. {/if}');
  524. $form -> setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
  525. $form -> setRequiredNote(_REQUIREDNOTE);
  526. $form -> accept($renderer);
  527. $smarty -> assign('T_RESET_PASSWORD_FORM', $renderer -> toArray());
  528. }
  529. /* -------------------------------------------------------End of Reset Password part--------------------------------------------------------- */
  530. /* -----------------------------------------------------Sign up part--------------------------------------------------------- */
  531. if (isset($_GET['ctg']) && ($_GET['ctg'] == "signup") && $configuration['signup']) {
  532. if (eF_checkSpam() == true) {
  533. $message = _SPAMDETECTION;
  534. $message_type = 'failure';
  535. eF_redirect(basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type='.$message_type);
  536. }
  537. $users = eF_countTableData("users", "login", "active=1 and archive=0");
  538. $smarty -> assign("T_CTG", "signup");
  539. $form = new HTML_QuickForm("signup_register_personal_form", "post", basename($_SERVER['PHP_SELF'])."?ctg=signup".(isset($_GET['ldap']) ? '&ldap=1' : ''), "", "class = 'indexForm'", true);
  540. $form -> removeAttribute('name');
  541. $form -> registerRule('checkParameter', 'callback', 'eF_checkParameter'); //Register this rule for checking user input with our function, eF_checkParameter
  542. $form -> registerRule('checkNotExist', 'callback', 'eF_checkNotExist'); //This rule is using our function, eF_checkNotExist, to ensure that no duplicate values are inserted in unique fields, such as login and email
  543. $form -> addElement('text', 'login', _LOGIN, (isset($_GET['ldap']) ? 'class = "inputText inactiveElement" readonly' : 'class = "inputText"'));
  544. $form -> addRule('login', _THEFIELD.' '._LOGIN.' '._ISMANDATORY, 'required', null, 'client');
  545. $form -> addRule('login', _THEFIELD.' "'._LOGIN.'" '._MUSTBESMALLERTHAN.' 50 '.mb_strtolower(_CHARACTERS), 'maxlength', 50, 'client');
  546. $form -> addRule('login', _THEFIELD.' '._LOGIN.' '._HASINVALIDCHARACTERS.'. '._ONLYALLOWEDCHARACTERSLOGIN, 'checkParameter', 'login');
  547. $form -> addRule('login', _THELOGIN.' &quot;'.($form -> exportValue('login')).'&quot; '._ALREADYEXISTS, 'checkNotExist', 'login');
  548. $form -> addElement(isset($_GET['ldap']) ? 'text' : 'password', 'password', _PASSWORD, 'class = "inputText"');
  549. $form -> addElement(isset($_GET['ldap']) ? 'text' : 'password', 'passrepeat', _REPEATPASSWORD, 'class = "inputText"');
  550. $form -> addRule('password', _THEFIELD.' '._PASSWORD.' '._ISMANDATORY, 'required', null, 'client');
  551. $form -> addRule('passrepeat', _THEFIELD.' '._REPEATPASSWORD.' '._ISMANDATORY, 'required', null, 'client');
  552. $form -> addRule(array('password', 'passrepeat'), _PASSWORDSDONOTMATCH, 'compare', null, 'client');
  553. if (!$_GET['ldap']) { //For LDAP registrations, this rule does not hold true
  554. $form -> addRule('passrepeat', str_replace("%x", $GLOBALS['configuration']['password_length'], _PASSWORDMUSTBE6CHARACTERS), 'minlength', $GLOBALS['configuration']['password_length'], 'client');
  555. }
  556. $form -> addElement('text', 'firstName', _FIRSTNAME, 'class = "inputText"');
  557. $form -> addRule('firstName', _THEFIELD.' '._FIRSTNAME.' '._ISMANDATORY, 'required', null, 'client');
  558. $form -> addRule('firstName', _THEFIELD.' "'._FIRSTNAME.'" '._MUSTBESMALLERTHAN.' 50 '.mb_strtolower(_CHARACTERS), 'maxlength', 50, 'client');
  559. $form -> addRule('firstName', _THEFIELD.' '._FIRSTNAME.' '._HASINVALIDCHARACTERS.'. '._ONLYALLOWEDCHARACTERSTEXT, 'checkParameter', 'text');
  560. $form -> addElement('text', 'lastName', _LASTNAME, 'class = "inputText"');
  561. $form -> addRule('lastName', _THEFIELD.' '._LASTNAME.' '._ISMANDATORY, 'required', null, 'client');
  562. $form -> addRule('lastName', _THEFIELD.' "'._LASTNAME.'" '._MUSTBESMALLERTHAN.' 50 '.mb_strtolower(_CHARACTERS), 'maxlength', 50, 'client');
  563. $form -> addRule('lastName', _THEFIELD.' '._LASTNAME.' '._HASINVALIDCHARACTERS.'. '._ONLYALLOWEDCHARACTERSTEXT, 'checkParameter', 'text');
  564. $form -> addElement('text', 'email', _EMAILADDRESS, 'class = "inputText "');
  565. $form -> addRule('email', _THEFIELD.' '._EMAILADDRESS.' '._ISMANDATORY, 'required', null, 'client');
  566. $form -> addRule('email', _THEFIELD.' '._EMAILADDRESS.' '._HASINVALIDCHARACTERS.'. '._ONLYALLOWEDCHARACTERSTEXT, 'email', null, 'client');
  567. //$form -> addRule('email', _THEEMAIL.' &quot;'.($form -> exportValue('email')).'&quot; '._ALREADYEXISTS, 'checkNotExist', 'email');
  568. $languages = array();
  569. foreach (EfrontSystem :: getLanguages() as $key => $value) {
  570. if ($value['active']) {
  571. $languages[$key] = $value['translation'];
  572. }
  573. }
  574. $form -> addElement('select', 'languages_NAME', _LANGUAGE, $languages, 'class = "inputSelect" onchange = "location = \'index.php?ctg=signup&bypass_language=\'+this.options[this.selectedIndex].value"'); //A select drop down for languages
  575. if ($_SESSION['s_language']) {
  576. $form -> setDefaults(array('languages_NAME' => $_SESSION['s_language'])); //The default language is also the selected one
  577. } else {
  578. $form -> setDefaults(array('languages_NAME' => $GLOBALS['configuration']['default_language'])); //The default language is also the selected one
  579. }
  580. if ($GLOBALS['configuration']['onelanguage']) {
  581. $form -> freeze(array('languages_NAME'));
  582. }
  583. $element = $form -> addElement('textarea', 'comments', _COMMENTS, 'class = "inputText" id = "comments"');
  584. $element -> setCols(40);
  585. $element -> setRows(2);
  586. $form -> addElement('submit', 'submit_register', _REGISTER, 'class = "flatButton"');
  587. if (isset($_GET['ldap'])) {
  588. $result = eF_getLdapValues($GLOBALS['configuration']['ldap_uid'].'='.$_GET['login'], array($GLOBALS['configuration']['ldap_preferredlanguage'],
  589. $GLOBALS['configuration']['ldap_mail'],
  590. $GLOBALS['configuration']['ldap_cn'],
  591. $GLOBALS['configuration']['ldap_uid']));
  592. $name_parts = explode(" ", $result[0]['cn'][0]);
  593. $first_name = array_shift($name_parts);
  594. sizeof($name_parts) == 0 ? $last_name = $first_name : $last_name = implode(" ", $name_parts);
  595. $form -> setDefaults(array("login" => $_GET['login'],
  596. "password" => _LDAPACCOUNTPASSWORD,
  597. "passrepeat" => _LDAPACCOUNTPASSWORD,
  598. "email" => $result[0]['mail'][0],
  599. "firstName" => $first_name,
  600. "lastName" => $last_name));
  601. //$form -> freeze(array('login', 'password', 'passrepeat'));
  602. $smarty -> assign("T_LDAP_USER", true);
  603. if (!$form -> isSubmitted()) {
  604. $message = _VERIFYFOLLOWINGINFOISCORRECT;
  605. $message_type = 'success';
  606. }
  607. } elseif ($configuration['only_ldap']) {
  608. $message = _ONLYLDAPREGISTRATIONPERMITTED;
  609. $message_type = 'failure';
  610. eF_redirect(basename($_SERVER['PHP_SELF'])."?message=".urlencode($message)."&message_type=$message_type");
  611. }
  612. if ($form -> isSubmitted()) {
  613. $fields_insert = array('users_LOGIN' => 'visitor',
  614. 'timestamp' => time(),
  615. 'action' => 'forms',
  616. 'comments' => 'signup',
  617. 'session_ip' => eF_encodeIP($_SERVER['REMOTE_ADDR']));
  618. eF_insertTableData("logs", $fields_insert);
  619. if ($form -> validate()) {
  620. try {
  621. if (isset($_SESSION['s_login'])) { //A logged-in user wants to signup: Log him out first
  622. $user = EfrontUserFactory :: factory($_SESSION['s_login']);
  623. $user -> logout(session_id());
  624. }
  625. $values = $form -> exportValues(); //Get the form values
  626. //Check the user_type. If it's an id, it means that it's not one of the basic user types; so derive the basic user type and populate the user_types_ID field
  627. $defaultUserType = $GLOBALS['configuration']['default_type'];
  628. if (is_numeric($defaultUserType)) {
  629. $result = eF_getTableData("user_types", "id, basic_user_type", "id=".$defaultUserType);
  630. if (sizeof($result) > 0) {
  631. $values['user_type'] = $result[0]['basic_user_type'];
  632. $values['user_types_ID'] = $result[0]['id'];
  633. } else {
  634. $values['user_type'] = 'student';
  635. }
  636. } else {
  637. $values['user_type'] = $defaultUserType;
  638. $values['user_types_ID'] = 0;
  639. }
  640. $user_data = array("login" => $values['login'],
  641. "password" => isset($_GET['ldap']) ? 'ldap' : $values['password'],
  642. "name" => $values['firstName'],
  643. "surname" => $values['lastName'],
  644. "email" => $values['email'],
  645. "comments" => $values['comments'],
  646. "pending" => ($configuration['activation']) ? 0 : 1,
  647. "active" => $configuration['activation'],
  648. "languages_NAME" => $values['languages_NAME'],
  649. "user_type" => $values['user_type'],
  650. "user_types_ID" => $values['user_types_ID']);
  651. foreach ($user_profile as $field) { //Get the custom fields values
  652. if ($field['type'] == 'date') {
  653. $user_data[$field['name']] = mktime($values[$field['name']]['H'], $values[$field['name']]['i'], $values[$field['name']]['s'], $values[$field['name']]['M'], $values[$field['name']]['d'], $values[$field['name']]['Y']);
  654. } else if ($field['type'] == 'branchinfo') {
  655. $self_registered_jobs[] = array("branch_ID" => $values[$field['name']. "_branches"], "job_description" => $_POST[$field['name']. "_jobs"], "supervisor" => $_POST[$field['name']. "_supervisors"], "mandatory" => $field['mandatory']);
  656. } else if ($field['type'] == 'groupinfo') {
  657. if ($values[$field['name']."_groups"]) {
  658. $groupToAdd = new EfrontGroup($values[$field['name']."_groups"]);
  659. }
  660. } else {
  661. $user_data[$field['name']] = $values[$field['name']];
  662. }
  663. }
  664. $newUser = EfrontUser :: createUser($user_data);
  665. $encrypted = true; //needed for autologin
  666. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_REGISTER, "users_LOGIN" => $user_data['login'], "users_name" => $user_data['name'], "users_surname" => $user_data['surname'], "entity_name" => $user_data['password']));
  667. // send not-visited notifications for the newly registered user
  668. //EfrontEvent::triggerEvent(array("type" => (-1) * EfrontEvent::SYSTEM_VISITED, "users_LOGIN" => $user_data['login'], "users_name" => $user_data['name'], "users_surname" => $user_data['surname']));
  669. //pr($self_registered_jobs);
  670. if ($configuration['activation'] == 0) {
  671. if ($configuration['mail_activation'] == 1){
  672. $tmp = eF_getTableData("users","timestamp, login, name,surname","login='".$user_data['login']."'");
  673. $timestamp = $tmp[0]["timestamp"];
  674. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_ON_EMAIL_ACTIVATION, "users_LOGIN" => $tmp[0]['login'], "users_name" => $tmp[0]['name'], "users_surname" => $tmp[0]['surname'], "timestamp" => $timestamp, "entity_name" => $timestamp));
  675. $message = _YOUWILLRECEIVEMAILFORACCOUNTACTIVATION;
  676. } else {
  677. $message = _ADMINISTRATORWILLACTIVATEYOURACCOUNT;
  678. }
  679. eF_redirect(basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type=success');
  680. exit;
  681. } else {
  682. $message = _SUCCESSREGISTER;
  683. $message_type = 'success';
  684. //Automatic registration trigers login as well, unless login_mode is enabled
  685. if ($_GET['ldap']) {
  686. $newUser -> login($_SESSION['ldap_user_pwd'], $encrypted);
  687. unset($_SESSION['ldap_user_pwd']);
  688. } else {
  689. $newUser -> login($newUser->user['password'], $encrypted);
  690. }
  691. if ($GLOBALS['configuration']['force_change_password'] && !$newUser -> isLdapUser && $newUser -> user['need_pwd_change']) {
  692. eF_redirect("index.php?ctg=password_change");
  693. } else if ($GLOBALS['configuration']['show_license_note'] && $newUser -> user['viewed_license'] == 0) {
  694. eF_redirect("index.php?ctg=agreement&message=".urlencode($message)."&message_type=".$message_type);
  695. } else if ($_SESSION['login_mode']) {
  696. eF_redirect("index.php?ctg=checkout&checkout=1&message=".urlencode($message)."&message_type=".$message_type);
  697. } else {
  698. EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_VISITED, "users_LOGIN" => $newUser -> user['login'], "users_name" => $newUser -> user['name'], "users_surname" => $newUser -> user['surname']));
  699. loginRedirect($newUser -> user['user_type'], urlencode($message), $message_type);
  700. }
  701. }
  702. } catch (Exception $e) {
  703. $smarty -> assign("T_EXCEPTION_TRACE", $e -> getTraceAsString());
  704. $message = $e -> getMessage().' &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(\''._ERRORDETAILS.'\', 2, \'error_details\')">'._MOREINFO.'</a>';
  705. $message_type = failure;
  706. }
  707. }
  708. }
  709. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
  710. $renderer -> setRequiredTemplate(
  711. '{$html}{if $required}
  712. &nbsp;<span class = "formRequired">*</span>
  713. {/if}'
  714. );
  715. $form -> setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
  716. $form -> setRequiredNote(_REQUIREDNOTE);
  717. $form -> accept($renderer);
  718. $smarty -> assign('T_PERSONAL_INFO_FORM', $renderer -> toArray());
  719. }
  720. /* --------------------------------------------------- End of Sign up part--------------------------------------------------- */
  721. /* -------------------------------------------------------Contact part--------------------------------------------------------- */
  722. if (isset($_GET['ctg']) && $_GET['ctg'] == 'contact') { //The user asked to display the contact form
  723. if (eF_checkSpam() == true) {
  724. $message = _SPAMDETECTION;
  725. $message_type = 'failure';
  726. eF_redirect(basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type='.$message_type);
  727. }
  728. $smarty -> assign('T_CTG', 'contact');
  729. $form = new HTML_QuickForm("contact_form", "post", basename($_SERVER['PHP_SELF'])."?ctg=contact", "", "class = 'indexForm'", true);
  730. $form -> registerRule('checkParameter', 'callback', 'eF_checkParameter'); //Register this rule for checking user input with our function, eF_checkParameter
  731. $form -> addElement('text', 'email', _YOUREMAIL, 'class = "inputText"');
  732. $form -> addRule('email', _THEFIELD.' "'._EMAIL.'" '._ISMANDATORY, 'required');
  733. $form -> addRule('email', _INVALIDFIELDDATA, 'checkParameter', 'email');
  734. $form -> addElement('text', 'message_subject', _MESSAGESUBJECT, 'class = "inputText"');
  735. //$form -> addRule('message_subject', _INVALIDFIELDDATA, 'checkParameter', 'text');
  736. $form -> addElement('textarea', 'message_body', _TEXT, 'class = "inputText" id = "contact"');
  737. $form -> addElement('submit', 'submit_contact', _SUBMIT, 'class = "flatButton"');
  738. if ($_GET['limit_reached']) {
  739. $form->setDefaults(array('message_subject' => _IWANTTOSIGNUPBUTMAXIMUMUSERSLIMITREACHED, 'message_body' => _IWANTTOSIGNUPBUTMAXIMUMUSERSLIMITREACHEDBODY));
  740. }
  741. if ($form -> isSubmitted()) {
  742. $fields_insert = array('users_LOGIN' => 'visitor',
  743. 'timestamp' => time(),
  744. 'action' => 'forms',
  745. 'comments' => 'contact',
  746. 'session_ip' => eF_encodeIP($_SERVER['REMOTE_ADDR']));
  747. eF_insertTableData("logs", $fields_insert);
  748. if ($form -> validate()) {
  749. $to = $form -> exportValue("email");
  750. $subject = $form -> exportValue("message_subject");
  751. $body = $form -> exportValue("message_body")."\r\n\r\n(".$subject." ["._FROM.": ".$to."])";
  752. if (eF_mail($to, $GLOBALS['configuration']['system_email'], $subject." ["._FROM.": ".$to."]", $body, false, true)) {
  753. $copied_body = _THANKYOUFORCONTACTINGUSBODY."<br/><hr/><br/>".$form -> exportValue("message_body");
  754. eF_mail($GLOBALS['configuration']['system_email'], $to, _THANKYOUFORCONTACTINGUS, $copied_body, false, false);
  755. $message = _SENDSUCCESS;
  756. $message_type = 'success';
  757. eF_redirect(basename($_SERVER['PHP_SELF']).'?message='.urlencode($message).'&message_type='.$message_type);
  758. } else {
  759. $message = _SENDFAILURE;
  760. $message_type = 'failure';
  761. }
  762. }
  763. }
  764. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
  765. $renderer -> setRequiredTemplate(
  766. '{$html}{if $required}
  767. &nbsp;<span class = "formRequired">*</span>
  768. {/if}');
  769. $form -> setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
  770. $form -> setRequiredNote(_REQUIREDNOTE);
  771. $form -> accept($renderer);
  772. $smarty -> assign('T_CONTACT_FORM', $renderer -> toArray());
  773. }
  774. /* -------------------------------------------------------End of Contact part--------------------------------------------------------- */
  775. /* -------------------------------------------------------Lesson information part--------------------------------------------------------- */
  776. if (isset($_GET['ctg']) && $_GET['ctg'] == 'lesson_info') { //The user asked to display information on a lesson
  777. //session_start(); //Isn't needed here if the head session_start() is in place
  778. if (!$smarty -> is_cached('index.tpl', $cacheId) || !$GLOBALS['configuration']['smarty_caching']) {
  779. include("directions_tree.php");
  780. try {
  781. if (isset($_GET['lessons_ID'])) {
  782. if (isset($lessons[$_GET['lessons_ID']]) && ($lessons[$_GET['lessons_ID']] instanceOf EfrontLesson)) {
  783. $smarty -> assign("T_HAS_LESSON", $lessons[$_GET['lessons_ID']] -> lesson['has_lesson']);
  784. }
  785. $lesson = new EfrontLesson($_GET['lessons_ID']);
  786. $lesson -> lesson['price_string'] = formatPrice($lesson -> lesson['price'], array($lesson -> options['recurring'], $lesson -> options['recurring_duration']), true);
  787. $lesson -> lesson['num_students'] = sizeof($lesson -> getStudentUsers());
  788. $lesson -> lesson['seats_remaining'] = $lesson -> lesson['max_users'] - $lesson -> lesson['num_students'];
  789. $lesson -> lesson['seats_remaining'] >= 0 OR $lesson -> lesson['seats_remaining'] = 0;
  790. $smarty -> assign("T_LESSON", $lesson);
  791. $lessonInformation = $lesson -> getInformation();
  792. $content = new EfrontContentTree($lesson);
  793. if (sizeof($content -> tree) > 0) {
  794. $smarty -> assign("T_CONTENT_TREE", $content -> toHTML(false, 'dhtml_content_tree', array('noclick' => 1)));
  795. }
  796. $lessonInfo = new LearningObjectInformation(unserialize($lesson -> lesson['info']));
  797. $smarty -> assign("T_LESSON_INFO", $lessonInfo);
  798. $additionalInfo = $lesson -> getInformation();
  799. $smarty -> assign("T_ADDITIONAL_LESSON_INFO", $additionalInfo);
  800. if ($lesson -> lesson['course_only']) {
  801. $smarty -> assign("T_LESSON_COURSES", $lesson -> getCourses());
  802. if (isset($_GET['from_course']) && $_GET['from_course']) {
  803. $course = new EfrontCourse($_GET['from_course']);
  804. $smarty -> assign ("T_COURSE", $course);
  805. $smarty -> assign("T_HAS_COURSE", in_array($course -> course['id'], array_keys($userCourses)));
  806. } elseif (isset($_GET['course']) && $_GET['course']) {
  807. $course = new EfrontCourse($_GET['course']);
  808. $smarty -> assign ("T_COURSE", $course);
  809. $smarty -> assign("T_HAS_COURSE", in_array($course -> course['id'], array_keys($userCourses)));
  810. }
  811. }
  812. } else if ($_GET['courses_ID']) {
  813. if (isset($courses[$_GET['courses_ID']]) && ($courses[$_GET['courses_ID']] instanceOf EfrontCourse)) {
  814. $smarty -> assign("T_HAS_COURSE", $courses[$_GET['courses_ID']] -> course['has_course']);
  815. }
  816. $course = new EfrontCourse($_GET['courses_ID']);
  817. $course -> course['num_students'] = sizeof($course -> getStudentUsers());
  818. $course -> course['seats_remaining'] = $course -> course['max_users'] - $course -> course['num_students'];
  819. $course -> course['seats_remaining'] >= 0 OR $course -> course['seats_remaining'] = 0;
  820. $smarty -> assign("T_COURSE", $course);
  821. if ((isset($_SESSION['s_type']) && $_SESSION['s_type'] == 'administrator') || in_array($_SESSION['s_login'], array_keys($course -> getUsers()))) {
  822. $smarty -> assign("T_HAS_COURSE", true);
  823. }
  824. $lessons = $course -> getCourseLessons();
  825. foreach ($lessons as $key => $lesson) {
  826. $content = new EfrontContentTree($lesson);
  827. if (sizeof($content -> tree) > 0) {
  828. $contentTree[$key] = $content -> toHTML(false, 'dhtml_content_tree_'.$lesson -> lesson['id'], array('noclick' => 1));
  829. }
  830. $lessonInfo[$key] = new LearningObjectInformation(unserialize($lesson -> lesson['info']));
  831. $additionalInfo[$key] = $lesson -> getInformation();
  832. }
  833. $smarty -> assign("T_ADDITIONAL_LESSON_INFO", $additionalInfo);
  834. $smarty -> assign("T_COURSE_LESSON_INFO", $lessonInfo);
  835. $smarty -> assign("T_CONTENT_TREE", $contentTree);
  836. $smarty -> assign("T_LANGUAGES", EfrontSystem :: getLanguages(true));
  837. $smarty -> assign("T_COURSE_LESSONS", $lessons);
  838. $constraints = array('archive' => false, 'active' => true, 'sort' => 'name', 'condition' => 'show_catalog=1');
  839. if ($course -> course['instance_source']) {
  840. $parentCourse = new EfrontCourse($course -> course['instance_source']);
  841. $instances = $parentCourse -> getInstances($constraints);
  842. $instances[$parentCourse -> course['id']] = $parentCourse;
  843. } else {
  844. $instances = $course -> getI

Large files files are truncated, but you can click here to view the full file