tce_functions_form.php 19.1 KB
Newer Older
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
1
2
3
4
<?php
//============================================================+
// File name   : tce_functions_form.php
// Begin       : 2001-11-07
Nicola Asuni's avatar
Nicola Asuni committed
5
// Last Update : 2013-04-02
nick's avatar
nick committed
6
//
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
7
8
9
10
11
12
// Description : Functions to handle XHTML Form Fields.
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
Nick's avatar
Nick committed
13
//               Tecnick.com LTD
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
14
15
16
//               www.tecnick.com
//               info@tecnick.com
//
nick's avatar
nick committed
17
// License:
Nicola Asuni's avatar
Nicola Asuni committed
18
//    Copyright (C) 2004-2013 Nicola Asuni - Tecnick.com LTD
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
19
20
21
22
//    See LICENSE.TXT file for more information.
//============================================================+

/**
nick's avatar
nick committed
23
 * @file
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
24
25
26
27
28
29
30
31
32
33
34
35
 * Functions to handle XHTML Form Fields.
 * @package com.tecnick.tcexam.shared
 * @author Nicola Asuni
 * @since 2001-11-07
 */

/**
 */

$formstatus = TRUE; //reset form status

// check buttons actions
Nick's avatar
Nick committed
36
if (isset($_POST['update'])) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
37
	$menu_mode = 'update';
Nick's avatar
Nick committed
38
} elseif (isset($_POST['delete'])) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
39
	$menu_mode = 'delete';
Nick's avatar
Nick committed
40
} elseif (isset($_POST['forcedelete'])) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
41
	$menu_mode = 'forcedelete';
Nick's avatar
Nick committed
42
} elseif (isset($_POST['cancel'])) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
43
	$menu_mode = 'cancel';
Nick's avatar
Nick committed
44
} elseif (isset($_POST['add'])) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
45
	$menu_mode = 'add';
Nick's avatar
Nick committed
46
} elseif (isset($_POST['clear'])) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
47
	$menu_mode = 'clear';
Nick's avatar
Nick committed
48
} elseif (isset($_POST['upload'])) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
49
	$menu_mode = 'upload';
Nick's avatar
Nick committed
50
} elseif (isset($_POST['addquestion'])) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
51
52
	$menu_mode = 'addquestion';
}
Nick's avatar
Nick committed
53
if (!isset($menu_mode)) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
54
55
56
57
58
59
60
61
	$menu_mode = '';
}

/**
 * Returns an array containing form fields.
 * @return array containing form fields
 */
function F_decode_form_fields() {
nick's avatar
nick committed
62
	return $_REQUEST;
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
63
64
65
66
67
}

/**
 * Check Required Form Fields.<br>
 * Returns a string containing a list of missing fields (comma separated).
nick's avatar
nick committed
68
 * @param $formfields (string) input array containing form fields
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
69
70
71
 * @return array containing a list of missing fields (if any)
 */
function F_check_required_fields($formfields) {
Nick's avatar
Nick committed
72
	if (empty($formfields) OR !array_key_exists('ff_required', $formfields) OR strlen($formfields['ff_required']) <= 0) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
73
74
75
76
77
78
79
		return FALSE;
	}
	$missing_fields = '';
	$required_fields = explode(',',$formfields['ff_required']);
	$required_fields_labels = explode(',',$formfields['ff_required_labels']); // form fields labels
	for($i=0; $i<count($required_fields); $i++) { //for each required field
		$fieldname = trim($required_fields[$i]);
Nick's avatar
Nick committed
80
81
		$fieldname = preg_replace('/[^a-z0-9_\[\]]/i', '', $fieldname);
		if (!array_key_exists($fieldname, $formfields) OR strlen(trim($formfields[$fieldname])) <= 0) { //if is empty
Nicola Asuni's avatar
Nicola Asuni committed
82
			if ($required_fields_labels[$i]) { // check if the field has a label
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
83
84
85
86
87
				$fieldname = $required_fields_labels[$i];
			}
			$missing_fields .= ', '.stripslashes($fieldname);
		}
	}
Nick's avatar
Nick committed
88
	if (strlen($missing_fields)>1) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
