Current File : /home/inlingua/public_html/noida/icentex/admin/backup/csv.php |
<?php
//include("check1.php");
//include("connection.php");
//print_r($_SESSION);
$fromdate="2011-09-01";
$toDate="2011-09-30";
$sqlQuery="select * from leaves where ((fromDate>='".$fromdate."' && fromdate<='".$toDate."') || (toDate>='".$fromdate."' && toDate<='".$toDate."')) && status='approved'";
//$sqlQuery1="select * from leaves where toDate>='".$fromdate."' && toDate<='".$toDate."' && status='approved'";
//$result=mysql_query($sqlQuery1);
//$sqlQuery = str_replace("\'", "'", $sqlQuery);
?>
<?php
function export_array_to_csv($inarray) {
while (list ($key1, $val1) = each ($inarray)) {
while (list ($key, $val) = each ($val1)) {
if (is_numeric($val)) {
$sendback .= $val.","; //integer value
}else{
$sendback .= "\"". $val ."\","; //string value
}//fi
}//end of while
$sendback = substr($sendback, 0, -1); //chop last ,
$sendback .= "\n";
}//End of while
return ($sendback);
}// end function
function send_file_to_client($filename, $data) {
header("Content-type: application/ofx");
header("Content-Disposition: attachment; filename=$filename");
echo $data;
};
function send_file_to_client_2($filename, $data) {
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
$file_extension = strtolower(substr(strrchr($filename,"."),1));
//Start condition switch( $file_extension )
switch( $file_extension )
{
case "csv": $ctype="application/force-download";break;
//case "csv": $ctype="application/octet-stream";break;
//case "pdf": $ctype="application/pdf"; break;
//case "exe": $ctype="application/octet-stream"; break;
//case "zip": $ctype="application/zip"; break;
//case "doc": $ctype="application/msword"; break;
//case "xls": $ctype="application/vnd.ms-excel"; break;
//case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
//case "gif": $ctype="image/gif"; break;
//case "png": $ctype="image/png"; break;
//case "jpeg":
//case "jpg": $ctype="image/jpg"; break;
//default: $ctype="application/force-download";
default: echo "<html><title>This file cannot be downloaded</title> <body>ERROR: This file cannot be downloaded</body></html>";exit;
}//End condition switch( $file_extension )
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype; charset=utf-8");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
echo $dataVal;
exit;
}
// Include the database connection details
require('dbConnection.php');
// Include common functions
//require('commonFunc.php');
// Include common functions
//require('globalVars.php');
// Include the table handler class
require('dbHandler.class.php');
// Init and connect to database
$dbObject = new dbHandler();
$dbObject->connect();
$vikas=array();
$vikas1=array();
//$vikas1=array(array("Date","Name","Program/Act","Paymode","ChequeNo","Amount","Remarks","Status","RegisterBy"));
//$year1=date("Y");
//$total=0;
$sqlQuery=$sqlQuery;
//$sqlQuery = "SELECT * FROM register where account='1' && regdProgram in (select recNo from program where forYear='$year1' && location='$_SESSION[location]') order by regdate desc";
$selectedRecords = $dbObject->Select($sqlQuery);
$vikas[0]="Instructor";
$vikas[1]="From Date";
$vikas[2]="To Date";
$vikas[3]="No. of Days";
$vikas[4]="Class Affected";
$vikas[5]="Status";
array_push($vikas1,$vikas);
/*while($num1=mysql_fetch_array($result))
{
$queryName="select * from timesheet_user where recNo='".$num1['timesheet_user_id']."'";
$resultName=mysql_query($queryName);
$numName=mysql_fetch_array($resultName);
$vikas[0]="".$numName['name']."";
$vikas[1]="".$num1[fromDate]."";
$vikas[2]="".$num1[toDate]."";
$vikas[3]="".$num1[noofdays]."";
$vikas[4]="".$num1[classAffected]."";
if($num1['emergencyLeave']=='Yes' && $num1['IsclassesSubstituted']=='No')
{
$addmsg='';
$addmsg='Emergency off and compensated and not applicable for salary and leave deduction';
}
else if($num1['emergencyLeave']==='Yes' && $num1['IsclassesSubstituted']=='Yes')
{
$addmsg='';
$addmsg='Emergency off and substiuted and applicable for salary and leave deduction';
}
else
{
$addmsg='';
}
$vikas[5]="".$addmsg."";
array_push($vikas1,$vikas);
}
*/
while($objectData=$dbObject->SelectNext())
{
$queryName="select * from timesheet_user where recNo='".$objectData['timesheet_user_id']."'";
$resultName=mysql_query($queryName);
$numName=mysql_fetch_array($resultName);
$vikas[0]="".$numName['name']."";
$vikas[1]="".$objectData[fromDate]."";
$vikas[2]="".$objectData[toDate]."";
$vikas[3]="".$objectData[noofdays]."";
$vikas[4]="".$objectData[classAffected]."";
if($objectData['emergencyLeave']=='Yes' && $objectData['IsclassesSubstituted']=='No')
{
$addmsg='';
$addmsg='Emergency off and compensated and not applicable for salary and leave deduction';
}
else if($objectData['emergencyLeave']==='Yes' && $objectData['IsclassesSubstituted']=='Yes')
{
$addmsg='';
$addmsg='Emergency off and substiuted and applicable for salary and leave deduction';
}
else
{
$addmsg='';
}
$vikas[5]="".$addmsg."";
array_push($vikas1,$vikas);
//$query="update orders set download='1' where recNo='$vikas[0]'";
//$result=mysql_query($query) or die(mysql_error());
}
//print_r($vikas1);
//How to use it:
//$dataArr[0][0] = "value1";
//$dataArr[0][1] = "value2";
//$dataArr[1][0] = "value3" ;
//$dataArr[1][1] = "123123123";
//$dataArr[2][0] = "12";
//$dataArr[2][1] = "value4";
//print_r($dataArr);
send_file_to_client("orderdatafile.csv", export_array_to_csv($vikas1));
?>