<?php
/**
 * File handling the blog
 *
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		###Manage blog###
 * @author 		karthiselvam_75ag08
 * @copyright	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: $
 * @since 		2008-12-22
 */
/**
 * File having common configuration variables required for the entire project
 */
require_once('./common/configs/config.inc.php'); //configurations
$CFG['lang']['include_files'][] = 'languages/%s/members/manageBlog.php';
$CFG['html']['header'] = 'general/html_header.php';
$CFG['html']['footer'] = 'general/html_footer.php';
$CFG['mods']['include_files'][] = 'common/classes/class_inputfilter_clean.php';
$CFG['lang']['include_files'][] = 'common/configs/config_blogs.inc.php';
$CFG['mods']['include_files'][] = 'common/classes/class_ListRecordsHandler.lib.php';
if ($CFG['admin']['module']['video_audio_blogsforum'])
	{
		$CFG['mods']['include_files'][] = 'common/classes/class_GrapUrl.lib.php';
		$CFG['mods']['include_files'][] = 'common/classes/class_Videopian.lib.php';
	}
$CFG['mods']['include_files'][] = 'common/classes/class_AnsVideoUpload.lib.php';
$CFG['mods']['include_files'][] = 'common/classes/class_ftp.lib.php';
$CFG['mods']['include_files'][] = 'common/classes/class_Image.lib.php';
$CFG['mods']['include_files'][] = 'common/classes/swiftmailer/lib/EasySwift.php';
$CFG['site']['is_module_page'] = $CFG['admin']['index']['anova_module'];
//compulsory
$CFG['mods']['is_include_only']['html_header'] = false;
$CFG['html']['is_use_header'] = false;
$CFG['auth']['is_authenticate'] = 'members';
/**
 * To include various types of files
 */
require($CFG['site']['project_path'].'common/application_top.inc.php');
if($CFG['feature']['html_editor'] == 'fckeditor')
	require($CFG['site']['project_path'].'fckeditor/fckEditorIntegration.php');

