<?php
require_once("include/config.php");
require_once("include/startup.php");             
// require_once("include/email/sendEmail.php");
// require_once("include/classes/sendMail.class.php");             


$AllTables = new AllTables();
$exhibitor = new exhibitor();
$Validation = new Validation();
$allform = new allform();

              
$id = session_id();

$verif_box = $_REQUEST["verif_box"];  
     
if (md5($verif_box) . 'a4xn' == $_COOKIE['tntcon']) 
{
    if ($_POST['txt_form_field1'] == '' && $_POST['txt_form_field2'] == $id && $_POST['txt_iagree'] == 'on')
    {

        $utm_source                                         = sanitize($_POST['txt_utm_source'], SQL + HTML);
        $utm_medium                                         = sanitize($_POST['txt_utm_medium'], SQL + HTML);
        $space                                                 = sanitize($_POST['txt_require'], SQL + HTML);
        $stall_area                                         = sanitize($_POST['txt_stall_area'], SQL + HTML);
        $sponsorship_opportunity                         = sanitize($_POST['txt_sponsorship_opportunity'], SQL + HTML);
        $fname                                                 = sanitize($_POST['txt_firstname'], SQL + HTML);
        $lname                                                 = sanitize($_POST['txt_lastname'], SQL + HTML);
        $company                                             = sanitize($_POST['txt_company'], SQL + HTML);
        $designation                                         = sanitize($_POST['txt_designation'], SQL + HTML);
        $email                                                 = sanitize($_POST['txt_email'], SQL + HTML);
        $phone                                                 = sanitize($_POST['txt_phone'], SQL + HTML);
        $mobile                                                 = sanitize($_POST['txt_mobile'], SQL + HTML);
        $fromname                                        = sanitize($_POST['txt_fromname'], SQL + HTML);
        $fromemail                                        = sanitize($_POST['txt_fromemail'], SQL);
        $recipientname                                  = sanitize($_POST['txt_recipientname'], SQL + HTML);
        $recipientemail                                  = sanitize($_POST['txt_recipientemail'], SQL);
        $subject                                             = sanitize($_POST['txt_subject'], SQL + HTML);
        //$form 												= sanitize($_POST['txt_form'], SQL+HTML);
        $redirectpagename                                    = sanitize($_POST['txt_redirect'], SQL + HTML);
        $formname                                            = sanitize($_POST['txt_formname'], SQL + HTML);
        $domainname                                         = sanitize($_POST['txt_domainname'], SQL + HTML);
        $formtype                                      = intval($_POST['txt_formtype']);

        $country                                             = sanitize($_POST['txt_country'], SQL + HTML);
        //$countryexpolde = explode('-',$country);
        //$countryname = $countryexpolde[1];
        // $industrybelong 							= sanitize($_POST['txt_industrybelong'], SQL+HTML);
        // $industryvisit 								= sanitize($_POST['txt_industryvisit'], SQL+HTML);

        $Invalid = "";
        // $Invalid .= $Validation->check_blank("txt_require", $space,"Require Space");
        // $Invalid .= $Validation->check_blank("txt_stall_area", $stall_area,"Stall Area");
        // $Invalid .= $Validation->check_blank("txt_sponsorship_opportunity", $sponsorship_opportunity,"Sponsorship Opportunity");
        $Invalid .= $Validation->check_blank("txt_firstname", $fname, "First Name");
        $Invalid .= $Validation->check_blank("txt_lastname", $lname, "Last Name");
        $Invalid .= $Validation->check_blank("txt_company", $company, "Company");
        // $Invalid .= $Validation->check_blank("txt_designation", $designation,"Designation");
        // $Invalid .= $Validation->check_blank("txt_email", $email,"Email");
        // $Invalid .= $Validation->check_blank("txt_phone", $phone,"Phone");
        // $Invalid .= $Validation->check_blank("txt_mobile", $mobile,"Mobile");


        if($Invalid) 
        {
            $msg = "Please fill the required field";
        } 
        else 
        {
            $exhibitorarray['exhibitiondetailid']                      = EXHIBITION_DETAILSID;
            $exhibitorarray['trak_form']                          = $utm_source;
            $exhibitorarray['trak_form_source']                  = $utm_medium;
            $exhibitorarray['space']                                          = $space;
            $exhibitorarray['stall_area']                                  = $stall_area;
            $exhibitorarray['sponsorship_oportunity']                 = $sponsorship_opportunity;
            $exhibitorarray['fname']                                          = $fname;
            $exhibitorarray['lname']                                          = $lname;
            $exhibitorarray['company_name']                                  = $company;
            $exhibitorarray['designation']                                  = $designation;
            $exhibitorarray['email']                                          = $email;
            $exhibitorarray['telno']                                          = $phone;
            $exhibitorarray['mobile']                                          = $mobile;
            $exhibitorarray['fromname']                                     = $fromname;
            $exhibitorarray['fromemail']                                     = $fromemail;
            $exhibitorarray['recipientname']                             = $recipientname;
            $exhibitorarray['recipientemail']                             = $recipientemail;
            $exhibitorarray['subject']                                     = $subject;
            $exhibitorarray['redirectpagename']                         = $redirectpagename;
            $exhibitorarray['formname']                                 = $formname;
            $exhibitorarray['domainname']                               = $domainname;
            $exhibitorarray['formtype']                                 = $formtype;
            $exhibitorarray['entry_date']                                    = date("Y-m-d h:i:s");
            $currentyear = date("Y");
            $exhibitorarray['exhibitionyear']                                    = $currentyear;
            $exhibitorarray['country']                                     = $country;
            $exhibitorarray['exhibitionyear']                             = date("Y");

            //$exhibitorarray['industrybelong']         						= $industrybelong;                      
            //$exhibitorarray['industryvisit']         						= $industryvisit;

            //print_r($exhibitorarray);  

            // $addexhibitor= $AllTables->AddInfo($exhibitorarray,'mstcontacts');     

            $addkoelnmesse = $allform->addallform($exhibitorarray);       // Added to koelnmesse-india.com          
            $addiile = $AllTables->AddInfo($exhibitorarray, 'allsitesforminfo');  // Added to iile database

            if ($addkoelnmesse)// && $addiile == 'true')
            {
                $from_name = $fromname;
                $from_email = $fromemail;
                $admin_to_name = $recipientname;
                $admin_to_email = $recipientemail;   
                $user_to_name = $fname;
                $user_to_email = $email;

                $user_subject = "Exhibitor Registration Confirmation - Orgatec India";
                $subject = $subject;
                $text_message = '';
                //$html_message = "A NEW REGISTRATION HAS BEEN RECEIVED FROM : $fname $lname OF Company : $company  ";
                foreach ($_POST as $key => $value) {

                    if (($key != "btn_submit") && ($key != "txt_form") && ($key != "txt_fromname") && ($key != "txt_fromemail") && ($key != "txt_recipientemail") && ($key != "txt_recipientname") && ($key != "txt_subject") && ($key != "txt_redirect") && ($key != "txt_Formtype") && ($key != "txt_Utm_source") && ($key != "txt_Utm_medium") && ($key != "txt_Domainname") && ($key != "txt_Form_field1") && ($key != "txt_Attachment1") && ($key != "txt_Iagree")) // everything except record ID,title,submit 
                    {
                        #Replce prefix of input field name
                        $key_replace = str_replace(array('txt_', 'cmb_', 'sel_'), '', $key);

                        #keep first letter is capital of key
                        $keyval = ucfirst($key_replace);

                        #Email content
                        $emailMsg .= "$keyval : $value <BR>";
                    }
                }
                $admin_html_message .= $emailMsg;
                $attachment = '';

                $user_html_message = "Dear $fname,<br><br>

                                Thank you for registering as an exhibitor for Orgatec India , taking place on 4-6 November  2025 at Jio World Convention Center , Mumbai. We’re excited to have you showcase your products/services at our event.
                                <br>
                                Our team will get back to you soon. We look forward to your participation and to making this event a success together.
                                <br><br>
                                Best Regards,<br>
                               Orgatec India<br>Revolutionizing The Future Of Workplaces";
                               
                $usersendmail = sendPHPMail($from_name, $from_email, $user_to_name, $user_to_email, $user_subject, $text_message, $user_html_message, $attachment);

                if ($usersendmail == '1') 
                {
                    $adminsendmail = sendPHPMail($from_name, $from_email, $admin_to_name, $admin_to_email, $subject, $text_message, $admin_html_message, $attachment);
                    $msg = '1';    
                } 
                else 
                {
                    // If email is not send to member that means the emailid is invalid or inappropriate to send email
                    $msg = 'Mail has not send to user';
                }
            } 
            else 
            {
                if ($addkoelnmesse) 
                {
                    $msg = "Not save main data";
                } 
                else 
                {
                    $msg =  "Not save data";
                }
            }  
        }
    }
    else
    {
        $msg = 'Fields are missing';       
    }
}
else 
{
    $msg = 'Invalid Captcha';
}

echo $msg;
exit;