<?php
/**
 * chkIsAllowedModule()
 *
 * @param array $module_arr
 * @return
 */
if(!function_exists('chkIsAllowedModule')){
function chkIsAllowedModule($module_arr = array())
	{
		global $CFG;
		foreach($module_arr as $key=>$value)
			{
				if(!isset($CFG['admin']['module'][$value]) or !$CFG['admin']['module'][$value])
					return false;
			}
		return true;
	}
}
/**
 * chkIsVideoAllowed()
 *
 * @param mixed $type
 * @return
 */
function chkIsVideoAllowed($type)
	{
		if (!proceeedSite()) return false;
		global $CFG;
		if(!isset($CFG['admin']['module']['video']) or !$CFG['admin']['module']['video'])
			return false;
		if(!isset($CFG['admin'][$type]['video']) or !$CFG['admin'][$type]['video'])
			return false;
		return true;
	}

function chkIsPaymentAllowed($type='payment')
	{
		global $CFG;
		if(!$CFG['admin']['module']['payment'])
			return false;

		if(isAdmin() or isNoPlansAvailable())
			return false;

		if (!proceeedSite()) return false;

		if(!isset($CFG['admin']['payment']['needed']) or !$CFG['admin']['payment']['needed'])
			return false;
		if(!isset($CFG['admin'][$type]['needed']) or !$CFG['admin'][$type]['needed'])
			return false;
		return true;
	}

function chkIsPaymentUpgradeAllowed($type='payment_upgrade')
	{
		if(!chkIsPaymentAllowed())
			return false;

		global $CFG;
		if(!isset($CFG['admin'][$type]['needed']) or !$CFG['admin'][$type]['needed'])
			return false;
		return true;
	}

/**
 * chkIsAudioAllowed()
 *
 * @param mixed $type
 * @return
 */
function chkIsAudioAllowed($type)
	{
		if (!proceeedSite()) return false;
		global $CFG;
		if(!isset($CFG['admin']['module']['audio']) or !$CFG['admin']['module']['audio'])
			return false;
		if(!isset($CFG['admin'][$type]['audio']) or !$CFG['admin'][$type]['audio'])
			return false;
		return true;
	}

function assignSessionToCFGplan()
	{
		global $CFG, $db;
		//if(!isset($_SESSION['plan']['plan_id']) && $_SESSION['plan']['plan_id'] == '')
		//	$_SESSION['plan']['plan_id'] = 1;

		if(isset($_SESSION['plan']['plan_id']) && $_SESSION['plan']['plan_id'] != '')
			$plan_id = $_SESSION['plan']['plan_id'];
		else
			{
				if(isMember()) Redirect2Url(getUrl('logout', '?inv', '?inv', 'root'));
				$plan_id = 0;
			}

		//need to disable the below to get default plan array for expired plan users
		//if(!$plan_id)
		//	return false;

		$sql = 'SELECT * FROM '.$CFG['db']['tbl']['payment_plan_settings'].' WHERE plan_id = \''.$plan_id.'\'';

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

		if($rs->PO_RecordCount())
			{
				$row = $rs->FetchRow();
				foreach($CFG['payment']['log_array'] as $k=>$v)
					{
						$CFG['plan'][$v] = $row[$v];
						$_SESSION['plan'][$v] = $row[$v];
					}
			}

		elseif($plan_id == '0')
			{
				$row = $CFG['payment']['default_log_array'];
				foreach($CFG['payment']['log_array'] as $k=>$v)
					{
						$CFG['plan'][$v] = $row[$v];
						$_SESSION['plan'][$v] = $row[$v];
					}
			}

	}

function getReceiptId($text)
	{
		return $text.md5(microtime());
	}

function writeLogForPayment($fileName,$arrKvp,$receiptId,$trdate='')
	{
		global $CFG;
		$kvp='';
		$stringData='';
		foreach ($arrKvp as $key => $value)
				{
 					$kvp.=$key.'='.$value.'&';
				}

		$fh = fopen($CFG['site']['project_path'].'files/logs/'.$fileName, 'a') or die("can't open file");
		fwrite($fh, $stringData);
		$stringData = "#~~#\n";
		fwrite($fh, $stringData);
		if($trdate != '')
			{
				$update = explode('/',$trdate);
				$stringData = "Added On: ".date('l dS \of F Y h:i:s A',mktime(0, 0, 0, $update[0], $update[1], $update[2]))."\n";
			}
		else
			{
				$stringData = "Added On: ".date('l dS \of F Y h:i:s A')."\n";
			}
		fwrite($fh, $stringData);
		$stringData = "Receipt Id: ".$receiptId."\n";
		fwrite($fh, $stringData);
		$stringData = "KVP:$kvp\n";
		fwrite($fh, $stringData);
		fclose($fh);
		//echo $stringData;
	}

/**
 * setUserConfigVariables()
 *
 * @return
 */
function setUserConfigVariables()
	{
		global $CFG;
		if(!isMember())
			{
				return false;
			}
		//everything is ok. stuff to $CFG array
		$CFG['user']['user_id'] = $_SESSION['user']['user_id'];
		$CFG['user']['name'] = $_SESSION['user']['name'];
		$CFG['user']['display_name'] = (isset($_SESSION['user']['display_name']))?$_SESSION['user']['display_name']:$_SESSION['user']['name'];
		$CFG['user']['email'] = $_SESSION['user']['email'];
		$CFG['user']['time_zone'] = $_SESSION['user']['time_zone'];
		$CFG['user']['pref_lang'] = $_SESSION['user']['pref_lang'];
		$CFG['user']['is_logged_in'] = $_SESSION['user']['is_logged_in'];
		$CFG['user']['usr_type'] = (isset($_SESSION['user']['usr_type']))?$_SESSION['user']['usr_type']:'';
		$CFG['user']['signup_type'] = (isset($_SESSION['user']['signup_type']))?$_SESSION['user']['signup_type']:'';
		$CFG['user']['expiry_date'] = (isset($_SESSION['user']['expiry_date']))?$_SESSION['user']['expiry_date']:'';
		$CFG['user']['last_paid_date'] = (isset($_SESSION['user']['last_paid_date']))?$_SESSION['user']['last_paid_date']:'';
		if(isset($_SESSION['user']['is_admin']))
			$CFG['user']['is_admin'] = $_SESSION['user']['is_admin'];

		return true;
	}

function getUserLog($user_id)
	{
		global $CFG, $db;
		$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 '.$CFG['db']['tbl']['users_ans_log'].
				' WHERE user_id='.$db->Param($user_id);
		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt, array($user_id));
		if (!$rs)
		        trigger_db_error($db);
		$user_ans_log = array('total_ques'=>'0', 'total_ans'=>'0', 'total_points'=>'0', 'date_updated'=>'');
		if ($rs->PO_RecordCount())
			$user_ans_log = $rs->FetchRow();

		return $user_ans_log;
	}
/**
 * getPopupDivId()
 *
 * @return
 */
function getPopupDivId()
	{
		global $popup_id;

		return $popup_id += 1;
	}
/**
 * getBrowser()
 *
 * @param string $id
 * @param string $height
 * @return
 */
function getBrowser($id='', $height='')
	{
		return $video_add_popup = 'return openAnovaAjaxWindow(\''.$id.'\');';
	}

/**
 * displayProfileImage()
 *
 * @param mixed $img_arr
 * @param mixed $img_type
 * @param mixed $showPopup
 * @param mixed $contentDisplay
 * @param mixed $changePosition
 * @return
 */
