You are here

function node_expire_default_settings_form_submit in Node expire 6

Same name and namespace in other branches
  1. 5 node_expire.module \node_expire_default_settings_form_submit()

Implementation of hook_form_submit().

1 string reference to 'node_expire_default_settings_form_submit'
node_expire_default_settings_form in ./node_expire.admin.inc
Configuration form for default expirations for node_expire

File

./node_expire.admin.inc, line 265
Module settings.

Code

function node_expire_default_settings_form_submit(&$form, &$form_state) {

  // Do we want to reset to the defaults?
  if ($form_state['clicked_button']['#value'] == t('Save configuration')) {
    foreach ($form_state['values'] as $key => $val) {
      if (is_array($val) and isset($val['enabled']) and $val['enabled'] == TRUE) {

        //         $node_visibility[$key] = array(
        //           'enabled'         => TRUE,
        //           'expiremode' => $val['expiremode'],
        //           'expire_timefrom' => $val['expire_timefrom'],
        //           'expire'          => $val['expiremode'] == NODE_EXPIRE_ONUPDATE ? 0 : $val['expire'],
        //           'isroot'          => isset($val['isroot']) ? $val['isroot'] : FALSE,
        //         );
        $node_visibility[] = $key;
        $node_visibility_sql[] = "'%s'";
      }
    }

    // Delete expirations from database if they don't longer pertain to this module
    if (empty($node_visibility)) {
      db_query('DELETE FROM {node_expire}');
    }
    else {
      $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(', ', $node_visibility_sql) . ')', $node_visibility);
      while ($row = db_fetch_array($query)) {
        $delete[] = $row['nid'];
      }
      if (!empty($delete)) {

        // 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) . ')');
      }
    }
  }
}