Dokeos PHP Cross Reference Learning Management Systems

Source: /main/exercice/exercise_category.php - 266 lines - 9335 bytes - Summary - Text - Print

Description: Exercise Administration

   1  <?php
   2  
   3  /* For licensing terms, see /dokeos_license.txt */
   4  
   5  /**
   6  ==============================================================================
   7  *     Exercise Administration
   8  *    @package dokeos.exercise
   9  ==============================================================================
  10  */
  11  // Language files that should be included
  12  $language_file[]='exercice';
  13  // setting the help
  14  $help_content = 'exerciselist';
  15  
  16  // including the global library
  17  require_once  '../inc/global.inc.php';
  18  
  19  // including additional libraries
  20  include ('exercise.class.php');
  21  include ('exercise.lib.php');
  22  include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  23  require_once  '../newscorm/learnpath.class.php';
  24  require_once  '../newscorm/learnpathItem.class.php';
  25  // setting the tabs
  26  $this_section=SECTION_COURSES;
  27  
  28  if(!api_is_allowed_to_edit()) {
  29      api_not_allowed(true);
  30  }
  31  
  32  // Add additional javascript, css
  33  $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
  34  $htmlHeadXtra[] = '<script>
  35    $(document).ready(function (){
  36      $("div.label").attr("style","width: 100%;text-align:left");
  37      $("div.row").attr("style","width: 100%;");
  38      $("div.formw").attr("style","width: 100%;");
  39    });
  40  </script>';
  41  
  42  // Add the lp_id parameter to all links if the lp_id is defined in the uri
  43  if (isset($_GET['lp_id']) && $_GET['lp_id'] > 0) {
  44    $lp_id = Security::remove_XSS($_GET['lp_id']);
  45   $htmlHeadXtra[] = '<script>
  46      $(document).ready(function (){
  47        $("a[href]").attr("href", function(index, href) {
  48            var param = "lp_id=' . $lp_id . '";
  49             var is_javascript_link = false;
  50             var info = href.split("javascript");
  51  
  52             if (info.length >= 2) {
  53               is_javascript_link = true;
  54             }
  55             if ($(this).attr("class") == "course_main_home_button" || $(this).attr("class") == "course_menu_button"  || $(this).attr("class") == "next_button"  || $(this).attr("class") == "prev_button" || is_javascript_link) {
  56               return href;
  57             } else {
  58               if (href.charAt(href.length - 1) === "?")
  59                   return href + param;
  60               else if (href.indexOf("?") > 0)
  61                   return href + "&" + param;
  62               else
  63                   return href + "?" + param;
  64             }
  65        });
  66      });
  67    </script>';
  68  }
  69  
  70  $htmlHeadXtra[] ='<script type="text/javascript">
  71  $(document).ready(function(){ 
  72  
  73      $(function() {
  74          $("#contentLeft ul").sortable({ opacity: 0.6, cursor: "move",cancel: ".nodrag", update: function() {            
  75              var order = $(this).sortable("serialize") + "&action=updateQuizCategory";
  76              var record = order.split("&");
  77              var recordlen = record.length;
  78              var disparr = new Array();
  79              for(var i=0;i<(recordlen-1);i++)
  80              {
  81               var recordval = record[i].split("=");
  82               disparr[i] = recordval[1];             
  83              }            
  84              // call ajax to save new position
  85              window.location.href = "'.api_get_self().'?'.api_get_cidReq().'&action=updateQuizCategory&disporder="+disparr;    
  86          }
  87          });
  88      });
  89  
  90  });
  91  </script> ';
  92  
  93  // Variable
  94  $learnpath_id = Security::remove_XSS($_GET['lp_id']);
  95  // Lp object
  96  if (isset($_SESSION['lpobject'])) {
  97   if ($debug > 0)
  98    error_log('New LP - SESSION[lpobject] is defined', 0);
  99   $oLP = unserialize($_SESSION['lpobject']);
 100   if (is_object($oLP)) {
 101    if ($debug > 0)
 102     error_log('New LP - oLP is object', 0);
 103    if ($myrefresh == 1 OR (empty($oLP->cc)) OR $oLP->cc != api_get_course_id()) {
 104     if ($debug > 0)
 105      error_log('New LP - Course has changed, discard lp object', 0);
 106     if ($myrefresh == 1) {
 107      $myrefresh_id = $oLP->get_id();
 108     }
 109     $oLP = null;
 110     api_session_unregister('oLP');
 111     api_session_unregister('lpobject');
 112    } else {
 113     $_SESSION['oLP'] = $oLP;
 114     $lp_found = true;
 115    }
 116   }
 117  }
 118  
 119  // Add the extra lp_id parameter to some links
 120  $add_params_for_lp = '';
 121  if (isset($_GET['lp_id'])) {
 122    $add_params_for_lp = "&lp_id=".$learnpath_id;
 123  }
 124  
 125  $TBL_QUIZ_CATEGORY = Database::get_course_table(TABLE_QUIZ_CATEGORY);
 126  
 127  if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'updateQuizCategory') {
 128  $disparr = explode(",", $_REQUEST['disporder']);
 129  $len = sizeof($disparr);
 130  $listingCounter = 1;
 131      for ($i = 0; $i < sizeof($disparr); $i++) {
 132      $sql = "UPDATE $TBL_QUIZ_CATEGORY SET display_order=" . Database::escape_string($listingCounter) . " WHERE id = " . Database::escape_string($disparr[$i]);
 133      $res = Database::query($sql, __FILE__, __LINE__);
 134      $listingCounter = $listingCounter + 1;
 135      } 
 136      header('Location:exercise_category.php?'.api_get_cidReq());
 137      exit;
 138  }
 139  
 140  /*********************
 141   * INIT EXERCISE
 142   *********************/
 143  
 144  // Display header
 145  Display :: display_tool_header();
 146  
 147  echo '<div class="actions">';
 148  echo '<a href="exercice.php?'.api_get_cidreq().'">'.Display :: return_icon('go_previous_32.png', get_lang('List')) . get_lang('List').'</a>';
 149  echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add_category">'.Display :: return_icon('category_32.png', get_lang('Newcategory')) . get_lang('Newcategory').'</a>';
 150  echo '</div>';
 151  
 152  if(isset($_REQUEST['cat_id']))
 153  {
 154      $sql = "SELECT * FROM $TBL_QUIZ_CATEGORY WHERE id = ".$_REQUEST['cat_id'];
 155      $result = api_sql_query($sql, __FILE__, __LINE__);
 156      while($row = Database::fetch_array($result))
 157      {
 158          $category_title = $row['category_title'];
 159      }
 160  }
 161  
 162  echo '<div id="content">';
 163  
 164  $form = new FormValidator('exercise_category', 'post', api_get_self().'?'.api_get_cidreq().'&cat_id='.$_REQUEST['cat_id'], null, array('style' => 'width: 100%; border: 0px'));
 165  if ($form -> validate()) {
 166          $form->getSubmitValue('category');
 167          $category_added = category_add($form);
 168      }
 169  if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete_category')
 170  {
 171      $sql = "DELETE FROM $TBL_QUIZ_CATEGORY WHERE id = ".$_REQUEST['cat_id'];
 172      api_sql_query($sql, __FILE__, __LINE__);
 173      header('Location:'.api_get_self().'?'.api_get_cidReq());
 174  }
 175  
 176  if(isset($_REQUEST['action']) && ($_REQUEST['action'] == 'add_category' || $_REQUEST['action'] == 'edit_category'))
 177  {
 178      echo '<table width="100%" border="0"><tr><td width="10%">&nbsp;</td><td width="50%" valign="top">';    
 179      $form->addElement('html','<div class="row"><div class="form_header">'.get_lang('Newcategory').'</div></div>');
 180      $form->addElement('text', 'category', get_lang('Category'), 'class="focus";style="width:300px;"');    
 181  
 182      $form->addElement('html', '<br/>');
 183      $form->addElement('style_submit_button', 'submitExercise', get_lang('Ok'), 'class="save"');
 184      $form->addElement('html', '</div>');
 185  
 186      $form->addRule('category', get_lang('Category'), 'required');
 187      $defaults['category'] = $category_title;
 188      $form->setDefaults($defaults);
 189      $form -> display();
 190      echo '</td><td>';
 191      Display::display_icon('KnockOnWood.png', get_lang('Teacher'));
 192      echo '</td>';
 193      echo '</tr></table>';    
 194  }
 195  else
 196  {
 197      $query = "SELECT * FROM $TBL_QUIZ_CATEGORY ORDER BY display_order";
 198      $result = api_sql_query($query, __FILE__, __LINE__);
 199  
 200      echo '<table class="data_table" width="100%"><tr>';
 201      echo '<th width="10%">'.get_lang('Move').'</th>';
 202      echo '<th width="70%">'.get_lang('Category').'</th>';
 203      echo '<th width="10%">'.get_lang('Edit').'</th>';
 204      echo '<th width="10%">'.get_lang('Delete').'</th>';
 205      echo '</tr></table>';
 206  
 207      echo '<div id="contentWrap"><div id="contentLeft"><ul class="dragdrop nobullets " id="categories">';
 208          $i = 0;
 209      while ($row = Database::fetch_array($result)) {
 210              $class = ($i%2==0) ? 'row_odd' : 'row_even';
 211          echo '<tr><td>';
 212          echo '<li id="recordsArray_' . $row['id'] . '" class="category">';
 213          echo '<div>';
 214          echo '<table class="data_table" width="100%">';
 215  
 216          echo '<tr class="'.$class.'" >';
 217          echo '<td width="10%" align="center"><img src="../img/drag-and-drop.png"></td>';
 218          echo '<td class="nodrag" width="70%">'.$row['category_title'].'</td>';
 219          if(api_is_allowed_to_edit())
 220          {
 221          echo '<td class="nodrag" width="10%" align="center"><a href="'.api_get_self().'?'.api_get_cidReq().'&action=edit_category&cat_id='.$row['id'].'"><img src="../img/edit_link.png"></a></td>';
 222          echo '<td class="nodrag" width="10%" align="center"><a href="'.api_get_self().'?'.api_get_cidReq().'&action=delete_category&cat_id='.$row['id'].'">'.Display::return_icon('pixel.gif','',array('class'=>'actionplaceholdericon actiondelete')).'</a></td>';
 223          }
 224          echo '</tr>';
 225          echo '</table></div></li></td></tr>';
 226                  $i++;
 227      }
 228  //    echo '</table>';    
 229      echo '</ul></div></div>';
 230  }
 231  
 232  echo '</div>';
 233  
 234  function category_add($form)
 235  {    
 236      $TBL_QUIZ_CATEGORY = Database::get_course_table(TABLE_QUIZ_CATEGORY);
 237      $category_title = $form->getSubmitValue('category');    
 238  
 239      if(isset($_REQUEST['cat_id']) && !empty($_REQUEST['cat_id']))
 240      {
 241          $sql = "UPDATE $TBL_QUIZ_CATEGORY SET category_title = '".$category_title."' WHERE id = ".$_REQUEST['cat_id'];        
 242          api_sql_query($sql, __FILE__, __LINE__);
 243      }
 244      else
 245      {
 246          $result = Database::query("SELECT MAX(display_order) FROM  ".$TBL_QUIZ_CATEGORY);
 247          list ($orderMax) = Database::fetch_row($result);
 248          $order = $orderMax +1;
 249          $session_id = api_get_session_id();
 250  
 251          $sql = "INSERT INTO $TBL_QUIZ_CATEGORY (category_title,display_order,session_id)
 252                          VALUES(                        
 253                              '" . Database::escape_string($category_title) . "',
 254                              ".$order.",
 255                              " . $session_id . "
 256                              )";    
 257          api_sql_query($sql, __FILE__, __LINE__);
 258      }
 259  }
 260  
 261  echo '<div class="actions">';
 262  echo '</div>';
 263  
 264  // display footer
 265  Display::display_footer();
 266  ?>

title

Description

title

Description

title

Description

title

title

Body