Thursday, Sep 09, 2010
Login

FCK with delete option – File manager plugin


Step 1 :
config.php and locate line:
$Config['ConfigAllowedCommands'] = array(‘QuickUpload’, ‘FileUpload’, ‘GetFolders’, ‘GetFoldersAndFiles’, ‘CreateFolder’) ;
just add function ‘DeleteFile’
Like this:
$Config['ConfigAllowedCommands'] = array(‘QuickUpload’, ‘FileUpload’, ‘GetFolders’, ‘GetFoldersAndFiles’, ‘CreateFolder’, ‘DeleteFile’) ;

Step 2:
Place the delete image into filemanager/browser/default/images

Step 3:

Open up filemanager/frmresourceslist.html for editing with your favorite text-editor
Create a Delete Link which will call the DeleteFile function (which we’ll create later)
Go to line #66 where you’ll find this:
JavaScript:
var sLink = ‘<a href=”#” onclick=”OpenFile(\” + fileUrl + ‘\’);return false;”>’ ;

Underneath that line, now insert this:
JavaScript:
var dLink = ‘<a href=”#” title=”Delete file” onclick=”DeleteFile(\” + escape(fileName) + ‘\’);return false;”>’ ;

Add the created Delete Link to the page
Go to line #75 (#74 if you haven’t added the Delete Link yet) where you’ll find this:

JavaScript:
oCell.innerHTML = sLink + ‘<img alt=”" src=”images/icons/’ + sIcon + ‘.gif” width=”16″ height=”16″ border=”0″></a>’ ;

Replace that line with:
JavaScript:
oCell.innerHTML = sLink + ‘<img alt=”" src=”images/icons/’ + sIcon + ‘.gif” width=”16″ height=”16″ border=”0″></a> ‘ +  dLink + ‘<img alt=”" src=”images/delete.gif” width=”16″ height=”16″ border=”0″></a>’ ;

Add a DeleteFile function (which will call the PHP script) and a DeleteFileCallBack function (which is called after the file was deleted) just before window.onload = { … }
The DeleteFile function:

JavaScript:
function DeleteFile( fileName, fileUrl ) {
if (confirm(‘Are you sure you wish to delete ‘ + unescape(fileName) + ‘?’)) {
oConnector.SendCommand( ‘DeleteFile’, “FileName=” + fileName, DeleteFileCallBack ) ;
}
}

The DeleteFileCallBack function
function DeleteFileCallBack ( fckXml ) {
var oNodes = fckXml.SelectNodes( ‘Connector/Error’ );
if (oNodes!=null && oNodes.length>0) {
var errNo = parseInt(oNodes[0].attributes.getNamedItem(‘number’).value) ;
switch (errNo) {
case 0 :
break;
case 102 :
case 103 :
alert(oNodes[0].attributes.getNamedItem(‘originalDescription’).value);
break;
default:
alert(‘DFi: Invalid XML response from connector..’);
}
} else {
alert(‘DFi: Invalid XML response from connector.’);
}
Refresh();
}

Step 4:
Open up filemanager/connectors/php/commands.php for editing at the very end of the file (just before the ?>)
Add a DeleteFile function which actually deletes the file
PHP:

function DeleteFile($resourceType, $currentFolder) {
$sErrorNumber = ’0′ ;
$sErrorMsg = ” ;
if ( isset( $_GET['FileName'] ) ) {
// Map the virtual path to the local server path.
$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;
$sFileName = $_GET['FileName'] ;
if ( strpos( $sFileName, ‘..’ ) !== FALSE ) {
$sErrorNumber = ’102′ ; // Invalid file name.
$sErrorMsg = ‘Invalid file name’;
} else {
if ( @unlink($sServerDir.$sFileName) ) {
$sErrorNumber = ’0′ ; // deleted
} else {
$sErrorNumber = ’103′ ; // not deleted
$sErrorMsg = ‘Could not delete file ‘.$sServerDir.$sFileName;
}
}
} else {
$sErrorNumber = ’102′ ; // no file set
$sErrorMsg = ‘No file specified’;
}
// Create the “Error” node.
echo ‘<Error number=”‘ . $sErrorNumber . ‘” originalDescription=”‘ . ConvertToXmlAttribute( $sErrorMsg ) . ‘” />’ ;
}

Step 5
:
Open up filemanager/connectors/php/connector.php for editing
Modify the switch statement to include the DeleteFile action
Go to line 100 where you’ll find “break ;”, after that add:
PHP:
case ‘DeleteFile’ : // Added by glad
DeleteFile( $sResourceType, $sCurrentFolder ) ;
break ;


1 Comment

  1. I am from Brazil and I apologize now for the English. It was translated by google translator.

    I would like to congratulate the author for the beautiful article. There are times I’m looking for something. Follow all the steps and ran right. Thanks for your help and congratulations on blog..

Leave a Reply

You must be logged in to post a comment.