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

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