3 set_include_path(get_include_path() . PATH_SEPARATOR
. '../lib' . PATH_SEPARATOR
. '../lang');
5 include("aur.inc"); # access AUR common functions
6 include("pkgfuncs.inc"); # package specific functions
7 include("search_po.inc"); # use some form of this for i18n support
8 set_lang(); # this sets up the visitor's language
9 check_sid(); # see if they're still logged in
10 html_header(); # print out the HTML header
21 # get login privileges
23 if (isset($_COOKIE["AURSID"])) {
24 # Only logged in users can do stuff
26 $atype = account_from_sid($_COOKIE["AURSID"]);
31 # grab the list of Package IDs to be operated on
33 isset($_REQUEST["IDs"]) ?
$ids = $_REQUEST["IDs"] : $ids = array();
34 #isset($_REQUEST["All_IDs"]) ?
35 # $all_ids = explode(":", $_REQUEST["All_IDs"]) :
39 # determine what button the visitor clicked
41 if (isset($_REQUEST["do_Flag"])) {
43 print __("You must be logged in before you can flag packages.");
51 # Flag the packages in $ids array
54 while (list($pid, $v) = each($ids)) {
62 $q = "UPDATE Packages SET OutOfDate = 1 ";
63 $q.= "WHERE ID IN (" . $flag . ")";
67 print __("The selected packages have been flagged out-of-date.");
71 print __("You did not select any packages to flag.");
75 pkgsearch_results_link();
79 } elseif (isset($_REQUEST["do_UnFlag"])) {
81 print __("You must be logged in before you can unflag packages.");
89 # Un-Flag the packages in $ids array
92 while (list($pid, $v) = each($ids)) {
100 $q = "UPDATE Packages SET OutOfDate = 0 ";
101 $q.= "WHERE ID IN (" . $unflag . ")";
105 print __("The selected packages have been unflagged.");
109 print __("You did not select any packages to unflag.");
113 pkgsearch_results_link();
117 } elseif (isset($_REQUEST["do_Disown"])) {
119 print __("You must be logged in before you can disown packages.");
123 # Disown the packages in $ids array
128 # Disown the packages in $ids array
131 while (list($pid, $v) = each($ids)) {
136 $disown .= ", ".$pid;
139 # Removed for now since we will have 1 maintainer
141 # if ($atype == "Trusted User" || $atype == "Developer") {
142 # $field = "AURMaintainerUID";
143 # } elseif ($atype == "User") {
144 # $field = "MaintainerUID";
148 $field = "MaintainerUID";
150 $q = "UPDATE Packages ";
151 $q.= "SET ".$field." = 0 ";
152 $q.= "WHERE ID IN (" . $disown . ") ";
153 $q.= "AND ".$field." = ".uid_from_sid($_COOKIE["AURSID"]);
158 print __("The selected packages have been disowned.");
162 print __("You did not select any packages to disown.");
166 pkgsearch_results_link();
171 } elseif (isset($_REQUEST["do_Delete"])) {
173 print __("You must be logged in before you can disown packages.");
176 # Delete the packages in $ids array (but only if they are Unsupported)
181 # Delete the packages in $ids array
184 while (list($pid, $v) = each($ids)) {
189 $delete .= ", ".$pid;
192 # if ($atype == "Trusted User" || $atype == "Developer") {
193 # $field = "AURMaintainerUID";
194 # } elseif ($atype == "User") {
195 # $field = "MaintainerUID";
199 $field = "MaintainerUID";
201 # Only grab Unsupported packages that "we" own or are not owned at all
203 $ids_to_delete = array();
204 $q = "SELECT Packages.ID FROM Packages, PackageLocations ";
205 $q.= "WHERE Packages.ID IN (" . $delete . ") ";
206 $q.= "AND Packages.LocationID = PackageLocations.ID ";
207 $q.= "AND PackageLocations.Location = 'unsupported' ";
208 # If they're a TU or dev, can always delete, otherwise check ownership
210 if ($atype == "Trusted User" ||
$atype == "Developer") {
211 $result = db_query($q, $dbh);
213 $q.= "AND $field IN (0, " . uid_from_sid($_COOKIE["AURSID"]) . ")";
214 $result = db_query($q, $dbh);
216 if ($result != Null && mysql_num_rows($result) > 0) {
217 while ($row = mysql_fetch_assoc($result)) {
218 $ids_to_delete[] = $row['ID'];
221 if (!empty($ids_to_delete)) {
222 # These are the packages that are safe to delete
224 foreach ($ids_to_delete as $id) {
225 # 1) delete from PackageVotes
226 $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id;
227 $result = db_query($q, $dbh);
229 # 2) delete from PackageContents
230 $q = "DELETE FROM PackageContents WHERE PackageID = " . $id;
231 $result = db_query($q, $dbh);
233 # 3) delete from PackageDepends
234 $q = "DELETE FROM PackageDepends WHERE PackageID = " . $id;
235 $result = db_query($q, $dbh);
237 # 4) delete from PackageSources
238 $q = "DELETE FROM PackageSources WHERE PackageID = " . $id;
239 $result = db_query($q, $dbh);
241 # 5) delete from PackageComments
242 $q = "DELETE FROM PackageComments WHERE PackageID = " . $id;
243 $result = db_query($q, $dbh);
245 # 6) delete from Packages
246 $q = "DELETE FROM Packages WHERE ID = " . $id;
247 $result = db_query($q, $dbh);
249 # 7) delete from CommentNotify
250 $q = "DELETE FROM CommentNotify WHERE PkgID = " . $id;
251 $result = db_query($q, $dbh);
253 # TODO question: Now that the package as been deleted, does
254 # the unsupported repo need to be regenerated?
255 # ANSWER: No, there is no actual repo for unsupported, so no worries! (PJM)
256 # TODO question: What about regenerating the AUR repo? (EJ)
258 # Print the success message
260 print __("The selected packages have been deleted.");
265 print __("None of the selected packages could be deleted.");
267 } # end if (!empty($ids_to_delete))
271 print __("You did not select any packages to delete.");
273 } # end if (!empty($ids))
274 pkgsearch_results_link();
277 } elseif (isset($_REQUEST["do_Adopt"])) {
279 print __("You must be logged in before you can adopt packages.");
283 # Adopt the packages in $ids array
288 # Adopt the packages in $ids array
291 while (list($pid, $v) = each($ids)) {
299 # if ($atype == "Trusted User" || $atype == "Developer") {
300 # $field = "AURMaintainerUID";
301 # } elseif ($atype == "User") {
302 #$field = "MaintainerUID";
306 $field = "MaintainerUID";
308 # NOTE: Only "orphaned" packages can be adopted at a particular
309 # user class (TU/Dev or User).
311 $q = "UPDATE Packages ";
312 $q.= "SET ".$field." = ".uid_from_sid($_COOKIE["AURSID"])." ";
313 $q.= "WHERE ID IN (" . $adopt . ") ";
314 if ($atype == "User")
316 # Regular users may only adopt orphan packages from unsupported
317 # FIXME: We assume that LocationID for unsupported is "2"
318 $q.= "AND ".$field." = 0";
319 $q.= " AND LocationID = 2";
325 print __("The selected packages have been adopted.");
329 print __("You did not select any packages to adopt.");
333 pkgsearch_results_link();
338 } elseif (isset($_REQUEST["do_Vote"])) {
340 print __("You must be logged in before you can vote for packages.");
344 # vote on the packages in $ids array.
348 $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]);
349 $uid = uid_from_sid($_COOKIE["AURSID"]);
350 # $vote_ids will contain the string of Package.IDs that
351 # the visitor hasn't voted for already
354 while (list($pid, $v) = each($ids)) {
355 if (!isset($my_votes[$pid])) {
356 # cast a vote for this package
361 $vote_clauses = "(".$uid.", ".$pid.")";
363 $vote_ids .= ", ".$pid;
364 $vote_clauses .= ", (".$uid.", ".$pid.")";
368 # only vote for packages the user hasn't already voted for
370 $q = "UPDATE Packages SET NumVotes = NumVotes + 1 ";
371 $q.= "WHERE ID IN (".$vote_ids.")";
374 $q = "INSERT INTO PackageVotes (UsersID, PackageID) VALUES ";
378 # Update the LastVoted field for this user
380 $q = "UPDATE Users SET LastVoted = UNIX_TIMESTAMP() ";
381 $q.= "WHERE ID = ".$uid;
385 print __("Your votes have been cast for the selected packages.");
390 print __("You did not select any packages to vote for.");
394 if (isset($_REQUEST["ID"])) {
395 pkgdetails_link($_REQUEST["ID"]);
397 pkgsearch_results_link();
403 } elseif (isset($_REQUEST["do_UnVote"])) {
405 print __("You must be logged in before you can un-vote for packages.");
409 # un-vote on the packages in $ids array.
413 $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]);
414 $uid = uid_from_sid($_COOKIE["AURSID"]);
415 # $unvote_ids will contain the string of Package.IDs that
416 # the visitor has voted for and wants to unvote.
419 while (list($pid, $v) = each($ids)) {
420 if (isset($my_votes[$pid])) {
421 # cast a un-vote for this package
427 $unvote_ids .= ", ".$pid;
431 # only un-vote for packages the user has already voted for
433 $q = "UPDATE Packages SET NumVotes = NumVotes - 1 ";
434 $q.= "WHERE ID IN (".$unvote_ids.")";
437 $q = "DELETE FROM PackageVotes WHERE UsersID = ".$uid." ";
438 $q.= "AND PackageID IN (".$unvote_ids.")";
442 print __("Your votes have been removed from the selected packages.");
447 print __("You did not select any packages to un-vote for.");
451 if (isset($_REQUEST["ID"])) {
452 pkgdetails_link($_REQUEST["ID"]);
454 pkgsearch_results_link();
460 } elseif (isset($_REQUEST["do_Details"])) {
462 if (!isset($_REQUEST["ID"]) ||
!intval($_REQUEST["ID"])) {
463 print __("Error trying to retrieve package details.")."<br />\n";
466 package_details($_REQUEST["ID"], $_COOKIE["AURSID"]);
470 # FIXME: If someone hits the detail page's vote button, this link dies
471 pkgsearch_results_link();
474 } elseif (isset($_REQUEST["do_FlagSafe"])) {
476 print __("You must be logged in before you can flag packages.");
479 if (!empty($ids) && $atype == "Trusted User") {
481 # There currently shouldn't be multiple requests here, but the format in which
482 # it's sent requires this
483 while (list($pid, $v) = each($ids)) {
484 $q = "UPDATE Packages SET Safe = 1, VerifiedBy = ".uid_from_sid($_COOKIE["AURSID"])." WHERE ID = ".$pid;
487 print __("The selected packages have been flagged safe.");
489 pkgdetails_link($pid);
493 print __("Couldn't flag package safe.");
498 } elseif (isset($_REQUEST["do_UnFlagSafe"])) {
500 print __("You must be logged in before you can unflag packages.");
503 if (!empty($ids) && $atype == "Trusted User") {
505 # There currently shouldn't be multiple requests here, but the format in which
506 # it's sent requires this
507 while (list($pid, $v) = each($ids)) {
508 $q = "UPDATE Packages SET Safe = 0 WHERE ID = ".$pid;
511 print __("The selected packages have been unflagged safe.");
513 pkgdetails_link($pid);
517 print __("Couldn't unflag package safe.");
522 } elseif (isset($_REQUEST["do_Notify"])) {
523 # I realize that the implementation here seems a bit convoluted, but we want to
524 # ensure that everything happens as it should, even if someone called this page
525 # without having clicked a button somewhere (naughty naughty). This also leaves
526 # room to someday expand and allow to add oneself to multiple lists at once. -SL
528 print __("You must be logged in before you can get notifications on comments.");
533 $uid = uid_from_sid($_COOKIE["AURSID"]);
534 # There currently shouldn't be multiple requests here, but the format in which
535 # it's sent requires this
536 while (list($pid, $v) = each($ids)) {
537 $q = "INSERT INTO CommentNotify (PkgID, UserID) VALUES (".$pid.', '.$uid.')';
540 print __("You have been added to the comment notification list.");
542 pkgdetails_link($pid);
546 print __("Couldn't add to notification list.");
550 } elseif (isset($_REQUEST["do_UnNotify"])) {
552 print __("You must be logged in before you can cancel notification on comments.");
557 $uid = uid_from_sid($_COOKIE["AURSID"]);
558 # There currently shouldn't be multiple requests here, but the format in which
559 # it's sent requires this
560 while (list($pid, $v) = each($ids)) {
561 $q = "DELETE FROM CommentNotify WHERE PkgID = ".$pid;
562 $q.= " AND UserID = ".$uid;
565 print __("You have been removed from the comment notification list.");
567 pkgdetails_link($pid);
571 print __("Couldn't remove from notification list.");
576 # do_More/do_Less/do_Search/do_MyPackages - just do a search
578 pkg_search_page($_COOKIE["AURSID"]);
582 html_footer("\$Id: packages.php 318 2006-09-17 20:36:55Z simo $");
583 # vim: ts=2 sw=2 noet ft=php