<?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-23
 */
require_once('../../common/configs/config.inc.php');
$CFG['lang']['include_files'][] = 'languages/%s/'.$CFG['admin']['index']['blog_module'].'/admin/manageBlogs.php';
$CFG['lang']['include_files'][] =	'languages/%s/common/email_notify.inc.php';
$CFG['html']['header'] = 'admin/html_header.php';
$CFG['html']['footer'] = 'admin/html_footer.php';
$CFG['mods']['include_files'][] = 'common/classes/class_inputfilter_clean.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';
	}
//compulsory
$CFG['site']['is_module_page']='blog';
$CFG['mods']['is_include_only']['html_header'] = false;
$CFG['html']['is_use_header'] = false;
$CFG['mods']['include_files'][] = 'common/classes/class_AnovaHandler.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';

if($CFG['feature']['html_editor'] == 'fckeditor')
require($CFG['site']['project_path'].'fckeditor/fckEditorIntegrationAdmin.php');

require($CFG['site']['project_path'].'common/application_top.inc.php');
class manageBlogs extends VideoUploadLib
	{
		public $blog_details_array = array();
		public $_dir_path = '../../';
		/**
		 * manageBlogs::buildSortQuery()
		 *
		 * @return
		 **/
		public function buildSortQuery()
			{
				$this->sql_sort = $this->fields_arr['orderby_field'].' '.$this->fields_arr['orderby'];
			}

		/**
		 * manageBlogs::buildConditionQuery()
		 *
		 * @return
		 */
		public function buildConditionQuery()
			{
				$this->sql_condition = '';
			}

		/**
		 * manageBlogs::updateBlog()
		 *
		 * @return
		 */
		public function updateBlog()
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['blogs'].
						' SET subject='.$this->dbObj->Param('subject').
						', seo_title='.$this->dbObj->Param('seo_title').
						', message='.$this->dbObj->Param('message').
						', status='.$this->dbObj->Param('status').
						', 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');
				$param_arr = array(
									$this->fields_arr['subject'],
									$this->fields_arr['seo_title'],
									$this->fields_arr['message'],
									$this->fields_arr['status'],
									$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']
								);

				$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->fields_arr['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->fields_arr['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->fields_arr['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->fields_arr['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');

		    }

		/**
		 * manageBlogs::insertBlog()
		 *
		 * @return
		 **/
		public function insertBlog()
			{
				$sql = 'INSERT '.$this->CFG['db']['tbl']['blogs'].
						' SET subject='.$this->dbObj->Param('subject').
						', seo_title='.$this->dbObj->Param('seo_title').
						', message='.$this->dbObj->Param('message').
						', accept_comments='.$this->dbObj->Param('accept_comments').
						', user_id='.$this->dbObj->Param('user_id').
						', blog_category_id='.$this->dbObj->Param('blog_category_id').
						', status='.$this->dbObj->Param('status').
						', publish_comments='.$this->dbObj->Param('publish_comments').
						', date_added=NOW()';
				$param_arr = array(
									$this->fields_arr['subject'],
									$this->fields_arr['seo_title'],
									$this->fields_arr['message'],
									$this->fields_arr['accept_comments'],
									$this->CFG['user']['user_id'],
									$this->fields_arr['blog_category_id'],
									$this->fields_arr['status'],
									$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->_dir_path.$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->_dir_path.$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->_dir_path.$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->_dir_path.$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);
			}
		/**
		 * manageBlogs::populateBlogsValue()
		 *
		 * @return
		 **/
		public function populateBlogsValue()
			{
				$sql = 'SELECT blog_id, subject, message, accept_comments, publish_comments, user_id,blog_category_id, video_id, audio_id, external_video_id, external_audio_id, status, date_added'.
						' FROM '.$this->CFG['db']['tbl']['blogs'].
						' 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);

				if ($row = $rs->FetchRow())
				    {
				     	$this->fields_arr['subject'] = $row['subject'];
						$this->fields_arr['message'] = $row['message'];
						$this->fields_arr['accept_comments'] = $row['accept_comments'];
						$this->fields_arr['status'] = $row['status'];
						$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'];
						return true;
				    }
				return false;
			}

		/**
		 * manageBlogs::showBlogsList()
		 *
		 * @return
		 **/
		public function showBlogsList()
			{
				$this->showBlogsList_arr	=	array();
				$inc=0;
				while($row = $this->fetchResultRecord())
					{
						$this->showBlogsList_arr[$inc]['anchor']	=	'anchor_'.$row['blog_id'];
						$this->showBlogsList_arr[$inc]['div_id']	=	'selPreview'.$row['blog_id'];
						$this->showBlogsList_arr[$inc]['userDetails']	=	$userDetails = $row;
						$this->showBlogsList_arr[$inc]['userDetails']['user_id']	=	$userDetails['uid'];
						$this->showBlogsList_arr[$inc]['user_id']	=	$userDetails['user_id'] = $row['uid'];
						$this->showBlogsList_arr[$inc]['blogcomment_url']	=	$this->CFG['site']['relative_url'].'blogComment.php?blog_id='.$row['blog_id'];
						$this->showBlogsList_arr[$inc]['wordWrapManual_subject']	=	wordWrapManual($row['subject'], 35);
						$this->showBlogsList_arr[$inc]['stripString_display_name']	=	stripString($userDetails['display_name'], $this->CFG['username']['short_length']);
						$this->showBlogsList_arr[$inc]['manageblogs_url']	=	$this->CFG['site']['url'].'admin/'.$this->CFG['admin']['index']['blog_module'].'/manageBlogs.php?act=edt&amp;blog_id='.$row['blog_id'].'&amp;start='.$this->fields_arr['start'];

						$this->showBlogsList_arr[$inc]['video_id'] = $row['video_id'];
						$this->showBlogsList_arr[$inc]['ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Blog_'.$row['video_id'], '?pg=Blog_'.$row['video_id'], 'members');
						$this->showBlogsList_arr[$inc]['ans_view_video']['on_click'] = 'blog_video_'.$row['video_id'];

						$this->showBlogsList_arr[$inc]['audio_id'] = $row['audio_id'];
						$this->showBlogsList_arr[$inc]['ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Blog_'.$row['audio_id'], '?pg=Blog_'.$row['audio_id'], 'members');
						$this->showBlogsList_arr[$inc]['ans_view_audio']['on_click'] = 'blog_audio_'.$row['audio_id'];

						$this->showBlogsList_arr[$inc]['external_video_id'] = $row['external_video_id'];
						$this->showBlogsList_arr[$inc]['ext_ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Blog_'.$row['external_video_id'], '?pg=Blog_'.$row['external_video_id'], 'members');
		  				$this->showBlogsList_arr[$inc]['ext_ans_view_video']['on_click'] = 'external_video_blog_'.$row['external_video_id'];

						$this->showBlogsList_arr[$inc]['external_audio_id'] = $row['external_audio_id'];
						$this->showBlogsList_arr[$inc]['ext_ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Blog_'.$row['external_audio_id'], '?pg=Blog_'.$row['external_audio_id'], 'members');
						$this->showBlogsList_arr[$inc]['ext_ans_view_audio']['on_click'] = 'external_audio_blog_'.$row['external_audio_id'];

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

		/**
		 * manageBlogs::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);
			}

		/**
		 * manageBlogs::resetFieldsArray()
		 *
		 * @return
		 */
		public function resetFieldsArray()
			{
				$this->setFormField('subject','');
				$this->setFormField('message','');
				$this->setFormField('accept_comments','Yes');
				$this->setFormField('act','');
				$this->setFormField('blog_category_id','');
				$this->setFormField('blog_id','');
				$this->setFormField('status','Active');
				$this->setFormField('redirect','');
				$this->setFormField('publish_comments','Yes');
			}

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

		/**
		 * manageBlogs::changeStatus()
		 *
		 * @param mixed $status
		 * @param mixed $sentmail
		 * @return
		 */
		public function changeStatus($status,$sentmail)
			{
				$blog_ids = addslashes($this->fields_arr['blog_id']);
				$blog_ids = explode(',', $blog_ids);
				$blog_ids = '\''.implode('\',\'', $blog_ids).'\'';

				if($sentmail)
					{
						$select_query = 'SELECT `user_id`,subject,seo_title,message
						            		 FROM `blogs` WHERE `blog_id` IN ('.$blog_ids.') AND status=\'Toactivate\'';

						$rs = $this->dbObj->Execute($select_query);
						if (!$rs)
				        	trigger_db_error($this->dbObj);

						if ($rs->PO_RecordCount())
							{
								while($row = $rs->FetchRow())
									{
										$this->sendPublishedMailAlert($row['user_id'],'Blogs',$row['seo_title'],$row['subject'],$row['message']);
									}
							}
					}
				if($sentmail)
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['blogs'].
						' SET status='.$this->dbObj->Param('status').
						' WHERE blog_id IN('.$blog_ids.') AND status=\'Toactivate\'';
					}
				else
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['blogs'].
						' SET status='.$this->dbObj->Param('status').
						' WHERE blog_id IN('.$blog_ids.') AND status<>\'Toactivate\'';
					}

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($status));
				if (!$rs)
				    trigger_db_error($this->dbObj);
			}
		/**
		 * manageBlog::generateRandomId()
		 *
		 * @return
		 */
		public function generateRandomId()
			{
				$time = time();
				$this->fields_arr['rid'] = md5($time);
			}
		/**
		 * AnswersFormHandler::chkIsValidCaptureVideoFile()
		 *
		 * @return
		 */
		public function chkIsValidCaptureVideoFile()
			{
				//for testing

				$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;
								#die('here');
							}

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

		/**
		 * AnswersFormHandler::chkIsValidCaptureAudioFile()
		 *
		 * @return
		 */
		public function chkIsValidCaptureAudioFile()
			{
				//for testing

				$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);
			}
		/**
		 * publish sent mail;
		 */
		 public function sendPublishedMailAlert($userid, $mailtype, $mail_content_seo, $mail_content, $content_description)
			{
				$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 == 'Blogs')
					{
						$url_link = getBlogUrl('blogcomment','?title='.$mail_content_seo, $mail_content_seo.'/', 'root');
						$band_link = "<a target=\"_blank\" href=\"".$url_link."\">".$mail_content."</a>";
						$subject = $this->getMailContent($this->LANG['blog_publish_subject'], array('VAR_USERNAME'=>$toDetails['display_name'], 'VAR_SITENAME'=>$this->CFG['site']['name'], 'VAR_DESCRIPTION_OF_BLOG'=>$content_description, 'VAR_BLOG'=>$band_link, 'VAR_LINK'=>$site_link));
						$content = $this->getMailContent($this->LANG['blog_publish_message'], array('VAR_USERNAME'=>$toDetails['display_name'], 'VAR_SITENAME'=>$this->CFG['site']['name'], 'VAR_DESCRIPTION_OF_BLOG'=>$content_description, 'VAR_BLOG'=>$band_link, 'VAR_LINK'=>$site_link));
					}
				$this->_sendMail($toDetails['email'],
								$subject,
								$content,
								$this->CFG['site']['noreply_name'],
								$this->CFG['site']['noreply_email']);
			}

		/**
		 * manageBlogs::_sendMail()
		 *
		 * @param mixed $to_email
		 * @param mixed $subject
		 * @param mixed $body
		 * @param mixed $sender_name
		 * @param mixed $sender_email
		 * @return
		 */
		private function _sendMail($to_email, $subject, $body, $sender_name, $sender_email)
			{
				$this->buildEmailTemplate($subject, $body, false, true);
				$EasySwift = new EasySwift($this->getSwiftConnection());
				$EasySwift->flush();
				$EasySwift->addPart($this->getEmailContent(), "text/html");
				$from_address = $sender_name.'<'.$sender_email.'>';
				return $EasySwift->send($to_email, $from_address, $this->getEmailSubject());
			}

		/**
		 * BlogWriting::populateBlogCatagory()
		 *
		 * @param string $err_tip
		 * @return
		 **/
		public function populateBlogCatagory($err_tip='')
			{
				$sql = 'SELECT blog_category_id, blog_category_name FROM '.$this->CFG['db']['tbl']['blog_category'].
						' WHERE  blog_category_status=\'Yes\'';

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

				$this->populateBlogCatagory_arr	=	array();
				$this->populateBlogCatagory_arr['RecordCount']	=	1;
				if(!$rs->PO_RecordCount())
					$this->populateBlogCatagory_arr['RecordCount']	=	0;
				$highlight_value = $this->fields_arr['blog_category_id'];
				$this->populateBlogCatagory_arr['row']	=	array();
				$inc=0;
				while($row = $rs->FetchRow())
					{
						$this->populateBlogCatagory_arr['row'][$inc]['record']	=	$row;
						if($highlight_value == $row['blog_category_id'])
							{
								$this->populateBlogCatagory_arr['row'][$inc]['selected_chk']	=	'SELECTED';
							}
						else
							{
								$this->populateBlogCatagory_arr['row'][$inc]['selected_chk']	=	'';
							}
						$inc++;
					}
				return 	$this->populateBlogCatagory_arr;
			}

		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=Question_'.$this->getFormField('rid'), '?pg=Question_'.$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=Blog_'.$this->getFormField('video_id'), '?pg=Blog_'.$this->getFormField('video_id'), 'members');
						if ($this->fields_arr['video'])
							$manageBlogs_arr['video_preview_url'] = getAnovaUrl('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'] = getAnovaUrl('ansviewvideo', '?pg=Blog_'.$this->getFormField('external_video_id'), '?pg=Blog_'.$this->getFormField('external_video_id'), 'members');
											}
									}
							}
					}

				$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=Question_'.$this->getFormField('rid'), '?pg=Question_'.$this->getFormField('rid'), 'members');
				$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=Blog_'.$this->getFormField('audio_id'), '?pg=Blog_'.$this->getFormField('audio_id'), 'members');
						if ($this->fields_arr['audio'])
							$manageBlogs_arr['audio_preview_url'] = getAnovaUrl('anspreviewaudio', '?pg=Blog_'.$this->getFormField('audio'), '?pg=Blog_'.$this->getFormField('audio'), 'members');
					}
				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=Blog_'.$this->getFormField('external_audio_id'), '?pg=Blog_'.$this->getFormField('external_audio_id'), 'members');
											}
									}
							}
					}

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

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

				return $manageBlogs_arr;
			}
	}
//--------------------Code begins-------------->>>>>//
$manageBlogs = new manageBlogs();
$manageBlogs->left_navigation_div = 'blogBlog';
if(!chkIsAllowedModule(array('blog')))
	Redirect2URL(getUrl($CFG['redirect']['dsabled_module_url']['file_name']));
//set blocks
$manageBlogs->setPageBlockNames(array('blogsEditor', 'blogsEditBlock', 'selBlogsListBlock'));
$manageBlogs->fp = false;
$manageBlogs->setFormField('from', '');
$manageBlogs->setFormField('video', '');
$manageBlogs->setFormField('video_id', '');
$manageBlogs->setFormField('audio', '');
$manageBlogs->setFormField('audio_id', '');
$manageBlogs->setFormField('external_video_id', '');
$manageBlogs->setFormField('external_audio_id', '');
$manageBlogs->setFormField('video_external_flv_url', '');
$manageBlogs->setFormField('flv_upload_type', '');
$manageBlogs->setFormField('file_extern', '');
$manageBlogs->setFormField('audio_external_url', '');
$manageBlogs->setFormField('audio_extern', '');
$manageBlogs->setFormField('rid', '');
$manageBlogs->setFormField('publish_comments', 'Yes');
/*********** Page Navigation Start *********/
$manageBlogs->setFormField('orderby_field', 'blog_id');
$manageBlogs->setFormField('orderby', 'DESC');
$manageBlogs->setFormField('start', '0');
$manageBlogs->setFormField('numpg', $CFG['data_tbl']['numpg']);
$manageBlogs->setMinRecordSelectLimit(2);
$manageBlogs->setMaxRecordSelectLimit($CFG['data_tbl']['max_record_select_limit']);
$manageBlogs->setNumPerPageListArr($CFG['data_tbl']['numperpage_list_arr']);
$manageBlogs->setTableNames(array($CFG['db']['tbl']['blogs'] .' as b LEFT JOIN '.$CFG['db']['tbl']['users'].' AS u on b.user_id = u.'.$manageBlogs->getUserTableField('user_id')));
$manageBlogs->setReturnColumns(array('b.blog_id', 'b.subject', 'b.seo_title', 'b.blog_category_id', 'b.accept_comments', 'b.total_comments', 'b.total_views', 'b.user_id AS uid', 'CASE when status=\'Active\' then  \''.$LANG['common_display_active'].'\' when status=\'Inactive\' then \''.$LANG['common_display_inactive'].'\' when status=\'Toactivate\' then \''.$LANG['common_unpublished'].'\' END status', 'b.date_added', 'b.abuse_count', 'b.video_id', 'b.audio_id', 'b.external_video_id', 'b.external_audio_id', 'b.user_id AS img_user_id', $manageBlogs->getUserTableFields(array('name', 'display_name', 'image_path', 'gender', 't_height', 't_width','s_height', 's_width','photo_server_url', 'photo_ext'))));
/************ page Navigation stop *************/
//set Form Fields
$manageBlogs->resetFieldsArray();
//show default pages
$manageBlogs->setPageBlockShow('selBlogsListBlock');
$manageBlogs->sanitizeFormInputs($_REQUEST);
if(!$manageBlogs->getFormField('rid'))
	$manageBlogs->generateRandomId();
