[ Index ]

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

title

Body

[close]

/course/ -> mod.php (source)

   1  <?php // $Id: mod.php,v 1.127.2.2 2008/03/10 19:01:32 garethmorgan Exp $
   2  
   3  //  Moves, adds, updates, duplicates or deletes modules in a course
   4  
   5      require("../config.php");
   6      require_once ("lib.php");
   7  
   8      require_login();
   9  
  10      $sectionreturn = optional_param('sr', '', PARAM_INT);
  11      $add           = optional_param('add','', PARAM_ALPHA);
  12      $type          = optional_param('type', '', PARAM_ALPHA);
  13      $indent        = optional_param('indent', 0, PARAM_INT);
  14      $update        = optional_param('update', 0, PARAM_INT);
  15      $hide          = optional_param('hide', 0, PARAM_INT);
  16      $show          = optional_param('show', 0, PARAM_INT);
  17      $copy          = optional_param('copy', 0, PARAM_INT);
  18      $moveto        = optional_param('moveto', 0, PARAM_INT);
  19      $movetosection = optional_param('movetosection', 0, PARAM_INT);
  20      $delete        = optional_param('delete', 0, PARAM_INT);
  21      $course        = optional_param('course', 0, PARAM_INT);
  22      $groupmode     = optional_param('groupmode', -1, PARAM_INT);
  23      $duplicate     = optional_param('duplicate', 0, PARAM_INT);
  24      $cancel        = optional_param('cancel', 0, PARAM_BOOL);
  25      $cancelcopy    = optional_param('cancelcopy', 0, PARAM_BOOL);
  26  
  27      if (isset($SESSION->modform)) {   // Variables are stored in the session
  28          $mod = $SESSION->modform;
  29          unset($SESSION->modform);
  30      } else {
  31          $mod = (object)$_POST;
  32      }
  33  
  34      if ($cancel) {
  35          if (!empty($SESSION->returnpage)) {
  36              $return = $SESSION->returnpage;
  37              unset($SESSION->returnpage);
  38              redirect($return);
  39          } else {
  40              redirect("view.php?id=$mod->course#section-$sectionreturn");
  41          }
  42      }
  43  
  44      //check if we are adding / editing a module that has new forms using formslib
  45      if (!empty($add)){
  46          $modname=$add;
  47          if (file_exists("../mod/$modname/mod_form.php")) {
  48              $id          = required_param('id', PARAM_INT);
  49              $section     = required_param('section', PARAM_INT);
  50              $type        = optional_param('type', '', PARAM_ALPHA);
  51              $returntomod = optional_param('return', 0, PARAM_BOOL);
  52  
  53              redirect("modedit.php?add=$add&type=$type&course=$id&section=$section&return=$returntomod");
  54          }
  55      }elseif (!empty($update)){
  56          if (!$modname=get_field_sql("SELECT md.name
  57                             FROM {$CFG->prefix}course_modules cm,
  58                                  {$CFG->prefix}modules md
  59                             WHERE cm.id = '$update' AND
  60                                   md.id = cm.module")){
  61              error('Invalid course module id!');
  62          }
  63          $returntomod = optional_param('return', 0, PARAM_BOOL);
  64          if (file_exists("../mod/$modname/mod_form.php")) {
  65              redirect("modedit.php?update=$update&return=$returntomod");
  66          }
  67      }
  68      //not adding / editing a module that has new forms using formslib
  69      //carry on
  70  
  71      if (!empty($course) and confirm_sesskey()) {    // add, delete or update form submitted
  72  
  73          if (empty($mod->coursemodule)) { //add
  74              if (! $course = get_record("course", "id", $mod->course)) {
  75                  error("This course doesn't exist");
  76              }
  77              $mod->instance = '';
  78              $mod->coursemodule = '';
  79          } else { //delete and update
  80              if (! $cm = get_record("course_modules", "id", $mod->coursemodule)) {
  81                  error("This course module doesn't exist");
  82              }
  83  
  84              if (! $course = get_record("course", "id", $cm->course)) {
  85                  error("This course doesn't exist");
  86              }
  87              $mod->instance = $cm->instance;
  88              $mod->coursemodule = $cm->id;
  89          }
  90  
  91          require_login($course->id); // needed to setup proper $COURSE
  92          $context = get_context_instance(CONTEXT_COURSE, $course->id);
  93          require_capability('moodle/course:manageactivities', $context);
  94  
  95          $mod->course = $course->id;
  96          $mod->modulename = clean_param($mod->modulename, PARAM_SAFEDIR);  // For safety
  97          $modlib = "$CFG->dirroot/mod/$mod->modulename/lib.php";
  98  
  99          if (file_exists($modlib)) {
 100              include_once($modlib);
 101          } else {
 102              error("This module is missing important code! ($modlib)");
 103          }
 104          $addinstancefunction    = $mod->modulename."_add_instance";
 105          $updateinstancefunction = $mod->modulename."_update_instance";
 106          $deleteinstancefunction = $mod->modulename."_delete_instance";
 107          $moderr = "$CFG->dirroot/mod/$mod->modulename/moderr.html";
 108  
 109          switch ($mod->mode) {
 110              case "update":
 111  
 112                  if (isset($mod->name)) {
 113                      if (trim($mod->name) == '') {
 114                          unset($mod->name);
 115                      }
 116                  }
 117  
 118                  $return = $updateinstancefunction($mod);
 119                  if (!$return) {
 120                      if (file_exists($moderr)) {
 121                          $form = $mod;
 122                          include_once($moderr);
 123                          die;
 124                      }
 125                      error("Could not update the $mod->modulename", "view.php?id=$course->id");
 126                  }
 127                  if (is_string($return)) {
 128                      error($return, "view.php?id=$course->id");
 129                  }
 130  
 131                  if (isset($mod->visible)) {
 132                      set_coursemodule_visible($mod->coursemodule, $mod->visible);
 133                  }
 134  
 135                  if (isset($mod->groupmode)) {
 136                      set_coursemodule_groupmode($mod->coursemodule, $mod->groupmode);
 137                  }
 138                  
 139                  if (isset($mod->groupingid)) {
 140                      set_coursemodule_groupingid($mod->coursemodule, $mod->groupingid);
 141                  }
 142                  
 143                  if (isset($mod->groupmembersonly)) {
 144                      set_coursemodule_groupmembersonly($mod->coursemodule, $mod->groupmembersonly);
 145                  }
 146  
 147                  if (isset($mod->redirect)) {
 148                      $SESSION->returnpage = $mod->redirecturl;
 149                  } else {
 150                      $SESSION->returnpage = "$CFG->wwwroot/mod/$mod->modulename/view.php?id=$mod->coursemodule";
 151                  }
 152  
 153                  add_to_log($course->id, "course", "update mod",
 154                             "../mod/$mod->modulename/view.php?id=$mod->coursemodule",
 155                             "$mod->modulename $mod->instance");
 156                  add_to_log($course->id, $mod->modulename, "update",
 157                             "view.php?id=$mod->coursemodule",
 158                             "$mod->instance", $mod->coursemodule);
 159                  break;
 160  
 161              case "add":
 162  
 163                  if (!course_allowed_module($course,$mod->modulename)) {
 164                      error("This module ($mod->modulename) has been disabled for this particular course");
 165                  }
 166  
 167                  if (!isset($mod->name) || trim($mod->name) == '') {
 168                      $mod->name = get_string("modulename", $mod->modulename);
 169                  }
 170  
 171                  $return = $addinstancefunction($mod);
 172                  if (!$return) {
 173                      if (file_exists($moderr)) {
 174                          $form = $mod;
 175                          include_once($moderr);
 176                          die;
 177                      }
 178                      error("Could not add a new instance of $mod->modulename", "view.php?id=$course->id");
 179                  }
 180                  if (is_string($return)) {
 181                      error($return, "view.php?id=$course->id");
 182                  }
 183  
 184                  if (!isset($mod->groupmode)) { // to deal with pre-1.5 modules
 185                      $mod->groupmode = $course->groupmode;  /// Default groupmode the same as course
 186                  }
 187                  
 188                  if (isset($mod->groupingid)) {
 189                      set_coursemodule_groupingid($mod->coursemodule, $mod->groupingid);
 190                  }
 191                  
 192                  if (isset($mod->groupmembersonly)) {
 193                      set_coursemodule_groupmembersonly($mod->coursemodule, $mod->groupmembersonly);
 194                  }
 195                  $mod->instance = $return;
 196  
 197                  // course_modules and course_sections each contain a reference
 198                  // to each other, so we have to update one of them twice.
 199  
 200                  if (! $mod->coursemodule = add_course_module($mod) ) {
 201                      error("Could not add a new course module");
 202                  }
 203                  if (! $sectionid = add_mod_to_section($mod) ) {
 204                      error("Could not add the new course module to that section");
 205                  }
 206  
 207                  if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
 208                      error("Could not update the course module with the correct section");
 209                  }
 210  
 211                  if (!isset($mod->visible)) {   // We get the section's visible field status
 212                      $mod->visible = get_field("course_sections","visible","id",$sectionid);
 213                  }
 214                  // make sure visibility is set correctly (in particular in calendar)
 215                  set_coursemodule_visible($mod->coursemodule, $mod->visible);
 216  
 217                  if (isset($mod->redirect)) {
 218                      $SESSION->returnpage = $mod->redirecturl;
 219                  } else {
 220                      $SESSION->returnpage = "$CFG->wwwroot/mod/$mod->modulename/view.php?id=$mod->coursemodule";
 221                  }
 222  
 223                  add_to_log($course->id, "course", "add mod",
 224                             "../mod/$mod->modulename/view.php?id=$mod->coursemodule",
 225                             "$mod->modulename $mod->instance");
 226                  add_to_log($course->id, $mod->modulename, "add",
 227                             "view.php?id=$mod->coursemodule",
 228                             "$mod->instance", $mod->coursemodule);
 229                  break;
 230  
 231              case "delete":
 232                  if ($cm and $cw = get_record("course_sections", "id", $cm->section)) {
 233                      $sectionreturn = $cw->section;
 234                  }
 235  
 236                  if (! $deleteinstancefunction($mod->instance)) {
 237                      notify("Could not delete the $mod->modulename (instance)");
 238                  }
 239                  if (! delete_course_module($mod->coursemodule)) {
 240                      notify("Could not delete the $mod->modulename (coursemodule)");
 241                  }
 242                  if (! delete_mod_from_section($mod->coursemodule, "$mod->section")) {
 243                      notify("Could not delete the $mod->modulename from that section");
 244                  }
 245  
 246                  unset($SESSION->returnpage);
 247  
 248                  add_to_log($course->id, "course", "delete mod",
 249                             "view.php?id=$mod->course",
 250                             "$mod->modulename $mod->instance", $mod->coursemodule);
 251                  break;
 252              default:
 253                  error("No mode defined");
 254  
 255          }
 256  
 257          rebuild_course_cache($course->id);
 258  
 259          if (!empty($SESSION->returnpage)) {
 260              $return = $SESSION->returnpage;
 261              unset($SESSION->returnpage);
 262              redirect($return);
 263          } else {
 264              redirect("view.php?id=$course->id#section-$sectionreturn");
 265          }
 266          exit;
 267      }
 268  
 269      if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) {
 270  
 271          if (! $cm = get_record("course_modules", "id", $USER->activitycopy)) {
 272              error("The copied course module doesn't exist!");
 273          }
 274  
 275          if (!empty($movetosection)) {
 276              if (! $section = get_record("course_sections", "id", $movetosection)) {
 277                  error("This section doesn't exist");
 278              }
 279              $beforecm = NULL;
 280  
 281          } else {                      // normal moveto
 282              if (! $beforecm = get_record("course_modules", "id", $moveto)) {
 283                  error("The destination course module doesn't exist");
 284              }
 285              if (! $section = get_record("course_sections", "id", $beforecm->section)) {
 286                  error("This section doesn't exist");
 287              }
 288          }
 289  
 290          require_login($section->course); // needed to setup proper $COURSE
 291          $context = get_context_instance(CONTEXT_COURSE, $section->course);
 292          require_capability('moodle/course:manageactivities', $context);
 293  
 294          if (!ismoving($section->course)) {
 295              error("You need to copy something first!");
 296          }
 297  
 298          moveto_module($cm, $section, $beforecm);
 299  
 300          unset($USER->activitycopy);
 301          unset($USER->activitycopycourse);
 302          unset($USER->activitycopyname);
 303  
 304          rebuild_course_cache($section->course);
 305  
 306          if (SITEID == $section->course) {
 307              redirect($CFG->wwwroot);
 308          } else {
 309              redirect("view.php?id=$section->course#section-$sectionreturn");
 310          }
 311  
 312      } else if (!empty($indent) and confirm_sesskey()) {
 313  
 314          $id = required_param('id',PARAM_INT);
 315  
 316          if (! $cm = get_record("course_modules", "id", $id)) {
 317              error("This course module doesn't exist");
 318          }
 319  
 320          require_login($cm->course); // needed to setup proper $COURSE
 321          $context = get_context_instance(CONTEXT_COURSE, $cm->course);
 322          require_capability('moodle/course:manageactivities', $context);
 323  
 324          $cm->indent += $indent;
 325  
 326          if ($cm->indent < 0) {
 327              $cm->indent = 0;
 328          }
 329  
 330          if (!set_field("course_modules", "indent", $cm->indent, "id", $cm->id)) {
 331              error("Could not update the indent level on that course module");
 332          }
 333  
 334          if (SITEID == $cm->course) {
 335              redirect($CFG->wwwroot);
 336          } else {
 337              redirect("view.php?id=$cm->course#section-$sectionreturn");
 338          }
 339          exit;
 340  
 341      } else if (!empty($hide) and confirm_sesskey()) {
 342  
 343          if (! $cm = get_record("course_modules", "id", $hide)) {
 344              error("This course module doesn't exist");
 345          }
 346  
 347          require_login($cm->course); // needed to setup proper $COURSE
 348          $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 349          require_capability('moodle/course:activityvisibility', $context);
 350  
 351          set_coursemodule_visible($cm->id, 0);
 352  
 353          rebuild_course_cache($cm->course);
 354  
 355          if (SITEID == $cm->course) {
 356              redirect($CFG->wwwroot);
 357          } else {
 358              redirect("view.php?id=$cm->course#section-$sectionreturn");
 359          }
 360          exit;
 361  
 362      } else if (!empty($show) and confirm_sesskey()) {
 363  
 364          if (! $cm = get_record("course_modules", "id", $show)) {
 365              error("This course module doesn't exist");
 366          }
 367  
 368          require_login($cm->course); // needed to setup proper $COURSE
 369          $context = get_context_instance(CONTEXT_COURSE, $cm->course);
 370          require_capability('moodle/course:activityvisibility', $context);
 371  
 372          if (! $section = get_record("course_sections", "id", $cm->section)) {
 373              error("This module doesn't exist");
 374          }
 375  
 376          if (! $module = get_record("modules", "id", $cm->module)) {
 377              error("This module doesn't exist");
 378          }
 379  
 380          if ($module->visible and ($section->visible or (SITEID == $cm->course))) {
 381              set_coursemodule_visible($cm->id, 1);
 382              rebuild_course_cache($cm->course);
 383          }
 384  
 385          if (SITEID == $cm->course) {
 386              redirect($CFG->wwwroot);
 387          } else {
 388              redirect("view.php?id=$cm->course#section-$sectionreturn");
 389          }
 390          exit;
 391  
 392      } else if ($groupmode > -1 and confirm_sesskey()) {
 393  
 394          $id = required_param( 'id', PARAM_INT );
 395  
 396          if (! $cm = get_record("course_modules", "id", $id)) {
 397              error("This course module doesn't exist");
 398          }
 399  
 400          require_login($cm->course); // needed to setup proper $COURSE
 401          $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 402          require_capability('moodle/course:manageactivities', $context);
 403  
 404          set_coursemodule_groupmode($cm->id, $groupmode);
 405  
 406          rebuild_course_cache($cm->course);
 407  
 408          if (SITEID == $cm->course) {
 409              redirect($CFG->wwwroot);
 410          } else {
 411              redirect("view.php?id=$cm->course#section-$sectionreturn");
 412          }
 413          exit;
 414  
 415      } else if (!empty($copy) and confirm_sesskey()) { // value = course module
 416  
 417          if (! $cm = get_record("course_modules", "id", $copy)) {
 418              error("This course module doesn't exist");
 419          }
 420  
 421          require_login($cm->course); // needed to setup proper $COURSE
 422          $context = get_context_instance(CONTEXT_COURSE, $cm->course);
 423          require_capability('moodle/course:manageactivities', $context);
 424  
 425          if (! $section = get_record("course_sections", "id", $cm->section)) {
 426              error("This module doesn't exist");
 427          }
 428  
 429          if (! $module = get_record("modules", "id", $cm->module)) {
 430              error("This module doesn't exist");
 431          }
 432  
 433          if (! $instance = get_record($module->name, "id", $cm->instance)) {
 434              error("Could not find the instance of this module");
 435          }
 436  
 437          $USER->activitycopy = $copy;
 438          $USER->activitycopycourse = $cm->course;
 439          $USER->activitycopyname = $instance->name;
 440  
 441          redirect("view.php?id=$cm->course#section-$sectionreturn");
 442  
 443      } else if (!empty($cancelcopy) and confirm_sesskey()) { // value = course module
 444  
 445          $courseid = $USER->activitycopycourse;
 446  
 447          unset($USER->activitycopy);
 448          unset($USER->activitycopycourse);
 449          unset($USER->activitycopyname);
 450  
 451          redirect("view.php?id=$courseid#section-$sectionreturn");
 452  
 453      } else if (!empty($delete) and confirm_sesskey()) {   // value = course module
 454  
 455          if (! $cm = get_record("course_modules", "id", $delete)) {
 456              error("This course module doesn't exist");
 457          }
 458  
 459          if (! $course = get_record("course", "id", $cm->course)) {
 460              error("This course doesn't exist");
 461          }
 462  
 463          require_login($cm->course); // needed to setup proper $COURSE
 464          $context = get_context_instance(CONTEXT_COURSE, $cm->course);
 465          require_capability('moodle/course:manageactivities', $context);
 466  
 467          if (! $module = get_record("modules", "id", $cm->module)) {
 468              error("This module doesn't exist");
 469          }
 470  
 471          if (! $instance = get_record($module->name, "id", $cm->instance)) {
 472              // Delete this module from the course right away
 473              if (! delete_mod_from_section($cm->id, $cm->section)) {
 474                  notify("Could not delete the $module->name from that section");
 475              }
 476              if (! delete_course_module($cm->id)) {
 477                  notify("Could not delete the $module->name (coursemodule)");
 478              }
 479              error("The required instance of this module didn't exist.  Module deleted.",
 480                    "$CFG->wwwroot/course/view.php?id=$course->id");
 481          }
 482  
 483          $fullmodulename = get_string("modulename", $module->name);
 484  
 485          $form->coursemodule = $cm->id;
 486          $form->section      = $cm->section;
 487          $form->course       = $cm->course;
 488          $form->instance     = $cm->instance;
 489          $form->modulename   = $module->name;
 490          $form->fullmodulename  = $fullmodulename;
 491          $form->instancename = $instance->name;
 492          $form->sesskey      = !empty($USER->id) ? $USER->sesskey : '';
 493  
 494          $strdeletecheck = get_string('deletecheck', '', $form->fullmodulename);
 495          $strdeletecheckfull = get_string('deletecheckfull', '', "$form->fullmodulename '$form->instancename'");
 496  
 497          $CFG->pagepath = 'mod/'.$module->name.'/delete';
 498  
 499          print_header_simple($strdeletecheck, '', build_navigation(array(array('name'=>$strdeletecheck,'link'=>'','type'=>'misc'))));
 500  
 501          print_simple_box_start('center', '60%', '#FFAAAA', 20, 'noticebox');
 502          print_heading($strdeletecheckfull);
 503          include_once ('mod_delete.html');
 504          print_simple_box_end();
 505          print_footer($course);
 506  
 507          exit;
 508  
 509  
 510      } else if (!empty($update) and confirm_sesskey()) {   // value = course module
 511  
 512          if (! $cm = get_record("course_modules", "id", $update)) {
 513              error("This course module doesn't exist");
 514          }
 515  
 516          if (! $course = get_record("course", "id", $cm->course)) {
 517              error("This course doesn't exist");
 518          }
 519  
 520          require_login($course->id); // needed to setup proper $COURSE
 521          $context = get_context_instance(CONTEXT_COURSE, $course->id);
 522          require_capability('moodle/course:manageactivities', $context);
 523  
 524          if (! $module = get_record("modules", "id", $cm->module)) {
 525              error("This module doesn't exist");
 526          }
 527  
 528          if (! $form = get_record($module->name, "id", $cm->instance)) {
 529              error("The required instance of this module doesn't exist");
 530          }
 531  
 532          if (! $cw = get_record("course_sections", "id", $cm->section)) {
 533              error("This course section doesn't exist");
 534          }
 535  
 536          if (isset($return)) {
 537              $SESSION->returnpage = "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id";
 538          }
 539  
 540          $form->coursemodule = $cm->id;
 541          $form->section      = $cm->section;     // The section ID
 542          $form->course       = $course->id;
 543          $form->module       = $module->id;
 544          $form->modulename   = $module->name;
 545          $form->instance     = $cm->instance;
 546          $form->mode         = "update";
 547          $form->sesskey      = !empty($USER->id) ? $USER->sesskey : '';
 548  
 549          $sectionname = get_section_name($course->format);
 550          $fullmodulename = get_string("modulename", $module->name);
 551  
 552          if ($form->section && $course->format != 'site') {
 553              $heading->what = $fullmodulename;
 554              $heading->in   = "$sectionname $cw->section";
 555              $pageheading = get_string("updatingain", "moodle", $heading);
 556          } else {
 557              $pageheading = get_string("updatinga", "moodle", $fullmodulename);
 558          }
 559          $strnav = "<a href=\"$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id\">".format_string($form->name,true)."</a> ->";
 560  
 561          if ($module->name == 'resource') {
 562              $CFG->pagepath = 'mod/'.$module->name.'/'.$form->type;
 563          } else {
 564              $CFG->pagepath = 'mod/'.$module->name.'/mod';
 565          }
 566  
 567      } else if (!empty($duplicate) and confirm_sesskey()) {   // value = course module
 568  
 569  
 570          if (! $cm = get_record("course_modules", "id", $duplicate)) {
 571              error("This course module doesn't exist");
 572          }
 573  
 574          if (! $course = get_record("course", "id", $cm->course)) {
 575              error("This course doesn't exist");
 576          }
 577  
 578          require_login($course->id); // needed to setup proper $COURSE
 579          $context = get_context_instance(CONTEXT_COURSE, $course->id);
 580          require_capability('moodle/course:manageactivities', $context);
 581  
 582          if (! $module = get_record("modules", "id", $cm->module)) {
 583              error("This module doesn't exist");
 584          }
 585  
 586          if (! $form = get_record($module->name, "id", $cm->instance)) {
 587              error("The required instance of this module doesn't exist");
 588          }
 589  
 590          if (! $cw = get_record("course_sections", "id", $cm->section)) {
 591              error("This course section doesn't exist");
 592          }
 593  
 594          if (isset($return)) {
 595              $SESSION->returnpage = "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id";
 596          }
 597  
 598          $section = get_field('course_sections', 'section', 'id', $cm->section);
 599  
 600          $form->coursemodule = $cm->id;
 601          $form->section      = $section;     // The section ID
 602          $form->course       = $course->id;
 603          $form->module       = $module->id;
 604          $form->modulename   = $module->name;
 605          $form->instance     = $cm->instance;
 606          $form->mode         = "add";
 607          $form->sesskey      = !empty($USER->id) ? $USER->sesskey : '';
 608  
 609          $sectionname    = get_string("name$course->format");
 610          $fullmodulename = get_string("modulename", $module->name);
 611  
 612          if ($form->section) {
 613              $heading->what = $fullmodulename;
 614              $heading->in   = "$sectionname $cw->section";
 615              $pageheading = get_string("duplicatingain", "moodle", $heading);
 616          } else {
 617              $pageheading = get_string("duplicatinga", "moodle", $fullmodulename);
 618          }
 619          $strnav = "<a href=\"$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id\">$form->name</a> ->";
 620  
 621          $CFG->pagepath = 'mod/'.$module->name.'/mod';
 622  
 623  
 624      } else if (!empty($add) and confirm_sesskey()) {
 625  
 626          $id = required_param('id',PARAM_INT);
 627          $section = required_param('section',PARAM_INT);
 628  
 629          if (! $course = get_record("course", "id", $id)) {
 630              error("This course doesn't exist");
 631          }
 632  
 633          if (! $module = get_record("modules", "name", $add)) {
 634              error("This module type doesn't exist");
 635          }
 636  
 637          $context = get_context_instance(CONTEXT_COURSE, $course->id);
 638          require_capability('moodle/course:manageactivities', $context);
 639  
 640          if (!course_allowed_module($course,$module->id)) {
 641              error("This module has been disabled for this particular course");
 642          }
 643  
 644          require_login($course->id); // needed to setup proper $COURSE
 645  
 646          $form->section    = $section;         // The section number itself
 647          $form->course     = $course->id;
 648          $form->module     = $module->id;
 649          $form->modulename = $module->name;
 650          $form->instance   = "";
 651          $form->coursemodule = "";
 652          $form->mode       = "add";
 653          $form->sesskey    = !empty($USER->id) ? $USER->sesskey : '';
 654          if (!empty($type)) {
 655              $form->type = $type;
 656          }
 657  
 658          $sectionname    = get_string("name$course->format");
 659          $fullmodulename = get_string("modulename", $module->name);
 660  
 661          if ($form->section && $course->format != 'site') {
 662              $heading->what = $fullmodulename;
 663              $heading->to   = "$sectionname $form->section";
 664              $pageheading = get_string("addinganewto", "moodle", $heading);
 665          } else {
 666              $pageheading = get_string("addinganew", "moodle", $fullmodulename);
 667          }
 668  
 669          $CFG->pagepath = 'mod/'.$module->name;
 670          if (!empty($type)) {
 671              $CFG->pagepath .= '/' . $type;
 672          }
 673          else {
 674              $CFG->pagepath .= '/mod';
 675          }
 676  
 677      } else {
 678          error("No action was specified");
 679      }
 680  
 681      require_login($course->id); // needed to setup proper $COURSE
 682      $context = get_context_instance(CONTEXT_COURSE, $course->id);
 683      require_capability('moodle/course:manageactivities', $context);
 684  
 685      $streditinga = get_string("editinga", "moodle", $fullmodulename);
 686      $strmodulenameplural = get_string("modulenameplural", $module->name);
 687  
 688      if ($module->name == "label") {
 689          $focuscursor = "form.content";
 690      } else {
 691          $focuscursor = "form.name";
 692      }
 693  
 694      $navlinks = array();
 695      $navlinks[] = array('name' => $strmodulenameplural, 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id", 'type' => 'activity');
 696      $navlinks[] = array('name' => $streditinga, 'link' => '', 'type' => 'action');
 697      $navigation = build_navigation($navlinks);
 698  
 699      print_header_simple($streditinga, '', $navigation, $focuscursor, "", false);
 700  
 701      if (!empty($cm->id)) {
 702          $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 703          $currenttab = 'update';
 704          $overridableroles = get_overridable_roles($context);
 705          $assignableroles  = get_assignable_roles($context);
 706          include_once($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php');
 707      }
 708  
 709      unset($SESSION->modform); // Clear any old ones that may be hanging around.
 710  
 711      $modform = "../mod/$module->name/mod.html";
 712  
 713      if (file_exists($modform)) {
 714  
 715          if ($usehtmleditor = can_use_html_editor()) {
 716              $defaultformat = FORMAT_HTML;
 717              $editorfields = '';
 718          } else {
 719              $defaultformat = FORMAT_MOODLE;
 720          }
 721  
 722          $icon = '<img class="icon" src="'.$CFG->modpixpath.'/'.$module->name.'/icon.gif" alt="'.get_string('modulename',$module->name).'"/>';
 723  
 724          print_heading_with_help($pageheading, "mods", $module->name, $icon);
 725          print_simple_box_start('center', '', '', 5, 'generalbox', $module->name);
 726          include_once($modform);
 727          print_simple_box_end();
 728  
 729          if ($usehtmleditor and empty($nohtmleditorneeded)) {
 730              use_html_editor($editorfields);
 731          }
 732  
 733      } else {
 734          notice("This module cannot be added to this course yet! (No file found at: $modform)", "$CFG->wwwroot/course/view.php?id=$course->id");
 735      }
 736  
 737      print_footer($course);
 738  ?>


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