template.lib.php 56 KB

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