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