4 // Site registration and verification form.
6 // Thierry Parmentelat -- INRIA
7 // based on persons/register.php
10 // Get session and API handles
11 require_once 'plc_session.php';
12 global $plc, $api, $adm;
15 require_once 'plc_drupal.php';
16 drupal_set_title('New Site Registration');
17 include 'plc_header.php';
19 include 'site_form.php';
24 $objectnames = array ('site','pi','tech','address');
26 $site_form = build_site_form(TRUE);
27 $input = parse_form ($site_form, $_REQUEST, $input);
28 $empty_form = $input['is_empty'];
33 $address=$input['address'];
36 // Look for missing/blank entries
37 $error = form_check_required ($site_form, $input);
43 // I considered using begin/commit
44 // but first it was incorrectly reporting errors - which I fixed
45 // second: you need site_id to perform AddSiteAddress
46 // but you cannot write
49 // AddSiteAddress(site_id,..)
50 // because site_id would not be evaluated at the time you use it
52 // and you cannot either write
55 // AddSiteAddress('login_base',...)
56 // because if the first call fails because login_base is already taken,
57 // then you're going to add the new address to the wrong site
59 // the bottom line is, there's no advantage in using begin/commit at all
62 $site['enabled']=FALSE;
63 $site_id=$adm->AddSite($site);
64 $api_error .= $adm->error();
65 if (empty($api_error)) {
66 $verboses [] = "Site created as disabled";
74 // Thierry on august 22 2007
75 // use NotifySupport to send this message, and get rid of the fake account
77 $subject = "Site registration form : new site " . $site['name'];
78 // should use GetMessages and stuff, but I do not trust the way
79 // templates are created in db-config, for upgrades notably
81 We received a site registration form for site name %s
83 To review, please visit https://%s:%d/db/sites/join_request.php?review=t&site_id=%d.
85 $body=sprintf($template,$site['name'],PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id);
86 $adm->NotifySupport($subject,$body);
88 $messages [] = "Your registration request has been received.";
89 $messages [] = "A mail was sent to the operations team, your application should be processed shortly.";
90 $messages [] = "Upon approval, the PI will receive an information e-mail";
91 $messages [] = "Please send a message to " . PLC_MAIL_SUPPORT_ADDRESS . " if this request is not instructed within a few days.";
94 $adm->AddSiteAddress($site_id,$address);
95 $api_error = $adm->error();
96 if (empty($api_error)) {
97 $verboses [] = "Address created";
103 // Thierry 23 august 2007
104 // avoid using a pre-existing federated account
105 $known_pi = $adm->GetPersons(array("email"=>$pi['email'],
106 "peer_id"=>NULL),array("person_id"));
108 $messages [] = " Note: PI was already known";
109 $pi_id=$known_pi[0]['person_id'];
111 $pi['enabled']=FALSE;
112 $pi_id=$adm->AddPerson($pi);
113 $api_error = $adm->error();
114 if (empty($api_error)) {
115 $verboses [] = "PI created as disabled</p>";
117 $error .= $api_error;
120 if ($adm->AddPersonToSite($pi_id,$site_id)) {
121 $verboses [] = "PI attached to new site";
123 if ($adm->AddRoleToPerson('pi',$pi_id)) {
124 $verboses [] = $pi['email'] . " granted PI role</p>";
127 if ($pi['email'] == $tech['email']) {
128 // need to assign tech role so the registration request gets filled properly
129 if ($adm->AddRoleToPerson('tech',$pi_id)) {
130 $verboses [] = $pi['email'] . " granted Tech role</p>";
134 $known_tech = $adm->GetPersons(array("email"=>$tech['email'],
135 "peer_id"=>NULL),array("person_id"));
137 $messages [] = " Note: Tech was already known";
138 $tech_id=$known_tech[0]['person_id'];
140 $tech['enabled']=FALSE;
141 $tech_id=$adm->AddPerson($tech);
142 $api_error = $adm->error();
143 if (empty($api_error)) {
144 $verboses [] = "Tech created as disabled</p>";
146 $error .= $api_error;
149 if ($adm->AddPersonToSite($tech_id,$site_id)) {
150 $verboses [] = "Tech attached to new site";
152 if ($adm->AddRoleToPerson('tech',$tech_id)) {
153 $verboses [] = $tech['email'] . " granted Tech role";
155 if ( ($tech['user-role']) && $adm->AddRoleToPerson('user',$tech_id) ) {
156 $verboses [] = $tech['email'] . " granted User role";
163 if (!empty($messages)) {
164 print '<div class="messages status"><ul>';
165 foreach ($messages as $line) {
171 if ($verbose && !empty($verboses)) {
172 print '<div class="messages status"><ul>';
173 print "<p> Verbose messages</p>";
174 foreach ($verboses as $line) {
180 if (!empty($error)) {
181 print '<div class="messages error">' . $error . '</div>';
183 // to prevent resubmit
184 $site['site_id']="XXX";
188 $self = $_SERVER['PHP_SELF'];
189 if (!empty($_SERVER['QUERY_STRING'])) {
190 $self .= "?" . $_SERVER['QUERY_STRING'];
194 <div class="content">
196 <form action="$self" method="post">
198 <table border="0" width="100%" cellspacing="0" cellpadding="3">
201 // Do not allow resubmits
202 if (empty($site['site_id'])) {
203 print '<tr><td colspan=2 align=center><input type="submit" name="op" value="Register" class="form-submit" /></td></tr>';
206 form_render_table2 ($site_form, $input, ! $empty_form);
208 // Do not allow resubmits
209 if (empty($site['site_id'])) {
210 print '<tr><td colspan=2> </td></tr>';
211 print '<tr><td colspan=2 align=center><input type="submit" name="op" value="Register" class="form-submit" /></td></tr>';
214 print "</table></form></div>";
216 include 'plc_footer.php';