-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg_account.admin.inc
More file actions
339 lines (267 loc) · 12 KB
/
pg_account.admin.inc
File metadata and controls
339 lines (267 loc) · 12 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?php
function pg_account_history(){
drupal_add_css(drupal_get_path('module', 'pg_account') .'/css/pg_account.css');
$header = array(
'date' => array('data' => t('Date'), 'field' => 'pgt.changed', 'sort' => 'desc'),
'amount' => array('data' => t('Amount'), 'field' => 'pgt.amount'),
'user' => array('data' => t('User'), 'field' => 'u.name'),
'description' => array('data' => t('Description')),
'status' => array('data' => t('Payment status'), 'field' => 'pgt.status'),
);
$query = db_select('pg_account_transaction', 'pat')->extend('AltPager')->extend('TableSort')->extend('FormFilterAPI');
$query->fields('pat');
$query->leftjoin('pgapi_transaction', 'pgt', 'pat.pgapi_txnid = %alias.txnid');
$query->fields('pgt', array('status','workflow', 'description', 'title', 'changed'));
$query->leftjoin('users', 'u', 'pat.uid = %alias.uid');
$query->fields('u',array('name'));
$query->processFilters('pg_account_operator_history');
$query->extend('TableSort');
$query->orderByHeader($header);
$transactions= $query->execute()->fetchAll();
foreach ($transactions as $txn) {
$description = $txn->title.'<br>' ; //.$txn->description;
if($txn->status == PG_COMPLETED){
if(!empty($txn->gateway)){
if($txn->amount > 0){
$description .= t('Paid by: !gateway',array('!gateway' => module_invoke($txn->gateway, 'pgapi_gw','display name'))) . '<br>';
}else{
}
}
}
if(!empty($txn->description)){
$description .= t('Description:') . ' ' . $txn->description;
}
$account = user_load($txn->uid);
$class = array($txn->operation, 'status-'.$txn->status, 'workflow-'.$txn->workflow );
$rows[] = array(
'data'=>array(
array( 'data' => format_date($txn->changed,'custom','M d, Y'), 'class' => 'date'),
array( 'data' => pgapi_format_price($txn->amount), 'class' => array('amount')),
theme('username',array('account' => $account)),
$description,
pgapi_get_status($txn->status),
),
'class' => $class,
);
}//while
if(empty($rows)){
$rows[] = array(array('data' => t('No data available.'), 'colspan' => '6'));
}
$pagerCountShow = theme('altpager');
$form = formfilterapi_get_form('pg_account_operator_history');
$output = drupal_render($form);
$output .= '<br>';
$output .= $pagerCountShow;
$output .= '<div width=99% style="overflow-x: auto; ">';
$output .= theme('table', array( 'header' => $header, 'rows' => $rows));
$output .= "</div>";
$output .= $pagerCountShow;
return $output;
}
/* Transaction status callbacks*/
function pg_account_fail ($t){
global $user;
if($user->uid!=1 && $user->uid != $t->uid){
drupal_access_denied();
}
return theme('pg_account_fail',$t);
}
function pg_account_complete ($t){
global $user;
if($user->uid != 1 and $user->uid != $t->uid){
drupal_access_denied();
}
return theme('pg_account_complete',$t);
}
function pg_account_pending($t){
global $user;
if($user->uid != 1 and $user->uid != $t->uid){
drupal_access_denied();
}
return theme('pg_account_pending',$t);
}
function pg_account_settings(){
$roles = array_map('check_plain', user_roles(TRUE));
$form['pg_account_operator_messages'] = array(
'#type' => 'fieldset',
'#title' => t('Operator messages'),
'#description' => t('Please use tokens to form title and message for notifications based on balance adjustment by operator.')
);
$form['pg_account_operator_messages']['add'] = array(
'#type' => 'fieldset',
'#title' => t('Add balance'),
);
$form['pg_account_operator_messages']['add']['pg_account_admin_title_add'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('pg_account_admin_title_add',PG_ACCOUNT_ADD_BALANCE_ADMIN_TITLE),
'#size' => 150,
'#maxlength' => 255,
);
$form['pg_account_operator_messages']['add']['pg_account_admin_message_add'] = array(
'#type' => 'text_format',
'#title' => t('Message'),
'#default_value' => variable_get('pg_account_admin_message_add_body',PG_ACCOUNT_ADD_BALANCE_ADMIN_MESSAGE),
'#rows' => 6,
'#resizable' => TRUE,
'#format' => variable_get('pg_account_admin_message_add_format',NULL),
);
$form['pg_account_operator_messages']['add']['tokens'] = array(
'#theme' => 'token_tree',
'#token_types' => array('pg_account'),
);
$form['pg_account_operator_messages']['sub'] = array(
'#type' => 'fieldset',
'#title' => t('Withdraw balance'),
);
$form['pg_account_operator_messages']['sub']['pg_account_admin_title_sub'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('pg_account_admin_title_sub',PG_ACCOUNT_SUB_BALANCE_ADMIN_TITLE),
'#size' => 150,
'#maxlength' => 255,
);
$form['pg_account_operator_messages']['sub']['pg_account_admin_message_sub'] = array(
'#type' => 'text_format',
'#title' => t('Message'),
'#default_value' => variable_get('pg_account_admin_message_sub_body',PG_ACCOUNT_SUB_BALANCE_ADMIN_MESSAGE),
'#rows' => 6,
'#resizable' => TRUE,
'#format' => variable_get('pg_account_admin_message_sub_format',NULL),
);
$form['pg_account_operator_messages']['sub']['tokens'] = array(
'#theme' => 'token_tree',
'#token_types' => array('pg_account'),
);
$form['pg_account_user_messages'] = array(
'#type' => 'fieldset',
'#title' => t('User messages'),
'#description' => t('Please use tokens to form title and message for notifications based on balance adjustment by operator .')
);
$form['pg_account_user_messages']['add'] = array(
'#type' => 'fieldset',
'#title' => t('Add balance'),
);
$form['pg_account_user_messages']['add']['pg_account_user_title_add'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('pg_account_user_title_add',PG_ACCOUNT_ADD_BALANCE_USER_TITLE),
'#size' => 150,
'#maxlength' => 255,
);
$form['pg_account_user_messages']['add']['pg_account_user_message_add'] = array(
'#type' => 'text_format',
'#title' => t('Message'),
'#default_value' => variable_get('pg_account_user_message_add_body',PG_ACCOUNT_ADD_BALANCE_USER_MESSAGE),
'#rows' => 6,
'#resizable' => TRUE,
'#format' => variable_get('pg_account_user_message_add_format',NULL),
);
$form['pg_account_user_messages']['add']['tokens'] = array(
'#theme' => 'token_tree',
'#token_types' => array('pg_account'),
);
$form['pg_account_user_messages']['sub'] = array(
'#type' => 'fieldset',
'#title' => t('Withdraw from balance'),
);
$form['pg_account_user_messages']['sub']['pg_account_user_title_sub'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('pg_account_user_title_sub',PG_ACCOUNT_SUB_BALANCE_USER_TITLE),
'#size' => 150,
'#maxlength' => 255,
);
$form['pg_account_user_messages']['sub']['pg_account_user_message_sub'] = array(
'#type' => 'text_format',
'#title' => t('Message'),
'#default_value' => variable_get('pg_account_user_message_sub_body',PG_ACCOUNT_SUB_BALANCE_USER_MESSAGE),
'#rows' => 6,
'#resizable' => TRUE,
'#format' => variable_get('pg_account_user_message_sub_format',NULL),
);
$form['pg_account_user_messages']['sub']['tokens'] = array(
'#theme' => 'token_tree',
'#token_types' => array('pg_account'),
);
$form['pg_account_user_messages']['send'] = array(
'#type' => 'fieldset',
'#title' => t('Send transfer'),
);
$form['pg_account_user_messages']['send']['pg_account_user_title_send'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('pg_account_user_title_send',PG_ACCOUNT_SEND_BALANCE_USER_TITLE),
'#size' => 150,
'#maxlength' => 255,
);
$form['pg_account_user_messages']['send']['pg_account_user_message_send'] = array(
'#type' => 'text_format',
'#title' => t('Message'),
'#default_value' => variable_get('pg_account_user_message_send_body',PG_ACCOUNT_SEND_BALANCE_USER_MESSAGE),
'#rows' => 6,
'#resizable' => TRUE,
'#format' => variable_get('pg_account_user_message_send_format',NULL),
);
$form['pg_account_user_messages']['send']['tokens'] = array(
'#theme' => 'token_tree',
'#token_types' => array('pg_account'),
);
$form['pg_account_user_messages']['receive'] = array(
'#type' => 'fieldset',
'#title' => t('Receive transfer'),
);
$form['pg_account_user_messages']['receive']['pg_account_user_title_receive'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('pg_account_user_title_receive',PG_ACCOUNT_RECEIVE_BALANCE_USER_TITLE),
'#size' => 150,
'#maxlength' => 255,
);
$form['pg_account_user_messages']['receive']['pg_account_user_message_receive'] = array(
'#type' => 'text_format',
'#title' => t('Message'),
'#default_value' => variable_get('pg_account_user_message_receive_body',PG_ACCOUNT_RECEIVE_BALANCE_USER_MESSAGE),
'#rows' => 6,
'#resizable' => TRUE,
'#format' => variable_get('pg_account_user_message_receive_format',NULL),
);
$form['pg_account_user_messages']['receive']['tokens'] = array(
'#theme' => 'token_tree',
'#token_types' => array('pg_account'),
);
$form['pg_account_roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
'#default_value' => variable_get('pg_account_roles',array()),
'#options' => $roles,
'#description' => t('Please select role to send notification about user balance changes.')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save changes'),
);
return $form;
}
function pg_account_settings_submit($form, &$form_state){
variable_set('pg_account_roles',$form_state['values']['pg_account_roles']);
variable_set('pg_account_admin_title_add',$form_state['values']['pg_account_admin_title_add']);
variable_set('pg_account_admin_message_add_body',$form_state['values']['pg_account_admin_message_add']['value']);
variable_set('pg_account_admin_message_add_format',$form_state['values']['pg_account_admin_message_add']['format']);
variable_set('pg_account_admin_title_sub',$form_state['values']['pg_account_admin_title_sub']);
variable_set('pg_account_admin_message_sub_body',$form_state['values']['pg_account_admin_message_sub']['value']);
variable_set('pg_account_admin_message_sub_format',$form_state['values']['pg_account_admin_message_sub']['format']);
variable_set('pg_account_user_title_add',$form_state['values']['pg_account_user_title_add']);
variable_set('pg_account_user_message_add_body',$form_state['values']['pg_account_user_message_add']['value']);
variable_set('pg_account_user_message_add_format',$form_state['values']['pg_account_user_message_add']['format']);
variable_set('pg_account_user_title_sub',$form_state['values']['pg_account_user_title_sub']);
variable_set('pg_account_user_message_sub_body',$form_state['values']['pg_account_user_message_sub']['value']);
variable_set('pg_account_user_message_sub_format',$form_state['values']['pg_account_user_message_sub']['format']);
variable_set('pg_account_user_title_send',$form_state['values']['pg_account_user_title_send']);
variable_set('pg_account_user_message_send_body',$form_state['values']['pg_account_user_message_send']['value']);
variable_set('pg_account_user_message_send_format',$form_state['values']['pg_account_user_message_send']['format']);
variable_set('pg_account_user_title_receive',$form_state['values']['pg_account_user_title_receive']);
variable_set('pg_account_user_message_receive_body',$form_state['values']['pg_account_user_message_receive']['value']);
variable_set('pg_account_user_message_receive_format',$form_state['values']['pg_account_user_message_receive']['format']);
drupal_set_message(t('Changes saved.'));
}