<?php
session_start();
if (!empty($_POST['email']) && !empty($_POST['name']) && !empty($_POST['contactno'])) {
  $name = $_POST['name'];
  $email = $_POST['email'];
  $contactno = $_POST['contactno'];
  $city = $_POST['city'];
  $course = $_POST['selectcourse'];
  $universtiy_name = 'DPU';
  $formtype = $_POST['formtype'];
  $source = $_POST['source'];
  $from = $_POST['from'];
  $all_univ = "all";
  $subcourse_ID = $_POST['subcourse_ID'];
  $campaign_name = $_SESSION["campaign_name"];
  $ad_group = $_SESSION["ad_group"];
  $ads = $_SESSION["ads"];
  $source_campaign = $_SESSION["sourcecampaign"];

  if (!empty($_POST['email']) && !empty($_POST['name']) && !empty($_POST['contactno'])) {

    lsq_leads($name, $email, $contactno, $course, $specializations, $city, $campaign_name, $ad_group, $ads, $source_campaign);

    if ($from == "pop") {

      header("Location: https://onlinedypatil.com/thankyou.php");
      exit();
    } elseif ($from == "livechat") {
      header("Location: https://wa.link/lsgdm0");
      exit();
    } elseif ($from == "callus") {
      header("Location: tel:9289753708");
      exit();
    } else {
      header("Location: https://onlinedypatil.com/");
      exit();
    }
  }
} else {
  $unversity = "https://onlinedypatil.com/";
  alert_msg($unversity);
  echo '404 Error';
}

function lsq_leads($name, $email, $contactno, $course, $specializations, $city, $campaign_name, $ad_group, $ads, $source_campaign)
{
  $curl = curl_init();

  curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://admin.collegevidya.com/landing_page_create/',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => array('gender' => 'other', 'name' => $name, 'email' => $email, 'mobile' => $contactno, 'course' => $course, 'specializations' => $specializations, 'state' => $city, 'source' => 'DPU', 'sub_source' => 'Google', 'campaign_name' => $campaign_name, 'ad_group_name' => $ad_group, 'ads_name' => $ads, 'source_campaign' => $source_campaign, 'website_url' => 'https://onlinedypatil.com/', 'universityID' => '52'),
  ));

  $response = curl_exec($curl);

  curl_close($curl);
  return $response;
}

function alert_msg($unversity)
{
  $postet = [

    "unversity" => $unversity,
  ];
  $posted_data = json_encode($postet);
  $curl = curl_init();
  curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://www.ignouadmissions.com/email_managment/landing-page-alert.php',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $posted_data,
    CURLOPT_HTTPHEADER => array(
      'Content-Type: application/json'
    ),
  ));
  $response = curl_exec($curl);
  curl_close($curl);
  return $response;
}
