<?php
require_once "../config/connect.php";
set_time_limit(10);


require_once "class.writeexcel_workbook.inc.php";
require_once "class.writeexcel_worksheet.inc.php";


$fname = tempnam("/tmp", "bookStatus.xls");
$workbook = &new writeexcel_workbook($fname);
$worksheet = &$workbook->addworksheet('Books Status');

# The general syntax is write($row, $column, $token). Note that row and
# column are zero indexed
#
$header =& $workbook->addformat();
$header->set_size(10);
$header->set_color('white');
$header->set_align('center');
$header->set_align('vcenter');
$header->set_pattern();
$header->set_fg_color('grey');

$worksheet->set_column(0,0,40);
$worksheet->set_column(0,1,40);
$worksheet->set_column(0,2,40);
$worksheet->set_column(0,3,40);
$worksheet->set_column(0,4,40);
$worksheet->set_column(0,5,40);

$center =& $workbook->addformat();
$center->set_align('center');

# Write some text
$worksheet->write(0, 0,  "Title", $header);
$worksheet->write(0, 1,  "Author", $header);
$worksheet->write(0, 2,  "Publisher Name", $header);
$worksheet->write(0, 3,  "Place of Publication", $header);
$worksheet->write(0, 4,  "ISBN Number", $header);
$worksheet->write(0, 5,  "Subject", $header);

# Write some numbers

$books = mysql_query("SELECT * FROM books") or die(mysql_error());
$count = 0;
WHILE($data = mysql_fetch_array($books)){
	$count++;
	$title = $data['title'];
	$author = $data['author'];
	$publisher_name = $data['publisher_name'];
	$Place_publication = $data['place_publication'];
	$isbn_no = $data['isbn_no'];
	$subclass_1 = $data['subclass_1'];
	$worksheet->write($count, 0, $title); 
	$worksheet->write($count, 1, $author); 
	$worksheet->write($count, 2, $publisher_name); 
	$worksheet->write($count, 3, $Place_publication); 
	$worksheet->write($count, 4, $isbn_no); 
	$worksheet->write($count, 5, $subclass_1); 
}




$workbook->close();

header("Content-Type: application/x-msexcel; name=\"bookStatus.xls\"");
header("Content-Disposition: inline; filename=\"bookStatus.xls\"");
$fh=fopen($fname, "rb");
fpassthru($fh);
unlink($fname);

?>
