PluginProbe
Contact Forms by Cimatti / 1.3.5
Contact Forms by Cimatti v1.3.5
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.3.5, at accua-forms.php

3,720 lines 161.5 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', 10, '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', 10, "accua_forms", 'accua_dashboard_page');
8
9 $form_edit_page = add_submenu_page('accua_forms', 'Forms', 'Forms', 10, "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'), 10, "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'), 10, "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'), 10, "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'), 10, "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); ?> ;
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?')), 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
1276 </div>
1277 <p></p>
1278 <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>
1279
1280 </div>
1281 <script>
1282 jQuery('input[type=radio]').change(function() {
1283 var name = jQuery(this).attr('name');
1284 if (jQuery(this).val() == '1') {
1285 jQuery('#'+name+' .defalut_message').hide();
1286 jQuery('#'+name+' .wp-editor-wrap').show();
1287 }
1288 else {
1289 if(jQuery(this).val() != '-1')
1290 jQuery('#'+name+' .defalut_message').show();
1291 else
1292 jQuery('#'+name+' .defalut_message').hide();
1293 jQuery('#'+name+' .wp-editor-wrap').hide();
1294 }
1295 });
1296
1297 jQuery('input[type=checkbox]').click(function() {
1298 var name = jQuery(this).attr('name');
1299 if (!this.checked) {
1300 jQuery('#'+name+' .default_value').show();
1301 jQuery('#'+name+' .accua_form_value, #'+name+' .wp-picker-container').hide();
1302 }
1303 else {
1304 jQuery('#'+name+' .default_value').hide();
1305 jQuery('#'+name+' .accua_form_value, #'+name+' .wp-picker-container').show();
1306 }
1307 });
1308
1309 jQuery(".token_link").click(function() {
1310 jQuery("#dialog_token").dialog("open");
1311 return false;
1312 });
1313
1314 //inizializzazione
1315 jQuery(document).ready(function($){
1316 $('#accua_form_preview_area_wrapper').resizable({handles: 's'});
1317 $('#accua_form_preview_area').css({
1318 'width': '100%',
1319 'height': '100%'
1320 });
1321 $.each(
1322 ['success_message','error_message','admin_emails_message','confirmation_emails_message'],
1323 function(i,key){
1324 var value = $('#accua_form_'+key+' .accua_form_check_override:checked').val();
1325 if(value!=undefined && value!=0) {
1326 if(value!=-1)
1327 jQuery('#accua_form_'+key+' .wp-editor-wrap').show();
1328 else
1329 jQuery('#accua_form_'+key+' .wp-editor-wrap').hide();
1330 jQuery('#accua_form_'+key+' .defalut_message').hide();
1331
1332 }
1333 else {
1334 jQuery('#accua_form_'+key+' .wp-editor-wrap').hide();
1335 jQuery('#accua_form_'+key+' .defalut_message').show();
1336 }
1337 }
1338 );
1339 $.each(
1340 ['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'],
1341 function(i,key){
1342 if(!$('#accua_form_'+key+' .accua_form_check_override').is(':checked')) {
1343 jQuery('#accua_form_'+key+' .default_value').show();
1344 jQuery('#accua_form_'+key+' .accua_form_value, #accua_form_'+key+' .wp-picker-container').hide();
1345 }
1346 else {
1347 jQuery('#accua_form_'+key+' .default_value').hide();
1348 jQuery('#accua_form_'+key+' .accua_form_value, #accua_form_'+key+' .wp-picker-container').show();
1349 }
1350 });
1351 $("#dialog_token").dialog({ dialogClass:'wp-dialog' ,autoOpen : false, modal : true, show : "blind", hide : "blind"});
1352
1353 $('#accua_token a').appendTo('.wp-media-buttons');
1354
1355 });
1356
1357 jQuery(document).ready(function($){
1358
1359 var originalWidth = $(document).width();
1360 if(originalWidth <= 883) { //iphone
1361 $(".metabox-holder").width('98%');
1362 }
1363
1364 $(window).resize(function (e) {
1365 var newWidth = $(document).width();
1366 if(newWidth <= 883) {
1367 if (originalWidth > 883) {
1368 $(".metabox-holder").width('98%');
1369 }
1370 } else if (originalWidth<=883) {
1371 $(".metabox-holder").width('47%');
1372 }
1373 originalWidth = newWidth;
1374 });
1375 });
1376
1377 </script>
1378
1379 <?php
1380 }
1381
1382 function accua_forms_fields_page_head() {
1383 /*
1384 $baseurl = WP_PLUGIN_URL.'/'.substr(plugin_basename(__FILE__),0,-strlen(basename(__FILE__)));
1385 ?>
1386 <script type="text/javascript" src="<?php echo $baseurl.'/qtip/jquery.qtip-1.0.0-rc3.js'; ?>"></script>
1387 <script type="text/javascript">
1388 var avail_fields = {
1389 first_name: {
1390 id: "first_name",
1391 name: "First Name",
1392 type: "textfield"
1393 },
1394 last_name: {
1395 id: "last_name",
1396 name: "Last Name",
1397 type: "textfield"
1398 },
1399 email: {
1400 id: "email",
1401 name: "Email",
1402 type: "email"
1403 }
1404 };
1405
1406 jQuery(function($){
1407 $avail = $('#available_fields_container');
1408 for(var id in avail_fields) {
1409 var field = avail_fields[id];
1410 var el = $('<div></div>').text(field.name);
1411 el.prepend('<input type="checkbox" />');
1412 var content = $('<div><span>Id: </span></div>');
1413 content.append($('<input type="text" />').val(field.id));
1414 content.append($('<br /><span>Name: </span>'));
1415 content.append($('<input type="text" />').val(field.name));
1416 content.append($('<br /><span>Type: </span>'));
1417 content.append($('<select><option value="textfield">Textfield</option><option value="textarea">Textarea</option><option value="email">Email</option></select>').val(field.type));
1418 el.qtip({
1419 content: {
1420 text: content
1421 },
1422 position: {
1423 target: 'mouse',
1424 corner: {
1425 target: 'bottomRight',
1426 tooltip: 'topLeft'
1427 },
1428 adjust: {
1429 mouse: false
1430 }
1431 },
1432 show: {
1433 when: {
1434 event: 'mouseover'
1435 },
1436 solo: true
1437 },
1438 hide: {
1439 when: {
1440 event: 'unfocus'
1441 }
1442 }
1443 });
1444 $avail.append(el);
1445 }
1446 });
1447 </script>
1448 <style type="text/css">
1449 .container > div {
1450 padding: 0px;
1451 margin-bottom: 6px;
1452 }
1453 </style>
1454 <?php
1455 */
1456 }
1457
1458 function accua_forms_fields_page() {
1459 /*
1460 ?>
1461 <div class="wrap"><h2>Edit Form Fields</h2>
1462 <div id="available_fields_container" class="container"></div>
1463 </div>
1464 <?php
1465 */
1466 $message = '';
1467
1468 /*
1469 $avail_fields = array(
1470 'first_name' => array (
1471 'id' => "first_name",
1472 'name' => "First Name",
1473 'type' => "textfield",
1474 'description' => 'This is the first name',
1475 ),
1476 'last_name' => array (
1477 'id' => "last_name",
1478 'name' => "Last Name",
1479 'type' => "textfield",
1480 'description' => 'This is the last name',
1481 ),
1482 'email' => array (
1483 'id' => "email",
1484 'name' => "Email",
1485 'type' => "email",
1486 'description' => 'This is the email',
1487 ),
1488 );
1489 */
1490
1491 $avail_fields = get_option('accua_forms_avail_fields', array());
1492
1493 $default_form_values = array(
1494 'id' => '',
1495 'name' => '',
1496 'type' => 'textfield',
1497 'description' => '',
1498 'default_value' => '',
1499 'allowed_values' => '',
1500 );
1501
1502 $editing = false;
1503 $adding = true;
1504
1505 if (!empty($_POST['action'])) {
1506 $post = stripslashes_deep($_POST);
1507 switch($post['action']) {
1508 case 'edit-form-field':
1509 if (empty($avail_fields[$post['form-field-id']])) {
1510 $message .= 'Field "'.htmlspecialchars($post['form-field-id']).'" doesn\'t exists';
1511 } else {
1512 if (empty($post['delete-field'])) {
1513 $avail_fields[$post['form-field-id']] = array(
1514 'id' => $post['form-field-id'],
1515 'name' => $post['form-field-name'],
1516 'type' => $post['form-field-type'],
1517 'description' => $post['form-field-description'],
1518 'default_value' => $post['form-field-default-value'],
1519 'allowed_values' => $post['form-field-allowed-values'],
1520 );
1521 $message .= sprintf( __( 'Field "%s" updated', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1522 } else {
1523 unset ($avail_fields[$post['form-field-id']]);
1524 $message .= sprintf( __( 'Field "%s" deleted', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1525 }
1526 update_option('accua_forms_avail_fields', $avail_fields);
1527 }
1528 break;
1529 case 'add-form-field':
1530 $fill_form_fields = true;
1531 $valid = true;
1532 if (empty($post['form-field-id']) || !preg_match('/^[a-z0-9_-]+$/i', $post['form-field-id'])) {
1533 $message .= "<p>".__( 'Only letters, numbers, hyphen and underscores allowed in field identificative slug', 'accua-form-api')."</p>";
1534 $valid = false;
1535 }
1536 if(substr($post['form-field-id'], 0, 2) == '__') {
1537 $message .= "<p>".__( 'The field identificative slug can\'t start with two underscores (__)', 'accua-form-api')."</p>";
1538 $valid = false;
1539 }
1540 if (!empty($avail_fields[$post['form-field-id']])) {
1541 $message .= sprintf( __( '<p>A field with identificative slug "%s" already exists</p> Field "%s" deleted', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1542 $valid = false;
1543 }
1544 if (strlen($post['form-field-id']) > 70) {
1545 $message .= "<p>".__( 'The identificative slug cannot be longer than 70 characters', 'accua-form-api')."</p>";
1546 $valid = false;
1547 }
1548 if ($valid) {
1549 $fill_form_fields = false;
1550 $avail_fields[$post['form-field-id']] = array(
1551 'id' => $post['form-field-id'],
1552 'name' => $post['form-field-name'],
1553 'type' => $post['form-field-type'],
1554 'description' => $post['form-field-description'],
1555 'default_value' => $post['form-field-default-value'],
1556 'allowed_values' => $post['form-field-allowed-values'],
1557 );
1558 update_option('accua_forms_avail_fields', $avail_fields);
1559 $message .= sprintf( __( 'Field "%s" created', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1560 }
1561 if ($fill_form_fields) {
1562 $editing = true;
1563 $default_form_values = array(
1564 'id' => $post['form-field-id'],
1565 'name' => $post['form-field-name'],
1566 'type' => $post['form-field-type'],
1567 'description' => $post['form-field-description'],
1568 'default_value' => $post['form-field-default-value'],
1569 'allowed_values' => $post['form-field-allowed-values'],
1570 );
1571 }
1572 break;
1573 }
1574 } else if (!empty($_GET['edit-fid'])) {
1575 $fid = stripslashes($_GET['edit-fid']);
1576 if (empty($avail_fields[$fid])) {
1577 $message .= sprintf( __( 'Field "%s" doesn\'t exists', 'accua-form-api'), $fid );
1578 } else {
1579 $adding = false;
1580 $editing = true;
1581 $default_form_values = $avail_fields[$fid];
1582 }
1583 }
1584
1585 ?>
1586 <div id="accua_forms_fields_page" class="accua_forms_admin_page wrap nosubsub">
1587 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
1588 <h2><?php _e( 'Form fields', 'accua-form-api'); ?></h2>
1589 <?php /* screen_icon(); ?>
1590 <h2><?php echo esc_html( $title );
1591 if ( !empty($_REQUEST['s']) )
1592 printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?>
1593 </h2>
1594
1595 <?php if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) ) : ?>
1596 <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
1597 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
1598 endif; */ ?>
1599 <div id="ajax-response"><?php echo $message?></div>
1600
1601 <?php /*
1602 <form class="search-form" action="" method="get">
1603 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1604 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1605
1606 <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
1607
1608 </form>
1609 */ ?>
1610
1611 <br class="clear" />
1612
1613 <div id="col-container">
1614
1615 <div id="col-right">
1616 <div class="col-wrap">
1617 <?php if (!$editing) { ?>
1618 <form id="posts-filter" action="" method="post">
1619 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1620 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1621
1622 <?php /* $wp_list_table->display(); */ ?>
1623
1624 <table cellspacing="0" class="wp-list-table widefat fixed tags">
1625 <thead>
1626 <tr>
1627 <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox" /></th>
1628 <th style="" class="manage-column column-name" id="name" scope="col"><?php _e( 'Label', 'accua-form-api'); ?></th>
1629 <th style="" class="manage-column column-description" id="description" scope="col"><?php _e( 'Description', 'accua-form-api'); ?></th>
1630 <th style="" class="manage-column column-slug" id="slug" scope="col"><?php _e( 'Slug', 'accua-form-api'); ?></th>
1631 <th style="" class="manage-column column-type" id="type" scope="col"><?php _e( 'Type', 'accua-form-api'); ?></th>
1632 </tr>
1633 </thead>
1634
1635 <tfoot>
1636 <tr>
1637 <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox" /></th>
1638 <th style="" class="manage-column column-name" scope="col"><?php _e( 'Label', 'accua-form-api'); ?></th>
1639 <th style="" class="manage-column column-description" scope="col"><?php _e( 'Description', 'accua-form-api'); ?></th>
1640 <th style="" class="manage-column column-slug" scope="col"><?php _e( 'Slug', 'accua-form-api'); ?></th>
1641 <th style="" class="manage-column column-type" scope="col"><?php _e( 'Type', 'accua-form-api'); ?></th>
1642 </tr>
1643 </tfoot>
1644
1645 <tbody class="list:tag" id="the-list">
1646 <?php
1647 foreach ($avail_fields as $id => $field) {
1648 foreach (array('id', 'name', 'type', 'description') as $i) {
1649 $field[$i] = htmlspecialchars($field[$i], ENT_QUOTES);
1650 }
1651 echo <<<END_OF_ROW
1652 <tr id="field-{$field['id']}">
1653 <th class="check-column" scope="row"><input type="checkbox" /></th>
1654 <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>
1655 <td class="description column-description">{$field['description']}</td>
1656 <td class="slug column-slug">{$field['id']}</td>
1657 <td class="type column-type">{$field['type']}</td>
1658 </tr>
1659 END_OF_ROW;
1660 }
1661 ?>
1662 </tbody>
1663 </table>
1664
1665 <br class="clear" />
1666 </form>
1667 <?php } ?>
1668 <?php /* if ( 'category' == $taxonomy ) : ?>
1669 <div class="form-wrap">
1670 <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>
1671 <?php if ( current_user_can( 'import' ) ) : ?>
1672 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
1673 <?php endif; ?>
1674 </div>
1675 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
1676 <div class="form-wrap">
1677 <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>'), 'import.php') ;?>.</p>
1678 </div>
1679 <?php endif;
1680 do_action('after-' . $taxonomy . '-table', $taxonomy);
1681 */ ?>
1682
1683 </div>
1684 </div><!-- /col-right -->
1685
1686 <div id="col-left">
1687 <div class="col-wrap">
1688
1689 <?php
1690 /*
1691 if ( !is_null( $tax->labels->popular_items ) ) {
1692 if ( current_user_can( $tax->cap->edit_terms ) )
1693 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
1694 else
1695 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
1696
1697 if ( $tag_cloud ) :
1698 ?>
1699 <div class="tagcloud">
1700 <h3><?php echo $tax->labels->popular_items; ?></h3>
1701 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
1702 </div>
1703 <?php
1704 endif;
1705 }
1706 */
1707
1708 /*
1709 if ( current_user_can($tax->cap->edit_terms) ) {
1710 // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form
1711 if ( 'category' == $taxonomy )
1712 do_action('add_category_form_pre', (object)array('parent' => 0) );
1713 elseif ( 'link_category' == $taxonomy )
1714 do_action('add_link_category_form_pre', (object)array('parent' => 0) );
1715 else
1716 do_action('add_tag_form_pre', $taxonomy);
1717
1718 do_action($taxonomy . '_pre_add_form', $taxonomy);
1719 */
1720
1721 $types = array(
1722 'textfield' => __( 'Text Field', 'accua-form-api'),
1723 'textarea' => __( 'Text Area', 'accua-form-api'),
1724 'email' => __( 'Email', 'accua-form-api'),
1725 'autoreply_email' => __( 'Autoreply Email', 'accua-form-api'),
1726 'checkbox' => __( 'Checkbox','accua-form-api'),
1727 'select' => __('Select', 'accua-form-api'),
1728 'radio' => __( 'Radio buttons', 'accua-form-api'),
1729 'multiselect' => __( 'Multiple selections area', 'accua-form-api'),
1730 'multicheckbox' => __( 'Multiple checkboxes', 'accua-form-api'),
1731 'post-select' => __( 'Post select', 'accua-form-api'),
1732 'post-multicheckbox' => __( 'Multiple post checkboxes', 'accua-form-api'),
1733 'colorpicker' => __( 'Color picker', 'accua-form-api'),
1734 'hidden' => __('Hidden value', 'accua-form-api'),
1735 'file' => __('File upload', 'accua-form-api'),
1736 'submit' => __( 'Submit button', 'accua-form-api'),
1737 'html' => __( 'Custom HTML', 'accua-form-api'),
1738 'captcha' => __( 'Captcha', 'accua-form-api'),
1739 'password' => 'Password',
1740 'password-and-confirm' => __( 'Password and password confirmation','accua-form-api'),
1741 );
1742
1743
1744 ?>
1745 <div class="form-wrap">
1746 <h3><?php echo $adding? __( 'Add new field','accua-form-api'): __( 'Edit field','accua-form-api') ; ?></h3>
1747 <form id="addtag" method="post" action="admin.php?page=accua_forms_fields" class="validate">
1748 <input type="hidden" name="action" value="<?php echo $adding?'add':'edit'; ?>-form-field" />
1749 <?php /*
1750 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
1751 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1752 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1753 */ ?>
1754 <?php wp_nonce_field('add-tag', '_wpnonce_add-form-field'); ?>
1755
1756 <div class="form-field form-required">
1757 <label for="tag-name"><?php _e( 'Field label', 'accua-form-api'); ?></label>
1758 <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" />
1759 <p><?php _e('The name is how it appears on your site.', 'accua-form-api'); ?></p>
1760 </div>
1761 <?php /* if ( ! global_terms_enabled() ) : */ ?>
1762 <div class="form-field">
1763 <label for="tag-slug"><?php _e( 'Field slug (identificative)', 'accua-form-api'); ?></label>
1764 <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" />
1765 <?php if (!$adding) { echo '<input type="hidden" name="form-field-id" value="'.htmlspecialchars($default_form_values['id'], ENT_QUOTES).'" />'; } ?>
1766 <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>
1767 </div>
1768 <div class="form-field">
1769 <label for="parent"><?php _e( 'Field type', 'accua-form-api'); ?></label>
1770 <select class="postform" id="parent" name="form-field-type">
1771 <?php /*
1772 <option value="textfield" class="level-0" <?php echo ($default_form_values['type'] == 'textfield')?'selected="selected"':'';?> >Text Field</option>
1773 <option value="textarea" class="level-0" <?php echo ($default_form_values['type'] == 'textarea')?'selected="selected"':'';?> >Text Area</option>
1774 <option value="email" class="level-0" <?php echo ($default_form_values['type'] == 'email')?'selected="selected"':'';?> >Email</option>
1775 <option value="checkbox" class="level-0" <?php echo ($default_form_values['type'] == 'checkbox')?'selected="selected"':'';?> >Checkbox</option>
1776 <option value="select" class="level-0" <?php echo ($default_form_values['type'] == 'select')?'selected="selected"':'';?> >Select</option>
1777 */
1778 foreach ($types as $typeid => $typename) {
1779 $selected = ($default_form_values['type'] == $typeid)?'selected="selected"':'';
1780 echo <<<EOT
1781 <option value="{$typeid}" class="level-0" {$selected} >{$typename}</option>
1782 EOT;
1783 }
1784
1785 ?>
1786 </select>
1787 </div>
1788 <?php /* endif; // global_terms_enabled() */ ?>
1789 <?php /* if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
1790 <div class="form-field">
1791 <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
1792 <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
1793 <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
1794 <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>
1795 <?php endif; ?>
1796 </div>
1797 <?php endif; // is_taxonomy_hierarchical() */ ?>
1798 <div class="form-field">
1799 <label for="tag-description"><?php _e( 'Field description', 'accua-form-api'); ?></label>
1800 <textarea name="form-field-description" id="tag-description" rows="5" cols="40"><?php echo htmlspecialchars($default_form_values['description'], ENT_QUOTES) ?></textarea>
1801 <p><?php _e('The description is not prominent by default; however, some themes may show it.', 'accua-form-api'); ?></p>
1802 </div>
1803
1804 <div class="form-field">
1805 <label for="form-field-default-value"><?php _e( 'Default value(s)', 'accua-form-api'); ?>:</label>
1806 <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>
1807 <p><?php _e( 'For multiple default values in multiple select and multiple checkboxes, use | as separator.', 'accua-form-api'); ?></p>
1808 </div>
1809
1810 <div class="form-field">
1811 <label for="form-field-allowed-values"><?php _e( 'Allowed values', 'accua-form-api'); ?>:</label>
1812 <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>
1813 <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>
1814 </div>
1815
1816
1817 <?php
1818 /*
1819 if ( ! is_taxonomy_hierarchical($taxonomy) )
1820 do_action('add_tag_form_fields', $taxonomy);
1821 do_action($taxonomy . '_add_form_fields', $taxonomy);
1822 */
1823
1824 if ($adding) {
1825 submit_button( __( 'Add new field', 'accua-form-api'), 'button' );
1826 } else {
1827 submit_button( __( 'Save changes', 'accua-form-api'), 'button' );
1828 submit_button( __( 'Delete field', 'accua-form-api'), 'button', 'delete-field');
1829 }
1830
1831 /*
1832 // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form
1833 if ( 'category' == $taxonomy )
1834 do_action('edit_category_form', (object)array('parent' => 0) );
1835 elseif ( 'link_category' == $taxonomy )
1836 do_action('edit_link_category_form', (object)array('parent' => 0) );
1837 else
1838 do_action('add_tag_form', $taxonomy);
1839
1840 do_action($taxonomy . '_add_form', $taxonomy);
1841 */
1842 ?>
1843 </form></div>
1844 <?php /* } */ ?>
1845
1846 </div>
1847 </div><!-- /col-left -->
1848
1849 </div><!-- /col-container -->
1850 </div><!-- /wrap -->
1851 <?php
1852 /* echo '<pre>accua_forms_avail_fields:', htmlspecialchars(print_r($avail_fields, true)), '</pre>'; */
1853 }
1854
1855 function accua_forms_settings_page() {
1856 ?>
1857 <div id="accua_forms_settings_page" class="accua_forms_admin_page wrap">
1858 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
1859 <h2><?php _e( 'Default Form settings', 'accua-form-api'); ?></h2>
1860 <?php
1861 $empty_form_data = array(
1862 'success_message' => '',
1863 'error_message' => '',
1864 'emails_from_name' => '',
1865 'emails_from' => '',
1866 'admin_emails_to' => '',
1867 'emails_bcc' => '',
1868 'admin_emails_subject' => '',
1869 'admin_emails_message' => '',
1870 'confirmation_emails_subject' => '',
1871 'confirmation_emails_message' => '',
1872 'layout' => 'sidebyside',
1873 'style_margin' => '',
1874 'style_border_color' => '',
1875 'style_border_width' => '',
1876 'style_border_radius' => '',
1877 'style_background_color' => '',
1878 'style_padding' => '',
1879 'style_color' => '',
1880 'style_font_size' => '',
1881 'style_field_spacing' => '',
1882 'style_field_border_color' => '',
1883 'style_field_border_width' => '',
1884 'style_field_border_radius' => '',
1885 'style_field_background_color' => '',
1886 'style_field_padding' => '',
1887 'style_field_color' => '',
1888 'style_submit_border_color' => '',
1889 'style_submit_border_width' => '',
1890 'style_submit_border_radius' => '',
1891 'style_submit_background_color' => '',
1892 'style_submit_padding' => '',
1893 'style_submit_color' => '',
1894 'style_submit_font_size' => '',
1895 );
1896
1897 $empty_file_data = array(
1898 'valid_extensions' => '',
1899 'max_size' => '',
1900 'dest_path' => '',
1901 );
1902
1903 if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['accua_form_save_form_settings'])) {
1904 $post = stripslashes_deep($_POST);
1905 $post += $empty_form_data;
1906 $post += $empty_file_data;
1907 $form_data = array();
1908 $file_data = array();
1909 foreach($empty_form_data as $key=>$val){
1910 $form_data[$key] = $post[$key];
1911 }
1912 foreach($empty_file_data as $key=>$val){
1913 $file_data[$key] = $post[$key];
1914 }
1915
1916
1917
1918 update_option('accua_forms_default_form_data', $form_data);
1919 update_option('accua_forms_default_file_field_data', $file_data);
1920 } else {
1921 $form_data = get_option('accua_forms_default_form_data',array()) + $empty_form_data;
1922 $file_data = get_option('accua_forms_default_file_field_data',array()) + $empty_file_data;
1923 }
1924 ?>
1925 <form method="post">
1926 <input type="hidden" name="accua_form_save_form_settings" value="1" />
1927 <?php /*
1928 <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>
1929 <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>
1930 <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>
1931 <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>
1932 <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>
1933 <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>
1934 <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>
1935 <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>
1936 <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>
1937 <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>
1938 */ ?>
1939 <div id="accua_tab_messages" class="content_tab">
1940 <?php
1941 $settings_editor = array(
1942 'teeny' => true,
1943 'editor_class' => 'accua_form_value',
1944 'tinymce' => array(
1945 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,'));
1946 ?>
1947 <div class="metabox-holder accua-forms-metabox-holder">
1948 <div class="postbox ">
1949 <h3 class="hndle"><span><?php _e('1. On-screen success message', 'accua-form-api'); ?></span></h3>
1950 <div class="inside" id="dashboard_right_now">
1951 <div id="accua_form_success_message">
1952 <?php wp_editor( $form_data['success_message'] , 'success_message' , $settings_editor); ?>
1953 </div>
1954 </div>
1955 </div>
1956 </div>
1957
1958 <div class="metabox-holder accua-forms-metabox-holder">
1959 <div class="postbox ">
1960 <h3 class="hndle"><span><?php _e('2. On-screen error message', 'accua-form-api'); ?></span></h3>
1961 <div class="inside" id="dashboard_right_now">
1962 <div id="accua_form_error_message">
1963 <?php wp_editor( $form_data['error_message'] , 'error_message' , $settings_editor); ?>
1964 </div>
1965 </div>
1966 </div>
1967 </div>
1968 <br clear="all"/>
1969 <div class="metabox-holder accua-forms-metabox-holder">
1970 <div class="postbox ">
1971 <h3 class="hndle"><span><?php _e('3. Email to notify administrator', 'accua-form-api'); ?></span></h3>
1972 <div class="inside" id="dashboard_right_now">
1973 <div id="accua_form_admin_emails_to" class="label_input">
1974 <label><?php _e( 'To', 'accua-form-api'); ?></label>
1975 <input name="admin_emails_to" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_to'], ENT_QUOTES) ?>" />
1976 </div>
1977 <br clear="all" />
1978 <div id="accua_form_emails_bcc" class="label_input">
1979 <label><?php _e( 'Bcc', 'accua-form-api'); ?></label>
1980 <input name="emails_bcc" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_bcc'], ENT_QUOTES) ?>" />
1981 </div>
1982 <br clear="all" />
1983 <div id="accua_form_admin_emails_subject" class="label_input">
1984 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
1985 <input name="admin_emails_subject" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_subject'], ENT_QUOTES) ?>" />
1986 </div>
1987 <br clear="all" />
1988 <div id="accua_form_admin_emails_message">
1989 <?php wp_editor( $form_data['admin_emails_message'] , 'admin_emails_message' , $settings_editor); ?>
1990 </div>
1991
1992 </div>
1993 </div>
1994 </div>
1995
1996 <div class="metabox-holder accua-forms-metabox-holder">
1997 <div class="postbox ">
1998 <h3 class="hndle"><span><?php _e('4. Email confirmation to the person who completed the form', 'accua-form-api'); ?></span></h3>
1999 <div class="inside" id="dashboard_right_now">
2000 <div id="accua_form_emails_from_name" class="label_input">
2001 <label><?php _e( 'From name', 'accua-form-api'); ?></label>
2002 <input class="accua_form_value" name="emails_from_name" type="text" value="<?php echo htmlspecialchars($form_data['emails_from_name'], ENT_QUOTES) ?>" />
2003 </div>
2004 <div id="accua_form_emails_from" class="label_input">
2005 <label><?php _e( 'From email', 'accua-form-api'); ?></label>
2006 <input class="accua_form_value" name="emails_from" type="text" value="<?php echo htmlspecialchars($form_data['emails_from'], ENT_QUOTES) ?>" />
2007 </div>
2008 <br clear="all" />
2009 <div id="accua_form_confirmation_emails_subject" class="label_input">
2010 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
2011 <input class="accua_form_value" type="text" name="confirmation_emails_subject" value="<?php echo htmlspecialchars($form_data['confirmation_emails_subject'], ENT_QUOTES) ?>" />
2012 </div>
2013 <br clear="all" />
2014 <div id="accua_form_confirmation_emails_message">
2015 <?php wp_editor( $form_data['confirmation_emails_message'] , 'confirmation_emails_message' , $settings_editor); ?>
2016 </div>
2017 </div>
2018 </div>
2019 </div>
2020 <br clear="all"/>
2021
2022 <div class="metabox-holder accua-forms-metabox-holder">
2023 <div class="postbox ">
2024 <h3 class="hndle"><span><?php _e( 'File upload default settings', 'accua-form-api'); ?></span></h3>
2025 <div class="inside" id="dashboard_right_now">
2026 <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>
2027 <small><?php _e( 'List of valid extensions, without dot, one per line.', 'accua-form-api'); ?></small>
2028 </div>
2029 <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 />
2030 <small><?php _e( 'You can use suffix K, M or G for kilobyte, megabyte or gigabyte.', 'accua-form-api'); ?>
2031 <?php
2032 $server_max_size = AccuaForm_Element_File::file_upload_max_size();
2033 if ($server_max_size > 0) {
2034 _e( 'This value is limited by server upload limits of ', 'accua-form-api');
2035 echo AccuaForm_Element_File::format_size($server_max_size).". ";
2036 _e( 'If you need a greater limit you should ask to the server administrator.', 'accua-form-api');
2037 }
2038 ?>
2039 </small>
2040 </div>
2041 <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) ?>" />
2042 <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>
2043 </div>
2044 </div>
2045 </div>
2046 </div>
2047
2048 <div class="metabox-holder accua-forms-metabox-holder">
2049 <div class="postbox ">
2050 <h3 class="hndle"><span><?php _e( 'Layout &amp; Styling', 'accua-form-api'); ?></span></h3>
2051 <div class="inside" id="dashboard_right_now">
2052 <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>
2053 <h4><?php _e( 'Forms', 'accua-form-api'); ?></h4>
2054 <div id="accua_form_layout"> <?php _e( 'Layout', 'accua-form-api'); ?>
2055 <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>
2056 </div>
2057 <div id="accua_form_style_margin" class="label_input">
2058 <label><?php _e( 'Margin', 'accua-form-api'); ?></label>
2059 <input name="style_margin" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_margin'], ENT_QUOTES) ?>" />
2060 </div>
2061 <div id="accua_form_style_border_color" class="label_input">
2062 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2063 <input name="style_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_color'], ENT_QUOTES) ?>" />
2064 </div>
2065 <div id="accua_form_style_border_width" class="label_input">
2066 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2067 <input name="style_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_width'], ENT_QUOTES) ?>" />
2068 </div>
2069 <div id="accua_form_style_border_radius" class="label_input">
2070 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2071 <input name="style_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_radius'], ENT_QUOTES) ?>" />
2072 </div>
2073 <div id="accua_form_style_background_color" class="label_input">
2074 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2075 <input name="style_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_background_color'], ENT_QUOTES) ?>" />
2076 </div>
2077 <div id="accua_form_style_padding" class="label_input">
2078 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2079 <input name="style_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_padding'], ENT_QUOTES) ?>" />
2080 </div>
2081 <div id="accua_form_style_color" class="label_input">
2082 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2083 <input name="style_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_color'], ENT_QUOTES) ?>" />
2084 </div>
2085 <div id="accua_form_style_font_size" class="label_input">
2086 <label><?php _e( 'Font size', 'accua-form-api'); ?></label>
2087 <input name="style_font_size" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_font_size'], ENT_QUOTES) ?>" />
2088 </div>
2089
2090 <h4><?php _e( 'Fields', 'accua-form-api'); ?></h4>
2091 <div id="accua_form_style_field_spacing" class="label_input">
2092 <label><?php _e( 'Spacing', 'accua-form-api'); ?></label>
2093 <input name="style_field_spacing" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_spacing'], ENT_QUOTES) ?>" />
2094 </div>
2095 <div id="accua_form_style_field_border_color" class="label_input">
2096 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2097 <input name="style_field_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_color'], ENT_QUOTES) ?>" />
2098 </div>
2099 <div id="accua_form_style_field_border_width" class="label_input">
2100 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2101 <input name="style_field_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_width'], ENT_QUOTES) ?>" />
2102 </div>
2103 <div id="accua_form_style_field_border_radius" class="label_input">
2104 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2105 <input name="style_field_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_radius'], ENT_QUOTES) ?>" />
2106 </div>
2107 <div id="accua_form_style_field_background_color" class="label_input">
2108 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2109 <input name="style_field_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_background_color'], ENT_QUOTES) ?>" />
2110 </div>
2111 <div id="accua_form_style_field_padding" class="label_input">
2112 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2113 <input name="style_field_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_padding'], ENT_QUOTES) ?>" />
2114 </div>
2115 <div id="accua_form_style_field_color" class="label_input">
2116 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2117 <input name="style_field_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_color'], ENT_QUOTES) ?>" />
2118 </div>
2119
2120 <h4><?php _e( 'Submit button', 'accua-form-api'); ?></h4>
2121 <div id="accua_form_style_submit_border_color" class="label_input">
2122 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2123 <input name="style_submit_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_color'], ENT_QUOTES) ?>" />
2124 </div>
2125 <div id="accua_form_style_submit_border_width" class="label_input">
2126 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2127 <input name="style_submit_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_width'], ENT_QUOTES) ?>" />
2128 </div>
2129 <div id="accua_form_style_submit_border_radius" class="label_input">
2130 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2131 <input name="style_submit_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_radius'], ENT_QUOTES) ?>" />
2132 </div>
2133 <div id="accua_form_style_submit_background_color" class="label_input">
2134 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2135 <input name="style_submit_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_background_color'], ENT_QUOTES) ?>" />
2136 </div>
2137 <div id="accua_form_style_submit_padding" class="label_input">
2138 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2139 <input name="style_submit_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_padding'], ENT_QUOTES) ?>" />
2140 </div>
2141 <div id="accua_form_style_submit_color" class="label_input">
2142 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2143 <input name="style_submit_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_color'], ENT_QUOTES) ?>" />
2144 </div>
2145 <div id="accua_form_style_submit_font_size" class="label_input">
2146 <label><?php _e( 'Font size', 'accua-form-api'); ?></label>
2147 <input name="style_submit_font_size" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_font_size'], ENT_QUOTES) ?>" />
2148 </div>
2149 <br clear="all" />
2150 </div>
2151 </div>
2152 </div>
2153
2154
2155 <br clear="all"/>
2156
2157 </div>
2158
2159 <?php /*
2160 <h3><?php _e( 'File upload default settings', 'accua-form-api'); ?></h3>
2161 <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>
2162 <small><?php _e( 'List of valid extensions, without dot, one per line.', 'accua-form-api'); ?></small>
2163 </p>
2164 <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 />
2165 <small><?php _e( 'You can use suffix K, M or G for kilobyte, megabyte or gigabyte.', 'accua-form-api'); ?>
2166 <?php
2167 $server_max_size = AccuaForm_Element_File::file_upload_max_size();
2168 if ($server_max_size > 0) {
2169 _e( 'This value is limited by server upload limits of ', 'accua-form-api');
2170 echo AccuaForm_Element_File::format_size($server_max_size).". ";
2171 _e( 'If you need a greater limit you should ask to the server administrator.', 'accua-form-api');
2172 }
2173 ?>
2174 </small></p>
2175 <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) ?>" />
2176 <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>
2177 </p> */ ?>
2178 <p><input class="button button-primary button-large" id="accua_form_save_settings" type="submit" value="Save settings" /></p>
2179 </form>
2180 </div>
2181
2182 <script type='text/javascript'>
2183 jQuery(function($) {
2184 $('#accua_form_style_border_color .accua_form_value').wpColorPicker();
2185 $('#accua_form_style_background_color .accua_form_value').wpColorPicker();
2186 $('#accua_form_style_color .accua_form_value').wpColorPicker();
2187 $('#accua_form_style_field_border_color .accua_form_value').wpColorPicker();
2188 $('#accua_form_style_field_background_color .accua_form_value').wpColorPicker();
2189 $('#accua_form_style_field_color .accua_form_value').wpColorPicker();
2190 $('#accua_form_style_submit_border_color .accua_form_value').wpColorPicker();
2191 $('#accua_form_style_submit_background_color .accua_form_value').wpColorPicker();
2192 $('#accua_form_style_submit_color .accua_form_value').wpColorPicker();
2193 });
2194 </script>
2195
2196 <?php
2197 }
2198
2199 function _accua_forms_get_abs_dest_path($dest_path = '') {
2200 if ($dest_path === '') {
2201 return realpath(ABSPATH) . '/wp-content/uploads/accua-forms';
2202 } else if (substr($dest_path,0,1) === '/') {
2203 return $dest_path;
2204 } else {
2205 return realpath(ABSPATH) . '/' . $dest_path;
2206 }
2207 }
2208
2209 function _accua_forms_get_form_data($fid = false, $return_empty = true, $restore_trash = false){
2210 $empty_form_data = array(
2211 'fields' => array(),
2212 'title' => '',
2213 'success_message' => '',
2214 'error_message' => '',
2215 'emails_from_name' => '',
2216 'emails_from' => '',
2217 'admin_emails_to' => '',
2218 'emails_bcc' => '',
2219 'admin_emails_subject' => '',
2220 'admin_emails_message' => '',
2221 'confirmation_emails_subject' => '',
2222 'confirmation_emails_message' => '',
2223 'use_ajax' => true,
2224 'layout' => 'sidebyside',
2225 'style_margin' => '',
2226 'style_border_color' => '',
2227 'style_border_width' => '',
2228 'style_border_radius' => '',
2229 'style_background_color' => '',
2230 'style_padding' => '',
2231 'style_color' => '',
2232 'style_font_size' => '',
2233 'style_field_spacing' => '',
2234 'style_field_border_color' => '',
2235 'style_field_border_width' => '',
2236 'style_field_border_radius' => '',
2237 'style_field_background_color' => '',
2238 'style_field_padding' => '',
2239 'style_field_color' => '',
2240 'style_submit_border_color' => '',
2241 'style_submit_border_width' => '',
2242 'style_submit_border_radius' => '',
2243 'style_submit_background_color' => '',
2244 'style_submit_padding' => '',
2245 'style_submit_color' => '',
2246 'style_submit_font_size' => '',
2247 );
2248
2249 if ($fid === false) {
2250 return $empty_form_data;
2251 }
2252
2253 $default_form_data = get_option('accua_forms_default_form_data',array());
2254
2255 if ($fid === null) {
2256 return $default_form_data + $empty_form_data;
2257 }
2258
2259 $forms_data = get_option('accua_forms_saved_forms', array());
2260 if ($restore_trash) {
2261 $trash_data = get_option('accua_forms_trash_forms', array());
2262 if (isset($trash_data[$fid])) {
2263 $forms_data[$fid] = $trash_data[$fid];
2264 update_option('accua_forms_saved_forms', $forms_data);
2265 unset($trash_data[$fid]);
2266 update_option('accua_forms_trash_forms', $trash_data);
2267 }
2268 }
2269
2270 if (isset($forms_data[$fid])) {
2271 $form_data = array(
2272 '_overrided' => $forms_data[$fid]
2273 ) + $forms_data[$fid] + $default_form_data + $empty_form_data;
2274 /*
2275 if ($form_data['fields']) {
2276 foreach ($form_data['fields'] as $i => $istance_data) {
2277 // TODO: popuplate default fields data?
2278 }
2279 }
2280 */
2281 return $form_data;
2282 } else if ($return_empty) {
2283 return array(
2284 '_overrided' => array()
2285 ) + $default_form_data + $empty_form_data;
2286 } else {
2287 return null;
2288 }
2289
2290 }
2291
2292 function _accua_forms_style_parameters($params) {
2293 $ret = '';
2294 foreach ($params as $key => $value) {
2295 $value = trim($value);
2296 if ($value !== '') {
2297 if (is_numeric($value)) {
2298 $ret .= "{$key}:{$value}px;";
2299 } else {
2300 $ret .= "{$key}:{$value};";
2301 }
2302 if ($key == 'border-width') {
2303 $ret .= "border-style:solid;";
2304 }
2305 }
2306 }
2307 return $ret;
2308 }
2309
2310 add_action('accua_form_alter', 'accua_forms_form_generate', -999, 2);
2311 function accua_forms_form_generate($baseid, $form) {
2312 if (substr($baseid, 0, 14) == '__accua-form__') {
2313 $fid = substr($baseid,14);
2314 $form_data = _accua_forms_get_form_data($fid, false);
2315 /*
2316 echo '<!-- fid = ';
2317 print_r($fid);
2318 echo "\n\nform_data = ";
2319 print_r($form_data);
2320 echo "\n-->";
2321 */
2322 if ($form_data) {
2323 $form_style = _accua_forms_style_parameters(array(
2324 'margin' => $form_data['style_margin'],
2325 'border-color' => $form_data['style_border_color'],
2326 'border-width' => $form_data['style_border_width'],
2327 'border-radius' => $form_data['style_border_radius'],
2328 'background' => $form_data['style_background_color'],
2329 'padding' => $form_data['style_padding'],
2330 'color' => $form_data['style_color'],
2331 'font-size' => $form_data['style_font_size'],
2332 ));
2333
2334 $field_style = _accua_forms_style_parameters(array(
2335 'margin-bottom' => $form_data['style_field_spacing'],
2336 'border-color' => $form_data['style_field_border_color'],
2337 'border-width' => $form_data['style_field_border_width'],
2338 'border-radius' => $form_data['style_field_border_radius'],
2339 'background' => (trim($form_data['style_field_background_color']) === '')?'transparent':$form_data['style_field_background_color'],
2340 'padding' => $form_data['style_field_padding'],
2341 'color' => (trim($form_data['style_field_color']) === '')?$form_data['style_color']:$form_data['style_field_color'],
2342 'font-size' => $form_data['style_font_size'],
2343 ));
2344 $field_properties = array();
2345 if ($field_style !== '') {
2346 $field_properties['style'] = $field_style;
2347 }
2348
2349 $submit_style = _accua_forms_style_parameters(array(
2350 'border-color' => $form_data['style_submit_border_color'],
2351 'border-width' => $form_data['style_submit_border_width'],
2352 'border-radius' => $form_data['style_submit_border_radius'],
2353 'background' => $form_data['style_submit_background_color'],
2354 'padding' => $form_data['style_submit_padding'],
2355 'color' => $form_data['style_submit_color'],
2356 'font-size' => $form_data['style_submit_font_size'],
2357 ));
2358 $submit_properties = array();
2359 if ($submit_style !== '') {
2360 $submit_properties['style'] = $submit_style;
2361 }
2362
2363 if ($form_style !== '') {
2364 $form->configure(array('style' => $form_style));
2365 }
2366
2367 if (!empty($form_data['use_ajax'])){
2368 $form->configure(array(
2369 "accua_ajax" => 1,
2370 ));
2371 }
2372
2373 $add_submit = true;
2374 $fieldset_open = false;
2375 $avail_fields = get_option('accua_forms_avail_fields', array());
2376
2377 foreach ($form_data['fields'] as $istance_data) {
2378
2379 if (empty($avail_fields[$istance_data['ref']])) {
2380 $field_data = array();
2381 if (!empty($istance_data['ref'])) {
2382 if ($istance_data['ref'] == '__fieldset-begin') {
2383 $field_data = array(
2384 'id' => '__fieldset-begin',
2385 'name' => __('Fieldset begin', 'accua-form-api'),
2386 'type' => 'fieldset-begin',
2387 'description' => '',
2388 );
2389 } else if ($istance_data['ref'] == '__fieldset-end') {
2390 $field_data = array(
2391 'id' => '__fieldset-end',
2392 'name' => __('Fieldset end', 'accua-form-api'),
2393 'type' => 'fieldset-end',
2394 'description' => '',
2395 );
2396 }
2397 }
2398 } else {
2399 $field_data = $avail_fields[$istance_data['ref']];
2400 }
2401
2402 $field_data += array(
2403 'id' => '__html',
2404 'name' => __( 'Custom HTML content', 'accua-form-api'),
2405 'type' => 'html',
2406 'description' => __('Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
2407 'default_value' => '',
2408 'allowed_values' => '',
2409 );
2410
2411 $istance_data += array(
2412 'istance_id' => $field_data['id'],
2413 'widget_number' => '',
2414 'ref' => $field_data['id'],
2415 'label' => $field_data['name'],
2416 'default_value' => $field_data['default_value'],
2417 'allowed_values' => $field_data['allowed_values'],
2418 );
2419
2420 $element = null;
2421
2422 $allowed_val = trim($istance_data['allowed_values']);
2423
2424
2425 if ($field_data['type'] == 'post-multicheckbox' || $field_data['type'] == 'post-select') {
2426 $posts = accua_get_pages($allowed_val);
2427 $allowed_values = array();
2428 foreach ($posts as $p) {
2429 //$allowed_values[$p->ID] = apply_filters( 'the_title', $p->post_title, $p->ID );
2430 $allowed_values[$p->ID] = $p->post_title;
2431 }
2432 } else {
2433 if ($field_data['type'] == 'file') {
2434 $filedata = get_option('accua_forms_default_file_field_data',array());
2435 $filedata += array(
2436 'valid_extensions' => '',
2437 'max_filesize' => '',
2438 'dest_path' => '',
2439 );
2440 if ($allowed_val == '') {
2441 $allowed_val = trim($filedata['valid_extensions']);
2442 }
2443 }
2444
2445 $allowed_val = explode("\n",$allowed_val);
2446 $allowed_values = array();
2447 foreach ($allowed_val as $val) {
2448 $val = explode('|',$val,2);
2449 $val[0] = trim($val[0]);
2450 /*
2451 if (empty($val[0])) {
2452 continue;
2453 }
2454 */
2455 if ((!isset($val[1])) || (trim($val[1])==='')) {
2456 if ($val[0] === '') {
2457 continue;
2458 } else {
2459 $val[1] = $val[0];
2460 }
2461 }
2462 $allowed_values[$val[0]] = $val[1];
2463 }
2464 }
2465
2466 switch ($field_data['type']) {
2467 case 'textarea':
2468 $element = new Element_Textarea($istance_data['label'], $istance_data['istance_id'], $field_properties+array('cols' => '50', 'value'=>$istance_data['default_value']));
2469 break;
2470 case 'hidden':
2471 $element = new Element_Hidden($istance_data['istance_id'], $istance_data['default_value']);
2472 break;
2473 case 'checkbox':
2474 $lab = $istance_data['label'];
2475 if (!empty($istance_data['required'])) {
2476 $lab .= ' <strong>*</strong>';
2477 }
2478 if ($allowed_values) {
2479 reset($allowed_values);
2480 $val = (string) key($allowed_values);
2481 $defval = trim($istance_data['default_value']);
2482 } else if ($istance_data['default_value'] == '1') {
2483 $defval = $val = '1';
2484 } else {
2485 $val = empty($istance_data['default_value'])?'1':$istance_data['default_value'];
2486 $defval = '';
2487 }
2488 $element = new AccuaForm_Element_Checkbox('', $istance_data['istance_id'], array($val => $lab), array('value' => $defval));
2489 break;
2490 case 'select':
2491 case 'post-select':
2492 if (!isset($allowed_values[''])) {
2493 $allowed_values = array('' => '') + $allowed_values;
2494 }
2495 $defval = trim($istance_data['default_value']);
2496 $element = new AccuaForm_Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, $field_properties+array('value'=>$defval));
2497 break;
2498 case 'radio':
2499 $defval = trim($istance_data['default_value']);
2500 $element = new AccuaForm_Element_Radio($istance_data['label'], $istance_data['istance_id'], $allowed_values, array('value'=>$defval));
2501 break;
2502 case 'multiselect':
2503 $defval = explode('|', $istance_data['default_value']);
2504 foreach ($defval as $k => $v) {
2505 $defval[$k] = trim($v);
2506 }
2507 $element = new AccuaForm_Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, $field_properties+array('multiple' => true, 'value'=>$defval));
2508 break;
2509 case 'multicheckbox':
2510 case 'post-multicheckbox':
2511 $defval = explode('|', $istance_data['default_value']);
2512 foreach ($defval as $k => $v) {
2513 $defval[$k] = trim($v);
2514 }
2515 $element = new AccuaForm_Element_Checkbox($istance_data['label'], $istance_data['istance_id'], $allowed_values, array('value'=>$defval));
2516 break;
2517 case 'file':
2518 $fdata = array();
2519
2520 if ($allowed_values) {
2521 $fdata['validExtensions'] = array_keys($allowed_values);
2522 }
2523
2524 if ($filedata['max_size'] !== ''){
2525 $fdata['maxSize'] = $filedata['max_size'];
2526 }
2527
2528 $fdata['destPath'] = _accua_forms_get_abs_dest_path($filedata['dest_path']);
2529
2530 $element = new AccuaForm_Element_File($istance_data['label'], $istance_data['istance_id'], $field_properties+$fdata);
2531 break;
2532 case 'html':
2533 $element = new Element_HTML($istance_data['default_value']);
2534 break;
2535 case 'email':
2536 case 'autoreply_email':
2537 $element = new AccuaForm_Element_Email($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2538 $element->setValidation(new Validation_Email(
2539 str_replace('%element%', $istance_data['label'], __("Attention: '%element%' must contain an email address.", 'accua-form-api'))
2540 ));
2541 //"Errore: '{$istance_data['label']}' deve contenere un indirizzo email valido."
2542 break;
2543 case 'colorpicker':
2544 $element = new AccuaForm_Element_ColorPicker($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2545 break;
2546 case 'fieldset-begin':
2547 if ($fieldset_open) {
2548 $form->addElement(new AccuaForm_Element_FieldsetEnd());
2549 } else {
2550 $fieldset_open = true;
2551 }
2552 $element = new AccuaForm_Element_FieldsetBegin($istance_data['label']);
2553 break;
2554 case 'fieldset-end':
2555 if ($fieldset_open) {
2556 $element = new AccuaForm_Element_FieldsetEnd();
2557 $fieldset_open = false;
2558 }
2559 break;
2560 case 'submit':
2561 $add_submit = false;
2562 $element = new Element_Button($istance_data['label'], 'submit', $submit_properties+array('name' => $istance_data['istance_id'], 'value' => $istance_data['default_value']));
2563 break;
2564 case 'captcha':
2565 $element = new AccuaForm_Element_Captcha ($istance_data['label'], array("description" => ""));
2566 break;
2567 case 'password':
2568 $element = new Element_Password($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2569 break;
2570 case 'password-and-confirm':
2571 $id_2 = "___{$istance_data['istance_id']}___confirmpass";
2572 $element = new Element_Password(__("Password", 'accua-form-api'), $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2573 $element_conf = new Element_Password(__("Confirm password", 'accua-form-api'), $id_2, $field_properties+array('value'=>$istance_data['default_value']));
2574 $element_conf->setValidation(new AccuaForm_Validation_Password());
2575 break;
2576 //case 'textfield':
2577 default:
2578 $element = new Element_Textbox($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value']));
2579 break;
2580 }
2581 if ($element) {
2582 if (!empty($istance_data['required'])) {
2583 $element->setClass('accuaforms-field-required');
2584 if($field_data['type']!='password-and-confirm') {
2585 $element->setValidation(new Validation_Required(
2586 str_replace('%element%', $istance_data['label'], __("Attention: '%element%' is a required field.", 'accua-form-api'))
2587 ));
2588 } else {
2589 $element->setValidation(new Validation_Required(
2590 str_replace('%element%', $istance_data['label'], __("Attention: Passwords are required fields.", 'accua-form-api'))
2591 ));
2592 }
2593 }
2594
2595 if ($elementName = $element->getName()) {
2596 $element->setClass('accuaform-fieldname-'.$elementName);
2597 }
2598
2599 if ($field_data['type']) {
2600 $element->setClass('accuaform-fieldtype-'.$field_data['type']);
2601 }
2602
2603 $form->addElement($element);
2604 if($element_conf!=NULL) {
2605 $form->addElement($element_conf);
2606 $element_conf=NULL;
2607 }
2608 }
2609 }
2610 if ($fieldset_open) {
2611 $form->addElement(new AccuaForm_Element_FieldsetEnd());
2612 $fieldset_open = false;
2613 }
2614 if ($add_submit) {
2615 $form->addElement(new Element_Button(__('Submit', 'accua-form-api'), 'submit', $submit_properties));
2616 }
2617 }
2618
2619 }
2620 }
2621
2622 function accua_forms_aggregate_submitted_data(&$replace_map, $params = array()) {
2623 if (empty($params['txt']) && empty($params['html']) && empty($params['json']) && empty($params['email'])) {
2624 $params += array(
2625 'txt' => true,
2626 'html' => true,
2627 'json' => true,
2628 'email' => true,
2629 );
2630 }
2631
2632 if (!empty($params['txt'])) {
2633 $replace_map['__submitted_txt'] = implode("\n",$replace_map['__submitted_txt_raw']);
2634 }
2635 if (!empty($params['html'])) {
2636 $replace_map['__submitted_html'] = implode('</td></tr><tr><td>',$replace_map['__submitted_html_raw']);
2637 }
2638 if (!empty($params['json'])) {
2639 $replace_map['__submitted_json'] = json_encode($replace_map['__submitted_json_raw']);
2640 }
2641 if (!empty($params['email'])) {
2642 $replace_map['__autoreply_email'] = implode('; ', $replace_map['__autoreply_email_raw']);
2643 }
2644
2645 }
2646
2647 add_filter('accua_form_validate', 'accua_forms_validation_handler', 10, 4);
2648 function accua_forms_validation_handler($valid, $submittedID, $submittedData, $form){
2649 if (substr($submittedID, 0, 14) == '__accua-form__') {
2650 $fid = substr($submittedID,14);
2651 $form_data = _accua_forms_get_form_data($fid, false);
2652 if ($form_data) {
2653 return apply_filters('accua_forms_validation', $valid, $fid, $submittedData, $form);
2654 }
2655 }
2656 return $valid;
2657 }
2658
2659 add_action('accua_form_submit', 'accua_forms_form_submission_handler', -10, 3);
2660 function accua_forms_form_submission_handler($submittedID, $submittedData, $form) {
2661 if ( empty( $GLOBALS['wp_rewrite'] ) )
2662 $GLOBALS['wp_rewrite'] = new WP_Rewrite();
2663
2664 if (!class_exists('AccuaConditionalReplacer')){
2665 require_once('AccuaConditionalReplacer.php');
2666 }
2667 if (substr($submittedID, 0, 14) == '__accua-form__') {
2668 $fid = substr($submittedID,14);
2669 $form_data = _accua_forms_get_form_data($fid, false);
2670 if ($form_data) {
2671 global $wpdb;
2672
2673 $time = time();
2674
2675 $wpdb->insert(
2676 $wpdb->prefix . 'accua_forms_submissions',
2677 array (
2678 'afs_form_id' => $fid,
2679 'afs_post_id' => $form->stats['pid'],
2680 'afs_ip' => $form->stats['ip'],
2681 'afs_uri' => $form->stats['uri'],
2682 'afs_referrer' => $form->stats['referrer'],
2683 'afs_lang' => $form->stats['lang'],
2684 'afs_created' => gmdate('Y-m-d H:i:s', $form->stats['created']),
2685 'afs_submitted' => gmdate('Y-m-d H:i:s', $time),
2686 'afs_stats' => json_encode(array(
2687 'user_agent' => $form->stats['user_agent'],
2688 'platform' => $form->stats['platform'],
2689 'tentatives' => $form->stats['tentatives'],
2690 'submit_method' => $form->stats['submit_method'],
2691 )),
2692 )
2693 );
2694
2695 $submission_id = $form->stats['submission_id'] = $wpdb->insert_id;
2696
2697
2698
2699 $replace_map = array(
2700 '__fid' => $fid,
2701 '__subid' => $submission_id,
2702 '__pid' => $form->stats['pid'],
2703 '__ip' => $form->stats['ip'],
2704 '__uri' => $form->stats['uri'],
2705 '__url' => $form->stats['url'],
2706 '__referrer' => $form->stats['referrer'],
2707 '__lang' => $form->stats['lang'],
2708 '__locale' => $form->stats['locale'],
2709 '__created' => $form->stats['created'],
2710 '__created_day' => date('l j F Y', $form->stats['created']),
2711 '__created_day_month_year' => date('j F Y', $form->stats['created']),
2712 '__created_hour' => date('G:i', $form->stats['created']),
2713 '__submitted' => $time,
2714 '__submitted_day' => date('l j F Y', $time),
2715 '__submitted_day_month_year' => date('j F Y', $time),
2716 '__submitted_hour' => date('G:i', $time),
2717 '__confirmation_emails_message' => $form_data['confirmation_emails_message'],
2718 '__user_agent' => $form->stats['user_agent'],
2719 '__platform' => $form->stats['platform'],
2720 '__tentatives' => $form->stats['tentatives'],
2721 '__submit_method' => $form->stats['submit_method'],
2722 );
2723
2724 $avail_fields = get_option('accua_forms_avail_fields', array());
2725
2726 $replace_map['__autoreply_email_raw'] = array();
2727 $replace_map['__submitted_txt_raw'] = array();
2728 $replace_map['__submitted_html_raw'] = array();
2729 $replace_map['__submitted_json_raw'] = array();
2730
2731 $_field_data = array();
2732 $_istance_data = array();
2733
2734 foreach ($submittedData as $istance_id => $value) {
2735 if (empty($form_data['fields'][$istance_id])) {
2736 continue;
2737 }
2738 $istance_data = $form_data['fields'][$istance_id];
2739
2740 if (empty($avail_fields[$istance_data['ref']])) {
2741 $fieldset_data = array();
2742 if (!empty($istance_data['ref'])) {
2743 if ($istance_data['ref'] == '__fieldset-begin') {
2744 $field_data = array(
2745 'id' => '__fieldset-begin',
2746 'name' => __('Fieldset begin', 'accua-form-api'),
2747 'type' => 'fieldset-begin',
2748 'description' => '',
2749 );
2750 } else if ($istance_data['ref'] == '__fieldset-end') {
2751 $field_data = array(
2752 'id' => '__fieldset-end',
2753 'name' => __('Fieldset end', 'accua-form-api'),
2754 'type' => 'fieldset-end',
2755 'description' => '',
2756 );
2757 }
2758 }
2759 } else {
2760 $field_data = $avail_fields[$istance_data['ref']];
2761 }
2762
2763 $field_data += array(
2764 'id' => '__html',
2765 'name' => __( 'Custom HTML content', 'accua-form-api'),
2766 'type' => 'html',
2767 'description' => __( 'Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
2768 'default_value' => '',
2769 'allowed_values' => '',
2770 );
2771
2772 /*
2773 echo "<!-- istance_data: "
2774 , print_r($istance_data, true)
2775 , "\nfield_data: "
2776 , print_r($field_data, true)
2777 , "\nvalue: "
2778 , print_r($value, true)
2779 , "\n-->\n";
2780 */
2781
2782 $istance_data += array(
2783 'istance_id' => $field_data['id'],
2784 'widget_number' => '',
2785 'ref' => $field_data['id'],
2786 'label' => $field_data['name'],
2787 'default_value' => $field_data['default_value'],
2788 'allowed_values' => $field_data['allowed_values'],
2789 );
2790
2791 $type = $field_data['type'];
2792
2793 switch ($field_data['type']) {
2794 case 'checkbox':
2795 case 'submit':
2796 if (empty($value)) {
2797 $replace_map[$istance_data['istance_id']] = $value = '';
2798 } else {
2799 if (empty($istance_data['default_value'])) {
2800 $replace_map[$istance_data['istance_id']] = 'Checked';
2801 $value = '1';
2802 } else {
2803 $replace_map[$istance_data['istance_id']] = $value = $istance_data['default_value'];
2804 }
2805 }
2806 break;
2807 case 'multiselect':
2808 case 'multicheckbox':
2809 if (is_array($value)) {
2810 $replace_map[$istance_data['istance_id']] = implode(', ',$value);
2811 $value = implode('|',$value);
2812 } else {
2813 $replace_map[$istance_data['istance_id']] = $value = '';
2814 }
2815 break;
2816 case 'post-multicheckbox':
2817 if (is_array($value) && $value) {
2818 $el = $form->getElementByName($istance_id);
2819 $opts = $el->getOptions();
2820 $value2 = array();
2821 foreach ($value as $val) {
2822 if (isset($opts[$val])) {
2823 $value2[] = $val . ': ' . trim(preg_replace('/[\s\n\r]+/', ' ', $opts[$val]));
2824 }
2825 }
2826 $replace_map[$istance_data['istance_id']] = $value = implode("\n", $value2);
2827 } else {
2828 $replace_map[$istance_data['istance_id']] = $value = '';
2829 }
2830 break;
2831 case 'post-select':
2832 if ($value !== '') {
2833 $el = $form->getElementByName($istance_id);
2834 $opts = $el->getOptions();
2835 if (isset($opts[$value])) {
2836 $value = $value . ': ' . trim(preg_replace('/[\s\n\r]+/', ' ', $opts[$value]));
2837 } else {
2838 $value = '';
2839 }
2840 }
2841 $replace_map[$istance_data['istance_id']] = $value;
2842 break;
2843 case 'autoreply_email':
2844 if ($value !== '') {
2845 $replace_map['__autoreply_email_raw'][] = $value;
2846 }
2847 $replace_map[$istance_data['istance_id']] = $value;
2848 break;
2849 case 'file':
2850 //TODO: move temp file to "{$submission_id}_{$field_data['id']}_{$file['name']}"; value is $file['name']
2851 $buildid = $submittedData['_AccuaForm_buildID'];
2852 $file_download_url = '';
2853 $file = $form->getFile($istance_id);
2854 if ($value !== null && $value !== '' && $file) {
2855 if ($form->renameFile($istance_id, "{$submission_id}_{$field_data['id']}_{$file['name']}")) {
2856 $urlfield = rawurlencode($istance_data['istance_id']);
2857 $urlfile = rawurlencode($value);
2858 $file_download_url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$submission_id}&field={$urlfield}&file={$urlfile}";
2859 }
2860 }
2861 $replace_map[$istance_data['istance_id']] = $value;
2862 $replace_map['__download_'.$istance_data['istance_id']] = $file_download_url;
2863 break;
2864 case 'password':
2865 case 'password-and-confirm':
2866 $value = trim($value);
2867 $replace_map[$istance_data['istance_id']] = $value;
2868 $type = 'hashed-password';
2869 if ($value !== '') {
2870 $value = wp_hash_password($value);
2871 }
2872 $replace_map['__hashed_'.$istance_data['istance_id']] = $value;
2873 break;
2874 default:
2875 $replace_map[$istance_data['istance_id']] = $value;
2876 }
2877
2878 switch ($field_data['type']) {
2879 case 'file':
2880 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value\t$file_download_url";
2881 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = "$value\t$file_download_url";
2882 $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>";
2883 break;
2884
2885 case 'email':
2886 case 'autoreply_email':
2887 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2888 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2889 $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>";
2890 break;
2891 case 'submit':
2892 break;
2893 case 'colorpicker':
2894 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2895 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2896 if ($value === '') {
2897 $value_html = '';
2898 } else {
2899 $value_esc = htmlspecialchars($value, ENT_QUOTES);
2900 $value_html = "<span style='color: $value_esc'><font color='$value_esc'>&#9608;</font></span> $value_esc";
2901 }
2902 $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "<strong>{$istance_data['istance_id']}</strong></td><td class='valori_submitted'>$value_html";
2903 break;
2904 case 'password':
2905 case 'password-and-confirm':
2906 break;
2907 default:
2908 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2909 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2910 $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "<strong>{$istance_data['istance_id']}</strong></td><td class='valori_submitted'>".htmlspecialchars($value);
2911 }
2912
2913 $wpdb->insert(
2914 $wpdb->prefix . 'accua_forms_submissions_values',
2915 array (
2916 'afsv_sub_id' => $submission_id,
2917 'afsv_field_id' => $istance_data['istance_id'],
2918 'afsv_type' => $type,
2919 'afsv_value' => $value,
2920 ),
2921 array('%d','%s','%s','%s')
2922 );
2923
2924 $_field_data[$istance_data['istance_id']] = $field_data;
2925 $_istance_data[$istance_data['istance_id']] = $istance_data;
2926
2927 }
2928
2929 $replace_map['__autoreply'] = (bool) ($replace_map['__autoreply_email_raw']
2930 && $form_data['confirmation_emails_subject']
2931 && $form_data['confirmation_emails_message']);
2932
2933 accua_forms_aggregate_submitted_data($replace_map);
2934
2935 //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
2936 $replace_map = apply_filters('accua_forms_form_submission_handler', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data);
2937
2938 //Newer filter, with an easier name
2939 $replace_map = apply_filters('accua_forms_submission', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data);
2940
2941 $submitted_html = '<table><tr><td>' . $replace_map['__submitted_html'] . '</td></tr></table>';
2942 $confirmation_emails_message = $replace_map['__confirmation_emails_message'];
2943 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']);
2944
2945 $replace_map_html = array();
2946 foreach($replace_map as $key => $value) {
2947 $replace_map_html["!$key"] = $value;
2948 $replace_map_html[$key] = htmlspecialchars($value, ENT_QUOTES);
2949 }
2950
2951 $replace_map['__submitted_html'] = $replace_map_html['__submitted_html'] = $replace_map_html['!__submitted_html'] = $submitted_html;
2952 $replacer_html = new AccuaConditionalReplacer($replace_map_html);
2953
2954 $confirmation_emails_message = $replace_map['__confirmation_emails_message'] = $replacer_html->doReplace($confirmation_emails_message);
2955 $replacer_html->appendPattern(array('__confirmation_emails_message' => $confirmation_emails_message, '!__confirmation_emails_message' => $confirmation_emails_message));
2956 $replacer = new AccuaConditionalReplacer($replace_map);
2957
2958 $form_data_replaced = array();
2959
2960 $settings = array(
2961 'emails_from_name',
2962 'emails_from',
2963 'admin_emails_to',
2964 'emails_bcc',
2965 'admin_emails_subject',
2966 'confirmation_emails_subject',
2967 );
2968
2969 foreach($settings as $i) {
2970 $form_data_replaced[$i] = $replacer->doReplace($form_data[$i]);
2971 }
2972
2973 $settings_html = array(
2974 'success_message',
2975 'admin_emails_message',
2976 );
2977
2978 foreach($settings_html as $i) {
2979 $form_data_replaced[$i] = $replacer_html->doReplace($form_data[$i]);
2980 }
2981
2982 AccuaForm::appendSubmittedMessages(wpautop($form_data_replaced['success_message']));
2983
2984 $header = array("Content-Type: text/html; charset=".get_option('blog_charset'));
2985
2986 $emails_from = trim($form_data_replaced['emails_from']);
2987 if (strpos($emails_from, '@') !== false) {
2988 if ((strpos($emails_from, '<') === false) && is_email($emails_from)) {
2989 $emails_from_name = trim($form_data_replaced['emails_from_name']);
2990 if ($emails_from_name !== '') {
2991 $emails_from = "=?" . get_bloginfo('charset') . "?B?" . base64_encode($emails_from_name) . "?= <$emails_from>";
2992 }
2993 }
2994 $header[] = 'From: '.$emails_from;
2995 }
2996
2997 if ($form_data_replaced['emails_bcc']) {
2998 $header[] = 'Bcc: '.$form_data_replaced['emails_bcc'];
2999 }
3000
3001 if ($form_data_replaced['admin_emails_to']
3002 && $form_data_replaced['admin_emails_subject']) {
3003 /*
3004 $admin_tos = explode(',', strtr($form_data_replaced['admin_emails_to'], "\n\t\r;", ',,,,'));
3005 foreach ($admin_tos as $admin_to) {
3006 $mail1 = wp_mail(trim($admin_to), $form_data_replaced['admin_emails_subject'], $form_data_replaced['admin_emails_message'], $header);
3007 }
3008 */
3009 $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);
3010 }
3011
3012 if ($replace_map['__autoreply'] && $replace_map['__autoreply_email']
3013 && $form_data_replaced['confirmation_emails_subject']
3014 && $confirmation_emails_message) {
3015 $mail2 = wp_mail($replace_map['__autoreply_email'], $form_data_replaced['confirmation_emails_subject'], '<html><head></head><body>'.wpautop($confirmation_emails_message).'</body></html>', $header);
3016 }
3017
3018 /*
3019 echo "<!-- replace_map: "
3020 , print_r($replace_map, true)
3021 , "\nreplace_map: "
3022 , print_r($replace_map, true)
3023 , "\nform_data_replaced: "
3024 , print_r($form_data_replaced, true)
3025 , "\nautoreply_email: "
3026 , print_r($autoreply_email, true)
3027 , "\nmail1: "
3028 , print_r($mail1, true)
3029 , "\nmail2: "
3030 , print_r($mail2, true)
3031 ,"\n-->";
3032 */
3033 }
3034 }
3035 }
3036
3037 function accua_forms_get_submission_data($subid, $options = array()){
3038 //TODO: Completa e usa per sostituire i campi
3039 global $wpdb;
3040 $subid = (int) $subid;
3041 $options += array(
3042 'extra' => true,
3043 'file_format' => 'name',
3044 );
3045 $ret = array();
3046 if ($options['extra']) {
3047 $query1 = "SELECT *
3048 FROM `{$wpdb->prefix}accua_forms_submissions`
3049 WHERE afs_id = $subid";
3050 $data = $wpdb->get_row($query1);
3051 if (!empty($data)) {
3052 $created = $data->afs_created;
3053 $created[10] = 'T';
3054 $created.='.00+00:00';
3055 $created = strtotime($created);
3056 $submitted = $data->afs_submitted;
3057 $submitted[10] = 'T';
3058 $submitted.='.00+00:00';
3059 $submitted = strtotime($submitted);
3060 if ($data->afs_stats) {
3061 $stats = json_decode($data->afs_stats, true);
3062 if (!$stats) {
3063 $stats = array();
3064 }
3065 } else {
3066 $stats = array();
3067 }
3068 $stats += array(
3069 'user_agent' => '',
3070 'platform' => '',
3071 'tentatives' => '',
3072 'submit_method' => '',
3073 );
3074 $ret += array(
3075 '__fid' => $data->afs_form_id,
3076 '__subid' => $subid,
3077 '__pid' => $data->afs_post_id,
3078 '__ip' => $data->afs_id,
3079 '__uri' => $data->afs_uri,
3080 '__referrer' => $data->afs_referrer,
3081 '__lang' => $data->afs_lang,
3082 '__created' => $created,
3083 '__created_day' => date('l j F Y', $created),
3084 '__created_hour' => date('G:i', $created),
3085 '__submitted' => $submitted,
3086 '__submitted_day' => date('l j F Y', $submitted),
3087 '__submitted_hour' => date('G:i', $submitted),
3088 '__user_agent' => $stats['user_agent'],
3089 '__platform' => $stats['platform'],
3090 '__tentatives' => $stats['tentatives'],
3091 '__submit_method' => $stats['submit_method'],
3092 );
3093 }
3094 }
3095
3096 $query2 = "SELECT *
3097 FROM `{$wpdb->prefix}accua_forms_submissions_values`
3098 WHERE afsv_sub_id = $subid";
3099
3100 $data2 = $wpdb->get_results($query2, OBJECT);
3101
3102 foreach ($data2 as $row) {
3103 switch ($row->afsv_type) {
3104 case 'file' :
3105 if ($options['file_format'] == 'url' || $options['file_format'] == 'link') {
3106 $fieldid = rawurlencode($row->afsv_field_id);
3107 $filename = rawurlencode($row->afsv_value);
3108 $url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$row->afsv_sub_id}&field={$fieldid}&file={$filename}";
3109 if ($options['file_format'] == 'link'){
3110 $url = htmlspecialchars($url,ENT_QUOTES);
3111 $filename = htmlspecialchars($row->afsv_value,ENT_QUOTES);
3112 $fielddata = "<a href='{$url}' target='_blank'>{$filename}</a>";
3113 } else {
3114 $fielddata = $url;
3115 }
3116 } else { // $options['file_format'] == 'name'
3117 $fielddata = $row->afsv_value;
3118 }
3119 break;
3120 default:
3121 $fielddata = $row->afsv_value;
3122 }
3123 $ret[$row->afsv_field_id] = $fielddata;
3124 }
3125 return $ret;
3126 }
3127
3128 add_shortcode( 'accua-form', 'accua_forms_shortcode_handler' );
3129 function accua_forms_shortcode_handler($atts, $content = '', $code = '') {
3130 if (empty($atts['fid'])) {
3131 return '';
3132 }
3133
3134 $fid = $atts['fid'];
3135 $form_data = _accua_forms_get_form_data($fid, false);
3136
3137 if (! $form_data) {
3138 return '';
3139 }
3140
3141 $fid = '__accua-form__'.$fid;
3142
3143 $out = '';
3144
3145 if (AccuaForm::getSubmittedID() == $fid) {
3146 /* return "<pre>Form submitted.\n\nData: " . print_r(AccuaForm::getSubmittedData(), true) . '</pre>'; */
3147 $messages = AccuaForm::getSubmittedMessages();
3148 if ($messages) {
3149 $out .= '<div id="_response_messages_'.$fid.'" class="accua-form-messages">'.$messages.'</div>';
3150 }
3151 if (AccuaForm::isValid()) {
3152 return $out;
3153 }
3154 $form = AccuaForm::getSubmittedForm();
3155 } else {
3156 $form = AccuaForm::create($fid, array('layout'=>$form_data['layout']));
3157 }
3158
3159 return $out . $form->render(true);
3160 }
3161
3162 function accua_forms_include($fid, $atts=array(), $content = '', $code = '') {
3163 $atts['fid'] = $fid;
3164 echo accua_forms_shortcode_handler($atts, $content, $code);
3165 }
3166
3167 function accua_forms_submissions_list_page_head(){
3168 require_once('accua-forms-submissions-page.php');
3169 accua_forms_submissions_list_page(true);
3170 }
3171
3172 add_action('wp_ajax_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file');
3173 add_action('wp_ajax_nopriv_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file');
3174 function accua_forms_download_submitted_file(){
3175 $get = stripslashes_deep($_GET);
3176 if (isset($get['subid'],$get['field'],$get['file'])) {
3177 global $wpdb;
3178 $subid = (int) $get['subid'];
3179 $field = $get['field'];
3180 $file = $get['file'];
3181 $query = "SELECT *
3182 FROM `{$wpdb->prefix}accua_forms_submissions_values`
3183 WHERE afsv_sub_id = %d
3184 AND afsv_field_id = %s
3185 AND afsv_value = %s
3186 ";
3187 $query = $wpdb->prepare($query, $subid, $field, $file);
3188 $subval = $wpdb->get_results($query, OBJECT);
3189 if ($subval) {
3190 $file_data = get_option('accua_forms_default_file_field_data',array()) + array('dest_path' => '');
3191 $dest_path = _accua_forms_get_abs_dest_path($file_data['dest_path']);
3192 $filename = "{$dest_path}/{$subid}_{$field}_{$file}";
3193 if (is_file($filename) && is_readable($filename)){
3194 if (function_exists('finfo_open')){
3195 @ $finfo = finfo_open(FILEINFO_MIME);
3196 if ($finfo) {
3197 @ $filetype = finfo_file($finfo, $filename);
3198 @ finfo_close($finfo);
3199 }
3200 }
3201 if (empty($filetype) && function_exists('mime_content_type')){
3202 @ $filetype = mime_content_type($filename);
3203 }
3204 if (empty($filetype)) {
3205 $filetype = "application/octet-stream";
3206 }
3207 header("Content-type: $filetype");
3208 header("Content-length: ".filesize($filename));
3209 header("Content-disposition: attachment; filename=\"$file\"");
3210 readfile($filename);
3211 die('');
3212 }
3213 }
3214 }
3215 header("HTTP/1.0 404 Not Found");
3216 //header("Status: 404 Not Found");
3217 die('File not found');
3218 }
3219
3220 function accua_forms_buildConditionalReplacer($map = array()) {
3221 if (!class_exists('AccuaConditionalReplacer')){
3222 require_once('AccuaConditionalReplacer.php');
3223 }
3224 return new AccuaConditionalReplacer($map);
3225 }
3226
3227
3228 add_action('wp_ajax_accua_forms_preview', 'accua_forms_preview');
3229 function accua_forms_preview() {
3230 if (!current_user_can(10)){
3231 die ('');
3232 }
3233
3234 echo '<html><head>';
3235 wp_print_styles();
3236 wp_print_head_scripts();
3237 echo '</head><body>';
3238 echo accua_forms_shortcode_handler(array('fid'=>$_REQUEST['fid']));
3239 wp_print_footer_scripts();
3240 echo '</body></html>';
3241 die('');
3242 }
3243
3244 //salvataggio file excel
3245 add_action('wp_ajax_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel');
3246 //add_action('wp_ajax_nopriv_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel');
3247
3248 function accua_forms_submission_page_save_excel() {
3249 if (!current_user_can(10)){
3250 header("HTTP/1.0 401 Access Denied");
3251 //header("Status: 401 Access Denied");
3252 die('You are not authorized to access this page.');
3253 }
3254
3255 require_once('accua-forms-submissions-page.php');
3256 $listTable = new Accua_Forms_Submissions_List_Table();
3257 $listTable->prepare_items(true);
3258 $show_col = explode( ',', $_GET['accua_show_field']);
3259
3260 header("Content-disposition: attachment; filename=downloads-report.xls");
3261 header("Content-type: application/vnd.ms-excel");
3262 accua_forms_submission_page_save_excel_general($listTable,$show_col);
3263 die('');
3264 }
3265
3266
3267
3268 function accua_forms_submission_page_save_excel_general(Accua_Forms_Submissions_List_Table $listTable,array $show_col,array $options=array()) {
3269 global $wpdb;
3270
3271 //creo il file excel
3272 ?><html xmlns:o="urn:schemas-microsoft-com:office:office"
3273 xmlns:x="urn:schemas-microsoft-com:office:excel"
3274 xmlns="http://www.w3.org/TR/REC-html40">
3275 <head>
3276 <meta http-equiv=Content-Type content="text/html; charset=<?php echo get_option('blog_charset'); ?>" />
3277 <meta name=ProgId content=Excel.Sheet />
3278 <style>
3279 <!--
3280 td {vertical-align:top;}
3281 .head_row {font-weight:bold;}
3282 .column-date { mso-number-format:"Short Date"; }
3283 .datetime_cell { mso-number-format:"yyyy\\-mm\\-dd\\ hh\:mm\:ss"; }
3284 -->
3285 </style>
3286 <!--[if gte mso 9]><xml>
3287 <x:ExcelWorkbook>
3288 <x:ExcelWorksheets>
3289 <x:ExcelWorksheet>
3290 <x:WorksheetOptions>
3291 <x:FreezePanes/>
3292 <x:FilterOn/>
3293 <x:SplitHorizontal>1</x:SplitHorizontal>
3294 <x:TopRowBottomPane>1</x:TopRowBottomPane>
3295 <x:ActivePane>2</x:ActivePane>
3296 <x:Panes>
3297 <x:Pane>
3298 <x:Number>3</x:Number>
3299 </x:Pane>
3300 <x:Pane>
3301 <x:Number>2</x:Number>
3302 </x:Pane>
3303 </x:Panes>
3304 </x:WorksheetOptions>
3305 </x:ExcelWorksheet>
3306 </x:ExcelWorksheets>
3307 </x:ExcelWorkbook>
3308 </xml><![endif]-->
3309 </head>
3310 <body>
3311 <table x:str border=1 >
3312 <tr class='head-row'>
3313 <?php
3314 $cols = $listTable->get_columns();
3315 foreach($cols as $col_key=>$col_value) {
3316 if(in_array($col_key, $show_col)) { ?>
3317 <td x:autofilter="all"><?php echo $col_value; ?></td>
3318 <?php }
3319 } ?>
3320 </tr>
3321
3322 <?php
3323 /* gestire la data
3324 $ut_date = $result->date;
3325 $ut_date[10] = 'T';
3326 $ut_date.='.00+00:00';
3327 $excel_date = (strtotime($ut_date) / 86400 + 25569);
3328 $parts_date = explode('-', substr($result->date, 0, 10));
3329 $date = "{$parts_date[2]}/{$parts_date[1]}/{$parts_date[0]}";
3330 echo "<td class='column-date' x:num='$excel_date' SDVAL=\"$excel_date\" SDNUM=\"1033;0;DD/MM/YYYY\">$date</td>\n";
3331 */
3332 ?>
3333 <?php
3334
3335
3336 foreach($listTable->items as $id_submission=>$single_submission) {
3337 echo "<tr>";
3338 foreach($cols as $col_key=>$col_value) {
3339 if(in_array($col_key, $show_col)) {
3340 echo "<td class='.$col_key.'>";
3341 if(isset($single_submission[$col_key])) {
3342 if ( method_exists( $this, 'column_' . $column_name ) ) {
3343 echo call_user_func( array( &$listTable, 'column_' . $col_key ), $single_submission );
3344 }
3345 else {
3346 echo $listTable->column_default( $single_submission, $col_key );
3347 }
3348 }
3349 echo "</td>";
3350 }
3351
3352 }
3353 echo "</tr>";
3354 }
3355
3356 ?>
3357 </table>
3358 </body>
3359 </html>
3360 <?php
3361 }
3362
3363 function accua_forms_print_tokens() {
3364 $avail_fields = get_option('accua_forms_avail_fields', array());
3365 $tokens = '';
3366 foreach($avail_fields as $key=>$value) {
3367 $tokens .= $value['name'] . ": {" . $key . "}\n";
3368 if ($value['type'] == 'file') {
3369 $tokens .= $value['name'] . " (download link): {__download_" . $key . "}\n";
3370 }
3371 }
3372
3373 echo <<<EOT
3374 <div class="accua_forms_token_list">
3375 <h2>Tokens</h2>
3376 <em>In HTML text, use {!token_name} to insert unfiltered token value</em>
3377 <h3>Fields</h3>
3378 <em>These tokens are available only if the field is added to the form</em>
3379 <pre>$tokens</pre>
3380 <h3>Generic tokens</h3>
3381 <pre>{__fid}
3382 {__subid}
3383 {__pid}
3384 {__ip}
3385 {__uri}
3386 {__url}
3387 {__referrer}
3388 {__lang}
3389 {__locale}
3390 {__created}
3391 {__created_day}
3392 {__created_day_month_year}
3393 {__created_hour}
3394 {__submitted}
3395 {__submitted_day}
3396 {__submitted_day_month_year}
3397 {__submitted_hour}
3398 {__user_agent}
3399 {__platform}
3400 {__tentatives}
3401 {__submit_method}
3402 {__submitted_txt}
3403 {__submitted_html}
3404 {__submitted_json}
3405 {__autoreply}
3406 {__autoreply_email}
3407 {__confirmation_emails_message}</pre>
3408 </div>
3409 EOT;
3410 do_action('accua_forms_print_tokens');
3411 }
3412
3413 function &accua_get_pages($args = '') {
3414 global $wpdb;
3415
3416 $defaults = array(
3417 'child_of' => 0, 'sort_order' => 'ASC',
3418 'sort_column' => 'post_title', 'hierarchical' => 1,
3419 'exclude' => array(), 'include' => array(),
3420 'meta_key' => '', 'meta_value' => '',
3421 'meta_value_lt' => '', 'meta_value_gt' => '',
3422 'meta_value_le' => '', 'meta_value_ge' => '',
3423 'meta_value_like' => '', 'meta_value_format' => 'string',
3424 'authors' => '', 'parent' => -1, 'exclude_tree' => '',
3425 'number' => '', 'offset' => 0,
3426 'post_type' => 'page', 'post_status' => 'publish',
3427 );
3428
3429 $r = wp_parse_args( $args, $defaults );
3430 extract( $r, EXTR_SKIP );
3431 $number = (int) $number;
3432 $offset = (int) $offset;
3433
3434 /*
3435 // Make sure the post type is hierarchical
3436 $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
3437 if ( !in_array( $post_type, $hierarchical_post_types ) )
3438 return false;
3439 */
3440
3441 // Make sure we have a valid post type
3442 if ( !is_array( $post_type ) )
3443 $post_type = explode( ',', $post_type );
3444 if ( array_diff( $post_type, get_post_types() ) )
3445 return false;
3446
3447 // Make sure we have a valid post status
3448 if ( !is_array( $post_status ) )
3449 $post_status = explode( ',', $post_status );
3450 if ( array_diff( $post_status, get_post_stati() ) )
3451 return false;
3452
3453 /*
3454 $cache = array();
3455 $key = md5( serialize( compact(array_keys($defaults)) ) );
3456 if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) {
3457 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
3458 $pages = apply_filters('get_pages', $cache[ $key ], $r );
3459 return $pages;
3460 }
3461 }
3462
3463 if ( !is_array($cache) )
3464 $cache = array();
3465 */
3466
3467 $inclusions = '';
3468 if ( !empty($include) ) {
3469 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
3470 $parent = -1;
3471 $exclude = '';
3472 $meta_key = '';
3473 $meta_value = '';
3474 $meta_value_lt = '';
3475 $meta_value_gt = '';
3476 $meta_value_le = '';
3477 $meta_value_ge = '';
3478 $meta_value_like = '';
3479 $hierarchical = false;
3480 $incpages = wp_parse_id_list( $include );
3481 if ( ! empty( $incpages ) ) {
3482 foreach ( $incpages as $incpage ) {
3483 if (empty($inclusions))
3484 $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
3485 else
3486 $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
3487 }
3488 }
3489 }
3490 if (!empty($inclusions))
3491 $inclusions .= ')';
3492
3493 $exclusions = '';
3494 if ( !empty($exclude) ) {
3495 $expages = wp_parse_id_list( $exclude );
3496 if ( ! empty( $expages ) ) {
3497 foreach ( $expages as $expage ) {
3498 if (empty($exclusions))
3499 $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage);
3500 else
3501 $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage);
3502 }
3503 }
3504 }
3505 if (!empty($exclusions))
3506 $exclusions .= ')';
3507
3508 $author_query = '';
3509 if (!empty($authors)) {
3510 $post_authors = preg_split('/[\s,]+/',$authors);
3511
3512 if ( ! empty( $post_authors ) ) {
3513 foreach ( $post_authors as $post_author ) {
3514 //Do we have an author id or an author login?
3515 if ( 0 == intval($post_author) ) {
3516 $post_author = get_user_by('login', $post_author);
3517 if ( empty($post_author) )
3518 continue;
3519 if ( empty($post_author->ID) )
3520 continue;
3521 $post_author = $post_author->ID;
3522 }
3523
3524 if ( '' == $author_query )
3525 $author_query = $wpdb->prepare(' post_author = %d ', $post_author);
3526 else
3527 $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
3528 }
3529 if ( '' != $author_query )
3530 $author_query = " AND ($author_query)";
3531 }
3532 }
3533
3534 $join = '';
3535 $where = "$exclusions $inclusions ";
3536 if ( ! ( empty( $meta_key ) && empty( $meta_value )
3537 && empty( $meta_value_lt ) && empty( $meta_value_gt )
3538 && empty( $meta_value_le ) && empty( $meta_value_ge )
3539 && empty( $meta_value_like ) ) ) {
3540 $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
3541
3542 // meta_key and meta_value might be slashed
3543 $meta_key = stripslashes($meta_key);
3544 $meta_value = stripslashes($meta_value);
3545 $meta_value_lt = stripslashes($meta_value_lt);
3546 $meta_value_gt = stripslashes($meta_value_gt);
3547 $meta_value_le = stripslashes($meta_value_le);
3548 $meta_value_ge = stripslashes($meta_value_ge);
3549 $meta_value_like = stripslashes($meta_value_like);
3550
3551 if ( ! empty( $meta_key ) ) {
3552 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
3553 }
3554
3555 $meta_value_field = "$wpdb->postmeta.meta_value";
3556 $meta_value_timestamp = false;
3557 switch($meta_value_format) {
3558 case 'timestamp':
3559 $meta_value_field = "TIMESTAMP( $meta_value_field )";
3560 $meta_value_param = "FROM_UNIXTIME( %s )";
3561 $meta_value_timestamp = true;
3562 break;
3563 case 'int':
3564 $meta_value_param = "%d";
3565 break;
3566 case 'float':
3567 $meta_value_param = "%f";
3568 break;
3569 //case 'string':
3570 default:
3571 $meta_value_param = "%s";
3572 }
3573
3574 if ( ! empty( $meta_value ) ) {
3575 if ($meta_value_timestamp) {
3576 $meta_value = strtotime($meta_value);
3577 }
3578 $where .= $wpdb->prepare(" AND $meta_value_field = $meta_value_param", $meta_value);
3579 }
3580 if ( ! empty( $meta_value_lt ) ) {
3581 if ($meta_value_timestamp) {
3582 $meta_value_lt = strtotime($meta_value_lt);
3583 }
3584 $where .= $wpdb->prepare(" AND $meta_value_field < $meta_value_param", $meta_value_lt);
3585 }
3586 if ( ! empty( $meta_value_gt ) ) {
3587 if ($meta_value_timestamp) {
3588 $meta_value_gt = strtotime($meta_value_gt);
3589 }
3590 $where .= $wpdb->prepare(" AND $meta_value_field > $meta_value_param", $meta_value_gt);
3591 }
3592 if ( ! empty( $meta_value_le ) ) {
3593 if ($meta_value_timestamp) {
3594 $meta_value_le = strtotime($meta_value_le);
3595 }
3596 $where .= $wpdb->prepare(" AND $meta_value_field <= $meta_value_param", $meta_value_le);
3597 }
3598 if ( ! empty( $meta_value_ge ) ) {
3599 if ($meta_value_timestamp) {
3600 $meta_value_ge = strtotime($meta_value_ge);
3601 }
3602 $where .= $wpdb->prepare(" AND $meta_value_field >= $meta_value_param", $meta_value_ge);
3603 }
3604 if ( ! empty( $meta_value_like ) ) {
3605 if ($meta_value_timestamp) {
3606 $meta_value_like = strtotime($meta_value_like);
3607 }
3608 $where .= $wpdb->prepare(" AND $meta_value_field like $meta_value_param", $meta_value_like);
3609 }
3610 }
3611
3612 if ( $parent >= 0 )
3613 $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
3614
3615
3616 if ( 1 == count ( $post_type ) ) {
3617 $where_post_type = $wpdb->prepare( "post_type = %s", array_shift( $post_type ) );
3618 } else {
3619 $post_type = implode( "', '", $post_type );
3620 $where_post_type = "post_type IN ('$post_type')";
3621 }
3622
3623 if ( 1 == count( $post_status ) ) {
3624 $where_post_type .= $wpdb->prepare( " AND post_status = %s", array_shift( $post_status ) );
3625 } else {
3626 $post_status = implode( "', '", $post_status );
3627 $where_post_type .= " AND post_status IN ('$post_status')";
3628 }
3629
3630 $orderby_array = array();
3631 $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
3632 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
3633 'ID', 'rand', 'comment_count');
3634 foreach ( explode( ',', $sort_column ) as $orderby ) {
3635 $orderby = trim( $orderby );
3636 if ( !in_array( $orderby, $allowed_keys ) )
3637 continue;
3638
3639 switch ( $orderby ) {
3640 case 'menu_order':
3641 break;
3642 case 'ID':
3643 $orderby = "$wpdb->posts.ID";
3644 break;
3645 case 'rand':
3646 $orderby = 'RAND()';
3647 break;
3648 case 'comment_count':
3649 $orderby = "$wpdb->posts.comment_count";
3650 break;
3651 default:
3652 if ( 0 === strpos( $orderby, 'post_' ) )
3653 $orderby = "$wpdb->posts." . $orderby;
3654 else
3655 $orderby = "$wpdb->posts.post_" . $orderby;
3656 }
3657
3658 $orderby_array[] = $orderby;
3659
3660 }
3661 $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title";
3662
3663 $sort_order = strtoupper( $sort_order );
3664 if ( '' !== $sort_order && !in_array( $sort_order, array( 'ASC', 'DESC' ) ) )
3665 $sort_order = 'ASC';
3666
3667 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
3668 $query .= $author_query;
3669 $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
3670
3671 if ( !empty($number) )
3672 $query .= ' LIMIT ' . $offset . ',' . $number;
3673
3674 //echo "<!-- accua_forms_query:\n$query\n-->";
3675
3676 $pages = $wpdb->get_results($query);
3677
3678 if ( empty($pages) ) {
3679 $pages = apply_filters('get_pages', array(), $r);
3680 return $pages;
3681 }
3682
3683 // Sanitize before caching so it'll only get done once
3684 $num_pages = count($pages);
3685 for ($i = 0; $i < $num_pages; $i++) {
3686 $pages[$i] = sanitize_post($pages[$i], 'raw');
3687 }
3688
3689 /*
3690 // Update cache.
3691 update_post_cache( $pages );
3692 */
3693
3694 if ( $child_of || $hierarchical )
3695 $pages = & get_page_children($child_of, $pages);
3696
3697 if ( !empty($exclude_tree) ) {
3698 $exclude = (int) $exclude_tree;
3699 $children = get_page_children($exclude, $pages);
3700 $excludes = array();
3701 foreach ( $children as $child )
3702 $excludes[] = $child->ID;
3703 $excludes[] = $exclude;
3704 $num_pages = count($pages);
3705 for ( $i = 0; $i < $num_pages; $i++ ) {
3706 if ( in_array($pages[$i]->ID, $excludes) )
3707 unset($pages[$i]);
3708 }
3709 }
3710
3711 /*
3712 $cache[ $key ] = $pages;
3713 wp_cache_set( 'get_pages', $cache, 'posts' );
3714 */
3715
3716 $pages = apply_filters('get_pages', $pages, $r);
3717
3718 return $pages;
3719 }
3720