<?php

ob_start();

require("includes/check_auth_user.php");

require("includes/dbconnect.php");

include('includes/function.php');



$formname = 'Pending - To DO List';

$maindb = 'todo';

$trandb = 'todotran';

$bseries = $_SESSION["user_series"];



$file = 'followup_fr.php';



$admin = $_SESSION["admin_" . $dbname];

$zdb = $_SESSION["zdbyear_" . $dbname];

$myyear = $_SESSION[$myyear];



$zroot = $_SESSION["zdbroot"];



$username = $_SESSION["username_" . $dbname];



$getus = mysqli_query($conn, "select code from passmain where `user`='$username'");

$fetus = mysqli_fetch_array($getus);

$user = $fetus['code'];



mysqli_select_db($conn, $zdb) or die(mysqli_error($conn));





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

    $count = $_POST["items"];

//    browse($count);

    for ($i = 0; $i <= $count; $i++) {

        $vouchno = $_POST["vouchno_$i"];

        $remark = $_POST["remark_$i"];

        $done = $_POST["done_$i"];

        if ($done != "") {

            $querymain = mysqli_query($conn, "SELECT * FROM `todo` where vouchno = '$vouchno'") or die(mysqli_error($conn));

            $fetmain = mysqli_fetch_object($querymain)or die(mysqli_error($conn));

            $queryas = mysqli_query($conn, "SELECT * FROM $zroot.`passmain` where code = '$fetmain->assby'") or die(mysqli_error($conn));

            $fetass = mysqli_fetch_object($queryas)or die(mysqli_error($conn));

            $mobnum = $fetass->mobno;

            

            if ($mobnum != '') {



                $msgtech = "To Do List No $vouchno has been completed by $username Rapid Residency";



                $user = "RAPIDK";

                $password = "RAPIDK2022";

                $senderid = "RAPIDK";

//    $url = "144.76.39.175/api.php?";

                $url = "http://vas.mobilogi.com/api.php?";









                $mobilenumbers = $mobnum;



                $messagetech = urlencode($msgtech);



                $chtech = curl_init();

                if (!$chtech) {

                    die("Couldn't initialize a cURL handle");

                }

                $rettech = curl_setopt($chtech, CURLOPT_URL, $url);

                curl_setopt($chtech, CURLOPT_POST, 1);

                curl_setopt($chtech, CURLOPT_POSTFIELDS, "username=$user&password=$password&route=1&sender=$senderid&mobile[]=$mobilenumbers&message[]=$messagetech&templateid=1207164752002863129");



                $rettech = curl_setopt($chtech, CURLOPT_RETURNTRANSFER, true);



                $curlresponsetech = curl_exec($chtech);

                if (curl_errno($chtech)) {

//        echo 'curl error : ' . curl_error($chtech);

                }

                if (empty($rettech)) {



                    die(curl_error($chtech));

                    curl_close($chtech);

                } else {

                    $infotech = curl_getinfo($chtech);

                    curl_close($chtech);



//        echo $curlresponsetech;

                }

                $succ = true;

            } else {

                $succ = false;

            }

            

            mysqli_query($conn, "Update `todo` set remark1='$remark',done='$done' where vouchno = '$vouchno'");

        }

    }

}



include("includes/linkshead.php");

?>

<!--<script src="MyScript/service.js" type="text/javascript"></script>-->

</head>

<body>

    <form method="post">

        <!-- Default box -->

        <!-- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 pad"> -->

            <!-- <div class="panel panel-default"> -->
