1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category module
|
5
|
* @package Form
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: save_field.php 1553 2011-12-31 15:03:03Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/tags/2.8.3/wb/modules/form/save_field.php $
|
14
|
* @lastmodified $Date: 2011-12-31 16:03:03 +0100 (Sat, 31 Dec 2011) $
|
15
|
* @description
|
16
|
*/
|
17
|
|
18
|
require('../../config.php');
|
19
|
|
20
|
// suppress to print the header, so no new FTAN will be set
|
21
|
$admin_header = false;
|
22
|
// Tells script to update when this page was last updated
|
23
|
$update_when_modified = true;
|
24
|
// Include WB admin wrapper script
|
25
|
require(WB_PATH.'/modules/admin.php');
|
26
|
/* */
|
27
|
|
28
|
$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' ) ? '#'.SEC_ANCHOR.$section['section_id'] : '' );
|
29
|
|
30
|
// check FTAN
|
31
|
if (!$admin->checkFTAN())
|
32
|
{
|
33
|
$admin->print_header();
|
34
|
$admin->print_error('::'.$MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id.$sec_anchor);
|
35
|
}
|
36
|
|
37
|
// Get id
|
38
|
$field_id = intval($admin->checkIDKEY('field_id', false ));
|
39
|
if (!$field_id) {
|
40
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'].'::', ADMIN_URL.'/pages/modify.php?page_id='.$page_id.$sec_anchor);
|
41
|
}
|
42
|
// After check print the header to get a new FTAN
|
43
|
$admin->print_header();
|
44
|
|
45
|
/*
|
46
|
// Get id
|
47
|
if(!isset($_POST['field_id']) OR !is_numeric($_POST['field_id'])) {
|
48
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
49
|
} else {
|
50
|
$field_id = (int)$_POST['field_id'];
|
51
|
}
|
52
|
/*
|
53
|
// Include WB admin wrapper script
|
54
|
$update_when_modified = true; // Tells script to update when this page was last updated
|
55
|
|
56
|
if (!$admin->checkFTAN())
|
57
|
{
|
58
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
59
|
exit();
|
60
|
}
|
61
|
*/
|
62
|
// Validate all fields
|
63
|
if($admin->get_post('title') == '' OR $admin->get_post('type') == '') {
|
64
|
$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'§ion_id='.$section_id.'&field_id='.$admin->getIDKEY($field_id));
|
65
|
} else {
|
66
|
$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title'), ENT_QUOTES));
|
67
|
$type = $admin->add_slashes($admin->get_post('type'));
|
68
|
$required = (int) $admin->add_slashes($admin->get_post('required'));
|
69
|
}
|
70
|
$value = '';
|
71
|
|
72
|
// Update row
|
73
|
$sql = 'UPDATE `'.TABLE_PREFIX.'mod_form_fields SET` ';
|
74
|
$sql .= 'title = \''.$title.'\', ';
|
75
|
$sql .= 'type = \''.$type.'\', ';
|
76
|
$sql .= 'required = \''.$required.'\' ';
|
77
|
$sql .= 'WHERE field_id = '.(int)$field_id.' ';
|
78
|
if($database->query($sql)) { }
|
79
|
|
80
|
// If field type has multiple options, get all values and implode them
|
81
|
$list_count = $admin->get_post('list_count');
|
82
|
if(is_numeric($list_count)) {
|
83
|
$values = array();
|
84
|
for($i = 1; $i <= $list_count; $i++) {
|
85
|
if($admin->get_post('value'.$i) != '') {
|
86
|
$values[] = str_replace(",",",",$admin->get_post('value'.$i));
|
87
|
}
|
88
|
}
|
89
|
$value = implode(',', $values);
|
90
|
}
|
91
|
|
92
|
// Get extra fields for field-type-specific settings
|
93
|
if($admin->get_post('type') == 'textfield') {
|
94
|
$length = $admin->get_post_escaped('length');
|
95
|
$value = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('value'));
|
96
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$length' WHERE field_id = '$field_id'");
|
97
|
} elseif($admin->get_post('type') == 'textarea') {
|
98
|
$value = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('value'));
|
99
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '' WHERE field_id = '$field_id'");
|
100
|
} elseif($admin->get_post('type') == 'heading') {
|
101
|
$extra = str_replace(array("[[", "]]"), '', $admin->get_post('template'));
|
102
|
if(trim($extra) == '') $extra = '<tr><td class="frm-field_heading" colspan="2">{TITLE}{FIELD}</td></tr>';
|
103
|
$extra = $admin->add_slashes($extra);
|
104
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '', extra = '$extra' WHERE field_id = '$field_id'");
|
105
|
} elseif($admin->get_post('type') == 'select') {
|
106
|
$extra = $admin->get_post_escaped('size').','.$admin->get_post_escaped('multiselect');
|
107
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
|
108
|
} elseif($admin->get_post('type') == 'checkbox') {
|
109
|
$extra = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('seperator'));
|
110
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
|
111
|
} elseif($admin->get_post('type') == 'radio') {
|
112
|
$extra = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('seperator'));
|
113
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
|
114
|
}
|
115
|
|
116
|
// Check if there is a db error, otherwise say successful
|
117
|
if($database->is_error()) {
|
118
|
$admin->print_error($database->get_error(), WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'§ion_id='.$section_id.'&field_id='.$admin->getIDKEY($field_id));
|
119
|
} else {
|
120
|
$admin->print_success($TEXT['SUCCESS'], WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'§ion_id='.$section_id.'&field_id='.$admin->getIDKEY($field_id));
|
121
|
}
|
122
|
|
123
|
// Print admin footer
|
124
|
$admin->print_footer();
|