<?php
//--------------class forumsResponsesFormHandler--------------->>>//
/**
 * @category	Anova
 * @package		forumsResponsesFormHandler
 * @author 		shankar_76ag08
 * @copyright	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id:
 * @since 		2008-10-29
 **/
class forumsResponsesFormHandler extends ForumHandler
	{
		//Variable to store group forum details
		public $forum_details_arr;
		//Variable to store response details
		public $forum_topic_details_arr;

		/**
		 * set the condition
		 *
		 * @access public
		 * @return void
		 **/
		public function buildConditionQuery($condition='')
			{
				$this->sql_condition = $condition;
			}

		/**
		 * To sort the query
		 *
		 * @access public
		 * @return void
		 **/
		public function checkSortQuery($field, $sort='asc')
			{
				if(!($this->sql_sort))
				{
					$this->sql_sort = $field . ' ' . $sort;
				}
			}

		/**
		 * To delete the give response id
		 *
		 * @param 		integer $forum_id
		 * @param 		integer $topic_id
		 * @param 		interger $response_id
		 * @access public
		 * @return void
		 **/
		public function deleteResponse($forum_id, $topic_id, $response_id)
			{
				$sql = 'DELETE FROM '.$this->CFG['db']['tbl']['forum_response'].' '.
						'WHERE topic_id = '.$this->dbObj->Param($topic_id).' '.
						'AND response_id = '.$this->dbObj->Param($response_id).' '.
						'AND response_user_id = '.$this->dbObj->Param($this->CFG['user']['user_id']);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($topic_id, $response_id, $this->CFG['user']['user_id']));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				$this->updateTotalResponse($topic_id);
				$this->updateTotalResponseForums($forum_id);
				return true;
			}

		/**
		 * To update the total_response in forum_topic table
		 *
		 * @param 		integer $topic_id
		 * @access public
		 * @return void
		 **/
		public function updateTotalResponse($topic_id)
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['forum_topics'].' SET '.
						'total_response = total_response - 1 '.
						'WHERE topic_id = '.$this->dbObj->Param($topic_id).' '.
						'AND total_response > 0 ';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($topic_id));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				return true;
			}

		/**
		 * To update total_response count in forums table
		 *
		 * @param 		integer $forum_id
		 * @access public
		 * @return void
		 **/
		public function updateTotalResponseForums($forum_id)
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['forums'].' SET '.
						'total_response = total_response - 1 '.
						'WHERE forum_id = '.$this->dbObj->Param($forum_id).' '.
						'AND total_response > 0 ';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($forum_id));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				return true;
			}

		/**
		 * To display the forums topic responses
		 *
		 * @access public
		 * @return void
		 **/
		public function showForumResponse()
			{
				$showForumResponse_arr = array();
				$i = 0;
				$inc = 1;
				$clsNoBorder = '';
				while($row = $this->fetchResultRecord())
					{
						if($i == 0) $clsNoBorder = 'clsNoBorder';
						else $clsNoBorder = '';
						$i++;
						$showForumResponse_arr[$inc]['record'] = $row;
						$userDetails = $row;
						$userDetails['user_id'] = $row['response_user_id'];
						$showForumResponse_arr[$inc]['userDetails'] = $userDetails;
						$showForumResponse_arr[$inc]['clsNoBorder'] = $clsNoBorder;
						$showForumResponse_arr[$inc]['responseId'] = $row['response_id'];
						$showForumResponse_arr[$inc]['user_myanswers']['url'] = getMemberUrl($userDetails['user_id'], $userDetails['name']);
						$showForumResponse_arr[$inc]['user_myanswers']['title'] = stripString(ucwords($row['display_name']), $this->CFG['username']['short_length']);

						$row['forum_response'] = str_replace('&lt;a href=&quot;', '&lt;a target=&quot;_blank&quot; href=&quot;', $row['forum_response']);
						$showForumResponse_arr[$inc]['modified_forum_response'] = nl2br(wordWrapManual($row['forum_response'], $this->CFG['admin']['forum']['line_length']));

						if ($row['response_user_id'] == $this->CFG['user']['user_id'])
							{
								$showForumResponse_arr[$inc]['anchor'] = 'dAlt_'.$row['response_id'];

								$showForumResponse_arr[$inc]['forums_response_create']['url'] = getForumsUrl('forumsresponsecreate', '?title='.$this->forum_details_arr['seo_title'].'&amp;topic_title='.$this->forum_topic_details_arr['seo_title'].'&amp;response_id='.$row['response_id'], $this->forum_details_arr['seo_title'].'/'.$this->forum_topic_details_arr['seo_title'].'/'.$row['response_id'].'/', 'members');
							}

						$showForumResponse_arr[$inc]['separator_class'] = 'clsNoLeftBgPadngMrgn';
						if((chkVideoModuleAllowed('forumresponse') AND $row['video_id'])
							OR (chkAudioModuleAllowed('forumresponse') AND $row['audio_id'])
							OR (chkExternalVideoModuleAllowed('forumresponse') AND $row['external_video_id'])
							OR (chkExternalAudioModuleAllowed('forumresponse') AND $row['external_audio_id']))
							{
								$showForumResponse_arr[$inc]['separator_class'] = '';
							}

						$showForumResponse_arr[$inc]['ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Forumresponse_'.$row['video_id'], '?pg=Forumresponse_'.$row['video_id']);
						$showForumResponse_arr[$inc]['ans_view_video']['on_click'] = 'forumresponse_video_'.$row['video_id'];

						$showForumResponse_arr[$inc]['ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Forumresponse_'.$row['audio_id'], '?pg=Forumresponse_'.$row['audio_id']);
						$showForumResponse_arr[$inc]['ans_view_audio']['on_click'] = 'forumresponse_audio_'.$row['audio_id'];

						$showForumResponse_arr[$inc]['ext_ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Forumresponse_'.$row['external_video_id'], '?pg=Forumresponse_'.$row['external_video_id']);
		  				$showForumResponse_arr[$inc]['ext_ans_view_video']['on_click'] = 'external_video_forumresponse_'.$row['external_video_id'];

						$showForumResponse_arr[$inc]['ext_ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Forumresponse_'.$row['external_audio_id'], '?pg=Forumresponse_'.$row['external_audio_id']);
						$showForumResponse_arr[$inc]['ext_ans_view_audio']['on_click'] = 'external_audio_forumresponse_'.$row['external_audio_id'];

						$inc++;
					}
				return $showForumResponse_arr;
			}

		/**
		 * To update the forum_topic table
		 *
		 * @param string $topic_id
		 * @access public
		 * @return integer
		 **/
		public function updateTopicViews($topic_id)
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['forum_topics'].
						' SET total_views = total_views + 1'.
						' WHERE topic_id = '.$this->dbObj->Param($topic_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($topic_id));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				return true;
			}

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function updateQuestionAbuseCount()
		    {
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['forum_topics'].' SET abuse_count=abuse_count+1'.
						' WHERE topic_id='.$this->dbObj->Param('topic_id');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['topic_id']));
				if (!$rs)
					    trigger_db_error($this->dbObj);
		    }

		/**
		 * forumsResponsesFormHandler::updateAbuseForum()
		 *
		 * @return
		 */
		public function updateAbuseForum()
			{
				$sql = 'SELECT abuse_id FROM '.$this->CFG['db']['tbl']['abuse_forum'].
						' WHERE topic_id='.$this->dbObj->Param('topic_id').
						' AND reported_by='.$this->dbObj->Param('reported_by');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['topic_id'],
														 $this->CFG['user']['user_id']));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				if (!$rs->PO_RecordCount())
					{
						$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['abuse_forum'].
								' SET topic_id='.$this->dbObj->Param('topic_id').
								', reported_by='.$this->dbObj->Param('reported_by').
								', reason='.$this->dbObj->Param('reason').
								', date_abused=NOW()';
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['topic_id'],
																 $this->CFG['user']['user_id'],
																 $this->fields_arr['reason']));
						if (!$rs)
						        trigger_db_error($this->dbObj);

						if ($this->dbObj->Affected_Rows())
							{
								$this->updateQuestionAbuseCount();
							}
					}
			}

		/**
		 * forumsResponsesFormHandler::publishResponse()
		 *
		 * @return
		 */
		public function publishResponse()
			{
				$resp_details = $this->forumRelatedDetails('', '', $this->fields_arr['response_id']);

				$sql = 'UPDATE '.$this->CFG['db']['tbl']['forum_response'].' SET response_status=\'Yes\' WHERE response_id='.$this->dbObj->Param('rid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['response_id']));
				if (!$rs)
					    trigger_db_error($this->dbObj);

				if ($this->dbObj->Affected_Rows())
					{
						// To update topic table..
						$usr_sql = 'UPDATE '.$this->CFG['db']['tbl']['forum_topics'].' SET'.
								' total_response = total_response + 1'.
								', total_views = total_views + 1'.
								', last_post_user_id = '.$this->dbObj->Param('user_id').
								', last_post_date = now()'.
								' WHERE topic_id = '.$this->dbObj->Param('topic_id');

						$usr_stmt = $this->dbObj->Prepare($usr_sql);
						$usr_rs = $this->dbObj->Execute($usr_stmt, array($resp_details['response_ownerid'], $this->fields_arr['topic_id']));
						if (!$usr_rs)
						        trigger_db_error($this->dbObj);

						// To update forum table
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['forums'].' SET '.
								'last_post_user_id = '.$this->dbObj->Param('user_id').', '.
								'last_post_date = now(), '.
								'total_response = total_response + 1 '.
								'WHERE forum_id = '.$this->dbObj->Param('forum_id');
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($resp_details['response_ownerid'], $this->fields_arr['forum_id']));
						if (!$rs)
						        trigger_db_error($this->dbObj);

						// To update user log table for posts....
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['users_ans_log'].
								' SET total_posts = total_posts + 1'.
								' WHERE '.$this->getUserTableField('user_id').' = '.$this->dbObj->Param('user_id');
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($resp_details['response_ownerid']));
						if (!$rs)
						        trigger_db_error($this->dbObj);

						$this->sendPublishedMailAlert($this->fields_arr['forum_id'], $this->fields_arr['topic_id'], $resp_details['response_ownername'], $resp_details['response_owneremail'], $resp_details['response']);

					}
		    	}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function chkIsForumAbusedAlready($tid)
			{
				$uid = $this->CFG['user']['user_id'];
				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['abuse_forum'].
						' WHERE topic_id='.$this->dbObj->Param('tid').
						' AND reported_by='.$this->dbObj->Param('uid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($tid, $uid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					return true;
				return false;
			}

		/**
		 * forumsResponsesFormHandler::sendPublishedMailAlert()
		 *
		 * @param mixed $forum_id
		 * @param mixed $topic_id
		 * @param mixed $receivername
		 * @param mixed $toEmail
		 * @param mixed $mailcontent
		 * @return
		 */
		public function sendPublishedMailAlert($forum_id, $topic_id, $receivername, $toEmail, $mailcontent)
			{
				$site_link = "<a target=\"_blank\" href=\"".URL($this->CFG['site']['url'])."\">".URL($this->CFG['site']['url'])."</a>";
				$forum_details = $this->forumRelatedDetails($forum_id);
				$topic_details = $this->forumRelatedDetails('',$topic_id);
				$url_link = getForumsUrl('forumsresponses', '?title='.$forum_details['forum_seo'].'&amp;topic_title='.$topic_details['topic_seo'], $forum_details['forum_seo'].'/'.$topic_details['topic_seo'].'/', 'root');
				$forum_link = "<a target=\"_blank\" href=\"".$url_link."\"><strong>".$forum_details['forum']."</strong></a>";
				$subject = $this->getMailContent($this->LANG['forum_response_publish_subject'], array('VAR_USERNAME'=>$receivername, 'VAR_SITENAME'=>$this->CFG['site']['name'], 'VAR_FORUM'=>$forum_link, 'VAR_DESCRIPTION_OF_FORUM'=>$mailcontent, 'VAR_LINK'=>$site_link));
				$content = $this->getMailContent($this->LANG['forum_response_publish_message'], array('VAR_USERNAME'=>$receivername, 'VAR_SITENAME'=>$this->CFG['site']['name'], 'VAR_FORUM'=>$forum_link, 'VAR_DESCRIPTION_OF_FORUM'=>$mailcontent, 'VAR_LINK'=>$site_link));

				$this->_sendMail($toEmail, $subject, $content, $this->CFG['site']['noreply_name'], $this->CFG['site']['noreply_email']);
			}

		/**
		 * forumsResponsesFormHandler::_sendMail()
		 *
		 * @param mixed $to_email
		 * @param mixed $subject
		 * @param mixed $body
		 * @param mixed $sender_name
		 * @param mixed $sender_email
		 * @return
		 */
		private function _sendMail($to_email, $subject, $body, $sender_name, $sender_email)
			{
				$this->buildEmailTemplate($subject, $body, false, true);

				$EasySwift = new EasySwift($this->getSwiftConnection());
				$EasySwift->flush();
				$EasySwift->addPart($this->getEmailContent(), "text/html");
				$from_address = $sender_name.'<'.$sender_email.'>';
				return $EasySwift->send($to_email, $from_address, $this->getEmailSubject());
			}

	}
//<<<<<<<--------------class forumsResponsesFormHandler---------------//

//--------------------Code begins-------------->>>>>//
$forumsResponses = new forumsResponsesFormHandler();
if(!chkIsAllowedModule(array('forums')))
	Redirect2URL(getForumsUrl($CFG['redirect']['dsabled_module_url']['file_name']));
$forumsResponses->setPageBlockNames(array('form_title', 'form_forum_title', 'form_show_responses', 'form_confirm'));
$forumsResponses->setAllPageBlocksHide();
//default form fields and values...
$forumsResponses->setFormField('id', '');
$forumsResponses->setFormField('task', '');
$forumsResponses->setFormField('forum_id', '');
$forumsResponses->setFormField('title', '');
$forumsResponses->setFormField('topic_id', '');
$forumsResponses->setFormField('topic_title', '');
$forumsResponses->setFormField('msg', '');
$forumsResponses->setFormField('pbl', '');
$forumsResponses->setFormField('act', '');
$forumsResponses->setFormField('response_id', '');
$forumsResponses->setFormField('reason', '');
$forumsResponses->setFormField('forum_userid', '');
$forumsResponses->setFormField('numpg',0);
$forumsResponses->setFormField('start',0);
/*************Start navigation******/
//fetch number of records show in the result--numpg
$condition = '';
$forumsResponses->unpublished = '';
$forumsResponses->numpg = $CFG['data_tbl']['numpg'];
$forumsResponses->setFormField('start', 0);
$forumsResponses->setFormField('numpg', $CFG['data_tbl']['numpg']);