function displayProfileImage($img_arr, $img_type, $showPopup = true, $contentDisplay = false, $changePosition = false)
    {
		global $CFG, $smartyObj;
		$displayProfileImage_arr = array();
		if (isUserImageAllowed())
			{
				$img_src = '';
				$width = '';
				$attr = '';
				$img_type_lc = strtolower($CFG['admin']['ans_photos'][$img_type.'_name']);
				if (isset($img_arr['image_path']) AND !empty($img_arr['image_path']))
					{
						$img_src = $img_arr['image_path'];
						$attr = ' width="'.$CFG['admin']['ans_photos'][$img_type.'_width'].'"';
					}
				else if (isset($img_arr['photo_ext']) AND (!empty($img_arr['photo_ext'])))
					{
						$img_src = $img_arr['photo_server_url'].$CFG['admin']['ans_photos']['folder'].getImageName($img_arr['img_user_id']).$CFG['admin']['ans_photos'][$img_type.'_name'].'.'.$img_arr['photo_ext'];
						$attr = GET_IMAGE_ATTRIBUTES($CFG['admin']['ans_photos'][$img_type.'_width'], $CFG['admin']['ans_photos'][$img_type.'_height'], $img_arr[$img_type_lc.'_width'], $img_arr[$img_type_lc.'_height']);
					}
				elseif(isset($img_arr['gender']) AND !empty($img_arr['gender']))
					{
						$gender = strtoupper($img_arr['gender']);
						$img_src = $CFG['site']['url'].'design/templates/'.$CFG['html']['template']['default'].'/images/no-female-'.$img_type.'.jpg';
						if ($gender == 'M' || $gender == 'MALE')
							$img_src = $CFG['site']['url'].'design/templates/'.$CFG['html']['template']['default'].'/images/no-male-'.$img_type.'.jpg';
					}

				$displayProfileImage_arr['img_src'] = $img_src;
				$displayProfileImage_arr['additional_class'] = '';
				if ($changePosition)
					$displayProfileImage_arr['additional_class'] = ' clsForumUserPopup';

				if ($img_src)
					{
						$altName = (isset($img_arr['asked_by']))? $img_arr['asked_by'] : ((isset($img_arr['answered_by']))? $img_arr['answered_by']:((isset($img_arr['display_name']))? $img_arr['display_name']:''));
						$altName = stripString($altName, $CFG['username']['short_length']);
						$user_url = getMemberUrl($img_arr['user_id'], $img_arr['name']);
						if (strpos($CFG['site']['relative_url'], 'admin/'))
							$user_url = $CFG['site']['url'].'admin/viewMembers.php?uid='.$img_arr['user_id'];

						$displayProfileImage_arr['showPopup'] = $showPopup;
						if ($showPopup)
							{
								$url = getAnovaUrl('userdetails');
								$pars = 'uid='.$img_arr['user_id'];
								$popupDivId = 'popup_'.getPopupDivId();
								if (isset($img_arr['image_id']))
									$popupDivId .= $img_arr['image_id'].'_'.$popupDivId;

								$onmouseover = 'showUserInfoPopup(\''.$url.'\', \''.$pars.'\', \''.$popupDivId.'\');';
								if ($contentDisplay)
									{
										$onmouseover .= 'changePopupDivPosition(\''.$popupDivId.'\');';
							 		}
							 	$onmouseover = 'onmouseover="'.$onmouseover.'"';
								$displayProfileImage_arr['onmouseover'] = $onmouseover;
								$displayProfileImage_arr['user_url'] = $user_url;
								$displayProfileImage_arr['popupDivId'] = $popupDivId;
								$displayProfileImage_arr['attr'] = $attr;
								$displayProfileImage_arr['altName'] = $altName;
								$displayProfileImage_arr['url'] = $url;
								$displayProfileImage_arr['pars'] = $pars;
							}
						else
							{
								$displayProfileImage_arr['user_url'] = $user_url;
								$displayProfileImage_arr['attr'] = $attr;
								$displayProfileImage_arr['altName'] = $altName;
							}
					}
			}
		$smartyObj->assign('displayProfileImage_arr', $displayProfileImage_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
		if(($CFG['site']['script_name'] == 'manageSettings.php' && $img_type == 'medium') || ($CFG['site']['script_name'] == 'myanswers.php' && $img_type == 'medium'))
			$smartyObj->display('displayUserImage.tpl');
		else
			$smartyObj->display('displayProfileImage.tpl');
    }
/**
 * displayBlogUserSmallImage()
 *
 * @param mixed $img_arr
 * @param mixed $showPopup
 * @return
 */
function displayBlogUserSmallImage($img_arr, $showPopup = true)
    {
		displayProfileImage($img_arr, 'small', $showPopup);
		return ;
    }

/**
 * displayForumUserSmallImage()
 *
 * @param mixed $img_arr
 * @param mixed $showPopup
 * @param mixed $contentDisplay
 * @param mixed $changePosition
 * @return
 */
function displayForumUserSmallImage($img_arr, $showPopup = true, $contentDisplay = false, $changePosition = false)
    {
    	displayProfileImage($img_arr, 'small', $showPopup, $contentDisplay, $changePosition);
		return ;
    }

/**
 * getQuestionBadgeUrl()
 *
 * @param string $qid
 * @param mixed $append_script
 * @return
 */
function getQuestionBadgeUrl($qid = '', $append_script = true)
	{
		global $CFG;
		$badgeUrl = getAnovaUrl('embedcontent', '?embed=question&amp;qid='.$qid, 'question/'.$qid.'/', 'root');

		if ($append_script)
			{
				$badgeUrl = '<script src="'.$badgeUrl.'"></script>';
			}
		return $badgeUrl;
	}
function getAnovaUrl($file_name, $normal = '', $htaccess = '', $change = '')
	{
		global $CFG;
		return getAnova2Url($file_name, $normal, $htaccess, $change, $CFG['admin']['index']['anova_module']);
	}
function getForumsUrl($file_name, $normal = '', $htaccess = '', $change = '')
	{
		return getAnova2Url($file_name, $normal, $htaccess, $change, 'forums');
	}
function getBlogUrl($file_name, $normal = '', $htaccess = '', $change = '')
	{
		return getAnova2Url($file_name, $normal, $htaccess, $change, 'blog');
	}
function getDebatesUrl($file_name, $normal = '', $htaccess = '', $change = '')
	{
		return getAnova2Url($file_name, $normal, $htaccess, $change, 'debate');
	}
/**
 * proceeedSite()
 *
 * @return
 */
function proceeedSite()
	{
		return true;
	}
/**
 * isUserImageAllowed()
 *
 * @return
 */
function isUserImageAllowed()
	{
		global $CFG;
		if(!isset($CFG['admin']['profile_image']['allowed']) or !$CFG['admin']['profile_image']['allowed'])
			return false;
		return true;
	}
function getUserLevelNumber($points)
	{
		global $CFG;
		if($points >= $CFG['user']['level_six']['points'])
			{
				$userLevelNumber = '6';
			}
		elseif($points >= $CFG['user']['level_five']['points'])
			{
				$userLevelNumber = '5';
			}
		elseif($points >= $CFG['user']['level_four']['points'])
			{
				$userLevelNumber = '4';
			}
		elseif($points >= $CFG['user']['level_three']['points'])
			{
				$userLevelNumber = '3';
			}
		elseif($points >= $CFG['user']['level_two']['points'])
			{
				$userLevelNumber = '2';
			}
		else
			{
				$userLevelNumber = '1';
			}
		return $userLevelNumber;
	}
/**
 * To show answers search option
 *
 * @return 		void
 * @access 		public
 */
function showAnswerSearchOption()
	{
		$not_allowed_pages_array = array('blogCategory.php', 'blogComment.php',
		                                 'blogs.php', 'manageBlog.php', 'topAnalysts.php',
										 'forums.php', 'forumsResponses.php', 'forumsTopics.php',
										 'forumsResponseCreate.php', 'forumSearch.php', 'forumsTopicCreate.php',
										 'mySubscribedForum.php', 'forumsAddTitle.php', 'debates.php',
										 'debatesResponse.php', 'debateCategories.php', 'debateTags.php');

		if(displayBlock($not_allowed_pages_array))
			return;

		global $smartyObj, $LANG, $CFG;
		$showAnswerSearchOption_arr = array();

		/*if($this->getFormField('more_questions'))
			{
				if(isset($_SESSION['more_questions']) && $this->_currentPage == 'questions')
					$showAnswerSearchOption_arr['question_field_value'] = $_SESSION['more_questions'];
			}
		else if($this->getFormField('search_question'))
			{
				if(isset($_SESSION['search_question']) && $this->_currentPage == 'questions')
					$showAnswerSearchOption_arr['question_field_value'] = $_SESSION['search_question'];
				else
					{
						$showAnswerSearchOption_arr['question_field_value'] = $this->LANG['header_search_for_questions'];
					}
			}
		else*/
			$showAnswerSearchOption_arr['question_field_value'] = $LANG['header_search_for_questions'];

		$showAnswerSearchOption_arr['defaultText'] = $LANG['header_search_for_questions'];

		$showAnswerSearchOption_arr['form_action'] = getAnovaUrl('questions', '?view=search', 'search/');
		$showAnswerSearchOption_arr['advanced_search']['url'] = getAnovaUrl('questions', '?so=adv&amp;view=search', 'search/?so=adv');

		$smartyObj->assign('showAnswerSearchOption_arr', $showAnswerSearchOption_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
		$smartyObj->display('showAnswerSearchOption.tpl');
	}
/**
 * To show forums search option
 *
 * @return 		void
 * @access 		public
 */
function showForumsSearchOption()
	{
		$allowed_pages_array = array('forums.php', 'forumsResponses.php', 'forumsResponseCreate.php', 'forumsAddTitle.php',
									 'forumSearch.php', 'forumsTopics.php', 'forumsTopicCreate.php', 'mySubscribedForum.php');

		if(!displayBlock($allowed_pages_array))
			return;

		global $smartyObj, $LANG, $CFG;
		$showForumsSearchOption_arr = array();

		/*if($this->getFormField('forum_topic'))
			{
				if(isset($_SESSION['forum_topic']) && $this->_currentPage == 'forumsearch')
					$showForumsSearchOption_arr['forum_field_value'] = $_SESSION['forum_topic'];
			}
		else if($this->getFormField('search_forum_topic'))
			{
				if(isset($_SESSION['search_forum_topic']) && $this->_currentPage == 'forumsearch')
					{
						$showForumsSearchOption_arr['forum_field_value'] = $_SESSION['search_forum_topic'];
					}
				else
					{
						$showForumsSearchOption_arr['forum_field_value'] = $this->LANG['header_search_for_forum_topics'];
					}
			}
		else*/
			$showForumsSearchOption_arr['forum_field_value'] = $LANG['header_search_for_forum_topics'];

		$showForumsSearchOption_arr['defaultText'] = $LANG['header_search_for_forum_topics'];

		$showForumsSearchOption_arr['form_action'] = getForumsUrl('forumsearch');
		$showForumsSearchOption_arr['advanced_search']['url'] = getForumsUrl('forumsearch', '?so=adv', '?so=adv');

		$smartyObj->assign('showForumsSearchOption_arr', $showForumsSearchOption_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['forum_module']);
		$smartyObj->display('showForumsSearchOption.tpl');
	}
/**
* To show blogs search option
*
* @return 		void
* @access 		public
*/
function showBlogsSearchOption()
	{
		$allowed_pages_array = array('blogCategory.php', 'blogComment.php',
		                         'blogs.php', 'manageBlog.php');

		if(!displayBlock($allowed_pages_array))
		return;

		global $smartyObj, $LANG, $CFG;
		$showBlogsSearchOption_arr = array();
		/*
		if($this->getFormField('subject'))
		{
			if(isset($_SESSION['subject']) && $this->_currentPage == 'blogs')
				$showBlogsSearchOption_arr['blog_field_value'] = $_SESSION['subject'];
		}
		else if($this->getFormField('search_blog_subject'))
		{
			if(isset($_SESSION['search_blog_subject']) && $this->_currentPage == 'blogs')
				{
					$showBlogsSearchOption_arr['blog_field_value'] = $_SESSION['search_blog_subject'];
				}
			else
				{
					$showBlogsSearchOption_arr['blog_field_value'] = $this->LANG['header_search_for_blog_subject'];
				}
		}
		else*/
		$showBlogsSearchOption_arr['blog_field_value'] = $LANG['header_search_for_blog_subject'];

		$showBlogsSearchOption_arr['defaultText'] = $LANG['header_search_for_blog_subject'];
		$showBlogsSearchOption_arr['form_action'] = getBlogUrl('blogs');
		$showBlogsSearchOption_arr['advanced_search']['url'] = getBlogUrl('blogs', '?so=adv', '?so=adv');

		$smartyObj->assign('showBlogsSearchOption_arr', $showBlogsSearchOption_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['blog_module']);
		$smartyObj->display('showBlogsSearchOption.tpl');
	}
/**
 * HeaderFormHandler::showMemberSearchOption()
 *
 * @return
 */
function showMemberSearchOption()
	{
		$allowed_pages_array = array('topAnalysts.php');

		if(!displayBlock($allowed_pages_array))
			return;

		global $smartyObj, $LANG, $CFG;
		$showMemberSearchOption_arr = array();

		/*if($this->getFormField('search_member'))
			$showMemberSearchOption_arr['question_field_value'] = $this->getFormField('search_member');
		else*/
			$showMemberSearchOption_arr['question_field_value'] = $LANG['header_search_for_members'];

		$showMemberSearchOption_arr['defaultText'] = $LANG['header_search_for_members'];
		$showMemberSearchOption_arr['form_action'] = getAnovaUrl('topanalysts');
		$showMemberSearchOption_arr['advanced_search']['url'] = getAnovaUrl('topanalysts', '?so=adv', '?so=adv');

		$smartyObj->assign('showMemberSearchOption_arr', $showMemberSearchOption_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
		$smartyObj->display('showMemberSearchOption.tpl');
	}
/**
 * To show debate search obtion
 * @return 		void
 * @access 		public
 */
function showDebateSearchOption()
	{
		$allowed_pages_array = array('debates.php', 'debatesResponse.php',
		                             'debateCategories.php', 'debateTags.php');
		if(!displayBlock($allowed_pages_array))
			return;

		global $smartyObj, $LANG, $CFG;
		$showDebateSearchOption_arr = array();

		/*if($this->getFormField('more_debates'))
			{
				if(isset($_SESSION['more_debates']) && $this->_currentPage == 'debates')
					$showDebateSearchOption_arr['debate_field_value'] = $_SESSION['more_debates'];
			}
		elseif($this->getFormField('search_debate'))
			{
				if(isset($_SESSION['search_debate']) && $this->_currentPage == 'debates')
					$showDebateSearchOption_arr['debate_field_value'] = $_SESSION['search_debate'];
				else
					{
						$showDebateSearchOption_arr['debate_field_value'] = $this->LANG['search_for_debates'];
					}
			}
		else*/
			$showDebateSearchOption_arr['debate_field_value'] = $LANG['search_for_debates'];
		$showDebateSearchOption_arr['defaultText'] = strtolower($LANG['search_for_debates']);

		$showDebateSearchOption_arr['form_action'] = getDebatesUrl('debates', '?view=search', 'search/');
		$showDebateSearchOption_arr['advanced_search']['url']= getDebatesUrl('debates', '?so=adv&view=search', 'search/?so=adv');

		$smartyObj->assign('showDebateSearchOption_arr', $showDebateSearchOption_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['debate_module']);
		$smartyObj->display('showDebateSearchOption.tpl');
	}
/**
 *
 * @return 		void
 * @access 		public
 */
function solvedQuestionsCount()
	{
		global $smartyObj, $db, $CFG;
		$smartyObj->assign('solved_question_count', 0);

		$sql = 'SELECT ques_id FROM '.$CFG['db']['tbl']['questions'].
				' WHERE status NOT IN(\'Blocked\',\'ToActivate\') AND date_closed < NOW()';
		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt);
		if (!$rs)
			    trigger_db_error($db);
		if ($solved_question_count = $rs->PO_RecordCount() AND $solved_question_count > 1)
			{
				$smartyObj->assign('solved_question_count', ($solved_question_count - 1));
				return true;
			}
		return false;
	}

/**
* HeaderFormHandler::populateTopMenu()
*
* @return
*/
function populateTopMenu()
{
	global $smartyObj, $CFG;

	$anovaObj = new FormHandler();

	$populateTopMenu_arr = array();
	$currentPage = $CFG['html']['current_script_name'];
	$cssClassToMainLink = 'clsActiveHeaderMainLink';
	$cssClassToHighlightMainLink = 'clsActiveLink clsHighlightHeaderLink';
	$populateTopMenu_arr['forums']['class'] = $populateTopMenu_arr['blogs']['class'] = $populateTopMenu_arr['debate']['class'] = $populateTopMenu_arr['mail']['class'] = $populateTopMenu_arr['login']['class'] = $populateTopMenu_arr['payment']['class'] = $populateTopMenu_arr['logout']['class'] = $cssClassToMainLink;
	$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
	$$currentPage = $cssClassToHighlightMainLink;

	$ans_page_arr = array('questions', 'answer', 'categories', 'tags');
	if(in_array($currentPage, $ans_page_arr))
		{
			$populateTopMenu_arr['questions']['class'] = $cssClassToHighlightMainLink;
		}

	$ans_page_arr = array('forums', 'forumsAddTitle', 'forumsTopics', 'forumsTopicCreate', 'forumsResponses', 'forumsResponseCreate', 'forumSearch');
	if(in_array($currentPage, $ans_page_arr))
		{
			$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
			$populateTopMenu_arr['forums']['class'] = $cssClassToHighlightMainLink;
		}

	$ans_page_arr = array('blogs', 'blogCategory', 'blogComment', 'manageBlog');
	if(in_array($currentPage, $ans_page_arr))
		{
			$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
			$populateTopMenu_arr['blogs']['class'] = $cssClassToHighlightMainLink;
		}

	$ans_page_arr = array('mail', 'mailCompose', 'mailRead');
	if(in_array($currentPage, $ans_page_arr))
		{
			$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
			$populateTopMenu_arr['mail']['class'] = $cssClassToHighlightMainLink;
		}

	$ans_page_arr = array('login', 'devLogin');
	if(in_array($currentPage, $ans_page_arr))
		{
			$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
			$populateTopMenu_arr['login']['class'] = $cssClassToHighlightMainLink;
		}

	$ans_page_arr = array('debates', 'debatesResponse','debateCategories','debateTags');
	if(in_array($currentPage, $ans_page_arr))
		{
			$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
			$populateTopMenu_arr['debate']['class'] = $cssClassToHighlightMainLink;
		}

	$ans_page_arr = array('paymentUpgrade');
	if(in_array($currentPage, $ans_page_arr))
		{
			$populateTopMenu_arr['questions']['class'] = $cssClassToMainLink;
			$populateTopMenu_arr['payment']['class'] = $cssClassToHighlightMainLink;
		}

	$populateTopMenu_arr['questions']['url'] = getAnovaUrl('questions');
	$populateTopMenu_arr['forums']['url'] = getForumsUrl('forums');
	$populateTopMenu_arr['blogs']['url'] = getBlogUrl('blogs');
	$populateTopMenu_arr['debate']['url'] = getDebatesUrl('debates','?view=open&sort=date&order=d','?sort=date&order=d');
	$populateTopMenu_arr['mail']['url'] = getUrl('mail', '?folder=inbox', 'inbox/', 'members');
	$populateTopMenu_arr['login']['url'] = getUrl('login', '', '', 'root');
	$populateTopMenu_arr['logout']['url'] = getUrl('logout', '', '', 'root');
	$populateTopMenu_arr['payment']['url'] = getAnovaUrl('paymentupgrade', '', '', 'members');

	if ($CFG['user']['user_id'])
		{
			$populateTopMenu_arr['profile']['url'] = getMemberUrl($CFG['user']['user_id'], $CFG['user']['name']);
			$populateTopMenu_arr['settings']['url'] = getSettingsUrl();
			$populateTopMenu_arr['userLog'] = getUserLog($CFG['user']['user_id']);
			$populateTopMenu_arr['userLevelNumber'] = '';
			if($CFG['admin']['user_levels']['allowed'])
				$populateTopMenu_arr['userLevelNumber'] = getUserLevelNumber($populateTopMenu_arr['userLog']['total_points']);
		}

	$populateTopMenu_arr['myprofile']['url'] = getMemberUrl($CFG['user']['user_id'], $CFG['user']['name']);
	$populateTopMenu_arr['editprofile']['url'] = getSettingsUrl();
	$populateTopMenu_arr['user_details'] = getUserDetailsFromUsersTable($CFG['db']['tbl']['users'], $CFG['user']['user_id']);
	//$populateTopMenu_arr['displayUserImage'] = displayProfileImage($populateTopMenu_arr['user_details'], 'small', false);

	$smartyObj->assign('populateTopMenu_arr', $populateTopMenu_arr);
	setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
	$smartyObj->display('populateTopMenu.tpl');
}
function getUserDetailsFromUsersTable($user_table, $user_id)
	{
		global $CFG;
		global $db;

		$sql = 'SELECT '.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')).
				', '.getUserTableField('user_id').' AS img_user_id'.
				' FROM '.$user_table.
				' WHERE '.getUserTableField('user_id').' = '.$db->Param($user_id);
		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt, array($user_id));
		if (!$rs)
				trigger_db_error($db);
		$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();
			}
		return	$row;
	}
