<?php
require_once ('CLbaseform.php');

class CLfrmuser extends baseForm
{
	function CLfrmuser()
	{
		$this->__construct();
	}

	function __construct()
	{
		baseForm::__construct();
		$this->_form = new HTML_QuickForm('form','post',$_SERVER['PHP_SELF'],'',null,true);
		$this->db = new DataBase();
	}

	/**
	 * Smarty Element 設定
	 * @param
	 * @return
	 */
	function setElements()
	{
		//登録フォーム作成
		$_form = new HTML_QuickForm('form', 'post', $_SERVER['PHP_SELF'], '', null, true);

		//ユーザーデータの取得
		$userData	 = "";
		$userData	 = $this->getdata();
		$userDataDef = "";
		$userDataDef = $this->getuserdata();
		$userArray	 = array();

		$i = 0;
		foreach ($userData as $key => $val) {
			$i++;
			$userArray[] = 'usr_code'.$i;
			$chk		  = "";
			if(count($userDataDef) != 0){
				if(isset($userDataDef[$key]) && $userDataDef[$key] != ''){
					$chk = array('checked'=>true);
				}
			}
			$this->_form->addElement('checkbox', 'usr_code'.$i, '', $val, $chk);
			$this->_form->addElement('hidden', 'usr_code' . '_hid' . $i, $key);
		}
		$this->bsmactlr->view->assign('userdata', $userArray);
	}

	/**
	 * ボタン作成
	 * @param	frozen
	 * @return
	 */
	function setButtons($frozen = false)
	{
		$buttons = array();
		if ($frozen) {
			if($_SESSION["usr_info"]["usr_kanri"]==1){
				$buttons[] = $this->_form->createElement('submit', 'BTNback', ' 編集に戻る ', array('id' => 'BTNback', 'class' => 'bBtnBack'));
				$buttons[] = $this->_form->createElement('submit', 'BTNsave', ' 保存 ', array('id' => 'BTNsave', 'class' => 'bBtnSave'));
			}
		} else {
		    if($_SESSION["usr_info"]["usr_kanri"]==1) {
			$buttons[] = $this->_form->createElement('submit', 'BTNnext', ' 次へ進む ', array('id' => 'BTNnext', 'class' => 'bBtnNext'));
		    }
		}
		$this->_form->addGroup($buttons, "buttons", null, '&nbsp; &nbsp;');
	}

	/**
 	 * ユーザーデータ取得
	 * @param
 	 * @return array
 	 */
 	function getdata()
 	{
 	 	$data  = array();

 	 	$sql = "select usr_code
 	 	              ,usr_sei
 	 	              ,usr_mei
 	 	        from   tbl_user
 	 	        where  usr_kanri = '0'
 	 	        and    usr_status = '1'
 	 	        order by usr_code ";
		$result = $this->db->query($sql);

		if($result != null) {
			//データ取得
			while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
				$data[$row["usr_code"]] = $row["usr_sei"].$row["usr_mei"];
			}
		}
		return $data;
	}

    /**
 	 * ユーザーデータ取得
	 * @param
 	 * @return array
 	 */
 	function getuserdata()
 	{
 	 	$data  = array();
 	 	$sql = "select frm_usr_id
 	 	        from   mdl_extMdlFormGnrtr_tbl_form_user
 	 	        order by frm_usr_id ";

		$result = $this->db->query($sql);

		if($result != null) {
			//データ取得
			while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
				$data[$row['frm_usr_id']] = $row;
			}
		}
		return $data;
	}

}
?>