

<?php 
if(!empty($_POST['infregid'])){
  $officeid=$_REQUEST['officeid'];  
  $infregid=$_REQUEST['infregid'];
 ######## CON ########
 $userSent = $_REQUEST['userSent'];
 $sentAppoint = $_REQUEST['sentAppoint'];
 $DeptSent = $_REQUEST['DeptSent'];
 $tskcom = $_REQUEST['tskcom'];
 
 $dueDate = date('Y-m-d');
 $today = date('Y-m-d H:i:s');
 $year= date('Y');

 foreach($officeid as $value)
 {
     if ($value<>0)
     {

         $stmt = $db->prepare("INSERT INTO tbl_con_infos (reg_info_id, dSent, appntsent, iSd,info_sts,conTrm,dRcv,recvappnt,iRcv,dueCon,con_doctype) VALUES(?,?,?,?,?,?,?,?,?,?,?)");
         $stmt->execute(array($infregid, $DeptSent, $sentAppoint,$userSent,2,$today,$value,0,0,$dueDate,3));
     }
 }

    $update = $db->prepare("UPDATE `tbl_info_register` SET tsknotes='".$tskcom."',stts_reg=5 WHERE `regst_id`='".$infregid."' ");
    $update->execute();
    
    echo'<script type="text/javascript">
        jQuery(function validation(){
        swal("Successfully", "Request Assigned!", "success", {
        button: "Continue",
        });
        });
    </script>';
  
} // CoN

####### CANCEL ORDER #######
if(isset($_REQUEST['cancereq'])){
    $regid=$_REQUEST['regid'];

    $upte = $db->prepare("UPDATE `tbl_info_register` SET stts_reg=7 WHERE `regst_id`='".$regid."' ");
    $upte->execute();

    echo'<script type="text/javascript">
        jQuery(function validation(){
        swal("Oooh Snap", "Request Cancelled!", "error", {
        button: "Continue",
        });
        });
    </script>';
}

?>
<br>

