function weather_es_form_submit in Weather_es 7
Same name and namespace in other branches
- 6.3 weather_es.module \weather_es_form_submit()
@author jmsirvent
2 string references to 'weather_es_form_submit'
- weather_es_edit_form in ./
weather_es.module - @author jmsirvent
- weather_es_modify_form in ./
weather_es.module - @author jmsirvent
File
- ./
weather_es.module, line 410
Code
function weather_es_form_submit($form, &$form_state) {
// There's only a AHAH sent...
if (!empty($form_state['ahah_submission'])) {
$form_state['rebuild'] = FALSE;
return;
}
// Get data from AEMET
$aemet = new weather_es_Aemet($form_state['values']['combo']['ciudad']);
if ($aemet
->getName() != '') {
// Save a new user configuration or rewrite an existing one
//if ($_POST['op'] == t('Save configuration')) {
if ($form_state['clicked_button']['#value'] == t('Save configuration')) {
// Delete previous user configuration
db_delete('weather_es_conf')
->condition('wid', array(
':wid' => $form_state['storage']['wid'],
))
->execute();
}
// Avoid adding a city already in the user configuration
if (!db_query("SELECT COUNT(wid) FROM {weather_es_conf} WHERE wid = :wid AND cit_cod = :cod", array(
':wid' => $form_state['storage']['wid'],
':cod' => $form_state['values']['combo']['ciudad'],
))
->fetchField()) {
// Save configuration data
// TODO full info
//_weather_es_conf_save($form_state['storage']['wid'], $form_state['values']['combo']['ciudad'], $form_state['values']['idioma'], serialize(array_filter($form_state['values']['informacion'])), $form_state['values']['cantidad']);
_weather_es_conf_save($form_state['storage']['wid'], $form_state['values']['combo']['ciudad'], 'en', serialize(array_filter($form_state['values']['informacion'])), 're');
}
else {
// Change an old configuration
// TODO full info
//_weather_es_conf_update($form_state['storage']['wid'], $form_state['values']['combo']['ciudad'], $form_state['values']['idioma'], $form_state['values']['informacion'], $form_state['values']['cantidad']);
_weather_es_conf_update($form_state['storage']['wid'], $form_state['values']['combo']['ciudad'], 'en', serialize(array_filter($form_state['values']['informacion'])), 're');
}
// Delete the previous city data and save the new one
db_delete('weather_es_data')
->condition('cit_cod', array(
':cit_cod' => $form_state['values']['combo']['ciudad'],
))
->execute();
//$cities = _weather_es_cities($form_state['values']['combo']['provincia']);
$cities = _weather_es_cities(substr($form_state['values']['combo']['ciudad'], 0, 2));
_weather_es_data_save($form_state['values']['combo']['ciudad'], $cities[$form_state['values']['combo']['ciudad']], serialize($aemet));
drupal_set_message(t('Config save for: %city.', array(
'%city' => $cities[$form_state['values']['combo']['ciudad']],
)));
}
else {
// The connection with AEMET has failt, try in 10'
db_update('weather_es_data')
->fields(array(
'nex_upd' => time() + 10 * 60,
))
->condition('cit_cod', $form_state['values']['combo']['ciudad'])
->execute();
drupal_set_message(t('The connection with AEMET has failt.'));
}
// Redirect the user to the table. $form['#redirect'] and $form_state['redirect'] don't work...
drupal_goto(_weather_es_redirect($form_state['storage']['wid']));
}