Order #Item #Order QuantityPricePrice With Tax';
}
PANEL='xlsDetail'
{
DESC='';
DETAILS=' $ODORD$ODITEM$ODQTY$ODPRIC';
}
PANEL='xlsFooter'
{
DESC='';
DETAILS='
FalseFalse ';
}
}
PREVIEWS='*'
{
PREVIEW='Main List'
{
SEG='ListHeader';
SEG='ListDetails'
{
REPEAT='10';
}
SEG='ListFooter';
}
}
ACTIONS='
// Program Name: phptoexcelv2.php
// Program Title: Example 150 - Convert table to XLS with PHP
// Created by: FENRIR
// Template family: Idaho
// Template name: List All Records in File
// Purpose:
// Program Modifications:
// DB Connection code
require(\'/esdi/websmart/v7.0/include/xl_functions001.php\');
$options = array(\'i5_naming\' => DB2_I5_NAMING_ON);
global $db2conn;
$db2conn = xl_db2_connect($options);
if(!$db2conn)
{
die(\'Failed to connect to database!\');
}
// Check the cookie
if(isset($_COOKIE[\'wsnumbc\']))
{
$wsnum = $_COOKIE[\'wsnumbc\'];
}
else
{
setcookie(\'wsnumbc\', $wsnum);
}
// Global variable for calculated fields
// Global variables should be defined here
global $title;
global $authName;
global $fileName;
global $rowCount;
// As a default task for this program, execute the display function
if ($pf_task == \'default\')
display();
if ($pf_task == \'toexcel\')
toExcel();
// close the database connection
db2_close($db2conn);
/********************
End of mainline code
********************/
function display()
{
// Make all global variables available here
foreach($GLOBALS as $arraykey=>$arrayvalue)
{
global $$arraykey;
}
$query = \'select ODORD, ODITEM, ODQTY, ODPRIC from XL_WEBDEMO/MU_ORDDF where ODORD = 100026\';
// Fetch rows for page: relative to initial cursor
if (!($stmt = db2_exec($db2conn, $query)))
{
// close the database connection
db2_close($db2conn);
die("Error ".db2_stmt_error() .":".db2_stmt_errormsg(). "");
}
// Output header
wrtseg("ListHeader");
while ($row = db2_fetch_assoc($stmt))
{
// set color of the line
xl_set_row_color(\'altcol1\', \'altcol2\');
$ODORD = $row[\'ODORD\'];
$ODITEM = $row[\'ODITEM\'];
$ODQTY = $row[\'ODQTY\'];
$ODPRIC = $row[\'ODPRIC\'];
wrtseg("ListDetails");
}
wrtseg("ListFooter");
}
function toExcel()
{
// Make all global variables available here
foreach($GLOBALS as $arraykey=>$arrayvalue)
{
global $$arraykey;
}
$query = \'select ODORD, ODITEM, ODQTY, ODPRIC from XL_WEBDEMO/MU_ORDDF where ODORD = 100026\';
// Fetch rows for page: relative to initial cursor
if (!($stmt = db2_exec($db2conn, $query)))
{
echo "Error ".db2_stmt_error() .":".db2_stmt_errormsg(). "";
die;
}
// Output header
wrtHeader();
$rowCount = 0;
while ($row = db2_fetch_assoc($stmt))
{
$ODORD = $row[\'ODORD\'];
$ODITEM = $row[\'ODITEM\'];
$ODQTY = $row[\'ODQTY\'];
$ODPRIC = $row[\'ODPRIC\'];
$rowCount++;
// Output details
wrtseg("xlsDetail");
}
// Output footer
wrtseg("xlsFooter");
}
function wrtHeader()
{
// Make all global variables available here
foreach($GLOBALS as $arraykey=>$arrayvalue)
{
if($arraykey[0]!=\'_\' && $arraykey != \'GLOBALS\')
global $$arraykey;
}
// Set worksheet title
if(isset($_REQUEST[\'xlsTitle\']))
{
$title = htmlspecialchars($_REQUEST[\'xlsTitle\']);
}
else
{
$title = "Worksheet 1";
}
// strip out special chars first
$title = preg_replace ("/[\\\\\\|:|\\/|\\?|\\*|\\[|\\]]/", "", $title);
// Substring it to the allowed length
$title = substr ($title, 0, 31);
// Set author name
$authName = "Author\'s Name";
// Strip out special characters
$authName = preg_replace ("/[\\\\\\|:|\\/|\\?|\\*|\\[|\\]]/", "", $authName);
// Set XLS file name
if(isset($_REQUEST[\'xlsName\']))
{
$fileName = htmlspecialchars($_REQUEST[\'xlsName\']);
}
else
{
$fileName = "Excel1";
}
// Set content headers
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Content-Disposition: inline; filename=\\"" . $fileName . ".xls\\"");
header("Cache-Control: private");
// Output Header XML
wrtseg("xlsHeader");
}';
}