configure_homepage.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  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 '../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' => Container::getRouter()->generate('administration'),
  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('language.platform_language');
  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" value="<?php echo $notice_title; ?>" class="form-control"/>
  750. </div>
  751. <div class="col-sm-3"></div>
  752. </div>
  753. <div class="form-group">
  754. <label class="col-sm-3 control-label"><?php echo get_lang('NoticeText'); ?></label>
  755. <div class="col-sm-6">
  756. <textarea name="notice_text" cols="30" rows="5" wrap="virtual" class="form-control"><?php echo $notice_text; ?></textarea>
  757. </div>
  758. <div class="col-sm-3"></div>
  759. </div>
  760. <div class="form-group">
  761. <div class="col-sm-3"></div>
  762. <div class="col-sm-6">
  763. <div class="checkbox">
  764. <label>
  765. <input type="checkbox" name="all_langs" 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" value="<?php echo get_lang('Ok'); ?>"><?php echo get_lang('Ok'); ?></button>
  774. </div>
  775. </div>
  776. </div>
  777. </div>
  778. </form>
  779. <?php
  780. break;
  781. case 'insert_tabs':
  782. case 'edit_tabs':
  783. case 'insert_link':
  784. case 'edit_link':
  785. $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
  786. if (!empty($errorMsg)) {
  787. Display::display_normal_message($errorMsg);
  788. }
  789. $default = array();
  790. $form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;'));
  791. $renderer =& $form->defaultRenderer();
  792. $form->addElement('header', '', $tool_name);
  793. $form->addElement('hidden', 'formSent', '1');
  794. $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
  795. $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : '');
  796. $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
  797. if (!empty($link_name)) {
  798. $default['link_name'] = $link_name;
  799. }
  800. $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
  801. $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : '';
  802. $form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
  803. $options = array('-1' => get_lang('FirstPlace'));
  804. $selected = '';
  805. if ($action == 'insert_link' || $action == 'insert_tabs') {
  806. $add_in_tab = 1;
  807. if (is_array($home_menu)){
  808. foreach ($home_menu as $key => $enreg) {
  809. if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
  810. $options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
  811. $formSentCheck = (!empty($_POST['formSent']) ? true : false);
  812. $selected = $formSentCheck && $insert_where == $key ? $key : '';
  813. }
  814. }
  815. }
  816. $default['insert_link'] = $selected;
  817. $form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options);
  818. }
  819. $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
  820. if ($action == 'insert_tabs' || $action == 'edit_tabs') {
  821. $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1);
  822. $default['add_in_tab'] = $add_in_tab;
  823. }
  824. if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); }
  825. if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) {
  826. $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
  827. $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  828. $form->addButtonSave(get_lang('Save'),'submit');
  829. } else {
  830. if (in_array($action, array('edit_tabs','insert_tabs'))) {
  831. $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : '');
  832. $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  833. }
  834. $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
  835. $form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>');
  836. $i = 0;
  837. foreach ($_languages['name'] as $key => $value) {
  838. $i++;
  839. $lang_name = $_languages['folder'][$key];
  840. $html_langs = '<td width="300">';
  841. $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
  842. $html_langs .= '</td>';
  843. if ($i % 5 == 0) {
  844. $html_langs .= '</tr><tr>';
  845. }
  846. $form->addElement('html', $html_langs);
  847. }
  848. $form->addElement('html','</tr></table><br/>');
  849. $form->addButtonSave(get_lang('Save'),'submit');
  850. }
  851. $form->setDefaults($default);
  852. $form->display();
  853. break;
  854. case 'edit_top':
  855. case 'edit_news':
  856. if ($action == 'edit_top') {
  857. $name = $topf;
  858. $open = $home_top;
  859. } else {
  860. $name = $newsf;
  861. $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  862. }
  863. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  864. if (!empty($errorMsg)) {
  865. Display::display_normal_message($errorMsg); //main API
  866. }
  867. $default = array();
  868. $form = new FormValidator(
  869. 'configure_homepage_'.$action,
  870. 'post',
  871. $selfUrl.'?action='.$action,
  872. '',
  873. array('style' => 'margin: 0px;')
  874. );
  875. $renderer =& $form->defaultRenderer();
  876. $renderer->setHeaderTemplate('');
  877. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  878. $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
  879. $renderer->setRequiredNoteTemplate('');
  880. $form->addElement('hidden', 'formSent', '1');
  881. if ($action == 'edit_news') {
  882. $_languages = api_get_languages();
  883. $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
  884. $html .= '<select name="news_languages">';
  885. $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>';
  886. foreach ($_languages['name'] as $key => $value) {
  887. $english_name = $_languages['folder'][$key];
  888. if ($language == $english_name) {
  889. $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
  890. } else {
  891. $html .= '<option value="'.$english_name.'">'.$value.'</option>';
  892. }
  893. }
  894. $html .= '</select></td></tr>';
  895. $form->addElement('html', $html);
  896. }
  897. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  898. $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  899. $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs'));
  900. $form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>');
  901. $currentLanguage = api_get_language_isocode();
  902. $i = 0;
  903. foreach ($_languages['name'] as $key => $value) {
  904. $lang_name = $_languages['folder'][$key];
  905. $i++;
  906. $checked = null;
  907. if ($languageGet == $lang_name) {
  908. $checked = "checked";
  909. }
  910. $html_langs = '<td width="300">';
  911. $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" />&nbsp;'.$value.'<label/>';
  912. $html_langs .= '</td>';
  913. if ($i % 5 == 0) {
  914. $html_langs .= '</tr><tr>';
  915. }
  916. $form->addElement('html', $html_langs);
  917. }
  918. $form->addElement('html','</tr></table><br/>');
  919. $form->addButtonSave(get_lang('Save'));
  920. $form->setDefaults($default);
  921. $form->display();
  922. break;
  923. default: // When no action applies, default page to update campus homepage
  924. ?>
  925. <section id="page-home">
  926. <div class="row">
  927. <div class="col-md-3">
  928. <!-- login block -->
  929. <div id="login_block" class="panel panel-default">
  930. <div class="panel-body">
  931. <?php echo api_display_language_form(); ?>
  932. <form id="formLogin" class="form-horizontal">
  933. <div class="input-group">
  934. <div class="input-group-addon"><em class="fa fa-user"></em></div>
  935. <input class="form-control" type="text" id="login" value="" disabled="disabled" />
  936. </div>
  937. <div class="input-group">
  938. <div class="input-group-addon"><em class="fa fa-lock"></em></div>
  939. <input type="password" id="password"class="form-control" value="" disabled="disabled" />
  940. </div>
  941. <button class="btn btn-primary btn-block" type="button" name="submitAuth" value="<?php echo get_lang('Ok'); ?>" disabled="disabled"><?php echo get_lang('Ok'); ?></button>
  942. </form>
  943. <ul class="nav nav-pills nav-stacked">
  944. <li><?php echo api_ucfirst(get_lang('Registration')); ?></li>
  945. <li><?php echo api_ucfirst(get_lang('LostPassword')); ?></li>
  946. </ul>
  947. </div>
  948. </div>
  949. <!-- notice block -->
  950. <div class="panel-group" id="notice-block" role="tablist" aria-multiselectable="true">
  951. <div class="panel panel-default">
  952. <div class="panel-heading" role="tab" id="headingOne">
  953. <h4 class="panel-title">
  954. <a role="button" data-toggle="collapse" data-parent="#notice-block" href="#notice-list" aria-expanded="true" aria-controls="notice-list">
  955. <?php echo get_lang('Notice'); ?>
  956. <a class="pull-right" href="<?php echo $selfUrl; ?>?action=edit_notice"><?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?></a>
  957. </a>
  958. </h4>
  959. </div>
  960. <div id="notice-list" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
  961. <div class="panel-body">
  962. <?php
  963. $home_notice = '';
  964. if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
  965. $home_notice = @(string)file_get_contents($homep.$noticef.'_'.$lang.$ext);
  966. } else {
  967. $home_notice = @(string)file_get_contents($homep.$noticef.$ext);
  968. }
  969. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  970. echo '<div class="homepage_notice">';
  971. echo $home_notice;
  972. echo '</div>';
  973. ?>
  974. </div>
  975. </div>
  976. </div>
  977. </div>
  978. <!-- insert link block -->
  979. <div class="panel-group" id="links-block" role="tablist" aria-multiselectable="true">
  980. <div class="panel panel-default">
  981. <div class="panel-heading" role="tab" id="headingOne">
  982. <h4 class="panel-title">
  983. <a role="button" data-toggle="collapse" data-parent="#links-block" href="#links-list" aria-expanded="true" aria-controls="links-list">
  984. <?php echo api_ucfirst(get_lang('General')); ?>
  985. </a>
  986. </h4>
  987. </div>
  988. <div id="links-list" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
  989. <div class="panel-body">
  990. <a href="<?php echo $selfUrl; ?>?action=insert_link"><?php echo Display::return_icon('add.png', get_lang('InsertLink')).'&nbsp;'. get_lang('InsertLink'); ?>
  991. </a>
  992. <ul class="menulist">
  993. <?php
  994. $home_menu = '';
  995. if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
  996. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  997. } else {
  998. $home_menu = @file($homep.$menuf.$ext);
  999. }
  1000. if (empty($home_menu)) {
  1001. $home_menu = array();
  1002. }
  1003. if (!empty($home_menu)) {
  1004. $home_menu = implode("\n", $home_menu);
  1005. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  1006. $home_menu = explode("\n", $home_menu);
  1007. }
  1008. $i = 0;
  1009. foreach ($home_menu as $enreg) {
  1010. $enreg = trim($enreg);
  1011. if (!empty($enreg)) {
  1012. $edit_link = '<a href="'.$selfUrl.'?action=edit_link&amp;link_index='.$i.'">'.Display::return_icon('edit.png', get_lang('Edit')).'</a>';
  1013. $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>';
  1014. 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);
  1015. $i++;
  1016. }
  1017. }
  1018. ?>
  1019. </ul>
  1020. </div>
  1021. </div>
  1022. </div>
  1023. </div>
  1024. </div>
  1025. <div class="col-md-9">
  1026. <div class="actions">
  1027. <a href="<?php echo $selfUrl; ?>?action=edit_top&language=<?php echo $languageGet; ?>">
  1028. <?php echo Display::return_icon('edit.png', get_lang('EditHomePage'),null,ICON_SIZE_SMALL).'&nbsp;'. get_lang('EditHomePage'); ?>
  1029. </a>
  1030. </div>
  1031. <section id="homepage-home">
  1032. <?php
  1033. //print home_top contents
  1034. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  1035. $home_top_temp = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
  1036. } else {
  1037. $home_top_temp = @(string)file_get_contents($homep.$topf.$ext);
  1038. }
  1039. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  1040. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  1041. echo $open;
  1042. ?>
  1043. </section>
  1044. <?php
  1045. $access_url_id = 1;
  1046. // we only show the category options for the main chamilo installation
  1047. if (api_is_multiple_url_enabled()) {
  1048. $access_url_id = api_get_current_access_url_id();
  1049. }
  1050. if ($access_url_id == 1) {
  1051. echo '<div class="actions">';
  1052. echo '<a href="course_category.php">'.Display::return_icon('edit.png', get_lang('Edit')).'&nbsp;'.get_lang('EditCategories').'</a>';
  1053. echo '</div>';
  1054. }
  1055. echo '<ul class="list-group">';
  1056. if ($access_url_id == 1) {
  1057. if (sizeof($Categories)) {
  1058. foreach ($Categories as $enreg) {
  1059. echo '<li class="list-group-item">'.Display::return_icon('folder.png', $enreg['name']).'&nbsp;'.$enreg['name'].'</li>';
  1060. }
  1061. unset($Categories);
  1062. } else {
  1063. echo get_lang('NoCategories');
  1064. }
  1065. }
  1066. echo '</ul>';
  1067. ?>
  1068. <?php
  1069. if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
  1070. $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  1071. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  1072. echo $open;
  1073. } else {
  1074. $open = @(string)file_get_contents($homep.$newsf.$ext);
  1075. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  1076. echo $open;
  1077. }
  1078. ?>
  1079. <?php
  1080. // Add new page
  1081. $home_menu = '';
  1082. if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) {
  1083. $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
  1084. } else {
  1085. $home_menu = @file($homep.$mtloggedin.$ext);
  1086. }
  1087. if (empty($home_menu)) {
  1088. if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
  1089. $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
  1090. }
  1091. }
  1092. if (empty($home_menu)) {
  1093. $home_menu = array();
  1094. }
  1095. if (!empty($home_menu)) {
  1096. $home_menu = implode("\n", $home_menu);
  1097. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  1098. $home_menu = explode("\n", $home_menu);
  1099. }
  1100. $link_list = '';
  1101. $tab_counter = 0;
  1102. foreach ($home_menu as $enreg) {
  1103. $enreg = trim($enreg);
  1104. if (!empty($enreg)) {
  1105. $edit_link = ' <a href="'.$selfUrl.'?action=edit_tabs&amp;link_index='.$tab_counter.'" ><span>'.Display::return_icon('edit.png', get_lang('Edit')).'</span></a>';
  1106. $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>';
  1107. $tab_string = str_replace(array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'),
  1108. array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=', $edit_link.$delete_link.'</li>'),
  1109. $enreg);
  1110. $tab_string = str_replace(array('<li>', '</li>','class="hide_menu"', 'hide_menu'), '', $tab_string);
  1111. $link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item'));
  1112. $tab_counter++;
  1113. }
  1114. }
  1115. ?>
  1116. <div class="actions">
  1117. <a href="<?php echo $selfUrl; ?>?action=insert_tabs">
  1118. <?php echo Display::return_icon('add.png', get_lang('InsertLink')) .'&nbsp;'. get_lang('InsertLink'); ?>
  1119. </a>
  1120. </div>
  1121. <?php
  1122. echo '<ul id="list-hiperlink" class="list-group">';
  1123. echo $link_list;
  1124. echo '</ul>';
  1125. ?>
  1126. </div>
  1127. </div>
  1128. </section>
  1129. <?php break;
  1130. }
  1131. Display::display_footer();