89
		$missing_fields = substr($missing_fields, 1); // cuts first comma
nick's avatar
nick committed
90
	}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
91
92
93
94
95
96
	return ($missing_fields);
}

/**
 * Check fields format using regular expression comparisons.<br>
 * Returns a string containing a list of wrong fields (comma separated).
nick's avatar
nick committed
97
 *
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
98
99
 * NOTE:
 * to check a field create a new hidden field with the same name starting with 'x_'
nick's avatar
nick committed
100
 *
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
101
102
 * An example powerful regular expression for email check is:
 *  ^([a-zA-Z0-9_\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
nick's avatar
nick committed
103
 * @param $formfields (string) input array containing form fields
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
104
105
106
 * @return array containing a list of wrongfields (if any)
 */
function F_check_fields_format($formfields) {
Nick's avatar
Nick committed
107
	if (empty($formfields)) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
108
109
110
111
		return '';
	}
	reset($formfields);
	$wrongfields = '';
Nicola Asuni's avatar
Nicola Asuni committed
112
113
114
	while (list($key, $value) = each($formfields)) {
		if (substr($key, 0, 2) == 'x_') {
			$fieldname = substr($key, 2);
Nick's avatar
Nick committed
115
116
117
118
			$fieldname = preg_replace('/[^a-z0-9_\[\]]/i', '', $fieldname);
			if (array_key_exists($fieldname, $formfields) AND strlen($formfields[$fieldname]) > 0) { //if is not empty
				if (!preg_match("'".stripslashes($value)."'i", $formfields[$fieldname])) { //check regular expression
					if (isset($formfields['xl_'.$fieldname]) AND !empty($formfields['xl_'.$fieldname])) { //check if field has label
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
119
120
121
122
123
124
125
						$fieldname = $formfields['xl_'.$fieldname];
					}
					$wrongfields .= ', '.stripslashes($fieldname);
				}
			}
		}
	}
Nick's avatar
Nick committed
126
	if (strlen($wrongfields) > 1) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
127
		$wrongfields = substr($wrongfields, 2); // cuts first 2 chars
nick's avatar
nick committed
128
	}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
129
130
131
132
133
134
135
136
137
138
139
140
141
	return ($wrongfields);
}

/**
 * Check Form Fields.
 * see: F_check_required_fields, F_check_fields_format
 * @return false in case of error, true otherwise
 */
function F_check_form_fields() {
	require_once('../config/tce_config.php');
	global $l;
	$formfields = F_decode_form_fields(); //decode form fields
	//check missing fields
Nick's avatar
Nick committed
142
	if ($missing_fields = F_check_required_fields($formfields)) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
143
144
145
146
147
		F_print_error('WARNING', $l['m_form_missing_fields'].': '.$missing_fields);
		F_stripslashes_formfields();
		return FALSE;
	}
	//check fields format
Nick's avatar
Nick committed
148
	if ($wrong_fields = F_check_fields_format($formfields)) {
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
149
150
151
152
153
154
155
156
157
158
159
160
		F_print_error('WARNING', $l['m_form_wrong_fields'].': '.$wrong_fields);
		F_stripslashes_formfields();
		return FALSE;
	}
	return TRUE;
}

/**
 * Strip slashes from posted form fields.
 */
function F_stripslashes_formfields() {
	foreach ($_POST as $key => $value) {
tecnickcom's avatar
tecnickcom committed
161
		if (($key[0] != '_') AND (is_string($value))) {
Nick's avatar
Nick committed
162
			$key = preg_replace('/[^a-z0-9_\[\]]/i', '', $key);
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
163
			global $$key;
Nick's avatar
Nick committed
164
165
166
			if (!isset($$key)) {
				$$key = stripslashes($value);
			}
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
167
168
169
170
171
		}
	}
}

/**
nick's avatar
nick committed
172
 * Returns XHTML code string to display a window close button
nick's avatar
nick committed
173
 * @param $onclick (string) additional javascript code to execute before closing the window.
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
 * @return XHTML code string
 */
