link.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. // name of the language file that needs to be included
  43. $language_file = "link";
  44. // including libraries
  45. include("../inc/global.inc.php");
  46. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  47. include("linkfunctions.php");
  48. $this_section=SECTION_COURSES;
  49. api_protect_course_script();
  50. // Database Table definitions
  51. $tbl_link = Database::get_course_table(TABLE_LINK);
  52. $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
  53. //statistics
  54. event_access_tool(TOOL_LINK);
  55. $nameTools = get_lang("Links");
  56. Display::display_header($nameTools, 'Links');
  57. ?>
  58. <script type="text/javascript">
  59. /* <![CDATA[ */
  60. function MM_popupMsg(msg) { //v1.0
  61. confirm(msg);
  62. }
  63. /* ]]> */
  64. </script>
  65. <?php
  66. /*
  67. -----------------------------------------------------------
  68. Introduction section
  69. -----------------------------------------------------------
  70. */
  71. Display::display_introduction_section(TOOL_LINK);
  72. // @todo change the $_REQUEST into $_POST or $_GET
  73. // @todo remove this code
  74. $link_submitted = $_POST["submitLink"];
  75. $category_submitted = $_POST["submitCategory"];
  76. $urlview = $_GET["urlview"];
  77. $submitImport = $_POST["submitImport"];
  78. $down = $_GET['down'];
  79. $up = $_GET['up'];
  80. $catmove = $_GET['catmove'];
  81. $editlink = $_REQUEST['editlink'];
  82. $id = $_REQUEST['id'];
  83. $urllink = $_REQUEST['urllink'];
  84. $title = $_REQUEST['title'];
  85. $description = $_REQUEST['description'];
  86. $selectcategory = $_REQUEST['selectcategory'];
  87. $submitLink = $_REQUEST['submitLink'];
  88. $action = $_REQUEST['action'];
  89. $category_title = $_REQUEST['category_title'];
  90. $submitCategory = $_REQUEST['submitCategory'];
  91. /*
  92. -----------------------------------------------------------
  93. Action Handling
  94. -----------------------------------------------------------
  95. */
  96. switch($_GET['action'])
  97. {
  98. case "addlink":
  99. if($link_submitted)
  100. {
  101. if(!addlinkcategory("link")) // here we add a link
  102. {
  103. unset($submitLink);
  104. }
  105. }
  106. break;
  107. case "addcategory":
  108. if($category_submitted)
  109. {
  110. if(!addlinkcategory("category")) // here we add a category
  111. {
  112. unset($submitCategory);
  113. }
  114. }
  115. break;
  116. case "importcsv":
  117. if($_POST["submitImport"])
  118. {
  119. import_csvfile();
  120. }
  121. break;
  122. case "deletelink":
  123. deletelinkcategory("link"); // here we delete a link
  124. break;
  125. case "deletecategory":
  126. deletelinkcategory("category"); // here we delete a category
  127. break;
  128. case "editlink":
  129. editlinkcategory("link"); // here we edit a link
  130. break;
  131. case "editcategory":
  132. editlinkcategory("category"); // here we edit a category
  133. break;
  134. case "visible":
  135. change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
  136. break;
  137. case "invisible":
  138. change_visibility($_GET['id'],$_GET['scope']); // here we edit a category
  139. break;
  140. }
  141. if (is_allowed_to_edit())
  142. {
  143. // Displaying the correct title and the form for adding a category or link. This is only shown when nothing
  144. // has been submitted yet, hence !isset($submitLink)
  145. if (($_GET['action']=="addlink" or $_GET['action']=="editlink") and !$_POST['submitLink'])
  146. {
  147. echo "<h4>";
  148. if ($_GET['action']=="addlink")
  149. {echo get_lang("LinkAdd");}
  150. else
  151. {echo get_lang("LinkMod");}
  152. echo "</h4>\n\n";
  153. if ($category=="")
  154. {$category=0;}
  155. echo "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\">";
  156. if ($_GET['action']=="editlink")
  157. {
  158. echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['id']."\" />";
  159. }
  160. echo "<table><tr>"
  161. . "<td align=\"right\">URL<span class=\"required\">*</span> :</td>"
  162. . "<td><input type=\"text\" name=\"urllink\" size=\"50\" value=\"" . (empty($urllink)?'http://':htmlentities($urllink)) . "\" /></td>" . "</tr>";
  163. echo "<tr>"
  164. . "<td align=\"right\">" . get_lang("LinkName") . " :</td>"
  165. . "<td><input type=\"text\" name=\"title\" size=\"50\" value=\"" . htmlentities($title,ENT_QUOTES,$charset) . "\" /></td>"
  166. . "</tr>"
  167. . "<tr>" .
  168. "<td align=\"right\" valign=\"top\">" . get_lang("Description") . " :</td>" .
  169. "<td><textarea rows=\"3\" cols=\"50\" name=\"description\">" .
  170. htmlentities($description,ENT_QUOTES,$charset) . "</textarea></td></tr>";
  171. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  172. $resultcategories = api_sql_query($sqlcategories)or die("Error: " . mysql_error());
  173. if(mysql_num_rows($resultcategories))
  174. {
  175. echo "<tr><td align=\"right\">".get_lang("Category")." :</td><td>",
  176. "<select name=\"selectcategory\">",
  177. "<option value=\"0\">--</option>";
  178. while ($myrow = mysql_fetch_array($resultcategories))
  179. {
  180. echo "<option value=\"".$myrow["id"]."\"";
  181. if ($myrow["id"]==$category)
  182. {echo " selected";}
  183. echo ">".$myrow["category_title"]."</option>";
  184. }
  185. echo "</select></td></tr>";
  186. }
  187. 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>";
  188. echo "<tr><td></td><td><input type=\"Submit\" name=\"submitLink\" value=\"".get_lang("Ok")."\" /></td></tr>",
  189. "</table>",
  190. "</form>";
  191. }
  192. elseif(($_GET['action']=="addcategory" or $_GET['action']=="editcategory") and !$submitCategory)
  193. {
  194. echo "<h4>";
  195. if ($_GET['action']=="addcategory")
  196. {echo get_lang("CategoryAdd");}
  197. else
  198. {echo get_lang("CategoryMod");}
  199. echo "</h4>\n\n";
  200. echo "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\">";
  201. if ($_GET['action']=="editcategory")
  202. {
  203. echo "<input type=\"hidden\" name=\"id\" value=\"".$id."\" />";
  204. }
  205. echo "<table><tr>",
  206. "<td align=\"right\">".get_lang("CategoryName")."<span class=\"required\">*</span> :</td>",
  207. "<td><input type=\"text\" name=\"category_title\" size=\"50\" value=\"",htmlentities($category_title,ENT_QUOTES,$charset)."\" /></td>",
  208. "</tr>",
  209. "<tr><td align=\"right\" valign=\"top\">".get_lang("Description")." :</td>",
  210. "<td><textarea rows=\"3\" cols=\"50\" name=\"description\">",htmlentities($description,ENT_QUOTES,$charset)."</textarea></td></tr>",
  211. "<tr><td></td><td><input type=\"Submit\" name=\"submitCategory\" value=\"".get_lang("Ok")."\" /></td></tr>",
  212. "</table>",
  213. "</form>";
  214. }
  215. /*elseif(($_GET['action']=="importcsv") and !$submitImport) // RH start
  216. {
  217. echo "<h4>", get_lang('CsvImport'), "</h4>\n\n",
  218. "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\" enctype=\"multipart/form-data\">",
  219. // uncomment if you want to set a limit: '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  220. '<input type="file" name="import_file" size="30">', "\n",
  221. "<input type=\"Submit\" name=\"submitImport\" value=\"".get_lang('Ok')."\">",
  222. "</form>";
  223. echo get_lang('CsvExplain');
  224. }*/
  225. }
  226. if (isset($down))
  227. {
  228. movecatlink($down);
  229. }
  230. if (isset($up))
  231. {
  232. movecatlink($up);
  233. }
  234. /*
  235. -----------------------------------------------------------
  236. Action Links
  237. -----------------------------------------------------------
  238. */
  239. if(is_allowed_to_edit())
  240. {
  241. echo Display::return_icon('file_html_new.gif')." <a href=\"".api_get_self()."?".api_get_cidreq()."&action=addlink&amp;category=".$category."&amp;urlview=$urlview\">".get_lang("LinkAdd")."</a>\n";
  242. echo Display::return_icon('folder_new.gif')." <a href=\"".api_get_self()."?".api_get_cidreq()."&action=addcategory&amp;urlview=".$urlview."\">".get_lang("CategoryAdd")."</a>\n";
  243. /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH*/
  244. }
  245. //making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
  246. //number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
  247. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  248. $resultcategories=api_sql_query($sqlcategories);
  249. $aantalcategories = @mysql_num_rows($resultcategories);
  250. echo Display::return_icon('remove.gif')." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  251. for($j = 1; $j <= $aantalcategories; $j++)
  252. {
  253. echo "0";
  254. }
  255. echo "\">$shownone</a>";
  256. echo Display::return_icon('add.gif')." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  257. for($j = 1; $j <= $aantalcategories; $j++)
  258. {
  259. echo "1";
  260. }
  261. echo "\">$showall</a>";
  262. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  263. $resultcategories=api_sql_query($sqlcategories);
  264. //Starting the table which contains the categories
  265. echo "<br /><br /><table class=\"data_table\">";
  266. // displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
  267. $sqlLinks = "SELECT * FROM ".$tbl_link." WHERE category_id=0 or category_id IS NULL";
  268. $result = api_sql_query($sqlLinks);
  269. $numberofzerocategory=mysql_num_rows($result);
  270. if ($numberofzerocategory!==0)
  271. {
  272. echo "<tr><th style=\"font-weight: bold; text-align:left;padding-left: 10px;\"><i>".get_lang('NoCategory')."</i></th></tr>";
  273. echo "<tr><td>";
  274. showlinksofcategory(0);
  275. echo "</td></tr>";
  276. }
  277. $i=0;
  278. $catcounter=1;
  279. $view="0";
  280. while ($myrow=@mysql_fetch_array($resultcategories))
  281. {
  282. if (!isset($urlview))
  283. {
  284. // No $view set in the url, thus for each category link it should be all zeros except it's own
  285. makedefaultviewcode($i);
  286. }
  287. else
  288. {
  289. $view=$urlview;
  290. $view[$i]="1";
  291. }
  292. // if the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a
  293. // - instead of a +, the category is no longer clickable and all the links of this category are displayed
  294. $myrow["description"]=text_filter($myrow["description"]);
  295. if ($urlview[$i]=="1")
  296. {
  297. $newurlview=$urlview;
  298. $newurlview[$i]="0";
  299. echo "<tr>",
  300. "<th style=\"font-weight: bold; text-align:left;padding-left: 10px;\">- <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=".$newurlview."\">".htmlentities($myrow["category_title"],ENT_QUOTES,$charset)."</a><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
  301. if (is_allowed_to_edit())
  302. {
  303. showcategoryadmintools($myrow["id"]);
  304. }
  305. echo "</th>",
  306. "</tr>",
  307. "<tr>",
  308. "<td>",showlinksofcategory($myrow["id"])."</td>",
  309. "</tr>";
  310. }
  311. else
  312. {
  313. echo "<tr><th style=\"font-weight: bold; text-align:left;padding-left: 10px;\">+ <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  314. echo is_array($view)?implode('',$view):$view;
  315. echo "\">".htmlentities($myrow["category_title"],ENT_QUOTES,$charset)."</a><br />&nbsp;&nbsp;&nbsp;";
  316. echo $myrow["description"];
  317. if (is_allowed_to_edit())
  318. {
  319. showcategoryadmintools($myrow["id"]);
  320. }
  321. echo "</th>",
  322. "</tr>";
  323. }
  324. // displaying the link of the category
  325. $i++;
  326. }
  327. echo "</table>";
  328. //////////////////////////////////////////////////////////////////////////////
  329. Display::display_footer();
  330. ?>