<?php
// DISPLAY ALL ERRORS
//error_reporting(E_ALL);
ini_set('display_errors', 0);
date_default_timezone_set('Asia/Bangkok');
session_start();

// START & CONFIG
ob_start();
require 'setup/config.php';

$LANG =  'cn';
// SET LANGUAGE
if (isset($_GET['lang'])){	
	$_SESSION['HTTP_ACCEPT_LANGUAGE'] = $_GET['lang'];
}
if (isset($_SESSION['HTTP_ACCEPT_LANGUAGE']) and file_exists('lang/' . $_SESSION['HTTP_ACCEPT_LANGUAGE'] . '.php')) {	
	if((@include 'lang/' . $_SESSION['HTTP_ACCEPT_LANGUAGE'] . '.php') === false){
		echo 'Caught exception: Translate file is wrong';
	}else{
		@include_once('lang/' . $_SESSION['HTTP_ACCEPT_LANGUAGE'] . '.php');
	}
} else {
	if((@include 'lang/' . $LANG . '.php') === false){
		echo 'Caught exception: Translate file is wrong';
	}else{
		@include_once('lang/' . $LANG . '.php');
	}
}

// INI VARs
$found = 0;                     // MARKER HOW MANY HITS FOUND A SEARCH
$done = 0;                     // MARKER HOW MANY ENTRYs ARE DONE
$msg = '';                    // TOAST MESSAGE
$file = 'data/Corresponding.json'; // DATA FILE NAME
// LOGIN CHECK
session_start();
$login = check_current_user_login($ARR_USERS, $SALT);
$currentuser = $login['user'];
//var_dump($login);
if ($login['status'] == 200) {
    
} else {
    header('location: login.php');
    exit;
}
/* $sessionname = md5($USER . $SALT);
  if (!@$_SESSION[$sessionname]) {
  header('location: login.php');
  exit;
  } */
if (@$_GET['import'] == 1){
    require_once('PHPExcel.php');

    $filename = "RIMBA.xlsx";
    $type = PHPExcel_IOFactory::identify($filename);
    $objReader = PHPExcel_IOFactory::createReader($type);
    $objPHPExcel = $objReader->load($filename);

    foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
        $worksheets[$worksheet->getTitle()] = $worksheet->toArray();
    }
    $id =time();
    foreach ($worksheets['RIMBA'] as $r){
        if($r[0] != ''){
            $id++;
            $array['id'] = $id;
            $array['stt'] = $r[0];
            $array['code'] = $r[1];
            $array['abbreviation'] = $r[2];
            $array['fullname'] = $r[3];
            $array['createby'] = 'Auto';
            $array['accept'] = 0;
            //$array['modifiedtime'] = time();
            $arr_data[] = $array;
        }
    }
    $convert_array_to_json = array_values($arr_data);
    $write_json = json_encode($convert_array_to_json);
    file_put_contents($file, $write_json);
    echo 'done';
    die;
    print_r($worksheets['RIMBA']);
}
// DELETE ENTRY IF DEL LINK IS CLICKED
if (@$_GET['delete_id'] != '' && $currentuser->gm  == '1' ) {
    $data = json_decode(file_get_contents($file), true);
    foreach ( $data as $key => $r  ){
        if($r['id'] == @$_GET['delete_id']){
			//if ($currentuser->role == 'Manager' || ( $currentuser->role == 'Operator' && $r['status'] == '' ) ) {
				unset($data[$key]);
			//}
        }
    }
	
    $convert_array_to_json = array_values($data);
    $write_json = json_encode($convert_array_to_json);
    file_put_contents($file, $write_json);
	header('location: corresponding.php?msg=' . $i18n['Entry successfully deleted.']);
}

