template.lib.php 51 KB

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