<?php
/**
 * Class to handle the form fields
 *
 * This is having class FormHandler to handle the validation of form fields, to
 * set or get values for form fields, to handle page blocks, to handle CSS for
 * form fields and to populate the common static array file.
 *
 * PHP version 5.0
 *
 * @category	Anova
 * @package		AnovaHandler
 * @author		anandaraj_088at09
 * @copyright	Copyright (c) 2009 - 2010 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id : $
 * @since 		2010-07-15
 */
if(class_exists('ListRecordsHandler'))
	{
		$parent_class = 2;
	}
else
	{
		$parent_class = 1;
	}

switch($parent_class)
	{
		case 2:
			class Handlers extends ListRecordsHandler{}
			break;
		case 1:
		default:
			class Handlers extends FormHandler{}
			break;
	}

class AnovaHandler extends Handlers
	{

		/**
		 * @var		array array of error tips for fields
		 */
		protected $fields_err_tip_arr = array();

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function isShowIndexBlock($block, $userAllowed='yes')
			{
				$ok = true;
				switch($block){
					case 'no':
						$ok = false;
						break;
					case 'yes':
						if ($userAllowed != 'yes')
							$ok = false;
						break;
				} // switch
				return $ok;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayProfileImage($img_arr, $img_type, $showPopup = true, $contentDisplay = false)
			{
				displayProfileImage($img_arr, $img_type, $showPopup, $contentDisplay);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayBlogUserSmallImage($img_arr, $showPopup = true)
		    {
				$this->displayProfileImage($img_arr, 'tiny', $showPopup);
		    }

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function insertUsersAnswerLog()
			{
				if (isset($_SESSION['is_user_log_available']))
					return ;

				$uid = $this->CFG['user']['user_id'];
				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['users_ans_log'].
						' WHERE user_id='.$this->dbObj->Param($uid);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($uid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if (!$rs->PO_RecordCount())
					{
						$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['users_ans_log'].
								' SET user_id='.$this->dbObj->Param($uid);
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($uid));
						if (!$rs)
							    trigger_db_error($this->dbObj);
					}

				//To know points for viewing updated
				$_SESSION['is_user_log_available'] = true;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function insertAdvanceSearch()
			{
				if (isset($_SESSION['is_advance_search_available']))
					return ;

				$uid = $this->CFG['user']['user_id'];
				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['advanced_search'].
						' WHERE user_id='.$this->dbObj->Param($uid);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($uid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if (!$rs->PO_RecordCount())
					{
						$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['advanced_search'].
								' SET user_id='.$this->dbObj->Param($uid);
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($uid));
						if (!$rs)
							    trigger_db_error($this->dbObj);
					}

				//To know points for viewing updated
				$_SESSION['is_advance_search_available'] = true;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getExternalVideoDetails($external_video_id)
			{
				$sql = 'SELECT video_id, video_for, video_ext, video_flv_url, flv_upload_type, video_status, video_encoded_status'.
						' FROM '.$this->CFG['db']['tbl']['ans_video'].
						' WHERE video_id = '.$this->dbObj->Param($external_video_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($external_video_id));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					return $rs->FetchRow();
				return false;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getExternalAudioDetails($external_audio_id)
			{
				$sql = 'SELECT audio_id, audio_for, audio_ext, audio_url, audio_upload_type, audio_status, audio_encoded_status'.
						' FROM '.$this->CFG['db']['tbl']['ans_audio'].
						' WHERE audio_id = '.$this->dbObj->Param($external_audio_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($external_audio_id));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					return $rs->FetchRow();
				return false;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getUserOptions()
			{
				$user_options = array('recent_questions'=>'yes', 'best_answered_questions'=>'yes',
									  'popular_questions'=>'yes', 'recently_answered'=>'yes',
									  'recent_forums'=>'yes', 'recent_blogs'=>'yes', 'featured_analyst'=>'yes',
									  'popular_videos'=>'yes', 'recent_debates'=>'yes', 'popular_debates'=>'yes');
				if ($uid = $this->CFG['user']['user_id'])
					{
						$sql = 'SELECT index_block FROM '.$this->CFG['db']['tbl']['users_ans_log'].
								' WHERE user_id='.$this->dbObj->Param($uid);
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($uid));
						if (!$rs)
							    trigger_db_error($this->dbObj);
						if ($rs->PO_RecordCount())
							{
								$row = $rs->FetchRow();
								if ($row['index_block'])
									{
										$index_blocks = unserialize($row['index_block']);
										foreach($index_blocks as $block=>$value){
											$user_options[$block] = $value;
										}
									}
							}
					}
				return $user_options;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayForumUserSmallImage($img_arr, $showPopup = true, $contentDisplay = false, $changePosition = false)
			{
				displayProfileImage($img_arr, 'tiny', $showPopup, $contentDisplay, $changePosition);
				return ;
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getUserTableFields($user_fields, $trim=true)
		    {
				$str = '';
				foreach($user_fields as $field){
					if (isset($this->CFG['users'][$field]) AND $this->CFG['users'][$field])
						$str .= $this->CFG['users'][$field].' AS '.$field.', ';
				}
				if ($trim)
					$str = substr($str, 0, strrpos($str, ', '));
				return $str;
		    }

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getUserTableField($user_field)
		    {
		    	if (isset($this->CFG['users'][$user_field]) AND $this->CFG['users'][$user_field])
					return $this->CFG['users'][$user_field];
		    }

		/**
		 * get username for user_id
		 *
		 * @param 		string $user_table
		 * @param 		integer $user_id
		 * @return 		string
		 * @access 		public
		 */
		public function getUserDetailsFromUsersTable($user_table, $user_id)
			{
				if (isset($this->_cache_user_details[$user_id]))
					{
						return $this->_cache_user_details[$user_id];
					}

				$sql = 'SELECT '.$this->getUserTableFields(array('user_id', 'name', 'display_name', 'email', 'image_path', 'bio', 'gender', 'usr_status', 'user_access', 't_height', 't_width', 's_height', 's_width', 'photo_server_url', 'photo_ext', 'usr_type', 'expiry_date', 'last_paid_date', 'signup_type', 'receipt_id', 'payment_gateway')).
						', '.$this->getUserTableField('user_id').' AS img_user_id'.
						' FROM '.$user_table.
						' WHERE '.$this->getUserTableField('user_id').' = '.$this->dbObj->Param($user_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($user_id));
				if (!$rs)
						trigger_db_error($this->dbObj);
				$row = array('name'=>'', 'display_name'=>'', 'email'=>'', 'image_path'=>'', 'gender'=>'', 'usr_status'=>'', 'user_access'=>'', 'img_user_id'=>'', 't_height'=>'', 't_width'=>'', 's_height'=>'', 's_width'=>'', 'photo_server_url'=>'', 'photo_ext'=>'', 'usr_type'=>'', 'expiry_date'=>'', 'last_paid_date'=>'', 'signup_type'=>'', 'receipt_id'=>'', 'payment_gateway'=>'');
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
					}

				//cache user detalis
				$this->_cache_user_details[$user_id] = $row;

				return	$row;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getUserLog($user_id)
			{
				if (isset($this->_cache_user_log_details[$user_id]))
					{
						return $this->_cache_user_log_details[$user_id];
					}
				$sql = 'SELECT total_ques, total_ans, total_points, total_best_ans, total_debates, total_debate_response'.
						', DATE_FORMAT(date_updated,\'%D %b %Y\') as date_updated'.
						' FROM '.$this->CFG['db']['tbl']['users_ans_log'].
						' WHERE user_id='.$this->dbObj->Param($user_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($user_id));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				$user_ans_log = array('total_ques'=>'0', 'total_ans'=>'0', 'total_points'=>'0', 'date_updated'=>'');
				if ($rs->PO_RecordCount())
					$user_ans_log = $rs->FetchRow();

				//cache user log details
				$this->_cache_user_log_details[$user_id] = $user_ans_log;

				return $user_ans_log;
			}

				/**
		 * Function to create week top analysts
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function createWeekExperts()
			{
				$sql = 'SELECT TIMEDIFF(NOW(), date_added) time_diff FROM '.$this->CFG['db']['tbl']['view_weekly_experts'].
						' LIMIT 0, 1';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						$time_diff = explode(':', $row['time_diff']);
						$mins_after_created = ($time_diff[0]*60)+($time_diff[1]);
						$mins_after_created = ($time_diff[2])?($mins_after_created+1):$mins_after_created;
						if ($mins_after_created < $this->CFG['admin']['week_experts']['refresh'])
							{
								return ;
							}
					}

				$sql = 'CREATE OR REPLACE VIEW view_ques_expert AS'.
						' SELECT COUNT( ques_id ) AS \'total_count\', user_id,'.
						' (COUNT( ques_id ) * '.$this->CFG['admin']['ask_answers']['points'].') AS \'points\''.
						' FROM '.$this->CFG['db']['tbl']['questions'].
						' WHERE DATE_ADD(date_asked, INTERVAL 7 DAY) >= NOW()'.
						' GROUP BY user_id';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);

				$sql = 'CREATE OR REPLACE VIEW view_ans_expert AS'.
						' SELECT COUNT( ans_id ) AS \'total_count\', user_id,'.
						' (COUNT( ans_id ) * '.$this->CFG['admin']['reply_answers']['points'].') AS \'points\''.
						' FROM '.$this->CFG['db']['tbl']['answers'].
						' WHERE DATE_ADD(date_answered, INTERVAL 7 DAY) >= NOW()'.
						' GROUP BY user_id';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);

				$sql = 'CREATE OR REPLACE ALGORITHM=MERGE VIEW view_experts AS'.
						' SELECT * FROM view_ques_expert UNION ALL SELECT * FROM view_ans_expert';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);

				$sql = 'TRUNCATE TABLE '.$this->CFG['db']['tbl']['view_weekly_experts'];
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);

				$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['view_weekly_experts'].
						' SELECT user_id, SUM(points) AS \'week_points\', NOW() FROM view_experts GROUP BY user_id';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getBlogCategory($cat_id)
			{
				if (!$cat_id) return false;

				if (isset($this->_cache_blog_category_details[$cat_id]))
					{
						return $this->_cache_blog_category_details[$cat_id]['blog_category_name'];
					}

				$sql = 'SELECT blog_category_name FROM '.$this->CFG['db']['tbl']['blog_category'].
					   ' WHERE blog_category_id='.$cat_id;
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						//cache blog category name
						$this->_cache_blog_category_details[$cat_id] = $row;

						return $row['blog_category_name'];
					}
				return false;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getSeoTitle($table_name='', $title_field='', $current_title_value='', $primary_field='', $primary_field_value='')
			{
				if ($primary_field_value)
					{
						$sql = 'SELECT seo_title FROM '.$table_name.
								' WHERE '.$primary_field.'='.$this->dbObj->Param($primary_field_value).
								' AND '.$title_field.'='.$this->dbObj->Param($current_title_value);

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

						// execute sql
						$rs = $this->dbObj->Execute($stmt, array($primary_field_value, $current_title_value));

						//raise user error... fatal
						if (!$rs)
							trigger_db_error($this->dbObj);
						if ($rs->PO_RecordCount())
							{
								$row = $rs->FetchRow();
								$seoTitle = trim($row['seo_title']);
								if ($seoTitle)
									{
										return $seoTitle;
									}
							}
					}

				$primaryCheck = '';
				$sql =  'SELECT COUNT('.$title_field.') AS title_count'.
						' FROM '.$table_name.
						' WHERE '.$title_field.' = '.$this->dbObj->Param($current_title_value);
				$paramFields = array($current_title_value);

				$sql = $sql.$primaryCheck;
				// prepare sql
				$stmt = $this->dbObj->Prepare($sql);
				// execute sql
				$rs = $this->dbObj->Execute($stmt, array($paramFields));
				//raise user error... fatal
				if (!$rs)
					trigger_db_error($this->dbObj);
				$row = $rs->FetchRow();
				$previousEntryCount = $row['title_count'];
				$seoTitle = $current_title_value;
				//Convert charset
				$seoTitle = seoFriendlyAnovaText($seoTitle, $this->CFG['site']['charset']);
				//$seoTitle = ereg_replace ('[^a-zA-Z0-9]', '-', trim($seoTitle));
				$seoTitle = preg_replace('/(-)+$/','',$seoTitle);
				//Removed repeated - symbol
				$seoTitle = ereg_replace('([-]+)', '-', trim($seoTitle));
				$seoTitle = ($seoTitle)?$seoTitle:'1';
				$seoTitle .= $previousEntryCount?'-'.$previousEntryCount:'';

				$seoTitle = $this->getSeoName($table_name, $primary_field, 'seo_title', $seoTitle);

				return $seoTitle;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function removeDuplicateKeywords($keywords)
			{
				$not_allowed_search_array = $this->CFG['admin']['not_allowed_chars'];
				$keywords = replaceCharacter($not_allowed_search_array, '', $keywords);
				$keywords_arr = explode(' ', $keywords);
				$keywords_arr = array_unique($keywords_arr);
				foreach($keywords_arr as $key=>$value)
					{
						$len = strlen($value);
						if(!($len>=$this->CFG['admin']['tag_min_size'] and $len<=$this->CFG['admin']['tag_max_size']))
							unset($keywords_arr[$key]);
					}
				$keywords = implode(' ', $keywords_arr);
				return trim($keywords);
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function checkAndRenameString($table_name, $primary_key_field, $to_field_name, $str)
			{
				$sql_sub_sub = 'SELECT COUNT('.$primary_key_field.') as cnt FROM '.$table_name.' WHERE
								'.$to_field_name.' = '.$this->dbObj->Param($str);

				$stmt_sub_sub = $this->dbObj->Prepare($sql_sub_sub);
				$rs_sub_sub = $this->dbObj->Execute($stmt_sub_sub, array($str));
				//raise user error... fatal
				if (!$rs_sub_sub)
						trigger_db_error($this->dbObj);
				$row_sub_sub = $rs_sub_sub->FetchRow();
				if ($row_sub_sub['cnt'] > 0)
					return true;
				return false;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getSeoName($table_name, $primary_key_field, $to_field_name, $str_to_convert)
			{
				$temp_str = $to_str = $str_to_convert;
				if ($check = $this->checkAndRenameString($table_name, $primary_key_field, $to_field_name, $to_str))
				{
					$i = 0;
					while(true)
						{
							$to_str = $temp_str.'-'.++$i;
							if (!$this->checkAndRenameString($table_name, $primary_key_field, $to_field_name, $to_str))
								break;
						}
				}
				return $to_str;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getSeoTitleForForum($forum_title = '', $forum_id = 0)
			{
				return $this->getSeoTitle($this->CFG['db']['tbl']['forums'], 'forum_title' ,$forum_title , 'forum_id', $forum_id);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getSeoTitleForQuestion($question = '', $ques_id = 0)
			{
				return $this->getSeoTitle($this->CFG['db']['tbl']['questions'], 'question' ,$question , 'ques_id', $ques_id);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getSeoTitleForQuestionCategory($cat_name = '', $cat_id = 0)
			{
				return $this->getSeoTitle($this->CFG['db']['tbl']['questions_category'], 'cat_name' ,$cat_name , 'cat_id', $cat_id);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getSeoTitleForForumTopic($forum_topic = '', $topic_id = 0)
			{
				return $this->getSeoTitle($this->CFG['db']['tbl']['forum_topics'], 'forum_topic' ,$forum_topic , 'topic_id', $topic_id);
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function isAllowedToAsk()
		    {
				$uid = $this->CFG['user']['user_id'];
				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['users_ans_log'].
						' WHERE user_id='.$this->dbObj->Param($uid).' AND is_blocked=\'No\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($uid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					return true;
				return false;
		    }

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getContentDetails($row)
			{
				$contentDetails = array();

				switch($row['type_for']){
					case 'Question':
						$contentDetails = $this->getQuestionDetails($row['content_id']);
						if ($contentDetails)
							$contentDetails['link'] = $contentDetails['qLink'];
						break;
					case 'Answer':
						$contentDetails = $this->getAnswerDetails($row['content_id']);
						if ($contentDetails)
							$contentDetails['link'] = $contentDetails['aLink'];
						break;
					case 'Blog':
						$contentDetails = $this->getBlogDetails($row['content_id']);
						if ($contentDetails){
							$contentDetails['question'] = $contentDetails['subject'];
							$contentDetails['link'] = $contentDetails['blink'];
						}
						break;
					case 'Blogcomment':
						$contentDetails = $this->getBlogComments($row['content_id']);
						if ($contentDetails){
							$contentDetails['question'] = $contentDetails['subject'];
							$contentDetails['link'] = $contentDetails['blink'];
						}
						break;
					case 'Forumresponse':
						$contentDetails = $this->getForumResponses($row['content_id']);
						if ($contentDetails){
							$contentDetails['question'] = $contentDetails['topic'];
							$contentDetails['link'] = $contentDetails['forumtopic_link'];
						}
						break;
					case 'Debate':
						$contentDetails = $this->getDebateDetails($row['content_id']);
						if ($contentDetails){
							$contentDetails['link'] = $contentDetails['dLink'];
							$contentDetails['question'] = $contentDetails['subject'];
						}
						break;
				} // switch

				$img_attributes = '';
				if ($contentDetails)
					{
						if ($row['type'] == 'video')
							{
								$imgSrc = '';
					            $ext_video_id = $contentDetails['external_video_id'];
								$identifyContent = $row['type_for'].$ext_video_id.$row['content_id'];
								if($ext_video_id == $row['type_id'])
									{
										$img_file = $this->CFG['site']['url'].$this->CFG['admin']['ans_videos']['thumbnail_folder'].getImageName($ext_video_id).'T.'.$this->CFG['video']['image']['extensions'];
										$member_file = '../'.$this->CFG['admin']['ans_videos']['thumbnail_folder'].getImageName($ext_video_id).'T.'.$this->CFG['video']['image']['extensions'];
										$root_file = $this->CFG['admin']['ans_videos']['thumbnail_folder'].getImageName($ext_video_id).'T.'.$this->CFG['video']['image']['extensions'];
										if(file_exists($member_file) OR file_exists($root_file))
											{
												$imgSrc = $img_file;
											}
										else
											{
												$imgSrc = $this->CFG['site']['url'].'design/templates/'. $this->CFG['html']['template']['default'].'/images/popular_audio.jpg';
											}
										$this->contentDisplayedArray[] = $identifyContent;
									}
								else if ($video_id = $contentDetails['video_id'])
									{
										$imgSrc = $this->CFG['site']['url'].$this->CFG['admin']['ans_videos']['thumbnail_folder'].getImageName($video_id).'T.'.$this->CFG['video']['image']['extensions'];
										$img_attributes = GET_IMAGE_ATTRIBUTES('83', '58', $this->CFG['admin']['ans_videos']['thumb_width'], $this->CFG['admin']['ans_videos']['thumb_height']);
									}
							}

						if ($row['type'] == 'audio')
							$imgSrc = $this->CFG['site']['url'].'design/templates/'.$this->CFG['html']['template']['default'].'/images/popular_audio.jpg';

						//image source
						$contentDetails['imgSrc'] = $imgSrc;
						$contentDetails['img_attributes'] = $img_attributes;
					}
				return $contentDetails;
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function showCategoryName($cat_id)
		    {
				if (isset($this->_cache_category_details[$cat_id]))
					{
						$row = $this->_cache_category_details[$cat_id];
						$showCategoryName_val = '<a href="'.getAnovaUrl('questions', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/').'">'.$row['cat_name'].'</a>';
						return $showCategoryName_val;
					}

				$sql = 'SELECT cat_name, seo_title, cat_id FROM '.$this->CFG['db']['tbl']['questions_category'].
						' WHERE cat_id='.$this->dbObj->Param('cat_id');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($cat_id));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						//cache category details
						$this->_cache_category_details[$cat_id] = $row;
						$showCategoryName_val = '<a href="'.getAnovaUrl('questions', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/').'">'.$row['cat_name'].'</a>';
						return $showCategoryName_val;
					}
				return false;
		    }
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getUsersDisplayName($name)
			{
				$sql = 'SELECT '.$this->getUserTableField('display_name').' as display_name'.
						' FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE '.$this->getUserTableField('name').' = '.$this->dbObj->Param($name);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($name));
				if (!$rs)
						trigger_db_error($this->dbObj);
				$display_name = '';
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						$display_name = $row['display_name'];
					}
				return	$display_name;
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function updateQuestionViews()
		    {
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['questions'].
						' SET total_views=total_views+1'.
						' WHERE ques_id='.$this->dbObj->Param('qid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['qid']));
				if (!$rs)
				        trigger_db_error($this->dbObj);
		    }

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

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getEmailOptionsOfUser($uid)
		    {
				$sql = 'SELECT subscribe_keywords, keyword_mail, reply_mail, favorite_mail, best_ans_mail, abuse_mail'.
						' FROM '.$this->CFG['db']['tbl']['users_ans_log'].
						' WHERE user_id='.$this->dbObj->Param('uid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($uid));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				$row = array('subscribe_keywords' => '', 'keyword_mail' => 'Yes', 'reply_mail' => 'Yes',
							 'favorite_mail' => 'Yes', 'best_ans_mail' => 'Yes', 'abuse_mail' => 'Yes');
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row;
		    }

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function chkIsAnswerAbusedAlready($aid)
			{
				$uid = $this->CFG['user']['user_id'];
				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['abuse_answers'].
						' WHERE ans_id='.$this->dbObj->Param('aid').
						' AND reported_by='.$this->dbObj->Param('uid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($aid, $uid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					return true;
				return false;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function increaseBestAnswerPoints($uid)
			{
				if ($uid and $this->CFG['admin']['best_answers']['allowed'])
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['users_ans_log'].
								' SET total_points = total_points + '.$this->CFG['admin']['best_answers']['points'].
								' , total_best_ans = total_best_ans + 1'.
								' WHERE user_id='.$this->dbObj->Param($uid);
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($uid));
						if (!$rs)
							    trigger_db_error($this->dbObj);
					}
			}

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function populateCategories()
		    {
				$populateCategories_arr = array();
				$sql = 'SELECT cat_id, cat_name FROM '.$this->CFG['db']['tbl']['questions_category'].' WHERE parent_id=0 AND status=\'1\' ORDER BY cat_name';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow()) {
							$populateCategories_arr[$row['cat_id']] = wordWrapManual($row['cat_name'],$this->CFG['admin']['category']['line_length'], $this->CFG['admin']['category']['short_length']);
						} // while
					}
				return $populateCategories_arr;
		    }

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function populateSubCategories($cid)
		    {
				if (!$cid)
					return ;
				$populateSubCategories_arr = array();
				$sql = 'SELECT cat_id, cat_name FROM '.$this->CFG['db']['tbl']['questions_category'].
						' WHERE parent_id='.$this->dbObj->Param('cid').
						' AND parent_id!=0'.
						' AND status=\'1\' ORDER BY cat_name';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($cid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow()) {
							$populateSubCategories_arr[$row['cat_id']] = $row['cat_name'];
						} // while
					}
				return $populateSubCategories_arr;
		    }
		/**
		 * get user details user_id
		 *
		 * @param 		integer $user_id
		 * @return 		string
		 * @access 		public
		 */
		public function getUserDetails($user_id)
			{
				if (isset($this->_cache_user_details[$user_id]))
					{
						return $this->_cache_user_details[$user_id];
					}

				$sql = 'SELECT '.$this->getUserTableFields(array('user_id', 'display_name', 'name', 'email', 'image_path', 'gender', 'usr_status', 'user_access', 't_height', 't_width', 's_height', 's_width', 'photo_server_url', 'photo_ext')).
						', '.$this->getUserTableField('user_id').' AS img_user_id'.
						' FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE '.$this->getUserTableField('user_id').'='.$this->dbObj->Param($user_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($user_id));
				if (!$rs)
						trigger_db_error($this->dbObj);
				$row = array('name'=>'', 'display_name'=>'', 'email'=>'', 'image_path'=>'', 'gender'=>'', 'usr_status'=>'', 'user_access'=>'', 'img_user_id'=>'', 't_height'=>'', 't_width'=>'', 's_height'=>'', 's_width'=>'', 'photo_server_url'=>'', 'photo_ext'=>'');
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
					}
				//cache user details
				$this->_cache_user_details[$user_id] = $row;

				return	$row;
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function showQuestionList()
			{
				global $smartyObj;
				$showQuestionList_arr = array();
				$i = 0;
				if($this->getFormField('question')=='both_av')
					{
						$this->ques_type = $this->LANG['audio_video'];
					}
				else
					{
						$this->ques_type = ucfirst($this->getFormField('question'));
					}

			   if($this->getFormField('type') != 'ask_only')
				   {
				   		$showQuestionList_arr['row'] = array();
				   		$inc = 1;
						while($row = $this->fetchResultRecord())
							{
								$i++;
								$showQuestionList_arr['row'][$inc]['clsOddOrEvenQuestion'] = 'clsEvenQuestion';
								if ($i%2)
									$showQuestionList_arr['row'][$inc]['clsOddOrEvenQuestion'] = 'clsOddQuestion';

								$ques = strip_tags($row['question']);

								$showQuestionList_arr['row'][$inc]['answer']['url'] = getAnovaUrl('answer', '?title='.$row['seo_title'], $row['seo_title'].'/');
								$showQuestionList_arr['row'][$inc]['question_manual'] = wordWrapManual($ques, $this->CFG['admin']['question']['line_length'], $this->CFG['admin']['question']['short_length']);
								$inc++;
							}
	                 }
				$showQuestionList_arr['form_action'] = getAnovaUrl('widgetgenerate', '', '', 'members');
				$smartyObj->assign('showQuestionList_arr', $showQuestionList_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('showQuestionList.tpl');
			}

		/**
		 *
		 * @param mixed $id
		 * @param mixed $type
		 * @return
		 */
		public function hasAnyAttachment($id, $type)
			{
				$sql = 'SELECT attachment_id, attachment_name, photo_server_url FROM '.$this->CFG['db']['tbl']['attachments'].
						' WHERE content_id='.$id.
						' AND content_type=\''.$type.'\' ORDER BY attachment_id';

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

				$attachment_details = array();
				if ($rs->PO_RecordCount())
					{
						$attachment_details = $rs->FetchRow();
					}
				return $attachment_details;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getQuestionDetails($ques_id=0)
			{
				if (isset($this->_cache_question_details[$ques_id]))
					{
						return $this->_cache_question_details[$ques_id];
					}
				$questionDetails = array();

				$sql = 'SELECT q.ques_id, q.total_answer, q.votes, q.cat_id, q.pcat_id, q.best_ans_id, q.status,q.description, q.total_stars, q.question, UNIX_TIMESTAMP(date_asked) as date_asked'.
						', '.$this->getUserTableField('display_name').' as asked_by, '.$this->getUserTableFields(array('image_path', 'name', 'gender', 't_height', 't_width', 'photo_server_url', 'photo_ext', 's_width', 's_height'), false).' q.user_id'.
						', q.user_id AS img_user_id, q.external_video_id, q.external_audio_id, video_id, audio_id, IF(status=\'Open\' AND date_closed>=NOW(), 1, 0) is_open, TIMEDIFF(date_closed, NOW()) as date_closed'.
						', q.total_videos, q.total_audios, q.total_views, q.seo_title FROM '.$this->CFG['db']['tbl']['questions'].' AS q, '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE q.ques_id='.$this->dbObj->Param($ques_id).
						' AND q.user_id=u.'.$this->getUserTableField('user_id').
						' AND q.status IN (\'Open\', \'Resolved\')'.
						' AND u.'.$this->getUserTableField('usr_status').'=\'Ok\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($ques_id));
				if (!$rs)
					    trigger_db_error($this->dbObj);

				if ($rs->PO_RecordCount())
					{
						$questionDetails = $rs->FetchRow();
						$questionDetails['qLink'] = getAnovaUrl('answer', '?title='.$questionDetails['seo_title'], $questionDetails['seo_title'].'/');
						$questionDetails['question_link'] = '<a href="'.$questionDetails['qLink'].'">'.wordWrapManual($questionDetails['question'], $this->CFG['admin']['question']['line_length'], $this->CFG['admin']['question']['short_length']).'</a>';
						$questionDetails['asked_by_link'] = '<a href="'.getMemberUrl($questionDetails['user_id'], $questionDetails['name']).'">'.stripString($questionDetails['asked_by'], $this->CFG['username']['medium_length']).'</a>';

						$cat_id = ($questionDetails['cat_id']) ? $questionDetails['cat_id'] : $questionDetails['pcat_id'];
						$questionDetails['showCategoryName'] = $this->showCategoryName($cat_id);

						$questionDetails['audio_on_click'] = 'ques_audio_'.$questionDetails['audio_id'];
						$questionDetails['audio_url'] = getAnovaUrl('ansviewaudio', '?pg=Question_'.$questionDetails['audio_id'], '?pg=Question_'.$questionDetails['audio_id']);

						$questionDetails['video_on_click'] = 'ques_video_'.$questionDetails['video_id'];
						$questionDetails['video_url'] = getAnovaUrl('ansviewvideo', '?pg=Question_'.$questionDetails['video_id'], '?pg=Question_'.$questionDetails['video_id']);

						$questionDetails['ext_ans_view_video']['url'] = getAnovaUrl('ansviewvideo', '?pg=Question_'.$questionDetails['external_video_id'], '?pg=Question_'.$questionDetails['external_video_id']);
		  				$questionDetails['ext_ans_view_video']['on_click'] = 'external_video_ques_'.$questionDetails['external_video_id'];

						$questionDetails['ext_ans_view_audio']['url'] = getAnovaUrl('ansviewaudio', '?pg=Question_'.$questionDetails['external_audio_id'], '?pg=Question_'.$questionDetails['external_audio_id']);
						$questionDetails['ext_ans_view_audio']['on_click'] = 'external_audio_ques_'.$questionDetails['external_audio_id'];

						$questionDetails['has_attachment'] = false;
						if ($this->CFG['admin']['attachments_questions']['allowed'] && $attachment_details = $this->hasAnyAttachment($questionDetails['ques_id'], 'Question'))
							{
								$questionDetails['has_attachment'] = true;
								$extern = strtolower(substr($attachment_details['attachment_name'], strrpos($attachment_details['attachment_name'], '.')+1));
								$attachment_original_file_name = getImageName($attachment_details['attachment_id']).$this->CFG['admin']['ans_pictures']['large_name'].'.'.$extern;
								$questionDetails['img_id'] = 'Question_'.$ques_id.'_'.$attachment_details['attachment_id'];
								$questionDetails['attachment_path'] = getAnovaUrl('answer', '?title='.$questionDetails['seo_title'].'&amp;imgdetail='.$questionDetails['img_id'], $questionDetails['seo_title'].'/?imgdetail='.$questionDetails['img_id']);
								$questionDetails['image_large_path'] = $attachment_details['photo_server_url'].$this->CFG['admin']['index']['anova_module'].'/'.$this->CFG['admin']['ans_attachments_path'].$attachment_original_file_name;
							}
					}
				//cache question details
				$this->_cache_question_details[$ques_id] = $questionDetails;

				return $questionDetails;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getAnswerDetails($ans_id)
			{
				$sql = 'SELECT a.ans_id, a.ques_id, a.votes, a.video_id, a.external_video_id, a.audio_id, a.external_audio_id, a.user_id, a.answer, a.source, TIMEDIFF(NOW(), date_answered) as date_answered'.
						', u.'.$this->getUserTableField('user_id').' as img_user_id, '.$this->getUserTableFields(array('image_path', 'gender', 't_height', 't_width', 's_height', 's_width','photo_server_url', 'photo_ext', 'name'), false).$this->getUserTableField('display_name').' as answered_by'.
						' FROM '.$this->CFG['db']['tbl']['answers'].' AS a'.
						', '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE a.user_id=u.'.$this->getUserTableField('user_id').
						' AND u.'.$this->getUserTableField('usr_status').'=\'Ok\''.
						' AND a.ans_id='.$this->dbObj->Param('aid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($ans_id));
				if (!$rs)
					    trigger_db_error($this->dbObj);

				$answerDetails = array();
				if ($rs->PO_RecordCount())
					{
						$answerDetails = $rs->FetchRow();

						$questionDetails = $this->getQuestionDetails($answerDetails['ques_id']);
						if(!isset($questionDetails['question']))
							return;
						$answerDetails['question'] = $questionDetails['question'];
						$answerDetails['date_asked'] = $questionDetails['date_asked'];
						$answerDetails['is_open'] = $questionDetails['is_open'];
						$answerDetails['seo_title'] = $questionDetails['seo_title'];
						$answerDetails['qLink'] = $questionDetails['qLink'];
						$answerDetails['question_link'] = $questionDetails['question_link'];
						$answerDetails['asked_by_link'] = $questionDetails['asked_by_link'];
                              $answerDetails['answered_by_link'] = '<a href="'.getMemberUrl($answerDetails['user_id'], $answerDetails['name']).'">'.$answerDetails['answered_by'].'</a>';
						$answerId = 'answermore'.$ans_id;
						$answerDetails['aLink'] = getAnovaUrl('answer', '?title='.$questionDetails['seo_title'], $questionDetails['seo_title'].'/').'#'.$answerId;
						$answerDetails['answer_link'] = '<a href="'.$questionDetails['qLink'].'">'.wordWrapManual($answerDetails['answer'], $this->CFG['admin']['question']['line_length'], $this->CFG['admin']['question']['short_length']).'</a>';

					}
				return $answerDetails;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getBlogDetails($blog_id)
			{
				$blogDetails = array();

				$sql = 'SELECT blog_id, subject, seo_title, message, blog_category_id, total_comments, total_views, b.user_id, b.video_id, b.audio_id, b.external_video_id, b.external_audio_id, UNIX_TIMESTAMP(date_added) as date_added, u.'.$this->getUserTableField('image_path').' AS image_path, u.'.$this->getUserTableField('user_id').' AS img_user_id , u.'.$this->getUserTableField('t_height').' AS t_height'.', u.'.$this->getUserTableField('t_width').' AS t_width, u.'.$this->getUserTableField('photo_server_url').' AS photo_server_url'.
						', u.'.$this->getUserTableField('s_width').' AS s_width, u.'.$this->getUserTableField('s_height').' AS s_height'.
						', u.'.$this->getUserTableField('gender').' AS gender'.
						', u.'.$this->getUserTableField('photo_ext').' AS photo_ext, u.'.$this->getUserTableField('name').' AS name'.
						' FROM '.$this->CFG['db']['tbl']['blogs'].' AS b'.', '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE status=\'Active\''.
						' AND b.user_id = u.user_id'.
						' AND u.'.$this->getUserTableField('usr_status').' = \'Ok\''.
						' AND blog_id='.$this->dbObj->Param($blog_id);

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

				if ($rs->PO_RecordCount())
					{
						$blogDetails = $rs->FetchRow();
						$blogDetails['blog_link'] = '<a href="'.getBlogUrl('blogcomment','?title='.$blogDetails['seo_title'], $blogDetails['seo_title'].'/').'">'.wordWrapManual($blogDetails['subject'], $this->CFG['admin']['blog']['line_length'], $this->CFG['admin']['blog']['short_length']).'</a>';
						$blogDetails['blink'] = getBlogUrl('blogcomment','?title='.$blogDetails['seo_title'], $blogDetails['seo_title'].'/');
						$blogDetails['blog_user_name'] = '<a href="'.getMemberUrl($blogDetails['user_id'], $blogDetails['name']).'">'.stripString($blogDetails['name'], $this->CFG['username']['medium_length']).'</a>';
						$blogDetails['blogcategoryname'] =  $this->getBlogCategory($blogDetails['blog_category_id']);
					}

				return $blogDetails;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getBlogComments($comment_id)
			{
				$blogDetails = array();

				$sql = 'SELECT b.blog_id, b.video_id, b.audio_id, b.external_video_id, b.external_audio_id, b.comment FROM '.$this->CFG['db']['tbl']['blog_comment'].' AS b'.', '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE b.status=\'Active\''.
						' AND b.user_id = u.user_id'.
						' AND u.'.$this->getUserTableField('usr_status').' = \'Ok\''.
						' AND b.comment_id='.$this->dbObj->Param($comment_id);

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

				if ($rs->PO_RecordCount())
					{
						$blogComments = $rs->FetchRow();
						$blogDetails = $this->getBlogDetails($blogComments['blog_id']);
						$blogDetails['video_id'] = $blogComments['video_id'];
						$blogDetails['audio_id'] = $blogComments['audio_id'];
						$blogDetails['external_video_id'] = $blogComments['external_video_id'];
						$blogDetails['external_audio_id'] = $blogComments['external_audio_id'];
						$blogDetails['blogcomment_link'] = wordWrapManual($blogComments['comment'], $this->CFG['admin']['question']['line_length'], $this->CFG['admin']['question']['short_length']);
					}

				return $blogDetails;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getForumResponses($response_id)
			{
				$forumDetails = array();

				$sql = 'SELECT f.response_id, f.topic_id, f.response_user_id, f.video_id, f.audio_id, f.external_video_id, f.external_audio_id, f.forum_response FROM '.$this->CFG['db']['tbl']['forum_response'].' AS f'.', '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE f.response_status=\'Yes\''.
						' AND f.response_user_id = u.user_id'.
						' AND u.'.$this->getUserTableField('usr_status').' = \'Ok\''.
						' AND f.response_id='.$this->dbObj->Param($response_id);

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

				if ($rs->PO_RecordCount())
					{
						$responseDetails = $rs->FetchRow();
						$forumDetails = $this->getForumTopicDetails($responseDetails['topic_id']);
						$forumDetails['video_id'] = $responseDetails['video_id'];
						$forumDetails['audio_id'] = $responseDetails['audio_id'];
						$forumDetails['external_video_id'] = $responseDetails['external_video_id'];
						$forumDetails['external_audio_id'] = $responseDetails['external_audio_id'];
						$forumDetails['user_id'] = $responseDetails['response_user_id'];
						$forumDetails['forumresponse_link'] = wordWrapManual($responseDetails['forum_response'], $this->CFG['admin']['question']['line_length'], $this->CFG['admin']['question']['short_length']);
					}

				return $forumDetails;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getForumTopicDetails($topic_id)
			{
				$topicDetails = array();

				$sql = 'SELECT t.forum_topic as topic,t.user_id as topic_ownerid, t.seo_title as topic_seo, t.forum_id as topic_forumid, f.seo_title as forum_seo,'.
							' u.display_name as topic_ownername, u.email as topic_owneremail FROM '.$this->CFG['db']['tbl']['forum_topics'].' as t LEFT JOIN '.$this->CFG['db']['tbl']['users'].' as u ON t.user_id=u.user_id,'.$this->CFG['db']['tbl']['forums'].
							' as f WHERE f.forum_id = t.forum_id AND t.topic_id = '.$this->dbObj->Param($topic_id);

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

				if ($rs->PO_RecordCount())
					{
						$topicDetails = $rs->FetchRow();
						$topicDetails['forumtopic_link'] = getForumsUrl('forumsresponses','?title='.$topicDetails['forum_seo'].'&amp;topic_title='.$topicDetails['topic_seo'], $topicDetails['forum_seo'].'/'.$topicDetails['topic_seo'].'/');
						$topicDetails['forum_link'] = '<a href='.getForumsUrl('forumsresponses','?title='.$topicDetails['forum_seo'].'&amp;topic_title='.$topicDetails['topic_seo'], $topicDetails['forum_seo'].'/'.$topicDetails['topic_seo'].'/').'>'.wordWrapManual($topicDetails['topic'], $this->CFG['admin']['forum']['line_length'], $this->CFG['admin']['forum']['short_length']).'</a>';
					}

				return $topicDetails;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getDebateDetails($did = 0)
			{
				$debateDetails = array();
				$sql = 'SELECT d.debate_id, d.total_againsts+d.total_fors as totalResponse, d.cat_id, d.best_response_id, d.status, d.total_stars, d.subject, TIMEDIFF(NOW(), date_asked) as date_asked'.
						', '.$this->getUserTableField('display_name').' as asked_by, '.$this->getUserTableFields(array('image_path', 'name', 'gender', 't_height', 't_width', 'photo_server_url', 'photo_ext', 's_width', 's_height'), false).' d.user_id'.
						', d.user_id AS img_user_id, video_id, audio_id, IF(status=\'Open\' AND date_closed>=NOW(), 1, 0) is_open, TIMEDIFF(date_closed, NOW()) as date_closed'.
						', d.total_videos, d.total_audios, d.seo_title FROM '.$this->CFG['db']['tbl']['debates'].' AS d, '.$this->CFG['db']['tbl']['users'].' AS u'.
						' WHERE d.debate_id='.$this->dbObj->Param($did).
						' AND d.user_id=u.'.$this->getUserTableField('user_id').
						' AND d.status IN (\'Open\', \'Resolved\')'.
						' AND u.'.$this->getUserTableField('usr_status').'=\'Ok\'';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($did));
				if (!$rs)
					    trigger_db_error($this->dbObj);

				if ($rs->PO_RecordCount())
					{
						$debateDetails = $rs->FetchRow();
						$debateDetails['dLink'] = getDebatesUrl('debatesresponse', '?title='.$debateDetails['seo_title'], $debateDetails['seo_title'].'/');
						$debateDetails['debate_link'] = '<a href="'.$debateDetails['dLink'].'">'.wordWrapManual($debateDetails['subject'], $this->CFG['admin']['question']['line_length'], $this->CFG['admin']['question']['short_length']).'</a>';
						$debateDetails['asked_by_link'] = '<a href="'.getMemberUrl($debateDetails['user_id'], $debateDetails['name']).'">'.stripString($debateDetails['asked_by'], $this->CFG['username']['medium_length']).'</a>';
					}


				return $debateDetails;
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function commonDeleteAttachments($content_type, $content_id)
			{
				$sql = 'SELECT attachment_id, attachment_name FROM '.$this->CFG['db']['tbl']['attachments'].
						' WHERE content_type=\''.$content_type.'\''.
						' AND content_id IN('.$content_id.')';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
				        trigger_db_error($this->dbObj);
				while($row=$rs->FetchRow())
					{
						$extern = strtolower(substr($row['attachment_name'], strrpos($row['attachment_name'], '.')+1));
						$attachment_large_file_name = '../'.$this->CFG['admin']['ans_attachments_path'].getImageName($row['attachment_id']).$this->CFG['admin']['ans_pictures']['large_name'].'.'.$extern;
						$attachment_small_file_name = '../'.$this->CFG['admin']['ans_attachments_path'].getImageName($row['attachment_id']).$this->CFG['admin']['ans_pictures']['small_name'].'.'.$extern;
						@unlink($attachment_large_file_name);
						@unlink($attachment_small_file_name);
					}

				$sql = 'DELETE FROM '.$this->CFG['db']['tbl']['attachments'].
						' WHERE content_type=\''.$content_type.'\''.
						' AND content_id IN('.$content_id.')';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
				        trigger_db_error($this->dbObj);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function decreaseBestAnswerPoints($uid)
			{
				if ($uid and $this->CFG['admin']['best_answers']['allowed'])
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['users_ans_log'].
								' SET total_points = total_points - '.$this->CFG['admin']['best_answers']['points'].
								' , total_best_ans = total_best_ans - 1'.
								' WHERE user_id='.$this->dbObj->Param($uid);
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($uid));
						if (!$rs)
							    trigger_db_error($this->dbObj);
					}
			}

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getResolvedQuestions($uid)
		    {
				$sql = 'SELECT COUNT(ques_id) AS resolved FROM '.$this->CFG['db']['tbl']['questions'].
						' WHERE user_id='.$this->dbObj->Param($uid).' AND status NOT IN(\'Blocked\',\'ToActivate\') AND date_closed<NOW()';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($uid));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				$row = $rs->FetchRow();
				return $row['resolved'];
		    }
		public function initializeSetFormFieldBilling()
			{
				$this->setFormField('billing_payment_type', 'CC');
				$this->setFormField('billing_bank_routing_number', '');
				$this->setFormField('billing_bank_acct_number', '');
				$this->setFormField('billing_bank_acct_type', '');
				$this->setFormField('billing_bank_name', '');
				$this->setFormField('billing_bank_acct_name_first', '');
				$this->setFormField('billing_bank_acct_name_last', '');
				$this->setFormField('billing_payment_gateway', '');
				$this->setFormField('billing_payment_method', '');
				$this->setFormField('billing_card_first', '');
				$this->setFormField('billing_card_last', '');
				$this->setFormField('billing_address', '');
				$this->setFormField('billing_city', '');
				$this->setFormField('billing_state', '');
				$this->setFormField('billing_zip', '');
				$this->setFormField('billing_phone', '');
				$this->setFormField('billing_card_number', '');
				$this->setFormField('billing_expires', '');
				$this->setFormField('billing_security', '');
				$this->setFormField('billing_expires_year', '');
				$this->setFormField('billing_expires_month', '');
				$this->setFormField('billing_country', '');
				$this->populateExpireYearList = $this->populateExpireYearList();
				$this->populateExpireMonthList = $this->populateExpireMonthList();
				$this->setFormField('payment_plan','');//'paymentType', '');
				$this->setFormField('amount', '');
				$this->setFormField('rbamt', '');
				$this->setFormField('rbfreq', '');
				$this->setFormField('rbduration', '');
				$this->setFormField('plan_id','');//''promo_code', '');
				$this->setFormField('payment_valid', '');

			}
		public function populateExpireYearList()
			{
				$curYear = date('y');
				$yearArr = array();
				$yearArrTemp = array();
				for($i=$curYear; $i<=99; $i++)
					{
						if(strlen($i) < 2)
							{
								$i = '0'.$i;
							}
						$yearArrTemp = array($i => $i);
						$yearArr = 	$yearArr + $yearArrTemp;
					}
				return $yearArr;
			}
		public function populateExpireMonthList()
			{
				$monthArr = array();
				$monthArrTemp = array();
				for($i=1; $i<=12; $i++)
					{
						if(strlen($i) < 2)
							{
								$i = '0'.$i;
							}
						$monthArrTemp = array($i => $i);
						$monthArr = $monthArr + $monthArrTemp;
					}
				return $monthArr;
			}
	    public function chkIsValidCardNo($field_name,$err_tip)
			{
				$cardArr = explode('-', $this->fields_arr[$field_name]);

				if(count($cardArr) == 4)
					{
						if(is_numeric($cardArr[0]) and is_numeric($cardArr[1]) and is_numeric($cardArr[2]) and is_numeric($cardArr[3]))
							{
								if( isset($this->fields_arr['billing_payment_method']) AND $this->fields_arr['billing_payment_method'] == 'Amex' )
									{
										$is_ok = false;
										if(strlen($cardArr[0]) == 4 and strlen($cardArr[1]) == 2 and strlen($cardArr[2]) == 4  and strlen($cardArr[3]) == 5)
											{
												$is_ok = true;
											}
									}
								elseif(strlen($cardArr[0]) == 4 and strlen($cardArr[1]) == 4 and strlen($cardArr[2]) == 4  and strlen($cardArr[3]) == 4)
									{
										$is_ok = true;
									}
								else
									{
										$is_ok = false;
									}
							}
						else
							{
								$is_ok = false;
							}
					}
				else
					{
						$is_ok = false;
					}
				if(!$is_ok)
					{
						$this->setFormFieldErrorTip($field_name, $err_tip);
					}
				return $is_ok;
			}
		public function chkIsValidCardExpireDate($field_name)
			{
				$curMonth = date('m');
				$curYear = date('y');
				$cardexpire = explode('/',$field_name);
				if((isset($cardexpire[0]) and ctype_digit($cardexpire[0])) and (isset($cardexpire[1]) and ctype_digit($cardexpire[1])))
					{
						if(($cardexpire[0] >= 01) and ($cardexpire[0] <= 12) and ($cardexpire[1] >= 01) and ($cardexpire[1] <= 99))
							{
								if($cardexpire[1] > $curYear)
									{
										return true;
									}
								else if($cardexpire[1] == $curYear)
									{
										if($cardexpire[0] >= $curMonth)
											{
												return true;
											}
									}
							}
					}
				return false;
			}
		public function chkIsValidCardSecurityNo($field_name,$err_tip)
			{
				$cardno=strlen($this->getFormField($field_name));
				if($this->getFormField('billing_payment_method')!= 'Amex')
					{
						if(($cardno != 3))
							{
								$this->setFormFieldErrorTip($field_name, $err_tip);
								return false;
							}
					}
				else
					{
						if(($cardno != 4))
							{
								$this->setFormFieldErrorTip($field_name, $err_tip);
								return false;
							}
					}
				return true;
			}

		public function chkIsValidBillingInformation()
			{

				if($this->getFormField('billing_payment_type') == 'CC')
					{

						if(!$this->isPaidPlan)
							{
								return;
							}

						$this->chkIsNotEmpty('billing_payment_type', $this->LANG['err_tip_compulsory']);
						$this->chkIsNotEmpty('billing_payment_gateway', $this->LANG['err_tip_compulsory']);
						$this->chkIsNotEmpty('billing_payment_method', $this->LANG['err_tip_compulsory']);
						$this->chkIsNotEmpty('billing_card_first', $this->LANG['err_tip_compulsory']);
						//$this->chkIsNotEmpty('billing_card_last', $this->LANG['err_tip_compulsory']);
						//$this->chkIsNotEmpty('billing_address', $this->LANG['err_tip_compulsory']);
						//$this->chkIsNotEmpty('billing_city', $this->LANG['err_tip_compulsory']);
						//$this->chkIsNotEmpty('billing_state', $this->LANG['err_tip_compulsory']);
						//$this->chkIsNotEmpty('billing_country', $this->LANG['err_tip_compulsory']);
						//$this->chkIsNotEmpty('billing_zip', $this->LANG['err_tip_compulsory']);
					     //$this->chkIsNotEmpty('billing_phone', $this->LANG['err_tip_compulsory']);
						$this->chkIsNotEmpty('billing_card_number', $this->LANG['err_tip_compulsory']) and $this->chkIsValidCardNo('billing_card_number',$this->LANG['common_err_tip_invalid_card_no']);
						$this->chkIsNotEmpty('billing_expires_month', $this->LANG['err_tip_compulsory']);
						$this->chkIsNotEmpty('billing_expires_year', $this->LANG['err_tip_compulsory']);
						if($this->getFormField('billing_expires_month') and $this->getFormField('billing_expires_year'))
							{
								$billing_expires = $this->getFormField('billing_expires_month').'/'.$this->getFormField('billing_expires_year');
								if(!$this->chkIsValidCardExpireDate($billing_expires))
									{
										$this->setFormFieldErrorTip('billing_expires_month',$this->LANG['common_err_tip_invalid_card_expire']);
										$this->setFormFieldErrorTip('billing_expires_year',$this->LANG['common_err_tip_invalid_card_expire']);
									}
								else
									{
										$this->setFormField('billing_expires',$billing_expires);
									}
							}
						$this->chkIsNotEmpty('billing_security', $this->LANG['err_tip_compulsory']) and $this->chkIsNumeric('billing_security', $this->LANG['common_err_tip_numeric']) and $this->chkIsValidCardSecurityNo('billing_security', $this->LANG['common_err_tip_invalid_card_security']);
						//echo '<pre>';print_r($this->fields_err_tip_arr);echo '</pre>';
				}
			else
				{
					$this->chkIsNotEmpty('billing_bank_name', $this->LANG['err_tip_compulsory']);
					$this->chkIsNotEmpty('billing_bank_acct_name_first', $this->LANG['err_tip_compulsory']);
					$this->chkIsNotEmpty('billing_bank_acct_name_last', $this->LANG['err_tip_compulsory']);
					$this->chkIsNotEmpty('billing_bank_acct_type', $this->LANG['err_tip_compulsory']);
					$this->chkIsNotEmpty('billing_bank_acct_number', $this->LANG['err_tip_compulsory']) and $this->chkIsValidNumericLength('billing_bank_acct_number',20, $this->LANG['common_err_tip_numeric'],'Not more than 20 digits') ;
					$this->chkIsNotEmpty('billing_bank_routing_number', $this->LANG['err_tip_compulsory']) and $this->chkIsValidNumericEqualLength('billing_bank_routing_number',9, $this->LANG['common_err_tip_numeric'],'Should be 9 digits') ;

				}
			}

		/********* payment gateway related functions start *************/
		public function setPPObject()
			{
				$this->PPObj = new paypalCreditCard();
			}

		public function getExpiryDate($duration,  $duration_type, $from_date = '')
			{
				if($from_date)
					{
						$from_date = '\''.$from_date.'\'';
					}
				else
					{
						$from_date = 'NOW()';
					}

				if($duration == $this->CFG['plan']['unlimited'])
					{
						$duration = 50;
						$duration_type = 'Year';
					}

				$sql = ' SELECT DATE_ADD('.$from_date.', INTERVAL '.$duration.' '.strtoupper($duration_type).') AS expiry_date';

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

				$row = $rs->FetchRow();
				return $row['expiry_date'];
			}

		public function getFormattedDate($date, $format)
			{
				$sql = 'SELECT DATE_FORMAT(\''.$date.'\', \''.$format.'\') AS formatted_date';

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

				$row = $rs->FetchRow();
				return $row['formatted_date'];
			}

		public function getNextPaymentDate()
			{
				$sql = 'SELECT DAY(LAST_DAY(NOW()))-DAY(NOW()) AS diff, DAY(NOW()) AS da';

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

				$row = $rs->FetchRow();

				$from_date = '';
				if($row['da'])
					{
						if($row['da']>15)
							{
								$sql = 'SELECT DATE_ADD(NOW(), INTERVAL '.($row['diff']+1).' DAY) AS from_date';
							}
						else
							{
								$sql = 'SELECT SUBDATE(NOW(), INTERVAL day(NOW())-1 DAY) AS from_date';
							}

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

						$row = $rs->FetchRow();
						$from_date = $row['from_date'];
					}
				return $from_date;
			}

		public function startOneTimeTransaction($amount, $content_id)
			{
				//echo '<br>coming for startOneTime function...';
				$success_status = false;
				if($this->getFormField('billing_payment_gateway') == 'PAYPAL')
					{
						$this->setPPObject();
						$this->PPObj->receptID = $this->_RECEIPT_ID;
						$this->PPObj->AMT = $amount;
						$success_status = $this->PPObj->doPayPalSinglePayment($content_id, $this->tariff_details['plan_id']);
					}

				if($success_status)
					{
						$msg = str_replace('{billed_amount}', '$'.$amount, $this->LANG['success_msg_payment_details']);
						$this->setCommonSuccessMsg(nl2br($msg));
						$this->setPageBlockShow('block_msg_form_success');
						//$this->fadeSuccessMsg('success');
						return true;
					}
				$this->setCommonErrorMsg($this->LANG['common_msg_error_payment']);
				return false;
			}


		public function doOneTimeTransaction($content_id)
			{
				//echo '<br>coming for doOneTime function...';
				$amount = $this->tariff_details['plan_amount'];
				$due_date = $this->tariff_details['plan_expired'];
				if($this->startOneTimeTransaction($amount, $content_id))
					{
						$expiry_date = $this->getExpiryDate($due_date,  'Day');
						$this->_EXPIRY_DATE = $expiry_date;
						return true;
					}
				return false;
			}

		public function updateTotalIssued()
			{
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['payment_plan_settings'].' SET plan_total_used=plan_total_used+1 WHERE'.
						' plan_id = '.$this->dbObj->Param('plan_id');

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

		public function getTariffDetails($tariff_name)
			{
				if(!chkIsPaymentAllowed())
					return true;
				//echo '<br>tariff details getting...for plan id='.$tariff_name;
				$sql = 'SELECT p.plan_id, p.plan_name, p.plan_recur_amount, p.plan_recur_total, p.plan_expired, p.plan_amount, p.plan_type'.
						' FROM '.$this->CFG['db']['tbl']['payment_plan_settings'].' as p '.
						' WHERE p.plan_id= '.$this->dbObj->Param($tariff_name).' AND'.
						' p.plan_status=\'Yes\'';

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

				if($row = $rs->FetchRow())
					{
						return $row;
					}
				return false;
			}

		public function testSignupFields()
			{
				$_POST['name'] = 'test'.substr(time(),0,5);
				$_POST['display_name'] = 'tesrec';
				$_POST['email'] = 'anova_'.substr(time(),0,3).'@test.com';
				$_POST['password'] = 'welcome';
				$_POST['confirm_password'] = 'welcome';
				$_POST['gender'] = 'Male';
				$_POST['bio'] = 'testsetes';
				$_POST['billing_payment_type'] = 'CC';
				$_POST['billing_payment_gateway'] = 'PAYPAL';
				$_POST['billing_payment_method'] = 'Visa';
				$_POST['billing_country'] = 'US';
				$_POST['terms'] = '1';
				$_POST['signup_submit'] = 'Submit';

			}

		/********* payment gateway related functions end *************/
		public function overRideConfigs($isPost=true)
			{
				global $CFG, $smartyObj;

				if(!chkIsPaymentAllowed('payment'))
					return;

				if(!$CFG['user']['user_id'])
					return;

				if($CFG['plan']['plan_video_post_count'] != $CFG['plan']['unlimited'] and $isPost)
					{
						if(!$this->isAllwedToPostVideo())
							{
								if(chkIsPaymentAlertMessageAllowed())
									$this->CFG['admin']['paymentmodule']['video'] = $CFG['admin']['paymentmodule']['video'] = false;
								else
									$CFG['admin']['module']['video'] = false;
							}

					}
    			if($CFG['plan']['plan_audio_post_count'] != $CFG['plan']['unlimited'] and $isPost)
    				{
						if(!$this->isAllwedToPostAudio())
							{
								if(chkIsPaymentAlertMessageAllowed())
									$this->CFG['admin']['paymentmodule']['audio'] = $CFG['admin']['paymentmodule']['audio'] = false;
								else
									$CFG['admin']['module']['audio'] = false;
							}
					}

    			unset($_SESSION['video_record_time']);
				if($CFG['plan']['plan_video_recording_time'] != $CFG['plan']['unlimited'])
    				{
						$_SESSION['video_record_time'] = $CFG['plan']['plan_video_recording_time'];
					}

    			unset($_SESSION['audio_record_time']);
				if($CFG['plan']['plan_audio_recording_time'] != $CFG['plan']['unlimited'])
    				{
						$_SESSION['audio_record_time'] = $CFG['plan']['plan_audio_recording_time'];
					}

				if($CFG['plan']['plan_ans_characters'] != $CFG['plan']['unlimited'])
    				{
						$CFG['admin']['answers']['limit'] = $CFG['plan']['plan_ans_characters'];
					}

				if($CFG['plan']['plan_rate_ques'] == 'No')
    				{
						if(chkIsPaymentAlertMessageAllowed())
							$this->CFG['admin']['paymentmodule']['rate_ques'] = $CFG['admin']['paymentmodule']['rate_ques'] = false;
						else
							$CFG['admin']['question']['ratings'] = false;
					}

				if($CFG['plan']['plan_rate_ans'] == 'No')
    				{
						if(chkIsPaymentAlertMessageAllowed())
							$this->CFG['admin']['paymentmodule']['rate_ans'] = $CFG['admin']['paymentmodule']['rate_ans'] = false;
						else
							$CFG['admin']['answer']['ratings'] = false;
					}


				$smartyObj->assign('CFG', $CFG);
			}

		public function isAllwedToPostVideo()
			{
				$sql = 'SELECT video_id FROM '.$this->CFG['db']['tbl']['ans_video'].''.
				       ' WHERE user_id = '.$this->dbObj->Param('user_id').
				       ' AND date_added >= '.$this->dbObj->Param('date_added').
					   ' AND video_status = \'Ok\'';

				$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($numrows < $this->CFG['plan']['plan_video_post_count']and $this->CFG['plan']['plan_video_post_count'] != 0)
					return true;
				else
					return false;


			}
		public function isAllwedToPostAudio()
			{
				$sql = 'SELECT audio_id FROM '.$this->CFG['db']['tbl']['ans_audio'].''.
				       ' WHERE user_id = '.$this->dbObj->Param('user_id').
				       ' AND date_added >= '.$this->dbObj->Param('date_added').
					   ' AND audio_status = \'Ok\'';

				$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($numrows < $this->CFG['plan']['plan_audio_post_count']and $this->CFG['plan']['plan_audio_post_count'] != 0)
					return true;
				else
					return false;


			}

		public function getPaymentPlanName($plan_id)
			{

				$sql = 'SELECT plan_name FROM ' .$this->CFG['db']['tbl']['payment_plan_settings'].
				 	   ' WHERE plan_id = '.$this->dbObj->Param($plan_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($plan_id));
				if (!$rs)
						trigger_db_error($this->dbObj);

				$row=$rs->FetchRow();
				return $row['plan_name'];
			}

		public function getWPSpaymentLog($username, $txn_id, $planFor = 'signup')
			{
				$sql = 'SELECT * FROM ' .$this->CFG['db']['tbl']['wps_paypal_transaction_log'].
				 	   ' WHERE payer_name = '.$this->dbObj->Param($username).
				 	   ' AND plan_for = '.$this->dbObj->Param($planFor).
				 	   ' AND txn_id = '.$this->dbObj->Param($txn_id).
				 	   ' AND payment_status = \'Completed\'';

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($username, $planFor, $txn_id));
				if (!$rs)
						trigger_db_error($this->dbObj);

				$row = false;
				if($rs->PO_RecordCount())
					{
						$ok = true;
						$row=$rs->FetchRow();
					}

				return $row;
			}

		public function checkIsActivePlan($plan_id)
			{
				$sql = 'SELECT plan_name FROM ' .$this->CFG['db']['tbl']['payment_plan_settings'].
				 	   ' WHERE plan_status = \'Yes\' AND plan_id = '.$this->dbObj->Param('plan_id');
				$stmt = $this->dbObj->Prepare($sql);
				// execute query
				$rs = $this->dbObj->Execute($stmt,array($plan_id));
				//raise user error... fatal
				if (!$rs)
						trigger_db_error($this->dbObj);

				$numrows = $rs->PO_RecordCount();
				if($numrows > 0)
					return true;
				else
					return false;
			}

		public function chkIsPlanAvailable($plan_id)
			{
				if($plan_id == '0')
					return true;

				$sql = 'SELECT plan_name FROM ' .$this->CFG['db']['tbl']['payment_plan_settings'].
				 	   ' WHERE plan_id = '.$this->dbObj->Param('plan_id');
				$stmt = $this->dbObj->Prepare($sql);
				// execute query
				$rs = $this->dbObj->Execute($stmt,array($plan_id));
				//raise user error... fatal
				if (!$rs)
						trigger_db_error($this->dbObj);

				$numrows = $rs->PO_RecordCount();
				if($numrows > 0)
					return true;
				else
					return false;

			}

		//////////  payment Log  for planwise ////////////////
		public function getPlanLogForQuestion()
			{
				$sql = 'SELECT ques_id FROM '.$this->CFG['db']['tbl']['questions'].
						' WHERE user_id = '.$this->dbObj->Param('user_id').
						' AND date_asked >= '.$this->dbObj->Param('date_asked');

				$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_ques'] != $this->CFG['plan']['unlimited'])
					return ($this->CFG['plan']['plan_total_ques'] - $numrows);
						else
							return $this->CFG['plan']['unlimited_text'];

			}

		public function getPlanLogForQuestionPerDay()
			{
				$sql = 'SELECT ques_id FROM '.$this->CFG['db']['tbl']['questions'].
				       ' WHERE user_id = '.$this->dbObj->Param('user_id').
					   ' AND DATE_FORMAT(date_asked, \''.$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_ques_perday'] != $this->CFG['plan']['unlimited'])
					return ($this->CFG['plan']['plan_ques_perday'] - $numrows);
						else
							return $this->CFG['plan']['unlimited_text'];
			}

		public function getPlanLogForAnswer()
			{
				$sql = 'SELECT ans_id FROM '.$this->CFG['db']['tbl']['answers'].
				       ' WHERE user_id = '.$this->dbObj->Param('user_id').
				       ' AND date_answered >= '.$this->dbObj->Param('last_paid_date');

				$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_ans'] != $this->CFG['plan']['unlimited'])
					return ($this->CFG['plan']['plan_total_ans'] - $numrows);
				else
					return $this->CFG['plan']['unlimited_text'];
			}

		public function getPlanLogForAnswerPerDay()
			{
				$sql = 'SELECT ans_id from '.$this->CFG['db']['tbl']['answers'].
				       ' WHERE user_id = '.$this->dbObj->Param('user_id').
					   ' AND DATE_FORMAT(date_answered, \''.$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_ans_perday'] != $this->CFG['plan']['unlimited'] )
					return ($this->CFG['plan']['plan_ans_perday'] - $numrows);
				else
					return $this->CFG['plan']['unlimited_text'];
			}

		public function getPlanLogForVideo()
			{
				$sql = 'SELECT video_id FROM '.$this->CFG['db']['tbl']['ans_video'].''.
				       ' WHERE user_id = '.$this->dbObj->Param('user_id').
				       ' AND date_added >= '.$this->dbObj->Param('date_added').
					   ' AND video_status = \'Ok\'';

				$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_video_post_count'] != $this->CFG['plan']['unlimited'] )
					return ($this->CFG['plan']['plan_video_post_count'] - $numrows);
				else
					return $this->CFG['plan']['unlimited_text'];
			}

		public function getPlanLogForAudio()
			{
				$sql = 'SELECT audio_id FROM '.$this->CFG['db']['tbl']['ans_audio'].''.
				       ' WHERE user_id = '.$this->dbObj->Param('user_id').
				       ' AND date_added >= '.$this->dbObj->Param('date_added').
					   ' AND audio_status = \'Ok\'';

				$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_audio_post_count'] != $this->CFG['plan']['unlimited'] )
					return ($this->CFG['plan']['plan_audio_post_count'] - $numrows);
				else
					return $this->CFG['plan']['unlimited_text'];
			}

		public function getPlanLogForFeaturedQuestion()
			{
				$sql = 'SELECT ques_id FROM '.$this->CFG['db']['tbl']['questions'].
				       ' WHERE featured=\'Yes\' AND user_id = '.$this->dbObj->Param('user_id').
					   ' AND date_asked >= '.$this->dbObj->Param('last_paid_date');

				$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_featured_ques_count'] != $this->CFG['plan']['unlimited'] )
					return ($this->CFG['plan']['plan_featured_ques_count'] - $numrows);
						else
							return $this->CFG['plan']['unlimited_text'];
			}
		/**
		 * FormHandler::UpdateUserVote()
		 *
		 * @param mixed $type
		 * @param mixed $value
		 * @param mixed $user_id
		 * @param mixed $id
		 * @return
		 */
		public function UpdateUserVote($type, $value, $user_id, $id )
			{
				if ($type == 'question')
					{
						$table_name = 'users_vote_question';
						$table_name1 = 'questions';
						$fieldname = 'ques_id';
					}
				elseif ($type == 'answer')
					{
						$table_name = 'users_vote_answer';
						$fieldname = 'ans_id';
						$table_name1 = 'answers';
					}
				$sql = 'SELECT * from '.$this->CFG['db']['tbl'][$table_name].
						' WHERE '.$fieldname.' = '.$this->dbObj->Param($id).
						' AND user_id ='.$this->dbObj->Param($user_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($id, $user_id));
				if (!$rs)
				        trigger_db_error($this->dbObj);
				$num_rows = $rs->PO_RecordCount();
				if($num_rows == 0)
					{
						$sql = 'INSERT INTO '.$this->CFG['db']['tbl'][$table_name].
								' SET voting ='.$this->dbObj->Param($value).
								', '.$fieldname.' = '.$this->dbObj->Param($id).
								', user_id ='.$this->dbObj->Param($user_id);
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($value, $id, $user_id));
						if (!$rs)
								trigger_db_error($this->dbObj);

						if($value ==1)
							{
								$sql = 'UPDATE '.$this->CFG['db']['tbl'][$table_name1].
										' SET votes = votes+1'.
										' WHERE '.$fieldname.' = '.$this->dbObj->Param($id);
							}
						else if($value ==-1)
							{
								$sql = 'UPDATE '.$this->CFG['db']['tbl'][$table_name1].
										' SET votes = votes-1'.
										' WHERE '.$fieldname.' = '.$this->dbObj->Param($id);
							}
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($id));
						if (!$rs)
								trigger_db_error($this->dbObj);
					}
			}

		/**
		 * FormHandler::getTotalVotes()
		 *
		 * @param mixed $type
		 * @param mixed $id
		 * @return
		 */
		public function getTotalVotes($type, $id)
			{
				if ($type == 'question')
					{
						$table_name = 'questions';
						$fieldname = 'ques_id';
					}
				elseif ($type == 'answer')
					{
						$table_name = 'answers';
						$fieldname = 'ans_id';
					}
				$sql = 'SELECT  votes FROM '.$this->CFG['db']['tbl'][$table_name].
				        ' WHERE '.$fieldname .'='.$this->dbObj->Param($id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($id));
				if (!$rs)
				        trigger_db_error($this->dbObj);

				if ($rs->PO_RecordCount())
					{
						$row= $rs->FetchRow();
						return $row['votes'];
					}
			}

		/**
		 * FormHandler::chkIfUserVoted()
		 *
		 * @param mixed $type
		 * @param mixed $id
		 * @param mixed $user_id
		 * @return
		 */
		public function chkIfUserVoted($type, $id, $user_id)
			{
				if ($type == 'question')
					{
						$table_name = 'users_vote_question';
						$fieldname = 'ques_id';
					}
				elseif ($type == 'answer')
					{
						$table_name = 'users_vote_answer';
						$fieldname = 'ans_id';
					}
				$sql = 'SELECT * FROM '.$this->CFG['db']['tbl'][$table_name].
				        ' WHERE '.$fieldname .'='.$this->dbObj->Param($id).
						' AND user_id = '.$this->dbObj->Param($user_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($id, $user_id));
				if (!$rs)
				        trigger_db_error($this->dbObj);

				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						return $row['voting'];
					}
				else
					return 0;
			}
		/**
		 * FormHandler::getUserLevelTitle()
		 *
		 * @param mixed $level
		 * @return
		 */
		public function getUserLevelTitle($level)
			{
				if($level == '6')
					{
						$userLevelTitle = $this->CFG['user']['level_six']['text'];
					}
				elseif($level == '5')
					{
						$userLevelTitle = $this->CFG['user']['level_five']['text'];
					}
				elseif($level == '4')
					{
						$userLevelTitle = $this->CFG['user']['level_four']['text'];
					}
				elseif($level == '3')
					{
						$userLevelTitle = $this->CFG['user']['level_three']['text'];
					}
				elseif($level == '2')
					{
						$userLevelTitle = $this->CFG['user']['level_two']['text'];
					}
				else
					{
						$userLevelTitle = $this->CFG['user']['level_one']['text'];
					}
				return $userLevelTitle;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayImageGallery($imgdetail, $admin=false, $page='')
			{
				global $smartyObj;

				$image_detail = explode('_', $imgdetail);
				$content_type = $image_detail[0];
				$content_id = $image_detail[1];
				$display_id = $image_detail[2];

				$sql = 'SELECT attachment_id, attachment_name, photo_server_url, content_id, content_type'.
						' FROM '.$this->CFG['db']['tbl']['attachments'].' AS bc'.
						' WHERE content_id='.$this->dbObj->Param($content_id).
						' AND content_type='.$this->dbObj->Param($content_type).
						' ORDER BY attachment_id ';
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($content_id, $content_type));
				if (!$rs)
				    trigger_db_error($this->dbObj);

				$displayImage = array();
				$imagesArray = array();
				$loadImages = array();
				$display_key = -1;
				while($row = $rs->FetchRow()) {
					$imagesArray[] = $row['attachment_id'];
					if ($row['attachment_id'] == $display_id)
						{
							$display_key = count($imagesArray)-1;
							$extern = strtolower(substr($row['attachment_name'], strrpos($row['attachment_name'], '.')+1));
							$attachment_file_name = getImageName($row['attachment_id']).$this->CFG['admin']['ans_pictures']['large_name'].'.'.$extern;

							$displayImage['img_id'] = $row['content_type'].'_'.$row['content_id'].'_'.$row['attachment_id'];

							if($page == 'questions')
								{
									$displayImage['attachment_path'] = getAnovaUrl('questions', '?view=ask&cid='.$this->fields_arr['cid'].'&imgdetail='.$displayImage['img_id'], 'ask/?cid='.$this->fields_arr['cid'].'&imgdetail='.$displayImage['img_id']);
								}
							else
								{
									if (!$admin)
										$displayImage['attachment_path'] = getAnovaUrl('answer', '?title='.$this->fields_arr['seo_title'].'&imgdetail='.$displayImage['img_id'], $this->fields_arr['seo_title'].'/?imgdetail='.$displayImage['img_id']);
									else
										$displayImage['attachment_path'] = $this->CFG['site']['relative_url'].'viewAnswers.php?qid='.$this->getFormField('qid').'&imgdetail='.$displayImage['img_id'];
								}
							$displayImage['image_path'] = $row['photo_server_url'].$this->CFG['admin']['index']['anova_module'].'/'.$this->CFG['admin']['ans_attachments_path'].$attachment_file_name;
							$image_info = getimagesize($displayImage['image_path']);
							$renderWidth = ($this->CFG['admin']['ans_photos']['large_width']/1440) * $this->fields_arr['w'];
							$renderHeight = ($this->CFG['admin']['ans_photos']['large_height']/693) * $this->fields_arr['h'];
							$displayImage['attributes'] = GET_IMAGE_ATTRIBUTES($renderWidth, $renderHeight, $image_info[0], $image_info[1]);
						}
						$extern_1 = strtolower(substr($row['attachment_name'], strrpos($row['attachment_name'], '.')+1));
						$attachment_file_name_1 = getImageName($row['attachment_id']).$this->CFG['admin']['ans_pictures']['large_name'].'.'.$extern_1;
						$loadImages[] = $row['photo_server_url'].$this->CFG['admin']['index']['anova_module'].'/'.$this->CFG['admin']['ans_attachments_path'].$attachment_file_name_1;
				}
				if ($display_key != -1)
					{
						if (isset($imagesArray[$display_key-1]))
							{
								$img_id = $content_type.'_'.$content_id.'_'.$imagesArray[$display_key-1];
								$displayImage['previous_image'] = $img_id;
								if($page == 'questions')
									{
										$displayImage['previous_path'] = getAnovaUrl('questions', '?view=ask&cid='.$this->fields_arr['cid'].'&imgdetail='.$img_id, 'ask/?cid='.$this->fields_arr['cid'].'&imgdetail='.$img_id);
									}
								else
									{
										if (!$admin)
											$displayImage['previous_path'] = getAnovaUrl('answer', '?title='.$this->fields_arr['seo_title'].'&imgdetail='.$img_id, $this->fields_arr['seo_title'].'/?imgdetail='.$img_id);
										else
											$displayImage['previous_path'] = $this->CFG['site']['relative_url'].'viewAnswers.php?qid='.$this->getFormField('qid').'&imgdetail='.$img_id;
									}
							}
						if (isset($imagesArray[$display_key+1]))
							{
								$img_id = $content_type.'_'.$content_id.'_'.$imagesArray[$display_key+1];
								$displayImage['next_image'] = $img_id;
								if($page == 'questions')
									{
										$displayImage['next_path'] = getAnovaUrl('questions', '?view=ask&cid='.$this->fields_arr['cid'].'&imgdetail='.$img_id, 'ask/?cid='.$this->fields_arr['cid'].'&imgdetail='.$img_id);
									}
								else
									{
										if (!$admin)
											$displayImage['next_path'] = getAnovaUrl('answer', '?title='.$this->fields_arr['seo_title'].'&imgdetail='.$img_id, $this->fields_arr['seo_title'].'/?imgdetail='.$img_id);
										else
											$displayImage['next_path'] = $this->CFG['site']['relative_url'].'viewAnswers.php?qid='.$this->getFormField('qid').'&imgdetail='.$img_id;
									}
							}
					}
				$smartyObj->assign('displayImage', $displayImage);
				$smartyObj->assign('loadImages', $loadImages);
				setTemplateFolder('general/', $this->CFG['admin']['index']['anova_module']);
				$smartyObj->display('displayImageGallery.tpl');
			}

		/**
		 * FormHandler::isFacebookUser()
		 *
		 * @return
		 */
		public function isFacebookUser($uid = '')
			{
				if($uid == '')
					$uid = $this->CFG['user']['user_id'];

				if (isset($this->_cache_isFacebookUser[$uid]))
					{
						return $this->_cache_isFacebookUser[$uid];
					}

				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['facebook_identity'].
					   ' WHERE user_id = '.$this->dbObj->Param($uid);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($uid));
				if (!$rs)
				        trigger_db_error($this->dbObj);

				if($rs->PO_RecordCount())
					$isFacebookUser = true;
				else
					$isFacebookUser = false;
				//cache facebook user
				$this->_cache_isFacebookUser[$uid] = $isFacebookUser;

				return	$isFacebookUser;
			}

		/**
		 * FormHandler::getFacebookProfileStatus()
		 *
		 * @return
		 */
		public function getFacebookProfileStatus()
			{
		 		$sql = 'SELECT * FROM '.$this->CFG['db']['tbl']['facebook_profile'].
		            	' WHERE user_id = '.$this->dbObj->Param($this->CFG['user']['user_id']);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->CFG['user']['user_id']));
				if (!$rs)
						trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						return $row;
					}
				return false;
			}

		/**
		 * FormHandler::updateImagePath()
		 *
		 * @return
		 */
		public function updateImagePath()
			{
				$uid = $this->CFG['user']['user_id'];
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['users'].
				    	' SET img_path = \'\', photo_server_url = \'\', t_height = 0, s_height = 0, s_width = 0, l_width = 0, l_height = 0, photo_ext = \'\''.
						' WHERE user_id = '.$this->dbObj->Param($uid);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($uid));
				if (!$rs)
				        trigger_db_error($this->dbObj);
		   }

		/**
		 * FormHandler::chkIsFaceBookImageUploaded()
		 *
		 * @param mixed $file_name
		 * @param mixed $user_id
		 * @return
		 */
		public function chkIsFaceBookImageUploaded($file_name,  $user_id)
			{
			    if($file_name == '')
			    	{
			    		$this->updateImagePath();
					}
				else
					{
						$output = $this->CFG['site']['project_path'].'files/facebook_image/'.md5($file_name).'.jpg';

						file_put_contents($output, getContents($file_name));
						$file_name = $output;
						$extern = 'jpg';
						//Initialize width and height of the image
						$this->setFormField('photo_ext', $extern);
						$image_name = getImageName($user_id);
						$temp_dir = $this->CFG['site']['project_path'] . $this->CFG['admin']['ans_photos']['temp_folder'];
						$this->chkAndCreateFolder($temp_dir);
						$temp_file = $temp_dir . $image_name;
						if(copy($file_name, $temp_file))
							{
								$imageObj = new ImageHandler($temp_file);
								$this->setIHObject($imageObj);
								$this->storeImagesTempServer($temp_file, $extern);
								$dir = $this->CFG['admin']['ans_photos']['folder'];
								$local_upload = true;

								if ($this->getServerDetails())
									{
										if ($FtpObj = new FtpHandler($this->getFormField('ftp_server'), $this->getFormField('ftp_usrename'), $this->getFormField('ftp_password')))
											{
												$FtpObj->makeDirectory($dir);
												$FtpObj->changeDirectory($dir);
												$FtpObj->moveTo($temp_file . '.' . $extern, $dir . $image_name . '.' . $extern);
												unlink($temp_file . '.' . $extern);
												if ($this->CFG['admin']['ans_photos']['large_name'] == 'L')
													{
														$FtpObj->moveTo($temp_file . 'L.' . $extern, $dir . $image_name . 'L.' . $extern);
														unlink($temp_file . 'L.' . $extern);
													}
												if ($this->CFG['admin']['ans_photos']['thumb_name'] == 'T')
													{
														$FtpObj->moveTo($temp_file . 'T.' . $extern, $dir . $image_name . 'T.' . $extern);
														unlink($temp_file . 'T.' . $extern);
													}
												if ($this->CFG['admin']['ans_photos']['small_name'] == 'S')
													{
														$FtpObj->moveTo($temp_file . 'S.' . $extern, $dir . $image_name . 'S.' . $extern);
														unlink($temp_file . 'S.' . $extern);
													}
												$this->setFormField('server_url', $this->getFormField('server_url'));
												$local_upload = false;
												return;
											}
									}
								if ($local_upload)
									{
										$dir = $this->CFG['site']['project_path']  . $this->CFG['admin']['ans_photos']['folder'];
										$this->chkAndCreateFolder($dir);
										$uploadUrl = $dir . $image_name;
										if ($this->CFG['admin']['ans_photos']['large_name'] == 'L')
											{
												copy($temp_file . 'L.' . $extern, $uploadUrl . 'L.' . $extern);
												unlink($temp_file . 'L.' . $extern);
											}
										if ($this->CFG['admin']['ans_photos']['thumb_name'] == 'T')
											{
												copy($temp_file . 'T.' . $extern, $uploadUrl . 'T.' . $extern);
												unlink($temp_file . 'T.' . $extern);
											}
										if ($this->CFG['admin']['ans_photos']['small_name'] == 'S')
											{
												copy($temp_file . 'S.' . $extern, $uploadUrl . 'S.' . $extern);
												unlink($temp_file . 'S.' . $extern);
											}
										$this->setFormField('server_url', $this->CFG['site']['url']);
									}
								$sql = 'UPDATE '.$this->CFG['db']['tbl']['users'].
										' SET '.$this->CFG['users']['t_width'].'='.$this->dbObj->Param($this->T_WIDTH).
										', '.$this->CFG['users']['t_height'].'='.$this->dbObj->Param($this->T_HEIGHT).
										', '.$this->CFG['users']['l_width'].'='.$this->dbObj->Param($this->L_WIDTH).
										', '.$this->CFG['users']['l_height'].'='.$this->dbObj->Param($this->L_HEIGHT).
										', '.$this->CFG['users']['s_width'].'='.$this->dbObj->Param($this->S_WIDTH).
										', '.$this->CFG['users']['s_height'].'='.$this->dbObj->Param($this->S_HEIGHT).
										', '.$this->CFG['users']['photo_ext'].'='.$this->dbObj->Param($extern).
										', '.$this->CFG['users']['image_path'].'=\'\''.
										', '.$this->CFG['users']['photo_server_url'].'='.$this->dbObj->Param($this->fields_arr['server_url']).
										' WHERE '.$this->CFG['users']['user_id'].'='.$this->dbObj->Param($user_id);
								$stmt = $this->dbObj->Prepare($sql);
								$rs = $this->dbObj->Execute($stmt, array($this->T_WIDTH, $this->T_HEIGHT, $this->L_WIDTH, $this->L_HEIGHT,
																		 $this->S_WIDTH, $this->S_HEIGHT, $extern, $this->fields_arr['server_url'], $user_id));
								if (!$rs)
									trigger_db_error($this->dbObj);

								@unlink($output);
								return true;
							}
						else
							{
								$this->updateImagePath();
							}
					  }
			}

		/**
		 * FormHandler::updateFaceBookInfiniteSession()
		 *
		 * @param mixed $user_id
		 * @param string $session
		 * @param mixed $facebook_id
		 * @return
		 */
		public function updateFaceBookInfiniteSession($user_id,$session = '',$facebook_id)
			{
				$sql = 'SELECT facebook_id, infinite_session FROM ' . $this->CFG['db']['tbl']['facebook_identity'] .
						' WHERE user_id='. $this->dbObj->Param('user_id');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt,array($user_id));
			    if (!$rs)
				    trigger_db_error($this->dbObj);

				if($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();

						if($row['facebook_id'] != $facebook_id || $row['infinite_session'] != $session)
							{
								$sql_ins = 'UPDATE ' . $this->CFG['db']['tbl']['facebook_identity'] . ' SET infinite_session = '. $this->dbObj->Param('session').
										', facebook_id='.$this->dbObj->Param('facebook_id').' WHERE user_id = ' . $this->dbObj->Param('user_id');
								$stmt_ins = $this->dbObj->Prepare($sql_ins);
								$rs_ins = $this->dbObj->Execute($stmt_ins,array($session, $facebook_id, $user_id));
							    if (!$rs_ins)
								    trigger_db_error($this->dbObj);
							}
					}
			}

		/**
		 * FormHandler::updateFacebookPostId()
		 *
		 * @param mixed $ques_id
		 * @param mixed $post_id
		 * @return
		 */
		public function updateFacebookPostId($ques_id, $post_id)
			{
				$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['facebook_posts'].
						' SET facebook_postid = '.$this->dbObj->Param($post_id).
						', content_id = '.$this->dbObj->Param($ques_id).
						', date_added = '.$this->dbObj->SQLDate('Y-m-d H:i:s');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($post_id, $ques_id));
				if (!$rs)
					    trigger_db_error($this->dbObj);
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function fetchAnonymsUser()
			{
				if (isset($this->_cache_anonyms_user))
					{
						return $this->_cache_anonyms_user;
					}
				$anonyms_name = 'anonyms';
				$sql = 'SELECT '.$this->getUserTableFields(array('user_id', 'name')).
						' FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE '.$this->getUserTableField('name').'='.$this->dbObj->Param($anonyms_name);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($anonyms_name));
				if (!$rs)
						trigger_db_error($this->dbObj);
				$row = array();
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
					}
				//cache anonyms user
				$this->_cache_anonyms_user = $row;

				return	$row;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function isAnonymsUser($uid)
			{
				$isAnonymsUser = false;
				if (isset($this->_cache_anonyms_user) OR isset($this->_cache_is_anonyms_user))
					{
						return true;
					}
				$anonyms_name = 'anonyms';
				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE '.$this->getUserTableField('name').'='.$this->dbObj->Param($anonyms_name).
						' AND '.$this->getUserTableField('user_id').'='.$this->dbObj->Param($uid);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($anonyms_name, $uid));
				if (!$rs)
					    trigger_db_error($this->dbObj);

				if ($rs->PO_RecordCount())
					{
						$isAnonymsUser = true;
					}
				//cache anonyms user
				$this->_cache_is_anonyms_user = $isAnonymsUser;

				return $isAnonymsUser;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function fetchFacebookUserDetails($ans_id)
			{
				$sql = 'SELECT name, profile_url FROM '.$this->CFG['db']['tbl']['facebook_replies'].
						' WHERE comment_id = '.$this->dbObj->Param($ans_id);
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($ans_id));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				$row = array();
				if ($rs->PO_RecordCount())
					$row = $rs->FetchRow();
				return $row;
			}
		/**
		 * FormHandler::chkIsValidExternalUrl()
		 *
		 * @param mixed $url
		 * @return
		 */
		public function chkIsValidExternalUrl($url)
			{
				$url_type = 'Other';

				if($this->CFG['admin']['external_video']['youtube'] AND strpos($url, 'youtube.com') and strpos($url, 'watch') and strpos($url, 'v='))
					{
						$url_type = 'Youtube';
					}
				else if($this->CFG['admin']['external_video']['dailymotion'] AND strpos($url, 'dailymotion.com') and strpos($url, 'video/'))
					{
						$url_type = 'Dailymotion';
					}
				else if($this->CFG['admin']['external_video']['google'] AND strpos($url, 'video.google.com') and strpos($url, 'docid='))
					{
						$url_type = 'Google';
					}
				else if($this->CFG['admin']['external_video']['myspace'] AND strpos($url, 'vids.myspace.com') and strpos($url, 'vids.individual'))
					{
						$url_type = 'Myspace';
					}
				else if($this->CFG['admin']['external_video']['metacafe'] AND strpos($url, 'metacafe.com') and strpos($url, 'watch'))
					{
						$url_type = 'Metacafe';
					}
				else if($this->CFG['admin']['external_video']['blip'] AND strpos($url, 'blip.tv') and strpos($url, 'file'))
					{
						$url_type = 'Blip';
					}
				else
					{
						return false;
					}
				return $url_type;
			}
		/**
		 * FormHandler::chkIsURLAlreadyAdded()
		 *
		 * @param mixed $field_name
		 * @param mixed $error_tip
		 * @param mixed $type
		 * @param string $user_id
		 * @return
		 */
		public function chkIsURLAlreadyAdded($field_name, $error_tip, $video_table, $content_id = '')
			{
				$sql = 'SELECT 1 FROM ' . $video_table . ' WHERE external_url = '. $this->dbObj->Param($this->fields_arr[$field_name]) .
						' AND user_id = ' . $this->dbObj->Param('user_id');

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt,array(html_entity_decode($this->fields_arr[$field_name]), $content_id));

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

				if($rs->PO_RecordCount())
					{
						$this->setFormFieldErrorTip($field_name, $error_tip);
						return false;
					}
				return true;
			}
		//>>>>>>> debate Module function start from here ------------------------->
		/**
		 *
		 * @return 		void
		 * @access 		public
		 **/
		public function updateDebateViews()
		    {
				$sql = 'UPDATE '.$this->CFG['db']['tbl']['debates'].
						' SET total_views=total_views+1'.
						' WHERE debate_id='.$this->dbObj->Param('did');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($this->fields_arr['did']));
				if (!$rs)
				        trigger_db_error($this->dbObj);
		    }
	 	/**
		 *
		 * @access public
		 * @return void
		 **/
		public function showDebateCategoryName($cat_id)
		    {
				if (isset($this->_cache_category_details[$cat_id]))
					{
						$row = $this->_cache_category_details[$cat_id];
						$showDebateCategoryName_val = '<span>'.$this->LANG['common_in'].' <a href="'.getDebatesUrl('debates', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/').'">'.$row['cat_name'].'</a></span>';
						return $showDebateCategoryName_val;
					}

				$sql = 'SELECT cat_name, seo_title, cat_id FROM '.$this->CFG['db']['tbl']['questions_category'].' WHERE cat_id='.$this->dbObj->Param('cat_id');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($cat_id));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						$row = $rs->FetchRow();
						//cache category details
						$this->_cache_category_details[$cat_id] = $row;
						$showDebateCategoryName_val = '<span>'.$this->LANG['common_in'].' <a href="'.getDebatesUrl('debates', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/').'">'.$row['cat_name'].'</a></span>';
						return $showDebateCategoryName_val;
					}
				return false;
		    }

		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function displayDebatesTopLinks()
		    {
		    	global $smartyObj;
		    	$currentPage = $this->CFG['html']['current_script_name'];
				$clsActiveMisNavLinks = 'clsActiveMisNavLinks';
				$displayDebatesTopLinks_arr['myanswers'] = $displayDebatesTopLinks_arr['topAnalysts'] = $displayDebatesTopLinks_arr['askDebates'] = $displayDebatesTopLinks_arr['openDebates'] = $displayDebatesTopLinks_arr['resolvedDebates'] = '';
				$$currentPage = $clsActiveMisNavLinks;
				if ($currentPage == 'debates')
					{
						if ($this->fields_arr['view'] == 'open')
							{
								$displayDebatesTopLinks_arr['openDebates'] = $clsActiveMisNavLinks;
							}
						elseif ($this->fields_arr['view'] == 'resolved')
							{
								$displayDebatesTopLinks_arr['resolvedDebates'] = $clsActiveMisNavLinks;
							}
						elseif ($this->fields_arr['view'] == 'ask')
							{
								$displayDebatesTopLinks_arr['askDebates'] = $clsActiveMisNavLinks;
							}
					}
				$displayDebatesTopLinks_arr['askDebates_url']	= getDebatesUrl('debates', '?view=ask', 'ask/');
				$displayDebatesTopLinks_arr['openDebates_url'] = getDebatesUrl('debates', '?view=open&sort=date&order=d', 'open/?sort=date&order=d');
				$displayDebatesTopLinks_arr['resolvedDebates_url'] = getDebatesUrl('debates', '?view=resolved&sort=date&order=d', 'resolved/?sort=date&order=d');

				$smartyObj->assign('displayDebatesTopLinks_arr', $displayDebatesTopLinks_arr);
				setTemplateFolder('general/', $this->CFG['admin']['index']['debate_module']);
				$this->assignSmartyVariables();
				$smartyObj->display('displayDebateTopLinks.tpl');
		    }

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

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function increaseBestResponsePoints($uid)
			{
				if ($uid and $this->CFG['admin']['best_responses']['allowed'])
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['users_ans_log'].
								' SET total_points = total_points + '.$this->CFG['admin']['best_response']['points'].
								' , total_best_debate_response = total_best_debate_response + 1'.
								' WHERE user_id='.$this->dbObj->Param($uid);
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($uid));
						if (!$rs)
							  trigger_db_error($this->dbObj);
					}
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function decreaseBestResponsePoints($uid)
			{
				if ($uid and $this->CFG['admin']['best_responses']['allowed'])
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['users_ans_log'].
								' SET total_points = total_points - '.$this->CFG['admin']['best_response']['points'].
								' , total_best_debate_response = total_best_debate_response - 1'.
								' WHERE user_id='.$this->dbObj->Param($uid);
						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, array($uid));
						if (!$rs)
							  trigger_db_error($this->dbObj);
					}
			}

		/**
		 * @return void
		 * @access public
		 */
		 public function showDebatesPages()
			{
				global $smartyObj;
				$showDebatesPages = array();
				$allowed_pages_array = array('manageDebates.php', 'viewDebates.php');

				if(!displayBlock($allowed_pages_array))
					return;

				$currentPage = $this->CFG['html']['current_script_name'];
				$cssClassToHighlightMainLink = 'clsActiveHeaderMainLink';
				$manageSearchDebates = '';
				$manageDebates = $viewDebates = '';
				$$currentPage = $cssClassToHighlightMainLink;

				$sub_arr = array('manageDebates', 'viewDebates');
				if(in_array($currentPage, $sub_arr))
					$manageDebates = $cssClassToHighlightMainLink;
				if ($currentPage == 'manageDebates')
					{
						if ($this->fields_arr['mode'] == 'search')
							{
								$manageSearchDebates = $cssClassToHighlightMainLink;
								$manageDebates = '';
							}

						$cat_id = ($this->fields_arr['cat_id'])?$this->fields_arr['cat_id']:$this->fields_arr['parent_id'];
					}
				$showDebatesPages['manageDebates']=$manageDebates;
				$showDebatesPages['manageSearchDebates']=$manageSearchDebates;
				$smartyObj->assign('showDebatesPages', $showDebatesPages);
				setTemplateFolder('admin/');
				$this->assignSmartyVariables();
				$smartyObj->display('showDebatesPages.tpl');
			}


		//<<<<<<< debate module function end here -------------------------------->

		/**
		 * VideoUpload::setIHObject()
		 *
		 * @param $imObj
		 * @return
		 **/
		public function setIHObject($imObj)
			{
				$this->imageObj = $imObj;
			}

		/**
		 *
		 * @param $file_name
		 * @param $normal
		 * @param $htaccess
		 * @param $change
		 * @return
		 **/
		public function getBlogUrl($file_name, $normal = '', $htaccess = '', $change = 'current')
			{
				return getBlogUrl($file_name, $normal, $htaccess, $change);
			}

		/**
		 * To get the form field error for live validation
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getFormFieldElementErrorTip($field_name, $select='')
			{
				$span_id = '';
				if(isset($select) && $select !='')
					$span_id = 'id="selectspan"';
				return (isset($this->fields_err_tip_arr[$field_name]) and $this->fields_err_tip_arr[$field_name]) ? '<span '.$span_id.'class="LV_validation_message LV_invalid">'.$this->fields_err_tip_arr[$field_name].'</span>' : '';
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getCSSFormFieldElementClass($field_name)
			{
				$class_name = isset($this->fields_err_tip_arr[$field_name]) ? 'LV_invalid_field' : '';
				return $class_name;
			}

	   /**
        * To set the css class for error tip
        *
        * We can set the css error tip class for the form fields
        *
        * @param 		string $class_name Error tip class name
        * @return 		void
		* @access 		public
        */
		public function setCSSFormFieldErrorTipClass($class_name)
			{
				$this->css_class_arr['form_field_err_tip'] = $class_name;
			}

	   /**
        * To set the default css class for label
        *
        * @param 		string $class_name default label class
        * @return 		void
		* @access 		public
        */
		public function setCSSFormLabelCellDefaultClass($class_name)
			{
				$this->css_class_arr['form_label_cell_default'] = $class_name;
			}

	   /**
        * To set the css class for error label
        *
        * @param 		string $class_name error label class
        * @return 		void
		* @access 		public
        */
		public function setCSSFormLabelCellErrorClass($class_name)
			{
				$this->css_class_arr['form_label_cell_error'] = $class_name;
			}

	   /**
        * To set the default css class for form field
        *
        * @param 		string $class_name default form field class
        * @return 		void
		* @access 		public
        */
		public function setCSSFormFieldCellDefaultClass($class_name)
			{
				$this->css_class_arr['form_field_cell_default'] = $class_name;
			}

	   /**
        * To set css class for error form fields
        *
        * @param 		string $class_name error form field class
        * @return 		void
		* @access 		public
        */
		public function setCSSFormFieldCellErrorClass($class_name)
			{
				$this->css_class_arr['form_field_cell_error'] = $class_name;
			}

	   /**
        * To get the css label class
        *
        * @param 		string $field_name form field
        * @return 		string
		* @access 		public
        */
		public function getCSSFormLabelCellClass($field_name)
			{
				$class_name = isset($this->fields_err_tip_arr[$field_name]) ? 'form_label_cell_error' : 'form_label_cell_default';
				return $this->css_class_arr[$class_name];
			}

	   /**
        * To get the css form field class
        *
        * @param 		string $field_name form field name
        * @return 		string
		* @access 		public
        */
		public function getCSSFormFieldCellClass($field_name)
			{
				$class_name = isset($this->fields_err_tip_arr[$field_name]) ? 'form_field_cell_error' : 'form_field_cell_default';
				return $this->css_class_arr[$class_name];
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function appendMetaDetails($text_to_add, $category)
			{
				global $LANG, $CFG;

				$split_string = explode(" ", $text_to_add);
				if($CFG['html']['meta']['min_characters_appendable'] && (count($split_string) > $CFG['html']['meta']['min_characters_appendable']))
					{
						$new_text = '';
						for($inc = 0; $inc < $CFG['html']['meta']['min_characters_appendable']; $inc++)
							{
								$new_text.=$split_string[$inc].' ';
							}
						$text_to_add = $new_text;
					}
				$text_to_add = htmlspecialchars($category.$text_to_add);
				if(isset($LANG['meta_'.strtolower($CFG['html']['current_script_name']).'_keywords']))
					$LANG['meta_'.strtolower($CFG['html']['current_script_name']).'_keywords'] = $text_to_add.', '.$LANG['meta_'.strtolower($CFG['html']['current_script_name']).'_keywords'];
				else
					$CFG['html']['meta']['keywords'] = $text_to_add.', '.$CFG['html']['meta']['keywords'];

				if(isset($LANG['meta_'.strtolower($CFG['html']['current_script_name']).'_description']))
					$LANG['meta_'.strtolower($CFG['html']['current_script_name']).'_description'] = $text_to_add.', '.$LANG['meta_'.strtolower($CFG['html']['current_script_name']).'_description'];
				else
					$CFG['html']['meta']['description'] = $text_to_add.', '.$CFG['html']['meta']['description'];
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getTimeToGoFormat($time)
			{
				global $LANG;
				$date_added_pc = explode(':', $time);

				$date_added_pc[0] = intval($date_added_pc[0]);
				$date_added_pc[1] = intval($date_added_pc[1]);
				$date_added_pc[2] = intval($date_added_pc[2]);

				if($date_added_pc[0])
					{
						$day = floor($date_added_pc[0]/24);
						if($day>365)
							{
								$year = floor($day/365);
								if($year == 1)
									$time = $year.' '.$LANG['year_left_to_answer'];
								else
									$time = $year.' '.$LANG['years_left_to_answer'];
							}
						else if($day>30)
							{
								$month = floor($day/30);
								if($month == 1)
									$time = $month.' '.$LANG['month_left_to_answer'];
								else
									$time = $month.' '.$LANG['months_left_to_answer'];
							}
						else if($day)
							{
								if($day == 1)
									$time = $day.' '.$LANG['day_left_to_answer'];
								else
									$time = $day.' '.$LANG['days_left_to_answer'];
							}
						else
							{
								if($date_added_pc[0] == 1)
									$time = $date_added_pc[0].' '.$LANG['hour_left_to_answer'];
								else
									$time = $date_added_pc[0].' '.$LANG['hours_left_to_answer'];
							}
					}
				else if($date_added_pc[1])
					{
						if($date_added_pc[1] == 1)
							$time = $date_added_pc[1].' '.$LANG['minute_left_to_answer'];
						else
							$time = $date_added_pc[1].' '.$LANG['minutes_left_to_answer'];
					}
				else
					{
						if($date_added_pc[2] == 1)
							$time = $date_added_pc[2].' '.$LANG['second_left_to_answer'];
						else
							$time = $date_added_pc[2].' '.$LANG['seconds_left_to_answer'];
					}
				return $time;
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function getTimeDiffernceFormat($time)
			{
				return getTimeDiffernce($time);
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function addThisOption()
			{
				addThisOption();
				return ;
			}
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getBrowser($id='', $height='')
			{
				return getBrowser($id, $height);
			}
		/**
		 *
		 * @access public
		 * @return void
		 **/
		public function isFavoriteContent($cid, $ctype)
		    {
				$sql = 'SELECT bookmark_id FROM '.$this->CFG['db']['tbl']['user_bookmarked'].
						' WHERE content_id = '.$this->dbObj->Param('content_id') .' AND'.
						' content_type = '.$this->dbObj->Param('content_type').' AND'.
						' user_id = '.$this->dbObj->Param('user_id');

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

				$ok = false;
				if ($rs->PO_RecordCount())
					$ok = true;
				return $ok;
		    }
		/**
		 * AnovaHandler::ShowHelpTip()
		 *
		 * @param $tip_key
		 * @param $tip_for
		 * @return
		 **/
		public function ShowHelpTip($tip_key = '', $tip_for = '')
			{
				ShowHelpTip($tip_key, $tip_for);
			}

				/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getSeoTitleForBlogs($subject = '', $blog_id = 0)
			{
				return $this->getSeoTitle($this->CFG['db']['tbl']['blogs'], 'subject' ,$subject , 'blog_id', $blog_id);
			}
	}
?>