<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 100% !important;overflow: inherit !important;} 
</style>
<?php
if($_POST){
	$mysqlImportFilename ='';
	if(isset($_FILES["photo"]["name"]) && !empty($_FILES["photo"]["name"])){
		$lfilename = basename($_FILES['photo']['name']);
		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
		if(in_array($lext,array('csv'))) 
		{

			$lnewfile=md5(microtime()).".".$lext;
			if(move_uploaded_file($_FILES['photo']['tmp_name'],"media/".$lnewfile))
			{
				// Read in entire file
				$file = "media/".$lnewfile;$ij=0;
				// Loop through each line
				if (($handle = fopen($file, "r")) !== FALSE) { 
				    
					while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
					    
					   // print_r($data);
						$ij++; 
						if($ij!=1){
                            $admissionno = $data[0];
                            $amount = $data[2];
                            if($amount!=0){

                                $idno = $db->getVal("select idno from student where admissionno='$admissionno' and session='".$_SESSION["admin"]["session"]."' ");
                                $class = $db->getVal("select class from student where admissionno='$admissionno' and session='".$_SESSION["admin"]["session"]."'  ");
                                    $newary = array(
                                            "name"      =>  "Transport_dues",
                                            "class"     =>  $class,
                                            "fee"       =>  $amount,
                                            "otype"     =>  $idno,
                                            "month"     =>  1,
                                            "school_id" =>  $_SESSION["admin"]["school_id"],
                                            "session"   =>  $_SESSION["admin"]["session"],
                                            "added_by"  =>  $_SESSION["admin"]["uid"]
                                            );

    						    if($idno){
    						      //  print_r($newary); 
        						    
                                    $flg = $db->insertAry("otherfee_structure",$newary);
                                    echo "$flg<br>";
    						    }
                            }

						}
					}
					unlink("media/".$lnewfile);
					die();
					fclose($handle);
				}else{
					echo "File error ".$handle ;
				}
				
				
				
				
				$_SESSION["msg"]="Student imported successfully";
				//////////////////////////**************setting backup table***********////////////////////////////
				if($db->getErMsg()=="")
				redirect("?src=Student&page_id=import_expense");
				else
				$alert_err[] = $db->getErMsg();
				
			} else {
			    echo "error";
			}
		}else{
			$alert_err[]="Invalid file extension";
		}
	}
	
}
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
?> 
<div class="row-fluid">
    <form method="post" action="" enctype="multipart/form-data">
		<div class="span12">

			<div class="top-bar">
				<h3><i class="icon-cog"></i> Import Expense File</h3>
			</div>

			<div class="well no-padding">

				<input type="hidden" name="ss" value="1">
                <div class="control-group">
					<label class="control-label" for="msg">CSV File</label>
					<div class="controls">
                    <!--<a href="<?php echo URL_ROOT ?>media/student.csv" style="float:right" >(Download Sample)</a>-->
						<input type="file" id="file" name="photo" class="input-block-level">
					</div>
				</div>
				<div class="form-actions">
					<button type="submit" class="btn btn-primary"> import</button>
					<button type="reset" class="btn"> Cancel</button>
				</div>

			</div>

		</div>

    </form>
</div>
	
	