Dokeos PHP Cross Reference Learning Management Systems

Source: /main/newscorm/lp_ajax_change_position.php - 63 lines - 1835 bytes - Summary - Text - Print

Description: Learning Path This script allow to modify the Learning path position

   1  <?php
   2  /* For licensing terms, see /dokeos_license.txt */
   3  
   4  /**
   5  *     Learning Path
   6  *    This script allow to modify the Learning path position
   7  *    @package dokeos.learnpath
   8  *    @author    Isaac flores <florespaz@bidsoft.net>
   9  */
  10  
  11  require_once ('../inc/global.inc.php');
  12  
  13  if (isset($_GET['action']) && $_GET['action'] == 'change_lp_position') {
  14   $lp_id = Security::remove_XSS($_GET['lp_id']);
  15   $new_order = Security::remove_XSS($_GET['new_order']);
  16   change_lp_position($lp_id,$new_order);
  17  }
  18  
  19  /**
  20   * Change the learning path position
  21   * @param integer $lp_id
  22   * @param integer $new_position
  23   * @return string
  24   */
  25  function change_lp_position ($lp_id, $new_position) {
  26    $new_position = intval($new_position);
  27    $lp_id = intval($lp_id);
  28  
  29    $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  30    $sql = 'SELECT display_order FROM ' . $lp_table . ' WHERE id=' . $lp_id;
  31    $rs = Database::query($sql, __FILE__, __LINE__);
  32  
  33    if (($old_position = Database::result($rs, 0)) !== false) {
  34       $old_position = intval($old_position);
  35  
  36     if ($new_position > $old_position) {
  37      $sql = 'UPDATE ' . $lp_table . '
  38         SET display_order = display_order - 1
  39         WHERE display_order > ' . $old_position . '
  40         AND display_order <= ' . $new_position;
  41      Database::query($sql, __FILE__, __LINE__);
  42     } else {
  43      $sql = 'UPDATE ' . $lp_table . '
  44         SET display_order = display_order + 1
  45         WHERE display_order < ' . $old_position . '
  46         AND display_order >= ' . $new_position;
  47      Database::query($sql, __FILE__, __LINE__);
  48     }
  49     $sql = 'UPDATE ' . $lp_table . '
  50        SET display_order = ' . $new_position . '
  51        WHERE id=' . $lp_id;
  52  
  53     $rs = Database::query($sql, __FILE__, __LINE__);
  54  
  55     // Ajax response
  56     if ($new_position !== false && ($new_position != $old_position)) {
  57       echo 'true';
  58     } else {
  59       echo 'false';
  60     }
  61  
  62    }
  63  }

title

Description

title

Description

title

Description

title

title

Body