template.lib.php 51 KB

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