| 1 |
<?php |
| 2 |
/** |
| 3 |
* Give Export Donations Settings |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @subpackage Classes/Give_Settings_Data |
| 7 |
* @copyright Copyright (c) 2016, GiveWP |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 2.1 |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
if ( ! class_exists( 'Give_Export_Donations' ) ) { |
| 17 |
|
| 18 |
/** |
| 19 |
* Class Give_Export_Donations |
| 20 |
* |
| 21 |
* @sine 2.1 |
| 22 |
*/ |
| 23 |
final class Give_Export_Donations { |
| 24 |
|
| 25 |
/** |
| 26 |
* Importer type |
| 27 |
* |
| 28 |
* @since 2.1 |
| 29 |
* |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
private $exporter_type = 'export_donations'; |
| 33 |
|
| 34 |
/** |
| 35 |
* Instance. |
| 36 |
* |
| 37 |
* @since 2.1 |
| 38 |
*/ |
| 39 |
private static $instance; |
| 40 |
|
| 41 |
/** |
| 42 |
* Singleton pattern. |
| 43 |
* |
| 44 |
* @since 2.1 |
| 45 |
* |
| 46 |
* @access private |
| 47 |
*/ |
| 48 |
private function __construct() { |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Get instance. |
| 53 |
* |
| 54 |
* @since 2.1 |
| 55 |
* |
| 56 |
* @access public |
| 57 |
* |
| 58 |
* @return static |
| 59 |
*/ |
| 60 |
public static function get_instance() { |
| 61 |
if ( null === static::$instance ) { |
| 62 |
self::$instance = new static(); |
| 63 |
} |
| 64 |
|
| 65 |
return self::$instance; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Setup |
| 70 |
* |
| 71 |
* @since 2.1 |
| 72 |
* |
| 73 |
* @return void |
| 74 |
*/ |
| 75 |
public function setup() { |
| 76 |
$this->setup_hooks(); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
/** |
| 81 |
* Setup Hooks. |
| 82 |
* |
| 83 |
* @since 2.1 |
| 84 |
* |
| 85 |
* @return void |
| 86 |
*/ |
| 87 |
private function setup_hooks() { |
| 88 |
if ( ! $this->is_donations_export_page() ) { |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
// Do not render main export tools page. |
| 93 |
remove_action( |
| 94 |
'give_admin_field_tools_export', |
| 95 |
[ |
| 96 |
'Give_Settings_Export', |
| 97 |
'render_export_field', |
| 98 |
], |
| 99 |
10 |
| 100 |
); |
| 101 |
|
| 102 |
// Render donation export page |
| 103 |
add_action( 'give_admin_field_tools_export', [ $this, 'render_page' ] ); |
| 104 |
|
| 105 |
// Print the HTML. |
| 106 |
add_action( 'give_tools_export_donations_form_start', [ $this, 'html' ] ); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Filter to modify the Taxonomy args |
| 111 |
* |
| 112 |
* @since 2.1 |
| 113 |
* |
| 114 |
* @param array $args args for Taxonomy |
| 115 |
* |
| 116 |
* @return array args for Taxonomy |
| 117 |
*/ |
| 118 |
function give_forms_taxonomy_dropdown( $args ) { |
| 119 |
$args['number'] = 30; |
| 120 |
|
| 121 |
return $args; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Print the HTML for core setting exporter. |
| 126 |
* |
| 127 |
* @since 2.1 |
| 128 |
*/ |
| 129 |
public function html() { |
| 130 |
?> |
| 131 |
<section id="give-export-donations"> |
| 132 |
<table class="widefat export-options-table give-table"> |
| 133 |
<tbody> |
| 134 |
<tr class="top"> |
| 135 |
<td colspan="2"> |
| 136 |
<h2 id="give-export-title"><?php _e( 'Export Donation History and Custom Fields to CSV', 'give' ); ?></h2> |
| 137 |
<p class="give-field-description"><?php _e( 'Download an export of donors for specific donation forms with the option to include custom fields.', 'give' ); ?></p> |
| 138 |
</td> |
| 139 |
</tr> |
| 140 |
|
| 141 |
<?php |
| 142 |
if ( give_is_setting_enabled( give_get_option( 'categories' ) ) ) { |
| 143 |
add_filter( 'give_forms_category_dropdown', [ $this, 'give_forms_taxonomy_dropdown' ] ); |
| 144 |
?> |
| 145 |
<tr> |
| 146 |
<td scope="row" class="row-title"> |
| 147 |
<label |
| 148 |
for="give_forms_categories"><?php _e( 'Filter by Categories:', 'give' ); ?></label> |
| 149 |
</td> |
| 150 |
<td class="give-field-wrap"> |
| 151 |
<div class="give-clearfix"> |
| 152 |
<?php |
| 153 |
echo Give()->html->category_dropdown( |
| 154 |
'give_forms_categories[]', |
| 155 |
0, |
| 156 |
[ |
| 157 |
'id' => 'give_forms_categories', |
| 158 |
'class' => 'give_forms_categories', |
| 159 |
'chosen' => true, |
| 160 |
'multiple' => true, |
| 161 |
'selected' => [], |
| 162 |
'show_option_all' => false, |
| 163 |
'placeholder' => __( 'Choose one or more from categories', 'give' ), |
| 164 |
'data' => [ 'search-type' => 'categories' ], |
| 165 |
] |
| 166 |
); |
| 167 |
?> |
| 168 |
</div> |
| 169 |
</td> |
| 170 |
</tr> |
| 171 |
<?php |
| 172 |
remove_filter( 'give_forms_category_dropdown', [ $this, 'give_forms_taxonomy_dropdown' ] ); |
| 173 |
} |
| 174 |
|
| 175 |
if ( give_is_setting_enabled( give_get_option( 'tags' ) ) ) { |
| 176 |
add_filter( 'give_forms_tag_dropdown', [ $this, 'give_forms_taxonomy_dropdown' ] ); |
| 177 |
?> |
| 178 |
<tr> |
| 179 |
<td scope="row" class="row-title"> |
| 180 |
<label |
| 181 |
for="give_forms_tags"><?php _e( 'Filter by Tags:', 'give' ); ?></label> |
| 182 |
</td> |
| 183 |
<td class="give-field-wrap"> |
| 184 |
<div class="give-clearfix"> |
| 185 |
<?php |
| 186 |
echo Give()->html->tags_dropdown( |
| 187 |
'give_forms_tags[]', |
| 188 |
0, |
| 189 |
[ |
| 190 |
'id' => 'give_forms_tags', |
| 191 |
'class' => 'give_forms_tags', |
| 192 |
'chosen' => true, |
| 193 |
'multiple' => true, |
| 194 |
'selected' => [], |
| 195 |
'show_option_all' => false, |
| 196 |
'placeholder' => __( 'Choose one or more from tags', 'give' ), |
| 197 |
'data' => [ 'search-type' => 'tags' ], |
| 198 |
] |
| 199 |
); |
| 200 |
?> |
| 201 |
</div> |
| 202 |
</td> |
| 203 |
</tr> |
| 204 |
<?php |
| 205 |
remove_filter( 'give_forms_tag_dropdown', [ $this, 'give_forms_taxonomy_dropdown' ] ); |
| 206 |
} |
| 207 |
?> |
| 208 |
|
| 209 |
<tr class="give-export-donation-form"> |
| 210 |
<td scope="row" class="row-title"> |
| 211 |
<label |
| 212 |
for="give_payment_form_select"><?php _e( 'Filter by Donation Form:', 'give' ); ?></label> |
| 213 |
</td> |
| 214 |
<td class="give-field-wrap"> |
| 215 |
<div class="give-clearfix"> |
| 216 |
<?php |
| 217 |
$args = [ |
| 218 |
'name' => 'forms', |
| 219 |
'id' => 'give-payment-form-select', |
| 220 |
'class' => 'give-width-25em', |
| 221 |
'chosen' => true, |
| 222 |
'placeholder' => __( 'All Forms', 'give' ), |
| 223 |
'data' => [ 'no-form' => __( 'No donation forms found', 'give' ) ], |
| 224 |
]; |
| 225 |
echo Give()->html->forms_dropdown( $args ); |
| 226 |
?> |
| 227 |
|
| 228 |
<input type="hidden" name="form_ids" class="form_ids" /> |
| 229 |
</div> |
| 230 |
</td> |
| 231 |
</tr> |
| 232 |
|
| 233 |
<tr> |
| 234 |
<td scope="row" class="row-title"> |
| 235 |
<label for="give-payment-export-start"><?php _e( 'Filter by Date:', 'give' ); ?></label> |
| 236 |
</td> |
| 237 |
<td class="give-field-wrap"> |
| 238 |
<div class="give-clearfix"> |
| 239 |
<?php |
| 240 |
$args = [ |
| 241 |
'id' => 'give-payment-export-start', |
| 242 |
'name' => 'start', |
| 243 |
'placeholder' => __( 'Start Date', 'give' ), |
| 244 |
'autocomplete' => 'off', |
| 245 |
]; |
| 246 |
echo Give()->html->date_field( $args ); |
| 247 |
?> |
| 248 |
<?php |
| 249 |
$args = [ |
| 250 |
'id' => 'give-payment-export-end', |
| 251 |
'name' => 'end', |
| 252 |
'placeholder' => __( 'End Date', 'give' ), |
| 253 |
'autocomplete' => 'off', |
| 254 |
]; |
| 255 |
echo Give()->html->date_field( $args ); |
| 256 |
?> |
| 257 |
</div> |
| 258 |
</td> |
| 259 |
</tr> |
| 260 |
|
| 261 |
<tr> |
| 262 |
<td scope="row" class="row-title"> |
| 263 |
<label |
| 264 |
for="give-export-donations-status"><?php _e( 'Filter by Status:', 'give' ); ?></label> |
| 265 |
</td> |
| 266 |
<td> |
| 267 |
<div class="give-clearfix"> |
| 268 |
<select name="status" id="give-export-donations-status"> |
| 269 |
<option value="any"><?php _e( 'All Statuses', 'give' ); ?></option> |
| 270 |
<?php |
| 271 |
$statuses = give_get_payment_statuses(); |
| 272 |
foreach ( $statuses as $status => $label ) { |
| 273 |
echo '<option value="' . $status . '">' . $label . '</option>'; |
| 274 |
} |
| 275 |
?> |
| 276 |
</select> |
| 277 |
</div> |
| 278 |
</td> |
| 279 |
</tr> |
| 280 |
|
| 281 |
<?php |
| 282 |
/** |
| 283 |
* Add fields columns that are going to be exported when exporting donations |
| 284 |
* |
| 285 |
* @since 2.1 |
| 286 |
*/ |
| 287 |
do_action( 'give_export_donation_fields' ); |
| 288 |
?> |
| 289 |
|
| 290 |
<tr class="end"> |
| 291 |
<td> |
| 292 |
</td> |
| 293 |
<td> |
| 294 |
<?php wp_nonce_field( 'give_ajax_export', 'give_ajax_export' ); ?> |
| 295 |
<input type="hidden" name="give-export-class" value="Give_Export_Donations_CSV"/> |
| 296 |
<input type="button" value="<?php esc_attr_e( 'Deselect All Fields', 'give' ); ?>" data-value="<?php esc_attr_e( 'Select All Fields', 'give' ); ?>" class="give-toggle-checkbox-selection button button-secondary"> |
| 297 |
<input type="submit" value="<?php esc_attr_e( 'Generate CSV', 'give' ); ?>" class="give-export-donation-button button button-primary"> |
| 298 |
<div class="add-notices"></div> |
| 299 |
</td> |
| 300 |
</tr> |
| 301 |
</tbody> |
| 302 |
</table> |
| 303 |
</section> |
| 304 |
<?php |
| 305 |
} |
| 306 |
|
| 307 |
/** |
| 308 |
* Render donations export page |
| 309 |
* |
| 310 |
* @since 2.1 |
| 311 |
*/ |
| 312 |
public function render_page() { |
| 313 |
/** |
| 314 |
* Fires before displaying the export div tools. |
| 315 |
* |
| 316 |
* @since 2.1 |
| 317 |
*/ |
| 318 |
do_action( 'give_tools_export_donations_main_before' ); |
| 319 |
?> |
| 320 |
<div id="poststuff" class="give-clearfix"> |
| 321 |
<div class="postbox"> |
| 322 |
<h1 class="give-export-h1" align="center"><?php _e( 'Export Donations', 'give' ); ?></h1> |
| 323 |
<div class="inside give-tools-setting-page-export give-export_donations"> |
| 324 |
<?php |
| 325 |
/** |
| 326 |
* Fires before from start. |
| 327 |
* |
| 328 |
* @since 2.1 |
| 329 |
*/ |
| 330 |
do_action( 'give_tools_export_donations_form_before_start' ); |
| 331 |
?> |
| 332 |
<form method="post" |
| 333 |
id="give-export_donations-form" |
| 334 |
class="give-export-form tools-setting-page-export tools-setting-page-export" |
| 335 |
enctype="multipart/form-data"> |
| 336 |
|
| 337 |
<?php |
| 338 |
/** |
| 339 |
* Fires just after form start. |
| 340 |
* |
| 341 |
* @since 2.1 |
| 342 |
*/ |
| 343 |
do_action( 'give_tools_export_donations_form_start' ); |
| 344 |
?> |
| 345 |
|
| 346 |
<?php |
| 347 |
/** |
| 348 |
* Fires just after before form end. |
| 349 |
* |
| 350 |
* @since 2.1 |
| 351 |
*/ |
| 352 |
do_action( 'give_tools_export_donations_form_end' ); |
| 353 |
?> |
| 354 |
</form> |
| 355 |
<?php |
| 356 |
/** |
| 357 |
* Fires just after form end. |
| 358 |
* |
| 359 |
* @since 2.1 |
| 360 |
*/ |
| 361 |
do_action( 'give_tools_export_donations_form_after_end' ); |
| 362 |
?> |
| 363 |
</div><!-- .inside --> |
| 364 |
</div><!-- .postbox --> |
| 365 |
</div><!-- #poststuff --> |
| 366 |
<?php |
| 367 |
/** |
| 368 |
* Fires after displaying the export div tools. |
| 369 |
* |
| 370 |
* @since 2.1 |
| 371 |
*/ |
| 372 |
do_action( 'give_tools_export_donations_main_after' ); |
| 373 |
} |
| 374 |
|
| 375 |
/** |
| 376 |
* Get if current page export donations page or not |
| 377 |
* |
| 378 |
* @since 2.1 |
| 379 |
* |
| 380 |
* @return bool |
| 381 |
*/ |
| 382 |
private function is_donations_export_page() { |
| 383 |
return 'export' === give_get_current_setting_tab() && isset( $_GET['type'] ) && $this->exporter_type === give_clean( $_GET['type'] ); |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
Give_Export_Donations::get_instance()->setup(); |
| 388 |
} |
| 389 |
|