if (@$_GET['accept'] != '' && ( $currentuser->gm  == '1' || $currentuser->name == 'DANNA') ) {
    $data = json_decode(file_get_contents($file), true);
    foreach ( $data as $key => $r  ){
        if($r['id'] == @$_GET['accept']){
            if ($currentuser->role == 'Manager' || $currentuser->name == 'DANNA' ) {
                $data[$key]['accept'] = 1;
                $data[$key]['accepttime'] = time();
                $data[$key]['whoaccept'] = $currentuser->name;
                
            }
        }
    }
	
    $convert_array_to_json = array_values($data);
    $write_json = json_encode($convert_array_to_json);
    file_put_contents($file, $write_json);
	header('location: corresponding.php?msg=' . $i18n['Entry successfully deleted.']);
}

if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['code'] != '' 
    && $_POST['abbreviation'] != '' && $_POST['fullname'] != '' ) {
		
	if(count((array)$_FILES['fileupload']['name']) > 0){
			 foreach ($_FILES['fileupload']['name'] as $filekey => $fileu){
				if($_FILES['fileupload']['error'][$filekey] != 0 || strpos($_FILES['fileupload']['filetype'][$filekey],'application/octet-stream') !== false || strpos($fileu,'.php') !== false || strpos($fileu,'.html') !== false ){ continue; }
				
				 $filename_text = time().'_'.$fileu;
				 $filename[] = $fileu;
				 $filetype[] = $_FILES['fileupload']['type'][$filekey];
				 $filesize[] =  $_FILES['fileupload']['size'][$filekey];
				 $filetimeupload[] = time();
				 $filecreatebyid[] = $currentuser->id;
				 $filecreatebyname[] = $currentuser->name;
				 $filepath[] = $filename_text;
				 copy( $_FILES['fileupload']['tmp_name'][$filekey] , __DIR__.'/uploads/'.$filename_text );
			 }
			
	}	
        if( $currentuser->gm  == '1' || $currentuser->name == 'DANNA'  ){
            $accept = 1;
        }else{
            $accept = 1;
        }
	if($_POST['id'] == ''){		
		$receivable = $amount = 0;
        $formdata = array(
        'id' => time()
        , 'code' => $_POST['code']
        , 'stt' =>(count(json_decode(file_get_contents($file), true))+1)
        , 'abbreviation' => $_POST['abbreviation']
        , 'fullname' => $_POST['fullname']
         , 'accept' => $accept        
		, 'createby' => $currentuser->name
		, 'filename' => $filename
		, 'filetype' => $filetype
		, 'filesize' => $filesize
		, 'filetimeupload' => $filetimeupload
		, 'filecreatebyid' => $filecreatebyid
		, 'filecreatebyname' => $filecreatebyname
		, 'filepath' => $filepath
		);
		$arr_data = array();
		if (file_exists($file)) {
			$jsondata = file_get_contents($file);
			$arr_data = json_decode($jsondata, true);
		}
		$arr_data[] = $formdata;
	}else{
		$arr_data = array();
			if (file_exists($file)) {
        		$jsondata = file_get_contents($file);
        		$arr_data = json_decode($jsondata, true);
    		}
		foreach ($arr_data as $key => $r){
			if($r['id'] == $_POST['id']){
				if(file_exists('logs/'.$_POST['id'])){
					$textlog = '----------------------'.date('Y-m-d H:i:s').' - '.$currentuser->name.'----------------------'.PHP_EOL.$_POST['code'].PHP_EOL.$_POST['abbreviation'].PHP_EOL.$_POST['fullname'];
				}else{
					$textlog = $_POST['code'].PHP_EOL.$_POST['abbreviation'].PHP_EOL.$_POST['fullname'].PHP_EOL.'----------------------'.date('Y-m-d H:i:s').' - '.$currentuser->name.'----------------------'.PHP_EOL.$_POST['code'].PHP_EOL.$_POST['abbreviation'].PHP_EOL.$_POST['fullname'];
				}
				$arr_data[$key]['code'] = $_POST['code'];
				$arr_data[$key]['abbreviation'] = $_POST['abbreviation'];
				$arr_data[$key]['fullname'] = $_POST['fullname'];
				$arr_data[$key]['modifiedname'] = $currentuser->name;
				$arr_data[$key]['modifiedtime'] = time();
                                if( $currentuser->gm  == '1' || $currentuser->name == 'DANNA'  ){
                                    $arr_data[$key]['accept'] = 1;
                                }
        
				if(count((array)$filename) > 0){
					$arr_data[$key]['filename'] = $filename;
					$arr_data[$key]['filetype'] = $filetype;
					$arr_data[$key]['filesize'] = $filesize;
					$arr_data[$key]['filetimeupload'] = $filetimeupload;
					$arr_data[$key]['filecreatebyid'] = $filecreatebyid;
					$arr_data[$key]['filecreatebyname'] = $filecreatebyname;
					$arr_data[$key]['filepath'] = $filepath;
				}
				file_put_contents('logs/'.$_POST['id'],file_get_contents('logs/'.$_POST['id']).$textlog.PHP_EOL);
			}			
		}
		
	}
    
	$arr_data = array_values($arr_data);
    $jsondata = json_encode($arr_data);
    if (file_put_contents($file, $jsondata)) {
        $msg = $i18n['Data successfully saved!'];
    } else {
        $msg = $i18n['ERROR &mdash; Data not saved!'];
    }
    header('location: corresponding.php?msg=' . $msg);
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $_GET['msg'] = $i18n['All fields are required!'];
}

