You are here

function photos_editlist_submit in Album Photos 7.3

Same name and namespace in other branches
  1. 6.2 inc/photos.edit.inc \photos_editlist_submit()

Submit modifications to existing images.

1 string reference to 'photos_editlist_submit'
photos_editlist_form in inc/photos.edit.inc
Edit list form.

File

inc/photos.edit.inc, line 889
Handles uploading and editing images.

Code

function photos_editlist_submit($form, &$form_state) {
  foreach ($form_state['values']['photos'] as $fid => $key) {
    if (!empty($key['del'])) {
      if ($form_state['values']['cover_fid'] == $fid) {
        db_update('photos_album')
          ->fields(array(
          'fid' => 0,
        ))
          ->condition('pid', $form_state['values']['oldpid'])
          ->execute();
      }
      $msg[] = photos_file_del($fid, $key['filepath']);
      $uids[] = $key['uid'];
    }
    else {
      db_update('photos_image')
        ->fields(array(
        'pid' => $key['pid'],
        'des' => $key['des'],
        'wid' => $key['wid'],
      ))
        ->condition('fid', $fid)
        ->execute();
      if ($key['title'] != $key['oldtitle']) {
        db_update('photos_image')
          ->fields(array(
          'title' => $key['title'],
        ))
          ->condition('fid', $fid)
          ->execute();
      }
      if ($key['pid'] != $form_state['values']['oldpid']) {
        $sub_select = db_select('photos_comment', 'v')
          ->fields('v', array(
          'cid',
        ))
          ->condition('v.fid', $fid)
          ->execute()
          ->fetchCol();
        if (!empty($sub_select)) {
          db_update('comment')
            ->fields(array(
            'nid' => $key['pid'],
          ))
            ->condition('cid', $sub_select, 'IN')
            ->execute();
        }
        $pid[] = $key['pid'];
        $uids[] = $key['uid'];
      }
    }
  }
  if (isset($msg)) {
    $pid[] = $form_state['values']['oldpid'];
    drupal_set_message(t('%count images are deleted.', array(
      '%count' => count($msg),
    )));
  }
  if (isset($pid) && count($pid)) {
    foreach ($pid as $nid) {
      if (module_exists('comment')) {
        _comment_update_node_statistics($nid);
      }
      photos_set_count('node_album', $nid);
    }
    $uid = array_unique($uids);
    foreach ($uid as $id) {
      photos_set_count('user_image', $id);
    }
  }
}