Project

General

Profile

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 1538 2011-12-10 15:06:15Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/form/save_field.php $
14
 * @lastmodified    $Date: 2011-12-10 16:06:15 +0100 (Sat, 10 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
// check FTAN
29
if (!$admin->checkFTAN())
30
{
31
	$admin->print_header();
32
	$admin->print_error('::'.$MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
33
}
34
// After check print the header
35
$admin->print_header();
36

    
37

    
38
/*  */
39
// Get id
40
$field_id = intval($admin->checkIDKEY('field_id', false ));
41
if (!$field_id) {
42
 $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'].'::', ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
43
}
44
/*
45
// Get id
46
if(!isset($_POST['field_id']) OR !is_numeric($_POST['field_id'])) {
47
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
48
} else {
49
	$field_id = (int)$_POST['field_id'];
50
}
51
/*
52
// Include WB admin wrapper script
53
$update_when_modified = true; // Tells script to update when this page was last updated
54

    
55
if (!$admin->checkFTAN())
56
{
57
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
58
	exit();
59
}
60
*/
61
// Validate all fields
62
if($admin->get_post('title') == '' OR $admin->get_post('type') == '') {
63
	$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'&section_id='.$section_id.'&field_id='.$admin->getIDKEY($field_id));
64
} else {
65
	$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title'), ENT_QUOTES));
66
	$type = $admin->add_slashes($admin->get_post('type'));
67
	$required = (int) $admin->add_slashes($admin->get_post('required'));
68
}
69
$value = '';
70

    
71
// Update row
72
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET title = '$title', type = '$type', required = '$required' WHERE field_id = '$field_id'");
73

    
74
// If field type has multiple options, get all values and implode them
75
$list_count = $admin->get_post('list_count');
76
if(is_numeric($list_count)) {
77
	$values = array();
78
	for($i = 1; $i <= $list_count; $i++) {
79
		if($admin->get_post('value'.$i) != '') {
80
			$values[] = str_replace(",","&#44;",$admin->get_post('value'.$i));
81
		}
82
	}
83
	$value = implode(',', $values);
84
}
85

    
86
// Get extra fields for field-type-specific settings
87
if($admin->get_post('type') == 'textfield') {
88
	$length = $admin->get_post_escaped('length');
89
	$value = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('value'));
90
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$length' WHERE field_id = '$field_id'");
91
} elseif($admin->get_post('type') == 'textarea') {
92
	$value = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('value'));
93
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '' WHERE field_id = '$field_id'");
94
} elseif($admin->get_post('type') == 'heading') {
95
	$extra = str_replace(array("[[", "]]"), '', $admin->get_post('template'));
96
	if(trim($extra) == '') $extra = '<tr><td class="field_heading" colspan="2">{TITLE}{FIELD}</td></tr>';
97
	$extra = $admin->add_slashes($extra);
98
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '', extra = '$extra' WHERE field_id = '$field_id'");
99
} elseif($admin->get_post('type') == 'select') {
100
	$extra = $admin->get_post_escaped('size').','.$admin->get_post_escaped('multiselect');
101
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
102
} elseif($admin->get_post('type') == 'checkbox') {
103
	$extra = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('seperator'));
104
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
105
} elseif($admin->get_post('type') == 'radio') {
106
	$extra = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('seperator'));
107
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
108
}
109

    
110
// Check if there is a db error, otherwise say successful
111
if($database->is_error()) {
112
	$admin->print_error($database->get_error(), WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'&section_id='.$section_id.'&field_id='.$admin->getIDKEY($field_id));
113
} else {
114
	$admin->print_success($TEXT['SUCCESS'],     WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'&section_id='.$section_id.'&field_id='.$admin->getIDKEY($field_id));
115
}
116

    
117
// Print admin footer
118
$admin->print_footer();
(16-16/22)