function F_close_button($onclick='') {
	require_once('../config/tce_config.php');
	global $l;
	$str = '';
	$str .= '<div class="row">'.K_NEWLINE;
	$str .= '<form action="'.$_SERVER['SCRIPT_NAME'].'" id="closeform">'.K_NEWLINE;
	$str .= '<div>'.K_NEWLINE;
	$str .= '<input type="button" name="wclose" id="wclose" value="'.$l['w_close'].'" title="'.$l['h_close_window'].'" onclick="'.$onclick.'window.close();" />'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	$str .= '</form>'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	return $str;
}

/**
 * Returns XHTML code string to display Form Submit Button.
nick's avatar
nick committed
192
193
194
 * @param $name (string) button name
 * @param $value (string) label for button
 * @param $title (string) button title, default=""
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
195
196
197
198
199
200
 * @return XHTML code string
 */
function F_submit_button($name, $value, $title="") {
	echo '<input type="submit" name="'.$name.'" id="'.$name.'" value="'.$value.'" title="'.$title.'" />';
}

Nick's avatar
Nick committed
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
/**
 * Print input row form.
 * @param $field_name (string) Name of the form field.
 * @param $name (string) Label.
 * @param $description (string) Label description (tooltip).
 * @param $tip (string) Help to be displayed on the right of the input field.
 * @param $value (string) Initial value.
 * @param $format (string) Regular expression to check the format of the field.
 * @param $maxlen (int) Maximum input lenght.
 * @param $date (boolean) True if the field is a date input.
 * @param $datetime (boolean) True if the field is a date-time input.
 * @param $password (boolean) True if the field is a password.
 * @param $prefix (string) code to be displayed after label.
 * @return string
 */
function getFormRowTextInput($field_name, $name, $description='', $tip='', $value='', $format='', $maxlen=255, $date=false, $datetime=false, $password=false, $prefix='') {
	require_once(dirname(__FILE__).'/../config/tce_config.php');
	global $l;
	if (strlen($description) == 0) {
		$description = $name;
	}
	$str = ''; // string to return
	$button = '';
	if ($date) {
		$button = '<button name="'.$field_name.'_date_trigger" id="'.$field_name.'_date_trigger" title="'.$l['w_calendar'].'">...</button>';
		$jsdate = 'Calendar.setup({inputField: "'.$field_name.'", ifFormat: "%Y-%m-%d", button: "'.$field_name.'_date_trigger"});'.K_NEWLINE;
		$format = '^([0-9]{4})([\-])([0-9]{2})([\-])([0-9]{2})$';
		$maxlen = 10;
		if (strlen($tip) == 0) {
			$tip = $l['w_date_format'];
		}

	} elseif ($datetime) {
		$button = '<button name="'.$field_name.'_date_trigger" id="'.$field_name.'_date_trigger" title="'.$l['w_calendar'].'">...</button>';
		$jsdate = 'Calendar.setup({inputField: "'.$field_name.'", ifFormat: "%Y-%m-%d %H:%M:%S", showsTime: "true", button: "'.$field_name.'_date_trigger"});'.K_NEWLINE;
		$format = '^([0-9]{4})([\-])([0-9]{2})([\-])([0-9]{2})([ ])([0-9]{2})([\:])([0-9]{2})([\:])([0-9]{2})$';
		$maxlen = 19;
		if (strlen($tip) == 0) {
			$tip = $l['w_datetime_format'];
		}
	}
	$str .= '<div class="row">'.K_NEWLINE;
	$str .= '<span class="label">'.K_NEWLINE;
	$str .= '<label for="'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
	if (!empty($prefix)) {
		$str .= $prefix;
	}
	$str .= '</span>'.K_NEWLINE;
	$str .= '<span class="formw">'.K_NEWLINE;
	$str .= '<input type="';
	if ($password) {
		$str .= 'password';
	} else {
		$str .= 'text';
	}
Nicola Asuni's avatar
Nicola Asuni committed
256
257
	$str .= '"';
	if ($date OR $datetime) {
Nicola Asuni's avatar
Nicola Asuni committed
258
259
260
261
262
		$str .= ' style="direction:ltr;';
		if ($l['a_meta_dir'] == 'rtl') {
			$str .= 'text-align:right;';
		}
		$str .= '"';
Nicola Asuni's avatar
Nicola Asuni committed
263
264
	}
	$str .= ' name="'.$field_name.'" id="'.$field_name.'" value="'.htmlspecialchars($value, ENT_COMPAT, $l['a_meta_charset']).'" size="20" maxlength="'.$maxlen.'" title="'.$description.'" />';
Nick's avatar
Nick committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
	$str .= $button;
	if (strlen($tip) > 0) {
		$str .= ' <span class="labeldesc">'.$tip.'</span>';
	}
	if (strlen($format) > 0) {
		$str .= '<input type="hidden" name="x_'.$field_name.'" id="x_'.$field_name.'" value="'.$format.'" />'.K_NEWLINE;
		$str .= '<input type="hidden" name="xl_'.$field_name.'" id="xl_'.$field_name.'" value="'.$name.'" />'.K_NEWLINE;
	}
	$str .= '</span>'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	if ($date OR $datetime) {
		$str .= '<script type="text/javascript">'.K_NEWLINE;
		$str .= '//<![CDATA['.K_NEWLINE;
		$str .= $jsdate;
		$str .= '//]]>'.K_NEWLINE;
		$str .= '</script>'.K_NEWLINE;
	}
	return $str;
}

