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

//Modelクラスを読み込み
require_once("../../class/CLinqlist.php");


class inqlistResult extends CLinqlist
{
	function DirectMailSendAct(&$bsmactlr)
	{
		$this->__construct($bsmactlr);
	}

	function __construct(&$bsmactlr)
	{
		CLinqlist::__construct();
		$this->bsmactlr = $bsmactlr;
		$this->_view = new View("pc/admin");
	}

	function action()
	{
		$tpl_file = "result.tpl";

		//コードセット
		$frm_id = isset($_REQUEST["frm_id"]) ? $_REQUEST["frm_id"] : null;

		//フォーム名取得＆アサイン
		$this->_view->assign('frm_name', $this->getFormName($frm_id));

		//selectパーツ取得
		$part = $this->getSelectPart($frm_id);

		//selectパーツ大枠配列形成
		if(is_array($part) && count($part) > 0){
			foreach($part as $key => $val){
				$total_cnt = 0; //パーツ別トータル回答数

				$ary_tmp = null;
				$ary_tmp = explode('%%%', $val["prt_part_select_value"]);
				foreach($ary_tmp as $key2 => $val2){
					$part[$key]["prt_part_select"][$key2]["str"] = $val2;
					$part[$key]["prt_part_select"][$key2]["cnt"] = 0;
				}

				//回答取得
				$ans = $this->getSelectAnswer($val["prt_frm_id"], $val["prt_part_id"]);
				$ans_ary = null;
				if(is_array($ans) && count($ans) > 0){
					$ans_tmp = null;
					foreach($ans as $key3 => $val3){
						$ans_tmp = explode('%%%', $val3["idet_part_value"]);
						foreach($ans_tmp as $key4 => $val4){
							$ans_ary[] = $val4;
						}
					}
				}

				//回答カウントアップ
				if(is_array($ans_ary) && count($ans_ary) > 0){
					foreach($ans_ary as $key5 => $val5){
						foreach($part[$key]["prt_part_select"] as $key6 => $val6){
							if($val5 == $val6["str"]){
								$part[$key]["prt_part_select"][$key6]["cnt"]++; //個別カウントアップ
								$total_cnt++; //トータルカウントアップ
							}
						}
					}
				}
				$part[$key]["prt_part_total_cnt"] = $total_cnt;

				//パーツタイプ
				if($val["prt_part_sub_type"] == 'radiobutton'){
					$part[$key]["prt_part_sub_type_str"] = "ラジオボタン";
				}else if($val["prt_part_sub_type"] == 'checkbox'){
					$part[$key]["prt_part_sub_type_str"] = "チェックボックス";
				}else if($val["prt_part_sub_type"] == 'dropdown'){
					$part[$key]["prt_part_sub_type_str"] = "プルダウン";
				}
			}
		}

		$this->_view->assign('part', $part);



		$this->_view->assign(CSS_PATH, BINGOTOPURL.'/usr-data/modules/extMdlFormGnrtr/admin/css/imported.css');
		$this->_view->display(MODULES_PATH."/extMdlFormGnrtr/admin/frmlist/".$tpl_file);
	}
}

$frm = new inqlistResult($bsmactlr);
$frm->action();

?>