예제 #1
0
 static function initial_checks($id, $password)
 {
     $vpl = new mod_vpl($id);
     //No context validation (session is OK)
     //self::validate_context($vpl->get_context());
     if (!$vpl->pass_network_check()) {
         throw new Exception(get_string('opnotallowfromclient', VPL) . ' ' . getremoteaddr());
     }
     if (!$vpl->pass_password_check($password)) {
         throw new Exception(get_string('requiredpassword', VPL));
     }
     return $vpl;
 }
예제 #2
0
 $raw_data_size = strlen($raw_data);
 if ($_SERVER['CONTENT_LENGTH'] != $raw_data_size) {
     throw new Exception("Ajax POST error: CONTENT_LENGTH expected " . $_SERVER['CONTENT_LENGTH'] . " found {$raw_data_size})");
 }
 $data = json_decode($raw_data);
 if (!$vpl->is_submit_able()) {
     throw new Exception(get_string('notavailable'));
 }
 if (!$userid || $userid == $USER->id) {
     // Make own submission
     $userid = $USER->id;
     $vpl->require_capability(VPL_SUBMIT_CAPABILITY);
     if (!$vpl->pass_network_check()) {
         throw new Exception(get_string('opnotallowfromclient', VPL) . ' ' . getremoteaddr());
     }
     if (!$vpl->pass_password_check()) {
         throw new Exception(get_string('requiredpassword', VPL));
     }
 } else {
     // Make other user submission
     $vpl->require_capability(VPL_MANAGE_CAPABILITY);
 }
 $instance = $vpl->get_instance();
 switch ($action) {
     case 'save':
         $postfiles = (array) $data;
         $files = array();
         foreach ($postfiles as $name => $data) {
             $files[] = array('name' => $name, 'data' => $data);
         }
         mod_vpl_edit::save($vpl, $userid, $files);