configure_homepage.php 32 KB

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