You are here

function filedepotAjaxServer_moveCheckedFiles in filedepot 7

Same name and namespace in other branches
  1. 6 lib-ajaxserver.php \filedepotAjaxServer_moveCheckedFiles()
1 call to filedepotAjaxServer_moveCheckedFiles()
filedepot_dispatcher in ./ajaxserver.php

File

./lib-ajaxserver.php, line 1320
lib-ajaxserver.php Library functions for the ajax_server

Code

function filedepotAjaxServer_moveCheckedFiles() {
  global $user;
  $filedepot = filedepot_filedepot();
  $message = '';
  $retval = array();
  $cid = intval($_POST['cid']);
  $newcid = intval($_POST['newcid']);
  $reportmode = check_plain($_POST['reportmode']);
  $fileitems = check_plain($_POST['checkeditems']);
  $files = explode(',', $fileitems);
  $filedepot->cid = $cid;
  $filedepot->activeview = $reportmode;
  $movedfiles = 0;
  if ($newcid > 0 and $user->uid > 0) {
    foreach ($files as $id) {
      if ($id > 0) {
        if ($reportmode == 'incoming') {
          if ($filedepot
            ->moveIncomingFile($id, $newcid)) {
            $movedfiles++;
          }
        }
        else {
          if ($filedepot
            ->moveFile($id, $newcid)) {
            $movedfiles++;
          }
        }
      }
    }
  }
  if ($movedfiles > 0) {
    $message = "Successfully moved {$movedfiles} files to this folder.";
    if ($reportmode == 'incoming') {

      // Send out email notifications of new file added to all users subscribed  -  Get fileid for the new file record
      $args = array(
        ':cid' => $newcid,
        ':uid' => $user->uid,
      );
      $fid = db_query_range("SELECT fid FROM {filedepot_files} WHERE cid=:cid AND submitter=:uid ORDER BY fid DESC", 0, 1, $args)
        ->fetchField();
      filedepot_sendNotification($fid, FILEDEPOT_NOTIFY_NEWFILE);
    }
    $cid = $newcid;
  }
  elseif ($newcid == 0) {
    $message = 'Unable to move any files - Invalid new folder selected';
  }
  else {
    $message = 'Unable to move any files - invalid folder or insufficient rights';
  }
  $retval['retcode'] = 200;
  $retval['cid'] = $cid;
  $retval['movedfiles'] = $movedfiles;
  $retval['message'] = $message;
  $retval['activefolder'] = theme('filedepot_activefolder');
  $retval['displayhtml'] = filedepot_displayFolderListing($cid);
  return $retval;
}