<?php
/**
 * [LJCMS] (C)2012-2099 LJdev,Inc.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2013.11.19
*/

class guestboolAModel extends X {
    
    public function getList($items) {
        $where      = " WHERE 1=1".$items['searchsql'];
        $start      = ($items['page']-1)*$items['pagesize'];
        $countsql   = "SELECT COUNT(v.gid) FROM ".DB_PREFIX."guestbool AS v".$where;
        $total      = parent::$obj->fetch_count($countsql);
        $sql        = "SELECT v.*FROM ".DB_PREFIX."guestbool AS v".
                      $where." ORDER BY v.addtime DESC LIMIT ".$start.", ".$items['pagesize']."";
        $array = parent::$obj->getall($sql);
        return array($total, $array);
    }
    
    
    public function getData($id) {
        $sql = "SELECT v.* FROM ".DB_PREFIX."guestbool AS v".
                " WHERE v.gid='".intval($id)."'";
        $data = parent::$obj->fetch_first($sql);
        return array($data);
    }
    
    
    public function doAdd($array) {
        $gid = parent::$obj->fetch_newid('SELECT MAX(gid) FROM '.DB_PREFIX.'guestbool', 1);
        $array = array_merge(array(
                'gid'=>$gid,
				'ip'=>XRequest::getip(),
            ), $array);
        $result = parent::$obj->insert(DB_PREFIX.'guestbool', $array);
		return $result;        
    }
    
    
    public function doEdit($id, $array) {
        $result = parent::$obj->update(DB_PREFIX.'guestbool', $array, "gid='".intval($id)."'");        
        return $result;
    }
    
    
    public function doDel($id) {
		return parent::$obj->query("DELETE FROM ".DB_PREFIX."guestbool WHERE gid='".intval($id)."'");
    }
        
    
    public function doUpdate($id, $type) {
        if ($type == 'flagopen') {
            return parent::$obj->query("UPDATE ".DB_PREFIX."guestbool SET flag='1' WHERE gid='".intval($id)."'");     
        }
        elseif ($type == 'flagclose') {
            return parent::$obj->query("UPDATE ".DB_PREFIX."guestbool SET flag='0' WHERE gid='".intval($id)."'"); 
        }
    }
}
?>
