PluginProbe
Contact Forms by Cimatti / 1.4.1
Contact Forms by Cimatti v1.4.1
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / accua-forms.php

accua-forms.php in Contact Forms by Cimatti 1.4.1, at accua-forms.php

3,825 lines 167.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 add_action('admin_menu', 'accua_forms_menu', -95);
3 function accua_forms_menu(){
4 $dashboard_admin_page=add_menu_page('Wordpress Contact Forms by Cimatti', 'Forms', 'manage_options', 'accua_forms', 'accua_dashboard_page', ACCUA_FORMS_DIR_URL.'img/cimatti-16-icon.png');
5 add_action('load-'.$dashboard_admin_page, 'accua_dashboard_page_head');
6
7 add_submenu_page('accua_forms', 'Wordpress Contact Forms by Cimatti', 'Dashboard', 'manage_options', "accua_forms", 'accua_dashboard_page');
8
9 $form_edit_page = add_submenu_page('accua_forms', 'Forms', 'Forms', 'manage_options', "accua_forms_list", 'accua_forms_list_page');
10 add_action('admin_head-'.$form_edit_page, 'accua_forms_edit_page_head');
11 add_action( 'admin_print_styles-'.$form_edit_page, 'accua_forms_edit_page_head_styles');
12 add_action( 'admin_print_scripts-'.$form_edit_page, 'accua_forms_edit_page_head_scripts');
13
14 $form_add_page = add_submenu_page('accua_forms', __('Add new form', 'accua-form-api'), __('Add new', 'accua-form-api'), 'manage_options', "accua_forms_add", 'accua_forms_add_page');
15 add_action('admin_head-'.$form_add_page, 'accua_forms_edit_page_head');
16 add_action( 'admin_print_styles-'.$form_add_page, 'accua_forms_edit_page_head_styles');
17 add_action( 'admin_print_scripts-'.$form_add_page, 'accua_forms_edit_page_head_scripts');
18
19 $form_submissions_page = add_submenu_page('accua_forms', __('Forms submissions', 'accua-form-api') , __('Submissions', 'accua-form-api'), 'manage_options', "accua_forms_submissions_list", 'accua_forms_submissions_list_page');
20 add_action('admin_head-'.$form_submissions_page, 'accua_forms_submissions_list_page_head');
21
22 $form_fields_page = add_submenu_page('accua_forms', __( 'Form fields', 'accua-form-api'), __('Fields', 'accua-form-api'), 'manage_options', "accua_forms_fields", 'accua_forms_fields_page');
23 //add_action('admin_head-'.$form_fields_page, 'accua_forms_fields_page_head');
24 add_action( 'admin_print_styles-'.$form_fields_page, 'accua_forms_edit_page_head_styles');
25
26 $settings_page = add_submenu_page('accua_forms', __( 'Default Forms settings', 'accua-form-api'), __('Settings', 'accua-form-api'), 'manage_options', "accua_forms_settings", 'accua_forms_settings_page');
27 add_action( 'admin_print_styles-'.$settings_page, 'accua_forms_edit_page_head_styles');
28 add_action( 'admin_print_scripts-'.$settings_page, 'accua_forms_settings_page_head_scripts');
29
30 wp_enqueue_script('jquery-form');
31 wp_enqueue_script('jquery-color');
32 wp_enqueue_script('jquery-ui-core');
33 wp_enqueue_script('jquery-ui-tabs');
34 wp_enqueue_script('jquery-ui-sortable');
35 wp_enqueue_script('jquery-ui-draggable');
36 wp_enqueue_script('jquery-ui-droppable');
37 wp_enqueue_script('jquery-ui-selectable');
38 wp_enqueue_script('jquery-ui-resizable');
39 wp_enqueue_script('jquery-ui-dialog');
40 wp_enqueue_style('wp-jquery-ui-dialog');
41 }
42
43 function accua_forms_report_page_head(){
44 $column_list = array(
45 'month' => __( 'Month', 'accua-form-api'),
46 'unique_submissions' => __( 'Unique submissions', 'accua-form-api') ,
47 'submissions' => __('Total submissions', 'accua-form-api'),
48 );
49 global $hook_suffix;
50 register_column_headers($hook_suffix, $column_list);
51
52 //$baseurl = WP_PLUGIN_URL.'/'.substr(plugin_basename(__FILE__),0,-strlen(basename(__FILE__)));
53 //echo '<link href="'.$baseurl.'/flot/layout.css" rel="stylesheet" type="text/css">';
54 //echo '<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="'.$baseurl.'/flot/excanvas.min.js"></script><![endif]-->';
55 //echo '<script language="javascript" type="text/javascript" src="'.$baseurl.'/flot/jquery.flot.js"></script>';
56
57 }
58
59
60 function accua_forms_report_page() {
61 ?>
62 <div id="accua_forms_report_page" class="accua_forms_admin_page wrap">
63 <h2>Forms submissions report</h2>
64
65 <?php
66 global $wpdb, $hook_suffix;
67 $months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
68
69 $query = "SELECT YEAR(sub_date) AS `year`, MONTH(sub_date) AS `month`, COUNT(DISTINCT `email`) AS `unique_submissions`, COUNT(*) AS `submissions`
70 FROM `{$wpdb->prefix}cformssubmissions`
71 GROUP BY `year`, `month`
72 ORDER BY `year` DESC, `month` DESC";
73
74 $results = $wpdb->get_results($query);
75
76 if ($results) {
77 ?>
78 <style type="text/css">
79 .column-submissions, .column-unique_submissions {
80 text-align: right !important;
81 }
82 </style>
83 <div id="accua-form-report-graph" style="height:300px;"></div>
84 <table class="widefat" id="stnl_review_reviewed">
85 <thead>
86 <tr><?php print_column_headers($hook_suffix); ?></tr>
87 </thead>
88
89 <tfoot>
90 <tr><?php print_column_headers($hook_suffix, false); ?></tr>
91 </tfoot>
92
93 <tbody>
94 <?php
95 $alternate = false;
96 $hidden = get_hidden_columns($hook_suffix);
97 $data = array(
98 array( 'label' => __( 'Unique submissions', 'accua-form-api'), 'data' => array()),
99 array( 'label' => __( 'Total submissions', 'accua-form-api'), 'data' => array()),
100 );
101 foreach ($results as $result){
102 $month = $months[$result->month];
103 echo "<tr class='iedit ".(($alternate = !$alternate)?'alternate':'')."'>\n";
104 echo "<td class='column-month'".(in_array('month', $hidden)?" style='display:none;'":'').">$month {$result->year}</td>\n";
105 echo "<td class='column-unique_submissions'".(in_array('unique_submissions', $hidden)?" style='display:none;'":'').">{$result->unique_submissions}</td>\n";
106 echo "<td class='column-submissions'".(in_array('submissions', $hidden)?" style='display:none;'":'').">{$result->submissions}</td>\n";
107 echo "</tr>\n";
108 $time = mktime(0, 0, 0, $result->month, 1, $result->year) * 1000;
109 $data[0]['data'][] = array($time, (int)$result->unique_submissions);
110 $data[1]['data'][] = array($time, (int)$result->submissions);
111 }
112 /*
113 $year = $results[0]->year;
114 $month = $results[0]->month;
115 while ($year <= $result->year || $month <= $result->month) {
116
117 $month++;
118 if ($month > 12) {
119 $year++;
120 $month = 1;
121 }
122 }
123 */
124 ?>
125 </tbody>
126 </table>
127 <script type="text/javascript">
128 jQuery(function($){
129 var data = <?php echo json_encode($data, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP); ?> ;
130 var options = {
131 xaxis: {
132 //autoscaleMargin: 0.005,
133 mode: "time",
134 timeformat: "%b %y",
135 minTickSize: [1, "month"]
136 },
137 legend: {
138 position: "nw"
139 }
140 };
141 $.plot($("#accua-form-report-graph"), data, options);
142 });
143 </script>
144 <?php
145 }
146 ?>
147
148 </div>
149 <?php
150 }
151
152 function accua_forms_edit_page_head_styles() {
153 //wp_admin_css( 'widgets' );
154 wp_enqueue_style( 'accua-forms-admin', plugins_url('accua-forms-admin.css', __FILE__), array('wp-color-picker'), '2');
155 }
156
157 function accua_forms_edit_page_head_scripts() {
158 //wp_enqueue_script('admin-widgets');
159 /*wp_enqueue_script('jquery-ui-sortable');
160 wp_enqueue_script('jquery-ui-draggable');
161 wp_enqueue_script('jquery-ui-droppable');*/
162 wp_enqueue_script( 'accua-form-fields', plugins_url( 'form-fields.js' , __FILE__ ), array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '2' );
163 wp_enqueue_script( 'accua-form-settings', plugins_url( 'form-settings.js' , __FILE__ ), array( 'jquery', 'wp-color-picker' ), '1.1');
164 }
165
166 function accua_forms_settings_page_head_scripts() {
167 wp_enqueue_script('wp-color-picker');
168 }
169
170 function accua_forms_edit_page_head() {
171 if (isset($_POST['accua-form-edit-action']) || (!isset($_GET['fid']))) {
172 _accua_forms_form_edit_action();
173 require_once('accua-forms-list-page.php');
174 accua_forms_list_page_table(true);
175 }
176
177 ?>
178 <style type="text/css">
179 .container > div {
180 padding: 0px;
181 margin-bottom: 6px;
182 }
183 .widget-liquid-right .widget, #wp_inactive_widgets .widget, .widget-liquid-right .sidebar-description, .widget-placeholder {
184 width: 95%;
185 }
186 .column-submissions {
187 text-align: right !important;
188 }
189 </style>
190 <?php
191 }
192
193 add_action( 'wp_ajax_accua-form-fields-order' , 'accua_forms_form_fields_order');
194 function accua_forms_form_fields_order() {
195 $post = stripslashes_deep($_POST);
196 //update_option('accua_forms_form_fields_order_post', $post);
197
198 if (empty($post['sidebars'])) {
199 die('-1');
200 }
201
202 $forms_data = get_option('accua_forms_saved_forms', array());
203
204 foreach ($post['sidebars'] as $fid => $order) {
205 if (strpos($fid, 'cimatti-accua-fields-form-area-') !== 0){
206 die('-1');
207 }
208 $fid = substr($fid, 31);
209
210 $old_fields = $forms_data[$fid]['fields'];
211 unset($forms_data[$fid]['fields']);
212 $new_fields = array();
213
214 $order = explode(',', $order);
215
216 foreach ($order as $i) {
217 $i = preg_replace('/^(new-)?widget-\\d+_/', '', $i);
218 if (isset($old_fields[$i])) {
219 $new_fields[$i] = $old_fields[$i];
220 unset($old_fields[$i]);
221 }
222 }
223
224 if($old_fields){
225 $new_fields += $old_fields;
226 }
227 $forms_data[$fid]['fields'] = $new_fields;
228 }
229
230 update_option('accua_forms_saved_forms', $forms_data);
231
232 die('1');
233 }
234
235 add_action( 'wp_ajax_accua-save-form-field', 'accua_forms_save_form_field');
236 function accua_forms_save_form_field() {
237 $post = stripslashes_deep($_POST);
238
239 //update_option('accua_forms_save_form_field_post', $post);
240
241 $forms_data = get_option('accua_forms_saved_forms', array());
242 $fid = $post['form-id'];
243 if (empty($forms_data[$fid]['fields'])) {
244 $forms_data[$fid]['fields'] = array();
245 }
246
247 @ $wid = $post['widget-id'];
248 if (empty($post['delete_widget'])) {
249 //$istance_id = $post['multi_number'];
250 @ $ref = $post['id_base'];
251 $required = !empty($post["form-field-{$wid}-required"]);
252 $widget_number = empty($post['multi_number']) ? (empty($post['widget_number']) ? '' : $post['widget_number']) : $post['multi_number'];
253
254 $forms_data[$fid]['fields'][$wid] = array (
255 'istance_id' => $wid,
256 'widget_number' => $widget_number,
257 'ref' => $ref,
258 'required' => $required,
259 );
260
261 if (!empty($post["form-field-{$wid}-override-label"])) {
262 @ $label = (string) $post["form-field-{$wid}-label"];
263 $forms_data[$fid]['fields'][$wid]['label'] = $label;
264 }
265
266 if (!empty($post["form-field-{$wid}-override-default-value"])) {
267 @ $default_value = (string) $post["form-field-{$wid}-default-value"];
268 $forms_data[$fid]['fields'][$wid]['default_value'] = $default_value;
269 }
270
271 if (!empty($post["form-field-{$wid}-override-allowed-values"])) {
272 @ $allowed_values = (string) $post["form-field-{$wid}-allowed-values"];
273 $forms_data[$fid]['fields'][$wid]['allowed_values'] = $allowed_values;
274 }
275
276
277 } else {
278 unset($forms_data[$fid]['fields'][$wid]);
279 }
280
281 update_option('accua_forms_saved_forms', $forms_data);
282
283 die('1');
284 }
285
286 add_action( 'wp_ajax_accua-save-form-settings', 'accua_forms_save_form_settings');
287 function accua_forms_save_form_settings() {
288 $post = stripslashes_deep($_POST);
289
290 $forms_data = get_option('accua_forms_saved_forms', array());
291 $fid = $post['form-id'];
292
293
294 $settings = array(
295 'title',
296 'success_message',
297 'success_message_no_message',
298 'error_message',
299 'error_message_no_message',
300 'emails_from_name',
301 'emails_from',
302 'admin_emails_to',
303 'emails_bcc',
304 'admin_emails_subject',
305 'admin_emails_message',
306 'admin_emails_message_no_message',
307 'confirmation_emails_subject',
308 'confirmation_emails_message',
309 'confirmation_emails_message_no_message',
310 //'use_ajax',
311
312 'layout',
313 'style_margin',
314 'style_border_color',
315 'style_border_width',
316 'style_border_radius',
317 'style_background_color',
318 'style_padding',
319 'style_color',
320 'style_font_size',
321 'style_field_spacing',
322 'style_field_border_color',
323 'style_field_border_width',
324 'style_field_border_radius',
325 'style_field_background_color',
326 'style_field_padding',
327 'style_field_color',
328 'style_submit_border_color',
329 'style_submit_border_width',
330 'style_submit_border_radius',
331 'style_submit_background_color',
332 'style_submit_padding',
333 'style_submit_color',
334 'style_submit_font_size',
335 );
336
337 // print_r($post);
338
339 foreach($settings as $i) {
340 if (isset($post[$i])) {
341 $forms_data[$fid][$i] = $post[$i];
342 } else {
343 unset($forms_data[$fid][$i]);
344 }
345 }
346
347
348 $forms_data[$fid]['use_ajax'] = !empty($post['use_ajax']);
349
350 update_option('accua_forms_saved_forms', $forms_data);
351
352 print_r($forms_data[$fid]);
353
354 die('');
355 }
356
357 function accua_forms_field_settings_form_counter() {
358 static $i = 0;
359 $i++;
360 return $i;
361 }
362
363 function accua_forms_field_text_settings_form($fid, $field_data=array(), $istance_data=array()){
364 static $html_multi_number = 1;
365 $i = accua_forms_field_settings_form_counter();
366
367 $hidden = '';
368 if (!is_array($istance_data)) {
369 if ($istance_data === 'hidden') {
370 $hidden = 'style="display:none"';
371 }
372 $istance_data = array();
373 $empty_istance = true;
374 } else {
375 $empty_istance = empty($istance_data);
376 }
377
378 if (!is_array($field_data)){
379 $field_data = array();
380 }
381
382 $field_data += array(
383 'id' => '__html',
384 'name' => __( 'Custom HTML content', 'accua-form-api'),
385 'type' => 'html',
386 'description' => __('Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
387 'default_value' => '',
388 'allowed_values' => '',
389 );
390
391 $override_label = isset($istance_data['label']) ? 'checked="checked"' : '';
392 $override_default_value = isset($istance_data['default_value']) ? 'checked="checked"' : '';
393 $override_allowed_values = isset($istance_data['allowed_values']) ? 'checked="checked"' : '';
394
395 if (($field_data['type'] === 'file') && ($field_data['allowed_values'] === '')) {
396 $file_data = get_option('accua_forms_default_file_field_data',array());
397 if (isset($file_data['valid_extensions'])){
398 $field_data['allowed_values'] = $file_data['valid_extensions'];
399 }
400 }
401
402 $istance_data += array(
403 'istance_id' => $field_data['id'],
404 'widget_number' => '',
405 'ref' => $field_data['id'],
406 'label' => $field_data['name'],
407 'default_value' => $field_data['default_value'],
408 'allowed_values' => $field_data['allowed_values'],
409 'required' => false,
410 );
411
412
413
414 foreach ($istance_data as $key => $value) {
415 $istance_data[$key] = htmlspecialchars($istance_data[$key], ENT_QUOTES);
416 }
417
418 foreach ($field_data as $key => $value) {
419 $field_data[$key] = htmlspecialchars($field_data[$key], ENT_QUOTES);
420 }
421
422 $multi_number = '';
423
424 if (in_array($istance_data['ref'], array('__html','__fieldset-begin','__fieldset-end'))) {
425 $forceoverride_field = true;
426 if ($empty_istance) {
427 $add_new = 'multi';
428 $istance_data['istance_id'] .= '-__i__';
429 $istance_data['widget_number'] = 1;
430 $multi_number = 1 + $html_multi_number;
431 } else {
432 if ($html_multi_number < $istance_data['widget_number']) {
433 $html_multi_number = $istance_data['widget_number'];
434 }
435 }
436 } else {
437 $forceoverride_field = false;
438 $add_new = $empty_istance ? 'single' : '';
439 }
440
441 $fid = htmlspecialchars($fid, ENT_QUOTES);
442 $testi_eot = array (
443 'label' => __( 'Label', 'accua-form-api'),
444 'override' => __( 'override', 'accua-form-api'),
445 'default_value' => __( 'Default value', 'accua-form-api'),
446 'default_values' => __( 'Default value(s)', 'accua-form-api'),
447 'desc_def' => __( 'For multiple default values, use | as separator.', 'accua-form-api'),
448 'allowed_values' => __( 'Allowed values', 'accua-form-api'),
449 'desc_all' => __( 'The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database. The label is optional, and the key will be used as the label if no label is specified.', 'accua-form-api'),
450 'allowed_extensions' => __( 'Allowed extensions', 'accua-form-api'),
451 'desc_all_ext' => __( 'Accepted file extensions. One per line, without dots.', 'accua-form-api'),
452 'required' => __( 'Required', 'accua-form-api'),
453 'custom_HTML_content' => __( 'Custom HTML content', 'accua-form-api'),
454 'remove' => __( 'Remove', 'accua-form-api'),
455 'close' => __( 'Close', 'accua-form-api'),
456 'save' => __( 'Save', 'accua-form-api')
457 );
458
459 if ($forceoverride_field) {
460 $override_begin = '';
461 $override_type = 'hidden';
462 $override_end = '';
463 } else {
464 $override_begin = "({$testi_eot['override']}: ";
465 $override_type = 'checkbox';
466 $override_end = ')';
467 }
468
469 $content = <<<EOT
470 <p><label for="widget-{$istance_data['istance_id']}-label">{$testi_eot['label']}:</label>
471 {$override_begin}<input type="{$override_type}" name="form-field-{$istance_data['istance_id']}-override-label" value="1" {$override_label} />{$override_end}<br>
472 <input type="text" value="{$istance_data['label']}" name="form-field-{$istance_data['istance_id']}-label" id="widget-{$istance_data['istance_id']}-label" class="widefat"></p>
473 EOT;
474
475 $default_value = <<<EOT
476 <p><label for="widget-{$istance_data['istance_id']}-default-value">{$testi_eot['default_value']}:</label>
477 {$override_begin}<input type="{$override_type}" name="form-field-{$istance_data['istance_id']}-override-default-value" value="1" {$override_default_value} />{$override_end}<br>
478 <input type="text" value="{$istance_data['default_value']}" name="form-field-{$istance_data['istance_id']}-default-value" id="widget-{$istance_data['istance_id']}-default-value" class="widefat"></p>
479 EOT;
480
481 $default_values = <<<EOT
482 <p><label for="widget-{$istance_data['istance_id']}-default-value">{$testi_eot['default_value']}:</label>
483 {$override_begin}<input type="{$override_type}" name="form-field-{$istance_data['istance_id']}-override-default-value" value="1" {$override_default_value} />{$override_end}<br>
484 <input type="text" value="{$istance_data['default_value']}" name="form-field-{$istance_data['istance_id']}-default-value" id="widget-{$istance_data['istance_id']}-default-value" class="widefat"><br />
485 </p>
486 EOT;
487
488 $allowed_values = <<<EOT
489 <p><label for="widget-{$istance_data['istance_id']}-allowed-values">{$testi_eot['allowed_values']}:</label>
490 {$override_begin}<input type="{$override_type}" name="form-field-{$istance_data['istance_id']}-override-allowed-values" value="1" {$override_allowed_values} />{$override_end}<br>
491 <textarea rows="6" cols="50" name="form-field-{$istance_data['istance_id']}-allowed-values" id="widget-{$istance_data['istance_id']}-allowed-values" class="widefat">{$istance_data['allowed_values']}</textarea><br />
492 {$testi_eot['desc_all']}</p>
493 EOT;
494
495 $allowed_ext = <<<EOT
496 <p><label for="widget-{$istance_data['istance_id']}-allowed-values">{$testi_eot['allowed_extensions']}:</label>
497 {$override_begin}<input type="{$override_type}" name="form-field-{$istance_data['istance_id']}-override-allowed-values" value="1" {$override_allowed_values} />{$override_end}<br>
498 <textarea rows="6" cols="50" name="form-field-{$istance_data['istance_id']}-allowed-values" id="widget-{$istance_data['istance_id']}-allowed-values" class="widefat">{$istance_data['allowed_values']}</textarea><br />
499 {$testi_eot['desc_all_ext']}</p>
500 EOT;
501
502 $required_checked = empty($istance_data['required']) ? '' : 'checked="checked"';
503 $required = <<<EOT
504 <p><label for="widget-{$istance_data['istance_id']}-required">{$testi_eot['required']}:</label> <input type="checkbox" value="1" {$required_checked} name="form-field-{$istance_data['istance_id']}-required" id="widget-{$istance_data['istance_id']}-required"></p>
505 EOT;
506
507 switch ($field_data['type']) {
508 case 'textarea':
509 $content .= <<<EOT
510 <p><label for="widget-{$istance_data['istance_id']}-default-value">{$testi_eot['default_value']}:</label>
511 {$override_begin}<input type="{$override_type}" name="form-field-{$istance_data['istance_id']}-override-default-value" value="1" {$override_default_value} />{$override_end}<br>
512 <textarea rows="6" cols="50" name="form-field-{$istance_data['istance_id']}-default-value" id="widget-{$istance_data['istance_id']}-default-value" class="widefat">{$istance_data['default_value']}</textarea></p>
513 $required
514 EOT;
515 break;
516 case 'hidden':
517 $content = $default_value;
518 break;
519 case 'checkbox':
520 $content .= $default_value . $required;
521 break;
522 case 'select':
523 case 'radio':
524 case 'post-select':
525 $content .= $default_value . $allowed_values . $required;
526 break;
527 case 'multiselect':
528 case 'multicheckbox':
529 case 'post-multicheckbox':
530 $content .= $default_values . $allowed_values . $required;
531 break;
532 case 'file':
533 $content .= $allowed_ext . $required;
534 case 'submit':
535 case 'fieldset-begin':
536 //just the label
537 break;
538 case 'fieldset-end':
539 //Nothing!
540 $content = '';
541 break;
542 case 'html':
543 $content = <<<EOT
544 <p><label for="widget-{$istance_data['istance_id']}-default-value">{$testi_eot['custom_HTML_content']}</label>
545 {$override_begin}<input type="{$override_type}" name="form-field-{$istance_data['istance_id']}-override-default-value" value="1" {$override_default_value} />{$override_end}<br>
546 <textarea rows="6" cols="50" name="form-field-{$istance_data['istance_id']}-default-value" id="widget-{$istance_data['istance_id']}-default-value" class="widefat">{$istance_data['default_value']}</textarea></p>
547 EOT;
548 break;
549 case 'email':
550 case 'autoreply_email':
551 case 'textfield':
552 case 'colorpicker':
553 case 'datepicker':
554 case 'dateselect':
555 default:
556 $content .= $default_value . $required;
557 break;
558 }
559 $adminurl = admin_url();
560
561 return <<<EOT
562 <div class="widget ui-draggable" id="widget-{$i}_{$istance_data['istance_id']}" $hidden> <div class="widget-top">
563 <div class="widget-title-action">
564 <a href="#available-widgets" class="widget-action hide-if-no-js"></a>
565 </div>
566 <div class="widget-title"><h4>{$field_data['name']}<span class="in-widget-title"></span></h4></div>
567 </div>
568
569 <div class="widget-inside">
570 <form method="post" action="">
571 <div class="widget-content">
572 $content
573 </div>
574 <input type="hidden" value="{$fid}" name="form-id">
575 <input type="hidden" value="{$istance_data['istance_id']}" class="widget-id" name="widget-id">
576 <input type="hidden" value="{$field_data['id']}" class="id_base" name="id_base">
577 <input type="hidden" value="250" class="widget-width" name="widget-width">
578 <input type="hidden" value="200" class="widget-height" name="widget-height">
579 <input type="hidden" value="{$istance_data['widget_number']}" class="widget_number" name="widget_number">
580 <input type="hidden" value="{$multi_number}" class="multi_number" name="multi_number">
581 <input type="hidden" value="{$add_new}" class="add_new" name="add_new">
582
583 <div class="widget-control-actions">
584 <div class="alignleft">
585 <a href="#remove" class="widget-control-remove">{$testi_eot['remove']}</a> |
586 <a href="#close" class="widget-control-close">{$testi_eot['close']}</a>
587 </div>
588 <div class="alignright">
589 <img alt="" title="" class="ajax-feedback" src="{$adminurl}images/wpspin_light.gif">
590 <input type="submit" value="{$testi_eot['save']}" class="button-primary widget-control-save" id="widget-{$istance_data['istance_id']}-savewidget" name="savewidget">
591 </div>
592 <br class="clear">
593 </div>
594 </form>
595 </div>
596
597 <!--<div class="widget-description">
598 {$field_data['description']}
599 </div>-->
600 </div>
601
602 EOT;
603 }
604
605 function accua_forms_add_page($message='') {
606 $forms_data = get_option('accua_forms_saved_forms', array());
607 $trash_data = get_option('accua_forms_trash_forms', array());
608 if (!empty($_GET['fid'])) {
609 $fid = htmlspecialchars(stripslashes($_GET['fid']), ENT_QUOTES);
610 } else {
611 if ($message === '') {
612 $fid = 1 + ((int) get_option('accua_forms_lastid', 0));
613 while (isset($forms_data[$fid]) || isset($trash_data[$fid])) {
614 $fid++;
615 }
616 update_option('accua_forms_lastid', $fid);
617 $message = _accua_forms_test_clonefrom($fid);
618 if ($message === '') {
619 return accua_forms_edit_page($fid);
620 }
621 } else {
622 $fid = '';
623 }
624 }
625 if (!empty($_GET['clonefrom'])) {
626 $clonefrom = stripslashes($_GET['clonefrom']);
627 } else {
628 $clonefrom = '';
629 }
630 ?>
631
632 <div id="accua_forms_add_page" class="accua_forms_admin_page wrap">
633 <h2><?php _e( 'Create a form', 'accua-form-api'); ?> </h2>
634 <?php if ($message !== '') {
635 echo "<div style='border:1px solid; padding: 10px;'>$message</div>";
636 } ?>
637 <form action="admin.php" method="GET">
638 <input type="hidden" name="page" value="accua_forms" />
639 <p>Form id: <input type="text" name="fid" value="<?php echo $fid; ?>" /></p>
640 <?php
641 if ($forms_data) {
642 echo '<p><select name="clonefrom">
643 <option value="">'.__( 'Empty form', 'accua-form-api').'</option>
644 <optgroup label="'.__( 'Clone form:', 'accua-form-api').'">';
645 foreach ($forms_data as $i => $formdata) {
646 $sel = ($i == $clonefrom) ? " selected='selected'" : '';
647 $i = htmlspecialchars($i, ENT_QUOTES);
648 if (isset($formdata['title']) && ('' !== trim($formdata['title']))) {
649 $formtitle = htmlspecialchars($formdata['title']);
650 } else {
651 $formtitle = $i;
652 }
653 echo "<option value='$i'$sel>$formtitle</option>\n";
654 }
655 echo '</optgroup></select></p>';
656 }
657 ?>
658 <p><input type="submit" value="<?php _e( 'Create', 'accua-form-api'); ?>" /></p>
659 </form>
660 </div>
661 <?php
662 }
663
664 function _accua_forms_test_clonefrom($fid){
665 $error = '';
666 if (isset($_GET['clonefrom'])&&$_GET['clonefrom']!=='') {
667 $clonefrom = stripslashes($_GET['clonefrom']);
668 $forms_data = get_option('accua_forms_saved_forms', array());
669 if (isset($forms_data[$fid])){
670 $error .= "<p>".__( 'Form already exists', 'accua-form-api')."</p>";
671 } else if (empty($forms_data[$clonefrom])) {
672 $error .= "<p>".__( 'Source form doesn\'t exists.', 'accua-form-api')."</p>";
673 } else {
674 $forms_data[$fid] = $forms_data[$clonefrom];
675 if (!isset($forms_data[$fid]['title'])) {
676 $forms_data[$fid]['title'] = $clonefrom ." ".__( 'clone', 'accua-form-api');
677 } else {
678 $forms_data[$fid]['title'] .= " ". __( 'clone', 'accua-form-api');
679 }
680 update_option('accua_forms_saved_forms', $forms_data);
681 }
682 }
683 return $error;
684 }
685
686 function _accua_forms_form_edit_action() {
687 static $message = null;
688 if ($message === null) {
689 $message = '';
690 if (isset($_POST['accua-form-edit-action'])){
691 $post = stripslashes_deep($_POST);
692 switch ($post['accua-form-edit-action']) {
693 case 'delete':
694 $fid = $post['form-id'];
695 $forms_data = get_option('accua_forms_saved_forms', array());
696 unset($forms_data[$fid]);
697 update_option('accua_forms_saved_forms', $forms_data);
698 $fid = htmlspecialchars($fid);
699 $message .= sprintf( __( 'Form \"%s\" deleted','accua-form-api' ), $fid );
700 break;
701 }
702 }
703 }
704 return $message;
705 }
706
707 function accua_forms_list_page() {
708 $message = '';
709 if (isset($_POST['accua-form-edit-action'])){
710 $message = _accua_forms_form_edit_action();
711 } else if (isset($_GET['fid'])) {
712 if (!isset($fid)) {
713 $fid = stripslashes($_GET['fid']);
714 }
715 $error = '';
716 if (!preg_match('/^[a-z0-9_-]+$/i', $fid)) {
717 $error .= "<p>".__( 'Only letters, numbers, hyphen and underscores allowed in form identificative name', 'accua-form-api')."</p>";
718 }
719 if (substr($fid,0,2) == '__') {
720 $error .= "<p>".__( 'The identificative name can\'t start with two underscores (__)', 'accua-form-api')."</p>";
721 }
722 if (strlen($fid) > 70) {
723 $error .= "<p>".__( 'You cannot use more than 70 characters for the identificative name', 'accua-form-api')."</p>";
724 }
725 if ($error === '' && (isset($_GET['clonefrom'])&&$_GET['clonefrom']!=='')) {
726 $error .= _accua_forms_test_clonefrom($fid);
727 }
728 if ($error === '') {
729 return accua_forms_edit_page($fid);
730 } else {
731 return accua_forms_add_page($error);
732 }
733 }
734 ?>
735 <div id="accua_forms_list_page" class="accua_forms_admin_page wrap">
736 <?php if ($message !== '') {
737 echo "<div style='border:1px solid; padding: 10px;'>$message</div>";
738 } ?>
739 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
740 <h2><?php _e( 'Contact Forms by Cimatti', 'accua-form-api'); ?>
741 <a class="add-new-h2" href="<?php echo get_admin_url(); ?>admin.php?page=accua_forms_add"><?php _e('Add New','accua-form-api'); ?></a>
742 </h2>
743 <div ><?php
744 echo strtr(__( 'Use the orange %img_c button in the TinyMCE editor to include the forms in posts, pages or other content types (shortcode and php functions also available)', 'accua-form-api'),
745 array('%img_c'=>'<img alt="C" src="' . plugins_url('img/cimatti-16-icon.png', __FILE__ ) . '" />')
746 );
747 ?></div>
748 <?php
749 accua_forms_list_page_table();
750 ?>
751 </div>
752 <?php
753 }
754
755 function accua_forms_edit_page($fid) {
756 wp_enqueue_script('jquery-ui-tabs','','','',true);
757 wp_enqueue_script('accua_tabs', plugins_url('accua_tabs.js', __FILE__ ), array( 'jquery' ), '1');
758
759 /*
760 $avail_fields = array(
761 'first_name' => array (
762 'id' => "first_name",
763 'name' => "First Name",
764 'type' => "textfield",
765 'description' => 'This is the first name',
766 ),
767 'last_name' => array (
768 'id' => "last_name",
769 'name' => "Last Name",
770 'type' => "textfield",
771 'description' => 'This is the last name',
772 ),
773 'email' => array (
774 'id' => "email",
775 'name' => "Email",
776 'type' => "email",
777 'description' => 'This is the email',
778 ),
779 );
780 */
781
782 $avail_fields = get_option('accua_forms_avail_fields', array());
783 $default_form_data = get_option('accua_forms_default_form_data',array());
784
785
786
787 $form_data = _accua_forms_get_form_data($fid, true, !empty($_GET['restore']));
788 $form_overrided_data = $form_data['_overrided'];
789
790 $fid_esc = htmlspecialchars($fid, ENT_QUOTES);
791
792 $adminurl = admin_url();
793
794 global $wp_version;
795 if (version_compare($wp_version, '4') >= 0) {
796 ?>
797 <style>
798 #widgets-right .accua-form-widget-scroll-wrapper .widget.ui-draggable {
799 height: auto !important;
800 }
801 </style>
802 <?php
803 }
804
805 ?>
806 <div id="accua_forms_edit_page" class="accua_forms_admin_page wrap">
807 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
808 <h2><?php _e( 'Edit Form', 'accua-form-api'); ?></h2>
809 <div id="titlediv"><br />
810 <label id="title-prompt-text" class="screen-reader-text" for="title"><?php _e( 'Enter title here', 'accua-form-api'); ?></label>
811 <input id="title" type="text" autocomplete="off" value="<?php echo htmlspecialchars($form_data['title'], ENT_QUOTES) ?>" size="30" name="post_title">
812
813 <script type="text/javascript">
814 jQuery(function($){
815 if ( jQuery('#titlediv #title').val() == '' )
816 jQuery('#title-prompt-text').removeClass('screen-reader-text');
817
818 jQuery('#titlediv #title').focus(function() {
819 jQuery('#title-prompt-text').addClass('screen-reader-text');
820 });
821 jQuery('#titlediv #title').blur(function() {
822 if ( jQuery('#titlediv #title').val() == '' )
823 jQuery('#title-prompt-text').removeClass('screen-reader-text');
824 });
825 });
826 </script>
827 </div>
828
829 <div id="accua_tabs">
830 <div id="save_settings_top" class="accua_forms_save_settings_top">
831 <form id="delete_form" action="admin.php?page=accua_forms_list" method="POST" onsubmit="return confirm(<?php echo htmlspecialchars(json_encode(__('Do you really want to delete this form?', 'accua-form-api'), JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP), ENT_QUOTES); ?>);">
832 <input type="hidden" name="accua-form-edit-action" value="delete" />
833 <input type="hidden" name="form-id" value="<?php echo $fid_esc; ?>" />
834 <input type="submit" value="<?php _e( 'Delete this form', 'accua-form-api'); ?>" />
835 </form>
836 <input class="button button-primary button-large accua_form_save_settings_button" id="accua_form_save_settings" type="button" value="<?php echo htmlspecialchars(__( 'Save settings', 'accua-form-api'), ENT_QUOTES); ?>" />
837 <span class="accua_form_save_settings_status"></span>
838 </div>
839 <ul id="ul_accua_tabs">
840 <li class="tabs"><a href="#accua_tab_fields"><?php _e( 'Fields', 'accua-form-api'); ?></a></li>
841 <li class="tabs"><a href="#accua_tab_messages"><?php _e( 'Messages', 'accua-form-api'); ?></a></li>
842 <li class="tabs"><a href="#accua_tab_preview"><?php _e( 'Preview/Test', 'accua-form-api'); ?></a></li>
843 </ul>
844 <div id="accua_tab_fields" class="content_tab">
845 <div style="width:69%; float:right;" class="container">
846 <!--
847 <h3>Form Fields</h3>
848 <div id="form_fields_container">
849 </div>
850 -->
851
852 <div class="widget-liquid-right" style="width:100%">
853 <div id="widgets-right" style="width:100%">
854 <div class="widgets-holder-wrap">
855 <div class="sidebar-name">
856 <div class="sidebar-name-arrow"><br></div>
857 <h3><?php _e( 'Form fields', 'accua-form-api'); ?> <span><img alt="" title="" class="ajax-feedback" src="<?php echo $adminurl;?>images/wpspin_light.gif"></span></h3>
858 </div>
859 <div class="widgets-sortables ui-sortable" id="cimatti-accua-fields-form-area-<?php echo $fid_esc ?>">
860 <div class="sidebar-description" style="width: 95%">
861 <p class="description"><?php _e( 'Drop fields here', 'accua-form-api'); ?></p>
862 </div>
863 <?php
864 foreach ($form_data['fields'] as $field) {
865 if (empty($avail_fields[$field['ref']])) {
866 $ref = array();
867 if (!empty($field['ref'])) {
868 if ($field['ref'] == '__fieldset-begin') {
869 $ref = array(
870 'id' => '__fieldset-begin',
871 'name' => __('Fieldset begin', 'accua-form-api'),
872 'type' => 'fieldset-begin',
873 'description' => '',
874 );
875 } else if ($field['ref'] == '__fieldset-end') {
876 $ref = array(
877 'id' => '__fieldset-end',
878 'name' => __('Fieldset end', 'accua-form-api'),
879 'type' => 'fieldset-end',
880 'description' => '',
881 );
882 }
883 }
884 } else {
885 $ref = $avail_fields[$field['ref']];
886 }
887 echo accua_forms_field_text_settings_form($fid, $ref, $field);
888 }
889 ?>
890 </div>
891 </div>
892 </div>
893 </div>
894
895 </div>
896
897 <div style="width:30%; float:left;">
898 <!--
899 <h3>Available fields</h3>
900 <div id="available_fields_container" class="container">
901 </div>
902 -->
903 <!-- Begin available fields -->
904
905 <div class="widget-liquid-left" style="margin-right:0">
906 <!-- <div id="widgets-left"> -->
907 <div id="widgets-left" style="margin-right:5px;">
908 <div id="available-widgets" class="widgets-holder-wrap">
909 <div class="sidebar-name">
910 <div class="sidebar-name-arrow"><br /></div>
911 <h3><?php _e( 'Available fields', 'accua-form-api'); ?> <span id="removing-widget"><?php _ex('Deactivate', 'removing-widget'); ?> <span></span></span></h3></div>
912 <div class="widget-holder">
913 <p class="description"><?php _e( 'Drag fields from here to a sidebar on the right to activate them. Drag fields back here to deactivate them.', 'accua-form-api'); ?><br/><br/>
914 <a href="admin.php?page=accua_forms_fields"><strong><?php _e( 'Create new fields here', 'accua-form-api'); ?></strong></a></p>
915
916 <div id="widget-list">
917 <!-- begin fields list -->
918
919 <?php
920 foreach ($avail_fields as $avail_field) {
921 $hidden = (empty($form_data['fields'][$avail_field['id']])) ? false : 'hidden';
922 echo accua_forms_field_text_settings_form($fid, $avail_field, $hidden);
923 }
924 //Custom HTML field
925 echo accua_forms_field_text_settings_form($fid);
926 //Fieldset begin
927 echo accua_forms_field_text_settings_form($fid, array(
928 'id' => '__fieldset-begin',
929 'name' => __( 'Fieldset begin', 'accua-form-api'),
930 'type' => 'fieldset-begin',
931 'description' => __('You can use this field multiple times.', 'accua-form-api'),
932 'default_value' => '',
933 'allowed_values' => '',
934 ));
935 //Fieldset end
936 echo accua_forms_field_text_settings_form($fid, array(
937 'id' => '__fieldset-end',
938 'name' => __( 'Fieldset end', 'accua-form-api'),
939 'type' => 'fieldset-end',
940 'description' => __('You can use this field multiple times.', 'accua-form-api'),
941 'default_value' => '',
942 'allowed_values' => '',
943 ));
944 ?>
945
946 <!-- end fields list -->
947 </div>
948
949 <br class='clear' />
950 </div>
951 <br class="clear" />
952 </div>
953
954 </div>
955 </div>
956 <!-- End available fields -->
957 </div>
958
959
960 <div style="clear:both;">&nbsp;</div>
961
962 <?php /* * / ?>
963 <pre>
964 accua_forms_form_fields_order_post: <?php echo htmlspecialchars(print_r(get_option('accua_forms_form_fields_order_post'), true)); ?>
965
966 accua_forms_save_form_field_post: <?php echo htmlspecialchars(print_r(get_option('accua_forms_save_form_field_post'), true)); ?>
967
968 accua_forms_saved_form_data: <?php echo htmlspecialchars(print_r($form_data, true)); ?>
969
970 </pre>
971 <?php /* */ ?>
972 </div>
973 <div id="accua_tab_messages" class="content_tab">
974 <?php
975 $settings_editor = array(
976 'teeny' => true,
977 'editor_class' => 'accua_form_value',
978 'tinymce' => array(
979 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,'));
980 ?>
981
982 <div class="metabox-holder accua-forms-metabox-holder">
983 <div class="postbox ">
984 <h3 class="hndle"><span><?php _e('1. On-screen success message', 'accua-form-api'); ?></span></h3>
985 <div class="inside" id="dashboard_right_now">
986 <div id="accua_form_success_message">
987 <input class="accua_form_check_override" name="accua_form_success_message" type="radio" value="0" <?php if (!isset($form_overrided_data['success_message'])) {echo ' checked ';} ?>> <?php _e( 'Use the default message', 'accua-form-api'); ?>
988 <input class="accua_form_check_override" name="accua_form_success_message" type="radio" value="1" <?php if (isset($form_overrided_data['success_message']) && !isset($form_overrided_data['success_message_no_message'])) {echo ' checked ';} ?>/> <?php _e( 'Customize', 'accua-form-api'); ?>
989 <input class="accua_form_check_override" name="accua_form_success_message" type="radio" value="-1" <?php if (isset($form_overrided_data['success_message_no_message'])) {echo ' checked ';} ?>/> <?php _e( 'Don\'t show any messages', 'accua-form-api'); ?><br />
990 <div class="defalut_message">
991 <?php _e( 'Default Success message', 'accua-form-api'); ?>
992 <div class="defalut_content_message"><?php echo wpautop($default_form_data['success_message']); ?></div>
993 </div>
994 <?php wp_editor( $form_data['success_message'] , 'accua_form_success_message_textarea' , $settings_editor); ?>
995 <!-- <textarea class="accua_form_value" style="width:95%"; cols="80" rows="8"><?php echo htmlspecialchars($form_data['success_message'], ENT_QUOTES) ?></textarea> -->
996 </div>
997 </div>
998 </div>
999 </div>
1000
1001 <div class="metabox-holder accua-forms-metabox-holder">
1002 <div class="postbox ">
1003 <h3 class="hndle"><span><?php _e('2. On-screen error message', 'accua-form-api'); ?></span></h3>
1004 <div class="inside" id="dashboard_right_now">
1005 <div id="accua_form_error_message">
1006 <input class="accua_form_check_override" name="accua_form_error_message" type="radio" value="0" <?php if (!isset($form_overrided_data['error_message'])) {echo ' checked ';} ?>> <?php _e( 'Use the default message', 'accua-form-api'); ?>
1007 <input class="accua_form_check_override" name="accua_form_error_message" type="radio" value="1" <?php if (isset($form_overrided_data['error_message']) && !isset($form_overrided_data['error_message_no_message'])) {echo ' checked ';} ?>/> <?php _e( 'Customize', 'accua-form-api'); ?>
1008 <input class="accua_form_check_override" name="accua_form_error_message" type="radio" value="-1" <?php if (isset($form_overrided_data['error_message_no_message'])) {echo ' checked ';} ?>/> <?php _e( 'Don\'t show any messages', 'accua-form-api'); ?><br />
1009 <div class="defalut_message">
1010 <?php _e( 'Default error message', 'accua-form-api'); ?> <br />
1011 <div class="defalut_content_message" ><?php echo wpautop($default_form_data['error_message']); ?></div>
1012 </div>
1013 <?php wp_editor( $form_data['error_message'] , 'accua_form_error_message_textarea' , $settings_editor); ?>
1014 </div>
1015 </div>
1016 </div>
1017 </div>
1018 <br clear="all"/>
1019 <div class="metabox-holder accua-forms-metabox-holder">
1020 <div class="postbox ">
1021 <h3 class="hndle"><span><?php _e('3. Email to notify administrator', 'accua-form-api'); ?></span></h3>
1022 <div class="inside" id="dashboard_right_now">
1023 <div id="accua_form_admin_emails_to" class="label_input">
1024 <label><?php _e( 'To', 'accua-form-api'); ?></label>
1025 <div class="default_value"><?php echo htmlspecialchars($default_form_data['admin_emails_to']); ?></div>
1026 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_to'], ENT_QUOTES) ?>" />
1027 <input name="accua_form_admin_emails_to" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['admin_emails_to'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1028 </div>
1029 <div id="accua_form_emails_bcc" class="label_input">
1030 <label><?php _e( 'Bcc', 'accua-form-api'); ?></label>
1031 <div class="default_value"><?php echo htmlspecialchars($default_form_data['emails_bcc']); ?></div>
1032 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_bcc'], ENT_QUOTES) ?>" />
1033 <input name ="accua_form_emails_bcc" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['emails_bcc'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1034 </div>
1035
1036 <div id="accua_form_admin_emails_subject" class="label_input">
1037 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
1038 <div class="default_value"><?php echo htmlspecialchars($default_form_data['admin_emails_subject']); ?></div>
1039 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_subject'], ENT_QUOTES) ?>" />
1040 <input name="accua_form_admin_emails_subject" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['admin_emails_subject'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1041 </div>
1042
1043 <div id="accua_form_admin_emails_message">
1044 <input class="accua_form_check_override" name="accua_form_admin_emails_message" type="radio" value="0" <?php if (!isset($form_overrided_data['admin_emails_message'])) {echo ' checked ';} ?>> <?php _e( 'Use the default message', 'accua-form-api'); ?>
1045 <input class="accua_form_check_override" name="accua_form_admin_emails_message" type="radio" value="1" <?php if (isset($form_overrided_data['admin_emails_message']) && !isset($form_overrided_data['admin_emails_message_no_message'])) {echo ' checked ';} ?>/> <?php _e( 'Customize', 'accua-form-api'); ?>
1046 <input class="accua_form_check_override" name="accua_form_admin_emails_message" type="radio" value="-1" <?php if (isset($form_overrided_data['admin_emails_message_no_message'])) {echo ' checked ';} ?>/> <?php _e( 'Don\'t show any messages', 'accua-form-api'); ?><br />
1047 <div class="defalut_message">
1048 <?php _e( 'Default message', 'accua-form-api'); ?>
1049 <div class="defalut_content_message"><?php echo wpautop($default_form_data['admin_emails_message']); ?></div>
1050 </div>
1051 <?php wp_editor( $form_data['admin_emails_message'] , 'accua_form_admin_emails_message_textarea' , $settings_editor); ?>
1052 </div>
1053
1054 </div>
1055 </div>
1056 </div>
1057
1058 <div class="metabox-holder accua-forms-metabox-holder">
1059 <div class="postbox ">
1060 <h3 class="hndle"><span><?php _e('4. Email confirmation to the person who completed the form', 'accua-form-api'); ?></span></h3>
1061 <div class="inside" id="dashboard_right_now">
1062 <div id="accua_form_emails_from_name" class="label_input">
1063 <label><?php _e( 'From name', 'accua-form-api'); ?></label>
1064 <div class="default_value"><?php echo htmlspecialchars($default_form_data['emails_from_name']); ?></div>
1065 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_from_name'], ENT_QUOTES) ?>" />
1066 <input name="accua_form_emails_from_name" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['emails_from_name'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1067 </div>
1068 <div id="accua_form_emails_from" class="label_input">
1069 <label><?php _e( 'From email', 'accua-form-api'); ?></label>
1070 <div class="default_value"><?php echo htmlspecialchars($default_form_data['emails_from']); ?></div>
1071 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_from'], ENT_QUOTES) ?>" />
1072 <input name="accua_form_emails_from" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['emails_from'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1073 </div>
1074 <div id="accua_form_confirmation_emails_subject" class="label_input">
1075 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
1076 <div class="default_value"><?php echo htmlspecialchars($default_form_data['confirmation_emails_subject']); ?></div>
1077 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['confirmation_emails_subject'], ENT_QUOTES) ?>" />
1078 <input name="accua_form_confirmation_emails_subject" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['confirmation_emails_subject'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1079 </div>
1080
1081 <div id="accua_form_confirmation_emails_message">
1082 <input class="accua_form_check_override" name="accua_form_confirmation_emails_message" type="radio" value="0" <?php if (!isset($form_overrided_data['confirmation_emails_message'])) {echo ' checked ';} ?>> <?php _e( 'Use the default message', 'accua-form-api'); ?>
1083 <input class="accua_form_check_override" name="accua_form_confirmation_emails_message" type="radio" value="1" <?php if (isset($form_overrided_data['confirmation_emails_message']) && !isset($form_overrided_data['confirmation_emails_message_no_message'])) {echo ' checked ';} ?>/> <?php _e( 'Customize', 'accua-form-api'); ?>
1084 <input class="accua_form_check_override" name="accua_form_confirmation_emails_message" type="radio" value="-1" <?php if (isset($form_overrided_data['confirmation_emails_message_no_message'])) {echo ' checked ';} ?>/> <?php _e( 'Don\'t show any messages', 'accua-form-api'); ?><br />
1085 <div class="defalut_message">
1086 <?php _e( 'Default message', 'accua-form-api'); ?>
1087 <div class="defalut_content_message"><?php echo wpautop($default_form_data['confirmation_emails_message']); ?></div>
1088 </div>
1089 <?php wp_editor( $form_data['confirmation_emails_message'] , 'accua_form_confirmation_emails_message_textarea' , $settings_editor); ?>
1090 </div>
1091 </div>
1092 </div>
1093 </div>
1094 <br clear="all"/>
1095
1096 <?php accua_forms_print_tokens(); ?>
1097
1098 <input type="hidden" id="accua_form_save_settings_id" value="<?php echo $fid_esc; ?>" />
1099 </div>
1100
1101 <div id="accua_tab_preview" class="content_tab">
1102
1103 <p style="clear:both;"><?php _e( 'Preview is updated when you click on "Save settings" button', 'accua-form-api'); ?></p>
1104 <div id="accua_form_preview_area_wrapper">
1105 <iframe id="accua_form_preview_area" src="admin-ajax.php?action=accua_forms_preview&fid=<?php echo htmlspecialchars($fid,ENT_QUOTES);?>" ></iframe>
1106 </div>
1107
1108 <p id="accua_form_use_ajax"><input class="accua_form_value" type="checkbox" value="1" <?php if (!empty($form_data['use_ajax'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Use AJAX to avoid page reload when submitting form', 'accua-form-api'); ?></p>
1109
1110 <h4><?php _e( 'Forms', 'accua-form-api'); ?></h4>
1111
1112 <p id="accua_form_layout"><?php _e('Layout', 'accua-form-api'); ?> <select name="layout" class="accua_form_value">
1113 <option value="" <?php if (isset($form_overrided_data['layout'])) { echo 'selected="selected"'; } ?>>default (<?php if($default_form_data['layout']=='sidebyside') _e( 'Labels on the left of the fields', 'accua-form-api'); else _e( 'Labels on top of the fields', 'accua-form-api'); ?>)</option><option value="sidebyside" <?php if ((isset($form_overrided_data['layout'])) && ($form_data['layout'] == 'sidebyside')) { echo 'selected="selected"'; } ?>><?php _e( 'Labels on the left of the fields', 'accua-form-api'); ?></option><option value="toplabel" <?php if ((isset($form_overrided_data['layout'])) && ($form_data['layout'] == 'toplabel')) { echo 'selected="selected"'; } ?>><?php _e( 'Labels on top of the fields', 'accua-form-api'); ?></option></select>
1114 </p>
1115
1116 <div id="accua_form_style_margin" class="label_input">
1117 <label><?php _e( 'Margin', 'accua-form-api'); ?></label>
1118 <div class="default_value"><?php echo $default_form_data['style_margin']; ?></div>
1119 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_margin'], ENT_QUOTES) ?>" />
1120 <input name="accua_form_style_margin" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_margin'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1121 </div>
1122
1123 <div id="accua_form_style_border_color" class="label_input">
1124 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
1125 <div class="default_value"><?php echo $default_form_data['style_border_color']; ?></div>
1126 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_color'], ENT_QUOTES) ?>" />
1127 <input name="accua_form_style_border_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_border_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1128 </div>
1129
1130 <div id="accua_form_style_border_width" class="label_input">
1131 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
1132 <div class="default_value"><?php echo $default_form_data['style_border_width']; ?></div>
1133 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_width'], ENT_QUOTES) ?>" />
1134 <input name="accua_form_style_border_width" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_border_width'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1135 </div>
1136
1137 <div id="accua_form_style_border_radius" class="label_input">
1138 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
1139 <div class="default_value"><?php echo $default_form_data['style_border_radius']; ?></div>
1140 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_radius'], ENT_QUOTES) ?>" />
1141 <input name="accua_form_style_border_radius" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_border_radius'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1142 </div>
1143
1144 <div id="accua_form_style_background_color" class="label_input">
1145 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
1146 <div class="default_value"><?php echo $default_form_data['style_background_color']; ?></div>
1147 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_background_color'], ENT_QUOTES) ?>" />
1148 <input name="accua_form_style_background_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_background_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1149 </div>
1150
1151 <div id="accua_form_style_padding" class="label_input">
1152 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
1153 <div class="default_value"><?php echo $default_form_data['style_padding']; ?></div>
1154 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_padding'], ENT_QUOTES) ?>" />
1155 <input name="accua_form_style_padding" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_padding'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1156 </div>
1157
1158 <div id="accua_form_style_color" class="label_input">
1159 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
1160 <div class="default_value"><?php echo $default_form_data['style_color']; ?></div>
1161 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_color'], ENT_QUOTES) ?>" />
1162 <input name="accua_form_style_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1163 </div>
1164
1165 <div id="accua_form_style_font_size" class="label_input">
1166 <label><?php _e( 'Font size', 'accua-form-api'); ?></label>
1167 <div class="default_value"><?php echo $default_form_data['style_font_size']; ?></div>
1168 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_font_size'], ENT_QUOTES) ?>" />
1169 <input name="accua_form_style_font_size" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_font_size'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1170 </div>
1171
1172 <h4><?php _e( 'Fields', 'accua-form-api'); ?></h4>
1173
1174 <div id="accua_form_style_field_spacing" class="label_input">
1175 <label><?php _e( 'Spacing', 'accua-form-api'); ?></label>
1176 <div class="default_value"><?php echo $default_form_data['style_field_spacing']; ?></div>
1177 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_spacing'], ENT_QUOTES) ?>" />
1178 <input name="accua_form_style_field_spacing" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_field_spacing'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1179 </div>
1180
1181 <div id="accua_form_style_field_border_color" class="label_input">
1182 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
1183 <div class="default_value"><?php echo $default_form_data['style_field_border_color']; ?></div>
1184 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_color'], ENT_QUOTES) ?>" />
1185 <input name="accua_form_style_field_border_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_field_border_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1186 </div>
1187
1188 <div id="accua_form_style_field_border_width" class="label_input">
1189 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
1190 <div class="default_value"><?php echo $default_form_data['style_field_border_width']; ?></div>
1191 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_width'], ENT_QUOTES) ?>" />
1192 <input name="accua_form_style_field_border_width" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_field_border_width'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1193 </div>
1194
1195 <div id="accua_form_style_field_border_radius" class="label_input">
1196 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
1197 <div class="default_value"><?php echo $default_form_data['style_field_border_radius']; ?></div>
1198 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_radius'], ENT_QUOTES) ?>" />
1199 <input name="accua_form_style_field_border_radius" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_field_border_radius'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1200 </div>
1201
1202 <div id="accua_form_style_field_background_color" class="label_input">
1203 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
1204 <div class="default_value"><?php echo $default_form_data['style_field_background_color']; ?></div>
1205 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_background_color'], ENT_QUOTES) ?>" />
1206 <input name="accua_form_style_field_background_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_field_background_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1207 </div>
1208
1209 <div id="accua_form_style_field_padding" class="label_input">
1210 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
1211 <div class="default_value"><?php echo $default_form_data['style_field_padding']; ?></div>
1212 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_padding'], ENT_QUOTES) ?>" />
1213 <input name="accua_form_style_field_padding" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_field_padding'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1214 </div>
1215
1216 <div id="accua_form_style_field_color" class="label_input">
1217 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
1218 <div class="default_value"><?php echo $default_form_data['style_field_color']; ?></div>
1219 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_color'], ENT_QUOTES) ?>" />
1220 <input name="accua_form_style_field_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_field_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1221 </div>
1222
1223
1224 <h4><?php _e( 'Submit button', 'accua-form-api'); ?></h4>
1225
1226 <div id="accua_form_style_submit_border_color" class="label_input">
1227 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
1228 <div class="default_value"><?php echo $default_form_data['style_submit_border_color']; ?></div>
1229 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_color'], ENT_QUOTES) ?>" />
1230 <input name="accua_form_style_submit_border_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_submit_border_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1231 </div>
1232
1233 <div id="accua_form_style_submit_border_width" class="label_input">
1234 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
1235 <div class="default_value"><?php echo $default_form_data['style_submit_border_width']; ?></div>
1236 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_width'], ENT_QUOTES) ?>" />
1237 <input name="accua_form_style_submit_border_width" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_submit_border_width'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1238 </div>
1239
1240 <div id="accua_form_style_submit_border_radius" class="label_input">
1241 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
1242 <div class="default_value"><?php echo $default_form_data['style_submit_border_radius']; ?></div>
1243 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_radius'], ENT_QUOTES) ?>" />
1244 <input name="accua_form_style_submit_border_radius" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_submit_border_radius'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1245 </div>
1246
1247 <div id="accua_form_style_submit_background_color" class="label_input">
1248 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
1249 <div class="default_value"><?php echo $default_form_data['style_submit_background_color']; ?></div>
1250 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_background_color'], ENT_QUOTES) ?>" />
1251 <input name="accua_form_style_submit_background_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_submit_background_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1252 </div>
1253
1254 <div id="accua_form_style_submit_padding" class="label_input">
1255 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
1256 <div class="default_value"><?php echo $default_form_data['style_submit_padding']; ?></div>
1257 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_padding'], ENT_QUOTES) ?>" />
1258 <input name="accua_form_style_submit_padding" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_submit_padding'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1259 </div>
1260
1261 <div id="accua_form_style_submit_color" class="label_input">
1262 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
1263 <div class="default_value"><?php echo $default_form_data['style_submit_color']; ?></div>
1264 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_color'], ENT_QUOTES) ?>" />
1265 <input name="accua_form_style_submit_color" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_submit_color'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1266 </div>
1267
1268 <div id="accua_form_style_submit_font_size" class="label_input">
1269 <label><?php _e( 'Font size', 'accua-form-api'); ?></label>
1270 <div class="default_value"><?php echo $default_form_data['style_submit_font_size']; ?></div>
1271 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_font_size'], ENT_QUOTES) ?>" />
1272 <input name="accua_form_style_submit_font_size" class="accua_form_check_override" type="checkbox" value="1" <?php if (isset($form_overrided_data['style_submit_font_size'])) {echo 'checked="checked" ';} ?>/><?php _e( 'Customize', 'accua-form-api'); ?>
1273 </div>
1274
1275 <br clear="all"/>
1276
1277 </div>
1278 <p></p>
1279 <input class="button button-primary button-large accua_form_save_settings_button" id="accua_form_save_settings_2" type="button" value="<?php _e( 'Save settings', 'accua-form-api'); ?>" /> <span class="accua_form_save_settings_status"></span>
1280
1281 </div>
1282 <script>
1283 jQuery('input[type=radio]').change(function() {
1284 var name = jQuery(this).attr('name');
1285 if (jQuery(this).val() == '1') {
1286 jQuery('#'+name+' .defalut_message').hide();
1287 jQuery('#'+name+' .wp-editor-wrap').show();
1288 }
1289 else {
1290 if(jQuery(this).val() != '-1')
1291 jQuery('#'+name+' .defalut_message').show();
1292 else
1293 jQuery('#'+name+' .defalut_message').hide();
1294 jQuery('#'+name+' .wp-editor-wrap').hide();
1295 }
1296 });
1297
1298 jQuery('input[type=checkbox]').click(function() {
1299 var name = jQuery(this).attr('name');
1300 if (!this.checked) {
1301 jQuery('#'+name+' .default_value').show();
1302 jQuery('#'+name+' .accua_form_value, #'+name+' .wp-picker-container').hide();
1303 }
1304 else {
1305 jQuery('#'+name+' .default_value').hide();
1306 jQuery('#'+name+' .accua_form_value, #'+name+' .wp-picker-container').show();
1307 }
1308 });
1309
1310 jQuery(".token_link").click(function() {
1311 jQuery("#dialog_token").dialog("open");
1312 return false;
1313 });
1314
1315 //inizializzazione
1316 jQuery(document).ready(function($){
1317 $('#accua_form_preview_area_wrapper').resizable({handles: 's'});
1318 $('#accua_form_preview_area').css({
1319 'width': '100%',
1320 'height': '100%'
1321 });
1322 $.each(
1323 ['success_message','error_message','admin_emails_message','confirmation_emails_message'],
1324 function(i,key){
1325 var value = $('#accua_form_'+key+' .accua_form_check_override:checked').val();
1326 if(value!=undefined && value!=0) {
1327 if(value!=-1)
1328 jQuery('#accua_form_'+key+' .wp-editor-wrap').show();
1329 else
1330 jQuery('#accua_form_'+key+' .wp-editor-wrap').hide();
1331 jQuery('#accua_form_'+key+' .defalut_message').hide();
1332
1333 }
1334 else {
1335 jQuery('#accua_form_'+key+' .wp-editor-wrap').hide();
1336 jQuery('#accua_form_'+key+' .defalut_message').show();
1337 }
1338 }
1339 );
1340 $.each(
1341 ['emails_from_name','emails_from','admin_emails_to','emails_bcc','admin_emails_subject','confirmation_emails_subject','style_margin','style_border_color','style_border_width','style_border_radius','style_background_color','style_padding','style_color','style_font_size','style_field_spacing','style_field_border_color','style_field_border_width','style_field_border_radius','style_field_background_color','style_field_padding','style_field_color','style_submit_border_color','style_submit_border_width','style_submit_border_radius','style_submit_background_color','style_submit_padding','style_submit_color','style_submit_font_size'],
1342 function(i,key){
1343 if(!$('#accua_form_'+key+' .accua_form_check_override').is(':checked')) {
1344 jQuery('#accua_form_'+key+' .default_value').show();
1345 jQuery('#accua_form_'+key+' .accua_form_value, #accua_form_'+key+' .wp-picker-container').hide();
1346 }
1347 else {
1348 jQuery('#accua_form_'+key+' .default_value').hide();
1349 jQuery('#accua_form_'+key+' .accua_form_value, #accua_form_'+key+' .wp-picker-container').show();
1350 }
1351 });
1352 $("#dialog_token").dialog({ dialogClass:'wp-dialog' ,autoOpen : false, modal : true, show : "blind", hide : "blind"});
1353
1354 $('#accua_token a').appendTo('.wp-media-buttons');
1355
1356 });
1357
1358 jQuery(document).ready(function($){
1359
1360 var originalWidth = $(document).width();
1361 if(originalWidth <= 883) { //iphone
1362 $(".metabox-holder").width('98%');
1363 }
1364
1365 $(window).resize(function (e) {
1366 var newWidth = $(document).width();
1367 if(newWidth <= 883) {
1368 if (originalWidth > 883) {
1369 $(".metabox-holder").width('98%');
1370 }
1371 } else if (originalWidth<=883) {
1372 $(".metabox-holder").width('47%');
1373 }
1374 originalWidth = newWidth;
1375 });
1376 });
1377
1378 </script>
1379
1380 <?php
1381 }
1382
1383 function accua_forms_fields_page_head() {
1384 /*
1385 $baseurl = WP_PLUGIN_URL.'/'.substr(plugin_basename(__FILE__),0,-strlen(basename(__FILE__)));
1386 ?>
1387 <script type="text/javascript" src="<?php echo $baseurl.'/qtip/jquery.qtip-1.0.0-rc3.js'; ?>"></script>
1388 <script type="text/javascript">
1389 var avail_fields = {
1390 first_name: {
1391 id: "first_name",
1392 name: "First Name",
1393 type: "textfield"
1394 },
1395 last_name: {
1396 id: "last_name",
1397 name: "Last Name",
1398 type: "textfield"
1399 },
1400 email: {
1401 id: "email",
1402 name: "Email",
1403 type: "email"
1404 }
1405 };
1406
1407 jQuery(function($){
1408 $avail = $('#available_fields_container');
1409 for(var id in avail_fields) {
1410 var field = avail_fields[id];
1411 var el = $('<div></div>').text(field.name);
1412 el.prepend('<input type="checkbox" />');
1413 var content = $('<div><span>Id: </span></div>');
1414 content.append($('<input type="text" />').val(field.id));
1415 content.append($('<br /><span>Name: </span>'));
1416 content.append($('<input type="text" />').val(field.name));
1417 content.append($('<br /><span>Type: </span>'));
1418 content.append($('<select><option value="textfield">Textfield</option><option value="textarea">Textarea</option><option value="email">Email</option></select>').val(field.type));
1419 el.qtip({
1420 content: {
1421 text: content
1422 },
1423 position: {
1424 target: 'mouse',
1425 corner: {
1426 target: 'bottomRight',
1427 tooltip: 'topLeft'
1428 },
1429 adjust: {
1430 mouse: false
1431 }
1432 },
1433 show: {
1434 when: {
1435 event: 'mouseover'
1436 },
1437 solo: true
1438 },
1439 hide: {
1440 when: {
1441 event: 'unfocus'
1442 }
1443 }
1444 });
1445 $avail.append(el);
1446 }
1447 });
1448 </script>
1449 <style type="text/css">
1450 .container > div {
1451 padding: 0px;
1452 margin-bottom: 6px;
1453 }
1454 </style>
1455 <?php
1456 */
1457 }
1458
1459 function accua_forms_fields_page() {
1460 /*
1461 ?>
1462 <div class="wrap"><h2>Edit Form Fields</h2>
1463 <div id="available_fields_container" class="container"></div>
1464 </div>
1465 <?php
1466 */
1467 $message = '';
1468
1469 /*
1470 $avail_fields = array(
1471 'first_name' => array (
1472 'id' => "first_name",
1473 'name' => "First Name",
1474 'type' => "textfield",
1475 'description' => 'This is the first name',
1476 ),
1477 'last_name' => array (
1478 'id' => "last_name",
1479 'name' => "Last Name",
1480 'type' => "textfield",
1481 'description' => 'This is the last name',
1482 ),
1483 'email' => array (
1484 'id' => "email",
1485 'name' => "Email",
1486 'type' => "email",
1487 'description' => 'This is the email',
1488 ),
1489 );
1490 */
1491
1492 $avail_fields = get_option('accua_forms_avail_fields', array());
1493
1494 $default_form_values = array(
1495 'id' => '',
1496 'name' => '',
1497 'type' => 'textfield',
1498 'description' => '',
1499 'default_value' => '',
1500 'allowed_values' => '',
1501 );
1502
1503 $editing = false;
1504 $adding = true;
1505
1506 if (!empty($_POST['action'])) {
1507 $post = stripslashes_deep($_POST);
1508 switch($post['action']) {
1509 case 'edit-form-field':
1510 if (empty($avail_fields[$post['form-field-id']])) {
1511 $message .= 'Field "'.htmlspecialchars($post['form-field-id']).'" doesn\'t exists';
1512 } else {
1513 if (empty($post['delete-field'])) {
1514 $avail_fields[$post['form-field-id']] = array(
1515 'id' => $post['form-field-id'],
1516 'name' => $post['form-field-name'],
1517 'type' => $post['form-field-type'],
1518 'description' => $post['form-field-description'],
1519 'default_value' => $post['form-field-default-value'],
1520 'allowed_values' => $post['form-field-allowed-values'],
1521 );
1522 $message .= sprintf( __( 'Field "%s" updated', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1523 do_action('accua_forms_field_updated', $avail_fields[$post['form-field-id']]);
1524 } else {
1525 $deleting_field = $avail_fields[$post['form-field-id']];
1526 unset ($avail_fields[$post['form-field-id']]);
1527 $message .= sprintf( __( 'Field "%s" deleted', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1528 do_action('accua_forms_field_deleted', $deleting_field);
1529 }
1530 update_option('accua_forms_avail_fields', $avail_fields);
1531 }
1532 break;
1533 case 'add-form-field':
1534 $fill_form_fields = true;
1535 $valid = true;
1536 if (empty($post['form-field-id']) || !preg_match('/^[a-z0-9_-]+$/i', $post['form-field-id'])) {
1537 $message .= "<p>".__( 'Only letters, numbers, hyphen and underscores allowed in field identificative slug', 'accua-form-api')."</p>";
1538 $valid = false;
1539 }
1540 if(substr($post['form-field-id'], 0, 2) == '__') {
1541 $message .= "<p>".__( 'The field identificative slug can\'t start with two underscores (__)', 'accua-form-api')."</p>";
1542 $valid = false;
1543 }
1544 if (!empty($avail_fields[$post['form-field-id']])) {
1545 $message .= sprintf( __( '<p>A field with identificative slug "%s" already exists</p> Field "%s" deleted', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1546 $valid = false;
1547 }
1548 if (strlen($post['form-field-id']) > 70) {
1549 $message .= "<p>".__( 'The identificative slug cannot be longer than 70 characters', 'accua-form-api')."</p>";
1550 $valid = false;
1551 }
1552 if ($valid) {
1553 $fill_form_fields = false;
1554 $avail_fields[$post['form-field-id']] = array(
1555 'id' => $post['form-field-id'],
1556 'name' => $post['form-field-name'],
1557 'type' => $post['form-field-type'],
1558 'description' => $post['form-field-description'],
1559 'default_value' => $post['form-field-default-value'],
1560 'allowed_values' => $post['form-field-allowed-values'],
1561 );
1562 update_option('accua_forms_avail_fields', $avail_fields);
1563 $message .= sprintf( __( 'Field "%s" created', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1564 do_action('accua_forms_field_added', $avail_fields[$post['form-field-id']]);
1565 }
1566 if ($fill_form_fields) {
1567 $editing = true;
1568 $default_form_values = array(
1569 'id' => $post['form-field-id'],
1570 'name' => $post['form-field-name'],
1571 'type' => $post['form-field-type'],
1572 'description' => $post['form-field-description'],
1573 'default_value' => $post['form-field-default-value'],
1574 'allowed_values' => $post['form-field-allowed-values'],
1575 );
1576 }
1577 break;
1578 }
1579 } else if (!empty($_GET['edit-fid'])) {
1580 $fid = stripslashes($_GET['edit-fid']);
1581 if (empty($avail_fields[$fid])) {
1582 $message .= sprintf( __( 'Field "%s" doesn\'t exists', 'accua-form-api'), $fid );
1583 } else {
1584 $adding = false;
1585 $editing = true;
1586 $default_form_values = $avail_fields[$fid];
1587 }
1588 }
1589
1590 ?>
1591 <div id="accua_forms_fields_page" class="accua_forms_admin_page wrap nosubsub">
1592 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
1593 <h2><?php _e( 'Form fields', 'accua-form-api'); ?></h2>
1594 <?php /* screen_icon(); ?>
1595 <h2><?php echo esc_html( $title );
1596 if ( !empty($_REQUEST['s']) )
1597 printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?>
1598 </h2>
1599
1600 <?php if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) ) : ?>
1601 <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
1602 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
1603 endif; */ ?>
1604 <div id="ajax-response"><?php echo $message?></div>
1605
1606 <?php /*
1607 <form class="search-form" action="" method="get">
1608 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1609 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1610
1611 <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
1612
1613 </form>
1614 */ ?>
1615
1616 <br class="clear" />
1617
1618 <div id="col-container">
1619
1620 <div id="col-right">
1621 <div class="col-wrap">
1622 <?php if (!$editing) { ?>
1623 <form id="posts-filter" action="" method="post">
1624 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1625 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1626
1627 <?php /* $wp_list_table->display(); */ ?>
1628
1629 <table cellspacing="0" class="wp-list-table widefat fixed tags">
1630 <thead>
1631 <tr>
1632 <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox" /></th>
1633 <th style="" class="manage-column column-name" id="name" scope="col"><?php _e( 'Label', 'accua-form-api'); ?></th>
1634 <th style="" class="manage-column column-description" id="description" scope="col"><?php _e( 'Description', 'accua-form-api'); ?></th>
1635 <th style="" class="manage-column column-slug" id="slug" scope="col"><?php _e( 'Slug', 'accua-form-api'); ?></th>
1636 <th style="" class="manage-column column-type" id="type" scope="col"><?php _e( 'Type', 'accua-form-api'); ?></th>
1637 </tr>
1638 </thead>
1639
1640 <tfoot>
1641 <tr>
1642 <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox" /></th>
1643 <th style="" class="manage-column column-name" scope="col"><?php _e( 'Label', 'accua-form-api'); ?></th>
1644 <th style="" class="manage-column column-description" scope="col"><?php _e( 'Description', 'accua-form-api'); ?></th>
1645 <th style="" class="manage-column column-slug" scope="col"><?php _e( 'Slug', 'accua-form-api'); ?></th>
1646 <th style="" class="manage-column column-type" scope="col"><?php _e( 'Type', 'accua-form-api'); ?></th>
1647 </tr>
1648 </tfoot>
1649
1650 <tbody class="list:tag" id="the-list">
1651 <?php
1652 foreach ($avail_fields as $id => $field) {
1653 foreach (array('id', 'name', 'type', 'description') as $i) {
1654 $field[$i] = htmlspecialchars($field[$i], ENT_QUOTES);
1655 }
1656 echo <<<END_OF_ROW
1657 <tr id="field-{$field['id']}">
1658 <th class="check-column" scope="row"><input type="checkbox" /></th>
1659 <td class="name column-name"><strong><a title="Edit “{$field['name']}”" href="admin.php?page=accua_forms_fields&amp;edit-fid={$field['id']}" class="row-title">{$field['name']}</a></strong><br><div class="row-actions"><span class="edit"><a href="admin.php?page=accua_forms_fields&amp;edit-fid={$field['id']}">Edit</a></span></div></td>
1660 <td class="description column-description">{$field['description']}</td>
1661 <td class="slug column-slug">{$field['id']}</td>
1662 <td class="type column-type">{$field['type']}</td>
1663 </tr>
1664 END_OF_ROW;
1665 }
1666 ?>
1667 </tbody>
1668 </table>
1669
1670 <br class="clear" />
1671 </form>
1672 <?php } ?>
1673 <?php /* if ( 'category' == $taxonomy ) : ?>
1674 <div class="form-wrap">
1675 <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_cat_name(get_option('default_category')))) ?></p>
1676 <?php if ( current_user_can( 'import' ) ) : ?>
1677 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
1678 <?php endif; ?>
1679 </div>
1680 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
1681 <div class="form-wrap">
1682 <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>'), 'import.php') ;?>.</p>
1683 </div>
1684 <?php endif;
1685 do_action('after-' . $taxonomy . '-table', $taxonomy);
1686 */ ?>
1687
1688 </div>
1689 </div><!-- /col-right -->
1690
1691 <div id="col-left">
1692 <div class="col-wrap">
1693
1694 <?php
1695 /*
1696 if ( !is_null( $tax->labels->popular_items ) ) {
1697 if ( current_user_can( $tax->cap->edit_terms ) )
1698 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
1699 else
1700 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
1701
1702 if ( $tag_cloud ) :
1703 ?>
1704 <div class="tagcloud">
1705 <h3><?php echo $tax->labels->popular_items; ?></h3>
1706 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
1707 </div>
1708 <?php
1709 endif;
1710 }
1711 */
1712
1713 /*
1714 if ( current_user_can($tax->cap->edit_terms) ) {
1715 // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form
1716 if ( 'category' == $taxonomy )
1717 do_action('add_category_form_pre', (object)array('parent' => 0) );
1718 elseif ( 'link_category' == $taxonomy )
1719 do_action('add_link_category_form_pre', (object)array('parent' => 0) );
1720 else
1721 do_action('add_tag_form_pre', $taxonomy);
1722
1723 do_action($taxonomy . '_pre_add_form', $taxonomy);
1724 */
1725
1726 $types = array(
1727 'textfield' => __( 'Text Field', 'accua-form-api'),
1728 'textarea' => __( 'Text Area', 'accua-form-api'),
1729 'email' => __( 'Email', 'accua-form-api'),
1730 'autoreply_email' => __( 'Autoreply Email', 'accua-form-api'),
1731 'checkbox' => __( 'Checkbox','accua-form-api'),
1732 'select' => __('Select', 'accua-form-api'),
1733 'radio' => __( 'Radio buttons', 'accua-form-api'),
1734 'multiselect' => __( 'Multiple selections area', 'accua-form-api'),
1735 'multicheckbox' => __( 'Multiple checkboxes', 'accua-form-api'),
1736 'post-select' => __( 'Post select', 'accua-form-api'),
1737 'post-multicheckbox' => __( 'Multiple post checkboxes', 'accua-form-api'),
1738 'colorpicker' => __( 'Color picker', 'accua-form-api'),
1739 'hidden' => __('Hidden value', 'accua-form-api'),
1740 'file' => __('File upload', 'accua-form-api'),
1741 'submit' => __( 'Submit button', 'accua-form-api'),
1742 'html' => __( 'Custom HTML', 'accua-form-api'),
1743 'captcha' => __( 'Captcha', 'accua-form-api'),
1744 'password' => 'Password',
1745 'password-and-confirm' => __( 'Password and password confirmation','accua-form-api'),
1746 );
1747
1748
1749 ?>
1750 <div class="form-wrap">
1751 <h3><?php echo $adding? __( 'Add new field','accua-form-api'): __( 'Edit field','accua-form-api') ; ?></h3>
1752 <form id="addtag" method="post" action="admin.php?page=accua_forms_fields" class="validate">
1753 <input type="hidden" name="action" value="<?php echo $adding?'add':'edit'; ?>-form-field" />
1754 <?php /*
1755 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
1756 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1757 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1758 */ ?>
1759 <?php wp_nonce_field('add-tag', '_wpnonce_add-form-field'); ?>
1760
1761 <div class="form-field form-required">
1762 <label for="tag-name"><?php _e( 'Field label', 'accua-form-api'); ?></label>
1763 <input name="form-field-name" id="tag-name" type="text" value="<?php echo htmlspecialchars($default_form_values['name'], ENT_QUOTES) ?>" size="40" aria-required="true" />
1764 <p><?php _e('The name is how it appears on your site.', 'accua-form-api'); ?></p>
1765 </div>
1766 <?php /* if ( ! global_terms_enabled() ) : */ ?>
1767 <div class="form-field">
1768 <label for="tag-slug"><?php _e( 'Field slug (identificative)', 'accua-form-api'); ?></label>
1769 <input name="form-field-id" id="tag-slug" type="text" value="<?php echo htmlspecialchars($default_form_values['id'], ENT_QUOTES) ?>" <?php if (!$adding) { echo 'disabled="disabled"'; } ?> size="40" />
1770 <?php if (!$adding) { echo '<input type="hidden" name="form-field-id" value="'.htmlspecialchars($default_form_values['id'], ENT_QUOTES).'" />'; } ?>
1771 <p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is used as an identificator, and is unchangeable. It is usually all lowercase and it must contains only letters, numbers, and underscores.', 'accua-form-api'); ?></p>
1772 </div>
1773 <div class="form-field">
1774 <label for="parent"><?php _e( 'Field type', 'accua-form-api'); ?></label>
1775 <select class="postform" id="parent" name="form-field-type">
1776 <?php /*
1777 <option value="textfield" class="level-0" <?php echo ($default_form_values['type'] == 'textfield')?'selected="selected"':'';?> >Text Field</option>
1778 <option value="textarea" class="level-0" <?php echo ($default_form_values['type'] == 'textarea')?'selected="selected"':'';?> >Text Area</option>
1779 <option value="email" class="level-0" <?php echo ($default_form_values['type'] == 'email')?'selected="selected"':'';?> >Email</option>
1780 <option value="checkbox" class="level-0" <?php echo ($default_form_values['type'] == 'checkbox')?'selected="selected"':'';?> >Checkbox</option>
1781 <option value="select" class="level-0" <?php echo ($default_form_values['type'] == 'select')?'selected="selected"':'';?> >Select</option>
1782 */
1783 foreach ($types as $typeid => $typename) {
1784 $selected = ($default_form_values['type'] == $typeid)?'selected="selected"':'';
1785 echo <<<EOT
1786 <option value="{$typeid}" class="level-0" {$selected} >{$typename}</option>
1787 EOT;
1788 }
1789
1790 ?>
1791 </select>
1792 </div>
1793 <?php /* endif; // global_terms_enabled() */ ?>
1794 <?php /* if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
1795 <div class="form-field">
1796 <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
1797 <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
1798 <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
1799 <p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
1800 <?php endif; ?>
1801 </div>
1802 <?php endif; // is_taxonomy_hierarchical() */ ?>
1803 <div class="form-field">
1804 <label for="tag-description"><?php _e( 'Field description', 'accua-form-api'); ?></label>
1805 <textarea name="form-field-description" id="tag-description" rows="5" cols="40"><?php echo htmlspecialchars($default_form_values['description'], ENT_QUOTES) ?></textarea>
1806 <p><?php _e('The description is not prominent by default; however, some themes may show it.', 'accua-form-api'); ?></p>
1807 </div>
1808
1809 <div class="form-field">
1810 <label for="form-field-default-value"><?php _e( 'Default value(s)', 'accua-form-api'); ?>:</label>
1811 <textarea name="form-field-default-value" id="form-field-default-value" rows="5" cols="40"><?php echo htmlspecialchars($default_form_values['default_value'], ENT_QUOTES) ?></textarea>
1812 <p><?php _e( 'For multiple default values in multiple select and multiple checkboxes, use | as separator.', 'accua-form-api'); ?></p>
1813 </div>
1814
1815 <div class="form-field">
1816 <label for="form-field-allowed-values"><?php _e( 'Allowed values', 'accua-form-api'); ?>:</label>
1817 <textarea rows="5" cols="40" name="form-field-allowed-values" id=form-field-allowed-values"><?php echo htmlspecialchars($default_form_values['allowed_values'], ENT_QUOTES) ?></textarea>
1818 <p><?php _e( 'Options used in select, radio and multiple checkboxes. Enter one value per line, in the format key|label. The key is the value that will be stored in the database. The label is optional, and the key will be used as the label if no label is specified. For file fields, this indicates allowed extensions (one per line without dot)', 'accua-form-api'); ?></p>
1819 </div>
1820
1821
1822 <?php
1823 /*
1824 if ( ! is_taxonomy_hierarchical($taxonomy) )
1825 do_action('add_tag_form_fields', $taxonomy);
1826 do_action($taxonomy . '_add_form_fields', $taxonomy);
1827 */
1828
1829 if ($adding) {
1830 submit_button( __( 'Add new field', 'accua-form-api'), 'button' );
1831 } else {
1832 submit_button( __( 'Save changes', 'accua-form-api'), 'button' );
1833 submit_button( __( 'Delete field', 'accua-form-api'), 'button', 'delete-field');
1834 }
1835
1836 /*
1837 // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form
1838 if ( 'category' == $taxonomy )
1839 do_action('edit_category_form', (object)array('parent' => 0) );
1840 elseif ( 'link_category' == $taxonomy )
1841 do_action('edit_link_category_form', (object)array('parent' => 0) );
1842 else
1843 do_action('add_tag_form', $taxonomy);
1844
1845 do_action($taxonomy . '_add_form', $taxonomy);
1846 */
1847 ?>
1848 </form></div>
1849 <?php /* } */ ?>
1850
1851 </div>
1852 </div><!-- /col-left -->
1853
1854 </div><!-- /col-container -->
1855 </div><!-- /wrap -->
1856 <?php
1857 /* echo '<pre>accua_forms_avail_fields:', htmlspecialchars(print_r($avail_fields, true)), '</pre>'; */
1858 }
1859
1860 function accua_forms_settings_page() {
1861 ?>
1862 <div id="accua_forms_settings_page" class="accua_forms_admin_page wrap">
1863 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
1864 <h2><?php _e( 'Default Form settings', 'accua-form-api'); ?></h2>
1865 <?php
1866 $empty_form_data = array(
1867 'success_message' => '',
1868 'error_message' => '',
1869 'emails_from_name' => '',
1870 'emails_from' => '',
1871 'admin_emails_to' => '',
1872 'emails_bcc' => '',
1873 'admin_emails_subject' => '',
1874 'admin_emails_message' => '',
1875 'confirmation_emails_subject' => '',
1876 'confirmation_emails_message' => '',
1877 'layout' => 'sidebyside',
1878 'style_margin' => '',
1879 'style_border_color' => '',
1880 'style_border_width' => '',
1881 'style_border_radius' => '',
1882 'style_background_color' => '',
1883 'style_padding' => '',
1884 'style_color' => '',
1885 'style_font_size' => '',
1886 'style_field_spacing' => '',
1887 'style_field_border_color' => '',
1888 'style_field_border_width' => '',
1889 'style_field_border_radius' => '',
1890 'style_field_background_color' => '',
1891 'style_field_padding' => '',
1892 'style_field_color' => '',
1893 'style_submit_border_color' => '',
1894 'style_submit_border_width' => '',
1895 'style_submit_border_radius' => '',
1896 'style_submit_background_color' => '',
1897 'style_submit_padding' => '',
1898 'style_submit_color' => '',
1899 'style_submit_font_size' => '',
1900 );
1901
1902 $empty_file_data = array(
1903 'valid_extensions' => '',
1904 'max_size' => '',
1905 'dest_path' => '',
1906 );
1907
1908 $empty_captcha_data = array(
1909 'recaptcha_force_v1' => '',
1910 'recaptcha_public_key' => '',
1911 'recaptcha_private_key' => '',
1912 );
1913
1914 if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['accua_form_save_form_settings'])) {
1915 $post = stripslashes_deep($_POST);
1916 $post += $empty_form_data;
1917 $post += $empty_file_data;
1918 $post += $empty_captcha_data;
1919 $form_data = array();
1920 $file_data = array();
1921 $captcha_data = array();
1922 foreach($empty_form_data as $key=>$val){
1923 $form_data[$key] = $post[$key];
1924 }
1925 foreach($empty_file_data as $key=>$val){
1926 $file_data[$key] = $post[$key];
1927 }
1928 foreach($empty_captcha_data as $key=>$val){
1929 $captcha_data[$key] = $post[$key];
1930 }
1931
1932 update_option('accua_forms_default_form_data', $form_data);
1933 update_option('accua_forms_default_file_field_data', $file_data);
1934 update_option('accua_forms_default_captcha_field_data', $captcha_data);
1935 } else {
1936 $form_data = get_option('accua_forms_default_form_data',array()) + $empty_form_data;
1937 $file_data = get_option('accua_forms_default_file_field_data',array()) + $empty_file_data;
1938 $captcha_data = get_option('accua_forms_default_captcha_field_data',array()) + $empty_captcha_data;
1939 }
1940 ?>
1941 <form method="post">
1942 <input type="hidden" name="accua_form_save_form_settings" value="1" />
1943 <?php /*
1944 <p id="accua_form_layout"><?php _e( 'Layout', 'accua-form-api'); ?>: <select name="layout" class="accua_form_value"><option value="sidebyside" <?php if ($form_data['layout'] == 'sidebyside') { echo 'selected="selected"'; } ?>>Labels on the left of the fields</option><option value="toplabel" <?php if ($form_data['layout'] == 'toplabel') { echo 'selected="selected"'; } ?>>Labels on top of the fields</option></select></p>
1945 <p id="accua_form_success_message"><?php _e( 'Success message', 'accua-form-api'); ?>:<br /><textarea name="success_message" class="accua_form_value" style="width:95%"; cols="80" rows="8"><?php echo htmlspecialchars($form_data['success_message'], ENT_QUOTES) ?></textarea></p>
1946 <p id="accua_form_error_message"><?php _e( 'Error message', 'accua-form-api'); ?>:<br /><textarea name="error_message" class="accua_form_value" style="width:95%"; cols="80" rows="8"><?php echo htmlspecialchars($form_data['error_message'], ENT_QUOTES) ?></textarea></p>
1947 <p id="accua_form_emails_from"><?php _e( 'Emails from', 'accua-form-api'); ?>: <input name="emails_from" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_from'], ENT_QUOTES) ?>" /></p>
1948 <p id="accua_form_admin_emails_to"><?php _e( 'Admin emails to', 'accua-form-api'); ?>: <input name="admin_emails_to" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_to'], ENT_QUOTES) ?>" /></p>
1949 <p id="accua_form_emails_bcc"><?php _e( 'Emails bcc', 'accua-form-api'); ?>: <input name="emails_bcc" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_bcc'], ENT_QUOTES) ?>" /></p>
1950 <p id="accua_form_admin_emails_subject"><?php _e( 'Admin email subject', 'accua-form-api'); ?>: <input name="admin_emails_subject" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_subject'], ENT_QUOTES) ?>" /></p>
1951 <p id="accua_form_admin_emails_message"><?php _e( 'Admin email message', 'accua-form-api'); ?>:<br /><textarea name="admin_emails_message" class="accua_form_value" style="width:95%"; cols="80" rows="8"><?php echo htmlspecialchars($form_data['admin_emails_message'], ENT_QUOTES) ?></textarea></p>
1952 <p id="accua_form_confirmation_emails_subject"><?php _e( 'Confirmation email subject', 'accua-form-api'); ?>: <input name="confirmation_emails_subject" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['confirmation_emails_subject'], ENT_QUOTES) ?>" /></p>
1953 <p id="accua_form_confirmation_emails_message"><?php _e( 'Confirmation email message', 'accua-form-api'); ?>:<br /><textarea name="confirmation_emails_message" class="accua_form_value" style="width:95%"; cols="80" rows="8"><?php echo htmlspecialchars($form_data['confirmation_emails_message'], ENT_QUOTES) ?></textarea></p>
1954 */ ?>
1955 <div id="accua_tab_messages" class="content_tab">
1956 <?php
1957 $settings_editor = array(
1958 'teeny' => true,
1959 'editor_class' => 'accua_form_value',
1960 'tinymce' => array(
1961 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,'));
1962 ?>
1963 <div class="metabox-holder accua-forms-metabox-holder">
1964 <div class="postbox ">
1965 <h3 class="hndle"><span><?php _e('1. On-screen success message', 'accua-form-api'); ?></span></h3>
1966 <div class="inside" id="dashboard_right_now">
1967 <div id="accua_form_success_message">
1968 <?php wp_editor( $form_data['success_message'] , 'success_message' , $settings_editor); ?>
1969 </div>
1970 </div>
1971 </div>
1972 </div>
1973
1974 <div class="metabox-holder accua-forms-metabox-holder">
1975 <div class="postbox ">
1976 <h3 class="hndle"><span><?php _e('2. On-screen error message', 'accua-form-api'); ?></span></h3>
1977 <div class="inside" id="dashboard_right_now">
1978 <div id="accua_form_error_message">
1979 <?php wp_editor( $form_data['error_message'] , 'error_message' , $settings_editor); ?>
1980 </div>
1981 </div>
1982 </div>
1983 </div>
1984 <br clear="all"/>
1985 <div class="metabox-holder accua-forms-metabox-holder">
1986 <div class="postbox ">
1987 <h3 class="hndle"><span><?php _e('3. Email to notify administrator', 'accua-form-api'); ?></span></h3>
1988 <div class="inside" id="dashboard_right_now">
1989 <div id="accua_form_admin_emails_to" class="label_input">
1990 <label><?php _e( 'To', 'accua-form-api'); ?></label>
1991 <input name="admin_emails_to" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_to'], ENT_QUOTES) ?>" />
1992 </div>
1993 <br clear="all" />
1994 <div id="accua_form_emails_bcc" class="label_input">
1995 <label><?php _e( 'Bcc', 'accua-form-api'); ?></label>
1996 <input name="emails_bcc" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_bcc'], ENT_QUOTES) ?>" />
1997 </div>
1998 <br clear="all" />
1999 <div id="accua_form_admin_emails_subject" class="label_input">
2000 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
2001 <input name="admin_emails_subject" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_subject'], ENT_QUOTES) ?>" />
2002 </div>
2003 <br clear="all" />
2004 <div id="accua_form_admin_emails_message">
2005 <?php wp_editor( $form_data['admin_emails_message'] , 'admin_emails_message' , $settings_editor); ?>
2006 </div>
2007
2008 </div>
2009 </div>
2010 </div>
2011
2012 <div class="metabox-holder accua-forms-metabox-holder">
2013 <div class="postbox ">
2014 <h3 class="hndle"><span><?php _e('4. Email confirmation to the person who completed the form', 'accua-form-api'); ?></span></h3>
2015 <div class="inside" id="dashboard_right_now">
2016 <div id="accua_form_emails_from_name" class="label_input">
2017 <label><?php _e( 'From name', 'accua-form-api'); ?></label>
2018 <input class="accua_form_value" name="emails_from_name" type="text" value="<?php echo htmlspecialchars($form_data['emails_from_name'], ENT_QUOTES) ?>" />
2019 </div>
2020 <div id="accua_form_emails_from" class="label_input">
2021 <label><?php _e( 'From email', 'accua-form-api'); ?></label>
2022 <input class="accua_form_value" name="emails_from" type="text" value="<?php echo htmlspecialchars($form_data['emails_from'], ENT_QUOTES) ?>" />
2023 </div>
2024 <br clear="all" />
2025 <div id="accua_form_confirmation_emails_subject" class="label_input">
2026 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
2027 <input class="accua_form_value" type="text" name="confirmation_emails_subject" value="<?php echo htmlspecialchars($form_data['confirmation_emails_subject'], ENT_QUOTES) ?>" />
2028 </div>
2029 <br clear="all" />
2030 <div id="accua_form_confirmation_emails_message">
2031 <?php wp_editor( $form_data['confirmation_emails_message'] , 'confirmation_emails_message' , $settings_editor); ?>
2032 </div>
2033 </div>
2034 </div>
2035 </div>
2036 <br clear="all"/>
2037
2038 <div class="metabox-holder accua-forms-metabox-holder">
2039 <div class="postbox ">
2040 <h3 class="hndle"><span><?php _e( 'File upload default settings', 'accua-form-api'); ?></span></h3>
2041 <div class="inside" id="dashboard_right_now">
2042 <div id="accua_form_valid_extensions"><?php _e( 'Valid extensions', 'accua-form-api'); ?> <br /><textarea name="valid_extensions" class="accua_form_value" style="width:95%"; cols="80" rows="8"><?php echo htmlspecialchars($file_data['valid_extensions'], ENT_QUOTES) ?></textarea>
2043 <small><?php _e( 'List of valid extensions, without dot, one per line.', 'accua-form-api'); ?></small>
2044 </div>
2045 <div id="accua_form_max_size"><?php _e( 'Maximum file size:', 'accua-form-api'); ?> <input name="max_size" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($file_data['max_size'], ENT_QUOTES) ?>" /><br />
2046 <small><?php _e( 'You can use suffix K, M or G for kilobyte, megabyte or gigabyte.', 'accua-form-api'); ?>
2047 <?php
2048 $server_max_size = AccuaForm_Element_File::file_upload_max_size();
2049 if ($server_max_size > 0) {
2050 _e( 'This value is limited by server upload limits of ', 'accua-form-api');
2051 echo AccuaForm_Element_File::format_size($server_max_size).". ";
2052 _e( 'If you need a greater limit you should ask to the server administrator.', 'accua-form-api');
2053 }
2054 ?>
2055 </small>
2056 </div>
2057 <div id="accua_form_dest_path"><?php _e( 'Upload path', 'accua-form-api');?> : <input name="dest_path" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($file_data['dest_path'], ENT_QUOTES) ?>" />
2058 <small><?php _e( 'If it stars with \'/\' an absolute path is used, otherwise a path relative to the WordPress installation directory. Default value is "wp-content/uploads/accua-forms"', 'accua-form-api');?>.</small>
2059 </div>
2060 </div>
2061 </div>
2062
2063 <div class="postbox ">
2064 <h3 class="hndle"><span><?php _e( 'reCaptcha settings', 'accua-form-api'); ?></span></h3>
2065 <div class="inside" id="dashboard_right_now">
2066 <p><?php _e( 'If you leave the key fields blank, old reCAPTCHA 1.0 is used with universal keys', 'accua-form-api');?></p>
2067 <p><?php echo strtr(__('If you want to use reCAPTCHA 2.0, please register on %REGISTERURL% and enter the keys for this site in the following fields', 'accua-form-api'), array('%REGISTERURL%' => '<a href="https://www.google.com/recaptcha" target="_blank">google.com/recaptcha</a>'));?></p>
2068 <div id="accua_"><?php _e('Site key', 'accua-form-api');?> : <input name="recaptcha_public_key" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($captcha_data['recaptcha_public_key'], ENT_QUOTES) ?>" />
2069 </div>
2070 <div id="accua_"><?php _e('Secret key', 'accua-form-api');?> : <input name="recaptcha_private_key" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($captcha_data['recaptcha_private_key'], ENT_QUOTES) ?>" />
2071 </div>
2072 <div id="accua_"><?php _e('Force old reCAPTCHA v1.0', 'accua-form-api');?> : <input type="checkbox" name="recaptcha_force_v1" class="accua_form_value" type="text" value="1" <?php if($captcha_data['recaptcha_force_v1']) { echo 'checked="checked"'; } ?> /><br />
2073 <small><?php _e( "Check if you want to use old reCAPTCHA 1.0 with the keys you provided", 'accua-form-api');?>.</small>
2074 </div>
2075 </div>
2076 </div>
2077 </div>
2078
2079 <div class="metabox-holder accua-forms-metabox-holder">
2080 <div class="postbox ">
2081 <h3 class="hndle"><span><?php _e( 'Layout &amp; Styling', 'accua-form-api'); ?></span></h3>
2082 <div class="inside" id="dashboard_right_now">
2083 <p><?php _e( 'Customize the look and feel of your forms. Leave fields empty if you wish to use the native styles of your WordPress Theme.', 'accua-form-api'); ?><p>
2084 <h4><?php _e( 'Forms', 'accua-form-api'); ?></h4>
2085 <div id="accua_form_layout"> <?php _e( 'Layout', 'accua-form-api'); ?>
2086 <select name="layout" class="accua_form_value"><option value="sidebyside" <?php if ($form_data['layout'] == 'sidebyside') { echo 'selected="selected"'; } ?>>Labels on the left of the fields</option><option value="toplabel" <?php if ($form_data['layout'] == 'toplabel') { echo 'selected="selected"'; } ?>>Labels on top of the fields</option></select>
2087 </div>
2088 <div id="accua_form_style_margin" class="label_input">
2089 <label><?php _e( 'Margin', 'accua-form-api'); ?></label>
2090 <input name="style_margin" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_margin'], ENT_QUOTES) ?>" />
2091 </div>
2092 <div id="accua_form_style_border_color" class="label_input">
2093 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2094 <input name="style_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_color'], ENT_QUOTES) ?>" />
2095 </div>
2096 <div id="accua_form_style_border_width" class="label_input">
2097 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2098 <input name="style_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_width'], ENT_QUOTES) ?>" />
2099 </div>
2100 <div id="accua_form_style_border_radius" class="label_input">
2101 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2102 <input name="style_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_radius'], ENT_QUOTES) ?>" />
2103 </div>
2104 <div id="accua_form_style_background_color" class="label_input">
2105 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2106 <input name="style_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_background_color'], ENT_QUOTES) ?>" />
2107 </div>
2108 <div id="accua_form_style_padding" class="label_input">
2109 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2110 <input name="style_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_padding'], ENT_QUOTES) ?>" />
2111 </div>
2112 <div id="accua_form_style_color" class="label_input">
2113 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2114 <input name="style_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_color'], ENT_QUOTES) ?>" />
2115 </div>
2116 <div id="accua_form_style_font_size" class="label_input">
2117 <label><?php _e( 'Font size', 'accua-form-api'); ?></label>
2118 <input name="style_font_size" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_font_size'], ENT_QUOTES) ?>" />
2119 </div>
2120
2121 <h4><?php _e( 'Fields', 'accua-form-api'); ?></h4>
2122 <div id="accua_form_style_field_spacing" class="label_input">
2123 <label><?php _e( 'Spacing', 'accua-form-api'); ?></label>
2124 <input name="style_field_spacing" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_spacing'], ENT_QUOTES) ?>" />
2125 </div>
2126 <div id="accua_form_style_field_border_color" class="label_input">
2127 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2128 <input name="style_field_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_color'], ENT_QUOTES) ?>" />
2129 </div>
2130 <div id="accua_form_style_field_border_width" class="label_input">
2131 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2132 <input name="style_field_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_width'], ENT_QUOTES) ?>" />
2133 </div>
2134 <div id="accua_form_style_field_border_radius" class="label_input">
2135 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2136 <input name="style_field_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_radius'], ENT_QUOTES) ?>" />
2137 </div>
2138 <div id="accua_form_style_field_background_color" class="label_input">
2139 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2140 <input name="style_field_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_background_color'], ENT_QUOTES) ?>" />
2141 </div>
2142 <div id="accua_form_style_field_padding" class="label_input">
2143 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2144 <input name="style_field_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_padding'], ENT_QUOTES) ?>" />
2145 </div>
2146 <div id="accua_form_style_field_color" class="label_input">
2147 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2148 <input name="style_field_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_color'], ENT_QUOTES) ?>" />
2149 </div>
2150
2151 <h4><?php _e( 'Submit button', 'accua-form-api'); ?></h4>
2152 <div id="accua_form_style_submit_border_color" class="label_input">
2153 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2154 <input name="style_submit_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_color'], ENT_QUOTES) ?>" />
2155 </div>
2156 <div id="accua_form_style_submit_border_width" class="label_input">
2157 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2158 <input name="style_submit_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_width'], ENT_QUOTES) ?>" />
2159 </div>
2160 <div id="accua_form_style_submit_border_radius" class="label_input">
2161 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2162 <input name="style_submit_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_radius'], ENT_QUOTES) ?>" />
2163 </div>
2164 <div id="accua_form_style_submit_background_color" class="label_input">
2165 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2166 <input name="style_submit_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_background_color'], ENT_QUOTES) ?>" />
2167 </div>
2168 <div id="accua_form_style_submit_padding" class="label_input">
2169 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2170 <input name="style_submit_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_padding'], ENT_QUOTES) ?>" />
2171 </div>
2172 <div id="accua_form_style_submit_color" class="label_input">
2173 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2174 <input name="style_submit_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_color'], ENT_QUOTES) ?>" />
2175 </div>
2176 <div id="accua_form_style_submit_font_size" class="label_input">
2177 <label><?php _e( 'Font size', 'accua-form-api'); ?></label>
2178 <input name="style_submit_font_size" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_font_size'], ENT_QUOTES) ?>" />
2179 </div>
2180 <br clear="all" />
2181 </div>
2182 </div>
2183 </div>
2184
2185
2186 <br clear="all"/>
2187
2188 </div>
2189
2190 <?php /*
2191 <h3><?php _e( 'File upload default settings', 'accua-form-api'); ?></h3>
2192 <p id="accua_form_valid_extensions"><?php _e( 'Valid extensions', 'accua-form-api'); ?> <br /><textarea name="valid_extensions" class="accua_form_value" style="width:95%"; cols="80" rows="8"><?php echo htmlspecialchars($file_data['valid_extensions'], ENT_QUOTES) ?></textarea>
2193 <small><?php _e( 'List of valid extensions, without dot, one per line.', 'accua-form-api'); ?></small>
2194 </p>
2195 <p id="accua_form_max_size"><?php _e( 'Maximum file size:', 'accua-form-api'); ?> <input name="max_size" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($file_data['max_size'], ENT_QUOTES) ?>" /><br />
2196 <small><?php _e( 'You can use suffix K, M or G for kilobyte, megabyte or gigabyte.', 'accua-form-api'); ?>
2197 <?php
2198 $server_max_size = AccuaForm_Element_File::file_upload_max_size();
2199 if ($server_max_size > 0) {
2200 _e( 'This value is limited by server upload limits of ', 'accua-form-api');
2201 echo AccuaForm_Element_File::format_size($server_max_size).". ";
2202 _e( 'If you need a greater limit you should ask to the server administrator.', 'accua-form-api');
2203 }
2204 ?>
2205 </small></p>
2206 <p id="accua_form_dest_path"><?php _e( 'Upload path', 'accua-form-api');?> : <input name="dest_path" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($file_data['dest_path'], ENT_QUOTES) ?>" />
2207 <small><?php _e( 'If it stars with \'/\' an absolute path is used, otherwise a path relative to the WordPress installation directory. Default value is "wp-content/uploads/accua-forms"', 'accua-form-api');?>.</small>
2208 </p> */ ?>
2209 <p><input class="button button-primary button-large" id="accua_form_save_settings" type="submit" value="Save settings" /></p>
2210 </form>
2211 </div>
2212
2213 <script type='text/javascript'>
2214 jQuery(function($) {
2215 $('#accua_form_style_border_color .accua_form_value').wpColorPicker();
2216 $('#accua_form_style_background_color .accua_form_value').wpColorPicker();
2217 $('#accua_form_style_color .accua_form_value').wpColorPicker();
2218 $('#accua_form_style_field_border_color .accua_form_value').wpColorPicker();
2219 $('#accua_form_style_field_background_color .accua_form_value').wpColorPicker();
2220 $('#accua_form_style_field_color .accua_form_value').wpColorPicker();
2221 $('#accua_form_style_submit_border_color .accua_form_value').wpColorPicker();
2222 $('#accua_form_style_submit_background_color .accua_form_value').wpColorPicker();
2223 $('#accua_form_style_submit_color .accua_form_value').wpColorPicker();
2224 });
2225 </script>
2226
2227 <?php
2228 }
2229
2230 function _accua_forms_get_abs_dest_path($dest_path = '') {
2231 if ($dest_path === '') {
2232 return realpath(ABSPATH) . '/wp-content/uploads/accua-forms';
2233 } else if (substr($dest_path,0,1) === '/') {
2234 return $dest_path;
2235 } else {
2236 return realpath(ABSPATH) . '/' . $dest_path;
2237 }
2238 }
2239
2240 function _accua_forms_get_form_data($fid = false, $return_empty = true, $restore_trash = false){
2241 $empty_form_data = array(
2242 'fields' => array(),
2243 'title' => '',
2244 'success_message' => '',
2245 'error_message' => '',
2246 'emails_from_name' => '',
2247 'emails_from' => '',
2248 'admin_emails_to' => '',
2249 'emails_bcc' => '',
2250 'admin_emails_subject' => '',
2251 'admin_emails_message' => '',
2252 'confirmation_emails_subject' => '',
2253 'confirmation_emails_message' => '',
2254 'use_ajax' => true,
2255 'layout' => 'sidebyside',
2256 'style_margin' => '',
2257 'style_border_color' => '',
2258 'style_border_width' => '',
2259 'style_border_radius' => '',
2260 'style_background_color' => '',
2261 'style_padding' => '',
2262 'style_color' => '',
2263 'style_font_size' => '',
2264 'style_field_spacing' => '',
2265 'style_field_border_color' => '',
2266 'style_field_border_width' => '',
2267 'style_field_border_radius' => '',
2268 'style_field_background_color' => '',
2269 'style_field_padding' => '',
2270 'style_field_color' => '',
2271 'style_submit_border_color' => '',
2272 'style_submit_border_width' => '',
2273 'style_submit_border_radius' => '',
2274 'style_submit_background_color' => '',
2275 'style_submit_padding' => '',
2276 'style_submit_color' => '',
2277 'style_submit_font_size' => '',
2278 );
2279
2280 if ($fid === false) {
2281 return $empty_form_data;
2282 }
2283
2284 $default_form_data = get_option('accua_forms_default_form_data',array());
2285
2286 if ($fid === null) {
2287 return $default_form_data + $empty_form_data;
2288 }
2289
2290 $forms_data = get_option('accua_forms_saved_forms', array());
2291 if ($restore_trash) {
2292 $trash_data = get_option('accua_forms_trash_forms', array());
2293 if (isset($trash_data[$fid])) {
2294 $forms_data[$fid] = $trash_data[$fid];
2295 update_option('accua_forms_saved_forms', $forms_data);
2296 unset($trash_data[$fid]);
2297 update_option('accua_forms_trash_forms', $trash_data);
2298 }
2299 }
2300
2301 if (isset($forms_data[$fid])) {
2302 $form_data = array(
2303 '_overrided' => $forms_data[$fid]
2304 ) + $forms_data[$fid] + $default_form_data + $empty_form_data;
2305 /*
2306 if ($form_data['fields']) {
2307 foreach ($form_data['fields'] as $i => $istance_data) {
2308 // TODO: popuplate default fields data?
2309 }
2310 }
2311 */
2312 return $form_data;
2313 } else if ($return_empty) {
2314 return array(
2315 '_overrided' => array()
2316 ) + $default_form_data + $empty_form_data;
2317 } else {
2318 return null;
2319 }
2320
2321 }
2322
2323 function _accua_forms_style_parameters($params) {
2324 $ret = '';
2325 foreach ($params as $key => $value) {
2326 $value = trim($value);
2327 if ($value !== '') {
2328 if (is_numeric($value)) {
2329 $ret .= "{$key}:{$value}px;";
2330 } else {
2331 $ret .= "{$key}:{$value};";
2332 }
2333 if ($key == 'border-width') {
2334 $ret .= "border-style:solid;";
2335 }
2336 }
2337 }
2338 return $ret;
2339 }
2340
2341 add_action('accua_form_alter', 'accua_forms_form_generate', -999, 2);
2342 function accua_forms_form_generate($baseid, $form) {
2343 if (substr($baseid, 0, 14) == '__accua-form__') {
2344 $fid = substr($baseid,14);
2345 $form_data = _accua_forms_get_form_data($fid, false);
2346 /*
2347 echo '<!-- fid = ';
2348 print_r($fid);
2349 echo "\n\nform_data = ";
2350 print_r($form_data);
2351 echo "\n-->";
2352 */
2353 if ($form_data) {
2354 $form_style = _accua_forms_style_parameters(array(
2355 'margin' => $form_data['style_margin'],
2356 'border-color' => $form_data['style_border_color'],
2357 'border-width' => $form_data['style_border_width'],
2358 'border-radius' => $form_data['style_border_radius'],
2359 'background' => $form_data['style_background_color'],
2360 'padding' => $form_data['style_padding'],
2361 'color' => $form_data['style_color'],
2362 'font-size' => $form_data['style_font_size'],
2363 ));
2364
2365 $field_style = _accua_forms_style_parameters(array(
2366 'margin-bottom' => $form_data['style_field_spacing'],
2367 'border-color' => $form_data['style_field_border_color'],
2368 'border-width' => $form_data['style_field_border_width'],
2369 'border-radius' => $form_data['style_field_border_radius'],
2370 'background' => (trim($form_data['style_field_background_color']) === '')?'transparent':$form_data['style_field_background_color'],
2371 'padding' => $form_data['style_field_padding'],
2372 'color' => (trim($form_data['style_field_color']) === '')?$form_data['style_color']:$form_data['style_field_color'],
2373 'font-size' => $form_data['style_font_size'],
2374 ));
2375 $field_properties = array();
2376 if ($field_style !== '') {
2377 $field_properties['style'] = $field_style;
2378 }
2379
2380 $submit_style = _accua_forms_style_parameters(array(
2381 'border-color' => $form_data['style_submit_border_color'],
2382 'border-width' => $form_data['style_submit_border_width'],
2383 'border-radius' => $form_data['style_submit_border_radius'],
2384 'background' => $form_data['style_submit_background_color'],
2385 'padding' => $form_data['style_submit_padding'],
2386 'color' => $form_data['style_submit_color'],
2387 'font-size' => $form_data['style_submit_font_size'],
2388 ));
2389 $submit_properties = array();
2390 if ($submit_style !== '') {
2391 $submit_properties['style'] = $submit_style;
2392 }
2393
2394 if ($form_style !== '') {
2395 $form->configure(array('style' => $form_style));
2396 }
2397
2398 if (!empty($form_data['use_ajax'])){
2399 $form->configure(array(
2400 "accua_ajax" => 1,
2401 ));
2402 }
2403
2404 $add_submit = true;
2405 $fieldset_open = false;
2406 $avail_fields = get_option('accua_forms_avail_fields', array());
2407
2408 foreach ($form_data['fields'] as $istance_data) {
2409
2410 if (empty($avail_fields[$istance_data['ref']])) {
2411 $field_data = array();
2412 if (!empty($istance_data['ref'])) {
2413 if ($istance_data['ref'] == '__fieldset-begin') {
2414 $field_data = array(
2415 'id' => '__fieldset-begin',
2416 'name' => __('Fieldset begin', 'accua-form-api'),
2417 'type' => 'fieldset-begin',
2418 'description' => '',
2419 );
2420 } else if ($istance_data['ref'] == '__fieldset-end') {
2421 $field_data = array(
2422 'id' => '__fieldset-end',
2423 'name' => __('Fieldset end', 'accua-form-api'),
2424 'type' => 'fieldset-end',
2425 'description' => '',
2426 );
2427 }
2428 }
2429 } else {
2430 $field_data = $avail_fields[$istance_data['ref']];
2431 }
2432
2433 $field_data += array(
2434 'id' => '__html',
2435 'name' => __( 'Custom HTML content', 'accua-form-api'),
2436 'type' => 'html',
2437 'description' => __('Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
2438 'default_value' => '',
2439 'allowed_values' => '',
2440 );
2441
2442 $istance_data += array(
2443 'istance_id' => $field_data['id'],
2444 'widget_number' => '',
2445 'ref' => $field_data['id'],
2446 'label' => $field_data['name'],
2447 'default_value' => $field_data['default_value'],
2448 'allowed_values' => $field_data['allowed_values'],
2449 );
2450
2451 $element = null;
2452
2453 $allowed_val = trim($istance_data['allowed_values']);
2454
2455
2456 if ($field_data['type'] == 'post-multicheckbox' || $field_data['type'] == 'post-select') {
2457 $posts = accua_get_pages($allowed_val);
2458 $allowed_values = array();
2459 foreach ($posts as $p) {
2460 //$allowed_values[$p->ID] = apply_filters( 'the_title', $p->post_title, $p->ID );
2461 $allowed_values[$p->ID] = $p->post_title;
2462 }
2463 } else {
2464 if ($field_data['type'] == 'file') {
2465 $filedata = get_option('accua_forms_default_file_field_data',array());
2466 $filedata += array(
2467 'valid_extensions' => '',
2468 'max_filesize' => '',
2469 'dest_path' => '',
2470 );
2471 if ($allowed_val == '') {
2472 $allowed_val = trim($filedata['valid_extensions']);
2473 }
2474 }
2475
2476 $allowed_val = explode("\n",$allowed_val);
2477 $allowed_values = array();
2478 foreach ($allowed_val as $val) {
2479 $val = explode('|',$val,2);
2480 $val[0] = trim($val[0]);
2481 /*
2482 if (empty($val[0])) {
2483 continue;
2484 }
2485 */
2486 if ((!isset($val[1])) || (trim($val[1])==='')) {
2487 if ($val[0] === '') {
2488 continue;
2489 } else {
2490 $val[1] = $val[0];
2491 }
2492 }
2493 $allowed_values[$val[0]] = $val[1];
2494 }
2495 }
2496
2497 switch ($field_data['type']) {
2498 case 'textarea':
2499 $element = new Element_Textarea($istance_data['label'], $istance_data['istance_id'], $field_properties+array('cols' => '50', 'value'=>$istance_data['default_value']));
2500 break;
2501 case 'hidden':
2502 $element = new Element_Hidden($istance_data['istance_id'], $istance_data['default_value']);
2503 break;
2504 case 'checkbox':
2505 $lab = $istance_data['label'];
2506 if (!empty($istance_data['required'])) {
2507 $lab .= ' <strong>*</strong>';
2508 }
2509 if ($allowed_values) {
2510 reset($allowed_values);
2511 $val = (string) key($allowed_values);
2512 $defval = trim($istance_data['default_value']);
2513 } else if ($istance_data['default_value'] == '1') {
2514 $defval = $val = '1';
2515 } else {
2516 $val = empty($istance_data['default_value'])?'1':$istance_data['default_value'];
2517 $defval = '';
2518 }
2519 $element = new AccuaForm_Element_Checkbox('', $istance_data['istance_id'], array($val => $lab), array('value' => $defval));
2520 break;
2521 case 'select':
2522 case 'post-select':
2523 if (!isset($allowed_values[''])) {
2524 $allowed_values = array('' => '') + $allowed_values;
2525 }
2526 $defval = trim($istance_data['default_value']);
2527 $element = new AccuaForm_Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, $field_properties+array('value'=>$defval));
2528 break;
2529 case 'radio':
2530 $defval = trim($istance_data['default_value']);
2531 $element = new AccuaForm_Element_Radio($istance_data['label'], $istance_data['istance_id'], $allowed_values, array('value'=>$defval));
2532 break;
2533 case 'multiselect':
2534 $defval = explode('|', $istance_data['default_value']);
2535 foreach ($defval as $k => $v) {
2536 $defval[$k] = trim($v);
2537 }
2538 $element = new AccuaForm_Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, $field_properties+array('multiple' => true, 'value'=>$defval));
2539 break;
2540 case 'multicheckbox':
2541 case 'post-multicheckbox':
2542 $defval = explode('|', $istance_data['default_value']);
2543 foreach ($defval as $k => $v) {
2544 $defval[$k] = trim($v);
2545 }
2546 $element = new AccuaForm_Element_Checkbox($istance_data['label'], $istance_data['istance_id'], $allowed_values, array('value'=>$defval));
2547 break;
2548 case 'file':
2549 $fdata = array();
2550
2551 if ($allowed_values) {
2552 $fdata['validExtensions'] = array_keys($allowed_values);
2553 }
2554
2555 if ($filedata['max_size'] !== ''){
2556 $fdata['maxSize'] = $filedata['max_size'];
2557 }
2558
2559 $fdata['destPath'] = _accua_forms_get_abs_dest_path($filedata['dest_path']);
2560
2561 $element = new AccuaForm_Element_File($istance_data['label'], $istance_data['istance_id'], $field_properties+$fdata);
2562 break;
2563 case 'html':
2564 $element = new Element_HTML($istance_data['default_value']);
2565 break;
2566 case 'email':
2567 case 'autoreply_email':
2568 $element = new AccuaForm_Element_Email($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2569 $element->setValidation(new Validation_Email(
2570 str_replace('%element%', $istance_data['label'], __("Attention: '%element%' must contain an email address.", 'accua-form-api'))
2571 ));
2572 //"Errore: '{$istance_data['label']}' deve contenere un indirizzo email valido."
2573 break;
2574 case 'colorpicker':
2575 $element = new AccuaForm_Element_ColorPicker($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2576 break;
2577 case 'fieldset-begin':
2578 if ($fieldset_open) {
2579 $form->addElement(new AccuaForm_Element_FieldsetEnd());
2580 } else {
2581 $fieldset_open = true;
2582 }
2583 $element = new AccuaForm_Element_FieldsetBegin($istance_data['label']);
2584 break;
2585 case 'fieldset-end':
2586 if ($fieldset_open) {
2587 $element = new AccuaForm_Element_FieldsetEnd();
2588 $fieldset_open = false;
2589 }
2590 break;
2591 case 'submit':
2592 $add_submit = false;
2593 $element = new Element_Button($istance_data['label'], 'submit', $submit_properties+array('name' => $istance_data['istance_id'], 'value' => $istance_data['default_value']));
2594 break;
2595 case 'captcha':
2596 $empty_captcha_data = array(
2597 'recaptcha_force_v1' => '',
2598 'recaptcha_public_key' => '',
2599 'recaptcha_private_key' => '',
2600 );
2601 $captcha_data = get_option('accua_forms_default_captcha_field_data',array()) + $empty_captcha_data;
2602 $captcha_properties = array("description" => "");
2603 $captcha_use_v1 = true;
2604 if (($captcha_data['recaptcha_public_key'] !== '') && ($captcha_data['recaptcha_private_key'] !== '')) {
2605 $captcha_properties['privateKey'] = $captcha_data['recaptcha_private_key'];
2606 $captcha_properties['publicKey'] = $captcha_data['recaptcha_public_key'];
2607 $captcha_use_v1 = $captcha_data['recaptcha_force_v1'];
2608 }
2609 if ($captcha_use_v1) {
2610 $element = new AccuaForm_Element_Captcha ($istance_data['label'], $captcha_properties);
2611 } else {
2612 $element = new AccuaForm_Element_Captcha2 ($istance_data['label'], $captcha_properties);
2613 }
2614 break;
2615 case 'password':
2616 $element = new Element_Password($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2617 break;
2618 case 'password-and-confirm':
2619 $id_2 = "___{$istance_data['istance_id']}___confirmpass";
2620 $element = new Element_Password(__("Password", 'accua-form-api'), $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2621 $element_conf = new Element_Password(__("Confirm password", 'accua-form-api'), $id_2, $field_properties+array('value'=>$istance_data['default_value']));
2622 $element_conf->setValidation(new AccuaForm_Validation_Password());
2623 break;
2624 //case 'textfield':
2625 default:
2626 $element = new Element_Textbox($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2627 break;
2628 }
2629 if ($element) {
2630 if (!empty($istance_data['required'])) {
2631 $element->setClass('accuaforms-field-required');
2632 if($field_data['type']!='password-and-confirm') {
2633 $element->setValidation(new Validation_Required(
2634 str_replace('%element%', $istance_data['label'], __("Attention: '%element%' is a required field.", 'accua-form-api'))
2635 ));
2636 } else {
2637 $element->setValidation(new Validation_Required(
2638 str_replace('%element%', $istance_data['label'], __("Attention: Passwords are required fields.", 'accua-form-api'))
2639 ));
2640 }
2641 }
2642
2643 if ($elementName = $element->getName()) {
2644 $element->setClass('accuaform-fieldname-'.$elementName);
2645 }
2646
2647 if ($field_data['type']) {
2648 $element->setClass('accuaform-fieldtype-'.$field_data['type']);
2649 }
2650
2651 $form->addElement($element);
2652 if($element_conf!=NULL) {
2653 $form->addElement($element_conf);
2654 $element_conf=NULL;
2655 }
2656 }
2657 }
2658 if ($fieldset_open) {
2659 $form->addElement(new AccuaForm_Element_FieldsetEnd());
2660 $fieldset_open = false;
2661 }
2662 if ($add_submit) {
2663 $form->addElement(new Element_Button(__('Submit', 'accua-form-api'), 'submit', $submit_properties));
2664 }
2665 }
2666
2667 }
2668 }
2669
2670 function accua_forms_aggregate_submitted_data(&$replace_map, $params = array()) {
2671 if (empty($params['txt']) && empty($params['html']) && empty($params['json']) && empty($params['email'])) {
2672 $params += array(
2673 'txt' => true,
2674 'html' => true,
2675 'json' => true,
2676 'email' => true,
2677 );
2678 }
2679
2680 if (!empty($params['txt'])) {
2681 $replace_map['__submitted_txt'] = implode("\n",$replace_map['__submitted_txt_raw']);
2682 }
2683 if (!empty($params['html'])) {
2684 $replace_map['__submitted_html'] = implode('</td></tr><tr><td>',$replace_map['__submitted_html_raw']);
2685 }
2686 if (!empty($params['json'])) {
2687 $replace_map['__submitted_json'] = json_encode($replace_map['__submitted_json_raw'], JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP);
2688 }
2689 if (!empty($params['email'])) {
2690 $replace_map['__autoreply_email'] = implode('; ', $replace_map['__autoreply_email_raw']);
2691 }
2692
2693 }
2694
2695 add_filter('accua_form_validate', 'accua_forms_validation_handler', 10, 4);
2696 function accua_forms_validation_handler($valid, $submittedID, $submittedData, $form){
2697 if (substr($submittedID, 0, 14) == '__accua-form__') {
2698 $fid = substr($submittedID,14);
2699 $form_data = _accua_forms_get_form_data($fid, false);
2700 if ($form_data) {
2701 return apply_filters('accua_forms_validation', $valid, $fid, $submittedData, $form);
2702 }
2703 }
2704 return $valid;
2705 }
2706
2707 add_action('accua_form_submit', 'accua_forms_form_submission_handler', -10, 3);
2708 function accua_forms_form_submission_handler($submittedID, $submittedData, $form) {
2709 if ( empty( $GLOBALS['wp_rewrite'] ) )
2710 $GLOBALS['wp_rewrite'] = new WP_Rewrite();
2711
2712 if (!class_exists('AccuaConditionalReplacer')){
2713 require_once('AccuaConditionalReplacer.php');
2714 }
2715 if (substr($submittedID, 0, 14) == '__accua-form__') {
2716 $fid = substr($submittedID,14);
2717 $form_data = _accua_forms_get_form_data($fid, false);
2718 if ($form_data) {
2719 global $wpdb;
2720
2721 $time = time();
2722
2723 $wpdb->insert(
2724 $wpdb->prefix . 'accua_forms_submissions',
2725 array (
2726 'afs_form_id' => $fid,
2727 'afs_post_id' => $form->stats['pid'],
2728 'afs_ip' => $form->stats['ip'],
2729 'afs_uri' => $form->stats['uri'],
2730 'afs_referrer' => $form->stats['referrer'],
2731 'afs_lang' => $form->stats['lang'],
2732 'afs_created' => gmdate('Y-m-d H:i:s', $form->stats['created']),
2733 'afs_submitted' => gmdate('Y-m-d H:i:s', $time),
2734 'afs_stats' => json_encode(array(
2735 'user_agent' => $form->stats['user_agent'],
2736 'platform' => $form->stats['platform'],
2737 'tentatives' => $form->stats['tentatives'],
2738 'submit_method' => $form->stats['submit_method'],
2739 ), JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP),
2740 )
2741 );
2742
2743 $submission_id = $form->stats['submission_id'] = $wpdb->insert_id;
2744
2745
2746
2747 $replace_map = array(
2748 '__fid' => $fid,
2749 '__subid' => $submission_id,
2750 '__pid' => $form->stats['pid'],
2751 '__ip' => $form->stats['ip'],
2752 '__uri' => $form->stats['uri'],
2753 '__url' => $form->stats['url'],
2754 '__referrer' => $form->stats['referrer'],
2755 '__lang' => $form->stats['lang'],
2756 '__locale' => $form->stats['locale'],
2757 '__created' => $form->stats['created'],
2758 '__created_day' => date('l j F Y', $form->stats['created']),
2759 '__created_day_month_year' => date('j F Y', $form->stats['created']),
2760 '__created_hour' => date('G:i', $form->stats['created']),
2761 '__submitted' => $time,
2762 '__submitted_day' => date('l j F Y', $time),
2763 '__submitted_day_month_year' => date('j F Y', $time),
2764 '__submitted_hour' => date('G:i', $time),
2765 '__confirmation_emails_message' => $form_data['confirmation_emails_message'],
2766 '__user_agent' => $form->stats['user_agent'],
2767 '__platform' => $form->stats['platform'],
2768 '__tentatives' => $form->stats['tentatives'],
2769 '__submit_method' => $form->stats['submit_method'],
2770 );
2771
2772 $avail_fields = get_option('accua_forms_avail_fields', array());
2773
2774 $replace_map['__autoreply_email_raw'] = array();
2775 $replace_map['__submitted_txt_raw'] = array();
2776 $replace_map['__submitted_html_raw'] = array();
2777 $replace_map['__submitted_json_raw'] = array();
2778
2779 $_field_data = array();
2780 $_istance_data = array();
2781
2782 foreach ($submittedData as $istance_id => $value) {
2783 if (empty($form_data['fields'][$istance_id])) {
2784 continue;
2785 }
2786 $istance_data = $form_data['fields'][$istance_id];
2787
2788 if (empty($avail_fields[$istance_data['ref']])) {
2789 $fieldset_data = array();
2790 if (!empty($istance_data['ref'])) {
2791 if ($istance_data['ref'] == '__fieldset-begin') {
2792 $field_data = array(
2793 'id' => '__fieldset-begin',
2794 'name' => __('Fieldset begin', 'accua-form-api'),
2795 'type' => 'fieldset-begin',
2796 'description' => '',
2797 );
2798 } else if ($istance_data['ref'] == '__fieldset-end') {
2799 $field_data = array(
2800 'id' => '__fieldset-end',
2801 'name' => __('Fieldset end', 'accua-form-api'),
2802 'type' => 'fieldset-end',
2803 'description' => '',
2804 );
2805 }
2806 }
2807 } else {
2808 $field_data = $avail_fields[$istance_data['ref']];
2809 }
2810
2811 $field_data += array(
2812 'id' => '__html',
2813 'name' => __( 'Custom HTML content', 'accua-form-api'),
2814 'type' => 'html',
2815 'description' => __( 'Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
2816 'default_value' => '',
2817 'allowed_values' => '',
2818 );
2819
2820 /*
2821 echo "<!-- istance_data: "
2822 , print_r($istance_data, true)
2823 , "\nfield_data: "
2824 , print_r($field_data, true)
2825 , "\nvalue: "
2826 , print_r($value, true)
2827 , "\n-->\n";
2828 */
2829
2830 $istance_data += array(
2831 'istance_id' => $field_data['id'],
2832 'widget_number' => '',
2833 'ref' => $field_data['id'],
2834 'label' => $field_data['name'],
2835 'default_value' => $field_data['default_value'],
2836 'allowed_values' => $field_data['allowed_values'],
2837 );
2838
2839 $type = $field_data['type'];
2840
2841 switch ($field_data['type']) {
2842 case 'checkbox':
2843 case 'submit':
2844 if (empty($value)) {
2845 $replace_map[$istance_data['istance_id']] = $value = '';
2846 } else {
2847 if (empty($istance_data['default_value'])) {
2848 $replace_map[$istance_data['istance_id']] = 'Checked';
2849 $value = '1';
2850 } else {
2851 $replace_map[$istance_data['istance_id']] = $value = $istance_data['default_value'];
2852 }
2853 }
2854 break;
2855 case 'multiselect':
2856 case 'multicheckbox':
2857 case 'select':
2858 case 'radio':
2859 $el = $form->getElementByName($istance_id);
2860 $opts = $el->getOptions();
2861 if (!is_array($value)) {
2862 $value = array($value);
2863 }
2864 $label = array();
2865 foreach ($value as $val) {
2866 if (isset($opts[$val])) {
2867 $label[] = $opts[$val];
2868 }
2869 }
2870 $replace_map['__label_'.$istance_data['istance_id']] = implode(", ", $labels);
2871 $replace_map[$istance_data['istance_id']] = implode(', ',$value);
2872 $value = implode('|',$value);
2873 break;
2874 case 'post-multicheckbox':
2875 if (is_array($value) && $value) {
2876 $el = $form->getElementByName($istance_id);
2877 $opts = $el->getOptions();
2878 $value2 = array();
2879 $titles = array();
2880 $ids = array();
2881 $urls = array();
2882 foreach ($value as $val) {
2883 if (isset($opts[$val])) {
2884 $titles[] = $opts[$value];
2885 $ids[] = $value;
2886 $urls[] = get_permalink($value);
2887 $value2[] = $val . ': ' . trim(preg_replace('/[\s\n\r]+/', ' ', $opts[$val]));
2888 }
2889 }
2890 $replace_map['__label_'.$istance_data['istance_id']] = $replace_map['__post_title_'.$istance_data['istance_id']] = implode("\n", $titles);
2891 $replace_map['__post_id_'.$istance_data['istance_id']] = implode("\n", $ids);
2892 $replace_map['__post_url_'.$istance_data['istance_id']] = implode("\n", $urls);
2893 $replace_map[$istance_data['istance_id']] = $value = implode("\n", $value2);
2894 } else {
2895 $replace_map['__label_'.$istance_data['istance_id']] = $replace_map['__post_title_'.$istance_data['istance_id']] = '';
2896 $replace_map['__post_id_'.$istance_data['istance_id']] = '';
2897 $replace_map['__post_url_'.$istance_data['istance_id']] = '';
2898 $replace_map[$istance_data['istance_id']] = $value = '';
2899 }
2900 break;
2901 case 'post-select':
2902 if ($value !== '') {
2903 $el = $form->getElementByName($istance_id);
2904 $opts = $el->getOptions();
2905 if (isset($opts[$value])) {
2906 $replace_map['__label_'.$istance_data['istance_id']] = $replace_map['__post_title_'.$istance_data['istance_id']] = $opts[$value];
2907 $replace_map['__post_id_'.$istance_data['istance_id']] = $value;
2908 $replace_map['__post_url_'.$istance_data['istance_id']] = get_permalink($value);
2909 $value = $value . ': ' . trim(preg_replace('/[\s\n\r]+/', ' ', $opts[$value]));
2910 } else {
2911 $replace_map['__label_'.$istance_data['istance_id']] = $replace_map['__post_title_'.$istance_data['istance_id']] = '';
2912 $replace_map['__post_id_'.$istance_data['istance_id']] = '';
2913 $replace_map['__post_url_'.$istance_data['istance_id']] = '';
2914 $value = '';
2915 }
2916 }
2917 $replace_map[$istance_data['istance_id']] = $value;
2918 break;
2919 case 'autoreply_email':
2920 if ($value !== '') {
2921 $replace_map['__autoreply_email_raw'][] = $value;
2922 }
2923 $replace_map[$istance_data['istance_id']] = $value;
2924 break;
2925 case 'file':
2926 //TODO: move temp file to "{$submission_id}_{$field_data['id']}_{$file['name']}"; value is $file['name']
2927 $buildid = $submittedData['_AccuaForm_buildID'];
2928 $file_download_url = '';
2929 $file = $form->getFile($istance_id);
2930 if ($value !== null && $value !== '' && $file) {
2931 if ($form->renameFile($istance_id, "{$submission_id}_{$field_data['id']}_{$file['name']}")) {
2932 $urlfield = rawurlencode($istance_data['istance_id']);
2933 $urlfile = rawurlencode($value);
2934 $file_download_url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$submission_id}&field={$urlfield}&file={$urlfile}";
2935 }
2936 }
2937 $replace_map[$istance_data['istance_id']] = $value;
2938 $replace_map['__download_'.$istance_data['istance_id']] = $file_download_url;
2939 break;
2940 case 'password':
2941 case 'password-and-confirm':
2942 $value = trim($value);
2943 $replace_map[$istance_data['istance_id']] = $value;
2944 $type = 'hashed-password';
2945 if ($value !== '') {
2946 $value = wp_hash_password($value);
2947 }
2948 $replace_map['__hashed_'.$istance_data['istance_id']] = $value;
2949 break;
2950 default:
2951 $replace_map[$istance_data['istance_id']] = $value;
2952 }
2953
2954 switch ($field_data['type']) {
2955 case 'file':
2956 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value\t$file_download_url";
2957 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = "$value\t$file_download_url";
2958 $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "<strong>{$istance_data['istance_id']}</strong></td><td class='valori_submitted'><a href='".htmlspecialchars($file_download_url,ENT_QUOTES)."'>".htmlspecialchars($value)."</a>";
2959 break;
2960
2961 case 'email':
2962 case 'autoreply_email':
2963 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2964 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2965 $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "<strong>{$istance_data['istance_id']}</strong></td><td class='valori_submitted'><a href='mailto:".htmlspecialchars($value,ENT_QUOTES)."'>".htmlspecialchars($value)."</a>";
2966 break;
2967 case 'submit':
2968 break;
2969 case 'colorpicker':
2970 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2971 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2972 if ($value === '') {
2973 $value_html = '';
2974 } else {
2975 $value_esc = htmlspecialchars($value, ENT_QUOTES);
2976 $value_html = "<span style='color: $value_esc'><font color='$value_esc'>&#9608;</font></span> $value_esc";
2977 }
2978 $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "<strong>{$istance_data['istance_id']}</strong></td><td class='valori_submitted'>$value_html";
2979 break;
2980 case 'password':
2981 case 'password-and-confirm':
2982 break;
2983 default:
2984 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2985 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2986 $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "<strong>{$istance_data['istance_id']}</strong></td><td class='valori_submitted'>".htmlspecialchars($value);
2987 }
2988
2989 if ($submission_id) {
2990 $wpdb->insert(
2991 $wpdb->prefix . 'accua_forms_submissions_values',
2992 array (
2993 'afsv_sub_id' => $submission_id,
2994 'afsv_field_id' => $istance_data['istance_id'],
2995 'afsv_type' => $type,
2996 'afsv_value' => $value,
2997 ),
2998 array('%d','%s','%s','%s')
2999 );
3000 }
3001
3002 $_field_data[$istance_data['istance_id']] = $field_data;
3003 $_istance_data[$istance_data['istance_id']] = $istance_data;
3004
3005 }
3006
3007 $replace_map['__autoreply'] = (bool) ($replace_map['__autoreply_email_raw']
3008 && $form_data['confirmation_emails_subject']
3009 && $form_data['confirmation_emails_message']);
3010
3011 accua_forms_aggregate_submitted_data($replace_map);
3012
3013 //Older undocumented filter, maintained for backward compatibility. In fact filter accua_forms_form_submission_handler is called before accua_forms_submission, but for the rest they are the same
3014 $replace_map = apply_filters('accua_forms_form_submission_handler', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data);
3015
3016 //Newer filter, with an easier name
3017 $replace_map = apply_filters('accua_forms_submission', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data);
3018
3019 $submitted_html = '<table><tr><td>' . $replace_map['__submitted_html'] . '</td></tr></table>';
3020 $confirmation_emails_message = $replace_map['__confirmation_emails_message'];
3021 unset($replace_map['__submitted_html'], $replace_map['__confirmation_emails_message'], $replace_map['__submitted_txt_raw'], $replace_map['__submitted_html_raw'], $replace_map['__submitted_json_raw'], $replace_map['__autoreply_email_raw']);
3022
3023 $replace_map_html = array();
3024 foreach($replace_map as $key => $value) {
3025 $replace_map_html["!$key"] = $value;
3026 $replace_map_html[$key] = htmlspecialchars($value, ENT_QUOTES);
3027 }
3028
3029 $replace_map['__submitted_html'] = $replace_map_html['__submitted_html'] = $replace_map_html['!__submitted_html'] = $submitted_html;
3030 $replacer_html = new AccuaConditionalReplacer($replace_map_html);
3031
3032 $confirmation_emails_message = $replace_map['__confirmation_emails_message'] = $replacer_html->doReplace($confirmation_emails_message);
3033 $replacer_html->appendPattern(array('__confirmation_emails_message' => $confirmation_emails_message, '!__confirmation_emails_message' => $confirmation_emails_message));
3034 $replacer = new AccuaConditionalReplacer($replace_map);
3035
3036 $form_data_replaced = array();
3037
3038 $settings = array(
3039 'emails_from_name',
3040 'emails_from',
3041 'admin_emails_to',
3042 'emails_bcc',
3043 'admin_emails_subject',
3044 'confirmation_emails_subject',
3045 );
3046
3047 foreach($settings as $i) {
3048 $form_data_replaced[$i] = $replacer->doReplace($form_data[$i]);
3049 }
3050
3051 $settings_html = array(
3052 'success_message',
3053 'admin_emails_message',
3054 );
3055
3056 foreach($settings_html as $i) {
3057 $form_data_replaced[$i] = $replacer_html->doReplace($form_data[$i]);
3058 }
3059
3060 AccuaForm::appendSubmittedMessages(wpautop($form_data_replaced['success_message']));
3061
3062 $header = array("Content-Type: text/html; charset=".get_option('blog_charset'));
3063
3064 $emails_from = trim($form_data_replaced['emails_from']);
3065 if (strpos($emails_from, '@') !== false) {
3066 if ((strpos($emails_from, '<') === false) && is_email($emails_from)) {
3067 $emails_from_name = trim($form_data_replaced['emails_from_name']);
3068 if ($emails_from_name !== '') {
3069 $emails_from = "=?" . get_bloginfo('charset') . "?B?" . base64_encode($emails_from_name) . "?= <$emails_from>";
3070 }
3071 }
3072 $header[] = 'From: '.$emails_from;
3073 }
3074
3075 if ($form_data_replaced['emails_bcc']) {
3076 $header[] = 'Bcc: '.$form_data_replaced['emails_bcc'];
3077 }
3078
3079 if ($form_data_replaced['admin_emails_to']
3080 && $form_data_replaced['admin_emails_subject']) {
3081 /*
3082 $admin_tos = explode(',', strtr($form_data_replaced['admin_emails_to'], "\n\t\r;", ',,,,'));
3083 foreach ($admin_tos as $admin_to) {
3084 $mail1 = wp_mail(trim($admin_to), $form_data_replaced['admin_emails_subject'], $form_data_replaced['admin_emails_message'], $header);
3085 }
3086 */
3087 $mail1 = wp_mail($form_data_replaced['admin_emails_to'], $form_data_replaced['admin_emails_subject'],'<html><head></head><body style="background:#f9f8f8;font-size: 12px;font-family: "Lucida Sans","Lucida Grande", Verdana, Arial, Sans-Serif;"">'.wpautop($form_data_replaced['admin_emails_message']).'</body></html>', $header);
3088 }
3089
3090 if ($replace_map['__autoreply'] && $replace_map['__autoreply_email']
3091 && $form_data_replaced['confirmation_emails_subject']
3092 && $confirmation_emails_message) {
3093 $mail2 = wp_mail($replace_map['__autoreply_email'], $form_data_replaced['confirmation_emails_subject'], '<html><head></head><body>'.wpautop($confirmation_emails_message).'</body></html>', $header);
3094 }
3095
3096 /*
3097 echo "<!-- replace_map: "
3098 , print_r($replace_map, true)
3099 , "\nreplace_map: "
3100 , print_r($replace_map, true)
3101 , "\nform_data_replaced: "
3102 , print_r($form_data_replaced, true)
3103 , "\nautoreply_email: "
3104 , print_r($autoreply_email, true)
3105 , "\nmail1: "
3106 , print_r($mail1, true)
3107 , "\nmail2: "
3108 , print_r($mail2, true)
3109 ,"\n-->";
3110 */
3111 }
3112 }
3113 }
3114
3115 function accua_forms_get_submission_data($subid, $options = array()){
3116 //TODO: Completa e usa per sostituire i campi
3117 global $wpdb;
3118 $subid = (int) $subid;
3119 $options += array(
3120 'extra' => true,
3121 'file_format' => 'name',
3122 );
3123 $ret = array();
3124 if ($options['extra']) {
3125 $query1 = "SELECT *
3126 FROM `{$wpdb->prefix}accua_forms_submissions`
3127 WHERE afs_id = $subid";
3128 $data = $wpdb->get_row($query1);
3129 if (!empty($data)) {
3130 $created = $data->afs_created;
3131 $created[10] = 'T';
3132 $created.='.00+00:00';
3133 $created = strtotime($created);
3134 $submitted = $data->afs_submitted;
3135 $submitted[10] = 'T';
3136 $submitted.='.00+00:00';
3137 $submitted = strtotime($submitted);
3138 if ($data->afs_stats) {
3139 $stats = json_decode($data->afs_stats, true);
3140 if (!$stats) {
3141 $stats = array();
3142 }
3143 } else {
3144 $stats = array();
3145 }
3146 $stats += array(
3147 'user_agent' => '',
3148 'platform' => '',
3149 'tentatives' => '',
3150 'submit_method' => '',
3151 );
3152 $ret += array(
3153 '__fid' => $data->afs_form_id,
3154 '__subid' => $subid,
3155 '__pid' => $data->afs_post_id,
3156 '__ip' => $data->afs_id,
3157 '__uri' => $data->afs_uri,
3158 '__referrer' => $data->afs_referrer,
3159 '__lang' => $data->afs_lang,
3160 '__created' => $created,
3161 '__created_day' => date('l j F Y', $created),
3162 '__created_hour' => date('G:i', $created),
3163 '__submitted' => $submitted,
3164 '__submitted_day' => date('l j F Y', $submitted),
3165 '__submitted_hour' => date('G:i', $submitted),
3166 '__user_agent' => $stats['user_agent'],
3167 '__platform' => $stats['platform'],
3168 '__tentatives' => $stats['tentatives'],
3169 '__submit_method' => $stats['submit_method'],
3170 );
3171 }
3172 }
3173
3174 $query2 = "SELECT *
3175 FROM `{$wpdb->prefix}accua_forms_submissions_values`
3176 WHERE afsv_sub_id = $subid";
3177
3178 $data2 = $wpdb->get_results($query2, OBJECT);
3179
3180 foreach ($data2 as $row) {
3181 switch ($row->afsv_type) {
3182 case 'file' :
3183 if ($options['file_format'] == 'url' || $options['file_format'] == 'link') {
3184 $fieldid = rawurlencode($row->afsv_field_id);
3185 $filename = rawurlencode($row->afsv_value);
3186 $url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$row->afsv_sub_id}&field={$fieldid}&file={$filename}";
3187 if ($options['file_format'] == 'link'){
3188 $url = htmlspecialchars($url,ENT_QUOTES);
3189 $filename = htmlspecialchars($row->afsv_value,ENT_QUOTES);
3190 $fielddata = "<a href='{$url}' target='_blank'>{$filename}</a>";
3191 } else {
3192 $fielddata = $url;
3193 }
3194 } else { // $options['file_format'] == 'name'
3195 $fielddata = $row->afsv_value;
3196 }
3197 break;
3198 default:
3199 $fielddata = $row->afsv_value;
3200 }
3201 $ret[$row->afsv_field_id] = $fielddata;
3202 }
3203 return $ret;
3204 }
3205
3206 add_shortcode( 'accua-form', 'accua_forms_shortcode_handler' );
3207 function accua_forms_shortcode_handler($atts, $content = '', $code = '') {
3208 if (empty($atts['fid'])) {
3209 return '';
3210 }
3211
3212 $fid = $atts['fid'];
3213 $form_data = _accua_forms_get_form_data($fid, false);
3214
3215 if (! $form_data) {
3216 return '';
3217 }
3218
3219 $fid = '__accua-form__'.$fid;
3220
3221 $out = '';
3222
3223 if (AccuaForm::getSubmittedID() == $fid) {
3224 /* return "<pre>Form submitted.\n\nData: " . print_r(AccuaForm::getSubmittedData(), true) . '</pre>'; */
3225 $messages = AccuaForm::getSubmittedMessages();
3226 if ($messages) {
3227 $out .= '<div id="_response_messages_'.$fid.'" class="accua-form-messages">'.$messages.'</div>';
3228 }
3229 if (AccuaForm::isValid()) {
3230 return $out;
3231 }
3232 $form = AccuaForm::getSubmittedForm();
3233 } else {
3234 $form = AccuaForm::create($fid, array('layout'=>$form_data['layout']));
3235 }
3236
3237 return $out . $form->render(true);
3238 }
3239
3240 function accua_forms_include($fid, $atts=array(), $content = '', $code = '') {
3241 $atts['fid'] = $fid;
3242 echo accua_forms_shortcode_handler($atts, $content, $code);
3243 }
3244
3245 function accua_forms_submissions_list_page_head(){
3246 require_once('accua-forms-submissions-page.php');
3247 accua_forms_submissions_list_page(true);
3248 }
3249
3250 add_action('wp_ajax_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file');
3251 add_action('wp_ajax_nopriv_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file');
3252 function accua_forms_download_submitted_file(){
3253 $get = stripslashes_deep($_GET);
3254 if (isset($get['subid'],$get['field'],$get['file'])) {
3255 global $wpdb;
3256 $subid = (int) $get['subid'];
3257 $field = $get['field'];
3258 $file = $get['file'];
3259 $query = "SELECT *
3260 FROM `{$wpdb->prefix}accua_forms_submissions_values`
3261 WHERE afsv_sub_id = %d
3262 AND afsv_field_id = %s
3263 AND afsv_value = %s
3264 ";
3265 $query = $wpdb->prepare($query, $subid, $field, $file);
3266 $subval = $wpdb->get_results($query, OBJECT);
3267 if ($subval) {
3268 $file_data = get_option('accua_forms_default_file_field_data',array()) + array('dest_path' => '');
3269 $dest_path = _accua_forms_get_abs_dest_path($file_data['dest_path']);
3270 $filename = "{$dest_path}/{$subid}_{$field}_{$file}";
3271 if (is_file($filename) && is_readable($filename)){
3272 if (function_exists('finfo_open')){
3273 @ $finfo = finfo_open(FILEINFO_MIME);
3274 if ($finfo) {
3275 @ $filetype = finfo_file($finfo, $filename);
3276 @ finfo_close($finfo);
3277 }
3278 }
3279 if (empty($filetype) && function_exists('mime_content_type')){
3280 @ $filetype = mime_content_type($filename);
3281 }
3282 if (empty($filetype)) {
3283 $filetype = "application/octet-stream";
3284 }
3285 header("Content-type: $filetype");
3286 header("Content-length: ".filesize($filename));
3287 header("Content-disposition: attachment; filename=\"$file\"");
3288 readfile($filename);
3289 die('');
3290 }
3291 }
3292 }
3293 header("HTTP/1.0 404 Not Found");
3294 //header("Status: 404 Not Found");
3295 die('File not found');
3296 }
3297
3298 function accua_forms_buildConditionalReplacer($map = array()) {
3299 if (!class_exists('AccuaConditionalReplacer')){
3300 require_once('AccuaConditionalReplacer.php');
3301 }
3302 return new AccuaConditionalReplacer($map);
3303 }
3304
3305
3306 add_action('wp_ajax_accua_forms_preview', 'accua_forms_preview');
3307 function accua_forms_preview() {
3308 if (!current_user_can('manage_options')){
3309 die ('');
3310 }
3311
3312 echo '<html><head>';
3313 wp_print_styles();
3314 wp_print_head_scripts();
3315 echo '</head><body>';
3316 echo accua_forms_shortcode_handler(array('fid'=>$_REQUEST['fid']));
3317 wp_print_footer_scripts();
3318 echo '</body></html>';
3319 die('');
3320 }
3321
3322 //salvataggio file excel
3323 add_action('wp_ajax_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel');
3324 //add_action('wp_ajax_nopriv_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel');
3325
3326 function accua_forms_submission_page_save_excel() {
3327 if (!current_user_can('manage_options')){
3328 header("HTTP/1.0 401 Access Denied");
3329 //header("Status: 401 Access Denied");
3330 die('You are not authorized to access this page.');
3331 }
3332
3333 require_once('accua-forms-submissions-page.php');
3334 $listTable = new Accua_Forms_Submissions_List_Table();
3335 $listTable->prepare_items(true);
3336 $show_col = explode( ',', $_GET['accua_show_field']);
3337
3338 header("Content-disposition: attachment; filename=downloads-report.xls");
3339 header("Content-type: application/vnd.ms-excel");
3340 accua_forms_submission_page_save_excel_general($listTable,$show_col);
3341 die('');
3342 }
3343
3344
3345
3346 function accua_forms_submission_page_save_excel_general(Accua_Forms_Submissions_List_Table $listTable,array $show_col,array $options=array()) {
3347 global $wpdb;
3348
3349 //creo il file excel
3350 ?><html xmlns:o="urn:schemas-microsoft-com:office:office"
3351 xmlns:x="urn:schemas-microsoft-com:office:excel"
3352 xmlns="http://www.w3.org/TR/REC-html40">
3353 <head>
3354 <meta http-equiv=Content-Type content="text/html; charset=<?php echo get_option('blog_charset'); ?>" />
3355 <meta name=ProgId content=Excel.Sheet />
3356 <style>
3357 <!--
3358 td {vertical-align:top;}
3359 .head_row {font-weight:bold;}
3360 .column-date { mso-number-format:"Short Date"; }
3361 .datetime_cell { mso-number-format:"yyyy\\-mm\\-dd\\ hh\:mm\:ss"; }
3362 -->
3363 </style>
3364 <!--[if gte mso 9]><xml>
3365 <x:ExcelWorkbook>
3366 <x:ExcelWorksheets>
3367 <x:ExcelWorksheet>
3368 <x:WorksheetOptions>
3369 <x:FreezePanes/>
3370 <x:FilterOn/>
3371 <x:SplitHorizontal>1</x:SplitHorizontal>
3372 <x:TopRowBottomPane>1</x:TopRowBottomPane>
3373 <x:ActivePane>2</x:ActivePane>
3374 <x:Panes>
3375 <x:Pane>
3376 <x:Number>3</x:Number>
3377 </x:Pane>
3378 <x:Pane>
3379 <x:Number>2</x:Number>
3380 </x:Pane>
3381 </x:Panes>
3382 </x:WorksheetOptions>
3383 </x:ExcelWorksheet>
3384 </x:ExcelWorksheets>
3385 </x:ExcelWorkbook>
3386 </xml><![endif]-->
3387 </head>
3388 <body>
3389 <table x:str border=1 >
3390 <tr class='head-row'>
3391 <?php
3392 $cols = $listTable->get_columns();
3393 foreach($cols as $col_key=>$col_value) {
3394 if(in_array($col_key, $show_col)) { ?>
3395 <td x:autofilter="all"><?php echo $col_value; ?></td>
3396 <?php }
3397 } ?>
3398 </tr>
3399
3400 <?php
3401 /* gestire la data
3402 $ut_date = $result->date;
3403 $ut_date[10] = 'T';
3404 $ut_date.='.00+00:00';
3405 $excel_date = (strtotime($ut_date) / 86400 + 25569);
3406 $parts_date = explode('-', substr($result->date, 0, 10));
3407 $date = "{$parts_date[2]}/{$parts_date[1]}/{$parts_date[0]}";
3408 echo "<td class='column-date' x:num='$excel_date' SDVAL=\"$excel_date\" SDNUM=\"1033;0;DD/MM/YYYY\">$date</td>\n";
3409 */
3410 ?>
3411 <?php
3412
3413
3414 foreach($listTable->items as $id_submission=>$single_submission) {
3415 echo "<tr>";
3416 foreach($cols as $col_key=>$col_value) {
3417 if(in_array($col_key, $show_col)) {
3418 echo "<td class='.$col_key.'>";
3419 if(isset($single_submission[$col_key])) {
3420 if ( method_exists( $this, 'column_' . $column_name ) ) {
3421 echo call_user_func( array( &$listTable, 'column_' . $col_key ), $single_submission );
3422 }
3423 else {
3424 echo $listTable->column_default( $single_submission, $col_key );
3425 }
3426 }
3427 echo "</td>";
3428 }
3429
3430 }
3431 echo "</tr>";
3432 }
3433
3434 ?>
3435 </table>
3436 </body>
3437 </html>
3438 <?php
3439 }
3440
3441 function accua_forms_print_tokens() {
3442 $avail_fields = get_option('accua_forms_avail_fields', array());
3443 $tokens = '';
3444 foreach($avail_fields as $key=>$value) {
3445 $tokens .= $value['name'] . ": {" . $key . "}\n";
3446 switch ($value['type']) {
3447 case 'file':
3448 $tokens .= $value['name'] . " (download link): {__download_" . $key . "}\n";
3449 break;
3450 case 'multiselect':
3451 case 'multicheckbox':
3452 $tokens .= $value['name'] . " (labels): {__label_" . $key . "}\n";
3453 break;
3454 case 'select':
3455 case 'radio':
3456 $tokens .= $value['name'] . " (label): {__label_" . $key . "}\n";
3457 break;
3458 case 'post-multicheckbox':
3459 $tokens .= $value['name'] . " (posts titles): {__label_" . $key . "}\n";
3460 $tokens .= $value['name'] . " (posts ids): {__post_id_" . $key . "}\n";
3461 $tokens .= $value['name'] . " (posts urls): {__post_url_" . $key . "}\n";
3462 break;
3463 case 'post-select':
3464 $tokens .= $value['name'] . " (post title): {__label_" . $key . "}\n";
3465 $tokens .= $value['name'] . " (post id): {__post_id_" . $key . "}\n";
3466 $tokens .= $value['name'] . " (post url): {__post_url_" . $key . "}\n";
3467 break;
3468 }
3469 }
3470
3471 echo <<<EOT
3472 <div class="accua_forms_token_list">
3473 <h2>Tokens</h2>
3474 <em>In HTML text, use {!token_name} to insert unfiltered token value</em>
3475 <h3>Fields</h3>
3476 <em>These tokens are available only if the field is added to the form</em>
3477 <pre>$tokens</pre>
3478 <h3>Generic tokens</h3>
3479 <pre>{__fid}
3480 {__subid}
3481 {__pid}
3482 {__ip}
3483 {__uri}
3484 {__url}
3485 {__referrer}
3486 {__lang}
3487 {__locale}
3488 {__created}
3489 {__created_day}
3490 {__created_day_month_year}
3491 {__created_hour}
3492 {__submitted}
3493 {__submitted_day}
3494 {__submitted_day_month_year}
3495 {__submitted_hour}
3496 {__user_agent}
3497 {__platform}
3498 {__tentatives}
3499 {__submit_method}
3500 {__submitted_txt}
3501 {__submitted_html}
3502 {__submitted_json}
3503 {__autoreply}
3504 {__autoreply_email}
3505 {__confirmation_emails_message}</pre>
3506 </div>
3507 EOT;
3508 do_action('accua_forms_print_tokens');
3509 }
3510
3511 function &accua_get_pages($args = '') {
3512 global $wpdb;
3513
3514 $defaults = array(
3515 'child_of' => 0, 'sort_order' => 'ASC',
3516 'sort_column' => 'post_title', 'hierarchical' => 1,
3517 'exclude' => array(), 'include' => array(),
3518 'meta_key' => '', 'meta_value' => '',
3519 'meta_value_lt' => '', 'meta_value_gt' => '',
3520 'meta_value_le' => '', 'meta_value_ge' => '',
3521 'meta_value_like' => '', 'meta_value_format' => 'string',
3522 'authors' => '', 'parent' => -1, 'exclude_tree' => '',
3523 'number' => '', 'offset' => 0,
3524 'post_type' => 'page', 'post_status' => 'publish',
3525 );
3526
3527 $r = wp_parse_args( $args, $defaults );
3528 extract( $r, EXTR_SKIP );
3529 $number = (int) $number;
3530 $offset = (int) $offset;
3531
3532 /*
3533 // Make sure the post type is hierarchical
3534 $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
3535 if ( !in_array( $post_type, $hierarchical_post_types ) )
3536 return false;
3537 */
3538
3539 // Make sure we have a valid post type
3540 if ( !is_array( $post_type ) )
3541 $post_type = explode( ',', $post_type );
3542 if ( array_diff( $post_type, get_post_types() ) )
3543 return false;
3544
3545 // Make sure we have a valid post status
3546 if ( !is_array( $post_status ) )
3547 $post_status = explode( ',', $post_status );
3548 if ( array_diff( $post_status, get_post_stati() ) )
3549 return false;
3550
3551 /*
3552 $cache = array();
3553 $key = md5( serialize( compact(array_keys($defaults)) ) );
3554 if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) {
3555 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
3556 $pages = apply_filters('get_pages', $cache[ $key ], $r );
3557 return $pages;
3558 }
3559 }
3560
3561 if ( !is_array($cache) )
3562 $cache = array();
3563 */
3564
3565 $inclusions = '';
3566 if ( !empty($include) ) {
3567 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
3568 $parent = -1;
3569 $exclude = '';
3570 $meta_key = '';
3571 $meta_value = '';
3572 $meta_value_lt = '';
3573 $meta_value_gt = '';
3574 $meta_value_le = '';
3575 $meta_value_ge = '';
3576 $meta_value_like = '';
3577 $hierarchical = false;
3578 $incpages = wp_parse_id_list( $include );
3579 if ( ! empty( $incpages ) ) {
3580 foreach ( $incpages as $incpage ) {
3581 if (empty($inclusions))
3582 $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
3583 else
3584 $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
3585 }
3586 }
3587 }
3588 if (!empty($inclusions))
3589 $inclusions .= ')';
3590
3591 $exclusions = '';
3592 if ( !empty($exclude) ) {
3593 $expages = wp_parse_id_list( $exclude );
3594 if ( ! empty( $expages ) ) {
3595 foreach ( $expages as $expage ) {
3596 if (empty($exclusions))
3597 $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage);
3598 else
3599 $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage);
3600 }
3601 }
3602 }
3603 if (!empty($exclusions))
3604 $exclusions .= ')';
3605
3606 $author_query = '';
3607 if (!empty($authors)) {
3608 $post_authors = preg_split('/[\s,]+/',$authors);
3609
3610 if ( ! empty( $post_authors ) ) {
3611 foreach ( $post_authors as $post_author ) {
3612 //Do we have an author id or an author login?
3613 if ( 0 == intval($post_author) ) {
3614 $post_author = get_user_by('login', $post_author);
3615 if ( empty($post_author) )
3616 continue;
3617 if ( empty($post_author->ID) )
3618 continue;
3619 $post_author = $post_author->ID;
3620 }
3621
3622 if ( '' == $author_query )
3623 $author_query = $wpdb->prepare(' post_author = %d ', $post_author);
3624 else
3625 $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
3626 }
3627 if ( '' != $author_query )
3628 $author_query = " AND ($author_query)";
3629 }
3630 }
3631
3632 $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
3633 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
3634 'ID', 'rand', 'comment_count');
3635
3636 $join = '';
3637 $where = "$exclusions $inclusions ";
3638 if ( ! ( empty( $meta_key ) && empty( $meta_value )
3639 && empty( $meta_value_lt ) && empty( $meta_value_gt )
3640 && empty( $meta_value_le ) && empty( $meta_value_ge )
3641 && empty( $meta_value_like ) ) ) {
3642 $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
3643 $allowed_keys[] = 'meta_key';
3644 $allowed_keys[] = 'meta_value';
3645
3646 // meta_key and meta_value might be slashed
3647 $meta_key = stripslashes($meta_key);
3648 $meta_value = stripslashes($meta_value);
3649 $meta_value_lt = stripslashes($meta_value_lt);
3650 $meta_value_gt = stripslashes($meta_value_gt);
3651 $meta_value_le = stripslashes($meta_value_le);
3652 $meta_value_ge = stripslashes($meta_value_ge);
3653 $meta_value_like = stripslashes($meta_value_like);
3654
3655 if ( ! empty( $meta_key ) ) {
3656 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
3657 }
3658
3659 $meta_value_field = "$wpdb->postmeta.meta_value";
3660 $meta_value_timestamp = false;
3661 switch($meta_value_format) {
3662 case 'timestamp':
3663 $meta_value_field = "TIMESTAMP( $meta_value_field )";
3664 $meta_value_param = "FROM_UNIXTIME( %s )";
3665 $meta_value_timestamp = true;
3666 break;
3667 case 'int':
3668 $meta_value_param = "%d";
3669 break;
3670 case 'float':
3671 $meta_value_param = "%f";
3672 break;
3673 //case 'string':
3674 default:
3675 $meta_value_param = "%s";
3676 }
3677
3678 if ( ! empty( $meta_value ) ) {
3679 if ($meta_value_timestamp) {
3680 $meta_value = strtotime($meta_value);
3681 }
3682 $where .= $wpdb->prepare(" AND $meta_value_field = $meta_value_param", $meta_value);
3683 }
3684 if ( ! empty( $meta_value_lt ) ) {
3685 if ($meta_value_timestamp) {
3686 $meta_value_lt = strtotime($meta_value_lt);
3687 }
3688 $where .= $wpdb->prepare(" AND $meta_value_field < $meta_value_param", $meta_value_lt);
3689 }
3690 if ( ! empty( $meta_value_gt ) ) {
3691 if ($meta_value_timestamp) {
3692 $meta_value_gt = strtotime($meta_value_gt);
3693 }
3694 $where .= $wpdb->prepare(" AND $meta_value_field > $meta_value_param", $meta_value_gt);
3695 }
3696 if ( ! empty( $meta_value_le ) ) {
3697 if ($meta_value_timestamp) {
3698 $meta_value_le = strtotime($meta_value_le);
3699 }
3700 $where .= $wpdb->prepare(" AND $meta_value_field <= $meta_value_param", $meta_value_le);
3701 }
3702 if ( ! empty( $meta_value_ge ) ) {
3703 if ($meta_value_timestamp) {
3704 $meta_value_ge = strtotime($meta_value_ge);
3705 }
3706 $where .= $wpdb->prepare(" AND $meta_value_field >= $meta_value_param", $meta_value_ge);
3707 }
3708 if ( ! empty( $meta_value_like ) ) {
3709 if ($meta_value_timestamp) {
3710 $meta_value_like = strtotime($meta_value_like);
3711 }
3712 $where .= $wpdb->prepare(" AND $meta_value_field like $meta_value_param", $meta_value_like);
3713 }
3714 }
3715
3716 if ( $parent >= 0 )
3717 $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
3718
3719
3720 if ( 1 == count ( $post_type ) ) {
3721 $where_post_type = $wpdb->prepare( "post_type = %s", array_shift( $post_type ) );
3722 } else {
3723 $post_type = implode( "', '", $post_type );
3724 $where_post_type = "post_type IN ('$post_type')";
3725 }
3726
3727 if ( 1 == count( $post_status ) ) {
3728 $where_post_type .= $wpdb->prepare( " AND post_status = %s", array_shift( $post_status ) );
3729 } else {
3730 $post_status = implode( "', '", $post_status );
3731 $where_post_type .= " AND post_status IN ('$post_status')";
3732 }
3733
3734 $orderby_array = array();
3735 foreach ( explode( ',', $sort_column ) as $orderby ) {
3736 $orderby = trim( $orderby );
3737 if ( !in_array( $orderby, $allowed_keys ) )
3738 continue;
3739
3740 switch ( $orderby ) {
3741 case 'menu_order':
3742 break;
3743 case 'ID':
3744 $orderby = "$wpdb->posts.ID";
3745 break;
3746 case 'rand':
3747 $orderby = 'RAND()';
3748 break;
3749 case 'comment_count':
3750 $orderby = "$wpdb->posts.comment_count";
3751 break;
3752 case 'meta_key':
3753 case 'meta_value':
3754 $orderby = "$wpdb->postmeta.$orderby";
3755 break;
3756 default:
3757 if ( 0 === strpos( $orderby, 'post_' ) )
3758 $orderby = "$wpdb->posts." . $orderby;
3759 else
3760 $orderby = "$wpdb->posts.post_" . $orderby;
3761 }
3762
3763 $orderby_array[] = $orderby;
3764
3765 }
3766 $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title";
3767
3768 $sort_order = strtoupper( $sort_order );
3769 if ( '' !== $sort_order && !in_array( $sort_order, array( 'ASC', 'DESC' ) ) )
3770 $sort_order = 'ASC';
3771
3772 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
3773 $query .= $author_query;
3774 $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
3775
3776 if ( !empty($number) )
3777 $query .= ' LIMIT ' . $offset . ',' . $number;
3778
3779 //echo "<!-- accua_forms_query:\n$query\n-->";
3780
3781 $pages = $wpdb->get_results($query);
3782
3783 if ( empty($pages) ) {
3784 $pages = apply_filters('get_pages', array(), $r);
3785 return $pages;
3786 }
3787
3788 // Sanitize before caching so it'll only get done once
3789 $num_pages = count($pages);
3790 for ($i = 0; $i < $num_pages; $i++) {
3791 $pages[$i] = sanitize_post($pages[$i], 'raw');
3792 }
3793
3794 /*
3795 // Update cache.
3796 update_post_cache( $pages );
3797 */
3798
3799 if ( $child_of || $hierarchical )
3800 $pages = & get_page_children($child_of, $pages);
3801
3802 if ( !empty($exclude_tree) ) {
3803 $exclude = (int) $exclude_tree;
3804 $children = get_page_children($exclude, $pages);
3805 $excludes = array();
3806 foreach ( $children as $child )
3807 $excludes[] = $child->ID;
3808 $excludes[] = $exclude;
3809 $num_pages = count($pages);
3810 for ( $i = 0; $i < $num_pages; $i++ ) {
3811 if ( in_array($pages[$i]->ID, $excludes) )
3812 unset($pages[$i]);
3813 }
3814 }
3815
3816 /*
3817 $cache[ $key ] = $pages;
3818 wp_cache_set( 'get_pages', $cache, 'posts' );
3819 */
3820
3821 $pages = apply_filters('get_pages', $pages, $r);
3822
3823 return $pages;
3824 }
3825