fixed: show no slices when user has no slices
[plewww.git] / planetlab / sites / site_form.php
index 7e06ed0..88cc490 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: site_form.php 823 2007-09-07 10:13:27Z thierry $
+// $Id$
 
 // Drupalish, but does not use Drupal itself to generate the form
 
@@ -9,38 +9,21 @@ function build_site_form ($register_mode) {
   $form = array();
   $form['site:name'] = array('title' => 'Site name', 'required' => TRUE,
                             'maxlength' => 40, 'size' => 20,
-                            'comment' => '<strong>Site Information</strong>:');
+                            'comment' => '<span class="bold">Site Information</span>');
   $form['site:login_base'] = array('title' => 'Login base', 'required' => TRUE,
                                   'maxlength' => 16, 'size' => 10);
   $form['site:abbreviated_name'] = array('title' => 'Abbreviated name', 'required' => TRUE,
-                                        'maxlength' => 20, 'size' => 12);
+                                        'maxlength' => 40, 'size' => 20);
   $form['site:url'] = array('title' => 'URL', 'required' => TRUE,
-                           'maxlength' => 30, 'size' => 30);
-  $form['site:latitude'] = array('title' => 'Latitude', 'required' => FALSE,
+                           'maxlength' => 128, 'size' => 30);
+  $form['site:latitude'] = array('title' => 'Latitude', 'required' => TRUE,
                                 'maxlength' => 10, 'size' => 10, 'type' => 'double');