class manageBlog extends VideoUploadLib
	{
		public $blog_details_array = array();
		public $_dir_path = '';
		/**
		 * manageBlog::buildSortQuery()
		 *
		 * @return
		 **/
		public function buildSortQuery()
			{
				$this->sql_sort = $this->fields_arr['orderby_field'].' '.$this->fields_arr['orderby'];
			}

		/**
		 * manageBlog::buildConditionQuery()
		 *
		 * @return
		 */
		public function buildConditionQuery()
			{
				$this->sql_condition = 'user_id=\''.$this->CFG['user']['user_id'].'\' AND status=\'Active\'';
			}

		/**
		 * manageBlog::updateBlog()
		 *
		 * @return
		 */
		public function updateBlog()
			{

				$this->fields_arr['message'] = replaceListClass($this->fields_arr['message']);

				$sql = 'UPDATE '.$this->CFG['db']['tbl']['blogs'].
						' SET subject='.$this->dbObj->Param('subject_new').
						', seo_title='.$this->dbObj->Param('seo_title').
						', message='.$this->dbObj->Param('message').
						', publish_comments='.$this->dbObj->Param('publish_comments').
						', blog_category_id='.$this->dbObj->Param('blog_category_id').
						', video_id='.$this->dbObj->Param('video_id').
						', external_video_id='.$this->dbObj->Param('external_video_id').
						', audio_id='.$this->dbObj->Param('audio_id').
						', external_audio_id='.$this->dbObj->Param('external_audio_id').
						', accept_comments='.$this->dbObj->Param('accept_comments').
						' WHERE blog_id='.$this->dbObj->Param('blog_id').
						' AND user_id='.$this->dbObj->Param('user_id');
				$param_arr = array(
									$this->fields_arr['subject_new'],
									$this->fields_arr['seo_title'],
									$this->fields_arr['message'],
									$this->fields_arr['publish_comments'],
									$this->fields_arr['blog_category_id'],
									$this->fields_arr['video_id'],
									$this->fields_arr['external_video_id'],
									$this->fields_arr['audio_id'],
									$this->fields_arr['external_audio_id'],
									$this->fields_arr['accept_comments'],
									$this->fields_arr['blog_id'],
									$this->CFG['user']['user_id']
									);

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, $param_arr);
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				if($this->fields_arr['video'] or ($this->fields_arr['video_id']==0))
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_video'].' SET'.
								' video_status=\'Deleted\' WHERE'.
								' content_id='.$this->dbObj->Param('content_id').' AND'.
								' video_id='.$this->dbObj->Param('video_id').' AND'.
								' video_for=\'Blog\'';

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

						$this->fields_arr['content_id'] = $this->fields_arr['blog_id'];
						if($this->fields_arr['video'])
							$this->addNewVideo();
					}
				if($this->fields_arr['video_external_flv_url'] or $this->fields_arr['file_extern'] or ($this->fields_arr['external_video_id']==0))
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_video'].' SET'.
								' video_status=\'Deleted\' WHERE'.
								' content_id='.$this->dbObj->Param('content_id').' AND'.
								' video_id='.$this->dbObj->Param('external_video_id').' AND'.
								' video_for=\'Blog\'';

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

						$this->fields_arr['content_id'] = $this->fields_arr['blog_id'];
						if($this->fields_arr['video_external_flv_url'] or $this->fields_arr['file_extern'])
							$this->addExternalVideo('Blog');
					}


				if($this->fields_arr['audio'] or ($this->fields_arr['audio_id']==0))
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_audio'].' SET'.
								' audio_status=\'Deleted\' WHERE'.
								' content_id='.$this->dbObj->Param('content_id').' AND'.
								' audio_id='.$this->dbObj->Param('audio_id').' AND'.
								' audio_for=\'Blog\'';

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

						$this->fields_arr['content_id'] = $this->fields_arr['blog_id'];
						if($this->fields_arr['audio'])
							$this->addNewAudio();
					}
				if($this->fields_arr['audio_external_url'] or $this->fields_arr['audio_extern'] or ($this->fields_arr['external_audio_id']==0))
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_audio'].' SET'.
								' audio_status=\'Deleted\' WHERE'.
								' content_id='.$this->dbObj->Param('content_id').' AND'.
								' audio_id='.$this->dbObj->Param('external_audio_id').' AND'.
								' audio_for=\'Blog\'';

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

						$this->fields_arr['content_id'] = $this->fields_arr['blog_id'];
						if($this->fields_arr['audio_external_url'] or $this->fields_arr['audio_extern'])
							$this->addExternalAudio('Blog');
					}

				$this->fields_arr['content_id'] = $this->fields_arr['blog_id'];
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function addBlog()
		    {
				$this->fields_arr['content_id'] = $this->insertBlog();
				$this->addNewVideo();
				$this->addExternalVideo('Blog');
				$this->addNewAudio();
				$this->addExternalAudio('Blog');

		    }
		/**
		 * manageBlog::insertBlog()
		 *
		 * @return
		 **/
		public function insertBlog()
			{
				 $this->fields_arr['message'] = replaceListClass($this->fields_arr['message']);

				 $sql = 'INSERT '.$this->CFG['db']['tbl']['blogs'].
						' SET subject='.$this->dbObj->Param('subject_new').
						', seo_title='.$this->dbObj->Param('seo_title').
						', message='.$this->dbObj->Param('message').
						', blog_category_id='.$this->dbObj->Param('blog_category_id').
						', accept_comments='.$this->dbObj->Param('accept_comments').
						', user_id='.$this->dbObj->Param('user_id').
						', publish_comments='.$this->dbObj->Param('publish_comments').
						', date_added=NOW()';
				//Check auto publish are not
				if(!$this->CFG['admin']['blogs_auto_publish']['allowed'])
					{
						$sql .= ', status=\'Toactivate\'';
					}
				$param_arr = array(
									$this->fields_arr['subject_new'],
									$this->fields_arr['seo_title'],
									$this->fields_arr['message'],
									$this->fields_arr['blog_category_id'],
									$this->fields_arr['accept_comments'],
									$this->CFG['user']['user_id'],
									$this->fields_arr['publish_comments']
									);

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, $param_arr);
				    if (!$rs)
					    trigger_db_error($this->dbObj);
				return $this->dbObj->Insert_ID();
			}

		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=\'Blog\','.
						' 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=\'Blog\','.
						' 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);
			}
		/**
		 * manageBlog::populateBlogsValue()
		 *
		 * @return
		 **/
		public function populateBlogsValue()
			{
				 $sql = 'SELECT blog_id, subject, message, accept_comments, user_id, blog_category_id, video_id, external_video_id, audio_id, external_audio_id, status, publish_comments, date_added'.
						' FROM '.$this->CFG['db']['tbl']['blogs'].' AS b'.
						' WHERE blog_id='.$this->dbObj->Param('blog_id').
						' AND user_id='.$this->dbObj->Param('user_id');

				$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 ($row = $rs->FetchRow())
				    {
				     	$this->blog_details_array['video_id'] = $row['video_id'];
				     	$this->blog_details_array['audio_id'] = $row['audio_id'];
				     	$this->blog_details_array['external_video_id'] = $row['external_video_id'];
				     	$this->blog_details_array['external_audio_id'] = $row['external_audio_id'];

						$this->fields_arr['subject_new'] = $row['subject'];
						$this->fields_arr['message'] = $row['message'];
						$this->fields_arr['blog_category_id'] = $row['blog_category_id'];
						$this->fields_arr['publish_comments'] = $row['publish_comments'];
						$this->fields_arr['video_id'] = $row['video_id'];
						$this->fields_arr['audio_id'] = $row['audio_id'];
						$this->fields_arr['external_video_id'] = $row['external_video_id'];
						$this->fields_arr['external_audio_id'] = $row['external_audio_id'];
						$this->fields_arr['accept_comments'] = ($row['accept_comments']=='Yes')?$this->LANG['common_yes_option']:$this->LANG['common_no_option'];
						return true;
				    }
				return false;
			}

		/**
		 * manageBlog::showBlogsList()
		 *
		 * @return
		 **/
		public function showBlogsList()
			{
				$this->showBlogsList_arr=array();
				$inc=0;
				while($row = $this->fetchResultRecord())
					{
						$this->showBlogsList_arr[$inc]['record']	=	$row;
						$this->showBlogsList_arr[$inc]['anchor']	=	'anchor_'.$row['blog_id'];
						$this->showBlogsList_arr[$inc]['blogcomment_url']	=	getUrl('blogcomment','?title='.$row['seo_title'], $row['seo_title'].'/');
						$this->showBlogsList_arr[$inc]['strip_subject']	=	stripString($row['subject'], 35);
						$this->showBlogsList_arr[$inc]['get_blog_category']	=	$this->getBlogCategory($row['blog_category_id']);
						$this->showBlogsList_arr[$inc]['yes_or_no']	=	($row['accept_comments']=='Yes')?$this->LANG['common_yes_option']:$this->LANG['common_no_option'];
						$this->showBlogsList_arr[$inc]['manageblog_edit_url']	=	getUrl('manageblog','?act=edt&amp;blog_id='.$row['blog_id'].'&amp;start='.$this->fields_arr['start'], '?act=edt&amp;blog_id='.$row['blog_id'].'&amp;start='.$this->fields_arr['start']);
						$inc++;
					}
				return $this->showBlogsList_arr;
			}

		/**
		 * manageBlog::deleteSelectedBlogs()
		 *
		 * @return
		 **/
		public function deleteSelectedBlogs()
			{
				$blog_ids = addslashes($this->fields_arr['blog_id']);
				$blog_ids = explode(',', $blog_ids);
				$blog_ids = '\''.implode('\',\'', $blog_ids).'\'';

				$sql = 'DELETE FROM '.$this->CFG['db']['tbl']['blogs'].
						' WHERE blog_id IN('.$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 IN('.$blog_ids.')';

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					trigger_db_error($this->dbObj);

				$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_video'].
						' SET video_status=\'Deleted\' WHERE content_id IN('.$blog_ids.') AND video_for=\'Blog\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_audio'].
						' SET audio_status=\'Deleted\' WHERE content_id IN('.$blog_ids.') AND audio_for=\'Blog\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				    if (!$rs)
					    trigger_db_error($this->dbObj);

			}

		/**
		 * manageBlog::resetFieldsArray()
		 *
		 * @return
		 */
		public function resetFieldsArray()
			{
				$this->setFormField('subject_new','');
				$this->setFormField('message','');
				$this->setFormField('accept_comments','Yes');
				$this->setFormField('blog_category_id','');
				$this->setFormField('act','');
				$this->setFormField('blog_id','');
				$this->setFormField('redirect','');
			}

		/**
		 * manageBlog::doDefaultValidation()
		 *
		 * @return
		 */
		public function doDefaultValidation()
			{
				$this->chkIsNotEmpty('subject_new', $this->LANG['err_tip_compulsory']);
				$this->chkIsNotEmpty('message', $this->LANG['err_tip_compulsory']);
				$this->chkIsNotEmpty('blog_category_id', $this->LANG['err_tip_compulsory']);
			}

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function populateCategories()
		    {
				$sql = 'SELECT blog_category_id, blog_category_name FROM '.$this->CFG['db']['tbl']['blog_category'].
						' WHERE blog_category_status=\'Yes\' ORDER BY blog_category_name';

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					trigger_db_error($this->dbObj);

				$populateCategories_arr=array();
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow())
							{
								$populateCategories_arr[$row['blog_category_id']] = $row['blog_category_name'];
							}
					}
				return 	$populateCategories_arr;
		    }
		/**
		 * manageBlog::generateRandomId()
		 *
		 * @return
		 */
		public function generateRandomId()
			{
				$time = time();
				$this->fields_arr['rid'] = md5($time);
			}
		/**
		 * manageBlog::chkIsValidCaptureVideoFile()
		 *
		 * @return
		 */
		public function chkIsValidCaptureVideoFile()
			{
				$file_name = $this->CFG['admin']['video']['red5_flv_path'].$this->fields_arr['rid'].'.flv';
				//if($this->fields_arr['video']=$this->fields_arr['rid'])
				if($this->fields_arr['video']==$this->fields_arr['rid'])
					{
						if(is_file($file_name))
							return true;

						$this->fields_arr['video'] = '';
						return false;
					}
				if(is_file($file_name))
					unlink($file_name);
			}

		/**
		 * manageBlog::chkIsValidCaptureAudioFile()
		 *
		 * @return
		 */
		public function chkIsValidCaptureAudioFile()
			{
				$file_name = $this->CFG['admin']['video']['red5_flv_path'].$this->fields_arr['rid'].'AUD.flv';
				//if($this->fields_arr['audio']=$this->fields_arr['rid'])
				if($this->fields_arr['audio']==$this->fields_arr['rid'])
					{
						if(is_file($file_name))
							{return true;}
						$this->fields_arr['audio'] = '';
						return false;
					}
				if(is_file($file_name))
					unlink($file_name);
			}

		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'] = getUrl('anspreviewvideo', '?pg=Blog_'.$this->getFormField('rid'), '?pg=Blog_'.$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'] = getUrl('ansviewvideo', '?pg=Blog_'.$this->getFormField('video_id'), '?pg=Blog_'.$this->getFormField('video_id'));
						if ($this->fields_arr['video'])
							$manageBlogs_arr['video_preview_url'] = getUrl('anspreviewvideo', '?pg=Blog_'.$this->getFormField('video'), '?pg=Blog_'.$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'] = getUrl('ansviewvideo', '?pg=Blog_'.$this->getFormField('external_video_id'), '?pg=Blog_'.$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'] = getUrl('anspreviewaudio', '?pg=Blog_'.$this->getFormField('rid'), '?pg=Blog_'.$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'] = getUrl('ansviewaudio', '?pg=Blog_'.$this->getFormField('audio_id'), '?pg=Blog_'.$this->getFormField('audio_id'));
						if ($this->fields_arr['audio'])
							$manageBlogs_arr['audio_preview_url'] = getUrl('anspreviewaudio', '?pg=Blog_'.$this->getFormField('audio'), '?pg=Blog_'.$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'] = getUrl('ansviewaudio', '?pg=Blog_'.$this->getFormField('external_audio_id'), '?pg=Blog_'.$this->getFormField('external_audio_id'));
											}
									}
							}
					}

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

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

				return $manageBlogs_arr;
			}


			public function paymentUpgradeDisplay()
				{
					$notifyBlog_arr = array();

					if(chkIsPaymentAllowed('payment_blog'))
						{
							if(chkIsPaymentAlertMessageAllowed())
								{
									$req_count = $this->getPlanLogForBlog();
									$req_today_count = $this->getPlanLogForBlogPerDay();
									$req_count = $req_count < 0?'0':$req_count;
									$req_today_count = $req_today_count < 0?'0':$req_today_count;

									if($req_count == $this->CFG['plan']['unlimited_text'])
										$notifyBlog_arr['total_notify'] = $this->CFG['plan']['unlimited_text'];
									elseif(chkIsPaymentUpgradeAllowed())
										{
											$notifyBlog_arr['total_notify'] = str_ireplace('VAR_LIMIT', $req_count, $this->LANG['total_notify_upgrade']);
											$notifyBlog_arr['total_notify'] = str_ireplace('VAR_UPGRADE', '<a href="'.getUrl('paymentupgrade', '', '', 'members').'">'.$this->LANG['blog_upgrade'].'</a>', $notifyBlog_arr['total_notify']);
										}
									else
										$notifyBlog_arr['total_notify'] = str_ireplace('VAR_LIMIT', $req_count, $this->LANG['total_notify_admin']);

									if($req_today_count == $this->CFG['plan']['unlimited_text'])
										$notifyBlog_arr['today_notify'] = $this->CFG['plan']['unlimited_text'];
									elseif(chkIsPaymentUpgradeAllowed())
										{
											$notifyBlog_arr['today_notify'] = str_ireplace('VAR_LIMIT', $req_today_count, $this->LANG['today_notify_upgrade']);
											$notifyBlog_arr['today_notify'] = str_ireplace('VAR_UPGRADE', '<a href="'.getUrl('paymentupgrade', '', '', 'members').'">'.$this->LANG['blog_upgrade'].'</a>', $notifyBlog_arr['today_notify']);
										}
									else
										$notifyBlog_arr['today_notify'] = str_ireplace('VAR_LIMIT', $req_today_count, $this->LANG['today_notify_admin']);
								}

						}
					return $notifyBlog_arr;
				}

				public function getPlanLogForBlog()
					{
						$sql = 'SELECT blog_id FROM '.$this->CFG['db']['tbl']['blogs'].
								' WHERE user_id = '.$this->dbObj->Param('user_id').
								' AND date_added >= '.$this->dbObj->Param('date_added');

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

						$numrows = $rs->PO_RecordCount();

						if($this->CFG['plan']['plan_total_blog'] != $this->CFG['plan']['unlimited'])
							return ($this->CFG['plan']['plan_total_blog'] - $numrows);
						else
							return $this->CFG['plan']['unlimited_text'];

					}

				public function getPlanLogForBlogPerDay()
					{
						$sql = 'SELECT blog_id FROM '.$this->CFG['db']['tbl']['blogs'].
						       ' WHERE user_id = '.$this->dbObj->Param('user_id').
							   ' AND DATE_FORMAT(date_added, \''.$this->CFG['mysql_format']['date_time'].'\') >= DATE_FORMAT((select DATE_SUB(now(), INTERVAL 1 DAY)),\''.$this->CFG['mysql_format']['date_time'].'\')';

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

						$numrows = $rs->PO_RecordCount();

						if($this->CFG['plan']['plan_blog_perday'] != $this->CFG['plan']['unlimited'])
							return ($this->CFG['plan']['plan_blog_perday'] - $numrows);
						else
							return $this->CFG['plan']['unlimited_text'];
					}
				public function totalPostedBlogCount($user_id)
					{
						if(!chkIsPaymentAllowed('payment_blog'))
							return true;

						$sql = 'SELECT blog_id FROM '.$this->CFG['db']['tbl']['blogs'].
						       ' WHERE user_id = '.$this->dbObj->Param('user_id').
							   ' AND date_added >= '.$this->dbObj->Param('date_added');

						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($user_id, $this->CFG['user']['last_paid_date']));
						if (!$rs)
						    trigger_db_error($this->dbObj);
						$numrows = $rs->PO_RecordCount();
						if($numrows < $this->CFG['plan']['plan_total_blog'] || $this->CFG['plan']['plan_total_blog'] == $this->CFG['plan']['unlimited'])
							return true;
						else
							return false;
					}
				public function todayPostedBlogCount($user_id)
					{
						if(!chkIsPaymentAllowed('payment_blog'))
							return true;

						$sql = 'SELECT blog_id FROM '.$this->CFG['db']['tbl']['blogs'].''.
						       ' WHERE user_id = '.$this->dbObj->Param('user_id').''.
							   ' AND DATE_FORMAT(date_added, \''.$this->CFG['mysql_format']['date_time'].'\') >= DATE_FORMAT((select DATE_SUB(now(), INTERVAL 1 DAY)),\''.$this->CFG['mysql_format']['date_time'].'\')';

						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($user_id));
						if (!$rs)
						    trigger_db_error($this->dbObj);
						$numrows = $rs->PO_RecordCount();
						if($numrows < $this->CFG['plan']['plan_blog_perday'] || $this->CFG['plan']['plan_blog_perday'] == $this->CFG['plan']['unlimited'] )
							return true;
						else
							return false;
					}
	}

//--------------------Code begins-------------->>>>>//
$manageBlog = new manageBlog();
if(!chkIsAllowedModule(array('blog')))
	Redirect2URL(getUrl($CFG['redirect']['dsabled_module_url']['file_name']));
//set blocks
$manageBlog->setPageBlockNames(array('blogsEditor', 'blogsEditBlock', 'selBlogsListBlock', 'blogsUpgrade', 'blogsTitle'));
$manageBlog->fp = false;
/*********** Page Navigation Start *********/
$manageBlog->setFormField('from', '');
$manageBlog->setFormField('video', '');
$manageBlog->setFormField('video_id', '');
$manageBlog->setFormField('audio', '');
$manageBlog->setFormField('audio_id', '');
$manageBlog->setFormField('external_video_id', '');
$manageBlog->setFormField('external_audio_id', '');
$manageBlog->setFormField('video_external_flv_url', '');
$manageBlog->setFormField('flv_upload_type', '');
$manageBlog->setFormField('file_extern', '');
$manageBlog->setFormField('audio_external_url', '');
$manageBlog->setFormField('audio_extern', '');
$manageBlog->setFormField('rid', '');
$manageBlog->setFormField('publish_comments', 'Yes');
$manageBlog->setFormField('orderby_field', 'blog_id');
$manageBlog->setFormField('orderby', 'DESC');
$manageBlog->setFormField('start', '0');
$manageBlog->setFormField('start', '0');
$manageBlog->setFormField('numpg', $CFG['data_tbl']['numpg']);
$manageBlog->setMinRecordSelectLimit(2);
$manageBlog->setMaxRecordSelectLimit($CFG['data_tbl']['max_record_select_limit']);
$manageBlog->setNumPerPageListArr($CFG['data_tbl']['numperpage_list_arr']);
$manageBlog->setTableNames(array($CFG['db']['tbl']['blogs']));
$manageBlog->setReturnColumns(array('blog_id', 'subject', 'seo_title', 'message', 'blog_category_id', 'accept_comments', 'total_comments', 'total_views', 'user_id', 'status', 'date_added'));
/************ page Navigation stop *************/
//set Form Fields
$manageBlog->resetFieldsArray();
$manageBlog->setAllPageBlocksHide();
//show default pages
$manageBlog->setPageBlockShow('selBlogsListBlock');
$manageblogActive = 'clsActiveBlogTopLink';
$addblogActive = '';
$is_validBlog = true;
$isAllowedToAsk = true;
$manageBlog->sanitizeFormInputs($_REQUEST);

if(!$manageBlog->getFormField('rid'))
	$manageBlog->generateRandomId();

if (!$CFG['admin']['blogs_create']['allowed'])
	Redirect2Url (getUrl('blogs'));
if (!$manageBlog->isAllowedToAsk())
	{
		$isAllowedToAsk = false;
		$manageblogActive = '';
		$manageBlog->setAllPageBlocksHide();
		$manageBlog->setPageBlockShow('block_msg_form_error');
		if ($manageBlog->isFormPOSTed($_GET, 'add'))
		$manageBlog->setCommonErrorMsg($LANG['manageBlog_info_not_allowed_to_post']);
		else
			$manageBlog->setCommonErrorMsg($LANG['manageBlog_info_not_allowed_to_manage']);


	}
else if($manageBlog->isFormPOSTed($_POST,'add_submit'))
	{
		$manageBlog->doDefaultValidation();

		if(chkVideoModuleAllowed('blog'))
			$manageBlog->chkIsValidCaptureVideoFile();
		if(chkAudioModuleAllowed('blog'))
			$manageBlog->chkIsValidCaptureAudioFile();

		// create the new InputFilter instance
		$filter = new InputFilter($CFG['fckeditor']['allowed_tags'], $CFG['fckeditor']['allowed_attr']);
		// use the new filter to process the string
		$manageBlog->setFormfield('message' ,$filter->process($manageBlog->getFormfield('message')));

		if($manageBlog->isValidFormInputs())
			{
				$manageBlog->setFormField('message', html_entity_decode($manageBlog->getFormField('message'), ENT_QUOTES, $CFG['site']['charset']));
				$manageBlog->setFormField('seo_title', $manageBlog->getSeoTitleForBlogs($manageBlog->getFormField('subject_new'), $manageBlog->getFormField('blog_id')));
				if ($CFG['debug']['store_log'])
					{
						$manageBlog->createErrorLogFile('blog');
					}
				$manageBlog->addBlog();
				if ($CFG['debug']['store_log'])
					{
						$manageBlog->closeErrorLogFile();
					}

				if($CFG['admin']['blogs_auto_publish']['allowed']){
					$manageBlog->setCommonSuccessMsg($LANG['manageBlog_msg_success_added']);
				} else {
					$manageBlog->setCommonSuccessMsg($LANG['manageBlog_msg_success_added_publish']);
				}
				$manageBlog->setPageBlockShow('block_msg_form_success');
				Redirect2Url (getUrl('blogs','?added', '?added'));
			}
		else
			{
				$manageBlog->setCommonErrorMsg($LANG['common_msg_error_sorry']);
				$manageBlog->setPageBlockShow('block_msg_form_error');
				$manageBlog->setPageBlockShow('blogsEditor');
			}
	}
