-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
executable file
·109 lines (94 loc) · 3 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
require 'vendor/autoload.php';
use \PhpOffice\PhpWord\PhpWord;
use \PhpOffice\PhpWord\Template;
$fileName = 'file.docx';
$tagsWanted = array(
'NUNBER_OF_FTE',
'ACTUAL_NUMBER_OF_HACCP_plans',
'EFFECTIVE_ON_SITE_AUDIT_DURATION',
'FSSC_Company_Number'
);
$header = array(
'Alias',
'Tag',
'Content',
'Checkbox selected',
'Is float'
);
$table = array();
$table[] = $header;
if (file_exists($fileName)) {
$word = \PhpOffice\PhpWord\IOFactory::load($fileName);
$tags = $word->getTags();
if (!empty($tags)) {
foreach ($tags as $tag) {
$isTag = isset($tag['property']['tag']) && in_array(
$tag['property']['tag'],
$tagsWanted
);
if (isset($tag['property']) &&
isset($tag['property']['alias']) &&
isset($tag['property']['tag'])
/** &&
(
$isTag ||
isset($tag['property']['is_checkbox']) && $tag['property']['is_checkbox'] ||
isset($tag['property']['is_date']) && $tag['property']['is_date']
)
**/
) {
$isCheckBox = isset($tag['property']['is_checkbox']) && $tag['property']['is_checkbox'];
$float = null;
if ($isTag) {
if (is_numeric($tag['content']['content'])) {
$float = (float)$tag['content']['content'];
if (is_float($float)) {
$float = 'true';
} else {
$float = 'false';
}
} else {
$float = 'false';
}
}
$checkBoxResult = null;
if ($isCheckBox) {
$checkBoxResult = $tag['property']['checkbox_selected'];
}
$row = array(
$tag['property']['alias'],
$tag['property']['tag'],
$tag['content']['content'],
$checkBoxResult,
$float
);
if (!($checkBoxResult == '0')) {
$table[] = $row;
}
}
}
if (!empty($table)) {
echo '<table border="1" style="border-collapse:collapse;">';
foreach ($table as $row) {
echo '<tr><td>';
echo $row[0];
echo '<td>';
echo $row[1];
echo '<td>';
echo $row[2];
echo '</td><td>';
echo $row[3];
echo '</td><td>';
echo $row[4];
echo '</td></tr>';
}
}
}
// Extracts the document.xml file
$template = new Template($fileName);
file_put_contents(basename($fileName) . '.xml', $template->documentXML);
} else {
echo "File doesn't exists $fileName";
}
exit;