// CREATE DATA FILE IF NOT EXISTS
if (!is_file($file)) {
    file_put_contents($file, '');
}

// READ DATA
$data = json_decode(file_get_contents($file), true);


// HEADER
ob_end_flush();
include 'tpl/header.php';
// FORM FOR NEW ENTRY
if( $currentuser->gm  == '1' || 1 == 1  ){
    ?>
        <div class="badge grey lighten-3 hoverable create-user">
            <form action="" method="POST"  enctype="multipart/form-data" >
			<input value=""  id="id" name="id" type="hidden"  />
                <div class="row ">
                    <div class="input-field col s1">
                        <input
                            id="code" 
                            name="code" 
                            type="text" 
                            class="validate sjkdbskjj" 
                            required="required"  autocomplete="off"  maxlength="4" value="<?php echo @$_POST['code'];?>" />
                        <label for="code">Code/代码</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
					<div class="input-field col s1">
                        <input
                            id="abbreviation" 
                            name="abbreviation" 
                            type="text" 
                            class="validate" 
                            required="required"  autocomplete="off"  value="<?php echo @$_POST['abbreviation'];?>" />
                        <label for="abbreviation">abbreviation/简称</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
					<div class="input-field col s1">
                        <input
                            id="fullname" 
                            name="fullname" 
                            type="text" 
                            class="validate" 
                            required="required"  autocomplete="off"  value="<?php echo @$_POST['fullname'];?>" />
                        <label for="fullname">fullname/全名</label>
                        <span class="helper-text" data-error="Error" data-success="OK">
                           
                        </span>
                    </div>
                    <div class="input-field col s1" style="    text-align: right;">
                        <button class="colortoptran btn waves-effect waves-light" type="submit" name="action">
                          Save
                        </button>
                    </div>
                    <div class="input-field col s1 ">
                        <a style="    background: #4e4e4e;" class="btn  btn-default waves-effect waves-light" href="./index.php">
                            <?php echo $i18n['Go Back']; ?>
                        </a>
                    </div>
					<div class="input-field col s3  dhkasbdbas" style="display:none;"  >
						<div class="file-field">
							<div class="btn btn-primary btn-sm float-left" style="padding: 3px;" >
								  <span><?php echo $i18n['Choose file']; ?></span>
								  <input type="file"  name="fileupload[]"  id="fileupload"  multiple="multiple" >
							</div>
							<div class="file-path-wrapper">
								  <input class="file-path validate" type="text" placeholder="<?php echo $i18n['Upload your file']; ?>">
							</div>
						</div>
					</div>	
                </div>
            </form>
        </div>
    <?php
}
// DATA TABLE
if (!empty($data)) {
    // LOOP EACH ENTRY
    ?>
<script>

function highlightDifferencesParaGraphs(another,main ) {
    var mainRows = main,
      anotherRows = another;
    mainRows.each(function(rowNumber, mainRow) {
      var anotherRow = anotherRows.eq(rowNumber),
        anotherCells = anotherRow,
        mainCells = $(mainRow);
      mainCells.each(function(colNumber, cell) {
        var anotherCell = anotherCells.eq(colNumber);
		var oldElem = anotherCell;var newElem = $(cell);
		var oldText = oldElem.text();	var   text = '';	
		newElem.text().split('').forEach(function(val, i){
			if (val != oldText.charAt(i))
			  text += "<span class='highlight'>"+val+"</span>";  
			else
			  text += val;            
		});
		$(cell).html('<p>'+text+'</p>'); 
       // main.toggleClass("highlight", anotherCell.text() !== $(cell).text())
      })
    })

}
</script>	
        <table class="striped responsive-table hoverable tablesorter" id="tab-table">
            <thead>
                <tr>
                    <th ></th>
                    <th ><input class="dnoon" ref="1" type="text" placeholder="搜: Code/代码" /></th>
                    <th ><input class="dnoon" ref="2" type="text" placeholder="搜: Abbreviation/简称" /></th>
                    <th ><input class="dnoon" ref="3" type="text" placeholder="搜: Fullname/全名" /></th>
					<th style="display:none;" >File</th>
					<th >Created/Modified</th>
					<th  ><?php echo $i18n['Action']; ?></th>
                </tr>
            </thead>
        <tbody>
   <?php 
     $total_receivable = $total_amount = $total_profit = 0;
     $countNo = 0;//$data = array_reverse($data);
     foreach ($data as $key => $values) {
         $data2[$values['code'].$values['id']] = $values;
     }
     ksort($data2);
        foreach ($data2 as $key => $values) {
			
							if (file_exists("logs/".$values['id'])) {
								$logs = file_get_contents("logs/".$values['id']);
								$old = explode ('----------------------',$logs);
								$logs = str_replace(PHP_EOL,'<br>',$logs); $old = '<p>'.str_replace(PHP_EOL,'</p><p>',str_replace(array('  ','/n','/r','/t'),'',trim($old[0]))).'</p>';
								$logsmode = '<a  href="#" data-target="modal6" class="modal-trigger cllogcontent" ><span style="display:none;" >'. $logs .'</span><i class="grey-text small material-icons">content_paste</i></a>';
							}else{
								$logsmode = '';
							}
							if($currentuser->gm != '1'){
								$logsmode = '';
							}
								$file = ''; 
								
								
								foreach ($values['filename'] as $keyfile => $dataf ){
										$fnjf++;
										if ( strpos($values['filetype'][$keyfile] , 'pdf')  !== false ) {
												
												
												if( $currentuser->location == '中国' ){
													$file .=  '<a ref="https://htlservice.net/expense/uploads/'.rawurlencode($values['filepath'][$keyfile]).'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}else{
													$file .=  '<a ref="https://drive.google.com/viewerng/viewer?url=https://htlservice.net/expense/uploads/'.urlencode($values['filepath'][$keyfile]).'?pid=explorer&efh=false&a=v&chrome=false&embedded=true" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/pdf.png" style="width:24px;height:auto;" /></a>';
												}
										} elseif ( strpos($values['filetype'][$keyfile] , 'sheet')  !== false || strpos($values['filepath'][$keyfile] , '.xls')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/expense/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/excel.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'zip')  !== false ) { 
												$file .=  '<a download href="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/zip.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'doc')  !== false ) { 
												$file .=  '<a ref="https://view.officeapps.live.com/op/embed.aspx?src=https://htlservice.net/expense/uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'"  href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));" ><img src="https://htlservice.net/Docs/tpl/img/word.png" style="width:24px;height:auto;" /></a>';
										} elseif ( strpos($values['filetype'][$keyfile] , 'image')  !== false ) { 
												$file .=  '<a ref="uploads/'.$values['filepath'][$keyfile].'" data-target="readfile" class="modal-trigger isreadder'.$fnjf.'" isreadder="'.$fnjf.'" href="javascript:void(0);" onclick="$(\'.isleft,.isright\').attr(\'nextread\',\''.$fnjf.'\');$(\'.iframereadfile\').attr(\'src\',$(this).attr(\'ref\'));"  ><img src="https://htlservice.net/Docs/tpl/img/png.png" style="width:24px;height:auto;" /></a>';
										} else{
												$file .=  '<a download href="uploads/'.$values['filepath'][$keyfile].'" ><img src="https://htlservice.net/Docs/tpl/img/file.png" style="width:24px;height:auto;" /></a>';
										}
								}
			
			?>    
                <tr  >
                    <td style="padding-left:20px; " ><?php echo ++$k; ?></td>
                    <td style="padding-left:20px; " ><?php echo $values['code']; ?></td>
                    <td style="padding-left:20px"><?php echo $values['abbreviation']; ?></td>
                    <td style="padding-left:20px"><a data-target="modal8" href="#" class="modal-trigger payerdetail" name="<?= $values['name']?>" id="<?= $values['id']?>"  ><?php echo $values['fullname'];?></a></td>
					<td style="display:none;" ><?php echo $file;  ?></td>
					<td style="padding-left:20px">
							<b>Created:</b> <a href="#" title="<?php echo date('Y.m.d',$values['id']); ?>" ><?php echo $values['createby']; ?></a> | 
							<b>Modified:</b> <a href="#"  title="<?php echo date('Y.m.d',$values['modifiedtime']); ?>" ><?php echo $values['modifiedname']; ?></a> | 
                                                        <?php if($values['accept'] == 1){  ?>
                                                        <b>接受:</b> <a href="#" title="<?php  ?>" ><?php 
                                                        echo $values['whoaccept']; 
                                                        echo ':'.date('Y.m.d',$values['accepttime']); ?></a><br>
                                                        <?php } ?>
						</td>
						
						<td style="padding-left:20px">
							
                                                        <?php if($values['accept'] != 1  ){  ?>
							<?php if( $currentuser->gm  == '1' ){ ?>
							<a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['Click alert link for delete!']?>" href="corresponding.php?delete_id=<?php echo $values['id']; ?>" >
								<i class="red-text text-darken-4 small material-icons">delete_forever</i>
							</a>
							<?php } ?>
							<a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['EDIT'] ?>" href="#" onclick='editc("<?php echo addslashes(json_encode($values)); ?>")'>
								<i class="grey-text small material-icons">mode_edit</i>
							</a>
                                                        <?php if( $currentuser->gm  == '1' || $currentuser->name == 'DANNA'  ){ ?>
                                                        <a  href="corresponding.php?accept=<?php echo $values['id']; ?>" >
                                                            <button style="    width: 100px;    background: #a0a0a0;    margin-top: -21px;" id="1640665447" class="btn btn-danger waves-effect waves-light sendtoaproval ">接受</button>
							</a>
                                                        <?php } ?>
                                                        <?php }else{ ?>
                                                        <?php if( $currentuser->gm  == '1' || $currentuser->name == 'DANNA'   ){ ?>
                                                    	<a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['Click alert link for delete!']?>" href="noti.php?delete_id=<?php echo $values['id']; ?>" >
								<i class="red-text text-darken-4 small material-icons">delete_forever</i>
							</a>
							
							<a class="tooltipped" data-position="top" data-tooltip="<?= $i18n['EDIT'] ?>" href="#" onclick='editc("<?php echo addslashes(json_encode($values)); ?>")'>
								<i class="grey-text small material-icons">mode_edit</i>
							</a>
                                                        <?php echo $logsmode; ?>
                                                        <?php } ?>
                                                        <?php } ?>
			
						</td>
					<?php if($values['modifiedname'] != ''){ ?>
					<td style="display:none;" class="old<?php echo $values['id']; ?>" ><?php echo $old; ?></td>
					<script>
					$(document).ready(function(){
						highlightDifferencesParaGraphs($(".old<?php echo $values['id']; ?> p"),$(".isnew<?php echo $values['id']; ?> p"));
					});	
					</script>
					<?php } ?>
                </tr>
            <?php 
			}
        }
    ?>
        </tbody>
        </table>
