echo $row[4];
    ?>
</td>
                              <td align="center" style="vertical-align:top;"><?php 
    echo $row[5];
    ?>
</td>
                              <td align="center" style="vertical-align:top;"><?php 
    echo $row[2];
    ?>
</td>
                              <td style="vertical-align:top;"><ul>
                                    <?php 
    $rows1 = selectrec("`spare_id`", "groups_details", "active=1 and group_id=" . $row[0]);
    foreach ($rows1 as $row1) {
        echo "<li>" . singlefield("spare_name", "spares", "spare_id=" . $row1[0]) . "</li>";
    }
    ?>

                                  </ul>
                              </td>
                              <td style="vertical-align:top;"><ul>
                                    <?php 
    $rows2 = selectrec("`vin_num`", "groups_vins", "active=1 and group_id=" . $row[0]);
    foreach ($rows2 as $row2) {
        echo "<li>" . $row2[0] . "</li>";
    }
    ?>

                                  </ul>
                              </td>
            echo $row[4];
            ?>
</td>
                              <td align="center" style="vertical-align:top;"><?php 
            echo $row[5];
            ?>
</td>
                              <td align="center" style="vertical-align:top;"><?php 
            echo $row[2];
            ?>
</td>
                              <td style="vertical-align:top;">
                                    <?php 
            $rows1 = selectrec("`spare_id`,`url`,`existing_part`,`new_part`,`dateofchange`", "groups_details", "active=1 and changed=1 and group_id=" . $row[0]);
            foreach ($rows1 as $row1) {
                echo "<a href='" . $row1[1] . "' target='_blank'>" . singlefield("spare_name", "spares", "spare_id=" . $row1[0]) . "</a>";
                $existing_part = $row1[2];
                $new_part = $row1[3];
                $dateofchange = $row1[4];
            }
            ?>

                                  
                              </td>

                              <td align="center" style="vertical-align:top;"><?php 
            echo $existing_part;
            ?>
</td>
                              <td align="center" style="vertical-align:top;"><?php 
            echo $new_part;
                      <tbody id="tbodyproducts">



