public sites page sortable/searcheable -- has a link to the KML/googlemaps stuff
[plewww.git] / planetlab / sites / sites.php
1 <?php
2   // $Id$
3   //
4
5   // Require login
6 require_once 'plc_login.php';
7
8 // Get session and API handles
9 require_once 'plc_session.php';
10 global $plc, $api;
11
12 // Print header
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
15
16 // Common functions
17 require_once 'plc_functions.php';
18 require_once 'plc_peers.php';
19 require_once 'linetabs.php';
20 require_once 'table.php';
21 require_once 'nifty.php';
22
23 // -------------------- 
24 // recognized URL arguments
25 $peerscope=$_GET['peerscope'];
26 $pattern=$_GET['pattern'];
27
28 // --- decoration
29 $title="Sites";
30 $tabs=array();
31 $tabs []= tab_sites();
32 $tabs []= tab_sites_local();
33 $tabs []= tab_mysite();
34
35 // -------------------- 
36 $site_filter=array();
37
38 function site_status ($site) {
39
40   $class=($site['peer_id']) ? 'plc-foreign' : 'plc-warning';
41
42   $messages=array();
43   
44   if (empty ($site['node_ids'])) 
45     $messages [] = "No node";
46
47   // do all this stuff on local sites only
48   if ( ! $site['peer_id'] ) {
49     
50     // check that site is enabled
51     if ( ! $site['enabled']) 
52       $messages [] = "Not enabled";
53   
54     // check that site has at least a PI and a tech
55     global $api;
56     $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids"));
57     $nb_pis=0;
58     $nb_tech=0;
59     if ( $persons) foreach ($persons as $person) {
60         if (in_array( '20', $person['role_ids'])) $nb_pis += 1;
61         if (in_array( '40', $person['role_ids'])) $nb_techs += 1;
62       }
63     if ($nb_pis == 0) $messages [] = "No PI";
64     if ($nb_techs == 0) $messages [] = "No Tech";
65     
66     if (! $site['is_public']) $messages []= "Not public";
67
68     // check number of slices
69     if ( $site['max_slices'] == 0) {
70       $messages [] = "No slice allowed";
71     } else if (count($site["slice_ids"]) >= $site['max_slices']) {
72       $messages [] = "No slice left";
73     }
74   }
75
76   return plc_vertical_table ($messages,$class);
77 }
78
79 ////////////////////
80 // The set of columns to fetch
81 // and the filter applied for fetching sites
82 if ($pattern) {
83   $site_filter['login_base']=$pattern;
84   $title .= " with login_base matching " . $pattern;
85  } else {
86   $site_filter['login_base']="*";
87  }
88
89 // server-side selection on peerscope
90 $peerscope = new PeerScope ($api,$peerscope);
91 $site_filter=array_merge($site_filter,$peerscope->filter());
92 $title .= ' - ' . $peerscope->label();
93
94 if (! plc_is_admin()) {
95   $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
96   $site_filter = array_merge ($site_filter, array ("enabled" => TRUE));
97  } else {
98   $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , "is_public",
99                         "enabled", "person_ids", "max_slices", "slice_ids", "node_ids");
100  }
101
102 if (plc_is_admin()) 
103   $tabs['Joining Sites'] = array ('url'=>l_sites_pending(),
104                                   'bubble'=>'Review pending join requests');
105
106 drupal_set_title($title);
107 plekit_linetabs($tabs);
108
109 // go
110 $sites= $api->GetSites( $site_filter , $site_columns);
111
112 $peers=new Peers($api);
113
114 $nifty=new PlekitNifty ('','objects-list','big');
115 $nifty->start();
116
117 $headers=array();
118 if (plc_is_admin()) {
119   $headers['I']='int';
120 }
121 $headers['Peer']="string";
122 $headers['Full Name']="string";
123 $headers['Login']="string";
124 $headers['Abbrev.']="string";
125 if (plc_is_admin()) {
126   $headers['N']="int";
127   $headers['U']="int";
128   $headers['S']="int";
129   $headers['?']="string";
130  }
131
132 if (plc_is_admin()) {
133   $table=new PlekitTable("sites",$headers,3);
134 } else {
135   $table=new PlekitTable("sites",$headers,2);
136 }
137 $table->start();
138
139 if ($sites) foreach ($sites as $site) {
140   $peer_id=$site['peer_id'];
141   $site_id=$site['site_id'];
142   $login_base=$site['login_base'];
143   $table->row_start();
144   if (plc_is_admin()) {
145     $table->cell(l_site_t($site_id,$site_id));
146   }
147   $peers->cell($table,$peer_id);
148   $table->cell (l_site_t($site_id,htmlentities($site['name'])));
149   $table->cell (l_site_t($site_id,$login_base));
150   $table->cell (htmlentities($site['abbreviated_name']));
151   if (plc_is_admin()) {
152     $table->cell(href(l_nodes_site($site_id),count($site['node_ids'])));
153     $table->cell(href(l_persons_site($site_id),count($site['person_ids'])));
154     $table->cell(href(l_slices_site($site_id),count($site['slice_ids'])));
155     $table->cell(site_status($site));
156   }
157   $table->row_end();
158 }
159 $notes=array();
160 if (plc_is_admin()) {
161   $notes []= "N = number of nodes";
162   $notes []= "U = number of users";
163   $notes []= "S = number of slices";
164   $notes []= "I = site_id";
165   $notes []= "? = status";
166  }
167
168 $table->end(array('notes'=>$notes));
169 $nifty->end();
170
171 //plekit_linetabs ($tabs,"bottom");
172
173 // Print footer
174 include 'plc_footer.php';
175
176 ?>