$forumsResponses->setMinRecordSelectLimit($CFG['data_tbl']['min_record_select_limit']);
$forumsResponses->setMaxRecordSelectLimit($CFG['data_tbl']['max_record_select_limit']);
$forumsResponses->setNumPerPageListArr($CFG['data_tbl']['numperpage_list_arr']);
//Set tables and fields to return
$forumsResponses->setTableNames(array());
$forumsResponses->setReturnColumns(array());
/*************End navigation******/
$forumsResponses->sanitizeFormInputs($_REQUEST);

$title = $LANG['forumlistall_title_index'];
$forumsResponses->alter_link = '';
if ($forumsResponses->isFormGETed($_GET, 'title') && $forumsResponses->isFormGETed($_GET, 'topic_title'))
	{
		$forumsResponses->chkIsNotEmpty('title', $LANG['err_tip_compulsory'])and
			$forumsResponses->isValidForumId($forumsResponses->getFormField('title'), $LANG['forums_err_tip_invalid_forum_id']);
		$forumsResponses->chkIsNotEmpty('topic_title', $LANG['err_tip_compulsory'])and
			$forumsResponses->isValidForumTopicId($forumsResponses->getFormField('forum_id'), $forumsResponses->getFormField('topic_title'), $LANG['forumsresponses_err_tip_invalid_forum_topic_id']);
		$forumsResponses->getFormField('response_id')and
			$forumsResponses->chkIsNotEmpty('response_id', $LANG['err_tip_compulsory'])and
				$forumsResponses->chkIsNumeric('response_id', $LANG['err_tip_compulsory'])and
					$forumsResponses->isValidForumResponseId($forumsResponses->getFormField('topic_id'), $forumsResponses->getFormField('response_id'), $LANG['forumsresponses_err_tip_invalid_forum_response_id']);

		if ($forumsResponses->getFormField('act') == 'delete')
			{
				$forumsResponses->setPageBlockShow('block_msg_form_success');
				$LANG['forumsresponses_success_message'] = $LANG['forumsresponses_deleted_success'];
				$forumsResponses->setCommonSuccessMsg($LANG['forumsresponses_success_message']);
			}
		elseif($forumsResponses->isFormGETed($_GET, 'msg'))
			{
				$forumsResponses->setPageBlockShow('block_msg_form_success');
				if($forumsResponses->getFormField('msg') == 'add')
						{
							if($forumsResponses->forum_topic_details_arr['publish_status'] == 'Yes' or $forumsResponses->forum_topic_details_arr['user_id'] == $CFG['user']['user_id'])
								$LANG['forumsresponses_success_message'] = $LANG['forumsresponses_posted_success'];
							else
								$LANG['forumsresponses_success_message'] = $LANG['forumsresponses_waiting_for_publish'];
						}
					else
						$LANG['forumsresponses_success_message'] = $LANG['forumsresponses_updated_success'];
				$forumsResponses->setCommonSuccessMsg($LANG['forumsresponses_success_message']);
			}

		if($forumsResponses->isFormGETed($_GET, 'task'))
			{
				$forumsResponses->updateTopicViews($forumsResponses->getFormField('topic_id'));
			}

		if (!$forumsResponses->isValidFormInputs())
			{
				Redirect2URL(getForumsUrl('forums'));
			}
		if ($forumsResponses->isFormPOSTed($_POST, 'cancel'))
			{
				$forumsResponses->setFormField('response_id', '');
			}
		if ($forumsResponses->isFormPOSTed($_POST, 'confirm'))
			{
				if (!isMember())
					{
						$_SESSION['url'] = getForumsUrl('forumsresponses', '?title='.$forumsResponses->getFormField('title').'&amp;topic_title='.$forumsResponses->getFormField('topic_title'), $forumsResponses->getFormField('title').'/'.$forumsResponses->getFormField('topic_title'),'root');
						$_SESSION['login_error'] = 'login_err_authorization_required';
						Redirect2URL(getUrl('login'));
					}

				if($forumsResponses->getFormField('act') == 'publish')
					{
						$forumsResponses->publishResponse();
						$forumsResponses->setFormField('response_id', '');
					}
				else
					{
						$forumsResponses->deleteResponse($forumsResponses->getFormField('forum_id'), $forumsResponses->getFormField('topic_id'), $forumsResponses->getFormField('response_id'));
						$forumsResponses->setFormField('response_id', '');
					}
			}

		if($CFG['html']['meta']['appendable'])
			{
				$forumsResponses->appendMetaDetails(html_entity_decode($forumsResponses->forum_details_arr['forum_title']).' - '.html_entity_decode($forumsResponses->forum_topic_details_arr['forum_topic']), '');
			}
	}
