Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2.  
  3. <?php
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "root";
  7. $database = "lamp2proj1";
  8.  
  9. // Create connection
  10. $connection = new mysqli($servername, $username, $password, $database);
  11.  
  12. if ($connection->connect_error)
  13. {
  14. die("Connection failed: " . $connection->connect_error);
  15. }
  16.  
  17. $tasks = $connection->query('SELECT * FROM task');
  18. ?>
  19.  
  20. <html>
  21. <head>
  22. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  23. <title>Project 1</title>
  24. </head>
  25. <body>
  26. <h1>My task list</h1>
  27. <h2>Tasks to display</h2>
  28. <form>
  29. <input type="radio" name="tasksDisplay" value="incomplete" checked> Show incomplete only<br>
  30. <input type="radio" name="tasksDisplay" value="all"> Show all<br>
  31. </form>
  32. <h2>Sort Order</h2>
  33. <form>
  34. <input type="radio" name="sortOrder" value="dateCreated" checked> Sort by date created<br>
  35. <input type="radio" name="sortOrder" value="priority"> Sort by priority<br><br>
  36. </form>
  37. <!--<h3>Description</h3>
  38. <h3>Priority</h3>
  39. <h3>Date Created</h3>
  40. <h3>Date Completed</h3>
  41. <button type="buttonComplete">Complete selected</button>
  42. <button type="buttonDelete">Delete selected</button>-->
  43. <table style='border:1px solid black;' border='1'>
  44. <tr>
  45. <th></th>
  46. <th>Description</th>
  47. <th>Priority</th>
  48. <th>Date Created</th>
  49. <th>Date Completed</th>
  50. </tr>
  51. <?php if($tasks)
  52. {
  53. while ($row = $tasks->fetch_array())
  54. {
  55. echo
  56. "<tr>
  57. <td><input class='taskrow' type='checkbox'/ value=".$row['id']."></td>
  58. <td>".$row['description']."</td>
  59. <td>".$row['priority']."</td>
  60. <td>".$row['dateCreated']."</td>
  61. <td>".$row['dateCompleted']."</td>
  62. <td>
  63. <a data-id=".$row['id']." href=\"#\">Delete</a>
  64. </td>
  65. </tr>";
  66. }
  67. }
  68. ?>
  69. </table><br>
  70. <button id="deleteRows">Delete Selected</button>
  71. <form id="newPost" method="POST" action="Proj1Structure.php">
  72. <h2>Add a new task:</h2>
  73. Task: <input type="text" name="description"><br>
  74. Priority:
  75. <select name="priority">
  76. <option value="1">Very low</option>
  77. <option value="2">Low</option>
  78. <option value="3">Meh</option>
  79. <option value="4">Important</option>
  80. <option value="5">Very Important</option>
  81. </select>
  82. <br>
  83. <input type="submit" value="Submit">
  84. </form>
  85. <script type="text/javascript" src="jquery.min.js"></script>
  86. <script>
  87. $('[data-id]').each(function()
  88. {
  89. $(this).on('click', function(event) {
  90. event.preventDefault();
  91. deleteRow([$(this).data('id')]);
  92. });
  93. });
  94.  
  95. $('#deleteRows').on('click', function(event) {
  96. var obj = [];
  97. $('.taskrow:checked').each(function() {
  98. obj.push(parseInt($(this).val(), 10));
  99. });
  100. deleteRow(obj);
  101. });
  102.  
  103. // New task submission
  104. $('#newPost').on('submit', function(event) {
  105. event.preventDefault();
  106.  
  107. // If description is empty return
  108. var $description = $(this).find('input[name="description"]');
  109. if($description.val().trim() === '') {
  110. $description.val('');
  111. return;
  112. }
  113.  
  114. // Send data through POST
  115. $.ajax({ url: 'Proj1Structure.php',
  116. data: {
  117. action: 'newItem',
  118. data: JSON.stringify($(this).serialize())
  119. },
  120. type: 'post',
  121. success: function(output) {
  122. console.log(output);
  123. location.reload();
  124. }
  125. });
  126.  
  127. });
  128.  
  129. function newItem(data) {
  130.  
  131. }
  132.  
  133. function deleteRow(ids) {
  134. $.ajax({ url: 'Proj1Structure.php',
  135. data: {
  136. action: 'delete',
  137. data: JSON.stringify(ids)
  138. },
  139. type: 'post',
  140. success: function(output) {
  141. console.log(output);
  142. location.reload();
  143. }
  144. });
  145. }
  146. </script>
  147. </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement