<?php
/*
=====================================================
 Модуль создал: REZER (http://rezer.net)
=====================================================
 Файл: comments.php
=====================================================
 Данный код защищен авторскими правами
=====================================================
 Назначение: вывод комментариев и формы добавления
=====================================================
*/

if( !defined( "DATALIFEENGINE" ) ) die( "Hacking attempt!" );

// Комментарии
if( $Board->Config['com_on'] == "yes" && $allow_comm == 1 )
	{
		// Форма добавления комментариев
		$com_groups_captcha = explode( ",", $Board->Config['com_groups_captcha'] );
		$allow_groups_add_com = explode( ",", $Board->Config['com_groups_add'] );
		if( $is_logged || $Board->Config['com_anonim'] == "yes" )
			{
				if( in_array( $member_id['user_group'], $allow_groups_add_com ) || !$is_logged )
					{
						$allow_add_com = true;
						include_once( ENGINE_DIR."/modules/board/addcomments.php" );
						include_once( ENGINE_DIR."/modules/board/editor/bb_comment.php" );
						$tpl->Load_Template( "board/{$Folder}/comments/addcomments.tpl" );
																
						$tpl->copy_template = "<div id=\"addcomments_form\">".$tpl->copy_template."<input type=\"hidden\" name=\"board_id\" value=\"{$id}\" /></div>";
						$tpl->copy_template = "".$tpl->copy_template."<script language=\"javascript\" type=\"text/javascript\">var form_test = document.getElementById( 'addcomments_form' ).innerHTML;</script>";
						$tpl->set( "{editor}", $bb_code );
						$tpl->set( "{text}", $comment );
						if( !$is_logged )
							{
								$tpl->set( "[not-logged]", "" );
								$tpl->set( "[/not-logged]", "" );
							}
								else
							{
																		
								$tpl->set_block( "'\\[not-logged\\](.*?)\\[/not-logged\\]'si", "" );
							}
																	
						if( in_array( $member_id['user_group'], $com_groups_captcha ) )
							{
								$tpl->set( "{captcha}", "<span id=\"dle-captcha\"><img src=\"/engine/modules/antibot.php\" border=\"0\" width=\"120\" height=\"50\" onclick=\"BoardReCaptcha(); return false;\" style=\"cursor: pointer;\" /></span>" );
								$tpl->set( "[captcha]", "" );
								$tpl->set( "[/captcha]", "" );
							}
								else
							{
								$tpl->set_block( "'\\[captcha\\](.*?)\\[/captcha\\]'si", "" );
							}
																
						$tpl->compile( "board_addcomments" );
						$tpl->clear();
					}
						else
					{
						$error_add = "Вы находитесь в группе, которой запрещено комментировать объявления.";		
					}
			}
				else
			{
				$error_add = "Для того, чтобы добавлять комментарии, необходимо авторизироваться.";	
			}
										
		// Вывод комментариев
		if( $comm_num > 0 )
			{
				require_once( ENGINE_DIR."/modules/board/tree.comments.class.php" );
				$Board->Config['com_sort'] = ( $Board->Config['com_sort'] == "desc" ) ? "desc" : "asc";
														
				$TreeCom = new tree_comments();
				$TreeCom->CreateDB( "", $Board->Config['com_sort'] );
														
				$com_on_page = intval( $Board->Config['com_max_on_page'] );
				if( $Board->Config['com_navigation_on'] == "yes" && $com_on_page > 0 )
					{
						$CatAltName = $Board->DB['category'][ $category ]['alt_name'];
						$LinkCat = $Board->ReturnLinkCategory( $category );
						if( $config['allow_alt_url'] == "yes" )
							$com_url = "{$LinkCat}{page},{$id}-{$alt_name}.html";
						else
							$com_url = "/index.php?do=board&amp;boardcat={$CatAltName}&amp;id={$id}&amp;com_page={page}";
																
						$TreeCom->URL = $com_url;
						$TreeCom->Navigation = true;
						$TreeCom->ComOnPage = $com_on_page;
						$TreeCom->Page = intval( $_REQUEST['com_page'] );
						if( $Board->Config['com_ajax_navigation'] == "yes" ) $TreeCom->Ajax = true;
					}
						else
					{
						$TreeCom->Navigation = false;
					}
														
				if( $Board->Config['com_allocation'] == "yes" ) $TreeCom->AllocationGroups = true;
				if( $Board->Config['com_alternation'] == "yes" ) $TreeCom->Alternation = true;
				if( $allow_add_com ) $TreeCom->AllowAdd = true;
														
				$allow_group_com_moder = explode( ",", $Board->Config['com_groups_moder'] );
				if( in_array( $member_id['user_group'], $allow_group_com_moder ) ) $TreeCom->AllowEdit = true;
				$TreeCom->ComDIR = "board/{$Folder}/comments";
				$TreeCom->Page = intval( $_REQUEST['com_page'] );
				$TreeCom->start();
														
				$TreeCom->BuildNavigation();
				$tpl->result['board_comments'] = "<div id=\"BoardCommentsList\">{$tpl->result['board_comments']}</div>{$tpl->result['nav_comments']}";
														
				$TreeCom->apocalypse();
			}
	}
		else
	{
		$not_comments = true;	
	}
						
?>