Example #1
0
function viewqueries()
{
    global $tplname, $usr;
    global $viewquery_line, $noqueries, $bgcolor1, $bgcolor2;
    $tplname = 'viewqueries';
    $dbc = new dataBase();
    $i = 0;
    $content = '';
    //$rs = sql("SELECT `id`, `name` FROM `queries` WHERE `user_id`='&1' ORDER BY `name` ASC", $usr['userid']);
    $query = "SELECT id, name FROM `queries` WHERE `user_id`=:1 ORDER BY `name` ASC";
    $dbc->multiVariableQuery($query, $usr['userid']);
    if ($dbc->rowCount() != 0) {
        //while ($r = sql_fetch_array($rs))
        while ($r = $dbc->dbResultFetch()) {
            $thisline = $viewquery_line;
            $thisline = mb_ereg_replace('{queryname}', htmlspecialchars($r['name'], ENT_COMPAT, 'UTF-8'), $thisline);
            $thisline = mb_ereg_replace('{queryid}', htmlspecialchars($r['id'], ENT_COMPAT, 'UTF-8'), $thisline);
            if ($i % 2 == 1) {
                $thisline = mb_ereg_replace('{bgcolor}', $bgcolor2, $thisline);
            } else {
                $thisline = mb_ereg_replace('{bgcolor}', $bgcolor1, $thisline);
            }
            $content .= $thisline;
            $i++;
        }
        //mysql_free_result($rs);
    } else {
        $content = $noqueries;
    }
    unset($dbc);
    tpl_set_var('queries', $content);
    tpl_BuildTemplate();
    exit;
}
Example #2
0
 /**  =====================================================================================
      * Funkcja sprawdzająca czy użytkownik uczestniczył w wydarzeniu
      *
      * dane wejściowe:
      * id skrzynki
      * id zalogowanego użytkownika
      *
      * zwraca true lub false
      *
       ===================================================================================== */
 private static function is_event_attended($cache_id, $user_id)
 {
     $q = 'SELECT user_id FROM cache_logs WHERE cache_id =:v1 AND user_id =:v2 AND type = 7 AND Deleted=0';
     $db = new dataBase();
     $params['v1']['value'] = (int) $cache_id;
     $params['v1']['data_type'] = 'integer';
     $params['v2']['value'] = (int) $user_id;
     $params['v2']['data_type'] = 'integer';
     $db->paramQuery($q, $params);
     $rec = $db->dbResultFetch();
     unset($db);
     if (isset($rec['user_id'])) {
         return true;
     } else {
         return false;
     }
 }
     $user_id = $usr['userid'];
 }
 tpl_set_var('userid', $user_id);
 require $stylepath . '/viewprofile.inc.php';
 require $stylepath . '/lib/icons.inc.php';
 $tplname = 'viewprofile';
 if ($user_id != $usr['userid']) {
     // do not highlight My stats menu item if browsing other users stats
     $mnu_siteid = 'start';
 }
 $stat_menu = array('title' => tr('Statictics'), 'menustring' => tr('Statictics'), 'siteid' => 'statlisting', 'navicolor' => '#E8DDE4', 'visible' => false, 'filename' => 'viewprofile.php?userid=' . $user_id, 'submenu' => array(array('title' => tr('graph_find'), 'menustring' => tr('graph_find'), 'visible' => true, 'filename' => 'ustatsg2.php?userid=' . $user_id, 'newwindow' => false, 'siteid' => 'findstat', 'icon' => 'images/actions/stat'), array('title' => tr('graph_created'), 'menustring' => tr('graph_created'), 'visible' => true, 'filename' => 'ustatsg1.php?userid=' . $user_id, 'newwindow' => false, 'siteid' => 'createstat', 'icon' => 'images/actions/stat')));
 $content = "";
 $database = new dataBase();
 $rddQuery = "select TO_DAYS(NOW()) - TO_DAYS(`date_created`) `diff` from `user` WHERE user_id=:1 ";
 $database->multiVariableQuery($rddQuery, $user_id);
 $ddays = $database->dbResultFetch();
 $query = "SELECT admin, guru, hidden_count, founds_count, is_active_flag, email, password, log_notes_count, notfounds_count, username, last_login, country, date_created, description, hide_flag FROM user WHERE user_id=:1 LIMIT 1";
 $database->multiVariableQuery($query, $user_id);
 $user_record = $database->dbResultFetch();
 tpl_set_var('username', $user_record['username']);
 if (date('m') == 4 and date('d') == 1) {
     tpl_set_var('username', tr('primaAprilis1'));
 }
 tpl_set_var('country', tr($user_record['country']));
 tpl_set_var('registered', fixPlMonth(strftime($dateformat, strtotime($user_record['date_created']))));
 $description = $user_record['description'];
 tpl_set_var('description', nl2br($description));
 if ($description != "") {
     tpl_set_var('description_start', '');
     tpl_set_var('description_end', '');
 } else {
Example #4
0
         require_once $rootpath . 'lib/eventhandler.inc.php';
         event_new_log($cache_id, $usr['userid'] + 0);
     }
     //redirect to viewcache
     $no_tpl_build = true;
     //include('viewcache.php');
     tpl_redirect('viewcache.php?cacheid=' . $cache_id);
 } else {
     $sql = "SELECT count(*) as founds FROM `cache_logs` WHERE `deleted`=0 AND user_id='" . sql_escape($usr['userid']) . "' AND cache_id='" . sql_escape($cache_id) . "' AND type = '1'";
     $res = mysql_fetch_array(mysql_query($sql));
     $sql = "SELECT status, type FROM `caches` WHERE cache_id='" . sql_escape($cache_id) . "'";
     $res2 = mysql_fetch_array(mysql_query($sql));
     $db = new dataBase();
     $queryEventAttended = "SELECT count(*) as eventAttended FROM `cache_logs` WHERE `deleted`=0 AND user_id=:1 AND cache_id=:2 AND type = '7'";
     $db->multiVariableQuery($queryEventAttended, $usr['userid'], $cache_id);
     $eventAttended = $db->dbResultFetch();
     // debug('$res', $res);
     // debug('$res2', $res2);
     // debug('$log_types', $log_types);
     /*                 * **************
                      * build logtypeoptions
                      *
                      * value  = Info
                      *
                      * -2=  Chose log type;
                       1 = Found;
                       2 = Didn't found';
                       3 = Write a note;
                       4 = Moved;
                       5 = Needs maintenace;
                       6 = Made service;
Example #5
0
 $multiplier['sm'] = 0.62137;
 $multiplier['nm'] = 0.53996;
 if (isset($_REQUEST['queryid']) || isset($_REQUEST['showresult'])) {
     $bCookieQueryid = false;
     $queryid = isset($_REQUEST['queryid']) ? addslashes($_REQUEST['queryid']) : 0;
 } else {
     $bCookieQueryid = true;
     $queryid = get_cookie_setting('lastqueryid');
     if ($queryid == false) {
         $queryid = 0;
     }
     if ($queryid != 0) {
         // check if query exists
         $sqlstr = "SELECT COUNT(*) `count` FROM `queries` WHERE id= :1";
         $dbc->multiVariableQuery($sqlstr, $queryid);
         $rCount = $dbc->dbResultFetch();
         if ($rCount['count'] == 0) {
             $queryid = 0;
         }
         $dbc->reset();
     }
     if ($queryid == 0) {
         // das Suchformular wird initialisiert (keine Vorbelegungen vorhanden)
         $_REQUEST['cache_attribs'] = '';
         $rs = sql('SELECT `id` FROM `cache_attrib` WHERE `default`=1');
         while ($r = sql_fetch_assoc($rs)) {
             if ($_REQUEST['cache_attribs'] != '') {
                 $_REQUEST['cache_attribs'] .= ';';
             }
             $_REQUEST['cache_attribs'] .= $r['id'];
         }
Example #6
0
 }
 $i = 0;
 $content = '';
 /* $rs = sql("   SELECT `cache_rating`.`cache_id` AS `cache_id`, `caches`.`name` AS `cachename`,
    `user`.`username` AS `ownername`, `user`.`user_id` AS `owner_id`
    FROM `cache_rating`, `caches`, `user`
    WHERE `cache_rating`.`cache_id` = `caches`.`cache_id`
    AND `caches`.`user_id`=`user`.`user_id`
    AND `cache_rating`.`user_id`='&1' ORDER BY `caches`.`name` ASC", $userid); */
 $query = "SELECT `cache_rating`.`cache_id` AS `cache_id`, `caches`.`name` AS `cachename`,\n                `user`.`username` AS `ownername`, `user`.`user_id` AS `owner_id`\n                FROM `cache_rating`, `caches`, `user`\n                WHERE `cache_rating`.`cache_id` = `caches`.`cache_id`\n                  AND `caches`.`user_id`=`user`.`user_id`\n                  AND `cache_rating`.`user_id`= :1 ORDER BY `caches`.`name` ASC";
 $dbc = new dataBase();
 $dbc->multiVariableQuery($query, $userid);
 //if (mysql_num_rows($rs) != 0)
 if ($dbc->rowCount() != 0) {
     //          while ($r = sql_fetch_array($rs))
     while ($r = $dbc->dbResultFetch()) {
         $thisline = $viewtop5_line;
         $thisline = mb_ereg_replace('{cachename}', htmlspecialchars($r['cachename'], ENT_COMPAT, 'UTF-8'), $thisline);
         $thisline = mb_ereg_replace('{cacheid}', htmlspecialchars($r['cache_id'], ENT_COMPAT, 'UTF-8'), $thisline);
         $thisline = mb_ereg_replace('{ownername}', htmlspecialchars($r['ownername'], ENT_COMPAT, 'UTF-8'), $thisline);
         $thisline = mb_ereg_replace('{owner_id}', htmlspecialchars($r['owner_id'], ENT_COMPAT, 'UTF-8'), $thisline);
         if ($i % 2 == 1) {
             $thisline = mb_ereg_replace('{bgcolor}', $bgcolor2, $thisline);
         } else {
             $thisline = mb_ereg_replace('{bgcolor}', $bgcolor1, $thisline);
         }
         $content .= $thisline;
         $i++;
     }
     unset($dbc);
     //mysql_free_result($rs);
set_time_limit(1800);
if (!$usr && $hide_coords) {
    die;
}
$dbc = new dataBase();
$sql = 'SELECT ';
if (isset($lat_rad) && isset($lon_rad)) {
    $sql .= getCalcDistanceSqlFormula($usr !== false, $lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
} else {
    if ($usr === false) {
        $sql .= '0 distance, ';
    } else {
        //get the users home coords
        $sqlstr = "SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`= :1";
        $dbc->multiVariableQuery($sqlstr, $usr['userid']);
        $record_coords = $dbc->dbResultFetch();
        if ($record_coords['latitude'] == NULL || $record_coords['longitude'] == NULL || ($record_coords['latitude'] == 0 || $record_coords['longitude'] == 0)) {
            $sql .= '0 distance, ';
        } else {
            //TODO: load from the users-profile
            $distance_unit = 'km';
            $lon_rad = $record_coords['longitude'] * 3.14159 / 180;
            $lat_rad = $record_coords['latitude'] * 3.14159 / 180;
            $sql .= getCalcDistanceSqlFormula($usr !== false, $record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
        }
        $dbc->reset();
        unset($dbc);
    }
}
$sql .= '`caches`.`cache_id` `cache_id`, `caches`.`status` `status`, `caches`.`type` `type`, `caches`.`size` `size`, `caches`.`user_id` `user_id`, ';
if ($usr === false) {
Example #8
0
}
////////////////////
//echo " var chartOpt = gcb.getChartOption();";
//echo " chartOpt.vAxis.title= '".tr2('NrCaches',$lang)."';";
echo "</script>";
unset($dbc);
////////////////////////////
foreach ($asUserID as $sID) {
    $sCondition = " and cl.user_id = '" . $sID . "'";
    $sCondition .= $sDateCondition;
    $dbc = new dataBase();
    $query = "SELECT u.username username, u.user_id user_id,\n            " . $sGranulate . ",\n            COUNT(*) count\n\n            FROM\n            cache_logs cl\n            join caches c on c.cache_id = cl.cache_id\n            join user u on cl.user_id = u.user_id\n\n            WHERE cl.deleted=0 " . $sTypeCondition . $sCondition . "GROUP BY period";
    $dbc->multiVariableQuery($query);
    echo "<script type='text/javascript'>";
    $nStart = 1;
    while ($record = $dbc->dbResultFetch()) {
        $nPeriod = $record['period'];
        $nVal = $record['count'];
        if ($nStart == 1) {
            $sUserName = $record['username'];
            $sUserName = str_replace("'", "`", $sUserName);
            $nUserId = $record['user_id'];
            echo "\n            gcb.addEmptyRow();\n            gcb.addToLastRow( 0, '{$sUserName}' );\n            ";
            $nStart = 0;
        }
        $nrCol = $aNrColumn[$nPeriod];
        echo "gcb.addToLastRow( {$nrCol}+1 , {$nVal} );";
    }
    echo "</script>";
    unset($dbc);
}
Example #9
0
 if ($cache_record['mp3count'] > 0) {
     $mp3files = '';
     $thatquery = "SELECT `id`, `url`, `title`, `uuid`, `seq` FROM `mp3` WHERE `object_id`=:v1 AND `object_type`=2 ORDER BY seq, date_created";
     $params['v1']['value'] = (int) $cache_id;
     $params['v1']['data_type'] = 'integer';
     if (!isset($dbc)) {
         $dbc = new dataBase();
     }
     $dbc->paramQuery($thatquery, $params);
     $mp3_count = $dbc->rowCount();
     $mp3_all = $dbc->dbResultFetchAll();
     $thatquery = "SELECT `seq` FROM `mp3` WHERE `object_id`=:v1 AND `object_type`=2 ORDER BY `seq` DESC";
     //get highest seq number for this cache
     $dbc->paramQuery($thatquery, $params);
     //params are same as a few lines above
     $max_seq_record = $dbc->dbResultFetch();
     unset($params);
     //clear to avoid overlaping on next paramQuery (if any))
     $max_seq_number = isset($max_seq_record['seq']) ? $max_seq_record['seq'] : 0;
     if ($max_seq_number < $mp3_count) {
         $max_seq_number = $mp3_count;
     }
     tpl_set_var('def_seq_m', $max_seq_number + 1);
     // set default seq for mp3 to be added (if link is click) - this line updated link to newmp3.php)  )
     for ($i = 0; $i < $mp3_count; $i++) {
         $tmpline1 = $mp3line;
         $mp3_record = $mp3_all[$i];
         $tmpline1 = mb_ereg_replace('{seq_drop_mp3}', build_drop_seq($i + 1, $mp3_record['seq'], $max_seq_number, $mp3_record['id'], 'mp3'), $tmpline1);
         $tmpline1 = mb_ereg_replace('{link}', htmlspecialchars($mp3_record['url'], ENT_COMPAT, 'UTF-8'), $tmpline1);
         $tmpline1 = mb_ereg_replace('{title}', htmlspecialchars($mp3_record['title'], ENT_COMPAT, 'UTF-8'), $tmpline1);
         $tmpline1 = mb_ereg_replace('{uuid}', htmlspecialchars($mp3_record['uuid'], ENT_COMPAT, 'UTF-8'), $tmpline1);
Example #10
0
                $record_logs = $dbc->dbResultFetch();
                $tmp_cache = $cache_notpublished_line;
                $tmp_cache = mb_ereg_replace('{cacheimage}', icon_cache_status($record_caches['status'], $record_caches['cache_status_text']), $tmp_cache);
                $tmp_cache = mb_ereg_replace('{cachestatus}', htmlspecialchars($record_caches['cache_status_text'], ENT_COMPAT, 'UTF-8'), $tmp_cache);
                $tmp_cache = mb_ereg_replace('{cacheid}', htmlspecialchars(urlencode($record_caches['cache_id']), ENT_COMPAT, 'UTF-8'), $tmp_cache);
                if (is_null($record_caches['date_activate'])) {
                    $tmp_cache = mb_ereg_replace('{date}', $no_time_set, $tmp_cache);
                } else {
                    $tmp_cache = mb_ereg_replace('{date}', strftime($datetimeformat, strtotime($record_caches['date_activate'])), $tmp_cache);
                }
                $tmp_cache = mb_ereg_replace('{cachename}', htmlspecialchars($record_caches['name'], ENT_COMPAT, 'UTF-8'), $tmp_cache);
                $caches .= "\n" . $tmp_cache;
            }
            tpl_set_var('notpublishedcaches', $caches);
        }
        unset($dbc);
        // get number of sent emails
        $dbc = new dataBase();
        $emails_sent = '0';
        $sql = "SELECT COUNT(*) AS `emails_sent` FROM `email_user` WHERE `from_user_id`=:1";
        $dbc->multiVariableQuery($sql, $usr['userid']);
        $row = $dbc->dbResultFetch();
        if ($dbc->rowCount()) {
            $emails_sent = $row['emails_sent'];
        }
        tpl_set_var('emails_sent', $emails_sent);
        unset($dbc);
    }
}
//make the template and send it out
tpl_BuildTemplate();
Example #11
0
 /**
  *
  * @@param array $opt -  database accesing data from opencaching config
  * @param float $lat geografical latitude (coordinates)
  * @param float $lon geografical longitude (coordinates)
  *
  * @return array with code and names of regions selected from input geografical coordinates.void
  */
 public function GetRegion($lat, $lon)
 {
     require_once __DIR__ . '/lib/gis/gis.class.php';
     $lat_float = (double) $lat;
     $lon_float = (double) $lon;
     $sCode = '';
     $tmpqery = "SELECT `level`, `code`, AsText(`shape`) AS `geometry` FROM `nuts_layer` WHERE WITHIN(GeomFromText('POINT({$lon}  {$lat})'), `shape`) ORDER BY `level` DESC";
     $db = new dataBase();
     $db->simpleQuery($tmpqery);
     $rsLayers = $db->dbResultFetchAll();
     foreach ($rsLayers as $rLayers) {
         if (gis::ptInLineRing($rLayers['geometry'], 'POINT(' . $lon . ' ' . $lat . ')')) {
             $sCode = $rLayers['code'];
             break;
         }
     }
     if ($sCode != '') {
         $adm1 = null;
         $code1 = null;
         $adm2 = null;
         $code2 = null;
         $adm3 = null;
         $code3 = null;
         $adm4 = null;
         $code4 = null;
         if (mb_strlen($sCode) > 5) {
             $sCode = mb_substr($sCode, 0, 5);
         }
         if (mb_strlen($sCode) == 5) {
             $code4 = $sCode;
             $q = "SELECT `name` FROM `nuts_codes` WHERE `code`='{$sCode}'";
             $db->simpleQuery($q);
             $re = $db->dbResultFetch();
             $adm4 = $re["name"];
             unset($re, $q);
             $sCode = mb_substr($sCode, 0, 4);
         }
         if (mb_strlen($sCode) == 4) {
             $code3 = $sCode;
             $q = "SELECT `name` FROM `nuts_codes` WHERE `code`='{$sCode}'";
             $db->simpleQuery($q);
             $re = $db->dbResultFetch();
             $adm3 = $re["name"];
             unset($re, $q);
             $sCode = mb_substr($sCode, 0, 3);
         }
         if (mb_strlen($sCode) == 3) {
             $code2 = $sCode;
             $q = "SELECT `name` FROM `nuts_codes` WHERE `code`='{$sCode}'";
             $db->simpleQuery($q);
             $re = $db->dbResultFetch();
             $adm2 = $re["name"];
             unset($re, $q);
             $sCode = mb_substr($sCode, 0, 2);
         }
         if (mb_strlen($sCode) == 2) {
             $code1 = $sCode;
             // try to get localised name first
             $q = "SELECT `countries`.`pl` FROM `countries` WHERE `countries`.`short`='{$sCode}'";
             // TODO: country column should be localized
             $db->simpleQuery($q);
             $re = $db->dbResultFetch();
             $adm1 = $re["pl"];
             unset($re, $q);
             if ($adm1 == null) {
                 $q = "SELECT `name` FROM `nuts_codes` WHERE `code`='{$sCode}'";
                 $db->simpleQuery($q);
                 $re = $db->dbResultFetch();
                 $adm1 = $re["name"];
                 unset($re, $q);
             }
         }
         $wynik['adm1'] = $adm1;
         $wynik['adm2'] = $adm2;
         $wynik['adm3'] = $adm3;
         $wynik['adm4'] = $adm4;
         $wynik['code1'] = $code1;
         $wynik['code2'] = $code2;
         $wynik['code3'] = $code3;
         $wynik['code4'] = $code4;
     } else {
         $wynik = false;
     }
     return $wynik;
 }
Example #12
0
function revertLog($log_id, $language, $lang)
{
    // set $debug = true to display debug messages (or false to hide).
    $debug = false;
    global $tplname, $usr, $lang, $stylepath, $oc_nodeid, $error_wrong_node, $removed_message_title, $removed_message_end, $emailheaders, $rootpath, $cacheid, $log_record, $cache_types, $cache_size, $cache_status, $dblink;
    $logRs = new dataBase($debug);
    $logRsQuery = "SELECT   `cache_logs`.`node` AS `node`, `cache_logs`.`uuid` AS `uuid`, `cache_logs`.`cache_id` AS `cache_id`, `caches`.`user_id` AS `cache_owner_id`,\n                            `caches`.`name` AS `cache_name`, `cache_logs`.`text` AS `log_text`, `cache_logs`.`type` AS `log_type`,\n                            `cache_logs`.`user_id` AS `log_user_id`, `cache_logs`.`date` AS `log_date`,\n                            `log_types`.`icon_small` AS `icon_small`,\n                            `log_types_text`.`text_listing` AS `text_listing`,\n                            `user`.`username` as `log_username`\n                     FROM   `log_types`, `log_types_text`, `cache_logs`, `caches`, `user`\n                    WHERE   `cache_logs`.`id`=:log_id\n                      AND   `cache_logs`.`user_id`=`user`.`user_id`\n                      AND   `caches`.`cache_id`=`cache_logs`.`cache_id`\n                      AND   `log_types_text`.`log_types_id`=`log_types`.`id` AND `log_types_text`.`lang`=:lang\n                      AND   `cache_logs`.`deleted` = 1\n                      AND   `log_types`.`id`=`cache_logs`.`type`";
    $logRs->paramQuery($logRsQuery, array('log_id' => array('value' => $log_id, 'data_type' => 'integer'), 'lang' => array('value' => $lang, 'data_type' => 'string')));
    //log exists?
    if ($logRs->rowCount() == 1) {
        $log_record = $logRs->dbResultFetch();
        unset($logRs);
        //  include($stylepath . '/removelog.inc.php');
        if ($log_record['node'] != $oc_nodeid) {
            tpl_errorMsg('removelog', $error_wrong_node);
            exit;
        }
        //cache-owner or log-owner
        if ($log_record['log_user_id'] == $usr['userid'] || $log_record['cache_owner_id'] == $usr['userid'] || $usr['admin']) {
            // revert the log.
            $revert = new dataBase($debug);
            $query = "UPDATE `cache_logs` SET deleted = 0 , `last_modified`=NOW() WHERE `cache_logs`.`id`=:log_id LIMIT 1";
            $revert->paramQuery($query, array('log_id' => array('value' => $log_id, 'data_type' => 'i')));
            unset($revert);
            //user stats update
            $statUpd = new dataBase();
            $query = "SELECT `founds_count`, `notfounds_count`, `log_notes_count` FROM `user` WHERE `user_id`=:user_id";
            $statUpd->paramQuery($query, array('user_id' => array('value' => $log_record['log_user_id'], 'data_type' => 'i')));
            $user_record = $statUpd->dbResultFetch();
            unset($statUpd);
            if ($log_record['log_type'] == 1 || $log_record['log_type'] == 7) {
                $user_record['founds_count']++;
            } elseif ($log_record['log_type'] == 2) {
                $user_record['notfounds_count']++;
            } elseif ($log_record['log_type'] == 3) {
                $user_record['log_notes_count']++;
            }
            $updateUser = new dataBase($debug);
            $query = "UPDATE `user` SET `founds_count`=:var1, `notfounds_count`=:var2, `log_notes_count`=:var3 WHERE `user_id`=:var4";
            $params = array('var1' => array('value' => $user_record['founds_count'], 'data_type' => 'i'), 'var2' => array('value' => $user_record['notfounds_count'], 'data_type' => 'i'), 'var3' => array('value' => $user_record['log_notes_count'], 'data_type' => 'i'), 'var4' => array('value' => $log_record['log_user_id'], 'data_type' => 'i'));
            $updateUser->paramQuery($query, $params);
            unset($updateUser, $params, $user_record);
            //call eventhandler
            require_once $rootpath . 'lib/eventhandler.inc.php';
            event_remove_log($cacheid, $usr['userid'] + 0);
            //update cache-stat if type or log_date changed
            $cachStat = new dataBase($debug);
            $query = "SELECT `founds`, `notfounds`, `notes` FROM `caches` WHERE `cache_id`=:var1";
            $cachStat->paramQuery($query, array('var1' => array('value' => $log_record['cache_id'], 'data_type' => 'i')));
            $cache_record = $cachStat->dbResultFetch();
            unset($cachStat);
            if ($log_record['log_type'] == 1 || $log_record['log_type'] == 7) {
                $cache_record['founds']++;
            } elseif ($log_record['log_type'] == 2 || $log_record['log_type'] == 8) {
                $cache_record['notfounds']++;
            } elseif ($log_record['log_type'] == 3) {
                $cache_record['notes']++;
            }
            //Update last found
            $lastF = new dataBase();
            $query = "SELECT MAX(`cache_logs`.`date`) AS `date` FROM `cache_logs` WHERE ((cache_logs.`type`=1) AND (cache_logs.`cache_id`=:last_tmp))";
            $lastF->paramQuery($query, array('last_tmp' => array('value' => $log_record['cache_id'], 'data_type' => 'i')));
            $lastfound_record = $lastF->dbResultFetch();
            unset($statUpd);
            if ($lastfound_record['date'] === NULL) {
                $lastfound = 'NULL';
            } else {
                $lastfound = $lastfound_record['date'];
            }
            $updateCache = new dataBase();
            $query = "UPDATE `caches` SET `last_found`=:var1, `founds`=:var2, `notfounds`=:var3, `notes`=:var4 WHERE `cache_id`=:var5";
            $params = array('var1' => array('value' => $lastfound, 'data_type' => 'string'), 'var2' => array('value' => $cache_record['founds'], 'data_type' => 'i'), 'var3' => array('value' => $cache_record['notfounds'], 'data_type' => 'i'), 'var4' => array('value' => $cache_record['notes'], 'data_type' => 'i'), 'var5' => array('value' => $log_record['cache_id'], 'data_type' => 'i'));
            $updateCache->paramQuery($query, $params);
            unset($updateCache, $params, $cache_record);
            $_GET['cacheid'] = $log_record['cache_id'];
            $_REQUEST['cacheid'] = $log_record['cache_id'];
            require 'viewcache.php';
        } else {
            //TODO: hm ... no permission to revert the log
            $_GET['cacheid'] = $log_record['cache_id'];
            $_REQUEST['cacheid'] = $log_record['cache_id'];
            require 'viewcache.php';
        }
    } else {
        //TODO: log doesn't exist
        $_GET['cacheid'] = $log_record['cache_id'];
        $_REQUEST['cacheid'] = $log_record['cache_id'];
        require 'viewcache.php';
    }
}
 function run()
 {
     $db = new dataBase();
     $db->switchDebug(false);
     $sql = "SELECT cache_id, status FROM caches";
     $params = array();
     if (isset($_GET['cache_id'])) {
         $sql .= ' where cache_id=:cache_id';
         $params['cache_id']['value'] = intval($_GET['cache_id']);
         $params['cache_id']['data_type'] = 'integer';
     }
     $db->paramQuery($sql, $params);
     $caches = $db->dbResultFetchAll();
     set_time_limit(3600);
     $total_touched = 0;
     foreach ($caches as $cache) {
         $cache_id = $cache['cache_id'];
         // usuniecie falszywych ocen
         //echo "cache_logs.cache_id=".sql_escape($rs['cache_id']).", user.username="******"<br />";
         //$sql = "DELETE FROM scores WHERE cache_id = '".sql_escape($rs['cache_id'])."' AND user_id = '".sql_escape($rs['user_id'])."'";
         //mysql_query($sql);
         $db->multiVariableQuery("delete from scores where cache_id = :1 and user_id not in (\n                    select user_id from cache_logs where deleted=0 and cache_id = :2\n                )", $cache_id, $cache_id);
         // zliczenie ocen po usunieciu
         $db->multiVariableQuery("SELECT avg(score) as avg_score, count(score) as votes FROM scores WHERE cache_id = :1", $cache_id);
         $row = $db->dbResultFetch();
         if ($row == false) {
             $liczba = 0;
             $srednia = 0;
         } else {
             $liczba = $row['votes'];
             if ($liczba > 0) {
                 $srednia = round($row['avg_score'], 4);
             } else {
                 $srednia = 0;
             }
         }
         unset($row);
         $db->closeCursor();
         // repair founds
         $founds = $db->multiVariableQueryValue("SELECT count(*) FROM cache_logs WHERE deleted=0 AND cache_id = :1 AND (type=1 OR type=7)", 0, $cache_id);
         $notfounds = $db->multiVariableQueryValue("SELECT count(*) FROM cache_logs WHERE deleted=0 AND cache_id = :1 AND (type=2 OR type=8)", 0, $cache_id);
         $notes = $db->multiVariableQueryValue("SELECT count(*) FROM cache_logs WHERE deleted=0 AND cache_id = :1 AND type=3", 0, $cache_id);
         $watchers = $db->multiVariableQueryValue("SELECT count(*) FROM cache_watches WHERE cache_id = :1", 0, $cache_id);
         $ignorers = $db->multiVariableQueryValue("SELECT count(*) FROM cache_ignore WHERE cache_id = :1", 0, $cache_id);
         $sql = "\n                UPDATE caches\n                SET\n                    votes=:new_votes,\n                    score=:new_score,\n                    founds=:new_founds,\n                    notfounds=:new_notfounds,\n                    notes=:new_notes,\n                    watcher=:new_watchers,\n                    ignorer_count=:new_ignorers\n                WHERE\n                    cache_id=:cache_id\n                    AND (\n                        votes is null\n                        OR score is null\n                        OR founds is null\n                        OR notfounds is null\n                        OR notes is null\n                        OR watcher is null\n                        OR ignorer_count is null\n                        OR votes!=:new_votes\n                        OR abs(score-:new_score)>0.0001\n                        OR founds!=:new_founds\n                        OR notfounds!=:new_notfounds\n                        OR notes!=:new_notes\n                        OR watcher!=:new_watchers\n                        OR ignorer_count!=:new_ignorers\n                    )\n            ";
         $params = array();
         $params['new_votes']['value'] = intval($liczba);
         $params['new_votes']['data_type'] = 'integer';
         $params['new_score']['value'] = strval($srednia);
         $params['new_score']['data_type'] = 'string';
         $params['new_founds']['value'] = intval($founds);
         $params['new_founds']['data_type'] = 'integer';
         $params['new_notfounds']['value'] = intval($notfounds);
         $params['new_notfounds']['data_type'] = 'integer';
         $params['new_notes']['value'] = intval($notes);
         $params['new_notes']['data_type'] = 'integer';
         $params['new_watchers']['value'] = intval($watchers);
         $params['new_watchers']['data_type'] = 'integer';
         $params['new_ignorers']['value'] = intval($ignorers);
         $params['new_ignorers']['data_type'] = 'integer';
         $params['cache_id']['value'] = intval($cache_id);
         $params['cache_id']['data_type'] = 'integer';
         $db->paramQuery($sql, $params);
         if ($db->rowCount() > 0) {
             echo "<b>cache_id={$cache_id}</b><br>";
             echo "ratings={$liczba}<br>rating={$srednia}<br>";
             echo "founds={$founds}<br>notfounds={$notfounds}<br>";
             echo "notes={$notes}<br>watchers={$watchers}<br>";
             echo "ignorers={$ignorers}<br>";
             $total_touched++;
         }
         $db->closeCursor();
     }
     set_time_limit(60);
     unset($db);
     echo "-----------------------------------<br>total_touched={$total_touched}<br>";
 }
Example #14
0
     $stmp = '<option value="XX" selected="selected">' . $no_answer . '</option>';
 } else {
     $stmp = '<option value="XX">' . $no_answer . '</option>';
 }
 if (isset($_POST['submit_all_countries'])) {
     $show_all_countries = 1;
 }
 if (checkField('countries', 'list_default_' . $lang)) {
     $lang_db = $lang;
 } else {
     $lang_db = "en";
 }
 //Country in defaults ?
 if ($show_all_countries == 0 && $country != 'XX') {
     $db->multiVariableQuery("SELECT `list_default_" . sql_escape($lang_db) . "` FROM `countries` WHERE `short`=:1", $country);
     $record2 = $db->dbResultFetch();
     if ($record2['list_default_' . $lang_db] == 0) {
         $show_all_countries = 1;
     } else {
         $show_all_countries = 0;
     }
     $db->reset();
 }
 if ($show_all_countries == 1) {
     $rs2 = sql("SELECT `&1`, `list_default_" . sql_escape($lang_db) . "`, `short`, `sort_" . sql_escape($lang_db) . "` FROM `countries` ORDER BY `sort_" . sql_escape($lang_db) . '` ASC', $lang_db);
 } else {
     $rs2 = sql("SELECT `&1`, `list_default_" . sql_escape($lang_db) . "`, `short`, `sort_" . sql_escape($lang_db) . "` FROM `countries` WHERE `list_default_" . sql_escape($lang_db) . "`=1 ORDER BY `sort_" . sql_escape($lang_db) . '` ASC', $lang_db);
 }
 for ($i = 0; $i < mysql_num_rows($rs2); $i++) {
     $record2 = sql_fetch_array($rs2);
     if ($record2['short'] == $country) {
 //$notes_rs = sql("SELECT `cache_notes`.`cache_id` `cacheid`, `caches`.`name` `cache_name`, `cache_type`.`icon_small` `icon_large` FROM `cache_notes` INNER JOIN caches ON (`caches`.`cache_id` = `cache_notes`.`cache_id`), `cache_type`  WHERE `cache_notes`.`user_id`=&1 AND `cache_type`.`id`=`caches`.`type` GROUP BY `cacheid` ORDER BY `cacheid`,`date` DESC",$userid);
 $query = "\n                            SELECT `cache_notes`.`cache_id` `cacheid`,\n                                `cache_notes`.`desc` `notes_desc`,\n                                `caches`.`name` `cache_name`,\n                                `cache_type`.`icon_small` `icon_large`,\n                                `caches`.`type` `cache_type`,\n                                `caches`.`cache_id` `cache_id`,\n                                `caches`.`user_id` `user_id`,\n                                note_id,\n                                cl.text AS log_text,\n                                cl.type AS log_type,\n                                cl.user_id AS luser_id,\n                                cl.date AS log_date,\n                                cl.deleted AS log_deleted,\n                                log_types.icon_small AS icon_small,\n                                user.username AS user_name,\n                                cache_mod_cords.id as cache_mod_cords_id,\n                                cache_mod_cords.longitude,\n                                cache_mod_cords.latitude\n                            FROM\n                                `cache_notes`\n                                INNER JOIN `caches` ON (`cache_notes`.`cache_id`=`caches`.`cache_id`)\n                                INNER JOIN cache_type ON (caches.type = cache_type.id)\n                                left outer JOIN cache_logs as cl ON (caches.cache_id = cl.cache_id)\n                                left outer JOIN log_types ON (cl.type = log_types.id)\n                                left outer JOIN user ON (cl.user_id = user.user_id)\n                                left outer JOIN cache_mod_cords ON (\n                                        cache_mod_cords.user_id = cache_notes.user_id\n                                        AND cache_mod_cords.cache_id = cache_notes.cache_id\n                                    )\n                            WHERE\n                                `cache_notes`.`user_id`=:1\n                                AND `cache_type`.`id`=`caches`.`type`\n                                AND\n                                    ( cl.id is null or cl.id =\n                                    ( SELECT id\n                                        FROM cache_logs cl_id\n                                        WHERE cl.cache_id = cl_id.cache_id and cl_id.date =\n\n                                            ( SELECT max( cache_logs.date )\n                                                FROM cache_logs\n                                                WHERE cl.cache_id = cache_id\n                                            )\n                                            limit 1\n                                        ))\n                            GROUP BY `cacheid`\n                            UNION\n                            SELECT `cache_mod_cords`.`cache_id` `cacheid`,\n                                `cache_notes`.`desc` `notes_desc`,\n                                `caches`.`name` `cache_name`,\n                                `cache_type`.`icon_small` `icon_large`,\n                                `caches`.`type` `cache_type`,\n                                `caches`.`cache_id` `cache_id`,\n                                `caches`.`user_id` `user_id`,\n                                note_id,\n                                cl.text AS log_text,\n                                cl.type AS log_type,\n                                cl.user_id AS luser_id,\n                                cl.date AS log_date,\n                                cl.deleted AS log_deleted,\n                                log_types.icon_small AS icon_small,\n                                user.username AS user_name,\n                                cache_mod_cords.id as cache_mod_cords_id,\n                                cache_mod_cords.longitude,\n                                cache_mod_cords.latitude\n                            FROM\n                                cache_mod_cords\n                                INNER JOIN `caches` ON (`cache_mod_cords`.`cache_id`=`caches`.`cache_id`)\n                                INNER JOIN cache_type ON (caches.type = cache_type.id)\n                                left outer JOIN cache_logs as cl ON (caches.cache_id = cl.cache_id)\n                                left outer JOIN log_types ON (cl.type = log_types.id)\n                                left outer JOIN user ON (cl.user_id = user.user_id)\n                                left outer JOIN cache_notes ON (\n                                        cache_notes.user_id = cache_mod_cords.user_id\n                                        AND cache_notes.cache_id = cache_mod_cords.cache_id\n                                    )\n                            WHERE\n                                `cache_mod_cords`.`user_id`=:1\n                                AND `cache_type`.`id`=`caches`.`type`\n                                AND\n                                    ( cl.id is null or cl.id =\n                                    ( SELECT id\n                                        FROM cache_logs cl_id\n                                        WHERE cl.cache_id = cl_id.cache_id and cl_id.date =\n\n                                            ( SELECT max( cache_logs.date )\n                                                FROM cache_logs\n                                                WHERE cl.cache_id = cache_id\n                                            )\n                                            limit 1\n                                        ))\n                            GROUP BY `cacheid`\n                            ORDER BY `cache_name`, log_date DESC";
 $db->multiVariableQuery($query, $userid);
 //if (mysql_num_rows($notes_rs) != 0)
 $count = $db->rowCount();
 if ($count != 0) {
     //$notes = '<table border="0" cellspacing="2" cellpadding="1" style="margin-left: 10px; line-height: 1.4em; font-size: 13px;" width="95%">';
     //$notes .= '<tr><td width="22">&nbsp;</td><td><strong>GeoCache</strong></td></tr><tr><td colspan="2"><hr></hr></td></tr>';
     $notes = "";
     $bgcolor1 = '#ffffff';
     $bgcolor2 = '#eeeeee';
     //for ($i = 0; $i < mysql_num_rows($notes_rs); $i++)
     for ($i = 0; $i < $count; $i++) {
         $bgcolor = $i % 2 ? $bgcolor1 : $bgcolor2;
         //$notes_record = sql_fetch_array($notes_rs);
         $notes_record = $db->dbResultFetch();
         $cacheicon = myninc::checkCacheStatusByUser($notes_record, $usr['userid']);
         $user_coords = '&nbsp;';
         if ($notes_record['latitude'] != null && $notes_record['longitude'] != null) {
             $user_coords = mb_ereg_replace(" ", "&nbsp;", htmlspecialchars(help_latToDegreeStr($notes_record['latitude'], 1), ENT_COMPAT, 'UTF-8')) . '&nbsp;' . mb_ereg_replace(" ", "&nbsp;", htmlspecialchars(help_lonToDegreeStr($notes_record['longitude'], 1), ENT_COMPAT, 'UTF-8'));
             $user_coords .= '&nbsp;<a class="links"  href="mycache_notes.php?delete_coords=' . $notes_record['cache_mod_cords_id'] . '" onclick="return confirm(\'' . tr('coordsmod_info_02') . '\');"><img style="vertical-align: middle;" src="tpl/stdstyle/images/log/16x16-trash.png" title=' . tr('reset_coords') . ' /></a>';
         }
         $delete_user_note = '&nbsp;';
         if ($notes_record['notes_desc'] != null) {
             $delete_user_note = '<a class="links"  href="mycache_notes.php?delete={noteid}" onclick="return confirm(\'' . tr("mycache_notes_01") . '\');"><img style="vertical-align: middle;" src="tpl/stdstyle/images/log/16x16-trash.png" alt="" title=' . tr('delete') . ' /></a>';
         }
         $notes .= '<tr>
                         <td style="background-color: {bgcolor}"><img src="' . $cacheicon . '" alt="" /></td>
                         <td align="left"  style="background-color: {bgcolor}"><a  href="viewcache.php?cacheid={cacheid}" onmouseover="if (\'{notes_text}\' != \'\') Tip(\'{notes_text}\', OFFSETY, 25, OFFSETX, -135, PADDING,5, WIDTH,280,SHADOW,true)" onmouseout="UnTip()">' . $notes_record['cache_name'] . '</a></td>
                         <td style="background-color: {bgcolor}">&nbsp;</td>
                         <td nowrap style="background-color: {bgcolor}">' . $user_coords . '</td>
Example #16
0
    tpl_set_var('blogDisplay', 'none');
}
/////////////////////////////////////////////////////
//Titled Caches
///////////////////////////////////////////////////
$usrid = -1;
$TitledCaches = "";
$dbc = new dataBase();
if ($usr != false) {
    $usrid = $usr['userid'];
}
$query = "SELECT caches.cache_id, caches.name cacheName, adm1 cacheCountry, adm3 cacheRegion, caches.type cache_type, \n        caches.user_id, user.username userName, cache_titled.date_alg, cache_logs.text, cache_desc.short_desc,\n        logUser.user_id logUserId, logUser.username logUserName\nFROM cache_titled\nJOIN caches ON cache_titled.cache_id = caches.cache_id\nJOIN cache_desc ON caches.cache_id = cache_desc.cache_id and language=:1\nJOIN cache_location ON caches.cache_id = cache_location.cache_id\nJOIN user ON caches.user_id = user.user_id\n        \nJOIN cache_logs ON cache_logs.id = cache_titled.log_id \nJOIN user logUser ON logUser.user_id = cache_logs.user_id\n               \nORDER BY date_alg DESC \nLIMIT 1";
$dbc->multiVariableQuery($query, $lang);
$pattern = "<span style='font-size:13px'><img src='{cacheIcon}' class='icon16' alt='Cache' title='Cache' />\n        <a href='viewcache.php?cacheid={cacheId}'><b>{cacheName}</b></a></span> \n        \n        <span style='font-size:11px'> " . tr('hidden_by') . "</span>\n        <span style='font-size:13px'><a href='viewprofile.php?userid={userId}'><b>{userName}</b></a></span><br>\n                \n        <span style='font-size:11px;font-style:italic'>{cacheShortDesc}</span><br>\n                \n        <span class='content-title-noshade' style='font-size:11px'>{country} > {region}</span>\n        <br><br>        \n        <table class='CacheTitledLog' >\n                <tr><td>{logText}\n                <br><br><img src='images/rating-star.png'/> Autor: <a href='viewprofile.php?userid={logUserId}'><b>{logUserName}<b></a></td></tr>\n        </table>";
for ($i = 0; $i < $dbc->rowCount(); $i++) {
    $rec = $dbc->dbResultFetch();
    $line = $pattern;
    $line = mb_ereg_replace('{cacheIcon}', myninc::checkCacheStatusByUser($rec, $usrid), $line);
    $line = mb_ereg_replace('{dateAlg}', $rec["date_alg"], $line);
    $line = mb_ereg_replace('{cacheName}', $rec["cacheName"], $line);
    $line = mb_ereg_replace('{userId}', $rec["user_id"], $line);
    $line = mb_ereg_replace('{userName}', $rec["userName"], $line);
    $line = mb_ereg_replace('{cacheId}', $rec["cache_id"], $line);
    $line = mb_ereg_replace('{country}', $rec["cacheCountry"], $line);
    $line = mb_ereg_replace('{region}', $rec["cacheRegion"], $line);
    $line = mb_ereg_replace('{cacheShortDesc}', $rec["short_desc"], $line);
    $line = mb_ereg_replace('{logUserId}', $rec["logUserId"], $line);
    $line = mb_ereg_replace('{logUserName}', $rec["logUserName"], $line);
    $text = mb_ereg_replace('<p>', '', $rec["text"]);
    $text = mb_ereg_replace('</p>', '<br>', $text);
    $line = mb_ereg_replace('{logText}', $text, $line);
Example #17
0
 $dbc = new dataBase();
 //get all caches ignored
 //$rs = mysql_query('SELECT `cache_ignore`.`cache_id` AS `cache_id`, `caches`.`name` AS `name`, `caches`.`last_found` AS `last_found` FROM `cache_ignore` INNER JOIN `caches` ON (`cache_ignore`.`cache_id` = `caches`.`cache_id`) WHERE `cache_ignore`.`user_id`=\'' . addslashes($usr['userid']) . '\' ORDER BY `caches`.`name`', $dblink);
 $query = "SELECT `cache_ignore`.`cache_id` AS `cache_id`, `caches`.`name` AS `name`, `caches`.`last_found` AS `last_found` FROM `cache_ignore` INNER JOIN `caches` ON (`cache_ignore`.`cache_id` = `caches`.`cache_id`) WHERE `cache_ignore`.`user_id`= :1 ORDER BY `caches`.`name`";
 $dbc->multiVariableQuery($query, $usr['userid']);
 $rowCount = $dbc->rowCount();
 if ($rowCount == 0) {
     tpl_set_var('no_ignores', $no_ignores);
     tpl_set_var('ignores_caches', '');
     tpl_set_var('title_text_tab', '');
 } else {
     //tpl_set_var('title_text_tab', $title_text_lbl);
     tpl_set_var('no_ignores', '');
     $ignores = '';
     for ($i = 0; $i < $rowCount; $i++) {
         $record = $dbc->dbResultFetch();
         //$tmp_ignore = $i % 2 == 0 ? $ignoree : $ignoreo;
         $bgcolor = $i % 2 ? $bgcolor1 : $bgcolor2;
         $tmp_ignore = $ignore;
         $tmp_ignore = str_replace('{cachename}', htmlspecialchars($record['name']), $tmp_ignore);
         if ($record['last_found'] == NULL || $record['last_found'] == '0000-00-00 00:00:00') {
             $tmp_ignore = str_replace('{lastfound}', htmlspecialchars($no_found_date), $tmp_ignore);
         } else {
             $tmp_ignore = str_replace('{lastfound}', htmlspecialchars(strftime($dateformat, strtotime($record['last_found']))), $tmp_ignore);
         }
         $tmp_ignore = str_replace('{urlencode_cacheid}', htmlspecialchars(urlencode($record['cache_id'])), $tmp_ignore);
         $tmp_ignore = str_replace('{cacheid}', htmlspecialchars($record['cache_id']), $tmp_ignore);
         $tmp_ignore = mb_ereg_replace('{bgcolor}', $bgcolor, $tmp_ignore);
         $ignores .= $tmp_ignore . "\n";
     }
     tpl_set_var('ignores_caches', $ignores);
Example #18
0
     $pages .= '<a href="newlogs.php?start=' . ($start + $LOGS_PER_PAGE) . '">{next_img}</a> ';
     $pages .= '<a href="newlogs.php?start=' . ($i - 1) * $LOGS_PER_PAGE . '">{last_img}</a> ';
 } else {
     $pages .= ' {next_img_inactive} {last_img_inactive}';
 }
 $rsQuery = "SELECT `cache_logs`.`id` FROM `cache_logs` USE INDEX(date_created), `caches`\n            WHERE `cache_logs`.`cache_id`=`caches`.`cache_id`\n            AND `cache_logs`.`deleted`=0\n            AND `caches`.`status` IN (1, 2, 3)\n            ORDER BY  `cache_logs`.`date_created` DESC\n            LIMIT :variable1, :variable2 ";
 $db->paramQuery($rsQuery, array('variable1' => array('value' => intval($start), 'data_type' => 'integer'), 'variable2' => array('value' => intval($LOGS_PER_PAGE), 'data_type' => 'integer')));
 $log_ids = '';
 if ($db->rowCount() == 0) {
     $log_ids = '0';
 }
 //powertrail vel geopath variables
 $pt_cache_intro_tr = tr('pt_cache');
 $pt_icon_title_tr = tr('pt139');
 for ($i = 0; $i < $db->rowCount(); $i++) {
     $record = $db->dbResultFetch();
     if ($i > 0) {
         $log_ids .= ', ' . $record['id'];
     } else {
         $log_ids = $record['id'];
     }
 }
 $rsQuery = "SELECT cache_logs.id, cache_logs.cache_id AS cache_id,\n                  cache_logs.type AS log_type,\n                  cache_logs.date AS log_date,\n                 `cache_logs`.`encrypt` `encrypt`,\n                  cache_logs.user_id AS luser_id,\n                  cache_logs.text AS log_text,\n                  cache_logs.text_html AS text_html,\n                  caches.name AS cache_name,\n                  caches.user_id AS cache_owner,\n                  user.username AS user_name,\n                  caches.user_id AS user_id,\n                  user.user_id AS xuser_id,\n                  caches.wp_oc AS wp_name,\n                  caches.type AS cache_type,\n                  cache_type.icon_small AS cache_icon_small,\n                  log_types.icon_small AS icon_small,\n                  log_types.pl as pl,\n                  IF(ISNULL(`cache_rating`.`cache_id`), 0, 1) AS `recommended`,\n                  COUNT(gk_item.id) AS geokret_in,\n                 `PowerTrail`.`id` AS PT_ID,\n                 `PowerTrail`.`name` AS PT_name,\n                 `PowerTrail`.`type` As PT_type,\n                 `PowerTrail`.`image` AS PT_image\n                  FROM (cache_logs INNER JOIN caches ON (caches.cache_id = cache_logs.cache_id)) INNER JOIN user ON (cache_logs.user_id = user.user_id) INNER JOIN log_types ON (cache_logs.type = log_types.id) INNER JOIN cache_type ON (caches.type = cache_type.id) LEFT JOIN `cache_rating` ON `cache_logs`.`cache_id`=`cache_rating`.`cache_id` AND `cache_logs`.`user_id`=`cache_rating`.`user_id`\n                  LEFT JOIN gk_item_waypoint ON gk_item_waypoint.wp = caches.wp_oc\n                  LEFT JOIN gk_item ON gk_item.id = gk_item_waypoint.id AND\n\n                  gk_item.stateid<>1 AND gk_item.stateid<>4 AND gk_item.typeid<>2 AND gk_item.stateid !=5\n                  LEFT JOIN `powerTrail_caches` ON cache_logs.cache_id = `powerTrail_caches`.`cacheId`\n                  LEFT JOIN `PowerTrail` ON `PowerTrail`.`id` = `powerTrail_caches`.`PowerTrailId`  AND `PowerTrail`.`status` = 1\n                  WHERE cache_logs.deleted=0 AND cache_logs.id IN ({$log_ids}) AND cache_logs.cache_id=caches.cache_id AND caches.status<> 4 AND caches.status<> 5 AND caches.status<> 6\n                  GROUP BY cache_logs.id\n                  ORDER BY cache_logs.date_created DESC";
 $file_content = '';
 $tr_myn_click_to_view_cache = tr('myn_click_to_view_cache');
 $bgColor = '#eeeeee';
 $db->simpleQuery($rsQuery);
 for ($i = 0; $i < $db->rowCount(); $i++) {
     if ($bgColor == '#eeeeee') {
         $bgColor = '#ffffff';
     } else {
     tpl_redirect('login.php?target=' . $target);
 } else {
     $tplname = 'confirmCacheCandidate';
     tpl_set_var('ptYes', 'none');
     tpl_set_var('ptNo', 'none');
     tpl_set_var('hack', 'none');
     tpl_set_var('ptName', '');
     tpl_set_var('noRecord', 'none');
     tpl_set_var('ptId', '');
     // check if logged user is a cache owner
     $code = $_REQUEST['code'];
     $ownerDecision = (int) $_REQUEST['result'];
     $query = 'SELECT * FROM `PowerTrail_cacheCandidate`, caches WHERE `link` = :1 AND PowerTrail_cacheCandidate.CacheId = caches.cache_id';
     $db = new dataBase();
     $db->multiVariableQuery($query, $code);
     $dbData = $db->dbResultFetch();
     if ($dbData === false) {
         // record not found
         tpl_set_var('noRecord', 'block');
     } else {
         $ptData = powerTrailBase::getPtDbRow($dbData['PowerTrailId']);
         tpl_set_var('ptName', $ptData['name']);
         tpl_set_var('ptId', $dbData['PowerTrailId']);
         if ($usr['userid'] == $dbData['user_id']) {
             // go on
             if ($ownerDecision === 0) {
                 // just remove cache from candidate table
                 removeDbEntery($code);
                 tpl_set_var('ptNo', 'block');
             }
             if ($ownerDecision === 1) {
}
$distance_unit = 'km';
$sql = 'SELECT ';
if (isset($lat_rad) && isset($lon_rad)) {
    if ($CalcDistance) {
        $sql .= getCalcDistanceSqlFormula($usr !== false, $lon_rad * 180 / 3.14159, $lat_rad * 180 / 3.14159, 0, $multiplier[$distance_unit]) . ' `distance`, ';
    }
} else {
    if ($usr === false) {
        if ($CalcDistance) {
            $sql .= '0 distance, ';
        }
    } elseif ($CalcDistance) {
        //get the users home coords
        $dbc->multiVariableQuery("SELECT `latitude`, `longitude` FROM `user` WHERE `user_id`=:1", $usr['userid']);
        $record_coords = $dbc->dbResultFetch();
        if ($record_coords['latitude'] == NULL || $record_coords['longitude'] == NULL || ($record_coords['latitude'] == 0 || $record_coords['longitude'] == 0)) {
            $sql .= '0 distance, ';
        } else {
            //TODO: load from the users-profile
            $distance_unit = 'km';
            $lon_rad = $record_coords['longitude'] * 3.14159 / 180;
            $lat_rad = $record_coords['latitude'] * 3.14159 / 180;
            $sql .= getCalcDistanceSqlFormula($usr !== false, $record_coords['longitude'], $record_coords['latitude'], 0, $multiplier[$distance_unit]) . ' `distance`, ';
        }
        $dbc->reset();
    }
}
$sql .= '   `caches`.`name` `name`, `caches`.`status` `status`, `caches`.`wp_oc` `wp_oc`,
                `caches`.`difficulty` `difficulty`, `caches`.`terrain` `terrain`, `caches`.`desc_languages` `desc_languages`,
                `caches`.`date_created` `date_created`, `caches`.`type` `cache_type`, `caches`.`cache_id` `cache_id`,