Esempio n. 1
0
            sql("INSERT INTO `removed_objects` (`localID`, `uuid`, `type`, `removed_date`, `node`) VALUES ('&1', '&2', 6, NOW(), '&3')", $localid, $uuid, $oc_nodeid);
            switch ($type) {
                // log
                case 1:
                    sql("UPDATE `cache_logs` SET `mp3count`=`mp3count`-1 WHERE `id`='&1'", $objectid);
                    $rs = sql("SELECT `cache_id` FROM `cache_logs` WHERE `deleted`=0 AND `id`='&1'", $objectid);
                    $r = sql_fetch_array($rs);
                    mysql_free_result($rs);
                    tpl_redirect('viewlogs.php?cacheid=' . urlencode($r['cache_id']));
                    break;
                    // cache
                // cache
                case 2:
                    sql("UPDATE `caches` SET `mp3count`=`mp3count`-1 WHERE `cache_id`='&1'", $objectid);
                    tpl_redirect('editcache.php?cacheid=' . urlencode($objectid));
                    break;
            }
            tpl_redirect('index.php');
            exit;
        } else {
            $tplname = 'message';
            tpl_set_var('messagetitle', $message_title_internal);
            tpl_set_var('message_start', '');
            tpl_set_var('message_end', '');
            tpl_set_var('message', $message_internal);
        }
    }
}
//make the template and send it out
tpl_BuildTemplate();
Esempio n. 2
0
function tpl_errorMsg($tplnameError, $msg)
{
    global $tplname;
    $tplname = 'error';
    tpl_set_var('error_msg', $msg);
    tpl_set_var('tplname', $tplnameError);
    tpl_BuildTemplate();
    exit;
}
 public function endzik()
 {
     tpl_BuildTemplate();
     exit;
 }
