<?php
/**
 * blogList
 *
 * @package
 * @author karthiselvam_75ag08
 * @copyright Copyright (c) 2009
 * @version $Id: $
 * @access public
 **/
class blogList extends VideoUploadLib
	{
		public $enabled_edit_fields = array();
		public $repliesArray = array();
		public $msg = '';
		public $_dir_path = '';

		/**
		 * blogList::buildSortQuery()
		 *
		 * @return
		 **/
		public function buildSortQuery()
			{
				$this->sql_sort = $this->fields_arr['orderby_field'].' '.$this->fields_arr['orderby'];
			}

		public function buildConditionQuery()
			{
				$this->sql_condition = 'blog_id=\''.$this->fields_arr['blog_id'].'\'';
				$this->sql_condition .= 'AND main_comment_id=0 ';
				//publish comment no check the status
				if($this->fields_arr['user_id'] != $this->CFG['user']['user_id'])
					$this->sql_condition .= 'AND status=\'Active\'';

				if ($this->CFG['admin']['ignore_user'])
					{
						$this->sql_condition .= ' AND NOT EXISTS (SELECT 1 FROM '.$this->CFG['db']['tbl']['user_ignored'].' AS ui WHERE ui.user_id='.$this->CFG['user']['user_id'].' AND ui.ignored_id=bc.user_id)';
					}
			}
		/**
		 * blogList::showBlogsList()
		 *
		 * @return
		 **/
		public function showCommentsList()
			{
				$this->buildSelectQuery();
				$this->buildConditionQuery();
				$this->buildSortQuery();
				$this->buildQuery();
				$this->executeQuery();
				$this->showCommentsList_arr=array();
				if($this->isResultsFound())
					{
						$paging_arr = array();
						if($this->CFG['feature']['rewrite_mode'] != 'htaccess')
							$paging_arr[] = 'title';

						$i = 1;
						$inc=0;
						while($row = $this->fetchResultRecord())
							{
								$this->showCommentsList_arr[$inc]['i']=$i++;
								$this->showCommentsList_arr[$inc]['record']=$row;
								$this->showCommentsList_arr[$inc]['clsOddOrEvenQuestion'] = 'clsEvenQuestion';
								if ($i%2)
									$this->showCommentsList_arr[$inc]['clsOddOrEvenQuestion'] = 'clsOddQuestion';
								$this->showCommentsList_arr[$inc]['date_added']=($row['date_added'] != '') ? $this->getTimeDiffernceFormat($row['date_added']) : '';
								$userDetails = $this->getUserDetailsFromUsersTable($this->CFG['db']['tbl']['users'], $row['user_id']);
								$userDetails['image_id'] = 'comment';
								$this->showCommentsList_arr[$inc]['userDetails'] = $userDetails;
								$name = $userDetails['display_name'];
								$this->showCommentsList_arr[$inc]['wordwrap_comment']	=	wordWrapManual($row['comment'], $this->CFG['admin']['blog']['line_length']);
								$this->showCommentsList_arr[$inc]['myanswers_url']	=	getMemberUrl($userDetails['user_id'], $userDetails['name']);
								$this->showCommentsList_arr[$inc]['strip_name']	=	stripString($name, $this->CFG['username']['short_length']);
								$this->showCommentsList_arr[$inc]['replySpanIDId']	=	$replySpanIDId = 'replySpanID_'.$row['comment_id'];
								$this->showCommentsList_arr[$inc]['viewSpanId']	=	$viewSpanId = 'viewSpanId'.$row['comment_id'];
								$this->showCommentsList_arr[$inc]['selReplyId']	=	$selReplyId = 'selReplyId'.$row['comment_id'];
								$this->showCommentsList_arr[$inc]['selViewReplyId']	=	$selViewReplyId = 'selViewReplyId'.$row['comment_id'];
								$this->showCommentsList_arr[$inc]['image_id'] 	=	$userDetails['image_id'] = 'comment';
								$this->showCommentsList_arr[$inc]['blogcomment_url']	=	getBlogUrl('blogcomment', '?title='.$this->fields_arr['seo_title'], $this->fields_arr['seo_title'].'/', 'members');
								$this->showCommentsList_arr[$inc]['myanswers_url']	=	getMemberUrl($userDetails['user_id'], $userDetails['name']);
								$this->showCommentsList_arr[$inc]['blogcomment_pars']	=	'blog_id='. $this->fields_arr['blog_id'].'&amp;ajax_page=true&amp;showOptionToAnswer=1&amp;comment_id='.$row['comment_id'].'&amp;selReplyId='.$this->showCommentsList_arr[$inc]['selReplyId'];
								if ($this->hasReply($row['comment_id']))
								{
									$this->showCommentsList_arr[$inc]['fetchReply']	=	$this->fetchReply($row['comment_id']);
								}

								$this->showCommentsList_arr[$inc]['separator_class'] = 'clsNoLeftBgPadngMrgn';
								if((chkVideoModuleAllowed('blogcomment') AND $row['video_id'])
									OR (chkAudioModuleAllowed('blogcomment') AND $row['audio_id'])
									OR (chkExternalVideoModuleAllowed('blogcomment') AND $row['external_video_id'])
									OR (chkExternalAudioModuleAllowed('blogcomment') AND $row['external_audio_id']))
									{
										$this->showCommentsList_arr[$inc]['separator_class'] = '';
									}

								$this->showCommentsList_arr[$inc]['ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Blogcomment_'.$row['video_id'], '?pg=Blogcomment_'.$row['video_id']);
								$this->showCommentsList_arr[$inc]['ans_view_video']['on_click'] = 'ques_video_'.$row['video_id'];

								$this->showCommentsList_arr[$inc]['ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Blogcomment_'.$row['audio_id'], '?pg=Blogcomment_'.$row['audio_id']);
								$this->showCommentsList_arr[$inc]['ans_view_audio']['on_click'] = 'ques_audio_'.$row['audio_id'];

								$this->showCommentsList_arr[$inc]['ext_ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Blogcomment_'.$row['external_video_id'], '?pg=Blogcomment_'.$row['external_video_id']);
				  				$this->showCommentsList_arr[$inc]['ext_ans_view_video']['on_click'] = 'external_video_ques_'.$row['external_video_id'];

								$this->showCommentsList_arr[$inc]['ext_ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Blogcomment_'.$row['external_audio_id'], '?pg=Blogcomment_'.$row['external_audio_id']);
								$this->showCommentsList_arr[$inc]['ext_ans_view_audio']['on_click'] = 'external_audio_ques_'.$row['external_audio_id'];

								$inc++;
							}
					}
					return 	$this->showCommentsList_arr;
			}

		public function resetFieldsArray()
			{
				$this->setFormField('ajax_page', '');
				$this->setFormField('blog_id', '');
				$this->setFormField('title', '');
				$this->setFormField('act', '');
				$this->setFormField('comment', '');
				$this->setFormField('reason', '');
				$this->setFormField('audio_id', '');
				$this->setFormField('video_id', '');
				$this->setFormField('external_audio_id', '');
				$this->setFormField('external_video_id', '');
				$this->setFormField('succ', '');
			}

		/**
		 * manageBlog::populateBlogsValue()
		 *
		 * @return
		 **/
		public function populateBlogsValue()
			{
				$sql = 'SELECT blog_id, subject, seo_title, message, video_id, audio_id, external_video_id, external_audio_id, accept_comments, user_id, status,'.
						' UNIX_TIMESTAMP(date_added) AS date_added, total_views, total_comments,publish_comments, blog_category_id'.
						' FROM '.$this->CFG['db']['tbl']['blogs'].' WHERE'.
						' seo_title='.$this->dbObj->Param('title').' AND status=\'Active\'';

				$stmt = $this->dbObj->Prepare($sql);

				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['title']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				if ($row = $rs->FetchRow())
				    {
				     	$row['date_added'] = ($row['date_added'] != '') ? $this->getTimeDiffernceFormat($row['date_added']) : '';
						$this->fields_arr['subject'] = $row['subject'];
						$this->fields_arr['blog_id'] = $row['blog_id'];
						$this->fields_arr['seo_title'] = $row['seo_title'];
						$this->fields_arr['message'] = $row['message'];
						$this->fields_arr['date_added'] = $row['date_added'];
						$this->fields_arr['user_id'] = $row['user_id'];
						$this->fields_arr['blog_video'] = $row['video_id'];
						$this->fields_arr['blog_audio'] = $row['audio_id'];
						$this->fields_arr['blog_ext_video'] = $row['external_video_id'];
						$this->fields_arr['blog_ext_audio'] = $row['external_audio_id'];
						$this->fields_arr['total_views'] = $row['total_views'];
						$this->fields_arr['total_comments'] = $row['total_comments'];
						$this->fields_arr['accept_comments'] = $row['accept_comments'];
						$this->fields_arr['blog_category_id'] = $row['blog_category_id'];
						$this->fields_arr['publish_comments'] = $row['publish_comments'];
						return true;
				    }
				return false;
			}

		public function displayBlog()
			{
				$displayBlog_arr['userdetails']=$userDetails =	$this->getUserDetailsFromUsersTable($this->CFG['db']['tbl']['users'], $this->fields_arr['user_id']);
				$displayBlog_arr['wordwrap_msg'] = wordWrapManual($this->fields_arr['message'], $this->CFG['admin']['blog']['line_length']);
				$displayBlog_arr['myanswers_url'] = getMemberUrl($userDetails['user_id'], $userDetails['name']);
				$displayBlog_arr['strip_username'] = stripString($userDetails['display_name'], $this->CFG['username']['short_length']);
				$displayBlog_arr['blog_category'] = $this->getBlogCategory($this->fields_arr['blog_category_id']);
				$displayBlog_arr['bookmark_url'] = getBlogUrl('blogcomment','?title='.$this->fields_arr['seo_title'], $this->fields_arr['seo_title'].'/','root');
				$displayBlog_arr['bookmark_title'] = $this->fields_arr['subject'];
				if ($this->CFG['admin']['blogs']['ratings'])
					{
						$blog_url = getBlogUrl('blogcomment', '?title='.$this->fields_arr['seo_title'], $this->fields_arr['seo_title'].'/', 'members');
						$displayBlog_arr['getblogratings']=$this->getBlogRatings($this->CFG['db']['tbl']['users_stared_blogs'],
								$this->CFG['db']['tbl']['blogs'],
								$this->fields_arr['blog_id'],
								$this->fields_arr['user_id'],
								$this->CFG['site']['project_path_relative'],
								$this->CFG['site']['relative_url'],
								$blog_url);
					}

				if($this->fields_arr['accept_comments']=='Yes')
					{
						$this->setPageBlockShow('selAcceptCommentBlock');
					}

				$displayBlog_arr['separator_class'] = 'clsNoLeftBgPadngMrgn';
				if((chkVideoModuleAllowed('blog') AND $this->fields_arr['blog_video'])
					OR (chkAudioModuleAllowed('blog') AND $this->fields_arr['blog_audio'])
					OR (chkExternalVideoModuleAllowed('blog') AND $this->fields_arr['blog_ext_video'])
					OR (chkExternalAudioModuleAllowed('blog') AND $this->fields_arr['blog_ext_audio']))
					{
						$displayBlog_arr['separator_class'] = '';
					}

				$displayBlog_arr['ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Blog_'.$this->fields_arr['blog_video'], '?pg=Blog_'.$this->fields_arr['blog_video']);
				$displayBlog_arr['ans_view_video']['on_click'] = 'blog_video_'.$this->fields_arr['blog_video'];

				$displayBlog_arr['ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Blog_'.$this->fields_arr['blog_audio'], '?pg=Blog_'.$this->fields_arr['blog_audio']);
				$displayBlog_arr['ans_view_audio']['on_click'] = 'blog_audio_'.$this->fields_arr['blog_audio'];

				$displayBlog_arr['ext_ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Blog_'.$this->fields_arr['blog_ext_video'], '?pg=Blog_'.$this->fields_arr['blog_ext_video']);
  				$displayBlog_arr['ext_ans_view_video']['on_click'] = 'external_video_blog_'.$this->fields_arr['blog_ext_video'];

				$displayBlog_arr['ext_ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Blog_'.$this->fields_arr['blog_ext_audio'], '?pg=Blog_'.$this->fields_arr['blog_ext_audio']);
				$displayBlog_arr['ext_ans_view_audio']['on_click'] = 'external_audio_blog_'.$this->fields_arr['blog_ext_audio'];

				return $displayBlog_arr;
			}

		/**
		 * get answers rating
		 *
		 * @param 		String $users_stared_blog_table
		 * @param 		String $blog_table
		 * @param 		integer $blog_id
		 * @param 		integer $user_id
		 * @param 		String $cfg_project_path_relative
		 * @return 		void
		 * @access 		public
		 */
		public function getBlogRatings($users_stared_blog_table, $blog_table, $blog_id, $user_id, $cfg_project_path_relative, $relative_path, $blog_url)
			{
				$start 	= 1000;
				$end 	= 1004;
				$ratingsTitle = array($this->LANG['rating_below_average'],
									  $this->LANG['rating_average'],
									  $this->LANG['rating_good'],
									  $this->LANG['rating_excellent']);
								$pointer = 1;
								$ratingscnt = 0;
								$inc=0;
								$this->getBlogRatingsarray=array();
								if ($this->CFG['user']['user_id'] == 0)
									{
										for ($j=$start;$j<$end; $j++)
											{
												$this->getBlogRatingsarray['row'][$inc]['login_lightwindow']=$this->CFG['site']['url'].'login.php?light_url='.$blog_url;
												$this->getBlogRatingsarray['row'][$inc]['ratingsTitle']=$ratingsTitle[$ratingscnt];
												$this->getBlogRatingsarray['row'][$inc]['img_src']=$this->CFG['site']['url'].'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-rate.gif';
												$this->getBlogRatingsarray['row'][$inc]['inc']	=	$j+1;
												$this->getBlogRatingsarray['row'][$inc]['mouseOverAnswers']='mouseOverAnswers('.$this->getBlogRatingsarray['row'][$inc]['inc'].','.$start.',\''.$cfg_project_path_relative.'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-ratehover.gif\',\''.$cfg_project_path_relative.'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-rate.gif\')';
												$this->getBlogRatingsarray['row'][$inc]['mouseOutAnswers']='mouseOutAnswers('.$start.')';
												$this->getBlogRatingsarray['row'][$inc]['pointer']=$pointer;
												$this->getBlogRatingsarray['row'][$inc]['on_click'] = 'blog_rate_'.$pointer;
												$inc++;
												$pointer++;
												$ratingscnt++;
											}
									}
								elseif($this->CFG['user']['user_id'] == $user_id)
									{
										//nothing
									}
								else
									{
										$sql = 'SELECT rating FROM '.$users_stared_blog_table.' WHERE blog_id = '.$this->dbObj->Param($blog_id).
											   ' AND user_id = '.$this->dbObj->Param($this->CFG['user']['user_id']);

										$stmt = $this->dbObj->Prepare($sql);
										$result = $this->dbObj->Execute($stmt, array($blog_id, $this->CFG['user']['user_id']));
										if (!$result)
												trigger_db_error($this->dbObj);

										$rating = 0;
										$this->getBlogRatingsarray['RecordCount']=0;
										if ($result->PO_RecordCount())
											{
												$this->getBlogRatingsarray['RecordCount']=1;
												$row['rating'] = 0;
												if ($result->PO_RecordCount())
													$row = $result->FetchRow();
												$rating = $row['rating'];
												$pointer = 1;
												$ratingscnt = 0;
												$inc=0;
												$jnc=0;
												$this->getBlogRatingsarray['i']=array();
												$this->getBlogRatingsarray['j']=array();
												for ($i=$start;$i<$rating+$start; $i++)
													{
														$this->getBlogRatingsarray['i'][$inc]['inc']	=	$i+1;
														$this->getBlogRatingsarray['i'][$inc]['ratingsTitle']=$ratingsTitle[$ratingscnt];
														$this->getBlogRatingsarray['i'][$inc]['img_src']=$this->CFG['site']['url'].'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-ratehover.gif';
														$this->getBlogRatingsarray['i'][$inc]['pointer']=$pointer;
														$this->getBlogRatingsarray['i'][$inc]['mouseOutAnswers']='mouseOutAnswers('.$start.')';
														$this->getBlogRatingsarray['i'][$inc]['mouseOverAnswers']='mouseOverAnswers('.$this->getBlogRatingsarray['i'][$inc]['inc'].','.$start.',\''.$cfg_project_path_relative.'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-ratehover.gif\',\''.$cfg_project_path_relative.'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-rate.gif\')';
														$this->getBlogRatingsarray['i'][$inc]['onclick']='getQuestionRatingDetails(\''.$relative_path.'ratingAnswer.php\', \'action=blogs&amp;blog_id='.$blog_id.'&amp;uid='.$user_id.'&amp;rating='.$pointer.'\',\'selBlogRatingContent\')';
														$pointer++;
														$ratingscnt++;
														$inc++;
													}
												for ($j=$i;$j<$end; $j++)
													{
														$this->getBlogRatingsarray['j'][$jnc]['jnc']	=	$j+1;
														$this->getBlogRatingsarray['j'][$jnc]['img_src1']=$this->CFG['site']['url'].'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-rate.gif';
														$this->getBlogRatingsarray['j'][$jnc]['pointer1']=$pointer;
														$this->getBlogRatingsarray['j'][$jnc]['ratingsTitle1']=$ratingsTitle[$ratingscnt];
														$this->getBlogRatingsarray['j'][$jnc]['mouseOutAnswers1']='mouseOutAnswers('.$start.')';
														$this->getBlogRatingsarray['j'][$jnc]['mouseOverAnswers1']='mouseOverAnswers('.$this->getBlogRatingsarray['j'][$jnc]['jnc'].','.$start.',\''.$cfg_project_path_relative.'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-ratehover.gif\',\''.$cfg_project_path_relative.'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-rate.gif\')';
														$this->getBlogRatingsarray['j'][$jnc]['onclick1']='getQuestionRatingDetails(\''.$relative_path.'ratingAnswer.php\', \'action=blogs&amp;blog_id='.$blog_id.'&amp;uid='.$user_id.'&amp;rating='.$pointer.'\', \'selBlogRatingContent\')';
														$pointer++;
														$ratingscnt++;
														$jnc++;
													}

												}
											else
												{
													$this->getBlogRatingsarray['RecordCount']=0;
													$jnc=0;
													$pointer = 1;
													$ratingscnt = 0;
													$jnc=0;
													for ($j=$start;$j<$end; $j++)
														{

															$this->getBlogRatingsarray['row'][$jnc]['ratingsTitle']=$ratingsTitle[$ratingscnt];
															$this->getBlogRatingsarray['row'][$jnc]['img_src']=$cfg_project_path_relative.'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-rate.gif';
															$this->getBlogRatingsarray['row'][$jnc]['pointer']=$pointer;
															$this->getBlogRatingsarray['row'][$jnc]['mouseOutAnswers']='mouseOutAnswers(\''.$start.'\')';
															$this->getBlogRatingsarray['row'][$jnc]['onclick']='getQuestionRatingDetails(\''.$relative_path.'ratingAnswer.php\', \'action=blogs&amp;blog_id='.$blog_id.'&amp;uid='.$user_id.'&amp;rating='.$pointer.'\', \'selBlogRatingContent\')';
															$this->getBlogRatingsarray['row'][$jnc]['jnc']	=	$j+1;
															$this->getBlogRatingsarray['row'][$jnc]['mouseOverAnswers']='mouseOverAnswers('.$this->getBlogRatingsarray['row'][$jnc]['jnc'].','.$start.',\''.$this->CFG['site']['url'].'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-ratehover.gif\',\''.$cfg_project_path_relative.'design/templates/'.$this->CFG['html']['template']['default'].'/images/icon-rate.gif\')';
															$pointer++;
															$ratingscnt++;
															$jnc++;
														}
												}
									}
						$sql = 'SELECT COUNT(star_id) as cnt FROM '.$users_stared_blog_table.' WHERE blog_id = '.$this->dbObj->Param($blog_id);
						$stmt = $this->dbObj->Prepare($sql);
						$result = $this->dbObj->Execute($stmt, array($blog_id));
						if (!$result)
								trigger_db_error($this->dbObj);
						// returns record id
						$row = $result->FetchRow();
						$this->getBlogRatingsarray['rating_count']=$row['cnt'];
						$sql = 'SELECT total_stars FROM '.$blog_table.' WHERE blog_id = '.$this->dbObj->Param($blog_id);

						$stmt = $this->dbObj->Prepare($sql);
						$result = $this->dbObj->Execute($stmt, array($blog_id));

						if (!$result)
							trigger_db_error($this->dbObj);

						// returns record id
						$rating = 0;
						if ($result->PO_RecordCount())
							{
							$row = $result->FetchRow();
							$this->getBlogRatingsarray['rating']	=	$row['total_stars'];
						}
					$this->getBlogRatingsarray['user_id']	=	$user_id;
					return $this->getBlogRatingsarray;
			}
		public function postComment()
			{
				$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['blog_comment'].
						' SET blog_id='.$this->dbObj->Param('blog_id').
						', user_id='.$this->dbObj->Param('user_id').
						', comment='.$this->dbObj->Param('comment').
						', date_added=NOW()';
				//set publish comment
				//check the login user is blog owner
				if($this->fields_arr['publish_comments']=='No' && $this->CFG['user']['user_id'] !=$this->fields_arr['user_id'])
					{
						$sql .= ', status=\'ToActivate\'';
					}
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['blog_id'], $this->CFG['user']['user_id'], strip_tags(html_entity_decode($this->fields_arr['comment']), '<br><br />')));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				$next_id = $this->dbObj->Insert_ID();

				if($this->fields_arr['publish_comments']=='Yes' or $this->CFG['user']['user_id'] ==$this->fields_arr['user_id'])
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['blogs'].
								' SET total_comments=total_comments+1'.
								' WHERE blog_id='.$this->dbObj->Param('blog_id').
								' AND accept_comments=\'Yes\'';
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['blog_id']));
						    if (!$rs)
							    trigger_db_error($this->dbObj);
					}
				$this->fields_arr['content_id'] = $next_id;
				$this->addNewVideo();
				$this->addExternalVideo('Blogcomment');
				$this->addNewAudio();
				$this->addExternalAudio('Blogcomment');
			}

		public function addNewVideo()
			{
				if($this->fields_arr['video'])
					{
						#echo 'here'.$this->fields_arr['video'];die();
						$this->fields_arr['video_id'] = $this->insertAnsVideoTable();
						//added code for logging
						if($this->fp)
							{
								$log_str = 'Video Record created : '.$this->fields_arr['video_id']."\r\n";
								$this->writetoTempFile($log_str);
							}
						$video_name = getImageName($this->fields_arr['video_id']);

						$temp_dir = $this->CFG['admin']['ans_videos']['temp_folder'];
						$this->chkAndCreateFolder($temp_dir);
						$temp_file = $temp_dir.$video_name.'.flv';

						$file_name = $this->CFG['admin']['video']['red5_flv_path'].$this->fields_arr['rid'].'.flv';
						copy($file_name, $temp_file);
						unlink($file_name);
						//added code for logging
						if($this->fp)
							{
								$log_str = 'Video stored in temp server : '.$temp_file."\r\n";
								$this->writetoTempFile($log_str);
							}

						$this->changeAnsVideoStatus($this->fields_arr['video_id'], 'No');
						if($this->CFG['admin']['ans_videos']['video_auto_encode'] or 1)
							{
								//added code for logging
								if($this->fp)
									{
										$log_str = 'Calling Video Encode \r\n';
										$this->writetoTempFile($log_str);
									}
								$this->videoEncode($this->fields_arr['video_id']);
							}

						$temp_dir = $this->CFG['admin']['ans_videos']['temp_folder'];
						$temp_file = $temp_dir.$this->fields_arr['rid'].'.flv';
						if(file_exists($temp_file))
							unlink($temp_file);
					}
			}

		public function addNewAudio()
			{
				if($this->fields_arr['audio'])
					{
						$this->fields_arr['audio_id'] = $this->insertAnsAudioTable();

						//added code for logging
						if($this->fp)
							{
								$log_str = 'Audio Record created : '.$this->fields_arr['audio_id']."\r\n";
								$this->writetoTempFile($log_str);
							}
						$audio_name = getImageName($this->fields_arr['audio_id']);

						$temp_dir = $this->CFG['admin']['ans_audios']['temp_folder'];
						$this->chkAndCreateFolder($temp_dir);
						$temp_file = $temp_dir.$audio_name.'.flv';

						$file_name = $this->CFG['admin']['video']['red5_flv_path'].$this->fields_arr['rid'].'AUD.flv';
						copy($file_name, $temp_file);
						unlink($file_name);
						//added code for logging
						if($this->fp)
							{
								$log_str = 'Audio stored in temp server : '.$temp_file."\r\n";
								$this->writetoTempFile($log_str);
							}

						$this->changeAnsAudioStatus($this->fields_arr['audio_id'], 'No');
						if($this->CFG['admin']['ans_audios']['audio_auto_encode'] or 1)
							{
								//added code for logging
								if($this->fp)
									{
										$log_str = 'Calling Audio Encode \r\n';
										$this->writetoTempFile($log_str);
									}
								$this->audioEncode($this->fields_arr['audio_id']);
							}

						$temp_dir = $this->CFG['admin']['ans_audios']['temp_folder'];
						$temp_file = $temp_dir.$this->fields_arr['rid'].'AUD.flv';
						if(file_exists($temp_file))
							unlink($temp_file);
					}

			}
		public function insertAnsVideoTable()
			{
				$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['ans_video'].' SET'.
						' content_id='.$this->dbObj->Param('content_id').','.
						' user_id='.$this->dbObj->Param('user_id').','.
						' video_for=\'Blogcomment\','.
						' video_ext=\'flv\','.
						' date_added=NOW(),'.
						' video_encoded_status=\'Partial\'';

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['content_id'], $this->CFG['user']['user_id']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				return $this->dbObj->Insert_ID();
			}
		public function insertAnsAudioTable()
			{
				$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['ans_audio'].' SET'.
						' content_id='.$this->dbObj->Param('content_id').','.
						' user_id='.$this->dbObj->Param('user_id').','.
						' audio_for=\'Blogcomment\','.
						' audio_ext=\'flv\','.
						' date_added=NOW(),'.
						' audio_encoded_status=\'Partial\'';

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['content_id'], $this->CFG['user']['user_id']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				return $this->dbObj->Insert_ID();
			}
		/**
		 * VideoUpload::changeVideoStatus()
		 *
		 * @param $video_id
		 * @return
		 **/
		public function changeAnsVideoStatus($video_id, $status)
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_video'].' SET'.
						' video_encoded_status='.$this->dbObj->Param('video_encoded_status').
						' WHERE video_id='.$this->dbObj->Param('video_id');

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($status, $video_id));
				    if (!$rs)
					    trigger_db_error($this->dbObj);
			}
		/**
		 * AudioUpload::changeAudioStatus()
		 *
		 * @param $audio_id
		 * @return
		 **/
		public function changeAnsAudioStatus($audio_id, $status)
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_audio'].' SET'.
						' audio_encoded_status='.$this->dbObj->Param('audio_encoded_status').
						' WHERE audio_id='.$this->dbObj->Param('audio_id');

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($status, $audio_id));
				    if (!$rs)
					   trigger_db_error($this->dbObj);
			}
		public function incrementViews()
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['blogs'].
						' SET total_views=total_views+1'.
						' WHERE blog_id='.$this->dbObj->Param('blog_id');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['blog_id']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);
			}
		/**
		 * ViewVideo::updateCommentAndVideoTable()
		 *
		 * @return
		 **/
		public function updateCommentAndVideoTable()
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['blog_comment'].
						' SET comment='.$this->dbObj->Param('comment').
						' WHERE comment_id='.$this->dbObj->Param('comment_id');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['f'], $this->fields_arr['comment_id']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				echo $this->getFormField('comment_id');
				echo '***--***!!!';
				echo $this->getFormField('f');
			}
		/**
		 * publish the comment
		 */
		public function publishComment()
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['blog_comment'].
						' SET status=\'Active\' WHERE comment_id='.$this->fields_arr['comment_id'];
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				    if (!$rs)
					    trigger_db_error($this->dbObj);


				$sql = 'UPDATE '.$this->CFG['db']['tbl']['blogs'].
								' SET total_comments=total_comments+1'.
								' WHERE blog_id='.$this->dbObj->Param('blog_id').
								' AND accept_comments=\'Yes\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['blog_id']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				//COMMENT SENTER MAIL
				$sql = 'SELECT `user_id`,comment,blog_id
						FROM `blog_comment`
						WHERE comment_id='.$this->fields_arr['comment_id'];
				$rs = $this->dbObj->Execute($sql);
				if (!$rs)
		        	trigger_db_error($this->dbObj);

				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow())
							{
								$this->sendPublishedMailAlert($row['user_id'],'Comment',$this->fields_arr['blog_id'],$row['comment']);
							}
					}
			}
		/**
		 * publish sent mail;
		 */
		 public function sendPublishedMailAlert($userid, $mailtype, $blog_id, $content_description)
			{
				$select_query = 'SELECT `user_id`,subject,seo_title,message
						         FROM `blogs`
								 WHERE `blog_id`=('.$blog_id.')';
				$stmt = $this->dbObj->Prepare($select_query);
				$rs = $this->dbObj->Execute($stmt);
				    if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow())
							{
								$mail_content_seo = $row['seo_title'];
								$mail_content = $row['subject'];
							}
					}
				$toDetails = $this->getUserDetailsFromUsersTable($this->CFG['db']['tbl']['users'], $userid);
				$site_link = "<a target=\"_blank\" href=\"".URL($this->CFG['site']['url'])."\">".URL($this->CFG['site']['url'])."</a>";
				if($mailtype == 'Comment')
					{
						$url_link = getBlogUrl('blogcomment','?title='.$mail_content_seo, $mail_content_seo.'/','root');
						$comment_link = "<a target=\"_blank\" href=\"".$url_link."\">".$mail_content."</a>";
						$subject = $this->getMailContent($this->LANG['comment_publish_subject'], array('VAR_USERNAME'=>$toDetails['display_name'], 'VAR_SITENAME'=>$this->CFG['site']['name'], 'VAR_DESCRIPTION_OF_COMMENT'=>$content_description, 'VAR_COMMENT'=>$comment_link, 'VAR_LINK'=>$site_link));
						$content = $this->getMailContent($this->LANG['comment_publish_message'], array('VAR_USERNAME'=>$toDetails['display_name'], 'VAR_SITENAME'=>$this->CFG['site']['name'], 'VAR_DESCRIPTION_OF_COMMENT'=>$content_description, 'VAR_COMMENT'=>$comment_link, 'VAR_LINK'=>$site_link));
					}

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

		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());
			}

		public function deleteComment()
			{
				$sql = 'DELETE FROM '.$this->CFG['db']['tbl']['blog_comment'].
						' WHERE comment_id='.$this->dbObj->Param('comment_id');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['comment_id']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				if($this->dbObj->Affected_Rows())
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['blogs'].
								' SET total_comments = total_comments-1'.
								' WHERE blog_id='.$this->dbObj->Param('blog_id');
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['blog_id']));
						    if (!$rs)
							    trigger_db_error($this->dbObj);
					}

				$sql = 'DELETE FROM '.$this->CFG['db']['tbl']['blog_comment'].
						' WHERE main_comment_id='.$this->dbObj->Param('comment_id');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['comment_id']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function deleteBlog()
			{
				$blog_ids = $this->fields_arr['blog_id'];

				$sql = 'DELETE FROM '.$this->CFG['db']['tbl']['blogs'].
						' WHERE blog_id='.$blog_ids;
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				$sql = 'DELETE FROM '.$this->CFG['db']['tbl']['blog_comment'].
						' WHERE blog_id='.$blog_ids;
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				    if (!$rs)
					    trigger_db_error($this->dbObj);

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

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['blog_id']));
				if (!$rs)
					    trigger_db_error($this->dbObj);
		    }

		public function updateAbuseBlog()
			{
				$sql = 'SELECT abuse_id FROM '.$this->CFG['db']['tbl']['abuse_blog'].
						' WHERE blog_id='.$this->dbObj->Param('blog_id').
						' AND reported_by='.$this->dbObj->Param('reported_by');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['blog_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_blog'].
								' SET blog_id='.$this->dbObj->Param('blog_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['blog_id'],
																 $this->CFG['user']['user_id'],
																 $this->fields_arr['reason']));
						if (!$rs)
						        trigger_db_error($this->dbObj);

						if ($this->dbObj->Affected_Rows())
							{
								$this->updateBlogAbuseCount();
							}
					}
			}
		public function addReply()
			{
				$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['blog_comment'].
						' SET blog_id='.$this->dbObj->Param('blog_id').
						', user_id='.$this->dbObj->Param('user_id').
						', comment='.$this->dbObj->Param('user_reply').
						', main_comment_id='.$this->dbObj->Param('comment_id').
						', date_added=NOW()';

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['blog_id'], $this->CFG['user']['user_id'], strip_tags(html_entity_decode($this->fields_arr['user_reply']), '<br><br />'), $this->fields_arr['comment_id']));

				    if (!$rs)
					    trigger_db_error($this->dbObj);
			}
		public function fetchReply($mainComment_id)
			{
				if (!$this->repliesArray)
					return ;
				$fetchReply_arr=array();
				$inc=0;
				foreach($this->repliesArray as $row1)
					{
						$fetchReply_arr[$inc]['record']	=	$row1;
						$fetchReply_arr[$inc]['date_added']	=	$row1['date_added'] = ($row1['date_added'] != '') ? $this->getTimeDiffernceFormat($row1['date_added']) : '';
						$fetchReply_arr[$inc]['userDetails']	=	$userDetails = $this->getUserDetailsFromUsersTable($this->CFG['db']['tbl']['users'], $row1['user_id']);
						$fetchReply_arr[$inc]['user_comment']	=	nl2br(wordWrapManual($row1['comment'], $this->CFG['admin']['blog']['line_length']));
						$fetchReply_arr[$inc]['myanswers_url']	=	getMemberUrl($userDetails['user_id'], $userDetails['name']);
						$name = $userDetails['display_name'];
						$fetchReply_arr[$inc]['strip_name']	=	stripString($name, $this->CFG['username']['short_length']);
						$fetchReply_arr[$inc]['usr_chk']	=	false;
						if ($this->CFG['user']['user_id']==$row1['user_id'] OR $this->CFG['user']['user_id']==$this->fields_arr['user_id'])
							$fetchReply_arr[$inc]['usr_chk']	=	true;
						$fetchReply_arr[$inc]['blogcomment_url']	=	getAnovaUrl('blogcomment','?title='.$this->fields_arr['seo_title'], $this->fields_arr['seo_title'].'/');
						$fetchReply_arr[$inc]['onclick_confirm']='return Confirmation(\'selDelMsgConfirm\', \'msgConfirmform\', Array(\'act\',\'comment_id\', \'main_comment_id\',\'msgConfirmText\'), Array(\'deletereplies\',\''.$row1['comment_id'].'\', \''.$row1['main_comment_id'].'\', \''.$this->LANG['blogcomment_confirm_reply_message'].'\'), Array(\'value\',\'value\',\'value\',\'innerHTML\'), -25, -500)';
						$fetchReply_arr[$inc]['userDetails']['image_id']	=	$userDetails['image_id'] = 'reply'.$mainComment_id.'_';
						$inc++;
						$name = $userDetails['display_name'];
					}
				return $fetchReply_arr;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function hasReply($mainComment_id)
			{
				$sql = 'SELECT comment_id, blog_id, user_id, comment, main_comment_id, UNIX_TIMESTAMP(date_added) AS date_added'.
						' FROM '.$this->CFG['db']['tbl']['blog_comment'].' AS bc'.
						' WHERE main_comment_id='.$this->dbObj->Param('comment_id');
				if ($this->CFG['admin']['ignore_user'])
					{
						$sql .= ' AND NOT EXISTS (SELECT 1 FROM '.$this->CFG['db']['tbl']['user_ignored'].' AS ui WHERE ui.user_id='.$this->CFG['user']['user_id'].' AND ui.ignored_id=bc.user_id)';
					}
				$sql .= ' ORDER BY comment_id DESC';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($mainComment_id));
			    if (!$rs)
				    trigger_db_error($this->dbObj);

				$this->repliesArray = array();
				while($row = $rs->FetchRow())
					{
						$this->repliesArray[] = $row;
					}
				return $this->repliesArray;
			}
		public function declareBlogValues()
			{
				$manageBlogs_arr = array();

				$manageBlogs_arr['style_add_video'] = $manageBlogs_arr['style_add_external_video']= '';
				$manageBlogs_arr['style_delete_video'] = $manageBlogs_arr['style_delete_external_video']= 'style="display:none"';
				$manageBlogs_arr['style_preview_video'] = $manageBlogs_arr['style_preview_external_video']= 'style="display:none"';
				$manageBlogs_arr['video_preview_url'] = $manageBlogs_arr['video_default_preview_url'] = getAnovaUrl('anspreviewvideo', '?pg=Blogcomment_'.$this->getFormField('rid'), '?pg=Blogcomment_'.$this->getFormField('rid'), 'members');
				$manageBlogs_arr['video_not_encoded_info'] = $this->LANG['video_not_encoded_info'];
				$manageBlogs_arr['external_video_onclick'] = 'return showVideoExternalPreview();';
				$manageBlogs_arr['external_video_preview_url'] = $_SERVER['REQUEST_URI'];

				if($this->fields_arr['video'] or $this->fields_arr['video_id'])
					{
						$manageBlogs_arr['style_delete_video'] = '';
						$manageBlogs_arr['style_preview_video'] = '';
						$manageBlogs_arr['style_add_video'] = 'style="display:none"';

						if ($this->fields_arr['video_id'])
							$manageBlogs_arr['video_preview_url'] = getAnovaUrl('ansviewvideo', '?pg=Blogcomment_'.$this->getFormField('video_id'), '?pg=Blogcomment_'.$this->getFormField('video_id'));
						if ($this->fields_arr['video'])
							$manageBlogs_arr['video_preview_url'] = getAnovaUrl('anspreviewvideo', '?pg=Blogcomment_'.$this->getFormField('video'), '?pg=Blogcomment_'.$this->getFormField('video'), 'members');
					}
				if($this->fields_arr['video_external_flv_url'] or $this->fields_arr['file_extern'] or $this->fields_arr['external_video_id'])
					{
						$manageBlogs_arr['style_delete_external_video'] = '';
						$manageBlogs_arr['style_preview_external_video'] = '';
						$manageBlogs_arr['style_add_external_video'] = 'style="display:none"';

						if (!$this->fields_arr['video_external_flv_url'] AND !$this->fields_arr['file_extern'])
							{
								if ($this->fields_arr['external_video_id'] AND $external_video_details = $this->getExternalVideoDetails($this->fields_arr['external_video_id']))
									{
										if ($external_video_details['video_status'] == 'Ok' AND $external_video_details['video_encoded_status'] == 'Yes')
											{
												$manageBlogs_arr['external_video_onclick'] = getBrowser('video');
												$manageBlogs_arr['external_video_preview_url'] = getAnovaUrl('ansviewvideo', '?pg=Blogcomment_'.$this->getFormField('external_video_id'), '?pg=Blogcomment_'.$this->getFormField('external_video_id'));
											}
									}
							}
					}

				$manageBlogs_arr['style_add_audio'] = $manageBlogs_arr['style_add_external_audio']= '';
				$manageBlogs_arr['style_delete_audio'] = $manageBlogs_arr['style_delete_external_audio']= 'style="display:none"';
				$manageBlogs_arr['style_preview_audio'] = $manageBlogs_arr['style_preview_external_audio']= 'style="display:none"';
				$manageBlogs_arr['audio_preview_url'] = $manageBlogs_arr['audio_default_preview_url'] = getAnovaUrl('anspreviewaudio', '?pg=Blogcomment_'.$this->getFormField('rid'), '?pg=Blogcomment_'.$this->getFormField('rid'));
				$manageBlogs_arr['audio_not_encoded_info'] = $this->LANG['audio_not_encoded_info'];
				$manageBlogs_arr['external_audio_onclick'] = 'return showAudioExternalPreview();';
				$manageBlogs_arr['external_audio_preview_url'] = $_SERVER['REQUEST_URI'];

				if($this->fields_arr['audio'] or $this->fields_arr['audio_id'])
					{
						$manageBlogs_arr['style_delete_audio'] = '';
						$manageBlogs_arr['style_preview_audio'] = '';
						$manageBlogs_arr['style_add_audio'] = 'style="display:none"';
						if ($this->fields_arr['audio_id'])
							$manageBlogs_arr['audio_preview_url'] = getAnovaUrl('ansviewaudio', '?pg=Blogcomment_'.$this->getFormField('audio_id'), '?pg=Blogcomment_'.$this->getFormField('audio_id'));
						if ($this->fields_arr['audio'])
							$manageBlogs_arr['audio_preview_url'] = getAnovaUrl('anspreviewaudio', '?pg=Blogcomment_'.$this->getFormField('audio'), '?pg=Blogcomment_'.$this->getFormField('audio'));
					}
				if($this->fields_arr['audio_external_url'] or $this->fields_arr['audio_extern'] or $this->fields_arr['external_audio_id'])
					{
						$manageBlogs_arr['style_delete_external_audio'] = '';
						$manageBlogs_arr['style_preview_external_audio'] = '';
						$manageBlogs_arr['style_add_external_audio'] = 'style="display:none"';

						if (!$this->fields_arr['audio_external_url'] AND !$this->fields_arr['audio_extern'])
							{
								if ($this->fields_arr['external_audio_id'] AND $external_audio_details = $this->getExternalAudioDetails($this->fields_arr['external_audio_id']))
									{
										if ($external_audio_details['audio_status'] == 'Ok' AND $external_audio_details['audio_encoded_status'] == 'Yes')
											{
												$manageBlogs_arr['external_audio_onclick'] = getBrowser('external_audio_preview');
												$manageBlogs_arr['external_audio_preview_url'] = getAnovaUrl('ansviewaudio', '?pg=Blogcomment_'.$this->getFormField('external_audio_id'), '?pg=Blogcomment_'.$this->getFormField('external_audio_id'));
											}
									}
							}
					}

				if(chkVideoModuleAllowed('blogcomment'))
					{
						 $manageBlogs_arr['video_upload_url'] = getAnovaUrl('videoupload', '?rid='.$this->fields_arr['rid'], '?rid='.$this->fields_arr['rid']);
					}
				if(chkExternalVideoModuleAllowed('blogcomment'))
					{
						 $manageBlogs_arr['external_video_upload_url'] = getAnovaUrl('externalvideoupload', '?rid='.$this->fields_arr['rid'], '?rid='.$this->fields_arr['rid']);
					}

				if(chkAudioModuleAllowed('blogcomment'))
					{
						$manageBlogs_arr['audio_upload_url'] = getAnovaUrl('audioupload', '?rid='.$this->fields_arr['rid'].'AUD', '?rid='.$this->fields_arr['rid'].'AUD');
					}
				if(chkExternalAudioModuleAllowed('blogcomment'))
					{
						 $manageBlogs_arr['external_audio_upload_url'] = getAnovaUrl('externalaudioupload',  '?rid='.$this->fields_arr['rid'], '?rid='.$this->fields_arr['rid']);
					}

				return $manageBlogs_arr;
			}
		/**
		 * bloglist::generateRandomId()
		 *
		 * @return
		 */
		public function generateRandomId()
			{
				$time = time();
				$this->fields_arr['rid'] = md5($time);
			}

	}
//--------------------Code begins-------------->>>>>//
$blogList = new blogList();
if(!chkIsAllowedModule(array('blog')))
	Redirect2URL(getUrl($CFG['redirect']['dsabled_module_url']['file_name']));
//set blocks
$blogList->setPageBlockNames(array('selCommentListBlock', 'selAcceptCommentBlock', 'selBlogDetails'));
$blogList->setFormField('from', '');
$blogList->setFormField('video', '');
$blogList->setFormField('video_id', '');
$blogList->setFormField('audio', '');
$blogList->setFormField('audio_id', '');
$blogList->setFormField('external_video_id', '');
$blogList->setFormField('external_audio_id', '');
$blogList->setFormField('video_external_flv_url', '');
$blogList->setFormField('flv_upload_type', '');
$blogList->setFormField('file_extern', '');
$blogList->setFormField('audio_external_url', '');
$blogList->setFormField('audio_extern', '');
$blogList->setFormField('rid', '');
$blogList->setFormField('f', '');
$blogList->setFormField('msg', '');
$blogList->setFormField('act', '');
$blogList->setFormField('succ', '');
$blogList->setFormField('type', '');
$blogList->setFormField('page', '');
$blogList->setFormField('comment_id', '');
$blogList->setFormField('replySpanIDId', '');
$blogList->setFormField('blog_id', '');
$blogList->setFormField('user_reply', '');
$blogList->setFormField('selReplyId', '');
$blogList->setFormField('main_comment_id', '');
$blogList->setFormField('action', '');
$blogList->setFormField('post', '');
$blogList->setFormField('seo_title', '');

