diff options
-rw-r--r-- | lib/class/tmp_playlist.class.php | 20 | ||||
-rw-r--r-- | lib/init.php | 8 | ||||
-rw-r--r-- | server/ajax.server.php | 25 | ||||
-rw-r--r-- | templates/show_tv_playlist.inc.php | 14 | ||||
-rw-r--r-- | tv.php | 6 |
5 files changed, 65 insertions, 8 deletions
diff --git a/lib/class/tmp_playlist.class.php b/lib/class/tmp_playlist.class.php index 656ad44b..a262f3e8 100644 --- a/lib/class/tmp_playlist.class.php +++ b/lib/class/tmp_playlist.class.php @@ -376,6 +376,26 @@ class tmpPlaylist { } // vote_active /** + * remove_vote + * This is called to remove a vote by a user for an object, it uses the object_id + * As that's what we'll have most the time, no need to check if they've got an existing + * vote for this, just remove anything that is there + */ + function remove_vote($object_id) { + + $object_id = sql_escape($object_id); + $user_id = sql_escape($GLOBALS['user']->id); + + $sql = "DELETE FROM user_vote USING user_vote INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . + "WHERE user='$user_id' AND tmp_playlist_data.object_id='$object_id' " . + "AND tmp_playlist_data.tmp_playlist='" . sql_escape($this->id) . "'"; + $db_results = mysql_query($sql,dbh()); + + return true; + + } // remove_vote + + /** * delete_track * This deletes a track and any assoicated votes, we only check for * votes if it's vote playlist, id is a object_id diff --git a/lib/init.php b/lib/init.php index 47c55ad3..b6826943 100644 --- a/lib/init.php +++ b/lib/init.php @@ -289,7 +289,13 @@ elseif (!conf('use_auth')) { set_theme(); } else { - $user = new user(); + if (isset($_REQUEST['sessid'])) { + $results = vauth_get_session($_REQUEST['sessid']); + session_id(scrub_in($_REQUEST['sessid'])); + session_start(); + } + $user = new user($results['username']); + init_preferences(); } diff --git a/server/ajax.server.php b/server/ajax.server.php index 5c173b10..7787fac1 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -41,7 +41,6 @@ header("Cache-Control: no-cache"); switch ($action) { /* Controls Localplay */ case 'localplay': - init_preferences(); $localplay = init_localplay(); $localplay->connect(); $function = scrub_in($_GET['cmd']); @@ -75,9 +74,6 @@ switch ($action) { break; /* For changing the current play type */ case 'change_play_type': - init_preferences(); - session_id(scrub_in($_REQUEST['sessid'])); - session_start(); $_SESSION['data']['old_play_type'] = conf('play_type'); $pref_id = get_preference_id('play_type'); $GLOBALS['user']->update_preference($pref_id,$_GET['type']); @@ -131,6 +127,27 @@ switch ($action) { $xml_doc = xml_from_array($results); echo $xml_doc; break; + /* This can be a positve (1) or negative (-1) vote */ + case 'vote': + if (!$GLOBALS['user']->has_access(25) || $GLOBALS['user']->prefs['play_type'] != 'democratic') { break; } + /* Get the playlist */ + $tmp_playlist = get_democratic_playlist(-1); + + if ($_REQUEST['vote'] == '1') { + $tmp_playlist->vote(array($_REQUEST['object_id'])); + } + else { + $tmp_playlist->remove_vote($_REQUEST['object_id']); + } + + ob_start(); + $songs = $tmp_playlist->get_items(); + require_once(conf('prefix') . '/templates/show_tv_playlist.inc.php'); + $results['tv_playlist'] = ob_get_contents(); + ob_end_clean(); + $xml_doc = xml_from_array($results); + echo $xml_doc; + break; default: echo "Default Action"; break; diff --git a/templates/show_tv_playlist.inc.php b/templates/show_tv_playlist.inc.php index 19a2c80b..150b0b05 100644 --- a/templates/show_tv_playlist.inc.php +++ b/templates/show_tv_playlist.inc.php @@ -18,13 +18,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* Some defaults */ +$web_path = conf('web_path'); ?> <h3><?php echo _('Current Playlist'); ?></h3> <table cellspacing="0"> <tr class="table-header"> + <td><?php echo _('Action'); ?></td> <td><?php echo _('Votes'); ?></td> <td><?php echo _('Song'); ?></td> - <td><?php echo _('Length'); ?></td> </tr> <?php foreach($songs as $row_id=>$song_id) { @@ -32,9 +34,15 @@ foreach($songs as $row_id=>$song_id) { $song->format_song(); ?> <tr> + <td> + <?php if ($tmp_playlist->has_vote($song_id)) { ?> + <input class="button" type="button" value="-" onclick="ajaxPut('<?php echo conf('ajax_url'); ?>?action=vote&object_id=<?php echo $song_id; ?>&vote=-1<?php echo conf('ajax_info'); ?>')" /> + <?php } else { ?> + <input class="button" type="button" value="+" onclick="ajaxPut('<?php echo conf('ajax_url'); ?>?action=vote&object_id=<?php echo $song_id; ?>&vote=1<?php echo conf('ajax_info'); ?>')" /> + <?php } ?> + </td> <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> + <td><?php echo scrub_out($song->title . ' / ' . $song->get_album_name()); ?></td> </tr> <?php } ?> </table> @@ -48,6 +48,12 @@ switch ($action) { $songs = $tmp_playlist->get_items(); require_once(conf('prefix') . '/templates/show_tv.inc.php'); break; + /* This sends the playlist to the 'method' of their chosing */ + case 'send_playlist': + + + + break; case 'update_playlist': /* Only Admins Here */ if (!$GLOBALS['user']->has_access(100)) { |