addvote.php 2.6 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
14

if (isset($_COOKIE["AURSID"])) {
  $atype = account_from_sid($_COOKIE["AURSID"]);
canyonknight's avatar
canyonknight committed
15
  $uid = uid_from_sid($_COOKIE["AURSID"]);
Callan Barrett's avatar
Callan Barrett committed
16
17
18
19
} else {
  $atype = "";
}

20
if ($atype == "Trusted User" || $atype == "Developer") {
21

22
23
24
25
26
	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
27
		$error = "";
28

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

canyonknight's avatar
canyonknight committed
34
				if (open_user_proposals($_POST['user'])) {
35
					$error.= __("%s already has proposal running for them.", htmlentities($_POST['user']));
Callan Barrett's avatar
Callan Barrett committed
36
37
38
39
				}
			}
		}

40
41
		if (!empty($_POST['length'])) {
			if (!is_numeric($_POST['length'])) {
42
				$error.=  __("Length must be a number.") ;
43
			} else if ($_POST['length'] < 1) {
44
				$error.= __("Length must be at least 1.");
45
46
47
48
49
50
51
52
			} else {
				$len = (60*60*24)*$_POST['length'];
			}
		} else {
			$len = 60*60*24*7;
		}

		if (empty($_POST['agenda'])) {
53
			$error.= __("Proposal cannot be empty.");
Callan Barrett's avatar
Callan Barrett committed
54
55
56
57
		}
	}

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

60
		print "<p class=\"pkgoutput\">" . __("New proposal submitted.") . "</p>\n";
Callan Barrett's avatar
Callan Barrett committed
61
62
	} else {
?>
63
64

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

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

Lukas Fleischer's avatar
Lukas Fleischer committed
71
	<form action="<?= get_uri('/addvote/'); ?>" method="post">
72
		<p>
Lukas Fleischer's avatar
Lukas Fleischer committed
73
			<b><?= __("Applicant/TU") ?></b>
74
			<input type="text" name="user" value="<?php if (!empty($_POST['user'])) { print htmlentities($_POST['user'], ENT_QUOTES); } ?>" />
Lukas Fleischer's avatar
Lukas Fleischer committed
75
			<?= __("(empty if not applicable)") ?>
76
77
		</p>
		<p>
Lukas Fleischer's avatar
Lukas Fleischer committed
78
			<b><?= __("Length in days") ?></b>
79
			<input type="text" name="length" value="<?php if (!empty($_POST['length'])) { print htmlentities($_POST['length'], ENT_QUOTES); } ?>" />
Lukas Fleischer's avatar
Lukas Fleischer committed
80
			<?= __("(defaults to 7 if empty)") ?>
81
82
		</p>
		<p>
Lukas Fleischer's avatar
Lukas Fleischer committed
83
		<b><?= __("Proposal") ?></b><br />
84
85
		<textarea name="agenda" rows="15" cols="80"><?php if (!empty($_POST['agenda'])) { print htmlentities($_POST['agenda']); } ?></textarea><br />
		<input type="hidden" name="addVote" value="1" />
Lukas Fleischer's avatar
Lukas Fleischer committed
86
87
		<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
		<input type="submit" class="button" value="<?= __("Submit"); ?>" />
88
89
		</p>
	</form>
90
</div>
Callan Barrett's avatar
Callan Barrett committed
91
92
93
<?php
	}
} else {
94
	print __("You are not allowed to access this area.");
Callan Barrett's avatar
Callan Barrett committed
95
96
97
98
}

html_footer(AUR_VERSION);