template.lib.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class Template
  5. *
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. * @todo better organization of the class, methods and variables
  8. *
  9. */
  10. class Template
  11. {
  12. /**
  13. * The Template folder name see main/template
  14. * @var string
  15. */
  16. public $templateFolder = 'default';
  17. /**
  18. * The theme that will be used: chamilo, public_admin, chamilo_red, etc
  19. * This variable is set from the database
  20. * @var string
  21. */
  22. public $theme = '';
  23. /**
  24. * @var string
  25. */
  26. public $preview_theme = '';
  27. public $title = null;
  28. public $show_header;
  29. public $show_footer;
  30. public $help;
  31. public $menu_navigation = array(); //Used in the userportal.lib.php function: return_navigation_course_links()
  32. public $show_learnpath = false; // This is a learnpath section or not?
  33. public $plugin = null;
  34. public $course_id = null;
  35. public $user_is_logged_in = false;
  36. public $twig = null;
  37. /* Loads chamilo plugins */
  38. public $load_plugins = false;
  39. public $params = array();
  40. public $force_plugin_load = false;
  41. /**
  42. * @param string $title
  43. * @param bool $show_header
  44. * @param bool $show_footer
  45. * @param bool $show_learnpath
  46. * @param bool $hide_global_chat
  47. * @param bool $load_plugins
  48. * @param bool $sendHeaders send http headers or not
  49. */
  50. public function __construct(
  51. $title = '',
  52. $show_header = true,
  53. $show_footer = true,
  54. $show_learnpath = false,
  55. $hide_global_chat = false,
  56. $load_plugins = true,
  57. $sendHeaders = true
  58. ) {
  59. // Page title
  60. $this->title = $title;
  61. $this->show_learnpath = $show_learnpath;
  62. $this->hide_global_chat = $hide_global_chat;
  63. $this->load_plugins = $load_plugins;
  64. $template_paths = array(
  65. api_get_path(SYS_CODE_PATH).'template/overrides', // user defined templates
  66. api_get_path(SYS_CODE_PATH).'template', //template folder
  67. api_get_path(SYS_PLUGIN_PATH) // plugin folder
  68. );
  69. $cache_folder = api_get_path(SYS_ARCHIVE_PATH).'twig';
  70. if (!is_dir($cache_folder)) {
  71. mkdir($cache_folder, api_get_permissions_for_new_directories());
  72. }
  73. $loader = new Twig_Loader_Filesystem($template_paths);
  74. //Setting Twig options depending on the server see http://twig.sensiolabs.org/doc/api.html#environment-options
  75. if (api_get_setting('server_type') == 'test') {
  76. $options = array(
  77. //'cache' => api_get_path(SYS_ARCHIVE_PATH), //path to the cache folder
  78. 'autoescape' => false,
  79. 'debug' => true,
  80. 'auto_reload' => true,
  81. 'optimizations' => 0,
  82. // turn on optimizations with -1
  83. 'strict_variables' => false,
  84. //If set to false, Twig will silently ignore invalid variables
  85. );
  86. } else {
  87. $options = array(
  88. 'cache' => $cache_folder,
  89. //path to the cache folder
  90. 'autoescape' => false,
  91. 'debug' => false,
  92. 'auto_reload' => false,
  93. 'optimizations' => -1,
  94. // turn on optimizations with -1
  95. 'strict_variables' => false
  96. //If set to false, Twig will silently ignore invalid variables
  97. );
  98. }
  99. $this->twig = new Twig_Environment($loader, $options);
  100. $this->twig->addFilter('get_plugin_lang', new Twig_Filter_Function('get_plugin_lang'));
  101. $this->twig->addFilter('get_lang', new Twig_Filter_Function('get_lang'));
  102. $this->twig->addFilter('get_path', new Twig_Filter_Function('api_get_path'));
  103. $this->twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting'));
  104. $this->twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
  105. $this->twig->addFilter('return_logo', new Twig_Filter_Function('return_logo'));
  106. $this->twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
  107. $this->twig->addFilter('display_page_header', new Twig_Filter_Function('Display::page_header_and_translate'));
  108. $this->twig->addFilter(
  109. 'display_page_subheader',
  110. new Twig_Filter_Function('Display::page_subheader_and_translate')
  111. );
  112. $this->twig->addFilter('icon', new Twig_Filter_Function('Template::get_icon_path'));
  113. $this->twig->addFilter('img', new Twig_Filter_Function('Template::get_image'));
  114. $this->twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
  115. $this->twig->addFilter('api_get_local_time', new Twig_Filter_Function('api_get_local_time'));
  116. /*
  117. $lexer = new Twig_Lexer($this->twig, array(
  118. //'tag_comment' => array('{*', '*}'),
  119. //'tag_comment' => array('{#', '#}'),
  120. //'tag_block' => array('{', '}'),
  121. //'tag_variable' => array('{$', '}'),
  122. ));
  123. $this->twig->setLexer($lexer); */
  124. //Setting system variables
  125. $this->set_system_parameters();
  126. //Setting user variables
  127. $this->set_user_parameters();
  128. //Setting course variables
  129. $this->set_course_parameters();
  130. //Setting administrator variables
  131. $this->setAdministratorParams();
  132. //header and footer are showed by default
  133. $this->set_footer($show_footer);
  134. $this->set_header($show_header);
  135. $this->set_header_parameters($sendHeaders);
  136. $this->set_footer_parameters();
  137. $defaultStyle = api_get_configuration_value('default_template');
  138. if (!empty($defaultStyle)) {
  139. $this->templateFolder = $defaultStyle;
  140. }
  141. $this->assign('template', $this->templateFolder);
  142. $this->assign('locale', api_get_language_isocode());
  143. $this->assign('css_styles', $this->theme);
  144. $this->assign('login_class', null);
  145. $this->setLoginForm();
  146. // Chamilo plugins
  147. if ($this->show_header) {
  148. if ($this->load_plugins) {
  149. $this->plugin = new AppPlugin();
  150. //1. Showing installed plugins in regions
  151. $plugin_regions = $this->plugin->get_plugin_regions();
  152. foreach ($plugin_regions as $region) {
  153. $this->set_plugin_region($region);
  154. }
  155. //2. Loading the course plugin info
  156. global $course_plugin;
  157. if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
  158. //Load plugin get_langs
  159. $this->plugin->load_plugin_lang_variables($course_plugin);
  160. }
  161. }
  162. }
  163. }
  164. /**
  165. * @param string $image
  166. * @param int $size
  167. *
  168. * @return string
  169. */
  170. public static function get_icon_path($image, $size = ICON_SIZE_SMALL)
  171. {
  172. return Display::return_icon($image, '', array(), $size, false, true);
  173. }
  174. /**
  175. * @param string $image
  176. * @param int $size
  177. * @param string $name
  178. * @return string
  179. */
  180. public static function get_image($image, $size = ICON_SIZE_SMALL, $name)
  181. {
  182. return Display::return_icon($image, $name, array(), $size);
  183. }
  184. /**
  185. * @param string $timestamp
  186. * @param string $format
  187. *
  188. * @return string
  189. */
  190. public static function format_date($timestamp, $format = null)
  191. {
  192. return api_format_date($timestamp, $format);
  193. }
  194. /**
  195. * Return the item's url key:
  196. *
  197. * c_id=xx&id=xx
  198. *
  199. * @param object $item
  200. * @return string
  201. */
  202. public static function key($item)
  203. {
  204. $id = isset($item->id) ? $item->id : null;
  205. $c_id = isset($item->c_id) ? $item->c_id : null;
  206. $result = '';
  207. if ($c_id) {
  208. $result = "c_id=$c_id";
  209. }
  210. if ($id) {
  211. if ($result) {
  212. $result .= "&amp;id=$id";
  213. } else {
  214. $result .= "&amp;id=$id";
  215. }
  216. }
  217. return $result;
  218. }
  219. /**
  220. * @param string $helpInput
  221. */
  222. public function setHelp($helpInput = null)
  223. {
  224. if (!empty($helpInput)) {
  225. $help = $helpInput;
  226. } else {
  227. $help = $this->help;
  228. }
  229. $content = '';
  230. if (api_get_setting('enable_help_link') == 'true') {
  231. if (!empty($help)) {
  232. $help = Security::remove_XSS($help);
  233. $content = '<li class="help">';
  234. $content .= Display::url(
  235. Display::return_icon('help.large.png', get_lang('Help')),
  236. api_get_path(WEB_CODE_PATH) . 'help/help.php?open=' . $help,
  237. [
  238. 'class' => 'ajax',
  239. 'data-title' => get_lang('Help')
  240. ]
  241. );
  242. $content .= '</li>';
  243. }
  244. }
  245. $this->assign('help_content', $content);
  246. }
  247. /**
  248. * Use template system to parse the actions menu
  249. * @todo finish it!
  250. **/
  251. public function set_actions($actions)
  252. {
  253. $action_string = '';
  254. if (!empty($actions)) {
  255. foreach ($actions as $action) {
  256. $action_string .= $action;
  257. }
  258. }
  259. $this->assign('actions', $actions);
  260. }
  261. /**
  262. * Shortcut to display a 1 col layout (index.php)
  263. * */
  264. public function display_one_col_template()
  265. {
  266. $tpl = $this->get_template('layout/layout_1_col.tpl');
  267. $this->display($tpl);
  268. }
  269. /**
  270. * Shortcut to display a 2 col layout (userportal.php)
  271. **/
  272. public function display_two_col_template()
  273. {
  274. $tpl = $this->get_template('layout/layout_2_col.tpl');
  275. $this->display($tpl);
  276. }
  277. /**
  278. * Displays an empty template
  279. */
  280. public function display_blank_template()
  281. {
  282. $tpl = $this->get_template('layout/blank.tpl');
  283. $this->display($tpl);
  284. }
  285. /**
  286. * Displays an empty template
  287. */
  288. public function display_no_layout_template()
  289. {
  290. $tpl = $this->get_template('layout/no_layout.tpl');
  291. $this->display($tpl);
  292. }
  293. /**
  294. * Sets the footer visibility
  295. * @param bool true if we show the footer
  296. */
  297. public function set_footer($status)
  298. {
  299. $this->show_footer = $status;
  300. $this->assign('show_footer', $status);
  301. }
  302. /**
  303. * return true if toolbar has to be displayed for user
  304. * @return bool
  305. */
  306. public static function isToolBarDisplayedForUser()
  307. {
  308. //Toolbar
  309. $show_admin_toolbar = api_get_setting('show_admin_toolbar');
  310. $show_toolbar = false;
  311. switch ($show_admin_toolbar) {
  312. case 'do_not_show':
  313. break;
  314. case 'show_to_admin':
  315. if (api_is_platform_admin()) {
  316. $show_toolbar = true;
  317. }
  318. break;
  319. case 'show_to_admin_and_teachers':
  320. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  321. $show_toolbar = true;
  322. }
  323. break;
  324. case 'show_to_all':
  325. $show_toolbar = true;
  326. break;
  327. }
  328. return $show_toolbar;
  329. }
  330. /**
  331. * Sets the header visibility
  332. * @param bool true if we show the header
  333. */
  334. public function set_header($status)
  335. {
  336. $this->show_header = $status;
  337. $this->assign('show_header', $status);
  338. $show_toolbar = 0;
  339. if (self::isToolBarDisplayedForUser()) {
  340. $show_toolbar = 1;
  341. }
  342. $this->assign('show_toolbar', $show_toolbar);
  343. //Only if course is available
  344. $show_course_shortcut = null;
  345. $show_course_navigation_menu = null;
  346. if (!empty($this->course_id) && $this->user_is_logged_in) {
  347. if (api_get_setting('show_toolshortcuts') != 'false') {
  348. //Course toolbar
  349. $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
  350. }
  351. if (api_get_setting('show_navigation_menu') != 'false') {
  352. //Course toolbar
  353. $show_course_navigation_menu = CourseHome::show_navigation_menu();
  354. }
  355. }
  356. $this->assign('show_course_shortcut', $show_course_shortcut);
  357. $this->assign('show_course_navigation_menu', $show_course_navigation_menu);
  358. }
  359. /**
  360. * @param string $name
  361. *
  362. * @return string
  363. */
  364. public function get_template($name)
  365. {
  366. return $this->templateFolder.'/'.$name;
  367. }
  368. /**
  369. * Set course parameters
  370. */
  371. private function set_course_parameters()
  372. {
  373. //Setting course id
  374. $course = api_get_course_info();
  375. if (empty($course)) {
  376. $this->assign('course_is_set', false);
  377. return;
  378. }
  379. $this->assign('course_is_set', true);
  380. $this->course_id = $course['id'];
  381. $_c = array(
  382. 'id' => $course['id'],
  383. 'code' => $course['code'],
  384. 'title' => $course['name'],
  385. 'visibility' => $course['visibility'],
  386. 'language' => $course['language'],
  387. 'directory' => $course['directory'],
  388. 'session_id' => api_get_session_id(),
  389. 'user_is_teacher' => api_is_course_admin(),
  390. 'student_view' => (!empty($_GET['isStudentView']) && $_GET['isStudentView'] == 'true'),
  391. );
  392. $this->assign('course_code', $course['code']);
  393. $this->assign('_c', $_c);
  394. }
  395. /**
  396. * Set user parameters
  397. */
  398. private function set_user_parameters()
  399. {
  400. $user_info = array();
  401. $user_info['logged'] = 0;
  402. $this->user_is_logged_in = false;
  403. if (api_user_is_login()) {
  404. $user_info = api_get_user_info(api_get_user_id(), true);
  405. $user_info['logged'] = 1;
  406. $user_info['is_admin'] = 0;
  407. if (api_is_platform_admin()) {
  408. $user_info['is_admin'] = 1;
  409. }
  410. $user_info['messages_count'] = MessageManager::get_new_messages();
  411. $this->user_is_logged_in = true;
  412. }
  413. // Setting the $_u array that could be use in any template
  414. $this->assign('_u', $user_info);
  415. }
  416. /**
  417. * Set system parameters
  418. */
  419. private function set_system_parameters()
  420. {
  421. global $_configuration;
  422. $this->theme = api_get_visual_theme();
  423. //Setting app paths/URLs
  424. $_p = array(
  425. 'web' => api_get_path(WEB_PATH),
  426. 'web_relative' => api_get_path(REL_PATH),
  427. 'web_course' => api_get_path(WEB_COURSE_PATH),
  428. 'web_main' => api_get_path(WEB_CODE_PATH),
  429. 'web_css' => api_get_path(WEB_CSS_PATH),
  430. 'web_css_theme' => api_get_path(WEB_CSS_PATH) . 'themes/' . $this->theme . '/',
  431. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  432. 'web_img' => api_get_path(WEB_IMG_PATH),
  433. 'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
  434. 'web_lib' => api_get_path(WEB_LIBRARY_PATH),
  435. 'web_upload' => api_get_path(WEB_UPLOAD_PATH),
  436. 'web_self' => api_get_self(),
  437. 'web_query_vars' => api_htmlentities($_SERVER['QUERY_STRING']),
  438. 'web_self_query_vars' => api_htmlentities($_SERVER['REQUEST_URI']),
  439. 'web_cid_query' => api_get_cidreq(),
  440. );
  441. $this->assign('_p', $_p);
  442. //Here we can add system parameters that can be use in any template
  443. $_s = array(
  444. 'software_name' => $_configuration['software_name'],
  445. 'system_version' => $_configuration['system_version'],
  446. 'site_name' => api_get_setting('siteName'),
  447. 'institution' => api_get_setting('Institution'),
  448. 'date' => api_format_date('now', DATE_FORMAT_LONG),
  449. 'timezone' => _api_get_timezone(),
  450. 'gamification_mode' => api_get_setting('gamification_mode')
  451. );
  452. $this->assign('_s', $_s);
  453. }
  454. /**
  455. * Set theme, include mainstream CSS files
  456. * @return void
  457. * @see setCssCustomFiles() for additional CSS sheets
  458. */
  459. public function setCssFiles()
  460. {
  461. global $disable_js_and_css_files;
  462. $css = array();
  463. $this->theme = api_get_visual_theme();
  464. if (!empty($this->preview_theme)) {
  465. $this->theme = $this->preview_theme;
  466. }
  467. // Default CSS Bootstrap
  468. $bowerCSSFiles = [
  469. 'bootstrap-daterangepicker/daterangepicker-bs3.css',
  470. 'fontawesome/css/font-awesome.min.css',
  471. 'jquery-ui/themes/smoothness/theme.css',
  472. 'jquery-ui/themes/smoothness/jquery-ui.min.css',
  473. 'mediaelement/build/mediaelementplayer.min.css',
  474. 'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.css',
  475. 'bootstrap/dist/css/bootstrap.min.css',
  476. 'jquery.scrollbar/jquery.scrollbar.css',
  477. ];
  478. foreach ($bowerCSSFiles as $file) {
  479. $css[] = api_get_path(WEB_PATH).'web/assets/'.$file;
  480. }
  481. $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/bootstrap-select/css/bootstrap-select.min.css';
  482. $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css';
  483. $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/style.css';
  484. if (api_is_global_chat_enabled()) {
  485. $css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css';
  486. }
  487. //THEME CSS STYLE
  488. // $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'responsive.css');
  489. $css_file_to_string = null;
  490. foreach ($css as $file) {
  491. $css_file_to_string .= api_get_css($file);
  492. }
  493. if (!$disable_js_and_css_files) {
  494. $this->assign('css_static_file_to_string', $css_file_to_string);
  495. }
  496. }
  497. /**
  498. * Prepare custom CSS to be added at the very end of the <head> section
  499. * @return void
  500. * @see setCssFiles() for the mainstream CSS files
  501. */
  502. public function setCssCustomFiles()
  503. {
  504. global $disable_js_and_css_files;
  505. // Base CSS
  506. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css');
  507. if ($this->show_learnpath) {
  508. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'scorm.css');
  509. if (is_file(api_get_path(SYS_CSS_PATH).'themes/'.$this->theme.'/learnpath.css')) {
  510. $css[] = api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/learnpath.css';
  511. }
  512. }
  513. $css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'themes/'.$this->theme.'/default.css');
  514. $css_file_to_string = null;
  515. foreach ($css as $file) {
  516. $css_file_to_string .= api_get_css($file);
  517. }
  518. // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
  519. if (SHOW_TEXT_NEAR_ICONS == true) {
  520. //hack in order to fix the actions buttons
  521. $css_file_to_string .= '<style>
  522. .td_actions a {
  523. float:left;
  524. width:100%;
  525. }
  526. .forum_message_left a {
  527. float:left;
  528. width:100%;
  529. }
  530. </style>';
  531. }
  532. $navigator_info = api_get_navigator();
  533. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  534. $css_file_to_string .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n";
  535. }
  536. if (!$disable_js_and_css_files) {
  537. $this->assign('css_custom_file_to_string', $css_file_to_string);
  538. $style_print = '';
  539. if (is_readable(api_get_path(SYS_CSS_PATH).$this->theme.'/print.css')) {
  540. $style_print = api_get_css(api_get_cdn_path(api_get_path(WEB_CSS_PATH) . $this->theme . '/print.css'),
  541. 'print');
  542. }
  543. $this->assign('css_style_print', $style_print);
  544. }
  545. // Logo
  546. $logo = return_logo($this->theme);
  547. $this->assign('logo', $logo);
  548. $this->assign('show_media_element', 1);
  549. }
  550. /**
  551. * Declare and define the template variable that will be used to load
  552. * javascript libraries in the header.
  553. */
  554. public function set_js_files()
  555. {
  556. global $disable_js_and_css_files, $htmlHeadXtra;
  557. $isoCode = api_get_language_isocode();
  558. $selectLink = 'bootstrap-select/js/i18n/defaults-' . $isoCode . '_' . strtoupper($isoCode) . '.min.js';
  559. if ($isoCode == 'en') {
  560. $selectLink = 'bootstrap-select/js/i18n/defaults-' . $isoCode . '_US.min.js';
  561. }
  562. // JS files
  563. $js_files = array(
  564. 'chosen/chosen.jquery.min.js',
  565. 'bootstrap-select/js/bootstrap-select.min.js',
  566. $selectLink
  567. );
  568. $viewBySession = api_get_setting('my_courses_view_by_session') === 'true';
  569. if (api_is_global_chat_enabled() || $viewBySession) {
  570. // Do not include the global chat in LP
  571. if ($this->show_learnpath == false &&
  572. $this->show_footer == true &&
  573. $this->hide_global_chat == false
  574. ) {
  575. $js_files[] = 'chat/js/chat.js';
  576. }
  577. }
  578. if (api_get_setting('accessibility_font_resize') == 'true') {
  579. $js_files[] = 'fontresize.js';
  580. }
  581. // Do not use minified version - generates errors (at least in the skills wheel)
  582. $js_files[] = 'tag/jquery.fcbkcomplete.js';
  583. $js_file_to_string = null;
  584. $bowerJsFiles = [
  585. 'modernizr/modernizr.js',
  586. 'jquery/dist/jquery.min.js',
  587. 'bootstrap/dist/js/bootstrap.min.js',
  588. 'jquery-ui/jquery-ui.min.js',
  589. 'moment/min/moment-with-locales.min.js',
  590. 'bootstrap-daterangepicker/daterangepicker.js',
  591. 'jquery-timeago/jquery.timeago.js',
  592. 'mediaelement/build/mediaelement-and-player.min.js',
  593. 'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js',
  594. 'image-map-resizer/js/imageMapResizer.min.js',
  595. 'jquery.scrollbar/jquery.scrollbar.min.js'
  596. ];
  597. if (CHAMILO_LOAD_WYSIWYG == true) {
  598. $bowerJsFiles[] = 'ckeditor/ckeditor.js';
  599. }
  600. if (api_get_setting('include_asciimathml_script') == 'true') {
  601. $bowerJsFiles[] = 'MathJax/MathJax.js?config=AM_HTMLorMML';
  602. }
  603. if ($isoCode != 'en') {
  604. $bowerJsFiles[] = 'jqueryui-timepicker-addon/dist/i18n/jquery-ui-timepicker-' . $isoCode . '.js';
  605. $bowerJsFiles[] = 'jquery-ui/ui/minified/i18n/datepicker-' . $isoCode . '.min.js';
  606. }
  607. foreach ($bowerJsFiles as $file) {
  608. $js_file_to_string .= '<script type="text/javascript" src="'.api_get_path(WEB_PATH).'web/assets/'.$file.'"></script>'."\n";
  609. }
  610. foreach ($js_files as $file) {
  611. $js_file_to_string .= api_get_js($file);
  612. }
  613. // Loading email_editor js
  614. if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
  615. $js_file_to_string .= $this->fetch('default/mail_editor/email_link.js.tpl');
  616. }
  617. if (!$disable_js_and_css_files) {
  618. $this->assign('js_file_to_string', $js_file_to_string);
  619. //Adding jquery ui by default
  620. $extra_headers = api_get_jquery_ui_js();
  621. //$extra_headers = '';
  622. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  623. foreach ($htmlHeadXtra as & $this_html_head) {
  624. $extra_headers .= $this_html_head."\n";
  625. }
  626. }
  627. $this->assign('extra_headers', $extra_headers);
  628. }
  629. }
  630. /**
  631. * Special function to declare last-minute JS libraries which depend on
  632. * other things to be declared first. In particular, it might be useful
  633. * under IE9 with compatibility mode, which for some reason is getting
  634. * upset when a variable is used in a function (even if not used yet)
  635. * when this variable hasn't been defined yet.
  636. */
  637. public function set_js_files_post()
  638. {
  639. global $disable_js_and_css_files, $htmlHeadXtra;
  640. $js_files = array();
  641. if (api_is_global_chat_enabled()) {
  642. //Do not include the global chat in LP
  643. if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) {
  644. $js_files[] = 'chat/js/chat.js';
  645. }
  646. }
  647. $js_file_to_string = null;
  648. foreach ($js_files as $js_file) {
  649. $js_file_to_string .= api_get_js($js_file);
  650. }
  651. if (!$disable_js_and_css_files) {
  652. $this->assign('js_file_to_string_post', $js_file_to_string);
  653. }
  654. }
  655. /**
  656. * Set header parameters
  657. * @param bool $sendHeaders send headers
  658. */
  659. private function set_header_parameters($sendHeaders)
  660. {
  661. global $httpHeadXtra, $interbreadcrumb, $language_file, $_configuration, $this_section;
  662. $_course = api_get_course_info();
  663. $help = $this->help;
  664. $nameTools = $this->title;
  665. $navigation = return_navigation_array();
  666. $this->menu_navigation = $navigation['menu_navigation'];
  667. $this->assign('system_charset', api_get_system_encoding());
  668. if (isset($httpHeadXtra) && $httpHeadXtra) {
  669. foreach ($httpHeadXtra as & $thisHttpHead) {
  670. header($thisHttpHead);
  671. }
  672. }
  673. $this->assign('online_button', Display::return_icon('statusonline.png', null, null, ICON_SIZE_ATOM));
  674. $this->assign('offline_button',Display::return_icon('statusoffline.png', null, null, ICON_SIZE_ATOM));
  675. // Get language iso-code for this page - ignore errors
  676. $this->assign('document_language', api_get_language_isocode());
  677. $course_title = isset($_course['name']) ? $_course['name'] : null;
  678. $title_list = array();
  679. $title_list[] = api_get_setting('Institution');
  680. $title_list[] = api_get_setting('siteName');
  681. if (!empty($course_title)) {
  682. $title_list[] = $course_title;
  683. }
  684. if ($nameTools != '') {
  685. $title_list[] = $nameTools;
  686. }
  687. $title_string = '';
  688. for ($i = 0; $i < count($title_list); $i++) {
  689. $title_string .= $title_list[$i];
  690. if (isset($title_list[$i + 1])) {
  691. $item = trim($title_list[$i + 1]);
  692. if (!empty($item)) {
  693. $title_string .= ' - ';
  694. }
  695. }
  696. }
  697. $this->assign('title_string', $title_string);
  698. //Setting the theme and CSS files
  699. $css = $this->setCssFiles();
  700. $this->set_js_files();
  701. $this->setCssCustomFiles($css);
  702. //$this->set_js_files_post();
  703. $browser = api_browser_support('check_browser');
  704. if ($browser[0] == 'Internet Explorer' && $browser[1] >= '11') {
  705. $browser_head = '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />';
  706. $this->assign('browser_specific_head', $browser_head);
  707. }
  708. // Implementation of prefetch.
  709. // See http://cdn.chamilo.org/main/img/online.png for details
  710. $prefetch = '';
  711. if (!empty($_configuration['cdn_enable'])) {
  712. $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
  713. foreach ($_configuration['cdn'] as $host => $exts) {
  714. $prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
  715. }
  716. }
  717. $this->assign('prefetch', $prefetch);
  718. $this->assign('text_direction', api_get_text_direction());
  719. $this->assign('section_name', 'section-'.$this_section);
  720. //Defaul root chamilo favicon
  721. $favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_PATH) . 'favicon.ico" type="image/x-icon" />';
  722. //Added to verify if in the current Chamilo Theme exist a favicon
  723. $favicoThemeUrl = api_get_path(SYS_CSS_PATH) . 'themes/' . $this->theme . '/images/';
  724. //If exist pick the current chamilo theme favicon
  725. if (is_file($favicoThemeUrl . 'favicon.ico')) {
  726. $favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_CSS_PATH)
  727. . 'themes/' . $this->theme . '/images/favicon.ico" type="image/x-icon" />';
  728. }
  729. if (api_is_multiple_url_enabled()) {
  730. $access_url_id = api_get_current_access_url_id();
  731. if ($access_url_id != -1) {
  732. $url_info = api_get_access_url($access_url_id);
  733. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  734. $clean_url = api_replace_dangerous_char($url);
  735. $clean_url = str_replace('/', '-', $clean_url);
  736. $clean_url .= '/';
  737. $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
  738. $icon_real_homep = api_get_path(SYS_APP_PATH).'home/'.$clean_url;
  739. //we create the new dir for the new sites
  740. if (is_file($icon_real_homep.'favicon.ico')) {
  741. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  742. }
  743. }
  744. }
  745. $this->assign('favico', $favico);
  746. $this->setHelp();
  747. //@todo move this in the template
  748. $bug_notification_link = '';
  749. $iconBug = Display::return_icon('bug.png', get_lang('ReportABug'), null, ICON_SIZE_LARGE);
  750. if (api_get_setting('show_link_bug_notification') == 'true' && $this->user_is_logged_in) {
  751. $bug_notification_link = '<li class="report">
  752. <a href="http://support.chamilo.org/projects/chamilo-18/wiki/How_to_report_bugs" target="_blank">
  753. '. $iconBug . '
  754. </a>
  755. </li>';
  756. }
  757. $this->assign('bug_notification_link', $bug_notification_link);
  758. $notification = return_notification_menu();
  759. $this->assign('notification_menu', $notification);
  760. $resize = '';
  761. if (api_get_setting('accessibility_font_resize') == 'true') {
  762. $resize .= '<div class="resize_font">';
  763. $resize .= '<div class="btn-group">';
  764. $resize .= '<a title="'.get_lang('DecreaseFontSize').'" href="#" class="decrease_font btn btn-default"><em class="fa fa-font"></em></a>';
  765. $resize .= '<a title="'.get_lang('ResetFontSize').'" href="#" class="reset_font btn btn-default"><em class="fa fa-font"></em></a>';
  766. $resize .= '<a title="'.get_lang('IncreaseFontSize').'" href="#" class="increase_font btn btn-default"><em class="fa fa-font"></em></a>';
  767. $resize .= '</div>';
  768. $resize .= '</div>';
  769. }
  770. $this->assign('accessibility', $resize);
  771. // Preparing values for the menu
  772. // Logout link
  773. $hideLogout = api_get_setting('hide_logout_button');
  774. if ($hideLogout === 'true') {
  775. $this->assign('logout_link', null);
  776. } else {
  777. $this->assign('logout_link', api_get_path(WEB_PATH).'index.php?logout=logout&uid='.api_get_user_id());
  778. }
  779. //Profile link
  780. if (api_get_setting('allow_social_tool') == 'true') {
  781. $profile_url = api_get_path(WEB_CODE_PATH).'social/home.php';
  782. $profile_link = Display::url(get_lang('Profile'), $profile_url);
  783. } else {
  784. $profile_url = api_get_path(WEB_CODE_PATH).'auth/profile.php';
  785. $profile_link = Display::url(get_lang('Profile'), $profile_url);
  786. }
  787. $this->assign('profile_link', $profile_link);
  788. $this->assign('profile_url', $profile_url);
  789. //Message link
  790. $message_link = null;
  791. $message_url = null;
  792. if (api_get_setting('allow_message_tool') == 'true') {
  793. $message_url = api_get_path(WEB_CODE_PATH).'messages/inbox.php';
  794. $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
  795. }
  796. $this->assign('message_link', $message_link);
  797. $this->assign('message_url', $message_url);
  798. // Certificate Link
  799. $certificatesUrl = api_get_path(WEB_CODE_PATH).'gradebook/my_certificates.php';
  800. $certificateLink = Display::url(get_lang('MyCertificates'), $certificatesUrl);
  801. $allow = api_get_configuration_value('hide_my_certificate_link');
  802. if ($allow === false) {
  803. $this->assign('certificate_link', $certificateLink);
  804. }
  805. $institution = api_get_setting('Institution');
  806. $portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
  807. $this->assign('portal_name', $portal_name);
  808. // Menu
  809. $menu = return_menu();
  810. $this->assign('menu', $menu);
  811. // Setting notifications
  812. $count_unread_message = 0;
  813. if (api_get_setting('allow_message_tool') == 'true') {
  814. // get count unread message and total invitations
  815. $count_unread_message = MessageManager::get_number_of_messages(true);
  816. }
  817. $total_invitations = 0;
  818. if (api_get_setting('allow_social_tool') == 'true') {
  819. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
  820. api_get_user_id()
  821. );
  822. $usergroup = new UserGroup();
  823. $group_pending_invitations = $usergroup->get_groups_by_user(
  824. api_get_user_id(),
  825. GROUP_USER_PERMISSION_PENDING_INVITATION,
  826. false
  827. );
  828. if (!empty($group_pending_invitations)) {
  829. $group_pending_invitations = count($group_pending_invitations);
  830. } else {
  831. $group_pending_invitations = 0;
  832. }
  833. $total_invitations = intval($number_of_new_messages_of_friend) + $group_pending_invitations + intval($count_unread_message);
  834. }
  835. $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : null);
  836. $this->assign('user_notifications', $total_invitations);
  837. // Block Breadcrumb
  838. $breadcrumb = return_breadcrumb($interbreadcrumb, $language_file, $nameTools);
  839. $this->assign('breadcrumb', $breadcrumb);
  840. //Extra content
  841. $extra_header = null;
  842. if (!api_is_platform_admin()) {
  843. $extra_header = trim(api_get_setting('header_extra_content'));
  844. }
  845. $this->assign('header_extra_content', $extra_header);
  846. if ($sendHeaders) {
  847. header('Content-Type: text/html; charset='.api_get_system_encoding());
  848. header(
  849. 'X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'], 0, 1)
  850. );
  851. }
  852. $socialMeta = '';
  853. $metaTitle = api_get_setting('meta_title');
  854. if (!empty($metaTitle)) {
  855. $socialMeta .= '<meta name="twitter:card" content="summary" />' . "\n";
  856. $metaSite = api_get_setting('meta_twitter_site');
  857. if (!empty($metaSite)) {
  858. $socialMeta .= '<meta name="twitter:site" content="' . $metaSite . '" />' . "\n";
  859. $metaCreator = api_get_setting('meta_twitter_creator');
  860. if (!empty($metaCreator)) {
  861. $socialMeta .= '<meta name="twitter:creator" content="' . $metaCreator . '" />' . "\n";
  862. }
  863. }
  864. // The user badge page emits its own meta tags, so if this is
  865. // enabled, ignore the global ones
  866. $userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
  867. $skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0;
  868. if (!$userId && !$skillId) {
  869. // no combination of user and skill ID has been defined,
  870. // so print the normal OpenGraph meta tags
  871. $socialMeta .= '<meta property="og:title" content="' . $metaTitle . '" />' . "\n";
  872. $socialMeta .= '<meta property="og:url" content="' . api_get_path(WEB_PATH) . '" />' . "\n";
  873. $metaDescription = api_get_setting('meta_description');
  874. if (!empty($metaDescription)) {
  875. $socialMeta .= '<meta property="og:description" content="' . $metaDescription . '" />' . "\n";
  876. }
  877. $metaImage = api_get_setting('meta_image_path');
  878. if (!empty($metaImage)) {
  879. if (is_file(api_get_path(SYS_PATH) . $metaImage)) {
  880. $path = api_get_path(WEB_PATH) . $metaImage;
  881. $socialMeta .= '<meta property="og:image" content="' . $path . '" />' . "\n";
  882. }
  883. }
  884. }
  885. }
  886. $this->assign('social_meta', $socialMeta);
  887. }
  888. /**
  889. * Set footer parameters
  890. */
  891. private function set_footer_parameters()
  892. {
  893. if (api_get_setting('show_administrator_data') == 'true') {
  894. // Administrator name
  895. $administrator_data = get_lang('Manager').' : '.Display::encrypted_mailto_link(
  896. api_get_setting('emailAdministrator'),
  897. api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))
  898. );
  899. $this->assign('administrator_name', $administrator_data);
  900. }
  901. // Loading footer extra content
  902. if (!api_is_platform_admin()) {
  903. $extra_footer = trim(api_get_setting('footer_extra_content'));
  904. if (!empty($extra_footer)) {
  905. $this->assign('footer_extra_content', $extra_footer);
  906. }
  907. }
  908. // Tutor name
  909. if (api_get_setting('show_tutor_data') == 'true') {
  910. // Course manager
  911. $courseId = api_get_course_int_id();
  912. $id_session = api_get_session_id();
  913. if (!empty($courseId)) {
  914. $tutor_data = '';
  915. if ($id_session != 0) {
  916. $coachs_email = CourseManager::get_email_of_tutor_to_session(
  917. $id_session,
  918. $courseId
  919. );
  920. $email_link = array();
  921. foreach ($coachs_email as $coach) {
  922. $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
  923. }
  924. if (count($coachs_email) > 1) {
  925. $tutor_data .= get_lang('Coachs').' : ';
  926. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  927. } elseif (count($coachs_email) == 1) {
  928. $tutor_data .= get_lang('Coach').' : ';
  929. $tutor_data .= array_to_string($email_link, CourseManager::USER_SEPARATOR);
  930. } elseif (count($coachs_email) == 0) {
  931. $tutor_data .= '';
  932. }
  933. }
  934. $this->assign('session_teachers', $tutor_data);
  935. }
  936. }
  937. if (api_get_setting('show_teacher_data') == 'true') {
  938. // course manager
  939. $courseId = api_get_course_int_id();
  940. if (!empty($courseId)) {
  941. $teacher_data = '';
  942. $mail= CourseManager::get_emails_of_tutors_to_course($courseId);
  943. if (!empty($mail)) {
  944. $teachers_parsed = array();
  945. foreach ($mail as $value) {
  946. foreach ($value as $email => $name) {
  947. $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
  948. }
  949. }
  950. $label = get_lang('Teacher');
  951. if (count($mail) > 1) {
  952. $label = get_lang('Teachers');
  953. }
  954. $teacher_data .= $label.' : '.array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
  955. }
  956. $this->assign('teachers', $teacher_data);
  957. }
  958. }
  959. }
  960. /**
  961. * Show header template.
  962. */
  963. public function show_header_template()
  964. {
  965. $tpl = $this->get_template('layout/show_header.tpl');
  966. $this->display($tpl);
  967. }
  968. /**
  969. * Show footer template.
  970. */
  971. public function show_footer_template()
  972. {
  973. $tpl = $this->get_template('layout/show_footer.tpl');
  974. $this->display($tpl);
  975. }
  976. /**
  977. * Show footer js template.
  978. */
  979. public function show_footer_js_template()
  980. {
  981. $tpl = $this->get_template('layout/footer.js.tpl');
  982. $this->display($tpl);
  983. }
  984. /**
  985. * Sets the plugin content in a template variable
  986. * @param string $plugin_region
  987. * @return null
  988. */
  989. public function set_plugin_region($plugin_region)
  990. {
  991. if (!empty($plugin_region)) {
  992. $region_content = $this->plugin->load_region($plugin_region, $this, $this->force_plugin_load);
  993. if (!empty($region_content)) {
  994. $this->assign('plugin_'.$plugin_region, $region_content);
  995. } else {
  996. $this->assign('plugin_'.$plugin_region, null);
  997. }
  998. }
  999. return null;
  1000. }
  1001. /**
  1002. * @param string $template
  1003. * @return string
  1004. */
  1005. public function fetch($template = null)
  1006. {
  1007. $template = $this->twig->loadTemplate($template);
  1008. return $template->render($this->params);
  1009. }
  1010. /**
  1011. * @param string $variable
  1012. * @param mixed $value
  1013. */
  1014. public function assign($variable, $value = '')
  1015. {
  1016. $this->params[$variable] = $value;
  1017. }
  1018. /**
  1019. * Render the template
  1020. * @param string $template The template path
  1021. * @param boolean $clearFlashMessages Clear the $_SESSION variables for flash messages
  1022. */
  1023. public function display($template, $clearFlashMessages = true)
  1024. {
  1025. $this->assign('flash_messages', Display::getFlashToString());
  1026. if ($clearFlashMessages) {
  1027. Display::cleanFlashMessages();
  1028. }
  1029. echo $this->twig->render($template, $this->params);
  1030. }
  1031. /**
  1032. * Adds a body class for login pages
  1033. */
  1034. public function setLoginBodyClass()
  1035. {
  1036. $this->assign('login_class', 'section-login');
  1037. }
  1038. /**
  1039. * The theme that will be used if the database is not working.
  1040. * @return string
  1041. */
  1042. public static function getThemeFallback()
  1043. {
  1044. $theme = api_get_configuration_value('theme_fallback');
  1045. if (empty($theme)) {
  1046. $theme = 'chamilo';
  1047. }
  1048. return $theme;
  1049. }
  1050. /**
  1051. * @param bool|true $setLoginForm
  1052. */
  1053. public function setLoginForm($setLoginForm = true)
  1054. {
  1055. global $loginFailed;
  1056. $userId = api_get_user_id();
  1057. if (!($userId) || api_is_anonymous($userId)) {
  1058. // Only display if the user isn't logged in.
  1059. $this->assign(
  1060. 'login_language_form',
  1061. api_display_language_form(true)
  1062. );
  1063. if ($setLoginForm) {
  1064. $this->assign('login_form', $this->displayLoginForm());
  1065. if ($loginFailed) {
  1066. $this->assign('login_failed', $this::handleLoginFailed());
  1067. }
  1068. }
  1069. }
  1070. }
  1071. /**
  1072. * @return string
  1073. */
  1074. public function handleLoginFailed()
  1075. {
  1076. $message = get_lang('InvalidId');
  1077. if (!isset($_GET['error'])) {
  1078. if (api_is_self_registration_allowed()) {
  1079. $message = get_lang('InvalidForSelfRegistration');
  1080. }
  1081. } else {
  1082. switch ($_GET['error']) {
  1083. case '':
  1084. if (api_is_self_registration_allowed()) {
  1085. $message = get_lang('InvalidForSelfRegistration');
  1086. }
  1087. break;
  1088. case 'account_expired':
  1089. $message = get_lang('AccountExpired');
  1090. break;
  1091. case 'account_inactive':
  1092. $message = get_lang('AccountInactive');
  1093. break;
  1094. case 'user_password_incorrect':
  1095. $message = get_lang('InvalidId');
  1096. break;
  1097. case 'access_url_inactive':
  1098. $message = get_lang('AccountURLInactive');
  1099. break;
  1100. case 'wrong_captcha':
  1101. $message = get_lang('TheTextYouEnteredDoesNotMatchThePicture');
  1102. break;
  1103. case 'blocked_by_captcha':
  1104. $message = get_lang('AccountBlockedByCaptcha');
  1105. break;
  1106. case 'multiple_connection_not_allowed':
  1107. $message = get_lang('MultipleConnectionsAreNotAllow');
  1108. break;
  1109. case 'unrecognize_sso_origin':
  1110. //$message = get_lang('SSOError');
  1111. break;
  1112. }
  1113. }
  1114. return Display::return_message($message, 'error');
  1115. }
  1116. /**
  1117. * @return string
  1118. */
  1119. public function displayLoginForm()
  1120. {
  1121. $form = new FormValidator(
  1122. 'formLogin',
  1123. 'POST',
  1124. null,
  1125. null,
  1126. null,
  1127. FormValidator::LAYOUT_BOX_NO_LABEL
  1128. );
  1129. $form->addText(
  1130. 'login',
  1131. get_lang('UserName'),
  1132. true,
  1133. array(
  1134. 'id' => 'login',
  1135. 'autofocus' => 'autofocus',
  1136. 'icon' => 'user fa-fw',
  1137. 'placeholder' => get_lang('UserName'),
  1138. 'autocapitalize' => 'none'
  1139. )
  1140. );
  1141. $form->addElement(
  1142. 'password',
  1143. 'password',
  1144. get_lang('Pass'),
  1145. array(
  1146. 'id' => 'password',
  1147. 'icon' => 'lock fa-fw',
  1148. 'placeholder' => get_lang('Pass'),
  1149. 'autocapitalize' => 'none',
  1150. )
  1151. );
  1152. // Captcha
  1153. $captcha = api_get_setting('allow_captcha');
  1154. $allowCaptcha = $captcha === 'true';
  1155. if ($allowCaptcha) {
  1156. $useCaptcha = isset($_SESSION['loginFailed']) ? $_SESSION['loginFailed'] : null;
  1157. if ($useCaptcha) {
  1158. $ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
  1159. $options = array(
  1160. 'width' => 250,
  1161. 'height' => 90,
  1162. 'callback' => $ajax.'&var='.basename(__FILE__, '.php'),
  1163. 'sessionVar' => basename(__FILE__, '.php'),
  1164. 'imageOptions' => array(
  1165. 'font_size' => 20,
  1166. 'font_path' => api_get_path(SYS_FONTS_PATH) . 'opensans/',
  1167. 'font_file' => 'OpenSans-Regular.ttf',
  1168. //'output' => 'gif'
  1169. )
  1170. );
  1171. // Minimum options using all defaults (including defaults for Image_Text):
  1172. //$options = array('callback' => 'qfcaptcha_image.php');
  1173. $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options);
  1174. $form->addHtml(get_lang('ClickOnTheImageForANewOne'));
  1175. $form->addElement('text', 'captcha', get_lang('EnterTheLettersYouSee'));
  1176. $form->addRule('captcha', get_lang('EnterTheCharactersYouReadInTheImage'), 'required', null, 'client');
  1177. $form->addRule('captcha', get_lang('TheTextYouEnteredDoesNotMatchThePicture'), 'CAPTCHA', $captcha_question);
  1178. }
  1179. }
  1180. $form->addButton('submitAuth', get_lang('LoginEnter'), null, 'primary', null, 'btn-block');
  1181. $html = $form->returnForm();
  1182. if (api_get_setting('openid_authentication') == 'true') {
  1183. include_once 'main/auth/openid/login.php';
  1184. $html .= '<div>'.openid_form().'</div>';
  1185. }
  1186. return $html;
  1187. }
  1188. /**
  1189. * Set administrator variables
  1190. */
  1191. private function setAdministratorParams()
  1192. {
  1193. $_admin = [
  1194. 'email' => api_get_setting('emailAdministrator'),
  1195. 'surname' => api_get_setting('administratorSurname'),
  1196. 'name' => api_get_setting('administratorName'),
  1197. 'telephone' => api_get_setting('administratorTelephone')
  1198. ];
  1199. $this->assign('_admin', $_admin);
  1200. }
  1201. }