<?php
include "../includes/config.php";
$currentDatetime = date('Y-m-d h:i:s');
$sql = "SELECT product_id,publish_timezone,product_name FROM ".$tableprefix."products WHERE publish_status ='N' ";

$queryResult = mysql_query($sql) or die (mysql_error());
$cnt=0;

date_default_timezone_set('Asia/Kolkata');
$server_off_set = "+05:30";

if(mysql_num_rows($queryResult) > 0)
{  
   $res = DbHelper::fetchAll($queryResult);   
    // echo "<pre>";print_r($res);exit;
     foreach ($res as $key => $value) {
     
        if($value->publish_timezone!=NULL){
        //target/seller time zone
        $target_time_zone = new DateTimeZone($value->publish_timezone);        
        $timeZoneVal = new DateTime('now', $target_time_zone);  
        //get the exact GMT format       
        $sellerOffSetVal = $timeZoneVal->format('P');        
        $updateSql = "UPDATE ".$tableprefix."products SET publish_status ='Y' WHERE product_id=".$value->product_id ." AND (CONVERT_TZ(publish_scheduled_date, '".$server_off_set."','".$sellerOffSetVal."'))<=now()";        
        mysql_query($updateSql);        
        if($updateSql)$cnt++;   
        
        }
        else{echo "<br>Seller timezone not available for product : ".$value->product_name;}
     }
     echo "<br>".$cnt." products updated";
}else{
     echo "<br>".$cnt." products updated";
}


?>