/*********** Page Navigation Start *********/
$blogList->setFormField('orderby_field', 'comment_id');
$blogList->setFormField('orderby', 'DESC');
$blogList->setFormField('start', '0');
$blogList->setFormField('numpg', $CFG['data_tbl']['numpg']);
$blogList->setMinRecordSelectLimit(2);
$blogList->setMaxRecordSelectLimit($CFG['data_tbl']['max_record_select_limit']);
$blogList->setNumPerPageListArr($CFG['data_tbl']['numperpage_list_arr']);
$blogList->setTableNames(array($CFG['db']['tbl']['blog_comment'].' AS bc'));
$blogList->setReturnColumns(array('comment_id', 'blog_id', 'bc.user_id', 'comment','status','TIME_TO_SEC(TIMEDIFF(NOW(), date_added)) AS date_edit', 'UNIX_TIMESTAMP(date_added) AS date_added', 'video_id', 'audio_id', 'external_video_id', 'external_audio_id'));
/************ page Navigation stop *************/
//set Form Fields
$blogList->resetFieldsArray();
$blogList->sanitizeFormInputs($_REQUEST);
$title = $LANG['blog_cmd_title'];
$blogList->fp = false;
if(!$blogList->getFormField('rid'))
	$blogList->generateRandomId();
if (!isMember() && $blogList->getFormField('post'))
	{
		$_SESSION['url'] = getBlogUrl('blogcomment', '?title='.$blogList->getFormField('title'), $blogList->getFormField('title').'/');
		$_SESSION['login_error'] = 'login_err_authorization_required';
		Redirect2URL($CFG['auth']['login_url']['url']);
	}
