/** * Convert an array of form fields to an atlas composition and queue it up. */ function compose_from_postvars(&$dbh, $post, $user_id) { $extents = $post['pages']; $paper_size = isset($post['paper_size']) ? $post['paper_size'] : 'letter'; $orientation = isset($post['orientation']) ? $post['orientation'] : 'portrait'; $layout = isset($post['layout']) ? $post['layout'] : 'full-page'; $provider = $post['provider']; $title = $post['atlas_title']; $grid = filter_var($post['grid'], FILTER_VALIDATE_BOOLEAN) ? 1 : 0; $redcross = filter_var($post['redcross'], FILTER_VALIDATE_BOOLEAN) ? 1 : 0; $private = filter_var($post['private'], FILTER_VALIDATE_BOOLEAN) ? 1 : 0; if (!is_array($extents)) { return null; } // // "orientation" above refers to the *map*, so if we want half-size // we'll need to flip the orientation of the overall printed sheet // to accommodate it. // if ($orientation == 'landscape' && $layout == 'half-page') { $orientation = 'portrait'; } elseif ($orientation == 'portrait' && $layout == 'half-page') { $orientation = 'landscape'; } list($printed_width, $printed_height) = get_printed_dimensions($paper_size, $orientation, $layout); $printed_aspect = $printed_width / $printed_height; // We have all of the information. Make some pages. $message = array('action' => 'compose', 'paper_size' => strtolower($paper_size), 'orientation' => $orientation, 'provider' => $provider, 'layout' => $layout, 'pages' => array()); $print = add_print($dbh, $user_id); $print['title'] = $title; $print['text'] = trim($post['atlas_text']); $print['paper_size'] = $message['paper_size']; $print['orientation'] = $message['orientation']; $print['layout'] = $message['layout']; $print['private'] = $private; // build up bounds for each page in the message $print['north'] = -90; $print['east'] = -180; $print['south'] = 90; $print['west'] = 180; foreach ($extents as $key => $value) { list($north, $west, $south, $east) = array_map('floatval', explode(',', $value)); $mmap = create_mmap_from_bounds($paper_size, $orientation, $north, $west, $south, $east, $layout); $bounds = get_mmap_bounds($mmap); $text = trim(sprintf("%s\n\n%s", $post['atlas_title'], $post['atlas_text'])); $message['pages'][] = array('zoom' => $mmap->coordinate->zoom, 'number' => $key, 'provider' => $provider, 'bounds' => $bounds, 'text' => $text); $print['north'] = max($print['north'], $bounds[0]); $print['south'] = min($print['south'], $bounds[2]); $print['west'] = min($print['west'], $bounds[1]); $print['east'] = max($print['east'], $bounds[3]); } // prepare the index page and add it to the message for safekeeping. if (count($extents) > 1) { $mmap = create_mmap_from_bounds($paper_size, $orientation, $print['north'], $print['west'], $print['south'], $print['east'], $layout); $index = array('number' => 'i', 'zoom' => $mmap->coordinate->zoom, 'bounds' => get_mmap_bounds($mmap, 0.1), 'provider' => $provider, 'role' => 'index', 'text' => ''); array_unshift($message['pages'], $index); } // create pages based on message contents 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: if ($value['role'] != 'index' && $grid) { $message['pages'][$i]['provider'] = "{$value['provider']},http://tile.stamen.com/utm/{Z}/{X}/{Y}.png"; } if ($redcross) { $message['pages'][$i]['provider'] = "{$value['provider']},http://a.tiles.mapbox.com/v3/americanredcross.HAIYAN_Atlas_Bounds/{Z}/{X}/{Y}.png"; } } // Deal with WOEIDs $place = latlon_placeinfo(0.5 * ($print['north'] + $print['south']), 0.5 * ($print['west'] + $print['east']), $post['page_zoom'] - 3); $print['country_name'] = $place[0]; $print['country_woeid'] = $place[1]; $print['region_name'] = $place[2]; $print['region_woeid'] = $place[3]; $print['place_name'] = $place[4]; $print['place_woeid'] = $place[5]; 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.0; 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; }
$scan['will_edit'] = $_POST['will_edit']; $scan['has_geotiff'] = $_POST['has_geotiff']; $scan['has_geojpeg'] = $_POST['has_geojpeg']; $scan['has_stickers'] = $_POST['has_stickers']; if ($_POST['print_id'] && $_POST['print_page_number']) { $scan['print_id'] = $_POST['print_id']; $scan['print_page_number'] = $_POST['print_page_number']; } else { $scan['print_href'] = $_POST['print_href']; } if (preg_match('/^-?\\d+(\\.\\d+)?(,-?\\d+(\\.\\d+)?){3}$/', $_POST['geojpeg_bounds'])) { $scan['geojpeg_bounds'] = $_POST['geojpeg_bounds']; $zoom = $scan['min_zoom'] / 2 + $scan['max_zoom'] / 2; list($south, $west, $north, $east) = explode(',', $_POST['geojpeg_bounds']); $lat = $south / 2 + $north / 2; $lon = $west / 2 + $east / 2; $place = latlon_placeinfo($lat, $lon, $zoom); $scan['country_name'] = $place[0]; $scan['region_name'] = $place[2]; $scan['place_name'] = $place[4]; $scan['country_woeid'] = $place[1]; $scan['region_woeid'] = $place[3]; $scan['place_woeid'] = $place[5]; } add_log($context->db, "Posting additional details to scan {$scan['id']}"); set_scan($context->db, $scan); finish_scan($context->db, $scan['id']); $context->db->query('COMMIT'); } header('HTTP/1.1 200'); echo "OK\n";