<?PHP
/*
Simfatic Forms Main Form processor script

This script does all the server side processing. 
(Displaying the form, processing form submissions,
displaying errors, making CAPTCHA image, and so on.) 

All pages (including the form page) are displayed using 
templates in the 'templ' sub folder. 

The overall structure is that of a list of modules. Depending on the 
arguments (POST/GET) passed to the script, the modules process in sequence. 

Please note that just appending  a header and footer to this script won't work.
To embed the form, use the 'Copy & Paste' code in the 'Take the Code' page. 
To extend the functionality, see 'Extension Modules' in the help.

*/

@ini_set("display_errors", 1);//the error handler is added later in FormProc
error_reporting(E_ALL & ~((defined('E_STRICT')?E_STRICT:0)|E_NOTICE));

require_once(dirname(__FILE__)."/include/donor-lib.php");
$formproc_obj =  new SFM_FormProcessor('donor');
$formproc_obj->initTimeZone('Asia/Kolkata');
$formproc_obj->setFormID('0cc5d151-d826-41ad-9803-7575d5cc56f3');
$formproc_obj->setFormKey('5a257581-4d11-461a-bd26-f42f2a01ab17');
$formproc_obj->setLocale('en-IN','dd-MM-yyyy');
$formproc_obj->setEmailFormatHTML(true);
$formproc_obj->EnableLogging(false);
$formproc_obj->SetDebugMode(false);
$formproc_obj->setIsInstalled(true);
$formproc_obj->EnableLoadFormValuesFromURL(true);
$formproc_obj->SetPrintPreviewPage(sfm_readfile(dirname(__FILE__)."/templ/donor_print_preview_file.txt"));
$formproc_obj->SetSingleBoxErrorDisplay(true);
$formproc_obj->setFormPage(0,sfm_readfile(dirname(__FILE__)."/templ/donor_form_page_0.txt"));
$formproc_obj->AddElementInfo('username','text','');
$formproc_obj->AddElementInfo('fname','text','');
$formproc_obj->AddElementInfo('reipassword','text','');
$formproc_obj->AddElementInfo('ipassword','text','');
$formproc_obj->AddElementInfo('Gender','radio_group','');
$formproc_obj->AddElementInfo('ydob','listbox','');
$formproc_obj->AddElementInfo('bloodgroup','listbox','');
$formproc_obj->AddElementInfo('weight','decimal','');
$formproc_obj->AddElementInfo('mobile','text','');
$formproc_obj->AddElementInfo('dayphone','text','');
$formproc_obj->AddElementInfo('email','text','');
$formproc_obj->AddElementInfo('state','listbox','');
$formproc_obj->AddElementInfo('city','listbox','');
$formproc_obj->AddElementInfo('how_often','listbox','');
$formproc_obj->AddElementInfo('age_more_than_18','single_chk','');
$formproc_obj->AddElementInfo('terms','single_chk','');
$formproc_obj->AddDefaultValue('ydob','Select');
$formproc_obj->AddDefaultValue('bloodgroup','Select');
$formproc_obj->AddDefaultValue('weight','0');
$formproc_obj->AddDefaultValue('state','Select');
$formproc_obj->AddDefaultValue('city','Select');
$formproc_obj->setFormDBLogin('localhost','sauranbe_donator','BC185214DBA2E1693F6124D974DA6CFB','sauranbe_biharbloodbank');
$formproc_obj->SetHiddenInputTrapVarName('td1f04d95bb36f6912b9e');
$formproc_obj->SetFromAddress('Email biharbloodbank.in<info@biharbloodbank.in>');
$sfm_captcha =  new FM_CaptchaCreator('Captcha');
$sfm_captcha->SetSize(150,60);
$sfm_captcha->SetCharset('2356789ABCDEFGHJKLMNPQRSTUVWXYZ');
$sfm_captcha->SetCaseInsensitiveMatch(true);
$sfm_captcha->SetNChars(6);
$sfm_captcha->SetNLines(4);
$sfm_captcha->SetFontFile('images/SFOldRepublicBold.ttf');
$sfm_captcha->SetErrorStrings('Please input the code displayed in the image','The code does not match. Please try again.');
$formproc_obj->addModule($sfm_captcha);

$page_renderer =  new FM_FormPageDisplayModule();
$formproc_obj->addModule($page_renderer);

$admin_page =  new FM_AdminPageHandler();
$admin_page->SetPageTemplate(sfm_readfile(dirname(__FILE__)."/templ/donor_admin_page_templ.txt"));
$admin_page->SetLogin('sauravkr','BC185214DBA2E1693F6124D974DA6CFB');
$admin_page->SetLoginTemplate(sfm_readfile(dirname(__FILE__)."/templ/donor_admin_page_login.txt"));
$formproc_obj->addModule($admin_page);