else
	{
		//now redirect to forums main page...
		Redirect2URL(getForumsUrl('forums'));
	}

if ($forumsResponses->isValidFormInputs())
	{
		$title .= ' - '.$forumsResponses->forum_details_arr['forum_title'];
		$title .= ' - '.$forumsResponses->forum_topic_details_arr['forum_topic'];
		$show_unpublished = false;
		if($forumsResponses->isFormGETed($_GET, 'pbl') and isMember())
			{
				$forumsResponses->unpublished = ' - '.$LANG['forumsresponses_unpublished'];
				$show_unpublished = true;
				$forumsResponses->alter_link = '<a href="'.getForumsUrl('forumsresponses', '?title='.$forumsResponses->forum_details_arr['seo_title'].'&amp;topic_title='.$forumsResponses->forum_topic_details_arr['seo_title'], $forumsResponses->forum_details_arr['seo_title'].'/'.$forumsResponses->forum_topic_details_arr['seo_title']).'">'.$LANG['forumsresponses_allresponses'].'</a>';
			}

		/*************Start navigation******/
		//Set tables and fields to return
		$forumsResponses->setTableNames(array($CFG['db']['tbl']['forum_response'].' as gr', $CFG['db']['tbl']['users'].' as u'));
		$return_fields = array('gr.response_id', 'gr.topic_id', 'gr.forum_response', 'gr.response_status', 'gr.response_user_id', 'gr.video_id', 'gr.audio_id', 'gr.external_video_id', 'gr.external_audio_id', 'DATE_FORMAT(gr.date_added, \''.$CFG['format']['date'].'\') as date_added');
		if($forumsResponses->getUserTableField('name'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('name').' AS name';
			}
		if($forumsResponses->getUserTableField('display_name'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('display_name').' AS display_name';
			}
		if($forumsResponses->getUserTableField('image_path'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('image_path').' AS image_path';
			}
		if($forumsResponses->getUserTableField('gender'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('gender').' AS gender';
			}
		if($forumsResponses->getUserTableField('user_id'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('user_id').' AS img_user_id';
			}
		if($forumsResponses->getUserTableField('t_height'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('t_height').' AS t_height';
			}
		if($forumsResponses->getUserTableField('t_width'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('t_width').' AS t_width';
			}
		if($forumsResponses->getUserTableField('s_height'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('s_height').' AS s_height';
			}
		if($forumsResponses->getUserTableField('s_width'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('s_width').' AS s_width';
			}
		if($forumsResponses->getUserTableField('photo_server_url'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('photo_server_url').' AS photo_server_url';
			}
		if($forumsResponses->getUserTableField('photo_ext'))
			{
				$return_fields[] = 'u.'.$forumsResponses->getUserTableField('photo_ext').' AS photo_ext';
			}

		$forumsResponses->setReturnColumns($return_fields);
		//Condition of the query
		$condition = 'gr.response_user_id = u.'.$forumsResponses->getUserTableField('user_id').' AND gr.topic_id = \''.$forumsResponses->getFormField('topic_id').'\'';
		if($forumsResponses->forum_topic_details_arr['user_id'] == $CFG['user']['user_id'])
			{
				if($show_unpublished)
					$condition .= ' AND gr.response_status =\'ToActivate\'';
				else
					$condition .= ' AND gr.response_status !=\'No\'';
			}
		else
			{
				$condition .= ' AND gr.response_status =\'Yes\'';
			}

		if ($CFG['admin']['ignore_user'])
			{
				$condition .= ' AND NOT EXISTS (SELECT 1 FROM '.$CFG['db']['tbl']['user_ignored'].' AS ui WHERE ui.user_id='.$CFG['user']['user_id'].' AND ui.ignored_id=gr.response_user_id)';
			}

		$forumsResponses->buildSelectQuery();
		$forumsResponses->buildConditionQuery($condition);
		$forumsResponses->buildSortQuery();
		$forumsResponses->checkSortQuery('gr.date_added', $CFG['admin']['forums']['order']);
		$forumsResponses->buildQuery();
		$forumsResponses->executeQuery();
		/*************End navigation******/

		$forumsResponses->setPageBlockShow('form_forum_title');
		$forumsResponses->setPageBlockShow('form_show_responses');
		if ($forumsResponses->isResultsFound())
			{
				$forumsResponses->form_show_responses_arr = array();
				if ($forumsResponses->forum_topic_details_arr)
					{
						$forumsResponses->form_show_responses_arr['user_myanswers']['url'] = getMemberUrl($forumsResponses->forum_topic_details_arr['user_id'], $forumsResponses->forum_topic_details_arr['name']);
					}

				$forumsResponses->form_show_responses_arr['showForumResponse'] = $forumsResponses->showForumResponse();
				$smartyObj->assign('smarty_paging_list', $forumsResponses->populatePageLinksGET($forumsResponses->getFormField('start'), array('title', 'topic_title','task')));
		    }
		else
			{
				$forumsResponses->form_show_responses_arr['forums_response_create']['url'] = getForumsUrl('forumsresponsecreate', '?title='.$forumsResponses->getFormField('title').'&amp;topic_title='.$forumsResponses->getFormField('topic_title'), $forumsResponses->getFormField('title').'/'.$forumsResponses->getFormField('topic_title').'/', 'members');
			}

		if ($forumsResponses->getFormField('response_id'))
			{
				$forumsResponses->setPageBlockShow('form_confirm');
			}

		if($forumsResponses->isFormPOSTed($_POST, 'confirm_action'))
			{
				if (!isMember())
					{
						$_SESSION['url'] = getForumsUrl('forumsresponses', '?title='.$forumsResponses->getFormField('title').'&amp;topic_title='.$forumsResponses->getFormField('topic_title'), $forumsResponses->getFormField('title').'/'.$forumsResponses->getFormField('topic_title'),'root');
						$_SESSION['login_error'] = 'login_err_authorization_required';
						Redirect2URL(getUrl('login'));
					}
				$forumsResponses->chkIsNotEmpty('reason', $LANG['err_tip_compulsory']);
				if ($forumsResponses->isValidFormInputs())
					{
						$forumsResponses->updateAbuseForum();
						$forumsResponses->setPageBlockShow('block_msg_form_success');
						$LANG['forumsresponses_success_message'] = $LANG['forum_abused_successfully'];
						$forumsResponses->setCommonSuccessMsg($LANG['forumsresponses_success_message']);
					}
				else
					{
						$forumsResponses->setCommonErrorMsg($LANG['blog_cmd_err_msg_reason_empty']);
						$forumsResponses->setPageBlockShow('block_msg_form_error');
					}
			}
	}
else
	{
		$forumsResponses->setPageBlockShow('block_msg_form_error');
		Redirect2URL(getForumsUrl('forums'));
	}
$forumsResponses->myforums_url = getForumsUrl('forumstopics', '?title='.$forumsResponses->getFormField('title'), $forumsResponses->getFormField('title').'/');
$forumsResponses->myforums_title = wordWrapManual($forumsResponses->forum_details_arr['forum_title'],15);
$forumsResponses->topic_title = wordWrapManual($forumsResponses->forum_topic_details_arr['forum_topic'], 15);

if($forumsResponses->isShowPageBlock('form_forum_title'))
	{
		$forumsResponses->form_forum_title_arr = array();

		$forumsResponses->forum_response_url = getForumsUrl('forumstopics', '?title='.$forumsResponses->getFormField('title'), $forumsResponses->getFormField('title').'/', 'members');

		$forumsResponses->form_forum_title_arr['login']['url'] = getUrl('login', '?light_url='.$forumsResponses->forum_response_url, '?light_url='.$forumsResponses->forum_response_url, 'root');
		$forumsResponses->form_forum_title_arr['email_to_friends']['url'] = getForumsUrl('emailforums', '?tid='.$forumsResponses->getFormField('topic_id'), $forumsResponses->getFormField('topic_id').'/');

		if (isMember() and ($forumsResponses->forum_topic_details_arr['user_id'] != $CFG['user']['user_id']))
			{
				$forumsResponses->form_forum_title_arr['anchor'] = 'abuseContent';
			}

		$forumsResponses->form_forum_title_arr['favorite_answers']['url'] = getAnovaUrl('favoriteanswers');
		$forumsResponses->form_forum_title_arr['forum_response_create']['url'] = getForumsUrl('forumsresponsecreate', '?title='.$forumsResponses->getFormField('title').'&amp;topic_title='.$forumsResponses->getFormField('topic_title'), $forumsResponses->getFormField('title').'/'.$forumsResponses->getFormField('topic_title').'/', 'members');
		$forumsResponses->form_forum_title_arr['login_forum_response_create']['url'] = getUrl('login', '?light_url='.$forumsResponses->forum_response_url, '?light_url='.$forumsResponses->forum_response_url, 'root');

	}
$forumsResponses->confirmForm_hidden_arr = array('start', 'forum_id', 'topic_id');

$forumsResponses->bookmark_url = getForumsUrl('forumsresponses', '?title='.$forumsResponses->getFormField('title').'&amp;topic_title='.$forumsResponses->getFormField('topic_title'), $forumsResponses->getFormField('title').'/'.$forumsResponses->getFormField('topic_title'),'root');
$forumsResponses->bookmark_title = $forumsResponses->forum_topic_details_arr['forum_topic'];
$forumsResponses->forum_topic_details_arr['response_text'] = ($forumsResponses->forum_topic_details_arr['total_response']>1)?$LANG['common_total_responses']:$LANG['common_total_response'];
//<<<<--------------------Code Ends----------------------//

$CFG['site']['title'] = $title.' - '.$CFG['site']['title'];

//--------------------Page block templates begins-------------------->>>>>//
//include the header file
$forumsResponses->includeHeader();
//include the content of the page
setTemplateFolder('general/', $CFG['admin']['index']['forum_module']);
$smartyObj->display('forumsResponses.tpl');
//include the footer of the page
//<<<<<<--------------------Page block templates Ends--------------------//
?>
<script language="javascript" type="text/javascript">
	var replace_url = '<?php echo getUrl('login', '', '', 'root');?>';
	var block_arr= new Array('selMsgConfirm', 'selMsgConfirmMulti', 'selEditPhotoComments','selMsgAbuseConfirm');
	var total_comments = 10;
	var minimum_counts = 10000;
</script>
<script language="javascript" type="text/javascript">
function toggleResponse(spanObj, responseID){
	var moreObj = 'responsemore'+responseID;
	var lessObj = 'responseless'+responseID;

	if ($(lessObj).style.display == 'none'){
		$(moreObj).hide();
		$(lessObj).show();
	}else{
		$(moreObj).show();
		$(lessObj).hide();
	}
	toggleNavBar();
}
var expand = true;
var clicked = true;
var toggleExpandResponses = function(){
	if (clicked){
		//clicked = false;
		for (var i=1; i<=commentsArray.length; i++){
			moreObj = 'responsemore'+commentsArray[i];
			lessObj = 'responseless'+commentsArray[i];
			if ($(moreObj)){
				if (expand){
					$(moreObj).hide();
					$(lessObj).show();
				}else{
					$(moreObj).show();
					$(lessObj).hide();
				}
			}
		}
		expand = (expand)?false:true;
		//setTimeout('changeClickedStatus()', 2000);
		toggleNavBar();
	}
}
var changeClickedStatus = function(){
	toggleNavBar();
	clicked = true;
}
</script>
<?php
$forumsResponses->includeFooter();
?>