www/includes/global.inc.php

Thu, 12 Oct 2023 14:19:46 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 12 Oct 2023 14:19:46 +0200
changeset 849
16079aef4c4c
parent 839
1590da0dd513
permissions
-rw-r--r--

Version 0.3.44. Moved iSpindel Plato calculation from the php script to bmsd. This uses calibration data in the mon_ispindels table. Setup of this data will be done by the bmsapp applications. Default settings are stored in MySQL. From now on you don't need to store calibration data in the iSpindel.

<?php
/*****************************************************************************
 * Copyright (C) 2014-2022
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of Brewery Management System
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * BrewCloud is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/

/*
 * Look for the style names in the jqwidgets/styles directory.
 */
//$my_style = 'ui-darkness';
$my_style = 'ui-mbse';

require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/version.php');

if (isset($_GET['record']))
	$my_record = $_GET['record'];
else
	$my_record = -1;
if (isset($_GET['uuid']))
	$my_uuid = $_GET['uuid'];
else
	$my_uuid = '';
if (isset($_GET['return']))
	$my_return = $_GET['return'];
else
	$my_return = '';
if (isset($_GET['code']))
	$my_code = $_GET['code'];
else
	$my_code = '';
if (isset($_GET['name']))
	$my_name = $_GET['name'];
else
	$my_name = '';
if (isset($_GET['select']))
	$my_select = $_GET['select'];
else
	$my_select = '';
if (isset($_GET['split']))
        $my_split = $_GET['split'];
else
        $my_split = 0;
if (isset($_GET['stage']))
        $my_stage = $_GET['stage'];
else
        $my_stage = 0;

$escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
$replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");

/* Load setup record */
#Connect to the database
$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
if (! $connect) {
        die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
mysqli_set_charset($connect, "utf8" );
$my_default_water = $my_brewery_name = $my_ibu_method = $my_color_method = '';
$my_factor_mashhop = $my_factor_fwh = $my_factor_pellet = $my_factor_plug = $my_factor_wethop = $my_factor_cryohop = 0;
$my_brix_correction = $my_grain_absorbtion = 1.0;

$result = mysqli_query($connect, "SELECT * FROM profile_setup WHERE record='1'") or die("SQL Error 1: " . mysqli_error($connect));
if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
	/* search water name */
	$wresult = mysqli_query($connect, "SELECT name FROM inventory_waters WHERE record='".$row['default_water']."';");
	if ($wrow = mysqli_fetch_array($wresult, MYSQLI_ASSOC))
		$my_default_water = str_replace($escapers, $replacements, $wrow['name']);
	$my_brewery_name = str_replace($escapers, $replacements, $row['brewery_name']);
	$my_factor_mashhop = floatval($row['factor_mashhop']);
	$my_factor_fwh= floatval($row['factor_fwh']);
	$my_factor_pellet= floatval($row['factor_pellet']);
	$my_factor_plug= floatval($row['factor_plug']);
	$my_factor_wethop = floatval($row['factor_wethop']);
	$my_factor_cryohop = floatval($row['factor_cryohop']);
	$my_ibu_method = $row['ibu_method'];
	$my_color_method = $row['color_method'];
	$my_brix_correction = floatval($row['brix_correction']);
	$my_grain_absorbtion = floatval($row['grain_absorption']);
}



