template.lib.php 54 KB

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