<?


$sys['user'] = $_GET['user'];

if ($_GET['uid']) {

	$shareInfo = $share->getInfo($_GET['uid']."::".gluePath($sys['path'], $sys['object']));
	$sys['fullPath'] = $shareInfo['path'];
	//debug($sys);
	//debug($shareInfo);
} else {

$path = gluePath("/",$sys['path'], $sys['object']);
$sys['fullPath'] = gluePath($permissions['path'],$path);

}


if (!isCleanFilename($sys['object'])){
die(base64_encode("dirty filename ".$sys['object']));
}



if (!$permissions['readonly']) {

	if ($_POST && is_array($shareInfo) && !$shareInfo['write']) {
		$msg = "<span style=\"white-space:nowrap\">".$lang->get("Shared folder has readonly access")."</span>.<br>".$lang->get("You cannot add comments.")."";
		$statusBarMessage[] = array($msg, 0);
	} else {
		if ($_POST['submited']) {
			$comments->set($sys['fullPath'], $str->fromHTML($_POST['descr']));
			$log->act("0", "comment", $sys['fullPath'].": ".$str->fromHTML($_POST['descr']));
		}
		if ($_GET['delete'] && !$_GET['uid']) {
			$comments->delete($sys['fullPath'], $_GET['delete']);
			$log->act("0", "comment deleted", $sys['fullPath']);
		}
	
		if ($_GET['deleteall'] && !$_GET['uid']) {
			$comments->delete($sys['fullPath']);
			$log->act("0", "all comments deleted", $sys['fullPath']);
		}
	}
}



$title = $lang->get("Comments");
//template header
require_once($sys['root']."/system/templates/popup/header.inc");

$results = $comments->get($sys['fullPath']);

?>
<style type="text/css">
td.title
{
text-align:right;
width:50px;
vertical-align:top;
font-weight:bold;
padding-right:10px;
background-image:url(images/interface/locationbarbg.gif);
background-repeat:repeat-x;
background-color:white;
border-top:1px solid white;
border-right:1px solid silver;
border-bottom:1px solid silver;
border-left:1px solid white;
padding:5px;
vertical-align:top;
width:100px;
}

td.user
{
text-align:right;
width:50px;
vertical-align:top;
font-weight:bold;
background-color:white;
border-top:1px solid white;
border-right:1px solid silver;
border-bottom:1px solid silver;
border-left:1px solid white;
padding:5px;
vertical-align:top;
width:150px;
}

td.description
{
border-top:1px solid white;
border-right:1px solid silver;
border-bottom:1px solid silver;
border-left:1px solid white;
padding:5px;
vertical-align:top;
background-image:none;
background-color:#E4E4E4;
width:100%;
}

td.delete
{
border-top:1px solid white;
border-right:1px solid silver;
border-bottom:1px solid silver;
border-left:1px solid white;
padding:5px;
vertical-align:top;
background-image:none;
background-color:#E4E4E4;
width:50px;
}
</style>


<table cellspacing="0" cellpadding="0" border="0" style="width:100%;height:100%;background-color:#F2F2F2">
<tr>
    <td background="images/popup/top-bg.gif" height="26">&nbsp;</td>
</tr>

<tr>
    <td style="padding:10px;" valign="top">
<!-- Popup Contents -->




<?

if (is_array($results)) {
?>
<br>
<table style="width:500px" cellpadding="0" cellspacing="0" border="0" align="center">
<td class="title" style="width:100%">&nbsp;</td>
</tr></table>
<table style="width:500px" cellpadding="0" cellspacing="0" border="0" align="center">
<?
for ($i = 0 ; $i < sizeof($results) ; $i++) {
?>
<tr title="<?$lang->display("Posted on ");?><?echo date("j F Y - H:i", $comments->tmpdb->db[$results[$i]]['date']);?>"><td class="user"><?echo $comments->tmpdb->db[$results[$i]]['user'];?>:</td><td class="description"><?echo $comments->htmlDescription($comments->tmpdb->db[$results[$i]]['msg']);?></td><td class="delete">
<?


if (!$permissions['readonly'] && !$_GET['uid']) {
$tpl->btn(
$lang->get("Delete"), 
"document.location.href='?file=comments&path=".$str->forURL($sys['path'])."&object=".$str->forURL($sys['object'])."&uid=".$str->forURL($sys['uid'])."&delete=".$comments->tmpdb->db[$results[$i]]['date']."'"
);

} else {
echo "&nbsp;";
}


?>
</td></tr>

<?
}

} else {
?>
<br>
<table style="width:500px" cellpadding="0" cellspacing="0" border="0" align="center">
<tr><td class="description" style="background-image:url(images/interface/locationbarbg.gif);background-color:#E4E4E4;" align="center"><?$lang->display("No comments");?></td></tr>
<?
}
?>

</table>

	</td>
</tr>

<tr height="100">
    <td align="center">

<form action="<?echo glueURL(array("uid"=>$str->forURL($sys['uid']),"path"=> $str->forURL($sys['path']),"object"=>$str->forURL($sys['object']),"file"=>"comments"));?>" method="post" name="commentForm">
<br>

<table style="width:500px;text-align:center;" cellpadding="0" cellspacing="0" border="0"  align="center">
<tr><td>
<textarea name="descr" style="align:left;width:500px;text-align:left;margin-left:10px;margin-right:10px;height:70px;"></textarea>
</td></tr></table>


<table cellpadding="1" cellspacing="3" border="0" align="center" style="position:relative;top:18px;z-index:1">
<tr><td>
<input type="hidden" name="submited" value="1">
<?
if (!$permissions['readonly']) {
$tpl->btn(
$lang->get(" Add "), 
"document.commentForm.submit()"
);
} else {
$tpl->btn(
$lang->get(" Add "), 
"msg('noperm', 1)"
);

}
?>	
</td>

<?
if (is_array($results)) {
if (!$permissions['readonly'] && !$_GET['uid']) {
?>
<td>
<?
$tpl->btn(
$lang->get("Delete all"), 
"document.location.href='?file=comments&path=".$str->forURL($sys['path'])."&object=".$str->forURL($sys['object'])."&uid=".$str->forURL($sys['uid'])."&deleteall=1'"
);
?>
</td>
<?
}
}
?>
<td>
<?
$tpl->btn(
$lang->get("Close"), 
"self.close();window.close()"
)
?>
</td></tr></table>
</form>

	</td>
</tr>

<tr>
    <td background="images/popup/bottom-bg.gif" height="46">&nbsp;</td>
</tr>
</table>

<?
//template footer
require_once($sys['root']."/system/templates/popup/footer.inc");
?>