if($manageBlogs->isFormPOSTed($_POST,'add_submit'))
	{
		$manageBlogs->doDefaultValidation();

		if(chkVideoModuleAllowed('blog'))
			$manageBlogs->chkIsValidCaptureVideoFile();
		if(chkAudioModuleAllowed('blog'))
			$manageBlogs->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
		$manageBlogs->setFormfield('message' ,$filter->process($manageBlogs->getFormfield('message')));
		if($manageBlogs->isValidFormInputs())
			{
				$manageBlogs->setFormField('message', html_entity_decode($manageBlogs->getFormField('message'), ENT_QUOTES, $CFG['site']['charset']));
				$manageBlogs->setFormField('seo_title', $manageBlogs->getSeoTitleForBlogs($manageBlogs->getFormField('subject'), $manageBlogs->getFormField('blog_id')));
				if ($CFG['debug']['store_log'])
					{
						$manageBlogs->createErrorLogFile('blog');
					}
				$manageBlogs->addBlog();
				if ($CFG['debug']['store_log'])
					{
						$manageBlogs->closeErrorLogFile();
					}

				$manageBlogs->setCommonSuccessMsg($LANG['msg_success_added']);
				$manageBlogs->setPageBlockShow('block_msg_form_success');
				$manageBlogs->resetFieldsArray();
			}
		else
			{
				$manageBlogs->setPageBlockShow('blogsEditor');
				$manageBlogs->setCommonErrorMsg($LANG['common_msg_error_sorry']);
				$manageBlogs->setPageBlockShow('block_msg_form_error');
			}
	}
