more renamings
[plewww.git] / planetlab / sites / sites.php
1 <?php
2   // $Id: index.php 11750 2009-01-29 10:11:53Z thierry $
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
22 // -------------------- 
23 // recognized URL arguments
24 $peerscope=$_GET['peerscope'];
25 $pattern=$_GET['pattern'];
26
27 // --- decoration
28 $title="Sites";
29 $tabs=array();
30 $tabs []= tab_mysite();
31 $tabs []= tab_sites_local();
32
33 // -------------------- 
34 $site_filter=array();
35
36 function site_status ($site) {
37
38   $messages=array();
39   
40   if (empty ($site['node_ids'])) 
41     $messages [] = "No node";
42
43   $class=($site['peer_id']) ? 'plc-foreign' : 'plc-warning';
44
45   // do all this stuff on local sites only
46   if ( ! $site['peer_id'] ) {
47     
48     // check that site is enabled
49     if ( ! $site['enabled']) 
50       $messages [] = "Not enabled";
51   
52     // check that site has at least a PI and a tech
53     global $api;
54     $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids"));
55     $nb_pis=0;
56     $nb_tech=0;
57     if ( $persons) foreach ($persons as $person) {
58         if (in_array( '20', $person['role_ids'])) $nb_pis += 1;
59         if (in_array( '40', $person['role_ids'])) $nb_techs += 1;
60       }
61     if ($nb_pis == 0) $messages [] = "No PI";
62     if ($nb_techs == 0) $messages [] = "No Tech";
63     
64     if (! $site['is_public']) $messages []= "Not public";
65
66     // check number of slices
67     if ( $site['max_slices'] == 0) {
68       $messages [] = "No slice allowed";
69     } else if (count($site["slice_ids"]) >= $site['max_slices']) {
70       $messages [] = "No slice left";
71     }
72   }
73
74   return plc_vertical_table ($messages,$class);
75 }
76
77 ////////////////////
78 // The set of columns to fetch
79 // and the filter applied for fetching sites
80 if ($pattern) {
81   $site_filter['login_base']=$pattern;
82   $title .= " with login_base matching " . $pattern;
83  } else {
84   $site_filter['login_base']="*";
85  }
86
87 // server-side selection on peerscope
88 $peerscope = new PeerScope ($api,$peerscope);
89 $site_filter=array_merge($site_filter,$peerscope->filter());
90 $title .= ' - ' . $peerscope->label();
91
92 if (! plc_is_admin()) {
93   $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
94   $site_filter = array_merge ($site_filter, array ("enabled" => TRUE));
95  } else {
96   $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , 
97                         "enabled", "person_ids", "max_slices", "slice_ids", "node_ids");
98  }
99
100 if (plc_is_admin()) 
101   $tabs['Pending'] = array ('url'=>l_sites_pending(),
102                             'bubble'=>'Review pending join requests');
103
104 drupal_set_title($title);
105 plekit_linetabs($tabs);
106
107 // go
108 $sites= $api->GetSites( $site_filter , $site_columns);
109
110 $peers=new Peers($api);
111
112 $headers['Peer']="string";
113 $headers['Full Name']="string";
114 $headers['Login']="string";
115 $headers['Abbrev.']="string";
116 if (plc_is_admin()) {
117   $headers['N']="int";
118   $headers['U']="int";
119   $headers['S']="int";
120   $headers['?']="string";
121  }
122
123 $table=new PlekitTable("sites",$headers,2);
124 $table->start();
125
126 if ($sites) foreach ($sites as $site) {
127   $shortname = $peers->shortname($site['peer_id']);
128   $table->row_start();
129   $table->cell($shortname);
130   $table->cell (l_site_t($site['site_id'],htmlentities($site['name'])));
131   $table->cell ($site['login_base']);
132   $table->cell (htmlentities($site['abbreviated_name']));
133   if (plc_is_admin()) {
134     $table->cell(count($site['node_ids']));
135     $table->cell(count($site['person_ids']));
136     $table->cell(count($site['slice_ids']));
137     $table->cell(site_status($site));
138   }
139   $table->row_end();
140 }
141 $notes=array("N = number of sites / U = number of users / S = number of slices");
142
143 $table->end(array('notes'=>$notes));
144
145 //plekit_linetabs ($tabs,"bottom");
146
147 // Print footer
148 include 'plc_footer.php';
149
150 ?>