function make_results_table($slices, $signer, $ma_url, $sa_url) { print "<h3>Results</h3>"; if (count($slices) == 0) { print "<p>No results found. (warning: no partial matches!)</p>"; } else { print "<table><tr><th>Slice name</th><th>Owner</th><th>Expiration</th><th>Next resource exp.</th><th>Actions</th></tr>"; foreach ($slices as $slice) { $slice_urn = $slice[SA_SLICE_TABLE_FIELDNAME::SLICE_URN]; $name = $slice[SA_SLICE_TABLE_FIELDNAME::SLICE_NAME]; $expiration = dateUIFormat($slice[SA_SLICE_TABLE_FIELDNAME::EXPIRATION]); $owner_id = $slice[SA_SLICE_TABLE_FIELDNAME::OWNER_ID]; $owner_detail_list = lookup_member_details($ma_url, $signer, array($owner_id)); $owner_details = $owner_detail_list[$owner_id]; $member = new Member($owner_id); $member->init_from_record($owner_details); $owner_name = $member->prettyName(); $owner_email = $owner_details[MA_ATTRIBUTE_NAME::EMAIL_ADDRESS]; $mailto_link = "<a href='mailto:{$owner_email}'>{$owner_name}</a>"; $slivers = lookup_sliver_info_by_slice($sa_url, $signer, $slice_urn); if (count($slivers) == 0) { $next_exp = "<i>No resources for this slice</i>"; } else { $first_sliver = reset($slivers); $next_exp = new DateTime($first_sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_EXPIRATION]); foreach ($slivers as $sliver) { $this_date = new DateTime($sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_EXPIRATION]); if ($next_exp > $this_date) { $next_exp = $this_date; } } $next_exp = dateUIFormat($next_exp); } print "<tr><td>{$name}</td><td>{$mailto_link}</td><td>{$expiration}</td><td>{$next_exp}</td>"; print "<td><button onclick='expand_info(this);'>More info</button>"; print "<button class='hideinfo' onclick='hide_info(this);' style='display:none;'>Close</button></td></tr>"; $project_info = get_project_info($slice, $signer, $ma_url, $sa_url); $aggregate_info = get_aggregate_info($slice, $signer, $sa_url); $member_info = get_member_info($slice, $signer, $ma_url, $sa_url); print "<tr style='display:none'>"; print "<td style='vertical-align:top'>"; print "<b style='text-decoration: underline;'>Slice URN</b><br> {$slice_urn}<br><br>"; print $project_info; print "</td>"; print "<td colspan='2' style='vertical-align:top'>{$aggregate_info}</td>"; print "<td colspan='2' style='vertical-align:top'>{$member_info}</td> </tr>"; } print "</table>"; } }
$project_slice_counts[$slice_project_id] = 1; } if (!array_key_exists($slice_project_id, $project_objects)) { // Slice is in an expired project $project_expiration = ""; $project_expiration_dt = new DateTime(); $slice_project_name = "-Expired Project-"; } else { // Slice is in an active project $project = $project_objects[$slice_project_id]; $project_expiration = $project[PA_PROJECT_TABLE_FIELDNAME::EXPIRATION]; $project_expiration_dt = new DateTime($project_expiration); $slice_project_name = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_NAME]; } // For printing out "next resource expires in N days" $slivers = lookup_sliver_info_by_slice($sa_url, $user, $slice_urn); $next_resource_exp_date = get_next_resource_expiration($slivers); $max_renewal_days = get_max_renewal_days($project_expiration); $slice_boxes .= make_slice_box($slice_name, $slice_id, $slice_owner_id, $slice_owner_name, $slice_project_name, $slice_project_id, count($slivers), $slice_exp_date, $next_resource_exp_date, $max_renewal_days); } // Get names of all the project leads for the user's projects $lead_names = lookup_member_names_for_rows($ma_url, $user, $all_projects, PA_PROJECT_TABLE_FIELDNAME::LEAD_ID); // Make and fill dictionary of project join requests // Do this for ACTIVE projects only $project_request_map = array(); if (count($project_objects) > 0) { $reqlist = get_pending_requests_for_user($sa_url, $user, $user->account_id, CS_CONTEXT_TYPE::PROJECT); foreach ($reqlist as $req) { if ($req[RQ_REQUEST_TABLE_FIELDNAME::STATUS] != RQ_REQUEST_STATUS::PENDING) { continue; }
/** * Determine the aggregates in a given slice from the sliver info data. * * Return an array of the aggregates. */ function aggregates_in_slice($sa_url, $user, $slice_urn) { $slivers = lookup_sliver_info_by_slice($sa_url, $user, $slice_urn); $all_aggs = get_services_of_type(SR_SERVICE_TYPE::AGGREGATE_MANAGER); /* Construct a map from aggregate URN to aggregate for faster lookup inside the sliver loop. */ $urn2agg = array(); foreach ($all_aggs as $agg) { $agg_urn = $agg[SR_TABLE_FIELDNAME::SERVICE_URN]; $urn2agg[$agg_urn] = $agg; } $aggs_with_resources = array(); // map the sliver aggregate URNs to aggregate IDs foreach ($slivers as $sliver) { $urn = $sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_AGGREGATE_URN]; if (!array_key_exists($urn, $aggs_with_resources) && array_key_exists($urn, $urn2agg)) { $aggs_with_resources[$urn] = $urn2agg[$urn]; } } return array_values($aggs_with_resources); }
function list_slice($slice, $user) { global $project_objects, $slice_owner_names; global $base_url, $slice_base_url, $listres_base_url, $resource_base_url; global $delete_sliver_base_url; global $gemini_base_url, $labwiki_base_url; global $disabled, $jfed_button_start, $jfed_button_part2; global $sa_url, $user; global $portal_max_slice_renewal_days; $slice_id = $slice[SA_SLICE_TABLE_FIELDNAME::SLICE_ID]; $slice_urn = $slice[SA_ARGUMENT::SLICE_URN]; $slice_expired = false; if (array_key_exists(SA_SLICE_TABLE_FIELDNAME::EXPIRED, $slice)) { $slice_expired = $slice[SA_SLICE_TABLE_FIELDNAME::EXPIRED]; } $disable_buttons_str = ""; if (isset($slice_expired) && convert_boolean($slice_expired)) { $disable_buttons_str = "disabled"; } $slice_name = $slice[SA_ARGUMENT::SLICE_NAME]; $args['slice_id'] = $slice_id; $query = http_build_query($args); $slice_url = $slice_base_url . $query; print "<tr class='slicetablerow'><td><a href='{$slice_url}'>{$slice_name}</a></td>"; $slice_project_id = $slice[SA_ARGUMENT::PROJECT_ID]; // There's an odd edge case in which a project has expired // but some slice of the project has not. In this case, $project_objects may not // contain the project of the slice. If so, list the project using something else. if (!array_key_exists($slice_project_id, $project_objects)) { $slice_project_name = "-Expired Project-"; $project_expiration = ""; } else { $project = $project_objects[$slice_project_id]; $project_expiration = $project[PA_PROJECT_TABLE_FIELDNAME::EXPIRATION]; $slice_project_name = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_NAME]; } print "<td><a href='project.php?project_id={$slice_project_id}'>{$slice_project_name}</a></td>"; // Slice owner name $slice_owner_id = $slice[SA_ARGUMENT::OWNER_ID]; $slice_owner_name = $slice_owner_names[$slice_owner_id]; print "<td>{$slice_owner_name}</td>"; // Slice expiration $slice_exp_date = $slice[SA_ARGUMENT::EXPIRATION]; $slice_exp_hours = get_time_diff($slice_exp_date); $slice_exp_str = dateUIFormat($slice_exp_date); $slice_exp_pretty_str = "In <b>" . get_time_diff_string($slice_exp_hours) . "</b>"; $slice_exp_color = get_urgency_color($slice_exp_hours); $slice_exp_icon = get_urgency_icon($slice_exp_hours); print "<td><span title='{$slice_exp_str}'>{$slice_exp_pretty_str} "; print "<i class='material-icons' style='color:{$slice_exp_color}; font-size: 18px;'>{$slice_exp_icon}</i></span></td>"; // Next resource expiration $slivers = lookup_sliver_info_by_slice($sa_url, $user, $slice_urn); $resource_count = count($slivers); if ($resource_count == 0) { $resource_exp_str = ""; $resource_exp_pretty_str = "<i>No resources</i>"; $resource_exp_color = "#5F584E"; $resource_exp_icon = ""; $resource_exp_hours = 1000000; } else { $first_sliver = reset($slivers); $next_exp = new DateTime($first_sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_EXPIRATION]); foreach ($slivers as $sliver) { $this_date = new DateTime($sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_EXPIRATION]); if ($next_exp > $this_date) { $next_exp = $this_date; } } $resource_exp_str = dateUIFormat($next_exp); $resource_exp_hours = get_time_diff($resource_exp_str); $resource_exp_pretty_str = "In <b>" . get_time_diff_string($resource_exp_hours) . "</b>"; $resource_exp_color = get_urgency_color($resource_exp_hours); $resource_exp_icon = get_urgency_icon($resource_exp_hours); } print "<td><span title='{$resource_exp_str}'>{$resource_exp_pretty_str} "; print "<i class='material-icons' style='color:{$resource_exp_color}; font-size: 18px;'>{$resource_exp_icon}</i></span></td>"; // Slice actions $add_url = $resource_base_url . $query; $remove_url = $delete_sliver_base_url . $query; $listres_url = $listres_base_url . $query; $gemini_url = $gemini_base_url . $query; $labwiki_url = $labwiki_base_url . $query; print "<td style='text-align: center;'>"; print "<ul class='selectorcontainer slicetableactions' style='margin: 0px;'><li class='has-sub selector' style='float:none;'>"; print "<span class='selectorshown'>Actions</span><ul class='submenu'>"; print "<li><a href='{$slice_url}'>Manage slice</a></li>"; if ($user->isAllowed(SA_ACTION::ADD_SLIVERS, CS_CONTEXT_TYPE::SLICE, $slice_id)) { print "<li><a href='{$add_url}'>Add resources</a></li>"; } $dashboard_max_renewal_days = 7; $renewal_days = min($dashboard_max_renewal_days, $portal_max_slice_renewal_days); if ($project_expiration) { $project_expiration_dt = new DateTime($project_expiration); $now_dt = new DateTime(); $difference = $project_expiration_dt->diff($now_dt); $renewal_days = $difference->days; $renewal_days = min($renewal_days, $portal_max_slice_renewal_days, $dashboard_max_renewal_days); } $slivers = lookup_sliver_info_by_slice($sa_url, $user, $slice_urn); $renewal_hours = 24 * $renewal_days; $disable_renewal = ""; if ($slice_exp_hours > $renewal_hours && $resource_exp_hours > $renewal_hours) { $disable_renewal = "class='disabledaction'"; } if ($resource_count > 0) { print "<li><a {$disable_renewal} onclick='renew_slice(\"{$slice_id}\", {$renewal_days}, {$resource_count}, {$slice_exp_hours}, {$resource_exp_hours});'>Renew resources ({$renewal_days} days)</a></li>"; if ($user->isAllowed(SA_ACTION::GET_SLICE_CREDENTIAL, CS_CONTEXT_TYPE::SLICE, $slice_id)) { print "<li><a onclick='info_set_location(\"{$slice_id}\", \"{$listres_url}\")'>Resource details</a></li>"; } if ($user->isAllowed(SA_ACTION::DELETE_SLIVERS, CS_CONTEXT_TYPE::SLICE, $slice_id)) { print "<li><a onclick='info_set_location(\"{$slice_id}\", \"{$remove_url}\")'>Delete resources</a></li>"; } } print "</ul></li></ul>"; print "</td></tr>\n"; }
function setup_jacks_slice_context() { global $user; global $slice; global $slice_id; global $slice_name; global $ma_url; global $sa_url; global $all_ams; global $slice_ams; global $slice_urn; global $slice_expiration; // Set globals for variables used in slice jacks page later global $owner_email; global $slice_date_expiration; global $member_names; global $slice_creation; global $slice_desc; global $slice_owner_name; global $members; unset($slice); include "tool-lookupids.php"; if (!isset($sa_url)) { $sa_url = get_first_service_of_type(SR_SERVICE_TYPE::SLICE_AUTHORITY); } if (!isset($ma_url)) { $ma_url = get_first_service_of_type(SR_SERVICE_TYPE::MEMBER_AUTHORITY); } if (isset($slice)) { $slice_name = $slice[SA_ARGUMENT::SLICE_NAME]; // error_log("SLICE = " . print_r($slice, true)); $slice_desc = $slice[SA_ARGUMENT::SLICE_DESCRIPTION]; $slice_creation_db = $slice[SA_ARGUMENT::CREATION]; $slice_creation = dateUIFormat($slice_creation_db); $slice_expiration_db = $slice[SA_ARGUMENT::EXPIRATION]; $slice_expiration = dateUIFormat($slice_expiration_db); $slice_date_expiration = dateOnlyUIFormat($slice_expiration_db); $slice_urn = $slice[SA_ARGUMENT::SLICE_URN]; $slice_owner_id = $slice[SA_ARGUMENT::OWNER_ID]; $owner = $user->fetchMember($slice_owner_id); $slice_owner_name = $owner->prettyName(); $owner_email = $owner->email(); $project_name = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_NAME]; //error_log("slice project_name result: $project_name\n"); // Fill in members of slice member table $members = get_slice_members($sa_url, $user, $slice_id); $member_names = lookup_member_names_for_rows($ma_url, $user, $members, SA_SLICE_MEMBER_TABLE_FIELDNAME::MEMBER_ID); //find only ams that slice has resources on $slivers = lookup_sliver_info_by_slice($sa_url, $user, $slice_urn); //find aggregates to be able to return just am_id $all_aggs = get_services_of_type(SR_SERVICE_TYPE::AGGREGATE_MANAGER); $aggs_with_resources = array(); //do the comparison and find ams foreach ($slivers as $sliver) { foreach ($all_aggs as $agg) { if ($sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_AGGREGATE_URN] == $agg[SR_TABLE_FIELDNAME::SERVICE_URN]) { $aggs_with_resources[] = $agg[SR_TABLE_FIELDNAME::SERVICE_ID]; break; } } } //return unique ids $slice_ams = array_unique($aggs_with_resources, SORT_REGULAR); // Now restore the array to a numerically ordered array because // array_unique preserves keys, so it could turn into, in effect, a // dictionary. $slice_ams = array_values($slice_ams); } else { print "Unable to load slice<br/>\n"; $_SESSION['lasterror'] = "Unable to load slice"; relative_redirect("home.php"); exit; } if (!isset($all_ams)) { $am_list = get_services_of_type(SR_SERVICE_TYPE::AGGREGATE_MANAGER); $all_ams = array(); foreach ($am_list as $am) { $single_am = array(); $service_id = $am[SR_TABLE_FIELDNAME::SERVICE_ID]; $single_am['name'] = $am[SR_TABLE_FIELDNAME::SERVICE_NAME]; $single_am['url'] = $am[SR_TABLE_FIELDNAME::SERVICE_URL]; $single_am['urn'] = $am[SR_TABLE_FIELDNAME::SERVICE_URN]; $all_ams[$service_id] = $single_am; } } }