Converted all short tags to full tags
[aur-xilon.git] / web / html / pkgedit.php
blob4bd354432d55ceacc14526da7d7811ad96840908
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"); # use some form of this for i18n support
7 include("pkgedit_po.inc"); # i18n translations for this script
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
11 $svn_idstr = "\$Id: pkgedit.php 295 2006-08-08 00:59:10Z pjmattal $";
13 $DBUG = 0;
14 if ($DBUG) {
15 print "<pre>\n";
16 print_r($_REQUEST);
17 print "</pre>\n";
20 # Make sure this visitor is logged in
22 if (isset($_COOKIE["AURSID"])) {
23 $atype = account_from_sid($_COOKIE["AURSID"]);
24 } else {
25 $atype = "";
27 if (!$atype) {
28 print __("You must be logged in before you can edit package information.");
29 print "<br />\n";
30 html_footer($svn_idstr);
31 exit();
34 # Must know what package to operate on throughout this entire script
36 if (!$_REQUEST["ID"]) {
37 print __("Missing package ID.");
38 print "<br />\n";
39 html_footer($svn_idstr);
43 # Delete a comment for this package
45 if ($_REQUEST["del_Comment"]) {
46 if ($_REQUEST["comment_id"]) {
47 if (canDeleteComment($_REQUEST["comment_id"], $atype, $_COOKIE["AURSID"])) {
48 $dbh = db_connect();
49 $uid = uid_from_sid($_COOKIE["AURSID"]);
50 $q = "UPDATE PackageComments ";
51 $q.= "SET DelUsersID = ".$uid." ";
52 $q.= "WHERE ID = ".intval($_REQUEST["comment_id"]);
53 db_query($q, $dbh);
54 print __("Comment has been deleted.")."<br />\n";
55 } else {
56 print __("You are not allowed to delete this comment.")."<br />\n";
58 } else {
59 print __("Missing comment ID.")."<br />\n";
61 pkgdetails_link($_REQUEST["ID"]);
62 html_footer($svn_idstr);
63 exit();
66 # Add a comment to this package
68 if ($_REQUEST["add_Comment"]) {
69 if ($_REQUEST["comment"]) {
70 # Insert the comment
72 $dbh = db_connect();
73 $q = "INSERT INTO PackageComments ";
74 $q.= "(PackageID, UsersID, Comments, CommentTS) VALUES (";
75 $q.= intval($_REQUEST["ID"]).", ".uid_from_sid($_COOKIE["AURSID"]) . ", ";
76 $q.= "'".mysql_real_escape_string($_REQUEST["comment"])."', ";
77 $q.= "UNIX_TIMESTAMP())";
78 db_query($q, $dbh);
79 print __("Comment has been added.")."<br />&nbsp;<br />\n";
80 pkgdetails_link($_REQUEST["ID"]);
82 # Send email notifications
84 $q = "SELECT CommentNotify.*, Users.Email ";
85 $q.= "FROM CommentNotify, Users ";
86 $q.= "WHERE Users.ID = CommentNotify.UserID ";
87 $q.= "AND CommentNotify.UserID != ".uid_from_sid($_COOKIE["AURSID"])." ";
88 $q.= "AND CommentNotify.PkgID = ".intval($_REQUEST["ID"]);
89 $result = db_query($q, $dbh);
90 $bcc = array();
91 if (mysql_num_rows($result)) {
92 while ($row = mysql_fetch_assoc($result)) {
93 array_push($bcc, $row['Email']);
95 $q = "SELECT Packages.Name ";
96 $q.= "FROM Packages ";
97 $q.= "WHERE Packages.ID = ".intval($_REQUEST["ID"]);
98 $result = db_query($q, $dbh);
99 $row = mysql_fetch_assoc($result);
100 #TODO: native language emails for users, based on their prefs
101 # Simply making these strings translatable won't work, users would be
102 # getting emails in the language that the user who posted the comment was in
103 $body = "A comment has been added to ".$row['Name'].", you may view it at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=".$_REQUEST["ID"]."\n\n\n---\nYou received this e-mail because you chose to recieve notifications of new comments on this package, if you no longer wish to recieve notifications about this package, please go the the above package page and click the UnNotify.";
104 $body = wordwrap($body, 70);
105 $bcc = implode(', ', $bcc);
106 $headers = "Bcc: $bcc\nReply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n";
107 @mail(' ', "AUR Comment Notification for ".$row['Name'], $body, $headers);
110 } else {
111 # Prompt visitor for comment
113 print "<form action='/pkgedit.php' method='post'>\n";
114 print "<input type='hidden' name='add_Comment' value='1'>\n";
115 print "<input type='hidden' name='ID' value=\"".$_REQUEST["ID"]."\">\n";
116 print __("Enter your comment below.")."<br />&nbsp;<br />\n";
117 print "<textarea name='comment' rows='10' cols='50'></textarea>\n";
118 print "<br />&nbsp;<br />\n";
119 print "<input type='submit' value=\"".__("Submit")."\">\n";
120 print "<input type='reset' value=\"".__("Reset")."\">\n";
121 print "</form>\n";
123 html_footer($svn_idstr);
124 exit();
127 # Change package category
129 if ($_REQUEST["change_Category"]) {
130 $cat_array = pkgCategories();
131 $dbh = db_connect();
133 if ($_REQUEST["category_id"]) {
134 # Try and set the requested category_id
136 if (array_key_exists($_REQUEST["category_id"], $cat_array)) {
137 $q = "UPDATE Packages SET CategoryID = ".intval($_REQUEST["category_id"]);
138 $q.= " WHERE ID = ".intval($_REQUEST["ID"]);
139 db_query($q, $dbh);
140 print __("Package category updated.")."<br />\n";
142 } else {
143 print __("Invalid category ID.")."<br />\n";
145 pkgdetails_link($_REQUEST["ID"]);
147 } else {
148 # Prompt visitor for new category_id
150 $q = "SELECT CategoryID FROM Packages WHERE ID = ".intval($_REQUEST["ID"]);
151 $result = db_query($q, $dbh);
152 if ($result != NULL) {
153 $catid = mysql_fetch_row($result);
155 print "<form action='/pkgedit.php' method='post'>\n";
156 print "<input type='hidden' name='change_Category' value='1'>\n";
157 print "<input type='hidden' name='ID' value=\"".$_REQUEST["ID"]."\">\n";
158 print __("Select new category").":&nbsp;\n";
159 print "<select name='category_id'>\n";
160 while (list($id,$cat) = each($cat_array)) {
161 print "<option value='".$id."'";
162 if ($id == $catid[0]) {
163 print " selected";
165 print "> ".$cat."</option>\n";
167 print "</select>\n";
168 print "<br />&nbsp;<br />\n";
169 print "<input type='submit' value=\"".__("Submit")."\">\n";
170 print "<input type='reset' value=\"".__("Reset")."\">\n";
171 print "</form>\n";
174 html_footer($svn_idstr);
175 exit();
178 print __("You've found a bug if you see this....")."<br />\n";
180 html_footer($svn_idstr); # Use the $Id: pkgedit.php 295 2006-08-08 00:59:10Z pjmattal $ keyword
181 # NOTE: when checking in a new file, use
182 # 'svn propset svn:keywords "Id" filename.php'
183 # to tell svn to expand the "Id" keyword.
185 # vim: ts=2 sw=2 noet ft=php