<!-- 
                <div class="panel-heading">

                    <h3 class="panel-title" style="color:#EF6D75"><?php Echo $formname; ?></h3>

                    <div class="actions pull-right">


                    </div>



                </div> -->



                <!-- <div class="panel-body"> -->

                    <!-- <div class="">

                        <input type="submit" name="submit" value="Update" class="btn btn-primary text-right" style="float: right;background-color: green">



                        <table id="dataTable" class="table table-bordered" style="width:100%">

                            <thead>

                                <tr  class="mySearchTr">

                                    <th style="width:5%;">Sr.</th>

                                    <th style="width:5%;">Voucher</th>

                                    <th style="width:15%;">Date</th>

                                    <th style="width:35%;">Task</th>

                                    <th style="width:10%;">Assigned By</th>

                                    <th style="width:30%;">Remarks</th>

                                    <th style="width:5%;">Done</th>

                                   

                                </tr>

                            </thead>

                            <tbody>

                                <?php

                                // $srchresult = mysqli_query($conn, "SELECT a.*,b.staff, DATE_FORMAT(a.`vouchdt`,'%d-%m-%Y') as vouchdt

                                //                                    FROM `$maindb` a, `$trandb` b  where a.vouchno = b.vouchno and b.`staff` = '$user'

                                //                                    and a.`done` != 'Y'")or die(mysqli_error($conn));

                                // $ctr = 1;

                                // $pctr = 0;

                                // while ($row = mysqli_fetch_array($srchresult)) {

                                //     $getas = mysqli_query($conn, "SELECT code,user FROM $zroot.`passmain`

                                //                                      WHERE code ='$row[assby]'") or die(mysqli_error($conn));

                                //     $fetas = mysqli_fetch_array($getas);

                                //     $remark = $row['remark1'] . '  ' . $row['remark2'];



                                //     echo "<tr>";

                                //     echo "<td style='padding-left: 30px;'>$ctr</td>";

                                //     echo "<td ><input type='hidden' name='vouchno_$pctr' value='$row[vouchno]'>$row[vouchno]</td>";

                                //     echo "<td >$row[vouchdt]</td>";

                                //     echo "<td >$row[task]</td>";

                                //     echo "<td >$fetas[user]</td>";

                                //     echo "<td ><input type='text' class='form-control' name='remark_$pctr' value='$row[remark1]' style='width:100%'></td>";

                                //     echo "<td style='padding-bottom:34px'><input type='checkbox' class='form-control' name='done_$pctr' value='Y' style='width:25px;height:25px;padding-bottom:2%'></td>";


                                //     echo "</tr>";

                                //     $ctr++;

                                //     $pctr++;

                                // }

                                ?> 

                            </tbody>

                        </table>

                        <input type="hidden" name="items" value="<?= $pctr ?>">



                    </div> -->

                <!-- </div> -->

            <!-- </div> -->

        <!-- </div> -->



        <!--task given-->

        <!-- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 pad">

            <div class="panel panel-default">

                <div class="panel-heading">

                    <h3 class="panel-title" style="color:#EF6D75">Task Given</h3> -->

                    <!--                    <div class="actions pull-right">

                                            <i class="fa fa-chevron-down"></i>

                                            <input type="submit" name="submit" value="Update" class="btn btn-success" >

                                        </div>-->



                <!-- </div>



                <div class="panel-body">

                    <div class="">

                        <table id="example1" class="table table-bordered" style="width:100%">

                            <thead>

                                <tr class="mySearchTr">

                                    <th style="width:5%;">Sr.</th>

                                    <th style="width:5%;">Voucher</th>

                                    <th style="width:15%;">Date</th>

                                    <th style="width:35%;">Task</th>

                                    <th style="width:10%;">Assigned To</th>

                                    <th style="width:30%;">Remarks</th> -->

                                    <!--                                    

                                                                        <th style="width:10%;">Action</th>-->

                                <!-- </tr>

                            </thead>

                            <tbody> -->

                                <?php

//                                 $srchresult2 = mysqli_query($conn, "SELECT a.*,b.staff, DATE_FORMAT(a.`vouchdt`,'%d-%m-%Y') as vouchdt

//                                                                    FROM `$maindb` a, `$trandb` b  where a.vouchno = b.vouchno and a.`assby` = '$user'

//                                                                    and a.`done` != 'Y'")or die(mysqli_error($conn));

//                                 $ctr2 = 1;

//                                 $pctr2 = 0;

//                                 while ($row2 = mysqli_fetch_array($srchresult2)) {

//                                     $getas2 = mysqli_query($conn, "SELECT code,user FROM $zroot.`passmain`

//                                                                      WHERE code ='$row2[staff]'") or die(mysqli_error($conn));

//                                     $fetas2 = mysqli_fetch_array($getas2);

//                                     $remark2 = $row2['remark1'] . '  ' . $row2['remark2'];



//                                     echo "<tr>";

//                                     echo "<td style='padding-left: 30px;'>$ctr2</td>";

//                                     echo "<td >$row2[vouchno]</td>";

//                                     echo "<td >$row2[vouchdt]</td>";

//                                     echo "<td >$row2[task]</td>";

//                                     echo "<td >$fetas2[user]</td>";

//                                     echo "<td >$row2[remark1]</td>";

// //                                    echo "<td align='left'><a href=\"$file?mode=edit&$keyfld=$row[vouchno]\"><img src='images/edit.png'></a>&nbsp;&nbsp;&nbsp;&nbsp;</td>";

//                                     echo "</tr>";

//                                     $ctr++;

//                                     $pctr++;

//                                 }

                                ?> 

                            <!-- </tbody>

                        </table>

                        <input type="hidden" name="items" value="<?= $pctr ?>">



                    </div>

                </div>

            </div>

        </div> -->

    </form>

    <?php include("includes/linksfoot.php"); ?>

</body>

</html>

