opentbs

Форк
0
/
demo_ms_word.php 
99 строк · 4.2 Кб
1
<?php
2

3
// Include classes
4
include_once('tbs_class.php'); // Load the TinyButStrong template engine
5
include_once('../tbs_plugin_opentbs.php'); // Load the OpenTBS plugin
6

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');
11
	}
12
}
13

14
// Initialize the TBS instance
15
$TBS = new clsTinyButStrong; // new instance of TBS
16
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load the OpenTBS plugin
17

18
// ------------------------------
19
// Prepare some data for the demo
20
// ------------------------------
21

22
// Retrieve the user name to display
23
$yourname = (isset($_POST['yourname'])) ? $_POST['yourname'] : '';
24
$yourname = trim(''.$yourname);
25
if ($yourname=='') $yourname = "(no name)";
26

27
// A recordset for merging tables
28
$data = array();
29
$data[] = array('rank'=> 'A', 'firstname'=>'Sandra' , 'name'=>'Hill'      , 'number'=>'1523d', 'score'=>200, '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, '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, 'email_1'=>'wmc@tbs.com', 'email_2'=>'william@tbs.com', 'email_3'=>'w.m.dowell@tbs.com' );
32

33
// Other single data items
34
$x_num = 3152.456;
35
$x_pc = 0.2567;
36
$x_dt = mktime(13,0,0,2,15,2010);
37
$x_bt = true;
38
$x_bf = false;
39
$x_delete = 1;
40

41
// -----------------
42
// Load the template
43
// -----------------
44

45
$template = 'demo_ms_word.docx';
46
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).
47

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.
54

55
// --------------------------------------------
56
// Merging and other operations on the template
57
// --------------------------------------------
58

59
// Merge data in the body of the document
60
$TBS->MergeBlock('a,b', $data);
61

62
// Merge data in colmuns
63
$data = array(
64
 array('date' => '2013-10-13', 'thin' => 156, 'heavy' => 128, 'total' => 284),
65
 array('date' => '2013-10-14', 'thin' => 233, 'heavy' =>  25, 'total' => 284),
66
 array('date' => '2013-10-15', 'thin' => 110, 'heavy' => 412, 'total' => 130),
67
 array('date' => '2013-10-16', 'thin' => 258, 'heavy' => 522, 'total' => 258),
68
);
69
$TBS->MergeBlock('c', $data);
70

71

72
// Change chart series
73
$ChartNameOrNum = 'chart_evol_by_cat'; // see Alt. Text of the shape that embeds the chart
74
$SeriesNameOrNum = 'Series 2';
75
$NewValues = array( array('Category A','Category B','Category C','Category D'), array(3, 1.1, 4.0, 3.3) );
76
$NewLegend = "Updated series 2";
77
$TBS->PlugIn(OPENTBS_CHART, $ChartNameOrNum, $SeriesNameOrNum, $NewValues, $NewLegend);
78

79
// Delete comments
80
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
81

82
// -----------------
83
// Output the result
84
// -----------------
85

86
// Define the name of the output file
87
$save_as = (isset($_POST['save_as']) && (trim($_POST['save_as'])!=='') && ($_SERVER['SERVER_NAME']=='localhost')) ? trim($_POST['save_as']) : '';
88
$output_file_name = str_replace('.', '_'.date('Y-m-d').$save_as.'.', $template);
89
if ($save_as==='') {
90
	// Output the result as a downloadable file (only streaming, no data saved in the server)
91
	$TBS->Show(OPENTBS_DOWNLOAD, $output_file_name); // Also merges all [onshow] automatic fields.
92
	// Be sure that no more output is done, otherwise the download file is corrupted with extra data.
93
	exit();
94
} else {
95
	// Output the result as a file on the server.
96
	$TBS->Show(OPENTBS_FILE, $output_file_name); // Also merges all [onshow] automatic fields.
97
	// The script can continue.
98
	exit("File [$output_file_name] has been created.");
99
}
100

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.