<?php
	function design_list(){
		global $connect;
		$disp='none';
		if(isset($_POST['sub_search1'])){
			$disp='block';
		}
		$disp_r = '25';
		if(isset($_POST['disp_rec'])!=''){
			$disp_r = $_POST['disp_rec'];
		}
	$startrec = 1;
	$no_rec=$disp_r;
	$design_list_html = '';

	if(isset($_GET['page'])!=''){
		$page=$_GET['page'];
	} else {
		$page=1;
	}
	
	$ot=1;
			if(isset($_GET['ot'])!=''){
				$ot = $_GET['ot'];
			}
	if(isset($_GET['master_cat_id']))
				{
					$cat_id = base64_decode(base64_decode(base64_decode($_GET['master_cat_id'])));
					//THIS IS PAGE ID
					$tot_dis ="block";
				}
				else
				{
					$cat_id = '';
					$tot_dis = "none";
				} 

			$limX = ($page-1) * $no_rec;
			$SLCT = "SELECT * FROM design_det WHERE master_cat_id='$cat_id' and operation_type='".$ot."' ORDER BY design_det.design_det_id ASC LIMIT ".$limX.",".$no_rec."";

			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			if(mysqli_num_rows($QURY)>0)
			{
			while($FTCH = mysqli_fetch_object($QURY))
			{
				//echo $FTCH->design_det_id;
				$design_id	=	base64_encode(base64_encode(base64_encode($FTCH->design_det_id)));
				$SLCT_d = "SELECT  * FROM master_cat WHERE master_cat_id = '$FTCH->master_cat_id'";
				$QURY_d = mysqli_query($connect,$SLCT_d);
				$FTCH_d = mysqli_fetch_object($QURY_d);

				$SLCT_c = "SELECT  * FROM master_country WHERE master_country_id = '$FTCH->master_country_id'";
				$QURY_c = mysqli_query($connect,$SLCT_c);
				if(mysqli_num_rows($QURY_c)>0)
				{
					$FTCH_c = mysqli_fetch_object($QURY_c);
					$country_name=$FTCH_c->country_name;
				}else{
					$country_name='Nil';
				}

				$SLCT_dc = "SELECT  * FROM master_cad_cat WHERE master_cad_cat_id = '$FTCH->master_cad_cat_id'";
				$QURY_dc = mysqli_query($connect,$SLCT_dc);
				if(mysqli_num_rows($QURY_dc)>0)
				{
					$FTCH_dc = mysqli_fetch_object($QURY_dc);
					$cad_cat = $FTCH_dc->cad_cat_name;
				}
				else
				{
					$cad_cat = "----";
				}

				if($FTCH->statu_s == 'active'){ $sts_s = 1; }else{ $sts_s = 2; }

				if($loop%2 != "0")
					$bg = "gradeX";
				else
					$bg = "class='gradeC'";

				if($FTCH->mas_fin_ext!=''){ $imag = "../mas_fin_images/S.".$FTCH->mas_fin_ext; $imag1 = "../mas_fin_images/L.".$FTCH->mas_fin_ext; }

				else if($FTCH->cad_fin_ext!=''){ $imag = "../cad_fin_images/S.".$FTCH->cad_fin_ext; $imag1 = "../cad_fin_images/L.".$FTCH->cad_fin_ext; }

				else if($FTCH->imag_ext!=''){ $imag = "../design_images/S.".$FTCH->imag_ext; $imag1 = "../design_images/L.".$FTCH->imag_ext; }

           $design_list_html .='<tr '.$bg.'>
            <td align="center" style="display:table-cell;vertical-align:middle">'.$loop .'</td>
            <td align="left" style="display:table-cell;vertical-align:middle">
'.$FTCH_d->master_cat_name." ".$FTCH->design_no;

			if($FTCH->up_status=="yes"){ 
			$design_list_html .='( Old '.$FTCH->no_of_tm_alt.' )';
			} 
			$design_list_html .='</td>
            <td align="center" style="display:table-cell;vertical-align:middle">'.$cad_cat.'</td>
            <td align="center" style="display:table-cell;vertical-align:middle">'.$FTCH->no_of_pieces." / ".$FTCH->master_pieces.'</td>
            <td align="center" style="display:table-cell;vertical-align:middle">'.str_replace("-","/",$FTCH->design_date).'</td>
            <td align="left" style="display:table-cell;vertical-align:middle">
			'.$FTCH->design_status.'</td>
            <td class="center">
                <div class="body" align="center">
                	<a href="'.$imag1.'" title="<h2>'.$FTCH_d->master_cat_name." ".$FTCH->design_no.'</h2>" class="lightbox" rel="group"><img src="'.$imag.'" width="60" height="60"/></a>
               </div>
            </td>
            <td class="center" style="display:table-cell;vertical-align:middle">
            <a href="design_view.php?design_id='.$design_id.'&ot='.$ot.'" id="viewlink'.$loop.'" onfocus="foc(this.id)" onblur="stnon(this.id)">';
			
			if($FTCH->up_status=="yes"){ 
			$design_list_html .='View'; 
			}else{ 
			
			$design_list_html .='Update'; } 
			$design_list_html .='| <div id="ajaxres_'.$loop.'">
			<a href="javascript:0" onfocus="foc(this.id)" onblur="stnon(this.id)" onclick="des_act_ina('.$FTCH->design_det_id.','.$sts_s.','.$loop.');">'.$FTCH->statu_s.'</a></div></a>
            </td>
			<td style="display:table-cell;vertical-align:middle">
				<div class="grid4 searchDrop">
                    <select  data-placeholder="" class="select" name="sub_cat_name'.$loop.'" id="sub_cat_name'.$loop.'" onfocus="foc(this.id)" onblur="stnon(this.id)" onchange="des_sub_cat(this.value,'.$design_id.')" style="text-align: left;">
                        <option value="">Choose a Sub Category...</option>';
                       
						$SLCT_con = "SELECT master_sub_category_id,sub_category_name FROM master_sub_category WHERE statu_s='active' ORDER BY sub_category_name ASC";
						$QURY_con = mysqli_query($connect,$SLCT_con);
						while($FTCH_con = mysqli_fetch_object($QURY_con))
						{
                        $design_list_html .='<option';
						if($FTCH_con->master_sub_category_id==$FTCH->master_sub_category_id){ 
						
						$design_list_html .='selected=""';
						} $design_list_html .='value="'.base64_encode(base64_encode(base64_encode(base64_encode($FTCH_con->master_sub_category_id)))).'">'.$FTCH_con->sub_category_name.'</option>';
						}
            $design_list_html .=' </select>
                </div>
			</td>
            </tr>';
			$loop ++;
			 }
			 }
			 
			 $design_list_html .='</table>';
			 
			 echo $design_list_html;
			 
	}