function getUserTableField($user_field)
    {
    	global $CFG;
		return $CFG['users'][$user_field];
    }
function getUserTableFields($user_fields, $trim=true)
    {
		global $CFG;

		$str = '';
		foreach($user_fields as $field){
			if (isset($CFG['users'][$field]) AND $CFG['users'][$field])
				$str .= $CFG['users'][$field].' AS '.$field.', ';
		}
		if ($trim)
			$str = substr($str, 0, strrpos($str, ', '));
		return $str;
    }
function getSettingsUrl()
	{
		return getAnovaUrl('managesettings', '', '', 'members');
		//FOR RAYZZ INTEGRATION
		//return getUrl('profilebasic', '', '', 'members');
	}
/**
 * getAnovaModuleRightMenu()
 *
 * @param mixed $question_table
 * @param mixed $limit
 * @return
 */
function getAnovaModuleRightMenu()
	{
		global $smartyObj, $db, $CFG;

		$populateAlphabetPagingList_arr = array();

		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['answer']['manual'] = 'Answers';
		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['answer']['url'] = getAnovaUrl('questions');

		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['forums']['manual'] = 'Forums';
		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['forums']['url'] = getForumsUrl('forums');

		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['blog']['manual'] = 'Blogs';
		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['blog']['url'] = getBlogUrl('blogs');

		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['debate']['manual'] = 'Debates';
		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['debate']['url'] = getDebatesUrl('debates','?view=open&sort=date&order=d','?sort=date&order=d');

		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['inbox']['manual'] = 'Inbox';
		$getAnovaModuleRightMenu_arr['anova_module_right_menu']['inbox']['url'] = getUrl('mail', '?folder=inbox', 'inbox/', 'members');

		$smartyObj->assign('getAnovaModuleRightMenu_arr', $getAnovaModuleRightMenu_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
		$smartyObj->display('rightBarAnova.tpl');
	}

/**
 * HeaderFormHandler::getUnansweredQuestion()
 *
 * @param mixed $question_table
 * @param mixed $limit
 * @return
 */
function getUnansweredQuestion($question_table, $limit)
	{
		global $smartyObj, $db, $CFG;
		$getUnansweredQuestion_arr = array();
		$sql = 'SELECT ques_id, user_id, question, seo_title FROM '.$question_table.
			   ' WHERE total_answer = 0 '.
			   ' AND (status = \'Open\' OR status = \'Resolved\') ORDER BY RAND()';
		if ($limit)
			$sql .= ' LIMIT 0,'.($limit + 1);
		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt);
		if (!$rs)
			    trigger_db_error($db);

		$getUnansweredQuestion_arr['count'] = $rs->PO_RecordCount();
		if ($count = $rs->PO_RecordCount())
			{
				$i = $inc = 1;
				$getUnansweredQuestion_arr['row'] = array();
				while($row = $rs->FetchRow())
					{
						$getUnansweredQuestion_arr['row'][$inc]['record'] = $row;
						$getUnansweredQuestion_arr['row'][$inc]['answer']['url'] = getAnovaUrl('answer', '?title='.$row['seo_title'], $row['seo_title'].'/');
						$getUnansweredQuestion_arr['row'][$inc]['row_question_manual'] = stripString($row['question']);

						$inc++;
              			if ($i++ >= $limit)
							break;
					}
			}
		$getUnansweredQuestion_arr['unanswered_questions']['url'] = getAnovaUrl('questions', '?view=unanswered', 'unanswered/');

		$smartyObj->assign('getUnansweredQuestion_arr', $getUnansweredQuestion_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
		$smartyObj->display('getUnansweredQuestion.tpl');
	}

/**
 * HeaderFormHandler::populateAlphabetPagingList()
 *
 * @param mixed $paging_list_arr
 * @return
 */
function populateAlphabetPagingList($paging_list_arr, $anovaObj)
	{
		global $smartyObj, $db, $CFG;

		$populateAlphabetPagingList_arr = array();
		$inc = 1;
		foreach($paging_list_arr as $key=>$value)
			{
				$populateAlphabetPagingList_arr[$inc]['alphaUrl'] = getAnovaUrl('questions', '?view=all&amp;al='.$key, 'open/?al='.$key);
				$populateAlphabetPagingList_arr[$inc]['clsActiveQuestionLib'] = '';
				if ($anovaObj->getFormField('al') == $value)
					$populateAlphabetPagingList_arr[$inc]['clsActiveQuestionLib'] = ' class="clsActiveQuestionLib"';
				elseif ($anovaObj->getFormField('al') == 1 AND $value == '#')
					$populateAlphabetPagingList_arr[$inc]['clsActiveQuestionLib'] = ' class="clsActiveQuestionLib"';

				$populateAlphabetPagingList_arr[$inc]['value'] = $value;
				$inc++;
			}

		$smartyObj->assign('populateAlphabetPagingList_arr', $populateAlphabetPagingList_arr);
		setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
		$smartyObj->display('populateAlphabetPagingList.tpl');
	}

/**
 *
 * @access public
 * @return void
 **/
function getAllCategories($cat_table, $limit, $for, $anovaObj)
    {
    	global $smartyObj, $db, $CFG;

    	$getAllCategories_arr = array();
    	if($for == 'total_debates')
			{
				$allowed_pages_array = array('debates.php', 'debatesResponse.php', 'debateCategories.php','debateTags.php');
				if(!displayBlock($allowed_pages_array))
					return;
			}
		$sql = 'SELECT cat_id, cat_name, seo_title, has_child, '.$for.' FROM '.$cat_table.
				' WHERE status=\'1\''.
				' AND parent_id=0'.
				' ORDER BY '.$for.' DESC';
		if ($limit)
			$sql .= ' LIMIT 0,'.($limit + 1);

		$parent_id = 0;
		$cat_id = 0;
		if ($anovaObj->getFormField('parent_id'))
			{
				$parent_id = $anovaObj->getFormField('parent_id');
				$cat_id = $anovaObj->getFormField('cid');
			}
		elseif ($anovaObj->getFormField('cat_id'))
			{
				$parent_id = $anovaObj->getFormField('cat_id');
			}

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

		$getAllCategories_arr['rs_PO_RecordCount'] = $rs->PO_RecordCount();
		$getAllCategories_arr['parent_id'] = $parent_id;
		if ($count = $rs->PO_RecordCount())
			{
				$i=1;
				$inc = 1;
				$getAllCategories_arr['row'] = array();
				while($row = $rs->FetchRow())
					{
						$getAllCategories_arr['row'][$inc]['record'] = $row;
						$getAllCategories_arr['row'][$inc]['class'] = 'clsInactive';
						if ($parent_id == $row['cat_id'])
							$getAllCategories_arr['row'][$inc]['class'] = 'clsActive';

						$getAllCategories_arr['row'][$inc]['clsDropDown'] = '';
						if ($row['has_child'] == '1')
							$getAllCategories_arr['row'][$inc]['clsDropDown'] = 'class="clsDropDown"';

						if($for == 'total_questions')
			  				$getAllCategories_arr['row'][$inc]['questions_category']['url'] = getAnovaUrl('questions', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/');
			  			elseif($for == 'total_debates')
							$getAllCategories_arr['row'][$inc]['questions_category']['url'] = getDebatesUrl('debates', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/');

						$getAllCategories_arr['row'][$inc]['row_cat_name_manual'] = stripString($row['cat_name']);

						if ($parent_id == $row['cat_id'])
							{
								$getAllCategories_arr['row'][$inc]['getAllSubCategories_arr'] = getAllSubCategories($cat_table, $parent_id, $cat_id, $for);
							}
						$inc++;
              			if ($i++ >= $limit)
              				break;
					}
			}
		if($for == 'total_debates')
			$getAllCategories_arr['categories']['url'] = getDebatesUrl('debatecategories');
		else
			$getAllCategories_arr['categories']['url'] = getAnovaUrl('categories');

		$smartyObj->assign('getAllCategories_arr', $getAllCategories_arr);

		if($for == 'total_debates')
			{
				setTemplateFolder('general/', $CFG['admin']['index']['debate_module']);
				$smartyObj->display('getAllDebateCategories.tpl');
			}
		else
			{
				setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
				$smartyObj->display('getAllCategories.tpl');
			}
    }

/**
 *
 * @access public
 * @return void
 **/
function getAllSubCategories($cat_table, $parent_id, $cat_id, $for)
    {
		if (!$parent_id)
			return ;

		global $smartyObj, $db, $CFG;

		$sql = 'SELECT cat_id, cat_name, seo_title, '.$for.' FROM '.$cat_table.
				' WHERE parent_id='.$db->Param('parent_id').' AND status=\'1\''.
				' ORDER BY cat_name';

		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt, array($parent_id));
		if (!$rs)
			    trigger_db_error($db);

		if ($count = $rs->PO_RecordCount())
			{
				$getAllSubCategories_arr = array();
				$inc = 1;
				while($row = $rs->FetchRow())
					{
						$getAllSubCategories_arr[$inc]['record'] = $row;
						$getAllSubCategories_arr[$inc]['class'] = 'clsInactive';
						if ($cat_id == $row['cat_id'])
							$getAllSubCategories_arr[$inc]['class'] = 'clsActive';
						if($for == 'total_questions')
							$getAllSubCategories_arr[$inc]['questions_category']['url'] = getAnovaUrl('questions', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/');
						elseif($for == 'total_debates')
							$getAllSubCategories_arr[$inc]['questions_category']['url'] = getDebatesUrl('debates', '?cat='.$row['seo_title'], 'dir/'.$row['seo_title'].'/');
						$getAllSubCategories_arr[$inc]['row_cat_name_manual'] = stripString($row['cat_name']);

						$inc++;
					}
				return $getAllSubCategories_arr;
			}
		return ;
    }

/**
 *
 * @return 		void
 * @access 		public
 */
function setFontSizeInsteadOfSearchCount($tag_array=array())
	{
		$formattedArray = $tag_array;
		$max_qty = max(array_values($formattedArray));
		$min_qty = min(array_values($formattedArray));
		$max_font_size = 28;
		$min_font_size = 12;
		$spread = $max_qty - $min_qty;
		if (0 == $spread) { // Divide by zero
			$spread = 1;
		}
		$step = ($max_font_size - $min_font_size)/($spread);
			foreach ($tag_array as $catname => $count)
			{
				$size = $min_font_size + ($count - $min_qty) * $step;
				$formattedArray[$catname] = ceil($size);
			}
		return $formattedArray;
	}

/**
 *
 * @return 		void
 * @access 		public
 */
function showTopTags()
	{
		global $smartyObj, $db, $CFG;

		if ($CFG['admin']['index']['top_tags'])
			{
				$showTopTags_arr = array();
				$showTopTags_arr['displayTopTags_arr'] = displayTopTags($CFG['admin']['index']['top_tags_count']);

				$smartyObj->assign('showTopTags_arr', $showTopTags_arr);
				setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
				$smartyObj->display('showTopTags.tpl');
			}
	}


/**
 * To display popular tags
 *
 * @return 		void
 * @access 		public
 */
function displayTopTags($limit = 5)
	{
		global $smartyObj, $db, $CFG;

		$displayTopTags_arr = array();
		$top_tags = getTags('TOP', $limit);
		$displayTopTags_arr['top_tags'] = $top_tags;

			if ($top_tags)
				{
					$classes = array('clsTagStyleBlue', 'clsTagStyleGrey', 'clsTagStyleGreen', 'clsTagStyleRed');
					$tagClassArray = array();
					foreach($top_tags as $row)
						{
							$tagArray[$row['tag_name']] = $row['total_count'];
							$class = $classes[rand(0, count($classes))%count($classes)];
							$tagClassArray[$row['tag_name']] = $class;
						}
					$tagArray = setFontSizeInsteadOfSearchCount($tagArray);

					$displayTopTags_arr['tag_arr'] = array();
					$inc = 1;
					foreach($tagArray as $tag=>$fontSize)
						{
							$displayTopTags_arr['tag_arr'][$inc]['questions_tag']['url'] = getAnovaUrl('questions', '?view=search&amp;tags='.$tag, 'search/?tags='.$tag);
							$displayTopTags_arr['tag_arr'][$inc]['class']	=	'clsTagStyleFont'.$fontSize;
							$displayTopTags_arr['tag_arr'][$inc]['tag'] = $tag;
							$inc++;
						}//foreach

            		$displayTopTags_arr['tags']['url'] = getAnovaUrl('tags', '?t=freq&amp;s=f', '?t=freq&amp;s=f');
				}
		return $displayTopTags_arr;
	}

/**
 *
 * @return 		void
 * @access 		public
 */
function getTags($type, $limit)
	{
		global $smartyObj, $db, $CFG;

		$sql = 'SELECT tag_name, search_count, total_count FROM '.$CFG['db']['tbl']['tags'];
		if ($type == 'SEARCH')
			$sql .= ' WHERE search_count>0 AND total_count>0 ORDER BY search_count DESC';
		else
			$sql .= ' WHERE total_count>0 ORDER BY total_count DESC';

		$sql .= ' LIMIT 0,'.$limit;

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

		$tagArray = array();
		if ($rs->PO_RecordCount())
			{
		        while($row = $rs->FetchRow())
		            {
		            	$tagArray[] = $row;
					}
			}
		return $tagArray;
	}

/**
 *
 * @return 		void
 * @access 		public
 */
function showTopDebateTags()
	{
		global $smartyObj, $db, $CFG;

		if ($CFG['admin']['index']['top_tags'])
			{
				$showTopDebateTags_arr = array();
				$showTopDebateTags_arr['displayTopTags_arr'] = displayTopDebateTags($CFG['admin']['index']['top_tags_count']);
				$smartyObj->assign('displayTopDebateTags_arr',$showTopDebateTags_arr );
				setTemplateFolder('general/', $CFG['admin']['index']['debate_module']);
				$smartyObj->display('showTopDebateTags.tpl');
			}
	}

/**
 *
 *
 */
function displayTopDebateTags($limit = 5)
	{
		global $smartyObj, $db, $CFG;

		$displayTopDebateTags_arr = array();
		$top_tags = getDebateTags('TOP', $limit);
		$displayTopDebateTags_arr['top_tags'] = $top_tags;
		if ($top_tags)
		{
			$classes = array('clsTagStyleBlue', 'clsTagStyleGrey', 'clsTagStyleGreen', 'clsTagStyleRed');
			$tagClassArray = array();
			foreach($top_tags as $row)
			{
				$tagArray[$row['tag_name']] = $row['total_debate_count'];
				$class = $classes[rand(0, count($classes))%count($classes)];
				$tagClassArray[$row['tag_name']] = $class;
			}

			$tagArray = setFontSizeInsteadOfSearchCount($tagArray);
			$inc = 0;
			foreach($tagArray as $tag=>$fontSize){
				$displayTopDebateTags_arr['tag_Array'][$inc]['debates_tag_url'] = getDebatesUrl('debates', '?view=search&tags='.$tag, 'search/?tags='.$tag);
				$displayTopDebateTags_arr['tag_Array'][$inc]['class'] = $tagClassArray[$tag];
				$displayTopDebateTags_arr['tag_Array'][$inc]['fontSizeClass'] = 'style="font-size:'.$fontSize.'px"';
				$displayTopDebateTags_arr['tag_Array'][$inc]['tag'] = $tag;
				$inc++;
			}
			$displayTopDebateTags_arr['tags']['url'] = getDebatesUrl('debateTags', '?t=freq&s=f', '?t=freq&s=f');
		}
		return $displayTopDebateTags_arr;
	}

/**
 * To display debate tags
 *
 * @return 		void
 * @access 		public
 */
function getDebateTags($type, $limit)
	{
		global $smartyObj, $db, $CFG;

		$sql = 'SELECT tag_name, search_debate_count, total_debate_count FROM '.$CFG['db']['tbl']['tags'];
		if ($type == 'SEARCH')
			$sql .= ' WHERE search_debate_count>0 AND total_debate_count>0 ORDER BY search_debate_count DESC';
		else
			$sql .= ' WHERE total_debate_count>0 ORDER BY total_debate_count DESC';

		$sql .= ' LIMIT 0,'.$limit;

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

		$tagArray = array();
		if ($rs->PO_RecordCount())
			{
		        while($row = $rs->FetchRow())
		            {
		            	$tagArray[] = $row;
					}
			}
		return $tagArray;
	}

/**
 *
 * @return 		void
 * @access 		public
 */
function showTopSearchedDebateTags()
	{
	    global $smartyObj, $db, $CFG;

		if ($CFG['admin']['index']['top_search_tags'])
		{
			$showTopSearchedTags_arr = array();
			$showTopSearchedDebateTags = displayTopSearchedDebateTags($CFG['admin']['index']['top_search_tags_count']);
			$smartyObj->assign('showTopSearchedDebateTags', $showTopSearchedDebateTags);
			setTemplateFolder('general/', $CFG['admin']['index']['debate_module']);
			$smartyObj->display('displayTopSearchedDebateTags.tpl');
		}
	}

function displayTopSearchedDebateTags($limit = 5)
	{
		global $smartyObj, $db, $CFG;

		$displayTopSearchedDebateTags_arr = array();
		$top_tags = getDebateTags('SEARCH', $limit);
		$displayTopSearchedDebateTags_arr['top_tags'] = $top_tags;
		if ($top_tags)
			{
				$classes = array('clsTagStyleBlue', 'clsTagStyleGrey', 'clsTagStyleGreen', 'clsTagStyleRed');
				$tagClassArray = array();
				foreach($top_tags as $row){
					$tagArray[$row['tag_name']] = $row['search_debate_count'];
					$class = $classes[rand(0, count($classes))%count($classes)];
					$tagClassArray[$row['tag_name']] = $class;
				}
				$tagArray = setFontSizeInsteadOfSearchCount($tagArray);
				$inc = 1;
				foreach($tagArray as $tag=>$fontSize)
					{
						$displayTopSearchedDebateTags_arr['tag_Array'][$inc]['debates_tag_url'] = getDebatesUrl('debates', '?view=search&tags='.$tag.'/&s=f', 'search/?tags='.$tag.'/&s=f');
						$displayTopSearchedDebateTags_arr['tag_Array'][$inc]['class'] = $tagClassArray[$tag];
						$displayTopSearchedDebateTags_arr['tag_Array'][$inc]['fontSizeClass'] = 'style="font-size:'.$fontSize.'px"';
						$displayTopSearchedDebateTags_arr['tag_Array'][$inc]['tag'] = $tag;
						$inc++;
					}//foreach
				$displayTopSearchedDebateTags_arr['tags']['url'] = getDebatesUrl('debateTags', '?t=search&s=f', '?t=search&s=f');
			}
		return $displayTopSearchedDebateTags_arr;
	}

/**
 *
 * @access public
 * @return void
 **/
function showFeaturedDebates($users_table,$debate_table, $limit, $lang, $anovaObj)
    {
		global $smartyObj, $db, $CFG;

		$allowed_pages_array = array('debates.php', 'debatesResponse.php', 'debateCategories.php','debateTags.php');
		if(!displayBlock($allowed_pages_array))
			return;

		 $sql = 'SELECT debate_id, d.seo_title, d.description, d.best_response_id, d.total_againsts,d.date_featured,
				d.total_fors, (d.total_againsts+d.total_fors) AS totalResponse,
				d.featured, d.total_videos, d.total_audios, d.pcat_id, d.cat_id, d.status, d.user_id,'.
				getUserTableField('display_name').' as asked_by, u.'.getUserTableField('user_id').' as img_user_id,'.
				getUserTableFields(array('name', 'image_path', 'gender', 't_height', 't_width', 's_height', 's_width', 'photo_server_url', 'photo_ext'), false).
				'subject, total_stars, TIMEDIFF(NOW(), date_asked) as date_asked, TIMEDIFF(date_closed, NOW()) as date_closed,
				IF(status=\'Open\' AND date_closed>=NOW(), 1, 0) is_open, video_id, audio_id
				FROM '.$debate_table.' AS d, '.$users_table.' AS u
				WHERE d.user_id = u.user_id AND u.usr_status = \'Ok\'
				AND d.featured <> \'0\'
				AND NOT EXISTS ( SELECT 1 FROM user_ignored AS ui WHERE ui.user_id ='.$CFG['user']['user_id'].'
				AND ui.ignored_id = d.user_id ) AND d.status NOT IN ( \'Blocked\', \'ToActivate\' ) ORDER BY date_featured DESC';
		if ($limit)
			$sql .= ' LIMIT 0,'.($limit + 1);
		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt);
		if (!$rs)
			 trigger_db_error($db);
        $showFeaturedDebatesArray = array();
		if ($count = $rs->PO_RecordCount())
			{
				$i=1;
				while($row = $rs->FetchRow())
					{
						$showFeaturedDebatesArray[$i]['debatesResponse_class'] = 'clsActive';
						$showFeaturedDebatesArray[$i]['debatesResponse_url'] = getDebatesUrl('debatesresponse', '?title='.$row['seo_title'], $row['seo_title'].'/');
						$showFeaturedDebatesArray[$i]['debatesResponse_name'] = stripString($row['subject']);
						if ($i++ >= $limit)
                  		break;
					}
			}
		if ($count = $rs->PO_RecordCount())
			{
				$showFeaturedDebatesMoreLink = getDebatesUrl('debates','?view=featured&sort=date&order=d&al=All&','featured/?sort=date&order=d&al=All&');
				$smartyObj->assign('showFeaturedDebatesMoreLink', $showFeaturedDebatesMoreLink);
			}
		$smartyObj->assign('showFeaturedDebatesArray', $showFeaturedDebatesArray);
		setTemplateFolder('general/', $CFG['admin']['index']['debate_module']);
		$smartyObj->display('showFeaturedDebates.tpl');
    }


/**
 * rightBarSettings()
 *
 * @param mixed $pagingarr
 * @return
 */
function rightBarSettings()
  	{

		global $smartyObj, $db, $CFG, $LANG_LIST_ARR, $LANG;

		$pagingarr = $LANG_LIST_ARR['paging_list'];

  		if($CFG['admin']['index']['right_bar_anova'])
  			getAnovaModuleRightMenu();

		if(chkIsAllowedModule(array('debate')))
			$allowed_pages_array = array('debates.php', 'debatesResponse.php', 'debateCategories.php','debateTags.php');
		else
			$allowed_pages_array =array();

		if(displayBlock($allowed_pages_array))
			$sql = ' SELECT * from '.$CFG['db']['tbl']['rightbar_settings'].' WHERE type=\'Debate\' OR type=\'Common\' ORDER BY debate_order_value ASC';
		else
			$sql = ' SELECT * from '.$CFG['db']['tbl']['rightbar_settings'].' WHERE type=\'Answer\' OR type=\'Common\' ORDER BY order_value ASC';

		$stmt = $db->Prepare($sql);
		$rs = $db->Execute($stmt);
		if (!$rs)
		        trigger_db_error($db);
		if ($rs->PO_RecordCount())
			{
				$anovaObj = new FormHandler();
				$anovaObj->setFormField('al', '');
				$anovaObj->setFormField('parent_id', '');
				$anovaObj->setFormField('cat_id', '');
				$anovaObj->setFormField('cid', '');
				$anovaObj->sanitizeFormInputs($_REQUEST);
				while($row = $rs->FetchRow()) {

					if($row['title'] == 'unanswered_question' AND $CFG['admin']['rightbar']['unanswered_question'])
						{
							getUnansweredQuestion($CFG['db']['tbl']['questions'], $CFG['admin']['index']['question_limit']);
						}
					elseif($row['title'] == 'question_library' AND $CFG['admin']['rightbar']['library'])
					 	{
							 populateAlphabetPagingList($pagingarr, $anovaObj);
						}
					elseif($row['title'] == 'categories' AND $CFG['admin']['rightbar']['categories'])
					 	{
							getAllCategories($CFG['db']['tbl']['questions_category'], $CFG['admin']['index']['category_limit'], 'total_questions', $anovaObj);
						}
					elseif($row['title'] == 'top_tags' AND $CFG['admin']['rightbar']['top_tags'])
					 	{
							showTopTags();
						}
					elseif($row['title'] == 'debates_categories')
					 	{
							if($CFG['admin']['rightbar']['debates_categories'] )
								getAllCategories($CFG['db']['tbl']['questions_category'], $CFG['admin']['index']['category_limit'], 'total_debates', $anovaObj);
						}
					elseif($row['title'] == 'top_tags')
					 	{
							if($CFG['admin']['rightbar']['top_tags'])
	 						showTopTags();
						}
					elseif($row['title'] == 'top_searched_tags')
					 	{
							 if($CFG['admin']['rightbar']['top_searched_tags'])
								showTopSearchedTags();
						}
					elseif($row['title'] == 'featured_debates')
					 	{
							if($CFG['admin']['rightbar']['featured_debates'])
	 							showFeaturedDebates($CFG['db']['tbl']['users'],$CFG['db']['tbl']['debates'],$CFG['admin']['index']['featured_debates_limit'], $LANG['featured_debates'], $anovaObj);
						}
					elseif($row['title'] == 'debates_top_tags')
					 	{
							if($CFG['admin']['rightbar']['debates_top_tags'])
	 							showTopDebateTags();
						}

					elseif($row['title'] == 'debates_top_searched_tags')
					 	{
							 if($CFG['admin']['rightbar']['debates_top_searched_tags'])
								showTopSearchedDebateTags();
						}
				}
			}
	}
function chkExternalVideoAllowed($type)
	{
		if (!proceeedSite()) return false;
		global $CFG;
		if(!isset($CFG['admin']['module']['external_video_audio']) or !$CFG['admin']['module']['external_video_audio'])
			return false;
		if(!isset($CFG['admin'][$type]['external_video']) or !$CFG['admin'][$type]['external_video'])
			return false;
		return true;
	}

function chkExternalAudioAllowed($type)
	{
		if (!proceeedSite()) return false;
		global $CFG;
		if(!isset($CFG['admin']['module']['external_video_audio']) or !$CFG['admin']['module']['external_video_audio'])
			return false;
		if(!isset($CFG['admin'][$type]['external_audio']) or !$CFG['admin'][$type]['external_audio'])
			return false;
		return true;
	}
// For Blogs and Forums
function chkExternalVideoModuleAllowed($type)
	{
		if (!proceeedSite()) return false;
		global $CFG;
		if(!isset($CFG['admin']['module']['video_audio_blogsforum']) or !$CFG['admin']['module']['video_audio_blogsforum'])
			return false;
		if(!isset($CFG['admin'][$type]['external_video']) or !$CFG['admin'][$type]['external_video'])
			return false;
		return true;
	}
function chkExternalAudioModuleAllowed($type)
	{
		if (!proceeedSite()) return false;
		global $CFG;
		if(!isset($CFG['admin']['module']['video_audio_blogsforum']) or !$CFG['admin']['module']['video_audio_blogsforum'])
			return false;
		if(!isset($CFG['admin'][$type]['external_audio']) or !$CFG['admin'][$type]['external_audio'])
			return false;
		return true;
	}
function chkVideoModuleAllowed($type)
	{
		if (!proceeedSite()) return false;
		global $CFG;
		if(!isset($CFG['admin']['module']['video_audio_blogsforum']) or !$CFG['admin']['module']['video_audio_blogsforum'])
			return false;
		if(!isset($CFG['admin'][$type]['video']) or !$CFG['admin'][$type]['video'])
			return false;
		return true;
	}
function chkAudioModuleAllowed($type)
	{
		if (!proceeedSite()) return false;
		global $CFG;
		if(!isset($CFG['admin']['module']['video_audio_blogsforum']) or !$CFG['admin']['module']['video_audio_blogsforum'])
			return false;
		if(!isset($CFG['admin'][$type]['audio']) or !$CFG['admin'][$type]['audio'])
			return false;
		return true;
	}

/**
 * HeaderFormHandler::displayStaticPageLinks()
 *
 * @return
 */
function displayStaticPageLinks()
	{
		global $smartyObj, $db, $CFG;

		$displayStaticPageLinks_val = '';

		$sql = 'SELECT page_title, seo_title FROM '.$CFG['db']['tbl']['static_pages'].
				' WHERE page_status=\'Yes\' AND link_in_footer=\'Yes\'';

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

		if (!$rs->PO_RecordCount())
			return ;

		while($row = $rs->FetchRow()) {
			$sPage = $row['page_title'];
			$seoPage = $row['seo_title'];

			$displayStaticPageLinks_val .= '<li><a href="'.getAnovaUrl('static', '?pg='.$seoPage, $seoPage.'/').'"><span>'.$sPage.'</span></a></li>';
		}

		return $displayStaticPageLinks_val;
	}
function getMemberUrl($uid, $uname, $page='')
	{
		return getAnovaUrl('myanswers', '?uid='.$uname, $uname.'/', 'root');
		// FOR RAYZZ INTEGRATION
		//return getUrl('viewprofile', '?user='.$uname, $uname.'/', $page);
	}
function populateAnovaJSVariables()
{
	global $CFG, $LANG;
	$popupPosition = 330;
	?>
<script language="javascript" type="text/javascript">
	var SITE_URL = '<?php echo $CFG['site']['url'];?>';
	var ANOVA_MODULE_NAME = '<?php echo $CFG['admin']['index']['anova_module'];?>';
	var SITE_TEMPLATE = '<?php echo $CFG['html']['template']['default'];?>'
	var SITE_SCREEN = '<?php echo $CFG['html']['stylesheet']['screen']['default'];?>'
	var SITE_SUGGEST_URL = '<?php echo getAnovaUrl('questions', '?view=open&amp;al=all&related_question=', 'search/?related_question=');?>';
	var LOGIN_URL = '<?php echo getUrl('login', '', '', 'root');?>';
	var processingSrc = '<img src="<?php echo $CFG['site']['url'].'design/templates/'.$CFG['html']['template']['default'].'/images/processing.gif';?>" alt="<?php echo $LANG['header_loading'];?>"/>';
	var loadingInfoSrc = '<img src="<?php echo $CFG['site']['url'].'design/templates/'.$CFG['html']['template']['default'].'/images/loading.gif';?>" alt="<?php echo $LANG['header_loading'];?>"/>';
	var popupPosition = '<?php echo $popupPosition;?>';
	var LANG_CLOSE = '<?php echo $LANG['header_close'];?>';
	var LANG_LOADING = '<?php echo $LANG['header_loading'];?>';
	var LANG_OR = '<?php echo $LANG['header_or'];?>';
	var LANG_CANCEL = '<?php echo $LANG['common_cancel'];?>';
	var LANG_limit = '<?php echo $LANG['header_limit'];?>';
	var LANG_limit_exceeds = '<?php echo $LANG['header_limit_exceeds'];?>';
	var LANG_valid_reason_for_abusing = '<?php echo $LANG['header_valid_reason_for_abusing'];?>';
	var LANG_valid_response_for_debate = '<?php echo $LANG['valid_response_for_debate'];?>';
	var LANG_compulsory = '<?php echo $LANG['err_tip_compulsory'];?>';
	var LANG_invalid_email = '<?php echo $LANG['header_err_tip_invalid_email'];?>';
	var LANG_invalid = '<?php echo $LANG['header_err_tip_invalid_number'];?>';
	var LANG_sending_email = '<?php echo $LANG['header_sending_email_msg'];?>';
	var LANG_updating_msg = '<?php echo $LANG['header_updating_msg'];?>';
	var LANG_remaining_again = '<?php echo $LANG['header_remainig_again'];?>';
	var LANG_exceed_limit = '<?php echo $LANG['header_exceed_limit'];?>';
	var LANG_remaining = '<?php echo $LANG['header_remainig'];?>';
	var LANG_not_match = '<?php echo $LANG['common_err_tip_same_password'];?>';
	var LANG_mustbe = '<?php echo $LANG['live_validate_mustbe'];?>';
	var LANG_mustbe_integer = '<?php echo $LANG['live_validate_mustbe_integer'];?>';
    var LANG_mustnotbe_less = '<?php echo $LANG['live_validate_mustnotbe_less'];?>';
	var LANG_mustnotbe_more = '<?php echo $LANG['live_validate_mustnotbe_more'];?>';
	var LANG_chars = '<?php echo $LANG['live_validate_characters'];?>';
	var ques_max_len = '<?php echo $CFG['admin']['question']['limit'];?>';
	var ques_des_max_len = '<?php echo $CFG['admin']['description']['limit'];?>';
	var ans_des_max_length = '<?php echo $CFG['admin']['answers']['limit'];?>';
	<?php if(chkIsPaymentAllowed('payment_answers') && isMember()){?>
	ans_des_max_length = '<?php echo $CFG['plan']['plan_ans_characters'];?>';
	<?php }
	if(chkAllowedModule(array('payment'))){?>
	var payment_option = '<?php echo $CFG['admin']['payment_method'];?>';
	<?php
	}?>
	var bio_count ='<?php echo $CFG['admin']['bio_count'];?>';
	var file_upload_limit = '<?php echo $CFG['admin']['attachments_allowed']['count'];?>';
	var file_upload_limit_exceeds = '<?php echo $LANG['file_size_exceeds'];?>';
	var LANG_already_voted = '<?php echo $LANG['already_voted'];?>';
	var cfg_site_url = '<?php echo $CFG['site']['url'];?>';
	var logoutUrl = '<?php echo $CFG['site']['url'].getUrl('logout', '', '', 'root');?>';
	var LANG_update_text = '<?php echo $LANG['common_updating'];?>';
	var admin_index_anova_module = '<?php echo $CFG['admin']['index']['anova_module'];?>';
</script>
<?php if(chkIsAllowedModule(array('video')) or chkIsAllowedModule(array('audio')) or chkIsAllowedModule(array('external_video_audio')) or $CFG['admin']['module']['video_audio_blogsforum']) { ?>
<script language="javascript" type="text/javascript" src="<?php echo $CFG['site']['url'].$CFG['admin']['index']['anova_module'];?>/js/swfobject.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $CFG['site']['url'].$CFG['admin']['index']['anova_module'];?>/js/JSFCommunicator.js"></script>
<?php } ?>
<script language="javascript" type="text/javascript" src="<?php echo $CFG['site']['url'].$CFG['admin']['index']['anova_module'];?>/js/browsersniff.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $CFG['site']['url'].$CFG['admin']['index']['anova_module'];?>/js/swfupload/swfupload.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $CFG['site']['url'].$CFG['admin']['index']['anova_module'];?>/js/swfupload/handlers.js"></script>
<script language="javascript" type="text/javascript">
<?php
	if($CFG['site']['jserror_block'])
		{
?>
	function blockError(){return true;}
	window.onerror = blockError;
<?php
		}
?>
</script>
	<?php
}
/**
 * addThisOption()
 *
 * @return
 */
function addThisOption()
	{
		global $smartyObj;
		setTemplateFolder('general/');
		$smartyObj->display('addThisOption.tpl');
	}

/**
 * getUserProfileBadgeUrl()
 *
 * @param string $username
 * @param mixed $append_script
 * @return
 */
function getUserProfileBadgeUrl($username = '', $append_script = true)
	{
		global $CFG;
		$badgeUrl = getAnovaUrl('embedcontent', '?embed=user&amp;user='.$username, 'user/'.$username.'/', 'root');
		if ($append_script)
			{
				$badgeUrl = '<script src="'.$badgeUrl.'"></script>';
			}
		return $badgeUrl;
	}
/**
 * getImageName()
 *
 * @param mixed $text
 * @return
 */
function getImageName($text)
	{
		$text = md5($text);
		return substr($text, 0, 15);
	}
function chkIsPaymentAlertMessageAllowed($type='payment_alert')
	{
		if(!chkIsPaymentAllowed())
			return false;

		global $CFG;
		if(!isset($CFG['admin'][$type]['needed']) or !$CFG['admin'][$type]['needed'])
			return false;
		return true;
	}
/**
 * used to get the image with and height
 *
 * @access	public
 * @param	integer required width
 * @param	integer required height
 * @param	integer	image original width
 * @param	integer	image original height
 * @return	string
 */
function GET_IMAGE_ATTRIBUTES($cfg_width = 0, $cfg_height = 0, $img_width = 0, $img_height = 0)
	{
		if ($cfg_width > 0 AND $cfg_height > 0 AND ($cfg_width < $img_width) AND ($cfg_height < $img_height))
			$attr = ($img_width > $img_height)? " width=\"".$cfg_width."\"" : " height=\"".$cfg_height."\"";
			else if ($cfg_width > 0 AND $cfg_width < $img_width)
				$attr = " width=\"".$cfg_width."\"";
				else if ($cfg_height > 0 AND $cfg_height < $img_height)
					$attr = " height=\"".$cfg_height."\"";
					else
						$attr = "";
		return $attr;
	}
/**
 * php2js()
 *
 * @param mixed $dta
 * @return
 */
function php2js($dta)
  	{
		if(is_object($dta))
		  	$dta = get_object_vars($dta);
		if(is_array($dta)) {
		  foreach($dta AS $k=>$d)
		    	$dta[$k] = php2js($k).":".php2js($d);
		  return '{'.implode(',',$dta).'}';
		}
		elseif(is_numeric($dta))
		  	return "$dta";
		elseif(is_string($dta))
		  	return '"'.str_replace('"','\\"',$dta).'"';
		else
		  	return 'null';
  	}

function seoFriendlyAnovaText($text,$from_enc)
	{
		$charsToRemove = array('~', '`', '@', '#', '$', '%', '^', '&amp;', '*', '(', ')', '_', '+', '=', '{', '[', '}', ']', ':', '&quot;', '\'', '|', '\\',
									'&lt;', ',', '&gt;', '.', '?', '/', '!', ';', ' ');
		$text = str_replace($charsToRemove, '-', $text);
	    return $text;
	}

/**
 * checkIsDemoSiteForLicense()
 *
 * @return
 */
function checkIsDemoSiteForLicense()
	{
				return true; //g_m or false ?
	}

/**
 * isDemoSite()
 *
 * @return
 */
function isDemoSite()
	{
		global $CFG;
		if(isset($CFG['admin']['is_demo_site']) and $CFG['admin']['is_demo_site']==true)
			{
				return true;
			}
		return false;
	}

/**
 * isDemoSiteAndDemoUserId()
 *
 * @param mixed $user_id
 * @return
 */
function isDemoSiteAndDemoUserId($user_id)
	{
		global $CFG;
		if(isset($CFG['admin']['is_demo_site']) and $CFG['admin']['is_demo_site']==true)
			{
				if(in_array($user_id, $CFG['admin']['demo_user_ids']))
					{
						return true;
					}
			}
		return false;
	}

/**
 * chkBrowser()
 *
 * @return
 */
function chkBrowser()
	{
		if(strchr(strtolower($_SERVER['HTTP_USER_AGENT']),"opera") == '' and strchr(strtolower($_SERVER['HTTP_USER_AGENT']),"safari") == '')
			return true;
	}
function populateAdminAnovaLeftNavigation()
	{
	   	 global $smartyObj;
	     setTemplateFolder('admin/','anova');
	     //$smartyObj->assign('admin_main_menu_arrays', additionalanovaAdminMenuLink());
		 $smartyObj->display('left_anova_navigation_links.tpl');
		 ?>
		<script language="javascript" type="text/javascript">
			var inc = divArray.length;
			var temp_anova_menu_array = new Array('anovaSetting', 'anovaAnswers', 'anovaVideoPlayer');
			for(jnc=0;jnc<temp_anova_menu_array.length;jnc++)
				divArray[inc++] = temp_anova_menu_array[jnc];


		</script>
	   	 <?
	}

function populateAdminForumsLeftNavigation()
	{
	   	 global $smartyObj;
	     setTemplateFolder('admin/','forums');
	     //$smartyObj->assign('admin_main_menu_arrays', additionalanovaAdminMenuLink());
		 $smartyObj->display('left_forums_navigation_links.tpl');
		 ?>
		<script language="javascript" type="text/javascript">
			var inc = divArray.length;
			var temp_forums_menu_array = new Array('forumsSetting', 'forumsForums');
			for(jnc=0;jnc<temp_forums_menu_array.length;jnc++)
				divArray[inc++] = temp_forums_menu_array[jnc];
		</script>
	   	 <?
	}

function populateAdminBlogLeftNavigation()
	{
	   	 global $smartyObj;
	     setTemplateFolder('admin/','blog');
	     //$smartyObj->assign('admin_main_menu_arrays', additionalanovaAdminMenuLink());
		 $smartyObj->display('left_blog_navigation_links.tpl');
		 ?>
		<script language="javascript" type="text/javascript">
			var inc = divArray.length;
			var temp_blog_menu_array = new Array('blogSetting', 'blogBlog');
			for(jnc=0;jnc<temp_blog_menu_array.length;jnc++)
				divArray[inc++] = temp_blog_menu_array[jnc];

		</script>
	   	 <?
	}

function populateAdminDebateLeftNavigation()
	{
	   	 global $smartyObj;
	     setTemplateFolder('admin/','debate');
	     //$smartyObj->assign('admin_main_menu_arrays', additionalanovaAdminMenuLink());
		 $smartyObj->display('left_debate_navigation_links.tpl');
		 ?>
		<script language="javascript" type="text/javascript">
			var inc = divArray.length;
			var temp_debate_menu_array = new Array('debateSetting', 'debateDebate');
			for(jnc=0;jnc<temp_debate_menu_array.length;jnc++)
				divArray[inc++] = temp_debate_menu_array[jnc];
		</script>
	   	 <?
	}
function getAnova2Url($file_name, $normal = '', $htaccess = '', $change = '', $module='')
	{
		global $CFG, $folder_names_arr;
		if ($module == $CFG['admin']['index']['anova_module'] AND $CFG['feature']['rewrite_mode'] != 'normal')
			{
				$module = '';
			}
		$relativeUrl = '';
		if(!$change)
			{
				$change='current';
			}
		if (!proceeedSite()) return $CFG['site']['url'].'install.php';

		$normal = $CFG['page_url'][$file_name]['normal'].$normal;
		$htaccess = $CFG['page_url'][$file_name]['htaccess'].$htaccess;

		if($CFG['feature']['rewrite_mode']=='clean')
			{
				$normal = getCleanUrl($normal);
			}
		if($CFG['feature']['rewrite_mode']=='htaccess')
			{
				if(strrpos($htaccess, '/')==strlen($htaccess)-1 and ($htaccess!=$CFG['site']['url']) and ($htaccess!=$CFG['site']['url'].'/members/') and ($htaccess!=$CFG['site']['url'].'/admin/'))
					{
						$htaccess = substr($htaccess, 0, strrpos($htaccess, '/')).$CFG['feature']['rewrite_mode_endwith'];
					}
				$htaccess = str_replace('/?', '.html?', $htaccess);
				$htaccess = str_replace('/&', '.html&', $htaccess);
			}

		if($module)
			{
				if($CFG['site']['relative_url']==$CFG['site']['url'])
					{
						$relativeUrl=$CFG['site']['url'].$module.'/';

			        }
				foreach($folder_names_arr as $folder)
					{
						if($CFG['site']['relative_url']==$CFG['site']['url'].$folder)
							{
								$relativeUrl=$CFG['site']['url'].$module.'/'.$folder;
								break;
							}
					}
				foreach($CFG['site']['modules_arr'] as $mod)
					{

						if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/')
							{
								$relativeUrl=$CFG['site']['url'].$module.'/';
								break;
							}
						if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/members/')
							{
								$relativeUrl=$CFG['site']['url'].$module.'/members/';
								break;
							}
						if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/rss/')
							{
								$relativeUrl=$CFG['site']['url'].$module.'/rss/';
								break;
							}
						if($CFG['site']['relative_url']==$CFG['site']['url'].'admin/'.$mod.'/')
							{
								$relativeUrl=$CFG['site']['url'].'admin/'.$module.'/';
								break;
							}

					}

				$siteUrl=$CFG['site']['url'].$module.'/';

			}
		else
			{
				foreach($CFG['site']['modules_arr'] as $mod)
					{
						if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/')
							{
								$CFG['site']['relative_url']=$CFG['site']['url'];
							}
						if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/members/')
							{
								$relativeUrl=$CFG['site']['url'].'members/';
								break;
							}
						if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/rss/')
							{
								$relativeUrl=$CFG['site']['url'].'rss/';
								break;
							}
						if($CFG['site']['relative_url']==$CFG['site']['url'].$mod.'/admin/')
							{
								$relativeUrl=$CFG['site']['url'].'admin/';
								break;
							}
					}

				$siteUrl=$CFG['site']['url'];
			}

		if(!$relativeUrl)
			{
				$relativeUrl=$CFG['site']['relative_url'];
				$siteUrl=$CFG['site']['url'];
			}
		switch($change)
			{
				case 'current':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $relativeUrl.$htaccess;
						else
							return $relativeUrl.$normal;
					break;
				case 'root':
				case 'members':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $siteUrl.$htaccess;
						else
							return $siteUrl.$normal;
					break;
				case 'admin':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $siteUrl.'admin/'.$htaccess;
						else
							return $siteUrl.'admin/'.$normal;
					break;
				case 'nothing':
						if($CFG['feature']['rewrite_mode']=='htaccess')
							return $htaccess;
						else
							return $normal;
					break;
			}
	}
function replaceListClass($fckInput)
	{
		$fckInput = str_ireplace('<ul>','<ul class="clsFckunOrderedLi">',$fckInput);
		$fckInput = str_ireplace('<ol>','<ol class="clsFckOrderedLi">',$fckInput);
		return $fckInput;
	}
?>