else if($manageBlog->isFormPOSTed($_POST,'update_submit'))
	{

		$manageBlog->doDefaultValidation();
		//$manageBlog->populateBlogsValue();

		if(chkVideoModuleAllowed('blog'))
			$manageBlog->chkIsValidCaptureVideoFile();
		if(chkAudioModuleAllowed('blog'))
			$manageBlog->chkIsValidCaptureAudioFile();

		// create the new InputFilter instance
		$filter = new InputFilter($CFG['fckeditor']['allowed_tags'], $CFG['fckeditor']['allowed_attr']);
		// use the new filter to process the string
		$manageBlog->setFormfield('message' ,$filter->process($manageBlog->getFormfield('message')));
		if($manageBlog->isValidFormInputs())
			{
				$manageBlog->setFormField('message', html_entity_decode($manageBlog->getFormField('message'), ENT_QUOTES, $CFG['site']['charset']));
				$manageBlog->setFormField('seo_title', $manageBlog->getSeoTitleForBlogs($manageBlog->getFormField('subject_new'), $manageBlog->getFormField('blog_id')));
				if ($CFG['debug']['store_log'])
					{
						$manageBlog->createErrorLogFile('blog');
					}
				$manageBlog->updateBlog();
				if ($CFG['debug']['store_log'])
					{
						$manageBlog->closeErrorLogFile();
					}
				$manageBlog->setCommonSuccessMsg($LANG['manageBlog_msg_success_update']);
				$manageBlog->setPageBlockShow('block_msg_form_success');
				$manageBlog->resetFieldsArray();
				if($manageBlog->getFormField('from')=='cmt')
					{
						Redirect2Url (getUrl('blogcomment','?title='.$manageBlog->getFormField('seo_title').'&msg=edited', $manageBlog->getFormField('seo_title').'/'.'edited/'));
					}
				Redirect2Url (getUrl('manageblog','?update', '?update'));
			}
		else
			{
				$manageBlog->populateBlogsValue();
				$manageBlog->setCommonErrorMsg($LANG['common_msg_error_sorry']);
				$manageBlog->setPageBlockShow('block_msg_form_error');
				$manageBlog->setPageBlockShow('blogsEditor');
				$manageBlog->setPageBlockShow('blogsEditBlock');
			}
	}
