<?php
//--変数設定-------------------------------------
$dir = '../../../common/lib/';
$dir_lib = './lib/';
$self_name = basename($_SERVER['PHP_SELF']);
//--変数設定-------------------------------------
//$dir_data = '../../cgi-data/contact/';
if ($_SERVER['HTTP_HOST'] == 'aquarius.gofield.com') {
    $dir_data = './';
} else {
    $dir_data = '../../../../data/contact/';
}

//--ライブラリ設定-------------------------------
require_once($dir_lib.'lib.php');

//--フォーム値取得-------------------------------
//$internal_encoding = mb_internal_encoding();
//while (list($key, $val) = each($_POST)) {
//    $val = mb_convert_encoding($val, 'euc-jp', "$internal_encoding");
//    $val = get_magic_quotes_gpc() ? stripslashes($val) : $val;
//    $val = trim($val);
//    $val = str_replace( "\"", "&quot;", $val);
//    $val = mb_convert_kana($val, 'Ka', 'euc-jp');
//    $val = htmlspecialchars($val, ENT_QUOTES);
//    if ($key != 'action' && $key != 'submit') {
//        $hidden_html .= "<input type=\"hidden\" name=\"$key\" value=\"$val\" />\n";
//    }
//    $val = str_replace("\r\n", "<br />", $val);
//    $val = str_replace("\n", "<br />", $val);
//    $$key = $val;
//}

//$v_add1[$add1] = ' selected';

//--添付ファイル---------------------------------
$tmp_dir = './tmp/';
$ok_file_type = array("jpg","zip","lzh","xls","xlsx","doc","docx","ppt","pptx","jpg","gif","png","bmp","txt","pdf","rft");


if($back) {
	$action = '';
}

