main(); exit(); class Entry { var $tmpl; var $now; var $frm; var $template = array(); var $errors = array(); var $frm_query = array( FRM_INQUIRY => array('name', 'kana', 'sex', 'age', 'email', 'body', 'shop'), FRM_STAFF => array('place', 'name', 'kana', 'sex', 'age', 'job', 'zip', 'address', 'tel', 'email', 'body'), FRM_EMPLOYEE => array('name', 'kana', 'sex', 'age', 'job', 'zip', 'address', 'tel', 'email', 'body'), ); var $places = array( "選択してください", "越谷店", "川越店", "浦和店", "上尾店", "川崎店", "大和店", "平塚店", ); // 勤務希望店舗 var $shops = array( "選択してください", "越谷店", "川越店", "浦和店", "上尾店", "川崎店", "大和店", "平塚店", "その他", ); //お問い合わせ店舗 function Entry() { $this->now = time(); } function main() { $this->tmpl = new Tmpl2(); if (isset($_REQUEST['frm'])) { $this->frm = $_REQUEST['frm']; } else { $this->frm = FRM_INQUIRY; } $this->_getTemplates(); if (isset($_POST['in'])) { $indat = $_POST['in']; } else { $indat = null; } $this->_validateErrors($indat); if ((!empty($indat) && count($this->errors) == 0) && (isset($_POST['submit_btn']) && cOuter($_POST['submit_btn']) != SUBMIT_STRING_MODIFY)) { if (cOuter($_POST['submit_btn']) == SUBMIT_STRING_CONFIRM) { $this->tmpl->fname = $this->template[PAGE_CONFIRM]; $this->_setIndat($indat, $this->tmpl); } else { $this->_createCsv($indat); $this->_sendMailUser($indat); $this->_sendMailOwner($indat); header('Location: ' . URL . '/thanks.php?frm=' . $this->frm); exit(); } } else { $this->tmpl->fname = $this->template[PAGE_TOP]; if (!empty($indat)) { $this->_setError(); $this->_setIndat($indat, $this->tmpl); } else { $this->_resetError(); $this->_resetForm(); } } $this->_outPage(); } function _setShop($val = 0) { $this->tmpl->loopset("lp_shop"); foreach ($this->shops as $key => $place) { $this->tmpl->assign("id", $key); $this->tmpl->assign("name", $place); if ($val == $key) { $this->tmpl->assign("selected_shop", " selected=''"); } else { $this->tmpl->assign("selected_shop", ""); } $this->tmpl->loopnext(); } $this->tmpl->loopset(""); $this->tmpl->assign("in_shop_name", $this->shops[$val]); } function _setPlace($val = 0) { $this->tmpl->loopset("lp_place"); foreach ($this->places as $key => $place) { $this->tmpl->assign("id", $key); $this->tmpl->assign("name", $place); if ($val == $key) { $this->tmpl->assign("selected_place", " selected=''"); } else { $this->tmpl->assign("selected_place", ""); } $this->tmpl->loopnext(); } $this->tmpl->loopset(""); $this->tmpl->assign("in_place_name", $this->places[$val]); } function _resetForm() { foreach ($this->frm_query[$this->frm] as $frmq) { if ($frmq == 'place') { $this->_setPlace(0); } elseif ($frmq == 'shop') { $this->_setShop(0); } else { $this->tmpl->assign("in_" . $frmq, ""); } } } function _resetError() { foreach ($this->frm_query[$this->frm] as $frmq) { $this->tmpl->assign("error_" . $frmq, ""); } } function _outPage() { $this->tmpl->assign('vfrm', $this->frm); $this->tmpl->flush(); } function _validateErrors($val) { $this->_validSex($val['sex']); $this->_validAge($val['age']); $this->_validTel($val['tel']); if (isset($val['shop'])) { $this->_validShop($val['shop']); } if (isset($val['place'])) { $this->_validPlace($val['place']); } if (isset($val['email'])) { $this->_validEmail($val['email']); } if (isset($val['body'])) { $this->_validBody($val['body']); } if (isset($val['name'])) { $this->_validName($val['name']); } if (isset($val['kana'])) { $this->_validKana($val['kana']); } if (isset($val['job'])) { $this->_validJob($val['job']); } if (isset($val['address'])) { $this->_validAddress($val['address']); } if (isset($val['zip'])) { $this->_validZip($val['zip']); } } function _validShop($val = 0) { if ($val == 0) { $this->errors['shop'] = ERROR_MESSAGE_REQUIRE; } } function _validPlace($val = 0) { if ($val == 0) { $this->errors['place'] = ERROR_MESSAGE_REQUIRE; } } function _validJob($val = "") { if (empty($val)) { $this->errors['job'] = ERROR_MESSAGE_REQUIRE; return; } } function _validAddress($val = "") { // if (empty($val)) { // $this->errors['address'] = ERROR_MESSAGE_REQUIRE; // return; // } } function _validSex($val = "") { if ($this->frm != FRM_INQUIRY) { if (empty($val)) { $this->errors['sex'] = ERROR_MESSAGE_REQUIRE; return; } } } function _isZenkaku($val = "") { $pat = "/[0-9a-z]*/i"; if (preg_match($pat, $val)) { return false; } else { return true; } } function _validName($val = ""){ if (empty($val)) { $this->errors['name'] = ERROR_MESSAGE_REQUIRE; return; } if ($this->_isZenkaku($val)) { $this->errors['name'] = ERROR_MESSAGE_ONLY_ZENKAKU; return; } } function _validKana($val = "") { if (empty($val)) { $this->errors['kana'] = ERROR_MESSAGE_REQUIRE; return; } if ($this->_isZenkaku($val)) { $this->errors['kana'] = ERROR_MESSAGE_ONLY_ZENKAKU; return; } } function _validAge($val = "") { if (!empty($val) || $this->frm != FRM_INQUIRY) { $val = mb_convert_kana($val, 'n'); if (!is_numeric($val)) { $this->errors['age'] = ERROR_MESSAGE_ONLY_NUM; return; } if ($val > 150) { $this->errors['age'] = ERROR_MESSAGE_ILLEGAL_VALUE; } } } function _validZip($val = "") { $pat = "/^[0-9]{3}-{0,1}[0-9]{2,4}$/"; if (!empty($val)) { $val = mb_convert_kana($val, 'n'); if (preg_match($pat, $val) === false) { $this->errors['zip'] = ERROR_MESSAGE_ILLEGAL_ZIP; return; } $val = removeZipDust($val); $inLength = strlen($val); if ($inLength < 5 || $inLength > 7) { $this->errors['zip'] = ERROR_MESSAGE_ILLEGAL_LENGTH; return; } } } function _validTel($val = "") { $pat = "/^[0-9]{2,4}-{0,1}[0-9]{2,4}-{0,1}[0-9]{3,4}$/"; if ($this->frm == FRM_INQUIRY) { return; } if (empty($val)) { $this->errors['tel'] = ERROR_MESSAGE_REQUIRE; return; } $val = mb_convert_kana($val, 'n'); if (!preg_match($pat, $val)) { $this->errors['tel'] = ERROR_MESSAGE_ILLEGAL_TEL; return; } $val = removeZipDust($val); $inTelLength = strlen($val); if ($inTelLength < 10 || $inTelLength > 12) { $this->errors['tel'] = ERROR_MESSAGE_ILLEGAL_LENGTH; return; } } function _validEmail($val = "") { $pat = "/^([a-z0-9.!#$%&'*+\/=?^_`{|}~-]+)@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z]{2,4}|museum|travel)$/i"; if (empty($val)) { $this->errors['email'] = ERROR_MESSAGE_REQUIRE; return; } if (!preg_match($pat, $val)) { $this->errors['email'] = ERROR_MESSAGE_ILLEGAL_EMAIL; return; } } function _validBody($val = "") { if (empty($val) && $this->frm == FRM_INQUIRY) { $this->errors['body'] = ERROR_MESSAGE_REQUIRE; return; } } function _createCsv($indat = array()) { $suffix = ".csv"; $fileType = array('toiawase', 'arubaito', 'seishain'); $csvFileName = $fileType[$this->frm] . '_' . date("Ym", $this->now) . $suffix; $body = ""; $indat = $this->_setCsvForm($indat); if (!file_exists(DIR_CSV . $csvFileName)) { $csvtmpl = new Tmpl2(); $csvtmpl->fname = "tmpl/csv/" . $fileType[$this->frm] . $suffix; $body = $csvtmpl->flush(1); } $body .= date("Y-m-d H:i:s", $this->now) . ','; $body .= implode(',', $indat) . CRLF; $body = mb_convert_encoding($body, 'SJIS', 'UTF-8'); if ($fp = fopen(DIR_CSV . $csvFileName, 'a')) { fwrite($fp, $body); fclose($fp); return true; } else { return false; } } function _setCsvForm($val) { array_walk($val, 'aw_cOuter'); $val = changeNgLetter($val); if (isset($val['zip'])) { $val['zip'] = "\t" . $this->_setNumCombo($val['zip']); } if (isset($val['tel'])) { $val['tel'] = "\t" . $this->_setNumCombo($val['tel']); } if (isset($val['fax'])) { $val['fax'] = "\t" . $this->_setNumCombo($val['fax']); } if (isset($val['mobile'])) { $val['mobile'] = "\t" . $this->_setNumCombo($val['mobile']); } if (isset($val['age'])) { $val['age'] = mb_convert_kana($val['age'], 'n'); } if (isset($val['place'])) { $val['place'] = $this->places[$val['place']]; } if (isset($val['shop'])) { $val['shop'] = $this->shops[$val['shop']]; } if (isset($val['sex'])) { switch ($val['sex']) { case 1: $val['sex'] = '男性'; break; case 2: $val['sex'] = '女性'; break; default: $val['sex'] = '未選択'; break; } } return $val; } function _setNumCombo($val = '') { $val = mb_convert_kana($val, 'n'); $val = removeZipDust($val); return $val; } function _sendMailUser($indat = array()) { $tmpl = new Tmpl2($this->template[MAIL_USER]); $this->_setIndat($indat, $tmpl); $tmpl->assign('url', SITEURL); $body = $tmpl->flush(1); $body = $this->_convertMailBody($body); $subject = $this->_convertMailSubject(SUBJECT_SEND_COPY); $to = $indat['email']; switch ($this->frm) { case FRM_ENTRY_STAFF: $from = EMAIL_SUPPORT_STAFF; break; case FRM_ENTRY_EMPLOYEE: $from = EMAIL_SUPPORT_EMPLOYEE; break; default: $from = EMAIL_SUPPORT_INQUIRY; break; } mail($to, $subject, $body, "From: " . $from); } function _sendMailOwner($indat = array()) { $tmpl = new Tmpl2($this->template[MAIL_OWNER]); $this->_setIndat($indat, $tmpl); $tmpl->assign('url', URL); $body = $tmpl->flush(1); $body_original = $body; $body = $this->_convertMailBody($body); $subjects = array(SUBJECT_INQUIRY, SUBJECT_ENTRY_STAFF, SUBJECT_ENTRY_EMPLOYEE); if (isset($subjects[$this->frm])) { $subject = $this->_convertMailSubject($subjects[$this->frm]); } else { $subject = $this->_convertMailSubject("エラー"); } switch ($this->frm) { case FRM_ENTRY_STAFF: $to = EMAIL_SUPPORT_STAFF; break; case FRM_ENTRY_EMPLOYEE: $to = EMAIL_SUPPORT_EMPLOYEE; break; default: $to = EMAIL_SUPPORT_INQUIRY; break; } $from = $indat['email']; // mail($to, $subject, $body, "From: " . $from); mb_send_mail($to, $subjects[$this->frm], mb_convert_kana($body_original, "KVa"), "From: " . $from); } function _convertMailSubject($val = "") { return mb_encode_mimeheader($val, "ISO-2022-JP","B"); } function _convertMailBody($val = "") { $val = mb_convert_kana($val, "KVa"); return mb_convert_encoding($val, "ISO-2022-JP", "UTF-8"); } /* * テンプレートを指定する場合 * $sw と $tmpl(テンプレートクラスを指定する) */ function _setIndat($indat, &$tmplc) { if (!empty($indat)) { foreach ($indat as $inkey => $ind) { $tmplc->assign('in_' . $inkey, h(cOuter($ind))); } if (isset($indat['shop'])) { $this->_setShop($indat['shop']); $tmplc->assign('in_shop_name', $this->shops[$indat['shop']]); } if (isset($indat['shop'])) { $this->_setShop($indat['shop']); $tmplc->assign('in_shop_name', $this->shops[$indat['shop']]); } if (isset($indat['place'])) { $this->_setPlace($indat['place']); $tmplc->assign('in_place_name', $this->places[$indat['place']]); } if (isset($indat['age'])) { $tmplc->assign('age_suffix', '歳'); } else { $tmplc->assign('age_suffix', ''); } if (!isset($indat['sex'])) { $indat['sex'] = 0; } switch ($indat['sex']) { case 1: $tmplc->assign('selected_1' , 'checked=""'); $tmplc->assign('selected_2' , ''); $tmplc->assign('in_sex_name', '男性'); break; case 2: $tmplc->assign('selected_1' , ''); $tmplc->assign('selected_2' , 'checked=""'); $tmplc->assign('in_sex_name', '女性'); break; default: $tmplc->assign('selected_1' , ''); $tmplc->assign('selected_2' , ''); $tmplc->assign('in_sex_name', '未選択'); } } } function _setError() { $this->_resetError($this->frm); if (count($this->errors) > 0) { foreach ($this->errors as $key => $error) { $this->tmpl->assign('error_' . $key, $error); } } } function _getTemplates() { switch ($this->frm) { case FRM_STAFF: $this->template[PAGE_TOP] = "tmpl/staff/index.html"; $this->template[PAGE_CONFIRM] = "tmpl/staff/confirm.html"; $this->template[PAGE_THANKS] = "tmpl/staff/thanks.html"; $this->template[MAIL_USER] = "tmpl/staff/toUser.txt"; $this->template[MAIL_OWNER] = "tmpl/staff/toOwner.txt"; break; case FRM_EMPLOYEE: $this->template[PAGE_TOP] = "tmpl/employee/index.html"; $this->template[PAGE_CONFIRM] = "tmpl/employee/confirm.html"; $this->template[PAGE_THANKS] = "tmpl/employee/thanks.html"; $this->template[MAIL_USER] = "tmpl/employee/toUser.txt"; $this->template[MAIL_OWNER] = "tmpl/employee/toOwner.txt"; break; case FRM_INQUIRY: $this->template[PAGE_TOP] = "tmpl/inquiry/index.html"; $this->template[PAGE_CONFIRM] = "tmpl/inquiry/confirm.html"; $this->template[PAGE_THANKS] = "tmpl/inquiry/thanks.html"; $this->template[MAIL_USER] = "tmpl/inquiry/toUser.txt"; $this->template[MAIL_OWNER] = "tmpl/inquiry/toOwner.txt"; breaK; default: die("予期せぬエラーが発生しました。"); } } } /* ******************************************************************** * その他の関数 * *******************************************************************/ /* * 文字コード応急処置 */ function cOuter($val = "") { if (mb_detect_encoding($val) == "EUC-JP") { $val = mb_convert_encoding($val, "UTF-8", "EUC-JP"); } return $val; } function h($val = "") { return htmlspecialchars($val); } function pr($val = "") { echo "
";
	print_r($val);
	echo "
"; } function removeZipDust($val) { $val = mb_convert_kana($val, 'n'); $pat = "[^0-9]"; return mb_ereg_replace($pat, '', $val); } function aw_cOuter(&$val) { if (mb_detect_encoding($val) == "EUC-JP") { $val = mb_convert_encoding($val, "UTF-8", "EUC-JP"); } } function changeNgLetter($val = array(), $rep = ".") { $pat = "/,|\r|\n|'|\"/"; foreach ($val as $k => $v) { $val[$k] = preg_replace($pat, $rep, $v); } return $val; } ?>