$cid = $filter->getCleanData('int', $_GET['cid']); $data['error'] = ''; $data['fid'] = $fid; $ret = nexdoc_updateFileSubscription($fid, 'toggle'); if ($ret['retcode'] === true) { $data['retcode'] = 200; if ($ret['subscribed'] === true) { $data['subscribed'] = true; $data['message'] = 'You will be notified of any new versions of this file'; fm_updateAuditLog("Subscription record added for FID: {$fid}"); $data['notifyicon'] = "{$_CONF['site_url']}/nexfile3/images/email-green.gif"; $data['notifymsg'] = 'Notification Enabled - Click to change'; } elseif ($ret['subscribed'] === false) { $data['subscribed'] = false; $data['message'] = 'You will not be notified of any new versions of this file'; fm_updateAuditLog("Unsubscription record added for FID: {$fid}"); $data['notifyicon'] = "{$_CONF['site_url']}/nexfile3/images/email-regular.gif"; $data['notifymsg'] = 'Notification Disabled - Click to change'; } } else { $data['error'] = 'Error accessing file record'; $data['retcode'] = 404; } $retval = json_encode($data); break; case 'multisubscribe': if ($uid > 1) { $reportmode = $filter->getCleanData('char', $_POST['reportmode']); $fileitems = $filter->getDbData('text', $_POST['checkeditems']); $files = explode(',', $fileitems); foreach ($files as $fid) {
function nexdoc_moveQueuefile($id, $newcid) { global $_CONF, $_TABLES, $_USER, $_FMCONF; $filemoved = false; if ($newcid > 0) { $query = DB_query("SELECT orig_filename,queue_filename,timestamp,uid,size,mimetype FROM {$_TABLES['nxfile_import_queue']} WHERE id={$id}"); list($fname, $qname, $date, $submitter, $filesize, $mimetype) = DB_fetchArray($query); $sourcefile = $_FMCONF['storage_path'] . "queue/{$qname}"; $targetfile = $_FMCONF['storage_path'] . "{$newcid}/{$fname}"; if (!empty($qname) and !empty($fname) and file_exists($sourcefile)) { if ($submitter == $_USER['uid'] or fm_getPermission($newcid, 'admin')) { /* Need to move the file */ $pos = strrpos($fname, '.') + 1; $fileExtension = substr($fname, $pos); $ret = @rename($sourcefile, $targetfile); if ($ret and file_exists($targetfile)) { @unlink($sourcefile); $filemoved = true; } elseif (file_exists($targetfile)) { COM_errorLog("Move failed - file of same name exists - {$sourcefile}"); // Let's give the new file a random name and try the move again - add the numerical MonthDayHourSecond $targetfile = $_FMCONF['storage_path'] . "{$newcid}/{$fname}-" . date('mdHms'); COM_errorLog("Attempting to move with a random name - {$targetfile}"); $ret = @rename($sourcefile, $targetfile); if ($ret and file_exists($targetfile)) { @unlink($sourcefile); $filemoved = true; } else { COM_errorLog("Move with random filename also failed"); } } if ($filemoved) { // File successfully moved - create new records // Set status of file to 1 - online $fname = addslashes($fname); $qname = addslashes($qname); $sql = "INSERT INTO {$_TABLES['nxfile_files']} (cid,fname,title,version,ftype,size,mimetype,extension,submitter,status,date) "; $sql .= "VALUES ({$newcid},'{$fname}','{$fname}','1','file',"; $sql .= "'{$filesize}','{$mimetype}','{$fileExtension}',{$submitter},1,'{$date}')"; DB_query($sql); $fid = DB_insertId(); // New File ID DB_query("INSERT INTO {$_TABLES['nxfile_filedetail']} (fid,description,hits,rating,votes,comments)\r\n VALUES ('{$fid}','File uploaded with no description','0','0','0','0')"); DB_query("INSERT INTO {$_TABLES['nxfile_fileversions']} (fid,fname,ftype,version,notes,size,date,uid,status)\r\n VALUES ('{$fid}','{$fname}','file','1','','{$filesize}','{$date}','{$submitter}','1')"); PLG_itemSaved($fid, 'nexfile_filesaved'); // Optionally add notification records and send out notifications to all users with view access to this new file if (DB_getItem($_TABLES['nxfile_categories'], 'auto_create_notifications', "cid={$newcid}") == 1) { fm_autoCreateNotifications($fid, $newcid); } // Send out notifications of update if ($_POST['notification'] == 1) { fm_sendNotification($fid); } fm_updateAuditLog("Direct upload of File ID: {$fid}, in Category: {$newcid}"); // Remove the incoming queue file DB_query("DELETE FROM {$_TABLES['nxfile_import_queue']} WHERE id={$id}"); } else { $GLOBALS['fm_errmsg'] = 'Error moving file'; } } else { COM_errorLog("User {$_USER['username']} does not have access to move file: {$fid} {$fname} to category: {$newcid}"); } } else { $GLOBALS['fm_errmsg'] = "Error moving file - source file {$gname} missing"; COM_errorLog("Nexfile: {$GLOBALS['fm_errmsg']}"); } } return $filemoved; }