/**
 * Print text box row form.
 * @param $field_name (string) Name of the form field.
 * @param $name (string) Label.
 * @param $description (string) Label description (tooltip).
 * @param $value (string) Initial value.
 * @param $disabled (boolean) If true disable the field.
 * @param $prefix (string) code to be displayed after label.
 * @return string
 */
function getFormRowTextBox($field_name, $name, $description='', $value='', $disabled=false, $prefix='') {
	require_once(dirname(__FILE__).'/../config/tce_config.php');
	global $l;
	if (strlen($description) == 0) {
		$description = $name;
	}
	$str = ''; // string to return
	$str .= '<div class="row">'.K_NEWLINE;
	$str .= '<span class="label">'.K_NEWLINE;
	$str .= '<label for="'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
	if (!empty($prefix)) {
		$str .= $prefix;
	}
	$str .= '</span>'.K_NEWLINE;
	$str .= '<span class="formw">'.K_NEWLINE;
	$str .= '<textarea cols="50" rows="5" name="'.$field_name.'" id="'.$field_name.'" title="'.$description.'"';
	if ($disabled) {
		$str .= ' readonly="readonly" class="disabled"';
	}
	$str .= '>'.htmlspecialchars($value, ENT_NOQUOTES, $l['a_meta_charset']).'</textarea>'.K_NEWLINE;
	$str .= '</span>'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	return $str;
}

/**
 * Print select box row form.
 * @param $field_name (string) Name of the form field.
 * @param $name (string) Label.
 * @param $description (string) Label description (tooltip).
 * @param $tip (string) Help to be displayed on the right of the input field.
 * @param $value (string) Initial value.
 * @param $items (array) array of items to print key => value.
 * @param $prefix (string) code to be displayed after label.
 * @return string
 */
function getFormRowSelectBox($field_name, $name, $description='', $tip='', $value='', $items=array(), $prefix='') {
	require_once(dirname(__FILE__).'/../config/tce_config.php');
	global $l;
	if (strlen($description) == 0) {
		$description = $name;
	}
	$str = ''; // string to return
	$str .= '<div class="row">'.K_NEWLINE;
	$str .= '<span class="label">'.K_NEWLINE;
	$str .= '<label for="'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
	if (!empty($prefix)) {
		$str .= $prefix;
	}
	$str .= '</span>'.K_NEWLINE;
	$str .= '<span class="formw">'.K_NEWLINE;
	$str .= '<select name="'.$field_name.'" id="'.$field_name.'" size="0" title="'.$description.'">'.K_NEWLINE;
	foreach ($items as $key => $val) {
		$str .= '<option value="'.$key.'"';
		if ($key == $value) {
			$str .= ' selected="selected"';
		}
		$str .= '>'.$val.'</option>'.K_NEWLINE;
	}
	$str .= '</select>'.K_NEWLINE;
	if (strlen($tip) > 0) {
		$str .= ' <span class="labeldesc">'.$tip.'</span>';
	}
	$str .= '</span>'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	return $str;
}

