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