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 require_once 'site_form.php';
20 require_once 'details.php';
21 require_once 'nifty.php';
26 $objectnames = array ('site','pi','tech','address');
28 $site_form = build_site_form(TRUE);
29 $input = parse_form ($site_form, $_REQUEST, $input);
30 $empty_form = $input['is_empty'];
35 $address=$input['address'];
38 // Look for missing/blank entries
39 $error = form_check_required ($site_form, $input);
45 // I considered using begin/commit
46 // but first it was incorrectly reporting errors - which I fixed
47 // second: you need site_id to perform AddSiteAddress
48 // but you cannot write
51 // AddSiteAddress(site_id,..)
52 // because site_id would not be evaluated at the time you use it
54 // and you cannot either write
57 // AddSiteAddress('login_base',...)
58 // because if the first call fails because login_base is already taken,
59 // then you're going to add the new address to the wrong site
61 // the bottom line is, there's no advantage in using begin/commit at all
64 $site['enabled']=FALSE;
65 $site_id=$adm->AddSite($site);
66 $api_error .= $adm->error();
67 if (empty($api_error)) {
68 $verboses [] = "Site created as disabled";
76 // Thierry on august 22 2007
77 // use NotifySupport to send this message, and get rid of the fake account
79 $subject = "Site registration form : new site " . $site['name'];
80 // should use GetMessages and stuff, but I do not trust the way
81 // templates are created in db-config, for upgrades notably
83 We received a site registration form for site name %s
85 To review, please visit https://%s:%d/db/sites/join_request.php?review=t&site_id=%d.
87 $body=sprintf($template,$site['name'],PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id);
88 $adm->NotifySupport($subject,$body);
90 $messages [] = "Your registration request has been received.";
91 $messages [] = "A mail was sent to the operations team, your application should be processed shortly.";
92 $messages [] = "Upon approval, the PI will receive an information e-mail";
93 $messages [] = "Please send a message to " . PLC_MAIL_SUPPORT_ADDRESS . " if this request is not instructed within a few days.";
96 $adm->AddSiteAddress($site_id,$address);
97 $api_error = $adm->error();
98 if (empty($api_error)) {
99 $verboses [] = "Address created";
101 $error .= $api_error;
105 // Thierry 23 august 2007
106 // avoid using a pre-existing federated account
107 $known_pi = $adm->GetPersons(array("email"=>$pi['email'],
108 "peer_id"=>NULL),array("person_id"));
110 $messages [] = " Note: PI was already known";
111 $pi_id=$known_pi[0]['person_id'];
113 $pi['enabled']=FALSE;
114 $pi_id=$adm->AddPerson($pi);
115 $api_error = $adm->error();
116 if (empty($api_error)) {
117 $verboses [] = "PI created as disabled</p>";
119 $error .= $api_error;
122 if ($adm->AddPersonToSite($pi_id,$site_id)) {
123 $verboses [] = "PI attached to new site";
125 if ($adm->AddRoleToPerson('pi',$pi_id)) {
126 $verboses [] = $pi['email'] . " granted PI role</p>";
129 if ($pi['email'] == $tech['email']) {
130 // need to assign tech role so the registration request gets filled properly
131 if ($adm->AddRoleToPerson('tech',$pi_id)) {
132 $verboses [] = $pi['email'] . " granted Tech role</p>";
136 $known_tech = $adm->GetPersons(array("email"=>$tech['email'],
137 "peer_id"=>NULL),array("person_id"));
139 $messages [] = " Note: Tech was already known";
140 $tech_id=$known_tech[0]['person_id'];
142 $tech['enabled']=FALSE;
143 $tech_id=$adm->AddPerson($tech);
144 $api_error = $adm->error();
145 if (empty($api_error)) {
146 $verboses [] = "Tech created as disabled</p>";
148 $error .= $api_error;
151 if ($adm->AddPersonToSite($tech_id,$site_id)) {
152 $verboses [] = "Tech attached to new site";
154 if ($adm->AddRoleToPerson('tech',$tech_id)) {
155 $verboses [] = $tech['email'] . " granted Tech role";
157 if ( ($tech['user-role']) && $adm->AddRoleToPerson('user',$tech_id) ) {
158 $verboses [] = $tech['email'] . " granted User role";
165 if (!empty($messages)) {
166 print '<div class="messages status"><ul>';
167 foreach ($messages as $line) {
173 if ($verbose && !empty($verboses)) {
174 print '<div class="messages status"><ul>';
175 print "<p> Verbose messages</p>";
176 foreach ($verboses as $line) {
182 if (!empty($error)) {
183 print '<div class="messages error">' . $error . '</div>';
185 // to prevent resubmit
186 $site['site_id']="XXX";
190 $self = $_SERVER['PHP_SELF'];
191 if (!empty($_SERVER['QUERY_STRING'])) {
192 $self .= "?" . $_SERVER['QUERY_STRING'];
196 <div class="content">
198 <form action="$self" method="post">
202 $nifty=new PlekitNifty ('register','site-register','medium');
204 $details = new PlekitDetails(TRUE);
207 $register_button='<input type="submit" name="op" value="Register" class="form-submit" />';
209 // Do not allow resubmits
210 if (empty($site['site_id'])) {
211 $details->tr($register_button,'center');
214 form_render_details ($details, $site_form, $input, ! $empty_form);
216 // Do not allow resubmits
217 if (empty($site['site_id'])) {
220 $details->tr($register_button,'center');
225 print "</form></div>";
227 include 'plc_footer.php';