$blogList->showVideoAudio = false;
if(($CFG['admin']['module']['video_audio_blogsforum']) && (chkVideoModuleAllowed('blogcomment') || chkExternalVideoModuleAllowed('blogcomment') || chkAudioModuleAllowed('blogcomment') || chkExternalAudioModuleAllowed('blogcomment')))
	{
		$blogList->showVideoAudio = true;
	}
//show default pages..
if($blogList->populateBlogsValue())
	{
		if($CFG['html']['meta']['appendable'])
			{
				$blogList->appendMetaDetails(html_entity_decode($blogList->getFormField('subject')), $blogList->getBlogCategory($blogList->getFormField('blog_category_id')).' - ');
			}

		$blogList->ajaxCommonVar['action']='';
		if ($blogList->isFormPOSTed($_REQUEST, 'showOptionToAnswer'))
			{
				#die('here');
				ob_start();
				$blogList->ajaxCommonVar['action']	=	'showOptionToAnswer';
				$blogList->showOptionToAnswer['is_member']=true;
				if (!isMember())
					{
						$blogList->showOptionToAnswer['is_member']=false;
						$_SESSION['url'] = getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
						echo 'Session Expired. <a href="'.$CFG['auth']['login_url']['url'].'?r">Login to continue..!</a>';
						die();
					}
				$blogList->showOptionToAnswer['comment_id']	=	$blogList->getFormField('comment_id');
				$blogList->showOptionToAnswer['blog_id']	=	$blogList->getFormField('blog_id');
				$blogList->showOptionToAnswer['selReplyId']	=	$blogList->getFormField('selReplyId');
				$blogList->showOptionToAnswer['blogComment_url']	=	getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
				$blogList->showOptionToAnswer['blogComment_pars']	=	'blog_id='. $blogList->getFormField('blog_id').'&amp;ajax_page=true&amp;cancelOptionToAnswer=1&amp;comment_id='.$blogList->getFormField('comment_id').'&amp;selReplyId='.$blogList->getFormField('selReplyId');
				$blogList->showOptionToAnswer['blogComment_url1']	=	getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title').'&blog_id='.$blogList->getFormField('blog_id'), $blogList->getFormField('seo_title').'/?blog_id='.$blogList->getFormField('blog_id'));
				$blogList->showOptionToAnswer['blogComment_pars1']	=	'&amp;ajax_page=true&amp;postYourAnswer=1&amp;comment_id='.$blogList->getFormField('comment_id').'&amp;selReplyId='.$blogList->getFormField('selReplyId');
				$blogList->showOptionToAnswer['blogComment_pars2']	=	'postans'.$blogList->getFormField('comment_id');
			}
		 if ($blogList->isFormPOSTed($_REQUEST, 'cancelOptionToAnswer'))
			{
				ob_start();
				$blogList->ajaxCommonVar['action']	=	'cancelOptionToAnswer';
				$blogList->cancelOptionToAnswer['is_member']=true;
				if (!isMember())
					{
						$_SESSION['url'] = getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
						echo 'Session Expired. <a href="'.$CFG['auth']['login_url']['url'].'?r">Login to continue..!</a>';
						$blogList->cancelOptionToAnswer['is_member']=false;
						die();
					}
				$blogList->cancelOptionToAnswer['replySpanIDId']	= $blogList->getFormField('replySpanIDId');
				$blogList->cancelOptionToAnswer['comment_id']	=	$blogList->getFormField('comment_id');
				$blogList->cancelOptionToAnswer['viewSpanId']	=	'viewSpanId'.$blogList->getFormField('comment_id');
				$blogList->cancelOptionToAnswer['selViewReplyId']	= 'selViewReplyId'.$blogList->getFormField('comment_id');
				if ($blogList->hasReply($blogList->getFormField('comment_id')))
					{
						$blogList->cancelOptionToAnswer['fetchReply']	=	$blogList->fetchReply($blogList->getFormField('comment_id'));
					}
			}
		if ($blogList->isFormPOSTed($_REQUEST, 'deleteComments'))
			{
				ob_start();
				if (!isMember())
					{
						$_SESSION['url'] = getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
						echo 'Session Expired. <a href="'.$CFG['auth']['login_url']['url'].'?r">Login to continue..!</a>';
						die();
					}
				$blogList->ajaxCommonVar['action']	=	'deleteComments';
				$blogList->deleteComments['is_member']=true;
				if (!isMember())
					{
						$blogList->deleteComments['is_member']=false;
						die();
					}
				$blogList->deleteComments['blog_id']	=	$blogList->getFormField('blog_id');
				$blogList->deleteComments['comment_id']	=	$blogList->getFormField('comment_id');
				$blogList->deleteComments['main_comment_id']	=	$blogList->getFormField('main_comment_id');
				$blogList->deleteComments['action1']	=	$blogList->getFormField('action');
				if ($blogList->getFormField('blog_id') AND $blogList->getFormField('comment_id') AND $blogList->getFormField('main_comment_id'))
				{
					$blogList->deleteReply();
					$blogList->deleteComments['selViewReplyId']	= 'selViewReplyId'.$blogList->getFormField('comment_id');
					if ($blogList->hasReply($blogList->getFormField('main_comment_id')))
						{

							$blogList->deleteComments['fetchReply']=$blogList->fetchReply($blogList->getFormField('comment_id'));
						}
				}
			}
		if ($blogList->isFormPOSTed($_REQUEST, 'viewOptionToAnswer'))
			{
						ob_start();
						$replySpanIDId = $blogList->getFormField('replySpanIDId');
						$ques_id = $blogList->getFormField('comment_id');

						$blogList->fetchReply($ques_id);
						die();
			}
		if ($blogList->isFormPOSTed($_REQUEST, 'postYourAnswer'))
			{
				ob_start();
				if (!isMember())
					{
						$_SESSION['url'] = getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
						echo 'Session Expired. <a href="'.$CFG['auth']['login_url']['url'].'?r">Login to continue..!</a>';
						die();
					}
				$blogList->ajaxCommonVar['action']	=	'postYourAnswer';
				if ($blogList->getFormField('user_reply'))
					{
						$comment_id = $blogList->getFormField('comment_id');
						$user_reply = $blogList->getFormField('user_reply');
						$blog_id = $blogList->getFormField('blog_id');
						$viewSpanId = 'viewSpanId'.$blogList->getFormField('comment_id');
						$selViewReplyId = 'selViewReplyId'.$blogList->getFormField('comment_id');
						$blogList->addReply();
						if ($blogList->hasReply($blogList->getFormField('comment_id')))
							{
								$blogList->postYourAnswer['comment_id']='viewSpanId'.$blogList->getFormField('comment_id');
								$blogList->postYourAnswer['user_reply']='viewSpanId'.$blogList->getFormField('user_reply');
								$blogList->postYourAnswer['blog_id']='viewSpanId'.$blogList->getFormField('blog_id');
								$blogList->postYourAnswer['viewSpanId']='viewSpanId'.$blogList->getFormField('comment_id');
								$blogList->postYourAnswer['selViewReplyId']='selViewReplyId'.$blogList->getFormField('comment_id');
								$blogList->postYourAnswer['fetchReply']	=	$blogList->fetchReply($blogList->getFormField('comment_id'));
							}
					}
			}
		if ($blogList->isFormPOSTed($_POST, 'post_comment'))
			{
				if(chkVideoModuleAllowed('blogcomment'))
					$blogList->chkIsValidCaptureVideoFile();
				if(chkAudioModuleAllowed('blogcomment'))
					$blogList->chkIsValidCaptureAudioFile();

				$blogList->chkIsNotEmpty('comment', $LANG['err_tip_compulsory']);
				if ($blogList->isValidFormInputs() && trim($blogList->getFormField('comment')))
					{
						if ($CFG['debug']['store_log'])
							{
								$blogList->createErrorLogFile('blogcomment');
							}
						$blogList->postComment();
						if ($CFG['debug']['store_log'])
							{
								$blogList->closeErrorLogFile();
							}
						if($blogList->getFormField('publish_comments') == 'Yes' or $blogList->getFormField('user_id') == $CFG['user']['user_id'])
							$blogList->setCommonSuccessMsg($blogList->LANG['blog_cmd_comment_post_success']);
						else
							$blogList->setCommonSuccessMsg($blogList->LANG['blog_cmd_comment_post_publish_success']);
						$blogList->setPageBlockShow('block_msg_form_success');
						Redirect2Url(getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title').'&msg=add', $blogList->getFormField('seo_title').'/?msg=add'));
					}
			}
		if(isAjax())
			{
				if($blogList->getFormField('act')=='postcomment')
					{
						if (!isMember())
							{
								$_SESSION['url'] = getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
								echo 'Session Expired. <a href="'.$CFG['auth']['login_url']['url'].'?r">Login to continue..!</a>';
								die();
							}
						$blogList->setFormField('comment', strip_tags(html_entity_decode($blogList->getFormField('comment')), '<a><i><br><br />'));
						$blogList->msg = $LANG['blog_cmd_comment_post_failure'];
						if (trim($blogList->getFormField('comment')))
							{
								$blogList->postComment();
								if($blogList->getFormField('publish_comments') == 'Yes' or $blogList->getFormField('user_id') == $CFG['user']['user_id'])
									$blogList->setCommonSuccessMsg($blogList->LANG['blog_cmd_comment_post_success']);
								else
									$blogList->setCommonSuccessMsg($blogList->LANG['blog_cmd_comment_post_publish_success']);
								$blogList->setPageBlockShow('block_msg_form_success');
							}

						$blogList->setPageBlockShow('selAcceptCommentBlock');
						$blogList->selCommentListBlock['showCommentsList']=$blogList->showCommentsList();
						$blogList->paging_arr = array('title');
						$smartyObj->assign('smarty_paging_list', $blogList->populatePageLinksGET($blogList->getFormField('start'),$blogList->paging_arr));
						$blogList->selCommentListBlock['login_lightwindow'] = $blogList->CFG['site']['url'].'login.php?light_url='.getBlogUrl('blogcomment', '?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
						$blogList->msgConfirmForm_hidden_arr = array('start', 'blog_id');
						$blogList->includeAjaxHeader();
						setTemplateFolder('general/', $CFG['admin']['index']['blog_module']);
						$smartyObj->display('blogCommentList.tpl');
						$blogList->includeAjaxFooter();
						exit;
					}
				$blogList->includeAjaxHeader();
				setTemplateFolder('general/', $CFG['admin']['index']['blog_module']);
				$smartyObj->display('blogCommentAJAX.tpl');
				$blogList->includeAjaxFooter();
				exit;
			}
		else
			{
				if($blogList->isFormPOSTed($_POST, 'confirm_delete'))
					{
						if (!isMember())
							{
								$_SESSION['url'] = getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
								$_SESSION['login_error'] = 'login_err_authorization_required';
								Redirect2URL(getUrl('login'));
							}
						elseif($blogList->getFormField('act') == 'publishcomments')
							{
								$blogList->publishComment();
								Redirect2Url(getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title').'&msg=pub', $blogList->getFormField('seo_title').'/?msg=pub'));
							}
						elseif($blogList->getFormField('act') == 'deletecomments')
							{
								$blogList->deleteComment();
								Redirect2Url(getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title').'&msg=del', $blogList->getFormField('seo_title').'/?msg=del'));
							}
						elseif($blogList->getFormField('act') == 'deleteblog')
							{
								$blogList->deleteBlog();
								Redirect2Url(getBlogUrl('blogs', '?succ=deleted', '?succ=deleted'));
							}
					}

				if($blogList->isFormGETed($_GET, 'msg'))
					{
						if($blogList->getFormField('msg')=='pub' AND $blogList->isValidFormInputs())
							{
								$blogList->setPageBlockShow('block_msg_form_success');
								$blogList->setCommonSuccessMsg($blogList->LANG['blog_cmd_comment_publish_success']);
							}
						if($blogList->getFormField('msg')=='add' AND $blogList->isValidFormInputs())
							{
								$blogList->setPageBlockShow('block_msg_form_success');
								$blogList->setCommonSuccessMsg($blogList->LANG['blog_cmd_comment_post_success']);
							}
						if($blogList->getFormField('msg')=='del' AND $blogList->isValidFormInputs())
							{
								$blogList->setPageBlockShow('block_msg_form_success');
								$blogList->setCommonSuccessMsg($blogList->LANG['blog_cmd_success_deleted']);

							}
						if($blogList->getFormField('msg')=='edited' AND $blogList->isValidFormInputs())
							{
								$blogList->setPageBlockShow('block_msg_form_success');
								$blogList->setCommonSuccessMsg($blogList->LANG['blog_edited_successfully']);
							}
					}
				$blogList->incrementViews();
				$blogList->setPageBlockShow('selBlogDetails');
				$blogList->setPageBlockShow('selCommentListBlock');
				$LANG['blog_cmd_title'] = wordWrapManual($blogList->getFormField('subject'), $CFG['admin']['blog']['line_length']);
				$title .= ' - '.$blogList->getFormField('subject');
				if($blogList->isFormPOSTed($_POST, 'confirm_action'))
					{
						$blogList->chkIsNotEmpty('reason', $LANG['err_tip_compulsory']);
						if ($blogList->isValidFormInputs())
							{
								$blogList->updateAbuseBlog();
								$blogList->setPageBlockShow('block_msg_form_error');
								$blogList->setCommonErrorMsg($LANG['blog_cmd_abused_successfully']);
							}
							else
								{
									$blogList->setCommonErrorMsg($LANG['blog_cmd_err_msg_reason_empty']);
									$blogList->setPageBlockShow('block_msg_form_error');
								}
					}
			}
		}
	else
		{
			$blogList->setCommonErrorMsg($LANG['blog_cmd_invalid_blogs_id']);
			$blogList->setPageBlockShow('block_msg_form_error');
		}
//<<<<--------------------Code Ends----------------------//
//--------------------Page block templates begins-------------------->>>>>//
if(!isAjax())
	{
		$CFG['site']['title'] = $title.' - '.$CFG['site']['title'];
		$blogList->blog_comment_arr['blog_cmd_title']=$LANG['blog_cmd_title'];
		$blogList->blog_comment_arr['login_lightwindow_url']=$CFG['site']['url'].'login.php';
		$blogList->blog_comment_arr['manageblog_url_mem']=getBlogUrl('manageblog', '', '', 'members');
		$blogList->blog_comment_arr['manageblog_url_add']=getBlogUrl('manageblog','?add', '?add', 'members');
		$blogList->blog_comment_arr['manageblog_url_mem_add']=getBlogUrl('manageblog','?add', 'add/', 'members');
		$blogList->blog_comment_arr['blogcomment_url']=getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
		$blogList->blog_comment_arr['blogcomment_del_url']=getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/','members');
		$blogList->blog_comment_arr['blogcomment_del_url_pra']='blog_id='.$blogList->getFormField('blog_id').'&amp;ajax_page=true&amp;deleteComments=1';
		if($blogList->isShowPageBlock('selBlogDetails'))
			{
				$blogList->selBlogDetails['displayBlog']=$blogList->displayBlog();
			}
		if($blogList->isShowPageBlock('selCommentListBlock'))
			{
				//comments List array...
				$blogList->selCommentListBlock['showCommentsList']=$blogList->showCommentsList();
				$blogList->selCommentListBlock['login_lightwindow']=$blogList->CFG['site']['url'].'login.php?light_url='.getBlogUrl('blogcomment','?title='.$blogList->getFormField('seo_title'), $blogList->getFormField('seo_title').'/');
				$blogList->paging_arr = array('title');
				$smartyObj->assign('smarty_paging_list', $blogList->populatePageLinksGET($blogList->getFormField('start'),$blogList->paging_arr));
				//Add comments array...

				if($CFG['feature']['rewrite_mode'] == 'normal')
				{
					$blogList->selCommentListBlock['url']	=	getBlogUrl('blogcomment','','','members');
					$blogList->selCommentListBlock['pars']	=	'title='.$blogList->getFormField('seo_title').'&amp;ajax_page=true&amp;act=postcomment';
				}
				else
				{
					$blogList->selCommentListBlock['url']	=	getBlogUrl('blogcomment','',$blogList->getFormField('seo_title').'/','members');
					$blogList->selCommentListBlock['pars']	=	'ajax_page=true&amp;act=postcomment';
				}
						$blogList->msgConfirmForm_hidden_arr = array('start','blog_id');
			}
}
$blogList->blogsEditBlock['manageBlogs_arr'] = $blogList->declareBlogValues();
$blogList->blogsEditBlock['populateHidden'] = array('start', 'blog_id', 'from', 'rid', 'video', 'video_external_flv_url', 'flv_upload_type', 'file_extern', 'audio', 'audio_external_url', 'audio_extern', 'video_id', 'external_video_id', 'audio_id', 'external_audio_id');

//include the header file
$blogList->includeHeader();
//include the content of the page
setTemplateFolder('general/', $CFG['admin']['index']['blog_module']);
$smartyObj->display('blogComment.tpl');
$video_format_arr = '';
$audio_format_arr = '';
if(isset($CFG['admin']['ans_videos']['format_arr']) && $CFG['admin']['ans_videos']['format_arr'])
	$video_format_arr = implode(',', $CFG['admin']['ans_videos']['format_arr']);
if(isset($CFG['admin']['ans_audios']['format_arr']) && $CFG['admin']['ans_audios']['format_arr'])
	$audio_format_arr = implode(',', $CFG['admin']['ans_audios']['format_arr']);
//includ the footer of the page
?>
<script type="text/javascript">
	<?php
	 if($blogList->isShowPageBlock('selAcceptCommentBlock') AND isMember() AND $blogList->isAllowedToAsk())
		{ ?>
			//needLiveValidation('comment',Array('Presence'));
  <?php } ?>
</script>
<script language="javascript" type="text/javascript" src="<?php echo $CFG['site']['url'].$CFG['admin']['index']['blog_module'];?>/js/blogs.js"></script>
        <script language="javascript" type="text/javascript">
            var site_url = '<?php echo $CFG['site']['url'];?>';
            var block_arr = new Array('selEditPhotoComments','selMsgAbuseConfirm', 'selMsgConfirm', 'selDelMsgConfirm');
            var replace_url = '<?php echo getUrl('login', '', '', 'root');?>';
            var deleteConfirmation = "<?php echo $LANG['blog_cmd_delete_confirmation'];?>";
            var total_comments = 10;
            var minimum_counts = 10000;
            var MAX_comment_limit = '<?php echo $CFG['admin']['comment']['limit'];?>';
</script>
<script language="javascript" type="text/javascript">
var LANG_seconds = '<?php echo $LANG['list_seconds']?>';
var LANG_del_msg = '<?php echo $LANG['blog_cmd_comment_deleted_successfully']?>';
var max_timer = '<?php echo $CFG['admin']['blogs']['comment_edit_allowed_time'];?>';
//changeTimer();
var dontUse = 0;

function toggleComments(spanObj, commentID){
	var moreObj = 'commentsmore'+commentID;
	var lessObj = 'commentsless'+commentID;

	if ($(lessObj).style.display == 'none'){
		$(moreObj).hide();
		$(lessObj).show();
	}else{
		$(moreObj).show();
		$(lessObj).hide();
	}
	toggleNavBar();
}
var expand = true;
var clicked = true;
var toggleExpandComments = function(){
	if (clicked){
		//clicked = false;
		for (var i=1; i<=commentsArray.length; i++){
			moreObj = 'commentsmore'+commentsArray[i];
			lessObj = 'commentsless'+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;
}
function removeSpam(id)
 {
      var spamId = id;
      $(spamId).innerHTML = '';
 }
</script>
<?php if($CFG['admin']['module']['video_audio_blogsforum']) { ?>
<script language="javascript">
var video_extension = '<?php echo $video_format_arr;?>';
var audio_extension = '<?php echo $audio_format_arr;?>';
function thisMovie(movieName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window.document[movieName]

  } else {
   return window.document[movieName]
  }
}
function createJSFCommunicatorObject(playerObj)
{
	fc = new JSFCommunicator(playerObj);
}
var onUploadComplete = function()
{
	var str = arguments[0];
	var index = str.lastIndexOf('.');
	str = str.substring(index+1);
	var video_extension_array = video_extension.split(",");
	var audio_extension_array = audio_extension.split(",");

	if (extensionLookup(video_extension_array, str)){
		$('file_extern').value = str;
		mediaType = 'Video';
		$('external_video_add').style.display = 'none';
		$('external_video_add1').style.display = 'none';
		$('external_video_add2').style.display = '';
		$('external_video_delete').style.display = '';
		if (($('external_video_preview'))) {
			$('external_video_preview').style.display = '';
			$('external_video_preview').href = externalVideoPreviewUrl;
			$('external_video_preview').onclick = showVideoExternalPreview;
			$('external_video_preview').removeClassName('lightwindow');
			$('external_video_preview').href= '#';
		}
	} else if (extensionLookup(audio_extension_array, str)) {
		$('audio_extern').value = str;
		mediaType = 'Audio';
		$('external_audio_add').style.display = 'none';
		$('external_audio_add1').style.display = 'none';
		$('external_audio_add2').style.display = '';
		$('external_audio_delete').style.display = '';
		if (($('external_audio_preview'))) {
			$('external_audio_preview').style.display = '';
			$('external_audio_preview').href = externalAudioPreviewUrl;
			$('external_audio_preview').onclick = showAudioExternalPreview;
			$('external_audio_preview').removeClassName('lightwindow');
			$('external_audio_preview').href= '#';
		}
	}
	ffMacOsCloseWindow();
}
function extensionLookup(mediaArray, extern) {
    for (var i = 0; i < mediaArray.length ; i++) {
        if (mediaArray[i] == extern) {
            return true;
        }
    }
    return false;
}
function onClickThis()
{
		fc.callFunction("_level0","uploadSelcted");
}
function showNormalUpload()
{
	var obj = document.getElementById('selUploadFlash');
	obj.style.display = 'none';
	var obj = document.getElementById('selUploadNormal');
	obj.style.display = '';
	return false;
}
function makeDisable()
{
	document.getElementById('Upload').disabled = true;
}
function makeEnable()
{
	//document.getElementById('Upload').disabled = false;
	//Upload.disabled = false;
}
</script>
<? } ?>
<script language="javascript" type="text/javascript">
	var saveVideo = function(){
		$('video_add').style.display = 'none';
		$('video_delete').style.display = '';
		if (($('video_preview'))) {
			$('video_preview').style.display = '';
			$('video_preview').href = videoPreviewUrl;
		}
		$('video_secnd').style.display = '';
		$('video_first').style.display = 'none';
		$('video').value = $('rid').value;
		ffMacOsCloseWindow();
	}
	var removeVideo = function(){
		alert_manual('<?php echo $LANG['common_video_deleted'];?>');
		$('video_delete').style.display = 'none';
		if (($('video_preview'))) $('video_preview').style.display = 'none';
		$('video_add').style.display = '';
		$('video').value = '';
		$('video_id').value = '0';
		$('video_secnd').style.display = 'none';
		$('video_first').style.display = '';
		return false;
	}
	var removeExternalVideo = function(){
		alert_manual('<?php echo $LANG['successfully_external_video_deleted'];?>', 'external_video_delete');
		$('external_video_delete').style.display = 'none';
		if (($('external_video_preview'))) $('external_video_preview').style.display = 'none';
		$('external_video_add').style.display = '';
		$('external_video_add1').style.display = '';
		$('external_video_add2').style.display = 'none';
		$('video_external_flv_url').value = '';
		$('file_extern').value = '';
		$('external_video_id').value = '0';
		return false;
	}
	var confrimRemove = function(){
		var act_value = arguments[0];
		var anchorLink = arguments[1];
		var msg_confirm = arguments[2];
		if(arguments.length>=4)
			add_top_position = arguments[4];
		if(arguments.length>=6)
			add_left_position = arguments[5];

		var confirm_message = msg_confirm;

		$('confirmMessage').innerHTML = confirm_message;
		document.formConfirm.action.value = act_value;
		Confirmation('selMsgConfirm', 'formConfirm', Array(), Array(), Array());

		return false;
	}
	var doRemoveAction = function(){
		if (document.formConfirm.action.value == 'external_video')
			removeExternalVideo();
		else if (document.formConfirm.action.value == 'external_audio')
			removeExternalAudio();
		else if (document.formConfirm.action.value == 'video')
			removeVideo();
		else
			removeAudio();
	}
	var deleteVideo = function(){
		ffMacOsCloseWindow();
	}
	var saveAudio = function(){
		$('audio_add').style.display = 'none';
		$('audio_delete').style.display = '';
		$('audio_secnd').style.display = '';
		$('audio_first').style.display = 'none';
		if (($('audio_preview'))) {
			$('audio_preview').style.display = '';
			$('audio_preview').href = audioPreviewUrl;
		}
		$('audio').value = $('rid').value;
		ffMacOsCloseWindow();
	}
	var removeAudio = function(){
		alert_manual('<?php echo $LANG['common_audio_deleted'];?>');
		$('audio_delete').style.display = 'none';
		$('audio_secnd').style.display = 'none';
		$('audio_first').style.display = '';

		if (($('audio_preview'))) $('audio_preview').style.display = 'none';
		$('audio_add').style.display = '';
		$('audio').value = '';
		$('audio_id').value = '0';
		return false;
	}
	var removeExternalAudio = function(){
		alert_manual('<?php echo $LANG['successfully_external_audio_deleted'];?>', 'external_audio_delete');
		$('external_audio_delete').style.display = 'none';
		if (($('external_audio_preview'))) $('external_audio_preview').style.display = 'none';
		$('external_audio_add').style.display = '';
		$('external_audio_add1').style.display = '';
		$('external_audio_add2').style.display = 'none';
		$('audio_external_url').value = '';
		$('audio_extern').value = '';
		$('external_audio_id').value = '0';
		return false;
	}

	var deleteAudio = function(){
		ffMacOsCloseWindow();
	}
	var removeId = 0;
	function add_more_upload(lang) {

		var id = removeId++;
		var imgdiv = $('tdID');
		var ptags = imgdiv.getElementsByTagName("p");
		var len = ptags.length;

		if(len > <?php echo $CFG['admin']['attachments_allowed']['count']+1;?>)
			$('brsBtn').style.display = 'none';

		if(len > <?php echo $CFG['admin']['attachments_allowed']['count']+2;?>)
			return;

		var rowTemplate = '<p class="clsAttachments" id="p_'+id+'"><input type="file" name="attachments[]" value=""> <a class="clsRemoveAttachment" href="#" onClick="removeThis('+id+');return false;">'+lang+'<\/a><\/p>';

		new Insertion.Before('brsBtn', rowTemplate);
	}

	function removeThis(id)	{
		var remId = id;
		$('p_'+remId).remove();
		$('brsBtn').style.display = '';
	}
</script>
<?php
//<<<<<<--------------------Page block templates Ends--------------------//
$blogList->includeFooter();
?>