235. File Comparison Report

Produced on Mon May 12 13:05:21 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.

235.1 Files compared

# Location File Last Modified
1 Dolphin-v.6.0.5\inc membership_levels.inc.php Thu Jan 31 09:17:20 2008 UTC
2 Dolphin-v.6.1.0\inc membership_levels.inc.php Tue Apr 15 11:33:44 2008 UTC

235.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 6 1758
Changed 3 11
Inserted 2 5
Removed 0 0

235.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

235.4 Active regular expressions

No regular expressions were active.

235.5 Comparison detail

1   <?   1   <?
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     21  
22   require_on ce( 'heade r.inc.php'  );   22   require_on ce( 'heade r.inc.php'  );
23   require_on ce( BX_DIR ECTORY_PAT H_INC . 'd b.inc.php'  );   23   require_on ce( BX_DIR ECTORY_PAT H_INC . 'd b.inc.php'  );
24   require_on ce( BX_DIR ECTORY_PAT H_INC . 'l anguages.i nc.php' );   24   require_on ce( BX_DIR ECTORY_PAT H_INC . 'l anguages.i nc.php' );
25     25  
26   //MESSAGE  CONSTANTS  PASSED TO  _t_ext() F UNCTION BY  checkActi on()   26   //MESSAGE  CONSTANTS  PASSED TO  _t_ext() F UNCTION BY  checkActi on()
27   //NOTE: ch eckAction( ) RETURNS  LANGUAGE D EPENDANT M ESSAGES   27   //NOTE: ch eckAction( ) RETURNS  LANGUAGE D EPENDANT M ESSAGES
28     28  
29   define('CH ECK_ACTION _MESSAGE_N OT_ALLOWED ',           "_ACTION _NOT_ALLOW ED");   29   define('CH ECK_ACTION _MESSAGE_N OT_ALLOWED ',           "_ACTION _NOT_ALLOW ED");
30   define('CH ECK_ACTION _MESSAGE_N OT_ACTIVE' ,            "_ACTION _NOT_ACTIV E");   30   define('CH ECK_ACTION _MESSAGE_N OT_ACTIVE' ,            "_ACTION _NOT_ACTIV E");
31   define('CH ECK_ACTION _MESSAGE_L IMIT_REACH ED',         "_ACTION _LIMIT_REA CHED");   31   define('CH ECK_ACTION _MESSAGE_L IMIT_REACH ED',         "_ACTION _LIMIT_REA CHED");
32   define('CH ECK_ACTION _MESSAGE_M ESSAGE_EVE RY_PERIOD' , "_ACTION _EVERY_PER IOD");   32   define('CH ECK_ACTION _MESSAGE_M ESSAGE_EVE RY_PERIOD' , "_ACTION _EVERY_PER IOD");
33   define('CH ECK_ACTION _MESSAGE_N OT_ALLOWED _BEFORE',    "_ACTION _NOT_ALLOW ED_BEFORE" );   33   define('CH ECK_ACTION _MESSAGE_N OT_ALLOWED _BEFORE',    "_ACTION _NOT_ALLOW ED_BEFORE" );
34   define('CH ECK_ACTION _MESSAGE_N OT_ALLOWED _AFTER',     "_ACTION _NOT_ALLOW ED_AFTER") ;   34   define('CH ECK_ACTION _MESSAGE_N OT_ALLOWED _AFTER',     "_ACTION _NOT_ALLOW ED_AFTER") ;
35     35  
36   //NODES OF  THE $args  ARRAY THA T IS PASSE D TO THE _ t_ext() FU NCTION BY  checkActio n()   36   //NODES OF  THE $args  ARRAY THA T IS PASSE D TO THE _ t_ext() FU NCTION BY  checkActio n()
37     37  
38   define('CH ECK_ACTION _LANG_FILE _ACTION',      1);   38   define('CH ECK_ACTION _LANG_FILE _ACTION',      1);
39   define('CH ECK_ACTION _LANG_FILE _MEMBERSHI P', 2);   39   define('CH ECK_ACTION _LANG_FILE _MEMBERSHI P', 2);
40   define('CH ECK_ACTION _LANG_FILE _LIMIT',       3);   40   define('CH ECK_ACTION _LANG_FILE _LIMIT',       3);
41   define('CH ECK_ACTION _LANG_FILE _PERIOD',      4);   41   define('CH ECK_ACTION _LANG_FILE _PERIOD',      4);
42   define('CH ECK_ACTION _LANG_FILE _AFTER',       5);   42   define('CH ECK_ACTION _LANG_FILE _AFTER',       5);
43   define('CH ECK_ACTION _LANG_FILE _BEFORE',      6);   43   define('CH ECK_ACTION _LANG_FILE _BEFORE',      6);
44   define('CH ECK_ACTION _LANG_FILE _SITE_EMAI L', 7);   44   define('CH ECK_ACTION _LANG_FILE _SITE_EMAI L', 7);
45     45  
46   //ACTION I D's   46   //ACTION I D's
47     47  
48   define('AC TION_ID_SE ND_VKISS',        1);   48   define('AC TION_ID_SE ND_VKISS',        1);
49   define('AC TION_ID_US E_CHAT',          2);   49   define('AC TION_ID_US E_CHAT',          2);
50   define('AC TION_ID_US E_IM',        3);   50   define('AC TION_ID_US E_IM',        3);
51   define('AC TION_ID_VI EW_PROFILE S',    4);   51   define('AC TION_ID_VI EW_PROFILE S',    4);
52   define('AC TION_ID_US E_FORUM',         5);   52   define('AC TION_ID_US E_FORUM',         5);
53   define('AC TION_ID_MA KE_SEARCH' ,      6);   53   define('AC TION_ID_MA KE_SEARCH' ,      6);
54   define('AC TION_ID_VO TE',              7);   54   define('AC TION_ID_VO TE',              7);
55   define('AC TION_ID_SE ND_MESSAGE ',     8);   55   define('AC TION_ID_SE ND_MESSAGE ',     8);
56   define('AC TION_ID_VI EW_PHOTOS' ,      9);   56   define('AC TION_ID_VI EW_PHOTOS' ,      9);
57   define('AC TION_ID_US E_RAY_IM',       10);   57   define('AC TION_ID_US E_RAY_IM',       10);
58   define('AC TION_ID_US E_RAY_VR',       11);   58   define('AC TION_ID_US E_RAY_VR',       11);
59   define('AC TION_ID_US E_RAY_CHAT ',    12);   59   define('AC TION_ID_US E_RAY_CHAT ',    12);
60   define('AC TION_ID_US E_GUESTBOO K',   13);   60   define('AC TION_ID_US E_GUESTBOO K',   13);
61   define('AC TION_ID_VI EW_GUESTBO OK',  14);   61   define('AC TION_ID_VI EW_GUESTBO OK',  14);
62   define('AC TION_ID_GE T_EMAIL',        15);   62   define('AC TION_ID_GE T_EMAIL',        15);
63   define('AC TION_ID_US E_GALLERY' ,     16);   63   define('AC TION_ID_US E_GALLERY' ,     16);
64   define('AC TION_ID_VI EW_GALLERY ',    17);   64   define('AC TION_ID_VI EW_GALLERY ',    17);
65   define('AC TION_ID_US E_RAY_MP3' ,     18);   65   define('AC TION_ID_US E_RAY_MP3' ,     18);
66   define('AC TION_ID_US E_BLOG',         19);   66   define('AC TION_ID_US E_BLOG',         19);
67   define('AC TION_ID_VI EW_BLOG',        20);   67   define('AC TION_ID_VI EW_BLOG',        20);
68   define('AC TION_ID_US E_RAY_VP',   21);   68   define('AC TION_ID_US E_RAY_VP',   21);
69   define('AC TION_ID_US E_RAY_PRES ENCE',     22);   69   define('AC TION_ID_US E_RAY_PRES ENCE',     22);
70   define('AC TION_ID_CA N_AD_CLASS IFIEDS',   23);   70   define('AC TION_ID_CA N_AD_CLASS IFIEDS',   23);
71   define('AC TION_ID_RA TE_PHOTOS' ,          24);   71   define('AC TION_ID_RA TE_PHOTOS' ,          24);
72   define('AC TION_ID_US E_ORCA_PUB LIC_FORUM' ,   25);   72   define('AC TION_ID_US E_ORCA_PUB LIC_FORUM' ,   25);
73   define('AC TION_ID_US E_ORCA_PRI VATE_FORUM ',  26);   73   define('AC TION_ID_US E_ORCA_PRI VATE_FORUM ',  26);
74   define('AC TION_ID_UP LOAD_GALLE RY_MUSIC',  27);   74   define('AC TION_ID_UP LOAD_GALLE RY_MUSIC',  27);
75   define('AC TION_ID_UP LOAD_GALLE RY_PHOTO',  28);   75   define('AC TION_ID_UP LOAD_GALLE RY_PHOTO',  28);
76   define('AC TION_ID_UP LOAD_GALLE RY_VIDEO',  29);   76   define('AC TION_ID_UP LOAD_GALLE RY_VIDEO',  29);
77   define('AC TION_ID_VI EW_GALLERY _MUSIC', 3 0);   77   define('AC TION_ID_VI EW_GALLERY _MUSIC', 3 0);
78   define('AC TION_ID_VI EW_GALLERY _PHOTO', 3 1);   78   define('AC TION_ID_VI EW_GALLERY _PHOTO', 3 1);
79   define('AC TION_ID_VI EW_GALLERY _VIDEO', 3 2);   79   define('AC TION_ID_VI EW_GALLERY _VIDEO', 3 2);
    80   define('AC TION_ID_CO MMENTS_POS T', 33);
    81   define('AC TION_ID_CO MMENTS_VOT E', 34);
    82   define('AC TION_ID_CO MMENTS_EDI T_OWN', 35 );
    83   define('AC TION_ID_CO MMENTS_REM OVE_OWN',  36);
