<?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.1.1.1.18.1 2004/09/26 10:51:04 kazuyan Exp $ */

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

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

	/* delete_songs(); */

	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)
			{
				$mp3info->title = $data;
			}

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

			if(!$cats->exists('mains',$mp3info->genre))
			{
				/* $cats->add($mp3info->genre,0,$mp3info->descr,'','public',''); */
				$cats->add(array(
					'name'   => $mp3info->genre,
					'descr'  => $mp3info->descr,
					'access' => 'public',
					'data'   => ''
				));
			}

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

	if ($debug)
	{
		echo '<pre>' . $buffer . '</pre>';
		echo '<a href="'.$GLOBALS['phpgw']->link('/dj/index.php') . '">'.lang('OK').'</a>';
	}
	else
	{
		echo '<a href="'.$GLOBALS['phpgw']->link('/dj/index.php') . '">'.lang('OK').'</a>';
		//echo "<br>" . lang('Successfully imported %1 records',$num);
		if($num)
		{
			echo "<br>" . lang('Successfully imported %1 records',$num)."\n";
		}
		else
		{
			echo "<br>" . lang('No new files')."\n";
		}
	}
	$GLOBALS['phpgw']->common->phpgw_footer();
?>
