PluginProbe
Webling / 3.2.0
Webling v3.2.0
trunk 2.0 3.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.5.0 3.6.0 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.9.0 3.9.1 3.9.2
webling / src / admin / pages / form_edit.php

form_edit.php in Webling 3.2.0, at src/admin/pages/form_edit.php

453 lines 19.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class webling_page_form_edit {
4
5 public static function html() {
6 global $wpdb;
7
8 if (isset($_GET['form_id'])) {
9 $id = intval($_GET['form_id']);
10 } else {
11 $id = 0;
12 }
13
14 $formfields = [];
15 $active_formfields = [];
16
17 try {
18 $member_properties = WeblingApiHelper::Instance()->getMemberProperties();
19 $member_fields = WeblingApiHelper::Instance()->getMutableMemberFields();
20 } catch (Exception $e) {
21 include_once(__DIR__.'/../errors/no_connection.html.php');
22 return;
23 }
24
25 if (!WeblingApiHelper::Instance()->hasMemberWriteAccess()) {
26 include_once(__DIR__.'/../errors/no_write_access.html.php');
27 WeblingApiHelper::Instance()->clearCache();
28 return;
29 }
30
31 if ($id) {
32 $sql = "SELECT * FROM {$wpdb->prefix}webling_forms WHERE id = '".$id."'";
33 $data = $wpdb->get_row($sql, 'ARRAY_A');
34 if (!$data) {
35 echo 'Form with ID '.$id.' not found!';
36 return;
37 }
38 $sql = "SELECT * FROM {$wpdb->prefix}webling_form_fields WHERE form_id = '".$id."' ORDER BY `order` ASC";
39 $formfields = $wpdb->get_results($sql, 'ARRAY_A');
40 foreach ($formfields as $formfield) {
41 $active_formfields[] = $formfield['webling_field_id'];
42 }
43 } else {
44 $data = array(
45 'id' => 0,
46 'title' => __('Neues Anmeldeformular', 'webling'),
47 'group_id' => 0,
48 'notification_email' => '',
49 'confirmation_text' => __('<h2>Vielen Dank</h2>Wir haben Ihre Anmeldung erhalten.', 'webling'),
50 'submit_button_text' => __('Absenden', 'webling'),
51 'confirmation_email_enabled' => 0,
52 'confirmation_email_webling_field' => 0,
53 'confirmation_email_subject' => __("Ihre Anmeldung", 'webling'),
54 'confirmation_email_text' => __("Vielen Dank!\n\nWir haben Ihre Anmeldung erhalten.\n\nFreundliche Grüsse", 'webling'),
55 'class' => '',
56 );
57 }
58
59 echo '<div class="wrap webling-admin">';
60 if ($id) {
61 echo '<h2>'.__('Formular bearbeiten', 'webling').' (ID: '.$id.')</h2>';
62 } else {
63 echo '<h2>'.__('Formular erstellen', 'webling').'</h2>';
64 }
65 ?>
66 <form action="admin-post.php" method="post">
67 <input type="hidden" name="action" value="save_form">
68 <input type="hidden" name="form_id" value="<?php echo $data['id']; ?>">
69
70 <div id="poststuff">
71 <div id="post-body" class="metabox-holder columns-2">
72 <div id="post-body-content">
73
74 <div id="titlediv">
75 <div id="titlewrap">
76 <input type="text" name="title" size="30" id="title" placeholder="<?php echo __('Formularname', 'webling') ?>" spellcheck="true" autocomplete="off" value="<?php echo esc_attr($data['title']); ?>">
77 </div>
78 </div>
79
80 <br>
81 <div class="bodywrap">
82
83 <h2 class="nav-tab-wrapper wp-clearfix webling-tabs">
84 <a id="webling_form_tab_fields" href="#" onclick="webling_change_form_tab('fields')" class="nav-tab nav-tab-active"><?php echo __('Formularfelder', 'webling') ?></a>
85 <a id="webling_form_tab_settings" href="#" onclick="webling_change_form_tab('settings')" class="nav-tab"><?php echo __('Einstellungen', 'webling') ?></a>
86 <a id="webling_form_tab_emails" href="#" onclick="webling_change_form_tab('emails')" class="nav-tab"><?php echo __('E-Mails', 'webling') ?></a>
87 </h2>
88
89 <div class="webling-tabs-body">
90
91 <div id="webling_form_fields">
92 <br>
93 <div class="widgets-holder-wrap">
94 <p class="webling-fields-hint"><?php echo __('Ziehe Felder aus der Seitenleiste in diesen Bereich um sie zum Formular hinzuzufügen.', 'webling') ?></p>
95 <ul id="sortable_main" class="connectedSortable webling-fields-holder">
96 <?php
97 foreach ($formfields as $formfield) {
98 if (isset($member_fields[$formfield['webling_field_id']])) {
99 $fieldname = $member_fields[$formfield['webling_field_id']];
100 self::field_markup($fieldname, $member_properties[$fieldname], $formfield);
101 }
102 }
103 ?>
104 </ul>
105 </div>
106 </div>
107
108 <div id="webling_form_settings" style="display: none">
109 <table class="form-table">
110 <tr>
111 <th scope="row"><?php echo __('Mitglied in folgender Webling Gruppe erfassen', 'webling') ?></th>
112 <td>
113 <?php echo self::group_select($data['group_id']); ?>
114 <p class="description"><?php echo __('Nach dem Absenden des Formulars wird in dieser Gruppe in Webling ein Mitglied mit den angegebenen Daten erstellt.', 'webling') ?></p>
115 </td>
116 </tr>
117 <tr>
118 <th scope="row"><?php echo __('Text "Absenden"-Button', 'webling') ?></th>
119 <td>
120 <input type="text" placeholder="<?php echo __('Absenden', 'webling') ?>" name="submit_button_text" value="<?php echo esc_attr($data['submit_button_text']); ?>" class="regular-text">
121 <p class="description"><?php echo __('Text der auf dem Formular Absenden Button steht', 'webling') ?></p>
122 </td>
123 </tr>
124 <tr>
125 <th scope="row"><?php echo __('CSS Klasse', 'webling') ?></th>
126 <td>
127 <input type="text" placeholder="<?php echo __('CSS Klasse', 'webling') ?>" name="class" value="<?php echo esc_attr($data['class']); ?>" class="regular-text">
128 <p class="description"><?php echo __('CSS Klasse für dieses Formular, kann für eigene Designanpassungen verwendet werden.', 'webling') ?></p>
129 </td>
130 </tr>
131 <tr>
132 <th scope="row"><?php echo __('Bestätigungstext nach Absenden', 'webling') ?></th>
133 <td>
134 <?php wp_editor($data['confirmation_text'], 'confirmation_text'); ?>
135 <p class="description"><?php echo __('Dieser Text wird dem Besucher angezeigt, nachdem das Formular abgesendet wurde.', 'webling') ?></p>
136 </td>
137 </tr>
138 </table>
139 </div>
140
141 <div id="webling_form_emails" style="display: none">
142 <h2 class="title"><?php echo __('E-Mail Benachrichtigung an Admin', 'webling') ?></h2>
143 <p><?php echo __('Bei jeder Anmeldung über das Formular können die übermittelten Daten an eine E-Mail Adresse zur Info gesendet werden.', 'webling') ?></p>
144 <table class="form-table">
145 <tr>
146 <th scope="row"><?php echo __('Benachrichtigung senden an', 'webling') ?></th>
147 <td>
148 <input type="text" placeholder="<?php echo __('E-Mail Adresse', 'webling') ?>" name="notification_email" value="<?php echo esc_attr($data['notification_email']); ?>" class="regular-text">
149 <p class="description"><?php echo __('Eine E-Mail mit den übermittelten Formulardaten wird an diese Adresse versandt.', 'webling') ?></p>
150 </td>
151 </tr>
152 </table>
153 <h2 class="title"><?php echo __('E-Mail Bestätigung an Besucher', 'webling') ?></h2>
154 <p></p>
155 <table class="form-table">
156 <tr>
157 <th scope="row"><?php echo __('E-Mail Bestätgung an Besucher senden', 'webling') ?></th>
158 <td>
159 <fieldset>
160 <label for="confirmation_email_enabled">
161 <input name="confirmation_email_enabled" onclick="webling_toggle_confirmation_settings()" type="checkbox" id="confirmation_email_enabled" <?php echo ($data['confirmation_email_enabled'] ? 'checked' : ''); ?>>
162 <?php echo __('Eine Bestätigung an den Besucher senden', 'webling') ?>
163 </label>
164 </fieldset>
165 <p class="description"><?php echo __('Eine Bestätigung per E-Mail an den Besucher senden wenn er das Formular abgeschickt hat.', 'webling') ?></p>
166 </td>
167 </tr>
168 <tr class="webling_confirmation_settings">
169 <th scope="row"><?php echo __('E-Mail Formular Feld', 'webling') ?></th>
170 <td>
171 <script type="text/javascript">
172 var preselected_confirmation_email_webling_field = <?php echo intval($data['confirmation_email_webling_field']); ?>;
173 </script>
174 <select id="confirmation_email_webling_field" name="confirmation_email_webling_field" class="regular-text"></select>
175 <p class="description" id="confirmation_email_webling_field_error" style="color: red;"><?php echo __('Kein E-Mail Feld im Formular gefunden. Füge ein E-Mail Feld zum Formular hinzu um diese Funktion zu nutzen.', 'webling') ?></p>
176 <p class="description"><?php echo __('Wähle das E-Mail Feld in deinem Formular. Der Besucher erhält eine Bestätigung an die Adresse die in das hier ausgewählte Feld eingegeben wurde. Das E-Mail wird nur versandt, wenn die Adresse ausgefüllt wurde und gültig ist.', 'webling') ?></p>
177 </td>
178 </tr>
179 <tr class="webling_confirmation_settings">
180 <th scope="row"><?php echo __('E-Mail Betreff', 'webling') ?></th>
181 <td>
182 <input type="text" placeholder="<?php echo __('E-Mail Betreff', 'webling') ?>" name="confirmation_email_subject" value="<?php echo esc_attr($data['confirmation_email_subject']); ?>" class="regular-text">
183 <p class="description"><?php echo __('Der Betreff der E-Mail an den Besucher.', 'webling') ?></p>
184 </td>
185 </tr>
186 <tr class="webling_confirmation_settings">
187 <th scope="row"><?php echo __('E-Mail Text', 'webling') ?></th>
188 <td>
189 <textarea placeholder="<?php echo __('E-Mail Bestätigungstext', 'webling') ?>" name="confirmation_email_text" style="width: 100%; height: 300px"><?php echo esc_html($data['confirmation_email_text']); ?></textarea>
190 <p class="description"><?php echo __('Der E-Mail-Text der an den Besucher gesendet wird. Du kannst in diesem Text Platzhalter im Format <code>[[Feldname]]</code> verwenden. Achtung: Verwende den Feldnamen in Webling und nicht den Feldnamen aus dem Formular!', 'webling') ?></p>
191 </td>
192 </tr>
193 </table>
194 </div>
195
196 </div>
197
198 <?php
199 if ($id) {
200 submit_button(__('Formular speichern', 'webling'), 'primary', 'submit');
201 } else {
202 submit_button(__('Formular erstellen', 'webling'), 'primary', 'submit');
203 }
204 ?>
205 </div>
206 </div>
207 <div id="postbox-container-1" class="postbox-container">
208 <div id="side-sortables" class="meta-box-sortables">
209 <div id="submitdiv" class="postbox">
210 <h2 class="hndle"><span><?php echo __('Veröffentlichen', 'webling') ?></span></h2>
211 <div class="inside">
212 <div class="submitbox" id="submitpost">
213 <div id="misc-publishing-actions">
214 <div class="misc-pub-section">
215 <?php if ($id) { ?>
216 <p><?php echo __('Füge diesen Shortcode in eine Seite oder einen Artikel ein um dieses Formular anzuzeigen:', 'webling') ?></p>
217 <p>
218 <input title="Shortcode" class="shortcode" type="text" value='[webling_form id="<?php echo $id; ?>"]'>
219 </p>
220 <?php } else { ?>
221 <p><?php echo __('Nach dem Erstellen wird ein Shortcode erstellt, mit welchem du das Formular auf einer Seite oder in einem Artikel anzeigen kannst.', 'webling') ?></p>
222 <?php } ?>
223 </div>
224 </div>
225 <div id="major-publishing-actions">
226 <!--div id="delete-action">
227 <a class="submitdelete deletion" href="http://localhost/webling/wordpress-4.7.0/wp-admin/post.php?post=1&amp;action=trash&amp;_wpnonce=970d6cb90f">Move to Trash</a>
228 </div-->
229 <div id="publishing-action">
230 <input name="save" type="submit" class="button button-primary button-large" id="publish" value="<?php echo __('Speichern', 'webling') ?>">
231 </div>
232 <div class="clear"></div>
233 </div>
234 </div>
235 </div>
236 </div>
237 <div id="webling_fields_div" class="postbox">
238 <h2 class="hndle"><span><?php echo __('Felder', 'webling') ?></span></h2>
239 <div class="inside">
240 <p><?php echo __('Ziehe diese Felder in den Hauptbereich um sie zum Formular hinzuzufügen:', 'webling') ?></p>
241 <ul id="sortable_side" class="connectedSortable">
242 <?php
243 foreach ($member_properties as $name => $config) {
244 if (!in_array($config['id'], $active_formfields)) {
245 if (!in_array($member_properties[$name]['datatype'], WeblingApiHelper::$immutableFields)) {
246 self::field_markup($name, $config);
247 }
248 }
249 }
250 ?>
251 </ul>
252 </div>
253 </div>
254 </div>
255 </div>
256 </div>
257 </div>
258 </form>
259
260 </div>
261
262 <script type="text/javascript">
263 jQuery(function() {
264 jQuery("#sortable_main, #sortable_side").sortable({
265 connectWith: ".connectedSortable",
266 handle: ".widget-top",
267 start: function (event, ui) {
268 if (jQuery(event.currentTarget).attr('id') == 'sortable_side') {
269 jQuery("#sortable_main").addClass('dragging');
270 }
271 },
272 stop: function (event, ui) {
273 jQuery("#sortable_main").removeClass('dragging');
274 webling_update_sorted_form_fields();
275 }
276 }).disableSelection();
277
278 jQuery("#confirmation_email_webling_field").change(function() {
279 preselected_confirmation_email_webling_field = parseInt(jQuery("#confirmation_email_webling_field").val());
280 console.log(preselected_confirmation_email_webling_field);
281 });
282
283 webling_update_sorted_form_fields();
284 webling_toggle_confirmation_settings();
285 });
286 </script>
287
288 <?php
289 }
290
291 protected static function group_select($selected = 0) {
292 $tree = WeblingApiHelper::Instance()->getMembergroupTree();
293
294 // select first root group if no selection given
295 if (!$selected) {
296 $keys = array_keys($tree);
297 $selected = $keys[0];
298 }
299
300 $html = '';
301 foreach ($tree as $nodeId => $node) {
302 $html .= self::group_select_recursive($nodeId, $node, $selected);
303 }
304 return '<select name="group_id">'.$html.'</select>';
305 }
306
307 protected static function group_select_recursive($nodeId, $tree, $selected, $indent = 0) {
308 $is_selected = ($nodeId == $selected && $tree['writeable'] ? ' selected' : '');
309 $is_writeable = ($tree['writeable'] ? '' : ' disabled');
310 $html = '<option value="'.$nodeId.'" '.$is_selected.$is_writeable.'>'.str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $indent).$tree['title'] .'</option>';
311 foreach ($tree['childs'] as $nodeId => $node) {
312 $html .= self::group_select_recursive($nodeId, $node, $selected, $indent+1);
313 }
314 return $html;
315 }
316
317 protected static function translated_datatype($config) {
318 switch($config['datatype']) {
319 case 'text':
320 if (isset($config['type']) && $config['type'] == 'email') {
321 return __('Text, E-Mail', 'webling');
322 } else {
323 return __('Text', 'webling');
324 }
325 break;
326 case 'longtext':
327 return __('Mehrzeiliger Text', 'webling');
328 break;
329 case 'int':
330 return __('Zahl', 'webling');
331 break;
332 case 'numeric':
333 return __('Betrag', 'webling');
334 break;
335 case 'bool':
336 return __('Checkbox', 'webling');
337 break;
338 case 'enum':
339 return __('Auswahlfeld', 'webling');
340 break;
341 case 'multienum':
342 return __('Mehrfachauswahlfeld', 'webling');
343 break;
344 case 'date':
345 return __('Datum', 'webling');
346 break;
347 case 'image':
348 case 'file':
349 case 'autoincrement':
350 default:
351 return ucfirst($config['datatype']);
352 }
353 }
354
355 protected static function field_markup($name, $config, $data = null) {
356 if (!is_array($data)) {
357 $data = [
358 'required' => 0,
359 'field_name' => $name,
360 'field_name_position' => 'TOP',
361 'placeholder_text' => '',
362 'description_text' => '',
363 'class' => ''
364 ];
365 }
366 $fieldid = $config['id'];
367 $type = $config['datatype'];
368 ?>
369 <li class="widget" id="webling-field-<?php echo $fieldid; ?>" <?php echo (isset($config['type']) ? ' data-webling-type="'.$config['type'].'"' : ''); ?>>
370 <div class="widget-top" onclick="webling_toggle_field('<?php echo $fieldid; ?>')">
371 <div class="widget-title-action">
372 <a class="widget-action" href="#"></a>
373 </div>
374 <div class="widget-title ui-sortable-handle">
375 <h3><?php echo esc_html($name); ?></h3>
376 </div>
377 </div>
378 <div class="widget-inside">
379 <div class="widget-content">
380 <input type="hidden" name="fields[<?php echo $fieldid; ?>][webling_field_id]" value="<?php echo $config['id']; ?>" class="fieldid">
381 <input type="hidden" name="fields[<?php echo $fieldid; ?>][order]" class="order" value="0">
382 <table class="form-table">
383 <tr>
384 <th scope="row"><?php echo __('Feld in Webling', 'webling') ?></th>
385 <td><?php echo esc_html($name); ?> <span class="description">(<?php echo self::translated_datatype($config) ?>)</span></td>
386 </tr>
387 <tr <?php if($type == 'multienum') echo 'style="display: none;"'; ?>>
388 <th scope="row"><?php echo __('Pflichtfeld', 'webling') ?></th>
389 <td>
390 <label>
391 <input name="fields[<?php echo $fieldid; ?>][required]" type="checkbox" value="1" <?php echo ($data['required'] ? 'checked' : ''); ?>>
392 <?php echo __('Feld muss ausgefüllt werden', 'webling') ?>
393 </label>
394 </td>
395 </tr>
396 <tr>
397 <th scope="row"><?php echo __('Feldname', 'webling') ?></th>
398 <td>
399 <input type="text" name="fields[<?php echo $fieldid; ?>][field_name]" value="<?php echo esc_attr($data['field_name']); ?>" placeholder="<?php echo __('Name des Formularfeldes', 'webling') ?>" class="regular-text fieldname">
400 </td>
401 </tr>
402 <tr>
403 <th scope="row"><?php echo __('Position des Feldnamens', 'webling') ?></th>
404 <td>
405 <select name="fields[<?php echo $fieldid; ?>][field_name_position]">
406 <option value="TOP" <?php echo ($data['field_name_position'] == 'TOP' ? 'selected' : ''); ?>><?php echo __('Oberhalb', 'webling') ?></option>
407 <option value="LEFT" <?php echo ($data['field_name_position'] == 'LEFT' ? 'selected' : ''); ?>><?php echo __('Links', 'webling') ?></option>
408 <option value="HIDDEN" <?php echo ($data['field_name_position'] == 'HIDDEN' ? 'selected' : ''); ?>><?php echo __('Feldnamen nicht anzeigen', 'webling') ?></option>
409 </select>
410 </td>
411 </tr>
412 <tr <?php if(in_array($type, array('date','multienum'))) echo 'style="display: none;"'; ?>>
413 <th scope="row">
414 <?php
415 if($type == 'bool') echo __('Beschriftung', 'webling');
416 else echo __('Platzhalter', 'webling');
417 ?>
418 </th>
419 <td>
420 <input type="text" name="fields[<?php echo $fieldid; ?>][placeholder_text]" value="<?php echo esc_attr($data['placeholder_text']); ?>" placeholder="<?php
421 if($type == 'bool') echo __('Beschriftung der Checkbox', 'webling');
422 else echo __('Platzhalter text', 'webling');
423 ?>" class="regular-text">
424 </td>
425 </tr>
426 <tr>
427 <th scope="row"><?php echo __('Beschreibungstext', 'webling') ?></th>
428 <td>
429 <input type="text" name="fields[<?php echo $fieldid; ?>][description_text]" value="<?php echo esc_attr($data['description_text']); ?>" placeholder="<?php echo __('Kurzer Hilfe- oder Beschreibungstext', 'webling') ?>" class="regular-text">
430 </td>
431 </tr>
432 <tr>
433 <th scope="row"><?php echo __('CSS Klasse', 'webling') ?></th>
434 <td>
435 <input type="text" name="fields[<?php echo $fieldid; ?>][class]" value="<?php echo esc_attr($data['class']); ?>" placeholder="<?php echo __('CSS Klasse', 'webling') ?>" class="regular-text">
436 </td>
437 </tr>
438 </table>
439 <div class="widget-control-actions">
440 <div class="alignleft">
441 <a class="widget-control-remove" href="#remove" onclick="return webling_remove_field('<?php echo $fieldid; ?>')"><?php echo __('Feld entfernen', 'webling') ?></a> |
442 <a class="widget-control-close" href="#close" onclick="return webling_toggle_field('<?php echo $fieldid; ?>')"><?php echo __('Schliessen', 'webling') ?></a>
443 </div>
444 <br class="clear">
445 </div>
446
447 </div>
448 </div>
449 </li>
450 <?php
451 }
452 }
453