<?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.4.1 2006/10/24 06:53:05 skwashd Exp $ */

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

	$song_id  = (int) isset($_REQUEST['song_id'])  ? $_REQUEST['song_id']  : 0;
	$songlist = isset($_REQUEST['songlist']) ? $_REQUEST['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 ('" . $GLOBALS['phpgw']->db->db_addslashes($song_name) . "')",__LINE__,__FILE__);
	}
	else if ( count($songlist) )
	{
		$list = unserialize(rawurldecode($songlist));

		if ( !is_array($list) )
		{
			$list = array();
		}

		foreach ( $list as $song_id )
		{
			//echo '<br>' . $song_id;
			$GLOBALS['phpgw']->db->query('SELECT * FROM phpgw_dj_songlist WHERE song_id=' . (int)$song_id,__LINE__,__FILE__);
			$GLOBALS['phpgw']->db->next_record();	

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

			$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_dj_que (que_song) VALUES ('" . $GLOBALS['phpgw']->db->db_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='" . $GLOBALS['phpgw']->db->db_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', true)));
		$GLOBALS['phpgw']->template->set_var('row_artist',trim($db2->f('song_artist', true)));
		$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();
?>
