handling toggle parts visible tag: now rely on local storage, so avoid
[plewww.git] / planetlab / nodes / node_add.php
index 78b5e3b..cbcb3d0 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-// $Id$ 
-
 // Require login
 require_once 'plc_login.php';
 
@@ -11,14 +9,20 @@ global $plc, $api;
 
 // Common functions
 require_once 'plc_functions.php';
+require_once 'toggle.php';
 require_once 'details.php';
 require_once 'form.php';
   
 // if not a admin, pi, or tech then redirect to node index
 // xxx does not take site into account
-$has_privileges=plc_is_admin() || plc_is_pi() || plc_is_tech();
+$has_privileges=plc_is_admin();
+$is_pi_or_tech=plc_is_pi() || plc_is_tech();
 if( ! $has_privileges) {
-  drupal_set_error ("Insufficient provileges to add a node");
+  if ( $is_pi_or_tech) {
+    drupal_goto(l_register_node());
+    return 0;
+  }
+  drupal_set_error ("Insufficient privileges to add a node");
   header( "index.php" );
   return 0;
 }
@@ -32,10 +36,12 @@ if ( $_POST['add-node'] )  {
 
   $errors= array();
 
+  $site_id = trim($_POST['site_id']);
   $hostname = trim($_POST['hostname']);
   $model= trim($_POST['model']);
-  $ip = trim($_POST['ip']);
+  $node_type = trim ($_POST['node_type']);
   $method = trim($_POST['method']);
+  $ip = trim($_POST['ip']);
   $netmask = trim($_POST['netmask']);
   $network = trim($_POST['network']);
   $broadcast = trim($_POST['broadcast']);
@@ -79,8 +85,7 @@ if ( $_POST['add-node'] )  {
     drupal_set_error(plc_itemize($errors));
   } else {
     // add new node and its interface
-    $node_fields= array( "hostname"=>$hostname, "model"=>$model );
-    $site_id= plc_my_site_id();
+    $node_fields= array( "hostname"=>$hostname, "model"=>$model , "node_type" => $node_type);
     $node_id= $api->AddNode( intval( $site_id ), $node_fields );
 
     if ( empty($node_id) || ($node_id < 0) ) {
@@ -136,39 +141,63 @@ drupal_set_html_head ('
 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
 ');
 
-$sites=$api->GetSites(array(plc_my_site_id()));
-$site=$sites[0];
-$sitename=$site['name'];
-                      
-drupal_set_title('Add a new node in site "' . $sitename . '"');
+drupal_set_title('Add a new node to site');
 
 // defaults
-$method = $_POST['method'];
-if( ! $method ) $method= "static";
-
 $model = $_POST['model'];
 if( ! $model ) $model= "Custom";
 
+$node_type = $_POST['node_type'];
+if ( ! $node_type ) $node_type= "regular";
+
+$method = $_POST['method'];
+if( ! $method ) $method= "static";
+
 print <<< EOF
 <p class='node_add'>
-This page lets you declare a new machine in your site. 
-This must be done before the machine is turned on, as it will allow you to download a boot image when complete for this node.
+This page lets you declare a new machine to a site.
+<br/>
+This must be done before the machine is turned on, 
+as it will allow you to download a boot image when complete for this node.
+<br/>
+It is now reserved to admins, as regular users are supposed to use the register wizard, that among other things enforces PCU deployment.
 <br/>
-You must enter an IP address even if you use DHCP.
+An IP address is required even if you use DHCP.
 </p>
 EOF;
 
+$toggle = new PlekitToggle ('add-node',"Add Node",
+                           array('bubble'=>'Add a node - does not enforce PCU - for admins only !',
+                                 'visible'=>get_arg('show_details')));
+$toggle->start();
+
 $details=new PlekitDetails($has_privileges);
 
 // xxx hardwire network type for now
 $form_variables = array('type'=>"ipv4");
 //$form=$details->form_start(l_actions(),$form_variables);
-$form=$details->form_start('/db/nodes/node_add.php',$form_variables);
+$form=$details->form_start('/db/nodes/node_add.php',$form_variables,
+                          array('onSubmit'=>'return interfaceSubmit()'));
 
 $details->start();
 
+$site_columns=array( "site_id", "name", "login_base" );
+$local_sites= $api->GetSites( array("peer_id"=>NULL, '-SORT'=>'name'), $site_columns );
+function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
+$site_selector = array_map ("site_selector",$local_sites);
+$site_select = $form->select_html("site_id", $site_selector, array('id'=>'site_id'));
+$details->th_td("Site",
+                $site_select,
+                "site_id",
+                array('input_type'=>'select','value'=>$interface['site_id']));
+
 $details->th_td("Hostname",$hostname,"hostname");
 $details->th_td("Model",$model,"model");
+$node_type_select = $form->select_html ("node_type",
+                                      node_type_selectors($api,$node_type),
+                                      array('id'=>'node_type'));
+$details->th_td("Reservation",$node_type_select,"node_type",
+               array('input_type'=>'select','value'=>$node_type));
 $method_select = $form->select_html ("method",
                                     interface_method_selectors($api,$method,true),
                                     array('id'=>'method',
@@ -198,12 +227,12 @@ $details->space();
 $details->th_td("BW limit (bps)",$bwlimit,"bwlimit",array('width'=>11));
 
 // the buttons
-$add_button = $form->submit_html ("add-node","Add New Node",
-                                 array('onSubmit'=>'interfaceSubmit()'));
+$add_button = $form->submit_html ("add-node","Add New Node");
 $details->tr($add_button,"right");
 
-$details->end();
 $form->end();
+$details->end();
+$toggle->end();
 
 // Print footer
 include 'plc_footer.php';