/** * Menu callback; show admininster user notification settings form. */ function notify_admin() { $result = db_query('SELECT u.uid, u.name, u.mail, n.* FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE n.status = 1 AND u.status = 1 ORDER BY u.name'); $form = array(); $form['#tree'] = TRUE; $form['#theme'] = 'notify_admin_default'; $form['info'] = array('#type' => 'markup', '#value' => ''. t('The following table shows all users that have notifications enabled.') .''); while ($notify = db_fetch_object($result)) { $form['users'][$notify->uid]['name'] = array('#type' => 'markup', '#value' => theme('username', $notify)); $form['users'][$notify->uid]['mail'] = array('#type' => 'markup', '#value' => $notify->mail); $form['users'][$notify->uid]['node'] = array('#type' => 'checkbox', '#default_value' => $notify->node); $form['users'][$notify->uid]['teasers'] = array('#type' => 'select', '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body'))); $form['users'][$notify->uid]['comment'] = array('#type' => 'checkbox', '#default_value' => $notify->comment); $form['users'][$notify->uid]['attempts'] = array('#type' => 'markup', '#value' => $notify->attempts ? intval($notify->attempts) : 0); } $form['submit'] = array('#type' => 'button', '#value' => t('Save'), '#submit' => TRUE); $form['submitandsendnow'] = array('#type' => 'button', '#value' => t('Save and send now'), '#submit' => TRUE); return drupal_get_form('notify_admin', $form); } function notify_admin_validate($form_id, $form_values, $form) { dprint_r($form_values); dprint_r($_POST); dprint_r('validated'); } /** * Submit for the notify_admin form. */ function notify_admin_submit($form_id, $form_values) { dprint_r($form_values); dprint_r($_POST); die('here'); if ($form_values['submitandsendnow'] == t('Save and send now')) { $status = _notify_send(); variable_set('notify_send_last', time()); cache_clear_all('variables'); if ($status['sent'] > 0) { drupal_set_message(t('%count pending notification e-mails have been sent.', array('%count' => $status['sent']))); } elseif ($status['failed'] > 0) { drupal_set_message(t('%count notification e-mails could not be sent.', array('%count' => $status['failed'])), 'error'); } else { drupal_set_message(t('No notification e-mails needed to be sent.')); } } foreach ($form_values['users'] as $uid => $settings) { db_query('UPDATE {notify} SET node = %d, teasers = %d, comment = %d WHERE uid = %d', $settings['node'], $settings['teasers'], $settings['comment'], $uid); } drupal_set_message(t('Notify settings saved.')); return ''; }