Advertisement
Stybyk

ZalohaBezCasu

May 27th, 2015
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.51 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $MySQLUsername = "root";
  5. $MySQLPassword = "Luc1nka";
  6. $MySQLHost = "localhost";
  7. $MySQLDB = "Automaty";              
  8. $dbConnection = mysql_connect($MySQLHost, $MySQLUsername, $MySQLPassword);
  9. mysql_select_db($MySQLDB, $dbConnection);
  10.  
  11.  
  12. If (isset($_GET['action'])){
  13.        
  14.         $action = $_GET['action'];
  15.         $pin = mysql_real_escape_string($_GET['pin']);
  16.         if ($action == "turnOn"){
  17.             $setting = "1";
  18.             mysql_query("UPDATE i2cA SET Status='$setting' WHERE pinID='$pin';");
  19.             mysql_close();
  20.             header('Location: control.php');
  21.         } else If ($action == "turnOff"){
  22.             $setting = "0";
  23.             mysql_query("UPDATE i2cA SET Status='$setting' WHERE pinID='$pin';");
  24.             mysql_close();
  25.             header('Location: control.php');          
  26.         }
  27.    
  28.      if ($action == "AturnOn"){
  29.             $Asetting = "1";
  30.             mysql_query("UPDATE i2cA SET Automat='$Asetting' WHERE pinID='$pin';");
  31.             mysql_close();
  32.             header('Location: control.php');
  33.         } else If
  34.     ($action == "AturnOff"){
  35.             $Asetting = "0";
  36.             mysql_query("UPDATE i2cA SET Automat='$Asetting' WHERE pinID='$pin';");
  37.             mysql_close();
  38.             header('Location: control.php');
  39.         }
  40.    
  41.     else IF ($action =="automatStart"){
  42.             $pin = mysql_real_escape_string($_GET['pin']);
  43.             $zapnout = mysql_real_escape_string($_GET['automatZapnout']);
  44.             mysql_query("UPDATE i2cA SET Zapnout='$zapnout' WHERE pinID='$pin';");
  45.             header('Location: control.php');
  46.     }
  47.    
  48.     else IF ($action =="edit"){
  49.             $pin = mysql_real_escape_string($_GET['pin']);
  50.             $query = mysql_query("SELECT Description FROM i2cA WHERE pinID='$pin';");
  51.             $descRow = mysql_fetch_assoc($query);
  52.             $description = $descRow['Description'];
  53.             print '
  54.             <html><head><title>Update Pin ' . $pin . '</title></head><body>
  55.             <table border="0">
  56.             <form name="edit" action="control.php" method="get">
  57.             <input type="hidden" name="action" value="update">
  58.             <input type="hidden" name="pin" value="' . $pin . '">
  59.             <tr>
  60.             <td><p>Description: </p></td><td><input type="text" name="description" value="' . $description . '"></td><td><input type="submit" value="Confirm"></td>
  61.             </tr>
  62.             </form>
  63.             </table>
  64.    
  65.             </body></html>
  66.             ';
  67.             mysql_close();
  68.         } else IF ($action =="update"){
  69.             $pin = mysql_real_escape_string($_GET['pin']);
  70.             $description = mysql_real_escape_string($_GET['description']);
  71.             mysql_query("UPDATE i2cA SET Description='$description' WHERE pinID='$pin';");
  72.             header('Location: control.php');
  73.         } else {
  74.             header('Location: control.php');
  75.         }
  76.     }
  77.  else {
  78.     print '
  79.         <html>
  80.         <head>
  81.         <title>Test Page</title>
  82.         </head>
  83.         <font face="verdana">
  84.    
  85.         ';
  86.         $query = mysql_query("SELECT pinID, Status ,Description ,Automat,Zapnout,Vypnout FROM i2cA;");
  87.         //$query2 = mysql_query("SELECT pinNumber, pinDescription FROM pinDescription;");
  88.         $totalGPIOCount = mysql_num_rows($query);
  89.         $currentGPIOCount = 0;
  90.         print '<table name="GPIO" border="1" cellpadding="5">';
  91.         print '<tr><th>GPIO #</th><th>Funkce</th><th>Status</th><th>Zapni/Vypni</th><th>Automatika</th><th>Auto/Manual</th><th>Zapnout</th><th>Vypnout</th></tr>';
  92.         while ($currentGPIOCount < $totalGPIOCount){
  93.             $pinRow = mysql_fetch_assoc($query);
  94.        
  95.             $pinNumber = $pinRow['pinID'];
  96.             $pinStatus = $pinRow['Status'];
  97.             $pinDescription = $pinRow['Description'];
  98.       $pinAStatus = $pinRow['Automat'];        
  99.       $pinAstart = $pinRow['Zapnout'];
  100.       $pinAstop = $pinRow['Vypnout'];
  101.            
  102.      
  103.       If ($pinStatus == "0"){
  104.                 $buttonValue = "Zapni";
  105.                 $action = "turnOn";
  106.                 $image = "off.jpg";
  107.          }
  108.            
  109.        else     If ($pinStatus == "1"){
  110.                 $buttonValue = "Vypni";
  111.                 $action = "turnOff";
  112.                 $image = "on.jpg";
  113.             }
  114.      
  115.       If ($pinAStatus == "0"){
  116.                                 $AbuttonValue = "Automatika";
  117.                                 $actionA = "AturnOn";
  118.                                 $Aimage = "off.jpg";
  119.          }
  120.                        
  121.        else     If ($pinAStatus == "1"){
  122.                                 $AbuttonValue = "Manual";
  123.                                 $actionA = "AturnOff";
  124.                                 $Aimage = "on.jpg";
  125.                         }
  126.      
  127.      
  128.      
  129.       print '<tr>';
  130.                         print '<td align="center">' . $pinNumber . '</td>
  131.           <td align="center">' . $pinDescription . '<form name="pin' . $pinNumber . '" action="control.php" method="get"><input type="hidden" name="action" value="edit"><input type="hidden" name="pin" value="' . $pinNumber . '"><input type="submit" value="Edit"></form></td>
  132.           <td align="center"><img src="' . $image . '" width="50"></td>
  133.           <td align="center" valign="middle"><form name="pin' . $pinNumber . 'edit" action="control.php" method="get"><input type="hidden" name="action" value="' . $action . '"><input type="hidden" name="pin" value="' . $pinNumber . '"><input type="submit" value="' . $buttonValue . '"></form></td>            
  134.          <td align="center"><img src="' . $Aimage . '" width="50"></td>
  135.          <td align="center" valign="middle"><form name="pin' . $pinNumber . 'Aedit" action="control.php" method="get"><input type="hidden" name="action" value="' . $actionA . '"><input type="hidden" name="pin" value="' . $pinNumber . '"><input type="submit" value="' . $AbuttonValue . '"></form></td>
  136.          
  137.            ';  
  138.              
  139.              
  140.              
  141.              
  142.              
  143.             print '</tr>';
  144.             $currentGPIOCount ++;
  145.         }
  146.         print '</table>';
  147.         mysql_close();
  148.     print '
  149.     <br><br>
  150.    
  151.     </font>
  152.  
  153.     </html>
  154.     ';
  155. }
  156. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement