Exemplo n.º 1
0
{
    function getPosition()
    {
        return "CEO";
    }
}
# Create an instance of our employee extension class, CEO. The calls to
# getName() and getPosition() are standard, the call to getTitle() uses
# the director wrappers to call CEO.getPosition.
$e = new CEO("Alice");
print $e->getName() . " is a " . $e->getPosition() . "\n";
printf("Just call her \"%s\"\n", $e->getTitle());
print "----------------------\n";
# Create a new EmployeeList instance.  This class does not have a C++
# director wrapper, but can be used freely with other classes that do.
$list = new EmployeeList();
# EmployeeList owns its items, so we must surrender ownership of objects
# we add. This involves first clearing the ->disown member to tell the
# C++ director to start reference counting.
$e->thisown = 0;
$list->addEmployee($e);
print "----------------------\n";
# Now we access the first four items in list (three are C++ objects that
# EmployeeList's constructor adds, the last is our CEO). The virtual
# methods of all these instances are treated the same. For items 0, 1, and
# 2, both all methods resolve in C++. For item 3, our CEO, getTitle calls
# getPosition which resolves in PHP. The call to getPosition is
# slightly different, however, from the e.getPosition() call above, since
# now the object reference has been "laundered" by passing through
# EmployeeList as an Employee*. Previously, PHP resolved the call
# immediately in CEO, but now PHP thinks the object is an instance of
                <thead>
                    <tr>                        
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Phone</th>
                        <th>E-mail</th>
                        <th>UserName</th>
                        <th>Password</th>
                        <th>Permission</th>
<!--                        <th>Info/Editing</th>-->
                    </tr>                    
                </thead> 
                <tbody>
                    <?php 
include_once 'EmployeeList.php';
$employeeObj = new EmployeeList();
$repsList = $employeeObj->GetRepresentativeList();
if (count($repsList) == 0) {
    echo 'There is no representatives in database';
} else {
    while ($row = mysql_fetch_array($repsList)) {
        ?>
                    <tr>
                        <td><?php 
        echo $row['FirstName'];
        ?>
</td>
                        <td><?php 
        echo $row['LastName'];
        ?>
</td>
Exemplo n.º 3
0
{
    public function search($term)
    {
        $employees = array();
        $connection = mysqli_connect("localhost", "root", "", "pyus") or die(mysqli_connect_error());
        $query = $connection->prepare("SELECT username, firstname, surname FROM employees WHERE username LIKE ? OR firstname LIKE ? OR surname LIKE ?;");
        $term = $term . "%";
        $query->bind_param("sss", $term, $term, $term);
        $query->execute();
        $result = $query->get_result();
        while ($row = $result->fetch_assoc()) {
            array_push($employees, new Employee($row['username'], $row['firstname'], $row['surname']));
        }
        return $employees;
    }
}
?>

<form action='list.php' method='POST'>
<input name='term' placeholder='search'><br/>
<input type='submit' value="Search">
</form>

<?php 
$employees = new EmployeeList();
if (isset($_POST['term'])) {
    $term = $_POST['term'];
    foreach ($employees->search($term) as $employee) {
        echo "<b>" . $employee->surname . "</b>, " . $employee->firstname . " (" . $employee->username . ")</br>";
    }
}