'; $closeLabelDescRep = ''; $form["CHOOSE_ESTIMATE"] = 0; $form["ESTIMATE_TYPE_1"] = 1; $form["ESTIMATE_TYPE_2"] = 2; $action["CHECK_FORM"] = 0; $action["SEND_FORM"] = 0; $action["SHOW_FORM"] = 0; $action["SHOW_END_MSG"] = 0; $error = 0; if(isset($_POST["invia_form"])){ $action["CHECK_FORM"] = 1; } else { $action["SHOW_FORM"] = 1; } // Imposta lingua $lang = $defLang; if(isset($_GET["lang"])) $lang = $_GET["lang"]; if(isset($_POST["lang"])) $lang = $_POST["lang"]; $labels = &$fieldLabels[$lang]; // CONTROLLO INPUT if($action["CHECK_FORM"]){ if($_POST["tipo_preventivo"]==$form["ESTIMATE_TYPE_1"]){ $reqField = array(0,1,2,3,6,7,8,9,10); } if($_POST["tipo_preventivo"]==$form["ESTIMATE_TYPE_2"]){ $reqField = array(0,1,2,3); } foreach($reqField as $i){ $fldName = $formFieldsList[$_POST["tipo_preventivo"]][$i]; if(empty($_POST[$fldName])){ $error++; $errorMsg = htmlentities($errorMessage[$lang][0]); break; } } // Inserimento allegato if(!$error>0 && $_FILES["allegato_testo_traduzione"]["name"]!=""){ $mimeType = $_FILES["allegato_testo_traduzione"]["type"]; $tempName = $_FILES["allegato_testo_traduzione"]['tmp_name']; $fileName = $_FILES["allegato_testo_traduzione"]["name"]; $file = $uploadDir.$_FILES["allegato_testo_traduzione"]["name"]; // Controlla se il file abbia un mime type abilitato $typeValid = 0; foreach($allowedType as $type){ if($mimeType==$type){ $typeValid = 1; break; } } if(!$typeValid){ $error++; $errorMsg = htmlentities($errorMessage[$lang][1]); } } if(!$error>0) $action["SEND_FORM"] = 1; else $action["SHOW_FORM"] = 1; } // INVIO DATI FORM if($action["SEND_FORM"]){ $mailBody = ""; foreach ($formFieldsList[$_POST["tipo_preventivo"]] As $field){ if($field=="allegato_testo_traduzione" || $field=="MAX_FILE_SIZE") continue; if(ereg("(.+)(.+)",$labels[$field],$tokens)) $flabel = $tokens[1]; else $flabel = $labels[$field]; $mailBody .= str_replace("*","",$flabel).":\r\n"; $mailBody .= stripslashes($_POST[$field])."\r\n\r\n"; } $headers["Subject"] = $pageTitle[$lang][$_POST["tipo_preventivo"]]; $mime = new Mail_mime($nl); $mime->setTXTBody($mailBody); if(isset($file)){ if(!move_uploaded_file($tempName,$file)){ $error++; } if(!$error>0){ $encoding = ($mimeType=="text/richtext")?"quoted-printable":"base64"; $mime->addAttachment($file,$mimeType,$fileName,TRUE,$encoding); } } $body = $mime->get(); $hdrs = $mime->headers($headers); // Stabilisce connessione al server $mail =& Mail::factory('smtp',$smtpSettings); // Invia il messaggio $mail->send($mailTo, $hdrs, $body); $action["SHOW_END_MSG"] = 1; /*echo "
".$body."
"; $action["SHOW_END_MSG"] = 0;*/ } if($action["SHOW_END_MSG"]){ $tmpl = new patTemplate(); $tmpl->setBasedir( "templates" ); $tmpl->readTemplatesFromFile("endmsg.tmpl.htm"); if($error>0) $tmpl->addVar("end","MESSAGE",$errorMessage[$lang][2]); else $tmpl->addVar("end","MESSAGE",$successMessage[$lang]); $tmpl->setAttribute("leftmenu_".$lang,"visibility","visible"); $tmpl->displayParsedTemplate(); } // VISUALIZZAZIONE FORM if($action["SHOW_FORM"]){ // Inizializzazione template $tmpl = new patTemplate(); $tmpl->setBasedir( "templates" ); $tmpl->readTemplatesFromFile("form_preventivi.tmpl.shtml"); $tmpl->addGlobalVar("LANG_N","lang"); $tmpl->addGlobalVar("LANG_V",$lang); if(isset($_POST["tipo_preventivo"])){ $viewForm = $_POST["tipo_preventivo"]; $title = $pageTitle[$lang][$_POST["tipo_preventivo"]]; $tmpl->addVar("form","TIPO_PREVENTIVO_N","tipo_preventivo"); $tmpl->addVar("form","TIPO_PREVENTIVO_V",$viewForm); foreach ($buttonLabels[$lang] As $blk=>$blv) $tmpl->addVar("form",strtoupper($blk),$blv); } else { $viewForm = $form["CHOOSE_ESTIMATE"]; $pt = &$pageTitle[$lang]; $title = $pt[$form["CHOOSE_ESTIMATE"]]; if(count($pt)>1){ for($i=1;$iaddVar("form",("SUBFORM_".$i."_L"),$pt[$i]); } } //$includePath = INCLUDE_ROOT.$slashes.$lang.$slashes; // Creazione e assegnamento variabili template foreach ($formFieldsList[$viewForm] As $field){ $fieldVarName = strtoupper($field)."_N"; $labelVarName = strtoupper($field)."_L"; $tmpl->addVar("form",$fieldVarName,$field); if(isset($_POST[$field])){ $valueVarName = strtoupper($field)."_V"; $tmpl->addVar("form",$valueVarName,$_POST[$field]); } if(!isset($labels[$field])) $tmpl->addVar("form",$labelVarName,"--NO LABEL--"); else { $pattern = "(.+)(.+)"; if(ereg($pattern,$labels[$field],$tokens)) $tmpl->addVar("form",$labelVarName,(htmlentities($tokens[1]). $openLabelDescRep. htmlentities($tokens[2]). $closeLabelDescRep)); else $tmpl->addVar("form",$labelVarName,htmlentities($labels[$field])); } } if(isset($errorMsg)) $tmpl->addVar("error","ERROR_MSG",$errorMsg); $tmpl->addVar("form","FORM_TITLE",$title); // determina direzione in tag HTML $html_decl = ($lang=="ar")?"":""; $tmpl->addVar("form","HTML_DECL",$html_decl); $tmpl->addVar("form","FORM_ACTION",$_SERVER["PHP_SELF"]); $tmpl->setAttribute(("form".$viewForm),"visibility","visible"); $tmpl->setAttribute("leftmenu_".$lang,"visibility","visible"); $tmpl->displayParsedTemplate(); } ?>