template.lib.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Julio Montoya <gugli100@gmail.com>
  5. * @todo better organization of the class, methods and variables
  6. *
  7. * */
  8. use \ChamiloSession as Session;
  9. use Silex\Application;
  10. class Template
  11. {
  12. private $app;
  13. public $preview_theme = null;
  14. public $theme; // the chamilo theme public_admin, chamilo, chamilo_red, etc
  15. public $title = null;
  16. public $show_header;
  17. public $show_footer;
  18. public $help;
  19. public $menu_navigation = array();
  20. public $show_learnpath = false; // This is a learnpath section or not?
  21. public $plugin = null;
  22. public $course_id = null;
  23. public $user_is_logged_in = false;
  24. public $twig = null;
  25. public $jquery_ui_theme;
  26. public $force_plugin_load = true;
  27. public $navigation_array;
  28. /**
  29. * @param Application $app
  30. */
  31. public function __construct(Application $app = null)
  32. {
  33. if (empty($app)) {
  34. global $app;
  35. $this->app = &$app;
  36. } else {
  37. //ugly fix just for now
  38. $this->app = &$app;
  39. }
  40. $this->app['classic_layout'] = true;
  41. $this->navigation_array = $this->returnNavigationArray();
  42. // Just in case
  43. global $tool_name;
  44. // Page title
  45. $this->title = isset($app['title']) ? $app['title'] : $tool_name;
  46. $this->show_learnpath = $app['template.show_learnpath'];
  47. /* Current themes: cupertino, smoothness, ui-lightness.
  48. Find the themes folder in main/inc/lib/javascript/jquery-ui */
  49. $this->jquery_ui_theme = 'smoothness';
  50. //Setting system variables
  51. $this->setSystemParameters();
  52. //Setting user variables
  53. $this->setUserParameters();
  54. //Setting course variables
  55. $this->setCourseParameters();
  56. //Using global because all scripts have this variable
  57. global $interbreadcrumb;
  58. if (isset($this->app['breadcrumb']) && !empty($this->app['breadcrumb'])) {
  59. if (empty($interbreadcrumb)) {
  60. $interbreadcrumb = $this->app['breadcrumb'];
  61. } else {
  62. $interbreadcrumb = array_merge($interbreadcrumb, $this->app['breadcrumb']);
  63. }
  64. }
  65. if (!empty($interbreadcrumb)) {
  66. $this->app['breadcrumb'] = $interbreadcrumb;
  67. }
  68. //header and footer are showed by default
  69. $this->setFooter($app['template.show_footer']);
  70. $this->setHeader($app['template.show_header']);
  71. $this->setHeaderParameters();
  72. $this->setFooterParameters();
  73. $this->assign('style', $app['template_style']);
  74. //Chamilo plugins
  75. if ($this->show_header) {
  76. if ($app['template.load_plugins'] && !empty($app['plugins'])) {
  77. $this->plugin = new AppPlugin();
  78. //1. Showing installed plugins in regions
  79. $plugin_regions = $this->plugin->get_plugin_regions();
  80. foreach ($plugin_regions as $region) {
  81. $this->set_plugin_region($region);
  82. }
  83. //2. Loading the course plugin info
  84. global $course_plugin;
  85. if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
  86. //Load plugin get_langs
  87. $this->plugin->load_plugin_lang_variables($course_plugin);
  88. }
  89. }
  90. }
  91. }
  92. /**
  93. * Get icon path
  94. * @param string $image
  95. * @param int $size
  96. *
  97. * @return string
  98. */
  99. public static function get_icon_path($image, $size = ICON_SIZE_SMALL)
  100. {
  101. return Display:: return_icon($image, '', array(), $size, false, true);
  102. }
  103. /**
  104. * Format date
  105. * @param string $timestamp
  106. * @param string $format
  107. *
  108. * @return string
  109. */
  110. public static function format_date($timestamp, $format = null)
  111. {
  112. return api_format_date($timestamp, $format);
  113. }
  114. /**
  115. * @param string $help_input
  116. */
  117. public function setHelp($help_input = null)
  118. {
  119. if (!empty($help_input)) {
  120. $help = $help_input;
  121. } else {
  122. $help = $this->help;
  123. }
  124. $this->assign('help_content', $help);
  125. }
  126. /**
  127. * Use template system to parse the actions menu
  128. * @todo finish it!
  129. * @param array $actions
  130. *
  131. **/
  132. public function setActions($actions)
  133. {
  134. $action_string = '';
  135. if (!empty($actions)) {
  136. foreach ($actions as $action) {
  137. $action_string .= $action;
  138. }
  139. }
  140. $this->assign('actions', $actions);
  141. }
  142. /**
  143. * Shortcut to display a 1 col layout (index.php)
  144. * */
  145. public function display_one_col_template()
  146. {
  147. $tpl = $this->get_template('layout/layout_1_col.tpl');
  148. $this->display($tpl);
  149. }
  150. /**
  151. * Shortcut to display a 2 col layout (userportal.php)
  152. * */
  153. public function display_two_col_template()
  154. {
  155. $tpl = $this->get_template('layout/layout_2_col.tpl');
  156. $this->display($tpl);
  157. }
  158. /**
  159. * Displays an empty template
  160. */
  161. public function display_blank_template()
  162. {
  163. $tpl = $this->get_template('layout/blank.tpl');
  164. $this->display($tpl);
  165. }
  166. /**
  167. * Displays an empty template
  168. */
  169. public function display_no_layout_template()
  170. {
  171. $tpl = $this->get_template('layout/no_layout.tpl');
  172. $this->display($tpl);
  173. }
  174. /**
  175. * Sets the footer visibility
  176. * @param bool true if we show the footer
  177. */
  178. public function setFooter($status)
  179. {
  180. $this->show_footer = $status;
  181. $this->assign('show_footer', $status);
  182. }
  183. /**
  184. * Sets the header visibility
  185. * @param bool true if we show the header
  186. */
  187. public function setHeader($status)
  188. {
  189. $this->show_header = $status;
  190. $this->assign('show_header', $status);
  191. //Toolbar
  192. $show_admin_toolbar = api_get_setting('show_admin_toolbar');
  193. $show_toolbar = 0;
  194. switch ($show_admin_toolbar) {
  195. case 'do_not_show':
  196. break;
  197. case 'show_to_admin':
  198. if (api_is_platform_admin()) {
  199. $show_toolbar = 1;
  200. }
  201. break;
  202. case 'show_to_admin_and_teachers':
  203. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  204. $show_toolbar = 1;
  205. }
  206. break;
  207. case 'show_to_all':
  208. $show_toolbar = 1;
  209. break;
  210. }
  211. $this->assign('show_toolbar', $show_toolbar);
  212. //Only if course is available
  213. $show_course_shortcut = null;
  214. $show_course_navigation_menu = null;
  215. if (!empty($this->course_id) && $this->user_is_logged_in) {
  216. if (api_get_setting('show_toolshortcuts') != 'false') {
  217. //Course toolbar
  218. $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
  219. }
  220. if (api_get_setting('show_navigation_menu') != 'false') {
  221. //Course toolbar
  222. $show_course_navigation_menu = CourseHome::show_navigation_menu();
  223. }
  224. }
  225. $this->assign('show_course_shortcut', $show_course_shortcut);
  226. $this->assign('show_course_navigation_menu', $show_course_navigation_menu);
  227. }
  228. /**
  229. * @param string $name
  230. * @return string
  231. */
  232. public function get_template($name)
  233. {
  234. return $this->app['template_style'].'/'.$name;
  235. }
  236. /** Set course parameters */
  237. private function setCourseParameters()
  238. {
  239. //Setting course id
  240. $this->course_id = api_get_course_int_id();
  241. $this->app['course_code'] = api_get_course_id();
  242. $this->app['session_id'] = api_get_session_id();
  243. }
  244. /**
  245. * Set user parameters
  246. */
  247. private function setUserParameters()
  248. {
  249. $user_info = array();
  250. $user_info['logged'] = 0;
  251. $this->user_is_logged_in = false;
  252. if (api_user_is_login()) {
  253. $user_info = $this->app['current_user'];
  254. $user_info['logged'] = 1;
  255. $user_info['is_admin'] = 0;
  256. if (api_is_platform_admin()) {
  257. $user_info['is_admin'] = 1;
  258. }
  259. $new_messages = MessageManager::get_new_messages();
  260. $user_info['messages_count'] = $new_messages != 0 ? Display::label($new_messages, 'warning') : null;
  261. /*$usergroup = new UserGroup();
  262. $messages_invitations_count = $usergroup->get_groups_by_user_count($user_info['user_id'], GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  263. $user_info['messages_invitations_count'] = $messages_invitations_count != 0 ? Display::label(
  264. $messages_invitations_count,
  265. 'warning'
  266. ) : null;*/
  267. $this->user_is_logged_in = true;
  268. }
  269. //Setting the $_u array that could be use in any template
  270. $this->assign('_u', $user_info);
  271. }
  272. /**
  273. * Set system parameters
  274. */
  275. private function setSystemParameters()
  276. {
  277. global $_configuration;
  278. //Setting app paths/URLs
  279. $_p = array(
  280. 'web' => api_get_path(WEB_PATH),
  281. 'web_course' => api_get_path(WEB_COURSE_PATH),
  282. 'web_main' => api_get_path(WEB_CODE_PATH),
  283. 'web_css' => api_get_path(WEB_CSS_PATH),
  284. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  285. 'web_img' => api_get_path(WEB_IMG_PATH),
  286. 'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
  287. 'web_lib' => api_get_path(WEB_LIBRARY_PATH),
  288. 'public_web' => api_get_path(WEB_PUBLIC_PATH)
  289. );
  290. $this->assign('_p', $_p);
  291. //Here we can add system parameters that can be use in any template
  292. $_s = array(
  293. 'software_name' => api_get_software_name(),
  294. 'system_version' => $_configuration['system_version'],
  295. 'site_name' => api_get_setting('siteName'),
  296. 'institution' => api_get_setting('Institution')
  297. );
  298. $this->assign('_s', $_s);
  299. }
  300. /**
  301. * Set theme, include CSS files
  302. */
  303. private function setCssFiles()
  304. {
  305. global $disable_js_and_css_files;
  306. $css = array();
  307. $this->theme = api_get_visual_theme();
  308. if (isset($_POST['style']) && api_is_platform_admin()) {
  309. $this->preview_theme = $_POST['style'];
  310. }
  311. if (!empty($this->preview_theme)) {
  312. $this->theme = $this->preview_theme;
  313. }
  314. $this->app['theme'] = $this->theme;
  315. $cssPath = api_get_path(WEB_CSS_PATH);
  316. // Base CSS.
  317. $css[] = api_get_cdn_path($cssPath.'base.css');
  318. // Compressed version of default + all CSS files
  319. // @todo use assetic to compress files
  320. // $css[] = api_get_cdn_path(api_get_path(WEB_PATH).'web/css/'.$this->theme.'/style.css');
  321. // Default theme CSS.
  322. $css[] = api_get_cdn_path($cssPath.$this->theme.'/default.css');
  323. $css[] = api_get_cdn_path($cssPath.'bootstrap-responsive.css');
  324. $css[] = api_get_cdn_path($cssPath.'responsive.css');
  325. $css[] = api_get_cdn_path($cssPath.'font_awesome/css/font-awesome.css');
  326. // Extra CSS files.
  327. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css';
  328. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
  329. if ($this->show_learnpath) {
  330. $css[] = $cssPath.$this->theme.'/learnpath.css';
  331. $css[] = $cssPath.$this->theme.'/scorm.css';
  332. }
  333. if (api_is_global_chat_enabled()) {
  334. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chat/css/chat.css';
  335. }
  336. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/'.$this->jquery_ui_theme.'/jquery-ui-custom.css';
  337. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/default.css';
  338. $css_file_to_string = null;
  339. foreach ($css as $file) {
  340. $css_file_to_string .= api_get_css($file);
  341. }
  342. // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
  343. if (SHOW_TEXT_NEAR_ICONS == true) {
  344. //hack in order to fix the actions buttons
  345. $css_file_to_string .= '<style>
  346. .td_actions a {
  347. float:left;
  348. width:100%;
  349. }
  350. .forum_message_left a {
  351. float:left;
  352. width:100%;
  353. }
  354. </style>';
  355. }
  356. $navigator_info = api_get_navigator();
  357. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  358. $css_file_to_string .= 'img, div { behavior: url('.api_get_path(
  359. WEB_LIBRARY_PATH
  360. ).'javascript/iepngfix/iepngfix.htc) } '."\n";
  361. }
  362. if (!$disable_js_and_css_files) {
  363. $this->assign('css_file_to_string', $css_file_to_string);
  364. $style_print = api_get_css(api_get_cdn_path($cssPath.$this->theme.'/print.css'), 'print');
  365. $this->assign('css_style_print', $style_print);
  366. }
  367. }
  368. /**
  369. * Sets JS files
  370. */
  371. private function setJsFiles()
  372. {
  373. global $disable_js_and_css_files, $htmlHeadXtra;
  374. //JS files
  375. $js_files = array(
  376. 'modernizr.js',
  377. 'jquery.min.js',
  378. 'chosen/chosen.jquery.min.js',
  379. 'jquery-ui/'.$this->jquery_ui_theme.'/jquery-ui-custom.min.js',
  380. //'jquery-ui/jquery.ui.touch-punch.js',
  381. 'thickbox.js',
  382. 'ckeditor/ckeditor.js',
  383. //'tinymce/tinymce.min.js',
  384. 'bootstrap/bootstrap.js',
  385. );
  386. if (api_is_global_chat_enabled()) {
  387. //Do not include the global chat in LP
  388. if ($this->show_learnpath == false && $this->show_footer == true && $this->app['template.hide_global_chat'] == false) {
  389. $js_files[] = 'chat/js/chat.js';
  390. }
  391. }
  392. if (api_get_setting('accessibility_font_resize') == 'true') {
  393. $js_files[] = 'fontresize.js';
  394. }
  395. if (api_get_setting('include_asciimathml_script') == 'true') {
  396. $js_files[] = 'asciimath/ASCIIMathML.js';
  397. }
  398. $js_file_to_string = null;
  399. foreach ($js_files as $js_file) {
  400. $js_file_to_string .= api_get_js($js_file);
  401. }
  402. //Loading email_editor js
  403. if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
  404. $js_file_to_string .= $this->fetch($this->app['template_style'].'/mail_editor/email_link.js.tpl');
  405. }
  406. //$js_file_to_string = api_get_js_simple(api_get_path(WEB_PATH).'web/js/script.js').$js_file_to_string;
  407. if (!$disable_js_and_css_files) {
  408. $this->assign('js_file_to_string', $js_file_to_string);
  409. $extra_headers = null;
  410. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  411. foreach ($htmlHeadXtra as $this_html_head) {
  412. $extra_headers .= $this_html_head."\n";
  413. }
  414. }
  415. if (isset($this->app['extraJS'])) {
  416. foreach ($this->app['extraJS'] as $this_html_head) {
  417. $extra_headers .= $this_html_head."\n";
  418. }
  419. }
  420. $this->assign('extra_headers', $extra_headers);
  421. }
  422. }
  423. /**
  424. * Set header parameters
  425. */
  426. private function setHeaderParameters()
  427. {
  428. $_course = api_get_course_info();
  429. $_configuration = $this->app['configuration'];
  430. $this_section = $this->app['this_section'];
  431. $nameTools = $this->title;
  432. $navigation = $this->navigation_array;
  433. $this->menu_navigation = $navigation['menu_navigation'];
  434. $this->assign('system_charset', api_get_system_encoding());
  435. $this->assign('online_button', Display::return_icon('online.png'));
  436. $this->assign('offline_button', Display::return_icon('offline.png'));
  437. // Get language iso-code for this page - ignore errors
  438. $this->assign('document_language', api_get_language_isocode());
  439. $course_title = isset($_course['name']) ? $_course['name'] : null;
  440. $title_list = array();
  441. $title_list[] = api_get_setting('Institution');
  442. $title_list[] = api_get_setting('siteName');
  443. if (!empty($course_title)) {
  444. $title_list[] = $course_title;
  445. }
  446. if ($nameTools != '') {
  447. $title_list[] = $nameTools;
  448. }
  449. $title_string = '';
  450. for ($i = 0; $i < count($title_list); $i++) {
  451. $title_string .= $title_list[$i];
  452. if (isset($title_list[$i + 1])) {
  453. $item = trim($title_list[$i + 1]);
  454. if (!empty($item)) {
  455. $title_string .= ' - ';
  456. }
  457. }
  458. }
  459. $this->assign('title_string', $title_string);
  460. //Setting the theme and CSS files
  461. $this->setCssFiles();
  462. $this->setJsFiles();
  463. // Implementation of prefetch.
  464. // See http://cdn.chamilo.org/main/img/online.png for details
  465. $prefetch = '';
  466. if (!empty($_configuration['cdn_enable'])) {
  467. $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
  468. foreach ($_configuration['cdn'] as $host => $exts) {
  469. $prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
  470. }
  471. }
  472. $this->assign('prefetch', $prefetch);
  473. $this->assign('text_direction', api_get_text_direction());
  474. $this->assign('section_name', 'section-'.$this_section);
  475. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
  476. if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
  477. $access_url_id = api_get_current_access_url_id();
  478. if ($access_url_id != -1) {
  479. $url_info = api_get_access_url($access_url_id);
  480. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  481. $clean_url = replace_dangerous_char($url);
  482. $clean_url = str_replace('/', '-', $clean_url);
  483. $clean_url .= '/';
  484. $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
  485. $icon_real_homep = api_get_path(SYS_PATH).'home/'.$clean_url;
  486. //we create the new dir for the new sites
  487. if (is_file($icon_real_homep.'favicon.ico')) {
  488. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  489. }
  490. }
  491. }
  492. $this->assign('favico', $favico);
  493. $this->setHelp();
  494. $notification = $this->returnNotificationMenu();
  495. $this->assign('notification_menu', $notification);
  496. //Preparing values for the menu
  497. //Logout link
  498. $this->assign('logout_link', api_get_path(WEB_PUBLIC_PATH).'logout');
  499. //Profile link
  500. if (api_get_setting('allow_social_tool') == 'true') {
  501. $profile_link = '<a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">'.get_lang('Profile').'</a>';
  502. } else {
  503. $profile_link = '<a href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php">'.get_lang('Profile').'</a>';
  504. }
  505. $this->assign('profile_link', $profile_link);
  506. //Message link
  507. $message_link = null;
  508. if (api_get_setting('allow_message_tool') == 'true') {
  509. $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
  510. }
  511. $this->assign('message_link', $message_link);
  512. $institution = api_get_setting('Institution');
  513. $portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
  514. $this->assign('portal_name', $portal_name);
  515. //Menu
  516. $menu = $this->returnMenu();
  517. $this->assign('menu', $menu);
  518. //Breadcrumb
  519. $breadcrumb = $this->returnBreadcrumb();
  520. $this->assign('breadcrumb', $breadcrumb);
  521. //Extra content
  522. $extra_header = null;
  523. if (!api_is_platform_admin()) {
  524. $extra_header = trim(api_get_setting('header_extra_content'));
  525. }
  526. $this->assign('header_extra_content', $extra_header);
  527. }
  528. /**
  529. * Set footer parameters
  530. */
  531. private function setFooterParameters()
  532. {
  533. //Show admin data
  534. //$this->assign('show_administrator_data', api_get_setting('show_administrator_data'));
  535. if (api_get_setting('show_administrator_data') == 'true') {
  536. //Administrator name
  537. $administrator_data = get_lang('Manager').' : '.Display::encrypted_mailto_link(
  538. api_get_setting('emailAdministrator'),
  539. api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))
  540. );
  541. $this->assign('administrator_name', $administrator_data);
  542. }
  543. //Loading footer extra content
  544. if (!api_is_platform_admin()) {
  545. $extra_footer = trim(api_get_setting('footer_extra_content'));
  546. if (!empty($extra_footer)) {
  547. $this->assign('footer_extra_content', $extra_footer);
  548. }
  549. }
  550. $courseId = api_get_course_int_id();
  551. //Tutor name
  552. if (api_get_setting('show_tutor_data') == 'true') {
  553. // Course manager
  554. $id_session = api_get_session_id();
  555. if (isset($courseId) && $courseId != -1 && !empty($courseId)) {
  556. $tutor_data = '';
  557. if ($id_session != 0) {
  558. $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $courseId);
  559. $email_link = array();
  560. foreach ($coachs_email as $coach) {
  561. $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
  562. }
  563. if (count($coachs_email) > 1) {
  564. $tutor_data .= get_lang('Coachs').' : ';
  565. $tutor_data .= ArrayClass::array_to_string($email_link, CourseManager::USER_SEPARATOR);
  566. } elseif (count($coachs_email) == 1) {
  567. $tutor_data .= get_lang('Coach').' : ';
  568. $tutor_data .= ArrayClass::array_to_string($email_link, CourseManager::USER_SEPARATOR);
  569. } elseif (count($coachs_email) == 0) {
  570. $tutor_data .= '';
  571. }
  572. }
  573. $this->assign('session_teachers', $tutor_data);
  574. }
  575. }
  576. if (api_get_setting('show_teacher_data') == 'true') {
  577. // course manager
  578. if (isset($courseId) && $courseId != -1 && !empty($courseId)) {
  579. $teacher_data = '';
  580. $mail = CourseManager::get_emails_of_tutors_to_course($courseId);
  581. if (!empty($mail)) {
  582. $teachers_parsed = array();
  583. foreach ($mail as $value) {
  584. foreach ($value as $email => $name) {
  585. $teachers_parsed[] = Display::encrypted_mailto_link($email, $name);
  586. }
  587. }
  588. $label = get_lang('Teacher');
  589. if (count($mail) > 1) {
  590. $label = get_lang('Teachers');
  591. }
  592. $teacher_data .= $label.' : '.ArrayClass::array_to_string($teachers_parsed, CourseManager::USER_SEPARATOR);
  593. }
  594. $this->assign('teachers', $teacher_data);
  595. }
  596. }
  597. }
  598. public function manageDisplay($content)
  599. {
  600. //$this->assign('content', $content);
  601. }
  602. /* Sets the plugin content in a template variable */
  603. private function set_plugin_region($plugin_region)
  604. {
  605. if (!empty($plugin_region)) {
  606. $region_content = $this->plugin->load_region($this->app['plugins'], $plugin_region, $this, $this->force_plugin_load);
  607. if (!empty($region_content)) {
  608. $this->assign('plugin_'.$plugin_region, $region_content);
  609. } else {
  610. $this->assign('plugin_'.$plugin_region, null);
  611. }
  612. }
  613. return null;
  614. }
  615. /**
  616. * @param string $template
  617. * @return mixed
  618. */
  619. public function fetch($template = null)
  620. {
  621. $template = $this->app['twig']->loadTemplate($template);
  622. return $template->render(array());
  623. }
  624. public function assign($key, $value = null)
  625. {
  626. if ($this->app['allowed'] == true) {
  627. $this->app['twig']->addGlobal($key, $value);
  628. }
  629. }
  630. public function display($template = null)
  631. {
  632. if (!empty($template)) {
  633. $this->app['default_layout'] = $template;
  634. }
  635. $this->app->run();
  636. }
  637. /**
  638. * @return null|string
  639. */
  640. public function returnMenu()
  641. {
  642. $navigation = $this->navigation_array;
  643. $navigation = $navigation['navigation'];
  644. // Displaying the tabs
  645. $lang = api_get_user_language();
  646. //Preparing home folder for multiple urls
  647. if (api_get_multiple_access_url()) {
  648. $access_url_id = api_get_current_access_url_id();
  649. if ($access_url_id != -1) {
  650. $url_info = api_get_access_url($access_url_id);
  651. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  652. $clean_url = replace_dangerous_char($url);
  653. $clean_url = str_replace('/', '-', $clean_url);
  654. $clean_url .= '/';
  655. $homep = api_get_path(SYS_DATA_PATH).'home/'.$clean_url; //homep for Home Path
  656. //we create the new dir for the new sites
  657. if (!is_dir($homep)) {
  658. mkdir($homep, api_get_permissions_for_new_directories());
  659. }
  660. }
  661. } else {
  662. $homep = api_get_path(SYS_PATH).'home/';
  663. }
  664. $ext = '.html';
  665. $menutabs = 'home_tabs';
  666. $home_top = '';
  667. if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
  668. $home_top = @(string)file_get_contents($homep.$menutabs.'_'.$lang.$ext);
  669. } elseif (is_file($homep.$menutabs.$lang.$ext) && is_readable($homep.$menutabs.$lang.$ext)) {
  670. $home_top = @(string)file_get_contents($homep.$menutabs.$lang.$ext);
  671. } else {
  672. //$errorMsg = get_lang('HomePageFilesNotReadable');
  673. }
  674. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  675. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top);
  676. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  677. $lis = '';
  678. if (!empty($open)) {
  679. if (strpos($open, 'show_menu') === false) {
  680. if (api_is_anonymous()) {
  681. $navigation[SECTION_CAMPUS] = null;
  682. }
  683. } else {
  684. //$lis .= Display::tag('li', $open);
  685. $lis .= $open;
  686. }
  687. }
  688. if (count($navigation) > 0 || !empty($lis)) {
  689. $pre_lis = '';
  690. foreach ($navigation as $section => $navigation_info) {
  691. if (isset($GLOBALS['this_section'])) {
  692. $current = $section == $GLOBALS['this_section'] ? ' id="current" class="active" ' : '';
  693. } else {
  694. $current = '';
  695. }
  696. if (!empty($navigation_info['title'])) {
  697. $pre_lis .= '<li'.$current.' ><a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a></li>';
  698. }
  699. }
  700. $lis = $pre_lis.$lis;
  701. }
  702. $menu = null;
  703. if (!empty($lis)) {
  704. $menu .= $lis;
  705. }
  706. return $menu;
  707. }
  708. /**
  709. *
  710. * @return string
  711. */
  712. public function getNavigationLinks()
  713. {
  714. // Deleting the myprofile link.
  715. if (api_get_setting('allow_social_tool') == 'true') {
  716. unset($this->menu_navigation['myprofile']);
  717. }
  718. return $this->menu_navigation;
  719. }
  720. /**
  721. * @param string $layout
  722. * @return mixed
  723. */
  724. public function render_layout($layout = null)
  725. {
  726. if (empty($layout)) {
  727. $layout = $this->app['default_layout'];
  728. }
  729. return $this->app['twig']->render($this->app['template_style'].'/layout/'.$layout);
  730. }
  731. /**
  732. * @param string $template
  733. * @param array $elements
  734. * @return mixed
  735. */
  736. public function render_template($template, $elements = array())
  737. {
  738. return $this->app['twig']->render($this->app['template_style'].'/'.$template, $elements);
  739. }
  740. /**
  741. * Determines the possible tabs (=sections) that are available.
  742. * This function is used when creating the tabs in the third header line and
  743. * all the sections that do not appear there (as determined by the
  744. * platform admin on the Chamilo configuration settings page)
  745. * will appear in the right hand menu that appears on several other pages
  746. * @return array containing all the possible tabs
  747. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  748. */
  749. public function getTabs()
  750. {
  751. $_course = api_get_course_info();
  752. $navigation = array();
  753. // Campus Homepage
  754. $navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PATH).'index.php';
  755. $navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage');
  756. // My Courses
  757. if (api_is_allowed_to_create_course()) {
  758. // Link to my courses for teachers
  759. $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true';
  760. $navigation['mycourses']['title'] = get_lang('MyCourses');
  761. } else {
  762. // Link to my courses for students
  763. $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php';
  764. $navigation['mycourses']['title'] = get_lang('MyCourses');
  765. }
  766. // My Profile
  767. $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH).'auth/profile.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
  768. $navigation['myprofile']['title'] = get_lang('ModifyProfile');
  769. // Link to my agenda
  770. $navigation['myagenda']['url'] = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=personal';
  771. $navigation['myagenda']['title'] = get_lang('MyAgenda');
  772. // Gradebook
  773. if (api_get_setting('gradebook_enable') == 'true') {
  774. $navigation['mygradebook']['url'] = api_get_path(
  775. WEB_CODE_PATH
  776. ).'gradebook/gradebook.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
  777. $navigation['mygradebook']['title'] = get_lang('MyGradebook');
  778. }
  779. // Reporting
  780. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  781. // Link to my space
  782. $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/';
  783. $navigation['session_my_space']['title'] = get_lang('MySpace');
  784. } else {
  785. // Link to my progress
  786. $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH).'auth/my_progress.php';
  787. $navigation['session_my_progress']['title'] = get_lang('MyProgress');
  788. }
  789. // Social
  790. if (api_get_setting('allow_social_tool') == 'true') {
  791. $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
  792. $navigation['social']['title'] = get_lang('SocialNetwork');
  793. }
  794. // Dashboard
  795. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  796. $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
  797. $navigation['dashboard']['title'] = get_lang('Dashboard');
  798. }
  799. // Reports
  800. /*
  801. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  802. $navigation['reports']['url'] = api_get_path(WEB_CODE_PATH).'reports/index.php';
  803. $navigation['reports']['title'] = get_lang('Reports');
  804. }*/
  805. // Custom tabs
  806. for ($i = 1; $i <= 3; $i++) {
  807. if (api_get_setting('custom_tab_'.$i.'_name') && api_get_setting('custom_tab_'.$i.'_url')) {
  808. $navigation['custom_tab_'.$i]['url'] = api_get_setting('custom_tab_'.$i.'_url');
  809. $navigation['custom_tab_'.$i]['title'] = api_get_setting('custom_tab_'.$i.'_name');
  810. }
  811. }
  812. // Platform administration
  813. if (api_is_platform_admin(true)) {
  814. $navigation['platform_admin']['url'] = api_get_path(WEB_CODE_PATH).'admin/';
  815. $navigation['platform_admin']['title'] = get_lang('PlatformAdmin');
  816. }
  817. if (api_is_question_manager()) {
  818. $navigation['question_manager']['url'] = api_get_path(WEB_PUBLIC_PATH).'admin/questionmanager';
  819. $navigation['question_manager']['title'] = get_lang('PlatformAdmin');
  820. }
  821. return $navigation;
  822. }
  823. /**
  824. * @param string $theme
  825. * @deprecated the logo is wrote in the main_header.tpl file
  826. * @return string
  827. */
  828. public function returnLogo($theme)
  829. {
  830. $_course = api_get_course_info();
  831. $html = '';
  832. $logo = api_get_path(SYS_CODE_PATH).'css/'.$theme.'/images/header-logo.png';
  833. $site_name = api_get_setting('siteName');
  834. if (file_exists($logo)) {
  835. $site_name = api_get_setting('Institution').' - '.$site_name;
  836. $html .= '<div id="logo">';
  837. $image_url = api_get_path(WEB_CSS_PATH).$theme.'/images/header-logo.png';
  838. $logo = Display::img($image_url, $site_name, array('title' => $site_name));
  839. $html .= Display::url($logo, api_get_path(WEB_PATH).'index.php');
  840. $html .= '</div>';
  841. } else {
  842. $html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$site_name.'</a>';
  843. $iurl = api_get_setting('InstitutionUrl');
  844. $iname = api_get_setting('Institution');
  845. if (!empty($iname)) {
  846. $html .= '-&nbsp;<a href="'.$iurl.'" target="_top">'.$iname.'</a>';
  847. }
  848. // External link section a.k.a Department - Department URL
  849. if (isset($_course['extLink']) && $_course['extLink']['name'] != '') {
  850. $html .= '<span class="extLinkSeparator"> - </span>';
  851. if ($_course['extLink']['url'] != '') {
  852. $html .= '<a class="extLink" href="'.$_course['extLink']['url'].'" target="_top">';
  853. $html .= $_course['extLink']['name'];
  854. $html .= '</a>';
  855. } else {
  856. $html .= $_course['extLink']['name'];
  857. }
  858. }
  859. }
  860. return $html;
  861. }
  862. /**
  863. * @return string
  864. */
  865. public function returnNotificationMenu()
  866. {
  867. $_course = api_get_course_info();
  868. $course_id = api_get_course_id();
  869. $user_id = api_get_user_id();
  870. $html = '';
  871. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting(
  872. 'showonline',
  873. 'users'
  874. ) == 'true' AND $user_id) OR (api_get_setting('showonline', 'course') == 'true' AND $user_id AND $course_id)
  875. ) {
  876. $number = Online::who_is_online_count(api_get_setting('time_limit_whosonline'));
  877. $number_online_in_course = 0;
  878. if (!empty($_course['id'])) {
  879. $number_online_in_course = Online::who_is_online_in_this_course_count(
  880. $user_id,
  881. api_get_setting('time_limit_whosonline'),
  882. $_course['id']
  883. );
  884. }
  885. // Display the who's online of the platform
  886. if ($number) {
  887. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting(
  888. 'showonline',
  889. 'users'
  890. ) == 'true' AND $user_id)
  891. ) {
  892. $html .= '<li><a href="'.SocialManager::getUserOnlineLink().'" target="_top" title="'.get_lang(
  893. 'UsersOnline'
  894. ).'" >'.
  895. Display::return_icon(
  896. 'user.png',
  897. get_lang('UsersOnline'),
  898. array(),
  899. ICON_SIZE_TINY
  900. ).' '.$number.'</a></li>';
  901. }
  902. }
  903. // Display the who's online for the course
  904. if ($number_online_in_course) {
  905. if (is_array($_course) AND api_get_setting(
  906. 'showonline',
  907. 'course'
  908. ) == 'true' AND isset($_course['sysCode'])
  909. ) {
  910. $html .= '<li><a href="'.SocialManager::getUserOnlineLink($_course['sysCode']).'" target="_top">'.
  911. Display::return_icon(
  912. 'course.png',
  913. get_lang('UsersOnline').' '.get_lang('InThisCourse'),
  914. array(),
  915. ICON_SIZE_TINY
  916. ).' '.$number_online_in_course.' </a></li>';
  917. }
  918. }
  919. // Display the who's online for the session
  920. if (isset($user_id) && api_get_session_id() != 0) {
  921. if (api_is_allowed_to_edit()) {
  922. $html .= '<li><a href="'.SocialManager::getUserOnlineLink(null, api_get_session_id()).'&id_coach='.$user_id.'" >'.
  923. Display::return_icon(
  924. 'session.png',
  925. get_lang('UsersConnectedToMySessions'),
  926. array(),
  927. ICON_SIZE_TINY
  928. ).' </a></li>';
  929. }
  930. }
  931. }
  932. if (api_get_setting('accessibility_font_resize') == 'true') {
  933. $html .= '<li class="resize_font">';
  934. $html .= '<span class="decrease_font" title="'.get_lang(
  935. 'DecreaseFontSize'
  936. ).'">A</span> <span class="reset_font" title="'.get_lang(
  937. 'ResetFontSize'
  938. ).'">A</span> <span class="increase_font" title="'.get_lang('IncreaseFontSize').'">A</span>';
  939. $html .= '</li>';
  940. }
  941. return $html;
  942. }
  943. /**
  944. * @return array
  945. */
  946. public function returnNavigationArray()
  947. {
  948. $navigation = array();
  949. $menu_navigation = array();
  950. $possible_tabs = $this->getTabs();
  951. // Campus Homepage
  952. if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
  953. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  954. } else {
  955. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  956. }
  957. if (api_get_user_id() && !api_is_anonymous()) {
  958. // My Courses
  959. if (api_get_setting('show_tabs', 'my_courses') == 'true') {
  960. $navigation['mycourses'] = $possible_tabs['mycourses'];
  961. } else {
  962. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  963. }
  964. // My Profile
  965. if (api_get_setting('show_tabs', 'my_profile') == 'true' && api_get_setting(
  966. 'allow_social_tool'
  967. ) != 'true'
  968. ) {
  969. $navigation['myprofile'] = $possible_tabs['myprofile'];
  970. } else {
  971. $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
  972. }
  973. // My Agenda
  974. if (api_get_setting('show_tabs', 'my_agenda') == 'true') {
  975. $navigation['myagenda'] = $possible_tabs['myagenda'];
  976. } else {
  977. $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
  978. }
  979. // Gradebook
  980. if (api_get_setting('gradebook_enable') == 'true') {
  981. if (api_get_setting('show_tabs', 'my_gradebook') == 'true') {
  982. $navigation['mygradebook'] = $possible_tabs['mygradebook'];
  983. } else {
  984. $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
  985. }
  986. }
  987. // Reporting
  988. if (api_get_setting('show_tabs', 'reporting') == 'true') {
  989. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  990. $navigation['session_my_space'] = $possible_tabs['session_my_space'];
  991. } else {
  992. $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  993. }
  994. } else {
  995. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  996. $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
  997. } else {
  998. $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  999. }
  1000. }
  1001. // Social Networking
  1002. if (api_get_setting('show_tabs', 'social') == 'true') {
  1003. if (api_get_setting('allow_social_tool') == 'true') {
  1004. $navigation['social'] = $possible_tabs['social'];
  1005. }
  1006. } else {
  1007. $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  1008. }
  1009. // Dashboard
  1010. if (api_get_setting('show_tabs', 'dashboard') == 'true') {
  1011. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  1012. $navigation['dashboard'] = $possible_tabs['dashboard'];
  1013. }
  1014. } else {
  1015. $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  1016. }
  1017. // Administration
  1018. if (api_is_platform_admin(true)) {
  1019. if (api_get_setting('show_tabs', 'platform_administration') == 'true') {
  1020. $navigation['platform_admin'] = $possible_tabs['platform_admin'];
  1021. } else {
  1022. $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
  1023. }
  1024. }
  1025. if (api_is_question_manager()) {
  1026. $navigation['question_manager'] = $possible_tabs['question_manager'];
  1027. }
  1028. // Reports
  1029. if (!empty($possible_tabs['reports'])) {
  1030. if (api_get_setting('show_tabs', 'reports') == 'true') {
  1031. if ((api_is_platform_admin() || api_is_drh() || api_is_session_admin()) && Rights::hasRight(
  1032. 'show_tabs:reports'
  1033. )
  1034. ) {
  1035. $navigation['reports'] = $possible_tabs['reports'];
  1036. }
  1037. } else {
  1038. $menu_navigation['reports'] = $possible_tabs['reports'];
  1039. }
  1040. }
  1041. // Custom tabs
  1042. for ($i = 1; $i <= 3; $i++) {
  1043. if (api_get_setting('show_tabs', 'custom_tab_'.$i) == 'true') {
  1044. if (isset($possible_tabs['custom_tab_'.$i])) {
  1045. $navigation['custom_tab_'.$i] = $possible_tabs['custom_tab_'.$i];
  1046. }
  1047. } else {
  1048. if (isset($possible_tabs['custom_tab_'.$i])) {
  1049. $menu_navigation['custom_tab_'.$i] = $possible_tabs['custom_tab_'.$i];
  1050. }
  1051. }
  1052. }
  1053. }
  1054. $return = array(
  1055. 'menu_navigation' => $menu_navigation,
  1056. 'navigation' => $navigation,
  1057. 'possible_tabs' => $possible_tabs
  1058. );
  1059. return $return;
  1060. }
  1061. /**
  1062. * Return breadcrumb
  1063. * @return string
  1064. */
  1065. public function returnBreadcrumb()
  1066. {
  1067. $interbreadcrumb = $this->app['breadcrumb'];
  1068. $session_id = api_get_session_id();
  1069. $session_name = api_get_session_name($session_id);
  1070. $_course = api_get_course_info();
  1071. $user_id = api_get_user_id();
  1072. $course_id = api_get_course_id();
  1073. /* Plugins for banner section */
  1074. $web_course_path = api_get_path(WEB_COURSE_PATH);
  1075. /* If the user is a coach he can see the users who are logged in its session */
  1076. $navigation = array();
  1077. // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage
  1078. // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  1079. $session_name = Text::cut($session_name, MAX_LENGTH_BREADCRUMB);
  1080. $my_session_name = is_null($session_name) ? '' : '&nbsp;('.$session_name.')';
  1081. if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) {
  1082. $navigation_item['url'] = $web_course_path.$_course['path'].'/index.php'.(!empty($session_id) ? '?id_session='.$session_id : '');
  1083. $course_title = Text::cut($_course['name'], MAX_LENGTH_BREADCRUMB);
  1084. switch (api_get_setting('breadcrumbs_course_homepage')) {
  1085. case 'get_lang':
  1086. $navigation_item['title'] = Display::img(
  1087. api_get_path(WEB_CSS_PATH).'home.png',
  1088. get_lang('CourseHomepageLink')
  1089. ).' '.get_lang('CourseHomepageLink');
  1090. break;
  1091. case 'course_code':
  1092. $navigation_item['title'] = Display::img(
  1093. api_get_path(WEB_CSS_PATH).'home.png',
  1094. $_course['official_code']
  1095. ).' '.$_course['official_code'];
  1096. break;
  1097. case 'session_name_and_course_title':
  1098. $navigation_item['title'] = Display::img(
  1099. api_get_path(WEB_CSS_PATH).'home.png',
  1100. $_course['name'].$my_session_name
  1101. ).' '.$course_title.$my_session_name;
  1102. break;
  1103. default:
  1104. if (api_get_session_id() != -1) {
  1105. $navigation_item['title'] = Display::img(
  1106. api_get_path(WEB_CSS_PATH).'home.png',
  1107. $_course['name'].$my_session_name
  1108. ).' '.$course_title.$my_session_name;
  1109. } else {
  1110. $navigation_item['title'] = Display::img(
  1111. api_get_path(WEB_CSS_PATH).'home.png',
  1112. $_course['name']
  1113. ).' '.$course_title;
  1114. }
  1115. break;
  1116. }
  1117. $navigation[] = $navigation_item;
  1118. }
  1119. // Part 2: Interbreadcrumbs.
  1120. // If there is an array $interbreadcrumb defined then these have to appear before the last breadcrumb
  1121. // (which is the tool itself)
  1122. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  1123. foreach ($interbreadcrumb as $breadcrumb_step) {
  1124. if ($breadcrumb_step['url'] != '#') {
  1125. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  1126. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  1127. } else {
  1128. $navigation_item['url'] = '#';
  1129. }
  1130. $navigation_item['title'] = $breadcrumb_step['name'];
  1131. // titles for shared folders
  1132. if ($breadcrumb_step['name'] == 'shared_folder') {
  1133. $navigation_item['title'] = get_lang('UserFolders');
  1134. } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
  1135. $navigation_item['title'] = get_lang('UserFolders');
  1136. } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) {
  1137. $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
  1138. $navigation_item['title'] = $userinfo['complete_name'];
  1139. } elseif ($breadcrumb_step['name'] == 'chat_files') {
  1140. $navigation_item['title'] = get_lang('ChatFiles');
  1141. } elseif ($breadcrumb_step['name'] == 'images') {
  1142. $navigation_item['title'] = get_lang('Images');
  1143. } elseif ($breadcrumb_step['name'] == 'video') {
  1144. $navigation_item['title'] = get_lang('Video');
  1145. } elseif ($breadcrumb_step['name'] == 'audio') {
  1146. $navigation_item['title'] = get_lang('Audio');
  1147. } elseif ($breadcrumb_step['name'] == 'flash') {
  1148. $navigation_item['title'] = get_lang('Flash');
  1149. } elseif ($breadcrumb_step['name'] == 'gallery') {
  1150. $navigation_item['title'] = get_lang('Gallery');
  1151. }
  1152. //Fixes breadcrumb title now we applied the Security::remove_XSS and we cut the string depending of the MAX_LENGTH_BREADCRUMB value
  1153. $navigation_item['title'] = Text::cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  1154. $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
  1155. $navigation[] = $navigation_item;
  1156. }
  1157. }
  1158. // part 3: The tool itself. If we are on the course homepage we do not want to display the title of the course because this
  1159. // is the same as the first part of the breadcrumbs (see part 1)
  1160. $final_navigation = array();
  1161. $counter = 0;
  1162. foreach ($navigation as $index => $navigation_info) {
  1163. if (!empty($navigation_info['title'])) {
  1164. if ($navigation_info['url'] == '#') {
  1165. $final_navigation[$index] = $navigation_info['title'];
  1166. } else {
  1167. $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" class="" target="_top">'.$navigation_info['title'].'</a>';
  1168. }
  1169. $counter++;
  1170. }
  1171. }
  1172. $html = '';
  1173. /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
  1174. $view_as_student_link = null;
  1175. if ($user_id && isset($course_id)) {
  1176. if ((api_is_course_admin() || api_is_course_coach() || api_is_platform_admin()) && api_get_setting(
  1177. 'student_view_enabled'
  1178. ) == 'true'
  1179. ) {
  1180. $view_as_student_link = api_display_tool_view_option();
  1181. }
  1182. }
  1183. if (!empty($final_navigation)) {
  1184. $lis = '';
  1185. $i = 0;
  1186. $final_navigation_count = count($final_navigation);
  1187. if (!empty($final_navigation)) {
  1188. // $home_link.= '<span class="divider">/</span>';
  1189. if (!empty($home_link)) {
  1190. $lis .= Display::tag('li', $home_link);
  1191. }
  1192. foreach ($final_navigation as $bread) {
  1193. $bread_check = trim(strip_tags($bread));
  1194. if (!empty($bread_check)) {
  1195. if ($final_navigation_count - 1 > $i) {
  1196. $bread .= '<span class="divider">/</span>';
  1197. }
  1198. $lis .= Display::tag('li', $bread);
  1199. $i++;
  1200. }
  1201. }
  1202. } else {
  1203. if (!empty($home_link)) {
  1204. $lis .= Display::tag('li', $home_link);
  1205. }
  1206. }
  1207. // View as student/teacher link
  1208. if (!empty($view_as_student_link)) {
  1209. $lis .= Display::tag(
  1210. 'li',
  1211. $view_as_student_link,
  1212. array('id' => 'view_as_link', 'class' => 'pull-right')
  1213. );
  1214. }
  1215. if (!empty($lis)) {
  1216. $html .= Display::tag('ul', $lis, array('class' => 'breadcrumb'));
  1217. }
  1218. }
  1219. return $html;
  1220. }
  1221. }