else if($manageBlogs->isFormPOSTed($_POST,'update_submit'))
	{
		$manageBlogs->doDefaultValidation();
		if(chkVideoModuleAllowed('blog'))
			$manageBlogs->chkIsValidCaptureVideoFile();
		if(chkAudioModuleAllowed('blog'))
			$manageBlogs->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
		$manageBlogs->setFormfield('message' ,$filter->process($manageBlogs->getFormfield('message')));
		if($manageBlogs->isValidFormInputs())
			{
				$manageBlogs->setFormField('message', html_entity_decode($manageBlogs->getFormField('message'), ENT_QUOTES, $CFG['site']['charset']));
				$manageBlogs->setFormField('seo_title', $manageBlogs->getSeoTitleForBlogs($manageBlogs->getFormField('subject'), $manageBlogs->getFormField('blog_id')));
				if ($CFG['debug']['store_log'])
					{
						$manageBlogs->createErrorLogFile('blog');
					}
				$manageBlogs->updateBlog();
				if ($CFG['debug']['store_log'])
					{
						$manageBlogs->closeErrorLogFile();
					}

				$manageBlogs->setCommonSuccessMsg($LANG['msg_success_update']);
				$manageBlogs->setPageBlockShow('block_msg_form_success');
				if ($manageBlogs->getFormField('redirect'))
					Redirect2URL($CFG['site']['relative_url'].'blogComment.php?blog_id='.$manageBlogs->getFormField('blog_id').'&msg=edited');
				$manageBlogs->resetFieldsArray();
			}
		else
			{
				$manageBlogs->setCommonErrorMsg($LANG['common_msg_error_sorry']);
				$manageBlogs->setPageBlockShow('block_msg_form_error');
				$manageBlogs->setPageBlockShow('blogsEditor');
				$manageBlogs->setPageBlockShow('blogsEditBlock');
			}
	}
