<?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: scan.php,v 1.3 2001/05/11 18:00:45 milosch Exp $ */

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

	$sep = SEP;

	$cats = CreateObject('phpgwapi.categories');
	$num = 0;
	$files = get_files();

	while (list($key,$data) = each($files))
	{
		//echo '<br>Checking '. $data;
		if (!song_exists($data))
		{
			echo '<br>' . lang('Adding') . ' ' . $data;
			$buffer .= $data;
			$mp3info = get_info($data);

			$mp3info->title = $mp3info->name;
			if (!$mp3info->title)
			{
				$title = $data;
			}

			$mp3info->descr = $mp3info->genre .' (#'. $mp3info->genreno .')';

			if(!$cats->exists('mains',$mp3info->genre))
			{
				$cats->add($mp3info->genre,$mp3info->genre,$mp3info->descr,'','public','');
			}

			add_song($mp3info);
			$num++;
		}
	}

	if ($debug)
	{
		echo '<pre>$buffer</pre>';
		echo '<a href="'.$phpgw->link('/dj/index.php',
			"sort=$sort&order=$order&filter=$filter&start=$start&query=$query&cat_id=$cat_id")
			. '">'.lang('OK').'</a>';
		$phpgw->common->phpgw_footer();
	}
	else
	{
		echo '<a href="'.$phpgw->link('/dj/index.php',
			"sort=$sort&order=$order&filter=$filter&start=$start&query=$query&cat_id=$cat_id")
			. '">'.lang('OK').'</a>';
		//echo "<br>" . lang('Successfully imported x records',$num);
		if($num)
		{
			echo "<br>Successfully imported $num records\n";
		}
		else
		{
			echo "<br>No new files\n";
		}

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