summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--genre.php6
-rw-r--r--lib/general.lib.php22
-rw-r--r--lib/search.php55
-rw-r--r--templates/show_search.inc28
4 files changed, 88 insertions, 23 deletions
diff --git a/genre.php b/genre.php
index fa060c38..0b4f94e4 100644
--- a/genre.php
+++ b/genre.php
@@ -40,6 +40,8 @@ switch($action) {
$songs = $genre->get_songs();
show_songs($songs);
break;
+ case 'show_genre':
+ default:
case 'show_albums':
$genre = new Genre($_REQUEST['genre_id']);
show_genre($_REQUEST['genre_id']);
@@ -52,10 +54,6 @@ switch($action) {
$artists = $genre->get_artists();
require (conf('prefix') . '/templates/show_artists.inc');
break;
- case 'show_genre':
- default:
- show_genre($_REQUEST['genre_id']);
- break;
} // action
diff --git a/lib/general.lib.php b/lib/general.lib.php
index 3dbe6d23..aa8f27a9 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -809,4 +809,26 @@ function scrub_out($str) {
} // scrub_out
+/**
+ * make_bool
+ * This takes a value and returns what I consider to be the correct boolean value
+ * This is used instead of settype alone because settype considers 0 and "false" to
+ * be true
+ * @package General
+ */
+function make_bool($string) {
+
+ if (strcasecmp($string,'false') == 0) {
+ return '0';
+ }
+
+ if ($string == '0') {
+ return '0';
+ }
+
+ return settype($string,"bool");
+
+} // make_bool
+
+
?>
diff --git a/lib/search.php b/lib/search.php
index 43d2f54d..c84791e8 100644
--- a/lib/search.php
+++ b/lib/search.php
@@ -40,14 +40,26 @@ function run_search($data) {
} // end foreach
/* Figure out if they want a AND based search or a OR based search */
+ switch($_REQUEST['operator']) {
+ case 'or':
+ $operator = 'OR';
+ break;
+ default:
+ $operator = 'AND';
+ break;
+ } // end switch on operator
+
+ /* Figure out what type of method they would like to use, exact or fuzzy */
switch($_REQUEST['method']) {
case 'fuzzy':
- $method = 'OR';
+ $method = "LIKE '%__%'";
break;
default:
- $method = 'AND';
+ $method = "= '__'";
break;
} // end switch on method
+
+ $limit = intval($_REQUEST['limit']);
/* Switch, and run the correct function */
switch($_REQUEST['object_type']) {
@@ -57,11 +69,11 @@ function run_search($data) {
case 'song':
$function_name = 'search_' . $_REQUEST['object_type'];
if (function_exists($function_name)) {
- $results = call_user_func($function_name,$search,$method);
+ $results = call_user_func($function_name,$search,$operator,$method,$limit);
return $results;
}
default:
- $results = search_song($search,$method);
+ $results = search_song($search,$operator,$method,$limit);
return $results;
break;
} // end switch
@@ -77,45 +89,53 @@ function run_search($data) {
* @package Search
* @catagory Search
*/
-function search_song($data,$method) {
+function search_song($data,$operator,$method,$limit) {
/* Generate BASE SQL */
$base_sql = "SELECT DISTINCT(song.id) FROM song";
$where_sql = '';
$table_sql = ',';
+ if ($limit > 0) {
+ $limit_sql = " LIMIT $limit";
+ }
+
+
foreach ($data as $type=>$value) {
-
+
+ /* Create correct Value statement based on method */
+ $value_string = str_replace("__",$value,$method);
+
switch ($type) {
case 'title':
- $where_sql .= " song.title LIKE '%$value%' $method";
+ $where_sql .= " song.title $value_string $operator";
break;
case 'album':
- $where_sql .= " ( song.album=album.id AND album.name LIKE '%$value%' ) $method";
+ $where_sql .= " ( song.album=album.id AND album.name $value_string ) $operator";
$table_sql .= "album,";
break;
case 'artist':
- $where_sql .= " ( song.artist=artist.id AND artist.name LIKE '%$value%' ) $method";
+ $where_sql .= " ( song.artist=artist.id AND artist.name $value_string ) $operator";
$table_sql .= "artist,";
break;
case 'genre':
- $where_sql .= " ( song.genre=genre.id AND genre.name LIKE '%$value%' ) $method";
+ $where_sql .= " ( song.genre=genre.id AND genre.name $value_string ) $operator";
$table_sql .= "genre,";
break;
case 'year':
- $where_sql .= " song.year LIKE '%$value%' $method";
+ $where_sql .= " song.year $value_string $operator";
break;
case 'filename':
- $where_sql .= " song.file LIKE '%$value%' $method";
+ $where_sql .= " song.file $value_string $operator";
break;
case 'played':
/* This is a 0/1 value so bool it */
- $value = settype($value, "bool");
- $where_sql .= " song.played = '$value' $method";
+ $value = make_bool($value);
+ $where_sql .= " song.played = '$value' $operator";
break;
case 'minbitrate':
$value = intval($value);
- $where_sql .= " song.bitrate >= '$value' $method";
+ $where_sql .= " song.bitrate >= '$value' $operator";
break;
default:
// Notzing!
@@ -127,9 +147,10 @@ function search_song($data,$method) {
/* Trim off the extra $method's and ,'s then combine the sucka! */
$table_sql = rtrim($table_sql,',');
- $where_sql = rtrim($where_sql,$method);
+ $where_sql = rtrim($where_sql,$operator);
+
+ $sql = $base_sql . $table_sql . " WHERE" . $where_sql . $limit_sql;
- $sql = $base_sql . $table_sql . " WHERE" . $where_sql;
$db_results = mysql_query($sql, dbh());
while ($r = mysql_fetch_assoc($db_results)) {
diff --git a/templates/show_search.inc b/templates/show_search.inc
index 31de22be..d10c6601 100644
--- a/templates/show_search.inc
+++ b/templates/show_search.inc
@@ -19,7 +19,12 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
+/* Setup the needed variables that check the correct boxes */
+foreach ($_REQUEST['search_object'] as $key) {
+ $name = "check_" . $key;
+ $field_name = $key . "_string";
+ ${$name} = "checked=\"checked\" onload=\"flipField('$field_name');\" ";
+}
/**
* search template
@@ -37,7 +42,7 @@
<tr class="<?php echo flip_class(); ?>">
<td><?php echo _("Title"); ?></td>
<td>
- <input type="checkbox" name="search_object[]" value="title" onclick="flipField('title_string');" />
+ <input type="checkbox" name="search_object[]" value="title" onclick="flipField('title_string');" <?php echo $check_title; ?> />
<input type="textbox" id="title_string" name="title_string" value="<?php echo scrub_out($_REQUEST['title_string']); ?>" disabled="disabled" />
</td>
<td><?php echo _("Artist"); ?></td>
@@ -110,6 +115,15 @@
<option value="genre"><?php echo _("Genres"); ?></option>
</select>
</td>
+ <td><?php echo _("Operator"); ?>:</td>
+ <td>
+ <select name="operator">
+ <option value="or"><?php echo _("OR"); ?></option>
+ <option value="and"><?php echo _("AND"); ?></option>
+ </select>
+ </td>
+</tr>
+<tr class="<?php echo flip_class(); ?>">
<td><?php echo _("Method"); ?>:</td>
<td>
<select name="method">
@@ -117,6 +131,16 @@
<option value="exact"><?php echo _("Exact"); ?></option>
</select>
</td>
+ <td><?php echo _("Maxium Results"); ?>:</td>
+ <td>
+ <select name="limit">
+ <option value="0"><?php echo _("Unlimited"); ?></option>
+ <option value="25">25</option>
+ <option value="50">50</option>
+ <option value="100">100</option>
+ <option value="500">500</option>
+ </select>
+ </td>
</tr>
<tr class="<?php echo flip_class(); ?>">
<td>&nbsp;</td>