fixed: show no slices when user has no slices
[plewww.git] / planetlab / sites / register.php
index 7a79eda..56d2f7b 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-// $Id$
 //
 // Site registration and verification form. 
 //
@@ -34,6 +33,11 @@ $pi=$input['pi'];
 $tech=$input['tech'];
 $address=$input['address'];
 
+# allow address to be left out
+function non_empty_address ($address) {
+  return !empty($address['line1']);
+}
+
 if (! $empty_form ) {
   // Look for missing/blank entries
   $error = form_check_required ($site_form, $input);
@@ -62,10 +66,12 @@ if (! $empty_form ) {
     
     // creating the site
     $site['enabled']=FALSE;
+    global $PENDING_CONSORTIUM_ID;
+    $site['ext_consortium_id']=$PENDING_CONSORTIUM_ID;
     $site_id=$adm->AddSite($site);
     $api_error .= $adm->error();
     if (empty($api_error)) {
-      $verboses [] = "Site created as disabled";
+      $verboses [] = "Site created as disabled, with ext_consortium_id=".$PENDING_CONSORTIUM_ID;
     } else {
       $error .= $api_error;
     }
@@ -93,12 +99,14 @@ EOF;
     $messages [] = "Please send a message to " . PLC_MAIL_SUPPORT_ADDRESS . " if this request is not instructed within a few days.";
 
   // creating address
-    $adm->AddSiteAddress($site_id,$address);
-    $api_error = $adm->error();
-    if (empty($api_error)) {
-      $verboses [] = "Address created";
-    } else {
-      $error .= $api_error;
+    if (non_empty_address($address)) {
+      $adm->AddSiteAddress($site_id,$address);
+      $api_error = $adm->error();
+      if (empty($api_error)) {
+       $verboses [] = "Address created";
+      } else {
+       $error .= $api_error;
+      }
     }
 
     // creating PI
@@ -135,6 +143,11 @@ EOF;
       // creating TECH
       $known_tech = $adm->GetPersons(array("email"=>$tech['email'],
                                           "peer_id"=>NULL),array("person_id"));
+      // jan-2013 with improvements in plcapi-5.1-6 about managing persons and tags,
+      // AddPerson has gone more picky and we need to remove some fields
+      // that no longer are silently ignored by AddPerson
+      $user_role_required=$tech['user-role'];
+      unset($tech['user-role']);
       if ($known_tech) {
        $messages [] = " Note: Tech was already known";
        $tech_id=$known_tech[0]['person_id'];
@@ -154,7 +167,7 @@ EOF;
       if ($adm->AddRoleToPerson('tech',$tech_id)) {
        $verboses [] = $tech['email'] . " granted Tech role";
       }
-      if ( ($tech['user-role']) && $adm->AddRoleToPerson('user',$tech_id) ) {
+      if ( $user_role_required && $adm->AddRoleToPerson('user',$tech_id) ) {
        $verboses [] = $tech['email'] . " granted User role";
       }
     }