function node_expire_default_settings_form_submit in Node expire 5
Same name and namespace in other branches
- 6 node_expire.admin.inc \node_expire_default_settings_form_submit()
Implementation of hook_form_submit()
File
- ./
node_expire.module, line 514 - Alerts administrators of possibly outdated materials and optionally unpublishes them.
Code
function node_expire_default_settings_form_submit($form_id, $form_values) {
// Do we want to reset to the defaults?
if ($form_values['op'] == t('Reset to defaults')) {
variable_del('node-expire-node-visibility');
drupal_set_message(t('Settings reset back to defaults.'));
}
else {
// Generate the settings as we need them for our module
$node_visibility = array();
foreach ($form_values as $key => $val) {
if (is_array($val) && isset($val['enabled']) && $val['enabled'] == true) {
$node_visibility[$key] = array(
'enabled' => true,
'expiration_type' => $val['expiration_type'],
'expire_timefrom' => $val['expire_timefrom'],
'expire' => $val['expiration_type'] == 'onupdate' ? '' : $val['expire'],
'isroot' => isset($val['isroot']) ? $val['isroot'] : false,
);
}
}
variable_set('node-expire-node-visibility', $node_visibility);
// Delete expirations from database if they no longer pertain to this module
if (count($node_visibility) == 0) {
db_query("DELETE FROM {node_expire}");
}
else {
$allowed = array();
foreach (array_keys($node_visibility) as $val) {
$allowed[] = "'" . $val . "'";
}
$query = db_query("SELECT a.nid FROM {node_expire} a LEFT JOIN {node} b on a.nid = b.nid WHERE b.type NOT IN (" . implode(', ', $allowed) . ")");
$delete = array();
while ($row = db_fetch_object($query)) {
$delete[] = $row->nid;
}
if (count($delete) > 0) {
// Using the normal db_query method, drupal escapes the quotes necessary for the query.
// This data should be safe anyways since it's pulling from the validated node types.
db_query("DELETE FROM {node_expire} WHERE nid IN(" . implode(', ', $delete) . ")");
}
}
drupal_set_message(t('Saved new settings.'));
}
}