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