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

2,990 lines 120.7 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
29 wp_enqueue_script('jquery-form');
30 wp_enqueue_script('jquery-color');
31 wp_enqueue_script('jquery-ui-core');
32 wp_enqueue_script('jquery-ui-tabs');
33 wp_enqueue_script('jquery-ui-sortable');
34 wp_enqueue_script('jquery-ui-draggable');
35 wp_enqueue_script('jquery-ui-droppable');
36 wp_enqueue_script('jquery-ui-selectable');
37 wp_enqueue_script('jquery-ui-resizable');
38 wp_enqueue_script('jquery-ui-dialog');
39 wp_enqueue_style('wp-jquery-ui-dialog');
40 }
41
42 function accua_forms_report_page_head(){
43 $column_list = array(
44 'month' => __( 'Month', 'accua-form-api'),
45 'unique_submissions' => __( 'Unique submissions', 'accua-form-api') ,
46 'submissions' => __('Total submissions', 'accua-form-api'),
47 );
48 global $hook_suffix;
49 register_column_headers($hook_suffix, $column_list);
50
51 //$baseurl = WP_PLUGIN_URL.'/'.substr(plugin_basename(__FILE__),0,-strlen(basename(__FILE__)));
52 //echo '<link href="'.$baseurl.'/flot/layout.css" rel="stylesheet" type="text/css">';
53 //echo '<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="'.$baseurl.'/flot/excanvas.min.js"></script><![endif]-->';
54 //echo '<script language="javascript" type="text/javascript" src="'.$baseurl.'/flot/jquery.flot.js"></script>';
55
56 }
57
58
59 function accua_forms_report_page() {
60 ?>
61 <div class="wrap">
62 <h2>Forms submissions report</h2>
63
64 <?php
65 global $wpdb, $hook_suffix;
66 $months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
67
68 $query = "SELECT YEAR(sub_date) AS `year`, MONTH(sub_date) AS `month`, COUNT(DISTINCT `email`) AS `unique_submissions`, COUNT(*) AS `submissions`
69 FROM `{$wpdb->prefix}cformssubmissions`
70 GROUP BY `year`, `month`
71 ORDER BY `year` DESC, `month` DESC";
72
73 $results = $wpdb->get_results($query);
74
75 if ($results) {
76 ?>
77 <style type="text/css">
78 .column-submissions, .column-unique_submissions {
79 text-align: right !important;
80 }
81 </style>
82 <div id="accua-form-report-graph" style="height:300px;"></div>
83 <table class="widefat" id="stnl_review_reviewed">
84 <thead>
85 <tr><?php print_column_headers($hook_suffix); ?></tr>
86 </thead>
87
88 <tfoot>
89 <tr><?php print_column_headers($hook_suffix, false); ?></tr>
90 </tfoot>
91
92 <tbody>
93 <?php
94 $alternate = false;
95 $hidden = get_hidden_columns($hook_suffix);
96 $data = array(
97 array( 'label' => __( 'Unique submissions', 'accua-form-api'), 'data' => array()),
98 array( 'label' => __( 'Total submissions', 'accua-form-api'), 'data' => array()),
99 );
100 foreach ($results as $result){
101 $month = $months[$result->month];
102 echo "<tr class='iedit ".(($alternate = !$alternate)?'alternate':'')."'>\n";
103 echo "<td class='column-month'".(in_array('month', $hidden)?" style='display:none;'":'').">$month {$result->year}</td>\n";
104 echo "<td class='column-unique_submissions'".(in_array('unique_submissions', $hidden)?" style='display:none;'":'').">{$result->unique_submissions}</td>\n";
105 echo "<td class='column-submissions'".(in_array('submissions', $hidden)?" style='display:none;'":'').">{$result->submissions}</td>\n";
106 echo "</tr>\n";
107 $time = mktime(0, 0, 0, $result->month, 1, $result->year) * 1000;
108 $data[0]['data'][] = array($time, (int)$result->unique_submissions);
109 $data[1]['data'][] = array($time, (int)$result->submissions);
110 }
111 /*
112 $year = $results[0]->year;
113 $month = $results[0]->month;
114 while ($year <= $result->year || $month <= $result->month) {
115
116 $month++;
117 if ($month > 12) {
118 $year++;
119 $month = 1;
120 }
121 }
122 */
123 ?>
124 </tbody>
125 </table>
126 <script type="text/javascript">
127 jQuery(function($){
128 var data = <?php echo json_encode($data); ?> ;
129 var options = {
130 xaxis: {
131 //autoscaleMargin: 0.005,
132 mode: "time",
133 timeformat: "%b %y",
134 minTickSize: [1, "month"]
135 },
136 legend: {
137 position: "nw"
138 }
139 };
140 $.plot($("#accua-form-report-graph"), data, options);
141 });
142 </script>
143 <?php
144 }
145 ?>
146
147 </div>
148 <?php
149 }
150
151 function accua_forms_edit_page_head_styles() {
152 wp_admin_css( 'widgets' );
153 wp_enqueue_style( 'accua-forms-admin', plugins_url('accua-forms-admin.css', __FILE__), array(), '1');
154 }
155
156 function accua_forms_edit_page_head_scripts() {
157 //wp_enqueue_script('admin-widgets');
158 /*wp_enqueue_script('jquery-ui-sortable');
159 wp_enqueue_script('jquery-ui-draggable');
160 wp_enqueue_script('jquery-ui-droppable');*/
161 wp_enqueue_script( 'accua-form-fields', plugins_url( 'form-fields.js' , __FILE__ ), array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ) );
162 wp_enqueue_script( 'accua-form-settings', plugins_url( 'form-settings.js' , __FILE__ ), array( 'jquery' ), '0.2.3');
163 }
164
165 function accua_forms_edit_page_head() {
166 if (isset($_POST['accua-form-edit-action']) || (!isset($_GET['fid']))) {
167 _accua_forms_form_edit_action();
168 require_once('accua-forms-list-page.php');
169 accua_forms_list_page_table(true);
170 }
171
172 ?>
173 <style type="text/css">
174 .container > div {
175 padding: 0px;
176 margin-bottom: 6px;
177 }
178 .widget-liquid-right .widget, #wp_inactive_widgets .widget, .widget-liquid-right .sidebar-description, .widget-placeholder {
179 width: 95%;
180 }
181 .column-submissions {
182 text-align: right !important;
183 }
184 </style>
185 <?php
186 }
187
188 add_action( 'wp_ajax_accua-form-fields-order' , 'accua_forms_form_fields_order');
189 function accua_forms_form_fields_order() {
190 $post = stripslashes_deep($_POST);
191 //update_option('accua_forms_form_fields_order_post', $post);
192
193 if (empty($post['sidebars'])) {
194 die('-1');
195 }
196
197 $forms_data = get_option('accua_forms_saved_forms', array());
198
199 foreach ($post['sidebars'] as $fid => $order) {
200 if (strpos($fid, 'cimatti-accua-fields-form-area-') !== 0){
201 die('-1');
202 }
203 $fid = substr($fid, 31);
204
205 $old_fields = $forms_data[$fid]['fields'];
206 unset($forms_data[$fid]['fields']);
207 $new_fields = array();
208
209 $order = explode(',', $order);
210
211 foreach ($order as $i) {
212 $i = preg_replace('/^(new-)?widget-\\d+_/', '', $i);
213 if (isset($old_fields[$i])) {
214 $new_fields[$i] = $old_fields[$i];
215 unset($old_fields[$i]);
216 }
217 }
218
219 if($old_fields){
220 $new_fields += $old_fields;
221 }
222 $forms_data[$fid]['fields'] = $new_fields;
223 }
224
225 update_option('accua_forms_saved_forms', $forms_data);
226
227 die('1');
228 }
229
230 add_action( 'wp_ajax_accua-save-form-field', 'accua_forms_save_form_field');
231 function accua_forms_save_form_field() {
232 $post = stripslashes_deep($_POST);
233
234 //update_option('accua_forms_save_form_field_post', $post);
235
236 $forms_data = get_option('accua_forms_saved_forms', array());
237 $fid = $post['form-id'];
238 if (empty($forms_data[$fid]['fields'])) {
239 $forms_data[$fid]['fields'] = array();
240 }
241
242 @ $wid = $post['widget-id'];
243 if (empty($post['delete_widget'])) {
244 //$istance_id = $post['multi_number'];
245 @ $ref = $post['id_base'];
246 $required = !empty($post["form-field-{$wid}-required"]);
247 $widget_number = empty($post['multi_number']) ? (empty($post['widget_number']) ? '' : $post['widget_number']) : $post['multi_number'];
248
249 $forms_data[$fid]['fields'][$wid] = array (
250 'istance_id' => $wid,
251 'widget_number' => $widget_number,
252 'ref' => $ref,
253 'required' => $required,
254 );
255
256 if (!empty($post["form-field-{$wid}-override-label"])) {
257 @ $label = (string) $post["form-field-{$wid}-label"];
258 $forms_data[$fid]['fields'][$wid]['label'] = $label;
259 }
260
261 if (!empty($post["form-field-{$wid}-override-default-value"])) {
262 @ $default_value = (string) $post["form-field-{$wid}-default-value"];
263 $forms_data[$fid]['fields'][$wid]['default_value'] = $default_value;
264 }
265
266 if (!empty($post["form-field-{$wid}-override-allowed-values"])) {
267 @ $allowed_values = (string) $post["form-field-{$wid}-allowed-values"];
268 $forms_data[$fid]['fields'][$wid]['allowed_values'] = $allowed_values;
269 }
270
271
272 } else {
273 unset($forms_data[$fid]['fields'][$wid]);
274 }
275
276 update_option('accua_forms_saved_forms', $forms_data);
277
278 die('1');
279 }
280
281 add_action( 'wp_ajax_accua-save-form-settings', 'accua_forms_save_form_settings');
282 function accua_forms_save_form_settings() {
283 $post = stripslashes_deep($_POST);
284
285 $forms_data = get_option('accua_forms_saved_forms', array());
286 $fid = $post['form-id'];
287
288
289 $settings = array(
290 'title',
291 'layout',
292 'success_message',
293 'success_message_no_message',
294 'error_message',
295 'error_message_no_message',
296 'emails_from',
297 'admin_emails_to',
298 'emails_bcc',
299 'admin_emails_subject',
300 'admin_emails_message',
301 'admin_emails_message_no_message',
302 'confirmation_emails_subject',
303 'confirmation_emails_message',
304 'confirmation_emails_message_no_message',
305
306 //'use_ajax',
307 );
308
309 // print_r($post);
310
311 foreach($settings as $i) {
312 if (isset($post[$i])) {
313 $forms_data[$fid][$i] = $post[$i];
314 } else {
315 unset($forms_data[$fid][$i]);
316 }
317 }
318
319
320 $forms_data[$fid]['use_ajax'] = !empty($post['use_ajax']);
321
322 update_option('accua_forms_saved_forms', $forms_data);
323
324 print_r($forms_data[$fid]);
325
326 die('');
327 }
328
329 function accua_forms_field_settings_form_counter() {
330 static $i = 0;
331 $i++;
332 return $i;
333 }
334
335 function accua_forms_field_text_settings_form($fid, $field_data=array(), $istance_data=array()){
336 static $html_multi_number = 1;
337 $i = accua_forms_field_settings_form_counter();
338
339 $hidden = '';
340 if (!is_array($istance_data)) {
341 if ($istance_data === 'hidden') {
342 $hidden = 'style="display:none"';
343 }
344 $istance_data = array();
345 $empty_istance = true;
346 } else {
347 $empty_istance = empty($istance_data);
348 }
349
350 if (!is_array($field_data)){
351 $field_data = array();
352 }
353
354 $field_data += array(
355 'id' => '__html',
356 'name' => __( 'Custom HTML content', 'accua-form-api'),
357 'type' => 'html',
358 'description' => __('Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
359 'default_value' => '',
360 'allowed_values' => '',
361 );
362
363 $override_label = isset($istance_data['label']) ? 'checked="checked"' : '';
364 $override_default_value = isset($istance_data['default_value']) ? 'checked="checked"' : '';
365 $override_allowed_values = isset($istance_data['allowed_values']) ? 'checked="checked"' : '';
366
367 if (($field_data['type'] === 'file') && ($field_data['allowed_values'] === '')) {
368 $file_data = get_option('accua_forms_default_file_field_data',array());
369 if (isset($file_data['valid_extensions'])){
370 $field_data['allowed_values'] = $file_data['valid_extensions'];
371 }
372 }
373
374 $istance_data += array(
375 'istance_id' => $field_data['id'],
376 'widget_number' => '',
377 'ref' => $field_data['id'],
378 'label' => $field_data['name'],
379 'default_value' => $field_data['default_value'],
380 'allowed_values' => $field_data['allowed_values'],
381 'required' => false,
382 );
383
384
385
386 foreach ($istance_data as $key => $value) {
387 $istance_data[$key] = htmlspecialchars($istance_data[$key], ENT_QUOTES);
388 }
389
390 foreach ($field_data as $key => $value) {
391 $field_data[$key] = htmlspecialchars($field_data[$key], ENT_QUOTES);
392 }
393
394 $multi_number = '';
395
396 if ($istance_data['ref'] == '__html') {
397 if ($empty_istance) {
398 $add_new = 'multi';
399 $istance_data['istance_id'] .= '-__i__';
400 $istance_data['widget_number'] = 1;
401 $multi_number = 1 + $html_multi_number;
402 } else {
403 if ($html_multi_number < $istance_data['widget_number']) {
404 $html_multi_number = $istance_data['widget_number'];
405 }
406 }
407 } else {
408 $add_new = $empty_istance ? 'single' : '';
409 }
410
411 $fid = htmlspecialchars($fid, ENT_QUOTES);
412 $testi_eot = array (
413 'label' => __( 'Label', 'accua-form-api'),
414 'override' => __( 'override', 'accua-form-api'),
415 'default_value' => __( 'Default value', 'accua-form-api'),
416 'default_values' => __( 'Default value(s)', 'accua-form-api'),
417 'desc_def' => __( 'For multiple default values, use | as separator.', 'accua-form-api'),
418 'allowed_values' => __( 'Allowed values', 'accua-form-api'),
419 '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'),
420 'allowed_extensions' => __( 'Allowed extensions', 'accua-form-api'),
421 'desc_all_ext' => __( 'Accepted file extensions. One per line, without dots.', 'accua-form-api'),
422 'required' => __( 'Required', 'accua-form-api'),
423 'custom_HTML_content' => __( 'Custom HTML content', 'accua-form-api'),
424 'remove' => __( 'Remove', 'accua-form-api'),
425 'close' => __( 'Close', 'accua-form-api'),
426 'save' => __( 'Save', 'accua-form-api')
427 );
428
429
430
431
432 $content = <<<EOT
433 <p><label for="widget-{$istance_data['istance_id']}-label">{$testi_eot['label']}:</label>
434 ({$testi_eot['override']}: <input type="checkbox" name="form-field-{$istance_data['istance_id']}-override-label" value="1" {$override_label} />)<br>
435 <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>
436 EOT;
437
438 $default_value = <<<EOT
439 <p><label for="widget-{$istance_data['istance_id']}-default-value">{$testi_eot['default_value']}:</label>
440 ({$testi_eot['override']}: <input type="checkbox" name="form-field-{$istance_data['istance_id']}-override-default-value" value="1" {$override_default_value} />)<br>
441 <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>
442 EOT;
443
444 $default_values = <<<EOT
445 <p><label for="widget-{$istance_data['istance_id']}-default-value">{$testi_eot['default_value']}:</label>
446 ({$testi_eot['override']}: <input type="checkbox" name="form-field-{$istance_data['istance_id']}-override-default-value" value="1" {$override_default_value} />)<br>
447 <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 />
448 </p>
449 EOT;
450
451 $allowed_values = <<<EOT
452 <p><label for="widget-{$istance_data['istance_id']}-allowed-values">{$testi_eot['allowed_values']}:</label>
453 ({$testi_eot['override']}: <input type="checkbox" name="form-field-{$istance_data['istance_id']}-override-allowed-values" value="1" {$override_allowed_values} />)<br>
454 <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 />
455 {$testi_eot['desc_all']}</p>
456 EOT;
457
458 $allowed_ext = <<<EOT
459 <p><label for="widget-{$istance_data['istance_id']}-allowed-values">{$testi_eot['allowed_extensions']}:</label>
460 ({$testi_eot['override']}: <input type="checkbox" name="form-field-{$istance_data['istance_id']}-override-allowed-values" value="1" {$override_allowed_values} />)<br>
461 <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 />
462 {$testi_eot['desc_all_ext']}</p>
463 EOT;
464
465 $required_checked = empty($istance_data['required']) ? '' : 'checked="checked"';
466 $required = <<<EOT
467 <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>
468 EOT;
469
470 switch ($field_data['type']) {
471 case 'textarea':
472 $content .= <<<EOT
473 <p><label for="widget-{$istance_data['istance_id']}-default-value">{$testi_eot['default_value']}:</label>
474 ({$testi_eot['override']}: <input type="checkbox" name="form-field-{$istance_data['istance_id']}-override-default-value" value="1" {$override_default_value} />)<br>
475 <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>
476 $required
477 EOT;
478 break;
479 case 'hidden':
480 $content = $default_value;
481 break;
482 case 'checkbox':
483 $content .= $default_value . $required;
484 break;
485 case 'select':
486 case 'radio':
487 $content .= $default_value . $allowed_values . $required;
488 break;
489 case 'multiselect':
490 case 'multicheckbox':
491 case 'post-multicheckbox':
492 $content .= $default_values . $allowed_values . $required;
493 break;
494 case 'file':
495 $content .= $allowed_ext . $required;
496 case 'submit':
497 //just the label
498 break;
499 case 'html':
500 $content = <<<EOT
501 <p><label for="widget-{$istance_data['istance_id']}-default-value">{$testi_eot['custom_HTML_content']}</label>
502 ({$testi_eot['override']}: <input type="checkbox" name="form-field-{$istance_data['istance_id']}-override-default-value" value="1" {$override_default_value} />)<br>
503 <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>
504 EOT;
505 break;
506 case 'email':
507 case 'autoreply_email':
508 case 'textfield':
509 default:
510 $content .= $default_value . $required;
511 break;
512 }
513 $adminurl = admin_url();
514 return <<<EOT
515 <div class="widget ui-draggable" id="widget-{$i}_{$istance_data['istance_id']}" $hidden> <div class="widget-top">
516 <div class="widget-title-action">
517 <a href="#available-widgets" class="widget-action hide-if-no-js"></a>
518 </div>
519 <div class="widget-title"><h4>{$field_data['name']}<span class="in-widget-title"></span></h4></div>
520 </div>
521
522 <div class="widget-inside">
523 <form method="post" action="">
524 <div class="widget-content">
525 $content
526 </div>
527 <input type="hidden" value="{$fid}" name="form-id">
528 <input type="hidden" value="{$istance_data['istance_id']}" class="widget-id" name="widget-id">
529 <input type="hidden" value="{$field_data['id']}" class="id_base" name="id_base">
530 <input type="hidden" value="250" class="widget-width" name="widget-width">
531 <input type="hidden" value="200" class="widget-height" name="widget-height">
532 <input type="hidden" value="{$istance_data['widget_number']}" class="widget_number" name="widget_number">
533 <input type="hidden" value="{$multi_number}" class="multi_number" name="multi_number">
534 <input type="hidden" value="{$add_new}" class="add_new" name="add_new">
535
536 <div class="widget-control-actions">
537 <div class="alignleft">
538 <a href="#remove" class="widget-control-remove">{$testi_eot['remove']}</a> |
539 <a href="#close" class="widget-control-close">{$testi_eot['close']}</a>
540 </div>
541 <div class="alignright">
542 <img alt="" title="" class="ajax-feedback" src="{$adminurl}images/wpspin_light.gif">
543 <input type="submit" value="{$testi_eot['save']}" class="button-primary widget-control-save" id="widget-{$istance_data['istance_id']}-savewidget" name="savewidget">
544 </div>
545 <br class="clear">
546 </div>
547 </form>
548 </div>
549
550 <!--<div class="widget-description">
551 {$field_data['description']}
552 </div>-->
553 </div>
554
555 EOT;
556 }
557
558 function accua_forms_add_page($message='') {
559 $forms_data = get_option('accua_forms_saved_forms', array());
560 if (!empty($_GET['fid'])) {
561 $fid = htmlspecialchars(stripslashes($_GET['fid']), ENT_QUOTES);
562 } else {
563 if ($message === '') {
564 $fid = 1 + ((int) get_option('accua_forms_lastid', 0));
565 while (isset($forms_data[$fid])) {
566 $fid++;
567 }
568 update_option('accua_forms_lastid', $fid);
569 $message = _accua_forms_test_clonefrom($fid);
570 if ($message === '') {
571 return accua_forms_edit_page($fid);
572 }
573 } else {
574 $fid = '';
575 }
576 }
577 if (!empty($_GET['clonefrom'])) {
578 $clonefrom = stripslashes($_GET['clonefrom']);
579 } else {
580 $clonefrom = '';
581 }
582 ?>
583
584 <div class="wrap">
585 <h2><?php _e( 'Create a form', 'accua-form-api'); ?> </h2>
586 <?php if ($message !== '') {
587 echo "<div style='border:1px solid; padding: 10px;'>$message</div>";
588 } ?>
589 <form action="admin.php" method="GET">
590 <input type="hidden" name="page" value="accua_forms" />
591 <p>Form id: <input type="text" name="fid" value="<?php echo $fid; ?>" /></p>
592 <?php
593 if ($forms_data) {
594 echo '<p><select name="clonefrom">
595 <option value="">'.__( 'Empty form', 'accua-form-api').'</option>
596 <optgroup label="'.__( 'Clone form:', 'accua-form-api').'">';
597 foreach ($forms_data as $i => $formdata) {
598 $sel = ($i == $clonefrom) ? " selected='selected'" : '';
599 $i = htmlspecialchars($i, ENT_QUOTES);
600 if (isset($formdata['title']) && ('' !== trim($formdata['title']))) {
601 $formtitle = htmlspecialchars($formdata['title']);
602 } else {
603 $formtitle = $i;
604 }
605 echo "<option value='$i'$sel>$formtitle</option>\n";
606 }
607 echo '</optgroup></select></p>';
608 }
609 ?>
610 <p><input type="submit" value="<?php _e( 'Create', 'accua-form-api'); ?>" /></p>
611 </form>
612 </div>
613 <?php
614 }
615
616 function _accua_forms_test_clonefrom($fid){
617 $error = '';
618 if (isset($_GET['clonefrom'])&&$_GET['clonefrom']!=='') {
619 $clonefrom = stripslashes($_GET['clonefrom']);
620 $forms_data = get_option('accua_forms_saved_forms', array());
621 if (isset($forms_data[$fid])){
622 $error .= "<p>".__( 'Form already exists', 'accua-form-api')."</p>";
623 } else if (empty($forms_data[$clonefrom])) {
624 $error .= "<p>".__( 'Source form doesn\'t exists.', 'accua-form-api')."</p>";
625 } else {
626 $forms_data[$fid] = $forms_data[$clonefrom];
627 if (!isset($forms_data[$fid]['title'])) {
628 $forms_data[$fid]['title'] = $clonefrom ." ".__( 'clone', 'accua-form-api');
629 } else {
630 $forms_data[$fid]['title'] .= " ". __( 'clone', 'accua-form-api');
631 }
632 update_option('accua_forms_saved_forms', $forms_data);
633 }
634 }
635 return $error;
636 }
637
638 function _accua_forms_form_edit_action() {
639 static $message = null;
640 if ($message === null) {
641 $message = '';
642 if (isset($_POST['accua-form-edit-action'])){
643 $post = stripslashes_deep($_POST);
644 switch ($post['accua-form-edit-action']) {
645 case 'delete':
646 $fid = $post['form-id'];
647 $forms_data = get_option('accua_forms_saved_forms', array());
648 unset($forms_data[$fid]);
649 update_option('accua_forms_saved_forms', $forms_data);
650 $fid = htmlspecialchars($fid);
651 $message .= sprintf( __( 'Form \"%s\" deleted','accua-form-api' ), $fid );
652 break;
653 }
654 }
655 }
656 return $message;
657 }
658
659 function accua_forms_list_page() {
660 $message = '';
661 if (isset($_POST['accua-form-edit-action'])){
662 $message = _accua_forms_form_edit_action();
663 } else if (isset($_GET['fid'])) {
664 if (!isset($fid)) {
665 $fid = stripslashes($_GET['fid']);
666 }
667 $error = '';
668 if (!preg_match('/^[a-z0-9_-]+$/i', $fid)) {
669 $error .= "<p>".__( 'Only letters, numbers, hyphen and underscores allowed in form identificative name', 'accua-form-api')."</p>";
670 }
671 if (substr($fid,0,2) == '__') {
672 $error .= "<p>".__( 'The identificative name can\'t start with two underscores (__)', 'accua-form-api')."</p>";
673 }
674 if (strlen($fid) > 70) {
675 $error .= "<p>".__( 'You cannot use more than 70 characters for the identificative name', 'accua-form-api')."</p>";
676 }
677 if ($error === '' && (isset($_GET['clonefrom'])&&$_GET['clonefrom']!=='')) {
678 $error .= _accua_forms_test_clonefrom($fid);
679 }
680 if ($error === '') {
681 return accua_forms_edit_page($fid);
682 } else {
683 return accua_forms_add_page($error);
684 }
685 }
686 ?>
687 <div class="wrap">
688 <?php if ($message !== '') {
689 echo "<div style='border:1px solid; padding: 10px;'>$message</div>";
690 } ?>
691 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
692 <h2><?php _e( 'Contact Forms by Cimatti', 'accua-form-api'); ?>
693 <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>
694 </h2>
695 <div ><?php
696 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'),
697 array('%img_c'=>'<img alt="C" src="' . plugins_url('img/cimatti-16-icon.png', __FILE__ ) . '" />')
698 );
699 ?></div>
700 <?php
701 accua_forms_list_page_table();
702 ?>
703 </div>
704 <?php
705 }
706
707 function accua_forms_edit_page($fid) {
708 wp_enqueue_script('jquery-ui-tabs','','','',true);
709 wp_enqueue_script('accua_tabs', plugins_url('accua_tabs.js', __FILE__ ), array( 'jquery' ));
710
711 /*
712 $avail_fields = array(
713 'first_name' => array (
714 'id' => "first_name",
715 'name' => "First Name",
716 'type' => "textfield",
717 'description' => 'This is the first name',
718 ),
719 'last_name' => array (
720 'id' => "last_name",
721 'name' => "Last Name",
722 'type' => "textfield",
723 'description' => 'This is the last name',
724 ),
725 'email' => array (
726 'id' => "email",
727 'name' => "Email",
728 'type' => "email",
729 'description' => 'This is the email',
730 ),
731 );
732 */
733
734 $avail_fields = get_option('accua_forms_avail_fields', array());
735 $default_form_data = get_option('accua_forms_default_form_data',array());
736
737
738
739 $form_data = _accua_forms_get_form_data($fid, true, !empty($_GET['restore']));
740 $form_overrided_data = $form_data['_overrided'];
741
742 $fid_esc = htmlspecialchars($fid, ENT_QUOTES);
743
744 $adminurl = admin_url();
745
746 ?>
747 <div class="wrap" id="accua-forms-edit-form-page">
748 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
749 <h2><?php _e( 'Edit Form', 'accua-form-api'); ?></h2>
750 <div id="titlediv"><br />
751 <label id="title-prompt-text" class="screen-reader-text" for="title"><?php _e( 'Enter title here', 'accua-form-api'); ?></label>
752 <input id="title" type="text" autocomplete="off" value="<?php echo htmlspecialchars($form_data['title'], ENT_QUOTES) ?>" size="30" name="post_title">
753
754 <script type="text/javascript">
755 jQuery(function($){
756 if ( jQuery('#titlediv #title').val() == '' )
757 jQuery('#title-prompt-text').removeClass('screen-reader-text');
758
759 jQuery('#titlediv #title').focus(function() {
760 jQuery('#title-prompt-text').addClass('screen-reader-text');
761 });
762 jQuery('#titlediv #title').blur(function() {
763 if ( jQuery('#titlediv #title').val() == '' )
764 jQuery('#title-prompt-text').removeClass('screen-reader-text');
765 });
766 });
767 </script>
768 </div>
769
770 <div id="accua_tabs">
771 <div id="save_settings_top" class="accua_forms_save_settings_top">
772 <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?'); ?>');">
773 <input type="hidden" name="accua-form-edit-action" value="delete" />
774 <input type="hidden" name="form-id" value="<?php echo $fid_esc; ?>" />
775 <input type="submit" value="<?php _e( 'Delete this form', 'accua-form-api'); ?>" />
776 </form>
777 <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'); ?>" />
778 <span class="accua_form_save_settings_status"></span>
779 </div>
780 <ul id="ul_accua_tabs">
781 <li class="tabs"><a href="#accua_tab_fields"><?php _e( 'Fields', 'accua-form-api'); ?></a></li>
782 <li class="tabs"><a href="#accua_tab_messages"><?php _e( 'Messages', 'accua-form-api'); ?></a></li>
783 <li class="tabs"><a href="#accua_tab_preview"><?php _e( 'Preview/Test', 'accua-form-api'); ?></a></li>
784 </ul>
785 <div id="accua_tab_fields" class="content_tab">
786 <div style="width:69%; float:right;" class="container">
787 <!--
788 <h3>Form Fields</h3>
789 <div id="form_fields_container">
790 </div>
791 -->
792
793 <div class="widget-liquid-right" style="width:100%">
794 <div id="widgets-right" style="width:100%">
795 <div class="widgets-holder-wrap">
796 <div class="sidebar-name">
797 <div class="sidebar-name-arrow"><br></div>
798 <h3><?php _e( 'Form fields', 'accua-form-api'); ?> <span><img alt="" title="" class="ajax-feedback" src="<?php echo $adminurl;?>images/wpspin_dark.gif"></span></h3>
799 </div>
800 <div class="widgets-sortables ui-sortable" id="cimatti-accua-fields-form-area-<?php echo $fid_esc ?>">
801 <div class="sidebar-description" style="width: 95%">
802 <p class="description"><?php _e( 'Drop fields here', 'accua-form-api'); ?></p>
803 </div>
804 <?php
805 foreach ($form_data['fields'] as $field) {
806 if (empty($avail_fields[$field['ref']])) {
807 $ref = array();
808 } else {
809 $ref = $avail_fields[$field['ref']];
810 }
811 echo accua_forms_field_text_settings_form($fid, $ref, $field);
812 }
813 ?>
814 </div>
815 </div>
816 </div>
817 </div>
818
819 </div>
820
821 <div style="width:30%; float:left;">
822 <!--
823 <h3>Available fields</h3>
824 <div id="available_fields_container" class="container">
825 </div>
826 -->
827 <!-- Begin available fields -->
828
829 <div class="widget-liquid-left" style="margin-right:0">
830 <!-- <div id="widgets-left"> -->
831 <div id="widgets-left" style="margin-right:5px;">
832 <div id="available-widgets" class="widgets-holder-wrap">
833 <div class="sidebar-name">
834 <div class="sidebar-name-arrow"><br /></div>
835 <h3><?php _e( 'Available fields', 'accua-form-api'); ?> <span id="removing-widget"><?php _ex('Deactivate', 'removing-widget'); ?> <span></span></span></h3></div>
836 <div class="widget-holder">
837 <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/>
838 <a href="admin.php?page=accua_forms_fields"><strong><?php _e( 'Create new fields here', 'accua-form-api'); ?></strong></a></p>
839
840 <div id="widget-list">
841 <!-- begin fields list -->
842
843 <?php
844 foreach ($avail_fields as $avail_field) {
845 $hidden = (empty($form_data['fields'][$avail_field['id']])) ? false : 'hidden';
846 echo accua_forms_field_text_settings_form($fid, $avail_field, $hidden);
847 }
848 //Custom HTML field
849 echo accua_forms_field_text_settings_form($fid);
850 ?>
851
852 <!-- end fields list -->
853 </div>
854
855 <br class='clear' />
856 </div>
857 <br class="clear" />
858 </div>
859
860 </div>
861 </div>
862 <!-- End available fields -->
863 </div>
864
865
866 <div style="clear:both;">&nbsp;</div>
867
868 <?php /* * / ?>
869 <pre>
870 accua_forms_form_fields_order_post: <?php echo htmlspecialchars(print_r(get_option('accua_forms_form_fields_order_post'), true)); ?>
871
872 accua_forms_save_form_field_post: <?php echo htmlspecialchars(print_r(get_option('accua_forms_save_form_field_post'), true)); ?>
873
874 accua_forms_saved_form_data: <?php echo htmlspecialchars(print_r($form_data, true)); ?>
875
876 </pre>
877 <?php /* */ ?>
878 </div>
879 <div id="accua_tab_messages" class="content_tab">
880 <?php
881 $settings_editor = array(
882 'teeny' => true,
883 'editor_class' => 'accua_form_value',
884 'tinymce' => array(
885 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,'));
886 ?>
887
888 <div class="metabox-holder accua-forms-metabox-holder">
889 <div class="postbox ">
890 <h3 class="hndle"><span><?php _e('1. On-screen success message', 'accua-form-api'); ?></span></h3>
891 <div class="inside" id="dashboard_right_now">
892 <div id="accua_form_success_message">
893 <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'); ?>
894 <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'); ?>
895 <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 />
896 <div class="defalut_message">
897 <?php _e( 'Default Success message', 'accua-form-api'); ?>
898 <div class="defalut_content_message"><?php echo wpautop($default_form_data['success_message']); ?></div>
899 </div>
900 <?php wp_editor( $form_data['success_message'] , 'accua_form_success_message_textarea' , $settings_editor); ?>
901 <!-- <textarea class="accua_form_value" style="width:95%"; cols="80" rows="8"><?php echo htmlspecialchars($form_data['success_message'], ENT_QUOTES) ?></textarea> -->
902 </div>
903 </div>
904 </div>
905 </div>
906
907 <div class="metabox-holder accua-forms-metabox-holder">
908 <div class="postbox ">
909 <h3 class="hndle"><span><?php _e('2. On-screen error message', 'accua-form-api'); ?></span></h3>
910 <div class="inside" id="dashboard_right_now">
911 <div id="accua_form_error_message">
912 <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'); ?>
913 <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'); ?>
914 <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 />
915 <div class="defalut_message">
916 <?php _e( 'Default error message', 'accua-form-api'); ?> <br />
917 <div class="defalut_content_message" ><?php echo wpautop($default_form_data['error_message']); ?></div>
918 </div>
919 <?php wp_editor( $form_data['error_message'] , 'accua_form_error_message_textarea' , $settings_editor); ?>
920 </div>
921 </div>
922 </div>
923 </div>
924 <br clear="all"/>
925 <div class="metabox-holder accua-forms-metabox-holder">
926 <div class="postbox ">
927 <h3 class="hndle"><span><?php _e('3. Email to notify administrator', 'accua-form-api'); ?></span></h3>
928 <div class="inside" id="dashboard_right_now">
929 <div id="accua_form_admin_emails_to" class="label_input">
930 <label><?php _e( 'To', 'accua-form-api'); ?></label>
931 <div class="default_value"><?php echo $default_form_data['admin_emails_to']; ?></div>
932 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_to'], ENT_QUOTES) ?>" />
933 <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'); ?>
934 </div>
935 <div id="accua_form_emails_bcc" class="label_input">
936 <label><?php _e( 'Bcc', 'accua-form-api'); ?></label>
937 <div class="default_value"><?php echo $default_form_data['emails_bcc']; ?></div>
938 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_bcc'], ENT_QUOTES) ?>" />
939 <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'); ?>
940 </div>
941
942 <div id="accua_form_admin_emails_subject" class="label_input">
943 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
944 <div class="default_value"><?php echo $default_form_data['admin_emails_subject']; ?></div>
945 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_subject'], ENT_QUOTES) ?>" />
946 <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'); ?>
947 </div>
948
949 <div id="accua_form_admin_emails_message">
950 <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'); ?>
951 <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'); ?>
952 <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 />
953 <div class="defalut_message">
954 <?php _e( 'Default message', 'accua-form-api'); ?>
955 <div class="defalut_content_message"><?php echo wpautop($default_form_data['admin_emails_message']); ?></div>
956 </div>
957 <?php wp_editor( $form_data['admin_emails_message'] , 'accua_form_admin_emails_message_textarea' , $settings_editor); ?>
958 </div>
959
960 </div>
961 </div>
962 </div>
963
964 <div class="metabox-holder accua-forms-metabox-holder">
965 <div class="postbox ">
966 <h3 class="hndle"><span><?php _e('4. Email confirmation to the person who completed the form', 'accua-form-api'); ?></span></h3>
967 <div class="inside" id="dashboard_right_now">
968 <div id="accua_form_emails_from" class="label_input">
969 <label><?php _e( 'From', 'accua-form-api'); ?></label>
970 <div class="default_value"><?php echo $default_form_data['emails_from']; ?></div>
971 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_from'], ENT_QUOTES) ?>" />
972 <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'); ?>
973 </div>
974 <div id="accua_form_confirmation_emails_subject" class="label_input">
975 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
976 <div class="default_value"><?php echo $default_form_data['confirmation_emails_subject']; ?></div>
977 <input class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['confirmation_emails_subject'], ENT_QUOTES) ?>" />
978 <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'); ?>
979 </div>
980
981 <div id="accua_form_confirmation_emails_message">
982 <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'); ?>
983 <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'); ?>
984 <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 />
985 <div class="defalut_message">
986 <?php _e( 'Default message', 'accua-form-api'); ?>
987 <div class="defalut_content_message"><?php echo wpautop($default_form_data['confirmation_emails_message']); ?></div>
988 </div>
989 <?php wp_editor( $form_data['confirmation_emails_message'] , 'accua_form_confirmation_emails_message_textarea' , $settings_editor); ?>
990 </div>
991 </div>
992 </div>
993 </div>
994 <br clear="all"/>
995
996 <?php accua_forms_print_tokens(); ?>
997
998 <input type="hidden" id="accua_form_save_settings_id" value="<?php echo $fid_esc; ?>" />
999 </div>
1000
1001 <div id="accua_tab_preview" class="content_tab">
1002 <p id="accua_form_layout"><?php _e('Layout', 'accua-form-api'); ?> <select name="layout" class="accua_form_value">
1003 <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>
1004 </p>
1005 <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>
1006 <p style="clear:both;"><?php _e( 'Preview is updated when you click on "Save settings" button', 'accua-form-api'); ?></p>
1007 <div id="accua_form_preview_area_wrapper">
1008 <iframe id="accua_form_preview_area" src="admin-ajax.php?action=accua_forms_preview&fid=<?php echo htmlspecialchars($fid,ENT_QUOTES);?>" ></iframe>
1009 </div>
1010 </div>
1011 <p></p>
1012 <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>
1013
1014 </div>
1015 <script>
1016 jQuery('input[type=radio]').change(function() {
1017 var name = jQuery(this).attr('name');
1018 if (jQuery(this).val() == '1') {
1019 jQuery('#'+name+' .defalut_message').hide();
1020 jQuery('#'+name+' .wp-editor-wrap').show();
1021 }
1022 else {
1023 if(jQuery(this).val() != '-1')
1024 jQuery('#'+name+' .defalut_message').show();
1025 else
1026 jQuery('#'+name+' .defalut_message').hide();
1027 jQuery('#'+name+' .wp-editor-wrap').hide();
1028 }
1029 });
1030
1031 jQuery('input[type=checkbox]').click(function() {
1032 var name = jQuery(this).attr('name');
1033 if (!this.checked) {
1034 jQuery('#'+name+' .default_value').show();
1035 jQuery('#'+name+' .accua_form_value').hide();
1036 }
1037 else {
1038 jQuery('#'+name+' .default_value').hide();
1039 jQuery('#'+name+' .accua_form_value').show();
1040 }
1041 });
1042
1043 jQuery(".token_link").click(function() {
1044 jQuery("#dialog_token").dialog("open");
1045 return false;
1046 });
1047
1048 //inizializzazione
1049 jQuery(document).ready(function($){
1050 $('#accua_form_preview_area_wrapper').resizable({handles: 's'});
1051 $('#accua_form_preview_area').css({
1052 'width': '100%',
1053 'height': '100%'
1054 });
1055 $.each(
1056 ['success_message','error_message','admin_emails_message','confirmation_emails_message'],
1057 function(i,key){
1058 var value = $('#accua_form_'+key+' .accua_form_check_override:checked').val();
1059 if(value!=undefined && value!=0) {
1060 if(value!=-1)
1061 jQuery('#accua_form_'+key+' .wp-editor-wrap').show();
1062 else
1063 jQuery('#accua_form_'+key+' .wp-editor-wrap').hide();
1064 jQuery('#accua_form_'+key+' .defalut_message').hide();
1065
1066 }
1067 else {
1068 jQuery('#accua_form_'+key+' .wp-editor-wrap').hide();
1069 jQuery('#accua_form_'+key+' .defalut_message').show();
1070 }
1071 }
1072 );
1073 $.each(
1074 ['emails_from','admin_emails_to','emails_bcc','admin_emails_subject','confirmation_emails_subject'],
1075 function(i,key){
1076 if(!$('#accua_form_'+key+' .accua_form_check_override').is(':checked')) {
1077 jQuery('#accua_form_'+key+' .default_value').show();
1078 jQuery('#accua_form_'+key+' .accua_form_value').hide();
1079 }
1080 else {
1081 jQuery('#accua_form_'+key+' .default_value').hide();
1082 jQuery('#accua_form_'+key+' .accua_form_value').show();
1083 }
1084 });
1085 $("#dialog_token").dialog({ dialogClass:'wp-dialog' ,autoOpen : false, modal : true, show : "blind", hide : "blind"});
1086
1087 $('#accua_token a').appendTo('.wp-media-buttons');
1088
1089 });
1090
1091 jQuery(document).ready(function($){
1092
1093 var originalWidth = $(document).width();
1094 if(originalWidth <= 883) { //iphone
1095 $(".metabox-holder").width('98%');
1096 }
1097
1098 $(window).resize(function (e) {
1099 var newWidth = $(document).width();
1100 if(newWidth <= 883) {
1101 if (originalWidth > 883) {
1102 $(".metabox-holder").width('98%');
1103 }
1104 } else if (originalWidth<=883) {
1105 $(".metabox-holder").width('47%');
1106 }
1107 originalWidth = newWidth;
1108 });
1109 });
1110
1111 </script>
1112
1113 <?php
1114 }
1115
1116 function accua_forms_fields_page_head() {
1117 /*
1118 $baseurl = WP_PLUGIN_URL.'/'.substr(plugin_basename(__FILE__),0,-strlen(basename(__FILE__)));
1119 ?>
1120 <script type="text/javascript" src="<?php echo $baseurl.'/qtip/jquery.qtip-1.0.0-rc3.js'; ?>"></script>
1121 <script type="text/javascript">
1122 var avail_fields = {
1123 first_name: {
1124 id: "first_name",
1125 name: "First Name",
1126 type: "textfield"
1127 },
1128 last_name: {
1129 id: "last_name",
1130 name: "Last Name",
1131 type: "textfield"
1132 },
1133 email: {
1134 id: "email",
1135 name: "Email",
1136 type: "email"
1137 }
1138 };
1139
1140 jQuery(function($){
1141 $avail = $('#available_fields_container');
1142 for(var id in avail_fields) {
1143 var field = avail_fields[id];
1144 var el = $('<div></div>').text(field.name);
1145 el.prepend('<input type="checkbox" />');
1146 var content = $('<div><span>Id: </span></div>');
1147 content.append($('<input type="text" />').val(field.id));
1148 content.append($('<br /><span>Name: </span>'));
1149 content.append($('<input type="text" />').val(field.name));
1150 content.append($('<br /><span>Type: </span>'));
1151 content.append($('<select><option value="textfield">Textfield</option><option value="textarea">Textarea</option><option value="email">Email</option></select>').val(field.type));
1152 el.qtip({
1153 content: {
1154 text: content
1155 },
1156 position: {
1157 target: 'mouse',
1158 corner: {
1159 target: 'bottomRight',
1160 tooltip: 'topLeft'
1161 },
1162 adjust: {
1163 mouse: false
1164 }
1165 },
1166 show: {
1167 when: {
1168 event: 'mouseover'
1169 },
1170 solo: true
1171 },
1172 hide: {
1173 when: {
1174 event: 'unfocus'
1175 }
1176 }
1177 });
1178 $avail.append(el);
1179 }
1180 });
1181 </script>
1182 <style type="text/css">
1183 .container > div {
1184 padding: 0px;
1185 margin-bottom: 6px;
1186 }
1187 </style>
1188 <?php
1189 */
1190 }
1191
1192 function accua_forms_fields_page() {
1193 /*
1194 ?>
1195 <div class="wrap"><h2>Edit Form Fields</h2>
1196 <div id="available_fields_container" class="container"></div>
1197 </div>
1198 <?php
1199 */
1200 $message = '';
1201
1202 /*
1203 $avail_fields = array(
1204 'first_name' => array (
1205 'id' => "first_name",
1206 'name' => "First Name",
1207 'type' => "textfield",
1208 'description' => 'This is the first name',
1209 ),
1210 'last_name' => array (
1211 'id' => "last_name",
1212 'name' => "Last Name",
1213 'type' => "textfield",
1214 'description' => 'This is the last name',
1215 ),
1216 'email' => array (
1217 'id' => "email",
1218 'name' => "Email",
1219 'type' => "email",
1220 'description' => 'This is the email',
1221 ),
1222 );
1223 */
1224
1225 $avail_fields = get_option('accua_forms_avail_fields', array());
1226
1227 $default_form_values = array(
1228 'id' => '',
1229 'name' => '',
1230 'type' => 'textfield',
1231 'description' => '',
1232 'default_value' => '',
1233 'allowed_values' => '',
1234 );
1235
1236 $editing = false;
1237 $adding = true;
1238
1239 if (!empty($_POST['action'])) {
1240 $post = stripslashes_deep($_POST);
1241 switch($post['action']) {
1242 case 'edit-form-field':
1243 if (empty($avail_fields[$post['form-field-id']])) {
1244 $message .= 'Field "'.htmlspecialchars($post['form-field-id']).'" doesn\'t exists';
1245 } else {
1246 if (empty($post['delete-field'])) {
1247 $avail_fields[$post['form-field-id']] = array(
1248 'id' => $post['form-field-id'],
1249 'name' => $post['form-field-name'],
1250 'type' => $post['form-field-type'],
1251 'description' => $post['form-field-description'],
1252 'default_value' => $post['form-field-default-value'],
1253 'allowed_values' => $post['form-field-allowed-values'],
1254 );
1255 $message .= sprintf( __( 'Field "%s" updated', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1256 } else {
1257 unset ($avail_fields[$post['form-field-id']]);
1258 $message .= sprintf( __( 'Field "%s" deleted', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1259 }
1260 update_option('accua_forms_avail_fields', $avail_fields);
1261 }
1262 break;
1263 case 'add-form-field':
1264 $fill_form_fields = true;
1265 $valid = true;
1266 if (empty($post['form-field-id']) || !preg_match('/^[a-z0-9_-]+$/i', $post['form-field-id'])) {
1267 $message .= "<p>".__( 'Only letters, numbers, hyphen and underscores allowed in field identificative slug', 'accua-form-api')."</p>";
1268 $valid = false;
1269 }
1270 if(substr($post['form-field-id'], 0, 2) == '__') {
1271 $message .= "<p>".__( 'The field identificative slug can\'t start with two underscores (__)', 'accua-form-api')."</p>";
1272 $valid = false;
1273 }
1274 if (!empty($avail_fields[$post['form-field-id']])) {
1275 $message .= sprintf( __( '<p>A field with identificative slug "%s" already exists</p> Field "%s" deleted', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1276 $valid = false;
1277 }
1278 if (strlen($post['form-field-id']) > 70) {
1279 $message .= "<p>".__( 'The identificative slug cannot be longer than 70 characters', 'accua-form-api')."</p>";
1280 $valid = false;
1281 }
1282 if ($valid) {
1283 $fill_form_fields = false;
1284 $avail_fields[$post['form-field-id']] = array(
1285 'id' => $post['form-field-id'],
1286 'name' => $post['form-field-name'],
1287 'type' => $post['form-field-type'],
1288 'description' => $post['form-field-description'],
1289 'default_value' => $post['form-field-default-value'],
1290 'allowed_values' => $post['form-field-allowed-values'],
1291 );
1292 update_option('accua_forms_avail_fields', $avail_fields);
1293 $message .= sprintf( __( 'Field "%s" created', 'accua-form-api'), htmlspecialchars($post['form-field-id']) );
1294 }
1295 if ($fill_form_fields) {
1296 $editing = true;
1297 $default_form_values = array(
1298 'id' => $post['form-field-id'],
1299 'name' => $post['form-field-name'],
1300 'type' => $post['form-field-type'],
1301 'description' => $post['form-field-description'],
1302 'default_value' => $post['form-field-default-value'],
1303 'allowed_values' => $post['form-field-allowed-values'],
1304 );
1305 }
1306 break;
1307 }
1308 } else if (!empty($_GET['edit-fid'])) {
1309 $fid = stripslashes($_GET['edit-fid']);
1310 if (empty($avail_fields[$fid])) {
1311 $message .= sprintf( __( 'Field "%s" doesn\'t exists', 'accua-form-api'), $fid );
1312 } else {
1313 $adding = false;
1314 $editing = true;
1315 $default_form_values = $avail_fields[$fid];
1316 }
1317 }
1318
1319 ?>
1320 <div class="wrap nosubsub">
1321 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
1322 <h2><?php _e( 'Form fields', 'accua-form-api'); ?></h2>
1323 <?php /* screen_icon(); ?>
1324 <h2><?php echo esc_html( $title );
1325 if ( !empty($_REQUEST['s']) )
1326 printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?>
1327 </h2>
1328
1329 <?php if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) ) : ?>
1330 <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
1331 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
1332 endif; */ ?>
1333 <div id="ajax-response"><?php echo $message?></div>
1334
1335 <?php /*
1336 <form class="search-form" action="" method="get">
1337 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1338 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1339
1340 <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
1341
1342 </form>
1343 */ ?>
1344
1345 <br class="clear" />
1346
1347 <div id="col-container">
1348
1349 <div id="col-right">
1350 <div class="col-wrap">
1351 <?php if (!$editing) { ?>
1352 <form id="posts-filter" action="" method="post">
1353 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1354 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1355
1356 <?php /* $wp_list_table->display(); */ ?>
1357
1358 <table cellspacing="0" class="wp-list-table widefat fixed tags">
1359 <thead>
1360 <tr>
1361 <th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox" /></th>
1362 <th style="" class="manage-column column-name" id="name" scope="col"><?php _e( 'Label', 'accua-form-api'); ?></th>
1363 <th style="" class="manage-column column-description" id="description" scope="col"><?php _e( 'Description', 'accua-form-api'); ?></th>
1364 <th style="" class="manage-column column-slug" id="slug" scope="col"><?php _e( 'Slug', 'accua-form-api'); ?></th>
1365 <th style="" class="manage-column column-type" id="type" scope="col"><?php _e( 'Type', 'accua-form-api'); ?></th>
1366 </tr>
1367 </thead>
1368
1369 <tfoot>
1370 <tr>
1371 <th style="" class="manage-column column-cb check-column" scope="col"><input type="checkbox" /></th>
1372 <th style="" class="manage-column column-name" scope="col"><?php _e( 'Label', 'accua-form-api'); ?></th>
1373 <th style="" class="manage-column column-description" scope="col"><?php _e( 'Description', 'accua-form-api'); ?></th>
1374 <th style="" class="manage-column column-slug" scope="col"><?php _e( 'Slug', 'accua-form-api'); ?></th>
1375 <th style="" class="manage-column column-type" scope="col"><?php _e( 'Type', 'accua-form-api'); ?></th>
1376 </tr>
1377 </tfoot>
1378
1379 <tbody class="list:tag" id="the-list">
1380 <?php
1381 foreach ($avail_fields as $id => $field) {
1382 foreach (array('id', 'name', 'type', 'description') as $i) {
1383 $field[$i] = htmlspecialchars($field[$i], ENT_QUOTES);
1384 }
1385 echo <<<END_OF_ROW
1386 <tr id="field-{$field['id']}">
1387 <th class="check-column" scope="row"><input type="checkbox" /></th>
1388 <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>
1389 <td class="description column-description">{$field['description']}</td>
1390 <td class="slug column-slug">{$field['id']}</td>
1391 <td class="type column-type">{$field['type']}</td>
1392 </tr>
1393 END_OF_ROW;
1394 }
1395 ?>
1396 </tbody>
1397 </table>
1398
1399 <br class="clear" />
1400 </form>
1401 <?php } ?>
1402 <?php /* if ( 'category' == $taxonomy ) : ?>
1403 <div class="form-wrap">
1404 <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>
1405 <?php if ( current_user_can( 'import' ) ) : ?>
1406 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
1407 <?php endif; ?>
1408 </div>
1409 <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
1410 <div class="form-wrap">
1411 <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>'), 'import.php') ;?>.</p>
1412 </div>
1413 <?php endif;
1414 do_action('after-' . $taxonomy . '-table', $taxonomy);
1415 */ ?>
1416
1417 </div>
1418 </div><!-- /col-right -->
1419
1420 <div id="col-left">
1421 <div class="col-wrap">
1422
1423 <?php
1424 /*
1425 if ( !is_null( $tax->labels->popular_items ) ) {
1426 if ( current_user_can( $tax->cap->edit_terms ) )
1427 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
1428 else
1429 $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
1430
1431 if ( $tag_cloud ) :
1432 ?>
1433 <div class="tagcloud">
1434 <h3><?php echo $tax->labels->popular_items; ?></h3>
1435 <?php echo $tag_cloud; unset( $tag_cloud ); ?>
1436 </div>
1437 <?php
1438 endif;
1439 }
1440 */
1441
1442 /*
1443 if ( current_user_can($tax->cap->edit_terms) ) {
1444 // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form
1445 if ( 'category' == $taxonomy )
1446 do_action('add_category_form_pre', (object)array('parent' => 0) );
1447 elseif ( 'link_category' == $taxonomy )
1448 do_action('add_link_category_form_pre', (object)array('parent' => 0) );
1449 else
1450 do_action('add_tag_form_pre', $taxonomy);
1451
1452 do_action($taxonomy . '_pre_add_form', $taxonomy);
1453 */
1454
1455 $types = array(
1456 'textfield' => __( 'Text Field', 'accua-form-api'),
1457 'textarea' => __( 'Text Area', 'accua-form-api'),
1458 'email' => __( 'Email', 'accua-form-api'),
1459 'autoreply_email' => __( 'Autoreply Email', 'accua-form-api'),
1460 'checkbox' => __( 'Checkbox','accua-form-api'),
1461 'select' => __('Select', 'accua-form-api'),
1462 'radio' => __( 'Radio buttons', 'accua-form-api'),
1463 'multiselect' => __( 'Multiple selections area', 'accua-form-api'),
1464 'multicheckbox' => __( 'Multiple checkboxes', 'accua-form-api'),
1465 'post-multicheckbox' => __( 'Multiple post checkboxes', 'accua-form-api'),
1466 'hidden' => __('Hidden value', 'accua-form-api'),
1467 'file' => __('File upload', 'accua-form-api'),
1468 'submit' => __( 'Submit button', 'accua-form-api'),
1469 'html' => __( 'Custom HTML', 'accua-form-api'),
1470 'captcha' => __( 'Captcha', 'accua-form-api'),
1471 'password' => 'Password',
1472 'password-and-confirm' => __( 'Password and password confirmation','accua-form-api'),
1473 );
1474
1475
1476 ?>
1477 <div class="form-wrap">
1478 <h3><?php echo $adding? __( 'Add new field','accua-form-api'): __( 'Edit field','accua-form-api') ; ?></h3>
1479 <form id="addtag" method="post" action="admin.php?page=accua_forms_fields" class="validate">
1480 <input type="hidden" name="action" value="<?php echo $adding?'add':'edit'; ?>-form-field" />
1481 <?php /*
1482 <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
1483 <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
1484 <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
1485 */ ?>
1486 <?php wp_nonce_field('add-tag', '_wpnonce_add-form-field'); ?>
1487
1488 <div class="form-field form-required">
1489 <label for="tag-name"><?php _e( 'Field label', 'accua-form-api'); ?></label>
1490 <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" />
1491 <p><?php _e('The name is how it appears on your site.', 'accua-form-api'); ?></p>
1492 </div>
1493 <?php /* if ( ! global_terms_enabled() ) : */ ?>
1494 <div class="form-field">
1495 <label for="tag-slug"><?php _e( 'Field slug (identificative)', 'accua-form-api'); ?></label>
1496 <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" />
1497 <?php if (!$adding) { echo '<input type="hiden" name="form-field-id" value="'.htmlspecialchars($default_form_values['id'], ENT_QUOTES).'" />'; } ?>
1498 <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>
1499 </div>
1500 <div class="form-field">
1501 <label for="parent"><?php _e( 'Field type', 'accua-form-api'); ?></label>
1502 <select class="postform" id="parent" name="form-field-type">
1503 <?php /*
1504 <option value="textfield" class="level-0" <?php echo ($default_form_values['type'] == 'textfield')?'selected="selected"':'';?> >Text Field</option>
1505 <option value="textarea" class="level-0" <?php echo ($default_form_values['type'] == 'textarea')?'selected="selected"':'';?> >Text Area</option>
1506 <option value="email" class="level-0" <?php echo ($default_form_values['type'] == 'email')?'selected="selected"':'';?> >Email</option>
1507 <option value="checkbox" class="level-0" <?php echo ($default_form_values['type'] == 'checkbox')?'selected="selected"':'';?> >Checkbox</option>
1508 <option value="select" class="level-0" <?php echo ($default_form_values['type'] == 'select')?'selected="selected"':'';?> >Select</option>
1509 */
1510 foreach ($types as $typeid => $typename) {
1511 $selected = ($default_form_values['type'] == $typeid)?'selected="selected"':'';
1512 echo <<<EOT
1513 <option value="{$typeid}" class="level-0" {$selected} >{$typename}</option>
1514 EOT;
1515 }
1516
1517 ?>
1518 </select>
1519 </div>
1520 <?php /* endif; // global_terms_enabled() */ ?>
1521 <?php /* if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
1522 <div class="form-field">
1523 <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
1524 <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
1525 <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
1526 <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>
1527 <?php endif; ?>
1528 </div>
1529 <?php endif; // is_taxonomy_hierarchical() */ ?>
1530 <div class="form-field">
1531 <label for="tag-description"><?php _e( 'Field description', 'accua-form-api'); ?></label>
1532 <textarea name="form-field-description" id="tag-description" rows="5" cols="40"><?php echo htmlspecialchars($default_form_values['description'], ENT_QUOTES) ?></textarea>
1533 <p><?php _e('The description is not prominent by default; however, some themes may show it.', 'accua-form-api'); ?></p>
1534 </div>
1535
1536 <div class="form-field">
1537 <label for="form-field-default-value"><?php _e( 'Default value(s)', 'accua-form-api'); ?>:</label>
1538 <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>
1539 <p><?php _e( 'For multiple default values in multiple select and multiple checkboxes, use | as separator.', 'accua-form-api'); ?></p>
1540 </div>
1541
1542 <div class="form-field">
1543 <label for="form-field-allowed-values"><?php _e( 'Allowed values', 'accua-form-api'); ?>:</label>
1544 <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>
1545 <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>
1546 </div>
1547
1548
1549 <?php
1550 /*
1551 if ( ! is_taxonomy_hierarchical($taxonomy) )
1552 do_action('add_tag_form_fields', $taxonomy);
1553 do_action($taxonomy . '_add_form_fields', $taxonomy);
1554 */
1555
1556 if ($adding) {
1557 submit_button( __( 'Add new field', 'accua-form-api'), 'button' );
1558 } else {
1559 submit_button( __( 'Save changes', 'accua-form-api'), 'button' );
1560 submit_button( __( 'Delete field', 'accua-form-api'), 'button', 'delete-field');
1561 }
1562
1563 /*
1564 // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form
1565 if ( 'category' == $taxonomy )
1566 do_action('edit_category_form', (object)array('parent' => 0) );
1567 elseif ( 'link_category' == $taxonomy )
1568 do_action('edit_link_category_form', (object)array('parent' => 0) );
1569 else
1570 do_action('add_tag_form', $taxonomy);
1571
1572 do_action($taxonomy . '_add_form', $taxonomy);
1573 */
1574 ?>
1575 </form></div>
1576 <?php /* } */ ?>
1577
1578 </div>
1579 </div><!-- /col-left -->
1580
1581 </div><!-- /col-container -->
1582 </div><!-- /wrap -->
1583 <?php
1584 /* echo '<pre>accua_forms_avail_fields:', htmlspecialchars(print_r($avail_fields, true)), '</pre>'; */
1585 }
1586
1587 function accua_forms_settings_page() {
1588 ?>
1589 <div class="wrap">
1590 <div id="icon-contact-forms-cimatti-logo" class="icon32"></div>
1591 <h2><?php _e( 'Default Form settings', 'accua-form-api'); ?></h2>
1592 <?php
1593 $empty_form_data = array(
1594 'layout' => 'sidebyside',
1595 'success_message' => '',
1596 'error_message' => '',
1597 'emails_from' => '',
1598 'admin_emails_to' => '',
1599 'emails_bcc' => '',
1600 'admin_emails_subject' => '',
1601 'admin_emails_message' => '',
1602 'confirmation_emails_subject' => '',
1603 'confirmation_emails_message' => '',
1604 );
1605
1606 $empty_file_data = array(
1607 'valid_extensions' => '',
1608 'max_size' => '',
1609 'dest_path' => '',
1610 );
1611
1612 if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['accua_form_save_form_settings'])) {
1613 $post = stripslashes_deep($_POST);
1614 $post += $empty_form_data;
1615 $post += $empty_file_data;
1616 $form_data = array();
1617 $file_data = array();
1618 foreach($empty_form_data as $key=>$val){
1619 $form_data[$key] = $post[$key];
1620 }
1621 foreach($empty_file_data as $key=>$val){
1622 $file_data[$key] = $post[$key];
1623 }
1624
1625
1626
1627 update_option('accua_forms_default_form_data', $form_data);
1628 update_option('accua_forms_default_file_field_data', $file_data);
1629 } else {
1630 $form_data = get_option('accua_forms_default_form_data',array()) + $empty_form_data;
1631 $file_data = get_option('accua_forms_default_file_field_data',array()) + $empty_file_data;
1632 }
1633 ?>
1634 <form method="post">
1635 <input type="hidden" name="accua_form_save_form_settings" value="1" />
1636 <!--
1637 <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>
1638 <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>
1639 <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>
1640 <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>
1641 <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>
1642 <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>
1643 <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>
1644 <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>
1645 <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>
1646 <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>
1647 -->
1648 <div id="accua_tab_messages" class="content_tab">
1649 <div id="accua_form_layout">
1650 <?php _e( 'Layout', 'accua-form-api'); ?>
1651 <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>
1652 </div>
1653 <br clear="all"/>
1654 <?php
1655 $settings_editor = array(
1656 'teeny' => true,
1657 'editor_class' => 'accua_form_value',
1658 'tinymce' => array(
1659 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,'));
1660 ?>
1661 <div class="metabox-holder accua-forms-metabox-holder">
1662 <div class="postbox ">
1663 <h3 class="hndle"><span><?php _e('1. On-screen success message', 'accua-form-api'); ?></span></h3>
1664 <div class="inside" id="dashboard_right_now">
1665 <div id="accua_form_success_message">
1666 <?php wp_editor( $form_data['success_message'] , 'success_message' , $settings_editor); ?>
1667 </div>
1668 </div>
1669 </div>
1670 </div>
1671
1672 <div class="metabox-holder accua-forms-metabox-holder">
1673 <div class="postbox ">
1674 <h3 class="hndle"><span><?php _e('2. On-screen error message', 'accua-form-api'); ?></span></h3>
1675 <div class="inside" id="dashboard_right_now">
1676 <div id="accua_form_error_message">
1677 <?php wp_editor( $form_data['error_message'] , 'error_message' , $settings_editor); ?>
1678 </div>
1679 </div>
1680 </div>
1681 </div>
1682 <br clear="all"/>
1683 <div class="metabox-holder accua-forms-metabox-holder">
1684 <div class="postbox ">
1685 <h3 class="hndle"><span><?php _e('3. Email to notify administrator', 'accua-form-api'); ?></span></h3>
1686 <div class="inside" id="dashboard_right_now">
1687 <div id="accua_form_admin_emails_to" class="label_input">
1688 <label><?php _e( 'To', 'accua-form-api'); ?></label>
1689 <input name="admin_emails_to" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_to'], ENT_QUOTES) ?>" />
1690 </div>
1691 <br clear="all" />
1692 <div id="accua_form_emails_bcc" class="label_input">
1693 <label><?php _e( 'Bcc', 'accua-form-api'); ?></label>
1694 <input name="emails_bcc" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['emails_bcc'], ENT_QUOTES) ?>" />
1695 </div>
1696 <br clear="all" />
1697 <div id="accua_form_admin_emails_subject" class="label_input">
1698 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
1699 <input name="admin_emails_subject" class="accua_form_value" type="text" value="<?php echo htmlspecialchars($form_data['admin_emails_subject'], ENT_QUOTES) ?>" />
1700 </div>
1701 <br clear="all" />
1702 <div id="accua_form_admin_emails_message">
1703 <?php wp_editor( $form_data['admin_emails_message'] , 'admin_emails_message' , $settings_editor); ?>
1704 </div>
1705
1706 </div>
1707 </div>
1708 </div>
1709
1710 <div class="metabox-holder accua-forms-metabox-holder">
1711 <div class="postbox ">
1712 <h3 class="hndle"><span><?php _e('4. Email confirmation to the person who completed the form', 'accua-form-api'); ?></span></h3>
1713 <div class="inside" id="dashboard_right_now">
1714 <div id="accua_form_emails_from" class="label_input">
1715 <label><?php _e( 'From', 'accua-form-api'); ?></label>
1716 <input class="accua_form_value" name="emails_from" type="text" value="<?php echo htmlspecialchars($form_data['emails_from'], ENT_QUOTES) ?>" />
1717 </div>
1718 <br clear="all" />
1719 <div id="accua_form_confirmation_emails_subject" class="label_input">
1720 <label><?php _e( 'Subject', 'accua-form-api'); ?></label>
1721 <input class="accua_form_value" type="text" name="confirmation_emails_subject" value="<?php echo htmlspecialchars($form_data['confirmation_emails_subject'], ENT_QUOTES) ?>" />
1722 </div>
1723 <br clear="all" />
1724 <div id="accua_form_confirmation_emails_message">
1725 <?php wp_editor( $form_data['confirmation_emails_message'] , 'confirmation_emails_message' , $settings_editor); ?>
1726 </div>
1727 </div>
1728 </div>
1729 </div>
1730 <br clear="all"/>
1731
1732 <div class="metabox-holder accua-forms-metabox-holder">
1733 <div class="postbox ">
1734 <h3 class="hndle"><span><?php _e( 'File upload default settings', 'accua-form-api'); ?></span></h3>
1735 <div class="inside" id="dashboard_right_now">
1736 <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>
1737 <small><?php _e( 'List of valid extensions, without dot, one per line.', 'accua-form-api'); ?></small>
1738 </div>
1739 <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 />
1740 <small><?php _e( 'You can use suffix K, M or G for kilobyte, megabyte or gigabyte.', 'accua-form-api'); ?>
1741 <?php
1742 $server_max_size = AccuaForm_Element_File::file_upload_max_size();
1743 if ($server_max_size > 0) {
1744 _e( 'This value is limited by server upload limits of ', 'accua-form-api');
1745 echo AccuaForm_Element_File::format_size($server_max_size).". ";
1746 _e( 'If you need a greater limit you should ask to the server administrator.', 'accua-form-api');
1747 }
1748 ?>
1749 </small>
1750 </div>
1751 <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) ?>" />
1752 <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>
1753 </div>
1754 </div>
1755 </div>
1756 </div>
1757 <br clear="all"/>
1758
1759 </div>
1760
1761 <!--
1762 <h3><?php _e( 'File upload default settings', 'accua-form-api'); ?></h3>
1763 <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>
1764 <small><?php _e( 'List of valid extensions, without dot, one per line.', 'accua-form-api'); ?></small>
1765 </p>
1766 <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 />
1767 <small><?php _e( 'You can use suffix K, M or G for kilobyte, megabyte or gigabyte.', 'accua-form-api'); ?>
1768 <?php
1769 $server_max_size = AccuaForm_Element_File::file_upload_max_size();
1770 if ($server_max_size > 0) {
1771 _e( 'This value is limited by server upload limits of ', 'accua-form-api');
1772 echo AccuaForm_Element_File::format_size($server_max_size).". ";
1773 _e( 'If you need a greater limit you should ask to the server administrator.', 'accua-form-api');
1774 }
1775 ?>
1776 </small></p>
1777 <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) ?>" />
1778 <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>
1779 </p> -->
1780 <p><input class="button button-primary button-large" id="accua_form_save_settings" type="submit" value="Save settings" /></p>
1781 </form>
1782 </div>
1783 <?php
1784 }
1785
1786 function _accua_forms_get_abs_dest_path($dest_path = '') {
1787 if ($dest_path === '') {
1788 return realpath(ABSPATH) . '/wp-content/uploads/accua-forms';
1789 } else if (substr($dest_path,0,1) === '/') {
1790 return $dest_path;
1791 } else {
1792 return realpath(ABSPATH) . '/' . $dest_path;
1793 }
1794 }
1795
1796 function _accua_forms_get_form_data($fid = false, $return_empty = true, $restore_trash = false){
1797 $empty_form_data = array(
1798 'fields' => array(),
1799 'title' => '',
1800 'layout' => 'sidebyside',
1801 'success_message' => '',
1802 'error_message' => '',
1803 'emails_from' => '',
1804 'admin_emails_to' => '',
1805 'emails_bcc' => '',
1806 'admin_emails_subject' => '',
1807 'admin_emails_message' => '',
1808 'confirmation_emails_subject' => '',
1809 'confirmation_emails_message' => '',
1810 'use_ajax' => true,
1811 );
1812
1813 if ($fid === false) {
1814 return $empty_form_data;
1815 }
1816
1817 $default_form_data = get_option('accua_forms_default_form_data',array());
1818
1819 if ($fid === null) {
1820 return $default_form_data + $empty_form_data;
1821 }
1822
1823 $forms_data = get_option('accua_forms_saved_forms', array());
1824 if ($restore_trash) {
1825 $trash_data = get_option('accua_forms_trash_forms', array());
1826 if (isset($trash_data[$fid])) {
1827 $forms_data[$fid] = $trash_data[$fid];
1828 update_option('accua_forms_saved_forms', $forms_data);
1829 unset($trash_data[$fid]);
1830 update_option('accua_forms_trash_forms', $trash_data);
1831 }
1832 }
1833
1834 if (isset($forms_data[$fid])) {
1835 $form_data = array(
1836 '_overrided' => $forms_data[$fid]
1837 ) + $forms_data[$fid] + $default_form_data + $empty_form_data;
1838 /*
1839 if ($form_data['fields']) {
1840 foreach ($form_data['fields'] as $i => $istance_data) {
1841 // TODO: popuplate default fields data?
1842 }
1843 }
1844 */
1845 return $form_data;
1846 } else if ($return_empty) {
1847 return array(
1848 '_overrided' => array()
1849 ) + $default_form_data + $empty_form_data;
1850 } else {
1851 return null;
1852 }
1853
1854 }
1855
1856 add_action('accua_form_alter', 'accua_forms_form_generate', -999, 2);
1857 function accua_forms_form_generate($baseid, $form) {
1858 if (substr($baseid, 0, 14) == '__accua-form__') {
1859 $fid = substr($baseid,14);
1860 $form_data = _accua_forms_get_form_data($fid, false);
1861 /*
1862 echo '<!-- fid = ';
1863 print_r($fid);
1864 echo "\n\nform_data = ";
1865 print_r($form_data);
1866 echo "\n-->";
1867 */
1868 if ($form_data) {
1869 if (!empty($form_data['use_ajax'])){
1870 $form->configure(array(
1871 "accua_ajax" => 1,
1872 ));
1873 }
1874
1875 $add_submit = true;
1876 $avail_fields = get_option('accua_forms_avail_fields', array());
1877
1878 foreach ($form_data['fields'] as $istance_data) {
1879
1880 if (empty($avail_fields[$istance_data['ref']])) {
1881 $field_data = array();
1882 } else {
1883 $field_data = $avail_fields[$istance_data['ref']];
1884 }
1885
1886 $field_data += array(
1887 'id' => '__html',
1888 'name' => __( 'Custom HTML content', 'accua-form-api'),
1889 'type' => 'html',
1890 'description' => __('Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
1891 'default_value' => '',
1892 'allowed_values' => '',
1893 );
1894
1895 $istance_data += array(
1896 'istance_id' => $field_data['id'],
1897 'widget_number' => '',
1898 'ref' => $field_data['id'],
1899 'label' => $field_data['name'],
1900 'default_value' => $field_data['default_value'],
1901 'allowed_values' => $field_data['allowed_values'],
1902 );
1903
1904 $element = null;
1905
1906 $allowed_val = trim($istance_data['allowed_values']);
1907
1908
1909 if ($field_data['type'] == 'post-multicheckbox') {
1910 $posts = accua_get_pages($allowed_val);
1911 $allowed_values = array();
1912 foreach ($posts as $p) {
1913 //$allowed_values[$p->ID] = apply_filters( 'the_title', $p->post_title, $p->ID );
1914 $allowed_values[$p->ID] = $p->post_title;
1915 }
1916 } else {
1917 if ($field_data['type'] == 'file') {
1918 $filedata = get_option('accua_forms_default_file_field_data',array());
1919 $filedata += array(
1920 'valid_extensions' => '',
1921 'max_filesize' => '',
1922 'dest_path' => '',
1923 );
1924 if ($allowed_val == '') {
1925 $allowed_val = trim($filedata['valid_extensions']);
1926 }
1927 }
1928
1929 $allowed_val = explode("\n",$allowed_val);
1930 $allowed_values = array();
1931 foreach ($allowed_val as $val) {
1932 $val = explode('|',$val,2);
1933 $val[0] = trim($val[0]);
1934 /*
1935 if (empty($val[0])) {
1936 continue;
1937 }
1938 */
1939 if ((!isset($val[1])) || (trim($val[1])==='')) {
1940 if ($val[0] === '') {
1941 continue;
1942 } else {
1943 $val[1] = $val[0];
1944 }
1945 }
1946 $allowed_values[$val[0]] = $val[1];
1947 }
1948 }
1949
1950 switch ($field_data['type']) {
1951 case 'textarea':
1952 $element = new Element_Textarea($istance_data['label'], $istance_data['istance_id'], array('cols' => '50'));
1953 break;
1954 case 'hidden':
1955 $element = new Element_Hidden($istance_data['istance_id'], $istance_data['default_value']);
1956 break;
1957 case 'checkbox':
1958 $val = empty($istance_data['default_value'])?'1':$istance_data['default_value'];
1959 $lab = $istance_data['label'];
1960 if (!empty($istance_data['required'])) {
1961 $lab .= ' <strong>*</strong>';
1962 }
1963 $element = new AccuaForm_Element_Checkbox('', $istance_data['istance_id'], array($val => $lab));
1964 break;
1965 case 'select':
1966 if (!isset($allowed_values[''])) {
1967 $allowed_values = array('' => '') + $allowed_values;
1968 }
1969 $element = new Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values);
1970 break;
1971 case 'radio':
1972 $element = new Element_Radio($istance_data['label'], $istance_data['istance_id'], $allowed_values);
1973 break;
1974 case 'multiselect':
1975 $element = new Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, array('multiple' => true));
1976 break;
1977 case 'multicheckbox':
1978 $element = new AccuaForm_Element_Checkbox($istance_data['label'], $istance_data['istance_id'], $allowed_values);
1979 case 'post-multicheckbox':
1980 $element = new AccuaForm_Element_Checkbox($istance_data['label'], $istance_data['istance_id'], $allowed_values);
1981 break;
1982 case 'file':
1983 $fdata = array();
1984
1985 if ($allowed_values) {
1986 $fdata['validExtensions'] = array_keys($allowed_values);
1987 }
1988
1989 if ($filedata['max_size'] !== ''){
1990 $fdata['maxSize'] = $filedata['max_size'];
1991 }
1992
1993 $fdata['destPath'] = _accua_forms_get_abs_dest_path($filedata['dest_path']);
1994
1995 $element = new AccuaForm_Element_File($istance_data['label'], $istance_data['istance_id'], $fdata);
1996 break;
1997 case 'html':
1998 $element = new Element_HTML($istance_data['default_value']);
1999 break;
2000 case 'email':
2001 case 'autoreply_email':
2002 $element = new AccuaForm_Element_Email($istance_data['label'], $istance_data['istance_id']);
2003 $element->setValidation(new Validation_Email(
2004 str_replace('%element%', $istance_data['label'], __("Attention: '%element%' must contain an email address.", 'accua-form-api'))
2005 ));
2006 //"Errore: '{$istance_data['label']}' deve contenere un indirizzo email valido."
2007 break;
2008 case 'submit':
2009 $add_submit = false;
2010 $element = new Element_Button($istance_data['label'], 'submit', array('name' => $istance_data['istance_id'], 'value' => $istance_data['default_value']));
2011 break;
2012 case 'captcha':
2013 $element = new Element_Captcha ($istance_data['label'], array("description" => ""));
2014 break;
2015 case 'password':
2016 $element = new Element_Password($istance_data['label'], $istance_data['istance_id']);
2017 break;
2018 case 'password-and-confirm':
2019 $id_2 = "___".$istance_data['istance_id']."___confirmpass";
2020 $element = new Element_Password("Password", $istance_data['istance_id']);
2021 $element_conf = new Element_Password("Conferma password", $id_2);
2022 $element_conf->setValidation(new AccuaForm_Validation_Password(
2023 str_replace('%element%', "Conferma password", __("Attention: '%element%' is a required field.", 'accua-form-api'))
2024 ));
2025 break;
2026 case 'textfield':
2027 default:
2028 $element = new Element_Textbox($istance_data['label'], $istance_data['istance_id']);
2029 break;
2030 }
2031
2032 if (!empty($istance_data['required'])) {
2033 $element->setClass('accuaforms-field-required');
2034 if($field_data['type']!='password-and-confirm') {
2035 $element->setValidation(new Validation_Required(
2036 str_replace('%element%', $istance_data['label'], __("Attention: '%element%' is a required field.", 'accua-form-api'))
2037 ));
2038 } else {
2039 $element->setValidation(new Validation_Required(
2040 str_replace('%element%', $istance_data['label'], __("Attention: Passwords are required fields.", 'accua-form-api'))
2041 ));
2042 }
2043 }
2044
2045 if ($elementName = $element->getName()) {
2046 $element->setClass('accuaform-fieldname-'.$elementName);
2047 }
2048
2049 if ($field_data['type']) {
2050 $element->setClass('accuaform-fieldtype-'.$field_data['type']);
2051 }
2052
2053 $form->addElement($element);
2054 if($element_conf!=NULL) {
2055 $form->addElement($element_conf);
2056 $element_conf=NULL;
2057 }
2058 }
2059
2060 if ($add_submit) {
2061 $form->addElement(new Element_Button);
2062 }
2063 }
2064
2065 }
2066 }
2067
2068 function accua_forms_aggregate_submitted_data(&$replace_map, $params = array()) {
2069 if (empty($params['txt']) && empty($params['html']) && empty($params['json']) && empty($params['email'])) {
2070 $params += array(
2071 'txt' => true,
2072 'html' => true,
2073 'json' => true,
2074 'email' => true,
2075 );
2076 }
2077
2078 if (!empty($params['txt'])) {
2079 $replace_map['__submitted_txt'] = implode("\n",$replace_map['__submitted_txt_raw']);
2080 }
2081 if (!empty($params['html'])) {
2082 $replace_map['__submitted_html'] = implode('</td></tr><tr><td>',$replace_map['__submitted_html_raw']);
2083 }
2084 if (!empty($params['json'])) {
2085 $replace_map['__submitted_json'] = json_encode($replace_map['__submitted_json_raw']);
2086 }
2087 if (!empty($params['email'])) {
2088 $replace_map['__autoreply_email'] = implode('; ', $replace_map['__autoreply_email_raw']);
2089 }
2090
2091 }
2092
2093 add_action('accua_form_submit', 'accua_forms_form_submission_handler', -10, 3);
2094 function accua_forms_form_submission_handler($submittedID, $submittedData, $form) {
2095 if ( empty( $GLOBALS['wp_rewrite'] ) )
2096 $GLOBALS['wp_rewrite'] = new WP_Rewrite();
2097
2098 if (!class_exists('AccuaConditionalReplacer')){
2099 require_once('AccuaConditionalReplacer.php');
2100 }
2101 if (substr($submittedID, 0, 14) == '__accua-form__') {
2102 $fid = substr($submittedID,14);
2103 $form_data = _accua_forms_get_form_data($fid, false);
2104 if ($form_data) {
2105 global $wpdb;
2106
2107 $time = time();
2108
2109 $wpdb->insert(
2110 $wpdb->prefix . 'accua_forms_submissions',
2111 array (
2112 'afs_form_id' => $fid,
2113 'afs_post_id' => $form->stats['pid'],
2114 'afs_ip' => $form->stats['ip'],
2115 'afs_uri' => $form->stats['uri'],
2116 'afs_referrer' => $form->stats['referrer'],
2117 'afs_lang' => $form->stats['lang'],
2118 'afs_created' => gmdate('Y-m-d H:i:s', $form->stats['created']),
2119 'afs_submitted' => gmdate('Y-m-d H:i:s', $time),
2120 'afs_stats' => json_encode(array(
2121 'user_agent' => $form->stats['user_agent'],
2122 'platform' => $form->stats['platform'],
2123 'tentatives' => $form->stats['tentatives'],
2124 'submit_method' => $form->stats['submit_method'],
2125 )),
2126 )
2127 );
2128
2129 $submission_id = $form->stats['submission_id'] = $wpdb->insert_id;
2130
2131
2132
2133 $replace_map = array(
2134 '__fid' => $fid,
2135 '__subid' => $submission_id,
2136 '__pid' => $form->stats['pid'],
2137 '__ip' => $form->stats['ip'],
2138 '__uri' => $form->stats['uri'],
2139 '__url' => $form->stats['url'],
2140 '__referrer' => $form->stats['referrer'],
2141 '__lang' => $form->stats['lang'],
2142 '__locale' => $form->stats['locale'],
2143 '__created' => $form->stats['created'],
2144 '__created_day' => date('l j F Y', $form->stats['created']),
2145 '__created_day_month_year' => date('j F Y', $form->stats['created']),
2146 '__created_hour' => date('G:i', $form->stats['created']),
2147 '__submitted' => $time,
2148 '__submitted_day' => date('l j F Y', $time),
2149 '__submitted_day_month_year' => date('j F Y', $time),
2150 '__submitted_hour' => date('G:i', $time),
2151 '__confirmation_emails_message' => $form_data['confirmation_emails_message'],
2152 '__user_agent' => $form->stats['user_agent'],
2153 '__platform' => $form->stats['platform'],
2154 '__tentatives' => $form->stats['tentatives'],
2155 '__submit_method' => $form->stats['submit_method'],
2156 );
2157
2158 $avail_fields = get_option('accua_forms_avail_fields', array());
2159
2160 $replace_map['__autoreply_email_raw'] = array();
2161 $replace_map['__submitted_txt_raw'] = array();
2162 $replace_map['__submitted_html_raw'] = array();
2163 $replace_map['__submitted_json_raw'] = array();
2164
2165 $_field_data = array();
2166 $_istance_data = array();
2167
2168 foreach ($submittedData as $istance_id => $value) {
2169 if (empty($form_data['fields'][$istance_id])) {
2170 continue;
2171 }
2172 $istance_data = $form_data['fields'][$istance_id];
2173
2174 if (empty($avail_fields[$istance_data['ref']])) {
2175 $field_data = array();
2176 } else {
2177 $field_data = $avail_fields[$istance_data['ref']];
2178 }
2179
2180 $field_data += array(
2181 'id' => '__html',
2182 'name' => __( 'Custom HTML content', 'accua-form-api'),
2183 'type' => 'html',
2184 'description' => __( 'Use this special field to inject raw HTML in the form. You can use this multiple times.', 'accua-form-api'),
2185 'default_value' => '',
2186 'allowed_values' => '',
2187 );
2188
2189 /*
2190 echo "<!-- istance_data: "
2191 , print_r($istance_data, true)
2192 , "\nfield_data: "
2193 , print_r($field_data, true)
2194 , "\nvalue: "
2195 , print_r($value, true)
2196 , "\n-->\n";
2197 */
2198
2199 $istance_data += array(
2200 'istance_id' => $field_data['id'],
2201 'widget_number' => '',
2202 'ref' => $field_data['id'],
2203 'label' => $field_data['name'],
2204 'default_value' => $field_data['default_value'],
2205 'allowed_values' => $field_data['allowed_values'],
2206 );
2207
2208 switch ($field_data['type']) {
2209 case 'checkbox':
2210 case 'submit':
2211 if (empty($value)) {
2212 $replace_map[$istance_data['istance_id']] = $value = '';
2213 } else {
2214 if (empty($istance_data['default_value'])) {
2215 $replace_map[$istance_data['istance_id']] = 'Checked';
2216 $value = '1';
2217 } else {
2218 $replace_map[$istance_data['istance_id']] = $value = $istance_data['default_value'];
2219 }
2220 }
2221 break;
2222 case 'multiselect':
2223 case 'multicheckbox':
2224 $replace_map[$istance_data['istance_id']] = implode(', ',$value);
2225 $value = implode('|',$value);
2226 break;
2227 case 'post-multicheckbox':
2228 $el = $form->getElementByName($istance_id);
2229 $opts = $el->getOptions();
2230 $value2 = array();
2231 foreach ($value as $val) {
2232 if (isset($opts[$val])) {
2233 $value2[] = $val . ': ' . trim(preg_replace('/[\s\n\r]+/', ' ', $opts[$val]));
2234 }
2235 }
2236 $replace_map[$istance_data['istance_id']] = $value = implode("\n", $value2);
2237 break;
2238 /*
2239 case 'file':
2240 //URL to file, or attach
2241 break;
2242 */
2243 case 'autoreply_email':
2244 if ($value !== '') {
2245 $replace_map['__autoreply_email_raw'][] = $value;
2246 }
2247 $replace_map[$istance_data['istance_id']] = $value;
2248 break;
2249 case 'file':
2250 //TODO: move temp file to "{$submission_id}_{$field_data['id']}_{$file['name']}"; value is $file['name']
2251 $buildid = $submittedData['_AccuaForm_buildID'];
2252 $file_download_url = '';
2253 $file = $form->getFile($istance_id);
2254 if ($value !== null && $value !== '' && $file) {
2255 if ($form->renameFile($istance_id, "{$submission_id}_{$field_data['id']}_{$file['name']}")) {
2256 $urlfield = rawurlencode($istance_data['istance_id']);
2257 $urlfile = rawurlencode($value);
2258 $file_download_url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$submission_id}&field={$urlfield}&file={$urlfile}";
2259 }
2260 }
2261 $replace_map[$istance_data['istance_id']] = $value;
2262 $replace_map['__download_'.$istance_data['istance_id']] = $file_download_url;
2263 break;
2264 default:
2265 $replace_map[$istance_data['istance_id']] = $value;
2266 }
2267
2268 switch ($field_data['type']) {
2269 case 'file':
2270 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value\t$file_download_url";
2271 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = "$value\t$file_download_url";
2272 $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>";
2273 break;
2274
2275 case 'email':
2276 case 'autoreply_email':
2277 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2278 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2279 $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>";
2280 break;
2281 case 'submit':
2282 break;
2283 default:
2284 $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value";
2285 $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value;
2286 $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "<strong>{$istance_data['istance_id']}</strong></td><td class='valori_submitted'>".htmlspecialchars($value);
2287 }
2288
2289 $wpdb->insert(
2290 $wpdb->prefix . 'accua_forms_submissions_values',
2291 array (
2292 'afsv_sub_id' => $submission_id,
2293 'afsv_field_id' => $istance_data['istance_id'],
2294 'afsv_type' => $field_data['type'],
2295 'afsv_value' => $value,
2296 ),
2297 array('%d','%s','%s','%s')
2298 );
2299
2300 $_field_data[$istance_data['istance_id']] = $field_data;
2301 $_istance_data[$istance_data['istance_id']] = $istance_data;
2302
2303 }
2304
2305 $replace_map['__autoreply'] = (bool) ($replace_map['__autoreply_email_raw']
2306 && $form_data['confirmation_emails_subject']
2307 && $form_data['confirmation_emails_message']);
2308
2309 accua_forms_aggregate_submitted_data($replace_map);
2310
2311 $replace_map = apply_filters('accua_forms_form_submission_handler', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data);
2312
2313 $replace_map['__submitted_html'] = $submitted_html = '<table><tr><td>' . $replace_map['__submitted_html'] . '</td></tr></table>';
2314 unset($replace_map['__submitted_txt_raw'], $replace_map['__submitted_html_raw'], $replace_map['__submitted_json_raw'], $replace_map['__autoreply_email_raw']);
2315
2316 $replacer = new AccuaConditionalReplacer($replace_map);
2317
2318 $confirmation_emails_message = $replace_map['__confirmation_emails_message'];
2319
2320 unset($replace_map['__submitted_html'], $replace_map['__confirmation_emails_message']);
2321 foreach($replace_map as $key => $value) {
2322 $replace_map[$key] = htmlspecialchars($value, ENT_QUOTES);
2323 }
2324 $replace_map['__submitted_html'] = $submitted_html;
2325
2326 $replacer_html = new AccuaConditionalReplacer($replace_map);
2327
2328 $confirmation_emails_message = $replacer_html->doReplace($confirmation_emails_message);
2329 $replacer_html->appendPattern(array('__confirmation_emails_message' => $confirmation_emails_message));
2330
2331 $form_data_replaced = array();
2332
2333 $settings = array(
2334 'emails_from',
2335 'admin_emails_to',
2336 'emails_bcc',
2337 'admin_emails_subject',
2338 'confirmation_emails_subject',
2339 );
2340
2341 foreach($settings as $i) {
2342 $form_data_replaced[$i] = $replacer->doReplace($form_data[$i]);
2343 }
2344
2345 $settings_html = array(
2346 'success_message',
2347 'admin_emails_message',
2348 );
2349
2350 foreach($settings_html as $i) {
2351 $form_data_replaced[$i] = $replacer_html->doReplace($form_data[$i]);
2352 }
2353
2354 AccuaForm::appendSubmittedMessages(wpautop($form_data_replaced['success_message']));
2355
2356 $header = array("Content-Type: text/html; charset=".get_option('blog_charset'));
2357
2358
2359 if ($form_data_replaced['emails_from']) {
2360 $header[] = 'From: '.$form_data_replaced['emails_from'];
2361 }
2362
2363 if ($form_data_replaced['emails_bcc']) {
2364 $header[] = 'Bcc: '.$form_data_replaced['emails_bcc'];
2365 }
2366
2367 if ($form_data_replaced['admin_emails_to']
2368 && $form_data_replaced['admin_emails_subject']) {
2369 /*
2370 $admin_tos = explode(',', strtr($form_data_replaced['admin_emails_to'], "\n\t\r;", ',,,,'));
2371 foreach ($admin_tos as $admin_to) {
2372 $mail1 = wp_mail(trim($admin_to), $form_data_replaced['admin_emails_subject'], $form_data_replaced['admin_emails_message'], $header);
2373 }
2374 */
2375 $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);
2376 }
2377
2378 if ($replace_map['__autoreply'] && $replace_map['__autoreply_email']
2379 && $form_data_replaced['confirmation_emails_subject']
2380 && $confirmation_emails_message) {
2381 $mail2 = wp_mail($replace_map['__autoreply_email'], $form_data_replaced['confirmation_emails_subject'], '<html><head></head><body>'.wpautop($confirmation_emails_message).'</body></html>', $header);
2382 }
2383
2384 /*
2385 echo "<!-- replace_map: "
2386 , print_r($replace_map, true)
2387 , "\nreplace_map: "
2388 , print_r($replace_map, true)
2389 , "\nform_data_replaced: "
2390 , print_r($form_data_replaced, true)
2391 , "\nautoreply_email: "
2392 , print_r($autoreply_email, true)
2393 , "\nmail1: "
2394 , print_r($mail1, true)
2395 , "\nmail2: "
2396 , print_r($mail2, true)
2397 ,"\n-->";
2398 */
2399 }
2400 }
2401 }
2402
2403 function accua_forms_get_submission_data($subid, $options = array()){
2404 //TODO: Completa e usa per sostituire i campi
2405 global $wpdb;
2406 $subid = (int) $subid;
2407 $options += array(
2408 'extra' => true,
2409 'file_format' => 'name',
2410 );
2411 $ret = array();
2412 if ($options['extra']) {
2413 $query1 = "SELECT *
2414 FROM `{$wpdb->prefix}accua_forms_submissions`
2415 WHERE afs_id = $subid";
2416 $data = $wpdb->get_row($query1);
2417 if (!empty($data)) {
2418 $created = $data->afs_created;
2419 $created[10] = 'T';
2420 $created.='.00+00:00';
2421 $created = strtotime($created);
2422 $submitted = $data->afs_submitted;
2423 $submitted[10] = 'T';
2424 $submitted.='.00+00:00';
2425 $submitted = strtotime($submitted);
2426 $ret += array(
2427 '__fid' => $data->afs_form_id,
2428 '__subid' => $subid,
2429 '__pid' => $data->afs_post_id,
2430 '__ip' => $data->afs_id,
2431 '__uri' => $data->afs_uri,
2432 '__referrer' => $data->afs_referrer,
2433 '__lang' => $data->afs_lang,
2434 '__created' => $created,
2435 '__created_day' => date('l j F Y', $created),
2436 '__created_hour' => date('G:i', $created),
2437 '__submitted' => $submitted,
2438 '__submitted_day' => date('l j F Y', $submitted),
2439 '__submitted_hour' => date('G:i', $submitted),
2440 );
2441 }
2442 }
2443
2444 $query2 = "SELECT *
2445 FROM `{$wpdb->prefix}accua_forms_submissions_values`
2446 WHERE afsv_sub_id = $subid";
2447
2448 $data2 = $wpdb->get_results($query2, OBJECT);
2449
2450 foreach ($data2 as $row) {
2451 switch ($row->afsv_type) {
2452 case 'file' :
2453 if ($options['file_format'] == 'url' || $options['file_format'] == 'link') {
2454 $fieldid = rawurlencode($row->afsv_field_id);
2455 $filename = rawurlencode($row->afsv_value);
2456 $url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$row->afsv_sub_id}&field={$fieldid}&file={$filename}";
2457 if ($options['file_format'] == 'url'){
2458 $url = htmlspecialchars($url,ENT_QUOTES);
2459 $filename = htmlspecialchars($row->afsv_value,ENT_QUOTES);
2460 $fielddata = "<a href='{$url}' target='_blank'>{$filename}</a>";
2461 } else {
2462 $fielddata = $url;
2463 }
2464 } else { // $options['file_format'] == 'name'
2465 $fielddata = $row->afsv_value;
2466 }
2467 break;
2468 default:
2469 $fielddata = $row->afsv_value;
2470 }
2471 $ret[$row->afsv_field_id] = $fielddata;
2472 }
2473 return $ret;
2474 }
2475
2476 add_shortcode( 'accua-form', 'accua_forms_shortcode_handler' );
2477 function accua_forms_shortcode_handler($atts, $content = '', $code = '') {
2478 if (empty($atts['fid'])) {
2479 return '';
2480 }
2481
2482 $fid = $atts['fid'];
2483 $form_data = _accua_forms_get_form_data($fid, false);
2484
2485 if (! $form_data) {
2486 return '';
2487 }
2488
2489 $fid = '__accua-form__'.$fid;
2490
2491 $out = '';
2492
2493 if (AccuaForm::getSumbittedID() == $fid) {
2494 /* return "<pre>Form submitted.\n\nData: " . print_r(AccuaForm::getSubmittedData(), true) . '</pre>'; */
2495 $messages = AccuaForm::getSubmittedMessages();
2496 if ($messages) {
2497 $out .= '<div id="_response_messages_'.$fid.'" class="accua-form-messages">'.$messages.'</div>';
2498 }
2499 if (AccuaForm::isValid()) {
2500 return $out;
2501 }
2502 $form = AccuaForm::getSubmittedForm();
2503 } else {
2504 $form = AccuaForm::create($fid, array('layout'=>$form_data['layout']));
2505 }
2506
2507 return $out . $form->render(true);
2508 }
2509
2510 function accua_forms_submissions_list_page_head(){
2511 require_once('accua-forms-submissions-page.php');
2512 accua_forms_submissions_list_page(true);
2513 }
2514
2515 add_action('wp_ajax_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file');
2516 add_action('wp_ajax_nopriv_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file');
2517 function accua_forms_download_submitted_file(){
2518 $get = stripslashes_deep($_GET);
2519 if (isset($get['subid'],$get['field'],$get['file'])) {
2520 global $wpdb;
2521 $subid = (int) $get['subid'];
2522 $field = $get['field'];
2523 $file = $get['file'];
2524 $query = "SELECT *
2525 FROM `{$wpdb->prefix}accua_forms_submissions_values`
2526 WHERE afsv_sub_id = %d
2527 AND afsv_field_id = %s
2528 AND afsv_value = %s
2529 ";
2530 $query = $wpdb->prepare($query, $subid, $field, $file);
2531 $subval = $wpdb->get_results($query, OBJECT);
2532 if ($subval) {
2533 $file_data = get_option('accua_forms_default_file_field_data',array()) + array('dest_path' => '');
2534 $dest_path = _accua_forms_get_abs_dest_path($file_data['dest_path']);
2535 $filename = "{$dest_path}/{$subid}_{$field}_{$file}";
2536 if (is_file($filename) && is_readable($filename)){
2537 if (function_exists('finfo_open')){
2538 @ $finfo = finfo_open(FILEINFO_MIME);
2539 if ($finfo) {
2540 @ $filetype = finfo_file($finfo, $filename);
2541 @ finfo_close($finfo);
2542 }
2543 }
2544 if (empty($filetype) && function_exists('mime_content_type')){
2545 @ $filetype = mime_content_type($filename);
2546 }
2547 if (empty($filetype)) {
2548 $filetype = "application/octet-stream";
2549 }
2550 header("Content-type: $filetype");
2551 header("Content-length: ".filesize($filename));
2552 header("Content-disposition: attachment; filename=\"$file\"");
2553 readfile($filename);
2554 die;
2555 }
2556 }
2557 }
2558 header("HTTP/1.0 404 Not Found");
2559 //header("Status: 404 Not Found");
2560 die('File not found');
2561 }
2562
2563 function accua_forms_buildConditionalReplacer($map = array()) {
2564 if (!class_exists('AccuaConditionalReplacer')){
2565 require_once('AccuaConditionalReplacer.php');
2566 }
2567 return new AccuaConditionalReplacer($map);
2568 }
2569
2570
2571 add_action('wp_ajax_accua_forms_preview', 'accua_forms_preview');
2572 function accua_forms_preview() {
2573 if (!current_user_can(10)){
2574 die ('');
2575 }
2576 wp_enqueue_script('jquery');
2577 echo '<html><head>';
2578 wp_print_styles();
2579 wp_print_head_scripts();
2580 echo '</head><body>';
2581 echo accua_forms_shortcode_handler(array('fid'=>$_REQUEST['fid']));
2582 wp_print_footer_scripts();
2583 echo '</body></html>';
2584 die;
2585 }
2586
2587 //salvataggio file excel
2588 add_action('wp_ajax_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel');
2589 //add_action('wp_ajax_nopriv_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel');
2590
2591 function accua_forms_submission_page_save_excel() {
2592 require_once('accua-forms-submissions-page.php');
2593 $listTable = new Accua_Forms_Submissions_List_Table();
2594 $listTable->prepare_items(true);
2595 $show_col = explode( ',', $_GET['accua_show_field']);
2596 accua_forms_submission_page_save_excel_general($listTable,$show_col,'');
2597 }
2598
2599
2600
2601 function accua_forms_submission_page_save_excel_general(Accua_Forms_Submissions_List_Table $listTable,array $show_col,$file_name='') {
2602
2603 if (!current_user_can(10)){
2604 header("HTTP/1.0 401 Access Denied");
2605 //header("Status: 401 Access Denied");
2606 die('You are not authorized to access this page.');
2607 }
2608
2609 global $wpdb;
2610
2611 //creo il file excel
2612 header("Content-disposition: attachment; filename=downloads-report".$file_name.".xls");
2613 header("Content-type: application/vnd.ms-excel");
2614 ?><html xmlns:o="urn:schemas-microsoft-com:office:office"
2615 xmlns:x="urn:schemas-microsoft-com:office:excel"
2616 xmlns="http://www.w3.org/TR/REC-html40">
2617 <head>
2618 <meta http-equiv=Content-Type content="text/html; charset=<?php echo get_option('blog_charset'); ?>" />
2619 <meta name=ProgId content=Excel.Sheet />
2620 <style>
2621 <!--
2622 td {vertical-align:top;}
2623 .head_row {font-weight:bold;}
2624 .column-date { mso-number-format:"Short Date"; }
2625 .datetime_cell { mso-number-format:"yyyy\\-mm\\-dd\\ hh\:mm\:ss"; }
2626 -->
2627 </style>
2628 <!--[if gte mso 9]><xml>
2629 <x:ExcelWorkbook>
2630 <x:ExcelWorksheets>
2631 <x:ExcelWorksheet>
2632 <x:WorksheetOptions>
2633 <x:FreezePanes/>
2634 <x:FilterOn/>
2635 <x:SplitHorizontal>1</x:SplitHorizontal>
2636 <x:TopRowBottomPane>1</x:TopRowBottomPane>
2637 <x:ActivePane>2</x:ActivePane>
2638 <x:Panes>
2639 <x:Pane>
2640 <x:Number>3</x:Number>
2641 </x:Pane>
2642 <x:Pane>
2643 <x:Number>2</x:Number>
2644 </x:Pane>
2645 </x:Panes>
2646 </x:WorksheetOptions>
2647 </x:ExcelWorksheet>
2648 </x:ExcelWorksheets>
2649 </x:ExcelWorkbook>
2650 </xml><![endif]-->
2651 </head>
2652 <body>
2653 <table x:str border=1 >
2654 <tr class='head-row'>
2655 <?php
2656 $cols = $listTable->get_columns();
2657 foreach($cols as $col_key=>$col_value) {
2658 if(in_array($col_key, $show_col)) { ?>
2659 <td x:autofilter="all"><?php echo $col_value; ?></td>
2660 <?php }
2661 } ?>
2662 </tr>
2663
2664 <?php
2665 /* gestire la data
2666 $ut_date = $result->date;
2667 $ut_date[10] = 'T';
2668 $ut_date.='.00+00:00';
2669 $excel_date = (strtotime($ut_date) / 86400 + 25569);
2670 $parts_date = explode('-', substr($result->date, 0, 10));
2671 $date = "{$parts_date[2]}/{$parts_date[1]}/{$parts_date[0]}";
2672 echo "<td class='column-date' x:num='$excel_date' SDVAL=\"$excel_date\" SDNUM=\"1033;0;DD/MM/YYYY\">$date</td>\n";
2673 */
2674 ?>
2675 <?php
2676
2677
2678 foreach($listTable->items as $id_submission=>$single_submission) {
2679 echo "<tr>";
2680 foreach($cols as $col_key=>$col_value) {
2681 if(in_array($col_key, $show_col)) {
2682 echo "<td class='.$col_key.'>";
2683 if(isset($single_submission[$col_key])) {
2684 if ( method_exists( $this, 'column_' . $column_name ) ) {
2685 echo call_user_func( array( &$listTable, 'column_' . $col_key ), $single_submission );
2686 }
2687 else {
2688 echo $listTable->column_default( $single_submission, $col_key );
2689 }
2690 }
2691 echo "</td>";
2692 }
2693
2694 }
2695 echo "</tr>";
2696 }
2697
2698 ?>
2699 </table>
2700 </body>
2701 </html>
2702 <?php
2703 }
2704
2705 function accua_forms_print_tokens() {
2706 $avail_fields = get_option('accua_forms_avail_fields', array());
2707 $tokens = '';
2708 foreach($avail_fields as $key=>$value) {
2709 $tokens .= $value['name'] . ": {" . $key . "}\n";
2710 if ($value['type'] == 'file') {
2711 $tokens .= $value['name'] . " (download link): {__download_" . $key . "}\n";
2712 }
2713 }
2714
2715 echo <<<EOT
2716 <div class="accua_forms_token_list">
2717 <h2>Tokens</h2>
2718 <h3>Fields</h3>
2719 <em>These tokens are available only if the field is added to the form</em>
2720 <pre>$tokens</pre>
2721 <h3>Generic tokens</h3>
2722 <pre>{__fid}
2723 {__subid}
2724 {__pid}
2725 {__ip}
2726 {__uri}
2727 {__url}
2728 {__referrer}
2729 {__lang}
2730 {__locale}
2731 {__created}
2732 {__created_day}
2733 {__created_day_month_year}
2734 {__created_hour}
2735 {__submitted}
2736 {__submitted_day}
2737 {__submitted_day_month_year}
2738 {__submitted_hour}
2739 {__user_agent}
2740 {__platform}
2741 {__tentatives}
2742 {__submit_method}
2743 {__submitted_txt}
2744 {__submitted_html}
2745 {__submitted_json}
2746 {__autoreply}
2747 {__autoreply_email}
2748 {__confirmation_emails_message}</pre>
2749 </div>
2750 EOT;
2751 do_action('accua_forms_print_tokens');
2752 }
2753
2754 function &accua_get_pages($args = '') {
2755 global $wpdb;
2756
2757 $defaults = array(
2758 'child_of' => 0, 'sort_order' => 'ASC',
2759 'sort_column' => 'post_title', 'hierarchical' => 1,
2760 'exclude' => array(), 'include' => array(),
2761 'meta_key' => '', 'meta_value' => '',
2762 'authors' => '', 'parent' => -1, 'exclude_tree' => '',
2763 'number' => '', 'offset' => 0,
2764 'post_type' => 'page', 'post_status' => 'publish',
2765 );
2766
2767 $r = wp_parse_args( $args, $defaults );
2768 extract( $r, EXTR_SKIP );
2769 $number = (int) $number;
2770 $offset = (int) $offset;
2771
2772 /*
2773 // Make sure the post type is hierarchical
2774 $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
2775 if ( !in_array( $post_type, $hierarchical_post_types ) )
2776 return false;
2777 */
2778
2779 // Make sure we have a valid post type
2780 if ( !is_array( $post_type ) )
2781 $post_type = explode( ',', $post_type );
2782 if ( array_diff( $post_type, get_post_types() ) )
2783 return false;
2784
2785 // Make sure we have a valid post status
2786 if ( !is_array( $post_status ) )
2787 $post_status = explode( ',', $post_status );
2788 if ( array_diff( $post_status, get_post_stati() ) )
2789 return false;
2790
2791 /*
2792 $cache = array();
2793 $key = md5( serialize( compact(array_keys($defaults)) ) );
2794 if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) {
2795 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
2796 $pages = apply_filters('get_pages', $cache[ $key ], $r );
2797 return $pages;
2798 }
2799 }
2800
2801 if ( !is_array($cache) )
2802 $cache = array();
2803 */
2804
2805 $inclusions = '';
2806 if ( !empty($include) ) {
2807 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
2808 $parent = -1;
2809 $exclude = '';
2810 $meta_key = '';
2811 $meta_value = '';
2812 $hierarchical = false;
2813 $incpages = wp_parse_id_list( $include );
2814 if ( ! empty( $incpages ) ) {
2815 foreach ( $incpages as $incpage ) {
2816 if (empty($inclusions))
2817 $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
2818 else
2819 $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
2820 }
2821 }
2822 }
2823 if (!empty($inclusions))
2824 $inclusions .= ')';
2825
2826 $exclusions = '';
2827 if ( !empty($exclude) ) {
2828 $expages = wp_parse_id_list( $exclude );
2829 if ( ! empty( $expages ) ) {
2830 foreach ( $expages as $expage ) {
2831 if (empty($exclusions))
2832 $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage);
2833 else
2834 $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage);
2835 }
2836 }
2837 }
2838 if (!empty($exclusions))
2839 $exclusions .= ')';
2840
2841 $author_query = '';
2842 if (!empty($authors)) {
2843 $post_authors = preg_split('/[\s,]+/',$authors);
2844
2845 if ( ! empty( $post_authors ) ) {
2846 foreach ( $post_authors as $post_author ) {
2847 //Do we have an author id or an author login?
2848 if ( 0 == intval($post_author) ) {
2849 $post_author = get_user_by('login', $post_author);
2850 if ( empty($post_author) )
2851 continue;
2852 if ( empty($post_author->ID) )
2853 continue;
2854 $post_author = $post_author->ID;
2855 }
2856
2857 if ( '' == $author_query )
2858 $author_query = $wpdb->prepare(' post_author = %d ', $post_author);
2859 else
2860 $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
2861 }
2862 if ( '' != $author_query )
2863 $author_query = " AND ($author_query)";
2864 }
2865 }
2866
2867 $join = '';
2868 $where = "$exclusions $inclusions ";
2869 if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) {
2870 $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
2871
2872 // meta_key and meta_value might be slashed
2873 $meta_key = stripslashes($meta_key);
2874 $meta_value = stripslashes($meta_value);
2875 if ( ! empty( $meta_key ) )
2876 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
2877 if ( ! empty( $meta_value ) )
2878 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
2879
2880 }
2881
2882 if ( $parent >= 0 )
2883 $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
2884
2885
2886 if ( 1 == count ( $post_type ) ) {
2887 $where_post_type = $wpdb->prepare( "post_type = %s", array_shift( $post_type ) );
2888 } else {
2889 $post_type = implode( "', '", $post_type );
2890 $where_post_type = "post_type IN ('$post_type')";
2891 }
2892
2893 if ( 1 == count( $post_status ) ) {
2894 $where_post_type .= $wpdb->prepare( " AND post_status = %s", array_shift( $post_status ) );
2895 } else {
2896 $post_status = implode( "', '", $post_status );
2897 $where_post_type .= " AND post_status IN ('$post_status')";
2898 }
2899
2900 $orderby_array = array();
2901 $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
2902 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
2903 'ID', 'rand', 'comment_count');
2904 foreach ( explode( ',', $sort_column ) as $orderby ) {
2905 $orderby = trim( $orderby );
2906 if ( !in_array( $orderby, $allowed_keys ) )
2907 continue;
2908
2909 switch ( $orderby ) {
2910 case 'menu_order':
2911 break;
2912 case 'ID':
2913 $orderby = "$wpdb->posts.ID";
2914 break;
2915 case 'rand':
2916 $orderby = 'RAND()';
2917 break;
2918 case 'comment_count':
2919 $orderby = "$wpdb->posts.comment_count";
2920 break;
2921 default:
2922 if ( 0 === strpos( $orderby, 'post_' ) )
2923 $orderby = "$wpdb->posts." . $orderby;
2924 else
2925 $orderby = "$wpdb->posts.post_" . $orderby;
2926 }
2927
2928 $orderby_array[] = $orderby;
2929
2930 }
2931 $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title";
2932
2933 $sort_order = strtoupper( $sort_order );
2934 if ( '' !== $sort_order && !in_array( $sort_order, array( 'ASC', 'DESC' ) ) )
2935 $sort_order = 'ASC';
2936
2937 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
2938 $query .= $author_query;
2939 $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
2940
2941 if ( !empty($number) )
2942 $query .= ' LIMIT ' . $offset . ',' . $number;
2943
2944 echo "<!-- accua_forms_query:\n$query\n-->";
2945
2946 $pages = $wpdb->get_results($query);
2947
2948 if ( empty($pages) ) {
2949 $pages = apply_filters('get_pages', array(), $r);
2950 return $pages;
2951 }
2952
2953 // Sanitize before caching so it'll only get done once
2954 $num_pages = count($pages);
2955 for ($i = 0; $i < $num_pages; $i++) {
2956 $pages[$i] = sanitize_post($pages[$i], 'raw');
2957 }
2958
2959 /*
2960 // Update cache.
2961 update_post_cache( $pages );
2962 */
2963
2964 if ( $child_of || $hierarchical )
2965 $pages = & get_page_children($child_of, $pages);
2966
2967 if ( !empty($exclude_tree) ) {
2968 $exclude = (int) $exclude_tree;
2969 $children = get_page_children($exclude, $pages);
2970 $excludes = array();
2971 foreach ( $children as $child )
2972 $excludes[] = $child->ID;
2973 $excludes[] = $exclude;
2974 $num_pages = count($pages);
2975 for ( $i = 0; $i < $num_pages; $i++ ) {
2976 if ( in_array($pages[$i]->ID, $excludes) )
2977 unset($pages[$i]);
2978 }
2979 }
2980
2981 /*
2982 $cache[ $key ] = $pages;
2983 wp_cache_set( 'get_pages', $cache, 'posts' );
2984 */
2985
2986 $pages = apply_filters('get_pages', $pages, $r);
2987
2988 return $pages;
2989 }
2990