Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $dbname = "laboratory";
- $db = new mysqli($hostname, $username, $password, $dbname) or die ("Could Not Connect To MySql");
- function increaseSalaries($date, $percentage){
- $updateBonus = "UPDATE technician SET tbonus = tsalary * " . $percentage . "/100 WHERE thiredate <'".$date . "'; UPDATE technician SET tsalary = (" . $percentage . "/100 * tsalary+tsalary) WHERE thiredate <'". $date. "'";
- return $updateBonus;
- }
- ?>
- <!DOCTYPE HTML>
- <html>
- <head>
- <link href='https://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'>
- <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css">
- <meta charset='utf-8'>
- <title>University-jxc02</title>
- <link rel='stylesheet' href='public/css/screen.css' />
- </head>
- <body>
- <div class= "header">
- <div class='header-content'>
- <p>Jaad Chacra - University Database</p>
- </div>
- </div>
- <div class="name-form">
- <h5>Submit the name of the Lab to retrieve information about the technicians that belong to this department </h5>
- <div class="row">
- <form class="col s12" method = "post">
- <div class="row">
- <div class="input-field col s12">
- <input placeholder="" id="lab_name" name="lab_name"type="text" class="validate">
- <label class="active"disabled="true"for="lab_name">Lab Name</label>
- </div>
- </div>
- <div class="buttons-wrapper">
- <input type ="submit" class ="btn waves-effect waves-light buttons" value = "Submit"/>
- </div>
- </form>
- </div>
- </div>
- <?php if(isset($_POST['lab_name'])){ ?>
- <div class="result-description">
- <h6>Technicians belonging to the lab <strong><?php echo $_POST['lab_name']?></strong></h6>
- </div>
- <div class= "table-wrapper">
- <table class="highlight">
- <thead>
- <tr>
- <th>Number</th>
- <th>Name</th>
- <th>Job</th>
- <th>Managers Name</th>
- <th>Hire Date</th>
- <th>Salary</th>
- <th>Bonus</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $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" ;
- foreach ($db->query($techniciansReturned) as $row) {?>
- <tr>
- <td><?php echo $row['tno'];?></td>
- <td><?php echo $row['tname']; ?></td>
- <td><?php echo $row['tjob']; ?></td>
- <td><?php echo $row['mname'];?></td>
- <td><?php echo $row['thiredate']; ?></td>
- <td><?php echo $row['tsalary']; ?></td>
- <td><?php echo $row['tbonus']; ?></td>
- </tr>
- <?php }?>
- </tbody>
- </table>
- </div>
- <?php }?>
- <div class="update-salaries-form">
- <h5>Submit the date and a percentage of raise to update the salaries of technicians concerned</h5>
- <div class="row">
- <form class="col s12" method="post">
- <div class= "input-field col s6">
- <input type="date" class="datepicker" id="date_picked" name="date_picked">
- </div>
- <div class ="input-field col s6">
- <input placeholder="" id="percentage_raise" type="text" name="percentage_raise"class="validate">
- <label class="active"for="percentage_raise">Percentage</label>
- </div>
- <div class="buttons-wrapper">
- <input name = "submit_second_form"type ="submit" class ="btn waves-effect waves-light buttons" value = "Submit"/>
- </div>
- </form>
- </div>
- </div>
- <?php if($_POST['submit_second_form'] =="Submit" &&isset($_POST['date_picked']) && isset($_POST['percentage_raise'])) {
- $db->exec(increaseSalaries($_POST['date_picked'], $_POST['percentage_raise']));
- $techniciansAffected = "SELECT tno, tname, tjob, tmgr, thiredate, tsalary, tbonus FROM TECHNICIAN t WHERE thiredate <'" . $_POST['date_picked']. "'" ;
- ?>
- <div class="result-description">
- <h6>Technicians hired before date <strong><?php echo $_POST['date_picked']?></strong> affected by <strong><?php echo $_POST['percentage_raise']?></strong>% raise.</h6>
- </div>
- <div class= "table-wrapper">
- <table class="highlight">
- <thead>
- <tr>
- <th>Number</th>
- <th>Name</th>
- <th>Job</th>
- <th>Managers Name</th>
- <th>Hire Date</th>
- <th>Salary</th>
- <th>Bonus</th>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach ($db->query($techniciansAffected) as $row) {?>
- <tr>
- <td><?php echo $row['tno'];?></td>
- <td><?php echo $row['tname']; ?></td>
- <td><?php echo $row['tjob']; ?></td>
- <td><?php echo $row['tmgr'];?></td>
- <td><?php echo $row['thiredate']; ?></td>
- <td><?php echo $row['tsalary']; ?></td>
- <td><?php echo $row['tbonus']; ?></td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- </div>
- <?php }?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement