addvote.php 3.1 KB
Newer Older
Callan Barrett's avatar
Callan Barrett committed
1
2
<?php

3
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
Callan Barrett's avatar
Callan Barrett committed
4

5
include_once("aur.inc.php");
Callan Barrett's avatar
Callan Barrett committed
6
7
set_lang();
check_sid();
8
9
10
11

$title = __("Add Proposal");

html_header($title);
Callan Barrett's avatar
Callan Barrett committed
12
13

if (isset($_COOKIE["AURSID"])) {
Lukas Fleischer's avatar
Lukas Fleischer committed
14
	$uid = uid_from_sid($_COOKIE["AURSID"]);
Callan Barrett's avatar
Callan Barrett committed
15
16
}

Lukas Fleischer's avatar
Lukas Fleischer committed
17
if (has_credential(CRED_TU_ADD_VOTE)) {
18

19
20
21
22
23
	if (!empty($_POST['addVote']) && !check_token()) {
		$error = __("Invalid token for user action.");
	}

	if (!empty($_POST['addVote']) && check_token()) {
Callan Barrett's avatar
Callan Barrett committed
24
		$error = "";
25

26
		if (!empty($_POST['user'])) {
canyonknight's avatar
canyonknight committed
27
			if (!valid_user($_POST['user'])) {
28
				$error.= __("Username does not exist.");
Callan Barrett's avatar
Callan Barrett committed
29
30
			} else {

canyonknight's avatar
canyonknight committed
31
				if (open_user_proposals($_POST['user'])) {
32
					$error.= __("%s already has proposal running for them.", htmlentities($_POST['user']));
Callan Barrett's avatar
Callan Barrett committed
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
		if (!empty($_POST['type'])) {
			switch ($_POST['type']) {
			case "add_tu":
				/* Addition of a TU */
				$len = 7 * 24 * 60 * 60;
				$quorum = 0.66;
				break;
			case "remove_tu":
				/* Removal of a TU */
				$len = 7 * 24 * 60 * 60;
				$quorum = 0.75;
				break;
			case "remove_inactive_tu":
				/* Removal of a TU (undeclared inactivity) */
				$len = 5 * 24 * 60 * 60;
				$quorum = 0.66;
				break;
			case "bylaws":
				/* Amendment of Bylaws */
				$len = 7 * 24 * 60 * 60;
				$quorum = 0.75;
				break;
			default:
				$error.=  __("Invalid type.") ;
				break;
62
63
			}
		} else {
64
			$error.=  __("Invalid type.") ;
65
66
67
		}

		if (empty($_POST['agenda'])) {
68
			$error.= __("Proposal cannot be empty.");
Callan Barrett's avatar
Callan Barrett committed
69
70
71
72
		}
	}

	if (!empty($_POST['addVote']) && empty($error)) {
73
		add_tu_proposal($_POST['agenda'], $_POST['user'], $len, $quorum, $uid);
Callan Barrett's avatar
Callan Barrett committed
74

75
		print "<p class=\"pkgoutput\">" . __("New proposal submitted.") . "</p>\n";
Callan Barrett's avatar
Callan Barrett committed
76
77
	} else {
?>
78
79

<?php if (!empty($error)): ?>
Lukas Fleischer's avatar
Lukas Fleischer committed
80
	<p style="color: red;" class="pkgoutput"><?= $error ?></p>
81
82
<?php endif; ?>

83
<div class="box">
Lukas Fleischer's avatar
Lukas Fleischer committed
84
	<h2><?= __("Submit a proposal to vote on.") ?></h2>
85

Lukas Fleischer's avatar
Lukas Fleischer committed
86
	<form action="<?= get_uri('/addvote/'); ?>" method="post">
87
		<p>
Lukas Fleischer's avatar
Lukas Fleischer committed
88
89
			<label for="id_user"><?= __("Applicant/TU") ?></label>
			<input type="text" name="user" id="id_user" value="<?php if (!empty($_POST['user'])) { print htmlentities($_POST['user'], ENT_QUOTES); } ?>" />
Lukas Fleischer's avatar
Lukas Fleischer committed
90
			<?= __("(empty if not applicable)") ?>
91
92
		</p>
		<p>
93
94
95
96
97
98
99
			<label for="id_type"><?= __("Type") ?></label>
			<select name="type" id="id_type">
				<option value="add_tu"><?= __("Addition of a TU") ?></option>
				<option value="remove_tu"><?= __("Removal of a TU") ?></option>
				<option value="remove_inactive_tu"><?= __("Removal of a TU (undeclared inactivity)") ?></option>
				<option value="bylaws"><?= __("Amendment of Bylaws") ?></option>
			</select>
100
101
		</p>
		<p>
Lukas Fleischer's avatar
Lukas Fleischer committed
102
103
		<label for="id_agenda"><?= __("Proposal") ?></label><br />
		<textarea name="agenda" id="id_agenda" rows="15" cols="80"><?php if (!empty($_POST['agenda'])) { print htmlentities($_POST['agenda']); } ?></textarea><br />
104
		<input type="hidden" name="addVote" value="1" />
Lukas Fleischer's avatar
Lukas Fleischer committed
105
106
		<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
		<input type="submit" class="button" value="<?= __("Submit"); ?>" />
107
108
		</p>
	</form>
109
</div>
Callan Barrett's avatar
Callan Barrett committed
110
111
112
<?php
	}
} else {
113
	print __("You are not allowed to access this area.");
Callan Barrett's avatar
Callan Barrett committed
114
115
}

116
html_footer(AURWEB_VERSION);
Callan Barrett's avatar
Callan Barrett committed
117