<? include ("../settings.php"); ?>
<? include ("session.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Delegate Details</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script>
        function takeattendance(session){
            $("#session_id").val(session);
            $.ajax({
                type:"POST",
                url:"attendance_take_ajax.php",
                data:$("#delegate").serialize(),//only input
                success: function(response){
                    if (response != "1"){
                        alert(response);
						$('#myModal').modal('hide');
                    }else{
                        alert("Attendance Taken.");
                        $('#myModal').modal('hide');
                    }
                }
            });
        }
        
         function printnamebadge(){
            $.ajax({
                type:"POST",
                url:"reprintnamebadge.php",
                data:$("#delegate").serialize(),//only input
                success: function(response){
                    if (response != "1"){
                        alert(response);
                    }else{
                        alert("Reprinted.");
                    }
                }
            });
        }

        function removeattendance(session){
            $("#session_id").val(session);
            var ans = confirm("Are you sure you want to delete?");
            if (ans == true) {
                $.ajax({
                    type:"POST",
                    url:"attendance_remove_ajax.php",
                    data:$("#delegate").serialize(),//only input
                    success: function(response){
                        if (response != "1"){
                            alert(response);
                        }else{
                            alert("Attendance Removed.");
                            $('#myModal').modal('hide');
                        }
                    }
                });
            } 
        }

    </script>
   </head>
<body>
<div class="well">
<div class="content" bgcolor="#FFFFD0">
<div class="col-12 feature">
<div class="panelCheck">
    <div class="panel-heading">
        <h3 class "panel-title"><strong>Delegate Details</strong></h3>
    </div>

    <form name="delegate" id="delegate" method='POST' action="" enctype="multipart/form-data" class="form-horizontal" role="form">
    <center>
       
<?
    $bind = array(
        ":search1" => $_REQUEST['registrant_id']
    );
    $results = $db->select("tbl_registrant", "registrant_id = :search1", $bind);
    $result = $results[0];
    
    $tbind = array(":search1"=>$result['table_id']);
    $tresults = $db->select("tbl_table","tbl_id=:search1",$tbind);
    //print_r($tresults);
    $tresult = $tresults[0];
    
    $rbind = array(":search1"=>$result['role_id']);
    $rresults = $db->select("tbl_role","role_id=:search1",$rbind);
    $rresult = $rresults[0];
    $role = $rresult['role_name'];
    //<input type='text' class='form-control' id='datevisit' name='datevisit' value="=date("d-m-Y",strtotime ($row['datevisit']));">
?>        
<div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title">Delegate's' Particulars</h3>
      </div>
      <div class="panel-body">
        <div>
            <?
                $sessions = $db->select("tbl_session");
                foreach ($sessions as $session){
                    $bind = array(
                        ":search1" => $_REQUEST['registrant_id'],
                        ":search2" => $session['session_id']
                    );
                    $attend = $db->select("tbl_registrant_attendance", "registrant_id = :search1 AND session_id = :search2", $bind);
                    if (count($attend)>0){
                        $disabletake = "disabled";
                        $disableremove = "";
                    }else{
                        $disabletake = "";
                        $disableremove = "disabled";
                    }
                    ?>
                        <input type="button" class="btn btn-info" name="take" value="Take Attendance (<?=$session['session_name']?>)" onclick="takeattendance(<?=$session['session_id']?>);" <?=$disabletake;?>>&nbsp;&nbsp;&nbsp;
                        <input type="button" class="btn btn-danger" name="remove" value="Remove Attendance (<?=$session['session_name']?>)" onclick="removeattendance(<?=$session['session_id']?>);" <?=$disableremove;?>><br/><br/>
                    <?
                }

            ?>           
                <br/><br/><br/>

        </div>
		<div class='form-group'>
            <label for='registrant_type' class='col-lg-4 control-label'>Registrant Type</label>
            <div class='col-lg-6 text-left'>
                <?=$role;?>
            </div>
        </div> 		
        <div class='form-group'>
            <label for='role_id' class='col-lg-4 control-label'>Delegate Number</label>
            <div class='col-lg-4  text-left'>
                 <?=$result['registrant_sn'];?>           
            </div>
        </div> 
        <div class='form-group'>
            <label for='registrant_fullname' class='col-lg-4 control-label'>Full Name</label>
            <div class='col-lg-6 text-left'>
                <?=$result['registrant_fullname'];?>
            </div>
        </div>
        <div class='form-group'>
            <label for='registrant_organisation' class='col-lg-4 control-label'>Organisation</label>
            <div class='col-lg-6 text-left'>
                <?=$result['registrant_organisation'];?>
            </div>
        </div>
		<div class='form-group'>
            <label for='registrant_diet' class='col-lg-4 control-label'>Diet</label>
            <div class='col-lg-6 text-left'>
                <?=$result['registrant_diet'];?>
            </div>
        </div>
        <div class='form-group'>
            <label for='registrant_designation' class='col-lg-4 control-label'>Badge Colour</label>
            <div class='col-lg-6 text-left'>
                <?=$result['registrant_badgecolour'];?>
            </div>
        </div>
        <div class='form-group'>
            <label for='registrant_remarks' class='col-lg-4 control-label'>Remarks</label>
            <div class='col-lg-6 text-left'>
                <?=$result['remarks'];?>
            </div>
        </div>
    </div>       
    
     <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title">OFFICIAL USE</h3>
      </div>         
      <div class="panel-body">
        <div class='form-group'>
            <label for='role_id' class='col-lg-4 control-label'>Attended</label>
            <div class='col-lg-4  text-left'>
                 <?
                    $bind = array(
                        ":search1" => $_REQUEST['registrant_id']
                    );
                    $attend = $db->select("tbl_registrant_attendance", "registrant_id = :search1", $bind);
                    if (count($attend)>0){
                        echo "Yes (".date('h:ia - d M Y', strtotime($attend[0]['attendance_datetime'])).")";
                        $disabletake = "disabled";
                        $disableremove = "";
                    }else{
                        echo "No";
                        $disabletake = "";
                        $disableremove = "disabled";
                    }
                ?>           
            </div>
        </div>          
       
        <div>
            <?
                $sessions = $db->select("tbl_session");
                foreach ($sessions as $session){
                    $bind = array(
                        ":search1" => $_REQUEST['registrant_id'],
                        ":search2" => $session['session_id']
                    );
                    $attend = $db->select("tbl_registrant_attendance", "registrant_id = :search1 AND session_id = :search2", $bind);
                    if (count($attend)>0){
                        $disabletake = "disabled";
                        $disableremove = "";
                    }else{
                        $disabletake = "";
                        $disableremove = "disabled";
                    }
                    ?>
                        <input type="button" class="btn btn-info" name="take" value="Take Attendance (<?=$session['session_name']?>)" onclick="takeattendance(<?=$session['session_id']?>);" <?=$disabletake;?>>&nbsp;&nbsp;&nbsp;
                        <input type="button" class="btn btn-danger" name="remove" value="Remove Attendance (<?=$session['session_name']?>)" onclick="removeattendance(<?=$session['session_id']?>);" <?=$disableremove;?>><br/><br/>
                    <?
                }

            ?>           
                <input type="button" class="btn btn-success" name="reprint" value="Reprint Name Badge" onclick="printnamebadge();" >
                <br/><br/><br/>

        </div>   
    </div>
     </div>       
    <input type="hidden" name="registrant_id" value="<?php echo $result['registrant_id']; ?>">
    <input type="hidden" name="session_id" id="session_id" value="0">
    <input type="button" class="btn btn-info" name="take" value="Take Attendance" onclick="takeattendance();" <?=$disabletake;?>>&nbsp;&nbsp;&nbsp;
    <input type="button" class="btn btn-danger" name="remove" value="Remove Attendance" onclick="removeattendance();" <?=$disableremove;?>><br/><br/>
    <input type="button" class="btn btn-success" name="take" value="Print Name Badge" onclick="printnamebadge();" <?=$disableremove;?>><br/><br/>
    <input type="button" value="Close" class="btn btn-default" onclick="$('#myModal').modal('hide')">
    <br><br>        
        
    </center>
    <span>
    </span>
    </form>
</div>
</div>
</div>
</div>
</body>
</html>
    
    

<?

	function cleandata(&$inputarray){
		foreach ($inputarray as $key => $value) {
			if (!is_array($inputarray[$key]))
				$inputarray[$key]=htmlentities($value,ENT_QUOTES);
		}
	}

?>
