configure_homepage.php 61 KB

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