Beispiel #1
0
function memorization_print_new_verse_box()
{
    global $CFG, $USER;
    print_box_start('add-verse-box generalbox box');
    print_heading(get_string('newverse', 'memorization'));
    $biblebooks = biblebooks_array();
    // create the book selector
    $biblebookoptions = '';
    foreach ($biblebooks as $booknumber => $bookofbible) {
        if ($booknumber == 0) {
            continue;
        }
        $biblebookoptions .= '<option value="' . $booknumber . '">' . $bookofbible . '</option>';
    }
    $startbookid = '<select name="startbookid">' . $biblebookoptions . '</select>';
    $endbookid = '<select name="endbookid">' . $biblebookoptions . '</select>';
    // create the chapter inputs
    $startchapter = '<input type="text" name="startchapter" size="5" />';
    $endchapter = '<input type="text" name="endchapter" size="5"/>';
    // create the verse inputs
    $startverse = '<input type="text" name="startverse" size="5"/>';
    $endverse = '<input type="text" name="endverse" size="5"/>';
    // create the version chooser
    $versions = get_records('memorization_version');
    if (!empty($versions)) {
        $versionselect = '<select name="versionid">';
        $lastversionid = get_field_sql("SELECT versionid FROM {$CFG->prefix}memorization_verse WHERE userid={$USER->id} ORDER BY id DESC");
        foreach ($versions as $versionid => $version) {
            $selected = $versionid == $lastversionid ? ' SELECTED="selected" ' : '';
            $versionselect .= '<option ' . $selected . ' value="' . $versionid . '">' . $version->value . '</option>';
        }
        $versionselect .= '</select>';
    }
    $currenturl = new moodle_url(qualified_me());
    echo '<form method="POST" action="addverse.php?' . $currenturl->get_query_string() . '">
          <input type="hidden" name="sesskey" value="' . sesskey() . '">
          <table>
            <tr>
              <td>' . get_string('fromverse', 'memorization') . '</td>
              <td>' . $startbookid . ' ' . $startchapter . ':' . $startverse . '</td>
            </tr>

            <tr>
              <td>' . get_string('toverse', 'memorization') . '</td>
              <td>' . $endbookid . ' ' . $endchapter . ':' . $endverse . '</td>
            </tr>

            <tr>
              <td>' . get_string('version', 'memorization') . '</td>
              <td>' . $versionselect . '</td>
            </tr>
          </table>
          <input type="submit">
          </form>';
    print_box_end();
}
Beispiel #2
0
 /**
  * Handle adding a block.
  * @return boolean true if anything was done. False if not.
  */
 public function process_url_add()
 {
     global $CFG, $PAGE, $OUTPUT;
     $blocktype = optional_param('bui_addblock', null, PARAM_PLUGIN);
     if ($blocktype === null) {
         return false;
     }
     require_sesskey();
     if (!$this->page->user_can_edit_blocks()) {
         throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('addblock'));
     }
     $addableblocks = $this->get_addable_blocks();
     if ($blocktype === '') {
         // Display add block selection.
         $addpage = new moodle_page();
         $addpage->set_pagelayout('admin');
         $addpage->blocks->show_only_fake_blocks(true);
         $addpage->set_course($this->page->course);
         $addpage->set_context($this->page->context);
         if ($this->page->cm) {
             $addpage->set_cm($this->page->cm);
         }
         $addpagebase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
         $addpageparams = $this->page->url->params();
         $addpage->set_url($addpagebase, $addpageparams);
         $addpage->set_block_actions_done();
         // At this point we are going to display the block selector, overwrite global $PAGE ready for this.
         $PAGE = $addpage;
         // Some functions use $OUTPUT so we need to replace that too.
         $OUTPUT = $addpage->get_renderer('core');
         $site = get_site();
         $straddblock = get_string('addblock');
         $PAGE->navbar->add($straddblock);
         $PAGE->set_title($straddblock);
         $PAGE->set_heading($site->fullname);
         echo $OUTPUT->header();
         echo $OUTPUT->heading($straddblock);
         if (!$addableblocks) {
             echo $OUTPUT->box(get_string('noblockstoaddhere'));
             echo $OUTPUT->container($OUTPUT->action_link($addpage->url, get_string('back')), 'm-x-3 m-b-1');
         } else {
             $url = new moodle_url($addpage->url, array('sesskey' => sesskey()));
             echo $OUTPUT->render_from_template('core/add_block_body', ['blocks' => array_values($addableblocks), 'url' => '?' . $url->get_query_string(false)]);
             echo $OUTPUT->container($OUTPUT->action_link($addpage->url, get_string('cancel')), 'm-x-3 m-b-1');
         }
         echo $OUTPUT->footer();
         // Make sure that nothing else happens after we have displayed this form.
         exit;
     }
     if (!array_key_exists($blocktype, $addableblocks)) {
         throw new moodle_exception('cannotaddthisblocktype', '', $this->page->url->out(), $blocktype);
     }
     $this->add_block_at_end_of_default_region($blocktype);
     // If the page URL was a guess, it will contain the bui_... param, so we must make sure it is not there.
     $this->page->ensure_param_not_in_url('bui_addblock');
     return true;
 }
Beispiel #3
0
}
// if we have a verse to save then save or confirm it is correct
if (optional_param('startbookid', false, PARAM_INT) !== false) {
    $startbookid = required_param('startbookid', PARAM_INT);
    $startchapter = required_param('startchapter', PARAM_INT);
    $startverse = required_param('startverse', PARAM_INT);
    $endbookid = required_param('endbookid', PARAM_INT);
    $endchapter = required_param('endchapter', PARAM_INT);
    $endverse = required_param('endverse', PARAM_INT);
    $versionid = required_param('versionid', PARAM_INT);
    $currenturl = new moodle_url(qualified_me());
    $currenturl->params(array('startbookid' => $startbookid, 'startchapter' => $startchapter, 'startverse' => $startverse, 'endbookid' => $endbookid, 'endchapter' => $endchapter, 'endverse' => $endverse, 'versionid' => $versionid, 'sesskey' => sesskey()));
    $versetext = lookup_bible_verse($versionid, $startbookid, $startchapter, $startverse, $endbookid, $endchapter, $endverse);
    if (!optional_param('confirm', 0, PARAM_BOOL)) {
        $linkyes = $currenturl->out(false, array('confirm' => '1'));
        $linkno = $CFG->wwwroot . '/mod/memorization/view.php?' . $currenturl->get_query_string();
        $message = '<div class="confirm-verse">' . get_string('confirmverse', 'memorization') . '</div>' . '<div class="verse">' . $versetext . '</div>';
        print_header_simple(get_string('notice'));
        notice_yesno($message, $linkyes, $linkno);
        print_footer();
        exit;
    }
    $versionname = get_field('memorization_version', 'name', 'id', $versionid);
    $verse = (object) array('userid' => $userid, 'startbookid' => $startbookid, 'startchapter' => $startchapter, 'startverse' => $startverse, 'endbookid' => $endbookid, 'endchapter' => $endchapter, 'endverse' => $endverse, 'text' => $versetext, 'versionid' => $versionid, 'repetitions' => 0);
    $verse = addslashes_recursive($verse);
    if (!insert_record('memorization_verse', $verse)) {
        print_header();
        error('There was an error adding your verse. Please try again');
    }
    redirect('view.php?' . $currenturl->get_query_string());
}