当前位置: 首页>>代码示例>>PHP>>正文


PHP require_sesskey函数代码示例

本文整理汇总了PHP中require_sesskey函数的典型用法代码示例。如果您正苦于以下问题:PHP require_sesskey函数的具体用法?PHP require_sesskey怎么用?PHP require_sesskey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了require_sesskey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check_answer

 public function check_answer()
 {
     global $DB, $CFG;
     $formattextdefoptions = new stdClass();
     $formattextdefoptions->noclean = true;
     $formattextdefoptions->para = false;
     $answers = $this->get_answers();
     shuffle($answers);
     $params = array('answers' => $answers, 'lessonid' => $this->lesson->id, 'contents' => $this->get_contents());
     $mform = new lesson_display_answer_form_truefalse($CFG->wwwroot . '/mod/lesson/continue.php', $params);
     $data = $mform->get_data();
     require_sesskey();
     $result = parent::check_answer();
     if (empty($data->answerid)) {
         $result->noanswer = true;
         return $result;
     }
     $result->answerid = $data->answerid;
     $answer = $DB->get_record("lesson_answers", array("id" => $result->answerid), '*', MUST_EXIST);
     if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
         $result->correctanswer = true;
     }
     if ($this->lesson->custom) {
         if ($answer->score > 0) {
             $result->correctanswer = true;
         } else {
             $result->correctanswer = false;
         }
     }
     $result->newpageid = $answer->jumpto;
     $result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
     $result->studentanswer = $result->userresponse = $answer->answer;
     return $result;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:34,代码来源:truefalse.php

示例2: check_answer

    public function check_answer() {
        global $CFG;
        $result = parent::check_answer();

        $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents()));
        $data = $mform->get_data();
        require_sesskey();

        $formattextdefoptions = new stdClass();
        $formattextdefoptions->noclean = true;
        $formattextdefoptions->para = false;

        // set defaults
        $result->response = '';
        $result->newpageid = 0;

        if (!isset($data->answer) || !is_numeric($data->answer)) {
            $result->noanswer = true;
            return $result;
        } else {
            // Just doing default PARAM_RAW, not doing PARAM_INT because it could be a float.
            $result->useranswer = (float)$data->answer;
        }
        $result->studentanswer = $result->userresponse = $result->useranswer;
        $answers = $this->get_answers();
        foreach ($answers as $answer) {
            $answer = parent::rewrite_answers_urls($answer);
            if (strpos($answer->answer, ':')) {
                // there's a pairs of values
                list($min, $max) = explode(':', $answer->answer);
                $minimum = (float) $min;
                $maximum = (float) $max;
            } else {
                // there's only one value
                $minimum = (float) $answer->answer;
                $maximum = $minimum;
            }
            if (($result->useranswer >= $minimum) && ($result->useranswer <= $maximum)) {
                $result->newpageid = $answer->jumpto;
                $result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
                if ($this->lesson->jumpto_is_correct($this->properties->id, $result->newpageid)) {
                    $result->correctanswer = true;
                }
                if ($this->lesson->custom) {
                    if ($answer->score > 0) {
                        $result->correctanswer = true;
                    } else {
                        $result->correctanswer = false;
                    }
                }
                $result->answerid = $answer->id;
                return $result;
            }
        }
        return $result;
    }
开发者ID:rezaies,项目名称:moodle,代码行数:56,代码来源:numerical.php

示例3: addsection_action

 /**
  * Add a new section with the provided title and (optional) summary
  *
  * @return string
  */
 public function addsection_action()
 {
     global $CFG, $PAGE, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     $sectioname = required_param('newsection', PARAM_TEXT);
     $summary = optional_param('summary', '', PARAM_RAW);
     require_sesskey();
     $courseid = $PAGE->context->get_course_context()->instanceid;
     $course = course_get_format($courseid)->get_course();
     $course->numsections++;
     course_get_format($course)->update_course_format_options(array('numsections' => $course->numsections));
     course_create_sections_if_missing($course, range(0, $course->numsections));
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info($course->numsections, MUST_EXIST);
     $DB->set_field('course_sections', 'name', $sectioname, array('id' => $section->id));
     $DB->set_field('course_sections', 'summary', $summary, array('id' => $section->id));
     $DB->set_field('course_sections', 'summaryformat', FORMAT_HTML, array('id' => $section->id));
     rebuild_course_cache($course->id);
     redirect(course_get_url($course, $section->section));
 }
