227. File Comparison Report

Produced on Mon May 12 13:05:17 2008 UTC. This report uses XHTML and CSS2, and is best viewed with a reasonably standards compliant browser such as the latest version of Firefox or Internet Explorer. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

227.1 Files compared

# Location File Last Modified
1 Dolphin-v.6.0.5\inc checkout.inc.php Wed Oct 17 08:48:20 2007 UTC
2 Dolphin-v.6.1.0\inc checkout.inc.php Sat Apr 26 08:19:16 2008 UTC

227.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 7 1962
Changed 0 0
Inserted 0 0
Removed 6 13

227.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

227.4 Active regular expressions

No regular expressions were active.

227.5 Comparison detail

1   <?php   1   <?php
2     2  
3   /********* ********** ********** ********** ********** ********** ********** ******   3   /********* ********** ********** ********** ********** ********** ********** ******
4   *                              D olphin Sma rt Communi ty Builder   4   *                              D olphin Sma rt Communi ty Builder
5   *                                 --------- --------   5   *                                 --------- --------
6   *     begi n                 : M on Mar 23  2006   6   *     begi n                 : M on Mar 23  2006
7   *     copy right             : ( C) 2006 Bo onEx Group   7   *     copy right             : ( C) 2006 Bo onEx Group
8   *     webs ite               : h ttp://www. boonex.com /   8   *     webs ite               : h ttp://www. boonex.com /
9   * This fil e is part  of Dolphin  - Smart C ommunity B uilder   9   * This fil e is part  of Dolphin  - Smart C ommunity B uilder
10   *   10   *
11   * Dolphin  is free so ftware. Th is work is  licensed  under a Cr eative Com mons Attri bution 3.0  License.    11   * Dolphin  is free so ftware. Th is work is  licensed  under a Cr eative Com mons Attri bution 3.0  License. 
12   * http://c reativecom mons.org/l icenses/by /3.0/   12   * http://c reativecom mons.org/l icenses/by /3.0/
13   *   13   *
14   * Dolphin  is distrib uted in th e hope tha t it will  be useful,  but WITHO UT ANY WAR RANTY;   14   * Dolphin  is distrib uted in th e hope tha t it will  be useful,  but WITHO UT ANY WAR RANTY;
15   * without  even the i mplied war ranty of   MERCHANTAB ILITY or F ITNESS FOR  A PARTICU LAR PURPOS E.   15   * without  even the i mplied war ranty of   MERCHANTAB ILITY or F ITNESS FOR  A PARTICU LAR PURPOS E.
16   * See the  Creative C ommons Att ribution 3 .0 License  for more  details.    16   * See the  Creative C ommons Att ribution 3 .0 License  for more  details. 
17   * You shou ld have re ceived a c opy of the  Creative  Commons At tribution  3.0 Licens e along wi th Dolphin   17   * You shou ld have re ceived a c opy of the  Creative  Commons At tribution  3.0 Licens e along wi th Dolphin
18   * see lice nse.txt fi le; if not , write to  marketing @boonex.co m   18   * see lice nse.txt fi le; if not , write to  marketing @boonex.co m
19   ********** ********** ********** ********** ********** ********** ********** *****/   19   ********** ********** ********** ********** ********** ********** ********** *****/
20     20  
21   require_on ce( 'heade r.inc.php'  );   21   require_on ce( 'heade r.inc.php'  );
22   require_on ce( BX_DIR ECTORY_PAT H_INC . 'd b.inc.php'  );   22   require_on ce( BX_DIR ECTORY_PAT H_INC . 'd b.inc.php'  );
23   require_on ce( BX_DIR ECTORY_PAT H_INC . 'u tils.inc.p hp' );   23   require_on ce( BX_DIR ECTORY_PAT H_INC . 'u tils.inc.p hp' );
24   require_on ce( BX_DIR ECTORY_PAT H_INC . 'p rofiles.in c.php' );   24   require_on ce( BX_DIR ECTORY_PAT H_INC . 'p rofiles.in c.php' );
25   require_on ce( BX_DIR ECTORY_PAT H_INC . 's dating.inc .php' );   25   require_on ce( BX_DIR ECTORY_PAT H_INC . 's dating.inc .php' );
26   require_on ce( BX_DIR ECTORY_PAT H_INC . 'm embership_ levels.inc .php' );   26   require_on ce( BX_DIR ECTORY_PAT H_INC . 'm embership_ levels.inc .php' );
27     27  
28   $separator  = '|';   28   $separator  = '|';
29   $dir['chec kout'] = $ dir['root' ] . 'check out/';   29   $dir['chec kout'] = $ dir['root' ] . 'check out/';
30   $site['che ckout'] =  $site['url '] . 'chec kout/';   30   $site['che ckout'] =  $site['url '] . 'chec kout/';
31     31  
32   $memberID  = (int)$_C OOKIE['mem berID'];   32   $memberID  = (int)$_C OOKIE['mem berID'];
33   $currency_ code = get Param( 'cu rrency_cod e' );   33   $currency_ code = get Param( 'cu rrency_cod e' );
34   $enable_re curring =  getParam(  'enable_re curring' )  == 'on';   34   $enable_re curring =  getParam(  'enable_re curring' )  == 'on';
35     35  
36   $cryptKey  = 'secret_ string';   36   $cryptKey  = 'secret_ string';
37     37  
38   /**   38   /**
39    * Implode s data arr ay key ele ments usin g global s eparator   39    * Implode s data arr ay key ele ments usin g global s eparator
40    *   40    *
41    * @param  array $dat a                     - array wi th transac tion data   41    * @param  array $dat a                     - array wi th transac tion data
42    *   42    *
43    * @return  string                          - imploded  string   43    * @return  string                          - imploded  string
44    *   44    *
45    *   45    *
46    */   46    */
47   function t ransDataTo String( $d ata )   47   function t ransDataTo String( $d ata )
48   {   48   {
49       global  $separato r;   49       global  $separato r;
50     50  
51       $res =  $data['me mberID'] .  $separato r;   51       $res =  $data['me mberID'] .  $separato r;
52       $res . = $data['a ction'] .  $separator ;   52       $res . = $data['a ction'] .  $separator ;
53       $res . = $data['a mount'] .  $separator ;   53       $res . = $data['a mount'] .  $separator ;
54       $res . = $data['c ryptedAmou nt'] . $se parator;   54       $res . = $data['c ryptedAmou nt'] . $se parator;
55       $res . = $data['c urrency']  . $separat or;   55       $res . = $data['c urrency']  . $separat or;
56       $res . = $data['d ata'] . $s eparator;   56       $res . = $data['d ata'] . $s eparator;
57       $res . = $data['c ryptedData '] . $sepa rator;   57       $res . = $data['c ryptedData '] . $sepa rator;
58       $res . = $data['t ranID'];   58       $res . = $data['t ranID'];
59     59  
60       return  $res;   60       return  $res;
61   }   61   }
62     62  
63   /**   63   /**
64    * Explode s string i nto data a rray using  global se parator   64    * Explode s string i nto data a rray using  global se parator
65    *   65    *
66    * @param  string $st ring                  - string t o explode   66    * @param  string $st ring                  - string t o explode
67    *   67    *
68    * @return  array                           - exploded  associati ve array   68    * @return  array                           - exploded  associati ve array
69    *   69    *
70    *   70    *
71    */   71    */
72   function t ransString ToData( $s tring )   72   function t ransString ToData( $s tring )
73   {   73   {
74       global  $separato r;   74       global  $separato r;
75     75  
76       $arr =  explode(  $separator , $string  );   76       $arr =  explode(  $separator , $string  );
77       $res =  array();   77       $res =  array();
78       $res[' memberID']  = $arr[0] ;   78       $res[' memberID']  = $arr[0] ;
79       $res[' action'] =  $arr[1];   79       $res[' action'] =  $arr[1];
80       $res[' amount'] =  $arr[2];   80       $res[' amount'] =  $arr[2];
81       $res[' cryptedAmo unt'] = $a rr[3];   81       $res[' cryptedAmo unt'] = $a rr[3];
82       $res[' currency']  = $arr[4] ;   82       $res[' currency']  = $arr[4] ;
83       $res[' data'] = $ arr[5];   83       $res[' data'] = $ arr[5];
84       $res[' cryptedDat a'] = $arr [6];   84       $res[' cryptedDat a'] = $arr [6];
85       $res[' tranID'] =  $arr[7];   85       $res[' tranID'] =  $arr[7];
86     86  
87       return  $res;   87       return  $res;
88   }   88   }
89     89  
90   /**   90   /**
91    * Encodes  data stri ng to pass  it throug h checkout  system   91    * Encodes  data stri ng to pass  it throug h checkout  system
92    *   92    *
93    * @param  string $st ring                  - string t o encode   93    * @param  string $st ring                  - string t o encode
94    *   94    *
95    * @return  string                          - encoded  string   95    * @return  string                          - encoded  string
96    *   96    *
97    *   97    *
98    */   98    */
99   function e ncodeStrin g( $string  )   99   function e ncodeStrin g( $string  )
100   {   100   {
101       return  urlencode ( base64_e ncode( $st ring ) );   101       return  urlencode ( base64_e ncode( $st ring ) );
102   }   102   }
103     103  
104   /**   104   /**
105    * Decodes  data stri ng receive d from che ckout syst em   105    * Decodes  data stri ng receive d from che ckout syst em
106    *   106    *
107    * @param  string $st ring                  - string t o decode   107    * @param  string $st ring                  - string t o decode
108    *   108    *
109    * @return  string                          - decoded  string   109    * @return  string                          - decoded  string
110    *   110    *
111    *   111    *
112    */   112    */
113   function d ecodeStrin g( $string  )   113   function d ecodeStrin g( $string  )
114   {   114   {
115       return  base64_de code( urld ecode( $st ring ) );   115       return  base64_de code( urld ecode( $st ring ) );
116   }   116   }
117     117  
118   /**   118   /**
119    * Returns  URL where  member sh ould be di rected aft er payment  completio n   119    * Returns  URL where  member sh ould be di rected aft er payment  completio n
120    *   120    *
121    * @param  string $ch eckoutActi on         - payment  type actio n (e.g mem ership, cr edits, etc )   121    * @param  string $ch eckoutActi on         - payment  type actio n (e.g mem ership, cr edits, etc )
122    * @param  string $da ta                    - payment  action dat a (e.g. me mbership I D or event  ID)   122    * @param  string $da ta                    - payment  action dat a (e.g. me mbership I D or event  ID)
123    *   123    *
124    * @return  string                          - return U RL   124    * @return  string                          - return U RL
125    *   125    *
126    *   126    *
127    */   127    */
128   function r eturnURLBy Action( $c heckoutAct ion, $data  )   128   function r eturnURLBy Action( $c heckoutAct ion, $data  )
129   {   129   {
130       global  $site;   130       global  $site;
131     131  
132       switch  ( $checko utAction )   132       switch  ( $checko utAction )
133       {   133       {
134           ca se 'member ship':   134           ca se 'member ship':
135                return " {$site['ur l']}member ship.php";   135                return " {$site['ur l']}member ship.php";
136           ca se 'speedd ating':   136           ca se 'speedd ating':
137                return " {$site['ur l']}events .php?actio n=show_inf o&event_id ={$data}";   137                return " {$site['ur l']}events .php?actio n=show_inf o&event_id ={$data}";
138           ca se 'credit s':    
139                return " {$site['ur l']}member ship.php";    
140           ca se 'profil es':   138           ca se 'profil es':
141                return " {$site['ur l']}result .php";   139                return " {$site['ur l']}result .php";
142           de fault:   140           de fault:
143                return ' ';   141                return ' ';
144       }   142       }
145   }   143   }
146     144  
147   /**   145   /**
148    * Returns  transacti on descrip tion   146    * Returns  transacti on descrip tion
149    *   147    *
150    * @param  string $ch eckoutActi on         - payment  type actio n (e.g mem ership, cr edits, etc )   148    * @param  string $ch eckoutActi on         - payment  type actio n (e.g mem ership, cr edits, etc )
151    * @param  string $da ta                    - payment  action dat a (e.g. me mbership I D or event  ID)   149    * @param  string $da ta                    - payment  action dat a (e.g. me mbership I D or event  ID)
152    * @param  bool $lang uageParse             - indicate s if descr iption sho uld be lan guage-pars ed   150    * @param  bool $lang uageParse             - indicate s if descr iption sho uld be lan guage-pars ed
153    *   151    *
154    * @return  string                          - return U RL   152    * @return  string                          - return U RL
155    *   153    *
156    *   154    *
157    */   155    */
158   function r eturnDescB yAction( $ checkoutAc tion, $dat a, $langua geParse )   156   function r eturnDescB yAction( $ checkoutAc tion, $dat a, $langua geParse )
159   {   157   {
160       switch  ( $checko utAction )   158       switch  ( $checko utAction )
161       {   159       {
162           ca se 'member ship':   160           ca se 'member ship':
163                $members hipArr = g etMembersh ipInfo( $d ata );   161                $members hipArr = g etMembersh ipInfo( $d ata );
164                if ( $la nguagePars e )   162                if ( $la nguagePars e )
165                    retu rn _t('_Me mbership p urchase')  . ' - ' .  $membershi pArr['Name '];   163                    retu rn _t('_Me mbership p urchase')  . ' - ' .  $membershi pArr['Name '];
166                else   164                else
167                    retu rn 'Member ship purch ase - ' .  $membershi pArr['Name '];   165                    retu rn 'Member ship purch ase - ' .  $membershi pArr['Name '];
168           ca se 'speedd ating':   166           ca se 'speedd ating':
169                $eventAr r = db_arr ( 'SELECT  `Title` FR OM `SDatin gEvents` W HERE `ID`  = '. (int) $data );   167                $eventAr r = db_arr ( 'SELECT  `Title` FR OM `SDatin gEvents` W HERE `ID`  = '. (int) $data );
170                if ( $la nguagePars e )   168                if ( $la nguagePars e )
171                    retu rn _t('_Sp eedDating  ticket pur chase') .  ' - ' . $e ventArr['T itle'];   169                    retu rn _t('_Sp eedDating  ticket pur chase') .  ' - ' . $e ventArr['T itle'];
172                else   170                else
173                    retu rn 'SpeedD ating tick et purchas e - ' . $e ventArr['T itle'];   171                    retu rn 'SpeedD ating tick et purchas e - ' . $e ventArr['T itle'];
174           ca se 'credit s':    
175                if ( $la nguagePars e )    
176                    retu rn _t('_Cr edits purc hase') . '  - ' . get CreditsAmo untByIndex ( $data );    
177                else    
178                    retu rn 'Credit s purchase  - ' . get CreditsAmo untByIndex ( $data );    
179           ca se 'profil es':   172           ca se 'profil es':
180                if ( $la nguagePars e )   173                if ( $la nguagePars e )
181                    retu rn _t('_Pr ofiles pur chase') .  ' - ' . $d ata;   174                    retu rn _t('_Pr ofiles pur chase') .  ' - ' . $d ata;
182                else   175                else
183                    retu rn 'Profil es purchas e - ' . $d ata;   176                    retu rn 'Profil es purchas e - ' . $d ata;
184           de fault:   177           de fault:
185                return ' ';   178                return ' ';
186       }   179       }
187   }   180   }
188     181  
189   /**   182   /**
190    * Puts in itial tran saction da ta into th e database   183    * Puts in itial tran saction da ta into th e database
191    *   184    *
192    * @param  array $che ckoutData             - transact ion data a rray   185    * @param  array $che ckoutData             - transact ion data a rray
193    *      (  'checkout_ action',              - action f or which t ransaction  need to b e created   186    *      (  'checkout_ action',              - action f or which t ransaction  need to b e created
194    *         'amount',                        - payment  sum   187    *         'amount',                        - payment  sum
195    *         'data',                          - action s pecific da ta   188    *         'data',                          - action s pecific da ta
196    *         'descripti on'                   - transact ion descri ption   189    *         'descripti on'                   - transact ion descri ption
197    *      )   190    *      )
198    *   191    *
199    * @param  int $membe rID                   - initiati ng member  ID   192    * @param  int $membe rID                   - initiati ng member  ID
200    * @param  int $provi derID                 - payment  provider I D   193    * @param  int $provi derID                 - payment  provider I D
201    *   194    *
202    * @return  int/bool                        - ID of in itiated tr ansaction  on success , false ot herwise   195    * @return  int/bool                        - ID of in itiated tr ansaction  on success , false ot herwise
203    *   196    *
204    *   197    *
205    */   198    */
206   function i nitiateTra nsaction(  $checkoutD ata, $memb erID, $pro viderID )   199   function i nitiateTra nsaction(  $checkoutD ata, $memb erID, $pro viderID )
207   {   200   {
208       global  $MySQL;   201       global  $MySQL;
209       global  $cryptKey ;   202       global  $cryptKey ;
210       global  $currency _code;   203       global  $currency _code;
211     204  
212       // arg uments val idation   205       // arg uments val idation
213       $provi derID = (i nt)$provid erID;   206       $provi derID = (i nt)$provid erID;
214       $membe rID = (int )$memberID ;   207       $membe rID = (int )$memberID ;
215     208  
216       $trans actionData ['memberID '] = $memb erID;   209       $trans actionData ['memberID '] = $memb erID;
217       $trans actionData ['action']  = $checko utData['ch eckout_act ion'];   210       $trans actionData ['action']  = $checko utData['ch eckout_act ion'];
218       $trans actionData ['amount']  = sprintf ( "%.2f",  (float)$ch eckoutData ['amount']  );   211       $trans actionData ['amount']  = sprintf ( "%.2f",  (float)$ch eckoutData ['amount']  );
219       $trans actionData ['cryptedA mount'] =  crypt( $tr ansactionD ata['amoun t'], $cryp tKey );   212       $trans actionData ['cryptedA mount'] =  crypt( $tr ansactionD ata['amoun t'], $cryp tKey );
220       $trans actionData ['currency '] = $curr ency_code;   213       $trans actionData ['currency '] = $curr ency_code;
221       $trans actionData ['data'] =  $checkout Data['data '];   214       $trans actionData ['data'] =  $checkout Data['data '];
222       $trans actionData ['cryptedD ata'] = cr ypt( $tran sactionDat a['data'],  $cryptKey  );   215       $trans actionData ['cryptedD ata'] = cr ypt( $tran sactionDat a['data'],  $cryptKey  );
223       list($ usec, $sec ) = explod e(' ', mic rotime());   216       list($ usec, $sec ) = explod e(' ', mic rotime());
224       srand(  $usec + $ sec );   217       srand(  $usec + $ sec );
225       $trans actionData ['tranID']  = time()  . rand(100 0, 9999);   218       $trans actionData ['tranID']  = time()  . rand(100 0, 9999);
226     219  
227       $trans actionStri ng = trans DataToStri ng( $trans actionData  );   220       $trans actionStri ng = trans DataToStri ng( $trans actionData  );
228       $trans actionDesc  = process _db_input(  $checkout Data['desc ription'],  0, 1 );   221       $trans actionDesc  = process _db_input(  $checkout Data['desc ription'],  0, 1 );
229       $res =  db_res( " INSERT INT O `Transac tions` SET   222       $res =  db_res( " INSERT INT O `Transac tions` SET
230                             `IDMem ber` = {$m emberID},   223                             `IDMem ber` = {$m emberID},
231                             `IDPro vider` = { $providerI D},   224                             `IDPro vider` = { $providerI D},
232                             `gtwTr ansactionI D` = '{$tr ansactionD ata['tranI D']}',   225                             `gtwTr ansactionI D` = '{$tr ansactionD ata['tranI D']}',
233                             `Date`  = NOW(),   226                             `Date`  = NOW(),
234                             `Amoun t` = {$tra nsactionDa ta['amount ']},   227                             `Amoun t` = {$tra nsactionDa ta['amount ']},
235                             `Curre ncy` = '{$ transactio nData['cur rency']}',   228                             `Curre ncy` = '{$ transactio nData['cur rency']}',
236                             `Statu s` = 'pend ing',   229                             `Statu s` = 'pend ing',
237                             `Data`  = '{$tran sactionStr ing}',   230                             `Data`  = '{$tran sactionStr ing}',
238                             `Descr iption` =  '{$transac tionDesc}' " );   231                             `Descr iption` =  '{$transac tionDesc}' " );
239       if ( $ res && mys ql_affecte d_rows( $M ySQL->link  ) > 0 )   232       if ( $ res && mys ql_affecte d_rows( $M ySQL->link  ) > 0 )
240       {   233       {
241           re turn mysql _insert_id ( $MySQL-> link );   234           re turn mysql _insert_id ( $MySQL-> link );
242       }   235       }
243       else   236       else
244           re turn false ;   237           re turn false ;
245   }   238   }
246     239  
247   /**   240   /**
248    * Updates  transacti on state a nd data in  the datab ase   241    * Updates  transacti on state a nd data in  the datab ase
249    *   242    *
250    * @param  int $local TranID                - transact ion ID in  the databa se   243    * @param  int $local TranID                - transact ion ID in  the databa se
251    * @param  string $gt wTranID               - payment  gateway tr ansaction  identifier   244    * @param  string $gt wTranID               - payment  gateway tr ansaction  identifier
252    * @param  bool $appr oved                  - indicate s if trans action was  successfu l   245    * @param  bool $appr oved                  - indicate s if trans action was  successfu l
253    * @param  string $no te                    - customer  note for  the transa ction   246    * @param  string $no te                    - customer  note for  the transa ction
254    *   247    *
255    * @return  bool                            - true on  success, f alse other wise   248    * @return  bool                            - true on  success, f alse other wise
256    *   249    *
257    *   250    *
258    */   251    */
259   function f inishTrans action( $l ocalTranID , $gtwTran ID, $appro ved = true , $note =  '' )   252   function f inishTrans action( $l ocalTranID , $gtwTran ID, $appro ved = true , $note =  '' )
260   {   253   {
261       global  $MySQL;   254       global  $MySQL;
262     255  
263       // arg uments val idation   256       // arg uments val idation
264       $local TranID = ( int)$local TranID;   257       $local TranID = ( int)$local TranID;
265     258  
266       $gtwTr anID = pro cess_db_in put( $gtwT ranID );   259       $gtwTr anID = pro cess_db_in put( $gtwT ranID );
267       $note  = process_ db_input(  $note );   260       $note  = process_ db_input(  $note );
268       $statu s = ($appr oved ? 'ap proved' :  'declined' );   261       $statu s = ($appr oved ? 'ap proved' :  'declined' );
269     262  
270       $res =  db_res( " UPDATE `Tr ansactions ` SET   263       $res =  db_res( " UPDATE `Tr ansactions ` SET
271                             `Statu s` = '{$st atus}',   264                             `Statu s` = '{$st atus}',
272                             `Date`  = NOW(),   265                             `Date`  = NOW(),
273                             `gtwTr ansactionI D` = '{$gt wTranID}',   266                             `gtwTr ansactionI D` = '{$gt wTranID}',
274                             `Note`  = '{$note }'   267                             `Note`  = '{$note }'
275                         WHERE `ID`  = {$local TranID}   268                         WHERE `ID`  = {$local TranID}
276                             AND `S tatus` = ' pending'"  );   269                             AND `S tatus` = ' pending'"  );
277       if ( $ res && mys ql_affecte d_rows( $M ySQL->link  ) > 0 )   270       if ( $ res && mys ql_affecte d_rows( $M ySQL->link  ) > 0 )
278       {   271       {
279           re turn true;   272           re turn true;
280       }   273       }
281       else   274       else
282           re turn false ;   275           re turn false ;
283   }   276   }
284     277  
285   /**   278   /**
286    * Perform s script p urchase ac tions for  specified  transactio n   279    * Perform s script p urchase ac tions for  specified  transactio n
287    *   280    *
288    * @param  int $local TranID                - transact ion ID in  the databa se   281    * @param  int $local TranID                - transact ion ID in  the databa se
289    * @param  int $resul t                     - purchase  result fr om checkou t file   282    * @param  int $resul t                     - purchase  result fr om checkou t file
290    *                                            (it coul d be chang ed inside)   283    *                                            (it coul d be chang ed inside)
291    *   284    *
292    * @return  bool                            - true on  success, f alse other wise   285    * @return  bool                            - true on  success, f alse other wise
293    *   286    *
294    *   287    *
295    */   288    */
296   function p urchaseTra nsaction(  $localTran ID, &$resu lt )   289   function p urchaseTra nsaction(  $localTran ID, &$resu lt )
297   {   290   {
298       // arg uments val idation   291       // arg uments val idation
299       $local TranID = ( int)$local TranID;   292       $local TranID = ( int)$local TranID;
300     293  
301       $tranR es = db_re s( "SELECT  `Data` FR OM `Transa ctions`   294       $tranR es = db_re s( "SELECT  `Data` FR OM `Transa ctions`
302                                 WH ERE `ID` =  {$localTr anID}" );   295                                 WH ERE `ID` =  {$localTr anID}" );
303       if ( ! $tranRes | | mysql_nu m_rows($tr anRes) ==  0 )   296       if ( ! $tranRes | | mysql_nu m_rows($tr anRes) ==  0 )
304           re turn false ;   297           re turn false ;
305     298  
306       $tranA rr = mysql _fetch_ass oc( $tranR es );   299       $tranA rr = mysql _fetch_ass oc( $tranR es );
307       $tranD ata = tran sStringToD ata( $tran Arr['Data' ] );   300       $tranD ata = tran sStringToD ata( $tran Arr['Data' ] );
308     301  
309       return  performPu rchase( $t ranData['m emberID'],  $tranData ['action'] , $tranDat a['data'],   302       return  performPu rchase( $t ranData['m emberID'],  $tranData ['action'] , $tranDat a['data'],
310           $t ranData['a mount'], $ result, $l ocalTranID  );   303           $t ranData['a mount'], $ result, $l ocalTranID  );
311   }   304   }
312     305  
313   /**   306   /**
314    * Puts in itial subs cription d ata into t he databas e   307    * Puts in itial subs cription d ata into t he databas e
315    *   308    *
316    * @param  int $local TranID                - ID of tr ansaction  which was  initiated  on checkou t   309    * @param  int $local TranID                - ID of tr ansaction  which was  initiated  on checkou t
317    *                                            request   310    *                                            request
318    * @param  int $recur ringDays              - subscrip tion perio d days   311    * @param  int $recur ringDays              - subscrip tion perio d days
319    *   312    *
320    * @return  bool                            - true on  success, f alse other wise   313    * @return  bool                            - true on  success, f alse other wise
321    *   314    *
322    *   315    *
323    */   316    */
324   function i nitiateSub scription(  $localTra nID, $recu rringDays  )   317   function i nitiateSub scription(  $localTra nID, $recu rringDays  )
325   {   318   {
326       global  $MySQL;   319       global  $MySQL;
327     320  
328       // arg uments val idation   321       // arg uments val idation
329       $local TranID = ( int)$local TranID;   322       $local TranID = ( int)$local TranID;
330       $recur ringDays =  (int)$rec urringDays ;   323       $recur ringDays =  (int)$rec urringDays ;
331     324  
332       // lin k subscrip tion info  to dummy t ransaction   325       // lin k subscrip tion info  to dummy t ransaction
333       $res =  db_res( " INSERT INT O `Payment Subscripti ons` SET   326       $res =  db_res( " INSERT INT O `Payment Subscripti ons` SET
334                                 `T ransaction ID` = {$lo calTranID} ,   327                                 `T ransaction ID` = {$lo calTranID} ,
335                                 `S tartDate`  = NOW(),   328                                 `S tartDate`  = NOW(),
336                                 `P eriod` = { $recurring Days},   329                                 `P eriod` = { $recurring Days},
337                                 `C hargesNumb er` = 0" ) ;   330                                 `C hargesNumb er` = 0" ) ;
338       if ( $ res && mys ql_affecte d_rows( $M ySQL->link  ) > 0 )   331       if ( $ res && mys ql_affecte d_rows( $M ySQL->link  ) > 0 )
339       {   332       {
340           re turn true;   333           re turn true;
341       }   334       }
342       else   335       else
343           re turn false ;   336           re turn false ;
344   }   337   }
345     338  
346   /**   339   /**
347    * Removes  subscript ion data f rom the da tabase   340    * Removes  subscript ion data f rom the da tabase
348    *   341    *
349    * @param  int $local TranID                - ID of tr ansaction  which was  created on  subscript ion   342    * @param  int $local TranID                - ID of tr ansaction  which was  created on  subscript ion
350    *   343    *
351    * @return  bool                            - true on  success, f alse other wise   344    * @return  bool                            - true on  success, f alse other wise
352    *   345    *
353    *   346    *
354    */   347    */
355   function c ancelSubsc ription( $ localTranI D )   348   function c ancelSubsc ription( $ localTranI D )
356   {   349   {
357       global  $MySQL;   350       global  $MySQL;
358     351  
359       // arg uments val idation   352       // arg uments val idation
360       $local TranID = ( int)$local TranID;   353       $local TranID = ( int)$local TranID;
361     354  
362       // rem ove subscr iption inf o with dum my transac tion   355       // rem ove subscr iption inf o with dum my transac tion
363       $res =  db_res( " DELETE FRO M `Payment Subscripti ons`   356       $res =  db_res( " DELETE FRO M `Payment Subscripti ons`
364                             WHERE  `Transacti onID` = {$ localTranI D}" );   357                             WHERE  `Transacti onID` = {$ localTranI D}" );
365       if ( ! $res || my sql_affect ed_rows( $ MySQL->lin k ) == 0 )   358       if ( ! $res || my sql_affect ed_rows( $ MySQL->lin k ) == 0 )
366       {   359       {
367           re turn false ;   360           re turn false ;
368       }   361       }
369     362  
370       // del ete dummy  transactio n   363       // del ete dummy  transactio n
371       $res =  db_res( " DELETE FRO M `Transac tions`   364       $res =  db_res( " DELETE FRO M `Transac tions`
372                             WHERE  `ID` = {$l ocalTranID }" );   365                             WHERE  `ID` = {$l ocalTranID }" );
373       if ( $ res && mys ql_affecte d_rows( $M ySQL->link  ) > 0 )   366       if ( $ res && mys ql_affecte d_rows( $M ySQL->link  ) > 0 )
374       {   367       {
375           re turn true;   368           re turn true;
376       }   369       }
377       else   370       else
378           re turn false ;   371           re turn false ;
379   }   372   }
380     373  
381   /**   374   /**
382    * Checks  if specifi ed member  was subscr ibed by sp ecified pr ovider and  then   375    * Checks  if specifi ed member  was subscr ibed by sp ecified pr ovider and  then
383    * initiat es new tra nsaction b asing on d ata from t ransaction , which wa s created   376    * initiat es new tra nsaction b asing on d ata from t ransaction , which wa s created
384    * on subs cription   377    * on subs cription
385    *   378    *
386    * @param  int $local TranID                - ID of tr ansaction  which was  created on  subscript ion   379    * @param  int $local TranID                - ID of tr ansaction  which was  created on  subscript ion
387    *                                            Function  initiates  new trans action usi ng data fr om   380    *                                            Function  initiates  new trans action usi ng data fr om
388    *                                            this tra nsaction   381    *                                            this tra nsaction
389    *   382    *
390    * @return  int/bool                        - ID of in itiated tr ansaction  on success , false ot herwise   383    * @return  int/bool                        - ID of in itiated tr ansaction  on success , false ot herwise
391    *   384    *
392    *   385    *
393    */   386    */
394   function i nitiateSub scriptionT ransaction ( $localTr anID )   387   function i nitiateSub scriptionT ransaction ( $localTr anID )
395   {   388   {
396       // arg uments val idation   389       // arg uments val idation
397       $local TranID = ( int)$local TranID;   390       $local TranID = ( int)$local TranID;
398     391  
399       // sel ect dummy  transactio n info   392       // sel ect dummy  transactio n info
400       $tranR es = db_re s( "SELECT  `IDProvid er`, `Data ` FROM `Tr ansactions `   393       $tranR es = db_re s( "SELECT  `IDProvid er`, `Data ` FROM `Tr ansactions `
401                                 WH ERE `ID` =  {$localTr anID}" );   394                                 WH ERE `ID` =  {$localTr anID}" );
402       if ( ! $tranRes | | mysql_nu m_rows($tr anRes) ==  0 )   395       if ( ! $tranRes | | mysql_nu m_rows($tr anRes) ==  0 )
403           re turn false ;   396           re turn false ;
404     397  
405       $tranA rr = mysql _fetch_ass oc( $tranR es );   398       $tranA rr = mysql _fetch_ass oc( $tranR es );
406       $tranD ata = tran sStringToD ata( $tran Arr['Data' ] );   399       $tranD ata = tran sStringToD ata( $tran Arr['Data' ] );
407     400  
408       // che ck if memb er subscri bed   401       // che ck if memb er subscri bed
409       $subsA rr = db_ar r( "SELECT  `Transact ionID`, `C hargesNumb er` FROM ` PaymentSub scriptions `   402       $subsA rr = db_ar r( "SELECT  `Transact ionID`, `C hargesNumb er` FROM ` PaymentSub scriptions `
410                                 WH ERE `Trans actionID`  = {$localT ranID}" );   403                                 WH ERE `Trans actionID`  = {$localT ranID}" );
411       if ( ! $subsArr )   404       if ( ! $subsArr )
412           re turn false ;   405           re turn false ;
413     406  
414       $check outData['c heckout_ac tion'] = $ tranData[' action'];   407       $check outData['c heckout_ac tion'] = $ tranData[' action'];
415       $check outData['a mount'] =  $tranData[ 'amount'];   408       $check outData['a mount'] =  $tranData[ 'amount'];
416       $check outData['d ata'] = $t ranData['d ata'];   409       $check outData['d ata'] = $t ranData['d ata'];
417       $check outData['d escription '] = retur nDescByAct ion( $tran Data['acti on'], $tra nData['dat a'], true  );   410       $check outData['d escription '] = retur nDescByAct ion( $tran Data['acti on'], $tra nData['dat a'], true  );
418     411  
419       $res =  initiateT ransaction ( $checkou tData, $tr anData['me mberID'],  $tranArr[' IDProvider '] );   412       $res =  initiateT ransaction ( $checkou tData, $tr anData['me mberID'],  $tranArr[' IDProvider '] );
420       if ( ! $res )   413       if ( ! $res )
421           re turn false ;   414           re turn false ;
422       else   415       else
423           re turn $res;   416           re turn $res;
424   }   417   }
425     418  
426   /**   419   /**
427    * Checks  if specifi ed member  was subscr ibed by sp ecified pr ovider the n   420    * Checks  if specifi ed member  was subscr ibed by sp ecified pr ovider the n
428    * updates  database  info about  subscript ion and ca lls finish Transactio n function   421    * updates  database  info about  subscript ion and ca lls finish Transactio n function
429    *   422    *
430    * @param  int $local TranID                - transact ion ID in  the databa se   423    * @param  int $local TranID                - transact ion ID in  the databa se
431    * @param  int $subsT ranID                 - ID of tr ansaction  which was  created on  subscript ion   424    * @param  int $subsT ranID                 - ID of tr ansaction  which was  created on  subscript ion
432    * @param  string $gt wTranID               - payment  gateway tr ansaction  identifier   425    * @param  string $gt wTranID               - payment  gateway tr ansaction  identifier
433    * @param  bool $appr oved                  - indicate s if trans action was  successfu l   426    * @param  bool $appr oved                  - indicate s if trans action was  successfu l
434    * @param  string $no te                    - customer  note for  the transa ction   427    * @param  string $no te                    - customer  note for  the transa ction
435    *   428    *
436    * @return  bool                            - true on  success, f alse other wise   429    * @return  bool                            - true on  success, f alse other wise
437    *   430    *
438    *   431    *
439    */   432    */
440   function f inishSubsc riptionTra nsaction(  $localTran ID, $subsT ranID, $gt wTranID, $ approved =  true, $no te = '' )   433   function f inishSubsc riptionTra nsaction(  $localTran ID, $subsT ranID, $gt wTranID, $ approved =  true, $no te = '' )
441   {   434   {
442       global  $MySQL;   435       global  $MySQL;
443     436  
444       // arg uments val idation   437       // arg uments val idation
445       $local TranID = ( int)$local TranID;   438       $local TranID = ( int)$local TranID;
446       $subsT ranID = (i nt)$subsTr anID;   439       $subsT ranID = (i nt)$subsTr anID;
447     440  
448       $res =  true;   441       $res =  true;
449       if ( $ approved )   442       if ( $ approved )
450       {   443       {
451           $r es = db_re s( "UPDATE  `PaymentS ubscriptio ns` SET   444           $r es = db_re s( "UPDATE  `PaymentS ubscriptio ns` SET
452                                      `Charges Number` =  `ChargesNu mber` + 1   445                                      `Charges Number` =  `ChargesNu mber` + 1
453                                 WH ERE `Trans actionID`  = {$subsTr anID}" );   446                                 WH ERE `Trans actionID`  = {$subsTr anID}" );
454           $r es = ( $re s && mysql _affected_ rows( $MyS QL->link )  > 0);   447           $r es = ( $re s && mysql _affected_ rows( $MyS QL->link )  > 0);
455       }   448       }
456     449  
457       if ( $ res )   450       if ( $ res )
458       {   451       {
459           re turn finis hTransacti on( $local TranID, $g twTranID,  $approved,  $note );   452           re turn finis hTransacti on( $local TranID, $g twTranID,  $approved,  $note );
460       }   453       }
461       else   454       else
462           re turn false ;   455           re turn false ;
463   }   456   }
464     457  
465   /**   458   /**
466    * Perform s script p urchase ac tions for  specified  parameters  and makes  fraud che ck also   459    * Perform s script p urchase ac tions for  specified  parameters  and makes  fraud che ck also
467    *   460    *
468    * @param  int $membe rID                   - member I D   461    * @param  int $membe rID                   - member I D
469    * @param  string $ch eckoutActi on         - payment  type actio n (e.g mem ership, cr edits, etc )   462    * @param  string $ch eckoutActi on         - payment  type actio n (e.g mem ership, cr edits, etc )
470    * @param  string $da ta                    - payment  action dat a (e.g. me mbership I D or event  ID)   463    * @param  string $da ta                    - payment  action dat a (e.g. me mbership I D or event  ID)
471    * @param  string $am ount                  - payment  sum   464    * @param  string $am ount                  - payment  sum
472    * @param  int $resul t                     - purchase  result fr om checkou t file   465    * @param  int $resul t                     - purchase  result fr om checkou t file
473    *                                            (it coul d be chang ed inside)   466    *                                            (it coul d be chang ed inside)
474    * @param  int $local TranID                - transact ion ID in  the databa se   467    * @param  int $local TranID                - transact ion ID in  the databa se
475    *   468    *
476    * @return  bool                            - true on  success, f alse other wise   469    * @return  bool                            - true on  success, f alse other wise
477    *   470    *
478    *   471    *
479    */   472    */
480   function p erformPurc hase( $mem berID, $ch eckoutActi on, $data,  $amount,  &$result,  $localTran ID = 0 )   473   function p erformPurc hase( $mem berID, $ch eckoutActi on, $data,  $amount,  &$result,  $localTran ID = 0 )
481   {   474   {
482       global  $site;   475       global  $site;
483     476  
484       // arg uments val idation   477       // arg uments val idation
485       $amoun t = sprint f( '%.2f',  (float)$a mount );   478       $amoun t = sprint f( '%.2f',  (float)$a mount );
486     479  
487       switch  ( $checko utAction )   480       switch  ( $checko utAction )
488       {   481       {
489           ca se 'member ship':   482           ca se 'member ship':
490                $members hipID = (i nt)$data;   483                $members hipID = (i nt)$data;
491                $res = b uyMembersh ip( $membe rID, $memb ershipID,  $amount, $ localTranI D );   484                $res = b uyMembersh ip( $membe rID, $memb ershipID,  $amount, $ localTranI D );
492                return $ res;   485                return $ res;
493     486  
494           ca se 'speedd ating':   487           ca se 'speedd ating':
495                $eventID  = (int)$d ata;   488                $eventID  = (int)$d ata;
496                $res = i sTicketAva ilable( $m emberID, $ eventID );   489                $res = i sTicketAva ilable( $m emberID, $ eventID );
497                // fraud  check   490                // fraud  check
498                if ( $re s === fals e )   491                if ( $re s === fals e )
499                    retu rn false;   492                    retu rn false;
500                if ( $re s != $amou nt )   493                if ( $re s != $amou nt )
501                    retu rn false;   494                    retu rn false;
502     495  
503                $res = p urchaseTic ket( $memb erID, $eve ntID, $loc alTranID ) ;   496                $res = p urchaseTic ket( $memb erID, $eve ntID, $loc alTranID ) ;
504                // if ti cket purch ased, but  email wasn 't sent th en change  result val ue   497                // if ti cket purch ased, but  email wasn 't sent th en change  result val ue
505                if ( $re s === 3 )   498                if ( $re s === 3 )
506                {   499                {
507                    $res ult = 3;   500                    $res ult = 3;
508                    retu rn true;   501                    retu rn true;
509                }   502                }
510                else   503                else
511                {   504                {
512                    retu rn $res;   505                    retu rn $res;
513                }   506                }
514     507  
515           de fault:   508           de fault:
516                return f alse;   509                return f alse;
517       }   510       }
518   }   511   }
519     512  
520   /**   513   /**
521    * Perform s appropri ate action  for payme nt result   514    * Perform s appropri ate action  for payme nt result
522    *   515    *
523    * If data base trans action ID  specified  and it is  possible t o determin e return U RL   516    * If data base trans action ID  specified  and it is  possible t o determin e return U RL
524    * then it  posts res ult to ret urn page.  Otherwise  it just sh ows error  message.   517    * then it  posts res ult to ret urn page.  Otherwise  it just sh ows error  message.
525    *   518    *
526    * @param  int $resul t                     - payment  result   519    * @param  int $resul t                     - payment  result
527    *      -1  - fraud a ttempt   520    *      -1  - fraud a ttempt
528    *       0  - transac tion decli ned or not  completed   521    *       0  - transac tion decli ned or not  completed
529    *       1  - transac tion succe ssful   522    *       1  - transac tion succe ssful
530    *       2  - interna l error   523    *       2  - interna l error
531    * @param  string $er rorMessage            - error me ssage whic h was   524    * @param  string $er rorMessage            - error me ssage whic h was
532    * @param  int $local TranID                - transact ion ID   525    * @param  int $local TranID                - transact ion ID
533    *   526    *
534    *   527    *
535    */   528    */
536   function p rocessVali dationResu lt( $resul t, $errorM essage, $l ocalTranID  = 0, $ret urnURL = ' ' )   529   function p rocessVali dationResu lt( $resul t, $errorM essage, $l ocalTranID  = 0, $ret urnURL = ' ' )
537   {   530   {
538       global  $site;   531       global  $site;
539     532  
540       // arg uments val idation   533       // arg uments val idation
541       $resul t = (int)$ result;   534       $resul t = (int)$ result;
542       $local TranID = ( int)$local TranID;   535       $local TranID = ( int)$local TranID;
543     536  
544       $formD ata = arra y( 'result ' => $resu lt );   537       $formD ata = arra y( 'result ' => $resu lt );
545     538  
546       if ( $ localTranI D )   539       if ( $ localTranI D )
547       {   540       {
548           $t ranRes = d b_res( "SE LECT `Data ` FROM `Tr ansactions `   541           $t ranRes = d b_res( "SE LECT `Data ` FROM `Tr ansactions `
549                                      WHERE `I D` = {$loc alTranID}"  );   542                                      WHERE `I D` = {$loc alTranID}"  );
550           if  ( $tranRe s && mysql _num_rows( $tranRes)  > 0 )   543           if  ( $tranRe s && mysql _num_rows( $tranRes)  > 0 )
551           {   544           {
552                $tranArr  = mysql_f etch_assoc ($tranRes) ;   545                $tranArr  = mysql_f etch_assoc ($tranRes) ;
553                $tranDat a = transS tringToDat a( $tranAr r['Data']  );   546                $tranDat a = transS tringToDat a( $tranAr r['Data']  );
554                $returnU RL = retur nURLByActi on( $tranD ata['actio n'], $tran Data['data '] );   547                $returnU RL = retur nURLByActi on( $tranD ata['actio n'], $tran Data['data '] );
555           }   548           }
556       }   549       }
557     550  
558       switch  ( $result  )   551       switch  ( $result  )
559       {   552       {
560           ca se -1:   553           ca se -1:
561                reportFr audAttempt ( $errorMe ssage );   554                reportFr audAttempt ( $errorMe ssage );
562                if ( str len($retur nURL) )   555                if ( str len($retur nURL) )
563                    Redi rect( $ret urnURL, $f ormData, ' post' );   556                    Redi rect( $ret urnURL, $f ormData, ' post' );
564                else   557                else
565                    Prin tErrorPage ( _t('_RES ULT-1') );   558                    Prin tErrorPage ( _t('_RES ULT-1') );
566                break;   559                break;
567     560  
568           ca se 0:   561           ca se 0:
569                if ( str len($retur nURL) )   562                if ( str len($retur nURL) )
570                    Redi rect( $ret urnURL, $f ormData, ' post' );   563                    Redi rect( $ret urnURL, $f ormData, ' post' );
571                else   564                else
572                    Prin tErrorPage ( _t('_RES ULT0') );   565                    Prin tErrorPage ( _t('_RES ULT0') );
573                break;   566                break;
574     567  
575           ca se 1:   568           ca se 1:
576                if ( str len($retur nURL) )   569                if ( str len($retur nURL) )
577                    Redi rect( $ret urnURL, $f ormData, ' post' );   570                    Redi rect( $ret urnURL, $f ormData, ' post' );
578                else   571                else
579                    Redi rect( $sit e['url'] .  'member.p hp', $form Data, 'pos t' );   572                    Redi rect( $sit e['url'] .  'member.p hp', $form Data, 'pos t' );
580                break;   573                break;
581     574  
582           ca se 2:   575           ca se 2:
583                PrintErr orPage( 'I nternal er ror occure d: ' . $er rorMessage  );   576                PrintErr orPage( 'I nternal er ror occure d: ' . $er rorMessage  );
584                break;   577                break;
585     578  
586           ca se 1000:   579           ca se 1000:
587                if ( str len($retur nURL) )   580                if ( str len($retur nURL) )
588                    Redi rect( $ret urnURL, $f ormData, ' post' );   581                    Redi rect( $ret urnURL, $f ormData, ' post' );
589                else   582                else
590                    Prin tErrorPage ( _t('_RES ULT1000')  );   583                    Prin tErrorPage ( _t('_RES ULT1000')  );
591                break;   584                break;
592       }   585       }
593   }   586   }
594     587  
595   /**   588   /**
596    * Sends e mail to si te admin w ith paymen t and user  informati on   589    * Sends e mail to si te admin w ith paymen t and user  informati on
597    *   590    *
598    * @return  bool                            - true if  sending su cceed, fal se otherwi se   591    * @return  bool                            - true if  sending su cceed, fal se otherwi se
599    *   592    *
600    *   593    *
601    */   594    */
602   function r eportFraud Attempt( $ message )   595   function r eportFraud Attempt( $ message )
603   {   596   {
604       global  $site;   597       global  $site;
605     598  
606       $payme ntModuleNa me = PAYME NT_MODULE_ NAME;   599       $payme ntModuleNa me = PAYME NT_MODULE_ NAME;
607       $userI P = getenv ('HTTP_CLI ENT_IP') ?  getenv('H TTP_CLIENT _IP') : ge tenv('REMO TE_ADDR');   600       $userI P = getenv ('HTTP_CLI ENT_IP') ?  getenv('H TTP_CLIENT _IP') : ge tenv('REMO TE_ADDR');
608       $curre ntDatetime  = date("l  dS of F Y  h:i:s A") ;   601       $curre ntDatetime  = date("l  dS of F Y  h:i:s A") ;
609     602  
610     603  
611       $subje ct = 'Frau d attempt  report';   604       $subje ct = 'Frau d attempt  report';
612     605  
613       $messa ge = <<<EO M   606       $messa ge = <<<EO M
614   Fraud atte mpt was de tected in  {$site['ti tle']} che ckout syst em.   607   Fraud atte mpt was de tected in  {$site['ti tle']} che ckout syst em.
615   Here is de tails:   608   Here is de tails:
616       Date/t ime: {$cur rentDateti me}   609       Date/t ime: {$cur rentDateti me}
617       IP: {$ userIP}   610       IP: {$ userIP}
618       Paymen t module n ame: {$pay mentModule Name}   611       Paymen t module n ame: {$pay mentModule Name}
619       Messag e: {$messa ge}   612       Messag e: {$messa ge}
620   EOM;   613   EOM;
621     614  
622       $ret =  sendMail(  $site['em ail'], $su bject, $me ssage );   615       $ret =  sendMail(  $site['em ail'], $su bject, $me ssage );
623     616  
624     617  
625       return  $ret;   618       return  $ret;
626   }   619   }
627     620  
628   /**   621   /**
629    * Selects  all or on ly active  payment pr oviders an d returns  array with  their   622    * Selects  all or on ly active  payment pr oviders an d returns  array with  their
630    * names a nd caption s   623    * names a nd caption s
631    *   624    *
632    * @param  bool $acti veOnly                - indicate s if only  active pay ment provi ders shoul d be   625    * @param  bool $acti veOnly                - indicate s if only  active pay ment provi ders shoul d be
633    *                                            selected   626    *                                            selected
634    *   627    *
635    * @return  array                           - array of  providers   628    * @return  array                           - array of  providers
636    *               ( pr oviderID = > Array('N ame' => pr oviderName , 'Caption ' => provi derCaption ),   629    *               ( pr oviderID = > Array('N ame' => pr oviderName , 'Caption ' => provi derCaption ),
637    *                 .. . )   630    *                 .. . )
638    *   631    *
639    *   632    *
640    */   633    */
641   function g etPaymentP roviders(  $activeOnl y = false  )   634   function g etPaymentP roviders(  $activeOnl y = false  )
642   {   635   {
643       $resul t = array( );   636       $resul t = array( );
644       if ( $ activeOnly  )   637       if ( $ activeOnly  )
645           $q ueryFilter  = 'WHERE  `Active`';   638           $q ueryFilter  = 'WHERE  `Active`';
646     639  
647       $provi derRes = d b_res( "SE LECT `ID`,  `Name`, ` Caption` F ROM `Payme ntProvider s` {$query Filter}" ) ;   640       $provi derRes = d b_res( "SE LECT `ID`,  `Name`, ` Caption` F ROM `Payme ntProvider s` {$query Filter}" ) ;
648       while  ( $provide rArr = mys ql_fetch_a ssoc($prov iderRes) )   641       while  ( $provide rArr = mys ql_fetch_a ssoc($prov iderRes) )
649       {   642       {
650           $r esult[$pro viderArr[' ID']]['Nam e'] = $pro viderArr[' Name'];   643           $r esult[$pro viderArr[' ID']]['Nam e'] = $pro viderArr[' Name'];
651           $r esult[$pro viderArr[' ID']]['Cap tion'] = $ providerAr r['Caption '];   644           $r esult[$pro viderArr[' ID']]['Cap tion'] = $ providerAr r['Caption '];
652       }   645       }
653     646  
654       return  $result;   647       return  $result;
655   }   648   }
656     649  
657   /**   650   /**
658    * Reads c urrent mod ule config uration fr om the dat abase   651    * Reads c urrent mod ule config uration fr om the dat abase
659    *   (acco rding to t he 'PAYMEN T_MODULE_N AME' const ant)   652    *   (acco rding to t he 'PAYMEN T_MODULE_N AME' const ant)
660    *   653    *
661    *   654    *
662    */   655    */
663   function i nitProvide rConfigura tion()   656   function i nitProvide rConfigura tion()
664   {   657   {
665       global  $provider Conf;   658       global  $provider Conf;
666     659  
667       $provi derConf =  array();   660       $provi derConf =  array();
668     661  
669       if ( ! defined( ' PAYMENT_MO DULE_NAME'  ) )   662       if ( ! defined( ' PAYMENT_MO DULE_NAME'  ) )
670           re turn;   663           re turn;
671       $provi derRes = d b_res( "SE LECT `ID`,  `Name`, ` Caption`,  `Active`,  `Mode`, `D ebug`, `Ch eckoutFile name`, `Ch eckoutURL` , `Support sRecurring ` FROM `Pa ymentProvi ders` WHER E `Name` =  '". PAYME NT_MODULE_ NAME ."'"  );   664       $provi derRes = d b_res( "SE LECT `ID`,  `Name`, ` Caption`,  `Active`,  `Mode`, `D ebug`, `Ch eckoutFile name`, `Ch eckoutURL` , `Support sRecurring ` FROM `Pa ymentProvi ders` WHER E `Name` =  '". PAYME NT_MODULE_ NAME ."'"  );
672       $provi derArr = m ysql_fetch _assoc($pr oviderRes) ;   665       $provi derArr = m ysql_fetch _assoc($pr oviderRes) ;
673       foreac h ( $provi derArr as  $key => $v alue )   666       foreac h ( $provi derArr as  $key => $v alue )
674           $p roviderCon f[$key] =  $value;   667           $p roviderCon f[$key] =  $value;
675     668  
676       $param Res = db_r es( "SELEC T `Name`,  `Type`, `V alue` FROM  `PaymentP arameters`  WHERE `ID Provider`  = {$provid erConf['ID ']}" );   669       $param Res = db_r es( "SELEC T `Name`,  `Type`, `V alue` FROM  `PaymentP arameters`  WHERE `ID Provider`  = {$provid erConf['ID ']}" );
677       while  ( $paramAr r = mysql_ fetch_asso c($paramRe s) )   670       while  ( $paramAr r = mysql_ fetch_asso c($paramRe s) )
678       {   671       {
679           if  ( $paramA rr['Type']  == 'check ' )   672           if  ( $paramA rr['Type']  == 'check ' )
680                $provide rConf['Par am_' . $pa ramArr['Na me']] = ($ paramArr[' Value'] ==  'on' ? tr ue : false );   673                $provide rConf['Par am_' . $pa ramArr['Na me']] = ($ paramArr[' Value'] ==  'on' ? tr ue : false );
681           el se   674           el se
682                $provide rConf['Par am_' . $pa ramArr['Na me']] = $p aramArr['V alue'];   675                $provide rConf['Par am_' . $pa ramArr['Na me']] = $p aramArr['V alue'];
683       }   676       }
684   }   677   }
685     678  
686   /**   679   /**
687    * Perform s common p ayment mod ule config uration va lidation   680    * Perform s common p ayment mod ule config uration va lidation
688    *   681    *
689    * @param  string &$e rrorMessag e          - error me ssage when  return re sult is no t true   682    * @param  string &$e rrorMessag e          - error me ssage when  return re sult is no t true
690    *   683    *
691    * @return  bool                            - true if  configurat ion is val id, false  otherwise   684    * @return  bool                            - true if  configurat ion is val id, false  otherwise
692    *   685    *
693    *   686    *
694    */   687    */
695   function c ommonValid ateConfigu ration( &$ errorMessa ge )   688   function c ommonValid ateConfigu ration( &$ errorMessa ge )
696   {   689   {
697       global  $provider Conf;   690       global  $provider Conf;
698       global  $debugFil ename;   691       global  $debugFil ename;
699     692  
700       if ( ! defined( ' PAYMENT_MO DULE_NAME'  ) )   693       if ( ! defined( ' PAYMENT_MO DULE_NAME'  ) )
701           re turn false ;   694           re turn false ;
702     695  
703       if ( $ providerCo nf['Debug' ] )   696       if ( $ providerCo nf['Debug' ] )
704       {   697       {
705           $f ileExists  = file_exi sts( $debu gFilename  );   698           $f ileExists  = file_exi sts( $debu gFilename  );
706           if  ( $fileEx ists )   699           if  ( $fileEx ists )
707           {   700           {
708                    clea rstatcache ();   701                    clea rstatcache ();
709                    $per ms = filep erms( $deb ugFilename  );   702                    $per ms = filep erms( $deb ugFilename  );
710                    $fil eRWAccessi ble = ($pe rms & 0x00 04 && $per ms & 0x000 2) ? true  : false;   703                    $fil eRWAccessi ble = ($pe rms & 0x00 04 && $per ms & 0x000 2) ? true  : false;
711           }   704           }
712           if  ( !$fileE xists || ! $fileRWAcc essible )   705           if  ( !$fileE xists || ! $fileRWAcc essible )
713           {   706           {
714                $errorMe ssage = 'D ebug mode  enabled, b ut debug f ile is not  writable' ;   707                $errorMe ssage = 'D ebug mode  enabled, b ut debug f ile is not  writable' ;
715                return f alse;   708                return f alse;
716           }   709           }
717       }   710       }
718     711  
719       return  true;   712       return  true;
720   }   713   }
721     714  
722   /**   715   /**
723    * Perform s common p ayment tra nsaction v alidation   716    * Perform s common p ayment tra nsaction v alidation
724    *   717    *
725    * @param  int $local TranID                - transact ion ID   718    * @param  int $local TranID                - transact ion ID
726    * @param  string $am ount                  - payment  sum, recei ved from t he gateway   719    * @param  string $am ount                  - payment  sum, recei ved from t he gateway
727    * @param  string &$e rrorMessag e          - error me ssage when  return re sult is no t true   720    * @param  string &$e rrorMessag e          - error me ssage when  return re sult is no t true
728    *   721    *
729    * @return  bool                            - true if  configurat ion is val id, false  otherwise   722    * @return  bool                            - true if  configurat ion is val id, false  otherwise
730    *   723    *
731    *   724    *
732    */   725    */
733   function c ommonValid ateTransac tion( $loc alTranID,  $amount, & $errorMess age )   726   function c ommonValid ateTransac tion( $loc alTranID,  $amount, & $errorMess age )
734   {   727   {
735       global  $cryptKey ;   728       global  $cryptKey ;
736     729  
737       // arg uments val idation   730       // arg uments val idation
738       $local TranID = ( int)$local TranID;   731       $local TranID = ( int)$local TranID;
739     732  
740       $tranR es = db_re s( "SELECT  `Data` FR OM `Transa ctions`   733       $tranR es = db_re s( "SELECT  `Data` FR OM `Transa ctions`
741                                 WH ERE `ID` =  {$localTr anID}" );   734                                 WH ERE `ID` =  {$localTr anID}" );
742       if ( ! $tranRes | | mysql_nu m_rows($tr anRes) ==  0 )   735       if ( ! $tranRes | | mysql_nu m_rows($tr anRes) ==  0 )
743       {   736       {
744           $e rrorMessag e = 'Inval id transac tion ID';   737           $e rrorMessag e = 'Inval id transac tion ID';
745           re turn false ;   738           re turn false ;
746       }   739       }
747     740  
748       $tranA rr = mysql _fetch_ass oc( $tranR es );   741       $tranA rr = mysql _fetch_ass oc( $tranR es );
749       $tranD ata = tran sStringToD ata( $tran Arr['Data' ] );   742       $tranD ata = tran sStringToD ata( $tran Arr['Data' ] );
750     743  
751       if ( $ tranData[' amount'] ! = sprintf(  "%.2f", ( float)$amo unt ) )   744       if ( $ tranData[' amount'] ! = sprintf(  "%.2f", ( float)$amo unt ) )
752       {   745       {
753           $e rrorMessag e = 'Inval id payment  sum';   746           $e rrorMessag e = 'Inval id payment  sum';
754           re turn false ;   747           re turn false ;
755       }   748       }
756     749  
757       $res =  db_res( " SELECT `ID ` FROM `Pr ofiles` WH ERE `ID` =  {$tranDat a['memberI D']}" );   750       $res =  db_res( " SELECT `ID ` FROM `Pr ofiles` WH ERE `ID` =  {$tranDat a['memberI D']}" );
758       if ( ! $res )   751       if ( ! $res )
759       {   752       {
760           $e rrorMessag e = 'Inval id member  ID';   753           $e rrorMessag e = 'Inval id member  ID';
761           re turn false ;   754           re turn false ;
762       }   755       }
763     756  
764       if ( c rypt($tran Data['amou nt'], $cry ptKey) !=  $tranData[ 'cryptedAm ount'] ||   757       if ( c rypt($tran Data['amou nt'], $cry ptKey) !=  $tranData[ 'cryptedAm ount'] ||
765            c rypt($tran Data['data '], $crypt Key) != $t ranData['c ryptedData '] )   758            c rypt($tran Data['data '], $crypt Key) != $t ranData['c ryptedData '] )
766        {   759        {
767           $e rrorMessag e = 'Inval id verific ation data ';   760           $e rrorMessag e = 'Inval id verific ation data ';
768           re turn false ;   761           re turn false ;
769        }   762        }
770     763  
771       return  true;   764       return  true;
772   }   765   }
773     766  
774   /**   767   /**
775    * Writes  debug outp ut to the  appropriat e text fil e   768    * Writes  debug outp ut to the  appropriat e text fil e
776    *   769    *
777    * @param  string $da taName                - name of  data to be  written   770    * @param  string $da taName                - name of  data to be  written
778    * @param  undef $dat a                     - data to  be written   771    * @param  undef $dat a                     - data to  be written
779    * @param  bool $incl udeDateTim e          - indicate s if date  and time s hould be i ncluded in to the out put   772    * @param  bool $incl udeDateTim e          - indicate s if date  and time s hould be i ncluded in to the out put
780    *   773    *
781    * @return  bool                            - true if  write succ ess, false  otherwise   774    * @return  bool                            - true if  write succ ess, false  otherwise
782    *   775    *
783    *   776    *
784    */   777    */
785   function w riteDebugL og( $dataN ame, $data , $include DateTime =  true )   778   function w riteDebugL og( $dataN ame, $data , $include DateTime =  true )
786   {   779   {
787       global  $provider Conf;   780       global  $provider Conf;
788       global  $debugFil ename;   781       global  $debugFil ename;
789     782  
790       if ( ! defined( ' PAYMENT_MO DULE_NAME'  ) )   783       if ( ! defined( ' PAYMENT_MO DULE_NAME'  ) )
791           re turn false ;   784           re turn false ;
792     785  
793       $fileE xists = fi le_exists(  $debugFil ename );   786       $fileE xists = fi le_exists(  $debugFil ename );
794       if ( $ fileExists  )   787       if ( $ fileExists  )
795       {   788       {
796           cl earstatcac he();   789           cl earstatcac he();
797           $p erms = fil eperms( $d ebugFilena me );   790           $p erms = fil eperms( $d ebugFilena me );
798           $f ileRWAcces sible = ($ perms & 0x 0004 && $p erms & 0x0 002) ? tru e : false;   791           $f ileRWAcces sible = ($ perms & 0x 0004 && $p erms & 0x0 002) ? tru e : false;
799       }   792       }
800     793  
801       if ( ! $fileExist s || !$fil eRWAccessi ble )   794       if ( ! $fileExist s || !$fil eRWAccessi ble )
802           re turn false ;   795           re turn false ;
803     796  
804       $fp =  fopen( $de bugFilenam e, 'a' );   797       $fp =  fopen( $de bugFilenam e, 'a' );
805     798  
806       if ( $ includeDat eTime )   799       if ( $ includeDat eTime )
807           fw rite( $fp,  'Debug st arted at '  . date (" l dS of F  Y h:i:s A" ) . "\n" ) ;   800           fw rite( $fp,  'Debug st arted at '  . date (" l dS of F  Y h:i:s A" ) . "\n" ) ;
808     801  
809       if ( i s_array($d ata) )   802       if ( i s_array($d ata) )
810       {   803       {
811           fw rite( $fp,  "\t{$data Name}: Arr ay\n" );   804           fw rite( $fp,  "\t{$data Name}: Arr ay\n" );
812           fo reach ( $d ata as $ke y => $valu e )   805           fo reach ( $d ata as $ke y => $valu e )
813                fwrite(  $fp, "\t\t {$key}: {$ value}\n"  );   806                fwrite(  $fp, "\t\t {$key}: {$ value}\n"  );
814       }   807       }
815       else   808       else
816       {   809       {
817           fw rite( $fp,  "\t{$data Name}: {$d ata}\n" );   810           fw rite( $fp,  "\t{$data Name}: {$d ata}\n" );
818       }   811       }
819     812  
820       fclose ( $fp );   813       fclose ( $fp );
821     814  
822       return  true;   815       return  true;
823   }   816   }
824     817  
825   /**   818   /**
826    * Calcula tes financ ial statis tic for sp ecified qu ery parame ters group ed by   819    * Calcula tes financ ial statis tic for sp ecified qu ery parame ters group ed by
827    * transac tion type  for specif ied affili ate   820    * transac tion type  for specif ied affili ate
828    *   821    *
829    * @param  int $affID                       - affiliat e ID   822    * @param  int $affID                       - affiliat e ID
830    * @param  array $tra nArray                - array wi th data fo r transact ion query   823    * @param  array $tra nArray                - array wi th data fo r transact ion query
831    *           ( 'order _num',                - select t ransaction  with spec ified orde r number   824    *           ( 'order _num',                - select t ransaction  with spec ified orde r number
832    *             'last_ days',                - select t ransaction s for spec ified last  days   825    *             'last_ days',                - select t ransaction s for spec ified last  days
833    *             'exact _date',               - select t ransaction s for spec ified date   826    *             'exact _date',               - select t ransaction s for spec ified date
834    *             'betwe en_date1',            - select t ransaction s between  date1 and  date2   827    *             'betwe en_date1',            - select t ransaction s between  date1 and  date2
835    *             'betwe en_date2'  )   828    *             'betwe en_date2'  )
836    *   829    *
837    * @return  array                           - array wi th financi al statist ic   830    * @return  array                           - array wi th financi al statist ic
838    *           ( 'membe rship_amou nt',       - sum of m embership  transactio ns   831    *           ( 'membe rship_amou nt',       - sum of m embership  transactio ns
839    *             'credi ts_amount' ,          - sum of c redit purc hase trans actions    
840    *             'sales _amount',             - sum of p rofile pur chase tran sactions   832    *             'sales _amount',             - sum of p rofile pur chase tran sactions
841    *             'sdati ng_amount' ,          - sum of S peedDating  ticket pu rchase tra nsactions   833    *             'sdati ng_amount' ,          - sum of S peedDating  ticket pu rchase tra nsactions
842    *             'total ' )                   - total su m   834    *             'total ' )                   - total su m
843    *   835    *
844    *   836    *
845    */   837    */
846   function g etFinanceA ffStat( $a ffID, $tra nArray )   838   function g etFinanceA ffStat( $a ffID, $tra nArray )
847   {   839   {
848       global  $currency _code;   840       global  $currency _code;
849       global  $separato r;   841       global  $separato r;
850     842  
851       $affID  = (int)$a ffID;   843       $affID  = (int)$a ffID;
852     844  
853       if ( i sset($tran Array['ord er_num'])  )   845       if ( i sset($tran Array['ord er_num'])  )
854       {   846       {
855           $t ranFilter  = "`gtwTra nsactionID ` = '". pr ocess_db_i nput( $tra nArray['or der_num'],  0, 1 ) ." '";   847           $t ranFilter  = "`gtwTra nsactionID ` = '". pr ocess_db_i nput( $tra nArray['or der_num'],  0, 1 ) ." '";
856       }   848       }
857       elseif  ( isset($ tranArray[ 'last_days ']) )   849       elseif  ( isset($ tranArray[ 'last_days ']) )
858       {   850       {
859           $t ranFilter  = "( TO_DA YS( NOW()  ) - TO_DAY S( `Date`  ) <= ". (( int)$tranA rray['last _days']) . " )";   851           $t ranFilter  = "( TO_DA YS( NOW()  ) - TO_DAY S( `Date`  ) <= ". (( int)$tranA rray['last _days']) . " )";
860       }   852       }
861       elseif  ( isset($ tranArray[ 'exact_dat e']) )   853       elseif  ( isset($ tranArray[ 'exact_dat e']) )
862       {   854       {
863           $e xactDate =  strtotime ( $tranArr ay['exact_ date'] );   855           $e xactDate =  strtotime ( $tranArr ay['exact_ date'] );
864           if  ( $exactD ate != -1  )   856           if  ( $exactD ate != -1  )
865                $tranFil ter = "TO_ DAYS( FROM _UNIXTIME( $exactDate ) ) = TO_D AYS( `Date ` )";   857                $tranFil ter = "TO_ DAYS( FROM _UNIXTIME( $exactDate ) ) = TO_D AYS( `Date ` )";
866           el se   858           el se
867                $tranFil ter = "1";   859                $tranFil ter = "1";
868       }   860       }
869       elseif  ( isset($ tranArray[ 'between_d ate1']) &&  isset($tr anArray['b etween_dat e2']) )   861       elseif  ( isset($ tranArray[ 'between_d ate1']) &&  isset($tr anArray['b etween_dat e2']) )
870       {   862       {
871           if  ( $tranAr ray['betwe en_date1']  == 'start ' )   863           if  ( $tranAr ray['betwe en_date1']  == 'start ' )
872                $between Date1 = 0;   864                $between Date1 = 0;
873           el seif ( $tr anArray['b etween_dat e1'] == 'n ow' )   865           el seif ( $tr anArray['b etween_dat e1'] == 'n ow' )
874                $between Date1 = ti me();   866                $between Date1 = ti me();
875           el se   867           el se
876                $between Date1 = st rtotime( $ tranArray[ 'between_d ate1'] );   868                $between Date1 = st rtotime( $ tranArray[ 'between_d ate1'] );
877           if  ( $tranAr ray['betwe en_date2']  == 'start ' )   869           if  ( $tranAr ray['betwe en_date2']  == 'start ' )
878                $between Date2 = 0;   870                $between Date2 = 0;
879           el seif ( $tr anArray['b etween_dat e2'] == 'n ow' )   871           el seif ( $tr anArray['b etween_dat e2'] == 'n ow' )
880                $between Date2 = ti me();   872                $between Date2 = ti me();
881           el se   873           el se
882                $between Date2 = st rtotime( $ tranArray[ 'between_d ate2'] );   874                $between Date2 = st rtotime( $ tranArray[ 'between_d ate2'] );
883     875  
884           if  ( $betwee nDate1 !=  -1 && $bet weenDate2  != -1 )   876           if  ( $betwee nDate1 !=  -1 && $bet weenDate2  != -1 )
885                $tranFil ter = "( T O_DAYS( FR OM_UNIXTIM E($between Date1) ) < = TO_DAYS(  `Date` )  AND TO_DAY S( FROM_UN IXTIME($be tweenDate2 ) ) >= TO_ DAYS( `Dat e` ) )";   877                $tranFil ter = "( T O_DAYS( FR OM_UNIXTIM E($between Date1) ) < = TO_DAYS(  `Date` )  AND TO_DAY S( FROM_UN IXTIME($be tweenDate2 ) ) >= TO_ DAYS( `Dat e` ) )";
886           el se   878           el se
887                $tranFil ter = "1";   879                $tranFil ter = "1";
888       }   880       }
889       else   881       else
890       {   882       {
891           $t ranFilter  = "1";   883           $t ranFilter  = "1";
892       }   884       }
893     885  
894       // Fil l the arra y   886       // Fil l the arra y
895       $fin =  array();   887       $fin =  array();
896       $arr =  db_arr( " SELECT `Pe rcent` FRO M `aff` WH ERE `ID` =  $affID");   888       $arr =  db_arr( " SELECT `Pe rcent` FRO M `aff` WH ERE `ID` =  $affID");
897       $perce nt = (floa t)$arr['Pe rcent'] /  100.0;   889       $perce nt = (floa t)$arr['Pe rcent'] /  100.0;
898       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Data` LI KE '%{$sep arator}mem bership{$s eparator}% ' AND `Cur rency` = ' {$currency _code}'" ) ;   890       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Data` LI KE '%{$sep arator}mem bership{$s eparator}% ' AND `Cur rency` = ' {$currency _code}'" ) ;
899       $fin[' membership _amount']  = sprintf(  "%.2f", $ percent *  (float)$ar r[0] );   891       $fin[' membership _amount']  = sprintf(  "%.2f", $ percent *  (float)$ar r[0] );
900       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Data` LI KE '%{$sep arator}cre dits{$sepa rator}%' A ND `Curren cy` = '{$c urrency_co de}'" );    
901       $fin[' credits_am ount'] = s printf( "% .2f", $per cent * (fl oat)$arr[0 ] );    
902       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Data` LI KE '%{$sep arator}pro files{$sep arator}%'  AND `Curre ncy` = '{$ currency_c ode}'" );   892       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Data` LI KE '%{$sep arator}pro files{$sep arator}%'  AND `Curre ncy` = '{$ currency_c ode}'" );
903       $fin[' sales_amou nt'] = spr intf( "%.2 f", $perce nt * (floa t)$arr[0]  );   893       $fin[' sales_amou nt'] = spr intf( "%.2 f", $perce nt * (floa t)$arr[0]  );
904       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Data` LI KE '%{$sep arator}spe eddating{$ separator} %' AND `Cu rrency` =  '{$currenc y_code}'"  );   894       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Data` LI KE '%{$sep arator}spe eddating{$ separator} %' AND `Cu rrency` =  '{$currenc y_code}'"  );
905       $fin[' sdating_am ount'] = s printf( "% .2f", $per cent * (fl oat)$arr[0 ] );   895       $fin[' sdating_am ount'] = s printf( "% .2f", $per cent * (fl oat)$arr[0 ] );
906       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Currency ` = '{$cur rency_code }'" );   896       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` INNER J OIN `aff_m embers` ON  (`idProfi le` = `IDM ember`) WH ERE {$tran Filter} AN D `idAff`  = {$affID}  AND `Stat us` = 'app roved' AND  `Currency ` = '{$cur rency_code }'" );
907       $fin[' total'] =  sprintf( " %.2f", $pe rcent * (f loat)$arr[ 0] );   897       $fin[' total'] =  sprintf( " %.2f", $pe rcent * (f loat)$arr[ 0] );
908     898  
909       return  $fin;   899       return  $fin;
910   }   900   }
911     901  
912   /**   902   /**
913    * Calcula tes financ ial statis tic for sp ecified qu ery parame ters group ed by   903    * Calcula tes financ ial statis tic for sp ecified qu ery parame ters group ed by
914    * transac tion type   904    * transac tion type
915    *   905    *
916    * @param  array $tra nArray                - array wi th data fo r transact ion query   906    * @param  array $tra nArray                - array wi th data fo r transact ion query
917    *           ( 'order _num',                - select t ransaction  with spec ified orde r number   907    *           ( 'order _num',                - select t ransaction  with spec ified orde r number
918    *             'last_ days',                - select t ransaction s for spec ified last  days   908    *             'last_ days',                - select t ransaction s for spec ified last  days
919    *             'exact _date',               - select t ransaction s for spec ified date   909    *             'exact _date',               - select t ransaction s for spec ified date
920    *             'betwe en_date1',            - select t ransaction s between  date1 and  date2   910    *             'betwe en_date1',            - select t ransaction s between  date1 and  date2
921    *             'betwe en_date2'  )   911    *             'betwe en_date2'  )
922    *   912    *
923    * @return  array                           - array wi th financi al statist ic   913    * @return  array                           - array wi th financi al statist ic
924    *           ( 'membe rship_amou nt',       - sum of m embership  transactio ns   914    *           ( 'membe rship_amou nt',       - sum of m embership  transactio ns
925    *             'credi ts_amount' ,          - sum of c redit purc hase trans actions    
926    *             'sales _amount',             - sum of p rofile pur chase tran sactions   915    *             'sales _amount',             - sum of p rofile pur chase tran sactions
927    *             'sdati ng_amount' ,          - sum of S peedDating  ticket pu rchase tra nsactions   916    *             'sdati ng_amount' ,          - sum of S peedDating  ticket pu rchase tra nsactions
928    *             'total ' )                   - total su m   917    *             'total ' )                   - total su m
929    *   918    *
930    *   919    *
931    */   920    */
932   function g etFinanceS tat( $tran Array )   921   function g etFinanceS tat( $tran Array )
933   {   922   {
934       global  $currency _code;   923       global  $currency _code;
935       global  $separato r;   924       global  $separato r;
936     925  
937       if ( i sset($tran Array['ord er_num'])  )   926       if ( i sset($tran Array['ord er_num'])  )
938       {   927       {
939           $t ranFilter  = "`gtwTra nsactionID ` = '". pr ocess_db_i nput( $tra nArray['or der_num'],  0, 1 ) ." '";   928           $t ranFilter  = "`gtwTra nsactionID ` = '". pr ocess_db_i nput( $tra nArray['or der_num'],  0, 1 ) ." '";
940       }   929       }
941       elseif  ( isset($ tranArray[ 'last_days ']) )   930       elseif  ( isset($ tranArray[ 'last_days ']) )
942       {   931       {
943           $t ranFilter  = "( TO_DA YS( NOW()  ) - TO_DAY S( `Date`  ) <= ". (( int)$tranA rray['last _days']) . " )";   932           $t ranFilter  = "( TO_DA YS( NOW()  ) - TO_DAY S( `Date`  ) <= ". (( int)$tranA rray['last _days']) . " )";
944       }   933       }
945       elseif  ( isset($ tranArray[ 'exact_dat e']) )   934       elseif  ( isset($ tranArray[ 'exact_dat e']) )
946       {   935       {
947           $e xactDate =  strtotime ( $tranArr ay['exact_ date'] );   936           $e xactDate =  strtotime ( $tranArr ay['exact_ date'] );
948           if  ( $exactD ate != -1  )   937           if  ( $exactD ate != -1  )
949                $tranFil ter = "TO_ DAYS( FROM _UNIXTIME( $exactDate ) ) = TO_D AYS( `Date ` )";   938                $tranFil ter = "TO_ DAYS( FROM _UNIXTIME( $exactDate ) ) = TO_D AYS( `Date ` )";
950           el se   939           el se
951                $tranFil ter = "1";   940                $tranFil ter = "1";
952       }   941       }
953       elseif  ( isset($ tranArray[ 'between_d ate1']) &&  isset($tr anArray['b etween_dat e2']) )   942       elseif  ( isset($ tranArray[ 'between_d ate1']) &&  isset($tr anArray['b etween_dat e2']) )
954       {   943       {
955           if  ( $tranAr ray['betwe en_date1']  == 'start ' )   944           if  ( $tranAr ray['betwe en_date1']  == 'start ' )
956                $between Date1 = 0;   945                $between Date1 = 0;
957           el seif ( $tr anArray['b etween_dat e1'] == 'n ow' )   946           el seif ( $tr anArray['b etween_dat e1'] == 'n ow' )
958                $between Date1 = ti me();   947                $between Date1 = ti me();
959           el se   948           el se
960                $between Date1 = st rtotime( $ tranArray[ 'between_d ate1'] );   949                $between Date1 = st rtotime( $ tranArray[ 'between_d ate1'] );
961           if  ( $tranAr ray['betwe en_date2']  == 'start ' )   950           if  ( $tranAr ray['betwe en_date2']  == 'start ' )
962                $between Date2 = 0;   951                $between Date2 = 0;
963           el seif ( $tr anArray['b etween_dat e2'] == 'n ow' )   952           el seif ( $tr anArray['b etween_dat e2'] == 'n ow' )
964                $between Date2 = ti me();   953                $between Date2 = ti me();
965           el se   954           el se
966                $between Date2 = st rtotime( $ tranArray[ 'between_d ate2'] );   955                $between Date2 = st rtotime( $ tranArray[ 'between_d ate2'] );
967     956  
968           if  ( $betwee nDate1 !=  -1 && $bet weenDate2  != -1 )   957           if  ( $betwee nDate1 !=  -1 && $bet weenDate2  != -1 )
969                $tranFil ter = "( T O_DAYS( FR OM_UNIXTIM E($between Date1) ) < = TO_DAYS(  `Date` )  AND TO_DAY S( FROM_UN IXTIME($be tweenDate2 ) ) >= TO_ DAYS( `Dat e` ) )";   958                $tranFil ter = "( T O_DAYS( FR OM_UNIXTIM E($between Date1) ) < = TO_DAYS(  `Date` )  AND TO_DAY S( FROM_UN IXTIME($be tweenDate2 ) ) >= TO_ DAYS( `Dat e` ) )";
970           el se   959           el se
971                $tranFil ter = "1";   960                $tranFil ter = "1";
972       }   961       }
973       else   962       else
974       {   963       {
975           $t ranFilter  = "1";   964           $t ranFilter  = "1";
976       }   965       }
977     966  
978       // Fil l the arra y   967       // Fil l the arra y
979       $fin =  array();   968       $fin =  array();
980       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Data`  LIKE '%{$s eparator}m embership{ $separator }%' AND `C urrency` =  '{$curren cy_code}'"  );   969       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Data`  LIKE '%{$s eparator}m embership{ $separator }%' AND `C urrency` =  '{$curren cy_code}'"  );
981       $fin[' membership _amount']  = sprintf(  "%.2f", ( float)$arr [0] );   970       $fin[' membership _amount']  = sprintf(  "%.2f", ( float)$arr [0] );
982       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Data`  LIKE '%{$s eparator}c redits{$se parator}%'  AND `Curr ency` = '{ $currency_ code}'" );    
983       $fin[' credits_am ount'] = s printf( "% .2f", (flo at)$arr[0]  );    
984       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Data`  LIKE '%{$s eparator}p rofiles{$s eparator}% ' AND `Cur rency` = ' {$currency _code}'" ) ;   971       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Data`  LIKE '%{$s eparator}p rofiles{$s eparator}% ' AND `Cur rency` = ' {$currency _code}'" ) ;
985       $fin[' sales_amou nt'] = spr intf( "%.2 f", (float )$arr[0] ) ;   972       $fin[' sales_amou nt'] = spr intf( "%.2 f", (float )$arr[0] ) ;
986       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Data`  LIKE '%{$s eparator}s peeddating {$separato r}%' AND ` Currency`  = '{$curre ncy_code}' " );   973       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Data`  LIKE '%{$s eparator}s peeddating {$separato r}%' AND ` Currency`  = '{$curre ncy_code}' " );
987       $fin[' sdating_am ount'] = s printf( "% .2f", (flo at)$arr[0]  );   974       $fin[' sdating_am ount'] = s printf( "% .2f", (flo at)$arr[0]  );
988       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Curren cy` = '{$c urrency_co de}'" );   975       $arr =  db_arr( " SELECT SUM ( `Amount`  ) FROM `T ransaction s` WHERE { $tranFilte r} AND `St atus` = 'a pproved' A ND `Curren cy` = '{$c urrency_co de}'" );
989       $fin[' total'] =  sprintf( " %.2f", (fl oat)$arr[0 ] );   976       $fin[' total'] =  sprintf( " %.2f", (fl oat)$arr[0 ] );
990     977  
991       return  $fin;   978       return  $fin;
992   }   979   }
993     980  
994   ?>   981   ?>