<?php

/**
 *--------------------------------------
 * 留言
 *--------------------------------------
 * @project		: uwa
 * @author		: cblee
 * @created		: 2012-10-18
 * @copyright	: (c)2012 AsThis
 *--------------------------------------
 */

class GuestbookModl extends Modl
{
	public function get_guestbookList($where = '', $order = '', $limit = 10)
	{
		$_GL = $this->where($where)->order($order)->limit($limit)->select();
		return $_GL;
	}


	public function get_guestbookInfo($guestbookId)
	{
		$_GI = $this->where('guestbook_id = \''.$guestbookId.'\'')->find();
		return $_GI;
	}

	public function pass_guestbook($guestbookId)
	{
		$result = array('data' => '', 'error' => '');

		if(false === $this->where('guestbook_id = \''.$guestbookId.'\'')->set_field('g_status', 1))
		{
			$result['error'] = L('PASS_FAILED');
			return $result;
		}

		return $result;
	}

	public function add_guestbook($data)
	{
		$result = array('data' => '', 'error' => '');

		if(false === $this->insert($data))
		{
			$result['error'] = L('ADD_FAILED');
			return $result;
		}

		return $result;
	}

	public function edit_guestbook($data)
	{
		$result = array('data' => '', 'error' => '');

		if(false === $this->update($data))
		{
			$result['error'] = L('UPDATE_FAILED');
			return $result;
		}

		return $result;
	}

	public function delete_guestbook($guestbookId)
	{
		$result = array('data' => '', 'error' => '');

		if(false === $this->delete($guestbookId))
		{
			$result['error'] = L('DELETE_FAILED');
			return $result;
		}

		return $result;
	}

	public function delete_same_ip($guestbookId)
	{
		$result = array('data' => '', 'error' => '');

		$_GI = $this->get_guestbookInfo($guestbookId);
		if(empty($_GI))
		{
			$result['error'] = L('ITEM_NOT_EXSIT');
			return $result;
		}

		if(false === $this->where("`g_add_ip` ='".$_GI['g_add_ip']."'")->delete())
		{
			$result['error'] = L('DELETE_FAILED');
			return $result;
		}

		return $result;
	}

}


?>