$validator =  new FM_FormValidator();
$validator->addValidation("username","required","Please fill in username");
$validator->addValidation("username","alnum","The input for username should be a valid alpha-numeric value");
$validator->addValidation("fname","required","Please fill in Name");
$validator->addValidation("fname","alpha_s","The input for Name should be a valid alphabetic value");
$validator->addValidation("reipassword","required","Please fill in ConfirmPassword");
$validator->addValidation("reipassword","alnum","The input for ConfirmPassword should be a valid alpha-numeric value");
$validator->addValidation("reipassword","eqelmnt=ipassword","Confirm Password should be equal to Password");
$validator->addValidation("ipassword","required","Please fill in Password");
$validator->addValidation("ipassword","alnum","The input for Password should be a valid alpha-numeric value");
$validator->addValidation("Gender","selone","Please select gender");
$validator->addValidation("ydob","dontselect=Select","Please select an option for ydob");
$validator->addValidation("bloodgroup","dontselect=Select","Please select an option for bloodgroup");
$validator->addValidation("weight","numeric","The input for  should be a valid numeric value");
$validator->addValidation("weight","required","Please fill in Weight");
$validator->addValidation("weight","greaterthan=50.00","The value of Weight should be greater than 50.00");
$validator->addValidation("mobile","required","Please fill in mobile");
$validator->addValidation("mobile","numeric","The input for mobile should be a valid numeric value");
$validator->addValidation("mobile","minlen=10","The length of the input for mobile should be at least 10.");
$validator->addValidation("mobile","maxlen=13","The length of the input for mobile should not exceed 13");
$validator->addValidation("dayphone","required","Please fill in dayphone");
$validator->addValidation("dayphone","numeric","The input for dayphone should be a valid numeric value");
$validator->addValidation("dayphone","maxlen=13","The length of the input for dayphone should not exceed 13");
$validator->addValidation("dayphone","minlen=10","The length of the input for dayphone should be at least 10.");
$validator->addValidation("email","email","The input for Email should be a valid email value");
$validator->addValidation("email","required","Please fill in email");
$validator->addValidation("state","dontselect=Select","Please select an option for state");
$validator->addValidation("city","dontselect=Select","Please select an option for city");
$validator->addValidation("age_more_than_18","selmin=1","Can't proceed if your age is less than 18");
$validator->addValidation("terms","selmin=1","Can't proceed as you do not agree to the terms & conditions");
$formproc_obj->addModule($validator);

$confirmpage =  new FM_ConfirmPage(sfm_readfile(dirname(__FILE__)."/templ/donor_confirm_page.txt"));
$confirmpage->SetButtonCode(sfm_readfile(dirname(__FILE__)."/templ/donor_confirm_button_code.txt"),sfm_readfile(dirname(__FILE__)."/templ/donor_edit_button_code.txt"),sfm_readfile(dirname(__FILE__)."/templ/donor_print_button_code.txt"));
$confirmpage->SetExtraCode(sfm_readfile(dirname(__FILE__)."/templ/donor_confirm_ie6_png_fix.txt"));
$formproc_obj->addModule($confirmpage);

$data_email_sender =  new FM_FormDataSender(sfm_readfile(dirname(__FILE__)."/templ/donor_email_subj.txt"),sfm_readfile(dirname(__FILE__)."/templ/donor_email_body.txt"),'%email%');
$data_email_sender->AddToAddr('Saurav Kumar<sauravkumar120@gmail.com>');
$data_email_sender->AddToAddr('Suraj<suraj277922@gmail.com>');
$data_email_sender->AddToAddr('Email biharbloodbank.in<info@biharbloodbank.in>');
$formproc_obj->addModule($data_email_sender);

$autoresp =  new FM_AutoResponseSender(sfm_readfile(dirname(__FILE__)."/templ/donor_resp_subj.txt"),sfm_readfile(dirname(__FILE__)."/templ/donor_resp_body.txt"));
$autoresp->SetToVariables('fname','email');
$formproc_obj->addModule($autoresp);

$s_db_handler =  new FM_SimpleDB('donor');
$s_db_handler->AddField('_sfm_form_submision_time_','VARCHAR(50)','FormSubmissionTime');
$s_db_handler->AddField('_sfm_visitor_ip_','VARCHAR(50)','VisitorsIP');
$s_db_handler->AddField('_sfm_unique_id_','VARCHAR(35)','UniqueID');
$s_db_handler->AddField('username','VARCHAR(50)');
$s_db_handler->AddField('fname','VARCHAR(50)');
$s_db_handler->AddField('reipassword','VARCHAR(50)');
$s_db_handler->AddField('ipassword','VARCHAR(50)');
$s_db_handler->AddField('Gender','VARCHAR(50)');
$s_db_handler->AddField('ydob','VARCHAR(50)');
$s_db_handler->AddField('bloodgroup','VARCHAR(50)');
$s_db_handler->AddField('weight','DOUBLE');
$s_db_handler->AddField('mobile','VARCHAR(13)');
$s_db_handler->AddField('dayphone','VARCHAR(13)');
$s_db_handler->AddField('email','VARCHAR(50)');
$s_db_handler->AddField('state','VARCHAR(50)');
$s_db_handler->AddField('city','VARCHAR(50)');
$s_db_handler->AddField('how_often','VARCHAR(50)');
$s_db_handler->AddField('age_more_than_18','VARCHAR(50)');
$s_db_handler->AddField('terms','VARCHAR(50)');
$formproc_obj->addModule($s_db_handler);

$tupage =  new FM_ThankYouPage(sfm_readfile(dirname(__FILE__)."/templ/donor_thank_u.txt"));
$formproc_obj->addModule($tupage);

$uniqueid_s =  new FM_ShortUniqueID('donor');
$formproc_obj->AddExtensionModule($uniqueid_s);
$sfm_captcha->SetValidator($validator);
$sfm_captcha->SetConfirmPage($confirmpage);
$page_renderer->SetFormValidator($validator);
$formproc_obj->ProcessForm();

?>