configure_homepage.php 40 KB

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