<?php 
$rows = selectrec("`product_id`,`product_type_id`,`product`,`url`", "product", "active=1");
foreach ($rows as $row) {
    ?>

                    <tr>
                      <td width="20%" align="center"><strong><?php 
    echo $row[0];
    ?>
</strong></td>
                      <td align="center"><?php 
    echo singlefield("product_type", "product_types", "product_type_id=" . $row[1]);
    ?>
</td>
                      <td align="center"><?php 
    echo $row[2];
    ?>
</td>
                      <td align="center"><?php 
    if ($row[3] != "") {
        echo "<img src='" . $row[3] . "' style='max-width:100px;'>";
    }
    ?>
</td>
                      <td align="center"><a href='javascript:deleteproduct(<?php 
    echo $row[0];
    ?>
    <tr class="smalltr">
      <td width="5%" align="center"><strong><?php 
        echo $count;
        ?>
</strong></td>
      <td align="center"><?php 
        echo singlefield("product_type", "product_types", "product_type_id=" . $row[1]);
        ?>
</td>
      <td align="center"><?php 
        echo singlefield("group_name", "groups", "group_id=" . $row[2]);
        ?>
</td>
      <td align="center"><?php 
        echo singlefield("bulletin_type_name", "bulletin", "bulletin_type_id=" . $row[3]);
        ?>
</td>
      <td align="center"><?php 
        echo $row[4];
        ?>
</td>
      <td align="center"><?php 
        echo $row[5];
        ?>
</td>
      <td align="center"><?php 
        echo $row[10];
        ?>
</td>
      <td align="center"><?php 
function getMcSubCategories()
{
    if (!$_SESSION['permission_list']['motorcycle']) {
        $str = '{';
        $str .= '"msg" : "Failure"';
        $str .= '}';
        echo $str;
        return;
    }
    $category_id = $_GET['category'];
    $model_id = $_GET['model'];
    $rows = selectrec("subcategory_id, subcategory_name, img_url", "epc_mc_subcategory", "active=1 and category_id=" . $category_id . " and model_id=" . $model_id);
    $plate_ids = array();
    foreach ($rows as $row) {
        array_push($plate_ids, $row[0]);
    }
    $str = '{
                "Brand" : "Bajaj Auto Ltd",
                "product" : "Aftersell",
                "msg" : "success",
                "category" : "Motorcycle",
                "sub_category" : "Electronic Parts Catelogue",
                "legend" : [';
    foreach ($rows as $row) {
        $str .= '{"status":"' . singlefield("count(part_details_id)", "epc_mc_part_details", "part_details_id=" . $row[0]) . '","subcategory_id" : "' . $row[0] . '", "subcategory_name" : "' . $row[1] . '", "img_url" : "' . $row[2] . '"},';
    }
    if (count($rows) > 0) {
        $str = substr($str, 0, -1);
    }
    $str .= '], "first_plate_id" : "' . min($plate_ids) . '","last_plate_id" : "' . max($plate_ids) . '"
            }';
    echo $str;
}
function insertUpdate($table, $cols, $vals, $compField, $compCond)
{
    if (singlefield($compField, $table, $compCond)) {
        // echo $compField.",".$compCond;
        $col_val = arrayToQuery($cols, $vals);
        if (updaterecs($table, $col_val, $compCond)) {
            $arr = array('status' => 1, 'message' => 'Sync Success', 'sync_time' => date("d/m/Y h:i:sa"));
        } else {
            $arr = array('status' => 0, 'message' => 'Sync Failure. Please try again');
        }
    } else {
        $fields = rtrim(implode(',', $cols), ',');
        $vals = rtrim(implode(',', $vals), ',');
        if (insertrec($table, $fields, $vals)) {
            $arr = array('status' => 1, 'message' => 'Sync Success', 'sync_time' => date("d/m/Y h:i:sa"));
        } else {
            $arr = array('status' => 0, 'message' => 'Sync Failure. Please try again');
        }
    }
    return $arr;
}
function fPassword()
{
    $txtEmail = $_POST["txtEmail"];
    $userid = singlefield("id", "users", "email = '" . $txtEmail . "'");
    if ($userid) {
        passwordResetByEmail($userid);
        $arr = array('status' => 1, 'message' => 'Success');
    } else {
        $arr = array('status' => 0, 'message' => 'Reset Failure. Please try again');
    }
    echo json_encode($arr);
}
function loginCheck()
{
    $username = $_POST['username'];
    $password = $_POST['password'];
    $uType = $_POST['userType'];
    if ($uType == "1" || $uType == "2" || $uType == "3") {
        $userid = singlefield("id", "users", "username='******' and password='******' and admin=" . $uType);
    } else {
        if ($uType == "4") {
            $userid = singlefield("dealer_id", "dealers", "dealer_username='******' and dealer_password='******' and active=1");
        } else {
            if ($uType == "5") {
                $userid = singlefield("asc_id", "`asc`", "asc_username='******' and asc_password='******' and active=1");
            }
        }
    }
    if ($userid) {
        if ($uType == "1" || $uType == "2" || $uType == "3") {
            $_SESSION['NAME'] = singlefield("name", "users", "ID=" . $userid);
            $_SESSION['EMAIL'] = singlefield("email", "users", "ID=" . $userid);
            $_SESSION['USERNAME'] = singlefield("username", "users", "ID=" . $userid);
            $_SESSION['ADMINROLE'] = singlefield("admin", "users", "ID=" . $userid);
        } else {
            if ($uType == "4") {
                $_SESSION['NAME'] = singlefield("dealer_name", "dealers", "dealer_id=" . $userid);
                $_SESSION['EMAIL'] = singlefield("dealer_email", "dealers", "dealer_id=" . $userid);
                $_SESSION['USERNAME'] = singlefield("dealer_username", "dealers", "dealer_id=" . $userid);
                $_SESSION['ADMINROLE'] = 4;
            } else {
                if ($uType == "5") {
                    $_SESSION['NAME'] = singlefield("asc_name", "`asc`", "asc_id=" . $userid);
                    $_SESSION['EMAIL'] = singlefield("asc_email", "`asc`", "asc_id=" . $userid);
                    $_SESSION['USERNAME'] = singlefield("asc_username", "`asc`", "asc_id=" . $userid);
                    $_SESSION['ADMINROLE'] = 5;
                }
            }
        }
        $arr = array('status' => 1, 'message' => 'Success', 'adminRole' => $_SESSION['ADMINROLE'], 'name' => $_SESSION['NAME'], 'email' => $_SESSION['EMAIL'], 'username' => $_SESSION['USERNAME']);
    } else {
        $arr = array('status' => 0, 'message' => 'Login Failure');
    }
    echo json_encode($arr);
}