link.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <?php // $Id: link.php 22251 2009-07-20 16:56:54Z iflorespaz $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue Notre Dame, 152, B-1140 Evere, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * Main script for the links tool.
  20. *
  21. * Features:
  22. * - Organize links into categories;
  23. * - favorites/bookmarks-like interface;
  24. * - move links up/down within a category;
  25. * - move categories up/down;
  26. * - expand/collapse all categories (except the main "non"-category);
  27. * - add link to 'root' category => category-less link is always visible.
  28. *
  29. * @author Patrick Cool, main author, completely rewritten
  30. * @author Rene Haentjens, added CSV file import (October 2004)
  31. * @package dokeos.link
  32. * @todo improve organisation, tables should come from database library
  33. ==============================================================================
  34. */
  35. /*
  36. ==============================================================================
  37. INIT SECTION
  38. ==============================================================================
  39. */
  40. // name of the language file that needs to be included
  41. $language_file = array('link','admin');
  42. // including libraries
  43. require_once "../inc/global.inc.php";
  44. require_once "linkfunctions.php";
  45. $this_section=SECTION_COURSES;
  46. api_protect_course_script();
  47. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  48. $htmlHeadXtra[] = '<script type="text/javascript">
  49. $(document).ready( function() {
  50. for (i=0;i<$(".actions").length;i++) {
  51. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
  52. $(".actions:eq("+i+")").hide();
  53. }
  54. }
  55. $("#div_target").attr("style","display:none;")//hide
  56. $("#id_check_target").click(function () {
  57. if($(this).attr("checked")==true) {
  58. $("#div_target").attr("style","display:block;")//show
  59. } else {
  60. $("#div_target").attr("style","display:none;")//hide
  61. }
  62. });
  63. $(window).load(function () {
  64. if($("#id_check_target").attr("checked")==true) {
  65. $("#div_target").attr("style","display:block;")//show
  66. } else {
  67. $("#div_target").attr("style","display:none;")//hide
  68. }
  69. });
  70. } );
  71. </script>';
  72. // div_target
  73. // @todo change the $_REQUEST into $_POST or $_GET
  74. // @todo remove this code
  75. $link_submitted = (isset($_POST['submitLink'])?true:false);
  76. $category_submitted = (isset($_POST['submitCategory'])?true:false);
  77. $urlview = (!empty($_GET['urlview'])?$_GET['urlview']:'');
  78. $submitImport = (!empty($_POST['submitImport'])?$_POST['submitImport']:'');
  79. $down = (!empty($_GET['down'])?$_GET['down']:'');
  80. $up = (!empty($_GET['up'])?$_GET['up']:'');
  81. $catmove = (!empty($_GET['catmove'])?$_GET['catmove']:'');
  82. $editlink = (!empty($_REQUEST['editlink'])?$_REQUEST['editlink']:'');
  83. $id = (!empty($_REQUEST['id'])?$_REQUEST['id']:'');
  84. $urllink = (!empty($_REQUEST['urllink'])?$_REQUEST['urllink']:'');
  85. $title = (!empty($_REQUEST['title'])?$_REQUEST['title']:'');
  86. $description = (!empty($_REQUEST['description'])?$_REQUEST['description']:'');
  87. $selectcategory = (!empty($_REQUEST['selectcategory'])?$_REQUEST['selectcategory']:'');
  88. $submitLink = (isset($_REQUEST['submitLink'])?true : false);
  89. $action = (!empty($_REQUEST['action'])?$_REQUEST['action']:'');
  90. $category_title = (!empty($_REQUEST['category_title'])?$_REQUEST['category_title']:'');
  91. $submitCategory = isset($_POST['submitCategory'])?true:false;
  92. $nameTools = get_lang('Links');
  93. //condition for the session
  94. $session_id = api_get_session_id();
  95. $condition_session = api_get_session_condition($session_id, false);
  96. if (isset($_GET['action']) && $_GET['action']=='addlink') {
  97. $nameTools = '';
  98. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  99. $interbreadcrumb[] = array ('url' => 'link.php?action=addlink', 'name' => get_lang('AddLink'));
  100. }
  101. if (isset($_GET['action']) && $_GET['action']=='addcategory') {
  102. $nameTools = '';
  103. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  104. $interbreadcrumb[] = array ('url' => 'link.php?action=addcategory', 'name' => get_lang('AddCategory'));
  105. }
  106. if (isset($_GET['action']) && $_GET['action']=='editlink') {
  107. $nameTools = '';
  108. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  109. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('EditLink'));
  110. }
  111. // Database Table definitions
  112. $tbl_link = Database::get_course_table(TABLE_LINK);
  113. $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
  114. //statistics
  115. event_access_tool(TOOL_LINK);
  116. Display::display_header($nameTools, 'Links');
  117. ?>
  118. <script type="text/javascript">
  119. /* <![CDATA[ */
  120. function MM_popupMsg(msg) { //v1.0
  121. confirm(msg);
  122. }
  123. /* ]]> */
  124. </script>
  125. <?php
  126. /*
  127. -----------------------------------------------------------
  128. Action Handling
  129. -----------------------------------------------------------
  130. */
  131. $nameTools = get_lang("Links");
  132. if(isset($_GET['action'])) {
  133. switch($_GET['action']) {
  134. case "addlink":
  135. if($link_submitted)
  136. {
  137. if(!addlinkcategory("link")) // here we add a link
  138. {
  139. unset($submitLink);
  140. }
  141. }
  142. break;
  143. case "addcategory":
  144. if($category_submitted)
  145. {
  146. if(!addlinkcategory("category")) // here we add a category
  147. {
  148. unset($submitCategory);
  149. }
  150. }
  151. break;
  152. case "importcsv":
  153. if($_POST["submitImport"])
  154. {
  155. import_csvfile();
  156. }
  157. break;
  158. case "deletelink":
  159. deletelinkcategory("link"); // here we delete a link
  160. break;
  161. case "deletecategory":
  162. deletelinkcategory("category"); // here we delete a category
  163. break;
  164. case "editlink":
  165. editlinkcategory("link"); // here we edit a link
  166. break;
  167. case "editcategory":
  168. editlinkcategory("category"); // here we edit a category
  169. break;
  170. case "visible":
  171. change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
  172. break;
  173. case "invisible":
  174. change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
  175. break;
  176. }
  177. }
  178. /*
  179. -----------------------------------------------------------
  180. Introduction section
  181. -----------------------------------------------------------
  182. */
  183. Display::display_introduction_section(TOOL_LINK);
  184. if (api_is_allowed_to_edit(null, true) and isset($_GET['action'])) {
  185. echo '<div class="actions">';
  186. echo '<a href="link.php?cidReq='.Security::remove_XSS($_GET['cidReq']).'&amp;urlview='.Security::remove_XSS($_GET['urlview']).'">'.Display::return_icon('back.png',get_lang('BackToLinksOverview')).get_lang('BackToLinksOverview').'</a>';
  187. echo '</div>';
  188. if(api_get_setting('search_enabled')=='true') {
  189. if (!extension_loaded('xapian')) {
  190. Display::display_error_message(get_lang('SearchXapianModuleNotInstaled'));
  191. }
  192. }
  193. // Displaying the correct title and the form for adding a category or link. This is only shown when nothing
  194. // has been submitted yet, hence !isset($submitLink)
  195. if (($_GET['action']=="addlink" or $_GET['action']=="editlink") and empty($_POST['submitLink'])) {
  196. echo '<div class="row">';
  197. if ($_GET['action']=="addlink")
  198. {echo '<div class="form_header">'.get_lang("LinkAdd").'</div>';}
  199. else
  200. {echo '<div class="form_header">'.get_lang("LinkMod").'</div>';}
  201. echo '</div>';
  202. if ($category=="") {
  203. $category=0;
  204. }
  205. echo "<form method=\"post\" action=\"".api_get_self()."?action=".Security::remove_XSS($_GET['action'])."&amp;urlview=".Security::remove_XSS($urlview)."\">";
  206. if ($_GET['action']=="editlink")
  207. {
  208. echo "<input type=\"hidden\" name=\"id\" value=\"".Security::remove_XSS($_GET['id'])."\" />";
  209. }
  210. echo ' <div class="row">
  211. <div class="label">
  212. <span class="form_required">*</span> '.get_lang('Url').'
  213. </div>
  214. <div class="formw">
  215. <input type="text" name="urllink" size="50" value="' . (empty($urllink)?'http://':api_htmlentities($urllink, ENT_COMPAT, $charset)) . '" />
  216. </div>
  217. </div>';
  218. echo ' <div class="row">
  219. <div class="label">
  220. '.get_lang('LinkName').'
  221. </div>
  222. <div class="formw">
  223. <input type="text" name="title" size="50" value="' . api_htmlentities($title,ENT_QUOTES,$charset) . '" />
  224. </div>
  225. </div>';
  226. echo ' <div class="row">
  227. <div class="label">
  228. '.get_lang('Description').'
  229. </div>
  230. <div class="formw">
  231. <textarea rows="3" cols="50" name="description">' . api_htmlentities($description,ENT_QUOTES,$charset) . '</textarea>
  232. </div>
  233. </div>';
  234. $sqlcategories = "SELECT * FROM ".$tbl_categories." $condition_session ORDER BY display_order DESC";
  235. $resultcategories = Database::query($sqlcategories,__FILE__,__LINE__);
  236. if (Database::num_rows($resultcategories)) {
  237. echo ' <div class="row">
  238. <div class="label">
  239. '.get_lang('Category').'
  240. </div>
  241. <div class="formw">';
  242. echo ' <select name="selectcategory">';
  243. echo ' <option value="0">--</option>';
  244. while ($myrow = Database::fetch_array($resultcategories))
  245. {
  246. echo " <option value=\"".$myrow["id"]."\"";
  247. if ($myrow["id"]==$category)
  248. {echo " selected";}
  249. echo ">".$myrow["category_title"]."</option>";
  250. }
  251. echo ' </select>';
  252. echo ' </div>
  253. </div>';
  254. }
  255. echo ' <div class="row">
  256. <div class="label">
  257. '.get_lang('OnHomepage').'?
  258. </div>
  259. <div class="formw">
  260. <input id="id_check_target" class="checkbox" type="checkbox" name="onhomepage" id="onhomepage" value="1"'.$onhomepage.'><label for="onhomepage"> '.get_lang('Yes').'</label>
  261. </div>
  262. </div>';
  263. echo ' <div class="row" id="div_target">
  264. <div class="label">
  265. '.get_lang('AddTargetOfLinkOnHomepage').'
  266. </div>
  267. <div class="formw" >
  268. <select name="target_link" id="target_link">
  269. <option value="_self">_self</option>
  270. <option value="_blank">_blank</option>
  271. <option value="_parent">_parent</option>
  272. <option value="_top">_top</option>
  273. </select>
  274. </div>
  275. </div>';
  276. if(api_get_setting('search_enabled')=='true')
  277. {
  278. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  279. $specific_fields = get_specific_field_list();
  280. echo ' <div class="row">
  281. <div class="label">
  282. '.get_lang('SearchFeatureDoIndexLink').'?
  283. </div>
  284. <div class="formw">
  285. <input class="checkbox" type="checkbox" name="index_document" id="index_document" checked="checked"><label for="index_document"> '.get_lang('Yes').'</label>
  286. </div>';
  287. foreach ($specific_fields as $specific_field) {
  288. //Author : <input name="A" type="text" />
  289. $default_values = '';
  290. if ($_GET['action']=="editlink")
  291. {
  292. $filter = array('course_code'=> "'". api_get_course_id() ."'", 'field_id' => $specific_field['id'], 'ref_id' => Security::remove_XSS($_GET['id']), 'tool_id' => '\''. TOOL_LINK .'\'');
  293. $values = get_specific_field_values_list($filter, array('value'));
  294. if ( !empty($values) ) {
  295. $arr_str_values = array();
  296. foreach ($values as $value) {
  297. $arr_str_values[] = $value['value'];
  298. }
  299. $default_values = implode(', ', $arr_str_values);
  300. }
  301. }
  302. $sf_textbox = '
  303. <div class="row">
  304. <div class="label">%s</div>
  305. <div class="formw">
  306. <input name="%s" type="text" value="%s"/>
  307. </div>
  308. </div>';
  309. echo sprintf($sf_textbox, $specific_field['name'], $specific_field['code'], $default_values);
  310. }
  311. }
  312. echo ' <div class="row">
  313. <div class="label">
  314. </div>
  315. <div class="formw">
  316. <button class="save" type="Submit" name="submitLink" value="OK">'.get_lang('SaveLink').'</button>
  317. </div>
  318. </div>';
  319. echo '</form>';
  320. } elseif(($_GET['action']=="addcategory" or $_GET['action']=="editcategory") and !$submitCategory) {
  321. echo '<div class="row">';
  322. if ($_GET['action']=="addcategory") {
  323. echo '<div class="form_header">'.get_lang('CategoryAdd').'</div>';
  324. $my_cat_title=get_lang('CategoryAdd');
  325. } else {
  326. echo '<div class="form_header">'.get_lang('CategoryMod').'</div>';
  327. $my_cat_title=get_lang('CategoryMod');
  328. }
  329. echo "</div>\n\n";
  330. echo "<form method=\"post\" action=\"".api_get_self()."?action=".Security::remove_XSS($_GET['action'])."&amp;urlview=".Security::remove_XSS($urlview)."\">";
  331. if ($_GET['action']=="editcategory")
  332. {
  333. echo "<input type=\"hidden\" name=\"id\" value=\"".$id."\" />";
  334. }
  335. echo ' <div class="row">
  336. <div class="label">
  337. <span class="form_required">*</span> '.get_lang('CategoryName').'
  338. </div>
  339. <div class="formw">
  340. <input type="text" name="category_title" size="50" value="'.api_htmlentities($category_title,ENT_QUOTES,$charset).'" />
  341. </div>
  342. </div>';
  343. echo ' <div class="row">
  344. <div class="label">
  345. '.get_lang('Description').'
  346. </div>
  347. <div class="formw">
  348. <textarea rows="3" cols="50" name="description">'.api_htmlentities($description,ENT_QUOTES,$charset).'</textarea>
  349. </div>
  350. </div>';
  351. echo ' <div class="row">
  352. <div class="label">
  353. </div>
  354. <div class="formw">
  355. <button class="save" type="submit" name="submitCategory">'.$my_cat_title.' </button>
  356. </div>
  357. </div>';
  358. echo "</form>";
  359. }
  360. /*elseif(($_GET['action']=="importcsv") and !$submitImport) // RH start
  361. {
  362. echo "<h4>", get_lang('CsvImport'), "</h4>\n\n",
  363. "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\" enctype=\"multipart/form-data\">",
  364. // uncomment if you want to set a limit: '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  365. '<input type="file" name="import_file" size="30">', "\n",
  366. "<input type=\"Submit\" name=\"submitImport\" value=\"".get_lang('Ok')."\">",
  367. "</form>";
  368. echo get_lang('CsvExplain');
  369. }*/
  370. }
  371. if (!empty($down)) {
  372. movecatlink($down);
  373. }
  374. if (!empty($up)) {
  375. movecatlink($up);
  376. }
  377. if (empty($_GET['action']) || ($_GET['action']!='editlink' && $_GET['action']!='addcategory' && $_GET['action']!='addlink') || $link_submitted || $category_submitted) {
  378. /*
  379. -----------------------------------------------------------
  380. Action Links
  381. -----------------------------------------------------------
  382. */
  383. if ((isset($_GET['action'] ) && $_GET['action']=='editcategory' && isset($_GET['id'])) || (isset($_GET['action']) && $_GET['action']=='addcategory')) {
  384. echo '<br/><br/><br/>';
  385. }
  386. echo '<div class="actions">';
  387. if(api_is_allowed_to_edit(null, true)) {
  388. $urlview = Security::remove_XSS($urlview);
  389. echo Display::return_icon('linksnew.gif',get_lang('LinkAdd'))." <a href=\"".api_get_self()."?".api_get_cidreq()."&action=addlink&amp;category=".(!empty($category)?$category:'')."&amp;urlview=$urlview\">".get_lang("LinkAdd")."</a>\n";
  390. echo Display::return_icon('folder_new.gif', get_lang("CategoryAdd"))." <a href=\"".api_get_self()."?".api_get_cidreq()."&action=addcategory&amp;urlview=".$urlview."\">".get_lang("CategoryAdd")."</a>\n";
  391. /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH*/
  392. }
  393. //making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
  394. //number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
  395. $sqlcategories = "SELECT * FROM ".$tbl_categories." $condition_session ORDER BY display_order DESC";
  396. $resultcategories = Database::query($sqlcategories);
  397. $aantalcategories = Database::num_rows($resultcategories);
  398. if ($aantalcategories > 0) {
  399. echo Display::return_icon('remove.gif', $shownone)." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  400. for($j = 1; $j <= $aantalcategories; $j++) {
  401. echo "0";
  402. }
  403. echo "\">".get_lang('shownone')."</a>";
  404. echo Display::return_icon('add.gif', $showall)." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  405. for($j = 1; $j <= $aantalcategories; $j++)
  406. {
  407. echo "1";
  408. }
  409. echo "\">".get_lang('showall')."</a>";
  410. }
  411. echo '</div>';
  412. //Starting the table which contains the categories
  413. $sqlcategories = "SELECT * FROM ".$tbl_categories." $condition_session ORDER BY display_order DESC";
  414. $resultcategories = Database::query($sqlcategories);
  415. echo '<table class="data_table">';
  416. // displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
  417. $sqlLinks = "SELECT * FROM ".$tbl_link." WHERE category_id=0 or category_id IS NULL";
  418. $result = Database::query($sqlLinks);
  419. $numberofzerocategory=Database::num_rows($result);
  420. if ($numberofzerocategory!==0) {
  421. echo "<tr><th style=\"font-weight: bold; text-align:left;padding-left: 10px;\"><i>".get_lang('General')."</i></th></tr>";
  422. echo '</table>';
  423. showlinksofcategory(0);
  424. }
  425. $i=0;
  426. $catcounter=1;
  427. $view="0";
  428. while ($myrow = Database::fetch_array($resultcategories)) {
  429. //validacion when belongs to a session
  430. $session_img = api_get_session_image($myrow['session_id'], $_user['status']);
  431. //if (!isset($urlview))
  432. if ($urlview == '')
  433. {
  434. // No $view set in the url, thus for each category link it should be all zeros except it's own
  435. makedefaultviewcode($i);
  436. }
  437. else
  438. {
  439. $view=$urlview;
  440. $view[$i]="1";
  441. }
  442. // if the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a
  443. // - instead of a +, the category is no longer clickable and all the links of this category are displayed
  444. $myrow["description"]=text_filter($myrow["description"]);
  445. if ($urlview[$i]=="1")
  446. {
  447. $newurlview=$urlview;
  448. $newurlview[$i]="0";
  449. echo '<tr>';
  450. echo '<table class="data_table">';
  451. echo '<tr>';
  452. echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;">';
  453. echo '<a href="'.api_get_self()."?".api_get_cidreq()."&urlview=".Security::remove_XSS($newurlview)."\">";
  454. echo "<img src=../img/remove.gif>&nbsp;&nbsp;".api_htmlentities($myrow["category_title"],ENT_QUOTES,$charset)."</a><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
  455. if (api_is_allowed_to_edit(null,true))
  456. {
  457. echo '<th>';
  458. showcategoryadmintools($myrow["id"]);
  459. echo '</th>';
  460. }
  461. echo '</th>';
  462. echo '</tr>';
  463. echo '</table>';
  464. echo showlinksofcategory($myrow["id"]);
  465. echo '</tr>';
  466. }
  467. else
  468. {
  469. echo '<tr>';
  470. echo '<table class="data_table">';
  471. echo '<tr>';
  472. echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;"><a href="'.api_get_self()."?".api_get_cidreq()."&urlview=";
  473. echo is_array($view)?implode('',$view):$view;
  474. echo "\"><img src=../img/add.gif>&nbsp;&nbsp;". api_htmlentities($myrow["category_title"],ENT_QUOTES,$charset). $session_img;
  475. echo'</a><br />&nbsp;&nbsp;&nbsp;';
  476. echo $myrow["description"];
  477. if (api_is_allowed_to_edit(null, true))
  478. {
  479. echo '<th style="text-align:center;">';
  480. showcategoryadmintools($myrow["id"]);
  481. echo '</th>';
  482. }
  483. echo '</th>';
  484. echo '</tr>';
  485. echo '</table>';
  486. echo '</tr>';
  487. }
  488. // displaying the link of the category
  489. $i++;
  490. }
  491. echo '</table>';
  492. ////////////////////////////////////////////////////////////////////////////
  493. }
  494. Display::display_footer();
  495. ?>