'success' , 'message' => 'Attenzione, ci sono degli errori:
' , 'data' => null ); public $error_msg = array( 'titolo' => '
  • Devi specificare un titolo
  • ' ,'nome' => '
  • Devi specificare un nome
  • ' ,'cognome' => '
  • Devi specificare un cognome
  • ' ,'indirizzo' => '
  • Devi specificare un indirizzo
  • ' ,'n_civico' => '
  • Devi specificare un numero civico
  • ' ,'req_cap' => '
  • Devi specificare un CAP
  • ' ,'wrg_cap' => '
  • Devi specificare un CAP valido. Sono ammessi solo caratteri numerici
  • ' ,'citta' => '
  • Devi specificare una città
  • ' ,'provincia' => '
  • Devi specificare una provincia
  • ' ,'req_tel_cell' => '
  • Devi specificare un numero di telefono fisso o cellulare
  • ' ,'wrg_tel_cell' => '
  • Devi specificare un numero di telefono fisso o cellulare valido. Sono ammessi solo caratteri numerici
  • ' ,'wrg_fax' => '
  • Devi specificare un numero fax (opzionale) valido. Sono ammessi solo caratteri numerici
  • ' ,'req_email' => '
  • Devi specificare un indirizzo email
  • ' ,'wrg_email' => '
  • Devi specificare un indirizzo email valido del tipo tuonome@tuogestore.ext
  • ' ,'biglietto' => '
  • Scegli il biglietto che vuoi ricevere
  • ' ,'filmato' => '
  • Scegli il filmato che vuoi ricevere
  • ' ,'accetto_normativa' => '
  • Devi accettare la normativa sulla privacy
  • ' ); /* -------------------------------------------------------------------------- * Costruttore * @access public * @return void */ public function __construct() { date_default_timezone_set('Europe/Amsterdam'); if(! $this->is_ajax_request()){ $this->get_content(); } else { $this->main(); } } /* -------------------------------------------------------------------------- * Elabora un file di template e lo mostra a video * @access public */ public function get_content() { $template = file_get_contents('form_contatti.html'); ob_start(); eval("?>$template"); echo ob_get_clean(); } /* -------------------------------------------------------------------------- * Stampa un array formattato con
    		 * @access public
    		*/
    		public function pr($array) {
    			echo '
    ';
    			print_r($array);
    			echo '
    '; } /* -------------------------------------------------------------------------- * Restituisce una data nel formato specificato negli argomenti * @access public * @return date */ public function datetime($format = 'd-m-Y H:i:s', $hour = 1) { return date($format, mktime(date('H')+ intval($hour), date('i'), date('s'), date('m'), date('d'), date('Y'))); } /* -------------------------------------------------------------------------- * Controlla la chiamata * @access public * @return void */ public function is_ajax_request (){ return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); //return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); } /* -------------------------------------------------------------------------- * Stampa un array json * @access public * @return void */ public function output_json($status, $message, $data) { $json = array( 'status' => $status , 'message' => $message , 'data' => $data ); // header('Cache-Control: no-cache, must-revalidate'); // header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // header('Content-type: application/json'); echo json_encode($json); } /* -------------------------------------------------------------------------- * Validazione del form * @access public * @param $var string * @return void */ public function validate_form($post) { if(empty($post['titolo'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['titolo']; } if(empty($post['nome'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['nome']; } if(empty($post['cognome'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['cognome']; } if(empty($post['indirizzo'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['indirizzo']; } if(empty($post['n_civico'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['n_civico']; } if(!empty($post['cap'])) { if(!is_numeric($post['cap'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['wrg_cap']; } } else{ $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['req_cap']; } if(empty($post['citta'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['citta']; } if(empty($post['provincia'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['provincia']; } if(!empty($post['tel_cell'])) { if(!is_numeric($post['tel_cell'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['wrg_tel_cell']; } } else{ $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['req_tel_cell']; } if(!empty($post['fax']) && !is_numeric($post['fax'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['wrg_fax']; } if(!empty($post['email'])) { if(!filter_var($post['email'], FILTER_VALIDATE_EMAIL)) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['wrg_email']; } } else{ $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['req_email']; } if(@$post['desidero_biglietto'] == 'Sì') { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['biglietto']; } if(@$post['desidero_filmato'] == 'Sì') { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['filmato']; } if(!isset($post['accetto_normativa'])) { $this->json['status'] = 'failure'; $this->json['message'] .= '
    '.$this->error_msg['accetto_normativa']; } if($this->json['status'] == 'success') return true; else return false; } // -------------------------------------------------------------------------- /* * Salva il form inviato nel file csv * @access public * @return date */ public function save($post) { $file = '../admin/form_contatti.csv'; if(!file_exists($file)) { $fp = fopen($file, 'x+'); fwrite($fp,pack("CCC",0xef,0xbb,0xbf)); $intestazione = array( 'Titolo' ,'Società' ,'Nome' ,'Cognome' ,'Indirizzo' ,'Numero civico' ,'CAP' ,'Città' ,'Provincia' ,'Stato' ,'Tel/Cell' ,'Email' ,'Fax' ,'Desidero ricevere le password per i software IS MENSOLA e PUNZONAMENTO' ,'Desidero ricevere il DVD DEMO e le schede tecniche' ,'Desidero ricevere BIGLIETTO GRATUITO per la fiera di' ,'Desidero ricevere il FILMATO completo del seminario di' ,'Desidero prenotare una DEMO ON LINE' ,'Desidero partecipare a un futuro seminario' ,'Note' ,'Data e ora di registrazione' ); fputcsv($fp, $intestazione, ';', '"'); fwrite($fp, "\r\n\r\n"); } else { $fp = fopen($file, 'a+'); } $user = array(); $user['titolo'] = $post['titolo']; if(empty($post['societa'])) $user['societa'] = 'Non specificato'; else $user['societa'] = $post['societa']; $user['nome'] = $post['nome']; $user['cognome'] = $post['cognome']; $user['indirizzo'] = $post['indirizzo']; $user['n_civico'] = $post['n_civico']; $user['cap'] = $post['cap']; $user['citta'] = $post['citta']; $user['provincia'] = $post['provincia']; if(empty($post['stato'])) $user['stato'] = 'Non specificato'; else $user['stato'] = $post['stato']; $user['tel_cell'] = $post['tel_cell']; $user['email'] = $post['email']; if(empty($post['fax'])) $user['fax'] = 'Non specificato'; else $user['fax'] = $post['fax']; if(!(isset($post['desidero_password']))) $user['desidero_password'] = 'No'; else $user['desidero_password'] = 'Sì'; if(!(isset($post['desidero_dvd']))) $user['desidero_dvd'] = 'No'; else $user['desidero_dvd'] = 'Sì'; if(!(isset($post['desidero_biglietto']))) $user['desidero_biglietto'] = 'No'; else $user['desidero_biglietto'] = $post['desidero_biglietto']; if(!(isset($post['desidero_filmato']))) $user['desidero_filmato'] = 'No'; else $user['desidero_filmato'] = $post['desidero_filmato']; if(!(isset($post['desidero_demo']))) $user['desidero_demo'] = 'No'; else $user['desidero_demo'] = 'Sì'; if(!(isset($post['desidero_futuro_seminario']))) $user['desidero_futuro_seminario'] = 'No'; else $user['desidero_futuro_seminario'] = 'Sì'; if(!(isset($post['notes']))) $user['notes'] = 'Non specificate'; else $user['notes'] = $post['notes']; $user['data'] = $this->datetime(); $user_csv = $user; $user_csv['fax'] != 'Non specificato' && $user_csv['fax'] = '="'. $user_csv['fax'] .'"'; $user_csv['tel_cell'] = '="'. $user_csv['tel_cell'] .'"'; $user_csv['cap'] = '="'. $user_csv['cap'] .'"'; fputcsv($fp, $user_csv, ';', '"'); fclose($fp); return $user; } // -------------------------------------------------------------------------- /* * Invia una mail all'amministratore e all'utente con la mail appena registrata * @access public * @return date */ public function send_email($user) { $link_logo = 'http://www.cdmdolmen.it/richiesta-informazioni/mail_assets/img/email_footer_logo.jpg'; $link_icon_fb = 'http://www.cdmdolmen.it/richiesta-informazioni/mail_assets/img/facebook_icon.gif'; $company = '

    --
    '. '

    CDM DOLMEN E OMNIA IS srl

    '. 'Via Drovetti 9/F – 10138 Torino
    '. 'Tel. 011.4470755 – Fax 011.4348458
    '. 'dolmen@cdmdolmen.it
    '. 'www.cdmdolmen.it
    '. '
    '. '
    '. 'Segui CDM DOLMEN cliccando “Mi piace” su Facebook!'; //Invio della mail all'utente $message = array( 'dest' => $user['email'] ,'subject' => 'Risposta automatica da CDM DOLMEN' ,'body' => 'Gentile Professionista,
    '. 'La sua richiesta è stata inoltrata a CDM DOLMEN.
    '. 'A breve riceverà i dettagli tramite e-mail o sarà contattato.
    '. 'La ringraziamo per l’attenzione, cordiali saluti.
    '. $company ,'headers' => 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=utf-8' . "\r\n" . 'From: '. "\r\n" .'Reply-To: dolmen@cdmdolmen.it' . "\r\n" ); if(mail($message['dest'], $message['subject'], $message['body'], $message['headers'])){ $this->json['status'] = 'success'; $this->json['message'] = 'Hai correttamente inviato il form, a breve riceverai una mail di conferma. Grazie per la collaborazione.'; } else $this->json['message'] = 'C\'è un errore nell\'invio del form, per favore, contattaci'; //Invio della mail all'admin $message = array( 'dest' => "dolmen@cdmdolmen.it" ,'subject' => 'Nuova registrazione al form contatti' ,'body' => 'Il giorno '. $user['data'] . ' è stata effettuata una nuova registrazione al form contatti con i seguenti dati:

    ' . 'Titolo: '. $user['titolo']. '
    '. 'Società: '. $user['societa']. '

    '. 'Nome: '. $user['nome']. '
    '. 'Cognome: '. $user['cognome']. '
    '. 'Indirizzo: '. $user['indirizzo']. ', '.$user['n_civico']. '
    '. 'CAP: '. $user['cap']. '
    '. 'Città: '. $user['citta']. '
    '. 'Provincia: '. $user['provincia']. '
    '. 'Stato: '. $user['stato']. '
    '. 'Tel/Cell: '. $user['tel_cell']. '
    '. 'Email: '. $user['email']. '
    '. 'Fax: '. $user['fax']. '

    '. 'Desidero ricevere le password per i software IS MENSOLA e PUNZONAMENTO: '. $user['desidero_password']. '
    '. 'Desidero ricevere il DVD DEMO e le schede tecniche: '. $user['desidero_dvd']. '
    '. 'Desidero ricevere BIGLIETTO GRATUITO per la fiera di: '. $user['desidero_biglietto']. '
    '. 'Desidero ricevere il FILMATO completo del seminario di: '. $user['desidero_filmato']. '
    '. 'Desidero prenotare una DEMO ON LINE: '. $user['desidero_demo']. '
    '. 'Desidero partecipare a un futuro seminario: '. $user['desidero_futuro_seminario']. '

    '. 'Note: '. $user['notes'] ,'headers' => 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=utf-8' . "\r\n" . 'From: <' . $user['email'] . '>'. "\r\n" . 'Reply-To: '. $user['email'] . "\r\n" ); if(mail($message['dest'], $message['subject'], $message['body'], $message['headers'])){ $this->json['status'] = 'success'; $this->json['message'] = 'Hai correttamente inviato il form, a breve riceverai una mail di conferma. Grazie per la collaborazione.'; } else $this->json['message'] = 'C\'è un errore nell\'invio del form, per favore, contattaci'; } // -------------------------------------------------------------------------- /* * Valida, salva in archivio ed invia una mail di avvenuta registrazione all'amministratore ed all'utente * @access public * @return date */ public function main() { if($this->validate_form($_POST)) { $user = $this->save($_POST); $this->send_email($user); } $this->output_json($this->json['status'], $this->json['message'], $this->json['data']); } } new Form;