1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category module
|
5
|
* @package Form
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2004-2009, Ryan Djurovich
|
8
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9
|
* @link http://www.websitebaker2.org/
|
10
|
* @license http://www.gnu.org/licenses/gpl.html
|
11
|
* @platform WebsiteBaker 2.8.x
|
12
|
* @requirements PHP 5.2.2 and higher
|
13
|
* @version $Id: save_field.php 1407 2011-01-22 17:21:32Z FrankH $
|
14
|
* @filesource $HeadURL: $
|
15
|
* @lastmodified $Date: $
|
16
|
* @description
|
17
|
*/
|
18
|
|
19
|
require('../../config.php');
|
20
|
require(WB_PATH.'/modules/admin.php');
|
21
|
|
22
|
// Get id
|
23
|
if(!isset($_POST['field_id']) OR !is_numeric($_POST['field_id'])) {
|
24
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
25
|
exit(0);
|
26
|
} else {
|
27
|
$field_id = $_POST['field_id'];
|
28
|
}
|
29
|
|
30
|
// Include WB admin wrapper script
|
31
|
$update_when_modified = true; // Tells script to update when this page was last updated
|
32
|
|
33
|
if (!$admin->checkFTAN())
|
34
|
{
|
35
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
36
|
exit();
|
37
|
}
|
38
|
|
39
|
// Validate all fields
|
40
|
if($admin->get_post('title') == '' OR $admin->get_post('type') == '') {
|
41
|
$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));
|
42
|
} else {
|
43
|
$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title'), ENT_QUOTES));
|
44
|
$type = $admin->add_slashes($admin->get_post('type'));
|
45
|
$required = (int) $admin->add_slashes($admin->get_post('required'));
|
46
|
}
|
47
|
$value = '';
|
48
|
|
49
|
// Update row
|
50
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET title = '$title', type = '$type', required = '$required' WHERE field_id = '$field_id'");
|
51
|
|
52
|
// If field type has multiple options, get all values and implode them
|
53
|
$list_count = $admin->get_post('list_count');
|
54
|
if(is_numeric($list_count)) {
|
55
|
$values = array();
|
56
|
for($i = 1; $i <= $list_count; $i++) {
|
57
|
if($admin->get_post('value'.$i) != '') {
|
58
|
$values[] = str_replace(",",",",$admin->get_post('value'.$i));
|
59
|
}
|
60
|
}
|
61
|
$value = implode(',', $values);
|
62
|
}
|
63
|
|
64
|
// Get extra fields for field-type-specific settings
|
65
|
if($admin->get_post('type') == 'textfield') {
|
66
|
$length = $admin->get_post_escaped('length');
|
67
|
$value = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('value'));
|
68
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$length' WHERE field_id = '$field_id'");
|
69
|
} elseif($admin->get_post('type') == 'textarea') {
|
70
|
$value = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('value'));
|
71
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '' WHERE field_id = '$field_id'");
|
72
|
} elseif($admin->get_post('type') == 'heading') {
|
73
|
$extra = str_replace(array("[[", "]]"), '', $admin->get_post('template'));
|
74
|
if(trim($extra) == '') $extra = '<tr><td class="field_heading" colspan="2">{TITLE}{FIELD}</td></tr>';
|
75
|
$extra = $admin->add_slashes($extra);
|
76
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '', extra = '$extra' WHERE field_id = '$field_id'");
|
77
|
} elseif($admin->get_post('type') == 'select') {
|
78
|
$extra = $admin->get_post_escaped('size').','.$admin->get_post_escaped('multiselect');
|
79
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
|
80
|
} elseif($admin->get_post('type') == 'checkbox') {
|
81
|
$extra = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('seperator'));
|
82
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
|
83
|
} elseif($admin->get_post('type') == 'radio') {
|
84
|
$extra = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('seperator'));
|
85
|
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
|
86
|
}
|
87
|
|
88
|
// Check if there is a db error, otherwise say successful
|
89
|
if($database->is_error()) {
|
90
|
$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));
|
91
|
} else {
|
92
|
$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));
|
93
|
}
|
94
|
|
95
|
// Print admin footer
|
96
|
$admin->print_footer();
|
97
|
|
98
|
?>
|