configure_homepage.php 40 KB

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