else if($manageBlogs->isFormPOSTed($_POST,'cancel_submit') || $manageBlogs->isFormPOSTed($_POST,'update_canecl'))
	{
		Redirect2URL($CFG['site']['relative_url'].'manageBlogs.php');
		$manageBlogs->resetFieldsArray();
	}
else if($manageBlogs->isFormGETed($_GET, 'act'))
	{
		$manageBlogs->setPageBlockShow('blogsEditor');
		if($manageBlogs->getFormField('act')=='edt')
			{
				if($manageBlogs->populateBlogsValue())
					$manageBlogs->setPageBlockShow('blogsEditBlock');
			}
	}
else if($manageBlogs->isFormPOSTed($_POST, 'action_blog'))
	{
		if($manageBlogs->getFormField('act')=='delete')
			{
				$manageBlogs->deleteSelectedBlogs();
				$manageBlogs->setCommonSuccessMsg($LANG['manageBlogs_success_deleted']);
			}
		if($manageBlogs->getFormField('act')=='Toactivate')
			{
				$manageBlogs->changeStatus('Inactive',false);
				$manageBlogs->setCommonSuccessMsg($LANG['success_toactivate']);
			}
		if($manageBlogs->getFormField('act')=='Active')
			{
				$manageBlogs->changeStatus('Active',false);
				$manageBlogs->setCommonSuccessMsg($LANG['success_active']);
			}
		if($manageBlogs->getFormField('act')=='Publish')
			{
				$manageBlogs->changeStatus('Active',true);
				$manageBlogs->setCommonSuccessMsg($LANG['success_publish']);
			}
		$manageBlogs->setPageBlockShow('block_msg_form_success');
		$manageBlogs->resetFieldsArray();
	}
