configure_homepage.php 46 KB

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