Project

General

Profile

1
<?php
2

    
3
// $Id: save_field.php 1074 2009-07-16 19:07:23Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
/*
27
The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
28
for his contributions to this module - adding extra field types
29
*/
30

    
31
require('../../config.php');
32

    
33
// Get id
34
if(!isset($_POST['field_id']) OR !is_numeric($_POST['field_id'])) {
35
	header("Location: ".ADMIN_URL."/pages/index.php");
36
	exit(0);
37
} else {
38
	$field_id = $_POST['field_id'];
39
}
40

    
41
// Include WB admin wrapper script
42
$update_when_modified = true; // Tells script to update when this page was last updated
43
require(WB_PATH.'/modules/admin.php');
44

    
45
// Validate all fields
46
if($admin->get_post('title') == '' OR $admin->get_post('type') == '') {
47
	$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='.$field_id);
48
} else {
49
	$title = $admin->add_slashes($admin->get_post('title'));
50
	$type = $admin->add_slashes($admin->get_post('type'));
51
	$required = $admin->add_slashes($admin->get_post('required'));
52
}
53
$value = '';
54

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

    
58
// If field type has multiple options, get all values and implode them
59
$list_count = $admin->get_post('list_count');
60
if(is_numeric($list_count)) {
61
	$values = array();
62
	for($i = 1; $i <= $list_count; $i++) {
63
		if($admin->get_post('value'.$i) != '') {
64
			$values[] = str_replace(",","&#44;",$admin->get_post('value'.$i));
65
		}
66
	}
67
	$value = implode(',', $values);
68
}
69

    
70
// Get extra fields for field-type-specific settings
71
if($admin->get_post('type') == 'textfield') {
72
	$length = $admin->get_post_escaped('length');
73
	$value = $admin->get_post_escaped('value');
74
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$length' WHERE field_id = '$field_id'");
75
} elseif($admin->get_post('type') == 'textarea') {
76
	$value = $admin->get_post_escaped('value');
77
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '' WHERE field_id = '$field_id'");
78
} elseif($admin->get_post('type') == 'heading') {
79
	$extra = $admin->get_post('template');
80
	if(trim($extra) == '') $extra = '<tr><td class="field_heading" colspan="2">{TITLE}{FIELD}</td></tr>';
81
	$extra = $admin->add_slashes($extra);
82
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '', extra = '$extra' WHERE field_id = '$field_id'");
83
} elseif($admin->get_post('type') == 'select') {
84
	$extra = $admin->get_post_escaped('size').','.$admin->get_post_escaped('multiselect');
85
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
86
} elseif($admin->get_post('type') == 'checkbox') {
87
	$extra = $admin->get_post_escaped('seperator');
88
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
89
} elseif($admin->get_post('type') == 'radio') {
90
	$extra = $admin->get_post_escaped('seperator');
91
	$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
92
}
93

    
94
// Check if there is a db error, otherwise say successful
95
if($database->is_error()) {
96
	$admin->print_error($database->get_error(), WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'&section_id='.$section_id.'&field_id='.$field_id);
97
} else {
98
	$admin->print_success($TEXT['SUCCESS'], WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'&section_id='.$section_id.'&field_id='.$field_id);
99
}
100

    
101
// Print admin footer
102
$admin->print_footer();
103

    
104
?>
(16-16/21)