<form class="form-horizontal" id="" method="POST" action="" autocomplete="off">
    <input type="hidden" name="userSent" value="<?php echo $userid;?>" required style="width: 90%;">
    <input type="hidden" name="sentAppoint" value="<?php echo $tle_id;?>" required style="width: 90%;">
    <input type="hidden" name="DeptSent" value="<?php echo $role_id;?>" required style="width: 90%;">

    <table class="table table-hover w-100" style="font-size: 11px;">
        <thead class="thead-themed">
            <tr>
                <th style="font-weight: bold;width: 5px;"></th>
                <th style="font-weight: bold;">TRACKING CODE</th>
                <th style="font-weight: bold;">CLIENT NAME</th>
                <th style="font-weight: bold;">SUBJECT MATTER</th>
                <th style="font-weight: bold;">REQUEST DATE</th>
                <th style="font-weight: bold;">TYPE</th>
                <th style="font-weight: bold;width: 12%;">ATTACHMENT</th>

                <?php 
                if($pvge==1){
                ?>
                <th style="font-weight: bold;">ACTION</th>
                <?php }?>
            </tr>
        </thead>

        <tbody>
            <?php 
             ####### FETCH ######
            $stmtReq = $db->prepare('SELECT *FROM tbl_info_register i
            INNER JOIN tbl_clients c ON c.ct_id=i.clnt_id 
            INNER JOIN tbl_reqs_type r ON r.reqtype_id=i.reqtype
            WHERE reg_dept="'.$role_id.'" AND i.doctype=3 AND i.stts_reg=1 ORDER BY regst_id DESC');
            $stmtReq->execute();
            while($ffReq = $stmtReq->fetch()){
                $regstid = $ffReq['regst_id'];

                $stts_reg=$ffReq['stts_reg'];
                $stsQue = $db->prepare('SELECT *FROM tbl_status WHERE status_id="'.$stts_reg.'"');
                $stsQue->execute();
                $getSts=$stsQue->fetch();
   
               if($stts_reg == 1){
                   $icon='<i class="fa fa-exclamation-circle" aria-hidden="true"></i>';
                   $btn='btn-warning';
               }elseif($stts_reg == 5){
                   $icon='<i class="fa fa-check" aria-hidden="true"></i>';
                   $btn='btn-success';
               }else{
                   $icon='<i class="fa fa-folder-open" aria-hidden="true"></i>';
                   $btn='btn-default';
               }
            ?>
            <tr class="b-tr">
                <td>
                    <div class="custom-control custom-radio">
                        <input type="radio" name="infregid" value="<?php echo $regstid;?>" class="custom-control-input active" id="<?php echo $regstid;?>">
                        <label class="custom-control-label" for="<?php echo $regstid;?>"></label>
                    </div>
                </td>

                <td>
                    <?php echo $ffReq['track_id'];?><br>
                    <label class="btn <?php echo $btn;?> btn-xs" style="font-weight: bold;"><?php echo  $icon." ".$getSts['status_name'];?></label>
                </td>
                <td><?php echo $ffReq['ct_names'];?></td>
                <td><?php echo $ffReq['sub_matt'];?></td>
                <td><?php echo date('d/m/Y',strtotime($ffReq['requestDate']));?></td>
                <td><?php echo "REQUEST FOR ".$ffReq['reqtype_name'];?></td>  

                <td class="text-left">
                   <?php 
                    $i=0;
                    $select = $db->prepare("SELECT * FROM `tbl_docs` WHERE registID = '".$regstid."' ORDER BY doc_id DESC");
                    $select->execute(); 
                    while($row = $select->fetch()){
                         $doc_id = $row['doc_id'];
                         $uploaded_on = $row['uploaded_on'];
                         $docName = $row['docName'];
                         $rec_dpt = $row['rec_dpt'];
                         $usID = $row['usID'];
                         $stts_doc = $row['stts_doc'];
                         $i++;
                         
                         //Hide Extension
                         $file = new SplFileInfo($docName);
                         $ext  = $file->getExtension();
                         //Get File Name
                         $fileName = basename($docName);
                         $fileNameNoExtension = preg_replace("/\.[^.]+$/", "", $fileName);

                         //DOC ICON
                         if($ext == "pdf"){
                            $imgIcon = "pdf.png";
                         }if($ext == 'xls' || $ext == 'xlsx'){
                            $imgIcon = "excel.png";  
                         }if($ext == 'doc' || $ext == 'docx'){
                             $imgIcon = "docx.png";
                         }if($ext == 'ppt' || $ext == 'pptx'){
                             $imgIcon = "pptx.png";
                         }if($ext == 'zip' || $ext == 'rar' || $ext == 'tar'){
                            $imgIcon = "zip.png";
                        }
                   ?>                    
                    <a href="../docs/<?php echo $docName;?>">
                        <img src="../img/icon/<?php echo $imgIcon;?>" width="30" title="<?php echo $docName;?>">
                    </a> 
                   <?php 
                    }
                   ?>
                </td>

                <?php 
                if($pvge==1){
                ?>

                <td>
                <button type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#btncancel_<?php echo $regstid;?>" 
                    style="border-radius: 4px;" title="Cancel Request"><i class="fa fa-times" aria-hidden="true"></i></button>
                </td>
                <?php }?>
            </tr>
            
        <?php 
            include 'cancelReq.php';
          }
        ?>
        </tbody>                           
    </table>

    <hr>  
    <?php 
    if($pvge==1){
    ?>  
    <div class="row">
        <label class="col-md-1"><b>Department: </b></label>
        <div class="col-sm-3">
            <select multiple="multiple" id="multiple-basic" name="officeid[]" data-placeholder="~select dept~"
                class="select2 form-control border-top-0 border-left-0 border-right-0 px-0 rounded-0 fs-md mt-2 pr-5" tabindex="2">                            
                <?php
                $stmt = $db->query('select * from tbl_role');

                    try
                    {
                        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                            ?>
                                <option value="<?php echo $row['role_id']; ?>"><?php echo $row['role_name']; ?></option>
                            <?php
                            }
                        }
                        catch (PDOException $ex) {
                        //Something went wrong rollback!
                        echo $ex->getMessage();
                    }
                ?>	
            </select>
        </div>    
        
        <label class="col-md-1"><b>Comment: </b></label>
        <div class="col-sm-3">
            <textarea type="text" name="tskcom" rows="2" class="form-control" placeholder="Write comment..." required></textarea>
        </div>
    </div>

    <button type="submit" name="btnAssign" class="btn btn-primary btn-sm"style="border-radius: 4px;font-weight: bold;" 
    title="Assign to head office"><i class="fa fa-check" aria-hidden="true"></i> Assign</button>  
    <?php }?>
</form>
