Exemplo n.º 1
0
include_once "aur.inc.php";
set_lang();
check_sid();
$title = __("Add Proposal");
html_header($title);
if (isset($_COOKIE["AURSID"])) {
    $uid = uid_from_sid($_COOKIE["AURSID"]);
}
if (has_credential(CRED_TU_ADD_VOTE)) {
    if (!empty($_POST['addVote']) && !check_token()) {
        $error = __("Invalid token for user action.");
    }
    if (!empty($_POST['addVote']) && check_token()) {
        $error = "";
        if (!empty($_POST['user'])) {
            if (!uid_from_username($_POST['user'])) {
                $error .= __("Username does not exist.");
            } else {
                if (open_user_proposals($_POST['user'])) {
                    $error .= __("%s already has proposal running for them.", htmlentities($_POST['user']));
                }
            }
        }
        if (!empty($_POST['type'])) {
            switch ($_POST['type']) {
                case "add_tu":
                    /* Addition of a TU */
                    $len = 7 * 24 * 60 * 60;
                    $quorum = 0.66;
                    break;
                case "remove_tu":
Exemplo n.º 2
0
function pkg_search_page($SID = "")
{
    $dbh = DB::connect();
    /*
     * Get commonly used variables.
     * TODO: Reduce the number of database queries!
     */
    if ($SID) {
        $myuid = uid_from_sid($SID);
    }
    /* Sanitize paging variables. */
    if (isset($_GET['O'])) {
        $_GET['O'] = max(intval($_GET['O']), 0);
    } else {
        $_GET['O'] = 0;
    }
    if (isset($_GET["PP"])) {
        $_GET["PP"] = bound(intval($_GET["PP"]), 50, 250);
    } else {
        $_GET["PP"] = 50;
    }
    /*
     * FIXME: Pull out DB-related code. All of it! This one's worth a
     * choco-chip cookie, one of those nice big soft ones.
     */
    /* Build the package search query. */
    $q_select = "SELECT ";
    if ($SID) {
        $q_select .= "CommentNotify.UserID AS Notify,\n\t\t\t   PackageVotes.UsersID AS Voted, ";
    }
    $q_select .= "Users.Username AS Maintainer,\n\tPackages.Name, Packages.Version, Packages.Description,\n\tPackageBases.NumVotes, PackageBases.Popularity, Packages.ID,\n\tPackages.PackageBaseID, PackageBases.OutOfDateTS ";
    $q_from = "FROM Packages\n\tLEFT JOIN PackageBases ON (PackageBases.ID = Packages.PackageBaseID)\n\tLEFT JOIN Users ON (PackageBases.MaintainerUID = Users.ID) ";
    if ($SID) {
        /* This is not needed for the total row count query. */
        $q_from_extra = "LEFT JOIN PackageVotes\n\t\tON (PackageBases.ID = PackageVotes.PackageBaseID AND PackageVotes.UsersID = {$myuid})\n\t\tLEFT JOIN CommentNotify\n\t\tON (PackageBases.ID = CommentNotify.PackageBaseID AND CommentNotify.UserID = {$myuid}) ";
    } else {
        $q_from_extra = "";
    }
    $q_where = 'WHERE PackageBases.PackagerUID IS NOT NULL ';
    if (isset($_GET['K'])) {
        if (isset($_GET["SeB"]) && $_GET["SeB"] == "m") {
            /* Search by maintainer. */
            $q_where .= "AND Users.Username = "******" ";
        } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") {
            /* Search by submitter. */
            $q_where .= "AND SubmitterUID = " . intval(uid_from_username($_GET['K'])) . " ";
        } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") {
            /* Search by name. */
            $K = "%" . addcslashes($_GET['K'], '%_') . "%";
            $q_where .= "AND (Packages.Name LIKE " . $dbh->quote($K) . ") ";
        } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "b") {
            /* Search by package base name. */
            $K = "%" . addcslashes($_GET['K'], '%_') . "%";
            $q_where .= "AND (PackageBases.Name LIKE " . $dbh->quote($K) . ") ";
        } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "k") {
            /* Search by keywords. */
            $q_where .= construct_keyword_search($dbh, false);
        } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "N") {
            /* Search by name (exact match). */
            $q_where .= "AND (Packages.Name = " . $dbh->quote($_GET['K']) . ") ";
        } elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "B") {
            /* Search by package base name (exact match). */
            $q_where .= "AND (PackageBases.Name = " . $dbh->quote($_GET['K']) . ") ";
        } else {
            /* Keyword search (default). */
            $q_where .= construct_keyword_search($dbh, true);
        }
    }
    if (isset($_GET["do_Orphans"])) {
        $q_where .= "AND MaintainerUID IS NULL ";
    }
    if (isset($_GET['outdated'])) {
        if ($_GET['outdated'] == 'on') {
            $q_where .= "AND OutOfDateTS IS NOT NULL ";
        } elseif ($_GET['outdated'] == 'off') {
            $q_where .= "AND OutOfDateTS IS NULL ";
        }
    }
    $order = isset($_GET["SO"]) && $_GET["SO"] == 'd' ? 'DESC' : 'ASC';
    $q_sort = "ORDER BY ";
    $sort_by = isset($_GET["SB"]) ? $_GET["SB"] : '';
    switch ($sort_by) {
        case 'v':
            $q_sort .= "NumVotes " . $order . ", ";
            break;
        case 'p':
            $q_sort .= "Popularity " . $order . ", ";
            break;
        case 'w':
            if ($SID) {
                $q_sort .= "Voted " . $order . ", ";
            }
            break;
        case 'o':
            if ($SID) {
                $q_sort .= "Notify " . $order . ", ";
            }
            break;
        case 'm':
            $q_sort .= "Maintainer " . $order . ", ";
            break;
        case 'l':
            $q_sort .= "ModifiedTS " . $order . ", ";
            break;
        case 'a':
            /* For compatibility with old search links. */
            $q_sort .= "-ModifiedTS " . $order . ", ";
            break;
        default:
            break;
    }
    $q_sort .= " Packages.Name " . $order . " ";
    $q_limit = "LIMIT " . $_GET["PP"] . " OFFSET " . $_GET["O"];
    $q = $q_select . $q_from . $q_from_extra . $q_where . $q_sort . $q_limit;
    $q_total = "SELECT COUNT(*) " . $q_from . $q_where;
    $result = $dbh->query($q);
    $result_t = $dbh->query($q_total);
    if ($result_t) {
        $row = $result_t->fetch(PDO::FETCH_NUM);
        $total = $row[0];
    } else {
        $total = 0;
    }
    if ($result && $total > 0) {
        if (isset($_GET["SO"]) && $_GET["SO"] == "d") {
            $SO_next = "a";
        } else {
            $SO_next = "d";
        }
    }
    /* Calculate the results to use. */
    $first = $_GET['O'] + 1;
    /* Calculation of pagination links. */
    $per_page = $_GET['PP'] > 0 ? $_GET['PP'] : 50;
    $current = ceil($first / $per_page);
    $pages = ceil($total / $per_page);
    $templ_pages = array();
    if ($current > 1) {
        $templ_pages['« ' . __('First')] = 0;
        $templ_pages['‹ ' . __('Previous')] = ($current - 2) * $per_page;
    }
    if ($current - 5 > 1) {
        $templ_pages["..."] = false;
    }
    for ($i = max($current - 5, 1); $i <= min($pages, $current + 5); $i++) {
        $templ_pages[$i] = ($i - 1) * $per_page;
    }
    if ($current + 5 < $pages) {
        $templ_pages["... "] = false;
    }
    if ($current < $pages) {
        $templ_pages[__('Next') . ' &rsaquo;'] = $current * $per_page;
        $templ_pages[__('Last') . ' &raquo;'] = ($pages - 1) * $per_page;
    }
    include 'pkg_search_form.php';
    $searchresults = array();
    if ($result) {
        while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
            $searchresults[] = $row;
        }
    }
    include 'pkg_search_results.php';
    return;
}
Exemplo n.º 3
0
/**
 * Determine the user's ID in the database using a username or email address
 *
 * @param string $username The username or email address of an account
 *
 * @return string Return user ID if exists, otherwise null
 */
