You are here

function imagepicker_edit_form_do in Image Picker 6.2

Same name and namespace in other branches
  1. 7 imagepicker.edit.inc \imagepicker_edit_form_do()
1 string reference to 'imagepicker_edit_form_do'
imagepicker_edit_form in ./imagepicker.edit.inc

File

./imagepicker.edit.inc, line 97
Contains the functions pertaining to editing image information

Code

function imagepicker_edit_form_do($form, &$form_state) {
  $img_id = $form_state['values']['img_id'];
  $src = $form_state['values']['src'];
  if (isset($form_state['values']['account']) && $src == 'admin') {
    $user = user_load(array(
      'uid' => $form_state['values']['account'],
    ));
  }
  else {
    global $user;
  }
  if ($src == 'admin') {
    $outpath = IMAGEPICKER_ADMIN_PATH . '/images/user/' . $user->uid . '/browse/' . $img_id;
  }
  elseif ($src == 'account') {
    $outpath = 'user/' . $user->uid . '/imagepicker/images/browse/' . $img_id;
  }
  else {
    $outpath = 'imagepicker/browse/' . $img_id;
  }
  $result = db_query_range("SELECT uid, img_name FROM {imagepicker} WHERE img_id = '%d'", $img_id, 0, 1);
  $img = db_fetch_array($result);
  if ($img) {
    if ($img['uid'] == $user->uid) {
      $title = $form_state['values']['title'];
      $description = $form_state['values']['description'];
      if (drupal_strlen($description) > 254) {
        $description = drupal_substr($description, 0, 254);
      }
      $date = time();
      if (db_query("UPDATE {imagepicker} SET img_title = '%s', img_description = '%s', img_date = '%s' WHERE img_id = '%d'", array(
        check_plain($title),
        check_plain($description),
        $date,
        $img_id,
      ))) {
        drupal_set_message(t('Image was successfully updated.'));
        drupal_goto($outpath);
      }
      else {
        drupal_set_message(t('Error while updating image.'));
      }
    }
    else {
      drupal_set_message(t('This image does not belong to you.'), 'error');
      watchdog('imagepicker', 'User uid %d attempted to edit image belonging to user uid %d', array(
        $user->uid,
        $img['uid'],
      ), WATCHDOG_WARNING);
    }
  }
  else {
    drupal_set_message(t('Image not found.'), 'error');
  }
  drupal_goto($outpath);
}