<?php 
/*
 *
 * sflog!
 * Copyright (C) 2005 Alberto Sfolcini <a.sfolcini@gmail.com>
 *
 * This file is a part of sflog!.
 *
 * sflog! 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.
 *
 * sflog! is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */
 
  require_once(dirname(__FILE__)."/../../common/WriteFile.class.php");
  require_once(dirname(__FILE__)."/../../cms/PhotoBlogBar.class.php");
  require_once(dirname(__FILE__)."/../../cms/Constants.inc.php");
  require_once(dirname(__FILE__)."/../../cms/Auth.class.php");

  // Check for authorizations
  $auth = new Auth();
  if (!$auth->isAuth()){
  	header("Location: login.php");
  	die();
  }
  // ------ end auth's check

  /**
   * Write filecomment
   */
  function writeComment($fileName,$strComment){
  	$fn = $fileName.'.comment';
  	$fw = new WriteFile($fn,REWRITE);
  	$fw->writeStr($strComment);
  	$fw->closeFile();
  }	


  if (isset($_GET['id'])){
  	if (!($_GET['id']=='')){
	   $id = stripslashes($_GET['id']);  	  	
  	}
  }
  
  if (isset($_POST['id'])){
  	if (!($_POST['id']=='')){
  		$id = stripslashes($_POST['id']);
  	}
  	if (isset($_POST['comment'])){
	  	if (!($_POST['comment']==''))
	  		$comment = stripslashes($_POST['comment']);
	  	else
	  		$comment = '';
  	}
  	
  	// write
  	writeComment($id,$comment);
  }
  
  
  
  // read the current comment value
  if (file_exists($id.'.comment'))
  	$comment = file_get_contents($id.'.comment');
  else
  	$comment = "";
  
?>	
<FORM name="comment" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
	<input type="hidden" name="id" value="<?=$id?>">
	<table cellspacing="0" cellpaddgin="0" border="0">
		<tr>
			<td align="center"><img src="<?=$id?>" border="0" width="200px" heigth="200px" alt=""></td>
			<br>
		</tr>
		<tr>
			<td>
				<textarea name="comment" cols="55" rows="5"><?=trim($comment)?></textarea>
			</td>			
		</tr>
		<tr>
			<td><input type="SUBMIT" value="update" size="1"></td>
		</tr>
	</table>
</FORM>