<?php
require "inc.php";
defined('IN_DIALOG') or $obj_msg->on_error('access');

$obj_tab_upload=new cls_tab_other_upload($obj_db);
$tab_upload=DB_PRE."other_upload";
(!isset($get_me_folder_id))? $get_me_folder_id=0:$get_id=intval($get_me_folder_id);
if(!isset($get_win_type)) $get_win_type="";
if(!isset($get_win_objid)) $get_win_objid="";

if(isset($get_viewmod)) $_SESSION['upload_viewmod']=$get_viewmod;
if(!isset($_SESSION['upload_viewmod'])) $_SESSION['upload_viewmod']="default";
$get_viewmod=$_SESSION['upload_viewmod'];

$page_folder_path="<a href=\"javascript:on_dir_open(0);\">顶级</a> ".me_get_folder_path($get_me_folder_id);

$page_footer_info=<<<HTML
HTML;
switch($get_act)
{
	case "paste"://粘贴
	{
		if(!isset($get_paste_source)||intval($get_paste_source)==0) break;
		$lng_paste_source=$get_paste_source;
		$str_paste_name=basename($get_paste_source);
		if($get_paste_type=="dir")//目录粘贴
		{
			if($get_paste_act=="copy"){
				$msg_return=$obj_tab_upload->on_folder_copy($lng_paste_source,$get_me_folder_id);
				if($msg_return["err"]!="") $obj_msg->alert($msg_return["err"]);
			}else{
				$msg_return=$obj_tab_upload->on_folder_copy($lng_paste_source,$get_me_folder_id);
				if($msg_return["err"]!=""){
					$obj_msg->alert($msg_return["err"]);
				}else{
					$msg_return=$obj_tab_upload->on_folder_del($lng_paste_source);
					if($msg_return["err"]!="") $obj_msg->alert($msg_return["err"]);
				}
			}
		}else{//文件粘贴
		if($get_paste_act=="copy"){
				$msg_return=$obj_tab_upload->on_file_copy($lng_paste_source,$get_me_folder_id);
				if($msg_return["err"]!="") $obj_msg->alert($msg_return["err"]);
			}else{
				$msg_return=$obj_tab_upload->on_file_copy($lng_paste_source,$get_me_folder_id);
				if($msg_return["err"]!=""){
					$obj_msg->alert($msg_return["err"]);
				}else{
					$msg_return=$obj_tab_upload->on_del($lng_paste_source);
					if($msg_return["err"]!="") $obj_msg->alert($msg_return["err"]);
				}
			}
		}
		//清空粘贴文本框
		if($get_paste_act=="cut")
		{
			$get_paste_source="";
			$get_paste_type="";
			$get_paste_act="";
		}
		break;
	}
	case "delete":// 删除
	{
		if(!isset($get_del_source)||$get_del_source=="") break;
		if($get_del_type=="dir")
		{
			$msg_return=$obj_tab_upload->on_folder_del($get_del_source);
		}else{
			$msg_return=$obj_tab_upload->on_del($get_del_source);
		}
		if($msg_return["err"]!="")
		{
			$obj_msg->alert($msg_return["err"]);
		}
		break;
	}
	case "rename"://重命名
	{
		if(!isset($get_rename_source)||intval($get_rename_source)<1) break;
		if(!isset($get_rename)||$get_rename=="") break;
		if($get_rename_type=="dir")
		{
			$msg_return=$obj_tab_upload->on_folder_rename($get_rename_source,$get_rename);
		}else{
			$msg_return=$obj_tab_upload->on_file_rename($get_rename_source,$get_rename);
		}
		if($msg_return["err"]!="")
		{
			$obj_msg->alert($msg_return["err"]);
		}
		break;
	}
	case "createdir"://新建文件夹
	{
		if(!isset($get_new_dirname)||$get_new_dirname=="") break;
		$arr_fields=array();
		$arr_fields["folder_name"]=$get_new_dirname;
		$arr_fields["folder_pid"]=$get_me_folder_id;
		$msg_return=$obj_tab_upload->on_save_folder($arr_fields);	
		if($msg_return["err"]!="")
		{
			$obj_msg->alert($msg_return["err"]);
		}
		break;
	}
	case "up_webfile"://网络抓取文件
	{
		$obj_tab_upload->set_folder_id($get_me_folder_id);
		$msg_return=$obj_tab_upload->on_upload_web($get_up_webfile);
		if($msg_return["err"]!="")
		{
			$obj_msg->alert($msg_return["err"]);
		}
		break;
	}
}
$str_where=" where upload_folder_id='".$get_me_folder_id."' and upload_user_id='".$dialog_uid."'";
$arr_file=array();
$str_sql="SELECT count(*) as num FROM ".$tab_upload.$str_where;
$obj_rs    = $obj_db->get_one($str_sql);
$int_total = $obj_rs["num"];
$int_pages = ceil($int_total/$int_pagesize);
$get_page = min($int_pages, $get_page);
$get_page  = max(intval($get_page), 1);
$str_page_show=get_pages($int_total, $get_page, $int_pagesize);
$int_offset = $int_pagesize*($get_page-1);
$str_limit = " LIMIT ".$int_offset.", ".$int_pagesize;

$str_sql="SELECT * FROM ".$tab_upload.$str_where." order by upload_id desc".$str_limit;
$obj_result = $obj_db->query($str_sql);
while($obj_rs = $obj_db->fetch_array($obj_result))
{
	$obj_rs["upload_addtime"]=format_date($obj_rs["upload_addtime"],"y-m-d");
	$obj_rs["upload_size"]=format_filesize($obj_rs["upload_size"],"M");
	$obj_rs["pic"]=me_get_pic($obj_rs["upload_path"],$obj_rs["upload_ext"]);
	$arr_file[] = $obj_rs;
}

$arr_folder=array();
$str_sql="SELECT * FROM ".DB_PRE."other_upload_folder where folder_user_id='".$dialog_uid."' and folder_pid='".$get_me_folder_id."'";
$obj_result = $obj_db->query($str_sql);
while($obj_rs = $obj_db->fetch_array($obj_result))
{
	$obj_rs["folder_addtime"]=format_date($obj_rs["folder_addtime"],"y-m-d");
	$arr_folder[] = $obj_rs;
}


include 'tpl/upload.tpl.php';

function me_get_pic($msg_path,$msg_ext)
{
	if(is_pic($msg_path)) return WEB_URL.$msg_path;
	return WEB_URL."/dialog/images/pic/".$msg_ext.".gif";
}
function me_get_folder_path($msg_pid)
{
	global $obj_db,$dialog_uid;
	$str_x="";
	$str_sql="SELECT * FROM ".DB_PRE."other_upload_folder where folder_user_id='".$dialog_uid."' and folder_id='".$msg_pid."'";
	$obj_result = $obj_db->query($str_sql);
	if($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$str_x="<a href=\"javascript:on_dir_open(".$obj_rs["folder_id"].");\">".$obj_rs["folder_name"]."</a>";
		$str_x=me_get_folder_path($obj_rs["folder_pid"])." -> ".$str_x;
	}
	return $str_x;
}

?>