<div class="wrap">
	<h3 class="wp-heading-inline"><?php _e('Import Token Holder',CIP_TXTDOMAIN); ?></h3>
	<!--p><a class="page-title-action" href="<?php echo get_stylesheet_directory_uri().'/user-import-sample.csv'; ?>" download>Download Sample</a></p-->
	<form method="post" enctype="multipart/form-data">
		<input type="file" name="data_excel" required />
		<input type="submit" class="button button-primary button-large" name="submit" value="Import" />
	</form>				
</div>
<?php
if( isset( $_POST['submit'] ) ){
	if( isset($_FILES['data_excel']['name']) && !empty($_FILES['data_excel']['name']) ){
		$file = $_FILES['data_excel']['tmp_name'];
		include( 'PHPExcel/Classes/PHPExcel/IOFactory.php' );
		$inputFileName = $file;
		try {
			$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
			$objReader = PHPExcel_IOFactory::createReader($inputFileType);
			$objReader->setInputEncoding('ISO-8859-1');
			$objPHPExcel = $objReader->load($inputFileName);
		}catch(Exception $e){
			echo '<pre>'; print_r( $e->getMessage() ); echo '</pre>';
			exit;
		}
		$sheet = $objPHPExcel->getSheet(0);
		$highestRow = $sheet->getHighestRow();
		$highestColumn = $sheet->getHighestColumn();
		$count = 2;
		$status = "publish";
		for($row = 2; $row <= $highestRow; $row++){
			$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
			
			echo '<pre>';
			print_r( $rowData );
			echo '</pre>';
			/*$fname = ( $rowData[0][0] != "" ) ? $rowData[0][0] : '';
			$email = $rowData[0][1];
			$password = $rowData[0][2];
			$username = sanitize_user($email, true);
			$user_id = wp_create_user( $username, $password, $email );
			if( !is_wp_error($user_id) ) {
				wp_setcookie($username,$password, true);
				wp_set_current_user($user_id,$username);
				update_user_meta( $user_id,'first_name',$fname );
				update_user_meta( $user_id,'force_login',1 );
				echo '<pre style="border: 2px solid #4caf50;padding: 5px;">'; echo 'Row no. '.$row.' inserted, user id = '.$user_id; echo '</pre>';
			}else{
				echo '<pre style="border: 2px solid #f44336;padding: 5px;">'; echo 'Row no. '.$row.' failed'; echo '</pre>';
			}*/
		}
	}
}
?>