get_exception(); } } /* 出力準備 */ $smarty = new SmartyEx(); $smarty->prepare(); /* Validateクラスインスタンス生成 */ if( $err_str === "" ) { try { $validate = new Validate(); } catch( ValidateError $e ) { $err_str .= $e->get_exception(); } } /* 期限切れ */ if( $err_str === "" ) { if (strtotime($stamp) < mktime()) { $err_str = '受付は終了致しました。'; } } /* 回答制限 */ if( $err_str === "" ) { foreach ($time AS $k => $v) { $time[$k]['count'] = $limit; } $log_path = $log_dir . $num_file; $fp = fopen($log_path, 'r'); while ($row = fgetcsv($fp)) { $time[$row[1]]['count']--; if ($time[$row[1]]['count'] == 0) { unset($time[$row[1]]); } } if (empty($time)) $err_str = '定員を超えたため、応募を締切らせていただきました。'; } /* Request値の検証 */ if( $err_str === "" ) { if (!empty($_POST)) $rq = $_POST; if (!empty($rq['action'])) { $action = $rq['action']; unset($rq['action']); } if (isset($_GET['thanks'])) { $template_file = 'thanks.tpl'; $smarty->display( $template_dir . $template_file ); exit; } elseif ($action == 'check' || $action == 'return' || $action == 'exec') { if (!$validate->__range($rq['name'], 1, 255)) { $errmsg[] = "・予約者名の入力が正しくありません。"; } $rq['tel1'] = mb_convert_kana($rq['tel1'], 'a'); $rq['tel2'] = mb_convert_kana($rq['tel2'], 'a'); $rq['tel3'] = mb_convert_kana($rq['tel3'], 'a'); if (!$validate->__tel(sprintf('%s-%s-%s', $rq['tel1'], $rq['tel2'], $rq['tel3']))) { $errmsg[] = "・携帯電話番号の入力が正しくありません。"; } if (!$validate->__email($rq['email'])) { $errmsg[] = "・連絡用メールアドレスの入力が正しくありません。"; } elseif ($rq['email'] != $rq['email_check']) { $errmsg[] = "・連絡用メールアドレスが確認用と異なります。"; } if (!$validate->__range($rq['area'], 1, 100)) { $errmsg[] = "・お住いの市町村の入力が正しくありません。"; } if (!isset($num[$rq['num1']])) { $errmsg[] = "・大人(人数)の選択が正しくありません。"; } if (!isset($num[$rq['num2']])) { $errmsg[] = "・体験するお子さま(人数)の選択が正しくありません。"; } $tmp_time = $time; for ($i=1;$i<=5;$i++) { if ($i <= (int)$rq['num2']) { if (!$validate->__range($rq['name'.$i], 1, 255)) { $errmsg[] = "・参加するお子さま".$i."のお名前の入力が正しくありません。"; } if (!isset($tmp_time[$rq['time'.$i]])) { $errmsg[] = "・参加するお子さま".$i."のご予約時間の選択が正しくありません。"; } elseif (empty($tmp_time[$rq['time'.$i]]['count'])) { $errmsg[] = "・参加するお子さま".$i."のご予約時間は定員を超えています。"; } else { $tmp_time[$rq['time'.$i]]['count']--; } } else { $rq['name'.$i] = ''; $rq['time'.$i] = ''; } } unset($tmp_time); if (empty($errmsg)) { if( $action == 'check' ) { $template_file = 'confirm.tpl'; } elseif ($action == 'return') { } elseif ($action == 'exec') { $num2 = $rq['num2']; // 人数登録 $csv = ''; for ($i=1;$i<=$num2;$i++) { $log = array(); $log[] = date('Y/m/d H:i'); $log[] = $rq['time'.$i]; foreach ($log AS $k => $v) { $log[$k] = '"' . $v . '"'; } $csv .= join(',', $log) . "\n"; } $csv = mb_convert_encoding($csv, 'SJIS-win', mb_detect_encoding($csv)); $log_path = $log_dir . $num_file; if (is_file($log_path) && is_writable($log_path)) { $fp = fopen($log_path, 'a+'); $result = fputs($fp,$csv); fclose($fp); } // ログ登録 $rq['tel'] = sprintf('%s-%s-%s', $rq['tel1'], $rq['tel2'], $rq['tel3']); $rq['num1'] = $num[$rq['num1']]; $rq['num2'] = $num[$rq['num2']]; for ($i=1;$i<=$num2;$i++) { $rq['time'.$i] = (!empty($rq['time'.$i]))? $job[$time[$rq['time'.$i]]['group']].'/'.$time[$rq['time'.$i]]['time']:''; } $log = array(); $log[] = date('Y/m/d H:i'); $log[] = $rq['name']; $log[] = $rq['tel']; $log[] = $rq['email']; $log[] = $rq['area']; $log[] = $rq['num1']; $log[] = $rq['num2']; for ($i=1;$i<=5;$i++) { $log[] = $rq['name'.$i]; $log[] = $rq['time'.$i]; } foreach ($log AS $k => $v) { $log[$k] = '"' . $v . '"'; } $csv = (!empty($log)) ? join(',', $log) . "\n":''; $csv = mb_convert_encoding($csv, 'SJIS-win', mb_detect_encoding($csv)); $log_path = $log_dir . $log_file; if (is_file($log_path) && is_writable($log_path)) { $fp = fopen($log_path, 'a+'); $result = fputs($fp,$csv); fclose($fp); } // サンクスメール $send_email = htmlspecialchars($rq['email']); if (file_exists($read_file)) { $send_data = file($read_file); if (!empty($send_data)) { $rq['child'] = ''; for ($i=1;$i<=$num2;$i++) { $rq['child'] .= '体験するお子さまのお名前'.$i.'/'.$rq['name'.$i]."\n"; $rq['child'] .= '予約          /'.$rq['time'.$i]."\n"; } $to = $send_email; $to_name = $send_email; $subject = array_shift($send_data); $subject = set_multibyte_mime($subject, 'UTF-8', 'ISO-2022-JP'); $message = implode('', $send_data); foreach ($rq AS $k => $v) { $key = strtoupper($k); $message = str_replace( "{##".$key."##}", $v, $message ); } $message = str_replace( "
", "\r", $message ); locomill_send_mail3( $to, $to_name, $from, $from_name, $return_to, $subject, $message ); locomill_send_mail3( $from, $to_name, $from, $from_name, $return_to, $subject, $message ); } else { $err_str .= "・送信に失敗しました(内部テンプレート欠損)。
"; } } else { $err_str .= "・送信に失敗しました(内部テンプレートエラー)。
"; } header( 'Location: index.shtml?thanks' ); exit; } } } else { $rq = array('num2' => 1); } } /* 変数の準備 */ foreach ($rq AS $k => $v) { if (is_array($v)) { foreach ($v AS $v2) { $values[$k][] = htmlspecialchars($v2); } } else { $values[$k] = htmlspecialchars($v); } } $smarty->assign( "VALUES", $values ); $smarty->assign( "LIMIT", $stamp ); $smarty->assign( "NUM", $num ); $smarty->assign( "JOB", $job ); $smarty->assign( "TIME", $time ); $temp = array(); foreach ($time AS $k => $v) { if (!isset($temp[$v['group']]['name'])) { $temp[$v['group']]['name'] = $job[$v['group']]; } if (!isset($temp[$v['group']]['child'])) { $temp[$v['group']]['child'] = array(); } $temp[$v['group']]['child'][$k] = array('name' => $v['time'], 'count' => $v['count']); } $smarty->assign( "TIME_ARRAY", $temp ); // エラー文字列 $smarty->assign( "ERRMSG", trim(join('
', $errmsg))); $smarty->assign( "ERR_STR", $err_str ); /* 出 力 */ $smarty->display( $template_dir . $template_file );