pkgbase.php 5.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');

include_once("aur.inc.php");
set_lang();
include_once('pkgfuncs.inc.php');
check_sid();

/*
 * Retrieve package base ID and name, unless initialized by the routing
 * framework.
 */
if (!isset($base_id) || !isset($pkgbase_name)) {
	if (isset($_GET['ID'])) {
		$base_id = intval($_GET['ID']);
		$pkgbase_name = pkgbase_name_from_id($_GET['ID']);
	} else if (isset($_GET['N'])) {
		$base_id = pkgbase_from_name($_GET['N']);
		$pkgbase_name = $_GET['N'];
	} else {
		unset($base_id, $pkgbase_name);
	}

25
	if (isset($base_id) && ($base_id == 0 || $base_id == NULL || $pkgbase_name == NULL)) {
26
27
28
29
30
31
32
33
34
		header("HTTP/1.0 404 Not Found");
		include "./404.php";
		return;
	}
}

/* Set the title to package base name. */
$title = $pkgbase_name;

35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Grab the list of package base IDs to be operated on. */
$ids = array();
if (isset($_POST['IDs'])) {
	foreach ($_POST['IDs'] as $id => $i) {
		$id = intval($id);
		if ($id > 0) {
			$ids[] = $id;
		}
	}
}

/* Perform package base actions. */
$ret = false;
$output = "";
Marcel Korpel's avatar
Marcel Korpel committed
49
$fragment = "";
50
51
if (check_token()) {
	if (current_action("do_Flag")) {
52
		list($ret, $output) = pkgbase_flag($ids, $_POST['comments']);
53
	} elseif (current_action("do_UnFlag")) {
Lukas Fleischer's avatar
Lukas Fleischer committed
54
		list($ret, $output) = pkgbase_unflag($ids);
55
	} elseif (current_action("do_Adopt")) {
Lukas Fleischer's avatar
Lukas Fleischer committed
56
		list($ret, $output) = pkgbase_adopt($ids, true, NULL);
57
	} elseif (current_action("do_Disown")) {
58
		if (isset($_POST['confirm'])) {
59
60
61
62
63
64
			$via = isset($_POST['via']) ? $_POST['via'] : NULL;
			list($ret, $output) = pkgbase_adopt($ids, false, $via);
		} else {
			$output = __("The selected packages have not been disowned, check the confirmation checkbox.");
			$ret = false;
		}
65
	} elseif (current_action("do_Vote")) {
Lukas Fleischer's avatar
Lukas Fleischer committed
66
		list($ret, $output) = pkgbase_vote($ids, true);
67
	} elseif (current_action("do_UnVote")) {
Lukas Fleischer's avatar
Lukas Fleischer committed
68
		list($ret, $output) = pkgbase_vote($ids, false);
69
	} elseif (current_action("do_Delete")) {
70
		if (isset($_POST['confirm'])) {
71
			$via = isset($_POST['via']) ? $_POST['via'] : NULL;
72
			if (!isset($_POST['merge_Into']) || empty($_POST['merge_Into'])) {
Lukas Fleischer's avatar
Lukas Fleischer committed
73
				list($ret, $output) = pkgbase_delete($ids, NULL, $via);
74
				unset($_GET['ID']);
75
				unset($base_id);
76
77
78
			}
			else {
				$merge_base_id = pkgbase_from_name($_POST['merge_Into']);
79
				if (!$merge_base_id) {
80
					$output = __("Cannot find package to merge votes and comments into.");
81
					$ret = false;
82
83
84
85
86
87
				} elseif (in_array($merge_base_id, $ids)) {
					$output = __("Cannot merge a package base with itself.");
					$ret = false;
				} else {
					list($ret, $output) = pkgbase_delete($ids, $merge_base_id, $via);
					unset($_GET['ID']);
88
					unset($base_id);
89
90
91
92
93
				}
			}
		}
		else {
			$output = __("The selected packages have not been deleted, check the confirmation checkbox.");
94
			$ret = false;
95
96
		}
	} elseif (current_action("do_Notify")) {
Lukas Fleischer's avatar
Lukas Fleischer committed
97
		list($ret, $output) = pkgbase_notify($ids);
98
	} elseif (current_action("do_UnNotify")) {
Lukas Fleischer's avatar
Lukas Fleischer committed
99
		list($ret, $output) = pkgbase_notify($ids, false);
100
	} elseif (current_action("do_DeleteComment")) {
Lukas Fleischer's avatar
Lukas Fleischer committed
101
		list($ret, $output) = pkgbase_delete_comment();
102
103
104
105
106
	} elseif (current_action("do_UndeleteComment")) {
		list($ret, $output) = pkgbase_delete_comment(true);
		if ($ret && isset($_POST["comment_id"])) {
			$fragment = '#comment-' . intval($_POST["comment_id"]);
		}
107
108
109
110
	} elseif (current_action("do_PinComment")) {
		list($ret, $output) = pkgbase_pin_comment();
	} elseif (current_action("do_UnpinComment")) {
		list($ret, $output) = pkgbase_pin_comment(true);
111
112
	} elseif (current_action("do_SetKeywords")) {
		list($ret, $output) = pkgbase_set_keywords($base_id, preg_split("/[\s,;]+/", $_POST['keywords'], -1, PREG_SPLIT_NO_EMPTY));
113
	} elseif (current_action("do_FileRequest")) {
114
		list($ret, $output) = pkgreq_file($ids, $_POST['type'], $_POST['merge_into'], $_POST['comments']);
115
	} elseif (current_action("do_CloseRequest")) {
116
		list($ret, $output) = pkgreq_close($_POST['reqid'], $_POST['reason'], $_POST['comments']);
117
118
	} elseif (current_action("do_EditComaintainers")) {
		list($ret, $output) = pkgbase_set_comaintainers($base_id, explode("\n", $_POST['users']));
Marcel Korpel's avatar
Marcel Korpel committed
119
	} elseif (current_action("do_AddComment")) {
120
		$uid = uid_from_sid($_COOKIE["AURSID"]);
Marcel Korpel's avatar
Marcel Korpel committed
121
		list($ret, $output) = pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']);
122
		$fragment = '#news';
123
124
	} elseif (current_action("do_EditComment")) {
		list($ret, $output) = pkgbase_edit_comment($_REQUEST['comment']);
Marcel Korpel's avatar
Marcel Korpel committed
125
126
127
		if ($ret && isset($_POST["comment_id"])) {
			$fragment = '#comment-' . intval($_POST["comment_id"]);
		}
128
129
130
	}

	if ($ret) {
131
132
		if (current_action("do_CloseRequest") ||
		    (current_action("do_Delete") && $_POST['via'])) {
133
134
135
136
			/* Redirect back to package request page on success. */
			header('Location: ' . get_pkgreq_route());
			exit();
		} if (isset($base_id)) {
137
			/* Redirect back to package base page on success. */
Marcel Korpel's avatar
Marcel Korpel committed
138
			header('Location: ' . get_pkgbase_uri($pkgbase_name) . $fragment);
139
140
141
142
143
144
145
146
147
			exit();
		} else {
			/* Redirect back to package search page. */
			header('Location: ' . get_pkg_route());
			exit();
		}
	}
}

148
$pkgs = pkgbase_get_pkgnames($base_id);
149
if (!$output && count($pkgs) == 1) {
150
	/* Not a split package. Redirect to the package page. */
151
	if (empty($_SERVER['QUERY_STRING'])) {
Marcel Korpel's avatar
Marcel Korpel committed
152
		header('Location: ' . get_pkg_uri($pkgs[0]) . $fragment);
153
	} else {
Marcel Korpel's avatar
Marcel Korpel committed
154
		header('Location: ' . get_pkg_uri($pkgs[0]) . '?' . $_SERVER['QUERY_STRING'] . $fragment);
155
	}
156
157
}

158
$details = pkgbase_get_details($base_id);
159
160
161
html_header($title, $details);
?>

162
<?php if ($output): ?>
163
<?php if ($ret): ?>
164
<p class="pkgoutput"><?= htmlspecialchars($output) ?></p>
165
<?php else: ?>
166
<ul class="errorlist"><li><?= htmlspecialchars($output) ?></li></ul>
167
<?php endif; ?>
168
169
<?php endif; ?>

170
171
172
<?php
include('pkg_search_form.php');
if (isset($_COOKIE["AURSID"])) {
173
	pkgbase_display_details($base_id, $details, $_COOKIE["AURSID"]);
174
} else {
175
	pkgbase_display_details($base_id, $details, null);
176
177
}

178
html_footer(AURWEB_VERSION);
179