template.lib.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  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. /** @var Symfony\Component\Security\Core\SecurityContext */
  30. private $security;
  31. /**
  32. * @param Application $app
  33. */
  34. public function __construct(Application $app, $database, $security)
  35. {
  36. $this->app = &$app;
  37. $this->security = $security;
  38. $this->app['classic_layout'] = true;
  39. $this->navigation_array = $this->returnNavigationArray();
  40. // Just in case
  41. global $tool_name;
  42. // Page title
  43. $this->title = isset($app['title']) ? $app['title'] : $tool_name;
  44. $this->show_learnpath = $app['template.show_learnpath'];
  45. /* Current themes: cupertino, smoothness, ui-lightness.
  46. Find the themes folder in main/inc/lib/javascript/jquery-ui */
  47. $this->jquery_ui_theme = 'smoothness';
  48. // Setting system variables.
  49. $this->setSystemParameters();
  50. // Setting user variables.
  51. $this->setUserParameters();
  52. // Setting course variables.
  53. $this->setCourseParameters();
  54. // header and footer are showed by default
  55. $this->setFooter($app['template.show_footer']);
  56. $this->setHeader($app['template.show_header']);
  57. $this->setHeaderParameters();
  58. $this->setFooterParameters();
  59. $this->assign('style', $app['template_style']);
  60. //Chamilo plugins
  61. if ($this->show_header) {
  62. if ($app['template.load_plugins'] && !empty($app['plugins'])) {
  63. $this->plugin = new AppPlugin();
  64. //1. Showing installed plugins in regions
  65. $plugin_regions = $this->plugin->get_plugin_regions();
  66. foreach ($plugin_regions as $region) {
  67. $this->set_plugin_region($region);
  68. }
  69. //2. Loading the course plugin info
  70. global $course_plugin;
  71. if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
  72. //Load plugin get_langs
  73. $this->plugin->load_plugin_lang_variables($course_plugin);
  74. }
  75. }
  76. }
  77. }
  78. /**
  79. * @param array $interbreadcrumb
  80. */
  81. public function setBreadcrumb($interbreadcrumb)
  82. {
  83. if (isset($this->app['breadcrumb']) && !empty($this->app['breadcrumb'])) {
  84. if (empty($interbreadcrumb)) {
  85. $interbreadcrumb = $this->app['breadcrumb'];
  86. } else {
  87. $interbreadcrumb = array_merge($interbreadcrumb, $this->app['breadcrumb']);
  88. }
  89. }
  90. if (!empty($interbreadcrumb)) {
  91. $this->app['breadcrumb'] = $interbreadcrumb;
  92. }
  93. }
  94. /**
  95. * Get icon path
  96. * @param string $image
  97. * @param int $size
  98. *
  99. * @return string
  100. */
  101. public static function get_icon_path($image, $size = ICON_SIZE_SMALL)
  102. {
  103. return Display:: return_icon($image, '', array(), $size, false, true);
  104. }
  105. /**
  106. * Format date
  107. * @param string $timestamp
  108. * @param string $format
  109. *
  110. * @return string
  111. */
  112. public static function format_date($timestamp, $format = null)
  113. {
  114. return api_format_date($timestamp, $format);
  115. }
  116. /**
  117. * @param string $help_input
  118. */
  119. public function setHelp($help_input = null)
  120. {
  121. if (!empty($help_input)) {
  122. $help = $help_input;
  123. } else {
  124. $help = $this->help;
  125. }
  126. $this->assign('help_content', $help);
  127. }
  128. /**
  129. * Use template system to parse the actions menu
  130. * @todo finish it!
  131. * @param array $actions
  132. *
  133. **/
  134. public function setActions($actions)
  135. {
  136. $action_string = '';
  137. if (!empty($actions)) {
  138. foreach ($actions as $action) {
  139. $action_string .= $action;
  140. }
  141. }
  142. $this->assign('actions', $actions);
  143. }
  144. /**
  145. * Shortcut to display a 1 col layout (index.php)
  146. * */
  147. public function display_one_col_template()
  148. {
  149. $tpl = $this->get_template('layout/layout_1_col.tpl');
  150. $this->display($tpl);
  151. }
  152. /**
  153. * Shortcut to display a 2 col layout (userportal.php)
  154. * */
  155. public function display_two_col_template()
  156. {
  157. $tpl = $this->get_template('layout/layout_2_col.tpl');
  158. $this->display($tpl);
  159. }
  160. /**
  161. * Displays an empty template
  162. */
  163. public function display_blank_template()
  164. {
  165. $tpl = $this->get_template('layout/blank.tpl');
  166. $this->display($tpl);
  167. }
  168. /**
  169. * Displays an empty template
  170. */
  171. public function display_no_layout_template()
  172. {
  173. $tpl = $this->get_template('layout/no_layout.tpl');
  174. $this->display($tpl);
  175. }
  176. /**
  177. * Sets the footer visibility
  178. * @param bool true if we show the footer
  179. */
  180. public function setFooter($status)
  181. {
  182. $this->show_footer = $status;
  183. $this->assign('show_footer', $status);
  184. }
  185. /**
  186. * Sets the header visibility
  187. * @param bool true if we show the header
  188. */
  189. public function setHeader($status)
  190. {
  191. $this->show_header = $status;
  192. $this->assign('show_header', $status);
  193. //Toolbar
  194. $show_admin_toolbar = api_get_setting('show_admin_toolbar');
  195. $show_toolbar = 0;
  196. switch ($show_admin_toolbar) {
  197. case 'do_not_show':
  198. break;
  199. case 'show_to_admin':
  200. if (api_is_platform_admin()) {
  201. $show_toolbar = 1;
  202. }
  203. break;
  204. case 'show_to_admin_and_teachers':
  205. if (api_is_platform_admin() || api_is_allowed_to_edit()) {
  206. $show_toolbar = 1;
  207. }
  208. break;
  209. case 'show_to_all':
  210. $show_toolbar = 1;
  211. break;
  212. }
  213. $this->assign('show_toolbar', $show_toolbar);
  214. //Only if course is available
  215. $show_course_shortcut = null;
  216. $show_course_navigation_menu = null;
  217. if (!empty($this->course_id) && $this->user_is_logged_in) {
  218. if (api_get_setting('show_toolshortcuts') != 'false') {
  219. //Course toolbar
  220. $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts();
  221. }
  222. if (api_get_setting('show_navigation_menu') != 'false') {
  223. //Course toolbar
  224. $show_course_navigation_menu = CourseHome::show_navigation_menu();
  225. }
  226. }
  227. $this->assign('show_course_shortcut', $show_course_shortcut);
  228. $this->assign('show_course_navigation_menu', $show_course_navigation_menu);
  229. }
  230. /**
  231. * @param string $name
  232. * @return string
  233. */
  234. public function get_template($name)
  235. {
  236. return $this->app['template_style'].'/'.$name;
  237. }
  238. /** Set course parameters */
  239. private function setCourseParameters()
  240. {
  241. //Setting course id
  242. $this->course_id = api_get_course_int_id();
  243. $this->app['course_code'] = api_get_course_id();
  244. $this->app['session_id'] = api_get_session_id();
  245. }
  246. /**
  247. * Set user parameters
  248. */
  249. private function setUserParameters()
  250. {
  251. $user_info = array();
  252. $user_info['logged'] = 0;
  253. $this->user_is_logged_in = false;
  254. $user_info = isset($this->app['current_user']) ? $this->app['current_user'] : null;
  255. if (api_user_is_login() && !empty($user_info)) {
  256. $user_info['logged'] = 1;
  257. $user_info['is_admin'] = 0;
  258. if (api_is_platform_admin()) {
  259. $user_info['is_admin'] = 1;
  260. }
  261. $new_messages = MessageManager::get_new_messages();
  262. $user_info['messages_count'] = $new_messages != 0 ? Display::label($new_messages, 'warning') : null;
  263. /*$usergroup = new UserGroup();
  264. $messages_invitations_count = $usergroup->get_groups_by_user_count($user_info['user_id'], GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  265. $user_info['messages_invitations_count'] = $messages_invitations_count != 0 ? Display::label(
  266. $messages_invitations_count,
  267. 'warning'
  268. ) : null;*/
  269. $this->user_is_logged_in = true;
  270. }
  271. //Setting the $_u array that could be use in any template
  272. $this->assign('_u', $user_info);
  273. }
  274. /**
  275. * Set system parameters
  276. */
  277. private function setSystemParameters()
  278. {
  279. global $_configuration;
  280. //Setting app paths/URLs
  281. $_p = array(
  282. 'web' => api_get_path(WEB_PATH),
  283. 'web_course' => api_get_path(WEB_COURSE_PATH),
  284. 'web_main' => api_get_path(WEB_CODE_PATH),
  285. 'web_css' => api_get_path(WEB_CSS_PATH),
  286. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  287. 'web_img' => api_get_path(WEB_IMG_PATH),
  288. 'web_plugin' => api_get_path(WEB_PLUGIN_PATH),
  289. 'web_lib' => api_get_path(WEB_LIBRARY_PATH),
  290. 'public_web' => api_get_path(WEB_PUBLIC_PATH)
  291. );
  292. $this->assign('_p', $_p);
  293. //Here we can add system parameters that can be use in any template
  294. $_s = array(
  295. 'software_name' => api_get_software_name(),
  296. 'system_version' => $_configuration['system_version'],
  297. 'site_name' => api_get_setting('siteName'),
  298. 'institution' => api_get_setting('Institution')
  299. );
  300. $this->assign('_s', $_s);
  301. }
  302. /**
  303. * Set theme, include CSS files
  304. */
  305. private function setCssFiles()
  306. {
  307. global $disable_js_and_css_files;
  308. $css = array();
  309. $this->theme = api_get_visual_theme();
  310. if (isset($_POST['style']) && api_is_platform_admin()) {
  311. $this->preview_theme = $_POST['style'];
  312. }
  313. if (!empty($this->preview_theme)) {
  314. $this->theme = $this->preview_theme;
  315. }
  316. $this->app['theme'] = $this->theme;
  317. $cssPath = api_get_path(WEB_CSS_PATH);
  318. // Loads only 1 css file
  319. if ($this->app['assetic.enabled']) {
  320. $css[] = api_get_path(WEB_PUBLIC_PATH).'css/'.$this->theme.'/style.css';
  321. } else {
  322. // Base CSS.
  323. $css[] = api_get_cdn_path($cssPath.'base.css');
  324. // Default theme CSS.
  325. $css[] = api_get_cdn_path($cssPath.$this->theme.'/default.css');
  326. $css[] = api_get_cdn_path($cssPath.'bootstrap-responsive.css');
  327. $css[] = api_get_cdn_path($cssPath.'responsive.css');
  328. // Extra CSS files.
  329. if ($this->show_learnpath) {
  330. $css[] = $cssPath.$this->theme.'/learnpath.css';
  331. $css[] = $cssPath.$this->theme.'/scorm.css';
  332. }
  333. if (api_is_global_chat_enabled()) {
  334. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chat/css/chat.css';
  335. }
  336. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/'.$this->jquery_ui_theme.'/jquery-ui-custom.css';
  337. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/default.css';
  338. }
  339. $css[] = api_get_cdn_path($cssPath.'font_awesome/css/font-awesome.css');
  340. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css';
  341. $css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
  342. $css_file_to_string = null;
  343. foreach ($css as $file) {
  344. $css_file_to_string .= api_get_css($file);
  345. }
  346. // @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
  347. if (SHOW_TEXT_NEAR_ICONS == true) {
  348. //hack in order to fix the actions buttons
  349. $css_file_to_string .= '<style>
  350. .td_actions a {
  351. float:left;
  352. width:100%;
  353. }
  354. .forum_message_left a {
  355. float:left;
  356. width:100%;
  357. }
  358. </style>';
  359. }
  360. $navigator_info = api_get_navigator();
  361. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  362. $css_file_to_string .= 'img, div { behavior: url('.api_get_path(
  363. WEB_LIBRARY_PATH
  364. ).'javascript/iepngfix/iepngfix.htc) } '."\n";
  365. }
  366. if (!$disable_js_and_css_files) {
  367. $this->assign('css_file_to_string', $css_file_to_string);
  368. $style_print = api_get_css(api_get_cdn_path($cssPath.$this->theme.'/print.css'), 'print');
  369. $this->assign('css_style_print', $style_print);
  370. }
  371. }
  372. /**
  373. * @param array $htmlHeadXtra
  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. /**
  762. * @param string $layout
  763. * @return mixed
  764. */
  765. public function render_layout($layout = null)
  766. {
  767. if (empty($layout)) {
  768. $layout = $this->app['default_layout'];
  769. }
  770. $this->addJsFiles();
  771. return $this->app['twig']->render($this->app['template_style'].'/layout/'.$layout);
  772. }
  773. /**
  774. * @param string $template
  775. * @param array $elements
  776. * @return mixed
  777. */
  778. public function render_template($template, $elements = array())
  779. {
  780. $this->addJsFiles();
  781. return $this->app['twig']->render($this->app['template_style'].'/'.$template, $elements);
  782. }
  783. /**
  784. * Determines the possible tabs (=sections) that are available.
  785. * This function is used when creating the tabs in the third header line and
  786. * all the sections that do not appear there (as determined by the
  787. * platform admin on the Chamilo configuration settings page)
  788. * will appear in the right hand menu that appears on several other pages
  789. * @return array containing all the possible tabs
  790. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  791. */
  792. public function getTabs()
  793. {
  794. $_course = api_get_course_info();
  795. $navigation = array();
  796. // Campus Homepage
  797. $navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PUBLIC_PATH).'index';
  798. $navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage');
  799. // My Courses
  800. $navigation['mycourses']['url'] = api_get_path(WEB_PUBLIC_PATH).'userportal';
  801. $navigation['mycourses']['title'] = get_lang('MyCourses');
  802. // My Profile
  803. if (api_is_profile_readable()) {
  804. $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH).'auth/profile.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
  805. $navigation['myprofile']['title'] = get_lang('ModifyProfile');
  806. }
  807. // Link to my agenda
  808. $navigation['myagenda']['url'] = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=personal';
  809. $navigation['myagenda']['title'] = get_lang('MyAgenda');
  810. // Gradebook
  811. if (api_get_setting('gradebook_enable') == 'true') {
  812. $navigation['mygradebook']['url'] = api_get_path(
  813. WEB_CODE_PATH
  814. ).'gradebook/gradebook.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
  815. $navigation['mygradebook']['title'] = get_lang('MyGradebook');
  816. }
  817. // Reporting
  818. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  819. // Link to my space
  820. $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/index.php';
  821. $navigation['session_my_space']['title'] = get_lang('MySpace');
  822. } else {
  823. // Link to my progress
  824. $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH).'auth/my_progress.php';
  825. $navigation['session_my_progress']['title'] = get_lang('MyProgress');
  826. }
  827. // Social
  828. if (api_get_setting('allow_social_tool') == 'true') {
  829. $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
  830. $navigation['social']['title'] = get_lang('SocialNetwork');
  831. }
  832. // Dashboard
  833. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  834. $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
  835. $navigation['dashboard']['title'] = get_lang('Dashboard');
  836. }
  837. // Custom tabs
  838. for ($i = 1; $i <= 3; $i++) {
  839. if (api_get_setting('custom_tab_'.$i.'_name') && api_get_setting('custom_tab_'.$i.'_url')) {
  840. $navigation['custom_tab_'.$i]['url'] = api_get_setting('custom_tab_'.$i.'_url');
  841. $navigation['custom_tab_'.$i]['title'] = api_get_setting('custom_tab_'.$i.'_name');
  842. }
  843. }
  844. // Adding block settings for each role
  845. if (isset($this->app['allow_admin_toolbar'])) {
  846. $roleTemplate = array();
  847. foreach ($this->app['allow_admin_toolbar'] as $role) {
  848. if ($this->security->getToken() && $this->security->isGranted($role)) {
  849. // Fixes in order to match the templates
  850. if ($role == 'ROLE_ADMIN') {
  851. $role = 'administrator';
  852. }
  853. if ($role == 'ROLE_QUESTION_MANAGER') {
  854. $role = 'QUESTIONMANAGER';
  855. }
  856. $stripRole = strtolower(str_replace('ROLE_', '', $role));
  857. $roleTemplate[] = $stripRole;
  858. }
  859. }
  860. if (!empty($roleTemplate)) {
  861. if (api_get_setting('show_tabs', 'platform_administration') == 'true') {
  862. $navigation['admin']['url'] = api_get_path(WEB_PUBLIC_PATH).'admin';
  863. $navigation['admin']['title'] = get_lang('PlatformAdmin');
  864. }
  865. }
  866. $this->app['admin_toolbar_roles'] = $roleTemplate;
  867. }
  868. return $navigation;
  869. }
  870. /**
  871. * @param string $theme
  872. * @deprecated the logo is wrote in the main_header.tpl file
  873. * @return string
  874. */
  875. public function returnLogo($theme)
  876. {
  877. $_course = api_get_course_info();
  878. $html = '';
  879. $logo = api_get_path(SYS_CODE_PATH).'css/'.$theme.'/images/header-logo.png';
  880. $site_name = api_get_setting('siteName');
  881. if (file_exists($logo)) {
  882. $site_name = api_get_setting('Institution').' - '.$site_name;
  883. $html .= '<div id="logo">';
  884. $image_url = api_get_path(WEB_CSS_PATH).$theme.'/images/header-logo.png';
  885. $logo = Display::img($image_url, $site_name, array('title' => $site_name));
  886. $html .= Display::url($logo, api_get_path(WEB_PATH).'index.php');
  887. $html .= '</div>';
  888. } else {
  889. $html .= '<a href="'.api_get_path(WEB_PATH).'index.php" target="_top">'.$site_name.'</a>';
  890. $iurl = api_get_setting('InstitutionUrl');
  891. $iname = api_get_setting('Institution');
  892. if (!empty($iname)) {
  893. $html .= '-&nbsp;<a href="'.$iurl.'" target="_top">'.$iname.'</a>';
  894. }
  895. // External link section a.k.a Department - Department URL
  896. if (isset($_course['extLink']) && $_course['extLink']['name'] != '') {
  897. $html .= '<span class="extLinkSeparator"> - </span>';
  898. if ($_course['extLink']['url'] != '') {
  899. $html .= '<a class="extLink" href="'.$_course['extLink']['url'].'" target="_top">';
  900. $html .= $_course['extLink']['name'];
  901. $html .= '</a>';
  902. } else {
  903. $html .= $_course['extLink']['name'];
  904. }
  905. }
  906. }
  907. return $html;
  908. }
  909. /**
  910. * @return string
  911. */
  912. public function returnNotificationMenu()
  913. {
  914. $_course = api_get_course_info();
  915. $course_id = api_get_course_id();
  916. $user_id = api_get_user_id();
  917. $html = '';
  918. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting(
  919. 'showonline',
  920. 'users'
  921. ) == 'true' AND $user_id) OR (api_get_setting('showonline', 'course') == 'true' AND $user_id AND $course_id)
  922. ) {
  923. $number = Online::who_is_online_count(api_get_setting('time_limit_whosonline'));
  924. $number_online_in_course = 0;
  925. if (!empty($_course['id'])) {
  926. $number_online_in_course = Online::who_is_online_in_this_course_count(
  927. $user_id,
  928. api_get_setting('time_limit_whosonline'),
  929. $_course['id']
  930. );
  931. }
  932. // Display the who's online of the platform
  933. if ($number) {
  934. if ((api_get_setting('showonline', 'world') == 'true' AND !$user_id) OR (api_get_setting(
  935. 'showonline',
  936. 'users'
  937. ) == 'true' AND $user_id)
  938. ) {
  939. $html .= '<li><a href="'.SocialManager::getUserOnlineLink().'" target="_top" title="'.get_lang(
  940. 'UsersOnline'
  941. ).'" >'.
  942. Display::return_icon(
  943. 'user.png',
  944. get_lang('UsersOnline'),
  945. array(),
  946. ICON_SIZE_TINY
  947. ).' '.$number.'</a></li>';
  948. }
  949. }
  950. // Display the who's online for the course
  951. if ($number_online_in_course) {
  952. if (is_array($_course) AND api_get_setting(
  953. 'showonline',
  954. 'course'
  955. ) == 'true' AND isset($_course['sysCode'])
  956. ) {
  957. $html .= '<li><a href="'.SocialManager::getUserOnlineLink($_course['sysCode']).'" target="_top">'.
  958. Display::return_icon(
  959. 'course.png',
  960. get_lang('UsersOnline').' '.get_lang('InThisCourse'),
  961. array(),
  962. ICON_SIZE_TINY
  963. ).' '.$number_online_in_course.' </a></li>';
  964. }
  965. }
  966. // Display the who's online for the session
  967. if (api_get_setting('showonline', 'session') == 'true') {
  968. if (isset($user_id) && api_get_session_id() != 0) {
  969. if (api_is_allowed_to_edit()) {
  970. $html .= '<li><a href="'.SocialManager::getUserOnlineLink(null, api_get_session_id()).'&id_coach='.$user_id.'" >'.
  971. Display::return_icon(
  972. 'session.png',
  973. get_lang('UsersConnectedToMySessions'),
  974. array(),
  975. ICON_SIZE_TINY
  976. ).' </a></li>';
  977. }
  978. }
  979. }
  980. }
  981. if (api_get_setting('accessibility_font_resize') == 'true') {
  982. $html .= '<li class="resize_font">';
  983. $html .= '<span class="decrease_font" title="'.get_lang(
  984. 'DecreaseFontSize'
  985. ).'">A</span> <span class="reset_font" title="'.get_lang(
  986. 'ResetFontSize'
  987. ).'">A</span> <span class="increase_font" title="'.get_lang('IncreaseFontSize').'">A</span>';
  988. $html .= '</li>';
  989. }
  990. return $html;
  991. }
  992. /**
  993. * Gets the main menu
  994. *
  995. * @return array
  996. */
  997. public function returnNavigationArray()
  998. {
  999. $navigation = array();
  1000. $menu_navigation = array();
  1001. $possible_tabs = $this->getTabs();
  1002. // Campus Homepage
  1003. if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
  1004. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  1005. } else {
  1006. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  1007. }
  1008. if (api_get_user_id() && !api_is_anonymous()) {
  1009. // My Courses
  1010. if (api_get_setting('show_tabs', 'my_courses') == 'true') {
  1011. $navigation['mycourses'] = $possible_tabs['mycourses'];
  1012. } else {
  1013. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  1014. }
  1015. // My Profile
  1016. if (api_get_setting('show_tabs', 'my_profile') == 'true' && api_get_setting('allow_social_tool') != 'true') {
  1017. if (isset($possible_tabs['myprofile'])) {
  1018. $navigation['myprofile'] = $possible_tabs['myprofile'];
  1019. }
  1020. } else {
  1021. if (isset($possible_tabs['myprofile'])) {
  1022. $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
  1023. }
  1024. }
  1025. // My Agenda
  1026. if (api_get_setting('show_tabs', 'my_agenda') == 'true') {
  1027. $navigation['myagenda'] = $possible_tabs['myagenda'];
  1028. } else {
  1029. $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
  1030. }
  1031. // Gradebook
  1032. if (api_get_setting('gradebook_enable') == 'true') {
  1033. if (api_get_setting('show_tabs', 'my_gradebook') == 'true') {
  1034. $navigation['mygradebook'] = $possible_tabs['mygradebook'];
  1035. } else {
  1036. $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
  1037. }
  1038. }
  1039. // Reporting
  1040. if (api_get_setting('show_tabs', 'reporting') == 'true') {
  1041. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  1042. $navigation['session_my_space'] = $possible_tabs['session_my_space'];
  1043. } else {
  1044. $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  1045. }
  1046. } else {
  1047. if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
  1048. $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
  1049. } else {
  1050. $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  1051. }
  1052. }
  1053. // Social Networking
  1054. if (api_get_setting('show_tabs', 'social') == 'true') {
  1055. if (api_get_setting('allow_social_tool') == 'true') {
  1056. $navigation['social'] = $possible_tabs['social'];
  1057. }
  1058. } else {
  1059. $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  1060. }
  1061. // Dashboard
  1062. if (api_get_setting('show_tabs', 'dashboard') == 'true') {
  1063. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  1064. $navigation['dashboard'] = $possible_tabs['dashboard'];
  1065. }
  1066. } else {
  1067. $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  1068. }
  1069. if (isset($possible_tabs['admin'])) {
  1070. $navigation['platform_admin'] = $possible_tabs['admin'];
  1071. $navigation['platform_admin'] = $possible_tabs['admin'];
  1072. }
  1073. // Reports
  1074. if (!empty($possible_tabs['reports'])) {
  1075. if (api_get_setting('show_tabs', 'reports') == 'true') {
  1076. if ((api_is_platform_admin() || api_is_drh() || api_is_session_admin()) && Rights::hasRight(
  1077. 'show_tabs:reports'
  1078. )
  1079. ) {
  1080. $navigation['reports'] = $possible_tabs['reports'];
  1081. }
  1082. } else {
  1083. $menu_navigation['reports'] = $possible_tabs['reports'];
  1084. }
  1085. }
  1086. // Custom tabs
  1087. for ($i = 1; $i <= 3; $i++) {
  1088. if (api_get_setting('show_tabs', 'custom_tab_'.$i) == 'true') {
  1089. if (isset($possible_tabs['custom_tab_'.$i])) {
  1090. $navigation['custom_tab_'.$i] = $possible_tabs['custom_tab_'.$i];
  1091. }
  1092. } else {
  1093. if (isset($possible_tabs['custom_tab_'.$i])) {
  1094. $menu_navigation['custom_tab_'.$i] = $possible_tabs['custom_tab_'.$i];
  1095. }
  1096. }
  1097. }
  1098. }
  1099. $return = array(
  1100. 'menu_navigation' => $menu_navigation,
  1101. 'navigation' => $navigation,
  1102. 'possible_tabs' => $possible_tabs
  1103. );
  1104. return $return;
  1105. }
  1106. /**
  1107. * Return breadcrumb
  1108. * @return string
  1109. */
  1110. public function returnBreadcrumb()
  1111. {
  1112. $interbreadcrumb = $this->app['breadcrumb'];
  1113. $session_id = api_get_session_id();
  1114. $session_name = api_get_session_name($session_id);
  1115. $_course = api_get_course_info();
  1116. $user_id = api_get_user_id();
  1117. $course_id = api_get_course_id();
  1118. /* Plugins for banner section */
  1119. $web_course_path = api_get_path(WEB_COURSE_PATH);
  1120. /* If the user is a coach he can see the users who are logged in its session */
  1121. $navigation = array();
  1122. // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage
  1123. // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  1124. $session_name = Text::cut($session_name, MAX_LENGTH_BREADCRUMB);
  1125. $my_session_name = is_null($session_name) ? '' : '&nbsp;('.$session_name.')';
  1126. if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) {
  1127. $navigation_item['url'] = $web_course_path.$_course['path'].'/index.php'.(!empty($session_id) ? '?id_session='.$session_id : '');
  1128. $course_title = Text::cut($_course['name'], MAX_LENGTH_BREADCRUMB);
  1129. switch (api_get_setting('breadcrumbs_course_homepage')) {
  1130. case 'get_lang':
  1131. $navigation_item['title'] = Display::img(
  1132. api_get_path(WEB_CSS_PATH).'home.png',
  1133. get_lang('CourseHomepageLink')
  1134. ).' '.get_lang('CourseHomepageLink');
  1135. break;
  1136. case 'course_code':
  1137. $navigation_item['title'] = Display::img(
  1138. api_get_path(WEB_CSS_PATH).'home.png',
  1139. $_course['official_code']
  1140. ).' '.$_course['official_code'];
  1141. break;
  1142. case 'session_name_and_course_title':
  1143. $navigation_item['title'] = Display::img(
  1144. api_get_path(WEB_CSS_PATH).'home.png',
  1145. $_course['name'].$my_session_name
  1146. ).' '.$course_title.$my_session_name;
  1147. break;
  1148. default:
  1149. if (api_get_session_id() != -1) {
  1150. $navigation_item['title'] = Display::img(
  1151. api_get_path(WEB_CSS_PATH).'home.png',
  1152. $_course['name'].$my_session_name
  1153. ).' '.$course_title.$my_session_name;
  1154. } else {
  1155. $navigation_item['title'] = Display::img(
  1156. api_get_path(WEB_CSS_PATH).'home.png',
  1157. $_course['name']
  1158. ).' '.$course_title;
  1159. }
  1160. break;
  1161. }
  1162. $navigation[] = $navigation_item;
  1163. }
  1164. // Part 2: Interbreadcrumbs.
  1165. // If there is an array $interbreadcrumb defined then these have to appear before the last breadcrumb
  1166. // (which is the tool itself)
  1167. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  1168. foreach ($interbreadcrumb as $breadcrumb_step) {
  1169. if ($breadcrumb_step['url'] != '#') {
  1170. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  1171. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  1172. } else {
  1173. $navigation_item['url'] = '#';
  1174. }
  1175. $navigation_item['title'] = $breadcrumb_step['name'];
  1176. // titles for shared folders
  1177. if ($breadcrumb_step['name'] == 'shared_folder') {
  1178. $navigation_item['title'] = get_lang('UserFolders');
  1179. } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
  1180. $navigation_item['title'] = get_lang('UserFolders');
  1181. } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) {
  1182. $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
  1183. $navigation_item['title'] = $userinfo['complete_name'];
  1184. } elseif ($breadcrumb_step['name'] == 'chat_files') {
  1185. $navigation_item['title'] = get_lang('ChatFiles');
  1186. } elseif ($breadcrumb_step['name'] == 'images') {
  1187. $navigation_item['title'] = get_lang('Images');
  1188. } elseif ($breadcrumb_step['name'] == 'video') {
  1189. $navigation_item['title'] = get_lang('Video');
  1190. } elseif ($breadcrumb_step['name'] == 'audio') {
  1191. $navigation_item['title'] = get_lang('Audio');
  1192. } elseif ($breadcrumb_step['name'] == 'flash') {
  1193. $navigation_item['title'] = get_lang('Flash');
  1194. } elseif ($breadcrumb_step['name'] == 'gallery') {
  1195. $navigation_item['title'] = get_lang('Gallery');
  1196. }
  1197. // Fixes breadcrumb title now we applied the Security::remove_XSS and we cut the string depending of the MAX_LENGTH_BREADCRUMB value
  1198. $navigation_item['title'] = Text::cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  1199. $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
  1200. $navigation[] = $navigation_item;
  1201. }
  1202. }
  1203. // 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
  1204. // is the same as the first part of the breadcrumbs (see part 1)
  1205. $final_navigation = array();
  1206. $counter = 0;
  1207. foreach ($navigation as $index => $navigation_info) {
  1208. if (!empty($navigation_info['title'])) {
  1209. if ($navigation_info['url'] == '#') {
  1210. $final_navigation[$index] = $navigation_info['title'];
  1211. } else {
  1212. $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" class="" target="_top">'.$navigation_info['title'].'</a>';
  1213. }
  1214. $counter++;
  1215. }
  1216. }
  1217. $html = '';
  1218. /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
  1219. $view_as_student_link = null;
  1220. if ($user_id && isset($course_id)) {
  1221. if ((api_is_course_admin() || api_is_course_coach() || api_is_platform_admin()) && api_get_setting(
  1222. 'student_view_enabled'
  1223. ) == 'true'
  1224. ) {
  1225. $view_as_student_link = api_display_tool_view_option();
  1226. }
  1227. }
  1228. if (!empty($final_navigation)) {
  1229. $lis = '';
  1230. $i = 0;
  1231. $final_navigation_count = count($final_navigation);
  1232. if (!empty($final_navigation)) {
  1233. // $home_link.= '<span class="divider">/</span>';
  1234. if (!empty($home_link)) {
  1235. $lis .= Display::tag('li', $home_link);
  1236. }
  1237. foreach ($final_navigation as $bread) {
  1238. $bread_check = trim(strip_tags($bread));
  1239. if (!empty($bread_check)) {
  1240. if ($final_navigation_count - 1 > $i) {
  1241. $bread .= '<span class="divider">/</span>';
  1242. }
  1243. $lis .= Display::tag('li', $bread);
  1244. $i++;
  1245. }
  1246. }
  1247. } else {
  1248. if (!empty($home_link)) {
  1249. $lis .= Display::tag('li', $home_link);
  1250. }
  1251. }
  1252. // View as student/teacher link
  1253. if (!empty($view_as_student_link)) {
  1254. $lis .= Display::tag(
  1255. 'li',
  1256. $view_as_student_link,
  1257. array('id' => 'view_as_link', 'class' => 'pull-right')
  1258. );
  1259. }
  1260. if (!empty($lis)) {
  1261. $html .= Display::tag('ul', $lis, array('class' => 'breadcrumb'));
  1262. }
  1263. }
  1264. return $html;
  1265. }
  1266. /**
  1267. * Returns a list of directories inside CSS
  1268. * @return array
  1269. */
  1270. public function getStyleSheetFolderList()
  1271. {
  1272. $dirs = $this->app['chamilo.filesystem']->getStyleSheetFolders();
  1273. $themes = array();
  1274. foreach ($dirs as $dir) {
  1275. $themes[] = $dir->getFilename();
  1276. }
  1277. return $themes;
  1278. }
  1279. }