<?php
require_once("CLpartcommon.php");
class CLpartlist extends CLpartcommon
{
	function CLpartlist()
	{
		$this->__construct();
	}

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

	/**
	 * Smarty edit Element 設定
	 * @param
	 * @return
	 */
	function setEditElements()
	{
		$this->_form->addElement('hidden', 'token',   null);

		//パーツラベル
		$this->_form->addElement('text', 'prt_part_label',   null, array('size' => 20,'maxlength' => '100','id' => 'prt_part_label'));

		//パーツコメント
		$this->_form->addElement('text', 'prt_part_comment', null, array('size' => 20,'maxlength' => '100','id' => 'prt_part_comment'));

		//色の値
		$this->_form->addElement('text','prt_part_comment_color', '', array('size'=>8,'maxlength'=>'6','id'=>'prt_part_comment_color','ime-mode'=>'disabled'));

		//表示位置
		$item[]=$this->_form->addElement('radio', null, null, '上', 'top');
		$item[]=$this->_form->addElement('radio', null, null, '右横', 'right');
		$item[]=$this->_form->addElement('radio', null, null, '下', 'bottom');
		$this->_form->addGroup($item, 'prt_part_comment_position', null, '&nbsp;&nbsp;');
		$this->_form->setDefaults(array('prt_part_comment_position' => 'right'));

		//必須入力
		$this->_form->addElement('checkbox', 'prt_part_mustflg', null, '必須入力にする',null);

		//textbox(disabled)画像
		$this->_form->addElement('text',     'text_disabled1',    null, array('size' => 20, 'maxlength' => '20', 'id' => 'text_disabled1', 'disabled' => 'disabled', 'style' =>'background-color:#dddddd;'));
		$this->_form->addElement('text',     'text_disabled2',    null, array('size' => 8,  'maxlength' => '8',  'id' => 'text_disabled2', 'disabled' => 'disabled', 'style' =>'background-color:#dddddd;'));
		$this->_form->addElement('textarea', 'textarea_disabled', null, array('cols' => 40, 'rows' => 3,'id' => 'multiply', 'disabled '=> 'disabled', 'style' =>'background-color:#dddddd;'));
		$this->_form->addElement('text',     'text_tel',          null, array('size' => 5,  'maxlength' => '5',  'id' => 'text_tel', 'disabled' => 'disabled', 'style' =>'background-color:#dddddd;'));

		//guidetext
		$this->_form->addElement('textarea', 'prt_part_guidetext_value', null, array('cols' => 50, 'rows' => 4, 'id' => 'prt_part_guidetext_value'));

		//text
		$this->_form->addElement('text',     'single',   null, array('size' => 30,'maxlength' => '30','id' => 'single'));
		$this->_form->addElement('textarea', 'multiply', null, array('cols' => 40, 'rows' => 3, 'id' => 'multiply'));

		$sub_type_single[]=$this->_form->addElement('radio', null, null, 'テキスト ','single', array('onclick' => 'part_subtype_change("text","single");', 'id' => 'sub_type_single'));
		$this->_form->addGroup($sub_type_single, 'sub_type_single', null, '<br>');
		$sub_type_multiply[]=$this->_form->addElement('radio', null, null, 'テキストエリア ','multiply', array('onclick' => 'part_subtype_change("text","multiply");', 'id' => 'sub_type_multiply'));
		$this->_form->addGroup($sub_type_multiply, 'sub_type_multiply', null, '<br>');

		//text サイズ
		$this->_form->addElement('text','text_size',null, array('size' =>3,'maxlength' => '2','id' => 'text_size', 'style'=>'ime-mode:disabled;'));
		$this->_form->addElement('text','col_size',null, array('size' => 3,'maxlength' => '2','id' => 'col_size', 'style'=>'ime-mode:disabled;'));
		$this->_form->addElement('text','row_size',null, array('size' => 3,'maxlength' => '2','id' => 'row_size', 'style'=>'ime-mode:disabled;'));

		//テキストモード
		$mode[]=$this->_form->createElement('radio', null, null, '全て', 'all', array('onclick' => 'setHelpGuide()','id' => 'text_all'));
		$mode[]=$this->_form->createElement('radio', null, null, 'カタカナのみ', 'katakana', array('onclick' => 'setHelpGuide()','id' => 'text_kana'));
		$mode[]=$this->_form->createElement('radio', null, null, '半角英数', 'harfchar', array('onclick' => 'setHelpGuide()','id' => 'text_harf'));
		$mode[]=$this->_form->createElement('radio', null, null, '数字のみ', 'number', array('onclick' => 'setHelpGuide()','id' => 'text_num'));
		$mode[]=$this->_form->createElement('radio', null, null, '日付 *yyyy/mm/dd', 'date', array('onclick' => 'setHelpGuide(\'text_date\')','id' => 'text_date'));
		$this->_form->addGroup($mode, 'prt_part_ime_mode', null, '&nbsp;&nbsp;');

		$this->_form->setDefaults(array('sub_type_single' => 'single','prt_part_ime_mode' => 'all'));

		//select
		$selecttype[]=$this->_form->addElement('radio', null, null, 'ラジオボタン', 'radiobutton', array('onclick' => 'setRowButton()'));
		$selecttype[]=$this->_form->addElement('radio', null, null, 'チェックボックス', 'checkbox', array('onclick' => 'setRowButton()'));
		$selecttype[]=$this->_form->addElement('radio', null, null, 'プルダウン', 'dropdown', array('onclick' => 'setRowButton(\'drop\')', 'id'=>'dropdown'));
		$this->_form->addGroup($selecttype, 'select', null, '&nbsp;&nbsp;');

		$selectrow[]=$this->_form->addElement('radio', null, null, '横に並べる', 'side');
		$selectrow[]=$this->_form->addElement('radio', null, null, '縦に並べる', 'length');
		$this->_form->addGroup($selectrow, 'prt_part_select_row', null, '&nbsp;&nbsp;');

		$this->_form->setDefaults(array('select' => 'radiobutton'));
		$this->_form->setDefaults(array('prt_part_select_row' => 'side'));

		$this->_form->addElement('textarea', 'prt_part_select_value', null, array('cols' => 50, 'rows' => 5, 'id' => 'prt_part_select_value'));

		//name
		$sub_type_nametogether[]=$this->_form->addElement('radio', null, null, '同一フィールド','nametogether', array('onclick' => 'part_subtype_change("name","nametogether");', 'id' => 'sub_type_nametogether'));
		$this->_form->addGroup($sub_type_nametogether, 'sub_type_nametogether', null, '<br>');
		$sub_type_nameseparate[]=$this->_form->addElement('radio', null, null, '姓名別 ','nameseparate', array('onclick' => 'part_subtype_change("name","nameseparate");', 'id' => 'sub_type_nameseparate'));
		$this->_form->addGroup($sub_type_nameseparate, 'sub_type_nameseparate', null, '<br>');
		$this->_form->setDefaults(array('sub_type_nametogether' => 'nametogether'));

		$this->_form->addElement('checkbox', 'prt_part_fullname_kanaflg', null, '項目を追加する',null);

		//address
		$this->_form->addElement('checkbox', 'prt_part_address_zipflg', null, '項目を追加する',array('onclick' => 'part_subtype_change("address","prt_part_address_zipflg");','id' => 'prt_part_address_zipflg'));

		$sub_type_addresstogether[]=$this->_form->addElement('radio', null, null, '同一フィールド','addresstogether', array('onclick' => 'part_subtype_change("address","addresstogether");', 'id' => 'sub_type_addresstogether'));
		$this->_form->addGroup($sub_type_addresstogether, 'sub_type_addresstogether', null, '');
		$sub_type_addressseparate[]=$this->_form->addElement('radio', null, null, '項目別 ','addressseparate', array('onclick' => 'part_subtype_change("address","addressseparate");', 'id' => 'sub_type_addressseparate'));
		$this->_form->addGroup($sub_type_addressseparate, 'sub_type_addressseparate', null, '');
		$this->_form->setDefaults(array('sub_type_addresstogether' => 'addresstogether'));

		$this->_form->addElement('checkbox', 'prt_part_address_value1', null, '都道府県',	array('onclick' => 'part_subtype_change("address","prt_part_address_value1");','id' => 'prt_part_address_value1'));
		$this->_form->addElement('checkbox', 'prt_part_address_value2', null, '市区町村', 	array('onclick' => 'part_subtype_change("address","prt_part_address_value2");','id' => 'prt_part_address_value2'));
		$this->_form->addElement('checkbox', 'prt_part_address_value3', null, '番　　地',    array('onclick' => 'part_subtype_change("address","prt_part_address_value3");','id' => 'prt_part_address_value3'));
		$this->_form->addElement('checkbox', 'prt_part_address_value4', null, 'ビル名等',	array('onclick' => 'part_subtype_change("address","prt_part_address_value4");','id' => 'prt_part_address_value4'));


		$this->_form->addElement('checkbox', 'prt_part_mustflg_zip', null, '必須入力にする', array('id' => 'prt_part_mustflg_zip'));
		$this->_form->addElement('checkbox', 'prt_part_mustflg_adr', null, '必須入力にする', array('id' => 'prt_part_mustflg_adr'));

		$this->_form->addElement('checkbox', 'prt_part_mustflg1', null, '必須入力にする', array('id' => 'prt_part_mustflg1'));
		$this->_form->addElement('checkbox', 'prt_part_mustflg2', null, '必須入力にする', array('id' => 'prt_part_mustflg2'));
		$this->_form->addElement('checkbox', 'prt_part_mustflg3', null, '必須入力にする', array('id' => 'prt_part_mustflg3'));
		$this->_form->addElement('checkbox', 'prt_part_mustflg4', null, '必須入力にする', array('id' => 'prt_part_mustflg4'));

		//datetime
		$datetimetype[]=$this->_form->addElement('radio', null, null, '日付', 		'date', array('onclick' => 'part_subtype_change("datetime","date");', 'id' => 'sub_type_date'));
		$datetimetype[]=$this->_form->addElement('radio', null, null, '時間', 		'time', array('onclick' => 'part_subtype_change("datetime","time");', 'id' => 'sub_type_time'));
		$datetimetype[]=$this->_form->addElement('radio', null, null, '日付＆時間',	'datetime', array('onclick' => 'part_subtype_change("datetime","datetime");', 'id' => 'sub_type_datetime'));
		$this->_form->addGroup($datetimetype, 'datetime', null, '&nbsp;&nbsp;');
		$this->_form->setDefaults(array('datetime' => 'date'));

		$intervaltype[]=$this->_form->addElement('radio', null, null, '10分', '10分', array('id' => 'sub_type_datetime_interval10'));
		$intervaltype[]=$this->_form->addElement('radio', null, null, '15分', '15分', array('id' => 'sub_type_datetime_interval15'));
		$intervaltype[]=$this->_form->addElement('radio', null, null, '30分', '30分', array('id' => 'sub_type_datetime_interval30'));
		$this->_form->addGroup($intervaltype, 'prt_part_datetime_interval', null, '&nbsp;&nbsp;');
		$this->_form->setDefaults(array('prt_part_datetime_interval' => '10分'));

		$this->_form->addElement('checkbox', 'prt_part_datetime_defaultflg', null, '表示する',null);
		$this->_form->addElement('checkbox', 'prt_part_datetime_fromtoflg', null, 'FROM〜TO&nbsp;形式にする',null);

		//telphone
		$sub_type_onepart[]=$this->_form->addElement('radio', null, null, '同一フィールド','onepart', array('onclick' => 'part_subtype_change("telphone","onepart");', 'id' => 'sub_type_onepart'));
		$this->_form->addGroup($sub_type_onepart, 'sub_type_onepart', null, '<br>');
		$sub_type_threepart[]=$this->_form->addElement('radio', null, null, '通常 ','threepart', array('onclick' => 'part_subtype_change("telphone","threepart");', 'id' => 'sub_type_threepart'));
		$this->_form->addGroup($sub_type_threepart, 'sub_type_threepart', null, '<br>');

		$this->_form->setDefaults(array('sub_type_onepart' => 'onepart'));

		//web
		$this->_form->addElement('checkbox', 'prt_part_web_guideflg', null, '「http://」ガイド表示', array('id' => 'prt_part_web_guideflg'));
		$this->_form->addElement('checkbox', 'prt_part_web_linkflg',  null, '確認画面でリンク表示',  array('id' => 'prt_part_web_linkflg'));

		//mail
		$this->_form->addElement('checkbox', 'all_mail', 				  null, '項目を追加する', array('onclick' => 'part_subtype_change("mail","allmail");', 'id' => 'sub_type_allmail'));
		$this->_form->addElement('checkbox', 'pc_mail', 				  null, '項目を追加する', array('onclick' => 'part_subtype_change("mail","pcmail");', 'id' => 'sub_type_pcmail'));
		$this->_form->addElement('checkbox', 'mobile_mail', 			  null, '項目を追加する', array('onclick' => 'part_subtype_change("mail","mobilemail");', 'id' => 'sub_type_mobilemail'));
		$this->_form->addElement('checkbox', 'prt_part_mustflg_all',   	  null, '必須入力にする',  array('id' => 'prt_part_mustflg_all'));
		$this->_form->addElement('checkbox', 'prt_part_mustflg_mobile',   null, '必須入力にする',  array('id' => 'prt_part_mustflg_mobile'));
		$this->_form->addElement('checkbox', 'prt_part_mustflg_pc', 	  null, '必須入力にする',  array('id' => 'prt_part_mustflg_pc'));
		$this->_form->addElement('checkbox', 'prt_part_mail_registerflg', null, '重複登録を許可する', array('id' => 'prt_part_mail_registerflg'));
		$this->_form->addElement('hidden', 'defaultflg', $_REQUEST['prt_u_date'],array('id' => 'defaultflg'));
		//fileupload
		$limitype[]=$this->_form->addElement('radio', null, null, '全て許可&nbsp;※実行ファイル（.exe）は除く', '0', array('onclick' => 'part_subtype_change("fileupload","limitNo");', 'id' => 'limitNo'));
		$limitype[]=$this->_form->addElement('radio', null, null, '指定した拡張子のみ許可 ', '1', array('onclick' => 'part_subtype_change("fileupload","limitYes");', 'id' => 'limitYes'));
		$this->_form->addGroup($limitype, 'limit', null, '<br/>');
		$this->_form->setDefaults(array('limit' => '0'));

		$this->_form->addElement('checkbox', 'pdf',			null, 'PDF',        array('id' => 'pdf'));
		$this->_form->addElement('checkbox', 'excel',		null, 'Excel',      array('id' => 'excel'));
		$this->_form->addElement('checkbox', 'word',		null, 'Word',       array('id' => 'word'));
		//$this->_form->addElement('checkbox', 'Power_Point', null, 'PowerPoint', array('id' => 'power_point'));
		//$this->_form->addElement('checkbox', 'jpeg',		null, 'jpeg',       array('id' => 'jpeg'));
		$this->_form->addElement('checkbox', 'jpg',		null, 'jpg',       array('id' => 'jpg'));
		$this->_form->addElement('checkbox', 'gif',		null, 'gif',       array('id' => 'gif'));
		$this->_form->addElement('checkbox', 'png',			null, 'png',        array('id' => 'png'));
		//$this->_form->addElement('checkbox', 'zip',			null, 'zip',        array('id' => 'zip'));

		$this->_form->addElement('textarea', 'prt_part_fileupload_subfiletype', null, array('cols' => 50, 'rows' => 4, 'id' => 'prt_part_fileupload_subfiletype'));

		//line
		$line_size = array("1"=>"1px", "3"=>"3px", "5"=>"5px","7"=>"7px", "9"=>"9px");
		$this->_form->addElement('select','prt_part_line_size'.$data[$i]['prt_part_id'], null, $line_size);
		$this->_form->addElement('text','prt_part_line_color', '', array('size'=>9,'maxlength'=>'7','id'=>'prt_part_line_color','ime-mode'=>'disabled'));

		$this->_form->addElement('hidden','prt_frm_id',    $_REQUEST["prt_frm_id"]);
		$this->_form->addElement('hidden','prt_part_id',   $_REQUEST["prt_part_id"]);
		$this->_form->addElement('hidden','prt_part_type', $_REQUEST["prt_part_type"]);
	}

