<?php 
class adminhome_model extends Model
{
	
	function gUpdate($tableName,$where,$qData)
		{	
			foreach($where as $col=>$val)
				$this->db->where($col,$val);		
			$this->db->update($tableName,$qData);		
		}
	
//=========================== End  dActor Queries


	function countITMOVIESTop()
		{
			$query=$this->db->query(" select * from movie as M HAVING 60 <= (select AVG(AMOUNT) as SG from rating_movie as RM where RM.ITEM = M.movieId and MEMBER = '0' ) ");
			return $query->num_rows();
		}

	function getITMOVIESTop($OB,$offset,$per_page)
		{
			$query=$this->db->query(" select * from movie as M HAVING 60 <= (select AVG(AMOUNT) as SG from rating_movie as RM where RM.ITEM = M.movieId and MEMBER = '0' ) order by $OB desc limit $offset,$per_page ");
			return $query->result_array();
		}



	function countITMOVIES()
		{
			$query=$this->db->query(" select * from  movie where it = '1' ");
			return $query->num_rows();
		}

	function getITMOVIES($OB,$offset,$per_page)
		{
			$query=$this->db->query(" select * from  movie where it = '1' order by $OB desc limit $offset,$per_page ");
			return $query->result_array();
		}

	function countAllGuideCommentCount($gID)
		{
			$query=$this->db->query(" select * from guidecomments as GC, users as U where GC.userID = U.userID and gID = '$gID' ");
			return $query->num_rows();
		}

	function getAllMoviesFromGuide1234($gID,$offset,$per_page)
		{
			$query=$this->db->query(" select * from guidecomments as GC, users as U where GC.userID = U.userID and gID = '$gID' limit $offset,$per_page");
			return $query->result_array();
		}



	function countAllGuideMovies($gID)
		{
			$query=$this->db->query(" select * from guide as G, movie_guide as MG, movie as M where G.gID = MG.gID and MG.gID = '$gID' and MG.movieId = M.movieId ");
			return $query->num_rows();
		}

	function getAllMoviesFromGuide($gID,$offset,$per_page)
		{
			$query=$this->db->query(" select * from guide as G, movie_guide as MG , movie as M where G.gID = MG.gID and MG.gID = '$gID'  and MG.movieId = M.movieId  order by MG.mgRank desc limit $offset,$per_page ");
			return $query->result_array();
		}

	function getAllMovie()
		{
			$query=$this->db->query(" select * from movie ");
			return $query->num_rows();
		}
	
	function getMoviesForBO($OB,$offset,$per_page)
		{
			$query=$this->db->query(" select * from movie order by $OB desc limit $offset,$per_page ");
			return $query->result_array();
		}


	function getNewsCritics($commentId,$offset,$per_page)
		{
			
			$query=$this->db->query("select * from commentreply as CC, users as U where CC.userID = U.userID and CC.commentId = '$commentId'  order by insertTime desc limit $offset,$per_page ");
			
			return $query->result_array();
		}

		function getFeatureCritics($commentId,$offset,$per_page)
		{
			
			$query=$this->db->query("select * from commentreply as CC, users as U where CC.userID = U.userID and CC.commentId = '$commentId'  order by insertTime desc limit $offset,$per_page ");
			
			return $query->result_array();
		}


		function getColCritics($commentId,$offset,$per_page)
		{
			
			$query=$this->db->query("select * from commentreply as CC, users as U where CC.userID = U.userID and CC.commentId = '$commentId' order by insertTime desc limit $offset,$per_page ");
			
			return $query->result_array();
		}

		
		function getMovieCritics($cID,$offset,$per_page)
		{
			
			$query=$this->db->query(" select * from cretics_comments as CC, users as U where CC.userID = U.userID and CC.cID = '$cID' ");
			
			return $query->result_array();
		}

	function getSearchResultUser($q,$fn)
		{
			$query=$this->db->query(" select * from users where $fn like '%$q%'");
			return $query->result_array();
		}
	
	function getSearchResultMovie($q)
		{
			$query=$this->db->query(" select * from movie where movieName like '%$q%'  ");
			return $query->result_array();
		}
		
		
	function getSearchResultActor($q)
		{
			$query=$this->db->query(" select * from actor where actorName like '$q%' and gender='actor' ");
			return $query->result_array();
		}
		
	function getSearchResultActress($q)
		{
			$query=$this->db->query(" select * from actor where actorName like '$q%' and gender='actress' ");
			return $query->result_array();
		}
		
	function getSearchResultsinger($q)
		{
			$query=$this->db->query(" select * from actor where actorName like '$q%' and gender='singer' ");
			return $query->result_array();
		}
		
	function getSearchResultartist($q)
		{
			$query=$this->db->query(" select * from actor where actorName like '$q%' and gender='artist' ");
			return $query->result_array();
		}
	
	function getSearchResultdirector($q)
		{
			$query=$this->db->query(" select * from actor where actorName like '$q%' and gender='director' ");
			return $query->result_array();
		}
	
	function getMovieData($f,$as,$offset,$per_page)
		{
			$query=$this->db->query(" select * from movie order by $f $as limit $offset,$per_page ");
			return $query->result_array();		
		}
	
	function getUserArticleCount($userID)
		{
			$query=$this->db->query(" select * from article where userID = '$userID' ");
			return $query->num_rows();		
		}
	
	function getAllUserArticles($userID,$offset,$per_page)
		{
			//echo "select * from article where userID = '$userID' limit $offset,$per_page";
			$query=$this->db->query(" select * from article where userID = '$userID' order by aID desc limit $offset,$per_page ");
			return $query->result_array();		
		
		}
		
	function getUserPhotoCount($userID)
		{
			$query=$this->db->query(" select * from photos where userID = '$userID' ");
			return $query->num_rows();		
		}


	function getAllUserPhoto($userID,$offset,$per_page)
		{
			//echo "select * from article where userID = '$userID' limit $offset,$per_page";
			$query=$this->db->query(" select * from photos where userID = '$userID' order by insertTime desc limit $offset,$per_page ");
			return $query->result_array();		
		
		}

	
	function insertTheBannerDetails($data)
	{
		$this->db->insert('banner', $data); 
		$a = $this->db->insert_id();
		return $a;		

	}

	function updateTheBannerDetails($data)
	{
		$this->db->where('bannerID', $data['bannerID']);
		$this->db->update('banner', $data); 
	}

	
	function getRssData()
		{
		
			$query=$this->db->query(" select * from news order by insertTime desc ");
			return $query->result_array();
		
		}
	
	function gInsert($tableName,$qData)
		{
			$this->db->insert($tableName, $qData); 
			return $ID = $this->db->insert_id();	
		}
		
	function getAllBlogsSortName($offset,$per_page)
		{
			$query=$this->db->query(" select * from blog  order by bInsertTime desc limit $offset,$per_page ");
			return $query->result_array();
		}	
		
	function getLoadData($type,$offset,$per_page)
		{
			$query=$this->db->query(" select * from loan where loanType ='$type' order by status, insertTime limit $offset,$per_page ");
			return $query->result_array();
		}
	
	function countLoan($type)
		{
		$query=$this->db->query(" select * from loan where loanType = '$type' ");
		return $query->num_rows();		
		}


	function getNewsData($type,$offset,$per_page)
		{
			$query=$this->db->query(" select * from news limit $offset,$per_page ");
			return $query->result_array();
		}
	
