link.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. <?php // $Id: link.php 21662 2009-06-29 14:55:09Z iflorespaz $
  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 = array('link','admin');
  42. // including libraries
  43. require_once "../inc/global.inc.php";
  44. require_once api_get_path(LIBRARY_PATH).'events.lib.inc.php';
  45. require_once "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. if(api_get_setting('search_enabled')=='true') {
  165. if (!extension_loaded('xapian')) {
  166. Display::display_error_message(get_lang('SearchXapianModuleNotInstaled'));
  167. }
  168. }
  169. // Displaying the correct title and the form for adding a category or link. This is only shown when nothing
  170. // has been submitted yet, hence !isset($submitLink)
  171. if (($_GET['action']=="addlink" or $_GET['action']=="editlink") and empty($_POST['submitLink'])) {
  172. echo '<div class="row">';
  173. if ($_GET['action']=="addlink")
  174. {echo '<div class="form_header">'.get_lang("LinkAdd").'</div>';}
  175. else
  176. {echo '<div class="form_header">'.get_lang("LinkMod").'</div>';}
  177. echo '</div>';
  178. if ($category=="") {
  179. $category=0;
  180. }
  181. echo "<form method=\"post\" action=\"".api_get_self()."?action=".Security::remove_XSS($_GET['action'])."&amp;urlview=".Security::remove_XSS($urlview)."\">";
  182. if ($_GET['action']=="editlink")
  183. {
  184. echo "<input type=\"hidden\" name=\"id\" value=\"".Security::remove_XSS($_GET['id'])."\" />";
  185. }
  186. echo ' <div class="row">
  187. <div class="label">
  188. <span class="form_required">*</span> '.get_lang('Url').'
  189. </div>
  190. <div class="formw">
  191. <input type="text" name="urllink" size="50" value="' . (empty($urllink)?'http://':api_htmlentities($urllink, ENT_COMPAT, $charset)) . '" />
  192. </div>
  193. </div>';
  194. echo ' <div class="row">
  195. <div class="label">
  196. '.get_lang('LinkName').'
  197. </div>
  198. <div class="formw">
  199. <input type="text" name="title" size="50" value="' . api_htmlentities($title,ENT_QUOTES,$charset) . '" />
  200. </div>
  201. </div>';
  202. echo ' <div class="row">
  203. <div class="label">
  204. '.get_lang('Description').'
  205. </div>
  206. <div class="formw">
  207. <textarea rows="3" cols="50" name="description">' . api_htmlentities($description,ENT_QUOTES,$charset) . '</textarea>
  208. </div>
  209. </div>';
  210. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  211. $resultcategories = api_sql_query($sqlcategories,__FILE__,__LINE__);
  212. if (Database::num_rows($resultcategories)) {
  213. echo ' <div class="row">
  214. <div class="label">
  215. '.get_lang('Category').'
  216. </div>
  217. <div class="formw">';
  218. echo ' <select name="selectcategory">';
  219. echo ' <option value="0">--</option>';
  220. while ($myrow = Database::fetch_array($resultcategories))
  221. {
  222. echo " <option value=\"".$myrow["id"]."\"";
  223. if ($myrow["id"]==$category)
  224. {echo " selected";}
  225. echo ">".$myrow["category_title"]."</option>";
  226. }
  227. echo ' </select>';
  228. echo ' </div>
  229. </div>';
  230. }
  231. echo ' <div class="row">
  232. <div class="label">
  233. '.get_lang('OnHomepage').'?
  234. </div>
  235. <div class="formw">
  236. <input class="checkbox" type="checkbox" name="onhomepage" id="onhomepage" value="1"'.$onhomepage.'><label for="onhomepage"> '.get_lang('Yes').'</label>
  237. </div>
  238. </div>';
  239. if(api_get_setting('search_enabled')=='true')
  240. {
  241. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  242. $specific_fields = get_specific_field_list();
  243. echo ' <div class="row">
  244. <div class="label">
  245. '.get_lang('SearchFeatureDoIndexLink').'?
  246. </div>
  247. <div class="formw">
  248. <input class="checkbox" type="checkbox" name="index_document" id="index_document" checked="checked"><label for="index_document"> '.get_lang('Yes').'</label>
  249. </div>';
  250. foreach ($specific_fields as $specific_field) {
  251. //Author : <input name="A" type="text" />
  252. $default_values = '';
  253. if ($_GET['action']=="editlink")
  254. {
  255. $filter = array('course_code'=> "'". api_get_course_id() ."'", 'field_id' => $specific_field['id'], 'ref_id' => Security::remove_XSS($_GET['id']), 'tool_id' => '\''. TOOL_LINK .'\'');
  256. $values = get_specific_field_values_list($filter, array('value'));
  257. if ( !empty($values) ) {
  258. $arr_str_values = array();
  259. foreach ($values as $value) {
  260. $arr_str_values[] = $value['value'];
  261. }
  262. $default_values = implode(', ', $arr_str_values);
  263. }
  264. }
  265. $sf_textbox = '
  266. <div class="row">
  267. <div class="label">%s</div>
  268. <div class="formw">
  269. <input name="%s" type="text" value="%s"/>
  270. </div>
  271. </div>';
  272. echo sprintf($sf_textbox, $specific_field['name'], $specific_field['code'], $default_values);
  273. }
  274. }
  275. echo ' <div class="row">
  276. <div class="label">
  277. </div>
  278. <div class="formw">
  279. <button class="save" type="Submit" name="submitLink" value="OK">'.get_lang('SaveLink').'</button>
  280. </div>
  281. </div>';
  282. echo '</form>';
  283. } elseif(($_GET['action']=="addcategory" or $_GET['action']=="editcategory") and !$submitCategory) {
  284. echo '<div class="row">';
  285. if ($_GET['action']=="addcategory")
  286. {echo '<div class="form_header">'.get_lang('CategoryAdd').'</div>';}
  287. else
  288. {echo '<div class="form_header">'.get_lang('CategoryMod').'</div>';}
  289. echo "</div>\n\n";
  290. echo "<form method=\"post\" action=\"".api_get_self()."?action=".Security::remove_XSS($_GET['action'])."&amp;urlview=".Security::remove_XSS($urlview)."\">";
  291. if ($_GET['action']=="editcategory")
  292. {
  293. echo "<input type=\"hidden\" name=\"id\" value=\"".$id."\" />";
  294. }
  295. echo ' <div class="row">
  296. <div class="label">
  297. <span class="form_required">*</span> '.get_lang('CategoryName').'
  298. </div>
  299. <div class="formw">
  300. <input type="text" name="category_title" size="50" value="'.api_htmlentities($category_title,ENT_QUOTES,$charset).'" />
  301. </div>
  302. </div>';
  303. echo ' <div class="row">
  304. <div class="label">
  305. '.get_lang('Description').'
  306. </div>
  307. <div class="formw">
  308. <textarea rows="3" cols="50" name="description">'.api_htmlentities($description,ENT_QUOTES,$charset).'</textarea>
  309. </div>
  310. </div>';
  311. echo ' <div class="row">
  312. <div class="label">
  313. </div>
  314. <div class="formw">
  315. <button class="save" type="submit" name="submitCategory">'.get_lang('CreateCategory').' </button>
  316. </div>
  317. </div>';
  318. echo "</form>";
  319. }
  320. /*elseif(($_GET['action']=="importcsv") and !$submitImport) // RH start
  321. {
  322. echo "<h4>", get_lang('CsvImport'), "</h4>\n\n",
  323. "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\" enctype=\"multipart/form-data\">",
  324. // uncomment if you want to set a limit: '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  325. '<input type="file" name="import_file" size="30">', "\n",
  326. "<input type=\"Submit\" name=\"submitImport\" value=\"".get_lang('Ok')."\">",
  327. "</form>";
  328. echo get_lang('CsvExplain');
  329. }*/
  330. }
  331. if (!empty($down)) {
  332. movecatlink($down);
  333. }
  334. if (!empty($up)) {
  335. movecatlink($up);
  336. }
  337. if (empty($_GET['action']) || ($_GET['action']!='editlink' && $_GET['action']!='addcategory' && $_GET['action']!='addlink') || $link_submitted || $category_submitted) {
  338. /*
  339. -----------------------------------------------------------
  340. Action Links
  341. -----------------------------------------------------------
  342. */
  343. echo '<div class="actions">';
  344. if(is_allowed_to_edit()) {
  345. $urlview = Security::remove_XSS($urlview);
  346. 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";
  347. 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";
  348. /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH*/
  349. }
  350. //making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
  351. //number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
  352. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  353. $resultcategories=api_sql_query($sqlcategories);
  354. $aantalcategories = Database::num_rows($resultcategories);
  355. if ($aantalcategories > 0) {
  356. echo Display::return_icon('remove.gif', $shownone)." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  357. for($j = 1; $j <= $aantalcategories; $j++) {
  358. echo "0";
  359. }
  360. echo "\">".get_lang('shownone')."</a>";
  361. echo Display::return_icon('add.gif', $showall)." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  362. for($j = 1; $j <= $aantalcategories; $j++)
  363. {
  364. echo "1";
  365. }
  366. echo "\">".get_lang('showall')."</a>";
  367. }
  368. echo '</div>';
  369. //Starting the table which contains the categories
  370. $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  371. $resultcategories=api_sql_query($sqlcategories);
  372. echo '<table class="data_table">';
  373. // displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
  374. $sqlLinks = "SELECT * FROM ".$tbl_link." WHERE category_id=0 or category_id IS NULL";
  375. $result = api_sql_query($sqlLinks);
  376. $numberofzerocategory=Database::num_rows($result);
  377. if ($numberofzerocategory!==0) {
  378. echo "<tr><th style=\"font-weight: bold; text-align:left;padding-left: 10px;\"><i>".get_lang('General')."</i></th></tr>";
  379. echo '</table>';
  380. showlinksofcategory(0);
  381. }
  382. $i=0;
  383. $catcounter=1;
  384. $view="0";
  385. while ($myrow=Database::fetch_array($resultcategories))
  386. {
  387. //if (!isset($urlview))
  388. if ($urlview == '')
  389. {
  390. // No $view set in the url, thus for each category link it should be all zeros except it's own
  391. makedefaultviewcode($i);
  392. }
  393. else
  394. {
  395. $view=$urlview;
  396. $view[$i]="1";
  397. }
  398. // if the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a
  399. // - instead of a +, the category is no longer clickable and all the links of this category are displayed
  400. $myrow["description"]=text_filter($myrow["description"]);
  401. if ($urlview[$i]=="1")
  402. {
  403. $newurlview=$urlview;
  404. $newurlview[$i]="0";
  405. echo '<tr>';
  406. echo '<table class="data_table">';
  407. echo '<tr>';
  408. echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;">';
  409. echo '<a href="'.api_get_self()."?".api_get_cidreq()."&urlview=".Security::remove_XSS($newurlview)."\">";
  410. echo "<img src=../img/remove.gif>&nbsp;&nbsp;".api_htmlentities($myrow["category_title"],ENT_QUOTES,$charset)."</a><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
  411. if (is_allowed_to_edit())
  412. {
  413. echo '<th>';
  414. showcategoryadmintools($myrow["id"]);
  415. echo '</th>';
  416. }
  417. echo '</th>';
  418. echo '</tr>';
  419. echo '</table>';
  420. echo showlinksofcategory($myrow["id"]);
  421. echo '</tr>';
  422. }
  423. else
  424. {
  425. echo '<tr>';
  426. echo '<table class="data_table">';
  427. echo '<tr>';
  428. echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;"><a href="'.api_get_self()."?".api_get_cidreq()."&urlview=";
  429. echo is_array($view)?implode('',$view):$view;
  430. echo "\"><img src=../img/add.gif>&nbsp;&nbsp;". api_htmlentities($myrow["category_title"],ENT_QUOTES,$charset);
  431. echo'</a><br />&nbsp;&nbsp;&nbsp;';
  432. echo $myrow["description"];
  433. if (is_allowed_to_edit())
  434. {
  435. echo '<th style="text-align:center;">';
  436. showcategoryadmintools($myrow["id"]);
  437. echo '</th>';
  438. }
  439. echo '</th>';
  440. echo '</tr>';
  441. echo '</table>';
  442. echo '</tr>';
  443. }
  444. // displaying the link of the category
  445. $i++;
  446. }
  447. echo '</table>';
  448. ////////////////////////////////////////////////////////////////////////////
  449. }
  450. Display::display_footer();
  451. ?>