<?php require_once '../lib/lib.everything.php'; enforce_master_on_off_switch($_SERVER['HTTP_ACCEPT_LANGUAGE']); $context = default_context(True); /**** ... ****/ $scan_id = $_GET['scan_id']; $key = $_POST['marker_number']; $marker = $_POST; $json_response = array('status' => 200, 'marker_number' => null, 'message' => ''); if ($key < 0) { if (($scan = get_scan($context->db, $scan_id)) && $marker['note'] && $marker['lat'] && $marker['lon']) { $context->db->query('START TRANSACTION'); $note_number = 1; foreach (get_scan_notes($context->db, array('scan' => $scan['id'])) as $note) { $note_number = max($note_number, $note['note_number'] + 1); } $note = add_scan_note($context->db, $scan['id'], $note_number); $note['note'] = $marker['note']; $note['latitude'] = $marker['lat']; $note['longitude'] = $marker['lon']; $note['user_id'] = $marker['user_id']; $user = get_user($context->db, $marker['user_id']); if ($user['name']) { $note['username'] = $user['name']; } else { $note['username'] = ''; } if ($marker['type'] && $marker['type'] == 'POLYGON') { $note['geometry'] = $marker['geometry']; } else {
<?php require_once '../lib/lib.everything.php'; enforce_master_on_off_switch($_SERVER['HTTP_ACCEPT_LANGUAGE']); $context = default_context(True); /**** ... ****/ $scan_id = $_GET['id'] ? $_GET['id'] : null; $scan = get_scan($context->db, $scan_id); $context->sm->assign('scan', $scan); $print = get_print($context->db, $scan['print_id']); $context->sm->assign('print', $print); $notes = get_scan_notes($context->db, array('scan' => $scan['id'])); $context->sm->assign('notes', $notes); $form = get_form($context->db, $print['form_id']); $context->sm->assign('form', $form); if (preg_match('#^(\\w+)/(\\d+)$#', $scan['print_id'], $matches)) { $print_id = $matches[1]; $page_number = $matches[2]; $context->sm->assign('page_number', $page_number); } $user = get_user($context->db, $scan['user_id']); if ($user['name']) { $context->sm->assign('user_name', $user['name']); } else { $context->sm->assign('user_name', 'Anonymous'); } if ($context->type == 'text/html') { header("Content-Type: text/html; charset=UTF-8"); print $context->sm->fetch("scan-polygon.html.tpl"); } elseif ($context->type == 'application/paperwalking+xml') { header("Content-Type: application/paperwalking+xml; charset=UTF-8");
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; }