@@ -32,9 +32,8 @@ function kkd_pff_paystack_txncheck($name,$txncharge){
3232 function kkd_pff_paystack_setting_page () {
3333 ?>
3434 <h1>Paystack Forms API KEYS Settings!</h1>
35- <h3>Paystack</h3>
36-
37- <h4>Optional: To avoid situations where bad network makes it impossible to verify transactions, set your webhook URL <a href="https://dashboard.paystack.co/#/settings/developer">here</a> to the URL below<strong style="color: red"><pre><code><?php echo get_site_url ().'/kkd/wpffp/webhook/ ' ; ?> </code></pre></strong></
35+
36+ <h4>Optional: To avoid situations where bad network makes it impossible to verify transactions, set your webhook URL <a href="https://dashboard.paystack.co/#/settings/developer">here</a> to the URL below<strong style="color: red"><pre><code><?php echo admin_url ("admin-ajax.php " ) . "?action=kkd_paystack_pff " ;?> </code></pre></strong></
3837 <form method="post" action="options.php">
3938 <?php settings_fields ( 'kkd-pff-paystack-settings-group ' ); do_settings_sections ( 'kkd-pff-paystack-settings-group ' ); ?>
4039 <table class="form-table paystack_setting_page">
@@ -525,17 +524,22 @@ function kkd_pff_paystack_payment_submissions(){
525524 $ txncharge = get_post_meta ($ id ,'_txncharge ' ,true );
526525
527526 $ exampleListTable = new Kkd_Pff_Paystack_Payments_List_Table ();
528- $ exampleListTable ->prepare_items ();
527+ $ data = $ exampleListTable ->prepare_items ();
528+
529529 ?>
530530 <div id="welcome-panel" class="welcome-panel">
531531 <div class="welcome-panel-content">
532532 <h1 style="margin: 0px;"><?php echo $ obj ->post_title ; ?> Payments </h1>
533533 <p class="about-description">All payments made for this form</p>
534+ <?php if ($ data > 0 ) { ?>
535+
534536 <form action="<?php echo admin_url ('admin-post.php ' ); ?> " method="post">
535537 <input type="hidden" name="action" value="kkd_pff_export_excel">
536538 <input type="hidden" name="form_id" value="<?php echo $ id ; ?> ">
537539 <button type="submit" class="button button-primary button-hero load-customize" >Export Data to Excel</button>
538540 </form>
541+ <?php } ?>
542+
539543 <br><br>
540544 </div>
541545 </div>
@@ -563,91 +567,62 @@ function Kkd_pff_export_excel() {
563567 $ i = 0 ;
564568
565569 if (count ($ alldbdata ) > 0 ) {
566- $ header = $ alldbdata [0 ];
567- $ csv_output .= "#, " ;
568- $ csv_output .= "Email, " ;
569- $ csv_output .= "Amount, " ;
570- $ csv_output .= "Reference, " ;
571- $ new = json_decode ($ header ->metadata );
572- $ text = '' ;
573- if (array_key_exists ("0 " , $ new )) {
574- foreach ($ new as $ key => $ item ) {
575- $ csv_output .= $ item ->display_name .", " ;
576- }
577- }else {
578- if (count ($ new ) > 0 ) {
570+ $ header = $ alldbdata [0 ];
571+ $ csv_output .= "#, " ;
572+ $ csv_output .= "Email, " ;
573+ $ csv_output .= "Amount, " ;
574+ $ csv_output .= "Reference, " ;
575+ $ new = json_decode ($ header ->metadata );
576+ $ text = '' ;
577+ if (array_key_exists ("0 " , $ new )) {
579578 foreach ($ new as $ key => $ item ) {
580- $ csv_output .= $ key .", " ;
579+ $ csv_output .= $ item ->display_name .", " ;
580+ }
581+ }else {
582+ if (count ($ new ) > 0 ) {
583+ foreach ($ new as $ key => $ item ) {
584+ $ csv_output .= $ key .", " ;
585+ }
581586 }
582587 }
583- }
584- $ csv_output .= "\n" ;
585-
586-
587- }
588- foreach ($ alldbdata as $ key => $ dbdata ) {
589- $ newkey = $ key +1 ;
590- if ($ dbdata ->txn_code_2 != "" ) {
591- $ txn_code = $ dbdata ->txn_code_2 ;
592- }else {
593- $ txn_code = $ dbdata ->txn_code ;
594- }
595- // $csv_output .= $txn_code;//.",";
596- // $csv_output .= "\n";
597- // $i++;
598- // $data[] = array(
599- // 'id' => $newkey,
600- // 'email' => '<a href="mailto:'.$dbdata->email.'">'.$dbdata->email.'</a>',
601- // 'amount' => $currency.'<b>'.number_format($dbdata->amount).'</b>',
602- // 'txn_code' => $txn_code,
603- // 'metadata' => format_data($dbdata->metadata),
604- // 'date' => $dbdata->created_at
605- // );
606- $ csv_output .= $ newkey .", " ;
607- $ csv_output .= $ dbdata ->email .", " ;
608- $ csv_output .= $ currency .' ' .$ dbdata ->amount .", " ;
609- $ csv_output .= $ txn_code .", " ;
610- $ new = json_decode ($ header ->metadata );
611- $ text = '' ;
612- if (array_key_exists ("0 " , $ new )) {
613- foreach ($ new as $ key => $ item ) {
614- $ csv_output .= $ item ->value .", " ;
588+ $ csv_output .= "\n" ;
589+
590+ foreach ($ alldbdata as $ key => $ dbdata ) {
591+ $ newkey = $ key +1 ;
592+ if ($ dbdata ->txn_code_2 != "" ) {
593+ $ txn_code = $ dbdata ->txn_code_2 ;
594+ }else {
595+ $ txn_code = $ dbdata ->txn_code ;
615596 }
616- }else {
617- if (count ($ new ) > 0 ) {
597+ $ csv_output .= $ newkey .", " ;
598+ $ csv_output .= $ dbdata ->email .", " ;
599+ $ csv_output .= $ currency .' ' .$ dbdata ->amount .", " ;
600+ $ csv_output .= $ txn_code .", " ;
601+ $ new = json_decode ($ header ->metadata );
602+ $ text = '' ;
603+ if (array_key_exists ("0 " , $ new )) {
618604 foreach ($ new as $ key => $ item ) {
619- $ csv_output .= $ item .", " ;
605+ $ csv_output .= $ item ->value .", " ;
606+ }
607+ }else {
608+ if (count ($ new ) > 0 ) {
609+ foreach ($ new as $ key => $ item ) {
610+ $ csv_output .= $ item .", " ;
611+ }
620612 }
621613 }
614+ $ csv_output .= "\n" ;
622615 }
623- $ csv_output .= "\n" ;
624- }
625616
626- // $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
627- // mysql_select_db($db) or die("Can not connect.");
628-
629- // $result = mysql_query("SHOW COLUMNS FROM ".$table."");
630- // if (mysql_num_rows($result) > 0) {
631- // while ($row = mysql_fetch_assoc($result)) {
632- // $csv_output .= $row[‘Field’]."; ";
633- // $i++;
634- // }
635- // }
636-
637- // $values = mysql_query("SELECT * FROM ".$table."");
638- // while ($rowr = mysql_fetch_row($values)) {
639- // for ($j=0;$j<$i;$j++) {
640- // $csv_output .= $rowr[$j]."; ";
641- // }
642- // $csv_output .= "\n";
643- // }
644-
645- $ filename = $ obj ->post_title ."_payments_ " .date ("Y-m-d_H-i " ,time ());
646- header ("Content-type: application/vnd.ms-excel " );
647- header ("Content-disposition: csv " . date ("Y-m-d " ) . ".csv " );
648- header ( "Content-disposition: filename= " .$ filename .".csv " );
649- print $ csv_output ;
650- exit ;
617+
618+ $ filename = $ obj ->post_title ."_payments_ " .date ("Y-m-d_H-i " ,time ());
619+ header ("Content-type: application/vnd.ms-excel " );
620+ header ("Content-disposition: csv " . date ("Y-m-d " ) . ".csv " );
621+ header ( "Content-disposition: filename= " .$ filename .".csv " );
622+ print $ csv_output ;
623+ exit ;
624+ }
625+
651626
652627 // Handle request then generate response using echo or leaving PHP and using HTML
653628}
@@ -740,6 +715,9 @@ public function prepare_items(){
740715 $ data = array_slice ($ data ,(($ currentPage -1 )*$ perPage ),$ perPage );
741716 $ this ->_column_headers = array ($ columns , $ hidden , $ sortable );
742717 $ this ->items = $ data ;
718+
719+ $ rows = count ($ alldbdata );
720+ return $ rows ;
743721 }
744722 public function get_columns (){
745723 $ columns = array (
0 commit comments