-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgapi.admin.inc
162 lines (135 loc) · 4.43 KB
/
pgapi.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
158
159
160
161
162
<?php
/**
* @file
* Administative functions for PGAPI module.
*/
/**
* Menu callback to list sub-items.
*/
function pgapi_admin_menu_block_page() {
$item = menu_get_item();
module_load_include('inc', 'system', 'system.admin');
if ($content = system_admin_menu_block($item)) {
$output = theme('admin_block_content', array('content' => $content));
}
else {
$output = t('You do not have any administrative items.');
}
return $output;
}
/**
* Form-builder for PGAPI currency settings.
*/
function pgapi_admin_currency_settings($form, &$form_state) {
$pgapi_currency = variable_get('pgapi_currency', array());
$form['currency'] = array(
'#tree' => TRUE,
);
$form['currency']['symbol'] = array(
'#type' => 'textfield',
'#title' => t('Symbol'),
'#default_value' => isset($pgapi_currency['symbol']) ? $pgapi_currency['symbol'] : '',
'#description' => t("Please enter symbol of the Account Balance currency."),
'#required' => TRUE,
);
$form['currency']['decimal_places'] = array(
'#type' => 'textfield',
'#title' => t('Decimal places'),
'#default_value' => isset($pgapi_currency['decimal_places']) ? $pgapi_currency['decimal_places'] : '',
'#description' => t("Please enter number of decimal places."),
'#required' => TRUE,
);
$form['currency']['decimal'] = array(
'#type' => 'textfield',
'#title' => t('Decimal delimiter'),
'#default_value' => isset($pgapi_currency['decimal']) ? $pgapi_currency['decimal'] : '',
'#description' => t('Please enter decimal delimiter.'),
'#required' => TRUE,
);
$form['currency']['thousands'] = array(
'#type' => 'textfield',
'#title' => t('Thousands places'),
'#default_value' => isset($pgapi_currency['thousands']) ? $pgapi_currency['thousands'] : '',
'#description' => t('Please enter thousands delimeter.'),
'#required' => TRUE,
);
$form['currency']['symbol_position'] = array(
'#type' => 'radios',
'#title' => t('Simbol position'),
'#options' => array(1 => t('Left'), 0 => t('Right')),
'#default_value' => isset($pgapi_currency['symbol_position']) ? $pgapi_currency['symbol_position'] : 0,
'#description' => t('Please select symbol position.'),
'#required' => TRUE,
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save currency settings'),
);
return $form;
}
/**
* Submit function for PGAPI common settings form.
*/
function pgapi_admin_currency_settings_submit($form, &$form_state) {
$pgapi_currency = array_filter($form_state['values']['currency']);
// Save enabled gateways.
variable_set('pgapi_currency', $pgapi_currency);
drupal_set_message(t('Currency settings saved.'));
}
/**
* Form-builder for PGAPI gateway settings.
*/
function pgapi_admin_gateway_settings($form, &$form_state) {
$pgapi_gw = pgapi_get_enabled_payment_systems();
$gateways = pgapi_get_gateway_options();
if (empty($gateways)) {
$form['gateways']['#markup'] = t('No payment gateways available.');
}
else {
$form['gateways'] = array(
'#type' => 'checkboxes',
'#title' => t('Payment gateways'),
'#options' => $gateways,
'#default_value' => $pgapi_gw,
);
// Add the buttons.
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update status of payment gateways'),
);
}
return $form;
}
/**
* Submit function for PGAPI common settings form.
*/
function pgapi_admin_gateway_settings_submit($form, &$form_state) {
$pgapi_gw = array_filter($form_state['values']['gateways']);
// Save enabled gateways.
variable_set('pgapi_gw', $pgapi_gw);
drupal_set_message(t('Status of payment gateway has been updated.'));
}
/**
* Implements hook_FORMID().
*/
function pgapi_admin_notices_settings($form, &$form_state) {
$form['notice_admin'] = array(
'#type' => 'checkbox',
'#title' => t('Alert the administrator about the payment'),
'#default_value' => variable_get('pgapi_notice_admin', FALSE),
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update notices settings'),
);
return $form;
}
/**
* Implements hook_FORMID_submit().
*/
function pgapi_admin_notices_settings_submit($form, &$form_state) {
variable_set('pgapi_notice_admin', $form_state['values']['notice_admin']);
drupal_set_message(t('Notices settings has been updated.'));
}