Created
November 13, 2012 15:29
-
-
Save novalagung/4066335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Example</title> | |
<style> | |
html, body { | |
height: 100%; | |
width: 100%; | |
} | |
body { | |
overflow-x: hidden; | |
} | |
.center-middle { | |
display: table; | |
height: 100%; | |
width: 100%; | |
} | |
.center-middle > div { | |
display: table-cell; | |
height: 100%; | |
width: 100%; | |
vertical-align: middle; | |
} | |
#main { | |
height: 500px; | |
width: 500px; | |
margin: 0px auto; | |
background-color: #FDFDFD; | |
} | |
textarea[name=file-content] { | |
width: 693px; | |
height: 300px; | |
} | |
</style> | |
</head> | |
<body> | |
<?php | |
$is_file_uploaded = false; | |
$file_target_name = ''; | |
$data = array(); | |
if (isset($_POST['submit']) && $_POST['submit'] == 'Read') { | |
$file_target_name = basename($_FILES['file-target']['name']); | |
if (move_uploaded_file($_FILES['file-target']['tmp_name'], $file_target_name)) { | |
$is_file_uploaded = true; | |
} | |
} | |
?> | |
<div class="center-middle"> | |
<div> | |
<div id="main"> | |
<form enctype="multipart/form-data" method="post"> | |
<div> | |
<label>Choose a file</label> | |
<input type="file" required name="file-target" /> | |
<input type="submit" name="submit" value="Read" /> | |
</div> | |
<div> | |
<textarea name="file-content"> | |
<?php | |
if ($is_file_uploaded) { | |
$file_target_handler = fopen($file_target_name, "r"); | |
$i = 0; | |
$cloned_target = array(); | |
if (!feof($file_target_handler)) { | |
while ($row = fgets($file_target_handler)) { | |
if (trim($row) != "") { | |
$i++; | |
$cloned_target [] = $row; | |
} | |
} | |
} | |
} | |
$e = $i; | |
$i = 0; | |
$isBTS = false; | |
$isDaerah = false; | |
$data_row = array(); | |
foreach ($cloned_target as $key => $value) { | |
if ($i > 4 && $i < $e - 5) { | |
if (strpos($value, 'HST') !== false) { | |
$kode = explode("(", $value); | |
$kode = explode(")", $kode[1]); | |
$nama = explode(" ", trim($kode[1])); | |
$waktu = explode(" ", strrev(trim($kode[1]))); | |
$data_row['kode'] = $kode[0]; | |
$data_row['nama'] = $nama[0]; | |
$data_row['waktu'] = strrev($waktu[0] . " " . $waktu[1]); | |
if (!$isBTS && !$isDaerah) { | |
$isBTS = 0; | |
$isDaerah = 0; | |
} | |
echo "{$data_row['kode']} {$data_row['nama']} {$data_row['waktu']}\n"; | |
} | |
$isBTS++; | |
if ($isBTS == 2) { | |
$isBTS = false; | |
$bts = explode(" ", $value); | |
$bts = trim(str_replace($bts[0], "", $value)); | |
$data_row['bts'] = $bts; | |
echo "{$data_row['bts']}\n"; | |
} | |
$isDaerah++; | |
if ($isDaerah == 3) { | |
$data_row['daerah'] = trim($value); | |
echo "{$data_row['daerah']}\n\n"; | |
$isDaerah = false; | |
} | |
if (count($data_row) == 5) { | |
$data [] = $data_row; | |
$data_row = array(); | |
} | |
} | |
$i++; | |
} | |
if (count($data) == 0) { | |
echo "DATA KOSONG !"; | |
} | |
?> | |
</textarea> | |
</div> | |
<pre> | |
<?php | |
function aasort(&$array, $key) { | |
$sorter = array(); | |
$ret = array(); | |
reset($array); | |
foreach ($array as $ii => $va) { | |
$sorter[$ii] = $va[$key]; | |
} | |
asort($sorter); | |
foreach ($sorter as $ii => $va) { | |
$ret[$ii] = $array[$ii]; | |
} | |
$array = $ret; | |
} | |
function longDateToSecond($date) { | |
$o = explode(" ", $date); | |
$o = $o[1]; | |
$o = explode(":", $o); | |
$time = 0; | |
$time += (((int) $o[0]) * 3600); | |
$time += (((int) $o[1]) * 60); | |
$time += $o[2]; | |
return $time; | |
} | |
try { | |
if (count($data) > 0) { | |
mysql_connect('localhost', 'root', '') or die(mysql_error()); | |
mysql_select_db('koneksi1') or die(mysql_error()); | |
aasort($data, 'kode'); | |
$kode = ""; | |
$time = ""; | |
$data2 = $data; | |
$skip = false; | |
foreach ($data as $key => $val) { | |
if ($skip) { | |
$skip = false; | |
continue; | |
} | |
foreach ($data2 as $key2 => $val2) { | |
if ($val["kode"] == $val2["kode"] && $val["waktu"] != $val2["waktu"]) { | |
unset($data[$key]); | |
unset($data[$key2]); | |
$second = longDateToSecond($val["waktu"]) - longDateToSecond($val2['waktu']); | |
$second = (int) str_replace('-', '', $second + ''); | |
$date = explode(" ", $val['waktu']); | |
$date = trim($date[0]); | |
$time = $date . " " . date("H:i:s", $second); | |
mysql_query("Insert into buku(kode, nama, waktu, bts, daerah, sisa) values('{$val['kode']}', '{$val['nama']}', '{$val['waktu']}', '{$val['bts']}', '{$val['daerah']}', '{$second}')") or die(mysql_error()); | |
if (!$skip) { | |
$skip = true; | |
} | |
} | |
} | |
} | |
/** start rest data */ | |
/** {$data} */ | |
/** end rest data */ | |
} | |
} catch (Exception $e) { | |
print $e->getTraceAsString(); | |
} | |
?> | |
</form> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment