| 1 |
<?php |
| 2 |
/** |
| 3 |
* Display select field. |
| 4 |
* |
| 5 |
* @author David Bisset |
| 6 |
* @package Charitable/Admin View/Settings |
| 7 |
* @copyright Copyright (c) 2022, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.0.0 |
| 10 |
* @version 1.6.25 |
| 11 |
*/ |
| 12 |
|
| 13 |
$value = charitable_get_option( $view_args['key'] ); |
| 14 |
|
| 15 |
if ( false === $value ) { |
| 16 |
$value = isset( $view_args['default'] ) ? $view_args['default'] : ''; |
| 17 |
} |
| 18 |
|
| 19 |
$form_action_url = isset( $view_args['form_action_url'] ) ? $view_args['form_action_url'] : ''; |
| 20 |
$form_action_method = isset( $view_args['form_action_method'] ) ? $view_args['form_action_method'] : 'POST'; |
| 21 |
$button_label = isset( $view_args['button_label'] ) ? $view_args['button_label'] : 'Submit'; |
| 22 |
$nonce_action_name = isset( $view_args['nonce_action_name'] ) ? $view_args['nonce_action_name'] : 'wpcharitable-action'; |
| 23 |
$nonce_field_name = isset( $view_args['nonce_field_name'] ) ? $view_args['nonce_field_name'] : false; |
| 24 |
$select_name = isset( $view_args['select_name'] ) ? $view_args['select_name'] : $view_args['name']; |
| 25 |
$error_message = false; |
| 26 |
|
| 27 |
// determine if the fields should be shown, based on what we are trying to do with them. |
| 28 |
if ( isset( $view_args['nonce_action_name'] ) && 'import_donations' === $view_args['nonce_action_name'] && is_array( $view_args['options'] ) && 0 === count( $view_args['options'] ) ) { |
| 29 |
$error_message = '<strong>' . __('You have no campaigns to import donations into.', 'charitable' ) . '</strong>.'; |
| 30 |
} |
| 31 |
?> |
| 32 |
<form action="<?php echo $form_action_url; ?>" method="POST" enctype="multipart/form-data" class="form-contains-file"> |
| 33 |
|
| 34 |
<?php wp_nonce_field( $nonce_action_name, $nonce_field_name ); ?> |
| 35 |
|
| 36 |
<?php if ( isset( $view_args['options'] ) && ! $error_message ) : ?> |
| 37 |
<p class="top-label"><?php _e('Select a campaign to import donations into:', 'charitable' ); ?></p> |
| 38 |
<?php endif; ?> |
| 39 |
|
| 40 |
<?php if ( isset( $view_args['options'] ) ) : ?> |
| 41 |
<div class="charitable-setting-dropdown-container"> |
| 42 |
<?php if ( ! $error_message ) { ?> |
| 43 |
<select id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); ?>" |
| 44 |
name="<?php printf( 'charitable_settings[%s]', $select_name ); ?>" |
| 45 |
class="<?php echo esc_attr( $view_args['classes'] ); ?>" |
| 46 |
<?php echo charitable_get_arbitrary_attributes( $view_args ); ?> |
| 47 |
> |
| 48 |
<?php |
| 49 |
foreach ( $view_args['options'] as $key => $option ) : |
| 50 |
if ( is_array( $option ) ) : |
| 51 |
$label = isset( $option['label'] ) ? $option['label'] : ''; |
| 52 |
?> |
| 53 |
<optgroup label="<?php echo $label; ?>"> |
| 54 |
<?php foreach ( $option['options'] as $k => $opt ) : ?> |
| 55 |
<option value="<?php echo $k; ?>" <?php selected( $k, $value ); ?>><?php echo $opt; ?></option> |
| 56 |
<?php endforeach ?> |
| 57 |
</optgroup> |
| 58 |
<?php else : ?> |
| 59 |
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $value ); ?>><?php echo $option; ?></option> |
| 60 |
<?php |
| 61 |
endif; |
| 62 |
endforeach |
| 63 |
?> |
| 64 |
</select> |
| 65 |
<?php } else { ?> |
| 66 |
<p><?php echo $error_message; ?></p> |
| 67 |
<?php } ?> |
| 68 |
<?php endif; ?> |
| 69 |
</div> |
| 70 |
<?php if ( ! $error_message ) { ?> |
| 71 |
<div class="charitable-setting-file-container"> |
| 72 |
|
| 73 |
<input type="file" id="<?php printf( 'charitable_settings_%s', implode( '_', $view_args['key'] ) ); ?>" |
| 74 |
name="<?php printf( 'charitable_settings[%s]', $view_args['name'] ); ?>" |
| 75 |
class="<?php echo esc_attr( $view_args['classes'] ); ?>" |
| 76 |
<?php echo charitable_get_arbitrary_attributes( $view_args ); ?> |
| 77 |
accept=".jsn,.json" |
| 78 |
/> |
| 79 |
<input class="button button-primary" type="submit" value="<?php echo $button_label; ?>"> |
| 80 |
|
| 81 |
</div> |
| 82 |
<?php } ?> |
| 83 |
</form> |
| 84 |
<?php if ( isset( $view_args['help'] ) ) : ?> |
| 85 |
<div class="charitable-help"><?php echo $view_args['help']; ?></div> |
| 86 |
<?php |
| 87 |
endif; |
| 88 |
|