link.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) 2003-2005 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * Main script for the links tool.
  22. *
  23. * Features:
  24. * - Organize links into categories;
  25. * - favorites/bookmarks-like interface;
  26. * - move links up/down within a category;
  27. * - move categories up/down;
  28. * - expand/collapse all categories (except the main "non"-category);
  29. * - add link to 'root' category => category-less link is always visible.
  30. *
  31. * @author Patrick Cool, main author, completely rewritten
  32. * @author Rene Haentjens, added CSV file import (October 2004)
  33. * @package dokeos.link
  34. * @todo improve organisation, tables should come from database library
  35. ==============================================================================
  36. */
  37. /*
  38. ==============================================================================
  39. INIT SECTION
  40. ==============================================================================
  41. */
  42. $langFile = "link";
  43. include("../inc/global.inc.php");
  44. $this_section=SECTION_COURSES;
  45. api_protect_course_script();
  46. $tbl_link = Database::get_course_table(LINK_TABLE);
  47. $tbl_categories = Database::get_course_table(LINK_CATEGORY_TABLE);
  48. $nameTools = get_lang("Links");
  49. //statistics
  50. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  51. event_access_tool(TOOL_LINK);
  52. Display::display_header($nameTools,"Links");
  53. $is_allowedToEdit = is_allowed_to_edit();
  54. ?>
  55. <script type="text/javascript">
  56. /* <![CDATA[ */
  57. function MM_popupMsg(msg) { //v1.0
  58. confirm(msg);
  59. }
  60. /* ]]> */
  61. </script>
  62. <?php
  63. //api_display_tool_title($nameTools);
  64. /*
  65. -----------------------------------------------------------
  66. Introduction section
  67. (editable by course admins)
  68. -----------------------------------------------------------
  69. */
  70. Display::display_introduction_section(TOOL_LINK);
  71. include("linkfunctions.php");
  72. $link_submitted = $_POST["submitLink"];
  73. $category_submitted = $_POST["submitCategory"];
  74. $urlview = $_GET["urlview"];
  75. $submitImport = $_POST["submitImport"];
  76. $down = $_GET['down'];
  77. $up = $_GET['up'];
  78. $catmove = $_GET['catmove'];
  79. $editlink = $_REQUEST['editlink'];
  80. $id = $_REQUEST['id'];
  81. $urllink = $_REQUEST['urllink'];
  82. $title = $_REQUEST['title'];
  83. $description = $_REQUEST['description'];
  84. $selectcategory = $_REQUEST['selectcategory'];
  85. $submitLink = $_REQUEST['submitLink'];
  86. $action = $_REQUEST['action'];
  87. $category_title = $_REQUEST['category_title'];
  88. $submitCategory = $_REQUEST['submitCategory'];
  89. // treating the post date by calling the relevant function depending of the action querystring.
  90. switch($_GET['action'])
  91. {
  92. case "addlink": if($link_submitted)
  93. {
  94. if(!addlinkcategory("link")) // here we add a link
  95. {
  96. unset($submitLink);
  97. }
  98. }
  99. break;
  100. case "addcategory": if($category_submitted)
  101. {
  102. if(!addlinkcategory("category")) // here we add a category
  103. {
  104. unset($submitCategory);
  105. }
  106. }
  107. break;
  108. case "importcsv": if($submitImport) import_csvfile();
  109. break;
  110. case "deletelink": deletelinkcategory("link"); // here we delete a link
  111. break;
  112. case "deletecategory": deletelinkcategory("category"); // here we delete a category
  113. break;
  114. case "editlink": editlinkcategory("link"); // here we edit a link
  115. break;
  116. case "editcategory": editlinkcategory("category"); // here we edit a category
  117. break;
  118. case "visible": change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
  119. break;
  120. case "invisible": change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
  121. break;
  122. }
  123. if($is_allowedToEdit)
  124. {
  125. echo "<ul>\n";
  126. echo "<li><a href=\"".$_SERVER['PHP_SELF']."?action=addlink&amp;category=".$category."&amp;urlview=$urlview\">".get_lang("LinkAdd")."</a></li>\n",
  127. "<li><a href=\"".$_SERVER['PHP_SELF']."?action=addcategory&amp;urlview=".$urlview."\">".get_lang("CategoryAdd")."</a></li>\n",
  128. /* "<li><a href=\"".$_SERVER['PHP_SELF']."?action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a></li>\n", // RH*/
  129. "</ul>\n\n";
  130. //displaying the error / status messages if there is one
  131. if (!empty($catlinkstatus) or !empty($msgErr))
  132. {
  133. Display :: display_normal_message($catlinkstatus.$msgErr);
  134. unset($catlinkstatus);
  135. unset($msgErr);
  136. }
  137. // Displaying the correct title and the form for adding a category or link. This is only shown when nothing
  138. // has been submitted yet, hence !isset($submitLink)
  139. if (($_GET['action']=="addlink" or $_GET['action']=="editlink") and !$_POST['submitLink'])
  140. {
  141. echo "<h4>";
  142. if ($_GET['action']=="addlink")
  143. {echo get_lang("LinkAdd");}
  144. else
  145. {echo get_lang("LinkMod");}
  146. echo "</h4>\n\n";
  147. if ($category=="")
  148. {$category=0;}
  149. echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."?action=".$_GET['action']."&amp;urlview=".$urlview."\">";
  150. if ($_GET['action']=="editlink")
  151. {
  152. echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['id']."\" />";
  153. }
  154. echo "<table><tr>"
  155. . "<td align=\"right\">URL<span class=\"required\">*</span> :</td>"
  156. . "<td><input type=\"text\" name=\"urllink\" size=\"50\" value=\"" . (empty($urllink)?'http://':htmlentities($urllink)) . "\" /></td>" . "</tr>";
  157. echo "<tr>"
  158. . "<td align=\"right\">" . get_lang("LinkName") . " :</td>"
  159. . "<td><input type=\"text\" name=\"title\" size=\"50\" value=\"" . htmlentities($title) . "\" /></td>"
  160. . "</tr>"
  161. . "<tr>" .
  162. "<td align=\"right\" valign=\"top\">" . get_lang("Description") . " :</td>" .
  163. "<td><textarea wrap=\"physical\" rows=\"3\" cols=\"50\" name=\"description\">" .
  164. htmlentities($description) . "</textarea></td></tr>";
  165. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  166. $resultcategories = api_sql_query($sqlcategories)or die("Error: " . mysql_error());
  167. if(mysql_num_rows($resultcategories))
  168. {
  169. echo "<tr><td align=\"right\">".get_lang("Category")." :</td><td>",
  170. "<select name=\"selectcategory\">",
  171. "<option value=\"0\">--</option>";
  172. while ($myrow = mysql_fetch_array($resultcategories))
  173. {
  174. echo "<option value=\"".$myrow["id"]."\"";
  175. if ($myrow["id"]==$category)
  176. {echo " selected";}
  177. echo ">".$myrow["category_title"]."</option>";
  178. }
  179. echo "</select></td></tr>";
  180. }
  181. echo "<tr><td align=\"right\">".get_lang("OnHomepage")." ? </td><td><input class=\"checkbox\" type=\"checkbox\" name=\"onhomepage\" id=\"onhomepage\" value=\"1\" $onhomepage><label for=\"onhomepage\"> ".get_lang("Yes")."</label></td></tr>";
  182. echo "<tr><td></td><td><input type=\"Submit\" name=\"submitLink\" value=\"".get_lang("Ok")."\" /></td></tr>",
  183. "</table>",
  184. "</form>";
  185. }
  186. elseif(($_GET['action']=="addcategory" or $_GET['action']=="editcategory") and !$submitCategory)
  187. {
  188. echo "<h4>";
  189. if ($_GET['action']=="addcategory")
  190. {echo get_lang("CategoryAdd");}
  191. else
  192. {echo get_lang("CategoryMod");}
  193. echo "</h4>\n\n";
  194. echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."?action=".$_GET['action']."&amp;urlview=".$urlview."\">";
  195. if ($_GET['action']=="editcategory")
  196. {
  197. echo "<input type=\"hidden\" name=\"id\" value=\"".$id."\" />";
  198. }
  199. echo "<table><tr>",
  200. "<td align=\"right\">".get_lang("CategoryName")."<span class=\"required\">*</span> :</td>",
  201. "<td><input type=\"text\" name=\"category_title\" size=\"50\" value=\"",htmlentities($category_title)."\" /></td>",
  202. "</tr>",
  203. "<tr><td align=\"right\" valign=\"top\">".get_lang("Description")." :</td>",
  204. "<td><textarea wrap=\"physical\" rows=\"3\" cols=\"50\" name=\"description\">",htmlentities($description)."</textarea></td></tr>",
  205. "<tr><td></td><td><input type=\"Submit\" name=\"submitCategory\" value=\"".get_lang("Ok")."\"></td></tr>",
  206. "</table>",
  207. "</form>";
  208. }
  209. /*elseif(($_GET['action']=="importcsv") and !$submitImport) // RH start
  210. {
  211. echo "<h4>", get_lang('CsvImport'), "</h4>\n\n",
  212. "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."?action=".$_GET['action']."&amp;urlview=".$urlview."\" enctype=\"multipart/form-data\">",
  213. // uncomment if you want to set a limit: '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  214. '<input type="file" name="import_file" size="30">', "\n",
  215. "<input type=\"Submit\" name=\"submitImport\" value=\"".get_lang('Ok')."\">",
  216. "</form>";
  217. echo get_lang('CsvExplain');
  218. }*/
  219. echo "<hr/>";
  220. }
  221. //making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
  222. //number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
  223. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  224. $resultcategories=api_sql_query($sqlcategories);
  225. $aantalcategories = @mysql_num_rows($resultcategories);
  226. echo "<a href=\"".$_SERVER['PHP_SELF']."?urlview=";
  227. for($j = 1; $j <= $aantalcategories; $j++)
  228. {
  229. echo "0";
  230. }
  231. echo "\">$shownone</a>";
  232. echo " | <a href=\"".$_SERVER['PHP_SELF']."?urlview=";
  233. for($j = 1; $j <= $aantalcategories; $j++)
  234. {
  235. echo "1";
  236. }
  237. echo "\">$showall</a>";
  238. if (isset($down))
  239. {
  240. movecatlink($down);
  241. }
  242. if (isset($up))
  243. {
  244. movecatlink($up);
  245. }
  246. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  247. $resultcategories=api_sql_query($sqlcategories);
  248. //Starting the table which contains the categories
  249. echo "<table width=\"100%\">";
  250. // displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
  251. $sqlLinks = "SELECT * FROM ".$tbl_link." WHERE category_id=0 or category_id IS NULL";
  252. $result = api_sql_query($sqlLinks);
  253. $numberofzerocategory=mysql_num_rows($result);
  254. if ($numberofzerocategory!==0)
  255. {
  256. echo "<tr><td bgcolor=\"#e6e6e6\"><i>".get_lang('NoCategory')."</i></td></tr>";
  257. echo "<tr><td>";
  258. showlinksofcategory(0);
  259. echo "</td></tr>";
  260. }
  261. $i=0;
  262. $catcounter=1;
  263. $view="0";
  264. while ($myrow=@mysql_fetch_array($resultcategories))
  265. {
  266. if (!isset($urlview))
  267. {
  268. // No $view set in the url, thus for each category link it should be all zeros except it's own
  269. makedefaultviewcode($i);
  270. }
  271. else
  272. {
  273. $view=$urlview;
  274. $view[$i]="1";
  275. }
  276. // if the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a
  277. // - instead of a +, the category is no longer clickable and all the links of this category are displayed
  278. $myrow["description"]=text_filter($myrow["description"]);
  279. if ($urlview[$i]=="1")
  280. {
  281. $newurlview=$urlview;
  282. $newurlview[$i]="0";
  283. echo "<tr>",
  284. "<td bgcolor=\"#e6e6e6\"><b>- <a href=\"".$_SERVER['PHP_SELF']."?urlview=".$newurlview."\">".htmlentities($myrow["category_title"])."</a></b><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
  285. if ($is_allowedToEdit)
  286. {
  287. showcategoryadmintools($myrow["id"]);
  288. }
  289. echo "</td>",
  290. "</tr>",
  291. "<tr>",
  292. "<td>",showlinksofcategory($myrow["id"])."</td>",
  293. "</tr>";
  294. }
  295. else
  296. {
  297. echo "<tr><td bgcolor=\"#E6E6E6\"><b>+ <a href=\"".$_SERVER['PHP_SELF']."?urlview=";
  298. echo is_array($view)?implode('',$view):$view;
  299. echo "\">".htmlentities($myrow["category_title"])."</a></b><br>&nbsp;&nbsp;&nbsp;";
  300. echo $myrow["description"];
  301. if ($is_allowedToEdit)
  302. {
  303. showcategoryadmintools($myrow["id"]);
  304. }
  305. echo "</td>",
  306. "</tr>";
  307. }
  308. // displaying the link of the category
  309. $i++;
  310. }
  311. echo "</table>";
  312. //////////////////////////////////////////////////////////////////////////////
  313. Display::display_footer();
  314. ?>