changeset 50:2e4ed4d58660

If setShowOnly is not set, but material is set, use material type to set the class. Also validate the material name and class values (if set) better and earlier.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 02 Sep 2021 08:24:10 +0300
parents 527d37859f28
children 568f680e9d25
files info.php
diffstat 1 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/info.php	Mon Aug 23 18:19:40 2021 +0300
+++ b/info.php	Thu Sep 02 08:24:10 2021 +0300
@@ -136,13 +136,38 @@
 //
 // Actual main code begins
 //
-$setShowOnly = intval(stGetRequestItem("o", 0, TRUE));
+if (($tmp = stGetRequestItem("m", FALSE, TRUE)) !== FALSE)
+{
+  $tmp = preg_replace("/ +/", " ", preg_replace("/[^a-z ]/", " ", strtolower($tmp)));
+  if (isset($matDataTable[$tmp]))
+  {
+    // If material is valid, use it
+    $setShowMat = $tmp;
+    $setShowMatName = strtoupper(substr($tmp, 0, 1)).substr($tmp, 1);
+  }
+}
 
-if (isset($_GET["m"]))
+if (($tmp = stGetRequestItem("o", FALSE, TRUE)) !== FALSE)
 {
-  $setShowMat = trim(preg_replace("/[^a-z ]/", " ", strtolower($_GET["m"])));
-  $setShowMat = preg_replace("/ +/", " ", $setShowMat);
-  $setShowMatName = strtoupper(substr($setShowMat, 0, 1)).substr($setShowMat, 1);
+  // If the showOnly class is set and valid, use it
+  $tmp = intval($tmp);
+  if (isset($matTypeTable[$tmp]))
+    $setShowOnly = $tmp;
+}
+else
+if (isset($matDataTable[$setShowMat]))
+{
+  // Get showOnly type from material class
+  $mtype = $matDataTable[$setShowMat][14];
+
+  foreach ($matTypeTable as $index => $data)
+  {
+    if ($data[1] == $mtype || $data[2] == $mtype)
+    {
+      $setShowOnly = $index;
+      break;
+    }
+  }
 }
 
 $setSwapRows = (isset($_GET["swap"]) && is_array($_GET["swap"])) ? $_GET["swap"] : array();
@@ -228,6 +253,7 @@
   "</table>\n".
   "</form>\n";
 
+
 //
 // Now, act accordingly ..
 //