-
Notifications
You must be signed in to change notification settings - Fork 5
/
modify_settings.php
400 lines (359 loc) · 14.5 KB
/
modify_settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<?php
/**
* WebsiteBaker CMS module: mpForm
* ===============================
* This module allows you to create customised online forms, such as a feedback form with file upload and customizable email notifications. mpForm allows forms over one or more pages, loops of forms, conditionally displayed sections within a single page, and many more things. User input for the same session_id will become a single row in the submitted table. Since Version 1.1.0 many ajax helpers enable you to speed up the process of creating forms with this module. Since 1.2.0 forms can be imported and exported directly in the module.
*
* @category page
* @module mpform
* @version 1.3.36
* @authors Frank Heyne, NorHei(heimsath.org), Christian M. Stefan (Stefek), Martin Hecht (mrbaseman) and others
* @copyright (c) 2009 - 2020, Website Baker Org. e.V.
* @url https://github.com/WebsiteBaker-modules/mpform
* @license GNU General Public License
* @platform 2.8.x
* @requirements php >= 5.3
*
**/
/* This file prints the settings form of the module in the backend. */
// unset page/section IDs defined via GET before including the admin file (we expect POST here)
unset($_GET['page_id']);
unset($_GET['section_id']);
// manually include the config.php file (defines the required constants)
require('../../config.php');
// $admin_header = false;
// Tells script to update when this page was last updated
$update_when_modified = false;
// show the info banner
$print_info_banner = true;
// Include WB admin wrapper script
require(WB_PATH.'/modules/admin.php');
// include core functions of WB 2.7 to edit the optional module CSS files (frontend.css, backend.css)
@include_once(WB_PATH .'/framework/module.functions.php');
require_once(dirname(__FILE__).'/constants.php');
// obtain module directory
$mod_dir = basename(dirname(__FILE__));
// include the module language file depending on the backend language of the current user
if (!@include(get_module_language_file($mod_dir))) return;
// Get header and footer
$query_content = $database->query(
"SELECT *"
. " FROM `".TP_MPFORM."settings`"
. " WHERE `section_id` = '$section_id'"
);
$setting = $query_content->fetchRow();
// protect from cross page reading
if (($setting['page_id'] != $page_id)
&& (!(defined('MPFORM_SKIP_ID_CHECK')&&(MPFORM_SKIP_ID_CHECK)))) {
$sUrlToGo = ADMIN_URL."/pages/index.php";
if(headers_sent())
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']
.' (ID_CHECK) '.__FILE__.':'.__LINE__,
$sUrlToGo);
else
header("Location: ". $sUrlToGo);
exit(0);
}
// include template parser class and set template
if (!class_exists('Template') && file_exists(WB_PATH . '/include/phplib/template.inc'))
require_once(WB_PATH . '/include/phplib/template.inc');
$tpl = new Template(dirname(__FILE__) . '/htt/');
// define how to handle unknown variables
// (default:='remove', during development use 'keep' or 'comment')
$tpl->set_unknowns('keep');
// define debug mode (default:=0 (disabled), 1:=variable assignments,
// 2:=calls to get variable, 4:=show internals)
$tpl->debug = 0;
$tpl->set_file('page', 'backend_modify_settings.htt');
$tpl->set_block('page', 'main_block', 'main');
// replace all placeholder {xxx} of the template file with values from language file
foreach($LANG['backend'] as $key => $value) {
$tpl->set_var($key, $value);
}
// obtain display option from the database table
$table = TP_MPFORM."settings";
$sql = "SELECT *"
. " FROM `$table`"
. " WHERE `section_id` = '$section_id'";
$sql_result = $database->query($sql);
$settings = $sql_result->fetchRow();
// replace all placeholder {xxx} of the template file with values from the db
foreach($settings as $key => $value) {
$tpl->set_var($key, $value);
}
$email_from_value = $setting['email_from'];
$email_replyto_value = $setting['email_replyto'];
$email_fromname_value = $setting['email_fromname'];
$success_email_from_value = $setting['success_email_from'];
$success_email_fromname_value = $setting['success_email_fromname'];
// replace static template placeholders with values from language file
$tpl->set_var(
array(
// variables from Website Baker framework
'PAGE_ID' => (int) $page_id,
'SECTION_ID' => (int) $section_id,
'ADMIN_URL' => ADMIN_URL,
'WB_URL' => WB_URL,
'MOD_CLASS' => strtolower(basename(dirname(__FILE__))),
'MODULE_URL' => WB_URL . "/modules/mpform",
'FTAN' => method_exists( $admin, 'getFTAN' ) ? $admin->getFTAN() : '',
// variables from global WB language files
'TXT_SAVE' => $TEXT['SAVE'],
'TXT_CANCEL' => $TEXT['CANCEL'],
'is_following_true_checked' => (($settings['is_following']==true) ? 'checked="checked"' : ''),
'is_following_false_checked' => (($settings['is_following']==true) ? '' : 'checked="checked"'),
'txt_header' => $TEXT['HEADER'],
'txt_field_loop' => $TEXT['FIELD'].' '.$TEXT['LOOP'],
'txt_footer' => $TEXT['FOOTER'],
'email_from' => ((substr($settings['email_from'], 0, 5) != 'field')
&& ($settings['email_from'] != 'wbu')
&& ($settings['email_from'] != 'EMAIL_FROM')
? $settings['email_from'] : ''),
'email_replyto' => ((substr($settings['email_replyto'], 0, 5) != 'field')
&& ($settings['email_replyto'] != 'wbu')
? $settings['email_replyto'] : ''),
'des_email_from_field' => '',
'email_fromname' => ((substr($settings['email_fromname'], 0, 5) != 'field')
&& ($settings['email_fromname'] != 'wbu')
? $settings['email_fromname'] : ''),
'des_email_fromname_field' => '',
'des_email_fromname' => '',
'des_email_subject' => '',
'txt_email_subject' => $TEXT['SUBJECT'],
'des_success_email_to' => '',
'success_email_from' => ((substr($settings['success_email_from'], 0, 5) != 'field')
&& ($settings['success_email_from'] != 'wbu')
&& ($settings['success_email_from'] != 'EMAIL_FROM')
? $settings['success_email_from'] : ''),
'success_email_fromname' => ((substr($settings['success_email_fromname'], 0, 5) != 'field')
&& ($settings['success_email_fromname'] != 'wbu')
? $settings['success_email_fromname'] : ''),
'des_success_email_from' => '',
'des_success_email_fromname' => '',
'des_success_email_subject' => '',
'txt_success_email_subject' => $TEXT['SUBJECT'],
'txt_success_email_text' => $TEXT['TEXT'],
'txt_email_text' => $TEXT['TEXT'],
'NONE' => $TEXT['NONE'],
'TXT_YES' => $TEXT['YES'],
'TXT_NO' => $TEXT['NO'],
// module settings
'MOD_SAVE_URL' => WB_URL
. str_replace("\\","/",substr(dirname(__FILE__),strlen(WB_PATH)))
. '/save_settings.php',
'MOD_CANCEL_URL' => ADMIN_URL.'/pages/modify.php?page_id='.$page_id
)
);
// returns list of email fields from the form
function give_me_address_list(&$tpl, $curr_value, $java=true, $fname = '', $wbt, $listtype='email'){
global $database, $section_id, $TEXT;
$tpl->set_block('main_block', $fname.'_block' , $fname);
$rt = false;
// add authenticated user:
$s = "<option value=\"wbu\"";
if($curr_value == 'wbu') {
$s .= " selected='selected'";
$rt = true;
}
if ($java)
$s .= " onclick=\"javascript:"
. " document.getElementById('"
. $fname."_slave').style.display = 'none';\"";
$s .= ">$wbt</option>";
$tpl->set_var('options_'.$fname, $s);
$tpl->parse($fname, $fname.'_block', true);
$s = '';
// add server email
$s = "<option value=\"SERVER_EMAIL\"";
if($curr_value == 'SERVER_EMAIL') {
$s .= " selected='selected'";
$rt = true;
}
if ($java)
$s .= " onclick=\"javascript:"
. " document.getElementById('"
. $fname."_slave').style.display = 'none';\"";
$s .= ">".$TEXT['SERVER_EMAIL']."</option>";
$tpl->set_var('options_'.$fname, $s);
$tpl->parse($fname, $fname.'_block', true);
$s = '';
$query_email_fields
= $database->query(
"SELECT `field_id`,`title`"
. " FROM `".TP_MPFORM."fields`"
. " WHERE `section_id` = '$section_id'"
. " AND (`type` = '$listtype')"
. " ORDER BY `position` ASC");
if($query_email_fields->numRows() > 0) {
while($field = $query_email_fields->fetchRow()) {
$s = "<option value=\"field".$field['field_id']."\"";
if($curr_value == 'field'.$field['field_id']) {
$s .= " selected='selected'";
$rt = true;
}
if ($java)
$s .= " onclick=\"javascript: "
. " document.getElementById('". $fname."_slave').style.display"
. " = 'none';\"";
$s .= ">".$TEXT['FIELD'].': '.$field['title']. "</option>";
$tpl->set_var('options_'.$fname, $s);
$tpl->parse($fname, $fname.'_block', true);
}
} else {
$tpl->set_var('options_'.$fname, $s);
$tpl->parse($fname, $fname.'_block', true);
}
return $rt;
}
// returns list of text fields from the form
function give_me_name_list(&$tpl, $curr_value, $java=true, $fname = '', $wbt, $listtype='textfield'){
global $database, $section_id, $TEXT;
$tpl->set_block('main_block', $fname.'_block' , $fname);
$rt = false;
// add authenticated user:
$s = "<option value=\"wbu\"";
if($curr_value == 'wbu') {
$s .= " selected='selected'";
$rt = true;
}
if ($java)
$s .= " onclick=\"javascript:"
. " document.getElementById('". $fname."_slave').style.display"
. " = 'none';\"";
$s .= ">$wbt</option>";
$tpl->set_var('options_'.$fname, $s);
$tpl->parse($fname, $fname.'_block', true);
$s = '';
$query_email_fields
= $database->query(
"SELECT `field_id`,`title`"
. " FROM `".TP_MPFORM."fields`"
. " WHERE `section_id` = '$section_id'"
. " AND (`type` = '$listtype')"
. " ORDER BY `position` ASC"
);
if($query_email_fields->numRows() > 0) {
while($field = $query_email_fields->fetchRow()) {
$s = "<option value=\"field".$field['field_id']."\"";
if(preg_match('/field'.$field['field_id'].'\b/',$curr_value)) {
$s .= " selected='selected'";
$rt = true;
}
if ($java)
$s .= " onclick=\"javascript:"
. " document.getElementById('". $fname."_slave').style.display"
. " = 'none';\"";
$s .= ">".$TEXT['FIELD'].': '.$field['title']. "</option>";
$tpl->set_var('options_'.$fname, $s);
$tpl->parse($fname, $fname.'_block', true);
}
} else {
$tpl->set_var('options_'.$fname, $s);
$tpl->parse($fname, $fname.'_block', true);
}
return $rt;
}
// returns list of possible success pages
function give_me_pages_list(&$tpl, $page, $fname){
global $database, $admin;
$tpl->set_block('main_block', $fname.'_block' , 'schleife');
$s = '';
// Get exisiting pages and show the pagenames
$query = $database->query(
"SELECT * FROM `".TABLE_PREFIX."pages`"
. " WHERE `visibility` <> 'deleted'"
);
while($mail_page = $query->fetchRow()) {
if(!$admin->page_is_visible($mail_page)) continue;
$mail_pagename = $mail_page['menu_title'];
$success_page = $mail_page['page_id'];
//$rt .= $success_page.':'.$success_page.':';
if($page == $success_page) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$s = '<option value="'.$success_page.'"'.$selected.'>'.$mail_pagename.'</option>';
$tpl->set_var('options_'.$fname, $s);
$tpl->parse('schleife', $fname.'_block', true);
}
}
// fill some fields with lists
$rt1
= give_me_address_list(
$tpl,
$email_from_value,
true,
'email_from_f',
$LANG['backend']['TXT_USER_ADDR']
);
$tpl->set_var(
'display_email_from_field',
(($rt1) ? 'none' : 'block')
);
$rt2
= give_me_name_list(
$tpl,
$email_fromname_value,
true,
'email_fromname_f',
$LANG['backend']['TXT_USER_NAME']
);
$tpl->set_var(
'display_email_fromname_field',
(($rt2) ? 'none' : 'block')
);
$rt3
= give_me_address_list(
$tpl,
$email_replyto_value,
true,
'email_replyto_f',
$LANG['backend']['TXT_USER_ADDR']
);
$tpl->set_var(
'display_email_replyto_field',
(($rt3) ? 'none' : 'block')
);
$rt4
= give_me_address_list(
$tpl,
$success_email_from_value,
true,
'success_email_from_f',
$LANG['backend']['TXT_USER_ADDR'],
'email_recip'
);
$tpl->set_var(
'display_success_email_from_field',
(($rt4) ? 'none' : 'block')
);
$rt5
= give_me_name_list(
$tpl,
$success_email_fromname_value,
true,
'success_email_fromname_f',
$LANG['backend']['TXT_USER_NAME'],
'email_recip'
);
$tpl->set_var(
'display_success_email_fromname_field',
(($rt5) ? 'none' : 'block')
);
give_me_address_list(
$tpl,
$settings['success_email_to'],
false,
'success_email_to',
$LANG['backend']['TXT_USER_ADDR']
);
give_me_pages_list(
$tpl,
$settings['success_page'],
'success_page'
);
// Parse template objects output
$tpl->parse('main', 'main_block', false);
$tpl->pparse('output', 'page',false, false);
$admin->print_footer();