else if($manageBlog->isFormPOSTed($_POST,'update_cancel'))
	{
		$manageBlog->resetFieldsArray();
		Redirect2Url (getUrl('manageblog'));
	}
else if($manageBlog->isFormGETed($_GET, 'act'))
	{
		if($manageBlog->getFormField('act')=='edt')
			{
				if($manageBlog->populateBlogsValue())
				{
					$manageBlog->setPageBlockShow('blogsEditBlock');
					$manageBlog->setPageBlockShow('blogsTitle');
				}
				else
              		$is_validBlog = false;
			}
	}
else if($manageBlog->isFormPOSTed($_POST, 'action_blog'))
	{
		if($manageBlog->getFormField('act')=='delete')
			{
				$manageBlog->deleteSelectedBlogs();
				$manageBlog->setCommonSuccessMsg($LANG['manageBlog_success_deleted']);
			}
		$manageBlog->setPageBlockShow('block_msg_form_success');
		$manageBlog->resetFieldsArray();
	}
if(($manageBlog->getFormField('act')=='edt' OR $manageBlog->isFormPOSTed($_GET, 'add')) AND $isAllowedToAsk)
	{
		$manageBlog->setPageBlockShow('blogsEditor');
		$manageBlog->setPageBlockShow('blogsTitle');
	}

