00001 <?php
00002
00003
00012 function update_settings() {
00013 $form = array();
00014
00015 $notify_emails = variable_get('update_notify_emails', array());
00016 $form['update_notify_emails'] = array(
00017 '#type' => 'textarea',
00018 '#title' => t('E-mail addresses to notify when updates are available'),
00019 '#rows' => 4,
00020 '#default_value' => implode("\n", $notify_emails),
00021 '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'),
00022 );
00023
00024 $form['update_check_frequency'] = array(
00025 '#type' => 'radios',
00026 '#title' => t('Check for updates'),
00027 '#default_value' => variable_get('update_check_frequency', 1),
00028 '#options' => array(
00029 '1' => t('Daily'),
00030 '7' => t('Weekly'),
00031 ),
00032 '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
00033 );
00034
00035 $form['update_notification_threshold'] = array(
00036 '#type' => 'radios',
00037 '#title' => t('Notification threshold'),
00038 '#default_value' => variable_get('update_notification_threshold', 'all'),
00039 '#options' => array(
00040 'all' => t('All newer versions'),
00041 'security' => t('Only security updates'),
00042 ),
00043 '#description' => t('If there are updates available of Drupal core or any of your installed modules and themes, your site will print an error message on the <a href="@status_report">status report</a>, the <a href="@modules_page">modules page</a>, and the <a href="@themes_page">themes page</a>. You can choose to only see these error messages if a security update is available, or to be notified about any newer versions.', array('@status_report' => url('admin/reports/status'), '@modules_page' => url('admin/build/modules'), '@themes_page' => url('admin/build/themes')))
00044 );
00045
00046 $form = system_settings_form($form);
00047
00048 $form['#validate'][] = 'update_settings_validate';
00049
00050
00051 unset($form['#submit']);
00052
00053 return $form;
00054 }
00055
00061 function update_settings_validate($form, &$form_state) {
00062 if (!empty($form_state['values']['update_notify_emails'])) {
00063 $valid = array();
00064 $invalid = array();
00065 foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
00066 $email = trim($email);
00067 if (!empty($email)) {
00068 if (valid_email_address($email)) {
00069 $valid[] = $email;
00070 }
00071 else {
00072 $invalid[] = $email;
00073 }
00074 }
00075 }
00076 if (empty($invalid)) {
00077 $form_state['notify_emails'] = $valid;
00078 }
00079 elseif (count($invalid) == 1) {
00080 form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));
00081 }
00082 else {
00083 form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));
00084 }
00085 }
00086 }
00087
00091 function update_settings_submit($form, $form_state) {
00092 $op = $form_state['values']['op'];
00093
00094 if ($op == t('Reset to defaults')) {
00095 unset($form_state['notify_emails']);
00096 }
00097 else {
00098 if (empty($form_state['notify_emails'])) {
00099 variable_del('update_notify_emails');
00100 }
00101 else {
00102 variable_set('update_notify_emails', $form_state['notify_emails']);
00103 }
00104 unset($form_state['notify_emails']);
00105 unset($form_state['values']['update_notify_emails']);
00106 }
00107 system_settings_form_submit($form, $form_state);
00108 }