|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00032 require_once("../../config.php"); 00033 require_once($CFG->dirroot.'/mod/lesson/locallib.php'); 00034 00035 $id = required_param('id', PARAM_INT); // Course Module ID 00036 $action = required_param('action', PARAM_ALPHA); // Action 00037 $pageid = required_param('pageid', PARAM_INT); 00038 00039 $cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);; 00040 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); 00041 $lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST)); 00042 00043 require_login($course, false, $cm); 00044 00045 $url = new moodle_url('/mod/lesson/lesson.php', array('id'=>$id,'action'=>$action)); 00046 $PAGE->set_url($url); 00047 00048 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00049 require_capability('mod/lesson:edit', $context); 00050 require_sesskey(); 00051 00052 $lessonoutput = $PAGE->get_renderer('mod_lesson'); 00053 00055 switch ($action) { 00056 case 'confirmdelete': 00057 $PAGE->navbar->add(get_string($action, 'lesson')); 00058 00059 $thispage = $lesson->load_page($pageid); 00060 00061 echo $lessonoutput->header($lesson, $cm); 00062 echo $OUTPUT->heading(get_string("deletingpage", "lesson", format_string($thispage->title))); 00063 // print the jumps to this page 00064 $params = array("lessonid" => $lesson->id, "pageid" => $pageid); 00065 if ($answers = $DB->get_records_select("lesson_answers", "lessonid = :lessonid AND jumpto = :pageid + 1", $params)) { 00066 echo $OUTPUT->heading(get_string("thefollowingpagesjumptothispage", "lesson")); 00067 echo "<p align=\"center\">\n"; 00068 foreach ($answers as $answer) { 00069 if (!$title = $DB->get_field("lesson_pages", "title", array("id" => $answer->pageid))) { 00070 print_error('cannotfindpagetitle', 'lesson'); 00071 } 00072 echo $title."<br />\n"; 00073 } 00074 } 00075 echo $OUTPUT->confirm(get_string("confirmdeletionofthispage","lesson"),"lesson.php?action=delete&id=$cm->id&pageid=$pageid","view.php?id=$cm->id"); 00076 00077 break; 00078 case 'move': 00079 $PAGE->navbar->add(get_string($action, 'lesson')); 00080 00081 $title = $DB->get_field("lesson_pages", "title", array("id" => $pageid)); 00082 00083 echo $lessonoutput->header($lesson, $cm); 00084 echo $OUTPUT->heading(get_string("moving", "lesson", format_string($title))); 00085 00086 $params = array ("lessonid" => $lesson->id, "prevpageid" => 0); 00087 if (!$page = $DB->get_record_select("lesson_pages", "lessonid = :lessonid AND prevpageid = :prevpageid", $params)) { 00088 print_error('cannotfindfirstpage', 'lesson'); 00089 } 00090 00091 echo "<center><table cellpadding=\"5\" border=\"1\">\n"; 00092 echo "<tr><td><a href=\"lesson.php?id=$cm->id&sesskey=".sesskey()."&action=moveit&pageid=$pageid&after=0\"><small>". 00093 get_string("movepagehere", "lesson")."</small></a></td></tr>\n"; 00094 while (true) { 00095 if ($page->id != $pageid) { 00096 if (!$title = trim(format_string($page->title))) { 00097 $title = "<< ".get_string("notitle", "lesson")." >>"; 00098 } 00099 echo "<tr><td><b>$title</b></td></tr>\n"; 00100 echo "<tr><td><a href=\"lesson.php?id=$cm->id&sesskey=".sesskey()."&action=moveit&pageid=$pageid&after={$page->id}\"><small>". 00101 get_string("movepagehere", "lesson")."</small></a></td></tr>\n"; 00102 } 00103 if ($page->nextpageid) { 00104 if (!$page = $DB->get_record("lesson_pages", array("id" => $page->nextpageid))) { 00105 print_error('cannotfindnextpage', 'lesson'); 00106 } 00107 } else { 00108 // last page reached 00109 break; 00110 } 00111 } 00112 echo "</table>\n"; 00113 00114 break; 00115 case 'delete': 00116 $thispage = $lesson->load_page($pageid); 00117 $thispage->delete(); 00118 redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id"); 00119 break; 00120 case 'moveit': 00121 $after = (int)required_param('after', PARAM_INT); // target page 00122 00123 $pages = $lesson->load_all_pages(); 00124 00125 if (!array_key_exists($pageid, $pages) || ($after!=0 && !array_key_exists($after, $pages))) { 00126 print_error('cannotfindpages', 'lesson', "$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id"); 00127 } 00128 $pagetomove = clone($pages[$pageid]); 00129 unset($pages[$pageid]); 00130 00131 $pageids = array(); 00132 if ($after === 0) { 00133 $pageids['p0'] = $pageid; 00134 } 00135 foreach ($pages as $page) { 00136 $pageids[] = $page->id; 00137 if ($page->id == $after) { 00138 $pageids[] = $pageid; 00139 } 00140 } 00141 00142 $pageidsref = $pageids; 00143 reset($pageidsref); 00144 $prev = 0; 00145 $next = next($pageidsref); 00146 foreach ($pageids as $pid) { 00147 if ($pid === $pageid) { 00148 $page = $pagetomove; 00149 } else { 00150 $page = $pages[$pid]; 00151 } 00152 if ($page->prevpageid != $prev || $page->nextpageid != $next) { 00153 $page->move($next, $prev); 00154 } 00155 $prev = $page->id; 00156 $next = next($pageidsref); 00157 if (!$next) { 00158 $next = 0; 00159 } 00160 } 00161 00162 redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id"); 00163 break; 00164 default: 00165 print_error('unknowaction'); 00166 break; 00167 } 00168 00169 echo $lessonoutput->footer();