<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$success = false;
$maindb = 'accmast';
$society = $_SESSION["society_" . $dbname];
$file = "multi_mail.php";

$exam = $_REQUEST["exam"];
$center = $_REQUEST["center"];
$section = $_REQUEST["section"];
$session = $_REQUEST["session"];
$medium = $_REQUEST["medium"];
$search = $_REQUEST["search"];

$examcond = '';
$centcond = '';
$sectcond = '';
$medcond = '';
$sesscond = '';
$searcond = '';

if (!empty($search)) {
    $searcond = "AND a.`custcode` LIKE '%$search%' ";
}else{
    $searcond = "";
}
if (!empty($exam)) {
    $examcond = "AND b.`examcode` = '$exam' ";
}

if (!empty($center)) {
    $centcond = "AND a.`centcode` = '$center' ";
    $centcond1 = "AND `centcode` = '$center' ";
}

if (!empty($section)) {
    $sectcond = "AND b.`section` = '$section' ";
}

if (!empty($medium)) {
    $medcond = "AND a.`medmcode` = '$medium' ";
}

if (!empty($session)) {
    $sesscond = "AND b.`session` = '$session' ";
}

    $mainqry = mysqli_query($conn, "SELECT a.*, b.examcode FROM `accmast` a, demdmain b WHERE a.`accode` = b.`accode` and a.email !=''
                            $centcond $searcond $examcond $sesscond $medcond $sectcond group by a.email order by a.custcode")or die(mysqli_error($conn));

$num = mysqli_num_rows($mainqry);

if ($num > 0) {
    echo "<table class='table table-bordered table-hover myTable' width='100%'>";
    echo "<tr style='background-color: #6082BF;color: white;'>";
    echo "<td width='5%'><input type='checkbox' class='form-control acheck' id='acheck' style='width:50%'></td>";
    echo "<td width='10%'><b>Code</b></td>";
    echo "<td width='25%'><b>Name</b></td>";
    echo "<td width='40%'><b>Address</b></td>";
    echo "<td width='10%'><b>Email</b></td>";
    echo "</tr>";
    $ctr = 0;
    while ($row2 = mysqli_fetch_array($mainqry)) {
        $email = $row2['email'];
        $modcode = $row2['custcode'];
        $modname = $row2['name'];
        $maccode = $row2['accode'];
        $addr = $row2['add1'] . " " . $row2['add2'] . " " . $row2['add3'];
        $ctr++;

        echo "<tr class='schltab'>";
        echo "<td><input type='checkbox' class='form-control mcheck'  name='chk_$ctr' value='1' style='width:50%'></td>";
        echo "<td><b>$modcode</b>
              <input type='hidden' style='border: none' class='scust' value='$modcode' name='custcode_$ctr' readonly>
              <input type='hidden' value='$maccode' class='accode'>
              </td>";
        echo "<td><b>$modname<input type='hidden' style='border: none' class='email' value='$email' name='email_$ctr'></b></td>";
        echo "<td><b>$addr</b></td>";
        echo "<td><b>$email</b></td>";
        echo "</tr>";
    }
    echo"<input type='hidden' value='$ctr' name='count' class='form-control ' style='width:50%'>";
    echo "</table>";
} else {
    echo"<h1>No Record Found.</h1>";
}
