configure_homepage.php 34 KB

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