function block_weather_es_contents in Weather_es 6.2
Same name and namespace in other branches
- 5 weather_es.module \block_weather_es_contents()
- 6.3 weather_es.module \block_weather_es_contents()
- 6 weather_es.module \block_weather_es_contents()
Show the weather_es contents
2 calls to block_weather_es_contents()
File
- ./
weather_es.module, line 405 - Shows weather data of Spain (by AEMET)
Code
function block_weather_es_contents($which_block, $page = 1) {
global $user;
$sql = "SELECT * FROM {weather_es_config} wec WHERE wec.uid = %d";
// Block 0 is about the site, 1 is about the user
if ($which_block == 0) {
$usrcnfresult = db_query(db_rewrite_sql($sql), 0);
}
else {
$usrcnfresult = db_query(db_rewrite_sql($sql), $user->uid);
}
$content .= '<div id="weather_es_container-' . $which_block . '" class="weather_es_container">';
while ($usrcnf = db_fetch_object($usrcnfresult)) {
// Update ancient data
if ($usrcnf->pro_act < time()) {
if ($which_block == 0) {
$wuid = 0;
}
else {
$wuid = $usrcnf->uid;
}
$ciudad = $usrcnf->cod_pro . $usrcnf->cod_loc;
$aemet = _weather_es_aemet($wuid, $usrcnf->cod_pro . $usrcnf->cod_loc, $usrcnf->lan, $usrcnf->cit_nam);
if ($aemet != -1) {
// Delete the previous city data and save the new one
db_query("DELETE FROM {weather_es_data} WHERE cod_pro = %d AND cod_loc = %d", $usrcnf->cod_pro, $usrcnf->cod_loc);
weather_es_save_data($usrcnf->cod_pro, $usrcnf->cod_loc, $aemet);
// Next connection to AEMET in 4h
db_query("UPDATE {weather_es_config} SET pro_act = %d WHERE uid = %d AND cod_pro = %d AND cod_loc = %d", time() + 4 * 3600, $wuid, $usrcnf->cod_pro, $usrcnf->cod_loc);
}
else {
// The connection with AEMET has failt, try in 10'
db_query("UPDATE {weather_es_config} SET pro_act = %d WHERE uid = %d AND cod_pro = %d AND cod_loc = %d", time() + 10 * 60, $wuid, $cod_pro, $cod_loc);
}
}
$content .= '<strong>' . check_markup($usrcnf->cit_nam) . '</strong>';
$content .= t('<small><strong>Weather forecast by AEMET.</strong></small>');
$sql = "SELECT * FROM {weather_es_data} wed WHERE cod_pro = %d AND wed.cod_loc = %d ORDER BY wed.did ASC";
$result = db_query_range(db_rewrite_sql($sql), $usrcnf->cod_pro, $usrcnf->cod_loc, 2 * ($page - 1), 2);
// Show the data by the theme
while ($data = db_fetch_object($result)) {
$content .= theme('weather_es', $data, $usrcnf);
}
}
return $content .= '</div>';
}