-
Notifications
You must be signed in to change notification settings - Fork 3
/
FormDesigner.php
275 lines (274 loc) · 15.3 KB
/
FormDesigner.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
/* $Id$ */
include('includes/session.inc');
$title = _('Form Designer');
include('includes/header.inc');
function FontSizes() {
return array(6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24); //Possible font sizes
}
function SimpleTextLine($key) {
/* Displays a table row containing the attributes for a
* line of text of type `SimpleText` and the values
* given in the object $key
*/
$FontSizes=FontSizes();
echo '<td class="number">'._('Font Size').' = '.'</td><td><select name="'.$key['id'].'FontSize">';
foreach ($FontSizes as $FontSize) {
if ($FontSize==$key->FontSize) {
echo '<option selected="True" value="'.$FontSize.'">'.$FontSize.'</option>';
} else {
echo '<option value="'.$FontSize.'">'.$FontSize.'</option>';
}
}
echo '</select></td>';
/* Display the X co-ordinate (mm from the left hand side of page) */
echo '<td class="number">'._('x').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'x" size="4" maxlength="4" value="'.$key->x.'" /></td>';
/* Display the Y co-ordinate (mm from the top of the page) */
echo '<td class="number">'._('y').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'y" size="4" maxlength="4" value="'.$key->y.'" /></td>';
}
function MultiTextLine($key) {
/* Displays a table row containing the attributes for a
* line of text of type `MultiLineText` and the values
* given in the object $key
*/
$FontSizes=FontSizes();
echo '<td class="number">'._('Font Size').' = '.'</td><td><select name="'.$key['id'].'FontSize">';
foreach ($FontSizes as $FontSize) {
if ($FontSize==$key->FontSize) {
echo '<option selected="True" value="'.$FontSize.'">'.$FontSize.'</option>';
} else {
echo '<option value="'.$FontSize.'">'.$FontSize.'</option>';
}
}
echo '</select></td>';
/* Display the length of the field in mm */
echo '<td class="number">'._('Length').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'Length" size="4" maxlength="4" value="'.$key->Length.'" /></td></tr><tr>';
/* Display the X co-ordinate (mm from the left hand side of page) */
echo '<td class="number">'._('x').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'x" size="4" maxlength="4" value="'.$key->x.'" /></td>';
/* Display the Y co-ordinate (mm from the top of the page) */
echo '<td class="number">'._('y').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'y" size="4" maxlength="4" value="'.$key->y.'" /></td>';
}
function DataTextLine($key) {
/* Displays a table row containing the attributes for a
* line of text of type `DataText` and the values
* given in the object $key
*/
$FontSizes=FontSizes();
echo '<td class="number">'._('Font Size').' = '.'</td><td><select name="'.$key['id'].'FontSize">';
foreach ($FontSizes as $FontSize) {
if ($FontSize==$key->FontSize) {
echo '<option selected="True" value="'.$FontSize.'">'.$FontSize.'</option>';
} else {
echo '<option value="'.$FontSize.'">'.$FontSize.'</option>';
}
}
echo '</select></td>';
/* Display the length of the field in mm */
echo '<td class="number">'._('Length').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'Length" size="4" maxlength="4" value="'.$key->Length.'" /></td>';
/* Display the X co-ordinate (mm from the left hand side of page) */
echo '<td class="number">'._('x').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'x" size="4" maxlength="4" value="'.$key->x.'" /></td>';
}
/* If the user has chosen to either preview the form, or
* save it then we first have to get the POST values into a
* simplexml object and then save the file as either a
* temporary file, or into the main code
*/
if (isset($_POST['preview']) or isset($_POST['save'])) {
/*First create a simple xml object from the main file */
$FormDesign = simplexml_load_file($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName']);
$FormDesign['name']=$_POST['formname'];
if (substr($_POST['PaperSize'],-8)=='Portrait') {
$_POST['PaperSize']=substr($_POST['PaperSize'],0,strlen($_POST['PaperSize'])-9);
}
$FormDesign->PaperSize=$_POST['PaperSize'];
$FormDesign->LineHeight=$_POST['LineHeight'];
/*Iterate through the object filling in the values from
* the POST variables */
foreach ($FormDesign as $key) {
foreach ($key as $subkey=>$value) {
if ($key['type']=='ElementArray') {
foreach ($value as $subsubkey=>$subvalue) {
$value->$subsubkey = $_POST[$value['id'].$subsubkey];
}
} else {
$key->$subkey = $_POST[$key['id'].$subkey];
}
}
}
/* If we are just previewing the form then
* save it to the temporary directory and call the
* PDF creating script */
if (isset($_POST['preview'])) {
$FormDesign->asXML(sys_get_temp_dir().'/'.$_POST['FormName']);
switch ($_POST['FormName']) {
case 'PurchaseOrder.xml':
echo '<meta http-equiv="Refresh" content="0; url=' . $rootpath . '/PO_PDFPurchOrder.php?OrderNo=Preview">';
break;
case 'GoodsReceived.xml':
echo '<meta http-equiv="Refresh" content="0; url=' . $rootpath . '/PDFGrn.php?GRNNo=Preview&PONo=1">';
break;
case 'SalesInvoice.xml':
echo '<meta http-equiv="Refresh" content="0; url=' . $rootpath . '/PrintCustTrans.php?FromTransNo=Preview&InvOrCredit=Invoice&PrintPDF=True">';
break;
case 'PickingList.xml':
echo '<meta http-equiv="Refresh" content="0; url=' . $rootpath . '/PDFPickingList.php?TransNo=Preview">';
break;
}
} else {
/* otherwise check that the web server has write premissions on the companies
* directory and save the xml file to the correct directory */
if (is_writable($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName'])) {
$FormDesign->asXML($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName']);
} else {
prnMsg( _('The web server does not have write permissions on the file ').'<br />'.$PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName'].
'<br />'._('Your changes cannot be saved').'<br />'._('See your system administrator to correct this problem'), 'error');
}
}
}
/* If no form has been selected to edit, then offer a
* drop down list of possible forms */
if (empty($_POST['FormName'])) {
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' . $title.'</p><br />';
echo '<form method="post" id="ChooseForm" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection"><tr>';
echo '<td>'. _('Select the form to edit') .'</td><td><select name="FormName">';
/* Iterate throght the appropriate companies FormDesigns/ directory
* and extract the form name from each of the xml files found */
if ($handle = opendir($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/')) {
while (false !== ($file = readdir($handle))) {
if ($file[0]!='.') {
$FormDesign = simplexml_load_file($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$file);
echo '<option value="'.$file.'">'.$FormDesign['name'].'</option>';
}
}
closedir($handle);
}
echo '</select></td></tr></table>';
echo '<br /><div class="centre"><button tabindex="6" type="submit" name="submit">' . _('Edit Form Layout') . '</button></div><br />';
echo '</form>';
include('includes/footer.inc');
exit;
} // End of if (empty($_POST['FormName']))
/* If we are not previewing the form then load up the simplexml
* object from the main xml file */
if (empty($_POST['preview'])) {
$FormDesign = simplexml_load_file($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/'.$_POST['FormName']);
}
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/reports.png" title="' . _('Form Design') . '" alt="" />' .
' ' . _('Form Design').'<br />'. $FormDesign['name'] . '</p>';
echo '<div class="page_help_text">' . _('Enter the changes that you want in the form layout below.') .'<br /> '. _('All measurements are in points (72dpi = 72pts per inch)') . '.</div><br />';
$Papers=array('A4_Landscape', 'A4_Portrait', 'A5_Landscape', 'A5_Portrait', 'A3_Landscape', 'A3_Portrait', 'letter_Portrait', 'letter_Landscape', 'legal_Portrait', 'legal_Landscape'); // Possible paper sizes/orientations
echo '<form method="post" id="Form" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<input name="FormName" type="hidden" value="'.$_POST['FormName'].'" />';
echo '<table width="95%" class="selection">'; //Start of outer table
echo '<tr><th width="33%" class="header">'._('Form Name').' <input type="text" name="formname" value="'.$FormDesign['name'].'" /></th>';
/* Select the paper size/orientation */
echo '<th width="33%" class="header">'._('Paper Size').' <select name="PaperSize">';
foreach ($Papers as $Paper) {
if (substr($Paper,-8)=='Portrait') {
$PaperValue=substr($Paper,0,strlen($Paper)-9);
} else {
$PaperValue=$Paper;
}
if ($PaperValue==$FormDesign->PaperSize) {
echo '<option selected="True" value="'.$PaperValue.'">'.$Paper.'</option>';
} else {
echo '<option value="'.$PaperValue.'">'.$Paper.'</option>';
}
}
echo '</select></th>';
/* and the standard line height for the form */
echo '<th width="33%" class="header">'._('Line Height').' <input type="text" class="number" name="LineHeight" size="3" maxlength="3" value="'.$FormDesign->LineHeight.'" /></th></tr><tr>';
$counter=1; // Count how many sub tables are in the row
foreach ($FormDesign as $key) {
switch ($key['type']) {
case 'image':
echo '<td colspan="1" valign="top"><table width="100%" class="selection"><tr><th colspan="8" class="header">'.$key['name'].'</th></tr>';
echo '<td class="number">'._('x').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'x" size="4" maxlength="4" value="'.$key->x.'" /></td>';
echo '<td class="number">'._('y').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'y" size="4" maxlength="4" value="'.$key->y.'" /></td>';
echo '<td class="number">'._('Width').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'width" size="4" maxlength="4" value="'.$key->width.'" /></td>';
echo '<td class="number">'._('Height').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'height" size="4" maxlength="4" value="'.$key->height.'" /></td>';
echo '</table></td>';
$counter=$counter+1;
break;
case 'SimpleText':
echo '<td colspan="1" valign="top"><table width="100%" class="selection"><tr><th colspan="6" class="header">'.$key['name'].'</th></tr>'."\n";
SimpleTextLine($key);
echo '</table></td>';
$counter=$counter+1;
break;
case 'MultiLineText':
echo '<td colspan="1" valign="top"><table width="100%" class="selection"><tr><th colspan="4" class="header">'.$key['name'].'</th></tr>'."\n";
MultiTextLine($key);
echo '</table></td>';
$counter=$counter+1;
break;
case 'ElementArray':
echo '<td colspan="1" valign="top"><table width="100%" class="selection"><tr><th colspan="7" class="header">'.$key['name'].'</th></tr>'."\n";
foreach ($key as $subkey) {
if ($subkey['type']=='SimpleText') {
echo '<tr>';
echo '<td>'.$subkey['name'].'</td>';
SimpleTextLine($subkey);
echo '</tr>';
} else if ($subkey['type']=='MultiLineText') {
echo '<tr>';
echo '<td>'.$subkey['name'].'</td>';
MultiTextLine($subkey);
echo '</tr>';
} else {
echo '<tr>';
if ($subkey['type']=='DataText') {
echo '<td>'.$subkey['name'].'</td>';
DataTextLine($subkey);
} elseif ($subkey['type']=='StartLine') {
echo '<td colspan="3">'.$subkey['name'].' = '.'</td><td><input type="text" class="number" name="StartLine" size="4" maxlength="4" value="'.$key->y.'" /></td>';
}
echo '</tr>';
}
}
echo '</table></td>';
$counter=$counter+1;
break;
case 'CurvedRectangle':
echo '<td colspan="1" valign="top"><table width="100%" class="selection"><tr><th colspan="6" class="header">'.$key['name'].'</th></tr>';
echo '<td class="number">'._('x').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'x" size="4" maxlength="4" value="'.$key->x.'" /></td>';
echo '<td class="number">'._('y').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'y" size="4" maxlength="4" value="'.$key->y.'" /></td>';
echo '<td class="number">'._('Width').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'width" size="4" maxlength="4" value="'.$key->width.'" /></td></tr><tr>';
echo '<td class="number">'._('Height').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'height" size="4" maxlength="4" value="'.$key->height.'" /></td>';
echo '<td class="number">'._('Radius').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'radius" size="3" maxlength="3" value="'.$key->radius.'" /></td>';
echo '</table></td>';
$counter=$counter+1;
break;
case 'Rectangle':
echo '<td colspan="1" valign="top"><table width="100%" class="selection"><tr><th colspan="6" class="header">'.$key['name'].'</th></tr>';
echo '<td class="number">'._('x').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'x" size="4" maxlength="4" value="'.$key->x.'" /></td>';
echo '<td class="number">'._('y').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'y" size="4" maxlength="4" value="'.$key->y.'" /></td></tr><tr>';
echo '<td class="number">'._('Width').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'width" size="4" maxlength="4" value="'.$key->width.'" /></td>';
echo '<td class="number">'._('Height').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'height" size="4" maxlength="4" value="'.$key->height.'" /></td>';
echo '</table></td>';
$counter=$counter+1;
break;
case 'Line':
echo '<td colspan="1" valign="top"><table width="100%" class="selection"><tr><th colspan="6" class="header">'.$key['name'].'</th></tr>';
echo '<td class="number">'._('Start x co-ordinate').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'startx" size="4" maxlength="4" value="'.$key->startx.'" /></td>';
echo '<td class="number">'._('Start y co-ordinate').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'starty" size="4" maxlength="4" value="'.$key->starty.'" /></td></tr><tr>';
echo '<td class="number">'._('End x co-ordinate').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'endx" size="4" maxlength="4" value="'.$key->endx.'" /></td>';
echo '<td class="number">'._('End y co-ordinate').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'endy" size="4" maxlength="4" value="'.$key->endy.'" /></td>';
echo '</table></td>';
$counter=$counter+1;
break;
}
if ($counter==4) { // If the row is full start a new one
$counter=1;
echo '</tr><tr>';
}
}
echo '</tr></table>'; //End of outer table
echo '<br /><div class="centre"><button tabindex="6" type="submit" name="preview">' . _('Preview the Form Layout') . '</button></div>';
echo '<br /><div class="centre"><button tabindex="6" type="submit" name="save">' . _('Save the Form Layout') . '</button></div><br />';
echo '</form>';
include('includes/footer.inc');
?>