From d3c2d950a65b2cace0079d1561332a327888be88 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 4 May 2011 09:34:21 +0000 Subject: [PATCH] Fix: optimize code --- htdocs/paypal/transaction.php | 157 +++++++++++++++++----------------- 1 file changed, 80 insertions(+), 77 deletions(-) diff --git a/htdocs/paypal/transaction.php b/htdocs/paypal/transaction.php index 050159acaad..7b5a82e1f38 100644 --- a/htdocs/paypal/transaction.php +++ b/htdocs/paypal/transaction.php @@ -29,11 +29,20 @@ require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypalfunctions.lib.php"); $langs->load("paypal"); -$action = GETPOST('action'); - // Security check //$result=restrictedArea($user,'paypal'); +$action = GETPOST('action'); +$page = GETPOST("page",'int'); +$startDateStr=GETPOST('startDateStr'); +$endDateStr=GETPOST('endDateStr'); +$transactionID=urlencode(GETPOST('transactionID')); + +if ($page == -1) { $page = 0; } +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; + /* * Actions @@ -47,38 +56,32 @@ $action = GETPOST('action'); $nvpStr=''; -$startDateStr=GETPOST('startDateStr'); -$endDateStr=GETPOST('endDateStr'); -$transactionID=urlencode(GETPOST('transactionID')); - -if(isset($endDateStr) && ! empty($startDateStr)) { - $start_time = dol_stringtotime($startDateStr); - $iso_start = dol_print_date($start_time,'dayhourrfc'); - $nvpStr="&STARTDATE=$iso_start"; +if(isset($startDateStr) && ! empty($startDateStr)) { + $start_date_str = $startDateStr; + $start_time = dol_stringtotime($start_date_str); +} else { + $start_time = dol_now()-86400; + $start_date_str = dol_print_date($start_time,'day'); } +$iso_start = dol_print_date($start_time,'dayhourrfc'); +$nvpStr.="&STARTDATE=$iso_start"; + if(isset($endDateStr) && ! empty($endDateStr)) { - $end_time = dol_stringtotime($endDateStr); - $iso_end = dol_print_date($end_time,'dayhourrfc'); - $nvpStr.="&ENDDATE=$iso_end"; + $end_date_str = $endDateStr; + $end_time = dol_stringtotime($end_date_str); +} else { + $end_time = dol_now(); + $end_date_str = dol_print_date($end_time,'day'); } +$iso_end = dol_print_date($end_time,'dayhourrfc'); +$nvpStr.="&ENDDATE=$iso_end"; + if(isset($transactionID) && ! empty($transactionID)) { - $nvpStr=$nvpStr."&TRANSACTIONID=$transactionID"; + $nvpStr.="&TRANSACTIONID=$transactionID"; } -if (isset($startDateStr) && ! empty($startDateStr)) { - $start_date_str = $startDateStr; -} else { - $yesterdayDate = dol_now()-86400; - $start_date_str = dol_print_date($yesterdayDate,'day'); -} -if (isset($endDateStr) && ! empty($startDateStr)) { - $end_date_str = $endDateStr; -} else { - $currentDate = dol_now(); - $end_date_str = dol_print_date($currentDate,'day'); -} llxHeader(); @@ -110,6 +113,8 @@ llxHeader(); trans('PaypalTransaction'), $page, $_SERVER['PHP_SELF']); + print '
'; print ''; @@ -138,6 +143,7 @@ print ''; print '
'; +// Call Paypal API if (! empty($nvpStr)) { $resArray=hash_call("TransactionSearch",$nvpStr); @@ -155,59 +161,56 @@ if (! empty($nvpStr)) header("Location: $location"); } */ - - - print_barre_liste($title, $_GET['page'], $_SERVER['PHP_SELF'],'',$sortfield,$sortorder,'',$num); - - print ''; - print ''; - print_liste_field_titre($langs->trans('ID'),$_SERVER['PHP_SELF'],'','',''.$socid.'&viewstatut='.$viewstatut,'width="25%"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Date'),$_SERVER['PHP_SELF'],'','',''.$socid.'&viewstatut='.$viewstatut,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Status'),$_SERVER['PHP_SELF'],'','',''.$socid.'&viewstatut='.$viewstatut,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('ThirdPartyName'),$_SERVER['PHP_SELF'],'','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('GrossAmount'),$_SERVER['PHP_SELF'],'','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('FeeAmount'),$_SERVER['PHP_SELF'],'','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('NetAmount'),$_SERVER['PHP_SELF'],'','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); - print ''; - - if(! isset($resArray["L_TRANSACTIONID0"])) - { - print ''; - print ''; - print ''; - } - else - { - $i=0; - - while (isset($resArray["L_TRANSACTIONID".$i])) - { - $transactionID = $resArray["L_TRANSACTIONID".$i]; - $timeStamp = dol_stringtotime($resArray["L_TIMESTAMP".$i]); - $payerName = $resArray["L_NAME".$i]; - $amount = $resArray["L_AMT".$i]; - $feeamount = $resArray["L_FEEAMT".$i]; - $netamount = $resArray["L_NETAMT".$i]; - $currency = $resArray["L_CURRENCYCODE".$i]; - $status = $resArray["L_STATUS".$i]; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $i++; - } - } - - print '
'.$langs->trans("NoTransactionSelected").'
'.$transactionID.''.dol_print_date($timeStamp,'dayhour').''.$status.''.$payerName.''.$amount.' '.$currency.''.$feeamount.' '.$currency.''.$netamount.' '.$currency.'
'; } +print ''; +print ''; +print_liste_field_titre($langs->trans('ID'),$_SERVER['PHP_SELF'],'','',''.$socid.'&viewstatut='.$viewstatut,'width="25%"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('Date'),$_SERVER['PHP_SELF'],'','',''.$socid.'&viewstatut='.$viewstatut,'align="center"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('Status'),$_SERVER['PHP_SELF'],'','',''.$socid.'&viewstatut='.$viewstatut,'align="center"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('ThirdPartyName'),$_SERVER['PHP_SELF'],'','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('GrossAmount'),$_SERVER['PHP_SELF'],'','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('FeeAmount'),$_SERVER['PHP_SELF'],'','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('NetAmount'),$_SERVER['PHP_SELF'],'','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder); +print ''; + +if(! isset($resArray["L_TRANSACTIONID0"])) +{ + print ''; + print ''; + print ''; +} +else +{ + $i=0; + + while (isset($resArray["L_TRANSACTIONID".$i])) + { + $transactionID = $resArray["L_TRANSACTIONID".$i]; + $timeStamp = dol_stringtotime($resArray["L_TIMESTAMP".$i]); + $payerName = $resArray["L_NAME".$i]; + $amount = $resArray["L_AMT".$i]; + $feeamount = $resArray["L_FEEAMT".$i]; + $netamount = $resArray["L_NETAMT".$i]; + $currency = $resArray["L_CURRENCYCODE".$i]; + $status = $resArray["L_STATUS".$i]; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $i++; + } +} + +print '
'.$langs->trans("NoTransactionSelected").'
'.$transactionID.''.dol_print_date($timeStamp,'dayhour').''.$status.''.$payerName.''.$amount.' '.$currency.''.$feeamount.' '.$currency.''.$netamount.' '.$currency.'
'; + llxFooter('$Date$ - $Revision$'); ?> \ No newline at end of file