	function countNews($type)
		{
		$query=$this->db->query(" select * from news  ");
		return $query->num_rows();		
		}

	function getArticleData($type,$offset,$per_page)
		{
			$query=$this->db->query(" select * from article order by aID desc limit $offset,$per_page ");
			return $query->result_array();
		}
	
	function countArticle($type)
		{
		$query=$this->db->query(" select * from article  ");
		return $query->num_rows();		
		}
		
		
		
		function getFeaturesData($type,$offset,$per_page)
		{
			$query=$this->db->query(" select * from features order by featureID desc limit $offset,$per_page ");
			return $query->result_array();
		}
	
	function countFeatures($type)
		{
		$query=$this->db->query(" select * from features  ");
		return $query->num_rows();		
		}
		
		
		
		function countColumn($type)
		{
		$query=$this->db->query(" select * from newscolumn where pID = '0' ");
		return $query->num_rows();		
		}
		
		
		function getColumnData($type,$offset,$per_page)
		{
			$query=$this->db->query(" select * from newscolumn  where pID = '0' order by colID desc limit $offset,$per_page ");
			return $query->result_array();
		}
	

	function countActor($type)
		{
		$query=$this->db->query(" select * from actor  ");
		return $query->num_rows();		
		}
	
		function getActorData($type,$offset,$per_page)
		{
			$query=$this->db->query(" select * from article limit $offset,$per_page ");
			return $query->result_array();
		}
	
	function checkRelatedRelation($catID)
	{
		
		$query=$this->db->query(" select * from relateitem limit 1 ");
		foreach($query->result_array() as $row)
			$relCat = $row['itemData'];
		
		$SG = explode('|',$relCat);
		foreach($SG as $row5)
			if($row5 == $catID)
				 return TRUE;   
		
		return FALSE;	
	}
	
	function countSearchRows($key)
		{
		
		$query=$this->db->query(" select * from audio where aName like '$key%' ");
		return $query->num_rows();		
		}

	function countASearchRows($c1,$c2,$c3,$c4)
		{
		
		$query=$this->db->query(" select * from audio $c1 $c2 $c3 $c4   ");
		return $query->num_rows();		
		}

	function countASearchResult($c1,$c2,$c3,$c4,$offset,$per_page)
		{
		//echo "select * from audio $c1 $c2 $c3 $c4 limit $offset,$per_page";
			$query=$this->db->query(" select * from audio $c1 $c2 $c3 $c4 limit $offset,$per_page  ");
			return $query->result_array();
		
		
		}

	
	function countSearchResult($key,$offset,$per_page)
		{
		$query=$this->db->query(" select * from audio where aName like '$key%' limit $offset,$per_page  ");
		return $query->result_array();
		
		
		}
		
		
		function countmovie($movieId)
		{
		$query=$this->db->query(" select * from movie  ");
		return $query->num_rows();		
		}
	
		function getMovie($movieId,$offset,$per_page)
		{
			$query=$this->db->query(" select * from movie limit $offset,$per_page ");
			return $query->result_array();
		}
	
function getMovie1()
{
			$query=$this->db->query(" select * from movie ");
			return $query->result_array();
		}
	
	
	
	function countMemberRows()
		{
		$query=$this->db->query(" select * from users ");
		return $query->num_rows();		
		}
	
	function countCommRows()
		{
		$query=$this->db->query(" select * from users as U, audio as A, mcomments as C where C.aID = A.aID and U.userID = C.userID order by ratetime desc  ");
		return $query->num_rows();		
		
		}
	
	function getAllUse($offset,$per_page)
		{
		$query=$this->db->query(" select * from users limit $offset,$per_page ");
		return $query->result_array();
		
		
		}

	function getCommentS($offset,$per_page)
		{
		$query=$this->db->query(" select * from users as U, audio as A, mcomments as C where C.aID = A.aID and U.userID = C.userID order by ratetime desc limit $offset,$per_page ");
		return $query->result_array();
		
		
		}


	
	function checkFvtVideo($aID,$userID)
		{
		
		$query=$this->db->query(" select * from fvt where aID = '$aID' and userID = '$userID' ");
		foreach($query->result_array() as $row)
			return TRUE;
		return FALSE;	
		
		}
	
	function insertIntoFvtList($aID,$userID)
		{
			$data['aID'] = $aID;
			$data['userID'] = $userID;
			$data['insertTime'] = time();
			$insert = $this->db->insert('fvt',$data);
		}
	
	function insertIntoactmovie($data)
		{
			$data['actorId'] = $actorId;
			$data['movieId'] = $movieId;
			$data['movieActor'] = $movieActor;
			$data['insertTime'] = time();
			$insert = $this->db->insert('actormovie',$data);
		}
	
	
	function insertMovieTrack($data)
		{
			$this->db->insert('movietrack',$data);
			return $this->db->insert_id();	
		}
	
	function insertIntoPayment($data)
		{
			$this->db->insert('payment',$data);
			return $this->db->insert_id();	
		}
	
	function addProfile($data)
		{
			$this->db->insert('profile',$data);
		}

	function insertImage($data)
		{
			$this->db->insert('gallery',$data);
		}
	
	function editProfile($pID,$data)
		{
		
			$this->db->where('pID',$pID);		
			$this->db->update('profile',$data);		
		}
	
	function getListingOwner($LID)
		{
		
		$query=$this->db->query(" select * from listingsdb as LD, users as U where LD.userdb_id = U.userID and LD.listingsdb_id = '$LID' ");
		foreach($query->result_array() as $row5	)
			return $row5['emailAdd'];
		
		}
	
	function getCountryfromid($id)
		{
		$query=$this->db->query(" select * from country where cID = '$id' ");
		foreach($query->result_array() as $row5	)
			return $row5['cName'];
		}
	
	function deleteAffiliateSite($siteID)
		{
		$q1=$this->db->query(" select * from listingsdb where siteID = '$siteID' ");
			foreach($q1->result_array() as $row1)
				{

					$q3 =$this->db->query(" select * from listingimages where LID = '$row1[listingsdb_id]' ");		
						foreach($q3->result_array() as $row3)
							{
							$NAME = $row3['fileName'];
							$q2=$this->db->query(" delete from listingimages where  imageID  = '$row3[imageID]' ");
							$CWD = getcwd();
							$FN = $CWD."/listingImages/".$NAME;
							unlink($FN);
							}
							
					$q4=$this->db->query(" delete from listingsdbelements where  listingsdb_id = '$row1[listingsdb_id]' ");
							
				}
		$q5=$this->db->query(" delete from affiliatesite where  siteID = '$siteID' ");

		}
	
	function insertIntoListingCatTable($cat,$LID)
		{
		foreach($cat as $row5)
		$query=$this->db->query(" INSERT INTO `listingcategory` ( `lcID` , `LID` , `catID` )VALUES (NULL, '$LID', '$row5'); ");
		}

	function getAllSubAdmin()
		{
		$query=$this->db->query(" select * from subadmin order by insertTime ");
		return $query->result_array();	
		}
	
	function getReview($rID)
		{
		$query=$this->db->query(" select * from review where rID = '$rID' ");
		return $query->result_array();	
		
		}

	function editReview($RID,$review)
		{
		$query=$this->db->query(" update review set reviewDetails = '$review' where rID = '$RID' ");
		}

