Dokeos PHP Cross Reference Learning Management Systems

Source: /main/link/link.php - 854 lines - 31663 bytes - Summary - Text - Print

Description: Main script for the links tool.

   1  <?php
   2  
   3  /* For licensing terms, see /dokeos_license.txt */
   4  
   5  /**
   6    ==============================================================================
   7   * Main script for the links tool.
   8   *
   9   * Features:
  10   * - Organize links into categories;
  11   * - favorites/bookmarks-like interface;
  12   * - move links up/down within a category;
  13   * - move categories up/down;
  14   * - expand/collapse all categories (except the main "non"-category);
  15   * - add link to 'root' category => category-less link is always visible.
  16   *
  17   * @author Patrick Cool, main author, completely rewritten
  18   * @author Rene Haentjens, added CSV file import (October 2004)
  19   * @package dokeos.link
  20   * @todo improve organisation, tables should come from database library
  21    ==============================================================================
  22   */
  23  // name of the language file that needs to be included
  24  $language_file = array('link', 'admin');
  25  
  26  // setting the help
  27  $help_content = 'links';
  28  
  29  // including the global Dokeos file
  30  require_once  '../inc/global.inc.php';
  31  
  32  // Including additional libraries.
  33  require_once  "linkfunctions.php";
  34  require_once  '../newscorm/learnpath.class.php';
  35  require_once  '../newscorm/learnpathItem.class.php';
  36  
  37  /* @todo: is this used? */
  38  define('DOKEOS_LINK', true);
  39  
  40  // setting the section (for the tabs)
  41  $this_section = SECTION_COURSES;
  42  
  43  // Access restrictions
  44  api_protect_course_script();
  45  
  46  // Add additional javascript, css
  47  $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.ui.all.js" type="text/javascript" language="javascript"></script>';
  48  
  49  if (api_is_allowed_to_edit ()) {
  50   $htmlHeadXtra[] = '<link rel="stylesheet" href="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css" type="text/css" media="screen" />';
  51   $htmlHeadXtra[] = '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.js"></script>';
  52  }
  53  
  54  $htmlHeadXtra[] = '<script type="text/javascript">
  55  $(document).ready( function() {
  56      $("#div_target").attr("style","display:none;")//hide
  57  
  58      $("#id_check_target").click(function () {
  59        if($(this).attr("checked")==true) {
  60            $("#div_target").attr("style","display:block;")//show
  61        } else {
  62            $("#div_target").attr("style","display:none;")//hide
  63        }
  64      });
  65  
  66      $(window).load(function () {
  67        if($("#id_check_target").attr("checked")==true) {
  68            $("#div_target").attr("style","display:block;")//show
  69        } else {
  70            $("#div_target").attr("style","display:none;")//hide
  71        }
  72      });
  73  
  74   } );
  75  
  76   </script>';
  77  
  78  
  79  //   div_target
  80  // @todo change the $_REQUEST into $_POST or $_GET
  81  // @todo remove this code
  82  $link_submitted = (isset($_POST['submitLink']) ? true : false);
  83  $category_submitted = (isset($_POST['submitCategory']) ? true : false);
  84  $urlview = (!empty($_GET['urlview']) ? $_GET['urlview'] : '');
  85  $submitImport = (!empty($_POST['submitImport']) ? $_POST['submitImport'] : '');
  86  $down = (!empty($_GET['down']) ? $_GET['down'] : '');
  87  $up = (!empty($_GET['up']) ? $_GET['up'] : '');
  88  $catmove = (!empty($_GET['catmove']) ? $_GET['catmove'] : '');
  89  $editlink = (!empty($_REQUEST['editlink']) ? $_REQUEST['editlink'] : '');
  90  $id = (!empty($_REQUEST['id']) ? $_REQUEST['id'] : '');
  91  $urllink = (!empty($_REQUEST['urllink']) ? $_REQUEST['urllink'] : '');
  92  $title = (!empty($_REQUEST['title']) ? $_REQUEST['title'] : '');
  93  $description = (!empty($_REQUEST['description']) ? $_REQUEST['description'] : '');
  94  $selectcategory = (!empty($_REQUEST['selectcategory']) ? $_REQUEST['selectcategory'] : '');
  95  $submitLink = (isset($_REQUEST['submitLink']) ? true : false);
  96  $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : '');
  97  $category_title = (!empty($_REQUEST['category_title']) ? $_REQUEST['category_title'] : '');
  98  $submitCategory = isset($_POST['submitCategory']) ? true : false;
  99  $nameTools = get_lang('Links');
 100  
 101  //condition for the session
 102  $session_id = api_get_session_id();
 103  $condition_session = api_get_session_condition($session_id, false);
 104  
 105  if (isset($_GET['action']) && $_GET['action'] == 'addlink') {
 106   $nameTools = '';
 107   $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links'));
 108   $interbreadcrumb[] = array('url' => 'link.php?action=addlink', 'name' => get_lang('AddLink'));
 109  }
 110  
 111  if (isset($_GET['action']) && $_GET['action'] == 'addcategory') {
 112   $nameTools = '';
 113   $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links'));
 114   $interbreadcrumb[] = array('url' => 'link.php?action=addcategory', 'name' => get_lang('AddCategory'));
 115  }
 116  
 117  if (isset($_GET['action']) && $_GET['action'] == 'editlink') {
 118   $nameTools = '';
 119   $interbreadcrumb[] = array('url' => 'link.php', 'name' => get_lang('Links'));
 120   $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('EditLink'));
 121  }
 122  
 123  // Variable
 124  $lp_id = Security::remove_XSS($_GET['lp_id']);
 125  // Lp object
 126  if (isset($_SESSION['lpobject'])) {
 127   if ($debug > 0)
 128    error_log('New LP - SESSION[lpobject] is defined', 0);
 129   $oLP = unserialize($_SESSION['lpobject']);
 130   if (is_object($oLP)) {
 131    if ($debug > 0)
 132     error_log('New LP - oLP is object', 0);
 133    if ($myrefresh == 1 OR (empty($oLP->cc)) OR $oLP->cc != api_get_course_id()) {
 134     if ($debug > 0)
 135      error_log('New LP - Course has changed, discard lp object', 0);
 136     if ($myrefresh == 1) {
 137      $myrefresh_id = $oLP->get_id();
 138     }
 139     $oLP = null;
 140     api_session_unregister('oLP');
 141     api_session_unregister('lpobject');
 142    } else {
 143     $_SESSION['oLP'] = $oLP;
 144     $lp_found = true;
 145    }
 146   }
 147  }
 148  
 149  // Add the extra lp_id parameter to some links
 150  $add_params_for_lp = '';
 151  if (isset($_GET['lp_id'])) {
 152    $add_params_for_lp = "&lp_id=".$lp_id;
 153  }
 154  
 155  // Database Table definitions
 156  $tbl_link = Database::get_course_table(TABLE_LINK);
 157  $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
 158  $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
 159  
 160  //statistics
 161  event_access_tool(TOOL_LINK);
 162  
 163  // Display the header
 164  Display :: display_tool_header();
 165  ?>
 166  <script type="text/javascript">
 167   /* <![CDATA[ */
 168   function MM_popupMsg(msg) { //v1.0
 169    confirm(msg);
 170   }
 171   /* ]]> */
 172  </script>
 173  <?php
 174  if (api_is_allowed_to_edit ()) {
 175  ?>
 176  <script type="text/javascript">
 177   $(document).ready(function(){
 178    var category_before = "";
 179    var category_after = "";
 180      
 181    $(".category_0, #categories ul").sortable({
 182     //Allow to put any link in any category
 183     connectWith: '.category_0, #categories ul',
 184     handle   :   $('.move1'),
 185     cursor   :  'move',
 186     cancel: ".nodrag",
 187     //Event thrown when the drag n drop start
 188     start: function(event, ui) {
 189        parentElement = ui.item.parent();
 190      //We keep into the memory the current link category
 191      category_before = getCategoryId(parentElement);
 192      var viewParameter = getUrlViewParameter();    
 193      if(category_before == 0 && viewParameter == '') {                  
 194              window.location.href = "link.php?urlview=1111111111&fold=Y";
 195              return;
 196      }    
 197     },
 198  
 199     //Event thrown when a link is moved in another category
 200     receive: function(event, ui) {
 201  
 202      parentElement = ui.item.parent();
 203      //Check if the parent ul has a category
 204      //We will compare the id of the parent category and the category id after moved
 205      category_after = getCategoryId(parentElement);
 206      itemId = getItemId(ui.item);
 207              
 208      var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
 209      var record = order.split("&");
 210      var recordlen = record.length;
 211      var disparr = new Array();
 212      for(var i=0;i<(recordlen-1);i++){
 213       var recordval = record[i].split("=");
 214       disparr[i] = recordval[1];
 215      }
 216              
 217      //Links' category has changed
 218      if (!category_after) {
 219          category_after = 0;
 220      } 
 221      if(category_before != category_after){
 222       $.ajax({
 223            //We update the link category
 224            url: "link.php?action=changeLinkCategory&itemId="+itemId+"&categoryId="+category_after,
 225            complete: function(){
 226             //we update the order of all links of the new category
 227             var viewParameter = getUrlViewParameter();
 228             var viewString = "";
 229             if(viewParameter.length > 0){
 230              viewString = "&urlview="+viewParameter;
 231              window.location.href = "link.php?action=updateRecordsListings&disporder="+disparr+viewString;    
 232             }
 233            }
 234       });
 235       return false;
 236      }
 237              
 238     },
 239  
 240     //Event thrown at the end of a drag n drop. Useful only when a link is moved in the same category because if a link is moved in another category,
 241     //the receive event is thrown first and the redirection will stop all events
 242     stop: function(event, ui) {
 243              
 244      var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
 245      var record = order.split("&");
 246      var recordlen = record.length;
 247      var disparr = new Array();
 248      for(var i=0;i<(recordlen-1);i++){
 249       var recordval = record[i].split("=");
 250       disparr[i] = recordval[1];
 251      }
 252  
 253      var viewParameter = getUrlViewParameter();
 254      var viewString = "";
 255      if(viewParameter.length > 0){
 256       viewString = "&urlview="+viewParameter;
 257      }
 258      //Update the links order in the category    
 259      window.location.href = "link.php?action=updateRecordsListings&disporder="+disparr+viewString;
 260      return;
 261  
 262     }
 263          
 264    });
 265  
 266  
 267    //Allow th change the categories order
 268    $("#categories").sortable(
 269      {
 270      connectWith: '#categories',
 271      cursor   :  'move',
 272      handle   :  $('.move'),
 273      cancel: ".nodrag",
 274      update: function(event, ui) {
 275      var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
 276      var record = order.split("&");
 277      var recordlen = record.length;
 278      var disparr = new Array();
 279      for(var i=0;i<(recordlen-1);i++)
 280      {
 281       var recordval = record[i].split("=");
 282       disparr[i] = recordval[1];
 283      }
 284  
 285      var viewParameter = getUrlViewParameter();
 286      var viewString = "";
 287      if(viewParameter.length > 0){
 288       viewString = "&urlview="+viewParameter;
 289      }
 290      //update the order of all categories    
 291      window.location.href = "link.php?action=updateRecordsListings&type=categories&disporder="+disparr+viewString;
 292      return;
 293     }
 294    });
 295  
 296   });
 297  
 298   function getCategoryId(parentElement){
 299    if(parentElement.is("[class*='category']")){
 300     var classList =$(parentElement).attr('class').split(/\s+/);
 301     var category_id;
 302     for(var i= 0; i < classList.length; i++){
 303      var index = classList[i].indexOf('category_');
 304      if (index != -1) {
 305       return classList[i].substr(9,classList[i].length);
 306      }
 307     }
 308     return;
 309    }
 310   }
 311   function getItemId(item){
 312    var arrayTemp = $(item).attr("id").split('_');
 313  
 314    return arrayTemp[1];
 315   }
 316   function getUrlViewParameter(){
 317    var vars = [], hash;
 318    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
 319    for(var i = 0; i < hashes.length; i++)
 320    {
 321     hash = hashes[i].split('=');
 322     if(hash[0] == "urlview"){
 323      return hash[1];
 324     }
 325    }
 326    return "";
 327   }
 328  
 329  </script>
 330  <?php
 331  }
 332  ?>
 333  <?php
 334  
 335  $link_id = Security::remove_XSS($_GET['id']);
 336  
 337  $action = $_GET['action'];
 338  $updateRecordsArray = $_GET['disporder'];
 339  $disporder = $_GET['disporder'];
 340  
 341  if ($action == "changeLinkCategory") {
 342   $itemId = Security::remove_XSS($_GET["itemId"]);
 343   $categoryId = Security::remove_XSS($_GET["categoryId"]);
 344   $sql = "UPDATE $tbl_link SET category_id=" . Database::escape_string($categoryId) . " WHERE id = " . Database::escape_string($itemId);
 345   $res = Database::query($sql, __FILE__, __LINE__);
 346   exit;
 347  }
 348  
 349  if ($action == "updateRecordsListings") {
 350   $disparr = explode(",", $disporder);
 351   if (isset($_GET['type']) && $_GET['type'] == 'categories') {
 352    $table_name = $tbl_categories;
 353   } else {
 354    $table_name = $tbl_link;
 355   }
 356   $len = sizeof($disparr);
 357   $listingCounter = $len;
 358   for ($i = 0; $i < sizeof($disparr); $i++) {
 359    $sql = "UPDATE $table_name SET display_order=" . Database::escape_string($listingCounter) . " WHERE id = " . Database::escape_string($disparr[$i]);
 360    $res = Database::query($sql, __FILE__, __LINE__);
 361    $listingCounter = $listingCounter - 1;
 362   }
 363  }
 364  
 365  
 366  /*
 367    -----------------------------------------------------------
 368    Action Handling
 369    -----------------------------------------------------------
 370   */
 371  $nameTools = get_lang("Links");
 372  
 373  if (isset($_GET['action'])) {
 374   switch ($_GET['action']) {
 375    case "addlink":
 376     if ($link_submitted) {
 377      if (!addlinkcategory("link")) { // here we add a link
 378       unset($submitLink);
 379      }
 380     }
 381     break;
 382    case "addcategory":
 383     if ($category_submitted) {
 384      if (!addlinkcategory("category")) { // here we add a category
 385       unset($submitCategory);
 386      }
 387     }
 388     break;
 389    case "importcsv":
 390     if ($_POST["submitImport"]) {
 391      import_csvfile();
 392     }
 393     break;
 394    case "deletelink":
 395     deletelinkcategory("link"); // here we delete a link
 396     break;
 397  
 398    case "deletecategory":
 399     deletelinkcategory("category"); // here we delete a category
 400     break;
 401    case "editlink":
 402     editlinkcategory("link"); // here we edit a link
 403     break;
 404    case "editcategory":
 405     editlinkcategory("category"); // here we edit a category
 406     break;
 407    case "visible":
 408     change_visibility($_GET['id'], $_GET['scope']); // here we edit a category
 409     break;
 410    case "invisible":
 411     change_visibility($_GET['id'], $_GET['scope']); // here we edit a category
 412     break;
 413   }
 414  }
 415  
 416  if (isset($_GET['add_to_course']) && isset($_POST['link_add'])) {
 417  $link_id = Security::remove_XSS($_GET['add_to_course']);
 418  $link_title = $_POST['link_title'];
 419  list($lp_name, $lp_id) = explode("@", $_POST['course']);
 420  $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
 421  $query = "SELECT max(id) AS maxid FROM " . $tbl_lp_item;
 422  $result = api_sql_query($query, __FILE__, __LINE__);
 423  while ($obj = Database::fetch_object($result)) {
 424    $maxid = $obj->maxid;
 425  }
 426  $query = "SELECT max(display_order) AS disporder FROM " . $tbl_lp_item . " WHERE lp_id=" . Database::escape_string($lp_id);
 427  $result = api_sql_query($query, __FILE__, __LINE__);
 428  while ($obj = Database::fetch_object($result)) {
 429  $display_order = $obj->disporder;
 430  }
 431  
 432   $sql = "INSERT INTO " . $tbl_lp_item . " (lp_id,
 433                              item_type,
 434                              ref,
 435                              title,
 436                              description,
 437                              path,                                                                
 438                              previous_item_id,
 439                              next_item_id,                        
 440                              display_order) VALUES(" . Database::escape_string($lp_id) . ",
 441                              'link',
 442                              '" . ($maxid + 1) . "',
 443                              '" . Database::escape_string($link_title) . "',
 444                              '',
 445                              '" . Database::escape_string($link_id) . "',
 446                              " . $maxid . ",
 447                              " . ($maxid + 2) . ",
 448                              " . ($display_order + 1) . ")";
 449   $result = api_sql_query($sql, __FILE__, __LINE__); 
 450  }
 451  
 452  // display the introduction section
 453  Display::display_introduction_section(TOOL_LINK);
 454  
 455  
 456  if (api_is_allowed_to_edit(null, true) and isset($_GET['action'])) {
 457   // Search
 458   if (api_get_setting('search_enabled') == 'true') {
 459    if (!extension_loaded('xapian')) {
 460     Display::display_error_message(get_lang('SearchXapianModuleNotInstaled'));
 461    }
 462   }
 463   // Displaying the correct title and the form for adding a category or link. This is only shown when nothing
 464   // has been submitted yet, hence !isset($submitLink)
 465   if (($_GET['action'] == "addlink" or $_GET['action'] == "editlink") and empty($_POST['submitLink'])) {
 466    if ($category == "") {
 467     $category = 0;
 468    }
 469  
 470    // actions (when adding a link)
 471    echo '<div class="actions">';
 472    echo '<a href="link.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;urlview=' . Security::remove_XSS($_GET['urlview']) . '">' . Display::return_icon('pixel.gif', get_lang('BackToLinksOverview'), array('class' => 'toolactionplaceholdericon toolactionback')) . get_lang('BackToLinksOverview') . '</a>';
 473    if (isset($_GET['lp_id']) && $_GET['lp_id'] > 0) {
 474    echo '<a href="../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=add_item&type=step&lp_id='.$_GET['lp_id'].'">' . Display::return_icon('pixel.gif', get_lang('Content'),array('class'=>'toolactionplaceholdericon toolactionauthorcontent')).get_lang("Content") . '</a>';
 475    echo '<a href="../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=admin_view&lp_id='.$_GET['lp_id'].'">' . Display::return_icon('pixel.gif', get_lang('Scenario'),array('class'=>'toolactionplaceholdericon toolactionauthorscenario')).get_lang("Scenario") . '</a>';
 476    }
 477    echo '</div>';
 478  
 479    // start the content div
 480    echo '<div id="content">';
 481  
 482    echo "<form name='add_link' method=\"post\" action=\"" . api_get_self() . "?action=" . Security::remove_XSS($_GET['action']) . "&amp;urlview=" . Security::remove_XSS($urlview) .$add_params_for_lp. "\">";
 483    if ($_GET['action'] == "editlink") {
 484     echo "<input type=\"hidden\" name=\"id\" value=\"" . Security::remove_XSS($_GET['id']) . "\" />";
 485     $clean_link_id = trim(Security::remove_XSS($_GET['id']));
 486    }
 487  
 488    echo '    <div class="row">
 489                      <div class="label">
 490                          <span class="form_required">*</span> ' . get_lang('Url') . '
 491                      </div>
 492                      <div class="formw">
 493                          <input type="text" class="focus" name="urllink" size="50" value="' . (empty($urllink) ? 'http://' : api_htmlentities($urllink, ENT_COMPAT, $charset)) . '" />
 494                      </div>
 495                  </div>';
 496  
 497    echo '    <div class="row">
 498                      <div class="label">
 499                          ' . get_lang('Text') . '
 500                      </div>
 501                      <div class="formw">
 502                          <input type="text" name="title" size="50" value="' . api_htmlentities($title, ENT_QUOTES, $charset) . '" />
 503                      </div>
 504                  </div>';
 505    echo '    <div class="row">
 506                      <div class="label">
 507                          ' . get_lang('Objective') . '
 508                      </div>
 509                      <div class="formw">
 510                          <textarea rows="3" cols="50" name="description">' . api_htmlentities($description, ENT_QUOTES, $charset) . '</textarea>
 511                      </div>
 512                  </div>';
 513  
 514  
 515  
 516  
 517    $sqlcategories = "SELECT * FROM " . $tbl_categories . " $condition_session ORDER BY display_order DESC";
 518    $resultcategories = Database::query($sqlcategories, __FILE__, __LINE__);
 519  
 520    if (Database::num_rows($resultcategories)) {
 521     echo '    <div class="row">
 522                          <div class="label">
 523                              ' . get_lang('Category') . '
 524                          </div>
 525                          <div class="formw">';
 526     echo '            <select name="selectcategory">';
 527     echo '            <option value="0">--</option>';
 528     while ($myrow = Database::fetch_array($resultcategories)) {
 529      echo "        <option value=\"" . $myrow["id"] . "\"";
 530      if ($myrow["id"] == $category) {
 531       echo " selected";
 532      }
 533      echo ">" . $myrow["category_title"] . "</option>";
 534     }
 535     echo '            </select>';
 536     echo '        </div>
 537                      </div>';
 538    }
 539  
 540    echo '    <div class="row">
 541                      <div class="label">
 542                          ' . get_lang('OnHomepage') . '?
 543                      </div>
 544                      <div class="formw">
 545                          <input id="id_check_target" class="checkbox" type="checkbox" name="onhomepage" id="onhomepage" value="1"' . $onhomepage . '><label for="onhomepage"> ' . get_lang('Yes') . '</label>
 546                      </div>
 547                  </div>';
 548    echo '    <div class="row" id="div_target">
 549                      <div class="label">
 550                          ' . get_lang('AddTargetOfLinkOnHomepage') . '
 551                      </div>
 552                      <div class="formw" >
 553                          <select  name="target_link" id="target_link">
 554                          <option value="_self">_self</option>
 555                          <option value="_blank">_blank</option>
 556                          <option value="_parent">_parent</option>
 557                          <option value="_top">_top</option>
 558                          </select>
 559                      </div>
 560                  </div>';
 561  
 562  
 563  
 564    if (api_get_setting('search_enabled') == 'true') {
 565     require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
 566     $specific_fields = get_specific_field_list();
 567  
 568     foreach ($specific_fields as $specific_field) {
 569      $default_values = '';
 570      if ($_GET['action'] == "editlink") {
 571       $filter = array('course_code' => "'" . api_get_course_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => Security::remove_XSS($_GET['id']), 'tool_id' => '\'' . TOOL_LINK . '\'');
 572       $values = get_specific_field_values_list($filter, array('value'));
 573       if (!empty($values)) {
 574        $arr_str_values = array();
 575        foreach ($values as $value) {
 576         $arr_str_values[] = $value['value'];
 577        }
 578        $default_values = implode(', ', $arr_str_values);
 579       }
 580      }
 581  
 582      $sf_textbox = '
 583                          <div class="row">
 584                              <div class="label">%s</div>
 585                              <div class="formw">
 586                                  <input name="%s" type="text" value="%s"/>
 587                              </div>
 588                          </div>';
 589  
 590      echo sprintf($sf_textbox, $specific_field['name'], $specific_field['code'], $default_values);
 591     }
 592    }
 593  
 594    echo '    <div class="row">
 595                      <div class="label">
 596                      </div>
 597                      <div class="formw">
 598                          <button class="save" type="Submit" name="submitLink" value="OK">' . get_lang('SaveLink') . '</button>
 599                      </div>
 600                  </div>';
 601  
 602    echo '</form>';
 603  
 604    // close the content div
 605    echo '</div>';
 606   } elseif (($_GET['action'] == "addcategory" or $_GET['action'] == "editcategory") and !$submitCategory) {
 607    if ($_GET['action'] == "addcategory") {
 608     //    echo '<div class="form_header">'.get_lang('CategoryAdd').'</div>';
 609     $my_cat_title = get_lang('CategoryAdd');
 610    } else {
 611     //    echo '<div class="form_header">'.get_lang('CategoryMod').'</div>';
 612     $my_cat_title = get_lang('CategoryMod');
 613    }
 614  
 615    // actions (when adding a category)
 616    echo '<div class="actions">';
 617    echo '<a href="link.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;urlview=' . Security::remove_XSS($_GET['urlview']) . '">' . Display::return_icon('pixel.gif', get_lang('BackToLinksOverview'), array('class' => 'toolactionplaceholdericon toolactionback')) . get_lang('BackToLinksOverview') . '</a>';
 618    echo '</div>';
 619  
 620    // start the content div
 621    echo '<div id="content">';
 622  
 623    echo "<form name='add_category' method=\"post\" action=\"" . api_get_self() . "?action=" . Security::remove_XSS($_GET['action']) . "&amp;urlview=" . Security::remove_XSS($urlview) . "\">";
 624    if ($_GET['action'] == "editcategory") {
 625     echo "<input type=\"hidden\" name=\"id\" value=\"" . $id . "\" />";
 626    }
 627  
 628    echo '    <div class="row">
 629                      <div class="label">
 630                          <span class="form_required">*</span> ' . get_lang('FolderName') . '
 631                      </div>
 632                      <div class="formw">
 633                          <input type="text" class="focus" name="category_title" size="50" value="' . $category_title . '" />
 634                      </div>
 635                  </div>';
 636  
 637    echo '    <div class="row">
 638                      <div class="label">
 639                      </div>
 640                      <div class="formw">
 641                          <button class="save" type="submit" name="submitCategory">' . get_lang('Validate') . ' </button>
 642                      </div>
 643                  </div>';
 644  
 645    echo "</form>";
 646  
 647    // close the content div
 648    echo '</div>';
 649   }
 650   /* elseif(($_GET['action']=="importcsv") and !$submitImport)  // RH start
 651     {
 652     echo "<h4>", get_lang('CsvImport'), "</h4>\n\n",
 653     "<form method=\"post\" action=\"".api_get_self()."?action=".$_GET['action']."&amp;urlview=".$urlview."\" enctype=\"multipart/form-data\">",
 654     // uncomment if you want to set a limit: '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
 655     '<input type="file" name="import_file" size="30">', "\n",
 656     "<input type=\"Submit\" name=\"submitImport\" value=\"".get_lang('Ok')."\">",
 657     "</form>";
 658     echo get_lang('CsvExplain');
 659     } */
 660  }
 661  
 662  
 663  if (!empty($down)) {
 664   movecatlink($down);
 665  }
 666  if (!empty($up)) {
 667   movecatlink($up);
 668  }
 669  
 670  if (empty($_GET['action']) || ($_GET['action'] != 'editlink' && $_GET['action'] != 'addcategory' && $_GET['action'] != 'addlink' && $_GET['action'] != 'editcategory') || $link_submitted || $category_submitted) {
 671   /*
 672     -----------------------------------------------------------
 673     Action Links
 674     -----------------------------------------------------------
 675    */
 676   echo '<div class="actions">';
 677   if (api_is_allowed_to_edit(null, true)) {
 678    $urlview = Security::remove_XSS($urlview);
 679    echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=addlink&amp;category=" . (!empty($category) ? $category : '') . "&amp;urlview=$urlview\">" . Display::return_icon('pixel.gif', get_lang('LinkAdd'), array('class' => 'toolactionplaceholdericon toolactionslink')) . '&nbsp;&nbsp;' . get_lang("LinkAdd") . "</a>\n";
 680    echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=addcategory&amp;urlview=" . $urlview . "\">" . Display::return_icon('pixel.gif', get_lang("Folder"), array('class' => 'toolactionplaceholdericon toolactioncreatefolder')) . '&nbsp;&nbsp;' . get_lang("Folder") . "</a>";
 681    /* "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=importcsv&amp;urlview=".$urlview."\">".get_lang('CsvImport')."</a>\n", // RH */
 682    if (isset($_GET['lp_id']) && $_GET['lp_id'] > 0) {
 683    echo '<a href="../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=add_item&type=step&lp_id='.Security::remove_XSS($_GET['lp_id']).'">' . Display::return_icon('pixel.gif', get_lang('Content'),array('class'=>'toolactionplaceholdericon toolactionauthorcontent')).get_lang("Content") . '</a>';
 684    echo '<a href="../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=admin_view&lp_id='.Security::remove_XSS($_GET['lp_id']).'">' . Display::return_icon('pixel.gif', get_lang('Scenario'),array('class'=>'toolactionplaceholdericon toolactionauthorscenario')).get_lang("Scenario") . '</a>';
 685    }
 686   }
 687   //making the show none / show all links. Show none means urlview=0000 (number of zeros depending on the
 688   //number of categories). Show all means urlview=1111 (number of 1 depending on teh number of categories).
 689   $sqlcategories = "SELECT * FROM " . $tbl_categories . " $condition_session ORDER BY display_order DESC";
 690   $resultcategories = Database::query($sqlcategories);
 691   $aantalcategories = Database::num_rows($resultcategories);
 692   if ($aantalcategories > 0) {
 693       if(($_REQUEST['unfold'] == 'Y')||(empty($_REQUEST['fold'])))
 694       {
 695    echo " <a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&fold=Y&urlview=";
 696    for ($j = 1; $j <= $aantalcategories; $j++) {
 697     echo "1";
 698    }
 699    echo "\">" . Display::return_icon('unfold32.png', $shownone) . '&nbsp;&nbsp;' . get_lang('Unfold') . "</a>";
 700       }
 701      else
 702       {
 703    echo " <a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&unfold=Y&urlview=";
 704    for ($j = 1; $j <= $aantalcategories; $j++) {
 705     echo "0";
 706    }
 707    echo "\">" . Display::return_icon('fold32.png', $showall) . '&nbsp;&nbsp;' . get_lang('Fold') . "</a>";
 708       }
 709   }
 710   echo '</div>';
 711  
 712   global $linkCounter;
 713   $linkCounter = 1;
 714  
 715   // start the content div
 716   echo '<div id="content">';
 717  
 718   //Starting the table which contains the categories
 719   $sqlcategories = "SELECT * FROM " . $tbl_categories . " $condition_session ORDER BY display_order DESC";
 720   $resultcategories = Database::query($sqlcategories);
 721   
 722   // displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
 723   $sqlLinks = "SELECT * FROM " . $tbl_link . " WHERE category_id=0 or category_id IS NULL";
 724   $result = Database::query($sqlLinks);
 725   $numberofzerocategory = Database::num_rows($result);
 726   if ($numberofzerocategory !== 0) {
 727       echo '<table class="data_table">';
 728    if (api_is_allowed_to_edit ()) {
 729     echo "<tr><th width='6%' align='center' style='padding-right: 0px;'>" . get_lang('Move') . "</th>";
 730     echo "<th width='54%' align='left' style='padding-right: 0px;padding-left: 5px;'>" . get_lang('Link') . "</th>";
 731     echo "<th width='10%' style='padding-right: 0px;'>" . get_lang('Modify') . "</th>";
 732     echo "<th width='10%' style='padding-right: 0px;'>" . get_lang('Delete') . "</th>";
 733     echo "<th width='10%' style='padding-right: 0px;'>" . get_lang('Visible') . "</th>";
 734     echo "<th width='10%' style='padding-right: 0px;'>" . get_lang('Module') . "</th>";
 735    } else {
 736     echo "<tr><th width='100%' align='left'>" . get_lang('Links') . "</th>";
 737    }
 738    echo "</tr>";
 739    echo '</table>';
 740    showlinksofcategory(0);
 741   }
 742   else
 743   {
 744       echo '<tr><th>&nbsp;</th></tr></table>';
 745   }
 746  
 747   $i = 0;
 748   $catcounter = 1;
 749   $view = "0";
 750  
 751   if (Database::num_rows($resultcategories)) {
 752   echo '<div id="contentWrap"><div id="contentLeft"><ul class="dragdrop nobullets" id="categories">';
 753   //Create empty list to allow move link outside category
 754   $draggable_class = api_is_allowed_to_edit() ? 'draggable' : '';
 755   echo '<ul class="dragdrop ui-sortable"><li id="recordsArray_0" class="'.$draggable_class.'">&nbsp;</li></ul>';
 756  
 757   while ($myrow = Database::fetch_array($resultcategories)) {
 758    //validacion when belongs to a session
 759    $session_img = api_get_session_image($myrow['session_id'], $_user['status']);
 760  
 761    //if (!isset($urlview))
 762    if ($urlview == '') {
 763     // No $view set in the url, thus for each category link it should be all zeros except it's own
 764     makedefaultviewcode($i);
 765    } else {
 766     $view = $urlview;
 767     $view[$i] = "1";
 768    }
 769    // if the $urlview has a 1 for this categorie, this means it is expanded and should be desplayed as a
 770    // - instead of a +, the category is no longer clickable and all the links of this category are displayed
 771    $myrow["description"] = text_filter($myrow["description"]);
 772  
 773    $width_link_column = "94";
 774    $parent_draggable = "parent_no_draggable";
 775    if (api_is_allowed_to_edit(null, true)) {
 776     $parent_draggable = "parent_draggable";
 777     $width_link_column = "60";
 778    }
 779  
 780    if ($urlview[$i] == "1") {
 781       $newurlview = $urlview;
 782       $newurlview[$i] = "0";
 783       
 784       //echo '<tr><td>';
 785       echo '<li id="recordsArray_' . $myrow["id"] . '" class="category">';
 786       echo '<div class="'.$parent_draggable.' rounded move">';
 787       //echo '<table class="data_table">';
 788       echo '<table width="100%" style="margin-left: -10px;margin-top:-2px;" >';
 789       echo '<tr>';
 790       //echo '<th width="6%" style="text-align:left; padding: 0px 0px 0px 5px; background: #e2e1df"><img src="../img/drag-and-drop.png"></th>';
 791       echo '<th width="' . $width_link_column . '%"  style="font-weight: bold; text-align:left;padding-left: 5px; vertical-align: top; height: 40px;">';
 792       echo '<a href="' . api_get_self() . "?" . api_get_cidreq() . "&urlview=" . Security::remove_XSS($newurlview) . "\">";
 793       echo '<img src="../img/action-slide-up.png" align="top" /></a>';
 794       echo '<a style="display: inline-block; margin:8px 0px 0px 5px;" href="' . api_get_self() . "?" . api_get_cidreq() . "&urlview=" . Security::remove_XSS($newurlview) . "\">" . api_htmlentities($myrow["category_title"], ENT_QUOTES, $charset) . "</a>";
 795       echo '</th>';
 796       if (api_is_allowed_to_edit(null, true)) {
 797        showcategoryadmintools($myrow["id"]);
 798        echo '<th style="">&nbsp;</th>';
 799       }
 800       echo '</tr>';
 801       echo '</table>';
 802       echo '</div>';
 803       echo showlinksofcategory($myrow["id"]);
 804       //echo '</td></tr>';
 805  //   echo '</table></div></li>';
 806       echo '</li>';
 807       //echo '</td></tr>';
 808    } else {
 809        // Collapsed view
 810       //echo '<tr><td>';
 811       echo '<li id="recordsArray_' . $myrow["id"] . '" class="category">';
 812       echo '<div class="'.$parent_draggable.' rounded move">';
 813       echo '<table width="100%" style="margin-left: -10px;margin-top:-2px;">';
 814       echo '<tr>';
 815       //echo '<th width="6%" style="background: #e2e1df;text-align:left; padding: 0px 0px 0px 5px;"><img src="../img/drag-and-drop.png"></th>';
 816       echo '<th width="' . $width_link_column . '%" style="font-weight: bold; text-align:left;padding-left: 5px;vertical-align: top; height: 40px;">
 817                        <a href="' . api_get_self() . "?" . api_get_cidreq() . "&urlview=";
 818       echo is_array($view) ? implode('', $view) : $view;
 819       echo "\"><img src='../img/action-slide-down.png' align='top' /></a>";
 820       echo '<a style="display: inline-block; margin:8px 0px 0px 5px;" href="' . api_get_self() . "?" . api_get_cidreq() . "&urlview=";
 821       echo is_array($view) ? implode('', $view) : $view;
 822       echo "\">" . api_htmlentities($myrow["category_title"], ENT_QUOTES, $charset) . $session_img . '</a>';
 823       echo '</th>';
 824       if (api_is_allowed_to_edit(null, true)) {
 825        showcategoryadmintools($myrow["id"]);
 826        echo '<th style="">&nbsp;</th>';
 827       }
 828       echo '</tr>';
 829       echo '</table></div></li>';
 830       //echo '</td></tr>';
 831    }
 832    // displaying the link of the category
 833    $i++;
 834   }
 835   echo '</ul></div></div>';
 836   }//End If num rows >0
 837  
 838  
 839   echo '<div class="clear"> </div>';
 840  
 841  
 842   // close the content div
 843   echo '<div class="clear"> </div>';
 844   echo '</div>';
 845  }
 846  
 847  // bottom actions bar
 848  echo '<div class="actions">';
 849  echo '&nbsp;';
 850  echo '</div>';
 851  
 852  // display the footer
 853  Display::display_footer();
 854  ?>

title

Description

title

Description

title

Description

title

title

Body