configure_homepage.php 32 KB

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