4
include_once('tbs_class.php'); // Load the TinyButStrong template engine
5
include_once('../tbs_plugin_opentbs.php'); // Load the OpenTBS plugin
7
// prevent from a PHP configuration problem when using mktime() and date()
8
if (version_compare(PHP_VERSION,'5.1.0')>=0) {
9
if (ini_get('date.timezone')=='') {
10
date_default_timezone_set('UTC');
14
// Initialize the TBS instance
15
$TBS = new clsTinyButStrong; // new instance of TBS
16
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load the OpenTBS plugin
18
// ------------------------------
19
// Prepare some data for the demo
20
// ------------------------------
22
// Retrieve the user name to display
23
$yourname = (isset($_POST['yourname'])) ? $_POST['yourname'] : '';
24
$yourname = trim(''.$yourname);
25
if ($yourname=='') $yourname = "(no name)";
27
// A recordset for merging tables
29
$data[] = array('rank'=> 'A', 'firstname'=>'Sandra' , 'name'=>'Hill' , 'number'=>'1523d', 'score'=>200, 'visits'=>15, 'email_1'=>'sh@tbs.com', 'email_2'=>'sandra@tbs.com', 'email_3'=>'s.hill@tbs.com');
30
$data[] = array('rank'=> 'A', 'firstname'=>'Roger' , 'name'=>'Smith' , 'number'=>'1234f', 'score'=>800, 'visits'=>33, 'email_1'=>'rs@tbs.com', 'email_2'=>'robert@tbs.com', 'email_3'=>'r.smith@tbs.com' );
31
$data[] = array('rank'=> 'B', 'firstname'=>'William', 'name'=>'Mac Dowell', 'number'=>'5491y', 'score'=>130, 'visits'=>16, 'email_1'=>'wmc@tbs.com', 'email_2'=>'william@tbs.com', 'email_3'=>'w.m.dowell@tbs.com' );
33
// Other single data items
36
$x_dt = mktime(13,0,0,2,15,2010);
45
$template = 'demo_oo_spreadsheet.ods';
46
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).
48
// ----------------------
49
// Debug mode of the demo
50
// ----------------------
51
if (isset($_POST['debug']) && ($_POST['debug']=='current')) $TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT, true); // Display the intented XML of the current sub-file, and exit.
52
if (isset($_POST['debug']) && ($_POST['debug']=='info')) $TBS->Plugin(OPENTBS_DEBUG_INFO, true); // Display information about the document, and exit.
53
if (isset($_POST['debug']) && ($_POST['debug']=='show')) $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW); // Tells TBS to display information when the document is merged. No exit.
55
// --------------------------------------------
56
// Merging and other operations on the template
57
// --------------------------------------------
59
$TBS->PlugIn(OPENTBS_SELECT_SHEET, "Cells and rows");
61
// Merge data in the first sheet
62
$TBS->MergeBlock('a,b', $data);
64
// Merge cells (extending columns)
65
$TBS->MergeBlock('c1,c2', $data);
67
$TBS->PlugIn(OPENTBS_SELECT_SHEET, "Dynamic columns");
69
// Merge data in Sheet 2
70
$TBS->MergeBlock('dc1,dc2', 'num', 3);
71
$TBS->MergeBlock('b2', $data);
73
$TBS->PlugIn(OPENTBS_SELECT_SHEET, "Charts");
75
// Merge data linked to chart #1
77
array('team' => "M.T.R.", 'victories' => 23),
78
array('team' => "Young-B", 'victories' => 18),
79
array('team' => "Red&Green", 'victories' => 9),
80
array('team' => "Kings", 'victories' => 12),
82
$TBS->MergeBlock('ch', $data);
84
// Merge data embedded in chart #2
92
$TBS->PlugIn(OPENTBS_CHART_DELETE_CATEGORY, 'chart_members_by_category', '*'); // delete all categories used in the template
93
$TBS->PlugIn(OPENTBS_CHART, 'chart_members_by_category', 1, $NewValues);
96
$TBS->PlugIn(OPENTBS_SELECT_SHEET, "Pictures");
98
// Merge pictures of the current sheet
99
$x_picture = 'pic_1523d.gif';
100
//$TBS->PlugIn(OPENTBS_MERGE_SPECIAL_ITEMS);
103
$TBS->PlugIn(OPENTBS_DELETE_SHEETS, 'Sheet to delete');
106
// Display a sheet (make it visible)
107
$TBS->PlugIn(OPENTBS_DISPLAY_SHEETS, 'Sheet to show');
113
// Define the name of the output file
114
$save_as = (isset($_POST['save_as']) && (trim($_POST['save_as'])!=='') && ($_SERVER['SERVER_NAME']=='localhost')) ? trim($_POST['save_as']) : '';
115
$output_file_name = str_replace('.', '_'.date('Y-m-d').$save_as.'.', $template);
117
// Output the result as a downloadable file (only streaming, no data saved in the server)
118
$TBS->Show(OPENTBS_DOWNLOAD, $output_file_name); // Also merges all [onshow] automatic fields.
119
// Be sure that no more output is done, otherwise the download file is corrupted with extra data.
122
// Output the result as a file on the server.
123
$TBS->Show(OPENTBS_FILE, $output_file_name); // Also merges all [onshow] automatic fields.
124
// The script can continue.
125
exit("File [$output_file_name] has been created.");