configure_homepage.php 46 KB

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