Exemple #1
0
    die("No such atlas.\n");
}
// 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'];
Exemple #2
0
<?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 ($progress = $_POST['progress']) {
    $context->db->query('START TRANSACTION');
    $print['progress'] = $progress;
    set_print($context->db, $print);
    $context->db->query('COMMIT');
}
header('HTTP/1.1 200');
echo "OK\n";
Exemple #3
0
<?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");
Exemple #4
0
$center_x = $extent[1] + $extent[3] / 2;
$context->sm->assign('scan', $scan);
if ($scan['print_id'] && $scan['print_page_number']) {
    $print_id = $scan['print_id'];
    $print_page_number = $scan['print_page_number'];
} elseif ($scan['print_href']) {
    $parsed_print_href = parse_url($scan['print_href']);
    parse_str($parsed_print_href['query'], $href_fragment);
    if (preg_match('#(\\w+)\\/(\\w+)#', $href_fragment['id'], $m)) {
        $print_id = $m[1];
        $print_page_number = $m[2];
    }
}
$context->sm->assign('print_id', $print_id);
$context->sm->assign('print_page_number', $print_page_number);
if ($print_id && ($print = get_print($context->db, $print_id))) {
    $context->sm->assign('print', $print);
}
//Get the title of the print associated with the scan
if ($print['title']) {
    $title = $print['title'];
} else {
    $title = 'Untitled';
}
$context->sm->assign('title', $title);
$form = get_form($context->db, $print['form_id']);
$context->sm->assign('form', $form);
// Get the number of pages for the print
$pages = get_print_pages($context->db, $print_id);
$context->sm->assign('zoom', $pages[0]['zoom']);
$context->sm->assign('page_count', count($pages));
Exemple #5
0
}
$pagination_args = array('perpage' => $prints_per_page, 'page' => $page_num);
$title = get_args_title($context->db, $scan_args);
list($scans, $pagination_results, $where_clauses) = get_scans($context->db, $scan_args, $pagination_args);
// get total count of prints
// passing in $print_args array to keep count in sync
$scans_total = get_scans_count($context->db, $where_clauses);
// update pagination results
$pagination_results = get_scans_pagination_display_obj($pagination_results, $scans_total, $scan_args);
$users = array();
foreach ($scans as $i => $scan) {
    $user_id = $print['user_id'];
    if ($users[$user_id] == null && $user_id != null) {
        $users[$user_id] = get_user($context->db, $user_id);
    }
    $scans[$i]['user'] = $users[$user_id];
    if ($scan['print_id']) {
        $scans[$i]['print'] = get_print($context->db, $scan['print_id']);
    }
}
$context->sm->assign('pagination', $pagination_results);
$context->sm->assign('title', $title);
$context->sm->assign('scans', $scans);
$context->sm->assign('query_without_page', http_build_query($scan_args));
if ($context->type == 'text/html') {
    header("Content-Type: text/html; charset=UTF-8");
    print $context->sm->fetch("snapshots.html.tpl");
} else {
    header('HTTP/1.1 400');
    die("Unknown type.\n");
}
Exemple #6
0
/**
 * 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;
}
Exemple #7
0
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;
}