예제 #1
0
require_once '../lib/lib.everything.php';
enforce_master_on_off_switch($_SERVER['HTTP_ACCEPT_LANGUAGE']);
$context = default_context(True);
/**** ... ****/
$scan_args = array('date' => preg_match('#^\\d{4}-\\d\\d-\\d\\d$#', $_GET['date']) ? $_GET['date'] : null, 'month' => preg_match('#^\\d{4}-\\d\\d$#', $_GET['month']) ? $_GET['month'] : null, 'place' => is_numeric($_GET['place']) ? $_GET['place'] : null, 'user' => preg_match('/^\\w+$/', $_GET['user']) ? $_GET['user'] : null);
// set intial pagination request params
// TODO: globalize prints_per_page
$prints_per_page = 50;
$page_num = 1;
if (isset($_GET['page'])) {
    $page_num = intval($_GET['page']);
}
$pagination_args = array('perpage' => $prints_per_page, 'page' => $page_num);
$title = get_args_title($context->db, $scan_args);
list($scans, $pagination_results, $where_clauses) = get_scans($context->db, $scan_args, $pagination_args);
// get total count of prints
// passing in $print_args array to keep count in sync
$scans_total = get_scans_count($context->db, $where_clauses);
// update pagination results
$pagination_results = get_scans_pagination_display_obj($pagination_results, $scans_total, $scan_args);
$users = array();
foreach ($scans as $i => $scan) {
    $user_id = $print['user_id'];
    if ($users[$user_id] == null && $user_id != null) {
        $users[$user_id] = get_user($context->db, $user_id);
    }
    $scans[$i]['user'] = $users[$user_id];
    if ($scan['print_id']) {
        $scans[$i]['print'] = get_print($context->db, $scan['print_id']);
    }
                    echo 'Failed to log in';
                }
                insert_record('attendance_scan_logs', $rec);
                add_to_log($course->id, 'attforblock', 'scan added', 'scan.php?course=' . $course->id, $user->lastname . ' ' . $user->firstname);
            } else {
                print_error('cantaddscan', 'attforblock', "scan.php?id={$id}");
            }
            break;
    }
}
show_tabs($cm, $context, 'scan');
$i = 1;
$table->width = '400px';
$table->head = array('#', get_string('scan', 'attforblock'));
$table->align = array('center', 'center', 'center');
$scans = get_scans($course->id);
if (count_records_select('attendance_scan_logs')) {
    // check if session titles exist
    foreach ($scans as $st) {
        $table->data[$i][] = $i;
        $table->data[$i][] = userdate($st->timescanned, get_string('strftimehm', 'attforblock'));
        $table->data[$i][] = ereg_replace("[^A-Za-z]", "", $st->scan);
        if ($st->scannedin == 0) {
            $table->data[$i][] = 'Out';
        } else {
            $table->data[$i][] = 'In';
        }
        $i++;
    }
}
$new_row = array('*', '<input type="password" name="newscan" size="30" maxlength="30" value="" />', '<input type="submit" name="action" value="' . get_string('scan', 'attforblock') . '"/>');
예제 #3
0
function get_print_activity(&$dbh, $print_id, $group_notes)
{
    $print = get_print($dbh, $print_id);
    $pages = get_print_pages($dbh, $print_id);
    $print['page_count'] = count($pages);
    $print['pages'] = $pages;
    $users = array();
    $user_id = $print['user_id'];
    if ($users[$user_id] == null && $user_id != null) {
        $users[$user_id] = get_user($dbh, $user_id);
    }
    $print['user_name'] = $users[$user_id]['name'];
    list($scans, $pagination_results, $where_clauses) = get_scans($dbh, array('print' => $print['id']), 9999);
    if ($scans) {
        $note_args = array('scans' => array());
        foreach ($scans as $i => $scan) {
            $note_args['scans'][] = $scan['id'];
            $user_id = $scan['user_id'];
            if ($users[$user_id] == null && $user_id != null) {
                $users[$user_id] = get_user($dbh, $user_id);
            }
            $scans[$i]['user_name'] = $users[$user_id]['name'];
            $scans[$i]['page'] = get_print_page($dbh, $scan['print_id'], $scan['print_page_number']);
        }
        $notes = get_scan_notes($dbh, $note_args);
        foreach ($notes as $i => $note) {
            $notes[$i]['scan'] = $scan;
            $user_id = $note['user_id'];
            if (is_null($users[$user_id])) {
                $users[$user_id] = get_user($dbh, $user_id);
            }
            $notes[$i]['user_name'] = $users[$user_id]['name'];
        }
    } else {
        $notes = array();
    }
    $activity = array(array('type' => 'print', 'print' => $print));
    $times = array($print['created']);
    foreach ($scans as $scan) {
        $activity[] = array('type' => 'scan', 'scan' => $scan);
        $times[] = $scan['created'];
    }
    foreach ($notes as $note) {
        $activity[] = array('type' => 'note', 'note' => $note);
        $times[] = $note['created'];
    }
    array_multisort($times, SORT_ASC, $activity);
    if ($group_notes) {
        $scan_note_indexes = array();
        // group notes into lists by scan, ending on the latest
        for ($i = count($activity) - 1; $i >= 0; $i--) {
            if ($activity[$i]['type'] != 'note') {
                continue;
            }
            $note = $activity[$i]['note'];
            $group = "{$note['scan']['id']}-{$note['user_name']}";
            if (isset($scan_note_indexes[$group])) {
                //
                // Add this note to the existing array in the activity list.
                //
                $index = $scan_note_indexes[$group];
                array_unshift($activity[$index]['notes'], $note);
                $activity[$i] = array('type' => false);
            } else {
                //
                // Most-recent note by this person on this scan;
                // prepare an array of notes in the activity list.
                //
                $scan_note_indexes[$group] = $i;
                $activity[$i] = array('type' => 'notes', 'notes' => array($note));
            }
        }
    }
    return $activity;
}