<?php
/**
 * File handling the My Subscribed Uesr
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		###My subscribed tag###
 * @author 		karthiselvam_75ag08
 * @copyright	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: $
 * @since 		2008-12-19
 */
class subscribedTag extends FormHandler
	{
		public $user_details = array();

		/**
		 * subscribedTag::populateTagList()
		 *
		 * @return
		 */
		public function populateTagList()
			{
				$sql = 'SELECT subscribe_keywords 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($this->fields_arr['uid']));
				    if (!$rs)
					    trigger_db_error($this->dbObj);

				$row = $rs->FetchRow();
				$subscribed_tags = array();
				$populateTagList_Arr=array();
				if (trim($row['subscribe_keywords']))
					{
						$subscribed_tags = explode(' ', trim($row['subscribe_keywords']));
						$classes = array('clsTagStyleBlue', 'clsTagStyleGrey', 'clsTagStyleGreen', 'clsTagStyleRed');
						$tagClassArray = array();
						$tagArray = array();
						foreach($subscribed_tags as $eachTag)
							{
								$tagArray[$eachTag] = $this->getTagQuestionsCount($eachTag);
								$class = $classes[rand(0, count($classes))%count($classes)];
								$tagClassArray[$eachTag] = $class;
							} // while
						$tagArray = $this->setFontSizeInsteadOfSearchCount($tagArray);
						$inc=1;
						foreach($tagArray as $tag=>$fontSize)
							{
								$class 	= $tagClassArray[$tag];
								$fontSizeClass= 'style="font-size:'.$fontSize.'px"';
								$populateTagList_Arr[$inc]['questions_url']=getAnovaUrl('questions','?view=search&tags='.$tag, 'search/?tags='.$tag);
								$populateTagList_Arr[$inc]['tag']=$tag;
								$populateTagList_Arr[$inc]['cssclassname']=$class;
								$populateTagList_Arr[$inc]['fontSizeClass']=$fontSizeClass;
								$inc++;
							}
					}
					return $populateTagList_Arr;
			}

		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function getTagQuestionsCount($tag_name)
			{
				$sql = 'SELECT total_count FROM '.$this->CFG['db']['tbl']['tags'].
						' WHERE tag_name='.$this->dbObj->Param($tag_name);

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

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

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

		/**
		 * subscribedTag::populateUserDetails()
		 *
		 * @return
		 */
		public function populateUserDetails()
			{
				$sql = 'SELECT '.$this->getUserTableFields(array('name', 'user_id', 'display_name')).
						' FROM '.$this->CFG['db']['tbl']['users'].
						' WHERE '.$this->getUserTableField('name').' = '.$this->dbObj->Param('name').
						' AND '.$this->getUserTableField('usr_status').'=\'OK\'';

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

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

				if($row = $rs->FetchRow())
					{
						$this->user_details = $row;
						$this->setFormField('uid', $row['user_id']);
						return true;
					}
				return false;
			}
	}

//--------------------Code begins-------------->>>>>//
$subscribedTag = new subscribedTag();
//set blocks
$subscribedTag->setPageBlockNames(array('tag_list_block'));
//show default pages
$subscribedTag->setFormField('uid', '');
$subscribedTag->sanitizeFormInputs($_REQUEST);
if(!$subscribedTag->getFormField('uid'))
	$subscribedTag->setFormField('uid', $CFG['user']['user_id']);
if($subscribedTag->populateUserDetails())
	{
		$subscribedTag->setPageBlockShow('tag_list_block');
		$LANG['mysubscribedtag_back_to_user_profile_user'] = str_ireplace('VAR_USERNAME', $subscribedTag->user_details['display_name'], $LANG['mysubscribedtag_back_to_user_profile_user']);
		$LANG['mysubscribedtag_back_to_user_profile'] = ($CFG['user']['user_id']==$subscribedTag->getFormField('uid'))?$LANG['mysubscribedtag_back_to_user_profile']:$LANG['mysubscribedtag_back_to_user_profile_user'];
		$LANG['mysubscribedtag_title_user_name'] = str_ireplace('VAR_USERNAME', $subscribedTag->user_details['display_name'], $LANG['mysubscribedtag_title_user_name']);
		$LANG['mysubscribedtag_title'] = ($subscribedTag->getFormField('uid')==$CFG['user']['user_id'])?$LANG['mysubscribedtag_title']:$LANG['mysubscribedtag_title_user_name'];
		$back_link = getMemberUrl($subscribedTag->user_details['user_id'], $subscribedTag->user_details['name']);
		$profile_name = $LANG['back_to_profile'];
		$subscribedTag->populateUserDetailsArr['back_link']=$back_link;
		$subscribedTag->populateUserDetailsArr['profile_name']=$profile_name;
		$subscribedTag->populateUserDetailsArr['profile_tooltip']=$LANG['mysubscribedtag_back_to_user_profile'];
	}
else
	{
		$subscribedTag->setPageBlockShow('block_msg_form_error');
		$subscribedTag->setCommonErrorMsg($LANG['err_tip_invalid_user']);
	}
//<<<<--------------------Code Ends----------------------//
//--------------------Page block templates begins-------------------->>>>>//
if ($subscribedTag->isShowPageBlock('tag_list_block'))
	{
		$display_username =	$LANG['common_subscribed'];
		$uid = $subscribedTag->getFormField('uid');
		$dname = $subscribedTag->user_details['display_name'];
		$uname = $subscribedTag->user_details['name'];
		if($CFG['user']['user_id'] != $uid)
			{
				$display_username = str_ireplace('VAR_USERNAME', ucwords($dname), $LANG['common_subscribed_others']);
			}
		$subscribedTag->tag_list_block['display_username']	=	$display_username;
		$subscribedTag->tag_list_block['tag_url']	=	getAnovaUrl('mysubscribedtag', '?uid='.$uname, $uname.'/');
		$subscribedTag->tag_list_block['user_url']	=	getAnovaUrl('mysubscribeduser', '?uid='.$uname, $uname.'/');
		$subscribedTag->tag_list_block['forum_url']	=	getForumsUrl('mysubscribedforum', '?uid='.$uname, $uname.'/');
		$subscribedTag->tag_list_block['populateTagList']	=	$subscribedTag->populateTagList();
	}
//include the header file
$subscribedTag->includeHeader();
//include the content of the page
setTemplateFolder('general/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('mySubscribedTag.tpl');
//includ the footer of the page
?>
<script language="javascript" type="text/javascript">
	var block_arr= new Array('selMsgConfirm');
</script>
<?php
//<<<<<<--------------------Page block templates Ends--------------------//
$subscribedTag->includeFooter();
?>