开发者ID:nadavkav,项目名称:moodle-theme_snap,代码行数:25,代码来源:addsection_controller.php

示例4: flag_action

 /**
  * Toggle Post Flags
  */
 public function flag_action()
 {
     global $DB;
     require_sesskey();
     $postid = required_param('postid', PARAM_INT);
     $flag = required_param('flag', PARAM_ALPHA);
     $returnurl = required_param('returnurl', PARAM_LOCALURL);
     $flags = $DB->get_field('hsuforum_posts', 'flags', array('id' => $postid), MUST_EXIST);
     $flaglib = new \hsuforum_lib_flag();
     $newflags = $flaglib->toggle_flag($flags, $flag);
     if ($newflags != $flags) {
         $updateok = $DB->set_field('hsuforum_posts', 'flags', $newflags, array('id' => $postid));
         if (AJAX_SCRIPT && !$updateok) {
             http_response_code(500);
         }
     }
     if (!AJAX_SCRIPT) {
         redirect(new \moodle_url($returnurl));
     }
 }
开发者ID:cdsmith-umn,项目名称:moodle-mod_hsuforum,代码行数:23,代码来源:flag_controller.php

示例5: process_add_attempt

 /**
  * Check for a sess key and then call add_attempt.
  *
  * @param int $userid int The user to add the attempt for
  * @return bool - true if successful.
  */
 protected function process_add_attempt($userid)
 {
     require_sesskey();
     return $this->add_attempt($userid);
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:11,代码来源:locallib.php

示例6: process_url_move

 /**
  * Handle showing/processing the submission from the block editing form.
  * @return boolean true if the form was submitted and the new config saved. Does not
  *      return if the editing form was displayed. False otherwise.
  */
 public function process_url_move()
 {
     global $CFG, $DB, $PAGE;
     $blockid = optional_param('bui_moveid', null, PARAM_INT);
     if (!$blockid) {
         return false;
     }
     require_sesskey();
     $block = $this->find_instance($blockid);
     if (!$this->page->user_can_edit_blocks()) {
         throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock'));
     }
     $newregion = optional_param('bui_newregion', '', PARAM_ALPHANUMEXT);
     $newweight = optional_param('bui_newweight', null, PARAM_FLOAT);
     if (!$newregion || is_null($newweight)) {
         // Don't have a valid target position yet, must be just starting the move.
         $this->movingblock = $blockid;
         $this->page->ensure_param_not_in_url('bui_moveid');
         return false;
     }
     if (!$this->is_known_region($newregion)) {
         throw new moodle_exception('unknownblockregion', '', $this->page->url, $newregion);
     }
     // Move this block. This may involve moving other nearby blocks.
     $blocks = $this->birecordsbyregion[$newregion];
     $maxweight = self::MAX_WEIGHT;
     $minweight = -self::MAX_WEIGHT;
     // Initialise the used weights and spareweights array with the default values
     $spareweights = array();
     $usedweights = array();
     for ($i = $minweight; $i <= $maxweight; $i++) {
         $spareweights[$i] = $i;
         $usedweights[$i] = array();
     }
     // Check each block and sort out where we have used weights
     foreach ($blocks as $bi) {
         if ($bi->weight > $maxweight) {
             // If this statement is true then the blocks weight is more than the
             // current maximum. To ensure that we can get the best block position
             // we will initialise elements within the usedweights and spareweights
             // arrays between the blocks weight (which will then be the new max) and
             // the current max
             $parseweight = $bi->weight;
             while (!array_key_exists($parseweight, $usedweights)) {
                 $usedweights[$parseweight] = array();
                 $spareweights[$parseweight] = $parseweight;
                 $parseweight--;
             }
             $maxweight = $bi->weight;
         } else {
             if ($bi->weight < $minweight) {
                 // As above except this time the blocks weight is LESS than the
                 // the current minimum, so we will initialise the array from the
                 // blocks weight (new minimum) to the current minimum
                 $parseweight = $bi->weight;
                 while (!array_key_exists($parseweight, $usedweights)) {
                     $usedweights[$parseweight] = array();
                     $spareweights[$parseweight] = $parseweight;
                     $parseweight++;
                 }
                 $minweight = $bi->weight;
             }
         }
         if ($bi->id != $block->instance->id) {
             unset($spareweights[$bi->weight]);
             $usedweights[$bi->weight][] = $bi->id;
         }
     }
     // First we find the nearest gap in the list of weights.
     $bestdistance = max(abs($newweight - self::MAX_WEIGHT), abs($newweight + self::MAX_WEIGHT)) + 1;
     $bestgap = null;
     foreach ($spareweights as $spareweight) {
         if (abs($newweight - $spareweight) < $bestdistance) {
             $bestdistance = abs($newweight - $spareweight);
             $bestgap = $spareweight;
         }
     }
     // If there is no gap, we have to go outside -self::MAX_WEIGHT .. self::MAX_WEIGHT.
     if (is_null($bestgap)) {
         $bestgap = self::MAX_WEIGHT + 1;
         while (!empty($usedweights[$bestgap])) {
             $bestgap++;
         }
     }
     // Now we know the gap we are aiming for, so move all the blocks along.
     if ($bestgap < $newweight) {
         $newweight = floor($newweight);
         for ($weight = $bestgap + 1; $weight <= $newweight; $weight++) {
             foreach ($usedweights[$weight] as $biid) {
                 $this->reposition_block($biid, $newregion, $weight - 1);
             }
         }
         $this->reposition_block($block->instance->id, $newregion, $newweight);
     } else {
         $newweight = ceil($newweight);
//.........这里部分代码省略.........
开发者ID:Burick,项目名称:moodle,代码行数:101,代码来源:blocklib.php

示例7: file_get_submitted_draft_itemid

/**
 * Returns draft area itemid for a given element.
 *
 * @category files
 * @param string $elname name of formlib editor element, or a hidden form field that stores the draft area item id, etc.
 * @return int the itemid, or 0 if there is not one yet.
 */
function file_get_submitted_draft_itemid($elname)
{
    // this is a nasty hack, ideally all new elements should use arrays here or there should be a new parameter
    if (!isset($_REQUEST[$elname])) {
        return 0;
    }
    if (is_array($_REQUEST[$elname])) {
        $param = optional_param_array($elname, 0, PARAM_INT);
        if (!empty($param['itemid'])) {
            $param = $param['itemid'];
        } else {
            debugging('Missing itemid, maybe caused by unset maxfiles option', DEBUG_DEVELOPER);
            return false;
        }
    } else {
        $param = optional_param($elname, 0, PARAM_INT);
    }
    if ($param) {
        require_sesskey();
    }
    return $param;
}
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:29,代码来源:filelib.php

示例8: file_get_submitted_draft_itemid

/**
 * Returns draft area itemid for a given element.
 *
 * @param string $elname name of formlib editor element, or a hidden form field that stores the draft area item id, etc.
 * @return integer the itemid, or 0 if there is not one yet.
 */
function file_get_submitted_draft_itemid($elname)
{
    $param = optional_param($elname, 0, PARAM_INT);
    if ($param) {
        require_sesskey();
    }
    if (is_array($param)) {
        if (!empty($param['itemid'])) {
            $param = $param['itemid'];
        } else {
            debugging('Missing itemid, maybe caused by unset maxfiles option', DEBUG_DEVELOPER);
            return false;
        }
    }
    return $param;
}
开发者ID:hatone,项目名称:moodle,代码行数:22,代码来源:filelib.php

示例9: construction_override

 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);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:35,代码来源:endofcluster.php

示例10: process_save_grade

 /**
  * save grade
  *
  * @param  moodleform $mform
  * @return bool - was the grade saved
  */
 private function process_save_grade(&$mform)
 {
     global $USER, $DB, $CFG;
     // Include grade form
     require_once $CFG->dirroot . '/mod/assign/gradeform.php';
     // Need submit permission to submit an assignment
     require_capability('mod/assign:grade', $this->context);
     require_sesskey();
     $rownum = required_param('rownum', PARAM_INT);
     $useridlist = optional_param('useridlist', '', PARAM_TEXT);
     if ($useridlist) {
         $useridlist = explode(',', $useridlist);
     } else {
         $useridlist = $this->get_grading_userid_list();
     }
     $last = false;
     $userid = $useridlist[$rownum];
     if ($rownum == count($useridlist) - 1) {
         $last = true;
     }
     $data = new stdClass();
     $mform = new mod_assign_grade_form(null, array($this, $data, array('rownum' => $rownum, 'useridlist' => $useridlist, 'last' => false)), 'post', '', array('class' => 'gradeform'));
     if ($formdata = $mform->get_data()) {
         $grade = $this->get_user_grade($userid, true);
         $gradingdisabled = $this->grading_disabled($userid);
         $gradinginstance = $this->get_grading_instance($userid, $gradingdisabled);
         if (!$gradingdisabled) {
             if ($gradinginstance) {
                 $grade->grade = $gradinginstance->submit_and_get_grade($formdata->advancedgrading, $grade->id);
             } else {
                 // handle the case when grade is set to No Grade
                 if (isset($formdata->grade)) {
                     $grade->grade = grade_floatval(unformat_float($formdata->grade));
                 }
             }
         }
         $grade->grader = $USER->id;
         $adminconfig = $this->get_admin_config();
         $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
         // call save in plugins
         foreach ($this->feedbackplugins as $plugin) {
             if ($plugin->is_enabled() && $plugin->is_visible()) {
                 if (!$plugin->save($grade, $formdata)) {
                     $result = false;
                     print_error($plugin->get_error());
                 }
                 if ('assignfeedback_' . $plugin->get_type() == $gradebookplugin) {
                     // this is the feedback plugin chose to push comments to the gradebook
                     $grade->feedbacktext = $plugin->text_for_gradebook($grade);
                     $grade->feedbackformat = $plugin->format_for_gradebook($grade);
                 }
             }
         }
         $this->process_outcomes($userid, $formdata);
         $grade->mailed = 0;
         $this->update_grade($grade);
         $this->notify_grade_modified($grade);
         $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
         $this->add_to_log('grade submission', $this->format_grade_for_log($grade));
     } else {
         return false;
     }
     return true;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:70,代码来源:locallib.php

示例11: page_coupons

 /**
  * Render coupon page (including header / footer).
  *
  * @param int $id block instance id
  * @param int $filter table filter
  * @param int $ownerid the owner id of the coupons. Set 0 or NULL to see all.
  * @return string
  */
 protected function page_coupons($id, $filter, $ownerid = null)
 {
     // Actions anyone?
     $action = optional_param('action', null, PARAM_ALPHA);
     if ($action === 'delete' && $filter === \block_coupon\tables\coupons::UNUSED) {
         global $DB;
         require_sesskey();
         $id = required_param('itemid', PARAM_INT);
         $DB->delete_records('block_coupon', array('id' => $id));
         $DB->delete_records('block_coupon_cohorts', array('couponid' => $id));
         $DB->delete_records('block_coupon_groups', array('couponid' => $id));
         $DB->delete_records('block_coupon_courses', array('couponid' => $id));
         redirect($this->page->url, get_string('coupon:deleted', 'block_coupon'));
     }
     // Table instance.
     $table = new \block_coupon\tables\coupons($ownerid, $filter);
     $table->baseurl = $this->page->url;
     $table->is_downloadable(true);
     $table->show_download_buttons_at(array(TABLE_P_BOTTOM, TABLE_P_TOP));
     $download = optional_param('download', '', PARAM_ALPHA);
     if (!empty($download)) {
         $table->is_downloading($download, 'coupons', 'coupons');
         $table->render(25);
         exit;
     }
     $selectedtab = '';
     switch ($filter) {
         case \block_coupon\tables\coupons::UNUSED:
             $selectedtab = 'cpunused';
             break;
         case \block_coupon\tables\coupons::USED:
             $selectedtab = 'cpused';
             break;
     }
     $out = '';
     $out .= $this->header();
     $out .= html_writer::start_div('block-coupon-container');
     $out .= html_writer::start_div();
     $out .= $this->get_tabs($this->page->context, $selectedtab, array('id' => $id));
     $out .= html_writer::end_div();
     ob_start();
     $table->render(25);
     $out .= ob_get_clean();
     $out .= html_writer::end_div();
     $out .= $this->footer();
     return $out;
 }
开发者ID:sebastianberm,项目名称:moodle-block_coupon,代码行数:55,代码来源:renderer.php

示例12: call_external_function

 /**
  * Call an external function validating all params/returns correctly.
  *
  * Note that an external function may modify the state of the current page, so this wrapper
  * saves and restores tha PAGE and COURSE global variables before/after calling the external function.
  *
  * @param string $function A webservice function name.
  * @param array $args Params array (named params)
  * @param boolean $ajaxonly If true, an extra check will be peformed to see if ajax is required.
  * @return array containing keys for error (bool), exception and data.
  */
 public static function call_external_function($function, $args, $ajaxonly = false)
 {
     global $PAGE, $COURSE, $CFG, $SITE;
     require_once $CFG->libdir . "/pagelib.php";
     $externalfunctioninfo = self::external_function_info($function);
     $currentpage = $PAGE;
     $currentcourse = $COURSE;
     $response = array();
     try {
         // Taken straight from from setup.php.
         if (!empty($CFG->moodlepageclass)) {
             if (!empty($CFG->moodlepageclassfile)) {
                 require_once $CFG->moodlepageclassfile;
             }
             $classname = $CFG->moodlepageclass;
         } else {
             $classname = 'moodle_page';
         }
         $PAGE = new $classname();
         $COURSE = clone $SITE;
         if ($ajaxonly && !$externalfunctioninfo->allowed_from_ajax) {
             throw new moodle_exception('servicenotavailable', 'webservice');
         }
         // Do not allow access to write or delete webservices as a public user.
         if ($externalfunctioninfo->loginrequired) {
             if (defined('NO_MOODLE_COOKIES') && NO_MOODLE_COOKIES && !PHPUNIT_TEST) {
                 throw new moodle_exception('servicenotavailable', 'webservice');
             }
             if (!isloggedin()) {
                 throw new moodle_exception('servicenotavailable', 'webservice');
             } else {
                 require_sesskey();
             }
         }
         // Validate params, this also sorts the params properly, we need the correct order in the next part.
         $callable = array($externalfunctioninfo->classname, 'validate_parameters');
         $params = call_user_func($callable, $externalfunctioninfo->parameters_desc, $args);
         // Execute - gulp!
         $callable = array($externalfunctioninfo->classname, $externalfunctioninfo->methodname);
         $result = call_user_func_array($callable, array_values($params));
         // Validate the return parameters.
         if ($externalfunctioninfo->returns_desc !== null) {
             $callable = array($externalfunctioninfo->classname, 'clean_returnvalue');
             $result = call_user_func($callable, $externalfunctioninfo->returns_desc, $result);
         }
         $response['error'] = false;
         $response['data'] = $result;
     } catch (Exception $e) {
         $exception = get_exception_info($e);
         unset($exception->a);
         if (!debugging('', DEBUG_DEVELOPER)) {
             unset($exception->debuginfo);
             unset($exception->backtrace);
         }
         $response['error'] = true;
         $response['exception'] = $exception;
         // Do not process the remaining requests.
     }
     $PAGE = $currentpage;
     $COURSE = $currentcourse;
     return $response;
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:73,代码来源:externallib.php

示例13: check_answer

 public function check_answer()
 {
     global $CFG, $PAGE;
     $formattextdefoptions = new stdClass();
     $formattextdefoptions->noclean = true;
     $formattextdefoptions->para = false;
     $result = parent::check_answer();
     $mform = $this->make_answer_form();
     $data = $mform->get_data();
     require_sesskey();
     if (!$data) {
         redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id)));
     }
     $response = $data->response;
     if (!is_array($response)) {
         $result->noanswer = true;
         return $result;
     }
     $answers = $this->get_answers();
     $correct = array_shift($answers);
     $wrong = array_shift($answers);
     foreach ($answers as $key => $answer) {
         if ($answer->answer === '' or $answer->response === '') {
             // incomplete option!
             unset($answers[$key]);
         }
     }
     // get he users exact responses for record keeping
     $hits = 0;
     $userresponse = array();
     foreach ($response as $key => $value) {
         foreach ($answers as $answer) {
             if ($value === $answer->response) {
                 $userresponse[] = $answer->id;
             }
             if ((int) $answer->id === (int) $key) {
                 $result->studentanswer .= '<br />' . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . ' = ' . $value;
             }
             if ((int) $answer->id === (int) $key and $value === $answer->response) {
                 $hits++;
             }
         }
     }
     $result->userresponse = implode(",", $userresponse);
     if ($hits == count($answers)) {
         $result->correctanswer = true;
         $result->response = format_text($correct->answer, $correct->answerformat, $formattextdefoptions);
         $result->answerid = $correct->id;
         $result->newpageid = $correct->jumpto;
     } else {
         $result->correctanswer = false;
         $result->response = format_text($wrong->answer, $wrong->answerformat, $formattextdefoptions);
         $result->answerid = $wrong->id;
         $result->newpageid = $wrong->jumpto;
     }
     return $result;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:57,代码来源:matching.php

示例14: handle_remote_request

 /**
  * Hook method to handle the remote request to install an add-on
  *
  * This is used as a callback when the admin picks a plugin version in the
  * Moodle Plugins directory and is redirected back to their site to install
  * it.
  *
  * This hook is called early from admin/tool/installaddon/index.php page so that
  * it has opportunity to take over the UI.
  *
  * @param tool_installaddon_renderer $output
  * @param string|null $request
  * @param bool $confirmed
  */
 public function handle_remote_request(tool_installaddon_renderer $output, $request, $confirmed = false)
 {
     global $CFG;
     require_once dirname(__FILE__) . '/pluginfo_client.php';
     if (is_null($request)) {
         return;
     }
     $data = $this->decode_remote_request($request);
     if ($data === false) {
         echo $output->remote_request_invalid_page($this->index_url());
         exit;
     }
     list($plugintype, $pluginname) = normalize_component($data->component);
     $plugintypepath = $this->get_plugintype_root($plugintype);
     if (file_exists($plugintypepath . '/' . $pluginname)) {
         echo $output->remote_request_alreadyinstalled_page($data, $this->index_url());
         exit;
     }
     if (!$this->is_plugintype_writable($plugintype)) {
         $continueurl = $this->index_url(array('installaddonrequest' => $request));
         echo $output->remote_request_permcheck_page($data, $plugintypepath, $continueurl, $this->index_url());
         exit;
     }
     $continueurl = $this->index_url(array('installaddonrequest' => $request, 'confirm' => 1, 'sesskey' => sesskey()));
     if (!$confirmed) {
         echo $output->remote_request_confirm_page($data, $continueurl, $this->index_url());
         exit;
     }
     // The admin has confirmed their intention to install the add-on.
     require_sesskey();
     // Fetch the plugin info. The essential information is the URL to download the ZIP
     // and the MD5 hash of the ZIP, obtained via HTTPS.
     $client = tool_installaddon_pluginfo_client::instance();
     try {
         $pluginfo = $client->get_pluginfo($data->component, $data->version);
     } catch (tool_installaddon_pluginfo_exception $e) {
         if (debugging()) {
             throw $e;
         } else {
             echo $output->remote_request_pluginfo_exception($data, $e, $this->index_url());
             exit;
         }
     }
     // Fetch the ZIP with the plugin version
     $jobid = md5(rand() . uniqid('', true));
     $sourcedir = make_temp_directory('tool_installaddon/' . $jobid . '/source');
     $zipfilename = 'downloaded.zip';
     try {
         $this->download_file($pluginfo->downloadurl, $sourcedir . '/' . $zipfilename);
     } catch (tool_installaddon_installer_exception $e) {
         if (debugging()) {
             throw $e;
         } else {
             echo $output->installer_exception($e, $this->index_url());
             exit;
         }
     }
     // Check the MD5 checksum
     $md5expected = $pluginfo->downloadmd5;
     $md5actual = md5_file($sourcedir . '/' . $zipfilename);
     if ($md5expected !== $md5actual) {
         $e = new tool_installaddon_installer_exception('err_zip_md5', array('expected' => $md5expected, 'actual' => $md5actual));
         if (debugging()) {
             throw $e;
         } else {
             echo $output->installer_exception($e, $this->index_url());
             exit;
         }
     }
     // Redirect to the validation page.
     $nexturl = new moodle_url('/admin/tool/installaddon/validate.php', array('sesskey' => sesskey(), 'jobid' => $jobid, 'zip' => $zipfilename, 'type' => $plugintype));
     redirect($nexturl);
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:87,代码来源:installer.php

示例15: init

 /**
  * Allocate submissions as requested by user
  *
  * @return workshop_allocation_result
  */
 public function init()
 {
     global $PAGE;
     $mode = optional_param('mode', 'display', PARAM_ALPHA);
     $perpage = optional_param('perpage', null, PARAM_INT);
     if ($perpage and $perpage > 0 and $perpage <= 1000) {
         require_sesskey();
         set_user_preference('workshopallocation_manual_perpage', $perpage);
         redirect($PAGE->url);
     }
     $result = new workshop_allocation_result($this);
     switch ($mode) {
         case 'new':
             if (!confirm_sesskey()) {
                 throw new moodle_exception('confirmsesskeybad');
             }
             $reviewerid = required_param('by', PARAM_INT);
             $authorid = required_param('of', PARAM_INT);
             $m = array();
             // message object to be passed to the next page
             $submission = $this->workshop->get_submission_by_author($authorid);
             if (!$submission) {
                 // nothing submitted by the given user
                 $m[] = self::MSG_NOSUBMISSION;
                 $m[] = $authorid;
             } else {
                 // ok, we have the submission
                 $res = $this->workshop->add_allocation($submission, $reviewerid);
                 if ($res == workshop::ALLOCATION_EXISTS) {
                     $m[] = self::MSG_EXISTS;
                     $m[] = $submission->authorid;
                     $m[] = $reviewerid;
                 } else {
                     $m[] = self::MSG_ADDED;
                     $m[] = $submission->authorid;
                     $m[] = $reviewerid;
                 }
             }
             $m = implode('-', $m);
             // serialize message object to be passed via URL
             redirect($PAGE->url->out(false, array('m' => $m)));
             break;
         case 'del':
             if (!confirm_sesskey()) {
                 throw new moodle_exception('confirmsesskeybad');
             }
             $assessmentid = required_param('what', PARAM_INT);
             $confirmed = optional_param('confirm', 0, PARAM_INT);
             $assessment = $this->workshop->get_assessment_by_id($assessmentid);
             if ($assessment) {
                 if (!$confirmed) {
                     $m[] = self::MSG_CONFIRM_DEL;
                     $m[] = $assessment->id;
                     $m[] = $assessment->authorid;
                     $m[] = $assessment->reviewerid;
                     if (is_null($assessment->grade)) {
                         $m[] = 0;
                     } else {
                         $m[] = 1;
                     }
                 } else {
                     if ($this->workshop->delete_assessment($assessment->id)) {
                         $m[] = self::MSG_DELETED;
                         $m[] = $assessment->authorid;
                         $m[] = $assessment->reviewerid;
                     } else {
                         $m[] = self::MSG_DELETE_ERROR;
                         $m[] = $assessment->authorid;
                         $m[] = $assessment->reviewerid;
                     }
                 }
                 $m = implode('-', $m);
                 // serialize message object to be passed via URL
                 redirect($PAGE->url->out(false, array('m' => $m)));
             }
             break;
     }
     $result->set_status(workshop_allocation_result::STATUS_VOID);
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:85,代码来源:lib.php


注:本文中的require_sesskey函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。