configure_homepage.php 60 KB

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