template.lib.php 54 KB

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