[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

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

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Handles lesson actions
  20   *
  21   * ACTIONS handled are:
  22   *    confirmdelete
  23   *    delete
  24   *    move
  25   *    moveit
  26   * @package mod_lesson
  27   * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   **/
  30  
  31  require_once("../../config.php");
  32  require_once($CFG->dirroot.'/mod/lesson/locallib.php');
  33  
  34  $id     = required_param('id', PARAM_INT);         // Course Module ID
  35  $action = required_param('action', PARAM_ALPHA);   // Action
  36  $pageid = required_param('pageid', PARAM_INT);
  37  
  38  $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
  39  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  40  $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
  41  
  42  require_login($course, false, $cm);
  43  
  44  $url = new moodle_url('/mod/lesson/lesson.php', array('id'=>$id,'action'=>$action));
  45  $PAGE->set_url($url);
  46  
  47  $context = context_module::instance($cm->id);
  48  require_capability('mod/lesson:edit', $context);
  49  require_sesskey();
  50  
  51  $lessonoutput = $PAGE->get_renderer('mod_lesson');
  52  
  53  /// Process the action
  54  switch ($action) {
  55      case 'confirmdelete':
  56          $PAGE->navbar->add(get_string($action, 'lesson'));
  57  
  58          $thispage = $lesson->load_page($pageid);
  59  
  60          echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('deletingpage', 'lesson', format_string($thispage->title)));
  61          echo $OUTPUT->heading(get_string("deletingpage", "lesson", format_string($thispage->title)));
  62          // print the jumps to this page
  63          $params = array("lessonid" => $lesson->id, "pageid" => $pageid);
  64          if ($answers = $DB->get_records_select("lesson_answers", "lessonid = :lessonid AND jumpto = :pageid + 1", $params)) {
  65              echo $OUTPUT->heading(get_string("thefollowingpagesjumptothispage", "lesson"));
  66              echo "<p align=\"center\">\n";
  67              foreach ($answers as $answer) {
  68                  if (!$title = $DB->get_field("lesson_pages", "title", array("id" => $answer->pageid))) {
  69                      print_error('cannotfindpagetitle', 'lesson');
  70                  }
  71                  echo $title."<br />\n";
  72              }
  73          }
  74          echo $OUTPUT->confirm(get_string("confirmdeletionofthispage","lesson"),"lesson.php?action=delete&id=$cm->id&pageid=$pageid","view.php?id=$cm->id");
  75  
  76          break;
  77      case 'move':
  78          $PAGE->navbar->add(get_string($action, 'lesson'));
  79  
  80          $title = $DB->get_field("lesson_pages", "title", array("id" => $pageid));
  81  
  82          echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('moving', 'lesson', format_String($title)));
  83          echo $OUTPUT->heading(get_string("moving", "lesson", format_string($title)), 3);
  84  
  85          $params = array ("lessonid" => $lesson->id, "prevpageid" => 0);
  86          if (!$page = $DB->get_record_select("lesson_pages", "lessonid = :lessonid AND prevpageid = :prevpageid", $params)) {
  87              print_error('cannotfindfirstpage', 'lesson');
  88          }
  89  
  90          echo html_writer::start_tag('div', array('class' => 'move-page'));
  91  
  92          echo html_writer::start_tag('div', array('class' => 'available-position'));
  93          $moveurl = "lesson.php?id=$cm->id&sesskey=".sesskey()."&action=moveit&pageid=$pageid&after=0";
  94          echo html_writer::link($moveurl, get_string("movepagehere", "lesson"));
  95          echo html_writer::end_tag('div');
  96  
  97          while (true) {
  98              if ($page->id != $pageid) {
  99                  if (!$title = trim(format_string($page->title))) {
 100                      $title = "<< ".get_string("notitle", "lesson")."  >>";
 101                  }
 102                  echo html_writer::tag('div', $title, array('class' => 'page'));
 103  
 104                  echo html_writer::start_tag('div', array('class' => 'available-position'));
 105                  $moveurl = "lesson.php?id=$cm->id&sesskey=".sesskey()."&action=moveit&pageid=$pageid&after={$page->id}";
 106                  echo html_writer::link($moveurl, get_string("movepagehere", "lesson"));
 107                  echo html_writer::end_tag('div');
 108              }
 109              if ($page->nextpageid) {
 110                  if (!$page = $DB->get_record("lesson_pages", array("id" => $page->nextpageid))) {
 111                      print_error('cannotfindnextpage', 'lesson');
 112                  }
 113              } else {
 114                  // last page reached
 115                  break;
 116              }
 117          }
 118          echo html_writer::end_tag('div');
 119  
 120          break;
 121      case 'delete':
 122          $thispage = $lesson->load_page($pageid);
 123          $thispage->delete();
 124          redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id");
 125          break;
 126      case 'moveit':
 127          $after = (int)required_param('after', PARAM_INT); // target page
 128  
 129          $pages = $lesson->load_all_pages();
 130  
 131          if (!array_key_exists($pageid, $pages) || ($after!=0 && !array_key_exists($after, $pages))) {
 132              print_error('cannotfindpages', 'lesson', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id");
 133          }
 134          $pagetomove = clone($pages[$pageid]);
 135          unset($pages[$pageid]);
 136  
 137          $pageids = array();
 138          if ($after === 0) {
 139              $pageids['p0'] = $pageid;
 140          }
 141          foreach ($pages as $page) {
 142              $pageids[] = $page->id;
 143              if ($page->id == $after) {
 144                  $pageids[] = $pageid;
 145              }
 146          }
 147  
 148          $pageidsref = $pageids;
 149          reset($pageidsref);
 150          $prev = 0;
 151          $next = next($pageidsref);
 152          foreach ($pageids as $pid) {
 153              if ($pid === $pageid) {
 154                  $page = $pagetomove;
 155              } else {
 156                  $page = $pages[$pid];
 157              }
 158              if ($page->prevpageid != $prev || $page->nextpageid != $next) {
 159                  $page->move($next, $prev);
 160              }
 161              $prev = $page->id;
 162              $next = next($pageidsref);
 163              if (!$next) {
 164                  $next = 0;
 165              }
 166          }
 167  
 168          redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id");
 169          break;
 170      default:
 171          print_error('unknowaction');
 172          break;
 173  }
 174  
 175  echo $lessonoutput->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1