/**
 * Print check box row form.
 * @param $field_name (string) Name of the form field.
 * @param $name (string) Label.
 * @param $description (string) Label description (tooltip).
 * @param $tip (string) Help to be displayed on the right of the input field.
 * @param $value (string) Initial value.
 * @param $selected (boolean) set to true if selected.
 * @param $disabled (boolean) set to true to disable the field
 * @param $prefix (string) code to be displayed after label.
 * @return string
 */
function getFormRowCheckBox($field_name, $name, $description='', $tip='', $value='', $selected=false, $disabled=false, $prefix='') {
	require_once(dirname(__FILE__).'/../config/tce_config.php');
	global $l;
	if (strlen($description) == 0) {
		$description = $name;
	}
	$str = ''; // string to return
	$str .= '<div class="row">'.K_NEWLINE;
	$str .= '<span class="label">'.K_NEWLINE;
	$hidden = '';
	if ($disabled) {
		// add hidden field to be submitted
		$hidden = '<input type="hidden" name="'.$field_name.'" id="'.$field_name.'" value="'.htmlspecialchars($value, ENT_COMPAT, $l['a_meta_charset']).'" />'.K_NEWLINE;
		$field_name = 'DISABLED_'.$field_name;
	}
	$str .= '<label for="'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
	if (!empty($prefix)) {
		$str .= $prefix;
	}
	$str .= '</span>'.K_NEWLINE;
	$str .= '<span class="formw">'.K_NEWLINE;
	$str .= '<input type="checkbox"';
	if ($disabled) {
		$str .= ' readonly="readonly" class="disabled"';
	}
	$str .= ' name="'.$field_name.'" id="'.$field_name.'" value="'.$value.'"';
	if (F_getBoolean($selected)) {
		$str .= ' checked="checked"';
	}
	$str .= ' title="'.$description.'" />';
	$str .= $hidden;
	if (strlen($tip) > 0) {
		$str .= ' <span class="labeldesc">'.$tip.'</span>';
	}
	$str .= '</span>'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	return $str;
}

/**
 * Print fixed value row form.
 * @param $field_name (string) Name of the form field.
 * @param $name (string) Label.
 * @param $description (string) Label description (tooltip).
 * @param $tip (string) Help to be displayed on the right of the input field.
 * @param $value (string) Initial value.
 * @param $currency (boolean) if true the value is a curency number.
 * @param $prefix (string) code to be displayed after label.
 * @return string
 */
function getFormRowFixedValue($field_name, $name, $description='', $tip='', $value='', $currency=false, $prefix='') {
	require_once(dirname(__FILE__).'/../config/tce_config.php');
	global $l;
	if (strlen($description) == 0) {
		$description = $name;
	}
	$str = ''; // string to return
	$str .= '<div class="row">'.K_NEWLINE;
	$str .= '<span class="label">'.K_NEWLINE;
	$str .= '<label for="DISABLED_'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
	if (!empty($prefix)) {
		$str .= $prefix;
	}
	$str .= '</span>'.K_NEWLINE;
	$str .= '<span class="formw">'.K_NEWLINE;
	$str .= '<input type="text" readonly="readonly" name="DISABLED_'.$field_name.'" id="DISABLED_'.$field_name.'"';
	if ($currency) {
		$value = F_formatCurrency($value, 2);
		$str .= ' class="disablednum"';
	} else {
		$str .= ' class="disabled"';
	}
	$size = 20; // default value
	if (strlen($value) > 20) {
		$size = 40;
	}
	$str .= ' value="'.htmlspecialchars($value, ENT_COMPAT, $l['a_meta_charset']).'" size="'.$size.'" maxlength="255" title="'.$description.'" />';
	if (strlen($tip) > 0) {
		$str .= ' <span class="labeldesc">'.$tip.'</span>';
	}
	// add hidden field to be submitted
	$str .= '<input type="hidden" name="'.$field_name.'" id="'.$field_name.'" value="'.htmlspecialchars($value, ENT_COMPAT, $l['a_meta_charset']).'" />'.K_NEWLINE;
	$str .= '</span>'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	return $str;
}

