    
<?php 
    $conid=$_REQUEST['con'];
    $nowdue = date('Y-m-d H:i:s');
    $queCon = $db->prepare('SELECT *FROM tbl_info_register i
    INNER JOIN tbl_con_infos cn ON cn.reg_info_id=i.regst_id 
    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 cn.con_info_id="'.$conid.'"');
    $queCon->execute();
    while($ffCon = $queCon->fetch()){
    $regstid = $ffCon['regst_id'];  
    $appntsent= $ffCon['appntsent']; 
    $stats = $ffCon['info_sts'];
    ### RECEIVE DETAILS ####### 
    $snder = $db->prepare("SELECT * FROM tbl_role r
    INNER JOIN tbl_title t ON t.department_id = r.role_id 
    WHERE t.title_id ='".$appntsent."'");  
    $snder->execute();
    $viewSnder = $snder->fetch();
 
    $roleNam = $viewSnder['role_name'];
    $tileNam = $viewSnder['title_name'];
     
    ### RECEIVE DETAILS #######

    ###### ACTION #####
    if($stats==2){
        $upd = $db->prepare("UPDATE `tbl_con_infos` SET `info_sts`=9,`recvappnt`='".$tle_id."',`iRcv`='".$userid."',`receivTrm`='".$nowdue."'
         WHERE `con_info_id`='".$conid."' ");
        $upd->execute();

        $upd2 = $db->prepare("UPDATE `tbl_info_register` SET `stts_reg`=9 WHERE `regst_id`='".$regstid."' ");
        $upd2->execute();
    }
?>

<div class="subheader">
    <h1 class="subheader-title" style="font-weight: bold;">
        <i class='subheader-icon fa fa-eye text-primary'></i><?php echo $title;?> 
    </h1>
    <div class="d-flex mr-4">
    <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
    </div>
</div>

<form  class="form-horizontal" id="" method="POST" action="" autocomplete="off">
<div class="card mb-g border shadow-0">
    <div class="card-header bg-white p-0 header">
        <div class="p-3 d-flex flex-row">
            <div class="d-block ml-2">
                <span class="h6 font-weight-bold text-uppercase d-block m-0">
                    <?php echo $ffCon['sub_matt'];?>
                </span>
                <div class="clearfix"></div>  
            </div>
        </div>
    </div>

    <div class="card-body ">

    <div class="row">
        <div class="col-lg-6 col-xl-3 order-lg-1 order-xl-1">
            <!-- REQUEST SUMMARY -->
            <div class="card mb-g rounded-top">
                <div class="row no-gutters row-grid">
                    
                    <div class="col-6">
                        <div class="text-center py-3">
                            <h5 class="mb-0 fw-700">
                                Request For
                                <i><small class="text-muted mb-0"><?php echo $ffCon['reqtype_name'];?></small></i>
                            </h5>
                        </div>
                    </div>

                    <div class="col-6">
                        <div class="text-center py-3">
                            <h5 class="mb-0 fw-700">
                                Client
                                <i><small class="text-muted mb-0"><?php echo $ffCon['ct_names'];?></small></i>
                            </h5>
                        </div>
                    </div>

                    <div class="col-12">
                        <div class="p-3 text-center">
                            <a href="javascript:void(0);" class="font-weight-bold">Request Date</a> 
                            <span class="text-primary d-inline-block mx-3"><?php echo date('d/M/Y',strtotime($ffCon['requestDate']));?></span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- END REQUEST SUMMARY -->

            <!-- Support Docs -->
            <div class="card mb-g">
                <div class="row row-grid no-gutters">
                    <div class="col-12">
                        <div class="p-3">
                            <h2 class="mb-0 fs-xl">
                                Supporting Docs
                            </h2>
                        </div>
                    </div>
                    
                    <div class="row">
                    <?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;?>" class="text-center d-flex position-relative" title="<?php echo $docName;?>">
                         <img src="../img/icon/<?php echo $imgIcon;?>" width="80" style="padding: 10px;margin-left: 10px;" title="<?php echo $docName;?>">
                        </a>
                  
                    <?php 
                    }
                   ?>
                              
                    <br>
                </div>

                </div>
            </div>
            <!--End Support Docs -->                                
        </div>

        
       
        <!-- PROCEED -->
        <div class="col-lg-12 col-xl-6 order-lg-3 order-xl-2">
            <div class="card border mb-g">
          
                <div class="col-12">
                    <div class="p-3 header">
                        <h2 class="mb-0 fs-xl">
                          <i class="fa fa-plus-circle" aria-hidden="true"></i> Assignment Form                    
                        </h2>
                    </div>
                </div>
                <br>

                <div class="card-body pl-4 pt-4 pr-4 pb-0">
                    <div class="d-flex flex-column">
                        <br>
                            <div class="row">
                            <div class="col-md-1"></div>
                                <input type="hidden" name="conctid" value="<?php echo $conid;?>">
                                <input type="hidden" name="regid" value="<?php echo $regstid;?>">
                               
                                <label class="col-md-3"><b>Assign to:<span class="required" style="color:red">*</span> </b></label>
                                <div class="col-sm-5">
                                    <select multiple="multiple" id="multiple-basic" name="assignto_ids[]" data-placeholder="~select appointment~"
                                        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_title where department_id="'.$role_id.'" AND title_id!="'.$tle_id.'" AND tpvge=2');

                                            try
                                            {
                                                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                                    ?>
                                                        <option value="<?php echo $row['title_id']; ?>"><?php echo $row['title_name']; ?></option>
                                                    <?php
                                                    }
                                                }
                                                catch (PDOException $ex) {
                                                //Something went wrong rollback!
                                                echo $ex->getMessage();
                                            }
                                        ?>	
                                    </select>
                                </div>
                            </div>
                            
                            <br>
                            <div class="row">
                            <div class="col-md-1"></div>

                                <label class="col-md-3"><b>Status:<span class="required" style="color:red">*</span> </b></label>
                                <div class="col-sm-5">
                                    <select class="select2 form-control w-100" name="assgnSts" id="assgnSts" data-placeholder="-choose status-" required>
                                        <option></option>
                                        <?php
                                            $stmt = $db->query('SELECT *FROM tbl_status WHERE status_id=11 ORDER BY status_id ASC');
                                            try
                                            {
                                                while ($rrr = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                                ?>
                                                    <option value="<?php echo $rrr['status_id']; ?>"><?php echo $rrr['status_name']; ?></option>
                                                <?php
                                                }
                                                }
                                                catch (PDOException $ex) {
                                                //Something went wrong rollback!
                                                echo $ex->getMessage();
                                            }
                                        ?>	
                                    </select>
                                </div>
                            </div>
                            <br>

                            <div class="row">
                            <div class="col-md-1"></div>

                                <label class="col-md-3"><b>Project:<span class="required" style="color:red">*</span> </b></label>
                                <div class="col-sm-5">
                                    
                                    <select class="select2 form-control w-100" name="prjc" id="prjc" data-placeholder="-select project-" required>
                                        <option></option>
                                            <?php
                                                $sth = $db->query('SELECT * FROM tbl_projects WHERE prjsts != 10 ORDER BY projid DESC');
                                                try
                                                {
                                                    while ($rr2 = $sth->fetch(PDO::FETCH_ASSOC)) {
                                                    ?>
                                                        <option value="<?php echo $rr2['projid']; ?>"><?php echo $rr2['codeproj']; ?></option>
                                                    <?php
                                                    }
                                                    }
                                                    catch (PDOException $ex) {
                                                    //Something went wrong rollback!
                                                    echo $ex->getMessage();
                                                }
                                            ?>	
                                    </select>     
                                </div>
                            </div>
                            <br>
  
                            <div class="row">
                            <div class="col-md-1"></div>

                                <label class="col-md-3"><b>Comment:<span class="required" style="color:red">*</span> </b></label>
                                <div class="col-sm-5">
                                    <textarea type="text" name="tskcom" rows="2" class="form-control" placeholder="Write comment..." required></textarea>
                                </div>
                            </div>
                            <br>
                       <!-- form -->
                    </div>
                </div>
            </div>  
        </div>
        <!--  PROCEED -->
      
        <div class="col-lg-6 col-xl-3 order-lg-2 order-xl-3">
            <!-- SENDER SUMMARY -->
             <div class="card mb-g rounded-top">
                <div class="row no-gutters row-grid">
                    
                    <div class="col-6">
                        <div class="text-center py-3">
                            <h5 class="mb-0 fw-700">
                                Department From
                                <i><small class="text-muted mb-0"><?php echo $roleNam;?></small></i>
                            </h5>
                        </div>
                    </div>

                    <div class="col-6">
                        <div class="text-center py-3">
                            <h5 class="mb-0 fw-700">
                                Appointment
                                <i><small class="text-muted mb-0"><?php echo $tileNam;?></small></i>
                            </h5>
                        </div>
                    </div>

                    <div class="col-12">
                        <div class="p-3 text-center">
                            <a href="javascript:void(0);" class="font-weight-bold">Assigned Date</a> 
                            <span class="text-primary d-inline-block mx-3"><?php echo date('d/M/Y',strtotime($ffCon['dueCon']));?></span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- END SENDER SUMMARY -->        

            <!-- add : -->
            <div class="card mb-2">
                <div class="card-body">
                    <a href="javascript:void(0);" class="d-flex flex-row align-items-center">
                        <div class='icon-stack display-3 flex-shrink-0'>
                            <i class="fa fa-circle icon-stack-3x opacity-100 color-primary-600"></i>
                            <i class="fa fa-comment icon-stack-1x opacity-100 color-primary-500" style="color: #fff;"></i>
                        </div>
                        <div class="ml-3">
                            <strong>
                             Task Note
                            </strong>
                            <br>
                            <?php echo $ffCon['tsknotes'];?>
                        </div>
                    </a>
                </div>
            </div>                          

        </div>

    </div>

    </div>

    <div class="card-footer">
        <div class="d-flex align-items-center">
            <span class="text-sm text-muted font-italic">

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

                <div class="alert alert-info" role="alert" id="asgnAlert" style="display: none;">
                    <strong><b>Well Done!</b></strong> You have already assign.
                </div>
            </span>
            <a href="gate?b=getmytsk" class="flex-shrink-0 ml-auto" style="font-weight: bold;">Go back <i class="fa fa-mail-reply ml-2"></i> </a>
        </div>
    </div>
</div>  
</form>
        
<?php  }?>



<script>
//  SAVE ORDER
    $(document).ready(function(){
    $('#asgnAlert').hide();   
    $("#btnreqAssign").show();
    $("#savereq_asgn").submit(function(e){
        e.preventDefault();

    var formdata = new FormData(this);
    $.ajax({
        url: "savereq_asgn",
        type: "POST",
        data: formdata,
        mimeTypes:"multipart/form-data",
        contentType: false,
        cache: false,
        processData: false,
        success: function(formData){
        $('#asgnAlert').show();    
        $("#btnreqAssign").hide();
        pop_up_request(formData);
        },error: function(){
            alert("okey");
        }
        });
    });
      
    // Notification  
    function pop_up_request(feedback) {
    jQuery(function validation(){
    swal("Well done.", "Assigned Successfully!", "success", {
    button: "ok",
      });
    });
    }

   });

</script>
