configure_homepage.php 51 KB

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