link.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?php // $Id: link.php 18126 2009-02-01 19:55:12Z 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 = (!empty($_POST['submitLink'])?$_POST['submitLink']:'');
  51. $category_submitted = (!empty($_POST['submitCategory'])?$_POST['submitCategory']:'');
  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 = (!empty($_REQUEST['submitLink'])?$_REQUEST['submitLink']:'');
  64. $action = (!empty($_REQUEST['action'])?$_REQUEST['action']:'');
  65. $category_title = (!empty($_REQUEST['category_title'])?$_REQUEST['category_title']:'');
  66. $submitCategory = (!empty($_REQUEST['submitCategory'])?$_REQUEST['submitCategory']:'');
  67. $nameTools = get_lang('Links');
  68. if (isset($_GET['action']) && $_GET['action']=='addlink')
  69. {
  70. $nameTools = '';
  71. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  72. $interbreadcrumb[] = array ('url' => 'link.php?action=addlink', 'name' => get_lang('AddLink'));
  73. }
  74. if (isset($_GET['action']) && $_GET['action']=='addcategory')
  75. {
  76. $nameTools = '';
  77. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  78. $interbreadcrumb[] = array ('url' => 'link.php?action=addcategory', 'name' => get_lang('AddCategory'));
  79. }
  80. if (isset($_GET['action']) && $_GET['action']=='editlink')
  81. {
  82. $nameTools = '';
  83. $interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
  84. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('EditLink'));
  85. }
  86. // Database Table definitions
  87. $tbl_link = Database::get_course_table(TABLE_LINK);
  88. $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
  89. //statistics
  90. event_access_tool(TOOL_LINK);
  91. Display::display_header($nameTools, 'Links');
  92. ?>
  93. <script type="text/javascript">
  94. /* <![CDATA[ */
  95. function MM_popupMsg(msg) { //v1.0
  96. confirm(msg);
  97. }
  98. /* ]]> */
  99. </script>
  100. <?php
  101. /*
  102. -----------------------------------------------------------
  103. Action Handling
  104. -----------------------------------------------------------
  105. */
  106. $nameTools = get_lang("Links");
  107. if(isset($_GET['action']))
  108. {
  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. -----------------------------------------------------------
  157. Introduction section
  158. -----------------------------------------------------------
  159. */
  160. $fck_attribute['Width'] = '100%';
  161. $fck_attribute['Height'] = '400';
  162. $fck_attribute['ToolbarSet'] = 'Full';
  163. Display::display_introduction_section(TOOL_LINK,'left');
  164. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  165. if (is_allowed_to_edit() and isset($_GET['action']))
  166. {
  167. // Displaying the correct title and the form for adding a category or link. This is only shown when nothing
  168. // has been submitted yet, hence !isset($submitLink)
  169. if (($_GET['action']=="addlink" or $_GET['action']=="editlink") and empty($_POST['submitLink']))
  170. {
  171. if ($_GET['action']=="addlink")
  172. {echo '<div class="form_header">'.get_lang("LinkAdd").'</div>';}
  173. else
  174. {echo '<div class="form_header">'.get_lang("LinkMod").'</div>';}
  175. if ($category=="")
  176. {$category=0;}
  177. echo "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\">";
  178. if ($_GET['action']=="editlink")
  179. {
  180. echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['id']."\" />";
  181. }
  182. echo "<table><tr>"
  183. . "<td align=\"right\">URL<span class=\"required\">*</span> :</td>"
  184. . "<td><input type=\"text\" name=\"urllink\" size=\"50\" value=\"" . (empty($urllink)?'http://':htmlentities($urllink)) . "\" /></td>" . "</tr>";
  185. echo "<tr>"
  186. . "<td align=\"right\">" . get_lang("LinkName") . " :</td>"
  187. . "<td><input type=\"text\" name=\"title\" size=\"50\" value=\"" . htmlentities($title,ENT_QUOTES,$charset) . "\" /></td>"
  188. . "</tr>"
  189. . "<tr>" .
  190. "<td align=\"right\" valign=\"top\">" . get_lang("Description") . " :</td>" .
  191. "<td><textarea rows=\"3\" cols=\"50\" name=\"description\">" .
  192. htmlentities($description,ENT_QUOTES,$charset) . "</textarea></td></tr>";
  193. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  194. $resultcategories = api_sql_query($sqlcategories)or die("Error: " . mysql_error());
  195. if(mysql_num_rows($resultcategories))
  196. {
  197. echo "<tr><td align=\"right\">".get_lang("Category")." :</td><td>",
  198. "<select name=\"selectcategory\">",
  199. "<option value=\"0\">--</option>";
  200. while ($myrow = mysql_fetch_array($resultcategories))
  201. {
  202. echo "<option value=\"".$myrow["id"]."\"";
  203. if ($myrow["id"]==$category)
  204. {echo " selected";}
  205. echo ">".$myrow["category_title"]."</option>";
  206. }
  207. echo "</select></td></tr>";
  208. }
  209. 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>";
  210. if(api_get_setting('search_enabled')=='true')
  211. {
  212. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  213. $specific_fields = get_specific_field_list();
  214. echo '<tr><td align="right">'.get_lang("SearchFeatureDoIndexLink").' ? </td><td><input class="checkbox" type="checkbox" name="index_document" id="index_document" checked="checked"><label for="index_document">'.get_lang("Yes").'</label></td></tr>';
  215. foreach ($specific_fields as $specific_field) {
  216. //Author : <input name="A" type="text" />
  217. $default_values = '';
  218. if ($_GET['action']=="editlink")
  219. {
  220. $filter = array('course_code'=> "'". api_get_course_id() ."'", 'field_id' => $specific_field['id'], 'ref_id' => $_GET['id'], 'tool_id' => '\''. TOOL_LINK .'\'');
  221. $values = get_specific_field_values_list($filter, array('value'));
  222. if ( !empty($values) ) {
  223. $arr_str_values = array();
  224. foreach ($values as $value) {
  225. $arr_str_values[] = $value['value'];
  226. }
  227. $default_values = implode(', ', $arr_str_values);
  228. }
  229. }
  230. $sf_textbox = '<tr><td align="right">%s</td><td><input name="%s" type="text" value="%s"/>';
  231. echo sprintf($sf_textbox, $specific_field['name'], $specific_field['code'], $default_values);
  232. }
  233. }
  234. echo "<tr><td></td><td><input type=\"Submit\" name=\"submitLink\" value=\"".get_lang("Ok")."\" /></td></tr>",
  235. "</table>",
  236. "</form>";
  237. }
  238. elseif(($_GET['action']=="addcategory" or $_GET['action']=="editcategory") and !$submitCategory)
  239. {
  240. echo "<h4>";
  241. if ($_GET['action']=="addcategory")
  242. {echo '<div class="form_header">'.get_lang('CategoryAdd').'</div>';}
  243. else
  244. {echo '<div class="form_header">'.get_lang('CategoryMod').'</div>';}
  245. echo "</h4>\n\n";
  246. echo "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\">";
  247. if ($_GET['action']=="editcategory")
  248. {
  249. echo "<input type=\"hidden\" name=\"id\" value=\"".$id."\" />";
  250. }
  251. echo "<table><tr>",
  252. "<td align=\"right\">".get_lang("CategoryName")."<span class=\"required\">*</span> :</td>",
  253. "<td><input type=\"text\" name=\"category_title\" size=\"50\" value=\"",htmlentities($category_title,ENT_QUOTES,$charset)."\" /></td>",
  254. "</tr>",
  255. "<tr><td align=\"right\" valign=\"top\">".get_lang("Description")." :</td>",
  256. "<td><textarea rows=\"3\" cols=\"50\" name=\"description\">",htmlentities($description,ENT_QUOTES,$charset)."</textarea></td></tr>",
  257. "<tr><td></td><td><input type=\"Submit\" name=\"submitCategory\" value=\"".get_lang("Ok")."\" /></td></tr>",
  258. "</table>",
  259. "</form>";
  260. }
  261. /*elseif(($_GET['action']=="importcsv") and !$submitImport) // RH start
  262. {
  263. echo "<h4>", get_lang('CsvImport'), "</h4>\n\n",
  264. "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\" enctype=\"multipart/form-data\">",
  265. // uncomment if you want to set a limit: '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  266. '<input type="file" name="import_file" size="30">', "\n",
  267. "<input type=\"Submit\" name=\"submitImport\" value=\"".get_lang('Ok')."\">",
  268. "</form>";
  269. echo get_lang('CsvExplain');
  270. }*/
  271. }
  272. if (!empty($down))
  273. {
  274. movecatlink($down);
  275. }
  276. if (!empty($up))
  277. {
  278. movecatlink($up);
  279. }
  280. if (empty($_GET['action']) || ($_GET['action']!='editlink' && $_GET['action']!='addcategory' && $_GET['action']!='addlink') || $link_submitted || $category_submitted)
  281. {
  282. /*
  283. -----------------------------------------------------------
  284. Action Links
  285. -----------------------------------------------------------
  286. */
  287. echo '<div class="actions">';
  288. if(is_allowed_to_edit())
  289. {
  290. 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";
  291. 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";
  292. /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH*/
  293. }
  294. //making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
  295. //number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
  296. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  297. $resultcategories=api_sql_query($sqlcategories);
  298. $aantalcategories = @mysql_num_rows($resultcategories);
  299. echo Display::return_icon('remove.gif', $shownone)." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  300. for($j = 1; $j <= $aantalcategories; $j++)
  301. {
  302. echo "0";
  303. }
  304. echo "\">$shownone</a>";
  305. echo Display::return_icon('add.gif', $showall)." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  306. for($j = 1; $j <= $aantalcategories; $j++)
  307. {
  308. echo "1";
  309. }
  310. echo "\">$showall</a>";
  311. echo '</div>';
  312. //Starting the table which contains the categories
  313. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  314. $resultcategories=api_sql_query($sqlcategories);
  315. echo '<table class="data_table">';
  316. // displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
  317. $sqlLinks = "SELECT * FROM ".$tbl_link." WHERE category_id=0 or category_id IS NULL";
  318. $result = api_sql_query($sqlLinks);
  319. $numberofzerocategory=mysql_num_rows($result);
  320. if ($numberofzerocategory!==0)
  321. {
  322. echo "<tr><th style=\"font-weight: bold; text-align:left;padding-left: 10px;\"><i>".get_lang('General')."</i></th></tr>";
  323. echo '</table>';
  324. showlinksofcategory(0);
  325. }
  326. $i=0;
  327. $catcounter=1;
  328. $view="0";
  329. while ($myrow=@mysql_fetch_array($resultcategories))
  330. {
  331. if (!isset($urlview))
  332. {
  333. // No $view set in the url, thus for each category link it should be all zeros except it's own
  334. makedefaultviewcode($i);
  335. }
  336. else
  337. {
  338. $view=$urlview;
  339. $view[$i]="1";
  340. }
  341. // if the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a
  342. // - instead of a +, the category is no longer clickable and all the links of this category are displayed
  343. $myrow["description"]=text_filter($myrow["description"]);
  344. if ($urlview[$i]=="1")
  345. {
  346. $newurlview=$urlview;
  347. $newurlview[$i]="0";
  348. echo '<tr>';
  349. echo '<table class="data_table">';
  350. echo '<tr>';
  351. echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;">';
  352. echo '<a href="'.api_get_self()."?".api_get_cidreq()."&urlview=".$newurlview."\">";
  353. echo "<img src=../img/remove.gif>&nbsp;&nbsp;".htmlentities($myrow["category_title"],ENT_QUOTES,$charset)."</a><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
  354. if (is_allowed_to_edit())
  355. {
  356. echo '<th>';
  357. showcategoryadmintools($myrow["id"]);
  358. echo '</th>';
  359. }
  360. echo '</th>';
  361. echo '</tr>';
  362. echo '</table>';
  363. echo showlinksofcategory($myrow["id"]);
  364. echo '</tr>';
  365. }
  366. else
  367. {
  368. echo '<tr>';
  369. echo '<table class="data_table">';
  370. echo '<tr>';
  371. echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;"><a href="'.api_get_self()."?".api_get_cidreq()."&urlview=";
  372. echo is_array($view)?implode('',$view):$view;
  373. echo "\"><img src=../img/add.gif>&nbsp;&nbsp;". htmlentities($myrow["category_title"],ENT_QUOTES,$charset);
  374. echo'</a><br />&nbsp;&nbsp;&nbsp;';
  375. echo $myrow["description"];
  376. if (is_allowed_to_edit())
  377. {
  378. echo '<th style="text-align:center;">';
  379. showcategoryadmintools($myrow["id"]);
  380. echo '</th>';
  381. }
  382. echo '</th>';
  383. echo '</tr>';
  384. echo '</table>';
  385. echo '</tr>';
  386. }
  387. // displaying the link of the category
  388. $i++;
  389. }
  390. echo '</table>';
  391. ////////////////////////////////////////////////////////////////////////////
  392. }
  393. Display::display_footer();
  394. ?>