/** * Removes a user from a group. * * @param $uid The id of the user that is being removed * @param $sid The id of the sheet */ function removeUserFromGroup($uid, $sid) { global $databaseURI; $newGroupSettings = Group::encodeGroup(Group::createGroup($uid, $uid, $sid)); $URI = $databaseURI . "/group/user/{$uid}/exercisesheet/{$sid}"; http_put_data($URI, $newGroupSettings, true, $message); if ($message == "201") { return true; } else { return false; } }
} else { $notifications[] = MakeNotification("error", Language::Get('main', 'incorrectOldPassword', $langTemplate)); } } else { $notifications = $notifications + $f->notifications; } } else { if ($_POST['action'] == "SetAccountInfo") { $f = new FormEvaluator($_POST); $f->checkStringForKey('language', FormEvaluator::OPTIONAL, 'warning', '???.'); if ($f->evaluate(true)) { $foundValues = $f->foundValues; $language = $foundValues['language']; $newUserSettings = User::encodeUser(User::createUser($uid, null, null, null, null, null, null, null, null, null, null, null, null, null, $language)); $URI = $databaseURI . "/user/" . $uid; http_put_data($URI, $newUserSettings, true, $message); if ($message == "201") { $notifications[] = MakeNotification("success", Language::Get('main', 'languageChanged', $langTemplate)); } } else { $notifications = $notifications + $f->notifications; } } } } // load user data from the database $databaseURI = $getSiteURI . "/accountsettings/user/{$uid}"; $accountSettings_data = http_get($databaseURI, true); $accountSettings_data = json_decode($accountSettings_data, true); // construct a new header $h = Template::WithTemplateFile('include/Header/Header.template.html');
// bool which is true if any error occured $RequestError = false; foreach ($_POST as $key => $value) { // skips the first POST which includes the 'action' type if ($key == "action") { continue; } // changes the percentage for each exercise type $approvalConditionId = $key; $percentage = cleanInput($value); if (is_numeric($percentage) && $percentage >= 0 && $percentage <= 100) { $percentage = $percentage / 100; $newApprovalCondition = ApprovalCondition::createApprovalCondition($approvalConditionId, $cid, null, $percentage); $newApprovalConditionSettings = ApprovalCondition::encodeApprovalCondition($newApprovalCondition); $URI = $databaseURI . "/approvalcondition/approvalcondition/" . $approvalConditionId; http_put_data($URI, $newApprovalConditionSettings, true, $message); if ($message != "201") { $notifications[] = MakeNotification("error", Language::Get('main', 'errorSetCondition', $langTemplate)); $RequestError = true; } } else { $notifications[] = MakeNotification("warning", Language::Get('main', 'invalidInput', $langTemplate)); $RequestError = true; } } // creates a notification depending on RequestError if ($RequestError) { $notifications[] = MakeNotification("error", Language::Get('main', 'errorSetConditions', $langTemplate)); } else { $notifications[] = MakeNotification("success", Language::Get('main', 'successSetConditions', $langTemplate)); }
<?php echo $method; ?> Host Response:<br> </b> <pre> <?php // Main function: switch ($method) { case "GET": $response = http_get($url); break; case "POST": $response = http_post_data($url, $data); break; case "PUT": $response = http_put_data($url, $data); break; case "DELETE": echo "DELETE NOT SUPPORTED: {$url}"; exit; } //list($head,$body) = explode("{",$response); echo $response; echo "<b><h3><br>JSon pretty print:<br></h3></b>"; $json = http_parse_message($response)->body; echo json_encode(json_decode($json), JSON_PRETTY_PRINT); ?> </pre> </body> </html>
} } else { $editExerciseTypeNotifications[] = MakeNotification("error", Language::Get('main', 'missingFields', $langTemplate)); } } elseif ($_POST['action'] == "GrantRights") { // check if POST data is send if (isset($_POST['userID']) && isset($_POST['Rights'])) { // clean Input $userID = cleanInput($_POST['userID']); $Rights = cleanInput($_POST['Rights']); // validate POST data if (is_numeric($userID) == true && is_numeric($Rights) && $Rights >= 0 && $Rights < 3) { // create new coursestatus and edit existing one $data = User::encodeUser(User::createCourseStatus($userID, $cid, $Rights)); $url = $databaseURI . "/coursestatus/course/{$cid}/user/{$userID}"; http_put_data($url, $data, true, $message); // show notification if ($message == "201") { $grantRightsNotifications[] = MakeNotification("success", Language::Get('main', 'successSetCourseStatus', $langTemplate)); } } else { // otherwise show conflict page set_error("409"); exit; } } else { $grantRightsNotifications[] = MakeNotification("error", Language::Get('main', 'noSelectedUser', $langTemplate)); } } elseif ($_POST['action'] == "RevokeRights") { // check if POST data is send if (isset($_POST['userID'])) {
function put($url, $data = '', $http_options = array()) { $http_options = array_merge($this->http_options, $http_options); $this->http_parse_message(http_put_data($url, $data, $http_options, $this->response_info)); return $this->response_object->body; }
if (isset($_POST['deleteSubmissionWarning'])) { $notifications[] = MakeNotification("warning", Language::Get('main', 'askDeleteSubmission', $langTemplate)); } elseif (isset($_POST['deleteSubmission'])) { $suid = cleanInput($_POST['deleteSubmission']); // extractes the studentId of the submission $URI = $databaseURI . "/submission/" . $suid; $submission = http_get($URI, true); $submission = json_decode($submission, true); // only deletes the submission if it belongs to the user if ($submission['studentId'] == $uid) { $URI = $databaseURI . "/selectedsubmission/submission/" . $suid; http_delete($URI, true, $message); // todo: treat the case if the previous operation failed $submissionUpdate = Submission::createSubmission($suid, null, null, null, null, null, null, 0); $URI = $databaseURI . "/submission/submission/" . $suid; http_put_data($URI, Submission::encodeSubmission($submissionUpdate), true, $message2); if ($message == "201" && $message2 == 201) { $notifications[] = MakeNotification("success", Language::Get('main', 'successDeleteSubmission', $langTemplate)); } else { $notifications[] = MakeNotification("error", Language::Get('main', 'errorDeleteSubmission', $langTemplate)); } } } elseif (isset($_POST['downloadMarkings'])) { downloadMarkingsForSheet($uid, $_POST['downloadMarkings']); } // load tutor data from GetSite $URI = $getSiteURI . "/student/user/{$uid}/course/{$cid}"; $student_data = http_get($URI, true); $student_data = json_decode($student_data, true); $student_data['filesystemURI'] = $filesystemURI; $student_data['cid'] = $cid;
/** * Test Http functions. */ function test_functions() { http_cache_last_modified(); http_chunked_decode(); http_deflate(); http_inflate(); http_build_cookie(); http_date(); http_get_request_body_stream(); http_get_request_body(); http_get_request_headers(); http_match_etag(); http_match_modified(); http_match_request_header(); http_support(); http_negotiate_charset(); http_negotiate_content_type(); http_negotiate_language(); ob_deflatehandler(); ob_etaghandler(); ob_inflatehandler(); http_parse_cookie(); http_parse_headers(); http_parse_message(); http_parse_params(); http_persistent_handles_clean(); http_persistent_handles_count(); http_persistent_handles_ident(); http_get(); http_head(); http_post_data(); http_post_fields(); http_put_data(); http_put_file(); http_put_stream(); http_request_body_encode(); http_request_method_exists(); http_request_method_name(); http_request_method_register(); http_request_method_unregister(); http_request(); http_redirect(); http_send_content_disposition(); http_send_content_type(); http_send_data(); http_send_file(); http_send_last_modified(); http_send_status(); http_send_stream(); http_throttle(); http_build_str(); http_build_url(); }
function updateSubmission($submissionId, $accepted) { global $databaseURI; $newSubmission = Submission::createSubmission(null, null, null, null, null, $accepted, null, null); $newSubmission = Submission::encodeSubmission($newSubmission); $URI = $databaseURI . "/submission/{$submissionId}"; http_put_data($URI, $newSubmission, true, $message); if ($message != 201) { return false; } else { return true; } }