<?php
//==================DB Connection Parameters=============================================================

$server = 'localhost';
$username = 'triomind_edumessversion';
$password = '7l8^GDxW-RlZ';
$database = 'triomind_edumessversiontwo';

$link = mysqli_connect($server, $username, $password, $database);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$connection = new PDO('mysql:host=localhost;dbname=triomind_edumessversiontwo', $username, $password);

$MonnifyLivePaymentApi = 'MK_PROD_Z980GG4PYA';
$MonnifyTestPaymentApi = 'MK_TEST_WP7BY1ZC3Y';

$MonnifyLiveContractCode = '779688215159';
$MonnifyTestContractCode = '6890822651';



//================Get the unique Information for page customization=======================================
$defaultUrl = "https://edumess.com/";


$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";

// Get the host (hostname)
$host = str_replace('www.','',$_SERVER['HTTP_HOST']);

// Get the current path
$path = $_SERVER['REQUEST_URI'];

// Combine the components to get the full URL
$current_url = $protocol . "://" . $host . $path;

$main_url = $host;

$sqlGetLoginID = mysqli_query($link, "SELECT * FROM institution WHERE CustomUrl = '$host'");
$rowGetLoginID = mysqli_fetch_assoc($sqlGetLoginID);
$countLoginID = mysqli_num_rows($sqlGetLoginID);


$EduMESS_Wallet_Number = '8018133138';

$sql_edumesspaymentcharges = ("SELECT * FROM edumesspaymentcharges");
$result_edumesspaymentcharges = mysqli_query($link, $sql_edumesspaymentcharges);
$row_edumesspaymentcharges = mysqli_fetch_assoc($result_edumesspaymentcharges);

$charge = floatval($row_edumesspaymentcharges['ChargeAmount']);
$Cap = floatval($row_edumesspaymentcharges['Cap']);
$StampDuty = floatval($row_edumesspaymentcharges['StampDuty']);


