Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         Form
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       WebsiteBaker Org. e.V.
8
 * @link            http://websitebaker.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.3
11
 * @requirements    PHP 5.3.6 and higher
12
 * @version         $Id: save_field.php 2 2017-07-02 15:14:29Z Manuela $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/branches/main/modules/form/lib/save_field.php $
14
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
15
 * @description
16
 */
17
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
18
// suppress to print the header, so no new FTAN will be set
19
$admin_header = false;
20
// Tells script to update when this page was last updated
21
$update_when_modified = true;
22
// Include WB admin wrapper script
23
require(WB_PATH.'/modules/admin.php');
24
$sSectionIdPrefix = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR : 'Sec' );
25
$backUrl = ADMIN_URL.'/pages/modify.php?page_id='.$page_id.'#'.$sSectionIdPrefix.$section_id;
26
// check FTAN
27
if (!$admin->checkFTAN())
28
{
29
    $admin->print_header();
30
    $admin->print_error( ''.$MESSAGE['GENERIC_SECURITY_ACCESS'], $backUrl );
31
}
32
// Get id
33
$field_id = intval($admin->checkIDKEY('field_id', false ));
34
if (!$field_id) {
35
    $admin->print_header();
36
    $admin->print_error( ''.$MESSAGE['GENERIC_SECURITY_ACCESS'].'', $backUrl );
37
}
38
$backModuleUrl = WB_URL.'/modules/'.basename(__DIR__).'/modify_field.php?page_id='.$page_id.'&section_id='.$section_id.'&field_id='.$admin->getIDKEY($field_id);
39
// After check print the header to get a new FTAN
40
$admin->print_header();
41
// Validate all fields
42
if( ($admin->get_post('title') == '') || ($admin->get_post('type') == '') ) {
43
    $admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $backModuleUrl );
44
} else {
45
    $title = $admin->StripCodeFromText(($admin->get_post('title')));
46
    $type = ($admin->get_post('type'));
47
    $required = (int) ($admin->get_post('required'));
48
}
49

    
50
// Update row
51
$sql  = 'UPDATE `'.TABLE_PREFIX.'mod_form_fields SET` '
52
      . 'title = \''.$database->escapeString($title).'\', '
53
      . 'type = \''.$database->escapeString($type).'\', '
54
      . 'required = \''.$database->escapeString($required).'\' '
55
      . 'WHERE field_id = '.(int)$field_id.' ';
56
if($database->query($sql)) { }
57

    
58
// If field type has multiple options, get all values and implode them
59
    $value = $extra = '';
60
    $list_count = $admin->get_post('list_count');
61
    if(is_numeric($list_count)) {
62
        $values = array();
63
        for($i = 1; $i <= $list_count; $i++) {
64
            if($admin->get_post('value'.$i) != '') {
65
                $values[] = str_replace(",","&#44;",$admin->get_post('value'.$i));
66
            }
67
        }
68
        $value = implode(',', $values);
69
    } else {
70
        $admin->print_error( ''.$MESSAGE['GENERIC_SECURITY_ACCESS'].'', $backUrl );
71
    }
72
/**
73
 * 
74
// Get extra fields for field-type-specific settings
75
if($admin->get_post('type') == 'textfield') {
76
    $extra = intval($admin->get_post('length'));
77
    $value = $admin->StripCodeFromText( $admin->get_post('value'));
78
} elseif($admin->get_post('type') == 'textarea') {
79
    $value = $admin->StripCodeFromText( $admin->get_post('value'));
80
    $extra = '';
81
//    $database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '' WHERE field_id = '$field_id'");
82
} elseif($admin->get_post('type') == 'heading') {
83
    $extra = $admin->StripCodeFromText( $admin->get_post('template'));
84
    if(trim($extra) == '') $extra = '<tr><td class="frm-field_heading" colspan="2">{TITLE}{FIELD}</td></tr>';
85
//    $extra = $admin->add_slashes($extra);
86
    $value = '';
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 = intval($admin->get_post('size')).','.$admin->get_post('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->StripCodeFromText( $admin->get_post('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->StripCodeFromText( $admin->get_post('seperator'));
96
//    $database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET value = '$value', extra = '$extra' WHERE field_id = '$field_id'");
97
}
98
 */
99

    
100
// prepare sql-update
101
    switch($admin->get_post('type')):
102
        case 'textfield':
103
            $value = $admin->StripCodeFromText($admin->get_post('value'));
104
            $extra = intval($admin->get_post('length'));
105
            break;
106
        case 'textarea':
107
            $value = $admin->StripCodeFromText($admin->get_post('value'));
108
            $extra = '';
109
            break;
110
        case 'heading':
111
            $extra = $admin->StripCodeFromText( $admin->get_post('template'));
112
            if(trim($extra) == '') $extra = '<tr><td class="frm-field_heading" colspan="2">{TITLE}{FIELD}</td></tr>';
113
            break;
114
        case 'select':
115
            $extra = intval($admin->get_post('size')).','.$admin->get_post('multiselect');
116
            break;
117
        case 'checkbox':
118
            $extra = $admin->StripCodeFromText( $admin->get_post('seperator'));
119
            break;
120
        case 'radio':
121
            $extra = $admin->StripCodeFromText( $admin->get_post('seperator'));
122
            break;
123
        default:
124
            $value = '';
125
            $extra = '';
126
            break;
127
    endswitch;
128
    $sql  = 'UPDATE `'.TABLE_PREFIX.'mod_form_fields` SET '
129
          . '`value` = \''.$database->escapeString($value).'\', '
130
          . '`extra` = \''.$database->escapeString($extra).'\' '
131
          . 'WHERE `field_id` = \''.$database->escapeString($field_id).'\'';
132
    if( $database->query($sql) ) {
133
        $admin->print_success($TEXT['SUCCESS'], $backModuleUrl );
134
    }else {
135
        $admin->print_error($database->get_error(), $backModuleUrl );
136
    }
137
// Print admin footer
138
$admin->print_footer();
(3-3/3)