function run() { $db = new dataBase(); $db->switchDebug(false); $sql = "SELECT user_id FROM user where user_id >= 0 "; $params = array(); if (isset($_GET['user_id'])) { $sql .= ' and user_id=:user_id'; $params['user_id']['value'] = intval($_GET['user_id']); $params['user_id']['data_type'] = 'integer'; } $db->paramQuery($sql, $params); $users = $db->dbResultFetchAll(); set_time_limit(3600); $total_touched = 0; foreach ($users as $user) { $user_id = $user['user_id']; // repair founds $founds_count = $db->multiVariableQueryValue("SELECT count(id) FROM cache_logs WHERE deleted=0 AND user_id = :1 AND type=1", 0, $user_id); $notfounds_count = $db->multiVariableQueryValue("SELECT count(id) FROM cache_logs WHERE deleted=0 AND user_id = :1 AND type=2", 0, $user_id); $log_notes_count = $db->multiVariableQueryValue("SELECT count(id) FROM cache_logs WHERE deleted=0 AND user_id = :1 AND type=3", 0, $user_id); $cache_watches = $db->multiVariableQueryValue("SELECT count(id) FROM cache_watches WHERE user_id = :1", 0, $user_id); $cache_ignores = $db->multiVariableQueryValue("SELECT count(id) FROM cache_ignore WHERE user_id = :1", 0, $user_id); $hidden_count = $db->multiVariableQueryValue("select count(cache_id) from caches where status in (1,2,3) and user_id = :1", 0, $user_id); $sql = "\n UPDATE user\n SET\n hidden_count=:new_hidden_count,\n cache_ignores=:new_cache_ignores,\n log_notes_count=:new_log_notes_count,\n founds_count=:new_founds_count,\n notfounds_count=:new_notfounds_count,\n cache_watches=:new_cache_watches\n WHERE\n user_id=:user_id\n AND (\n hidden_count is null\n OR cache_ignores is null\n OR log_notes_count is null\n OR founds_count is null\n OR notfounds_count is null\n OR cache_watches is null\n OR hidden_count!=:new_hidden_count\n OR cache_ignores!=:new_cache_ignores\n OR log_notes_count!=:new_log_notes_count\n OR founds_count!=:new_founds_count\n OR notfounds_count!=:new_notfounds_count\n OR cache_watches!=:new_cache_watches\n )\n "; $params = array(); $params['new_hidden_count']['value'] = intval($hidden_count); $params['new_hidden_count']['data_type'] = 'integer'; $params['new_cache_ignores']['value'] = intval($cache_ignores); $params['new_cache_ignores']['data_type'] = 'integer'; $params['new_log_notes_count']['value'] = intval($log_notes_count); $params['new_log_notes_count']['data_type'] = 'integer'; $params['new_founds_count']['value'] = intval($founds_count); $params['new_founds_count']['data_type'] = 'integer'; $params['new_notfounds_count']['value'] = intval($notfounds_count); $params['new_notfounds_count']['data_type'] = 'integer'; $params['new_cache_watches']['value'] = intval($cache_watches); $params['new_cache_watches']['data_type'] = 'integer'; $params['user_id']['value'] = intval($user_id); $params['user_id']['data_type'] = 'integer'; $db->paramQuery($sql, $params); if ($db->rowCount() > 0) { echo "<b>user_id={$user_id}</b><br>"; echo "hidden_count={$hidden_count}<br>cache_ignores={$cache_ignores}<br>"; echo "log_notes_count={$log_notes_count}<br>founds_count={$founds_count}<br>"; echo "notfounds_count={$notfounds_count}<br>cache_watches={$cache_watches}<br>"; $total_touched++; } $db->closeCursor(); } set_time_limit(60); unset($db); echo "-----------------------------------<br>total_touched={$total_touched}<br>"; }
/** ===================================================================================== * 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; } }
if ($total_pages > $PAGES_LISTED) { $pages .= '<a href="mycaches.php?status=' . $stat_cache . '&start=' . ($i - 1) * $LOGS_PER_PAGE . '&col=' . $sort_col . '&sort=' . $sort_sort . '">{last_img}</a> '; } else { $pages .= '{last_img_inactive}'; } $caches_query = "\n SELECT\n `caches`.`cache_id`,\n `caches`.`name`,\n `date_hidden`,\n `status`,cache_type.icon_small AS cache_icon_small,\n `cache_status`.`id` AS `cache_status_id`,\n `caches`.`founds` AS `founds`,\n `caches`.`topratings` AS `topratings`,\n datediff(now(),`caches`.`last_found` ) as `ilosc_dni`,\n datediff(now(),`caches`.`last_modified` ) as `dni_od_zmiany`,\n COUNT(`gk_item`.`id`) AS `gkcount`,\n COALESCE(`cv`.`count`,0) AS `visits`\n FROM `caches`\n LEFT JOIN `gk_item_waypoint` ON `gk_item_waypoint`.`wp` = `caches`.`wp_oc`\n LEFT JOIN `gk_item`\n ON `gk_item`.`id` = `gk_item_waypoint`.`id`\n AND `gk_item`.`stateid`<>1\n AND `gk_item`.`stateid`<>4\n AND `gk_item`.`typeid`<>2\n AND `gk_item`.`stateid` <>5\n LEFT JOIN (\n SELECT\n `count`,\n `user_id_ip`,\n `cache_id`\n FROM `cache_visits`\n WHERE `user_id_ip`=0\n ) `cv`\n ON `caches`.`cache_id` = `cv`.`cache_id`\n INNER JOIN `cache_type` ON (`caches`.`type` = `cache_type`.`id`),\n `cache_status`\n WHERE\n `user_id`=:user_id\n AND `cache_status`.`id`=`caches`.`status`\n AND `caches`.`status` = :stat_cache\n GROUP BY `caches`.`cache_id`\n ORDER BY `{$sort_warunek}` {$sort_txt}\n LIMIT " . intval($start) . ", " . intval($LOGS_PER_PAGE); //$params['v1']['value'] = (string) $lang_db;; //$params['v1']['data_type'] = 'string'; $params['user_id']['value'] = (int) $user_id; $params['user_id']['data_type'] = 'integer'; $params['stat_cache']['value'] = (int) $stat_cache; $params['stat_cache']['data_type'] = 'integer'; if (!isset($dbc)) { $dbc = new dataBase(); } $dbc->paramQuery($caches_query, $params); unset($params); $log_record_all = $dbc->dbResultFetchAll(); $log_record_count = count($log_record_all); $file_content = ''; //while ($log_record=sql_fetch_assoc($rs)) //prepare second queryt $logs_query = "\n SELECT\n cache_logs.id,\n cache_logs.type AS log_type,\n cache_logs.text AS log_text,\n DATE_FORMAT(cache_logs.date,'%Y-%m-%d') AS log_date,\n caches.user_id AS cache_owner,\n cache_logs.encrypt encrypt,\n cache_logs.user_id AS luser_id,\n user.username AS user_name,\n user.user_id AS user_id,\n log_types.icon_small AS icon_small,\n datediff(now(),`cache_logs`.`date_created`) as `ilosc_dni`\n FROM\n cache_logs\n JOIN caches USING (cache_id)\n JOIN user ON (cache_logs.user_id=user.user_id)\n JOIN log_types ON (cache_logs.type = log_types.id)\n WHERE\n cache_logs.deleted=0 AND\n `cache_logs`.`cache_id`=:v1\n ORDER BY `cache_logs`.`date_created` DESC\n LIMIT 5"; $edit_geocache_tr = tr('mc_edit_geocache'); for ($zz = 0; $zz < $log_record_count; $zz++) { $log_record = $log_record_all[$zz]; $tabelka = ''; $tabelka .= '<td style="width: 90px;">' . htmlspecialchars(date($dateFormat, strtotime($log_record['date_hidden'])), ENT_COMPAT, 'UTF-8') . '</td>'; $tabelka .= '<td ><a href="editcache.php?cacheid=' . htmlspecialchars($log_record['cache_id'], ENT_COMPAT, 'UTF-8') . '"><img src="tpl/stdstyle/images/free_icons/pencil.png" alt="' . $edit_geocache_tr . '" title="' . $edit_geocache_tr . '"/></a></td>'; $tabelka .= '<td > <img src="tpl/stdstyle/images/' . $log_record['cache_icon_small'] . '" border="0" alt=""/></td>'; $tabelka .= '<td><b><a class="links" href="viewcache.php?cacheid=' . htmlspecialchars($log_record['cache_id'], ENT_COMPAT, 'UTF-8') . '">' . htmlspecialchars($log_record['name'], ENT_COMPAT, 'UTF-8') . '</a></b></td>';
for ($i = max(1, $startat); $i < $startat + $PAGES_LISTED; $i++) { $page_number = ($i - 1) * $LOGS_PER_PAGE; if ($page_number == $start) { $pages .= "<b>{$i}</b> "; } else { $pages .= "<a href='newlogs.php?start={$page_number}'>{$i}</a> "; } } if ($total_pages > $PAGES_LISTED) { $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']; } }
if (isGeokretInCache($cache_id)) { tpl_set_var('log_geokret', "<br /><img src=\"images/gk.png\" class=\"icon16\" alt=\"\" title=\"GeoKrety\" align=\"middle\" /> <b>" . tr('geokret_log') . " <a href='http://geokrety.org/ruchy.php'>geokrety.org</a></b>"); } else { tpl_set_var('log_geokret', ""); } /* GeoKretApi selector for logging Geokrets using GeoKretyApi */ $dbConWpt = new dataBase(); $dbConWpt->paramQuery("SELECT `secid` FROM `GeoKretyAPI` WHERE `userID` =:user_id LIMIT 1", array('user_id' => array('value' => $usr['userid'], 'data_type' => 'integer'))); if ($dbConWpt->rowCount() > 0) { tpl_set_var('GeoKretyApiNotConfigured', 'none'); tpl_set_var('GeoKretyApiConfigured', 'block'); $databaseResponse = $dbConWpt->dbResultFetch(); $secid = $databaseResponse['secid']; unset($dbConWpt); $dbConWpt = new dataBase(); $dbConWpt->paramQuery("SELECT `wp_oc` FROM `caches` WHERE `cache_id` = :cache_id", array('cache_id' => array('value' => $cache_id, 'data_type' => 'integer'))); $cwpt = $dbConWpt->dbResultFetch(); $cache_waypt = $cwpt['wp_oc']; unset($dbConWpt); $GeoKretSelector = new GeoKretyApi($secid, $cache_waypt); $GKSelect = $GeoKretSelector->MakeGeokretSelector($cachename); $GKSelect2 = $GeoKretSelector->MakeGeokretInCacheSelector($cachename); tpl_set_var('GeoKretApiSelector', $GKSelect); tpl_set_var('GeoKretApiSelector2', $GKSelect2); } else { tpl_set_var('GeoKretyApiNotConfigured', 'block'); tpl_set_var('GeoKretyApiConfigured', 'none'); tpl_set_var('GeoKretApiSelector', ''); } // descMode is depreciated. this was description type. Now all description are in html, then always use 3 for back compatibility $descMode = 3;
if ($usr == false) { $target = urlencode(tpl_get_current_page()); tpl_redirect('login.php?target=' . $target); } else { $tplname = 'searchuser'; $options['username'] = isset($_POST['username']) ? $_POST['username'] : ''; if (!isset($options['username'])) { $options['username'] = ''; } if ($options['username'] != '') { //$query = "SELECT user_id, username FROM user WHERE username LIKE '%" . sql_escape($options['username']) . "%' ORDER BY username ASC";; //$rs = sql($query); $query = "SELECT user_id, username, date_created FROM user WHERE username LIKE :username ORDER BY username ASC"; $params = array("username" => array("value" => '%' . sql_escape($options['username']) . '%', "data_type" => "string")); $dbc = new dataBase(); $dbc->paramQuery($query, $params); $bgcolor1 = '#eeeeee'; $bgcolor2 = '#ffffff'; $line = '<tr bgcolor={bgcolor}><td><a href=viewprofile.php?userid={user_id}>{username}</a></td><td> </td><td nowrap style="text-align:center;">{date_created}</td><td nowrap style="text-align:center;"></td></tr>'; $lines = ""; $ilosc = $dbc->rowCount(); //if (mysql_num_rows($rs) != 0) if ($ilosc != 0) { if ($ilosc == 1) { $record = $dbc->dbResultFetch(); tpl_redirect("viewprofile.php?userid=" . $record['user_id']); } else { //$ilosc=mysql_num_rows($rs); $linia = "Znaleziono {$ilosc} kont(a)</BR><UL>"; //while ($record = sql_fetch_array($rs)) $i = 0;
} else { tpl_set_var('def_seq', 1); //set default sequence to 1 for add picture link (in case there is no picture att all yet)) tpl_set_var('pictures', $nopictures); } //MP3 files only for type of cache: if ($cache_record['type'] == GeoCache::TYPE_OTHERTYPE || $cache_record['type'] == GeoCache::TYPE_MULTICACHE || $cache_record['type'] == GeoCache::TYPE_QUIZ) { 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 < mysql_num_rows($rs); $i++) { $record = sql_fetch_array($rs); $tmp_list = $i % 2 == 0 ? $list_e : $list_o; //modified coords if (($record['type'] == '7' || $record['type'] == '1' || $record['type'] == '3') && $usr != false) { //check if quiz (7) or other(1) or multi (3) and user is logged if (!isset($dbc)) { $dbc = new dataBase(); } $mod_coord_sql = 'SELECT cache_id FROM cache_mod_cords WHERE cache_id = :v1 AND user_id =:v2'; $params['v1']['value'] = (int) $record['cache_id']; $params['v1']['data_type'] = 'integer'; $params['v2']['value'] = (int) $usr['userid']; $params['v2']['data_type'] = 'integer'; $dbc->paramQuery($mod_coord_sql, $params); unset($params); if ($dbc->rowCount() > 0) { $tmp_list = str_replace('{mod_suffix}', '[F]', $tmp_list); } else { $tmp_list = str_replace('{mod_suffix}', '', $tmp_list); } } else { $tmp_list = str_replace('{mod_suffix}', '', $tmp_list); } $tmp_list = mb_ereg_replace('{cachename}', htmlspecialchars($record['name'], ENT_COMPAT, 'UTF-8'), $tmp_list); if ($record['last_found'] == NULL || $record['last_found'] == '0000-00-00 00:00:00') { $tmp_list = mb_ereg_replace('{lastfound}', htmlspecialchars($no_found_date, ENT_COMPAT, 'UTF-8'), $tmp_list); } else { $tmp_list = mb_ereg_replace('{lastfound}', htmlspecialchars(strftime($dateformat, strtotime($record['last_found'])), ENT_COMPAT, 'UTF-8'), $tmp_list); }
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>"; }