You are here

function simplelogin_background_form_submit in SimpleLogin 7

Implements of form submit function.

1 string reference to 'simplelogin_background_form_submit'
simplelogin_background_form in inc/simplelogin.inc
Implements of background image form.

File

inc/simplelogin.inc, line 35
The Login screens, which controls the customized background image.

Code

function simplelogin_background_form_submit($form, &$form_state) {
  global $user;
  if (isset($form_state['values']['login_bgimage']) && is_numeric($form_state['values']['login_bgimage']) && $form_state['values']['login_bgimage'] > 0) {
    $file = file_load($form_state['values']['login_bgimage']);
    $file->status = FILE_STATUS_PERMANENT;
    file_save($file);
    variable_set('simplelogin_fid', $file->fid);

    // Records that a module is using a file.
    file_usage_add($file, 'user', 'user', $user->uid);
    if ($file) {
      drupal_set_message(t('Image successfully uploaded.'), 'status');
    }
    else {
      form_set_error('image', t('Image was not uploaded.'));
    }
    unset($form_state['values']['login_bgimage']);
  }
  else {
    if (variable_get('simplelogin_fid', '') != '') {
      $file = file_load(variable_get('simplelogin_fid', ''));
      if ($file->fid) {

        // Delete the file and the usage record.
        file_delete($file, TRUE);
      }
      variable_set('simplelogin_fid', '');
    }
  }
}