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

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

<body>
    <div class="round-loader d-none">
        <div class="circle"></div>
    </div>
    <div class="main-wrapper">
        <?php $currentPage = 'basic-element';
		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">
                        <div class="card add-row">
                            <div class="card-body">
                                <h6 class="card-title">Edit Report
                                </h6>
                                <form class="forms-sample" action="" method="POST">
                                    <div class="form-group">
                                        <label for="report-select">Select Source Table*</label>
                                        <input type="text" disabled name="report_title"
                                            value="<?= $data[0]['report_tablename'] ?>" class="form-control"
                                            id="report-title" Placeholder="Enter Report Title">
                                    </div>
                                    <div class="form-group">
                                        <label for="report-title">Report Title*</label>
                                        <input type="text" name="report_title" value="<?= $data[0]['report_title'] ?>"
                                            class="form-control" id="report-title" Placeholder="Enter Report Title"
                                            required>
                                    </div>
                                    <div class="form-group">
                                        <label for="assembly_id">Assembly ID*</label>
                                        <input type="number" disabled name="assembly_id" class="form-control"
                                            value="<?= $data[0]['assembly_id'] ?>" id="assembly_id"
                                            Placeholder="Enter Assembly ID" required>
                                    </div>
                                    <div class="form-group">
                                        <label for="lok-sabha">Loksabha</label>
                                        <input type="text" name="lok_sabha" class="form-control" id="lok-sabha"
                                            value="<?= $data[0]['loksabha'] ?>" Placeholder="Enter Loksabha">
                                    </div>
                                    <div class="form-group">
                                        <label for="district">District</label>
                                        <input type="text" name="district" class="form-control" id="district"
                                            value="<?= $data[0]['district'] ?>" Placeholder="Enter District">
                                    </div>
                                    <div class="form-group">
                                        <label for="mla-name">MLA Name</label>
                                        <input type="text" name="mla_name" class="form-control"
                                            value="<?= $data[0]['mla_name'] ?>" id="mla-name"
                                            Placeholder="Enter MLA Name">
                                    </div>
                                    <div class="form-group">
                                        <label for="Factors">Party Preference</label>
                                        <div class="form-control" id="Factors"></div>
                                        <input type="text" name="factors" id="factors_input"
                                            value="<?= $data[0]['inclination_factors'] ?>" class="form-control" hidden>
                                    </div>
                                    <div class="form-group">
                                        <label for="Rating-Comment">Performance of State Govt. and MLA</label>
                                        <div class="form-control" id="Rating-Comment"></div>
                                        <input type="text" name="rating_comment" id="rating_comment_input"
                                            value="<?= $data[0]['rating_comment'] ?>" class="form-control" hidden>
                                    </div>
                                    <div class="form-group mt-3">
                                        <label for="Caste-Trends">Caste Trends</label>
                                        <div class="form-control" id="Caste-Trends"></div>
                                        <input type="text" name="caste_trends" id="caste_trends_input"
                                            value="<?= $data[0]['caste_trends'] ?>" class="form-control" hidden>
                                    </div>



                                    <div class="form-group mt-3">
                                        <label for="Age-Trends">Age Trends</label>
                                        <div class="form-control" id="Age-Trends"></div>
                                        <input type="text" name="age_trends" id="age_trends_input"
                                            value="<?= $data[0]['age_trends'] ?>" class="form-control" hidden>
                                    </div>
                                    <div class="form-group mt-3">
                                        <label for="Occupation-Trends">Occupation Trends</label>
                                        <div class="form-control" id="Occupation-Trends"></div>
                                        <input type="text" name="occupation_trends" id="occupation_trends_input"
                                            value="<?= $data[0]['occupation_trends'] ?>" class="form-control" hidden>
                                    </div>
                                    <div class="form-group mt-3">
                                        <label for="Education-Trends">Education Trends</label>
                                        <div class="form-control" id="Education-Trends"></div>
                                        <input type="text" name="education_trends" id="education_trends_input"
                                            value="<?= $data[0]['education_trends'] ?>" class="form-control" hidden>
                                    </div>
                                    <div class="form-group mt-3">
                                        <label for="Gender-Preference">Gender Preference</label>
                                        <div class="form-control" id="Gender-Preference"></div>
                                        <input type="text" name="gender_preference" id="gender_preference_input"
                                            value="<?= $data[0]['gender_preference'] ?>" class="form-control" hidden>
                                    </div>
                                    <div class="form-group mt-3">
                                        <label for="Active-Party-Workers">Active Party Workers</label>
                                        <div class="form-control" id="Active-Party-Workers"></div>
                                        <input type="text" name="active_party_workers" id="active_party_workers_input"
                                            value="<?= $data[0]['active_party_workers'] ?>" class="form-control" hidden>
                                    </div>
                                    <div class="form-group mt-3">
                                        <label for="Swot-and-Booth">SWOT and BOOTH Categorization</label>
                                        <div class="form-control" id="Swot-and-Booth"></div>
                                        <input type="text" name="swot_and_booth" id="swot_and_booth_input"
                                            value="<?= $data[0]['swot_and_booth'] ?>" class="form-control" hidden>
                                    </div>



                                    <div class="form-group mt-3">
                                        <button type="submit" name="submit" id=submit
                                            class="btn btn-primary mt-3 edit-report-submit">Submit</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include 'footer.php'; ?>
            <?php include 'js.php'; ?>
        </div>
    </div>
    <script>
    $(' .edit-report-submit').click(() => {
        $('.circle').addClass('animate_rotate');
        $('.round-loader').removeClass('d-none');
        setTimeout(
            () => {
                $('.circle').removeClass('animate_rotate');
                $('.round-loader').addClass('d-none');
            }, 5000);
    })
    var get_data_rating;
    var get_data_factors;
    var get_data_qualitative;
    ClassicEditor
        .create(document.querySelector('#Rating-Comment'))
        .then(rating => {
            rating.setData($('#rating_comment_input').val());
            rating.model.document.on('change:data', () => {
                var data = rating.getData();
                $('#rating_comment_input').val(data);
                get_data_rating = data;
            });
        })
        .catch(error => {
            console.error(error);
        });
    ClassicEditor
        .create(document.querySelector('#Factors'))
        .then(factors => {
            factors.setData($('#factors_input').val());
            factors.model.document.on('change:data', () => {
                var data = factors.getData();
                $('#factors_input').val(data);
                get_data_factors = data;
            });
        })
        .catch(error => {
            console.error(error);
        });
    ClassicEditor
        .create(document.querySelector('#Caste-Trends'))
        .then(qualitative => {
            qualitative.setData($('#caste_trends_input').val());
            qualitative.model.document.on('change:data', () => {
                var data = qualitative.getData();
                $('#caste_trends_input').val(data);
                get_data_qualitative = data;
            });
        })
        .catch(error => {
            console.error(error);
        });

        //work
    ClassicEditor
        .create(document.querySelector('#Age-Trends'))
        .then(qualitative => {
            qualitative.setData($('#age_trends_input').val());
            qualitative.model.document.on('change:data', () => {
                var data = qualitative.getData();
                $('#age_trends_input').val(data);
                get_data_qualitative = data;
            });
        })
        .catch(error => {
            console.error(error);
        });
    ClassicEditor
        .create(document.querySelector('#Occupation-Trends'))
        .then(qualitative => {
            qualitative.setData($('#occupation_trends_input').val());
            qualitative.model.document.on('change:data', () => {
                var data = qualitative.getData();
                $('#occupation_trends_input').val(data);
                get_data_qualitative = data;
            });
        })
        .catch(error => {
            console.error(error);
        });
    ClassicEditor
        .create(document.querySelector('#Education-Trends'))
        .then(qualitative => {
            qualitative.setData($('#education_trends_input').val());
            qualitative.model.document.on('change:data', () => {
                var data = qualitative.getData();
                $('#education_trends_input').val(data);
                get_data_qualitative = data;
            });
        })
        .catch(error => {
            console.error(error);
        });
    ClassicEditor
        .create(document.querySelector('#Gender-Preference'))
        .then(qualitative => {
            qualitative.setData($('#gender_preference_input').val());
            qualitative.model.document.on('change:data', () => {
                var data = qualitative.getData();
                $('#gender_preference_input').val(data);
                get_data_qualitative = data;
            });
        })
        .catch(error => {
            console.error(error);
        });
    ClassicEditor
        .create(document.querySelector('#Active-Party-Workers'))
        .then(qualitative => {
            qualitative.setData($('#active_party_workers_input').val());
            qualitative.model.document.on('change:data', () => {
                var data = qualitative.getData();
                $('#active_party_workers_input').val(data);
                get_data_qualitative = data;
            });
        })
        .catch(error => {
            console.error(error);
        });
    ClassicEditor
        .create(document.querySelector('#Swot-and-Booth'))
        .then(qualitative => {
            qualitative.setData($('#swot_and_booth_input').val());
            qualitative.model.document.on('change:data', () => {
                var data = qualitative.getData();
                $('#swot_and_booth_input').val(data);
                get_data_qualitative = data;
            });
        })
        .catch(error => {
            console.error(error);
        });
    </script>
    <?php
	if (isset($_POST["submit"])) {
		$conn = connect_database();
		$report_title = $_POST["report_title"];
		$tablename = $_POST["report_select"];
		$mla_name = $_POST["mla_name"];
		$loksabha = $_POST["lok_sabha"];
		$district = $_POST["district"];
		$rating_comment = $_POST["rating_comment"];
		$factors = $_POST["factors"];
		$caste_trends = $_POST["caste_trends"];
		$age_trends = $_POST["age_trends"];
		$occupation_trends = $_POST["occupation_trends"];
		$education_trends = $_POST["education_trends"];
		$gender_preference = $_POST["gender_preference"];
		$active_party_workers = $_POST["active_party_workers"];
		$swot_and_booth = $_POST["swot_and_booth"];
		$id = $_GET['id'];
		$sql = "UPDATE `reportInfo` SET `loksabha` = '" . $loksabha . "',`district` = '" . $district . "',`report_title` = '" . $report_title . "', `mla_name` = '" . $mla_name . "', `rating_comment` = '" . $rating_comment . "', `inclination_factors` = '" . $factors . "', `caste_trends` = '" . $caste_trends . "', `age_trends` = '" . $age_trends . "', `occupation_trends` = '" . $occupation_trends . "', `education_trends` = '" . $education_trends . "', `gender_preference` = '" . $gender_preference . "', `active_party_workers` = '" . $active_party_workers . "', `swot_and_booth` = '" . $swot_and_booth . "'
				WHERE id =" . $id;
		$conn->query($sql);
		$conn->close();
		echo "<script>document.location = 'edit-report.php?id=" . $_GET['id'] . "';</script>";
	}
	?>
</body>

</html>