	function getListingReview($LID)
	{
	
		$query=$this->db->query(" select * from listingsdb as LD, review as R where listingsdb_id = '$LID' and LD.listingsdb_id = R.LID ");
		return $query->result_array();	
	
	}
	
	function getListingReviewPending($LID)
	{
	
		$query=$this->db->query(" select * from listingsdb as LD, review as R where listingsdb_id = '$LID' and LD.listingsdb_id = R.LID and R.approvedByAdmin = '0' ");
		return $query->result_array();	
	}
	
	
	function deleteReview($LID,$rID)
		{
		
		$query=$this->db->query(" delete from review where LID = '$LID' and rID = '$rID' ");
		
		}
	
	function addReview($LID,$review)
		{
		
		$TT = time();
		$query=$this->db->query(" INSERT INTO `review` ( `rID` , `reviewDetails` , `timeStamp` , `approvedByAdmin` , `approvedByOwner` , `LID`, `siteID` ) VALUES (NULL, ' $review', '$TT', '0', '0', '$LID','000'); ");
		
		}

	function getListingReviewPendingUser($LID)	
	{
	
		$query=$this->db->query(" select * from listingsdb as LD, review as R where listingsdb_id = '$LID' and LD.listingsdb_id = R.LID and R.approvedByOwner = '0' ");
		return $query->result_array();	
	}

	function acceptRevieOwner($rID)
		{
		$query=$this->db->query(" update review set approvedByOwner = '1' where rID = '$rID'  ");
		$query=$this->db->query(" select * from review where rID = '$rID'  ");
			foreach($query->result_array() as $row5)
				return $row5['LID'];	

		}

	function getListingMainCategory($LID)
		{
		$query=$this->db->query(" select * from listingsdb where listingsdb_id = '$LID'  ");
			foreach($query->result_array() as $row5)
				return $row5['categoryID'];	
		}

	function deleteRevieOwner($rID)
		{
			$query=$this->db->query(" select * from review where rID = '$rID'  ");
			foreach($query->result_array() as $row5)
				$XX =  $row5['LID'];	
			$query=$this->db->query(" delete from review where rID = '$rID' ");		
			return $XX;
		}

	function acceptReview($LID,$rID)
		{
		$query=$this->db->query(" update review set approvedByAdmin = '1' where rID = '$rID' and LID = '$LID' ");
		
		}
	
	
	function GetEmailtemplate($id)
	{
		$query=$this->db->query(" select * from listingsdb as LD, users as U where listingsdb_id = '$id' and LD.listingsdb_id = U.userID ");
		foreach($query->result_array() as $row)
			return $row['emailAdd']; 	
	}
	
	function getUserEmailAddress($uid)
	{
		$query=$this->db->query(" select * from emailtemplate where id = '$id' ");
		return $query->result_array(); 	
	}
		
	function getUserEmailAddress55($userdb_id)
	{
		$query=$this->db->query(" select * from users as U,listingsdb as LD where U.userID = LD.userdb_id and userdb_id = '$userdb_id' ");
		foreach($query->result_array() as $row5)
			return $row5['emailAdd']; 	
	}
		
	function updateRelate($data5)
	{
		$this->db->where('id', '5'); 
		$this->db->update('relateitem', $data5); 
	}
	
	function updateSite($data5,$siteID)
	{
		$this->db->where('siteID', $siteID ); 
		$this->db->update('affiliatesite', $data5); 
	}

	function addSite($data5)
	{
		$this->db->insert('affiliatesite', $data5); 
	}



	function insertEmailTemplate($name,$details,$when)
	{
		$query=$this->db->query(" INSERT INTO `emailtemplate` (`id`, `name`, `details`, `sendWhen`) VALUES (NULL, '$name', '$details', '$when'); ");	
	}
	
	function insertEmailTemplate11($name1,$name2,$name3,$name4,$details1,$details2,$details3,$details4,$when)
	{
		$query=$this->db->query(" INSERT INTO `emailtemplate` (`id`, `name_english`, `name_swedish`, `name_spanish`, `name_german`, `details_english`, `details_swedish`, `details_spanish`, `details_german`, `sendWhen`) VALUES (NULL, '$name1', '$name2', '$name3', '$name4', '$details1', '$details2', '$details3', '$details4', '$when'); ");	
	}
	
	
	function deleteEmailTemplate($id)
	{
		$query=$this->db->query(" delete from emailtemplate where id = '$id' ");	
	}
	
	function getRelationDetails()
	{
		$query=$this->db->query(" select * from relateitem limit 1 ");
		return $query->result_array(); 
	}

	function getAdministratorLoingInfo()
	{
		$query=$this->db->query("Select * from adminsettings");
		return $query->result_array(); 
	}
	function getSubAdministratorLoingInfo5($userName,$MDFP)
	{
		$query=$this->db->query("Select * from subadmin where subUsername= '$userName' and  subPassword= '$MDFP'");
		return $query->result_array(); 
	
	}

	function getSubAdministratorLoingInfo($userID)
	{
		//echo "Select * from subadmin where subAdminID = '$userID'";
		$query=$this->db->query("Select * from subadmin where subAdminID = '$userID'");
		return $query->result_array(); 
	}


	function updateSubPassword($userName,$NEWPASS,$language,$adminEmail)
	{
		$userID = $this->session->userdata('userID');
		$query=$this->db->query(" UPDATE subadmin SET subPassword='$NEWPASS',adminEmail = '$adminEmail' where subAdminID='$userID' ");
	}
	
	
	function updatePassword($userName,$NEWPASS,$language,$adminEmail)
	{
		$query=$this->db->query(" UPDATE adminsettings SET username='$userName',password='$NEWPASS',language='$language' ,adminEmail = '$adminEmail' where asid='1' ");
	}
	
	function getSelectedCategoryForListings($LID)
		{
		
		$query=$this->db->query(" select * from listingcategory as LC,category as C where LC.catID = C.catID  and LID = '$LID' group by C.catID ");
		return $query->result_array(); 
		}
	
	
	function getSiteDetails()
	{
		$query=$this->db->query(" select * from siteconfiguration limit 1 ");
		return $query->result_array(); 
	}
	
	function getLocationDetails($pID)
		{
		$query=$this->db->query(" select * from country where pID = '$pID' ");
		return $query->result_array(); 
		}
	
	function updateListingLocation($pID,$LID)
	{
		$query=$this->db->query(" update listingsdb set cID = '$pID' where listingsdb_id = '$LID' ");
	}
	
	function updateSiteDetails($data5)
	{
	
		$query=$this->db->query(" update siteconfiguration set bankName='$data5[bankName]' ,viewListing='$data5[viewListing]' ,userRegistration='$data5[userRegistration]' ,acNo='$data5[acNo]' ,branchName='$data5[branchName]' ,branchAddress='$data5[branchAddress]' ,city='$data5[city5]' ,country='$data5[country]' ,visitUrl='$data5[visitUrl]',regFees='$data5[regFees]',template='$data5[template]', paypalPayment ='$data5[paypalPayment]', paypalid='$data5[paypalid]', mbid = '$data5[mbid]', moneyBookerPayment ='$data5[moneyBookerPayment]', bankWirePayemnt ='$data5[bankWirePayemnt]', showReview = '$data5[showReview]', googleMapKey = '$data5[googleMapKey]' , showHits = '$data5[showHits]', homeTemplate = '$data5[homeTemplate]', LON = '$data5[LON]', LAT = '$data5[LAT]' , ZOOM = '$data5[ZOOM]', displayAdsType = '$data5[displayAdsType]', noOfAds = '$data5[noOfAds]', imgPixel = '$data5[imgPixel]', shoImg = '$data5[shoImg]', askContact = '$data5[askContact]', frontLang ='$data5[frontLang]'   where confID = '1' ");
	}
	
