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