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 else if(!empty($address)) $api->AddSiteAddress($site_id,$address);
245 $api->UpdatePerson($pi_id,$pi);
246 if ($tech_id != $pi_id) $api->UpdatePerson($tech_id,$tech);
248 $api_error=$api->error();
249 if (!empty($api_error)) {
250 $error .= $api->error();
252 $messages [] = "Join request updated for site " . $site['name'] ;
258 // Thierry - august 22 2007
259 // keep it simple - the admin who approves is now supposed to check
260 // the PI's email address, which makes the whole thing *a lot* simpler
261 // enable the site, enable the PI, and VerifyPerson the thec if different from the PI
262 $site['enabled'] = True;
263 global $APPROVED_CONSORTIUM_ID;
264 $site['ext_consortium_id'] = $APPROVED_CONSORTIUM_ID;
265 $api->UpdateSite ($site_id,$site);
266 $api_error=$api->error();
267 if (!empty($api_error)) {
268 $error .= $api->error();
269 $messages [] = "Could not enable site";
271 $messages[] = l_site_t ($site_id,"Site '" . $site['name'] . "' enabled");
274 if (empty ($error) && $address_id) {
276 $api->UpdateAddress($address_id,$address);
277 $api_error=$api->error();
278 if ( ! empty($api_error)) {
279 $error .= $api->error();
280 $messages [] = "Could not update address";
283 foreach ( array("Billing","Shipping") as $address_type) {
284 $api->AddAddressTypeToAddress($address_type,$address_id);
285 $api_error=$api->error();
286 if ( ! empty($api_error)) {
287 $error .= $api->error();
288 $messages [] = "Could not add address type " . $address_type;
292 // Update pi, and enable him
293 $api->UpdatePerson ($pi_id,$pi);
294 if ( $pi ['enabled' ] ) {
295 $messages [] = "PI already enabled";
297 $api->UpdatePerson ($pi_id,array("enabled"=>True));
298 $api_error=$api->error();
299 if (empty($api_error)) {
300 $messages[] = "Enabled PI as " . $pi['email'] ;
301 notify_enabled_pi ($api, $pi_id,$pi,$site_id, $site);
302 $messages[] = "Notified PI by email";
304 $error .= $api->error();
305 $messages [] = "Could not update PI";
309 if ($pi_id != $tech_id) {
310 // Update tech, and VerifyPerson him if needed
311 $api->UpdatePerson ($tech_id,$tech);
312 if ( $tech [ 'enabled' ] ) {
313 $messages [] = "Tech already enabled";
315 $api->VerifyPerson($tech_id);
316 $api_error=$api->error();
317 if (empty($api_error)) {
318 $messages[] = "Created account registration for Tech as " . $tech['email'];
320 $error .= $api->error();
321 $messages [] = "Could not verify Tech";
330 $error .= '<div class-"plc-warning">Internal error - unexpected request</div>';
338 if (!empty($messages)) {
339 print '<div class="messages status"><ul>';
340 foreach ($messages as $line) {
346 // Show errors if any
347 if (!empty($error)) {
348 print '<div class="messages error">' . $error . '</div>';
349 drupal_set_title('Join Request - Review');
350 render_join_request_review($api, $_POST['site_id']);
352 drupal_set_title('All currently pending join requests');
353 render_all_join_requests($api);
357 else // list all pending requests
360 drupal_set_title('All currently pending join requests');
361 render_all_join_requests($api);
365 include 'plc_footer.php';