else if($manageBlogs->isFormGETed($_GET, 'del'))
	{
		$manageBlogs->setCommonSuccessMsg($LANG['manageBlogs_success_deleted']);
		$manageBlogs->setPageBlockShow('block_msg_form_success');
	}
if($manageBlogs->isFormGETed($_GET, 'add'))
	{
		$manageBlogs->setPageBlockShow('blogsEditor');
	}
$manageBlogs->manageBlogsCommon['page_title']	=	$LANG['manageBlogs_title'];
if($manageBlogs->isShowPageBlock('blogsEditor'))
	{
		$manageBlogs->setPageBlockHide('selBlogsListBlock');
		if($manageBlogs->isShowPageBlock('blogsEditBlock'))
			$manageBlogs->manageBlogsCommon['page_title']	=	$LANG['manageBlogs_page_edit_title'];
		else
			$manageBlogs->manageBlogsCommon['page_title']	=	$LANG['common_add_blog'];
	}
//<<<<--------------------Code Ends----------------------//
//--------------------Page block templates begins-------------------->>>>>//
$manageBlogs->blogsEditor['hidden_array']	=	array();
if ($manageBlogs->isShowPageBlock('blogsEditor'))
	{
		$manageBlogs->blogsEditor['populateBlogCatagory']	=	$manageBlogs->populateBlogCatagory();
		$manageBlogs->blogsEditBlock['manageBlogs_arr'] = $manageBlogs->declareBlogValues();
		$manageBlogs->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');
		$manageBlogs->blogsEditor['hidden_array']	=	array('redirect');
		if($manageBlogs->isShowPageBlock('blogsEditBlock'))
			{
				$manageBlogs->blogsEditBlock['array']	=	array('start', 'blog_id');
			}
	}
