<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.1 www.exoops.info 2006/08 GPL 
include("header.php");
include_once(XOOPS_ROOT_PATH."/class/xoopscomments.php");
if ( isset($_POST['op']) ){
	switch($_POST['op']){
	    case "preview":
		include(XOOPS_ROOT_PATH."/header.php");
		$p_subject = $myts->makeTboxData4Preview($subject);
		if ( $nosmiley && $nohtml ) {
			$p_comment = $myts->makeTareaData4Preview($message,0,0,1);
		} elseif ( $nohtml ) {
			$p_comment = $myts->makeTareaData4Preview($message,0,1,1);
		} elseif ( $nosmiley ) {
			$p_comment = $myts->makeTareaData4Preview($message,1,0,1);
		} else {
			$p_comment = $myts->makeTareaData4Preview($message,1,1,1);
		}
		themecenterposts($p_subject,$p_comment);
		$anonuser = $myts->makeTboxData4PreviewInForm($_POST['anonuser']);
		$subject = $myts->makeTboxData4PreviewInForm($subject);
		$message = $myts->makeTareaData4PreviewInForm($message);
		OpenTable();
		include(XOOPS_ROOT_PATH."/include/commentform.inc.php");
		CloseTable();
		break;
	    case "post":
		
		if ( !empty($comment_id) ) {
			$photocomment = new XoopsComments($db->prefix("myalbum_comments"),$comment_id);
			$accesserror = 0;
			if ( $xoopsUser ) {
				if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
					if($photocomment->getVar("user_id") != $xoopsUser->getVar("uid")){
						$accesserror = 1;
					}
				}
			} else {
				$accesserror = 1;
			}
			if($accesserror == 1){
				redirect_header("photo.php?lid=".$item_id."&amp;comment_id=".$comment_id."&amp;order=".$order."&amp;mode=".$mode."",1,_PL_EDITNOTALLOWED);
				exit();
			}
		} else {
			$photocomment = new XoopsComments($db->prefix("myalbum_comments"));
			$photocomment->setVar("pid", $pid);
			$photocomment->setVar("item_id", $item_id);
			$photocomment->setVar("ip", $REMOTE_ADDR);
			if ( $xoopsUser ) {
				$uid = $xoopsUser->getVar("uid");
			} else {
				if ( $bcoosConfig['anonpost'] == 1 ) {
					$uid = 0;
				} else {
					redirect_header("photo.php?lid==".$item_id."&amp;comment_id=".$comment_id."&amp;order=".$order."&amp;mode=".$mode."&amp;pid=".$pid."",1,_PL_ANONNOTALLOWED);
					exit();
				}
			}
			$photocomment->setVar("user_id", $uid);
		}
if (!$xoopsUser && $bcoosConfig['anonpost'] && $bcoosConfig['captcha_comments'] && function_exists('imagecreate')) {
				include_once(XOOPS_ROOT_PATH."/class/rc4.crypt.php");
				$rc4 = new rc4_crypt();
				$rc4->key(strtoupper($verify_text));
				$verify_crc = base64_decode($verify_crc);
				$rc4->decrypt($verify_crc);
				if ( empty($verify_text) || $verify_crc != "verified" ) {
					include(XOOPS_ROOT_PATH."/header.php");
					$p_subject = $myts->makeTboxData4Preview($subject);
					if ( $nosmiley && $nohtml ) { $p_comment = $myts->makeTareaData4Preview($message,0,0,1); }
					elseif ( $nohtml ) {$p_comment = $myts->makeTareaData4Preview($message,0,1,1); }
					elseif ( $nosmiley ) { $p_comment = $myts->makeTareaData4Preview($message,1,0,1); }
					else { $p_comment = $myts->makeTareaData4Preview($message,1,1,1); }
					echo "<b>"._US_BADVERIF."</b>";
					themecenterposts($p_subject,$p_comment);
					$subject = $myts->makeTboxData4PreviewInForm($subject);
					$message = $myts->makeTareaData4PreviewInForm($message);
					OpenTable();
					include(XOOPS_ROOT_PATH."/include/commentform.inc.php");
					CloseTable();
					include_once(XOOPS_ROOT_PATH."/footer.php");//content
					exit();
				}
			}
		$photocomment->setVar("subject", $subject);
		$photocomment->setVar("comment", $message);
		$photocomment->setVar("nohtml", $nohtml);
		$photocomment->setVar("nosmiley", $nosmiley);
		$photocomment->setVar("icon", $icon);
		$photocomment->setVar("anonuser", $_POST['anonuser']);
		$photocomment->store();
		$db->query("update ".$db->prefix("myalbum_photos")." set comments=comments+1 where lid=$item_id ");
		redirect_header("photo.php?lid=".$item_id."&amp;comment_id=".$comment_id."&amp;order=".$order."&amp;mode=".$mode."",2,_THANKSSUBMIT);
		exit();
		break;
	}
} else {
	redirect_header("photo.php?lid=$item_id&comment_id=$comment_id&order=$order&mode=$mode",2);
	exit();
}
include(XOOPS_ROOT_PATH."/footer.php");
?>