if ($action == 'check') {

    if (($comment == '')) {//お問い合わせ内容
        $error_message['comment'] = $error_message1;
	$action = '';
        $error_flag++;
    }

    if (($company == '')) {//会社名
        $error_message['company'] = $error_message2;
	$action = '';
        $error_flag++;
    }


    if (($name == '')) {//ご担当者名
        $error_message['name'] = $error_message3;
	$action = '';
        $error_flag++;
    }

    if (($coun == '')) {//Paese
        $error_message['coun'] = $error_message4;
	$action = '';
        $error_flag++;
    }

    if ($mail1 == '') {//ご連絡先メールアドレス
        $error_message['mail1'] = $error_message13;
	$action = '';
        $error_flag++;
    } else if (!eregi("^([a-z0-9_-]|\\\|\\.)+@(([a-z0-9_-]|\\-)+\\.)+[a-z]{2,4}$", $mail1)) {
           $error_message['mail1'] = $error_message11;
	   $action = '';
           $error_flag++;
    }

    if ($mail2 == '') {//ご連絡先メールアドレス
        $error_message['mail2'] = $error_message13;
	$action = '';
        $error_flag++;
    } else if (!eregi("^([a-z0-9_-]|\\\|\\.)+@(([a-z0-9_-]|\\-)+\\.)+[a-z]{2,4}$", $mail2)) {
           $error_message['mail2'] = $error_message11;
	   $action = '';
           $error_flag++;
    } else if($mail1 != $mail2) {
           $error_message['mail2'] = $error_message12;
	   $action = '';
           $error_flag++;
    }

//--添付ファイル---------------------------------

$upfile_name = mb_convert_encoding($_FILES['upfile']['name'], 'euc-jp');
    $upfile_dir = $tmp_dir.$upfile_name;
    $upfile_type = $_FILES['upfile']['type'];
/*    list($fn, $ex) = explode('.', $upfile_name);
    $ex = strtolower($ex);*/
    $ex = explode('.', $upfile_name);
    $nums = count($ex);
    $ex = $ex[($nums-1)];

    //echo $tmp_file.'<br />';
    //echo $_FILES['upfile']['size'];
    //echo $ex.'<br />';
    //print_r($_FILES);
    if ($_FILES['upfile']['size']) {//添付ファイル


    	$file_ok = 0;
    	foreach($ok_file_type as $data) {
		if($ex == $data) {
			$file_ok = 1;
		}
	}

        if ($_FILES['upfile']['size'] > 20971520) {
            $error_message['upfile'] = $error_message9;
            $action = '';
            $error_flag++;
        } elseif ($file_ok == '0') {
            $error_message['upfile'] = $error_message10;
            $action = '';
            $error_flag++;
        } elseif ($_FILES['upfile']['tmp_name']) {
            if (!$error_flag) {
                copy($_FILES['upfile']['tmp_name'], $upfile_dir);//ファイル保存
                $hidden_html_upfile = "<input type=\"hidden\" name=\"upfile_dir\" value=\"$upfile_dir\" />\n";
                $hidden_html_upfile .= "<input type=\"hidden\" name=\"upfile_name\" value=\"$upfile_name\" />\n";
                $hidden_html_upfile .= "<input type=\"hidden\" name=\"upfile_type\" value=\"$upfile_type\" />\n";
            }
        }
    }


    //--メッセージ設定-------------------------------
    if ($error_flag) {
    	$message_html = "<p><font color='#ff0000'>I dati inseriti non sono validi. Prego controllare nuovamente.</font></p>\n";
    }
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it" xml:lang="it">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Modulo di Richiesta｜Contatti｜FUTEC Inc.</title>
<script type="text/javascript" src="/italy/common/js/common.js"></script>
<script type="text/javascript" src="/italy/common/js/include.js"></script>
<link type="text/css" href="/italy/common/css/import.css" rel="stylesheet" />
<link type="text/css" href="../../../common/css/contact02.css" rel="stylesheet" />
<script type="text/javascript"><!--
function hideHTML(){
    $("#jp_ad1").hide();
    $("#jp_ad2").hide();
    $("#jp_ad3").hide();
    $("#jp_ad4").hide();
    $("#other_ad").show();
}

function showHTML(){
    $("#other_ad").hide();
    $("#jp_ad1").show();
    $("#jp_ad2").show();
    $("#jp_ad3").show();
    $("#jp_ad4").show();
}
--></script>
<!--<link type="text/css" href="/italy/contact/css/contact.css" rel="stylesheet" />-->
<meta name="description" content="Modulo di Richiesta, Contatti, Sistema di Ispezione Web Stampato, Sistema di Ispezione, Ispezione Superficiale, FUTEC Misuratore di Spessore Un Mondo Di Controllo Qualità &amp; Miglioramento della Produttività." />
<meta name="keywords" content="Contatti vie email,Contatti,Sistema di Ispezione,Misuratore di Spessore, Ispezione Superficiale,misura,Ispezione,Stampa,Film,Rotocalco,Offset,Metallo,Raggi-X" />
</head>

<body>

<!-- ▼ header include ▼ -->
<script type="text/javascript" >
	include("/inc/italy/header-contact.html");
</script>
<!-- ▲ header include ▲ -->

<div class="container" id="top">
	<div class="breadCrumb">
		<ul>
		<li><a href="http://www.futec-global.com/italy/index.html">Home</a></li>
		<li>&nbsp;&gt;&nbsp;<a href="http://www.futec-global.com/italy/contact/index.html">Contatti</a></li>
		<li>&nbsp;&gt;&nbsp;<em>Modulo di Richiesta</em></li>
		</ul>
	<!-- /pan -->
	</div><!-- /breadCrumb -->
	
	<div class="contents">
		<div class="main">
			<h1 class="img-tit1"><img src="/italy/contact/entry/img/ind_tit.gif" width="644" height="39" alt="Modulo di Richiesta" /></h1><a name="f_top"></a>

			<?php
			//--入力フォーム表示、入力エラー表示-------------
			if ($action == '') {
				$comment_v = str_replace("<br />", "\n", $comment);
			?>

			<!--<div class="sslbg">
				<div class="sslmark">
					<script src="https://seal.verisign.com/getseal?host_name=www.futec.co.jp&amp;size=M&amp;use_flash=YES&amp;use_transparent=YES&amp;lang=en"></script>
				</div>
				<p>Entered information is secured by SSL and used for responding the inquiry to you only and not to use other purposes.</p>
			</div>

			<div class="explanation">
				<img src="./img/contact_form_img01.gif" alt="" />
			</div>-->
			<div class="explanation">
				Se avete qualche domanda, siete pregati di compilare il seguente e fare clic sul pulsante "Conferma".
		  </div>

			<?=$message_html?>

			<form method="post" action="./<?=$self_name?>#f_top" enctype="multipart/form-data">
				<table class="contactform" summary="Inquiry">
				<tr>
					<th>Domanda</th>
				</tr>
				<tr>
					<td>
					<?=$error_message['comment']?>
					<textarea class="inquiry" rows="26" cols="400" style="width:630px;height:250px;" name="comment"><?=$comment_v?></textarea>
					</td>
				</tr>
				</table>
				<!-- /Inquiry -->

				<!-- Inquiry -->
				<table class="contactform" summary="Inquiry2">
				<tr>
					<th width="176">Nome Azienda</th>
					<td><?=$error_message['company']?>
					<input id="input2" name="company" type="text" value="<?=$company?>" size="50" /></td>
				</tr>
				<tr>
					<th>Proprio Nome</th>
					<td><?=$error_message['name']?>
					<input id="input4" name="name" type="text" value="<?=$name?>" size="30" /></td>
				</tr>
				<tr>
					<th>Paese</th>
					<td><?=$error_message['coun']?>
					<input id="input5" name="coun" type="text" value="" size="50" />
					</td>
				</tr>
				<tr>
					<th>numero di telefono</th>
					<td><?=$error_message['tel']?>
					<input id="input6" name="tel" type="text" value="<?=$tel?>" size="50" /></td>
				</tr>
				<tr>
					<th>E-mail</th>
					<td>	<?=$error_message['mail1']?>
						<input id="input14" name="mail1" type="text" value="<?=$mail1?>" size="40" /><br />
						Digitare nuovamente indirizzo e-mail per conferma.<br />
						<?=$error_message['mail2']?>
						<input id="input15" name="mail2" type="text" value="<?=$mail2?>" size="40" />
					</td>
				</tr>
				</table>
				<!--お問い合わせ-->

				<div class="submit">
					<input type="image" src="/italy/contact/entry/img/btn_confiem.gif" alt="Confermare" value="" />
					<input type="hidden" name="action" value="check" />
					<input type="hidden" name="first" value="1" />
				</div>

			</form>
			<p class="gototop"><a href="#top"><img src="/italy/common/img/txt_gototop.gif" width="75" height="10" alt="Inizio Pagina" /></a></p><!-- /gototop -->
<?php
//--入力フォーム確認表示-------------------------
} elseif ($action == 'check') {
    $comment_v = str_replace("\n", "<br />", $comment);
?>
			<div class="explanation">
				<img src="/italy/contact/entry/img/contact_form_img02.gif" alt="" />
			</div>

			<div class="explanation">Si prega di confermare le informazioni qui di seguito. Se è corretto, fare clic sul pulsante &quot;&quot; Submit &quot;&quot;.<br />
		    Se si desidera apportare modifiche alle informazioni qui di seguito, si prega di fare clic sul pulsante &quot;&quot; Change &quot;&quot; e tornare alla schermata di immissione.</div>

				<!-- Inquiry -->
				<table class="contactform" summary=" " width="100%">
				<tr>
					<th width="176">Domanda</th>
					<td><?=$comment_v?></td>
				</tr>
				</table>
					
				<table class="contactform" summary=" " width="100%">
				<tr>
					<th width="176">Nome Azienda</th>
					<td><?=$company?></td>
				</tr>
				<tr>
					<th>Proprio Nome</th>
					<td><?=$name?></td>
				</tr>

				<tr>
					<th>Paese</th>
					<td><?=$coun?></td>
				</tr>
                
                <tr>
					<th>numero di telefono</th>
					<td><?=$tel?></td>
				</tr>

				<tr>
					<th>E-mail</th>
					<td><?=$mail1?></td>
				</tr>
				</table>
				<!-- /Inquiry -->

				<div class="confirm">
					<div class="confirm_sub">
						<!-- <a href="javascript:history.back();"> -->
						<form method="post" action="./<?=$self_name?>" name="form2">
						<input type="image" src="/italy/contact/entry/img/btn_edit.gif" alt="edit" name="back"/>
						<input type="hidden" name="first" value="1" />
						<?=$hidden_html?>
						</form>
					</div>


					<div class="confirm_sub">
					<form method="post" action="./<?=$self_name?>" name="form1">
						<input type="image" src="/italy/contact/entry/img/btn_submit.gif" alt="submit" value="" />
						<?=$hidden_html?>
						<?=$hidden_html_upfile?>
						<input type="hidden" name="action" value="send" />
					</div>
				</div>

			</form>
			<p class="gototop"><a href="#top"><img src="/italy/common/img/txt_gototop.gif" width="75" height="10" alt="Inizio Pagina" /></a></p><!-- /gototop -->

<?php
//--入力フォーム送信完了表示---------------------
} elseif ($action == 'send') {

//機種依存文字変換
    $name = replaceText($name);

//--メールアドレス-------------------------------
    $send_mail = "fu-product@mail.futec.co.jp";
//    $send_mail = "miyauchi@gofield.com"; 
    $send_mail_from = mb_encode_mimeheader($name).' <'.$mail1.'>';
    $send_mail_cc = '';
    $send_mail_bcc = '';

//--タイトル-------------------------------------
    $subject = 'Per commenti e osservazioni su FUTEC scrivere nella sezione "Contattaci"';

//--ヘッダー-------------------------------------
    $header  = "From: $send_mail_from\n";
    $header .= "Cc: $send_mail_cc\n";
    $header .= "Bcc: $send_mail_bcc\n";

//--添付ファイル追加-----------------------------
    $boundary = md5(uniqid(rand())); //バウンダリー文字（パートの境界）
    $header  = "From: $send_mail_from\n";
    $header .= "Reply-To: $send_mail_from\n";
    $header .= "X-Mailer: PHP/".phpversion()."\n";
    $header .= "MIME-version: 1.0\n";
    if (file_exists($upfile_dir)) { //アップファイルがあれば
        $header .= "Content-Type: multipart/mixed;\n";
        $header .= "\tboundary=\"$boundary\"\n";
        $msg = "This is a multi-part message in MIME format.\n\n";
        $msg .= "--$boundary\n";
        $msg .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
        $msg .= "Content-Transfer-Encoding: 7bit\n\n";
    } else {
        $header .= "Content-Type: text/plain; charset=ISO-2022-JP\n";
        $header .= "Content-Transfer-Encoding: 7bit\n";
    }

    $comment_v = str_replace("<br />", "\n ", $comment);
    $body  = "Una domanda nella sezione Contattaci è stata ricevuta da un cliente.\n";
    $body .= "Apprezziamo la gestione di questa materia.\n\n";
    $body .= "-----------------------------------------\n";
    $body .= "■Informazione Contatti.\n\n";
    $body .= "【Domanda】:\n $comment_v\n";
    $body .= "【Nome Azienda】: ".$company."\n";
    $body .= "【Proprio Nome】: ".$name."\n";
    $body .= "【Paese】: ".$coun."\n";
	$body .= "【numero di telefono】: ".$tel."\n";
    $body .= "【E-mail】: ".$mail1."\n";

    //機種依存文字変換
    $body = replaceText($body);

    $msg .= $body;

    if (file_exists($upfile_dir)) {
        $fp = fopen($upfile_dir, "r") or die("error"); //ファイルの読み込み
        $contents = fread($fp, filesize($upfile_dir));
        fclose($fp);
        $f_encoded = chunk_split(base64_encode($contents)); //エンコードして分割
        $msg .= "\n\n--$boundary\n";
        $msg .= "Content-Type: " . $upfile_type . ";\n";
        $msg .= "\tname=\"$upfile_name\"\n";
        $msg .= "Content-Transfer-Encoding: base64\n";
        $msg .= "Content-Disposition: attachment;\n";
        $msg .= "\tfilename=\"$upfile_name\"\n\n";
        $msg .= "$f_encoded\n";
        $msg .= "--$boundary--";
    }

//--メール送信[管理者]---------------------------
    mb_language('Japanese');
    mb_internal_encoding('utf-8');
    $msg = mb_convert_encoding($msg, 'ISO-2022-JP');

    $subject = mb_encode_mimeheader($subject, 'ISO-2022-JP');
    mail($send_mail, $subject, $msg, $header);
#    mail($send_mail2, $subject, $msg, $header);
#    mail($send_mail3, $subject, $msg, $header);

//--アップファイル削除---------------------------
    unlink($upfile_dir);

//--csvファイルへの読み込み----------------------
    $file = $dir_data.'form_contact_en.csv';//ファイル

    $date = date("Y/m/d/H:i:s");

    $fp = fopen("$file", "r") or die('ファイルオープン失敗');
    if ($fp) {
        while (!feof($fp)) {
            $dat_tmp .= fgets($fp, 8192);
        }
    }
    fclose($fp);


//--csvファイルへの書き込み----------------------
    $form_data = "\"$date\",\"$comment\",\"$company\",\"$busho\",\"$name\",\"$country\",\"$zip\",\"$add1\",\"$add2\",\"$tel\",\"$fax\",\"$mail1\"\n";
    $form_data = mb_convert_encoding($form_data, 'shift-jis');

    $fp = fopen("$file", "w") or die('ファイルオープン失敗');
    if ($fp) {
        flock($fp, LOCK_EX);
        fwrite($fp, $form_data);
        fwrite($fp, $dat_tmp);
    }
    fclose($fp);

//--メール送信完了メッセージ---------------------
?>

			<div class="explanation">
				<img src="/italy/contact/entry/img/contact_form_img03.gif" alt="" />
			</div>
			<div class="comp_explanation">
				Grazie per avere inviato la Vostra richiesta.
		  </div>
		<p class="gototop"><a href="#top"><img src="/italy/common/img/txt_gototop.gif" width="75" height="10" alt="Inizio Pagina" /></a></p><!-- /gototop -->
<?php
}
?>
		</div><!-- /main -->

		<div class="side">
			<div class="localNavi">
				<ul>
					<li><a href="http://www.futec-global.com/italy/contact/index.html">Contatti</a></li>
					<li><a href="http://www.futec-global.com/italy/contact/list.html">Posizioni FUTEC</a></li>
					<li class="stay"><a href="https://www.futec.co.jp/italy/contact/entry/index.php">Modulo di Richiesta</a></li>
				</ul>
				<p class="catTop"><a href="http://www.futec-global.com/italy/index.html">Home</a></p>
			</div><!-- /localNavi -->
		</div><!-- /side -->
	</div><!-- /scontents -->
	
    <!-- ▼ footer_navi include ▼ -->
	<script type="text/javascript" >
        include("/inc/italy/footer_navi.html");
    </script>
    <!-- ▲ footer_navi include ▲ -->

</div>

<!-- ▼ footer include ▼ -->
<script type="text/javascript" >
	include("/inc/italy/footer.html");
</script>
<!-- ▲ footer include ▲ -->

<?php

$dir_name = "italy/contact/entry";

if($action=='') {
	if(!$error_flag) {
        	$virtual_page = $dir_name."/step1.html";
    	} else {
        	$virtual_page = $dir_name."/step1_error.html";
	}
} else if($action=='check') {
	$virtual_page = $dir_name."/step2.html";
} else {
	$virtual_page = $dir_name."/step3.html";
?>
<!-- Google Code for FAI Web Inquiry Tracking Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 978856229;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "tlwICJu8_goQpdLg0gM";
var google_conversion_value = 0;
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript"  
src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/978856229/?value=0&amp;label=tlwICJu8_goQpdLg0gM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

<!-- begin Pardot Website Tracking code -->
 
<script type="text/javascript">
piAId = '44792';
piCId = '1294';
 
(function() {
        function async_load(){
               var s = document.createElement('script'); s.type = 'text/javascript';
               s.src = ('https:' == document.location.protocol ? 'https://pi' : 'http://cdn') + '.pardot.com/pd.js';
               var c = document.getElementsByTagName('script')[0]; c.parentNode.insertBefore(s, c);
        }
        if(window.attachEvent) { window.attachEvent('onload', async_load); }
        else { window.addEventListener('load', async_load, false); }
})();
</script>
 
<!-- end Pardot Website Tracking code --> 

<?php
}
	include_once($dir.'analyticstracking.php');
?>

</body>
</html>
