// get cloned or refreshed details $clone_child = NULL; $clone_parent = NULL; if (!$print['cloned']) { $clone_child = get_latest_print_clone($context->db, $print_id); } else { $clone_parent = get_print($context->db, $print['cloned']); } $refresh_child = NULL; $refresh_parent = NULL; if (!$print['refreshed']) { $refresh_child = get_latest_print_refresh($context->db, $print_id); } else { $refresh_parent = get_print($context->db, $print['refreshed']); } $pages = get_print_pages($context->db, $print_id); $print['page_count'] = count($pages); $isOSM = false; if ($pages) { $i = 0; while ($i < count($pages)) { $page = $pages[$i]; // check to see if provider is OSM to control visibility of 'Refresh' button in template if (strpos($page['provider'], "openstreetmap") !== false) { $isOSM = true; } // get page zoom from first page if ($page['page_number'] == 'A1') { $print['page_zoom'] = $page['zoom']; } // construct extent string
/** * clones an exisiting atlas * $clone_id = id of print to be cloned * $is_refresh flag will set either the refreshed column or cloned column in the DB with the $clone_id **/ function compose_clone(&$dbh, $post, $user_id, $clone_id, $is_refresh = false) { $org_print = get_print($dbh, $clone_id); $org_pages = get_print_pages($dbh, $clone_id); // if(!is_array($pages)) // return null; $message = array('action' => 'compose', 'paper_size' => strtolower($org_print['paper_size']), 'orientation' => $org_print['orientation'], 'provider' => $org_print['provider'], 'layout' => $org_print['layout'], 'pages' => array()); // set print $print = add_print($dbh, $user_id); $print['title'] = $post['atlas_title']; $print['text'] = $org_print['text']; $print['paper_size'] = $message['paper_size']; $print['orientation'] = $message['orientation']; $print['layout'] = $message['layout']; $print['private'] = $org_print['private']; $print['north'] = $org_print['north']; $print['south'] = $org_print['south']; $print['west'] = $org_print['west']; $print['east'] = $org_print['east']; $print['country_name'] = $org_print['country_name']; $print['country_woeid'] = $org_print['country_woeid']; $print['region_name'] = $org_print['region_name']; $print['region_woeid'] = $org_print['region_woeid']; $print['place_name'] = $org_print['place_name']; $print['place_woeid'] = $org_print['place_woeid']; if ($is_refresh) { $print['refreshed'] = $clone_id; $print['cloned'] = NULL; } else { $print['refreshed'] = NULL; $print['cloned'] = $clone_id; } // create messages foreach ($org_pages as $org_page) { $bounds = array(floatval($org_page['north']), floatval($org_page['west']), floatval($org_page['south']), floatval($org_page['east'])); $text = trim(sprintf("%s\n\n%s", $print['title'], $print['text'])); if ($org_page['page_number'] == 'i') { $message['pages'][] = array('number' => 'i', 'zoom' => intval($org_page['zoom']), 'bounds' => $bounds, 'provider' => $org_page['provider'], 'role' => 'index', 'text' => ''); } else { $message['pages'][] = array('zoom' => intval($org_page['zoom']), 'number' => $org_page['page_number'], 'provider' => $org_page['provider'], 'bounds' => $bounds, 'text' => $text); } } // create pages in DB foreach ($message['pages'] as $i => $value) { $page = add_print_page($dbh, $print['id'], $value['number']); $page['zoom'] = $value['zoom']; $_page = $value['bounds']; $page['north'] = $_page[0]; $page['south'] = $_page[2]; $page['west'] = $_page[1]; $page['east'] = $_page[3]; $page['provider'] = $value['provider']; set_print_page($dbh, $page); // add grid overlay to the printed output of each non-index page: /* Disabled after fixing the URL until UI is available if($value['role'] != 'index') $message['pages'][$i]['provider'] = "{$value['provider']},http://tile.stamen.com/utm/{Z}/{X}/{Y}.png"; */ } // Not sure what forms table is or does but leaving it in for now (SeanC) if ($post['form_id'] && ($form = get_form($dbh, $post['form_id']))) { $print['form_id'] = $form['id']; if ($form['parsed']) { $message['form_fields'] = get_form_fields($dbh, $form['id']); } else { // The form hasn't been parsed yet, probably because // compose-atlas.php was called with just a form_url. $message['form_id'] = $form['id']; $message['form_url'] = $form['form_url']; } } $print['progress'] = 0.1; // the first 10% is getting it queued set_print($dbh, $print); $message['print_id'] = $print['id']; // queue the task queue_task("tasks.composePrint", array("http://" . SERVER_NAME, API_PASSWORD), $message); return $print; }
$pagination_args = array('perpage' => $prints_per_page, 'page' => $page_num); $title = get_args_title($context->db, $print_args); // get prints array and pagination object used by get_prints query list($prints, $pagination_results, $where_clauses) = get_prints($context->db, $context->user, $print_args, $pagination_args); // get total count of prints // passing in $print_args array to keep count in sync $prints_total = get_prints_count($context->db, $where_clauses); // update pagination results $pagination_results = get_prints_pagination_display_obj($pagination_results, $prints_total, $print_args); $users = array(); foreach ($prints as $i => $print) { $user_id = $print['user_id']; if ($users[$user_id] == null && $user_id != null) { $users[$user_id] = get_user($context->db, $user_id); } $pages = get_print_pages($context->db, $print['id']); $prints[$i]['number_of_pages'] = count($pages); $prints[$i]['user'] = $users[$user_id]; } $context->sm->assign('pagination', $pagination_results); $context->sm->assign('atlas_count', count($prints)); $context->sm->assign('title', $title); $context->sm->assign('prints', $prints); $context->sm->assign('prints_json', json_encode($prints)); $context->sm->assign('query_without_page', http_build_query($print_args)); if ($context->type == 'text/html') { header("Content-Type: text/html; charset=UTF-8"); print $context->sm->fetch("atlases.html.tpl"); } else { header('HTTP/1.1 400'); die("Unknown type.\n");
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; }