/**
 * Print empty form row.
 * @return string
 */
function getFormSmallVertSpace() {
	$str = '<div class="row">&nbsp;</div>'.K_NEWLINE;
	return $str;
}

/**
 * Print empty form row.
 * @return string
 */
function getFormSmallDivSpace() {
	$str = '<div style="clear:both;height:1px;font-size:1px;">&nbsp;</div>'.K_NEWLINE;
	return $str;
}

/**
 * Print empty form row.
 * @return string
 */
function getFormRowVertSpace() {
	$str = '<div class="row" style="margin-bottom:5px;"><hr class="dashed"/></div>'.K_NEWLINE;
	return $str;
}

/**
 * Print form row with title.
 * @param $title (string) Title to be printed.
 * @return string
 */
function getFormRowVertDiv($title='') {
	$str = '<div class="row"><hr class="dashed"/></div><div class="row"><div style="color:#666666;text-align:center;">'.$title.'</div></div>'.K_NEWLINE;
	return $str;
}

/**
 * Print form row with submit button when noscript is active.
 * @param $name (string) Name of the input form field.
 * @return string
 */
function getFormNoscriptSelect($name='selectrecord') {
	require_once(dirname(__FILE__).'/../config/tce_config.php');
	global $l;
	$str = '<noscript>'.K_NEWLINE;
	$str .= '<div class="row">'.K_NEWLINE;
	$str .= '<span class="label">&nbsp;</span>'.K_NEWLINE;
	$str .= '<span class="formw">'.K_NEWLINE;
	$str .= '<input type="submit" name="'.$name.'" id="'.$name.'" value="'.$l['w_select'].'" />'.K_NEWLINE;
	$str .= '</span>'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	$str .= '</noscript>'.K_NEWLINE;
	return $str;
}

/**
 * Print form row with label and description
 * @param $name (string) Label.
 * @param $description (string) Label description (tooltip).
 * @param $value (string) Initial value.
 * @return string
 */
function getFormDescriptionLine($name, $description='', $value='') {
	if (strlen($description) == 0) {
		$description = $name;
	}
	$str = '<div class="row">'.K_NEWLINE;
	$str .= '<span class="label">'.K_NEWLINE;
	$str .= '<span title="'.$description.'">'.$name.'</span>'.K_NEWLINE;
	$str .= '</span>'.K_NEWLINE;
	$str .= '<span class="formw">'.K_NEWLINE;
	$str .= $value.'&nbsp;'.K_NEWLINE;
	$str .= '</span>'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	return $str;
}

/**
 * Print input row form to upluad a file.
 * @param $field_name (string) Name of the form field.
 * @param $field_id (string) ID of the form field.
 * @param $name (string) Label.
 * @param $description (string) Label description (tooltip).
 * @param $onchange (string) Javascript code to execute at onchange event.
 * @return string
 */
function getFormUploadFile($field_name, $field_id, $name, $description='', $onchange='') {
	if (strlen($description) == 0) {
		$description = $name;
	}
	$str = '<div class="row" id="div'.$field_id.'">'.K_NEWLINE;
	$str .= '<span class="label">'.K_NEWLINE;
	$str .= '<label for="'.$field_id.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
	$str .= '</span>'.K_NEWLINE;
	$str .= '<span class="formw">'.K_NEWLINE;
	$str .= '<input type="file" name="'.$field_name.'" id="'.$field_id.'" size="20" title="'.$description.'"';
	if (!empty($onchange)) {
		$str .= ' onchange="'.$onchange.'"';
	}
	$str .= ' />'.K_NEWLINE;
	$str .= '</span>'.K_NEWLINE;
	$str .= '&nbsp;'.K_NEWLINE;
	$str .= '</div>'.K_NEWLINE;
	return $str;
}

nicolaasuni's avatar
9.0.026    
nicolaasuni committed
569
//============================================================+
nick's avatar
nick committed
570
// END OF FILE
nicolaasuni's avatar
9.0.026    
nicolaasuni committed
571
//============================================================+