<?php

if (!empty($_POST['FirstFilterValue'])) {
    $uname = mysqli_real_escape_string($con, $_POST['FirstFilterValue']);
    $fran_sql = mysqli_query($con, "SELECT uid FROM users WHERE uname = '$uname' AND utype = 'Sub Associate'");
    if ($fran_row = mysqli_fetch_assoc($fran_sql)) {
        $conditions[] = "pSubFranchiee = '" . $fran_row['uid'] . "'";
    }
}

if (!empty($_POST['college'])) {
    $conditions[] = "pCollege = '" . mysqli_real_escape_string($con, $_POST['college']) . "'";
}

if (!empty($_POST['course'])) {
    $conditions[] = "product = '" . mysqli_real_escape_string($con, $_POST['course']) . "'";
}

if (isset($_POST['StatusValue']) && $_POST['StatusValue'] !== '') {
    $status = mysqli_real_escape_string($con, $_POST['StatusValue']);
    $conditions[] = "pStatus = '$status'";
}


if (!empty($_POST['StartDate']) && !empty($_POST['EndDate'])) {
    $startDate = mysqli_real_escape_string($con, $_POST['StartDate']);
    $endDate = mysqli_real_escape_string($con, $_POST['EndDate']);
    $conditions[] = "pCreateDate BETWEEN '$startDate' AND '$endDate'";
} elseif (!empty($_POST['StartDate'])) {
    $startDate = mysqli_real_escape_string($con, $_POST['StartDate']);
    $conditions[] = "pCreateDate >= '$startDate'";
} elseif (!empty($_POST['EndDate'])) {
    $endDate = mysqli_real_escape_string($con, $_POST['EndDate']);
    $conditions[] = "pCreateDate <= '$endDate'";
}

$conditions[] = "pFranchiee = '" . $_SESSION['uid'] . "'";

?>