function remove_track() { $userid = $this->session->userdata('userid'); $result = array("error" => FALSE); if (!$userid) { $result["error"] = "User must be logged in to access her playlist."; } else { $trackid = array($this->input->post('trackid')); $albumid = array($this->input->post('albumid')); $playlistid = $this->input->post('playlistid'); try { $pl = Playlist::load($playlistid); if ($pl->getOwnerId() != $userid) { throw new Exception("Sorry, you are not allowed to remove tracks from a playlist you did not create"); } if (!Playlist::removeTracks($trackid, $albumid, $playlistid)) { $result["error"] = TRUE; } } catch (Exception $e) { $result["error"] = $e->getMessage(); } } echo json_encode($result); }