<?php
session_start();
include 'config.php';
?>
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="Potenza - Job Application Form Wizard with Resume upload and Branch feature">
        <meta name="author" content="Ansonika">
        <title>AVIT - Admissions 2023</title>
        <link href="https://www.avit.ac.in/img/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <!-- GOOGLE WEB FONT -->
        <link href="https://fonts.googleapis.com/css?family=Work+Sans:400,500,600" rel="stylesheet">

        <!-- BASE CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/menu.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <link href="css/vendors.css" rel="stylesheet">

        <!-- YOUR CUSTOM CSS -->
        <link href="css/custom.css" rel="stylesheet">

        <script type="text/javascript">
            function delayedRedirect() {
                //window.location = "index.html"
            }
        </script>

    </head>
    <body style="background-color:#fff;" onLoad="setTimeout('delayedRedirect()', 200000)">
        <?php
        $slot = $_POST['slot'];
        $email = $_POST['email'];
        $name = $_POST['name'];
        $mobile = $_POST['phone'];
        $gender = $_POST['gender'];
        $nationality = $_POST['nationality'];
        $age = $_POST['age'];
        $dob = strtotime($_POST['dob']);
        
        $medium = $_POST['medium'];
        $stream = $_POST['stream'];
        $course_type = $_POST['course_type'];
        $course_1 = $_POST['course_1'];
        $course_2 = $_POST['course_2'];

        $ten_mark = $_POST['ten_mark'];
        $plustwo_mark = $_POST['plustwo_mark'];
        $phy = $_POST['phy'];
        $chem = $_POST['chem'];
        $maths = $_POST['maths'];
        $major = $_POST['major'];
        $major_mark = $_POST['major_mark'];
        $ug_consolidated_mark = $_POST['ug_consolidated_mark'];
        $ug_course_stream = $_POST['ug_course_stream'];

        $parent = $_POST['parent'];
        $mother = $_POST['mother'];
        $religion = $_POST['religion'];
        $community = $_POST['community'];
        $address_1 = $_POST['address_1'];
        $address_2 = $_POST['address_2'];
        $city = $_POST['city'];
        $pin_code = $_POST['pin_code'];
        $state = $_POST['state'];
        $aadharnumber = $_POST['aadharnumber'];
        $parentcontact = $_POST['parentcontact'];
        $parentsemail = $_POST['parentsemail'];
        $schoolname = $_POST['schoolname'];
        $board = $_POST['board'];
		if(isset($_POST['otherreligion'])){
			$otherreligion = $_POST['otherreligion'];
		} else {
			$otherreligion = "";
		}
		if(isset($_POST['othercommunity'])){
			$othercommunity = $_POST['othercommunity'];
		} else {
			$othercommunity = "";
		}
		if(isset($_POST['othermedium'])){
			$othermedium = $_POST['othermedium'];
		} else {
			$othermedium = "";
		}


        if (isset($_FILES['ten_marksheet'])) {
            $target_dir = '10marksheet/';
            $file_name = $_FILES['ten_marksheet']['name'];
            $file_tmp = $_FILES['ten_marksheet']['tmp_name'];
            $extension = explode('.', $_FILES['ten_marksheet']['name']);
            $file_ext = strtolower(end($extension));
            $marksheet_title = substr($name, 0, 3);
            $tenth_marksheet = $marksheet_title . "-" . time() . "." . $file_ext;
            move_uploaded_file($file_tmp, $target_dir . $tenth_marksheet);
        }


        if (isset($_FILES['plustwo_marksheet'])) {
            $target_dir = '12marksheet/';
            $file_name = $_FILES['plustwo_marksheet']['name'];
            $file_tmp = $_FILES['plustwo_marksheet']['tmp_name'];
            $extension = explode('.', $_FILES['plustwo_marksheet']['name']);
            $file_ext = strtolower(end($extension));
            $marksheet_title = substr($name, 0, 3);
            $plustwo_marksheet = $marksheet_title . "-" . time() . "." . $file_ext;
            move_uploaded_file($file_tmp, $target_dir . $plustwo_marksheet);
        }
		
		$ug_marksheet = "";
        
        if (isset($_FILES['photo'])) {
            $target_dir = 'photo/';
            $file_name = $_FILES['photo']['name'];
            $file_tmp = $_FILES['photo']['tmp_name'];
            $extension = explode('.', $_FILES['photo']['name']);
            $file_ext = strtolower(end($extension));
            $photo_title = substr($name, 0, 3);
            $photo = $photo_title . "-" . time() . "." . $file_ext;
            move_uploaded_file($file_tmp, $target_dir . $photo);
        }
		
		if (isset($_FILES['signature'])) {
            $target_dir = 'signature/';
            $file_name = $_FILES['signature']['name'];
            $file_tmp = $_FILES['signature']['tmp_name'];
            $extension = explode('.', $_FILES['signature']['name']);
            $file_ext = strtolower(end($extension));
            $photo_title = substr($name, 0, 3);
            $signature = $photo_title . "-" . time() . "." . $file_ext;
            move_uploaded_file($file_tmp, $target_dir . $signature);
        }
      
       $utm_source = $_POST['utm_source'];
       $utm_medium = $_POST['utm_medium'];
       $utm_campaign = $_POST['utm_campaign'];
      
        $added = time();
        // $insert_query = "INSERT leads SET "
        //         . "name='$name',"
        //         . "parent='$parent',"
        //         . "dob='$dob',"
        //         . "age='$age',"
        //         . "gender='$gender',"
        //         . "nationality='$nationality',"
        //         . "mobile='$mobile',"
        //         . "email='$email',"
        //         . "address_1='$address_1',"
        //         . "address_2='$address_2',"
        //         . "community='$community',"
        //         . "city='$city',"
        //         . "pincode='$pin_code',"
        //         . "state='$state',"
        //         . "ten_mark='$ten_mark',"
        //         . "plusone_mark='$plusone_mark',"
        //         . "plustwo_mark='$plustwo_mark',"
        //         . "phy='$phy',"
        //         . "chem='$chem',"
        //         . "maths='$maths',"
        //         . "major='$major',"
        //         . "major_mark='$major_mark',"
        //         . "ug_consolidated_mark='$ug_consolidated_mark',"
        //         . "ug_course_stream='$ug_course_stream',"
        //         . "ten_marksheet='$tenth_marksheet',"
        //         . "plustwo_marksheet='$plustwo_marksheet',"
        //         . "ug_marksheet='$ug_marksheet',"
        //         . "course_1='$course_1',"
        //         . "course_2='$course_2',"
        //         . "stream='$stream',"
        //         . "course_type='$course_type',"
        //         . "photo='$photo',"
        //         . "adhaar_front='$adhaarfront',"
        //         . "adhaar_back='$adhaarback',"
        //         . "created='$added'";
		
           $insert_query = "INSERT INTO leads2023(slot, name, parent, dob, age, gender, nationality, mobile, email, address_1, address_2, community, city, pincode, state, ten_mark, plusone_mark, plustwo_mark, phy, chem, maths, major, major_mark, ug_consolidated_mark, ug_course_stream, ten_marksheet, plustwo_marksheet, ug_marksheet, course_1, course_2, stream, course_type, photo, adhaar_front, adhaar_back, created, religion, signature, mother, medium, aadharnumber, parentscontact, parentsemail, schoolname, boardofexam, othercommunity, otherreligion, othermedium, appid, paymentstatus, paymentid, updatedby, utm_source, utm_medium, utm_campaign, updatename ) VALUES ('$slot', '$name', '$parent', '$dob', '$age', '$gender', '$nationality', '$mobile','$email','$address_1', '$address_2', '$community', '$city', '$pin_code', '$state', '$ten_mark', '$plusone_mark', '$plustwo_mark', '$phy', '$chem', '$maths', '$major', '$major_mark', '$ug_consolidated_mark', '$ug_course_stream', '$tenth_marksheet', '$plustwo_marksheet', '$ug_marksheet', '$course_1', '$course_2', '$stream', '$course_type', '$photo', '$adhaarfront', '$adhaarback', '$added', '$religion', '$signature', '$mother', '$medium', '$aadharnumber', '$parentcontact', '$parentsemail', '$schoolname', '$board', '$othercommunity', '$otherreligion', '$othermedium', '$utm_source', '$utm_medium', '$utm_campaign', '-', '-', '-', '-', '-')";
             
           if (mysqli_query($conn, $insert_query)) {
			$last_id = mysqli_insert_id($conn);
          	$last_id = sprintf('%0d',$last_id);
			$appid = "E230075".$last_id;
			$updatequery = "UPDATE `leads2023` SET `appid`='$appid' WHERE `id`=$last_id";
			$update = mysqli_query($conn, $updatequery);
            //Email Function

            
             
             
             $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><meta http-equiv="Content-type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="format-detection" content="date=no" /><meta name="format-detection" content="address=no" /><meta name="format-detection" content="telephone=no" /><meta name="x-apple-disable-message-reformatting" /><link href="https://fonts.googleapis.com/css?family=Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet"/><style type="text/css" media="screen">body{padding:0 !important;margin:0 !important;display:block !important;min-width:100% !important;width:100% !important;background:#fff;-webkit-text-size-adjust:none}a{color:#66b7f0;text-decoration:none}p{padding:0 !important;margin:0 !important}img{-ms-interpolation-mode:bicubic}.mcnPreviewText{display:none !important}@media only screen and (max-device-width: 480px), only screen and (max-width: 480px){.mobile-shell{width:100% !important;min-width:100% !important}.m-center{text-align:center !important}.center{margin:0 auto !important}.td{width:100% !important;min-width:100% !important}.m-br-3{height:3px !important}.m-br-4{height:4px !important;background:#ffffff !important}.m-br-15{height:15px !important}.m-br-25{height:25px !important}.m-td,.m-hide{display:none !important;width:0 !important;height:0 !important;font-size:0 !important;line-height:0 !important;min-height:0 !important}.m-block{display:block !important}.fluid-img img{width:100% !important;max-width:100% !important;height:auto !important}.column-top,.column{float:left !important;width:100% !important;display:block !important}.content-spacing{width:15px !important}.m-bg{display:block !important;width:100% !important;height:auto !important;background-position:center center !important}.h-auto{height:auto !important}.plr-15{padding-left:15px !important;padding-right:15px !important}.w-2{width:2% !important}.w-49{width:49% !important}.pb-4{padding-bottom:4px !important}.pb-15{padding-bottom:15px !important}.pt-0{padding-top:0 !important}.h1,.h1-white{font-size:36px !important;line-height:46px !important}.h2{font-size:26px !important;line-height:36px !important}.text-btn-large,.text-btn-large-white{padding:15px 25px !important}.text-btn,.text-btn-1,.text-btn-1-white{padding:12px 15px !important}}</style></head><body class="body" style="padding:0 !important; margin:0 !important; display:block !important; min-width:100% !important; width:100% !important; background:#ffffff; -webkit-text-size-adjust:none;"><table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff"><tr><td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"><table width="650" border="0" cellspacing="0" cellpadding="0" class="mobile-shell"><tr><td class="plr-15" style="padding: 20px 0;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><th class="column-top" valign="top" width="360" style="font-size:0pt; line-height:0pt; padding:0; margin:0; font-weight:normal; vertical-align:top;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="text-top to-left m-center" style="color:#888888; font-size:12px; line-height:20px; text-align:left;"> </td></tr></table></th><th class="column-top" valign="top" width="15" style="font-size:0pt; line-height:0pt; padding:0; margin:0; font-weight:normal; vertical-align:top;"><div style="font-size:0pt; line-height:0pt;" class="m-br-15"></div></th><th class="column-top" valign="top" style="font-size:0pt; line-height:0pt; padding:0; margin:0; font-weight:normal; vertical-align:top;"><table width="100%" border="0" cellspacing="0" cellpadding="0"></table></th></tr></table></td></tr></table></td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td> <repeater> <layout label="Section - Intro"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="img" height="245" bgcolor="#fff" style="font-size:0pt; line-height:0pt; text-align:left;">&nbsp;</td></tr></table></td><td align="center" valign="top" width="650" class="mobile-shell"><table width="650" border="0" cellspacing="0" cellpadding="0" class="mobile-shell"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="plr-15" style="padding: 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="h1 fw-medium" style="padding-bottom: 20px; color:#4a4a4a; font-size:40px; line-height:50px; text-align:center; font-weight:500;"></td></tr><tr><td class="text-1" style="padding-bottom: 30px; color:#4a4a4a; font-size:16px; line-height:30px; text-align:justify;"> <multiline> Dear Applicant,</br><p>&nbsp;</p> <b>Greetings from Aarupadai Veedu Institute of Technology!!!</b> </p><p>We appreciate your interest in our Institution. Your application has been submitted successfully; our student counsellor will contact you shortly.  </p>
			   
			   <p><b>AVIT ! A Community of Creative, Passionate & Aspiring Leaders of Tomorrow   </p><p>Click <a href="https://avcampusadmissions.com/avit/2023/admission/form/printdetails.php?appid='.$appid.'" target="_BLANK">here</a> to download your application form.</p> </multiline></td></tr><tr><td class="text-2" style="color:#4a4a4a; font-size:11px; line-height:15px; text-align:center;"></td></tr></table></td></tr></table></td></tr></table></td><td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="img" height="20" bgcolor="#ffffff" style="font-size:0pt; line-height:0pt; text-align:left;">&nbsp;</td></tr></table></td></tr></table> </layout> <table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"><table width="650" border="0" cellspacing="0" cellpadding="0" class="mobile-shell"><tr><td class="plr-15" style="padding: 0;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><th class="column-top" valign="top" width="225" style="font-size:9pt; line-height:15pt; padding:0; margin:0; font-weight:normal;text-align:left; vertical-align:top;"><multiline> <span class="link-4" style="color:#000; text-decoration:none;">Best Wishes<br /><b style="color:#000;font-size:16px;">Admission Officer, </span><br />VMRF-SMART 2023-24 <br/>Vinayaka missions Research Foundation<br /> New No.213, Old no. 160, <br />Poonamallee High Road, <br />Behind Doshi Towers ,<br />Kilpauk, Chennai, Tamil Nadu</multiline></th><th class="column-top" valign="top" width="15" style="font-size:0pt; line-height:0pt; padding:0; margin:0; font-weight:normal; vertical-align:top;"><div style="font-size:16px; line-height:30px;" class="m-br-15"></div></th><th class="column-top" valign="top" style="font-size:0pt; line-height:0pt; padding:0; margin:0; font-weight:normal; vertical-align:top;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="right" style="padding: 10px 0 25px 0;"><table border="0" cellspacing="0" cellpadding="0" class="center">
			   
			   <tr>
			   
			   
			   
			  <p>No<b>'.$appid.'</b></p>
			   
			   <td class="img" width="11" style="font-size:0pt; line-height:0pt; text-align:left;"><a href="https://www.facebook.com/AVITChennai/" target="_blank"><img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.png" width="22" height="22" editable="true" border="0" alt="" /></a></td>
                                      <td class="img" width="40" style="font-size:0pt; line-height:0pt; text-align:left;"></td>
                                      <td class="img" width="23" style="font-size:0pt; line-height:0pt; text-align:left;"><a href="https://twitter.com/AVITChennai" target="_blank"><img src="https://cdn-icons-png.flaticon.com/512/124/124021.png" width="22" height="22" editable="true" border="0" alt="" /></a></td>
                                      <td class="img" width="36" style="font-size:0pt; line-height:0pt; text-align:left;"></td>
                                      <td class="img" width="22" style="font-size:0pt; line-height:0pt; text-align:left;"><a href="https://www.instagram.com/avit_chennai/" target="_blank"><img src="https://upload.wikimedia.org/wikipedia/commons/a/a5/Instagram_icon.png" width="22" height="22" editable="true" border="0" alt="" /></a></td>
                                      <td class="img" width="36" style="font-size:0pt; line-height:0pt; text-align:left;"></td>
			   
			   </tr>
			   
			   
			   
			   </table></td></tr><tr><td class="text-footer-1 to-right m-center" align="right" style="color:#a0a09a; font-size:11px; line-height:22px; text-align:right;"> <div class="img-center" style="font-size:0pt; line-height:0pt; text-align:right;"><a href="https://avit.ac.in" target="_blank"><img src="https://www.avit.ac.in/online-scholarship-test-2021/images/logo.png" border="0"  editable="true" alt="" style="width: 200px;height:auto;" /></a></div></td></tr></table></th></tr></table></td></tr></table></td></tr></table><br /><table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#f4f4f4"><tr><td align="center" valign="top"><table width="650" border="0" cellspacing="0" cellpadding="0" class="mobile-shell"><tr><td class="text-bottom" style="padding: 35px 15px; color:#888888; font-size:11px; line-height:18px; text-align:center;"> For any queries kindly contact 98840 58280 | 87545 52018. Write your feedback to us on admission@avit.ac.in <br /> Should you wish to cancel your subscription, please <unsubscribe class="link-3-u" style="color:#a8a8a8; text-decoration:underline;"><span class="link-3-u" style="color:#a8a8a8; text-decoration:underline;">click here to unsubscribe.</span></unsubscribe></td></tr></table></td></tr></table></td></tr></table></body></html>';

             require 'sendgrid-php/vendor/autoload.php';
            $sendgrid = new \SendGrid\Mail\Mail();
            $sendgrid->setFrom("admissions@vinayakamissions.com", "AVIT Admission VMRF SMART Registration 2023-24 ");
            $sendgrid->setSubject("AVIT Admission VMRF SMART Registration 2023-24 ");
            $sendgrid->addCc("seniordeveloper@avit.ac.in");
            $sendgrid->addTo("$email", "$name");
            $sendgrid->addContent("text/html", $body);
            $sendgridkey = new \SendGrid('SG.cX6yJdbeTY6SVtjySIe_YA.xySHk3hwdSky-LjTVVc8s_YsASwSkKKEce3hT3QvDqw');
          
          
          
            try {
                $response = $sendgridkey->send($sendgrid);
            } catch (Exception $e) {
                echo 'Caught exception: ' . $e->getMessage() . "\n";
            }
             
             
                       
             
             
            // SMS Integration details
    $message = "Dear Arunkumar, 
Thank you for your interest in AVIT. We have received your request, will get back to you soon. 
Admission Team";
    $url = "https://malert.in/api/api_http.php";
    $recipients = array("$mobile");
    $param = array(
        'username' => 'smsbusiness',
        'password' => 'api@2020',
        'senderid' => 'JECSCH',
        'text' => "$message",
        'route' => 'Campaign',
        'type' => 'text',
        'datetime' => (new DateTime())->format("Y-m-d H:i:s"),
        'to' => implode(';', $recipients),
    );
    $post = http_build_query($param, '', '&');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Connection: close"));
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        $result = "cURL ERROR: " . curl_errno($ch) . " " . curl_error($ch);
    } else {
        $returnCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
        switch ($returnCode) {
            case 200:
                break;
            default:
                $result = "HTTP ERROR: " . $returnCode;
        }
    } 
    //curl_close($ch);
	$transactionamnt = 1;
	$_SESSION['orderid'] = $appid;
	$_SESSION['custid'] = $last_id;
	$_SESSION['transactionamount'] = $transactionamnt;
	
	require_once("PaytmChecksum.php");
	
	$paytmParams = array();

	$paytmParams["body"] = array(
		"requestType"   => "Payment",
		"mid"           => "Aarupa83467295709865",
		"websiteName"   => "WEBPROD",
		"orderId"       => $appid,
		"callbackUrl"   => $siteurl."paytm/pgResponse.php",
		"txnAmount"     => array(
			"value"     => $transactionamnt,
			"currency"  => "INR",
		),
		"userInfo"      => array(
			"custId"    => $last_id,
		),
	);

	/*
	* Generate checksum by parameters we have in body
	* Find your Merchant Key in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys 
	*/
	$checksum = PaytmChecksum::generateSignature(json_encode($paytmParams["body"], JSON_UNESCAPED_SLASHES), "AL8__uahGGE!C4oX");

	$paytmParams["head"] = array(
		"signature"    => $checksum
	);

	$post_data = json_encode($paytmParams, JSON_UNESCAPED_SLASHES);

	/* for Staging */
	 $url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid=Aarupa83467295709865&orderId=".$appid;

	/* for Production */
	 $url = "https://securegw.paytm.in/theia/api/v1/initiateTransaction?mid=Aarupa83467295709865&orderId=".$appid;

	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
	curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
	$response = curl_exec($ch);
	print_r($response);
        }
        ?>
		<form method="post" action="paytm/pgRedirect.php" name="paytm">
			<script type="text/javascript">
				document.paytm.submit();
			</script>
		</form>
        <div id="success">
            <div class="icon icon--order-success svg">
                <svg xmlns="http://www.w3.org/2000/svg" width="72px" height="72px">
                <g fill="none" stroke="#8EC343" stroke-width="2">
                <circle cx="36" cy="36" r="35" style="stroke-dasharray:240px, 240px; stroke-dashoffset: 480px;"></circle>
                <path d="M17.417,37.778l9.93,9.909l25.444-25.393" style="stroke-dasharray:50px, 50px; stroke-dashoffset: 0px;"></path>
                </g>
                </svg>
            </div>
            <h4><span>Request successfully sent!</span></h4>
            <small>You will be redirect to your Payment Page.<br>Please do not refresh or Close this page.</small>
			<?php 
			//header( "refresh:5;url=printdetails.php?id=".$last_id );
			?>
        </div>
    </body>
</html>