<?php

class gallary extends comman
{ 
	function photoGallary($category) {
		
		if (isset($_REQUEST["b_search"]) && $_REQUEST["txtsearch"]<>"") {		
			$s = $_REQUEST["txtsearch"];
			$sql = "select cat.cat_name, gal.photo_title, gal.photo from tbl_img_cat_assign ass 
				left join tbl_image_category cat on ass.cat_id = cat.id 
				left join tbl_gallary gal on ass.img_id = gal.id
				where (cat.cat_name LIKE '%$s%' or gal.photo_title LIKE '%$s%' and gal.status = 'Y') ORDER BY gal.id DESC";
		}
		else if(isset($_REQUEST["b_search"])) {
			$msg  ="Sorry currently no record found";
			$sql = "select cat.cat_name, gal.photo_title, gal.photo from tbl_img_cat_assign ass 
					left join tbl_image_category cat on ass.cat_id = cat.id 
					left join tbl_gallary gal on ass.img_id = gal.id
					where (cat.cat_name = 'null' or gal.photo_title = 'null' and gal.status = 'Y')";
		}
		else {			
			if(empty($category) or $category == 'select') {
				$sql = "select * from tbl_gallary where status = 'Y' ORDER BY id DESC";
			}
			elseif ($category == 'Uncategoriesed') {
				$sql = "select * from tbl_gallary where id not in (select img_id from tbl_img_cat_assign) ORDER BY id DESC";
			}
			else {
				$sql = "select ass.id, ass.img_id, ass.cat_id, cat.id, cat.cat_name, gal.id, gal.photo_title, gal.photo from tbl_img_cat_assign ass 
						left join tbl_image_category cat on ass.cat_id = cat.id 
						left join tbl_gallary gal on ass.img_id = gal.id
						where ass.cat_id = '".$category."' and gal.status = 'Y' ORDER BY gal.id DESC";
			}
		}
		
		$query = parent::queryExe($sql);
		if(parent::numOfRow($sql) > 0) {
			$arr = array();
			while ($galArr = parent::fetch_array()) {
				$arr[] = $galArr;
			}
		}
		return $arr;				
	}
		
	/*function make_combo($sql, $combo_name, $sel_value = '', $extra = '', $choose_one = '')
	{
		$result = parent::queryExe($sql);
		if (mysql_num_rows($result) > 0) {
			$arrAlbum = Array();
			$strAlbumCombo = "<select name='$combo_name' $extra class='textfield'>";
		//	//$strAlbumCombo .= "<option value=''>- - Select Category - -</option>";
			//$strAlbumCombo .= "<option value='Uncategoriesed'>Uncategoriesed</option>";
			//while ($line = mysql_fetch_array($result)) {
				$strAlbumCombo .= "<option value=\"" . $line[0] . "\"";
			//	if ($sel_value == $line[0]) {
					$strAlbumCombo .= " selected ";
				} 
			//	$strAlbumCombo .= ">" . $line[1] . "</option>";
			//} 
			$strAlbumCombo .= "</select>";
		} 
		return $strAlbumCombo;
	}		
}*/

	function make_combo($table_name, $combo_name, $sel_value = '', $extra = '', $choose_one = '') {
		$sql = "select * from ". $table_name ." where status = 'Y' order by id";
		$result = parent::queryExe($sql);
		if (mysql_num_rows($result) > 0) {
			$arrAlbum = Array();
			$strAlbumCombo = "<select name='$combo_name' $extra >";
			$strAlbumCombo .= "<option value=''>- - Select Category - -</option>";			
			while ($line = mysql_fetch_array($result)) {
				$strAlbumCombo .= "<option value=\"" . $line[0] . "\"";
				if ($sel_value == $line[0]) {
					$strAlbumCombo .= " selected ";
				} 
				$strAlbumCombo .= ">" . $line[1] . "</option>";
			} 
			$strAlbumCombo .= "</select>";
		} 
		
		
		return $strAlbumCombo;
	}

}