www-thermferm/units.php

changeset 554
ab9f22ab57b5
parent 518
fd36bedab944
child 564
3fc61dd28656
--- a/www-thermferm/units.php	Wed Jul 25 20:08:13 2018 +0200
+++ b/www-thermferm/units.php	Tue Jul 31 16:42:11 2018 +0200
@@ -1,6 +1,6 @@
 <?php
 /*****************************************************************************
- * Copyright (C) 2014-2017
+ * Copyright (C) 2014-2018
  *   
  * Michiel Broek <mbroek at mbse dot eu>
  *
@@ -56,16 +56,16 @@
 /*
  * Unit add
  *
- * @param string $_POST['Name'] The rpofile name
+ * @param string $_POST['Name'] The product name
  */
 function unit_add() {
 
     if ($_POST['key'] == 'Add') {
-	send_cmd("UNIT ADD ".$_POST['Name']);
+	send_cmd("UNIT ADD ".$_POST['ProductName']);
     }
 
     unset($_POST['UUID']);
-    unset($_POST['Name']);
+    unset($_POST['roductName']);
     unset($_POST['key']);
     unset($_POST['command']);
     load('units.php');
@@ -77,7 +77,6 @@
  * Unit update
  *
  * @param string $_POST['UUID'] The unit UUID
- * @param string $_POST['Name'] The unit name
  * @param string $_POST['key'] The button pressed.
  */
 function unit_update() {
@@ -90,7 +89,8 @@
 
     if ($_POST['key'] == 'Save') {
 	$cmd = array("UNIT PUT ".$_POST['UUID']);
-	$cmd[] = "NAME,".$_POST['Name'];
+	$cmd[] = "PRODUCT_CODE,".$_POST['ProductCode'];
+	$cmd[] = "PRODUCT_NAME,".$_POST['ProductName'];
 	$cmd[] = "VOLUME,".$_POST['Volume'];
 	$cmd[] = "AIR_ADDRESS,".$_POST['AirAddress'];
 	$cmd[] = "AIR_IDX,".$_POST['AirIdx'];
@@ -131,7 +131,8 @@
     }
 
     unset($_POST['UUID']);
-    unset($_POST['Name']);
+    unset($_POST['ProductName']);
+    unset($_POST['ProductCode']);
     unset($_POST['Volume']);
     unset($_POST['key']);
     unset($_POST['command']);
@@ -175,17 +176,16 @@
 
 
 /*
- * Test input of a modified or new profile.
+ * Test input of a modified or new fermentation unit.
  *
  * @param string $_POST['UUID'] Unique record UUID
- * @param string $_POST['Name'] Profile name
  * @param string $_POST['key'] Key choice, Save or Cancel
  * @param string $_POST['command'] Command used, 'add' or 'update'
  *
  * Return: 0 = Ok
  *         1 = Missing data
- *         2 = Name field too short
- *         3 = Name already in use
+ *  //       2 = Name field too short
+ *  //       3 = Name already in use
  *         4 = TempSetMax <= TempSetMin
  *         5 = TempSetMax < 25 or > 35
  *         6 = TempSetMin < -5 or > 15
@@ -201,8 +201,10 @@
 
     global $arr;
 
-    if (isset($_POST['UUID']) && isset($_POST['Name']) && isset($_POST['Volume']) && isset($_POST['AirAddress']) && isset($_POST['ChillerAddress']) &&
-	isset($_POST['BeerAddress']) && isset($_POST['HeaterAddress']) && isset($_POST['CoolerAddress']) && isset($_POST['LightAddress']) &&
+    if (isset($_POST['UUID']) && isset($_POST['ProductCode']) && isset($_POST['ProductName']) && isset($_POST['Volume']) && 
+	isset($_POST['AirAddress']) && isset($_POST['ChillerAddress']) &&
+	isset($_POST['BeerAddress']) && isset($_POST['HeaterAddress']) && 
+	isset($_POST['CoolerAddress']) && isset($_POST['LightAddress']) &&
 	isset($_POST['HeaterDelay']) && isset($_POST['CoolerDelay']) && isset($_POST['LightDelay']) && isset($_POST['PSUAddress']) &&
 	isset($_POST['FanAddress']) && isset($_POST['DoorAddress']) && isset($_POST['TempSetMin']) && isset($_POST['TempSetMax']) &&
 	isset($_POST['PIDC_pGain']) && isset($_POST['PIDC_iGain']) && isset($_POST['PIDC_dGain']) && isset($_POST['PIDC_idleRange']) &&
@@ -215,10 +217,10 @@
 	if ($_POST['key'] == 'Cancel')
 	    return 99;
 
-    	if (strlen($_POST['Name']) < 2)
-	    return 2;
+//    	if (strlen($_POST['Name']) < 2)
+//	    return 2;
 
-    	if (startsWith($arr[0], "212")) {
+/*    	if (startsWith($arr[0], "212")) {
 	    $j = 1;
 	    while (1) {
 	    	if (strcmp($arr[$j], ".") == 0)
@@ -229,7 +231,7 @@
 	    	}
 	    	$j++;
 	    }
-	}
+	} */
 
 	if ($_POST['TempSetMax'] <= $_POST['TempSetMin'])
 	    return 4;
@@ -361,18 +363,27 @@
 		break;
 	    $f = explode(",", $reply[$i]);
 
-	    if ($f[0] == "NAME") {
-    		$outstr .= '       <tr class="editor">'.PHP_EOL;
-    		$outstr .= '        <td class="editname">Unit Name</td>'.PHP_EOL;
-    		$outstr .= '        <td colspan="3" class="editfield"><input type="text" name="Name" size="50" value="'.$f[1].'"></td>'.PHP_EOL;
+	    if ($f[0] == "PRODUCT_CODE") {
+	    	$outstr .= '       <tr class="editor">'.PHP_EOL;
+		$outstr .= '        <td class="editname">Product Code</td>'.PHP_EOL;
+		$outstr .= '        <td colspan="3" class="editfield"><input type="text" name="ProductCode" size="32" value="'.$f[1].'"></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
+	    if ($f[0] == "PRODUCT_NAME") {
+    		$outstr .= '       <tr class="editor">'.PHP_EOL;
+    		$outstr .= '        <td class="editname">Product Name</td>'.PHP_EOL;
+    		$outstr .= '        <td colspan="3" class="editfield"><input type="text" name="ProductName" size="50" value="'.$f[1].'"></td>'.PHP_EOL;
+		$outstr .= '       </tr>'.PHP_EOL;
+	    }
+
 	    if ($f[0] == "VOLUME") {
     		$outstr .= '       <tr class="editor">'.PHP_EOL;
     		$outstr .= '        <td class="editname">Unit Volume</td>'.PHP_EOL;
     		$outstr .= '        <td colspan="3" class="editfield"><input type="text" name="Volume" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "AIR_ADDRESS") {
     		$outstr .= '       <tr class="editor">'.PHP_EOL;
     		$outstr .= '        <td class="editname">Air Sensor Address</td>'.PHP_EOL;
@@ -392,14 +403,13 @@
 		    }
 		}
     		$outstr .= '        </select></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "AIR_IDX") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Air domoticz idx</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="AirIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "BEER_ADDRESS") {
                 $outstr .= '       <tr class="editor">'.PHP_EOL;
                 $outstr .= '        <td class="editname">Beer Sensor Address</td>'.PHP_EOL;
@@ -419,14 +429,13 @@
                     }
 		}
 		$outstr .= '        </select></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "BEER_IDX") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Beer domoticz idx</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="BeerIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "CHILLER_ADDRESS") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Chiller Sensor Address</td>'.PHP_EOL;
@@ -446,14 +455,13 @@
 		    }
 		}
 		$outstr .= '        </select></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "CHILLER_IDX") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Chiller domoticz idx</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="ChillerIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "HEATER_ADDRESS") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Heater Switch Address</td>'.PHP_EOL;
