Project

General

Profile

1
<?php
2

    
3
// $Id: save_field.php 1069 2009-07-15 20:28:15Z 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
//overwrite php.ini on Apache servers for valid SESSION ID Separator
46
if(function_exists('ini_set')) {
47
	ini_set('arg_separator.output', '&amp;');
48
}
49

    
50
// Validate all fields
51
if($admin->get_post('title') == '' OR $admin->get_post('type') == '') {
52
	$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/form/modify_field.php?page_id='.$page_id.'&amp;section_id='.$section_id.'&amp;field_id='.$field_id);
53
} else {
54
	$title = $admin->add_slashes($admin->get_post('title'));
55
	$type = $admin->add_slashes($admin->get_post('type'));
56
	$required = $admin->add_slashes($admin->get_post('required'));
57
}
58
$value = '';
59

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

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

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

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

    
106
// Print admin footer
107
$admin->print_footer();
108

    
109
?>
(16-16/21)