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';
15 require_once 'plc_drupal.php';
16 include 'plc_header.php';
19 require_once 'plc_functions.php';
20 require_once 'details.php';
21 require_once 'nifty.php';
22 require_once 'table.php';
23 require_once 'nifty.php';
25 include 'site_form.php';
27 ////////////////////////////////////////
28 function render_all_join_requests($api) {
29 global $PENDING_CONSORTIUM_ID;
30 $filter = array("peer_id" => NULL, "ext_consortium_id" => $PENDING_CONSORTIUM_ID);
31 $columns=array('site_id','name','enabled','date_created');
32 $sites = $api->GetSites( $filter, $columns);
34 print("<p> No open join requests </p>");
39 $headers['Site Name']='string';
40 # trying the sortEnglishDateTime stuff - not too lucky so far
41 # http://www.frequency-decoder.com/demo/table-sort-revisited/custom-sort-functions/
42 $headers['submitted']='sortEnglishDateTime';
43 $headers['enabled']='string';
45 $nifty=new PlekitNifty ('pending','sites-pending','medium');
47 $table=new PlekitTable ('pending',$headers,2,
48 array('pagesize_area'=>FALSE,'pagesize'=>10000));
50 foreach($sites as $site) {
51 $site_id=$site['site_id'];
52 $link = $site['enabled'] ? l_site($site_id) : l_site_review_pending($site_id);
54 $table->cell(href($link,$site['site_id']));
55 $table->cell(href($link,$site['name']));
56 $table->cell(date("dS F Y",$site['date_created']) . " at " . date("G:i",$site['date_created']));
57 $table->cell( $site['enabled'] ? plc_warning_html('yes') : 'no');
64 function render_join_request_review($api, $site_id) {
65 $sites = $api->GetSites( array(intval($site_id)) );
67 print("<p class='plc-warning'> Invalid request with site_id=$site_id</p> ");
71 if ($site['enabled'] && $site['ext_consortium_id'] === $PENDING_CONSORTIUM_ID) {
72 print("<p class='plc-warning'> This site is already enabled </p>");
75 $addresses = $api->GetAddresses ($site['address_ids']);
76 if (empty ($addresses)) {
77 drupal_set_message("Site $site_id has no address - never mind");
78 $address=array('line1'=>'');
81 $address = $addresses[0];
82 $address_id=$address['address_id'];
84 # just in case there is no person attached yet
85 if (empty ($site['person_ids'])) {
88 $person_ids = $site['person_ids'];
89 $persons = $api->GetPersons( $person_ids, array( "person_id", "role_ids", "first_name", "last_name", "title", "email" , "phone") );
93 foreach($persons as $person) {
94 if ( in_array('20', $person['role_ids']) ) {
97 if ( in_array('40', $person['role_ids']) ) {
101 $pi_id = $pi['person_id'];
102 $tech_id = $tech['person_id'];
105 <p> Please review the join request below.</p>
106 <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>
107 <form name="join_request" method="post" action="/db/sites/join_request.php">
108 <input type="hidden" name="pi_id" value="$pi_id">
109 <input type="hidden" name="address_id" value="$address_id">
110 <input type="hidden" name="tech_id" value="$tech_id">
111 <input type="hidden" name="site_id" value="$site_id">
114 // don't render the tech part if that was the same as the pi
115 $site_form = build_site_form(FALSE);
116 $input = array ('site' => $site, 'address'=> $address, 'pi' => $pi, 'tech' => $tech);
118 $nifty=new PlekitNifty ('pending','site-pending','medium');
121 $details = new PlekitDetails(TRUE);
124 // display the buttons
126 <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr>
127 <td align=center><input type="submit" name="submitted" value="Delete"></td>
128 <td align=center><input type="submit" name="submitted" value="Update"></td>
129 <td align=center><input type="submit" name="submitted" value="Approve"></td>
133 $details->tr($buttons_row,'center');
134 // render the form - not supposed to be empty
135 form_render_details ($details,$site_form, $input, TRUE);
137 // display the buttons again
138 $details->tr($buttons_row,'center');
145 function notify_enabled_pi ($api, $pi_id, $pi, $site_id, $site) {
148 You have filed a site registration with the %s platform.
150 This registration has been approved, and your account was enabled
151 You were granted a PI role, meaning that you will be responsible
152 for managing personal accounts and slices for your site
154 You can now enter the system at
157 and the password that you provided at registration-time
159 You can directly access your site information at
160 https://%s:%d/db/sites/index.php?id=%d
162 Please start with adding nodes for this site with
163 https://%s:%d/db/nodes/node_add.php
165 Our support team will be glad to answer any question that you might have
166 They are reachable at mailto:%s
169 $body=sprintf($template,
171 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
173 PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id,
174 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
175 PLC_MAIL_SUPPORT_ADDRESS);
177 $subject="Site registration for " . $site['name'] . " has been approved by " . PLC_NAME;
178 $api->NotifyPersons(array($pi_id),$subject,$body);
183 $_person= $plc->person;
184 $_roles= $_person['role_ids'];
186 // only admins are allowed to view this page
187 if( !in_array( '10', $_roles ) ) {
189 print("<p> not allowed to view this page </p>");
191 else if ($_GET['review'])
195 drupal_set_title('Join Request - Review');
196 render_join_request_review($api, $_GET['site_id']);
199 else if ($_POST['submitted'] )
203 $site_form = build_site_form(FALSE);
204 $input = parse_form ($site_form, $_REQUEST, $input);
205 // xxx should not happen ?
206 $empty_form = $input['is_empty'];
210 $error .= '<div class-"plc-warning">Internal error - empty form !?!</div>';
212 if (empty ($error)) {
213 $site=$input['site'];
214 $address=$input['address'];
216 $tech=$input['tech'];
218 // Look for missing/blank entries
219 $error .= form_check_required ($site_form, $input);
223 // get objects id from the request
224 $site_id = intval(trim($_POST['site_id']));
225 $address_id = intval(trim($_POST['address_id']));
226 $pi_id = intval(trim($_POST['pi_id']));
227 $tech_id = intval(trim($_POST['tech_id']));
229 switch ($_POST['submitted']) {
231 $api->DeleteSite ($site_id);
232 $api_error=$api->error();
233 if (!empty($api_error)) {
234 $error .= $api->error();
236 $messages [] = "Site " . $site['name'] . " deleted";
242 $api->UpdateSite($site_id,$site);
243 if ($address_id) $api->UpdateAddress($address_id,$address);
244 $api->UpdatePerson($pi_id,$pi);
245 if ($tech_id != $pi_id) $api->UpdatePerson($tech_id,$tech);
247 $api_error=$api->error();
248 if (!empty($api_error)) {
249 $error .= $api->error();
251 $messages [] = "Join request updated for site " . $site['name'] ;
257 // Thierry - august 22 2007
258 // keep it simple - the admin who approves is now supposed to check
259 // the PI's email address, which makes the whole thing *a lot* simpler
260 // enable the site, enable the PI, and VerifyPerson the thec if different from the PI
261 $site['enabled'] = True;
262 global $APPROVED_CONSORTIUM_ID;
263 $site['ext_consortium_id'] = $APPROVED_CONSORTIUM_ID;
264 $api->UpdateSite ($site_id,$site);
265 $api_error=$api->error();
266 if (!empty($api_error)) {
267 $error .= $api->error();
268 $messages [] = "Could not enable site";
270 $messages[] = l_site_t ($site_id,"Site '" . $site['name'] . "' enabled");
273 if (empty ($error) && $address_id) {
275 $api->UpdateAddress($address_id,$address);
276 $api_error=$api->error();
277 if ( ! empty($api_error)) {
278 $error .= $api->error();
279 $messages [] = "Could not update address";
282 foreach ( array("Billing","Shipping") as $address_type) {
283 $api->AddAddressTypeToAddress($address_type,$address_id);
284 $api_error=$api->error();
285 if ( ! empty($api_error)) {
286 $error .= $api->error();
287 $messages [] = "Could not add address type " . $address_type;
291 // Update pi, and enable him
292 $api->UpdatePerson ($pi_id,$pi);
293 if ( $pi ['enabled' ] ) {
294 $messages [] = "PI already enabled";
296 $api->UpdatePerson ($pi_id,array("enabled"=>True));
297 $api_error=$api->error();
298 if (empty($api_error)) {
299 $messages[] = "Enabled PI as " . $pi['email'] ;
300 notify_enabled_pi ($api, $pi_id,$pi,$site_id, $site);
301 $messages[] = "Notified PI by email";
303 $error .= $api->error();
304 $messages [] = "Could not update PI";
308 if ($pi_id != $tech_id) {
309 // Update tech, and VerifyPerson him if needed
310 $api->UpdatePerson ($tech_id,$tech);
311 if ( $tech [ 'enabled' ] ) {
312 $messages [] = "Tech already enabled";
314 $api->VerifyPerson($tech_id);
315 $api_error=$api->error();
316 if (empty($api_error)) {
317 $messages[] = "Created account registration for Tech as " . $tech['email'];
319 $error .= $api->error();
320 $messages [] = "Could not verify Tech";
329 $error .= '<div class-"plc-warning">Internal error - unexpected request</div>';
337 if (!empty($messages)) {
338 print '<div class="messages status"><ul>';
339 foreach ($messages as $line) {
345 // Show errors if any
346 if (!empty($error)) {
347 print '<div class="messages error">' . $error . '</div>';
348 drupal_set_title('Join Request - Review');
349 render_join_request_review($api, $_POST['site_id']);
351 drupal_set_title('All currently pending join requests');
352 render_all_join_requests($api);
356 else // list all pending requests
359 drupal_set_title('All currently pending join requests');
360 render_all_join_requests($api);
364 include 'plc_footer.php';