Esempio n. 4
0
$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);
    $TitledCaches .= $line;
}
$is_titled = $dbc->rowCount() ? '1' : '0';
if ($is_titled == '0') {
    $TitledCaches = '';
}
tpl_set_var('TitledCaches', $TitledCaches);
tpl_set_var('is_titled', $is_titled);
unset($dbc);
//make the template and send it out
tpl_BuildTemplate(false);
//not neccessary, call tpl_BuildTemplate with true as argument and the db will be closed there
db_disconnect();
Esempio n. 5
0
function outputLocidSelectionForm($locSql, $urlparams)
{
    global $tplname, $locline, $stylepath, $bgcolor1, $bgcolor2;
    require_once $stylepath . '/selectlocid.inc.php';
    unset($urlparams['queryid']);
    unset($urlparams['locid']);
    $urlparams['searchto'] = 'search' . $urlparams['searchtype'];
    unset($urlparams['searchtype']);
    $tplname = 'selectlocid';
    // urlparams zusammenbauen
    $urlparamString = '';
    foreach ($urlparams as $name => $param) {
        // workaround for attribs
        if (is_array($param)) {
            $pnew = '';
            foreach ($param as $p) {
                if ($pnew != '') {
                    $pnew .= ';' . $p;
                } else {
                    $pnew .= $p;
                }
            }
            $param = $pnew;
        }
        if ($urlparamString != '') {
            $urlparamString .= '&' . $name . '=' . urlencode($param);
        } else {
            $urlparamString = $name . '=' . urlencode($param);
        }
    }
    $urlparamString .= '&locid={locid}';
    sql('CREATE TEMPORARY TABLE `locids` ENGINE=MEMORY ' . $locSql);
    sql('ALTER TABLE `locids` ADD PRIMARY KEY (`loc_id`)');
    $rs = sql('SELECT `geodb_textdata`.`loc_id` `loc_id`, `geodb_textdata`.`text_val` `text_val` FROM `geodb_textdata`, `locids` WHERE `locids`.`loc_id`=`geodb_textdata`.`loc_id` AND `geodb_textdata`.`text_type`=500100000 ORDER BY `text_val`');
    $nr = 1;
    $locations = '';
    while ($r = sql_fetch_array($rs)) {
        $thislocation = $locline;
        // locationsdings zusammenbauen
        $locString = '';
        $land = landFromLocid($r['loc_id']);
        if ($land != '') {
            $locString .= htmlspecialchars($land, ENT_COMPAT, 'UTF-8');
        }
        $rb = regierungsbezirkFromLocid($r['loc_id']);
        if ($rb != '') {
            $locString .= ' &gt; ' . htmlspecialchars($rb, ENT_COMPAT, 'UTF-8');
        }
        $lk = landkreisFromLocid($r['loc_id']);
        if ($lk != '') {
            $locString .= ' &gt; ' . htmlspecialchars($lk, ENT_COMPAT, 'UTF-8');
        }
        $thislocation = mb_ereg_replace('{parentlocations}', $locString, $thislocation);
        // koordinaten ermitteln
        $r['loc_id'] = $r['loc_id'] + 0;
        $rsCoords = sql('SELECT `lon`, `lat` FROM `geodb_coordinates` WHERE loc_id=' . $r['loc_id'] . ' LIMIT 1');
        if ($rCoords = sql_fetch_array($rsCoords)) {
            $coordString = help_latToDegreeStr($rCoords['lat']) . ' ' . help_lonToDegreeStr($rCoords['lon']);
        } else {
            $coordString = '[keine Koordinaten vorhanden]';
        }
        $thislocation = mb_ereg_replace('{coords}', htmlspecialchars($coordString, ENT_COMPAT, 'UTF-8'), $thislocation);
        $thislocation = mb_ereg_replace('{locationname}', htmlspecialchars($r['text_val'], ENT_COMPAT, 'UTF-8'), $thislocation);
        $thislocation = mb_ereg_replace('{urlparams}', $urlparamString, $thislocation);
        $thislocation = mb_ereg_replace('{locid}', urlencode($r['loc_id']), $thislocation);
        $thislocation = mb_ereg_replace('{nr}', $nr, $thislocation);
        $thislocation = mb_ereg_replace('{secondlocationname}', '', $thislocation);
        if ($nr % 2) {
            $thislocation = mb_ereg_replace('{bgcolor}', $bgcolor1, $thislocation);
        } else {
            $thislocation = mb_ereg_replace('{bgcolor}', $bgcolor2, $thislocation);
        }
        $nr++;
        $locations .= $thislocation . "\n";
    }
    tpl_set_var('locations', $locations);
    tpl_set_var('resultscount', mysql_num_rows($rs));
    tpl_set_var('pages', $first_img_inactive . ' ' . $prev_img_inactive . ' 1 ' . $next_img_inactive . ' ' . $last_img_inactive);
    tpl_BuildTemplate();
    exit;
}
Esempio n. 6
0
function savequery($queryid, $queryname, $saveas, $submit, $saveas_queryid)
{
    global $usr, $tplname;
    global $error_empty_name, $nosaveastext, $saveastext, $error_queryname_exists;
    $displayform = $submit == false;
    $error_no_name = false;
    $error_duplicate_name = false;
    // ok ... checken, ob die query uns gehört und dann speichern
    $rs = sql("SELECT `user_id` FROM `queries` WHERE `id`='&1' AND (`user_id`=0 OR `user_id`='&2')", $queryid, $usr['userid']);
    if (mysql_num_rows($rs) == 0) {
        echo 'fatal error: query not found or permission denied';
        exit;
    }
    mysql_free_result($rs);
    if ($saveas == false) {
        if ($displayform == false && $queryname == '') {
            $displayform = true;
            $error_no_name = true;
        } else {
            // prüfen ob name bereits vorhanden
            $rs = sql("SELECT COUNT(*) `c` FROM `queries` WHERE `user_id`='&1' AND `name`='&2'", $usr['userid'], $queryname);
            $r = sql_fetch_array($rs);
            mysql_free_result($rs);
            if ($r['c'] > 0) {
                $displayform = true;
                $error_duplicate_name = true;
            }
        }
    } else {
        if ($saveas_queryid == 0) {
            $displayform = true;
        } else {
            // prüfen ob saveas_queryid existiert und uns gehört
            $rs = sql("SELECT `user_id` FROM `queries` WHERE `id`='&1' AND (`user_id`=0 OR `user_id`='&2')", $saveas_queryid, $usr['userid']);
            if (mysql_num_rows($rs) == 0) {
                echo 'fatal error: saveas_query not found or permission denied';
                exit;
            }
            mysql_free_result($rs);
        }
    }
    if ($displayform == true) {
        // abfrageform für name
        $tplname = 'savequery';
        if ($error_no_name == true) {
            tpl_set_var('nameerror', $error_empty_name);
        } else {
            if ($error_duplicate_name == true) {
                tpl_set_var('nameerror', $error_queryname_exists);
            } else {
                tpl_set_var('nameerror', '');
            }
        }
        tpl_set_var('queryname', htmlspecialchars($queryname, ENT_COMPAT, 'UTF-8'));
        tpl_set_var('queryid', htmlspecialchars($queryid, ENT_COMPAT, 'UTF-8'));
        // oldqueries auslesen
        $options = '';
        $rs = sql("SELECT `id`, `name` FROM `queries` WHERE `user_id`='&1' ORDER BY `name` ASC", $usr['userid']);
        if (mysql_num_rows($rs) == 0) {
            tpl_set_var('selecttext', $nosaveastext);
            tpl_set_var('oldqueries', '');
        } else {
            tpl_set_var('selecttext', $saveastext);
            while ($r = sql_fetch_array($rs)) {
                if ($r['id'] == $queryid) {
                    $options .= '<option value="' . $r['id'] . '" selected="selected">' . htmlspecialchars($r['name'], ENT_COMPAT, 'UTF-8') . '</option>' . "\n";
                } else {
                    $options .= '<option value="' . $r['id'] . '">' . htmlspecialchars($r['name'], ENT_COMPAT, 'UTF-8') . '</option>' . "\n";
                }
            }
            mysql_free_result($rs);
            tpl_set_var('oldqueries', $options);
        }
        tpl_BuildTemplate();
        exit;
    }
    $rs = sql("SELECT `options` FROM `queries` WHERE `id`='&1'", $queryid);
    $r = sql_fetch_array($rs);
    mysql_free_result($rs);
    // ok, speichern
    if ($saveas == true) {
        sql("UPDATE `queries` SET `options`='&1', `last_queried`=NOW() WHERE `id`='&2'", $r['options'], $saveas_queryid);
    } else {
        sql("INSERT INTO `queries` (`user_id`, `last_queried`, `name`, `uuid`, `options`) VALUES ( '&1', NOW(), '&2', '&3', '&4')", $usr['userid'], $queryname, create_uuid(), $r['options']);
    }
    tpl_redirect('query.php?action=view');
}
Esempio n. 7
0
 /**
  * Call OKAPI, parse response and display the results
  * @param array $params - params of the cache to search and display
  */
 private function htmlFormat(array $params)
 {
     //call OKAPI
     $okapi_resp = \okapi\Facade::service_call('services/caches/shortcuts/search_and_retrieve', $this->user_id, $params);
     if (!is_a($okapi_resp, "ArrayObject")) {
         // strange OKAPI return !?
         error_log(__METHOD__ . ": ERROR: strange OKAPI response - not an ArrayObject");
         exit(0);
     }
     \okapi\OkapiErrorHandler::disable();
     if ($okapi_resp->count() == 0) {
         // no caches found
         exit(0);
     }
     // get the first object from the list
     $arrayCopy = $okapi_resp->getArrayCopy();
     $geoCache = new \lib\Objects\GeoCache\GeoCache(array('okapiRow' => array_pop($arrayCopy)));
     //generate the results
     if ($this->screenWidth < 400) {
         tpl_set_tplname('map/map_cacheinfo_small');
     } else {
         tpl_set_tplname('map/map_cacheinfo');
     }
     tpl_set_var('cache_lat', $geoCache->getCoordinates()->getLatitude());
     tpl_set_var('cache_lon', $geoCache->getCoordinates()->getLongitude());
     tpl_set_var('cache_name', $geoCache->getCacheName());
     tpl_set_var('cache_icon', $geoCache->getCacheIcon());
     $is_event = $geoCache->getCacheType() == $geoCache::TYPE_EVENT ? '1' : '0';
     // be aware: booleans not working here
     tpl_set_var('is_event', $is_event, false);
     $is_scored = $geoCache->getRatingId() != 0 && $geoCache->getRatingVotes() > 2 ? '1' : '0';
     tpl_set_var('is_scored', $is_scored, false);
     tpl_set_var('rating_desc', tr($geoCache->getRatingDesc()));
     $is_recommended = $geoCache->getRecommendations() > 0 ? '1' : '0';
     tpl_set_var('is_recommended', $is_recommended, false);
     tpl_set_var('cache_recommendations', $geoCache->getRecommendations(), false);
     tpl_set_var('cache_code', $geoCache->getWaypointId());
     tpl_set_var('cache_founds', $geoCache->getFounds());
     tpl_set_var('cache_not_founds', $geoCache->getNotFounds());
     tpl_set_var('cache_rating_votes', $geoCache->getRatingVotes());
     tpl_set_var('cache_willattends', $geoCache->getWillattends());
     tpl_set_var('cache_url', $geoCache->getCacheUrl());
     tpl_set_var('user_name', $geoCache->getOwner()->getUserName());
     tpl_set_var('user_profile', $geoCache->getOwner()->getProfileUrl());
     tpl_set_var('cache_size_desc', tr($geoCache->getSizeDesc()));
     $is_powertrail_part = $geoCache->isPowerTrailPart() ? '1' : '0';
     tpl_set_var('is_powertrail_part', $is_powertrail_part, false);
     if ($geoCache->isPowerTrailPart()) {
         tpl_set_var('pt_name', $geoCache->getPowerTrail()->getName());
         tpl_set_var('pt_image', $geoCache->getPowerTrail()->getImage());
         tpl_set_var('pt_icon', $geoCache->getPowerTrail()->getFootIcon());
         tpl_set_var('pt_url', $geoCache->getPowerTrail()->getPowerTrailUrl());
     }
     $is_titled = $geoCache->isTitled() ? 'true' : 'false';
     tpl_set_var('is_titled', $is_titled, false);
     //tpl_set_var('is_titled', $geoCache->isTitled(), false);
     // make the template and send it out
     tpl_BuildTemplate(false, false, true);
 }
 *
 * visualization of the search results:
 * @param searchdata + ... -
 *
 */
