link.php 17 KB

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