-  $form['site:longitude'] = array('title' => 'Longitude', 'required' => FALSE,
+  $form['site:longitude'] = array('title' => 'Longitude', 'required' => TRUE,
                                  'maxlength' => 10, 'size' => 10, 'type' => 'double');
 
-  $form['address:line1'] = array('title' => 'Address', 'required' => TRUE,
-                                'maxlength' => 40, 'size' => 30,
-                                'comment' => '<strong>Postal address</strong>:');
-  $form['address:line2'] = array('title' => 'Address (2)', 'required' => FALSE,
-                                'maxlength' => 40, 'size' => 30);
-  $form['address:line3'] = array('title' => 'Address (3)', 'required' => FALSE,
-                                'maxlength' => 40, 'size' => 30);
-  $form['address:city'] = array('title' => 'City', 'required' => TRUE,
-                               'maxlength' => 20, 'size' => 20);
-  $form['address:postalcode'] = array('title' => 'Postal Code', 'required' => TRUE,
-                                     'maxlength' => 10, 'size' => 10);
-# would have liked it *not* required but it is mandatory in the DB - sigh
-  $form['address:state'] = array('title' => 'State', 'required' => TRUE,
-                                'maxlength' => 20, 'size' => 20);
-  $form['address:country'] = array('title' => 'Country', 'required' => TRUE,
-                                  'maxlength' => 20, 'size' => 20);
-
   $form['pi:first_name'] = array('title' => 'PI First Name', 'required' => TRUE,
                                 'maxlength' => 20, 'size' => 20,
-                                'comment' => '<strong>Principal Investigator Information</strong>:');
+                                'comment' => '<span class="bold">Principal Investigator Information</span>');
   $form['pi:last_name'] = array('title' => 'PI Last Name', 'required' => TRUE,
                                'maxlength' => 20, 'size' => 20);
   $form['pi:title'] = array('title' => 'PI Title', 'required' => FALSE,
@@ -57,7 +40,7 @@ function build_site_form ($register_mode) {
 
   if ($register_mode) {
     // required for the following code
-    drupal_set_html_head('<script type="text/javascript" src="/planetlab/includes/plc_script.js"></script>');
+    drupal_set_html_head('<script type="text/javascript" src="/planetlab/sites/site_form.js"></script>');
 
     $fill_from_pi_button = <<< EOF
 <input type="button" value="Same as PI" onclick='copyValue("edit-pi:first_name","edit-tech:first_name");
@@ -73,7 +56,7 @@ EOF;
 
   $form['tech:first_name'] = array('title' => 'Tech First Name', 'required' => TRUE,
                                   'maxlength' => 20, 'size' => 20,
-                                  'comment' => '<strong>Technical Contact Information</strong>:' . $fill_from_pi_button);
+                                  'comment' => '<span class="bold">Technical Contact Information</span>' . $fill_from_pi_button);
   $form['tech:last_name'] = array('title' => 'Tech Last Name', 'required' => TRUE,
                                  'maxlength' => 20, 'size' => 20);
   $form['tech:title'] = array('title' => 'Tech Title', 'required' => FALSE,
@@ -88,6 +71,23 @@ EOF;
     $form['tech:user-role'] = array('type' => 'boolean', 'title' => 'Need user role', 'default' => TRUE);
   }
 
+  $form['address:line1'] = array('title' => 'Address', 'required' => FALSE,
+                                'maxlength' => 40, 'size' => 30,
+                                'comment' => '<span class="bold">Postal address</span>');
+  $form['address:line2'] = array('title' => 'Address (2)', 'required' => FALSE,
+                                'maxlength' => 40, 'size' => 30);
+  $form['address:line3'] = array('title' => 'Address (3)', 'required' => FALSE,
+                                'maxlength' => 40, 'size' => 30);
+  $form['address:city'] = array('title' => 'City', 'required' => FALSE,
+                               'maxlength' => 20, 'size' => 20);
+  $form['address:postalcode'] = array('title' => 'Postal Code', 'required' => FALSE,
+                                     'maxlength' => 10, 'size' => 10);
+# would have liked it *not* required but it is mandatory in the DB - sigh
+  $form['address:state'] = array('title' => 'State', 'required' => FALSE,
+                                'maxlength' => 20, 'size' => 20);
+  $form['address:country'] = array('title' => 'Country', 'required' => FALSE,
+                                  'maxlength' => 20, 'size' => 20);
+
   return $form;
 }
 
@@ -108,7 +108,7 @@ function parse_form ($form, $request, $input = NULL) {
 
   // fill with values form the form
   foreach ($form as $fullname => $item) {
-    list($objname,$field) = split(":",$fullname);
+    list($objname,$field) = explode(":",$fullname);
     $raw_input=$request[$fullname];
     if (!empty($raw_input)) {
       $empty_form = FALSE;
@@ -161,7 +161,7 @@ function parse_form ($form, $request, $input = NULL) {
 function form_check_required ($form, $input) {
   $missing = array();
   foreach ($form as $fullname => $item) {
-    list($objname,$field) = split(":",$fullname);
+    list($objname,$field) = explode(":",$fullname);
     if ($item['required'] && empty($input[$objname][$field])) {
       $missing[] = $item['title'];
     }
@@ -180,16 +180,16 @@ function form_check_required ($form, $input) {
 // if $outline_missing is set, missing required fields are outlined
 // fields typed as 'password' are displayed differently
 // expected to be embedded in a table with 2 columns
-function form_render_table2 ($form, $input, $outline_missing) {
+function form_render_details ($details, $site_form, $input, $outline_missing) {
 
-  foreach ($form as $fullname => $item) {
+  foreach ($site_form as $fullname => $item) {
     
-    list($objname,$field) = split(":",$fullname);
+    list($objname,$field) = explode(":",$fullname);
     
     // render the comment field
     if ( ! empty($item['comment'])) {
-      $comment=$item['comment'];
-      print "<tr><td colspan=2> $comment </td></tr>";
+      $details->space();
+      $details->tr ($item['comment'] . ":");
     }
 
     // compute line attributes
@@ -201,10 +201,7 @@ function form_render_table2 ($form, $input, $outline_missing) {
     }
 
     // Label part
-    print "<tr>";
-    print <<<EOF
-      <td> <label class="$class" for="edit-$fullname">$title: $required</label> </td>\n
-EOF;
+    $left_part = "<label class='$class' for='edit-$fullname'>$title: $required</label>";
 
     // input part
     if ($item['type'] == 'boolean') {
@@ -221,25 +218,23 @@ EOF;
        $checkedyes = "";
        $checkedno = "checked='checked'";
       }
-      print <<< EOF
-<td>
+      $right_part = <<<EOF
 <input type='radio' id="check-$fullname" name="$fullname" value="yes" $checkedyes> Yes
 <input type='radio' id="check-$fullname" name="$fullname" value="no"  $checkedno> No
-</td>\n
 EOF;
     } else {
       $type = ($item['type'] == 'password') ? "password" : "text";
       $value = !empty($input[$objname][$field]) ? $input[$objname][$field] : "";
       $maxlength = $item['maxlength'];
       $size = $item['size'];
-      print <<<EOF
-<td><input type="$type" id="edit-$fullname" name="$fullname" value="$value" 
+      $right_part= <<<EOF
+<input type="$type" id="edit-$fullname" name="$fullname" value="$value" 
 size="$size" maxlength="$maxlength" 
-class="form-text $class" /> </td>\n
+class="form-text $class" /> 
 EOF;
     }
 
-    print "</tr>\n";
+    $details->th_td($left_part,$right_part);
   }
 }