configure_homepage.php 40 KB

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