configure_homepage.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Configure the portal homepage (manages multi-urls and languages)
  5. * @package chamilo.admin
  6. */
  7. /**
  8. * Creates menu tabs for logged and anonymous users
  9. *
  10. * This function copies the file containing private a public tabs (home_tabs_logged_in_$language.html)
  11. * in to the public tab template (home_tabs_$language.html) but without the private tabs.
  12. * Private tabs are the ones including "?private" string in the end of the url, ex: http://google.com/?private
  13. *
  14. * @param string Name of the file been updated by the administration, ex: home_tabs_logged_in_($language).html
  15. */
  16. function home_tabs($file_logged_in)
  17. {
  18. $post = strpos($file_logged_in, "_logged_in");
  19. if ($post !== false) {
  20. $file_logged_out = str_replace('_logged_in', '', $file_logged_in);
  21. //variables initialization
  22. $data_logged_out = array();
  23. $data_logged_in = array();
  24. //we read the file with all links
  25. $file = file($file_logged_in);
  26. foreach ($file as $line) {
  27. $line = str_replace("\n", '', $line);
  28. //not logged user only sees public links
  29. if (!preg_match('/::private/', $line)) {
  30. $data_logged_out[] = $line;
  31. }
  32. //logged user only sees all links
  33. $data_logged_in[] = $line;
  34. }
  35. //tabs file for logged out users
  36. if (file_exists($file_logged_out)) {
  37. $fp = fopen($file_logged_out, 'w');
  38. fputs($fp, implode("\n", $data_logged_out));
  39. fclose($fp);
  40. }
  41. //tabs file for logged in users
  42. $fp = fopen($file_logged_in, 'w');
  43. fputs($fp, implode("\n", $data_logged_in));
  44. fclose($fp);
  45. }
  46. }
  47. $cidReset = true;
  48. require_once __DIR__.'/../inc/global.inc.php';
  49. $this_section = SECTION_PLATFORM_ADMIN;
  50. $_SESSION['this_section'] = $this_section;
  51. $this_page = '';
  52. api_protect_admin_script();
  53. $htmlHeadXtra[] = '<script>
  54. $(function() {
  55. $("#all_langs").change(function() {
  56. var checkboxes = $(this).closest("form").find("#table_langs").find(":checkbox");
  57. checkboxes.prop("checked", $(this).is(":checked"));
  58. });
  59. });
  60. </script>';
  61. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
  62. $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
  63. $tool_name = get_lang('ConfigureHomePage');
  64. $_languages = api_get_languages();
  65. $selfUrl = api_get_self();
  66. $interbreadcrumb[] = array(
  67. 'url' => 'index.php',
  68. 'name' => get_lang('PlatformAdmin')
  69. );
  70. if (!empty($action)) {
  71. $interbreadcrumb[] = array(
  72. 'url' => 'configure_homepage.php',
  73. 'name' => get_lang('ConfigureHomePage')
  74. );
  75. switch ($action) {
  76. case 'edit_top':
  77. $tool_name = get_lang('EditHomePage');
  78. break;
  79. case 'edit_news':
  80. $tool_name = get_lang('EditNews');
  81. break;
  82. case 'edit_notice':
  83. $tool_name = get_lang('EditNotice');
  84. break;
  85. case 'insert_link':
  86. $tool_name = get_lang('InsertLink');
  87. break;
  88. case 'edit_link':
  89. $tool_name = get_lang('EditLink');
  90. break;
  91. case 'insert_tabs':
  92. $tool_name = get_lang('InsertTabs');
  93. break;
  94. case 'edit_tabs':
  95. $tool_name = get_lang('EditTabs');
  96. break;
  97. }
  98. }
  99. // The global logic for language priorities should be:
  100. // - take language selected when connecting ($_SESSION['user_language_choice'])
  101. // or last language selected (taken from select box into SESSION by global.inc.php)
  102. // or, if unavailable;
  103. // - take default user language ($_SESSION['_user']['language']) - which is taken from
  104. // the database in local.inc.php or, if unavailable;
  105. // - take platform language (taken from the database campus setting 'platformLanguage')
  106. // Then if a language file doesn't exist, it should be created.
  107. // The default language for the homepage should use the default platform language
  108. // (if nothing else is selected), which means the 'no-language' file should be taken
  109. // to fill a new 'language-specified' language file, and then only the latter should be
  110. // modified. The original 'no-language' files should never be modified.
  111. // ----- Language selection -----
  112. // The final language selected and used everywhere in this script follows the rules
  113. // described above and is put into "$lang". Because this script includes
  114. // global.inc.php, the variables used for language purposes below are considered safe.
  115. $lang = ''; //el for "Edit Language"
  116. if (!empty($_SESSION['user_language_choice'])) {
  117. $lang = $_SESSION['user_language_choice'];
  118. } elseif (!empty($_SESSION['_user']['language'])) {
  119. $lang = $_SESSION['_user']['language'];
  120. } else {
  121. $lang = api_get_setting('platformLanguage');
  122. }
  123. $languageGet = isset($_GET['language']) ? Security::remove_XSS($_GET['language']) : $lang;
  124. // Ensuring availability of main files in the corresponding language
  125. $homePath = api_get_path(SYS_HOME_PATH);
  126. if (api_is_multiple_url_enabled()) {
  127. $access_url_id = api_get_current_access_url_id();
  128. if ($access_url_id != -1) {
  129. $url_info = api_get_access_url($access_url_id);
  130. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  131. $clean_url = api_replace_dangerous_char($url);
  132. $clean_url = str_replace('/', '-', $clean_url);
  133. $clean_url .= '/';
  134. $homep = $homePath; //homep for Home Path
  135. $homep_new = $homePath.$clean_url; //homep for Home Path added the url
  136. $new_url_dir = $homePath.$clean_url;
  137. //we create the new dir for the new sites
  138. if (!is_dir($new_url_dir)) {
  139. mkdir($new_url_dir, api_get_permissions_for_new_directories());
  140. }
  141. }
  142. } else {
  143. $homep_new = '';
  144. $homep = $homePath; //homep for Home Path
  145. }
  146. $menuf = 'home_menu'; //menuf for Menu File
  147. $newsf = 'home_news'; //newsf for News File
  148. $topf = 'home_top'; //topf for Top File
  149. $noticef = 'home_notice'; //noticef for Notice File
  150. $menutabs = 'home_tabs'; //menutabs for tabs Menu
  151. $mtloggedin = 'home_tabs_logged_in'; //menutabs for tabs Menu
  152. $ext = '.html'; //ext for HTML Extension - when used frequently, variables are
  153. // faster than hardcoded strings
  154. $homef = array($menuf, $newsf, $topf, $noticef, $menutabs, $mtloggedin);
  155. // If language-specific file does not exist, create it by copying default file
  156. foreach ($homef as $my_file) {
  157. if (api_is_multiple_url_enabled()) {
  158. if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
  159. if (!file_exists($homep.$my_file.$ext)) {
  160. touch($homep.$my_file.$ext);
  161. }
  162. @copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext);
  163. }
  164. } else {
  165. if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
  166. if (!file_exists($homep.$my_file.$ext)) {
  167. touch($homep.$my_file.$ext);
  168. }
  169. @copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext);
  170. }
  171. }
  172. }
  173. if (api_is_multiple_url_enabled()) {
  174. $homep = $homep_new;
  175. }
  176. // Check WCAG settings and prepare edition using WCAG
  177. $errorMsg = '';
  178. // Filter link param
  179. $link = '';
  180. if (!empty($_GET['link'])) {
  181. $link = $_GET['link'];
  182. // If the link parameter is suspicious, empty it
  183. if (strstr($link, '/') || !strstr($link, '.html') || strstr($link, '\\')) {
  184. $link = '';
  185. $action = '';
  186. }
  187. }
  188. // Start analysing requested actions
  189. if (!empty($action)) {
  190. if (!empty($_POST['formSent'])) {
  191. // Variables used are $homep for home path, $menuf for menu file, $newsf
  192. // for news file, $topf for top file, $noticef for noticefile,
  193. // $ext for '.html'
  194. switch ($action) {
  195. case 'edit_top':
  196. // Filter
  197. $home_top = trim(stripslashes($_POST['home_top']));
  198. // Write
  199. if (is_writable($homep)) {
  200. // Default
  201. if (is_writable($homep.$topf.'_'.$lang.$ext)) {
  202. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  203. fputs($fp, $home_top);
  204. fclose($fp);
  205. // Language
  206. foreach ($_languages['name'] as $key => $value) {
  207. $lang_name = $_languages['folder'][$key];
  208. if (isset($_POST[$lang_name])) {
  209. $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
  210. fputs($fp, $home_top);
  211. fclose($fp);
  212. }
  213. }
  214. } else {
  215. $errorMsg = get_lang('HomePageFilesNotWritable');
  216. }
  217. } else {
  218. //File does not exist
  219. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  220. fputs($fp, $home_top);
  221. fclose($fp);
  222. foreach ($_languages['name'] as $key => $value) {
  223. $lang_name = $_languages['folder'][$key];
  224. if (isset($_POST[$lang_name])) {
  225. if (file_exists($homep.$topf.'_'.$lang_name.$ext)) {
  226. $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
  227. fputs($fp, $home_top);
  228. fclose($fp);
  229. }
  230. }
  231. }
  232. }
  233. if (EventsMail::check_if_using_class('portal_homepage_edited')) {
  234. EventsDispatcher::events('portal_homepage_edited', array('about_user' => api_get_user_id()));
  235. }
  236. Event::addEvent(
  237. LOG_HOMEPAGE_CHANGED,
  238. 'edit_top',
  239. cut(strip_tags($home_top), 254),
  240. api_get_utc_datetime(),
  241. api_get_user_id()
  242. );
  243. break;
  244. case 'edit_notice':
  245. // Filter
  246. $notice_title = trim(strip_tags(stripslashes($_POST['notice_title'])));
  247. $notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>')));
  248. if (empty($notice_title) || empty($notice_text)) {
  249. $errorMsg = get_lang('NoticeWillBeNotDisplayed');
  250. }
  251. // Write
  252. if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
  253. if (is_writable($homep.$noticef.'_'.$lang.$ext)) {
  254. $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
  255. if ($errorMsg == '') {
  256. fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
  257. foreach ($_languages['name'] as $key => $value) {
  258. $lang_name = $_languages['folder'][$key];
  259. if (isset($_POST[$lang_name])) {
  260. if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
  261. if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) {
  262. $fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
  263. fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
  264. fclose($fp);
  265. }
  266. }
  267. }
  268. }
  269. } else {
  270. fputs($fp, '');
  271. foreach ($_languages['name'] as $key => $value) {
  272. $lang_name = $_languages['folder'][$key];
  273. if (isset($_POST[$lang_name])) {
  274. if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
  275. $fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
  276. fputs($fp1, '');
  277. fclose($fp1);
  278. }
  279. }
  280. }
  281. }
  282. fclose($fp);
  283. } else {
  284. $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable');
  285. }
  286. } else {
  287. //File does not exist
  288. $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
  289. fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
  290. fclose($fp);
  291. }
  292. Event::addEvent(
  293. LOG_HOMEPAGE_CHANGED,
  294. 'edit_notice',
  295. cut(strip_tags($notice_title), 254),
  296. api_get_utc_datetime(),
  297. api_get_user_id()
  298. );
  299. break;
  300. case 'edit_news':
  301. //Filter
  302. $home_news = trim(stripslashes($_POST['home_news']));
  303. //Write
  304. if ($s_languages_news != 'all') {
  305. if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) {
  306. if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) {
  307. $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
  308. fputs($fp, $home_news);
  309. fclose($fp);
  310. } else {
  311. $errorMsg = get_lang('HomePageFilesNotWritable');
  312. }
  313. } else {
  314. // File does not exist
  315. $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
  316. fputs($fp, $home_news);
  317. fclose($fp);
  318. }
  319. } else {
  320. // We update all the news file
  321. foreach ($_languages['name'] as $key => $value) {
  322. $english_name = $_languages['folder'][$key];
  323. if (file_exists($homep.$newsf.'_'.$english_name.$ext)) {
  324. if (is_writable($homep.$newsf.'_'.$english_name.$ext)) {
  325. $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
  326. fputs($fp, $home_news);
  327. fclose($fp);
  328. } else {
  329. $errorMsg = get_lang('HomePageFilesNotWritable');
  330. }
  331. } else {
  332. // File does not exist
  333. $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
  334. fputs($fp, $home_news);
  335. fclose($fp);
  336. }
  337. }
  338. }
  339. Event::addEvent(
  340. LOG_HOMEPAGE_CHANGED,
  341. 'edit_news',
  342. strip_tags(cut($home_news, 254)),
  343. api_get_utc_datetime(),
  344. api_get_user_id()
  345. );
  346. break;
  347. case 'insert_tabs':
  348. case 'edit_tabs':
  349. case 'insert_link':
  350. case 'edit_link':
  351. $link_index = intval($_POST['link_index']);
  352. $insert_where = intval($_POST['insert_where']);
  353. $link_name = trim(stripslashes($_POST['link_name']));
  354. $link_url = trim(stripslashes($_POST['link_url']));
  355. $add_in_tab = intval($_POST['add_in_tab']);
  356. $link_html = trim(stripslashes($_POST['link_html']));
  357. $filename = trim(stripslashes($_POST['filename']));
  358. $target_blank = isset($_POST['target_blank']);
  359. if ($link_url == 'http://' || $link_url == 'https://') {
  360. $link_url = '';
  361. } elseif (!empty($link_url) && !strstr($link_url, '://')) {
  362. $link_url = 'http://'.$link_url;
  363. }
  364. $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
  365. if (!is_writable($homep.$menuf.'_'.$lang.$ext)) {
  366. $errorMsg = get_lang('HomePageFilesNotWritable');
  367. } elseif (empty($link_name)) {
  368. $errorMsg = get_lang('PleaseEnterLinkName');
  369. } else {
  370. // New links are added as new files in the home/ directory
  371. if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) {
  372. $filename = api_replace_dangerous_char($link_name).'.html';
  373. }
  374. // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files)
  375. if (!empty($filename)) {
  376. $filename = str_replace('home_', 'user_', $filename);
  377. }
  378. // If the typical language suffix is not found in the file name,
  379. // replace the ".html" suffix by "_en.html" or the active menu language
  380. if (!strstr($filename, '_'.$lang.$ext)) {
  381. $filename = str_replace($ext, '_'.$lang.$ext, $filename);
  382. }
  383. // Get the contents of home_menu_en.html (or active menu language
  384. // version) into $home_menu as an array of one entry per line
  385. $home_menu = file($homep.$menuf.'_'.$lang.$ext);
  386. $home_menu = implode("\n", $home_menu);
  387. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  388. $home_menu = explode("\n", $home_menu);
  389. $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
  390. // Prepare place to insert the new link into (default is end of file)
  391. if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) {
  392. $insert_where = sizeof($home_menu) - 1;
  393. }
  394. //
  395. // For each line of the file, remove trailing spaces and special chars
  396. //foreach ($home_menu as $key => $enreg) {
  397. // $home_menu[$key] = trim($enreg);
  398. //}
  399. //
  400. // If the given link url is empty, then replace the link url by a link to the link file created
  401. if (empty($link_url) || $link_url == 'http://' || $link_url == 'https://') {
  402. $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
  403. // If the file doesn't exist, then create it and
  404. // fill it with default text
  405. $fp = @fopen($homep.$filename, 'w');
  406. if ($fp) {
  407. if (empty($link_html)) {
  408. fputs($fp, get_lang('MyTextHere'));
  409. home_tabs($homep.$filename);
  410. } else {
  411. fputs($fp, $link_html);
  412. home_tabs($homep.$filename);
  413. }
  414. fclose($fp);
  415. }
  416. }
  417. // If the requested action is to edit a link, open the file and
  418. // write to it (if the file doesn't exist, create it)
  419. if (in_array($action, array('edit_link')) && !empty($link_html)) {
  420. $fp = @fopen($homep.$filename, 'w');
  421. if ($fp) {
  422. fputs($fp, $link_html);
  423. home_tabs($homep.$filename);
  424. fclose($fp);
  425. }
  426. }
  427. $class_add_in_tab = 'class="show_menu"';
  428. if (!$add_in_tab) {
  429. $class_add_in_tab = 'class="hide_menu"';
  430. }
  431. // If the requested action is to create a link, make some room
  432. // for the new link in the home_menu array at the requested place
  433. // and insert the new link there
  434. if ($action == 'insert_link' || $action == 'insert_tabs') {
  435. for ($i = sizeof($home_menu); $i; $i--) {
  436. if ($i > $insert_where) {
  437. $home_menu[$i] = $home_menu[$i - 1];
  438. } else {
  439. break;
  440. }
  441. }
  442. $home_menu[$insert_where + 1] = '<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'.$link_name.'</a></li>';
  443. } else {
  444. // If the request is about a link edition, change the link
  445. $home_menu[$link_index] = '<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'.$link_name.'</a></li>';
  446. }
  447. // Re-build the file from the home_menu array
  448. $home_menu = implode("\n", $home_menu);
  449. // Write
  450. if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
  451. if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
  452. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  453. fputs($fp, $home_menu);
  454. home_tabs($homep.$menuf.'_'.$lang.$ext);
  455. fclose($fp);
  456. foreach ($_languages['name'] as $key => $value) {
  457. $lang_name = $_languages['folder'][$key];
  458. if (isset($_POST[$lang_name])) {
  459. $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
  460. fputs($fp, $home_menu);
  461. home_tabs($homep.$menuf.'_'.$lang_name.$ext);
  462. fclose($fp);
  463. }
  464. }
  465. if (file_exists($homep.$menuf.$ext)) {
  466. if (is_writable($homep.$menuf.$ext)) {
  467. $fpo = fopen($homep.$menuf.$ext, 'w');
  468. fputs($fpo, $home_menu);
  469. home_tabs($homep.$menuf.$ext);
  470. fclose($fpo);
  471. }
  472. }
  473. } else {
  474. $errorMsg = get_lang('HomePageFilesNotWritable');
  475. }
  476. } else {
  477. //File does not exist
  478. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  479. fputs($fp, $home_menu);
  480. home_tabs($homep.$menuf.'_'.$lang.$ext);
  481. fclose($fp);
  482. foreach ($_languages['name'] as $key => $value) {
  483. $lang_name = $_languages['folder'][$key];
  484. if (isset($_POST[$lang_name])) {
  485. $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
  486. fputs($fp, $home_menu);
  487. home_tabs($homep.$menuf.'_'.$lang_name.$ext);
  488. fclose($fp);
  489. }
  490. }
  491. }
  492. }
  493. Event::addEvent(
  494. LOG_HOMEPAGE_CHANGED,
  495. $action,
  496. cut($link_name.':'.$link_url, 254),
  497. api_get_utc_datetime(),
  498. api_get_user_id()
  499. );
  500. break;
  501. } //end of switch($action)
  502. if (empty($errorMsg)) {
  503. header('Location: '.$selfUrl.'?language='.$languageGet);
  504. exit();
  505. }
  506. } else {
  507. //if POST[formSent] is not set
  508. switch ($action) {
  509. case 'open_link':
  510. // Previously, filtering of GET['link'] was done here but it left
  511. // a security threat. Filtering has now been moved outside conditions
  512. break;
  513. case 'delete_tabs':
  514. case 'delete_link':
  515. // A link is deleted by getting the file into an array, removing the
  516. // link and re-writing the array to the file
  517. $link_index = intval($_GET['link_index']);
  518. $menuf = ($action == 'delete_tabs') ? $mtloggedin : $menuf;
  519. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  520. if (empty($home_menu)) {
  521. $home_menu = array();
  522. }
  523. foreach ($home_menu as $key => $enreg) {
  524. if ($key == $link_index) {
  525. unset($home_menu[$key]);
  526. } else {
  527. $home_menu[$key] = trim($enreg);
  528. }
  529. }
  530. $home_menu = implode("\n", $home_menu);
  531. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  532. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  533. fputs($fp, $home_menu);
  534. home_tabs($homep.$menuf.'_'.$lang.$ext);
  535. fclose($fp);
  536. if (file_exists($homep.$menuf.$ext)) {
  537. if (is_writable($homep.$menuf.$ext)) {
  538. $fpo = fopen($homep.$menuf.$ext, 'w');
  539. fputs($fpo, $home_menu);
  540. home_tabs($homep.$menuf.$ext);
  541. fclose($fpo);
  542. }
  543. }
  544. header('Location: '.$selfUrl);
  545. exit();
  546. break;
  547. case 'edit_top':
  548. // This request is only the preparation for the update of the home_top
  549. $home_top = '';
  550. if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
  551. $home_top = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
  552. } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
  553. $home_top = @(string) file_get_contents($homep.$topf.$lang.$ext);
  554. } else {
  555. $errorMsg = get_lang('HomePageFilesNotReadable');
  556. }
  557. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  558. break;
  559. case 'edit_notice':
  560. // This request is only the preparation for the update of the home_notice
  561. $home_notice = '';
  562. if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) {
  563. $home_notice = @file($homep.$noticef.'_'.$lang.$ext);
  564. } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) {
  565. $home_notice = @file($homep.$noticef.$lang.$ext);
  566. } else {
  567. $errorMsg = get_lang('HomePageFilesNotReadable');
  568. }
  569. if (empty($home_notice)) {
  570. $home_notice = array();
  571. }
  572. $notice_title = strip_tags($home_notice[0]);
  573. $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title));
  574. $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>');
  575. $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text)));
  576. break;
  577. case 'edit_news':
  578. // This request is the preparation for the update of the home_news page
  579. $home_news = '';
  580. if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
  581. $home_news = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
  582. } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
  583. $home_news = @(string) file_get_contents($homep.$newsf.$lang.$ext);
  584. } else {
  585. $errorMsg = get_lang('HomePageFilesNotReadable');
  586. }
  587. $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news)));
  588. break;
  589. case 'insert_link':
  590. // This request is the preparation for the addition of an item in home_menu
  591. $home_menu = '';
  592. $menuf = ($action == 'edit_tabs') ? $mtloggedin : $menuf;
  593. if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
  594. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  595. } elseif (is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
  596. $home_menu = @file($homep.$menuf.$lang.$ext);
  597. } else {
  598. $errorMsg = get_lang('HomePageFilesNotReadable');
  599. }
  600. if (empty($home_menu)) {
  601. $home_menu = array();
  602. }
  603. if (!empty($home_menu)) {
  604. $home_menu = implode("\n", $home_menu);
  605. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  606. $home_menu = explode("\n", $home_menu);
  607. }
  608. $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
  609. break;
  610. case 'insert_tabs':
  611. // This request is the preparation for the addition of an item in home_menu
  612. $home_menu = '';
  613. if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
  614. $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
  615. } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
  616. $home_menu = @file($homep.$mtloggedin.$lang.$ext);
  617. } elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) {
  618. $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
  619. } else {
  620. $errorMsg = get_lang('HomePageFilesNotReadable');
  621. }
  622. if (empty($home_menu)) {
  623. $home_menu = array();
  624. }
  625. if (!empty($home_menu)) {
  626. $home_menu = implode("\n", $home_menu);
  627. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  628. $home_menu = explode("\n", $home_menu);
  629. }
  630. $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
  631. break;
  632. case 'edit_tabs':
  633. case 'edit_link':
  634. // This request is the preparation for the edition of the links array
  635. $home_menu = '';
  636. $menuf = ($action == 'edit_tabs') ? $mtloggedin : $menuf;
  637. if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
  638. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  639. } elseif (is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
  640. $home_menu = @file($homep.$menuf.$lang.$ext);
  641. } else {
  642. $errorMsg = get_lang('HomePageFilesNotReadable');
  643. }
  644. if (empty($home_menu)) {
  645. if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
  646. $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
  647. }
  648. }
  649. if (empty($home_menu)) {
  650. $home_menu = array();
  651. }
  652. if (!empty($home_menu)) {
  653. $home_menu = implode("\n", $home_menu);
  654. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  655. $home_menu = explode("\n", $home_menu);
  656. }
  657. $link_index = intval($_GET['link_index']);
  658. $target_blank = false;
  659. $link_name = '';
  660. $link_url = '';
  661. //$home_menu_new = array();
  662. //
  663. //Cleaning array
  664. //foreach ($home_menu as $item) {
  665. // if(!empty($item)) {
  666. // $home_menu_new[] = $item;
  667. // }
  668. //}
  669. //$home_menu = $home_menu_new;
  670. // Cleaning the array
  671. $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
  672. // For each line of the home_menu file
  673. foreach ($home_menu as $key => $enreg) {
  674. // Check if the current item is the one we want to update
  675. if ($key == $link_index) {
  676. // This is the link we want to update
  677. // Check if the target should be "_blank"
  678. if (strstr($enreg, 'target="_blank"')) {
  679. $target_blank = true;
  680. }
  681. if (strstr($enreg, 'hide_menu')) {
  682. $add_in_tab = false;
  683. } else {
  684. $add_in_tab = true;
  685. }
  686. // Remove dangerous HTML tags from the link itself (this is an
  687. // additional measure in case a link previously contained
  688. // unsecure tags)
  689. $link_name = strip_tags($enreg);
  690. // Get the contents of "href" attribute in $link_url
  691. $enreg = explode('href="', $enreg);
  692. list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
  693. // If the link contains the web root of this portal, then strip
  694. // it off and keep only the name of the file that needs edition
  695. if (strstr($link_url, '?include=')) {
  696. $link_url = explode('?include=', $link_url);
  697. $filename = $link_url[sizeof($link_url) - 1];
  698. if (!strstr($filename, '/') && strstr($filename, '.html')) {
  699. // Get oonly the contents of the link file
  700. $link_html = @file($homep.$filename);
  701. $link_html = implode('', $link_html);
  702. $link_url = '';
  703. } else {
  704. $filename = '';
  705. }
  706. }
  707. break;
  708. }
  709. }
  710. break;
  711. }//end of second switch($action) (when POST['formSent'] was not set, yet)
  712. }// end of "else" in if($_POST['formSent']) condition
  713. } else {
  714. //if $action is empty, then prepare a list of the course categories to display (?)
  715. $Categories = CourseCategory::getCategoriesToDisplayInHomePage();
  716. }
  717. // Display section
  718. Display::display_header($tool_name);
  719. switch ($action) {
  720. case 'open_link':
  721. if (!empty($link)) {
  722. // $link is only set in case of action=open_link and is filtered
  723. $open = @(string) file_get_contents($homep.$link);
  724. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  725. echo $open;
  726. }
  727. break;
  728. case 'edit_notice':
  729. // Display for edit_notice case
  730. ?>
  731. <form action="<?php echo $selfUrl; ?>?action=<?php echo $action; ?>" method="post" class="form-horizontal">
  732. <legend><?php echo $tool_name; ?></legend>
  733. <input type="hidden" name="formSent" value="1"/>
  734. <?php
  735. if (!empty($errorMsg)) {
  736. echo Display::return_message($errorMsg, 'normal');
  737. }
  738. ?>
  739. <div class="row">
  740. <div class="col-md-12">
  741. <p><?php echo get_lang('LetThoseFieldsEmptyToHideTheNotice'); ?></p>
  742. <div class="form-group">
  743. <label class="col-sm-3 control-label"> <?php echo get_lang('NoticeTitle'); ?> </label>
  744. <div class="col-sm-6">
  745. <input type="text" name="notice_title" size="30" maxlength="50"
  746. value="<?php echo $notice_title; ?>" class="form-control"/>
  747. </div>
  748. <div class="col-sm-3"></div>
  749. </div>
  750. <div class="form-group">
  751. <label class="col-sm-3 control-label"><?php echo get_lang('NoticeText'); ?></label>
  752. <div class="col-sm-6">
  753. <textarea name="notice_text" cols="30" rows="5" wrap="virtual"
  754. class="form-control"><?php echo $notice_text; ?></textarea>
  755. </div>
  756. <div class="col-sm-3"></div>
  757. </div>
  758. <div class="form-group">
  759. <div class="col-sm-3"></div>
  760. <div class="col-sm-6">
  761. <div class="checkbox">
  762. <label>
  763. <input type="checkbox" name="all_langs"
  764. value="<?php echo get_lang('ApplyAllLanguages'); ?>"/> <?php echo get_lang('ApplyAllLanguages'); ?>
  765. </label>
  766. </div>
  767. </div>
  768. <div class="col-sm-3"></div>
  769. </div>
  770. <div class="form-group">
  771. <div class="col-sm-offset-3 col-sm-9">
  772. <button class="btn btn-primary" type="submit"
  773. value="<?php echo get_lang('Ok'); ?>"><?php echo get_lang('Ok'); ?></button>
  774. </div>
  775. </div>
  776. </div>
  777. </div>
  778. </form>
  779. <?php
  780. break;
  781. case 'insert_tabs':
  782. case 'edit_tabs':
  783. case 'insert_link':
  784. case 'edit_link':
  785. $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
  786. if (!empty($errorMsg)) {
  787. echo Display::return_message($errorMsg, 'normal');
  788. }
  789. $default = array();
  790. $form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;'));
  791. $renderer = & $form->defaultRenderer();
  792. $form->addElement('header', '', $tool_name);
  793. $form->addElement('hidden', 'formSent', '1');
  794. $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
  795. $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : '');
  796. $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
  797. if (!empty($link_name)) {
  798. $default['link_name'] = $link_name;
  799. }
  800. $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
  801. $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : '';
  802. $form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
  803. $options = array('-1' => get_lang('FirstPlace'));
  804. $selected = '';
  805. if ($action == 'insert_link' || $action == 'insert_tabs') {
  806. $add_in_tab = 1;
  807. if (is_array($home_menu)) {
  808. foreach ($home_menu as $key => $enreg) {
  809. if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
  810. $options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
  811. $formSentCheck = (!empty($_POST['formSent']) ? true : false);
  812. $selected = $formSentCheck && $insert_where == $key ? $key : '';
  813. }
  814. }
  815. }
  816. $default['insert_link'] = $selected;
  817. $form->addElement('select', 'insert_where', get_lang('InsertThisLink'), $options);
  818. }
  819. $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
  820. if ($action == 'insert_tabs' || $action == 'edit_tabs') {
  821. $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1);
  822. $default['add_in_tab'] = $add_in_tab;
  823. }
  824. if (!empty($target_blank)) {
  825. $target_blank_checkbox->setChecked(true);
  826. }
  827. if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) {
  828. $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
  829. $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  830. $form->addButtonSave(get_lang('Save'), 'submit');
  831. } else {
  832. if (in_array($action, array('edit_tabs', 'insert_tabs'))) {
  833. $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : '');
  834. $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  835. }
  836. $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
  837. $form->addElement('html', '<table id="table_langs" style="margin-left:159px;"><tr>');
  838. $i = 0;
  839. foreach ($_languages['name'] as $key => $value) {
  840. $i++;
  841. $lang_name = $_languages['folder'][$key];
  842. $html_langs = '<td width="300">';
  843. $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
  844. $html_langs .= '</td>';
  845. if ($i % 5 == 0) {
  846. $html_langs .= '</tr><tr>';
  847. }
  848. $form->addElement('html', $html_langs);
  849. }
  850. $form->addElement('html', '</tr></table><br/>');
  851. $form->addButtonSave(get_lang('Save'), 'submit');
  852. }
  853. $form->setDefaults($default);
  854. $form->display();
  855. break;
  856. case 'edit_top':
  857. case 'edit_news':
  858. if ($action == 'edit_top') {
  859. $name = $topf;
  860. $open = $home_top;
  861. } else {
  862. $name = $newsf;
  863. $open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
  864. }
  865. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  866. if (!empty($errorMsg)) {
  867. echo Display::return_message($errorMsg, 'normal'); //main API
  868. }
  869. $default = array();
  870. $form = new FormValidator(
  871. 'configure_homepage_'.$action,
  872. 'post',
  873. $selfUrl.'?action='.$action,
  874. '',
  875. array('style' => 'margin: 0px;')
  876. );
  877. $renderer = & $form->defaultRenderer();
  878. $renderer->setHeaderTemplate('');
  879. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  880. $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
  881. $renderer->setRequiredNoteTemplate('');
  882. $form->addElement('hidden', 'formSent', '1');
  883. if ($action == 'edit_news') {
  884. $_languages = api_get_languages();
  885. $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
  886. $html .= '<select name="news_languages">';
  887. $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>';
  888. foreach ($_languages['name'] as $key => $value) {
  889. $english_name = $_languages['folder'][$key];
  890. if ($language == $english_name) {
  891. $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
  892. } else {
  893. $html .= '<option value="'.$english_name.'">'.$value.'</option>';
  894. }
  895. }
  896. $html .= '</select></td></tr>';
  897. $form->addElement('html', $html);
  898. }
  899. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  900. $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  901. $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
  902. $form->addElement('html', '<table id="table_langs" style="margin-left:5px;"><tr>');
  903. $currentLanguage = api_get_interface_language();
  904. $i = 0;
  905. foreach ($_languages['name'] as $key => $value) {
  906. $lang_name = $_languages['folder'][$key];
  907. $i++;
  908. $checked = null;
  909. if ($languageGet == $lang_name) {
  910. $checked = "checked";
  911. }
  912. $html_langs = '<td width="300">';
  913. $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" />&nbsp;'.$value.'<label/>';
  914. $html_langs .= '</td>';
  915. if ($i % 5 == 0) {
  916. $html_langs .= '</tr><tr>';
  917. }
  918. $form->addElement('html', $html_langs);
  919. }
  920. $form->addElement('html', '</tr></table><br/>');
  921. $form->addButtonSave(get_lang('Save'));
  922. $form->setDefaults($default);
  923. $form->display();
  924. break;
  925. default: // When no action applies, default page to update campus homepage
  926. ?>
  927. <section id="page-home">
  928. <div class="row">
  929. <div class="col-md-3">
  930. <!-- login block -->
  931. <div id="login_block" class="panel panel-default">
  932. <div class="panel-body">
  933. <?php echo api_display_language_form(); ?>
  934. <form id="formLogin" class="form-horizontal">
  935. <div class="input-group">
  936. <div class="input-group-addon"><em class="fa fa-user"></em></div>
  937. <input class="form-control" type="text" id="login" value="" disabled="disabled"/>
  938. </div>
  939. <div class="input-group">
  940. <div class="input-group-addon"><em class="fa fa-lock"></em></div>
  941. <input type="password" id="password" class="form-control" value=""
  942. disabled="disabled"/>
  943. </div>
  944. <button class="btn btn-primary btn-block" type="button" name="submitAuth"
  945. value="<?php echo get_lang('Ok'); ?>"
  946. disabled="disabled"><?php echo get_lang('Ok'); ?></button>
  947. </form>
  948. <ul class="nav nav-pills nav-stacked">
  949. <li><?php echo api_ucfirst(get_lang('Registration')); ?></li>
  950. <li><?php echo api_ucfirst(get_lang('LostPassword')); ?></li>
  951. </ul>
  952. </div>
  953. </div>
  954. <!-- notice block -->
  955. <div class="panel-group" id="notice-block" role="tablist" aria-multiselectable="true">
  956. <div class="panel panel-default">
  957. <div class="panel-heading" role="tab" id="headingOne">
  958. <h4 class="panel-title">
  959. <a role="button" data-toggle="collapse" data-parent="#notice-block"
  960. href="#notice-list" aria-expanded="true" aria-controls="notice-list">
  961. <?php echo get_lang('Notice'); ?>
  962. <a class="pull-right"
  963. href="<?php echo $selfUrl; ?>?action=edit_notice"><?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?></a>
  964. </a>
  965. </h4>
  966. </div>
  967. <div id="notice-list" class="panel-collapse collapse in" role="tabpanel"
  968. aria-labelledby="headingOne">
  969. <div class="panel-body">
  970. <?php
  971. $home_notice = '';
  972. if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
  973. $home_notice = @(string) file_get_contents($homep.$noticef.'_'.$lang.$ext);
  974. } else {
  975. $home_notice = @(string) file_get_contents($homep.$noticef.$ext);
  976. }
  977. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  978. echo '<div class="homepage_notice">';
  979. echo $home_notice;
  980. echo '</div>';
  981. ?>
  982. </div>
  983. </div>
  984. </div>
  985. </div>
  986. <!-- insert link block -->
  987. <div class="panel-group" id="links-block" role="tablist" aria-multiselectable="true">
  988. <div class="panel panel-default">
  989. <div class="panel-heading" role="tab" id="headingOne">
  990. <h4 class="panel-title">
  991. <a role="button" data-toggle="collapse" data-parent="#links-block"
  992. href="#links-list" aria-expanded="true" aria-controls="links-list">
  993. <?php echo api_ucfirst(get_lang('General')); ?>
  994. </a>
  995. </h4>
  996. </div>
  997. <div id="links-list" class="panel-collapse collapse in" role="tabpanel"
  998. aria-labelledby="headingOne">
  999. <div class="panel-body">
  1000. <a href="<?php echo $selfUrl; ?>?action=insert_link"><?php echo Display::return_icon('add.png', get_lang('InsertLink')).'&nbsp;'.get_lang('InsertLink'); ?>
  1001. </a>
  1002. <ul class="menulist">
  1003. <?php
  1004. $home_menu = '';
  1005. if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
  1006. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  1007. } else {
  1008. $home_menu = @file($homep.$menuf.$ext);
  1009. }
  1010. if (empty($home_menu)) {
  1011. $home_menu = array();
  1012. }
  1013. if (!empty($home_menu)) {
  1014. $home_menu = implode("\n", $home_menu);
  1015. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  1016. $home_menu = explode("\n", $home_menu);
  1017. }
  1018. $i = 0;
  1019. foreach ($home_menu as $enreg) {
  1020. $enreg = trim($enreg);
  1021. if (!empty($enreg)) {
  1022. $edit_link = '<a href="'.$selfUrl.'?action=edit_link&amp;link_index='.$i.'">'.Display::return_icon('edit.png', get_lang('Edit')).'</a>';
  1023. $delete_link = '<a href="'.$selfUrl.'?action=delete_link&amp;link_index='.$i.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  1024. echo str_replace(array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'), array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=', $edit_link.' '.$delete_link.'</li>'), $enreg);
  1025. $i++;
  1026. }
  1027. }
  1028. ?>
  1029. </ul>
  1030. </div>
  1031. </div>
  1032. </div>
  1033. </div>
  1034. </div>
  1035. <div class="col-md-9">
  1036. <div class="actions">
  1037. <a href="<?php echo $selfUrl; ?>?action=edit_top&language=<?php echo $languageGet; ?>">
  1038. <?php echo Display::return_icon('edit.png', get_lang('EditHomePage'), null, ICON_SIZE_SMALL).'&nbsp;'.get_lang('EditHomePage'); ?>
  1039. </a>
  1040. </div>
  1041. <section id="homepage-home">
  1042. <?php
  1043. //print home_top contents
  1044. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  1045. $home_top_temp = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
  1046. } else {
  1047. $home_top_temp = @(string) file_get_contents($homep.$topf.$ext);
  1048. }
  1049. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  1050. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  1051. echo $open;
  1052. ?>
  1053. </section>
  1054. <?php
  1055. $access_url_id = 1;
  1056. // we only show the category options for the main chamilo installation
  1057. if (api_is_multiple_url_enabled()) {
  1058. $access_url_id = api_get_current_access_url_id();
  1059. }
  1060. if ($access_url_id == 1) {
  1061. echo '<div class="actions">';
  1062. echo '<a href="course_category.php">'.Display::return_icon('edit.png', get_lang('Edit')).'&nbsp;'.get_lang('EditCategories').'</a>';
  1063. echo '</div>';
  1064. echo '<ul class="list-group">';
  1065. if (count($Categories)) {
  1066. foreach ($Categories as $enreg) {
  1067. echo '<li class="list-group-item">'
  1068. .Display::return_icon('folder.png', get_lang('CourseCategory')).' '.$enreg['name']
  1069. .'</li>';
  1070. }
  1071. unset($Categories);
  1072. } else {
  1073. echo '<li class="list-group-item">'.get_lang('NoCategories').'</li>';
  1074. }
  1075. echo '</ul>';
  1076. }
  1077. ?>
  1078. <?php
  1079. if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
  1080. $open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
  1081. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  1082. echo $open;
  1083. } else {
  1084. $open = @(string) file_get_contents($homep.$newsf.$ext);
  1085. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  1086. echo $open;
  1087. }
  1088. ?>
  1089. <?php
  1090. // Add new page
  1091. $home_menu = '';
  1092. if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) {
  1093. $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
  1094. } else {
  1095. $home_menu = @file($homep.$mtloggedin.$ext);
  1096. }
  1097. if (empty($home_menu)) {
  1098. if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
  1099. $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
  1100. }
  1101. }
  1102. if (empty($home_menu)) {
  1103. $home_menu = array();
  1104. }
  1105. if (!empty($home_menu)) {
  1106. $home_menu = implode("\n", $home_menu);
  1107. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  1108. $home_menu = explode("\n", $home_menu);
  1109. }
  1110. $link_list = '';
  1111. $tab_counter = 0;
  1112. foreach ($home_menu as $enreg) {
  1113. $enreg = trim($enreg);
  1114. if (!empty($enreg)) {
  1115. $edit_link = ' <a href="'.$selfUrl.'?action=edit_tabs&amp;link_index='.$tab_counter.'" ><span>'.Display::return_icon('edit.png', get_lang('Edit')).'</span></a>';
  1116. $delete_link = ' <a href="'.$selfUrl.'?action=delete_tabs&amp;link_index='.$tab_counter.'" onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;"><span>'.Display::return_icon('delete.png', get_lang('Delete')).'</span></a>';
  1117. $tab_string = str_replace(
  1118. array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'),
  1119. array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=', $edit_link.$delete_link.'</li>'),
  1120. $enreg
  1121. );
  1122. $tab_string = str_replace([' class="hide_menu"', ' class="show_menu"'], '', $tab_string);
  1123. $tab_string = str_replace(array('<li>', '</li>'), '', $tab_string);
  1124. $link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item'));
  1125. $tab_counter++;
  1126. }
  1127. }
  1128. ?>
  1129. <div class="actions">
  1130. <a href="<?php echo $selfUrl; ?>?action=insert_tabs">
  1131. <?php echo Display::return_icon('add.png', get_lang('InsertLink')).'&nbsp;'.get_lang('InsertLink'); ?>
  1132. </a>
  1133. </div>
  1134. <?php
  1135. echo '<ul id="list-hiperlink" class="list-group">';
  1136. echo $link_list;
  1137. echo '</ul>';
  1138. ?>
  1139. </div>
  1140. </div>
  1141. </section>
  1142. <?php
  1143. break;
  1144. }
  1145. Display::display_footer();