link.php 14 KB

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