<?php
	/**
	 * CmsTestManager.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:10:08
	 *
	 * Created By 	: Rohit Soni
	 *
	 */

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

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

	/**
	 * Start of class CmsTestManager
	 */
	class CmsTestManager
	{
		/**
		 * Add CmsTest
		 */
		function addCmsTest ($CmsTest)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"INSERT INTO tcv_cms_test
					 (
						test_cont_id,
						cms_type,
						cms_id,
						language_id,
						title,
						seo_title,
						description,
						pass_message,
						fail_message,
						page_link,
						create_date,
						update_date,
						created_by,
						updated_by,
						creator_type_id,
						modifier_type_id
					 )
					 VALUES
					 (
						'".addslashes($CmsTest->getTestContId())."',
						'".addslashes($CmsTest->getCmsType())."',
						'".addslashes($CmsTest->getCmsId())."',
						'".addslashes($CmsTest->getLanguageId())."',
						'".addslashes($CmsTest->getTitle())."',
						'".addslashes($CmsTest->getSeoTitle())."',
						'".addslashes($CmsTest->getDescription())."',
						'".addslashes($CmsTest->getPassMessage())."',
						'".addslashes($CmsTest->getFailMessage())."',
						'".addslashes($CmsTest->getPageLink())."',
						'".addslashes($CmsTest->getCreateDate())."',
						'".addslashes($CmsTest->getUpdateDate())."',
						'".addslashes($CmsTest->getCreatedBy())."',
						'".addslashes($CmsTest->getUpdatedBy())."',
						'".addslashes($CmsTest->getCreatorTypeId())."',
						'".addslashes($CmsTest->getModifierTypeId())."'
					 )
					";

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


		/**
		 * Update CmsTest
		 */
		function updateCmsTest ($CmsTest)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"UPDATE tcv_cms_test
					 SET
						cms_type = '".addslashes($CmsTest->getCmsType())."',
						cms_id = '".addslashes($CmsTest->getCmsId())."',
						language_id = '".addslashes($CmsTest->getLanguageId())."',
						title = '".addslashes($CmsTest->getTitle())."',
						seo_title = '".addslashes($CmsTest->getSeoTitle())."',
						description = '".addslashes($CmsTest->getDescription())."',
						pass_message = '".addslashes($CmsTest->getPassMessage())."',
						fail_message = '".addslashes($CmsTest->getFailMessage())."',
						page_link = '".addslashes($CmsTest->getPageLink())."',
						create_date = '".addslashes($CmsTest->getCreateDate())."',
						update_date = '".addslashes($CmsTest->getUpdateDate())."',
						created_by = '".addslashes($CmsTest->getCreatedBy())."',
						updated_by = '".addslashes($CmsTest->getUpdatedBy())."',
						creator_type_id = '".addslashes($CmsTest->getCreatorTypeId())."',
						modifier_type_id = '".addslashes($CmsTest->getModifierTypeId())."'
   					 WHERE test_cont_id = '".$CmsTest->getTestContId()."'
					";

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


		/**
		 * Delete CmsTest
		 */
		function deleteCmsTest ($TestContId)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"DELETE FROM tcv_cms_test
   					 WHERE test_cont_id = $TestContId
					";

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


		/**
		 * Get Single CmsTest
		 */
		function getSingleCmsTest ($test_cont_id)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT *
					 FROM tcv_cms_test
					 WHERE test_cont_id = $test_cont_id
					";

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

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

					$arr = new CmsTest();

					$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 All CmsTest
		 */
		function getAllCmsTest ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

				$sql 	=
							"	SELECT *
								FROM tcv_cms_test";

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

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

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

						$arr[$count]->setTestContId(stripslashes($row->test_cont_id));
						$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));
					}

					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		function getSingleCmsTestFromTestID ($testid)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT *
					 FROM tcv_cms_test
					 WHERE cms_id = $testid
					";

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

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

					$arr = new CmsTest();

					$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 All CmsTest Count
		 */
		function getAllCmsTestCount ($where_clause = NULL)
		{
			try
			{
				$conn 	= new ConnectionPool();

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

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

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

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new CmsTestException(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 getSingleCmsTestQuestion ($where_clause = NULL)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT *
					 FROM tcv_cms_test
					";
					
					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 CmsTestException(mysql_errno($conn->connection),mysql_error($conn->connection));
					return array();
				}
				else
				{
					$row = $conn->db_fetch_object($result);

					$arr = new CmsTest();

					$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;
			}
		}
		
		
		
		function getSingleCmsAnswer($where_clause = NULL)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT *
					 FROM tcv_cms_test
					";
				if($where_clause != NULL)
					$sql .= " WHERE ".$where_clause;

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

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

					$arr = new CmsTest();

					$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;
			}
		}
		
		
		function updateTestsAnswersText($description,$updated_by,$modifier_type_id,$CmsAnsId,$LangId)
		{
			try
			{
				$conn	= new ConnectionPool();

				  $sql	=
					"UPDATE tcv_cms_test
					 SET
						description = '".$description."',
						update_date = '".date('Y-m-d H:i:s')."',
						updated_by = ".$updated_by.",
						modifier_type_id = ".$modifier_type_id."
   					 WHERE cms_id = ".$CmsAnsId." and language_id = ".$LangId."  and cms_type = 'A'
					";

				if(!$conn->db_query($sql))
				{
					throw new CmsTestException(mysql_errno($conn->connection),mysql_error($conn->connection));
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		 /**
		 * Created by : Rajesh Gite
		 * Description : Get All Answers of Question
		 * Parameters : condition
		 * Get All Answers
		 */
		
		function getSingleQuestionAnswersText ($where_clause = NULL)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT cms. * , q. * , a.image_path as image_path, a.is_correct as is_correct, a.test_answers_id as test_answer_id
					FROM `tcv_cms_test` AS cms, tcv_question AS q, tcv_tests_answers AS a
					WHERE test_answers_id = cms_id
					AND cms_type = 'A' AND q.question_id = a.question_id 
					";/*AND a.image_path = ''*/
				
				if($where_clause != NULL)
					$sql .= $where_clause;
			//	die($sql);	
			//echo $sql."<br>";	
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new CmsTestException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new CmsTest();
						$arr[$count]->setTestContId(stripslashes($row->test_cont_id));
						$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]->setTestAnswersId(stripslashes($row->test_answer_id));
						$arr[$count]->setImagePath(stripslashes($row->image_path));
						$arr[$count]->setIsCorrect(stripslashes($row->is_correct));
					}
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}
		
		/**
		 * Created by : Rajesh Gite
		 * Description : Get All Answers of Question
		 * Parameters : (int) question_id
		 * Get All Answers
		 */
		
		function getSingleQuestionAnswersImage ($question_id)
		{
			try
			{
				$conn	= new ConnectionPool();

				$sql	=
					"SELECT  a.*
					FROM tcv_tests_answers AS a ";
				
				if($question_id != NULL)
					$sql .= " WHERE question_id = ".$question_id."  ORDER BY RAND()";	//added  ORDER BY RAND() on 2 Nov 11
			//	die($sql);	
			//echo $sql."<br>";	
				$result	= $conn->db_query($sql);

				if((!$result) || ($conn->db_num_rows($result) == 0))
				{
					throw new CmsTestException(mysql_errno($conn->dbLink),mysql_error($conn->dbLink));
					return array();
				}
				else
				{
					for($count = 0; $row = $conn->db_fetch_object($result); $count ++)
					{
						$arr[$count] = new CmsTest();
						$arr[$count]->setTestContId(stripslashes($row->test_cont_id));
						$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]->setTestAnswersId(stripslashes($row->test_answers_id));
						$arr[$count]->setImagePath(stripslashes($row->image_path));
						$arr[$count]->setIsCorrect(stripslashes($row->is_correct));
					}
					return $arr;
				}
			}
			catch(Exception $e)
			{
				throw $e;
			}
		}

	}
	/**
	 * End of class CmsTestManager
	 */
?>
