<?php
session_start();

(!defined('IN_PowerBB')) ? die() : '';
include('common.php');
define('CLASS_NAME','PowerBBReplyAddMOD');
class PowerBBReplyAddMOD
{
	var $SectionInfo;
	var $SectionGroup;
	var $SubjectInfo;

	function run()
	{
		global $PowerBB;
		$this->_CommonCode();

		if ($PowerBB->_GET['index'])
		{
			$this->_Index();
		}
		elseif ($PowerBB->_GET['start'])
		{
			$this->_Start();
		}
		else
		{
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['path_not_true']);
		}

		if (!isset($PowerBB->_POST['ajax']))
		{
			$PowerBB->functions->GetFooter();
		}
	}

	function _CommonCode()
	{
		global $PowerBB;

		$PowerBB->functions->CleanVariable($_GET['id'],'intval');

		if (empty($PowerBB->_GET['id']))
		{
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['path_not_true']);
		}

		$SubjectArr 			= 	array();
		$SubjectArr['where'] 	= 	array('id',$PowerBB->_GET['id']);

		$this->SubjectInfo = $PowerBB->subject->GetSubjectInfo($SubjectArr);

 		  $this->SubjectInfo['title'] 				= 	$PowerBB->functions->CleanVariable($this->SubjectInfo['title'],'html');
          $this->SubjectInfo['title'] = str_ireplace("'",'"', $this->SubjectInfo['title']);

		// Kill XSS
		$PowerBB->functions->CleanVariable($this->SubjectInfo,'html');
		// Kill SQL Injection
		$PowerBB->functions->CleanVariable($this->SubjectInfo,'sql');

		$SecArr 			= 	array();
		$SecArr['where'] 	= 	array('id',$this->SubjectInfo['section']);

		$this->SectionInfo = $PowerBB->section->GetSectionInfo($SecArr);

		// Kill XSS
		$PowerBB->functions->CleanVariable($this->SectionInfo,'html');
		// Kill SQL Injection
		$PowerBB->functions->CleanVariable($this->SectionInfo,'sql');

		if (!$this->SubjectInfo)
		{
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['Requested_topic_does_not_exist']);
		}

		$Admin = $PowerBB->functions->ModeratorCheck($PowerBB->_GET['id']);

		$PowerBB->template->assign('Admin',$Admin);

		$Mod = false;

		if ($PowerBB->_CONF['member_permission'])
		{
			if ($PowerBB->_CONF['group_info']['admincp_allow']
				or $PowerBB->_CONF['group_info']['vice'])
			{
				$Mod = true;
			}
			else
			{
				if (isset($this->SectionInfo))
				{
					$ModArr 				= 	array();
					$ModArr['username'] 	= 	$PowerBB->_CONF['member_row']['username'];
					$ModArr['section_id']	=	$this->SectionInfo['id'];

					$Mod = $PowerBB->moderator->IsModerator($ModArr);
				}
			}
		}

		if (!$Mod)
		{
			if ($this->SubjectInfo['close'])
			{
				$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['This_topic_is_locked']);
			}
		}

		/** Get section's group information and make some checks **/
		$SecGroupArr 						= 	array();
		$SecGroupArr['where'] 				= 	array();

		$SecGroupArr['where'][0]			=	array();
		$SecGroupArr['where'][0]['name'] 	= 	'section_id';
		$SecGroupArr['where'][0]['oper']	=	'=';
		$SecGroupArr['where'][0]['value'] 	= 	$this->SectionInfo['id'];

		$SecGroupArr['where'][1]			=	array();
		$SecGroupArr['where'][1]['con']		=	'AND';
		$SecGroupArr['where'][1]['name']	=	'group_id';
		$SecGroupArr['where'][1]['oper']	=	'=';
		$SecGroupArr['where'][1]['value']	=	$PowerBB->_CONF['group_info']['id'];

		// Finally get the permissions of group
		$this->SectionGroup = $PowerBB->group->GetSectionGroupInfo($SecGroupArr);

     	$PowerBB->template->assign('upload_attach',$this->SectionGroup['upload_attach']);


		// The visitor can't show this section , so stop the page
		if (!$this->SectionGroup['view_section']
			or !$this->SectionGroup['write_reply'])
		{
			$PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['Mistake']);
          if (!$PowerBB->_CONF['member_permission'])
              {
              $PowerBB->template->display('login');
              $PowerBB->functions->error_stop();
			}
	        else
	        {
	        $PowerBB->functions->error($PowerBB->_CONF['template']['lang']['Sorry_you_can_not_write_in_this_section']);
	        }
	     }

		if ($PowerBB->_CONF['group_info']['view_subject'] == 0)
		{
          if (!$PowerBB->_CONF['member_permission'])
              {
              $PowerBB->template->display('login');
              $PowerBB->functions->error_stop();
			}
	        else
	        {
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['Sorry_you_can_not_write_in_this_section']);
	        }
		}
        /*
		if (!empty($this->SectionInfo['section_password'])
			and !$PowerBB->_CONF['group_info']['admincp_allow'])
		{
			// The visitor don't give me password , so require it
     		if (empty($PowerBB->_GET['password']))
        	{
      			$PowerBB->template->display('forum_password');
      			$PowerBB->functions->stop();
     		}
     		// The visitor give me password , so check
     		elseif (!empty($PowerBB->_GET['password']))
     		{
     			$PassArr = array();

     			// Section id
     			$PassArr['id'] = $this->SectionInfo['id'];

     			// The password to check
     			$PassArr['password'] = base64_decode($PowerBB->_GET['password']);

     			$IsTruePassword = $PowerBB->section->CheckPassword($PassArr);

     			// Stop ! it's don't true password
     			if (!$IsTruePassword)
     			{
     				$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['PasswordIsnotTrue']);
     			}

     		}
     	}
        */
     	$PowerBB->_CONF['template']['password'] = '&amp;password=' . base64_encode($this->SectionInfo['section_password']);

		//////////

		 $PowerBB->_GET['id'] = $PowerBB->functions->CleanVariable($PowerBB->_GET['id'],'intval');

		// Where is the member now?
		if ($PowerBB->_CONF['member_permission'])
     	{
     		$UpdateOnline 			= 	array();
			$UpdateOnline['field']	=	array();
			$UpdateOnline['field']['user_location'] 	= 	$PowerBB->_CONF['template']['lang']['Written_in_reply_to'].' <a href="index.php?page=topic&amp;show=1&amp;id=' . $PowerBB->_GET['id'] . '">' . $this->SubjectInfo['title'] . '</a>';

			$UpdateOnline['where']						=	array('username',$PowerBB->_CONF['member_row']['username']);

			$update = $PowerBB->online->UpdateOnline($UpdateOnline);
     	}

     	//////////
     	$PowerBB->template->assign('section_info',$this->SectionInfo);
     	 $PowerBB->template->assign('subject_info',$this->SubjectInfo);

         $PowerBB->template->assign('count',$PowerBB->_GET['count']);


	}

	function _preview()
	{
		global $PowerBB;

		$PowerBB->functions->GetEditorTools();

		$PowerBB->template->assign('id',$PowerBB->_GET['id']);

          if (!empty($PowerBB->_GET['qu_Subject']))
          {
          	 $SubjectArr = array();
		     $SubjectArr['where'] = array('id',$PowerBB->_GET['qu_Subject']);

		     $PowerBB->_CONF['template']['QuoteSubjectInfo'] = $PowerBB->subject->GetSubjectInfo($SubjectArr);

             $quote = '[quote=' . $PowerBB->_GET['user'] . ']' . $PowerBB->_CONF['template']['QuoteSubjectInfo']['text'] . '[/quote]';
             $quote = htmlspecialchars($quote);
             $PowerBB->template->assign('quote',$quote);
         }


		 if (!empty($PowerBB->_GET['qu_Reply']))
         {
          	 $ReplyArr = array();
		     $ReplyArr['where'] = array('id',$PowerBB->_GET['qu_Reply']);

		     $PowerBB->_CONF['template']['QuoteReplyInfo'] = $PowerBB->reply->GetReplyInfo($ReplyArr);

             $quote = '[quote=' . $PowerBB->_GET['user'] . ']' . $PowerBB->_CONF['template']['QuoteReplyInfo']['text'] . '[/quote]';
             $PowerBB->template->assign('quote',$quote);
         }


         // View subject in template new_reply
         if (!empty($PowerBB->_GET['id']))
         {

            $SubjectArr = $PowerBB->DB->sql_query("SELECT  *   FROM " . $PowerBB->table['subject'] . " WHERE id = " . $PowerBB->_GET['id'] . "  ");
            $GeSubjectInfo = array();
            while ($GeSubjectInfo = $PowerBB->DB->sql_fetch_array($SubjectArr))
            {
            $GeSubjectInfo['text'] = str_ireplace('&quot;','"',$GeSubjectInfo['text']);
            $GeSubjectInfo['text'] = str_ireplace('{39}',"'",$GeSubjectInfo['text']);
            $GeSubjectInfo['text'] = str_ireplace('cookie','**',$GeSubjectInfo['text']);
            $GeSubjectInfo['text'] = $PowerBB->Powerparse->replace($GeSubjectInfo['text']);
            $PowerBB->Powerparse->replace_smiles($GeSubjectInfo['text']);
            $PowerBB->Powerparse->replace_wordwrap($GeSubjectInfo['text']);
            $PowerBB->template->assign('GeSubjectInfo',$GeSubjectInfo);
           }

         }


          //////////

        $ExArr 						= 	array();
		$ExArr['order']				=	array();
		$ExArr['order']['field']	=	'id';
		$ExArr['order']['type']		=	'DESC';
		$ExArr['proc'] 				= 	array();
		$ExArr['proc']['*'] 		= 	array('method'=>'clean','param'=>'html');

		$PowerBB->_CONF['template']['while']['ExList'] = $PowerBB->extension->GetExtensionList($ExArr);

        ///////////////////
         $PowerBB->template->assign('section_id',$this->SectionInfo['id']);
        // show Custom_bbcode List
		$Custom_bbcodeArr 					= 	array();
		$Custom_bbcodeArr['order']			=	array();
		$Custom_bbcodeArr['order']['field']	=	'id';
		$Custom_bbcodeArr['order']['type']	=	'DESC';
		$Custom_bbcodeArr['proc'] 			= 	array();
		$Custom_bbcodeArr['proc']['*'] 		= 	array('method'=>'clean','param'=>'html');

		$PowerBB->_CONF['template']['while']['Custom_bbcodesList'] = $PowerBB->custom_bbcode->GetCustom_bbcodeList($Custom_bbcodeArr);


	      $PowerBB->template->display('new_reply');


          //////////

        // View 10 replys Inverse in template new_reply
         if (!empty($PowerBB->_GET['id']))
         {
         $ReplyArr = $PowerBB->DB->sql_query("SELECT  *   FROM " . $PowerBB->table['reply'] . " WHERE subject_id = " . $PowerBB->_GET['id'] . " ORDER by ID DESC limit 10 ");
         $GeReplyInfo = array();
         while ($GeReplyInfo = $PowerBB->DB->sql_fetch_array($ReplyArr))
         {

            $GeReplyInfo['text'] = str_ireplace('&quot;','"',$GeReplyInfo['text']);
            $GeReplyInfo['text'] = str_ireplace('{39}',"'",$GeReplyInfo['text']);
            $GeReplyInfo['text'] = str_ireplace('cookie','**',$GeReplyInfo['text']);
            $GeReplyInfo['text'] = $PowerBB->Powerparse->replace($GeReplyInfo['text']);
            $PowerBB->Powerparse->replace_smiles($GeReplyInfo['text']);
            $PowerBB->Powerparse->replace_wordwrap($GeReplyInfo['text']);
            $PowerBB->template->assign('GeReplyInfo',$GeReplyInfo);
            $PowerBB->template->display('view_reply');
         }
        }

	}


	function _Index()
	{
		global $PowerBB;


		$PowerBB->functions->GetEditorTools();

		$PowerBB->template->assign('id',$PowerBB->_GET['id']);

          if (!empty($PowerBB->_GET['qu_Subject']))
          {
          	 $SubjectArr = array();
		     $SubjectArr['where'] = array('id',$PowerBB->_GET['qu_Subject']);

		     $PowerBB->_CONF['template']['QuoteSubjectInfo'] = $PowerBB->subject->GetSubjectInfo($SubjectArr);

             $quote = '[quote=' . $PowerBB->_GET['user'] . ']' . $PowerBB->_CONF['template']['QuoteSubjectInfo']['text'] . '[/quote]';
             $quote = htmlspecialchars($quote);
             $PowerBB->template->assign('quote',$quote);
         }


		 //-----------------------------------------
		// Reset multi-quote cookie
		//-----------------------------------------

		if ( ! $mqtids )
		{
            $mqtids = $PowerBB->_COOKIE[$PowerBB->_CONF['mqtids']];


          if ($mqtids!='')
          {

          	if ($mqtids == ",")
			{
				$mqtids = "";
			}
           else
			{
				$PowerBB->template->assign('mqtids', $mqtids);

            }
           }
       }

		 if (!empty($PowerBB->_GET['qu_Reply']))
         {
          	 $ReplyArr = array();
		     $ReplyArr['where'] = array('id',$PowerBB->_GET['qu_Reply']);

		     $PowerBB->_CONF['template']['QuoteReplyInfo'] = $PowerBB->reply->GetReplyInfo($ReplyArr);

             $quote = '[quote=' . $PowerBB->_GET['user'] . ']' . $PowerBB->_CONF['template']['QuoteReplyInfo']['text'] . '[/quote]';
             $PowerBB->template->assign('quote',$quote);
         }



    	$PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['add_new_reply']);


         // View subject in template new_reply
         if (!empty($PowerBB->_GET['id']))
         {

            $SubjectArr = $PowerBB->DB->sql_query("SELECT  *   FROM " . $PowerBB->table['subject'] . " WHERE id = " . $PowerBB->_GET['id'] . "  ");
            $GeSubjectInfo = array();
            while ($GeSubjectInfo = $PowerBB->DB->sql_fetch_array($SubjectArr))
            {
            $GeSubjectInfo['text'] = str_ireplace('&quot;','',$GeSubjectInfo['text']);
            $GeSubjectInfo['text'] = str_ireplace('{39}',"'",$GeSubjectInfo['text']);
            $GeSubjectInfo['text'] = str_ireplace('cookie','**',$GeSubjectInfo['text']);
            $GeSubjectInfo['text'] = $PowerBB->Powerparse->replace($GeSubjectInfo['text']);
            $PowerBB->Powerparse->replace_smiles($GeSubjectInfo['text']);
            $PowerBB->Powerparse->replace_wordwrap($GeSubjectInfo['text']);
            $PowerBB->template->assign('GeSubjectInfo',$GeSubjectInfo);
           }

         }


          //////////

        $ExArr 						= 	array();
		$ExArr['order']				=	array();
		$ExArr['order']['field']	=	'id';
		$ExArr['order']['type']		=	'DESC';
		$ExArr['proc'] 				= 	array();
		$ExArr['proc']['*'] 		= 	array('method'=>'clean','param'=>'html');

		$PowerBB->_CONF['template']['while']['ExList'] = $PowerBB->extension->GetExtensionList($ExArr);

        ///////////////////
         $PowerBB->template->assign('section_id',$this->SectionInfo['id']);

        $checked 			= 	'no_icon';
	    $PowerBB->template->assign('checked',$checked);

        // show Custom_bbcode List
		$Custom_bbcodeArr 					= 	array();
		$Custom_bbcodeArr['order']			=	array();
		$Custom_bbcodeArr['order']['field']	=	'id';
		$Custom_bbcodeArr['order']['type']	=	'DESC';
		$Custom_bbcodeArr['proc'] 			= 	array();
		$Custom_bbcodeArr['proc']['*'] 		= 	array('method'=>'clean','param'=>'html');

		$PowerBB->_CONF['template']['while']['Custom_bbcodesList'] = $PowerBB->custom_bbcode->GetCustom_bbcodeList($Custom_bbcodeArr);


	      $PowerBB->template->display('new_reply');


          //////////

        // View 10 replys Inverse in template new_reply
         if (!empty($PowerBB->_GET['id']))
         {
         $ReplyArr = $PowerBB->DB->sql_query("SELECT  *   FROM " . $PowerBB->table['reply'] . " WHERE subject_id = " . $PowerBB->_GET['id'] . " ORDER by ID DESC limit 10 ");
         $GeReplyInfo = array();
         while ($GeReplyInfo = $PowerBB->DB->sql_fetch_array($ReplyArr))
         {

            $GeReplyInfo['text'] = $PowerBB->Powerparse->replace($GeReplyInfo['text']);
            $GeReplyInfo['text'] = str_replace('\"','"',$GeReplyInfo['text']);
            $PowerBB->Powerparse->replace_smiles($GeReplyInfo['text']);
            $PowerBB->Powerparse->replace_wordwrap($GeReplyInfo['text']);
            $GeReplyInfo['text'] = $PowerBB->Powerparse->censor_words($GeReplyInfo['text']);
            $PowerBB->template->assign('GeReplyInfo',$GeReplyInfo);

                 $PowerBB->template->display('view_reply');
         }
        }

	}

	function _Start()
	{
		global $PowerBB;
		setcookie('mqtids','',time()-360000);

		$PowerBB->_POST['title'] = $PowerBB->functions->CleanVariable($PowerBB->_POST['title'],'trim');
		$PowerBB->_POST['text'] = $PowerBB->functions->CleanVariable($PowerBB->_POST['text'],'trim');
      if ($PowerBB->_POST['preview'])
       {
    	$PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['add_new_reply']);
            $previewtext = $PowerBB->_POST['text'];
            $previewtext = $PowerBB->Powerparse->replace($previewtext);

            $PowerBB->Powerparse->replace_smiles($previewtext);

	        $PowerBB->template->assign('prev',stripslashes($PowerBB->_POST['text']));
	       	$PowerBB->template->assign('preview',stripslashes($previewtext));
	       	$PowerBB->template->assign('view_preview',stripslashes($PowerBB->_POST['text']));

           $this->_preview();

        }
      else
       {
			 if (!isset($PowerBB->_POST['ajax']))
			 {

		            if ((time() - $PowerBB->_CONF['info_row']['floodctrl']) <= $PowerBB->_CONF['member_row']['lastpost_time'] AND !$PowerBB->_CONF['group_info']['admincp_allow'])
		            {
			               $PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['execution_add_reply']);
						if (!$PowerBB->functions->ModeratorCheck($this->SectionInfo['id']))
						{
						$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['floodctrl']);
						}
		            }
		     		else
		     		{

		              	if (empty($PowerBB->_POST['text']))
						{
		     				   $PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['Mistake']);
		                       $PowerBB->functions->error($PowerBB->_CONF['template']['lang']['post_text_min']);
						}


                    if (!$PowerBB->_CONF['group_info']['admincp_allow'])
                     {
                     	$TextPost = utf8_decode($PowerBB->_POST['text']);
         			    $TextPost = preg_replace('#\[IMG\](.*)\[/IMG\]#siUe', '', $TextPost);

			     		if (isset($TextPost{$PowerBB->_CONF['info_row']['post_text_max']}))
			     		{
		     			     	  $PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['Mistake']);
		                    	  $PowerBB->functions->error($PowerBB->_CONF['template']['lang']['post_text_max']);
				     	 }

			     		 if (!isset($TextPost{$PowerBB->_CONF['info_row']['post_text_min']}))
			     		{
		                 $PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['Mistake']);
		                       $PowerBB->functions->error($PowerBB->_CONF['template']['lang']['post_text_min']);
			     		}
                     }
				     	if (!$PowerBB->_CONF['member_permission'])
			            {
				     		if(md5($PowerBB->_POST['code']) != $_SESSION['key'])
					        {
			     			  $PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['Mistake']);
			                $PowerBB->functions->error($PowerBB->_CONF['template']['lang']['Code_that_you_enter_the_wrong'],$stop,$stop);
				            }
			            }


						if (!$PowerBB->_CONF['member_permission'])
						{
							if (empty($PowerBB->_POST['guest_name']))
							{
			     				   $PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['Mistake']);
			                       $PowerBB->functions->error($PowerBB->_CONF['template']['lang']['You_do_not_type_your_name']);
							}
		                }


		     		if ((!$PowerBB->_CONF['member_row']['review_reply'] and ! $PowerBB->_CONF['group_info']['review_reply'])
		     			or $PowerBB->_CONF['group_info']['admincp_allow'])
					{
					$PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['execution_add_reply']);
						$PowerBB->functions->AddressBar('<a href="index.php?page=forum&amp;show=1&amp;id=' . $this->SectionInfo['id'] . $PowerBB->_CONF['template']['password'] . '">' . $this->SectionInfo['title'] . '</a>' . $PowerBB->_CONF['info_row']['adress_bar_separate'] . '<a href="index.php?page=topic&amp;show=1&amp;id=' . $this->SubjectInfo['id'] . $PowerBB->_CONF['template']['password'] . '">' . ($PowerBB->functions->CleanVariable($this->SubjectInfo['title'],'sql')) . '</a>' . $PowerBB->_CONF['info_row']['adress_bar_separate'] . $PowerBB->_CONF['template']['lang']['execution_add_reply']);
						$PowerBB->functions->msg($PowerBB->_CONF['template']['lang']['reply_Add_successfully1'] .'   "' . $PowerBB->_POST['title'] . '"  ' .$PowerBB->_CONF['template']['lang']['reply_Add_successfully2']);
		     		}
		     		else
		     		{
                        $PowerBB->functions->ShowHeader($PowerBB->_CONF['template']['lang']['execution_add_reply']);
						$PowerBB->functions->AddressBar('<a href="index.php?page=forum&amp;show=1&amp;id=' . $this->SectionInfo['id'] . $PowerBB->_CONF['template']['password'] . '">' . $this->SectionInfo['title'] . '</a>' . $PowerBB->_CONF['info_row']['adress_bar_separate'] . '<a href="index.php?page=topic&amp;show=1&amp;id=' . $this->SubjectInfo['id'] . $PowerBB->_CONF['template']['password'] . '">' . ($PowerBB->functions->CleanVariable($this->SubjectInfo['title'],'sql')) . '</a>' . $PowerBB->_CONF['info_row']['adress_bar_separate'] . $PowerBB->_CONF['template']['lang']['execution_add_reply']);
		     			$PowerBB->functions->msg($PowerBB->_CONF['template']['lang']['Waiting_approved_by_management']);
		     		}

		     	   }

		     }
		     else
		     {

		            if ((time() - $PowerBB->_CONF['info_row']['floodctrl']) <= $PowerBB->_CONF['member_row']['lastpost_time'])
		            {
						if (!$PowerBB->functions->ModeratorCheck($this->SectionInfo['id']))
						{
						  $PowerBB->functions->error_no_foot($PowerBB->_CONF['template']['lang']['floodctrl']);
						}
		            }

			 }


				if (empty($PowerBB->_POST['text']))
				{
					$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['Please_fill_in_all_the_information']);
				}


				if ($PowerBB->_POST['stick'])
				{
					$UpdateArr = array();
					$UpdateArr['where'] = array('id',$this->SubjectInfo['id']);

					$update = $PowerBB->subject->StickSubject($UpdateArr);
				}

				if ($PowerBB->_POST['close'])
				{
					$UpdateArr = array();
					$UpdateArr['reason'] = $PowerBB->_POST['reason'];
					$UpdateArr['where'] = array('id',$this->SubjectInfo['id']);

					$update = $PowerBB->subject->CloseSubject($UpdateArr);
				}
                if ($PowerBB->_POST['unstick'])
                {
                   $UpdateArr = array();
                   $UpdateArr['where'] = array('id',$this->SubjectInfo['id']);
                   $update = $PowerBB->subject->UnstickSubject($UpdateArr);
                }

                if ($PowerBB->_POST['unclose'])
                {
                    $UpdateArr = array();
                    $UpdateArr['reason'] = $PowerBB->_POST['reason'];
                    $UpdateArr['where'] = array('id',$this->SubjectInfo['id']);
                    $update = $PowerBB->subject->OpenSubject($UpdateArr);
                }

                   // Filter Words
                   $PowerBB->_POST['text'] = str_replace('target="_blank" ','',$PowerBB->_POST['text']);
		$PowerBB->_POST['title'] 	= 	$PowerBB->functions->CleanVariable($PowerBB->_POST['title'],'sql');
        $PowerBB->_POST['text'] 	= 	$PowerBB->functions->CleanVariable($PowerBB->_POST['text'],'sql');
                //

		     	$ReplyArr 			                = 	array();
		     	$ReplyArr['get_id']					=	true;
		     	$ReplyArr['field']               	= 	array();
		     	$ReplyArr['field']['title'] 		= 	$PowerBB->_POST['title'];
		     	if (!$PowerBB->_CONF['member_permission'])
				{
		     	$ReplyArr['field']['text'] 			= 	$PowerBB->functions->CleanVariable($PowerBB->_POST['text'].'[color=#4000BF][i][guest_name]'.$PowerBB->_CONF['template']['lang']['LastsPostsWriter'].$PowerBB->_POST['guest_name'].'[/guest_name][/i][/color]','html');
				$ReplyArr['field']['writer'] 				= 	'Guest';
				}
		     	else
		     	{
		     	$ReplyArr['field']['text'] 			= 	$PowerBB->functions->CleanVariable($PowerBB->_POST['text'],'html');
				$ReplyArr['field']['writer']				= 	$PowerBB->_CONF['rows']['member_row']['username'];
				}
		     	$ReplyArr['field']['subject_id'] 	= 	$this->SubjectInfo['id'];
		     	$ReplyArr['field']['write_time'] 	= 	$PowerBB->_CONF['now'];
		     	$ReplyArr['field']['section'] 		= 	$this->SubjectInfo['section'];
		     	$ReplyArr['field']['icon'] 			= 	$PowerBB->_POST['icon'];
		     	if (($PowerBB->_CONF['member_row']['review_reply'] or $PowerBB->_CONF['group_info']['review_reply'])
					and !$PowerBB->_CONF['group_info']['admincp_allow'])
				{
					$ReplyArr['field']['review_reply'] = 1;
				}


		     	$Insert = $PowerBB->reply->InsertReply($ReplyArr);

		     	if ($Insert)
		     	{
		     		//////////

		     		if ($this->SectionGroup['no_posts'])
		     		{
		     			$posts = $PowerBB->_CONF['member_row']['posts'] + 1;
		     		}
		     		else
		     		{
		     			$posts = $PowerBB->_CONF['member_row']['posts'];
		     		}

		     		if ($PowerBB->_CONF['group_info']['usertitle_change'])
		     		{
		     			$UsertitleArr 			= 	array();
		     			$UsertitleArr['where'] 	= 	array('posts',$posts);

		     			$UserTitle = $PowerBB->usertitle->GetUsertitleInfo($UsertitleArr);

		     			if ($UserTitle != false)
		     			{
		     				$usertitle = $UserTitle['usertitle'];
		     			}
		     			else
			     		{
							$GrpArr 			= 	array();
							$GrpArr['where'] 	= 	array('id',$PowerBB->_CONF['rows']['member_row']['usergroup']);

							$GroupStyleInfo = $PowerBB->group->GetGroupInfo($GrpArr);

			     			$usertitle = $GroupStyleInfo['user_title'];
			     		}
		     		}

		     		//////////
              		$Subjectid = $PowerBB->_GET['id'];
                    $PagerReplyNumArr = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT * FROM " . $PowerBB->table['reply'] . " WHERE subject_id='$Subjectid' and delete_topic <>1"));

			   		$MemberArr 				= 	array();
			   		$MemberArr['field'] 	= 	array();

		     		$MemberArr['field']['posts']			=	$posts;
		     		$MemberArr['field']['lastpost_time'] 	=	$PowerBB->_CONF['now'];
		     		$MemberArr['field']['user_title']		=	(isset($usertitle)) ? $usertitle : null;
		     		$MemberArr['where']						=	array('id',$PowerBB->_CONF['member_row']['id']);

		   			$UpdateMember = $PowerBB->member->UpdateMember($MemberArr);

		     		$TimeArr = array();

		     		$TimeArr['write_time'] 	= 	$PowerBB->_CONF['now'];
		     		$TimeArr['where']		=	array('id',$this->SubjectInfo['id']);

		     		$UpdateWriteTime = $PowerBB->subject->UpdateWriteTime($TimeArr);

		     		$RepArr 					= 	array();
		     		$RepArr['reply_number']		=	$PagerReplyNumArr;
		     		$RepArr['where'] 			= 	array('id',$this->SubjectInfo['id']);

		     		$UpdateReplyNumber = $PowerBB->subject->UpdateReplyNumber($RepArr);


  	                if (($PowerBB->_CONF['member_row']['review_reply'] and ! $PowerBB->_CONF['group_info']['review_reply'])
						and !$PowerBB->_CONF['group_info']['admincp_allow'])
					{

						$SubjectArr = array();
						$SubjectArr['where'] 				= 	array();
						$SubjectArr['where'] 			= 	array('id',$this->SubjectInfo['id']);
						$SubjectInfo = $PowerBB->subject->GetSubjectInfo($SubjectArr);

	                    $ReviewReply 					= 	array();
			     		$ReviewReply['review_reply']	=	 $SubjectInfo['review_reply'] +1;
			     		$ReviewReply['where'] 			= 	array('id',$this->SubjectInfo['id']);

			     		$UpdateReviewReply = $PowerBB->subject->UpdateReviewReply($ReviewReply);
                    }



                   $UpdateSubjectNumber = $PowerBB->cache->UpdateReplyNumber(array('reply_num'	=>	$PowerBB->_CONF['info_row']['reply_number']));

		     		//////////
		     		if (!$PowerBB->_CONF['member_permission'])
					{
	                $writer = 	$PowerBB->_CONF['template']['lang']['Guestp'];
					}
			     	else
			     	{
		            $writer = 	$PowerBB->_CONF['member_row']['username'];
					}
		     	if (($PowerBB->_CONF['member_row']['review_reply'] or $PowerBB->_CONF['group_info']['review_reply'])
					and !$PowerBB->_CONF['group_info']['admincp_allow'])
				{
					$review_reply = 1;
				}

		     		// The number of section's subjects number
		     		$UpdateArr 					= 	array();
		     		$UpdateArr['field']			=	array();

		     		$UpdateArr['field']['reply_num'] 	= 	$this->SectionInfo['reply_num'] + 1;
                   if(!$this->SubjectInfo['review_subject']){
					$UpdateArr['field']['last_writer'] 		= 	$writer;
		     		$UpdateArr['field']['last_subject'] 		= 	$PowerBB->_POST['title'];
		     		$UpdateArr['field']['last_subjectid'] 	= 	$this->SubjectInfo['id'];
		     		$UpdateArr['field']['last_date'] 	= 	$PowerBB->_CONF['now'];
		     		$UpdateArr['field']['last_time'] 	= 	$PowerBB->_CONF['now'];
		     		$UpdateArr['field']['last_reply'] 	= 	$PowerBB->reply->id;
		     		$UpdateArr['field']['icon'] 	    = 	$this->SubjectInfo['icon'];
		     		$UpdateArr['field']['last_berpage_nm']  = 	$PowerBB->_POST['count'];
		     		}
		     		$UpdateArr['field']['review_subject'] 		= 	$review_reply;

		     		$UpdateArr['where']					= 	array('id',$this->SectionInfo['id']);

		     		$UpdateSubjectNumber = $PowerBB->section->UpdateSection($UpdateArr);

		     		// Free memory
		     		unset($UpdateArr);

		     		//////////

		     		// Update section's cache
		     		$UpdateArr 				= 	array();
		     		$UpdateArr['parent'] 	= 	$this->SectionInfo['parent'];

		     		$update_cache = $PowerBB->section->UpdateSectionsCache($UpdateArr);

		     		unset($UpdateArr);

		     		//////////

		     		//////////

                    $get_section_parent = $PowerBB->DB->sql_query("SELECT  *   FROM " . $PowerBB->table['section'] . " WHERE parent = " . $this->SectionInfo['parent'] . " ");
	                $Inf_row = $PowerBB->DB->sql_fetch_array($get_section_parent);
                        if ($Inf_row)
						{

	                           //////////
				     		if (!$PowerBB->_CONF['member_permission'])
							{
			                $writer = 	$PowerBB->_CONF['template']['lang']['Guestp'];
							}
					     	else
					     	{
				            $writer = 	$PowerBB->_CONF['member_row']['username'];
							}

				     		$UpdateLastprantArr = array();
				     		$UpdateLastprantArr['field']			=	array();
							$UpdateLastprantArr['field']['last_writer'] 		= 	$writer;
				     		$UpdateLastprantArr['field']['last_subject'] 		= 	$PowerBB->_POST['title'];
				     		$UpdateLastprantArr['field']['last_subjectid'] 	= 	$this->SubjectInfo['id'];
				     		$UpdateLastprantArr['field']['last_date'] 	= 	$PowerBB->_CONF['now'];
				     		$UpdateLastprantArr['field']['last_time'] 	= 	$PowerBB->_CONF['now'];
		     	         	$UpdateLastprantArr['field']['icon'] 	    = 	$this->SubjectInfo['icon'];
		     		        $UpdateLastprantArr['field']['last_reply'] 	= 	$PowerBB->reply->id;
		     		        $UpdateLastprantArr['field']['last_berpage_nm']  = 	$PowerBB->_POST['count'];

				     		$UpdateLastprantArr['where'] 		        = 	array('id',$Inf_row['parent']);

				     		// Update Last subject's information
				     		$UpdateprantLast = $PowerBB->section->UpdateSection($UpdateLastprantArr);
							unset($UpdateLastprantArr);


				     	}

                     $get_sections_parent = $PowerBB->DB->sql_query("SELECT  *   FROM " . $PowerBB->table['section'] . " WHERE parent = " . $this->SectionInfo['parent'] . " ");
	                $Inf_rows = $PowerBB->DB->sql_fetch_array($get_section_parent);
                        if ($Inf_rows)
						{

	                           //////////
				     		if (!$PowerBB->_CONF['member_permission'])
							{
			                $writer = 	$PowerBB->_CONF['template']['lang']['Guestp'];
							}
					     	else
					     	{
				            $writer = 	$PowerBB->_CONF['member_row']['username'];
							}

				     		$UpdateLastprantArr = array();
				     		$UpdateLastprantArr['field']			=	array();
							$UpdateLastprantArr['field']['last_writer'] 		= 	$writer;
				     		$UpdateLastprantArr['field']['last_subject'] 		= 	$PowerBB->_POST['title'];
				     		$UpdateLastprantArr['field']['last_subjectid'] 	= 	$this->SubjectInfo['id'];
				     		$UpdateLastprantArr['field']['last_date'] 	= 	$PowerBB->_CONF['now'];
				     		$UpdateLastprantArr['field']['last_time'] 	= 	$PowerBB->_CONF['now'];
		     		        $UpdateLastprantArr['field']['last_reply'] 	= 	$PowerBB->reply->id;
		     		        $UpdateLastprantArr['field']['last_berpage_nm']  = 	$PowerBB->_POST['count'];
		     	         	$UpdateLastprantArr['field']['icon'] 	    = 	$this->SubjectInfo['icon'];
				     		$UpdateLastprantArr['where'] 		        = 	array('parent',$Inf_rows['id']);

				     		// Update Last subject's information
				     		$UpdateprantLast = $PowerBB->section->UpdateSection($UpdateLastprantArr);
							unset($UpdateLastprantArr);

					     		// Update section's cache
					     		$UpdateArr 				= 	array();
					     		$UpdateArr['parent'] 	= 	$Inf_rows['parent'];

					     		$update_cache = $PowerBB->section->UpdateSectionsCache($UpdateArr);

					     		unset($UpdateArr);

				     		if ($UpdateprantLast)
							{

		                           //////////
					     		if (!$PowerBB->_CONF['member_permission'])
								{
				                $writer = 	$PowerBB->_CONF['template']['lang']['Guestp'];
								}
						     	else
						     	{
					            $writer = 	$PowerBB->_CONF['member_row']['username'];
								}

					     		$UpdateLastprantArr = array();
					     		$UpdateLastprantArr['field']			=	array();
								$UpdateLastprantArr['field']['last_writer'] 		= 	$writer;
					     		$UpdateLastprantArr['field']['last_subject'] 		= 	$PowerBB->_POST['title'];
					     		$UpdateLastprantArr['field']['last_subjectid'] 	= 	$this->SubjectInfo['id'];
					     		$UpdateLastprantArr['field']['last_date'] 	= 	$PowerBB->_CONF['now'];
					     		$UpdateLastprantArr['field']['last_time'] 	= 	$PowerBB->_CONF['now'];
		     		            $UpdateLastprantArr['field']['last_reply'] 	= 	$PowerBB->reply->id;
		     		            $UpdateLastprantArr['field']['last_berpage_nm']  = 	$PowerBB->_POST['count'];
		     	         	    $UpdateLastprantArr['field']['icon'] 	    = 	$this->SubjectInfo['icon'];
					     		$UpdateLastprantArr['where'] 		        = 	array('id',$Inf_rows['parent']);

					     		// Update Last subject's information
					     		$UpdateprantLast = $PowerBB->section->UpdateSection($UpdateLastprantArr);
								unset($UpdateLastprantArr);

						     		// Update section's cache
						     		$UpdateArr 				= 	array();
						     		$UpdateArr['parent'] 	= 	$Inf_rows['parent'];

						     		$update_cache = $PowerBB->section->UpdateSectionsCache($UpdateArr);

						     		unset($UpdateArr);
						     }

				     	}

								// Update reply_num & subject_num
					   if ($this->SectionInfo['parent']<1)
						{
							$SectionCache = $this->SectionInfo['id'];

								$Section_Rnum = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT section FROM " . $PowerBB->table['reply'] . " WHERE section = " . $SectionCache . " AND delete_topic<>1 AND review_reply<>1"));
								$Section_Snum = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT section FROM " . $PowerBB->table['subject'] . " WHERE section = " . $SectionCache . " AND delete_topic<>1 AND review_subject<>1 "));


								$subject_num = $Section_Snum ;
								$reply_num   = $Section_Rnum;

								$UpdatesrFormSecArr = array();
								$UpdatesrFormSecArr['field']			=	array();

								$UpdatesrFormSecArr['field']['reply_num'] 	= 	$reply_num;
								$UpdatesrFormSecArr['field']['subject_num']  = 	$subject_num;

								$UpdatesrFormSecArr['where'] 		        = 	array('id',$SectionCache);

								// Update reply_num & subject_num
								$UpdaterSFormSec = $PowerBB->section->UpdateSection($UpdatesrFormSecArr);
                                 $UpdateSectionCache1 = $PowerBB->functions->UpdateSectionCache($SectionCache);
						}
						else
						{
						$SectionCache = $this->SectionInfo['parent'];


								$S_R = $PowerBB->DB->sql_query("SELECT * FROM " . $PowerBB->table['section'] . " WHERE parent = ".$SectionCache." ");
								while ($f_S_R = $PowerBB->DB->sql_fetch_array($S_R))
								{
								$Section_Rnum = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT section FROM " . $PowerBB->table['reply'] . " WHERE section = " . $SectionCache . " AND delete_topic<>1 AND review_reply<>1"));
								$Section_Snum = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT section FROM " . $PowerBB->table['subject'] . " WHERE section = " . $SectionCache . " AND delete_topic<>1 AND review_subject<>1 "));

								$Rnum = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT section FROM " . $PowerBB->table['reply'] . " WHERE section = " . $f_S_R['id'] . " AND delete_topic<>1 AND review_reply<>1"));
								$Snum = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT section FROM " . $PowerBB->table['subject'] . " WHERE section = " . $f_S_R['id'] . " AND delete_topic<>1 AND review_subject<>1 "));

								$subject_num = $Section_Snum + $Snum;
								$reply_num   = $Section_Rnum + $Rnum;

								$UpdatesrFormSecArr = array();
								$UpdatesrFormSecArr['field']			=	array();

								$UpdatesrFormSecArr['field']['reply_num'] 	= 	$reply_num;
								$UpdatesrFormSecArr['field']['subject_num']  = 	$subject_num;

								$UpdatesrFormSecArr['where'] 		        = 	array('id',$SectionCache);

								// Update reply_num & subject_num
								$UpdaterSFormSec = $PowerBB->section->UpdateSection($UpdatesrFormSecArr);
                                 $UpdateSectionCache1 = $PowerBB->functions->UpdateSectionCache($SectionCache);
				               }
						}

		     	     if ($PowerBB->_CONF['member_permission'])
				    {
		     		$LastArr = array();
		     		$LastArr['replier'] 	= 	$PowerBB->_CONF['member_row']['username'];
		     		$LastArr['where']		=	array('id',$this->SubjectInfo['id']);

		     		$UpdateLastReplier = $PowerBB->subject->UpdateLastReplier($LastArr);
		     		}

		     		//////////

		     		// Upload files

				   $GetAttachArr 					= 	array();
				   $GetAttachArr['where'] 			= 	array('reply','-'.$PowerBB->_CONF['member_row']['id']);
				   $Attachinfo = $PowerBB->attach->GetAttachInfo($GetAttachArr);

		     		if ($Attachinfo)
		     		{

					$ReplyArr 							= 	array();
					$ReplyArr['field'] 					= 	array();
					$ReplyArr['field']['attach_reply'] 	= 	'1';
					$ReplyArr['where'] 					= 	array('id',$PowerBB->reply->id);

					$update = $PowerBB->reply->UpdateReply($ReplyArr);

					//	Update All Attach
					 $member_id_Attach = '-'.$PowerBB->_CONF['member_row']['id'];
                     $getAttach = $PowerBB->DB->sql_query("SELECT  *   FROM " . $PowerBB->table['attach'] . " WHERE reply = '$member_id_Attach' ");
                     while ($getAttach_row = $PowerBB->DB->sql_fetch_array($getAttach))
                      {
						// Count a new download
						$UpdateArr 						= 	array();
						$UpdateArr['field'] 			= 	array();
                        $UpdateArr['field']['subject_id']	=	$PowerBB->reply->id;
						$UpdateArr['field']['reply'] 	= 	'1';
						$UpdateArr['where'] 			= 	array('id',$getAttach_row['id']);

                 		$update = $PowerBB->attach->UpdateAttach($UpdateArr);
                     }
		     		}

		     		//////////

					if ($PowerBB->_CONF['info_row']['allowed_emailed'] == '1')
					{

					$SectionInfoid = $this->SectionInfo['id'];
					$SubjectInfoid = $this->SubjectInfo['id'];
					$member_row_id = $PowerBB->_CONF['member_row']['id'];

					$subject_user_emailed_nm = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT * FROM " . $PowerBB->table['emailed'] . " WHERE subject_id='$SubjectInfoid' and user_id ='$member_row_id'"));


					if ($PowerBB->_POST['emailed'])
					{

					$EmailedArr 			= 	array();
					$EmailedArr['where'] 	= 	array('subject_id',$this->SubjectInfo['id']);

					$this->EmailedInfo = $PowerBB->emailed->GetEmailedInfo($EmailedArr);


					if ($subject_user_emailed_nm < 1)
					{
					$EmailedArr 								= 	array();
					$EmailedArr['get_id']						=	true;
					$EmailedArr['field']						=	array();
					$EmailedArr['field']['user_id'] 			= 	$PowerBB->_CONF['member_row']['id'];
					$EmailedArr['field']['subject_id'] 			= 	$this->SubjectInfo['id'];
					$EmailedArr['field']['subject_title'] 		= 	$PowerBB->_POST['title'];

					$Insert = $PowerBB->emailed->InsertEmailed($EmailedArr);
					}

					}
					//Send email notification to all participants in this department with a new reply
					$Adress_end	= 	'<a href="'.$PowerBB->functions->GetForumAdress().'index.php'.'">'.$PowerBB->functions->GetForumAdress().'index.php'.'</a>';
					$Adress = $PowerBB->functions->GetForumAdress();
					$topic_url	= 	'<a href="'.$PowerBB->functions->GetForumAdress().'index.php?page=topic&show=1&id=' . $SubjectInfoid . '">'.$PowerBB->functions->GetForumAdress().'index.php?page=topic&show=1&id=' . $SubjectInfoid . '</a>';
					$charset                =   $PowerBB->_CONF['info_row']['charset'];
					$PowerBB->_POST['message'] = $PowerBB->Powerparse->replace($PowerBB->_POST['message']);
					$starthtml = '<html dir=\"$charset\"><body>';
					$Endhtml = '</body></html>';
					$br = '<br>';
					$br = $PowerBB->Powerparse->replace($br);
					$title = $PowerBB->_CONF['template']['lang']['New_Reply'] ;
					$Form_Massege = $PowerBB->_CONF['member_row']['username'].$PowerBB->_CONF['template']['lang']['Has_written_new_Reply'] .
					$PowerBB->_POST['title'] . $br . $PowerBB->_CONF['template']['lang']['Please_login_on_the_following_link_to_access_the_subject'] . $topic_url .'<br>'. $PowerBB->_CONF['template']['lang']['greetings_Management_Forum']  . $PowerBB->_CONF['info_row']['title'] .'<br>' . $Adress_end . '';
					$Mem_not = $PowerBB->_CONF['member_row']['id'];

					$getmember_query = $PowerBB->DB->sql_query("SELECT Distinct user_id FROM " . $PowerBB->table['emailed'] . " WHERE user_id NOT IN ('$Mem_not') AND subject_id = '$SubjectInfoid'");

					if ($PowerBB->emailed->IsEmailed(array('where' => array('subject_id',$SubjectInfoid))))
					{

					while ($getmember_row = $PowerBB->DB->sql_fetch_array($getmember_query))
					{
					$MemArr 			= 	array();
					$MemArr['where'] 	= 	array('id',$getmember_row['user_id']);

					$MemInfo = $PowerBB->member->GetMemberInfo($MemArr);

					$username = $PowerBB->_CONF['template']['lang']['hello_your']  . $MemInfo['username'].'<br>';

                    	if ($PowerBB->_CONF['info_row']['mailer']=='phpmail')
						{
					     $Send = $PowerBB->functions->mail($MemInfo['email'],$title.':'.$PowerBB->_POST['title'],$starthtml.$username.$Form_Massege.$Endhtml,$PowerBB->_CONF['info_row']['send_email']);
			            }
						elseif ($PowerBB->_CONF['info_row']['mailer']=='smtp')
						{
						$to = $MemInfo['email'];
						$fromname = $PowerBB->_CONF['info_row']['title'];
						$message = $starthtml.$username.$Form_Massege.$Endhtml;
						$subject = $PowerBB->_POST['title'];
						$from = $PowerBB->_CONF['info_row']['send_email'];
                        $Send = $PowerBB->functions->send_this_smtp($to,$fromname,$message,$subject,$from);

						}

					}
					}

					///////////

					}


		     		$LastArr = array();

		     		$LastArr['writer'] 		= 	$PowerBB->_CONF['member_row']['username'];
		     		$LastArr['title'] 		= 	$this->SubjectInfo['title'];
		     		$LastArr['subject_id'] 	= 	$this->SubjectInfo['id'];
		     		$LastArr['date'] 		= 	$PowerBB->_CONF['date'];
		     		$LastArr['last_time'] 		= 	$PowerBB->_CONF['date'];
		     		$LastArr['icon'] 		= 	$PowerBB->_POST['icon'];
		     		$LastArr['last_reply'] 		= 	$PowerBB->reply->id;
		     		$LastArr['last_berpage_nm'] 		= 	$PowerBB->_POST['count'];
		     		$LastArr['where'] 		= 	(!$this->SectionInfo['parent']) ? array('id',$this->SectionInfo['id']) : array('id',$this->SectionInfo['parent']);


		     		$UpdateLast = $PowerBB->section->UpdateLastSubject($LastArr);


		     		if (!isset($PowerBB->_POST['ajax']))
		     		{
			   		  if ($PagerReplyNumArr < $PowerBB->_CONF['info_row']['perpage'])
					   {

			 	        $PowerBB->functions->redirect('index.php?page=topic&amp;show=1&amp;id=' . $this->SubjectInfo['id'] . '&amp;password=' . $PowerBB->_GET['password'].'#' . $PowerBB->reply->id);

					   }
			          elseif ($PagerReplyNumArr == $PowerBB->_CONF['info_row']['perpage'])
			          {

				        $PowerBB->functions->redirect('index.php?page=topic&amp;show=1&amp;id=' . $this->SubjectInfo['id'] . '&amp;password=' . $PowerBB->_GET['password'].'#' . $PowerBB->reply->id);

			          }
			          else
			          {
			              $ss_r = $PowerBB->_CONF['info_row']['perpage']/2+1;
			              $roun_ss_r = round($ss_r, 0);
				          $reply_number_r = $PagerReplyNumArr-$roun_ss_r;
				          $pagenum_r = $reply_number_r/$PowerBB->_CONF['info_row']['perpage'];
				          $round0_r = round($pagenum_r, 0);
				          $perpage_r = $round0_r*$PowerBB->_CONF['info_row']['perpage'];

						  $PowerBB->functions->redirect('index.php?page=topic&amp;show=1&amp;id=' . $this->SubjectInfo['id'] . '&amp;count=' . $perpage_r  . '#' . $PowerBB->reply->id);

			          }
		            }
		     		else
		     		{
		     			$GetArr 			= 	array();
		     			$GetArr['where'] 	= 	array('id',$PowerBB->reply->id);

		     			$PowerBB->_CONF['template']['Info'] = $PowerBB->reply->GetReplyInfo($GetArr);

		     			$PowerBB->_CONF['template']['Info']['id'] 				= 	$PowerBB->_CONF['member_row']['id'];
		     			$PowerBB->_CONF['template']['Info']['username'] 			= 	$PowerBB->_CONF['member_row']['username'];
		     			$PowerBB->_CONF['template']['Info']['avater_path'] 		= 	$PowerBB->_CONF['member_row']['avater_path'];
		     			$PowerBB->_CONF['template']['Info']['posts'] 				= 	$PowerBB->_CONF['member_row']['posts'];
		     			$PowerBB->_CONF['template']['Info']['user_country'] 		= 	$PowerBB->_CONF['member_row']['user_country'];
		     			$PowerBB->_CONF['template']['Info']['visitor'] 			= 	$PowerBB->_CONF['member_row']['visitor'];
		     			$PowerBB->_CONF['template']['Info']['away'] 				= 	$PowerBB->_CONF['member_row']['away'];
		     			$PowerBB->_CONF['template']['Info']['away_msg'] 			= 	$PowerBB->_CONF['member_row']['away_msg'];
		     			$PowerBB->_CONF['template']['Info']['register_date'] 		= 	$PowerBB->_CONF['member_row']['register_date'];
		     			$PowerBB->_CONF['template']['Info']['user_title'] 		= 	$PowerBB->_CONF['member_row']['user_title'];
		     			$PowerBB->_CONF['template']['Info']['reply_id'] 		= 	$PowerBB->reply->id;
		     			$PowerBB->_CONF['template']['Info']['user_gender'] 		= 	$PowerBB->_CONF['member_row']['user_gender'];
		     			$PowerBB->_CONF['template']['Info']['bday_day'] 		= 	$PowerBB->_CONF['member_row']['bday_day'];
		     			$PowerBB->_CONF['template']['Info']['bday_month'] 		= 	$PowerBB->_CONF['member_row']['bday_month'];
		     			$PowerBB->_CONF['template']['Info']['bday_year'] 		= 	$PowerBB->_CONF['member_row']['bday_year'];
		     			$PowerBB->_CONF['template']['Info']['invite_num'] 		    = 	$PowerBB->_CONF['member_row']['invite_num'];
		     			$PowerBB->_CONF['template']['Info']['warnings'] 		= 	$PowerBB->_CONF['member_row']['warnings'];

		     			// Make register date in nice format to show it
						if (is_numeric($PowerBB->_CONF['template']['Info']['register_date']))
						{
							$PowerBB->_CONF['template']['Info']['register_date'] = $PowerBB->functions->date($PowerBB->_CONF['template']['Info']['register_date']);
						}
						       $cache = unserialize(base64_decode($PowerBB->_CONF['member_row']['style_cache']));
                               $image_path = $PowerBB->_CONF['rows']['style']['image_path'];

						// Make member gender as a readable text
						$CheckOnline = ($PowerBB->_CONF['member_row']['logged'] < $PowerBB->_CONF['timeout']) ? false : true;

                     	($CheckOnline) ? $PowerBB->template->assign('status',"<img title='Online' src='$image_path/icon_user_online.gif'>") : $PowerBB->template->assign('status',"<img title='offline' src='$image_path/icon_user_offline.gif'>");


						if (empty($PowerBB->_CONF['member_row']['username_style_cache']))
						{
							$PowerBB->_CONF['template']['Info']['display_username'] = $PowerBB->_CONF['member_row']['username'];
						}
						else
						{
							$PowerBB->_CONF['template']['Info']['display_username'] = $PowerBB->_CONF['member_row']['username_style_cache'];

							$PowerBB->_CONF['template']['Info']['display_username'] = $PowerBB->functions->CleanVariable($PowerBB->_CONF['template']['Info']['display_username'],'unhtml');
						}

						$PowerBB->_CONF['template']['Info']['text'] = $PowerBB->Powerparse->replace($PowerBB->_CONF['template']['Info']['text']);

						// Convert the smiles to image
						$PowerBB->Powerparse->replace_smiles($PowerBB->_CONF['template']['Info']['text']);

						// Member signture is not empty , show make it nice with PowerCode
						if (!empty($PowerBB->_CONF['member_row']['user_sig']))
						{
							$PowerBB->_CONF['template']['Info']['user_sig'] = $PowerBB->Powerparse->replace($PowerBB->_CONF['member_row']['user_sig']);

							$PowerBB->Powerparse->replace_smiles($PowerBB->_CONF['template']['Info']['user_sig']);
						}

						$reply_date = $PowerBB->functions->date($PowerBB->_CONF['template']['Info']['write_time']);
						$reply_time = $PowerBB->functions->time($PowerBB->_CONF['template']['Info']['write_time']);
                       	$PowerBB->_CONF['template']['Info']['usergroup'] = $PowerBB->_CONF['member_row']['usergroup'];

                        $PowerBB->_CONF['template']['Info']['write_time'] = $reply_date . ' ; ' . $reply_time;
                       $PowerBB->template->assign('id',$PowerBB->_GET['id']);
                       $PowerBB->template->assign('password',$this->SectionInfo['section_password']);
                        $PowerBB->template->display('show_reply');
                     /*
              		$Subjectid = $PowerBB->_GET['id'];
                    $PagerReplyNumArr = $PowerBB->DB->sql_num_rows($PowerBB->DB->sql_query("SELECT * FROM " . $PowerBB->table['reply'] . " WHERE subject_id='$Subjectid' and delete_topic <>1"));

			              $ss_r = $PowerBB->_CONF['info_row']['perpage']/2+1;
			              $roun_ss_r = round($ss_r, 0);
				          $reply_number_r = $PagerReplyNumArr-$roun_ss_r;
				          $pagenum_r = $reply_number_r/$PowerBB->_CONF['info_row']['perpage'];
				          $round0_r = round($pagenum_r, 0);
				          $perpage_r = $round0_r*$PowerBB->_CONF['info_row']['perpage'];
				          $Num_0 = '0';

			   		  if ($PagerReplyNumArr < $PowerBB->_CONF['info_row']['perpage'])
					   {

				          if ($this->SubjectInfo['reply_number'] == '0')
				          {
                            echo ('<SCRIPT LANGUAGE="JavaScript">window.location="index.php?page=topic&show=1&id='.$SubjectInfoid.'&password=' . $PowerBB->_GET['password'].'";</script>');
                           }
                           else
			               {
			                 echo ('<SCRIPT LANGUAGE="JavaScript">window.location="index.php?page=topic&show=1&id='.$SubjectInfoid.'&password=' . $PowerBB->_GET['password'].'&count='.$Num_0.'#'.$PowerBB->reply->id.'";</script>');
			               }
					   }
			          elseif ($PagerReplyNumArr == $PowerBB->_CONF['info_row']['perpage'])
			          {

			           echo ('<SCRIPT LANGUAGE="JavaScript">window.location="index.php?page=topic&show=1&id='.$SubjectInfoid.'&password=' . $PowerBB->_GET['password'].'&count='.$Num_0.'#'.$PowerBB->reply->id.'";</script>');
			          }
			          else
			          {
			            print ('<script type="text/javascript">window.location="index.php?page=topic&show=1&id='.$SubjectInfoid.'&password=' . $PowerBB->_GET['password'].'&count='.$perpage_r.'#'.$PowerBB->reply->id.'";</script>');
			          }


                    */
                  }
		     	}
     	}
	}
}


?>
