<?php require_once '../lib/lib.everything.php'; enforce_master_on_off_switch($_SERVER['HTTP_ACCEPT_LANGUAGE']); $context = default_context(True); /**** ... ****/ $form_id = $_GET['id'] ? $_GET['id'] : null; $form = get_form($context->db, $form_id); $user = get_user($context->db, $form['user_id']); if ($user['name']) { $form['user_name'] = $user['name']; } else { $form['user_name'] = 'Anonymous'; } $context->sm->assign('form', $form); // Get fields $fields = get_form_fields($context->db, $form_id); $context->sm->assign('fields', $fields); $type = $_GET['type'] ? $_GET['type'] : $_SERVER['HTTP_ACCEPT']; $type = get_preferred_type($type); if ($type == 'text/html') { header("Content-Type: text/html; charset=UTF-8"); print $context->sm->fetch("form.html.tpl"); } else { header('HTTP/1.1 400'); die("Unknown type.\n"); }
/** * 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; }