dokeos-link
[ class tree: dokeos-link ] [ index: dokeos-link ] [ all elements ]

Source for file link.php

Documentation is available at link.php

  1. <?php
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004-2008 Dokeos SPRL
  7.     Copyright (c) 2003-2005 Ghent University (UGent)
  8.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9.  
  10.     For a full list of contributors, see "credits.txt".
  11.     The full license can be read in "license.txt".
  12.  
  13.     This program is free software; you can redistribute it and/or
  14.     modify it under the terms of the GNU General Public License
  15.     as published by the Free Software Foundation; either version 2
  16.     of the License, or (at your option) any later version.
  17.  
  18.     See the GNU General Public License for more details.
  19.  
  20.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  21.     Mail: info@dokeos.com
  22. ==============================================================================
  23. */
  24. /**
  25. ==============================================================================
  26. * Main script for the links tool.
  27. *
  28. * Features:
  29. * - Organize links into categories;
  30. * - favorites/bookmarks-like interface;
  31. * - move links up/down within a category;
  32. * - move categories up/down;
  33. * - expand/collapse all categories (except the main "non"-category);
  34. * - add link to 'root' category => category-less link is always visible.
  35. *
  36. @author Patrick Cool, main author, completely rewritten
  37. @author Rene Haentjens, added CSV file import (October 2004)
  38. @package dokeos.link
  39. @todo improve organisation, tables should come from database library
  40. ==============================================================================
  41. */
  42.  
  43. /*
  44. ==============================================================================
  45.         INIT SECTION
  46. ==============================================================================
  47. */
  48. // name of the language file that needs to be included
  49. $language_file "link";
  50.  
  51. // including libraries
  52. include("../inc/global.inc.php");
  53. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  54. include("linkfunctions.php");
  55.  
  56.  
  57. $this_section=SECTION_COURSES;
  58.  
  59.  
  60. // @todo change the $_REQUEST into $_POST or $_GET
  61. // @todo remove this code
  62. $link_submitted (!empty($_POST['submitLink'])?$_POST['submitLink']:'');
  63. $category_submitted (!empty($_POST['submitCategory'])?$_POST['submitCategory']:'');
  64. $urlview (!empty($_GET['urlview'])?$_GET['urlview']:'');
  65. $submitImport (!empty($_POST['submitImport'])?$_POST['submitImport']:'');
  66. $down (!empty($_GET['down'])?$_GET['down']:'');
  67. $up (!empty($_GET['up'])?$_GET['up']:'');
  68. $catmove (!empty($_GET['catmove'])?$_GET['catmove']:'');
  69. $editlink (!empty($_REQUEST['editlink'])?$_REQUEST['editlink']:'');
  70. $id (!empty($_REQUEST['id'])?$_REQUEST['id']:'');
  71. $urllink (!empty($_REQUEST['urllink'])?$_REQUEST['urllink']:'');
  72. $title (!empty($_REQUEST['title'])?$_REQUEST['title']:'');
  73. $description (!empty($_REQUEST['description'])?$_REQUEST['description']:'');
  74. $selectcategory (!empty($_REQUEST['selectcategory'])?$_REQUEST['selectcategory']:'');
  75. $submitLink (!empty($_REQUEST['submitLink'])?$_REQUEST['submitLink']:'');
  76. $action (!empty($_REQUEST['action'])?$_REQUEST['action']:'');
  77. $category_title (!empty($_REQUEST['category_title'])?$_REQUEST['category_title']:'');
  78. $submitCategory (!empty($_REQUEST['submitCategory'])?$_REQUEST['submitCategory']:'');
  79.  
  80. $nameTools get_lang('Links');
  81.  
  82.     if (isset($_GET['action']&& $_GET['action']=='addlink')
  83.     {
  84.         $nameTools '';
  85.         $interbreadcrumb[array ('url' => 'link.php''name' => get_lang('Links'));
  86.         $interbreadcrumb[array ('url' => 'link.php?action=addlink''name' => get_lang('AddLink'));
  87.     }    
  88.     
  89.     if (isset($_GET['action']&& $_GET['action']=='addcategory'
  90.     {
  91.         $nameTools '';
  92.         $interbreadcrumb[array ('url' => 'link.php''name' => get_lang('Links'));
  93.         $interbreadcrumb[array ('url' => 'link.php?action=addcategory''name' => get_lang('AddCategory'));
  94.     }
  95.     
  96.     if (isset($_GET['action']&& $_GET['action']=='editlink'
  97.     {
  98.         $nameTools '';
  99.         $interbreadcrumb[array ('url' => 'link.php''name' => get_lang('Links'));
  100.         $interbreadcrumb[array ('url' => '#''name' => get_lang('EditLink'));
  101.     }         
  102.     
  103.         
  104.         
  105. // Database Table definitions
  106.  
  107. //statistics
  108.  
  109. Display::display_header($nameTools'Links');
  110. ?>
  111. <script type="text/javascript">
  112. /* <![CDATA[ */
  113. function MM_popupMsg(msg) { //v1.0
  114.   confirm(msg);
  115. }
  116. /* ]]> */
  117. </script>
  118.  
  119. <?php
  120.  
  121.  
  122.  
  123. /*
  124. -----------------------------------------------------------
  125.     Action Handling
  126. -----------------------------------------------------------
  127. */
  128. $nameTools get_lang("Links");
  129.  
  130. if(isset($_GET['action']))
  131. {
  132.     switch($_GET['action'])
  133.     {
  134.         case "addlink":        
  135.             if($link_submitted)
  136.             {
  137.                 if(!addlinkcategory("link"))    // here we add a link
  138.                 {
  139.                     unset($submitLink);
  140.                 }
  141.             }
  142.             break;
  143.         case "addcategory":        
  144.             if($category_submitted)
  145.             {
  146.                 if(!addlinkcategory("category"))    // here we add a category
  147.                 {
  148.                     unset($submitCategory);
  149.                 }
  150.             }
  151.             break;        
  152.         case "importcsv":
  153.             if($_POST["submitImport"])
  154.             {
  155.                 import_csvfile();
  156.             }
  157.             break;
  158.         case "deletelink":
  159.             deletelinkcategory("link")// here we delete a link
  160.             break;
  161.             
  162.         case "deletecategory":
  163.             deletelinkcategory("category")// here we delete a category
  164.             break;
  165.         case "editlink":
  166.             editlinkcategory("link")// here we edit a link
  167.             break;
  168.         case "editcategory":
  169.             editlinkcategory("category")// here we edit a category
  170.             break;
  171.         case "visible":
  172.             change_visibility($_GET['id'],$_GET['scope'])// here we edit a category
  173.             break;
  174.         case "invisible":
  175.             change_visibility($_GET['id'],$_GET['scope'])// here we edit a category
  176.             break;
  177.     }
  178. }
  179.  
  180. /*
  181. -----------------------------------------------------------
  182.     Introduction section
  183. -----------------------------------------------------------
  184. */
  185.  
  186.  
  187. if (is_allowed_to_edit(and isset($_GET['action']))
  188. {
  189.     // Displaying the correct title and the form for adding a category or link. This is only shown when nothing
  190.     // has been submitted yet, hence !isset($submitLink)
  191.     if (($_GET['action']=="addlink" or $_GET['action']=="editlink"and empty($_POST['submitLink']))
  192.     {
  193.         echo "<h4>";
  194.         if ($_GET['action']=="addlink")
  195.             {echo get_lang("LinkAdd");}
  196.         else
  197.             {echo get_lang("LinkMod");}
  198.         echo "</h4>\n\n";
  199.         if ($category=="")
  200.             {$category=0;}
  201.         echo "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\">";
  202.         if ($_GET['action']=="editlink")
  203.         {
  204.             echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['id']."\" />";
  205.         }
  206.  
  207.         echo "<table><tr>"
  208.             . "<td align=\"right\">URL<span class=\"required\">*</span>  :</td>"
  209.             . "<td><input type=\"text\" name=\"urllink\" size=\"50\" value=\"" (empty($urllink)?'http://':htmlentities($urllink)) "\" /></td>"            "</tr>";
  210.         echo "<tr>"
  211.                 . "<td align=\"right\">" get_lang("LinkName"" :</td>"
  212.                 . "<td><input type=\"text\" name=\"title\" size=\"50\" value=\"" htmlentities($title,ENT_QUOTES,$charset"\" /></td>"
  213.                 . "</tr>"
  214.                 . "<tr>" .
  215.                 "<td align=\"right\" valign=\"top\">" get_lang("Description"" :</td>" .
  216.                 "<td><textarea rows=\"3\" cols=\"50\" name=\"description\">" .
  217.                 htmlentities($description,ENT_QUOTES,$charset"</textarea></td></tr>";
  218.  
  219.         $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  220.         $resultcategories api_sql_query($sqlcategories)or die("Error: " mysql_error());
  221.  
  222.         if(mysql_num_rows($resultcategories))
  223.         {
  224.             echo    "<tr><td align=\"right\">".get_lang("Category")." :</td><td>",
  225.                     "<select name=\"selectcategory\">",
  226.                     "<option value=\"0\">--</option>";
  227.  
  228.             while ($myrow mysql_fetch_array($resultcategories))
  229.             {
  230.                 echo "<option value=\"".$myrow["id"]."\"";
  231.                 if ($myrow["id"]==$category)
  232.                     {echo " selected";}
  233.                 echo ">".$myrow["category_title"]."</option>";
  234.             }
  235.             echo "</select></td></tr>";
  236.         }
  237.  
  238.         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>";
  239.  
  240.         echo "<tr><td></td><td><input type=\"Submit\" name=\"submitLink\" value=\"".get_lang("Ok")."\" /></td></tr>",
  241.             "</table>",
  242.             "</form>";
  243.     }
  244.     elseif(($_GET['action']=="addcategory" or $_GET['action']=="editcategory"and !$submitCategory)
  245.     {
  246.         echo "<h4>";
  247.         if ($_GET['action']=="addcategory")
  248.             {echo get_lang("CategoryAdd");}
  249.         else
  250.             {echo get_lang("CategoryMod");}
  251.         echo "</h4>\n\n";
  252.         echo "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\">";
  253.         if ($_GET['action']=="editcategory")
  254.         {
  255.             echo "<input type=\"hidden\" name=\"id\" value=\"".$id."\" />";
  256.         }
  257.         echo "<table><tr>",
  258.             "<td align=\"right\">".get_lang("CategoryName")."<span class=\"required\">*</span>  :</td>",
  259.             "<td><input type=\"text\" name=\"category_title\" size=\"50\" value=\"",htmlentities($category_title,ENT_QUOTES,$charset)."\" /></td>",
  260.             "</tr>",
  261.             "<tr><td align=\"right\" valign=\"top\">".get_lang("Description")." :</td>",
  262.             "<td><textarea rows=\"3\" cols=\"50\" name=\"description\">",htmlentities($description,ENT_QUOTES,$charset)."</textarea></td></tr>",
  263.             "<tr><td></td><td><input type=\"Submit\" name=\"submitCategory\" value=\"".get_lang("Ok")."\" /></td></tr>",
  264.             "</table>",
  265.             "</form>";
  266.     }
  267.     /*elseif(($_GET['action']=="importcsv") and !$submitImport)  // RH start
  268.     {
  269.         echo "<h4>", get_lang('CsvImport'), "</h4>\n\n",
  270.              "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\" enctype=\"multipart/form-data\">",
  271.                 // uncomment if you want to set a limit: '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  272.                 '<input type="file" name="import_file" size="30">', "\n",
  273.                  "<input type=\"Submit\" name=\"submitImport\" value=\"".get_lang('Ok')."\">",
  274.              "</form>";
  275.         echo get_lang('CsvExplain');
  276.     }*/
  277. }
  278.  
  279.  
  280. if (!empty($down))
  281.     {
  282.     movecatlink($down);
  283.     }
  284. if (!empty($up))
  285.     {
  286.     movecatlink($up);
  287.     }
  288.  
  289. if (empty($_GET['action']|| ($_GET['action']!='editlink' && $_GET['action']!='addcategory' && $_GET['action']!='addlink'|| $link_submitted || $category_submitted)
  290. {    
  291.     /*
  292.     -----------------------------------------------------------
  293.         Action Links
  294.     -----------------------------------------------------------
  295.     */
  296.     
  297.     if(is_allowed_to_edit())
  298.     {
  299.         echo Display::return_icon('file_html_new.gif')." <a href=\"".api_get_self()."?".api_get_cidreq()."&action=addlink&amp;category=".(!empty($category)?$category:'')."&amp;urlview=$urlview\">".get_lang("LinkAdd")."</a>\n";
  300.         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";
  301.            /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH*/
  302.     }
  303.     //making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
  304.     //number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
  305.     $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  306.     $resultcategories=api_sql_query($sqlcategories);
  307.     $aantalcategories @mysql_num_rows($resultcategories);
  308.     echo Display::return_icon('remove.gif')." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  309.     for($j 1$j <= $aantalcategories$j++)
  310.     {
  311.         echo "0";
  312.     }
  313.     echo "\">$shownone</a>";
  314.     echo Display::return_icon('add.gif')." <a href=\"".api_get_self()."?".api_get_cidreq()."&urlview=";
  315.     for($j 1$j <= $aantalcategories$j++)
  316.     {
  317.     echo "1";
  318.     }
  319.     echo "\">$showall</a>";
  320.  
  321.     //Starting the table which contains the categories
  322.     
  323.     $sqlcategories="SELECT * FROM ".$tbl_categories." ORDER BY display_order DESC";
  324.     $resultcategories=api_sql_query($sqlcategories);
  325.     
  326.     echo '<br /><br /><table class="data_table">';
  327.     // displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
  328.         $sqlLinks "SELECT * FROM ".$tbl_link." WHERE category_id=0 or category_id IS NULL";
  329.         $result api_sql_query($sqlLinks);
  330.         $numberofzerocategory=mysql_num_rows($result);
  331.         
  332.         if ($numberofzerocategory!==0)
  333.         {
  334.             echo "<tr><th style=\"font-weight: bold; text-align:left;padding-left: 10px;\"><i>".get_lang('General')."</i></th></tr>";
  335.             echo '</table>';    
  336.             showlinksofcategory(0);        
  337.         }
  338.         
  339.     $i=0;
  340.     $catcounter=1;
  341.     $view="0";
  342.     
  343.     while ($myrow=@mysql_fetch_array($resultcategories))
  344.     {
  345.         if (!isset($urlview))
  346.         {
  347.             // No $view set in the url, thus for each category link it should be all zeros except it's own
  348.             makedefaultviewcode($i);
  349.         }
  350.         else
  351.         {
  352.             $view=$urlview;
  353.             $view[$i]="1";
  354.         }
  355.         // if the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a
  356.         // - instead of a +, the category is no longer clickable and all the links of this category are displayed
  357.         $myrow["description"]=text_filter($myrow["description"]);
  358.         
  359.         if ($urlview[$i]=="1")
  360.         {
  361.             $newurlview=$urlview;
  362.             $newurlview[$i]="0";
  363.             
  364.             echo '<tr>';
  365.                 echo '<table class="data_table">';
  366.                 echo '<tr>';            
  367.                     echo '<th width="81%"  style="font-weight: bold; text-align:left;padding-left: 5px;">';
  368.                     echo '<a href="'.api_get_self()."?".api_get_cidreq()."&urlview=".$newurlview."\">";
  369.                     echo "<img src=../img/remove.gif>&nbsp;&nbsp;".htmlentities($myrow["category_title"],ENT_QUOTES,$charset)."</a><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
  370.                     
  371.                     if (is_allowed_to_edit())
  372.                         {    
  373.                             echo '<th>';    
  374.                             showcategoryadmintools($myrow["id"]);
  375.                             echo '</th>';            
  376.                         }
  377.                     echo '</th>';                        
  378.                 echo '</tr>';
  379.                 echo '</table>';        
  380.                 echo showlinksofcategory($myrow["id"]);                        
  381.             echo '</tr>';            
  382.         }
  383.         else
  384.         {        
  385.             echo '<tr>';
  386.                 echo '<table class="data_table">';
  387.                 echo '<tr>';            
  388.                     echo '<th width="81%" style="font-weight: bold; text-align:left;padding-left: 5px;"><a href="'.api_get_self()."?".api_get_cidreq()."&urlview=";
  389.                     echo is_array($view)?implode('',$view):$view;
  390.                     echo "\"><img src=../img/add.gif>&nbsp;&nbsp;".  htmlentities($myrow["category_title"],ENT_QUOTES,$charset);
  391.                     echo'</a><br />&nbsp;&nbsp;&nbsp;';
  392.                     echo $myrow["description"];                        
  393.                         if (is_allowed_to_edit())
  394.                         {        
  395.                             echo '<th style="text-align:center;">';    
  396.                             showcategoryadmintools($myrow["id"]);            
  397.                             echo '</th>';
  398.                         }
  399.                     echo '</th>';            
  400.                 echo '</tr>';
  401.                 
  402.                 
  403.                 echo '</table>';                        
  404.             echo '</tr>';                
  405.         }
  406.         // displaying the link of the category
  407.         $i++;
  408.     }
  409.     echo '</table>';
  410.     ////////////////////////////////////////////////////////////////////////////
  411. }        
  412.         
  413.         
  414.  
  415.  
  416.  
  417. ?>

Documentation generated on Thu, 12 Jun 2008 13:59:29 -0500 by phpDocumentor 1.4.1