configure_homepage.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. <?php // $Id: configure_homepage.php 22243 2009-07-20 15:08:31Z 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=api_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. if ($_configuration['multiple_access_urls']==true) {
  114. if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
  115. copy($homep.$my_file.$ext,$homep_new.$my_file.'_'.$lang.$ext);
  116. }
  117. } else {
  118. if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
  119. copy($homep.$my_file.$ext,$homep.$my_file.'_'.$lang.$ext);
  120. }
  121. }
  122. }
  123. if ($_configuration['multiple_access_urls']==true) {
  124. $homep = $homep_new;
  125. }
  126. // Check WCAG settings and prepare edition using WCAG
  127. $errorMsg='';
  128. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  129. $errorMsg=WCAG_Rendering::request_validation();
  130. }
  131. // Filter link param
  132. $link = '';
  133. if(!empty($_GET['link'])) {
  134. $link=$_GET['link'];
  135. // If the link parameter is suspicious, empty it
  136. if(strstr($link,'/') || !strstr($link,'.html') || strstr($link,'\\')) {
  137. $link='';
  138. $action='';
  139. }
  140. }
  141. global $_configuration;
  142. // Start analysing requested actions
  143. if(!empty($action)) {
  144. if($_POST['formSent']) {
  145. //variables used are $homep for home path, $menuf for menu file, $newsf
  146. // for news file, $topf for top file, $noticef for noticefile,
  147. // $ext for '.html'
  148. switch($action) {
  149. case 'edit_top':
  150. // Filter
  151. $home_top='';
  152. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  153. $home_top=WCAG_Rendering::prepareXHTML();
  154. } else {
  155. $home_top=trim(stripslashes($_POST['home_top']));
  156. }
  157. // Write
  158. if (file_exists($homep.$topf.'_'.$lang.$ext)) {
  159. if(is_writable($homep.$topf.'_'.$lang.$ext)) {
  160. $fp=fopen($homep.$topf.'_'.$lang.$ext,"w");
  161. fputs($fp,$home_top);
  162. fclose($fp);
  163. } else {
  164. $errorMsg=get_lang('HomePageFilesNotWritable');
  165. }
  166. } else {
  167. //File does not exist
  168. $fp=fopen($homep.$topf.'_'.$lang.$ext,"w");
  169. fputs($fp,$home_top);
  170. fclose($fp);
  171. }
  172. break;
  173. case 'edit_notice':
  174. // Filter
  175. $notice_title=trim(strip_tags(stripslashes($_POST['notice_title'])));
  176. $notice_text=trim(str_replace(array("\r","\n"),array("","<br />"),strip_tags(stripslashes($_POST['notice_text']),'<a>')));
  177. /*if(empty($notice_title))
  178. {
  179. $errorMsg=get_lang('PleaseEnterNoticeTitle');
  180. }
  181. elseif(empty($notice_text))
  182. {
  183. $errorMsg=get_lang('PleaseEnterNoticeText');
  184. }*/
  185. if(empty($notice_title) || empty($notice_text)){
  186. $errorMsg=get_lang('NoticeWillBeNotDisplayed');
  187. }
  188. // Write
  189. if(file_exists($homep.$noticef.'_'.$lang.$ext)) {
  190. if(is_writable($homep.$noticef.'_'.$lang.$ext)) {
  191. $fp=fopen($homep.$noticef.'_'.$lang.$ext,"w");
  192. if($errorMsg==''){
  193. fputs($fp,"<b>$notice_title</b><br />\n$notice_text");
  194. } else {
  195. fputs($fp,"");
  196. }
  197. fclose($fp);
  198. } else {
  199. $errorMsg.="<br/>\n".get_lang('HomePageFilesNotWritable');
  200. }
  201. } else {
  202. //File does not exist
  203. $fp=fopen($homep.$noticef.'_'.$lang.$ext,"w");
  204. fputs($fp,"<b>$notice_title</b><br />\n$notice_text");
  205. fclose($fp);
  206. }
  207. break;
  208. case 'edit_news':
  209. //Filter
  210. //$s_languages_news=$_POST["news_languages"];
  211. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  212. $home_news=WCAG_rendering::prepareXHTML();
  213. } else {
  214. $home_news=trim(stripslashes($_POST['home_news']));
  215. }
  216. //Write
  217. if($s_languages_news!="all"){
  218. if(file_exists($homep.$newsf.'_'.$s_languages_news.$ext)){
  219. if(is_writable($homep.$newsf.'_'.$s_languages_news.$ext)){
  220. $fp=fopen($homep.$newsf.'_'.$s_languages_news.$ext,"w");
  221. fputs($fp,$home_news);
  222. fclose($fp);
  223. }
  224. else{
  225. $errorMsg=get_lang('HomePageFilesNotWritable');
  226. }
  227. }
  228. //File not exists
  229. else{
  230. $fp=fopen($homep.$newsf.'_'.$s_languages_news.$ext,"w");
  231. fputs($fp,$home_news);
  232. fclose($fp);
  233. }
  234. }
  235. else //we update all the news file
  236. {
  237. $_languages=api_get_languages();
  238. foreach($_languages["name"] as $key => $value){
  239. $english_name=$_languages["folder"][$key];
  240. if(file_exists($homep.$newsf.'_'.$english_name.$ext)){
  241. if(is_writable($homep.$newsf.'_'.$english_name.$ext)){
  242. $fp=fopen($homep.$newsf.'_'.$english_name.$ext,"w");
  243. fputs($fp,$home_news);
  244. fclose($fp);
  245. }
  246. else{
  247. $errorMsg=get_lang('HomePageFilesNotWritable');
  248. }
  249. }
  250. //File not exists
  251. else{
  252. $fp=fopen($homep.$newsf.'_'.$english_name.$ext,"w");
  253. fputs($fp,$home_news);
  254. fclose($fp);
  255. }
  256. }
  257. }
  258. break;
  259. case 'insert_link':
  260. case 'edit_link':
  261. $link_index=intval($_POST['link_index']);
  262. $insert_where=intval($_POST['insert_where']);
  263. $link_name=trim(stripslashes($_POST['link_name']));
  264. $link_url=trim(stripslashes($_POST['link_url']));
  265. // WCAG
  266. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  267. $link_html=WCAG_Rendering::prepareXHTML();
  268. } else {
  269. $link_html=trim(stripslashes($_POST['link_html']));
  270. }
  271. $filename=trim(stripslashes($_POST['filename']));
  272. $target_blank=$_POST['target_blank']?true:false;
  273. if($link_url == 'http://') {
  274. $link_url='';
  275. }
  276. elseif(!empty($link_url) && !strstr($link_url,'://')) {
  277. $link_url='http://'.$link_url;
  278. }
  279. if(!is_writable($homep.$menuf.'_'.$lang.$ext)) {
  280. $errorMsg=get_lang('HomePageFilesNotWritable');
  281. }
  282. elseif(empty($link_name)) {
  283. $errorMsg=get_lang('PleaseEnterLinkName');
  284. } else {
  285. // New links are added as new files in the home/ directory
  286. if($action == 'insert_link' || empty($filename) || strstr($filename,'/') || !strstr($filename,'.html')) {
  287. $filename=replace_dangerous_char($link_name,'strict').'.html';
  288. }
  289. // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files)
  290. if(!empty($filename)) {
  291. $filename=str_replace('home_','user_',$filename);
  292. }
  293. // If the typical language suffix is not found in the file name,
  294. // replace the ".html" suffix by "_en.html" or the active menu language
  295. if(!strstr($filename,'_'.$lang.$ext)) {
  296. $filename=str_replace($ext,'_'.$lang.$ext,$filename);
  297. }
  298. // Get the contents of home_menu_en.html (or active menu language
  299. // version) into $home_menu as an array of one entry per line
  300. $home_menu=file($homep.$menuf.'_'.$lang.$ext);
  301. // Prepare place to insert the new link into (default is end of file)
  302. if($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) {
  303. $insert_where=sizeof($home_menu) - 1;
  304. }
  305. // For each line of the file, remove trailing spaces and special chars
  306. foreach($home_menu as $key=>$enreg) {
  307. $home_menu[$key]=trim($enreg);
  308. }
  309. // If the given link url is empty, then replace the link url by a link to the link file created
  310. if(empty($link_url)) {
  311. $link_url=api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
  312. // If the file doesn't exist, then create it and
  313. // fill it with default text
  314. if(!file_exists(api_get_path(SYS_PATH).'home/'.$filename)) {
  315. $fp=@fopen(api_get_path(SYS_PATH).'home/'.$filename,'w');
  316. if($fp) {
  317. fputs($fp,get_lang('MyTextHere'));
  318. fclose($fp);
  319. }
  320. }
  321. }
  322. // If the requested action is to edit a link, open the file and
  323. // write to it (if the file doesn't exist, create it)
  324. if($action == 'edit_link' && !empty($link_html)) {
  325. $fp=@fopen(api_get_path(SYS_PATH).'home/'.$filename,'w');
  326. if($fp) {
  327. fputs($fp,$link_html);
  328. fclose($fp);
  329. }
  330. }
  331. // If the requested action is to create a link, make some room
  332. // for the new link in the home_menu array at the requested place
  333. // and insert the new link there
  334. if($action == 'insert_link') {
  335. for($i=sizeof($home_menu);$i;$i--) {
  336. if($i > $insert_where) {
  337. $home_menu[$i]=$home_menu[$i-1];
  338. } else {
  339. break;
  340. }
  341. }
  342. $home_menu[$insert_where+1]='<li><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'.$link_name.'</a></li>';
  343. }
  344. else // If the request is about a link edition, change the link
  345. {
  346. $home_menu[$link_index]='<li><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'.$link_name.'</a></li>';
  347. }
  348. // Re-build the file from the home_menu array
  349. $home_menu=implode("\n",$home_menu);
  350. // Write
  351. if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
  352. if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
  353. $fp=fopen($homep.$menuf.'_'.$lang.$ext,"w");
  354. fputs($fp,$home_menu);
  355. fclose($fp);
  356. if (file_exists($homep.$menuf.$ext)) {
  357. if (is_writable($homep.$menuf.$ext)) {
  358. $fpo=fopen($homep.$menuf.$ext,"w");
  359. fputs($fpo,$home_menu);
  360. fclose($fpo);
  361. }
  362. }
  363. } else {
  364. $errorMsg=get_lang('HomePageFilesNotWritable');
  365. }
  366. }
  367. else //File does not exist
  368. {
  369. $fp=fopen($homep.$menuf.'_'.$lang.$ext,"w");
  370. fputs($fp,$home_menu);
  371. fclose($fp);
  372. }
  373. }
  374. break;
  375. } //end of switch($action)
  376. if(empty($errorMsg)) {
  377. header('Location: '.api_get_self());
  378. exit();
  379. }
  380. } else {
  381. //if POST[formSent] is not set
  382. switch($action) {
  383. case 'open_link':
  384. // Previously, filtering of GET['link'] was done here but it left
  385. // a security threat. Filtering has now been moved outside conditions
  386. break;
  387. case 'delete_link':
  388. // A link is deleted by getting the file into an array, removing the
  389. // link and re-writing the array to the file
  390. $link_index=intval($_GET['link_index']);
  391. $home_menu=file($homep.$menuf.'_'.$lang.$ext);
  392. foreach($home_menu as $key=>$enreg) {
  393. if($key == $link_index) {
  394. unset($home_menu[$key]);
  395. } else {
  396. $home_menu[$key]=trim($enreg);
  397. }
  398. }
  399. $home_menu=implode("\n",$home_menu);
  400. $fp=fopen($homep.$menuf.'_'.$lang.$ext,'w');
  401. fputs($fp,$home_menu);
  402. fclose($fp);
  403. if (file_exists($homep.$menuf.$ext)) {
  404. if (is_writable($homep.$menuf.$ext)) {
  405. $fpo=fopen($homep.$menuf.$ext,'w');
  406. fputs($fpo,$home_menu);
  407. fclose($fpo);
  408. }
  409. }
  410. header('Location: '.api_get_self());
  411. exit();
  412. break;
  413. case 'edit_top':
  414. // This request is only the preparation for the update of the home_top
  415. $home_top = '';
  416. if(is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
  417. $home_top=file_get_contents($homep.$topf.'_'.$lang.$ext);
  418. } elseif(is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
  419. $home_top=file_get_contents($homep.$topf.$lang.$ext);
  420. } else {
  421. $errorMsg=get_lang('HomePageFilesNotReadable');
  422. }
  423. break;
  424. case 'edit_notice':
  425. // This request is only the preparation for the update of the home_notice
  426. $home_notice = '';
  427. if(is_file($homep.$noticef.'_'.$lang.$ext)
  428. && is_readable($homep.$noticef.'_'.$lang.$ext))
  429. {
  430. $home_notice=file($homep.$noticef.'_'.$lang.$ext);
  431. }
  432. elseif(is_file($homep.$noticef.$lang.$ext)
  433. && is_readable($homep.$noticef.$lang.$ext))
  434. {
  435. $home_notice=file($homep.$noticef.$lang.$ext);
  436. }
  437. else
  438. {
  439. $errorMsg=get_lang('HomePageFilesNotReadable');
  440. }
  441. $notice_title=strip_tags($home_notice[0]);
  442. $notice_text=strip_tags(str_replace('<br />',"\n",$home_notice[1]),'<a>');
  443. break;
  444. case 'edit_news':
  445. // This request is the preparation for the update of the home_news page
  446. $home_news = '';
  447. if(is_file($homep.$newsf.'_'.$lang.$ext)
  448. && is_readable($homep.$newsf.'_'.$lang.$ext))
  449. {
  450. $home_news=file_get_contents($homep.$newsf.'_'.$lang.$ext);
  451. // $home_news=file($homep.$newsf.$ext);
  452. // $home_news=implode('',$home_news);
  453. }
  454. elseif(is_file($homep.$newsf.$lang.$ext)
  455. && is_readable($homep.$newsf.$lang.$ext))
  456. {
  457. $home_news=file_get_contents($homep.$newsf.$lang.$ext);
  458. }
  459. else
  460. {
  461. $errorMsg=get_lang('HomePageFilesNotReadable');
  462. }
  463. break;
  464. case 'insert_link':
  465. // This request is the preparation for the addition of an item in home_menu
  466. $home_menu = '';
  467. if(is_file($homep.$menuf.'_'.$lang.$ext)
  468. && is_readable($homep.$menuf.'_'.$lang.$ext))
  469. {
  470. $home_menu=file($homep.$menuf.'_'.$lang.$ext);
  471. }
  472. elseif(is_file($homep.$menuf.$lang.$ext)
  473. && is_readable($homep.$menuf.$lang.$ext))
  474. {
  475. $home_menu=file($homep.$menuf.$lang.$ext);
  476. }
  477. else
  478. {
  479. $errorMsg=get_lang('HomePageFilesNotReadable');
  480. }
  481. break;
  482. case 'edit_link':
  483. // This request is the preparation for the edition of the links array
  484. $home_menu = '';
  485. if(is_file($homep.$menuf.'_'.$lang.$ext)
  486. && is_readable($homep.$menuf.'_'.$lang.$ext))
  487. {
  488. $home_menu=file($homep.$menuf.'_'.$lang.$ext);
  489. }
  490. elseif(is_file($homep.$menuf.$lang.$ext)
  491. && is_readable($homep.$menuf.$lang.$ext))
  492. {
  493. $home_menu=file($homep.$menuf.$lang.$ext);
  494. }
  495. else
  496. {
  497. $errorMsg=get_lang('HomePageFilesNotReadable');
  498. }
  499. $link_index=intval($_GET['link_index']);
  500. $target_blank=false;
  501. $link_name='';
  502. $link_url='';
  503. // For each line of the home_menu file
  504. foreach($home_menu as $key=>$enreg) {
  505. // Check if the current item is the one we want to update
  506. if($key == $link_index) {
  507. // This is the link we want to update
  508. // Check if the target should be "_blank"
  509. if(strstr($enreg,'target="_blank"')) {
  510. $target_blank=true;
  511. }
  512. // Remove dangerous HTML tags from the link itself (this is an
  513. // additional measure in case a link previously contained
  514. // unsecure tags)
  515. $link_name=strip_tags($enreg);
  516. // Get the contents of "href" attribute in $link_url
  517. $enreg=explode('href="',$enreg);
  518. list($link_url)=explode('"',$enreg[sizeof($enreg)-1]);
  519. // If the link contains the web root of this portal, then strip
  520. // it off and keep only the name of the file that needs edition
  521. if(strstr($link_url,$_configuration['root_web']) && strstr($link_url,'?include=')) {
  522. $link_url=explode('?include=',$link_url);
  523. $filename=$link_url[sizeof($link_url)-1];
  524. if(!strstr($filename,'/') && strstr($filename,'.html')) {
  525. // Get oonly the contents of the link file
  526. $link_html=file(api_get_path(SYS_PATH).'home/'.$filename);
  527. $link_html=implode('',$link_html);
  528. $link_url='';
  529. } else {
  530. $filename='';
  531. }
  532. }
  533. break;
  534. }
  535. }
  536. break;
  537. }//end of second switch($action) (when POST['formSent'] was not set, yet)
  538. }// end of "else" in if($_POST['formSent']) condition
  539. }
  540. else //if $action is empty, then prepare a list of the course categories to display (?)
  541. {
  542. $result=Database::query("SELECT name FROM $tbl_category WHERE parent_id IS NULL ORDER BY tree_pos",__FILE__,__LINE__);
  543. $Categories=Database::store_result($result);
  544. }
  545. // -------------------------
  546. // ---- Display section ----
  547. // -------------------------
  548. Display::display_header($tool_name);
  549. //api_display_tool_title($tool_name);
  550. switch($action){
  551. case 'open_link':
  552. if(!empty($link))
  553. {
  554. // $link is only set in case of action=open_link and is filtered
  555. include($homep.$link);
  556. }
  557. break;
  558. case 'edit_notice':
  559. //------------ Display for edit_notice case --------------
  560. ?>
  561. <form action="<?php echo api_get_self(); ?>?action=<?php echo $action; ?>" method="post" style="margin:0px;">
  562. <div class="row"><div class="form_header"><?php echo $tool_name; ?></div></div>
  563. <input type="hidden" name="formSent" value="1"/>
  564. <?php
  565. if(!empty($errorMsg)) {
  566. //echo '<tr><td colspan="2">';
  567. Display::display_normal_message($errorMsg);
  568. //echo '</td></tr>';
  569. }
  570. ?>
  571. <table border="0" cellpadding="5" cellspacing="0">
  572. <tr><td colspan="2"><?php echo '<span style="font-style: italic;">'.get_lang('LetThoseFieldsEmptyToHideTheNotice').'</span>'; ?></tr>
  573. <tr>
  574. <td nowrap="nowrap"><?php echo get_lang('NoticeTitle'); ?> :</td>
  575. <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>
  576. </tr>
  577. <tr>
  578. <td nowrap="nowrap" valign="top"><?php echo get_lang('NoticeText'); ?> :</td>
  579. <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>
  580. </tr>
  581. <tr>
  582. <td>&nbsp;</td>
  583. <td><input type="submit" value="<?php echo get_lang('Ok'); ?>"/></td>
  584. </tr>
  585. </table>
  586. </form>
  587. <?php
  588. break;
  589. case 'insert_link':
  590. case 'edit_link':
  591. if(!empty($errorMsg)) {
  592. Display::display_normal_message($errorMsg); //main API
  593. }
  594. $default = array();
  595. $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  596. $renderer =& $form->defaultRenderer();
  597. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  598. $renderer->setElementTemplate('{element}');
  599. $renderer->setRequiredNoteTemplate('');
  600. $form->addElement('header', '', $tool_name);
  601. $form->addElement('hidden', 'formSent', '1');
  602. $form->addElement('hidden', 'link_index', $action == 'edit_link' ? $link_index : '0');
  603. $form->addElement('hidden', 'filename', $action == 'edit_link' ? $filename : '');
  604. $form->addElement('html', '<tr><td nowrap="nowrap" style="width: 15%;">'.get_lang('LinkName').' :</td><td>');
  605. $default['link_name'] = api_htmlentities($link_name, ENT_QUOTES, $charset);
  606. $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
  607. $form->addElement('html', '</td></tr>');
  608. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('LinkURL').' ('.get_lang('Optional').') :</td><td>');
  609. $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES, $charset);
  610. $form->addElement('text', 'link_url', get_lang('LinkName'), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
  611. $form->addElement('html', '</td></tr>');
  612. if($action == 'insert_link') {
  613. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('InsertThisLink').' :</td>');
  614. $form->addElement('html', '<td><select name="insert_where"><option value="-1">'.get_lang('FirstPlace').'</option>');
  615. foreach($home_menu as $key=>$enreg) {
  616. $form->addElement('html', '<option value="'.$key.'" '.($formSent && $insert_where == $key ? 'selected="selected"' : '').' >'.get_lang('After').' &quot;'.trim(strip_tags($enreg)).'&quot;</option>');
  617. }
  618. $form->addElement('html', '</select></td></tr>');
  619. }
  620. $form->addElement('html', '<tr><td nowrap="nowrap">'.get_lang('OpenInNewWindow').'</td><td>');
  621. $target_blank_checkbox = & $form->addElement('checkbox', 'target_blank', '', '&nbsp;'.get_lang('Yes'), 1);
  622. if ($target_blank) $target_blank_checkbox->setChecked(true);
  623. $form->addElement('html', '</td></tr>');
  624. //if($action == 'edit_link' && empty($link_url))
  625. if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://')) {
  626. $form->addElement('html', '</table><table border="0" cellpadding="5" cellspacing="0" width="100%"><tr><td>');
  627. $form->addElement('html', '</td></tr><tr><td>');
  628. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  629. $form->addElement('html', WCAG_Rendering::create_xhtml(isset($_POST['link_html'])?$_POST['link_html']:$link_html));
  630. } else {
  631. $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
  632. $form->add_html_editor('link_html', '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  633. }
  634. $form->addElement('html', '</td></tr><tr><td>');
  635. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  636. $form->addElement('html', '</td></tr>');
  637. } else {
  638. $form->addElement('html', '<tr><td>&nbsp;</td><td>');
  639. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  640. $form->addElement('html', '</td></tr>');
  641. }
  642. $form->setDefaults($default);
  643. $form->display();
  644. break;
  645. case 'edit_top':
  646. case 'edit_news':
  647. if($action == 'edit_top') {
  648. $name= $topf;
  649. $open = $home_top;
  650. } else {
  651. $name = $newsf;
  652. $open=@file_get_contents($homep.$newsf.'_'.$lang.$ext);
  653. }
  654. if(!empty($errorMsg)) {
  655. Display::display_normal_message($errorMsg); //main API
  656. }
  657. $default = array();
  658. $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;'));
  659. $renderer =& $form->defaultRenderer();
  660. $renderer->setHeaderTemplate('');
  661. $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
  662. $renderer->setElementTemplate('<tr><td>{element}</td></tr>');
  663. $renderer->setRequiredNoteTemplate('');
  664. $form->addElement('hidden', 'formSent', '1');
  665. if($action == 'edit_news'){
  666. $_languages=api_get_languages();
  667. $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
  668. $html .= '<select name="news_languages">';
  669. $html .= '<option value="all">'.get_lang('AllLanguages').'</option>';
  670. foreach ($_languages['name'] as $key => $value) {
  671. $english_name = $_languages['folder'][$key];
  672. if($language==$english_name){
  673. $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
  674. } else {
  675. $html .= '<option value="'.$english_name.'">'.$value.'</option>';
  676. }
  677. }
  678. $html .= '</select></td></tr>';
  679. $form->addElement('html', $html);
  680. }
  681. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  682. //TODO: review these lines
  683. // Print WCAG-specific HTML editor
  684. $html = '<tr><td>';
  685. $html .= WCAG_Rendering::create_xhtml($open);
  686. $html .= '</td></tr>';
  687. $form->addElement('html', $html);
  688. } else {
  689. $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
  690. $form->add_html_editor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
  691. }
  692. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  693. $form->setDefaults($default);
  694. $form->display();
  695. break;
  696. default: // When no action applies, default page to update campus homepage
  697. ?>
  698. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  699. <tr>
  700. <td width="80%" colspan="2" valign="top">
  701. <div class="actions">
  702. <a href="<?php echo api_get_self(); ?>?action=edit_top"><?php Display::display_icon('edit.gif', get_lang('EditHomePage')); ?></a>
  703. <a href="<?php echo api_get_self(); ?>?action=edit_top"><?php echo get_lang('EditHomePage'); ?></a>
  704. </div>
  705. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  706. <tr>
  707. <td colspan="2">
  708. <?php
  709. //print home_top contents
  710. if(file_exists($homep.$topf.'_'.$lang.$ext)) {
  711. $home_top_temp=file_get_contents($homep.$topf.'_'.$lang.$ext);
  712. } else {
  713. $home_top_temp=file_get_contents($homep.$topf.$ext);
  714. }
  715. $open=str_replace('{rel_path}',api_get_path(REL_PATH),$home_top_temp);
  716. echo $open;
  717. ?>
  718. </td>
  719. </tr>
  720. <tr>
  721. <?php
  722. $access_url_id =1;
  723. // we only show the category options for the main Dokeos installation
  724. if ($_configuration['multiple_access_urls']==true) {
  725. $access_url_id = api_get_current_access_url_id();
  726. }
  727. echo '<td width="50%">';
  728. if ($access_url_id ==1) {
  729. echo '<div class="actions">';
  730. echo '<a href="course_category.php">'.Display::display_icon('edit.gif', get_lang('Edit')).'</a>
  731. <a href="course_category.php">'.get_lang('EditCategories').'</a>';
  732. echo '</div>';
  733. }
  734. echo '</td>
  735. <td width="50%">
  736. <br />';
  737. /* <!--<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>--> */
  738. echo '</td></tr>
  739. <tr>
  740. <td width="50%" valign="top">
  741. <table border="0" cellpadding="5" cellspacing="0" width="100%">';
  742. if ($access_url_id ==1) {
  743. if(sizeof($Categories)) {
  744. foreach($Categories as $enreg) {
  745. echo '<tr><td>'.Display::return_icon('folder_document.gif', $enreg['name']).'&nbsp;'.$enreg['name'].'</td></tr>';
  746. }
  747. unset($Categories);
  748. } else {
  749. echo get_lang('NoCategories');
  750. }
  751. }
  752. echo '</table>';
  753. ?>
  754. </td>
  755. <!--<td width="50%" valign="top">
  756. <?php
  757. if(file_exists($homep.$newsf.'_'.$lang.$ext)) {
  758. include ($homep.$newsf.'_'.$lang.$ext);
  759. } else {
  760. include ($homep.$newsf.$ext);
  761. }
  762. ?>
  763. </td>-->
  764. </tr>
  765. </table>
  766. </td>
  767. <td width="20%" rowspan="3" valign="top">
  768. <div class="menu" style="width: 100%;">
  769. <?php
  770. api_display_language_form();
  771. ?>
  772. <form id="loginform">
  773. <table cellpadding="0">
  774. <tr>
  775. <td><label><?php echo get_lang('LoginName'); ?></label></td>
  776. <td><input type="text" id="login" size="15" value="" disabled="disabled" /></td>
  777. </tr>
  778. <tr>
  779. <td><label><?php echo get_lang('UserPassword'); ?></label></td>
  780. <td><input type="password" id="password" size="15" disabled="disabled" /></td>
  781. </tr>
  782. </table>
  783. <input type="button" value="<?php echo get_lang('Ok'); ?>" disabled="disabled" />
  784. </form>
  785. <div class="menusection">
  786. <span class="menusectioncaption"><?php echo get_lang('User'); ?></span>
  787. <ul class="menulist">
  788. <li><span style="color: #9D9DA1; font-weight: bold;"><?php echo api_ucfirst(get_lang('Registration')); ?></span></li>
  789. <li><span style="color: #9D9DA1; font-weight: bold;"><?php echo api_ucfirst(get_lang('LostPassword')); ?></span></li>
  790. </ul>
  791. </div>
  792. <br />
  793. <a href="<?php echo api_get_self(); ?>?action=insert_link"><?php Display::display_icon('insert_row.png', get_lang('InsertLink')); ?></a>
  794. <a href="<?php echo api_get_self(); ?>?action=insert_link"/><?php echo get_lang('InsertLink'); ?></a>
  795. <div class="menusection">
  796. <span class="menusectioncaption"><?php echo api_ucfirst(get_lang('General')); ?></span>
  797. <ul class="menulist">
  798. <?php
  799. $home_menu = '';
  800. if(file_exists($homep.$menuf.'_'.$lang.$ext)) {
  801. $home_menu = file($homep.$menuf.'_'.$lang.$ext);
  802. } else {
  803. $home_menu = file ($homep.$menuf.$ext);
  804. }
  805. foreach($home_menu as $key=>$enreg) {
  806. $enreg=trim($enreg);
  807. if(!empty($enreg)) {
  808. $edit_link='<a href="'.api_get_self().'?action=edit_link&amp;link_index='.$key.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  809. $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>';
  810. 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);
  811. }
  812. }
  813. ?>
  814. </ul>
  815. </div>
  816. <br />
  817. &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>
  818. <div class="note">
  819. <?php
  820. $home_notice = '';
  821. if(file_exists($homep.$noticef.'_'.$lang.$ext)) {
  822. $home_notice = @file_get_contents($homep.$noticef.'_'.$lang.$ext);
  823. } else {
  824. $home_notice = @file_get_contents($homep.$noticef.$ext);
  825. }
  826. echo $home_notice
  827. ?>
  828. </div>
  829. </div>
  830. </td>
  831. </tr>
  832. </table>
  833. <?php
  834. break;
  835. }
  836. /*
  837. ==============================================================================
  838. FOOTER
  839. ==============================================================================
  840. */
  841. Display::display_footer();
  842. ?>