<?php if ($currentuser->gm == "1"  ){ ?>	
<div id="modal6" class="modal">
  <div class="logcontent" style="padding: 15px;" ></div>
</div>
<?php } ?>

<style>
table.tablesorter thead tr th {
    background-color: #ddd;
}
.isleft{ width: 50px; height: 50px; position: fixed; left: 15px; top: 45%; z-index: 1000000; font-size: 54px; opacity: 0.2;cursor: pointer; } .isright{ width: 50px; height: 50px; position: fixed; right: 15px; top: 45%; z-index: 1000000; font-size: 54px; opacity: 0.2;cursor: pointer; } .isleft:hover , .isright:hover{ opacity: 0.5; } .isleft i , .isright i { } 
</style>           
<div id="readfile" class="modal" style="    width: 80%!important;" >
			<a onclick="$('.modal-overlay').trigger('click');" style="       background: transparent;    color: red;    font-weight: bold;    font-size: 35px;	    font-family: cursive;    width: 30px;    height: 30px;    top: 0px;    right: 20px;    position: absolute;    left: unset;    bottom: unset;    display: block;    cursor: pointer;" >x</a>
			<iframe class="iframereadfile" src="" width="100%" style="height:auto;    min-height: 550px;" ></iframe>
			<div class="isleft" ><i class="fas fa-chevron-left"></i></div>
			<div class="isright" ><i class="fas fa-chevron-right"></i></div>		
