Dokeos PHP Cross Reference Learning Management Systems

Source: /main/exercice/question_pool.php - 411 lines - 15307 bytes - Summary - Text - Print

Description: Question Pool This script allows administrators to manage questions and add them into their exercises. One question can be in several exercises

   1  <?php
   2  // $Id: question_pool.php 20451 2009-05-10 12:02:22Z ivantcholakov $
   3  
   4  /*
   5   ==============================================================================
   6   Dokeos - elearning and course management software
   7  
   8   Copyright (c) 2004-2009 Dokeos SPRL
   9   Copyright (c) 2003 Ghent University (UGent)
  10   Copyright (c) 2001 Universite catholique de Louvain (UCL)
  11   Copyright (c) various contributors
  12  
  13   For a full list of contributors, see "credits.txt".
  14   The full license can be read in "license.txt".
  15  
  16   This program is free software; you can redistribute it and/or
  17   modify it under the terms of the GNU General Public License
  18   as published by the Free Software Foundation; either version 2
  19   of the License, or (at your option) any later version.
  20  
  21   See the GNU General Public License for more details.
  22  
  23   Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  24   Mail: info@dokeos.com
  25   ==============================================================================
  26   */
  27  
  28  /**
  29   *     Question Pool
  30   *     This script allows administrators to manage questions and add them into their exercises.
  31   *     One question can be in several exercises
  32   *     @package dokeos.exercise
  33   *     @author Olivier Brouckaert
  34   *     @version $Id: question_pool.php 20451 2009-05-10 12:02:22Z ivantcholakov $
  35   */
  36  // name of the language file that needs to be included
  37  $language_file = 'exercice';
  38  
  39  include_once  'exercise.class.php';
  40  include_once  'question.class.php';
  41  include_once  'answer.class.php';
  42  include_once  '../inc/global.inc.php';
  43  
  44  $htmlHeadXtra[] =  '<script>
  45        $(document).ready(function (){
  46            $("#submit_add").click(function () {                  
  47                 var len = $("input[type=checkbox]").length;
  48                 var qnlist = [];
  49                 for(var i=1;i<=len;i++){
  50                     if($("#notify_checkbox_"+i).attr("checked")){
  51                         var chkval = $("#notify_checkbox_"+i).attr("value");
  52                         qnlist.push(chkval);
  53                     }
  54                 }               
  55                 $.post("ajax.php", {action: "reuse", fromExercise: '.$_GET["fromExercise"].', qnlist: qnlist}, 
  56                      function(data){                                
  57                          $("#reuse").html("");
  58                          $("#reuse").append(data);
  59                          window.location = "question_pool.php?fromExercise='.$_GET['fromExercise'].'"; 
  60                  });                    
  61            });           
  62            
  63        });      
  64        </script>';
  65  
  66  $this_section = SECTION_COURSES;
  67  
  68  $is_allowedToEdit = api_is_allowed_to_edit();
  69  
  70  $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  71  $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  72  $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  73  $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  74  
  75  $TBL_QUESTIONS_TEMPLATE = Database::get_main_table(TABLE_MAIN_QUIZ_QUESTION_TEMPLATES);
  76  $TBL_REPONSES_TEMPLATE = Database::get_main_table(TABLE_MAIN_QUIZ_ANSWER_TEMPLATES);
  77  
  78  
  79  if (empty($delete)) {
  80      $delete = intval($_GET['delete']);
  81  }
  82  if (empty($recup)) {
  83      $recup = intval($_GET['recup']);
  84  }
  85  
  86  if (empty($fromExercise)) {
  87      $fromExercise = intval($_GET['fromExercise']);
  88  }
  89  if(isset($_GET['exerciseId'])){
  90      $exerciseId = intval($_GET['exerciseId']);
  91  }
  92  elseif(isset($_REQUEST['exerciseId']))
  93  {
  94      $exerciseId = $_REQUEST['exerciseId'];
  95  }
  96  else
  97  {
  98      $exerciseId = 0;
  99  }
 100  if (isset($_REQUEST['exerciseLevel'])){
 101      $exerciseLevel = intval($_REQUEST['exerciseLevel']);
 102          if ($exerciseLevel == 0) {
 103              $exerciseLevel = -1;
 104          }
 105  } else {
 106      $exerciseLevel = -1;
 107  }
 108  if (!empty($_GET['page'])) {
 109      $page = intval($_GET['page']);
 110  }
 111  
 112  if (isset($_SESSION['editQn'])) {
 113      $_SESSION['editQn'] = '';
 114  }
 115  
 116  //only that type of question
 117  if (!empty($_GET['type'])) {
 118      $type = intval($_GET['type']);
 119  }
 120  
 121  // maximum number of questions on a same page
 122  $limitQuestPage = 10;
 123  
 124  // document path
 125  $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
 126  
 127  // picture path
 128  $picturePath = $documentPath . '/images';
 129  
 130  
 131  if (!($objExcercise instanceOf Exercise) && !empty($fromExercise)) {
 132      $objExercise = new Exercise();
 133      $objExercise->read($fromExercise);
 134  }
 135  if (!($objExcercise instanceOf Exercise) && !empty($exerciseId)) {
 136      $objExercise = new Exercise();
 137      $objExercise->read($exerciseId);
 138  }
 139  
 140  if ($is_allowedToEdit) {
 141      // deletes a question from the data base and all exercises
 142      if ($delete) {
 143          // construction of the Question object
 144          // if the question exists
 145          if ($objQuestionTmp = Question::read($delete)) {
 146              // deletes the question from all exercises
 147              $objQuestionTmp->delete();
 148          }
 149  
 150          // destruction of the Question object
 151          unset($objQuestionTmp);
 152      }
 153      // gets an existing question and copies it into a new exercise
 154      elseif ($recup && $fromExercise) {
 155          // if the question exists
 156          $objQuestionTmp = Question :: read($recup);
 157          if ($objQuestionTmp) {
 158              // adds the exercise ID represented by $fromExercise into the list of exercises for the current question
 159              $objQuestionTmp->addToList($fromExercise);
 160          }
 161  
 162          // destruction of the Question object
 163          unset($objQuestionTmp);
 164  
 165          if (!$objExcercise instanceOf Exercise) {
 166              $objExercise = new Exercise();
 167              $objExercise->read($fromExercise);
 168          }
 169          // adds the question ID represented by $recup into the list of questions for the current exercise
 170          $objExercise->addToList($recup);
 171          api_session_register('objExercise');
 172          header("Location: admin.php?exerciseId=$fromExercise");
 173          exit();
 174      }
 175  }
 176  
 177  if (isset($_SESSION['gradebook'])) {
 178      $gradebook = $_SESSION['gradebook'];
 179  }
 180  
 181  if (!empty($gradebook) && $gradebook == 'view') {
 182      $interbreadcrumb[] = array(
 183       'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
 184       'name' => get_lang('Gradebook')
 185      );
 186  }
 187  
 188  $nameTools = get_lang('QuestionPool');
 189  
 190  $interbreadcrumb[] = array("url" => "exercice.php", "name" => get_lang('Exercices'));
 191  
 192  // if admin of course
 193  if ($is_allowedToEdit) {
 194      Display::display_tool_header($nameTools, 'Exercise');
 195  
 196       $exercice_id = Security::remove_XSS($_REQUEST['fromExercise']);
 197       
 198      // Main buttons
 199       echo '<div class="actions">';
 200       echo '<a href="exercice.php?' . api_get_cidreq() . '">' . Display::return_icon('pixel.gif', get_lang('List'), array('class' => 'toolactionplaceholdericon toolactionlist'))  . get_lang('List') . '</a>';
 201       echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display::return_icon('pixel.gif', get_lang('NewEx'), array('class' => 'toolactionplaceholdericon toolactionnewquiz')) . get_lang('NewEx') . '</a>';
 202       echo '<a href="admin.php?' . api_get_cidreq() . '&exerciseId=' . $exercice_id . '">' . Display::return_icon('pixel.gif', get_lang('Questions'), array('class' => 'toolactionplaceholdericon toolactionquestion')) . get_lang('Questions') . '</a>';
 203       // ND_041010 Deplacement de code
 204      if (!empty($fromExercise)) {
 205          if (!isset($_SESSION['fromlp'])) {
 206              if (isset($_REQUEST['fullWin'])) {
 207                  echo '<a href="admin.php?'. api_get_cidreq().'">' . Display::return_icon('pixel.gif', get_lang('Quiz'), array('class' => 'toolactionplaceholdericon toolactionback')) . get_lang('Quiz'). '</a>';
 208              } else {
 209                  echo '<a href="admin.php?'. api_get_cidreq().'&exerciseId='.$fromExercise.'">' . Display::return_icon('pixel.gif', get_lang('Quiz'), array('class' => 'toolactionplaceholdericon toolactionback')) . get_lang('Quiz'). '</a>';
 210              }
 211          } else {
 212              echo '<a href="admin.php?'. api_get_cidreq().'">' . Display::return_icon('pixel.gif', get_lang('Quiz'), array('class' => 'toolactionplaceholdericon toolactionback')) . get_lang('Quiz'). '</a>';
 213          }
 214      } else {
 215          echo '<a href="admin.php?'. api_get_cidreq(). '&newQuestion=yes">' . Display::return_icon('pixel.gif', get_lang('NewQu'), array('class' => 'toolactionplaceholdericon toolactionback')).get_lang('NewQu') . '</a>';
 216      }
 217      if (isset($type)) {
 218          $url = api_get_self() . '?type=1';
 219      } else {
 220          $url = api_get_self();
 221      }
 222      // ND_041010
 223  ?>
 224  <div class="sectiontitle float_r">
 225  <form name="qnpool" method="get" action="<?php echo $url; ?>" style="display:inline;">
 226   <?php
 227      if (isset($type)) { 
 228          echo '<input type="hidden" name="type" value="1">';
 229      } 
 230      ?>
 231      <input type="hidden" name="fromExercise" value="<?php echo $fromExercise; ?>">
 232      
 233      <?php echo get_lang('Templates'); ?> :
 234      <select name="exerciseId" onchange="javascript:document.qnpool.submit();">
 235      <option value="0">-- <?php echo get_lang('Templates'); ?> --</option>    
 236      <?php 
 237      $sql="SELECT id,title FROM $TBL_EXERCICES WHERE id<>'".Database::escape_string($fromExercise)."' AND active<>'-1' ORDER BY id ";
 238      $result=api_sql_query($sql,__FILE__,__LINE__);
 239  
 240      // shows a list-box allowing to filter questions
 241      while($row=Database::fetch_array($result)) {
 242          ?>
 243          <option value="<?php echo $row['id']; ?>" <?php if($exerciseId == $row['id']) echo 'selected="selected"'; ?>><?php echo $row['title']; ?></option>
 244          <?php
 245      }
 246      ?> 
 247      </select>    
 248      &nbsp;
 249      <?php 
 250          echo get_lang('Difficulty');
 251          echo ' : <select name="exerciseLevel" onchange="javascript:document.qnpool.submit();">';                
 252          if (!isset($exerciseLevel)) $exerciseLevel = -1;            
 253          ?>
 254          <option value="-1">-- <?php echo get_lang('All') ?> --</option>';
 255          <option value="1" <?php if($exerciseLevel == '1'){echo 'selected';}?>><?php echo get_lang('Prerequisite') ?></option>';
 256          <option value="2" <?php if($exerciseLevel == '2'){echo 'selected';}?>><?php echo get_lang('Beginner') ?></option>';
 257          <option value="3" <?php if($exerciseLevel == '3'){echo 'selected';}?>><?php echo get_lang('Intermediate') ?></option>';
 258          <option value="4" <?php if($exerciseLevel == '4'){echo 'selected';}?>><?php echo get_lang('Advanced') ?></option>';
 259          <?php
 260          echo '</select> ';
 261      ?>
 262      </form></div>
 263  <?php
 264  
 265      echo '</div>';
 266      ?>
 267  
 268  <div id="content">
 269      <div><table width="100%"><tr><td align="right">
 270      <?php
 271      $from=$page*$limitQuestPage;
 272      if($exerciseId == 0)
 273      {
 274          if (isset($exerciseLevel) && $exerciseLevel != -1) {
 275              $where .= ' level='.$exerciseLevel.' AND ';
 276          }
 277          $sql="SELECT question.id,question.question,question.type,question.level 
 278                  FROM $TBL_EXERCICE_QUESTION rel_question,$TBL_QUESTIONS question,$TBL_EXERCICES quiz
 279                    WHERE $where rel_question.question_id=question.id AND rel_question.exercice_id=quiz.id AND question.type <> 6 AND quiz.active <> -1 GROUP BY question.question,question.type,question.level ORDER BY question_order LIMIT ".$from.", ".($limitQuestPage + 1);
 280      }
 281      else
 282      {
 283          if (isset($exerciseLevel) && $exerciseLevel != -1) {
 284              $where .= ' level='.$exerciseLevel.' AND ';
 285          }
 286          $sql="SELECT question.id,question.question,question.type,question.level 
 287                  FROM $TBL_EXERCICE_QUESTION rel_question,$TBL_QUESTIONS question,$TBL_EXERCICES quiz
 288                    WHERE $where rel_question.question_id=question.id AND  rel_question.exercice_id=quiz.id AND rel_question.exercice_id='".Database::escape_string($exerciseId)."'                 
 289                  AND question.type <> 6 AND quiz.active <> -1 GROUP BY question.question,question.type,question.level ORDER BY question_order LIMIT ".$from.", ".($limitQuestPage + 1);
 290      }                
 291  //    $exerciseId=0;
 292      
 293      $i = 1;
 294      $result=api_sql_query($sql,__FILE__,__LINE__);
 295      $nbrQuestions=Database::num_rows($result);
 296  
 297      if(!empty($page)) {
 298         echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&exerciseLevel='.intval($_GET['exerciseLevel']).'&fromExercise='.$fromExercise.'&page='.($page-1).'">'.Display::return_icon('pixel.gif', '', array('class' => 'actionplaceholdericon actionprev')).get_lang('PreviousPage').'</a> | &nbsp;';
 299      } elseif($nbrQuestions > $limitQuestPage) {
 300         echo Display::return_icon('pixel.gif', '', array('class' => 'actionplaceholdericon actionprev')).get_lang('PreviousPage').' | &nbsp;';
 301      }
 302  
 303      if($nbrQuestions > $limitQuestPage) {
 304          echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.intval($_GET['exerciseId']).'&exerciseLevel='.intval($_GET['exerciseLevel']).'&fromExercise='.$fromExercise.'&page='.($page+1).'">'.get_lang('NextPage').Display::return_icon('pixel.gif', '', array('class' => 'actionplaceholdericon actionnext')).'</a>';
 305      } elseif($page) {
 306         echo ' '.get_lang('NextPage').Display::return_icon('pixel.gif', '', array('class' => 'actionplaceholdericon actionnext'));
 307      }
 308      echo '</td>
 309      </tr>
 310      </table></div>';
 311      ?>
 312      <table class="data_table">
 313      <tr><th width="5%">&nbsp;</th><th width="65%" align="left"><?php echo get_lang('Question'); ?></th><th width="10%"><?php echo get_lang('Type'); ?></th><th width="10%"><?php echo get_lang('Level'); ?></th><th width="10%"><?php echo get_lang('ReuseQuestion'); ?></th></tr>
 314      <?php
 315      
 316      while ($row = Database::fetch_array($result)) {    
 317  
 318          if($i%2 == 0)
 319          {
 320              $class = "row_odd";
 321          }
 322          else
 323          {
 324              $class = "row_even";
 325          }
 326          
 327          $type = $row['type'];
 328          $level = $row['level'];
 329  
 330          if($type == '1')
 331          {
 332              $img_type = "multiple_choice_medium.png";
 333          }
 334          elseif($type == '2')
 335          {
 336              $img_type = "multiple_answer_medium.png";
 337          }
 338          elseif($type == '3')
 339          {
 340              $img_type = "reasoning_medium.png";
 341          }
 342          elseif($type == '4')
 343          {
 344              $img_type = "fill_in_the_blank_medium.png";
 345          }
 346          elseif($type == '5')
 347          {
 348              $img_type = "open_question_medium.png";
 349          }
 350          elseif($type == '6')
 351          {
 352              $img_type = "drag_drop_medium.png";
 353          }
 354          elseif($type == '7')
 355          {
 356              $img_type = "hotspots_medium.png";
 357          }
 358  
 359          if($level == '1')
 360          {
 361              $img_level = "level1.png";
 362              $class_level = "toolactionplaceholdericon toolactionlevel1";
 363          }
 364          elseif($level == '2')
 365          {
 366              $img_level = "level2.png";
 367              $class_level = "toolactionplaceholdericon toolactionlevel2";
 368          }
 369          elseif($level == '3')
 370          {
 371              $img_level = "level3.png";
 372              $class_level = "toolactionplaceholdericon toolactionlevel3";
 373          }
 374          elseif($level == '4')
 375          {
 376              $img_level = "level4.png";
 377              $class_level = "toolactionplaceholdericon toolactionlevel4";
 378          }
 379          
 380          
 381      echo '<tr class="'.$class.'" ><td width="5%" align="center"><input type="checkbox" name="notify_checkbox" id="notify_checkbox_'.$i.'" value="'.$row['id'].'" /></td><td width="65%">'.$row['question'].'</td><td align="center" width="10%"><img src="../img/'.$img_type.'"></td><td align="center" width="10%">'.Display::return_icon('pixel.gif', '', array('class' => $class_level)).'</td><td align="center" width="10%"><a href="'.api_get_self().'?'.api_get_cidreq().'&recup='.$row['id'].'&fromExercise='.$fromExercise.'">'.Display::return_icon('pixel.gif', '', array('class' => 'toolactionplaceholdericon tooladdquestion')).'</td></tr>';
 382      $i++;
 383      }
 384      ?>
 385      </table>
 386      <?php
 387           } else {
 388            // if not admin of course
 389            api_not_allowed(true);
 390           }
 391   if (api_is_allowed_to_edit ()) {
 392       echo '<br/><button class="cancel" type="button" name="submit_add" id="submit_add"  style="float:left;">'.get_lang('Reuse').'</button>';
 393   }
 394   ?>
 395   </div>
 396   <?php
 397    if (isset($_GET['exerciseId']) && $_GET['exerciseId'] > 0) {
 398        $quiz_id = Security::remove_XSS($_GET['exerciseId']);
 399    } elseif (isset($_GET['fromExercise']) && $_GET['fromExercise'] > 0) {
 400        $quiz_id = Security::remove_XSS($_GET['fromExercise']);
 401    }
 402    if (api_is_allowed_to_edit ()) {
 403   ?>
 404            <div class="actions">
 405             <a href="<?php echo 'exercice.php?show=result&' . api_get_cidreq(); ?>"><?php echo Display::return_icon('pixel.gif', get_lang('Tracking'), array('class' => 'actionplaceholdericon actiontracking')) . get_lang('Tracking') ?></a>
 406             <a href="<?php echo 'question_pool.php?fromExercise=' . $quiz_id . '&' . api_get_cidreq(); ?>"><?php echo Display::return_icon('pixel.gif', get_lang('QuizQuestionsPool'), array('class' => 'actionplaceholdericon actionquestionpool')) . get_lang('QuizQuestionsPool') ?></a>
 407            </div>
 408  <?php
 409    }
 410    Display::display_footer();
 411  ?>

title

Description

title

Description

title

Description

title

title

Body