


<?php
 
include('pagination.php');
 
function get_fields($page_id, $result, $columns,  $check,  $menu_id, $access_id)
{
	$menu_id = explode('|', $menu_id);
	$access_id  = explode('|', $access_id);
	
	$grid = "";
	 $grid .= "<thead id='tbl_head'><tr align='center'>";
 
	
	$grid .= "<th style='border:3px solid #333;' >Sl</th>";
	
	for($i = 0; $i < $columns; $i++)
	{
		$fields = mysqli_fetch_field($result);
		if($i != 0)
			$grid .= 	"<th style='border:3px solid #333;' >".$fields->name."</th>"; 
	}
	
	$grid .= 	"<th style='border:3px solid #333;' >Alternator</th>"; 
	
	switch($page_id)
	{ 
		case 'client_list' :
		break;
		case 'product_list' :
			$grid .= 	"<th style='border:3px solid #333;' >Details</th>"; 
		break;
	}
	
	$grid .= "</thead>";
	return $grid; 
}

function get_data($page_id, $sub_element_id, $result, $columns,  $check,  $page_no, $record,  $menu_id, $access_id)
{
	$m_id = explode('|', $menu_id);
	$a_id  = explode('|', $access_id);
 
 
	
	$grid = "";
	
	$j = ((($page_no * $record) -  $record) + 1);

	while ($row = mysqli_fetch_array($result))
	{
		$grid .= "<tbody>";
			
		if($j % 2 == 1)
			$grid .= "<tr class='odd' >";
		else
			$grid .= "<tr class='even'>";
		
 
 
		$grid .= "<td align='center' style='border-left:1px solid #000;border-bottom:1px solid #000;' >$j</td>";
 
		for($i = 1; $i < $columns; $i++)
		{
			if ($page_id == 'client_list')
			{
 				if($i == ($columns - 1))
					$grid .= 	"<td align ='center' style='border-left:1px solid #000;border-bottom:1px solid #000;border-right:1px solid #000;' >$row[$i]</td>";
				else
					$grid .= 	"<td align ='center' style='border-left:1px solid #000;border-bottom:1px solid #000;' >$row[$i]</td>";		
			}
			else
				$grid .= 	"<td align ='center' style='border-left:1px solid #000;border-bottom:1px solid #000;' >$row[$i]</td>";		
 
		}
		
		if($row['band'] == '1')
			$grid .= 	"<td align ='center' style='border-left:1px solid #000;border-bottom:1px solid #000;' >Mecc Alte</td>";
 
		else
			$grid .= 	"<td align ='center' style='border-left:1px solid #000;border-bottom:1px solid #000;' >Stamford</td>";		
	 
		  
		
		switch($page_id)
		{ 
 
			case 'client_list' :
			break;
			
			case 'product_list' :
				$grid .= 	"<td align ='center' style='border-left:1px solid #000;border-bottom:1px solid #000;border-right:1px solid #000;' >	<a title='Right Click then Save Target as can save this Document to your local drive' href='PDF/".$row[0].".pdf' target='_blank' >Details</a></td>";
			break;

			
	 
        
			
		}
		
		$grid .= "</tr>";
		$j++;
	}
	
	$grid .= "</tbody>";
	return $grid; 
}

function create_pagination($counter, $page_id, $sub_element_id, $page_no, $record,  $menu_id, $access_id)
{
	$grid = "";
	
	$grid .= "<div id = 'pagi_head' style='background-color:#FFF'>";
  	$grid .= "<table width='100%' border='0' cellspacing='0' cellpadding='0'  align='center' style='text-align:center;'>"; 
	$grid .= "<tr>
			<td  align='left' width='15%' ><b>Records:</b><select id='cmbRecourd' style='width:50px;'onchange=\"searchOperationPage('".$page_id."', 0, 0, 1, this.value, '$menu_id', '$access_id' )\">
					<option value='25'>25</option>
					<option value='50'>50</option>
					<option value='100'>100</option>
					<option value='200'>200</option>
 				</select></td>
			<td width='2%'>
				
 			</td>
			<td   align='left'>
				<b>Total Records: $counter</b>
			</td>
			<td  style='text-align:right;'> ";
		 $grid .= "Page : " .dispaly_pagination($counter, $page_no, $record, $page_id, $sub_element_id,  $menu_id, $access_id);		    
		 $grid .= " </td>
		  </tr>
		</table>
 		</div> ";
	
	
	return 	$grid;
}
 
function create_subpage($result, $counter, $page_id, $sub_element_id, $page_no, $record, $check, $field_count, $menu_id, $access_id)
{
 
	$grid = "";
	
	
	$grid = create_pagination($counter, $page_id, $sub_element_id, $page_no, $record,  $menu_id, $access_id);
	
	$grid .= "<div id='tbl_back'>";
  	$grid .= "<table width='100%' border='0' cellspacing='2' cellpadding='0'  align='center' style='text-align:left;'>"; 
	
	$columns = $field_count; 
	$grid .= get_fields($page_id, $result, $columns, $check,  $menu_id, $access_id );
	$grid .= get_data($page_id, $sub_element_id, $result, $columns, $check,  $page_no, $record,  $menu_id, $access_id);
	
	$grid .= "</table></div>";
	
	return $grid;
}

?>
 