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';
18 require_once 'plc_drupal.php';
19 include 'plc_header.php';
21 include 'site_form.php';
23 ////////////////////////////////////////
24 function render_all_join_requests($api) {
25 $sites = $api->GetSites( array("enabled" => False, "peer_id" => NULL));
27 print("<table width=100%>");
28 print("<tr><th>Site Name</th><th>site_id</th><th>Submitted</th></tr>");
29 foreach($sites as $site) {
30 printf("<tr><td><a href=/db/sites/join_request.php?review=t&site_id=%d> %s </a> </td>", $site['site_id'], $site['name']);
31 printf("<td><a href=/db/sites/join_request.php?review=t&site_id=%d> %d </a> </td>", $site['site_id'], $site['site_id']);
32 printf("<td> %s </td> </tr>", date("d F Y, G:i",$site['date_created']));
36 print("<p> No open join requests </p>");
40 function render_join_request_review($api, $site_id) {
41 $sites = $api->GetSites( array(intval($site_id)) );
43 print("<p class='plc-warning'> Invalid request with site_id=$site_id</p> ");
47 if ($site['enabled']) {
48 print("<p class='plc-warning'> This site is already enabled </p>");
51 $addresses = $api->GetAddresses ($site['address_ids']);
52 if (empty ($addresses)) {
53 print("<p class='plc-warning'> No address found for site_id=$site_id</p> ");
56 $address = $addresses[0];
57 $address_id=$address['address_id'];
58 # just in case there is no person attached yet
59 if (empty ($site['person_ids'])) {
62 $person_ids = $site['person_ids'];
63 $persons = $api->GetPersons( $person_ids, array( "person_id", "role_ids", "first_name", "last_name", "email" , "phone") );
67 foreach($persons as $person) {
68 if ( in_array('20', $person['role_ids']) ) {
71 if ( in_array('40', $person['role_ids']) ) {
75 $pi_id = $pi['person_id'];
76 $tech_id = $tech['person_id'];
79 <p> Please review the join request below.</p>
80 <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>
81 <form name="join_request" method="post" action="/db/sites/join_request.php">
82 <input type="hidden" name="pi_id" value="$pi_id">
83 <input type="hidden" name="address_id" value="$address_id">
84 <input type="hidden" name="tech_id" value="$tech_id">
85 <input type="hidden" name="site_id" value="$site_id">
87 <table border="0" width="100%" cellspacing="0" cellpadding="3">
90 $site_form = build_site_form(FALSE);
91 $input = array ('site' => $site, 'address'=> $address, 'pi' => $pi, 'tech' => $tech);
93 // display the buttons
97 <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr>
98 <td align=center><input type="submit" name="submitted" value="Delete"></td>
99 <td align=center><input type="submit" name="submitted" value="Update"></td>
100 <td align=center><input type="submit" name="submitted" value="Approve"></td>
105 // render the form - not supposed to be empty
106 form_render_table2 ($site_form, $input, TRUE);
108 // display the buttons
112 <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr>
113 <td align=center><input type="submit" name="submitted" value="Delete"></td>
114 <td align=center><input type="submit" name="submitted" value="Update"></td>
115 <td align=center><input type="submit" name="submitted" value="Approve"></td>
120 print "</table></form>";
123 function notify_enabled_pi ($api, $pi_id, $pi, $site_id, $site) {
126 You have filed a site registration with the %s platform.
128 This registration has been approved, and your account was enabled
129 You were granted a PI role, meaning that you will be responsible
130 for managing personal accounts and slices for your site
132 You can now enter the system at
135 and the password that you provided at registration-time
137 You can directly access your site information at
138 https://%s:%d/db/sites/index.php?id=%d
140 Please start with adding nodes for this site with
141 https://%s:%d/db/nodes/node_add.php
143 Our support team will be glad to answer any question that you might have
144 They are reachable at mailto:%s
147 $body=sprintf($template,
149 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
151 PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id,
152 PLC_WWW_HOST,PLC_WWW_SSL_PORT,
153 PLC_MAIL_SUPPORT_ADDRESS);
155 $subject="Site registration for " . $site['name'] . " has been approved by " . PLC_NAME;
156 $api->NotifyPersons(array($pi_id),$subject,$body);
161 $_person= $plc->person;
162 $_roles= $_person['role_ids'];
164 // only admins are allowed to view this page
165 if( !in_array( '10', $_roles ) ) {
167 print("<p> not allowed to view this page </p>");
169 else if ($_GET['review'])
173 drupal_set_title('Join Request - Review');
174 render_join_request_review($api, $_GET['site_id']);
177 else if ($_POST['submitted'] )
181 $site_form = build_site_form(FALSE);
182 $input = parse_form ($site_form, $_REQUEST, $input);
183 // xxx should not happen ?
184 $empty_form = $input['is_empty'];
188 $error .= '<div class-"plc-warning">Internal error - empty form !?!</div>';
190 if (empty ($error)) {
191 $site=$input['site'];
192 $address=$input['address'];
194 $tech=$input['tech'];
196 // Look for missing/blank entries
197 $error .= form_check_required ($site_form, $input);
201 // get objects id from the request
202 $site_id = intval(trim($_POST['site_id']));
203 $address_id = intval(trim($_POST['address_id']));
204 $pi_id = intval(trim($_POST['pi_id']));
205 $tech_id = intval(trim($_POST['tech_id']));
207 switch ($_POST['submitted']) {
209 $api->DeleteSite ($site_id);
210 $api_error=$api->error();
211 if (!empty($api_error)) {
212 $error .= $api->error();
214 $messages [] = "Site " . $site['name'] . " deleted";
220 $api->UpdateSite($site_id,$site);
221 $api->UpdateAddress($address_id,$address);
222 $api->UpdatePerson($pi_id,$pi);
223 $api->UpdatePerson($tech_id,$tech);
225 $api_error=$api->error();
226 if (!empty($api_error)) {
227 $error .= $api->error();
229 $messages [] = "Join request updated for site " . $site['name'] ;
235 // Thierry - august 22 2007
236 // keep it simple - the admin who approves is now supposed to check
237 // the PI's email address, which makes the whole thing *a lot* simpler
238 // enable the site, enable the PI, and VerifyPerson the thec if different from the PI
239 $site['enabled'] = True;
240 $api->UpdateSite ($site_id,$site);
241 $api_error=$api->error();
242 if (!empty($api_error)) {
243 $error .= $api->error();
244 $messages [] = "Could not enable site";
246 $messages[] = "Site " . $site['name'] . " enabled";
249 if (empty ($error)) {
251 $api->UpdateAddress($address_id,$address);
252 $api_error=$api->error();
253 if ( ! empty($api_error)) {
254 $error .= $api->error();
255 $messages [] = "Could not update address";
258 foreach ( array("Billing","Shipping") as $address_type) {
259 $api->AddAddressTypeToAddress($address_type,$address_id);
260 $api_error=$api->error();
261 if ( ! empty($api_error)) {
262 $error .= $api->error();
263 $messages [] = "Could not add address type " . $address_type;
267 // Update pi, and enable him
268 $api->UpdatePerson ($pi_id,$pi);
269 if ( $pi ['enabled' ] ) {
270 $messages [] = "PI already enabled";
272 $api->UpdatePerson ($pi_id,array("enabled"=>True));
273 $api_error=$api->error();
274 if (empty($api_error)) {
275 $messages[] = "Enabled PI as " . $pi['email'] ;
276 notify_enabled_pi ($api, $pi_id,$pi,$site_id, $site);
277 $messages[] = "Notified PI by email";
279 $error .= $api->error();
280 $messages [] = "Could not update PI";
284 if ($pi_id != $tech_id) {
285 // Update tech, and VerifyPerson him if needed
286 $api->UpdatePerson ($tech_id,$tech);
287 if ( $tech [ 'enabled' ] ) {
288 $messages [] = "Tech already enabled";
290 $api->VerifyPerson($tech_id);
291 $api_error=$api->error();
292 if (empty($api_error)) {
293 $messages[] = "Created account registration for Tech as " . $tech['email'];
295 $error .= $api->error();
296 $messages [] = "Could not verify Tech";
305 $error .= '<div class-"plc-warning">Internal error - unexpected request</div>';
313 if (!empty($messages)) {
314 print '<div class="messages status"><ul>';
315 foreach ($messages as $line) {
321 // Show errors if any
322 if (!empty($error)) {
323 print '<div class="messages error">' . $error . '</div>';
324 drupal_set_title('Join Request - Review');
325 render_join_request_review($api, $_POST['site_id']);
327 drupal_set_title('All currently pending join requests');
328 render_all_join_requests($api);
332 else // list all pending requests
335 drupal_set_title('All currently pending join requests');
336 render_all_join_requests($api);
340 include 'plc_footer.php';