You are here

function dynamic_background_admin_images_validate in Dynamic Background 7.2

Same name and namespace in other branches
  1. 6 includes/backgrounds.admin.inc \dynamic_background_admin_images_validate()
  2. 7 includes/backgrounds.admin.inc \dynamic_background_admin_images_validate()

The administration images form validator form. It handles uploading the image and deletion if the checkbox is flaged.

1 string reference to 'dynamic_background_admin_images_validate'
dynamic_background_admin_images in includes/backgrounds.admin.inc
The image administation form.

File

includes/backgrounds.admin.inc, line 132
Implementation of the administration image upload and selecton form.

Code

function dynamic_background_admin_images_validate($form, &$form_state) {
  if (isset($form_state['submit_handlers']) && $form_state['submit_handlers'][0] == 'dynamic_background_admin_images_add_one') {
    return;
  }

  // Load settings.
  $settings = variable_get('dynamic_background_setting', array());

  // Validate the file extension (move to config, with upload path).
  $validators = array(
    'file_validate_extensions' => array(
      $settings['extensions'],
    ),
  );

  // Loop through all uploaded files.
  if (!empty($_FILES)) {
    foreach ($_FILES['files']['name'] as $file_field => $val) {
      if ($val == '') {
        continue;
      }

      // Save the image.
      try {
        dynamic_background_save_image($file_field, 'default', -1);
      } catch (Exception $e) {
        form_set_error('default', $e
          ->getMessage());
      }
    }
  }

  // Check for image deletion.
  foreach ($form_state['values'] as $field => $data) {
    if (preg_match('/^image_(\\d{1,4})/', $field) && isset($data['picture_delete']) && $data['picture_delete']) {
      try {

        // Delete the image.
        dynamic_background_delete_image($data['fid']);
      } catch (Exception $e) {
        form_set_error($field, $e
          ->getMessage());
      }
    }
  }
}