summary page WIP
smbaker [Sat, 3 Nov 2012 02:57:26 +0000 (19:57 -0700)]
apps/gacksadmin/gacks_functions.php
apps/gacksadmin/user_summary.php [new file with mode: 0644]
apps/gacksadmin/vicci.module

index 58d5a8d..77d1e88 100644 (file)
@@ -37,6 +37,7 @@ function l_gacks_confirm_service($acct, $level, $autoRenew, $freezeUnreserved) {
 function l_gacks_add_reservation() { return "/db/gacks/user_add_reservation.php"; }
 function l_gacks_persons()         { return "/db/gacks/user_persons.php"; }
 function l_gacks_advanced($value, $url)        { $eurl=urlencode($url); return "/db/gacks/action.php?action=set-advanced&value=$value&url=$eurl"; }
+function l_gacks_summary()         { return "/db/gacks/user_summary.php"; }
 
 function gacksid($x) { return "gacksid:" . $x; }
 
@@ -136,6 +137,15 @@ function charge_kind_selectors($value)
     return $kind_selectors;
 }
 
+function bool_text($value, $true, $false)
+{
+    if ($value) {
+        return $true;
+    } else {
+        return $false;
+    }
+}
+
 function bool_selectors($value)
 {
     if ($value) {
@@ -342,34 +352,46 @@ function date_picker($name, $y, $m, $d)
     return $html;\r
 }
 
-function get_account_names($plcapi, $person_id)
+function get_slices($plcapi, $person_id, $fields)
 {
+    if (!in_array("name", $fields)) {
+        $fields []= "name";
+    }
+
     $persons = $plcapi->GetPersons(array('person_id'=>$person_id),array('person_id','email','slice_ids','role_ids','site_ids'));
     $person=$persons[0];\r
     $slice_filter=array('slice_id' => $person['slice_ids']);\r
-    $slices=$plcapi->GetSlices($slice_filter,array("name"));\r
+    $user_slices=$plcapi->GetSlices($slice_filter,$fields);\r
 \r
-    $slicenames = array();\r
-    foreach ($slices as $slice) {\r
-        $slicenames []= $slice['name'];\r
+    $slices = array();\r
+    foreach ($user_slices as $slice) {\r
+        $slices[$slice['name']] = $slice;\r
     }\r
 \r
     $is_pi = in_array( 20, $person['role_ids']);\r
     if ($is_pi) {\r
         $slice_filter=array('site_id'=>$person['site_ids'][0]);\r
-        $slices = $plcapi->GetSlices($slice_filter, array("name"));\r
-\r
-        //print "<br>filter:"; print_r($slice_filter);\r
-        //print "<br>slices:"; print_r($slices);\r
+        $pi_slices = $plcapi->GetSlices($slice_filter, $fields);\r
 \r
-        foreach ($slices as $slice) {\r
-            if (!in_array($slice['name'], $slicenames)) {\r
-                $slicenames []= $slice['name'];\r
+        foreach ($pi_slices as $slice) {\r
+            if (!array_key_exists($slice['name'], $slices)) {\r
+                $slices[$slice['name']] = $slice;\r
             }\r
         }\r
     }\r
 \r
-    return $slicenames;\r
+    return $slices;\r
+}
+
+function get_account_names($plcapi, $person_id)
+{
+    $slices = get_slices($plcapi, $person_id, array("name"));
+    $slicenames = array();
+    foreach ($slices as $name => $slice) {
+        $slicenames []= $name;
+    }
+
+    return $slicenames;
 }
 
 function account_selectors($plcapi, $person_id, $account_name)
@@ -544,6 +566,43 @@ function timezone_combo($form, &$timezone, $url)
     return auto_refresh_combo($form, "timezone", $selectors, $timezone, $url);
 }
 
+function account_table($plcapi, $gacksapi, $person_id)
+{
+    $slices = get_slices($plcapi, $person_id, array("name","person_ids","node_ids"));
+
+    $accounts = array();
+    foreach ($slices as $slicename => $slice) {
+         $accounts[$slicename] = $gacksapi->get_account(gacksid($slicename), "user");
+    }
+
+    $headers=array();
+    $headers["name"] = "string";\r
+    $headers["level"] = "string";\r
+    $headers["be"] = "string";\r
+    $headers["users"] = "integer";\r
+    $headers["slivers"] = "integer";\r
+    $headers["billingContacts"] = "string";\r
+\r
+    $table = new PlekitTable("accounts", $headers, 0);\r
+    $table->start();\r
+\r
+    foreach ($accounts as $name => $account) {
+        $slice = $slices[$name];
+        $table->row_start();
+        $table->cell($name);
+        $table->cell($account["level"]);
+        $table->cell(bool_text(!$account["freezeUnreserved"], "enabled", "disabled"));
+        $table->cell(count($slice["person_ids"]));
+        $table->cell(count($slice["node_ids"]));
+        $table->cell($account["billingContacts"]);
+
+        $table->row_end();
+    }
+
+    $table->end();
+
+}
+
 function date_combo($form, $name, &$y, &$m, &$d, $url)
 {
     $month_selectors = array();
diff --git a/apps/gacksadmin/user_summary.php b/apps/gacksadmin/user_summary.php
new file mode 100644 (file)
index 0000000..2ffa783
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+\r
+// Require login\r
+require_once 'plc_login.php';\r
+\r
+// Get session and API handles\r
+require_once 'plc_session.php';\r
+global $plc, $api, $adm;\r
+\r
+// Common functions\r
+require_once 'plc_functions.php';\r
+require_once 'gacks_functions.php';\r
+require_once 'linetabs.php';\r
+require_once 'table.php';\r
+require_once 'gacksclient.php';\r
+\r
+// find person roles\r
+$_person= $plc->person;\r
+$_person_id = $plc->person['person_id'];\r
+$_roles= $_person['role_ids'];
+
+// Print header
+require_once 'plc_drupal.php';\r
+drupal_set_title('Service Level');\r
+include 'plc_header.php';\r
+\r
+$gacksapi = new GACKSAPI();\r
+\r
+print "<br><br>";\r
+\r
+account_table($api, $gacksapi, $_person_id);\r
+\r
+include 'plc_footer.php';\r
+\r
+?>
+
index 7bf06e1..8435f21 100644 (file)
@@ -83,6 +83,9 @@ function vicci_block($op = 'list', $delta = 0, $edit = array()) {
            $block['subject'] .= " <font size=1>(pl)</font>";
         }
 
+        $bullet_item = href( l_gacks_summary(), "Summary");
+        $items []= expanded($bullet_item);
+
         $bullet_item = href( l_gacks_service_level(), "Service settings");
         $items []= expanded($bullet_item);