Example #1
0
 public function construction_override($pageid, lesson $lesson)
 {
     global $CFG, $PAGE, $DB;
     require_sesskey();
     $timenow = time();
     // the new page is not the first page (end of cluster always comes after an existing page)
     if (!($page = $DB->get_record("lesson_pages", array("id" => $pageid)))) {
         print_error('cannotfindpages', 'lesson');
     }
     // could put code in here to check if the user really can insert an end of cluster
     $newpage = new stdClass();
     $newpage->lessonid = $lesson->id;
     $newpage->prevpageid = $pageid;
     $newpage->nextpageid = $page->nextpageid;
     $newpage->qtype = $this->qtype;
     $newpage->timecreated = $timenow;
     $newpage->title = get_string("endofclustertitle", "lesson");
     $newpage->contents = get_string("endofclustertitle", "lesson");
     $newpageid = $DB->insert_record("lesson_pages", $newpage);
     // update the linked list...
     $DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid));
     if ($page->nextpageid) {
         // the new page is not the last page
         $DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid));
     }
     // ..and the single "answer"
     $newanswer = new stdClass();
     $newanswer->lessonid = $lesson->id;
     $newanswer->pageid = $newpageid;
     $newanswer->timecreated = $timenow;
     $newanswer->jumpto = LESSON_NEXTPAGE;
     $newanswerid = $DB->insert_record("lesson_answers", $newanswer);
     $lesson->add_message(get_string('addedendofcluster', 'lesson'), 'notifysuccess');
     redirect($CFG->wwwroot . '/mod/lesson/edit.php?id=' . $PAGE->cm->id);
 }
 public function construction_override($pageid, lesson $lesson)
 {
     global $DB, $CFG, $PAGE;
     require_sesskey();
     // first get the preceeding page
     $timenow = time();
     // the new page is not the first page (end of branch always comes after an existing page)
     if (!($page = $DB->get_record("lesson_pages", array("id" => $pageid)))) {
         print_error('cannotfindpagerecord', 'lesson');
     }
     // chain back up to find the (nearest branch table)
     $btpage = clone $page;
     $btpageid = $btpage->id;
     while ($btpage->qtype != LESSON_PAGE_BRANCHTABLE && $btpage->prevpageid > 0) {
         $btpageid = $btpage->prevpageid;
         if (!($btpage = $DB->get_record("lesson_pages", array("id" => $btpageid)))) {
             print_error('cannotfindpagerecord', 'lesson');
         }
     }
     if ($btpage->qtype == LESSON_PAGE_BRANCHTABLE) {
         $newpage = new stdClass();
         $newpage->lessonid = $lesson->id;
         $newpage->prevpageid = $pageid;
         $newpage->nextpageid = $page->nextpageid;
         $newpage->qtype = $this->qtype;
         $newpage->timecreated = $timenow;
         $newpage->title = get_string("endofbranch", "lesson");
         $newpage->contents = get_string("endofbranch", "lesson");
         $newpageid = $DB->insert_record("lesson_pages", $newpage);
         // update the linked list...
         $DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid));
         if ($page->nextpageid) {
             // the new page is not the last page
             $DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid));
         }
         // ..and the single "answer"
         $newanswer = new stdClass();
         $newanswer->lessonid = $lesson->id;
         $newanswer->pageid = $newpageid;
         $newanswer->timecreated = $timenow;
         $newanswer->jumpto = $btpageid;
         $newanswerid = $DB->insert_record("lesson_answers", $newanswer);
         $lesson->add_message(get_string('addedanendofbranch', 'lesson'), 'notifysuccess');
     } else {
         $lesson->add_message(get_string('nobranchtablefound', 'lesson'));
     }
     redirect($CFG->wwwroot . "/mod/lesson/edit.php?id=" . $PAGE->cm->id);
 }
Example #3
0
switch ($mode) {
    case 'add':
        // Ensure that we came from view.php
        if (!confirm_sesskey() or !data_submitted()) {
            print_error('invalidformdata');
        }
        break;

    case 'save':
        if (confirm_sesskey() and $form = data_submitted($CFG->wwwroot.'/mod/lesson/view.php')) {
            $name = trim(optional_param('name', '', PARAM_CLEAN));

            // Make sure it is not empty
            if (empty($name)) {
                $lesson->add_message(get_string('missingname', 'lesson'));
                $mode = 'add';
                break;
            }
            // Check for censored words
            $filterwords = explode(',', get_string('censorbadwords'));
            foreach ($filterwords as $filterword) {
                if (strstr($name, $filterword)) {
                    $lesson->add_message(get_string('namereject', 'lesson'));
                    $mode = 'add';
                    break;
                }
            }
            // Bad word was found
            if ($mode == 'add') {
                break;
Example #4
0
 public function construction_override($pageid, lesson $lesson)
 {
     global $PAGE, $CFG, $DB;
     require_sesskey();
     $timenow = time();
     if ($pageid == 0) {
         if ($lesson->has_pages()) {
             if (!($page = $DB->get_record("lesson_pages", array("prevpageid" => 0, "lessonid" => $lesson->id)))) {
                 print_error('cannotfindpagerecord', 'lesson');
             }
         } else {
             // This is the ONLY page
             $page = new stdClass();
             $page->id = 0;
         }
     } else {
         if (!($page = $DB->get_record("lesson_pages", array("id" => $pageid)))) {
             print_error('cannotfindpagerecord', 'lesson');
         }
     }
     $newpage = new stdClass();
     $newpage->lessonid = $lesson->id;
     $newpage->prevpageid = $pageid;
     if ($pageid != 0) {
         $newpage->nextpageid = $page->nextpageid;
     } else {
         $newpage->nextpageid = $page->id;
     }
     $newpage->qtype = $this->qtype;
     $newpage->timecreated = $timenow;
     $newpage->title = get_string("clustertitle", "lesson");
     $newpage->contents = get_string("clustertitle", "lesson");
     $newpageid = $DB->insert_record("lesson_pages", $newpage);
     // update the linked list...
     if ($pageid != 0) {
         $DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid));
     }
     if ($pageid == 0) {
         $page->nextpageid = $page->id;
     }
     if ($page->nextpageid) {
         // the new page is not the last page
         $DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid));
     }
     // ..and the single "answer"
     $newanswer = new stdClass();
     $newanswer->lessonid = $lesson->id;
     $newanswer->pageid = $newpageid;
     $newanswer->timecreated = $timenow;
     $newanswer->jumpto = LESSON_CLUSTERJUMP;
     $newanswerid = $DB->insert_record("lesson_answers", $newanswer);
     $lesson->add_message(get_string('addedcluster', 'lesson'), 'notifysuccess');
     redirect($CFG->wwwroot . '/mod/lesson/edit.php?id=' . $PAGE->cm->id);
 }