link.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <?php // $Id: link.php 21666 2009-06-30 00:20:57Z 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 api_get_path(LIBRARY_PATH).'events.lib.inc.php';
  45. require_once "linkfunctions.php";
  46. $this_section=SECTION_COURSES;
  47. api_protect_course_script();
  48. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  49. $htmlHeadXtra[] = '<script type="text/javascript">
  50. $(document).ready( function() {
  51. for (i=0;i<$(".actions").length;i++) {
  52. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
  53. $(".actions:eq("+i+")").hide();
  54. }
  55. }
  56. } );
  57. </script>';
  58. // @todo change the $_REQUEST into $_POST or $_GET
  59. // @todo remove this code
  60. $link_submitted = (isset($_POST['submitLink'])?true:false);
  61. $category_submitted = (isset($_POST['submitCategory'])?true:false);
  62. $urlview = (!empty($_GET['urlview'])?$_GET['urlview']:'');
  63. $submitImport = (!empty($_POST['submitImport'])?$_POST['submitImport']:'');
  64. $down = (!empty($_GET['down'])?$_GET['down']:'');
  65. $up = (!empty($_GET['up'])?$_GET['up']:'');
  66. $catmove = (!empty($_GET['catmove'])?$_GET['catmove']:'');
  67. $editlink = (!empty($_REQUEST['editlink'])?$_REQUEST['editlink']:'');
  68. $id = (!empty($_REQUEST['id'])?$_REQUEST['id']:'');
  69. $urllink = (!empty($_REQUEST['urllink'])?$_REQUEST['urllink']:'');
  70. $title = (!empty($_REQUEST['title'])?$_REQUEST['title']:'');
  71. $description = (!empty($_REQUEST['description'])?$_REQUEST['description']:'');
  72. $selectcategory = (!empty($_REQUEST['selectcategory'])?$_REQUEST['selectcategory']:'');
  73. $submitLink = (isset($_REQUEST['submitLink'])?true : false);
  74. $action = (!empty($_REQUEST['action'])?$_REQUEST['action']:'');
  75. $category_title = (!empty($_REQUEST['category_title'])?$_REQUEST['category_title']:'');
  76. $submitCategory = isset($_POST['submitCategory'])?true:false;
  77. $nameTools = get_lang('Links');
  78. if (isset($_GET['action']) && $_GET['action']=='addlink') {
  79. $nameTools = '';
  80. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  81. $interbreadcrumb[] = array ('url' => 'link.php?action=addlink', 'name' => get_lang('AddLink'));
  82. }
  83. if (isset($_GET['action']) && $_GET['action']=='addcategory') {
  84. $nameTools = '';
  85. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  86. $interbreadcrumb[] = array ('url' => 'link.php?action=addcategory', 'name' => get_lang('AddCategory'));
  87. }
  88. if (isset($_GET['action']) && $_GET['action']=='editlink') {
  89. $nameTools = '';
  90. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  91. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('EditLink'));
  92. }
  93. // Database Table definitions
  94. $tbl_link = Database::get_course_table(TABLE_LINK);
  95. $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
  96. //statistics
  97. event_access_tool(TOOL_LINK);
  98. Display::display_header($nameTools, 'Links');
  99. ?>
  100. <script type="text/javascript">
  101. /* <![CDATA[ */
  102. function MM_popupMsg(msg) { //v1.0
  103. confirm(msg);
  104. }
  105. /* ]]> */
  106. </script>
  107. <?php
  108. /*
  109. -----------------------------------------------------------
  110. Action Handling
  111. -----------------------------------------------------------
  112. */
  113. $nameTools = get_lang("Links");
  114. if(isset($_GET['action'])) {
  115. switch($_GET['action']) {
  116. case "addlink":
  117. if($link_submitted)
  118. {
  119. if(!addlinkcategory("link")) // here we add a link
  120. {
  121. unset($submitLink);
  122. }
  123. }
  124. break;
  125. case "addcategory":
  126. if($category_submitted)
  127. {
  128. if(!addlinkcategory("category")) // here we add a category
  129. {
  130. unset($submitCategory);
  131. }
  132. }
  133. break;
  134. case "importcsv":
  135. if($_POST["submitImport"])
  136. {
  137. import_csvfile();
  138. }
  139. break;
  140. case "deletelink":
  141. deletelinkcategory("link"); // here we delete a link
  142. break;
  143. case "deletecategory":
  144. deletelinkcategory("category"); // here we delete a category
  145. break;
  146. case "editlink":
  147. editlinkcategory("link"); // here we edit a link
  148. break;
  149. case "editcategory":
  150. editlinkcategory("category"); // here we edit a category
  151. break;
  152. case "visible":
  153. change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
  154. break;
  155. case "invisible":
  156. change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
  157. break;
  158. }
  159. }
  160. /*
  161. -----------------------------------------------------------
  162. Introduction section
  163. -----------------------------------------------------------
  164. */
  165. $fck_attribute['Width'] = '100%';
  166. $fck_attribute['Height'] = '300';
  167. $fck_attribute['ToolbarSet'] = 'Introduction';
  168. Display::display_introduction_section(TOOL_LINK,'left');
  169. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  170. if (is_allowed_to_edit() and isset($_GET['action'])) {
  171. echo '<div class="actions">';
  172. 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>';
  173. echo '</div>';
  174. if(api_get_setting('search_enabled')=='true') {
  175. if (!extension_loaded('xapian')) {
  176. Display::display_error_message(get_lang('SearchXapianModuleNotInstaled'));
  177. }
  178. }
  179. // Displaying the correct title and the form for adding a category or link. This is only shown when nothing
  180. // has been submitted yet, hence !isset($submitLink)
  181. if (($_GET['action']=="addlink" or $_GET['action']=="editlink") and empty($_POST['submitLink'])) {
  182. echo '<div class="row">';
  183. if ($_GET['action']=="addlink")
  184. {echo '<div class="form_header">'.get_lang("LinkAdd").'</div>';}
  185. else
  186. {echo '<div class="form_header">'.get_lang("LinkMod").'</div>';}
  187. echo '</div>';
  188. if ($category=="") {
  189. $category=0;
  190. }
  191. echo "<form method=\"post\" action=\"".api_get_self()."?action=".Security::remove_XSS($_GET['action'])."&amp;urlview=".Security::remove_XSS($urlview)."\">";
  192. if ($_GET['action']=="editlink")
  193. {
  194. echo "<input type=\"hidden\" name=\"id\" value=\"".Security::remove_XSS($_GET['id'])."\" />";
  195. }
  196. echo ' <div class="row">
  197. <div class="label">
  198. <span class="form_required">*</span> '.get_lang('Url').'
  199. </div>
  200. <div class="formw">
  201. <input type="text" name="urllink" size="50" value="' . (empty($urllink)?'http://':api_htmlentities($urllink, ENT_COMPAT, $charset)) . '" />
  202. </div>
  203. </div>';
  204. echo ' <div class="row">
  205. <div class="label">
  206. '.get_lang('LinkName').'
  207. </div>
  208. <div class="formw">
  209. <input type="text" name="title" size="50" value="' . api_htmlentities($title,ENT_QUOTES,$charset) . '" />
  210. </div>
  211. </div>';
  212. echo ' <div class="row">
  213. <div class="label">
  214. '.get_lang('Description').'
  215. </div>
  216. <div class="formw">
  217. <textarea rows="3" cols="50" name="description">' . api_htmlentities($description,ENT_QUOTES,$charset) . '</textarea>
  218. </div>
  219. </div>';
  220. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  221. $resultcategories = api_sql_query($sqlcategories,__FILE__,__LINE__);
  222. if (Database::num_rows($resultcategories)) {
  223. echo ' <div class="row">
  224. <div class="label">
  225. '.get_lang('Category').'
  226. </div>
  227. <div class="formw">';
  228. echo ' <select name="selectcategory">';
  229. echo ' <option value="0">--</option>';
  230. while ($myrow = Database::fetch_array($resultcategories))
  231. {
  232. echo " <option value=\"".$myrow["id"]."\"";
  233. if ($myrow["id"]==$category)
  234. {echo " selected";}
  235. echo ">".$myrow["category_title"]."</option>";
  236. }
  237. echo ' </select>';
  238. echo ' </div>
  239. </div>';
  240. }
  241. echo ' <div class="row">
  242. <div class="label">
  243. '.get_lang('OnHomepage').'?
  244. </div>
  245. <div class="formw">
  246. <input class="checkbox" type="checkbox" name="onhomepage" id="onhomepage" value="1"'.$onhomepage.'><label for="onhomepage"> '.get_lang('Yes').'</label>
  247. </div>
  248. </div>';
  249. if(api_get_setting('search_enabled')=='true')
  250. {
  251. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  252. $specific_fields = get_specific_field_list();
  253. echo ' <div class="row">
  254. <div class="label">
  255. '.get_lang('SearchFeatureDoIndexLink').'?
  256. </div>
  257. <div class="formw">
  258. <input class="checkbox" type="checkbox" name="index_document" id="index_document" checked="checked"><label for="index_document"> '.get_lang('Yes').'</label>
  259. </div>';
  260. foreach ($specific_fields as $specific_field) {
  261. //Author : <input name="A" type="text" />
  262. $default_values = '';
  263. if ($_GET['action']=="editlink")
  264. {
  265. $filter = array('course_code'=> "'". api_get_course_id() ."'", 'field_id' => $specific_field['id'], 'ref_id' => Security::remove_XSS($_GET['id']), 'tool_id' => '\''. TOOL_LINK .'\'');
  266. $values = get_specific_field_values_list($filter, array('value'));
  267. if ( !empty($values) ) {
  268. $arr_str_values = array();
  269. foreach ($values as $value) {
  270. $arr_str_values[] = $value['value'];
  271. }
  272. $default_values = implode(', ', $arr_str_values);
  273. }
  274. }
  275. $sf_textbox = '
  276. <div class="row">
  277. <div class="label">%s</div>
  278. <div class="formw">
  279. <input name="%s" type="text" value="%s"/>
  280. </div>
  281. </div>';
  282. echo sprintf($sf_textbox, $specific_field['name'], $specific_field['code'], $default_values);
  283. }
  284. }
  285. echo ' <div class="row">
  286. <div class="label">
  287. </div>
  288. <div class="formw">
  289. <button class="save" type="Submit" name="submitLink" value="OK">'.get_lang('SaveLink').'</button>
  290. </div>
  291. </div>';
  292. echo '</form>';
  293. } elseif(($_GET['action']=="addcategory" or $_GET['action']=="editcategory") and !$submitCategory) {
  294. echo '<div class="row">';
  295. if ($_GET['action']=="addcategory")
  296. {echo '<div class="form_header">'.get_lang('CategoryAdd').'</div>';}
  297. else
  298. {echo '<div class="form_header">'.get_lang('CategoryMod').'</div>';}
  299. echo "</div>\n\n";
  300. echo "<form method=\"post\" action=\"".api_get_self()."?action=".Security::remove_XSS($_GET['action'])."&amp;urlview=".Security::remove_XSS($urlview)."\">";
  301. if ($_GET['action']=="editcategory")
  302. {
  303. echo "<input type=\"hidden\" name=\"id\" value=\"".$id."\" />";
  304. }
  305. echo ' <div class="row">
  306. <div class="label">
  307. <span class="form_required">*</span> '.get_lang('CategoryName').'
  308. </div>
  309. <div class="formw">
  310. <input type="text" name="category_title" size="50" value="'.api_htmlentities($category_title,ENT_QUOTES,$charset).'" />
  311. </div>
  312. </div>';
  313. echo ' <div class="row">
  314. <div class="label">
  315. '.get_lang('Description').'
  316. </div>
  317. <div class="formw">
  318. <textarea rows="3" cols="50" name="description">'.api_htmlentities($description,ENT_QUOTES,$charset).'</textarea>
  319. </div>
  320. </div>';
  321. echo ' <div class="row">
  322. <div class="label">
  323. </div>
  324. <div class="formw">
  325. <button class="save" type="submit" name="submitCategory">'.get_lang('CreateCategory').' </button>
  326. </div>
  327. </div>';
  328. echo "</form>";
  329. }
  330. /*elseif(($_GET['action']=="importcsv") and !$submitImport) // RH start
  331. {
  332. echo "<h4>", get_lang('CsvImport'), "</h4>\n\n",
  333. "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\" enctype=\"multipart/form-data\">",
  334. // uncomment if you want to set a limit: '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  335. '<input type="file" name="import_file" size="30">', "\n",
  336. "<input type=\"Submit\" name=\"submitImport\" value=\"".get_lang('Ok')."\">",
  337. "</form>";
  338. echo get_lang('CsvExplain');
  339. }*/
  340. }
  341. if (!empty($down)) {
  342. movecatlink($down);
  343. }
  344. if (!empty($up)) {
  345. movecatlink($up);
  346. }
  347. if (empty($_GET['action']) || ($_GET['action']!='editlink' && $_GET['action']!='addcategory' && $_GET['action']!='addlink') || $link_submitted || $category_submitted) {
  348. /*
  349. -----------------------------------------------------------
  350. Action Links
  351. -----------------------------------------------------------
  352. */
  353. echo '<div class="actions">';
  354. if(is_allowed_to_edit()) {
  355. $urlview = Security::remove_XSS($urlview);
  356. 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";
  357. 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";
  358. /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH*/
  359. }
  360. //making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
  361. //number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
  362. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  363. $resultcategories=api_sql_query($sqlcategories);
  364. $aantalcategories = Database::num_rows($resultcategories);
  365. if ($aantalcategories > 0) {
  366. echo Display::return_icon('remove.gif', $shownone)." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  367. for($j = 1; $j <= $aantalcategories; $j++) {
  368. echo "0";
  369. }
  370. echo "\">".get_lang('shownone')."</a>";
  371. echo Display::return_icon('add.gif', $showall)." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  372. for($j = 1; $j <= $aantalcategories; $j++)
  373. {
  374. echo "1";
  375. }
  376. echo "\">".get_lang('showall')."</a>";
  377. }
  378. echo '</div>';
  379. //Starting the table which contains the categories
  380. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  381. $resultcategories=api_sql_query($sqlcategories);
  382. echo '<table class="data_table">';
  383. // displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
  384. $sqlLinks = "SELECT * FROM ".$tbl_link." WHERE category_id=0 or category_id IS NULL";
  385. $result = api_sql_query($sqlLinks);
  386. $numberofzerocategory=Database::num_rows($result);
  387. if ($numberofzerocategory!==0) {
  388. echo "<tr><th style=\"font-weight: bold; text-align:left;padding-left: 10px;\"><i>".get_lang('General')."</i></th></tr>";
  389. echo '</table>';
  390. showlinksofcategory(0);
  391. }
  392. $i=0;
  393. $catcounter=1;
  394. $view="0";
  395. while ($myrow=Database::fetch_array($resultcategories))
  396. {
  397. //if (!isset($urlview))
  398. if ($urlview == '')
  399. {
  400. // No $view set in the url, thus for each category link it should be all zeros except it's own
  401. makedefaultviewcode($i);
  402. }
  403. else
  404. {
  405. $view=$urlview;
  406. $view[$i]="1";
  407. }
  408. // if the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a
  409. // - instead of a +, the category is no longer clickable and all the links of this category are displayed
  410. $myrow["description"]=text_filter($myrow["description"]);
  411. if ($urlview[$i]=="1")
  412. {
  413. $newurlview=$urlview;
  414. $newurlview[$i]="0";
  415. echo '<tr>';
  416. echo '<table class="data_table">';
  417. echo '<tr>';
  418. echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;">';
  419. echo '<a href="'.api_get_self()."?".api_get_cidreq()."&urlview=".Security::remove_XSS($newurlview)."\">";
  420. echo "<img src=../img/remove.gif>&nbsp;&nbsp;".api_htmlentities($myrow["category_title"],ENT_QUOTES,$charset)."</a><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
  421. if (is_allowed_to_edit())
  422. {
  423. echo '<th>';
  424. showcategoryadmintools($myrow["id"]);
  425. echo '</th>';
  426. }
  427. echo '</th>';
  428. echo '</tr>';
  429. echo '</table>';
  430. echo showlinksofcategory($myrow["id"]);
  431. echo '</tr>';
  432. }
  433. else
  434. {
  435. echo '<tr>';
  436. echo '<table class="data_table">';
  437. echo '<tr>';
  438. echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;"><a href="'.api_get_self()."?".api_get_cidreq()."&urlview=";
  439. echo is_array($view)?implode('',$view):$view;
  440. echo "\"><img src=../img/add.gif>&nbsp;&nbsp;". api_htmlentities($myrow["category_title"],ENT_QUOTES,$charset);
  441. echo'</a><br />&nbsp;&nbsp;&nbsp;';
  442. echo $myrow["description"];
  443. if (is_allowed_to_edit())
  444. {
  445. echo '<th style="text-align:center;">';
  446. showcategoryadmintools($myrow["id"]);
  447. echo '</th>';
  448. }
  449. echo '</th>';
  450. echo '</tr>';
  451. echo '</table>';
  452. echo '</tr>';
  453. }
  454. // displaying the link of the category
  455. $i++;
  456. }
  457. echo '</table>';
  458. ////////////////////////////////////////////////////////////////////////////
  459. }
  460. Display::display_footer();
  461. ?>