<?php
/**
 * Copyright (C) LJCMS All rights reserved.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2016.03.19
 */

class guestbookIModel extends X {
    
    public function getList($items) {
        $where      = " WHERE v.flag='1' ".$items['searchsql'];
        $start      = ($items['page']-1)*$items['pagesize'];
        $countsql   = "SELECT COUNT(*) AS my_count FROM ".DB_PREFIX."guestbook AS v".$where;
        $total      = parent::$obj->fetch_count($countsql);
        $sql        = "SELECT v.* FROM ".DB_PREFIX."guestbook AS v".
                      $where." ORDER BY v.gid DESC LIMIT ".$start.", ".$items['pagesize']."";
        $array = parent::$obj->getall($sql);
        return array($total, $array);
    }
    
    
    public function getData($id) {
        $sql = "SELECT v.* FROM ".DB_PREFIX."guestbook 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.'guestbook', 1);
        $array = array_merge(array(
                'gid'=>$gid,
				'ip'=>XRequest::getip(),
                'addtime'=>time(),
            ), $array);
        $array['lang']=parent::$lang;
        $result = parent::$obj->insert(DB_PREFIX.'guestbook', $array);
		return $result;        
    }
}
?>
