home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / drupal-6.0.exe / drupal-6.0 / modules / update / update.settings.inc < prev   
Encoding:
Text File  |  2007-10-20  |  3.9 KB  |  109 lines

  1. <?php
  2. // $Id: update.settings.inc,v 1.3 2007/10/20 21:57:50 goba Exp $
  3.  
  4. /**
  5.  * @file
  6.  * Code required only for the update status settings form.
  7.  */
  8.  
  9. /**
  10.  * Form builder for the update settings tab.
  11.  */
  12. function update_settings() {
  13.   $form = array();
  14.  
  15.   $notify_emails = variable_get('update_notify_emails', array());
  16.   $form['update_notify_emails'] = array(
  17.     '#type' => 'textarea',
  18.     '#title' => t('E-mail addresses to notify when updates are available'),
  19.     '#rows' => 4,
  20.     '#default_value' => implode("\n", $notify_emails),
  21.     '#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.'),
  22.   );
  23.  
  24.   $form['update_check_frequency'] = array(
  25.     '#type' => 'radios',
  26.     '#title' => t('Check for updates'),
  27.     '#default_value' => variable_get('update_check_frequency', 1),
  28.     '#options' => array(
  29.       '1' => t('Daily'),
  30.       '7' => t('Weekly'),
  31.     ),
  32.     '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
  33.   );
  34.  
  35.   $form['update_notification_threshold'] = array(
  36.     '#type' => 'radios',
  37.     '#title' => t('Notification threshold'),
  38.     '#default_value' => variable_get('update_notification_threshold', 'all'),
  39.     '#options' => array(
  40.       'all' => t('All newer versions'),
  41.       'security' => t('Only security updates'),
  42.     ),
  43.     '#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')))
  44.   );
  45.  
  46.   $form = system_settings_form($form);
  47.   // Custom valiation callback for the email notification setting.
  48.   $form['#validate'][] = 'update_settings_validate';
  49.   // We need to call our own submit callback first, not the one from
  50.   // system_settings_form(), so that we can process and save the emails.
  51.   unset($form['#submit']);
  52.  
  53.   return $form;
  54. }
  55.  
  56. /**
  57.  * Validation callback for the settings form.
  58.  *
  59.  * Validates the email addresses and ensures the field is formatted correctly.
  60.  */
  61. function update_settings_validate($form, &$form_state) {
  62.   if (!empty($form_state['values']['update_notify_emails'])) {
  63.     $valid = array();
  64.     $invalid = array();
  65.     foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
  66.       $email = trim($email);
  67.       if (!empty($email)) {
  68.         if (valid_email_address($email)) {
  69.           $valid[] = $email;
  70.         }
  71.         else {
  72.           $invalid[] = $email;
  73.         }
  74.       }
  75.     }
  76.     if (empty($invalid)) {
  77.       $form_state['notify_emails'] = $valid;
  78.     }
  79.     elseif (count($invalid) == 1) {
  80.       form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));
  81.     }
  82.     else {
  83.       form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));
  84.     }
  85.   }
  86. }
  87.  
  88. /**
  89.  * Submit handler for the settings tab.
  90.  */
  91. function update_settings_submit($form, $form_state) {
  92.   $op = $form_state['values']['op'];
  93.  
  94.   if ($op == t('Reset to defaults')) {
  95.     unset($form_state['notify_emails']);
  96.   }
  97.   else {
  98.     if (empty($form_state['notify_emails'])) {
  99.       variable_del('update_notify_emails');
  100.     }
  101.     else {
  102.       variable_set('update_notify_emails', $form_state['notify_emails']);
  103.     }
  104.     unset($form_state['notify_emails']);
  105.     unset($form_state['values']['update_notify_emails']);
  106.   }
  107.   system_settings_form_submit($form, $form_state);
  108. }
  109.