<?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.5 2001/05/11 16:59:31 jengo Exp $ */

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

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

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

		$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;
			$phpgw->db->query("SELECT * FROM phpgw_dj_songlist WHERE song_id='$song_id'",__LINE__,__FILE__);
			$phpgw->db->next_record();	

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

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

	$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
	$p->set_file(array('request' => 'request.tpl'));
	$p->set_block('request','list','list');
	$p->set_block('request','row','row');

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

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

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

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

	$p->pfp('out','list');

	$phpgw->common->phpgw_footer();
?>
