Location: PHPKode > projects > PhpTimeClock > phptimeclock-2.0.0rc2/plugins/Punch_Board/load.php
<?php
/***************************************************************************
 * Copyright (C) 2006, 2008, 2009 by                                       *
 * PhpTimeClock team respective developers. http://www.PhpTimeClock.com/   *
 *                                                                         *
 * This program is free software: you can redistribute it and/or modify    *
 * it under the terms of the GNU Affero General Public License as          *
 * published by the Free Software Foundation, either version 3 of the      *
 * License, or (at your option) any later version.                         *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU Affero General Public License for more details.                     *
 *                                                                         *
 * You should have received a copy of the                                  *
 * GNU Affero General Public License along with this program.              *
 * If not, see http://www.gnu.org/licenses/.                               *
 ***************************************************************************/
/**
 * This module creates the user current/previous status table.
 */

if ('' == session_id()) {
    $page_description = "Punch Board";
    require_once '../../base/header.php';
    unset($page_description);
    $displayed_as_link = true;
} else {
    $displayed_as_link = false;
}

if (! is_application_enabled('Punch_Board')) {
    output_message('Punch Board is currently disabled.');
    return;
}

require PLUGIN_CONFIGURATION_FILE_NAME;
global $show_full_name;

if (OPTION_YES == $show_department_times_only) {
    require_once 'database_user_department.php';

    $departments = user_departments(authenticated_user_name());
    if (! empty($departments)) {
        foreach ($departments as $department) {
            $users_in_department = all_users_in_department($office, $department);
            foreach ($users_in_department as $user) {
                if (! array_search($users, $user)) {
                    $users[] = $user;
                }
            }
        }
    } else {
        $users = array();
    }
    unset($departments);
    unset($department);
    unset($users_in_department);
    unset($user);
} else {
    require_once 'database_user.php';
    $users = all_enabled_users();
}

open_group('punch-board');

if (! is_printer_friendly_mode()) {
    output_application_left('plugins/Punch_Board/load.php');
    output_printer_friendly_link();
    output_application_centre('plugins/Punch_Board/load.php');
}

open_group('display-board');
if (OPTION_YES == $display_header) {
    if ($displayed_as_link) {
        output_header(1, 'Current Punch Board Status');
    } else {
        output_header(2, 'Current Punch Board Status');
    }
}
$punch_headers = array();
$punches = array();
if (OPTION_YES == $display_name) {
    $punch_headers[] = 'Name';
}
if (OPTION_YES == $display_status) {
    $punch_headers[] = 'Status';
}
if (OPTION_YES == $display_date) {
    $punch_headers[] = 'Date';
}
if (OPTION_YES == $display_time) {
    $punch_headers[] = 'Time';
}
if (OPTION_YES == $display_department) {
    $punch_headers[] = 'Office';
    $punch_headers[] = 'Department';
}
if (OPTION_YES == $display_notes) {
    $punch_headers[] = 'Notes';
}
foreach ($users as $user) {
    $last_punch = user_last_punch($user);
    if (empty($last_punch)) { // Don't bother with users who have no punch
        continue;
    }
    $punch = array();
    if (OPTION_YES == $display_name) {
        if (OPTION_YES == $show_full_name) {
            $punch[] = user_full_name($user);
        } elseif (OPTION_NO == $show_full_name) {
            $punch[] = $user;
        }
    }
    if (OPTION_YES == $display_status) {
        // Get in or out status of the last punch
        $status = punch_status_information($last_punch['punch_status_name']);
        if (('Icon' == $display_status_option) or ('Both' == $display_status_option)) {
            if ($status['status_in']) { // An in status icon
                $status_row = START_NESTED_CALL.'output_image';
                $status_row .= PARAMETER_LIST_ITEM."themes/$theme_name/images/icons/status_in.gif";
                $status_row .= END_NESTED_CALL;
            } else { // An out status icon
                $status_row = START_NESTED_CALL.'output_image';
                $status_row .= PARAMETER_LIST_ITEM."themes/$theme_name/images/icons/status_out.gif";
                $status_row .= END_NESTED_CALL;
            }
        } else {
            $status_row = '';
        }
        $status_row .= START_NESTED_CALL.'output_text';
        $status_row .= PARAMETER_LIST_ITEM.$last_punch['punch_status_name'];
        $status_row .= PARAMETER_LIST_ITEM.'status-'.str_replace(' ', '-', $last_punch['punch_status_name']);
        $status_row .= END_NESTED_CALL;
        $punch[] = $status_row;
        unset($status_row);
    }
    if (OPTION_YES == $display_date) {
        $nested_call = START_NESTED_CALL.'output_text';
        $nested_call .= PARAMETER_LIST_ITEM.localise_date($last_punch['punch_time']);
        $nested_call .= PARAMETER_LIST_ITEM.'status-'.str_replace(' ', '-', $last_punch['punch_status_name']);
        $nested_call .= END_NESTED_CALL;
        $punch[] = $nested_call;
    }
    if (OPTION_YES == $display_time) {
        $nested_call = START_NESTED_CALL.'output_text';
        $nested_call .= PARAMETER_LIST_ITEM.localise_time($last_punch['punch_time']);
        $nested_call .= PARAMETER_LIST_ITEM.'status-'.str_replace(' ', '-', $last_punch['punch_status_name']);
        $nested_call .= END_NESTED_CALL;
        $punch[] = $nested_call;
    }
    if (OPTION_YES == $display_department) {
        if (empty($last_punch['department'])) {
            $punch[] = '';
            $punch[] = '';
        } else {
            $punch[] = $last_punch['department']['office_name'];
            $punch[] = $last_punch['department']['department_name'];
        }
    }
    if (OPTION_YES == $display_notes) {
        $punch[] = $last_punch['user_notes'];
    }
    $punches[] = $punch;
}
output_comment('Punch Status Log');
if (is_authentication_required('Punch_Board') and ! is_user_authenticated()) {
    output_message('You must be logged in to view the punch board.');
} else {
    output_table($punch_headers, $punches, 'punches');
    output_message('Punch board generated at '.localise_date_and_time(), 'generated');
}
close_group();

if (! is_printer_friendly_mode()) {
    output_application_right('base/punch_display.php');
}
close_group();

unset($punch_headers);
unset($punches);
unset($punch_width);
unset($users);
unset($user);
unset($last_punch);
unset($punch);
unset($status);
unset($status_row);

if ($displayed_as_link and (! is_printer_friendly_mode())) {
    require 'footer.php';
}
unset($displayed_as_link);
?>
Return current item: PhpTimeClock