<?php
session_start();
if (!isset($_SESSION['id'])) {
   header("location: main.php");
}
?>
<?php
$capchaval = substr(str_shuffle("1234abcdefghijkmnpqrABCDEFGHIJKL123456789stvwxyzMNPQRSTVWXYZ56789"), 0, 8);
error_reporting(0);
//session_start();
// include "fetch_data_complain.php";
include "connection.php";

$APP_ID = $_SESSION['id'];












// $APP_ID = 79;
$sql = "SELECT *  FROM AD_APP  WHERE APP_ID = '$APP_ID'";
$parse = ociparse($conn, $sql);
oci_execute($parse);

// print_r($sql);
while ($row = oci_fetch_assoc($parse)) {
   $user_row[] = $row;
}

// var_dump($division);
// echo count($division);
oci_free_statement($parse);


$SMS_MOBILE_NO =  $user_row[0]['SMS_MOBILE_NO'];









/* Start Procedure for Report */
$curs = oci_new_cursor($conn);

$stid = oci_parse($conn, "begin PKG_AD_Compain.DPD_AD_APP_Select_compain(:cur_data,:APP_ID); end;");


oci_bind_by_name($stid, ":cur_data", $curs, -1, OCI_B_CURSOR);
oci_bind_by_name($stid, ":APP_ID", $APP_ID, -1, SQLT_CHR);



oci_execute($stid);
oci_execute($curs);


while (($row = oci_fetch_array($curs, OCI_ASSOC + OCI_RETURN_NULLS)) != false) {

   $report_output[] = $row;
}



// $TRX_ID =  $report_output[0]['TRX_ID'];
// echo "$TRX_ID";


/* End Procedure for Report */
$bool = true;












if (isset($_POST['submit'])) {



   $COMP_DTL = $_POST['complain_des'];
   $COMP_IMAGE = $_POST['basedata'];








   $returnval = 0;
   $stid = oci_parse($conn, "begin PKG_AD_Compain.DPD_AD_Compain_submit(:o_status,:APP_ID,:COMP_DTL,:COMP_IMAGE); end;");


   oci_bind_by_name($stid, ":o_status", $returnval, -1, SQLT_INT);
   oci_bind_by_name($stid, ":APP_ID", $APP_ID, -1, SQLT_CHR);
   oci_bind_by_name($stid, ":COMP_DTL", $COMP_DTL, -1, SQLT_CHR);
   oci_bind_by_name($stid, ":COMP_IMAGE", $COMP_IMAGE, -1, SQLT_CHR);

   oci_execute($stid);

   oci_free_statement($stid);
   oci_close($conn);
   if ($returnval == '0') {
      echo '<script>alert("System Error Please Try Latter.")
      // window.location.href = "https://ndc.iadmissionbd.net/view1.php";
      </script>';
   } else if ($returnval == '1') {
      echo '<script>
      alert("Thank For Your Complain Submission. You will get reply on your complain very soon");
      // window.location.href = "https://www.itbadmission.com/ndc/view1.php";
      // window.location.href = "http://localhost/ndc/view1.php";
      window.location.href = "http://103.106.118.12/ndc_2025/download/view1.php";
      </script>';
   } 
}












?>



<html lang="en">

<head>
<link rel="icon" href="assets/img/logo.jpg" type="image/jpeg">
   <!-- Google tag (gtag.js) -->
   <script async src="https://www.googletagmanager.com/gtag/js?id=G-GQPGJ4YN30"></script>
   <script>
      window.dataLayer = window.dataLayer || [];

      function gtag() {
         dataLayer.push(arguments);
      }
      gtag('js', new Date());

      gtag('config', 'G-GQPGJ4YN30');
   </script>


   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Edit Profile</title>
   <!-- using online links -->
   <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

   <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">

   <link rel="stylesheet" href="//malihu.github.io/custom-scrollbar/jquery.mCustomScrollbar.min.css">

   <!-- CSS only -->
   <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
   <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> -->
   <style>
      select[readonly] {
         background: #eee;
         /*Simular campo inativo - Sugestão @GabrielRodrigues*/
         pointer-events: none;
         touch-action: none;
      }

      .header img {
         float: left;
         width: 100px;
         height: 100px;
         /* background: #555; */
      }
   </style>
</head>

<body>






   <!-- dashboard start -->
   <?php include 'dashboard.php'; ?>
   <!-- dashboard end -->

   <form action="" method="POST" enctype="multipart/form-data">

      <div class="container" style="width: 1200px;margin: 50px;">
         <div class="card">
         <?php include 'marquee1.php'; ?>
            <div class="card-body">



               <div class="row" style="margin-top: 30px;">
                  <div class="col-md-3">

                  </div>
                  <div class="col-md-7">




                     <div class="header">
                        <img src="assets/img/logo.jpg" alt="logo" width="60px" height="60px" />
                        <h4 style="font-weight: bold;text-align: center;">Admission Application Form 2025 </h4>
                        <h5 style="font-weight: bold;text-align: center;">Notre Dame College,Dhaka</h5>
                        <!-- <h6>Applied For Admission to Study : <label for="">Science(bangla)</label></h6> -->
                     </div>
                  </div>
                  <div class="col-md-2">
                  </div>
               </div>
               <div class="form-body">


                  <div class="row m-3">
                  

                     <div class="col-lg-12 col-md-12 col-sm-12">
                        <div class="p-3 mb-2" style="background-color: #ABCDEF;">
                           <h4 class="text-center text-weight-bolder" style="color: red;">Complain Box</h4>
                        </div>


                        <div class="col-lg-12 col-md-12 col-sm-12">
                                    <div class="row">
                                        <div class="col-lg-3 col-md-3 col-sm-12">
                                            <label for="text" class="text-center font-weight-bold">Image:</label>

                                        </div>
                                        <div class="col-lg-6 col-md-6 col-sm-12">
                                           
                                            <input type="file" accept="image/*" name="file" id="file" onchange="preview_image(event)" >
                                        </div>
                                        <div class="col-lg-3 col-md-3 col-sm-12">
                                            <img id="output_image" width="130px" height="130px"></img>
                                            <input type="text" class="form-control" name="basedata" id="basedata" hidden>
                                        </div>
                                    </div>
                                </div>





                        <div class="row">
                              <div class="col-lg-12 col-md-12 col-sm-12">
                                 <label for="text" class="text-center font-weight-bold">Complain Description:</label>
                              </div>
                              <div class="col-lg-12 col-md-12 col-sm-12">
                                 <textarea name="complain_des" id="complain_des" cols="50" rows="4"></textarea>
                              </div>
                           </div>
                     </div>

                  </div>





                  <div class="col text-center">
                     <button type="submit" class="btn btn-success m-3" name='submit' id='submit'>
                        Submit
                     </button>
                  </div>

   </form>




   <!-- Only Table Mini Start -->
   <div class="applicant-info" style="margin-top:20px;" id="mini-table">

      <div class="mini-tab">
         <div class="row">

            <div class="col-12">

               <!-- <div class="card-header" style="background-color: #ABCDEF;">
          <h4 class="text-center text-weight-bolder">Applicant Information</h4>
      </div> -->
               <div class="card-body" id="report">

                  <div class="p-3 mb-2" style="background-color: #ABCDEF;">
                     <h4 class="text-center text-weight-bolder">Complain Report</h4>
                  </div>

                  <!-- <a href="#" class="btn btn-info mb-2" onclick="full_det()">Full Details</a> -->

                  <table id="table_id" class="display" style="width:100%">
                     <thead>
                        <tr style="background:#11c7e0">
                           <!-- <th style="text-align: center;">Admit Card</th> -->
                           <th style="text-align: center;">Complain ID</th>
                           <th style="text-align: center;">Submission Date</th>
                           <th style="text-align: center;">Complain Details</th>
                           <th style="text-align: center;">Complain Image</th>
                           
                           <th style="text-align: center;"> Reply</th>
                           


                        </tr>
                     </thead>
                     <tbody style="font-size: 15px;">
                        <?php
                        if ($bool) {
                           for ($i = 0; $i < count($report_output); $i++) {


                        ?>
                              <tr style="color: black!important; border-bottom: 2px solid black;">


                              <td style="background: #e6f8fa; text-align: center; width: 15%;">
                                    <a class="text-decoration-none">
                                       <?php echo $report_output[$i]['COMP_ID'] ?>
                                    </a>
                                 </td>


                              <td style="background: #e6f8fa; text-align: center; width: 15%;">
                                    <a class="text-decoration-none">
                                       <?php echo $report_output[$i]['COMP_SUB_DATE'] ?>
                                    </a>
                                 </td>


                                 <td style="background: #e6f0e9; text-align: center; color: red; width: 50%;">
                                    <a class="text-decoration-none">
                                       <?php echo $report_output[$i]['COMPLAIN_DTL'] ?>
                                    </a>
                                 </td>

                                 <td style=" text-align: center;" style="width: 10%;">
                                    <a class="text-decoration-none" >
                                       <img src="data:image/jpeg;base64,<?php echo $report_output[$i]['COMP_IMG']->read(20000); ?>" id="output_image" width="130px" height="130px"></img>
                                    </a>
                                 </td>



                                 


                                 <td style="background: #79ed9c; text-align: center; width: 25%;">
                                    <a class="text-decoration-none">
                                       <?php echo $report_output[$i]['COMP_REPLY'] ?>
                                    </a>
                                 </td>

                              



                                 

















                              </tr>

                              
                              
                        <?php }
                        } ?>
                     </tbody>
                  </table>

               </div>
            </div>

         </div>
      </div>
   </div>
   <!-- Only Table Mini End -->
   </div>
   </div>
   </div>
   </div>


   </form>


   <!-- using online scripts -->
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
   <script src="//malihu.github.io/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
   <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>




   <script type='text/javascript'>
        $(document).ready(function() {
            $("#ssc_group").change(function() {
                $(this).find("option:selected").each(function() {
                    var optionValue = $(this).attr("value");
                    if (optionValue) {
                        $(".group").not("." + optionValue).hide();
                        $("." + optionValue).show();
                    } else {
                        $(".group").hide();
                    }
                });
            }).change();
        });

        /*function preview_image(event) 
        {
           var reader = new FileReader();
           reader.onload = function()
           {
              var output = document.getElementById('output_image');
              output.src = reader.result;
           }
           reader.readAsDataURL(event.target.files[0]);
        }*/
        const MAX_WIDTH = 90;
        const MAX_HEIGHT = 108;
        const MIME_TYPE = "image/jpeg";
        const QUALITY = 0.9;

        const input = document.getElementById("file");
        input.onchange = function(ev) {
            const file = ev.target.files[0]; // get the file
            const blobURL = URL.createObjectURL(file);
            const img = new Image();
            img.src = blobURL;
            img.onerror = function() {
                URL.revokeObjectURL(this.src);
                // Handle the failure properly
                console.log("Cannot load image");
            };
            img.onload = function() {
                URL.revokeObjectURL(this.src);
                const [newWidth, newHeight] = calculateSize(img, MAX_WIDTH, MAX_HEIGHT);
                const canvas = document.createElement("canvas");
                canvas.width = newWidth;
                canvas.height = newHeight;
                const ctx = canvas.getContext("2d");
                ctx.drawImage(img, 0, 0, newWidth, newHeight);
                canvas.toBlob(
                    (blob) => {
                        // Handle the compressed image. es. upload or save in local state
                        //displayInfo('Original file', file);
                        //displayInfo('Compressed file', blob);
                    },
                    MIME_TYPE,
                    QUALITY
                );
                var dataURL = canvas.toDataURL();
                document.getElementById('output_image')
                    .setAttribute(
                        'src', dataURL
                    );
                dataURL = dataURL.replace(/^data:image\/[a-z]+;base64,/, "");
                document.getElementById('basedata').value = dataURL;
                console.log(dataURL);
            };
        };

        function calculateSize(img, maxWidth, maxHeight) {
            let width = img.width;
            let height = img.height;

            // calculate the width and height, constraining the proportions
            if (width > height) {
                if (width > maxWidth) {
                    height = Math.round((height * maxWidth) / width);
                    width = maxWidth;
                }
            } else {
                if (height > maxHeight) {
                    width = Math.round((width * maxHeight) / height);
                    height = maxHeight;
                }
            }
            return [width, height];
        }
    </script>












</body>

</html>