	function getAllAffiliateSite()
	{
		$query=$this->db->query(" select * from affiliatesite");
		return $query->result_array(); 
	
	}
	
	//--------- Menu Management
	
		
	function checkMenuStatus($type)
	{
		$query=$this->db->query(" select * from menuitemsetting where ID = '1' ");
/*		echo "row[\"$type\"]; 		";
		exit;*/
		foreach($query->result_array() as $row)
				return $row["$type"]; 		
	}


	
	function channgeMenuStatus($type)
	{
			$query=$this->db->query("Select * from menuitemsetting where ID='1'");
			foreach ($query->result_array() as $row)
				$value = $row[$type];
			
			
			if($value == '1')
				{
					$query=$this->db->query("UPDATE menuitemsetting SET $type = '0' where ID='1' ");
					return 0;
				}
			else
				{
					$query=$this->db->query("UPDATE menuitemsetting SET $type = '1' where ID='1' ");
					return 1;
				}	

	}
	
	function getAffiliateSiteDetails($siteID)
	{
			$query=$this->db->query("Select * from affiliatesite where siteID='$siteID'");
			 return $query->result_array();
	}


	function channgeSiteStatus($siteID)
	{
			$query=$this->db->query("Select * from affiliatesite where siteID='$siteID'");
			foreach($query->result_array() as $row)
				$value = $row['status'];
			
			
			if($value == '1')
				{
					$query=$this->db->query("UPDATE affiliatesite SET status = '0' where siteID='$siteID' ");
					return 0;
				}
			else
				{
					$query=$this->db->query("UPDATE affiliatesite SET status = '1' where siteID='$siteID' ");
					return 1;
				}	
	}

	
	function getMenuStatus()
	{
		$query=$this->db->query(" select * from menuitemsetting where ID = '1' limit 1 ");
		return $query->result_array(); 
	}
	
	function deleteSelectedMenu($mID)
	{
		$query=$this->db->query(" delete from menuitems where mID = '$mID' ");
	}
	
	function updateSaprator($data)
	{
		//print_r($data);
		//echo "update menuitems set English_mName = '$data[English_mName]', mOrder='$data[mOrder]', mLink='$data[mLink]'  where mID = '$data[mID]'";
		$query=$this->db->query(" update menuitems set English_mName = '$data[English_mName]', mOrder='$data[mOrder]', mLink='$data[mLink]'  where mID = '$data[mID]' ");	
	}
	function updateContentPage($data)
	{
		$query=$this->db->query(" update menuitems set English_mName = '$data[English_mName]', Spanish_mName = '$data[Spanish_mName]', French_mName = '$data[French_mName]', German_mName = '$data[German_mName]',  mOrder='$data[mOrder]', English_mContent='$data[English_mContent]', Spanish_mContent='$data[Spanish_mContent]', French_mContent='$data[French_mContent]', German_mContent='$data[German_mContent]'   where mID = '$data[mID]' ");	
		
		
		
	}
	
	function getMenuInformation($type)
	{
		$query=$this->db->query(" select * from menuitems ");
		return $query->result_array(); 	
	}
	
	function insertMenu($data)
	{
		$this->db->insert('menuitems', $data); 
		$ID = $this->db->insert_id();	
		if($data['mLinkType']=='Wrap Site' || $data['mLinkType']=='Content Pages' || $data['mLinkType']=='URL')
			{
					$NEWLINK = $data['mLink'] . $ID;
					$query=$this->db->query(" update menuitems set mLink = '$NEWLINK' where mID = '$ID' ");
			}
	}
	
	function getSelectedMenuDetails($mID)
	{
		$query=$this->db->query(" select * from menuitems where mID = '$mID' ");
		return $query->result_array(); 		
	}
	
	function getMenuParentID($selected)
	{
		$query=$this->db->query(" select * from menuitems where mID = '$selected'");
		foreach($query->result_array() as $row) 		
			return $row['mPID'];
	}
	
	function checkParentSelected($mID,$mPID)
	{
		//echo " select * from menuitems where mID = '$mID' and mPID = '$mPID' <br><br>";
		$query=$this->db->query(" select * from menuitems where mID = '$mID' and mPID = '$mPID' ");
		foreach($query->result_array() as $row) 		
			return TRUE;
		return FALSE;
	}
	
	function updateMenu1($type,$mPID,$mID)
	{
		
		$query=$this->db->query(" update menuitems set mPID = '$mPID'  where mID = '$mID' ");
	}
	
	function updateMenu2($mLinkType,$mID)
	{
		$query=$this->db->query(" update menuitems set mLinkType = '$mLinkType'  where mID = '$mID' ");
	}
	
	function updateCategory555($data)
	{
		$query=$this->db->query(" update menuitems set English_mName = '$data[English_mName]', Spanish_mName = '$data[Spanish_mName]', French_mName = '$data[French_mName]', German_mName = '$data[German_mName]', mOrder = '$data[mOrder]', mLink = '$data[mLink]'  where mID = '$data[mID]' ");
	}
	
	function updateWrapSite($data)
	{

		$query=$this->db->query(" update menuitems set  English_mName = '$data[English_mName]', Spanish_mName = '$data[Spanish_mName]', French_mName = '$data[French_mName]', German_mName = '$data[German_mName]', mOrder = '$data[mOrder]', English_mContent = '$data[English_mContent]' , mLink = '$data[mLink]'  where mID = '$data[mID]' ");
	
	}
	
	
	//--------- End Menu Management
	//----------  User Management
	
	function deleteUser($uID)
	{
			$query=$this->db->query("delete from users where userID ='$uID' ");
	}
	
	function insertIntoUser($data)
	{
		$this->db->insert('users', $data); 
		$a = $this->db->insert_id();
		return $a;
	}
	
	function insertIntoSubadmin($data)
		{
		$this->db->insert('subadmin', $data); 
		$a = $this->db->insert_id();
		return $a;		
		}
	
	function updateIntoUser($row)
	{	
		$query=$this->db->query("UPDATE users SET mailID='$row[mailID]'  WHERE userID='$row[userID]'");
	}
	
	function searchUserRecord($user,$pass)
	{
			$query=$this->db->query("Select * from users where username ='$user' and password = '$pass' and status = '1' ");
			return $query->result_array();
	}
	
	function checkUser($email,$username)
	{
	/*echo "Select * from users where username ='$email' "; 
	exit;*/
			$query=$this->db->query("Select * from users where mailID ='$email' or username='$username' ");
			return $query->result_array();		
	}
	
	function checkSubAdmin($username)
		{
			$query=$this->db->query("Select * from subadmin where subUsername ='$username' ");
			return $query->result_array();
		}

	function getUserDetails($ID)
	{
		$query=$this->db->query(" Select * from users where userID = '$ID'");
		return $query->result_array();	
	}
	
