<?php
	/**
	 * TestManager.php
	 *
	 * Description	: A Simple Getter/Setter Bin Class
	 *
	 * Developed By : Suresh Shinde
	 *
	 * Developed On : 07 June, 2010
	 *
	 * Liscence 	: GPL
	 *
	 * Created On 	: 22/06/2011 10:06:43
	 *
	 * Created By 	: Rohit Soni
	 *
	 */

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

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

	/**
	 * Start of class TestManager
	 */
	class TestManager
	{
		/**
		 * Add Test
		 */
		function addTest ($Test)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"INSERT INTO tcv_test
					 (
						test_id,
						test_type,
						parent_id,
						test_group_id,
						is_private,
						is_compressed,
						random_ques_order,
						no_of_questions,
						plate_durations,
						min_score,
						sort_order,
						mild_score_min,
						mild_score_max,
						mod_score_min,
						mod_score_max,
						sev_score_min,
						sev_score_max,
						status,
						allow_mobile,
						d15,
						test_price,
						allow_deficiency,
						calculate_result,
						application_type,
						max_demo_plate 
					 )
					 VALUES
					 (
						'".addslashes($Test->getTestId())."',
						'".addslashes($Test->getTestType())."',
						'".addslashes($Test->getParentId())."',
						'".addslashes($Test->getTestGroupId())."',
						'".addslashes($Test->getIsPrivate())."',
						'".addslashes($Test->getIsCompressed())."',
						'".addslashes($Test->getRandomQuesOrder())."',
						'".addslashes($Test->getNoOfQuestions())."',
						'".addslashes($Test->getPlateDurations())."',
						'".addslashes($Test->getMinScore())."',
						'".addslashes($Test->getSortOrder())."',
						'".addslashes($Test->getMildScoreMin())."',
						'".addslashes($Test->getMildScoreMax())."',
						'".addslashes($Test->getModScoreMin())."',
						'".addslashes($Test->getModScoreMax())."',
						'".addslashes($Test->getSevScoreMin())."',
						'".addslashes($Test->getSevScoreMax())."',
						'".addslashes($Test->getStatus())."',
						'".addslashes($Test->getAllowMobile())."',
						'".addslashes($Test->getD15())."',
						'".addslashes($Test->getTestPrice())."',
						'".addslashes($Test->getAllowDeficiency())."',
						'".addslashes($Test->getCalculateResult())."',
						'".addslashes($Test->getApplicationType())."',
						'".addslashes($Test->getMaxDemoPlates())."'
					 )
					";

				if(!$conn->db_query($sql))
				{
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				}else
				{
					return $conn->db_last_insert_id();
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}


		/**
		 * Update Test
		 */
		function updateTest ($Test)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_test
					 SET
						test_type = '".addslashes($Test->getTestType())."',
						parent_id = '".addslashes($Test->getParentId())."',
						test_group_id = '".addslashes($Test->getTestGroupId())."',
						is_private = '".addslashes($Test->getIsPrivate())."',
						is_compressed = '".addslashes($Test->getIsCompressed())."',
						random_ques_order = '".addslashes($Test->getRandomQuesOrder())."',
						no_of_questions = '".addslashes($Test->getNoOfQuestions())."',
						plate_durations = '".addslashes($Test->getPlateDurations())."',
						min_score = '".addslashes($Test->getMinScore())."',
						sort_order = '".addslashes($Test->getSortOrder())."',
						mild_score_min = '".addslashes($Test->getMildScoreMin())."',
						mild_score_max = '".addslashes($Test->getMildScoreMax())."',
						mod_score_min = '".addslashes($Test->getModScoreMin())."',
						mod_score_max = '".addslashes($Test->getModScoreMax())."',
						sev_score_min = '".addslashes($Test->getSevScoreMin())."',
						sev_score_max = '".addslashes($Test->getSevScoreMax())."',
						status = '".addslashes($Test->getStatus())."',
						allow_mobile = '".addslashes($Test->getAllowMobile())."',
						d15 = '".addslashes($Test->getD15())."',
						test_price = '".addslashes($Test->getTestPrice())."',
						allow_deficiency = '".addslashes($Test->getAllowDeficiency())."',
						calculate_result = '".addslashes($Test->getCalculateResult())."',
						application_type = '".addslashes($Test->getApplicationType())."',
						max_demo_plate = '".addslashes($Test->getMaxDemoPlates())."'
   					 WHERE test_id = '".$Test->getTestId()."'
					";
				//echo $sql;
				if(!$conn->db_query($sql))
				{
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}


		/**
		 * Delete Test
		 */
		function deleteTest ($TestId)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"DELETE FROM tcv_test
   					 WHERE test_id = $TestId
					";

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


		/**
		 * Get Single Test
		 */
		function getSingleTest ($where_clause = NULL)
		{
			try
			{
				$conn	= new ConnectionPool();

				/*$sql	=
					"SELECT *
					 FROM tcv_test
					 LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id
					 WHERE 
					 tcv_test.test_id = $test_id AND tcv_cms_test.cms_id = $test_id AND tcv_cms_test.language_id  = $languageid";*/
					
				$sql	=
					"SELECT *
					 FROM tcv_test
					 LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id ";
					 
					 
				if($where_clause != NULL){
					$sql .= " WHERE ".$where_clause;
					}
					//echo $sql;
				$result	= $conn->db_query($sql);

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

					$arr = new Test();

					$arr->setTestId(stripslashes($row->test_id));
					$arr->setTestType(stripslashes($row->test_type));
					$arr->setParentId(stripslashes($row->parent_id));
					$arr->setTestGroupId(stripslashes($row->test_group_id));
					$arr->setIsPrivate(stripslashes($row->is_private));
					$arr->setIsCompressed(stripslashes($row->is_compressed));
					$arr->setRandomQuesOrder(stripslashes($row->random_ques_order));
					$arr->setNoOfQuestions(stripslashes($row->no_of_questions));
					$arr->setPlateDurations(stripslashes($row->plate_durations));
					$arr->setMinScore(stripslashes($row->min_score));
					$arr->setSortOrder(stripslashes($row->sort_order));
					$arr->setMildScoreMin(stripslashes($row->mild_score_min));
					$arr->setMildScoreMax(stripslashes($row->mild_score_max));
					$arr->setModScoreMin(stripslashes($row->mod_score_min));
					$arr->setModScoreMax(stripslashes($row->mod_score_max));
					$arr->setSevScoreMin(stripslashes($row->sev_score_min));
					$arr->setSevScoreMax(stripslashes($row->sev_score_max));
					$arr->setStatus(stripslashes($row->status));
					$arr->setAllowMobile(stripslashes($row->allow_mobile));
					$arr->setD15(stripslashes($row->d15));
					$arr->setTestPrice(stripslashes($row->test_price));
					$arr->setAllowDeficiency(stripslashes($row->allow_deficiency));
					$arr->setCalculateResult(stripslashes($row->calculate_result));
					$arr->setApplicationType(stripslashes($row->application_type));
					$arr->setMaxDemoPlates(stripslashes($row->max_demo_plate));
					
					//tcv_cms_test 
					$arr->setTestContId(stripslashes($row->test_cont_id));
					$arr->setCmsType(stripslashes($row->cms_type));
					$arr->setCmsId(stripslashes($row->cms_id));
					$arr->setLanguageId(stripslashes($row->language_id));
					$arr->setTitle(stripslashes($row->title));
					$arr->setSeoTitle(stripslashes($row->seo_title));
					$arr->setDescription(stripslashes($row->description));
					$arr->setPassMessage(stripslashes($row->pass_message));
					$arr->setFailMessage(stripslashes($row->fail_message));
					$arr->setPageLink(stripslashes($row->page_link));
					$arr->setCreateDate(stripslashes($row->create_date));
					$arr->setUpdateDate(stripslashes($row->update_date));
					$arr->setCreatedBy(stripslashes($row->created_by));
					$arr->setUpdatedBy(stripslashes($row->updated_by));
					$arr->setCreatorTypeId(stripslashes($row->creator_type_id));
					$arr->setModifierTypeId(stripslashes($row->modifier_type_id));
					
		
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}

		
		/**
		 * Get Single Test
		 */
		function getSingleTestData ($where_clause = NULL)
		{
			try
			{
				$conn	= new ConnectionPool();
	
				$sql	=
					"SELECT *
					 FROM tcv_test
					 INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id) ";
					 
					 
				if($where_clause != NULL){
					 $sql .= " WHERE ".$where_clause;
					}
					//echo $sql;
				$result	= $conn->db_query($sql);

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

					$arr = new Test();

					$arr->setTestId(stripslashes($row->test_id));
					$arr->setTestType(stripslashes($row->test_type));
					$arr->setParentId(stripslashes($row->parent_id));
					$arr->setTestGroupId(stripslashes($row->test_group_id));
					$arr->setIsPrivate(stripslashes($row->is_private));
					$arr->setIsCompressed(stripslashes($row->is_compressed));
					$arr->setRandomQuesOrder(stripslashes($row->random_ques_order));
					$arr->setNoOfQuestions(stripslashes($row->no_of_questions));
					$arr->setPlateDurations(stripslashes($row->plate_durations));
					$arr->setMinScore(stripslashes($row->min_score));
					$arr->setSortOrder(stripslashes($row->sort_order));
					$arr->setMildScoreMin(stripslashes($row->mild_score_min));
					$arr->setMildScoreMax(stripslashes($row->mild_score_max));
					$arr->setModScoreMin(stripslashes($row->mod_score_min));
					$arr->setModScoreMax(stripslashes($row->mod_score_max));
					$arr->setSevScoreMin(stripslashes($row->sev_score_min));
					$arr->setSevScoreMax(stripslashes($row->sev_score_max));
					$arr->setStatus(stripslashes($row->status));
					$arr->setAllowDeficiency(stripslashes($row->allow_deficiency));
					$arr->setCalculateResult(stripslashes($row->calculate_result));
					$arr->setMaxDemoPlates(stripslashes($row->max_demo_plate));
					$arr->setD15(stripslashes($row->d15));
					
					//tcv_cms_test 
					$arr->setTestContId(stripslashes($row->test_cont_id));
					$arr->setCmsType(stripslashes($row->cms_type));
					$arr->setCmsId(stripslashes($row->cms_id));
					$arr->setLanguageId(stripslashes($row->language_id));
					$arr->setTitle(stripslashes($row->title));
					$arr->setSeoTitle(stripslashes($row->seo_title));
					$arr->setDescription(stripslashes($row->description));
					$arr->setPassMessage(stripslashes($row->pass_message));
					$arr->setFailMessage(stripslashes($row->fail_message));
					$arr->setPageLink(stripslashes($row->page_link));
					$arr->setCreateDate(stripslashes($row->create_date));
					$arr->setUpdateDate(stripslashes($row->update_date));
					$arr->setCreatedBy(stripslashes($row->created_by));
					$arr->setUpdatedBy(stripslashes($row->updated_by));
					$arr->setCreatorTypeId(stripslashes($row->creator_type_id));
					$arr->setModifierTypeId(stripslashes($row->modifier_type_id));
					
		
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}


		 /**
		 * Created by : Mrunal Malusare
		 * Description : To get all Public tests having correct no. of questions exist.
		 * 
		 *  get all Public Tests 
		 **/ 

		function getAllPublicTests ()
		{
			try
			{
				$conn 	= new ConnectionPool();
				
				/*$sql 	= 	"SELECT DISTINCT tcv_cms_test. * , tcv_test.test_type AS test_type, tcv_cms_test.language_id 
								AS language_id FROM tcv_cms_test
							INNER JOIN tcv_test ON tcv_cms_test.cms_id = tcv_test.test_id
							INNER JOIN tcv_question ON tcv_test.no_of_questions <= (
							SELECT count( * )
							FROM tcv_question
							WHERE tcv_test.test_id = tcv_question.test_id )
							WHERE tcv_test.is_private = 'N'
							AND tcv_test.test_type != 'D'
							AND tcv_test.no_of_questions !=0
							AND tcv_test.status = 'A'
							AND tcv_cms_test.cms_type = 'T' ORDER BY tcv_test.sort_order ";*/	//commented by Mrunal M on 23 Nov 11
				$sql 	= 	"SELECT DISTINCT tcv_cms_test. * , tcv_test.test_type AS test_type, tcv_cms_test.language_id 
								AS language_id FROM tcv_cms_test
							INNER JOIN tcv_test ON tcv_cms_test.cms_id = tcv_test.test_id
							INNER JOIN tcv_question ON tcv_test.no_of_questions <= (
							SELECT count( * )
							FROM tcv_question
							WHERE tcv_test.test_id = tcv_question.test_id )
							WHERE tcv_test.is_private = 'N'
							AND tcv_test.test_type != 'D'
							AND tcv_test.no_of_questions !=0
							AND tcv_test.status = 'A'
							AND tcv_cms_test.cms_type = 'T' AND tcv_test.application_type = 'W' ";
							
							if(isset($_SESSION['select_language_id']) && !empty($_SESSION['select_language_id']))
							 $sql .= " AND language_id = '".$_SESSION['select_language_id']."' ";
								
							
							 $sql .= " ORDER BY tcv_test.sort_order ";		//added by Mrunal M on 23 Nov 11		


				
				//echo $sql;
				$result	= $conn->db_query($sql);
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					//throw new UsersTestsException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new Test();
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Get All Test
		 */
		function getAllTest ($startIndex = '',$endIndex = '',$where_clause = NULL,$sort = '',$ordertype = '')
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
						" SELECT * FROM tcv_test
						  LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id
						";

				if($where_clause != NULL){
					$sql .= " WHERE ".$where_clause;}
				
				if($sort != '')	
					$sql .=  "ORDER BY ".$sort." ".$ordertype." LIMIT ".$startIndex.",".$endIndex;
				
				//echo "<br><br><br><br>";
				//echo $sql;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setIsCompressed(stripslashes($row->is_compressed));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowMobile(stripslashes($row->allow_mobile));
						$arr[$count]->setD15(stripslashes($row->d15));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setApplicationType(stripslashes($row->application_type));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						
						
						//tcv_users_tests 
					}

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

		
		function getAllTestNormal ($where_clause)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
						" SELECT * FROM tcv_test
						  LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id
						";

				if($where_clause != NULL){
					$sql .= " WHERE ".$where_clause;}
					
				//echo "<br><br><br><br>";
				//echo $sql;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowMobile(stripslashes($row->allow_mobile));
						$arr[$count]->setD15(stripslashes($row->d15));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setApplicationType(stripslashes($row->application_type));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						
						
						//tcv_users_tests 
					}

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

				$sql 	=
					"SELECT count(*) AS count FROM tcv_test
					 LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id	 
					";

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

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

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

					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Get All Test Count
		 */
		function getAllTestCountData ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
					"SELECT count(*) AS count FROM tcv_test
					 INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id)	 
					";

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

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

					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Get All Test Count
		 */
		function getAllTestWhere ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
					"SELECT * FROM tcv_test
					 INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id)	 
					";

				if($where_clause != NULL)
					 $sql .= " WHERE ".$where_clause;
				//echo $sql.'<br/>';
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setIsCompressed(stripslashes($row->is_compressed));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						$arr[$count]->setD15(stripslashes($row->d15));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						
						
						//tcv_users_tests 
					}
					//print_r($arr);die;
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		function getAllTestBoughtByUser ( $user_id ,$where_clause = NULL )
		{
			try
			{
				$conn 	= new ConnectionPool();

 				
				$sql  =	" SELECT tcv_test.*,tcv_cms_test.* FROM tcv_test
					 INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id)	
					 INNER JOIN tcv_mobile_user_tests_transactions ON ( tcv_mobile_user_tests_transactions.test_id = tcv_test.test_id  AND tcv_mobile_user_tests_transactions.user_id = {$user_id} AND tcv_mobile_user_tests_transactions.status = 'A' )
					  ";
				
				
				
				if($where_clause != NULL)
					 $sql .= " WHERE ".$where_clause;
				//echo $sql."<br />";  exit;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						$arr[$count]->setD15(stripslashes($row->d15));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						
						//tcv_plan
						$arr[$count]->setPlanId(stripslashes($row->plan_id));
						
						
						//tcv_users_tests 
					}
					//print_r($arr);die;
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function getAllDeficiencyTest ($where_clause = NULL,$sort='',$ordertype='')
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
						" SELECT tcv_test.*,
						   tcv_cms_test.*,
						   tcv_dificiency_test_group.color_name,tcv_dificiency_test_group.group_name   
						  FROM tcv_test
						  LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id
						  LEFT JOIN  tcv_dificiency_test_group ON  tcv_dificiency_test_group.group_id   = tcv_test.test_group_id
						";

				if($where_clause != NULL)
					{	
					 $sql .= " WHERE ".$where_clause;
					}
					//echo "<br><br>"; 
				if($sort != NULL)
					$sql .=  "ORDER BY ".$sort." ".$ordertype;
				
				//echo "<br><br><br><br>";
				//echo $sql;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));						
						$arr[$count]->setIsCompressed(stripslashes($row->is_compressed));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						$arr[$count]->setAllowMobile(stripslashes($row->allow_mobile));
						$arr[$count]->setApplicationType(stripslashes($row->application_type));
						$arr[$count]->setD15(stripslashes($row->d15));
						
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						
						//tcv_dificiency_test_group 
						$arr[$count]->setGroupName(stripslashes($row->group_name));
						$arr[$count]->setColorName(stripslashes($row->color_name));
						
						
						
						
					}

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

				/*$sql 	=
					"SELECT count(*) AS count FROM tcv_test
					 LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id	 
					";*/
				$sql 	=
						" SELECT count(*) AS count   
						  FROM tcv_test
						  LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id
						  LEFT JOIN  tcv_dificiency_test_group ON  tcv_dificiency_test_group.group_id   = tcv_test.test_group_id
						";	

				if($where_clause != NULL)
					 $sql .= " WHERE ".$where_clause;
				//echo "<br><br><br><br>";
				//echo  $sql;
				$result	= $conn->db_query($sql);

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

					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function updateTestStatus($status,$id)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_test
					 SET
						tcv_test.status = '".addslashes($status)."'						
   					 WHERE tcv_test.test_id = ".$id."
					";

				$sql1 = "UPDATE tcv_cms_test SET update_date='".date("Y-m-d H:i:s")."' WHERE cms_id=".$id." AND cms_type='T'";

				$sql2 = "UPDATE tcv_question SET update_date='".date("Y-m-d H:i:s")."' WHERE test_id=".$id;

				if(!$conn->db_query($sql))
				{
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				}

				if(!$conn->db_query($sql1))
				{
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				}

				if(!$conn->db_query($sql2))
				{
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/*Function to update dates as per satuts modification.. added by Mrunal on 2 july 12*/
		function updateTestUpdateDateAsPerStatus ($test_id)
		{
			try
			{
				$conn	= new ConnectionPool();
				$date = time();
				$date = strtotime("+1 day", $date);
				$update_date = date('Y-m-d H:i:s',$date);
				 $sql	=
					"UPDATE  tcv_cms_test
						SET update_date = '".$update_date."'
   					 WHERE tcv_cms_test.cms_id  = $test_id AND cms_type = 'T'
					"; 

				
				if(!$conn->db_query($sql))
				{
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function getAllTestChangeOrder ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
						" SELECT * FROM tcv_test
						  LEFT JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id
						";
				if($where_clause != NULL)
					$sql .= " WHERE ".$where_clause;
						
				//echo "<br><br><br><br>";
				//echo $sql;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setIsCompressed(stripslashes($row->is_compressed));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						$arr[$count]->setD15(stripslashes($row->d15));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						
						
						//tcv_users_tests 
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function updateTestOrder ($TestId,$order)
		{
			try
			{
				$conn	= new ConnectionPool();

				  $sql	=
					"UPDATE   tcv_test
						SET tcv_test.sort_order = '$order'
   					 WHERE test_id = $TestId
					"; 

				
				if(!$conn->db_query($sql))
				{
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function getSingleTestFromTestID ($Test_id)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT *
					 FROM tcv_test
					 WHERE test_id=".$Test_id;
                 // echo 'sql'.$sql;
				$result	= $conn->db_query($sql);
				//$data = $conn->db_fetch_object($result);
				//echo 'result'.$data;
				//die($sql);
				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new TestException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					//echo 'rerere';
					$row = $conn->db_fetch_object($result);
                     //echo 'rerere'.$row;exit;
					$arr = new Test();

					$arr->setTestId(stripslashes($row->test_id));
					$arr->setTestType(stripslashes($row->test_type));
					$arr->setParentId(stripslashes($row->parent_id));
					$arr->setTestGroupId(stripslashes($row->test_group_id));
					$arr->setIsPrivate(stripslashes($row->is_private));
					$arr->setIsCompressed(stripslashes($row->is_compressed));
					$arr->setRandomQuesOrder(stripslashes($row->random_ques_order));
					$arr->setNoOfQuestions(stripslashes($row->no_of_questions));
					$arr->setPlateDurations(stripslashes($row->plate_durations));
					$arr->setMinScore(stripslashes($row->min_score));
					$arr->setSortOrder(stripslashes($row->sort_order));
					$arr->setMildScoreMin(stripslashes($row->mild_score_min));
					$arr->setMildScoreMax(stripslashes($row->mild_score_max));
					$arr->setModScoreMin(stripslashes($row->mod_score_min));
					$arr->setModScoreMax(stripslashes($row->mod_score_max));
					$arr->setSevScoreMin(stripslashes($row->sev_score_min));
					$arr->setSevScoreMax(stripslashes($row->sev_score_max));
					$arr->setStatus(stripslashes($row->status));
					$arr->setAllowDeficiency(stripslashes($row->allow_deficiency));
					$arr->setCalculateResult(stripslashes($row->calculate_result));
					$arr->setMaxDemoPlates(stripslashes($row->max_demo_plate));
					$arr->setD15(stripslashes($row->d15));
					
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		function getAllTestDefCount ($where_clause = NULL)
		{
			try
			{//SELECT count(*) AS count FROM tcv_test
				$conn 	= new ConnectionPool();

				$sql 	=
					"
					SELECT count(*) AS count   
						  FROM tcv_test
						  JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id and cms_type = 'T'
						  LEFT JOIN  tcv_dificiency_test_group ON  tcv_dificiency_test_group.group_id   = tcv_test.test_group_id
					";

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

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

					return $row->count;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		//Web Service Get All TEst	
	function getAllTestInfo ($where_clause = NULL,$sort,$ordertype)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
						" SELECT * FROM tcv_test
						  INNER JOIN  tcv_cms_test ON  tcv_cms_test.cms_id  = tcv_test.test_id
						  INNER JOIN  tcv_dificiency_test_group ON  tcv_dificiency_test_group.group_id  = tcv_test.test_group_id
						";

				if($where_clause != NULL){
					$sql .= " WHERE ".$where_clause;}
					
					$sql .=  "ORDER BY ".$sort." ".$ordertype;
				
				//echo "<br><br><br><br>";
				//echo $sql;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setIsCompressed(stripslashes($row->is_compressed));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setD15(stripslashes($row->d15));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setApplicationType(stripslashes($row->application_type));
						
						//tcv_dificiency_test_group 
						$arr[$count]->setGroupName(stripslashes($row->group_name));
						$arr[$count]->setColorName(stripslashes($row->color_name));
						
						
						//tcv_users_tests 
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
			
		}
		
		
		function getAllDefaultTestUnderPlan ($plan_id, $user_id ,$where_clause = NULL )
		{
			try
			{
				$conn 	= new ConnectionPool();
 				
				$sql  =	" SELECT tcv_test.*,tcv_cms_test.* FROM tcv_test
					  INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id)	
					  INNER JOIN  tcv_plan_test ON ( tcv_test.test_id = tcv_plan_test.test_id  && tcv_plan_test.plan_id =  {$plan_id} ) 
					  INNER JOIN tcv_user_plan ON ( tcv_user_plan.user_id = {$user_id} AND tcv_user_plan.plan_id = {$plan_id} AND tcv_cms_test.create_date < tcv_user_plan.create_date )
					  LEFT JOIN  tcv_payment_transaction ON ( tcv_payment_transaction.user_id = {$user_id}  && tcv_payment_transaction.plan_id =  {$plan_id} ) 
					  ";
				
				
				
				if($where_clause != NULL)
					 $sql .= " WHERE ".$where_clause;
				//echo $sql."<br />";  
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						$arr[$count]->setD15(stripslashes($row->d15));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						
						//tcv_plan
						$arr[$count]->setPlanId(stripslashes($row->plan_id));
						
						
						//tcv_users_tests 
					}
					//print_r($arr);die;
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		
		function fnSaveCompressData($intTestId,$strCompressData="",$strExcludeData="")
			{
				
				try
				{
					// Save data
					if($intTestId != "")
					{
						$conn	= new ConnectionPool();
						
						$sqlcnt	="SELECT * FROM tcv_compress_tests WHERE test_id = '$intTestId'";
						$resulttest	= $conn->db_query($sqlcnt);

						if((!$resulttest) || ($conn->db_num_rows($resulttest) == 0))
						{
							$sql	=
								"INSERT INTO tcv_compress_tests
								 (
									test_id,
									compress_test_id,
									exclude_test_id 
								 )
								 VALUES
								 (
									'".addslashes($intTestId)."',
									'".addslashes($strCompressData)."',
									'".addslashes($strExcludeData)."'
								 )
								";
						}
						else
						{
							$sql	= "UPDATE tcv_compress_tests
								 SET
									compress_test_id = '".addslashes($strCompressData)."',
									exclude_test_id = '".addslashes($strExcludeData)."'
								 WHERE test_id = '".$intTestId."'
								";
						}
							//print $sql;
							if(!$conn->db_query($sql))
							{
								throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
							}else
							{
								return true;
							}
					}
				}
				catch(Exception $e)
				{
					throw $e;
				}
			}
			
			function fnGetCompressData($intTestId)
			{
				$arrCompressData = array();
				try
				{
					// Save data
					if($intTestId != "")
					{
						$conn	= new ConnectionPool();

						$sql	="SELECT * FROM tcv_compress_tests WHERE test_id = '$intTestId'";

							if(!$conn->db_query($sql))
							{
								throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
							}else
							{
								
								$result	= $conn->db_query($sql);
								for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
								{
									$arrCompressData[$intTestId]['compress']=stripslashes($row->compress_test_id);
									$arrCompressData[$intTestId]['exclude']=stripslashes($row->exclude_test_id );
								}
							}
					}
				}
				catch(Exception $e)
				{
					throw $e;
				}
				
				return $arrCompressData;
			}
			
			function fnGetCompressCount($intTestId)
			{
					$conn = new ConnectionPool();

					$sql ="SELECT compress_test_id  FROM tcv_compress_tests WHERE test_id = '$intTestId' AND compress_test_id !='' limit 1";

				   if(!$conn->db_query($sql))
				   {
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				   }
				   else
				   {
					$result = $conn->db_query($sql);
					  if(count($result) > 0)
					  {
						return 1;
					  }
					  else
					  {
						return 0;
					  }
					
				   } 
			}
			
			function getAllCompressTestId($intTestId)
			{
				//$arrCompressData = array();
				$strCompressData = "";
				$conn = new ConnectionPool();

					$sql ="SELECT compress_test_id  FROM tcv_compress_tests WHERE test_id = '$intTestId' limit 1";
					//echo $sql;exit;

				   if(!$conn->db_query($sql))
				   {
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				   }
				   else
				   {
					$result = $conn->db_query($sql);
					  for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
						{
							$strCompressData=$row->compress_test_id;
						}
					
				   }
				   return $strCompressData;
			}


			function getAllCompressTestId_self($intTestId)
			{
				//$arrCompressData = array();
				$strCompressData = "";
				$conn = new ConnectionPool();

					$sql ="SELECT compress_test_id  FROM tcv_compress_tests WHERE compress_test_id REGEXP '$intTestId|,$intTestId|$intTestId,|,$intTestId,' limit 1";
					//echo $sql;

				   if(!$conn->db_query($sql))
				   {
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				   }
				   else
				   {
					$result = $conn->db_query($sql);
					  for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
						{
							$strCompressData=$row->compress_test_id;
						}
					
				   }
				   return $strCompressData;
			}
			
			function getAllExcludedTestById($parent_test_id)	//ADDED ON 30 aug 12
			{
				//$arrCompressData = array();
				$strExcludeData = "";
				$conn = new ConnectionPool();

					$sql ="SELECT exclude_test_id  FROM tcv_compress_tests WHERE test_id = '$parent_test_id' limit 1";

				   if(!$conn->db_query($sql))
				   {
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				   }
				   else
				   {
					$result = $conn->db_query($sql);
					  for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
						{
							$strExcludeData=$row->exclude_test_id;
						}
					
				   }
				   return $strExcludeData;
			}

			function getAllExcludedTestById_self($parent_test_id)	//ADDED ON 30 aug 12
			{
				//$arrCompressData = array();
				$strExcludeData = "";
				$conn = new ConnectionPool();

					$sql ="SELECT exclude_test_id  FROM tcv_compress_tests WHERE exclude_test_id REGEXP '$parent_test_id|,$parent_test_id|$parent_test_id,|,$parent_test_id,' limit 1";

				   if(!$conn->db_query($sql))
				   {
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				   }
				   else
				   {
					$result = $conn->db_query($sql);
					  for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
						{
							$strExcludeData=$row->exclude_test_id;
						}
					
				   }
				   return $strExcludeData;
			}
			
		
		
		
		function getAllTestUnderPlan ($plan_id, $user_id ,$where_clause = NULL )
		{
			try
			{
				$conn 	= new ConnectionPool();
 				
				$sql  =	" SELECT tcv_test.*,tcv_cms_test.* FROM tcv_test
					 INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id)	
					  INNER JOIN  tcv_plan_test ON ( tcv_test.test_id = tcv_plan_test.test_id  && tcv_plan_test.plan_id =  {$plan_id} ) 
					  INNER JOIN tcv_user_plan ON ( tcv_user_plan.user_id = {$user_id} AND tcv_user_plan.plan_id = {$plan_id} AND tcv_cms_test.create_date < tcv_user_plan.create_date )
					 
					  ";
				
				
				
				if($where_clause != NULL)
					 $sql .= " WHERE ".$where_clause;
				//echo $sql."<br />";  exit;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						$arr[$count]->setD15(stripslashes($row->d15));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						
						//tcv_plan
						$arr[$count]->setPlanId(stripslashes($row->plan_id));
						
						
						//tcv_users_tests 
					}
					//print_r($arr);die;
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		//Parag Added this
			
		function getAllTestUnderBatch ($where_clause = NULL )
		{
			try
			{
				$conn 	= new ConnectionPool();
 				
				$sql  =	" SELECT tcv_test.*,tcv_cms_test.*, is_delete FROM tcv_test
					 INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id)	
					 INNER JOIN  tcv_batch_tests ON ( tcv_test.test_id = tcv_batch_tests.test_id )
					  ";
				
				
				
				if($where_clause != NULL)
					 $sql .= " WHERE ".$where_clause;
				//echo $sql."<br />";  exit;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						$arr[$count]->setD15(stripslashes($row->d15));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						
						//tcv_plan
						$arr[$count]->setPlanId(stripslashes($row->plan_id));
						
						//from tcv_batch_tests
						$arr[$count]->setIsDeletedFromBatch(stripslashes($row->is_delete));	//Added on 24 july 12
						//tcv_users_tests 
					}
					//print_r($arr);die;
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
			
			function getAllTestIdWithoutExclude($intTestId)
			{
				$strExcludeData = "";
				$strAttachedWhereQuery = "";
				$strSendData = "";
				$conn = new ConnectionPool();
				$boolParentIdIsCompressed = "n";
				$sqlCmpress ="SELECT is_compressed  FROM  tcv_test WHERE test_id = '$intTestId' LIMIT 1";
					
				   if(!$conn->db_query($sqlCmpress))
				   {
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				   }
				   else
				   {
					$resultCompress = $conn->db_query($sqlCmpress);
					  for($count = 0; $row = $conn->db_fetch_object($resultCompress); $count ++)
						{
							$boolParentIdIsCompressed=$row->is_compressed;
						}
					
				   }

					$sql ="SELECT exclude_test_id  FROM tcv_compress_tests WHERE test_id = '$intTestId' limit 1";
					
				   if(!$conn->db_query($sql))
				   {
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				   }
				   else
				   {
					$result = $conn->db_query($sql);
					  for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
						{
							$strExcludeData=$row->exclude_test_id;
						}
					
				   }
				   
				   if($strExcludeData != "")
				   {
					$strAttachedWhereQuery = " AND tcv_test.test_id NOT IN($strExcludeData) ";
				   }
				   
				   $sqlWOExcludeData 	=
					"SELECT tcv_test.test_id as gettestid FROM tcv_test
					 INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id)	 
					 WHERE tcv_test.test_type = 'D' AND cms_type = 'T' AND tcv_test.status = 'A' AND tcv_test.parent_id = '$intTestId' $strAttachedWhereQuery
					 ORDER BY tcv_test.test_group_id";
					 
				   if(!$conn->db_query($sqlWOExcludeData))
				   {
					throw new TestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				   }
				   else
				   {
				     $arrResultedData = array();
					$resultWOExcludeData = $conn->db_query($sqlWOExcludeData);
					  for($count = 0; $row = $conn->db_fetch_object($resultWOExcludeData); $count ++)
						{
							$arrResultedData[]=$row->gettestid;
						}
						
						if($boolParentIdIsCompressed == "y")
						{
							$arrCompIds = explode(",", $this->getAllCompressTestId($intTestId));	
						}
						else
						{
							$arrCompIds = array();
						}

						$arrResultedData = array_unique(array_merge($arrCompIds,$arrResultedData));
							//@asort($arrResultedData);

						$strSendData = implode(",",$arrResultedData);
				   }
				   return $strSendData;
			}
			
		function getAllDefaultTestBoughtByUser ( $user_id ,$where_clause = NULL )
		{
			try
			{
				$conn 	= new ConnectionPool();

 				
				$sql  =	" SELECT tcv_test.*,tcv_cms_test.* FROM tcv_test
					 INNER JOIN  tcv_cms_test ON  (tcv_cms_test.cms_id  = tcv_test.test_id)	
					 INNER JOIN tcv_mobile_user_tests_transactions ON ( tcv_mobile_user_tests_transactions.test_id = tcv_test.test_id  AND tcv_mobile_user_tests_transactions.user_id = {$user_id} AND tcv_mobile_user_tests_transactions.status = 'A' )
					  ";
				
				
				
				if($where_clause != NULL)
					 $sql .= " WHERE ".$where_clause;
				//echo $sql."<br />";  exit;
				$result	= $conn->db_query($sql);

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

						$arr[$count]->setTestId(stripslashes($row->test_id));
						$arr[$count]->setTestType(stripslashes($row->test_type));
						$arr[$count]->setParentId(stripslashes($row->parent_id));
						$arr[$count]->setTestGroupId(stripslashes($row->test_group_id));
						$arr[$count]->setIsPrivate(stripslashes($row->is_private));
						$arr[$count]->setRandomQuesOrder(stripslashes($row->random_ques_order));
						$arr[$count]->setNoOfQuestions(stripslashes($row->no_of_questions));
						$arr[$count]->setPlateDurations(stripslashes($row->plate_durations));
						$arr[$count]->setMinScore(stripslashes($row->min_score));
						$arr[$count]->setSortOrder(stripslashes($row->sort_order));
						$arr[$count]->setMildScoreMin(stripslashes($row->mild_score_min));
						$arr[$count]->setMildScoreMax(stripslashes($row->mild_score_max));
						$arr[$count]->setModScoreMin(stripslashes($row->mod_score_min));
						$arr[$count]->setModScoreMax(stripslashes($row->mod_score_max));
						$arr[$count]->setSevScoreMin(stripslashes($row->sev_score_min));
						$arr[$count]->setSevScoreMax(stripslashes($row->sev_score_max));
						$arr[$count]->setStatus(stripslashes($row->status));
						$arr[$count]->setAllowDeficiency(stripslashes($row->allow_deficiency));
						$arr[$count]->setCalculateResult(stripslashes($row->calculate_result));
						$arr[$count]->setMaxDemoPlates(stripslashes($row->max_demo_plate));
						$arr[$count]->setD15(stripslashes($row->d15));
						
						//tcv_cms_test 
						$arr[$count]->setCmsType(stripslashes($row->cms_type));
						$arr[$count]->setCmsId(stripslashes($row->cms_id));
						$arr[$count]->setLanguageId(stripslashes($row->language_id));
						$arr[$count]->setTitle(stripslashes($row->title));
						$arr[$count]->setSeoTitle(stripslashes($row->seo_title));
						$arr[$count]->setDescription(stripslashes($row->description));
						$arr[$count]->setPassMessage(stripslashes($row->pass_message));
						$arr[$count]->setFailMessage(stripslashes($row->fail_message));
						$arr[$count]->setPageLink(stripslashes($row->page_link));
						$arr[$count]->setCreateDate(stripslashes($row->create_date));
						$arr[$count]->setUpdateDate(stripslashes($row->update_date));
						$arr[$count]->setCreatedBy(stripslashes($row->created_by));
						$arr[$count]->setUpdatedBy(stripslashes($row->updated_by));
						$arr[$count]->setCreatorTypeId(stripslashes($row->creator_type_id));
						$arr[$count]->setModifierTypeId(stripslashes($row->modifier_type_id));
						$arr[$count]->setTestPrice(stripslashes($row->test_price));
						
						//tcv_plan
						$arr[$count]->setPlanId(stripslashes($row->plan_id));
						
						
						//tcv_users_tests 
					}
					//print_r($arr);die;
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}		
	}
	/**
	 * End of class TestManager
	 */
?>
