<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$action=empty($action)?'files':trim($action);
	switch($action)
	{
		case 'files':
			if(isset($isupload) && $isupload==1)
			{
				require_once(DIRCMS_ROOT.'include/upload.class.php');
				$upload=new upload('files','upload/file/'.date('m').'/'.date('d'));
				echo '<script language="javascript" type="text/javascript">parent.document.getElementById("'.$uploadtext.'").value+="'.implode('\n',$upload->files).'\r\n";</script>';
			}
			include admin_tlp('upload_files');
			break;	
		case 'images':
			$iswatermark=$DIRCMS['watermark_enabled'];
			if(isset($isupload) && $isupload==1)
			{
				require_once(DIRCMS_ROOT.'include/upload.class.php');
				$upload=new upload('files','upload/file/'.date('m').'/'.date('d'));
				$imagearr=$upload->files;
				require_once(DIRCMS_ROOT.'include/image.class.php');
				$image=new image();

				if($is_form_thumb==1) //先生成缩略图
				{
					foreach($imagearr as $val)
					{
						$imgs[]=$image->thumb($val,$thumb_width,$thumb_height);
						@unlink($val);
					}
					$imagearr=$imgs;
				}
				if($is_form_watermark==1) //再加水印
				{
					foreach($upload->files as $val)
					{
						$image->watermark($val,WATERMARK_POS,WATERMARK_FILE,WATERMARK_PCT,WATERMARK_WORDS,WATERMARK_COLOR);
					}
				}
				
				echo '<script language="javascript" type="text/javascript">parent.document.getElementById("'.$uploadtext.'").value+="'.implode('\n',$imagearr).'\r\n";</script>';
			}
			include admin_tlp('upload_images');
			break;
		case 'thumb':
			if(isset($isupload) && $isupload==1)
			{
				require_once(DIRCMS_ROOT.'include/upload.class.php');
				$upload=new upload('files','upload/file/'.date('m').'/'.date('d'));
				$imagearr=$upload->files;
				require_once(DIRCMS_ROOT.'include/image.class.php');
				$image=new image();

				if($is_form_thumb==1) //先生成缩略图
				{
					foreach($imagearr as $val)
					{
						$imgs[]=$image->thumb($val,$thumb_width,$thumb_height);
					}
					$imagearr=$imgs;
				}
				if($is_form_watermark==1) //再加水印
				{
					foreach($upload->files as $val)
					{
						$image->watermark($val,WATERMARK_POS,WATERMARK_FILE,WATERMARK_PCT,WATERMARK_WORDS,WATERMARK_COLOR);
					}
				}
				showmsg("文件上传成功！<script language='javascript'>$(window.opener.document).find(\"form[@name='myform'] #thumb\").val(\"$imagearr[0]\");</script>");
			}
			include admin_tlp('upload_thumb');
			break;
	}
?>