</div>	
<div id="modal8" class="modal">
	<a onclick="$('.modal-overlay').trigger('click');" style="       background: transparent;    color: red;    font-weight: bold;    font-size: 35px;	    font-family: cursive;    width: 30px;    height: 30px;    top: 0px;    right: 20px;    position: absolute;    left: unset;    bottom: unset;    display: block;    cursor: pointer;" >x</a>
  <iframe class="receiverpayer" src="" width="100%" style="height:auto;    min-height: 600px;" ></iframe>
</div>
<style>
#modal8 { min-width: 1280px; }
.mystyle {
	display:none!important;
}
</style>
<script>
jQuery('.payerdetail').click(function(){
		jQuery('.receiverpayer').attr( 'src','/expense/index_payer2.php?name='+jQuery(this).attr('name')+'&id='+jQuery(this).attr('id'));
});	



jQuery.fn.ForceNumericOnly =
function()
{
    return this.each(function()
    {
        $(this).keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
            // home, end, period, and numpad decimal
            if (
                key == 8 || 
                key == 9 ||
                key == 13 ||
                key == 46 ||
                key == 110 ||
                key == 190 ||
                (key >= 35 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105)){
                    return true;
                }else{
                    alert('Number Only');
                    return false;
                }
        });
    });
};

jQuery.fn.ForceNumericOnly2 =
function()
{
    return this.each(function()
    {
        $(this).keydown(function(e)
        {
            if($(this).val().length < 3 ){
                var key = e.charCode || e.keyCode || 0;
                // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
                // home, end, period, and numpad decimal
                if (
                key == 8 || 
                key == 9 ||
                key == 13 ||
                key == 46 ||
                key == 110 ||
                key == 190 ||
                (key >= 35 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105)){
                    return true;
                }else{
                    alert('Number Only, then Letter');
                    return false;
                }
            }
        });
    });
};
jQuery(".sjkdbskjj").ForceNumericOnly();
jQuery("#abbreviation").ForceNumericOnly2();