	function counUsersRows()
	{
		$query=$this->db->query(" Select * from users ");
		return $query->num_rows();	
	}
	
	
	
	
	function getAllUsers($offset,$per_page)
	{
		$query=$this->db->query(" Select * from users  order by memberSince DESC limit $offset,$per_page");
		return $query->result_array();	
	}

	function getAllUsersSortName($offset,$per_page)
	{
		$query=$this->db->query(" Select * from users order by username limit $offset,$per_page");
		return $query->result_array();	
	}

	function getAllUsersSortStatus($offset,$per_page)
	{
		$query=$this->db->query(" Select * from users  order by status DESC limit $offset,$per_page");
		return $query->result_array();	
	}

	
	function getPendingUserList()
	{
		$query=$this->db->query(" Select * from users as U,pendinguserlist as PU where U.userID = PU.userID group by PU.userID ");
		return $query->result_array();	
	}
	
	function updateUserListingToAccepted($userID)
	{
		$query = $this->db->query("update users set status = '1' where userID = '$userID' ");
		$query = $this->db->query("delete from pendinguserlist where userID = '$userID' ");	
	}
	
	function updateUserListingToDeny($userID)
	{
		$query = $this->db->query("delete from users where userID = '$userID' ");
		$query = $this->db->query("delete from pendinguserlist where userID = '$userID' ");		
	
	}
	//---------  End User Management
	//-----------  Category
	
	function countRows()
	{
			$query = $this->db->query(" Select * from category ");
			return $query->num_rows();
	}

	function getAllCategory($offset,$per_page)
	{
			$query=$this->db->query("Select * from category order by catName_english limit $offset,$per_page");
			return $query->result_array();
	}
	
	function getAllCategory1($pID,$offset,$per_page)
	//Select * from category where pID = '4' order by catName desc limit 4,40
		{//echo "Select * from category where pID = '$pID' order by catName desc limit $offset,$per_page";
			$query=$this->db->query("Select * from category where pID = '$pID' order by catName_english desc limit $offset,$per_page");
			return $query->result_array();
		}
		
	function getAllCategory2($offset,$per_page)
	{
			$query=$this->db->query("Select * from category where pID = '0' order by catName_english limit $offset,$per_page");
			return $query->result_array();
	}
	
	function getpID($catID)
	{
			$query=$this->db->query("Select * from category where catID = '$catID' ");
			foreach($query->result_array() as $row5)
				return $row5['pID'];
	}
	
	function getSubCategory($pID)
	{
			$query=$this->db->query("Select * from category where pID = '$pID' ");
			return $query->result_array();
	
	}

	function getCatDetails($catid)
	{
			$query=$this->db->query("Select * from category where catID = '$catid'");
			return $query->result_array();
	}

	function checkCategory($categoryName)
	{
		$query = $this->db->query("SELECT * FROM category WHERE catName='$categoryName' ");
		return $query->result_array();	
	}
	
	function checkCategory1($categoryName1,$categoryName2,$categoryName3,$categoryName4)
	{
		$query = $this->db->query("SELECT * FROM category WHERE catName_english='$categoryName1' and catName_swedish='$categoryName2' and catName_spanish='$categoryName3' and catName_german='$categoryName4'");
		return $query->result_array();	
	}
	
	function updateCategory($data5,$catID,$CPID,$mainCategory)
		{
	
		$this->db->where('catID', $catID);
		$this->db->update('category', $data5);

	}
	
	function getCategoryName($catID)
		{
		$query = $this->db->query("SELECT * FROM category WHERE catID='$catID' ");
		foreach($query->result_array() as $row)
			return $row['English_catName'];
		}
	
	function checkRelation($catID,$mainCat)
		{
		//echo "SELECT * FROM catparent WHERE catID='$catID' and pID = '$mainCat' ";
		$query = $this->db->query("SELECT * FROM catparent WHERE catID='$catID' and pID = '$mainCat' ");
		
		foreach($query->result_array() as $row)
			return TRUE;
		return FALSE;
		}

	function checkCategory55($LID,$catID)
		{
		//echo "SELECT * FROM catparent WHERE catID='$catID' and pID = '$mainCat' ";
		$query = $this->db->query("SELECT * FROM listingcategory WHERE catID='$catID' and LID = '$LID' ");
		
		foreach($query->result_array() as $row)
			return TRUE;
		return FALSE;
		}


	function getMovieDetails($movieId)
	{
		$query=$this->db->query(" Select * from movie  where movieId='$movieId' ");
		return $query->result_array();	
	}
	function getAllMainMovie($movieId)
	{
		$query=$this->db->query(" Select * from movie  where movieId='$movieId' ");
		return $query->result_array();	
	}
	
	function deleteOldRelation($catID)
		{
		$query = $this->db->query("DELETE FROM catparent WHERE catID = '$catID' and org='0' ");
		}
	
	function relateCategory($catID,$mainCategory)
		{
		$query = $this->db->query("INSERT INTO `catparent` ( `cpID` , `catID` , `pID` ,`org` )VALUES (NULL , '$catID', '$mainCategory' , '0'); ");
		}

	function deleteCategory($catID)
	{
			$query=$this->db->query("DELETE FROM category WHERE catID = '$catID'");
	}
	
	function getAllSubCategories($pID)
	{
			//echo "Select * from category as C,catparent as CP WHERE C.catID=CP.catID and CP.pID = '$pID' and org = '1'";
			$query=$this->db->query("Select * from category as C,catparent as CP WHERE C.catID=CP.catID and CP.pID = '$pID' and org = '1'");
			return $query->result_array();
	}
	
	function deleteRelation($id)
	{
			$query=$this->db->query("DELETE FROM catparent WHERE cpID = '$id'");	
	}
	
	function getPerentLevel($pID)
	{
			$query=$this->db->query("select * from catparent where catID = '$pID' ");
			foreach($query->result_array() as $row)
					return $row['level'];

	}



	function insertCategory($data5,$pID,$level)
	{
	
		$this->db->insert('category', $data5); 
		$insertID = $this->db->insert_id();
	}

	function insertCategory1($data5)
	{
	
		$this->db->insert('category', $data5); 
		$insertID = $this->db->insert_id();
	}



	function addNewCoupon($data5)
	{
	
		$this->db->insert('coupon', $data5); 
		$insertID = $this->db->insert_id();
	}
	
		function getCatURL($id)
			{
			$query=$this->db->query("Select * from category where catID = '$id' ");
		foreach($query->result_array() as $row)
			return $row['catUrl'];
			}	
			
		function searchCategoryID($q)
			{
			$query=$this->db->query("Select * from category where catUrl = '$q' ");
		foreach($query->result_array() as $row)
			return $row['catID'];
			}
	
		function getParentID($catID)	
		{
			$query=$this->db->query("Select * from category as C,catparent as CP WHERE C.catID=CP.catID and C.catID = '$catID'");
		foreach($query->result_array() as $row)
			return $row['pID'];
		}


		function getCountryParentID($id)	
		{
			//echo "Select * from country where cID = '$id'";
			$query=$this->db->query("Select * from country where cID = '$id'");
		foreach($query->result_array() as $row)
			return $row['pID'];
		}

		
		
		
		function getListingName($LID)
		{
			$query=$this->db->query("Select * from listingsdb where listingsdb_id ='$LID'");
		foreach($query->result_array() as $row)
			return $row['listingsdb_title'];
		}
	
