This repository has been archived by the owner on Apr 5, 2019. It is now read-only.
forked from basisentscheid/basisentscheid
/
ballot_edit.php
144 lines (130 loc) · 4.15 KB
/
ballot_edit.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
<?
/**
*
* @author Magnus Rosenbaum <dev@cmr.cx>
* @package Basisentscheid
*/
require "inc/common_http.php";
Login::access("member");
if (!empty($_GET['id'])) {
$ballot = new Ballot($_GET['id']);
if (!$ballot->id) {
error(_("This ballot does not exist!"));
}
$period = new Period($ballot->period);
if ($period->state=="ballot_preparation") {
warning(_("Ballot preparation has already begun, so ballots can not be changed anymore."));
redirect("ballots.php?period=".$period->id);
}
} else {
$period = new Period(@$_GET['period']);
if (!$period) {
error(_("The requested period does not exist!"));
}
if ($period->state=="ballot_preparation") {
warning(_("Ballot preparation has already begun, so ballots can not be changed anymore."));
redirect("ballots.php?period=".$period->id);
}
if ($period->state=="ballot_assignment") {
warning(_("Ballot assignment has already begun, so ballot applications are not allowed anymore."));
redirect("ballots.php?period=".$period->id);
}
$ballot = new Ballot;
$ballot->period = $period->id;
}
$_SESSION['ngroup'] = $period->ngroup;
if ($action) {
switch ($action) {
case "save":
Login::access_action("member");
action_required_parameters('name', 'agents', 'opening_hour', 'opening_minute', 'ngroup');
if ($period->state=="ballot_preparation") {
warning(_("Ballot preparation has already begun, so ballots can not be changed anymore."));
redirect("ballots.php?period=".$period->id);
}
$ballot->name = trim($_POST['name']);
$ballot->agents = trim($_POST['agents']);
$ballot->opening = sprintf("%02d:%02d:00", $_POST['opening_hour'], $_POST['opening_minute']);
$ballot->ngroup = intval($_POST['ngroup']);
if (!$ballot->name) {
warning(_("The ballot name must not be empty."));
break;
}
if (!$ballot->agents) {
warning(_("The ballot agents must not be empty."));
break;
}
if ($ballot->id) {
$ballot->update();
} else {
if ($period->state=="ballot_assignment") {
warning(_("Ballot assignment has already begun, so ballot applications are not allowed anymore."));
redirect("ballots.php?period=".$period->id);
}
$ballot->create();
if (!$ballot->id) {
warning(_("The ballot could not be created!"));
redirect();
}
}
$period->select_ballot($ballot, true);
redirect("ballots.php?period=".$period->id);
default:
warning(_("Unknown action"));
redirect();
}
}
if ($ballot->id) {
html_head(sprintf(_("Edit Ballot %d"), $ballot->id), true);
} else {
html_head(_("New ballot"), true);
}
form("", "", "editform edit_ballot", "ballot", true);
?>
<fieldset>
<div class="input <?=stripes()?>"><label for="name"><?=_("Name or location of the ballot")?></label><span class="input"><input type="text" name="name" id="name" value="<?=h($ballot->name)?>"></span></div>
<div class="input <?=stripes()?>"><label for="ngroup"><?=_("Group of location")?></label><span class="input">
<?
input_select("ngroup", Ngroup::options($period->ngroup()->parent), $ballot->ngroup, 'id="ngroup"');
?>
</span></div>
<div class="input <?=stripes()?>"><label for="opening_hour"><?=_("Opening hours")?></label><span class="input">
<select name="opening_hour" id="opening_hour">
<?
if ($ballot->opening) {
list($hour, $minute, $second) = explode(":", $ballot->opening);
} else {
$hour = 0;
$minute = 0;
}
list($close_hour, $close_minute) = explode(":", BALLOT_CLOSE_TIME);
for ( $h=0; $h<$close_hour; $h++ ) {
?>
<option value="<?=$h?>"<?
if ($h==$hour) { ?> selected<? }
?>><?=$h?></option>
<?
}
?>
</select>
:
<select name="opening_minute">
<?
for ( $m=0; $m<60; $m++ ) {
?>
<option value="<?=$m?>"<?
if ($m==$minute) { ?> selected<? }
?>><?=sprintf("%02d", $m)?></option>
<?
}
?>
</select>
— <?=BALLOT_CLOSE_TIME?>
</span></div>
<div class="input <?=stripes()?>"><label for="agents"><?=_("Agents")?></label><span class="input"><input type="text" name="agents" id="agents" value="<?=h($ballot->agents)?>"></span></div>
<div class="buttons th"><span class="cancel"><a href="ballots.php?period=<?=$period->id?>"><?=_("cancel")?></a></span><span class="input"><input type="submit" value="<?=_("Save")?>"></span></div>
</fieldset>
<input type="hidden" name="action" value="save">
<?
form_end();
html_foot();