<?php
/**
 * Avatar images displaying page
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		###AvatarHandler###
 * @author 		karthiselvam_75ag80
 * @copyright	copyright (c) 2010 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id: portfolioContent.php 556 2007-09-20 12:26:07Z sridharan_08ag04 $
 * @since 		2008-11-11
 */
require_once('../common/configs/config.inc.php'); //configurations
$CFG['html']['is_use_header'] = false;
$CFG['html']['is_use_footer'] = false;
$CFG['http_headers']['is_cache'] = false;
$CFG['http_headers']['is_use_if_modified_since'] = false;
$CFG['is']['ajax_page'] = true;
$CFG['auth']['is_authenticate'] = 'members';

$CFG['site']['is_module_page'] = $CFG['admin']['index']['anova_module'];
require($CFG['site']['project_path'].'common/application_top.inc.php');

//-------------- Class AvatarHandler begins --------------->>>>>//
class AvatarHandler extends FormHandler
	{
		/**
		 *
		 * @return 		void
		 * @access 		public
		 */
		public function displayAvatars()
			{
				$avatar_img_arr = glob($this->CFG['site']['project_path'].$this->CFG['admin']['avatar_path']."default_*");
				$no_of_avatar_img = count($avatar_img_arr);
				$imgCnt = 0;
				$dispCnt = 0;
				$this->displayAvatars_arr	=	array();
				$this->displayAvatars_arr['start']	=	$start	=	$this->fields_arr['s'];
				$this->displayAvatars_arr['limit']	=	$limit	=	$this->fields_arr['l'];
				$tempMS	=	$this->displayAvatars_arr['start']-1;
				$this->displayAvatars_arr['showAvatars']	=	'showAvatars(\''.$this->CFG['site']['relative_url'].'avatars.php?uid='.$this->fields_arr['uid'].'\',\'s='.$tempMS.'\', \'selShowAvatarImages\'); return false;';
				if ($start==1 AND isMember())
					{
						$img_type_lc = 's';
						$this->displayAvatars_arr['user_details_arr']	=	$user_details_arr = $this->getUserDetailsFromUsersTable($this->CFG['db']['tbl']['users'], $this->fields_arr['uid']);
						if (($user_details_arr['photo_server_url'] AND $user_details_arr['photo_ext']) OR $user_details_arr['image_path'])
							{
								if (isset($user_details_arr['image_path']) AND !empty($user_details_arr['image_path']))
									{
										$img_src = $user_details_arr['image_path'];
										$attr = ' width="'.$this->CFG['admin']['ans_photos']['medium_width'].'"';
									}
								else if (isset($user_details_arr['photo_ext']) AND (!empty($user_details_arr['photo_ext'])))
									{
										$img_src = $user_details_arr['photo_server_url'].$this->CFG['admin']['ans_photos']['folder'].getImageName($user_details_arr['img_user_id']).$this->CFG['admin']['ans_photos']['thumb_name'].'.'.$user_details_arr['photo_ext'];
										$attr = GET_IMAGE_ATTRIBUTES($this->CFG['admin']['ans_photos']['medium_width'], $this->CFG['admin']['ans_photos']['medium_height'], $user_details_arr[$img_type_lc.'_width'], $user_details_arr[$img_type_lc.'_height']);
									}
								elseif(isset($user_details_arr['gender']) AND !empty($user_details_arr['gender']))
									{
										$gender = strtoupper($user_details_arr['gender']);
										$img_src = $this->CFG['site']['url'].'images/no-female-'.'thumb.jpg';
										if ($gender == 'M' || $gender == 'MALE')
											$img_src = $this->CFG['site']['url'].'images/no-male-'.'thumb.jpg';
									}
							$this->displayAvatars_arr['img_src']	=	$img_src;
							$this->displayAvatars_arr['attr']	=	$attr;
								if ($this->displayAvatars_arr['img_src'])
									{
										$no_of_avatar_img++;
										$imgCnt++;
										$dispCnt++;
									}
							}
					}
				$inc=0;
				$this->displayAvatars_arr['row']=array();
				foreach ($avatar_img_arr as $filename)
					{
						$imgCnt++;
						if ($imgCnt < $start)
							continue;
						$dispCnt++;
						$this->displayAvatars_arr['row'][$inc]['img_file']	=	substr($filename, strrpos($filename, 'avatars/') + 8);
						$this->displayAvatars_arr['row'][$inc]['url']	=	$this->CFG['site']['url'].$this->CFG['admin']['avatar_path'].$this->displayAvatars_arr['row'][$inc]['img_file'];
						if ($dispCnt == $limit)
							break;
						$inc++;
					}
				$this->displayAvatars_arr['no_of_avatar_img_mins_limit']	=	$no_of_avatar_img-$limit;
				if ($start <= ($no_of_avatar_img-$limit))
					{
						$tempPS	=	$this->displayAvatars_arr['start']+1;
						$this->displayAvatars_arr['showAvatars1']	=	'showAvatars(\''.$this->CFG['site']['relative_url'].'avatars.php?uid='.$this->fields_arr['uid'].'\', \'s='.$tempPS.'\', \'selShowAvatarImages\'); return false;';
					}
				return $this->displayAvatars_arr;
			}

		/**
		 * AvatarHandler::includeAjaxHeader()
		 *
		 * @param mixed $assign_var
		 * @return
		 */
		public function includeAjaxHeader($assign_var = true)
			{
				global $CFG, $smartyObj;
				if($assign_var)
					{
						$this->assignSmartyVariables();
					}
			}
	}
//----------------------------- Code begins ------------------>>>>>//
$answerRating = new AvatarHandler();

$answerRating->setFormField('uid', $CFG['user']['user_id']);
$answerRating->setFormField('s', 1);
$answerRating->setFormField('l',5);
$answerRating->sanitizeFormInputs($_REQUEST);
$answerRating->avatars['displayAvatars']=$answerRating->displayAvatars();
//<<<<<------------------------- Code ends ----------------------------------//

//--------------------Page block templates begins-------------------->>>>>//
$answerRating->includeAjaxHeader();
setTemplateFolder('members/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('avatars.tpl');
die();
$answerRating->includeAjaxFooter();
//<<<<<<--------------------Page block templates Ends--------------------//
?>