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_functions.php';
16 require_once 'plc_sorts.php';
19 require_once 'plc_drupal.php';
20 include 'plc_header.php';
22 include 'site_form.php';
24 ////////////////////////////////////////
25 function render_all_join_requests($api) {
26 $sites = $api->GetSites( array("enabled" => False, "peer_id" => NULL));
28 print("<table width=100%>");
29 print("<tr><th>Site Name</th><th>site_id</th><th>Submitted</th></tr>");
30 foreach($sites as $site) {
31 printf("<tr><td><a href=/db/sites/join_request.php?review=t&site_id=%d> %s </a> </td>", $site['site_id'], $site['name']);
32 printf("<td><a href=/db/sites/join_request.php?review=t&site_id=%d> %d </a> </td>", $site['site_id'], $site['site_id']);
33 printf("<td> %s </td> </tr>", date("d F Y, G:i",$site['date_created']));
37 print("<p> No open join requests </p>");
41 function render_join_request_review($api, $site_id) {
42 $sites = $api->GetSites( array(intval($site_id)) );
44 print("<p class='plc-warning'> Invalid request with site_id=$site_id</p> ");
48 if ($site['enabled']) {
49 print("<p class='plc-warning'> This site is already enabled </p>");
52 $addresses = $api->GetAddresses ($site['address_ids']);
53 if (empty ($addresses)) {
54 print("<p class='plc-warning'> No address found for site_id=$site_id</p> ");
57 $address = $addresses[0];
58 $address_id=$address['address_id'];
59 # just in case there is no person attached yet
60 if (empty ($site['person_ids'])) {
63 $person_ids = $site['person_ids'];
64 $persons = $api->GetPersons( $person_ids, array( "person_id", "role_ids", "first_name", "last_name", "email" , "phone") );
68 foreach($persons as $person) {
69 if ( in_array('20', $person['role_ids']) ) {
72 if ( in_array('40', $person['role_ids']) ) {
76 $pi_id = $pi['person_id'];
77 $tech_id = $tech['person_id'];
80 <p> Please review the join request below.</p>
81 <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>
82 <form name="join_request" method="post" action="/db/sites/join_request.php">
83 <input type="hidden" name="pi_id" value="$pi_id">
84 <input type="hidden" name="address_id" value="$address_id">
85 <input type="hidden" name="tech_id" value="$tech_id">
86 <input type="hidden" name="site_id" value="$site_id">
88 <table border="0" width="100%" cellspacing="0" cellpadding="3">
91 $site_form = build_site_form(FALSE);
92 $input = array ('site' => $site, 'address'=> $address, 'pi' => $pi, 'tech' => $tech);
94 // display the buttons
98 <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr>
99 <td align=center><input type="submit" name="submitted" value="Delete"></td>
100 <td align=center><input type="submit" name="submitted" value="Update"></td>
101 <td align=center><input type="submit" name="submitted" value="Approve"></td>
106 // render the form - not supposed to be empty
107 form_render_table2 ($site_form, $input, TRUE);
109 // display the buttons
113 <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr>
114 <td align=center><input type="submit" name="submitted" value="Delete"></td>
115 <td align=center><input type="submit" name="submitted" value="Update"></td>
116 <td align=center><input type="submit" name="submitted" value="Approve"></td>
121 print "</table></form>";
124 function notify_enabled_pi ($api, $pi_id, $pi, $site_id, $site) {
127 You have filed a site registration with the %s platform.
129 This registration has been approved, and your account was enabled
130 You were granted a PI role, meaning that you will be responsible
131 for managing personal accounts and slices for your site
133 You can now enter the system at
136 and the password that you provided at registration-time
138 You can directly access your site information at
139 https://%s:%d/db/sites/index.php?id=%d
141 Please start with adding nodes for this site with
142 https://%s:%d/db/nodes/node_add.php
144 Our support team will be glad to answer any question that you might have
145 They are reachable at mailto:%s
148 $body=sprintf($template,
150 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
152 PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id,
153 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
154 PLC_MAIL_SUPPORT_ADDRESS);
156 $subject="Site registration for " . $site['name'] . " has been approved by " . PLC_NAME;
157 $api->NotifyPersons(array($pi_id),$subject,$body);
162 $_person= $plc->person;
163 $_roles= $_person['role_ids'];
165 // only admins are allowed to view this page
166 if( !in_array( '10', $_roles ) ) {
168 print("<p> not allowed to view this page </p>");
170 else if ($_GET['review'])
174 drupal_set_title('Join Request - Review');
175 render_join_request_review($api, $_GET['site_id']);
178 else if ($_POST['submitted'] )
182 $site_form = build_site_form(FALSE);
183 $input = parse_form ($site_form, $_REQUEST, $input);
184 // xxx should not happen ?
185 $empty_form = $input['is_empty'];
189 $error .= '<div class-"plc-warning">Internal error - empty form !?!</div>';
191 if (empty ($error)) {
192 $site=$input['site'];
193 $address=$input['address'];
195 $tech=$input['tech'];
197 // Look for missing/blank entries
198 $error .= form_check_required ($site_form, $input);
202 // get objects id from the request
203 $site_id = intval(trim($_POST['site_id']));
204 $address_id = intval(trim($_POST['address_id']));
205 $pi_id = intval(trim($_POST['pi_id']));
206 $tech_id = intval(trim($_POST['tech_id']));
208 switch ($_POST['submitted']) {
210 $api->DeleteSite ($site_id);
211 $api_error=$api->error();
212 if (!empty($api_error)) {
213 $error .= $api->error();
215 $messages [] = "Site " . $site['name'] . " deleted";
221 $api->UpdateSite($site_id,$site);
222 $api->UpdateAddress($address_id,$address);
223 $api->UpdatePerson($pi_id,$pi);
224 $api->UpdatePerson($tech_id,$tech);
226 $api_error=$api->error();
227 if (!empty($api_error)) {
228 $error .= $api->error();
230 $messages [] = "Join request updated for site " . $site['name'] ;
236 // Thierry - august 22 2007
237 // keep it simple - the admin who approves is now supposed to check
238 // the PI's email address, which makes the whole thing *a lot* simpler
239 // enable the site, enable the PI, and VerifyPerson the thec if different from the PI
240 $site['enabled'] = True;
241 $api->UpdateSite ($site_id,$site);
242 $api_error=$api->error();
243 if (!empty($api_error)) {
244 $error .= $api->error();
245 $messages [] = "Could not enable site";
247 $messages[] = "Site " . $site['name'] . " enabled";
250 if (empty ($error)) {
252 $api->UpdateAddress($address_id,$address);
253 $api_error=$api->error();
254 if ( ! empty($api_error)) {
255 $error .= $api->error();
256 $messages [] = "Could not update address";
259 foreach ( array("Billing","Shipping") as $address_type) {
260 $api->AddAddressTypeToAddress($address_type,$address_id);
261 $api_error=$api->error();
262 if ( ! empty($api_error)) {
263 $error .= $api->error();
264 $messages [] = "Could not add address type " . $address_type;
268 // Update pi, and enable him
269 $api->UpdatePerson ($pi_id,$pi);
270 if ( $pi ['enabled' ] ) {
271 $messages [] = "PI already enabled";
273 $api->UpdatePerson ($pi_id,array("enabled"=>True));
274 $api_error=$api->error();
275 if (empty($api_error)) {
276 $messages[] = "Enabled PI as " . $pi['email'] ;
277 notify_enabled_pi ($api, $pi_id,$pi,$site_id, $site);
278 $messages[] = "Notified PI by email";
280 $error .= $api->error();
281 $messages [] = "Could not update PI";
285 if ($pi_id != $tech_id) {
286 // Update tech, and VerifyPerson him if needed
287 $api->UpdatePerson ($tech_id,$tech);
288 if ( $tech [ 'enabled' ] ) {
289 $messages [] = "Tech already enabled";
291 $api->VerifyPerson($tech_id);
292 $api_error=$api->error();
293 if (empty($api_error)) {
294 $messages[] = "Created account registration for Tech as " . $tech['email'];
296 $error .= $api->error();
297 $messages [] = "Could not verify Tech";
306 $error .= '<div class-"plc-warning">Internal error - unexpected request</div>';
314 if (!empty($messages)) {
315 print '<div class="messages status"><ul>';
316 foreach ($messages as $line) {
322 // Show errors if any
323 if (!empty($error)) {
324 print '<div class="messages error">' . $error . '</div>';
325 drupal_set_title('Join Request - Review');
326 render_join_request_review($api, $_POST['site_id']);
328 drupal_set_title('All currently pending join requests');
329 render_all_join_requests($api);
333 else // list all pending requests
336 drupal_set_title('All currently pending join requests');
337 render_all_join_requests($api);
341 include 'plc_footer.php';