1: <?php
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: $formstatus = true;
34:
35:
36: if (isset($_POST['update'])) {
37: $menu_mode = 'update';
38: } elseif (isset($_POST['delete'])) {
39: $menu_mode = 'delete';
40: } elseif (isset($_POST['forcedelete'])) {
41: $menu_mode = 'forcedelete';
42: } elseif (isset($_POST['cancel'])) {
43: $menu_mode = 'cancel';
44: } elseif (isset($_POST['add'])) {
45: $menu_mode = 'add';
46: } elseif (isset($_POST['clear'])) {
47: $menu_mode = 'clear';
48: } elseif (isset($_POST['upload'])) {
49: $menu_mode = 'upload';
50: } elseif (isset($_POST['addquestion'])) {
51: $menu_mode = 'addquestion';
52: }
53: if (!isset($menu_mode)) {
54: $menu_mode = '';
55: }
56:
57: 58: 59: 60:
61: function F_decode_form_fields()
62: {
63: return $_REQUEST;
64: }
65:
66: 67: 68: 69: 70: 71:
72: function F_check_required_fields($formfields)
73: {
74: if (empty($formfields) or !array_key_exists('ff_required', $formfields) or strlen($formfields['ff_required']) <= 0) {
75: return false;
76: }
77: $missing_fields = '';
78: $required_fields = explode(',', $formfields['ff_required']);
79: $required_fields_labels = explode(',', $formfields['ff_required_labels']);
80: for ($i=0; $i<count($required_fields); $i++) {
81: $fieldname = trim($required_fields[$i]);
82: $fieldname = preg_replace('/[^a-z0-9_\[\]]/i', '', $fieldname);
83: if (!array_key_exists($fieldname, $formfields) or strlen(trim($formfields[$fieldname])) <= 0) {
84: if ($required_fields_labels[$i]) {
85: $fieldname = $required_fields_labels[$i];
86: }
87: $missing_fields .= ', '.stripslashes($fieldname);
88: }
89: }
90: if (strlen($missing_fields)>1) {
91: $missing_fields = substr($missing_fields, 1);
92: }
93: return ($missing_fields);
94: }
95:
96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107:
108: function F_check_fields_format($formfields)
109: {
110: if (empty($formfields)) {
111: return '';
112: }
113: reset($formfields);
114: $wrongfields = '';
115: while (list($key, $value) = each($formfields)) {
116: if (substr($key, 0, 2) == 'x_') {
117: $fieldname = substr($key, 2);
118: $fieldname = preg_replace('/[^a-z0-9_\[\]]/i', '', $fieldname);
119: if (array_key_exists($fieldname, $formfields) and strlen($formfields[$fieldname]) > 0) {
120: if (!preg_match("'".stripslashes($value)."'i", $formfields[$fieldname])) {
121: if (isset($formfields['xl_'.$fieldname]) and !empty($formfields['xl_'.$fieldname])) {
122: $fieldname = $formfields['xl_'.$fieldname];
123: }
124: $wrongfields .= ', '.stripslashes($fieldname);
125: }
126: }
127: }
128: }
129: if (strlen($wrongfields) > 1) {
130: $wrongfields = substr($wrongfields, 2);
131: }
132: return ($wrongfields);
133: }
134:
135: 136: 137: 138: 139:
140: function F_check_form_fields()
141: {
142: require_once('../config/tce_config.php');
143: global $l;
144: $formfields = F_decode_form_fields();
145:
146: if ($missing_fields = F_check_required_fields($formfields)) {
147: F_print_error('WARNING', $l['m_form_missing_fields'].': '.$missing_fields);
148: F_stripslashes_formfields();
149: return false;
150: }
151:
152: if ($wrong_fields = F_check_fields_format($formfields)) {
153: F_print_error('WARNING', $l['m_form_wrong_fields'].': '.$wrong_fields);
154: F_stripslashes_formfields();
155: return false;
156: }
157: return true;
158: }
159:
160: 161: 162:
163: function F_stripslashes_formfields()
164: {
165: foreach ($_POST as $key => $value) {
166: if (($key[0] != '_') and (is_string($value))) {
167: $key = preg_replace('/[^a-z0-9_\[\]]/i', '', $key);
168: global $$key;
169: if (!isset($$key)) {
170: $$key = stripslashes($value);
171: }
172: }
173: }
174: }
175:
176: 177: 178: 179: 180:
181: function F_close_button($onclick = '')
182: {
183: require_once('../config/tce_config.php');
184: global $l;
185: $str = '';
186: $str .= '<div class="row">'.K_NEWLINE;
187: $str .= '<form action="'.$_SERVER['SCRIPT_NAME'].'" id="closeform">'.K_NEWLINE;
188: $str .= '<div>'.K_NEWLINE;
189: $str .= '<input type="button" name="wclose" id="wclose" value="'.$l['w_close'].'" title="'.$l['h_close_window'].'" onclick="'.$onclick.'window.close();" />'.K_NEWLINE;
190: $str .= '</div>'.K_NEWLINE;
191: $str .= '</form>'.K_NEWLINE;
192: $str .= '</div>'.K_NEWLINE;
193: return $str;
194: }
195:
196: 197: 198: 199: 200: 201: 202:
203: function F_submit_button($name, $value, $title = "")
204: {
205: echo '<input type="submit" name="'.$name.'" id="'.$name.'" value="'.$value.'" title="'.$title.'" />';
206: }
207:
208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222:
223: function getFormRowTextInput($field_name, $name, $description = '', $tip = '', $value = '', $format = '', $maxlen = 255, $date = false, $datetime = false, $password = false, $prefix = '')
224: {
225: require_once(dirname(__FILE__).'/../config/tce_config.php');
226: global $l;
227: if (strlen($description) == 0) {
228: $description = $name;
229: }
230: $str = '';
231: $button = '';
232: if ($date) {
233: $button = '<button name="'.$field_name.'_date_trigger" id="'.$field_name.'_date_trigger" title="'.$l['w_calendar'].'">...</button>';
234: $jsdate = 'Calendar.setup({inputField: "'.$field_name.'", ifFormat: "%Y-%m-%d", button: "'.$field_name.'_date_trigger"});'.K_NEWLINE;
235: $format = '^([0-9]{4})([\-])([0-9]{2})([\-])([0-9]{2})$';
236: $maxlen = 10;
237: if (strlen($tip) == 0) {
238: $tip = $l['w_date_format'];
239: }
240: } elseif ($datetime) {
241: $button = '<button name="'.$field_name.'_date_trigger" id="'.$field_name.'_date_trigger" title="'.$l['w_calendar'].'">...</button>';
242: $jsdate = 'Calendar.setup({inputField: "'.$field_name.'", ifFormat: "%Y-%m-%d %H:%M:%S", showsTime: "true", button: "'.$field_name.'_date_trigger"});'.K_NEWLINE;
243: $format = '^([0-9]{4})([\-])([0-9]{2})([\-])([0-9]{2})([ ])([0-9]{2})([\:])([0-9]{2})([\:])([0-9]{2})$';
244: $maxlen = 19;
245: if (strlen($tip) == 0) {
246: $tip = $l['w_datetime_format'];
247: }
248: }
249: $str .= '<div class="row">'.K_NEWLINE;
250: $str .= '<span class="label">'.K_NEWLINE;
251: $str .= '<label for="'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
252: if (!empty($prefix)) {
253: $str .= $prefix;
254: }
255: $str .= '</span>'.K_NEWLINE;
256: $str .= '<span class="formw">'.K_NEWLINE;
257: $str .= '<input type="';
258: if ($password) {
259: $str .= 'password';
260: } else {
261: $str .= 'text';
262: }
263: $str .= '"';
264: if ($date or $datetime) {
265: $str .= ' style="direction:ltr;';
266: if ($l['a_meta_dir'] == 'rtl') {
267: $str .= 'text-align:right;';
268: }
269: $str .= '"';
270: }
271: $str .= ' name="'.$field_name.'" id="'.$field_name.'" value="'.htmlspecialchars($value, ENT_COMPAT, $l['a_meta_charset']).'" size="20" maxlength="'.$maxlen.'" title="'.$description.'" />';
272: $str .= $button;
273: if (strlen($tip) > 0) {
274: $str .= ' <span class="labeldesc">'.$tip.'</span>';
275: }
276: if (strlen($format) > 0) {
277: $str .= '<input type="hidden" name="x_'.$field_name.'" id="x_'.$field_name.'" value="'.$format.'" />'.K_NEWLINE;
278: $str .= '<input type="hidden" name="xl_'.$field_name.'" id="xl_'.$field_name.'" value="'.$name.'" />'.K_NEWLINE;
279: }
280: $str .= '</span>'.K_NEWLINE;
281: $str .= '</div>'.K_NEWLINE;
282: if ($date or $datetime) {
283: $str .= '<script type="text/javascript">'.K_NEWLINE;
284: $str .= '//<![CDATA['.K_NEWLINE;
285: $str .= $jsdate;
286: $str .= '//]]>'.K_NEWLINE;
287: $str .= '</script>'.K_NEWLINE;
288: }
289: return $str;
290: }
291:
292: 293: 294: 295: 296: 297: 298: 299: 300: 301:
302: function getFormRowTextBox($field_name, $name, $description = '', $value = '', $disabled = false, $prefix = '')
303: {
304: require_once(dirname(__FILE__).'/../config/tce_config.php');
305: global $l;
306: if (strlen($description) == 0) {
307: $description = $name;
308: }
309: $str = '';
310: $str .= '<div class="row">'.K_NEWLINE;
311: $str .= '<span class="label">'.K_NEWLINE;
312: $str .= '<label for="'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
313: if (!empty($prefix)) {
314: $str .= $prefix;
315: }
316: $str .= '</span>'.K_NEWLINE;
317: $str .= '<span class="formw">'.K_NEWLINE;
318: $str .= '<textarea cols="50" rows="5" name="'.$field_name.'" id="'.$field_name.'" title="'.$description.'"';
319: if ($disabled) {
320: $str .= ' readonly="readonly" class="disabled"';
321: }
322: $str .= '>'.htmlspecialchars($value, ENT_NOQUOTES, $l['a_meta_charset']).'</textarea>'.K_NEWLINE;
323: $str .= '</span>'.K_NEWLINE;
324: $str .= '</div>'.K_NEWLINE;
325: return $str;
326: }
327:
328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338:
339: function getFormRowSelectBox($field_name, $name, $description = '', $tip = '', $value = '', $items = array(), $prefix = '')
340: {
341: require_once(dirname(__FILE__).'/../config/tce_config.php');
342: global $l;
343: if (strlen($description) == 0) {
344: $description = $name;
345: }
346: $str = '';
347: $str .= '<div class="row">'.K_NEWLINE;
348: $str .= '<span class="label">'.K_NEWLINE;
349: $str .= '<label for="'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
350: if (!empty($prefix)) {
351: $str .= $prefix;
352: }
353: $str .= '</span>'.K_NEWLINE;
354: $str .= '<span class="formw">'.K_NEWLINE;
355: $str .= '<select name="'.$field_name.'" id="'.$field_name.'" size="0" title="'.$description.'">'.K_NEWLINE;
356: foreach ($items as $key => $val) {
357: $str .= '<option value="'.$key.'"';
358: if ($key == $value) {
359: $str .= ' selected="selected"';
360: }
361: $str .= '>'.$val.'</option>'.K_NEWLINE;
362: }
363: $str .= '</select>'.K_NEWLINE;
364: if (strlen($tip) > 0) {
365: $str .= ' <span class="labeldesc">'.$tip.'</span>';
366: }
367: $str .= '</span>'.K_NEWLINE;
368: $str .= '</div>'.K_NEWLINE;
369: return $str;
370: }
371:
372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383:
384: function getFormRowCheckBox($field_name, $name, $description = '', $tip = '', $value = '', $selected = false, $disabled = false, $prefix = '')
385: {
386: require_once(dirname(__FILE__).'/../config/tce_config.php');
387: global $l;
388: if (strlen($description) == 0) {
389: $description = $name;
390: }
391: $str = '';
392: $str .= '<div class="row">'.K_NEWLINE;
393: $str .= '<span class="label">'.K_NEWLINE;
394: $hidden = '';
395: if ($disabled) {
396:
397: $hidden = '<input type="hidden" name="'.$field_name.'" id="'.$field_name.'" value="'.htmlspecialchars($value, ENT_COMPAT, $l['a_meta_charset']).'" />'.K_NEWLINE;
398: $field_name = 'DISABLED_'.$field_name;
399: }
400: $str .= '<label for="'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
401: if (!empty($prefix)) {
402: $str .= $prefix;
403: }
404: $str .= '</span>'.K_NEWLINE;
405: $str .= '<span class="formw">'.K_NEWLINE;
406: $str .= '<input type="checkbox"';
407: if ($disabled) {
408: $str .= ' readonly="readonly" class="disabled"';
409: }
410: $str .= ' name="'.$field_name.'" id="'.$field_name.'" value="'.$value.'"';
411: if (F_getBoolean($selected)) {
412: $str .= ' checked="checked"';
413: }
414: $str .= ' title="'.$description.'" />';
415: $str .= $hidden;
416: if (strlen($tip) > 0) {
417: $str .= ' <span class="labeldesc">'.$tip.'</span>';
418: }
419: $str .= '</span>'.K_NEWLINE;
420: $str .= '</div>'.K_NEWLINE;
421: return $str;
422: }
423:
424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434:
435: function getFormRowFixedValue($field_name, $name, $description = '', $tip = '', $value = '', $currency = false, $prefix = '')
436: {
437: require_once(dirname(__FILE__).'/../config/tce_config.php');
438: global $l;
439: if (strlen($description) == 0) {
440: $description = $name;
441: }
442: $str = '';
443: $str .= '<div class="row">'.K_NEWLINE;
444: $str .= '<span class="label">'.K_NEWLINE;
445: $str .= '<label for="DISABLED_'.$field_name.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
446: if (!empty($prefix)) {
447: $str .= $prefix;
448: }
449: $str .= '</span>'.K_NEWLINE;
450: $str .= '<span class="formw">'.K_NEWLINE;
451: $str .= '<input type="text" readonly="readonly" name="DISABLED_'.$field_name.'" id="DISABLED_'.$field_name.'"';
452: if ($currency) {
453: $value = F_formatCurrency($value, 2);
454: $str .= ' class="disablednum"';
455: } else {
456: $str .= ' class="disabled"';
457: }
458: $size = 20;
459: if (strlen($value) > 20) {
460: $size = 40;
461: }
462: $str .= ' value="'.htmlspecialchars($value, ENT_COMPAT, $l['a_meta_charset']).'" size="'.$size.'" maxlength="255" title="'.$description.'" />';
463: if (strlen($tip) > 0) {
464: $str .= ' <span class="labeldesc">'.$tip.'</span>';
465: }
466:
467: $str .= '<input type="hidden" name="'.$field_name.'" id="'.$field_name.'" value="'.htmlspecialchars($value, ENT_COMPAT, $l['a_meta_charset']).'" />'.K_NEWLINE;
468: $str .= '</span>'.K_NEWLINE;
469: $str .= '</div>'.K_NEWLINE;
470: return $str;
471: }
472:
473: 474: 475: 476:
477: function getFormSmallVertSpace()
478: {
479: $str = '<div class="row"> </div>'.K_NEWLINE;
480: return $str;
481: }
482:
483: 484: 485: 486:
487: function getFormSmallDivSpace()
488: {
489: $str = '<div style="clear:both;height:1px;font-size:1px;"> </div>'.K_NEWLINE;
490: return $str;
491: }
492:
493: 494: 495: 496:
497: function getFormRowVertSpace()
498: {
499: $str = '<div class="row" style="margin-bottom:5px;"><hr class="dashed"/></div>'.K_NEWLINE;
500: return $str;
501: }
502:
503: 504: 505: 506: 507:
508: function getFormRowVertDiv($title = '')
509: {
510: $str = '<div class="row"><hr class="dashed"/></div><div class="row"><div style="color:#666666;text-align:center;">'.$title.'</div></div>'.K_NEWLINE;
511: return $str;
512: }
513:
514: 515: 516: 517: 518:
519: function getFormNoscriptSelect($name = 'selectrecord')
520: {
521: require_once(dirname(__FILE__).'/../config/tce_config.php');
522: global $l;
523: $str = '<noscript>'.K_NEWLINE;
524: $str .= '<div class="row">'.K_NEWLINE;
525: $str .= '<span class="label"> </span>'.K_NEWLINE;
526: $str .= '<span class="formw">'.K_NEWLINE;
527: $str .= '<input type="submit" name="'.$name.'" id="'.$name.'" value="'.$l['w_select'].'" />'.K_NEWLINE;
528: $str .= '</span>'.K_NEWLINE;
529: $str .= '</div>'.K_NEWLINE;
530: $str .= '</noscript>'.K_NEWLINE;
531: return $str;
532: }
533:
534: 535: 536: 537: 538: 539: 540:
541: function getFormDescriptionLine($name, $description = '', $value = '')
542: {
543: if (strlen($description) == 0) {
544: $description = $name;
545: }
546: $str = '<div class="row">'.K_NEWLINE;
547: $str .= '<span class="label">'.K_NEWLINE;
548: $str .= '<span title="'.$description.'">'.$name.'</span>'.K_NEWLINE;
549: $str .= '</span>'.K_NEWLINE;
550: $str .= '<span class="formw">'.K_NEWLINE;
551: $str .= $value.' '.K_NEWLINE;
552: $str .= '</span>'.K_NEWLINE;
553: $str .= '</div>'.K_NEWLINE;
554: return $str;
555: }
556:
557: 558: 559: 560: 561: 562: 563: 564: 565:
566: function getFormUploadFile($field_name, $field_id, $name, $description = '', $onchange = '')
567: {
568: if (strlen($description) == 0) {
569: $description = $name;
570: }
571: $str = '<div class="row" id="div'.$field_id.'">'.K_NEWLINE;
572: $str .= '<span class="label">'.K_NEWLINE;
573: $str .= '<label for="'.$field_id.'" title="'.$description.'">'.$name.'</label>'.K_NEWLINE;
574: $str .= '</span>'.K_NEWLINE;
575: $str .= '<span class="formw">'.K_NEWLINE;
576: $str .= '<input type="file" name="'.$field_name.'" id="'.$field_id.'" size="20" title="'.$description.'"';
577: if (!empty($onchange)) {
578: $str .= ' onchange="'.$onchange.'"';
579: }
580: $str .= ' />'.K_NEWLINE;
581: $str .= '</span>'.K_NEWLINE;
582: $str .= ' '.K_NEWLINE;
583: $str .= '</div>'.K_NEWLINE;
584: return $str;
585: }
586:
587:
588:
589:
590: