Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. <?php
  2.  
  3. $hostname = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "laboratory";
  7.  
  8. $db = new mysqli($hostname, $username, $password, $dbname) or die ("Could Not Connect To MySql");
  9.  
  10. function increaseSalaries($date, $percentage){
  11. $updateBonus = "UPDATE technician SET tbonus = tsalary * " . $percentage . "/100 WHERE thiredate <'".$date . "'; UPDATE technician SET tsalary = (" . $percentage . "/100 * tsalary+tsalary) WHERE thiredate <'". $date. "'";
  12. return $updateBonus;
  13. }
  14.  
  15. ?>
  16. <!DOCTYPE HTML>
  17. <html>
  18. <head>
  19.  
  20. <link href='https://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'>
  21. <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
  22. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css">
  23. <meta charset='utf-8'>
  24. <title>University-jxc02</title>
  25. <link rel='stylesheet' href='public/css/screen.css' />
  26. </head>
  27. <body>
  28.  
  29. <div class= "header">
  30. <div class='header-content'>
  31. <p>Jaad Chacra - University Database</p>
  32. </div>
  33. </div>
  34. <div class="name-form">
  35. <h5>Submit the name of the Lab to retrieve information about the technicians that belong to this department </h5>
  36. <div class="row">
  37. <form class="col s12" method = "post">
  38. <div class="row">
  39. <div class="input-field col s12">
  40. <input placeholder="" id="lab_name" name="lab_name"type="text" class="validate">
  41. <label class="active"disabled="true"for="lab_name">Lab Name</label>
  42. </div>
  43. </div>
  44. <div class="buttons-wrapper">
  45. <input type ="submit" class ="btn waves-effect waves-light buttons" value = "Submit"/>
  46. </div>
  47. </form>
  48. </div>
  49. </div>
  50. <?php if(isset($_POST['lab_name'])){ ?>
  51. <div class="result-description">
  52. <h6>Technicians belonging to the lab <strong><?php echo $_POST['lab_name']?></strong></h6>
  53. </div>
  54. <div class= "table-wrapper">
  55. <table class="highlight">
  56. <thead>
  57. <tr>
  58. <th>Number</th>
  59. <th>Name</th>
  60. <th>Job</th>
  61. <th>Managers Name</th>
  62. <th>Hire Date</th>
  63. <th>Salary</th>
  64. <th>Bonus</th>
  65. </tr>
  66. </thead>
  67. <tbody>
  68. <?php
  69. $techniciansReturned = "SELECT t.tno, t.tname AS tname, t.tjob, m.tname AS mname, t.thiredate, t.tsalary, t.tbonus FROM TECHNICIAN t, TECHNICIAN m, LAB l WHERE t.tlno = l.lno AND l.lname = '" . $_POST['lab_name']. "' AND t.tmgr = m.tno" ;
  70. foreach ($db->query($techniciansReturned) as $row) {?>
  71. <tr>
  72. <td><?php echo $row['tno'];?></td>
  73. <td><?php echo $row['tname']; ?></td>
  74. <td><?php echo $row['tjob']; ?></td>
  75. <td><?php echo $row['mname'];?></td>
  76. <td><?php echo $row['thiredate']; ?></td>
  77. <td><?php echo $row['tsalary']; ?></td>
  78. <td><?php echo $row['tbonus']; ?></td>
  79. </tr>
  80. <?php }?>
  81. </tbody>
  82. </table>
  83.  
  84. </div>
  85. <?php }?>
  86. <div class="update-salaries-form">
  87. <h5>Submit the date and a percentage of raise to update the salaries of technicians concerned</h5>
  88. <div class="row">
  89. <form class="col s12" method="post">
  90. <div class= "input-field col s6">
  91. <input type="date" class="datepicker" id="date_picked" name="date_picked">
  92. </div>
  93. <div class ="input-field col s6">
  94. <input placeholder="" id="percentage_raise" type="text" name="percentage_raise"class="validate">
  95. <label class="active"for="percentage_raise">Percentage</label>
  96. </div>
  97. <div class="buttons-wrapper">
  98. <input name = "submit_second_form"type ="submit" class ="btn waves-effect waves-light buttons" value = "Submit"/>
  99. </div>
  100. </form>
  101. </div>
  102. </div>
  103. <?php if($_POST['submit_second_form'] =="Submit" &&isset($_POST['date_picked']) && isset($_POST['percentage_raise'])) {
  104. $db->exec(increaseSalaries($_POST['date_picked'], $_POST['percentage_raise']));
  105. $techniciansAffected = "SELECT tno, tname, tjob, tmgr, thiredate, tsalary, tbonus FROM TECHNICIAN t WHERE thiredate <'" . $_POST['date_picked']. "'" ;
  106. ?>
  107. <div class="result-description">
  108. <h6>Technicians hired before date <strong><?php echo $_POST['date_picked']?></strong> affected by <strong><?php echo $_POST['percentage_raise']?></strong>% raise.</h6>
  109. </div>
  110. <div class= "table-wrapper">
  111.  
  112. <table class="highlight">
  113. <thead>
  114. <tr>
  115. <th>Number</th>
  116. <th>Name</th>
  117. <th>Job</th>
  118. <th>Managers Name</th>
  119. <th>Hire Date</th>
  120. <th>Salary</th>
  121. <th>Bonus</th>
  122. </tr>
  123. </thead>
  124. <tbody>
  125. <?php
  126. foreach ($db->query($techniciansAffected) as $row) {?>
  127. <tr>
  128. <td><?php echo $row['tno'];?></td>
  129. <td><?php echo $row['tname']; ?></td>
  130. <td><?php echo $row['tjob']; ?></td>
  131. <td><?php echo $row['tmgr'];?></td>
  132. <td><?php echo $row['thiredate']; ?></td>
  133. <td><?php echo $row['tsalary']; ?></td>
  134. <td><?php echo $row['tbonus']; ?></td>
  135. </tr>
  136. <?php } ?>
  137. </tbody>
  138. </table>
  139. </div>
  140. <?php }?>
  141. </body>
  142. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement