configure_homepage.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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. global $_configuration;
  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. // Start analysing requested actions
  127. if (!empty($action)) {
  128. if ($_POST['formSent']) {
  129. // Variables used are $homep for home path, $menuf for menu file, $newsf
  130. // for news file, $topf for top file, $noticef for noticefile,
  131. // $ext for '.html'
  132. switch ($action) {
  133. case 'edit_top':
  134. // Filter
  135. $home_top = '';
  136. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  137. $home_top = WCAG_Rendering::prepareXHTML();
  138. } else {
  139. $home_top = trim(stripslashes($_POST['home_top']));
  140. }
  141. // Write
  142. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  143. if (is_writable($homep.$topf.'_'.$lang.$ext)) {
  144. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  145. fputs($fp, $home_top);
  146. fclose($fp);
  147. } else {
  148. $errorMsg = get_lang('HomePageFilesNotWritable');
  149. }
  150. } else {
  151. //File does not exist
  152. $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
  153. fputs($fp, $home_top);
  154. fclose($fp);
  155. }
  156. break;
  157. case 'edit_notice':
  158. // Filter
  159. $notice_title = trim(strip_tags(stripslashes($_POST['notice_title'])));
  160. $notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>')));
  161. if (empty($notice_title) || empty($notice_text)) {
  162. $errorMsg = get_lang('NoticeWillBeNotDisplayed');
  163. }
  164. // Write
  165. if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
  166. if (is_writable($homep.$noticef.'_'.$lang.$ext)) {
  167. $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
  168. if ($errorMsg == '') {
  169. fputs($fp, "<b>$notice_title</b><br />\n$notice_text");
  170. } else {
  171. fputs($fp, '');
  172. }
  173. fclose($fp);
  174. } else {
  175. $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable');
  176. }
  177. } else {
  178. //File does not exist
  179. $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
  180. fputs($fp, "<b>$notice_title</b><br />\n$notice_text");
  181. fclose($fp);
  182. }
  183. break;
  184. case 'edit_news':
  185. //Filter
  186. //$s_languages_news=$_POST["news_languages"]; // TODO: Why this line has been disabled?
  187. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  188. $home_news = WCAG_rendering::prepareXHTML();
  189. } else {
  190. $home_news = trim(stripslashes($_POST['home_news']));
  191. }
  192. //Write
  193. if ($s_languages_news != 'all') {
  194. if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) {
  195. if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) {
  196. $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
  197. fputs($fp, $home_news);
  198. fclose($fp);
  199. } else {
  200. $errorMsg = get_lang('HomePageFilesNotWritable');
  201. }
  202. } else {
  203. // File does not exist
  204. $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
  205. fputs($fp, $home_news);
  206. fclose($fp);
  207. }
  208. } else {
  209. // We update all the news file
  210. $_languages = api_get_languages();
  211. foreach ($_languages['name'] as $key => $value) {
  212. $english_name = $_languages['folder'][$key];
  213. if (file_exists($homep.$newsf.'_'.$english_name.$ext)) {
  214. if (is_writable($homep.$newsf.'_'.$english_name.$ext)) {
  215. $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
  216. fputs($fp, $home_news);
  217. fclose($fp);
  218. } else {
  219. $errorMsg = get_lang('HomePageFilesNotWritable');
  220. }
  221. } else {
  222. // File does not exist
  223. $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
  224. fputs($fp, $home_news);
  225. fclose($fp);
  226. }
  227. }
  228. }
  229. break;
  230. case 'insert_tabs':
  231. case 'edit_tabs':
  232. case 'insert_link':
  233. case 'edit_link':
  234. $link_index = intval($_POST['link_index']);
  235. $insert_where = intval($_POST['insert_where']);
  236. $link_name = trim(stripslashes($_POST['link_name']));
  237. $link_url = trim(stripslashes($_POST['link_url']));
  238. $add_in_tab = intval($_POST['add_in_tab']);
  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. $class_add_in_tab = 'show_menu';
  313. if (!$add_in_tab) {
  314. $class_add_in_tab = 'class="hide_menu"';
  315. }
  316. // If the requested action is to create a link, make some room
  317. // for the new link in the home_menu array at the requested place
  318. // and insert the new link there
  319. if ($action == 'insert_link' || $action == 'insert_tabs') {
  320. for ($i = sizeof($home_menu); $i; $i--) {
  321. if ($i > $insert_where) {
  322. $home_menu[$i] = $home_menu[$i - 1];
  323. } else {
  324. break;
  325. }
  326. }
  327. $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>';
  328. } else {
  329. // If the request is about a link edition, change the link
  330. $home_menu[$link_index]='<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'"><span>'.$link_name.'</span></a></li>';
  331. }
  332. // Re-build the file from the home_menu array
  333. $home_menu = implode("\n", $home_menu);
  334. // Write
  335. if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
  336. if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
  337. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  338. fputs($fp, $home_menu);
  339. fclose($fp);
  340. if (file_exists($homep.$menuf.$ext)) {
  341. if (is_writable($homep.$menuf.$ext)) {
  342. $fpo = fopen($homep.$menuf.$ext, 'w');
  343. fputs($fpo, $home_menu);
  344. fclose($fpo);
  345. }
  346. }
  347. } else {
  348. $errorMsg = get_lang('HomePageFilesNotWritable');
  349. }
  350. } else {
  351. //File does not exist
  352. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  353. fputs($fp, $home_menu);
  354. fclose($fp);
  355. }
  356. }
  357. break;
  358. } //end of switch($action)
  359. if (empty($errorMsg)) {
  360. header('Location: '.api_get_self());
  361. exit();
  362. }
  363. } else {
  364. //if POST[formSent] is not set
  365. switch ($action) {
  366. case 'open_link':
  367. // Previously, filtering of GET['link'] was done here but it left
  368. // a security threat. Filtering has now been moved outside conditions
  369. break;
  370. case 'delete_tabs':
  371. case 'delete_link':
  372. // A link is deleted by getting the file into an array, removing the
  373. // link and re-writing the array to the file
  374. $link_index = intval($_GET['link_index']);
  375. $menuf = ($action == 'delete_tabs')? $menutabs : $menuf;
  376. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  377. if (empty($home_menu)) {
  378. $home_menu = array();
  379. }
  380. foreach ($home_menu as $key => $enreg) {
  381. if ($key == $link_index) {
  382. unset($home_menu[$key]);
  383. } else {
  384. $home_menu[$key] = trim($enreg);
  385. }
  386. }
  387. $home_menu = implode("\n", $home_menu);
  388. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  389. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  390. fputs($fp, $home_menu);
  391. fclose($fp);
  392. if (file_exists($homep.$menuf.$ext)) {
  393. if (is_writable($homep.$menuf.$ext)) {
  394. $fpo = fopen($homep.$menuf.$ext,'w');
  395. fputs($fpo, $home_menu);
  396. fclose($fpo);
  397. }
  398. }
  399. header('Location: '.api_get_self());
  400. exit();
  401. break;
  402. case 'edit_top':
  403. // This request is only the preparation for the update of the home_top
  404. $home_top = '';
  405. if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
  406. $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
  407. } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
  408. $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext);
  409. } else {
  410. $errorMsg = get_lang('HomePageFilesNotReadable');
  411. }
  412. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  413. break;
  414. case 'edit_notice':
  415. // This request is only the preparation for the update of the home_notice
  416. $home_notice = '';
  417. if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) {
  418. $home_notice = @file($homep.$noticef.'_'.$lang.$ext);
  419. } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) {
  420. $home_notice = @file($homep.$noticef.$lang.$ext);
  421. } else {
  422. $errorMsg = get_lang('HomePageFilesNotReadable');
  423. }
  424. if (empty($home_notice)) {
  425. $home_notice = array();
  426. }
  427. $notice_title = strip_tags($home_notice[0]);
  428. $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title));
  429. $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>');
  430. $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text)));
  431. break;
  432. case 'edit_news':
  433. // This request is the preparation for the update of the home_news page
  434. $home_news = '';
  435. if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
  436. $home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  437. } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
  438. $home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext);
  439. } else {
  440. $errorMsg = get_lang('HomePageFilesNotReadable');
  441. }
  442. $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news)));
  443. break;
  444. case 'insert_link':
  445. // This request is the preparation for the addition of an item in home_menu
  446. $home_menu = '';
  447. $menuf = ($action == 'edit_tabs')? $menutabs : $menuf;
  448. if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
  449. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  450. } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
  451. $home_menu = @file($homep.$menuf.$lang.$ext);
  452. } else {
  453. $errorMsg = get_lang('HomePageFilesNotReadable');
  454. }
  455. if (empty($home_menu)) {
  456. $home_menu = array();
  457. }
  458. if (!empty($home_menu)) {
  459. $home_menu = implode("\n", $home_menu);
  460. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  461. $home_menu = explode("\n", $home_menu);
  462. }
  463. $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
  464. break;
  465. case 'insert_tabs':
  466. // This request is the preparation for the addition of an item in home_menu
  467. $home_menu = '';
  468. if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
  469. $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
  470. } elseif (is_file($homep.$menutabs.$lang.$ext) && is_readable($homep.$menutabs.$lang.$ext)) {
  471. $home_menu = @file($homep.$menutabs.$lang.$ext);
  472. } else {
  473. $errorMsg = get_lang('HomePageFilesNotReadable');
  474. }
  475. if (empty($home_menu)) {
  476. $home_menu = array();
  477. }
  478. if (!empty($home_menu)) {
  479. $home_menu = implode("\n", $home_menu);
  480. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  481. $home_menu = explode("\n", $home_menu);
  482. }
  483. $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
  484. break;
  485. case 'edit_tabs':
  486. case 'edit_link':
  487. // This request is the preparation for the edition of the links array
  488. $home_menu = '';
  489. $menuf = ($action == 'edit_tabs')? $menutabs : $menuf;
  490. if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
  491. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  492. } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
  493. $home_menu = @file($homep.$menuf.$lang.$ext);
  494. } else {
  495. $errorMsg = get_lang('HomePageFilesNotReadable');
  496. }
  497. if (empty($home_menu)) {
  498. $home_menu = array();
  499. }
  500. if (!empty($home_menu)) {
  501. $home_menu = implode("\n", $home_menu);
  502. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  503. $home_menu = explode("\n", $home_menu);
  504. }
  505. $link_index = intval($_GET['link_index']);
  506. $target_blank = false;
  507. $link_name = '';
  508. $link_url = '';
  509. //$home_menu_new = array();
  510. //
  511. //Cleaning array
  512. //foreach ($home_menu as $item) {
  513. // if(!empty($item)) {
  514. // $home_menu_new[] = $item;
  515. // }
  516. //}
  517. //$home_menu = $home_menu_new;
  518. // Cleaning the array
  519. $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
  520. // For each line of the home_menu file
  521. foreach ($home_menu as $key => $enreg) {
  522. // Check if the current item is the one we want to update
  523. if ($key == $link_index) {
  524. // This is the link we want to update
  525. // Check if the target should be "_blank"
  526. if (strstr($enreg, 'target="_blank"')) {
  527. $target_blank = true;
  528. }
  529. if (strstr($enreg, 'hide_menu')) {
  530. $add_in_tab = false;
  531. } else {
  532. $add_in_tab = true;
  533. }
  534. // Remove dangerous HTML tags from the link itself (this is an
  535. // additional measure in case a link previously contained
  536. // unsecure tags)
  537. $link_name = strip_tags($enreg);
  538. // Get the contents of "href" attribute in $link_url
  539. $enreg = explode('href="',$enreg);
  540. list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
  541. // If the link contains the web root of this portal, then strip
  542. // it off and keep only the name of the file that needs edition
  543. if (strstr($link_url, $_configuration['root_web']) && strstr($link_url, '?include=')) {
  544. $link_url = explode('?include=', $link_url);
  545. $filename = $link_url[sizeof($link_url) - 1];
  546. if (!strstr($filename, '/') && strstr($filename, '.html')) {
  547. // Get oonly the contents of the link file
  548. $link_html = @file($homep.$filename);
  549. $link_html = implode('', $link_html);
  550. $link_url = '';
  551. } else {
  552. $filename = '';
  553. }
  554. }
  555. break;
  556. }
  557. }
  558. break;
  559. }//end of second switch($action) (when POST['formSent'] was not set, yet)
  560. }// end of "else" in if($_POST['formSent']) condition
  561. } else {
  562. //if $action is empty, then prepare a list of the course categories to display (?)
  563. $Categories = Database::store_result(Database::query("SELECT name FROM $tbl_category WHERE parent_id IS NULL ORDER BY tree_pos"));
  564. }
  565. // Display section
  566. Display::display_header($tool_name);
  567. //api_display_tool_title($tool_name);
  568. switch ($action) {
  569. case 'open_link':
  570. if (!empty($link)) {
  571. // $link is only set in case of action=open_link and is filtered
  572. $open = @(string)file_get_contents($homep.$link);
  573. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  574. echo $open;
  575. }
  576. break;
  577. case 'edit_notice':
  578. // Display for edit_notice case
  579. ?>
  580. <form action="<?php echo api_get_self(); ?>?action=<?php echo $action; ?>" method="post" style="margin:0px;">
  581. <div class="row"><div class="form_header"><?php echo $tool_name; ?></div></div>
  582. <input type="hidden" name="formSent" value="1"/>
  583. <?php
  584. if (!empty($errorMsg)) {
  585. Display::display_normal_message($errorMsg);
  586. }
  587. ?>
  588. <table border="0" cellpadding="5" cellspacing="0">
  589. <tr><td colspan="2"><?php echo '<span style="font-style: italic;">'.get_lang('LetThoseFieldsEmptyToHideTheNotice').'</span>'; ?></tr>
  590. <tr>
  591. <td nowrap="nowrap"><?php echo get_lang('NoticeTitle'); ?> :</td>
  592. <td><input type="text" name="notice_title" size="30" maxlength="50" value="<?php echo $notice_title; ?>" style="width: 350px;"/></td>
  593. </tr>
  594. <tr>
  595. <td nowrap="nowrap" valign="top"><?php echo get_lang('NoticeText'); ?> :</td>
  596. <td><textarea name="notice_text" cols="30" rows="5" wrap="virtual" style="width: 350px;"><?php echo $notice_text; ?></textarea></td>
  597. </tr>
  598. <tr>
  599. <td>&nbsp;</td>
  600. <td><button class="save" type="submit" value="<?php echo get_lang('Ok'); ?>"><?php echo get_lang('Ok'); ?></button></td>
  601. </tr>
  602. </table>
  603. </form>
  604. <?php
  605. break;
  606. case 'insert_tabs':
  607. case 'edit_tabs':
  608. case 'insert_link':
  609. case 'edit_link':
  610. if (!empty($errorMsg)) {
  611. Display::display_normal_message($errorMsg);
  612. }
  613. $default = array();
  614. $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  615. $renderer =& $form->defaultRenderer();
  616. $form->addElement('header', '', $tool_name);
  617. $form->addElement('hidden', 'formSent', '1');
  618. $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
  619. $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? $filename : '');
  620. $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
  621. $default['link_name'] = $link_name;
  622. $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
  623. $form->addElement('text', 'link_url', array(get_lang('LinkURL'), get_lang('Optional')), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
  624. $options = array('-1' => get_lang('FirstPlace'));
  625. $selected = '';
  626. if ($action == 'insert_link' || $action == 'insert_tabs') {
  627. $add_in_tab = 1;
  628. if (is_array($home_menu)){
  629. foreach ($home_menu as $key => $enreg) {
  630. if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
  631. $options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
  632. $selected = $formSent && $insert_where == $key ? $key : '';
  633. }
  634. }
  635. }
  636. $default['insert_link'] = $selected;
  637. $form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options);
  638. }
  639. $target_blank_checkbox = & $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
  640. if ($action == 'insert_tabs' || $action == 'edit_tabs') {
  641. $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1);
  642. $default['add_in_tab'] = $add_in_tab;
  643. }
  644. if ($target_blank) $target_blank_checkbox->setChecked(true);
  645. if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://')) {
  646. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  647. $form->addElement('html', WCAG_Rendering::create_xhtml(isset($_POST['link_html'])?$_POST['link_html']:$link_html));
  648. } else {
  649. $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
  650. $form->add_html_editor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  651. }
  652. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  653. } else {
  654. if (in_array($action, array('edit_tabs','insert_tabs'))) {
  655. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  656. $form->addElement('html', get_lang('Content').' ('.get_lang('Optional').')');
  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', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  661. }
  662. }
  663. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  664. }
  665. $form->setDefaults($default);
  666. $form->display();
  667. break;
  668. case 'edit_top':
  669. case 'edit_news':
  670. if ($action == 'edit_top') {
  671. $name = $topf;
  672. $open = $home_top;
  673. } else {
  674. $name = $newsf;
  675. $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  676. }
  677. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  678. if (!empty($errorMsg)) {
  679. Display::display_normal_message($errorMsg); //main API
  680. }
  681. $default = array();
  682. $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  683. $renderer =& $form->defaultRenderer();
  684. $renderer->setHeaderTemplate('');
  685. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  686. $renderer->setElementTemplate('<tr><td>{element}</td></tr>');
  687. $renderer->setRequiredNoteTemplate('');
  688. $form->addElement('hidden', 'formSent', '1');
  689. if ($action == 'edit_news'){
  690. $_languages = api_get_languages();
  691. $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
  692. $html .= '<select name="news_languages">';
  693. $html .= '<option value="all">'.get_lang('AllLanguages').'</option>';
  694. foreach ($_languages['name'] as $key => $value) {
  695. $english_name = $_languages['folder'][$key];
  696. if ($language == $english_name) {
  697. $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
  698. } else {
  699. $html .= '<option value="'.$english_name.'">'.$value.'</option>';
  700. }
  701. }
  702. $html .= '</select></td></tr>';
  703. $form->addElement('html', $html);
  704. }
  705. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  706. //TODO: review these lines
  707. // Print WCAG-specific HTML editor
  708. $html = '<tr><td>';
  709. $html .= WCAG_Rendering::create_xhtml($open);
  710. $html .= '</td></tr>';
  711. $form->addElement('html', $html);
  712. } else {
  713. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  714. $form->add_html_editor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  715. }
  716. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  717. $form->setDefaults($default);
  718. $form->display();
  719. break;
  720. default: // When no action applies, default page to update campus homepage
  721. ?>
  722. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  723. <tr>
  724. <td width="70%" valign="top">
  725. <div class="actions">
  726. <a href="<?php echo api_get_self(); ?>?action=edit_top"><?php Display::display_icon('edit.gif', get_lang('EditHomePage')); ?></a>
  727. <a href="<?php echo api_get_self(); ?>?action=edit_top"><?php echo get_lang('EditHomePage'); ?></a>
  728. </div>
  729. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  730. <tr>
  731. <td colspan="2">
  732. <?php
  733. //print home_top contents
  734. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  735. $home_top_temp = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
  736. } else {
  737. $home_top_temp = @(string)file_get_contents($homep.$topf.$ext);
  738. }
  739. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  740. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  741. echo $open;
  742. ?>
  743. </td>
  744. </tr>
  745. <tr>
  746. <?php
  747. $access_url_id = 1;
  748. // we only show the category options for the main chamilo installation
  749. if ($_configuration['multiple_access_urls']) {
  750. $access_url_id = api_get_current_access_url_id();
  751. }
  752. echo '<td width="50%">';
  753. if ($access_url_id == 1) {
  754. echo '<div class="actions">';
  755. echo '<a href="course_category.php">'.Display::display_icon('edit.gif', get_lang('Edit')).'</a>
  756. <a href="course_category.php">'.get_lang('EditCategories').'</a>';
  757. echo '</div>';
  758. }
  759. echo '</td>
  760. <td width="50%">
  761. <br />';
  762. /* <!--<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>--> */
  763. echo '</td></tr>
  764. <tr>
  765. <td width="50%" valign="top">
  766. <table border="0" cellpadding="5" cellspacing="0" width="100%">';
  767. if ($access_url_id == 1) {
  768. if (sizeof($Categories)) {
  769. foreach ($Categories as $enreg) {
  770. echo '<tr><td>'.Display::return_icon('folder_document.gif', $enreg['name']).'&nbsp;'.$enreg['name'].'</td></tr>';
  771. }
  772. unset($Categories);
  773. } else {
  774. echo get_lang('NoCategories');
  775. }
  776. }
  777. echo '</table>';
  778. ?>
  779. </td>
  780. <!--<td width="50%" valign="top">
  781. <?php
  782. if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
  783. $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  784. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  785. echo $open;
  786. } else {
  787. $open = @(string)file_get_contents($homep.$newsf.$ext);
  788. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  789. echo $open;
  790. }
  791. ?>
  792. </td>-->
  793. </tr>
  794. </table>
  795. <?php
  796. // Add new page
  797. $home_menu = '';
  798. if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
  799. $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
  800. } else {
  801. $home_menu = @file($homep.$menutabs.$ext);
  802. }
  803. if (empty($home_menu)) {
  804. $home_menu = array();
  805. }
  806. if (!empty($home_menu)) {
  807. $home_menu = implode("\n", $home_menu);
  808. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  809. $home_menu = explode("\n", $home_menu);
  810. }
  811. $link_list = '';
  812. $tab_counter = 0;
  813. foreach ($home_menu as $enreg) {
  814. $enreg = trim($enreg);
  815. if (!empty($enreg)) {
  816. $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>';
  817. $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>';
  818. $tab_string = str_replace(array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'),
  819. array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename(api_get_self()).'?action=open_link&link=', $edit_link.$delete_link.'</li>'),
  820. $enreg);
  821. $tab_string = str_replace(array('<li>', '</li>','class="hide_menu"', 'hide_menu'), '', $tab_string);
  822. $link_list .= Display::tag('tr', Display::tag('td', $tab_string));
  823. $tab_counter++;
  824. }
  825. }
  826. ?>
  827. <div class="actions">
  828. <a href="<?php echo api_get_self(); ?>?action=insert_tabs"><?php Display::display_icon('addd.gif', get_lang('InsertLink')); echo get_lang('InsertLink'); ?></a>
  829. </div>
  830. <?php
  831. echo '<table class="data_table">';
  832. echo $link_list;
  833. echo '</table>';
  834. ?>
  835. </td>
  836. <td width="10%" valign="top"></td>
  837. <td width="20%" rowspan="3" valign="top">
  838. <div id="menu-wrapper">
  839. <div id="menu" class="menu">
  840. <?php echo api_display_language_form(); ?>
  841. <form id="formLogin">
  842. <div><label><?php echo get_lang('LoginName'); ?></label></div>
  843. <div><input type="text" id="login" size="15" value="" disabled="disabled" /></div>
  844. <div><label><?php echo get_lang('UserPassword'); ?></label></div>
  845. <div><input type="password" id="password" size="15" value="" disabled="disabled" /></div>
  846. <div><button class="login" type="button" name="submitAuth" value="<?php echo get_lang('Ok'); ?>" disabled="disabled"><?php echo get_lang('Ok'); ?></button></div>
  847. </form>
  848. <div class="clear"> &nbsp; </div>
  849. <div class="menusection">
  850. <span class="menusectioncaption"><?php echo get_lang('MenuUser'); ?></span>
  851. <ul class="menulist">
  852. <li><span style="color: #9D9DA1; font-weight: bold;"><?php echo api_ucfirst(get_lang('Registration')); ?></span></li>
  853. <li><span style="color: #9D9DA1; font-weight: bold;"><?php echo api_ucfirst(get_lang('LostPassword')); ?></span></li>
  854. </ul>
  855. </div>
  856. </div>
  857. <div id="menu" class="menu">
  858. <div class="menusection">
  859. <span class="menusectioncaption">
  860. <?php echo get_lang('Notice'); ?>
  861. <a href="<?php echo api_get_self(); ?>?action=edit_notice">
  862. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?></a>
  863. </span>
  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 '<div class="homepage_notice">';
  873. echo $home_notice;
  874. echo '</div>';
  875. ?>
  876. </div>
  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();