<?php
// ÆÀÂÛ¹ÜÀí¿ØÖÆÆ÷
class CommentAction extends BaseAction {
	protected function _initializeMore() {
		$this -> obj = M('comment');
		$this -> assign('modules', $this -> obj -> commentModule);
	}
	public function defaults() {
		$page = intval(R('page'));
		$pageSize = 20;
		$passed = R('passed') === ''?1:intval(R('passed'));
		$this -> obj -> commentModule or $this -> obj -> cache();
		$m = strtolower(R('m'));
		if ($m) {
			$module = get_module($m);
			if (isset($this -> obj -> commentModule[$module['id']])) {
				$module = $this -> obj -> commentModule[$module['id']];
				if ($module['extrcomment']) $this -> showMsg(L('COMMENT_CP_MODULE'));
			} else $this -> showMsg(L('COMMENT_IS_NOT_EXIST'));
			$this -> assign('module', $module);
			$data = $this -> obj -> getAdminList($module, $page, $pageSize, 'A.passed=' . $passed);
			$this -> assign('data', $data);
			$this -> assign('pages', $this -> obj -> pages());
			$this -> assign('passed', $passed);
			$this -> assign('orderurl', '?' . del_query_string('order|field'));
			$this -> assign('order', strtoupper(R('order')) == 'DESC'?'ASC':'DESC');
		} else {
			$commentModule = array();
			$tmpModules = $this -> obj -> commentModule;
			if (is_array($tmpModules)) {
				foreach($tmpModules as $tmp) {
					$tmp['cnt1'] = $this -> obj -> where(array('passed' => 0, 'module' => $tmp['id'])) -> count();
					$tmp['cnt2'] = $this -> obj -> where(array('passed' => 1, 'module' => $tmp['id'])) -> count();
					$commentModule[] = $tmp;
				}
			}
			$this -> assign('totle', $this -> obj -> count());
			$this -> assign('totle1', $this -> obj -> where('passed=0') -> count());
			$this -> assign('commentModule', $commentModule);
			$this -> assign('totle2', $this -> obj -> where('passed=1') -> count());
		}
		$this -> display('comment');
	}
	public function edit() {
		if ($this -> isSubmit) {
			if ($this -> obj -> save()) $this -> showMsg(L('OPERATE_SUCCESS'), $this -> forward);
			elseif ($this -> obj -> error) $this -> showMsg($this -> obj -> error);
			else $this -> showMsg(L('OPERATE_FAIL'));
		}
		$cid = intval(R('cid'));
		$data = $this -> obj -> find($cid);
		$module = get_module($data['module']);
		$this -> assign('module', $module);
		$this -> assign('m', $module['name']);
		$this -> assign('data', $data);
		$this -> display('comment');
	}
	// ÉóºË
	public function check() {
		if ($this -> obj -> setFields(array('passed' => 1))) $this -> showMsg(L('OPERATE_SUCCESS'), $this -> referer);
		else $this -> showMsg($this -> error);
	}
	// É¾³ý
	public function del() {
		if ($this -> obj -> del()) $this -> showMsg(L('OPERATE_SUCCESS'), $this -> referer);
		else $this -> showMsg($this -> error);
	}
}