<?php
require_once ('CLbaseform.php');
class CLpartcommon extends baseform
{
	function CLpartcommon()
	{
		$this->__construct();
	}

	function __construct()
	{
		baseform::__construct();
		$this->db = new DataBase();
	}
	/**
	 * Smarty prev Element 設定
	 * @param
	 * @return
	 */

	function setPartElements($data, $SelectValue, &$form)
	{
		//時間フィールド
		$h_ar = array(''=>'--');
		for($i = 0; $i < 25; $i++) {
			$h_ar[$i] = $i;
		}

		//テキストエリアのサイズ取得
		$single_size = 97; //フィールドサイズ初期値
		$multi_width_size = 97; //テキストエリア横幅初期値
		$multi_height_size = 3; //テキストエリア縦幅初期値
		foreach($data as $key => $row){
			if($row['prt_part_sub_type']=='single'){
				$size = explode('%%%',$row['prt_part_guidetext_value']);
				if(empty($size[0]) || $size[0] < 0){
					//0以下、未入力の時
					$data[$key]['text_size'] = $single_size;
				}else{
					$data[$key]['text_size'] = $size[0];
				}
			}else if($row['prt_part_sub_type']=='multiply'){
				$size = explode('%%%',$row['prt_part_guidetext_value']);
				if(empty($size[1]) || $size[1] < 0){
					//0以下、未入力の時
					$data[$key]['col_size'] = $multi_width_size;
				}else{
					$data[$key]['col_size'] = $size[1];
				}

				if(empty($size[2]) || $size[2] < 0){
					//0以下、未入力の時
					$data[$key]['row_size'] = $multi_height_size;
				}else{
					$data[$key]['row_size'] = $size[2];
				}
			}
		}

		$m10_ar = array(''=>'--','0'=>'00','10'=>'10','20'=>'20','30'=>'30','40'=>'40','50'=>'50');
		$m15_ar = array(''=>'--','0'=>'00','15'=>'15','30'=>'30','45'=>'45');
		$m30_ar = array(''=>'--','0'=>'00','30'=>'30');

		$form->registerRule('date_valid', 'callback', 'check_date_valid');
		$form->registerRule('check_date_from_to', 'callback', 'check_date_from_to');

		$form->registerRule('check_web_input', 'callback', 'check_web_input');
		$form->registerRule('check_all_input', 'callback', 'check_all_input');

		//validateに郵便番号チェックを登録
		$form->registerRule('check_zip', 'callback', 'check_zip');
		$form->registerRule('check_zip_required', 'callback', 'check_zip_required');

		//validateに電話番号チェックを登録
		$form->registerRule('rsv_check_tel_valid', 'callback', 'rsv_check_tel_valid');

		//電話番号入力チェック(分割時)を登録
		$form->registerRule('check_tel_require', 'callback', 'check_tel_require');
		//電話番号フォーマットチェック(分割時)を登録
		$form->registerRule('check_tel_format', 'callback', 'check_tel_format');

		//テキストにカタカナチェックを登録
		$form->registerRule('check_kana_input', 'callback', 'check_kana_input');
		//テキストに半角英数チェックを登録
		$form->registerRule('check_harfchar_input', 'callback', 'check_harfchar_input');
		//テキストに日付フォーマットチェックを登録
		$form->registerRule('check_date_format', 'callback', 'check_date_format');

		//日付・時間に日付妥当性チェックを登録
		$form->registerRule('check_date_input', 'callback', 'check_date_input');

		//日付・時間に時間入力チェックを登録
		$form->registerRule('check_time_input', 'callback', 'check_time_input');

		//日付・時間に必須入力チェックを登録
		$form->registerRule('check_require', 'callback', 'check_require');

		//画像認証チェック
		$form->registerRule('check_cap_frm', 'callback', 'check_cap_frm');

	    $form->addElement('hidden','sesname', session_id());
	    $form->addElement('hidden','protocol', "",array('id'=>'protocol'));
		for($i=0; $i<count($data); $i++) {
			//テキスト
			if($data[$i]['prt_part_type'] == 'text'){
				if ($data[$i]['prt_part_sub_type'] == 'single') {
				//single
					switch($data[$i]['prt_part_ime_mode']){
					case "katakana":
						$form->addElement('text', 'single'.$data[$i]['prt_part_id'], null, array('size' => $data[$i]['text_size'], 'id'=>'single'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active; width: '.$data[$i]["text_size"].'%;'));
						$form->addRule('single'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'はカタカナで入力してください。','check_kana_input',null);
						break;
					case "number":
						$form->addElement('text', 'single'.$data[$i]['prt_part_id'], null, array('size' => $data[$i]['text_size'], 'id'=>'single'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled; width: '.$data[$i]["text_size"].'%;'));
						if ($data[$i]['prt_part_mustflg'] == "1"){
							$form->addRule('single'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
						}
						$form->addRule('single'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'は数字で入力してください。','numeric',null);
						break;
					case "harfchar":
						$form->addElement('text', 'single'.$data[$i]['prt_part_id'], null, array('size' => $data[$i]['text_size'], 'id'=>'single'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled; width: '.$data[$i]["text_size"].'%;'));
						$form->addRule('single'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'は半角英数で入力してください。','check_harfchar_input',null);
						break;
					case "date":
						$form->addElement('text', 'single'.$data[$i]['prt_part_id'], null, array('size' => $data[$i]['text_size'], 'id'=>'single'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled; width: '.$data[$i]["text_size"].'%;'));
						$form->addRule('single'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'は2009/01/01の形式で入力してください。','check_date_format',null);
						$form->addRule('single'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'に正しい日付を入力してください。','check_date_input',null);
						break;
					default :
						$form->addElement('text', 'single'.$data[$i]['prt_part_id'], null, array('size' => $data[$i]['text_size'], 'id'=>'single'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active; width: '.$data[$i]["text_size"].'%;'));
					}
					if ($data[$i]['prt_part_mustflg'] == "1"){
						$form->addRule('single'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
					}
				} else if ($data[$i]['prt_part_sub_type'] == 'multiply') {
					//multiply
					if($data[$i]['prt_part_ime_mode']=="harfchar"){
						$form->addElement('textarea', 'multiply'.$data[$i]['prt_part_id'], null, array('rows' => $data[$i]['row_size'],  'id' => 'multiply'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled; width:'.$data[$i]['col_size'].'%;'));
					}else{
						$form->addElement('textarea', 'multiply'.$data[$i]['prt_part_id'], null, array('rows' => $data[$i]['row_size'],  'id' => 'multiply'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active; width:'.$data[$i]['col_size'].'%;'));
					}
					if ($data[$i]['prt_part_mustflg'] == "1"){
						$form->addRule('multiply'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
					}
					if ($data[$i]['prt_part_mustflg'] == "1"){
						$form->addRule('multiply'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
					}
					switch($data[$i]['prt_part_ime_mode']){
						case "katakana":
							$form->addRule('multiply'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'はカタカナで入力してください。','check_kana_input',null);
							break;
						case "harfchar":
							$form->addRule('multiply'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'は半角英数で入力してください。','check_harfchar_input',null);
							break;
					}
				}
			//選択肢
			} else if ($data[$i]['prt_part_sub_type'] == 'radiobutton') {
				$radio = array();
				for($j=0; $j<count($SelectValue); $j++){
					if($SelectValue[$j]['prt_part_id'] == $data[$i]['prt_part_id']) {
						$select = explode("%%%",$SelectValue[$j]["prt_part_select_value"]);
						foreach($select as $k=>$v){
							$radio[] = $form->addElement('radio', null, null, $v, $v, array('id' => 'radio'.$data[$i]['prt_part_id'].$k));
							$sort = ($data[$i]['prt_part_select_row'] == "side" ? "&nbsp;" : "<br />");
							$form->addGroup($radio, 'radio'.$data[$i]['prt_part_id'], null, $sort);
						}
					}
				}
				/*
				for($j=0; $j<count($SelectValue); $j++) {
					if ($SelectValue[$j]['prt_part_id'] == $data[$i]['prt_part_id']) {
						for ($a=0; $a<count($SelectValue[$j])-4; $a++) {
							$radio[] = $form->addElement('radio', null, null, $SelectValue[$j][$a], $SelectValue[$j][$a],array('id' => 'radio'.$data[$i]['prt_part_id'].$a));
						}
						$sort = ($data[$i]['prt_part_select_row'] == "side" ? "&nbsp;" : "<br />");
						$form->addGroup($radio, 'radio'.$data[$i]['prt_part_id'], null, $sort);
					}
				}
				*/
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->setDefaults(array('radio'.$data[$i]['prt_part_id'] => $SelectValue[$j][0]));
					$form->addRule('radio'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を選択してください。','required');
				}
			} else if ($data[$i]['prt_part_sub_type'] == 'checkbox') {
				$checkbox = array();
				for($j=0; $j<count($SelectValue); $j++){
					if($SelectValue[$j]['prt_part_id'] == $data[$i]['prt_part_id']) {
						$select = explode("%%%",$SelectValue[$j]["prt_part_select_value"]);
						foreach($select as $k=>$v){
							$checkbox[] = $form->createElement('checkbox', 'checkbox'.$k,	null, $v, array('id' => 'checkbox'.$data[$i]['prt_part_id'].$k));							
						}
						$sort = ($data[$i]['prt_part_select_row'] == "side" ? "&nbsp" : "<br />");
						$form->addGroup($checkbox, 'checkbox'.$data[$i]['prt_part_id'], null, $sort, array('id' => 'checkbox'.$data[$i]['prt_part_id']));
					}
				}
				/*
				for($j=0; $j<count($SelectValue); $j++) {
					if ($SelectValue[$j]['prt_part_id'] == $data[$i]['prt_part_id']) {
						for ($a=0; $a<count($SelectValue[$j])-4; $a++) {
							$checkbox[] = $form->addElement('checkbox', 'checkbox'.$a,	null, $SelectValue[$j][$a], array('id' => 'checkbox'.$data[$i]['prt_part_id'].$a));
						}
						$sort = ($data[$i]['prt_part_select_row'] == "side" ? "&nbsp" : "<br />");
						$form->addGroup($checkbox, 'checkbox'.$data[$i]['prt_part_id'], null, $sort, array('id' => 'checkbox'.$data[$i]['prt_part_id']));
					}
				}
				*/
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addRule('checkbox'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を選択してください。','required');
				}
			} else if ($data[$i]['prt_part_sub_type'] == 'dropdown') {
				for($j=0; $j<count($SelectValue); $j++) {
						unset($dropdown);
					if ($SelectValue[$j]['prt_part_id'] == $data[$i]['prt_part_id']) {
						$dropdown[''] = "-- 選択してください --";
						$selectValue = explode("%%%",$SelectValue[$j]["prt_part_select_value"]);
//						for ($a=0; $a<count($SelectValue[$j])-4; $a++) {
//							$dropdown = array_merge($dropdown, array($SelectValue[$j][$a] => $SelectValue[$j][$a]));
//						}
						foreach($selectValue as $v){
							$dropdown[$v] = $v;
						}
						//exit;
						$form->addElement('select','dropdown'.$data[$i]['prt_part_id'], null, $dropdown, array('id' => 'dropdown'.$data[$i]['prt_part_id']));
					}
				}
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addRule('dropdown'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を選択してください。','required');
				}
			//名前
			} else if ($data[$i]['prt_part_sub_type'] == 'nametogether') {
				//nametogether
				$partData = CLpartcommon::readParts($data[$i]['prt_frm_id'],$data[$i]['prt_part_id'],'prt_part_fullname_kanaflg');
			  	$form->addElement('text', 'nametogether'.$data[$i]['prt_part_id'], null, array('size' => 20, 'maxlength' => '20', 'id'=>'nametogether'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));
				$form->addElement('text', 'nametogether_kana'.$data[$i]['prt_part_id'], null, array('size' => 20, 'maxlength' => '20', 'id'=>'nametogether1'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addRule('nametogether'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
					if($partData[0] == 1){
						$form->addRule('nametogether_kana'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'のフリガナを入力してください。','required',null);
					}
				}
				if($partData[0] == 1){
					$form->addRule('nametogether_kana'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'のフリガナはカタカナで入力してください。','check_kana_input',null,'server');
				}
			} else if ($data[$i]['prt_part_sub_type'] == 'nameseparate') {
				//nameseparate
				$partData = CLpartcommon::readParts($data[$i]['prt_frm_id'],$data[$i]['prt_part_id'],'prt_part_fullname_kanaflg');

				$form->addElement('text', 'nameseparate1'.$data[$i]['prt_part_id'], null, array('size' => 10, 'maxlength' => '10', 'id'=>'nameseparate1'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));
				$form->addElement('text', 'nameseparate2'.$data[$i]['prt_part_id'], null, array('size' => 10, 'maxlength' => '10', 'id'=>'nameseparate2'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));

				$form->addElement('text', 'nameseparate_kana1'.$data[$i]['prt_part_id'], null, array('size' => 10, 'maxlength' => '10', 'id'=>'nameseparate_kana1'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));
				$form->addElement('text', 'nameseparate_kana2'.$data[$i]['prt_part_id'], null, array('size' => 10, 'maxlength' => '10', 'id'=>'nameseparate_kana2'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));

				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addRule('nameseparate1'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の姓を入力してください。','required',null);
					$form->addRule('nameseparate2'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の名を入力してください。','required',null);
					if($partData[0] == 1){
						$form->addRule('nameseparate_kana1'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'のフリガナ（姓）を入力してください。','required',null);
						$form->addRule('nameseparate_kana2'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'のフリガナ（名）を入力してください。','required',null);
					}
				}
				if($partData[0] == 1){
					$form->addRule('nameseparate_kana1'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'のフリガナ（姓）はカタカナで入力してください。','check_kana_input',null,'server');
					$form->addRule('nameseparate_kana2'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'のフリガナ（名）はカタカナで入力してください。','check_kana_input',null,'server');
				}
			//住所
			} else if ($data[$i]['prt_part_sub_type'] == 'addresstogether') {
				//同一フィールド
				$form->addElement('text', 'addresstogether'.$data[$i]['prt_part_id'], null, array('size' => 50, 'maxlength' => '100', 'id'=>'addresstogether'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));
				$zipcode[] = $form->createElement('text', 'zip1', null, array('size' => 4, 'maxlength' => '3', 'id'=>'prt_part_address_zipflg1'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$zipcode[] = $form->createElement('text', 'zip2', null, array('size' => 5, 'maxlength' => '4', 'id'=>'prt_part_address_zipflg2'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$form->addGroup($zipcode,"zipcode".$data[$i]['prt_part_id'],null,"&nbsp;-&nbsp;");
				unset($zipcode);
				if ($data[$i]['prt_part_mustflg_adr'] == "1"){
					$form->addRule('addresstogether'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の住所を入力してください。','required',null);
				}
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addGroupRule('zipcode'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の郵便番号を入力してください。','required',null,2);
				}
				$form->addRule('zipcode'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の郵便番号を正しく入力してください。','check_zip',null.'server');

			} else if ($data[$i]['prt_part_sub_type'] == 'addressseparate') {
				//複数フィールド
				$zipcode[] = $form->createElement('text', 'zip1', null, array('size' => 4, 'maxlength' => '3', 'id'=>'prt_part_address_zipflg1'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$zipcode[] = $form->createElement('text', 'zip2', null, array('size' => 5, 'maxlength' => '4', 'id'=>'prt_part_address_zipflg2'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$form->addGroup($zipcode,"zipcode".$data[$i]['prt_part_id'],null,"&nbsp;-&nbsp;");
				unset($zipcode);
				//都道府県
				$pref_ar = array(""=>"-- 選択してください --",
								"北海道"=>"北海道", "青森県"=>"青森県", "岩手県"=>"岩手県", "宮城県"=>"宮城県",    "秋田県"=>"秋田県",
								"山形県"=>"山形県", "福島県"=>"福島県", "茨城県"=>"茨城県", "栃木県"=>"栃木県",    "群馬県"=>"群馬県",
								"埼玉県"=>"埼玉県", "千葉県"=>"千葉県", "東京都"=>"東京都", "神奈川県"=>"神奈川県", "新潟県"=>"新潟県",
								"富山県"=>"富山県", "石川県"=>"石川県", "福井県"=>"福井県", "山梨県"=>"山梨県",    "長野県"=>"長野県",
								"岐阜県"=>"岐阜県", "静岡県"=>"静岡県", "愛知県"=>"愛知県", "三重県"=>"三重県",    "滋賀県"=>"滋賀県",
								"京都府"=>"京都府", "大阪府"=>"大阪府", "兵庫県"=>"兵庫県", "奈良県"=>"奈良県",    "和歌山県"=>"和歌山県",
								"鳥取県"=>"鳥取県", "島根県"=>"島根県", "岡山県"=>"岡山県", "広島県"=>"広島県",    "山口県"=>"山口県",
								"徳島県"=>"徳島県", "香川県"=>"香川県", "愛媛県"=>"愛媛県", "高知県"=>"高知県",    "福岡県"=>"福岡県",
								"佐賀県"=>"佐賀県", "長崎県"=>"長崎県", "熊本県"=>"熊本県", "大分県"=>"大分県",    "宮崎県"=>"宮崎県",
								"鹿児島県"=>"鹿児島県", "沖縄県"=>"沖縄県");
				//都道府県
				$form->addElement('select','smmbr_pref'.$data[$i]['prt_part_id'], null, $pref_ar, array('id' => 'smmbr_pref'.$data[$i]['prt_part_id']));
				//市区町村
				$form->addElement('text','smmbr_address2'.$data[$i]['prt_part_id'], null, array('size'=>40, 'id'=>'smmbr_address2'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));
				//番地
				$form->addElement('text','smmbr_address3'.$data[$i]['prt_part_id'], null, array('size'=>50, 'id'=>'smmbr_address3'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));
				//ビル名等
				$form->addElement('text','smmbr_address4'.$data[$i]['prt_part_id'], null, array('size'=>50, 'id'=>'smmbr_address4'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:active;'));

				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addGroupRule('zipcode'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の郵便番号を入力してください。','required',null,'server');
				}
				$form->addRule('zipcode'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の郵便番号を正しく入力してください。','check_zip',null.'server');

				if ($data[$i]['prt_part_mustflg1'] == "1"){
					$form->addRule('smmbr_pref'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の都道府県を選択してください。','required',null,'server');
				}

				if ($data[$i]['prt_part_mustflg2'] == "1"){
					$form->addRule('smmbr_address2'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の市区町村を入力してください。','required',null);
				}

				if ($data[$i]['prt_part_mustflg3'] == "1"){
					$form->addRule('smmbr_address3'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の番地を入力してください。','required',null);
				}

				if ($data[$i]['prt_part_mustflg4'] == "1"){
					$form->addRule('smmbr_address4'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'のビル名等を入力してください。','required',null);
				}
			//日付
			} else if ($data[$i]['prt_part_sub_type'] == 'date') {
				//date
				$form->addElement('text', 'date'.$data[$i]['prt_part_id'],null, array('size' => 12, 'maxlength' => '10', 'id'=>'date'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				//dateto
				$form->addElement('text', 'dateto'.$data[$i]['prt_part_id'], null, array('size' => 12, 'maxlength' => '10', 'id'=>'dateto'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));

				if ($data[$i]['prt_part_datetime_defaultflg'] == "1"){
					$form->setDefaults(array('date'.$data[$i]['prt_part_id'] => date("Y-m-d")));
					$form->setDefaults(array('dateto'.$data[$i]['prt_part_id'] => date("Y-m-d")));
				}

				if ($data[$i]['prt_part_mustflg'] == "1"){
					//「FROM～TO」フラグが１場合
					if ($data[$i]['prt_part_datetime_fromtoflg'] == "1"){
						$form->addRule('date'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の開始日を入力してください。','required',null);
						$form->addRule('dateto'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の終了日を入力してください。','required',null);
					}else{
						$form->addRule('date'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
					}
				}
				if ($data[$i]['prt_part_datetime_fromtoflg'] == "1"){
					$form->addRule(array('date'.$data[$i]['prt_part_id'],'dateto'.$data[$i]['prt_part_id']),'・'.$data[$i]['prt_part_label'].'の開始日が終了日を超えています。','check_date_from_to',null,'server');
					$form->addRule('date'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の開始日を正しく入力してください。','date_valid',null,'server');
					$form->addRule('dateto'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の終了日を正しく入力してください。','date_valid',null,'server');
				}else{
					$form->addRule('date'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を正しく入力してください。','date_valid',null,'server');
				}
			//時間
			} else if ($data[$i]['prt_part_sub_type'] == 'time') {
				//time
				$time[] = $form->createElement('select','hour', null, $h_ar);
				switch($data[$i]['prt_part_datetime_interval']){
					case "10分":
						$minute_ar = $m10_ar;
						break;
					case "15分":
						$minute_ar = $m15_ar;
						break;
					case "30分":
						$minute_ar = $m30_ar;
						break;
				}
				$time[] = $form->createElement('select','minute', null, $minute_ar);
				$form -> addGroup($time,"time".$data[$i]['prt_part_id'],null,"時");
				unset($time);

				//timeto
				//「FROM～TO」フラグが１場合
				if ($data[$i]['prt_part_datetime_fromtoflg'] == "1"){
					//$form->addElement('select','hourto'.$data[$i]['prt_part_id'], null, $h_ar, array('id' => 'hourto'.$data[$i]['prt_part_id']));
					$timeto[] = $form->createElement('select','hour', null, $h_ar);
					$timeto[] = $form->createElement('select','minute', null, $minute_ar);
					$form -> addGroup($timeto,"timeto".$data[$i]['prt_part_id'],null,"時");
					unset($timeto);
				}

				//Rule設定
				if ($data[$i]['prt_part_datetime_fromtoflg'] != "1"){
					//Fromのみの時
					if ($data[$i]['prt_part_mustflg'] == "1"){
						//必須項目の時
						$form->addGroupRule("time".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の時間を入力してください。','required',server);
					}
					$form->addRule("time".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の時間に未入力があります。','check_time_input',server);
				}else if($data[$i]['prt_part_datetime_fromtoflg'] == "1"){
					//From-Toの時
					if ($data[$i]['prt_part_mustflg'] == "1"){
						//必須項目の時
						$form->addGroupRule("time".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の開始時間を入力してください。','required',server);
						$form->addGroupRule("timeto".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の終了時間を入力してください。','required',server);
					}
					$form->addRule("time".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の開始時間を時分とも入力してください。','check_time_input',server);
					$form->addRule("timeto".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の終了時間を時分とも入力してください。','check_time_input',server);
					$form->addRule(array("time".$data[$i]['prt_part_id'],"timeto".$data[$i]['prt_part_id']),'・'.$data[$i]['prt_part_label'].'の開始時間、終了時間を入力してください。','check_time_input',server);
				}

			//日付時間
			} else if ($data[$i]['prt_part_sub_type'] == 'datetime') {
				//datetime
				$form->addElement('text', 'datetime'.$data[$i]['prt_part_id'], null, array('size' => 12, 'maxlength' => '10', 'id'=>'datetime'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled; width:72px;'));
				$time[] = $form->createElement('select','hour', null, $h_ar, array('id'=>'hour'.$data[$i]['prt_part_id']));
				switch($data[$i]['prt_part_datetime_interval']){
					case "10分":
						$minute_ar = $m10_ar;
						break;
					case "15分":
						$minute_ar = $m15_ar;
						break;
					case "30分":
						$minute_ar = $m30_ar;
						break;
				}
				$time[] = $form->createElement('select','minute', null, $minute_ar);
				$form->addGroup($time,"time".$data[$i]['prt_part_id'],null,"時");
				unset($time);

				if($data[$i]['prt_part_datetime_fromtoflg']==1){
					//From～Toの時
					$form->addElement('text', 'datetimeto'.$data[$i]['prt_part_id'], null, array('size' => 12, 'maxlength' => '10', 'id'=>'datetimeto'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;width:72px;'));
					$timeto[] = $form->createElement('select','hour', null, $h_ar, array('id'=>'hour'.$data[$i]['prt_part_id']));
					$timeto[] = $form->createElement('select','minute', null, $minute_ar);
					$form->addGroup($timeto,"timeto".$data[$i]['prt_part_id'],null,"時");
					unset($timeto);
				}

				if ($data[$i]['prt_part_datetime_defaultflg'] == "1"){
					//当日デフォルト設定
					$form->setDefaults(array('datetime'.$data[$i]['prt_part_id'] => date("Y-m-d")));
					$form->setDefaults(array('datetimeto'.$data[$i]['prt_part_id'] => date("Y-m-d")));
				}

				//Rule設定
				if ($data[$i]['prt_part_datetime_fromtoflg'] != "1"){
					//Fromのみの時
					if ($data[$i]['prt_part_mustflg'] == "1"){
						//必須項目の時
						$form->addRule("datetime".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の日付を入力してください。','required',null);
						$form->addGroupRule("time".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の時間を入力してください。','required',null);
					}else{
						$form->addRule("time".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の時間に未入力があります。','check_time_input',null ,'server');
						$form->addRule(array("time".$data[$i]['prt_part_id'],"datetime".$data[$i]['prt_part_id']),'・'.$data[$i]['prt_part_label'].'の日付、又は時間に未入力があります。','check_all_input',null ,'server');
					}
					$form->addRule('datetime'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の日付を正しく入力してください。','date_valid',null,'server');

				}else if($data[$i]['prt_part_datetime_fromtoflg'] == "1"){
					//From-Toの時
					if ($data[$i]['prt_part_mustflg'] == "1"){
						//必須項目の時
						$form->addRule("datetime".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の開始日を入力してください。','required',null);
						$form->addRule("datetimeto".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の終了日を入力してください。','required',null);
						$form->addGroupRule("time".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の開始時間を入力してください。','required',null);
						$form->addGroupRule("timeto".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の終了時間を入力してください。','required',null);
					}else{
						$form->addRule(array("time".$data[$i]['prt_part_id'],"timeto".$data[$i]['prt_part_id']),'・'.$data[$i]['prt_part_label'].'の開始時間、又は終了時間に未入力があります。','check_time_input',null ,'server');
						$form->addRule(array("time".$data[$i]['prt_part_id'],"datetime".$data[$i]['prt_part_id'],"timeto".$data[$i]['prt_part_id'],"datetimeto".$data[$i]['prt_part_id']),'・'.$data[$i]['prt_part_label'].'の開始日時、又は終了日時に未入力があります。','check_all_input',null ,'server');
						$form->addRule("time".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の開始時間を時分とも入力してください。','check_time_input',null ,'server');
						$form->addRule("timeto".$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の終了時間を時分とも入力してください。','check_time_input',null ,'server');
					}
					$form->addRule('datetime'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の開始日を正しく入力してください。','date_valid',null,'server');
					$form->addRule('datetimeto'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'の終了日を正しく入力してください。','date_valid',null,'server');
					$form->addRule(array('datetime'.$data[$i]['prt_part_id'],'datetimeto'.$data[$i]['prt_part_id']),'・'.$data[$i]['prt_part_label'].'の開始日が終了日を超えています。','check_date_from_to',null,'server');
				}
			//電話
			} else if ($data[$i]['prt_part_sub_type'] == 'onepart') {
				//onepart
				$form->addElement('text', 'onepart'.$data[$i]['prt_part_id'], null, array('size' => 13, 'maxlength' => '13', 'id'=>'onepart'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addRule('onepart'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
				}
				$form->addRule('onepart'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を半角数字と半角ハイフンで入力してください。','rsv_check_tel_valid',null);

			} else if ($data[$i]['prt_part_sub_type'] == 'threepart') {
				//threepart
				$tel[]=$form->createElement('text', '0', null, array('size' => 4, 'maxlength' => '4', 'id'=>'threepart1'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$tel[]=$form->createElement('text', '1', null, array('size' => 4, 'maxlength' => '4', 'id'=>'threepart2'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$tel[]=$form->createElement('text', '2', null, array('size' => 4, 'maxlength' => '4', 'id'=>'threepart3'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$form->addGroup($tel,'tel'.$data[$i]['prt_part_id'],null,"&nbsp;-&nbsp;");
				unset($tel);
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addGroupRule('tel'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null,'server');
					$form->addGroupRule('tel'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','numeric',null.'server');
				}
				$form->addRule('tel'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'は全て入力してください。','check_tel_require',null.'server');
				$form->addRule('tel'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を正しく入力してください。','check_tel_format',null.'server');

			} else if ($data[$i]['prt_part_sub_type'] == 'mobile') {
				//mobile
				$form->addElement('text', 'mobile'.$data[$i]['prt_part_id'], null, array('size' => 12, 'maxlength' => '12', 'id'=>'mobile'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addRule('mobile'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
				}
				$form->addRule('mobile'.$data[$i]['prt_part_id'],'・「ケータイ電話」を半角数字で入力してください。','numeric',null);
			//ガイドテキスト
			} else if ($data[$i]['prt_part_type'] == 'guidetext') {
				//guidetext
				$form->addElement('textarea', 'guidetext'.$data[$i]['prt_part_id'], null, array('cols' => 40, 'id' => 'guidetext'.$data[$i]['prt_part_id'], 'rows' => '3', 'style'=>'ime-mode:active;'));
				$form->addElement('hidden','hiddenguidetext'.$data[$i]['prt_part_id'], $data[$i]['prt_part_guidetext_value'],array("id"=>'hiddenguidetext'.$data[$i]['prt_part_id']));
			//Web
			} else if ($data[$i]['prt_part_type'] == 'web') {
				$value = ($data[$i]['prt_part_web_guideflg'] == '1'? 'http://':null);
				$form->addElement('text', 'web'.$data[$i]['prt_part_id'], '', array('size' => 60,'maxlength' => '60','id' => 'web'.$data[$i]['prt_part_id'], 'value'=> $value, 'style'=>'ime-mode:active;'));
				$form->addRule('web'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を正しく入力してください。','regex','/^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/','server');
				if ($data[$i]['prt_part_mustflg'] == "1"){
					if ($data[$i]['prt_part_web_guideflg'] == '1') {
					 	$form->addRule('web'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null,'server');
					    $form->addRule('web'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','check_web_input',null,'server');
					}else{
						$form->addRule('web'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
					}
				}
			//メール
			} else if ($data[$i]['prt_part_type'] == 'mail') {
				//mail
				$form->addElement('text','allmail'.$data[$i]['prt_part_id'], null, array('size'=>30,'id'=>'allmail'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$form->addElement('text','pcmail'.$data[$i]['prt_part_id'], null, array('size'=>30,'id'=>'pcmail'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$form->addElement('text','mobilemail'.$data[$i]['prt_part_id'], null, array('size'=>30,'id'=>'mobilemail'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));

				$form->addElement('text','allmail_conf'.$data[$i]['prt_part_id'], null, array('size'=>30,'id'=>'allmail_conf'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$form->addElement('text','pcmail_conf'.$data[$i]['prt_part_id'], null, array('size'=>30,'id'=>'pcmail_conf'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$form->addElement('text','mobilemail_conf'.$data[$i]['prt_part_id'], null, array('size'=>30,'id'=>'mobilemail_conf'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$postData = $form->getSubmitValues();

				if ($postData['allmail'.$data[$i]['prt_part_id']] != null) {
					$form->addRule('allmail'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'を正しく入力してください。', 'email', null);
					$form->addRule(array('allmail'.$data[$i]['prt_part_id'], 'allmail_conf'.$data[$i]['prt_part_id']),'・'.$data[$i]['prt_part_label'].'のアドレスと確認用アドレスが一致しません。', 'compare', null);
				}

				if ($postData['pcmail'.$data[$i]['prt_part_id']] != null) {
					$form->addRule('pcmail'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'(ＰＣメール)を正しく入力してください。', 'email', null);
					$form->addRule(array('pcmail'.$data[$i]['prt_part_id'], 'pcmail_conf'.$data[$i]['prt_part_id']), '・ＰＣメールアドレスと確認用アドレスが一致しません。', 'compare', null);
				}

				if ($postData['mobilemail'.$data[$i]['prt_part_id']] != null) {
					$form->addRule('mobilemail'.$data[$i]['prt_part_id'], '・'.$data[$i]['prt_part_label'].'(携帯メール)を正しく入力してください。', 'email', null);
					$form->addRule(array('mobilemail'.$data[$i]['prt_part_id'], 'mobilemail_conf'.$data[$i]['prt_part_id']), '・携帯メールアドレスと確認用アドレスが一致しません。', 'compare', null);
				}
				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addRule('allmail'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null);
				}

				if ($data[$i]['prt_part_mustflg1'] == "1"){
					$form->addRule('pcmail'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'(ＰＣメール)を入力してください。','required',null);
				}

				if ($data[$i]['prt_part_mustflg2'] == "1"){
					$form->addRule('mobilemail'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'(携帯メール)を入力してください。','required',null);
				}
			} else if ($data[$i]['prt_part_type'] == 'fileupload') {
				//ファイルアップロード
				$form->addElement('file','file'.$data[$i]['prt_part_id'], null, array('size'=>10, 'id' => 'file'.$data[$i]['prt_part_id']));

				if ($data[$i]['prt_part_mustflg'] == "1"){
					$form->addRule('file'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'のファイルを選択してください。','uploadedfile',null,'server');
				}
			} else if ($data[$i]['prt_part_type'] == 'caps') {
				//画像認証
				$captcha = '<img src="'.BINGOTOPURL.'/usr-data/modules/extMdlFormGnrtr/units/extMdlFormGnrtrForm/img.php?'.date("ymdhis").'" id="captcha">';
				$captcha_ssl = WWW_SSL.'/usr-data/modules/extMdlFormGnrtr/units/extMdlFormGnrtrForm/img.php?'.date("ymdhis");
				if($_REQUEST['d']){
					$this->_view->assign('captcha',$captcha);
					$this->_view->assign('captcha_ssl',$captcha_ssl);
				}else if($_REQUEST['BTNreview']=="プレビュー"){
					$this->bsmactlr->view->assign('captcha', $captcha);
				}
				$form->addElement('text','caps'.$data[$i]['prt_part_id'], null, array('size'=>12, 'id' => 'caps'.$data[$i]['prt_part_id'], 'style'=>'ime-mode:disabled;'));
				$form->addRule('caps'.$data[$i]['prt_part_id'],'・'.$data[$i]['prt_part_label'].'を入力してください。','required',null,'server');
				$form->addRule('caps'.$data[$i]['prt_part_id'],'・画像に表示されている文字を正しく入力してください。 ','check_cap_frm',null,'server');
			}
		}
	}

	/**
	 * 選択肢値を取得
	 * @param   null
	 * @return	array
	 */
	function getPartSelectValue($prt_frm_id=null) {
		$data = array();
		/*
		$sql = "select   prt_frm_id,
		 				 prt_part_id,
		 				 prt_part_order,
		 				 prt_part_select_value
		        from     mdl_extMdlFormGnrtr_tbl_part
		        where    prt_part_active = 1
		        	and  prt_frm_id  = ".$prt_frm_id."
		        	and  prt_part_select_value != ''
		        order by prt_part_order";

		$result = $this->db->query($sql);
		*/
		$sql = "select   prt_frm_id,
		 				 prt_part_id,
		 				 prt_part_order,
		 				 prt_part_select_value
		        from     mdl_extMdlFormGnrtr_tbl_part
		        where    prt_part_active = 1
		        	and  prt_frm_id  = ?
		        	and  prt_part_select_value IS NOT NULL
		        order by prt_part_order";

		$result = $this->db->prepare($sql, array($prt_frm_id));

		if($result != null) {
			//データ取得
			while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
				if(isset($row) && is_array($row) && count($row) > 0) {
					if ($row['prt_part_select_value'] != "") {
						$select_value = explode(UNITS_REPLACE_FLG, $row['prt_part_select_value']);
						foreach($select_value as $v){
							$row[$v] = $v;
						}
						//$row = array_merge($row, $select_value);
					}
					$data[] = $row;
				}
			}
		}
		return $data;
	}

	/**
	 * パーツの情報取得
	 * @param   null
	 * @return	array
	 */
	function getPartData($prt_frm_id=null) {
		$data = array();
		$sql = "select count(*) from mdl_extMdlFormGnrtr_tbl_form where frm_id=".$prt_frm_id." and frm_active=1";
		//フォームが存在しない時はデフォルトフォーム表示
		if($this->db->getOne($sql) == 0){
			$prt_frm_id = 1;
		}
		/*
		$sql = "select   prt_frm_id,
		 				 prt_part_id,
		 				 prt_part_type,
		 				 prt_part_sub_type,
		 				 prt_part_mustflg,
		 				 prt_part_order,
		 				 prt_part_label,
		 				 prt_part_comment,
		 				 prt_part_comment_position,
		 				 prt_part_comment_color,
		 				 prt_part_ime_mode,
		 				 prt_part_guidetext_value,
		 				 prt_part_select_value,
		 				 prt_part_select_row,
		 				 prt_part_fullname_kanaflg,
		 				 prt_part_address_zipflg,
		 				 prt_part_address_value,
		 				 prt_part_datetime_interval,
		 				 prt_part_datetime_defaultflg,
		 				 prt_part_datetime_fromtoflg,
		 				 prt_part_web_guideflg,
		 				 prt_part_web_linkflg,
		 				 prt_part_mail_addressflg,
		 				 prt_part_mail_registerflg,
		 				 prt_part_fileupload_limitflg,
		 				 prt_part_fileupload_filetype,
		 				 prt_part_fileupload_subfiletype,
		 				 prt_part_line_size,
		 				 prt_part_line_color
		        from     mdl_extMdlFormGnrtr_tbl_part
		        where    prt_part_active = 1
		        	and  prt_frm_id  = ".$prt_frm_id."
		        order by prt_part_order";

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

		$sql = "select   prt_frm_id,
		 				 prt_part_id,
		 				 prt_part_type,
		 				 prt_part_sub_type,
		 				 prt_part_mustflg,
		 				 prt_part_order,
		 				 prt_part_label,
		 				 prt_part_comment,
		 				 prt_part_comment_position,
		 				 prt_part_comment_color,
		 				 prt_part_ime_mode,
		 				 prt_part_guidetext_value,
		 				 prt_part_select_value,
		 				 prt_part_select_row,
		 				 prt_part_fullname_kanaflg,
		 				 prt_part_address_zipflg,
		 				 prt_part_address_value,
		 				 prt_part_datetime_interval,
		 				 prt_part_datetime_defaultflg,
		 				 prt_part_datetime_fromtoflg,
		 				 prt_part_web_guideflg,
		 				 prt_part_web_linkflg,
		 				 prt_part_mail_addressflg,
		 				 prt_part_mail_registerflg,
		 				 prt_part_fileupload_limitflg,
		 				 prt_part_fileupload_filetype,
		 				 prt_part_fileupload_subfiletype,
		 				 prt_part_line_size,
		 				 prt_part_line_color
		        from     mdl_extMdlFormGnrtr_tbl_part
		        where    prt_part_active = 1
		        	and  prt_frm_id  = ?
		        order by prt_part_order";

		$result = $this->db->prepare($sql, array($prt_frm_id));

		if($result != null) {
			//データ取得
			$i = 0;
			while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
				if(isset($row) && is_array($row) && count($row) > 0) {
					$mustflg	 		 = explode(UNITS_REPLACE_FLG, $row['prt_part_mustflg']);
					$mustType	 		 = explode(UNITS_REPLACE_FLG, $row['prt_part_mustflg']);
					$address_value 		 = explode(UNITS_REPLACE_FLG, $row['prt_part_address_value']);
					$mail_addressflg 	 = explode(UNITS_REPLACE_FLG, $row['prt_part_mail_addressflg']);
					$fileupload_filetype = explode(UNITS_REPLACE_FLG, $row['prt_part_fileupload_filetype']);

				   $tempData = array('prt_frm_id'						=> $row['prt_frm_id'],
					 				 'prt_part_id'						=> $row['prt_part_id'],
					 				 'prt_part_type'					=> $row['prt_part_type'],
					 				 'prt_part_sub_type'				=> $row['prt_part_sub_type'],
					 				 'prt_part_order'					=> $row['prt_part_order'],
					 				 'prt_part_label'					=> $row['prt_part_label'],
					 				 'prt_part_comment'					=> $row['prt_part_comment'],
				   					 'prt_part_comment_position'		=> $row['prt_part_comment_position'],
				   					 'prt_part_comment_color'			=> $row['prt_part_comment_color'],
				   					 'prt_part_select_value'			=> $row['prt_part_select_value'],
				   					 'prt_part_select_row'				=> $row['prt_part_select_row'],
				  					 'prt_part_ime_mode'				=> $row['prt_part_ime_mode'],
					 				 'prt_part_guidetext_value'			=> $row['prt_part_guidetext_value'],
					 				 'prt_part_fullname_kanaflg'		=> $row['prt_part_fullname_kanaflg'],
					 				 'prt_part_address_zipflg'			=> $row['prt_part_address_zipflg'],
					 				 'prt_part_datetime_interval'		=> $row['prt_part_datetime_interval'],
				    				 'prt_part_datetime_defaultflg'		=> $row['prt_part_datetime_defaultflg'],
					 				 'prt_part_datetime_fromtoflg'		=> $row['prt_part_datetime_fromtoflg'],
					 				 'prt_part_web_guideflg'			=> $row['prt_part_web_guideflg'],
					 				 'prt_part_web_linkflg'				=> $row['prt_part_web_linkflg'],
					 				 'prt_part_fileupload_limitflg'		=> $row['prt_part_fileupload_limitflg'],
					 				 'prt_part_fileupload_filetype'		=> $row['prt_part_fileupload_filetype'],
					 				 'prt_part_fileupload_subfiletype'	=> $row['prt_part_fileupload_subfiletype'],
					 				 'prt_part_line_size'				=> $row['prt_part_line_size'],
					 				 'prt_part_line_color'				=> $row['prt_part_line_color'],
									 'prt_part_mustflg' 				=> $mustflg[0],
				   					 'prt_part_mustflg1' 				=> $mustflg[1],
				   					 'prt_part_mustflg2' 				=> $mustflg[2],
				   					 'prt_part_mustflg3' 				=> $mustflg[3],
				   					 'prt_part_mustflg4' 				=> $mustflg[4],
				   					 'prt_part_mustflg_adr' 			=> $mustflg[5],
				   					 'prt_part_mustflg_all' 			=> $mustType[0],
				   					 'prt_part_mustflg_pc' 			    => $mustType[1],
				   					 'prt_part_mustflg_mobile' 			=> $mustType[2],
								     'prt_part_address_value1' 			=> $address_value[0],
								     'prt_part_address_value2' 			=> $address_value[1],
								     'prt_part_address_value3' 			=> $address_value[2],
								     'prt_part_address_value4' 			=> $address_value[3],
								     'prt_part_mail_addressflg1' 		=> $mail_addressflg[0],
				    				 'prt_part_mail_addressflg2' 		=> $mail_addressflg[1],
				  					 'prt_part_mail_addressflg3' 		=> $mail_addressflg[2],
				   				     'prt_part_mail_registerflg'        => $row['prt_part_mail_registerflg'],
									 'prt_part_fileupload_filetype1' 	=> $fileupload_filetype[0],
									 'prt_part_fileupload_filetype2' 	=> $fileupload_filetype[1],
									 'prt_part_fileupload_filetype3' 	=> $fileupload_filetype[2],
									 'prt_part_fileupload_filetype4' 	=> $fileupload_filetype[3],
									 'prt_part_fileupload_filetype5' 	=> $fileupload_filetype[4],
									 'prt_part_fileupload_filetype6' 	=> $fileupload_filetype[5],
									 'prt_part_fileupload_filetype7' 	=> $fileupload_filetype[6]
					);
					$data[$i] = $tempData;
					$i = $i + 1;
				}
			}
		}
		return $data;
	}

	/*
	 * 指定パーツデータ取得用
	 */
	function readParts($prt_frm_id=null,$prt_part_id=null,$select=null){
		$sql;
		$data = array();
		if(empty($select)){
			$sql = "select * from mdl_extMdlFormGnrtr_tbl_part where prt_part_active=1";
		}else{
			$sql = "select ".$select." from mdl_extMdlFormGnrtr_tbl_part where prt_part_active=1";
		}
		if(!empty($prt_frm_id)){
			$sql = $sql." and prt_frm_id =".$prt_frm_id;
		}
		if(!empty($prt_part_id)){
			$sql = $sql." and prt_part_id =".$prt_part_id;
		}
		$sql = $sql." order by prt_part_order";

		$result = $this->db->query($sql);
		if(!empty($result)){
			while($row = $result->fetchRow(DB_FETCHMODE_ASSOC)){
				if(empty($select)){
					$data[] = $row;
				}else{
					$data[] = $row[$select];
				}
			}
			return $data;
		}
		return null;
	}

	/**
	 * javascriptコードを作成する
	 * @param   $data
	 * @return	array
	 */
	function setJs($data)
	{
		$js ='';

		$js .='<style type="text/css">
				<!--//
				#examplecontainer {height:450px;  position:relative}'."\n";
				for($i=0; $i<count($data); $i++) {
					if($data[$i]['prt_part_type'] == 'datetime' || $data[$i]['prt_part_sub_type'] == 'date') {
	          			$js .='#' . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'div { display:none; position:absolute;z-index:1;}'."\n";
	          			if($data[$i]['prt_part_datetime_fromtoflg'] == "1"){
	          				$js .='#' . $data[$i]['prt_part_sub_type'] . 'to'. $data[$i]['prt_part_id'] . 'div { display:none; position:absolute;z-index:1;}'."\n";
	          			}
	          		}
	          	}
	    $js .= '//-->
              </style>'."\n";

		$js .= '<script type="text/javascript">
		    <!--//
			YAHOO.namespace("calendar");
			YAHOO.calendar.init = function() {
				function setStyle(obj) {
					obj.cfg.setProperty("MDY_YEAR_POSITION", 1);
					obj.cfg.setProperty("MDY_MONTH_POSITION", 2);
					obj.cfg.setProperty("MDY_DAY_POSITION", 3);
					obj.cfg.setProperty("MY_YEAR_POSITION", 1);
					obj.cfg.setProperty("MY_MONTH_POSITION", 2);
					obj.cfg.setProperty("MONTHS_SHORT",   ["1\u6708", "2\u6708", "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708", "8\u6708", "9\u6708", "10\u6708", "11\u6708", "12\u6708"]);
					obj.cfg.setProperty("MONTHS_LONG",    ["1\u6708", "2\u6708", "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708", "8\u6708", "9\u6708", "10\u6708", "11\u6708", "12\u6708"]);
					obj.cfg.setProperty("WEEKDAYS_1CHAR", ["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"]);
					obj.cfg.setProperty("WEEKDAYS_SHORT", ["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"]);
					obj.cfg.setProperty("WEEKDAYS_MEDIUM",["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"]);
					obj.cfg.setProperty("WEEKDAYS_LONG",  ["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"]);
					obj.cfg.setProperty("MY_LABEL_YEAR_POSITION",  1);
					obj.cfg.setProperty("MY_LABEL_MONTH_POSITION",  2);
					obj.cfg.setProperty("MY_LABEL_YEAR_SUFFIX",  "\u5E74");
					obj.cfg.setProperty("MY_LABEL_MONTH_SUFFIX",  "");
				}'."\n";


		$js .= ' function handleSelect(type,args,obj) {
		 			var dates = args[0];
		 			var date = dates[0];
		 			var year = date[0], month = date[1], day = date[2];
		 			var txtDate = null; '."\n";


		for($i=0; $i<count($data); $i++) {
			if($data[$i]['prt_part_type'] == 'datetime' && $data[$i]['prt_part_sub_type'] != 'time') {
				$js .= ' if(obj.id == "' . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'cal") {
							txtDate =  document.getElementById("' . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . '");
						}'."\n";
				if($data[$i]['prt_part_datetime_fromtoflg'] == 1) {
					$js .= ' if(obj.id == "' . $data[$i]['prt_part_sub_type'] . 'to'. $data[$i]['prt_part_id'] . 'cal") {
								txtDate =  document.getElementById("' . $data[$i]['prt_part_sub_type'] . 'to'. $data[$i]['prt_part_id'] . '");
							}'."\n";
				}
			}
		}

		$js .= ' txtDate.value = year + "-" + month + "-" +day
					obj.hide();
				}'."\n";

		for($i=0; $i<count($data); $i++) {
			if($data[$i]['prt_part_type'] == 'datetime' && $data[$i]['prt_part_sub_type'] != 'time') {
				$js .= $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'cal = new YAHOO.widget.Calendar("'.$data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'cal", "' . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'div", {close:true } );'."\n"
			        . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id']. 'cal.selectEvent.subscribe(handleSelect, '.$data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id']. 'cal, true);'."\n"
			        . 'setStyle('.$data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id']. 'cal);'."\n"
				    . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id']. 'cal.render();'."\n"
				    . 'YAHOO.util.Event.addListener("' . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'img", "click", ' . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'cal.show, ' . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'cal, true);'."\n"
				    . $data[$i]['prt_part_sub_type'] . $data[$i]['prt_part_id'] . 'cal.hide();'."\n";

				if($data[$i]['prt_part_datetime_fromtoflg'] == 1) {
					$js .= $data[$i]['prt_part_sub_type'] . 'to' . $data[$i]['prt_part_id'] . 'cal = new YAHOO.widget.Calendar("'.$data[$i]['prt_part_sub_type'] . 'to' .  $data[$i]['prt_part_id'] . 'cal", "' . $data[$i]['prt_part_sub_type'] . 'to' .  $data[$i]['prt_part_id'] . 'div", {close:true } );'."\n"
					    . $data[$i]['prt_part_sub_type'] .  'to' . $data[$i]['prt_part_id']. 'cal.selectEvent.subscribe(handleSelect, '.$data[$i]['prt_part_sub_type'] . 'to' .  $data[$i]['prt_part_id']. 'cal, true);'."\n"
					    . 'setStyle('.$data[$i]['prt_part_sub_type'] . 'to' .  $data[$i]['prt_part_id']. 'cal);'."\n"
						. $data[$i]['prt_part_sub_type'] . 'to' .  $data[$i]['prt_part_id']. 'cal.render();'."\n"
						. 'YAHOO.util.Event.addListener("' . $data[$i]['prt_part_sub_type'] .  'to' . $data[$i]['prt_part_id'] . 'img", "click", ' . $data[$i]['prt_part_sub_type'] .  'to' . $data[$i]['prt_part_id'] . 'cal.show, ' . $data[$i]['prt_part_sub_type'] .  'to' . $data[$i]['prt_part_id'] . 'cal, true);'."\n"
						. $data[$i]['prt_part_sub_type'] .  'to' . $data[$i]['prt_part_id'] . 'cal.hide();'."\n";
				}
			}
		}
	    $js .= '}
		    YAHOO.util.Event.onDOMReady(YAHOO.calendar.init);
			//-->
			</script>';

	    return $js;
	}
}

//ウエブサイトの入力チェック
function check_web_input($value){

	if(!isset($value) || empty($value) || $value == 'http://' || $value == ''){
		return false;
	}
	return true;
}

/**
 * 電話番号・ファックス番号チェック
 * @param	$value	text	入力値
 */
function rsv_check_tel_valid($value)
{
	if (preg_match("/^\d{2,4}\-\d{2,4}\-\d{2,4}$/", $value)) {
		return true;
	}
	return false;
}

/**
 * 電話番号桁数チェック(threepart時)
 * @param	$value	text	入力値
 */
function check_tel_length($value){
	if($value == ""){
		return true;
	}
	if(preg_match("/^\d{2,4}$/",$value)){
		return true;
	}
	return false;
}

/**
 * 電話番号入力チェック(threepart時)
 * @param	$value	text	入力値
 */
function check_tel_require($value){
	//全て未入力 or 全て入力時はtrue
	if(($value[0] =="" && $value[1] =="" && $value[2] =="") ||
		($value[0] !="" && $value[1] !="" && $value[2] !="")){
		return true;
	}
	return false;
}

/**
 * 電話番号フォーマットチェック(threepart時)
 * @param	$value	text	入力値
 */
function check_tel_format($value){
	foreach($value as $v){
		//入力があればフォーマットをチェック
		if(isset($v) && $v != ""){
			if(!ereg("^[0-9]{2,4}$",$v)){
				//１つでもエラーがあればFalse
				return false;
			}
		}
	}

	$tel = $value[0].$value[1].$value[2];
	if(!empty($tel)){
		if(!ereg("^[0-9]{10,12}$",$tel)){
			return false;
		}
	}
	return true;
}


/**
 * 全て入力のチェック
 * @param	$value	text	入力値
 */
function check_all_input($value){
	$rtn = false;
	//Fromのみ
	if(count($value) <= 2){
		//全て入力 or 未入力時はtrue
		if($value[1] != "" && $value[0]['hour'] != "" && $value[0]['minute'] != ""){
			$rtn = true;
		}else if($value[1] == "" && $value[0]['hour'] == "" && $value[0]['minute'] == ""){
			$rtn = true;
		}
	//Frmo-To
	}else{
		if($value[1] != "" && $value[0]['hour'] != "" && $value[0]['minute'] != "" &&
			$value[3] != "" && $value[2]['hour'] != "" && $value[2]['minute'] != ""){
			$rtn = true;
		}else if($value[1] == "" && $value[0]['hour'] == "" && $value[0]['minute'] == "" &&
				$value[3] == "" && $value[2]['hour'] == "" && $value[2]['minute'] == ""){
			$rtn = true;
		}
	}
	return $rtn;
}

/**
 * カタカナチェック
 * @param	$value	text	入力値
 */
function check_kana_input($value)
{
	if(!empty($value)){
    	if (mb_ereg("^([ァ-ヶｦー　[:space:]])+$",$value)) {
        	return true;
	    } else {
	        return false;
	    }
	}
	return true;
}

/**
 * 半角英数チェック
 * @param	$value	text	入力値
 */
function check_harfchar_input($value)
{
	if(!empty($value)){
	    if (preg_match("/^[\w\n\r\t\s,\?'!-;:]+$/s",$value)) {
	        return true;
	    } else {
	        return false;
	    }
	}
	return true;
}


/**
 * 日付フォーマットチェック
 * @param	$value	text	入力値
 */
function check_date_format($value)
{
	if(!empty($value)){
	    if (ereg("^[0-9]{4}/[0-2]{2}/[0-9]{2}$",$value)) {
	        return true;
	    } else {
	        return false;
	    }
	}
	return true;
}

/**
 * 日付妥当性チェック
 * @param	$value	text	入力値
 */
function check_date_input($value)
{
	if(!empty($value)){
		$date = explode("/",$value);
		if (checkdate($date[1],$date[2],$date[0])) {
			return true;
		}else{
			return false;
		}
	}
	return true;
}

/**
 * 時間入力チェック
 * @param	$value	text	入力値
 */
function check_time_input($value){
	if(count($value) <= 2){
		if($value['hour']=="" && $value['minute'] != ''){
			return false;
		}else if($value['hour']!="" && $value['minute'] == ''){
			return false;
		}
	}else{
		if($value[0]['hour']=="" && $value[0]['minute'] != ''){
			return false;
		}else if($value[0]['hour']!="" && $value[0]['minute'] == ''){
			return false;
		}else if($value[1]['hour']=="" && $value[1]['minute'] != ''){
			return false;
		}else if($value[1]['hour']!="" && $value[1]['minute'] == ''){
			return false;
		}
	}
	return true;
}

function check_require($v){
	$v = trim($v);
	if(!isset($v) || $v == null || $v == ""){
		return false;
	}
	echo $v;
	return true;
}

/**
 * 郵便番号フォーマットチェック
 *
 */
function check_zip($value){
	if((isset($value['zip1']) && trim($value['zip1']) != "") ||
		(isset($value['zip2']) && trim($value['zip2']) != "")){
		if(!ereg("^[0-9]{3}$",$value['zip1']) || !ereg("^[0-9]{4}$",$value['zip2'])){
			return false;
		}
	}
	return true;
}

/*
 * 画像認証チェック
 */
function check_cap_frm($str=null){
	if($str!=null) {
		$cap = isset($_SESSION['captext']) ? $_SESSION['captext'] : "";
		if($cap === $str){
			$_SESSION['capcheck'] = $str;
			return true;
		} else {
			$_SESSION['capcheck'] = false;
			return false;
		}
	}
}

function check_zip_required($v){
	if($v['zip1']=="" && $v['zip2']==""){
		return false;
	}
	return true;
}

?>