80     84  
81   //PREDEFIN ED MEMBERS HIP ID's   85   //PREDEFIN ED MEMBERS HIP ID's
82     86  
83   define('ME MBERSHIP_I D_NON_MEMB ER', 1);   87   define('ME MBERSHIP_I D_NON_MEMB ER', 1);
84   define('ME MBERSHIP_I D_STANDARD ', 2);   88   define('ME MBERSHIP_I D_STANDARD ', 2);
85   define('ME MBERSHIP_I D_PROMOTIO N', 3);   89   define('ME MBERSHIP_I D_PROMOTIO N', 3);
86     90  
87   //INDICES  FOR checkA ction() RE SULT ARRAY   91   //INDICES  FOR checkA ction() RE SULT ARRAY
88     92  
89   define('CH ECK_ACTION _RESULT',  0);   93   define('CH ECK_ACTION _RESULT',  0);
90   define('CH ECK_ACTION _MESSAGE',  1);   94   define('CH ECK_ACTION _MESSAGE',  1);
91   define('CH ECK_ACTION _PARAMETER ', 3);   95   define('CH ECK_ACTION _PARAMETER ', 3);
92     96  
93   //CHECK_AC TION_RESUL T NODE VAL UES   97   //CHECK_AC TION_RESUL T NODE VAL UES
94     98  
95   define('CH ECK_ACTION _RESULT_AL LOWED',                 0);   99   define('CH ECK_ACTION _RESULT_AL LOWED',                 0);
96   define('CH ECK_ACTION _RESULT_NO T_ALLOWED' ,            1);   100   define('CH ECK_ACTION _RESULT_NO T_ALLOWED' ,            1);
97   define('CH ECK_ACTION _RESULT_NO T_ACTIVE',              2);   101   define('CH ECK_ACTION _RESULT_NO T_ACTIVE',              2);
98   define('CH ECK_ACTION _RESULT_LI MIT_REACHE D',          3);   102   define('CH ECK_ACTION _RESULT_LI MIT_REACHE D',          3);
99   define('CH ECK_ACTION _RESULT_NO T_ALLOWED_ BEFORE',     4);   103   define('CH ECK_ACTION _RESULT_NO T_ALLOWED_ BEFORE',     4);
100   define('CH ECK_ACTION _RESULT_NO T_ALLOWED_ AFTER',      5);   104   define('CH ECK_ACTION _RESULT_NO T_ALLOWED_ AFTER',      5);
101     105  
102   /**   106   /**
103    * Returns  number of  members w ith a give n membersh ip at a gi ven time   107    * Returns  number of  members w ith a give n membersh ip at a gi ven time
104    *   108    *
105    * @param  int $membe rshipID      - member s of what  membership  should be  counted.   109    * @param  int $membe rshipID      - member s of what  membership  should be  counted.
106    *                                   if 0,  then all m embers are  counted ( $except is  not consi dered);   110    *                                   if 0,  then all m embers are  counted ( $except is  not consi dered);
107    *                                   if MEM BERSHIP_ID _NON_MEMBE R is speci fied, func tion retur ns -1   111    *                                   if MEM BERSHIP_ID _NON_MEMBE R is speci fied, func tion retur ns -1
108    *   112    *
109    * @param  unix_times tamp $time   - date/t ime to use  when coun ting membe rs.   113    * @param  unix_times tamp $time   - date/t ime to use  when coun ting membe rs.
110    *                                   if not  specified , uses the  present m oment   114    *                                   if not  specified , uses the  present m oment
111    * @param  boolean $e xcept        - if tru e, counts  all member s that DON 'T have sp ecified me mbership   115    * @param  boolean $e xcept        - if tru e, counts  all member s that DON 'T have sp ecified me mbership
112    *   116    *
113    *   117    *
114    */   118    */
115   function g etMembersC ount($memb ershipID =  0, $time  = '', $exc ept = fals e)   119   function g etMembersC ount($memb ershipID =  0, $time  = '', $exc ept = fals e)
116   {   120   {
117       $membe rshipID =  (int)$memb ershipID;   121       $membe rshipID =  (int)$memb ershipID;
118       $time  = ($time = = '') ? ti me() : (in t)$time;   122       $time  = ($time = = '') ? ti me() : (in t)$time;
119       $excep t = $excep t ? true :  false;   123       $excep t = $excep t ? true :  false;
120     124  
121       if($me mbershipID  == MEMBER SHIP_ID_NO N_MEMBER | | $members hipID < 0)  return -1 ;   125       if($me mbershipID  == MEMBER SHIP_ID_NO N_MEMBER | | $members hipID < 0)  return -1 ;
122     126  
123       $resPr ofiles = d b_res("SEL ECT COUNT( *) FROM Pr ofiles");   127       $resPr ofiles = d b_res("SEL ECT COUNT( *) FROM Pr ofiles");
124     128  
125       $total Profiles =  mysql_fet ch_row($re sProfiles) ;   129       $total Profiles =  mysql_fet ch_row($re sProfiles) ;
126       $total Profiles =  (int)$tot alProfiles [0];   130       $total Profiles =  (int)$tot alProfiles [0];
127     131  
128       if($me mbershipID  == 0) ret urn $total Profiles;   132       if($me mbershipID  == 0) ret urn $total Profiles;
129     133  
130       $query WhereMembe rship = '' ;   134       $query WhereMembe rship = '' ;
131     135  
132       if($me mbershipID  != MEMBER SHIP_ID_ST ANDARD) $q ueryWhereM embership  = "IDLevel  = $member shipID AND ";   136       if($me mbershipID  != MEMBER SHIP_ID_ST ANDARD) $q ueryWhereM embership  = "IDLevel  = $member shipID AND ";
133     137  
134       $query  = "   138       $query  = "
135           SE LECT  COUN T(DISTINCT  IDMember)   139           SE LECT  COUN T(DISTINCT  IDMember)
136           FR OM    Prof ileMemLeve ls   140           FR OM    Prof ileMemLeve ls
137           WH ERE   $que ryWhereMem bership   141           WH ERE   $que ryWhereMem bership
138                    (Dat eExpires I S NULL OR  UNIX_TIMES TAMP(DateE xpires) >  $time) AND   142                    (Dat eExpires I S NULL OR  UNIX_TIMES TAMP(DateE xpires) >  $time) AND
139                    (Dat eStarts IS  NULL OR U NIX_TIMEST AMP(DateSt arts) <= $ time)";   143                    (Dat eStarts IS  NULL OR U NIX_TIMEST AMP(DateSt arts) <= $ time)";
140     144  
141       $resPr ofileMemLe vels = db_ res($query );   145       $resPr ofileMemLe vels = db_ res($query );
142     146  
143       $membe rshipProfi les = mysq l_fetch_ro w($resProf ileMemLeve ls);   147       $membe rshipProfi les = mysq l_fetch_ro w($resProf ileMemLeve ls);
144       $membe rshipProfi les = (int )$membersh ipProfiles [0];   148       $membe rshipProfi les = (int )$membersh ipProfiles [0];
145     149  
146       if($me mbershipID  == MEMBER SHIP_ID_ST ANDARD) $m embershipP rofiles =  $totalProf iles - $me mbershipPr ofiles;   150       if($me mbershipID  == MEMBER SHIP_ID_ST ANDARD) $m embershipP rofiles =  $totalProf iles - $me mbershipPr ofiles;
147     151  
148       if($ex cept) $mem bershipPro files = $t otalProfil es - $memb ershipProf iles;   152       if($ex cept) $mem bershipPro files = $t otalProfil es - $memb ershipProf iles;
149     153  
150       return  $membersh ipProfiles ;   154       return  $membersh ipProfiles ;
151   }   155   }
152     156  
153   /**   157   /**
154    * This is  an intern al functio n - do NOT  use it ou tside of m embership_ levels.inc .php!   158    * This is  an intern al functio n - do NOT  use it ou tside of m embership_ levels.inc .php!
155    */   159    */
156   function g etMemberMe mbershipIn fo_current ($memberID , $time =  '')   160   function g etMemberMe mbershipIn fo_current ($memberID , $time =  '')
157   {   161   {
158       $membe rID = (int )$memberID ;   162       $membe rID = (int )$memberID ;
159       $time  = ($time = = '') ? ti me() : (in t)$time;   163       $time  = ($time = = '') ? ti me() : (in t)$time;
160     164  
161       //fetc h the last  purchased /assigned  membership   165       //fetc h the last  purchased /assigned  membership
162       //that  is still  active for  the given  member   166       //that  is still  active for  the given  member
163     167  
164       $resPr ofileMemLe vels = db_ res("   168       $resPr ofileMemLe vels = db_ res("
165           SE LECT  Prof ileMemLeve ls.IDLevel  as ID,   169           SE LECT  Prof ileMemLeve ls.IDLevel  as ID,
166                    MemL evels.Name  as Name,   170                    MemL evels.Name  as Name,
167                    UNIX _TIMESTAMP (ProfileMe mLevels.Da teStarts)  as DateSta rts,   171                    UNIX _TIMESTAMP (ProfileMe mLevels.Da teStarts)  as DateSta rts,
168                    UNIX _TIMESTAMP (ProfileMe mLevels.Da teExpires)  as DateEx pires   172                    UNIX _TIMESTAMP (ProfileMe mLevels.Da teExpires)  as DateEx pires
169     173  
170           FR OM    Prof ileMemLeve ls   174           FR OM    Prof ileMemLeve ls
171                    RIGH T JOIN Pro files   175                    RIGH T JOIN Pro files
172                    ON P rofileMemL evels.IDMe mber = Pro files.ID   176                    ON P rofileMemL evels.IDMe mber = Pro files.ID
173                         AND (Profi leMemLevel s.DateStar ts IS NULL   177                         AND (Profi leMemLevel s.DateStar ts IS NULL
174                             OR UNI X_TIMESTAM P(ProfileM emLevels.D ateStarts)  <= $time)   178                             OR UNI X_TIMESTAM P(ProfileM emLevels.D ateStarts)  <= $time)
175                         AND (Profi leMemLevel s.DateExpi res IS NUL L   179                         AND (Profi leMemLevel s.DateExpi res IS NUL L
176                             OR UNI X_TIMESTAM P(ProfileM emLevels.D ateExpires ) > $time)   180                             OR UNI X_TIMESTAM P(ProfileM emLevels.D ateExpires ) > $time)
177                    LEFT  JOIN MemL evels   181                    LEFT  JOIN MemL evels
178                    ON P rofileMemL evels.IDLe vel = MemL evels.ID   182                    ON P rofileMemL evels.IDLe vel = MemL evels.ID
179     183  
180           WH ERE   Prof iles.ID =  $memberID   184           WH ERE   Prof iles.ID =  $memberID
181     185  
182           OR DER BY Pro fileMemLev els.DateSt arts DESC   186           OR DER BY Pro fileMemLev els.DateSt arts DESC
183     187  
184           LI MIT 0, 1") ;   188           LI MIT 0, 1") ;
185     189  
186       //no s uch member  found   190       //no s uch member  found
187     191  
188       if(mys ql_num_row s($resProf ileMemLeve ls) < 1)   192       if(mys ql_num_row s($resProf ileMemLeve ls) < 1)
189       {   193       {
190           // fetch info  about Non -member me mbership   194           // fetch info  about Non -member me mbership
191     195  
192           $r esMemLevel s = db_res ("SELECT I D, Name FR OM MemLeve ls WHERE I D = ".MEMB ERSHIP_ID_ NON_MEMBER );   196           $r esMemLevel s = db_res ("SELECT I D, Name FR OM MemLeve ls WHERE I D = ".MEMB ERSHIP_ID_ NON_MEMBER );
193     197  
194           if (mysql_num _rows($res MemLevels)  < 1)   198           if (mysql_num _rows($res MemLevels)  < 1)
195           {   199           {
196     200  
197                //this s hould neve r happen,  but just i n case   201                //this s hould neve r happen,  but just i n case
198                echo "<b r /><b>get MemberMemb ershipInfo ()</b> fat al error:  <b>Non-Mem ber</b> me mbership n ot found." ;   202                echo "<b r /><b>get MemberMemb ershipInfo ()</b> fat al error:  <b>Non-Mem ber</b> me mbership n ot found." ;
199                exit();   203                exit();
200           }   204           }
201     205  
202           $a rrMemLevel  = mysql_f etch_assoc ($resMemLe vels);   206           $a rrMemLevel  = mysql_f etch_assoc ($resMemLe vels);
203     207  
204           re turn $arrM emLevel;   208           re turn $arrM emLevel;
205       }   209       }
206     210  
207       $arrMe mLevel = m ysql_fetch _assoc($re sProfileMe mLevels);   211       $arrMe mLevel = m ysql_fetch _assoc($re sProfileMe mLevels);
208     212  
209       //no p urchased/a ssigned me mberships  for the me mber or al l of them   213       //no p urchased/a ssigned me mberships  for the me mber or al l of them
210       //have  expired - - the memb er is assu med to hav e Standard  membershi p   214       //have  expired - - the memb er is assu med to hav e Standard  membershi p
211     215  
212       if(is_ null($arrM emLevel['I D']))   216       if(is_ null($arrM emLevel['I D']))
213       {   217       {
214     218  
215           $r esMemLevel s = db_res ("SELECT I D, Name FR OM MemLeve ls WHERE I D = ".MEMB ERSHIP_ID_ STANDARD);   219           $r esMemLevel s = db_res ("SELECT I D, Name FR OM MemLeve ls WHERE I D = ".MEMB ERSHIP_ID_ STANDARD);
216     220  
217           if (mysql_num _rows($res MemLevels)  < 1)   221           if (mysql_num _rows($res MemLevels)  < 1)
218           {   222           {
219     223  
220                //again,  this shou ld never h appen, but  just in c ase   224                //again,  this shou ld never h appen, but  just in c ase
221                echo "<b r /><b>get MemberMemb ershipInfo ()</b> fat al error:  <b>Standar d</b> memb ership not  found.";   225                echo "<b r /><b>get MemberMemb ershipInfo ()</b> fat al error:  <b>Standar d</b> memb ership not  found.";
222                exit();   226                exit();
223           }   227           }
224     228  
225           $a rrMemLevel  = mysql_f etch_assoc ($resMemLe vels);   229           $a rrMemLevel  = mysql_f etch_assoc ($resMemLe vels);
226       }   230       }
227     231  
228       return  $arrMemLe vel;   232       return  $arrMemLe vel;
229   }   233   }
230     234  
231   /**   235   /**
232    * Retriev es informa tion about  membershi p for a gi ven member  at a give n moment.   236    * Retriev es informa tion about  membershi p for a gi ven member  at a give n moment.
233    *   237    *
234    * If ther e are no m emberships  purchased /assigned  to the   238    * If ther e are no m emberships  purchased /assigned  to the
235    * given m ember or a ll of them  have expi red at the  given poi nt,   239    * given m ember or a ll of them  have expi red at the  given poi nt,
236    * the mem ber is ass umed to be  a standar d member,  and the fu nction   240    * the mem ber is ass umed to be  a standar d member,  and the fu nction
237    * returns   informat ion about  the Standa rd members hip. This  will   241    * returns   informat ion about  the Standa rd members hip. This  will
238    * also ha ppen if a  member was nt actuall y register ed in the  database   242    * also ha ppen if a  member was nt actuall y register ed in the  database
239    * at that  point - t he functio n will sti ll return  info about  Standard   243    * at that  point - t he functio n will sti ll return  info about  Standard
240    * members hip, not t he Non-mem ber one.   244    * members hip, not t he Non-mem ber one.
241    *   245    *
242    * If ther e is no pr ofile with  the given  $memberID ,   246    * If ther e is no pr ofile with  the given  $memberID ,
243    * the fun ction retu rns inform ation abou t the Non- member   247    * the fun ction retu rns inform ation abou t the Non- member
244    * predefi ned member ship.   248    * predefi ned member ship.
245    *   249    *
246    * The Sta ndard and  Non-member  membershi ps have th eir   250    * The Sta ndard and  Non-member  membershi ps have th eir
247    * DateSta rts and Da teExpires  attributes  set to NU LL.   251    * DateSta rts and Da teExpires  attributes  set to NU LL.
248    *   252    *
249    * @param  int $membe rID - ID o f a member  to get in fo about   253    * @param  int $membe rID - ID o f a member  to get in fo about
250    * @param  int $time      - spec ifies the  time to us e when det ermining m embership;   254    * @param  int $time      - spec ifies the  time to us e when det ermining m embership;
251    *                          if n ot specifi ed, the fu nction tak es the cur rent time   255    *                          if n ot specifi ed, the fu nction tak es the cur rent time
252    *   256    *
253    * @return  array(    'ID'             => m embership  id,   257    * @return  array(    'ID'             => m embership  id,
254    *                    'Name'           => m embership  name,   258    *                    'Name'           => m embership  name,
255    *                    'DateStart s'    => ( UNIX times tamp) date /time purc hased,   259    *                    'DateStart s'    => ( UNIX times tamp) date /time purc hased,
256    *                    'DateExpir es'   => ( UNIX times tamp) date /time expi res )   260    *                    'DateExpir es'   => ( UNIX times tamp) date /time expi res )
257    *   261    *
258    */   262    */
259   function g etMemberMe mbershipIn fo($member ID, $time  = '')   263   function g etMemberMe mbershipIn fo($member ID, $time  = '')
260   {   264   {
261       $time  = ($time = = '') ? ti me() : (in t)$time;   265       $time  = ($time = = '') ? ti me() : (in t)$time;
262     266  
263       $origi nalMembers hip = getM emberMembe rshipInfo_ current($m emberID, $ time);   267       $origi nalMembers hip = getM emberMembe rshipInfo_ current($m emberID, $ time);
264     268  
265       if( $o riginalMem bership['I D'] == MEM BERSHIP_ID _STANDARD  ||   269       if( $o riginalMem bership['I D'] == MEM BERSHIP_ID _STANDARD  ||
266           $o riginalMem bership['I D'] == MEM BERSHIP_ID _NON_MEMBE R )   270           $o riginalMem bership['I D'] == MEM BERSHIP_ID _NON_MEMBE R )
267       {   271       {
268           re turn $orig inalMember ship;   272           re turn $orig inalMember ship;
269       }   273       }
270     274  
271       $arrMe mbership =  $original Membership ;   275       $arrMe mbership =  $original Membership ;
272     276  
273       do   277       do
274       {   278       {
275           $d ateStarts  = $arrMemb ership['Da teStarts'] ;   279           $d ateStarts  = $arrMemb ership['Da teStarts'] ;
276           $a rrMembersh ip = getMe mberMember shipInfo_c urrent($me mberID, $d ateStarts  - 1);   280           $a rrMembersh ip = getMe mberMember shipInfo_c urrent($me mberID, $d ateStarts  - 1);
277       }   281       }
278       while( $arrMember ship['ID']  == $origi nalMembers hip['ID']  && (int)$a rrMembersh ip['DateSt arts']);   282       while( $arrMember ship['ID']  == $origi nalMembers hip['ID']  && (int)$a rrMembersh ip['DateSt arts']);
279     283  
280       $arrMe mbership =  $original Membership ;   284       $arrMe mbership =  $original Membership ;
281     285  
282       do   286       do
283       {   287       {
284           $d ateExpires  = $arrMem bership['D ateExpires '];   288           $d ateExpires  = $arrMem bership['D ateExpires '];
285           $a rrMembersh ip = getMe mberMember shipInfo_c urrent($me mberID, $d ateExpires );   289           $a rrMembersh ip = getMe mberMember shipInfo_c urrent($me mberID, $d ateExpires );
286       }   290       }
287       while( $arrMember ship['ID']  == $origi nalMembers hip['ID']  && (int)$a rrMembersh ip['DateEx pires']);   291       while( $arrMember ship['ID']  == $origi nalMembers hip['ID']  && (int)$a rrMembersh ip['DateEx pires']);
288     292  
289       $origi nalMembers hip['DateS tarts'] =  $dateStart s;   293       $origi nalMembers hip['DateS tarts'] =  $dateStart s;
290       $origi nalMembers hip['DateE xpires'] =  $dateExpi res;   294       $origi nalMembers hip['DateE xpires'] =  $dateExpi res;
291     295  
292       return  $original Membership ;   296       return  $original Membership ;
293   }   297   }
294     298  
295   /**   299   /**
296    * This is  an intern al functio n - do NOT  use it ou tside of m embership_ levels.inc .php!   300    * This is  an intern al functio n - do NOT  use it ou tside of m embership_ levels.inc .php!
297    */   301    */
298   function g etMemberMe mbershipIn fo_latest( $memberID,  $time = ' ')   302   function g etMemberMe mbershipIn fo_latest( $memberID,  $time = ' ')
299   {   303   {
300       $time  = ($time = = '') ? ti me() : (in t)$time;   304       $time  = ($time = = '') ? ti me() : (in t)$time;
301     305  
302       $origi nalMembers hip = getM emberMembe rshipInfo_ current($m emberID, $ time);   306       $origi nalMembers hip = getM emberMembe rshipInfo_ current($m emberID, $ time);
303     307  
304       if( $o riginalMem bership['I D'] == MEM BERSHIP_ID _STANDARD  ||   308       if( $o riginalMem bership['I D'] == MEM BERSHIP_ID _STANDARD  ||
305           $o riginalMem bership['I D'] == MEM BERSHIP_ID _NON_MEMBE R )   309           $o riginalMem bership['I D'] == MEM BERSHIP_ID _NON_MEMBE R )
306       {   310       {
307           re turn $orig inalMember ship;   311           re turn $orig inalMember ship;
308       }   312       }
309     313  
310       $arrMe mbership =  $original Membership ;   314       $arrMe mbership =  $original Membership ;
311       $lastM embership  = $origina lMembershi p;   315       $lastM embership  = $origina lMembershi p;
312     316  
313       do   317       do
314       {   318       {
315           $d ateExpires  = $arrMem bership['D ateExpires '];   319           $d ateExpires  = $arrMem bership['D ateExpires '];
316           $a rrMembersh ip = getMe mberMember shipInfo_c urrent($me mberID, $d ateExpires );   320           $a rrMembersh ip = getMe mberMember shipInfo_c urrent($me mberID, $d ateExpires );
317           if (!is_null( $dateExpir es))   321           if (!is_null( $dateExpir es))
318                $lastMem bership =  $arrMember ship;   322                $lastMem bership =  $arrMember ship;
319       }   323       }
320       while( $arrMember ship['ID']  != MEMBER SHIP_ID_ST ANDARD &&  (int)$arrM embership[ 'DateExpir es']);   324       while( $arrMember ship['ID']  != MEMBER SHIP_ID_ST ANDARD &&  (int)$arrM embership[ 'DateExpir es']);
321     325  
322       $arrMe mbership =  $lastMemb ership;   326       $arrMe mbership =  $lastMemb ership;
323     327  
324       do   328       do
325       {   329       {
326           $d ateStarts  = $arrMemb ership['Da teStarts'] ;   330           $d ateStarts  = $arrMemb ership['Da teStarts'] ;
327           $a rrMembersh ip = getMe mberMember shipInfo_c urrent($me mberID, $d ateStarts  - 1);   331           $a rrMembersh ip = getMe mberMember shipInfo_c urrent($me mberID, $d ateStarts  - 1);
328       }   332       }
329       while( $arrMember ship['ID']  == $lastM embership[ 'ID'] && ( int)$arrMe mbership[' DateStarts ']);   333       while( $arrMember ship['ID']  == $lastM embership[ 'ID'] && ( int)$arrMe mbership[' DateStarts ']);
330     334  
331       $origi nalMembers hip['DateS tarts'] =  $dateStart s;   335       $origi nalMembers hip['DateS tarts'] =  $dateStart s;
332       $origi nalMembers hip['DateE xpires'] =  $dateExpi res;   336       $origi nalMembers hip['DateE xpires'] =  $dateExpi res;
333     337  
334       return  $original Membership ;   338       return  $original Membership ;
335   }   339   }
336     340  
337   /**   341   /**
338    * Checks  if a given  action is  allowed f or a given  member an d updates  action inf ormation i f the   342    * Checks  if a given  action is  allowed f or a given  member an d updates  action inf ormation i f the
339    * action  is perform ed.   343    * action  is perform ed.
340    *   344    *
341    * @param  int $membe rID          - ID of  a member t hat is goi ng to perf orm an act ion   345    * @param  int $membe rID          - ID of  a member t hat is goi ng to perf orm an act ion
342    * @param  int $actio nID          - ID of  the action  itself   346    * @param  int $actio nID          - ID of  the action  itself
343    * @param  boolean $p erformActi on    - if  true, the n action i nformation  is update d, i.e. ac tion   347    * @param  boolean $p erformActi on    - if  true, the n action i nformation  is update d, i.e. ac tion
344    *                                   is 'pe rformed'   348    *                                   is 'pe rformed'
345    *   349    *
346    * @return  array(    CHECK_ACTI ON_RESULT  => CHECK_A CTION_RESU LT_ consta nt,   350    * @return  array(    CHECK_ACTI ON_RESULT  => CHECK_A CTION_RESU LT_ consta nt,
347    *                    CHECK_ACTI ON_MESSAGE  => CHECK_ ACTION_MES SAGE_ cons tant,   351    *                    CHECK_ACTI ON_MESSAGE  => CHECK_ ACTION_MES SAGE_ cons tant,
348    *                    CHECK_ACTI ON_PARAMET ER => addi tional act ion parame ter (strin g) )   352    *                    CHECK_ACTI ON_PARAMET ER => addi tional act ion parame ter (strin g) )
349    *   353    *
350    *   354    *
351    * NOTES:   355    * NOTES:
352    *   356    *
353    * $result [CHECK_ACT ION_MESSAG E] contain s a messag e with det ailed info rmation ab out the re sult,   357    * $result [CHECK_ACT ION_MESSAG E] contain s a messag e with det ailed info rmation ab out the re sult,
354    * already  processed  by the la nguage fil e   358    * already  processed  by the la nguage fil e
355    *   359    *
356    * if $res ult[CHECK_ ACTION_RES ULT] == CH ECK_ACTION _RESULT_AL LOWED then  this node  contains   360    * if $res ult[CHECK_ ACTION_RES ULT] == CH ECK_ACTION _RESULT_AL LOWED then  this node  contains
357    * an empt y string   361    * an empt y string
358    *   362    *
359    * The err or message s themselv es are sto red in the  language  file. Addi tional var iables are   363    * The err or message s themselv es are sto red in the  language  file. Addi tional var iables are
360    * passed  to the lan guages.inc .php funct ion _t_ext () as an a rray and c an be used  there in  the form o f   364    * passed  to the lan guages.inc .php funct ion _t_ext () as an a rray and c an be used  there in  the form o f
361    * {0}, {1 }, {2} ...   365    * {0}, {1 }, {2} ...
362    *   366    *
363    * Additio nal variab les passed  to the la ng. file o n errors ( can be use d in error  messages) :   367    * Additio nal variab les passed  to the la ng. file o n errors ( can be use d in error  messages) :
364    *   368    *
365    *  For al l errors:   369    *  For al l errors:
366    *   370    *
367    *      $a rg0[CHECK_ ACTION_LAN G_FILE_ACT ION]    =  name of th e action   371    *      $a rg0[CHECK_ ACTION_LAN G_FILE_ACT ION]    =  name of th e action
368    *      $a rg0[CHECK_ ACTION_LAN G_FILE_MEM BERSHIP]=  name of th e current  membership   372    *      $a rg0[CHECK_ ACTION_LAN G_FILE_MEM BERSHIP]=  name of th e current  membership
369    *   373    *
370    *  CHECK_ ACTION_RES ULT_LIMIT_ REACHED:   374    *  CHECK_ ACTION_RES ULT_LIMIT_ REACHED:
371    *   375    *
372    *      $a rg0[CHECK_ ACTION_LAN G_FILE_LIM IT]     =  limit on n umber of a ctions all owed for t he member   376    *      $a rg0[CHECK_ ACTION_LAN G_FILE_LIM IT]     =  limit on n umber of a ctions all owed for t he member
373    *      $a rg0[CHECK_ ACTION_LAN G_FILE_PER IOD]    =  period tha t the limi t is set f or (in hou rs, 0 if u nlimited)   377    *      $a rg0[CHECK_ ACTION_LAN G_FILE_PER IOD]    =  period tha t the limi t is set f or (in hou rs, 0 if u nlimited)
374    *   378    *
375    *  CHECK_ ACTION_RES ULT_NOT_AL LOWED_BEFO RE:   379    *  CHECK_ ACTION_RES ULT_NOT_AL LOWED_BEFO RE:
376    *   380    *
377    *      $a rg0[CHECK_ ACTION_LAN G_FILE_BEF ORE]    =  date/time  since when  the actio n is allow ed   381    *      $a rg0[CHECK_ ACTION_LAN G_FILE_BEF ORE]    =  date/time  since when  the actio n is allow ed
378    *   382    *
379    *  CHECK_ ACTION_RES ULT_NOT_AL LOWED_AFTE R:   383    *  CHECK_ ACTION_RES ULT_NOT_AL LOWED_AFTE R:
380    *   384    *
381    *      $a rg0[CHECK_ ACTION_LAN G_FILE_AFT ER]     =  date/time  since when  the actio n is not a llowed   385    *      $a rg0[CHECK_ ACTION_LAN G_FILE_AFT ER]     =  date/time  since when  the actio n is not a llowed
382    *   386    *
383    * $result [CHECK_ACT ION_PARAME TER] conta ins an add itional pa rameter th at can be  considered   387    * $result [CHECK_ACT ION_PARAME TER] conta ins an add itional pa rameter th at can be  considered
384    * when pe rforming t he action  (like the  number of  profiles t o show in  search res ult)   388    * when pe rforming t he action  (like the  number of  profiles t o show in  search res ult)
385   */   389   */
386   function   checkActio n($memberI D,   $actionID,   $performAc tion   =   false
)
  390   function   checkActio n($memberI D,   $actionID,   $performAc tion   =   false ,   $iForcedPr ofID   =   0 )
