You are here

function photos_editlist_submit in Album Photos 6.2

Same name and namespace in other branches
  1. 7.3 inc/photos.edit.inc \photos_editlist_submit()
1 string reference to 'photos_editlist_submit'
photos_editlist in inc/photos.edit.inc

File

inc/photos.edit.inc, line 301

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_query('UPDATE {x_album} SET fid = 0 WHERE pid = %d', $form_state['values']['oldpid']);
      }
      $msg[] = photos_file_del($fid, $key['filepath']);
      $uids[] = $key['uid'];
    }
    else {
      db_query("UPDATE {x_image} SET pid = %d, des = '%s', wid = %d WHERE fid = %d", $key['pid'], $key['des'], $key['wid'], $fid);
      if ($key['filename'] != $key['oldfilename']) {
        db_query("UPDATE {files} SET filename = '%s' WHERE fid = %d", check_plain($key['filename']), $fid);
      }
      if ($key['pid'] != $form_state['values']['oldpid']) {
        db_query('UPDATE {comments} SET nid = %d WHERE cid IN (SELECT cid FROM {x_vote} WHERE fid = %d)', $key['pid'], $fid);
        $pid[] = $key['pid'];
        $uids[] = $key['uid'];
      }
    }
  }
  if ($msg) {
    $pid[] = $form_state['values']['oldpid'];
    drupal_set_message(t('%count images are deleted.', array(
      '%count' => count($msg),
    )));
  }
  if (count($pid)) {
    foreach ($pid as $nid) {
      _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);
    }
  }
}