configure_homepage.php 44 KB

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