<?php
/*
	Copyright(c) 2010 Shift Tech Inc. All Rights Reserved.
 	http://www.shift-tech.jp/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
require_once (LIB_PATH.'/common/userDB.php');
class Admin_admin_user_Index extends userDB
{
	var $_p = 0;
	var $_form = null;
	var $_name = null;
	var $_kanri = null;

	function prepare($view)
	{
		$this->_form = new HTML_QuickForm('search','post',$_SERVER['PHP_SELF'],'',null,true);
		$this->_form->addElement('text','name',null, array('size'=>30,'maxlength'=>60,'id'=>'name'));
		$this->_form->addElement('select','kanri',null, array(""=>"指定無し","0"=>"担当者","1"=>"管理者"), array('id'=>'kanri'));
		
		$this->_p = $this->getRequest('p') ? $this->getRequest('p') : 0;
		if($this->getRequest('p') > 0) {
			$_SESSION['UserSearch']['p'] = $this->_p;
		}

		$referer= $_SERVER["HTTP_REFERER"];
		if (ereg(WWW_SSL."/admin/user/",$referer)) {
			$this->_name = isset($_SESSION['UserSearch']['name']) ? $_SESSION['UserSearch']['name'] : "";
			$this->_kanri = isset($_SESSION['UserSearch']['kanri']) ? $_SESSION['UserSearch']['kanri'] : "";
			$this->_p = isset($_SESSION['UserSearch']['p']) ? $_SESSION['UserSearch']['p'] : "0";
			$this->_form->setDefaults($_SESSION['UserSearch']);
		} else {
			unset($_SESSION['UserSearch']);
			$this->_name = "";
			$this->_kanri = "";
		}

		$srch = $this->getRequest('BTNsearch');
		if (!empty($srch)) {
			$this->_name = $this->getRequest('name');
			$_SESSION['UserSearch']['name'] = $this->_name;
			$this->_kanri = $this->getRequest('kanri');
			$_SESSION['UserSearch']['kanri'] = $this->_kanri;
			$_SESSION['UserSearch']['p'] = 0;
			$this->_p = 0;
		}
		$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($view);
		$this->_form->accept($renderer);
		$view->assign('form',$renderer->toArray());
		return null;
	}

	
	
	function perform($view)
	{
		$rtn = array();
		$list = $this->getList($this->_name,$this->_kanri);
		$rtn = Pager(AD_PAGER_LIMIT, $this->_p, $list, $method='GET', $urlvar='p');
		$view->assign('list', $rtn["pagedata"]);
		$view->assign('Pages', $rtn["pageNavi"]["all"]);
        return 'user/index.tpl';
	}
}
?>
