<?php
/**
 *  love.php
 *
 * @copyright			(C) 2005-2010 NewsTeng Inc.
 * @license				This is NOT a freeware, use is subject to license terms
 * @lastmodify			2010-12-16
   $Id: love.php 2 2010-12-16 10:59:13Z xuchao $
 */
defined('IN_XTCMS') or exit('No permission resources.');
base::load_app_class('admin', 'admin', 0);
base::load_sys_class('format', '', 0);
base::load_sys_class('form', '', 0);
class love extends admin {

private $db, $config;
	/**
	 * 析构函数
	 */
	public function __construct() {
		parent::__construct();
		$this->db = base::load_model('love_model');
		$this->config = base::load_config('system');
	}

	/**
	 * 管理会员
	 */
	public function manage() {
		/*搜索信息*/
		$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
		$type = isset($_GET['type']) ? $_GET['type'] : '';
		$start_time = isset($_GET['start_time']) ? $_GET['start_time'] : date('Y-m-d', SYS_TIME-date('t', SYS_TIME)*86400);
		$end_time = isset($_GET['end_time']) ? $_GET['end_time'] : date('Y-m-d', SYS_TIME);

		if (isset($_GET['search'])) {
			//默认选取一个月内的用户，防止用户量过大给数据造成灾难
			$where_start_time = strtotime($start_time);
			$where_end_time = strtotime($end_time) + 86400;
			//开始时间大于结束时间，置换变量
			if($where_start_time > $where_end_time) {
				$tmp = $where_start_time;
				$where_start_time = $where_end_time;
				$where_end_time = $tmp;
				unset($tmp);
			}
			$where = "postdate BETWEEN '$where_start_time' AND '$where_end_time' AND ";


			if($type == '1') {
				$where .= "lid = '$keyword'";
			} elseif($type == '2') {
				$where .= "postip = '$keyword'";
			}
		} else {
			$where = '';
		}

		$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
		$memberlist = $this->db->listinfo($where, 'lid DESC', $page, 12);
		$pages = $this->db->pages;
		include $this->admin_tpl('love_list');
	}


	/**
	 * 删除信息
	 */
	public function delete() {
		$lidarr = isset($_POST['lid']) ? $_POST['lid'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
		$where = to_sqls($lidarr, '', 'lid');
		if ($this->db->delete($where)) {
			showmessage(L('operation_success'), HTTP_REFERER);
		} else {
			showmessage(L('operation_failure'), HTTP_REFERER);
		}
	}

}
?>