		function getCatName($id)
			{
			$LANGUAGE = $this->session->userdata('language');
			$query=$this->db->query("Select * from category where catID = '$id'");
		foreach($query->result_array() as $row)
			return $row[$LANGUAGE.'_catTitle'];
			}


		function getCatName55($id)
			{
			$LANGUAGE = $this->session->userdata('language');
			$query=$this->db->query("Select * from category where catID = '$id'");
		foreach($query->result_array() as $row)
			return $row['English_catName'];
			}

	
	
	function getRelatedCatDetails($catID)
		{
			$query=$this->db->query("Select * from category as C,catparent as CP WHERE C.catID=CP.catID and C.catID = '$catID' group by CP.pID");
			return $query->result_array();
		
		}
	
	//------------  End Category
	
	
	//------------  Sub Category
	
	function countSubCatRows($mainCatID)
	{
			$query=$this->db->query("Select * from category as C,catparent as CP where C.catID=CP.catID and CP.pID = '$mainCatID' group by C.catID");
			return $query->num_rows();
	}

	function getAllSubCategory($mainCatID,$offset,$per_page)
	{
			$query=$this->db->query("Select * from category as C,catparent as CP where C.catID=CP.catID and CP.pID = '$mainCatID' group by C.catID limit $offset,$per_page ");
			return $query->result_array();	
	}
	

	function getAllMainCategories1()
	{
			$query = $this->db->query("Select * from category ");
			return $query->result_array();		
	}


	function getSubCatDetails($subcatid)
	{
			$query=$this->db->query("Select * from subcategory where subCatID='$subcatid' ");
			return $query->result_array();
	}

	function getAllMainCategories()
	{
			$query=$this->db->query("Select * from category");
			return $query->result_array();
	}	

	function getAllMainCategory($mainCat)
	{
			$LANGUAGE = $this->session->userdata('language');
			$query = $this->db->query("SELECT * FROM category WHERE catID='$mainCat' ");
			foreach($query->result_array() as $row)
				return $row[$LANGUAGE.'_catName'];		
	}

	function checkSubCategory($subCategory,$mainCategory)
	{
			$query=$this->db->query("Select * from subcategory where catID='$mainCategory' and subCatName='$subCategory'");
			return $query->result_array();
	}

	function deleteSubCategory($id)
	{
			$query=$this->db->query("DELETE FROM subcategory WHERE subCatID = '$id'");
	}
	
	function insertSubCategory($subCategory,$mainCategory,$catTitle,$catKeyword,$catDescription)
	{
			$query=$this->db->query("INSERT INTO `subcategory` ( `subCatID` , `catID` , `subCatName` , `subCatDiscription` ,`subCatTitle` ,`subCatKeyword` )VALUES (NULL , '$mainCategory', '$subCategory', '$catDescription' , '$catTitle' ,'$catKeyword');");
	}
	
	function updateSubCategory($subCatID,$subCategory,$mainCategory,$catTitle,$catKeyword,$catDescription)
	{
			
			$query=$this->db->query("UPDATE subcategory SET subCatName='$subCategory',subCatTitle = '$catTitle', subCatKeyword = '$catKeyword' , subCatDiscription ='$catDescription' where subCatID='$subCatID'");
	}


	
	//-----------  End Sub Category
	
		
	//------------ Email template

	function countRowsLog()
	{
		$query=$this->db->query("Select * from userlog where userid = 'Administrator' order by dateTime desc ");
		return $query->num_rows();
	}

	function getUserLog($offset,$per_page)
	{
		$query=$this->db->query("Select * from userlog order by dateTime desc limit $offset , $per_page");
		return $query->result_array();
	}

