Friday, October 26, 2018

Delete tree view file and folder


<?php

function is_dir_empty($dir) {
  if (!is_readable($dir)) return NULL;
  $handle = opendir($dir);
  while (false !== ($entry = readdir($handle))) {
    if ($entry != "." && $entry != "..") {
      return FALSE;
    }
  }
  return TRUE;
}



function deletFunction($dir){
   
   
    if ($handle = opendir($dir)) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {
               
                $pathDF=$dir.'/'.$entry;
               
               
                if(is_file($pathDF)){
                echo $pathDF;
                echo "</br>this is file"."</br>";
                unlink($pathDF);
                }
               
               
               
                if(is_dir($pathDF)){
                    echo $pathDF;
                   
                    if(is_dir_empty($pathDF)) {
                       
                        rmdir($pathDF);
                        echo "</br>---empty Dir"."</br>";
                    }else{
                        echo "</br>------Not Empty Dir</br>";
                        deletFunction($pathDF);
                    }
                   
                   
                    //deletFunction($pathDF);
                    //    break;
                }
                //
            }
        }
        closedir($handle);
    }
}
    deletFunction('abc');
?>

Import Sql File in db

<?php
 
// Name of the file
$filename = 'philipcollier.sql';
// MySQL host
$mysql_host = 'localhost';
// MySQL username
$mysql_username = 'philipc';
// MySQL password
$mysql_password = '0pdktr25i6qzg!@#';
// Database name
$mysql_database = 'philipcollier';

// Connect to MySQL server
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
// Select database
mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
    continue;

// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
    // Perform the query
    mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
    // Reset temp variable to empty
    $templine = '';
}
}
 echo "Tables imported successfully";
?>

amazon Reprise

foreach($rows as $index => $row){
   $img  = array();
   $innerHTML  = "";
   $SellerName = "";
   $i++;
   if($i%4==0) continue;
   if($i%5==0) {
    $data[] = $op;
    $op = array();
    $i=0;
    continue;
   }
   if($i==1){
    $text = preg_replace('/[^A-Za-z0-9." ]/', " ", $row->textContent);
    $text = preg_replace('/\s+/', ' ', $text);
    $op['price'] = $text;
   }else if($i==2){
    $text = preg_replace('/[^A-Za-z0-9." ]/', " ", $row->textContent);
    $text = preg_replace('/\s+/', ' ', $text);
    $op['condition'] = $text;
   }else if($i==3){
    $children = $row->childNodes;
    foreach ($children as $child)
    {
     $innerHTML .= $child->ownerDocument->saveXML( $child );
    }
    preg_match_all('/(alt|title|src)=("[^"]*")/i',$innerHTML, $img);
 
    if(!empty($img[2][0])){

     $imgTitle    = str_replace('"',"",$img[2][0]);
     $text     = preg_replace('/[^A-Za-z0-9." ]/', " ", $row->textContent);
     $text     = preg_replace('/\s+/', ' ', $text);
     $op['sellerName'] = strtoupper($imgTitle);
     $text     = "<b>".strtoupper($imgTitle) ."</b>"." ". $text;
     $op['seller']   = str_replace(" Just Launched Seller Profile","",$text);

    }else{
   
     $text     = preg_replace('/[^A-Za-z0-9." ]/', " ", $row->textContent);
     $text     = preg_replace('/\s+/', ' ', $text);
     $op['seller']   = str_replace(" Just Launched Seller Profile","",$text);
     $RawData    = explode(" out of ",strip_tags($op['seller']));
     foreach ($RawData as $key => $value){
       $FirrstValue  = $value;
       break;
     }
   
     $RawDataName = explode(" ",$FirrstValue);
     foreach ($RawDataName as $key => $value){
      $pos = strpos($value, ".");
      if ($pos === false) {
       $SellerName .= $value ." ";
      } else {
       break;
      }
     }

     $op['sellerName'] = trim(str_replace("1","",$SellerName));
     $op['seller'] = str_replace($op['sellerName'],"<b>".strtoupper($op['sellerName'])."</b> ",$op['seller']);

    }
   }
  }

