function block_weather_es_contents in Weather_es 5
Same name and namespace in other branches
- 6.3 weather_es.module \block_weather_es_contents()
- 6 weather_es.module \block_weather_es_contents()
- 6.2 weather_es.module \block_weather_es_contents()
Show the weather_es contents
1 call to block_weather_es_contents()
- weather_es_block in ./
weather_es.module - Implementation of hook_block().
File
- ./
weather_es.module, line 397 - Non-displayable characters.
Code
function block_weather_es_contents($which_block) {
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);
}
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 wed.cod_loc = %d ORDER BY wed.did ASC";
$result = pager_query(db_rewrite_sql($sql), 2, 0, "SELECT COUNT(cod_loc) FROM {weather_es_data} WHERE cod_loc = %d", $usrcnf->cod_loc, $usrcnf->cod_loc);
// Show the data by the theme
while ($data = db_fetch_object($result)) {
$content .= theme('weather_es', $data, $usrcnf);
}
$content .= theme('pager', NULL, NULL);
}
return $content;
}