Repository navigation
Expand file tree
/
Copy pathprocess_account_type.php
More file actions
342 lines (267 loc) · 11.1 KB
/
Copy pathprocess_account_type.php
File metadata and controls
342 lines (267 loc) · 11.1 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
340
341
342
<?php
///
/// ////
global $payment_button;
$payment_button = "";
/// needs_form ... needed for the gathering of account type specific information...
/// needs_approval ... In the approval queue for this type of account... Requires an administrator or group manager to allow the account..
/// needs_pay ... This type of account has a fee associated with it.
/// If none of these are true then, this is just a registration...
/// Adding a user feature is the same as adding an authspecial record.
/// Each record is specific to a UID, since this reflects the state of account type processing for each user.
/// Prototypical accounts may be determined by UID = 0
/// deal_accounts - A list of pairs. Accounts that may be added with price deals for having this account type.
function format_attainments_message($authobj,$srcobj) {
$requires = "The following steps have been accomplished:";
if ( !($authobj->needs_form) ) {
$requires .= "<div class='reqTitle'>";
$requires .= "Your information has been received";
$requires .= "</div>";
}
if ( !($authobj->needs_approval) && ( $srcobj->needs_approval ) ) {
$requires .= "<div class='reqTitle'>";
$requires .= "Approval received for this account type";
$requires .= "</div>";
}
if ( !($authobj->needs_pay) && ( $srcobj->needs_pay ) ) {
$requires .= "<div class='reqTitle'>";
$requires .= "Your payment has been received.";
$requires .= "</div>";
}
return($requires);
}
function format_requirements_message($authobj,$srcobj) {
$requires = "This type of account requires the following:";
if ( $authobj->needs_form && $srcobj->needs_form ) {
$requires .= "<div class='reqTitle'>";
$requires .= "More information";
$requires .= "</div>";
}
if ( $authobj->needs_approval && $srcobj->needs_approval ) {
$requires .= "<div class='reqTitle'>";
$requires .= "Approval by the administrator for this account type";
$requires .= "</div>";
}
if ( $authobj->needs_pay && $srcobj->needs_pay ) {
$requires .= "<div class='reqTitle'>";
$requires .= "Is accessible after a you pay a fee.";
$requires .= "</div>";
}
return($requires);
}
function fetch_authorization_state_forms($authobj) {
if ( $authobj->needs_form ) {
emit_requirements_form($objlist);
} else if ( $authobj->needs_approval ) {
format_state_message(t("Your request is being forwarded to an approval queue for examination by an administrator for this account type."));
to_approval_queue($objlist);
} else if ( $authobj->needs_pay ) {
$price = $authobj->price;
format_state_message(t("This account type requires a fee of $price."));
emit_payment_form($authobj);
}
}
///ID, UID, serviceid, account_type_id, needs_form, needs_approval, needs_pay, form, approval, price, registered, deal_accounts
function fetch_service_form($serviceid) { /// The form data needed to select an account type for this service
///
$qq = "select * from serivcesource where ( id = $serviceid )"; // Get the prototype..
$authobj = db_query_object($qq);
$authobj->requirements = format_requirements_message($authobj);
///
return($authobj);
}
function add_form_for_user($uid,$serviceid,$actype) {
///
$qq = "select au.*, ac.* from authspecials au INNER JOIN accounttypes ac on ( au.account_type_id = ac.id ) where ( au.UID = 0 ) AND (ac.type_name = '$actype') AND ( au.serviceid = $serviceid ) AND ( ac.serviceid = $serviceid )"; // Get the prototype..
$authobj = db_query_object($qq);
$ID = $authobj->ID;
// uid
$serviceid = $authobj->serviceid;
$account_type_id = $authobj->account_type_id;
$needs_form = $authobj->needs_form;
$needs_approval = $authobj->needs_approval;
$needs_pay = $authobj->needs_pay;
$form = $authobj->form;
$approval = $authobj->approval;
$price = $authobj->price;
$registered = $authobj->registered;
$deal_accounts = $authobj->deal_accounts;
/// Make a special copy for the user...
$ii = "insert into authspecials (ID, UID, serviceid, account_type_id, needs_form, needs_approval, needs_pay, form, price, registered, deal_accounts) VALUES";
$ii .= " ($ID, $uid, $serviceid, $account_type_id, $needs_form, $needs_approval, $needs_pay, '$form', '$price', $registered, '$deal_accounts')";
db_query_exe($ii);
}
function fetch_user_auth_state($uid, $servicename) {
global $payment_button;
global $SERVICE;
global $servicedir;
global $serviceid;
$qq = "select id from serivcesource where servicename = '$servicename'";
$serviceid = db_query_value($qq);
$qq = "select count(*) from authspecials where ( uid = $uid ) AND ( serviceid = $serviceid ) AND ( registered = 0 )";
$n = db_query_value($qq);
$output = "";
/// ----------------------------------
if ( $n > 0 ) {
$qq = "select * from authspecials where ( uid = $uid ) AND ( serviceid = $serviceid ) AND ( registered = 0 )";
$authobj = db_query_object($qq);
$qq = "select * from authspecials where ( id = $authobj->ID ) AND ( UID = 0 )";
$srcobj = db_query_object($qq);
$strattain = format_attainments_message($authobj,$srcobj);
$str = format_requirements_message($authobj,$srcobj);
$output .=<<<EODIV
<div class='requirementsStatment'>
$strattain
</div>
<div class='requirementsStatment'>
$str
</div>
<div id="FORM_STEP_$i" class="requirementsWorkflowStep" >
EODIV;
if ( $formobj->needs_pay ) {
$output .= '<form method="POST" action="accounttype/store_accounttype_form.php" onsubmit="fetch_payment_message();" target="payer">';
$output .= '<input type="hidden" NAME="workflowstep" value="pay" >';
$output .= '<input type="submit" NAME="continuer" value="next step: payment" >';
$output .= $payment_button;
} else {
/// Authorization given...
$output .= '<form method="POST" action="accounttype/store_accounttype_form.php" onsubmit="fetch_done_message();" target="registered">';
$output .= '<input type="hidden" NAME="workflowstep" value="registered" >';
$output .= '<input type="submit" NAME="continuer" value="next step: registered" >';
}
$output .=<<<EODIV
<input type="hidden" NAME="SERVICE" value="$SERVICE" >
<input type="hidden" NAME="servicedir" value="$servicedir" >
<input type="hidden" NAME="serviceid" value="$serviceid" >
<input type="hidden" NAME="fiz" value="$uid" >
</form></div>
EODIV;
$output .= "\n\n";
}
return($output);
}
function fetch_request_form($uid,$serviceid,$actypes) {
$qq = "select * from authspecials where (UID = '$uid') AND (serviceid = '$serviceid') AND (account_type_id in ($actypes)) "; // Get the prototype..
$authobj_l = db_query_object_list($qq);
return($authobj_l);
}
function map_acc_to_id($acctypes) {
$typenames = implode("','",$acctypes);
$qq = "select id from accounttypes where type_name in ('$typenames')";
$tl = db_query_list($qq);
$str = implode(",",$tl);
return($str);
}
function add_to_approval_queue($serviceid,$uid,$accounttype_ids) {
$now = datetime();
$values = "";
$sep = "";
$accounttype_ids_array = explode(",",$accounttype_ids);
foreach ( $accounttype_ids_array as $acid ) {
$values .= $sep . "(0, $uid, $serviceid, $acid, '$now')";
$sep = ",";
}
$ii = "insert into approval_queue (ID, UID, serviceid, account_type_id, whenadded) VALUES " . $values;
db_query_exe($ii);
}
function send_to_payment_queue($serviceid,$uid,$accounttype_ids) {
$now = datetime();
$payQ = "select price,id from authspecials where ( serviceid = $serviceid ) AND ( UID = $uid ) AND account_type_id in ( $accounttype_ids )";
$prices = db_query_object_list($payQ);
$values = "";
$sep = "";
foreach ( $prices as $priceobj ) {
$acid = $priceobj->id;
$price = $priceobj->price;
$values .= $sep . "(0, $uid, $serviceid, $acid, '$price', '$now')";
$sep = ",";
}
$ii = "insert into payment_queue (ID, UID, serviceid, account_type_id, price, whenadded) VALUES " . $values;
db_query_exe($ii);
}
function store_useful_post_data($post_array,$serviceid,$uid,$accounttype_ids) {
///
unset($post_array['SERVICE']);
unset($post_array['servicedir']);
unset($post_array['serviceid']);
unset($post_array['hasQuestionaire']);
unset($post_array['fiz']);
unset($post_array['accounttypes']);
unset($post_array['workflowstep']);
$text = "";
foreach ( $post_array as $key => $value ) {
$text .= "&$key=" . urlencode($value);
}
$uu = "update authspecials set POSTDATA = '$text' where ( serviceid = $serviceid ) AND ( UID = $uid ) AND account_type_id in ( $accounttype_ids )";
///ID, UID, serviceid, account_type_id, needs_form, needs_approval, needs_pay, form, approval, price, registered, deal_accounts
db_query_exe($uu);
}
function enocode_as_js($accobject) {
$ts = (array)($accobject);
$output = "{";
$sep = "";
foreach ( $ts as $key => $value ) {
$output .= $sep . "$key: '$value'";
$sep = ",";
}
$output = "}";
return($output);
}
function fetch_account_type_data($serviceid) {
$QQ = "SELECT ac.*, aut.* FROM accounttypes ac INNER JOIN authspecials aut ON ( ac.serviceid = aut.serviceid ) where ( aut.uid = 0 ) AND ( ac.serviceid = '$serviceid')";
$aclist = db_query_object_list($QQ);
$output = "<div class='account_type_report' style='width:95%;max-height:400px;'>\n";
$output .= "\t<div class='account_type_report_elem' style='width:95%' >";
///
$output .= "\t<span id='acc_name_$id' class='account_type_report_elem_id' >type_name</span>";
$output .= "\t<span id='acc_name_$id' class='account_type_report_elem_req' >needs_for</span>";
$output .= "\t<span id='acc_name_$id' class='account_type_report_elem_req' >needs_approval</span>";
$output .= "\t<span id='acc_name_$id' class='account_type_report_elem_req' >needs_pay</span>";
$output .= "\t<span id='acc_name_$id' class='account_type_report_elem_description' >description</span>";
foreach ( $aclist as $accobject ) {
$detaillist = enocode_as_js($accobject);
$jsdetails = "new account_type_details($detaillist)";
$output .= "<div class='account_type_report_elem' style='width:95%' onclick=\"edit_acc_type_details($jsdetails)\">";
///
$output .= "<span id='acc_name_$id' class='account_type_report_elem_id' >";
$output .= $aclist->type_name;
$output .= "</span>";
$output .= "<span id='acc_name_$id' class='account_type_report_elem_req' >";
$output .= ( $aclist->needs_form == 1 ) ? "X" : "_";
$output .= "</span>";
$output .= "<span id='acc_name_$id' class='account_type_report_elem_req' >";
$output .= ( $aclist->needs_approval == 1 ) ? "X" : "_";
$output .= "</span>";
$output .= "<span id='acc_name_$id' class='account_type_report_elem_req' >";
$output .= ( $aclist->needs_pay == 1 ) ? "X" : "_";
$output .= "</span>";
$output .= "<span id='acc_name_$id' class='account_type_report_elem_description' >";
$output .= $aclist->description;
$output .= "</span>";
///
$output .= "</div>\n";
}
$output .= "</div>\n";
return($output);
}
function store_account_type_data($serviceid,$js_accountdata) {
$accountdata = json_decode($js_accountdata);
$n = count($accountdata);
for ( $i = 0; $i < $n; $i++ ) {
$account_object = $accountdata[$i];
$UU = "UPDATE authspecials set ";
$sep = "";
foreach( $account_object as $key => $data ) {
if ( $key != 'id' ) {
$UU .= $sep . " $key = '$data'";
$sep = ",";
}
}
$id = $account_object['id'];
$UU .= "where id = '$id'";
db_query_exe($UU);
}
}
/*
*/
?>