<?php
  /**************************************************************************\
  * phpGroupWare - phpgw_dj                                                  *
  * http://www.phpgroupware.org                                              *
  * Written by Miles Lott <milosch@phpgroupware.org>                         *
  * --------------------------------------------                             *
  *  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.                                              *
  \**************************************************************************/

  /* $Id: download.php,v 1.2.4.1 2006/10/24 06:53:05 skwashd Exp $ */

	$GLOBALS['phpgw_info']['flags'] = array(
		'currentapp'           => 'dj',
		'enable_browser_class' => True,
		'noheader'             => True,
		'nonavbar'             => True,
		'noappheader'          => True,
		'noappfooter'          => True
	);
	include_once('../header.inc.php');

	$sep = SEP;

	if (!$song_id)
	{
		Header("Location: " . $GLOBALS['phpgw']->link("/dj/index.php"));
		$GLOBALS['phpgw']->common->phpgw_exit();
	}
	else
	{
		$sql = "SELECT song_name FROM phpgw_dj_songlist WHERE song_id=" . (int) $song_id;
		$GLOBALS['phpgw']->db->query($sql);
		$GLOBALS['phpgw']->db->next_record();
		$filename = $GLOBALS['phpgw']->db->f(0);

		if ($filename)
		{
			if ($fp = fopen($filename, "r"))
			{
				$content = fread($fp, filesize($filename));
				fclose($fp);
			}

			$GLOBALS['phpgw']->browser->content_header($filename,'application/octet-stream',filesize($filename));
			echo $content;
		}
	}
?>
