-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodify_fields.php
More file actions
213 lines (192 loc) · 9.91 KB
/
modify_fields.php
File metadata and controls
213 lines (192 loc) · 9.91 KB
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
<?php
/**
* oneforall - modify_fields.php
* @version 1.2.4 @license GNU GPL @platform WBCE 1.6.5+
*/
require('../../config.php');
require(WB_PATH.'/modules/admin.php');
$inc_path = dirname(__FILE__);
require_once($inc_path.'/info.php');
if(LANGUAGE_LOADED) {
require_once($inc_path.'/languages/EN.php');
if(file_exists($inc_path.'/languages/'.LANGUAGE.'.php')) {
require_once($inc_path.'/languages/'.LANGUAGE.'.php');
}
}
// Permissions
$settings_admin_only = $database->get_one(
"SELECT `value` FROM `".TABLE_PREFIX."mod_".$mod_name."_general_settings` WHERE `name` = 'settings_admin_only'"
);
$settings_admin_only = $settings_admin_only === 'false' ? false : true;
if($settings_admin_only && !$admin->isAdmin()) {
$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
}
// Default field types + templates
require_once($inc_path.'/add_field.php');
// Hidden default templates for JS
echo '<div id="mod_'.$mod_name.'_default_templates_b" style="display:none;">'."\n";
foreach($field_template as $template) {
echo '<code>'.$template."\n</code>\n";
}
echo '</div>';
// Sync checkbox state
$sync_type_template = isset($_SESSION[$mod_name]['sync_type_template'])
? $_SESSION[$mod_name]['sync_type_template']
: ' checked="checked"';
// Fields laden
$query_fields = $database->query(
"SELECT * FROM `".TABLE_PREFIX."mod_".$mod_name."_fields`
WHERE `section_id` = '$section_id' OR `section_id` = '0'
ORDER BY position, field_id ASC"
);
$fields_count = $query_fields->numRows();
?>
<script type="text/javascript">
jQuery().sortable || document.write('<script src="<?php echo WB_URL; ?>/modules/<?php echo $mod_name; ?>/js/jquery/ui/jquery-ui.min.js"><\/script>');
var mod_<?php echo $mod_name; ?> = {
mod_name: '<?php echo $mod_name; ?>',
txt_dragdrop_message: '<?php echo $MOD_ONEFORALL[$mod_name]['TXT_DRAGDROP_MESSAGE']; ?>'
};
</script>
<form name="modify" action="<?php echo WB_URL; ?>/modules/<?php echo $mod_name; ?>/save_fields.php" method="post">
<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
<!-- Header -->
<div class="ofa-fields-topbar">
<i class="fa fa-list"></i>
<strong><?php echo $MOD_ONEFORALL[$mod_name]['TXT_FIELDS']; ?></strong>
<span class="ofa-count-badge"><?php echo $fields_count; ?></span>
<label>
<input name="sync_type_template" id="sync_type_template" type="checkbox"<?php echo $sync_type_template; ?>>
<?php echo $MOD_ONEFORALL[$mod_name]['TXT_SYNC_TYPE_TEMPLATE']; ?>
</label>
</div>
<!-- Field Cards -->
<table id="mod_<?php echo $mod_name; ?>_custom_fields_b" style="width:100%;border-collapse:collapse;">
<tbody>
<?php
if($fields_count > 0) {
while($field = $query_fields->fetchRow()) {
$field = array_map(fn($v) => stripslashes($v ?? ''), $field);
$id = $field['field_id'];
$type = $field['type'];
$extra = $field['extra'];
$name = $field['name'];
$label = $field['label'];
$template = $field['template'];
// Extra-Feld Sichtbarkeit
$extra_field_class = 'mod_'.$mod_name.'_hidden_extra_field_b';
$dir_label = $ofa_label = $fg_label = $upload_label = $opts_label
= $multiopts_label = $cb_label = $sw_label = $radio_label = $group_label
= 'mod_'.$mod_name.'_hidden_extra_label_b';
switch($type) {
case 'oneforall_link': $extra_field_class = ''; $ofa_label = ''; break;
case 'foldergallery_link':$extra_field_class = ''; $fg_label = ''; break;
case 'media': $extra_field_class = ''; $dir_label = ''; break;
case 'upload': $extra_field_class = ''; $upload_label = ''; break;
case 'select': $extra_field_class = ''; $opts_label = ''; break;
case 'multiselect': $extra_field_class = ''; $multiopts_label = ''; break;
case 'checkbox': $extra_field_class = ''; $cb_label = ''; break;
case 'switch': $extra_field_class = 'switches'; $sw_label = ''; break;
case 'radio': $extra_field_class = ''; $radio_label = ''; break;
case 'group': $extra_field_class = ''; $group_label = ''; break;
}
$extra_label_html =
'<span class="'.$ofa_label.'">' .$MOD_ONEFORALL[$mod_name]['TXT_MODULE_NAME'].'</span>'.
'<span class="'.$fg_label.'">' .$MOD_ONEFORALL[$mod_name]['TXT_FOLDERGALLERY_SECTION_ID'].'</span>'.
'<span class="'.$dir_label.'">' .$MOD_ONEFORALL[$mod_name]['TXT_DIRECTORY'].'</span>'.
'<span class="'.$upload_label.'">'.$MOD_ONEFORALL[$mod_name]['TXT_SUBDIRECTORY_OF_MEDIA'].'</span>'.
'<span class="'.$opts_label.'">' .$MOD_ONEFORALL[$mod_name]['TXT_OPTIONS'].'</span>'.
'<span class="'.$multiopts_label.'">'.$MOD_ONEFORALL[$mod_name]['TXT_MULTIOPTIONS'].'</span>'.
'<span class="'.$cb_label.'">' .$MOD_ONEFORALL[$mod_name]['TXT_CHECKBOXES'].'</span>'.
'<span class="'.$sw_label.'">' .$MOD_ONEFORALL[$mod_name]['TXT_SWITCHES'].'</span>'.
'<span class="'.$radio_label.'">' .$MOD_ONEFORALL[$mod_name]['TXT_RADIO_BUTTONS'].'</span>'.
'<span class="'.$group_label.'">' .$MOD_ONEFORALL[$mod_name]['TXT_GROUPS'].'</span>';
?>
<tr id="id_<?php echo $id; ?>">
<td style="padding:0 0 .75rem 0;">
<div class="ofa-field-card">
<!-- Card Header: Drag + ID -->
<div class="ofa-field-card-header">
<span style="cursor:move;color:#bbb;font-size:1.1em;" title="Ziehen zum Sortieren">↕</span>
<span><?php echo $MOD_ONEFORALL[$mod_name]['TXT_CUSTOM_FIELD']; ?></span>
<span class="ofa-field-card-id">id <?php echo $id; ?></span>
<span class="ofa-field-placeholder" style="margin-left:auto;">
[<?php echo htmlspecialchars(strtoupper($name)); ?>]
|
[FIELD_<?php echo htmlspecialchars($id); ?>]
</span>
</div>
<!-- Typ / Name / Label / Extra -->
<div class="ofa-field-grid">
<div>
<span class="ofa-field-label"><?php echo $MOD_ONEFORALL[$mod_name]['TXT_FIELD_TYPE']; ?></span>
<select name="fields[<?php echo $id; ?>][type]" style="width:100%;box-sizing:border-box;">
<?php foreach($field_types as $ft => $ft_name): ?>
<option value="<?php echo $ft; ?>"<?php echo $type == $ft ? ' selected="selected"' : ''; ?>><?php echo $ft_name; ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<span class="ofa-field-label"><?php echo $MOD_ONEFORALL[$mod_name]['TXT_FIELD_NAME']; ?></span>
<input type="text" name="fields[<?php echo $id; ?>][name]" value="<?php echo htmlspecialchars($name); ?>" style="width:100%;box-sizing:border-box;">
</div>
<div>
<span class="ofa-field-label"><?php echo $MOD_ONEFORALL[$mod_name]['TXT_FIELD_LABEL']; ?></span>
<input type="text" name="fields[<?php echo $id; ?>][label]" value="<?php echo htmlspecialchars($label); ?>" style="width:100%;box-sizing:border-box;">
</div>
<?php if($extra_field_class !== 'mod_'.$mod_name.'_hidden_extra_field_b'): ?>
<div>
<span class="ofa-field-label"><?php echo $extra_label_html; ?></span>
<input type="text" class="<?php echo $extra_field_class; ?>"
name="fields[<?php echo $id; ?>][extra]"
value="<?php echo htmlspecialchars($extra ?? ''); ?>"
style="width:100%;box-sizing:border-box;">
</div>
<?php else: ?>
<input type="hidden" class="<?php echo $extra_field_class; ?>"
name="fields[<?php echo $id; ?>][extra]"
value="<?php echo htmlspecialchars($extra ?? ''); ?>">
<?php endif; ?>
</div>
<!-- Template -->
<div>
<span class="ofa-field-label"><?php echo $MOD_ONEFORALL[$mod_name]['TXT_FIELD_TEMPLATE']; ?></span>
<textarea name="fields[<?php echo $id; ?>][template]"
style="width:100%;box-sizing:border-box;font-family:monospace;font-size:.82em;
padding:.35em .5em;border:1px solid #ccc;border-radius:3px;
resize:vertical;min-height:52px;"><?php echo htmlspecialchars($template); ?></textarea>
</div>
</div>
</td>
</tr>
<?php
} // end while
} else {
echo '<tr><td><p style="color:#888;padding:.5em 0;">'.$TEXT['NONE_FOUND'].'</p></td></tr>';
}
?>
</tbody>
</table>
<!-- Action Bar: Save | Center(Dropdown+Add) | Cancel -->
<div class="ofa-fields-action-bar">
<input type="submit" name="save" value="<?php echo $TEXT['SAVE']; ?>"
class="ofa-btn ofa-btn-primary"
onclick="return confirm_delete('<?php echo $MOD_ONEFORALL[$mod_name]['TXT_CONFIRM_DELETE_FIELD']; ?>', '<?php echo $MOD_ONEFORALL[$mod_name]['TXT_CUSTOM_FIELD']; ?>')">
<div class="ofa-fields-action-center">
<select name="new_fields">
<?php foreach(range(1,10) as $num): ?>
<option value="<?php echo $num; ?>"<?php echo $num == 2 ? ' selected="selected"' : ''; ?>><?php echo $num; ?></option>
<?php endforeach; ?>
</select>
<input type="submit" name="add_fields"
value="… <?php echo $MOD_ONEFORALL[$mod_name]['TXT_ADD_NEW_FIELDS']; ?>"
class="ofa-btn ofa-btn-default"
onclick="return confirm_delete('<?php echo $MOD_ONEFORALL[$mod_name]['TXT_CONFIRM_DELETE_FIELD']; ?>', '<?php echo $MOD_ONEFORALL[$mod_name]['TXT_CUSTOM_FIELD']; ?>')">
</div>
<input type="button" value="<?php echo $TEXT['CANCEL']; ?>"
class="ofa-btn ofa-btn-default"
onclick="window.location='<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>'">
</div>
</form>
<?php $admin->print_footer(); ?>