<?php
class LinkModel{
	private $_model;
	public function __construct(){
		$this->_model = ZibanmaModel::get_instance();
	}
	
	public function zibanma_add($post){
		if(count($post)){
			foreach ($post as $v){
				$v = $this->_model->_common->filter_script($v);
			}
			return $this->_model->_db->execute("insert into [prefix]link values (null, '{$post[title]}', '{$post[url]}', '{$post[logo]}', '{$post[index]}', '{$post[name]}', '{$post[qq]}', '{$post[tel]}', '{$post[status]}'); ");
		}
		return null;
	}
	
	public function zibanma_get_list_all(){
		return $this->_model->_db->query("select * from [prefix]link; ");
	}
	
	public function zibanma_get_list($type){
		if($type == 'pic'){
			return $this->_model->_db->query("select * from [prefix]link where status=1 and logo!=''; ");
		}
		if($type == 'text'){
			return $this->_model->_db->query("select * from [prefix]link where status=1 and logo=''; ");
		}
		return $this->_model->_db->query("select * from [prefix]link where status=1; ");
	}
	
	public function zibanma_get_info_by_id($id){
		if($id){
			return $this->_model->_db->query("select * from [prefix]link where id={$id}; ");
		}
		return null;
	}
	
	public function zibanma_modification($post){
		if($post){
			return $this->_model->_db->execute("update [prefix]link set title='{$post[title]}',url='{$post[url]}',logo='{$post[logo]}',name='{$post[name]}',qq='{$post[qq]}',tel='{$post[tel]}',`index`='{$post[index]}',status='{$post[status]}' where id={$post[id]}; ");
		}
		return null;
	}
	
	public function zibanma_delete($id){
		if($id){
			return $this->_model->_db->execute("delete from [prefix]link where id={$id}");
		}
		return null;
	}
}
?>