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