Esempio n. 1
1
if ($grid_ok) {
    //geotag the page
    require_once 'geograph/conversions.class.php';
    $conv = new Conversions();
    list($lat, $long) = $conv->gridsquare_to_wgs84($square);
    $smarty->assign('lat', $lat);
    $smarty->assign('long', $long);
    $smarty->assign_by_ref('square', $square);
    //lets add an rastermap too
    $rastermap = new RasterMap($square, false, $square->natspecified, true);
    $rastermap->addLatLong($lat, $long);
    $smarty->assign_by_ref('gridref', $gridref);
    if (!empty($photographer_gridref)) {
        $psquare = new GridSquare();
        $pgrid_given = true;
        $pgrid_ok = $psquare->setByFullGridRef($photographer_gridref, true, false, true);
        if (!empty($psquare->nateastings)) {
            $rastermap->addViewpoint($psquare->reference_index, $psquare->nateastings, $psquare->natnorthings, $psquare->natgrlen);
            $smarty->assign_by_ref('photographer_gridref', $photographer_gridref);
        }
    }
    if (isset($view_direction) && strlen($view_direction) && $view_direction != -1) {
        $rastermap->addViewDirection(intval($view_direction));
        $smarty->assign_by_ref('view_direction', $view_direction);
    }
    $smarty->assign_by_ref('rastermap', $rastermap);
    $gaz = new Gazetteer();
    $places = $gaz->findListByNational($square->reference_index, $square->nateastings, $square->natnorthings, $square->reference_index == 1 ? 2000 : 5000);
    $smarty->assign_by_ref('places', $places);
}
$smarty->display($template, $cacheid);
 public function processQuery()
 {
     $q = $this->q;
     if (preg_match('/^([a-zA-Z]{1,3}) +(\\d{1,5})(\\.\\d*|) +(\\d{1,5})(\\.*\\d*|)/', $q, $matches) && $matches[1] != 'tp') {
         $square = new GridSquare();
         $grid_ok = $square->setByFullGridRef($matches[0], true);
         if ($grid_ok) {
             $gr = $square->grid_reference;
             $e = $square->nateastings;
             $n = $square->natnorthings;
             $q = preg_replace("/{$matches[0]}\\s*/", '', $q);
         } else {
             $r = "\t--invalid Grid Ref--";
         }
     } else {
         if (preg_match('/^([a-zA-Z]{1,3})(\\d{2,10})\\b/', $q, $matches) && $matches[1] != 'tp') {
             $square = new GridSquare();
             $grid_ok = $square->setByFullGridRef($matches[0], true);
             if ($grid_ok) {
                 $gr = $square->grid_reference;
                 $e = $square->nateastings;
                 $n = $square->natnorthings;
                 $q = preg_replace("/{$matches[0]}\\s*/", '', $q);
             } else {
                 $r = "\t--invalid Grid Ref--";
             }
         }
     }
     $qo = $q;
     if (strlen($qo) > 64) {
         $qo = '--complex query--';
     }
     if ($r) {
         //Handle Error
     } elseif (!empty($e)) {
         //Location search
         require_once 'geograph/conversions.class.php';
         $conv = new Conversions();
         $e = floor($e / 1000);
         $n = floor($n / 1000);
         $grs = array();
         for ($x = $e - 2; $x <= $e + 2; $x++) {
             for ($y = $n - 2; $y <= $n + 2; $y++) {
                 list($gr2, $len) = $conv->national_to_gridref($x * 1000, $y * 1000, 4, $square->reference_index, false);
                 $grs[] = $gr2;
             }
         }
         if (strpos($q, '~') === 0) {
             $q = preg_replace('/^\\~/', '', $q);
             $q = "(" . str_replace(" ", " | ", $q) . ") (" . join(" | ", $grs) . ")";
         } else {
             $q .= " (" . join(" | ", $grs) . ")";
         }
         $qo .= " near {$gr}";
     }
     $this->q = $q;
     $this->qoutput = $qo;
 }
