template.lib.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  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. $css_file_to_string = null;
  346. foreach ($css as $file) {
  347. $css_file_to_string .= api_get_css($file);
  348. }
  349. // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
  350. if (SHOW_TEXT_NEAR_ICONS == true) {
  351. //hack in order to fix the actions buttons
  352. $css_file_to_string .= '<style>
  353. .td_actions a {
  354. float:left;
  355. width:100%;
  356. }
  357. .forum_message_left a {
  358. float:left;
  359. width:100%;
  360. }
  361. </style>';
  362. }
  363. $navigator_info = api_get_navigator();
  364. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  365. $css_file_to_string .= 'img, div { behavior: url('.api_get_path(
  366. WEB_LIBRARY_PATH
  367. ).'javascript/iepngfix/iepngfix.htc) } '."\n";
  368. }
  369. if (!$disable_js_and_css_files) {
  370. $this->assign('css_file_to_string', $css_file_to_string);
  371. $style_print = api_get_css(api_get_cdn_path($cssPath.$this->theme.'/print.css'), 'print');
  372. $this->assign('css_style_print', $style_print);
  373. }
  374. }
  375. public function addJsFiles($htmlHeadXtra = array())
  376. {
  377. $extra_headers = null;
  378. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  379. foreach ($htmlHeadXtra as $this_html_head) {
  380. $extra_headers .= $this_html_head."\n";
  381. }
  382. }
  383. if (isset($this->app['extraJS'])) {
  384. foreach ($this->app['extraJS'] as $this_html_head) {
  385. $extra_headers .= $this_html_head."\n";
  386. }
  387. }
  388. $this->assign('extra_headers', $extra_headers);
  389. }
  390. /**
  391. * Sets JS files
  392. */
  393. private function setJsFiles()
  394. {
  395. global $disable_js_and_css_files, $htmlHeadXtra;
  396. $jsFolder = api_get_path(WEB_LIBRARY_PATH).'javascript/';
  397. if ($this->app['assetic.enabled']) {
  398. $js_files = array(
  399. api_get_path(WEB_PATH).'web/js/script.js',
  400. $jsFolder.'chosen/chosen.jquery.min.js',
  401. $jsFolder.'thickbox.js',
  402. $jsFolder.'ckeditor/ckeditor.js',
  403. );
  404. } else {
  405. //JS files
  406. $js_files = array(
  407. $jsFolder.'modernizr.js',
  408. $jsFolder.'jquery.min.js',
  409. $jsFolder.'chosen/chosen.jquery.min.js',
  410. $jsFolder.'jquery-ui/'.$this->jquery_ui_theme.'/jquery-ui-custom.min.js',
  411. //$jsFolder.'jquery-ui/jquery.ui.touch-punch.js',
  412. $jsFolder.'thickbox.js',
  413. $jsFolder.'ckeditor/ckeditor.js',
  414. //$jsFolder.'tinymce/tinymce.min.js',
  415. $jsFolder.'bootstrap/bootstrap.js',
  416. );
  417. }
  418. if (api_is_global_chat_enabled()) {
  419. //Do not include the global chat in LP
  420. if ($this->show_learnpath == false && $this->show_footer == true && $this->app['template.hide_global_chat'] == false) {
  421. $js_files[] = $jsFolder.'chat/js/chat.js';
  422. }
  423. }
  424. if (api_get_setting('accessibility_font_resize') == 'true') {
  425. $js_files[] = $jsFolder.'fontresize.js';
  426. }
  427. if (api_get_setting('include_asciimathml_script') == 'true') {
  428. $js_files[] = $jsFolder.'asciimath/ASCIIMathML.js';
  429. }
  430. if (api_get_setting('disable_copy_paste') == 'true') {
  431. $js_files[] = $jsFolder.'jquery.nocutcopypaste.js';
  432. }
  433. $js_file_to_string = null;
  434. foreach ($js_files as $js_file) {
  435. $js_file_to_string .= api_get_js_simple($js_file);
  436. }
  437. // Loading email_editor js.
  438. if (!api_is_anonymous() && api_get_setting('allow_email_editor') == 'true') {
  439. $js_file_to_string .= $this->fetch($this->app['template_style'].'/mail_editor/email_link.js.tpl');
  440. }
  441. if (!$disable_js_and_css_files) {
  442. $this->assign('js_file_to_string', $js_file_to_string);
  443. $extra_headers = null;
  444. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  445. foreach ($htmlHeadXtra as $this_html_head) {
  446. $extra_headers .= $this_html_head."\n";
  447. }
  448. }
  449. if (isset($this->app['extraJS'])) {
  450. foreach ($this->app['extraJS'] as $this_html_head) {
  451. $extra_headers .= $this_html_head."\n";
  452. }
  453. }
  454. $this->assign('extra_headers', $extra_headers);
  455. }
  456. }
  457. /**
  458. * Set header parameters
  459. */
  460. private function setHeaderParameters()
  461. {
  462. $_course = api_get_course_info();
  463. $_configuration = $this->app['configuration'];
  464. $this_section = $this->app['this_section'];
  465. $nameTools = $this->title;
  466. $navigation = $this->navigation_array;
  467. $this->menu_navigation = $navigation['menu_navigation'];
  468. $this->assign('system_charset', api_get_system_encoding());
  469. $this->assign('online_button', Display::return_icon('online.png'));
  470. $this->assign('offline_button', Display::return_icon('offline.png'));
  471. // Get language iso-code for this page - ignore errors
  472. $this->assign('document_language', api_get_language_isocode());
  473. $course_title = isset($_course['name']) ? $_course['name'] : null;
  474. $title_list = array();
  475. $title_list[] = api_get_setting('Institution');
  476. $title_list[] = api_get_setting('siteName');
  477. if (!empty($course_title)) {
  478. $title_list[] = $course_title;
  479. }
  480. if ($nameTools != '') {
  481. $title_list[] = $nameTools;
  482. }
  483. $title_string = '';
  484. for ($i = 0; $i < count($title_list); $i++) {
  485. $title_string .= $title_list[$i];
  486. if (isset($title_list[$i + 1])) {
  487. $item = trim($title_list[$i + 1]);
  488. if (!empty($item)) {
  489. $title_string .= ' - ';
  490. }
  491. }
  492. }
  493. $this->assign('title_string', $title_string);
  494. //Setting the theme and CSS files
  495. $this->setCssFiles();
  496. $this->setJsFiles();
  497. // Implementation of prefetch.
  498. // See http://cdn.chamilo.org/main/img/online.png for details
  499. $prefetch = '';
  500. if (!empty($_configuration['cdn_enable'])) {
  501. $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">';
  502. foreach ($_configuration['cdn'] as $host => $exts) {
  503. $prefetch .= '<link rel="dns-prefetch" href="'.$host.'">';
  504. }
  505. }
  506. $this->assign('prefetch', $prefetch);
  507. $this->assign('text_direction', api_get_text_direction());
  508. $this->assign('section_name', 'section-'.$this_section);
  509. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
  510. if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
  511. $access_url_id = api_get_current_access_url_id();
  512. if ($access_url_id != -1) {
  513. $url_info = api_get_current_access_url_info();
  514. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  515. $clean_url = api_replace_dangerous_char($url);
  516. $clean_url = str_replace('/', '-', $clean_url);
  517. $clean_url .= '/';
  518. $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
  519. $icon_real_homep = api_get_path(SYS_PATH).'home/'.$clean_url;
  520. //we create the new dir for the new sites
  521. if (is_file($icon_real_homep.'favicon.ico')) {
  522. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  523. }
  524. }
  525. }
  526. $this->assign('favico', $favico);
  527. $this->setHelp();
  528. $notification = $this->returnNotificationMenu();
  529. $this->assign('notification_menu', $notification);
  530. // Preparing values for the menu
  531. // Profile link.
  532. $this->assign('is_profile_editable', api_is_profile_readable());
  533. $profile_link = null;
  534. if (api_get_setting('allow_social_tool') == 'true') {
  535. $profile_link = '<a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">'.get_lang('Profile').'</a>';
  536. } else {
  537. if (api_is_profile_readable()) {
  538. $profile_link = '<a href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php">'.get_lang('Profile').'</a>';
  539. }
  540. }
  541. $this->assign('profile_link', $profile_link);
  542. // Message link.
  543. $message_link = null;
  544. if (api_get_setting('allow_message_tool') == 'true') {
  545. $message_link = '<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php">'.get_lang('Inbox').'</a>';
  546. }
  547. $this->assign('message_link', $message_link);
  548. $institution = api_get_setting('Institution');
  549. $portal_name = empty($institution) ? api_get_setting('siteName') : $institution;
  550. $this->assign('portal_name', $portal_name);
  551. // Menu.
  552. $menu = $this->returnMenu();
  553. $this->assign('menu', $menu);
  554. // Breadcrumb
  555. if ($this->loadBreadcrumb) {
  556. $this->loadBreadcrumbToTemplate();
  557. }
  558. // Extra content
  559. $extra_header = null;
  560. if (!api_is_platform_admin()) {
  561. $extra_header = trim(api_get_setting('header_extra_content'));
  562. }
  563. $this->assign('header_extra_content', $extra_header);
  564. }
  565. /**
  566. *
  567. */
  568. public function loadBreadcrumbToTemplate()
  569. {
  570. if (api_get_setting('breadcrumb_navigation_display') == 'false') {
  571. return;
  572. }
  573. $breadcrumb = $this->returnBreadcrumb();
  574. $this->assign('breadcrumb', $breadcrumb);
  575. }
  576. /**
  577. * Set footer parameters
  578. */
  579. private function setFooterParameters()
  580. {
  581. //Show admin data
  582. //$this->assign('show_administrator_data', api_get_setting('show_administrator_data'));
  583. if (api_get_setting('show_administrator_data') == 'true') {
  584. //Administrator name
  585. $administrator_data = get_lang('Manager').' : '.Display::encrypted_mailto_link(
  586. api_get_setting('emailAdministrator'),
  587. api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))
  588. );
  589. $this->assign('administrator_name', $administrator_data);
  590. }
  591. //Loading footer extra content
  592. if (!api_is_platform_admin()) {
  593. $extra_footer = trim(api_get_setting('footer_extra_content'));
  594. if (!empty($extra_footer)) {
  595. $this->assign('footer_extra_content', $extra_footer);
  596. }
  597. }
  598. $courseId = api_get_course_int_id();
  599. //Tutor name
  600. if (api_get_setting('show_tutor_data') == 'true') {
  601. // Course manager
  602. $id_session = api_get_session_id();
  603. if (isset($courseId) && $courseId != -1 && !empty($courseId)) {
  604. $tutor_data = '';
  605. if ($id_session != 0) {
  606. $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $courseId);
  607. $email_link = array();
  608. foreach ($coachs_email as $coach) {
  609. $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
  610. }
  611. if (count($coachs_email) > 1) {
  612. $tutor_data .= get_lang('Coachs').' : ';
  613. $tutor_data .= ArrayClass::array_to_string($email_link, CourseManager::USER_SEPARATOR);
  614. } elseif (count($coachs_email) == 1) {
  615. $tutor_data .= get_lang('Coach').' : ';
  616. $tutor_data .= ArrayClass::array_to_string($email_link, CourseManager::USER_SEPARATOR);
  617. } elseif (count($coachs_email) == 0) {
  618. $tutor_data .= '';
  619. }
  620. }
  621. $this->assign('session_teachers', $tutor_data);
  622. }
  623. }
  624. if (api_get_setting('show_teacher_data') == 'true') {
  625. // course manager
  626. if (isset($courseId) && $courseId != -1 && !empty($courseId)) {
  627. $courseInfo = api_get_course_info();
  628. $teacher_data = null;
  629. $label = get_lang('Teacher');
  630. if (count($courseInfo['teacher_list']) > 1) {
  631. $label = get_lang('Teachers');
  632. }
  633. $teacher_data .= $label.' : '.$courseInfo['teacher_list_formatted'];
  634. $this->assign('teachers', $teacher_data);
  635. }
  636. }
  637. }
  638. public function manageDisplay($content)
  639. {
  640. //$this->assign('content', $content);
  641. }
  642. /**
  643. * Sets the plugin content in a template variable
  644. * @param string
  645. */
  646. private function set_plugin_region($plugin_region)
  647. {
  648. if (!empty($plugin_region)) {
  649. $region_content = $this->plugin->load_region($this->app['plugins'], $plugin_region, $this, $this->force_plugin_load);
  650. if (!empty($region_content)) {
  651. $this->assign('plugin_'.$plugin_region, $region_content);
  652. } else {
  653. $this->assign('plugin_'.$plugin_region, null);
  654. }
  655. }
  656. }
  657. /**
  658. * @param string $template
  659. * @return mixed
  660. */
  661. public function fetch($template = null)
  662. {
  663. $template = $this->app['twig']->loadTemplate($template);
  664. return $template->render(array());
  665. }
  666. public function assign($key, $value = null)
  667. {
  668. if ($this->app['allowed'] == true) {
  669. $this->app['twig']->addGlobal($key, $value);
  670. }
  671. }
  672. public function display($template = null)
  673. {
  674. if (!empty($template)) {
  675. $this->app['default_layout'] = $template;
  676. }
  677. }
  678. /**
  679. * @return null|string
  680. */
  681. public function returnMenu()
  682. {
  683. $navigation = $this->navigation_array;
  684. $navigation = $navigation['navigation'];
  685. // Displaying the tabs
  686. $lang = api_get_user_language();
  687. // Preparing home folder for multiple urls
  688. if (api_get_multiple_access_url()) {
  689. $access_url_id = api_get_current_access_url_id();
  690. if ($access_url_id != -1) {
  691. $url_info = api_get_current_access_url_info();
  692. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  693. $clean_url = api_replace_dangerous_char($url);
  694. $clean_url = str_replace('/', '-', $clean_url);
  695. $clean_url .= '/';
  696. $homep = api_get_path(SYS_DATA_PATH).'home/'.$clean_url; //homep for Home Path
  697. //we create the new dir for the new sites
  698. if (!is_dir($homep)) {
  699. mkdir($homep, api_get_permissions_for_new_directories());
  700. }
  701. }
  702. } else {
  703. $homep = api_get_path(SYS_PATH).'home/';
  704. }
  705. $ext = '.html';
  706. $menutabs = 'home_tabs';
  707. $home_top = '';
  708. if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
  709. $home_top = @(string)file_get_contents($homep.$menutabs.'_'.$lang.$ext);
  710. } elseif (is_file($homep.$menutabs.$lang.$ext) && is_readable($homep.$menutabs.$lang.$ext)) {
  711. $home_top = @(string)file_get_contents($homep.$menutabs.$lang.$ext);
  712. } else {
  713. //$errorMsg = get_lang('HomePageFilesNotReadable');
  714. }
  715. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  716. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top);
  717. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  718. $lis = '';
  719. if (!empty($open)) {
  720. if (strpos($open, 'show_menu') === false) {
  721. if (api_is_anonymous()) {
  722. $navigation[SECTION_CAMPUS] = null;
  723. }
  724. } else {
  725. //$lis .= Display::tag('li', $open);
  726. $lis .= $open;
  727. }
  728. }
  729. if (count($navigation) > 0 || !empty($lis)) {
  730. $pre_lis = '';
  731. foreach ($navigation as $section => $navigation_info) {
  732. if (isset($GLOBALS['this_section'])) {
  733. $current = $section == $GLOBALS['this_section'] ? ' id="current" class="active" ' : '';
  734. } else {
  735. $current = '';
  736. }
  737. if (!empty($navigation_info['title'])) {
  738. $pre_lis .= '<li'.$current.' ><a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a></li>';
  739. }
  740. }
  741. $lis = $pre_lis.$lis;
  742. }
  743. $menu = null;
  744. if (!empty($lis)) {
  745. $menu .= $lis;
  746. }
  747. return $menu;
  748. }
  749. /**
  750. *
  751. * @return string
  752. */
  753. public function getNavigationLinks()
  754. {
  755. // Deleting the myprofile link.
  756. if (api_get_setting('allow_social_tool') == 'true') {
  757. unset($this->menu_navigation['myprofile']);
  758. }
  759. return $this->menu_navigation;
  760. }
  761. // Render Chamilo layouts:
  762. /**
  763. * @param string $layout
  764. * @return mixed
  765. */
  766. public function render_layout($layout = null)
  767. {
  768. if (empty($layout)) {
  769. $layout = $this->app['default_layout'];
  770. }
  771. $this->addJsFiles();
  772. return $this->app['twig']->render($this->app['template_style'].'/layout/'.$layout);
  773. }
  774. /**
  775. * @param string $template
  776. * @param array $elements
  777. * @return mixed
  778. */
  779. public function render_template($template, $elements = array())
  780. {
  781. $this->addJsFiles();
  782. return $this->app['twig']->render($this->app['template_style'].'/'.$template, $elements);
  783. }
  784. /**
  785. * Determines the possible tabs (=sections) that are available.
  786. * This function is used when creating the tabs in the third header line and
  787. * all the sections that do not appear there (as determined by the
  788. * platform admin on the Chamilo configuration settings page)
  789. * will appear in the right hand menu that appears on several other pages
  790. * @return array containing all the possible tabs
  791. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  792. */
  793. public function getTabs()
  794. {
  795. $_course = api_get_course_info();
  796. $navigation = array();
  797. // Campus Homepage
  798. $navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PUBLIC_PATH).'index';
  799. $navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage');
  800. // My Courses
  801. /*
  802. if (api_is_allowed_to_create_course()) {
  803. // Link to my courses for teachers
  804. $navigation['mycourses']['url'] = api_get_path(WEB_PUBLIC_PATH).'user_portal.php?nosession=true';
  805. $navigation['mycourses']['title'] = get_lang('MyCourses');
  806. } else {
  807. // Link to my courses for students
  808. $navigation['mycourses']['url'] = api_get_path(WEB_PUBLIC_PATH).'user_portal.php';
  809. $navigation['mycourses']['title'] = get_lang('MyCourses');
  810. }*/
  811. $navigation['mycourses']['url'] = api_get_path(WEB_PUBLIC_PATH).'userportal';
  812. $navigation['mycourses']['title'] = get_lang('MyCourses');
  813. // My Profile
  814. if (api_is_profile_readable()) {
  815. $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH).'auth/profile.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
  816. $navigation['myprofile']['title'] = get_lang('ModifyProfile');
  817. }
  818. // Link to my agenda
  819. $navigation['myagenda']['url'] = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=personal';
  820. $navigation['myagenda']['title'] = get_lang('MyAgenda');
  821. // Gradebook
  822. if (api_get_setting('gradebook_enable') == 'true') {
  823. $navigation['mygradebook']['url'] = api_get_path(
  824. WEB_CODE_PATH
  825. ).'gradebook/gradebook.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
  826. $navigation['mygradebook']['title'] = get_lang('MyGradebook');
  827. }
  828. // Reporting
  829. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  830. // Link to my space
  831. $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/index.php';
  832. $navigation['session_my_space']['title'] = get_lang('MySpace');
  833. } else {
  834. // Link to my progress
  835. $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH).'auth/my_progress.php';
  836. $navigation['session_my_progress']['title'] = get_lang('MyProgress');
  837. }
  838. // Social
  839. if (api_get_setting('allow_social_tool') == 'true') {
  840. $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
  841. $navigation['social']['title'] = get_lang('SocialNetwork');
  842. }
  843. // Dashboard
  844. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  845. $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
  846. $navigation['dashboard']['title'] = get_lang('Dashboard');
  847. }
  848. // Reports
  849. /*
  850. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  851. $navigation['reports']['url'] = api_get_path(WEB_CODE_PATH).'reports/index.php';
  852. $navigation['reports']['title'] = get_lang('Reports');
  853. }*/
  854. // Custom tabs
  855. for ($i = 1; $i <= 3; $i++) {
  856. if (api_get_setting('custom_tab_'.$i.'_name') && api_get_setting('custom_tab_'.$i.'_url')) {
  857. $navigation['custom_tab_'.$i]['url'] = api_get_setting('custom_tab_'.$i.'_url');
  858. $navigation['custom_tab_'.$i]['title'] = api_get_setting('custom_tab_'.$i.'_name');
  859. }
  860. }
  861. // Platform administration
  862. if (api_is_platform_admin(true)) {
  863. $navigation['platform_admin']['url'] = api_get_path(WEB_CODE_PATH).'admin/index.php';
  864. $navigation['platform_admin']['title'] = get_lang('PlatformAdmin');
  865. } else {
  866. if (api_is_question_manager()) {
  867. $navigation['question_manager']['url'] = api_get_path(WEB_PUBLIC_PATH).'admin/questionmanager';
  868. $navigation['question_manager']['title'] = get_lang('PlatformAdmin');
  869. }
  870. }
  871. return $navigation;
  872. }
  873. /**
  874. * @param string $theme
  875. * @deprecated the logo is wrote in the main_header.tpl file
  876. * @return string
  877. */
  878. public function returnLogo($theme)
  879. {
  880. $_course = api_get_course_info();
  881. $html = '';
  882. $logo = api_get_path(SYS_CODE_PATH).'css/'.$theme.'/images/header-logo.png';
  883. $site_name = api_get_setting('siteName');
  884. if (file_exists($logo)) {
  885. $site_name = api_get_setting('Institution').' - '.$site_name;
  886. $html .= '<div id="logo">';
  887. $image_url = api_get_path(WEB_CSS_PATH).$theme.'/images/header-logo.png';
  888. $logo = Display::img($image_url, $site_name, array('title' => $site_name));
  889. $html .= Display::url($logo, api_get_path(WEB_PATH).'index.php');
  890. $html .= '</div>';
  891. } else {
  892. $html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$site_name.'</a>';
  893. $iurl = api_get_setting('InstitutionUrl');
  894. $iname = api_get_setting('Institution');
  895. if (!empty($iname)) {
  896. $html .= '-&nbsp;<a href="'.$iurl.'" target="_top">'.$iname.'</a>';
  897. }
  898. // External link section a.k.a Department - Department URL
  899. if (isset($_course['extLink']) && $_course['extLink']['name'] != '') {
  900. $html .= '<span class="extLinkSeparator"> - </span>';
  901. if ($_course['extLink']['url'] != '') {
  902. $html .= '<a class="extLink" href="'.$_course['extLink']['url'].'" target="_top">';
  903. $html .= $_course['extLink']['name'];
  904. $html .= '</a>';
  905. } else {
  906. $html .= $_course['extLink']['name'];
  907. }
  908. }
  909. }
  910. return $html;
  911. }
  912. /**
  913. * @return string
  914. */
  915. public function returnNotificationMenu()
  916. {
  917. $_course = api_get_course_info();
  918. $course_id = api_get_course_id();
  919. $user_id = api_get_user_id();
  920. $html = '';
  921. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting(
  922. 'showonline',
  923. 'users'
  924. ) == 'true' AND $user_id) OR (api_get_setting('showonline', 'course') == 'true' AND $user_id AND $course_id)
  925. ) {
  926. $number = Online::who_is_online_count(api_get_setting('time_limit_whosonline'));
  927. $number_online_in_course = 0;
  928. if (!empty($_course['id'])) {
  929. $number_online_in_course = Online::who_is_online_in_this_course_count(
  930. $user_id,
  931. api_get_setting('time_limit_whosonline'),
  932. $_course['id']
  933. );
  934. }
  935. // Display the who's online of the platform
  936. if ($number) {
  937. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting(
  938. 'showonline',
  939. 'users'
  940. ) == 'true' AND $user_id)
  941. ) {
  942. $html .= '<li><a href="'.SocialManager::getUserOnlineLink().'" target="_top" title="'.get_lang(
  943. 'UsersOnline'
  944. ).'" >'.
  945. Display::return_icon(
  946. 'user.png',
  947. get_lang('UsersOnline'),
  948. array(),
  949. ICON_SIZE_TINY
  950. ).' '.$number.'</a></li>';
  951. }
  952. }
  953. // Display the who's online for the course
  954. if ($number_online_in_course) {
  955. if (is_array($_course) AND api_get_setting(
  956. 'showonline',
  957. 'course'
  958. ) == 'true' AND isset($_course['sysCode'])
  959. ) {
  960. $html .= '<li><a href="'.SocialManager::getUserOnlineLink($_course['sysCode']).'" target="_top">'.
  961. Display::return_icon(
  962. 'course.png',
  963. get_lang('UsersOnline').' '.get_lang('InThisCourse'),
  964. array(),
  965. ICON_SIZE_TINY
  966. ).' '.$number_online_in_course.' </a></li>';
  967. }
  968. }
  969. // Display the who's online for the session
  970. if (api_get_setting('showonline', 'session') == 'true') {
  971. if (isset($user_id) && api_get_session_id() != 0) {
  972. if (api_is_allowed_to_edit()) {
  973. $html .= '<li><a href="'.SocialManager::getUserOnlineLink(null, api_get_session_id()).'&id_coach='.$user_id.'" >'.
  974. Display::return_icon(
  975. 'session.png',
  976. get_lang('UsersConnectedToMySessions'),
  977. array(),
  978. ICON_SIZE_TINY
  979. ).' </a></li>';
  980. }
  981. }
  982. }
  983. }
  984. if (api_get_setting('accessibility_font_resize') == 'true') {
  985. $html .= '<li class="resize_font">';
  986. $html .= '<span class="decrease_font" title="'.get_lang(
  987. 'DecreaseFontSize'
  988. ).'">A</span> <span class="reset_font" title="'.get_lang(
  989. 'ResetFontSize'
  990. ).'">A</span> <span class="increase_font" title="'.get_lang('IncreaseFontSize').'">A</span>';
  991. $html .= '</li>';
  992. }
  993. return $html;
  994. }
  995. /**
  996. * Gets the main menu
  997. *
  998. * @return array
  999. */
  1000. public function returnNavigationArray()
  1001. {
  1002. $navigation = array();
  1003. $menu_navigation = array();
  1004. $possible_tabs = $this->getTabs();
  1005. // Campus Homepage
  1006. if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
  1007. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  1008. } else {
  1009. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  1010. }
  1011. if (api_get_user_id() && !api_is_anonymous()) {
  1012. // My Courses
  1013. if (api_get_setting('show_tabs', 'my_courses') == 'true') {
  1014. $navigation['mycourses'] = $possible_tabs['mycourses'];
  1015. } else {
  1016. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  1017. }
  1018. // My Profile
  1019. if (api_get_setting('show_tabs', 'my_profile') == 'true' && api_get_setting('allow_social_tool') != 'true') {
  1020. if (isset($possible_tabs['myprofile'])) {
  1021. $navigation['myprofile'] = $possible_tabs['myprofile'];
  1022. }
  1023. } else {
  1024. if (isset($possible_tabs['myprofile'])) {
  1025. $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
  1026. }
  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. }