diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-11-05 21:48:43 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-11-05 21:48:43 +0000 |
commit | a8589cef1e311a032a67ecdc61e2b73197373288 (patch) | |
tree | cfd486596c2126247acfca5a026db2c27cf06277 | |
parent | f24fa20acbd2d7ff7175dab391e75f743c634e87 (diff) | |
download | ampache-a8589cef1e311a032a67ecdc61e2b73197373288.tar.gz ampache-a8589cef1e311a032a67ecdc61e2b73197373288.tar.bz2 ampache-a8589cef1e311a032a67ecdc61e2b73197373288.zip |
working democratic play
-rwxr-xr-x | docs/CHANGELOG | 2 | ||||
-rw-r--r-- | lib/class/stream.class.php | 2 | ||||
-rw-r--r-- | lib/class/tmp_playlist.class.php | 92 | ||||
-rw-r--r-- | lib/init.php | 1 | ||||
-rw-r--r-- | lib/install.php | 19 | ||||
-rw-r--r-- | lib/ui.lib.php | 24 | ||||
-rw-r--r-- | templates/show_tv.inc.php | 2 | ||||
-rw-r--r-- | templates/show_tv_adminctl.inc.php | 3 | ||||
-rw-r--r-- | templates/show_tv_nowplaying.inc.php | 21 | ||||
-rw-r--r-- | templates/show_tv_playlist.inc.php | 40 | ||||
-rw-r--r-- | templates/sidebar.inc.php | 5 | ||||
-rw-r--r-- | tv.php | 6 |
12 files changed, 173 insertions, 44 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 4dad4337..fcad5dd6 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,8 @@ -------------------------------------------------------------------------- v.3.3.3-Alpha2 + - Added Democratic Play ability, UI incomplete and 'clunky' + - Added some extra error checking to the install process - Fixed issue with delete confirmation on playlist always being yes, even if you click no. - Added more error checking to install, won't let you continue diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index d9777879..6a5f595e 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -289,7 +289,7 @@ class Stream { */ function create_democratic() { - $tmp_playlist = new tmpPlaylist('-1'); + $tmp_playlist = get_democratic_playlist('-1'); $tmp_playlist->vote($this->songs); header("Location: " . return_referer()); diff --git a/lib/class/tmp_playlist.class.php b/lib/class/tmp_playlist.class.php index e730f09f..eea57066 100644 --- a/lib/class/tmp_playlist.class.php +++ b/lib/class/tmp_playlist.class.php @@ -83,12 +83,25 @@ class tmpPlaylist { */ function get_items() { - $sql = "SELECT object_id FROM tmp_playlist_data " . - "WHERE tmp_playlist_data.tmp_playlist='" . sql_escape($this->id) . "' ORDER by id ASC"; + $order = 'ORDER BY id ASC'; + + if ($this->type == 'vote') { + $order = "ORDER BY `count` DESC"; + $vote_select = ", user_vote.user AS `count`"; + $vote_join = "LEFT JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; + } + + /* Select all objects from this playlist */ + $sql = "SELECT tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select FROM tmp_playlist_data $vote_join " . + "WHERE tmp_playlist_data.tmp_playlist='" . sql_escape($this->id) . "' $order"; $db_results = mysql_query($sql, dbh()); + + /* Define the array */ + $items = array(); while ($results = mysql_fetch_assoc($db_results)) { - $items[] = $results['object_id']; + $key = $results['id']; + $items[$key] = $results['object_id']; } return $items; @@ -110,13 +123,13 @@ class tmpPlaylist { if ($this->type == 'vote') { /* Add conditions for voting */ $vote_select = ", user_vote.user AS `count`"; - $order = " ORDER BY `counte` DESC"; + $order = " ORDER BY `count` DESC"; $vote_join = "LEFT JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; } $sql = "SELECT tmp_playlist_data.object_id $vote_select FROM tmp_playlist_data $vote_join " . "WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT 1"; - $db_resutls = mysql_query($sql, dbh()); + $db_results = mysql_query($sql, dbh()); $results = mysql_fetch_assoc($db_results); @@ -132,6 +145,19 @@ class tmpPlaylist { } // get_next_object + /** + * get_vote_url + * This returns the special play URL for democratic play, only open to ADMINs + */ + function get_vote_url() { + + $link = conf('web_path') . '/play/index.php?tmp_id=' . scrub_out($this->id) . + '&sid=' . scrub_out(session_id()) . '&uid=' . scrub_out($GLOBALS['user']->id); + + return $link; + + } // get_vote_url + /** * create * This function initializes a new tmpPlaylist it is assoicated with the current @@ -150,6 +176,9 @@ class tmpPlaylist { $id = mysql_insert_id(dbh()); + /* Prune dead tmp_playlists */ + $this->prune_playlists(); + /* Clean any other playlists assoicated with this session */ $this->delete($sessid,$id); @@ -178,6 +207,22 @@ class tmpPlaylist { } // delete /** + * prune_playlists + * This deletes and playlists that don't have an assoicated session + */ + function prune_playlists() { + + /* Just delete if no matching session row */ + $sql = "DELETE FROM tmp_playlist USING tmp_playlist " . + "LEFT JOIN session ON session.id=tmp_playlist.session " . + "WHERE session.id IS NULL AND tmp_playlist.session != '-1'"; + $db_results = mysql_query($sql,dbh()); + + return true; + + } // prune_playlists + + /** * prune_tracks * This prunes tracks that don't have playlists */ @@ -219,7 +264,7 @@ class tmpPlaylist { /* Itterate through the objects if no vote, add to playlist and vote */ foreach ($items as $object_id) { if (!$this->has_vote($object_id)) { - $this->add_vote($object_id); + $this->add_vote($object_id,$this->id); } } // end foreach @@ -230,9 +275,10 @@ class tmpPlaylist { * add_vote * This takes a object id and user and actually inserts the row */ - function add_vote($object_id) { + function add_vote($object_id,$tmp_playlist) { - $object_id = sql_escape($object_id); + $object_id = sql_escape($object_id); + $tmp_playlist = sql_escape($tmp_playlist); /* If it's on the playlist just vote */ $sql = "SELECT id FROM tmp_playlist_data " . @@ -242,7 +288,7 @@ class tmpPlaylist { /* If it's not there, add it and pull ID */ if (!$results = mysql_fetch_assoc($db_results)) { $sql = "INSERT INTO tmp_playlist_data (`tmp_playlist`,`object_id`) " . - "VALUES ('-1','$object_id')"; + "VALUES ('$tmp_playlist','$object_id')"; $db_results = mysql_query($sql, dbh()); $results['id'] = mysql_insert_id(dbh()); } @@ -262,24 +308,44 @@ class tmpPlaylist { */ function has_vote($object_id) { + $tmp_id = sql_escape($this->id); + /* Query vote table */ $sql = "SELECT tmp_playlist_data.id FROM user_vote " . "INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . "WHERE user_vote.user='" . sql_escape($GLOBALS['user']->id) . "' " . - " AND tmp_playlist_data.object_id='" . sql_escape($object_id) . "' " . - " AND tmp_playlist_data.tmp_playlist='-1'"; + "AND tmp_playlist_data.object_id='" . sql_escape($object_id) . "' " . + "AND tmp_playlist_data.tmp_playlist='$tmp_id'"; $db_results = mysql_query($sql, dbh()); /* If we find row, they've voted!! */ if (mysql_num_rows($db_results)) { - return false; + return true; } - return true; + return false; } // has_vote /** + * get_vote + * This returns the current count for a specific song on this tmp_playlist + */ + function get_vote($object_id) { + + $object_id = sql_escape($object_id); + + $sql = "SELECT COUNT(`user`) AS `count` FROM user_vote " . + " WHERE object_id='$object_id'"; + $db_results = mysql_query($sql,dbh()); + + $results = mysql_fetch_assoc($db_results); + + return $results['count']; + + } // get_vote + + /** * vote_active * This checks to see if this playlist is a voting playlist * and if it is active diff --git a/lib/init.php b/lib/init.php index 661d0096..c5efb98a 100644 --- a/lib/init.php +++ b/lib/init.php @@ -148,6 +148,7 @@ require_once(conf('prefix') . '/lib/themes.php'); require_once(conf('prefix') . '/lib/stream.lib.php'); require_once(conf('prefix') . '/lib/playlist.lib.php'); require_once(conf('prefix') . '/lib/upload.php'); +require_once(conf('prefix') . '/lib/democratic.lib.php'); require_once(conf('prefix') . '/modules/lib.php'); require_once(conf('prefix') . '/modules/admin.php'); require_once(conf('prefix') . '/modules/catalog.php'); diff --git a/lib/install.php b/lib/install.php index 70b38780..b9cf9cdd 100644 --- a/lib/install.php +++ b/lib/install.php @@ -236,15 +236,30 @@ function install_create_config($web_path,$username,$password,$hostname,$database */ function install_create_account($username,$password) { + if (!strlen($username) OR !strlen($password)) { + $GLOBALS['error']->add_error('general',"No Username/Password specified"); + return false; + } + $results = read_config($GLOBALS['configfile'], 0, 0); $dbh = check_database($results['local_host'],$results['local_username'],$results['local_pass']); + + if (!is_resource($dbh)) { + $GLOBALS['error']->add_error('general','Database Connection Failed:' . mysql_error()); + return false; + } - @mysql_select_db($results['local_db'],$dbh); + $db_select = @mysql_select_db($results['local_db'],$dbh); + + if (!$db_select) { + $GLOBALS['error']->add_error('general','Database Select Failed:' . mysql_error()); + return false; + } $username = sql_escape($username,$dbh); $password = sql_escape($password,$dbh); - $sql = "INSERT INTO user (`username`,`password`,`offset_limit`,`access`) VALUES ('$username',PASSWORD('$password'),'50','admin')"; + $sql = "INSERT INTO user (`username`,`password`,`offset_limit`,`access`) VALUES ('$username',PASSWORD('$password'),'50','100')"; $db_results = mysql_query($sql, $dbh); if (!$db_results) { diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 2c7c0ecf..136a9584 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -326,7 +326,7 @@ function show_play_selected() { * @package Web Interface * @catagory Get */ -function get_now_playing() { +function get_now_playing($filter='') { $sql = "SELECT song_id,user FROM now_playing ORDER BY start_time DESC"; $db_results = mysql_query($sql, dbh()); @@ -336,28 +336,6 @@ function get_now_playing() { $np_user = new User($r['user']); $results[] = array('song'=>$song,'user'=>$np_user); } // end while -/* - $myMpd = init_mpd(); - - if (is_object($myMpd) AND conf('mpd_method') == 'file') { - $sql = "SELECT song.id FROM song WHERE file = \"". conf('mpd_dir') . "/" . - $myMpd->playlist[$myMpd->current_track_id]['file']. "\""; - - $db_results = @mysql_query($sql,dbh()); - - while ($r = mysql_fetch_assoc($db_results)) { - - $song = new Song($r['id']); - $song->format_song(); - $np_user = new User(0); - $np_user->fullname = 'MPD User'; - $np_user->username = 'mpd_user'; - $results[] = array('song'=>$song,'user'=>$np_user); - - } // end while - - } // end if we have a MPD object -*/ return $results; diff --git a/templates/show_tv.inc.php b/templates/show_tv.inc.php index 8a556d86..fd29bff7 100644 --- a/templates/show_tv.inc.php +++ b/templates/show_tv.inc.php @@ -51,6 +51,8 @@ else { </div> <!-- End Control Div --> <div id="tv_np"> +<?php require_once(conf('prefix') . '/templates/show_tv_nowplaying.inc.php'); ?> </div> <div id="tv_playlist"> +<?php require_once(conf('prefix') . '/templates/show_tv_playlist.inc.php'); ?> </div> diff --git a/templates/show_tv_adminctl.inc.php b/templates/show_tv_adminctl.inc.php index f2c383f1..77becb35 100644 --- a/templates/show_tv_adminctl.inc.php +++ b/templates/show_tv_adminctl.inc.php @@ -29,5 +29,6 @@ <input type="submit" value="<?php echo _('Activate'); ?>" /> </form> <?php } else { ?> -<?php echo _('Democratic Play Active'); ?> +<?php echo _('Democratic Play Active'); ?> +<a href="<?php echo $tmp_playlist->get_vote_url(); ?>"><?php echo _('Play'); ?></a> <?php } ?> diff --git a/templates/show_tv_nowplaying.inc.php b/templates/show_tv_nowplaying.inc.php new file mode 100644 index 00000000..5823f537 --- /dev/null +++ b/templates/show_tv_nowplaying.inc.php @@ -0,0 +1,21 @@ +<?php +/* + + Copyright (c) 2001 - 2006 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 v2 + as published by the Free Software Foundation + + 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. + +*/ +?> diff --git a/templates/show_tv_playlist.inc.php b/templates/show_tv_playlist.inc.php new file mode 100644 index 00000000..19a2c80b --- /dev/null +++ b/templates/show_tv_playlist.inc.php @@ -0,0 +1,40 @@ +<?php +/* + + Copyright (c) 2001 - 2006 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 v2 + as published by the Free Software Foundation. + + 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. + +*/ +?> +<h3><?php echo _('Current Playlist'); ?></h3> +<table cellspacing="0"> +<tr class="table-header"> + <td><?php echo _('Votes'); ?></td> + <td><?php echo _('Song'); ?></td> + <td><?php echo _('Length'); ?></td> +</tr> +<?php +foreach($songs as $row_id=>$song_id) { + $song = new Song($song_id); + $song->format_song(); +?> +<tr> + <td><?php echo scrub_out($tmp_playlist->get_vote($row_id)); ?></td> + <td><?php echo scrub_out($song->title); ?></td> + <td><?php echo scrub_out($song->length); ?></td> +</tr> +<?php } ?> +</table> diff --git a/templates/sidebar.inc.php b/templates/sidebar.inc.php index cd620975..ff61c4f8 100644 --- a/templates/sidebar.inc.php +++ b/templates/sidebar.inc.php @@ -196,6 +196,11 @@ $web_path = conf('web_path'); </li> <?php } // if horizontal orientation ?> <?php } // if localplay access ?> +<?php if ($GLOBALS['user']->prefs['play_type'] == 'democratic') { ?> + <li> + <a href="<?php echo $web_path; ?>/tv.php"><?php echo _('Democratic View'); ?></a> + </li> +<?php } // if democratic play ?> <?php if (conf('use_auth')) { ?> <li><a href="<?php echo $web_path; ?>/logout.php"><?php echo _('Logout'); ?></a></li> <?php } // end (conf('use_auth'))?> @@ -18,12 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - require_once('lib/init.php'); -/* Additional Library for tv stuff */ -require_once (conf('prefix') . '/lib/democratic.lib.php'); - $dbh = dbh(); $web_path = conf('web_path'); @@ -44,10 +40,12 @@ switch ($action) { /* Re-generate the playlist */ $tmp_playlist = new tmpPlaylist($id); + $songs = $tmp_playlist->get_items(); require_once(conf('prefix') . '/templates/show_tv.inc.php'); break; default: $tmp_playlist = get_democratic_playlist('-1'); + $songs = $tmp_playlist->get_items(); require_once(conf('prefix') . '/templates/show_tv.inc.php'); break; } // end switch on action |