Index: modules/user/user.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v
retrieving revision 1.25
diff -u -p -r1.25 user.admin.inc
--- modules/user/user.admin.inc	6 Sep 2008 08:36:22 -0000	1.25
+++ modules/user/user.admin.inc	9 Sep 2008 09:27:21 -0000
@@ -412,12 +412,6 @@ function user_admin_settings() {
     '#options' => array(t('Disabled'), t('Enabled')),
   );
 
-  // If picture support is enabled, check whether the picture directory exists:
-  if (variable_get('user_pictures', 0)) {
-    $picture_path = file_create_path(variable_get('user_picture_path', 'pictures'));
-    file_check_directory($picture_path, 1, 'user_picture_path');
-  }
-
   $form['pictures'] = array(
     '#type' => 'fieldset',
     '#title' => t('Pictures'),
@@ -451,14 +445,19 @@ function user_admin_settings() {
     '#maxlength' => 255,
     '#description' => t('Subdirectory in the directory %dir where pictures will be stored.', array('%dir' => file_directory_path() . '/')),
   );
-  $form['pictures']['settings']['user_picture_default'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Default picture'),
-    '#default_value' => variable_get('user_picture_default', ''),
-    '#size' => 30,
-    '#maxlength' => 255,
-    '#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'),
-  );
+  
+  if (variable_get('user_picture_default', '')) {
+    $picture = theme('user_picture', (object)array('name' => ''));
+    $form['pictures']['settings']['user_current_default_picture'] = array('#markup' => $picture);
+    $form['pictures']['settings']['user_picture_default_delete'] = array('#type' => 'checkbox', '#title' => t('Delete default picture'), '#description' => t('Check this box to delete your current default picture.'));
+  }
+  else {
+    $form['pictures']['settings']['user_picture_default_delete'] = array('#type' => 'hidden');
+  }
+  $form['pictures']['settings']['user_picture_default_upload'] = array('#type' => 'file', '#title' => t('Upload default picture'), '#size' => 48, '#description' => t('Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))));
+  $form['#validate'][] = 'user_validate_default_picture';
+  $form['#attributes'] = array('enctype' => "multipart/form-data");
+    
   $form['pictures']['settings']['user_picture_dimensions'] = array(
     '#type' => 'textfield',
     '#title' => t('Picture maximum dimensions'),
@@ -485,6 +484,50 @@ function user_admin_settings() {
   return system_settings_form($form);
 }
 
+function user_validate_default_picture(&$form, &$form_state) {
+  // If picture support is enabled, check whether the picture directory exists:
+  if ($form_state['values']['user_pictures'] == 1) {
+    $picture_path = file_create_path(variable_get('user_picture_path', 'pictures'));
+    file_check_directory($picture_path, 1, 'user_picture_path');
+  }
+  
+  // If required, validate the uploaded picture.
+  $validators = array(
+    'file_validate_is_image' => array(),
+    'file_validate_image_resolution' => array($form_state['values']['user_picture_dimensions']),
+    'file_validate_size' => array($form_state['values']['user_picture_file_size'] * 1024),
+  );
+  if ($file = file_save_upload('user_picture_default_upload', $validators)) {
+    // Remove the old picture.
+    $old_default = variable_get('user_picture_default', '');
+    if ($old_default && file_exists($old_default)) {
+      file_delete($old_default);
+    }
+
+    // The image was saved using file_save_upload() and was added to the
+    // files table as a temporary file. We'll make a copy and let the garbage
+    // collector delete the original upload.
+    $info = image_get_info($file->filepath);
+    $destination = $form_state['values']['user_picture_path'] . '/picture-default.' . $info['extension'];
+    if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
+      $form_state['values']['user_picture_default'] = $file->filepath;
+    }
+    else {
+      form_set_error('user_picture_default_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array('%directory' => $form_state['values']['user_picture_path'])));
+    }
+  }
+  if (!empty($form_state['values']['user_picture_default_delete'])) {
+    $default = variable_get('user_picture_default', '');
+    if ($default && file_exists($default)) {
+      file_delete($default);
+      $form_state['values']['user_picture_default'] = '';
+    }
+  }
+  unset($form_state['values']['user_picture_default_upload']);
+  unset($form_state['values']['user_picture_default_delete']);
+}
+
+
 /**
  * Menu callback: administer permissions.
  *
