Signed-off-by: Alexander Rødseth <[email protected]>
---
 web/lib/pkgfuncs.inc.php         |   49 ++++++++++++++++++++++++++++++++++++++
 web/template/pkg_search_form.php |   21 ++++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index 3e89fa3..9a2074e 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -92,6 +92,40 @@ function pkgCategories($dbh=NULL) {
        return $cats;
 }
 
+# grab the current list of distinct licenses
+#
+# "fromdb" is boolean and decides if the list of licenses
+# should be fetched from the available licenses in the database
+# or from a predefined list. Set to true or false here to make
+# either one the default. Set to false if the database load is too high.
+#
+function package_licenses($dbh=NULL, $fromdb=true) {
+       $lics = array();
+    if ($fromdb != false) {
+               if(!$dbh) {
+                       $dbh = db_connect();
+               }
+               $q = "SELECT DISTINCT License FROM Packages WHERE License != '' 
";
+               $q.= "ORDER BY License ASC";
+               $result = db_query($q, $dbh);
+               if ($result) {
+                       while ($row = mysql_fetch_row($result)) {
+                               $lics[] = $row[0];
+                       }
+               }
+    } else {
+               // All possible licenses from
+               // https://wiki.archlinux.org/index.php/PKGBUILD#license
+               $lics = array("AGPL", "AGPL3", "APACHE", "Apache", 
"Artistic2.0",
+                             "BSD", "CCPL", "CDDL", "CPL", "custom", "EPL", 
"FDL",
+                             "FDL1.2", "FDL1.3", "GPL", "GPL2", "GPL3", "LGPL",
+                             "LGPL2.1", "LGPL3", "LPPL", "MIT", "MPL", "PHP", 
"PSF",
+                             "PerlArtistic", "Python", "RUBY", "ZLIB", "ZPL");
+               // sort($lics);
+       }
+       return $lics;
+}
+
 # check to see if the package name exists
 #
 function pkgid_from_name($name="", $dbh=NULL) {
@@ -370,6 +404,9 @@ function package_details($id=0, $SID="", $dbh=NULL) {
  *                  s  - package submitter's username
  *    do_Orphans    - boolean. whether to search packages
  *                     without a maintainer
+ *    outdated - if the package is flagged: "on" or "off"
+ *    license - the license ID, where 0 is "Any"
+ *              license ID may change at any time
  *
  *
  *    These two are actually handled in packages.php.
@@ -396,6 +433,8 @@ function pkg_search_page($SID="", $dbh=NULL) {
                $myuid = uid_from_sid($SID, $dbh);
        // get a list of package categories
        $cats = pkgCategories($dbh); //meow
+       // get a list of licenses
+       $lics = package_licenses($dbh); // :-a
 
        // sanitize paging variables
        //
@@ -494,6 +533,16 @@ function pkg_search_page($SID="", $dbh=NULL) {
                        $q_where .= "AND OutOfDateTS IS NULL ";
                }
        }
+       
+       if (isset($_GET['license'])) {
+               // List ID ($lid) starts with 0 for "Any" and then enumerates 
the
+               // licenses from 1, which explains the "-1" below
+               $lid = intval($_GET["license"]);
+               if ($lid != 0) {
+                       // Make the query select on licenses too
+                       $q_where .= "AND Packages.License = '".$lics[$lid-1]."' 
";
+               }
+       }
 
        $order = (isset($_GET["SO"]) && $_GET["SO"] == 'd') ? 'DESC' : 'ASC';
 
diff --git a/web/template/pkg_search_form.php b/web/template/pkg_search_form.php
index 53d34fe..8c82859 100644
--- a/web/template/pkg_search_form.php
+++ b/web/template/pkg_search_form.php
@@ -119,6 +119,27 @@
                                                        ?>
                                                </select>
                                        </li>
+                                       <li>
+                                               <label><?php print 
__("License"); ?></label>
+                                               <select name='license'>
+                                                       <option value='0'><?php 
print __("Any"); ?></option>
+                                                       <?php
+                                                       $lics = 
package_licenses();
+                                                       for($id = 0; $id < 
sizeof($lics); ++$id):
+                                                               $lic = 
$lics[$id];
+                                                               // "Any" 
occupies slot 0
+                                                               $lid = $id+1;
+                                                               if 
(isset($_REQUEST['license']) && $_REQUEST['license'] == $lid):
+                                                       ?>
+                                                       <option value="<?php 
print $lid ?>" selected="selected"><?php print $lic; ?></option>
+                                                       <?php else: ?>
+                                                       <option value="<?php 
print $lid ?>"><?php print $lic; ?></option>
+                                                       <?php
+                                                               endif;
+                                                       endfor;
+                                                       ?>
+                                               </select>
+                                       </li>
                                </ul>
                        </div>
                        <?php endif; ?>
-- 
1.7.7

Reply via email to