function imagepicker_edit_form_do in Image Picker 7
Same name and namespace in other branches
- 6.2 imagepicker.edit.inc \imagepicker_edit_form_do()
1 string reference to 'imagepicker_edit_form_do'
File
- ./
imagepicker.edit.inc, line 104 - @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
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($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;
}
$query = db_select('imagepicker', 'i');
$query
->fields('i', array(
'uid',
'img_name',
));
$query
->range(0, 1);
$query
->condition('img_id', $img_id);
$img = $query
->execute()
->fetchObject();
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();
$num_updated = db_update('imagepicker')
->fields(array(
'img_title' => check_plain($title),
'img_description' => check_plain($description),
'img_date' => $date,
))
->condition('img_id', $img_id)
->execute();
if ($num_updated) {
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);
}