require_once './lib/common.inc.php';
require_once './lib/cachemap3_common.php';
//check if user logged in
handleUserLogged();
$tplname = 'cachemap-full';
// locate user for which map is displayed
$mapForUserObj = getMapUserObj();
tpl_set_var('userid', $mapForUserObj->getUserId());
// parse cords and zoom setings
parseCordsAndZoom($mapForUserObj);
// parse eventually printList changes
parsePrintList();
//parse PowerTrail filter in url
parsePowerTrailFilter(true);
//read from DB map settings and apply to the map
$filter = getDBFilter($usr['userid']);
//logged user or preview user?
setFilterSettings($filter);
//handle search-data - visualization of search results
parseSearchData();
tpl_set_var('username', $mapForUserObj->getUserName());
//actually not used in map-full now...
setTheRestOfCommonVars();
//...and lest run template in fullscrean mode...
tpl_BuildTemplate(true, true);
Esempio n. 9
0
function removelog($log_id, $language, $lang)
{
    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, $octeamEmailsSignature;
    $log_rs = sql("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`='&1'\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`='&2'\n                        AND `cache_logs`.`deleted` = &3\n                      AND `log_types`.`id`=`cache_logs`.`type`", $log_id, $lang, 0);
    //log exists?
    if (mysql_num_rows($log_rs) == 1) {
        $log_record = sql_fetch_array($log_rs);
        mysql_free_result($log_rs);
        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']) {
            if ($usr['admin'] && isset($_POST['userid'])) {
                $commit = 1;
            } else {
                $commit = isset($_REQUEST['commit']) ? $_REQUEST['commit'] : 0;
            }
            //we are the logger
            if ($log_record['log_user_id'] == $usr['userid']) {
                $tplname = 'removelog_logowner';
            } else {
                $tplname = 'removelog_cacheowner';
                if ($commit == 1) {
                    //send email to logowner schicken
                    $email_content = read_file($stylepath . '/email/removed_log.email');
                    $message = isset($_POST['logowner_message']) ? $_POST['logowner_message'] : '';
                    if ($message != '') {
                        //message to logowner
                        $message = $removed_message_title . "\n" . $message . "\n" . $removed_message_end;
                    }
                    //get cache owner name
                    $cache_owner_rs = sql("SELECT `username` FROM `user` WHERE `user_id`='&1'", $log_record['cache_owner_id']);
                    $cache_owner_record = sql_fetch_array($cache_owner_rs);
                    //get email address of logowner
                    $log_user_rs = sql("SELECT `email`, `username` FROM `user` WHERE `user_id`='&1'", $log_record['log_user_id']);
                    $log_user_record = sql_fetch_array($log_user_rs);
                    $email_content = mb_ereg_replace('{log_owner}', $log_user_record['username'], $email_content);
                    $email_content = mb_ereg_replace('{cache_owner}', $cache_owner_record['username'], $email_content);
                    $email_content = mb_ereg_replace('{cache_name}', $log_record['cache_name'], $email_content);
                    $email_content = mb_ereg_replace('{log_entry}', $log_record['log_text'], $email_content);
                    $email_content = mb_ereg_replace('{comment}', $message, $email_content);
                    $email_content = mb_ereg_replace('{removedLog_01}', tr('removedLog_01'), $email_content);
                    $email_content = mb_ereg_replace('{removedLog_02}', tr('removedLog_02'), $email_content);
                    $email_content = mb_ereg_replace('{removedLog_03}', tr('removedLog_03'), $email_content);
                    $email_content = mb_ereg_replace('{octeamEmailsSignature}', $octeamEmailsSignature, $email_content);
                    $email_content = mb_ereg_replace('{removedLog_04}', tr('removedLog_04'), $email_content);
                    //send email (only on single removement)
                    mb_send_mail($log_user_record['email'], $removed_log_title, $email_content, $emailheaders);
                }
            }
            if ($commit == 1) {
                // do not acually delete logs - just mark them as deleted.
                sql("UPDATE `cache_logs` SET deleted = 1, `del_by_user_id` =" . $usr['userid'] . " , `last_modified`=NOW(), `last_deleted`=NOW() WHERE `cache_logs`.`id`='&1' LIMIT 1", $log_id);
                recalculateUserStats($log_record['log_user_id']);
                // remove from cache_moved for log "MOVED" (mobilniaki by Łza)
                // (kod istniejący wcześniej, zaadaptowany)
                if ($log_record['log_type'] == 4) {
                    // jesli log jest ostatni - przywrocenie kordow z przedostatniego "przeniesiona"
                    $check_cml = sql("SELECT `latitude`,`longitude`,`id` FROM `cache_moved` WHERE `log_id`='&1'", $log_id);
                    if (mysql_num_rows($check_cml) != 0) {
                        $xy_log = sql_fetch_array($check_cml);
                        $check_cmc = sql("SELECT `latitude`,`longitude` FROM `caches` WHERE `cache_id`='&1'", $log_record['cache_id']);
                        if (mysql_num_rows($check_cmc) != 0) {
                            $xy_cache = sql_fetch_array($check_cmc);
                            if ($xy_cache['latitude'] == $xy_log['latitude'] && $xy_cache['longitude'] == $xy_log['longitude']) {
                                sql("DELETE FROM `cache_moved` WHERE `log_id`='&1' LIMIT 1", $log_id);
                                $get_xy = sql("SELECT `latitude`,`longitude` FROM `cache_moved` WHERE `cache_id`='&1' ORDER BY `date` DESC LIMIT 1", $log_record['cache_id']);
                                $old_xy = sql_fetch_array($get_xy);
                                if ($old_xy['longitude'] != '' && $old_xy['latitude'] != '') {
                                    sql("UPDATE `caches` SET `last_modified`=NOW(), `longitude`='&1', `latitude`='&2' WHERE `cache_id`='&3'", $old_xy['longitude'], $old_xy['latitude'], $log_record['cache_id']);
                                }
                            } else {
                                sql("DELETE FROM `cache_moved` WHERE `log_id`='&1' LIMIT 1", $log_id);
                            }
                        } else {
                            sql("DELETE FROM `cache_moved` WHERE `log_id`='&1' LIMIT 1", $log_id);
                        }
                    }
                }
                if ($log_record['log_type'] == 1 || $log_record['log_type'] == 7) {
                    // remove cache from users top caches, because the found log was deleted for some reason
                    sql("DELETE FROM `cache_rating` WHERE `user_id` = '&1' AND `cache_id` = '&2'", $log_record['log_user_id'], $log_record['cache_id']);
                    // Notify OKAPI's replicate module of the change.
                    // Details: https://github.com/opencaching/okapi/issues/265
                    require_once $rootpath . 'okapi/facade.php';
                    \okapi\Facade::schedule_user_entries_check($log_record['cache_id'], $log_record['log_user_id']);
                    \okapi\Facade::disable_error_handling();
                    // recalc scores for this cache
                    sql("DELETE FROM `scores` WHERE `user_id` = '&1' AND `cache_id` = '&2'", $log_record['log_user_id'], $log_record['cache_id']);
                    $sql = "SELECT count(*) FROM scores WHERE cache_id='" . sql_escape($log_record['cache_id']) . "'";
                    $liczba = mysql_result(mysql_query($sql), 0);
                    $sql = "SELECT SUM(score) FROM scores WHERE cache_id='" . sql_escape($log_record['cache_id']) . "'";
                    $suma = @mysql_result(@mysql_query($sql), 0) + 0;
                    // obliczenie nowej sredniej
                    if ($liczba != 0) {
                        $srednia = $suma / $liczba;
                    } else {
                        $srednia = 0;
                    }
                    $sql = "UPDATE caches SET votes='" . sql_escape($liczba) . "', score='" . sql_escape($srednia) . "' WHERE cache_id='" . sql_escape($log_record['cache_id']) . "'";
                    mysql_query($sql);
                }
                //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
                $cache_rs = sql("SELECT `founds`, `notfounds`, `notes` FROM `caches` WHERE `cache_id`='&1'", $log_record['cache_id']);
                $cache_record = sql_fetch_array($cache_rs);
                mysql_free_result($cache_rs);
                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
                $last_tmp = $log_record['cache_id'];
                $lastfound_rs = sql("SELECT MAX(`cache_logs`.`date`) AS `date` FROM `cache_logs` WHERE ((cache_logs.`type`=1) AND (cache_logs.`cache_id`='{$last_tmp}'))");
                $lastfound_record = sql_fetch_array($lastfound_rs);
                if ($lastfound_record['date'] === NULL) {
                    $lastfound = 'NULL';
                } else {
                    $lastfound = $lastfound_record['date'];
                }
                sql("UPDATE `caches` SET `last_found`='&1', `founds`='&2', `notfounds`='&3', `notes`='&4' WHERE `cache_id`='&5'", $lastfound, $cache_record['founds'], $cache_record['notfounds'], $cache_record['notes'], $log_record['cache_id']);
                unset($cache_record);
                if (!isset($_POST['userid'])) {
                    //cache anzeigen
                    $_GET['cacheid'] = $log_record['cache_id'];
                    $_REQUEST['cacheid'] = $log_record['cache_id'];
                    require 'viewcache.php';
                }
            } else {
                tpl_set_var('cachename', htmlspecialchars($log_record['cache_name'], ENT_COMPAT, 'UTF-8'));
                tpl_set_var('cacheid', htmlspecialchars($log_record['cache_id'], ENT_COMPAT, 'UTF-8'));
                tpl_set_var('logid_urlencode', htmlspecialchars(urlencode($log_id), ENT_COMPAT, 'UTF-8'));
                tpl_set_var('logid', htmlspecialchars($log_id, ENT_COMPAT, 'UTF-8'));
                $log = read_file($stylepath . '/viewcache_log.tpl.php');
                $log = mb_ereg_replace('{date}', htmlspecialchars(strftime("%d %B %Y", strtotime($log_record['log_date'])), ENT_COMPAT, 'UTF-8'), $log);
                if (isset($log_record['recommended']) && $log_record['recommended'] == 1) {
                    $log = mb_ereg_replace('{ratingimage}', $rating_picture, $log);
                } else {
                    $log = mb_ereg_replace('{ratingimage}', '', $log);
                }
                $log = mb_ereg_replace('{username}', htmlspecialchars($log_record['log_username'], ENT_COMPAT, 'UTF-8'), $log);
                $log = mb_ereg_replace('{userid}', htmlspecialchars($log_record['log_user_id'] + 0, ENT_COMPAT, 'UTF-8'), $log);
                tpl_set_var('log_user_name', htmlspecialchars($log_record['log_username'], ENT_COMPAT, 'UTF-8'));
                $log = mb_ereg_replace('{type}', htmlspecialchars($log_record['text_listing'], ENT_COMPAT, 'UTF-8'), $log);
                $log = mb_ereg_replace('{logimage}', icon_log_type($log_record['icon_small'], ""), $log);
                $log = mb_ereg_replace('{logfunctions}', '', $log);
                $log = mb_ereg_replace('{logpictures}', '', $log);
                $log = mb_ereg_replace('{logtext}', $log_record['log_text'], $log);
                $log = mb_ereg_replace('{username_aktywnosc}', '', $log);
                $log = mb_ereg_replace('{kordy_mobilniaka}', '', $log);
                tpl_set_var('log', $log);
                //make the template and send it out
                tpl_BuildTemplate();
            }
        } else {
            //TODO: hm ... no permission to remove the log
            d('no permission to remove the log');
        }
    } else {
        //TODO: log doesn't exist
        d('log doesn\'t exist');
    }
}