3 include_once("pkgbasefuncs.inc.php");
6 * Determine if the user can delete a specific package comment
8 * Only the comment submitter, Trusted Users, and Developers can delete
9 * comments. This function is used for the backend side of comment deletion.
11 * @param string $comment_id The comment ID in the database
13 * @return bool True if the user can delete the comment, otherwise false
15 function can_delete_comment($comment_id=0) {
18 $q = "SELECT UsersID FROM PackageComments ";
19 $q.= "WHERE ID = " . intval($comment_id);
20 $result = $dbh->query($q);
26 $uid = $result->fetch(PDO
::FETCH_COLUMN
, 0);
28 return has_credential(CRED_COMMENT_DELETE
, array($uid));
32 * Determine if the user can delete a specific package comment using an array
34 * Only the comment submitter, Trusted Users, and Developers can delete
35 * comments. This function is used for the frontend side of comment deletion.
37 * @param array $comment All database information relating a specific comment
39 * @return bool True if the user can delete the comment, otherwise false
41 function can_delete_comment_array($comment) {
42 return has_credential(CRED_COMMENT_DELETE
, array($comment['UsersID']));
46 * Determine if the visitor can submit blacklisted packages.
48 * Only Trusted Users and Developers can delete blacklisted packages. Packages
49 * are blacklisted if they are include in the official repositories.
51 * @return bool True if the user can submit blacklisted packages, otherwise false
53 function can_submit_blacklisted() {
54 return has_credential(CRED_PKGBASE_SUBMIT_BLACKLISTED
);
58 * Check to see if the package name already exists in the database
60 * @param string $name The package name to check
62 * @return string|void Package name if it already exists
64 function pkg_from_name($name="") {
65 if (!$name) {return NULL;}
67 $q = "SELECT ID FROM Packages ";
68 $q.= "WHERE Name = " . $dbh->quote($name);
69 $result = $dbh->query($q);
73 $row = $result->fetch(PDO
::FETCH_NUM
);
78 * Get licenses for a specific package
80 * @param int $pkgid The package to get licenses for
82 * @return array All licenses for the package
84 function pkg_licenses($pkgid) {
86 $pkgid = intval($pkgid);
89 $q = "SELECT l.Name FROM Licenses l ";
90 $q.= "INNER JOIN PackageLicenses pl ON pl.LicenseID = l.ID ";
91 $q.= "WHERE pl.PackageID = ". $pkgid;
92 $result = $dbh->query($q);
96 while ($row = $result->fetch(PDO
::FETCH_COLUMN
, 0)) {
104 * Get package groups for a specific package
106 * @param int $pkgid The package to get groups for
108 * @return array All package groups for the package
110 function pkg_groups($pkgid) {
112 $pkgid = intval($pkgid);
114 $dbh = DB
::connect();
115 $q = "SELECT g.Name FROM Groups g ";
116 $q.= "INNER JOIN PackageGroups pg ON pg.GroupID = g.ID ";
117 $q.= "WHERE pg.PackageID = ". $pkgid;
118 $result = $dbh->query($q);
122 while ($row = $result->fetch(PDO
::FETCH_COLUMN
, 0)) {
130 * Get package dependencies for a specific package
132 * @param int $pkgid The package to get dependencies for
134 * @return array All package dependencies for the package
136 function pkg_dependencies($pkgid) {
138 $pkgid = intval($pkgid);
140 $dbh = DB
::connect();
141 $q = "SELECT pd.DepName, dt.Name, pd.DepCondition, pd.DepArch, p.ID FROM PackageDepends pd ";
142 $q.= "LEFT JOIN Packages p ON pd.DepName = p.Name ";
143 $q.= "OR SUBSTRING(pd.DepName FROM 1 FOR POSITION(': ' IN pd.DepName) - 1) = p.Name ";
144 $q.= "LEFT JOIN DependencyTypes dt ON dt.ID = pd.DepTypeID ";
145 $q.= "WHERE pd.PackageID = ". $pkgid . " ";
146 $q.= "ORDER BY pd.DepName";
147 $result = $dbh->query($q);
151 while ($row = $result->fetch(PDO
::FETCH_NUM
)) {
159 * Get package relations for a specific package
161 * @param int $pkgid The package to get relations for
163 * @return array All package relations for the package
165 function pkg_relations($pkgid) {
167 $pkgid = intval($pkgid);
169 $dbh = DB
::connect();
170 $q = "SELECT pr.RelName, rt.Name, pr.RelCondition, pr.RelArch, p.ID FROM PackageRelations pr ";
171 $q.= "LEFT JOIN Packages p ON pr.RelName = p.Name ";
172 $q.= "LEFT JOIN RelationTypes rt ON rt.ID = pr.RelTypeID ";
173 $q.= "WHERE pr.PackageID = ". $pkgid . " ";
174 $q.= "ORDER BY pr.RelName";
175 $result = $dbh->query($q);
179 while ($row = $result->fetch(PDO
::FETCH_NUM
)) {
187 * Get the HTML code to display a package dependency link
189 * @param string $name The name of the dependency
190 * @param string $type The name of the dependency type
191 * @param string $cond The package dependency condition string
192 * @param string $arch The package dependency architecture
193 * @param int $pkg_id The package of the package to display the dependency for
195 * @return string The HTML code of the label to display
197 function pkg_depend_link($name, $type, $cond, $arch, $pkg_id) {
198 if ($type == 'optdepends' && strpos($name, ':') !== false) {
199 $tokens = explode(':', $name, 2);
207 if (is_null($pkg_id)) {
208 $link .= 'https://www.archlinux.org/packages/?q=' . urlencode($name);
210 $link .= htmlspecialchars(get_pkg_uri($name), ENT_QUOTES
);
212 $link .= '" title="' . __('View packages details for') .' ' . htmlspecialchars($name) . '">';
213 $link .= htmlspecialchars($name) . '</a>';
214 $link .= htmlspecialchars($cond);
216 if ($type != 'depends' ||
$arch) {
219 if ($type == 'makedepends') {
221 } elseif ($type == 'checkdepends') {
223 } elseif ($type == 'optdepends') {
227 if ($type != 'depends' && $arch) {
232 $link .= htmlspecialchars($arch);
236 if ($type == 'optdepends') {
237 $link .= ' – ' . htmlspecialchars($desc) . ' </em>';
246 * Get the HTML code to display a package relation
248 * @param string $name The name of the relation
249 * @param string $cond The package relation condition string
250 * @param string $arch The package relation architecture
252 * @return string The HTML code of the label to display
254 function pkg_rel_html($name, $cond, $arch) {
255 $html = htmlspecialchars($name) . htmlspecialchars($cond);
258 $html .= ' <em>(' . htmlspecialchars($arch) . ')</em>';
265 * Get the HTML code to display a source link
267 * @param string $url The URL of the source
268 * @param string $arch The source architecture
270 * @return string The HTML code of the label to display
272 function pkg_source_link($url, $arch) {
273 $url = explode('::', $url);
274 $parsed_url = parse_url($url[0]);
276 if (isset($parsed_url['scheme']) ||
isset($url[1])) {
277 $link = '<a href="' . htmlspecialchars((isset($url[1]) ?
$url[1] : $url[0]), ENT_QUOTES
) . '">' . htmlspecialchars($url[0]) . '</a>';
279 $link = htmlspecialchars($url[0]);
283 $link .= ' <em>(' . htmlspecialchars($arch) . ')</em>';
290 * Determine packages that depend on a package
292 * @param string $name The package name for the dependency search
294 * @return array All packages that depend on the specified package name
296 function pkg_required($name="") {
299 $dbh = DB
::connect();
300 $q = "SELECT DISTINCT p.Name, PackageID FROM PackageDepends pd ";
301 $q.= "JOIN Packages p ON pd.PackageID = p.ID ";
302 $q.= "WHERE DepName = " . $dbh->quote($name) . " ";
303 $q.= "ORDER BY p.Name";
304 $result = $dbh->query($q);
305 if (!$result) {return array();}
306 while ($row = $result->fetch(PDO
::FETCH_NUM
)) {
314 * Get all package sources for a specific package
316 * @param string $pkgid The package ID to get the sources for
318 * @return array All sources associated with a specific package
320 function pkg_sources($pkgid) {
322 $pkgid = intval($pkgid);
324 $dbh = DB
::connect();
325 $q = "SELECT Source, SourceArch FROM PackageSources ";
326 $q.= "WHERE PackageID = " . $pkgid;
327 $q.= " ORDER BY Source";
328 $result = $dbh->query($q);
332 while ($row = $result->fetch(PDO
::FETCH_NUM
)) {
340 * Determine package names from package IDs
342 * @param string|array $pkgids The package IDs to get names for
344 * @return array|string All names if multiple package IDs, otherwise package name
346 function pkg_name_from_id($pkgids) {
347 if (is_array($pkgids)) {
348 $pkgids = sanitize_ids($pkgids);
350 $dbh = DB
::connect();
351 $q = "SELECT Name FROM Packages WHERE ID IN (";
352 $q.= implode(",", $pkgids) . ")";
353 $result = $dbh->query($q);
355 while ($row = $result->fetch(PDO
::FETCH_ASSOC
)) {
356 $names[] = $row['Name'];
361 elseif ($pkgids > 0) {
362 $dbh = DB
::connect();
363 $q = "SELECT Name FROM Packages WHERE ID = " . $pkgids;
364 $result = $dbh->query($q);
366 $name = $result->fetch(PDO
::FETCH_NUM
);
376 * Determine if a package name is on the database blacklist
378 * @param string $name The package name to check
380 * @return bool True if the name is blacklisted, otherwise false
382 function pkg_name_is_blacklisted($name) {
383 $dbh = DB
::connect();
384 $q = "SELECT COUNT(*) FROM PackageBlacklist ";
385 $q.= "WHERE Name = " . $dbh->quote($name);
386 $result = $dbh->query($q);
388 if (!$result) return false;
389 return ($result->fetchColumn() > 0);
393 * Get the package details
395 * @param string $id The package ID to get description for
397 * @return array The package's details OR error message
399 function pkg_get_details($id=0) {
400 $dbh = DB
::connect();
402 $q = "SELECT Packages.*, PackageBases.ID AS BaseID, ";
403 $q.= "PackageBases.Name AS BaseName, PackageBases.CategoryID, ";
404 $q.= "PackageBases.NumVotes, PackageBases.OutOfDateTS, ";
405 $q.= "PackageBases.SubmittedTS, PackageBases.ModifiedTS, ";
406 $q.= "PackageBases.SubmitterUID, PackageBases.MaintainerUID, ";
407 $q.= "PackageBases.PackagerUID, PackageCategories.Category, ";
408 $q.= "(SELECT COUNT(*) FROM PackageRequests ";
409 $q.= " WHERE PackageRequests.PackageBaseID = Packages.PackageBaseID ";
410 $q.= " AND PackageRequests.Status = 0) AS RequestCount ";
411 $q.= "FROM Packages, PackageBases, PackageCategories ";
412 $q.= "WHERE PackageBases.ID = Packages.PackageBaseID ";
413 $q.= "AND PackageBases.CategoryID = PackageCategories.ID ";
414 $q.= "AND Packages.ID = " . intval($id);
415 $result = $dbh->query($q);
420 $row['error'] = __("Error retrieving package details.");
423 $row = $result->fetch(PDO
::FETCH_ASSOC
);
425 $row['error'] = __("Package details could not be found.");
433 * Display the package details page
435 * @param string $id The package ID to get details page for
436 * @param array $row Package details retrieved by pkg_get_details()
437 * @param string $SID The session ID of the visitor
441 function pkg_display_details($id=0, $row, $SID="") {
442 $dbh = DB
::connect();
444 if (isset($row['error'])) {
445 print "<p>" . $row['error'] . "</p>\n";
448 $base_id = pkgbase_from_pkgid($id);
449 $pkgbase_name = pkgbase_name_from_id($base_id);
451 include('pkg_details.php');
454 include('pkg_comment_form.php');
457 $limit = isset($_GET['comments']) ?
0 : 10;
458 $include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED
);
459 $comments = pkgbase_comments($base_id, $limit, $include_deleted);
460 if (!empty($comments)) {
461 include('pkg_comments.php');
466 /* pkg_search_page(SID)
467 * outputs the body of search/search results page
470 * SID - current Session ID
472 * package search page has been accessed
473 * request variables have not been sanitized
476 * O - starting result number
477 * PP - number of search hits per page
478 * C - package category ID number
479 * K - package search string
480 * SO - search hit sort order:
481 * values: a - ascending
483 * SB - sort search hits by:
484 * values: c - package category
486 * v - number of votes
487 * m - maintainer username
488 * SeB- property that search string (K) represents
489 * values: n - package name
490 * nd - package name & description
491 * x - package name (exact match)
492 * m - package maintainer's username
493 * s - package submitter's username
494 * do_Orphans - boolean. whether to search packages
495 * without a maintainer
498 * These two are actually handled in packages.php.
500 * IDs- integer array of ticked packages' IDs
501 * action - action to be taken on ticked packages
502 * values: do_Flag - Flag out-of-date
503 * do_UnFlag - Remove out-of-date flag
507 * do_Notify - Enable notification
508 * do_UnNotify - Disable notification
510 function pkg_search_page($SID="") {
511 $dbh = DB
::connect();
514 * Get commonly used variables.
515 * TODO: Reduce the number of database queries!
518 $myuid = uid_from_sid($SID);
519 $cats = pkgbase_categories($dbh);
521 /* Sanitize paging variables. */
522 if (isset($_GET['O'])) {
523 $_GET['O'] = max(intval($_GET['O']), 0);
528 if (isset($_GET["PP"])) {
529 $_GET["PP"] = bound(intval($_GET["PP"]), 50, 250);
535 * FIXME: Pull out DB-related code. All of it! This one's worth a
536 * choco-chip cookie, one of those nice big soft ones.
539 /* Build the package search query. */
540 $q_select = "SELECT ";
542 $q_select .= "CommentNotify.UserID AS Notify,
543 PackageVotes.UsersID AS Voted, ";
545 $q_select .= "Users.Username AS Maintainer,
546 PackageCategories.Category,
547 Packages.Name, Packages.Version, Packages.Description,
548 PackageBases.NumVotes, PackageBases.Popularity, Packages.ID,
549 Packages.PackageBaseID, PackageBases.OutOfDateTS ";
551 $q_from = "FROM Packages
552 LEFT JOIN PackageBases ON (PackageBases.ID = Packages.PackageBaseID)
553 LEFT JOIN Users ON (PackageBases.MaintainerUID = Users.ID)
554 LEFT JOIN PackageCategories
555 ON (PackageBases.CategoryID = PackageCategories.ID) ";
557 /* This is not needed for the total row count query. */
558 $q_from_extra = "LEFT JOIN PackageVotes
559 ON (PackageBases.ID = PackageVotes.PackageBaseID AND PackageVotes.UsersID = $myuid)
560 LEFT JOIN CommentNotify
561 ON (PackageBases.ID = CommentNotify.PackageBaseID AND CommentNotify.UserID = $myuid) ";
566 $q_where = 'WHERE PackageBases.PackagerUID IS NOT NULL ';
568 * TODO: Possibly do string matching on category to make request
569 * variable values more sensible.
571 if (isset($_GET["C"]) && intval($_GET["C"])) {
572 $q_where .= "AND PackageBases.CategoryID = ".intval($_GET["C"])." ";
575 if (isset($_GET['K'])) {
576 if (isset($_GET["SeB"]) && $_GET["SeB"] == "m") {
577 /* Search by maintainer. */
578 $q_where .= "AND Users.Username = " . $dbh->quote($_GET['K']) . " ";
580 elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") {
581 /* Search by submitter. */
582 $q_where .= "AND SubmitterUID = " . intval(uid_from_username($_GET['K'])) . " ";
584 elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") {
585 /* Search by name. */
586 $K = "%" . addcslashes($_GET['K'], '%_') . "%";
587 $q_where .= "AND (Packages.Name LIKE " . $dbh->quote($K) . ") ";
589 elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "b") {
590 /* Search by package base name. */
591 $K = "%" . addcslashes($_GET['K'], '%_') . "%";
592 $q_where .= "AND (PackageBases.Name LIKE " . $dbh->quote($K) . ") ";
594 elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "N") {
595 /* Search by name (exact match). */
596 $q_where .= "AND (Packages.Name = " . $dbh->quote($_GET['K']) . ") ";
598 elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "B") {
599 /* Search by package base name (exact match). */
600 $q_where .= "AND (PackageBases.Name = " . $dbh->quote($_GET['K']) . ") ";
603 /* Search by name and description (default). */
608 foreach (str_getcsv($_GET['K'], ' ') as $term) {
612 if ($count > 0 && strtolower($term) == "and") {
616 if ($count > 0 && strtolower($term) == "or") {
620 if ($count > 0 && strtolower($term) == "not") {
625 $term = "%" . addcslashes($term, '%_') . "%";
626 $q_keywords .= $op . " (Packages.Name LIKE " . $dbh->quote($term) . " OR ";
627 $q_keywords .= "Description LIKE " . $dbh->quote($term) . ") ";
636 if (!empty($q_keywords)) {
637 $q_where .= "AND (" . $q_keywords . ") ";
642 if (isset($_GET["do_Orphans"])) {
643 $q_where .= "AND MaintainerUID IS NULL ";
646 if (isset($_GET['outdated'])) {
647 if ($_GET['outdated'] == 'on') {
648 $q_where .= "AND OutOfDateTS IS NOT NULL ";
650 elseif ($_GET['outdated'] == 'off') {
651 $q_where .= "AND OutOfDateTS IS NULL ";
655 $order = (isset($_GET["SO"]) && $_GET["SO"] == 'd') ?
'DESC' : 'ASC';
657 $q_sort = "ORDER BY ";
658 $sort_by = isset($_GET["SB"]) ?
$_GET["SB"] : '';
661 $q_sort .= "CategoryID " . $order . ", ";
664 $q_sort .= "NumVotes " . $order . ", ";
667 $q_sort .= "Popularity " . $order . ", ";
671 $q_sort .= "Voted " . $order . ", ";
676 $q_sort .= "Notify " . $order . ", ";
680 $q_sort .= "Maintainer " . $order . ", ";
683 $q_sort .= "-ModifiedTS " . $order . ", ";
688 $q_sort .= " Packages.Name " . $order . " ";
690 $q_limit = "LIMIT ".$_GET["PP"]." OFFSET ".$_GET["O"];
692 $q = $q_select . $q_from . $q_from_extra . $q_where . $q_sort . $q_limit;
693 $q_total = "SELECT COUNT(*) " . $q_from . $q_where;
695 $result = $dbh->query($q);
696 $result_t = $dbh->query($q_total);
698 $row = $result_t->fetch(PDO
::FETCH_NUM
);
705 if ($result && $total > 0) {
706 if (isset($_GET["SO"]) && $_GET["SO"] == "d"){
714 /* Calculate the results to use. */
715 $first = $_GET['O'] +
1;
717 /* Calculation of pagination links. */
718 $per_page = ($_GET['PP'] > 0) ?
$_GET['PP'] : 50;
719 $current = ceil($first / $per_page);
720 $pages = ceil($total / $per_page);
721 $templ_pages = array();
724 $templ_pages['« ' . __('First')] = 0;
725 $templ_pages['‹ ' . __('Previous')] = ($current - 2) * $per_page;
728 if ($current - 5 > 1)
729 $templ_pages["..."] = false;
731 for ($i = max($current - 5, 1); $i <= min($pages, $current +
5); $i++
) {
732 $templ_pages[$i] = ($i - 1) * $per_page;
735 if ($current +
5 < $pages)
736 $templ_pages["... "] = false;
738 if ($current < $pages) {
739 $templ_pages[__('Next') . ' ›'] = $current * $per_page;
740 $templ_pages[__('Last') . ' »'] = ($pages - 1) * $per_page;
743 include('pkg_search_form.php');
746 while ($row = $result->fetch(PDO
::FETCH_ASSOC
)) {
747 $searchresults[] = $row;
751 include('pkg_search_results.php');
757 * Determine if a POST string has been sent by a visitor
759 * @param string $action String to check has been sent via POST
761 * @return bool True if the POST string was used, otherwise false
763 function current_action($action) {
764 return (isset($_POST['action']) && $_POST['action'] == $action) ||
765 isset($_POST[$action]);
769 * Determine if sent IDs are valid integers
771 * @param array $ids IDs to validate
773 * @return array All sent IDs that are valid integers
775 function sanitize_ids($ids) {
777 foreach ($ids as $id) {
787 * Add package information to the database for a specific package
789 * @param int $base_id ID of the package base
790 * @param string $pkgname Name of the new package
791 * @param string $pkgver Version of the new package
792 * @param string $pkgdesc Description of the new package
793 * @param string $pkgurl Upstream URL for the new package
795 * @return int ID of the new package
797 function pkg_create($base_id, $pkgname, $pkgver, $pkgdesc, $pkgurl) {
798 $dbh = DB
::connect();
799 $q = sprintf("INSERT INTO Packages (PackageBaseID, Name, Version, " .
800 "Description, URL) VALUES (%d, %s, %s, %s, %s)",
801 $base_id, $dbh->quote($pkgname), $dbh->quote($pkgver),
802 $dbh->quote($pkgdesc), $dbh->quote($pkgurl));
804 return $dbh->lastInsertId();
808 * Add a dependency for a specific package to the database
810 * @param int $pkgid The package ID to add the dependency for
811 * @param string $type The type of dependency to add
812 * @param string $depname The name of the dependency to add
813 * @param string $depcondition The type of dependency for the package
814 * @param string $deparch The architecture of the dependency to add
818 function pkg_add_dep($pkgid, $type, $depname, $depcondition, $deparch) {
819 $dbh = DB
::connect();
820 $q = sprintf("INSERT INTO PackageDepends (PackageID, DepTypeID, DepName, DepCondition, DepArch) VALUES (%d, %d, %s, %s, %s)",
822 pkg_dependency_type_id_from_name($type),
823 $dbh->quote($depname),
824 $dbh->quote($depcondition),
825 $deparch ?
$dbh->quote($deparch) : 'NULL'
831 * Add a relation for a specific package to the database
833 * @param int $pkgid The package ID to add the relation for
834 * @param string $type The type of relation to add
835 * @param string $relname The name of the relation to add
836 * @param string $relcondition The version requirement of the relation
837 * @param string $relarch The architecture of the relation to add
841 function pkg_add_rel($pkgid, $type, $relname, $relcondition, $relarch) {
842 $dbh = DB
::connect();
843 $q = sprintf("INSERT INTO PackageRelations (PackageID, RelTypeID, RelName, RelCondition, RelArch) VALUES (%d, %d, %s, %s, %s)",
845 pkg_relation_type_id_from_name($type),
846 $dbh->quote($relname),
847 $dbh->quote($relcondition),
848 $relarch ?
$dbh->quote($relarch) : 'NULL'
854 * Add a source for a specific package to the database
856 * @param int $pkgid The package ID to add the source for
857 * @param string $pkgsrc The package source to add to the database
858 * @param string $srcarch The architecture of the source to add
862 function pkg_add_src($pkgid, $pkgsrc, $srcarch) {
863 $dbh = DB
::connect();
864 $q = sprintf("INSERT INTO PackageSources (PackageID, Source, SourceArch) VALUES (%d, %s, %s)",
866 $dbh->quote($pkgsrc),
867 $srcarch ?
$dbh->quote($srcarch) : 'NULL'
873 * Creates a new group and returns its ID
875 * If the groups already exists, the ID of the already existing group is
878 * @param string $name The name of the group to create
880 * @return int The ID of the group
882 function pkg_create_group($name) {
883 $dbh = DB
::connect();
884 $q = sprintf("SELECT ID FROM Groups WHERE Name = %s", $dbh->quote($name));
885 $result = $dbh->query($q);
887 $grpid = $result->fetch(PDO
::FETCH_COLUMN
, 0);
893 $q = sprintf("INSERT INTO Groups (Name) VALUES (%s)", $dbh->quote($name));
895 return $dbh->lastInsertId();
899 * Add a package to a group
901 * @param int $pkgid The package ID of the package to add
902 * @param int $grpid The group ID of the group to add the package to
906 function pkg_add_grp($pkgid, $grpid) {
907 $dbh = DB
::connect();
908 $q = sprintf("INSERT INTO PackageGroups (PackageID, GroupID) VALUES (%d, %d)",
916 * Creates a new license and returns its ID
918 * If the license already exists, the ID of the already existing license is
921 * @param string $name The name of the license to create
923 * @return int The ID of the license
925 function pkg_create_license($name) {
926 $dbh = DB
::connect();
927 $q = sprintf("SELECT ID FROM Licenses WHERE Name = %s", $dbh->quote($name));
928 $result = $dbh->query($q);
930 $licid = $result->fetch(PDO
::FETCH_COLUMN
, 0);
936 $q = sprintf("INSERT INTO Licenses (Name) VALUES (%s)", $dbh->quote($name));
938 return $dbh->lastInsertId();
942 * Add a license to a package
944 * @param int $pkgid The package ID of the package
945 * @param int $grpid The ID of the license to add
949 function pkg_add_lic($pkgid, $licid) {
950 $dbh = DB
::connect();
951 $q = sprintf("INSERT INTO PackageLicenses (PackageID, LicenseID) VALUES (%d, %d)",
959 * Determine package information for latest package
961 * @param int $numpkgs Number of packages to get information on
963 * @return array $packages Package info for the specified number of recent packages
965 function latest_pkgs($numpkgs) {
966 $dbh = DB
::connect();
968 $q = "SELECT Packages.*, MaintainerUID, SubmittedTS ";
969 $q.= "FROM Packages LEFT JOIN PackageBases ON ";
970 $q.= "PackageBases.ID = Packages.PackageBaseID ";
971 $q.= "ORDER BY SubmittedTS DESC ";
972 $q.= "LIMIT " . intval($numpkgs);
973 $result = $dbh->query($q);
977 while ($row = $result->fetch(PDO
::FETCH_ASSOC
)) {