<?php
session_start();
?>
<!DOCTYPE html>
<html>

<head>
    <title>Polytical Edge | View Report</title>
    <?php include 'css.php';
  include './assets/database/fetch.php';
  $id = $_GET['id'];
  $fetchData = fetch_trends_data($id);
  ?>
</head>

<body>
    <div class="main-wrapper">
        <?php $currentPage = 'data-table';
    include 'sidebar.php'; ?>
        <div class="page-wrapper">
            <?php include 'header.php'; ?>
            <div class="page-content">
                <div class="row">
                    <div
                        class="col-md-12 grid-margin stretch-card <?php if ($_SESSION['role'] != 'Admin') { ?> d-none<?php } ?>">
                        <div class="card add-row">
                            <div class="card-body">
                                <h6 class="card-title">Adjust Reports</h6>
                                <div class="col-lg-12 p-4" style="border:1px solid grey; border-radius:10px;">
                                    <div class="d-flex" style="width: 100%;">
                                        <h6 class="p-2">Adjust Values -></h6>
                                        <Select id="select_adjust_table"
                                            style="border: none; color:black;padding:none; width:30px;"
                                            class="form-select col col-lg-2 col-md-2 col-sm-3 col-6 form-select-lg mb-3"
                                            aria-label=".form-select-lg example">
                                            <option value="Trends">Trends</option>
                                            <option value="Inclination">Inclination</option>
                                            <option value="Ratings">Ratings</option>
                                        </Select>
                                    </div>
                                    <div id="trends-adjustment-form" style="display:block;">
                                        <div
                                            class="dropdown show d-flex justify-content-center align-items-center w-100">
                                            <div class="btn-group btn-group-toggle" data-toggle="buttons">
                                                <label
                                                    class="col-12 btn btn-outline-info active d-flex justify-content-center align-items-center">
                                                    <input class="col col-lg-12 col-md-12 col-sm-12 " type="radio"
                                                        name="caste" id="caste" autocomplete="off" checked> Caste
                                                </label>
                                                <label
                                                    class="col col-lg-12 col-md-12 col-sm-12 col-12 btn btn-outline-info d-flex justify-content-center align-items-center">
                                                    <input type="radio" name="occupation" id="occupation"
                                                        autocomplete="off"> Occupation
                                                </label>
                                                <label
                                                    class="col col-lg-12 col-md-12 col-sm-12 col-12 btn btn-outline-info d-flex justify-content-center align-items-center">
                                                    <input type="radio" name="agegroup" id="agegroup"
                                                        autocomplete="off"> Age Group
                                                </label>
                                                <label
                                                    class="col col-lg-12 col-md-12 col-sm-12 col-12 btn btn-outline-info d-flex justify-content-center align-items-center">
                                                    <input type="radio" name="education" id="education"
                                                        autocomplete="off"> Education
                                                </label>
                                            </div>
                                        </div>

                                        <!-- adjust caste values -->
                                        <div class="col-md-12 pt-2">
                                            <form action="./view-report.php?id=<?= $_GET['id'] ?>" method="POST">
                                                <div class="row">
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3 col-sm-12">
                                                        <label for="select_adjustment">Select Caste</label>
                                                        <select class="btn-outline-info" name="select_adjustment"
                                                            id="select_adjustment">
                                                            <option selected disabled>Select The Caste</option>
                                                            <?php
                              $caste_data = fetch_caste();
                              foreach ($caste_data as $key => $caste) {
                                echo '<option value="' . $caste['caste'] . '">' . $caste['caste'] . '</option>';
                              }
                              ?>
                                                        </select>
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_INC">INC</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_INC" placeholder="0.00%"
                                                            name="select_adjustment_INC">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_BJP">BJP</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_BJP" placeholder="0.00%"
                                                            name="select_adjustment_BJP">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_AAP">AAP</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_AAP" placeholder="0.00%"
                                                            name="select_adjustment_AAP">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_Others">Others</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_Others" placeholder="0.00%"
                                                            name="select_adjustment_Others">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_button"
                                                            id="select_adjustment_button_lable">Total: 0</label>
                                                        <input class="form-control btn btn-outline-info" disabled="true"
                                                            name="submit" type="submit" value="Submit Report"
                                                            id="report_submit">
                                                    </div>
                                                </div>
                                            </form>
                                        </div>


                                        <!-- adjust occupation values -->
                                        <div class="col-md-12 pt-2">
                                            <form action="./view-report.php?id=<?= $_GET['id'] ?>" method="POST">
                                                <div class="row">
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3 col-sm-12">
                                                        <label for="select_adjustment">Select Occupation</label>
                                                        <select class="btn-outline-info" name="select_adjustment"
                                                            id="select_adjustment">
                                                            <option selected disabled>Select The Occupation</option>
                                                            <?php
                              $occupation_data = fetch_occupation();
                              foreach ($occupation_data as $key => $occupation) {
                                echo '<option value="' . $occupation['occupation'] . '">' . $occupation['occupation'] . '</option>';
                              }
                              ?>
                                                        </select>
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_INC">INC</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_INC" placeholder="0.00%"
                                                            name="select_adjustment_INC">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_BJP">BJP</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_BJP" placeholder="0.00%"
                                                            name="select_adjustment_BJP">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_AAP">AAP</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_AAP" placeholder="0.00%"
                                                            name="select_adjustment_AAP">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_Others">Others</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_Others" placeholder="0.00%"
                                                            name="select_adjustment_Others">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_button"
                                                            id="select_adjustment_button_lable">Total: 0</label>
                                                        <input class="form-control btn btn-outline-info" disabled="true"
                                                            name="submit" type="submit" value="Submit Report"
                                                            id="report_submit">
                                                    </div>
                                                </div>
                                            </form>
                                        </div>

                                        <!-- adjust age group values -->
                                        <div class="col-md-12 pt-2">
                                            <form action="./view-report.php?id=<?= $_GET['id'] ?>" method="POST">
                                                <div class="row">
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3 col-sm-12">
                                                        <label for="select_adjustment">Select Age Group</label>
                                                        <select class="btn-outline-info" name="select_adjustment"
                                                            id="select_adjustment">
                                                            <option selected disabled>Select The Age Group</option>
                                                            <?php
                              $age_group_data = fetch_age_group();
                              foreach ($age_group_data as $key => $age_group) {
                                echo '<option value="' . $age_group['age_group'] . '">' . $age_group['age_group'] . '</option>';
                              }
                              ?>
                                                        </select>
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_INC">INC</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_INC" placeholder="0.00%"
                                                            name="select_adjustment_INC">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_BJP">BJP</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_BJP" placeholder="0.00%"
                                                            name="select_adjustment_BJP">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_AAP">AAP</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_AAP" placeholder="0.00%"
                                                            name="select_adjustment_AAP">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_Others">Others</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_Others" placeholder="0.00%"
                                                            name="select_adjustment_Others">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_button"
                                                            id="select_adjustment_button_lable">Total: 0</label>
                                                        <input class="form-control btn btn-outline-info" disabled="true"
                                                            name="submit" type="submit" value="Submit Report"
                                                            id="report_submit">
                                                    </div>
                                                </div>
                                            </form>
                                        </div>

                                        <!-- adjust education values -->
                                        <div class="col-md-12 pt-2">
                                            <form action="./view-report.php?id=<?= $_GET['id'] ?>" method="POST">
                                                <div class="row">
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3 col-sm-12">
                                                        <label for="select_adjustment">Select Education</label>
                                                        <select class="btn-outline-info" name="select_adjustment"
                                                            id="select_adjustment">
                                                            <option selected disabled>Select The Education</option>
                                                            <?php
                              $education_data = fetch_education();
                              foreach ($education_data as $key => $education) {
                                echo '<option value="' . $education['education'] . '">' . $education['education'] . '</option>';
                              }
                              ?>
                                                        </select>
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_INC">INC</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_INC" placeholder="0.00%"
                                                            name="select_adjustment_INC">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_BJP">BJP</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_BJP" placeholder="0.00%"
                                                            name="select_adjustment_BJP">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_AAP">AAP</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_AAP" placeholder="0.00%"
                                                            name="select_adjustment_AAP">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_Others">Others</label>
                                                        <input class="form-control report-input" type="number"
                                                            disabled="true" placeholder="0.00%" max="100" min="-100"
                                                            id="select_adjustment_Others" placeholder="0.00%"
                                                            name="select_adjustment_Others">
                                                    </div>
                                                    <div class="col-lg-2 col-md-3 col-sm-12 mt-3">
                                                        <label for="select_adjustment_button"
                                                            id="select_adjustment_button_lable">Total: 0</label>
                                                        <input class="form-control btn btn-outline-info" disabled="true"
                                                            name="submit" type="submit" value="Submit Report"
                                                            id="report_submit">
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>

                                    <div id="inclination-adjustment-form" style="display:none;">
                                        <div class="col-lg-12 pt-5">
                                            <form action="./view-report.php?id=<?= $_GET['id'] ?>" method="POST">
                                                <div class="row">
                                                    <div class="col">
                                                        <label for="select_adjustment_INC_inclination">INC</label>
                                                        <input class="form-control report-input_inclination"
                                                            type="number" value="0" max="100" min="-100"
                                                            id="select_adjustment_INC_inclination"
                                                            name="select_adjustment_INC_inclination">
                                                    </div>
                                                    <div class="col">
                                                        <label for="select_adjustment_BJP_inclination">BJP</label>
                                                        <input class="form-control report-input_inclination"
                                                            type="number" value="0" max="100" min="-100"
                                                            id="select_adjustment_BJP_inclination"
                                                            name="select_adjustment_BJP_inclination">
                                                    </div>
                                                    <div class="col">
                                                        <label for="select_adjustment_AAP_inclination">AAP</label>
                                                        <input class="form-control report-input_inclination"
                                                            type="number" value="0" max="100" min="-100"
                                                            id="select_adjustment_AAP_inclination"
                                                            name="select_adjustment_AAP_inclination">
                                                    </div>
                                                    <div class="col">
                                                        <label for="select_adjustment_Others_inclination">Others</label>
                                                        <input class="form-control report-input_inclination"
                                                            type="number" value="0" max="100" min="-100"
                                                            id="select_adjustment_Others_inclination"
                                                            name="select_adjustment_Others_inclination">
                                                    </div>
                                                    <div class="col">
                                                        <label for="select_adjustment_button_inclination"
                                                            id="select_adjustment_button_lable_inclination">Total:
                                                            0</label>
                                                        <input class="form-control btn btn-outline-info"
                                                            name="submit_inclination" type="submit"
                                                            value="Submit Report" id="report_submit_inclination">
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    <div id="ratings-adjustment-form" style="display:none;">
                                        <div class="dropdown show col-lg-12 d-flex justify-content-center">
                                            <div class="btn-group btn-group-toggle" data-toggle="buttons">
                                                <label class="btn btn-outline-info active">
                                                    <input type="radio" name="q1" id="q1" value="Q1" autocomplete="off"
                                                        checked> Q1
                                                </label>
                                                <label class="btn btn-outline-info">
                                                    <input type="radio" name="q2" id="q2" value="Q2" autocomplete="off">
                                                    Q2
                                                </label>
                                                <label class="btn btn-outline-info">
                                                    <input type="radio" name="q3" id="q3" value="Q3" autocomplete="off">
                                                    Q3
                                                </label>
                                            </div>
                                        </div>
                                        <div class="col-lg-12 pt-5">
                                            <form action="./view-report.php?id=<?= $_GET['id'] ?>" method="POST">
                                                <div class="row">
                                                    <div class="col">
                                                        <label for="select_adjustment_very_bad">बहुत खराब (0-2)</label>
                                                        <input class="form-control report-input_rating" type="number"
                                                            value="0" max="100" min="-100"
                                                            id="select_adjustment_very_bad"
                                                            name="select_adjustment__very_bad">
                                                    </div>
                                                    <div class="col">
                                                        <label for="select_adjustment_bad">खराब (3-4)</label>
                                                        <input class="form-control report-input_rating" type="number"
                                                            value="0" max="100" min="-100" id="select_adjustment_bad"
                                                            name="select_adjustment_bad">
                                                    </div>
                                                    <div class="col">
                                                        <label for="select_adjustment_ok">ठीक (5-6)</label>
                                                        <input class="form-control report-input_rating" type="number"
                                                            value="0" max="100" min="-100" id="select_adjustment_ok"
                                                            name="select_adjustment_ok">
                                                    </div>
                                                    <div class="col">
                                                        <label for="select_adjustment_good">अच्छा (7-8)</label>
                                                        <input class="form-control report-input_rating" type="number"
                                                            value="0" max="100" min="-100" id="select_adjustment_good"
                                                            name="select_adjustment_good">
                                                    </div>
                                                    <div class="col">
                                                        <label for="select_adjustment_very_good">बहुत अच्छा
                                                            (9-10)</label>
                                                        <input class="form-control report-input_rating" type="number"
                                                            value="0" max="100" min="-100"
                                                            id="select_adjustment_very_good"
                                                            name="select_adjustment_very_good">
                                                    </div>
                                                    <div class="col">
                                                        <label for="report_submit_rating"
                                                            id="select_adjustment_button_lable_rating">Total: 0</label>
                                                        <input class="form-control btn btn-outline-info" name="submit"
                                                            type="submit" value="Submit Report"
                                                            id="report_submit_rating">
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12 grid-margin stretch-card">
                        <div class="card add-row">
                            <div class="card-body">
                                <div class="col-lg-12 p-4 d-flex justify-content-between">
                                    <div class="dropdown show d-flex justify-content-center align-items-center w-100">
                                        <div class="btn-group btn-group-toggle" data-toggle="buttons">
                                            <label id="trends_radio"
                                                class="col col-lg-12 col-md-12 col-sm-12 col-12 active btn btn-outline-info d-flex justify-content-center align-items-center">
                                                <input type="radio" name="agegroup" id="trends_radio" autocomplete="off"
                                                    checked> Trends
                                            </label>
                                            <label id="inclination_radio"
                                                class="col-12 btn btn-outline-info d-flex justify-content-center align-items-center">
                                                <input type="radio" name="caste" id="inclination_radio"
                                                    autocomplete="off"> Inclination
                                            </label>
                                            <label id="ratings_radio"
                                                class="col col-lg-12 col-md-12 col-sm-12 col-12 btn btn-outline-info d-flex justify-content-center align-items-center">
                                                <input type="radio" name="occupation" id="" autocomplete="off"> Ratings
                                            </label>
                                        </div>
                                    </div>
                                    <div class="dropdown show d-flex justify-content-center align-items-center w-100">
                                        <div class="btn-group btn-group-toggle">
                                            <input type="button" value="Download PDF" id="pdf_download_button"
                                                class="col col-lg-12 col-md-12 col-sm-12 col-12 btn btn-outline-info d-flex justify-content-center align-items-center">
                                            <input type="button" value="Download Doc" id="doc_download_button"
                                                class="col col-lg-12 col-md-12 col-sm-12 col-12 btn btn-outline-info d-flex justify-content-center align-items-center">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="print col-md-12 p-0">
                        <div class="trends_data_table col-md-12">
                            <div class="grid-margin stretch-card">
                                <div class="card add-row">
                                    <div class="card-body">
                                        <h6 class="card-title">Caste</h6>
                                        <div class="col-lg-12 p-4" style="border:1px solid grey; border-radius:10px;">
                                            <div class="table-scroll">
                                                <table id='dataTable' cellspacing="0" class='display dataTable table'>
                                                    <tr>
                                                        <th>S.No.</th>
                                                        <th>Caste</th>
                                                        <th>INC</th>
                                                        <th>BJP</th>
                                                        <th>AAP</th>
                                                        <th>Others</th>
                                                    </tr>
                                                    <tbody>
                                                        <?php
                            if (is_array($fetchData[0])) {
                              $sn = 1;
                              foreach ($fetchData[0] as $data) {
                            ?>
                                                        <tr>
                                                            <td>
                                                                <?= $sn; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['caste']; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['INC'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['BJP'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['AAP'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['Others'] . '%' ?? '-'; ?>
                                                            </td>
                                                        </tr>
                                                        <?php
                                $sn++;
                              }
                            } else { ?>
                                                        <tr>
                                                            <td colspan="8">
                                                                <?php echo $fetchData[0]; ?>
                                                            </td>
                                                        <tr>
                                                            <?php
                            } ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="grid-margin stretch-card">
                                <div class="card add-row">
                                    <div class="card-body">
                                        <h6 class="card-title">Occupation</h6>
                                        <div class="col-lg-12 p-4" style="border:1px solid grey; border-radius:10px;">
                                            <div class="table-scroll">
                                                <table id='dataTable' cellspacing="0" class='display dataTable table'>
                                                    <tr>
                                                        <th>S.No.</th>
                                                        <th>Occupation</th>
                                                        <th>INC</th>
                                                        <th>BJP</th>
                                                        <th>AAP</th>
                                                        <th>Others</th>
                                                    </tr>
                                                    <tbody>
                                                        <?php
                            if (is_array($fetchData[1])) {
                              $sn = 1;
                              foreach ($fetchData[1] as $data) {
                            ?>
                                                        <tr>
                                                            <td>
                                                                <?= $sn; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['occupation']; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['INC'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['BJP'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['AAP'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['Others'] . '%' ?? '-'; ?>
                                                            </td>
                                                        </tr>
                                                        <?php
                                $sn++;
                              }
                            } else { ?>
                                                        <tr>
                                                            <td colspan="8">
                                                                <?php echo $fetchData[1]; ?>
                                                            </td>
                                                        <tr>
                                                            <?php
                            } ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="grid-margin stretch-card">
                                <div class="card add-row">
                                    <div class="card-body">
                                        <h6 class="card-title">Age Group</h6>
                                        <div class="col-lg-12 p-4" style="border:1px solid grey; border-radius:10px;">
                                            <div class="table-scroll">
                                                <table id='dataTable' cellspacing="0" class='display dataTable table'>
                                                    <tr>
                                                        <th>S.No.</th>
                                                        <th>Age Group</th>
                                                        <th>INC</th>
                                                        <th>BJP</th>
                                                        <th>AAP</th>
                                                        <th>Others</th>
                                                    </tr>
                                                    <tbody>
                                                        <?php
                            if (is_array($fetchData[2])) {
                              $sn = 1;
                              foreach ($fetchData[2] as $data) {
                            ?>
                                                        <tr>
                                                            <td>
                                                                <?= $sn; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['age_group']; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['INC'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['BJP'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['AAP'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['Others'] . '%' ?? '-'; ?>
                                                            </td>
                                                        </tr>
                                                        <?php
                                $sn++;
                              }
                            } else { ?>
                                                        <tr>
                                                            <td colspan="8">
                                                                <?php echo $fetchData[2]; ?>
                                                            </td>
                                                        <tr>
                                                            <?php
                            } ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="grid-margin stretch-card">
                                <div class="card add-row">
                                    <div class="card-body">
                                        <h6 class="card-title">Education</h6>
                                        <div class="col-lg-12 p-4" style="border:1px solid grey; border-radius:10px;">
                                            <div class="table-scroll">
                                                <table id='dataTable' cellspacing="0" class='display dataTable table'>
                                                    <tr>
                                                        <th>S.No.</th>
                                                        <th><?= $table_filter ?></th>
                                                        <th>INC</th>
                                                        <th>BJP</th>
                                                        <th>AAP</th>
                                                        <th>Others</th>
                                                    </tr>
                                                    <tbody>
                                                        <?php
                            if (is_array($fetchData[3])) {
                              $sn = 1;
                              foreach ($fetchData[3] as $data) {
                            ?>
                                                        <tr>
                                                            <td>
                                                                <?= $sn; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['education']; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['INC'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['BJP'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['AAP'] . '%' ?? '-'; ?>
                                                            </td>
                                                            <td>
                                                                <?= $data['Others'] . '%' ?? '-'; ?>
                                                            </td>
                                                        </tr>
                                                        <?php
                                $sn++;
                              }
                            } else { ?>
                                                        <tr>
                                                            <td colspan="8">
                                                                <?php echo $fetchData[3]; ?>
                                                            </td>
                                                        <tr>
                                                            <?php
                            } ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="inclination_data_table col-md-12 stretch-card grid-margin d-none">
                            <div class="card add-row">
                                <div class="card-body">
                                    <h6 class="card-title">Inclination</h6>
                                    <div class="col-lg-12 p-4"
                                        style="border:1px solid grey; border-radius:10px;overflow:hidden;">
                                        <h3 style="position: absolute; top: 20px;left:20px;z-index:1;">NATURAL
                                            INCLINATION FOR PARTY</h3>
                                        <div id="chartContainer"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="ratings_data_table col-md-12 d-none">
                            <div class="grid-margin stretch-card">
                                <div class="card add-row">
                                    <div class="card-body">
                                        <h6 class="card-title">Q1</h6>
                                        <div class="col-lg-12 p-4" style="border:1px solid grey; border-radius:10px;">
                                            <h3>Central Govt - NDA</h3>
                                            <div id="ratings-charts-q1"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="grid-margin stretch-card">
                                <div class="card add-row">
                                    <div class="card-body">
                                        <h6 class="card-title">Q2</h6>
                                        <div class="col-lg-12 p-4" style="border:1px solid grey; border-radius:10px;">
                                            <h3>State Govt - BJP</h3>
                                            <div id="ratings-charts-q2"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="grid-margin stretch-card">
                                <div class="card add-row">
                                    <div class="card-body">
                                        <h6 class="card-title">Q3</h6>
                                        <div class="col-lg-12 p-4" style="border:1px solid grey; border-radius:10px;">
                                            <h3>MLA <?= $data['rating_candidate_name'] ?? '' ?></h3>
                                            <div id="ratings-charts-q3"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include 'footer.php'; ?>
            <?php include 'js.php'; ?>
        </div>
    </div>
    <script src="./assets/js/graph.js"></script>
    <script>
    $('#trends_radio').click(function() {
        $('.trends_data_table').removeClass('d-none');
        $('.ratings_data_table').addClass('d-none');
        $('.inclination_data_table').addClass('d-none');
    })
    $('#inclination_radio').click(function() {
        $('.inclination_data_table').removeClass('d-none');
        $('.trends_data_table').addClass('d-none');
        $('.ratings_data_table').addClass('d-none');
    })
    $('#ratings_radio').click(function() {
        $('.ratings_data_table').removeClass('d-none');
        $('.trends_data_table').addClass('d-none');
        $('.inclination_data_table').addClass('d-none');
    })

    $('#select_adjust_table').change(function() {
        if (this.value == 'Trends') {
            $('#trends-adjustment-form').css('display', 'block');
            $('#inclination-adjustment-form').css('display', 'none');
            $('#ratings-adjustment-form').css('display', 'none');
        } else if (this.value == 'Inclination') {
            $('#inclination-adjustment-form').css('display', 'block');
            $('#trends-adjustment-form').css('display', 'none');
            $('#ratings-adjustment-form').css('display', 'none');
        } else if (this.value == 'Ratings') {
            $('#ratings-adjustment-form').css('display', 'block');
            $('#inclination-adjustment-form').css('display', 'none');
            $('#trends-adjustment-form').css('display', 'none');
        }

    });
    $('#select_adjustment').change(function() {
        $('.report-input').prop('disabled', false);
        $('.report-input').prop('value', 0);
        $('#report_submit').prop('disabled', false);
        $(".report-input").removeClass("is-valid");
        $(".report-input").removeClass("is-invalid");
        document.getElementById('select_adjustment_button_lable').innerHTML = `Total: 0`;
    });
    $('#report_submit').on('click', () => {
        var caste = document.getElementById("select_adjustment").value
        var total = parseFloat(document.getElementById("select_adjustment_INC").value) + parseFloat(document
            .getElementById("select_adjustment_BJP").value) + parseFloat(document.getElementById(
            "select_adjustment_AAP").value) + parseFloat(document.getElementById("select_adjustment_Others")
            .value);
        if (total != 0) {
            event.preventDefault();
            $(".report-input").addClass("is-invalid");
            $(".report-input").removeClass("is-valid");
            alert('The total sum should be 0');
        } else {
            $(".report-input").removeClass("is-invalid");
            $(".report-input").addClass("is-valid");
            if (confirm(`Want to update Values of ${caste} ?`) == false) {
                event.preventDefault();
                $(".report-input").removeClass("is-valid");
            }
        }

    });
    $('.report-input').change(() => {
        var total = parseFloat(document.getElementById("select_adjustment_INC").value) + parseFloat(document
            .getElementById("select_adjustment_BJP").value) + parseFloat(document.getElementById(
            "select_adjustment_AAP").value) + parseFloat(document.getElementById("select_adjustment_Others")
            .value);
        document.getElementById('select_adjustment_button_lable').innerHTML = `Total: ${total}`;
        if (total != 0) {
            event.preventDefault();
            $(".report-input").addClass("is-invalid");
            $(".report-input").removeClass("is-valid");
        } else {
            $(".report-input").removeClass("is-invalid");
            $(".report-input").addClass("is-valid");
        }
    });

    // inclination

    $('#report_submit_inclination').on('click', () => {
        var total = parseFloat(document.getElementById("select_adjustment_INC_inclination").value) + parseFloat(
            document.getElementById("select_adjustment_BJP_inclination").value) + parseFloat(document
            .getElementById("select_adjustment_AAP_inclination").value) + parseFloat(document
            .getElementById("select_adjustment_Others_inclination").value);
        if (total != 0) {
            event.preventDefault();
            $(".report-input_inclination").addClass("is-invalid");
            $(".report-input_inclination").removeClass("is-valid");
            alert('The total sum should be 0');
        } else {
            $(".report-input_inclination").removeClass("is-invalid");
            $(".report-input_inclination").addClass("is-valid");
            if (confirm(`Want to update Values of Inclination?`) == false) {
                event.preventDefault();
                $(".report-input_inclination").removeClass("is-valid");
            }
        }
    });
    $('.report-input_inclination').change(() => {
        var total = parseFloat(document.getElementById("select_adjustment_INC_inclination").value) + parseFloat(
            document.getElementById("select_adjustment_BJP_inclination").value) + parseFloat(document
            .getElementById("select_adjustment_AAP_inclination").value) + parseFloat(document
            .getElementById("select_adjustment_Others_inclination").value);
        document.getElementById('select_adjustment_button_lable_inclination').innerHTML = `Total: ${total}`;
        if (total != 0) {
            event.preventDefault();
            $(".report-input_inclination").addClass("is-invalid");
            $(".report-input_inclination").removeClass("is-valid");
        } else {
            $(".report-input_inclination").removeClass("is-invalid");
            $(".report-input_inclination").addClass("is-valid");
        }
    });
    </script>
    <?php
  if (isset($_POST['submit'])) {
    $updateData = [
      'caste' => $_POST["select_adjustment"],
      'INC' => $_POST["select_adjustment_INC"] == '' ? 0 : $_POST["select_adjustment_INC"],
      'BJP' => $_POST["select_adjustment_BJP"] == '' ? 0 : $_POST["select_adjustment_BJP"],
      'AAP' => $_POST["select_adjustment_AAP"] == '' ? 0 : $_POST["select_adjustment_AAP"],
      'Others' => $_POST["select_adjustment_Others"] == '' ? 0 : $_POST["select_adjustment_Others"]
    ];
    update_trends_caste_values($updateData);
  }

  if (isset($_POST['submit_inclination'])) {
    $updateData = [
      'INC' => $_POST["select_adjustment_INC_inclination"] == '' ? 0 : $_POST["select_adjustment_INC_inclination"],
      'BJP' => $_POST["select_adjustment_BJP_inclination"] == '' ? 0 : $_POST["select_adjustment_BJP_inclination"],
      'AAP' => $_POST["select_adjustment_AAP_inclination"] == '' ? 0 : $_POST["select_adjustment_AAP_inclination"],
      'Others' => $_POST["select_adjustment_Others_inclination"] == '' ? 0 : $_POST["select_adjustment_Others_inclination"]
    ];
    update_inclination_values($updateData);
  }
  ?>
</body>

</html>