<?php
	error_reporting(0);
	define('INCLUDE_CHECK',true);
	session_start();
	require ('classes/config.php');
	require_once('classes/session.php');
	
	
	function get_file_extension($file_name) {
    return end(explode('.',$file_name));
}
 
function errors($error){
    if (!empty($error))
    {
            $i = 0;
            while ($i < count($error)){
            $showError.= '<div class="warning">'.$error[$i].'</div>';
            $i ++;}
            return $showError;
    }// close if empty errors
} // close function
 
 
if (isset($_POST['upfile'])){
// check feilds are not empty
 
if(get_file_extension($_FILES["uploaded"]["name"])!= 'csv')
{
$error[] = 'Only CSV files accepted!';
}
 
if (!$error){
 
$tot = 0;
$handle = fopen($_FILES["uploaded"]["tmp_name"], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    for ($c=0; $c < 1; $c++) {
 
            if($data[0] !='pin'){
                mysql_query("INSERT INTO epayment_pin(
			pin,
            serial_no,
            txn_ref,
			status,
			usedbyid,
			log_time	 
               )VALUES(
                    '".mysql_real_escape_string($data[0])."',
                    '".mysql_real_escape_string($data[1])."',
                    '".mysql_real_escape_string($data[2])."',
                    '".mysql_real_escape_string($data[3])."',
                    '".mysql_real_escape_string($data[4])."',
                    '".mysql_real_escape_string($data[5])."'
                )")or die(mysql_error());
            }
 
    $tot++;}
}
fclose($handle);
$content.= "<div class=bg-success> CSV File Imported, $tot records added </div>";
 
}// end no error
}//close if isset upfile
$er = errors($error);

?>
<title>OSCOTECH, ESA-OKE :: Admin-Dashboard > Upload ereg Card</title>


        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">ereg Card</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            
            <div class="row">
                <div class="col-lg-12">
                	<?php echo $content; ?>	
                    <?php echo $er; ?>	
                    <div class="panel panel-info">
                        <div class="panel-heading">
                            Import CSV Data
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-6">
                                    <form method="post" action="" role="form" enctype="multipart/form-data">
                                        <div class="form-group">
                                            <label>Upload ereg Cards:</label>
                                            <input class="form-control" name="uploaded" type="file" require>
                                        </div>
                                        <input type="submit" class="btn btn-danger" name="upfile"  value="Upload File" />
                                    </form>
                                </div>

        </div>
        <!-- /#page-wrapper -->
        

    </div>
    <!-- /#wrapper -->