configure_homepage.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. <?php // $Id: configure_homepage.php 20441 2009-05-10 07:39:15Z ivantcholakov $
  2. /*
  3. ===== =========================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. // name of the language file that needs to be included
  21. $language_file = array ('admin', 'accessibility');
  22. $cidReset=true;
  23. include('../inc/global.inc.php');
  24. $this_section=SECTION_PLATFORM_ADMIN;
  25. $_SESSION['this_section']=$this_section;
  26. api_protect_admin_script();
  27. require_once(api_get_path(LIBRARY_PATH).'WCAG/WCAG_rendering.php');
  28. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  29. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  30. require_once(api_get_path(LIBRARY_PATH).'security.lib.php');
  31. $action=Security::remove_XSS($_GET['action']);
  32. $tbl_category=Database::get_main_table(TABLE_MAIN_CATEGORY);
  33. $tool_name=get_lang('ConfigureHomePage');
  34. $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  35. if(!empty($action)){
  36. $interbreadcrumb[]=array('url' => 'configure_homepage.php',"name" => get_lang('ConfigureHomePage'));
  37. switch($action){
  38. case "edit_top":
  39. $tool_name=get_lang("EditHomePage");
  40. break;
  41. case "edit_news":
  42. $tool_name=get_lang("EditNews");
  43. break;
  44. case "edit_notice":
  45. $tool_name=get_lang("EditNotice");
  46. break;
  47. case "insert_link":
  48. $tool_name=get_lang("InsertLink");
  49. break;
  50. case "edit_link":
  51. $tool_name=get_lang("EditLink");
  52. break;
  53. }
  54. }
  55. //The global logic for language priorities should be:
  56. //- take language selected when connecting ($_SESSION['user_language_choice'])
  57. // or last language selected (taken from select box into SESSION by global.inc.php)
  58. // or, if unavailable;
  59. //- take default user language ($_SESSION['_user']['language']) - which is taken from
  60. // the database in local.inc.php or, if unavailable;
  61. //- take platform language (taken from the database campus setting 'platformLanguage')
  62. // Then if a language file doesn't exist, it should be created.
  63. // The default language for the homepage should use the default platform language
  64. // (if nothing else is selected), which means the 'no-language' file should be taken
  65. // to fill a new 'language-specified' language file, and then only the latter should be
  66. // modified. The original 'no-language' files should never be modified.
  67. // ----- Language selection -----
  68. // The final language selected and used everywhere in this script follows the rules
  69. // described above and is put into "$lang". Because this script includes
  70. // global.inc.php, the variables used for language purposes below are considered safe.
  71. $lang = ''; //el for "Edit Language"
  72. if(!empty($_SESSION['user_language_choice'])) {
  73. $lang=$_SESSION['user_language_choice'];
  74. } elseif(!empty($_SESSION['_user']['language'])) {
  75. $lang=$_SESSION['_user']['language'];
  76. } else {
  77. $lang=get_setting('platformLanguage');
  78. }
  79. // ----- Ensuring availability of main files in the corresponding language -----
  80. if ($_configuration['multiple_access_urls']==true) {
  81. $access_url_id = api_get_current_access_url_id();
  82. if ($access_url_id != -1){
  83. $url_info = api_get_access_url($access_url_id);
  84. // "http://" and the final "/" replaced
  85. $url = substr($url_info['url'],7,strlen($url_info['url'])-8);
  86. $clean_url = replace_dangerous_char($url);
  87. $clean_url = str_replace('/','-',$clean_url);
  88. $clean_url = $clean_url.'/';
  89. $homep = '../../home/'; //homep for Home Path
  90. $homep_new = '../../home/'.$clean_url; //homep for Home Path added the url
  91. $new_url_dir = api_get_path(SYS_PATH).'home/'.$clean_url;
  92. //we create the new dir for the new sites
  93. if (!is_dir($new_url_dir)){
  94. umask(0);
  95. $perm = api_get_setting('permissions_for_new_directories');
  96. $perm = octdec(!empty($perm)?$perm:'0755');
  97. mkdir($new_url_dir, $perm);
  98. }
  99. }
  100. } else {
  101. $homep_new ='';
  102. $homep = '../../home/'; //homep for Home Path
  103. }
  104. $menuf = 'home_menu'; //menuf for Menu File
  105. $newsf = 'home_news'; //newsf for News File
  106. $topf = 'home_top'; //topf for Top File
  107. $noticef = 'home_notice'; //noticef for Notice File
  108. $ext = '.html'; //ext for HTML Extension - when used frequently, variables are
  109. // faster than hardcoded strings
  110. $homef = array($menuf,$newsf,$topf,$noticef);
  111. // If language-specific file does not exist, create it by copying default file
  112. foreach($homef as $my_file)
  113. {
  114. if ($_configuration['multiple_access_urls']==true) {
  115. if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
  116. copy($homep.$my_file.$ext,$homep_new.$my_file.'_'.$lang.$ext);
  117. }
  118. } else {
  119. if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
  120. copy($homep.$my_file.$ext,$homep.$my_file.'_'.$lang.$ext);
  121. }
  122. }
  123. }
  124. if ($_configuration['multiple_access_urls']==true) {
  125. $homep = $homep_new;
  126. }
  127. // Check WCAG settings and prepare edition using WCAG
  128. $errorMsg='';
  129. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  130. $errorMsg=WCAG_Rendering::request_validation();
  131. }
  132. // Filter link param
  133. $link = '';
  134. if(!empty($_GET['link']))
  135. {
  136. $link=$_GET['link'];
  137. // If the link parameter is suspicious, empty it
  138. if(strstr($link,'/') || !strstr($link,'.html') || strstr($link,'\\'))
  139. {
  140. $link='';
  141. $action='';
  142. }
  143. }
  144. global $_configuration;
  145. // Start analysing requested actions
  146. if(!empty($action))
  147. {
  148. if($_POST['formSent']) {
  149. //variables used are $homep for home path, $menuf for menu file, $newsf
  150. // for news file, $topf for top file, $noticef for noticefile,
  151. // $ext for '.html'
  152. switch($action) {
  153. case 'edit_top':
  154. // Filter
  155. $home_top='';
  156. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  157. $home_top=WCAG_Rendering::prepareXHTML();
  158. } else {
  159. $home_top=trim(stripslashes($_POST['home_top']));
  160. }
  161. // Write
  162. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  163. if(is_writable($homep.$topf.'_'.$lang.$ext)) {
  164. $fp=fopen($homep.$topf.'_'.$lang.$ext,"w");
  165. fputs($fp,$home_top);
  166. fclose($fp);
  167. } else {
  168. $errorMsg=get_lang('HomePageFilesNotWritable');
  169. }
  170. } else {
  171. //File does not exist
  172. $fp=fopen($homep.$topf.'_'.$lang.$ext,"w");
  173. fputs($fp,$home_top);
  174. fclose($fp);
  175. }
  176. break;
  177. case 'edit_notice':
  178. // Filter
  179. $notice_title=trim(strip_tags(stripslashes($_POST['notice_title'])));
  180. $notice_text=trim(str_replace(array("\r","\n"),array("","<br />"),strip_tags(stripslashes($_POST['notice_text']),'<a>')));
  181. /*if(empty($notice_title))
  182. {
  183. $errorMsg=get_lang('PleaseEnterNoticeTitle');
  184. }
  185. elseif(empty($notice_text))
  186. {
  187. $errorMsg=get_lang('PleaseEnterNoticeText');
  188. }*/
  189. if(empty($notice_title) || empty($notice_text)){
  190. $errorMsg=get_lang('NoticeWillBeNotDisplayed');
  191. }
  192. // Write
  193. if(file_exists($homep.$noticef.'_'.$lang.$ext)) {
  194. if(is_writable($homep.$noticef.'_'.$lang.$ext)) {
  195. $fp=fopen($homep.$noticef.'_'.$lang.$ext,"w");
  196. if($errorMsg==''){
  197. fputs($fp,"<b>$notice_title</b><br />\n$notice_text");
  198. } else {
  199. fputs($fp,"");
  200. }
  201. fclose($fp);
  202. } else {
  203. $errorMsg.="<br/>\n".get_lang('HomePageFilesNotWritable');
  204. }
  205. } else {
  206. //File does not exist
  207. $fp=fopen($homep.$noticef.'_'.$lang.$ext,"w");
  208. fputs($fp,"<b>$notice_title</b><br />\n$notice_text");
  209. fclose($fp);
  210. }
  211. break;
  212. case 'edit_news':
  213. //Filter
  214. //$s_languages_news=$_POST["news_languages"];
  215. if (api_get_setting('wcag_anysurfer_public_pages')=='true')
  216. {
  217. $home_news=WCAG_rendering::prepareXHTML();
  218. } else
  219. {
  220. $home_news=trim(stripslashes($_POST['home_news']));
  221. }
  222. //Write
  223. if($s_languages_news!="all"){
  224. if(file_exists($homep.$newsf.'_'.$s_languages_news.$ext)){
  225. if(is_writable($homep.$newsf.'_'.$s_languages_news.$ext)){
  226. $fp=fopen($homep.$newsf.'_'.$s_languages_news.$ext,"w");
  227. fputs($fp,$home_news);
  228. fclose($fp);
  229. }
  230. else{
  231. $errorMsg=get_lang('HomePageFilesNotWritable');
  232. }
  233. }
  234. //File not exists
  235. else{
  236. $fp=fopen($homep.$newsf.'_'.$s_languages_news.$ext,"w");
  237. fputs($fp,$home_news);
  238. fclose($fp);
  239. }
  240. }
  241. else //we update all the news file
  242. {
  243. $_languages=api_get_languages();
  244. foreach($_languages["name"] as $key => $value){
  245. $english_name=$_languages["folder"][$key];
  246. if(file_exists($homep.$newsf.'_'.$english_name.$ext)){
  247. if(is_writable($homep.$newsf.'_'.$english_name.$ext)){
  248. $fp=fopen($homep.$newsf.'_'.$english_name.$ext,"w");
  249. fputs($fp,$home_news);
  250. fclose($fp);
  251. }
  252. else{
  253. $errorMsg=get_lang('HomePageFilesNotWritable');
  254. }
  255. }
  256. //File not exists
  257. else{
  258. $fp=fopen($homep.$newsf.'_'.$english_name.$ext,"w");
  259. fputs($fp,$home_news);
  260. fclose($fp);
  261. }
  262. }
  263. }
  264. break;
  265. case 'insert_link':
  266. case 'edit_link':
  267. $link_index=intval($_POST['link_index']);
  268. $insert_where=intval($_POST['insert_where']);
  269. $link_name=trim(stripslashes($_POST['link_name']));
  270. $link_url=trim(stripslashes($_POST['link_url']));
  271. // WCAG
  272. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  273. $link_html=WCAG_Rendering::prepareXHTML();
  274. } else {
  275. $link_html=trim(stripslashes($_POST['link_html']));
  276. }
  277. $filename=trim(stripslashes($_POST['filename']));
  278. $target_blank=$_POST['target_blank']?true:false;
  279. if($link_url == 'http://')
  280. {
  281. $link_url='';
  282. }
  283. elseif(!empty($link_url) && !strstr($link_url,'://'))
  284. {
  285. $link_url='http://'.$link_url;
  286. }
  287. if(!is_writable($homep.$menuf.'_'.$lang.$ext))
  288. {
  289. $errorMsg=get_lang('HomePageFilesNotWritable');
  290. }
  291. elseif(empty($link_name))
  292. {
  293. $errorMsg=get_lang('PleaseEnterLinkName');
  294. }
  295. else
  296. {
  297. // New links are added as new files in the home/ directory
  298. if($action == 'insert_link' || empty($filename) || strstr($filename,'/') || !strstr($filename,'.html'))
  299. {
  300. $filename=replace_dangerous_char($link_name,'strict').'.html';
  301. }
  302. // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files)
  303. if(!empty($filename))
  304. {
  305. $filename=str_replace('home_','user_',$filename);
  306. }
  307. // If the typical language suffix is not found in the file name,
  308. // replace the ".html" suffix by "_en.html" or the active menu language
  309. if(!strstr($filename,'_'.$lang.$ext))
  310. {
  311. $filename=str_replace($ext,'_'.$lang.$ext,$filename);
  312. }
  313. // Get the contents of home_menu_en.html (or active menu language
  314. // version) into $home_menu as an array of one entry per line
  315. $home_menu=file($homep.$menuf.'_'.$lang.$ext);
  316. // Prepare place to insert the new link into (default is end of file)
  317. if($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1))
  318. {
  319. $insert_where=sizeof($home_menu) - 1;
  320. }
  321. // For each line of the file, remove trailing spaces and special chars
  322. foreach($home_menu as $key=>$enreg)
  323. {
  324. $home_menu[$key]=trim($enreg);
  325. }
  326. // If the given link url is empty, then replace the link url by a link to the link file created
  327. if(empty($link_url))
  328. {
  329. $link_url=api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
  330. // If the file doesn't exist, then create it and
  331. // fill it with default text
  332. if(!file_exists(api_get_path(SYS_PATH).'home/'.$filename))
  333. {
  334. $fp=@fopen(api_get_path(SYS_PATH).'home/'.$filename,'w');
  335. if($fp)
  336. {
  337. fputs($fp,get_lang('MyTextHere'));
  338. fclose($fp);
  339. }
  340. }
  341. }
  342. // If the requested action is to edit a link, open the file and
  343. // write to it (if the file doesn't exist, create it)
  344. if($action == 'edit_link' && !empty($link_html))
  345. {
  346. $fp=@fopen(api_get_path(SYS_PATH).'home/'.$filename,'w');
  347. if($fp)
  348. {
  349. fputs($fp,$link_html);
  350. fclose($fp);
  351. }
  352. }
  353. // If the requested action is to create a link, make some room
  354. // for the new link in the home_menu array at the requested place
  355. // and insert the new link there
  356. if($action == 'insert_link')
  357. {
  358. for($i=sizeof($home_menu);$i;$i--)
  359. {
  360. if($i > $insert_where)
  361. {
  362. $home_menu[$i]=$home_menu[$i-1];
  363. }
  364. else
  365. {
  366. break;
  367. }
  368. }
  369. $home_menu[$insert_where+1]='<li><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'.$link_name.'</a></li>';
  370. }
  371. else // If the request is about a link edition, change the link
  372. {
  373. $home_menu[$link_index]='<li><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'.$link_name.'</a></li>';
  374. }
  375. // Re-build the file from the home_menu array
  376. $home_menu=implode("\n",$home_menu);
  377. // Write
  378. if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
  379. if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
  380. $fp=fopen($homep.$menuf.'_'.$lang.$ext,"w");
  381. fputs($fp,$home_menu);
  382. fclose($fp);
  383. if (file_exists($homep.$menuf.$ext)) {
  384. if (is_writable($homep.$menuf.$ext)) {
  385. $fpo=fopen($homep.$menuf.$ext,"w");
  386. fputs($fpo,$home_menu);
  387. fclose($fpo);
  388. }
  389. }
  390. } else {
  391. $errorMsg=get_lang('HomePageFilesNotWritable');
  392. }
  393. }
  394. else //File does not exist
  395. {
  396. $fp=fopen($homep.$menuf.'_'.$lang.$ext,"w");
  397. fputs($fp,$home_menu);
  398. fclose($fp);
  399. }
  400. }
  401. break;
  402. } //end of switch($action)
  403. if(empty($errorMsg))
  404. {
  405. header('Location: '.api_get_self());
  406. exit();
  407. }
  408. } else {
  409. //if POST[formSent] is not set
  410. switch($action) {
  411. case 'open_link':
  412. // Previously, filtering of GET['link'] was done here but it left
  413. // a security threat. Filtering has now been moved outside conditions
  414. break;
  415. case 'delete_link':
  416. // A link is deleted by getting the file into an array, removing the
  417. // link and re-writing the array to the file
  418. $link_index=intval($_GET['link_index']);
  419. $home_menu=file($homep.$menuf.'_'.$lang.$ext);
  420. foreach($home_menu as $key=>$enreg)
  421. {
  422. if($key == $link_index)
  423. {
  424. unset($home_menu[$key]);
  425. }
  426. else
  427. {
  428. $home_menu[$key]=trim($enreg);
  429. }
  430. }
  431. $home_menu=implode("\n",$home_menu);
  432. $fp=fopen($homep.$menuf.'_'.$lang.$ext,'w');
  433. fputs($fp,$home_menu);
  434. fclose($fp);
  435. if (file_exists($homep.$menuf.$ext)) {
  436. if (is_writable($homep.$menuf.$ext)) {
  437. $fpo=fopen($homep.$menuf.$ext,'w');
  438. fputs($fpo,$home_menu);
  439. fclose($fpo);
  440. }
  441. }
  442. header('Location: '.api_get_self());
  443. exit();
  444. break;
  445. case 'edit_top':
  446. // This request is only the preparation for the update of the home_top
  447. $home_top = '';
  448. if(is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
  449. $home_top=file_get_contents($homep.$topf.'_'.$lang.$ext);
  450. } elseif(is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
  451. $home_top=file_get_contents($homep.$topf.$lang.$ext);
  452. } else {
  453. $errorMsg=get_lang('HomePageFilesNotReadable');
  454. }
  455. break;
  456. case 'edit_notice':
  457. // This request is only the preparation for the update of the home_notice
  458. $home_notice = '';
  459. if(is_file($homep.$noticef.'_'.$lang.$ext)
  460. && is_readable($homep.$noticef.'_'.$lang.$ext))
  461. {
  462. $home_notice=file($homep.$noticef.'_'.$lang.$ext);
  463. }
  464. elseif(is_file($homep.$noticef.$lang.$ext)
  465. && is_readable($homep.$noticef.$lang.$ext))
  466. {
  467. $home_notice=file($homep.$noticef.$lang.$ext);
  468. }
  469. else
  470. {
  471. $errorMsg=get_lang('HomePageFilesNotReadable');
  472. }
  473. $notice_title=strip_tags($home_notice[0]);
  474. $notice_text=strip_tags(str_replace('<br />',"\n",$home_notice[1]),'<a>');
  475. break;
  476. case 'edit_news':
  477. // This request is the preparation for the update of the home_news page
  478. $home_news = '';
  479. if(is_file($homep.$newsf.'_'.$lang.$ext)
  480. && is_readable($homep.$newsf.'_'.$lang.$ext))
  481. {
  482. $home_news=file_get_contents($homep.$newsf.'_'.$lang.$ext);
  483. // $home_news=file($homep.$newsf.$ext);
  484. // $home_news=implode('',$home_news);
  485. }
  486. elseif(is_file($homep.$newsf.$lang.$ext)
  487. && is_readable($homep.$newsf.$lang.$ext))
  488. {
  489. $home_news=file_get_contents($homep.$newsf.$lang.$ext);
  490. }
  491. else
  492. {
  493. $errorMsg=get_lang('HomePageFilesNotReadable');
  494. }
  495. break;
  496. case 'insert_link':
  497. // This request is the preparation for the addition of an item in home_menu
  498. $home_menu = '';
  499. if(is_file($homep.$menuf.'_'.$lang.$ext)
  500. && is_readable($homep.$menuf.'_'.$lang.$ext))
  501. {
  502. $home_menu=file($homep.$menuf.'_'.$lang.$ext);
  503. }
  504. elseif(is_file($homep.$menuf.$lang.$ext)
  505. && is_readable($homep.$menuf.$lang.$ext))
  506. {
  507. $home_menu=file($homep.$menuf.$lang.$ext);
  508. }
  509. else
  510. {
  511. $errorMsg=get_lang('HomePageFilesNotReadable');
  512. }
  513. break;
  514. case 'edit_link':
  515. // This request is the preparation for the edition of the links array
  516. $home_menu = '';
  517. if(is_file($homep.$menuf.'_'.$lang.$ext)
  518. && is_readable($homep.$menuf.'_'.$lang.$ext))
  519. {
  520. $home_menu=file($homep.$menuf.'_'.$lang.$ext);
  521. }
  522. elseif(is_file($homep.$menuf.$lang.$ext)
  523. && is_readable($homep.$menuf.$lang.$ext))
  524. {
  525. $home_menu=file($homep.$menuf.$lang.$ext);
  526. }
  527. else
  528. {
  529. $errorMsg=get_lang('HomePageFilesNotReadable');
  530. }
  531. $link_index=intval($_GET['link_index']);
  532. $target_blank=false;
  533. $link_name='';
  534. $link_url='';
  535. // For each line of the home_menu file
  536. foreach($home_menu as $key=>$enreg)
  537. {
  538. // Check if the current item is the one we want to update
  539. if($key == $link_index)
  540. {
  541. // This is the link we want to update
  542. // Check if the target should be "_blank"
  543. if(strstr($enreg,'target="_blank"'))
  544. {
  545. $target_blank=true;
  546. }
  547. // Remove dangerous HTML tags from the link itself (this is an
  548. // additional measure in case a link previously contained
  549. // unsecure tags)
  550. $link_name=strip_tags($enreg);
  551. // Get the contents of "href" attribute in $link_url
  552. $enreg=explode('href="',$enreg);
  553. list($link_url)=explode('"',$enreg[sizeof($enreg)-1]);
  554. // If the link contains the web root of this portal, then strip
  555. // it off and keep only the name of the file that needs edition
  556. if(strstr($link_url,$_configuration['root_web']) && strstr($link_url,'?include='))
  557. {
  558. $link_url=explode('?include=',$link_url);
  559. $filename=$link_url[sizeof($link_url)-1];
  560. if(!strstr($filename,'/') && strstr($filename,'.html'))
  561. {
  562. // Get oonly the contents of the link file
  563. $link_html=file(api_get_path(SYS_PATH).'home/'.$filename);
  564. $link_html=implode('',$link_html);
  565. $link_url='';
  566. }
  567. else
  568. {
  569. $filename='';
  570. }
  571. }
  572. break;
  573. }
  574. }
  575. break;
  576. }//end of second switch($action) (when POST['formSent'] was not set, yet)
  577. }// end of "else" in if($_POST['formSent']) condition
  578. }
  579. else //if $action is empty, then prepare a list of the course categories to display (?)
  580. {
  581. $result=api_sql_query("SELECT name FROM $tbl_category WHERE parent_id IS NULL ORDER BY tree_pos",__FILE__,__LINE__);
  582. $Categories=api_store_result($result);
  583. }
  584. // -------------------------
  585. // ---- Display section ----
  586. // -------------------------
  587. Display::display_header($tool_name);
  588. //api_display_tool_title($tool_name);
  589. switch($action){
  590. case 'open_link':
  591. if(!empty($link))
  592. {
  593. // $link is only set in case of action=open_link and is filtered
  594. include($homep.$link);
  595. }
  596. break;
  597. case 'edit_notice':
  598. //------------ Display for edit_notice case --------------
  599. ?>
  600. <form action="<?php echo api_get_self(); ?>?action=<?php echo $action; ?>" method="post" style="margin:0px;">
  601. <div class="row"><div class="form_header"><?php echo $tool_name; ?></div></div>
  602. <input type="hidden" name="formSent" value="1"/>
  603. <?php
  604. if(!empty($errorMsg))
  605. {
  606. //echo '<tr><td colspan="2">';
  607. Display::display_normal_message($errorMsg);
  608. //echo '</td></tr>';
  609. }
  610. ?>
  611. <table border="0" cellpadding="5" cellspacing="0">
  612. <tr><td colspan="2"><?php echo '<span style="font-style: italic;">'.get_lang('LetThoseFieldsEmptyToHideTheNotice').'</span>'; ?></tr>
  613. <tr>
  614. <td nowrap="nowrap"><?php echo get_lang('NoticeTitle'); ?> :</td>
  615. <td><input type="text" name="notice_title" size="30" maxlength="50" value="<?php echo api_htmlentities($notice_title,ENT_QUOTES,$charset); ?>" style="width: 350px;"/></td>
  616. </tr>
  617. <tr>
  618. <td nowrap="nowrap" valign="top"><?php echo get_lang('NoticeText'); ?> :</td>
  619. <td><textarea name="notice_text" cols="30" rows="5" wrap="virtual" style="width: 350px;"><?php echo api_htmlentities($notice_text,ENT_QUOTES,$charset); ?></textarea></td>
  620. </tr>
  621. <tr>
  622. <td>&nbsp;</td>
  623. <td><input type="submit" value="<?php echo get_lang('Ok'); ?>"/></td>
  624. </tr>
  625. </table>
  626. </form>
  627. <?php
  628. break;
  629. case 'insert_link':
  630. case 'edit_link':
  631. if(!empty($errorMsg))
  632. {
  633. Display::display_normal_message($errorMsg); //main API
  634. }
  635. $fck_attribute['ToolbarSet'] = "LinksHomePage";
  636. $fck_attribute['Width'] = '100%';
  637. $fck_attribute['Height'] = '400';
  638. $default = array();
  639. $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  640. $renderer =& $form->defaultRenderer();
  641. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  642. $renderer->setElementTemplate('{element}');
  643. $renderer->setRequiredNoteTemplate('');
  644. $form->addElement('header', '', $tool_name);
  645. $form->addElement('hidden', 'formSent', '1');
  646. $form->addElement('hidden', 'link_index', $action == 'edit_link' ? $link_index : '0');
  647. $form->addElement('hidden', 'filename', $action == 'edit_link' ? $filename : '');
  648. $form->addElement('html', '<tr><td nowrap="nowrap" style="width: 15%;">'.get_lang('LinkName').' :</td><td>');
  649. $default['link_name'] = api_htmlentities($link_name, ENT_QUOTES, $charset);
  650. $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
  651. $form->addElement('html', '</td></tr>');
  652. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('LinkURL').' ('.get_lang('Optional').') :</td><td>');
  653. $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES, $charset);
  654. $form->addElement('text', 'link_url', get_lang('LinkName'), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
  655. $form->addElement('html', '</td></tr>');
  656. if($action == 'insert_link')
  657. {
  658. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('InsertThisLink').' :</td>');
  659. $form->addElement('html', '<td><select name="insert_where"><option value="-1">'.get_lang('FirstPlace').'</option>');
  660. foreach($home_menu as $key=>$enreg)
  661. {
  662. $form->addElement('html', '<option value="'.$key.'" '.($formSent && $insert_where == $key ? 'selected="selected"' : '').' >'.get_lang('After').' &quot;'.trim(strip_tags($enreg)).'&quot;</option>');
  663. }
  664. $form->addElement('html', '</select></td></tr>');
  665. }
  666. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('OpenInNewWindow').'</td><td>');
  667. $target_blank_checkbox = & $form->addElement('checkbox', 'target_blank', '', '&nbsp;'.get_lang('Yes'), 1);
  668. if ($target_blank) $target_blank_checkbox->setChecked(true);
  669. $form->addElement('html', '</td></tr>');
  670. //if($action == 'edit_link' && empty($link_url))
  671. if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://'))
  672. {
  673. $form->addElement('html', '</table><table border="0" cellpadding="5" cellspacing="0" width="100%"><tr><td>');
  674. $form->addElement('html', '</td></tr><tr><td>');
  675. if (api_get_setting('wcag_anysurfer_public_pages')=='true')
  676. {
  677. $form->addElement('html', WCAG_Rendering::create_xhtml(isset($_POST['link_html'])?$_POST['link_html']:$link_html));
  678. }
  679. else
  680. {
  681. $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
  682. $form->add_html_editor('link_html', '');
  683. }
  684. $form->addElement('html', '</td></tr><tr><td>');
  685. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  686. $form->addElement('html', '</td></tr>');
  687. }
  688. else
  689. {
  690. $form->addElement('html', '<tr><td>&nbsp;</td><td>');
  691. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  692. $form->addElement('html', '</td></tr>');
  693. }
  694. $form->setDefaults($default);
  695. $form->display();
  696. $fck_attribute = null;
  697. break;
  698. case 'edit_top':
  699. case 'edit_news':
  700. if($action == 'edit_top')
  701. {
  702. $name= $topf;
  703. $open = $home_top;
  704. }
  705. else
  706. {
  707. $name = $newsf;
  708. $open=@file_get_contents($homep.$newsf.'_'.$lang.$ext);
  709. }
  710. if(!empty($errorMsg))
  711. {
  712. Display::display_normal_message($errorMsg); //main API
  713. }
  714. $fck_attribute['ToolbarSet'] = "EditHomePage";
  715. $fck_attribute['Width'] = '100%';
  716. $fck_attribute['Height'] = '400';
  717. $default = array();
  718. $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  719. $renderer =& $form->defaultRenderer();
  720. $renderer->setHeaderTemplate('');
  721. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  722. $renderer->setElementTemplate('<tr><td>{element}</td></tr>');
  723. $renderer->setRequiredNoteTemplate('');
  724. $form->addElement('hidden', 'formSent', '1');
  725. if($action == 'edit_news'){
  726. $_languages=api_get_languages();
  727. $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
  728. $html .= '<select name="news_languages">';
  729. $html .= '<option value="all">'.get_lang('AllLanguages').'</option>';
  730. foreach ($_languages['name'] as $key => $value) {
  731. $english_name = $_languages['folder'][$key];
  732. if($language==$english_name){
  733. $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
  734. } else {
  735. $html .= '<option value="'.$english_name.'">'.$value.'</option>';
  736. }
  737. }
  738. $html .= '</select></td></tr>';
  739. $form->addElement('html', $html);
  740. }
  741. if (api_get_setting('wcag_anysurfer_public_pages')=='true')
  742. {
  743. //TODO: review these lines
  744. // Print WCAG-specific HTML editor
  745. $html = '<tr><td>';
  746. //$html .= '<script type="text/javascript" src="'.api_get_path(REL_PATH).'main/inc/lib/fckeditor/editor/plugins/ImageManagerStandalone/generic_dialog_common.js'.'" />';
  747. $html .= WCAG_Rendering::create_xhtml($open);
  748. $html .= '</td></tr>';
  749. $form->addElement('html', $html);
  750. } else {
  751. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  752. $form->add_html_editor($name, '');
  753. }
  754. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  755. $form->setDefaults($default);
  756. $form->display();
  757. $fck_attribute = null;
  758. break;
  759. default: // When no action applies, default page to update campus homepage
  760. ?>
  761. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  762. <tr>
  763. <td width="80%" colspan="2" valign="top">
  764. <div class="actions">
  765. <a href="<?php echo api_get_self(); ?>?action=edit_top"><?php Display::display_icon('edit.gif', get_lang('EditHomePage')); ?></a>
  766. <a href="<?php echo api_get_self(); ?>?action=edit_top"><?php echo get_lang('EditHomePage'); ?></a>
  767. </div>
  768. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  769. <tr>
  770. <td colspan="2">
  771. <?php
  772. //print home_top contents
  773. if(file_exists($homep.$topf.'_'.$lang.$ext)) {
  774. $home_top_temp=file_get_contents($homep.$topf.'_'.$lang.$ext);
  775. } else {
  776. $home_top_temp=file_get_contents($homep.$topf.$ext);
  777. }
  778. $open=str_replace('{rel_path}',api_get_path(REL_PATH),$home_top_temp);
  779. echo $open;
  780. ?>
  781. </td>
  782. </tr>
  783. <tr>
  784. <?php
  785. $access_url_id =1;
  786. // we only show the category options for the main Dokeos installation
  787. if ($_configuration['multiple_access_urls']==true) {
  788. $access_url_id = api_get_current_access_url_id();
  789. }
  790. echo '<td width="50%">';
  791. if ($access_url_id ==1) {
  792. echo '<div class="actions">';
  793. echo '<a href="course_category.php">'.Display::display_icon('edit.gif', get_lang('Edit')).'</a>
  794. <a href="course_category.php">'.get_lang('EditCategories').'</a>';
  795. echo '</div>';
  796. }
  797. echo '</td>
  798. <td width="50%">
  799. <br />';
  800. /* <!--<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>--> */
  801. echo '</td></tr>
  802. <tr>
  803. <td width="50%" valign="top">
  804. <table border="0" cellpadding="5" cellspacing="0" width="100%">';
  805. if ($access_url_id ==1) {
  806. if(sizeof($Categories)) {
  807. foreach($Categories as $enreg) {
  808. echo '<tr><td>'.Display::return_icon('folder_document.gif', $enreg['name']).'&nbsp;'.$enreg['name'].'</td></tr>';
  809. }
  810. unset($Categories);
  811. } else {
  812. echo get_lang('NoCategories');
  813. }
  814. }
  815. echo '</table>';
  816. ?>
  817. </td>
  818. <!--<td width="50%" valign="top">
  819. <?php
  820. if(file_exists($homep.$newsf.'_'.$lang.$ext)) {
  821. include ($homep.$newsf.'_'.$lang.$ext);
  822. } else {
  823. include ($homep.$newsf.$ext);
  824. }
  825. ?>
  826. </td>-->
  827. </tr>
  828. </table>
  829. </td>
  830. <td width="20%" rowspan="3" valign="top">
  831. <div class="menu" style="width: 100%;">
  832. <?php
  833. api_display_language_form();
  834. ?>
  835. <form id="loginform">
  836. <table cellpadding="0">
  837. <tr>
  838. <td><label><?php echo get_lang('LoginName'); ?></label></td>
  839. <td><input type="text" id="login" size="15" value="" disabled="disabled" /></td>
  840. </tr>
  841. <tr>
  842. <td><label><?php echo get_lang('UserPassword'); ?></label></td>
  843. <td><input type="password" id="password" size="15" disabled="disabled" /></td>
  844. </tr>
  845. </table>
  846. <input type="button" value="<?php echo get_lang('Ok'); ?>" disabled="disabled" />
  847. </form>
  848. <div class="menusection">
  849. <span class="menusectioncaption"><?php echo get_lang('User'); ?></span>
  850. <ul class="menulist">
  851. <li><span style="color: #9D9DA1; font-weight: bold;"><?php echo ucfirst(get_lang('Registration')); ?></span></li>
  852. <li><span style="color: #9D9DA1; font-weight: bold;"><?php echo ucfirst(get_lang('LostPassword')); ?></span></li>
  853. </ul>
  854. </div>
  855. <br />
  856. <a href="<?php echo api_get_self(); ?>?action=insert_link"><?php Display::display_icon('insert_row.png', get_lang('InsertLink')); ?></a>
  857. <a href="<?php echo api_get_self(); ?>?action=insert_link"/><?php echo get_lang('InsertLink'); ?></a>
  858. <div class="menusection">
  859. <span class="menusectioncaption"><?php echo ucfirst(get_lang('General')); ?></span>
  860. <ul class="menulist">
  861. <?php
  862. $home_menu = '';
  863. if(file_exists($homep.$menuf.'_'.$lang.$ext))
  864. {
  865. $home_menu = file($homep.$menuf.'_'.$lang.$ext);
  866. }
  867. else
  868. {
  869. $home_menu = file ($homep.$menuf.$ext);
  870. }
  871. foreach($home_menu as $key=>$enreg)
  872. {
  873. $enreg=trim($enreg);
  874. if(!empty($enreg))
  875. {
  876. $edit_link='<a href="'.api_get_self().'?action=edit_link&amp;link_index='.$key.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  877. $delete_link='<a href="'.api_get_self().'?action=delete_link&amp;link_index='.$key.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  878. 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);
  879. }
  880. }
  881. ?>
  882. </ul>
  883. </div>
  884. <br />
  885. &nbsp;&nbsp;<a href="<?php echo api_get_self(); ?>?action=edit_notice"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a> <a href="<?php echo api_get_self(); ?>?action=edit_notice"><?php echo get_lang('EditNotice'); ?></a>
  886. <div class="note">
  887. <?php
  888. $home_notice = '';
  889. if(file_exists($homep.$noticef.'_'.$lang.$ext))
  890. {
  891. $home_notice = @file_get_contents($homep.$noticef.'_'.$lang.$ext);
  892. }
  893. else
  894. {
  895. $home_notice = @file_get_contents($homep.$noticef.$ext);
  896. }
  897. echo $home_notice
  898. ?>
  899. </div>
  900. </div>
  901. </td>
  902. </tr>
  903. </table>
  904. <?php
  905. break;
  906. }
  907. /*
  908. ==============================================================================
  909. FOOTER
  910. ==============================================================================
  911. */
  912. Display::display_footer();
  913. ?>