	/**
	 * フォーム入力エラーチェックの設定
	 * @param
	 * @return
	 */
	function setEditRules($part_type=null)
	{
		$this->_form->applyFilter('__ALL__','trim');
		$this->_form->setJsWarnings('下記の項目が不正です', '');
		$this->_form->registerRule('check_color',callback,'check_color');

		switch($part_type){
			case 'guidetext':
			case 'text':
			case 'select':
			case 'datetime':
			case 'web':
			case 'mail':
			case 'telphone':
			case 'fileupload':
			case 'caps':
				$this->_form->addRule("prt_part_comment_color","・「補足テキスト文字色」の値が適切ではありません","check_color", null);
				break;
			case 'line':
				$this->_form->addRule("prt_part_line_color","・「罫線色」の値が適切ではありません","check_color", null);
				break;
		}

		if ($part_type != 'line') {
			$this->_form->addRule('prt_part_label', 	   '・「項目名」を入力してください',	'required', null);
		}

		if ($part_type == 'select') {
			$this->_form->addRule('prt_part_select_value', '・「選択項目」を入力してください',	'required', null);
		}

		if ($part_type == 'text') {
			$this->_form->addRule('text_size','・「サイズ(テキスト)」には数字を入力してください','numeric', null);
			$this->_form->addRule('col_size','・「サイズ(テキストエリア)・横」には数字を入力してください','numeric', null);
			$this->_form->addRule('row_size','・「サイズ(テキストエリア)・縦」には数字を入力してください','numeric', null);
		}
	}

