-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvariables.php
113 lines (96 loc) · 2.8 KB
/
variables.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
<?php
require 'inc.bootstrap.php';
do_logincheck();
if ( isset($_POST['manual_update']) ) {
$user->syncAnyAutoVar($_POST['manual_update']);
return do_redirect('variables');
}
else if ( isset($_POST['name'], $_POST['regex'], $_POST['replacement']) ) {
$invalid = count(array_filter($_POST)) != count($_POST);
if ( !$invalid ) {
$db->insert('variables', array(
'user_id' => $user->id,
'name' => trim($_POST['name']),
'regex' => trim($_POST['regex']),
'replacement' => trim($_POST['replacement']),
));
}
return do_redirect('variables');
}
else if ( isset($_POST['v']) ) {
foreach ( $_POST['v'] AS $id => $var ) {
$db->update('variables', $var, array('id' => $id, 'user_id' => $user->id));
}
return do_redirect('variables');
}
$_title = 'Variables';
include 'tpl.header.php';
?>
<style>
body:not(.show-editables) .editable { display: none; }
</style>
<h1>Your variables</h1>
<form autocomplete="off" action method="post">
<table border=1>
<thead>
<tr>
<th>Name</th>
<th class="editable">Regex</th>
<th class="editable">Replacement (XXX)</th>
<th>Value</th>
<th class="editable">Auto update type</th>
</tr>
</thead>
<tbody>
<? foreach ($user->variables as $var): ?>
<tr>
<td>
<input name="v[<?= $var->id ?>][name]" value="<?= html($var->name) ?>" size="10" class="manual-width" />
</td>
<td class="editable">
<input name="v[<?= $var->id ?>][regex]" value="<?= html($var->regex) ?>" />
</td>
<td class="editable">
<input name="v[<?= $var->id ?>][replacement]" value="<?= html($var->replacement) ?>" />
</td>
<td>
<input name="v[<?= $var->id ?>][value]" value="<?= html($var->value) ?>" size="6" class="manual-width" />
<?if ($var->auto_update_type): ?>
<button name="manual_update" value="<?= $var->auto_update_type ?>"><</button>
<?endif?>
</td>
<td class="editable">
<select name="v[<?= $var->id ?>][auto_update_type]">
<?= html_options(array(
'sprint' => 'Current sprint',
'sprints' => 'Current sprints',
), $var->auto_update_type, 'Custom') ?>
</select>
</td>
</tr>
<? endforeach ?>
</tbody>
</table>
<p>
(<a class="toggle-editables" href>edit</a>)
<button>Save</button>
</p>
</form>
<h2>Add variable</h2>
<form autocomplete="off" action method="post">
<p>Name: <input name="name" placeholder="Sprint #" /></p>
<p>Regex: <input name="regex" placeholder="sprint = \d+" /></p>
<p>Replacement: <input name="replacement" placeholder="sprint = XXX" /></p>
<p><button>Save</button></p>
</form>
<script>
$('.toggle-editables', true).on('click', function(e) {
e.preventDefault();
document.body.toggleClass('show-editables');
});
</script>
<?php
echo '<pre>';
print_r($user->filter_query_options);
echo '</pre>';
include 'tpl.footer.php';