<?php
include_once("../include/main.inc.php");
check_session('MyCpanel','index.php');
require_once('excel/reader.php');

################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start)==0 or $start=="")?$start=0:$start;
$pagesize = intval($pagesize)==0?$pagesize=20:$pagesize;


$heading="Upload Database";
$record_type="state";
$script_name="upload_database.php";
$table_name="member_tbl";
#################### Add Record ##################


########################################################
admin_header("Manage $record_type");	

 if(isset($_POST['upload']))
{
  $path="database/";	
 if($_FILES['uploaded']['name'] !='')
			{  				
			$tempname   = $_FILES['uploaded']['tmp_name'];
			$attachment = move_uploaded_file($tempname,$path.$_FILES['uploaded']['name']);		
			$filecontet1 = file_get_contents($path.$_FILES['uploaded']['name']);
			$data = new Spreadsheet_Excel_Reader();
			$data->setOutputEncoding('CP1251');
			$data->read('database/database.xls');
 			for ($x=2; $x <= count($data->sheets[0]["cells"]); $x++) {
    		$Company_Names = trim($data->sheets[0]["cells"][$x][1]);
    		$contact_name = trim($data->sheets[0]["cells"][$x][2]);
    		$Mobile = trim($data->sheets[0]["cells"][$x][3]);
    		$email = trim($data->sheets[0]["cells"][$x][4]);
    		$Tel = trim($data->sheets[0]["cells"][$x][5]);
    		$Mobile2 = trim($data->sheets[0]["cells"][$x][6]);
    		$Address = trim($data->sheets[0]["cells"][$x][7]);
    		$City = trim($data->sheets[0]["cells"][$x][8]);
    		$Postal_Code = trim($data->sheets[0]["cells"][$x][9]);
    		$state = trim($data->sheets[0]["cells"][$x][10]);
    		$Country = trim($data->sheets[0]["cells"][$x][11]);
    		$products = trim($data->sheets[0]["cells"][$x][12]);
    		$date=date("Y/m/d");
    		
    		
    		$companyRes=getResult("member_tbl"," where email='$email' or mobileNo='$Mobile'");
    		
    		if ($companyRes[email]=='') {
    		
    		$sql = "INSERT INTO member_tbl (email,pwd,memberName,phone,mobileNo,companyName,address,city,zipcode,state,country,companyDescription,offertosell,mobileNo2,recvDate)	VALUES ('$email','naturaltherapyindia','$contact_name','$Tel','$Mobile','$Company_Name','$Address','$City','$Postal_Code','$state','$Country','$products','$products','$Mobile2','$date')";
    		
    		echo $sql."\n";
    mysql_query($sql);
    
    echo "rahul";
    		
		}
    	
    		echo "testing";
    
			}
			}
			else 
			{
		  $error1 ="<span style='color:#FF0000; font-size:12px; '>you can not upload more than 1 mb file</span>";
			}	
 			
            //$sql = "INSERT into resume() values('$fname[0]','$lname[1]','$email[2]')";
           // mysql_query($sql) or die(mysql_error());
      
}
?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
1. Always upload database.xls file</br>
2. Always file save in "Excel 97 2003 Workbook" format</br></br>
 Please choose a file: <input name="uploaded" type="file" /><br />
 <input type="submit" name="upload" value="upload" />
 </form>
 
                </tr>
			
                </table>
              </div>
</td>
</tr>

</table>
<?

admin_footer();
exit;
?>