configure_homepage.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file = array('admin', 'accessibility');
  4. $cidReset = true;
  5. require '../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. // Prepare place to insert the new link into (default is end of file)
  276. if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) {
  277. $insert_where = sizeof($home_menu) - 1;
  278. }
  279. // For each line of the file, remove trailing spaces and special chars
  280. foreach ($home_menu as $key => $enreg) {
  281. $home_menu[$key] = trim($enreg);
  282. }
  283. // If the given link url is empty, then replace the link url by a link to the link file created
  284. if (empty($link_url)) {
  285. $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
  286. // If the file doesn't exist, then create it and
  287. // fill it with default text
  288. if (!file_exists(api_get_path(SYS_PATH).'home/'.$filename)) {
  289. $fp = @fopen(api_get_path(SYS_PATH).'home/'.$filename, 'w');
  290. if ($fp) {
  291. fputs($fp, get_lang('MyTextHere'));
  292. fclose($fp);
  293. }
  294. }
  295. }
  296. // If the requested action is to edit a link, open the file and
  297. // write to it (if the file doesn't exist, create it)
  298. if ($action == 'edit_link' && !empty($link_html)) {
  299. $fp = @fopen(api_get_path(SYS_PATH).'home/'.$filename, 'w');
  300. if ($fp) {
  301. fputs($fp, $link_html);
  302. fclose($fp);
  303. }
  304. }
  305. // If the requested action is to create a link, make some room
  306. // for the new link in the home_menu array at the requested place
  307. // and insert the new link there
  308. if ($action == 'insert_link' || $action == 'insert_tabs') {
  309. for ($i = sizeof($home_menu); $i; $i--) {
  310. if ($i > $insert_where) {
  311. $home_menu[$i] = $home_menu[$i - 1];
  312. } else {
  313. break;
  314. }
  315. }
  316. $home_menu[$insert_where + 1] = '<li><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'"><span>'.$link_name.'</span></a></li>';
  317. } else {
  318. // If the request is about a link edition, change the link
  319. $home_menu[$link_index]='<li><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'"><span>'.$link_name.'</span></a></li>';
  320. }
  321. // Re-build the file from the home_menu array
  322. $home_menu = implode("\n", $home_menu);
  323. // Write
  324. if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
  325. if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
  326. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  327. fputs($fp, $home_menu);
  328. fclose($fp);
  329. if (file_exists($homep.$menuf.$ext)) {
  330. if (is_writable($homep.$menuf.$ext)) {
  331. $fpo = fopen($homep.$menuf.$ext, 'w');
  332. fputs($fpo, $home_menu);
  333. fclose($fpo);
  334. }
  335. }
  336. } else {
  337. $errorMsg = get_lang('HomePageFilesNotWritable');
  338. }
  339. } else {
  340. //File does not exist
  341. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  342. fputs($fp, $home_menu);
  343. fclose($fp);
  344. }
  345. }
  346. break;
  347. } //end of switch($action)
  348. if (empty($errorMsg)) {
  349. header('Location: '.api_get_self());
  350. exit();
  351. }
  352. } else {
  353. //if POST[formSent] is not set
  354. switch ($action) {
  355. case 'open_link':
  356. // Previously, filtering of GET['link'] was done here but it left
  357. // a security threat. Filtering has now been moved outside conditions
  358. break;
  359. case 'delete_tabs':
  360. case 'delete_link':
  361. // A link is deleted by getting the file into an array, removing the
  362. // link and re-writing the array to the file
  363. $link_index = intval($_GET['link_index']);
  364. $menuf = ($action == 'delete_tabs')? $menutabs : $menuf;
  365. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  366. if (empty($home_menu)) {
  367. $home_menu = array();
  368. }
  369. foreach ($home_menu as $key => $enreg) {
  370. if ($key == $link_index) {
  371. unset($home_menu[$key]);
  372. } else {
  373. $home_menu[$key] = trim($enreg);
  374. }
  375. }
  376. $home_menu = implode("\n", $home_menu);
  377. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  378. $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
  379. fputs($fp, $home_menu);
  380. fclose($fp);
  381. if (file_exists($homep.$menuf.$ext)) {
  382. if (is_writable($homep.$menuf.$ext)) {
  383. $fpo = fopen($homep.$menuf.$ext,'w');
  384. fputs($fpo, $home_menu);
  385. fclose($fpo);
  386. }
  387. }
  388. header('Location: '.api_get_self());
  389. exit();
  390. break;
  391. case 'edit_top':
  392. // This request is only the preparation for the update of the home_top
  393. $home_top = '';
  394. if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
  395. $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
  396. } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
  397. $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext);
  398. } else {
  399. $errorMsg = get_lang('HomePageFilesNotReadable');
  400. }
  401. $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
  402. break;
  403. case 'edit_notice':
  404. // This request is only the preparation for the update of the home_notice
  405. $home_notice = '';
  406. if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) {
  407. $home_notice = @file($homep.$noticef.'_'.$lang.$ext);
  408. } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) {
  409. $home_notice = @file($homep.$noticef.$lang.$ext);
  410. } else {
  411. $errorMsg = get_lang('HomePageFilesNotReadable');
  412. }
  413. if (empty($home_notice)) {
  414. $home_notice = array();
  415. }
  416. $notice_title = strip_tags($home_notice[0]);
  417. $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title));
  418. $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>');
  419. $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text)));
  420. break;
  421. case 'edit_news':
  422. // This request is the preparation for the update of the home_news page
  423. $home_news = '';
  424. if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
  425. $home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  426. } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
  427. $home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext);
  428. } else {
  429. $errorMsg = get_lang('HomePageFilesNotReadable');
  430. }
  431. $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news)));
  432. break;
  433. case 'insert_link':
  434. // This request is the preparation for the addition of an item in home_menu
  435. $home_menu = '';
  436. $menuf = ($action == 'edit_tabs')? $menutabs : $menuf;
  437. if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
  438. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  439. } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
  440. $home_menu = @file($homep.$menuf.$lang.$ext);
  441. } else {
  442. $errorMsg = get_lang('HomePageFilesNotReadable');
  443. }
  444. if (empty($home_menu)) {
  445. $home_menu = array();
  446. }
  447. if (!empty($home_menu)) {
  448. $home_menu = implode("\n", $home_menu);
  449. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  450. $home_menu = explode("\n", $home_menu);
  451. }
  452. break;
  453. case 'insert_tabs':
  454. // This request is the preparation for the addition of an item in home_menu
  455. $home_menu = '';
  456. if (is_file($homep.$menutabs.'_'.$lang.$ext) && is_readable($homep.$menutabs.'_'.$lang.$ext)) {
  457. $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
  458. } elseif (is_file($homep.$menutabs.$lang.$ext) && is_readable($homep.$menutabs.$lang.$ext)) {
  459. $home_menu = @file($homep.$menutabs.$lang.$ext);
  460. } else {
  461. $errorMsg = get_lang('HomePageFilesNotReadable');
  462. }
  463. if (empty($home_menu)) {
  464. $home_menu = array();
  465. }
  466. if (!empty($home_menu)) {
  467. $home_menu = implode("\n", $home_menu);
  468. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  469. $home_menu = explode("\n", $home_menu);
  470. }
  471. break;
  472. case 'edit_tabs':
  473. case 'edit_link':
  474. // This request is the preparation for the edition of the links array
  475. $home_menu = '';
  476. $menuf = ($action == 'edit_tabs')? $menutabs : $menuf;
  477. if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
  478. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  479. } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
  480. $home_menu = @file($homep.$menuf.$lang.$ext);
  481. } else {
  482. $errorMsg = get_lang('HomePageFilesNotReadable');
  483. }
  484. if (empty($home_menu)) {
  485. $home_menu = array();
  486. }
  487. if (!empty($home_menu)) {
  488. $home_menu = implode("\n", $home_menu);
  489. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  490. $home_menu = explode("\n", $home_menu);
  491. }
  492. $link_index = intval($_GET['link_index']);
  493. $target_blank = false;
  494. $link_name = '';
  495. $link_url = '';
  496. // For each line of the home_menu file
  497. foreach ($home_menu as $key => $enreg) {
  498. // Check if the current item is the one we want to update
  499. if ($key == $link_index) {
  500. // This is the link we want to update
  501. // Check if the target should be "_blank"
  502. if (strstr($enreg, 'target="_blank"')) {
  503. $target_blank = true;
  504. }
  505. // Remove dangerous HTML tags from the link itself (this is an
  506. // additional measure in case a link previously contained
  507. // unsecure tags)
  508. $link_name = strip_tags($enreg);
  509. // Get the contents of "href" attribute in $link_url
  510. $enreg = explode('href="',$enreg);
  511. list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
  512. // If the link contains the web root of this portal, then strip
  513. // it off and keep only the name of the file that needs edition
  514. if (strstr($link_url, $_configuration['root_web']) && strstr($link_url, '?include=')) {
  515. $link_url = explode('?include=', $link_url);
  516. $filename = $link_url[sizeof($link_url) - 1];
  517. if (!strstr($filename, '/') && strstr($filename, '.html')) {
  518. // Get oonly the contents of the link file
  519. $link_html = @file(api_get_path(SYS_PATH).'home/'.$filename);
  520. $link_html = implode('', $link_html);
  521. $link_url = '';
  522. } else {
  523. $filename = '';
  524. }
  525. }
  526. break;
  527. }
  528. }
  529. break;
  530. }//end of second switch($action) (when POST['formSent'] was not set, yet)
  531. }// end of "else" in if($_POST['formSent']) condition
  532. } else {
  533. //if $action is empty, then prepare a list of the course categories to display (?)
  534. $Categories = Database::store_result(Database::query("SELECT name FROM $tbl_category WHERE parent_id IS NULL ORDER BY tree_pos"));
  535. }
  536. // Display section
  537. Display::display_header($tool_name);
  538. //api_display_tool_title($tool_name);
  539. switch ($action) {
  540. case 'open_link':
  541. if (!empty($link)) {
  542. // $link is only set in case of action=open_link and is filtered
  543. $open = @(string)file_get_contents($homep.$link);
  544. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  545. echo $open;
  546. }
  547. break;
  548. case 'edit_notice':
  549. // Display for edit_notice case
  550. ?>
  551. <form action="<?php echo api_get_self(); ?>?action=<?php echo $action; ?>" method="post" style="margin:0px;">
  552. <div class="row"><div class="form_header"><?php echo $tool_name; ?></div></div>
  553. <input type="hidden" name="formSent" value="1"/>
  554. <?php
  555. if (!empty($errorMsg)) {
  556. //echo '<tr><td colspan="2">';
  557. Display::display_normal_message($errorMsg);
  558. //echo '</td></tr>';
  559. }
  560. ?>
  561. <table border="0" cellpadding="5" cellspacing="0">
  562. <tr><td colspan="2"><?php echo '<span style="font-style: italic;">'.get_lang('LetThoseFieldsEmptyToHideTheNotice').'</span>'; ?></tr>
  563. <tr>
  564. <td nowrap="nowrap"><?php echo get_lang('NoticeTitle'); ?> :</td>
  565. <td><input type="text" name="notice_title" size="30" maxlength="50" value="<?php echo $notice_title; ?>" style="width: 350px;"/></td>
  566. </tr>
  567. <tr>
  568. <td nowrap="nowrap" valign="top"><?php echo get_lang('NoticeText'); ?> :</td>
  569. <td><textarea name="notice_text" cols="30" rows="5" wrap="virtual" style="width: 350px;"><?php echo $notice_text; ?></textarea></td>
  570. </tr>
  571. <tr>
  572. <td>&nbsp;</td>
  573. <td><button class="save" type="submit" value="<?php echo get_lang('Ok'); ?>"/><?php echo get_lang('Ok'); ?></button></td>
  574. </tr>
  575. </table>
  576. </form>
  577. <?php
  578. break;
  579. case 'insert_tabs':
  580. case 'edit_tabs':
  581. case 'insert_link':
  582. case 'edit_link':
  583. if (!empty($errorMsg)) {
  584. Display::display_normal_message($errorMsg);
  585. }
  586. $default = array();
  587. $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  588. $renderer =& $form->defaultRenderer();
  589. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  590. $renderer->setElementTemplate('{element}');
  591. $renderer->setRequiredNoteTemplate('');
  592. $form->addElement('header', '', $tool_name);
  593. $form->addElement('hidden', 'formSent', '1');
  594. $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
  595. $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? $filename : '');
  596. $form->addElement('html', '<tr><td nowrap="nowrap" style="width: 15%;">'.get_lang('LinkName').' :</td><td>');
  597. $default['link_name'] = $link_name;
  598. $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
  599. $form->addElement('html', '</td></tr>');
  600. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('LinkURL').' ('.get_lang('Optional').') :</td><td>');
  601. $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
  602. $form->addElement('text', 'link_url', get_lang('LinkName'), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
  603. $form->addElement('html', '</td></tr>');
  604. if ($action == 'insert_link' || $action == 'insert_tabs') {
  605. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('InsertThisLink').' :</td>');
  606. $form->addElement('html', '<td><select name="insert_where"><option value="-1">'.get_lang('FirstPlace').'</option>');
  607. if (is_array($home_menu)){
  608. foreach ($home_menu as $key => $enreg) {
  609. $form->addElement('html', '<option value="'.$key.'" '.($formSent && $insert_where == $key ? 'selected="selected"' : '').' >'.get_lang('After').' &quot;'.trim(strip_tags($enreg)).'&quot;</option>');
  610. }
  611. }
  612. $form->addElement('html', '</select></td></tr>');
  613. }
  614. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('OpenInNewWindow').'</td><td>');
  615. $target_blank_checkbox = & $form->addElement('checkbox', 'target_blank', '', '&nbsp;'.get_lang('Yes'), 1);
  616. if ($target_blank) $target_blank_checkbox->setChecked(true);
  617. $form->addElement('html', '</td></tr>');
  618. //if($action == 'edit_link' && empty($link_url))
  619. if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://')) {
  620. $form->addElement('html', '</table><table border="0" cellpadding="5" cellspacing="0" width="100%"><tr><td>');
  621. $form->addElement('html', '</td></tr><tr><td>');
  622. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  623. $form->addElement('html', WCAG_Rendering::create_xhtml(isset($_POST['link_html'])?$_POST['link_html']:$link_html));
  624. } else {
  625. $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
  626. $form->add_html_editor('link_html', '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  627. }
  628. $form->addElement('html', '</td></tr><tr><td>');
  629. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  630. $form->addElement('html', '</td></tr>');
  631. } else {
  632. $form->addElement('html', '<tr><td>&nbsp;</td><td>');
  633. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  634. $form->addElement('html', '</td></tr>');
  635. }
  636. $form->setDefaults($default);
  637. $form->display();
  638. break;
  639. case 'edit_top':
  640. case 'edit_news':
  641. if ($action == 'edit_top') {
  642. $name = $topf;
  643. $open = $home_top;
  644. } else {
  645. $name = $newsf;
  646. $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  647. }
  648. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  649. if (!empty($errorMsg)) {
  650. Display::display_normal_message($errorMsg); //main API
  651. }
  652. $default = array();
  653. $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  654. $renderer =& $form->defaultRenderer();
  655. $renderer->setHeaderTemplate('');
  656. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  657. $renderer->setElementTemplate('<tr><td>{element}</td></tr>');
  658. $renderer->setRequiredNoteTemplate('');
  659. $form->addElement('hidden', 'formSent', '1');
  660. if ($action == 'edit_news'){
  661. $_languages = api_get_languages();
  662. $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
  663. $html .= '<select name="news_languages">';
  664. $html .= '<option value="all">'.get_lang('AllLanguages').'</option>';
  665. foreach ($_languages['name'] as $key => $value) {
  666. $english_name = $_languages['folder'][$key];
  667. if ($language == $english_name) {
  668. $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
  669. } else {
  670. $html .= '<option value="'.$english_name.'">'.$value.'</option>';
  671. }
  672. }
  673. $html .= '</select></td></tr>';
  674. $form->addElement('html', $html);
  675. }
  676. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  677. //TODO: review these lines
  678. // Print WCAG-specific HTML editor
  679. $html = '<tr><td>';
  680. $html .= WCAG_Rendering::create_xhtml($open);
  681. $html .= '</td></tr>';
  682. $form->addElement('html', $html);
  683. } else {
  684. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  685. $form->add_html_editor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  686. }
  687. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  688. $form->setDefaults($default);
  689. $form->display();
  690. break;
  691. default: // When no action applies, default page to update campus homepage
  692. ?>
  693. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  694. <tr>
  695. <td width="80%" colspan="2" valign="top">
  696. <div class="actions">
  697. <a href="<?php echo api_get_self(); ?>?action=edit_top"><?php Display::display_icon('edit.gif', get_lang('EditHomePage')); ?></a>
  698. <a href="<?php echo api_get_self(); ?>?action=edit_top"><?php echo get_lang('EditHomePage'); ?></a>
  699. </div>
  700. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  701. <tr>
  702. <td colspan="2">
  703. <?php
  704. //print home_top contents
  705. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  706. $home_top_temp = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
  707. } else {
  708. $home_top_temp = @(string)file_get_contents($homep.$topf.$ext);
  709. }
  710. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  711. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  712. echo $open;
  713. ?>
  714. </td>
  715. </tr>
  716. <tr>
  717. <?php
  718. $access_url_id = 1;
  719. // we only show the category options for the main Dokeos installation
  720. if ($_configuration['multiple_access_urls']) {
  721. $access_url_id = api_get_current_access_url_id();
  722. }
  723. echo '<td width="50%">';
  724. if ($access_url_id == 1) {
  725. echo '<div class="actions">';
  726. echo '<a href="course_category.php">'.Display::display_icon('edit.gif', get_lang('Edit')).'</a>
  727. <a href="course_category.php">'.get_lang('EditCategories').'</a>';
  728. echo '</div>';
  729. }
  730. echo '</td>
  731. <td width="50%">
  732. <br />';
  733. /* <!--<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>--> */
  734. echo '</td></tr>
  735. <tr>
  736. <td width="50%" valign="top">
  737. <table border="0" cellpadding="5" cellspacing="0" width="100%">';
  738. if ($access_url_id == 1) {
  739. if (sizeof($Categories)) {
  740. foreach ($Categories as $enreg) {
  741. echo '<tr><td>'.Display::return_icon('folder_document.gif', $enreg['name']).'&nbsp;'.$enreg['name'].'</td></tr>';
  742. }
  743. unset($Categories);
  744. } else {
  745. echo get_lang('NoCategories');
  746. }
  747. }
  748. echo '</table>';
  749. ?>
  750. </td>
  751. <!--<td width="50%" valign="top">
  752. <?php
  753. if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
  754. $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
  755. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  756. echo $open;
  757. } else {
  758. $open = @(string)file_get_contents($homep.$newsf.$ext);
  759. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  760. echo $open;
  761. }
  762. ?>
  763. </td>-->
  764. </tr>
  765. </table>
  766. </td>
  767. <td width="20%" rowspan="3" valign="top">
  768. <div class="menu" style="width: 100%;">
  769. <?php
  770. api_display_language_form();
  771. ?>
  772. <form id="loginform">
  773. <table cellpadding="0">
  774. <tr>
  775. <td><label><?php echo get_lang('LoginName'); ?></label></td>
  776. <td><input type="text" id="login" size="15" value="" disabled="disabled" /></td>
  777. </tr>
  778. <tr>
  779. <td><label><?php echo get_lang('UserPassword'); ?></label></td>
  780. <td><input type="password" id="password" size="15" disabled="disabled" /></td>
  781. </tr>
  782. </table>
  783. <button class="login" type="button" name="submitAuth" value="<?php echo get_lang('Ok'); ?>" disabled="disabled"><?php echo get_lang('Ok'); ?></button>
  784. </form>
  785. <div class="menusection">
  786. <span class="menusectioncaption"><?php echo get_lang('User'); ?></span>
  787. <ul class="menulist">
  788. <li><span style="color: #9D9DA1; font-weight: bold;"><?php echo api_ucfirst(get_lang('Registration')); ?></span></li>
  789. <li><span style="color: #9D9DA1; font-weight: bold;"><?php echo api_ucfirst(get_lang('LostPassword')); ?></span></li>
  790. </ul>
  791. </div>
  792. <br />
  793. <a href="<?php echo api_get_self(); ?>?action=insert_link"><?php Display::display_icon('insert_row.png', get_lang('InsertLink')); ?></a>
  794. <a href="<?php echo api_get_self(); ?>?action=insert_link"/><?php echo get_lang('InsertLink'); ?></a>
  795. <div class="menusection">
  796. <span class="menusectioncaption"><?php echo api_ucfirst(get_lang('General')); ?></span>
  797. <ul class="menulist">
  798. <?php
  799. $home_menu = '';
  800. if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
  801. $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
  802. } else {
  803. $home_menu = @file($homep.$menuf.$ext);
  804. }
  805. if (empty($home_menu)) {
  806. $home_menu = array();
  807. }
  808. if (!empty($home_menu)) {
  809. $home_menu = implode("\n", $home_menu);
  810. $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  811. $home_menu = explode("\n", $home_menu);
  812. }
  813. foreach ($home_menu as $key => $enreg) {
  814. $enreg = trim($enreg);
  815. if (!empty($enreg)) {
  816. $edit_link = '<a href="'.api_get_self().'?action=edit_link&amp;link_index='.$key.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  817. $delete_link = '<a href="'.api_get_self().'?action=delete_link&amp;link_index='.$key.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  818. 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);
  819. }
  820. }
  821. ?>
  822. </ul>
  823. </div>
  824. <br />
  825. &nbsp;&nbsp;<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>
  826. <div class="note">
  827. <?php
  828. $home_notice = '';
  829. if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
  830. $home_notice = @(string)file_get_contents($homep.$noticef.'_'.$lang.$ext);
  831. } else {
  832. $home_notice = @(string)file_get_contents($homep.$noticef.$ext);
  833. }
  834. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  835. echo $home_notice;
  836. ?>
  837. </div>
  838. </div>
  839. </td>
  840. </tr>
  841. </table>
  842. <?php
  843. break;
  844. }
  845. Display::display_footer();