<?php
/**
 * 106云盘自动发卡平台网盘系统
 * ============================================================================
 * 版权所有 2016-2028 扎兰屯市姝妍计算机服务有限公司，并保留所有权利。
 * 网站地址: http://www.106ym.com
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ============================================================================
 */
namespace member\controller;
class Recycle extends Member {
    public function index(){
    	$this->display();
    }
    
	//恢复
	public function huifu(){
		$uid=session("user_auth.id");
		$pk_arr=I('pk');
		foreach ($pk_arr as $k => $v) {
			$pk=explode(',', $v); 
			$pk=array(
				'pk1'=>$uid,
				'pk2'=>$pk[1],
				'pk3'=>$pk[2],
				'pk4'=>$pk[3],
			);
			$info_file=O('file')->find(array('pk'=>$pk));
			O('file')->save(array(
				'pk'=>$pk,
				'attr'=>array('status'=>0),
			));
			$info_folder=O('folder')->find(array(
				'pk'=>array(
					'pk1'=>$uid,
					'pk2'=>'',
					'pk3'=>'',
					'pk4'=>$info_file['folder']
				)
			));
			$folder_pids[$k]=$info_folder['folder_pids'].','.$info_file['folder'];
		}
		
		$folder_pids=implode(',', $folder_pids);
		$folder_pids=explode(',', $folder_pids);
		$list_folder=$this->folder();
		foreach ($list_folder as $k => $v) {
			if(in_array($v['pk4'], $folder_pids)){
			    O('folder')->save(array(
					'pk'=>array(
						'pk1'=>$uid,
						'pk2'=>$v['pk2'],
						'pk3'=>$v['pk3'],
						'pk4'=>$v['pk4'],
					),
					'attr'=>array('status'=>0)
				));
			}
		}
		$this->ajaxReturn(array('status'=>1));
    }
	
    
	//回收站文件夹
	public function folder(){
		$uid=session("user_auth.id");
    	$spk = array (
		    'pk1' => $uid,
		    'pk2' => array('type' => 'INF_MAX'),
	        'pk3' => '',
	        'pk4' => '',
		);
		$epk = array (
		    'pk1' => $uid,
		    'pk2' => array('type' => 'INF_MIN'),
	        'pk3' => '',
	        'pk4' => '',
		);
		
		$list=O('folder')->select(array(
			'spk'=>$spk,
			'epk'=>$epk,
			'filter'=>array('status'=>array('eq',-1)),
		));
		return $list;
	}
	
	//回收站文件
	public function files(){
		$uid=session("user_auth.id");
    	$spk = array (
		    'pk1' => $uid,
		    'pk2' => '',
	        'pk3' => '',
	        'pk4' => array('type' => 'INF_MAX'),
		);
		$epk = array (
		    'pk1' => $uid,
		    'pk2' => '',
	        'pk3' => '',
	        'pk4' => array('type' => 'INF_MIN'),
		);
		
		$list=O('file')->select(array(
			'spk'=>$spk,
			'epk'=>$epk,
			'filter'=>array('status'=>array('eq',-1)),
		));
		foreach ($list as $k => &$v) {
			//图标
			if(isset($v['link'])){
			    $v['icon']=S('STATIC').'/static/public/images/filetype/html.gif';
			}else if(in_array(array_pop(explode('.', $v['name'])), array('7z','asp','aspx','bat','bmp','chm','css','db','dll','doc','exe','file','fla','gif','htm','html','images','ini','jpeg','jpg','js','jsp','lnk','mdb','mov','mp3','pdf','php','png','ppt','psd','qt','quicktime','rar','reg','rm','rmvb','shtml','swf','tif','torrent','txt','vbs','video','video2','video3','vsd','wmv','xls','xml','xsl','zip'))){
				$v['icon']=S('STATIC').'/static/public/images/filetype/'.array_pop(explode('.', $v['name'])).'.gif';
			}else{
				$v['icon']=S('STATIC').'/static/public/images/filetype/file.gif';
			}
		}
		
		$this->ajaxReturn($list);
	}
    
}