HomeHelpTrac

source: tags/6.1/membership.php @ 10242

Revision 10242, 9.0 KB checked in by Alexander Trofimov, 3 years ago (diff)

dolphin 6.1.5, initial commit

Line 
1<?
2
3/***************************************************************************
4*                            Dolphin Smart Community Builder
5*                              -----------------
6*     begin                : Mon Mar 23 2006
7*     copyright            : (C) 2006 BoonEx Group
8*     website              : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21require_once( 'inc/header.inc.php' );
22require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
23require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
24require_once( BX_DIRECTORY_PATH_INC . 'checkout.inc.php' );
25
26// --------------- page variables and login
27
28$_page['name_index'] = 10;
29$_page['css_name'] = 'membership.css';
30
31$logged['member'] = member_auth( 0 );
32
33$_page['header'] = _t( "_MEMBERSHIP_H" );
34$_page['header_text'] = _t( "_MEMBERSHIP_H1" );
35
36// free mode enabled then don't show anything
37if ( getParam('free_mode') == 'on' )
38{
39    $_page['name_index'] = 0;
40    $_page_cont[0]['page_main_code'] = '';
41    PageCode();
42    exit();
43}
44
45// --------------- GET/POST actions
46
47$subscriptionStatus = '';
48if ( isset($_REQUEST['action']) )
49{
50    switch ( $_REQUEST['action'] )
51    {
52        case 'cancel_subscription':
53            $transactionID = (int)$_REQUEST['tran_id'];
54            $subscriptionArr = db_arr( "SELECT `PaymentSubscriptions`.`TransactionID`, DATE_FORMAT(`PaymentSubscriptions`.`StartDate`,  '$date_format' ) AS StartDate, `PaymentSubscriptions`.`Period`, `Transactions`.`Description`, `PaymentProviders`.`Caption` AS `ProviderCaption` FROM `PaymentSubscriptions`
55                                            LEFT JOIN `Transactions` ON `PaymentSubscriptions`.`TransactionID` = `Transactions`.`ID`
56                                            LEFT JOIN `PaymentProviders` ON `Transactions`.`IDProvider` = `PaymentProviders`.`ID`
57                                            WHERE `PaymentSubscriptions`.`TransactionID` = {$transactionID}" );
58
59            if ( $subscriptionArr )
60            {
61                $recipient = $site['email'];
62                $subject = 'Unsubscription request';
63
64                $message = <<<EOM
65Dear Admin, please unsubscribe me from recurring payments.
66Below my subscription information:
67    Subscription date: {$subscriptionArr['StartDate']}
68    Payment provider: {$subscriptionArr['ProviderCaption']}
69    Subscription period: {$subscriptionArr['Period']}
70    Payment description: {$subscriptionArr['Description']}
71EOM;
72                $res = sendMail( $recipient, $subject, $message );
73            }
74            else
75            {
76                $res = false;
77            }
78
79            $subscriptionStatus = $res ? _t('_Subscription cancellation request was successfully sent') : _t('_Fail to sent subscription cancellation request');
80            break;
81    }
82}
83
84// --------------- [ END ] GET/POST actions
85
86// --------------- page components
87
88$_ni = $_page['name_index'];
89
90// NOTE: $memberID is defined in checkout.inc.php file
91$_page_cont[$_ni]['status'] = PageCompStatus( $memberID );
92$_page_cont[$_ni]['subscriptions'] =  ( $enable_recurring ? PageCompSubscriptions( $memberID, $subscriptionStatus ) : '' );
93$_page_cont[$_ni]['memberships'] = PageCompMemberships();
94
95// --------------- [END] page components
96
97PageCode();
98
99// --------------- page components functions
100
101/**
102 * membership status
103 */
104function PageCompStatus( $memberID )
105{
106    global $site;
107    global $oTemplConfig;
108
109    $ret = '';
110
111    if ( isset( $_REQUEST['result'] ) )
112    {
113        $resultMessage = '';
114        switch( $_REQUEST['result'] )
115        {
116            case '1000':
117                $resultMessage = _t( '_RESULT1000' );
118                break;
119            case '0':
120                $resultMessage = _t( '_RESULT0' );
121                break;
122            case '-1':
123                $resultMessage = _t( '_RESULT-1' );
124                break;
125            case '1':
126                $resultMessage = _t( '_RESULT1_THANK', $site['title'] );
127                break;
128        }
129        if ( strlen($resultMessage) )
130            $ret .= "<div class=\"result_message\">{$resultMessage}</div>\n";
131    }
132
133    $ret .= GetMembershipStatus($memberID, false);
134
135    $ret = "<div class=\"status_box\">\n{$ret}\n</div>\n";
136
137    return DesignBoxContent( _t("_Membership Status"), $ret, $oTemplConfig -> PageCompStatus_db_num );
138}
139
140/**
141 * payment subscriptions
142 */
143function PageCompSubscriptions( $memberID, $statusMessage )
144{
145    global $oTemplConfig;
146    global $date_format;
147    ob_start();
148
149    $subscriptionsRes = db_res( "SELECT `PaymentSubscriptions`.`TransactionID`, DATE_FORMAT(`PaymentSubscriptions`.`StartDate`, '$date_format' ) AS StartDate, `PaymentSubscriptions`.`Period`, `PaymentSubscriptions`.`ChargesNumber`, `Transactions`.`Description` FROM `PaymentSubscriptions`
150                                    LEFT JOIN `Transactions` ON `PaymentSubscriptions`.`TransactionID` = `Transactions`.`ID`
151                                    WHERE `Transactions`.`IDMember` = {$memberID}
152                                        AND `Transactions`.`Status` = 'declined'" );
153    $daysLangString = _t('_days');
154    $cancelLangString = _t('_Cancel');
155?>
156<div class="subscriptions_box">
157<?
158    if ( strlen($statusMessage) )
159        echo "<div class=\"result_message\">{$statusMessage}</div>\n";
160?>
161<form id="cancelSubscriptionForm" action="<?= $_SERVER['PHP_SELF'] ?>" method="post" style="margin: 0px;">
162    <input type="hidden" name="action" value="cancel_subscription" />
163    <input type="hidden" name="tran_id" id="cancel_transaction_id" value="0" />
164</form>
165<script type="text/javascript">
166<!--
167    function sendCancelForm( tranID )
168    {
169        document.getElementById('cancel_transaction_id').value = tranID;
170        document.forms['cancelSubscriptionForm'].submit();
171    }
172-->
173</script>
174<table cellpadding="4" cellspacing="0" border="0" width="100%">
175    <tr class="subscriptions_row_header">
176        <td align="left" width="110"><?= _t('_Start date') ?></td>
177        <td align="left"><?= _t('_Payment description') ?></td>
178        <td align="right" width="40"><?= _t('_Period') ?></td>
179        <td align="right" width="95"><?= _t('_Charges number') ?></td>
180        <td align="right" width="40">&nbsp;</td>
181    </tr>
182<?
183    while ( $subscriptionArr = mysql_fetch_assoc($subscriptionsRes) )
184    {
185?>
186    <tr class="subscriptions_row">
187        <td align="left" width="110"><?= $subscriptionArr['StartDate'] ?></td>
188        <td align="left"><?= process_line_output($subscriptionArr['Description']) ?></td>
189        <td align="right"><?= $subscriptionArr['Period'] . $daysLangString ?></td>
190        <td align="right"><?= $subscriptionArr['ChargesNumber'] ?></td>
191        <td align="right" width="40"><a href="javascript:void(0);" onclick="javascript: sendCancelForm(<?= $subscriptionArr['TransactionID'] ?>); return false;"><?= $cancelLangString ?></a></td>
192    </tr>
193<?
194    }
195?>
196</table>
197</div>
198<?
199
200    $ret = ob_get_contents();
201    ob_end_clean();
202
203    return DesignBoxContent( _t('_Subscriptions'), $ret, $oTemplConfig -> PageCompSubscriptions_db_num );
204}
205
206/**
207 * purchase memberships
208 */
209function PageCompMemberships()
210{
211    global $site;
212    global $doll;
213    global $oTemplConfig;
214
215    $expl_win_h = 400; //not global
216
217    $purchasableOnly = true;
218    $purchasableMemberships = getMemberships($purchasableOnly);
219
220    $ret = '';
221
222    foreach ($purchasableMemberships as $ID => $name)
223    {
224        ob_start();
225?>
226<div class="membership_line">
227    <form id="membership<?= $ID ?>Form" action="<?= $site['url'] . 'checkout.php' ?>" method="post" style="margin: 2px">
228    <input type="hidden" name="action" value="calculate" />
229    <input type="hidden" name="checkout_action" value="membership" />
230    <input type="hidden" name="allow_subscribe" value="on" />
231    <input type="hidden" name="data" value="<?= $ID ?>" />
232    <table cellpadding="4" cellspacing="0" border="0" width="100%">
233        <tr>
234            <td align="left"><?= htmlspecialchars($name) ?></td>
235            <td align="right">
236                <select class="no" name="amount" style="vertical-align: middle;">
237<?
238        $prices = getMembershipPrices($ID);
239        foreach ($prices as $days => $price)
240        {
241            $optionText = $days ? $days . ' '._t('_days') : _t('_Lifetime');
242            $optionText .= ' - ' . $doll . $price;
243            echo "<option value=\"{$price}\">{$optionText}</option>\n";
244        }
245?>
246                </select>
247            </td>
248            <td align="right" width="110">
249                <input type="submit" class="no" value="<?= _t( "_Check Out" ) ?>" style="width: 100px; vertical-align: middle;" />
250            </td>
251            <td align="right" width="60">
252                <a href="javascript:void(0);" onClick="javascript: window.open('explanation.php?explain=membership&type=<?= $ID ?>', '', 'width=<?= $oTemplConfig -> popUpWindowWidth ?>,height=<?= $expl_win_h ?>,menubar=no,status=no,resizable=no,scrollbars=yes,toolbar=no, location=no' );"><?= _t("_Explanation"); ?></a>
253            </td>
254        </tr>
255    </table>
256    </form>
257</div>
258<?
259        $ret .= ob_get_contents();
260        ob_end_clean();
261    }
262
263    $ret = "<div class=\"memberships_box\">\n{$ret}\n</div>\n";
264
265    return DesignBoxContent( _t("_Membership NEW"), $ret, $oTemplConfig -> PageCompMemberships_db_num );
266}
267
268?>
Note: See TracBrowser for help on using the repository browser.