Statistiques
| Branche: | Révision :

root / src / add_box.php @ a9b72d88

Historique | Voir | Annoter | Télécharger (2,88 ko)

1
<?php
2
session_start();
3
require("headers.php");
4

    
5
$box_map = array(
6
  "A" => range(1,2),
7
  "B" => range(1,3),
8
  "C" => range(1,4),
9
  "D" => range(1,5),
10
  "E" => range(1,6),
11
  "F" => range(1,7),
12
  "G" => range(1,8),
13
  "H" => range(1,9),
14
  "I" => range(1,10),
15
  "J" => range(1,9),
16
  "K" => range(1,4),
17
);
18

    
19
if (isset($_REQUEST["action"])) {
20
  $container = $_REQUEST["container"];
21
  $rack = $_REQUEST["rack"];
22
  $box = $_REQUEST["box"];
23
  if ($_REQUEST["action"] == "add_box_to_db") {
24
    $where_clause = "container='$container' AND rack='$rack' AND box='$box'";
25
    if (FALSE) {
26
      $qry = "UPDATE cl_storage SET cl_passages=NULL WHERE $where_clause";
27
      $result = mysql_query($qry, $connexion);      
28
    } else {
29
      $error = FALSE;
30
      $qry = "SELECT COUNT(*) FROM cl_storage WHERE $where_clause";   
31
      $result = mysql_query($qry);
32
      $row = mysql_fetch_row($result);
33
      $count = $row[0];
34
      if ($count > 0) {
35
        $error = TRUE;
36
        echo "<H4 style='background-color: red;'><b>ERROR!</b> Container $container rack $rack box $box ever exists!</H4>";
37
      }
38
      if ($session->mode != "super") {
39
        echo "<H4 style='background-color: red;'><b>ERROR!</b> You must be in <b>superuser mode</b> to add a Liquid N2 box.</H4>";
40
      }
41
      if (!$error & $session->mode == "super") {
42
        $qry_part = array();
43
        foreach ($box_map as $field_y => $fields) {
44
          foreach($fields as $field_x) {
45
            array_push($qry_part, "(NULL,'$container','$rack','$box','$field_y','$field_x',NULL)");
46
          }
47
        }
48
        $box_values = implode(",", $qry_part); 
49
        $qry = "INSERT INTO `cl_storage` VALUES $box_values";
50
        $result = mysql_query($qry, $connexion);            
51
        if ($result) {
52
          echo "<H4 style='background-color: green;'><b>CONGRATULATION!</b> You succesfully add container $container rack $rack box $box.</H4>";
53
        }
54
      }      
55
    }
56
  }
57
}
58

    
59

    
60
  $output = "";
61
  $output .= "<p>You want to add a new Liquid N2 box in your database.</p>";
62
  $output .= "<form>";
63

    
64
  $output .= "What is the number on the container?<br>";
65
  $output .= "Container: <select name='container' >";
66
  for ($i = 1; $i <= 50; $i++){
67
    $output .= "<option value='$i'>$i</option>";
68
  }
69
  $output .= "</select><br>";
70

    
71
  $output .= "What is the number on the rack?<br>";
72
  $output .= "Rack: <select name='rack' >";
73
  for ($i = 1; $i <= 50; $i++){
74
    $output .= "<option value='$i'>$i</option>";
75
  }
76
  $output .= "</select><br>";
77
  
78
  $output .= "What is the number on the box?<br>";
79
  $output .= "Box: <select name='box' >";
80
  for ($i = 1; $i <= 100; $i++){
81
    $output .= "<option value='$i'>$i</option>";
82
  }
83
  $output .= "<input type='hidden' name='action' value='add_box_to_db'>\n";
84
  $output .= "<br><input type='submit' value='Add this new box.'>\n";
85
  $output .= "</select><br>";
86
  $output .= "</form>";
87

    
88
  echo $output;
89

    
90
  // session_start ();
91
  require("footers.php");
92

    
93
  
94
?>
95

    
96