387   {   391   {
    392       global  $logged;
388       global  $site;   393       global  $site;
389     394  
390       //outp ut array i nitializat ion   395       //outp ut array i nitializat ion
391     396  
392       $resul t = array( );   397       $resul t = array( );
393       $arrLa ngFilePara ms = array ();   398       $arrLa ngFilePara ms = array ();
394     399  
395       $dateF ormat = "F  j, Y, g:i  a";  //us ed when di splaying e rror messa ges   400       $dateF ormat = "F  j, Y, g:i  a";  //us ed when di splaying e rror messa ges
396     401  
397       //inpu t validati on   402       //inpu t validati on
398     403  
399       $membe rID = (int )$memberID ;   404       $membe rID = (int )$memberID ;
400       $actio nID = (int )$actionID ;   405       $actio nID = (int )$actionID ;
401       $perfo rmAction =  $performA ction ? tr ue : false ;   406       $perfo rmAction =  $performA ction ? tr ue : false ;
402     407  
403       //get  current me mber's mem bership in formation   408       //get  current me mber's mem bership in formation
404     409  
405       $arrMe mbership =  getMember Membership Info($memb erID);   410       $arrMe mbership =  getMember Membership Info($memb erID);
406     411  
407       $arrLa ngFilePara ms[CHECK_A CTION_LANG _FILE_MEMB ERSHIP] =  $arrMember ship['Name '];   412       $arrLa ngFilePara ms[CHECK_A CTION_LANG _FILE_MEMB ERSHIP] =  $arrMember ship['Name '];
408       $arrLa ngFilePara ms[CHECK_A CTION_LANG _FILE_SITE _EMAIL] =  $site['ema il'];   413       $arrLa ngFilePara ms[CHECK_A CTION_LANG _FILE_SITE _EMAIL] =  $site['ema il'];
409     414  
410       //prof ile active  check   415       //prof ile active  check
411     416  
412        if($arrMem bership['I D']   !=   MEMBERSHIP _ID_NON_ME MBER
)
  417        if($arrMem bership['I D']   !=   MEMBERSHIP _ID_NON_ME MBER   ||   $logged['a dmin']   ||   $logged['m oderator'] )
413       {   418       {
414            $ act i ve   =   g e
t Profile I nfo(   $memberID   ) ;
  419            $
i D e s t
I D   =   $memberID
;
    420           if  (($logged ['admin']  || $logged ['moderato r']) && $i ForcedProf ID>0) {
    421                $iDestID  = $iForce dProfID;
    422                $perform Action = f alse;
    423           }
    424           $a ctive = ge tProfileIn fo( $iDest ID );
415           $a ctive = ($ active['St atus'] ==  'Active');   425           $a ctive = ($ active['St atus'] ==  'Active');
416     426  
417           if (!$active)   427           if (!$active)
418           {   428           {
419                $result[ CHECK_ACTI ON_RESULT]  = CHECK_A CTION_RESU LT_NOT_ACT IVE;   429                $result[ CHECK_ACTI ON_RESULT]  = CHECK_A CTION_RESU LT_NOT_ACT IVE;
420                $result[ CHECK_ACTI ON_MESSAGE ] = _t_ext (CHECK_ACT ION_MESSAG E_NOT_ACTI VE, $arrLa ngFilePara ms);   430                $result[ CHECK_ACTI ON_MESSAGE ] = _t_ext (CHECK_ACT ION_MESSAG E_NOT_ACTI VE, $arrLa ngFilePara ms);
421     431  
422                return $ result;   432                return $ result;
423           }   433           }
424       }   434       }
425     435  
426       //free  mode chec k   436       //free  mode chec k
427     437  
428       if(get Param("fre e_mode") = = "on")   438       if(get Param("fre e_mode") = = "on")
429       {   439       {
430           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_A LLOWED;   440           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_A LLOWED;
431           re turn $resu lt;   441           re turn $resu lt;
432       }   442       }
433     443  
434       //get  permission s for the  current ac tion   444       //get  permission s for the  current ac tion
435     445  
436       $resMe mbershipAc tion = db_ res("   446       $resMe mbershipAc tion = db_ res("
437           SE LECT  Name ,   447           SE LECT  Name ,
438                    IDAc tion,   448                    IDAc tion,
439                    Allo wedCount,   449                    Allo wedCount,
440                    Allo wedPeriodL en,   450                    Allo wedPeriodL en,
441                    UNIX _TIMESTAMP (AllowedPe riodStart)  as Allowe dPeriodSta rt,   451                    UNIX _TIMESTAMP (AllowedPe riodStart)  as Allowe dPeriodSta rt,
442                    UNIX _TIMESTAMP (AllowedPe riodEnd) a s AllowedP eriodEnd,   452                    UNIX _TIMESTAMP (AllowedPe riodEnd) a s AllowedP eriodEnd,
443                    Addi tionalPara mValue   453                    Addi tionalPara mValue
444           FR OM    MemA ctions   454           FR OM    MemA ctions
445                    LEFT  JOIN MemL evelAction s   455                    LEFT  JOIN MemL evelAction s
446                    ON   MemLevelAc tions.IDAc tion = Mem Actions.ID   456                    ON   MemLevelAc tions.IDAc tion = Mem Actions.ID
447                         AND MemLev elActions. IDLevel =  {$arrMembe rship['ID' ]}   457                         AND MemLev elActions. IDLevel =  {$arrMembe rship['ID' ]}
448           WH ERE   MemA ctions.ID  = $actionI D");   458           WH ERE   MemA ctions.ID  = $actionI D");
449     459  
450       //no s uch action   460       //no s uch action
451     461  
452       if(mys ql_num_row s($resMemb ershipActi on) < 1)   462       if(mys ql_num_row s($resMemb ershipActi on) < 1)
453       {   463       {
454           ec ho "<br /> <b>checkAc tion()</b>  fatal err or. Unknow n action I D: $action ID<br />";   464           ec ho "<br /> <b>checkAc tion()</b>  fatal err or. Unknow n action I D: $action ID<br />";
455           ex it();   465           ex it();
456       }   466       }
457     467  
458       $arrAc tion = mys ql_fetch_a ssoc($resM embershipA ction);   468       $arrAc tion = mys ql_fetch_a ssoc($resM embershipA ction);
459     469  
460       $resul t[CHECK_AC TION_PARAM ETER] = $a rrAction[' Additional ParamValue '];   470       $resul t[CHECK_AC TION_PARAM ETER] = $a rrAction[' Additional ParamValue '];
461       $arrLa ngFilePara ms[CHECK_A CTION_LANG _FILE_ACTI ON] = _t(' _'.$arrAct ion['Name' ]);   471       $arrLa ngFilePara ms[CHECK_A CTION_LANG _FILE_ACTI ON] = _t(' _'.$arrAct ion['Name' ]);
462     472  
463       //acti on is not  allowed fo r the curr ent member ship   473       //acti on is not  allowed fo r the curr ent member ship
464     474  
465       if(is_ null($arrA ction['IDA ction']))   475       if(is_ null($arrA ction['IDA ction']))
466       {   476       {
467           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_N OT_ALLOWED ;   477           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_N OT_ALLOWED ;
468           $r esult[CHEC K_ACTION_M ESSAGE] =  _t_ext(CHE CK_ACTION_ MESSAGE_NO T_ALLOWED,  $arrLangF ileParams) ;   478           $r esult[CHEC K_ACTION_M ESSAGE] =  _t_ext(CHE CK_ACTION_ MESSAGE_NO T_ALLOWED,  $arrLangF ileParams) ;
469           re turn $resu lt;   479           re turn $resu lt;
470       }   480       }
471     481  
472       //Chec k fixed pe riod limit ations if  present (a lso for no n-members)   482       //Chec k fixed pe riod limit ations if  present (a lso for no n-members)
473     483  
474       if($ar rAction['A llowedPeri odStart']  && time()  < $arrActi on['Allowe dPeriodSta rt'])   484       if($ar rAction['A llowedPeri odStart']  && time()  < $arrActi on['Allowe dPeriodSta rt'])
475       {   485       {
476     486  
477           $a rrLangFile Params[CHE CK_ACTION_ LANG_FILE_ BEFORE] =  date($date Format, $a rrAction[' AllowedPer iodStart'] );   487           $a rrLangFile Params[CHE CK_ACTION_ LANG_FILE_ BEFORE] =  date($date Format, $a rrAction[' AllowedPer iodStart'] );
478     488  
479           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_N OT_ALLOWED _BEFORE;   489           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_N OT_ALLOWED _BEFORE;
480           $r esult[CHEC K_ACTION_M ESSAGE] =  _t_ext(CHE CK_ACTION_ MESSAGE_NO T_ALLOWED_ BEFORE, $a rrLangFile Params);   490           $r esult[CHEC K_ACTION_M ESSAGE] =  _t_ext(CHE CK_ACTION_ MESSAGE_NO T_ALLOWED_ BEFORE, $a rrLangFile Params);
481     491  
482           re turn $resu lt;   492           re turn $resu lt;
483       }   493       }
484     494  
485       if($ar rAction['A llowedPeri odEnd'] &&  time() >  $arrAction ['AllowedP eriodEnd'] )   495       if($ar rAction['A llowedPeri odEnd'] &&  time() >  $arrAction ['AllowedP eriodEnd'] )
486       {   496       {
487     497  
488           $a rrLangFile Params[CHE CK_ACTION_ LANG_FILE_ AFTER] = d ate($dateF ormat, $ar rAction['A llowedPeri odEnd']);   498           $a rrLangFile Params[CHE CK_ACTION_ LANG_FILE_ AFTER] = d ate($dateF ormat, $ar rAction['A llowedPeri odEnd']);
489     499  
490           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_N OT_ALLOWED _AFTER;   500           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_N OT_ALLOWED _AFTER;
491           $r esult[CHEC K_ACTION_M ESSAGE] =  _t_ext(CHE CK_ACTION_ MESSAGE_NO T_ALLOWED_ AFTER, $ar rLangFileP arams);   501           $r esult[CHEC K_ACTION_M ESSAGE] =  _t_ext(CHE CK_ACTION_ MESSAGE_NO T_ALLOWED_ AFTER, $ar rLangFileP arams);
492     502  
493           re turn $resu lt;   503           re turn $resu lt;
494       }   504       }
495     505  
496       //if n on-member,  allow act ion withou t performi ng further  checks   506       //if n on-member,  allow act ion withou t performi ng further  checks
497     507  
498       if ($a rrMembersh ip['ID'] = = MEMBERSH IP_ID_NON_ MEMBER)   508       if ($a rrMembersh ip['ID'] = = MEMBERSH IP_ID_NON_ MEMBER)
499       {   509       {
500           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_A LLOWED;   510           $r esult[CHEC K_ACTION_R ESULT] = C HECK_ACTIO N_RESULT_A LLOWED;
501           re turn $resu lt;   511           re turn $resu lt;
502       }   512       }
503     513  
504       //chec k other li mitations  (for membe rs only)   514       //chec k other li mitations  (for membe rs only)
505     515  
506       $allow edCnt = (i nt)$arrAct ion['Allow edCount'];       //nu mber of al lowed acti ons   516       $allow edCnt = (i nt)$arrAct ion['Allow edCount'];       //nu mber of al lowed acti ons
507                                                                //if  not speci fied or 0,  number of   517                                                                //if  not speci fied or 0,  number of
508                                                                //ac tions is u nlimited   518                                                                //ac tions is u nlimited
509     519  
510       $perio dLen = (in t)$arrActi on['Allowe dPeriodLen '];   //pe riod for A llowedCoun t in hours   520       $perio dLen = (in t)$arrActi on['Allowe dPeriodLen '];   //pe riod for A llowedCoun t in hours
511                                                                //if  not speci fied, Allo wedCount i s   521                                                                //if  not speci fied, Allo wedCount i s
512                                                                //tr eated as t otal numbe r of actio ns   522                                                                //tr eated as t otal numbe r of actio ns
513                                                                //pe rmitted   523                                                                //pe rmitted
514     524  
515       //numb er of acti ons is lim ited   525       //numb er of acti ons is lim ited
516     526  
517       if($al lowedCnt >  0)   527       if($al lowedCnt >  0)
518       {   528       {
519           // get curren t action i nfo for th e member   529           // get curren t action i nfo for th e member
520     530  
521           $a ctionTrack  = db_res( "SELECT Ac tionsLeft,   531           $a ctionTrack  = db_res( "SELECT Ac tionsLeft,
522                                            UN IX_TIMESTA MP(ValidSi nce) as Va lidSince   532                                            UN IX_TIMESTA MP(ValidSi nce) as Va lidSince
523                                     FROM MemA ctionsTrac k   533                                     FROM MemA ctionsTrac k
524                                     WHERE IDA ction = $a ctionID AN D IDMember  = $member ID");   534                                     WHERE IDA ction = $a ctionID AN D IDMember  = $member ID");
525     535  
526           $a ctionsLeft  = $perfor mAction ?  $allowedCn t - 1 : $a llowedCnt;   536           $a ctionsLeft  = $perfor mAction ?  $allowedCn t - 1 : $a llowedCnt;
527           $v alidSince  = time();   537           $v alidSince  = time();
528     538  
529           // member is  requesting /performin g this act ion for th e first ti me,   539           // member is  requesting /performin g this act ion for th e first ti me,
530           // and there  is no corr esponding  record in  MemActions Track tabl e   540           // and there  is no corr esponding  record in  MemActions Track tabl e
531     541  
532           if (mysql_num _rows($act ionTrack)  <= 0)   542           if (mysql_num _rows($act ionTrack)  <= 0)
533           {   543           {
534                //add ac tion to Me mActionsTr ack table   544                //add ac tion to Me mActionsTr ack table
535     545  
536                db_res("   546                db_res("
537                    INSE RT INTO Me mActionsTr ack (IDAct ion, IDMem ber, Actio nsLeft, Va lidSince)   547                    INSE RT INTO Me mActionsTr ack (IDAct ion, IDMem ber, Actio nsLeft, Va lidSince)
538                    VALU ES ($actio nID, $memb erID, $act ionsLeft,  FROM_UNIXT IME($valid Since))");   548                    VALU ES ($actio nID, $memb erID, $act ionsLeft,  FROM_UNIXT IME($valid Since))");
539     549  
540                $result[ CHECK_ACTI ON_RESULT]  = CHECK_A CTION_RESU LT_ALLOWED ;   550                $result[ CHECK_ACTI ON_RESULT]  = CHECK_A CTION_RESU LT_ALLOWED ;
541                return $ result;   551                return $ result;
542           }   552           }
543     553  
544           // action has  been requ ested/perf ormed at l east once  at this po int   554           // action has  been requ ested/perf ormed at l east once  at this po int
545           // and there  is a corre sponding r ecord in M emActionsT rack table   555           // and there  is a corre sponding r ecord in M emActionsT rack table
546     556  
547           $a ctionTrack  = mysql_f etch_assoc ($actionTr ack);   557           $a ctionTrack  = mysql_f etch_assoc ($actionTr ack);
548     558  
549           // action rec ord in Mem ActionsTra ck table i s out of d ate   559           // action rec ord in Mem ActionsTra ck table i s out of d ate
550     560  
551           $p eriodEnd =  (int)$act ionTrack[' ValidSince '] + $peri odLen * 36 00; //Vali dSince is  in seconds , PeriodLe n is in ho urs   561           $p eriodEnd =  (int)$act ionTrack[' ValidSince '] + $peri odLen * 36 00; //Vali dSince is  in seconds , PeriodLe n is in ho urs
552     562  
553           if ($periodLe n > 0 && $ periodEnd  < time())   563           if ($periodLe n > 0 && $ periodEnd  < time())
554           {   564           {
555                db_res("   565                db_res("
556                    UPDA TE  MemAct ionsTrack   566                    UPDA TE  MemAct ionsTrack
557                    SET      Action sLeft = $a ctionsLeft , ValidSin ce = FROM_ UNIXTIME($ validSince )   567                    SET      Action sLeft = $a ctionsLeft , ValidSin ce = FROM_ UNIXTIME($ validSince )
558                    WHER E   IDActi on = $acti onID AND I DMember =  $memberID" );   568                    WHER E   IDActi on = $acti onID AND I DMember =  $memberID" );
559     569  
560                $result[ CHECK_ACTI ON_RESULT]  = CHECK_A CTION_RESU LT_ALLOWED ;   570                $result[ CHECK_ACTI ON_RESULT]  = CHECK_A CTION_RESU LT_ALLOWED ;
561                return $ result;   571                return $ result;
562           }   572           }
563     573  
564           // action rec ord is up  to date   574           // action rec ord is up  to date
565     575  
566           $a ctionsLeft  = (int)$a ctionTrack ['ActionsL eft'];   576           $a ctionsLeft  = (int)$a ctionTrack ['ActionsL eft'];
567     577  
568           // action lim it reached  for now   578           // action lim it reached  for now
569     579  
570           if ($actionsL eft <= 0 )   580           if ($actionsL eft <= 0 )
571           {   581           {
572                $arrLang FileParams [CHECK_ACT ION_LANG_F ILE_LIMIT]  = $allowe dCnt;   582                $arrLang FileParams [CHECK_ACT ION_LANG_F ILE_LIMIT]  = $allowe dCnt;
573                $arrLang FileParams [CHECK_ACT ION_LANG_F ILE_PERIOD ] = $perio dLen;   583                $arrLang FileParams [CHECK_ACT ION_LANG_F ILE_PERIOD ] = $perio dLen;
574     584  
575                $result[ CHECK_ACTI ON_RESULT]  = CHECK_A CTION_RESU LT_LIMIT_R EACHED;   585                $result[ CHECK_ACTI ON_RESULT]  = CHECK_A CTION_RESU LT_LIMIT_R EACHED;
576                $result[ CHECK_ACTI ON_MESSAGE ] = '<div  style="wid th: 80%">'  .   586                $result[ CHECK_ACTI ON_MESSAGE ] = '<div  style="wid th: 80%">'  .
577                    _t_e xt(CHECK_A CTION_MESS AGE_LIMIT_ REACHED, $ arrLangFil eParams) .   587                    _t_e xt(CHECK_A CTION_MESS AGE_LIMIT_ REACHED, $ arrLangFil eParams) .
578                    ($pe riodLen >  0 ? _t_ext (CHECK_ACT ION_MESSAG E_MESSAGE_ EVERY_PERI OD, $arrLa ngFilePara ms) : '')  .   588                    ($pe riodLen >  0 ? _t_ext (CHECK_ACT ION_MESSAG E_MESSAGE_ EVERY_PERI OD, $arrLa ngFilePara ms) : '')  .
579                    '.</ div>';   589                    '.</ div>';
580     590  
581                return $ result;   591                return $ result;
582           }   592           }
583     593  
584           if ($performA ction)   594           if ($performA ction)
585           {   595           {
586                $actions Left--;   596                $actions Left--;
587     597  
588                db_res("   598                db_res("
589                    UPDA TE MemActi onsTrack   599                    UPDA TE MemActi onsTrack
590                    SET  ActionsLef t = $actio nsLeft   600                    SET  ActionsLef t = $actio nsLeft
591                    WHER E IDAction  = $action ID AND IDM ember = $m emberID");   601                    WHER E IDAction  = $action ID AND IDM ember = $m emberID");
592           }   602           }
593       }   603       }
594     604  
595       $resul t[CHECK_AC TION_RESUL T] = CHECK _ACTION_RE SULT_ALLOW ED;   605       $resul t[CHECK_AC TION_RESUL T] = CHECK _ACTION_RE SULT_ALLOW ED;
596       return  $result;   606       return  $result;
597   }   607   }
598     608  
599   /**   609   /**
600    * Buy a m embership  for a memb er   610    * Buy a m embership  for a memb er
601    *   611    *
602    * @param  int $membe rID          - member  that is g oing to ge t the memb ership   612    * @param  int $membe rID          - member  that is g oing to ge t the memb ership
603    * @param  int $membe rshipID      - bought  membershi p   613    * @param  int $membe rshipID      - bought  membershi p
604    * @param  float $pri ce           - one of  the prici ng options  for the g iven membe rship   614    * @param  float $pri ce           - one of  the prici ng options  for the g iven membe rship
605    * @param  int $trans actionID     - intern al key of  the transa ction (ID  from Trans actions ta ble)   615    * @param  int $trans actionID     - intern al key of  the transa ction (ID  from Trans actions ta ble)
606    * @param  boolean $s tartsNow     - if tru e, the mem bership wi ll start i mmediately ;   616    * @param  boolean $s tartsNow     - if tru e, the mem bership wi ll start i mmediately ;
607    *                                   if fal se, the me mbership w ill start  after the  current   617    *                                   if fal se, the me mbership w ill start  after the  current
608    *                                   member ship expir es   618    *                                   member ship expir es
609    *   619    *
610    * @return  boolean                - true i n case of  success, f alse in ca se of fail ure   620    * @return  boolean                - true i n case of  success, f alse in ca se of fail ure
611    *   621    *
612    *   622    *
613    */   623    */
614   function b uyMembersh ip($member ID, $membe rshipID, $ price, $tr ansactionI D, $starts Now=false)   624   function b uyMembersh ip($member ID, $membe rshipID, $ price, $tr ansactionI D, $starts Now=false)
615   {   625   {
616       //inpu t validati on   626       //inpu t validati on
617     627  
618       $membe rID = (int )$memberID ;   628       $membe rID = (int )$memberID ;
619       $membe rshipID =  (int)$memb ershipID;   629       $membe rshipID =  (int)$memb ershipID;
620       $price  = (float) $price;   630       $price  = (float) $price;
621       $trans actionID =  (int)$tra nsactionID ;   631       $trans actionID =  (int)$tra nsactionID ;
622     632  
623       //chec k for pred efined non -purchasab le members hips   633       //chec k for pred efined non -purchasab le members hips
624     634  
625       if( $m embershipI D == MEMBE RSHIP_ID_N ON_MEMBER  ||   635       if( $m embershipI D == MEMBE RSHIP_ID_N ON_MEMBER  ||
626           $m embershipI D == MEMBE RSHIP_ID_S TANDARD ||   636           $m embershipI D == MEMBE RSHIP_ID_S TANDARD ||
627           $m embershipI D == MEMBE RSHIP_ID_P ROMOTION)   637           $m embershipI D == MEMBE RSHIP_ID_P ROMOTION)
628       {   638       {
629           re turn false ;   639           re turn false ;
630       }   640       }
631     641  
632       //chec k if membe rship is a ctive and  purchasabl e   642       //chec k if membe rship is a ctive and  purchasabl e
633     643  
634       $resMe mLevels =  db_res("SE LECT Activ e, Purchas able FROM  MemLevels  WHERE ID =  $membersh ipID");   644       $resMe mLevels =  db_res("SE LECT Activ e, Purchas able FROM  MemLevels  WHERE ID =  $membersh ipID");
635     645  
636       if(mys ql_num_row s($resMemL evels) <=  0) return  false;     //membersh ip not fou nd   646       if(mys ql_num_row s($resMemL evels) <=  0) return  false;     //membersh ip not fou nd
637     647  
638       $arrMe mbership =  mysql_fet ch_assoc($ resMemLeve ls);   648       $arrMe mbership =  mysql_fet ch_assoc($ resMemLeve ls);
639     649  
640       $membe rshipActiv e = $arrMe mbership[' Active'] = = 'yes' ?  true : fal se;   650       $membe rshipActiv e = $arrMe mbership[' Active'] = = 'yes' ?  true : fal se;
641       $membe rshipPurch asable = $ arrMembers hip['Purch asable'] = = 'yes' ?  true : fal se;   651       $membe rshipPurch asable = $ arrMembers hip['Purch asable'] = = 'yes' ?  true : fal se;
642     652  
643       if(!$m embershipA ctive || ! $membershi pPurchasab le) return  false;   653       if(!$m embershipA ctive || ! $membershi pPurchasab le) return  false;
644     654  
645       //chec k if the g iven prici ng option  is valid f or the giv en members hip   655       //chec k if the g iven prici ng option  is valid f or the giv en members hip
646     656  
647       $membe rshipPrice s = getMem bershipPri ces($membe rshipID);   657       $membe rshipPrice s = getMem bershipPri ces($membe rshipID);
648     658  
649       if(cou nt($member shipPrices ) <= 0) re turn false ;   659       if(cou nt($member shipPrices ) <= 0) re turn false ;
650     660  
651       $prici ngOptionEx ists = fal se;   661       $prici ngOptionEx ists = fal se;
652     662  
653       foreac h($members hipPrices  as $daysOp tion => $p riceOption )   663       foreac h($members hipPrices  as $daysOp tion => $p riceOption )
654       {   664       {
655           if ($priceOpt ion == $pr ice)   665           if ($priceOpt ion == $pr ice)
656           {   666           {
657                $pricing OptionExis ts = true;   667                $pricing OptionExis ts = true;
658                break;   668                break;
659           }   669           }
660       }   670       }
661     671  
662       if(!$p ricingOpti onExists)  return fal se;   672       if(!$p ricingOpti onExists)  return fal se;
663     673  
664       return  setMember ship($memb erID, $mem bershipID,  $daysOpti on, $start sNow, $tra nsactionID );   674       return  setMember ship($memb erID, $mem bershipID,  $daysOpti on, $start sNow, $tra nsactionID );
665   }   675   }
666     676  
667   /**   677   /**
668    * Set a m embership  for a memb er   678    * Set a m embership  for a memb er
669    *   679    *
670    * @param  int $membe rID          - member  that is g oing to ge t the memb ership   680    * @param  int $membe rID          - member  that is g oing to ge t the memb ership
671    * @param  int $membe rshipID      - member ship that  is going t o be assig ned to the  member   681    * @param  int $membe rshipID      - member ship that  is going t o be assig ned to the  member
672    *                                   if $me mbershipID  == MEMBER SHIP_ID_ST ANDARD the n $days   682    *                                   if $me mbershipID  == MEMBER SHIP_ID_ST ANDARD the n $days
673    *                                   and $s tartsNow p arameters  are not us ed, so Sta ndard   683    *                                   and $s tartsNow p arameters  are not us ed, so Sta ndard
674    *                                   member ship is al ways set i mmediately  and `fore ver`   684    *                                   member ship is al ways set i mmediately  and `fore ver`
675    *   685    *
676    * @param  int $days               - number  of days t o set memb ership for   686    * @param  int $days               - number  of days t o set memb ership for
677    *                                   if 0,  then the m embership  is set for ever   687    *                                   if 0,  then the m embership  is set for ever
678    *   688    *
679    * @param  boolean $s tartsNow     - if tru e, the mem bership wi ll start i mmediately ;   689    * @param  boolean $s tartsNow     - if tru e, the mem bership wi ll start i mmediately ;
680    *                                   if fal se, the me mbership w ill start  after the  current   690    *                                   if fal se, the me mbership w ill start  after the  current
681    *                                   member ship expir es   691    *                                   member ship expir es
682    *   692    *
683    * @return  boolean                - true i n case of  success, f alse in ca se of fail ure   693    * @return  boolean                - true i n case of  success, f alse in ca se of fail ure
684    *   694    *
685    *   695    *
686    */   696    */
687   function s etMembersh ip($member ID, $membe rshipID, $ days = 0,  $startsNow  = false,  $transacti onID = 0)   697   function s etMembersh ip($member ID, $membe rshipID, $ days = 0,  $startsNow  = false,  $transacti onID = 0)
688   {   698   {
689       $membe rID = (int )$memberID ;   699       $membe rID = (int )$memberID ;
690       $membe rshipID =  (int)$memb ershipID;   700       $membe rshipID =  (int)$memb ershipID;
691       $days  = (int)$da ys;   701       $days  = (int)$da ys;
692       $start sNow = $st artsNow ?  true : fal se;   702       $start sNow = $st artsNow ?  true : fal se;
693       $SECON DS_IN_DAY  = 86400;   703       $SECON DS_IN_DAY  = 86400;
694     704  
695       $trans actionID =  (int)$tra nsactionID ;   705       $trans actionID =  (int)$tra nsactionID ;
696       if($tr ansactionI D <= 0) $t ransaction ID = 'NULL ';   706       if($tr ansactionI D <= 0) $t ransaction ID = 'NULL ';
697     707  
698       //chec k if membe r exists   708       //chec k if membe r exists
699       $res =  db_res("S ELECT COUN T(ID) FROM  Profiles  WHERE ID =  $memberID ");   709       $res =  db_res("S ELECT COUN T(ID) FROM  Profiles  WHERE ID =  $memberID ");
700       $res =  mysql_fet ch_row($re s);   710       $res =  mysql_fet ch_row($re s);
701       if($re s[0]!=1) r eturn fals e;   711       if($re s[0]!=1) r eturn fals e;
702     712  
703       //chec k if membe rship exis ts   713       //chec k if membe rship exis ts
704       $res =  db_res("S ELECT COUN T(ID) FROM  MemLevels  WHERE ID  = $members hipID");   714       $res =  db_res("S ELECT COUN T(ID) FROM  MemLevels  WHERE ID  = $members hipID");
705       $res =  mysql_fet ch_row($re s);   715       $res =  mysql_fet ch_row($re s);
706       if($re s[0]!=1) r eturn fals e;   716       if($re s[0]!=1) r eturn fals e;
707     717  
708       if($me mbershipID  == MEMBER SHIP_ID_NO N_MEMBER)  return fal se;   718       if($me mbershipID  == MEMBER SHIP_ID_NO N_MEMBER)  return fal se;
709     719  
710       $curre ntMembersh ip = getMe mberMember shipInfo($ memberID);   720       $curre ntMembersh ip = getMe mberMember shipInfo($ memberID);
711       $lates tMembershi p = getMem berMembers hipInfo_la test($memb erID);   721       $lates tMembershi p = getMem berMembers hipInfo_la test($memb erID);
712     722  
713       if($me mbershipID  == MEMBER SHIP_ID_ST ANDARD)   723       if($me mbershipID  == MEMBER SHIP_ID_ST ANDARD)
714       {   724       {
715           // return if  already St andard   725           // return if  already St andard
716     726  
717           if ($currentM embership[ 'ID'] == M EMBERSHIP_ ID_STANDAR D) return  true;   727           if ($currentM embership[ 'ID'] == M EMBERSHIP_ ID_STANDAR D) return  true;
718     728  
719           // delete any  present a nd future  membership s   729           // delete any  present a nd future  membership s
720     730  
721           db _res("   731           db _res("
722                DELETE   FROM Profi leMemLevel s   732                DELETE   FROM Profi leMemLevel s
723                WHERE    IDMember =  $memberID   733                WHERE    IDMember =  $memberID
724                         AND (DateE xpires IS  NULL OR Da teExpires  > NOW())") ;   734                         AND (DateE xpires IS  NULL OR Da teExpires  > NOW())") ;
725     735  
726           if (mysql_aff ected_rows () > 0)   736           if (mysql_aff ected_rows () > 0)
727           {   737           {
728                return t rue;   738                return t rue;
729           }   739           }
730           el se   740           el se
731           {   741           {
732                return f alse;   742                return f alse;
733           }   743           }
734       }   744       }
735     745  
736       if($da ys < 0) re turn false ;   746       if($da ys < 0) re turn false ;
737     747  
738       $dateS tarts = ti me();   748       $dateS tarts = ti me();
739     749  
740       if(!$s tartsNow)   750       if(!$s tartsNow)
741       {   751       {
742           // make the m embership  start afte r the curr ent member ship expir es   752           // make the m embership  start afte r the curr ent member ship expir es
743     753  
744           if (!is_null( $latestMem bership['D ateExpires ']))   754           if (!is_null( $latestMem bership['D ateExpires ']))
745           {   755           {
746                $dateSta rts = $lat estMembers hip['DateE xpires'];   756                $dateSta rts = $lat estMembers hip['DateE xpires'];
747     757  
748                // if me mbership a lready exi sts then i t's unlimi ted - just  shift or  delete it   758                // if me mbership a lready exi sts then i t's unlimi ted - just  shift or  delete it
749                $res = d b_res("   759                $res = d b_res("
750                    SELE CT  IDMemb er   760                    SELE CT  IDMemb er
751                    FROM     Profil eMemLevels   761                    FROM     Profil eMemLevels
752                    WHER E   IDMemb er = $memb erID   762                    WHER E   IDMemb er = $memb erID
753                             AND UN IX_TIMESTA MP(DateSta rts) = $da teStarts   763                             AND UN IX_TIMESTA MP(DateSta rts) = $da teStarts
754                             AND ID Level = $m embershipI D");   764                             AND ID Level = $m embershipI D");
755                $res = m ysql_fetch _row($res) ;   765                $res = m ysql_fetch _row($res) ;
756                if($res[ 0])   766                if($res[ 0])
757                {   767                {
758                    if($ days == 0)   768                    if($ days == 0)
759                    {   769                    {
760                         db_res("DE LETE  FROM  ProfileMe mLevels   770                         db_res("DE LETE  FROM  ProfileMe mLevels
761                                 WH ERE   IDMe mber = $me mberID   771                                 WH ERE   IDMe mber = $me mberID
762                                          AND  UNIX_TIMES TAMP(DateS tarts) = $ dateStarts   772                                          AND  UNIX_TIMES TAMP(DateS tarts) = $ dateStarts
763                                          AND  IDLevel =  $membershi pID");   773                                          AND  IDLevel =  $membershi pID");
764                    }   774                    }
765                    else   775                    else
766                    {   776                    {
767                         db_res("UP DATE  Prof ileMemLeve ls   777                         db_res("UP DATE  Prof ileMemLeve ls
768                                 SE T     Date Starts = F ROM_UNIXTI ME(". ((in t)$dateSta rts + $day s * $SECON DS_IN_DAY)  .")   778                                 SE T     Date Starts = F ROM_UNIXTI ME(". ((in t)$dateSta rts + $day s * $SECON DS_IN_DAY)  .")
769                                 WH ERE   IDMe mber = $me mberID   779                                 WH ERE   IDMe mber = $me mberID
770                                          AND  UNIX_TIMES TAMP(DateS tarts) = $ dateStarts   780                                          AND  UNIX_TIMES TAMP(DateS tarts) = $ dateStarts
771                                          AND  IDLevel =  $membershi pID");   781                                          AND  IDLevel =  $membershi pID");
772                    }   782                    }
773                }   783                }
774           }   784           }
775       }   785       }
776     786  
777       if($da ys == 0)   787       if($da ys == 0)
778       {   788       {
779           // if days==0  then set  the member ship forev er   789           // if days==0  then set  the member ship forev er
780           $d ateExpires  = 'NULL';   790           $d ateExpires  = 'NULL';
781       }   791       }
782       else   792       else
783       {   793       {
784           $d ateExpires  = (int)$d ateStarts  + $days *  $SECONDS_I N_DAY;   794           $d ateExpires  = (int)$d ateStarts  + $days *  $SECONDS_I N_DAY;
785       }   795       }
786     796  
787       //inse rt corresp onding rec ord into P rofileMemL evels   797       //inse rt corresp onding rec ord into P rofileMemL evels
788     798  
789       db_res ("   799       db_res ("
790           IN SERT Profi leMemLevel s (IDMembe r, IDLevel , DateStar ts, DateEx pires, Tra nsactionID )   800           IN SERT Profi leMemLevel s (IDMembe r, IDLevel , DateStar ts, DateEx pires, Tra nsactionID )
791           VA LUES ($mem berID, $me mbershipID , FROM_UNI XTIME($dat eStarts),  FROM_UNIXT IME($dateE xpires), $ transactio nID)");   801           VA LUES ($mem berID, $me mbershipID , FROM_UNI XTIME($dat eStarts),  FROM_UNIXT IME($dateE xpires), $ transactio nID)");
792     802  
793       if(mys ql_affecte d_rows() < = 0) retur n false;   803       if(mys ql_affecte d_rows() < = 0) retur n false;
794     804  
795       return  true;   805       return  true;
796   }   806   }
797     807  
798   /**   808   /**
799    * Get the  list of e xisting me mberships   809    * Get the  list of e xisting me mberships
800    *   810    *
801    * @param  bool $purc hasableOnl y - if tru e, fetches  only purc hasable me mberships;   811    * @param  bool $purc hasableOnl y - if tru e, fetches  only purc hasable me mberships;
802    *                                   'purch asable' he re means t hat:   812    *                                   'purch asable' he re means t hat:
803    *                                   1. Mem Levels.Pur chasable =  'yes'   813    *                                   1. Mem Levels.Pur chasable =  'yes'
804    *                                   2. Mem Levels.Act ive = 'yes '   814    *                                   2. Mem Levels.Act ive = 'yes '
805    *                                   3. the re is at l east one p ricing opt ion for th e membersh ip   815    *                                   3. the re is at l east one p ricing opt ion for th e membersh ip
806    *   816    *
807    * @return  array( me mbershipID _1 => memb ershipName _1,  membe rshipID_2  => members hipName_2,  ...) - if  no such m emberships , then jus t array()   817    * @return  array( me mbershipID _1 => memb ershipName _1,  membe rshipID_2  => members hipName_2,  ...) - if  no such m emberships , then jus t array()
808    *   818    *
809    *   819    *
810    */   820    */
811   function g etMembersh ips($purch asableOnly  = false)   821   function g etMembersh ips($purch asableOnly  = false)
812   {   822   {
813       $resul t = array( );   823       $resul t = array( );
814     824  
815       $query Purchasabl e = '';   825       $query Purchasabl e = '';
816     826  
817       if($pu rchasableO nly)   827       if($pu rchasableO nly)
818       {   828       {
819           $q ueryPurcha sable = "I NNER JOIN  MemLevelPr ices ON Me mLevelPric es.IDLevel  = MemLeve ls.ID WHER E Purchasa ble = 'yes ' AND Acti ve = 'yes' ";   829           $q ueryPurcha sable = "I NNER JOIN  MemLevelPr ices ON Me mLevelPric es.IDLevel  = MemLeve ls.ID WHER E Purchasa ble = 'yes ' AND Acti ve = 'yes' ";
820       }   830       }
821     831  
822       $resMe mLevels =  db_res("SE LECT DISTI NCT ID, Na me FROM Me mLevels $q ueryPurcha sable");   832       $resMe mLevels =  db_res("SE LECT DISTI NCT ID, Na me FROM Me mLevels $q ueryPurcha sable");
823     833  
824       while( list($id,  $name) = m ysql_fetch _row($resM emLevels))   834       while( list($id,  $name) = m ysql_fetch _row($resM emLevels))
825       {   835       {
826           $r esult[(int )$id] = $n ame;   836           $r esult[(int )$id] = $n ame;
827       }   837       }
828     838  
829       return  $result;   839       return  $result;
830   }   840   }
831     841  
832   /**   842   /**
833    * Get pri cing optio ns for the  given mem bership   843    * Get pri cing optio ns for the  given mem bership
834    *   844    *
835    * @param  int $membe rshipID -  membership  to get pr ices for   845    * @param  int $membe rshipID -  membership  to get pr ices for
836    *   846    *
837    * @return  array( da ys1 => pri ce1, days2  => price2 , ...) - i f no price s set, the n just arr ay()   847    * @return  array( da ys1 => pri ce1, days2  => price2 , ...) - i f no price s set, the n just arr ay()
838    *   848    *
839    *   849    *
840    */   850    */
841   function g etMembersh ipPrices($ membership ID)   851   function g etMembersh ipPrices($ membership ID)
842   {   852   {
843       $membe rshipID =  (int)$memb ershipID;   853       $membe rshipID =  (int)$memb ershipID;
844       $resul t = array( );   854       $resul t = array( );
845     855  
846       $resMe mLevelPric es = db_re s("SELECT  Days, Pric e FROM Mem LevelPrice s WHERE ID Level = $m embershipI D ORDER BY  Days ASC" );   856       $resMe mLevelPric es = db_re s("SELECT  Days, Pric e FROM Mem LevelPrice s WHERE ID Level = $m embershipI D ORDER BY  Days ASC" );
847     857  
848       while( list($days , $price)  = mysql_fe tch_row($r esMemLevel Prices))   858       while( list($days , $price)  = mysql_fe tch_row($r esMemLevel Prices))
849       {   859       {
850           $r esult[(int )$days] =  (float)$pr ice;   860           $r esult[(int )$days] =  (float)$pr ice;
851       }   861       }
852     862  
853       return  $result;   863       return  $result;
854   }   864   }
855     865  
856   /**   866   /**
857    * Get inf o about a  given memb ership   867    * Get inf o about a  given memb ership
858    *   868    *
859    * @param  int $membe rshipID -  membership  to get in fo about   869    * @param  int $membe rshipID -  membership  to get in fo about
860    *   870    *
861    * @return  array(    'Name' =>  name,   871    * @return  array(    'Name' =>  name,
862    *                    'Active' = > active,   872    *                    'Active' = > active,
863    *                    'Purchasab le' => pur chasable,   873    *                    'Purchasab le' => pur chasable,
864    *                    'Removable ' => remov able)   874    *                    'Removable ' => remov able)
865    *   875    *
866    *   876    *
867    */   877    */
868   function g etMembersh ipInfo($me mbershipID )   878   function g etMembersh ipInfo($me mbershipID )
869   {   879   {
870       $membe rshipID =  (int)$memb ershipID;   880       $membe rshipID =  (int)$memb ershipID;
871       $resul t = array( );   881       $resul t = array( );
872     882  
873       $resMe mLevels =  db_res("SE LECT Name,  Active, P urchasable , Removabl e FROM Mem Levels WHE RE ID = $m embershipI D");   883       $resMe mLevels =  db_res("SE LECT Name,  Active, P urchasable , Removabl e FROM Mem Levels WHE RE ID = $m embershipI D");
874     884  
875       if(mys ql_num_row s($resMemL evels) > 0 )   885       if(mys ql_num_row s($resMemL evels) > 0 )
876       {   886       {
877           $r esult = my sql_fetch_ assoc($res MemLevels) ;   887           $r esult = my sql_fetch_ assoc($res MemLevels) ;
878       }   888       }
879     889  
880       return  $result;   890       return  $result;
881   }   891   }
882   ?>   892   ?>