	/**
	 * ボタン作成
	 * @param
	 * @return
	 */
	function setEditButtons()
	{
		$buttons = array();
		$buttons[] = $this->_form->createElement('submit', 'BTNList', ' 一覧に戻る ', array('id' => 'BTNList', 'class' => 'bsmBtnListBack'));
		$buttons[] = $this->_form->createElement('button','BTNcancel',' キャンセル ',array('id'=>'BTNcancel', 'class'=>'bsmBtnCancel', 'onClick'=>'parent.closeBox();'));
		$buttons[] = $this->_form->createElement('submit', 'BTNsubmit', '保存する', array('id' => 'BTNsubmit', 'class'=>'bsmBtnSaveUnit'));
		$this->_form->addGroup($buttons, "buttons", null, '&nbsp;&nbsp;');
	}

	/**
	 * ボタン作成
	 * @param
	 * @return
	 */
	function setPrevButtons()
	{
		$buttons = array();
		$buttons[] = $this->_form->createElement('submit', 'BTNcancel', '一覧に戻る', array('id' => 'BTNcancel', 'class' => 'bsmBtnListBack'));
		$buttons[] = $this->_form->createElement('submit', 'BTNsave', '公開する', array('id' => 'BTNsave', 'class' => 'bsmBtnOpen'));
		$this->_form->addGroup($buttons, "buttons", null, '&nbsp;&nbsp;');
	}

