Project

General

Profile

1 560 Ruebenwurz
<?php
2 1375 FrankH
/**
3
 *
4
 * @category        module
5
 * @package         Form
6
 * @author          WebsiteBaker Project
7 1714 Luisehahne
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1375 FrankH
 * @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$
13 1457 Luisehahne
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15 1714 Luisehahne
 * @description
16 1375 FrankH
 */
17 560 Ruebenwurz
18
require('../../config.php');
19 1457 Luisehahne
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 1375 FrankH
require(WB_PATH.'/modules/admin.php');
26 1457 Luisehahne
/* */
27 560 Ruebenwurz
28 1757 Luisehahne
$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? '#'.SEC_ANCHOR.$section['section_id'] : 'section_'.$section_id );
29 1553 Luisehahne
30 1457 Luisehahne
// check FTAN
31
if (!$admin->checkFTAN())
32
{
33
	$admin->print_header();
34 1553 Luisehahne
	$admin->print_error('::'.$MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id.$sec_anchor);
35 1457 Luisehahne
}
36
37 560 Ruebenwurz
// Get id
38 1457 Luisehahne
$field_id = intval($admin->checkIDKEY('field_id', false ));
39
if (!$field_id) {
40 1553 Luisehahne
 $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'].'::', ADMIN_URL.'/pages/modify.php?page_id='.$page_id.$sec_anchor);
41 1457 Luisehahne
}
42 1553 Luisehahne
// After check print the header to get a new FTAN
43
$admin->print_header();
44
45 1457 Luisehahne
/*
46
// Get id
47 560 Ruebenwurz
if(!isset($_POST['field_id']) OR !is_numeric($_POST['field_id'])) {
48 1375 FrankH
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
49 560 Ruebenwurz
} else {
50 1457 Luisehahne
	$field_id = (int)$_POST['field_id'];
51 560 Ruebenwurz
}
52 1457 Luisehahne
/*
53 560 Ruebenwurz
// Include WB admin wrapper script
54
$update_when_modified = true; // Tells script to update when this page was last updated
55
56 1375 FrankH
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 1457 Luisehahne
*/
62 560 Ruebenwurz
// Validate all fields
63
if($admin->get_post('title') == '' OR $admin->get_post('type') == '') {
64 1375 FrankH
	$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));
65 560 Ruebenwurz
} else {
66 1407 FrankH
	$title = str_replace(array("[[", "]]"), '', htmlspecialchars($admin->get_post_escaped('title'), ENT_QUOTES));
67 656 thorn
	$type = $admin->add_slashes($admin->get_post('type'));
68 1355 FrankH
	$required = (int) $admin->add_slashes($admin->get_post('required'));
69 560 Ruebenwurz
}
70 618 thorn
$value = '';
71 560 Ruebenwurz
72
// Update row
73 1553 Luisehahne
$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 560 Ruebenwurz
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(",","&#44;",$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 1407 FrankH
	$value = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('value'));
96 560 Ruebenwurz
	$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 1407 FrankH
	$value = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('value'));
99 560 Ruebenwurz
	$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 1407 FrankH
	$extra = str_replace(array("[[", "]]"), '', $admin->get_post('template'));
102 1553 Luisehahne
	if(trim($extra) == '') $extra = '<tr><td class="frm-field_heading" colspan="2">{TITLE}{FIELD}</td></tr>';
103 560 Ruebenwurz
	$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 1714 Luisehahne
	$extra = intval($admin->get_post_escaped('size')).','.$admin->get_post_escaped('multiselect');
107 560 Ruebenwurz
	$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 1407 FrankH
	$extra = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('seperator'));
110 560 Ruebenwurz
	$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 1407 FrankH
	$extra = str_replace(array("[[", "]]"), '', $admin->get_post_escaped('seperator'));
113 560 Ruebenwurz
	$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 1375 FrankH
	$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));
119 560 Ruebenwurz
} else {
120 1375 FrankH
	$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));
121 560 Ruebenwurz
}
122
123
// Print admin footer
124
$admin->print_footer();