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

3,532 lines 153.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 add_action('admin_menu', 'accua_forms_menu', -95);
3 function accua_forms_menu(){
4 $dashboard_admin_page=add_menu_page('Wordpress Contact Forms by Cimatti', 'Forms', 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 'hidden' => __('Hidden value', 'accua-form-api'),
1713 'file' => __('File upload', 'accua-form-api'),
1714 'submit' => __( 'Submit button', 'accua-form-api'),
1715 'html' => __( 'Custom HTML', 'accua-form-api'),
1716 'captcha' => __( 'Captcha', 'accua-form-api'),
1717 'password' => 'Password',
1718 'password-and-confirm' => __( 'Password and password confirmation','accua-form-api'),
1719 );
1720
1721
1722 ?>
1723 <div class="form-wrap">
1724 <h3><?php echo $adding? __( 'Add new field','accua-form-api'): __( 'Edit field','accua-form-api') ; ?></h3>
1725 <form id="addtag" method="post" action="admin.php?page=accua_forms_fields" class="validate">
1726 <input type="hidden" name="action" value="<?php echo $adding?'add':'edit'; ?>-form-field" />
1727 <?php /*
1728 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
1729 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1730 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1731 */ ?>
1732 <?php wp_nonce_field('add-tag', '_wpnonce_add-form-field'); ?>
1733
1734 <div class="form-field form-required">
1735 <label for="tag-name"><?php _e( 'Field label', 'accua-form-api'); ?></label>
1736 <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" />
1737 <p><?php _e('The name is how it appears on your site.', 'accua-form-api'); ?></p>
1738 </div>
1739 <?php /* if ( ! global_terms_enabled() ) : */ ?>
1740 <div class="form-field">
1741 <label for="tag-slug"><?php _e( 'Field slug (identificative)', 'accua-form-api'); ?></label>
1742 <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" />
1743 <?php if (!$adding) { echo '<input type="hiden" name="form-field-id" value="'.htmlspecialchars($default_form_values['id'], ENT_QUOTES).'" />'; } ?>
1744 <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>
1745 </div>
1746 <div class="form-field">
1747 <label for="parent"><?php _e( 'Field type', 'accua-form-api'); ?></label>
1748 <select class="postform" id="parent" name="form-field-type">
1749 <?php /*
1750 <option value="textfield" class="level-0" <?php echo ($default_form_values['type'] == 'textfield')?'selected="selected"':'';?> >Text Field</option>
1751 <option value="textarea" class="level-0" <?php echo ($default_form_values['type'] == 'textarea')?'selected="selected"':'';?> >Text Area</option>
1752 <option value="email" class="level-0" <?php echo ($default_form_values['type'] == 'email')?'selected="selected"':'';?> >Email</option>
1753 <option value="checkbox" class="level-0" <?php echo ($default_form_values['type'] == 'checkbox')?'selected="selected"':'';?> >Checkbox</option>
1754 <option value="select" class="level-0" <?php echo ($default_form_values['type'] == 'select')?'selected="selected"':'';?> >Select</option>
1755 */
1756 foreach ($types as $typeid => $typename) {
1757 $selected = ($default_form_values['type'] == $typeid)?'selected="selected"':'';
1758 echo <<<EOT
1759 <option value="{$typeid}" class="level-0" {$selected} >{$typename}</option>
1760 EOT;
1761 }
1762
1763 ?>
1764 </select>
1765 </div>
1766 <?php /* endif; // global_terms_enabled() */ ?>
1767 <?php /* if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
1768 <div class="form-field">
1769 <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
1770 <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
1771 <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
1772 <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>
1773 <?php endif; ?>
1774 </div>
1775 <?php endif; // is_taxonomy_hierarchical() */ ?>
1776 <div class="form-field">
1777 <label for="tag-description"><?php _e( 'Field description', 'accua-form-api'); ?></label>
1778 <textarea name="form-field-description" id="tag-description" rows="5" cols="40"><?php echo htmlspecialchars($default_form_values['description'], ENT_QUOTES) ?></textarea>
1779 <p><?php _e('The description is not prominent by default; however, some themes may show it.', 'accua-form-api'); ?></p>
1780 </div>
1781
1782 <div class="form-field">
1783 <label for="form-field-default-value"><?php _e( 'Default value(s)', 'accua-form-api'); ?>:</label>
1784 <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>
1785 <p><?php _e( 'For multiple default values in multiple select and multiple checkboxes, use | as separator.', 'accua-form-api'); ?></p>
1786 </div>
1787
1788 <div class="form-field">
1789 <label for="form-field-allowed-values"><?php _e( 'Allowed values', 'accua-form-api'); ?>:</label>
1790 <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>
1791 <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>
1792 </div>
1793
1794
1795 <?php
1796 /*
1797 if ( ! is_taxonomy_hierarchical($taxonomy) )
1798 do_action('add_tag_form_fields', $taxonomy);
1799 do_action($taxonomy . '_add_form_fields', $taxonomy);
1800 */
1801
1802 if ($adding) {
1803 submit_button( __( 'Add new field', 'accua-form-api'), 'button' );
1804 } else {
1805 submit_button( __( 'Save changes', 'accua-form-api'), 'button' );
1806 submit_button( __( 'Delete field', 'accua-form-api'), 'button', 'delete-field');
1807 }
1808
1809 /*
1810 // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form
1811 if ( 'category' == $taxonomy )
1812 do_action('edit_category_form', (object)array('parent' => 0) );
1813 elseif ( 'link_category' == $taxonomy )
1814 do_action('edit_link_category_form', (object)array('parent' => 0) );
1815 else
1816 do_action('add_tag_form', $taxonomy);
1817
1818 do_action($taxonomy . '_add_form', $taxonomy);
1819 */
1820 ?>
1821 </form></div>
1822 <?php /* } */ ?>
1823
1824 </div>
1825 </div><!-- /col-left -->
1826
1827 </div><!-- /col-container -->
1828 </div><!-- /wrap -->
1829 <?php
1830 /* echo '<pre>accua_forms_avail_fields:', htmlspecialchars(print_r($avail_fields, true)), '</pre>'; */
1831 }
1832
1833 function accua_forms_settings_page() {
1834 ?>
1835 <div id="accua_forms_settings_page" class="accua_forms_admin_page wrap">
1836 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
1837 <h2><?php _e( 'Default Form settings', 'accua-form-api'); ?></h2>
1838 <?php
1839 $empty_form_data = array(
1840 'success_message' => '',
1841 'error_message' => '',
1842 'emails_from' => '',
1843 'admin_emails_to' => '',
1844 'emails_bcc' => '',
1845 'admin_emails_subject' => '',
1846 'admin_emails_message' => '',
1847 'confirmation_emails_subject' => '',
1848 'confirmation_emails_message' => '',
1849 'layout' => 'sidebyside',
1850 'style_margin' => '',
1851 'style_border_color' => '',
1852 'style_border_width' => '',
1853 'style_border_radius' => '',
1854 'style_background_color' => '',
1855 'style_padding' => '',
1856 'style_color' => '',
1857 'style_font_size' => '',
1858 'style_field_spacing' => '',
1859 'style_field_border_color' => '',
1860 'style_field_border_width' => '',
1861 'style_field_border_radius' => '',
1862 'style_field_background_color' => '',
1863 'style_field_padding' => '',
1864 'style_field_color' => '',
1865 'style_submit_border_color' => '',
1866 'style_submit_border_width' => '',
1867 'style_submit_border_radius' => '',
1868 'style_submit_background_color' => '',
1869 'style_submit_padding' => '',
1870 'style_submit_color' => '',
1871 'style_submit_font_size' => '',
1872 );
1873
1874 $empty_file_data = array(
1875 'valid_extensions' => '',
1876 'max_size' => '',
1877 'dest_path' => '',
1878 );
1879
1880 if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['accua_form_save_form_settings'])) {
1881 $post = stripslashes_deep($_POST);
1882 $post += $empty_form_data;
1883 $post += $empty_file_data;
1884 $form_data = array();
1885 $file_data = array();
1886 foreach($empty_form_data as $key=>$val){
1887 $form_data[$key] = $post[$key];
1888 }
1889 foreach($empty_file_data as $key=>$val){
1890 $file_data[$key] = $post[$key];
1891 }
1892
1893
1894
1895 update_option('accua_forms_default_form_data', $form_data);
1896 update_option('accua_forms_default_file_field_data', $file_data);
1897 } else {
1898 $form_data = get_option('accua_forms_default_form_data',array()) + $empty_form_data;
1899 $file_data = get_option('accua_forms_default_file_field_data',array()) + $empty_file_data;
1900 }
1901 ?>
1902 <form method="post">
1903 <input type="hidden" name="accua_form_save_form_settings" value="1" />
1904 <?php /*
1905 <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>
1906 <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>
1907 <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>
1908 <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>
1909 <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>
1910 <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>
1911 <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>
1912 <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>
1913 <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>
1914 <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>
1915 */ ?>
1916 <div id="accua_tab_messages" class="content_tab">
1917 <?php
1918 $settings_editor = array(
1919 'teeny' => true,
1920 'editor_class' => 'accua_form_value',
1921 'tinymce' => array(
1922 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,'));
1923 ?>
1924 <div class="metabox-holder accua-forms-metabox-holder">
1925 <div class="postbox ">
1926 <h3 class="hndle"><span><?php _e('1. On-screen success message', 'accua-form-api'); ?></span></h3>
1927 <div class="inside" id="dashboard_right_now">
1928 <div id="accua_form_success_message">
1929 <?php wp_editor( $form_data['success_message'] , 'success_message' , $settings_editor); ?>
1930 </div>
1931 </div>
1932 </div>
1933 </div>
1934
1935 <div class="metabox-holder accua-forms-metabox-holder">
1936 <div class="postbox ">
1937 <h3 class="hndle"><span><?php _e('2. On-screen error message', 'accua-form-api'); ?></span></h3>
1938 <div class="inside" id="dashboard_right_now">
1939 <div id="accua_form_error_message">
1940 <?php wp_editor( $form_data['error_message'] , 'error_message' , $settings_editor); ?>
1941 </div>
1942 </div>
1943 </div>
1944 </div>
1945 <br clear="all"/>
1946 <div class="metabox-holder accua-forms-metabox-holder">
1947 <div class="postbox ">
1948 <h3 class="hndle"><span><?php _e('3. Email to notify administrator', 'accua-form-api'); ?></span></h3>
1949 <div class="inside" id="dashboard_right_now">
1950 <div id="accua_form_admin_emails_to" class="label_input">
1951 <label><?php _e( 'To', 'accua-form-api'); ?></label>
1952 <input name="admin_emails_to" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_to'], ENT_QUOTES) ?>" />
1953 </div>
1954 <br clear="all" />
1955 <div id="accua_form_emails_bcc" class="label_input">
1956 <label><?php _e( 'Bcc', 'accua-form-api'); ?></label>
1957 <input name="emails_bcc" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_bcc'], ENT_QUOTES) ?>" />
1958 </div>
1959 <br clear="all" />
1960 <div id="accua_form_admin_emails_subject" class="label_input">
1961 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
1962 <input name="admin_emails_subject" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_subject'], ENT_QUOTES) ?>" />
1963 </div>
1964 <br clear="all" />
1965 <div id="accua_form_admin_emails_message">
1966 <?php wp_editor( $form_data['admin_emails_message'] , 'admin_emails_message' , $settings_editor); ?>
1967 </div>
1968
1969 </div>
1970 </div>
1971 </div>
1972
1973 <div class="metabox-holder accua-forms-metabox-holder">
1974 <div class="postbox ">
1975 <h3 class="hndle"><span><?php _e('4. Email confirmation to the person who completed the form', 'accua-form-api'); ?></span></h3>
1976 <div class="inside" id="dashboard_right_now">
1977 <div id="accua_form_emails_from" class="label_input">
1978 <label><?php _e( 'From', 'accua-form-api'); ?></label>
1979 <input class="accua_form_value" name="emails_from" type="text" value="<?php echo htmlspecialchars($form_data['emails_from'], ENT_QUOTES) ?>" />
1980 </div>
1981 <br clear="all" />
1982 <div id="accua_form_confirmation_emails_subject" class="label_input">
1983 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
1984 <input class="accua_form_value" type="text" name="confirmation_emails_subject" value="<?php echo htmlspecialchars($form_data['confirmation_emails_subject'], ENT_QUOTES) ?>" />
1985 </div>
1986 <br clear="all" />
1987 <div id="accua_form_confirmation_emails_message">
1988 <?php wp_editor( $form_data['confirmation_emails_message'] , 'confirmation_emails_message' , $settings_editor); ?>
1989 </div>
1990 </div>
1991 </div>
1992 </div>
1993 <br clear="all"/>
1994
1995 <div class="metabox-holder accua-forms-metabox-holder">
1996 <div class="postbox ">
1997 <h3 class="hndle"><span><?php _e( 'File upload default settings', 'accua-form-api'); ?></span></h3>
1998 <div class="inside" id="dashboard_right_now">
1999 <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>
2000 <small><?php _e( 'List of valid extensions, without dot, one per line.', 'accua-form-api'); ?></small>
2001 </div>
2002 <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 />
2003 <small><?php _e( 'You can use suffix K, M or G for kilobyte, megabyte or gigabyte.', 'accua-form-api'); ?>
2004 <?php
2005 $server_max_size = AccuaForm_Element_File::file_upload_max_size();
2006 if ($server_max_size > 0) {
2007 _e( 'This value is limited by server upload limits of ', 'accua-form-api');
2008 echo AccuaForm_Element_File::format_size($server_max_size).". ";
2009 _e( 'If you need a greater limit you should ask to the server administrator.', 'accua-form-api');
2010 }
2011 ?>
2012 </small>
2013 </div>
2014 <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) ?>" />
2015 <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>
2016 </div>
2017 </div>
2018 </div>
2019 </div>
2020
2021 <div class="metabox-holder accua-forms-metabox-holder">
2022 <div class="postbox ">
2023 <h3 class="hndle"><span><?php _e( 'Layout &amp; Styling', 'accua-form-api'); ?></span></h3>
2024 <div class="inside" id="dashboard_right_now">
2025 <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>
2026 <h4><?php _e( 'Forms', 'accua-form-api'); ?></h4>
2027 <div id="accua_form_layout"> <?php _e( 'Layout', 'accua-form-api'); ?>
2028 <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>
2029 </div>
2030 <div id="accua_form_style_margin" class="label_input">
2031 <label><?php _e( 'Margin', 'accua-form-api'); ?></label>
2032 <input name="style_margin" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_margin'], ENT_QUOTES) ?>" />
2033 </div>
2034 <div id="accua_form_style_border_color" class="label_input">
2035 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2036 <input name="style_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_color'], ENT_QUOTES) ?>" />
2037 </div>
2038 <div id="accua_form_style_border_width" class="label_input">
2039 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2040 <input name="style_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_width'], ENT_QUOTES) ?>" />
2041 </div>
2042 <div id="accua_form_style_border_radius" class="label_input">
2043 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2044 <input name="style_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_border_radius'], ENT_QUOTES) ?>" />
2045 </div>
2046 <div id="accua_form_style_background_color" class="label_input">
2047 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2048 <input name="style_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_background_color'], ENT_QUOTES) ?>" />
2049 </div>
2050 <div id="accua_form_style_padding" class="label_input">
2051 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2052 <input name="style_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_padding'], ENT_QUOTES) ?>" />
2053 </div>
2054 <div id="accua_form_style_color" class="label_input">
2055 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2056 <input name="style_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_color'], ENT_QUOTES) ?>" />
2057 </div>
2058 <div id="accua_form_style_font_size" class="label_input">
2059 <label><?php _e( 'Font size', 'accua-form-api'); ?></label>
2060 <input name="style_font_size" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_font_size'], ENT_QUOTES) ?>" />
2061 </div>
2062
2063 <h4><?php _e( 'Fields', 'accua-form-api'); ?></h4>
2064 <div id="accua_form_style_field_spacing" class="label_input">
2065 <label><?php _e( 'Spacing', 'accua-form-api'); ?></label>
2066 <input name="style_field_spacing" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_spacing'], ENT_QUOTES) ?>" />
2067 </div>
2068 <div id="accua_form_style_field_border_color" class="label_input">
2069 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2070 <input name="style_field_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_color'], ENT_QUOTES) ?>" />
2071 </div>
2072 <div id="accua_form_style_field_border_width" class="label_input">
2073 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2074 <input name="style_field_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_width'], ENT_QUOTES) ?>" />
2075 </div>
2076 <div id="accua_form_style_field_border_radius" class="label_input">
2077 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2078 <input name="style_field_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_border_radius'], ENT_QUOTES) ?>" />
2079 </div>
2080 <div id="accua_form_style_field_background_color" class="label_input">
2081 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2082 <input name="style_field_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_background_color'], ENT_QUOTES) ?>" />
2083 </div>
2084 <div id="accua_form_style_field_padding" class="label_input">
2085 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2086 <input name="style_field_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_padding'], ENT_QUOTES) ?>" />
2087 </div>
2088 <div id="accua_form_style_field_color" class="label_input">
2089 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2090 <input name="style_field_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_field_color'], ENT_QUOTES) ?>" />
2091 </div>
2092
2093 <h4><?php _e( 'Submit button', 'accua-form-api'); ?></h4>
2094 <div id="accua_form_style_submit_border_color" class="label_input">
2095 <label><?php _e( 'Border color', 'accua-form-api'); ?></label>
2096 <input name="style_submit_border_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_color'], ENT_QUOTES) ?>" />
2097 </div>
2098 <div id="accua_form_style_submit_border_width" class="label_input">
2099 <label><?php _e( 'Border width', 'accua-form-api'); ?></label>
2100 <input name="style_submit_border_width" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_width'], ENT_QUOTES) ?>" />
2101 </div>
2102 <div id="accua_form_style_submit_border_radius" class="label_input">
2103 <label><?php _e( 'Rounded corner radius', 'accua-form-api'); ?></label>
2104 <input name="style_submit_border_radius" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_border_radius'], ENT_QUOTES) ?>" />
2105 </div>
2106 <div id="accua_form_style_submit_background_color" class="label_input">
2107 <label><?php _e( 'Background color', 'accua-form-api'); ?></label>
2108 <input name="style_submit_background_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_background_color'], ENT_QUOTES) ?>" />
2109 </div>
2110 <div id="accua_form_style_submit_padding" class="label_input">
2111 <label><?php _e( 'Padding', 'accua-form-api'); ?></label>
2112 <input name="style_submit_padding" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_padding'], ENT_QUOTES) ?>" />
2113 </div>
2114 <div id="accua_form_style_submit_color" class="label_input">
2115 <label><?php _e( 'Text color', 'accua-form-api'); ?></label>
2116 <input name="style_submit_color" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_color'], ENT_QUOTES) ?>" />
2117 </div>
2118 <div id="accua_form_style_submit_font_size" class="label_input">
2119 <label><?php _e( 'Font size', 'accua-form-api'); ?></label>
2120 <input name="style_submit_font_size" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['style_submit_font_size'], ENT_QUOTES) ?>" />
2121 </div>
2122 <br clear="all" />
2123 </div>
2124 </div>
2125 </div>
2126
2127
2128 <br clear="all"/>
2129
2130 </div>
2131
2132 <?php /*
2133 <h3><?php _e( 'File upload default settings', 'accua-form-api'); ?></h3>
2134 <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>
2135 <small><?php _e( 'List of valid extensions, without dot, one per line.', 'accua-form-api'); ?></small>
2136 </p>
2137 <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 />
2138 <small><?php _e( 'You can use suffix K, M or G for kilobyte, megabyte or gigabyte.', 'accua-form-api'); ?>
2139 <?php
2140 $server_max_size = AccuaForm_Element_File::file_upload_max_size();
2141 if ($server_max_size > 0) {
2142 _e( 'This value is limited by server upload limits of ', 'accua-form-api');
2143 echo AccuaForm_Element_File::format_size($server_max_size).". ";
2144 _e( 'If you need a greater limit you should ask to the server administrator.', 'accua-form-api');
2145 }
2146 ?>
2147 </small></p>
2148 <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) ?>" />
2149 <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>
2150 </p> */ ?>
2151 <p><input class="button button-primary button-large" id="accua_form_save_settings" type="submit" value="Save settings" /></p>
2152 </form>
2153 </div>
2154
2155 <script type='text/javascript'>
2156 jQuery(function($) {
2157 $('#accua_form_style_border_color .accua_form_value').wpColorPicker();
2158 $('#accua_form_style_background_color .accua_form_value').wpColorPicker();
2159 $('#accua_form_style_color .accua_form_value').wpColorPicker();
2160 $('#accua_form_style_field_border_color .accua_form_value').wpColorPicker();
2161 $('#accua_form_style_field_background_color .accua_form_value').wpColorPicker();
2162 $('#accua_form_style_field_color .accua_form_value').wpColorPicker();
2163 $('#accua_form_style_submit_border_color .accua_form_value').wpColorPicker();
2164 $('#accua_form_style_submit_background_color .accua_form_value').wpColorPicker();
2165 $('#accua_form_style_submit_color .accua_form_value').wpColorPicker();
2166 });
2167 </script>
2168
2169 <?php
2170 }
2171
2172 function _accua_forms_get_abs_dest_path($dest_path = '') {
2173 if ($dest_path === '') {
2174 return realpath(ABSPATH) . '/wp-content/uploads/accua-forms';
2175 } else if (substr($dest_path,0,1) === '/') {
2176 return $dest_path;
2177 } else {
2178 return realpath(ABSPATH) . '/' . $dest_path;
2179 }
2180 }
2181
2182 function _accua_forms_get_form_data($fid = false, $return_empty = true, $restore_trash = false){
2183 $empty_form_data = array(
2184 'fields' => array(),
2185 'title' => '',
2186 'success_message' => '',
2187 'error_message' => '',
2188 'emails_from' => '',
2189 'admin_emails_to' => '',
2190 'emails_bcc' => '',
2191 'admin_emails_subject' => '',
2192 'admin_emails_message' => '',
2193 'confirmation_emails_subject' => '',
2194 'confirmation_emails_message' => '',
2195 'use_ajax' => true,
2196 'layout' => 'sidebyside',
2197 'style_margin' => '',
2198 'style_border_color' => '',
2199 'style_border_width' => '',
2200 'style_border_radius' => '',
2201 'style_background_color' => '',
2202 'style_padding' => '',
2203 'style_color' => '',
2204 'style_font_size' => '',
2205 'style_field_spacing' => '',
2206 'style_field_border_color' => '',
2207 'style_field_border_width' => '',
2208 'style_field_border_radius' => '',
2209 'style_field_background_color' => '',
2210 'style_field_padding' => '',
2211 'style_field_color' => '',
2212 'style_submit_border_color' => '',
2213 'style_submit_border_width' => '',
2214 'style_submit_border_radius' => '',
2215 'style_submit_background_color' => '',
2216 'style_submit_padding' => '',
2217 'style_submit_color' => '',
2218 'style_submit_font_size' => '',
2219 );
2220
2221 if ($fid === false) {
2222 return $empty_form_data;
2223 }
2224
2225 $default_form_data = get_option('accua_forms_default_form_data',array());
2226
2227 if ($fid === null) {
2228 return $default_form_data + $empty_form_data;
2229 }
2230
2231 $forms_data = get_option('accua_forms_saved_forms', array());
2232 if ($restore_trash) {
2233 $trash_data = get_option('accua_forms_trash_forms', array());
2234 if (isset($trash_data[$fid])) {
2235 $forms_data[$fid] = $trash_data[$fid];
2236 update_option('accua_forms_saved_forms', $forms_data);
2237 unset($trash_data[$fid]);
2238 update_option('accua_forms_trash_forms', $trash_data);
2239 }
2240 }
2241
2242 if (isset($forms_data[$fid])) {
2243 $form_data = array(
2244 '_overrided' => $forms_data[$fid]
2245 ) + $forms_data[$fid] + $default_form_data + $empty_form_data;
2246 /*
2247 if ($form_data['fields']) {
2248 foreach ($form_data['fields'] as $i => $istance_data) {
2249 // TODO: popuplate default fields data?
2250 }
2251 }
2252 */
2253 return $form_data;
2254 } else if ($return_empty) {
2255 return array(
2256 '_overrided' => array()
2257 ) + $default_form_data + $empty_form_data;
2258 } else {
2259 return null;
2260 }
2261
2262 }
2263
2264 function _accua_forms_style_parameters($params) {
2265 $ret = '';
2266 foreach ($params as $key => $value) {
2267 $value = trim($value);
2268 if ($value !== '') {
2269 if (is_numeric($value)) {
2270 $ret .= "{$key}:{$value}px;";
2271 } else {
2272 $ret .= "{$key}:{$value};";
2273 }
2274 if ($key == 'border-width') {
2275 $ret .= "border-style:solid;";
2276 }
2277 }
2278 }
2279 return $ret;
2280 }
2281
2282 add_action('accua_form_alter', 'accua_forms_form_generate', -999, 2);
2283 function accua_forms_form_generate($baseid, $form) {
2284 if (substr($baseid, 0, 14) == '__accua-form__') {
2285 $fid = substr($baseid,14);
2286 $form_data = _accua_forms_get_form_data($fid, false);
2287 /*
2288 echo '<!-- fid = ';
2289 print_r($fid);
2290 echo "\n\nform_data = ";
2291 print_r($form_data);
2292 echo "\n-->";
2293 */
2294 if ($form_data) {
2295 $form_style = _accua_forms_style_parameters(array(
2296 'margin' => $form_data['style_margin'],
2297 'border-color' => $form_data['style_border_color'],
2298 'border-width' => $form_data['style_border_width'],
2299 'border-radius' => $form_data['style_border_radius'],
2300 'background' => $form_data['style_background_color'],
2301 'padding' => $form_data['style_padding'],
2302 'color' => $form_data['style_color'],
2303 'font-size' => $form_data['style_font_size'],
2304 ));
2305
2306 $field_style = _accua_forms_style_parameters(array(
2307 'margin-bottom' => $form_data['style_field_spacing'],
2308 'border-color' => $form_data['style_field_border_color'],
2309 'border-width' => $form_data['style_field_border_width'],
2310 'border-radius' => $form_data['style_field_border_radius'],
2311 'background' => (trim($form_data['style_field_background_color']) === '')?'transparent':$form_data['style_field_background_color'],
2312 'padding' => $form_data['style_field_padding'],
2313 'color' => (trim($form_data['style_field_color']) === '')?$form_data['style_color']:$form_data['style_field_color'],
2314 'font-size' => $form_data['style_font_size'],
2315 ));
2316 $field_properties = array();
2317 if ($field_style !== '') {
2318 $field_properties['style'] = $field_style;
2319 }
2320
2321 $submit_style = _accua_forms_style_parameters(array(
2322 'border-color' => $form_data['style_submit_border_color'],
2323 'border-width' => $form_data['style_submit_border_width'],
2324 'border-radius' => $form_data['style_submit_border_radius'],
2325 'background' => $form_data['style_submit_background_color'],
2326 'padding' => $form_data['style_submit_padding'],
2327 'color' => $form_data['style_submit_color'],
2328 'font-size' => $form_data['style_submit_font_size'],
2329 ));
2330 $submit_properties = array();
2331 if ($submit_style !== '') {
2332 $submit_properties['style'] = $submit_style;
2333 }
2334
2335 if ($form_style !== '') {
2336 $form->configure(array('style' => $form_style));
2337 }
2338
2339 if (!empty($form_data['use_ajax'])){
2340 $form->configure(array(
2341 "accua_ajax" => 1,
2342 ));
2343 }
2344
2345 $add_submit = true;
2346 $fieldset_open = false;
2347 $avail_fields = get_option('accua_forms_avail_fields', array());
2348
2349 foreach ($form_data['fields'] as $istance_data) {
2350
2351 if (empty($avail_fields[$istance_data['ref']])) {
2352 $field_data = array();
2353 if (!empty($istance_data['ref'])) {
2354 if ($istance_data['ref'] == '__fieldset-begin') {
2355 $field_data = array(
2356 'id' => '__fieldset-begin',
2357 'name' => __('Fieldset begin', 'accua-form-api'),
2358 'type' => 'fieldset-begin',
2359 'description' => '',
2360 );
2361 } else if ($istance_data['ref'] == '__fieldset-end') {
2362 $field_data = array(
2363 'id' => '__fieldset-end',
2364 'name' => __('Fieldset end', 'accua-form-api'),
2365 'type' => 'fieldset-end',
2366 'description' => '',
2367 );
2368 }
2369 }
2370 } else {
2371 $field_data = $avail_fields[$istance_data['ref']];
2372 }
2373
2374 $field_data += array(
2375 'id' => '__html',
2376 'name' => __( 'Custom HTML content', 'accua-form-api'),
2377 'type' => 'html',
2378 'description' => __('Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
2379 'default_value' => '',
2380 'allowed_values' => '',
2381 );
2382
2383 $istance_data += array(
2384 'istance_id' => $field_data['id'],
2385 'widget_number' => '',
2386 'ref' => $field_data['id'],
2387 'label' => $field_data['name'],
2388 'default_value' => $field_data['default_value'],
2389 'allowed_values' => $field_data['allowed_values'],
2390 );
2391
2392 $element = null;
2393
2394 $allowed_val = trim($istance_data['allowed_values']);
2395
2396
2397 if ($field_data['type'] == 'post-multicheckbox') {
2398 $posts = accua_get_pages($allowed_val);
2399 $allowed_values = array();
2400 foreach ($posts as $p) {
2401 //$allowed_values[$p->ID] = apply_filters( 'the_title', $p->post_title, $p->ID );
2402 $allowed_values[$p->ID] = $p->post_title;
2403 }
2404 } else {
2405 if ($field_data['type'] == 'file') {
2406 $filedata = get_option('accua_forms_default_file_field_data',array());
2407 $filedata += array(
2408 'valid_extensions' => '',
2409 'max_filesize' => '',
2410 'dest_path' => '',
2411 );
2412 if ($allowed_val == '') {
2413 $allowed_val = trim($filedata['valid_extensions']);
2414 }
2415 }
2416
2417 $allowed_val = explode("\n",$allowed_val);
2418 $allowed_values = array();
2419 foreach ($allowed_val as $val) {
2420 $val = explode('|',$val,2);
2421 $val[0] = trim($val[0]);
2422 /*
2423 if (empty($val[0])) {
2424 continue;
2425 }
2426 */
2427 if ((!isset($val[1])) || (trim($val[1])==='')) {
2428 if ($val[0] === '') {
2429 continue;
2430 } else {
2431 $val[1] = $val[0];
2432 }
2433 }
2434 $allowed_values[$val[0]] = $val[1];
2435 }
2436 }
2437
2438 switch ($field_data['type']) {
2439 case 'textarea':
2440 $element = new Element_Textarea($istance_data['label'], $istance_data['istance_id'], $field_properties+array('cols' => '50'));
2441 break;
2442 case 'hidden':
2443 $element = new Element_Hidden($istance_data['istance_id'], $istance_data['default_value']);
2444 break;
2445 case 'checkbox':
2446 $val = empty($istance_data['default_value'])?'1':$istance_data['default_value'];
2447 $lab = $istance_data['label'];
2448 if (!empty($istance_data['required'])) {
2449 $lab .= ' <strong>*</strong>';
2450 }
2451 $element = new AccuaForm_Element_Checkbox('', $istance_data['istance_id'], array($val => $lab));
2452 break;
2453 case 'select':
2454 if (!isset($allowed_values[''])) {
2455 $allowed_values = array('' => '') + $allowed_values;
2456 }
2457 $element = new Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, $field_properties);
2458 break;
2459 case 'radio':
2460 $element = new AccuaForm_Element_Radio($istance_data['label'], $istance_data['istance_id'], $allowed_values);
2461 break;
2462 case 'multiselect':
2463 $element = new Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, $field_properties+array('multiple' => true));
2464 break;
2465 case 'multicheckbox':
2466 $element = new AccuaForm_Element_Checkbox($istance_data['label'], $istance_data['istance_id'], $allowed_values);
2467 case 'post-multicheckbox':
2468 $element = new AccuaForm_Element_Checkbox($istance_data['label'], $istance_data['istance_id'], $allowed_values);
2469 break;
2470 case 'file':
2471 $fdata = array();
2472
2473 if ($allowed_values) {
2474 $fdata['validExtensions'] = array_keys($allowed_values);
2475 }
2476
2477 if ($filedata['max_size'] !== ''){
2478 $fdata['maxSize'] = $filedata['max_size'];
2479 }
2480
2481 $fdata['destPath'] = _accua_forms_get_abs_dest_path($filedata['dest_path']);
2482
2483 $element = new AccuaForm_Element_File($istance_data['label'], $istance_data['istance_id'], $field_properties+$fdata);
2484 break;
2485 case 'html':
2486 $element = new Element_HTML($istance_data['default_value']);
2487 break;
2488 case 'email':
2489 case 'autoreply_email':
2490 $element = new AccuaForm_Element_Email($istance_data['label'], $istance_data['istance_id'], $field_properties);
2491 $element->setValidation(new Validation_Email(
2492 str_replace('%element%', $istance_data['label'], __("Attention: '%element%' must contain an email address.", 'accua-form-api'))
2493 ));
2494 //"Errore: '{$istance_data['label']}' deve contenere un indirizzo email valido."
2495 break;
2496 case 'fieldset-begin':
2497 if ($fieldset_open) {
2498 $form->addElement(new AccuaForm_Element_FieldsetEnd());
2499 } else {
2500 $fieldset_open = true;
2501 }
2502 $element = new AccuaForm_Element_FieldsetBegin($istance_data['label']);
2503 break;
2504 case 'fieldset-end':
2505 if ($fieldset_open) {
2506 $element = new AccuaForm_Element_FieldsetEnd();
2507 $fieldset_open = false;
2508 }
2509 break;
2510 case 'submit':
2511 $add_submit = false;
2512 $element = new Element_Button($istance_data['label'], 'submit', $submit_properties+array('name' => $istance_data['istance_id'], 'value' => $istance_data['default_value']));
2513 break;
2514 case 'captcha':
2515 $element = new AccuaForm_Element_Captcha ($istance_data['label'], array("description" => ""));
2516 break;
2517 case 'password':
2518 $element = new Element_Password($istance_data['label'], $istance_data['istance_id'], $field_properties);
2519 break;
2520 case 'password-and-confirm':
2521 $id_2 = "___{$istance_data['istance_id']}___confirmpass";
2522 $element = new Element_Password(__("Password", 'accua-form-api'), $istance_data['istance_id'], $field_properties);
2523 $element_conf = new Element_Password(__("Confirm password", 'accua-form-api'), $id_2, $field_properties);
2524 $element_conf->setValidation(new AccuaForm_Validation_Password());
2525 break;
2526 //case 'textfield':
2527 default:
2528 $element = new Element_Textbox($istance_data['label'], $istance_data['istance_id'], $field_properties);
2529 break;
2530 }
2531
2532 if (!empty($istance_data['required'])) {
2533 $element->setClass('accuaforms-field-required');
2534 if($field_data['type']!='password-and-confirm') {
2535 $element->setValidation(new Validation_Required(
2536 str_replace('%element%', $istance_data['label'], __("Attention: '%element%' is a required field.", 'accua-form-api'))
2537 ));
2538 } else {
2539 $element->setValidation(new Validation_Required(
2540 str_replace('%element%', $istance_data['label'], __("Attention: Passwords are required fields.", 'accua-form-api'))
2541 ));
2542 }
2543 }
2544
2545 if ($elementName = $element->getName()) {
2546 $element->setClass('accuaform-fieldname-'.$elementName);
2547 }
2548
2549 if ($field_data['type']) {
2550 $element->setClass('accuaform-fieldtype-'.$field_data['type']);
2551 }
2552
2553 $form->addElement($element);
2554 if($element_conf!=NULL) {
2555 $form->addElement($element_conf);
2556 $element_conf=NULL;
2557 }
2558 }
2559 if ($fieldset_open) {
2560 $form->addElement(new AccuaForm_Element_FieldsetEnd());
2561 $fieldset_open = false;
2562 }
2563 if ($add_submit) {
2564 $form->addElement(new Element_Button(__('Submit', 'accua-form-api'), 'submit', $submit_properties));
2565 }
2566 }
2567
2568 }
2569 }
2570
2571 function accua_forms_aggregate_submitted_data(&$replace_map, $params = array()) {
2572 if (empty($params['txt']) && empty($params['html']) && empty($params['json']) && empty($params['email'])) {
2573 $params += array(
2574 'txt' => true,
2575 'html' => true,
2576 'json' => true,
2577 'email' => true,
2578 );
2579 }
2580
2581 if (!empty($params['txt'])) {
2582 $replace_map['__submitted_txt'] = implode("\n",$replace_map['__submitted_txt_raw']);
2583 }
2584 if (!empty($params['html'])) {
2585 $replace_map['__submitted_html'] = implode('</td></tr><tr><td>',$replace_map['__submitted_html_raw']);
2586 }
2587 if (!empty($params['json'])) {
2588 $replace_map['__submitted_json'] = json_encode($replace_map['__submitted_json_raw']);
2589 }
2590 if (!empty($params['email'])) {
2591 $replace_map['__autoreply_email'] = implode('; ', $replace_map['__autoreply_email_raw']);
2592 }
2593
2594 }
2595
2596 add_filter('accua_form_validate', 'accua_forms_validation_handler', 10, 4);
2597 function accua_forms_validation_handler($valid, $submittedID, $submittedData, $form){
2598 if (substr($submittedID, 0, 14) == '__accua-form__') {
2599 $fid = substr($submittedID,14);
2600 $form_data = _accua_forms_get_form_data($fid, false);
2601 if ($form_data) {
2602 return apply_filters('accua_forms_validation', $valid, $fid, $submittedData, $form);
2603 }
2604 }
2605 return $valid;
2606 }
2607
2608 add_action('accua_form_submit', 'accua_forms_form_submission_handler', -10, 3);
2609 function accua_forms_form_submission_handler($submittedID, $submittedData, $form) {
2610 if ( empty( $GLOBALS['wp_rewrite'] ) )
2611 $GLOBALS['wp_rewrite'] = new WP_Rewrite();
2612
2613 if (!class_exists('AccuaConditionalReplacer')){
2614 require_once('AccuaConditionalReplacer.php');
2615 }
2616 if (substr($submittedID, 0, 14) == '__accua-form__') {
2617 $fid = substr($submittedID,14);
2618 $form_data = _accua_forms_get_form_data($fid, false);
2619 if ($form_data) {
2620 global $wpdb;
2621
2622 $time = time();
2623
2624 $wpdb->insert(
2625 $wpdb->prefix . 'accua_forms_submissions',
2626 array (
2627 'afs_form_id' => $fid,
2628 'afs_post_id' => $form->stats['pid'],
2629 'afs_ip' => $form->stats['ip'],
2630 'afs_uri' => $form->stats['uri'],
2631 'afs_referrer' => $form->stats['referrer'],
2632 'afs_lang' => $form->stats['lang'],
2633 'afs_created' => gmdate('Y-m-d H:i:s', $form->stats['created']),
2634 'afs_submitted' => gmdate('Y-m-d H:i:s', $time),
2635 'afs_stats' => json_encode(array(
2636 'user_agent' => $form->stats['user_agent'],
2637 'platform' => $form->stats['platform'],
2638 'tentatives' => $form->stats['tentatives'],
2639 'submit_method' => $form->stats['submit_method'],
2640 )),
2641 )
2642 );
2643
2644 $submission_id = $form->stats['submission_id'] = $wpdb->insert_id;
2645
2646
2647
2648 $replace_map = array(
2649 '__fid' => $fid,
2650 '__subid' => $submission_id,
2651 '__pid' => $form->stats['pid'],
2652 '__ip' => $form->stats['ip'],
2653 '__uri' => $form->stats['uri'],
2654 '__url' => $form->stats['url'],
2655 '__referrer' => $form->stats['referrer'],
2656 '__lang' => $form->stats['lang'],
2657 '__locale' => $form->stats['locale'],
2658 '__created' => $form->stats['created'],
2659 '__created_day' => date('l j F Y', $form->stats['created']),
2660 '__created_day_month_year' => date('j F Y', $form->stats['created']),
2661 '__created_hour' => date('G:i', $form->stats['created']),
2662 '__submitted' => $time,
2663 '__submitted_day' => date('l j F Y', $time),
2664 '__submitted_day_month_year' => date('j F Y', $time),
2665 '__submitted_hour' => date('G:i', $time),
2666 '__confirmation_emails_message' => $form_data['confirmation_emails_message'],
2667 '__user_agent' => $form->stats['user_agent'],
2668 '__platform' => $form->stats['platform'],
2669 '__tentatives' => $form->stats['tentatives'],
2670 '__submit_method' => $form->stats['submit_method'],
2671 );
2672
2673 $avail_fields = get_option('accua_forms_avail_fields', array());
2674
2675 $replace_map['__autoreply_email_raw'] = array();
2676 $replace_map['__submitted_txt_raw'] = array();
2677 $replace_map['__submitted_html_raw'] = array();
2678 $replace_map['__submitted_json_raw'] = array();
2679
2680 $_field_data = array();
2681 $_istance_data = array();
2682
2683 foreach ($submittedData as $istance_id => $value) {
2684 if (empty($form_data['fields'][$istance_id])) {
2685 continue;
2686 }
2687 $istance_data = $form_data['fields'][$istance_id];
2688
2689 if (empty($avail_fields[$istance_data['ref']])) {
2690 $fieldset_data = array();
2691 if (!empty($istance_data['ref'])) {
2692 if ($istance_data['ref'] == '__fieldset-begin') {
2693 $field_data = array(
2694 'id' => '__fieldset-begin',
2695 'name' => __('Fieldset begin', 'accua-form-api'),
2696 'type' => 'fieldset-begin',
2697 'description' => '',
2698 );
2699 } else if ($istance_data['ref'] == '__fieldset-end') {
2700 $field_data = array(
2701 'id' => '__fieldset-end',
2702 'name' => __('Fieldset end', 'accua-form-api'),
2703 'type' => 'fieldset-end',
2704 'description' => '',
2705 );
2706 }
2707 }
2708 } else {
2709 $field_data = $avail_fields[$istance_data['ref']];
2710 }
2711
2712 $field_data += array(
2713 'id' => '__html',
2714 'name' => __( 'Custom HTML content', 'accua-form-api'),
2715 'type' => 'html',
2716 'description' => __( 'Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
2717 'default_value' => '',
2718 'allowed_values' => '',
2719 );
2720
2721 /*
2722 echo "<!-- istance_data: "
2723 , print_r($istance_data, true)
2724 , "\nfield_data: "
2725 , print_r($field_data, true)
2726 , "\nvalue: "
2727 , print_r($value, true)
2728 , "\n-->\n";
2729 */
2730
2731 $istance_data += array(
2732 'istance_id' => $field_data['id'],
2733 'widget_number' => '',
2734 'ref' => $field_data['id'],
2735 'label' => $field_data['name'],
2736 'default_value' => $field_data['default_value'],
2737 'allowed_values' => $field_data['allowed_values'],
2738 );
2739
2740 switch ($field_data['type']) {
2741 case 'checkbox':
2742 case 'submit':
2743 if (empty($value)) {
2744 $replace_map[$istance_data['istance_id']] = $value = '';
2745 } else {
2746 if (empty($istance_data['default_value'])) {
2747 $replace_map[$istance_data['istance_id']] = 'Checked';
2748 $value = '1';
2749 } else {
2750 $replace_map[$istance_data['istance_id']] = $value = $istance_data['default_value'];
2751 }
2752 }
2753 break;
2754 case 'multiselect':
2755 case 'multicheckbox':
2756 $replace_map[$istance_data['istance_id']] = implode(', ',$value);
2757 $value = implode('|',$value);
2758 break;
2759 case 'post-multicheckbox':
2760 $el = $form->getElementByName($istance_id);
2761 $opts = $el->getOptions();
2762 $value2 = array();
2763 foreach ($value as $val) {
2764 if (isset($opts[$val])) {
2765 $value2[] = $val . ': ' . trim(preg_replace('/[\s\n\r]+/', ' ', $opts[$val]));
2766 }
2767 }
2768 $replace_map[$istance_data['istance_id']] = $value = implode("\n", $value2);
2769 break;
2770 /*
2771 case 'file':
2772 //URL to file, or attach
2773 break;
2774 */
2775 case 'autoreply_email':
2776 if ($value !== '') {
2777 $replace_map['__autoreply_email_raw'][] = $value;
2778 }
2779 $replace_map[$istance_data['istance_id']] = $value;
2780 break;
2781 case 'file':
2782 //TODO: move temp file to "{$submission_id}_{$field_data['id']}_{$file['name']}"; value is $file['name']
2783 $buildid = $submittedData['_AccuaForm_buildID'];
2784 $file_download_url = '';
2785 $file = $form->getFile($istance_id);
2786 if ($value !== null && $value !== '' && $file) {
2787 if ($form->renameFile($istance_id, "{$submission_id}_{$field_data['id']}_{$file['name']}")) {
2788 $urlfield = rawurlencode($istance_data['istance_id']);
2789 $urlfile = rawurlencode($value);
2790 $file_download_url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$submission_id}&field={$urlfield}&file={$urlfile}";
2791 }
2792 }
2793 $replace_map[$istance_data['istance_id']] = $value;
2794 $replace_map['__download_'.$istance_data['istance_id']] = $file_download_url;
2795 break;
2796 default:
2797 $replace_map[$istance_data['istance_id']] = $value;
2798 }
2799
2800 switch ($field_data['type']) {
2801 case 'file':
2802 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value\t$file_download_url";
2803 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = "$value\t$file_download_url";
2804 $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>";
2805 break;
2806
2807 case 'email':
2808 case 'autoreply_email':
2809 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2810 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2811 $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>";
2812 break;
2813 case 'submit':
2814 break;
2815 default:
2816 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2817 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2818 $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "<strong>{$istance_data['istance_id']}</strong></td><td class='valori_submitted'>".htmlspecialchars($value);
2819 }
2820
2821 $wpdb->insert(
2822 $wpdb->prefix . 'accua_forms_submissions_values',
2823 array (
2824 'afsv_sub_id' => $submission_id,
2825 'afsv_field_id' => $istance_data['istance_id'],
2826 'afsv_type' => $field_data['type'],
2827 'afsv_value' => $value,
2828 ),
2829 array('%d','%s','%s','%s')
2830 );
2831
2832 $_field_data[$istance_data['istance_id']] = $field_data;
2833 $_istance_data[$istance_data['istance_id']] = $istance_data;
2834
2835 }
2836
2837 $replace_map['__autoreply'] = (bool) ($replace_map['__autoreply_email_raw']
2838 && $form_data['confirmation_emails_subject']
2839 && $form_data['confirmation_emails_message']);
2840
2841 accua_forms_aggregate_submitted_data($replace_map);
2842
2843 //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
2844 $replace_map = apply_filters('accua_forms_form_submission_handler', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data);
2845
2846 //Newer filter, with an easier name
2847 $replace_map = apply_filters('accua_forms_submission', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data);
2848
2849 $replace_map['__submitted_html'] = $submitted_html = '<table><tr><td>' . $replace_map['__submitted_html'] . '</td></tr></table>';
2850 unset($replace_map['__submitted_txt_raw'], $replace_map['__submitted_html_raw'], $replace_map['__submitted_json_raw'], $replace_map['__autoreply_email_raw']);
2851
2852 $replacer = new AccuaConditionalReplacer($replace_map);
2853
2854 $confirmation_emails_message = $replace_map['__confirmation_emails_message'];
2855
2856 unset($replace_map['__submitted_html'], $replace_map['__confirmation_emails_message']);
2857 foreach($replace_map as $key => $value) {
2858 $replace_map[$key] = htmlspecialchars($value, ENT_QUOTES);
2859 }
2860 $replace_map['__submitted_html'] = $submitted_html;
2861
2862 $replacer_html = new AccuaConditionalReplacer($replace_map);
2863
2864 $confirmation_emails_message = $replacer_html->doReplace($confirmation_emails_message);
2865 $replacer_html->appendPattern(array('__confirmation_emails_message' => $confirmation_emails_message));
2866
2867 $form_data_replaced = array();
2868
2869 $settings = array(
2870 'emails_from',
2871 'admin_emails_to',
2872 'emails_bcc',
2873 'admin_emails_subject',
2874 'confirmation_emails_subject',
2875 );
2876
2877 foreach($settings as $i) {
2878 $form_data_replaced[$i] = $replacer->doReplace($form_data[$i]);
2879 }
2880
2881 $settings_html = array(
2882 'success_message',
2883 'admin_emails_message',
2884 );
2885
2886 foreach($settings_html as $i) {
2887 $form_data_replaced[$i] = $replacer_html->doReplace($form_data[$i]);
2888 }
2889
2890 AccuaForm::appendSubmittedMessages(wpautop($form_data_replaced['success_message']));
2891
2892 $header = array("Content-Type: text/html; charset=".get_option('blog_charset'));
2893
2894
2895 if ($form_data_replaced['emails_from']) {
2896 $header[] = 'From: '.$form_data_replaced['emails_from'];
2897 }
2898
2899 if ($form_data_replaced['emails_bcc']) {
2900 $header[] = 'Bcc: '.$form_data_replaced['emails_bcc'];
2901 }
2902
2903 if ($form_data_replaced['admin_emails_to']
2904 && $form_data_replaced['admin_emails_subject']) {
2905 /*
2906 $admin_tos = explode(',', strtr($form_data_replaced['admin_emails_to'], "\n\t\r;", ',,,,'));
2907 foreach ($admin_tos as $admin_to) {
2908 $mail1 = wp_mail(trim($admin_to), $form_data_replaced['admin_emails_subject'], $form_data_replaced['admin_emails_message'], $header);
2909 }
2910 */
2911 $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);
2912 }
2913
2914 if ($replace_map['__autoreply'] && $replace_map['__autoreply_email']
2915 && $form_data_replaced['confirmation_emails_subject']
2916 && $confirmation_emails_message) {
2917 $mail2 = wp_mail($replace_map['__autoreply_email'], $form_data_replaced['confirmation_emails_subject'], '<html><head></head><body>'.wpautop($confirmation_emails_message).'</body></html>', $header);
2918 }
2919
2920 /*
2921 echo "<!-- replace_map: "
2922 , print_r($replace_map, true)
2923 , "\nreplace_map: "
2924 , print_r($replace_map, true)
2925 , "\nform_data_replaced: "
2926 , print_r($form_data_replaced, true)
2927 , "\nautoreply_email: "
2928 , print_r($autoreply_email, true)
2929 , "\nmail1: "
2930 , print_r($mail1, true)
2931 , "\nmail2: "
2932 , print_r($mail2, true)
2933 ,"\n-->";
2934 */
2935 }
2936 }
2937 }
2938
2939 function accua_forms_get_submission_data($subid, $options = array()){
2940 //TODO: Completa e usa per sostituire i campi
2941 global $wpdb;
2942 $subid = (int) $subid;
2943 $options += array(
2944 'extra' => true,
2945 'file_format' => 'name',
2946 );
2947 $ret = array();
2948 if ($options['extra']) {
2949 $query1 = "SELECT *
2950 FROM `{$wpdb->prefix}accua_forms_submissions`
2951 WHERE afs_id = $subid";
2952 $data = $wpdb->get_row($query1);
2953 if (!empty($data)) {
2954 $created = $data->afs_created;
2955 $created[10] = 'T';
2956 $created.='.00+00:00';
2957 $created = strtotime($created);
2958 $submitted = $data->afs_submitted;
2959 $submitted[10] = 'T';
2960 $submitted.='.00+00:00';
2961 $submitted = strtotime($submitted);
2962 $ret += array(
2963 '__fid' => $data->afs_form_id,
2964 '__subid' => $subid,
2965 '__pid' => $data->afs_post_id,
2966 '__ip' => $data->afs_id,
2967 '__uri' => $data->afs_uri,
2968 '__referrer' => $data->afs_referrer,
2969 '__lang' => $data->afs_lang,
2970 '__created' => $created,
2971 '__created_day' => date('l j F Y', $created),
2972 '__created_hour' => date('G:i', $created),
2973 '__submitted' => $submitted,
2974 '__submitted_day' => date('l j F Y', $submitted),
2975 '__submitted_hour' => date('G:i', $submitted),
2976 );
2977 }
2978 }
2979
2980 $query2 = "SELECT *
2981 FROM `{$wpdb->prefix}accua_forms_submissions_values`
2982 WHERE afsv_sub_id = $subid";
2983
2984 $data2 = $wpdb->get_results($query2, OBJECT);
2985
2986 foreach ($data2 as $row) {
2987 switch ($row->afsv_type) {
2988 case 'file' :
2989 if ($options['file_format'] == 'url' || $options['file_format'] == 'link') {
2990 $fieldid = rawurlencode($row->afsv_field_id);
2991 $filename = rawurlencode($row->afsv_value);
2992 $url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$row->afsv_sub_id}&field={$fieldid}&file={$filename}";
2993 if ($options['file_format'] == 'url'){
2994 $url = htmlspecialchars($url,ENT_QUOTES);
2995 $filename = htmlspecialchars($row->afsv_value,ENT_QUOTES);
2996 $fielddata = "<a href='{$url}' target='_blank'>{$filename}</a>";
2997 } else {
2998 $fielddata = $url;
2999 }
3000 } else { // $options['file_format'] == 'name'
3001 $fielddata = $row->afsv_value;
3002 }
3003 break;
3004 default:
3005 $fielddata = $row->afsv_value;
3006 }
3007 $ret[$row->afsv_field_id] = $fielddata;
3008 }
3009 return $ret;
3010 }
3011
3012 add_shortcode( 'accua-form', 'accua_forms_shortcode_handler' );
3013 function accua_forms_shortcode_handler($atts, $content = '', $code = '') {
3014 if (empty($atts['fid'])) {
3015 return '';
3016 }
3017
3018 $fid = $atts['fid'];
3019 $form_data = _accua_forms_get_form_data($fid, false);
3020
3021 if (! $form_data) {
3022 return '';
3023 }
3024
3025 $fid = '__accua-form__'.$fid;
3026
3027 $out = '';
3028
3029 if (AccuaForm::getSubmittedID() == $fid) {
3030 /* return "<pre>Form submitted.\n\nData: " . print_r(AccuaForm::getSubmittedData(), true) . '</pre>'; */
3031 $messages = AccuaForm::getSubmittedMessages();
3032 if ($messages) {
3033 $out .= '<div id="_response_messages_'.$fid.'" class="accua-form-messages">'.$messages.'</div>';
3034 }
3035 if (AccuaForm::isValid()) {
3036 return $out;
3037 }
3038 $form = AccuaForm::getSubmittedForm();
3039 } else {
3040 $form = AccuaForm::create($fid, array('layout'=>$form_data['layout']));
3041 }
3042
3043 return $out . $form->render(true);
3044 }
3045
3046 function accua_forms_include($fid, $atts=array(), $content = '', $code = '') {
3047 $atts['fid'] = $fid;
3048 echo accua_forms_shortcode_handler($atts, $content, $code);
3049 }
3050
3051 function accua_forms_submissions_list_page_head(){
3052 require_once('accua-forms-submissions-page.php');
3053 accua_forms_submissions_list_page(true);
3054 }
3055
3056 add_action('wp_ajax_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file');
3057 add_action('wp_ajax_nopriv_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file');
3058 function accua_forms_download_submitted_file(){
3059 $get = stripslashes_deep($_GET);
3060 if (isset($get['subid'],$get['field'],$get['file'])) {
3061 global $wpdb;
3062 $subid = (int) $get['subid'];
3063 $field = $get['field'];
3064 $file = $get['file'];
3065 $query = "SELECT *
3066 FROM `{$wpdb->prefix}accua_forms_submissions_values`
3067 WHERE afsv_sub_id = %d
3068 AND afsv_field_id = %s
3069 AND afsv_value = %s
3070 ";
3071 $query = $wpdb->prepare($query, $subid, $field, $file);
3072 $subval = $wpdb->get_results($query, OBJECT);
3073 if ($subval) {
3074 $file_data = get_option('accua_forms_default_file_field_data',array()) + array('dest_path' => '');
3075 $dest_path = _accua_forms_get_abs_dest_path($file_data['dest_path']);
3076 $filename = "{$dest_path}/{$subid}_{$field}_{$file}";
3077 if (is_file($filename) && is_readable($filename)){
3078 if (function_exists('finfo_open')){
3079 @ $finfo = finfo_open(FILEINFO_MIME);
3080 if ($finfo) {
3081 @ $filetype = finfo_file($finfo, $filename);
3082 @ finfo_close($finfo);
3083 }
3084 }
3085 if (empty($filetype) && function_exists('mime_content_type')){
3086 @ $filetype = mime_content_type($filename);
3087 }
3088 if (empty($filetype)) {
3089 $filetype = "application/octet-stream";
3090 }
3091 header("Content-type: $filetype");
3092 header("Content-length: ".filesize($filename));
3093 header("Content-disposition: attachment; filename=\"$file\"");
3094 readfile($filename);
3095 die('');
3096 }
3097 }
3098 }
3099 header("HTTP/1.0 404 Not Found");
3100 //header("Status: 404 Not Found");
3101 die('File not found');
3102 }
3103
3104 function accua_forms_buildConditionalReplacer($map = array()) {
3105 if (!class_exists('AccuaConditionalReplacer')){
3106 require_once('AccuaConditionalReplacer.php');
3107 }
3108 return new AccuaConditionalReplacer($map);
3109 }
3110
3111
3112 add_action('wp_ajax_accua_forms_preview', 'accua_forms_preview');
3113 function accua_forms_preview() {
3114 if (!current_user_can(10)){
3115 die ('');
3116 }
3117 wp_enqueue_script('jquery');
3118 echo '<html><head>';
3119 wp_print_styles();
3120 wp_print_head_scripts();
3121 echo '</head><body>';
3122 echo accua_forms_shortcode_handler(array('fid'=>$_REQUEST['fid']));
3123 wp_print_footer_scripts();
3124 echo '</body></html>';
3125 die('');
3126 }
3127
3128 //salvataggio file excel
3129 add_action('wp_ajax_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel');
3130 //add_action('wp_ajax_nopriv_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel');
3131
3132 function accua_forms_submission_page_save_excel() {
3133 require_once('accua-forms-submissions-page.php');
3134 $listTable = new Accua_Forms_Submissions_List_Table();
3135 $listTable->prepare_items(true);
3136 $show_col = explode( ',', $_GET['accua_show_field']);
3137 accua_forms_submission_page_save_excel_general($listTable,$show_col,'');
3138 die('');
3139 }
3140
3141
3142
3143 function accua_forms_submission_page_save_excel_general(Accua_Forms_Submissions_List_Table $listTable,array $show_col,$file_name='') {
3144
3145 if (!current_user_can(10)){
3146 header("HTTP/1.0 401 Access Denied");
3147 //header("Status: 401 Access Denied");
3148 die('You are not authorized to access this page.');
3149 }
3150
3151 global $wpdb;
3152
3153 //creo il file excel
3154 header("Content-disposition: attachment; filename=downloads-report".$file_name.".xls");
3155 header("Content-type: application/vnd.ms-excel");
3156 ?><html xmlns:o="urn:schemas-microsoft-com:office:office"
3157 xmlns:x="urn:schemas-microsoft-com:office:excel"
3158 xmlns="http://www.w3.org/TR/REC-html40">
3159 <head>
3160 <meta http-equiv=Content-Type content="text/html; charset=<?php echo get_option('blog_charset'); ?>" />
3161 <meta name=ProgId content=Excel.Sheet />
3162 <style>
3163 <!--
3164 td {vertical-align:top;}
3165 .head_row {font-weight:bold;}
3166 .column-date { mso-number-format:"Short Date"; }
3167 .datetime_cell { mso-number-format:"yyyy\\-mm\\-dd\\ hh\:mm\:ss"; }
3168 -->
3169 </style>
3170 <!--[if gte mso 9]><xml>
3171 <x:ExcelWorkbook>
3172 <x:ExcelWorksheets>
3173 <x:ExcelWorksheet>
3174 <x:WorksheetOptions>
3175 <x:FreezePanes/>
3176 <x:FilterOn/>
3177 <x:SplitHorizontal>1</x:SplitHorizontal>
3178 <x:TopRowBottomPane>1</x:TopRowBottomPane>
3179 <x:ActivePane>2</x:ActivePane>
3180 <x:Panes>
3181 <x:Pane>
3182 <x:Number>3</x:Number>
3183 </x:Pane>
3184 <x:Pane>
3185 <x:Number>2</x:Number>
3186 </x:Pane>
3187 </x:Panes>
3188 </x:WorksheetOptions>
3189 </x:ExcelWorksheet>
3190 </x:ExcelWorksheets>
3191 </x:ExcelWorkbook>
3192 </xml><![endif]-->
3193 </head>
3194 <body>
3195 <table x:str border=1 >
3196 <tr class='head-row'>
3197 <?php
3198 $cols = $listTable->get_columns();
3199 foreach($cols as $col_key=>$col_value) {
3200 if(in_array($col_key, $show_col)) { ?>
3201 <td x:autofilter="all"><?php echo $col_value; ?></td>
3202 <?php }
3203 } ?>
3204 </tr>
3205
3206 <?php
3207 /* gestire la data
3208 $ut_date = $result->date;
3209 $ut_date[10] = 'T';
3210 $ut_date.='.00+00:00';
3211 $excel_date = (strtotime($ut_date) / 86400 + 25569);
3212 $parts_date = explode('-', substr($result->date, 0, 10));
3213 $date = "{$parts_date[2]}/{$parts_date[1]}/{$parts_date[0]}";
3214 echo "<td class='column-date' x:num='$excel_date' SDVAL=\"$excel_date\" SDNUM=\"1033;0;DD/MM/YYYY\">$date</td>\n";
3215 */
3216 ?>
3217 <?php
3218
3219
3220 foreach($listTable->items as $id_submission=>$single_submission) {
3221 echo "<tr>";
3222 foreach($cols as $col_key=>$col_value) {
3223 if(in_array($col_key, $show_col)) {
3224 echo "<td class='.$col_key.'>";
3225 if(isset($single_submission[$col_key])) {
3226 if ( method_exists( $this, 'column_' . $column_name ) ) {
3227 echo call_user_func( array( &$listTable, 'column_' . $col_key ), $single_submission );
3228 }
3229 else {
3230 echo $listTable->column_default( $single_submission, $col_key );
3231 }
3232 }
3233 echo "</td>";
3234 }
3235
3236 }
3237 echo "</tr>";
3238 }
3239
3240 ?>
3241 </table>
3242 </body>
3243 </html>
3244 <?php
3245 }
3246
3247 function accua_forms_print_tokens() {
3248 $avail_fields = get_option('accua_forms_avail_fields', array());
3249 $tokens = '';
3250 foreach($avail_fields as $key=>$value) {
3251 $tokens .= $value['name'] . ": {" . $key . "}\n";
3252 if ($value['type'] == 'file') {
3253 $tokens .= $value['name'] . " (download link): {__download_" . $key . "}\n";
3254 }
3255 }
3256
3257 echo <<<EOT
3258 <div class="accua_forms_token_list">
3259 <h2>Tokens</h2>
3260 <h3>Fields</h3>
3261 <em>These tokens are available only if the field is added to the form</em>
3262 <pre>$tokens</pre>
3263 <h3>Generic tokens</h3>
3264 <pre>{__fid}
3265 {__subid}
3266 {__pid}
3267 {__ip}
3268 {__uri}
3269 {__url}
3270 {__referrer}
3271 {__lang}
3272 {__locale}
3273 {__created}
3274 {__created_day}
3275 {__created_day_month_year}
3276 {__created_hour}
3277 {__submitted}
3278 {__submitted_day}
3279 {__submitted_day_month_year}
3280 {__submitted_hour}
3281 {__user_agent}
3282 {__platform}
3283 {__tentatives}
3284 {__submit_method}
3285 {__submitted_txt}
3286 {__submitted_html}
3287 {__submitted_json}
3288 {__autoreply}
3289 {__autoreply_email}
3290 {__confirmation_emails_message}</pre>
3291 </div>
3292 EOT;
3293 do_action('accua_forms_print_tokens');
3294 }
3295
3296 function &accua_get_pages($args = '') {
3297 global $wpdb;
3298
3299 $defaults = array(
3300 'child_of' => 0, 'sort_order' => 'ASC',
3301 'sort_column' => 'post_title', 'hierarchical' => 1,
3302 'exclude' => array(), 'include' => array(),
3303 'meta_key' => '', 'meta_value' => '',
3304 'authors' => '', 'parent' => -1, 'exclude_tree' => '',
3305 'number' => '', 'offset' => 0,
3306 'post_type' => 'page', 'post_status' => 'publish',
3307 );
3308
3309 $r = wp_parse_args( $args, $defaults );
3310 extract( $r, EXTR_SKIP );
3311 $number = (int) $number;
3312 $offset = (int) $offset;
3313
3314 /*
3315 // Make sure the post type is hierarchical
3316 $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
3317 if ( !in_array( $post_type, $hierarchical_post_types ) )
3318 return false;
3319 */
3320
3321 // Make sure we have a valid post type
3322 if ( !is_array( $post_type ) )
3323 $post_type = explode( ',', $post_type );
3324 if ( array_diff( $post_type, get_post_types() ) )
3325 return false;
3326
3327 // Make sure we have a valid post status
3328 if ( !is_array( $post_status ) )
3329 $post_status = explode( ',', $post_status );
3330 if ( array_diff( $post_status, get_post_stati() ) )
3331 return false;
3332
3333 /*
3334 $cache = array();
3335 $key = md5( serialize( compact(array_keys($defaults)) ) );
3336 if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) {
3337 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
3338 $pages = apply_filters('get_pages', $cache[ $key ], $r );
3339 return $pages;
3340 }
3341 }
3342
3343 if ( !is_array($cache) )
3344 $cache = array();
3345 */
3346
3347 $inclusions = '';
3348 if ( !empty($include) ) {
3349 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
3350 $parent = -1;
3351 $exclude = '';
3352 $meta_key = '';
3353 $meta_value = '';
3354 $hierarchical = false;
3355 $incpages = wp_parse_id_list( $include );
3356 if ( ! empty( $incpages ) ) {
3357 foreach ( $incpages as $incpage ) {
3358 if (empty($inclusions))
3359 $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
3360 else
3361 $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
3362 }
3363 }
3364 }
3365 if (!empty($inclusions))
3366 $inclusions .= ')';
3367
3368 $exclusions = '';
3369 if ( !empty($exclude) ) {
3370 $expages = wp_parse_id_list( $exclude );
3371 if ( ! empty( $expages ) ) {
3372 foreach ( $expages as $expage ) {
3373 if (empty($exclusions))
3374 $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage);
3375 else
3376 $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage);
3377 }
3378 }
3379 }
3380 if (!empty($exclusions))
3381 $exclusions .= ')';
3382
3383 $author_query = '';
3384 if (!empty($authors)) {
3385 $post_authors = preg_split('/[\s,]+/',$authors);
3386
3387 if ( ! empty( $post_authors ) ) {
3388 foreach ( $post_authors as $post_author ) {
3389 //Do we have an author id or an author login?
3390 if ( 0 == intval($post_author) ) {
3391 $post_author = get_user_by('login', $post_author);
3392 if ( empty($post_author) )
3393 continue;
3394 if ( empty($post_author->ID) )
3395 continue;
3396 $post_author = $post_author->ID;
3397 }
3398
3399 if ( '' == $author_query )
3400 $author_query = $wpdb->prepare(' post_author = %d ', $post_author);
3401 else
3402 $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
3403 }
3404 if ( '' != $author_query )
3405 $author_query = " AND ($author_query)";
3406 }
3407 }
3408
3409 $join = '';
3410 $where = "$exclusions $inclusions ";
3411 if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) {
3412 $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
3413
3414 // meta_key and meta_value might be slashed
3415 $meta_key = stripslashes($meta_key);
3416 $meta_value = stripslashes($meta_value);
3417 if ( ! empty( $meta_key ) )
3418 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
3419 if ( ! empty( $meta_value ) )
3420 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
3421
3422 }
3423
3424 if ( $parent >= 0 )
3425 $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
3426
3427
3428 if ( 1 == count ( $post_type ) ) {
3429 $where_post_type = $wpdb->prepare( "post_type = %s", array_shift( $post_type ) );
3430 } else {
3431 $post_type = implode( "', '", $post_type );
3432 $where_post_type = "post_type IN ('$post_type')";
3433 }
3434
3435 if ( 1 == count( $post_status ) ) {
3436 $where_post_type .= $wpdb->prepare( " AND post_status = %s", array_shift( $post_status ) );
3437 } else {
3438 $post_status = implode( "', '", $post_status );
3439 $where_post_type .= " AND post_status IN ('$post_status')";
3440 }
3441
3442 $orderby_array = array();
3443 $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
3444 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
3445 'ID', 'rand', 'comment_count');
3446 foreach ( explode( ',', $sort_column ) as $orderby ) {
3447 $orderby = trim( $orderby );
3448 if ( !in_array( $orderby, $allowed_keys ) )
3449 continue;
3450
3451 switch ( $orderby ) {
3452 case 'menu_order':
3453 break;
3454 case 'ID':
3455 $orderby = "$wpdb->posts.ID";
3456 break;
3457 case 'rand':
3458 $orderby = 'RAND()';
3459 break;
3460 case 'comment_count':
3461 $orderby = "$wpdb->posts.comment_count";
3462 break;
3463 default:
3464 if ( 0 === strpos( $orderby, 'post_' ) )
3465 $orderby = "$wpdb->posts." . $orderby;
3466 else
3467 $orderby = "$wpdb->posts.post_" . $orderby;
3468 }
3469
3470 $orderby_array[] = $orderby;
3471
3472 }
3473 $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title";
3474
3475 $sort_order = strtoupper( $sort_order );
3476 if ( '' !== $sort_order && !in_array( $sort_order, array( 'ASC', 'DESC' ) ) )
3477 $sort_order = 'ASC';
3478
3479 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
3480 $query .= $author_query;
3481 $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
3482
3483 if ( !empty($number) )
3484 $query .= ' LIMIT ' . $offset . ',' . $number;
3485
3486 //echo "<!-- accua_forms_query:\n$query\n-->";
3487
3488 $pages = $wpdb->get_results($query);
3489
3490 if ( empty($pages) ) {
3491 $pages = apply_filters('get_pages', array(), $r);
3492 return $pages;
3493 }
3494
3495 // Sanitize before caching so it'll only get done once
3496 $num_pages = count($pages);
3497 for ($i = 0; $i < $num_pages; $i++) {
3498 $pages[$i] = sanitize_post($pages[$i], 'raw');
3499 }
3500
3501 /*
3502 // Update cache.
3503 update_post_cache( $pages );
3504 */
3505
3506 if ( $child_of || $hierarchical )
3507 $pages = & get_page_children($child_of, $pages);
3508
3509 if ( !empty($exclude_tree) ) {
3510 $exclude = (int) $exclude_tree;
3511 $children = get_page_children($exclude, $pages);
3512 $excludes = array();
3513 foreach ( $children as $child )
3514 $excludes[] = $child->ID;
3515 $excludes[] = $exclude;
3516 $num_pages = count($pages);
3517 for ( $i = 0; $i < $num_pages; $i++ ) {
3518 if ( in_array($pages[$i]->ID, $excludes) )
3519 unset($pages[$i]);
3520 }
3521 }
3522
3523 /*
3524 $cache[ $key ] = $pages;
3525 wp_cache_set( 'get_pages', $cache, 'posts' );
3526 */
3527
3528 $pages = apply_filters('get_pages', $pages, $r);
3529
3530 return $pages;
3531 }
3532