function page_header($title, $loadjs) {
	global $my_style;
	global $my_version;
	global $my_record;
	global $my_uuid;
	global $my_return;
	global $my_name;
	global $my_code;
	global $my_select;
	global $my_stage;
	global $my_split;
	global $my_brewery_name;
	global $my_factor_mashhop;
	global $my_factor_fwh;
	global $my_factor_pellet;
	global $my_factor_plug;
	global $my_factor_wethop;
	global $my_factor_cryohop;
	global $my_ibu_method;
	global $my_color_method;
	global $my_brix_correction;
	global $my_grain_absorbtion;
	global $my_default_water;
?>
<!DOCTYPE html>
<html lang=nl-NL>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>BMS v<?php echo $my_version;?> - <?php echo $title;?></title>
  <link type="text/css" href="css/style.css" rel="stylesheet" media="all" />
  <link type="text/css" href="jqwidgets/styles/jqx.base.css" rel="stylesheet" />
  <link type="text/css" href="jqwidgets/styles/jqx.<?php echo $my_style; ?>.css" rel="stylesheet" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <script>
    var theme = "<?php echo $my_style; ?>", my_record = "<?php echo $my_record; ?>",
	my_return = "<?php echo $my_return; ?>", my_name = "<?php echo $my_name; ?>", my_stage = "<?php echo $my_stage; ?>",
	my_code = "<?php echo $my_code; ?>", my_uuid = "<?php echo $my_uuid; ?>", my_split = "<?php echo $my_split; ?>",
	my_select = "<?php echo $my_select; ?>", my_brewery_name = "<?php echo $my_brewery_name; ?>", my_factor_mashhop = "<?php echo $my_factor_mashhop; ?>",
	my_factor_fwh = "<?php echo $my_factor_fwh; ?>", my_factor_pellet = "<?php echo $my_factor_pellet; ?>",
	my_factor_plug = "<?php echo $my_factor_plug; ?>", my_factor_wethop = "<?php echo $my_factor_wethop; ?>",
	my_factor_cryohop = "<?php echo $my_factor_cryohop; ?>", my_ibu_method = "<?php echo $my_ibu_method; ?>",
	my_color_method = "<?php echo $my_color_method; ?>", my_brix_correction = "<?php echo $my_brix_correction; ?>",
	my_grain_absorbtion = "<?php echo $my_grain_absorbtion; ?>", my_default_water = "<?php echo $my_default_water; ?>";
  </script>
  <script src="js/jquery-1.11.1.js"></script>
  <script src="js/reconnecting-websocket.min.js"></script>
  <script src="jqwidgets/jqxcore.js"></script>
  <script src="jqwidgets/jqxwindow.js"></script>
  <script src="jqwidgets/jqxmenu.js"></script>
  <script src="jqwidgets/jqxtabs.js"></script>
  <script src="jqwidgets/jqxdata.js"></script>
  <script src="jqwidgets/jqxdata.export.js"></script>
  <script src="jqwidgets/jqxloader.js"></script>
  <script src="jqwidgets/jqxbuttons.js"></script>
  <script src="jqwidgets/jqxscrollbar.js"></script>
  <script src="jqwidgets/jqxgrid.js"></script>
  <script src="jqwidgets/jqxgrid.grouping.js"></script>
  <script src="jqwidgets/jqxgrid.edit.js"></script>
  <script src="jqwidgets/jqxgrid.sort.js"></script>
  <script src="jqwidgets/jqxgrid.pager.js"></script>
  <script src="jqwidgets/jqxgrid.filter.js"></script>
  <script src="jqwidgets/jqxgrid.selection.js"></script>
  <script src="jqwidgets/jqxnumberinput.js"></script>
  <script src="jqwidgets/jqxlistbox.js"></script>
  <script src="jqwidgets/jqxdropdownlist.js"></script>
  <script src="jqwidgets/jqxdropdownbutton.js"></script>
  <script src="jqwidgets/jqxinput.js"></script>
  <script src="jqwidgets/jqxeditor.js"></script>
  <script src="jqwidgets/jqxtooltip.js"></script>
  <script src="jqwidgets/jqxswitchbutton.js"></script>
  <script src="jqwidgets/jqxradiobutton.js"></script>
  <script src="jqwidgets/jqxcheckbox.js"></script>
  <script src="jqwidgets/jqxdatetimeinput.js"></script>
  <script src="jqwidgets/jqxcalendar.js"></script>
  <script src="jqwidgets/jqxgauge.js"></script>
  <script src="jqwidgets/jqxchart.core.js"></script>
  <script src="jqwidgets/jqxchart.rangeselector.js"></script>
  <script src="jqwidgets/jqxdraw.js"></script>
  <script src="jqwidgets/jqxprogressbar.js"></script>
  <script src="jqwidgets/jqxfileupload.js"></script>
  <script src="jqwidgets/jqxpanel.js"></script>
  <script src="jqwidgets/globalization/globalize.js"></script>
  <script src="js/global.js"></script>
<?php
if (strlen($loadjs))
    echo  '  <script src="js/'.$loadjs.'.js"></script>'.PHP_EOL;
?>
 </head>

 <body class="default">
  <div id="jqxWidget">
   <div id="jqxLoader">
   </div>

   <!-- Menu -->
   <div id="jqxMenu" style='float: left;'>
    <ul>
     <li style='width: 80px;'>
      <a href="index.php">Home</a>
     </li>
     <li style='width: 80px;'>Monitoren
      <ul style='width: 200px;'>
       <li><img style='float: left; margin-right: 5px;' src='images/computer.png' />Systemen
        <ul style='width: 200px;'>
         <div id="m_nodes"></div>
        </ul>
       </li>
       <li><img style='float: left; margin-right: 5px;' src='images/fridge.png' />Klimaatkasten
        <ul style='width: 200px;'>
         <div id="m_fermenters"></div>
        </ul>
       </li>
       <li><img style='float: left; margin-right: 5px;' src='images/beerbottle.png' />CO2 meters
        <ul style='width: 250px;'>
         <div id="m_co2meters"></div>
        </ul>
       </li>
       <li><img style='float: left; margin-right: 5px;' src='images/fermenter.png' />iSpindels
        <ul style='width: 250px;'>
         <div id="m_ispindels"></div>
        </ul>
       </li>
      </ul>
     </li>
     <li style='width: 80px;'>Productie
      <ul style='width: 200px;'>
       <li><img style='float: left; margin-right: 5px;' src='images/beerstyles.png' /><a href="prod_inprod.php">In productie</a></li>
       <li><img style='float: left; margin-right: 5px;' src='images/database.png' /><a href="prod_archive_code.php">Archief op code</a></li>
       <li><img style='float: left; margin-right: 5px;' src='images/database.png' /><a href="prod_archive_date.php">Archief op datum</a></li>
       <li><img style='float: left; margin-right: 5px;' src='images/database.png' /><a href="prod_archive_name.php">Archief op naam</a></li>
      </ul>
     </li>
     <li style='width: 80px;'><a href="rec_main.php">Recepten</a></li>
     <li style='width: 80px;'><a href="gen_about.php">Over</a></li>
    </ul>
   </div> <!-- End menu -->

<?php
 $connect = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
 $result = mysqli_query($connect, "SELECT uuid,node,online FROM mon_nodes ORDER BY node");
 $menu_nodes = '';
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    if ($row['online'] == 1)
        $img = "network-idle.png";
    else
        $img = "network-error.png";
    $menu_nodes .= '<li><img style="float: left; margin-right: 5px;" src="images/'.$img.'" /><a href="mon_node.php?uuid='.$row['uuid'].'">'.$row['node'].'</a></li>';
 }
 mysqli_free_result($result);
 $menu_fermenters = '';
 $result = mysqli_query($connect, "SELECT uuid,node,alias,online FROM mon_fermenters ORDER BY node,alias");
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    if ($row['online'] == 1)
        $img = "network-idle.png";
    else
        $img = "network-error.png";
    $menu_fermenters .= '<li><img style="float: left; margin-right: 5px;" src="images/'.$img.'" /><a href="mon_fermenter.php?uuid='.$row['uuid'].'">'.$row['node'].'/'.$row['alias'].'</a></li>';
 }
 mysqli_free_result($result);
 $menu_co2meters = '';
 $result = mysqli_query($connect, "SELECT uuid,node,alias,online FROM mon_co2meters ORDER BY node,alias");
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    if ($row['online'] == 1)
        $img = "network-idle.png";
    else
        $img = "network-error.png";
    $menu_co2meters .= '<li><img style="float: left; margin-right: 5px;" src="images/'.$img.'" /><a href="mon_co2meter.php?uuid='.$row['uuid'].'">'.$row['node'].'/'.$row['alias'].'</a></li>';
 }
 mysqli_free_result($result);
 $menu_ispindels = '';
 $result = mysqli_query($connect, "SELECT uuid,node,alias,online FROM mon_ispindels ORDER BY node,alias");
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    if ($row['online'] == 1)
        $img = "network-idle.png";
    else
        $img = "network-error.png";
    $menu_ispindels .= '<li><img style="float: left; margin-right: 5px;" src="images/'.$img.'" /><a href="mon_ispindel.php?uuid='.$row['uuid'].'">'.$row['alias'].'</a></li>';
 }
 mysqli_free_result($result);
?>
 <script>
  $('#m_nodes').html('<?php echo $menu_nodes; ?>');
  $('#m_fermenters').html('<?php echo $menu_fermenters; ?>');
  $('#m_co2meters').html('<?php echo $menu_co2meters; ?>');
  $('#m_ispindels').html('<?php echo $menu_ispindels; ?>');
 </script>
<?php
}


function confirm_delete() {
?>
   <div id="eventWindow">
    <div>
     Bevestig verwijderen
    </div>
    <div>
     <div>
      Klik "OK" om dit record definitief te verwijderen.<br>
      Druk "Cancel" om te sluiten zonder dit record te verwijderen.
     </div>
     <div>
      <div style="float: right; margin-top: 15px; margin-bottom: 10px;">
       <input type="button" id="delOk" value="OK" style="margin-right: 15px" />
       <input type="button" id="delCancel" value="Cancel" style="margin-right: 65px" />
      </div>
     </div>
    </div>
   </div>

<?php
}


function page_footer() {
?>
  </div> <!-- jqxWidget -->
 </body>
</html>
<?php
}
?>

mercurial