get product price By SKU Amazon.

<?php

$amazonSellerId         = 'A1YXXXXXXXXYLJ';
$amazonMWSAuthToken     = '3653-XXXX-0245';
$amazonAWSAccessKeyId   = 'XXXXXXXXXX';
$amazonSecretKey        = 'XXXXXXXXXXXXXXXXX';
$amazonMarketPlaceId    = 'A21TJRUUN4KGV';
$sku='KNT311209';

$param = array();
$param['AWSAccessKeyId']     = $amazonAWSAccessKeyId;
$param['Action']             = 'GetMyPriceForSKU';
$param['SellerId']           = $amazonSellerId;
$param['MWSAuthToken']       = $amazonMWSAuthToken;
$param['SellerSKUList.SellerSKU.1']  = $sku;
$param['SignatureMethod']    = 'HmacSHA256';
$param['SignatureVersion']   = '2';
$param['Timestamp']          = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version']            = '2011-10-01';
$param['MarketplaceId'] = $amazonMarketPlaceId;
$secret = $amazonSecretKey;
$url = array();
foreach ($param as $key => $val) {
    $key = str_replace("%7E", "~", rawurlencode($key));
    $val = str_replace("%7E", "~", rawurlencode($val));
    $url[] = "{$key}={$val}";
}

sort($url);
$arr   = implode('&', $url);
$sign  = 'POST' . "\n";
$sign .= 'mws.amazonservices.in' . "\n";
$sign .= '/Products/2011-10-01' . "\n";
$sign .= $arr;
$signature      = hash_hmac("sha256", $sign, $secret, true);
$signature      = urlencode(base64_encode($signature));


$link  = "https://mws.amazonservices.in/Products/2011-10-01?";
$link .= $arr . "&Signature=" . $signature;

$httpHeader     =   array();
$httpHeader[]   =   'Transfer-Encoding: chunked';
$httpHeader[]   =   'Content-Type: application/xml';
//$httpHeader[]   =   'Content-MD5: ' . base64_encode(md5($amazon_feed, true));
//$httpHeader[]   =   'x-amazon-user-agent: MyScriptName/1.0';
$httpHeader[]   =   'Expect:';
$httpHeader[]   =   'Accept:';  

$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$errors=curl_error($ch);
curl_close($ch);

print_r($response); //xml response

Tuesday, September 25, 2018

How to Highlight Selected date in Datepicker

<!doctype html>
<html>
    <head>
        <title>How to Highlight selected date in Datepicker</title>
        <link href='jquery-ui.min.css' rel='stylesheet' type='text/css'>
        <script src='jquery-3.0.0.js' type='text/javascript'></script>
        <script src='jquery-ui.min.js' type='text/javascript'></script>
        <link href='style.css' rel='stylesheet' type='text/css'>
       
        <script type='text/javascript'>
           
            // An array of dates ( 'dd-mm-yyyy' )
/* var startDate ='25-09-2018';
var startDate ='29-09-2018';*/

            var highlight_dates = ['25-9-2018','26-9-2018','27-9-2018','29-9-2018'];
           
            $(document).ready(function(){
               
                // Initialize datepicker
                $('#datepicker').datepicker({
                    beforeShowDay: function(date){
                       
                        var month = date.getMonth()+1;
                        var year = date.getFullYear();
                        var day = date.getDate();
                       
                        // Change format of date
                        var newdate = day+"-"+month+'-'+year;
console.log(newdate);
                        // Set tooltip text when mouse over date
                        var tooltip_text = "New event on "+newdate;

                        // Check date in Array
                        if(jQuery.inArray(newdate, highlight_dates) != -1){
                            return [true, "highlight", tooltip_text ];
                        }
                        return [true];
                    }
                });
            });
        </script>
       
    </head>
    <body>
        <div class='container'>
           
            <input type='text' id='datepicker'><br>
           
        </div>
    </body>
</html>