Example #1
0
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
require_once 'geograph/gridimage.class.php';
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/imagelist.class.php';
require_once 'geograph/map.class.php';
require_once 'geograph/mapmosaic.class.php';
require_once 'geograph/rastermap.class.php';
include_messages('browse');
init_session();
$smarty = new GeographPage();
dieUnderHighLoad(4);
customGZipHandlerStart();
$square = new GridSquare();
if (isset($_GET['inner'])) {
    $template = 'browse_inner.tpl';
} else {
    $template = 'browse.tpl';
    $smarty->assign('prefixes', $square->getGridPrefixes());
    $smarty->assign('kmlist', $square->getKMList());
}
//we can be passed a gridreference as gridsquare/northings/eastings
//or just gridref. So lets initialise our grid square
$grid_given = false;
$grid_ok = false;
if (isset($_GET['nl'])) {
    $_SESSION['nl'] = intval($_GET['nl']);
    $smarty->assign('whichtable', $table);
    $template = 'statistics_tables_csv.tpl';
    # let the browser know what's coming
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"" . basename($_SERVER['SCRIPT_NAME'], '.php') . ".{$table}.csv\"");
    $cacheid = 'statistics|coverage_by_country.' . $table;
} else {
    $template = 'statistics_tables.tpl';
    $cacheid = 'statistics|coverage_by_country';
}
$smarty->caching = 2;
// lifetime is per cache
$smarty->cache_lifetime = 3600 * 24;
//24hr cache
if (!$smarty->is_cached($template, $cacheid)) {
    dieUnderHighLoad();
    $db = NewADOConnection($GLOBALS['DSN']);
    if (!$db) {
        die('Database connection failed');
    }
    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
    $tables = array();
    ###################
    $table = array();
    $table['title'] = "Great Britain";
    $table['table'] = $db->GetAll("\r\n\t\tselect \r\n\t\t\tloc_country.name as Country,\r\n\t\t\tcount(*) as `Grid Squares`,\r\n\t\t\tsum(has_geographs) as `Geographed`,\r\n\t\t\tsum(has_geographs)/count(*)*100 as Percentage,\r\n\t\t\tsum(imagecount) as 'Total Photos'\r\n\t\tfrom gridsquare gs\r\n\t\t\tinner join os_gaz on (placename_id-1000000 = os_gaz.seq)\r\n\t\t\tinner join os_gaz_county on (os_gaz.co_code = os_gaz_county.co_code)\r\n\t\t\tinner join loc_country on (country = loc_country.code)\r\n\t\twhere gs.reference_index = 1 and percent_land > 0\r\n\t\tgroup by country with rollup\r\n\t\t");
    foreach ($table['table'] as $id => $row) {
    }
    $table['total'] = count($table['table']);
    $table['table'][$table['total'] - 1]['Country'] = '-Total-';
    $tables[] = $table;
Example #3
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
if (!isset($_GET['BBOX'])) {
    die("This page provides a feed for Google Earth");
}
if (empty($_GET['i']) || !intval($_GET['i'])) {
    $_GET['i'] = 1522;
}
dieUnderHighLoad(2, 'earth_unavailable.tpl');
list($west, $south, $east, $north) = explode(',', trim(str_replace('e ', 'e+', $_GET['BBOX'])));
$span = min($north - $south, $east - $west);
if ($span > 7 || !$span) {
    $smarty = new GeographPage();
    header("Content-type: application/vnd.google-earth.kml+xml");
    $smarty->display("earth_outsidearea.tpl");
    exit;
}
$long = ($east - $west) / 2 + $west;
$lat = ($north - $south) / 2 + $south;
$ire = $lat > 51.2 && $lat < 55.73 && $long > -12.2 && $long < -4.8;
$uk = $lat > 49 && $lat < 62 && $long > -9.5 && $long < 2.3;
if (!$ire && !$uk) {
    $smarty = new GeographPage();
    header("Content-type: application/vnd.google-earth.kml+xml");
Example #4
0
$smarty = new GeographPage();
if (isset($_GET['output']) && $_GET['output'] == 'csv') {
    $template = 'statistics_table_csv.tpl';
    # let the browser know what's coming
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"" . basename($_SERVER['SCRIPT_NAME'], '.php') . ".csv\"");
} else {
    $template = 'statistics_table.tpl';
}
$cacheid = 'statistics|pulse';
$smarty->caching = 2;
// lifetime is per cache
$smarty->cache_lifetime = 600;
//10min cache
if (!$smarty->is_cached($template, $cacheid)) {
    dieUnderHighLoad(5);
    $db = NewADOConnection($GLOBALS['DSN']);
    if (!$db) {
        die('Database connection failed');
    }
    $title = "Geograph Pulse";
    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
    $table = array();
    $sql = "SELECT COUNT(*) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 10 MINUTE)";
    calc("Images Submitted in last 10 minutes", $sql);
    $sql = "SELECT COUNT(*) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 1 HOUR)";
    calc("Images Submitted in last hour", $sql);
    $sql = "SELECT MAX(gridimage_id) FROM gridimage_search";
    calc("Last Moderated Image", $sql);
    $table[] = array("Parameter" => '', "Value" => '');
    $sql = "SELECT COUNT(*) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 24 HOUR)";
Example #5
0
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
require_once 'geograph/gridimage.class.php';
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/imagelist.class.php';
require_once 'geograph/map.class.php';
require_once 'geograph/mapmosaic.class.php';
require_once 'geograph/rastermap.class.php';
init_session();
$smarty = new GeographPage();
dieUnderHighLoad(0.5);
#customGZipHandlerStart();
$square = new GridSquare();
$template = 'near.tpl';
$USER->mustHavePerm("basic");
//we can be passed a gridreference as gridsquare/northings/eastings
//or just gridref. So lets initialise our grid square
$grid_given = false;
$grid_ok = false;
//set by grid components?
if (isset($_GET['p'])) {
    $grid_given = true;
    //p=900y + (900-x);
    $p = intval($_GET['p']);
    $x = $p % 900;
    $y = ($p - $x) / 900;
    /**
     * run a standard search via the gridimage_search table (but will redirect to sphinx if possible)
     * @access private
     */
    function ExecuteCachedReturnRecordset($pg)
    {
        global $CONF;
        $db = $this->_getDB();
        $this->criteria->getSQLParts();
        extract($this->criteria->sql, EXTR_PREFIX_ALL ^ EXTR_REFS, 'sql');
        $this->currentPage = $pg;
        $pgsize = $this->criteria->resultsperpage;
        if (!$pgsize) {
            $pgsize = 15;
        }
        if ($pg == '' or $pg < 1) {
            $pg = 1;
        }
        $page = ($pg - 1) * $pgsize;
        if (strpos($sql_where, 'gs') !== FALSE) {
            $sql_where = str_replace('gs.', 'gi.', $sql_where);
        }
        $sql_fields = str_replace('gs.', 'gi.', $sql_fields);
        ###################
        # run_via_sphinx
        if (empty($_GET['legacy']) && empty($_SESSION['legacy']) && !empty($CONF['sphinx_host']) && isset($this->criteria->sphinx) && (strlen($this->criteria->sphinx['query']) || !empty($this->criteria->sphinx['d']) || !empty($this->criteria->sphinx['filters'])) && $this->criteria->sphinx['impossible'] == 0) {
            return $this->ExecuteSphinxRecordSet($pg);
        } elseif ($this->criteria->sphinx['no_legacy']) {
            //oh dear, no point even trying :(
            $this->resultCount = 0;
            return 0;
        }
        # /run_via_sphinx
        ###################
        if ($this->criteria->searchclass == 'Placename' && strpos($this->criteria->searchdesc, $this->criteria->searchq) == FALSE && isset($GLOBALS['smarty'])) {
            $GLOBALS['smarty']->assign("suggestions", array(array('gr' => '(anywhere)', 'localities' => 'as text search', 'query' => $this->criteria->searchq)));
        }
        if (!empty($sql_where)) {
            $sql_where = "WHERE {$sql_where}";
            $this->islimited = true;
        } elseif (preg_match('/^ rand\\(/', $sql_order)) {
            //homefully temporally
            dieUnderHighLoad(0, 'search_unavailable.tpl');
        }
        if (preg_match("/(left |inner |)join ([\\w\\,\\(\\) \\.\\'!=`]+) where/i", $sql_where, $matches)) {
            $sql_where = preg_replace("/(left |inner |)join ([\\w\\,\\(\\) \\.!=\\'`]+) where/i", '', $sql_where);
            $sql_from .= " {$matches[1]} join {$matches[2]}";
        }
        if ($pg > 1 || $CONF['search_count_first_page'] || $this->countOnly) {
            $resultCount = $db->getOne("select `count` from queries_count where id = {$this->query_id}");
            if ($resultCount) {
                $this->resultCount = $resultCount;
            } else {
                // construct the count sql
                if (preg_match("/group by ([\\w\\,\\(\\)\\/ ]+)/i", $sql_where, $matches)) {
                    $sql_where2 = preg_replace("/group by ([\\w\\,\\(\\)\\/ ]+)/i", '', $sql_where);
                    if ($matches[1] == 'gridimage_id') {
                        $matches[1] = 'gi.gridimage_id';
                    }
                    $sql = "/* i{$this->query_id} */ SELECT count(DISTINCT {$matches[1]}) FROM gridimage_search as gi {$sql_from} {$sql_where2}";
                } else {
                    $sql = "/* i{$this->query_id} */ SELECT count(*) FROM gridimage_search as gi {$sql_from} {$sql_where}";
                }
                if (!empty($_GET['debug'])) {
                    print "<BR><BR>{$sql}";
                }
                $this->checkExplain($sql);
                $doneexplain = 1;
                $this->resultCount = $db->CacheGetOne(3600, $sql);
                if (empty($_GET['BBOX']) && $this->display != 'reveal') {
                    $db->Execute("replace into queries_count set id = {$this->query_id},`count` = {$this->resultCount}");
                }
            }
            $this->numberOfPages = ceil($this->resultCount / $pgsize);
        }
        if ($this->countOnly || ($pg > 1 || $CONF['search_count_first_page']) && !$this->resultCount || $this->numberOfPages && $pg > $this->numberOfPages) {
            return 0;
        }
        if ($sql_order) {
            $sql_order = "ORDER BY {$sql_order}";
        }
        // construct the query sql
        $sql = <<<END
/* i{$this->query_id} */ SELECT gi.* {$sql_fields}
FROM gridimage_search as gi {$sql_from}
{$sql_where}
{$sql_order}
LIMIT {$page},{$pgsize}
END;
        if (!empty($_GET['debug'])) {
            print "<BR><BR>{$sql}";
        }
        if (!isset($doneexplain)) {
            $this->checkExplain($sql);
        }
        list($usec, $sec) = explode(' ', microtime());
        $querytime_before = (double) $usec + (double) $sec;
        $recordSet =& $db->Execute($sql);
        list($usec, $sec) = explode(' ', microtime());
        $querytime_after = (double) $usec + (double) $sec;
        $this->querytime = $querytime_after - $querytime_before;
        if ($pg == 1 && !$CONF['search_count_first_page']) {
            $count = $db->getOne("select `count` from queries_count where id = {$this->query_id}");
            if ($count) {
                $this->resultCount = $count;
                $this->numberOfPages = ceil($this->resultCount / $pgsize);
            } elseif (!empty($recordSet)) {
                $this->resultCount = $recordSet->RecordCount();
                if ($this->resultCount == $pgsize) {
                    $this->numberOfPages = 2;
                    $this->pageOneOnly = 1;
                } else {
                    $this->numberOfPages = ceil($this->resultCount / $pgsize);
                    if (empty($_GET['BBOX']) && $this->display != 'reveal') {
                        $db->Execute("replace into queries_count set id = {$this->query_id},`count` = {$this->resultCount}");
                    }
                }
            } else {
                $this->resultCount = 0;
                $this->numberOfPages = 0;
                $this->pageOneOnly = 1;
            }
        }
        return $recordSet;
    }
Example #7
0
     }
     if ($engine->criteria->user_id == $USER->user_id) {
         if (!$db) {
             $db = NewADOConnection($GLOBALS['DSN']);
             if (!$db) {
                 die('Database connection failed');
             }
         }
         $db->query("UPDATE queries SET use_timestamp = null WHERE id = {$i}");
         if (!$db->Affected_Rows()) {
             $db->query("UPDATE queries_archive SET use_timestamp = null WHERE id = {$i}");
         }
     }
     $smarty->display($template, $cacheid);
 } else {
     dieUnderHighLoad(2, 'search_unavailable.tpl');
     // -------------------------------
     //  Simple Form
     // -------------------------------
     if (is_int($i)) {
         require_once 'geograph/searchcriteria.class.php';
         $engine = new SearchEngine($i);
         if (empty($engine->criteria)) {
             die("Invalid Search Parameter");
         }
         $query = $engine->criteria;
         if ($query->searchclass != 'Special') {
             $smarty->assign('searchq', $query->searchq);
             list($q, $loc) = preg_split('/\\bnear(\\b|$)/', $query->searchq, 2);
             $smarty->assign('searchlocation', $loc);
             $smarty->assign('searchtext', $q);