<?
include getenv("DOCUMENT_ROOT")."/include/session_include.php";

$func->checkLevelModal(9);

$uid = trim($_GET["uid"]);
$orderdate = str_replace("-", "", trim($_GET["orderdate"]));
$customeruid = trim($_GET["customeruid"]);

if ($mode == "") {
		$mode = "update";
		$btnName = "UPDATE";
		$admTag = "DISABLED";
}

if($uid == "") {
		/*
		$msg = "Invalid Parameter. Please try again.";
		$func -> modalMsg ($msg, 1);
		echo "
			<script language=javascript>
			window.close();
			</script>";	
		exit();
		*/

		$setDisplayNEWStr = " DISPLAY:none; ";
		$setDisplayBTNStr = " DISPLAY:block; ";
		$setDisplaySIGNYESStr = " DISPLAY:none; ";
		$setDisplaySIGNNEWStr = " DISPLAY:inline; ";
			
} else {

		$qry_cnt = "SELECT COUNT(*) FROM tbl_daily WHERE d_uid = '".$uid."' ";
		$total_count=$jdb->rQuery($qry_cnt, "record query error");
							
		if ($total_count > 0) {
				// Get Information
				$query = "SELECT * FROM tbl_daily WHERE d_uid = '".$uid."' ";
				$result=$jdb->fQuery($query, "fetch query error");
				//	echo"$query";

				for($i=0; $i<sizeof($result); $i++)
				{
					//list($key, $value) = each($result);
					foreach ( (Array) $result as $key => $value )			
						$$key = $value;
				}

				$d_orderdateSTR = $func -> convertFormat ($d_orderdate, 3);
				$d_payeenameSTR = str_replace("\\", "", $d_payeename);
				
				$folderPath = getenv("DOCUMENT_ROOT")."/upload_sign/".$d_customeruid;
		}
		
		
		if (is_file($folderPath."/".trim($d_payeesign))) {
			$d_payeesignSTR = "<img style='border:1px solid;' src='/upload_sign/".$d_customeruid."/".$d_payeesign."'>";
			$setDisplayNEWStr = " DISPLAY:inline; ";
			$setDisplayBTNStr = " DISPLAY:none; ";
			$setDisplaySIGNYESStr = " DISPLAY:inline; ";
			$setDisplaySIGNNEWStr = " DISPLAY:none; ";			
		}
		else {
			$setDisplayNEWStr = " DISPLAY:none; ";
			$setDisplayBTNStr = " DISPLAY:block; ";
			$setDisplaySIGNYESStr = " DISPLAY:none; ";
			$setDisplaySIGNNEWStr = " DISPLAY:inline; ";
		}		

	
}


?>

<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Green Oil Inc. Intranet System</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="assets/img/cropped-green-oil-favicon-192x192.png" rel="icon">
  <link href="assets/img/cropped-green-oil-favicon-192x192.png" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,600;1,700&family=Amatic+SC:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&family=Inter:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <!--link href="/assets/vendor/aos/aos.css" rel="stylesheet"-->
  <link href="/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="/assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="/assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
  <link href="/assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="/assets/css/main.css" rel="stylesheet">
  <link href="/assets/css/table-style.css" rel="stylesheet">

  
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

  <!-- jQuery JS -->
  <script src="/assets/js/vendor/jquery-3.3.1.min.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>


  
<!--link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.css"-->
<!--link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/south-street/jquery-ui.css" rel="stylesheet"--> 
<script type="text/javascript" src="/assets/js/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript" src="/assets/js/jquery.signature.min.js"></script>
<link rel="stylesheet" type="text/css" href="/assets/css/jquery.signature.css">


<style>
    .kbw-signature { width: 340px; height: 120px;}
    #sig canvas{
        /*width: 100% !important;*/
        width: 100%;
        height: auto;
        border-bottom: 1px solid #BCBBBB;
    }

	.btn-clear{
	  color: #fff;
	  background: #BCBBBB;

	  border-radius: 5px;
	  border: 1px solid #BCBBBB;
	  float:right;
	}

</style>





<main id="main" class="main">

   <section class="page">


      <div class="container" data-aos="fade-up">

<FORM NAME=signaturepopup id=signaturepopup METHOD=POST ACTION="/lib/user_process.php">
    	<input type=hidden name=actionStr value="SIGNATURE">
    	<input type=hidden name=actionPage value="">
    	<input type=hidden name=uid id=uid value="<?=$uid?>">
    	<input type=hidden name=orderdate id=orderdate value="<?=$orderdate?>">
    	<input type=hidden name=customeruid id=customeruid value="<?=$customeruid?>">
		<input type=hidden name=customerno id=customerno value="<?=$customerno?>">
			<input type=hidden name=mode id=mode value="update">

<? if (trim($d_payeesign) != "") { ?>
			<input type=hidden name=d_payeesign id=d_payeesign value="<?=$d_payeesign?>">
<? }?>

            <table class="td-search">
              <!--tr>
                <td>
                  <span class="config-icon-box"><i class="bi bi-arrow-right"></i></span>Customer Name
                </td>
                <td>               
                   <input type="text" id="d_payeename" name="d_payeename" value="<?=htmlspecialchars($d_payeenameSTR, ENT_QUOTES)?>" placeholder="Customer Name" >
                </td>
              </tr-->

              <tr>
                <td colspan=2>
                  <span class="config-icon-box"><i class="bi bi-arrow-right"></i></span>Customer Signature
	                		<div id="newbtnid" style="<?=$setDisplayNEWStr?> float:right; padding-right: 10px;">New <input type="checkbox" id="signednew" name="signednew" value="1" ></div>
	                		<div id="clrbtnid" style="<?=$setDisplayBTNStr?> float:right; padding-right: 10px;padding-bottom: 10px;"><button id="clear" class="btn-clear">Clear</button></div>                  
                </td>
              </tr>
              <tr>
                <td colspan=2>              
							        <div id="signitureedid" style="<?=$setDisplaySIGNYESStr?>">
							            <?=$d_payeesignSTR?>
							        </div>	              	
			              	
							        <div id="signitureid" style="<?=$setDisplaySIGNNEWStr?>">
							            <div id="sig" ></div>
							            <br/>
							            <textarea id="signature64" name="signed" class="textarea" style="display: none;width: 100%;"></textarea>
							        </div> 
                 </td>
              </tr>

              <tr>
                <td colspan=2>                  
                  <div class="text-center"><button class="btn-sub" type="submit">SAVE</button></div>
                </td>
              </tr>
           
            </table>
            
  
          </FORM>

      </div><!--container Ends-->


    </section>

  </main>


<script type="text/javascript">
    var sig = $('#sig').signature({syncField: '#signature64', syncFormat: 'PNG', thickness: 2});
    $('#clear').click(function(e) {
        e.preventDefault();
        sig.signature('clear');
        $("#signature64").val('');
    });
</script>

<SCRIPT language=javascript>

$(document).ready(function()
{
  $('#signednew').change(function() 
  {
    if(this.checked != true)
    {
			document.getElementById("signitureedid").style.display="inline";
			document.getElementById("signitureid").style.display="none";
			document.getElementById("clrbtnid").style.display="none";
    }
    else {
			document.getElementById("signitureedid").style.display="none";
			document.getElementById("signitureid").style.display="inline";
			document.getElementById("clrbtnid").style.display="inline";
    }
  });   
});

</SCRIPT>