<?php
##
# Project: PHPDISK File Storage Solution
# This is NOT a freeware, use is subject to license terms.
#
# Site: http://www.phpdisk.com
#
# $Id: files.inc.php 488 2010-10-25 13:03:35Z along $
#
# Copyright (C) 2008-2010 PHPDisk Team. All Rights Reserved.
#
##
if(!defined('IN_PHPDISK') || !defined('IN_MYDISK')) {
exit('[PHPDisk] Access Denied');
}
define('SCRIPT_NAME',$item);
require_once lang(SCRIPT_NAME);
$lang = array_merge($pub_lang,$lang);
$cache_file = PHPDISK_ROOT."system/cache/$pd_uid/my_folders_4.inc.php";
file_exists($cache_file) ? require_once $cache_file : $option_folder_4 = get_option_folders(4,0);
$cache_file = PHPDISK_ROOT."system/cache/$pd_uid/pub_menu_option.inc.php";
file_exists($cache_file) ? require_once $cache_file : $pub_menu_option = get_option_public_folder(0);
// fix set_extract_code
$a_upload_file = urr("mydisk","item=upload&is_public=$is_public&cate_id=$cate_id&subcate_id=$subcate_id&folder_node=$folder_node&folder_id=$folder_id&uid=$pd_uid");
$a_folder_create = urr("mydisk","item=folders&action=folder_create&folder_node=1");
$a_share_folder = '';
$a_list_detail = urr("mydisk","item=files&action=detail");
$group_set = $group_settings[$pd_gid];
if(display_plugin('multi_server','open_multi_server_plugin',($settings['open_multi_server'] && $settings['upload_server_type']=='sub_server'),0)){
$arr_ids = strpos($group_set['server_ids'],',') ? explode(',',$group_set['server_ids']) : $group_set['server_ids'];
$server_oid = is_array($arr_ids) ? (int)$arr_ids[mt_rand(0,count($arr_ids))] : (int)$arr_ids;
if($server_oid>1){
// reload $a_upload_file
$rs = $db->fetch_one_array("select server_host,server_key from {$tpf}servers where server_oid='$server_oid'limit 1");
if($rs){
$a_upload_file = $rs['server_host'].'?'.pd_encode("is_public=$is_public&cate_id=$cate_id&subcate_id=$subcate_id&folder_node=$folder_node&folder_id=$folder_id&uid=$pd_uid&server_key={$rs['server_key']}");
}
unset($rs);
}
}
$tmp_arr = array('a_folder_create'=>$a_folder_create,'a_upload_file' =>$a_upload_file,'a_list_detail'=>$a_list_detail,'a_share_folder'=>$a_share_folder,'title'=>$lang['extract_file_list']);
$nav_arr = get_my_nav($tmp_arr);
switch($action){
case 'index':
case 'detail':
if($task == 'to_folder'){
if($p_formhash != formhash()){
exit($lang['system_error']);
}
$file_ids = gpc('file_ids','P',array());
$dest_folder = gpc('dest_folder','P',0);
$ids_arr = get_ids_arr($file_ids,$lang['please_select_operation_files']);
if($ids_arr[0]){
$error = true;
$sysmsg[] = $ids_arr[1];
}else{
$file_str = $ids_arr[1];
}
if($dest_folder == -1){
$error = true;
$sysmsg[] = $lang['please_select_dest_folder'];
}else{
$dest_folder = (int)$dest_folder;
}
if(!$error){
$ins = array(
'folder_id' => $dest_folder,
'is_public' => 0,
'cate_id' => 0,
'subcate_id' => 0,
'is_checked' => 1,
);
$db->query_unbuffered("update {$tpf}files set ".$db->sql_array($ins)." where file_id in ($file_str) and userid='$pd_uid'");
syn_folder_size();
folders_menu_cache(1);
reload_leftframe('mydisk','file');
$sysmsg[] = $lang['move_success'];
redirect($_SERVER['HTTP_REFERER'],$sysmsg);
}else{
redirect('back',$sysmsg);
}
}elseif($task =='to_public'){
if($p_formhash != formhash()){
exit($lang['system_error']);
}
$file_ids = gpc('file_ids','P',array());
$public_cate = gpc('public_cate','P',0);
$ids_arr = get_ids_arr($file_ids,$lang['please_select_operation_files']);
if($ids_arr[0]){
$error = true;
$sysmsg[] = $ids_arr[1];
}else{
$file_str = $ids_arr[1];
}
if($public_cate == -1){
$error = true;
$sysmsg[] = $lang['please_select_dest_folder'];
}else{
$public_cate = (int)$public_cate;
}
$pid = $db->result_first("select pid from {$tpf}categories where cate_id='$public_cate'");
if($pid){
$cate_id = $pid;
$subcate_id = $public_cate;
}else{
$cate_id = $public_cate;
$subcate_id = 0;
}
if(!$error){
$ins = array(
'folder_id' => 0,
'is_public' => 1,
'cate_id' => $cate_id,
'subcate_id' => $subcate_id,
'in_recycle' => 0,
'is_checked' => 0,
);
$db->query_unbuffered("update {$tpf}files set ".$db->sql_array($ins)." where file_id in ($file_str) and userid='$pd_uid' ");
syn_folder_size();
folders_menu_cache(1);
public_menu_cache(1);
public_menu_cache(1,1);
reload_leftframe('mydisk','file');
$sysmsg[] = $lang['move_success'];
redirect($_SERVER['HTTP_REFERER'],$sysmsg);
}else{
redirect('back',$sysmsg);
}
}elseif($task == 'to_share'){
if($p_formhash != formhash()){
exit($lang['system_error']);
}
$file_ids = gpc('file_ids','P',array());
$ids_arr = get_ids_arr($file_ids,$lang['please_select_operation_files']);
if($ids_arr[0]){
$error = true;
$sysmsg[] = $ids_arr[1];
}else{
$file_str = $ids_arr[1];
}
if(!$error){
$ins = array(
'in_share' => 1,
);
$db->query_unbuffered("update {$tpf}files set ".$db->sql_array($ins)." where file_id in ($file_str)");
$sysmsg[] = $lang['share_success'];
redirect($_SERVER['HTTP_REFERER'],$sysmsg);
}else{
redirect('back',$sysmsg);
}
}elseif($task =='to_extract'){
if($p_formhash != formhash()){
exit($lang['system_error']);
}
$file_ids = gpc('file_ids','P',array());
$ids_arr = get_ids_arr($file_ids,$lang['please_select_extract_files']);
if($ids_arr[0]){
$error = true;
$sysmsg[] = $ids_arr[1];
}else{
$file_str = $ids_arr[1];
}
if(count($file_ids) >10){
$error = true;
$sysmsg[] = $lang['extract_files_limit'];
}
$q = $db->query("select * from {$tpf}files where file_id in ($file_str) order by file_id desc");
$files_array = array();
while($rs = $db->fetch_array($q)){
if($rs['folder_id']){
$rs2 = $db->fetch_one_array("select folder_name from {$tpf}folders where folder_id='{$rs['folder_id']}'");
$rs['store_at'] = $rs2['folder_name'];
unset($rs2);
}else{
$rs['store_at'] = $lang['root_folder'];
}
$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
$rs['file_name_all'] = $rs['file_name'].$tmp_ext;
$rs['file_name'] = cutstr($rs['file_name'].$tmp_ext,35);
$rs['file_size'] = get_size($rs['file_size']);
$rs['file_time'] = custom_time("Y-m-d",$rs['file_time']);
$files_array[] = $rs;
}
$db->free($q);
unset($rs);
$default_date = date("Y-m-d",$timestamp+86400*10);
$extract_code_status = '';
$extract_total = 0;
$action = 'set_extract_code';
require_once template_echo(SCRIPT_NAME,TPL_NAME);
}elseif($task =='is_link_code'){
if($p_formhash != formhash()){
exit($lang['system_error']);
}
$file_ids = gpc('file_ids','P',array());
$ids_arr = get_ids_arr($file_ids,$lang['please_select_link_files']);
if($ids_arr[0]){
$error = true;
$sysmsg[] = $ids_arr[1];
}else{
$file_str = $ids_arr[1];
}
$q = $db->query("select file_id,file_name,file_key,file_extension,is_image,file_store_path,file_real_name,store_old,server_oid from {$tpf}files where file_id in ($file_str) order by file_id desc");
$upl_array = array();
while($rs = $db->fetch_array($q)){
$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
$rs['file_name_all'] = $rs['file_name'].$tmp_ext;
$rs['file_name'] = cutstr($rs['file_name'].$tmp_ext,35);
if(can_true_link($rs['file_extension'])){
if(display_plugin('multi_server','open_multi_server_plugin',$settings['open_multi_server'],0) && $rs['server_oid']>1){
$rs2 = $db->fetch_one_array("select