You are here

function notify_user_settings_form_submit in Notify 7

Same name and namespace in other branches
  1. 5.2 notify.module \notify_user_settings_form_submit()
  2. 5 notify.module \notify_user_settings_form_submit()
  3. 6 notify.module \notify_user_settings_form_submit()

Submit for the notify_user_settings form.

File

./notify.admin.inc, line 1077
Administrative pages callbacks for the Notify module.

Code

function notify_user_settings_form_submit($form, &$form_state) {
  unset($form);
  $uid = $form_state['values']['uid'];
  db_delete('notify')
    ->condition('uid', $uid)
    ->execute();
  $id = db_insert('notify')
    ->fields(array(
    'uid' => $uid,
    'status' => $form_state['values']['status'],
    'node' => $form_state['values']['node'],
    'teasers' => $form_state['values']['teasers'],
    'comment' => $form_state['values']['comment'],
  ))
    ->execute();
  $subscriptions = array();

  // Remember that this is a custom subscriber.
  $subscriber = _notify_user_has_subscriptions($uid);
  if (!$subscriber) {
    db_insert('notify_subscriptions')
      ->fields(array(
      'uid' => $uid,
      'type' => 'magic custom subscription',
    ))
      ->execute();
  }
  foreach ($form_state['values'] as $key => $value) {
    if (preg_match("/^" . NOTIFY_NODE_TYPE . "/", $key)) {
      $key = substr($key, 17);
      $id = db_query('SELECT id FROM {notify_subscriptions} WHERE (uid = :uid) AND (type = :key)', array(
        ':uid' => $uid,
        ':key' => $key,
      ))
        ->fetchObject();
      if ($id) {
        $id = $id->id;
        if (!$value) {
          db_delete('notify_subscriptions')
            ->condition('id', $id)
            ->execute();
        }
      }
      else {
        if ($value) {
          db_insert('notify_subscriptions')
            ->fields(array(
            'uid' => $uid,
            'type' => $key,
          ))
            ->execute();
        }
      }
    }
  }
  drupal_set_message(t('Notify settings saved.'));
}