/
paypal_donate.admin.inc
157 lines (135 loc) · 7.54 KB
/
paypal_donate.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
// $Id: paypal_donate.admin.inc 193 2010-11-24 22:53:19Z aklump $
/**
* @file
* Administration page callbacks for the paypal_donate module.
*/
/**
* Form builder. Configure paypal_donate.
*
* @ingroup forms
* @see system_settings_form().
*/
function paypal_donate_admin_settings() {
global $base_url;
//has the user defined how many blocks they want?
$total_blocks = variable_get('paypal_donate_total_blocks', 1);
$form['paypal_donate_total_blocks'] = array(
'#type' => 'select',
'#title' => t('Total donation blocks to create?'),
'#description' => t('This is usually one, unless you want to assign blocks to multiple regions or have different donation configurations in different places in your website. Note: You can only increase this number unless you reinstall this module.'),
'#default_value' => $total_blocks,
'#options' => array_combine(range($total_blocks, 15), range($total_blocks, 15)),
);
for ($delta = 1; $delta <= $total_blocks; ++$delta) {
//populate defaults with last block
$prev_delta = max($delta - 1, 1);
//fieldset wrapper
$form['paypal_donate_block_'. $delta] = array(
'#type' => 'fieldset',
'#title' => t('Block #@num Configuration', array(
'@num' => $delta,
)),
'#collapsible' => TRUE,
'#collapsed' => $delta != 1,
);
$form['paypal_donate_block_'. $delta]['paypal_donate_paypal_account_'. $delta] = array(
'#type' => 'textfield',
'#title' => 'Your PayPal Account Login (primary email address)',
//default to the first one if available
'#default_value' => variable_get('paypal_donate_paypal_account_'. $delta, variable_get('paypal_donate_paypal_account_'. $prev_delta, NULL)),
'#description' => t('Money will be deposited into this account. <strong>Do Not</strong> enter your paypal password!!!'),
'#required' => TRUE,
);
$form['paypal_donate_block_'. $delta]['paypal_donate_product_'. $delta] = array(
'#type' => 'textfield',
'#title' => t('Product description'),
'#default_value' => variable_get('paypal_donate_product_'. $delta, variable_get('paypal_donate_product_'. $prev_delta, t('Online Donation to @site', array('@site' => variable_get('site_name', $base_root))))),
'#description' => t('Enter a product name or description to show up on the paypal receipt.'),
'#required' => TRUE,
);
$form['paypal_donate_block_'. $delta]['paypal_donate_buttons_'. $delta] = array(
'#type' => 'textarea',
'#title' => t('Button Dollar Amounts'),
'#default_value' => variable_get('paypal_donate_buttons_'. $delta, variable_get('paypal_donate_buttons_'. $prev_delta,'10,50,100,?')),
'#rows' => 3,
'#description' => t('Enter an amount for each button you wish to have on your form; separate amounts by a comma. If you want the user to type in their own amount, enter a question mark (?) instead of a number. They will appear in the order you enter them. <strong>E.g. 5,10,25,50,?</strong>'),
'#required' => TRUE,
);
$form['paypal_donate_block_'. $delta]['paypal_donate_return_url_'. $delta] = array(
'#type' => 'textfield',
'#title' => 'Thank You Page Url',
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
'#size' => 40,
'#default_value' => variable_get('paypal_donate_return_url_'. $delta, variable_get('paypal_donate_return_url_'. $prev_delta, 'thank-you-for-your-donation')),
'#description' => t('After a user makes a donation, where should they be taken on your website. Enter the complete webpage address beginning with http://. <strong>Please make sure you create this page before accepting donations.</strong>'),
'#required' => TRUE,
);
$form['paypal_donate_block_'. $delta]['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['paypal_donate_block_'. $delta]['advanced']['paypal_donate_message_'. $delta] = array(
'#type' => 'textarea',
'#title' => t('Donation Message'),
'#default_value' => variable_get('paypal_donate_message_'. $delta, variable_get('paypal_donate_message_'. $prev_delta, t('You may donate by clicking a button below.'))),
'#rows' => 3,
'#description' => t('Enter a short message to appear above the donation buttons.'),
'#required' => FALSE,
);
$form['paypal_donate_block_'. $delta]['advanced']['paypal_donate_button_face_'. $delta] = array(
'#type' => 'textfield',
'#title' => t('Button Label (for user input amounts only)'),
'#default_value' => variable_get('paypal_donate_button_face_'. $delta, variable_get('paypal_donate_button_face_'. $prev_delta, t('Go'))),
);
$form['paypal_donate_block_'. $delta]['advanced']['paypal_donate_amount_location_'. $delta] = array(
'#type' => 'select',
'#title' => t('Display the Dollar Amount'),
'#default_value' => variable_get('paypal_donate_amount_location_'. $delta, variable_get('paypal_donate_amount_location_'. $prev_delta, 'face')),
'#options' => array(
'face' => t('Inside the button'),
'left' => t('To the left of the button (use css to style buttons)'),
),
'#description' => t('Where do you wan the dollar amount to print in relationship to the button. Experiment to see the difference. This option allows for greater css override ability.'),
);
$form['paypal_donate_block_'. $delta]['advanced']['paypal_donate_new_window_'. $delta] = array(
'#type' => 'select',
'#title' => t('Open PayPal in a new browser window?'),
'#default_value' => variable_get('paypal_donate_new_window_'. $delta, variable_get('paypal_donate_new_window_'. $prev_delta, 1)),
'#options' => array(
1 => t('Yes'),
0 => t('No'),
),
);
$paypal_logo = 'https://www.paypal.com/en_US/i/logo/PayPal_mark_50x34.gif';
$form['paypal_donate_block_'. $delta]['advanced']['chosen_logo_'. $delta] = array(
'#value' => '<img style="display: block; margin-bottom: 10px;" src="'. check_plain(variable_get('paypal_donate_logo_'. $delta, $paypal_logo)) .'" />',
);
$form['paypal_donate_block_'. $delta]['advanced']['paypal_donate_logo_'. $delta] = array(
'#type' => 'textfield',
'#title' => t('Small Logo or Icon'),
'#default_value' => variable_get('paypal_donate_logo_'. $delta, variable_get('paypal_donate_logo_'. $prev_delta, $paypal_logo)),
'#description' => t('Enter the url to a small logo to be displayed at the bottom of your donation block, such as the PayPal logo (<a href="@url" target="_blank">Get PayPal logos.</a>). You may leave this blank for no logo to appear.', array(
'%pplogo' => $paypal_logo,
'@url' => 'https://www.paypal.com/cgi-bin/webscr?cmd=xpt/general/OnlineLogoCenter-outside',
)),
'#required' => FALSE,
);
}
return system_settings_form($form);
}
/**
* Form validation handler for paypal_donate_admin_settings_form().
*
* @see paypal_donate_admin_settings_form()
* @see paypal_donate_admin_settings_form_submit()
*/
function paypal_donate_admin_settings_form_validate($form, &$form_state) {
for ($delta = 1; $delta < $values['paypal_donate_total_blocks']; ++$delta) {
if (!valid_email_address($form_state['values']['paypal_donate_paypal_account_'. $delta])) {
form_set_error('paypal_donate_paypal_account_'. $delta, t('Your PayPal account should be a valid email address; what you provided is not.'));
}
}
}