	/**
	 * パーツ情報取得
	 * @param   null
	 * @return	array
	 */
	function getList($frm_id) {
		//$frm_id = $_SESSION['frm_id'];
		$data = array();
		/*
		$sql = "select   prt_frm_id,
		 				 prt_part_id,
		 				 prt_part_label,
		 				 prt_part_type,
		 				 prt_part_sub_type,
		 				 prt_part_order,
		 				 prt_part_fileupload_limitflg,
		 				 prt_u_date
		        from     mdl_extMdlFormGnrtr_tbl_part
		        where    prt_part_active = 1
		        	and  prt_frm_id = ".$frm_id."
		        order by prt_part_order";

		$result = $this->db->query($sql);
		*/
		$sql = "select   prt_frm_id,
		 				 prt_part_id,
		 				 prt_part_label,
		 				 prt_part_type,
		 				 prt_part_sub_type,
		 				 prt_part_order,
		 				 prt_part_fileupload_limitflg,
		 				 prt_u_date
		        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($frm_id));

		if($result != null) {
			//データ取得
			while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
				if(isset($row) && is_array($row) && count($row) > 0) {
					$prt_part_sub_type = "";
					if($row['prt_part_sub_type'] != null){
						$prt_part_sub_type = $row['prt_part_sub_type'];
					}

					$data[$row['prt_part_id']] = array('prt_frm_id' 					=> $row['prt_frm_id'],
									                    'prt_part_id' 					=> $row['prt_part_id'],
									                    'prt_part_label' 				=> $row['prt_part_label'],
														'prt_part_type' 				=> $row['prt_part_type'],
														'prt_part_sub_type' 			=> $prt_part_sub_type,
														'prt_part_order' 				=> $row['prt_part_order'],
														'prt_part_fileupload_limitflg' 	=>	$row['prt_part_fileupload_limitflg'],
														'prt_u_date' 	=>	$row['prt_u_date']
														);

				}
			}
		}
		return $data;
	}

	/**
	 * パーツの編集の情報取得
	 * @param   null
	 * @return	array
	 */
	function getData($prt_frm_id=null, $prt_part_id=null) {
		$data = array();
		/*
		$sql = "select   prt_frm_id,
		 				 prt_part_id,
		 				 prt_part_type,
		 				 prt_part_sub_type,
		 				 prt_part_mustflg,
		 				 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."
		        	and  prt_part_id = ".$prt_part_id."";

		$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_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  = ?
		        	and  prt_part_id = ?";

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

		if($result != null) {
			//データ取得
			while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
				if(isset($row) && is_array($row) && count($row) > 0) {
					$data = $row;
				}
			}
		}
		return $data;
	}

	/**
	 * フォームの公開状態フラグを設定（0..未公開 1..公開）
	 * @param   null
	 * @return	array
	 */
	function updateFrmActflg($frm_id=null, $frmActflg=null) {
		if(isset($frm_id) && $frm_id != null) {

			if ($frmActflg == 1) {
				$data = array('frm_actflg' => '1',
						      'frm_u_date' => 'now');
			} else if($frmActflg == 0) {
				$data = array('frm_actflg' => '0',
						      'frm_u_date' => 'now');
			}
			$this->db->update("mdl_extMdlFormGnrtr_tbl_form", $data, "frm_id=".$frm_id);
		}
	}

	/**
	 * バーツ情報削除
	 * @param   null
	 * @return	array
	 */
	function deleteData() {
		if(isset($_REQUEST['prt_part_id']) && $_REQUEST['prt_part_id'] != null) {
			CLpartlist::partUpdate($_REQUEST);
		}
	}

	function partUpdate($data){
		$sql = "update mdl_extMdlFormGnrtr_tbl_part set prt_part_active=0, prt_u_date = now()
				where prt_part_id = ? and prt_frm_id = ?";

		if($this->db->prepare($sql,array($data['prt_part_id'], $data['prt_frm_id']))){
			return true;
		}
		return false;
	}

	//データ保存
	function doSave($record)
	{
		return $this->update($record);
	}

	/**
	 * 更新内容の登録
	 * @return	null or err_str
	 */
	function update($record)
	{
		if((isset($record["prt_frm_id"])  && is_numeric($record["prt_frm_id"]))&&
		   (isset($record["prt_part_id"]) && is_numeric($record["prt_part_id"]))) {
			$this->db->query('BEGIN');
			if($this->db->update("mdl_extMdlFormGnrtr_tbl_part", $record,"prt_frm_id=".$record["prt_frm_id"]." and prt_part_id=".$record["prt_part_id"])) {
				$this->db->query('COMMIT');
				return null;
			}
			$this->db->query('ROLLBACK');
			return "・保存に失敗しました";
		}
		return "・コードが不明です";
	}

	/**
	 * アップロード制御が限定する時、ファイル拡張子エラーチェックの設定
	 * @param
	 * @return
	 */
	function setTypeControlRules($post)
	{
		if ($post['prt_part_type'] == 'fileupload'){
			if($post['limit'] == "1"){
				if($post['pdf']   		!= "1"
				&& $post['excel'] 		!= "1"
				&& $post['word']        != "1"
				//&& $post['Power_Point'] != "1"
				//&& $post['jpeg']       	!= "1"
				&& $post['jpg']       	!= "1"
				&& $post['gif']       	!= "1"
				&& $post['png']        	!= "1"){
				//&& $post['zip']			!= "1"){

					if(isset($post['prt_part_fileupload_subfiletype']) && $post['prt_part_fileupload_subfiletype'] == ""){
						$this->_form->setElementError('', "・「許可する拡張子」を設定してください");
						return false;
					}else{
						return true;
					}
				}//ext
			}//limit
		}//fileupload

		if ($post['prt_part_type'] == 'address'){
			if($post['sub_type_addressseparate'] == "addressseparate"){
				if($post['prt_part_address_value1']!= "1"
					&& $post['prt_part_address_value2']!= "1"
					&& $post['prt_part_address_value3']!= "1"
					&& $post['prt_part_address_value4']!= "1"){
						$this->_form->setElementError('', "・「住所」の項目をチェックしてください");
						return false;
				}else{
						return true;
				}
			}//limit
		}//address

		if ($post['prt_part_type'] == 'mail'){
			if($post['all_mail'] != "1" && $post['pc_mail'] != "1" && $post['mobile_mail']!= "1"){
				$this->_form->setElementError('', "・「共用」又は「PCメール」と「携帯メール」のどちらかにチェックをしてください");
				return false;
			}else{
				return true;
			}
		}//mail

		return true;
	}//function
}

function check_color($color){
	if(preg_match("/^[0-9a-fA-F]{3,6}$/",$color)){
		return true;
	}
	return false;
}

?>