Skip to content

Commit

Permalink
Hide export button on no records.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kendysond committed Dec 20, 2016
1 parent 4e0523c commit 51eae9c
Showing 1 changed file with 58 additions and 80 deletions.
138 changes: 58 additions & 80 deletions admin/class-paystack-forms-admin.php
Expand Up @@ -32,9 +32,8 @@ function kkd_pff_paystack_txncheck($name,$txncharge){
function kkd_pff_paystack_setting_page() {
?>
<h1>Paystack Forms API KEYS Settings!</h1>
<h3>Paystack</h3>

<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></

<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></
<form method="post" action="options.php">
<?php settings_fields( 'kkd-pff-paystack-settings-group' ); do_settings_sections( 'kkd-pff-paystack-settings-group' ); ?>
<table class="form-table paystack_setting_page">
Expand Down Expand Up @@ -525,17 +524,22 @@ function kkd_pff_paystack_payment_submissions(){
$txncharge = get_post_meta($id,'_txncharge',true);

$exampleListTable = new Kkd_Pff_Paystack_Payments_List_Table();
$exampleListTable->prepare_items();
$data = $exampleListTable->prepare_items();

?>
<div id="welcome-panel" class="welcome-panel">
<div class="welcome-panel-content">
<h1 style="margin: 0px;"><?php echo $obj->post_title; ?> Payments </h1>
<p class="about-description">All payments made for this form</p>
<?php if ($data > 0) { ?>

<form action="<?php echo admin_url('admin-post.php'); ?>" method="post">
<input type="hidden" name="action" value="kkd_pff_export_excel">
<input type="hidden" name="form_id" value="<?php echo $id; ?>">
<button type="submit" class="button button-primary button-hero load-customize" >Export Data to Excel</button>
</form>
<?php } ?>

<br><br>
</div>
</div>
Expand Down Expand Up @@ -563,91 +567,62 @@ function Kkd_pff_export_excel() {
$i = 0;

if (count($alldbdata) > 0) {
$header = $alldbdata[0];
$csv_output .= "#,";
$csv_output .= "Email,";
$csv_output .= "Amount,";
$csv_output .= "Reference,";
$new = json_decode($header->metadata);
$text = '';
if (array_key_exists("0", $new)) {
foreach ($new as $key => $item) {
$csv_output .= $item->display_name.",";
}
}else{
if (count($new) > 0) {
$header = $alldbdata[0];
$csv_output .= "#,";
$csv_output .= "Email,";
$csv_output .= "Amount,";
$csv_output .= "Reference,";
$new = json_decode($header->metadata);
$text = '';
if (array_key_exists("0", $new)) {
foreach ($new as $key => $item) {
$csv_output .= $key.",";
$csv_output .= $item->display_name.",";
}
}else{
if (count($new) > 0) {
foreach ($new as $key => $item) {
$csv_output .= $key.",";
}
}
}
}
$csv_output .= "\n";


}
foreach ($alldbdata as $key => $dbdata) {
$newkey = $key+1;
if ($dbdata->txn_code_2 != "") {
$txn_code = $dbdata->txn_code_2;
}else{
$txn_code = $dbdata->txn_code;
}
// $csv_output .= $txn_code;//.",";
// $csv_output .= "\n";
// $i++;
// $data[] = array(
// 'id' => $newkey,
// 'email' => '<a href="mailto:'.$dbdata->email.'">'.$dbdata->email.'</a>',
// 'amount' => $currency.'<b>'.number_format($dbdata->amount).'</b>',
// 'txn_code' => $txn_code,
// 'metadata' => format_data($dbdata->metadata),
// 'date' => $dbdata->created_at
// );
$csv_output .= $newkey.",";
$csv_output .= $dbdata->email.",";
$csv_output .= $currency.' '.$dbdata->amount.",";
$csv_output .= $txn_code.",";
$new = json_decode($header->metadata);
$text = '';
if (array_key_exists("0", $new)) {
foreach ($new as $key => $item) {
$csv_output .= $item->value.",";
$csv_output .= "\n";

foreach ($alldbdata as $key => $dbdata) {
$newkey = $key+1;
if ($dbdata->txn_code_2 != "") {
$txn_code = $dbdata->txn_code_2;
}else{
$txn_code = $dbdata->txn_code;
}
}else{
if (count($new) > 0) {
$csv_output .= $newkey.",";
$csv_output .= $dbdata->email.",";
$csv_output .= $currency.' '.$dbdata->amount.",";
$csv_output .= $txn_code.",";
$new = json_decode($header->metadata);
$text = '';
if (array_key_exists("0", $new)) {
foreach ($new as $key => $item) {
$csv_output .= $item.",";
$csv_output .= $item->value.",";
}
}else{
if (count($new) > 0) {
foreach ($new as $key => $item) {
$csv_output .= $item.",";
}
}
}
$csv_output .= "\n";
}
$csv_output .= "\n";
}

// $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
// mysql_select_db($db) or die("Can not connect.");

// $result = mysql_query("SHOW COLUMNS FROM ".$table."");
// if (mysql_num_rows($result) > 0) {
// while ($row = mysql_fetch_assoc($result)) {
// $csv_output .= $row[‘Field’]."; ";
// $i++;
// }
// }

// $values = mysql_query("SELECT * FROM ".$table."");
// while ($rowr = mysql_fetch_row($values)) {
// for ($j=0;$j<$i;$j++) {
// $csv_output .= $rowr[$j]."; ";
// }
// $csv_output .= "\n";
// }

$filename = $obj->post_title."_payments_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;

$filename = $obj->post_title."_payments_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
}


// Handle request then generate response using echo or leaving PHP and using HTML
}
Expand Down Expand Up @@ -740,6 +715,9 @@ public function prepare_items(){
$data = array_slice($data,(($currentPage-1)*$perPage),$perPage);
$this->_column_headers = array($columns, $hidden, $sortable);
$this->items = $data;

$rows = count($alldbdata);
return $rows;
}
public function get_columns(){
$columns = array(
Expand Down

0 comments on commit 51eae9c

Please sign in to comment.