Location: PHPKode > projects > Music and Discography Database > music_db/new_record.php
<?
session_start();
require("common_funcs.php");
connectSQL();

if (isset($add)) {
    if ($inlogin) {
    query("SELECT album_id FROM album WHERE performer='$performer' AND title='$title'");
    if ($nur) {
        $message = 'This album has been uploaded!';
    }
    else {
        if ($year == '') $year = 0;
		if ($minutes == 0 and $seconds == 0) $time = '00:00:00';
		else {
			$min = $minutes%60;
			$hour = floor($minutes/60);
			$time = "$hour:$min:$seconds";
		}
        if ($disk == '') $disk = 0;
		if ($stars == 0) $vote = 0;
		else $vote = 1;
        sqlcmd("INSERT INTO album (performer,title,time,genre,year,stars,vote) 
                VALUES ('$performer','$title','$time','$genre','$year',$stars,$vote)");
        query("SELECT LAST_INSERT_ID()");
		if ($nur) $cid = mysql_fetch_row($res);
		else die("SQL INSERT ERROR!");
		if ($disk != '-1')
			sqlcmd("INSERT INTO shelf (user_id,album_id,storage,quality,format,comment) 
					VALUES ($inlogin,$cid[0],'$disk','$quality','$type','$log')");


        if ($_FILES["cover"]["tmp_name"] or trim($coveru) != '') {
            if (!($ffile = fopen($_FILES["cover"]["tmp_name"], "rb"))) {
				$rh = fopen($coveru, "rb");
		        $wh = fopen('/tmp/music_add.image', 'wb');
		        if ($rh===false || $wh===false) {
					// error reading or opening file
					return "Error 1.";
				}
				while (!feof($rh)) {
					if (fwrite($wh, fread($rh, 1024)) === FALSE) {
						// 'Download error: Cannot write to file ('.$file_target.')';
						return "Error 2.";
					}
				}
				fclose($rh);	
				fclose($wh);
				$mime = mime_content_type('/tmp/music_add.image');
				$size = filesize('/tmp/music_add.image');
				$ffile = fopen('/tmp/music_add.image','rb');
			} else {
				$mime = mime_content_type($_FILES["cover"]["tmp_name"]);
				$size = $_FILES['cover']['size'];
			}
			$contents = fread($ffile, $size);
			fclose($ffile);
            $contents = AddSlashes($contents);
            if($contents and $mime) {
              sqlcmd("INSERT INTO cover (album_id,image,mime,pg) VALUES ($cid[0],'$contents','$mime',0)");
            }
        }
        if ($nexus)
            sqlcmd("UPDATE nexus SET album_id='$cid[0]' WHERE album_id='-1'");
    }
    } else print "Impossible, No Rights!";
}

## HTML OUTPUT
print "
<HTML>
<HEAD>
    <TITLE>::: musicans database :::</TITLE>
    <LINK REL='stylesheet' HREF='styles_alter.css' TYPE='text/css'>
    <SCRIPT language='JavaScript' src='scripts.js'></SCRIPT>
    <SCRIPT>
      function PickUp() {
          var picked_inst = '';
          var insids = document.forms[0].instrum;
          for (var i = 0; i < insids.length; i++) {
              if (insids[i].selected) {
                  picked_inst += insids[i].value +',';
              }
          }
          document.forms[0].picked.value = picked_inst;
          document.forms[0].submit();
      }
      function EditNexus() {
          performer = document.forms[0].performer.value;
          title = document.forms[0].title.value;        
          openDGDialog('nexus.php?newrecord&album_id=-1&performer=' + performer + '&title=' + title, 950, 400, Returner);
          return false;
      }
      function Returner() {
          if ( dialogWin.returnedValue == '' ) return;
          var musicans = dialogWin.returnedValue;
          mi = musicans.replace(/;/g,'\\n');
          musicans = mi.replace(/:/g,' ... ');
          document.forms[0].musicans.value = musicans;
          document.forms[0].nexus.value = 1;
      }
</SCRIPT>
</HEAD>
<BODY>
<FORM METHOD='post' ENCTYPE='multipart/form-data'>
  <INPUT TYPE=hidden NAME=nexus VALUE=0>
  <DIV STYLE='border-bottom: 2px solid black;margin-bottom:14px'>
  <TABLE WIDTH=100% STYLE='padding:none;background:#818181;margin:none'>
    <TR><TD  STYLE='font-weight:bold;font-size:16px;'>New record</TD>
        <TD ALIGN=right><INPUT TYPE=submit NAME='add' VALUE='Add' class=button STYLE='background:#FFEFA2'></TD></TR>
  </TABLE>
</DIV>";

if (!isset($T)) $T = '';
query("SELECT substr(performer,1,1) as a FROM album GROUP BY a ORDER BY a");
$letters = array();
for ($i=0;$i<$nur;$i++) {
  $r = mysql_fetch_row($res);
  array_push($letters,$r[0]);
}

if (isset($keys)) { 
    query("SELECT performer FROM album 
           WHERE performer REGEXP '^$keys' 
           GROUP BY performer ORDER BY performer");
    $R = $nur; 
}
if (isset($sels) and $T=='') { 
    $sels = urldecode($sels); 
    $RES = $sels; 
    query("SELECT title,year 
           FROM album 
           WHERE performer LIKE '%$sels%' ORDER BY title "); 
    $R = $nur; 
} elseif (isset($sels) and $T!='') { 
    query("SELECT a.album_id,performer,title,storage,quality,time,genre,format,year,comment,stars 
           FROM album a LEFT JOIN shelf s ON (a.album_id=s.album_id) 
		   WHERE performer LIKE '%$T%' AND title LIKE '%$sels%' ORDER BY title"); 
    $R = $nur; 
	$RES = $T; 
} 
$RESULT = '';
for ($i=0;$i<$R;$i++) { 
    $r = next_row();
	if ($T == '') {
		if (isset($r['performer'])) $SP = $r['performer'];
		elseif (isset($r['title'])) $SP = $r['title'];
		$E = urlencode($SP); 
        if ($E == '') { 
            $SP = 'notitle'; $E = '*'; 
        } 
        if (isset($sels)) $year = " (".$r['year'].")"; 
        else $year = ''; 
        $RESULT .= "<A HREF='$PHP_SELF?sels=$E&T=$RES'>$SP$year</A><BR>"; 
    } else {
		$RESULT .= " 
		<TABLE STYLE='padding-top:15px'> 
			<TR><TD>Artist:</TD><TD CLASS='smallgrey'>{$r['performer']}</TD></TR>
			<TR><TD>Title:</TD><TD CLASS='smallgrey'>{$r['title']} ({$r['year']})</TD></TR>
			<TR><TD>Time:</TD><TD CLASS='smallgrey'>{$r['time']}</TD></TR>
			<TR><TD>Genre:</TD><TD CLASS='smallgrey'>{$r['genre']}</TD></TR>
			<TR><TD>Cat.No.:</TD><TD CLASS='smallgrey'>{$r['storage']}</TD></TR>
			<TR><TD>Quality:</TD><TD CLASS='smallgrey'>{$r['quality']}</TD></TR>
			<TR><TD>Encode:</TD><TD CLASS='smallgrey'>{$r['format']}</TD></TR>
			<TR><TD>Comment:</TD><TD CLASS='smallgrey'>{$r['comment']}</TD></TR>
			<TR><TD>Rating:</TD><TD CLASS='smallgrey'>{$r['stars']}</TD></TR>
		</TABLE>";
	}
}

print "$message<DIV ALIGN=right STYLE='padding-bottom:8px'>";
for ($i=0;$i<count($letters);$i++) {
    print "<A href='$PHP_SELF?keys=$letters[$i]' 
			STYLE='font-weight:600;color:#212121;font-size:11px;letter-spacing:6px'>$letters[$i]</A>";
}

if ($_FILES['browsefile']['tmp_name']) 
{
  require_once('/usr/share/php-getid3/getid3.php');
  $getID3 = new getID3;
  $tfi = $getID3->analyze( $_FILES['browsefile']['tmp_name'] );

  $id3_fileformat = $tfi[fileformat];
  $id3_album = $tfi[ogg][comments][album][0];
  $RES = $id3_artist =  $tfi[ogg][comments][artist][0];
  $id3_date = date('Y',strtotime($tfi[ogg][comments][date][0]));
  $id3_genre = $tfi[ogg][comments][genre][0];
  #print_r($tfi);
}

print "</DIV>
<INPUT TYPE=file NAME=browsefile SIZE=60 onChange='this.form.submit()'>";
if ($id3_fileformat=='') {
    $txt = file_get_contents($_FILES['browsefile']['tmp_name']);
    $txt = preg_replace('/\n/','<BR>',$txt);
    echo $txt;
}

print "
<TABLE CELLPADDING=0 CELLSPACING=0><TR><TD VALIGN=top>
    <INPUT TYPE=hidden NAME=id VALUE=$r[0]>
    <TABLE>
    <TR><TD STYLE='background:#a7ada6;width:60px'>Performer</TD><TD><INPUT TYPE=text NAME=performer SIZE=50 VALUE='$RES'></TD></TR>
    <TR><TD STYLE='background:#a7ada6'>Title</TD><TD><INPUT TYPE=text NAME=title SIZE=50 VALUE='". $id3_album."'></TD></TR>
    <TR><TD STYLE='background:#a7ada6'>Year</TD><TD><INPUT TYPE=text NAME=year SIZE=50 VALUE=". $id3_date ."></TD></TR>
    <TR><TD STYLE='background:#a7ada6'>Time</TD><TD>min:<SELECT NAME=minutes>";
	for ($i=0;$i<301;$i++) print "<OPTION>$i</OPTION>";
	print "</SELECT> sec:<SELECT NAME=seconds>";
	for ($i=0;$i<60;$i++) print "<OPTION>$i</OPTION>";
	print "</SELECT>
	</TD></TR>
    <TR><TD STYLE='background:#a7ada6'>Musicans</TD>
        <TD><TEXTAREA NAME=musicans cols=50 rows=4 CLASS=input READONLY></TEXTAREA><BR>
            <INPUT TYPE=button VALUE='Edit' OnClick='EditNexus()' class=button></TD></TR>
	<TR><TD STYLE='background:#a7ada6' ROWSPAN=2>Cover</TD><TD>file: <INPUT NAME=cover TYPE=file></TD></TR>
	<TR><TD>url: <INPUT NAME=coveru TYPE=text STYLE='width:90%'></TD></TR>

    <TR><TD STYLE='background:#6682aa'>Genre</TD><TD>"; make_select('GENRES','genre',$id3_genre); print"</TD></TR>
    <TR><TD STYLE='background:#6682aa'>Rating</TD><TD>
                <SELECT NAME=stars><OPTION value=0>&nbsp; n/a &nbsp;</OPTION>";
				$i = 1;
				while ($i<5) {
					printf ("<OPTION>%01.1f</OPTION>",$i);
					$i += 0.1;
				} 
                print "</SELECT> 
    <IMG SRC='icons/favourites-star-SH-16x16.png'>...<IMG SRC='icons/favourites-star-SH-16x16.png'></TD></TR>
	<TR><TD COLSPAN=2><DIV STYLE='height:4px'></DIV></TD></TR>

	<TR STYLE='background:#989568'><TD STYLE='font-size:10px'><b>on shelf</b></TD><TD>&nbsp;</TD></TR>
    <TR><TD STYLE='background:#989568'>Type</TD><TD>"; make_select('TYPES','type',$id3_fileformat); print"</TD></TR>
    <TR><TD STYLE='background:#989568'>Quality</TD><TD><INPUT TYPE=text NAME=quality SIZE=50></TD></TR>
    <TR><TD STYLE='background:#989568'>Catalog&nbsp;No.</TD><TD><INPUT TYPE=text NAME=disk SIZE=50></TD></TR>
    <TR><TD STYLE='background:#989568'>Comment</TD><TD><INPUT TYPE=text NAME=error SIZE=50></TD></TR>
    </TABLE>
</TD><TD VALIGN=top WIDTH=100% STYLE='padding-left:50px'>$RESULT</TD></TR></TABLE></FORM>";

?>
Return current item: Music and Discography Database