<?php


session_start();

include 'connect.php';

if(isset($_SESSION['adminemail']))

{

$user=$_SESSION['adminemail'];



$gtp=mysql_query("select * from admin where username='$user'");

$gtp1=mysql_fetch_array($gtp);




require_once 'PHPExcel.php';



require_once 'PHPExcel/IOFactory.php';



// Create new PHPExcel object



$objPHPExcel = new PHPExcel();



// Create a first sheet, representing sales data



//$objPHPExcel->setActiveSheetIndex(0);



$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Something');



// Rename sheet



//$objPHPExcel->getActiveSheet()->setTitle('Name of Sheet 1');



// Create a new worksheet, after the default sheet



$objPHPExcel->createSheet();



// Add some data to the second sheet, resembling some different data types



$objPHPExcel->setActiveSheetIndex(1);



$styleArray = array(



'font'  => array(



    'bold'  => true,



    'color' => array('rgb' => 'FF0000'),



));



$stylearr = array(



'font'  => array(



    'bold'  => true,



    'color' => array('rgb' => 'BD3A00'),



));





$stylear = array(



'font'  => array(



    'bold'  => true,



	'color' => array('rgb' => '00A404'),



));



$style = array(



'font'  => array(



    'bold'  => true,



));



$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);



$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(30);



$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(30);





$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Coconut Project');





$objPHPExcel->getActiveSheet()->getStyle("D1")->applyFromArray($styleArray);



$objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,));





$objPHPExcel->getActiveSheet()->setCellValue('A3', 'S.No.')->getStyle("A3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('B3', 'Name')->getStyle("B3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('C3', 'Mobile No.')->getStyle("C3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('D3', 'Village')->getStyle("D3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('E3', 'Taluk')->getStyle("E3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('F3', 'District')->getStyle("F3")->applyFromArray($style);



 $objPHPExcel->getActiveSheet()->setCellValue('G3', 'State')->getStyle("G3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('H3', 'Agriculture Experience')->getStyle("H3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('I3', 'Farming')->getStyle("I3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('J3', 'Variety')->getStyle("J3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('K3', 'Inter Crops')->getStyle("K3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('L3', 'Which type of fertilizer are used')->getStyle("L3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('M3', 'Irrigation System')->getStyle("M3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('N3', 'Types of soil')->getStyle("N3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('O3', 'Average yield per tree')->getStyle("O3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('P3', 'Which type of problem')->getStyle("P3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('Q3', 'Total agri land')->getStyle("Q3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('R3', 'Spacing Distance')->getStyle("R3")->applyFromArray($style);



$objPHPExcel->getActiveSheet()->setCellValue('S3', 'Crop Stage')->getStyle("S3")->applyFromArray($style);





$z=5;



$sno=0;


if($nmrw>0)
{

$get="select * from coconutproject order by ID ASC";

}
else
{
	
	$empd=mysql_query("select * from employee where username='$user'");
	$empd1=mysql_fetch_array($empd);

	$usr=$empd1['ID'];
	
	$get="select * from coconutproject order by ID ASC";
	
}

$getsite4=mysql_query($get);

$r=mysql_num_rows($getsite4);

while($getsite5=mysql_fetch_array($getsite4))

{



$a='A'.$z;

$b='B'.$z;

$c='C'.$z;

$d='D'.$z;

$e='E'.$z;

$f='F'.$z;

$g='G'.$z;

$h='H'.$z;

$i='I'.$z;

$j='J'.$z;

$k='K'.$z;

$l='L'.$z;

$m='M'.$z;

$n='N'.$z;

$o='O'.$z;

$p='P'.$z;

$q='Q'.$z;

$r='R'.$z;

$s='S'.$z;





$vil=mysql_query("select * from villages where ID='$getsite5[village]'");

$vil1=mysql_fetch_array($vil);





$tlk=mysql_query("select * from taluk where ID='$getsite5[taluk]'");

$tlk1=mysql_fetch_array($tlk);





$dis=mysql_query("select * from districts where ID='$getsite5[district]'");

$dis1=mysql_fetch_array($dis);





$ste=mysql_query("select * from statecode where ID='$getsite5[state]'");

$ste1=mysql_fetch_array($ste);



if($getsite5['variety']=='Others')
{
	$variety=$getsite5['variety1'];
}
else
{
	$variety=$getsite5['variety'];
}



$sno=$sno+1;





$objPHPExcel->getActiveSheet()->setCellValue($a, $sno);



$objPHPExcel->getActiveSheet()->setCellValue($b, $getsite5['name']);



$objPHPExcel->getActiveSheet()->setCellValue($c, $getsite5['mobile']);



$objPHPExcel->getActiveSheet()->setCellValue($d, $vil1['village']);



$objPHPExcel->getActiveSheet()->setCellValue($e, $tlk1['taluk']);



$objPHPExcel->getActiveSheet()->setCellValue($f, $dis1['district']);



$objPHPExcel->getActiveSheet()->setCellValue($g, $ste1['state']);



$objPHPExcel->getActiveSheet()->setCellValue($h, $getsite5['agricultureexperience']);



$objPHPExcel->getActiveSheet()->setCellValue($i, $getsite5['farming']);



$objPHPExcel->getActiveSheet()->setCellValue($j, $variety);



$objPHPExcel->getActiveSheet()->setCellValue($k, $getsite5['intercrops']);



$objPHPExcel->getActiveSheet()->setCellValue($l, $getsite5['whichtypeoffertilizer']);



$objPHPExcel->getActiveSheet()->setCellValue($m, $getsite5['irrigationsystem']);



$objPHPExcel->getActiveSheet()->setCellValue($n, $getsite5['typesofsoil']);



$objPHPExcel->getActiveSheet()->setCellValue($o, $getsite5['averageyieldpertree']);



$objPHPExcel->getActiveSheet()->setCellValue($p, $getsite5['whichtypeofproblem']);



$objPHPExcel->getActiveSheet()->setCellValue($q, $getsite5['totalagriland']);



$objPHPExcel->getActiveSheet()->setCellValue($r, $getsite5['spacingdistance']);



$objPHPExcel->getActiveSheet()->setCellValue($s, $getsite5['cropstage']);



$z=$z+1;



}







// Rename 2nd sheet





$objPHPExcel->getActiveSheet()->setTitle('Coconut_Project');



// Redirect output to a client’s web browser (Excel5)



header('Content-Type: application/vnd.ms-excel');



header('Content-Disposition: attachment;filename="coconutproject.xls"');



header('Cache-Control: max-age=0');



$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');



$objWriter->save('php://output');





}







?>