ok

Mini Shell

Direktori : /home2/selectio/www/lilyexpresslive/software/admin/
Upload File :
Current File : /home2/selectio/www/lilyexpresslive/software/admin/pincode-bulk-upload-status.php

<?php require_once ('header.php');

define( 'WP_MAX_MEMORY_LIMIT' , '512M' );
date_default_timezone_set('Asia/Kolkata');
$date = date('Y-m-d h:i:s', time());
$pincode = array();
$city_name = array();
$state_name = array();
$service_status = array();
$air_service = array();
$road_service = array();
$tat = array();
$area_code = array();

$errData = array();
$error_msg = array();
$error_msg_status = array();


if (isset($_POST["Import"]))
{
    try
    {
        $ri = 0;
        $filename = $_FILES["file"]["tmp_name"];
        if ($_FILES["file"]["size"] > 0)
        {
            $file = fopen($filename, "r");
            while (($emapData = fgetcsv($file, 10000, ",")) !== false)
            {
                $error_msg_status[$ri]=0;
                if ($emapData == '')
                {
                    break;
                }
                if ($ri > 0 && $emapData != '')
                {
                    /*Service Pinocde Existing or Not*/
                        $pinco = trim($emapData[0]);
                        $statement = $pdo->prepare("SELECT * FROM pincode where pin_code='$pinco'");
                        $statement->execute();
                        $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                        $count = $statement->rowCount();
                        if($count>0)
                        {
                            $error_msg[$ri] .= "Row Number " . $ri . " Pincode Already Exists...";
                            $error_msg_status[$ri]=1;
                        }
                        else if(!is_numeric($pinco)){
                            $error_msg[$ri] .= "Row Number " . $ri . " Pincode Number Only Allowed...";
                            $error_msg_status[$ri]=1;
                        }
                        $pincode[] = $emapData[0];
                    /*City Name*/
                    if($emapData[1]==""){
                        $city_name[]="";
                    }else{
                        $city_name[]=$emapData[1];
                    }
                    /*State Name*/
                    if($emapData[2]==""){
                        $state_name[]="";
                    }else{
                        $state_name[]=$emapData[1];
                    }
                    
                    /*Service Status*/
                    if($emapData[3]==""){
                        $service_status[]="Yes";
                    }else if($emapData[3]=='Yes' || $emapData[3]=='No'){
                        $service_status[]=$emapData[3];
                    }
                    else{
                        $error_msg[$ri] .= "Row Number " . $ri . " Service Only Allowed Yes or No...";
                        $error_msg_status[$ri]=1;
                         $service_status[]=$emapData[3];
                    }
                   
                    /*Air Service Status*/
                    if($emapData[4]==""){
                        $air_service[]="Yes";
                    }else if($emapData[4]=='Yes' || $emapData[4]=='No'){
                        $air_service[]=$emapData[4];
                    }
                    else{
                        $error_msg[$ri] .= "Row Number " . $ri . " Air Service Only Allowed Yes or No...";
                        $error_msg_status[$ri]=1;
                        $air_service[]=$emapData[4];
                    }
                    
                     /*Road Service Status*/
                    if($emapData[5]==""){
                        $road_service[]="Yes";
                    }else if($emapData[5]=='Yes' || $emapData[5]=='No'){
                        $road_service[]=$emapData[5];
                    }
                    else{
                        $error_msg[$ri] .= "Row Number " . $ri . " Road Service Only Allowed Yes or No...";
                        $error_msg_status[$ri]=1;
                        $road_service[]=$emapData[5];
                    }
                    
                    $tat[]=$emapData[6];
                    $area_code[]=$emapData[7];
                    
                    if (count($pincode) > 0)
                    {
                        foreach (array_count_values($pincode) as $num => $value)
                        {
                            if ($value > 1)
                            {
                                $error_msg[$ri] = " Row Number " . $ri . " Pincode ".$num ." is having duplicate value of " . $value . " times in our csv file";
                                $error_msg_status[$ri]=1;
                            }
                        }
                    }
                }
                $ri++;
            }
            fclose($file);
        }
        
       ?>
       <style>
           th{
               background:green;
               color:white;
               padding:2px;
               border:1px solid red;
           }
           td{
               padding:2px;
               border:1px solid red;
           }
       </style>
       <div style="padding:10px;">
           <center><h4><i class="fa fa-info-circle"></i> Pincode Upload Status Details</h4>
           <a href="pincode-bulk-upload.php" class="btn btn-danger btn-sm"><i class="fa fa-arrow-left"></i> Back to Pincode Bulk Upload</a></center><br>
       <table id="projectSpreadsheet"  style="font-size: 12px;" width="100%">
		        <tr class="table-success">
		        <th style="width: 3%;text-align: center;">S.No</th>
		        <th style="text-align: center;">Error Details</th>
		        <th style="text-align: center;">Pincode</th>
		        <th style="text-align: center;">City Name</th>
		        <th style="text-align: center;">State Name</th>
				<th style="text-align: center;">Service </th>
				<th style="text-align: center;">Air</th>
				<th style=";text-align: center;">Road</th>
				<th style="text-align: center;">Tat</th>
				<th style=";text-align: center;">Area Name</th>
		        </tr>
		        <tbody id="tbodyid">
       <?php
       $inserted_count=0;$inserted_counts=0;
       $error_count=0;
       $k=1;
       for($f=1;$f<$ri;$f++){
           
           $err_status=$error_msg_status[$f];
            if($err_status==0)
            {
               $inserted_count++; 
               $statement = $pdo->prepare("INSERT INTO pincode (`pin_code`, `city`, `state`, `service`, `air`, `road`, `tat`, `area_code`, `created_At`) VALUES (?,?,?,?,?,?,?,?,?)");
                               $result= $statement->execute(array(
                                    $pincode[$f-1],
                                    $city_name[$f-1],
                                    $state_name[$f-1],
                                    $service_status[$f-1],
                                    $air_service[$f-1],
                                    $road_service[$f-1],
                                    $tat[$f-1],
                                    $area_code[$f-1],
                                    $date
                                ));
               if($result){$inserted_counts++;}
               
               
            }else{ $error_count++;?>
            
            <tr class="table-active">
		    <td style="width: 3%;text-align: center;"><?php echo $k ?></td>
		    <td style="text-align: left;"><?php echo $error_msg[$f]; ?></td>
		    <td style="text-align: center;"><?php echo $pincode[$f-1] ?></td>
		    <td style="text-align: center;"><?php echo $city_name[$f-1] ?></td>
		    <td style="text-align: center;"><?php echo $state_name[$f-1] ?></td>
		    <td style="text-align: center;"><?php echo $service_status[$f-1] ?></td>
		    <td style="text-align: center;"><?php echo $air_service[$f-1] ?></td>
		    <td style="text-align: center;"><?php echo $road_service[$f-1] ?></td>
		    <td style="text-align: center;"><?php echo $tat[$f-1] ?></td>
		    <td style="text-align: center;"><?php echo $area_code[$f-1] ?></td>
		    </tr>
         <?php  $k++; }
       } ?>
       </tbody>
			</table>
       </div>
 <?php if($error_count>0){ echo "<br><center><a href='#' id='xx' class='btn btn-sm btn-warning'><i class='fa fa-download'></i> Download Error Report</a></center><br>";}
 if($inserted_count>0){ echo "<center style='color:green;'><h4> Eligible Insert Data : ".$inserted_count." Inserted Data : ".$inserted_counts." Pincode inserted successfully</h4></center><br><br><br>";} }
catch(Exception $e){
    echo "<center>Message: " . $e->getMessage()."</center>";
}
}?>
<script type="text/javascript">

