From 36ee5561035af335bc3c900ded7aa89066421226 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Tue, 24 Jun 2008 02:53:16 -0400 Subject: Move code out of index.php Move database queries to functions and html to templates. Signed-off-by: Loui Chang --- web/lib/stats.inc | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 web/lib/stats.inc (limited to 'web/lib') diff --git a/web/lib/stats.inc b/web/lib/stats.inc new file mode 100644 index 00000000..e659210f --- /dev/null +++ b/web/lib/stats.inc @@ -0,0 +1,72 @@ += $targstamp OR Packages.ModifiedTS >= $targstamp)"; + $result = db_query($q, $dbh); + $row = mysql_fetch_row($result); + $update_count = $row[0]; + + include('stats/general_stats_table.php'); +} + -- cgit v1.2.3-24-g4f1b From 2feee92a75d4fe7042be52d1eef4e6e466af4967 Mon Sep 17 00:00:00 2001 From: Andrea Scarpino Date: Tue, 8 Jul 2008 18:56:42 +0200 Subject: Remember user between sessions. Signed-off-by: Loui Chang --- web/lib/acctfuncs.inc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'web/lib') diff --git a/web/lib/acctfuncs.inc b/web/lib/acctfuncs.inc index bbd6b740..73db2708 100644 --- a/web/lib/acctfuncs.inc +++ b/web/lib/acctfuncs.inc @@ -644,7 +644,12 @@ function try_login() { if ($logged_in) { # set our SID cookie - setcookie("AURSID", $new_sid, 0, "/"); + if ($_POST['remember_me'] == "on") + # Set cookies for 30 days. + $cookie_time = time() + (60 * 60 * 24 * 30); + else + $cookie_time = 0; + setcookie("AURSID", $new_sid, $cookie_time, "/"); # header("Location: /index.php"); header("Location: " . $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']); $login_error = ""; -- cgit v1.2.3-24-g4f1b From 1deb924674d1a42fc9b127a18bdc012c84ec6f93 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Wed, 9 Jul 2008 00:30:05 -0400 Subject: Make JSON search return more information. Signed-off-by: Loui Chang --- web/lib/aurjson.class.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'web/lib') diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index 953f5aba..6ff9b0f2 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -22,6 +22,8 @@ if (!extension_loaded('json')) class AurJSON { private $dbh = false; private $exposed_methods = array('search','info'); + private $fields = array('ID','Name','Version','Description', + 'URL','URLPath','License','NumVotes','OutOfDate'); /** * Handles post data, and routes the request. @@ -42,7 +44,9 @@ class AurJSON { // do the routing if ( in_array($http_data['type'], $this->exposed_methods) ) { // ugh. this works. I hate you php. - $json = call_user_func_array(array(&$this,$http_data['type']),$http_data['arg']); + $json = call_user_func_array(array(&$this,$http_data['type']), + $http_data['arg']); + // allow rpc callback for XDomainAjax if ( isset($http_data['callback']) ) { return $http_data['callback'] . "({$json})"; @@ -87,22 +91,22 @@ class AurJSON { } $keyword_string = mysql_real_escape_string($keyword_string, $this->dbh); - $query = sprintf( - "SELECT Name,ID FROM Packages WHERE ( Name LIKE '%%%s%%' OR Description LIKE '%%%s%%' ) AND DummyPkg=0", - $keyword_string, $keyword_string ); + + $query = "SELECT " . implode(',', $this->fields) . + " FROM Packages WHERE DummyPkg=0 AND "; + $query .= sprintf("( Name LIKE '%%%s%%' OR Description LIKE '%%%s%%' )", + $keyword_string, $keyword_string); $result = db_query($query, $this->dbh); if ( $result && (mysql_num_rows($result) > 0) ) { $search_data = array(); while ( $row = mysql_fetch_assoc($result) ) { - $elem = array( - 'Name' => $row['Name'], - 'ID' => $row['ID'] ); - array_push($search_data,$elem); - } + array_push($search_data, $row); + } + mysql_free_result($result); - return $this->json_results('search',$search_data); + return $this->json_results('search', $search_data); } else { return $this->json_error('No results found'); @@ -115,7 +119,8 @@ class AurJSON { * @return mixed Returns an array of value data containing the package data **/ private function info($pqdata) { - $base_query = "SELECT ID,Name,Version,Description,URL,URLPath,License,NumVotes,OutOfDate FROM Packages WHERE DummyPkg=0 AND "; + $base_query = "SELECT " . implode(',', $this->fields) . + " FROM Packages WHERE DummyPkg=0 AND "; if ( is_numeric($pqdata) ) { // just using sprintf to coerce the pqd to an int @@ -127,7 +132,8 @@ class AurJSON { if(get_magic_quotes_gpc()) { $pqdata = stripslashes($pqdata); } - $query_stub = sprintf("Name=\"%s\"",mysql_real_escape_string($pqdata)); + $query_stub = sprintf("Name=\"%s\"", + mysql_real_escape_string($pqdata)); } $result = db_query($base_query.$query_stub, $this->dbh); @@ -135,11 +141,11 @@ class AurJSON { if ( $result && (mysql_num_rows($result) > 0) ) { $row = mysql_fetch_assoc($result); mysql_free_result($result); - return $this->json_results('info',$row); + return $this->json_results('info', $row); } else { return $this->json_error('No result found'); } } } -?> + -- cgit v1.2.3-24-g4f1b From 1a1a6eb36e17315f08eee0e44a83fe4bdf0887f5 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Wed, 9 Jul 2008 14:38:08 -0400 Subject: Add a new DEFAULT_LANG constant. DEFAULT_LANG will essentially be used to specify what language strings are initially written in. This will eliminate the need for English translation arrays in AUR and make adding or changing the English strings a lot easier. DEFAULT_LANG may be required for strings to display properly. Also change the output when a translation isn't found. Eliminate the which can cause validation errors depending on where the string is placed. Signed-off-by: Loui Chang --- web/lib/aur.inc | 8 +++----- web/lib/config.inc.proto | 11 ++++++++--- web/lib/translator.inc | 9 ++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'web/lib') diff --git a/web/lib/aur.inc b/web/lib/aur.inc index 81ffde26..ade5b82c 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -311,12 +311,11 @@ function set_lang() { $LANG = $row[0]; } $update_cookie = 1; - } else { - $LANG = "en"; } + # Set $LANG to default if nothing is valid. if (!array_key_exists($LANG, $SUPPORTED_LANGS)) { - $LANG = "en"; # default to English + $LANG = DEFAULT_LANG; } if ($update_cookie) { @@ -336,7 +335,7 @@ function html_header($title="") { global $SUPPORTED_LANGS; $login = try_login(); - $login_error = $login['error']; + $login_error = $login['error']; $title = htmlspecialchars($title, ENT_QUOTES); @@ -410,4 +409,3 @@ function uid_from_username($username="") return $row[0]; } -?> diff --git a/web/lib/config.inc.proto b/web/lib/config.inc.proto index 7a0a155d..505fa7cc 100644 --- a/web/lib/config.inc.proto +++ b/web/lib/config.inc.proto @@ -16,9 +16,12 @@ define( "USERNAME_MAX_LEN", 16 ); define( "PASSWD_MIN_LEN", 4 ); define( "PASSWD_MAX_LEN", 128 ); -$LOGIN_TIMEOUT = 7200; # number of idle seconds before timeout +# Language that messages are initially written in. +# This should never change. +define("DEFAULT_LANG", "en"); -$SUPPORTED_LANGS = array( # what languages we have translations for +# Languages we have translations for +$SUPPORTED_LANGS = array( "en" => "English", "pl" => "Polski", "it" => "Italiano", @@ -30,4 +33,6 @@ $SUPPORTED_LANGS = array( # what languages we have translations for "fr" => "Français" ); -?> +# Idle seconds before timeout +$LOGIN_TIMEOUT = 7200; + diff --git a/web/lib/translator.inc b/web/lib/translator.inc index 41ece89b..f16bd11f 100644 --- a/web/lib/translator.inc +++ b/web/lib/translator.inc @@ -37,12 +37,16 @@ function __() { # First argument is always string to be translated $tag = $args[0]; - $translated = $_t[$LANG][$tag]; + if (empty($LANG) || $LANG == DEFAULT_LANG) + $translated = $tag; + else + $translated = $_t[$LANG][$tag]; + if (empty($translated)) { # if it's a supported language, but there isn't a translation, # alert the visitor to the missing translation. # - $translated = "_${tag}_"; + $translated = "_${tag}_"; } # This condition is to reorganise the arguments in case of @@ -63,4 +67,3 @@ function __() { return $translated; } -?> -- cgit v1.2.3-24-g4f1b From 2c6bae2e63c69f87599e5ef081eeba0a8d08bf00 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Wed, 23 Jul 2008 10:36:41 -0400 Subject: Convert special chars in translations to html entities. This closes FS#10809 - bug in french translation of AUR web interface Signed-off-by: Loui Chang --- web/lib/translator.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'web/lib') diff --git a/web/lib/translator.inc b/web/lib/translator.inc index f16bd11f..fb9ed635 100644 --- a/web/lib/translator.inc +++ b/web/lib/translator.inc @@ -25,7 +25,6 @@ include_once("common_po.inc"); - function __() { global $_t; global $LANG; @@ -49,6 +48,8 @@ function __() { $translated = "_${tag}_"; } + $translated = htmlspecialchars($translated, ENT_QUOTES); + # This condition is to reorganise the arguments in case of # deprecated usage. __("string", array("string","string")) if (!empty($args[1]) && is_array($args[1])) { @@ -64,6 +65,7 @@ function __() { $translated = preg_replace("/\%[sh]/", $args[$i], $translated, 1); } } + return $translated; } -- cgit v1.2.3-24-g4f1b From 1d416d6891d2945af6bfcc67ebfeb89e83195c60 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Tue, 19 Aug 2008 15:35:58 -0400 Subject: Add Turkish to SUPPORTED_LANGS in config.inc.proto. Signed-off-by: Loui Chang --- web/lib/config.inc.proto | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'web/lib') diff --git a/web/lib/config.inc.proto b/web/lib/config.inc.proto index 505fa7cc..7248b930 100644 --- a/web/lib/config.inc.proto +++ b/web/lib/config.inc.proto @@ -22,15 +22,16 @@ define("DEFAULT_LANG", "en"); # Languages we have translations for $SUPPORTED_LANGS = array( + "ca" => "Català", + "de" => "Deutsch", "en" => "English", - "pl" => "Polski", + "es" => "Español", + "fr" => "Français", "it" => "Italiano", - "ca" => "Català", + "pl" => "Polski", "pt" => "Português", - "es" => "Español", - "de" => "Deutsch", "ru" => "Русский", - "fr" => "Français" + "tr" => "Türkçe" ); # Idle seconds before timeout -- cgit v1.2.3-24-g4f1b From 52fb8550a21aeac6a6c75700c78be36de8983e15 Mon Sep 17 00:00:00 2001 From: Andrea Scarpino Date: Tue, 26 Aug 2008 17:49:26 +0200 Subject: doesn't show disown package when already disowned Signed-off-by: Callan Barrett --- web/lib/pkgfuncs.inc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'web/lib') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 77b0ab11..484e5a65 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -512,14 +512,12 @@ function package_details($id=0, $SID="") { if ($row["MaintainerUID"] == 0) { echo "\n"; - } - - if ($row["MaintainerUID"] == uid_from_sid($SID) || - account_from_sid($SID) == "Trusted User" || - account_from_sid($SID) == "Developer") { + } else if ($row["MaintainerUID"] == uid_from_sid($SID) || + account_from_sid($SID) == "Trusted User" || + account_from_sid($SID) == "Developer") { echo "\n"; - } + } if (account_from_sid($SID) == "Trusted User" || account_from_sid($SID) == "Developer") { -- cgit v1.2.3-24-g4f1b From 5c3f01909301f641f57b2ffe8b59609de6be2256 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Fri, 12 Sep 2008 20:19:42 -0400 Subject: Use system rm in rm_rf function. PHP can't properly handle symlinks which causes problems when self-referencing symlinks appear. This closes FS#11187. Signed-off-by: Loui Chang --- web/lib/aur.inc | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'web/lib') diff --git a/web/lib/aur.inc b/web/lib/aur.inc index ade5b82c..a126bb94 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -374,19 +374,10 @@ function can_submit_pkg($name="", $sid="") { # recursive delete directory # function rm_rf($dirname="") { - $d = dir($dirname); - while ($f = $d->read()) { - if ($f != "." && $f != "..") { - if (is_dir($dirname."/".$f)) { - rm_rf($dirname."/".$f); - } - if (is_file($dirname."/".$f) || is_link($dirname."/".$f)) { - unlink($dirname."/".$f); - } - } + if ($dirname != "") { + exec('rm -rf ' . escapeshellcmd($dirname)); } - $d->close(); - rmdir($dirname); + return; } -- cgit v1.2.3-24-g4f1b From df39cded09cb2a1ed9ee2f11207b28ccbb24fd51 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Mon, 29 Sep 2008 00:07:33 +0800 Subject: Sort required by list in package details page. This closes FS#11420. Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/lib/pkgfuncs.inc | 1 + 1 file changed, 1 insertion(+) (limited to 'web/lib') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 484e5a65..5ba56da0 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -128,6 +128,7 @@ function package_required($pkgid=0) { $q.= "WHERE PackageDepends.PackageID = Packages.ID "; $q.= "AND PackageDepends.DepPkgID = "; $q.= mysql_real_escape_string($pkgid); + $q.= " ORDER BY Name"; $result = db_query($q, $dbh); if (!$result) {return array();} while ($row = mysql_fetch_row($result)) { -- cgit v1.2.3-24-g4f1b From c7bfd9528473da0886afd328f0fa68e26c97ca3d Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Thu, 18 Sep 2008 22:16:40 -0400 Subject: Take formatting out of version number in web/lib/version.inc Signed-off-by: Loui Chang Signed-off-by: Callan Barrett --- web/lib/version.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/lib') diff --git a/web/lib/version.inc b/web/lib/version.inc index dcc2f3c2..9ef059f2 100644 --- a/web/lib/version.inc +++ b/web/lib/version.inc @@ -1,3 +1,3 @@ v1.5.2" ); +define( "AUR_VERSION", "v1.5.2" ); -- cgit v1.2.3-24-g4f1b From 78ace0914eb6a8c6cc39306ab586ab741aa25187 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Sun, 5 Oct 2008 20:24:57 -0400 Subject: Show developer-TUs their total community packages. This closes: FS#11561 - Devs in AUR can't see their packages in Community Thanks to Hugo Doria for the original patch. Signed-off-by: Loui Chang Signed-off-by: Callan Barrett --- web/lib/stats.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/lib') diff --git a/web/lib/stats.inc b/web/lib/stats.inc index e659210f..6fbc0334 100644 --- a/web/lib/stats.inc +++ b/web/lib/stats.inc @@ -29,7 +29,7 @@ function user_table($user, $dbh) # If the user is a TU calculate the number of the packages $atype = account_from_sid($_COOKIE["AURSID"]); - if ($atype == 'Trusted User') { + if (($atype == 'Trusted User') || ($atype == 'Developer')) { $result = db_query(sprintf($base_q, 'community'), $dbh); $row = mysql_fetch_row($result); $maintainer_community_count = $row[0]; -- cgit v1.2.3-24-g4f1b From 8f5882e68deec6a8780653ae537aea7aa02283c3 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 01:46:31 +0800 Subject: Convert package flagging to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/lib/pkgfuncs.inc | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'web/lib') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 5ba56da0..a508a0be 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -985,4 +985,76 @@ function pkg_search_page($SID="") { return; } -?> +function pkg_flag ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can flag packages."); + } else { + return __("You must be logged in before you can unflag packages."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to flag."); + } else { + return __("You did not select any packages to unflag."); + } + } + + foreach ($ids as $pid => $v) { + if (!is_numeric($pid)) { + if ($action) { + return __("You did not select any packages to flag."); + } else { + return __("You did not select any packages to unflag."); + } + } + } + + $dbh = db_connect(); + + $first = 1; + foreach ($ids as $pid => $v) { + if ($first) { + $first = 0; + $flag = $pid; + } else { + $flag .= ", " . $pid; + } + } + + $ood = $action ? 1 : 0; + $q = "UPDATE Packages SET OutOfDate = " . $ood; + $q.= " WHERE ID IN (" . $flag . ")"; + + db_query($q, $dbh); + + if ($action) { + # Notify of flagging by email + $f_name = username_from_sid($_COOKIE['AURSID']); + $f_email = email_from_sid($_COOKIE['AURSID']); + $f_uid = uid_from_sid($_COOKIE['AURSID']); + $q = "SELECT Packages.Name, Users.Email, Packages.ID "; + $q.= "FROM Packages, Users "; + $q.= "WHERE Packages.ID IN (" . $flag .") "; + $q.= "AND Users.ID = Packages.MaintainerUID "; + $q.= "AND Users.ID != " . $f_uid; + $result = db_query($q, $dbh); + if (mysql_num_rows($result)) { + while ($row = mysql_fetch_assoc($result)) { + # construct email + $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . ". You may view your package at:\nhttp://aur.archlinux.org/packages.php?ID=" . $row['ID']; + $body = wordwrap($body, 70); + $headers = "To: ".$row['Email']."\nReply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n"; + @mail(' ', "AUR Out-of-date Notification for ".$row['Name'], $body, $headers); + } + } + } + + if ($action) { + return __("The selected packages have been flagged out-of-date."); + } else { + return __("The selected packages have been unflagged."); + } +} -- cgit v1.2.3-24-g4f1b From a447281d4f5ce2071ebc81b375c70ae44231b046 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sat, 4 Oct 2008 03:42:34 +0800 Subject: Convert package deletion to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/lib/pkgfuncs.inc | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'web/lib') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index a508a0be..c952b85d 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1058,3 +1058,76 @@ function pkg_flag ($atype, $ids, $action = True) { return __("The selected packages have been unflagged."); } } + +function pkg_delete ($atype, $ids) { + if (!$atype) { + return __("You must be logged in before you can disown packages."); + } + + if (empty($ids)) { + return __("You did not select any packages to delete."); + } + + # Delete the packages in $ids array (but only if they are Unsupported) + # + $dbh = db_connect(); + + # Delete the packages in $ids array + # + $first = 1; + foreach ($ids as $pid => $v) { + if ($first) { + $first = 0; + $delete = $pid; + } else { + $delete .= ", ".$pid; + } + } + + $field = "MaintainerUID"; + + # Only grab Unsupported packages that "we" own or are not owned at all + $ids_to_delete = array(); + $q = "SELECT Packages.ID FROM Packages, PackageLocations "; + $q.= "WHERE Packages.ID IN (" . $delete . ") "; + $q.= "AND Packages.LocationID = PackageLocations.ID "; + $q.= "AND PackageLocations.Location = 'unsupported' "; + + # If they're a TU or dev, can delete + if ($atype == "Trusted User" || $atype == "Developer") { + $result = db_query($q, $dbh); + } + + if ($result != Null && mysql_num_rows($result) > 0) { + while ($row = mysql_fetch_assoc($result)) { + $ids_to_delete[] = $row['ID']; + } + } + + if (empty($ids_to_delete)) { + return __("None of the selected packages could be deleted."); + } + + # These are the packages that are safe to delete + foreach ($ids_to_delete as $id) { + $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageDepends WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageSources WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageComments WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM Packages WHERE ID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM CommentNotify WHERE PkgID = " . $id; + $result = db_query($q, $dbh); + } + + return __("The selected packages have been deleted."); +} -- cgit v1.2.3-24-g4f1b From 5d4303d0b6afacb2b3a8731bdb9fdbd6c40f5c0e Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 02:13:35 +0800 Subject: Convert package adoption/disowning to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/lib/pkgfuncs.inc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'web/lib') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index c952b85d..415f3e71 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1131,3 +1131,61 @@ function pkg_delete ($atype, $ids) { return __("The selected packages have been deleted."); } + +function pkg_adopt ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can adopt packages."); + } else { + return __("You must be logged in before you can disown packages."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to adopt."); + } else { + return __("You did not select any packages to disown."); + } + } + + $dbh = db_connect(); + + $first = 1; + foreach ($ids as $pid => $v) { + if ($first) { + $first = 0; + $pkg = $pid; + } else { + $pkg .= ", ".$pid; + } + } + + $field = "MaintainerUID"; + $q = "UPDATE Packages "; + + if ($action) { + $user = uid_from_sid($_COOKIE["AURSID"]); + } else { + $user = 0; + } + + $q.= "SET $field = $user "; + $q.= "WHERE ID IN ($pkg) "; + + if ($action && $atype == "User") { + # Regular users may only adopt orphan packages from unsupported + $q.= "AND $field = 0 "; + $q.= "AND LocationID = 2 "; + } else if ($atype == "User") { + $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]); + } + + db_query($q, $dbh); + + if ($action) { + return __("The selected packages have been adopted."); + } else { + return __("The selected packages have been disowned."); + } +} -- cgit v1.2.3-24-g4f1b From 132fd7cfc791a76f084140b2901018a046160b84 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 02:54:13 +0800 Subject: Convert package voting to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/lib/pkgfuncs.inc | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'web/lib') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 415f3e71..7fe3f317 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1189,3 +1189,80 @@ function pkg_adopt ($atype, $ids, $action = True) { return __("The selected packages have been disowned."); } } + +function pkg_vote ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can vote for packages."); + } else { + return __("You must be logged in before you can un-vote for packages."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to vote for."); + } else { + return __("Your votes have been removed from the selected packages."); + } + } + + $dbh = db_connect(); + $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); + $uid = uid_from_sid($_COOKIE["AURSID"]); + + $first = 1; + foreach ($ids as $pid => $v) { + if ($action) { + $check = !isset($my_votes[$pid]); + } else { + $check = isset($my_votes[$pid]); + } + + if ($check) { + if ($first) { + $first = 0; + $vote_ids = $pid; + if ($action) { + $vote_clauses = "($uid, $pid)"; + } + } else { + $vote_ids .= ", $pid"; + if ($action) { + $vote_clauses .= ", ($uid, $pid)"; + } + } + } + } + + # only vote for packages the user hasn't already voted for + # + $op = $action ? "+" : "-"; + $q = "UPDATE Packages SET NumVotes = NumVotes $op 1 "; + $q.= "WHERE ID IN ($vote_ids)"; + + db_query($q, $dbh); + + if ($action) { + $q = "INSERT INTO PackageVotes (UsersID, PackageID) VALUES "; + $q.= $vote_clauses; + } else { + $q = "DELETE FROM PackageVotes WHERE UsersID = $uid "; + $q.= "AND PackageID IN ($vote_ids)"; + } + + db_query($q, $dbh); + + if ($action) { + $q = "UPDATE Users SET LastVoted = UNIX_TIMESTAMP() "; + $q.= "WHERE ID = $uid"; + + db_query($q, $dbh); + } + + if ($action) { + return __("Your votes have been cast for the selected packages."); + } else { + return __("Your votes have been removed from the selected packages."); + } +} -- cgit v1.2.3-24-g4f1b