if ($countLoginID > 0) {

    $GroupOfSchoolID = $rowGetLoginID['InstitutionID'];
    
    $AgencyOrSchoolOwnerID = $rowGetLoginID['AgencyOrSchoolOwnerID'];

    $SchoolGeneralName = $rowGetLoginID['InstitutionGeneralName'];
    $InstitutionMotto = $rowGetLoginID['InstitutionMotto'];
    $InstitutionPhone = $rowGetLoginID['InstitutionPhone'];
    $InstitutionEmail = $rowGetLoginID['InstitutionEmail'];
    $InstitutionLogo = $rowGetLoginID['InstitutionLogo'];
    $LoginBgImage = $rowGetLoginID['LoginBgImage'];
    $LoginBgImage2 = $rowGetLoginID['LoginBgImage2'];
    $LoginBgImage3 = $rowGetLoginID['LoginBgImage3'];

    $InstitutionPrimaryColor = $rowGetLoginID['InstitutionPrimaryColor'];
    $InstitutionSeconaryColor = $rowGetLoginID['InstitutionSeconaryColor'];


    $InstitutionFavicon = $rowGetLoginID['InstitutionFavicon'];
    $FacebookPage = $rowGetLoginID['FacebookPage'];
    $InstagramPage = $rowGetLoginID['InstagramPage'];
    $TwitterPage = $rowGetLoginID['TwitterPage'];

    $ActualPlan = $rowGetLoginID['ActualPlan'];
    $PlanAmount = $rowGetLoginID['PlanAmount'];
    $PlanPercentage = $rowGetLoginID['PlanPercentage'];
    $SessionOfSignup = $rowGetLoginID['SessionOfSignup'];
    $TermOfSignup = $rowGetLoginID['TermOfSignup'];
    $DateOfSignup = $rowGetLoginID['DateOfSignup'];

    $NoDaysToCount = $rowGetLoginID['NoDaysToCount'];
    $StartCountDate = $rowGetLoginID['StartCountDate'];
    $SubscriptionStatus = $rowGetLoginID['SubscriptionStatus'];
    $SmsSenderID = $rowGetLoginID['SmsSenderID'];
    
        //GET DEFAULT PROFILE PICTURE HERE
        $pros_select_defaultimage = mysqli_query($link, "SELECT * FROM `defaultimages` WHERE `ImageName`='abba_profile_dummy_image'");
        $pros_select_defaultimage_count = mysqli_num_rows($pros_select_defaultimage);
        $pros_select_defaultimage_row = mysqli_fetch_assoc($pros_select_defaultimage);
        $user_default_profile_image = $pros_select_defaultimage_row['BaseSixtyFour'];
       //GET DEFAULT PROFILE PICTURE HERE


    // Get Institute ID Using Group of Schools
    $sqlGetInstitute = mysqli_query($link, "SELECT * FROM institution WHERE InstitutionID ='$GroupOfSchoolID'");
    $fetchGetInstituteID = mysqli_fetch_assoc($sqlGetInstitute);
    $rowGetInstituteID = mysqli_num_rows($sqlGetInstitute);

    if ($rowGetInstituteID > 0) {
        $InstituteID = $fetchGetInstituteID['InstitutionID'];
        
        $AgencyOrSchoolOwnerID = $fetchGetInstituteID['AgencyOrSchoolOwnerID'];
        
        $sqlGetagencyorschoolowner = mysqli_query($link, "SELECT * FROM agencyorschoolowner WHERE AgencyOrSchoolOwnerID ='$AgencyOrSchoolOwnerID'");
        $fetchGetagencyorschoolownerID = mysqli_fetch_assoc($sqlGetagencyorschoolowner);
        $rowGetagencyorschoolownerID = mysqli_num_rows($sqlGetagencyorschoolowner);
    
        if ($rowGetagencyorschoolownerID > 0) {
            $ConsultantID = $fetchGetagencyorschoolownerID['ConsultantID'];
            
            $AgencyOrSchoolOwnerID = $fetchGetagencyorschoolownerID['AgencyOrSchoolOwnerID'];
            
            $sqlGetconsultant = mysqli_query($link, "SELECT * FROM consultant WHERE ConsultantID ='$ConsultantID'");
            $fetchGetconsultantID = mysqli_fetch_assoc($sqlGetconsultant);
            $rowGetconsultantID = mysqli_num_rows($sqlGetconsultant);
        
            if ($rowGetconsultantID > 0) {
                $ConsultantWhatsAppNumber = $fetchGetconsultantID['ConsultantWhatsAppNumber'];
            }
        }
    }
} else {
    header("Location: ../../default/");
}


		function getClientIp() {
			$ipAddress = '';

			if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
				$ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
			} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
				$ipAddress = $_SERVER['HTTP_CLIENT_IP'];
			} else {
				$ipAddress = $_SERVER['REMOTE_ADDR'];
			}

			return $ipAddress;
		}

		$ipAddress = getClientIp();


	function insert_activity_log($activity_log_inst_camp_id, $activity_log_userid, $activity_log_usertype,$activity_log_description, $activity_log_longitude, $activity_log_latitude, $link, $ipAddress){

		date_default_timezone_set("Africa/Lagos");
		$DateCreated = date('Y-m-d H:i:s');

		$sql_activity_log = mysqli_query($link, "INSERT INTO `activitylog`(`ActitvityLogID`, `InstitutionIDOrCampusID`, `UserID`, `UserType`, `IpAddress`, `Location`, `Longitude`, `Latitude`, `Description`, `Date/Time`) VALUES (NULL,'$activity_log_inst_camp_id','$activity_log_userid','$activity_log_usertype','$ipAddress','0','$activity_log_longitude','$activity_log_latitude','$activity_log_description','$DateCreated')");

	}

mysqli_set_charset($link, 'utf8');

?>