configure_homepage.php 39 KB

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