bugfix: the slice page was broken when nobody is in slice
[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_array($_GET, 'peerscope');
26 $pattern = get_array($_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     global $PENDING_CONSORTIUM_ID;
54     if ( $site['ext_consortium_id'] === $PENDING_CONSORTIUM_ID )
55       $messages [] = "Pending registration";
56
57     // check that site has at least a PI and a tech
58     global $api;
59     $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids"));
60     $nb_pis=0;
61     $nb_techs=0;
62     if ( $persons)
63       foreach ($persons as $person) {
64         if (in_array( '20', $person['role_ids'])) $nb_pis += 1;
65         if (in_array( '40', $person['role_ids'])) $nb_techs += 1;
66       }
67     if ($nb_pis == 0) $messages [] = "No PI";
68     if ($nb_techs == 0) $messages [] = "No Tech";
69
70     if (! $site['is_public']) $messages []= "Not public";
71
72     // check number of slices
73     if ( $site['max_slices'] == 0) {
74       $messages [] = "No slice allowed";
75     } else if (count($site["slice_ids"]) >= $site['max_slices']) {
76       $messages [] = "No slice left";
77     }
78   }
79
80   return plc_vertical_table ($messages,$class);
81 }
82
83 ////////////////////
84 // The set of columns to fetch
85 // and the filter applied for fetching sites
86 if ($pattern) {
87   $site_filter['login_base']=$pattern;
88   $title .= " with login_base matching " . $pattern;
89  } else {
90   $site_filter['login_base']="*";
91  }
92
93 // server-side selection on peerscope
94 $peerscope = new PeerScope ($api,$peerscope);
95 $site_filter=array_merge($site_filter,$peerscope->filter());
96 $title .= ' - ' . $peerscope->label();
97
98 if (! plc_is_admin()) {
99   $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
100   $site_filter = array_merge ($site_filter, array ("enabled" => TRUE));
101  } else {
102   $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" ,
103                         "is_public", "enabled", "ext_consortium_id",
104                         "person_ids", "max_slices", "slice_ids", "node_ids");
105  }
106
107 if (plc_is_admin())
108   $tabs['Joining Sites'] = array ('url'=>l_sites_pending(),
109                                   'bubble'=>'Review pending join requests');
110
111 drupal_set_title($title);
112 plekit_linetabs($tabs);
113
114 // go
115 $sites= $api->GetSites( $site_filter , $site_columns);
116
117 $peers=new Peers($api);
118
119 $nifty=new PlekitNifty ('','objects-list','big');
120 $nifty->start();
121
122 $headers=array();
123 if (plc_is_admin()) {
124   $headers['I']='int';
125 }
126 $headers['Peer']="string";
127 $headers['Full Name']="string";
128 $headers['Login']="string";
129 $headers['Abbrev.']="string";
130 if (plc_is_admin()) {
131   $headers['N']="int";
132   $headers['U']="int";
133   $headers['S']="int";
134   $headers['?']="string";
135  }
136
137 if (plc_is_admin()) {
138   $table=new PlekitTable("sites",$headers,3);
139 } else {
140   $table=new PlekitTable("sites",$headers,2);
141 }
142 $table->start();
143
144 if ($sites) foreach ($sites as $site) {
145   $peer_id=$site['peer_id'];
146   $site_id=$site['site_id'];
147   $login_base=$site['login_base'];
148   $table->row_start();
149   if (plc_is_admin()) {
150     $table->cell(l_site_t($site_id,$site_id));
151   }
152   $peers->cell($table,$peer_id);
153   // Thomas Dreibholz suggested that utf8_decode could be non-needed
154   // and maybe even harmful on modern systems like f23
155   // $table->cell (l_site_t($site_id,htmlentities(utf8_decode($site['name']))));
156   $table->cell (l_site_t($site_id,htmlentities($site['name'])));
157   $table->cell (l_site_t($site_id,$login_base));
158   $table->cell (htmlentities($site['abbreviated_name']));
159   if (plc_is_admin()) {
160     $table->cell(href(l_nodes_site($site_id),count($site['node_ids'])));
161     $table->cell(href(l_persons_site($site_id),count($site['person_ids'])));
162     $table->cell(href(l_slices_site($site_id),count($site['slice_ids'])));
163     $table->cell(site_status($site));
164   }
165   $table->row_end();
166 }
167 $notes=array();
168 if (plc_is_admin()) {
169   $notes []= "N = number of nodes";
170   $notes []= "U = number of users";
171   $notes []= "S = number of slices";
172   $notes []= "I = site_id";
173   $notes []= "? = status";
174  }
175
176 $table->end(array('notes'=>$notes));
177 $nifty->end();
178
179 //plekit_linetabs ($tabs,"bottom");
180
181 // Print footer
182 include 'plc_footer.php';
183
184 ?>