@@ -473,50 +481,46 @@
 		    }
 		}
 		$outstr .= '        </select></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "HEATER_DELAY") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Heater Switch Delay</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="HeaterDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "HEATER_IDX") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Heater domoticz idx</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="HeaterIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "PIDH_IMAX") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PID Heat Maximum</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDH_iMax" size="6" value="'.$f[1].'"> % (1..100)</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "PIDH_IDLERANGE") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Heater Idle Range</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDH_idleRange" size="6" value="'.$f[1].'"> &deg;C (Heater margin)</td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "PIDH_PGAIN") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PID Heat pGain</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDH_pGain" size="6" value="'.$f[1].'"> Proportional</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "PIDH_IGAIN") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PID Heat iGain</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDH_iGain" size="6" value="'.$f[1].'"> Intergral</td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "PIDH_DGAIN") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PID Heat dGain</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDH_dGain" size="6" value="'.$f[1].'"> Derivative</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "COOLER_ADDRESS") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Cooler Switch Address</td>'.PHP_EOL;
@@ -536,50 +540,46 @@
 		    }
 		}
 		$outstr .= '        </select></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "COOLER_DELAY") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Cooler Switch Delay</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="CoolerDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "COOLER_IDX") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Cooler domoticz idx</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="CoolerIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "PIDC_IMAX") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PID Cool Maximum</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDC_iMax" size="6" value="'.$f[1].'"> % (1..100)</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "PIDC_IDLERANGE") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Cooler Idle Range</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDC_idleRange" size="6" value="'.$f[1].'"> &deg;C (Cooler margin)</td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "PIDC_PGAIN") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PID Cool pGain</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDC_pGain" size="6" value="'.$f[1].'"> Proportional</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "PIDC_IGAIN") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PID Cool iGain</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDC_iGain" size="6" value="'.$f[1].'"> Intergral</td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "PIDC_DGAIN") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PID Cool dGain</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDC_dGain" size="6" value="'.$f[1].'"> Derivative</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "FAN_ADDRESS") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Fan Switch Address</td>'.PHP_EOL;
