diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-26 21:42:25 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-26 21:42:25 +0000 |
commit | 380a8615ae97295f650699e8ecdf478e54f75d74 (patch) | |
tree | ebf352226fccaabacda57f9315e8d8f898145e58 | |
parent | 7ea54a5c7127d48d300128869105a1e6fb2928f9 (diff) | |
download | ampache-380a8615ae97295f650699e8ecdf478e54f75d74.tar.gz ampache-380a8615ae97295f650699e8ecdf478e54f75d74.tar.bz2 ampache-380a8615ae97295f650699e8ecdf478e54f75d74.zip |
updated show_genre_pulldown, hopefully speeding it up
-rw-r--r-- | admin/song.php | 2 | ||||
-rw-r--r-- | lib/ui.lib.php | 599 | ||||
-rw-r--r-- | modules/lib.php | 88 | ||||
-rw-r--r-- | templates/show_random_play.inc | 2 | ||||
-rw-r--r-- | templates/show_random_play_bar.inc.php | 2 | ||||
-rw-r--r-- | templates/song_edit.inc | 2 |
6 files changed, 320 insertions, 375 deletions
diff --git a/admin/song.php b/admin/song.php index 15211e5e..ef535f51 100644 --- a/admin/song.php +++ b/admin/song.php @@ -145,7 +145,7 @@ echo <<<EDIT_SONG_3 <td>Genre:</td> <td colspan="2"> EDIT_SONG_3; - show_genre_pulldown($info->genre, 1); + show_genre_pulldown('genre',$info->genre); echo <<<EDIT_SONG_4 </td> </tr> diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 6c6396ca..81db6419 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -1,24 +1,24 @@ <?php /* - Copyright (c) 2001 - 2005 Ampache.org - All rights reserved. + Copyright (c) 2001 - 2005 Ampache.org + All rights reserved. - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ + */ /** * UI Function Library @@ -83,15 +83,15 @@ function get_preferences($username=0) { function init_preferences() { - /* Get Global Preferences */ - $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='-1' " . - " AND user_preference.preference = preferences.id AND preferences.type='system'"; - $db_results = mysql_query($sql, dbh()); + /* Get Global Preferences */ + $sql = "SELECT preferences.name,user_preference.value FROM preferences,user_preference WHERE user_preference.user='-1' " . + " AND user_preference.preference = preferences.id AND preferences.type='system'"; + $db_results = mysql_query($sql, dbh()); - while ($r = mysql_fetch_assoc($db_results)) { + while ($r = mysql_fetch_assoc($db_results)) { $name = $r['name']; - $results[$name] = $r['value']; - } // end while sys prefs + $results[$name] = $r['value']; + } // end while sys prefs /* Now we need to allow the user to override some stuff that's been set by the above */ $username = $_SESSION['userdata']['username']; @@ -151,7 +151,7 @@ function clear_now_playing() { */ function show_tool_box ($title, $items) { - include(conf('prefix') . "/templates/tool_box.inc"); + include(conf('prefix') . "/templates/tool_box.inc"); }// show_tool_box @@ -171,7 +171,7 @@ function show_box($title,$items) { */ function show_menu_items ($high) { - include(conf('prefix') . "/templates/menu.inc"); + include(conf('prefix') . "/templates/menu.inc"); } // show_menu_items @@ -209,10 +209,10 @@ if (!function_exists('_')) { */ function show_playlist_menu () { - echo "<br /><span class=\"header2\">" . _("Playlist Actions") . ": <a href=\"" . conf('web_path') . "/playlist.php?action=new\">" . _("New") ."</a> | "; - echo "<a href=\"" . conf('web_path') . "/playlist.php\"> " . _("View All") . "</a> | "; + echo "<br /><span class=\"header2\">" . _("Playlist Actions") . ": <a href=\"" . conf('web_path') . "/playlist.php?action=new\">" . _("New") ."</a> | "; + echo "<a href=\"" . conf('web_path') . "/playlist.php\"> " . _("View All") . "</a> | "; echo "<a href=\"" . conf('web_path') . "/playlist.php?action=show_import_playlist\"> " . _("Import") . "</a>"; - echo "</span><br /><br />"; + echo "</span><br /><br />"; } // show_playlist_menu @@ -221,7 +221,7 @@ function show_playlist_menu () { * shows the admin menu */ function show_admin_menu ($admin_highlight) { - include(conf('prefix') . "/templates/admin_menu.inc"); + include(conf('prefix') . "/templates/admin_menu.inc"); } // show_admin_menu /** @@ -232,7 +232,7 @@ function show_admin_menu ($admin_highlight) { function access_denied() { echo "<br /><br /><br />"; - echo "<div class=\"fatalerror\">" . _("Error Access Denied") . "</div>\n"; + echo "<div class=\"fatalerror\">" . _("Error Access Denied") . "</div>\n"; show_footer(); exit(); @@ -244,28 +244,28 @@ function access_denied() { */ function show_users () { - $dbh = dbh(); + $dbh = dbh(); - // Setup the View Ojbect - $view = new View(); - $view->import_session_view(); + // Setup the View Ojbect + $view = new View(); + $view->import_session_view(); - // if we are returning - if ($_REQUEST['keep_view']) { - $view->initialize(); - } - // If we aren't keeping the view then initlize it - else { - $sql = "SELECT username FROM user"; - $db_results = mysql_query($sql, $dbh); - $total_items = mysql_num_rows($db_results); - if ($match != "Show_all") { $offset_limit = $_SESSION['userdata']['offset_limit']; } - $view = new View($sql, 'admin/users.php','fullname',$total_items,$offset_limit); - } + // if we are returning + if ($_REQUEST['keep_view']) { + $view->initialize(); + } + // If we aren't keeping the view then initlize it + else { + $sql = "SELECT username FROM user"; + $db_results = mysql_query($sql, $dbh); + $total_items = mysql_num_rows($db_results); + if ($match != "Show_all") { $offset_limit = $_SESSION['userdata']['offset_limit']; } + $view = new View($sql, 'admin/users.php','fullname',$total_items,$offset_limit); + } - $db_result = mysql_query($view->sql, $dbh); + $db_result = mysql_query($view->sql, $dbh); - require(conf('prefix') . "/templates/show_users.inc"); + require(conf('prefix') . "/templates/show_users.inc"); } // show_users() @@ -298,25 +298,25 @@ function return_referer() { */ function show_alphabet_list ($type,$script="artist.php",$selected="false",$action='match') { - $list = array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,"0"); + $list = array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,"0"); - $style_name = "style_" . strtolower($selected); + $style_name = "style_" . strtolower($selected); ${$style_name} = "style=\"font-weight:bold;\""; - echo "<div class=\"alphabet\">"; - foreach ($list as $l) { + echo "<div class=\"alphabet\">"; + foreach ($list as $l) { $style_name = "style_" . strtolower($l); - echo "<a href=\"". conf('web_path') ."/$script?action=$action&match=$l\" " . ${$style_name} . ">$l</a> | \n"; - } + echo "<a href=\"". conf('web_path') ."/$script?action=$action&match=$l\" " . ${$style_name} . ">$l</a> | \n"; + } echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Browse\" $style_browse>" . _("Browse") . "</a> | \n"; - if ($script == "albums.php") { - echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Show_missing_art\" $style_show_missing_art>" . _("Show w/o art") . "</a> | \n"; - } // if we are on the albums page + if ($script == "albums.php") { + echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Show_missing_art\" $style_show_missing_art>" . _("Show w/o art") . "</a> | \n"; + } // if we are on the albums page - echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Show_all\" $style_show_all>" . _("Show all") . "</a>"; + echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Show_all\" $style_show_all>" . _("Show all") . "</a>"; - echo "</div>\n"; + echo "</div>\n"; } // show_alphabet_list /** @@ -339,7 +339,7 @@ function show_alphabet_form($match, $text, $action) { */ function show_local_control () { - require_once(conf('prefix') . "/templates/show_localplay.inc"); + require_once(conf('prefix') . "/templates/show_localplay.inc"); } // show_local_control @@ -368,26 +368,26 @@ function truncate_with_ellipse($text, $max=27) { */ function truncate_with_ellipsis($text, $max=27) { - /* If we want it to be shorter than three, just throw it back */ - if ($max > 3) { + /* If we want it to be shorter than three, just throw it back */ + if ($max > 3) { - /* Make sure the functions exist before doing the iconv mojo */ - if (function_exists('iconv') && function_exists('iconv_substr') && function_exists('iconv_strlen')) { - if (iconv_strlen($text, conf('site_charset')) > $max) { - $text = iconv_substr($text, 0, $max-3, conf('site_charset')); - $text .= iconv("ISO-8859-1", conf('site_charset'), "..."); - } - } + /* Make sure the functions exist before doing the iconv mojo */ + if (function_exists('iconv') && function_exists('iconv_substr') && function_exists('iconv_strlen')) { + if (iconv_strlen($text, conf('site_charset')) > $max) { + $text = iconv_substr($text, 0, $max-3, conf('site_charset')); + $text .= iconv("ISO-8859-1", conf('site_charset'), "..."); + } + } - /* Do normal substr if we don't have iconv */ - else { - if (strlen($text) > $max) { - $text = substr($text,0,$max-3)."..."; - } - } // else no iconv - } // else greater than 3 + /* Do normal substr if we don't have iconv */ + else { + if (strlen($text) > $max) { + $text = substr($text,0,$max-3)."..."; + } + } // else no iconv + } // else greater than 3 - return $text; + return $text; } // truncate_with_ellipsis @@ -407,10 +407,10 @@ function show_footer() { */ function show_now_playing() { - $dbh = dbh(); - $web_path = conf('web_path'); + $dbh = dbh(); + $web_path = conf('web_path'); $results = get_now_playing(); - require (conf('prefix') . "/templates/show_now_playing.inc"); + require (conf('prefix') . "/templates/show_now_playing.inc"); } // show_now_playing @@ -449,14 +449,14 @@ function show_playlist($playlist_id) { /* Create the Playlist */ $playlist = new Playlist($playlist_id); - $song_ids = $playlist->get_songs(); + $song_ids = $playlist->get_songs(); - if (count($song_ids) > 0) { - show_songs($song_ids, $playlist->id); - } - else { - echo "<p>" . _("No songs in this playlist.") . "</p>\n"; - } + if (count($song_ids) > 0) { + show_songs($song_ids, $playlist->id); + } + else { + echo "<p>" . _("No songs in this playlist.") . "</p>\n"; + } } // show_playlist @@ -494,11 +494,11 @@ function get_now_playing() { $sql = "SELECT song.id FROM song WHERE file = \"". conf('mpd_dir') . "/" . $myMpd->playlist[$myMpd->current_track_id]['file']. "\""; - $db_results = @mysql_query($sql,dbh()); + $db_results = @mysql_query($sql,dbh()); - while ($r = mysql_fetch_assoc($db_results)) { + while ($r = mysql_fetch_assoc($db_results)) { - $song = new Song($r['id']); + $song = new Song($r['id']); $song->format_song(); $np_user = new User(0); $np_user->fullname = 'MPD User'; @@ -524,39 +524,39 @@ function get_now_playing() { function get_all_ratings($rate_user,$sort_by) {; - $sql = "SELECT * FROM ratings WHERE user='$rate_user' AND object_type='$sort_by' ORDER BY user_rating DESC"; - $db_result = mysql_query( $sql, dbh() ); - - while($row = mysql_fetch_assoc($db_result)) - { - $type=$row['object_type']; - $id=$row['object_id']; - $rating=$row['user_rating']; - $art_image="<img border=\"0\" src=\"" . conf('web_path') . "/albumart.php?id=" . $id . "\" alt=\"Album Art\" height=\"100\" />"; - $art_link="<a href='http://" . conf('web_path') . "/ampache/albums.php?action=show&album=$id'>$art_image</a>"; - $artist_name=$album->f_artist; - $album_name=$album->name; - if($type=="album"){ - echo ("<table width=400>" . - "<tr>" . - "<td width=100 align=center>$artLink</td>" . - "<td width=* align=left>".ucfirst($type)." #$id<br>" . - "Rating: $rating</td>" . - "</tr>" . - "</table>"); - } - else{ - $artistLink="<a href='" . conf('web_path') . "/ampache/artists.php?action=show&artist=$id'>Artist $id</a>"; - echo ("<table width=150>" . - "<tr>" . - "<td align=left>$artist_link<br>" . - "Rating: $rating" . - "</td>" . - "</tr>" . - "</table>"); - } - - } + $sql = "SELECT * FROM ratings WHERE user='$rate_user' AND object_type='$sort_by' ORDER BY user_rating DESC"; + $db_result = mysql_query( $sql, dbh() ); + + while($row = mysql_fetch_assoc($db_result)) + { + $type=$row['object_type']; + $id=$row['object_id']; + $rating=$row['user_rating']; + $art_image="<img border=\"0\" src=\"" . conf('web_path') . "/albumart.php?id=" . $id . "\" alt=\"Album Art\" height=\"100\" />"; + $art_link="<a href='http://" . conf('web_path') . "/ampache/albums.php?action=show&album=$id'>$art_image</a>"; + $artist_name=$album->f_artist; + $album_name=$album->name; + if($type=="album"){ + echo ("<table width=400>" . + "<tr>" . + "<td width=100 align=center>$artLink</td>" . + "<td width=* align=left>".ucfirst($type)." #$id<br>" . + "Rating: $rating</td>" . + "</tr>" . + "</table>"); + } + else{ + $artistLink="<a href='" . conf('web_path') . "/ampache/artists.php?action=show&artist=$id'>Artist $id</a>"; + echo ("<table width=150>" . + "<tr>" . + "<td align=left>$artist_link<br>" . + "Rating: $rating" . + "</td>" . + "</tr>" . + "</table>"); + } + + } } // get_artist_rating() @@ -572,27 +572,27 @@ function get_all_ratings($rate_user,$sort_by) {; */ function set_artist_rating($artist_id, $rate_user, $rating) { - $artist_id = sql_escape($artist_id); - - $sql = "SELECT * FROM ratings WHERE user='$rate_user' AND object_type='artist' AND object_id='$artist_id'"; - $db_result = mysql_query( $sql, dbh() ); - $r = mysql_fetch_row( $db_result ); - - if($r[0]) { - $sql2 = "UPDATE ratings SET user_rating='$rating' WHERE object_id='$artist_id' AND user='$rate_user' AND object_type='artist'"; - $db_result2 = mysql_query( $sql2, dbh() ); - $r = mysql_fetch_row( $db_result2 ); - return mysql_insert_id( dbh() ); - } - else if(!$r[0]) { - $sql2 = "INSERT INTO ratings (id,user,object_type,object_id,user_rating) ". - "VALUES ('','$rate_user','artist','$artist_id','$rating')"; - $db_result2 = mysql_query( $sql2, dbh() ); - return mysql_insert_id(dbh() ); - } - else{ - return "NA"; - } + $artist_id = sql_escape($artist_id); + + $sql = "SELECT * FROM ratings WHERE user='$rate_user' AND object_type='artist' AND object_id='$artist_id'"; + $db_result = mysql_query( $sql, dbh() ); + $r = mysql_fetch_row( $db_result ); + + if($r[0]) { + $sql2 = "UPDATE ratings SET user_rating='$rating' WHERE object_id='$artist_id' AND user='$rate_user' AND object_type='artist'"; + $db_result2 = mysql_query( $sql2, dbh() ); + $r = mysql_fetch_row( $db_result2 ); + return mysql_insert_id( dbh() ); + } + else if(!$r[0]) { + $sql2 = "INSERT INTO ratings (id,user,object_type,object_id,user_rating) ". + "VALUES ('','$rate_user','artist','$artist_id','$rating')"; + $db_result2 = mysql_query( $sql2, dbh() ); + return mysql_insert_id(dbh() ); + } + else{ + return "NA"; + } } // set_artist_rating() /* @@ -607,26 +607,26 @@ function set_artist_rating($artist_id, $rate_user, $rating) { */ function set_album_rating($album_id, $rate_user, $rating) { - $album_id = sql_escape($album_id); - - $sql = "SELECT * FROM ratings WHERE user='$rate_user' AND object_type='album' AND object_id='$album_id'"; - $db_result = mysql_query( $sql, dbh() ); - $r = mysql_fetch_row( $db_result ); - - if($r[0]) { - $sql2 = "UPDATE ratings SET user_rating='$rating' WHERE object_id='$album_id' AND user='$rate_user' AND object_type='album'"; - $db_result2 = mysql_query( $sql2, dbh() ); - return mysql_insert_id( dbh() ); - } - else if(!$r[0]) { - $sql2 = "INSERT INTO ratings (id,user,object_type,object_id,user_rating) ". - "VALUES ('','$rate_user','album','$album_id','$rating')"; - $db_result2 = mysql_query( $sql2, dbh() ); - return mysql_insert_id( dbh() ); - } - else{ - return "NA"; - } + $album_id = sql_escape($album_id); + + $sql = "SELECT * FROM ratings WHERE user='$rate_user' AND object_type='album' AND object_id='$album_id'"; + $db_result = mysql_query( $sql, dbh() ); + $r = mysql_fetch_row( $db_result ); + + if($r[0]) { + $sql2 = "UPDATE ratings SET user_rating='$rating' WHERE object_id='$album_id' AND user='$rate_user' AND object_type='album'"; + $db_result2 = mysql_query( $sql2, dbh() ); + return mysql_insert_id( dbh() ); + } + else if(!$r[0]) { + $sql2 = "INSERT INTO ratings (id,user,object_type,object_id,user_rating) ". + "VALUES ('','$rate_user','album','$album_id','$rating')"; + $db_result2 = mysql_query( $sql2, dbh() ); + return mysql_insert_id( dbh() ); + } + else{ + return "NA"; + } } // set_album_rating() /* @@ -641,26 +641,26 @@ function set_album_rating($album_id, $rate_user, $rating) { */ function set_song_rating($song_id, $rate_user, $rating) { - $song_id = sql_escape($song_id); - - $sql = "SELECT * FROM ratings WHERE user='$rate_user' AND object_type='song' AND object_id='$song_id'"; - $db_result = mysql_query( $sql, dbh() ); - $r = mysql_fetch_row( $db_result ); - - if($r[0]){ - $sql2 = "UPDATE ratings SET user_rating='$rating' WHERE object_id='$song_id' AND user='$rate_user' AND object_type='song'"; - $db_result2 = mysql_query( $sql2, dbh() ); - return mysql_insert_id( dbh() ); - } - else if(!$r[0]){ - $sql2 = "INSERT INTO ratings (id,user,object_type,object_id,user_rating) ". - "VALUES ('','$rate_user','song','$song_id','$rating')"; - $db_result2 = mysql_query( $sql2, dbh() ); - return mysql_insert_id( dbh() ); - } - else{ - return "NA"; - } + $song_id = sql_escape($song_id); + + $sql = "SELECT * FROM ratings WHERE user='$rate_user' AND object_type='song' AND object_id='$song_id'"; + $db_result = mysql_query( $sql, dbh() ); + $r = mysql_fetch_row( $db_result ); + + if($r[0]){ + $sql2 = "UPDATE ratings SET user_rating='$rating' WHERE object_id='$song_id' AND user='$rate_user' AND object_type='song'"; + $db_result2 = mysql_query( $sql2, dbh() ); + return mysql_insert_id( dbh() ); + } + else if(!$r[0]){ + $sql2 = "INSERT INTO ratings (id,user,object_type,object_id,user_rating) ". + "VALUES ('','$rate_user','song','$song_id','$rating')"; + $db_result2 = mysql_query( $sql2, dbh() ); + return mysql_insert_id( dbh() ); + } + else{ + return "NA"; + } } // set_song_rating() /** @@ -744,7 +744,7 @@ function show_all_recent() { */ function show_local_catalog_info() { - $dbh = dbh(); + $dbh = dbh(); /* Before we display anything make sure that they have a catalog */ $query = "SELECT * FROM catalog"; @@ -756,61 +756,61 @@ function show_local_catalog_info() { return false; } - $query = "SELECT count(*) AS songs, SUM(size) AS size, SUM(time) as time FROM song"; - $db_result = mysql_query($query, $dbh); - $songs = mysql_fetch_assoc($db_result); - - $query = "SELECT count(*) FROM album"; - $db_result = mysql_query($query, $dbh); - $albums = mysql_fetch_row($db_result); - - $query = "SELECT count(*) FROM artist"; - $db_result = mysql_query($query, $dbh); - $artists = mysql_fetch_row($db_result); - - $sql = "SELECT count(*) FROM user"; - $db_result = mysql_query($sql, $dbh); - $users = mysql_fetch_row($db_result); - - $time = time(); - $last_seen_time = $time - 1200; - $sql = "SELECT count(DISTINCT s.username) FROM session AS s " . - "INNER JOIN user AS u ON s.username = u.username " . - "WHERE s.expire > " . $time . " " . - "AND u.last_seen > " . $last_seen_time; - $db_result = mysql_query($sql, $dbh); - $connected_users = mysql_fetch_row($db_result); - - $hours = floor($songs['time']/3600); - $size = $songs['size']/1048576; - - $days = floor($hours/24); - $hours = $hours%24; - - $time_text = "$days "; - $time_text .= ($days == 1) ? _("day") : _("days"); - $time_text .= ", $hours "; - $time_text .= ($hours == 1) ? _("hour") : _("hours"); - - if ( $size > 1024 ) { - $total_size = sprintf("%.2f", ($size/1024)); - $size_unit = "GB"; - } - else { - $total_size = sprintf("%.2f", $size); - $size_unit = "MB"; - } + $query = "SELECT count(*) AS songs, SUM(size) AS size, SUM(time) as time FROM song"; + $db_result = mysql_query($query, $dbh); + $songs = mysql_fetch_assoc($db_result); + + $query = "SELECT count(*) FROM album"; + $db_result = mysql_query($query, $dbh); + $albums = mysql_fetch_row($db_result); + + $query = "SELECT count(*) FROM artist"; + $db_result = mysql_query($query, $dbh); + $artists = mysql_fetch_row($db_result); + + $sql = "SELECT count(*) FROM user"; + $db_result = mysql_query($sql, $dbh); + $users = mysql_fetch_row($db_result); + + $time = time(); + $last_seen_time = $time - 1200; + $sql = "SELECT count(DISTINCT s.username) FROM session AS s " . + "INNER JOIN user AS u ON s.username = u.username " . + "WHERE s.expire > " . $time . " " . + "AND u.last_seen > " . $last_seen_time; + $db_result = mysql_query($sql, $dbh); + $connected_users = mysql_fetch_row($db_result); + + $hours = floor($songs['time']/3600); + $size = $songs['size']/1048576; + + $days = floor($hours/24); + $hours = $hours%24; + + $time_text = "$days "; + $time_text .= ($days == 1) ? _("day") : _("days"); + $time_text .= ", $hours "; + $time_text .= ($hours == 1) ? _("hour") : _("hours"); + + if ( $size > 1024 ) { + $total_size = sprintf("%.2f", ($size/1024)); + $size_unit = "GB"; + } + else { + $total_size = sprintf("%.2f", $size); + $size_unit = "MB"; + } require(conf('prefix') . "/templates/show_local_catalog_info.inc.php"); } // show_local_catalog_info /*! - @function img_resize - @discussion this automaticly resizes the image for thumbnail viewing - only works on gif/jpg/png this function also checks to make - sure php-gd is enabled -*/ + @function img_resize + @discussion this automaticly resizes the image for thumbnail viewing + only works on gif/jpg/png this function also checks to make + sure php-gd is enabled + */ function img_resize($image,$size,$type){ /* Make sure they even want us to resize it */ @@ -831,27 +831,27 @@ function img_resize($image,$size,$type){ return false; } - $src = imagecreatefromstring($image); - $width = imagesx($src); - $height = imagesy($src); + $src = imagecreatefromstring($image); + $width = imagesx($src); + $height = imagesy($src); - $new_w = $size['width']; - $new_h = $size['height']; + $new_w = $size['width']; + $new_h = $size['height']; $img = imagecreatetruecolor($new_w,$new_h); - imagecopyresampled($img,$src,0,0,0,0,$new_w,$new_h,$width,$height); + imagecopyresampled($img,$src,0,0,0,0,$new_w,$new_h,$width,$height); - // determine image type and send it to the client + // determine image type and send it to the client switch ($type) { case 'jpg': - imagejpeg($img,null,100); - break; + imagejpeg($img,null,100); + break; case 'gif': imagegif($img,null,100); - break; + break; case 'png': imagepng($img,null,100); - break; + break; } } // img_resize @@ -897,26 +897,26 @@ function show_random_play_bar() { */ function show_artist_pulldown ($artist_id,$select_name='artist') { - $query = "SELECT id FROM artist ORDER BY name"; - $db_result = mysql_query($query, dbh()); + $query = "SELECT id FROM artist ORDER BY name"; + $db_result = mysql_query($query, dbh()); - echo "\n<select name=\"$select_name\">\n"; + echo "\n<select name=\"$select_name\">\n"; - while ($r = mysql_fetch_assoc($db_result)) { + while ($r = mysql_fetch_assoc($db_result)) { $artist = new Artist($r['id']); $artist->get_count(); - if ( $artist_id == $r['id'] ) { - echo "\t<option value=\"" . $artist->id . "\" selected=\"selected\">". scrub_out($artist->name) . " (" . $artist->songs . ")</option>\n"; - } - else { - echo "\t<option value=\"" . $artist->id . "\">". scrub_out($artist->name) ."</option>\n"; - } + if ( $artist_id == $r['id'] ) { + echo "\t<option value=\"" . $artist->id . "\" selected=\"selected\">". scrub_out($artist->name) . " (" . $artist->songs . ")</option>\n"; + } + else { + echo "\t<option value=\"" . $artist->id . "\">". scrub_out($artist->name) ."</option>\n"; + } - } // end while fetching artists + } // end while fetching artists - echo "</select>\n"; + echo "</select>\n"; } // show_artist_pulldown @@ -928,24 +928,24 @@ function show_artist_pulldown ($artist_id,$select_name='artist') { */ function show_catalog_pulldown ($name='catalog',$style) { - $sql = "SELECT id,name FROM catalog ORDER BY name"; - $db_result = mysql_query($sql, dbh()); + $sql = "SELECT id,name FROM catalog ORDER BY name"; + $db_result = mysql_query($sql, dbh()); - echo "\n<select name=\"" . $name . "\" style=\"" . $style . "\">\n"; + echo "\n<select name=\"" . $name . "\" style=\"" . $style . "\">\n"; - echo "<option value=\"-1\">All</option>\n"; + echo "<option value=\"-1\">All</option>\n"; - while ($r = mysql_fetch_assoc($db_result)) { - $catalog_name = scrub_out($r['name']); + while ($r = mysql_fetch_assoc($db_result)) { + $catalog_name = scrub_out($r['name']); - if ( $catalog == $r['id'] ) { - echo " <option value=\"" .$r['id'] . "\" selected=\"selected\">$catalog_name</option>\n"; - } - else { - echo " <option value=\"" . $r['id'] . "\">$catalog_name</option>\n"; - } - } - echo "\n</select>\n"; + if ( $catalog == $r['id'] ) { + echo " <option value=\"" .$r['id'] . "\" selected=\"selected\">$catalog_name</option>\n"; + } + else { + echo " <option value=\"" . $r['id'] . "\">$catalog_name</option>\n"; + } + } + echo "\n</select>\n"; } // show_catalog_pulldown @@ -991,56 +991,56 @@ function get_location() { switch ($location['page']) { case 'index.php': $location['title'] = 'Home'; - break; + break; case 'search.php': $location['title'] = 'Search'; - break; + break; case 'preferences.php': $location['title'] = 'Preferences'; - break; + break; case 'admin/index.php': $location['title'] = 'Admin'; $location['section'] = 'admin'; - break; + break; case 'admin/catalog.php': $location['title'] = 'Catalog'; $location['section'] = 'admin'; - break; + break; case 'admin/users.php': $location['title'] = 'User Management'; $location['section'] = 'admin'; - break; + break; case 'admin/mail.php': $location['title'] = 'Mail Users'; $location['section'] = 'admin'; - break; + break; case 'admin/access.php': $location['title'] = 'Manage Access Lists'; $location['section'] = 'admin'; - break; + break; case 'admin/preferences.php': $location['title'] = 'Site Preferences'; $location['section'] = 'admin'; - break; + break; case 'browse.php': $location['title'] = 'Browse Music'; $location['section'] = 'browse'; - break; + break; case 'albums.php': $location['title'] = 'Albums'; $location['section'] = 'browse'; - break; + break; case 'artists.php': $location['title'] = 'Artists'; $location['section'] = 'browse'; - break; + break; case 'genre.php': $location['title'] = 'Genre'; $location['section'] = 'browse'; - break; + break; default: $location['title'] = ''; - break; + break; } // switch on raw page location return $location; @@ -1060,4 +1060,37 @@ function show_preference_box($preferences) { } // show_preference_box +/** + * show_genre_pulldown + * This shows a select of all of the genres, it takes the name of the select + * the currently selected and then the size + * + */ + +function show_genre_pulldown ($name,$selected='',$size=1) { + + /* Get them genre hippies */ + $sql = "SELECT genre.id,genre.name FROM genre ORDER BY genre.name"; + $db_result = mysql_query($sql, dbh()); + + echo "<select name=\"" . $name . "[]\" multiple=\"multiple\" size=\"$size\">\n"; + echo "\t<option value=\"-1\">" . _("All") . "</option>\n"; + + while ($r = mysql_fetch_assoc($db_result)) { + + $r['name'] = scrub_out($r['name']); + + if ( $selected == $r['id'] ) { + echo "\t<option value=\"" . $r['id'] . "\" selected=\"selected\">" . $r['name'] . "</option>\n"; + } + else { + echo " <option value=\"" . $r['id'] . "\">" . $r['name'] . "</option>\n"; + } + } // end while + + echo "</select>\n"; + +} // show_genre_pulldown + + ?> diff --git a/modules/lib.php b/modules/lib.php index e37acd49..e887ac54 100644 --- a/modules/lib.php +++ b/modules/lib.php @@ -75,94 +75,6 @@ function show_flagged_popup($reason,$label='value', $name='flagged_type', $other /* - * show_genre_pulldown() - * - * Set complete=1 if you want the entire genre list - * - */ - -function show_genre_pulldown ($genre, $complete, $lines= "'10' multiple='multiple'") { - - $dbh = dbh(); - - // find the genres we have in use - if ( $complete ) { - $sql = "SELECT id FROM genre ORDER BY name"; - } - else { - $sql = "SELECT DISTINCT song.genre FROM genre, song" . - " WHERE song.genre = genre.id" . - " ORDER BY genre.name"; - } - - $db_result = mysql_query($sql, $dbh); - - echo "<select name=\"genre[]\" size=".$lines.">\n"; - - if ( ! $complete ) { - $genre_info = get_genre_info( -1 ); - if ( $genre == -1 ) { - echo " <option value=\"-1\" selected=\"selected\">${genre_info[0]} - (${genre_info[1]})</option>\n"; - } - else { - echo " <option value=\"-1\">${genre_info[0]} - (${genre_info[1]})</option>\n"; - } - } - - while ( $r = mysql_fetch_row($db_result) ) { - // $r[0] = genre id - list($genre_name, $genre_count) = get_genre_info($r[0]); - $genre_name = htmlspecialchars($genre_name); - - if ( $genre == $r[0] ) { - echo " <option value=\"${r[0]}\" selected=\"selected\">$genre_name - ($genre_count)</option>\n"; - } - else { - echo " <option value=\"${r[0]}\">$genre_name - ($genre_count)</option>\n"; - } - } - echo " </select>\n"; - -} // show_genre_pulldown() - -/* - * update_counter() - * - * update what song/album/artist has just been played - * - */ - -function update_counter ($type, $id, $dbh=0) { - - global $settings; - if (!is_resource($dbh)) { - $dbh = dbh(); - } - - // from hopson: these queries will be very useful for generating overall statistics: - /* - SELECT song.title,SUM(object_count.count) FROM song,object_count WHERE object_count.object_type = 'song' AND object_count.object_id = song.id GROUP BY song.id; - - SELECT album.name,SUM(object_count.count) FROM album,object_count WHERE object_count.object_type = 'album' AND object_count.object_id = album.id GROUP BY album.id; - - SELECT artist.name,SUM(object_count.count) FROM artist,object_count WHERE object_count.object_type = 'artist' AND object_count.object_id = artist.id GROUP BY artist.id; - - SELECT playlist.name,SUM(object_count.count) FROM playlist,object_count WHERE object_count.object_type = 'playlist' AND object_count.object_id = playlist.id GROUP BY playlist.id; - */ - - if ( $type == 'song' ) { - $sql = "UPDATE $type SET times_played = times_played + 1 WHERE id = '$id'"; - } - else { - $sql = "UPDATE $type SET times_played = times_played + 1 WHERE id = '$id'"; - } - - $db_result = mysql_query($sql, $dbh); -} // update_counter() - - - -/* * delete_user_stats() * * just delete stats for specific users or all of them diff --git a/templates/show_random_play.inc b/templates/show_random_play.inc index 47482d19..dbddced2 100644 --- a/templates/show_random_play.inc +++ b/templates/show_random_play.inc @@ -48,7 +48,7 @@ </td> <td rowspan="3" valign="top"><?php echo _("From genre"); ?></td> <td rowspan="3"> - <?php show_genre_pulldown( -1, 0 ); ?> + <?php show_genre_pulldown('genre','','5'); ?> </td> </tr> <tr class="even"> diff --git a/templates/show_random_play_bar.inc.php b/templates/show_random_play_bar.inc.php index d1c38842..440e362c 100644 --- a/templates/show_random_play_bar.inc.php +++ b/templates/show_random_play_bar.inc.php @@ -44,7 +44,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. <option value="1000">1000</option> <option value="-1"><?php echo _("All"); ?></option> </select> - <?php show_genre_pulldown( -1, 0, "'1'" ); ?> + <?php show_genre_pulldown('genre'); ?> <select name="Quantifier"> <option value="Songs"><?php echo _("Songs"); ?></option> <option value="Minutes"><?php echo _("Minutes"); ?></option> diff --git a/templates/song_edit.inc b/templates/song_edit.inc index f3becdea..5c651e3f 100644 --- a/templates/song_edit.inc +++ b/templates/song_edit.inc @@ -56,7 +56,7 @@ $target = conf('web_path').'/admin/flags.php'; <tr> <td>Genre:</td> - <td> <?php show_genre_pulldown($song->genre, 1); ?> </td> + <td> <?php show_genre_pulldown('genre',$song-genre); ?> </td> </tr> <tr> |