$(document).ready(function(){
	$('.isleft').click(function(){
		if($('.isreadder'+$(this).attr('nextread')).prev().hasClass('modal-trigger')){
			$('.isreadder'+$(this).attr('nextread')).prev().trigger('click');
		}
	});
	$('.isright').click(function(){
		if($('.isreadder'+$(this).attr('nextread')).next().hasClass('modal-trigger')){
			$('.isreadder'+$(this).attr('nextread')).next().trigger('click');
		}
	});
});	
function editc(id) {

var obj = jQuery.parseJSON(id);
$('#code').next().addClass('active');
$('#abbreviation').next().addClass('active');
$('#fullname').next().addClass('active');
$('#id').val(obj.id);
$('#code').val(obj.code);
$('#abbreviation').val(obj.abbreviation);
$('#fullname').val(obj.fullname);
}
<?php if ($currentuser->gm == "1"  ){ ?>	
	$(".cllogcontent").click(function(){
		$(".logcontent").html($(this).find('span').html());
	});	
<?php } ?>        
</script>            
		
<style>
.highlight {    
    color: red;    background: #ffeded;
}
.Blue {
	border:solid 3px #039be5!important; 	
}
.Green {
	border:solid 3px #66bb6a!important; 
}
.Yellow {
	border:solid 3px #ffb300 !important; 
}
.Red {
	border:solid 3px #c62828!important; 
}
.google_translate_element2 ,.skiptranslate {
	display:none;
}
body {
	    top: 0px!important;
}
</style>
<script>
jQuery(document).ready(function($){
    

$(".dnoon").on('keyup change',function(){
          var input, filter, table, tr, td, i, txtValue;
          input = $(this).val();
          filter = input.toUpperCase();
          table = $(this).parents('table');
          tr = table.find('tbody tr');
          for (i = 0; i < tr.length; i++) {
                        if($(this).attr('ref') == 1){
                                td = tr[i].getElementsByTagName("td")[0];
                        }
                        if($(this).attr('ref') == 2){
                                td = tr[i].getElementsByTagName("td")[1];
                        }
                        if($(this).attr('ref') == 3){
                                td = tr[i].getElementsByTagName("td")[2];
                        }

                   if (td) {
                          txtValue = td.textContent || td.innerText;
                        
                          if (txtValue.toUpperCase().indexOf(filter) > -1) {
                                tr[i].style.display = "";
                          } else {
                                tr[i].style.display = "none";
                          }
                        }
          }
});
});
</script>
<?php  if($_SESSION['HTTP_ACCEPT_LANGUAGE'] != 'cn' && $_SESSION['HTTP_ACCEPT_LANGUAGE'] != ''){ ?>
<div id="google_translate_element2"></div>
<script type="text/javascript">function googleTranslateElementInit2() {
	new google.translate.TranslateElement({pageLanguage: 'cn', autoDisplay: false}, 'google_translate_element2');
	}</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit2"></script>

<script type="text/javascript">


function GTranslateFireEvent(a,b)
	{
	try
		{
		if(document.createEvent)
			{
			var c=document.createEvent("HTMLEvents");
			c.initEvent(b,true,true);
			a.dispatchEvent(c)
		}
		else
			{
			var c=document.createEventObject();
			a.fireEvent('on'+b,c)
		}
	}
	catch(e)
		{
	}
}
function doGTranslate(a)
	{
	if(a.value)a=a.value;
	if(a=='')return;
	var b=a.split('|')[1];
	var c;
	var d=document.getElementsByTagName('select');
	for(var i=0;i<d.length;	i++)if(d[i].className=='goog-te-combo')c=d[i];
	if(document.getElementById('google_translate_element2')==null||document.getElementById('google_translate_element2').innerHTML.length==0||c.length==0||c.innerHTML.length==0)
		{
		setTimeout(function()
			{
			doGTranslate(a)
		}
		,500)
	}
	else
		{
		c.value=b;
		GTranslateFireEvent(c,'change');
		GTranslateFireEvent(c,'change')
	}
}

doGTranslate('zh-CN|<?php echo $_SESSION['HTTP_ACCEPT_LANGUAGE']; ?>');


</script>

		
    <?php
}
// ENDIF no data



    
 // ECHO PROGRESS-BAR (only if there is no search performed) SEE tpl/css/progress.css
if (@$_GET['q'] == '') {
    echo '<div class="progress tooltipped" data-position="top"' .
    ' data-tooltip="' . $done . '/' . count((array)$data) . ' ' . $TYPE .
    '" title="' . $done . '/' . count((array)$data) . ' ' . $TYPE . '">' .
    '<div class="progress-bar green" data-width="' . ($done / count((array)$data) * 100) .
    '" style="width:' . ($done / count((array)$data) * 100) . '%"></div></div>';
}

// var_dump($sortdate); die;
// FOOTER
include 'tpl/footer.php';
?>
