<?php session_start();
require_once("./../../config/config.php");
require_once("./validated_admin.php");

$myformId=SESS_MASTER;
$myIp= ipCheck() ;
$dateceated=date("Y-m-d G:i:s");
$createdby='0';
$api_type=$_REQUEST['api_type'];


 /*brand store category start*/

  function brand_store($data){
    $myIp= ipCheck() ;
    $dateceated=date("Y-m-d G:i:s");
    global $conn;
    $sqlno = "SELECT coupon_code FROM  coupon WHERE coupon_code!='' AND company_name LIKE '$data%' OR short_title LIKE '$data%' OR full_title LIKE '$data%'";
               $myqueryno=$conn->query($sqlno);
               $mydarano= $myqueryno->fetchAll()  ;
               
               $rows_foundno = $myqueryno->rowCount();
               
                
               $sqloff = "SELECT coupon_code FROM  coupon WHERE coupon_code ='' AND company_name LIKE '$data%' OR short_title LIKE '$data%' OR full_title LIKE '$data%'";
               $myqueryoff=$conn->query($sqloff);
               $mydaraoff= $myqueryoff->fetchAll()  ;
               
               $rows_foundoff = $myqueryoff->rowCount();
          $olgaquery="UPDATE brand_master SET createdIp='$myIp',datecreated='$dateceated',total_coupon ='$rows_foundno',total_offers ='$rows_foundoff' WHERE brand_name='$data'"; 
     
        $stmt = $conn->prepare($olgaquery);
        $stmt->execute();
  }


   function store_store($data){
    $myIp= ipCheck() ;
    $dateceated=date("Y-m-d G:i:s");
    global $conn;
     $sqlno = "SELECT coupon_code FROM  coupon WHERE coupon_code!='' AND company_name LIKE '$data%' OR short_title LIKE '$data%' OR full_title LIKE '$data%'";
               $myqueryno=$conn->query($sqlno);
               $mydarano= $myqueryno->fetchAll()  ;
               
               $rows_foundno = $myqueryno->rowCount();
               
                
               $sqloff = "SELECT coupon_code FROM  coupon WHERE coupon_code ='' AND company_name LIKE '$data%' OR short_title LIKE '$data%' OR full_title LIKE '$data%'";
               $myqueryoff=$conn->query($sqloff);
               $mydaraoff= $myqueryoff->fetchAll()  ;
               
               $rows_foundoff = $myqueryoff->rowCount();

          $olgaquery="UPDATE store_master SET createdIp='$myIp',datecreated='$dateceated',total_coupon ='$rows_foundno',total_offers ='$rows_foundoff' WHERE store_name='$data'"; 
     
        $stmt = $conn->prepare($olgaquery);
        $stmt->execute();
  }

   function category_store($data){
    $myIp= ipCheck() ;
    $dateceated=date("Y-m-d G:i:s");
    global $conn;
    $sqlno = "SELECT coupon_code FROM  coupon WHERE coupon_code!='' AND category LIKE '$data%' OR short_title LIKE '$data%' OR full_title LIKE '$data%'";
               $myqueryno=$conn->query($sqlno);
               $mydarano= $myqueryno->fetchAll()  ;
               
               $rows_foundno = $myqueryno->rowCount();
               
                
               $sqloff = "SELECT coupon_code FROM  coupon WHERE coupon_code ='' AND category LIKE '$data%' OR short_title LIKE '$data%' OR full_title LIKE '$data%'";
               $myqueryoff=$conn->query($sqloff);
               $mydaraoff= $myqueryoff->fetchAll()  ;
               
               $rows_foundoff = $myqueryoff->rowCount();
          $olgaquery="UPDATE category_master SET createdIp='$myIp',datecreated='$dateceated',total_coupon ='$rows_foundno',total_offers ='$rows_foundoff' WHERE category='$data'"; 
     
        $stmt = $conn->prepare($olgaquery);
        $stmt->execute();
  }

 $sqlnbr = "SELECT brand_name FROM  brand_master";
               $myquerynobr=$conn->query($sqlnbr);
               $mydaranobr= $myquerynobr->fetchAll()  ;
               
               $rows_foundnobr = $myquerynobr->rowCount();
          foreach($mydaranobr as $data){

            $brand=$data['brand_name'];
            brand_store($brand);
  
  }

  $sqlnbr = "SELECT store_name FROM  store_master";
               $myquerynobr=$conn->query($sqlnbr);
               $mydaranobr= $myquerynobr->fetchAll()  ;
               
               $rows_foundnobr = $myquerynobr->rowCount();
          foreach($mydaranobr as $data){

            $store=$data['store_name'];
            store_store($store);
  
  }

   $sqlnbr = "SELECT category FROM  category_master";
               $myquerynobr=$conn->query($sqlnbr);
               $mydaranobr= $myquerynobr->fetchAll()  ;
               
               $rows_foundnobr = $myquerynobr->rowCount();
          foreach($mydaranobr as $data){

            $category=$data['category'];
            category_store($category);
  
  }


  /*brand store category end*/
   header("location:./../dashboard.php");