configure_homepage.php 47 KB

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