jjkeegan86

index.php rpints

Feb 5th, 2016
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.61 KB | None | 0 0
  1. <?php
  2.     if (!file_exists(__DIR__.'/includes/config.php')) {
  3.         header('Location: install/index.php', true, 303);
  4.         die();
  5.     }
  6. ?>
  7. <?php
  8.     require_once __DIR__.'/includes/config_names.php';
  9.  
  10.     require_once __DIR__.'/includes/config.php';
  11.  
  12.     require_once __DIR__.'/admin/includes/managers/tap_manager.php';
  13.    
  14.     //This can be used to choose between CSV or MYSQL DB
  15.     $db = true;
  16.    
  17.     // Setup array for all the beers that will be contained in the list
  18.     $beers = array();
  19.    
  20.     if($db){
  21.         // Connect to the database
  22.         db();
  23.    
  24.         if(isset($_POST['amount']))
  25.          {
  26.            $amount=$_POST['amount'];
  27.            $tap=$_POST['tap'];
  28.            $tapNum = $_POST['tapNum'];
  29.            $sql = "insert into pours (tapId,pinId, amountPoured, pulses) values (".$tap.",".$tap.",".$amount."/128,1)";
  30.             mysql_query($sql);
  31.         }  
  32.    
  33.         $config = array();
  34.         $sql = "SELECT * FROM config";
  35.         $qry = mysql_query($sql);
  36.         while($c = mysql_fetch_array($qry)){
  37.             $config[$c['configName']] = $c['configValue'];
  38.         }
  39.        
  40.         $sql =  "SELECT * FROM vwGetActiveTaps";
  41.         $qry = mysql_query($sql);
  42.         while($b = mysql_fetch_array($qry))
  43.         {
  44.             $beeritem = array(
  45.                 "id" => $b['id'],
  46.                 "beername" => $b['name'],
  47.                 "style" => $b['style'],
  48.                 "notes" => $b['notes'],
  49.                 "og" => $b['ogAct'],
  50.                 "fg" => $b['fgAct'],
  51.                 "srm" => $b['srmAct'],
  52.                 "ibu" => $b['ibuAct'],
  53.                 "startAmount" => $b['startAmount'],
  54.                 "amountPoured" => $b['amountPoured'],
  55.                 "remainAmount" => $b['remainAmount'],
  56.                 "tapNumber" => $b['tapNumber'],
  57.                 "srmRgb" => $b['srmRgb']
  58.             );
  59.             $beers[$b['tapNumber']] = $beeritem;
  60.            
  61.         }
  62.        
  63.         $tapManager = new TapManager();
  64.         $numberOfTaps = $tapManager->GetTapNumber();
  65.     }
  66.  
  67.  
  68.  
  69. ?>
  70. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  71. "http://www.w3.org/TR/html4/strict.dtd">
  72.  
  73. <html>
  74.     <head>
  75.         <title>RaspberryPints</title>
  76.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  77.  
  78.         <!-- Set location of Cascading Style Sheet -->
  79.         <link rel="stylesheet" type="text/css" href="style.css">
  80.        
  81.         <?php if($config[ConfigNames::UseHighResolution]) { ?>
  82.             <link rel="stylesheet" type="text/css" href="high-res.css">
  83.         <?php } ?>
  84.        
  85.         <link rel="shortcut icon" href="img/pint.ico">
  86.     </head>
  87.  
  88.     <body>
  89.         <div class="bodywrapper">
  90.             <!-- Header with Brewery Logo and Project Name -->
  91.             <div class="header clearfix">
  92.                 <div class="HeaderLeft">
  93.                     <?php if($config[ConfigNames::UseHighResolution]) { ?>         
  94.                         <a href="admin/admin.php"><img src="<?php echo $config[ConfigNames::LogoUrl] . "?" . time(); ?>" height="225" alt=""></a>
  95.                     <?php } else { ?>
  96.                         <a href="admin/admin.php"><img src="<?php echo $config[ConfigNames::LogoUrl] . "?" . time(); ?>" height="180" alt=""></a>
  97.                     <?php } ?>
  98.                 </div>
  99.                 <div class="HeaderCenter">
  100.                     <h1 id="HeaderTitle">
  101.                         <?php
  102.                             if (mb_strlen($config[ConfigNames::HeaderText], 'UTF-8') > ($config[ConfigNames::HeaderTextTruncLen])) {
  103.                                 $headerTextTrunced = substr($config[ConfigNames::HeaderText],0,$config[ConfigNames::HeaderTextTruncLen]) . "...";
  104.                                 echo $headerTextTrunced ; }
  105.                             else
  106.                                 echo $config[ConfigNames::HeaderText];
  107.                         ?>
  108.                     </h1>
  109.                 </div>
  110.                 <div class="HeaderRight">
  111.                     <?php if($config[ConfigNames::UseHighResolution]) { ?>         
  112.                         <a href="http://www.student.nvcc.edu/home/jokeegan/project/"><img src="img/hop.gif" height="190" alt=""></a>
  113.                     <?php } else { ?>
  114.                         <a href="http://www.student.nvcc.edu/home/jokeegan/project/"><img src="img/hop.gif" height="180" alt=""></a>
  115.                     <?php } ?>
  116.                 </div>
  117.             </div>
  118.             <!-- End Header Bar -->
  119.            
  120.             <table>
  121.                 <thead>
  122.                     <tr>
  123.                         <?php if($config[ConfigNames::ShowTapNumCol]){ ?>
  124.                             <th class="tap-num">
  125.                                 TAP<br>#
  126.                             </th>
  127.                         <?php } ?>
  128.                        
  129.                         <?php if($config[ConfigNames::ShowSrmCol]){ ?>
  130.                             <th class="srm">
  131.                                 GRAVITY<hr>COLOR
  132.                             </th>
  133.                         <?php } ?>
  134.                        
  135.                         <?php if($config[ConfigNames::ShowIbuCol]){ ?>
  136.                             <th class="ibu">
  137.                                 BALANCE<hr>BITTERNESS
  138.                             </th>
  139.                         <?php } ?>
  140.                        
  141.                         <th class="name">
  142.                             BEER NAME &nbsp; & &nbsp; STYLE<hr>TASTING NOTES
  143.                         </th>
  144.                        
  145.                         <?php if($config[ConfigNames::ShowAbvCol]){ ?>
  146.                             <th class="abv">
  147.                                 ALCOHOL<hr>ABV
  148.                             </th>
  149.                         <?php } ?>
  150.                        
  151.                         <?php if($config[ConfigNames::ShowKegCol]){ ?>
  152.                             <th class="keg">
  153.                                 POURED<hr>REMAINING
  154.                             </th>
  155.                         <?php } ?>
  156.                     </tr>
  157.                 </thead>
  158.                 <tbody>
  159.                     <?php for($i = 1; $i <= $numberOfTaps; $i++) {
  160.                         if( isset($beers[$i]) ) {
  161.                             $beer = $beers[$i];
  162.                     ?>
  163.                             <tr class="<?php if($i%2 > 0){ echo 'altrow'; }?>" id="<?php echo $beer['id']; ?>">
  164.                                 <?php if($config[ConfigNames::ShowTapNumCol]){ ?>
  165.                                     <td class="tap-num">
  166.                                         <span class="tapcircle"><?php echo $i; ?></span>
  167.                                     </td>
  168.                                 <?php } ?>
  169.                            
  170.                                 <?php if($config[ConfigNames::ShowSrmCol]){ ?>
  171.                                     <td class="srm">
  172.                                         <h3><?php echo $beer['og']; ?> OG</h3>
  173.                                        
  174.                                         <div class="srm-container">
  175.                                             <div class="srm-indicator" style="background-color: rgb(<?php echo $beer['srmRgb'] != "" ? $beer['srmRgb'] : "0,0,0" ?>)"></div>
  176.                                             <div class="srm-stroke"></div>
  177.                                         </div>
  178.                                        
  179.                                         <h2><?php echo $beer['srm']; ?> SRM</h2>
  180.                                     </td>
  181.                                 <?php } ?>
  182.                            
  183.                                 <?php if($config[ConfigNames::ShowIbuCol]){ ?>
  184.                                     <td class="ibu">
  185.                                         <h3>
  186.                                             <?php
  187.                                                 if( $beer['og'] > 1 ){
  188.                                                     echo number_format((($beer['ibu'])/(($beer['og']-1)*1000)), 2, '.', '');
  189.                                                 }else{
  190.                                                     echo '0.00';
  191.                                                 }
  192.                                             ?>
  193.                                             BU:GU
  194.                                         </h3>
  195.                                        
  196.                                         <div class="ibu-container">
  197.                                             <div class="ibu-indicator"><div class="ibu-full" style="height:<?php echo $beer['ibu'] > 100 ? 100 : $beer['ibu']; ?>%"></div></div>
  198.                                                
  199.                                             <?php
  200.                                                 /*
  201.                                                 if( $remaining > 0 ){
  202.                                                     ?><img class="ibu-max" src="img/ibu/offthechart.png" /><?php
  203.                                                 }
  204.                                                 */
  205.                                             ?>
  206.                                         </div>
  207.                                         <h2><?php echo $beer['ibu']; ?> IBU</h2>
  208.                                     </td>
  209.                                 <?php } ?>
  210.                            
  211.                                 <td class="name">
  212.                                     <h1><?php echo $beer['beername']; ?></h1>
  213.                                     <h2 class="subhead"><?php echo str_replace("_","",$beer['style']); ?></h2>
  214.                                     <p><?php echo $beer['notes']; ?></p>
  215.                                 </td>
  216.                            
  217.                                 <?php if(($config[ConfigNames::ShowAbvCol]) && ($config[ConfigNames::ShowAbvImg])){ ?>
  218.                                     <td class="abv">
  219.                                         <h3><?php
  220.                                             $calfromalc = (1881.22 * ($beer['fg'] * ($beer['og'] - $beer['fg'])))/(1.775 - $beer['og']);
  221.                                             $calfromcarbs = 3550.0 * $beer['fg'] * ((0.1808 * $beer['og']) + (0.8192 * $beer['fg']) - 1.0004);
  222.                                             if ( ($beer['og'] == 1) && ($beer['fg'] == 1 ) ) {
  223.                                                 $calfromalc = 0;
  224.                                                 $calfromcarbs = 0;
  225.                                                 }
  226.                                             echo number_format($calfromalc + $calfromcarbs), " kCal";
  227.                                             ?>
  228.                                         </h3>
  229.                                         <div class="abv-container">
  230.                                             <?php
  231.                                                 $abv = ($beer['og'] - $beer['fg']) * 131;
  232.                                                 $numCups = 0;
  233.                                                 $remaining = $abv * 20;
  234.                                                 do{
  235.                                                         if( $remaining < 100 ){
  236.                                                                 $level = $remaining;
  237.                                                         }else{
  238.                                                                 $level = 100;
  239.                                                         }
  240.                                                         ?><div class="abv-indicator"><div class="abv-full" style="height:<?php echo $level; ?>%"></div></div><?php
  241.                                                        
  242.                                                         $remaining = $remaining - $level;
  243.                                                         $numCups++;
  244.                                                 }while($remaining > 0 && $numCups < 2);
  245.                                                
  246.                                                 if( $remaining > 0 ){
  247.                                                     ?><div class="abv-offthechart"></div><?php
  248.                                                 }
  249.                                             ?>
  250.                                         </div>
  251.                                         <h2><?php echo number_format($abv, 1, '.', ',')."%"; ?> ABV</h2>
  252.                                     </td>
  253.                                 <?php } ?>
  254.                                
  255.                                 <?php if(($config[ConfigNames::ShowAbvCol]) && ! ($config[ConfigNames::ShowAbvImg])){ ?>
  256.                                     <td class="abv">
  257.                                         <h3><?php
  258.                                             $calfromalc = (1881.22 * ($beer['fg'] * ($beer['og'] - $beer['fg'])))/(1.775 - $beer['og']);
  259.                                             $calfromcarbs = 3550.0 * $beer['fg'] * ((0.1808 * $beer['og']) + (0.8192 * $beer['fg']) - 1.0004);
  260.                                             if ( ($beer['og'] == 1) && ($beer['fg'] == 1 ) ) {
  261.                                                 $calfromalc = 0;
  262.                                                 $calfromcarbs = 0;
  263.                                                 }
  264.                                             //echo number_format($calfromalc + $calfromcarbs), " kCal";
  265.                                             ?>
  266.                                         </h3>
  267.                                         <div class="abv">
  268.                                             <?php
  269.                                                 $abv = ($beer['og'] - $beer['fg']) * 131;
  270.                                             ?>
  271.                                         </div>
  272.     <h2><?php echo number_format($abv, 1, '.', ',')."%"; ?> ABV</h2>
  273. <h2>       
  274.  
  275.  <form action="" method="post">
  276. <select class = "styled-select"  name = "amount">
  277.     <option value="11" <?php if(isset($_POST['amount']) && $tapNum == $i && $amount == "11"){echo "selected";} ?>>Goblet</option>
  278.     <option value="17" <?php if(isset($_POST['amount']) && $tapNum == $i && $amount == "17"){echo "selected";} ?>>Pint</option>                        
  279.     <option value="6"  <?php if(isset($_POST['amount']) && $tapNum== $i && $amount=="6"){echo "selected";} ?>>Taste</option>
  280.     <option value="40" <?php if(isset($_POST['amount']) && $tapNum == $i && $amount == "40"){echo "selected";} ?>>Growler</option>
  281.  
  282. </select>                                  
  283. <br/>
  284. <input class="pour" type="submit" value ="Pour"/>
  285. <input type="hidden" name="tap" value="<?php echo $beer['id'];?>">
  286. <input type="hidden" name="tapNum" value="<?php echo $i;?>">
  287.  
  288. <br/>
  289. </form>
  290.  
  291. </h2>
  292.        
  293. </td>
  294.                                 <?php } ?>
  295.                                
  296.                                 <?php if($config[ConfigNames::ShowKegCol]){ ?>
  297.                                     <td class="keg">
  298.                                        
  299.                                        
  300.                                         <h3><?php echo number_format((($beer['startAmount'] - $beer['remainAmount']) * 128)); ?> fl oz poured</h3>
  301.                                         <?php
  302.                                             // Code for new kegs that are not full
  303.                                                                                         $tid = $beer['id'];
  304.                                                                                         $sql = "Select kegId from taps where id=".$tid." limit 1";
  305.                                                                                         $kegID = mysql_query($sql);
  306.                                                                                         $kegID = mysql_fetch_array($kegID);
  307.                                                                                         //echo $kegID[0];
  308.                                                                                         $sql = "SELECT `kegTypes`.`maxAmount` as kVolume FROM  `kegs`,`kegTypes` where  kegs.kegTypeId = kegTypes.id and kegs.id =".$kegID[0]."";
  309.                                                                                         $kvol = mysql_query($sql);
  310.                                                                                         $kvol = mysql_fetch_array($kvol);
  311.                                                                                         $kvol = $kvol[0];
  312.                                                                                         $kegImgClass = "";
  313.                                                                                         if ($beer['startAmount']>=$kvol) {
  314.                                                                                         $percentRemaining = $beer['remainAmount'] / $beer['startAmount'] * 100;
  315.                                                                                         } else {
  316.                                                                                         $percentRemaining =  $beer['remainAmount'] / $kvol * 100;
  317.                                                                                         }
  318.                                             if( $beer['remainAmount'] <= 0 ) {
  319.                                                 $kegImgClass = "keg-empty";
  320.                                                 $percentRemaining = 100; }
  321.                                             else if( $percentRemaining < 15 )
  322.                                                 $kegImgClass = "keg-red";
  323.                                             else if( $percentRemaining < 25 )
  324.                                                 $kegImgClass = "keg-orange";
  325.                                             else if( $percentRemaining < 45 )
  326.                                                 $kegImgClass = "keg-yellow";
  327.                                             else if ( $percentRemaining < 100 )
  328.                                                 $kegImgClass = "keg-green";
  329.                                             else if( $percentRemaining >= 100 )
  330.                                                 $kegImgClass = "keg-full";
  331.                                         ?>
  332.                                         <div class="keg-container">
  333.                                             <div class="keg-indicator"><div class="keg-full <?php echo $kegImgClass ?>" style="height:<?php echo $percentRemaining; ?>%"></div></div>
  334.                                         </div>
  335.                                         <h2><?php echo number_format(($beer['remainAmount'] * 128)); ?> fl oz left</h2>
  336.                                     </td>
  337.                                 <?php } ?>
  338.                             </tr>
  339.                         <?php }else{ ?>
  340.                             <tr class="<?php if($i%2 > 0){ echo 'altrow'; }?>">
  341.                                 <?php if($config[ConfigNames::ShowTapNumCol]){ ?>
  342.                                     <td class="tap-num">
  343.                                         <span class="tapcircle"><?php echo $i; ?></span>
  344.                                     </td>
  345.                                 <?php } ?>
  346.                            
  347.                                 <?php if($config[ConfigNames::ShowSrmCol]){ ?>
  348.                                     <td class="srm">
  349.                                         <h3></h3>                                      
  350.                                         <div class="srm-container">
  351.                                             <div class="srm-indicator"></div>
  352.                                             <div class="srm-stroke"></div>
  353.                                         </div>
  354.                                        
  355.                                         <h2></h2>
  356.                                     </td>
  357.                                 <?php } ?>
  358.                            
  359.                                 <?php if($config[ConfigNames::ShowIbuCol]){ ?>
  360.                                     <td class="ibu">
  361.                                         <h3></h3>                                      
  362.                                         <div class="ibu-container">
  363.                                             <div class="ibu-indicator"><div class="ibu-full" style="height:0%"></div></div>
  364.                                         </div>                             
  365.                                         <h2></h2>
  366.                                     </td>
  367.                                 <?php } ?>
  368.                            
  369.                                 <td class="name">
  370.                                     <h1>Nothing on tap</h1>
  371.                                     <h2 class="subhead"></h2>
  372.                                     <p></p>
  373.                                 </td>
  374.                                
  375.                                 <?php if(($config[ConfigNames::ShowAbvCol]) && ($config[ConfigNames::ShowAbvImg])){ ?>
  376.                                     <td class="abv">
  377.                                         <h3></h3>
  378.                                         <div class="abv-container">
  379.                                             <div class="abv-indicator"><div class="abv-full" style="height:0%"></div></div>
  380.                                         </div>
  381.                                         <h2></h2>
  382.                                     </td>
  383.                                 <?php } ?>
  384.  
  385.                                 <?php if(($config[ConfigNames::ShowAbvCol]) && ! ($config[ConfigNames::ShowAbvImg])){ ?>
  386.                                     <td class="abv">
  387.                                         <h3></h3>
  388.  
  389.                                         <h2></h2>
  390.                                     </td>
  391.                                 <?php } ?>                             
  392.                                
  393.                                 <?php if($config[ConfigNames::ShowKegCol]){ ?>
  394.                                     <td class="keg">
  395.                                         <h3></h3>
  396.                                         <div class="keg-container">
  397.                                             <div class="keg-indicator"><div class="keg-full keg-empty" style="height:0%"></div></div>
  398.                                         </div>
  399.                                         <h2>0 fl oz left</h2>
  400.                                     </td>
  401.                                 <?php } ?>
  402.                             </tr>
  403.                         <?php } ?>
  404.                     <?php } ?>
  405.                 </tbody>
  406.             </table>
  407.         </div>
  408.     </body>
  409. </html>
Add Comment
Please, Sign In to add comment