function weather_es_save_data in Weather_es 6.2
Same name and namespace in other branches
- 5 weather_es.module \weather_es_save_data()
- 6 weather_es.module \weather_es_save_data()
Save the data
2 calls to weather_es_save_data()
- block_weather_es_contents in ./
weather_es.module - Show the weather_es contents
- weather_es_configuration_form_submit in ./
weather_es.module - Handle the submission of the custom weather_es block.
File
- ./
weather_es.module, line 537 - Shows weather data of Spain (by AEMET)
Code
function weather_es_save_data($cod_pro, $cod_loc, $aemet) {
// 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", $cod_pro, $cod_loc);
// Save the data of the three first days
// am
if ($aemet[1][0] == 'am') {
for ($i = 0; $i < 3; $i++) {
db_query("INSERT INTO {weather_es_data} (cod_pro, cod_loc, day, ampm, sky_txt1, sky_img1, sky_txt2, sky_img2, rain, snow, tmax, tmin, win_dir1, win_spd1, win_dir2, win_spd2, iv_max, rsk)\n VALUES(%d, %d, '%s', '%s', '%s', %d, '%s', %d, %d, '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s')", $cod_pro, $cod_loc, $aemet[0][$i], $aemet[1][2 * $i], $aemet[4][2 * $i], $aemet[3][2 * $i], $aemet[4][2 * $i + 1], $aemet[3][2 * $i + 1], $aemet[5][$i], $aemet[6][$i], $aemet[7][$i], $aemet[8][$i], $aemet[9][2 * $i], $aemet[10][2 * $i], $aemet[9][2 * $i + 1], $aemet[10][2 * $i + 1], $aemet[11][$i], $aemet[12][$i]);
}
}
else {
db_query("INSERT INTO {weather_es_data} (cod_pro, cod_loc, day, ampm, sky_txt2, sky_img2, rain, snow, tmax, tmin, win_dir1, win_spd1, iv_max, rsk)\n VALUES(%d, %d, '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', %d, %d, '%s')", $cod_pro, $cod_loc, $aemet[0][0], $aemet[1][0], $aemet[4][0], $aemet[3][0], $aemet[5][0], $aemet[6][0], $aemet[7][0], $aemet[8][0], $aemet[9][0], $aemet[10][0], $aemet[11][0], $aemet[12][0]);
for ($i = 1; $i < 3; $i++) {
db_query("INSERT INTO {weather_es_data} (cod_pro, cod_loc, day, ampm, sky_txt1, sky_img1, sky_txt2, sky_img2, rain, snow, tmax, tmin, win_dir1, win_spd1, win_dir2, win_spd2, iv_max, rsk)\n VALUES(%d, %d, '%s', '%s', '%s', %d, '%s', %d, %d, '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s')", $cod_pro, $cod_loc, $aemet[0][$i], $aemet[1][2 * $i - 1], $aemet[4][2 * $i - 1], $aemet[3][2 * $i - 1], $aemet[4][2 * $i], $aemet[3][2 * $i], $aemet[5][$i], $aemet[6][$i], $aemet[7][$i], $aemet[8][$i], $aemet[9][2 * $i - 1], $aemet[10][2 * $i - 1], $aemet[9][2 * $i], $aemet[10][2 * $i], $aemet[11][$i], $aemet[12][$i]);
}
}
// Rest of the week
if ($aemet[1][0] == 'am') {
$offset = 0;
}
else {
$offset = -1;
}
for ($i = 3; $i < 7; $i++) {
db_query("INSERT INTO {weather_es_data} (cod_pro, cod_loc, day, sky_txt1, sky_img1, rain, snow, tmax, tmin, win_dir1, win_spd1)\n VALUES(%d, %d, '%s', '%s', %d, %d, '%s', %d, %d, '%s', %d)", $cod_pro, $cod_loc, $aemet[0][$i], $aemet[4][$i + 3 + $offset], $aemet[3][$i + 3 + $offset], $aemet[5][$i], $aemet[6][$i], $aemet[7][$i], $aemet[8][$i], $aemet[9][$i + 3 + $offset], $aemet[10][$i + 3 + $offset]);
}
}