-
Notifications
You must be signed in to change notification settings - Fork 24
/
manage_account.php
98 lines (72 loc) · 2.72 KB
/
manage_account.php
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
<?php
require_once(__DIR__ . '/global.php');
require_once(__DIR__ . '/classes/User.php');
$user = User::require_login();
$account = $user->getCurrentAccount();
UserTools::preventCSRF();
$template_info = StartupAPI::getTemplateInfo();
$template_info['account_isAdmin'] = ($account->getUserRole($user) == Account::ROLE_ADMIN);
$template_info['useSubscriptions'] = UserConfig::$useSubscriptions;
$template_info['account_id'] = $account->getID();
$template_info['account_name'] = $account->getName();
$template_info['account_isActive'] = $account->isActive();
$template_info['account_engine'] = is_null($account->getPaymentEngine()) ? 'None' : $account->getPaymentEngine()->getTitle();
$next_charge = $account->getNextCharge();
if (!is_null($next_charge)) {
$template_info['account_next_charge'] = preg_replace("/ .*/", "", $next_charge);
}
$plan = $account->getPlan(); // can be FALSE
$template_info['planIsSet'] = $plan ? TRUE : FALSE;
if ($plan) {
$template_info['plan_slug'] = $plan->getSlug();
$template_info['plan_name'] = $plan->getName();
$template_info['plan_description'] = $plan->getDescription();
$template_info['plan_base_price'] = $plan->getBasePrice();
$template_info['plan_base_period'] = $plan->getBasePeriod();
$template_info['plan_details_url'] = $plan->getDetailsURL();
$template_info['plan_grace_period'] = $plan->getGracePeriod();
}
$account_users = $account->getUsers();
uasort($account_users, function($a, $b) {
return strcmp($a[0]->getName(), $b[0]->getName());
});
$users = array();
$admins = array();
foreach ($account_users as $user_and_role) {
$account_user = $user_and_role[0];
$role = $user_and_role[1];
$disabled = $account_user->isDisabled();
$user_role = array(
'id' => $account_user->getID(),
'name' => $account_user->getName(),
'admin' => $role ? true : false,
'disabled' => $disabled
);
if ($user->isTheSameAs($account_user)) {
$user_role['self'] = true;
}
$users[] = $user_role;
if ($role) {
$admins[] = $user_role;
}
}
$template_info['users'] = $users;
$template_info['admins'] = $admins;
if ($account->isIndividual()) {
$template_info['account_isIndividual'] = true;
if (count($admins) > 0) {
$template_info['user'] = $admins[0];
}
} else {
$template_info['account_isIndividual'] = false;
}
$template_info['individual_no_admins'] = false;
if ($template_info['account_isIndividual'] && count($admins) == 0) {
$template_info['individual_no_admins'] = true;
}
$template_info['show_user_list'] = TRUE;
if ($template_info['account_isIndividual'] && count($admins) == 1 && count($users) == 1) {
$template_info['show_user_list'] = FALSE;
};
$template_info['PAGE']['SECTION'] = 'account';
StartupAPI::$template->display('@startupapi/account/manage_account.html.twig', $template_info);