class mContactform extends ModulePage
{
protected $Settings;
protected $Form;
protected $CurrentLanguageId;
protected $FieldTexts;
protected $GoogleCaptchaEnabled = false;
protected $GoogleCaptchaSitekey = '';
public function __construct()
{
// call parent
parent::__construct();
$action = $this->Module->ClassAction;
if (method_exists($this,$action))
$this->{$action}();
}
private function httpPost($url, $data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
public function Run()
{
// init vars
$FieldTexts = array();
// get form id
$form_id = 0;
if ($this->Module->Parameters->exists('form_id'))
$form_id = $this->Module->Parameters->get('form_id');
if ($form_id == 0)
return;
// load form
//$result = mysql_query('SELECT * FROM mod_contactform_form WHERE id = '. $form_id);
$result = $this->Database->doQuery('SELECT * FROM mod_contactform_form WHERE id = '. $form_id);
if ($result->num_rows == 0)
return;
$this->Form = $result->fetch_object(); //mysql_fetch_object($result);
// get language from session
$session = Session::getInstance();
$this->CurrentLanguageId = $session->getSectionValue('user','language');
// get all text for the current language
$result = $this->Database->doQuery('SELECT contactform_field,text FROM mod_contactform_language WHERE contactform_form_id = ' . $this->Form->id . ' AND language_id = ' . $this->CurrentLanguageId);
while($row = $result->fetch_object())
$this->FieldTexts[$row->contactform_field] = $row->text;
if (empty($action))
$action = "Main";
// redirect after post
if (isset($_SESSION['mContactForm']))
{
$this->Main_Success();
return;
}
// handle postback
if (isset($_POST['mContactformSend']))
$action = $action . '_PostBack';
// default action : Main (display form)
if (method_exists($this,$action))
$this->$action();
}
protected function renderField($fieldname,$mandatory,$type,$value)
{
$htmlString = "";
$mandatorySign = $mandatory==1||$mandatory==true?'*':'';
$htmlString .= '';
switch ($type)
{
case 'input': case 'number': $htmlString .= '
';
break;
case 'email': $htmlString .= '
';
break;
case 'textarea': $htmlString .= '
';
break;
case 'select': $htmlString .= '
';
break;
case 'check':
$htmlString .= ' FieldTexts[$fieldName]))
return $this->FieldTexts[$fieldName];
$result = mysql_query('SELECT text FROM mod_contactform_language WHERE mod_contactform_form_id = ' . $this->Form->id . ' AND contactform_field')
$fieldLanguage = new dbModContactformLanguage();
$fieldLanguage->ContactformFormId = $this->Settings->Id;
$fieldLanguage->ContactformField = strtolower($fieldName);
$fieldLanguage->LanguageId = $this->CurrentLanguageId;
if ($fieldLanguage->exists())
{
$this->FieldTexts[$fieldName] = $fieldLanguage->Text;
return $fieldLanguage->Text;
}
else
{
$this->FieldTexts[$fieldName] = $fieldName;
return $fieldName;
}
}*/
public function Main()
{
echo '
';
$invalid_message = $this->FieldTexts['invalid_message'];
if (strlen($invalid_message) == 0)
$invalid_message = 'De volgende verplichte velden zijn niet correct ingevuld:';
//$invalid_message = 'The following required fields are not correct:';
$invalid_message = str_replace("\n",'\n\\',$invalid_message);
echo '
';
}
protected function getPostedValue($fieldNumber)
{
$fieldType = 'field'.$fieldNumber.'_type';
$field = 'field'.$fieldNumber;
if ($this->Form->$fieldType == 'check')
{
if (isset($_POST[$field]))
{
return "X (ja / yes)";
}
else
{
return "";
}
}
else if (isset($_POST[$field]))
{
return $this->Database->escape(htmlspecialchars(utf8_decode(trim($_POST[$field]))));
//return mysql_escape_string(htmlspecialchars(trim(str_replace("\r","",$_POST[$field]))));
}
return "";
}
public function Main_PostBack()
{
if ($this->GoogleCaptchaEnabled)
{
if (isset($_POST['g-recaptcha-response']))
{
$result = $this->httpPost('https://www.google.com/recaptcha/api/siteverify', array('secret' => '6LdPG5MUAAAAAFPmVeyR4B2pYAKyL7xj86mGPFGT', 'response' => $_POST['g-recaptcha-response']));
if (empty($result))
$myError = $invalidCaptcha;
$resultObj = json_decode($result);
if (!$resultObj->success)
{
//$myError = $invalidCaptcha;
echo '
De controle of u geen robot bent is mislukt. Mogelijk is er iets misgegaan. Probeert u het a.u.b. opnieuw