Location: PHPKode > projects > Axis Groupware > musiclib/unused/tunez/admin_edit_id3.php
<?
die ("Probably just ruins stuff");
include ("tunez.inc.php");
include ("tunez_admin.inc.php");

$nrOfSongsBeforeUpdate = nrOfSongs();

displayHeader("Editing Song Info");
displayNavBar();
echo "<br>";
displayAdminNavBar();
echo "<br>";
echo "<form><input type=text name=song_id value=$song_id><input type=submit></form>\n\n<pre>";

if (!isset($action))
{
		echo "editing $song_id \n";

	$kweerie = "SELECT * from songs where song_id='$song_id'";
	$result = mysql_db_query("tunez", $kweerie);
	$row = mysql_fetch_array($result);

	$artist	= $row[artist];
	$songtitle = $row[songtitle];
	$filename = $row[filename];
	$album = $row[album];
	$year = $row[year];
	$genre = $row[genre];

	echo $filename;
	?>

	<form name="id3form" method=post>
	<input type=hidden name=action value="edit">
	<b>Artist:</b> <input type=text name=artist value="<? echo $artist?>"><br>
	<b>Songtitle:</b><input type=text name=songtitle value="<? echo $songtitle?>"><br>
	<b>Album:</b><input type=text name=album value="<? echo $album ?>"><br>
	<b>Jaar:</b><input type=text name=year value="<? echo $year ?>"><br>
	<b>Genre:</b><? dropdown_genre($genre); ?><br>
	<input type=submit>
	</form>

	<?
		$filehandle = fopen("$filename","r");

		$size = filesize("$filename");
		$seek = fseek($filehandle, $size-128);
		$tag = fgets($filehandle,128);

		
		if (strstr("$tag", "TAG") || strstr("$tag", "tag")) 
		{
			echo "TAG: $tag\n";

			// Extract the tag data and close the file
			// This is the correct order... 
			$songtitle = trim(substr($tag,3, 30));
			$artist	= trim(substr($tag,33, 30));
			$album = trim(substr($tag,63, 30));
			$year =  substr($tag,93, 4);
			$comment = trim(substr($tag,97,30));

			// Grab last char for the Genre
			// This can get confused for EOF with fgets
			$seek = fseek($filehandle, $size-1);
			$gen = ord(fgetc($filehandle));
			$genre = $genrename[$gen];

			echo "<b>Artist:</b> $artist <br>";
			echo "<b>Songtitle:</b> $songtitle <br>";
			echo "<b>Album:</b> $album <br>";
			echo "<b>Jaar:</b> $year <br>";
			echo "<b>Genre:</b> $genre <br>";

			fclose($filehandle);
		}
}

if ($action=="edit")
{
		# Get filename from database
		$kweerie = "SELECT * from songs where song_id='$song_id'";
		$result = mysql_db_query("tunez", $kweerie);
		$row = mysql_fetch_array($result);

		$filename = $row[filename];
		$filehandleR = fopen("$filename","r");

		# Checking for TAG

		$size = filesize("$filename");
		$seek = fseek($filehandleR, $size-128);
		$tag = fgets($filehandleR,128);
   
		echo "Filesize: $size \nDe TAG: $tag\n";   
		if (strstr("$tag", "TAG") || strstr("$tag", "tag")) 
		{
			echo "TAG exists.... overwriting....";
			$tagExists = "yes";
			//$seek = fseek($filehandle, $size-128);
		}
		else
		{
			echo "Not Tagged yet... doing it now";
			$tagExists = "no";
			//$seek = fseek($filehandle, $size);
		}
		fclose($filehandleR);
		$filehandleW = fopen("$filename","w");
		
		if ($tagExists == "yes")
		{
			$seek = fseek($filehandleW, $size-128);
		}
		else
		{
			$seek = fseek($filehandleW, $size);
		}
		
		$kweerie = "UPDATE songs SET artist = '$artist', songtitle = '$songtitle', album='$album', year = '$year', genre = '$genre' WHERE song_id=$song_id";
		echo "\n$kweerie\n";
		
		mysql_db_query("tunez", $kweerie);
		if (mysql_error()) { echo mysql_error();}
		
		# TAG construction starts here

		$artist = stripslashes($artist);
		$songtitle = stripslashes($songtitle);
		$album = stripslashes($album);

		$tag = "TAG";

		$tag .= $songtitle;
		$nrOfSpaces = 30  - strlen($songtitle);
		$tag .= gimmeSpaces($nrOfSpaces);

		$tag .= $artist;
		$nrOfSpaces = 30  - strlen($artist);
		$tag .= gimmeSpaces($nrOfSpaces);

		$tag .= $album;
		$nrOfSpaces = 30  - strlen($album);
		$tag .= gimmeSpaces($nrOfSpaces);

		$nrOfSpaces = 4  - strlen($year);
		$tag .= gimmeSpaces($nrOfSpaces);
		$tag .= $year;

		$tag .=  "http://tunez.sourceforge.net  ";

		$genre = (integer) $genre;
		$genre = chr($genre);

		$tag .= $genre;

		echo "\nsize van TAG: " . strlen($tag) . "\n";

		fputs($filehandleW, "$tag", 128);
		fclose($filehandleW);
		echo "\n12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678|";
		echo "\n$tag|";
		echo "\nTAG12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012341234567890123456789012345678901|";
}
displayFooter();
?>
Return current item: Axis Groupware