$(document).ready(function () {

	function exportTableToCSV($table, filename) {
    
        var $rows = $table.find('tr:has(td),tr:has(th)'),
    
            // Temporary delimiter characters unlikely to be typed by keyboard
            // This is to avoid accidentally splitting the actual contents
            tmpColDelim = String.fromCharCode(11), // vertical tab character
            tmpRowDelim = String.fromCharCode(0), // null character
    
            // actual delimiter characters for CSV format
            colDelim = '","',
            rowDelim = '"\r\n"',
    
            // Grab text from table into CSV formatted string
            csv = '"' + $rows.map(function (i, row) {
                var $row = $(row), $cols = $row.find('td,th');
    
                return $cols.map(function (j, col) {
                    var $col = $(col), text = $col.text();
    
                    return text.replace(/"/g, '""'); // escape double quotes
    
                }).get().join(tmpColDelim);
    
            }).get().join(tmpRowDelim)
                .split(tmpRowDelim).join(rowDelim)
                .split(tmpColDelim).join(colDelim) + '"',
    
            
    
            // Data URI
            csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
            
            console.log(csv);
            
        	if (window.navigator.msSaveBlob) { // IE 10+
        		//alert('IE' + csv);
        		window.navigator.msSaveOrOpenBlob(new Blob([csv], {type: "text/plain;charset=utf-8;"}), "csvname.csv")
        	} 
        	else {
        		$(this).attr({ 'download': filename, 'href': csvData, 'target': '_blank' }); 
        	}
    }
    
    // This must be a hyperlink
    $("#xx").on('click', function (event) {
    	
        exportTableToCSV.apply(this, [$('#projectSpreadsheet'), 'Pincode-Error-Report.csv']);
        
        // IF CSV, don't do event.preventDefault() or return false
        // We actually need this to be a typical hyperlink
    });

});
	</script>
<?php require_once ('footer.php'); ?>

Zerion Mini Shell 1.0