	function enterLogInfo($ip,$post,$status,$agent)
	{
		$dt = date("Y-m-d H:i:s");	
		
		
		$query=$this->db->query(" INSERT INTO `userlog` ( `logid` , `ipaddress` , `userid` , `browser` , `dateTime` , `status` )
VALUES (NULL , '$ip', '$post', '$agent', '$dt', '$status') ");

	}
		
	function countRows9()
	{
		$query=$this->db->query("Select * from emailtemplate");
		return $query->num_rows();
	}

	function showAllEmailTemplates()
	{
		$query=$this->db->query(" SELECT * FROM emailtemplate ");
		return $query->result_array();
	}
	
	function showWebpageById1($id)
	{
		$query=$this->db->query("Select * from emailtemplate WHERE eID='$id' ");
		return $query->result_array();
	}

	function editTemplate($id,$details,$when)
	{	
		$query =  $this->db->query("UPDATE `emailtemplate` SET `details` = '$details', sendWhen = '$when' WHERE `eID` = '$id' LIMIT 1 ;");
	}
	

	function editTemplate11($id,$name1,$name2,$name3,$name4,$details1,$details2,$details3,$details4,$when)
	{	
		$query =  $this->db->query("UPDATE `emailtemplate` SET `name_english` = '$name1', `name_swedish` = '$name2', `name_spanish` = '$name3', `name_german` = '$name4',`details_english` = '$details1',`details_swedish` = '$details2',`details_spanish` = '$details3',`details_german` = '$details4', sendWhen = '$when' WHERE `eID` = '$id' LIMIT 1 ;");
	}
	
	//----------- End Email Template
	
	//---------- Web Pages
	
	function getbanners()
	{
		$query=$this->db->query("Select * from banners ");
		return $query->result_array();
	
	}
	
	function showWebpageById($id)
	{
		$query=$this->db->query("Select * from webpages WHERE id='$id' ");
		return $query->result_array();
	}

	function showAllwebpages($offset,$per_page)
	{
		$query=$this->db->query("Select * from webpages limit $offset , $per_page");
		return $query->result_array();
	}
	
	function getExtraPagesList()
	{
		$query=$this->db->query("Select * from webpages ");
		return $query->result_array();
	}

	function countRows8()
	{
		$query=$this->db->query("Select * from webpages");
		return $query->num_rows();
	}


	function editwebpage($id,$details,$title,$description,$keywords,$name)
	{
		$query =  $this->db->query("UPDATE webpages SET details='$details',title='$title',description='$description',keywords='$keywords',name='$name' WHERE webID='$id'  ");
	}
	
	
	function editwebpage1($id,$details1,$details2,$details3,$details4,$title1,$title2,$title3,$title4,$description1,$description2,$description3,$description4,$keywords1,$keywords2,$keywords3,$keywords4,$name1,$name2,$name3,$name4)
	{
		$query =  $this->db->query("UPDATE webpages SET details_english='$details1',details_swedish='$details2',details_spanish='$details3',details_german='$details4',title_english='$title1',title_swedish='$title2',title_spanish='$title2',title_german='$title4',description_english='$description1',description_swedish='$description2',description_spanish='$description3',description_german='$description4',keywords_english='$keywords1',keywords_swedish='$keywords2',keywords_spanish='$keywords3',keywords_german='$keywords4',name_english='$name1',name_swedish='$name2',name_spanish='$name3',name_german='$name4' WHERE webID='$id'  ");
	}
	
	function getAllCoupon()
	{
		$query=$this->db->query("Select * from coupon order by insertTime desc ");
		return $query->result_array();	
	}	


	function updateSongsDetails($data5,$trackID)
	{
		$this->db->where('trackID', "$trackID"); 
		$this->db->update('soundtrack', $data5); 
	}

	function editSubAdmin($data,$subAdminID)
	{
		$this->db->where('subAdminID',$subAdminID);
		$this->db->update('subadmin',$data);
	}

	function editUserDetails($data,$subAdminID)
	{
		$this->db->where('userID',$subAdminID);
		$this->db->update('users',$data);
	}

	function getsongsdetails($id)
	{
		$query=$this->db->query("Select * from soundtrack where trackID ='$id' ");
		return $query->result_array();
	}
	
	function deleteSongsDetails($id)
	{
		$query =  $this->db->query("delete from soundtrack where trackID = '$id' limit 1 ");
	}
	
	
	function getVideos()
	{
		$query=$this->db->query("Select * from video ");
		return $query->result_array();
	}
	
		function countCVideosRows($catID)
		{
		$query=$this->db->query("Select * from audio where catID ='$catID' or actID = '$catID' ");
		return $query->num_rows();
		}

		function getCatVideos($catID,$offset,$per_page)
		{
		$query=$this->db->query("Select * from audio where catID ='$catID' or actID = '$catID' limit $offset,$per_page ");
		return $query->result_array();

		}



		function countCVideosRowsS($catID)
		{
		$query=$this->db->query("Select * from audio where actID ='$catID' ");
		return $query->num_rows();
		}

		function getCatVideosS($catID,$offset,$per_page)
		{
		$query=$this->db->query("Select * from audio where actID ='$catID' limit $offset,$per_page ");
		return $query->result_array();

		}

		
			
	function getVideos5($offset,$per_page,$orderby,$AscDesc)
		{
		$query=$this->db->query("Select * from audio  where aStatus <> '2' order by $orderby $AscDesc  limit $offset,$per_page ");
		return $query->result_array();
		}		
			
	
	function getVideosCategoryWise($offset,$per_page,$orderby,$AscDesc)
		{					
			$query=$this->db->query("Select * from audio as A, category as C where aStatus <> '2' and A.catID = C.catID order by C.catName $AscDesc  limit $offset,$per_page ");
			return $query->result_array();
		}
	
	function countVideosRows()
	{
		$query=$this->db->query(" Select * from audio ");
		return $query->num_rows();	
	
	}
			
	function fmusic($offset,$per_page,$orderby)
	{
		$query=$this->db->query(" Select * from fmusic order by $orderby desc  limit $offset,$per_page");
		return $query->result_array();	
	}

	function countfmusic()
	{
		$query=$this->db->query(" Select * from fmusic  ");
		return $query->num_rows();	
	}
		
			
			

	function getPendingAudios()
	{
		$query=$this->db->query("Select * from audio where aStatus = '2' order by aID desc ");
		return $query->result_array();
	}

	function getAudios($offset,$per_page)
	{
		$query=$this->db->query("Select * from audio where aStatus = '1' or aStatus = '0' order by aID desc limit $offset,$per_page ");
		return $query->result_array();
	}

	function counAudiosRows()
	{
		$query=$this->db->query("Select * from audio where aStatus = '1' or aStatus = '0' order by aID desc  ");
		return $query->num_rows();	
	}



	function getFAudios()
	{
		$query=$this->db->query("Select * from audio order by aID desc ");
		return $query->result_array();
	
	}
	
	function getAudioDetails($aID)
	{
		$query=$this->db->query("Select * from audio where aID = '$aID' ");
		return $query->result_array();
	}
	
	function insertVideoDetails($data)
	{
		$this->db->insert('video', $data); 
		$ID = $this->db->insert_id();	
	}

	function updateVideoDetails($data,$vID)
	{
		$this->db->where('vID', "$vID"); 
		$this->db->update('video', $data); 
	
	}
	
	function updateVideoFile($data,$vID)
	{
		$this->db->where('vID', "$vID"); 
		$this->db->update('video', $data); 
	}
	
	function getOldVideofile($vID)
	{
		$query = $this->db->query("Select * from video where vID = '$vID' ");
		foreach($query->result_array() as $row)
			return $row['vPath'];
	}
	
	function deleteVideoFile($vID)
	{
		$query = $this->db->query("delete from video where vID = '$vID' ");
	}
	
   	
	function updateAudioDetails($data,$aID)
	{

		$this->db->where('aID', "$aID"); 
		$this->db->update('audio', $data); 
	
	}
   
	function insertAudioDetails($data)
	{
		$this->db->insert('audio', $data); 
		return $ID = $this->db->insert_id();	
	}
	
	function updateFmusicRecords($data5,$fID)
	{
		$this->db->where('fID', "$fID"); 
		$this->db->update('fmusic', $data5); 
	
	}
	
	function insertSongsDetails($data5)
	{
		$this->db->insert('soundtrack', $data5); 
		return $ID = $this->db->insert_id();		
	}
	
	function deleteFmusicProduct($fID)
	{
		$query=$this->db->query(" delete from fmusic where fID = '$fID' limit 1 ");
	}
	
	function updateMusicProductThumb($fID,$file_name)
	{
		$query=$this->db->query(" update fmusic set fTumb  = '$file_name' where fID = '$fID' ");
	}
	
	function getMusicProductDetails($fID)
	{
		$query=$this->db->query(" Select * from fmusic where fID='$fID' ");
		return $query->result_array();		
	}
	
	function addNewMusicProduct($data5)
	{
		$this->db->insert('fmusic', $data5); 
		return $ID = $this->db->insert_id();	
	}
	
	function addNewBanner($data5)
	{
		$this->db->insert('banners', $data5); 
		return $ID = $this->db->insert_id();		
	}

	function editBanner($data5,$bID)
	{
		$this->db->where('bID', "$bID"); 
		$this->db->update('banners', $data5); 
	}
	
	function getBannerDetails($bID)
	{
		$query=$this->db->query(" Select * from banners where bID='$bID' ");
		return $query->result_array();		
	}
	
	function updateBannerImage($fID,$file_name)
	{
		$query = $this->db->query(" update banners set bPath = '$file_name' where bID = '$fID'  ");
	}
	
	function deleteBanners($bID)
	{
		$query = $this->db->query(" delete from banners  where bID = '$bID'  ");
	}
	
	function addNewUser($data5)
		{
		$this->db->insert('users', $data5); 
		$ID = $this->db->insert_id();
		$data55['userID'] = $ID;
		$data55['validCode'] = md5($data5['username']);
		$this->db->insert('validateuser', $data55); 
		return $ID;
		}
	
	function getUserName($userID)
	{
		$query=$this->db->query(" Select * from users as U ,validateuser as VU where VU.userID='$userID' and U.userID = VU.userID  ");
		foreach($query->result_array() as $row)
			return $row['username'];		
	}
	
	function userIsValidated($userID)
	{
		$query=$this->db->query(" update users set status = '1' where userID='$userID' ");
		$query=$this->db->query(" delete from validateuser where userID='$userID' ");
	}
	
	function updateOldPassword($userID,$newPass)
		{
		$query=$this->db->query(" update users set password  = '$newPass' where userID='$userID' ");
		}
	
	function checkUsernameEmail($username,$email)
	{
		$query=$this->db->query(" select * from users where username = '$username' and  mailID = '$email' ");
		foreach($query->result_array() as $row)
			return $row['userID'];
		return false;
	}
	
	function checkUsernamePassword($username,$password) //55277 
	{
		$query=$this->db->query(" select * from users where username = '$username' and  password = '$password' and status = '1' ");
		return $query->result_array();
	}
	
	function updateFrontUserUpdate($userID,$data)
	{
		$this->db->where('userID', "$userID"); 
		$this->db->update('users', $data); 
	}

	function updatePollDetails($data)
	{
		$this->db->where('pollID', "$data[pollID]"); 
		$this->db->update('polling', $data); 
	}

	function insertPollDetails($data5)
	{
		$this->db->insert('polling', $data5); 
		return $ID = $this->db->insert_id();		
	}
	
	function deletePollDetails($pID)
	{
		$query=$this->db->query(" delete from polling where pollID = '$pID' ");
	}
	
	function saveRequestDetails($data5)
	{
		$this->db->insert('movierequest', $data5); 
		return $ID = $this->db->insert_id();		
	}
	
	function updateFeaturedVideos()
	{
		$query=$this->db->query(" update audio set aFeatured = '0' where aFeatured = '1'  ");	
	}
	
	function searchUserQuery($q,$qType)
	{
		//echo " select * from audio as A,category as C where aName like '%$q%' and C.catID = A.catID and C.pID = '$qType' order by aTime desc ";
		$query=$this->db->query(" select * from audio as A,category as C where aName like '%$q%' and C.catID = A.catID and C.pID = '$qType' order by aTime desc ");
		return $query->result_array();		
	}
	
	function searchAll($q)
		{
		//echo "select * from audio as A,category as C where aName like '%$q%' and C.catID = A.catID order by aTime desc";
		$query=$this->db->query(" select * from category where catName like '%$q%' order by pID desc ");
		return $query->result_array();		
		
		
		}
	
	function alphabetsearch($q)
		{
		echo "select * from audio as A,category as C where aName like '$q%' and C.catID = A.catID order by aTime desc ";
		$query=$this->db->query(" select * from audio as A,category as C where aName like '$q%' and C.catID = A.catID order by aTime desc ");
		return $query->result_array();		
		}
	
	function asearchUserQuery($q)
	{
		$query=$this->db->query(" select * from audio as A,category as C where aName like '$q%' and C.catID = A.catID order by aTime desc ");
		return $query->result_array();		
	}
	
	function getSampleDetails($fID)
	{
		//echo "select * from fmusic where fID = '$fID'";
		$query=$this->db->query(" select * from fmusic where fID = '$fID' ");
		return $query->result_array();		
	}

	function updateMusicSample($fID,$file_name,$field1,$field2,$sampleName)
	{
	
		$query=$this->db->query(" update fmusic set $field1 = '$sampleName', $field2 = '$file_name' where fID = '$fID'  ");
	}

	function deleteFmusicSample($fID,$field1,$field2)
	{
		$query=$this->db->query(" update fmusic set $field1 = '', $field2 = '' where fID = '$fID'  ");
	}
	
	function getCategoryPendingList()
	{
		$query=$this->db->query(" select * from category where status  = '0' ");
		return $query->result_array();			
	}
	
	function updatePendingCateogryList($id)
	{
		$query=$this->db->query(" update category set status = '1' where catID = '$id' ");
	}
	function deletePendingCateogryList($id)
	{
		$query=$this->db->query(" delete from category where catID = '$id' ");
	}
	
	function getMusicByArtist($offset,$per_page,$orderBy,$AscDesc)
	{
		$query=$this->db->query(" select * from  fmusic order by $orderBy $AscDesc limit $offset,$per_page  ");
		return $query->result_array();		
	
	}
	// movies functions
	function getAllMovies($offset,$per_page,$field,$Aod )
		{
		$query=$this->db->query(" select * from  movie order by $field $Aod  limit $offset,$per_page  ");
		return $query->result_array();		
		
		}
		
		
		
		function countnewscolumn()
		{
		
		$query=$this->db->query("select aName,aDetails from newscolumn");
		return $query->num_rows();		
		}
		function getnewscolumnData($offset,$per_page)
		{
			$query=$this->db->query(" select * from newscolumn order by insertTime desc limit $offset,$per_page ");
			return $query->result_array();
		}





		function countallfeatures()
		{
		
		$query=$this->db->query("select aName,aDetails from features");
		return $query->num_rows();		
		}
		function getallfeaturesData($offset,$per_page)
		{
			$query=$this->db->query(" select * from features order by insertTime desc limit $offset,$per_page ");
			return $query->result_array();
		}


		function countSingleFeature($featureID)
		{
		
		$query=$this->db->query("select aName,aDetails from features where featureID='$featureID'");
		return $query->num_rows();		
		}
		function getSingleFeatureData($featureID,$offset,$per_page)
		{
			$query=$this->db->query(" select  * from features where featureID='$featureID' order by insertTime desc limit $offset,$per_page ");
			return $query->result_array();
		}

		
		function countFComments($featureID)
		{
		
		$query=$this->db->query("select C.thumbPath as thumb,C.comment,C.insertTime,C.postedBy  from comments as C, features as F where C.featureID=F.featureID and F.featureID='$featureID'");
		return $query->num_rows();		
		}
		function getFCommentsData($featureID,$offset,$per_page)
		{
			$query=$this->db->query(" select C.thumbPath as thumb,C.comment,C.insertTime,C.postedBy  from comments as C, features as F where C.featureID=F.featureID and F.featureID='$featureID' order by F.insertTime desc limit $offset,$per_page ");
			return $query->result_array();
		}

	function countAllNewsCommentCount($aID)
		{
		
	//	select * from comments as C, article as A where C.aID = A.aID and A.aID = '$aID'
		
				
			$query=$this->db->query("select * from comments as C, users as U where C.userID = U.userID and C.aID = '$aID' order by insertTime desc  ");
			return $query->num_rows();
		}

	function getAllNewsComments($aID,$offset,$per_page)
		{
			$query=$this->db->query("select * from comments as C, users as U where C.userID = U.userID and C.aID = '$aID' order by insertTime desc  limit $offset,$per_page");
			return $query->result_array();
		}

		function countAllFeaturesComment($featureID)
		{
		
			
			$query=$this->db->query(" select * from comments as C, users as U where C.userID = U.userID and C.featureID = '$featureID' and C.stat='1' ");
			return $query->num_rows();
		}

	function getAllFeaturesComments($featureID,$offset,$per_page)
		{
			$query=$this->db->query(" select * from comments as C, users as U where C.userID = U.userID and C.featureID = '$featureID' and C.stat='1' limit $offset,$per_page");
			return $query->result_array();
		}
		function countAllColComment($colID)
		{
		
			
			$query=$this->db->query(" select * from comments as C, users as U where C.userID = U.userID and C.colID = '$colID' and C.stat='1' ");
			return $query->num_rows();
		}

	function getAllColComments($colID,$offset,$per_page)
		{
			$query=$this->db->query(" select * from comments as C, users as U where C.userID = U.userID and C.colID = '$colID' and C.stat='1' limit $offset,$per_page");
			return $query->result_array();
		}

function updateCategorystatus($catid)
{
		$query=$this->db->query("update category set status = '1' where catID = '$catid' ");

}
function updateCategorystatus1($catid)
{		//echo "update category set status = '1' where catID = '$catid'";
		$query=$this->db->query("update category set status = '0' where catID = '$catid' ");

}




}	
?>