@@ -599,14 +599,13 @@
 		    }
 		}
 		$outstr .= '        </select></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "FAN_DELAY") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Fan Switch Delay</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="FanDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "FAN_IDX") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Fan domoticz idx</td>'.PHP_EOL;
@@ -632,20 +631,21 @@
 		    }
 		}
 		$outstr .= '        </select></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "LIGHT_DELAY") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Lights Delay</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="LightDelay" size="5" value="'.$f[1].'"> seconds (0..720)</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "LIGHT_IDX") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Light domoticz idx</td>'.PHP_EOL;
 		$outstr .= '        <td colspan="3" class="editfield"><input type="text" name="LightIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "DOOR_ADDRESS") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Door Sensor Address</td>'.PHP_EOL;
@@ -665,17 +665,16 @@
 		    }
 		}
 		$outstr .= '        </select></td>'.PHP_EOL;                        
-//		$outstr .= '       </tr>'.PHP_EOL;                                  
 	    }
 	    if ($f[0] == "DOOR_IDX") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Door domoticz idx</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="DoorIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "PSU_ADDRESS") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
-		$outstr .= '        <td class="editname">Power Supply Sensor Address</td>'.PHP_EOL;
+		$outstr .= '        <td class="editname">PSU Sensor Address</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><select name="PSUAddress">'.PHP_EOL;
 		$outstr .= '         <option value="">Not Assigned</option>'.PHP_EOL;
 		if (startsWith($devices[0], "212")) {
@@ -692,26 +691,24 @@
 		    }
 		}
 		$outstr .= '        </select></td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "PSU_IDX") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">PSU domoticz idx</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PSUIdx" size="5" value="'.$f[1].'"></td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    if ($f[0] == "TEMP_SET_MIN") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Min. temp setting</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="TempSetMin" size="5" value="'.$f[1].'"> &deg;C</td>'.PHP_EOL;
-//		$outstr .= '       </tr>'.PHP_EOL;
 	    }
 	    if ($f[0] == "TEMP_SET_MAX") {
-//		$outstr .= '       <tr class="editor">'.PHP_EOL;
 		$outstr .= '        <td class="editname">Max. temp setting</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="TempSetMax" size="5" value="'.$f[1].'"> &deg;C</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+
 	    $i++;
 	}
     }
@@ -769,7 +766,7 @@
     $outstr .= '     <table class="setup">'.PHP_EOL;
     $outstr .= '      <tr class="trhead">'.PHP_EOL;
     $outstr .= '       <td class="setup" style="width: 300px;">UUID</td>'.PHP_EOL;
-    $outstr .= '       <td class="setup" style="width: 300px;">Name</td>'.PHP_EOL;
+    $outstr .= '       <td class="setup" style="width: 300px;">Alias</td>'.PHP_EOL;
     $outstr .= '       <td class="setup" style="width: 60px;">Mode</td>'.PHP_EOL;
     $outstr .= '       <td class="setup" style="width: 40px;">Edit</td>'.PHP_EOL;
     $outstr .= '      </tr>'.PHP_EOL;
@@ -802,9 +799,10 @@
     $outstr .= '      <table class="editor">'.PHP_EOL;
     $outstr .= '      <tr class="trhead"><td colspan="3">Add new unit</td></tr>'.PHP_EOL;
     $outstr .= '       <tr class="editor">'.PHP_EOL;
-    $outstr .= '        <td class="editname">Unit Name</td>'.PHP_EOL;
-    $outstr .= '        <td class="editfield"><input type="text" name="Name" size="50" value=""></td>'.PHP_EOL;
+    $outstr .= '        <td class="editname">Product Name</td>'.PHP_EOL;
+    $outstr .= '        <td class="editfield"><input type="text" name="ProductName" size="50" value=""></td>'.PHP_EOL;
     $outstr .= '        <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL;
+    $outstr .= '<input type="hidden" value="FAKE000" name="ProductCode">';
     $outstr .= '<input type="hidden" value="0.0" name="Volume">';
     $outstr .= '<input type="hidden" value="" name="AirAddress">';
     $outstr .= '<input type="hidden" value="0" name="AirIdx">';

mercurial