Current File : //etc/zpanel/panel/etc/apps/filemanager/include/copy_move.php |
<?php
// ensure this file is being included by a parent file
if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
/**
* @version $Id: copy_move.php 203 2011-07-25 06:51:11Z soeren $
* @package eXtplorer
* @copyright soeren 2007-2011
* @author The eXtplorer project (http://extplorer.net)
* @author The The QuiX project (http://quixplorer.sourceforge.net)
*
* @license
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU General Public License Version 2 or later (the "GPL"), in
* which case the provisions of the GPL are applicable instead of
* those above. If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use
* your version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice and
* other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this file
* under either the MPL or the GPL."
*
*
*/
/**
* File/Directory Copy & Move Functions
*/
$copy_move_label="";
function ext_copy_move_items($dir) { // copy/move file/dir
$action = extGetParam( $_REQUEST, 'action' );
if(($GLOBALS["permissions"]&01)!=01){
ext_Result::sendResult( $action, false, $GLOBALS["error_msg"]["accessfunc"]);
}
//ext_Result::sendResult($action,false,"asdfasdfasdf");
// Vars
//$dir = str_replace(" ","***",$dir);
$first = extGetParam($GLOBALS['__POST'], 'first' );
if($first=="y") $new_dir=$dir;
else $new_dir = extGetParam($GLOBALS['__POST'], "new_dir");
if($new_dir==".") $new_dir="";
$cnt=count($GLOBALS['__POST']["selitems"]);
if (!$new_dir) {
ext_copy_move_dialog($dir);
return;
}
$copy_move_proceed_status =1;
if($cnt > 1) {
$c_copy_dir = get_abs_dir().$new_dir;
if(is_dir($c_copy_dir)) { }
else { $copy_move_proceed_status = 0; }
}
//ob_start();
//echo $mail_data;
//var_dump($explode_data);
//var_dump($GLOBALS);
//$out1 = ob_get_contents();
//ob_end_clean()
// DO COPY/MOVE
// ALL OK?
if ($copy_move_proceed_status == 1) {
if(!@$GLOBALS['ext_File']->file_exists(dirname(get_abs_dir($new_dir)))) {
ext_Result::sendResult( $action, false, dirname(get_abs_dir($new_dir)).": ".$GLOBALS["error_msg"]["targetexist"]);
}
if(!get_show_item($new_dir,"")) {
ext_Result::sendResult( $action, false, $new_dir.": ".$GLOBALS["error_msg"]["accesstarget"]);
}
if(!down_home(get_abs_dir($new_dir))) {
ext_Result::sendResult( $action, false, $new_dir.": ".$GLOBALS["error_msg"]["targetabovehome"]);
}
// copy / move files
$err=false;
require_once("common_function.php");
if (class_exists('CommonFunction')) {
$temp_file_name = CommonFunction::create_guid();
$temp_file_save_path = _EXT_FTPTMP_PATH."/g".$temp_file_name;
$f = fopen($temp_file_save_path,"w");
fclose($f);
CommonFunction::check_Session();
$copy_dir = get_abs_dir().$new_dir;
for($i=0;$i<$cnt;++$i) {
$tmp = basename(stripslashes($GLOBALS['__POST']["selitems"][$i]));
$new = basename(stripslashes($GLOBALS['__POST']["selitems"][$i]));
/*if( ext_isFTPMode() ) {
$abs_item = get_item_info($dir,$tmp);
$abs_new_item = $new_dir.'/'.$new;
} else {
$abs_item = get_abs_item($dir,$tmp);
$abs_new_item = get_abs_item($new_dir,$new);
// ext_Result::sendResult("copy",false,$dir."......".$tmp."-------".$new_dir."_____".$new." ---".$abs_item."*****".$abs_new_item;
}*/
$abs_item = get_abs_item($dir,$tmp);
$abs_new_item = get_abs_item($new_dir,$new);
$items[$i] = $tmp;
// Check
if($new=="") {
$error_msg = $GLOBALS["error_msg"]["miscnoname"];
$err=true; continue;
}
if(!@$GLOBALS['ext_File']->file_exists($abs_item)) {
$error_msg = $GLOBALS["error_msg"]["itemexist"];
$err=true; continue;
}
if(!get_show_item($dir, $tmp)) {
$error_msg = $GLOBALS["error_msg"]["accessitem"];
$err=true; continue;
}
if($GLOBALS['__POST']["override"]) {
} else {
if(@$GLOBALS['ext_File']->file_exists($abs_new_item)) {
$error_msg = $GLOBALS["error_msg"]["targetdoesexist"];
$err=true; continue;
}
}
// Copy / Move
if(!$err) {
if($action=="copy") {
if(@is_link(ext_TextEncoding::fromUTF8($abs_item)) || get_is_file(ext_TextEncoding::fromUTF8($abs_item))) {
// check file-exists to avoid error with 0-size files (PHP 4.3.0)
//if( ext_isFTPMode() ) $abs_item = '/'.$dir.'/'.$abs_item['name'];
file_put_contents($temp_file_save_path,$abs_item."\n",FILE_APPEND);
}
elseif(@get_is_dir(ext_TextEncoding::fromUTF8($abs_item))) {
//$ext_copy_dir = ext_isFTPMode() ? '/'.$dir.'/'.$abs_item['name'].'/' : $abs_item;
//if( ext_isFTPMode() ) $abs_new_item .= '/';
file_put_contents($temp_file_save_path,$abs_item."\n",FILE_APPEND);
}
}
else {
file_put_contents($temp_file_save_path,$abs_item."\n",FILE_APPEND);
//$ok= $GLOBALS['ext_File']->rename($abs_item,$abs_new_item);
}
} else {
@unlink($temp_file_save_path);
ext_Result::sendResult( $action, false, $error_msg);
}
}
if (!$err) {
$temp_file_save_path = str_replace(" ","***",$temp_file_save_path);
$copy_dir = str_replace(" ","***",$copy_dir);
$sock_msg = "file_copy_move ".$action." ".$temp_file_save_path." apache /var/sentora/temp/ ".$copy_dir;
$sock_d = CommonFunction::file_read_socket($sock_msg);
if (!$sock_d) {
ext_Result::sendResult(($action=='copy'?'Copy':'Move'), false,"Server is busy ,try after some time");
} else {
$copy_move_file_path = CommonFunction::remove_space($sock_d);
if(strlen($copy_move_file_path) > 0 ) {
if(array_key_exists("copy_move_file_path",$_SESSION)) {
unset($_SESSION['copy_move_file_path']);
}
$_SESSION['copy_move_file_path'] = $copy_move_file_path;
} else {
ext_Result::sendResult(($action=='copy'?'Copy':'Move'), false,"Server issue, try again after some timeddd");
}
}
} else {
@unlink($temp_file_save_path);
ext_Result::sendResult( $action, false, $error_msg);
}
//ext_Result::sendResult( $action, true, 'File '.($action=='copy'?'copied':'moved').' ,we are doing in background please wait');
} else {
ext_Result::sendResult( ($action=='copy'?'Copy':'Move'), false, "Server issue, try again after some timeiddd");
}
} else {
ext_Result::sendResult( ($action=='copy'?'Copy':'Move'), false, "Please check target directory is exist and it is given apache permission");
}
//ext_Result::sendResult( $action, true, 'The File(s)/Directory(s) were successfully '.($action=='copy'?'copied':'moved').'.' );
}
function ext_copy_move_dialog($dir='') {
$action = extGetParam( $_REQUEST, 'action' );
if($action == 'copy') {
$copy_move_label='Copy';
} else if($action == 'move'){
$copy_move_label='Move';
}
?>
{
"xtype": "form",
"id": "simpleform",
"labelWidth": 125,
"width": "340",
"url":"<?php echo basename( $GLOBALS['script_name']) ?>",
"dialogtitle": "<?php echo $copy_move_label; ?>",
"frame": true,
"items": [{
"xtype": "textfield",
"fieldLabel": "Destination",
"name": "new_dir",
"value": "<?php echo $dir ?>/",
"width":175,
"allowBlank":false
},{
"xtype": "checkbox",
"fieldLabel": "Override Existing?",
"name": "override",
}],
"buttons": [{
//text: '<?php echo ext_Lang::msg( 'btncreate', true ) ?>',
text: '<?php echo $copy_move_label; ?>',
handler: function() {
form = Ext.getCmp('simpleform').getForm();
statusBarMessage( 'Please wait...', true );
var requestParams = getRequestParams();
requestParams.confirm = 'true';
requestParams.action = '<?php echo $action ?>';
form.submit({
//reset: true,
reset: false,
success: function(form, action) {
console.log("This is ajax part");
copy_move_ajax_call();
/*
Ext.MessageBox.alert('Error!',"Message detail");
statusBarMessage( action.result.message, false, true );
try{
dirTree.getSelectionModel().getSelectedNode().reload();
} catch(e) {}
datastore.reload();
Ext.getCmp("dialog").destroy();*/
},
failure: function(form, action) {
if( !action.result ) return;
Ext.MessageBox.alert('Error!', action.result.error);
statusBarMessage( action.result.error, false, false );
},
scope: form,
// add some vars to the request, similar to hidden fields
params: requestParams
});
}
},{
text: '<?php echo ext_Lang::msg( 'btncancel', true ) ?>',
handler: function() { Ext.getCmp("dialog").destroy(); }
}]
}
<?php
}
?>