#!/usr/local/bin/perl
require "blendcommon.cgi";
require "blendiii.pl";
PrintHeader();

my($trueid,$truename) = getUserFromSession();

chugCGI(*input);
$id =  $input{"id"};




$id =~ /^(.*?)\.(.*?)\.(.*)$/;

$year = $1;
$mon = $2;
$rest = $3;

    $file = "$dirworks/$year/$mon/$rest.work";

open(READ,"$dirworks/$year/$mon/$rest.info");






$userid = <READ>; chomp $userid;
$username = <READ>; chomp $username;
$authorname = <READ>; chomp $authorname;
$title = <READ>; chomp $title;
$descrip = <READ>; chomp $descrip;
$kindofwork = <READ>; chomp $kindofwork;
close READ;

$editlink = "";
if($userid eq $trueid){
    $editlink = qq(<i>- <a href="/blend/submitwork.cgi?id=$id">edit this work</a></i>);
}

if($title eq "") { $title = "<i>Untitled</i>";}

$gogo = <<__EOQ__;
<i><a href="/blend/feedback.cgi?linkto=$id" target="_top"
onClick="
getElementById('commentspan').style.display='';
return false;"
>Comment on this Work</a></i>
<font size=-1><br>[[$id]]</font>
__EOQ__


print<<__EOQ__;
<head>
<title>
$title | blender of love 
</title>
<link rel="image_src" href="/blimage/iii/blender.png" />
</head>
<body>
<!-- facebook -->

<div id="fb-root"></div>
    <script>(function(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) return;
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
	fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>


<table border=0>
<tr><td>
__EOQ__




    if($authorname eq ""){
        print <<__EOQ__;
By <a href="/blend/av.cgi?id=$userid" target="_top">$username</a> $editlink<br>

__EOQ__
$aboutauthor = $username;
} else {
    print <<__EOQ__;

By $authorname <BR>
Submitted by <a href="/blend/av.cgi?id=$userid" target="_top">$username</a> $editlink <br>

__EOQ__
$aboutauthor = $authorname;

}

$rest =~ /^(.*?)\./;
$mday = $1;

@months = ("Jan", "Feb","Mar","Apr","May","Jun","Jul",
	   "Aug","Sep","Oct", "Nov", "Dec");
$month = $months[$mon-1];
print <<__EOQ__;
Date: $year $month $mday<br>


__EOQ__

print<<__EOQ__;
$gogo

</td></tr></table>
<span id="commentspan" style="display:none">
__EOQ__

    $title =~ s/\"/\'/g;

printCommentForm($trueid,$truename,qq($aboutauthor, about [["$title":$id]]:));

print<<__EOQ__;
</span>
<h2>$title</h2>
__EOQ__


    print "<table width=600><tr><td>";
open(BODY,"< $file");
while(defined($next=<BODY>)){
    print $next;
}
close BODY;
print "</td></tr></table>";

# facebook
print<<__EOQ__;
<br><br><br>
<div class="fb-like" data-href="http://loveblender.com/blend/wv.cgi?id=$id" data-send="true" data-width="450" data-show-faces="true"></div>
__EOQ__