if(($manageBlog->isFormPOSTed($_GET, 'add')) AND $isAllowedToAsk)
	{
		$manageBlog->blog_add['notifyBlog_arr'] = $manageBlog->paymentUpgradeDisplay();

		if($manageBlog->totalPostedBlogCount($CFG['user']['user_id']))
			  {
				if($manageBlog->todayPostedBlogCount($CFG['user']['user_id']))
					{
						if (chkIsPaymentAllowed('payment_blog'))
							{
								$manageBlog->overRideConfigs();
								$upgrade = '<a href="'.getUrl('paymentupgrade').'">'.$manageBlog->LANG['blog_upgrade'].'</a>';
								if(!chkIsPaymentUpgradeAllowed())
									$upgrade = $LANG['inform_site_admin'];
							}
						$manageBlog->setPageBlockShow('blogsUpgrade');
					}
				else
					{
						$manageBlog->setAllPageBlocksHide();
						$manageBlog->setPageBlockShow('block_msg_form_error');
						$manageBlog->setCommonErrorMsg($LANG['info_not_allowed_to_ask_today']);
					}
			   }
		else
		   {
		   		$manageBlog->setAllPageBlocksHide();
		   		$manageBlog->setPageBlockShow('block_msg_form_error');
				$upgrade = '<a href="'.getUrl('paymentupgrade').'">'.$manageBlog->LANG['blog_upgrade'].'</a>';
				if(!chkIsPaymentUpgradeAllowed())
						$upgrade = $LANG['inform_site_admin'];
				$LANG['info_limit_exceeded_to_ask_blog'] = str_ireplace('VAR_UPGRADE', $upgrade, $LANG['info_limit_exceeded_to_ask_blog']);
				$manageBlog->setCommonErrorMsg($LANG['info_limit_exceeded_to_ask_blog']);
		   }

		//$manageBlog->blog_add['notifyBlog_arr'] = $manageBlog->paymentUpgradeDisplay();
		//$manageBlog->setPageBlockShow('blogsUpgrade');
	}

