| 1 | <?php |
| 2 | /** |
| 3 | * Automate Gravatar Fetching and Export Selected Columns Addon for CampTix |
| 4 | */ |
| 5 | class CampTix_Addon_Export_selected_cols extends CampTix_Addon { |
| 6 | |
| 7 | |
| 8 | // Stores all the Columns available to export |
| 9 | public $columns_available = array(); |
| 10 | |
| 11 | /** |
| 12 | * Runs during camptix_init, see CampTix_Addon |
| 13 | */ |
| 14 | function camptix_init() { |
| 15 | global $camptix; |
| 16 | add_filter( 'camptix_menu_tools_tabs', array( $this, 'menu_tools_export_selected' ) ); |
| 17 | add_action( 'camptix_menu_tools_export-selected-cols', array( $this, 'menu_tools_export_fetch_gravatars' ), 10, 0 ); |
| 18 | add_action( 'load-tix_ticket_page_camptix_tools', array( $this, 'export_admin_init' ) ); // same here, but close |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Add 'Export Selected Columns' Tab to Tickets > Tools |
| 23 | * |
| 24 | */ |
| 25 | function menu_tools_export_selected( $types ) { |
| 26 | return array_merge( $types, array( |
| 27 | 'export-selected-cols' => __( 'Export Selected Columns', 'export-selected-cols' ), |
| 28 | ) ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Export Selected Columns tools menu |
| 33 | * @see export_admin_init() |
| 34 | */ |
| 35 | function menu_tools_export_fetch_gravatars() { |
| 36 | ?> |
| 37 | <form method="post" action="<?php echo esc_url( add_query_arg( 'tix_export', 1 ) ); ?>"> |
| 38 | <table class="form-table"> |
| 39 | <tbody> |
| 40 | <tr> |
| 41 | <th scope="row"><?php _e( 'Export attendees data to CSV', 'camptix' ); ?></th> |
| 42 | |
| 43 | </tr> |
| 44 | <tr> |
| 45 | <th scope="row"><?php _e( 'Select the Columns to export', 'camptix' ); ?></th> |
| 46 | </tr> |
| 47 | <tr> |
| 48 | <?php |
| 49 | $columns = array( |
| 50 | 'id' => __( 'Attendee ID', 'camptix' ), |
| 51 | 'ticket' => __( 'Ticket Type', 'camptix' ), |
| 52 | 'first_name' => __( 'First Name', 'camptix' ), |
| 53 | 'last_name' => __( 'Last Name', 'camptix' ), |
| 54 | 'email' => __( 'E-mail Address', 'camptix' ), |
| 55 | 'date' => __( 'Purchase date', 'camptix' ), |
| 56 | 'modified_date' => __( 'Last Modified date', 'camptix' ), |
| 57 | 'status' => __( 'Status', 'camptix' ), |
| 58 | 'txn_id' => __( 'Transaction ID', 'camptix' ), |
| 59 | 'coupon' => __( 'Coupon', 'camptix' ), |
| 60 | 'buyer_name' => __( 'Ticket Buyer Name', 'camptix' ), |
| 61 | 'buyer_email' => __( 'Ticket Buyer E-mail Address', 'camptix' ), |
| 62 | ); |
| 63 | |
| 64 | $columns_default_checked = array( |
| 65 | 'first_name' => __( 'First Name', 'camptix' ), |
| 66 | 'last_name' => __( 'Last Name', 'camptix' ), |
| 67 | 'email' => __( 'E-mail Address', 'camptix' ), |
| 68 | ); |
| 69 | |
| 70 | $extra_columns = apply_filters( 'camptix_attendee_report_extra_columns', array() ); |
| 71 | $columns = array_merge( $columns, $extra_columns ); |
| 72 | |
| 73 | $field_no = 0; |
| 74 | |
| 75 | foreach ( $columns as $column ) { |
| 76 | |
| 77 | if ( $field_no != 0 && $field_no % 4 != 0) { |
| 78 | if ( in_array ( $column , $columns_default_checked ) ){ |
| 79 | ?> |
| 80 | <td><label><input type="checkbox" checked name="tix_export_cols[<?php echo $field_no;?>]" value="1" /> <?php _e( $column, 'camptix' ); ?></label></td> |
| 81 | <?php |
| 82 | $key = array_search( $column , $columns ); |
| 83 | array_push( $this->columns_available , $key ); |
| 84 | |
| 85 | } |
| 86 | else { |
| 87 | ?> |
| 88 | <td><label><input type="checkbox" name="tix_export_cols[<?php echo $field_no?>]" value="1" /> <?php _e( $column, 'camptix' ); ?></label></td> |
| 89 | <?php |
| 90 | $key = array_search( $column , $columns ); |
| 91 | array_push( $this->columns_available , $key ); |
| 92 | } |
| 93 | } |
| 94 | else { |
| 95 | if ( in_array ( $column , $columns_default_checked ) ){ |
| 96 | ?> |
| 97 | </tr><tr><td><label><input type="checkbox" checked name="tix_export_cols[<?php echo $field_no?>]" value="1" /> <?php _e( $column, 'camptix' ); ?></label></td> |
| 98 | <?php |
| 99 | $key = array_search( $column , $columns ); |
| 100 | array_push( $this->columns_available , $key ); |
| 101 | } |
| 102 | else { |
| 103 | ?> |
| 104 | </tr><tr><td><label><input type="checkbox" name="tix_export_cols[<?php echo $field_no?>]" value="1" /> <?php _e( $column, 'camptix' ); ?></label></td> |
| 105 | <?php |
| 106 | $key = array_search( $column , $columns ); |
| 107 | array_push( $this->columns_available , $key ); |
| 108 | } |
| 109 | } |
| 110 | $field_no++; |
| 111 | } |
| 112 | |
| 113 | ?> |
| 114 | |
| 115 | |
| 116 | </tr> |
| 117 | <tr> |
| 118 | <th scope="row"><?php _e( 'Select Questions to export', 'camptix' ); ?></th> |
| 119 | <?php |
| 120 | global $camptix; |
| 121 | $questions = $camptix->get_all_questions(); |
| 122 | |
| 123 | $field_no = 0; |
| 124 | foreach ( $questions as $question ) { |
| 125 | if ( get_post_meta( $question->ID, 'tix_type', true ) == 'twitter' ) |
| 126 | $columns_default_checked[ 'tix_export_q_' . $question->ID ] = $question->post_title; |
| 127 | |
| 128 | if ( $field_no != 0 && $field_no % 4 != 0) { |
| 129 | if ( in_array ( $question->post_title , $columns_default_checked ) ){ |
| 130 | ?> |
| 131 | <td><label><input type="checkbox" checked name="tix_export_questions[<?php echo $question->ID?>]" value="1" /> <?php _e( $question->post_title, 'camptix' ); ?></label></td> |
| 132 | <?php |
| 133 | }else { |
| 134 | ?> |
| 135 | <td><label><input type="checkbox" name="tix_export_questions[<?php echo $question->ID?>]" value="1" /> <?php _e( $question->post_title, 'camptix' ); ?></label></td> |
| 136 | <?php |
| 137 | |
| 138 | } |
| 139 | } |
| 140 | else { |
| 141 | if ( in_array ( $question->post_title , $columns_default_checked ) ){ |
| 142 | ?> |
| 143 | </tr><tr><td><label><input type="checkbox" checked name="tix_export_questions[<?php echo $question->ID?>]" value="1" /> <?php _e( $question->post_title, 'camptix' ); ?></label></td> |
| 144 | |
| 145 | <?php |
| 146 | } |
| 147 | else { |
| 148 | ?> |
| 149 | </tr><tr><td><label><input type="checkbox" name="tix_export_questions[<?php echo $question->ID?>]" value="1" /> <?php _e( $question->post_title, 'camptix' ); ?></label></td> |
| 150 | <?php |
| 151 | |
| 152 | } |
| 153 | } |
| 154 | $field_no++; |
| 155 | } |
| 156 | ?> |
| 157 | </tr> |
| 158 | <tr> |
| 159 | <th><?php _e('Generate CSV for InDesign', 'camptix'); ?></th> |
| 160 | <td><label><input type="checkbox" name="tix_export_include_gravatars" value="1" /> <?php _e('Include Gravatars' , 'camptix'); ?></label></td> |
| 161 | </tr> |
| 162 | <tr> |
| 163 | <th><?php _e('Enter Folder/ Directory Path relative to WP ABSPATH to store the temp Zip File '); ?></th> |
| 164 | <td><input type="textbox" class="regular-text" name="tix_export_path_to_zip" value="output/camptix-gravatar-badges/" placeholder="Ex : /folder_for_zips/"/> |
| 165 | <?php _e( '<br>Please make sure the Directory exists <br>and it is accessible to the server');?> |
| 166 | </td> |
| 167 | </tr> |
| 168 | </tbody> |
| 169 | </table> |
| 170 | <p class="submit"> |
| 171 | <?php wp_nonce_field( 'tix_export' ); ?> |
| 172 | <input type="hidden" name="tix_export_submit" value="1" /> |
| 173 | <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Generate CSV/ ZIP', 'camptix' ); ?>" /> |
| 174 | </p> |
| 175 | </form> |
| 176 | <?php |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Fired at almost admin_init, used to serve the export download file. |
| 181 | * @see menu_tools_export() |
| 182 | */ |
| 183 | function export_admin_init() { |
| 184 | global $post, $camptix; |
| 185 | $errors = array(); |
| 186 | if ( ! current_user_can( $camptix->caps['manage_tools'] ) || 'export-selected-cols' != $camptix->get_tools_section() ) |
| 187 | return; |
| 188 | |
| 189 | if ( isset( $_POST['tix_export_submit'] ) && isset( $_GET['tix_export'] ) ) { |
| 190 | |
| 191 | if ( isset( $_POST['tix_export_include_gravatars'] ) && !isset ( $_POST[ 'tix_export_path_to_zip' ] ) ) { |
| 192 | |
| 193 | $errors[] = __( 'Please select a Folder Path for ZIP file export.', 'camptix' ); |
| 194 | } |
| 195 | |
| 196 | if ( ! isset( $_POST[ 'tix_export_cols' ] ) || count( $_POST[ 'tix_export_cols' ] ) == 0 ) |
| 197 | $errors[] = __( 'Please Select atleast one column to Export.', 'camptix' ); |
| 198 | |
| 199 | if ( isset( $_POST['tix_export_include_gravatars'] ) && isset ( $_POST[ 'tix_export_path_to_zip' ] ) && ! is_dir( ABSPATH . $_POST[ 'tix_export_path_to_zip' ] ) ) |
| 200 | $errors[] = __( 'Please enter a proper Path. Also, make sure it is accessible to the server', 'camptix' ); |
| 201 | |
| 202 | |
| 203 | if ( ( count( $errors ) == 0 ) ) { |
| 204 | |
| 205 | $format = 'csv'; |
| 206 | |
| 207 | $selected_columns = array(); |
| 208 | $selected_columns = array_map( 'strval', (array) $_POST['tix_export_cols'] ); |
| 209 | |
| 210 | $selected_questions = array(); |
| 211 | $selected_questions = array_map( 'strval', (array) $_POST['tix_export_questions'] ); |
| 212 | |
| 213 | $this->generate_attendee_report_with_gravatars( $format , $selected_columns , $selected_questions ); |
| 214 | die(); |
| 215 | } |
| 216 | else { |
| 217 | if ( count( $errors ) > 0 ) |
| 218 | foreach ( $errors as $error ) |
| 219 | add_settings_error( 'camptix', false, $error ); |
| 220 | } |
| 221 | |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Generate and return the raw attendee report contents with or without Gravatars |
| 227 | */ |
| 228 | function generate_attendee_report_with_gravatars( $format , $selected_columns , $selected_questions ) { |
| 229 | global $camptix; |
| 230 | |
| 231 | // Configuration |
| 232 | $gravatar_dir = ABSPATH . $_POST[ 'tix_export_path_to_zip' ]; |
| 233 | |
| 234 | // Boolean to Replace Empty Twitter Account with the First Name of Attendee |
| 235 | $replace_empty_twitter = false; |
| 236 | |
| 237 | if ( isset( $_POST[ 'tix_export_path_to_zip' ] )) |
| 238 | $path_to_zip = $_POST[ 'tix_export_path_to_zip' ]; |
| 239 | else |
| 240 | $path_to_zip = get_option('camptix_zip_folder_path'); |
| 241 | |
| 242 | $time_start = microtime( true ); |
| 243 | |
| 244 | $columns_nos = (array) array_keys( $selected_columns ); |
| 245 | |
| 246 | $columns = array(); |
| 247 | |
| 248 | $this->columns_available = $this->get_all_columns_available(); |
| 249 | $this->columns_available = array_values( $this->columns_available ); |
| 250 | |
| 251 | $questions_selected = array_keys( $selected_questions ); |
| 252 | |
| 253 | $question_titles = array(); |
| 254 | foreach ( $questions_selected as $question_id ) { |
| 255 | array_push( $question_titles , get_the_title( $question_id )); |
| 256 | } |
| 257 | |
| 258 | $column_key = 0; |
| 259 | foreach ( $columns_nos as $columns_no ) { |
| 260 | $columns[ $column_key ] = $this->columns_available[ $columns_no ]; |
| 261 | $column_key++; |
| 262 | } |
| 263 | |
| 264 | $all_column_headers = array_merge( $columns , $question_titles ); |
| 265 | |
| 266 | if ( isset( $_POST[ 'tix_export_include_gravatars' ] ) ) |
| 267 | array_push( $all_column_headers, '@Gravatars' ); |
| 268 | |
| 269 | ob_start(); |
| 270 | |
| 271 | // For CSV Download |
| 272 | $report = fopen( "php://output", 'w' ); |
| 273 | |
| 274 | // For CSV to be included in ZIP Download |
| 275 | $filename_2 = sprintf( 'camptix-export-%s.csv', date( 'Y-m-d' )); |
| 276 | $report_2 = fopen( $gravatar_dir . $filename_2, 'w' ); |
| 277 | |
| 278 | fputcsv( $report, $all_column_headers ); |
| 279 | fputcsv( $report_2, $all_column_headers ); |
| 280 | |
| 281 | $paged = 1; |
| 282 | while ( $attendees = get_posts( array( |
| 283 | 'post_type' => 'tix_attendee', |
| 284 | 'post_status' => array( 'publish', 'pending' ), |
| 285 | 'posts_per_page' => 200, |
| 286 | 'paged' => $paged++, |
| 287 | 'orderby' => 'ID', |
| 288 | 'order' => 'ASC', |
| 289 | 'cache_results' => false, |
| 290 | ) ) ) { |
| 291 | |
| 292 | $attendee_ids = array(); |
| 293 | foreach ( $attendees as $attendee ) |
| 294 | $attendee_ids[] = $attendee->ID; |
| 295 | |
| 296 | |
| 297 | $camptix->filter_post_meta = $camptix->prepare_metadata_for( $attendee_ids ); |
| 298 | unset( $attendee_ids, $attendee ); |
| 299 | |
| 300 | foreach ( $attendees as $attendee ) { |
| 301 | $attendee_id = $attendee->ID; |
| 302 | |
| 303 | $buyer = get_posts( array( |
| 304 | 'post_type' => 'tix_attendee', |
| 305 | 'post_status' => array( 'publish', 'pending' ), |
| 306 | 'posts_per_page' => 1, |
| 307 | 'orderby' => 'ID', |
| 308 | 'order' => 'ASC', |
| 309 | |
| 310 | 'meta_query' => array( |
| 311 | array( |
| 312 | 'key' => 'tix_access_token', |
| 313 | 'value' => get_post_meta( $attendee->ID, 'tix_access_token', true ), |
| 314 | ), |
| 315 | ), |
| 316 | ) ); |
| 317 | |
| 318 | $attendee_details = array( |
| 319 | 'id' => $attendee_id, |
| 320 | 'ticket' => $camptix->get_ticket_title( intval( get_post_meta( $attendee_id, 'tix_ticket_id', true ) ) ), |
| 321 | 'first_name' => get_post_meta( $attendee_id, 'tix_first_name', true ), |
| 322 | 'last_name' => get_post_meta( $attendee_id, 'tix_last_name', true ), |
| 323 | 'email' => get_post_meta( $attendee_id, 'tix_email', true ), |
| 324 | 'date' => mysql2date( 'Y-m-d g:ia', $attendee->post_date ), |
| 325 | 'modified_date' => mysql2date( 'Y-m-d g:ia', $attendee->post_modified ), |
| 326 | 'status' => ucfirst( $attendee->post_status ), |
| 327 | 'txn_id' => get_post_meta( $attendee_id, 'tix_transaction_id', true ), |
| 328 | 'coupon' => get_post_meta( $attendee_id, 'tix_coupon', true ), |
| 329 | 'buyer_name' => empty( $buyer[0]->post_title ) ? '' : $buyer[0]->post_title, |
| 330 | 'buyer_email' => get_post_meta( $attendee_id, 'tix_receipt_email', true ), |
| 331 | ); |
| 332 | |
| 333 | $line = array(); |
| 334 | |
| 335 | $index = 0; |
| 336 | // Take the Needed Attendee Details and leave everything else |
| 337 | foreach ( $columns as $column ) { |
| 338 | |
| 339 | if ( array_key_exists( $column , $attendee_details ) ){ |
| 340 | if ( $column == 'email' ) |
| 341 | $email_index = $index; |
| 342 | if ( $column == 'first_name' ) |
| 343 | $fname_index = $index; |
| 344 | if ( $column == 'last_name' ) |
| 345 | $lname_index = $index; |
| 346 | array_push( $line, $attendee_details[ $column ] ); |
| 347 | } |
| 348 | $index++; |
| 349 | |
| 350 | } |
| 351 | |
| 352 | $answers = (array) get_post_meta( $attendee_id, 'tix_questions', true ); |
| 353 | |
| 354 | foreach ( $questions_selected as $question ) { |
| 355 | |
| 356 | |
| 357 | if ( trim( get_the_title( $question ) == 'Twitter URL' ) ) { |
| 358 | if ( ! isset ( $answers[ $question] ) ) |
| 359 | $twitter_url = ''; |
| 360 | else |
| 361 | $twitter_url = $answers[ $question ]; |
| 362 | |
| 363 | // If they don't have a Twitter handle, add their first name instead. |
| 364 | //Add a @ to Twitter handles to avoid confusing them with first names. |
| 365 | if ( empty ( $twitter_url ) ) { |
| 366 | if ( $replace_empty_twitter ) { |
| 367 | $answers [ $question ] = $line[0]; |
| 368 | } |
| 369 | } else { |
| 370 | // Strip out everything but the username, and prefix a @ |
| 371 | $answers [ $question ] = '@' . preg_replace( |
| 372 | '/ |
| 373 | (https?:\/\/)? |
| 374 | (twitter\.com\/)? |
| 375 | (@)? |
| 376 | /ix', |
| 377 | '', |
| 378 | $twitter_url |
| 379 | ); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | // For multiple checkboxes |
| 384 | if ( isset( $answers[ $question ] ) && is_array( $answers[ $question ] ) ) |
| 385 | $answers[ $question ] = implode( ', ', (array) $answers[ $question ] ); |
| 386 | |
| 387 | if( isset( $answers [ $question ] ) ) { |
| 388 | array_push( $line, $answers[ $question ] ); |
| 389 | } |
| 390 | else { |
| 391 | array_push( $line, '' ); |
| 392 | } |
| 393 | |
| 394 | } |
| 395 | |
| 396 | $extra_columns = apply_filters( 'camptix_attendee_report_extra_columns', array() ); |
| 397 | |
| 398 | foreach ( $extra_columns as $index => $label ) { |
| 399 | $line[ $index ] = apply_filters( 'camptix_attendee_report_column_value_' . $index, '', $attendee ); |
| 400 | $line[ $index ] = apply_filters( 'camptix_attendee_report_column_value', $line[ $index ], $index, $attendee ); |
| 401 | } |
| 402 | |
| 403 | |
| 404 | if ( isset( $_POST['tix_export_include_gravatars'] ) ) { |
| 405 | |
| 406 | array_push( $all_column_headers, '@Gravatar'); |
| 407 | // Create empty badges for unknown attendees |
| 408 | if ( ( 'unknown.attendee@example.org' == $line[ $email_index ] ) ) { |
| 409 | $line = array(); |
| 410 | } |
| 411 | |
| 412 | $filename_jpg = 'mystery-man.jpg'; |
| 413 | |
| 414 | // Download the Gravatar |
| 415 | if ( $line[ $email_index ] ) { |
| 416 | $gravatar_source = wp_remote_get( 'http://www.gravatar.com/avatar/' . md5( strtolower( trim( $line[ $email_index ] ) ) ) . '.jpg?s=512&default=404' ); |
| 417 | if ( ! is_wp_error( $gravatar_source ) && 200 == $gravatar_source['response']['code'] ) { |
| 418 | |
| 419 | $filename_jpg = strtolower( remove_accents( $line[ $fname_index ] . '-' . $line[ $lname_index ] ) ); |
| 420 | $filename_jpg = sanitize_file_name( '-' . $filename_jpg . '.jpg' ); |
| 421 | $gravatar_file = fopen( $gravatar_dir . '/' . $filename_jpg, 'w' ); |
| 422 | fwrite( $gravatar_file, $gravatar_source['body'] ); |
| 423 | fclose( $gravatar_file ); |
| 424 | |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | // Update the final CSV |
| 429 | array_push( $line, $gravatar_dir . $filename_jpg ); |
| 430 | } |
| 431 | |
| 432 | // Make sure every column is printed. |
| 433 | $clean_line = array(); |
| 434 | foreach ( $all_column_headers as $key => $caption ) |
| 435 | $clean_line[$key] = isset( $line[$key] ) ? $line[$key] : ''; |
| 436 | |
| 437 | fputcsv( $report, $clean_line ); |
| 438 | fputcsv( $report_2, $clean_line ); |
| 439 | |
| 440 | } |
| 441 | |
| 442 | |
| 443 | /** |
| 444 | * Don't forget to clear up the used meta sort-of cache. |
| 445 | */ |
| 446 | $camptix->filter_post_meta = false; |
| 447 | } |
| 448 | |
| 449 | |
| 450 | fclose( $report ); |
| 451 | fclose( $report_2 ); |
| 452 | $report = ob_get_clean(); |
| 453 | |
| 454 | if ( !isset( $_POST['tix_export_include_gravatars'] ) ) { |
| 455 | export_to_csv( $report ); |
| 456 | return $report; |
| 457 | } |
| 458 | else { |
| 459 | |
| 460 | $format_zip = 'zip'; |
| 461 | $filename_zip = sprintf( 'camptix-export-%s.%s', date( 'Y-m-d' ), $format_zip ); |
| 462 | |
| 463 | $camptix->log( sprintf( 'Finished %s data export in %s seconds.', $format, microtime(true) - $time_start ) ); |
| 464 | |
| 465 | $files_in_gravatar_dir = scandir( $gravatar_dir ); |
| 466 | |
| 467 | zip_Files_and_Download( $files_in_gravatar_dir , $filename_zip , $gravatar_dir ); |
| 468 | |
| 469 | |
| 470 | exit(); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | |
| 475 | function get_all_columns_available(){ |
| 476 | global $camptix; |
| 477 | |
| 478 | $columns = array( |
| 479 | 'id' => __( 'Attendee ID', 'camptix' ), |
| 480 | 'ticket' => __( 'Ticket Type', 'camptix' ), |
| 481 | 'first_name' => __( 'First Name', 'camptix' ), |
| 482 | 'last_name' => __( 'Last Name', 'camptix' ), |
| 483 | 'email' => __( 'E-mail Address', 'camptix' ), |
| 484 | 'date' => __( 'Purchase date', 'camptix' ), |
| 485 | 'modified_date' => __( 'Last Modified date', 'camptix' ), |
| 486 | 'status' => __( 'Status', 'camptix' ), |
| 487 | 'txn_id' => __( 'Transaction ID', 'camptix' ), |
| 488 | 'coupon' => __( 'Coupon', 'camptix' ), |
| 489 | 'buyer_name' => __( 'Ticket Buyer Name', 'camptix' ), |
| 490 | 'buyer_email' => __( 'Ticket Buyer E-mail Address', 'camptix' ), |
| 491 | ); |
| 492 | |
| 493 | $columns = array_keys( $columns ); |
| 494 | $extra_columns = apply_filters( 'camptix_attendee_report_extra_columns', array() ); |
| 495 | $columns = array_merge( $columns, $extra_columns ); |
| 496 | |
| 497 | return $columns; |
| 498 | |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | function export_to_csv( $report ) { |
| 503 | |
| 504 | $format = 'csv'; |
| 505 | |
| 506 | $content_type = 'csv'; |
| 507 | |
| 508 | $filename = sprintf( 'camptix-export-csv-%s.%s', date( 'Y-m-d' ), $format ); |
| 509 | $filename = basename( $filename ); |
| 510 | header( 'Content-Type: ' . $content_type ); |
| 511 | header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); |
| 512 | header( "Cache-control: private" ); |
| 513 | header( 'Pragma: private' ); |
| 514 | header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); |
| 515 | |
| 516 | print_r( $report ); |
| 517 | return; |
| 518 | |
| 519 | } |
| 520 | |
| 521 | |
| 522 | function zip_Files_and_Download( $file_names, $archive_file_name, $file_path ) { |
| 523 | |
| 524 | $zip = new ZipArchive(); |
| 525 | |
| 526 | //create the file and throw the error if unsuccessful |
| 527 | if ( $zip->open( $archive_file_name, ZIPARCHIVE::CREATE ) !== TRUE ) { |
| 528 | exit("cannot open <$archive_file_name>\n"); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | //add each files of $file_name array to archive |
| 533 | foreach( $file_names as $files ) { |
| 534 | if( !is_dir( $files ) && ( $files !== "." ) && ( $files !== ".." ) && !strpos( $files , 'zip' ) ) |
| 535 | $zip->addFile( $file_path . $files, $files ); |
| 536 | } |
| 537 | |
| 538 | $zip->close(); |
| 539 | |
| 540 | unset($zip); |
| 541 | |
| 542 | //then send the headers to foce download the zip file |
| 543 | header("Content-type: application/zip"); |
| 544 | header("Content-Disposition: attachment; filename='" . basename( $archive_file_name ) . "'"); |
| 545 | header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); |
| 546 | header( "Cache-control: public" ); |
| 547 | readfile( basename( $archive_file_name ) ); |
| 548 | |
| 549 | unlink( $archive_file_name ); |
| 550 | |
| 551 | $files = scandir( $gravatar_dir ); // get all file names |
| 552 | foreach( $files as $file ){ // iterate files |
| 553 | if( is_file( $file ) ) |
| 554 | unlink( $file ); // delete file |
| 555 | } |
| 556 | |
| 557 | clearstatcache(); |
| 558 | |
| 559 | return; |
| 560 | |
| 561 | } |
| 562 | |
| 563 | |
| 564 | // Register this addon, creates an instance of this class when necessary. |
| 565 | camptix_register_addon( 'CampTix_Addon_Export_selected_cols' ); |