function cleanup_mapresult2($slaveId) { global $opt; // cleanup old entries $rs = sql("SELECT SQL_BUFFER_RESULT `result_id` FROM `map2_result` WHERE DATE_ADD(`date_created`, INTERVAL '&1' SECOND)<NOW()", $opt['map']['maxcacheage']); while ($r = sql_fetch_assoc($rs)) { sql("DELETE FROM `map2_result` WHERE `result_id`='&1'", $r['result_id']); } sql_free_result($rs); // now reduce table size? (29 bytes is the average row size) if (sql_value_slave("SELECT COUNT(*) FROM `map2_data`", 0) > $opt['map']['maxcachesize'] / 29) { while (sql_value_slave("SELECT COUNT(*) FROM `map2_data`", 0) > $opt['map']['maxcachereducedsize'] / 29) { $resultId = sql_value("SELECT `result_id` FROM `map2_result` WHERE `slave_id`='&1' ORDER BY `date_lastqueried` DESC LIMIT 1", 0, $slaveId); if ($resultId == 0) { return; } sql("DELETE FROM `map2_result` WHERE `result_id`='&1'", $resultId); } } $nMinId = sql_value("SELECT MIN(`result_id`) FROM `map2_result`", 0); if ($nMinId == 0) { sql("DELETE FROM `map2_data`"); } else { sql("DELETE FROM `map2_data` WHERE `result_id`<'&1'", $nMinId); } }
public static function getAttrbutesListArrayInternal($cacheId, $bOnlySelectable, $firstLetterUppercase) { global $opt; $attributes = array(); $rsAttrGroup = sql("SELECT `attribute_groups`.`id`,\n\t\t IFNULL(`tt1`.`text`, `attribute_groups`.`name`) AS `name`,\n\t\t IFNULL(`tt2`.`text`, `attribute_categories`.`name`) AS `category`,\n\t\t `attribute_categories`.`color`\n\t\t\tFROM `attribute_groups`\n\t\t\tINNER JOIN `attribute_categories` \n\t\t\t ON `attribute_groups`.`category_id`=`attribute_categories`.`id`\n\t\t\tLEFT JOIN `sys_trans` AS `t1` \n\t\t\t ON `attribute_groups`.`trans_id`=`t1`.`id` \n\t\t\t AND `attribute_groups`.`name`=`t1`.`text`\n\t\t\tLEFT JOIN `sys_trans_text` AS `tt1` \n\t\t\t ON `t1`.`id`=`tt1`.`trans_id` \n\t\t\t AND `tt1`.`lang`='&1'\n\t\t\tLEFT JOIN `sys_trans` AS `t2` \n\t\t\t ON `attribute_categories`.`trans_id`=`t2`.`id` \n\t\t\t AND `attribute_categories`.`name`=`t2`.`text`\n\t\t\tLEFT JOIN `sys_trans_text` AS `tt2` \n\t\t\t ON `t2`.`id`=`tt2`.`trans_id` \n\t\t\t AND `tt2`.`lang`='&1'\n\t\t\tORDER BY `attribute_groups`.`id` ASC", $opt['template']['locale']); while ($rAttrGroup = sql_fetch_assoc($rsAttrGroup)) { $attr = array(); $bFirst = true; $bSearchGroupDefault = false; if ($cacheId == 0) { $sAddWhereSql = ''; if ($bOnlySelectable == true) { $sAddWhereSql .= ' AND `cache_attrib`.`selectable`=1'; } $rsAttr = sql("SELECT `cache_attrib`.`id`, \n IFNULL(`tt1`.`text`, `cache_attrib`.`name`) AS `name`,\n\t\t\t\t\t\t\tIFNULL(`tt2`.`text`, `cache_attrib`.`html_desc`) AS `html_desc`,\n\t\t\t\t\t\t\t`cache_attrib`.`icon`, `cache_attrib`.`search_default`\n\t\t\t\t\tFROM `cache_attrib`\n\t\t\t\t\tLEFT JOIN `sys_trans` AS `t1` \n\t\t\t\t\t ON `cache_attrib`.`trans_id`=`t1`.`id` \n\t\t\t\t\t AND `cache_attrib`.`name`=`t1`.`text`\n\t\t\t\t\tLEFT JOIN `sys_trans_text` AS `tt1` \n\t\t\t\t\t ON `t1`.`id`=`tt1`.`trans_id` \n\t\t\t\t\t AND `tt1`.`lang`='&1'\n\t\t\t\t\tLEFT JOIN `sys_trans` AS `t2` \n\t\t\t\t\t ON `cache_attrib`.`html_desc_trans_id`=`t2`.`id`\n\t\t\t\t\tLEFT JOIN `sys_trans_text` AS `tt2` \n\t\t\t\t\t ON `t2`.`id`=`tt2`.`trans_id` \n\t\t\t\t\t AND `tt2`.`lang`='&1'\n\t\t\t\t\tWHERE `cache_attrib`.`group_id`='&2'" . $sAddWhereSql . "\n\t\t\t\t\tAND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1\n\t\t\t\t\tORDER BY `cache_attrib`.`group_id` ASC", $opt['template']['locale'], $rAttrGroup['id']); } else { $rsAttr = sql("SELECT `cache_attrib`.`id`, \n IFNULL(`tt1`.`text`, `cache_attrib`.`name`) AS `name`,\n\t\t\t\t\t\t\tIFNULL(`tt2`.`text`, `cache_attrib`.`html_desc`) AS `html_desc`,\n\t\t\t\t\t\t\t`cache_attrib`.`icon`, `cache_attrib`.`search_default`\n\t\t\t\t\tFROM `caches_attributes`\n\t\t\t\t\tINNER JOIN `cache_attrib` \n\t\t\t\t\t ON `caches_attributes`.`attrib_id`=`cache_attrib`.`id`\n\t\t\t\t\tLEFT JOIN `sys_trans` AS `t1` \n\t\t\t\t\t ON `cache_attrib`.`trans_id`=`t1`.`id` \n\t\t\t\t\t AND `cache_attrib`.`name`=`t1`.`text`\n\t\t\t\t\tLEFT JOIN `sys_trans_text` AS `tt1` \n\t\t\t\t\t ON `t1`.`id`=`tt1`.`trans_id` \n\t\t\t\t\t AND `tt1`.`lang`='&2'\n\t\t\t\t\tLEFT JOIN `sys_trans` AS `t2` \n\t\t\t\t\t ON `cache_attrib`.`html_desc_trans_id`=`t2`.`id`\n\t\t\t\t\tLEFT JOIN `sys_trans_text` AS `tt2` \n\t\t\t\t\t ON `t2`.`id`=`tt2`.`trans_id`\n\t\t\t\t\t AND `tt2`.`lang`='&2'\n\t\t\t\t\tWHERE `caches_attributes`.`cache_id`='&1' \n\t\t\t\t\tAND `cache_attrib`.`group_id`='&3'\n\t\t\t\t\tAND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1\n\t\t\t\t\tORDER BY `cache_attrib`.`group_id` ASC", $cacheId, $opt['template']['locale'], $rAttrGroup['id']); } while ($rAttr = sql_fetch_assoc($rsAttr)) { if ($firstLetterUppercase) { $rAttr['name'] = mb_strtoupper(mb_substr($rAttr['name'], 0, 1)) . mb_substr($rAttr['name'], 1); } $attr[] = $rAttr; if ($rAttr['search_default']) { $bSearchGroupDefault = true; } } sql_free_result($rsAttr); if (count($attr) > 0) { $attributes[] = array('id' => $rAttrGroup['id'], 'name' => $rAttrGroup['name'], 'color' => $rAttrGroup['color'], 'category' => $rAttrGroup['category'], 'search_default' => $bSearchGroupDefault, 'attr' => $attr); } } sql_free_result($rsAttrGroup); return $attributes; }
function t($message, $style, $resource_name, $line, $plural = '', $count = 1, $lang = null) { global $opt, $locale; // $locale is for lib1 compatibility if ($message == '') { return ''; } if ($plural != '' && $count != 1) { $message = $plural; } $search = $this->prepare_text($message); $loc = isset($opt['template']['locale']) ? $opt['template']['locale'] : $locale; if (!$lang || $lang == $loc) { $trans = gettext($search); } else { // do not use sql_value(), as this is also used from lib1 $rs = sql("SELECT IFNULL(`sys_trans_text`.`text`, '&3')\n\t\t\t FROM `sys_trans` \n\t\t\t LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'\n\t\t\t\t\t\t\t\t\tWHERE `sys_trans`.`text`='&2' LIMIT 1", $lang, $search, $message); if ($r = sql_fetch_array($rs)) { $trans = $r[0]; } else { $trans = ''; } sql_free_result($rs); } // safe w/o mb because asc(%) < 128 if (strpos($trans, "%") >= 0) { $trans = $this->v($trans); } return $trans; }
static function getAttrbutesListArrayInternal($cacheId, $bOnlySelectable) { global $opt; $attributes = array(); $rsAttrGroup = sql("SELECT `attribute_groups`.`id`, \r\n\t\t IFNULL(`tt1`.`text`, `attribute_groups`.`name`) AS `name`, \r\n\t\t IFNULL(`tt2`.`text`, `attribute_categories`.`name`) AS `category`, \r\n\t\t `attribute_categories`.`color`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `attribute_groups` \r\n\t\t\t\t\t\t\t\t\t\tINNER JOIN `attribute_categories` ON `attribute_groups`.`category_id`=`attribute_categories`.`id`\r\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN `sys_trans` AS `t1` ON `attribute_groups`.`trans_id`=`t1`.`id` AND `attribute_groups`.`name`=`t1`.`text` \r\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN `sys_trans_text` AS `tt1` ON `t1`.`id`=`tt1`.`trans_id` AND `tt1`.`lang`='&1' \r\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN `sys_trans` AS `t2` ON `attribute_categories`.`trans_id`=`t2`.`id` AND `attribute_categories`.`name`=`t2`.`text` \r\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN `sys_trans_text` AS `tt2` ON `t2`.`id`=`tt2`.`trans_id` AND `tt2`.`lang`='&1' \r\n\t\t\t\t\t\t\t\t\t\t\tORDER BY `attribute_groups`.`id` ASC", $opt['template']['locale']); while ($rAttrGroup = sql_fetch_assoc($rsAttrGroup)) { $attr = array(); $bFirst = true; if ($cacheId == 0) { $sAddWhereSql = ''; if ($bOnlySelectable == true) { $sAddWhereSql = ' AND `cache_attrib`.`selectable`=1'; } $rsAttr = sql("SELECT `cache_attrib`.`id`, IFNULL(`tt1`.`text`, `cache_attrib`.`name`) AS `name`,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tIFNULL(`tt2`.`text`, `cache_attrib`.`html_desc`) AS `html_desc`, `cache_attrib`.`icon`\r\n\t\t\t\t\t\t\t\t\t\t\t\t FROM `cache_attrib`\r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans` AS `t1` ON `cache_attrib`.`trans_id`=`t1`.`id` AND `cache_attrib`.`name`=`t1`.`text` \r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans_text` AS `tt1` ON `t1`.`id`=`tt1`.`trans_id` AND `tt1`.`lang`='&1' \r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans` AS `t2` ON `cache_attrib`.`html_desc_trans_id`=`t2`.`id` \r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans_text` AS `tt2` ON `t2`.`id`=`tt2`.`trans_id` AND `tt2`.`lang`='&1' \r\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE `cache_attrib`.`group_id`='&2'\r\n\t\t\t\t\t\t\t\t\t\t\t\tAND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1\r\n\t\t\t\t\t\t\t\t\t\t ORDER BY `cache_attrib`.`group_id` ASC", $opt['template']['locale'], $rAttrGroup['id']); } else { $rsAttr = sql("SELECT `cache_attrib`.`id`, IFNULL(`tt1`.`text`, `cache_attrib`.`name`) AS `name`,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tIFNULL(`tt2`.`text`, `cache_attrib`.`html_desc`) AS `html_desc`, `cache_attrib`.`icon`\r\n\t\t\t\t\t\t\t\t\t\t\t\t FROM `caches_attributes` \r\n\t\t\t\t\t\t\t\t\t INNER JOIN `cache_attrib` ON `caches_attributes`.`attrib_id`=`cache_attrib`.`id` \r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans` AS `t1` ON `cache_attrib`.`trans_id`=`t1`.`id` AND `cache_attrib`.`name`=`t1`.`text` \r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans_text` AS `tt1` ON `t1`.`id`=`tt1`.`trans_id` AND `tt1`.`lang`='&2' \r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans` AS `t2` ON `cache_attrib`.`html_desc_trans_id`=`t2`.`id` \r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans_text` AS `tt2` ON `t2`.`id`=`tt2`.`trans_id` AND `tt2`.`lang`='&2' \r\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE `caches_attributes`.`cache_id`='&1' AND `cache_attrib`.`group_id`='&3'\r\n\t\t\t\t\t\t\t\t\t\t\t\tAND NOT IFNULL(`cache_attrib`.`hidden`, 0)=1\r\n\t\t\t\t\t\t\t\t\t\t ORDER BY `cache_attrib`.`group_id` ASC", $cacheId, $opt['template']['locale'], $rAttrGroup['id']); } while ($rAttr = sql_fetch_assoc($rsAttr)) { $attr[] = $rAttr; } sql_free_result($rsAttr); if (count($attr) > 0) { $attributes[] = array('name' => $rAttrGroup['name'], 'color' => $rAttrGroup['color'], 'category' => $rAttrGroup['category'], 'attr' => $attr); } } sql_free_result($rsAttrGroup); return $attributes; }
function showlist($query, $type, $template) { if (is_array($query)) { if (sizeof($query) == 0) { return 0; } call_user_func('listplug_' . $type, $template, 'HEAD'); foreach ($query as $currentObj) { $template['current'] = $currentObj; call_user_func('listplug_' . $type, $template, 'BODY'); } call_user_func('listplug_' . $type, $template, 'FOOT'); return sizeof($query); } else { $res = sql_query($query); // don't do anything if there are no results $numrows = sql_num_rows($res); if ($numrows == 0) { return 0; } call_user_func('listplug_' . $type, $template, 'HEAD'); while ($template['current'] = sql_fetch_object($res)) { call_user_func('listplug_' . $type, $template, 'BODY'); } call_user_func('listplug_' . $type, $template, 'FOOT'); sql_free_result($res); // return amount of results return $numrows; } }
public function run() { $rsDuplicatePic = sql('SELECT `object_id`, `title` FROM `pictures` WHERE `object_type`=1 GROUP BY `object_id`, `title` HAVING COUNT(*) > 1'); while ($rDuplicatePic = sql_fetch_assoc($rsDuplicatePic)) { $rsInstances = sql(" SELECT `pictures`.`id` `picid`, `cache_logs`.`cache_id` `cache_id`\n FROM `pictures`\n LEFT JOIN `cache_logs` ON `cache_logs`.`id` = `pictures`.`object_id`\n WHERE `pictures`.`object_type`=1 AND `pictures`.`object_id`='&1' AND `pictures`.`title`='&2'\n ORDER BY `pictures`.`date_created`", $rDuplicatePic['object_id'], $rDuplicatePic['title']); $instances = sql_fetch_assoc_table($rsInstances); foreach ($instances as &$instance) { $instance['pic'] = new picture($instance['picid']); $instance['filesize'] = @filesize($instance['pic']->getFilename()); } $countInstances = count($instances); for ($n = 1; $n < $countInstances; ++$n) { if ($instances[$n]['filesize'] !== false) { // ensure that pic is stored locally for ($nn = $n - 1; $nn >= 0; --$nn) { if ($instances[$nn]['filesize'] === $instances[$n]['filesize']) { if (file_get_contents($instances[$nn]['pic']->getFilename()) == file_get_contents($instances[$n]['pic']->getFilename())) { $picture = $instances[$n]['pic']; echo 'deleting duplicate picture ' . $picture->getPictureId() . ' ("' . $picture->getTitle() . '")' . ' from log ' . $rDuplicatePic['object_id'] . ' of cache ' . $instances[$n]['cache_id'] . "\n"; $picture->delete(false); $instances[$n]['filesize'] = false; break; } } } } } } sql_free_result($rsDuplicatePic); }
function assignFromDB($userid) { global $tpl, $opt; $rs = sql("SELECT `p`.`id`, IFNULL(`tt`.`text`, `p`.`name`) AS `name`, `p`.`default_value`, `p`.`check_regex`, `p`.`option_order`, `u`.`option_visible`, `p`.`internal_use`, `p`.`option_input`, IFNULL(`u`.`option_value`, `p`.`default_value`) AS `option_value`\r\n\t\t FROM `profile_options` AS `p`\r\n\t\t LEFT JOIN `user_options` AS `u` ON `p`.`id`=`u`.`option_id` AND (`u`.`user_id` IS NULL OR `u`.`user_id`='&1')\r\n\t\t LEFT JOIN `sys_trans` AS `st` ON `p`.`trans_id`=`st`.`id` AND `p`.`name`=`st`.`text`\r\n\t\t LEFT JOIN `sys_trans_text` AS `tt` ON `st`.`id`=`tt`.`trans_id` AND `tt`.`lang`='&2'\r\n\t\t ORDER BY `p`.`internal_use` DESC, `p`.`option_order`", $userid + 0, $opt['template']['locale']); $tpl->assign_rs('useroptions', $rs); sql_free_result($rs); }
public function run() { $rsCache = sql("SELECT `cache_id`, `latitude`, `longitude` FROM `caches` WHERE `need_npa_recalc`=1"); while ($rCache = sql_fetch_assoc($rsCache)) { sql("DELETE FROM `cache_npa_areas` WHERE `cache_id`='&1' AND `calculated`=1", $rCache['cache_id']); $rsLayers = sql("SELECT `id`, `type_id`, AsText(`shape`) AS `geometry` \n FROM `npa_areas` WHERE `exclude`=0 AND MBRWITHIN(GeomFromText('&1'), `shape`)", 'POINT(' . $rCache['longitude'] . ' ' . $rCache['latitude'] . ')'); while ($rLayers = sql_fetch_assoc($rsLayers)) { if (gis::ptInLineRing($rLayers['geometry'], 'POINT(' . $rCache['longitude'] . ' ' . $rCache['latitude'] . ')')) { $bExclude = false; // prüfen, ob in ausgesparter Fläche $rsExclude = sql("SELECT `id`, AsText(`shape`) AS `geometry`\n FROM `npa_areas`\n WHERE `exclude` = 1\n AND `type_id`='&1'\n AND MBRWITHIN(GeomFromText('&2'), `shape`)", $rLayers['type_id'], 'POINT(' . $rCache['longitude'] . ' ' . $rCache['latitude'] . ')'); while (($rExclude = sql_fetch_assoc($rsExclude)) && $bExclude == false) { if (gis::ptInLineRing($rExclude['geometry'], 'POINT(' . $rCache['longitude'] . ' ' . $rCache['latitude'] . ')')) { $bExclude = true; } } sql_free_result($rsExclude); if ($bExclude == false) { sql("INSERT INTO `cache_npa_areas` (`cache_id`, `npa_id`, `calculated`)\n VALUES ('&1', '&2', 1) ON DUPLICATE KEY UPDATE `calculated`=1", $rCache['cache_id'], $rLayers['id']); } } } sql_free_result($rsLayers); sql("UPDATE `caches` SET `need_npa_recalc`=0 WHERE `cache_id`='&1'", $rCache['cache_id']); } sql_free_result($rsCache); }
function CheckThrottle() { global $opt, $tpl; $ip_string = $_SERVER['REMOTE_ADDR']; $ip_blocks = mb_split('\\.', $ip_string); $ip_numeric = $ip_blocks[3] + $ip_blocks[2] * 256 + $ip_blocks[1] * 65536 + $ip_blocks[0] * 16777216; sql('CREATE TABLE IF NOT EXISTS &tmpdb.`sys_accesslog` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `ip` INT UNSIGNED NOT NULL, `access_time` TIMESTAMP NOT NULL, INDEX (`access_time`), INDEX (`ip`)) ENGINE = MEMORY'); $rsStaus = sql("SHOW STATUS LIKE 'Threads_connected'"); $rStatus = sql_fetch_array($rsStaus); sql_free_result($rsStaus); if ($rStatus) { if ($rStatus[1] > $opt['db']['throttle_connection_count']) { $access_count = sql_value("SELECT COUNT(*) FROM &tmpdb.`sys_accesslog` WHERE ip ='&1'", 0, $ip_numeric); if ($access_count > $opt['db']['throttle_access_count']) { $tpl->error(ERROR_THROOTLE); } } } // remove old entries every 100st call if (mt_rand(0, 100) == 50) { sql("DELETE FROM &tmpdb.`sys_accesslog` WHERE `access_time`<CURRENT_TIMESTAMP()-'&2'", $ip_numeric, $opt['db']['throttle_access_time']); } sql("INSERT INTO &tmpdb.`sys_accesslog` (`ip`, `access_time`) VALUES ('&1', CURRENT_TIMESTAMP())", $ip_numeric); }
public function fill($max_inserts_count) { global $opt; $rowCount = 0; $nInsertCount = 0; if ($opt['logic']['waypoint_pool']['fill_gaps'] == true) { // query the first unused waypoint (between other waypoints) $rsStartWp = sql("SELECT SQL_BUFFER_RESULT DECTOWP(WPTODEC(`c`.`wp_oc`, '&1')+1, '&1') AS `free_wp`\n FROM `caches` AS `c`\n LEFT JOIN `caches` AS `cNext` ON DECTOWP(WPTODEC(`c`.`wp_oc`, '&1')+1, '&1')=`cNext`.`wp_oc`\n LEFT JOIN `cache_waypoint_pool` ON DECTOWP(WPTODEC(`c`.`wp_oc` ,'&1')+1, '&1')=`cache_waypoint_pool`.`wp_oc`\n WHERE `c`.`wp_oc` REGEXP '&2'\n AND ISNULL(`cNext`.`wp_oc`)\n AND ISNULL(`cache_waypoint_pool`.`wp_oc`)\n ORDER BY `free_wp` ASC\n LIMIT 250", $opt['logic']['waypoint_pool']['prefix'], '^' . $opt['logic']['waypoint_pool']['prefix'] . '[' . $opt['logic']['waypoint_pool']['valid_chars'] . ']{1,}$'); } else { // query the last used waypoint $rsStartWp = sql("SELECT SQL_BUFFER_RESULT DECTOWP(MAX(dec_wp)+1, '&2') AS `free_wp`\n FROM (\n SELECT MAX(WPTODEC(`wp_oc`, '&2')) AS dec_wp\n FROM `caches`\n WHERE `wp_oc` REGEXP '&1'\n UNION\n SELECT MAX(WPTODEC(`wp_oc`, '&2')) AS dec_wp\n FROM `cache_waypoint_pool`\n ) AS tbl", '^' . $opt['logic']['waypoint_pool']['prefix'] . '[' . $opt['logic']['waypoint_pool']['valid_chars'] . ']{1,}$', $opt['logic']['waypoint_pool']['prefix']); } while (($rStartWp = sql_fetch_assoc($rsStartWp)) && $nInsertCount < $max_inserts_count) { $free_wp = $rStartWp['free_wp']; if ($free_wp == '') { $free_wp = $opt['logic']['waypoint_pool']['prefix'] . '0001'; } $nInsertCount += $this->fill_turn($free_wp, $max_inserts_count - $nInsertCount); $rowCount++; } sql_free_result($rsStartWp); if ($rowCount == 0) { // new database ... $nInsertCount += $this->fill_turn($opt['logic']['waypoint_pool']['prefix'] . '0001', $max_inserts_count); } return $nInsertCount; }
function geodb_setCacheLocation($cache_id) { echo $cache_id . "\n"; $rs = sqll("SELECT `latitude`, `longitude`, `last_modified` FROM `caches` WHERE `cache_id`='&1'", $cache_id); if ($r = sql_fetch_array($rs)) { $nLocId = geodb_locidFromCoords($r['longitude'], $r['latitude']); if ($nLocId != 0) { $sAdm1 = geodb_landFromLocid($nLocId); $sAdm2 = geodb_regierungsbezirkFromLocid($nLocId); $sAdm3 = geodb_landkreisFromLocid($nLocId); } else { $sAdm1 = null; $sAdm2 = null; $sAdm3 = null; } if ($sAdm1 == '') { $sAdm1 = null; } if ($sAdm2 == '') { $sAdm2 = null; } if ($sAdm3 == '') { $sAdm3 = null; } sqll("INSERT INTO `cache_location` (`cache_id`, `last_modified`, `adm1`, `adm2`, `adm3`) VALUES ('&1', '&2', '&3', '&4', '&5') ON DUPLICATE KEY UPDATE `cache_id`='&1', `last_modified`='&2', `adm1`='&3', `adm2`='&4', `adm3`='&5'", $cache_id, $r['last_modified'], $sAdm1, $sAdm2, $sAdm3); } sql_free_result($rs); }
function run() { global $opt; $rsCache = sql("SELECT `caches`.`cache_id`, `caches`.`latitude`, `caches`.`longitude` FROM `caches` LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_id` WHERE ISNULL(`cache_location`.`cache_id`) UNION SELECT `caches`.`cache_id`, `caches`.`latitude`, `caches`.`longitude` FROM `caches` INNER JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_id` WHERE `caches`.`last_modified`>`cache_location`.`last_modified`"); while ($rCache = sql_fetch_assoc($rsCache)) { $sCode = ''; $rsLayers = sql("SELECT `level`, `code`, AsText(`shape`) AS `geometry` FROM `nuts_layer` WHERE WITHIN(GeomFromText('&1'), `shape`) ORDER BY `level` DESC", 'POINT(' . $rCache['longitude'] . ' ' . $rCache['latitude'] . ')'); while ($rLayers = sql_fetch_assoc($rsLayers)) { if (gis::ptInLineRing($rLayers['geometry'], 'POINT(' . $rCache['longitude'] . ' ' . $rCache['latitude'] . ')')) { $sCode = $rLayers['code']; break; } } sql_free_result($rsLayers); 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; $adm4 = sql_value("SELECT `name` FROM `nuts_codes` WHERE `code`='&1'", null, $sCode); $sCode = mb_substr($sCode, 0, 4); } if (mb_strlen($sCode) == 4) { $code3 = $sCode; $adm3 = sql_value("SELECT `name` FROM `nuts_codes` WHERE `code`='&1'", null, $sCode); $sCode = mb_substr($sCode, 0, 3); } if (mb_strlen($sCode) == 3) { $code2 = $sCode; $adm2 = sql_value("SELECT `name` FROM `nuts_codes` WHERE `code`='&1'", null, $sCode); $sCode = mb_substr($sCode, 0, 2); } if (mb_strlen($sCode) == 2) { $code1 = $sCode; // try to get localised name first $adm1 = sql_value("SELECT IFNULL(`sys_trans_text`.`text`, `countries`.`name`)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM `countries`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans` ON `countries`.`trans_id`=`sys_trans`.`id` AND `countries`.`name`=`sys_trans`.`text`\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&2'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE `countries`.`short`='&1'", null, $sCode, $opt['template']['default']['locale']); if ($adm1 == null) { $adm1 = sql_value("SELECT `name` FROM `nuts_codes` WHERE `code`='&1'", null, $sCode); } } sql("INSERT INTO `cache_location` (`cache_id`, `adm1`, `adm2`, `adm3`, `adm4`, `code1`, `code2`, `code3`, `code4`) VALUES ('&1', '&2', '&3', '&4', '&5', '&6', '&7', '&8', '&9') ON DUPLICATE KEY UPDATE `adm1`='&2', `adm2`='&3', `adm3`='&4', `adm4`='&5', `code1`='&6', `code2`='&7', `code3`='&8', `code4`='&9'", $rCache['cache_id'], $adm1, $adm2, $adm3, $adm4, $code1, $code2, $code3, $code4); } else { $sCountry = sql_value("SELECT IFNULL(`sys_trans_text`.`text`, `countries`.`name`)\r\n\t\t\t\t FROM `caches` \r\n\t\t\t\t INNER JOIN `countries` ON `caches`.`country`=`countries`.`short`\r\n\t\t\t\t LEFT JOIN `sys_trans` ON `countries`.`trans_id`=`sys_trans`.`id` AND `countries`.`name`=`sys_trans`.`text`\r\n\t\t\t\t LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&2'\r\n\t\t\t\t WHERE `caches`.`cache_id`='&1'", null, $rCache['cache_id'], $opt['template']['default']['locale']); $sCode1 = sql_value("SELECT `caches`.`country` FROM `caches` WHERE `caches`.`cache_id`='&1'", null, $rCache['cache_id']); sql("INSERT INTO `cache_location` (`cache_id`, `adm1`, `code1`) VALUES ('&1', '&2', '&3') ON DUPLICATE KEY UPDATE `adm1`='&2', `adm2`=NULL, `adm3`=NULL, `adm4`=NULL, `code1`='&3', `code2`=NULL, `code3`=NULL, `code4`=NULL", $rCache['cache_id'], $sCountry, $sCode1); } } sql_free_result($rsCache); }
function get_npas($cache_id) { $rsNPA = sql("SELECT `npa_areas`.`name` AS `npaName`, `npa_types`.`name` AS `npaTypeName`\n\t FROM `cache_npa_areas`\n\t INNER JOIN `npa_areas` ON `cache_npa_areas`.`npa_id`=`npa_areas`.`id`\n\t INNER JOIN `npa_types` ON `npa_areas`.`type_id`=`npa_types`.`id`\n\t WHERE `cache_npa_areas`.`cache_id`='&1'\n\t GROUP BY `npa_areas`.`type_id`, `npa_areas`.`name`\n\t ORDER BY `npa_types`.`ordinal` ASC", $cache_id); $npas = array(); while ($rNPA = sql_fetch_array($rsNPA)) { $npas[] = $rNPA; } sql_free_result($rsNPA); return $npas; }
function CreateCacheFile() { global $opt, $translate; $f = fopen($this->sMenuFilename, 'w'); fwrite($f, "<?php\n"); fwrite($f, 'global $menuitem;' . "\n"); fwrite($f, "\n"); $rsDefines = sqlf("SELECT `id`, `id_string` FROM `sys_menu`"); while ($rDefine = sql_fetch_assoc($rsDefines)) { fwrite($f, 'if (!defined(\'' . addslashes($rDefine['id_string']) . '\')) define(\'' . addslashes($rDefine['id_string']) . '\', ' . $rDefine['id'] . ");\n"); } sql_free_result($rsDefines); fwrite($f, "\n"); $aMenu = array(); $nPos = 0; $rsSubmenu = sqlf("SELECT `id` FROM `sys_menu` WHERE `parent`=0 ORDER BY `parent` ASC, `position` ASC"); while ($rSubmenu = sql_fetch_assoc($rsSubmenu)) { $aMenu[MNU_ROOT]['subitems'][$nPos] = $rSubmenu['id']; $nPos++; } sql_free_result($rsSubmenu); fwrite($f, "\n"); $rs = sqlf('SELECT `item`.`id`, `item`.`title`, `item`.`menustring`, `item`.`access`, `item`.`href`, `item`.`visible`, `item`.`parent` AS `parentid`, `item`.`color` AS `color` FROM `sys_menu` AS `item` LEFT JOIN `sys_menu` AS `parentitem` ON `item`.`parent`=`parentitem`.`id`'); while ($r = sql_fetch_assoc($rs)) { $aMenu[$r['id']]['title'] = $translate->t($r['title'], '', basename(__FILE__), __LINE__); $aMenu[$r['id']]['menustring'] = $translate->t($r['menustring'], '', basename(__FILE__), __LINE__); $aMenu[$r['id']]['authlevel'] = $r['access'] == 0 ? AUTH_LEVEL_ALL : AUTH_LEVEL_ADMIN; if (substr($r['href'], 0, 1) == '!') { $aMenu[$r['id']]['href'] = substr($r['href'], 1); $aMenu[$r['id']]['target'] = 'target="_blank"'; } else { $aMenu[$r['id']]['href'] = $r['href']; $aMenu[$r['id']]['target'] = ''; } $aMenu[$r['id']]['visible'] = $r['visible']; $aMenu[$r['id']]['sublevel'] = $this->pGetMenuSublevel($r['id']); if ($r['parentid'] != 0) { $aMenu[$r['id']]['parent'] = $r['parentid']; } if ($r['color'] != null) { $aMenu[$r['id']]['color'] = $r['color']; } $nPos = 0; $rsSubmenu = sqlf("SELECT `id` FROM `sys_menu` WHERE `parent`='&1' ORDER BY `parent` ASC, `position` ASC", $r['id']); while ($rSubmenu = sql_fetch_assoc($rsSubmenu)) { $aMenu[$r['id']]['subitems'][$nPos] = $rSubmenu['id']; $nPos++; } sql_free_result($rsSubmenu); } sql_free_result($rs); fwrite($f, '$menuitem = unserialize("' . str_replace('"', '\\"', serialize($aMenu)) . '");' . "\n"); fwrite($f, "?>"); fclose($f); }
function sql_dropProcedure($name) { $rs = sql("SHOW PROCEDURE STATUS LIKE '&1'", $name); while ($r = sql_fetch_assoc($rs)) { if ($r['Name'] == $name && $r['Type'] == 'PROCEDURE') { sql('DROP PROCEDURE `&1`', $name); return; } } sql_free_result($rs); }
function run() { $rsPublish = sql("SELECT `cache_id`, `user_id` FROM `caches` WHERE `status`=5 AND NOT ISNULL(`date_activate`) AND `date_activate`<=NOW()"); while ($rPublish = sql_fetch_array($rsPublish)) { $userid = $rPublish['user_id']; $cacheid = $rPublish['cache_id']; // update cache status to active sql("UPDATE `caches` SET `status`=1, `date_activate`=NULL WHERE `cache_id`='&1'", $cacheid); } sql_free_result($rsPublish); }
function pAppendSites($parentId, $viewall, $sublevel, &$aItems) { global $opt; $rs = sql("SELECT `sys_menu`.`id`, \r\n\t IF(`sys_menu`.`title`='', \r\n\t IFNULL(`ttMenu`.`text`, `sys_menu`.`menustring`), \r\n\t IFNULL(`ttTitle`.`text`, `sys_menu`.`title`)) AS `name`, \r\n\t `sys_menu`.`href`, \r\n\t `sys_menu`.`sitemap` \r\n\t FROM `sys_menu` \r\n\t LEFT JOIN `sys_trans` AS `tTitle` ON `sys_menu`.`title_trans_id`=`tTitle`.`id` AND `sys_menu`.`title`=`tTitle`.`text` \r\n\t LEFT JOIN `sys_trans_text` AS ttTitle ON `tTitle`.`id`=`ttTitle`.`trans_id` AND `ttTitle`.`lang`='&2' \r\n\t LEFT JOIN `sys_trans` AS `tMenu` ON `sys_menu`.`menustring_trans_id`=`tMenu`.`id` AND `sys_menu`.`menustring`=`tMenu`.`text` \r\n\t LEFT JOIN `sys_trans_text` AS `ttMenu` ON `tMenu`.`id`=`ttMenu`.`trans_id` AND `ttMenu`.`lang`='&2' \r\n\t WHERE `sys_menu`.`access`=0 AND `sys_menu`.`parent`='&1' AND (&3=1 OR `sys_menu`.`sitemap`=1)\r\n\t ORDER BY `sys_menu`.`parent` ASC, `sys_menu`.`position` ASC", $parentId, $opt['template']['locale'], $viewall ? 1 : 0); while ($r = sql_fetch_assoc($rs)) { $r['sublevel'] = $sublevel; $aItems[] = $r; pAppendSites($r['id'], $viewall, $sublevel + 1, &$aItems); } sql_free_result($rs); }
function action_display() { global $tpl; $rs = sql('SELECT `news`.`id` AS `id`, `news`.`date_created` AS `date_created`, `news`.`content` AS `content`, `news`.`display` AS `display`, `news_topics`.`name` AS `topic` FROM `news` INNER JOIN `news_topics` ON `news`.`topic`=`news_topics`.`id` ORDER BY `news`.`date_created` DESC'); $tpl->assign_rs('newsentries', $rs); sql_free_result($rs); $tpl->display(); }
public function archive_events() { // To prevent archiving events that were accidentally published with a wrong // event date - before the owner notices it - we also apply a limit of one month // to the publication date. $rs = sql("SELECT `cache_id`\n FROM `caches`\n WHERE `caches`.`type`=6 AND `caches`.`status`=1\n AND GREATEST(`date_hidden`,`date_created`) < NOW() - INTERVAL 35 DAY\n ORDER BY `date_hidden`\n LIMIT 1"); while ($rCache = sql_fetch_assoc($rs)) { $this->archive_cache($rCache['cache_id'], 'This event took place more than five weeks ago; therefore it is ' . 'being archived automatically. The owner may re-enable the listing ' . 'if it should stay active for some exceptional reason.'); } sql_free_result($rs); }
function get_table_def($table) { global $dbname, $crlf, $crlf2; $k = 0; $result = sql_query("SELECT * FROM {$table} limit 1"); $count = sql_num_fields($result); $schema_create = ""; $schema_create .= "DROP TABLE IF EXISTS {$table};{$crlf}"; $schema_create .= "CREATE TABLE {$table} ({$crlf}"; $result = sql_query("SHOW FIELDS FROM {$table}"); while ($row = sql_fetch_assoc($result)) { $schema_create .= " " . $row['Field'] . " " . $row['Type']; if (isset($row['Default']) && (!empty($row['Default']) || $row['Default'] == "0")) { $schema_create .= " DEFAULT '" . $row['Default'] . "'"; } if ($row["Null"] != "YES") { $schema_create .= " NOT NULL"; } if ($row["Extra"] != "") { $schema_create .= " " . $row['Extra']; } if ($k < $count - 1) { $schema_create .= ",{$crlf}"; } $k++; } $result = sql_query("SHOW KEYS FROM {$table}"); while ($row = sql_fetch_assoc($result)) { $kname = $row['Key_name']; if ($kname != "PRIMARY" && $row['Non_unique'] == 0) { $kname = "UNIQUE|{$kname}"; } if (!isset($index[$kname])) { $index[$kname] = array(); } $index[$kname][] = $row['Column_name']; } while (list($x, $columns) = @each($index)) { $schema_create .= ",{$crlf}"; if ($x == "PRIMARY") { $schema_create .= " PRIMARY KEY (" . implode($columns, ", ") . ")"; } elseif (substr($x, 0, 6) == "UNIQUE") { $schema_create .= " UNIQUE " . substr($x, 7) . " (" . implode($columns, ", ") . ")"; } else { $schema_create .= " KEY {$x} (" . implode($columns, ", ") . ")"; } } $schema_create .= "{$crlf})"; $schema_create = stripslashes($schema_create); $schema_create .= ";"; sql_free_result($result); return $schema_create; }
public function __construct() { global $opt; $this->translator = new Language_Translator(); // read available types from DB $rs = sql("SELECT `coordinates_type`.`id`, IFNULL(`trans`.`text`, `coordinates_type`.`name`) AS `name`, `coordinates_type`.`image`, IFNULL(`trans_pp`.`text`, `coordinates_type`.`preposition`) AS `preposition`\n\t\t FROM `coordinates_type`\n\t\t\t\t\t\tLEFT JOIN `sys_trans_text` `trans` ON `coordinates_type`.`trans_id`=`trans`.`trans_id` AND `trans`.`lang`='&1'\n\t\t\t\t\t\tLEFT JOIN `sys_trans_text` `trans_pp` ON `coordinates_type`.`pp_trans_id`=`trans_pp`.`trans_id` AND `trans_pp`.`lang`='&1'", $opt['template']['locale']); while ($r = sql_fetch_assoc($rs)) { $type = new ChildWp_Type($r['id'], $r['name'], $r['preposition'], $r['image']); $this->childWpTypes[$type->getId()] = $type; } sql_free_result($rs); }
function showstats($header, $condition, $limit) { echo "<h3>{$header}</h3>\n"; echo "<table>\n"; $rs = sql("SELECT COUNT(*) as `count`, `username` as `name`\n FROM `caches`\n LEFT JOIN `user` ON `user`.`user_id`=`caches`.`user_id`\n LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6\n WHERE status=1 AND " . $condition . "\n GROUP BY `caches`.`user_id`\n HAVING COUNT(*) >= {$limit}\n ORDER BY COUNT(*) DESC"); $n = 1; while ($r = sql_fetch_assoc($rs)) { echo " <tr><td style='text-align:right'> " . $n++ . ". </td><td style='text-align:right'>" . $r['count'] . "</td><td> " . $r['name'] . "</td></tr>\n"; } sql_free_result($rs); echo "</table>\n"; }
static function CreateCacheFile() { global $opt; $f = fopen($opt['rootpath'] . 'cache2/labels-' . $opt['template']['locale'] . '.inc.php', 'w'); fwrite($f, "<?php\n"); $a = array(); $rs = sql("SELECT `cache_attrib`.`id`, IFNULL(`sys_trans_text`.`text`, `cache_attrib`.`name`) AS `name`\n\t\t FROM `cache_attrib`\n\t\t LEFT JOIN `sys_trans` ON `cache_attrib`.`trans_id`=`sys_trans`.`id` AND `cache_attrib`.`name`=`sys_trans`.`text`\n\t\t LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'", $opt['template']['locale']); while ($r = sql_fetch_assoc($rs)) { $a[$r['id']] = $r['name']; } sql_free_result($rs); fwrite($f, 'labels::addLabels("cache_attrib", "' . str_replace('"', '\\"', serialize($a)) . '");' . "\n"); $a = array(); $rs = sql("SELECT `cache_size`.`id`, IFNULL(`sys_trans_text`.`text`, `cache_size`.`name`) AS `name`\n\t\t FROM `cache_size`\n\t\t LEFT JOIN `sys_trans` ON `cache_size`.`trans_id`=`sys_trans`.`id` AND `cache_size`.`name`=`sys_trans`.`text`\n\t\t LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'", $opt['template']['locale']); while ($r = sql_fetch_assoc($rs)) { $a[$r['id']] = $r['name']; } sql_free_result($rs); fwrite($f, 'labels::addLabels("cache_size", "' . str_replace('"', '\\"', serialize($a)) . '");' . "\n"); $a = array(); $rs = sql("SELECT `cache_status`.`id`, IFNULL(`sys_trans_text`.`text`, `cache_status`.`name`) AS `name`\n\t\t FROM `cache_status`\n\t\t LEFT JOIN `sys_trans` ON `cache_status`.`trans_id`=`sys_trans`.`id` AND `cache_status`.`name`=`sys_trans`.`text`\n\t\t LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'", $opt['template']['locale']); while ($r = sql_fetch_assoc($rs)) { $a[$r['id']] = $r['name']; } sql_free_result($rs); fwrite($f, 'labels::addLabels("cache_status", "' . str_replace('"', '\\"', serialize($a)) . '");' . "\n"); $a = array(); $rs = sql("SELECT `cache_type`.`id`, IFNULL(`sys_trans_text`.`text`, `cache_type`.`name`) AS `name`\n\t\t FROM `cache_type`\n\t\t LEFT JOIN `sys_trans` ON `cache_type`.`trans_id`=`sys_trans`.`id` AND `cache_type`.`name`=`sys_trans`.`text`\n\t\t LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'", $opt['template']['locale']); while ($r = sql_fetch_assoc($rs)) { $a[$r['id']] = $r['name']; } sql_free_result($rs); fwrite($f, 'labels::addLabels("cache_type", "' . str_replace('"', '\\"', serialize($a)) . '");' . "\n"); $a = array(); $rs = sql("SELECT `log_types`.`id`, IFNULL(`sys_trans_text`.`text`, `log_types`.`name`) AS `name`\n\t\t FROM `log_types`\n\t\t LEFT JOIN `sys_trans` ON `log_types`.`trans_id`=`sys_trans`.`id` AND `log_types`.`name`=`sys_trans`.`text`\n\t\t LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&1'", $opt['template']['locale']); while ($r = sql_fetch_assoc($rs)) { $a[$r['id']] = $r['name']; } sql_free_result($rs); fwrite($f, 'labels::addLabels("log_types", "' . str_replace('"', '\\"', serialize($a)) . '");' . "\n"); $nLastGroup = 1; $a = array(); $rs = sql("SELECT `countries_options`.`country`, \n\t\t IF(`countries_options`.`nodeId`='&1', 1, IF(`countries_options`.`nodeId`!=0, 2, 3)) AS `group`, \n\t\t IFNULL(`sys_trans_text`.`text`, `countries`.`name`) AS `name` \n\t\t FROM `countries_options` \n\t\t INNER JOIN `countries` ON `countries_options`.`country`=`countries`.`short`\n\t\t LEFT JOIN `sys_trans` ON `countries`.`trans_id`=`sys_trans`.`id` \n\t\t LEFT JOIN `sys_trans_text` ON `sys_trans`.`id`=`sys_trans_text`.`trans_id` AND `sys_trans_text`.`lang`='&2' \n\t\t WHERE `countries_options`.`display`=1 \n\t\t ORDER BY `group` ASC,\n\t\t IFNULL(`sys_trans_text`.`text`, `countries`.`name`) ASC", $opt['logic']['node']['id'], $opt['template']['locale']); while ($r = sql_fetch_assoc($rs)) { $r['begin_group'] = $r['group'] != $nLastGroup; $nLastGroup = $r['group']; $a[] = $r; } sql_free_result($rs); fwrite($f, 'labels::addLabels("usercountrieslist", "' . str_replace('"', '\\"', serialize($a)) . '");' . "\n"); fwrite($f, "?>"); fclose($f); }
public function run() { global $login; $rsPublish = sql("SELECT `cache_id`, `user_id`\n FROM `caches`\n WHERE `status`=5\n AND NOT ISNULL(`date_activate`)\n AND `date_activate`<=NOW()"); while ($rPublish = sql_fetch_array($rsPublish)) { $userid = $rPublish['user_id']; $cacheid = $rPublish['cache_id']; // update cache status to active sql("SET @STATUS_CHANGE_USER_ID='&1'", $login->userid); sql("UPDATE `caches` SET `status`=1, `date_activate`=NULL WHERE `cache_id`='&1'", $cacheid); } sql_free_result($rsPublish); }
function __construct($nUserId = ID_NEW) { $this->nUserId = $nUserId + 0; if ($nUserId == ID_NEW) { $rs = sqll('SELECT `id`, `name`, `default_value`, `check_regex`, `option_order`, 0 AS `option_visible`, `internal_use`, `default_value` AS `option_value` FROM `profile_options`'); } else { $rs = sqll("SELECT `p`.`id`, `p`.`name`, `p`.`default_value`, `p`.`check_regex`, `p`.`option_order`, IFNULL(`u`.`option_visible`, 0) AS `option_visible`, `p`.`internal_use`, IFNULL(`u`.`option_value`, `p`.`default_value`) AS `option_value`\r\n\t\t\t\t\t\tFROM `profile_options` AS `p`\r\n\t\t\t\t\t\tLEFT JOIN `user_options` AS `u` ON `p`.`id`=`u`.`option_id` AND (`u`.`user_id` IS NULL OR `u`.`user_id`='&1')\r\n\t\t\t\t\tUNION \r\n\t\t\t\t\t\tSELECT `u`.`option_id` AS `id`, `p`.`name`, `p`.`default_value`, `p`.`check_regex`, `p`.`option_order`, `u`.`option_visible`, `p`.`internal_use`, IFNULL(`u`.`option_value`, `p`.`default_value`) AS `option_value`\r\n\t\t\t\t\t\tFROM `user_options` AS `u`\r\n\t\t\t\t\t\tLEFT JOIN `profile_options` AS `p` ON `p`.`id`=`u`.`option_id`\r\n\t\t\t\t\t\tWHERE `u`.`user_id`='&1'", $this->nUserId); } while ($record = sql_fetch_array($rs)) { $this->nOptions[$record['id']] = $record; } sql_free_result($rs); }
function run() { $nIds = array(); $rs = sqlf("SHOW PROCESSLIST"); while ($r = sql_fetch_assoc($rs)) { $nIds[$r['Id']] = $r['Id']; } sql_free_result($rs); $rs = sqlf("SELECT DISTINCT `threadid` FROM `sys_temptables`"); while ($r = sql_fetch_assoc($rs)) { if (!isset($nIds[$r['threadid']])) { sqlf("DELETE FROM `sys_temptables` WHERE `threadid`='&1'", $r['threadid']); } } sql_free_result($rs); }
function get_cache_condition_history($cache_id) { $rs = sql("SELECT `date`, `needs_maintenance`, `listing_outdated`\n\t\t FROM `cache_logs`\n\t\t WHERE `cache_id`='&1' AND (`needs_maintenance` IS NOT NULL OR `listing_outdated` IS NOT NULL)\n\t\t ORDER BY `date`, `id`", $cache_id); $nm = $lo = 0; $cond = array(array('needs_maintenance' => $nm, 'listing_outdated' => $lo, 'date' => '0000-00-00 00:00:00')); while ($r = sql_fetch_assoc($rs)) { if ($r['needs_maintenance'] != $nm || $r['listing_outdated'] != $lo) { $nm = $r['needs_maintenance']; $lo = $r['listing_outdated']; $cond[] = array('needs_maintenance' => $nm, 'listing_outdated' => $lo, 'date' => $r['date']); } } sql_free_result($rs); $cond[] = array('needs_maintenance' => $nm, 'listing_outdated' => $lo, 'date' => '9999-12-31 23:59:59'); return $cond; }
function pAppendSites($parentId, $viewall, $sublevel, &$aItems) { global $opt; $rs = sql("SELECT `sys_menu`.`id`, \n\t IF(`sys_menu`.`title`='', \n\t IFNULL(`ttMenu`.`text`, `sys_menu`.`menustring`), \n\t IFNULL(`ttTitle`.`text`, `sys_menu`.`title`)) AS `name`, \n\t IF(SUBSTR(`sys_menu`.`href`,1,1)='!', SUBSTR(`sys_menu`.`href`,2), `sys_menu`.`href`) AS `href`,\n\t SUBSTR(`sys_menu`.`href`,1,1)='!' AS `blanktarget`,\n\t `sys_menu`.`sitemap` \n\t FROM `sys_menu` \n\t LEFT JOIN `sys_trans` AS `tTitle` ON `sys_menu`.`title_trans_id`=`tTitle`.`id` AND `sys_menu`.`title`=`tTitle`.`text` \n\t LEFT JOIN `sys_trans_text` AS ttTitle ON `tTitle`.`id`=`ttTitle`.`trans_id` AND `ttTitle`.`lang`='&2' \n\t LEFT JOIN `sys_trans` AS `tMenu` ON `sys_menu`.`menustring_trans_id`=`tMenu`.`id` AND `sys_menu`.`menustring`=`tMenu`.`text` \n\t LEFT JOIN `sys_trans_text` AS `ttMenu` ON `tMenu`.`id`=`ttMenu`.`trans_id` AND `ttMenu`.`lang`='&2' \n\t WHERE `sys_menu`.`access`=0 AND `sys_menu`.`parent`='&1' AND (&3=1 OR `sys_menu`.`sitemap`=1)\n\t ORDER BY `sys_menu`.`parent` ASC, `sys_menu`.`position` ASC", $parentId, $opt['template']['locale'], $viewall ? 1 : 0); while ($r = sql_fetch_assoc($rs)) { $r['sublevel'] = $sublevel; $aItems[] = $r; /* * pAppendSites($r['id'], $viewall, $sublevel+1, &$aItems); * * http://www.php.net/manual/en/language.references.pass.php * As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);. * And as of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error. * */ pAppendSites($r['id'], $viewall, $sublevel + 1, $aItems); } sql_free_result($rs); }
function discard_recommendation($log_id) { $rsLog = sql("SELECT\n `cache_logs`.`cache_id`,\n `cache_logs`.`user_id`,\n `cache_rating`.`rating_date` IS NOT NULL AS `is_rating_log`\n FROM `cache_logs`\n LEFT JOIN `cache_rating`\n ON `cache_rating`.`cache_id`=`cache_logs`.`cache_id`\n AND `cache_rating`.`user_id`=`cache_logs`.`user_id`\n AND `cache_rating`.`rating_date`=`cache_logs`.`date`\n WHERE\n `cache_logs`.`id`='&1' AND `cache_logs`.`type` IN (1,7)", $log_id); if ($rLog = sql_fetch_assoc($rsLog)) { $rsFirstOtherFound = sql("SELECT `date` FROM `cache_logs`\n WHERE `cache_id`='&1' AND `user_id`='&2' AND `id`<>'&3' AND `type` IN (1,7)\n ORDER BY `date`\n LIMIT 1", $rLog['cache_id'], $rLog['user_id'], $log_id); $rFirstOtherFound = sql_fetch_assoc($rsFirstOtherFound); sql_free_result($rsFirstOtherFound); if ($rLog['is_rating_log'] && $rFirstOtherFound) { sql("UPDATE `cache_rating`\n SET `rating_date`='&3'\n WHERE `cache_id`='&1' AND `user_id`='&2'", $rLog['cache_id'], $rLog['user_id'], $rFirstOtherFound['date']); // This will trigger an cache_logs.last_modified update of the corresponding // log, so that XML interface will resend it with the updated // "recommendation" flag. } elseif (!$rFirstOtherFound) { // This is also called for $rLog['is_rating_log'] == false, so that // even a rating record with inconsistent date gets deleted. sql("DELETE FROM `cache_rating` WHERE `cache_id` = '&1' AND `user_id` = '&2'", $rLog['cache_id'], $rLog['user_id']); } } sql_free_result($rsLog); }
function ConvertToWGS84($table) { $n = 1; $pks = array(); $val = array(); $rs = sql("SELECT * FROM `bfn`.`" . sql_escape($table) . "`"); while ($r = sql_fetch_assoc($rs)) { $pks[] = array('GID' => $r['GID'], 'ESEQ' => $r['ESEQ'], 'SEQ' => $r['SEQ']); $val[] = array('X1' => $r['X1'], 'X2' => $r['X2'], 'Y1' => $r['Y1'], 'Y2' => $r['Y2']); if (count($pks) >= 1000) { flushToDB($table, $pks, $val); $pks = array(); $val = array(); echo $table . ' ' . $n . "\n"; } $n = $n + 1; } sql_free_result($rs); flushToDB($table, $pks, $val); }