Your session has most likely timed out.

Your session has most likely timed out.

by Larry Herbison -
Number of replies: 0

The following code is for cloning current courses to master copies prior to a new semester.

  • If the "goto" button is clicked, it works. (Doesn't really do anything, but it doesn't crash.)
  • If the "clone" button is clicked, I get the "Your session has most likely timed out" screen. I can't tell where the error occurs because I can't get any echoes to show. I have commented out the entire "do something" chunk of code with no change, so that's not suspect.

Ideas?

popup.php:

	require_once('../../config.php');
  require_once('popup_form.php');

  global $DB, $CFG, $OUTPUT;

  require_login();

  $PAGE->set_context(context_system::instance());
  $PAGE->set_url('/blocks/mastercloner/popup.php');
  $PAGE->set_pagelayout('popup');
  $PAGE->set_title(get_string('mastercloner', 'block_mastercloner'));
  $PAGE->set_heading(get_string('mastercloner', 'block_mastercloner'));

  //-------- process the form --------

  $mform = new popup_form();

  if(!$mform->is_cancelled()) {
    $formdata = $mform->get_data();
    echo "formdata:".json_encode($formdata);

    //-------- clone
    if($formdata && isset($formdata->clone) 
        && $formdata->clone == get_string('clonecourses', 'block_mastercloner')) {
      /*
        Do something here, omitted for brevity
      */	
    }
    //-------- get category
    if($formdata && isset($formdata->goto) && $formdata->post == get_string('goto', 'block_mastercloner')) {
      // nothing to do here
    }
  }

  //-------- populate the form --------

  if($msg) {
    redirect('/blocks/masterclone/popup.php', $msg, null, 
      \core\output\notification::NOTIFY_INFO);
  }

  $cdata = [];
  $cdata['sourcecategoryid'] = $formdata->sourcecategoryid;

  $mform = new popup_form(null, $cdata, 'post');

  echo $OUTPUT->header();
  $mform->set_data($formdata);
  $mform->display();
  echo $OUTPUT->footer();

popup_form.php:

  if(!defined('MOODLE_INTERNAL')) {
    die('Direct access to this script is forbidden.');	///  It must be included from a Moodle page
  }

  require_once $CFG->libdir.'/formslib.php';

  class popup_form extends moodleform {
    // recursively load categories
    static function load_categories($parent, $name, &$categories) {
      global $DB;
      $children = $DB->get_records('course_categories',
        array('parent' => $parent), 'sortorder', 'id,name');
      foreach($children as $child) {
        $child->fullname = $name.' / '.$child->name;
        $categories[$child->id] = $child->fullname;
        self::load_categories($child->id, $child->fullname, $categories);
      }
    }

    function definition() {
      global $CFG, $COURSE, $USER, $DB;

      $mform =& $this->_form;
      $cdata = $this->_customdata;

      $mform->addElement('header', 'mainheader', 'Clone to Master Copy');
      $mform->setExpanded('mainheader');

      // re for prefix to strip from course name
      $mform->addElement('text', 'prefixmask', get_string('prefixmask', 'block_mastercloner'), 'size="24"');
      $mform->setType('prefixmask', PARAM_TEXT);

      // new 'master copy' suffix to add to course name  
      $mform->addElement('text', 'suffix', get_string('suffix', 'block_mastercloner'), 'size="24"');
      $mform->setType('suffix', PARAM_TEXT);

      // keep_term checkbox for programs that use the same classes
      // for unique terms  
      $mform->addElement('advcheckbox', 'keepterms', get_string('keepterms', 'block_mastercloner'), '', '', null, [0, 1]);
      $mform->setType('keepterms', PARAM_TEXT);

      // course categories
      // get categories
      $categories = array();
      self::load_categories(0, '', $categories);

      // destination
      $mform->addElement('select', 'destinationcategoryid', get_string('destinationcategory', 'block_mastercloner'), $categories);

      // source
      $mform->addElement('select', 'sourcecategoryid', get_string('sourcecategory', 'block_mastercloner'), $categories);

      // go to button
      $mform->addElement('submit', 'goto', get_string('goto', 'block_mastercloner'));
      
      // clone button
      $mform->addElement('submit', 'clone', get_string('clonecourses', 'block_mastercloner'));

      // courses
      if($cdata['sourcecategoryid']) {
        // get courses in 'source' category
        $courses = $DB->get_records('course', ['category' => $cdata['sourcecategoryid']], 'fullname', 'id,fullname');
        $lineno = 0;
        foreach($courses as $course) {
          ++$lineno;
          $mform->addElement('checkbox', "use$lineno", $course->fullname);
          $mform->addElement('hidden', "courseid$lineno", $course->id);
        }

        $mform->addElement('hidden', 'lines', $lineno);
      }
    }

    public function reset() {
      $this->_form->updateSubmission(null, null);
    }

  }


Average of ratings: -