Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/mod.php
Go to the documentation of this file.
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 
00026 require("../config.php");
00027 require_once("lib.php");
00028 
00029 $sectionreturn = optional_param('sr', '', PARAM_INT);
00030 $add           = optional_param('add', '', PARAM_ALPHA);
00031 $type          = optional_param('type', '', PARAM_ALPHA);
00032 $indent        = optional_param('indent', 0, PARAM_INT);
00033 $update        = optional_param('update', 0, PARAM_INT);
00034 $duplicate     = optional_param('duplicate', 0, PARAM_INT);
00035 $hide          = optional_param('hide', 0, PARAM_INT);
00036 $show          = optional_param('show', 0, PARAM_INT);
00037 $copy          = optional_param('copy', 0, PARAM_INT);
00038 $moveto        = optional_param('moveto', 0, PARAM_INT);
00039 $movetosection = optional_param('movetosection', 0, PARAM_INT);
00040 $delete        = optional_param('delete', 0, PARAM_INT);
00041 $course        = optional_param('course', 0, PARAM_INT);
00042 $groupmode     = optional_param('groupmode', -1, PARAM_INT);
00043 $cancelcopy    = optional_param('cancelcopy', 0, PARAM_BOOL);
00044 $confirm       = optional_param('confirm', 0, PARAM_BOOL);
00045 
00046 // This page should always redirect
00047 $url = new moodle_url('/course/mod.php');
00048 foreach (compact('indent','update','hide','show','copy','moveto','movetosection','delete','course','cancelcopy','confirm') as $key=>$value) {
00049     if ($value !== 0) {
00050         $url->param($key, $value);
00051     }
00052 }
00053 if ($sectionreturn !== '') {
00054     $url->param('sr', $sectionreturn);
00055 }
00056 if ($add !== '') {
00057     $url->param('add', $add);
00058 }
00059 if ($type !== '') {
00060     $url->param('type', $type);
00061 }
00062 if ($groupmode !== '') {
00063     $url->param('groupmode', $groupmode);
00064 }
00065 $PAGE->set_url($url);
00066 
00067 require_login();
00068 
00069 //check if we are adding / editing a module that has new forms using formslib
00070 if (!empty($add)) {
00071     $id          = required_param('id', PARAM_INT);
00072     $section     = required_param('section', PARAM_INT);
00073     $type        = optional_param('type', '', PARAM_ALPHA);
00074     $returntomod = optional_param('return', 0, PARAM_BOOL);
00075 
00076     redirect("$CFG->wwwroot/course/modedit.php?add=$add&type=$type&course=$id&section=$section&return=$returntomod");
00077 
00078 } else if (!empty($update)) {
00079     $cm = get_coursemodule_from_id('', $update, 0, true, MUST_EXIST);
00080     $returntomod = optional_param('return', 0, PARAM_BOOL);
00081     redirect("$CFG->wwwroot/course/modedit.php?update=$update&return=$returntomod");
00082 
00083 } else if (!empty($duplicate)) {
00084     $cm     = get_coursemodule_from_id('', $duplicate, 0, true, MUST_EXIST);
00085     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00086 
00087     require_login($course, false, $cm);
00088     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00089     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00090     require_capability('moodle/course:manageactivities', $coursecontext);
00091 
00092     if (!$confirm or !confirm_sesskey()) {
00093         $PAGE->set_title(get_string('duplicate'));
00094         $PAGE->set_heading($course->fullname);
00095         $PAGE->navbar->add(get_string('duplicatinga', 'core', format_string($cm->name)));
00096         $PAGE->set_pagelayout('incourse');
00097 
00098         $a = new stdClass();
00099         $a->modtype = get_string('modulename', $cm->modname);
00100         $a->modname = format_string($cm->name);
00101         $a->modid   = $cm->id;
00102 
00103         echo $OUTPUT->header();
00104         echo $OUTPUT->confirm(
00105             get_string('duplicateconfirm', 'core', $a),
00106             new single_button(
00107                 new moodle_url('/course/modduplicate.php', array('cmid' => $cm->id, 'course' => $course->id)),
00108                 get_string('continue'),
00109                 'post'),
00110             new single_button(
00111                 new moodle_url('/course/view.php#section-' . $cm->sectionnum, array('id' => $cm->course)),
00112                 get_string('cancel'),
00113                 'get')
00114         );
00115         echo $OUTPUT->footer();
00116         die();
00117     }
00118 
00119 } else if (!empty($delete)) {
00120     $cm     = get_coursemodule_from_id('', $delete, 0, true, MUST_EXIST);
00121     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00122 
00123     require_login($course, false, $cm);
00124     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00125     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00126     require_capability('moodle/course:manageactivities', $modcontext);
00127 
00128     $return = "$CFG->wwwroot/course/view.php?id=$cm->course#section-$cm->sectionnum";
00129 
00130     if (!$confirm or !confirm_sesskey()) {
00131         $fullmodulename = get_string('modulename', $cm->modname);
00132 
00133         $optionsyes = array('confirm'=>1, 'delete'=>$cm->id, 'sesskey'=>sesskey());
00134         $optionsno  = array('id'=>$cm->course);
00135 
00136         $strdeletecheck = get_string('deletecheck', '', $fullmodulename);
00137         $strdeletecheckfull = get_string('deletecheckfull', '', "$fullmodulename '$cm->name'");
00138 
00139         $PAGE->set_pagetype('mod-' . $cm->modname . '-delete');
00140         $PAGE->set_title($strdeletecheck);
00141         $PAGE->set_heading($course->fullname);
00142         $PAGE->navbar->add($strdeletecheck);
00143         echo $OUTPUT->header();
00144 
00145         // print_simple_box_start('center', '60%', '#FFAAAA', 20, 'noticebox');
00146         echo $OUTPUT->box_start('noticebox');
00147         $formcontinue = new single_button(new moodle_url("$CFG->wwwroot/course/mod.php", $optionsyes), get_string('yes'));
00148         $formcancel = new single_button(new moodle_url($return, $optionsno), get_string('no'), 'get');
00149         echo $OUTPUT->confirm($strdeletecheckfull, $formcontinue, $formcancel);
00150         echo $OUTPUT->box_end();
00151         echo $OUTPUT->footer();
00152 
00153         exit;
00154     }
00155 
00156     $modlib = "$CFG->dirroot/mod/$cm->modname/lib.php";
00157 
00158     if (file_exists($modlib)) {
00159         require_once($modlib);
00160     } else {
00161         print_error('modulemissingcode', '', '', $modlib);
00162     }
00163 
00164     $deleteinstancefunction = $cm->modname."_delete_instance";
00165 
00166     if (!$deleteinstancefunction($cm->instance)) {
00167         echo $OUTPUT->notification("Could not delete the $cm->modname (instance)");
00168     }
00169 
00170     // remove all module files in case modules forget to do that
00171     $fs = get_file_storage();
00172     $fs->delete_area_files($modcontext->id);
00173 
00174     if (!delete_course_module($cm->id)) {
00175         echo $OUTPUT->notification("Could not delete the $cm->modname (coursemodule)");
00176     }
00177     if (!delete_mod_from_section($cm->id, $cm->section)) {
00178         echo $OUTPUT->notification("Could not delete the $cm->modname from that section");
00179     }
00180 
00181     // Trigger a mod_deleted event with information about this module.
00182     $eventdata = new stdClass();
00183     $eventdata->modulename = $cm->modname;
00184     $eventdata->cmid       = $cm->id;
00185     $eventdata->courseid   = $course->id;
00186     $eventdata->userid     = $USER->id;
00187     events_trigger('mod_deleted', $eventdata);
00188 
00189     add_to_log($course->id, 'course', "delete mod",
00190                "view.php?id=$cm->course",
00191                "$cm->modname $cm->instance", $cm->id);
00192 
00193     rebuild_course_cache($course->id);
00194 
00195     redirect($return);
00196 }
00197 
00198 
00199 if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) {
00200     $cm     = get_coursemodule_from_id('', $USER->activitycopy, 0, true, MUST_EXIST);
00201     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00202 
00203     require_login($course, false, $cm);
00204     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00205     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00206     require_capability('moodle/course:manageactivities', $modcontext);
00207 
00208     if (!empty($movetosection)) {
00209         if (!$section = $DB->get_record('course_sections', array('id'=>$movetosection, 'course'=>$cm->course))) {
00210             print_error('sectionnotexist');
00211         }
00212         $beforecm = NULL;
00213 
00214     } else {                      // normal moveto
00215         if (!$beforecm = get_coursemodule_from_id('', $moveto, $cm->course, true)) {
00216             print_error('invalidcoursemodule');
00217         }
00218         if (!$section = $DB->get_record('course_sections', array('id'=>$beforecm->section, 'course'=>$cm->course))) {
00219             print_error('sectionnotexist');
00220         }
00221     }
00222 
00223     if (!ismoving($section->course)) {
00224         print_error('needcopy', '', "view.php?id=$section->course");
00225     }
00226 
00227     moveto_module($cm, $section, $beforecm);
00228 
00229     unset($USER->activitycopy);
00230     unset($USER->activitycopycourse);
00231     unset($USER->activitycopyname);
00232 
00233     rebuild_course_cache($section->course);
00234 
00235     if (SITEID == $section->course) {
00236         redirect($CFG->wwwroot);
00237     } else {
00238         redirect("view.php?id=$section->course#section-$sectionreturn");
00239     }
00240 
00241 } else if (!empty($indent) and confirm_sesskey()) {
00242     $id = required_param('id', PARAM_INT);
00243 
00244     $cm     = get_coursemodule_from_id('', $id, 0, true, MUST_EXIST);
00245     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00246 
00247     require_login($course, false, $cm);
00248     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00249     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00250     require_capability('moodle/course:manageactivities', $modcontext);
00251 
00252     $cm->indent += $indent;
00253 
00254     if ($cm->indent < 0) {
00255         $cm->indent = 0;
00256     }
00257 
00258     $DB->set_field('course_modules', 'indent', $cm->indent, array('id'=>$cm->id));
00259 
00260     rebuild_course_cache($cm->course);
00261 
00262     if (SITEID == $cm->course) {
00263         redirect($CFG->wwwroot);
00264     } else {
00265         redirect("view.php?id=$cm->course#section-$cm->sectionnum");
00266     }
00267 
00268 } else if (!empty($hide) and confirm_sesskey()) {
00269     $cm     = get_coursemodule_from_id('', $hide, 0, true, MUST_EXIST);
00270     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00271 
00272     require_login($course, false, $cm);
00273     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00274     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00275     require_capability('moodle/course:activityvisibility', $modcontext);
00276 
00277     set_coursemodule_visible($cm->id, 0);
00278 
00279     rebuild_course_cache($cm->course);
00280 
00281     if (SITEID == $cm->course) {
00282         redirect($CFG->wwwroot);
00283     } else {
00284         redirect("view.php?id=$cm->course#section-$cm->sectionnum");
00285     }
00286 
00287 } else if (!empty($show) and confirm_sesskey()) {
00288     $cm     = get_coursemodule_from_id('', $show, 0, true, MUST_EXIST);
00289     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00290 
00291     require_login($course, false, $cm);
00292     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00293     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00294     require_capability('moodle/course:activityvisibility', $modcontext);
00295 
00296     $section = $DB->get_record('course_sections', array('id'=>$cm->section), '*', MUST_EXIST);
00297 
00298     $module = $DB->get_record('modules', array('id'=>$cm->module), '*', MUST_EXIST);
00299 
00300     if ($module->visible and ($section->visible or (SITEID == $cm->course))) {
00301         set_coursemodule_visible($cm->id, 1);
00302         rebuild_course_cache($cm->course);
00303     }
00304 
00305     if (SITEID == $cm->course) {
00306         redirect($CFG->wwwroot);
00307     } else {
00308         redirect("view.php?id=$cm->course#section-$cm->sectionnum");
00309     }
00310 
00311 } else if ($groupmode > -1 and confirm_sesskey()) {
00312     $id = required_param('id', PARAM_INT);
00313 
00314     $cm     = get_coursemodule_from_id('', $id, 0, true, MUST_EXIST);
00315     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00316 
00317     require_login($course, false, $cm);
00318     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00319     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00320     require_capability('moodle/course:manageactivities', $modcontext);
00321 
00322     set_coursemodule_groupmode($cm->id, $groupmode);
00323 
00324     rebuild_course_cache($cm->course);
00325 
00326     if (SITEID == $cm->course) {
00327         redirect($CFG->wwwroot);
00328     } else {
00329         redirect("view.php?id=$cm->course#section-$cm->sectionnum");
00330     }
00331 
00332 } else if (!empty($copy) and confirm_sesskey()) { // value = course module
00333     $cm     = get_coursemodule_from_id('', $copy, 0, true, MUST_EXIST);
00334     $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00335 
00336     require_login($course, false, $cm);
00337     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00338     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00339     require_capability('moodle/course:manageactivities', $modcontext);
00340 
00341     $section = $DB->get_record('course_sections', array('id'=>$cm->section), '*', MUST_EXIST);
00342 
00343     $USER->activitycopy       = $copy;
00344     $USER->activitycopycourse = $cm->course;
00345     $USER->activitycopyname   = $cm->name;
00346 
00347     redirect("view.php?id=$cm->course#section-$sectionreturn");
00348 
00349 } else if (!empty($cancelcopy) and confirm_sesskey()) { // value = course module
00350 
00351     $courseid = $USER->activitycopycourse;
00352 
00353     unset($USER->activitycopy);
00354     unset($USER->activitycopycourse);
00355     unset($USER->activitycopyname);
00356 
00357     redirect("view.php?id=$courseid");
00358 
00359 } else {
00360     print_error('unknowaction');
00361 }
00362 
00363 
 All Data Structures Namespaces Files Functions Variables Enumerations