You are here

function imagepicker_edit_form_submit in Image Picker 5.2

Same name and namespace in other branches
  1. 5 imagepicker.module \imagepicker_edit_form_submit()

Submit edit form

File

./imagepicker.module, line 858
Enables permitted roles to upload images for insertion into configured nodes.

Code

function imagepicker_edit_form_submit($form_id, $form_values) {
  if ($form_values['op'] == t('Submit')) {
    $img_id = $form_values['img_id'];
    $src = $form_values['src'];
    if ($form_values['account'] && $src == 'admin') {
      $user = user_load(array(
        'uid' => $form_values['account'],
      ));
    }
    else {
      global $user;
    }
    if ($src == 'admin' && $form_values['account']) {
      $img = _imagepicker_get_img($img_id, FALSE, $user);
    }
    elseif ($src == 'account') {
      $img = _imagepicker_get_img($img_id);
    }
    else {
      $img = _imagepicker_get_img($img_id);
    }
    if ($img) {
      $title = htmlspecialchars($form_values['title']);
      $description = htmlspecialchars($form_values['description']);
      if (db_query("UPDATE {imagepicker} SET img_title = '%s', img_description = '%s' WHERE img_id = '%d'", array(
        $title,
        $description,
        $img_id,
      ))) {
        drupal_set_message(t('Image was successfully updated.'));
        if ($src == 'account') {
          $outpath = 'user/' . $user->uid . '/imagepicker/images/browse/' . $img_id;
        }
        elseif ($src == 'admin') {
          $outpath = 'admin/settings/imagepicker/images/user/' . $user->uid . '/browse/' . $img_id;
        }
        else {
          $outpath = 'imagepicker/browse/' . $img_id;
        }
        drupal_goto($outpath);
      }
      else {
        drupal_set_message(t('Error while updating image.'), 'error');
      }
    }
    else {
      drupal_set_message(t('Image not found.'), 'error');
    }
  }
  if ($src == 'account') {
    $outpath = 'user/' . $user->uid . '/imagepicker/images';
  }
  elseif ($src == 'admin') {
    $outpath = 'admin/settings/imagepicker/images';
  }
  else {
    $outpath = 'imagepicker/browse';
  }
  drupal_goto($outpath);
}