[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/lesson/ -> edit.php (source)

   1  <?php  // $Id: edit.php,v 1.13.2.1 2007/12/29 20:40:18 mark-nielsen Exp $
   2  /**
   3   * Provides the interface for overall authoring of lessons
   4   *
   5   * @version $Id: edit.php,v 1.13.2.1 2007/12/29 20:40:18 mark-nielsen Exp $
   6   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
   7   * @package lesson
   8   **/
   9  
  10      require_once('../../config.php');
  11      require_once ('locallib.php');
  12      require_once ('lib.php');
  13  
  14      $id      = required_param('id', PARAM_INT);             // Course Module ID
  15      $display = optional_param('display', 0, PARAM_INT);
  16      $mode    = optional_param('mode', get_user_preferences('lesson_view', 'collapsed'), PARAM_ALPHA);
  17      $pageid = optional_param('pageid', 0, PARAM_INT);
  18      
  19      if ($mode != 'single') {
  20          set_user_preference('lesson_view', $mode);
  21      }
  22      
  23      list($cm, $course, $lesson) = lesson_get_basics($id);
  24      
  25      if ($firstpage = get_record('lesson_pages', 'lessonid', $lesson->id, 'prevpageid', 0)) {
  26          if (!$pages = get_records('lesson_pages', 'lessonid', $lesson->id)) {
  27              error('Could not find lesson pages');
  28          }
  29      }
  30      
  31      if ($pageid) {
  32          if (!$singlepage = get_record('lesson_pages', 'id', $pageid)) {
  33              error('Could not find page ID: '.$pageid);
  34          }
  35      }
  36  
  37      require_login($course->id, false, $cm);
  38      $context = get_context_instance(CONTEXT_MODULE, $cm->id);
  39      require_capability('mod/lesson:manage', $context);
  40      
  41      lesson_print_header($cm, $course, $lesson, $mode);
  42  
  43      if (empty($firstpage)) {
  44          // There are no pages; give teacher some options
  45          if (has_capability('mod/lesson:edit', $context)) {
  46              print_simple_box( "<table cellpadding=\"5\" border=\"0\">\n<tr><th scope=\"col\">".get_string("whatdofirst", "lesson")."</th></tr><tr><td>".
  47                  "<a href=\"import.php?id=$cm->id&amp;pageid=0\">".
  48                  get_string("importquestions", "lesson")."</a></td></tr><tr><td>".
  49                  "<a href=\"importppt.php?id=$cm->id&amp;pageid=0\">".
  50                  get_string("importppt", "lesson")."</a></td></tr><tr><td>".
  51                  "<a href=\"lesson.php?id=$cm->id&amp;action=addbranchtable&amp;pageid=0&amp;firstpage=1\">".
  52                  get_string("addabranchtable", "lesson")."</a></td></tr><tr><td>".
  53                  "<a href=\"lesson.php?id=$cm->id&amp;action=addpage&amp;pageid=0&amp;firstpage=1\">".
  54                  get_string("addaquestionpage", "lesson").
  55                  "</a></td></tr></table>\n", 'center', '20%');
  56          }
  57      } else {
  58          // Set some standard variables
  59          $pageid = $firstpage->id;
  60          $prevpageid = 0;
  61          $npages = count($pages);
  62          
  63          switch ($mode) {
  64              case 'collapsed':
  65                  $table = new stdClass;
  66                  $table->head = array(get_string('pagetitle', 'lesson'), get_string('qtype', 'lesson'), get_string('jumps', 'lesson'), get_string('actions', 'lesson'));
  67                  $table->align = array('left', 'left', 'left', 'center');
  68                  $table->wrap = array('', 'nowrap', '', 'nowrap');
  69                  $table->tablealign = 'center';
  70                  $table->cellspacing = 0;
  71                  $table->cellpadding = '2px';
  72                  $table->data = array();
  73                  
  74                  while ($pageid != 0) {
  75                      $page = $pages[$pageid];
  76  
  77                      if ($page->qtype == LESSON_MATCHING) {
  78                          // The jumps for matching question type is stored
  79                          // in the 3rd and 4rth answer record.
  80                          $limitfrom = $limitnum = 2;
  81                      } else {
  82                          $limitfrom = $limitnum = '';
  83                      }
  84  
  85                      $jumps = array();
  86                      if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid", 'id', '*', $limitfrom, $limitnum)) {
  87                          foreach ($answers as $answer) {
  88                              $jumps[] = lesson_get_jump_name($answer->jumpto);
  89                          }
  90                      }
  91                      
  92                      $table->data[] = array("<a href=\"$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id&amp;mode=single&amp;pageid=".$page->id."\">".format_string($pages[$pageid]->title,true).'</a>',
  93                                             lesson_get_qtype_name($page->qtype),
  94                                             implode("<br />\n", $jumps),
  95                                             lesson_print_page_actions($cm->id, $page, $npages, true, true)
  96                                            );
  97                      $pageid = $page->nextpageid;
  98                  }
  99                  
 100                  print_table($table);
 101                  break;
 102                  
 103              case 'single':
 104                  // Only viewing a single page in full - change some variables to display just one
 105                  $prevpageid = $singlepage->prevpageid;
 106                  $pageid     = $singlepage->id;
 107                  
 108                  $pages = array();
 109                  $pages[$singlepage->id] = $singlepage;
 110                  
 111              case 'full':
 112                  echo '<table class="boxaligncenter" cellpadding="5" border="0" style="width:80%;">
 113                           <tr>
 114                               <td align="left">';
 115                  lesson_print_add_links($cm->id, $prevpageid);
 116                  echo '       </td>
 117                           </tr>';
 118  
 119                  while ($pageid != 0) {
 120                      $page = $pages[$pageid];
 121  
 122                      echo "<tr><td>\n";
 123                      echo "<table style=\"width:100%;\" border=\"1\" class=\"generalbox\"><tr><th colspan=\"2\" scope=\"col\">".format_string($page->title)."&nbsp;&nbsp;\n";
 124                      lesson_print_page_actions($cm->id, $page, $npages);
 125                      echo "</th></tr>\n";             
 126                      echo "<tr><td colspan=\"2\">\n";
 127                      $options = new stdClass;
 128                      $options->noclean = true;
 129                      echo format_text($page->contents, FORMAT_MOODLE, $options);
 130                      echo "</td></tr>\n";
 131                      // get the answers in a set order, the id order
 132                      if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
 133                          echo "<tr><td colspan=\"2\" align=\"center\"><strong>\n";
 134                          echo lesson_get_qtype_name($page->qtype);
 135                          switch ($page->qtype) {
 136                              case LESSON_SHORTANSWER :
 137                                  if ($page->qoption) {
 138                                      echo " - ".get_string("casesensitive", "lesson");
 139                                  }
 140                                  break;
 141                              case LESSON_MULTICHOICE :
 142                                  if ($page->qoption) {
 143                                      echo " - ".get_string("multianswer", "lesson");
 144                                  }
 145                                  break;
 146                              case LESSON_MATCHING :
 147                                  echo get_string("firstanswershould", "lesson");
 148                                  break;
 149                          }
 150                          echo "</strong></td></tr>\n";
 151                          $i = 1;
 152                          $n = 0;
 153                          $options = new stdClass;
 154                          $options->noclean = true;
 155                          $options->para = false;
 156                          foreach ($answers as $answer) {
 157                              switch ($page->qtype) {
 158                                  case LESSON_MULTICHOICE:
 159                                  case LESSON_TRUEFALSE:
 160                                  case LESSON_SHORTANSWER:
 161                                  case LESSON_NUMERICAL:
 162                                      echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
 163                                      if ($lesson->custom) {
 164                                          // if the score is > 0, then it is correct
 165                                          if ($answer->score > 0) {
 166                                              echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
 167                                          } else {
 168                                              echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
 169                                          }
 170                                      } else {
 171                                          if (lesson_iscorrect($page->id, $answer->jumpto)) {
 172                                              // underline correct answers
 173                                              echo '<span class="correct">'.get_string("answer", "lesson")." $i</span>: \n";
 174                                          } else {
 175                                              echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
 176                                          }
 177                                      }
 178                                      echo "</td><td style=\"width:80%;\">\n";
 179                                      echo format_text($answer->answer, FORMAT_MOODLE, $options);
 180                                      echo "</td></tr>\n";
 181                                      echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("response", "lesson")." $i</span>: \n";
 182                                      echo "</td><td>\n";
 183                                      echo format_text($answer->response, FORMAT_MOODLE, $options); 
 184                                      echo "</td></tr>\n";
 185                                      break;                            
 186                                  case LESSON_MATCHING:
 187                                      if ($n < 2) {
 188                                          if ($answer->answer != NULL) {
 189                                              if ($n == 0) {
 190                                                  echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("correctresponse", "lesson")."</span>: \n";
 191                                                  echo "</td><td>\n";
 192                                                  echo format_text($answer->answer, FORMAT_MOODLE, $options); 
 193                                                  echo "</td></tr>\n";
 194                                              } else {
 195                                                  echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("wrongresponse", "lesson")."</span>: \n";
 196                                                  echo "</td><td>\n";
 197                                                  echo format_text($answer->answer, FORMAT_MOODLE, $options); 
 198                                                  echo "</td></tr>\n";
 199                                              }
 200                                          }
 201                                          $n++;
 202                                          $i--;
 203                                      } else {
 204                                          echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
 205                                          if ($lesson->custom) {
 206                                              // if the score is > 0, then it is correct
 207                                              if ($answer->score > 0) {
 208                                                  echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
 209                                              } else {
 210                                                  echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
 211                                              }
 212                                          } else {
 213                                              if (lesson_iscorrect($page->id, $answer->jumpto)) {
 214                                                  // underline correct answers
 215                                                  echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
 216                                              } else {
 217                                                  echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
 218                                              }
 219                                          }
 220                                          echo "</td><td style=\"width:80%;\">\n";
 221                                          echo format_text($answer->answer, FORMAT_MOODLE, $options);
 222                                          echo "</td></tr>\n";
 223                                          echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("matchesanswer", "lesson")." $i</span>: \n";
 224                                          echo "</td><td>\n";
 225                                          echo format_text($answer->response, FORMAT_MOODLE, $options); 
 226                                          echo "</td></tr>\n";
 227                                      }
 228                                      break;
 229                                  case LESSON_BRANCHTABLE:
 230                                      echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
 231                                      echo '<span class="label">'.get_string("description", "lesson")." $i</span>: \n";
 232                                      echo "</td><td style=\"width:80%;\">\n";
 233                                      echo format_text($answer->answer, FORMAT_MOODLE, $options);
 234                                      echo "</td></tr>\n";
 235                                      break;
 236                              }
 237  
 238                              $jumptitle = lesson_get_jump_name($answer->jumpto);
 239                              if ($page->qtype == LESSON_MATCHING) {
 240                                  if ($i == 1) {
 241                                      echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("correctanswerscore", "lesson");
 242                                      echo "</span>: </td><td style=\"width:80%;\">\n";
 243                                      echo "$answer->score</td></tr>\n";
 244                                      echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("correctanswerjump", "lesson");
 245                                      echo "</span>:</td><td style=\"width:80%;\">\n";
 246                                      echo "$jumptitle</td></tr>\n";
 247                                  } elseif ($i == 2) {
 248                                      echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("wronganswerscore", "lesson");
 249                                      echo "</span>: </td><td style=\"width:80%;\">\n";
 250                                      echo "$answer->score</td></tr>\n";
 251                                      echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("wronganswerjump", "lesson");
 252                                      echo "</span>: </td><td style=\"width:80%;\">\n";
 253                                      echo "$jumptitle</td></tr>\n";
 254                                  }
 255                              } else {
 256                                  if ($lesson->custom and 
 257                                      $page->qtype != LESSON_BRANCHTABLE and 
 258                                      $page->qtype != LESSON_ENDOFBRANCH and
 259                                      $page->qtype != LESSON_CLUSTER and 
 260                                      $page->qtype != LESSON_ENDOFCLUSTER) {
 261                                      echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("score", "lesson")." $i";
 262                                      echo "</span>: </td><td style=\"width:80%;\">\n";
 263                                      echo "$answer->score</td></tr>\n";
 264                                  }
 265                                  echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("jump", "lesson")." $i";
 266                                  echo "</span>: </td><td style=\"width:80%;\">\n";
 267                                  echo "$jumptitle</td></tr>\n";
 268                              }
 269                              $i++;
 270                          }
 271                      }
 272                      echo "</table></td></tr>\n<tr><td align=\"left\">";
 273                      lesson_print_add_links($cm->id, $page->id);
 274                      echo "</td></tr><tr><td>\n";
 275                      // check the prev links - fix (silently) if necessary - there was a bug in
 276                      // versions 1 and 2 when add new pages. Not serious then as the backwards
 277                      // links were not used in those versions
 278                      if ($page->prevpageid != $prevpageid) {
 279                          // fix it
 280                          set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id);
 281                          debugging("<p>***prevpageid of page $page->id set to $prevpageid***");
 282                      }
 283                      
 284                      if (count($pages) == 1) {
 285                          echo "</td></tr>";
 286                          break;
 287                      }
 288                      
 289                      $prevpageid = $page->id;
 290                      $pageid = $page->nextpageid;
 291                      echo "</td></tr>";
 292                  }
 293                  echo "</table>";
 294                  break;
 295          }
 296      } 
 297  
 298      print_footer($course);
 299  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7