<?php $PageSecurity = 2;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
include("cocoon_config.php");
?>


<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
    <?php


    $where = array();

    if ($_REQUEST['code'] != '') {
        $where[] = " B.service_code LIKE '%" . $_REQUEST['code'] . "%'";
    }
    if ($_REQUEST['name'] != '') {
        $where[] = "B.desc LIKE '%" . $_REQUEST['name'] . "%'";
    }
    if ($_REQUEST['cat'] != '') {
        $where[] = "B.smajor_id='" . $_REQUEST['cat'] . "'";
    }
    if ($_REQUEST['subcat'] != '') {
        $where[] = "B.majerminer_master_id='" . $_REQUEST['subcat'] . "'";
    }


    if (!empty($where))
        $filter2 = implode(" and ", $where);
    if (!empty($where)) {
        //echo "SELECT id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate,conv_unit,conv_factor,item_exciable   FROM item_master WHERE ".$filter2;

        $sql = mysqli_query($link1, "SELECT B.service_code as id,B.majerminer_master_id AS minor, B.service_code AS StockID,B.desc AS item_name,B.smajor_id AS major FROM services B 
 	WHERE " . $filter2);
        $i = 0;
        if (mysqli_num_rows($sql) > 0) {
            while ($myrow = mysqli_fetch_array($sql)) {

                $parameter = $myrow['id'];

    ?>
                <tr bgcolor="#CCCCCC">
                    <td width="9%"><input type="checkbox" name="row_id[<?php echo $i; ?>]" id="row_id_<?php echo $i; ?>" value="<?php echo $parameter; ?>"
                            onclick="getItemsList(this,'<?php echo $parameter; ?>','<?php echo $myrow['major']; ?>','<?php echo string_sanitize($myrow['item_name']); ?> ','<?php echo $i; ?>','<?php echo $myrow['minor']; ?>')" /></td>
                    <td width="20%"><strong><?php echo $myrow['StockID']; ?></strong></td>
                    <td width="20%"><?php echo  $myrow['item_name']; ?></td>



                </tr>
    <?php $i++;
            }
        }
    } ?>
</table>

<?php
function string_sanitize($s)
{
    $result = preg_replace("/[^a-zA-Z0-9]+/", "", html_entity_decode($s, ENT_QUOTES));
    return $result;
}
?>