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; }
<?php require_once '../lib/lib.everything.php'; enforce_master_on_off_switch($_SERVER['HTTP_ACCEPT_LANGUAGE']); enforce_api_password($_POST['password']); $context = default_context(False); /**** ... ****/ $print_id = $_GET['id'] ? $_GET['id'] : null; $print = get_print($context->db, $print_id); if (!$print) { die_with_code(400, "I don't know that print"); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $context->db->query('START TRANSACTION'); foreach ($_POST['pages'] as $page_number => $_page) { $page = get_print_page($context->db, $print['id'], $page_number); if (!$page) { die_with_code(400, "I don't know that page"); } $page['preview_url'] = $_page['preview_url']; set_print_page($context->db, $page); } $print['pdf_url'] = $_POST['pdf_url']; $print['preview_url'] = $_POST['preview_url']; set_print($context->db, $print); finish_print($context->db, $print['id']); $context->db->query('COMMIT'); } header('HTTP/1.1 200'); echo "OK\n";