Example #1
0
function test_requests_for_url($url, $context_type, $context_id)
{
    global $signer;
    $insert_result = create_request($url, $signer, $context_type, $context_id, RQ_REQUEST_TYPE::JOIN, 'foobar', '');
    error_log("IR = " . print_r($insert_result, true));
    $request_id = $insert_result;
    $rows = get_requests_for_context($url, $signer, $context_type, $context_id);
    dump_rows($rows);
    $rows = get_requests_by_user($url, $signer, $signer->account_id, $context_type, $context_id);
    dump_rows($rows);
    $row = get_request_by_id($url, $signer, $request_id, $context_type);
    dump_row($row);
    $num_pending = get_number_of_pending_requests_for_user($url, $signer, $signer->account_id, $context_type, $context_id);
    error_log("Num_pending(pre) = " . print_r($num_pending, true));
    $pending = get_pending_requests_for_user($url, $signer, $signer->account_id, $context_type, $context_id);
    dump_rows($pending);
    resolve_pending_request($url, $signer, $context_type, $request_id, RQ_REQUEST_STATUS::APPROVED, 'resolved');
    $num_pending = get_number_of_pending_requests_for_user($url, $signer, $signer->account_id, $context_type, $context_id);
    error_log("Num_pending(post) = " . print_r($num_pending, true));
}
// Get the sa_url for accessing request information
if (!isset($sa_url)) {
    $sa_url = get_first_service_of_type(SR_SERVICE_TYPE::SLICE_AUTHORITY);
    if (!isset($sa_url) || is_null($sa_url) || $sa_url == '') {
        error_log("Found no Slice Authority Service");
    }
}
// confirm member is not already in this project
$pids = get_projects_for_member($sa_url, $user, $user->account_id, true);
if (isset($pids) && !is_null($pids) && in_array($project_id, $pids)) {
    error_log($user->prettyName() . " already in project " . $project_id);
    $_SESSION['lasterror'] = "You are already in this project.";
    relative_redirect("project.php?project_id={$project_id}");
}
// confirm member has not already requested to join this project
$rpids = get_requests_by_user($sa_url, $user, $user->account_id, CS_CONTEXT_TYPE::PROJECT, $project_id, RQ_REQUEST_STATUS::PENDING);
if (in_array($project_id, $rpids)) {
    error_log($user->prettyName() . " already requested to join project " . $project_id);
    $_SESSION['lasterror'] = "You already requested to join that project.";
    relative_redirect('home.php');
}
if (isset($message) && !is_null($message) && (!isset($error) || is_null($error))) {
    $request_id = create_request($sa_url, $user, CS_CONTEXT_TYPE::PROJECT, $project_id, RQ_REQUEST_TYPE::JOIN, $message);
    // FIXME: sub handle-project-request.php with handle-project-request.php?project_id=$project_id&member_id=$user->account_id&request_id=$request_id
    //  $ind = strpos($message, "handle-project-request.php");
    $hostname = $_SERVER['SERVER_NAME'];
    $message .= "To handle my request, go to the GENI Portal here:\nhttps://{$hostname}/secure/handle-project-request.php?project_id={$project_id}&member_id=" . $user->account_id . "&request_id={$request_id}\n\nRemember that when you approve this request, you agree to take\nresponsibility for my use of GENI resources within the project. \nYou should not approve unsolicited requests to join your project.\n\nThank you,\n" . $user->prettyName() . "\n";
    //  $message = substr_replace($message, "handle-project-request.php?project_id=" . $project_id . "&member_id=" . $user->account_id . "&request_id=" . $request_id, $ind, strlen("handle-project-request.php"));
    // Log the request
    // contexts include project and member
    $project_attributes = get_attribute_for_context(CS_CONTEXT_TYPE::PROJECT, $project_id);