Esempio n. 3
0
     case 'few':
         $typename = 'with few';
         $crit = 'imagecount<2 and (percent_land > 0 || imagecount>1)';
         break;
     default:
         $type = $typename = 'without';
         $crit = 'imagecount=0 and percent_land > 0';
         break;
 }
 $square = new GridSquare();
 if (!empty($_REQUEST['ll']) && preg_match("/\\b(-?\\d+\\.?\\d*)[, ]+(-?\\d+\\.?\\d*)\\b/", $_REQUEST['ll'], $ll)) {
     $conv = new Conversions();
     list($x, $y, $reference_index) = $conv->wgs84_to_internal($ll[1], $ll[2]);
     $grid_ok = $square->loadFromPosition($x, $y, true);
 } else {
     $grid_ok = $square->setByFullGridRef($_REQUEST['gridref']);
 }
 if ($grid_ok) {
     $template = 'gpx_download_gpx.tpl';
     $cacheid = $square->grid_reference . '-' . $type . '-' . $d;
     //regenerate?
     if (!$smarty->is_cached($template, $cacheid)) {
         $searchdesc = "squares within {$d}km of {$square->grid_reference} {$typename} photographs";
         $x = $square->x;
         $y = $square->y;
         $sql_where = $crit . ' and ';
         $left = $x - $d;
         $right = $x + $d;
         $top = $y + $d;
         $bottom = $y - $d;
         $rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
 function combineTiles(&$gr, $path = false)
 {
     global $CONF, $USER;
     if (is_string($gr)) {
         $square = new GridSquare();
         if (!$square->setByFullGridRef($gr)) {
             return false;
         }
     } else {
         //already a gridsquare object
         $square &= $gr;
     }
     $ll = $square->gridsquare;
     $service = 'OS50k-source';
     $tilewidth = $this->tilewidth[$service];
     list($source, $dummy) = explode('-', $service);
     $outputwidth = $this->tilewidth['OS50k'];
     //this isn't STRICTLY needed as getOSGBStorePath does the same floor, but do so in case we do exact calculations
     $east = floor($this->nateastings / 1000) * 1000;
     $nort = floor($this->natnorthings / 1000) * 1000;
     if (strlen($CONF['imagemagick_path'])) {
         $tilelist = array();
         $c = 0;
         $found = 0;
         foreach (range($nort + 1000, $nort - 1000, -1000) as $n) {
             foreach (range($east - 1000, $east + 1000, 1000) as $e) {
                 $newpath = $this->getOSGBStorePath($service, $e, $n);
                 if (file_exists($newpath)) {
                     $tilelist[] = $newpath;
                     $found = 1;
                 } else {
                     $tilelist[] = $CONF['rastermap'][$source]['path'] . $this->epoch . '/' . "blank{$tilewidth}.png";
                     if (!empty($_GET['debug']) && $USER->hasPerm('admin')) {
                         print "{$newpath} not found<br/>\n";
                     }
                 }
                 $c++;
             }
         }
         if (!$found) {
             if (!empty($_GET['debug']) && $USER->hasPerm('admin')) {
                 print "No content tiles found<br/>\n";
             }
             return false;
         }
         if (!$path) {
             $path = $this->getOSGBStorePath('OS50k', $east, $nort, true);
         }
         $cmd = sprintf('%s"%smontage" -geometry +0+0 %s -tile 3x3 png:- | "%sconvert" - -crop %ldx%ld+%ld+%ld +repage -thumbnail %ldx%ld -colors 128 -font "%s" -fill "#eeeeff" -draw "roundRectangle 6,230 155,243 3,3" -fill "#000066" -pointsize 10 -draw "text 10,240 \'© Crown Copyright %s\'" -colors 128 -depth 8 -type Palette png:%s', isset($_GET['nice']) ? 'nice ' : '', $CONF['imagemagick_path'], implode(' ', $tilelist), $CONF['imagemagick_path'], $tilewidth * 2, $tilewidth * 2, $tilewidth / 2, $tilewidth / 2, $outputwidth, $outputwidth, $CONF['imagemagick_font'], $CONF['OS_licence'], $path);
         if (isset($_ENV["OS"]) && strpos($_ENV["OS"], 'Windows') !== FALSE) {
             $cmd = str_replace('/', '\\', $cmd);
         }
         exec($cmd);
         if (!empty($_GET['debug']) && $USER->hasPerm('admin')) {
             print "<pre>{$cmd}</pre>";
         }
         if (file_exists($path)) {
             return true;
         } else {
             return false;
         }
     } else {
         //generate resized image
         die("gd not implemented!");
     }
 }
 /**
  * Updates a given field of the image, holding it for moderation if necessary
  * A series of calls to this function should be followed up with a call
  * to commit(), which persist the ticket and any unmoderated changes
  * @access public
  */
 function updateField($fieldname, $oldvalue, $newvalue, $moderated)
 {
     $ok = true;
     //no change?
     if ($oldvalue == $newvalue) {
         return $ok;
     }
     if (!$moderated) {
         //make the changes right away...
         $img =& $this->_getImage();
         if ($fieldname == "grid_reference") {
             $err = "";
             $ok = $img->reassignGridsquare($newvalue, $err);
             if ($ok) {
                 $this->commit_count++;
             } else {
                 die("Sorry, wasn't expecting reassignGridsquare to fail ({$err}) please contact us for assistance");
             }
         } elseif ($fieldname == "photographer_gridref") {
             //need to parse value for nat coords
             $sq = new GridSquare();
             if ($sq->setByFullGridRef($newvalue, true, true, true)) {
                 $img->viewpoint_eastings = $sq->nateastings;
                 $img->viewpoint_northings = $sq->natnorthings;
                 $img->viewpoint_grlen = $sq->natgrlen;
                 $img->viewpoint_refindex = $sq->reference_index;
                 $this->commit_count++;
             } elseif (empty($newvalue)) {
                 // we are setting to 'blank'
                 $img->viewpoint_eastings = 0;
                 $img->viewpoint_northings = 0;
                 $img->viewpoint_grlen = 0;
                 $img->viewpoint_refindex = 0;
                 $this->commit_count++;
             }
         } else {
             $img->{$fieldname} = $newvalue;
             //we'll do this commit later
             $this->commit_count++;
         }
         $status = "immediate";
         $approver_id = $this->user_id;
         $img->title = combineTexts($img->title1, $img->title2);
         $img->comment = combineTexts($img->comment1, $img->comment2);
     } else {
         $status = "pending";
         $approver_id = 0;
     }
     //have we already got a change record?
     $found = false;
     foreach ($this->changes as $c) {
         if ($c['field'] == $fieldname) {
             $found = true;
         }
     }
     if (!$found) {
         //create a change record
         $change = array("field" => $fieldname, "oldvalue" => $oldvalue, "newvalue" => $newvalue, "status" => $status, "approver_id" => $approver_id);
         $this->changes[] = $change;
     }
 }
Esempio n. 6
0
function UploadPicture()
{
    global $CONF;
    global $xml;
    global $USER;
    if (empty($_POST['userid']) || !intval($_POST['userid'])) {
        $xml['status'] = 'Not Logged In';
        returnXML();
    } else {
        $USER = new GeographUser(intval($_POST['userid']));
        //TODO: check validation hash?
        if ($_POST['validation'] != md5($_POST['userid'] . '#' . $CONF['register_confirmation_secret'])) {
            $xml['status'] = 'User not verified';
            returnXML();
        }
        if (!$USER->user_id || !$USER->hasPerm('basic')) {
            $xml['status'] = 'Not authorised to post';
            returnXML();
        }
    }
    $um = new UploadManager();
    $gs = new GridSquare();
    // this is the check that we like the client and any image has
    // come in with the appropriate cc licence
    $ccl = $_POST['cclicence'];
    if ($ccl != "I grant you the permission to use this submission " . "under the terms of the Creative Commons by-sa-2.0 licence") {
        $xml['status'] = 'Bad client submission';
        returnXML();
    }
    // validate the grid square - we may be going back to the user
    // quickly here :-)
    $gs->setByFullGridRef($_POST['subject']);
    if ($gs->errormsg != "") {
        $xml['status'] = $gs->errormsg;
        returnXML();
    }
    $takendate = strtotime_uk($_POST['date']);
    if ($takendate > time()) {
        $xml['status'] = "Date taken in future";
        returnXML();
    }
    // set up attributes from uploaded data
    $um->setSquare($gs);
    $um->setViewpoint($_POST['photographer']);
    $um->setDirection($_POST['direction']);
    $um->setTaken(date('Y-m-d', $takendate));
    $um->setTitle($_POST['title']);
    $um->setComment($_POST['comments']);
    $um->setClass($_POST['feature']);
    $um->setUserStatus($_POST['supplemental']);
    $um->processUpload($_FILES['uploadfile']['tmp_name']);
    // where there any errors back from the image processing?
    // if so, JUppy needs to know...
    if ($um->error != "") {
        $xml['status'] = $um->error;
    } else {
        // so far so good... can we commit the submission?
        $rc = $um->commit();
        if ($rc == "") {
            //clear user profile
            $ab = floor($USER->user_id / 10000);
            $smarty = new GeographPage();
            $smarty->clear_cache(null, "user{$ab}|{$USER->user_id}");
            $xml['status'] = "OK";
        } else {
            $xml['status'] = $rc;
        }
    }
    returnXML();
}
Esempio n. 7
0
        $smarty->assign('id', $page['geoevent_id']);
    } else {
        $template = 'static_404.tpl';
    }
}
if ($template != 'static_404.tpl' && isset($_POST) && isset($_POST['submit'])) {
    $errors = array();
    $_POST['event_date'] = sprintf("%04d-%02d-%02d", $_POST['event_dateYear'], $_POST['event_dateMonth'], $_POST['event_dateDay']);
    $_POST['event_time'] = $_POST['event_date'];
    $_POST['title'] = preg_replace('/[^\\w-\\., ]+/', '', trim($_POST['title']));
    if ($_POST['title'] == "New Event") {
        $errors['title'] = "Please give a meaningful title";
    }
    $gs = new GridSquare();
    if (!empty($_POST['grid_reference'])) {
        if ($gs->setByFullGridRef($_POST['grid_reference'])) {
            $_POST['gridsquare_id'] = $gs->gridsquare_id;
        } else {
            $errors['grid_reference'] = $gs->errormsg;
        }
    }
    $updates = array();
    foreach (array('url', 'title', 'description', 'event_time', 'gridsquare_id', 'gridimage_id') as $key) {
        if ($page[$key] != $_POST[$key]) {
            $updates[] = "`{$key}` = " . $db->Quote($_POST[$key]);
            $smarty->assign($key, $_POST[$key]);
        } elseif (empty($_POST[$key]) && $key != 'url' && $key != 'gridimage_id') {
            $errors[$key] = "missing required info";
        }
    }
    if (!count($updates)) {
Esempio n. 8
0
$smarty->assign('google_maps_api_key', $CONF['google_maps_api_key']);
if (isset($_REQUEST['inner'])) {
    $cacheid = 'iframe';
    $smarty->assign('inner', 1);
} else {
    $cacheid = '';
}
if (isset($_REQUEST['picasa'])) {
    $cacheid .= 'picasa';
    $smarty->assign('picasa', 1);
} elseif (isset($_REQUEST['submit2'])) {
    $cacheid .= 'submit2';
    $smarty->assign('submit2', 1);
}
if (!empty($_REQUEST['grid_reference'])) {
    $square = new GridSquare();
    $ok = $square->setByFullGridRef($_REQUEST['grid_reference']);
    if ($ok) {
        $smarty->assign('grid_reference', $grid_reference = $_REQUEST['grid_reference']);
        $smarty->assign('success', 1);
    } else {
        $smarty->assign('errormsg', $square->errormsg);
    }
}
$smarty->assign('lat0', $CONF['gmcentre'][0]);
$smarty->assign('lon0', $CONF['gmcentre'][1]);
$smarty->assign('latmin', $CONF['gmlatrange'][0][0]);
$smarty->assign('latmax', $CONF['gmlatrange'][0][1]);
$smarty->assign('lonmin', $CONF['gmlonrange'][0][0]);
$smarty->assign('lonmax', $CONF['gmlonrange'][0][1]);
$smarty->display('submitmap.tpl', $cacheid);
Esempio n. 9
0
     } else {
         $smarty->assign('errormsg', $square->errormsg);
     }
 }
 if (!empty($_REQUEST['step'])) {
     $step = intval($_REQUEST['step']);
 }
 if (empty($_REQUEST['grid_reference']) && $step == 2) {
     $step = 1;
 }
 if ($step == 2) {
     require_once 'geograph/rastermap.class.php';
     $rastermap = new RasterMap($square, true);
     if (isset($_POST['photographer_gridref'])) {
         $square2 = new GridSquare();
         $ok = $square2->setByFullGridRef($_POST['photographer_gridref'], false, false, true);
         $rastermap->addViewpoint($square2->reference_index, $square2->nateastings, $square2->natnorthings, $square2->natgrlen, $_POST['view_direction']);
     } elseif (isset($_POST['view_direction']) && strlen($_POST['view_direction']) && $_POST['view_direction'] != -1) {
         $rastermap->addViewDirection($_POST['view_direction']);
     }
     $smarty->assign_by_ref('rastermap', $rastermap);
     $smarty->assign_by_ref('square', $square);
     $smarty->assign('reference_index', $square->reference_index);
     require_once 'geograph/conversions.class.php';
     $conv = new Conversions();
     list($lat, $long) = $conv->gridsquare_to_wgs84($square);
     $smarty->assign('lat', $lat);
     $smarty->assign('long', $long);
     $rastermap->addLatLong($lat, $long);
     $dirs = array(-1 => '');
     $jump = 360 / 16;
 /**
  * create a more complex search object
  */
 function buildAdvancedQuery(&$dataarray, $autoredirect = 'auto')
 {
     global $CONF, $imagestatuses, $breakdowns, $sortorders, $USER;
     $dataarray = array_map("strip_tags", $dataarray);
     if (empty($dataarray['distance'])) {
         $dataarray['distance'] = $CONF['default_search_distance'];
     }
     $nearstring = $this->getNearString($dataarray['distance']);
     $searchdesc = '';
     if (!empty($dataarray['placename']) && $dataarray['placename'] != '(anywhere)') {
         //check if we actully want to perform a textsearch (it comes through in the placename beucase of the way the multiple mathc page works)
         if (strpos($dataarray['placename'], 'text:') === 0) {
             $dataarray['searchtext'] = preg_replace("/^text\\:/", '', $dataarray['placename']);
             unset($dataarray['placename']);
             unset($dataarray['location']);
         }
         //check if we actully want to perform a user_search
         if (strpos($dataarray['placename'], 'user:'******'user_id'] = preg_replace("/^user\\:/", '', $dataarray['placename']);
             unset($dataarray['placename']);
             if ($dataarray['old-placename'] == $dataarray['q']) {
                 unset($dataarray['q']);
             }
         }
     }
     if (!empty($dataarray['location']) && $dataarray['location'] != '(anywhere)' && empty($dataarray['placename']) && empty($dataarray['gridref']) && empty($dataarray['postcode'])) {
         $dataarray['placename'] = $dataarray['location'];
     }
     if (!empty($dataarray['q'])) {
         //we coming from multiple - which means there might be a text search stored in a q
         list($q, $placename) = preg_split('/\\s+near\\s+/', $dataarray['q']);
         if (!empty($dataarray['location'])) {
             $dataarray['searchtext'] = $q;
             if (empty($dataarray['placename'])) {
                 $dataarray['placename'] = $dataarray['location'];
             }
         } elseif ($placename && (empty($dataarray['searchtext']) || $dataarray['searchtext'] == $q)) {
             $dataarray['searchtext'] = $q;
             if (empty($dataarray['placename'])) {
                 $dataarray['placename'] = $placename;
             }
         }
     }
     if (!empty($dataarray['placename'])) {
         if (preg_match("/\\b([A-Z]{1,2})([0-9]{1,2}[A-Z]?) *([0-9]?)([A-Z]{0,2})\\b/i", $dataarray['placename'], $pc) && !in_array($pc[1], array('SV', 'SX', 'SZ', 'TV', 'SU', 'TL', 'TM', 'SH', 'SJ', 'TG', 'SC', 'SD', 'NX', 'NY', 'NZ', 'OV', 'NS', 'NT', 'NU', 'NL', 'NM', 'NO', 'NF', 'NH', 'NJ', 'NK', 'NA', 'NB', 'NC', 'ND', 'HW', 'HY', 'HZ', 'HT', 'Q', 'D', 'C', 'J', 'H', 'F', 'O', 'T', 'R', 'X', 'V'))) {
             $dataarray['postcode'] = $dataarray['placename'];
             unset($dataarray['placename']);
         } elseif (preg_match("/\\b([a-zA-Z]{1,3}) ?(\\d{1,5})[ \\.]?(\\d{1,5})\\b/", $dataarray['placename'], $gr)) {
             $dataarray['gridref'] = $dataarray['placename'];
             unset($dataarray['placename']);
         } elseif ($dataarray['placename'] == '(anywhere)') {
             unset($dataarray['placename']);
         }
     }
     if (!empty($dataarray['postcode'])) {
         if (preg_match("/^\\s*([A-Z]{1,2})([0-9]{1,2}[A-Z]?)\\s*([0-9]?)([A-Z]{0,2})\\s*\$/", strtoupper($dataarray['postcode']), $pc)) {
             require_once 'geograph/searchcriteria.class.php';
             $searchq = $pc[1] . $pc[2] . ($pc[3] ? " " . $pc[3] : '');
             $criteria = new SearchCriteria_Postcode();
             $criteria->setByPostcode($searchq);
             if ($criteria->y != 0) {
                 $searchclass = 'Postcode';
                 $searchdesc = ", {$nearstring} postcode " . $searchq;
                 $searchx = $criteria->x;
                 $searchy = $criteria->y;
             } else {
                 $this->errormsg = "Invalid Postcode or a newer Postcode not in our database, please try a different search method";
                 if ($pc[3]) {
                     $this->errormsg .= ", or use just the outcode [ {$pc[1]}{$pc[2]} ]";
                 }
             }
         } else {
             $this->errormsg = "Does not appear to be a valid Postcode";
         }
     } else {
         if (!empty($dataarray['gridref'])) {
             if (preg_match("/\\b([a-zA-Z]{1,3}) ?(\\d{1,5})[ \\.]?(\\d{1,5})\\b/", $dataarray['gridref'], $gr)) {
                 require_once 'geograph/gridsquare.class.php';
                 $square = new GridSquare();
                 $grid_ok = $square->setByFullGridRef($dataarray['gridref'], false, true);
                 if ($grid_ok || $square->x && $square->y) {
                     $searchclass = 'GridRef';
                     $searchq = $dataarray['gridref'];
                     $searchdesc = ", {$nearstring} grid reference " . $square->grid_reference;
                     $searchx = $square->x;
                     $searchy = $square->y;
                 } else {
                     $this->errormsg = $square->errormsg;
                 }
             } else {
                 $this->errormsg = "Does not appear to be a valid Grid Reference";
             }
         } else {
             if (!empty($dataarray['county_id'])) {
                 require_once 'geograph/searchcriteria.class.php';
                 $criteria = new SearchCriteria_County();
                 $criteria->setByCounty($dataarray['county_id']);
                 if (!empty($criteria->county_name)) {
                     $searchclass = 'County';
                     $searchq = $dataarray['county_id'];
                     $searchdesc = ", {$nearstring} center of " . $criteria->county_name;
                     $searchx = $criteria->x;
                     $searchy = $criteria->y;
                 } else {
                     $this->errormsg = "Invalid County????";
                 }
             } else {
                 if (!empty($dataarray['placename'])) {
                     $dataarray['placename'] = trim($dataarray['placename']);
                     require_once 'geograph/searchcriteria.class.php';
                     $criteria = new SearchCriteria_Placename();
                     $criteria->setByPlacename($dataarray['placename']);
                     if (!empty($criteria->placename)) {
                         $searchclass = 'Placename';
                         $searchq = $criteria->placename;
                         $searchdesc = ", {$nearstring} " . $criteria->placename;
                         $searchx = $criteria->x;
                         $searchy = $criteria->y;
                     } else {
                         if ($criteria->is_multiple) {
                             $searchdesc = ", {$nearstring} '" . $dataarray['placename'] . "'";
                         } else {
                             $this->errormsg = "Place not found, you might like to try a placename search";
                         }
                     }
                 } else {
                     if (!empty($dataarray['description']) && !empty($dataarray['searchq'])) {
                         if (!$dataarray['adminoverride']) {
                             $USER->mustHavePerm("admin");
                         }
                         $dataarray['description'] = trim($dataarray['description']);
                         $dataarray['searchq'] = trim($dataarray['searchq']);
                         $searchclass = 'Special';
                         if (!empty($dataarray['searchclass'])) {
                             $searchclass = $dataarray['searchclass'];
                         }
                         $searchq = $dataarray['searchq'];
                         if (preg_match("/;|update |delete |drop |replace |alter |password|email/i", $searchq)) {
                             die("Server Error");
                         }
                         $searchdesc = ", " . $dataarray['description'];
                         if (!empty($dataarray['x']) && !empty($dataarray['y'])) {
                             $searchx = $dataarray['x'];
                             $searchy = $dataarray['y'];
                         }
                     } else {
                         if (!empty($dataarray['all_ind'])) {
                             $searchclass = 'All';
                             $searchq = '';
                         } else {
                             $searchclass = 'All';
                             $searchq = '';
                         }
                     }
                 }
             }
         }
     }
     if (!empty($dataarray['searchtext'])) {
         $dataarray['searchtext'] = trim($dataarray['searchtext']);
         if (!empty($dataarray['ind_exact']) || preg_match('/^=/', $dataarray['searchtext'])) {
             if (preg_match('/^=?~/', $dataarray['searchtext'])) {
                 $searchdesc = ", exactly matching any of [" . preg_replace('/^=?~/', '', $dataarray['searchtext']) . "] " . $searchdesc;
             } else {
                 $searchdesc = ", exactly matching [" . preg_replace('/^=/', '', $dataarray['searchtext']) . "] " . $searchdesc;
             }
         } elseif (preg_match('/^~/', $dataarray['searchtext'])) {
             $searchdesc = ", matching any of [" . preg_replace('/^~/', '', $dataarray['searchtext']) . "] " . $searchdesc;
         } elseif (preg_match('/[~\\+\\^\\$:@ -]+/', $dataarray['searchtext'])) {
             $searchdesc = ", matching [" . $dataarray['searchtext'] . "] " . $searchdesc;
         } elseif (preg_match('/^".*"$/', $dataarray['searchtext'])) {
             $searchdesc = ", matching [\"" . $dataarray['searchtext'] . "\"] " . $searchdesc;
         } elseif (preg_match('/\\+$/', $dataarray['searchtext'])) {
             $searchdesc = ", all about [" . preg_replace('/\\+$/', '', $dataarray['searchtext']) . "] " . $searchdesc;
         } elseif (preg_match('/^\\^/', $dataarray['searchtext'])) {
             $searchdesc = ", matching whole word [" . str_replace('^', '', $dataarray['searchtext']) . "] " . $searchdesc;
         } else {
             $searchdesc = ", containing [" . $dataarray['searchtext'] . "] " . $searchdesc;
         }
     }
     if (!empty($dataarray['ind_exact'])) {
         $dataarray['searchtext'] = "=" . $dataarray['searchtext'];
     }
     if (isset($searchclass)) {
         $db = NewADOConnection($GLOBALS['DSN']);
         if (empty($db)) {
             die('Database connection failed');
         }
         $sql = "INSERT INTO queries SET searchclass = '{$searchclass}'," . "searchuse = " . $db->Quote($this->searchuse) . "," . "searchq = " . $db->Quote($searchq);
         if (isset($dataarray['searchtext'])) {
             $sql .= ",searchtext = " . $db->Quote($dataarray['searchtext']);
         }
         if (isset($dataarray['displayclass'])) {
             $sql .= ",displayclass = " . $db->Quote($dataarray['displayclass']);
         }
         if (isset($dataarray['resultsperpage'])) {
             $sql .= ",resultsperpage = " . $db->Quote(min(100, $dataarray['resultsperpage']));
         } elseif (isset($USER) && !empty($USER->search_results)) {
             $sql .= ",resultsperpage = " . $db->Quote($USER->search_results);
         }
         if (isset($searchx) && !empty($searchx) && !empty($searchy)) {
             $sql .= ",x = {$searchx},y = {$searchy}";
         }
         if (isset($USER) && $USER->registered) {
             $sql .= ",user_id = {$USER->user_id}";
         }
         if (!empty($dataarray['user_name'])) {
             $usercriteria = new SearchCriteria_All();
             $usercriteria->setByUsername($dataarray['user_name']);
             if (!empty($usercriteria->realname)) {
                 $sql .= ",limit1 = " . $db->Quote((!empty($dataarray['user_invert_ind']) ? '!' : '') . $usercriteria->user_id);
                 $searchdesc .= "," . (!empty($dataarray['user_invert_ind']) ? ' not' : '') . " by " . $usercriteria->realname;
                 $dataarray['user_id'] = $usercriteria->user_id;
             }
         } elseif (!empty($dataarray['user_id'])) {
             $sql .= ",limit1 = " . $db->Quote((!empty($dataarray['user_invert_ind']) ? '!' : '') . $dataarray['user_id']);
             $profile = new GeographUser($dataarray['user_id']);
             $searchdesc .= "," . (!empty($dataarray['user_invert_ind']) ? ' not' : '') . " by " . $profile->realname;
         }
         if (!empty($dataarray['moderation_status'])) {
             $sql .= ",limit2 = " . $db->Quote($dataarray['moderation_status']);
             $searchdesc .= ", showing " . $imagestatuses[$dataarray['moderation_status']] . " images";
         }
         if (!empty($dataarray['imageclass'])) {
             if ($dataarray['imageclass'] == '-') {
                 $sql .= ",limit3 = '-'";
                 $searchdesc .= ", unclassifed";
             } else {
                 $sql .= ",limit3 = " . $db->Quote($dataarray['imageclass']);
                 $searchdesc .= ", classifed as " . $dataarray['imageclass'];
             }
         }
         if (!empty($dataarray['reference_index'])) {
             $sql .= ",limit4 = " . $db->Quote($dataarray['reference_index']);
             $searchdesc .= ", in " . $CONF['references'][$dataarray['reference_index']];
         }
         if (!empty($dataarray['gridsquare'])) {
             $sql .= ",limit5 = " . $db->Quote($dataarray['gridsquare']);
             $searchdesc .= ", in " . $dataarray['gridsquare'];
         }
         $this->builddate($dataarray, "submitted_start");
         $this->builddate($dataarray, "submitted_end");
         if (!empty($dataarray['submitted_start']) || !empty($dataarray['submitted_end'])) {
             if (!empty($dataarray['submitted_start'])) {
                 if (preg_match("/0{4}-([01]?[1-9]+|10)-/", $dataarray['submitted_start']) > 0) {
                     //month only
                     $searchdesc .= ", submitted during " . $dataarray['submitted_startString'];
                     $dataarray['submitted_end'] = "";
                 } elseif (preg_match("/0{4}-0{2}-([0-3]?[1-9]+|10|20|30)/", $dataarray['submitted_start']) > 0) {
                     //day only
                     $searchdesc .= ", submitted in the last " . $dataarray['submitted_startDay'] . " days";
                     $dataarray['submitted_end'] = "";
                 } elseif (!empty($dataarray['submitted_end'])) {
                     if ($dataarray['submitted_end'] == $dataarray['submitted_start']) {
                         //both the same
                         $searchdesc .= ", submitted " . (is_numeric($dataarray['submitted_startString']) ? 'in ' : '') . $dataarray['submitted_startString'];
                     } else {
                         //between
                         //if the start date is later than the end then lets swap them!
                         $startdate = vsprintf("%04d%02%02", explode('-', $dataarray['submitted_start']));
                         $enddate = vsprintf("%04d%02%02", explode('-', $dataarray['submitted_end']));
                         if ($startdate > $enddate) {
                             $temp = $dataarray['submitted_startString'];
                             $dataarray['submitted_startString'] = $dataarray['submitted_endString'];
                             $dataarray['submitted_endString'] = $temp;
                             $temp = $dataarray['submitted_start'];
                             $dataarray['submitted_start'] = $dataarray['submitted_end'];
                             $dataarray['submitted_end'] = $temp;
                         }
                         $searchdesc .= ", submitted between " . $dataarray['submitted_startString'] . " and " . $dataarray['submitted_endString'] . " ";
                     }
                 } else {
                     //from
                     $searchdesc .= ", submitted after " . $dataarray['submitted_startString'];
                 }
             } else {
                 //to
                 $searchdesc .= ", submitted before " . $dataarray['submitted_endString'];
             }
             $sql .= ",limit6 = '{$dataarray['submitted_start']}^{$dataarray['submitted_end']}'";
         }
         $this->builddate($dataarray, "taken_start");
         $this->builddate($dataarray, "taken_end");
         if (!empty($dataarray['taken_start']) || !empty($dataarray['taken_end'])) {
             if (!empty($dataarray['taken_start'])) {
                 if (preg_match("/0{4}-([01]?[1-9]+|10)-/", $dataarray['taken_start']) > 0) {
                     //month only
                     $searchdesc .= ", taken during " . $dataarray['taken_startString'];
                     $dataarray['taken_end'] = "";
                 } elseif (preg_match("/0{4}-0{2}-([0-3]?[1-9]+|10|20|30)/", $dataarray['taken_start']) > 0) {
                     //day only
                     $searchdesc .= ", taken in the last " . $dataarray['taken_startDay'] . " days";
                     $dataarray['submitted_end'] = "";
                 } elseif (!empty($dataarray['taken_end'])) {
                     if ($dataarray['taken_end'] == $dataarray['taken_start']) {
                         //both the same
                         $searchdesc .= ", taken " . (is_numeric($dataarray['taken_startString']) ? 'in ' : '') . $dataarray['taken_startString'];
                     } else {
                         //between
                         //if the start date is later than the end then lets swap them!
                         $startdate = vsprintf("%04d%02%02", explode('-', $dataarray['taken_start']));
                         $enddate = vsprintf("%04d%02%02", explode('-', $dataarray['taken_end']));
                         if ($startdate > $enddate) {
                             $temp = $dataarray['taken_startString'];
                             $dataarray['taken_startString'] = $dataarray['taken_endString'];
                             $dataarray['taken_endString'] = $temp;
                             $temp = $dataarray['taken_start'];
                             $dataarray['taken_start'] = $dataarray['taken_end'];
                             $dataarray['taken_end'] = $temp;
                         }
                         $searchdesc .= ", taken between " . $dataarray['taken_startString'] . " and " . $dataarray['taken_endString'] . " ";
                     }
                 } else {
                     //from
                     $searchdesc .= ", taken after " . $dataarray['taken_startString'];
                 }
             } else {
                 //to
                 $searchdesc .= ", taken before " . $dataarray['taken_endString'];
             }
             $sql .= ",limit7 = '{$dataarray['taken_start']}^{$dataarray['taken_end']}'";
         } else {
             $this->builddate($dataarray, "taken");
             if (!empty($dataarray['taken'])) {
                 $dataarray['taken_start'] = $dataarray['taken'];
                 $dataarray['taken_end'] = $dataarray['taken'];
                 $searchdesc .= ", taken " . (is_numeric($dataarray['takenString']) ? 'in ' : '') . $dataarray['takenString'];
                 $sql .= ",limit7 = '{$dataarray['taken_start']}^{$dataarray['taken_end']}'";
                 unset($dataarray['taken']);
             }
         }
         if (!empty($dataarray['distance']) && isset($searchx) && $searchx > 0 && $searchy > 0) {
             $sql .= sprintf(",limit8 = %d", $dataarray['distance']);
         }
         if (!empty($dataarray['topic_id'])) {
             $sql .= ",limit9 = " . $dataarray['topic_id'];
             if ($dataarray['topic_id'] > 1) {
                 $topic_name = $db->getOne("SELECT topic_title FROM geobb_topics WHERE topic_id = " . $dataarray['topic_id']);
                 $searchdesc .= ", in topic " . $topic_name;
             } else {
                 $searchdesc .= ", in any topic";
             }
         }
         if (!empty($dataarray['route_id'])) {
             $sql .= ",limit10 = " . $dataarray['route_id'];
             $topic_name = $db->getOne("SELECT name FROM route WHERE route_id = " . $dataarray['route_id']);
             $searchdesc .= ", on route " . $topic_name;
         }
         if (!isset($dataarray['orderby'])) {
             $dataarray['orderby'] = '';
         }
         switch ($dataarray['orderby']) {
             case "":
                 if ($searchclass == 'All') {
                     $searchdesc .= ", in undefined order";
                 }
                 break;
             case "random":
                 $sql .= ",orderby = " . $db->Quote($dataarray['orderby']);
                 $searchdesc .= ", in Random order";
                 break;
             case "dist_sqd":
                 break;
             default:
                 $orderby = $dataarray['orderby'];
                 if ($dataarray['reverse_order_ind']) {
                     $orderby = preg_replace('/(,|$)/', ' desc$1', $orderby);
                     if (strpos($sortorders[$dataarray['orderby']], '-') > 1) {
                         $searchdesc .= ", in " . implode('-&gt;', array_reverse(explode('-&gt;', $sortorders[$dataarray['orderby']]))) . " order";
                     } else {
                         $searchdesc .= ", in reverse " . $sortorders[$dataarray['orderby']] . " order";
                     }
                 } else {
                     $searchdesc .= ", in " . $sortorders[$dataarray['orderby']] . " order";
                 }
                 $sql .= ",orderby = " . $db->Quote($orderby);
         }
         if (!empty($dataarray['breakby'])) {
             $sql .= ",breakby = " . $db->Quote($dataarray['breakby']);
             if (!empty($breakdowns[$dataarray['breakby']])) {
                 $searchdesc .= ", by " . $breakdowns[$dataarray['breakby']];
             }
         }
         $sql .= ",searchdesc = " . $db->Quote($searchdesc);
         $db->Execute($sql);
         $i = $db->Insert_ID();
         if ($autoredirect != false) {
             $extra = '';
             if (isset($_GET['page'])) {
                 $extra = "&page=" . intval($_GET['page']);
             }
             if ($dataarray['submit'] == 'Count') {
                 $extra .= '&count=1';
             }
             if (!empty($_GET['BBOX'])) {
                 $extra .= "&BBOX=" . $_GET['BBOX'];
             }
             header("Location:http://{$_SERVER['HTTP_HOST']}/{$this->page}?i={$i}{$extra}");
             $extra = str_replace('&', '&amp;', $extra);
             print "<a href=\"http://{$_SERVER['HTTP_HOST']}/{$this->page}?i={$i}{$extra}\">Your Search Results</a>";
             exit;
         } else {
             return $i;
         }
     } else {
         if (isset($criteria) && isset($criteria->is_multiple)) {
             if (!empty($dataarray['user_id'])) {
                 $profile = new GeographUser($dataarray['user_id']);
                 $searchdesc .= "," . ($dataarray['user_invert_ind'] ? ' not' : '') . " by " . $profile->realname;
             }
             if (!empty($dataarray['moderation_status'])) {
                 $searchdesc .= ", showing " . $imagestatuses[$dataarray['moderation_status']] . " images";
             }
             if (!empty($dataarray['imageclass'])) {
                 $searchdesc .= ", classifed as " . $dataarray['imageclass'];
             }
             if (!empty($dataarray['reference_index'])) {
                 $searchdesc .= ", in " . $CONF['references'][$dataarray['reference_index']];
             }
             if (!empty($dataarray['gridsquare'])) {
                 $searchdesc .= ", in " . $dataarray['gridsquare'];
             }
             if (!empty($dataarray['breakby'])) {
                 $searchdesc .= ", group by " . $breakdowns[$dataarray['breakby']];
             }
             if (!empty($dataarray['orderby'])) {
                 switch ($dataarray['orderby']) {
                     case "":
                         break;
                     case "random":
                         $searchdesc .= ", in Random order";
                         break;
                     case "dist_sqd":
                         break;
                     default:
                         $searchdesc .= ", in " . ($dataarray['reverse_order_ind'] ? 'reverse ' : '') . $sortorders[$dataarray['orderby']] . " order";
                 }
             }
             $this->searchdesc = $searchdesc;
             $this->criteria = $criteria;
         }
     }
 }
Esempio n. 11
0
         }
         if ($isowner && $sq->gridsquare_id == $image->gridsquare_id) {
             $moderated["grid_reference"] = false;
         }
     } else {
         $ok = false;
         $error['grid_reference'] = $sq->errormsg;
     }
 } else {
     $ok = false;
     $error['grid_reference'] = "Please specify a grid reference";
 }
 $sq = new GridSquare();
 $photographer_gridref = trim(stripslashes($_POST['photographer_gridref']));
 if (strlen($photographer_gridref)) {
     if ($sq->setByFullGridRef($photographer_gridref, false, true)) {
         //grid reference in $sq->grid_reference is OK, but might
         //be different to what we entered...
         if (strlen($sq->grid_reference) > strlen($photographer_gridref)) {
             $photographer_gridref = $sq->grid_reference;
         }
     } else {
         $ok = false;
         $error['photographer_gridref'] = $sq->errormsg;
     }
 }
 $view_direction = intval(trim(stripslashes($_POST['view_direction'])));
 $use6fig = intval(trim(stripslashes($_POST['use6fig'])));
 /////////////////////////////////////////////////////////////
 // STEP 2 - change control
 if ($ok) {
Esempio n. 12
0
 if (!empty($_GET['label'])) {
     $data['description'] = "labeled [" . strip_tags($_GET['label']) . "]";
     $db = NewADOConnection($GLOBALS['DSN']);
     $where = "label = " . $db->Quote($_GET['label']);
 } else {
     $data['description'] = "in a cluster";
     $where = 1;
 }
 $data['searchq'] = "inner join gridimage_group using (gridimage_id) where {$where} group by gridimage_id";
 $data['distance'] = 1;
 $nearstring = 'in';
 if (!empty($data['gridref'])) {
     require_once 'geograph/gridsquare.class.php';
     $square = new GridSquare();
     if ($square->validGridRef(preg_replace('/[^\\w]/', '', $data['gridref']))) {
         $grid_ok = $square->setByFullGridRef($data['gridref'], false, true);
         if ($grid_ok || $square->x && $square->y) {
             $data['description'] .= ", {$nearstring} grid reference " . $square->grid_reference;
             $data['x'] = $square->x;
             $data['y'] = $square->y;
         }
     }
     unset($data['gridref']);
 }
 if (empty($data['displayclass'])) {
     $data['displayclass'] = 'cluster2';
 }
 $data['breakby'] = 'label+';
 switch ($data['orderby']) {
     case 'label':
     case 'crc32(label)':
Esempio n. 13
0
         list($e, $n, $reference_index) = $conv->wgs84_to_national($_GET['lat'], $_GET['long'], $_GET['usehermert']);
         if ($reference_index == 1) {
             $en = array($e, $n);
             $_GET['datum'] = "osgb36";
         } else {
             if ($reference_index == 2) {
                 $en = array($e, $n);
                 $_GET['datum'] = "irish";
             }
         }
     }
 }
 if (isset($en) && count($en)) {
     list($gridref, $len) = $conv->national_to_gridref($en[0], $en[1], 0, $reference_index);
     $square = new GridSquare();
     if ($square->setByFullGridRef($gridref)) {
         //find a possible place
         $smarty->assign('place', $square->findNearestPlace(135000));
         //lets add an overview map too
         $overview = new GeographMapMosaic('largeoverview');
         $overview->setCentre($square->x, $square->y);
         //does call setAlignedOrigin
         $overview->assignToSmarty($smarty, 'overview');
         $smarty->assign('marker', $overview->getSquarePoint($square));
         //get a token to show a suroudding geograph map
         $mosaic = new GeographMapMosaic();
         $smarty->assign('map_token', $mosaic->getGridSquareToken($square));
     }
     $smarty->assign('gridref', $gridref);
     list($gridref, $len) = $conv->national_to_gridref($en[0], $en[1], 4, $reference_index);
     $smarty->assign('gridref4', $gridref);
Esempio n. 14
0
 function handleGridref($more = false)
 {
     $square = new GridSquare();
     $grid_given = true;
     $grid_ok = $square->setByFullGridRef($this->params[0]);
     $_GET['key'] = $this->params[1];
     ini_set('memory_limit', '64M');
     $image = new GridImage();
     if ($grid_ok) {
         $this->beginResponse();
         if ($square->imagecount) {
             if (!empty($_GET['limit']) || !empty($_GET['offset'])) {
                 $offset = @intval($_GET['offset']);
                 $limit = empty($_GET['limit']) ? 20 : intval($_GET['limit']);
                 $order = "order by null limit {$offset},{$limit}";
             } else {
                 $order = "order by null";
             }
             $images = $square->getImages(false, '', $order);
             $count = count($images);
             if ($this->output == 'json') {
                 require_once '3rdparty/JSON.php';
                 $json = new Services_JSON();
                 $whitelist = array('gridimage_id' => 1, 'seq_no' => 1, 'user_id' => 1, 'ftf' => 1, 'moderation_status' => 1, 'title' => 1, 'comment' => 1, 'submitted' => 1, 'realname' => 1, 'nateastings' => 1, 'natnorthings' => 1, 'natgrlen' => 1, 'imageclass' => 1, 'imagetaken' => 1, 'upd_timestamp' => 1, 'viewpoint_eastings' => 1, 'viewpoint_northings' => 1, 'viewpoint_grlen' => 1, 'view_direction' => 1, 'use6fig' => 1, 'credit_realname' => 1, 'profile_link' => 1);
                 #$whitelist = array('gridimage_id'=>1, 'seq_no'=>1, 'user_id'=>1, 'ftf'=>1, 'moderation_status'=>1, 'title'=>1, 'comment'=>1, 'submitted'=>1, 'realname'=>1, 'tags'=>1, 'nateastings'=>1, 'natnorthings'=>1, 'natgrlen'=>1, 'imageclass'=>1, 'imagetaken'=>1, 'upd_timestamp'=>1, 'viewpoint_eastings'=>1, 'viewpoint_northings'=>1, 'viewpoint_grlen'=>1, 'view_direction'=>1, 'use6fig'=>1, 'credit_realname'=>1, 'profile_link'=>1);
                 #FIXME title1,title2,comment1,comment2
                 foreach ($images as $i => $image) {
                     foreach ($image as $k => $v) {
                         if (empty($v) || empty($whitelist[$k])) {
                             unset($images[$i]->{$k});
                         }
                     }
                     $images[$i]->thumbnail = $image->getThumbnail(120, 120, true);
                 }
                 print $json->encode($images);
             } else {
                 echo '<status state="ok" count="' . $count . '"/>';
                 #FIXME title1,title2,comment1,comment2
                 foreach ($images as $i => $image) {
                     if ($image->moderation_status == 'geograph' || $image->moderation_status == 'accepted') {
                         echo " <image url=\"http://{$_SERVER['HTTP_HOST']}/photo/{$image->gridimage_id}\">";
                         echo ' <title>' . utf8_encode(htmlentities($image->title)) . '</title>';
                         echo " <user profile=\"http://{$_SERVER['HTTP_HOST']}{$image->profile_link}\">" . utf8_encode(htmlentities($image->realname)) . '</user>';
                         echo ' ' . preg_replace('/alt=".*?" /', '', $image->getThumbnail(120, 120));
                         if ($more) {
                             echo '<taken>' . htmlentities($image->imagetaken) . '</taken>';
                             echo '<submitted>' . htmlentities($image->submitted) . '</submitted>';
                             echo '<category>' . utf8_encode(htmlentities2($image->imageclass)) . '</category>';
                             echo '<comment><![CDATA[' . utf8_encode(htmlentities2($image->comment)) . ']]></comment>';
                             echo '<view_direction>' . htmlentities($image->view_direction) . '</view_direction>';
                         }
                         echo ' <location grid="' . $square->reference_index . '" eastings="' . $image->nateastings . '" northings="' . $image->natnorthings . '" figures="' . $image->natgrlen . '"/>';
                         echo '</image>';
                     }
                 }
             }
         } else {
             if ($this->output == 'json') {
                 print "{error: '0 results'}";
             } else {
                 echo '<status state="ok" count="0"/>';
             }
         }
         $this->endResponse();
     } else {
         $this->error("Invalid grid reference " . $this->params[0]);
     }
 }
Esempio n. 15
0
 * This program is distributed in the hope that it will be useful,
 * 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';
require_once 'geograph/gridsquare.class.php';
init_session();
$smarty = new GeographPage();
if (isset($_GET['gridref'])) {
    $square = new GridSquare();
    $ok = $square->setByFullGridRef($_GET['gridref'], false, true);
    if ($ok || $square->x && strlen($square->grid_reference) > 4) {
        $gridref = $square->grid_reference;
        $smarty->assign_by_ref('gridref', $gridref);
        $smarty->assign('showinfo', 1);
        $isadmin = $USER->hasPerm('moderator') || $USER->hasPerm('mapmod') ? 1 : 0;
        $smarty->assign_by_ref('isadmin', $isadmin);
        $db = NewADOConnection($GLOBALS['DSN']);
        $smarty->assign('check_count', -2);
        //can we find a square?
        $sq = $db->GetRow("select * from gridsquare where grid_reference='{$gridref}' limit 1");
        if (count($sq)) {
            $smarty->assign('percent_land', $sq['percent_land']);
            if ($count = $db->GetOne("select count(*) from mapfix_log where gridsquare_id='{$sq['gridsquare_id']}'")) {
                $smarty->assign('check_count', $count);
            } else {
Esempio n. 16
0
     $custom_where .= " and submitted LIKE " . $db->Quote($_GET['submittedyear'] . "%");
     $date = getFormattedDate($_GET['submittedyear']);
     $filtered_title .= " Submitted in {$date}";
 }
 if (isset($_GET['direction']) && strlen($_GET['direction'])) {
     $direction = intval($_GET['direction']);
     $custom_where .= " and view_direction = {$direction}";
     $view_direction = $direction % 90 == 0 ? strtoupper(heading_string($direction)) : ucwords(heading_string($direction));
     $filtered_title .= " Looking {$view_direction}";
 }
 if (!empty($_GET['viewpoint'])) {
     $viewpoint_square = new GridSquare();
     if ($_GET['viewpoint'] == '-') {
         $custom_where .= " and viewpoint_eastings = 0";
         $filtered_title = "photographer position unspecified";
     } elseif ($viewpoint_square->setByFullGridRef($_GET['viewpoint'], true, true)) {
         $e = intval($viewpoint_square->nateastings / 1000);
         $n = intval($viewpoint_square->natnorthings / 1000);
         $custom_where .= " and viewpoint_eastings DIV 1000 = {$e} AND viewpoint_northings DIV 1000 = {$n}";
         $filtered_title .= " Taken in " . $viewpoint_square->grid_reference;
     }
 }
 if (!empty($_GET['centi'])) {
     if ($_GET['centi'] == 'unspecified') {
         $custom_where .= " and nateastings = 0";
     } else {
         if ($_GET['centi'] == 'X') {
             require_once 'geograph/conversions.class.php';
             $conv = new Conversions();
             list($_GET['centi'], $len) = $conv->national_to_gridref($square->getNatEastings() - $correction, $square->getNatNorthings() - $correction, 6, $square->reference_index, $spaced);
         }
Esempio n. 17
0
    $grid_given = true;
    //p=900y + (900-x);
    $p = intval($_GET['p']);
    $x = $p % 900;
    $y = ($p - $x) / 900;
    $x = 900 - $x;
    $grid_ok = $square->loadFromPosition($x, $y, true);
    $grid_given = true;
    $smarty->assign('gridrefraw', $square->grid_reference);
} elseif (isset($_GET['setpos'])) {
    $grid_given = true;
    $grid_ok = $square->setGridPos($_GET['gridsquare'], $_GET['eastings'], $_GET['northings']);
    $smarty->assign('gridrefraw', $square->grid_reference);
} elseif (isset($_GET['gridref']) && strlen($_GET['gridref'])) {
    $grid_given = true;
    $grid_ok = $square->setByFullGridRef($_GET['gridref']);
    //preserve inputs in smarty
    if ($grid_ok) {
        $smarty->assign('gridrefraw', stripslashes($_GET['gridref']));
    } else {
        //preserve the input at least
        $smarty->assign('gridref', stripslashes($_GET['gridref']));
    }
}
$cacheid = '';
//process grid reference
if ($grid_given) {
    $square->rememberInSession();
    //now we see if the grid reference is actually available...
    if ($grid_ok) {
        $smarty->assign_by_ref('square', $square);
Esempio n. 18
0
 if (preg_match('/^([a-zA-Z]{1,3}) +(\\d{1,5})(\\.\\d*|) +(\\d{1,5})(\\.*\\d*|)/', $q, $matches) && $matches[1] != 'tp') {
     $square = new GridSquare();
     $grid_ok = $square->setByFullGridRef($matches[0], true);
     if ($grid_ok) {
         $gr = $square->grid_reference;
         $e = $square->nateastings;
         $n = $square->natnorthings;
         $q = preg_replace("/{$matches[0]}\\s*/", '', $q);
     } else {
         $r = "\t--invalid Grid Ref--";
         $nocache = 1;
     }
 } else {
     if (preg_match('/^([a-zA-Z]{1,3})(\\d{2,10})\\b/', $q, $matches) && $matches[1] != 'tp') {
         $square = new GridSquare();
         $grid_ok = $square->setByFullGridRef($matches[0], true);
         if ($grid_ok) {
             $gr = $square->grid_reference;
             $e = $square->nateastings;
             $n = $square->natnorthings;
             $q = preg_replace("/{$matches[0]}\\s*/", '', $q);
         } else {
             $r = "\t--invalid Grid Ref--";
             $nocache = 1;
         }
     }
 }
 if (preg_match('/\\bp(age|)(\\d+)\\s*$/', $q, $m)) {
     $offset = min(max((intval($m[2]) - 1) * 25, 0), 984);
     $q = preg_replace('/\\bp(age|)\\d+\\s*$/', '', $q);
 } else {
Esempio n. 19
0
    }
    if (isset($_POST['imagetakenYear'])) {
        $image->imagetaken = sprintf("%04d-%02d-%02d", $_POST['imagetakenYear'], $_POST['imagetakenMonth'], $_POST['imagetakenDay']);
    }
    $image->use6fig = !empty($_POST['use6fig']);
    if (!empty($_POST['grid_reference'])) {
        $image->grid_square = new GridSquare();
        $image->grid_square->setByFullGridRef($_POST['grid_reference']);
        $image->grid_reference = $image->grid_square->grid_reference;
        $image->natgrlen = $image->grid_square->natgrlen;
        $image->nateastings = $image->grid_square->nateastings;
        $image->natnorthings = $image->grid_square->natnorthings;
    }
    if (!empty($_POST['photographer_gridref'])) {
        $viewpoint = new GridSquare();
        $ok = $viewpoint->setByFullGridRef($_POST['photographer_gridref'], true);
        $image->viewpoint_eastings = $viewpoint->nateastings;
        $image->viewpoint_northings = $viewpoint->natnorthings;
        $image->viewpoint_grlen = $viewpoint->natgrlen;
    }
    $image->view_direction = intval(strip_tags(trim(stripslashes($_POST['view_direction']))));
    $image->fullpath = "/submit.php?preview=" . strip_tags(trim(stripslashes($_POST['upload_id'])));
    if (!empty($_POST['spelling'])) {
        require_once "3rdparty/spellchecker.class.php";
        ?>
	<style type="text/css">
		body { font-family:Georgia, Verdana, Arial, serif; }
		u { color:red }
		u span { color:black } 
		p { background-color:#eeeeee; border:1px solid gray; padding:10px }
	</style>
Esempio n. 20
0
require_once 'geograph/gridimage.class.php';
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/map.class.php';
if (!isLocalIPAddress()) {
    init_session();
    $USER->mustHavePerm("admin");
}
$db = NewADOConnection($GLOBALS['DSN']);
if (!$db) {
    die('Database connection failed');
}
require_once 'geograph/conversions.class.php';
$conv = new Conversions();
$gr = $_GET['gr'];
$square = new GridSquare();
$grid_ok = $square->setByFullGridRef($gr);
$html = '';
$kml = new kmlFile();
$kml->atom = true;
$stylefile = "http://{$CONF['KML_HOST']}/kml/style.kmz";
$folder = $kml->addChild('Document');
$folder->setItem('name', "{$gr} :: Geograph SuperLayer");
$links = new kmlPrimative('Folder');
$links->setItem('name', 'Next Level...');
$prefix = $db->GetRow('select * from gridprefix where prefix=' . $db->Quote($square->gridsquare) . ' limit 1');
$left = $prefix['origin_x'] + intval($square->eastings / 20) * 20;
$right = $left + 20 - 1;
$bottom = $prefix['origin_y'] + intval($square->northings / 20) * 20;
$top = $bottom + 20 - 1;
$rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
$sql_where = "CONTAINS(GeomFromText({$rectangle}),point_xy)";
 /**
  * commit the upload process
  */
 function commit($method = '', $skip_cleanup = false)
 {
     global $USER, $CONF, $memcache;
     if ($this->validUploadId($this->upload_id)) {
         $uploadfile = $this->_pendingJPEG($this->upload_id);
         if (!file_exists($uploadfile)) {
             return "Upload image not found";
         }
     } else {
         return "Must assign upload id";
     }
     if (!is_object($this->square)) {
         return "Must assign square";
     }
     $viewpoint = new GridSquare();
     if ($this->viewpoint_gridreference) {
         $ok = $viewpoint->setByFullGridRef($this->viewpoint_gridreference, true, true, true);
     }
     //get sequence number
     $mkey = $this->square->gridsquare_id;
     $seq_no =& $memcache->name_get('sid', $mkey);
     if (empty($seq_no) && !empty($CONF['use_insertionqueue'])) {
         $seq_no = $this->db->GetOne("select max(seq_no) from gridimage_queue where gridsquare_id={$this->square->gridsquare_id}");
     }
     if (empty($seq_no)) {
         $seq_no = $this->db->GetOne("select max(seq_no) from gridimage where gridsquare_id={$this->square->gridsquare_id}");
     }
     $seq_no = max($seq_no + 1, 0);
     $memcache->name_set('sid', $mkey, $seq_no, false, $memcache->period_long);
     //ftf is zero under image is moderated
     $ftf = 0;
     //get the exif data and set orientation
     $this->reReadExifFile();
     if (!empty($CONF['use_insertionqueue'])) {
         $table = "gridimage_queue";
     } else {
         $table = "gridimage";
     }
     //create record
     // nateasting/natnorthings will only have values if getNatEastings has been called (in this case because setByFullGridRef has been called IF an exact location is specifed)
     $sql = sprintf("insert into {$table} (" . "gridsquare_id, seq_no, user_id, ftf," . "moderation_status,title,comment,title2,comment2,nateastings,natnorthings,natgrlen,imageclass,imagetaken," . "submitted,viewpoint_eastings,viewpoint_northings,viewpoint_grlen,view_direction,use6fig,user_status,realname,reference_index,viewpoint_refindex) values " . "(%d,%d,%d,%d," . "'pending',%s,%s,%s,%s,%d,%d,'%d',%s,%s," . "now(),%d,%d,'%d',%d,%d,%s,%s,'%d','%d')", $this->square->gridsquare_id, $seq_no, $USER->user_id, $ftf, $this->db->Quote($this->title), $this->db->Quote($this->comment), $this->db->Quote($this->title2), $this->db->Quote($this->comment2), $this->square->nateastings, $this->square->natnorthings, $this->square->natgrlen, $this->db->Quote($this->imageclass), $this->db->Quote($this->imagetaken), $viewpoint->nateastings, $viewpoint->natnorthings, $viewpoint->natgrlen, $this->view_direction, $this->use6fig, $this->db->Quote($this->user_status), $this->db->Quote($this->realname), $this->square->reference_index, $viewpoint->reference_index);
     $this->db->Query($sql);
     //get the id
     $gridimage_id = $this->db->Insert_ID();
     //save the exif
     $sql = sprintf("insert into gridimage_exif (" . "gridimage_id,exif) values " . "(%d,%s)", $gridimage_id, $this->db->Quote($exif));
     $this->db->Query($sql);
     //copy image to correct area
     $src = $this->_pendingJPEG($this->upload_id);
     $image = new GridImage();
     $image->gridimage_id = $gridimage_id;
     $image->user_id = $USER->user_id;
     if ($this->clearexif && $CONF['exiftooldir'] !== '') {
         $cmd = sprintf("\"%sexiftool\" -overwrite_original -all= \"%s\" > /dev/null 2>&1", $CONF['exiftooldir'], $src);
         passthru($cmd);
     }
     $storedoriginal = false;
     if ($ok = $image->storeImage($src)) {
         $orginalfile = $this->_originalJPEG($this->upload_id);
         if (file_exists($orginalfile) && $this->largestsize && $this->largestsize > $CONF['img_max_size']) {
             if ($this->switchxy) {
                 list($oheight, $owidth, $otype, $oattr) = getimagesize($orginalfile);
             } else {
                 list($owidth, $oheight, $otype, $oattr) = getimagesize($orginalfile);
             }
             list($destwidth, $destheight, $destdim, $changedim) = $this->_new_size($owidth, $oheight, $this->largestsize);
             $this->_downsizeFile($orginalfile, $destdim);
             if ($this->clearexif && $CONF['exiftooldir'] !== '') {
                 $cmd = sprintf("\"%sexiftool\" -overwrite_original -all= \"%s\" > /dev/null 2>&1", $CONF['exiftooldir'], $orginalfile);
                 passthru($cmd);
             }
             $storedoriginal = $image->storeOriginal($orginalfile);
         }
         if (!$skip_cleanup) {
             $this->cleanUp();
         }
     }
     //fire an event
     require_once 'geograph/event.class.php';
     new Event(EVENT_NEWPHOTO, $gridimage_id . ',' . $USER->user_id . ',' . $storedoriginal);
     #//assign the snippets now we know the real id.
     #$gid = crc32($this->upload_id)+4294967296;
     #$gid += $USER->user_id * 4294967296;
     #
     #$this->db->Execute($sql = "UPDATE gridimage_snippet SET gridimage_id = $gridimage_id WHERE gridimage_id = ".$gid);
     $this->gridimage_id = $gridimage_id;
     #if (!empty($method)) {
     #	if (!empty($GLOBALS['STARTTIME'])) {
     #
     #		list($usec, $sec) = explode(' ',microtime());
     #		$endtime = ((float)$usec + (float)$sec);
     #		$timetaken = $endtime - $GLOBALS['STARTTIME'];
     #
     #		$this->db->Execute("INSERT INTO submission_method SET gridimage_id = $gridimage_id,method='$method',timetaken=$timetaken");
     #	} else {
     #		$this->db->Execute("INSERT INTO submission_method SET gridimage_id = $gridimage_id,method='$method'");
     #	}
     #}
 }
Esempio n. 22
0
 /**
  * update user profile
  * profile array should contain website, nickname, realname flag. A
  * public_email entry, if present, will cause the public_email flag
  * to be set. The idea is to simply pass the $_POST array - all values
  * are checked for validity
  */
 function updateProfile(&$profile, &$errors)
 {
     global $CONF, $MESSAGES;
     $db = $this->_getDB();
     $ok = true;
     $profile['realname'] = stripslashes($profile['realname']);
     $profile['nickname'] = stripslashes($profile['nickname']);
     $profile['website'] = stripslashes($profile['website']);
     $profile['oldpassword'] = stripslashes($profile['oldpassword']);
     $profile['password1'] = stripslashes($profile['password1']);
     $profile['password2'] = stripslashes($profile['password2']);
     // valid homesquare?
     $profile['grid_reference'] = stripslashes($profile['grid_reference']);
     $gridreference = '';
     $gs = new GridSquare();
     if (strlen($profile['grid_reference'])) {
         $gsok = $gs->setByFullGridRef($profile['grid_reference']);
         if (!$gsok) {
             $ok = false;
             $errors['grid_reference'] = $gs->errormsg;
         }
     }
     if (strlen($profile['realname'])) {
         if (!isValidRealName($profile['realname'])) {
             $ok = false;
             $errors['realname'] = $MESSAGES['class_user']['name_chars'];
         }
     } else {
         $ok = false;
         $errors['realname'] = $MESSAGES['class_user']['realname'];
     }
     if (strlen($profile['website']) && !isValidURL($profile['website'])) {
         //can we fix it?
         if (isValidURL("http://" . $profile['website'])) {
             $profile['website'] = "http://" . $profile['website'];
         } else {
             $ok = false;
             $errors['website'] = $MESSAGES['class_user']['website'];
         }
     }
     //unique nickname, since you can log in with it
     if (isValidRealName($profile['nickname'])) {
         //lets be sure it's unique
         $sql = 'select * from user where nickname=' . $db->Quote(stripslashes($profile['nickname'])) . " and user_id<>{$this->user_id} limit 1";
         $r = $db->GetRow($sql);
         if (count($r)) {
             $ok = false;
             $errors['nickname'] = $MESSAGES['class_user']['nickname_in_use'];
         }
         //todo check seperate table
     } else {
         $ok = false;
         $errors['nickname'] = $MESSAGES['class_user']['name_chars'];
     }
     if (strlen($profile['password1'])) {
         if (hash_hmac('md5', $profile['oldpassword'], $this->salt) != $this->password) {
             $ok = false;
             $errors['oldpassword'] = $MESSAGES['class_user']['oldpassword'];
         } elseif ($profile['password1'] != $profile['password2']) {
             $ok = false;
             $errors['password2'] = $MESSAGES['class_user']['password2'];
         } else {
             $salt = $this->randomSalt(8);
             $password = hash_hmac('md5', $profile['password1'], $salt);
         }
     } else {
         $password = $this->password;
         $salt = $this->salt;
     }
     //attempting to change email address?
     if ($profile['email'] != $this->email) {
         if (isValidEmailAddress($profile['email'])) {
             $errors['general'] = sprintf($MESSAGES['class_user']['mail_change'], $profile['email']);
             $ok = false;
             //we need to send the user an email with a confirmation link
             //so we put the information into a table
             $db->Execute("insert into user_emailchange " . "(user_id, oldemail,newemail,requested,status)" . "values(?,?,?,now(), 'pending')", array($this->user_id, $this->email, $profile['email']));
             $id = $db->Insert_ID();
             $url = "http://" . $_SERVER['HTTP_HOST'] . '/reg/m' . $id . '/' . substr(md5('m' . $id . $CONF['register_confirmation_secret']), 0, 16);
             $mail_body = $MESSAGES['class_user']['mailbody_mail_change'];
             $mail_subject = $MESSAGES['class_user']['mailsubject_mail_change'];
             $msg = sprintf($mail_body, $_SERVER['HTTP_HOST'], $profile['email'], $url);
             $sub = sprintf($mail_subject, $_SERVER['HTTP_HOST']);
             @mail($profile['email'], mb_encode_mimeheader($CONF['mail_subjectprefix'] . $sub, $CONF['mail_charset'], $CONF['mail_transferencoding']), $msg, "From: Geograph <{$CONF['mail_from']}>\n" . "MIME-Version: 1.0\n" . "Content-Type: text/plain; {$CONF['mail_charset']}\n" . "Content-Disposition: inline\n" . "Content-Transfer-Encoding: 8bit", is_null($CONF['mail_envelopefrom']) ? null : "-f {$CONF['mail_envelopefrom']}");
         } else {
             $errors['email'] = $MESSAGES['class_user']['new_email_invalid'];
             $ok = false;
         }
     }
     if ($ok) {
         //about box is always public - col to be removed
         $profile['public_about'] = 1;
         $profile['use_age_group'] = 0;
         //age info is useless to others, nice for us, no need
         //to give use a public option
         if ($this->realname != $profile['realname']) {
             $db->Execute(sprintf("insert into user_change set \n\t\t\t\t\tuser_id = %d,\n\t\t\t\t\tfield = 'realname',\n\t\t\t\t\tvalue = %s\n\t\t\t\t\t", $this->user_id, $db->Quote($profile['realname'])));
         }
         if ($this->nickname != $profile['nickname']) {
             $db->Execute(sprintf("insert into user_change set \n\t\t\t\t\tuser_id = %d,\n\t\t\t\t\tfield = 'nickname',\n\t\t\t\t\tvalue = %s\n\t\t\t\t\t", $this->user_id, $db->Quote($profile['nickname'])));
         }
         $sql = sprintf("update user set \n\t\t\t\trealname=%s,\n\t\t\t\tnickname=%s,\n\t\t\t\twebsite=%s,\n\t\t\t\tpublic_email=%d,\n\t\t\t\tsearch_results=%d,\n\t\t\t\tslideshow_delay=%d,\n\t\t\t\tabout_yourself=%s,\n\t\t\t\tpublic_about=%d,\n\t\t\t\tage_group=%d,\n\t\t\t\tuse_age_group=%d,\n\t\t\t\thome_gridsquare=%s,\n\t\t\t\tticket_public=%s,\n\t\t\t\tcalendar_public=%s,\n\t\t\t\tticket_option=%s,\n\t\t\t\tmessage_sig=%s,\n\t\t\t\tupload_size=%d,\n\t\t\t\tclear_exif=%d,\n\t\t\t\tsalt=%s,\n\t\t\t\tpassword=%s\n\t\t\t\twhere user_id=%d", $db->Quote($profile['realname']), $db->Quote($profile['nickname']), $db->Quote($profile['website']), empty($profile['public_email']) ? 0 : 1, $profile['search_results'], $profile['slideshow_delay'], $db->Quote(strip_tags(stripslashes($profile['about_yourself']))), $profile['public_about'] ? 1 : 0, $profile['age_group'], $profile['use_age_group'] ? 1 : 0, $gs->gridsquare_id, $db->Quote($profile['ticket_public']), $db->Quote($profile['calendar_public']), $db->Quote($profile['ticket_option']), $db->Quote(stripslashes($profile['message_sig'])), intval($profile['upload_size']), $profile['clear_exif'] ? 1 : 0, $db->Quote($salt), $db->Quote($password), $this->user_id);
         if ($db->Execute($sql) === false) {
             $errors['general'] = $MESSAGES['class_user']['error_dbupdate'] . $db->ErrorMsg();
             $ok = false;
         } else {
             //hurrah - it's all good - lets update ourself..
             //update gridimage_search too
             if ($this->realname != stripslashes($profile['realname'])) {
                 $sql = "update gridimage_search set realname=" . $db->Quote(stripslashes($profile['realname'])) . " where user_id = {$this->user_id}";
                 $db->Execute($sql);
             }
             $this->realname = $profile['realname'];
             $this->nickname = $profile['nickname'];
             $this->password = $password;
             $this->salt = $salt;
             $this->website = $profile['website'];
             $this->public_email = isset($profile['public_email']) ? 1 : 0;
             if (isset($profile['sortBy'])) {
                 $this->sortBy = stripslashes($profile['sortBy']);
             }
             $this->search_results = stripslashes($profile['search_results']);
             $this->slideshow_delay = stripslashes($profile['slideshow_delay']);
             $this->about_yourself = stripslashes($profile['about_yourself']);
             $this->public_about = stripslashes($profile['public_about']);
             $this->age_group = stripslashes($profile['age_group']);
             $this->use_age_group = stripslashes($profile['use_age_group']);
             $this->grid_reference = $gs->grid_reference;
             $this->calendar_public = stripslashes($profile['calendar_public']);
             $this->ticket_public = stripslashes($profile['ticket_public']);
             $this->ticket_option = stripslashes($profile['ticket_option']);
             $this->message_sig = stripslashes($profile['message_sig']);
             $this->upload_size = intval($profile['upload_size']);
             $this->clear_exif = !empty($profile['clear_exif']);
             $this->_forumUpdateProfile();
             $this->_forumLogin();
             if (!empty($profile['ticket_public_change'])) {
                 $sql = sprintf("update gridimage_ticket set `public`=%s where user_id = %d", $db->Quote($profile['ticket_public_change']), $this->user_id);
                 if ($db->Execute($sql) === false) {
                     $errors['general'] = $MESSAGES['class_user']['error_dbupdate'] . $db->ErrorMsg();
                     $ok = false;
                 }
             }
         }
     }
     return $ok;
 }
 /**
  * Reassigns the reference of this image - callers of this are responsible for ensuring
  * only authorized calls can be made, but the method performs full error checking of 
  * the supplied reference
  */
 function reassignGridsquare($grid_reference, &$error)
 {
     $ok = false;
     //is the reference valid?
     //old one is in $this->grid_square
     $newsq = new GridSquare();
     if (is_object($this->db)) {
         $newsq->_setDB($this->_getDB());
     }
     if ($newsq->setByFullGridRef($grid_reference, false, true, true)) {
         $db =& $this->_getDB();
         //ensure this is a real change
         if ($newsq->gridsquare_id != $this->gridsquare_id) {
             //get sequence number of target square - for a rejected image
             //we use a negative sequence number
             if ($this->moderation_status != 'rejected') {
                 $seq_no = $db->GetOne("select max(seq_no) from gridimage " . "where gridsquare_id={$newsq->gridsquare_id}");
                 $seq_no = max($seq_no + 1, 0);
             } else {
                 $seq_no = $db->GetOne("select min(seq_no) from gridimage " . "where gridsquare_id={$newsq->gridsquare_id}");
                 $seq_no = min($seq_no - 1, -1);
             }
             //was this image ftf?
             if ($this->ftf) {
                 //reset the ftf flag
                 $this->ftf = 0;
                 //need to assign ftf to another image in the square if possible
                 $next_geograph = $db->GetOne("select gridimage_id from gridimage " . "where gridsquare_id={$this->gridsquare_id} and moderation_status='geograph' " . "and gridimage_id<>{$this->gridimage_id} " . "order by gridimage_id");
                 if ($next_geograph) {
                     $db->Query("update gridimage set ftf=1 where gridimage_id={$next_geograph}");
                     $db->Query("update gridimage_search set ftf=1 where gridimage_id={$next_geograph}");
                 }
             }
             //does the image get ftf in the target square?
             if ($this->moderation_status == 'geograph') {
                 $geographs = $db->GetOne("select count(*) from gridimage " . "where gridsquare_id={$newsq->gridsquare_id} and moderation_status='geograph' and ftf = 1");
                 if ($geographs == 0) {
                     $this->ftf = 1;
                 }
             }
             $sql_set = "gridsquare_id='{$newsq->gridsquare_id}'," . "seq_no={$seq_no},ftf={$this->ftf}, ";
         }
         //if not a new square only update nateastings and natnorthings
         //we DONT use getNatEastings here because only want them if it more than 4 figure
         $east = $newsq->nateastings + 0;
         $north = $newsq->natnorthings + 0;
         $ri = $newsq->reference_index;
         //reassign image
         $db->Execute("update gridimage set {$sql_set} " . "nateastings={$east},natnorthings={$north},reference_index={$ri},natgrlen='{$newsq->natgrlen}' " . "where gridimage_id='{$this->gridimage_id}'");
         //ensure this is a real change
         if ($newsq->gridsquare_id != $this->gridsquare_id) {
             //fire an event (some of the stuff that follows
             //might be better as an event handler
             require_once 'geograph/event.class.php';
             new Event(EVENT_MOVEDPHOTO, "{$this->gridimage_id},{$this->grid_square->grid_reference},{$newsq->grid_reference}");
             //update cached data for old square and new square
             $this->grid_square->updateCounts();
             $newsq->updateCounts();
             //invalidate any cached maps
             //handled by the event above
             //update placename cached column
             //handled by the event above
             //updated cached tables
             //this isnt needed as reassignGridsquare is only called before commitChanges
             //$this->updateCachedTables();
             //updateCachedTables needs to know the new gridref for the lat/long calc!
             $this->newsq =& $newsq;
         }
         $ok = true;
     } else {
         //bad grid reference
         $ok = false;
         $error = $newsq->errormsg;
     }
     return $ok;
 }