<?php

include 'vp_dbconfig.php';
$start = $_REQUEST['start'];
$limit = $_REQUEST['limit'];
$user = $_REQUEST['user'];
$notifications_array = array();
$orderid_array = array();
if ($user == "vendor") {
    $vendor_name = FetchVendorNameFromId($vendor_id);
    if (!isset($_REQUEST['markorders'])) {
        if ($_REQUEST['first'] == "yes") {
            $query = "select * from vendor_notifications where value={$vendor_id} or user like '%|{$vendor_id}' order by created_at DESC, display_once ASC limit {$start}, {$limit}";
        } else {
            if ($_REQUEST['first'] == "no") {
                $query = "select * from vendor_notifications where display_once IN (0, 2) and (value={$vendor_id} or user like '%|{$vendor_id}') order by created_at DESC, display_once ASC limit {$start}, {$limit}";
            } else {
                if ($_REQUEST['first'] == "no2") {
                    $query = "select * from vendor_notifications where value={$vendor_id} or user like '%|{$vendor_id}' order by created_at DESC, display_once ASC limit {$start}, {$limit}";
                }
            }
        }
        //$query = "select * from vendor_notifications where display_once in (0, 2) and value=$vendor_id or user like '%|$vendor_id' order by FIND_IN_SET(display_once, '0, 2') limit $start, $limit";
        //echo $query;
        $result = mysql_query($query);
        //echo mysql_error()."<br><br>";
        while ($row = mysql_fetch_assoc($result)) {
            //echo "<br><br>I am in while.<br>";
            $id = $row['id'];
            $type = $row['type'];
            $user = $row['user'];
                         if ($type == "6") {
                             //echo "Landed 6.";
                             $comment_main = explode("|", $user);
                             $comment = $comment_main[0];
                             $vendor_name = FetchVendorNameFromId($comment_main[1]);
                             if (is_numeric($comment_main[1])) {
                                 $temp_notification = "<a href='vp_ordermain.php?orderid={$orderid}&flag=1&display_flag=0' target='_blank' style='text-decoration:none; color:black;'>- <b>{$vendor_name}</b> has added Comment '<b>{$comment}</b>' in Order <b>{$orderid}</b>.<br>{$time}</a>";
                             } else {
                                 $temp_notification = "<a href='vp_ordermain.php?orderid={$orderid}&flag=1&display_flag=0' target='_blank' style='text-decoration:none; color:black;'>- <b>" . $comment_main[1] . "</b> has added Comment '<b>{$comment}</b>' in Order <b>{$orderid}</b>.<br>{$time}</a>";
                             }
                         } else {
                             if ($type == "7") {
                                 //echo "Landed 7.";
                                 $remark_main = explode("|", $user);
                                 $remark = $remark_main[0];
                                 $vendor_name = FetchVendorNameFromId($remark_main[1]);
                                 if (is_numeric($remark_main[1])) {
                                     $temp_notification = "<a href='vp_ordermain.php?orderid={$orderid}&flag=1&display_flag=0' target='_blank' style='text-decoration:none; color:black;'>- <b>{$vendor_name}</b> has added a Remark '<b>{$remark}</b>' while accepting the Order <b>{$orderid}</b>.<br>{$time}</a>";
                                 } else {
                                     $temp_notification = "<a href='vp_ordermain.php?orderid={$orderid}&flag=1&display_flag=0' target='_blank' style='text-decoration:none; color:black;'>- <b>" . $remark_main[1] . "</b> has added a Remark '<b>{$remark}</b>' while accepting the Order <b>{$orderid}</b>.<br>{$time}</a>";
                                 }
                             } else {
                                 //echo "Landed Here.";
                             }
                         }
                     }
                 }
             }
         }
     }
 }