Advertisement
ebikjr

Untitled

Jun 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Smart home</title>
  5. <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
  6. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <div class="page-header">
  11. <h1> Sistem Kontrol Rumah </h1>
  12. </div>
  13. <p> Pilih Saklar </p>
  14. </div>
  15. <br>
  16. <div class="container">
  17. <div class="checkbox">
  18. <?php
  19. $data_condition = file_get_contents('data.json');
  20. $data_condition = json_decode($data_condition, true);
  21. for ($i=0; $i < count($data_condition); $i++)
  22. {
  23.  
  24. $ruang = $data_condition[$i]['ruang'];
  25. $status = (int)$data_condition[$i]['status'];
  26.  
  27. if ($status == 1) { $on = 'checked';} else {$on = '';
  28. }
  29. echo '<div class="checkbox"><label><input '.$on.' data-toggle="toggle" type="checkbox" id="'.$ruang.'">Saklar Lampu '.$ruang.'</label></div><br>';
  30. }
  31.  
  32. ?>
  33. </div>
  34. </div>
  35. </body>
  36. </html>
  37. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  38. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  39. <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
  40. <script>
  41.  
  42. <?php
  43. $data_condition = file_get_contents('data.json');
  44. $data_condition = json_decode($data_condition, true);
  45. for ($i=0; $i < count($data_condition); $i++)
  46. {
  47. $ruang = $data_condition[$i]['ruang'];
  48. ///$status = (int)$data_condition[$i]['status'];
  49. echo '$(function() {
  50. $("#'.$ruang.'").change(function() {
  51. d_post = $(this).prop("checked");
  52. if (d_post == true) { post = 1; } else{ post = 0; }
  53. saklar = "'.$ruang.'";
  54. $.ajax
  55. ({
  56. url:"home_sistem.php",
  57. method:"GET",
  58. data:{status:post,ruang:saklar},
  59. success:function(data)
  60. {
  61. alert(data);
  62. }
  63. })
  64. })
  65. })
  66. ';
  67. }
  68. ?>
  69. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement