Example #1
0
/**
 * This function displays all Jobs in the system
 */
function displayAllJobs()
{
    $field = 'JobID';
    $sort = 'ASC';
    if (isset($_GET['sorting'])) {
        if ($_GET['sorting'] == 'ASC') {
            $sort = 'ASC';
        } else {
            $sort = 'DESC';
        }
    }
    if (isset($_GET['field'])) {
        switch ($_GET['field']) {
            case "JobTitle":
                $field = 'JobTitle';
                break;
            case "MinSalary":
                $field = 'MinSalary';
                break;
            case "MaxSalary":
                $field = 'MaxSalary';
                break;
            default:
                $field = 'JobID';
        }
    }
    global $db_conn;
    $stmt = mysqli_stmt_init($db_conn);
    $sql = "SELECT * FROM `jobs` ORDER BY {$field} {$sort}";
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        print "Failed to prepare statement\n";
    } else {
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        mysqli_stmt_close($stmt);
        ?>
			<h1>Jobs</h1>
			<br/>
			<input type="button" onclick="document.location.href='?action=addJob';" value="Add Job" />
			<br/>
			<br/>
			<table>
				<tr>
					<th>Job ID <br/> <?php 
        echo parseSorting("jobs", "JobID", $field, $sort);
        ?>
</th>
					<th>Title <br/> <?php 
        echo parseSorting("jobs", "JobTitle", $field, $sort);
        ?>
</th>
					<th>Minimum Salary <br/> <?php 
        echo parseSorting("jobs", "MinSalary", $field, $sort);
        ?>
</th>
					<th>Maximum Salary <br/> <?php 
        echo parseSorting("jobs", "MaxSalary", $field, $sort);
        ?>
</th>
					<th>Action</th>
				</tr>

				<?php 
        $count = 1;
        while ($row = mysqli_fetch_assoc($result)) {
            $count++;
            ?>
					<tr <?php 
            if ($count % 2 == 0) {
                echo "class=\"highlight\" ";
            }
            ?>
>
						<td><?php 
            echo $row['JobID'];
            ?>
</td>
						<td><?php 
            echo $row['JobTitle'];
            ?>
</td>
						<td><?php 
            echo $row['MinSalary'];
            ?>
</td>
						<td><?php 
            echo $row['MaxSalary'];
            ?>
</td>
						<td>
							<a href="index.php?action=editJob&amp;id=<?php 
            echo $row['JobID'];
            ?>
">Edit</a>|<a class="delete" href="javascript:confirmAction('Are you sure?', 'index.php?action=deleteJob&amp;id=<?php 
            echo $row['JobID'];
            ?>
');">Remove</a>
						</td>
					</tr>
					<?php 
        }
        ?>
				</table>
				<?php 
    }
}
Example #2
0
/**
 * This is a template rendering function. As such it 
 * serves illustrative purposes and in general needs to
 * be configured for specific needs.
 * 
 * This function makes a report of all the records in the 
 * Jobs table. It outputs HTML and can sort records in the
 * table based on a predefined field and sortation order.
 */
function displayAllJobs()
{
    global $db_conn;
    #references connection to the database
    $field = 'JobID';
    #default sort column
    $sort = 'ASC';
    #default sorting order
    // Set the sortation order requested via the URL
    if (isset($_GET['sorting'])) {
        if ($_GET['sorting'] == 'ASC') {
            $sort = 'ASC';
        } else {
            $sort = 'DESC';
        }
    }
    // Set the sortation field requested by URL
    // on which soration should be applied
    if (isset($_GET['field'])) {
        switch ($_GET['field']) {
            case "JobTitle":
                $field = 'JobTitle';
                break;
            case "MinSalary":
                $field = 'MinSalary';
                break;
            case "MaxSalary":
                $field = 'MaxSalary';
                break;
            default:
                $field = 'JobID';
        }
    }
    // initializes a statement and return an object for use
    // with mysqli_stmt_prepare
    $stmt = mysqli_stmt_init($db_conn);
    // the query that should be parsed
    $sql = "SELECT * FROM `jobs` ORDER BY {$field} {$sort}";
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        // if things go wrong we sent a message to the screen
        add_to_message_stack("Query could not be parsed. This message is logged", true);
        // and a message to the system log. Note we do not give information
        // about SQL to the user.
        log_message("Query could not be parsed: " . $sql);
    } else {
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        mysqli_stmt_close($stmt);
        ?>
			<h1>Jobs</h1>
			<br/>
			<input type="button" onclick="document.location.href='?action=addJob';" value="Add Job" />
			<br/>
			<br/>
			<table>
				<tr>
					<th>Job ID <br/> <?php 
        echo parseSorting("jobs", "JobID", $field, $sort);
        ?>
</th>
					<th>Title <br/> <?php 
        echo parseSorting("jobs", "JobTitle", $field, $sort);
        ?>
</th>
					<th>Minimum Salary <br/> <?php 
        echo parseSorting("jobs", "MinSalary", $field, $sort);
        ?>
</th>
					<th>Maximum Salary <br/> <?php 
        echo parseSorting("jobs", "MaxSalary", $field, $sort);
        ?>
</th>
					<th>Action</th>
				</tr>

				<?php 
        $count = 1;
        while ($row = mysqli_fetch_assoc($result)) {
            $count++;
            ?>
					<tr <?php 
            if ($count % 2 == 0) {
                echo "class=\"highlight\" ";
            }
            ?>
>
						<td><?php 
            echo $row['JobID'];
            ?>
</td>
						<td><?php 
            echo $row['JobTitle'];
            ?>
</td>
						<td><?php 
            echo $row['MinSalary'];
            ?>
</td>
						<td><?php 
            echo $row['MaxSalary'];
            ?>
</td>
						<td>
							<a href="index.php?action=editJob&amp;id=<?php 
            echo $row['JobID'];
            ?>
">Edit</a>|<a class="delete" href="javascript:confirmAction('Are you sure?', 'index.php?action=deleteJob&amp;id=<?php 
            echo $row['JobID'];
            ?>
');">Remove</a>
						</td>
					</tr>
					<?php 
        }
        ?>
				</table>
				<?php 
    }
}
Example #3
0
/**
 * This function shows all the employees
 */
function displayAllEmployees()
{
    $field = 'EmployeeID';
    $sort = 'ASC';
    if (isset($_GET['sorting'])) {
        if ($_GET['sorting'] == 'ASC') {
            $sort = 'ASC';
        } else {
            $sort = 'DESC';
        }
    }
    if (isset($_GET['field'])) {
        switch ($_GET['field']) {
            case "FirstName":
                $field = 'FirstName';
                break;
            case "LastName":
                $field = 'LastName';
                break;
            case "Email":
                $field = 'Email';
                break;
            case "PhoneNumber":
                $field = 'PhoneNumber';
                break;
            case "HireDate":
                $field = 'HireDate';
                break;
            case "JobID":
                $field = 'JobID';
                break;
            case "Salary":
                $field = 'Salary';
                break;
            case "CommissionPCT":
                $field = 'CommissionPCT';
                break;
            case "ManagerID":
                $field = 'ManagerID';
                break;
            case "DepartmentID":
                $field = 'DepartmentID';
                break;
            default:
                $field = 'EmployeeID';
        }
    }
    global $db_conn;
    $stmt = mysqli_stmt_init($db_conn);
    $sql = "SELECT * FROM `employees` ORDER BY {$field} {$sort}";
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        print "Failed to prepare statement\n";
    } else {
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        mysqli_stmt_close($stmt);
        ?>

        <h1>Employees</h1>
        <br/>  
        <input type="button" onclick="document.location.href='?action=addEmployee';" value="Add Employee" />
        <br/>
        <br/>
        <table>
         <tr>
           <th>EmployeeID <br/> <?php 
        echo parseSorting("employees", "EmployeeID", $field, $sort);
        ?>
</th>
           <th>FirstName <br/> <?php 
        echo parseSorting("employees", "FirstName", $field, $sort);
        ?>
</th>
           <th>Lastname <br/> <?php 
        echo parseSorting("employees", "LastName", $field, $sort);
        ?>
</th>
           <th>Email <br/> <?php 
        echo parseSorting("employees", "Email", $field, $sort);
        ?>
</th>
           <th>Phone <br/> <?php 
        echo parseSorting("employees", "PhoneNumber", $field, $sort);
        ?>
</th>
           <th>Hire Date <br/> <?php 
        echo parseSorting("employees", "HireDate", $field, $sort);
        ?>
</th>
           <th>JobID <br/> <?php 
        echo parseSorting("employees", "JobID", $field, $sort);
        ?>
</th>
           <th>Salary <br/> <?php 
        echo parseSorting("employees", "Salary", $field, $sort);
        ?>
</th>
           <th>Commission PCT <br/> <?php 
        echo parseSorting("employees", "CommissionPCT", $field, $sort);
        ?>
</th>
           <th>ManagerID <br/> <?php 
        echo parseSorting("employees", "JobTitle", $field, $sort);
        ?>
</th>
           <th>DepartmentID <br/> <?php 
        echo parseSorting("employees", "ManagerID", $field, $sort);
        ?>
</th>
           <th>Action</th>
         </tr>


         <?php 
        $count = 1;
        while ($row = mysqli_fetch_assoc($result)) {
            $count++;
            ?>
          
          <tr <?php 
            if ($count % 2 == 0) {
                echo "class=\"highlight\" ";
            }
            ?>
>
            <td><?php 
            echo $row['EmployeeID'];
            ?>
</td>
            <td><?php 
            echo $row['FirstName'];
            ?>
</td>
            <td><?php 
            echo $row['LastName'];
            ?>
</td>
            <td><?php 
            echo $row['Email'];
            ?>
</td>
            <td><?php 
            echo $row['PhoneNumber'];
            ?>
</td>
            <td><?php 
            echo date("d-m-Y", strtotime($row['HireDate']));
            ?>
</td>
            <td><?php 
            echo $row['JobID'];
            ?>
</td>
            <td><?php 
            echo $row['Salary'];
            ?>
</td>
            <td><?php 
            echo $row['CommissionPCT'];
            ?>
</td>
            <td><?php 
            echo $row['ManagerID'];
            ?>
</td>
            <td><?php 
            echo $row['DepartmentID'];
            ?>
</td>
            <td>
              <a href="index.php?action=editEmployee&amp;id=<?php 
            echo $row['EmployeeID'];
            ?>
">Edit</a>|<a class="delete" href="javascript:confirmAction('Are you sure?', 'index.php?action=deleteEmployee&amp;id=<?php 
            echo $row['EmployeeID'];
            ?>
');">Remove</a>
            </td>
          </tr>
          <?php 
        }
        ?>
        </table>
        <?php 
    }
}
/**
 * This is a template rendering function. As such it 
 * serves illustrative purposes and in general needs to
 * be configured for specific needs.
 * 
 * This function makes a report of all the records in the 
 * Jobs table. It outputs HTML and can sort records in the
 * table based on a predefined field and sortation order.
 */
function displayAllCustomers()
{
    log_message("Backtrace: displayAllCustomers() called. ");
    global $db_conn;
    #references connection to the database
    $field = 'Wcode';
    #default sort column
    $sort = 'ASC';
    #default sorting order
    // Set the sortation order requested via the URL
    if (isset($_GET['sorting'])) {
        if ($_GET['sorting'] == 'ASC') {
            $sort = 'ASC';
        } else {
            $sort = 'DESC';
        }
    }
    // Set the sortation field requested by URL
    // on which soration should be applied
    if (isset($_GET['field'])) {
        switch ($_GET['field']) {
            case "Wcode":
                $field = 'Wcode';
                break;
            case "Naam":
                $field = 'Naam';
                break;
            case "Adres":
                $field = 'Adres';
                break;
            case "Plaats":
                $field = 'Plaats';
                break;
            case "Telefoonnr":
                $field = 'Plaats';
                break;
            default:
                $field = 'JobID';
        }
    }
    // initializes a statement and return an object for use
    // with mysqli_stmt_prepare
    $stmt = mysqli_stmt_init($db_conn);
    // the query that should be parsed
    $sql = "SELECT * FROM `winkel` ORDER BY {$field} {$sort}";
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        // if things go wrong we sent a message to the screen
        add_to_message_stack("Query could not be parsed. This message is logged", true);
        // and a message to the system log. Note we do not give information
        // about SQL to the user.
        log_message("Query could not be parsed: " . $sql);
    } else {
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        mysqli_stmt_close($stmt);
        ?>
			<h1>Customers</h1>
			<br/>
			<input type="button" onclick="document.location.href='?action=displayAddCustomer';" value="Add Customer" />
			<br/>
			<br/>
			<table>
				<tr>
					<th>Wcode <br/> <?php 
        echo parseSorting("showCustomers", "Wcode", $field, $sort);
        ?>
</th>
					<th>Name <br/> <?php 
        echo parseSorting("showCustomers", "Naam", $field, $sort);
        ?>
</th>
					<th>Address <br/> <?php 
        echo parseSorting("showCustomers", "Adres", $field, $sort);
        ?>
</th>
					<th>Place <br/> <?php 
        echo parseSorting("showCustomers", "Plaats", $field, $sort);
        ?>
</th>
					<th>Phone number <br/> <?php 
        echo parseSorting("showCustomers", "Telefoonnr", $field, $sort);
        ?>
</th>
					<th>Action</th>
				</tr>

				<?php 
        $count = 1;
        while ($row = mysqli_fetch_assoc($result)) {
            $count++;
            ?>
					<tr <?php 
            if ($count % 2 == 0) {
                echo "class=\"highlight\" ";
            }
            ?>
>
						<td><?php 
            echo $row['Wcode'];
            ?>
</td>
						<td><?php 
            echo $row['Naam'];
            ?>
</td>
						<td><?php 
            echo $row['Adres'];
            ?>
</td>
						<td><?php 
            echo $row['Plaats'];
            ?>
</td>
						<td><?php 
            echo $row['Telefoonnr'];
            ?>
</td>
						<td>
							<a href="index.php?action=displayEditCustomer&amp;id=<?php 
            echo $row['Wcode'];
            ?>
">Edit</a>|<a class="delete" href="javascript:confirmAction('Are you sure?', 'index.php?action=deleteCustomer&amp;id=<?php 
            echo $row['Wcode'];
            ?>
');">Remove</a>
						</td>
					</tr>
					<?php 
        }
        ?>
				</table>
				<?php 
    }
}
Example #5
0
/**
 * This function displays all Locations in the system
 */
function displayAllLocations()
{
    $field = 'LocationID';
    $sort = 'ASC';
    if (isset($_GET['sorting'])) {
        if ($_GET['sorting'] == 'ASC') {
            $sort = 'ASC';
        } else {
            $sort = 'DESC';
        }
    }
    if (isset($_GET['field'])) {
        switch ($_GET['field']) {
            case "StreetAddress":
                $field = 'StreetAddress';
                break;
            case "PostalCode":
                $field = 'PostalCode';
                break;
            case "City":
                $field = 'City';
                break;
            case "StateProvince":
                $field = 'StateProvince';
                break;
            case "CountryID":
                $field = 'CountryID';
                break;
            default:
                $field = 'LocationID';
        }
    }
    global $db_conn;
    $stmt = mysqli_stmt_init($db_conn);
    $sql = "SELECT * FROM `locations` ORDER BY {$field} {$sort}";
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        print "Failed to prepare statement\n";
    } else {
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        mysqli_stmt_close($stmt);
        ?>
        <h1>Locations</h1>
        <br/>
        <input type="button" onclick="document.location.href='?action=addLocation';" value="Add Location" />
        <br/>
        <br/>
        <table>
         <tr>
           <th> Location ID <br/> <?php 
        echo parseSorting("locations", "LocationID", $field, $sort);
        ?>
</th>
           <th>Street Adress <br/> <?php 
        echo parseSorting("locations", "StreetAddress", $field, $sort);
        ?>
</th>
           <th>Postalcode <br/> <?php 
        echo parseSorting("locations", "PostalCode", $field, $sort);
        ?>
</th>
           <th>City <br/> <?php 
        echo parseSorting("locations", "City", $field, $sort);
        ?>
</th>
           <th>State or Province <br/> <?php 
        echo parseSorting("locations", "StateProvince", $field, $sort);
        ?>
</th>
           <th>CountryID <br/> <?php 
        echo parseSorting("locations", "CountryID", $field, $sort);
        ?>
</th>
           <th>Action</th>
         </tr>
         <?php 
        $count = 1;
        while ($row = mysqli_fetch_assoc($result)) {
            $count++;
            ?>
          <tr <?php 
            if ($count % 2 == 0) {
                echo "class=\"highlight\" ";
            }
            ?>
>
            <td><?php 
            echo $row['LocationID'];
            ?>
</td>
            <td><?php 
            echo $row['StreetAddress'];
            ?>
</td>
            <td><?php 
            echo $row['PostalCode'];
            ?>
</td>
            <td><?php 
            echo $row['City'];
            ?>
</td>
            <td><?php 
            echo $row['StateProvince'];
            ?>
</td>
            <td><?php 
            echo $row['CountryID'];
            ?>
</td>
            <td>
              <a href="index.php?action=editLocation&amp;id=<?php 
            echo $row['LocationID'];
            ?>
">Edit</a>|<a class="delete" href="javascript:confirmAction('Are you sure?', 'index.php?action=deleteLocation&amp;id=<?php 
            echo $row['LocationID'];
            ?>
');">Remove</a>
            </td>
          </tr>
          <?php 
        }
        ?>
        </table>
        <?php 
    }
}