4 // page for administration of pending site registration requests
8 require_once 'plc_login.php';
10 // Get session and API handles
11 require_once 'plc_session.php';
12 require_once 'plc_api.php';
13 global $plc, $api, $adm;
16 require_once 'plc_drupal.php';
17 include 'plc_header.php';
20 require_once 'plc_functions.php';
21 require_once 'details.php';
22 require_once 'nifty.php';
23 require_once 'table.php';
24 require_once 'nifty.php';
26 include 'site_form.php';
28 ////////////////////////////////////////
29 function render_all_join_requests($api) {
30 global $PENDING_CONSORTIUM_ID;
31 $filter = array("peer_id" => NULL, "ext_consortium_id" => $PENDING_CONSORTIUM_ID);
32 $columns=array('site_id','name','enabled','date_created');
33 $sites = $api->GetSites( $filter, $columns);
35 print("<p> No open join requests </p>");
40 $headers['Site Name']='string';
41 # trying the sortEnglishDateTime stuff - not too lucky so far
42 # http://www.frequency-decoder.com/demo/table-sort-revisited/custom-sort-functions/
43 $headers['submitted']='sortEnglishDateTime';
44 $headers['enabled']='string';
46 $nifty=new PlekitNifty ('pending','sites-pending','medium');
48 $table=new PlekitTable ('pending',$headers,2,
49 array('pagesize_area'=>FALSE,'pagesize'=>10000));
51 foreach($sites as $site) {
52 $site_id=$site['site_id'];
53 $link = $site['enabled'] ? l_site($site_id) : l_site_review_pending($site_id);
55 $table->cell(href($link,$site['site_id']));
56 $table->cell(href($link,$site['name']));
57 $table->cell(date("dS F Y",$site['date_created']) . " at " . date("G:i",$site['date_created']));
58 $table->cell( $site['enabled'] ? plc_warning_html('yes') : 'no');
65 function render_join_request_review($api, $site_id) {
66 $sites = $api->GetSites( array(intval($site_id)) );
68 print("<p class='plc-warning'> Invalid request with site_id=$site_id</p> ");
72 if ($site['enabled'] && $site['ext_consortium_id'] === $PENDING_CONSORTIUM_ID) {
73 print("<p class='plc-warning'> This site is already enabled </p>");
76 $addresses = $api->GetAddresses ($site['address_ids']);
77 if (empty ($addresses)) {
78 drupal_set_message("Site $site_id has no address - never mind");
79 $address=array('line1'=>'');
82 $address = $addresses[0];
83 $address_id=$address['address_id'];
85 # just in case there is no person attached yet
86 if (empty ($site['person_ids'])) {
89 $person_ids = $site['person_ids'];
90 $persons = $api->GetPersons( $person_ids, array( "person_id", "role_ids", "first_name", "last_name", "title", "email" , "phone") );
94 foreach($persons as $person) {
95 if ( in_array('20', $person['role_ids']) ) {
98 if ( in_array('40', $person['role_ids']) ) {
102 $pi_id = $pi['person_id'];
103 $tech_id = $tech['person_id'];
106 <p> Please review the join request below.</p>
107 <p> <b> Warning:</b> the PI email address that was provided in this form will <b> not be checked</b> automatically. We expect that as part of the handshake with the site, the support team has had an opportunity to use this address so it can be considered safe. Please check it manually if this is not the case.</p>
108 <form name="join_request" method="post" action="/db/sites/join_request.php">
109 <input type="hidden" name="pi_id" value="$pi_id">
110 <input type="hidden" name="address_id" value="$address_id">
111 <input type="hidden" name="tech_id" value="$tech_id">
112 <input type="hidden" name="site_id" value="$site_id">
115 // don't render the tech part if that was the same as the pi
116 $site_form = build_site_form(FALSE);
117 $input = array ('site' => $site, 'address'=> $address, 'pi' => $pi, 'tech' => $tech);
119 $nifty=new PlekitNifty ('pending','site-pending','medium');
122 $details = new PlekitDetails(TRUE);
125 // display the buttons
127 <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr>
128 <td align=center><input type="submit" name="submitted" value="Delete"></td>
129 <td align=center><input type="submit" name="submitted" value="Update"></td>
130 <td align=center><input type="submit" name="submitted" value="Approve"></td>
134 $details->tr($buttons_row,'center');
135 // render the form - not supposed to be empty
136 form_render_details ($details,$site_form, $input, TRUE);
138 // display the buttons again
139 $details->tr($buttons_row,'center');
146 function notify_enabled_pi ($api, $pi_id, $pi, $site_id, $site) {
149 You have filed a site registration with the %s platform.
151 This registration has been approved, and your account was enabled
152 You were granted a PI role, meaning that you will be responsible
153 for managing personal accounts and slices for your site
155 You can now enter the system at
158 and the password that you provided at registration-time
160 You can directly access your site information at
161 https://%s:%d/db/sites/index.php?id=%d
163 Please start with adding nodes for this site with
164 https://%s:%d/db/nodes/node_add.php
166 Our support team will be glad to answer any question that you might have
167 They are reachable at mailto:%s
170 $body=sprintf($template,
172 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
174 PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id,
175 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
176 PLC_MAIL_SUPPORT_ADDRESS);
178 $subject="Site registration for " . $site['name'] . " has been approved by " . PLC_NAME;
179 $adm->NotifyPersons(array($pi_id),$subject,$body);
184 $_person= $plc->person;
185 $_roles= $_person['role_ids'];
187 // only admins are allowed to view this page
188 if( !in_array( '10', $_roles ) ) {
189 print("<p> not allowed to view this page </p>");
190 } else if (get_array($_GET, 'review')) {
192 drupal_set_title('Join Request - Review');
193 render_join_request_review($api, get_array($_GET, 'site_id'));
194 } else if (get_array($_POST, 'submitted')) {
196 $site_form = build_site_form(FALSE);
197 $input = parse_form ($site_form, $_REQUEST, $input);
198 // xxx should not happen ?
199 $empty_form = $input['is_empty'];
203 $error .= '<div class-"plc-warning">Internal error - empty form !?!</div>';
205 if (empty ($error)) {
206 $site=$input['site'];
207 $address=$input['address'];
209 $tech=$input['tech'];
211 // Look for missing/blank entries
212 $error .= form_check_required ($site_form, $input);
216 // get objects id from the request
217 $site_id = intval(trim($_POST['site_id']));
218 $address_id = intval(trim($_POST['address_id']));
219 $pi_id = intval(trim($_POST['pi_id']));
220 $tech_id = intval(trim($_POST['tech_id']));
222 switch ($_POST['submitted']) {
224 $api->DeleteSite ($site_id);
225 $api_error=$api->error();
226 if (!empty($api_error)) {
227 $error .= $api->error();
229 $messages [] = "Site " . $site['name'] . " deleted";
235 $api->UpdateSite($site_id,$site);
236 if ($address_id) $api->UpdateAddress($address_id,$address);
237 else if(!empty($address)) $api->AddSiteAddress($site_id,$address);
238 $api->UpdatePerson($pi_id,$pi);
239 if ($tech_id != $pi_id) $api->UpdatePerson($tech_id,$tech);
241 $api_error=$api->error();
242 if (!empty($api_error)) {
243 $error .= $api->error();
245 $messages [] = "Join request updated for site " . $site['name'] ;
251 // Thierry - august 22 2007
252 // keep it simple - the admin who approves is now supposed to check
253 // the PI's email address, which makes the whole thing *a lot* simpler
254 // enable the site, enable the PI, and VerifyPerson the thec if different from the PI
255 $site['enabled'] = True;
256 global $APPROVED_CONSORTIUM_ID;
257 $site['ext_consortium_id'] = $APPROVED_CONSORTIUM_ID;
258 $api->UpdateSite ($site_id,$site);
259 $api_error=$api->error();
260 if (!empty($api_error)) {
261 $error .= $api->error();
262 $messages [] = "Could not enable site";
264 $messages[] = l_site_t ($site_id,"Site '" . $site['name'] . "' enabled");
267 if (empty ($error) && $address_id) {
269 $api->UpdateAddress($address_id,$address);
270 $api_error=$api->error();
271 if ( ! empty($api_error)) {
272 $error .= $api->error();
273 $messages [] = "Could not update address";
276 foreach ( array("Billing","Shipping") as $address_type) {
277 $api->AddAddressTypeToAddress($address_type,$address_id);
278 $api_error=$api->error();
279 if ( ! empty($api_error)) {
280 $error .= $api->error();
281 $messages [] = "Could not add address type " . $address_type;
285 // Update pi, and enable him
286 $api->UpdatePerson ($pi_id,$pi);
287 if ( $pi ['enabled' ] ) {
288 $messages [] = "PI already enabled";
290 $api->UpdatePerson ($pi_id,array("enabled"=>True));
291 $api_error=$api->error();
292 if (empty($api_error)) {
293 $messages[] = "Enabled PI as " . $pi['email'] ;
294 notify_enabled_pi ($api, $pi_id,$pi,$site_id, $site);
295 $messages[] = "Notified PI by email";
297 $error .= $api->error();
298 $messages [] = "Could not update PI";
302 if ($pi_id != $tech_id) {
303 // Update tech, and VerifyPerson him if needed
304 $api->UpdatePerson ($tech_id,$tech);
305 if ( $tech [ 'enabled' ] ) {
306 $messages [] = "Tech already enabled";
308 $api->VerifyPerson($tech_id);
309 $api_error=$api->error();
310 if (empty($api_error)) {
311 $messages[] = "Created account registration for Tech as " . $tech['email'];
313 $error .= $api->error();
314 $messages [] = "Could not verify Tech";
323 $error .= '<div class-"plc-warning">Internal error - unexpected request</div>';
331 if (!empty($messages)) {
332 print '<div class="messages status"><ul>';
333 foreach ($messages as $line) {
339 // Show errors if any
340 if (!empty($error)) {
341 print '<div class="messages error">' . $error . '</div>';
342 drupal_set_title('Join Request - Review');
343 render_join_request_review($api, $_POST['site_id']);
345 drupal_set_title('All currently pending join requests');
346 render_all_join_requests($api);
350 else // list all pending requests
353 drupal_set_title('All currently pending join requests');
354 render_all_join_requests($api);
358 include 'plc_footer.php';