/[drupal]/contributions/modules/lm_paypal/lm_paypal_subscriptions.module
ViewVC logotype

Contents of /contributions/modules/lm_paypal/lm_paypal_subscriptions.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.33 - (show annotations) (download) (as text)
Sat Oct 11 09:05:04 2008 UTC (13 months, 2 weeks ago) by lyricnz
Branch: MAIN
CVS Tags: DRUPAL-4-7--1-0, HEAD
Branch point for: DRUPAL-4-7, DRUPAL-6--1
Changes since 1.32: +3 -3 lines
File MIME type: text/x-php
#258607 by chx, salvis, pndur etc: rename lm_paypal_subscriptions to avoid conflict with subscriptions module
1 <?php
2
3 // $Id: lm_paypal_subscriptions.module,v 1.32 2007/07/20 19:37:50 leemcl Exp $
4
5 /**
6 * @file
7 *
8 * PayPal Subscriptions interface.
9 *
10 * Lee McLoughlin <lee@lmmrtech.com>. July 2006
11 * This is a Drupal 4.7 module to handle PayPal subscriptions.
12 *
13 * It requires the lm_paypal module to be installed, enabled and configured.
14 *
15 * This module is licensed under Gnu General Public License Version 2
16 * see the LICENSE.txt file for more details.
17 */
18
19 //TODO:
20 // Admin option to add a user to a sub with an auto unsub at end of period
21 // probably best to do this with an option under edit user otherwise hard to
22 // find the user to add
23 // Add a subscr_modify based option to create buttons to extend a subscription
24 // find a way to export all subscriptions from paypal and consolidate them
25 // against those in this module
26 // change all the output blocks so they can be themed more easily
27 // go thru all the fields in the ips table and see what is actually needed
28 // On deleting a user issue a cancel on any subscriptions - can't do that from
29 // here, can only cancel on PayPal
30
31 define(LM_PAYPAL_SUBSCRIPTIONS, 'LM_PayPal_Subs');
32
33 // Don't change these here! Use the admin interface at admin/lm_paypal_subscriptions
34 define(LM_PAYPAL_SUBSCRIPTIONS_INPROGRESS_DEFAULT, '/lm_paypal/subscriptions_inprogress');
35 define(LM_PAYPAL_SUBSCRIPTIONS_MENU_REBUILD_DEFAULT, FALSE);
36
37 define(LM_PAYPAL_SUBSCRIPTIONS_UID_ADMIN_DEFAULT, 1);
38 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_ADMIN_ONSUB_DEFAULT, 1);
39 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_ADMIN_ONSUB_SUBJECT, 'New subscriber %Username to %Subscription%Node on %Site');
40 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_ADMIN_ONSUB_BODY, 'The user %Username has subscribed to %Subscription%Node on %Site on %Date');
41
42 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_ADMIN_ONEND_DEFAULT, 1);
43 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_ADMIN_ONEND_SUBJECT, 'User %Username leaves %Subscription%Node on %Site');
44 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_ADMIN_ONEND_BODY, 'The user %Username has ended their subscription to %Subscription%Node on %Site on %Date by %End');
45
46 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONSUB_DEFAULT, 0);
47 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONSUB_SUBJECT_DEFAULT, 'Welcome to %Subscription%Node');
48 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONSUB_BODY_DEFAULT, 'Hello %Username and welcome to your new subscription %Subscription%Node on %Site');
49
50 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONNEAREND_DEFAULT, 0);
51 define(LM_PAYPAL_SUBSCRIPTIONS_NEAREND_DAYS_DEFAULT, 5);
52 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONNEAREND_SUBJECT_DEFAULT, 'Your subscription %Subscription ends soon');
53 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONNEAREND_BODY_DEFAULT, 'Hello %Username your subscription to %Subscription on %Site ends in %Days days.');
54
55 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONEND_DEFAULT, 0);
56 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONEND_SUBJECT_DEFAULT, 'Goodbye from %Subscription');
57 define(LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONEND_BODY_DEFAULT, 'Hello %Username and thank you for being a subscriber to %Subscription on %Site. We hope you will join us again.');
58
59 define(LM_PAYPAL_SUBSCRIPTIONS_TERMS_DEFAULT, '');
60
61 // In theory a subscription will go:
62 // signedup, live, EOT (end of term) or cancelled
63 // however sometimes (often) a subscr_payment will arrive before a subscr_signup
64 // so then you'll get paid, live... instead
65 // If the incoming subscription details dont match those expected it will
66 // be blocked
67 // If the subscription amount is zero (probably for a trial period) then
68 // no payment will arrive
69 define(LM_PAYPAL_SUBSCRIPTIONS_STATUS_DEAD, 0);
70 define(LM_PAYPAL_SUBSCRIPTIONS_STATUS_LIVE, 1); // dont change this one!
71 define(LM_PAYPAL_SUBSCRIPTIONS_STATUS_SIGNEDUP, 2);
72 define(LM_PAYPAL_SUBSCRIPTIONS_STATUS_PAID, 3);
73 define(LM_PAYPAL_SUBSCRIPTIONS_STATUS_CANCELLED, 4);
74 define(LM_PAYPAL_SUBSCRIPTIONS_STATUS_EOT, 5);
75 define(LM_PAYPAL_SUBSCRIPTIONS_STATUS_BLOCKED, 6);
76
77 /**
78 * Initialize global variables.
79 */
80 function _lm_paypal_subscriptions_ini() {
81 _lm_paypal_ini();
82 global $_lm_paypal_subscriptions_inprogress; // page user is directed to on subscribe
83
84 // In theory this shouldn't be necessary but I've had one user require it.
85 global $_lm_paypal_subscriptions_menu_rebuild; // rebuild menu cache on role or group change
86
87 // Status of subscribers
88 global $_lm_paypal_subscriptions_stati;
89
90 static $inited = 0;
91
92 if ($inited) {
93 return;
94 }
95 $inited = 1;
96
97 $_lm_paypal_subscriptions_inprogress = variable_get('lm_paypal_subscriptions_inprogress', LM_PAYPAL_SUBSCRIPTIONS_INPROGRESS_DEFAULT);
98 $_lm_paypal_subscriptions_menu_rebuild = variable_get('lm_paypal_subscriptions_menu_rebuild', LM_PAYPAL_SUBSCRIPTIONS_MENU_REBUILD_DEFAULT);
99
100 $_lm_paypal_subscriptions_stati = array(
101 0 => t('dead'),
102 1 => t('live'),
103 2 => t('signedup'),
104 3 => t('paid'),
105 4 => t('cancelled'),
106 5 => t('eot'),
107 6 => t('blocked'),
108 );
109 }
110
111 /**
112 * Implementation of hook_help().
113 */
114 function lm_paypal_subscriptions_help($section) {
115 _lm_paypal_subscriptions_ini();
116 global $_lm_paypal_welcome; // Welcome message
117 global $_lm_paypal_drupal_major;
118 global $base_url;
119
120 $groups = l(t('create content > group'), 'node/add/og');
121 $subs = l(t('LM PayPal Subscriptions'), 'admin/lm_paypal/subscriptions');
122 if ($_lm_paypal_drupal_major > 4) {
123 // Drupal 5
124 $c = '!'; // t() has changed and to use a link in it use '!'
125 $admin = l('LM PayPal Admin', 'admin/lm_paypal/settings');
126 $roles = l(t('user management > roles'), 'admin/user/roles');
127 $access = l(t('user management > access control'), 'admin/user/access');
128 $blocks = l(t('site building > blocks'), 'admin/build/block');
129 }
130 else {
131 // Drupal 4
132 $c = '%';
133 $admin = l('LM PayPal Admin', 'admin/settings/lm_paypal');
134 $roles = l(t('access control > roles'), 'admin/access/roles');
135 $access = l(t('access control'), 'admin/access');
136 $blocks = l(t('administer blocks'), 'admin/block');
137 }
138 $help_subs = l(t('LM PayPal Subscriptions Help'), 'admin/help/lm_paypal_subscriptions');
139
140 switch ($section) {
141 // admin/help/lm_paypal_subscriptions
142 case 'admin/help#lm_paypal_subscriptions':
143 $output = $_lm_paypal_welcome;
144
145 $output .= '<p><b>'. t('Special Notes') . ':</b>';
146 $output .= '<ul>';
147 $output .= '<li><b>' . t('This module requires the module lm_paypal to be installed, enabled and configured.') . '</b></li>';
148 $output .= '<li>' . t('This module does not provide access control. The subscriptions defined here allow paid membership of a role or Organic Group only. Use this module in conjunction with an access control module such as <a href="http://drupal.org/project/taxonomy_access">Taxonomy Access Control</a> or <a href="http://drupal.org/project/premium">Premium</a> to restrict the actions of a role on your site.') . '</li>';
149 $output .= '<li>' . t('You must use the subscription buttons generated by this module. The button factory on PayPal cannot add all the information this module needs.') . '</li>';
150 $output .= '<li>' . t('Only authenticated users can take out subscriptions.') . '</li>';
151 $output .= '</ul>';
152 $output .= '</p>';
153
154 $output .= '<h2>' . t('Initial Configuration') . '</h2>';
155 $output .= '<p>' . t('If you are new to this module you need to:');
156 $output .= '<ul>';
157 $output .= '<li>' . t("Update the site specific settings via ${c}admin. Normally you only need to provide your PayPal Business Email.", array("${c}admin" => $admin)) . '</li>';
158 $output .= '<li>' . t("For role subscriptions, if not already created, use ${c}roles to create one or more additional roles to be associated with the subscriptions you are about to create.", array("${c}roles" => $roles)) .'</li>';
159 $output .= '<li>' . t("For Organic Group (OG) subscriptions, if not already created, use ${c}groups to create one or more additional groups.", array("${c}groups" => $groups)) .'</li>';
160 $output .= '<li>' . t('For role subscriptions configure your chosen access control module, for example <a href="http://drupal.org/project/taxonomy_access">Taxonomy Access Control</a> or <a href="http://drupal.org/project/premium">Premium</a>, to restrict roles as appropriate for your setup.') . '</li>';
161 $new = l(t('Create New Subscription'), 'admin/lm_paypal/subscriptions/new');
162 $output .= '<li> ' . t("Use ${c}new to create one or more subscription definitions.", array("${c}new" => $new)) .'</li>';
163 $output .= '<li>' . t("Make sure the right roles (usually just 'authenticated user') can see these subscription definitions by enabling it in ${c}access under <b>lm_paypal_module</b> 'access lm_paypal_subscribe'. ", array("${c}access" => $access));
164 $output .= t('<em>Special note:</em> If anonymous users are allowed to view the subscriptions pages then they are asked to login or register instead of subscribing. ') .'</li>';
165 $output .= '<li>' . t('Once completed the new menu item <b>PayPal Subscribe</b> will become available allowing users to select the subscriptions they wish to purchase. Users can also view their subscriptions under <b>my account</b>.') .'</li>';
166 $output .= '</ul>';
167 $output .= '</p>';
168
169 $output .= '<h2>' . t('Blocks') . '</h2>';
170 $output .= '<p>' . t("For each role or group subscription defined a subscribe block becomes automatically available. These can be configured via ${c}blocks", array("${c}blocks" => $blocks)) . '</p>';
171 $output .= '<p><b>' . t('Special note:') . '</b> ' . t('subscription blocks are only displayed to logged in users who do not already have that subscription.') . '</p>';
172
173 $output .= '<h2>' . t('Inline PHP Snippet') . '</h2>';
174 $output .= '<p>'. t("The following PHP snippet shows how to make a subscribe button appear for the subscription with a subid of 1. Admin's can find the subid via ${c}subs", array("${c}subs" => $subs)) . '</p>';
175 $output .= '<p>'. t('Note that nothing will appear if they are either not able to subscribe (not logged in) or if they have already subscribed:') .'</p>';
176 $output .= '<pre>'. t('&lt;?php
177 if (function_exists(\'lm_paypal_can_subscribe\')) {
178 $subid = 1;
179 if (lm_paypal_can_subscribe ($subid)) {
180 print \'Why not subscribe now? \' . lm_paypal_subscribe($subid,8);
181 }
182 }
183 ?&gt;') .'</pre>';
184 $output .= '<p>'. t('It is best to check that the lm_paypal_can_subscribe function exists before using it just in case the module has been disabled.') . '</p>';
185
186 $output .= '<h2>'. t('Viewing Subscriptions/Subscribers') .'</h2>';
187 $output .= '<p>'. t("To view all subscriptions and everyone who has subscribed to them use ${c}subs", array("${c}subs" => $subs)) . '</p>';
188
189 return $output;
190
191 // This is the brief description of the module displayed on the modules page
192 case 'admin/modules#description':
193 return t('Provides PayPal subscriptions to Drupal roles (requires lm_paypal).');
194
195 // This appears at the start of the module admin page
196 case 'admin/settings/lm_paypal_subscriptions':
197 // The admin page under Drupal 5
198 case 'admin/lm_paypal/subscriptions_settings':
199 // This appears at the start of the admin page
200 case 'admin/lm_paypal/subscriptions':
201 // This appears at the start of the new subscription page
202 case 'admin/lm_paypal/subscriptions/new':
203 $output = $_lm_paypal_welcome;
204
205 $output .= '<p>'. t("For detailed help please read ${c}help_subs", array("${c}help_subs" => $help_subs)) .'</p>';
206 return $output;
207
208 // This appears at the start of the subscriptions user page
209 case 'lm_paypal/subscribe':
210 $output .= '<p>'. t('The following lists all the subcriptions available via PayPal on this system. To take out one of these subscriptions you will need a login on this web site and a PayPal account. If you do not already have a PayPal account then PayPal will show you how to get an account when you subscribe.') .'</p>';
211 return $output;
212 }
213 }
214
215 /**
216 * Implementation of hook_perm().
217 * Return a list of the access control permissions that this module defines
218 */
219 function lm_paypal_subscriptions_perm() {
220 return array('access lm_paypal_subscribe');
221 }
222
223 /**
224 * Implementation of hook_menu().
225 */
226 function lm_paypal_subscriptions_menu($may_cache) {
227 _lm_paypal_subscriptions_ini();
228 global $_lm_paypal_drupal_major;
229
230 $items = array();
231
232 if ($may_cache) {
233 // TODO: For Drupal 5 put all the subscription admin menu entries into
234 // their own section
235 if ($_lm_paypal_drupal_major > 4) {
236 // New to Drupal 5 - hook_settings gone so settings is a normal page
237 $items[] = array(
238 'path' => 'admin/lm_paypal/subscriptions_settings',
239 'title' => t('LM PayPal Subscriptions Settings'),
240 'callback' => 'drupal_get_form',
241 'callback arguments' => array('lm_paypal_subscriptions_admin_settings'),
242 'access' => user_access('administer site configuration'),
243 'type' => MENU_NORMAL_ITEM,
244 'weight' => 1,
245 // New to Drupal 5 - every path has a description
246 'description' => t('PayPal subscriptions interface configuration.'),
247 );
248 }
249 // Subscription admin
250 $items[] = array(
251 'path' => 'admin/lm_paypal/subscriptions',
252 'title' => t('LM PayPal Subscriptions'),
253 'callback' => 'lm_paypal_view_subscriptions',
254 'access' => user_access('administer lm_paypal'),
255 'weight' => -3,
256 // New to Drupal 5 - every path has a description
257 'description' => t('View PayPal subscriptions.'),
258 );
259
260 $items[] = array(
261 'path' => 'admin/lm_paypal/subscriptions/new',
262 'title' => t('LM PayPal Create New Subscription'),
263 'callback' => 'lm_paypal_subscription_edit',
264 'access' => user_access('administer lm_paypal'),
265 // New to Drupal 5 - every path has a description
266 'description' => t('Create new PayPal subscriptions.'),
267 );
268
269 $items[] = array(
270 'path' => 'admin/lm_paypal/subscription/delete',
271 'title' => t('LM PayPal Delete Subscription'),
272 'type' => MENU_CALLBACK,
273 'callback' => 'lm_paypal_subscription_delete',
274 'access' => user_access('administer lm_paypal'),
275 );
276
277 $items[] = array(
278 'path' => 'admin/lm_paypal/subscription',
279 'title' => t('LM PayPal Show Subscription Details'),
280 'type' => MENU_CALLBACK,
281 'callback' => 'lm_paypal_subscription',
282 'access' => user_access('administer lm_paypal'),
283 );
284
285 $items[] = array(
286 'path' => 'admin/lm_paypal/subscribers',
287 'title' => t('LM PayPal Show Subscribers'),
288 'type' => MENU_CALLBACK,
289 'callback' => 'lm_paypal_subscribers',
290 'access' => user_access('administer lm_paypal'),
291 );
292
293 $items[] = array(
294 'path' => 'admin/lm_paypal/subscriber_edit',
295 'title' => t('LM PayPal Edit Subscriber'),
296 'type' => MENU_CALLBACK,
297 'callback' => 'lm_paypal_subscriber_edit',
298 'access' => user_access('administer lm_paypal'),
299 );
300
301 // User page to subscribe
302 $items[] = array(
303 'path' => 'lm_paypal/subscribe',
304 'title' => t('PayPal Subscribe'),
305 'callback' => 'lm_paypal_subscribe',
306 'access' => user_access('access lm_paypal_subscribe'),
307 // New to Drupal 5 - every path has a description
308 'description' => t('Subscribe using PayPal.'),
309 );
310
311 // By default we tell Paypal to redirect users here after subscribing
312 $items[] = array(
313 'path' => 'lm_paypal/subscriptions_inprogress',
314 'title' => t('LM PayPal Subscription In Progress'),
315 'type' => MENU_CALLBACK,
316 'callback' => 'lm_paypal_subscriptions_inprogress',
317 'access' => user_access('access lm_paypal_subscribe'),
318 );
319
320 }
321
322 return $items;
323 }
324
325 // Ugly magic to hide lm_paypal_settings from Drupal 5.0 as it spots its
326 // existance and refuses to access the real page.
327 if (strncmp(VERSION, '4', 1) == 0) {
328 /**
329 * Implementation of hook_settings()
330 * Note: hook_settings not used in Drupal 5.
331 */
332 function lm_paypal_subscriptions_settings() {
333 return lm_paypal_subscriptions_settings_form();
334 }
335 }
336
337 /**
338 */
339 function lm_paypal_subscriptions_admin_settings() {
340 $form = lm_paypal_subscriptions_settings_form();
341 return system_settings_form($form);
342 }
343
344 /**
345 */
346 function lm_paypal_subscriptions_settings_form() {
347 _lm_paypal_subscriptions_ini();
348 global $_lm_paypal_subscriptions_inprogress;
349 global $_lm_paypal_subscriptions_menu_rebuild;
350
351 if (!user_access('administer lm_paypal')) {
352 drupal_access_denied();
353 return;
354 }
355
356 $form['lm_paypal_subscriptions_inprogress'] = array(
357 '#type' => 'textfield',
358 '#title' => t('LM PayPal subscription in progress page'),
359 '#default_value' => $_lm_paypal_subscriptions_inprogress,
360 '#maxlength' => 100,
361 '#required' => TRUE,
362 '#description' => t('The page the user is sent to by PayPal after a subscribe. The default is ') . LM_PAYPAL_SUBSCRIPTIONS_INPROGRESS_DEFAULT . t(' but you might want to point it at a page you have created yourself.'),
363 );
364
365 $form['lm_paypal_subscriptions_menu_rebuild'] = array(
366 '#type' => 'checkbox',
367 '#title' => t('Rebuild menu cache on subscription change'),
368 '#default_value' => $_lm_paypal_subscriptions_menu_rebuild,
369 '#description' => t('On a user being added to/removed from a subscription rebuild the menu cache. Needed only if user logout/login fails to get the right menu items.'),
370 );
371
372 return $form;
373 }
374
375 /**
376 * Find all live node subscriptions.
377 *
378 * @return
379 * An array of of live node subscriptions
380 */
381 function lm_paypal_subscription_node_subs() {
382 $node_subs = array();
383 $output = '';
384 $sql = 'SELECT subid, item_name FROM {lm_paypal_subscriptions} WHERE status = 1 AND kind = 1';
385 $subs = db_query($sql);
386 if (db_num_rows($subs) <= 0) {
387 return $node_subs;
388 }
389
390 while ($so = db_fetch_object($subs)) {
391 $node_subs[$so->subid] = $so->item_name;
392 }
393
394 return $node_subs;
395 }
396
397 /**
398 * Tests if the given node has a live subscription.
399 *
400 * @param $nid
401 * The node to check for
402 *
403 * @return
404 * TRUE only if the node has a live subscription
405 */
406 function lm_paypal_node_subscribed($nid,&$subid) {
407 $sql = "SELECT * FROM {lm_paypal_subscribers} WHERE status = 1 AND nid = %d";
408 $sbs = db_query($sql, $nid);
409 if (db_num_rows($sbs) <= 0) {
410 // No subscribers
411 return FALSE;
412 }
413
414 if (!($sb = db_fetch_object($sbs))) {
415 // TODO: No object.. is this an error?
416 return FALSE;
417 }
418
419 $subid = $sb->subid;
420 return TRUE;
421 }
422
423 /**
424 * Display either all live subscriptions or a single one with a link to PayPal.
425 *
426 * @param $subid
427 * If given then a subscribe page is returned otherwise a list of
428 * available subscriptions is returned.
429 * @param $display
430 * If just showing a single subscription then $diplay lists what to show.
431 * 1 = item_name
432 * 2 = description
433 * 4 = human readable details of subscription
434 * 8 = button
435 * 16 = brief
436 * 32 = no section header (applies to list of subscriptions, subid=null)
437 * These can be added to get combinations (eg: 11 = 1 + 2 + 8)
438 * 64 = output a comma seperated list the current users subscriptions
439 * (or just none)
440 * @param button_url
441 * The url of the button to display
442 * @param nid
443 * For node subscriptions this is the node id
444 */
445 function lm_paypal_subscribe($subid = null, $display = 15, $button_url = '', $nid = null, $account = null) {
446 _lm_paypal_subscriptions_ini();
447 global $user;
448 global $_lm_paypal_debug;
449 global $_lm_paypal_host;
450 global $_lm_paypal_business;
451 global $_lm_paypal_subscriptions_inprogress;
452 global $_lm_paypal_drupal_major;
453 global $_lm_paypal_js_hide_email;
454
455 // Drupal 5 - t() has changed and to use a link in it use '!'
456 $c = ($_lm_paypal_drupal_major > 4 ? '!' : '%');
457
458 if (!is_null($account)) {
459 // I am looking at an account other than current user.
460 // I cannot tell if they are logged in or not .. so presume they are.
461 $logged_in = true;
462 }
463 else {
464 $logged_in = ($user->uid != 0);
465 }
466
467
468 $subid = check_plain($subid);
469
470 // Print out the details of just one subscription
471 if ($subid != '') {
472 if (!is_numeric($subid) || intval($subid) != $subid) {
473 $err = t('lm_paypal_subscribe requires integer subid: %subid', array('%subid' => $subid));
474 watchdog(
475 LM_PAYPAL_SUBSCRIPTIONS,
476 $err,
477 WATCHDOG_ERROR);
478 return $err;
479 }
480
481 if (!$logged_in) {
482 $login = l(t('login'), 'user');
483 $register = l(t('create new account'), 'user/register');
484 return t("You must ${c}login or ${c}register to subscribe", array("${c}login" => $login, "${c}register" => $register));
485 }
486
487 $sql = "SELECT * FROM {lm_paypal_subscriptions} WHERE subid = %d AND status = 1";
488 $subs = db_query($sql, $subid);
489 $so = db_fetch_object($subs);
490 if (! $so) {
491 $err = t('lm_paypal_subscribe cannot find subscription: %subid', array('%subid' => $subid));
492 watchdog(
493 LM_PAYPAL_SUBSCRIPTIONS,
494 $err,
495 WATCHDOG_ERROR);
496 return $err;
497 }
498
499 $output = '';
500 $output .= '<p>' . lm_paypal_subscription($subid, $display) . '</p>';
501
502 if (($display & 8) == 0) {
503 // If I am not displaying a button then I am done.
504 return $output;
505 }
506
507 $i_agree = $_SESSION['lm_paypal_I_agree'];
508 if ($so->terms != '' && $i_agree != $subid) {
509 $output .= lm_paypal_subscription_terms($subid, $so->terms);
510 return $output;
511 }
512 $_SESSION['lm_paypal_I_agree'] = '';
513
514 if ($button_url == '') {
515 // This is the default paypal subscribe button
516 $button_url = 'http://images.paypal.com/images/x-click-but20.gif';
517 $button_url = 'http://images.paypal.com/images/x-click-butcc-subscribe.gif';
518 }
519 else {
520 $button_url = check_url($button_url);
521 }
522
523 if ($so->return_url != '') {
524 $ret_url = $so->return_url;
525 }
526 else {
527 $ret_url = $_lm_paypal_subscriptions_inprogress;
528 }
529 if (variable_get('clean_url', 0)) {
530 $return_url = url(check_url($ret_url), null, null, TRUE);
531 }
532 else {
533 $return_url = url(null, 'q=' . check_url($ret_url), null, TRUE);
534 }
535 $notify_url = url('lm_paypal/ipn', null, null, TRUE);
536 $biz = check_plain($_lm_paypal_business);
537 $so->item_name = check_plain($so->item_name);
538
539 // Output a form that will redirect the user to PayPal - note all the fields
540 // are hidden so only the submit appears
541
542 // If email hiding is enabled then turn on this javascript
543 // and add an onsubmit action
544 $onsub = '';
545 if ($_lm_paypal_js_hide_email) {
546 lm_paypal_add_js();
547 $at = strpos($biz, '@');
548 $person = substr($biz, 0, $at);
549 $host = substr($biz, $at + 1, strlen($biz));
550 $biz = '';
551
552 $onsub = "onsubmit=\"lm_paypal_setbiz(this,'$person','$host')\"";
553 }
554
555 $form = "\n<form action=\"http://$_lm_paypal_host/cgi-bin/webscr\" method=\"post\" $onsub>\n";
556
557 $form .= "<input type=\"hidden\" name=\"cmd\" value=\"_xclick-subscriptions\">\n";
558 $form .= "<input type=\"hidden\" name=\"business\" value=\"$biz\">\n";
559 $form .= "<input type=\"hidden\" name=\"notify_url\" value=\"$notify_url\">\n";
560 $form .= "<input type=\"hidden\" name=\"item_name\" value=\"$so->item_name\">\n";
561 $form .= "<input type=\"hidden\" name=\"item_number\" value=\"$so->subid\">\n";
562 $form .= "<input type=\"hidden\" name=\"no_shipping\" value=\"1\">\n";
563 $form .= "<input type=\"hidden\" name=\"return\" value=\"$return_url\">\n";
564 $form .= "<input type=\"hidden\" name=\"cancel_return\" value=\"$return_url\">\n";
565 if ($so->currency_code) {
566 $form .= "<input type=\"hidden\" name=\"currency_code\" value=\"$so->currency_code\">\n";
567 }
568 if ($so->p1 != '' && $so->p1 > 0) {
569 $so->a1 = check_plain($so->a1);
570 $so->p1 = check_plain($so->p1);
571 $form .= "<input type=\"hidden\" name=\"a1\" value=\"$so->a1\">\n";
572 $form .= "<input type=\"hidden\" name=\"p1\" value=\"$so->p1\">\n";
573 $form .= "<input type=\"hidden\" name=\"t1\" value=\"$so->t1\">\n";
574 }
575 if ($so->p2 != '' && $so->p2 > 0) {
576 $so->a2 = check_plain($so->a2);
577 $so->p2 = check_plain($so->p2);
578 $form .= "<input type=\"hidden\" name=\"a2\" value=\"$so->a2\">\n";
579 $form .= "<input type=\"hidden\" name=\"p2\" value=\"$so->p2\">\n";
580 $form .= "<input type=\"hidden\" name=\"t2\" value=\"$so->t2\">\n";
581 }
582 $so->a3 = check_plain($so->a3);
583 $so->p3 = check_plain($so->p3);
584 $form .= "<input type=\"hidden\" name=\"a3\" value=\"$so->a3\">\n";
585 $form .= "<input type=\"hidden\" name=\"p3\" value=\"$so->p3\">\n";
586 $form .= "<input type=\"hidden\" name=\"t3\" value=\"$so->t3\">\n";
587 // If recurring times is set but recurring isn't then set it otherwise
588 // PayPal will reject this request
589 if ($so->srt != '' && $so->src == '') {
590 $so->src = 1;
591 }
592 if ($so->src != '') {
593 $form .= "<input type=\"hidden\" name=\"src\" value=\"$so->src\">\n";
594 if ($so->srt != '') {
595 $form .= "<input type=\"hidden\" name=\"srt\" value=\"$so->srt\">\n";
596 }
597 }
598 $form .= "<input type=\"hidden\" name=\"sra\" value=\"1\">\n";
599 $form .= "<input type=\"hidden\" name=\"no_note\" value=\"1\">\n";
600 if ($so->kind == 0 || $so->kind == 2) {
601 $custom = $user->uid;
602 }
603 if ($so->kind == 1) {
604 $custom = ($nid << 16) | ($user->uid & 0xFFFF);
605 }
606 $form .= "<input type=\"hidden\" name=\"custom\" value=\"$custom\">\n";
607 //$form .= "<input type=\"hidden\" name=\"invoice\" value=\"invoicenumber\">\n";
608 $form .= "<input type=\"hidden\" name=\"usr_manage\" value=\"0\">\n";
609 $form .= "<input type=\"image\" src=\"$button_url\" border=\"0\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\">\n";
610 $form .= "</form>\n";
611
612 $output .= $form;
613 return $output;
614 }
615
616 // Output a list of all the live role or group subscriptions
617 $output = '';
618 $sql = 'SELECT subid, item_name, description, status FROM {lm_paypal_subscriptions} WHERE status = 1 AND (kind = 0 OR kind = 2)';
619 $subs = db_query($sql);
620 if (db_num_rows($subs) <= 0) {
621 $output .= '<p>' . t('No subscriptions currently defined') . '</p>';
622 return $output;
623 }
624
625 if (($display & 64) != 0) {
626 $nSubs = 0;
627 while ($so = db_fetch_object($subs)) {
628 $already = lm_paypal_user_subscribed($so->subid, $account);
629 if (!$already) {
630 continue;
631 }
632 $item_name = check_plain($so->item_name);
633 if ($nSubs > 0) {
634 $output .= ", ";
635 }
636 $output .= '"' . $item_name . '"';
637 $nSubs ++;
638 }
639 if ($nSubs == 0) {
640 $output .= t('<b>none</b>');
641 }
642 return $output;
643 }
644
645 if (($display & 32) == 0) {
646 $output .= '<h2>' . t('Subscriptions') . '</h2>';
647 }
648
649 $header = array(t('Subscription Name'), t('Description'), '');
650 while ($so = db_fetch_object($subs)) {
651 $already = lm_paypal_user_subscribed($so->subid, $account);
652
653 $item_name = check_plain($so->item_name);
654 if ($already) {
655 $sub = t('already subscribed');
656 }
657 else {
658 if (!$logged_in) {
659 $login = l(t('login'), 'user');
660 $register = l(t('create new account'), 'user/register');
661 $sub = t("You must ${c}login or ${c}register to subscribe", array("${c}login" => $login, "${c}register" => $register));
662 }
663 else {
664 $sub = l(t('subscribe'), "lm_paypal/subscribe/$so->subid");
665 }
666 }
667
668 $rows[] = array('data' => array($item_name, $so->description, $sub));
669 $count++;
670 }
671 $output .= theme('table', $header, $rows);
672
673 $alias = urlencode($_lm_paypal_business);
674 $unsuburl = "https://$_lm_paypal_host/cgi-bin/webscr?cmd=_subscr-find&alias=$alias";
675
676 $output .= '<h3>' . t('To Unsubscribe') . '</h3>';
677 $output .= '<p>';
678 $output .= t('Click unsubscribe to log in to your PayPal account. Click the Details of the subscription in question. Click Cancel Subscription.');
679 $output .= "</p><p><a href=\"$unsuburl\">" . t('Unsubscribe') . '</a>';
680 $output .= '</p>';
681
682 return $output;
683 }
684
685 /**
686 * Finds if a user is already subscribed to this subid
687 *
688 * @param $subid
689 * The subscription to check
690 * @param $account
691 * The user to check, if null then the current user will be checked
692 *
693 * @return
694 * TRUE only for role subscriptions and if the current user is subscribed
695 */
696 function lm_paypal_user_subscribed($subid, $account = null) {
697 global $user;
698
699 if (is_null($account)) {
700 $uid = $user->uid;
701 }
702 else {
703 $uid = $account->uid;
704 }
705
706 $subid = check_plain($subid);
707
708 if (!is_numeric($subid) || intval($subid) != $subid) {
709 watchdog(
710 LM_PAYPAL_SUBSCRIPTIONS,
711 t('lm_paypal_user_subscribed requires integer subid: %subid', array('%subid' => $subid)),
712 WATCHDOG_ERROR);
713 return FALSE;
714 }
715
716 // kind 0 is a role subscription, kind 2 is a group
717 $sql = "SELECT uid, subid, status, kind FROM {lm_paypal_subscribers} WHERE uid = %d AND subid = %d AND status = 1 AND (kind = 0 OR kind = 2)";
718 $subs = db_query($sql, $uid, $subid);
719 if (db_num_rows($subs) <= 0) {
720 return FALSE;
721 }
722
723 $ss = db_fetch_object($subs);
724 if (! $ss) {
725 watchdog(
726 LM_PAYPAL_SUBSCRIPTIONS,
727 t('Cannot find the subscriber (uid %uid, subid %subid)', array('%uid' => $uid, '%subid' => $subid)),
728 WATCHDOG_ERROR);
729 return FALSE;
730 }
731 return TRUE;
732 }
733
734 /**
735 * Tests if the current user, if any, can subscribe to a given subscription.
736 *
737 * @param $subid
738 * The subscription the user is trying to subscribe to.
739 *
740 * @return
741 * TRUE only if there is a user and they have not already subscribed
742 */
743 function lm_paypal_can_subscribe($subid) {
744 global $user;
745 if ($user->uid == 0 ) {
746 return FALSE;
747 }
748 if (lm_paypal_user_subscribed($subid)) {
749 return FALSE;
750 }
751 return TRUE;
752 }
753
754 /**
755 * The user has to agree to the terms and conditions
756 */
757 function lm_paypal_subscription_terms($subid, $terms) {
758 _lm_paypal_subscriptions_ini();
759 global $_lm_paypal_drupal_major;
760
761 if ($_lm_paypal_drupal_major > 4) {
762 return drupal_get_form('lm_paypal_subscription_terms_form', $subid, $terms);
763 }
764 else {
765 $form = lm_paypal_subscription_terms_form($subid, $terms);
766
767 // Note: I've chosen a form_id the same as this function
768 return drupal_get_form('lm_paypal_subscription_terms', $form);
769 }
770 }
771
772 function lm_paypal_subscription_terms_form($subid, $terms) {
773 // Under Drupal 5 this form has the following base name and all the
774 // processing is done by calling #base_validate, ...
775 $form['#base'] = 'lm_paypal_subscription_terms';
776
777 $_SESSION['lm_paypal_I_agree'] = '';
778
779 $terms = check_plain($terms);
780
781 $form['terms'] = array(
782 '#value' => t('<h2>Terms and Conditions</h2><p>') . $terms .
783 t('</p><p><em>Before you can subscribe you must agree to these terms and conditions</em></p>'),
784 );
785
786 $form['terms_subid'] = array(
787 '#type' => 'hidden',
788 '#value' => $subid,
789 );
790
791 $form['submit'] = array(
792 '#type' => 'submit',
793 '#value' => t('I agree'),
794 );
795
796 return $form;
797 }
798
799 /**
800 * Process "I Agree" to terms form
801 *
802 * @param $form_id
803 * The form_id that caused this _submit function to be called
804 * @pararm $values
805 * The array of name,value pairs from the form
806 *
807 * @return
808 * The url to go to.
809 *
810 * The user has agreed to the terms and conditions. Allow them to subscribe.
811 */
812 function lm_paypal_subscription_terms_submit($form_id, $values) {
813 _lm_paypal_subscriptions_ini();
814 global $_lm_paypal_debug;
815
816 $subid = ($values ['terms_subid']);
817 $_SESSION['lm_paypal_I_agree'] = $subid;
818 return 'lm_paypal/subscribe/' . $subid;
819 }
820
821
822 /**
823 * Creates or edits a subscription.
824 *
825 * @param $subid
826 * If provided then edit this subscription instead creating a new one
827 */
828 function lm_paypal_subscription_edit($subid = '') {
829 _lm_paypal_subscriptions_ini();
830 global $_lm_paypal_drupal_major;
831
832 if ($_lm_paypal_drupal_major > 4) {
833 return drupal_get_form('lm_paypal_subscription_edit_form', $subid);
834 }
835 else {
836 $form = lm_paypal_subscription_edit_form($subid);
837
838 // Note: I've chosen a form_id the same as this function
839 return drupal_get_form('lm_paypal_subscription_edit', $form);
840 }
841 }
842
843 function lm_paypal_subscription_edit_form($subid = '') {
844 _lm_paypal_subscriptions_ini();
845 global $_lm_paypal_period_units_option;
846 global $_lm_paypal_currency_option;
847
848 // Under Drupal 5 this form has the following base name and all the
849 // processing is done by calling #base_validate, ...
850 $form['#base'] = 'lm_paypal_subscription_edit';
851
852 $subid = check_plain($subid);
853
854 if ($subid != '' && (!is_numeric($subid) || intval($subid) != $subid)) {
855 watchdog(
856 LM_PAYPAL_SUBSCRIPTIONS,
857 t('lm_paypal_subscription_edit requires empty or integer subid: %subid', array('%subid' => $subid)),
858 WATCHDOG_ERROR);
859 return '';
860 }
861
862 $edit = ($subid != '');
863
864 if ($edit) {
865 // Look up the default values
866 $sql = "SELECT * FROM {lm_paypal_subscriptions} WHERE subid = %d";
867 $subs = db_query($sql, $subid);
868
869 if (db_num_rows($subs) <= 0) {
870 watchdog(
871 LM_PAYPAL_SUBSCRIPTIONS,
872 t('Attempt to edit non existant subscription subid: %subid', array('%subid' => $subid)),
873 WATCHDOG_ERROR);
874 return '';
875 }
876
877 $so = db_fetch_object($subs);
878 if (! $so) {
879 watchdog(
880 LM_PAYPAL_SUBSCRIPTIONS,
881 t('Cannot find the subscription subid: %subid', array('%subid' => $subid)),
882 WATCHDOG_ERROR);
883 return '';
884 }
885
886 $form['edit_subid'] = array(
887 '#type' => 'hidden',
888 '#value' => $subid,
889 );
890 }
891 else {
892 // Initialise a new subscription
893 $so->src = 0;
894 $so->uid_admin = LM_PAYPAL_SUBSCRIPTIONS_UID_ADMIN_DEFAULT;
895 $so->send_admin_onsub = LM_PAYPAL_SUBSCRIPTIONS_SEND_ADMIN_ONSUB_DEFAULT;
896 $so->send_admin_onend = LM_PAYPAL_SUBSCRIPTIONS_SEND_ADMIN_ONEND_DEFAULT;
897
898 $so->send_user_onsub = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONSUB_DEFAULT;
899 $so->send_user_onsub_subject = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONSUB_SUBJECT_DEFAULT;
900 $so->send_user_onsub_body = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONSUB_BODY_DEFAULT;
901
902 $so->send_user_onnearend = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONNEAREND_DEFAULT;
903 $so->nearend_days = LM_PAYPAL_SUBSCRIPTIONS_NEAREND_DAYS_DEFAULT;
904 $so->send_user_onnearend_subject = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONNEAREND_SUBJECT_DEFAULT;
905 $so->send_user_onnearend_body = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONNEAREND_BODY_DEFAULT;
906
907 $so->send_user_onend = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONEND_DEFAULT;
908 $so->send_user_onend_subject = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONEND_SUBJECT_DEFAULT;
909 $so->send_user_onend_body = LM_PAYPAL_SUBSCRIPTIONS_SEND_USER_ONEND_BODY_DEFAULT;
910
911 $so->terms = LM_PAYPAL_SUBSCRIPTIONS_TERMS_DEFAULT;
912 }
913
914 $form['item_name'] = array(
915 '#type' => 'textfield',
916 '#title' => t('Subscription Name'),
917 '#maxlength' => 127,
918 '#default_value' => $so->item_name,
919 '#required' => TRUE,
920 '#description' => t('The name of the subscription'),
921 );
922
923 $form['description'] = array(
924 '#type' => 'textfield',
925 '#title' => t('Description'),
926 '#maxlength' => 127,
927 '#default_value' => $so->description,
928 '#required' => TRUE,
929 );
930
931 $kinds = array(0 => 'Role', 1 => 'Node');
932 $descr = t('Kind of subscription. Role subscriptions for users to gain an role. Node subscription to make a private node public.');
933
934 $og = (function_exists('og_subscribe_user'));
935
936 if ($og) {
937 $kinds[2] = 'Organic Group';
938 $descr .= t(' Organic Group for users to gain a group');
939 $og = true;
940 }
941
942 $form['kind'] = array(
943 '#type' => 'select',
944 '#title' => t('Subscription Kind'),
945 '#options' => $kinds,
946 '#default_value' => $so->kind,
947 '#required' => TRUE,
948 '#description' => $descr,
949 );
950
951 $form['rid'] = array(
952 '#type' => 'select',
953 '#title' => t('Subscribers Role'),
954 '#options' => lm_paypal_subscribable_roles(TRUE),
955 '#default_value' => $so->rid,
956 //'#required' => TRUE, - not required for node-subs only role-subs
957 '#description' => t('The role subscribers become members of. Only used when kind is Role'),
958 );
959
960 if ($og) {
961 // NOTE: Reusing the so->rid field for the Organic Group id
962 $form['gid'] = array(
963 '#type' => 'select',
964 '#title' => t('Subscribers Organic Group'),
965 '#options' => lm_paypal_subscribable_groups(),
966 '#default_value' => $so->rid,
967 //'#required' => TRUE, - not required for node-subs only role-subs
968 '#description' => t('The Organic Group subscribers become members of. Only used when kind is Organic Group. Only "Invite Only" groups can be used in subcsriptions.'),
969 );
970 }
971
972 $form['a3'] = array(
973 '#type' => 'textfield',
974 '#title' => t('Regular rate'),
975 '#maxlength' => 10,
976 '#default_value' => $so->a3,
977 '#required' => TRUE,
978 '#description' => t('This is the price of the subscription. (The currency is specified below.)'),
979 );
980
981 $form['p3'] = array(
982 '#type' => 'textfield',
983 '#title' => t('Regular billing cycle'),
984 '#maxlength' => 10,
985 '#default_value' => $so->p3,
986 '#required' => TRUE,
987 '#description' => t('This is the length of the billing cycle. The number is modified by the regular billing cycle units'),
988 );
989
990 $form['t3'] = array(
991 '#type' => 'select',
992 '#title' => t('Regular billing cycle units'),
993 '#options' => $_lm_paypal_period_units_option,
994 '#default_value' => $so->t3,
995 '#required' => TRUE,
996 '#description' => t('This is the units of the regular billing cycle'),
997 );
998
999 $form['src'] = array(
1000 '#type' => 'checkbox',
1001 '#title' => t('Recurring payments'),
1002 '#default_value' => $so->src,
1003 '#description' => t('If set the payment will recur unless your customer cancels the subscription before the end of the billing cycle. If omitted, the subscription payment will not recur at the end of the billing cycle'),
1004 );
1005
1006 $form['srt'] = array(
1007 '#type' => 'textfield',
1008 '#title' => t('Recurring Times'),
1009 '#maxlength' => 10,
1010 '#default_value' => $so->srt,
1011 '#description' => t('This is the number of payments which will occur at the regular rate. If omitted, payment will continue to recur at the regular rate until the subscription is cancelled. Requires Recurring payments to be set. <b>If set it must be at least 2</b>.'),
1012 );
1013
1014 $form['currency_code'] = array(
1015 '#type' => 'select',
1016 '#title' => t('The currency of the payment(s)'),
1017 '#default_value' => $so->currency_code,
1018 '#options' => $_lm_paypal_currency_option,
1019 '#description' => t('The currency to use in all payments relating to this subscription.'),
1020 );
1021
1022 $form['return_url'] = array(
1023 '#type' => 'textfield',
1024 '#title' => t('Return URL'),
1025 '#maxlength' => 200,
1026 '#default_value' => $so->return_url,
1027 '#description' => t('If set this is the URL the user is returned to after completing the transaction at PayPal. If can be used to override the default "thank you" page with a page of your own.'),
1028 );
1029
1030 $form['trial_header'] = array(
1031 '#value' => '<br><h2>' . t('Optional Trial Periods') . '</h2>',
1032 );
1033
1034 $form['a1'] = array(
1035 '#type' => 'textfield',
1036 '#title' => t('Trial amount 1'),
1037 '#maxlength' => 10,
1038 '#default_value' => $so->a1,
1039 '#description' => t('This is the price of the first trial period. For a free trial set this to 0'),
1040 );
1041
1042 $form['p1'] = array(
1043 '#type' => 'textfield',
1044 '#title' => t('Trial period 1'),
1045 '#maxlength' => 10,
1046 '#default_value' => $so->p1,
1047 '#description' => t('This is the length of the first trial period. The number is modified by the trial period 1 units'),
1048 );
1049
1050 $form['t1'] = array(
1051 '#type' => 'select',
1052 '#title' => t('Trial period 1 units'),
1053 '#options' => $_lm_paypal_period_units_option,
1054 '#default_value' => $so->t1,
1055 '#description' => t('This is the units of trial period 1'),
1056 );
1057
1058 $form['a2'] = array(
1059 '#type' => 'textfield',
1060 '#title' => t('Trial amount 2'),
1061 '#maxlength' => 10,
1062 '#default_value' => $so->a2,
1063 '#description' => t('This is the price of the second trial period. For a free trial set this to 0'),
1064 );
1065
1066 $form['p2'] = array(
1067 '#type' => 'textfield',
1068 '#title' => t('Trial period 2'),
1069 '#maxlength' => 10,
1070 '#default_value' => $so->p2,
1071 '#description' => t('This is the length of the second trial period. The number is modified by the trial period 2 units'),
1072 );
1073
1074 $form['t2'] = array(
1075 '#type' => 'select',
1076 '#title' => t('Trial period 2 units'),
1077 '#options' => $_lm_paypal_period_units_option,
1078 '#default_value' => $so->t2,
1079 '#description' => t('This is the units of trial period 2'),
1080 );
1081
1082 $form['admin_emails_header'] = array(
1083 '#value' => '<br><h2>' . t('Email administrator options') . '</h2>',
1084 );
1085
1086 $form['uid_admin'] = array(
1087 '#type' => 'textfield',
1088 '#title' => t('UID Admin'),
1089 '#maxlength' => 10,
1090 '#default_value' => $so->uid_admin,
1091 '#description' => t('UID of this subscriptions administrator'),
1092 );
1093
1094 $form['send_admin_onsub'] = array(
1095 '#type' => 'checkbox',
1096 '#title' => t('Email admin on subscription'),
1097 '#default_value' => $so->send_admin_onsub,
1098 '#description' => t('Email this subscriptions administrator when someone subscribes'),
1099 );
1100
1101 $form['send_admin_onend'] = array(
1102 '#type' => 'checkbox',
1103 '#title' => t('Email admin on subscription end'),
1104 '#default_value' => $so->send_admin_onend,
1105 '#description' => t('Email this subscriptions administrator when someones subscription ends by either cancel or end-of-term'),
1106 );
1107
1108 $form['send_user_header'] = array(
1109 '#value' => '<br><h2>' . t('Email subscriber options') . '</h2>' . t('The following variables can be used in the subject and body of messages:<ul><li>%Subscription - the subscriptions name</li><li>%Username - the subscribers name</li><li>%Login - the subscribers login</li><li>%Site - this sites name</li><li>%Uri - this uri</li><li>%Uri_brief - this uri stripped of http://</li><li>%Mailto - target of this email</li><li>%Date - the curent date/time</li></ul>'),
1110 );
1111
1112 $form['send_user_onsub'] = array(
1113 '#type' => 'checkbox',
1114 '#title' => t('Email user on subscription'),
1115 '#default_value' => $so->send_user_onsub,
1116 '#description' => t('Email the user when they subscribe'),
1117 );
1118
1119 $form['send_user_onsub_subject'] = array(
1120 '#type' => 'textfield',
1121 '#title' => t('New subscription email subject'),
1122 '#maxlength' => 80,
1123 '#default_value' => $so->send_user_onsub_subject,
1124 '#description' => t('Subject of email sent to a user on a new subscription'),
1125 );
1126
1127 $form['send_user_onsub_body'] = array(
1128 '#type' => 'textarea',
1129 '#title' => t('New subscription email body'),
1130 '#maxlength'