if($manageBlogs->isShowPageBlock('selBlogsListBlock'))
	{
		/****** navigtion continue*********/
		$manageBlogs->buildSelectQuery();
		$manageBlogs->buildConditionQuery();
		$manageBlogs->buildSortQuery();
		$manageBlogs->buildQuery();
		$manageBlogs->executeQuery();

		if($manageBlogs->isResultsFound())
			{
				$manageBlogs->selBlogsListBlock['anchor']	=	'dAltMlti';
				$manageBlogs->selBlogsListBlock['populateHidden']	=	array('start', 'orderby_field', 'orderby');
				$manageBlogs->selBlogsListBlock['showBlogsList']	=	$manageBlogs->showBlogsList();
				$smartyObj->assign('smarty_paging_list', $manageBlogs->populatePageLinksGET($manageBlogs->getFormField('start')));
				$manageBlogs->selBlogsListBlock['Confirmation_Publish']	=	'{Confirmation(\'selMsgConfirmList\', \'deleteForm\', Array(\'blog_id\', \'act\', \'confirmation_msg\'), Array(multiCheckValue, \'Publish\', \''.nl2br($LANG['activate_publish_message']).'\'), Array(\'value\', \'value\', \'innerHTML\'), \'blogsListForm\')};';
				$manageBlogs->selBlogsListBlock['Confirmation_Active']	=	'{Confirmation(\'selMsgConfirmList\', \'deleteForm\', Array(\'blog_id\', \'act\', \'confirmation_msg\'), Array(multiCheckValue, \'Active\', \''.nl2br($LANG['activate_confirmation']).'\'), Array(\'value\', \'value\', \'innerHTML\'), \'blogsListForm\');}';
				$manageBlogs->selBlogsListBlock['Confirmation_Toactivate']	=	'{Confirmation(\'selMsgConfirmList\', \'deleteForm\', Array(\'blog_id\', \'act\', \'confirmation_msg\'), Array(multiCheckValue, \'Toactivate\',\''.nl2br($LANG['toactivate_confirmation']).'\'), Array(\'value\', \'value\', \'innerHTML\'), \'blogsListForm\')};';
				$manageBlogs->selBlogsListBlock['Confirmation_delete']	=	'{Confirmation(\'selMsgConfirmList\', \'deleteForm\', Array(\'blog_id\', \'act\', \'confirmation_msg\'), Array(multiCheckValue, \'delete\', \''.nl2br($LANG['delete_confirmation']).'\'), Array(\'value\', \'value\', \'innerHTML\'), \'blogsListForm\');}';
			}
	}
//include the header file
$manageBlogs->includeHeader();
//include the content of the page
setTemplateFolder('admin/', $CFG['admin']['index']['blog_module']);
$smartyObj->display('manageBlogs.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>
<?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--------------------//
$manageBlogs->includeFooter();
?>