60628de258dba3b1678440d79210bdc9d9196023
[plewww.git] / planetlab / pub / slices.php
1 <?php
2 //
3 // Slice list
4 //
5 // Mark Huang <mlhuang@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
7 //
8 // $Id$ $
9 //
10
11 // Get API handle
12 require_once 'plc_session.php';
13 global $adm;
14
15 // Get PlanetFlow stats
16 global $planetflow, $active_bytes;
17 include_once '_gen_planetflow.php';
18
19 // Print header
20 require_once 'plc_drupal.php';
21 drupal_set_title('Projects');
22 include 'plc_header.php';
23
24 if (isset($_REQUEST['active'])) {
25
26 ?>
27
28 <p>A slice is essentially a login account on a set of nodes. The
29 following is a list of the most active slices; you may also view a
30 list of <a href="/db/pub/slices.php">all slices</a>.</p>
31
32 <?php } else { ?>
33
34 <p>A slice is essentially a login account on a set of nodes. The
35 following is a list of all slices; you may also view a list of <a
36 href="/db/pub/slices.php?active">just the most active slices</a>.</p>
37
38 <?php } ?>
39
40 <p>To provide feedback to the principals responsible for each slice,
41 check the <b>Feedback</b> box for each slice that you would like to
42 comment on, then click <b>Provide Feedback</b>.</p>
43
44 <form method="post" action="/db/pub/feedback.php">
45
46 <table cellspacing="0">
47   <thead>
48     <tr>
49       <th>Slice</th>
50       <th>Description</th>
51       <th>Site</th>
52       <th>MBytes/day</th>
53       <th>Feedback</th>
54     </tr>
55   </thead>
56   <tbody>
57
58 <?php
59
60 // Get all sites
61 $sites = $adm->GetSites(NULL, array('abbreviated_name', 'site_id'));
62 if (!empty($sites)) foreach ($sites as $site) {
63   $sites[$site['site_id']] = $site;
64 }
65
66 // Get all slices
67 $slices = $adm->GetSlices(NULL, array('name', 'url', 'description', 'site_id'));
68
69 // List just the active slices
70 if (isset($_REQUEST['active'])) {
71   // Byte threshold to be considered "active"
72   if (!empty($_REQUEST['mbytes'])) {
73     $active_bytes = intval($_REQUEST['mbytes'])*1024*1024;
74   } else {
75     $active_bytes = 100*1024*1024;
76   }
77
78   // Filter just the active slices
79   function __active_slice($slice) {
80     global $planetflow, $active_bytes;
81     return isset($planetflow[$slice['name']]) &&
82       ($planetflow[$slice['name']]['bytes'] >= $active_bytes);
83   }
84   $slices = array_filter($slices, '__active_slice');
85   
86   // Sort active slices by bytes in descending order
87   function __cmp_slices_by_bytes($slicea, $sliceb) {
88     global $planetflow;
89     return ($planetflow[$slicea['name']]['bytes'] > $planetflow[$sliceb['name']]['bytes']) ? -1 : 1;
90   }
91   usort($slices, '__cmp_slices_by_bytes');
92 } else {
93   // slice sort on name
94   function __cmp_slices($a, $b) {
95     return strcasecmp($a['name'], $b['name']);
96   }
97   // Alphabetically sort slices
98   usort($slices, '__cmp_slices');
99 }
100
101 $class = "";  
102 foreach ($slices as $slice) {
103   print "<tr class=\"$class\">";
104
105   print '<td valign="top"><a name="' .
106     htmlspecialchars($slice['name']) .
107     '">' .
108     htmlspecialchars($slice['name']) .
109     '</a></td>';
110
111   print '<td valign="top">';
112   print htmlspecialchars(trim($slice['description']));
113   if (!empty($slice['url'])) {
114     if (strncasecmp($slice['url'], "http", 4) != 0) {
115       $slice['url'] = "http://" . $slice['url'];
116     }
117     print '<br /><a href="' . htmlspecialchars($slice['url']) . '">More details...</a>';
118   }
119   print '</td>';
120
121   print '<td valign="top">';
122   if (isset($sites[$slice['site_id']])) {
123     $site = $sites[$slice['site_id']];
124     print htmlspecialchars($site['abbreviated_name']);
125   }
126   print '</td>';
127
128   print '<td valign="top">';
129   if (isset($planetflow[$slice['name']]) &&
130       isset($planetflow[$slice['name']]['bytes']) &&
131       $planetflow[$slice['name']]['bytes']/1024/1024 >= 1) {
132     print number_format($planetflow[$slice['name']]['bytes']/1024/1024, 0, '.', ',');
133   }
134   print '</td>';
135
136   print '<td valign="top">';
137   print '<input type="checkbox" name="slices[]" value="' . htmlspecialchars($slice['name']) . '" />';
138   print '</td>';
139
140   print '</tr>';
141
142   $class = $class == "oddrow" ? "" : "oddrow";
143 }
144
145 ?>
146
147   </tbody>
148 </table>
149
150 <input type="submit" value="Provide Feedback" />
151
152 </form>
153
154 <?php
155
156 include 'plc_footer.php';
157
158 ?>