<?php
!defined('P_W') && exit('Forbidden');
L::loadClass('upload', '', false);
/**
 * 店铺Logo上传实现
 * @author qiong
 *
 */
class PW_DianpuLogoUpload extends uploadBehavior {
	
	var $db;
	var $did;
	var $attachs;
	
	function PW_DianpuLogoUpload($did) {
		global $db, $db_ifathumb, $db_athumbsize, $db_uploadfiletype, $winduid;
		parent::uploadBehavior();
		$this->did = (int) $did;
		$this->db = & $db;
		$this->ifthumb = & $db_ifathumb;
		$this->thumbsize = '160	160';
		$db_imgsize = 2000;
		$this->ftype = array('gif' => $db_imgsize, 'jpg' => $db_imgsize, 'jpeg' => $db_imgsize, 'bmp' => $db_imgsize, 
			'png' => $db_imgsize);
	}
	
	/* (non-PHPdoc)
	 * @see lib/uploadBehavior#allowType()
	 */
	function allowType($key) {
		list($t) = explode('_', $key);
		return $t == 'logo';
	}
	
	/* (non-PHPdoc)
	 * @see lib/uploadBehavior#getFilePath()
	 */
	function getFilePath($currUpload) {
		$filename = $this->did . '.' . $currUpload['ext'];
		$savedir = 'dianpu/logo/';
		$thumbdir = 'thumb/dianpu/logo/';
		return array($filename, $savedir, $filename, $thumbdir);
	}
	
	/**
	 * @param array $uploaddb
	 */
	function update($uploaddb) {
		$this->attachs = $uploaddb;
	}
	
	/**
	 * @return string
	 */
	function getLogo() {
		$ret = current($this->attachs);
		return isset($ret['fileuploadurl']) ? $ret['fileuploadurl'] : '';
	}
	
	/* (non-PHPdoc)
	 * @see lib/uploadBehavior#allowThumb()
	 */
	function allowThumb() {
		return (int) $this->ifthumb;
	}
	
	/* (non-PHPdoc)
	 * @see lib/uploadBehavior#getThumbSize()
	 */
	function getThumbSize() {
		return $this->thumbsize;
	}
}
?>