Login   Register  
PHP Classes
elePHPant
Icontem

File: employee_detail.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Shibly  >  Simple DAL  >  employee_detail.php  >  Download  
File: employee_detail.php
Role: Example script
Content type: text/plain
Description: sample file 2
Class: Simple DAL
Simple MySQL database abstraction layer
Author: By
Last change: code updated
Date: 2012-02-11 17:15
Size: 5,696 bytes
 

Contents

Class file image Download
<?php
include_once('SupplierDAL.php');
include_once(
'EmployeeDAL.php');

$employeeDal = new EmployeeDAL();


$isEditing = isset($_GET['id']);
if(
$isEditing){
    
$employeeId $_GET['id'];
}

if(isset(
$_POST['add'])){
    
//form submitted
    
$name $_POST['name'];
    
$email $_POST['email'];
    
$phone $_POST['phone'];
    
$address $_POST['address'];
    
$zip $_POST['zip'];
    
$basic_salary $_POST['basic_salary'];
    
$grade $_POST['grade'];
    
$related_suppliers $_POST['supplierid'];

    
$house_rent $basic_salary 0.4;
    
$allowance $basic_salary 0.2;
    
$income_tax $basic_salary 0.1;
    
$net_income $basic_salary $house_rent $allowance $income_tax;
    
    if(
$isEditing){
        
//update employee
        
$employeeDal->updateEmployee($employeeId$name$email$phone$address$zip$basic_salary$allowance$house_rent$income_tax$net_income$grade$related_suppliers);
    }
    else{
        
//insert employee
        
$employeeDal->insertEmployee($name$email$phone$address$zip$basic_salary$allowance$house_rent$income_tax$net_income$grade$related_suppliers);
        
header("Status: 200");
        
header("Location: index.php");
        exit();
    }
}

$assignedSuppliers = array();
$employeeDetail = array();
if (
$isEditing) {
    
$assignedSuppliers $employeeDal->getSuppliersForEmployee($employeeId);
    
$employeeDetail $employeeDal->getEmployeeDetail($employeeId);
}

?>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
    <title>Employee Management</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="validation.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#basic_salary").keyup(
                    function() {
                        var basic_salary = $("#basic_salary").val();
                        if (isNaN(basic_salary) || basic_salary.length == 0) {
                            $("#houseRent, #allowance, #incomeTax, #netIncome").html("--");
                        }
                        else {
                            $("#houseRent").html(basic_salary * 0.4);
                            $("#allowance").html(basic_salary * 0.2);
                            $("#incomeTax").html(basic_salary * 0.1);
                            var total = basic_salary * 1 + basic_salary * 0.4 + basic_salary * 0.2 + basic_salary * 0.1;
                            $("#netIncome").html(total);
                        }
                        return true;
                    }).trigger("keyup");
        });
    </script>

</head>
<body>
<div id="container">
    <h1>Employee Information</h1>

    <form method="post" id="employeeDetail"
          action="employee_detail.php<?php echo ($isEditing "?id=$employeeId""); ?>">
        <div>
            <label for="name">Name</label>
            <input id="name" name="name" type="text" value="<?php $employeeDetail['Name']; ?>"/>
            <span id="nameInfo"></span>
        </div>
        <div>
            <label for="email">E-mail</label>
            <input id="email" name="email" type="text" value="<?php echo $employeeDetail['Email']; ?>"/>
            <span id="emailInfo"></span>
        </div>
        <div>
            <label for="phone">Phone</label>
            <input id="phone" name="phone" type="text" value="<?php echo $employeeDetail['Phone']; ?>"/>
        </div>
        <div>
            <label for="address">Address</label>
            <textarea id="address" cols="1" rows="1" name="address"><?php echo $employeeDetail['Address']; ?></textarea>
        </div>
        <div>
            <label for="zip">Zip</label>
            <input type="text" id="zip" name="zip" value="<?php echo $employeeDetail['Zip']; ?>"/>
            <span id="zipInfo"></span>
        </div>
        <div>

            <label for="basic_salary">Basic Salary</label>
            <input type="text" id="basic_salary" name="basic_salary" value="<?php echo $employeeDetail['Basic']; ?>"/>
            <span id="basicSalaryInfo"></span>
        </div>
        <div>
            <label for="houseRent">House Rent</label>

            <div id="houseRent" class="salary"></div>
            <label for="Allowance">Allowance</label>

            <div id="allowance" class="salary"></div>
            <label for="IncomeTax">Income Tax</label>

            <div id="incomeTax" class="salary"></div>
            <label for="netIncome">Net Income</label>

            <div id="netIncome" class="salary"></div>
        </div>
        <div>
            <label for="grade">Grade</label>
            <input type="text" name="grade" id="grade" value="<?php echo $employeeDetail['Grade']; ?>"/>
        </div>


        <h1>Supplier list</h1>

        <div class="supplier">
<?php
            $supplier_detail 
= new SupplierDAL();
    
$list_suppliers $supplier_detail->getSuppliers();

    foreach (
$list_suppliers as $rows)
    {
        
?>
        <input type="checkbox" name="supplierid[]"
               <?php if(in_array($rows['SupplierID'],$assignedSuppliers)){ ?>
            checked="checked"
            <?php ?>
               value="<?php echo $rows['SupplierID']; ?>"/> <?php echo $rows['Name']; ?>
        <br/>
        <?php

    
}
    
?>
        </div>
        <input id="add" name="add" type="submit" value="<?php echo ($isEditing "Update" "Add"); ?>"/>
    </form>
</div>
</body>
</html>