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';
23 include 'site_form.php';
25 ////////////////////////////////////////
26 function render_all_join_requests($api) {
27 $sites = $api->GetSites( array("enabled" => False, "peer_id" => NULL, "ext_consortium_id" => $PENDING_CONSORTIUM_ID));
29 print("<table width=100%>");
30 print("<tr><th>Site Name</th><th>site_id</th><th>Submitted</th></tr>");
31 foreach($sites as $site) {
32 printf("<tr><td><a href=/db/sites/join_request.php?review=t&site_id=%d> %s </a> </td>", $site['site_id'], $site['name']);
33 printf("<td><a href=/db/sites/join_request.php?review=t&site_id=%d> %d </a> </td>", $site['site_id'], $site['site_id']);
34 printf("<td> %s </td> </tr>", date("d F Y, G:i",$site['date_created']));
38 print("<p> No open join requests </p>");
42 function render_join_request_review($api, $site_id) {
43 $sites = $api->GetSites( array(intval($site_id)) );
45 print("<p class='plc-warning'> Invalid request with site_id=$site_id</p> ");
49 if ($site['enabled'] && $site['ext_consortium_id'] == $PENDING_CONSORTIUM_ID) {
50 print("<p class='plc-warning'> This site is already enabled </p>");
53 $addresses = $api->GetAddresses ($site['address_ids']);
54 if (empty ($addresses)) {
55 print("<p class='plc-warning'> No address found for site_id=$site_id</p> ");
58 $address = $addresses[0];
59 $address_id=$address['address_id'];
60 # just in case there is no person attached yet
61 if (empty ($site['person_ids'])) {
64 $person_ids = $site['person_ids'];
65 $persons = $api->GetPersons( $person_ids, array( "person_id", "role_ids", "first_name", "last_name", "title", "email" , "phone") );
69 foreach($persons as $person) {
70 if ( in_array('20', $person['role_ids']) ) {
73 if ( in_array('40', $person['role_ids']) ) {
77 $pi_id = $pi['person_id'];
78 $tech_id = $tech['person_id'];
81 <p> Please review the join request below.</p>
82 <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>
83 <form name="join_request" method="post" action="/db/sites/join_request.php">
84 <input type="hidden" name="pi_id" value="$pi_id">
85 <input type="hidden" name="address_id" value="$address_id">
86 <input type="hidden" name="tech_id" value="$tech_id">
87 <input type="hidden" name="site_id" value="$site_id">
90 $site_form = build_site_form(FALSE);
91 $input = array ('site' => $site, 'address'=> $address, 'pi' => $pi, 'tech' => $tech);
93 $nifty=new PlekitNifty ('pending','site-pending','medium');
96 $details = new PlekitDetails(TRUE);
99 // display the buttons
101 <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr>
102 <td align=center><input type="submit" name="submitted" value="Delete"></td>
103 <td align=center><input type="submit" name="submitted" value="Update"></td>
104 <td align=center><input type="submit" name="submitted" value="Approve"></td>
108 $details->tr($buttons_row,'center');
109 // render the form - not supposed to be empty
110 form_render_details ($details,$site_form, $input, TRUE);
112 // display the buttons again
113 $details->tr($buttons_row,'center');
120 function notify_enabled_pi ($api, $pi_id, $pi, $site_id, $site) {
123 You have filed a site registration with the %s platform.
125 This registration has been approved, and your account was enabled
126 You were granted a PI role, meaning that you will be responsible
127 for managing personal accounts and slices for your site
129 You can now enter the system at
132 and the password that you provided at registration-time
134 You can directly access your site information at
135 https://%s:%d/db/sites/index.php?id=%d
137 Please start with adding nodes for this site with
138 https://%s:%d/db/nodes/node_add.php
140 Our support team will be glad to answer any question that you might have
141 They are reachable at mailto:%s
144 $body=sprintf($template,
146 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
148 PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id,
149 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
150 PLC_MAIL_SUPPORT_ADDRESS);
152 $subject="Site registration for " . $site['name'] . " has been approved by " . PLC_NAME;
153 $api->NotifyPersons(array($pi_id),$subject,$body);
158 $_person= $plc->person;
159 $_roles= $_person['role_ids'];
161 // only admins are allowed to view this page
162 if( !in_array( '10', $_roles ) ) {
164 print("<p> not allowed to view this page </p>");
166 else if ($_GET['review'])
170 drupal_set_title('Join Request - Review');
171 render_join_request_review($api, $_GET['site_id']);
174 else if ($_POST['submitted'] )
178 $site_form = build_site_form(FALSE);
179 $input = parse_form ($site_form, $_REQUEST, $input);
180 // xxx should not happen ?
181 $empty_form = $input['is_empty'];
185 $error .= '<div class-"plc-warning">Internal error - empty form !?!</div>';
187 if (empty ($error)) {
188 $site=$input['site'];
189 $address=$input['address'];
191 $tech=$input['tech'];
193 // Look for missing/blank entries
194 $error .= form_check_required ($site_form, $input);
198 // get objects id from the request
199 $site_id = intval(trim($_POST['site_id']));
200 $address_id = intval(trim($_POST['address_id']));
201 $pi_id = intval(trim($_POST['pi_id']));
202 $tech_id = intval(trim($_POST['tech_id']));
204 switch ($_POST['submitted']) {
206 $api->DeleteSite ($site_id);
207 $api_error=$api->error();
208 if (!empty($api_error)) {
209 $error .= $api->error();
211 $messages [] = "Site " . $site['name'] . " deleted";
217 $api->UpdateSite($site_id,$site);
218 $api->UpdateAddress($address_id,$address);
219 $api->UpdatePerson($pi_id,$pi);
220 $api->UpdatePerson($tech_id,$tech);
222 $api_error=$api->error();
223 if (!empty($api_error)) {
224 $error .= $api->error();
226 $messages [] = "Join request updated for site " . $site['name'] ;
232 // Thierry - august 22 2007
233 // keep it simple - the admin who approves is now supposed to check
234 // the PI's email address, which makes the whole thing *a lot* simpler
235 // enable the site, enable the PI, and VerifyPerson the thec if different from the PI
236 $site['enabled'] = True;
237 $site['ext_consortium_id'] = $APPROVED_CONSORTIUM_ID;
238 $api->UpdateSite ($site_id,$site);
239 $api_error=$api->error();
240 if (!empty($api_error)) {
241 $error .= $api->error();
242 $messages [] = "Could not enable site";
244 $messages[] = "Site " . $site['name'] . " enabled";
247 if (empty ($error)) {
249 $api->UpdateAddress($address_id,$address);
250 $api_error=$api->error();
251 if ( ! empty($api_error)) {
252 $error .= $api->error();
253 $messages [] = "Could not update address";
256 foreach ( array("Billing","Shipping") as $address_type) {
257 $api->AddAddressTypeToAddress($address_type,$address_id);
258 $api_error=$api->error();
259 if ( ! empty($api_error)) {
260 $error .= $api->error();
261 $messages [] = "Could not add address type " . $address_type;
265 // Update pi, and enable him
266 $api->UpdatePerson ($pi_id,$pi);
267 if ( $pi ['enabled' ] ) {
268 $messages [] = "PI already enabled";
270 $api->UpdatePerson ($pi_id,array("enabled"=>True));
271 $api_error=$api->error();
272 if (empty($api_error)) {
273 $messages[] = "Enabled PI as " . $pi['email'] ;
274 notify_enabled_pi ($api, $pi_id,$pi,$site_id, $site);
275 $messages[] = "Notified PI by email";
277 $error .= $api->error();
278 $messages [] = "Could not update PI";
282 if ($pi_id != $tech_id) {
283 // Update tech, and VerifyPerson him if needed
284 $api->UpdatePerson ($tech_id,$tech);
285 if ( $tech [ 'enabled' ] ) {
286 $messages [] = "Tech already enabled";
288 $api->VerifyPerson($tech_id);
289 $api_error=$api->error();
290 if (empty($api_error)) {
291 $messages[] = "Created account registration for Tech as " . $tech['email'];
293 $error .= $api->error();
294 $messages [] = "Could not verify Tech";
303 $error .= '<div class-"plc-warning">Internal error - unexpected request</div>';
311 if (!empty($messages)) {
312 print '<div class="messages status"><ul>';
313 foreach ($messages as $line) {
319 // Show errors if any
320 if (!empty($error)) {
321 print '<div class="messages error">' . $error . '</div>';
322 drupal_set_title('Join Request - Review');
323 render_join_request_review($api, $_POST['site_id']);
325 drupal_set_title('All currently pending join requests');
326 render_all_join_requests($api);
330 else // list all pending requests
333 drupal_set_title('All currently pending join requests');
334 render_all_join_requests($api);
338 include 'plc_footer.php';