if($manageBlog->isFormPOSTed($_GET, 'added'))
	{
		if($CFG['admin']['blogs_auto_publish']['allowed'])
			$manageBlog->setCommonSuccessMsg($LANG['manageBlog_msg_success_added']);
		else
			$manageBlog->setCommonSuccessMsg($LANG['manageBlog_msg_success_added_publish']);
		$manageBlog->setPageBlockShow('block_msg_form_success');
	}
if($manageBlog->isFormPOSTed($_GET, 'update'))
	{
		$manageBlog->setCommonSuccessMsg($LANG['manageBlog_msg_success_update']);
		$manageBlog->setPageBlockShow('block_msg_form_success');
	}
$manageBlog->manageBlogCommon['page_title']	=	$LANG['manageBlog_title'];
if($manageBlog->isShowPageBlock('blogsEditor'))
	{
		$manageBlog->setPageBlockHide('selBlogsListBlock');
		$manageblogActive = '';
		if ($manageBlog->getFormField('act')!='edt')
			$addblogActive = 'clsActiveBlogTopLink';
		if($manageBlog->isShowPageBlock('blogsEditBlock'))
			$manageBlog->manageBlogCommon['page_title']	=	$LANG['manageBlog_page_edit_title'];
		else
			$manageBlog->manageBlogCommon['page_title']	=	$LANG['common_add_blog'];
	}
if(!$is_validBlog)
	{
		$manageBlog->setAllPageBlocksHide();
		$manageBlog->setCommonErrorMsg($LANG['manageBlog_invalid_blog']);
		$manageBlog->setPageBlockShow('block_msg_form_error');
	}
//<<<<--------------------Code Ends----------------------//
//--------------------Page block templates begins-------------------->>>>>//
$manageBlog->manageBlogCommon['manageblogActive']	=	$manageblogActive;
$manageBlog->manageBlogCommon['addblogActive']	=	$addblogActive;
$manageBlog->manageBlogCommon['manageblog_url']	=	getUrl('manageblog','','','members');
$manageBlog->manageBlogCommon['manageblog_addurl']	=	getUrl('manageblog','?add', '?add','members');
$manageBlog->manageBlogCommon['blogs_addurl']	=	getUrl('blogs');
if ($manageBlog->isShowPageBlock('blogsEditor'))
	{
		$manageBlog->blogsEditor['populateCategories_arr']	=	$manageBlog->populateCategories();
		$manageBlog->blogsEditBlock['manageBlogs_arr'] = $manageBlog->declareBlogValues();
		$manageBlog->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');
	}
if($manageBlog->isShowPageBlock('selBlogsListBlock'))
	{
		/****** navigtion continue*********/
		$manageBlog->buildSelectQuery();
		$manageBlog->buildConditionQuery();
		$manageBlog->buildSortQuery();
		$manageBlog->buildQuery();
		$manageBlog->executeQuery();
		if($manageBlog->isResultsFound())
			{
				$manageBlog->selBlogsListBlock['anchor']='dAltMlti';
				$smartyObj->assign('smarty_paging_list', $manageBlog->populatePageLinksGET($manageBlog->getFormField('start')));
				$manageBlog->selBlogsListBlock['showBlogsList']	=	$manageBlog->showBlogsList();
				$manageBlog->selBlogsListBlock['nl2br_delete_confirmation']	=	nl2br($LANG['manageBlog_delete_confirmation']);
				$manageBlog->selBlogsListBlock['populateHidden']	=	array('start');
				$manageBlog->selBlogsListBlock['onClick']	=	'if(getMultiCheckBoxValue(\'blogsListForm\', \'check_all\', \''.$manageBlog->LANG['common_check_atleast_one'].'\')){Confirmation(\'selMsgConfirmList\', \'deleteForm\', Array(\'blog_id\', \'act\', \'confirmation_msg\'), Array(multiCheckValue, \'delete\',\' '.nl2br($manageBlog->LANG['manageBlog_delete_confirmation']).'\'), Array(\'value\', \'value\', \'innerHTML\'), \'blogsListForm\');}';
			}
	}
//include the header file
$manageBlog->includeHeader();
//include the content of the page
setTemplateFolder('members/');
$smartyObj->display('manageBlog.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 language="javascript" type="text/javascript">
	var block_arr= new Array('selMsgConfirm', 'selMsgConfirmList');
</script>
<script language="javascript" type="text/javascript">
	<?php if ($manageBlog->isShowPageBlock('blogsEditor')){ ?>
	needLiveValidation('subject_new',Array('Presence'));
	<?php } ?>
</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--------------------//
$manageBlog->includeFooter();
?>