foreach ($files as $id) { // Check if this is a valid submission record if ($id > 0 and DB_count($_TABLES['nxfile_filesubmissions'], 'id', $id)) { // Verify that user has Admin Access to approve this file $cid = DB_getItem($_TABLES['nxfile_filesubmissions'], 'cid', "id={$id}"); $firephp->log("Checking if user has admin approval"); if ($cid > 0 and fm_getPermission($cid, array('admin', 'approval'), '', false)) { $firephp->log("User has approval permission"); $query = DB_query("SELECT cid,tempname,fname,notify FROM {$_TABLES['nxfile_filesubmissions']} WHERE id={$id}"); list($cid, $tempname, $fname, $notify) = DB_fetchArray($query); if (!empty($tempname) and file_exists("{$_FMCONF['storage_path']}{$cid}/submissions/{$tempname}")) { @unlink("{$_FMCONF['storage_path']}{$cid}/submissions/{$tempname}"); } // Check for notification record for user if ($notify == 1) { fm_sendNotification($id, "3"); } DB_query("DELETE FROM {$_TABLES['nxfile_filesubmissions']} WHERE id={$id}"); $deletedFiles++; } } } if ($deletedFiles > 0) { $data['retcode'] = 200; $firephp->log("Deleted {$deletedFiles} files"); $data = nexdocsrv_generateLeftSideNavigation($data); } else { $data['retcode'] = 400; } $data['displayhtml'] = nexdocsrv_generateFileListing(0, $reportmode); $retval = json_encode($data);
function nexdocsrv_approveFileSubmission($id) { global $_TABLES, $_CONF, $_FMCONF; $query = DB_query("SELECT fid,cid,fname,tempname,title,description,tags,ftype,size,version,version_note,submitter,date,version_ctl,notify FROM {$_TABLES['nxfile_filesubmissions']} WHERE id={$id}"); list($fid, $cid, $fname, $tmpname, $title, $description, $tags, $ftype, $fsize, $version, $verNote, $submitter, $date, $versionmgmt, $notify) = DB_fetchARRAY($query); $data = array(); // Check if there have been multiple submission requests for the same file and thus have same new version # if ($version == 1) { if ($ftype == 'file') { $curfile = "{$_FMCONF['storage_path']}{$cid}/submissions/{$tmpname}"; $newfile = "{$_FMCONF['storage_path']}{$cid}/{$fname}"; $rename = @rename($curfile, $newfile); } DB_query("INSERT INTO {$_TABLES['nxfile_files']} (cid,fname,title,version,ftype,size,submitter,status,date,version_ctl)\r\n VALUES ('{$cid}','{$fname}','{$title}','1','{$ftype}','{$fsize}','{$submitter}',1,'{$date}','{$versionmgmt}')"); $newfid = DB_insertId(); DB_query("INSERT INTO {$_TABLES['nxfile_filedetail']} (fid,description,hits,rating,votes,comments)\r\n VALUES ('{$newfid}','{$description}',0,0,0,0)"); DB_query("INSERT INTO {$_TABLES['nxfile_fileversions']} (fid,fname,ftype,version,notes,size,date,uid,status)\r\n VALUES ('{$newfid}','{$uploadfilename}','{$ftype}','1','{$verNote}','{$fsize}','{$date}','{$submitter}',1)"); } else { // Need to rename the current versioned file if ($ftype == 'file') { $curfile = $_CONF['path_html'] . 'nexfile/data/' . $cid . '/submissions/' . $tmpname; $newfile = $_CONF['path_html'] . 'nexfile/data/' . $cid . '/' . $fname; $rename = @rename($curfile, $newfile); } DB_query("INSERT INTO {$_TABLES['nxfile_fileversions']} (fid,fname,ftype,version,notes,size,date,uid,status)\r\n VALUES ('{$fid}','{$fname}','{$ftype}','{$version}','{$verNote}','{$fsize}','{$date}','{$submitter}','1')"); DB_query("UPDATE {$_TABLES['nxfile_files']} SET fname='{$fname}',version='{$version}', date='{$date}' WHERE fid={$fid}"); $newfid = $fid; } if ($newfid > 0) { $tagcloud = new nexfileTagCloud(); // Update tags table and return tags formated as required $tagcloud->update_tags($newfid, $tags); // Send out notifications of approval fm_sendNotification($newfid, "2"); DB_query("DELETE FROM {$_TABLES['nxfile_filesubmissions']} WHERE id={$id}"); // 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='{$cid}'") == 1) { fm_autoCreateNotifications($fid, $cid); } // Send out notifications of update to all subscribed users fm_sendNotification($newfid, "1"); return true; } else { return false; } }