<?php
/*
flash幻灯片管理模型
*/
class FlashModel extends DBModel{
	public function Add($POST){
		if ($_FILES['picture']['tmp_name']){
			$IO = new Easy_Filesystem();
			$POST['picture'] = $IO->setFile($_FILES['picture']);
		}else{
			$this->error[] = _('请上传海报');
		}
		$this->_DB->insert(VODCMS_FLASH, $POST);
		@unlink(ROOT.'Cache/tmp/flash.html');
		return $this->_DB->LastInsertID();

	}
	public function modify($POST){
		if ($POST['delfile']){
			$filename = strrev(base64_decode($POST['delfile']));
			if (is_file(ROOT.$filename)){
				$IO = new Easy_Filesystem();
				$IO->delete(ROOT.$filename);
				$POST['picture'] = '';
			}
		}
		if ($_FILES['picture']['tmp_name']){
			$IO = new Easy_Filesystem();
			$POST['picture'] = $IO->setFile($_FILES['picture']);
		}
		unset($POST['delfile']);
		return $this->_DB->update(VODCMS_FLASH, $POST, array('id'=>(int)$POST['id']));
	}
	public function getAll($where=null){
		$select = $this->_DB->select();
		$sql = $select->from(VODCMS_FLASH)->where($where)->order('id DESC')->toString();
		$total = $this->_DB->getCount($sql);
		$this->_Page->set($total);
		$this->printpage = $this->_Page->PrintPage();
		return $this->_DB->fetAll($sql);
	}
	public function getRow($id){
		$select = $this->_DB->select();
		$sql = $select->from(VODCMS_FLASH)->where(array('id'=> (int)$id))->order('id DESC')->toString();
		return $this->_DB->fetRow($sql);
	}
	public function  delete($id){
		return $this->_DB->delete(VODCMS_FLASH, array('id'=> (int)$id));
	}
	public function  locked($id){
		return $this->_DB->update(VODCMS_FLASH, 'locked=not(locked)' , array('id'=> (int)$id));
	}
}