get_exception();
}
}
/* 出力準備 */
$smarty = new SmartyEx();
$smarty->prepare();
/* マイプロフィール */
include('common/myprofile.inc');
if ($need_login) {
/* ログインチェック */
if ($is_login != 1 || empty($login_user_id)) {
header('location: https://' . LOCOMILL_DOMAIN_FQDN . '/login/?is_keep=1&rdr=/client_form/' . $dir . '/');
exit;
}
}
// 設定
$smarty->assign("LIMIT", $stamp);
$smarty->assign("TITLE", $title);
$smarty->assign("TITLE_S", $title_s);
$smarty->assign("FROM", $from);
/* Validateクラスインスタンス生成 */
if ($err_str === "") {
try {
$validate = new Validate();
} catch (ValidateError $e) {
$err_str .= $e->get_exception();
}
}
/* Areaクラスインスタンス生成 */
if ($err_str === "" && $is_login == 1) {
try {
$area = new Area($locomill->get_db3());
$temp = $area->get_data_array('area_master_01_tbl', true);
foreach ($temp AS $v) {
$area_01_array[$v['id']] = $v['name'];
}
$temp = $area->get_data_array('area_master_03_tbl', true);
foreach ($temp AS $v) {
$area_03_array[$v['id']] = $v['name'];
}
$temp = $area->get_data_array('area_tbl', true);
foreach ($temp AS $v) {
$area_04_array[$v['id']] = $v['name'];
}
} catch (AreaError $e) {
$err_str .= $e->get_exception();
}
}
/* 期限切れ */
if ($err_str === "") {
if (strtotime($stamp) < mktime() && LOCOMILL_HOSTNAME == 'www') {
$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'] = $time[$row[1]]['count'] - $row[2];
if ($time[$row[1]]['count'] == 0) {
unset($time[$row[1]]);
}
}
if (empty($time)) {
$err_str = '定員を超えたため、応募を締切らせていただきました。';
}
}
/* Request値の検証 */
if (isset($_GET['thanks'])) {
$template_file = 'thanks.tpl';
$smarty->display($template_dir . $template_file);
exit;
} elseif ($err_str === "") {
if (!empty($_POST)) {
$rq = $_POST;
}
if (!empty($rq['action'])) {
$action = $rq['action'];
unset($rq['action']);
}
if ($action == 'check' || $action == 'return' || $action == 'exec') {
if (!$validate->__range($rq['name'], 1, 255)) {
$errmsg[] = '・お名前の入力が正しくありません。';
}
if (!$validate->__range($rq['kana'], 1, 255)) {
$errmsg[] = '・ふりがなの入力が正しくありません。';
}
$rq['pcode1'] = mb_convert_kana($rq['pcode1'], 'a');
$rq['pcode2'] = mb_convert_kana($rq['pcode2'], 'a');
if (!preg_match('/^[0-9]{3}-[0-9]{4}$/', sprintf('%s-%s', $rq['pcode1'], $rq['pcode2']))) {
$errmsg[] = '・郵便番号の入力が正しくありません。';
}
if (!$validate->__range($rq['address'], 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[] = '・連絡用メールアドレスが確認用と異なります。';
}
$count = 0;
for ($i = 1; $i <= 3; $i++) {
if (!empty($rq['child' . $i])) {
$count++;
}
}
if (empty($rq['time']) || !is_array($rq['time'])) {
$errmsg[] = '・体験するコースと日時の選択が正しくありません。';
} else {
foreach ($rq['time'] AS $v) {
if ($time[$v]['count'] - $count < 0) {
$errmsg[] = '・指定の体験するコースと日時は定員を超えています。';
}
}
}
$flg = false;
for ($i = 1; $i <= 3; $i++) {
if (!empty($rq['child' . $i])) {
$flg = true;
if (!$validate->__range($rq['child' . $i], 1, 100)) {
$errmsg[] = '・体験するお子さまの年齢と性別' . $i . 'の入力が正しくありません。';
}
}
}
if (!$flg) {
$errmsg[] = '・体験するお子さまの年齢と性別の入力が正しくありません。';
}
if (!empty($rq['school'])) {
if (!$validate->__range($rq['school'], 1, 100)) {
$errmsg[] = '・小学校名の入力が正しくありません。';
}
}
if (empty($rq['agreement']) || $rq['agreement'] != 1) {
$errmsg[] = '・利用規約をご確認ください。';
}
if (empty($errmsg)) {
if ($action == 'check') {
$template_file = 'confirm.tpl';
} elseif ($action == 'return') {
} elseif ($action == 'exec') {
// 人数登録
foreach ($rq['time'] AS $v) {
$log = array();
$log[] = date('Y/m/d H:i');
$log[] = $v;
$log[] = $count;
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 . $num_file;
if (is_file($log_path) && is_writable($log_path)) {
$fp = fopen($log_path, 'a+');
$result = fputs($fp, $csv);
fclose($fp);
}
}
// ログ登録
$rq['pcode'] = sprintf('%s-%s', $rq['pcode1'], $rq['pcode2']);
$rq['tel'] = sprintf('%s-%s-%s', $rq['tel1'], $rq['tel2'], $rq['tel3']);
$temp = array();
foreach ($rq['time'] AS $v) {
$temp[] = $time[$v]['name'];
}
$rq['time'] = implode("\n", $temp);
$log = array();
$log[] = date('Y/m/d H:i');
$log[] = $rq['name'];
$log[] = $rq['kana'];
$log[] = $rq['pcode'];
$log[] = $rq['address'];
$log[] = $rq['tel'];
$log[] = $rq['email'];
$log[] = $rq['time'];
for ($i = 1; $i <= 3; $i++) {
$log[] = $rq['child' . $i];
}
$log[] = $rq['school'];
if ($need_login) {
$log[] = $login_user_id;
}
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)) {
$child = array();
for ($i = 1; $i <= 3; $i++) {
if (!empty($rq['child' . $i])) {
$child[] = $rq['child' . $i];
}
}
$rq['child'] = implode("\n", $child);
$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 .= '・送信に失敗しました(内部テンプレートエラー)。
';
}
if ($err_str == "") {
header('Location: ./?thanks');
exit;
}
}
}
} else {
if ($is_login == 1) {
$address = '';
if (!empty($member_data['prefect']) && isset($area_01_array[$member_data['prefect']])) {
$address .= $area_01_array[$member_data['prefect']];
}
if (!empty($member_data['city']) && isset($area_03_array[$member_data['city']])) {
$address .= $area_03_array[$member_data['city']];
}
if (!empty($member_data['town']) && isset($area_04_array[$member_data['town']])) {
$address .= $area_04_array[$member_data['town']];
}
if (!empty($member_data['email_pc'])) {
$email = $member_data['email_pc'];
} elseif (!empty($member_data['email_mobile'])) {
$email = $member_data['email_mobile'];
} else {
$email = '';
}
$rq = array('name' => $member_data['name_01'] . $member_data['name_02'],
'pcode1' => $member_data['zipcode_01'],
'pcode2' => $member_data['zipcode_02'],
'address' => $address . $member_data['address_01'],
'tel1' => $member_data['tel_01'],
'tel2' => $member_data['tel_02'],
'tel3' => $member_data['tel_03'],
'email' => $email,
'email_check' => $email);
} else {
$rq = array();
}
}
}
/* 変数の準備 */
if (!isset($rq['time'])) {
$rq['time'] = array();
}
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("TIME", $time);
// エラー文字列
$smarty->assign("ERRMSG", trim(join('
', $errmsg)));
$smarty->assign("ERR_STR", $err_str);
/* 出 力 */
$smarty->display($template_dir . $template_file);