function uid_from_loginname($loginname)
{
    $uid = uid_from_username($loginname);
    if (!$uid) {
        $uid = uid_from_email($loginname);
    }
    return $uid;
}
Exemplo n.º 4
0
/**
 * Adopt or disown packages
 *
 * @param array $base_ids Array of package base IDs to adopt/disown
 * @param bool $action Adopts if true, disowns if false. Adopts by default
 * @param int $via Package request to close upon adoption
 *
 * @return array Tuple of success/failure indicator and error message
 */
function pkgbase_adopt($base_ids, $action = true, $via)
{
    $dbh = DB::connect();
    $uid = uid_from_sid($_COOKIE["AURSID"]);
    if (!$uid) {
        if ($action) {
            return array(false, __("You must be logged in before you can adopt packages."));
        } else {
            return array(false, __("You must be logged in before you can disown packages."));
        }
    }
    /* Verify package ownership. */
    $base_ids = sanitize_ids($base_ids);
    $q = "SELECT ID FROM PackageBases ";
    $q .= "WHERE ID IN (" . implode(",", $base_ids) . ") ";
    if ($action && !has_credential(CRED_PKGBASE_ADOPT)) {
        /* Regular users may only adopt orphan packages. */
        $q .= "AND MaintainerUID IS NULL";
    }
    if (!$action && !has_credential(CRED_PKGBASE_DISOWN)) {
        /* Regular users may only disown their own packages. */
        $q .= "AND MaintainerUID = " . $uid;
    }
    $result = $dbh->query($q);
    $base_ids = $result->fetchAll(PDO::FETCH_COLUMN, 0);
    /* Error out if the list of remaining packages is empty. */
    if (empty($base_ids)) {
        if ($action) {
            return array(false, __("You did not select any packages to adopt."));
        } else {
            return array(false, __("You did not select any packages to disown."));
        }
    }
    /*
     * Close package request if the disownment was initiated through the
     * request interface. NOTE: This needs to happen *before* the actual
     * disown operation. Otherwise, the former maintainer will not be
     * included in the Cc list of the request notification email.
     */
    if ($via) {
        pkgreq_close(intval($via), 'accepted', '');
    }
    /* Scan through pending orphan requests and close them. */
    if (!$action) {
        $username = username_from_sid($_COOKIE['AURSID']);
        foreach ($base_ids as $base_id) {
            $pkgreq_ids = pkgreq_by_pkgbase($base_id, 'orphan');
            foreach ($pkgreq_ids as $pkgreq_id) {
                pkgreq_close(intval($pkgreq_id), 'accepted', 'The user ' . $username . ' disowned the package.', true);
            }
        }
    }
    /* Adopt or disown the package. */
    if ($action) {
        $q = "UPDATE PackageBases ";
        $q .= "SET MaintainerUID = {$uid} ";
        $q .= "WHERE ID IN (" . implode(",", $base_ids) . ") ";
        $dbh->exec($q);
    } else {
        /* Update the co-maintainer list when disowning a package. */
        if (has_credential(CRED_PKGBASE_DISOWN)) {
            foreach ($base_ids as $base_id) {
                pkgbase_set_comaintainers($base_id, array());
            }
            $q = "UPDATE PackageBases ";
            $q .= "SET MaintainerUID = NULL ";
            $q .= "WHERE ID IN (" . implode(",", $base_ids) . ") ";
            $dbh->exec($q);
        } else {
            foreach ($base_ids as $base_id) {
                $comaintainers = pkgbase_get_comaintainers($base_id);
                if (count($comaintainers) > 0) {
                    $uid = uid_from_username($comaintainers[0]);
                    $comaintainers = array_diff($comaintainers, array($comaintainers[0]));
                    pkgbase_set_comaintainers($base_id, $comaintainers);
                } else {
                    $uid = "NULL";
                }
                $q = "UPDATE PackageBases ";
                $q .= "SET MaintainerUID = " . $uid . " ";
                $q .= "WHERE ID = " . $base_id;
                $dbh->exec($q);
            }
        }
    }
    if ($action) {
        pkgbase_notify($base_ids);
        return array(true, __("The selected packages have been adopted."));
    } else {
        return array(true, __("The selected packages have been disowned."));
    }
}