template.lib.php 48 KB

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