Converted all short tags to full tags
[aur-xilon.git] / web / html / packages.php
blobe8aa5df4acc050ed466ef936b1a0b48f2786fd9e
1 <?php
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
12 # enable debugging
14 $DBUG = 0;
15 if ($DBUG) {
16 print "<pre>\n";
17 print_r($_REQUEST);
18 print "</pre>\n";
21 # get login privileges
23 if (isset($_COOKIE["AURSID"])) {
24 # Only logged in users can do stuff
26 $atype = account_from_sid($_COOKIE["AURSID"]);
27 } else {
28 $atype = "";
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"]) :
36 # $all_ids = array();
39 # determine what button the visitor clicked
41 if (isset($_REQUEST["do_Flag"])) {
42 if (!$atype) {
43 print __("You must be logged in before you can flag packages.");
44 print "<br />\n";
46 } else {
48 if (!empty($ids)) {
49 $dbh = db_connect();
51 # Flag the packages in $ids array
53 $first = 1;
54 while (list($pid, $v) = each($ids)) {
55 if ($first) {
56 $first = 0;
57 $flag = $pid;
58 } else {
59 $flag .= ", ".$pid;
62 $q = "UPDATE Packages SET OutOfDate = 1 ";
63 $q.= "WHERE ID IN (" . $flag . ")";
64 db_query($q, $dbh);
66 print "<p>\n";
67 print __("The selected packages have been flagged out-of-date.");
68 print "</p>\n";
69 } else {
70 print "<p>\n";
71 print __("You did not select any packages to flag.");
72 print "</p>\n";
75 pkgsearch_results_link();
79 } elseif (isset($_REQUEST["do_UnFlag"])) {
80 if (!$atype) {
81 print __("You must be logged in before you can unflag packages.");
82 print "<br />\n";
84 } else {
86 if (!empty($ids)) {
87 $dbh = db_connect();
89 # Un-Flag the packages in $ids array
91 $first = 1;
92 while (list($pid, $v) = each($ids)) {
93 if ($first) {
94 $first = 0;
95 $unflag = $pid;
96 } else {
97 $unflag .= ", ".$pid;
100 $q = "UPDATE Packages SET OutOfDate = 0 ";
101 $q.= "WHERE ID IN (" . $unflag . ")";
102 db_query($q, $dbh);
104 print "<p>\n";
105 print __("The selected packages have been unflagged.");
106 print "</p>\n";
107 } else {
108 print "<p>\n";
109 print __("You did not select any packages to unflag.");
110 print "</p>\n";
113 pkgsearch_results_link();
117 } elseif (isset($_REQUEST["do_Disown"])) {
118 if (!$atype) {
119 print __("You must be logged in before you can disown packages.");
120 print "<br />\n";
122 } else {
123 # Disown the packages in $ids array
125 if (!empty($ids)) {
126 $dbh = db_connect();
128 # Disown the packages in $ids array
130 $first = 1;
131 while (list($pid, $v) = each($ids)) {
132 if ($first) {
133 $first = 0;
134 $disown = $pid;
135 } else {
136 $disown .= ", ".$pid;
139 # Removed for now since we will have 1 maintainer
140 # PJM - 5 April 2005
141 # if ($atype == "Trusted User" || $atype == "Developer") {
142 # $field = "AURMaintainerUID";
143 # } elseif ($atype == "User") {
144 # $field = "MaintainerUID";
145 # } else {
146 # $field = "";
148 $field = "MaintainerUID";
149 if ($field) {
150 $q = "UPDATE Packages ";
151 $q.= "SET ".$field." = 0 ";
152 $q.= "WHERE ID IN (" . $disown . ") ";
153 $q.= "AND ".$field." = ".uid_from_sid($_COOKIE["AURSID"]);
154 db_query($q, $dbh);
157 print "<p>\n";
158 print __("The selected packages have been disowned.");
159 print "</p>\n";
160 } else {
161 print "<p>\n";
162 print __("You did not select any packages to disown.");
163 print "</p>\n";
166 pkgsearch_results_link();
171 } elseif (isset($_REQUEST["do_Delete"])) {
172 if (!$atype) {
173 print __("You must be logged in before you can disown packages.");
174 print "<br />\n";
175 } else {
176 # Delete the packages in $ids array (but only if they are Unsupported)
178 if (!empty($ids)) {
179 $dbh = db_connect();
181 # Delete the packages in $ids array
183 $first = 1;
184 while (list($pid, $v) = each($ids)) {
185 if ($first) {
186 $first = 0;
187 $delete = $pid;
188 } else {
189 $delete .= ", ".$pid;
192 # if ($atype == "Trusted User" || $atype == "Developer") {
193 # $field = "AURMaintainerUID";
194 # } elseif ($atype == "User") {
195 # $field = "MaintainerUID";
196 # } else {
197 # $field = "";
199 $field = "MaintainerUID";
200 if ($field) {
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);
212 } else {
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
259 print "<p>\n";
260 print __("The selected packages have been deleted.");
261 print "</p>\n";
263 } else {
264 print "<p>\n";
265 print __("None of the selected packages could be deleted.");
266 print "</p>\n";
267 } # end if (!empty($ids_to_delete))
268 } # end if ($field)
269 } else {
270 print "<p>\n";
271 print __("You did not select any packages to delete.");
272 print "</p>\n";
273 } # end if (!empty($ids))
274 pkgsearch_results_link();
275 } # end if (!atype)
277 } elseif (isset($_REQUEST["do_Adopt"])) {
278 if (!$atype) {
279 print __("You must be logged in before you can adopt packages.");
280 print "<br />\n";
282 } else {
283 # Adopt the packages in $ids array
285 if (!empty($ids)) {
286 $dbh = db_connect();
288 # Adopt the packages in $ids array
290 $first = 1;
291 while (list($pid, $v) = each($ids)) {
292 if ($first) {
293 $first = 0;
294 $adopt = $pid;
295 } else {
296 $adopt .= ", ".$pid;
299 # if ($atype == "Trusted User" || $atype == "Developer") {
300 # $field = "AURMaintainerUID";
301 # } elseif ($atype == "User") {
302 #$field = "MaintainerUID";
303 #} else {
304 # $field = "";
306 $field = "MaintainerUID";
307 if ($field) {
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";
321 db_query($q, $dbh);
324 print "<p>\n";
325 print __("The selected packages have been adopted.");
326 print "</p>\n";
327 } else {
328 print "<p>\n";
329 print __("You did not select any packages to adopt.");
330 print "</p>\n";
333 pkgsearch_results_link();
338 } elseif (isset($_REQUEST["do_Vote"])) {
339 if (!$atype) {
340 print __("You must be logged in before you can vote for packages.");
341 print "<br />\n";
343 } else {
344 # vote on the packages in $ids array.
346 if (!empty($ids)) {
347 $dbh = db_connect();
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
353 $first = 1;
354 while (list($pid, $v) = each($ids)) {
355 if (!isset($my_votes[$pid])) {
356 # cast a vote for this package
358 if ($first) {
359 $first = 0;
360 $vote_ids = $pid;
361 $vote_clauses = "(".$uid.", ".$pid.")";
362 } else {
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.")";
372 db_query($q, $dbh);
374 $q = "INSERT INTO PackageVotes (UsersID, PackageID) VALUES ";
375 $q.= $vote_clauses;
376 db_query($q, $dbh);
378 # Update the LastVoted field for this user
380 $q = "UPDATE Users SET LastVoted = UNIX_TIMESTAMP() ";
381 $q.= "WHERE ID = ".$uid;
382 db_query($q, $dbh);
384 print "<p>\n";
385 print __("Your votes have been cast for the selected packages.");
386 print "</p>\n";
388 } else {
389 print "<p>\n";
390 print __("You did not select any packages to vote for.");
391 print "</p>\n";
394 if (isset($_REQUEST["ID"])) {
395 pkgdetails_link($_REQUEST["ID"]);
396 } else {
397 pkgsearch_results_link();
403 } elseif (isset($_REQUEST["do_UnVote"])) {
404 if (!$atype) {
405 print __("You must be logged in before you can un-vote for packages.");
406 print "<br />\n";
408 } else {
409 # un-vote on the packages in $ids array.
411 if (!empty($ids)) {
412 $dbh = db_connect();
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.
418 $first = 1;
419 while (list($pid, $v) = each($ids)) {
420 if (isset($my_votes[$pid])) {
421 # cast a un-vote for this package
423 if ($first) {
424 $first = 0;
425 $unvote_ids = $pid;
426 } else {
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.")";
435 db_query($q, $dbh);
437 $q = "DELETE FROM PackageVotes WHERE UsersID = ".$uid." ";
438 $q.= "AND PackageID IN (".$unvote_ids.")";
439 db_query($q, $dbh);
441 print "<p>\n";
442 print __("Your votes have been removed from the selected packages.");
443 print "</p>\n";
445 } else {
446 print "<p>\n";
447 print __("You did not select any packages to un-vote for.");
448 print "</p>\n";
451 if (isset($_REQUEST["ID"])) {
452 pkgdetails_link($_REQUEST["ID"]);
453 } else {
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";
465 } else {
466 package_details($_REQUEST["ID"], $_COOKIE["AURSID"]);
469 print "<br />\n";
470 # FIXME: If someone hits the detail page's vote button, this link dies
471 pkgsearch_results_link();
474 } elseif (isset($_REQUEST["do_FlagSafe"])) {
475 if (!$atype) {
476 print __("You must be logged in before you can flag packages.");
477 print "<br />\n";
478 } else {
479 if (!empty($ids) && $atype == "Trusted User") {
480 $dbh = db_connect();
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;
485 db_query($q, $dbh);
486 print '<p>';
487 print __("The selected packages have been flagged safe.");
488 print '<br /></p>';
489 pkgdetails_link($pid);
491 } else {
492 print '<p>';
493 print __("Couldn't flag package safe.");
494 print '<br /></p>';
498 } elseif (isset($_REQUEST["do_UnFlagSafe"])) {
499 if (!$atype) {
500 print __("You must be logged in before you can unflag packages.");
501 print "<br />\n";
502 } else {
503 if (!empty($ids) && $atype == "Trusted User") {
504 $dbh = db_connect();
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;
509 db_query($q, $dbh);
510 print '<p>';
511 print __("The selected packages have been unflagged safe.");
512 print '<br /></p>';
513 pkgdetails_link($pid);
515 } else {
516 print '<p>';
517 print __("Couldn't unflag package safe.");
518 print '<br /></p>';
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
527 if (!$atype) {
528 print __("You must be logged in before you can get notifications on comments.");
529 print "<br />\n";
530 } else {
531 if (!empty($ids)) {
532 $dbh = db_connect();
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.')';
538 db_query($q, $dbh);
539 print '<p>';
540 print __("You have been added to the comment notification list.");
541 print '<br /></p>';
542 pkgdetails_link($pid);
544 } else {
545 print '<p>';
546 print __("Couldn't add to notification list.");
547 print '<br /></p>';
550 } elseif (isset($_REQUEST["do_UnNotify"])) {
551 if (!$atype) {
552 print __("You must be logged in before you can cancel notification on comments.");
553 print "<br />\n";
554 } else {
555 if (!empty($ids)) {
556 $dbh = db_connect();
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;
563 db_query($q, $dbh);
564 print '<p>';
565 print __("You have been removed from the comment notification list.");
566 print '<br /></p>';
567 pkgdetails_link($pid);
569 } else {
570 print '<p>';
571 print __("Couldn't remove from notification list.");
572 print '<br /></p>';
575 } else {
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