<?php
//お約束の呪文/////////////////////////////////
//ログインチェック、設定ファイル読み込み、Smarty Viewの生成を行う
require_once("../../../../../app_path.php");
require_once(APP_PATH.'/BSMAdminController.php');
$bsmactlr = new BSMAdminController();
///////////////////////////////////////////////

//Modelクラスを読み込み
//DBからのデータ読み込み、書き込み、大半の処理はこのModelクラスに書いてください。
require_once("../../class/CLpartlist.php");

class partlistAct extends CLpartlist
{
	function partlistAct(&$bsmactlr)
	{
		$this->__construct($bsmactlr);
	}

	function __construct(&$bsmactlr)
	{
		CLpartlist::__construct();
		$this->bsmactlr = $bsmactlr;

		//管理権限によるメニュー表示制御
		$this->setAuth($this->bsmactlr->view);
	}

	function action()
	{
		if($_SESSION['formg_tokenError'] === 1){
			unset($_SESSION['formg_tokenError']);
			$this->putTokenError();
			exit;
		}

		$tpl_file = "index.tpl";

		//ボタン
		$this->setEditButtons();

		//frm_defaultflg
		if(isset($_POST['frm_defaultflg']) && $_POST['frm_defaultflg'] != null){
			$_SESSION['frm_defaultflg'] = $_REQUEST['frm_defaultflg'];
		}

		if(isset($_POST['frm_id']) && $_POST['frm_id'] != null){
			$_SESSION['frm_id'] = $_REQUEST['frm_id'];
		}

		$this->bsmactlr->view->assign('frm_defaultflg',$_SESSION['frm_defaultflg']);

		//処理
		$req = isset($_POST['buttons']) ? $_POST['buttons'] : array();

		//一覧へ戻るボタン
		if (isset($req['BTNList']) && $req['BTNList'] != null) {
			header('location:../frmlist/index.php');
			exit();
		//削除ボタン
		} else if (isset($_REQUEST['BTNdelete']) && $_REQUEST['BTNdelete'] != null){
			if(!$this->check_token($_POST['token'])){
				$this->putTokenError();
			}
			$this->deleteData();
			$this->clrToken();
			header('location:index.php?frm_id='.$_REQUEST['prt_frm_id']);
			exit();
		}

		//フォームの公開状態フラグを設定（0..未公開 1..公開）
		if ($_REQUEST['frm_actflg'] == "1") {
			$this->updateFrmActflg($_SESSION['frm_id'], 0);
		}

		$list = $this->getList($_SESSION['frm_id']);
		$this->bsmactlr->view->assign('token', $this->getToken());
		$this->bsmactlr->view->assign('prt_frm_id', $_SESSION['frm_id']);
		$this->bsmactlr->view->assign('frm_defaultflg', $_SESSION['frm_defaultflg']);
		$this->bsmactlr->view->assign('tpllist', $list);

		$renderer = new HTML_QuickForm_Renderer_ArraySmarty($this->bsmactlr->view);
		$this->_form->accept($renderer);
		$this->bsmactlr->view->assign('form',$renderer->toArray());

		//set template file
		$this->bsmactlr->view->assign("MENU", $this->_tpl_path."/admin/common/menu.tpl");
		$this->bsmactlr->setHeadhtml('<link href="../css/imported.css" rel="stylesheet" type="text/css" media="all">');
		$this->bsmactlr->DisplayPage($this->bsmactlr->setTpl("/extMdlFormGnrtr/admin/partlist/".$tpl_file));
	}
}

$frm = new partlistAct($bsmactlr);
$frm->action();
?>