configure_homepage.php 49 KB

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