<?php
  /**************************************************************************\
  * phpGroupWare - phpgw_dj                                                  *
  * http://www.phpgroupware.org                                              *
  * Written by Joseph Engo <jengo@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: request.php,v 1.7 2001/09/15 12:05:51 milosch Exp $ */

	$GLOBALS['phpgw_info']['flags'] = array(
		'currentapp'              => 'dj',
		'enable_nextmatchs_class' => True
	);
	include('../header.inc.php');

	$song_id  = $HTTP_POST_VARS['song_id']  ? $HTTP_POST_VARS['song_id']  : $HTTP_GET_VARS['song_id'];
	$songlist = $HTTP_POST_VARS['songlist'] ? $HTTP_POST_VARS['songlist'] : $HTTP_GET_VARS['songlist'];

	if ($song_id)
	{
		$GLOBALS['phpgw']->db->query("SELECT * FROM phpgw_dj_songlist WHERE song_id='$song_id'",__LINE__,__FILE__);
		$GLOBALS['phpgw']->db->next_record();	

		$song_name = $GLOBALS['phpgw']->db->f('song_name');

		$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_dj_que (que_song) VALUES ('" . addslashes($song_name) . "')",__LINE__,__FILE__);
	}
	elseif($songlist)
	{
		$list = unserialize(rawurldecode($songlist));

		while (list($key,$song_id) = @each($list))
		{
			//echo '<br>' . $song_id;
			$GLOBALS['phpgw']->db->query("SELECT * FROM phpgw_dj_songlist WHERE song_id='$song_id'",__LINE__,__FILE__);
			$GLOBALS['phpgw']->db->next_record();	

			$song_name = $GLOBALS['phpgw']->db->f('song_name');

			$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_dj_que (que_song) VALUES ('" . addslashes($song_name) . "')",__LINE__,__FILE__);		
		}
	}

	$GLOBALS['phpgw']->template->set_file(array('request' => 'request.tpl'));
	$GLOBALS['phpgw']->template->set_block('request','list','list');
	$GLOBALS['phpgw']->template->set_block('request','row','row');

	$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
	$GLOBALS['phpgw']->template->set_var('message',lang('The following songs are in the queue to be played'));
	$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
	$GLOBALS['phpgw']->template->set_var('lang_artist',lang('Artist'));
	$GLOBALS['phpgw']->template->set_var('lang_year',lang('Year'));
	$GLOBALS['phpgw']->template->set_var('lang_genre',lang('Genre'));
	$GLOBALS['phpgw']->template->set_var('lang_time',lang('Time'));

	$db2 = $GLOBALS['phpgw']->db;
	$GLOBALS['phpgw']->db->query("select * from phpgw_dj_que order by que_id asc",__LINE__,__FILE__);
	while ($GLOBALS['phpgw']->db->next_record())
	{
		$db2->query("select * from phpgw_dj_songlist where song_name='" . addslashes($GLOBALS['phpgw']->db->f('que_song')) . "'",__LINE__,__FILE__);
		$db2->next_record();
		$totaltime = $totaltime + $db2->f('song_length');

		$GLOBALS['phpgw']->nextmatchs->template_alternate_row_color($GLOBALS['phpgw']->template);
		$GLOBALS['phpgw']->template->set_var('row_title',trim($db2->f('song_title')));
		$GLOBALS['phpgw']->template->set_var('row_artist',trim($db2->f('song_artist')));
		$GLOBALS['phpgw']->template->set_var('row_year',trim($db2->f('song_year')));
		$GLOBALS['phpgw']->template->set_var('row_genre',trim($db2->f('song_genre')));
		$GLOBALS['phpgw']->template->set_var('row_time',date('i:s',$db2->f('song_length')));

		$GLOBALS['phpgw']->template->parse('rows','row',True);
	}
	$GLOBALS['phpgw']->template->set_var('lang_totaltime',lang('Total time'));
	$GLOBALS['phpgw']->template->set_var('value_totaltime',date('i:s',$totaltime));
	$GLOBALS['phpgw']->template->set_var('value_done','<a href="' . $GLOBALS['phpgw']->link('/dj/index.php','cat_id='.$cat_id) . '">' . lang('Done') . '</a>');

	$GLOBALS['phpgw']->template->pfp('out','list');

	$GLOBALS['phpgw']->common->phpgw_footer();
?>
