Example #1
0
/**
 * Shows the question bank editing interface.
 *
 * The function also processes a number of actions:
 *
 * Actions affecting the question pool:
 * move           Moves a question to a different category
 * deleteselected Deletes the selected questions from the category
 * Other actions:
 * category      Chooses the category
 * displayoptions Sets display options
 *
 * @author Martin Dougiamas and many others. This has recently been extensively
 *         rewritten by Gustav Delius and other members of the Serving Mathematics project
 *         {@link http://maths.york.ac.uk/serving_maths}
 * @param moodle_url $pageurl object representing this pages url.
 */
function question_showbank($tabname, $contexts, $pageurl, $cm, $page, $perpage, $sortorder, $sortorderdecoded, $cat, $recurse, $showhidden, $showquestiontext)
{
    global $COURSE;
    if (optional_param('deleteselected', false, PARAM_BOOL)) {
        // teacher still has to confirm
        // make a list of all the questions that are selected
        $rawquestions = $_REQUEST;
        // This code is called by both POST forms and GET links, so cannot use data_submitted.
        $questionlist = '';
        // comma separated list of ids of questions to be deleted
        $questionnames = '';
        // string with names of questions separated by <br /> with
        // an asterix in front of those that are in use
        $inuse = false;
        // set to true if at least one of the questions is in use
        foreach ($rawquestions as $key => $value) {
            // Parse input for question ids
            if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
                $key = $matches[1];
                $questionlist .= $key . ',';
                question_require_capability_on($key, 'edit');
                if (record_exists('quiz_question_instances', 'question', $key)) {
                    $questionnames .= '* ';
                    $inuse = true;
                }
                $questionnames .= get_field('question', 'name', 'id', $key) . '<br />';
            }
        }
        if (!$questionlist) {
            // no questions were selected
            redirect($pageurl->out());
        }
        $questionlist = rtrim($questionlist, ',');
        // Add an explanation about questions in use
        if ($inuse) {
            $questionnames .= '<br />' . get_string('questionsinuse', 'quiz');
        }
        notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames), $pageurl->out_action(), $pageurl->out(true), array('deleteselected' => $questionlist, 'confirm' => md5($questionlist)), $pageurl->params(), 'post', 'get');
        echo '</td></tr>';
        echo '</table>';
        print_footer($COURSE);
        exit;
    }
    // starts with category selection form
    print_box_start('generalbox questionbank');
    print_heading(get_string('questionbank', 'question'), '', 2);
    question_category_form($contexts->having_one_edit_tab_cap($tabname), $pageurl, $cat, $recurse, $showhidden, $showquestiontext);
    // continues with list of questions
    question_list($contexts->having_one_edit_tab_cap($tabname), $pageurl, $cat, isset($cm) ? $cm : null, $recurse, $page, $perpage, $showhidden, $sortorder, $sortorderdecoded, $showquestiontext, $contexts->having_cap('moodle/question:add'));
    print_box_end();
}
Example #2
0
function memorization_print_view_method7week_mobile($userid)
{
    global $CFG;
    $verseconditions = array();
    $verseconditions['day'] = "(repetitions >= '" . MEMORIZATION_VERSE_DAY_LOWER . "' \n                               AND repetitions < '" . MEMORIZATION_VERSE_DAY_UPPER . "' \n                               AND timemodified < '" . strtotime('midnight') . "')";
    $verseconditions['week'] = "(repetitions >= '" . MEMORIZATION_VERSE_WEEK_LOWER . "' \n                                AND repetitions < '" . MEMORIZATION_VERSE_WEEK_UPPER . "' \n                                AND timemodified < '" . strtotime('last monday midnight') . "')";
    $verseconditions['month'] = "(repetitions >= '" . MEMORIZATION_VERSE_MONTH_LOWER . "' \n                                 AND repetitions < '" . MEMORIZATION_VERSE_MONTH_UPPER . "' \n                                 AND timemodified < '" . strtotime('first day of this month midnight') . "')";
    $verseconditions['quarterly'] = "(repetitions >= '" . MEMORIZATION_VERSE_LIFE_LOWER . "' \n                                     AND repetitions < '" . MEMORIZATION_VERSE_LIFE_UPPER . "' \n                                     AND timemodified < '" . strtotime('midnight 3 months ago') . "')";
    $verseconditionsstring = '(' . implode(' OR ', $verseconditions) . ')';
    $versesrs = get_recordset_select('memorization_verse', "userid = '{$userid}' AND {$verseconditionsstring}", 'repetitions ASC');
    print_box_start('day-verses mobilebox');
    while (($verse = rs_fetch_next_record($versesrs)) !== false) {
        switch (true) {
            case $verse->repetitions >= MEMORIZATION_VERSE_LIFE_LOWER:
                if (!isset($tabprinted[MEMORIZATION_VERSE_LIFE_LOWER])) {
                    print_box(get_string('quarterlyverses', 'memorization'), 'quarter-verse-title generalbox mobilebox');
                    $tabprinted[MEMORIZATION_VERSE_MONTH_LOWER] = true;
                }
                break;
            case $verse->repetitions >= MEMORIZATION_VERSE_MONTH_LOWER:
                if (!isset($tabprinted[MEMORIZATION_VERSE_MONTH_LOWER])) {
                    print_box(get_string('monthverses', 'memorization'), 'month-verse-title generalbox mobilebox');
                    $tabprinted[MEMORIZATION_VERSE_MONTH_LOWER] = true;
                }
                break;
            case $verse->repetitions >= MEMORIZATION_VERSE_WEEK_LOWER:
                if (!isset($tabprinted[MEMORIZATION_VERSE_WEEK_LOWER])) {
                    print_box(get_string('weekverses', 'memorization'), 'week-verse-title generalbox mobilebox');
                    $tabprinted[MEMORIZATION_VERSE_WEEK_LOWER] = true;
                }
                break;
            case $verse->repetitions >= MEMORIZATION_VERSE_DAY_LOWER:
                if (!isset($tabprinted[MEMORIZATION_VERSE_DAY_LOWER])) {
                    $url = new moodle_url('addverse.php', array('userid' => $userid));
                    print_box(get_string('dayverses', 'memorization') . '<div class="add-verse"><a href="' . $url->out_action() . '"><img src="' . $CFG->wwwroot . '/mod/memorization/pix/new.png" /></a></div>', 'day-verse-title generalbox mobilebox');
                    $tabprinted[MEMORIZATION_VERSE_DAY_LOWER] = true;
                }
                break;
        }
        $completion = !empty($verse->repetitions) ? 100 - $verse->repetitions / MEMORIZATION_COMPLETE * 100 : 100;
        echo '<table class="memorization-verse" id="memorization-verse-' . $verse->id . '">
                <tr>
                   <td class="hint"><a class="my-message-box" x="350" y="500" href="ajaxversedisplay.php?verseid=' . $verse->id . '&userid=' . $userid . '&sesskey=' . sesskey() . '"><img src="' . $CFG->wwwroot . '/mod/memorization/pix/bulb.png" /></a></td>
                   <td class="verse">
                        ' . _get_verse_text($verse) . '
                        <div class="progress" style="right: ' . $completion . '%;">&nbsp;</div>
                   </td>
                   <td class="check" id="' . $verse->id . '-' . ($verse->repetitions + 1) . '"> <img src="' . $CFG->pixpath . '/i/tick_green_big.gif" /></td>
                 </tr>
              </table>';
    }
    print_box_end();
    echo '<script type="text/javascript">
            jQuery(document).ready(function () {
                function parse_verse_id_from_repetion_box(elementid) {
                    return elementid.replace(/\\-[0-9]*$/, "");
                }

                function parse_repetition(elementid) {
                    return elementid.replace(/[0-9]+?\\-/, "");
                }

                function parse_verse_id_from_move_to_link(elementid) {
                    firststrip = elementid.replace(/move\\-verse\\-/, "");
                    return firststrip.replace(/\\-[0-9]*$/, "");
                }

                function parse_repetition_value_from_move_to_link(elementid) {
                    return elementid.replace(/.*\\-/, "");
                }

                function update_verse_in_database(verseid, newrepetition) {
                    jQuery.ajax({
                       type: "POST",
                       url: "ajaxupdateverserepetition.php",
                       data: "sesskey=' . sesskey() . '&userid=' . $userid . '&verseid="+verseid+"&newrepetition="+newrepetition,
                     });
                }

                jQuery("td.check").click(function () {
                    newrepetition = parse_repetition(jQuery(this).attr("id"));
                    verseid = parse_verse_id_from_repetion_box(jQuery(this).attr("id"));
                    update_verse_in_database(verseid, newrepetition);
                    jQuery("table#memorization-verse-"+verseid).fadeOut(800);
                });
            });
          </script>';
    return true;
}