<?php
if($_POST){
	$data=json_encode($_POST);
	$db->insertAry("extra",array("data"=>$data,"school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"],
"idno"=>$_GET["id"],"type"=>"tc"));
	echo $db->getErMsg();
}
?>
<form method="post" action="">
<?php 
$detail=$db->getVal("select data from extra where school_id='".$LinksDetails["id"]."' and idno='".$_GET["id"]."' and type='tc'");
if($detail!=""){
	$idata=json_decode($detail,true);
?>
<input type="button" value="print" onclick="window.print()" />
<?php
}else{
	?>
<input type="submit" value="save"  />
	<?php
}
$res=$db->getRow("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno=".$_GET["id"]);
//print_r($res);
?>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
var th = ['', 'thousand', 'million', 'billion', 'trillion'];
var dg = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
var tn = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
var tw = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
function toWords(s) {
    s = s.toString();
    s = s.replace(/[\, ]/g, '');
    if (s != parseFloat(s)) return 'not a number';
    var x = s.indexOf('.');
    if (x == -1) x = s.length;
    if (x > 15) return 'too big';
    var n = s.split('');
    var str = '';
    var sk = 0;
    for (var i = 0; i < x; i++) {
        if ((x - i) % 3 == 2) {
            if (n[i] == '1') {
                str += tn[Number(n[i + 1])] + ' ';
                i++;
                sk = 1;
            } else if (n[i] != 0) {
                str += tw[n[i] - 2] + ' ';
                sk = 1;
            }
        } else if (n[i] != 0) {
            str += dg[n[i]] + ' ';
            if ((x - i) % 3 == 0) str += 'hundred ';
            sk = 1;
        }
        if ((x - i) % 3 == 1) {
            if (sk) str += th[(x - i - 1) / 3] + ' ';
            sk = 0;
        }
    }
    if (x != s.length) {
        var y = s.length;
        str += 'point ';
        for (var i = x + 1; i < y; i++) str += dg[n[i]] + ' ';
    }
    return str.replace(/\s+/g, ' ');

}
$(document).ready(function(e) {
	$('#date').html(" "+toWords('<?php echo date('d', strtotime($res["dob"])); ?>')+" ");
	$('#year').html(" "+toWords('<?php echo date('Y', strtotime($res["dob"])); ?>')+" ");    
});
function printme(){
	window.print();
	window.onfocus=function(){ window.close();}
}
</script>

<style>
.tc{
	font-size:16px;
	font-family:"Courier New", Courier, monospace;
	color:#333;
	border:1px solid #333;
	font-weight:bold;
	width:658px;
	padding: 33px 51px;
}
.tc .txt{
	border:0px;
	border-bottom:2px dotted #333;
	font-family:"Courier New", Courier, monospace;
	color:#009;
	margin:2px 5px;
	display:inline-block;
}
.span{
	border-bottom:2px dotted #000; 
	display:inline-block;
	font-family:"Courier New", Courier, monospace;
}
</style>
<center>
<table border="0" class="tc">
  <tr>
    <td valign="top" width="60">
    <img width="60px" style="float:left" src="<?php echo $LinksDetails["logo"]?>" />
	</td>
    <td><div style="text-align:center"><h2 style="text-transform:uppercase"><?php echo $LinksDetails["site_name"]; ?></h2>
      <?php echo nl2br($LinksDetails["contact_content"]); ?></div>&nbsp;</td>
    <td width="150" align="right">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">
    <div style="margin:3px; padding:15px 5px; width:300px; float:right">
    Admission No. <span class="span" style="width:100px"><?php echo $res["admissionno"] ?></span><br />
    Child ID. <input type="text" class="txt" value="<?php echo $idata["childid"] ?>" name="childid" />

</div>
    <div style="margin:3px; padding:15px 5px; width:200px">SL No <span class="span" style="width:100px"><?php echo $res["idno"] ?></span></div>
    
    </td>
    </tr>
  <tr>
    <td colspan="3" align="center"><h1>TRANSFER CERTIFICATE</h1></td>
    </tr>
  <tr>
    <td colspan="3"> 
    &nbsp;&nbsp;&nbsp;This is to certify that <span class="txt" style="width:246px"><?php echo $res["name"] ?></span> 
    Son/Daughter of <span class="txt" style="width:357px"><?php echo $res["fname"] ?></span> 
    Cast <span class="txt" style="width:425px"><?php echo $res["cast"] ?></span> was 
    Admitted in to this school on the <input type="text" class="txt" name="admitted_school" value="<?php echo $idata["admitted_school"] ?>" style="width:178px" /><?php //echo $res["admissionclass"] ?> 
    on a transfer corticated  from <input type="text" class="txt" name="transfer_date" value="<?php echo $idata["transfer_date"] ?>" style="width:227px" /> 
    school and left on the <span class="txt" style="width:288px"> <?php echo date("d M Y") ?> </span> 
    with a <input type="text" class="txt" name="charactor" value="<?php echo $idata["charactor"] ?>" style="width:337px" /> Character.
    <br />
    <br />    &nbsp;&nbsp;&nbsp; He/She was then reading in the <input type="text" class="txt" name="classread" value="<?php echo $idata["classread"] ?>" style="width:160px" /> 
    Class sue to this school on his/her account has been paid. <br />
    <br />
    &nbsp;&nbsp;&nbsp;His/Her date of birth according  to the admission register is <span class="txt" style="width:307px"> <?php echo date('d-m-Y', strtotime($res["dob"])); ?> </span> in word 
    <div class="txt" style="width:510px"><span id="date"></span><span id="month"><?php echo date('F', strtotime($res["dob"])); ?></span><span id="year"></span></div><br /><br />
<br />
(<em>the following additional Information must be supplied if the scholar of the end of the School year</em>)<br />
<br />
<br />
Promotion has ben promised/refused to class <input type="text" class="txt" name="refused" value="<?php echo $idata["refused"] ?>" style="width:95px" /> 
</td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td valign="top">Date:<input type="text" class="txt" name="sdate"  value="<?php echo $idata["sdate"] ?>" style="width:140px" /></td>
    <td>&nbsp;</td>
    <td>Signed<br />Principel   
    </td>
  </tr>
</table>
</center>
<p>&nbsp;</p>
</form>