-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccounts.php
198 lines (165 loc) · 4.48 KB
/
accounts.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
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
<?php
require 'inc.bootstrap.php';
do_logincheck();
$accounts = get_accounts();
// Add another account
if ( isset($_POST['url'], $_POST['user'], $_POST['pass']) ) {
$url = trim($_POST['url'], ' /');
$username = trim($_POST['user']);
if ( !jira_test($url, $username, $_POST['pass'], $info) ) {
exit($info['error2']);
}
// Save credentials to cookie
$auth = 'Basic ' . base64_encode($username . ':' . $_POST['pass']);
do_login($url, $auth, $username);
// Save user to local db for preferences
try {
$db->insert('users', array(
'jira_url' => $url,
'jira_user' => $username,
));
}
catch ( db_exception $ex ) {
// Let's assume it failed because the user already exists.
}
return do_redirect('accounts');
}
// Switch to other account
else if ( isset($_GET['switch']) ) {
$index = $_GET['switch'];
if ( !isset($accounts[$index]) ) {
exit('Invalid index');
}
// Move account to # 0
$account = $accounts[$index];
unset($accounts[$index]);
array_unshift($accounts, $account);
do_session($accounts);
return do_redirect('accounts');
}
// Unlink account
else if ( isset($_GET['unlink']) ) {
$index = $_GET['unlink'];
if ( !isset($accounts[$index]) || $accounts[$index]->active ) {
exit('Invalid index');
}
unset($accounts[$index]);
do_session($accounts);
return do_redirect('accounts');
}
// Save user config/options
else if ( isset($_POST['config']) ) {
$db->delete('options', array('user_id' => $user->id));
foreach ($_POST['config'] as $name => $value) {
if ( isset(User::$_config[$name]) ) {
$db->insert('options', array(
'user_id' => $user->id,
'name' => $name,
'value' => implode(',', (array) $value),
));
}
}
return do_redirect('accounts');
}
// Unsync & re-sync
else if ( isset($_POST['unsync']) ) {
$user->unsync();
return do_redirect('accounts');
}
// Reset cookies
do_session(get_accounts());
$_title = 'Accounts';
include 'tpl.header.php';
?>
<style>
label:after {
content: '\A';
white-space: pre;
}
:not(:checked) + .board-id {
display: none;
}
</style>
<h1>Accounts</h1>
<ul>
<?foreach ($accounts as $i => $account):
?>
<li class="<?if ($account->active):?>active-account<?endif?>">
<?= html($account->getLabel()) ?>
<?if (!$account->active):?>
(<a href="?switch=<?= $i ?>">switch</a>)
(<a href="?unlink=<?= $i ?>">x</a>)
<?endif?>
</li>
<?endforeach?>
</ul>
<p><a href="logout.php">Log out all accounts</a></p>
<p><form method="post" action><button name="unsync" value="1">Reset cache</button></form></p>
<h2>Config for <span style="display: inline-block"><?= html($user->jira_id) ?></span></h2>
<form method="post">
<table>
<? foreach (array_filter(User::$_config) as $name => $info):
$checkbox = $info['type'] == 'checkbox';
?>
<tr>
<th align="right">
<input
id="config_<?= $name ?>"
type="<?= $info['type'] ?>"
name="config[<?= $name ?>]"
<?if ($checkbox): ?>
<?if ($user->config($name)):?>checked<?endif?>
<?else:?>
value="<?= html($user->config($name)) ?>"
<?endif?>
style="width: <?= $info['size'] ?>em"
<?if ($info['required']):?>required<?endif?>
/>
</th>
<td>
<?if ($info['required']):?> <span class="required">*</span><?endif?>
<label for="config_<?= $name ?>"><?= html($info['label']) ?></label>
</td>
</tr>
<? endforeach ?>
<tr>
<th align="right">Tempo</th>
<td><a href="tempo.php">probably <?= $user->has_tempo ? '' : 'not' ?></a></td>
</tr>
<tr valign="top">
<th align="right">Agile boards</th>
<td style="white-space: normal">
<? foreach ($user->agile_boards as $id => $name):
$checked = in_array($id, $user->selected_agile_boards) ? 'checked' : '';
?>
<label>
<input type="checkbox" name="config[agile_view_ids][]" value="<?= $id ?>" <?= $checked ?> />
<span class="board-id">(<?= $id ?>)</span>
<?= html($name) ?>
</label>
<? endforeach ?>
</td>
</tr>
<tr valign="top">
<th align="right">Show custom fields</th>
<td>
<? foreach ($user->custom_field_ids as $name => $id):
$checked = in_array($id, $user->selected_show_custom_fields) ? 'checked' : '';
?>
<label>
<input type="checkbox" name="config[show_custom_fields][]" value="<?= $id ?>" <?= $checked ?> />
<span class="board-id">(<?= $id ?>)</span>
<?= html($name) ?>
</label>
<? endforeach ?>
</td>
</tr>
</table>
<p><button>Save</button></p>
</form>
<h2>Add account</h2>
<?php
include 'tpl.login.php';
?>
<?php
include 'tpl.footer.php';