<?php
	/**
	 * UserManager.php
	 *
	 * Description	: A Simple Getter/Setter Bin Class
	 *
	 * Developed By : Suresh Shinde
	 *
	 * Developed On : 07 June, 2010
	 *
	 * Liscence 	: GPL
	 *
	 * Created On 	: 03/06/2011 12:52:57
	 *
	 * Created By 	: Mrunal Malusare
	 *
	 */

	/**
	 * Include BIN (Getters & Setters) Class
	 */
	require_once(dirname(__FILE__)."/User.php");

	/**
	 * Include Exception Class
	 */
	require_once(dirname(__FILE__)."/UserException.php");

	/**
	 * Start of class UserManager
	 */
	class UserManager
	{
		/**
		 * Add User
		 */
		function addUser ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"INSERT INTO tcv_user
					 (
						
						user_type_id,
						username,
						password,
						admin_password,
						admin_password_date,
						fname,
						mname,
						lname,
						email,
						is_old_data,
						status,
						corporate_user_id,
						distributor_user_id,
						create_date,
						created_by,
						creator_type_id,
						update_date,
						updated_by,
						modifier_type_id
					 )
					 VALUES
					 (
						
						'".addslashes($User->getUserTypeId())."',
						'".addslashes($User->getUsername())."',
						'".addslashes($User->getPassword())."',
						'".addslashes($User->getAdminPassword())."',
						'".addslashes($User->getAdminPasswordDate())."',
						'".addslashes($User->getFname())."',
						'".addslashes($User->getMname())."',
						'".addslashes($User->getLname())."',
						'".addslashes($User->getEmail())."',
						'".addslashes($User->getIsOldData())."',
						'".addslashes($User->getStatus())."',
						'".addslashes($User->getCorporateUserId())."',
						'".addslashes($User->getDistributorUserId())."',
						'".addslashes($User->getCreateDate())."',
						'".addslashes($User->getCreatedBy())."',
						'".addslashes($User->getCreatorTypeId())."',
						'".addslashes($User->getUpdateDate())."',
						'".addslashes($User->getUpdatedBy())."',
						'".addslashes($User->getModifierTypeId())."'
					 )
					";
					
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
				return mysql_insert_id();
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Add User
		 */
		function addTestUser ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"INSERT INTO tcv_user
					 (
						
						user_type_id,
						fname,
						mname,
						lname,
						email,
						is_old_data,
						username,
						password,
						admin_password,
						admin_password_date,
						status,
						corporate_user_id,
						distributor_user_id,
						create_date,
						created_by,
						creator_type_id,
						update_date,
						updated_by,
						modifier_type_id
					 )
					 VALUES
					 (
						
						'".addslashes($User->getUserTypeId())."',
						'".addslashes($User->getFname())."',
						'".addslashes($User->getMname())."',
						'".addslashes($User->getLname())."',
						'".addslashes($User->getEmail())."',
						'".addslashes($User->getIsOldData())."',
						'".addslashes($User->getUsername())."',
						'".addslashes($User->getPassword())."',
						'".addslashes($User->getAdminPassword())."',
						'".addslashes($User->getAdminPasswordDate())."',
						'".addslashes($User->getStatus())."',
						'".addslashes($User->getCorporateUserId())."',
						'".addslashes($User->getDistributorUserId())."',
						'".addslashes($User->getCreateDate())."',
						'".addslashes($User->getCreatedBy())."',
						'".addslashes($User->getCreatorTypeId())."',
						'".addslashes($User->getUpdateDate())."',
						'".addslashes($User->getUpdatedBy())."',
						'".addslashes($User->getModifierTypeId())."'
					 )
					";
					//echo $sql;

				if(!$conn->db_query($sql))
				{
					//throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
				return mysql_insert_id();
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}


		/**
		 * Update User
		 */
		function updateUser ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						user_type_id = '".addslashes($User->getUserTypeId())."',
						username = '".addslashes($User->getUsername())."',
						fname = '".addslashes($User->getFname())."',
						mname = '".addslashes($User->getMname())."',
						lname = '".addslashes($User->getLname())."',
						email = '".addslashes($User->getEmail())."',
						is_old_data = '".addslashes($User->getIsOldData())."',
						update_date = '".addslashes($User->getUpdateDate())."',
						updated_by = '".addslashes($User->getUpdatedBy())."',
						modifier_type_id = '".addslashes($User->getModifierTypeId())."'
   					 WHERE user_id = '".$User->getUserId()."'
					";
						/*password = '".addslashes($User->getPassword())."',
						status = '".addslashes($User->getStatus())."',
						corporate_user_id = '".addslashes($User->getCorporateUserId())."',
						distributor_user_id = '".addslashes($User->getDistributorUserId())."',
						create_date = '".addslashes($User->getCreateDate())."',
						created_by = '".addslashes($User->getCreatedBy())."',
						creator_type_id = '".addslashes($User->getCreatorTypeId())."',*/
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		/**
		 * Update User
		 */
		function updateUserType ($ps_user,$today,$updated_by,$modifier)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET 
					 user_type_id 		= '2',
					 update_date		=	'".$today."',
					 updated_by			=	'".$updated_by."',
					 modifier_type_id	=	'".$modifier."'
					 
   					 WHERE user_id IN(".$ps_user.")
					";
			
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Remove User
		 */
		function RemoveUser ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						status = 'D',
						update_date = '".addslashes($User->getUpdateDate())."',
						updated_by = '".addslashes($User->getUpdatedBy())."'
						
   					 WHERE user_id = '".$User->getUserId()."'
					";
						/*password = '".addslashes($User->getPassword())."',
						status = '".addslashes($User->getStatus())."',
						corporate_user_id = '".addslashes($User->getCorporateUserId())."',
						distributor_user_id = '".addslashes($User->getDistributorUserId())."',
						create_date = '".addslashes($User->getCreateDate())."',
						created_by = '".addslashes($User->getCreatedBy())."',
						creator_type_id = '".addslashes($User->getCreatorTypeId())."',*/
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Update User
		 */
		function updateTestUserTake ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						fname = '".addslashes($User->getFname())."',
						lname = '".addslashes($User->getLname())."',
						update_date = '".addslashes($User->getUpdateDate())."',
						
   					 WHERE user_id = '".$User->getUserId()."'
					";
						/*password = '".addslashes($User->getPassword())."',
						status = '".addslashes($User->getStatus())."',
						corporate_user_id = '".addslashes($User->getCorporateUserId())."',
						distributor_user_id = '".addslashes($User->getDistributorUserId())."',
						create_date = '".addslashes($User->getCreateDate())."',
						created_by = '".addslashes($User->getCreatedBy())."',
						creator_type_id = '".addslashes($User->getCreatorTypeId())."',*/
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Update User
		 */
		function updateTestUserUsernamePassword ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

		 	$sql	=
					"UPDATE tcv_user
					 SET
						
						username = '".addslashes($User->getUsername())."',
						password = '".addslashes($User->getPassword())."',
						Status = '".addslashes($User->getStatus())."',
						update_date = now()
						WHERE user_id = '".$User->getUserId()."'
					";
						
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Update User
		 */
		function updateUserPassword ($id,$pass)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						password = '$pass',
						update_date = now()
						
   					 WHERE user_id = '$id'
					";
					
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function updateUserAdminPassword ($id,$pass)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						admin_password = '$pass',
						admin_password_date = now(),
						update_date = now()
						
   					 WHERE user_id = '$id'
					";
					
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Update User
		 */
		function updateUserSelf ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						fname = '".addslashes($User->getFname())."',
						mname = '".addslashes($User->getMname())."',
						lname = '".addslashes($User->getLname())."',
						email = '".addslashes($User->getEmail())."',
						update_date = now()
						
   					 WHERE user_id = '".$User->getUserId()."'
					";
						/*password = '".addslashes($User->getPassword())."',
						status = '".addslashes($User->getStatus())."',
						corporate_user_id = '".addslashes($User->getCorporateUserId())."',
						distributor_user_id = '".addslashes($User->getDistributorUserId())."',
						create_date = '".addslashes($User->getCreateDate())."',
						created_by = '".addslashes($User->getCreatedBy())."',
						creator_type_id = '".addslashes($User->getCreatorTypeId())."',*/
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		/**
		 * Update User
		 */
		function updateUserEditTime ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						
						username = '".addslashes($User->getUsername())."',
						
						fname = '".addslashes($User->getFname())."',
						mname = '".addslashes($User->getMname())."',
						lname = '".addslashes($User->getLname())."',
						email = '".addslashes($User->getEmail())."',";
						
						if($User->getPassword() != '' )
						{
						$sql .=	"password = '".addslashes(md5($User->getPassword()))."',";
						}
						
						$sql .= " update_date = now(),
						updated_by = '".addslashes($User->getUpdatedBy())."',
						modifier_type_id = '".addslashes($User->getModifierTypeId())."'
   					 WHERE user_id = '".$User->getUserId()."'
					";
						
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}

		/**
		 * Delete User
		 */
		function deleteUser ($UserId)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"DELETE FROM tcv_user
   					 WHERE user_id = $UserId
					";

				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}


		/**
		 * Get Single User
		 */
		function getSingleUser ($user_id)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT *
					 FROM tcv_user
					 WHERE user_id = $user_id
					";
				$result	= $conn->db_query($sql);
				//echo $sql;
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
				
				
				//	throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					$row = $conn->db_fetch_object($result);

					$arr = new User();

					$arr->setUserId(stripslashes($row->user_id));
					$arr->setUserTypeId(stripslashes($row->user_type_id));
					$arr->setUsername(stripslashes($row->username));
					$arr->setPassword(stripslashes($row->password));
					$arr->setAdminPassword(stripslashes($row->admin_password));
					$arr->setAdminPasswordDate(stripslashes($row->admin_password_date));
					$arr->setFname(stripslashes($row->fname));
					$arr->setMname(stripslashes($row->mname));
					$arr->setLname(stripslashes($row->lname));
					$arr->setEmail(stripslashes($row->email));
					$arr->setIsOldData(stripslashes($row->is_old_data));
					$arr->setStatus(stripslashes($row->status));
					$arr->setCorporateUserId(stripslashes($row->corporate_user_id));
					$arr->setDistributorUserId(stripslashes($row->distributor_user_id));
					$arr->setCreateDate(stripslashes($row->create_date));
					$arr->setCreatedBy(stripslashes($row->created_by));
					$arr->setCreatorTypeId(stripslashes($row->creator_type_id));
					$arr->setUpdateDate(stripslashes($row->update_date));
					$arr->setUpdatedBy(stripslashes($row->updated_by));
					$arr->setModifierTypeId(stripslashes($row->modifier_type_id));

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		 /**
		 * Created by : Rajesh Gite
		 * Description : to get single user with his company
		 * Parameters : user_id
		 * Created Date : 07 July 2011
		 * Get Single User with User Company Name
		*/
		
		function getSingleUserWithCompany ($user_id)
		{
			try
			{
				$conn	= new ConnectionPool();
				/*$sql 	=
							"	SELECT u. * , i.company AS ucompany, m.subscribe as subscribe
FROM tcv_user u INNER JOIN tcv_user_info i ON u.user_id = i.user_id INNER JOIN tcv_mailing_list m ON i.mailing_id = m.mailing_id";*/

				$sql 	=
							"	SELECT u. * , i.company AS ucompany, m.subscribe as subscribe, tcv_user_address.street,i.employer_email_id
								FROM tcv_user u INNER JOIN tcv_user_info i ON u.user_id = i.user_id 
								INNER JOIN tcv_mailing_list m ON i.mailing_id = m.mailing_id
								LEFT JOIN tcv_user_address  ON tcv_user_address.user_id  = u.user_id and tcv_user_address.address_type = 'normal'
								";
								
				  $sql .= " WHERE u.user_id = ".$user_id;
				  
				
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					$row = $conn->db_fetch_object($result);

					$arr = new User();

					$arr->setUserId(stripslashes($row->user_id));
					$arr->setUserTypeId(stripslashes($row->user_type_id));
					$arr->setUsername(stripslashes($row->username));
					$arr->setPassword(stripslashes($row->password));
					$arr->setAdminPassword(stripslashes($row->admin_password));
					$arr->setAdminPasswordDate(stripslashes($row->admin_password_date));
					$arr->setFname(stripslashes($row->fname));
					$arr->setMname(stripslashes($row->mname));
					$arr->setLname(stripslashes($row->lname));
					$arr->setEmail(stripslashes($row->email));
					$arr->setIsOldData(stripslashes($row->is_old_data));
					$arr->setStatus(stripslashes($row->status));
					$arr->setCorporateUserId(stripslashes($row->corporate_user_id));
					$arr->setDistributorUserId(stripslashes($row->distributor_user_id));
					$arr->setCreateDate(stripslashes($row->create_date));
					$arr->setCreatedBy(stripslashes($row->created_by));
					$arr->setCreatorTypeId(stripslashes($row->creator_type_id));
					$arr->setUpdateDate(stripslashes($row->update_date));
					$arr->setUpdatedBy(stripslashes($row->updated_by));
					$arr->setModifierTypeId(stripslashes($row->modifier_type_id));
					$arr->setUserCompany(stripslashes($row->ucompany));
					$arr->setMailingSubscribe(stripslashes($row->subscribe));
					
					$arr->setStreet(stripslashes($row->street));
					$arr->setEmployerEmailId(stripslashes($row->employer_email_id));
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Get Single User
		 */
		function getSingleUserWhere ($where_clause)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT *
					 FROM tcv_user
					 WHERE $where_clause
					";
				
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					$row = $conn->db_fetch_object($result);

					$arr = new User();

					$arr->setUserId(stripslashes($row->user_id));
					$arr->setUserTypeId(stripslashes($row->user_type_id));
					$arr->setUsername(stripslashes($row->username));
					$arr->setPassword(stripslashes($row->password));
					$arr->setAdminPassword(stripslashes($row->admin_password));
					$arr->setAdminPasswordDate(stripslashes($row->admin_password_date));
					$arr->setFname(stripslashes($row->fname));
					$arr->setMname(stripslashes($row->mname));
					$arr->setLname(stripslashes($row->lname));
					$arr->setEmail(stripslashes($row->email));
					$arr->setIsOldData(stripslashes($row->is_old_data));
					$arr->setStatus(stripslashes($row->status));
					$arr->setCorporateUserId(stripslashes($row->corporate_user_id));
					$arr->setDistributorUserId(stripslashes($row->distributor_user_id));
					$arr->setCreateDate(stripslashes($row->create_date));
					$arr->setCreatedBy(stripslashes($row->created_by));
					$arr->setCreatorTypeId(stripslashes($row->creator_type_id));
					$arr->setUpdateDate(stripslashes($row->update_date));
					$arr->setUpdatedBy(stripslashes($row->updated_by));
					$arr->setModifierTypeId(stripslashes($row->modifier_type_id));

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
				/**
		 * Get Single User
		 */
		function getSingleUserLogin ($username , $password)
		{
			try
			{
				$conn	= new ConnectionPool();

				  $sql	=
					"SELECT *
					 FROM tcv_user
					 WHERE username = '$username' 
					 AND password = '$password'
					 AND status = 'A'
					";

				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					//return array();
					return 0;
				}
				else
				{
					$row = $conn->db_fetch_object($result);

					$arr = new User();

					$arr->setUserId(stripslashes($row->user_id));
					$arr->setUserTypeId(stripslashes($row->user_type_id));
					$arr->setUsername(stripslashes($row->username));
					$arr->setPassword(stripslashes($row->password));
					$arr->setAdminPassword(stripslashes($row->admin_password));
					$arr->setAdminPasswordDate(stripslashes($row->admin_password_date));
					$arr->setFname(stripslashes($row->fname));
					$arr->setMname(stripslashes($row->mname));
					$arr->setLname(stripslashes($row->lname));
					$arr->setEmail(stripslashes($row->email));
					$arr->setIsOldData(stripslashes($row->is_old_data));
					$arr->setStatus(stripslashes($row->status));
					$arr->setCorporateUserId(stripslashes($row->corporate_user_id));
					$arr->setDistributorUserId(stripslashes($row->distributor_user_id));
					$arr->setCreateDate(stripslashes($row->create_date));
					$arr->setCreatedBy(stripslashes($row->created_by));
					$arr->setCreatorTypeId(stripslashes($row->creator_type_id));
					$arr->setUpdateDate(stripslashes($row->update_date));
					$arr->setUpdatedBy(stripslashes($row->updated_by));
					$arr->setModifierTypeId(stripslashes($row->modifier_type_id));

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}



		/**
		 * Get All User
		 */
		function getAllUser ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
							"	SELECT *
								FROM tcv_user";
								
						

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setAdminPasswordDate(stripslashes($row->admin_password_date));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setDeviceRegistrationId(stripslashes($row->device_registration_id));
						$arr[$count]->setTokenId(stripslashes($row->token_id));
						$arr[$count]->setDeviceId(stripslashes($row->device_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		
		
		function getAllUserwhere ($where_clause = NULL)
		{
			//echo '<<<<dfdf<<<<<<<<';
				$conn 	= new ConnectionPool();

				$sql 	=
							
						"SELECT * FROM `tcv_user` where user_type_id =12 and device_id = 'Chart2020' and create_date BETWEEN CURDATE() - INTERVAL 8 DAY AND CURDATE()  order by create_date DESC";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if(($result))
				
				{
					
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setDeviceRegistrationId(stripslashes($row->device_registration_id));
						$arr[$count]->setTokenId(stripslashes($row->token_id));
						$arr[$count]->setDeviceId(stripslashes($row->device_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
					}

					return $arr; 
				}
			}
			
		
		
		/*Get all registered user*/
		
		function getAllUserregister ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
							
						"SELECT * FROM `tcv_user` where user_type_id  =12 and device_id != 'Chart2020' and create_date BETWEEN CURDATE() - INTERVAL 8 DAY AND CURDATE()  order by create_date DESC";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if(($result))
				
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setDeviceRegistrationId(stripslashes($row->device_registration_id));
						$arr[$count]->setTokenId(stripslashes($row->token_id));
						$arr[$count]->setDeviceId(stripslashes($row->device_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
					}

					return $arr; 
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/***Get ios user ****/
		
		function getAlliosUser ($where_clause = NULL)
		{
			//echo '<<<<dfdf<<<<<<<<';
				$conn 	= new ConnectionPool();

				$sql 	=
							
						"SELECT * FROM `tcv_user` where user_type_id =13 and create_date BETWEEN CURDATE() - INTERVAL 8 DAY AND CURDATE()  order by create_date DESC";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if(($result))
				
				{
					
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setDeviceRegistrationId(stripslashes($row->device_registration_id));
						$arr[$count]->setTokenId(stripslashes($row->token_id));
						$arr[$count]->setDeviceId(stripslashes($row->device_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
					}

					return $arr; 
				}
			}
		
		
		
		/***Get android user   ****/
		
		function getAllandroidUser ($where_clause = NULL)
		{
			//echo '<<<<dfdf<<<<<<<<';
				$conn 	= new ConnectionPool();

				$sql 	=
							
						"SELECT * FROM `tcv_user` where user_type_id =9 and create_date BETWEEN CURDATE() - INTERVAL 8 DAY AND CURDATE()  order by create_date DESC";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if(($result))
				
				{
					
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setDeviceRegistrationId(stripslashes($row->device_registration_id));
						$arr[$count]->setTokenId(stripslashes($row->token_id));
						$arr[$count]->setDeviceId(stripslashes($row->device_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
					}

					return $arr; 
				}
			}
		
		
				/***Get android user   ****/
		
		function getusertril ($where_clause = NULL)
		{
			//echo '<<<<dfdf<<<<<<<<';
				$conn 	= new ConnectionPool();

				$sql 	=
							
						"SELECT * FROM `tcv_user` where user_type_id = '12' and licence_type = '0'";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if(($result))
				
				{
					
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setDeviceRegistrationId(stripslashes($row->device_registration_id));
						$arr[$count]->setTokenId(stripslashes($row->token_id));
						$arr[$count]->setDeviceId(stripslashes($row->device_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
					}

					return $arr; 
				}
			}
			
		
//		/***Get ios user !Chart2020 ****/
//		
//		function getAlliosUserwhere ($where_clause = NULL)
//		{
//			//echo '<<<<dfdf<<<<<<<<';
//				$conn 	= new ConnectionPool();
//
//				$sql 	=
//							
//						"SELECT * FROM `tcv_user` where user_type_id =13 and device_id != 'Chart2020' and create_date BETWEEN CURDATE() - INTERVAL 8 DAY AND CURDATE()  order by create_date DESC";
//
//				if($where_clause != NULL)
//				$sql .= " WHERE ".$where_clause;
//				
//				
//				$result	= $conn->db_query($sql);
//				//echo $sql;
//				if(($result))
//				
//				{
//					
//					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
//					{
//						$arr[$count] = new User();
//
//						$arr[$count]->setUserId(stripslashes($row->user_id));
//						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
//						$arr[$count]->setUsername(stripslashes($row->username));
//						$arr[$count]->setPassword(stripslashes($row->password));
//						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
//						$arr[$count]->setFname(stripslashes($row->fname));
//						$arr[$count]->setMname(stripslashes($row->mname));
//						$arr[$count]->setLname(stripslashes($row->lname));
//						$arr[$count]->setEmail(stripslashes($row->email));
//						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
//						$arr[$count]->setStatus(stripslashes($row->status));
//						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
//						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
//						$arr[$count]->setDeviceRegistrationId(stripslashes($row->device_registration_id));
//						$arr[$count]->setTokenId(stripslashes($row->token_id));
//						$arr[$count]->setDeviceId(stripslashes($row->device_id));
//						$arr[$count]->setCreateDate(stripslashes($row->create_date));
//						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
//						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
//						
//						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
//						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
//						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
//					}
//
//					return $arr; 
//				}
//			}
//			
//		/***Get android user !Chart2020 ****/
//		
//		function getAllandroidUserwhere ($where_clause = NULL)
//		{
//			//echo '<<<<dfdf<<<<<<<<';
//				$conn 	= new ConnectionPool();
//
//				$sql 	=
//							
//						"SELECT * FROM `tcv_user` where user_type_id =9 and device_id != 'Chart2020' and create_date BETWEEN CURDATE() - INTERVAL 8 DAY AND CURDATE()  order by create_date DESC";
//
//				if($where_clause != NULL)
//				$sql .= " WHERE ".$where_clause;
//				
//				
//				$result	= $conn->db_query($sql);
//				//echo $sql;
//				if(($result))
//				
//				{
//					
//					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
//					{
//						$arr[$count] = new User();
//
//						$arr[$count]->setUserId(stripslashes($row->user_id));
//						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
//						$arr[$count]->setUsername(stripslashes($row->username));
//						$arr[$count]->setPassword(stripslashes($row->password));
//						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
//						$arr[$count]->setFname(stripslashes($row->fname));
//						$arr[$count]->setMname(stripslashes($row->mname));
//						$arr[$count]->setLname(stripslashes($row->lname));
//						$arr[$count]->setEmail(stripslashes($row->email));
//						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
//						$arr[$count]->setStatus(stripslashes($row->status));
//						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
//						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
//						$arr[$count]->setDeviceRegistrationId(stripslashes($row->device_registration_id));
//						$arr[$count]->setTokenId(stripslashes($row->token_id));
//						$arr[$count]->setDeviceId(stripslashes($row->device_id));
//						$arr[$count]->setCreateDate(stripslashes($row->create_date));
//						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
//						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
//						
//						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
//						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
//						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
//					}
//
//					return $arr; 
//				}
//			}	
//		
			
		
		
		
		/**
		 * Get All User
		 */
		function getAllUserForDistributorAcctSummary($sort_con,$where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
						"SELECT tcv_user.user_type_id as user_type_id,tcv_user.fname, tcv_user.lname, tcv_user.email, tcv_user.distributor_user_id, max( tcv_user_plan.create_date )  as latest_date , tcv_user_info.total_credits as total_credits , 
						SUM( tcv_user_plan.amt_paid ) as total_amt
						FROM tcv_user
						JOIN tcv_user_plan ON ( tcv_user.user_id = tcv_user_plan.user_id )
						JOIN tcv_user_info ON ( tcv_user_plan.user_id = tcv_user_info.user_id )
						";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				$sql .= " GROUP BY (
						tcv_user.user_id
						) ";
				$sql .= $sort_con;		
			
				$result	= $conn->db_query($sql);
				//echo $sql;
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setLatestDate(stripslashes($row->latest_date));
						$arr[$count]->setTotalCredit(stripslashes($row->total_credits));
						$arr[$count]->setTotalAmount(stripslashes($row->total_amt));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		/**
		 * Get All User
		 */
		function getAllUserTest ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
							"	SELECT *,tcv_users_tests.create_date as test_create_date
								FROM tcv_user INNER JOIN tcv_users_tests ON(tcv_user.user_id=tcv_users_tests.user_id)
								INNER JOIN tcv_cms_test on(tcv_users_tests.test_id = tcv_cms_test.cms_id)
								 ";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setAdminPasswordDate(stripslashes($row->admin_password_date));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setTestCreateDate(stripslashes($row->test_create_date));
						$arr[$count]->setTestTakenDate(stripslashes($row->test_taken_date));
						$arr[$count]->setPassed(stripslashes($row->passed));
						$arr[$count]->setTestTaken(stripslashes($row->test_taken));
						$arr[$count]->setUserTestId(stripslashes($row->user_test_id));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}

		/**
		 * Get All User
		 */
		function getAllUserTestCount ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
							"	SELECT count(*) As count
								FROM tcv_user INNER JOIN tcv_users_tests ON(tcv_user.user_id=tcv_users_tests.user_id) ";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{ 
				
					$row = $conn->db_fetch_object($result);
					
					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}


		 /**
		 * Created by : Mrunal Malusare
		 * Description : to get all user of type id 1 or 2
		 * Parameters : where condition
		 * Created Date : 6 june 11
		 * Get All User with User Type
		*/
		function getAllUserWithType ($where_clause = NULL)	//created by Mrunal Malusare on 6 jun 2011
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
							"	SELECT u.*, Description as utype
								FROM tcv_user u, tcv_usertype t";
								
				  $sql .= " WHERE user_type_id = type_id";
				 
				if($where_clause != NULL)
					$sql .= " AND ".$where_clause;
				//echo $sql;
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setAdminPasswordDate(stripslashes($row->admin_password_date));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setUserType(stripslashes($row->utype));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Created by : Rajesh Gite
		 * Description : To get all users of distributor in Report module
		 * Parameters : where condition
		 * Created Date : 02 JULY 2011
		 * Get All User with User Type
		*/
		
		function getAllUserWithType_Distributor ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
							"   SELECT u.*, Description as utype
								FROM tcv_user u, tcv_usertype t";
								
				  $sql .= " WHERE user_type_id = type_id";
				 
				if($where_clause != NULL)
					$sql .= " AND ".$where_clause;
				//echo $sql;
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setAdminPasswordDate(stripslashes($row->admin_password_date));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setUserType(stripslashes($row->utype));
						if(stripslashes($row->user_type_id) == 1)
						{
							$corp_user_count = $this->getCorpUserCount(stripslashes($row->user_id), stripslashes($row->distributor_user_id));
							if($corp_user_count == '')
							$corp_user_count = 0;
						}
						else
						{
							$corp_user_count = 0;
						}
						$arr[$count]->setCorpUserCount($corp_user_count);
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Created by : Rajesh Gite
		 * Description : To get corporate user count in Report module
		 * Parameters : where condition
		 * Created Date : 02 JULY 2011
		 * Get All User with User Type
		*/
		
		function getCorpUserCount($corp_user_id, $distributor_user_id='')
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	= " SELECT count(user_id) as corp_users FROM  tcv_user WHERE corporate_user_id = ".$corp_user_id." AND status = 'A'";
				//echo $sql;
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return 0;
				}
				else
				{
					$row = $conn->db_fetch_object($result);
					return $row->corp_users;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		/**
		 * Created by : Rajesh Gite
		 * Description : To Assign Users in View Commission History
		 * Parameters : where condition
		 * Created Date : 05 JULY 2011
		 * Get All User with User Type
		*/
		function getAllUserNotInDiscountCode ($where_clause = NULL, $dis_code_id)	//created by Mrunal Malusare on 6 jun 2011
		{
			try
			{
				$conn 	= new ConnectionPool();
				
				$sql 	=
							"	SELECT tcv_user.*, tcv_usertype.Description as utype
								FROM tcv_user INNER JOIN tcv_usertype ON tcv_user.user_type_id = tcv_usertype.type_id";
								
				  $sql .= " AND tcv_user.user_id NOT IN ( SELECT user_id FROM tcv_discount_code_usage WHERE                  			dis_code_id = ".$dis_code_id.") AND tcv_user.user_id NOT IN ( SELECT user_id FROM tcv_user_info WHERE                  			dis_code_id = ".$dis_code_id.")";

								
				if($where_clause != NULL)
					$sql .= " AND ".$where_clause;
				//die($sql);
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();
						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setAdminPasswordDate(stripslashes($row->admin_password_date));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setUserType(stripslashes($row->utype));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Created by : Pritam Dulam
		 * Description : to get all user of type id 1 or 2 with Exception handling.
		 * Parameters : where condition
		 * Created Date : 22 june 2011
		 * Get All User with User Type with exception handling.
		*/
		function getAllUserWithTypewithException ($where_clause = NULL)	//created by Mrunal Malusare on 6 jun 2011
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
							"	SELECT u.*, Description as utype
								FROM tcv_user u, tcv_usertype t";
								
				  $sql .= " WHERE user_type_id = type_id";
				 
				if($where_clause != NULL)
					$sql .= " AND ".$where_clause;
				//echo $sql;
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setAdminPasswordDate(stripslashes($row->admin_password_date));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setUserType(stripslashes($row->utype));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Created by : Mrunal Malusare
		 * Description : Update user status
		 * Parameters : User class object
		 * Update user status
		*/
		 function updateUserStatus ($User)
		{
			try
			{
				$conn	= new ConnectionPool();
				$sql	=
					"UPDATE tcv_user
					 SET
						status = '".addslashes($User->getStatus())."',
						update_date = '".addslashes($User->getUpdateDate())."',
						updated_by = '".addslashes($User->getUpdatedBy())."',
						modifier_type_id = '".addslashes($User->getModifierTypeId())."'						
   					 WHERE user_id = '".addslashes($User->getUserId())."'
					";	

				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Created by : Mrunal Malusare
		 * Description : switch user
		 * Parameters : User class object
		 * switch user
		 */
		 function switchUSer ($User)
		{
			try
			{
				$conn	= new ConnectionPool();
				$sql	=
					"UPDATE tcv_user
					 SET
						distributor_user_id = '".addslashes($User->getDistributorUserId())."',
						update_date = '".addslashes($User->getUpdateDate())."',
						updated_by = '".addslashes($User->getUpdatedBy())."',
						modifier_type_id = '".addslashes($User->getModifierTypeId())."'						
   					 WHERE user_id = '".addslashes($User->getUserId())."'
					";	

				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Created by : Mrunal Malusare
		 * Description : update user credentials
		 * Parameters : User class object
		 * update user credentials
		 */
		function updateUserCredentials ($User)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						
						password = '".addslashes($User->getPassword())."',
						update_date = '".addslashes($User->getUpdateDate())."',
						updated_by = '".addslashes($User->getUpdatedBy())."',
						modifier_type_id = '".addslashes($User->getModifierTypeId())."'	
   					 WHERE user_id = '".$User->getUserId()."'
					";

				//username = '".addslashes($User->getUsername())."',
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/***
		*	Update user password for Forgot Password
		*
		*/
		function updateUserPasswordForForgotPass ($user_id, $newPass)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						
						password = '".addslashes($newPass)."'
   					 WHERE user_id = '".$user_id."'
					";

				//username = '".addslashes($User->getUsername())."',
				if(!$conn->db_query($sql))
				{
					//throw new UserException(mysql_errno($conn->connection),mysql_error($conn->connection));
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink)); //added by Mrunal M on 30 june 11
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		//Update User EMail
		
		function updateUserEmail ($email, $user_id)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						
						email = '".addslashes($email)."'
   					 WHERE user_id = '".$user_id."'
					";

				//username = '".addslashes($User->getUsername())."',
				if(!$conn->db_query($sql))
				{
					//throw new UserException(mysql_errno($conn->connection),mysql_error($conn->connection));
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink)); //added by Mrunal M on 30 june 11
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Get All User Count
		 */
		function getAllUserCount ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
					"SELECT count(*) AS count
					 FROM tcv_user
					";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;

				$result	= $conn->db_query($sql);
				
				if((!$result))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}elseif (($conn->db_num_rows($result) == 0))
				{
					return 0;
				}
				else
				{
					$row	= $conn->db_fetch_object($result);

					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Get All User Count
		 */
		function checkUserNameExist ($username,$id)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
					"SELECT count(*) AS count
					 FROM tcv_user WHERE username = '".$username."' And user_id <> ".$id;

				$result	= $conn->db_query($sql);
				
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					$row	= $conn->db_fetch_object($result);

					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/*Created By :Pritam Dulam
		  Create Date: 22-06-2011	
		*/
		/**
		 * Get All User Count
		 */
		function getAllUserCountDist ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
					"SELECT count(*) AS count
					 FROM tcv_user u, tcv_usertype t
					 WHERE user_type_id = type_id
					";

				if($where_clause != NULL)
					$sql .= " AND ".$where_clause;

				$result	= $conn->db_query($sql);
				
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					$row	= $conn->db_fetch_object($result);

					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function getSingleUserTestInfo ($where_clause)
		{
			try
			{
				$conn	= new ConnectionPool();

				
				$sql =
					  " SELECT *
						FROM tcv_user
						LEFT JOIN tcv_user_test_info ON tcv_user_test_info.user_id = tcv_user.user_id";	
						
						if($where_clause != NULL)
					$sql .= "  WHERE".$where_clause;
					
				$result	= $conn->db_query($sql);
				//echo $sql;
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					//throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					$row = $conn->db_fetch_object($result);

					$arr = new User();

					$arr->setUserId(stripslashes($row->user_id));
					$arr->setUserTypeId(stripslashes($row->user_type_id));
					$arr->setUsername(stripslashes($row->username));
					$arr->setPassword(stripslashes($row->password));
					$arr->setAdminPassword(stripslashes($row->admin_password));
					$arr->setAdminPasswordDate(stripslashes($row->admin_password_date));
					$arr->setFname(stripslashes($row->fname));
					$arr->setMname(stripslashes($row->mname));
					$arr->setLname(stripslashes($row->lname));
					$arr->setEmail(stripslashes($row->email));
					$arr->setIsOldData(stripslashes($row->is_old_data));
					$arr->setStatus(stripslashes($row->status));
					$arr->setCorporateUserId(stripslashes($row->corporate_user_id));
					$arr->setDistributorUserId(stripslashes($row->distributor_user_id));
					$arr->setCreateDate(stripslashes($row->create_date));
					$arr->setCreatedBy(stripslashes($row->created_by));
					$arr->setCreatorTypeId(stripslashes($row->creator_type_id));
					$arr->setUpdateDate(stripslashes($row->update_date));
					$arr->setUpdatedBy(stripslashes($row->updated_by));
					$arr->setModifierTypeId(stripslashes($row->modifier_type_id));
					
					$arr->setBirthday(stripslashes($row->birthday));
					$arr->setIdentifier(stripslashes($row->identifier));

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function updateUserStatusOnDiscount($User)
		{
			try
			{
				$conn	= new ConnectionPool();
				$sql	=
					"UPDATE tcv_user
					 SET
						status = '".addslashes($User->getStatus())."',
						update_date = '".addslashes($User->getUpdateDate())."',
						updated_by = '".addslashes($_SESSION['adminUserId'])."',
						modifier_type_id = '".addslashes($_SESSION['adminUserType'])."'
   					 WHERE user_id = '".addslashes($User->getUserId())."'";	

				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
	  function getAllPublicSafetyUser ($where_clause = NULL)	//created by Mrunal Malusare on 6 jun 2011
		{
			try
			{
				$conn 	= new ConnectionPool();

					  
				  $sql 	= "	SELECT *, tcv_user.status as user_status 
							FROM tcv_user
							LEFT JOIN  tcv_user_info ON  tcv_user_info.user_id  = tcv_user.user_id
							LEFT JOIN   tcv_public_safety_dept ON   tcv_public_safety_dept.dept_id  = tcv_user_info.user_dept_id";
				  $sql .= " WHERE user_type_id = '8'";
				
				if($where_clause != NULL)
				$sql .= " AND ".$where_clause;
				
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setUsername(stripslashes($row->username));
						$arr[$count]->setPassword(stripslashes($row->password));
						$arr[$count]->setAdminPassword(stripslashes($row->admin_password));
						$arr[$count]->setAdminPasswordDate(stripslashes($row->admin_password_date));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setMname(stripslashes($row->mname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setStatus(stripslashes($row->user_status));
						$arr[$count]->setCorporateUserId(stripslashes($row->corporate_user_id));
						$arr[$count]->setDistributorUserId(stripslashes($row->distributor_user_id));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setUserType(stripslashes($row->utype));
						
						$arr[$count]->setUserDeptId(stripslashes($row->user_dept_id));
						$arr[$count]->setDeptName(stripslashes($row->dept_name));
						
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}	
		
		
		function getAllExpiredCorporateUsers($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
						"SELECT tcv_user.user_id,
								tcv_user.user_type_id as user_type_id,
								tcv_user.username,
								tcv_user.fname, 
								tcv_user.lname, 
								tcv_user.email,
								tcv_user_plan.expiry_date,
								DATEDIFF( CURDATE( ) , tcv_user_plan.expiry_date ) AS dayscount
								FROM tcv_user
								INNER JOIN tcv_user_plan ON ( tcv_user.user_id = tcv_user_plan.user_id )
						";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
			
				$result	= $conn->db_query($sql);
				//echo $sql;
				//echo '<br>';
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setLatestDate(stripslashes($row->latest_date));
						//$arr[$count]->setTotalCredit(stripslashes($row->total_credits));
						//$arr[$count]->setTotalAmount(stripslashes(number_format($row->total_amt, 2, '.', '')));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		function getAllCorporateUsers5CreditsLeft($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
						"SELECT tcv_user.user_id,
								tcv_user.user_type_id as user_type_id,
								tcv_user.username,
								tcv_user.fname, 
								tcv_user.lname, 
								tcv_user.email,
								tcv_user_info.unlimited_credits,
								tcv_user_info.total_credits
								FROM tcv_user
								INNER JOIN tcv_user_info ON ( tcv_user.user_id = tcv_user_info.user_id )
						";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;
			
				$result	= $conn->db_query($sql);
				//echo $sql;
				//echo '<br>';
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new User();

						$arr[$count]->setUserId(stripslashes($row->user_id));
						$arr[$count]->setFname(stripslashes($row->fname));
						$arr[$count]->setLname(stripslashes($row->lname));
						$arr[$count]->setEmail(stripslashes($row->email));
						$arr[$count]->setIsOldData(stripslashes($row->is_old_data));
						$arr[$count]->setUserTypeId(stripslashes($row->user_type_id));
						$arr[$count]->setLatestDate(stripslashes($row->latest_date));
						//$arr[$count]->setTotalCredit(stripslashes($row->total_credits));
						//$arr[$count]->setTotalAmount(stripslashes(number_format($row->total_amt, 2, '.', '')));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		//added for uzma shaikh date 19 apr 2012 for mobile app
		/**
		 * Get All User Count
		 */
		function getAllUserCountOnApp ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				 $sql 	=
					"SELECT count(*) AS count
					 FROM tcv_user
					";

				if($where_clause != NULL)
				$sql .= " WHERE ".$where_clause;

				$result	= $conn->db_query($sql);
				
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					$row	= $conn->db_fetch_object($result);

					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function addUserOnApp ($User)
		{
			try
			{
				$conn	= new ConnectionPool();
				//token_id,'".addslashes($User->getTokenId())."',
				$sql	=
					"INSERT INTO tcv_user
					 (
						user_type_id,
						username,
						password,
						fname,
						mname,
						lname,
						email,
						is_old_data,
						status,
						device_id,						
						licence_type,
						device_registration_id,
						corporate_user_id,
						distributor_user_id,
						create_date,
						created_by,
						creator_type_id,
						update_date,
						updated_by,
						modifier_type_id
					 )
					 VALUES
					 (
						
						'".addslashes($User->getUserTypeId())."',
						'".addslashes($User->getUsername())."',
						'".addslashes($User->getPassword())."',
						'".addslashes($User->getFname())."',
						'".addslashes($User->getMname())."',
						'".addslashes($User->getLname())."',
						'".addslashes($User->getEmail())."',
						'".addslashes($User->getIsOldData())."',
						'".addslashes($User->getStatus())."',
						'".addslashes($User->getDeviceId())."',
						'".addslashes($User->getLicenceType())."',
						'".addslashes($User->getDeviceRegistrationId())."',
						'".addslashes($User->getCorporateUserId())."',
						'".addslashes($User->getDistributorUserId())."',
						'".addslashes($User->getCreateDate())."',
						'".addslashes($User->getCreatedBy())."',
						'".addslashes($User->getCreatorTypeId())."',
						'".addslashes($User->getUpdateDate())."',
						'".addslashes($User->getUpdatedBy())."',
						'".addslashes($User->getModifierTypeId())."'
					 )
					";

				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
				return mysql_insert_id();
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		//end
				
		/**
		 * Get Single User
		 */
		function getSingleUserOnApp ($where_clause)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT *
					 FROM tcv_user
					 LEFT JOIN  tcv_user_info ON  tcv_user_info.user_id  = tcv_user.user_id
					";
					
				if($where_clause != NULL)
				 $sql .= " WHERE  ".$where_clause;
				
				
				$result	= $conn->db_query($sql);
				//echo $sql;
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					$row = $conn->db_fetch_object($result);

					$arr = new User();

					$arr->setUserId(stripslashes($row->user_id));
					$arr->setUserTypeId(stripslashes($row->user_type_id));
					$arr->setUsername(stripslashes($row->username));
					$arr->setPassword(stripslashes($row->password));
					$arr->setFname(stripslashes($row->fname));
					$arr->setMname(stripslashes($row->mname));
					$arr->setLname(stripslashes($row->lname));
					$arr->setEmail(stripslashes($row->email));
					$arr->setIsOldData(stripslashes($row->is_old_data));
					$arr->setStatus(stripslashes($row->status));
					$arr->setTotalCredit(stripslashes($row->total_credit));
					$arr->setUnlimitedCredits(stripslashes($row->unlimited_credits));
					$arr->setCorporateUserId(stripslashes($row->corporate_user_id));
					$arr->setDistributorUserId(stripslashes($row->distributor_user_id));
					
					
					$arr->setDeviceRegistrationId(stripslashes($row->device_registration_id));
					$arr->setTokenId(stripslashes($row->token_id));
					$arr->setDeviceId(stripslashes($row->device_id));
					$arr->setLicenceType(stripslashes($row->licence_type));
					$arr->setCreateDate(stripslashes($row->create_date));
					$arr->setCreatedBy(stripslashes($row->created_by));
					$arr->setCreatorTypeId(stripslashes($row->creator_type_id));
					$arr->setUpdateDate(stripslashes($row->update_date));
					$arr->setUpdatedBy(stripslashes($row->updated_by));
					$arr->setModifierTypeId(stripslashes($row->modifier_type_id));

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Remove User
		 */
		function UpadteUserStatusOnAppWhere ($where_clause,$status)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_user
					 SET
						status = '$status',
						update_date = '".addslashes(date('Y-m-d H:i:s'))."',
						updated_by = '0'
				";
				
				 $sql .= " WHERE  user_type_id = '9' AND ".$where_clause;
						/*password = '".addslashes($User->getPassword())."',
						status = '".addslashes($User->getStatus())."',
						corporate_user_id = '".addslashes($User->getCorporateUserId())."',
						distributor_user_id = '".addslashes($User->getDistributorUserId())."',
						create_date = '".addslashes($User->getCreateDate())."',
						created_by = '".addslashes($User->getCreatedBy())."',
						creator_type_id = '".addslashes($User->getCreatorTypeId())."',*/
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
			/**
		 * Update User
		 */
		function updateUserOnApp ($User)
		{
			try
			{
				$conn	= new ConnectionPool();
				//token_id = '".addslashes($User->getTokenId())."',
				$sql	=
					"UPDATE tcv_user
					 SET
						fname = '".addslashes($User->getFname())."',
						lname = '".addslashes($User->getLname())."',
						device_registration_id = '".addslashes($User->getDeviceRegistrationId())."',
						licence_type = '".addslashes($User->getLicenceType())."',
						update_date = '".addslashes($User->getUpdateDate())."',
						updated_by = '".addslashes($User->getUpdatedBy())."',
						modifier_type_id = '".addslashes($User->getModifierTypeId())."'
   					 WHERE user_id = '".$User->getUserId()."'
					";
						/*password = '".addslashes($User->getPassword())."',
						status = '".addslashes($User->getStatus())."',
						corporate_user_id = '".addslashes($User->getCorporateUserId())."',
						distributor_user_id = '".addslashes($User->getDistributorUserId())."',
						create_date = '".addslashes($User->getCreateDate())."',
						created_by = '".addslashes($User->getCreatedBy())."',
						creator_type_id = '".addslashes($User->getCreatorTypeId())."',*/
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function updateUserOnApp1 ($User)
		{
			try
			{
				$conn	= new ConnectionPool();
				//token_id = '".addslashes($User->getTokenId())."',
				$sql	=
					"UPDATE tcv_user
					 SET
						fname = '".addslashes($User->getFname())."',
						lname = '".addslashes($User->getLname())."',
						email = '".addslashes($User->getEmail())."',
						password = '".addslashes($User->getPassword())."',
						device_id = '".addslashes($User->getDeviceId())."',
						device_registration_id = '".addslashes($User->getDeviceRegistrationId())."',
						licence_type = '".addslashes($User->getLicenceType())."',
						update_date = '".addslashes($User->getUpdateDate())."',
						updated_by = '".addslashes($User->getUpdatedBy())."',
						modifier_type_id = '".addslashes($User->getModifierTypeId())."'
   					 WHERE user_id = '".$User->getUserId()."'
					";
						/*password = '".addslashes($User->getPassword())."',
						status = '".addslashes($User->getStatus())."',
						corporate_user_id = '".addslashes($User->getCorporateUserId())."',
						distributor_user_id = '".addslashes($User->getDistributorUserId())."',
						create_date = '".addslashes($User->getCreateDate())."',
						created_by = '".addslashes($User->getCreatedBy())."',
						creator_type_id = '".addslashes($User->getCreatorTypeId())."',*/
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		function updateWindowsUserType ($user_type_id,$today,$user_id,$modifier)
		{
			try
			{
				$conn	= new ConnectionPool();

				 $sql	=
					"UPDATE tcv_user
					 SET 
					 user_type_id 		=   '".$user_type_id."',
					 update_date		=	'".$today."',
					 updated_by			=	'".$user_id."',
					 modifier_type_id	=	'".$modifier."'
					 
   					WHERE user_id = '".$user_id."'
					";
			
				if(!$conn->db_query($sql))
				{
					throw new UserException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
	}
	/**
	 * End of class UserManager
	 */
?>
