Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $MySQLUsername = "root";
- $MySQLPassword = "Luc1nka";
- $MySQLHost = "localhost";
- $MySQLDB = "Automaty";
- $dbConnection = mysql_connect($MySQLHost, $MySQLUsername, $MySQLPassword);
- mysql_select_db($MySQLDB, $dbConnection);
- If (isset($_GET['action'])){
- $action = $_GET['action'];
- $pin = mysql_real_escape_string($_GET['pin']);
- if ($action == "turnOn"){
- $setting = "1";
- mysql_query("UPDATE i2cA SET Status='$setting' WHERE pinID='$pin';");
- mysql_close();
- header('Location: control.php');
- } else If ($action == "turnOff"){
- $setting = "0";
- mysql_query("UPDATE i2cA SET Status='$setting' WHERE pinID='$pin';");
- mysql_close();
- header('Location: control.php');
- }
- if ($action == "AturnOn"){
- $Asetting = "1";
- mysql_query("UPDATE i2cA SET Automat='$Asetting' WHERE pinID='$pin';");
- mysql_close();
- header('Location: control.php');
- } else If
- ($action == "AturnOff"){
- $Asetting = "0";
- mysql_query("UPDATE i2cA SET Automat='$Asetting' WHERE pinID='$pin';");
- mysql_close();
- header('Location: control.php');
- }
- else IF ($action =="automatStart"){
- $pin = mysql_real_escape_string($_GET['pin']);
- $zapnout = mysql_real_escape_string($_GET['automatZapnout']);
- mysql_query("UPDATE i2cA SET Zapnout='$zapnout' WHERE pinID='$pin';");
- header('Location: control.php');
- }
- else IF ($action =="edit"){
- $pin = mysql_real_escape_string($_GET['pin']);
- $query = mysql_query("SELECT Description FROM i2cA WHERE pinID='$pin';");
- $descRow = mysql_fetch_assoc($query);
- $description = $descRow['Description'];
- print '
- <html><head><title>Update Pin ' . $pin . '</title></head><body>
- <table border="0">
- <form name="edit" action="control.php" method="get">
- <input type="hidden" name="action" value="update">
- <input type="hidden" name="pin" value="' . $pin . '">
- <tr>
- <td><p>Description: </p></td><td><input type="text" name="description" value="' . $description . '"></td><td><input type="submit" value="Confirm"></td>
- </tr>
- </form>
- </table>
- </body></html>
- ';
- mysql_close();
- } else IF ($action =="update"){
- $pin = mysql_real_escape_string($_GET['pin']);
- $description = mysql_real_escape_string($_GET['description']);
- mysql_query("UPDATE i2cA SET Description='$description' WHERE pinID='$pin';");
- header('Location: control.php');
- } else {
- header('Location: control.php');
- }
- }
- else {
- print '
- <html>
- <head>
- <title>Test Page</title>
- </head>
- <font face="verdana">
- ';
- $query = mysql_query("SELECT pinID, Status ,Description ,Automat,Zapnout,Vypnout FROM i2cA;");
- //$query2 = mysql_query("SELECT pinNumber, pinDescription FROM pinDescription;");
- $totalGPIOCount = mysql_num_rows($query);
- $currentGPIOCount = 0;
- print '<table name="GPIO" border="1" cellpadding="5">';
- 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>';
- while ($currentGPIOCount < $totalGPIOCount){
- $pinRow = mysql_fetch_assoc($query);
- $pinNumber = $pinRow['pinID'];
- $pinStatus = $pinRow['Status'];
- $pinDescription = $pinRow['Description'];
- $pinAStatus = $pinRow['Automat'];
- $pinAstart = $pinRow['Zapnout'];
- $pinAstop = $pinRow['Vypnout'];
- If ($pinStatus == "0"){
- $buttonValue = "Zapni";
- $action = "turnOn";
- $image = "off.jpg";
- }
- else If ($pinStatus == "1"){
- $buttonValue = "Vypni";
- $action = "turnOff";
- $image = "on.jpg";
- }
- If ($pinAStatus == "0"){
- $AbuttonValue = "Automatika";
- $actionA = "AturnOn";
- $Aimage = "off.jpg";
- }
- else If ($pinAStatus == "1"){
- $AbuttonValue = "Manual";
- $actionA = "AturnOff";
- $Aimage = "on.jpg";
- }
- print '<tr>';
- print '<td align="center">' . $pinNumber . '</td>
- <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>
- <td align="center"><img src="' . $image . '" width="50"></td>
- <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>
- <td align="center"><img src="' . $Aimage . '" width="50"></td>
- <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>
- ';
- print '</tr>';
- $currentGPIOCount ++;
- }
- print '</table>';
- mysql_close();
- print '
- <br><br>
- </font>
- </html>
- ';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement