<?php
include_once "./header.php";
require 'app/config.php';

$stmt = $db->prepare("SELECT * FROM phone  WHERE status = ?");
$stmt->execute(["completed"]);

$row = $stmt->fetch();

while ($row = $stmt->fetch()) {
    
    
}
?>

<body>
    <input type="hidden" placeholder="default" id="pdpDefault" pdp-id="pdp-6317423" class="pdp-el">
    <div class="fluid-container data-form" style="display: none;">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <span id="close-form" onclick="close_form()">
                    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB7ElEQVR4nO2Z3UrDMBTH81Amft01012oCOKt+BAqKA4miCJ44Y0PIIj4id6IdzrfwyFDbzargjYbrZVFWtexuXY2TZN0kD+cu5X9fzkn56QNAFpaWlqZVh2jWWKge8tAhGBEZYTl/ZcBS3VjaIbLvIXRjizTJAoGw63kK6/YPGkHnGYG8MomQwB37AAYWhkC+EwAoNo06goNQKJWJz9GSW54QDOQH6ffN9fUPT1ihrALK36oA2iZp+a7HywQ9voSpVWT0tortTfW1AC4Z8dt80F8HR78C9E2HzxXiweROkBjYY42H8o9EP0y0WPebAEUV9XsARYIHvNEZBuNA8FrnoieA/0g7MIyt3kiY5BFQdCXN27zRNYkjoTgNE9kHiV8iMpTaCbsYryeT1QC+Bu29qfmgz1xwj6xiUyA0G6TEgQQDRDVKpuV51QggEiAfn0+ssUyQgBRAHGGVBoQQAQAy4TlhQBpAyQ5HjQW52mz/Bh+isWSAdyri24jVTPWC0pYJpz9PQUlNDFC3cvzRBO2E8KJYV7cJp4c9TPB8mrYWU7O7nbs34sBkBhAA+CBywDMzqdFA36wAxiwpNw4DgLeMgN4lwvqjaPfyKEpkETe5YJq85aBNgGPvMsF7/u83D0BLa9sEq+8lpaWFpClH85QF54vuUIVAAAAAElFTkSuQmCC" alt="close-window">
                </span>
                <h1 class="text-center mt-3">یادآور</h1>

                <form method="post" class="m-4" id="main-form" action="form.php">
                    <div class="form-group">
                        <label for="phone">شماره تلفن</label>
                        <input type="text" class="form-control" id="phone" name="phone" value="09140790345">
                        <!-- Help separar por comas varios emails 
                        <small id="emailHelp" class="form-text text-muted">Separar por comas varios emails.</small>-->
                    </div>
                    <!-- <div class="form-group">
                        <label for="frequency">Frecuencia (cada cuantos dias):</label>
                        <input type="number" class="form-control" id="frequency" name="frequency">
                    </div> -->
                    <div class="form-group">
                        <label for="send_time">تاریخ</label>
                        <input type="text" class="form-control" id="send_time" name="send_time">
                        <input type="hidden" class="form-control" id="gsend_time" name="gsend_time">
                        <input type="time" id="time" class="time-picker" name="time" data-coreui-toggle="time-picker">
                    </div>
                    <div class="form-group">
                        <label for="massage">متن پیامک:</label>
                        <textarea class="form-control" id="massage" name="massage" rows="10"></textarea>
                    </div>
                    <select id="pattern_code" name="pattern_code" class="form-select form-select-sm" aria-label=".form-select-sm example">
                        <option value="" >انتخاب ارسال پیشفرض</option>
                        <option value="oyskgvtnua2ve0q"  >پیامک یادآور آبیاری</option>

                    </select>
                    <span class="btn btn-warning m-3" id="send-test" >تست ارسال متن</span>
                    <button type="submit" class="btn btn-primary ">تنظیم</button>
                </form>


                <div id="editForm" style="display: none;">
                    <div class="card">
                        <div class="card-body">
                            <h2>Editar Email Reminder</h2>
                            <form>
                                <input type="hidden" id="editId">
                                <label for="editEmail">Email:</label><br>
                                <input type="text" id="editEmail" class="form-control"><br>
                                <label for="editFrequency">Frequency:</label><br>
                                <input type="text" id="editFrequency" class="form-control"><br>
                                <label for="editTemplate">Template:</label><br>
                                <textarea id="editTemplate" class="form-control" rows="10"></textarea><br>
                                <button type="button" onclick="submitEdit()" class="btn btn-success">Edit</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal" id="result-notice" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header justify-content-end ">
                    <div class="alert alert-success " role="alert">
                        موفق
                    </div>
                </div>
                <div class="modal-body text-success text-center">
                    <p>با موفقیت تنظیم شد</p>
                </div>

            </div>
        </div>
    </div>

    <script src="js/jquery-1.10.1.min.js"></script>
    <script src="js/persianDatepicker.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    <script src="js/main.js"></script>
    <script>
        $(function() {
            //usage
            $("#send_time").persianDatepicker({
                theme: "latoja",
                cellWidth: 14,
                cellHeight: 2,
                fontSize: 12,
                formatDate: "YYYY/MM/DD hh:mm:ss"
                
            });

            //themes
            $("#pdpDefault").persianDatepicker({
                alwaysShow: true,
                formatDate: "YYYY/MM/DD hh:mm:ss"
            });








        });
    </script>
    <?php
    $stmt_complete = $db->prepare("SELECT * FROM phone  WHERE status = ?");
$stmt_complete->execute(["completed"]);

$row = $stmt_complete->fetch();

while ($row = $stmt_complete->fetch()) {
    
   
    ?>
    <div class="completed-remider" data-complete=<?php  echo explode(" ",$row["send_time"])[0]; ?> style="display:none;"></div>
    <?php
    
}
   $stmt_pending = $db->prepare("SELECT * FROM phone  WHERE status = ?");
$stmt_pending->execute(["pending"]);

$row = $stmt_pending->fetch();

while ($row = $stmt_pending->fetch()) {
    
   
    ?>
    <div class="pending-remider" data-complete=<?php  echo explode(" ",$row["send_time"])[0]; ?> style="display:none;"></div>
    <?php
    
}
?>
   <script>
       function date_status(){
   setTimeout(function() {
      let completed_date= $(".completed-remider");
     let completed_day_el;
     
     completed_date.each(function() {
    completed_day_el=$(this).attr("data-complete").split("-")
    completed_day_el[1]=completed_day_el[1].charAt(0).replace("0", "").concat(completed_day_el[1].charAt(1));
    completed_day_el[2]=completed_day_el[2].charAt(0).replace("0", "").concat(completed_day_el[2].charAt(1));
    completed_day_el= completed_day_el.toString();
    completed_day_el=completed_day_el.replaceAll(",", "/");
   
     
   $(".day.cell[data-gdate='"+ completed_day_el +"']").addClass("bg-success");
  
   
  
  

});
}, 1000);
    setTimeout(function() {
      let pending_date= $(".pending-remider");
     let pending_day_el;
     
     pending_date.each(function() {
    pending_day_el=$(this).attr("data-complete").split("-")
    pending_day_el[1]=pending_day_el[1].charAt(0).replace("0", "").concat(pending_day_el[1].charAt(1));
    pending_day_el[2]=pending_day_el[2].charAt(0).replace("0", "").concat(pending_day_el[2].charAt(1));
    pending_day_el= pending_day_el.toString();
    pending_day_el=pending_day_el.replaceAll(",", "/");
   
     if($(".day.cell[data-gdate='"+ pending_day_el +"']").hasClass("bg-success")){
         
     }else{
         $(".day.cell[data-gdate='"+ pending_day_el +"']").addClass("bg-warning");
     }
   
  
   
  
  

});
}, 1000);
}
   </script>
</body>

</html>