PHP Developer

Tuesday, 30 October 2018

Abc

I have taken a half-day leave to go home on 6-FEB-2019, so please change the office hours from 08:30 am to 12:30, And I will try to complete the remaining 30-40 minutes on 4-5 February.

Wednesday, 18 July 2018

Create PDF in PHP

http://blog.chapagain.com.np/php-easily-create-pdf-on-the-fly/

Wednesday, 20 June 2018

Rest API

$siteurl = site_url();
$baseuri = $siteurl."/wp-json";
$method = $request->get_method();
$body = $request->get_body();
$route = $request->get_route();
$params = json_encode($request->get_params());
$fullapiurl = $baseuri.$route;
$ctype = $request->get_content_type();
$contentType = isset($ctype)?$ctype['value']:'application/json';
$url = parse_url($siteurl);

$route == "/wc/v2/login";


//authenication method over http
            $oauthTimestamp = time();
            $nonce = md5(mt_rand());
            $oauthSignatureMethod = "HMAC-SHA1";
            $oauthVersion = "1.0";

            $sigBase = $method."&" . rawurlencode($fullapiurl) . "&"
                . rawurlencode("oauth_consumer_key=" . rawurlencode($consumer_key)
                . "&oauth_nonce=" . rawurlencode($nonce)
                . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
                . "&oauth_timestamp=" . $oauthTimestamp
                . "&oauth_version=" . $oauthVersion);

            $sigKey = $consumer_secret . "&";
            $oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));

            $requestUrl = $fullapiurl . "?"
                . "oauth_consumer_key=" . rawurlencode($consumer_key)
                . "&oauth_nonce=" . rawurlencode($nonce)
                . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
                . "&oauth_timestamp=" . rawurlencode($oauthTimestamp)
                . "&oauth_version=" . rawurlencode($oauthVersion)
                . "&oauth_signature=" . rawurlencode($oauthSig);

$ch = curl_init($requestUrl);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $httpMethod = strtolower($method);
    if($httpMethod == "post"){           
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);       
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Content-Type: '.$contentType,
                       'Content-Length: ' . strlen($body))
         );
    }   
    else{
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);       
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Content-Type: '.$contentType)
         );
    }
   
    $response = curl_exec($ch);
    if(curl_errno($ch)) {
      echo 'Curl error: ' . curl_error($ch);
    }
    curl_close($ch);

Sunday, 17 June 2018

Jquery get selected checkbox values

<input type="checkbox" name="vehicle" value="('a', 'b', 'c', 'd')">abcd<br>
<input type="checkbox" name="vehicle" value="('e', 'f', 'g', 'h')">efgh<br>
<input type="checkbox" name="vehicle" value="('i', 'j', 'k', 'l')">ijkl<br>
<input type="checkbox" name="vehicle" value="('m', 'n', 'o', 'p')">mnop<br>
<input type="checkbox" name="vehicle" value="('q', 'r', 's', 't')">qrst<br>
<input type="checkbox" name="vehicle" value="('u', 'v', 'w', 'x')">uvwx<br>
<input type="checkbox" name="vehicle" value="('y', 'z', '1', '2')">yz12<br>
<input type="button" value="Get values" id="get_values">

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).on('click', '#get_values', function(){
var favorite = [];
$.each($("input[name='vehicle']:checked"), function(){           
favorite.push($(this).val());
$(this).append('Saved');
$( "<span>Saved</span>" ).insertAfter( this );
$(this).remove();
});
if(favorite.length > 0){
alert(favorite.join(", "));
}else{
alert("Select atleast one value from list.");
}
//alert("My favourite sports are: " + favorite.join(", "));
});
</script>

Thursday, 14 June 2018

Login

Link : https://drive.google.com/file/d/1VOrOUF97scv7qCf9PVqH4E4GhfJfgqmC/view?usp=sharing

Sunday, 10 June 2018

DataTable

https://drive.google.com/file/d/1nCY186V4uG7QFBWzrHmG-R555q9JK0GZ/view?usp=sharing

Wednesday, 14 March 2018

Sticky Header

https://codepen.io/jovanivezic/pen/ZQNdag
http://jsfiddle.net/0mLzseby/473/
http://jsfiddle.net/FDv2J/1913/
https://codepen.io/perminder-klair/pen/tdzue

Tuesday, 30 January 2018

Cash Back Plugin

https://drive.google.com/open?id=1fH0mmtCxUHYB9EpZIDmjyMU1UeJYhR6A

Thursday, 16 November 2017

Create custom carousel slider with custom post type using Slick slider library

Create custom carousel slider with custom post type using Slick slider library



<!------- Create Custom post Type Crousel Slider Using Slick Slider ---------->
<?php
$team_slider_html = '';

$args = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'posts_per_page' => 10,
);
$query = new WP_Query( $args );
$team_slider_html .= '<section class="center slider hometeam_slider">';
while ( $query->have_posts() ) : $query->the_post();
    if (has_post_thumbnail( get_the_ID() ) ){
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
        $featured_image = $image[0];
    }else{
        $featured_image = site_url().'/wp-content/uploads/2017/10/report-covers.png';
    }
    $team_slider_html .= '<div class="single_team_slide"><div class="single_slide_inner">';
    $team_slider_html .= '<div class="team_member_image"><img src="'.$featured_image.'"></div>';
    $team_slider_html .= '<div class="team_member_excerpt">'.get_the_excerpt().'</div>';
    $team_slider_html .= '<div class="team_member_name">'.get_the_title().'</div>';
    $team_slider_html .= '<div class="team_member_designation">'.get_post_meta( get_the_ID(), '_position', true ).'</div>';
    $team_slider_html .= '</div></div>';
endwhile;
$team_slider_html .= '</section>';

echo $team_slider_html;
?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick-theme.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.js'></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery(document).on('ready', function() {
    jQuery(".center").slick({
        dots: true,
        infinite: true,
        centerMode: true,
        autoplay: true,
        arrows: true,
        slidesToShow: 3,
        slidesToScroll: 1
    });
});
</script>


Create Custom Post slider with Post title in thumbnail Using Slick Slider Library

Create Custom Post slider with Post title in thumbnail Using Slick Slider Library



<!------ Create Custom post Slider With Thumbnail Using Slick Slider -------->
<?php
$tax_query4 = array(array('taxonomy' => 'products_type','field' => 'slug','terms' => array('patent-reports')));
$args4 = array(
        'post_type' => 'product',
        'post_status' => 'publish',
        'posts_per_page' => 5,
        'tax_query' => $tax_query4
    );
$query4 = new WP_Query( $args4 );

$new_patents_slider = '';
$new_patents_slider .= '<div class="main">';
$new_patents_slider .= '<div class="slider patents-for smart_patents">';
while ( $query4->have_posts() ) : $query4->the_post();
    if (has_post_thumbnail( get_the_ID() ) ){
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
        $featured_image = $image[0];
    }else{
        $featured_image = site_url().'/wp-content/uploads/2017/10/report-covers.png';
    }
    $new_patents_slider .= '<div class="img-responsive main-slide-single">';
    $new_patents_slider .= '<div class="main-slide-left"><img src="'.$featured_image.'"></div>';
    $new_patents_slider .= '<div class="main-slide-right">';
    $new_patents_slider .= '<div class="slider_title">'.get_the_title().'</div>';
    $new_patents_slider .= '<div class="slider_excerpt">'.get_the_excerpt().'</div>';
    $new_patents_slider .= '<a href="'.get_the_permalink().'">Read More</a>';
    $new_patents_slider .= '</div>';
    $new_patents_slider .= '</div>';
endwhile;
$new_patents_slider .= '</div>';
$new_patents_slider .= '<div class="slider patents-nav smart_patents">';
while ( $query4->have_posts() ) : $query4->the_post();
    $new_patents_slider .= '<div>';
    $new_patents_slider .= '<div class="img-responsive">';
    $new_patents_slider .= '<div class="thumb-title">';
    if(strlen(get_the_title()) > 50){
        $new_patents_slider .= substr(get_the_title(), 0,50).' ...';
    }else{
        $new_patents_slider .= get_the_title();
    }
    $new_patents_slider .= '</div>';
    $new_patents_slider .= '<a href="'.get_the_permalink().'">read more</a>';
    $new_patents_slider .= '</div>';
    $new_patents_slider .= '</div>';
endwhile;
$new_patents_slider .= '</div>';
$new_patents_slider .= '</div>';

echo $new_patents_slider;
?>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick-theme.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.min.js'></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script>

var noof_sliders = jQuery(".slick-initialized.slick-slider").length;
setTimeout(function(){
    for (i = 0; i < noof_sliders; i++) {
        jQuery(".slick-initialized.slick-slider")[i].slick.refresh();
    }
}, .5);
    
/***** Patents Tab jQuery (START) *****/
jQuery('.patents-for').slick({
    slidesToShow: 1,
    slidesToScroll: 1,
    arrows: false,
    fade: true,
    autoplay: true,
    asNavFor: '.patents-nav'
});
jQuery('.patents-nav').slick({
    slidesToShow: 3,
    slidesToScroll: 1,
    asNavFor: '.patents-for',
    dots: false,
    focusOnSelect: true
});
/***** Patents Tab jQuery (END) *****/

</script>


WordPress Custom Load More Posts Button Without Plugin

WordPress Custom Load More Posts Without Plugin



STEP 1 : Insert this code in functions.php file

<?php
/************ Pagination Function START *************/
function wp_pagination() {
    global $wp_query;
    $big = 12345678;
    $page_format = paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'type'  => 'array'
    ) );
    if( is_array($page_format) ) {
        $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
        echo '<div class="pagination"><ul>';
        echo '<li><span>'. $paged . ' of ' . $wp_query->max_num_pages .'</span></li>';
        foreach ( $page_format as $page ) {
                echo "<li>$page</li>";
        }
       echo '</ul></div>';
    }
}
/************ Pagination Function END *************/
?>

STEP 2 : Template code to get posts with Load morebutton

<?php
   $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
   query_posts(array(  
       'post_type' => 'product', //Post Type
       'post_status' => 'publish', //Post Status
       'paged' => $paged 
   ));
   ?>
<?php if (have_posts()) : ?>
    <section id="posts">
       <?php while (have_posts()) : the_post(); ?>
       <article class="post"><?php echo get_the_title();?></article><br>
       <?php endwhile; ?>
    </section>
    <?php if ( $wp_query->max_num_pages > 1 ) : ?>
        <nav class="load_more">
           <?php next_posts_link( 'Load More' ); ?>
        </nav>
        <script type="text/javascript">
            jQuery(document).ready(function(){
                jQuery('.load_more a').live('click', function(e){
                    e.preventDefault();
                    var link = jQuery(this).attr('href');
                    jQuery('.load_more').html('<span class="loader">Loading More Posts...</span>');
                    jQuery.get(link, function(data) {
                        var post = jQuery("#posts .post ", data);
                        jQuery('#posts').append(post);
                    });
                    jQuery('.load_more').load(link+' .load_more a');
                });
            });
        </script>
    <?php endif;  ?>
<?php endif;  ?>


Monday, 13 November 2017

How to create a Custom Widget in WordPress

How to create a Custom Widget in WordPress


<?php
//Create custom widget 
class Custom_latest_post_Widget extends WP_Widget {
    function __construct() {
        parent::__construct(
            'custom_latest_post_Widget', // Base ID
            'Latest Post List', // Name
            array('description' => __( 'Displays your latest posts. Outputs the post thumbnail, title and date per listing'))
        );
    }
    function widget($args, $instance) { //output
        extract( $args );
        // these are the widget options
        $title = apply_filters('widget_title', $instance['title']);
        $numberOfListings = $instance['numberOfListings'];
        $post_types = $instance['post_types'];
        $thumbnail_image = $instance['thumbnail_image'];
        $enable_excerpt = $instance['enable_excerpt'];
        $excerpt_length = $instance['excerpt_length'];
        $publish_date = $instance['publish_date'];
        $read_more_link = $instance['read_more_link'];
        $read_more_text = $instance['read_more_text'];

        echo $before_widget;
        // Check if title is set
        if ( $title ) {
            echo $before_title . $title . $after_title;
        }
        $this->getRealtyListings($numberOfListings, $post_types, $thumbnail_image, $enable_excerpt, $excerpt_length, $publish_date, $read_more_link, $read_more_text);
        echo $after_widget;
    }

    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        $instance['post_types'] = strip_tags($new_instance['post_types']);
        $instance['numberOfListings'] = strip_tags($new_instance['numberOfListings']);
        $instance['thumbnail_image'] = strip_tags($new_instance['thumbnail_image']);
        $instance['enable_excerpt'] = strip_tags($new_instance['enable_excerpt']);
        $instance['excerpt_length'] = strip_tags($new_instance['excerpt_length']);
        $instance['publish_date'] = strip_tags($new_instance['publish_date']);
        $instance['read_more_link'] = strip_tags($new_instance['read_more_link']);
        $instance['read_more_text'] = strip_tags($new_instance['read_more_text']);
        return $instance;
    }
    
    // widget form creation
    function form($instance) {

// Check values
if( $instance) {
$title = esc_attr($instance['title']);
$numberOfListings = esc_attr($instance['numberOfListings']);
$post_types = esc_attr($instance['post_types']);
$thumbnail_image = esc_attr($instance['thumbnail_image']);
$enable_excerpt = esc_attr($instance['enable_excerpt']);
$excerpt_length = esc_attr($instance['excerpt_length']);
$publish_date = esc_attr($instance['publish_date']);
$read_more_link = esc_attr($instance['read_more_link']);
$read_more_text = esc_attr($instance['read_more_text']);
} else {
$title = '';
$numberOfListings = '';
$post_types = '';
$thumbnail_image = '';
$enable_excerpt = '';
$excerpt_length = '';
$publish_date = '';
$read_more_link = '';
$read_more_text = '';
}
?>
        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'custom_latest_post_Widget'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
         </p>
         <p>
            <label for="<?php echo $this->get_field_id('post_types'); ?>"><?php _e('Post Type:', 'custom_latest_post_Widget'); ?></label>
            <select id="<?php echo $this->get_field_id('post_types'); ?>"  name="<?php echo $this->get_field_name('post_types'); ?>">
               <?php $post_types_array = array('post', 'news', 'product');
                  foreach($post_types_array as $single_post_types){ ?>
               <option <?php echo $single_post_types == $post_types ? 'selected="selected"' : '';?> value="<?php echo $single_post_types;?>"><?php echo $single_post_types; ?></option>
               <?php } ?>
            </select>
         </p>
         <p>
            <label for="<?php echo $this->get_field_id('numberOfListings'); ?>"><?php _e('Number of Listings:', 'custom_latest_post_Widget'); ?></label>
            <select id="<?php echo $this->get_field_id('numberOfListings'); ?>"  name="<?php echo $this->get_field_name('numberOfListings'); ?>">
               <?php for($x=1;$x<=10;$x++): ?>
               <option <?php echo $x == $numberOfListings ? 'selected="selected"' : '';?> value="<?php echo $x;?>"><?php echo $x; ?></option>
               <?php endfor;?>
            </select>
         </p>
         <p>
            <label for="<?php echo $this->get_field_id('thumbnail_image'); ?>"><?php _e('Show Thumbnail Image : ', 'custom_latest_post_Widget'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('thumbnail_image'); ?>" type="checkbox" name="<?php echo $this->get_field_name('thumbnail_image'); ?>" <?php if((!empty($thumbnail_image)) && ($thumbnail_image == 'thumb_image')){echo 'checked';}?> value="thumb_image">
         </p>
         <p>
            <label for="<?php echo $this->get_field_id('enable_excerpt'); ?>"><?php _e('Enable Excerpt : ', 'custom_latest_post_Widget'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('enable_excerpt'); ?>" type="checkbox" name="<?php echo $this->get_field_name('enable_excerpt'); ?>" <?php if((!empty($enable_excerpt)) && ($enable_excerpt == 'show_excerpt')){echo 'checked';}?> value="show_excerpt">
         </p>
         <p>
            <label for="<?php echo $this->get_field_id('excerpt_length'); ?>"><?php _e('Excerpt Length:', 'custom_latest_post_Widget'); ?></label>
            <select id="<?php echo $this->get_field_id('excerpt_length'); ?>"  name="<?php echo $this->get_field_name('excerpt_length'); ?>">
               <?php for($x=10;$x<=150;$x=$x+10): ?>
               <option <?php echo $x == $excerpt_length ? 'selected="selected"' : '';?> value="<?php echo $x;?>"><?php echo $x; ?></option>
               <?php endfor;?>
            </select>
         </p>
         <p>
            <label for="<?php echo $this->get_field_id('publish_date'); ?>"><?php _e('Publish Date : ', 'custom_latest_post_Widget'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('publish_date'); ?>" type="checkbox" name="<?php echo $this->get_field_name('publish_date'); ?>" <?php if((!empty($publish_date)) && ($publish_date == 'date')){echo 'checked';}?> value="date">
         </p>
         <p>
            <label for="<?php echo $this->get_field_id('read_more_link'); ?>"><?php _e('Read More Link : ', 'custom_latest_post_Widget'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('read_more_link'); ?>" type="checkbox" name="<?php echo $this->get_field_name('read_more_link'); ?>" <?php if((!empty($read_more_link)) && ($read_more_link == 'more_link')){echo 'checked';}?> value="more_link">
         </p>
         <p>
            <label for="<?php echo $this->get_field_id('read_more_text'); ?>"><?php _e('Read More Text : ', 'custom_latest_post_Widget'); ?></label>
            <input class="widefat" id="<?php echo $this->get_field_id('read_more_text'); ?>" name="<?php echo $this->get_field_name('read_more_text'); ?>" type="text" value="<?php echo $read_more_text; ?>" placeholder="Read More" />
         </p>
<?php
    }

    function getRealtyListings($numberOfListings, $post_types, $thumbnail_image, $enable_excerpt, $excerpt_length, $publish_date, $read_more_link, $read_more_text) { //html
        global $post;
        add_image_size( 'custom_latest_post_Widget_size', 85, 45, false );
        /*
        if($post_types == 'product'){
            $tax_query = array(array('taxonomy' => 'products_type','field' => 'slug','terms' => 'market-reports'));
        }else{
            $tax_query = '';
        }
        */

        $args = array(
            'post_type' => $post_types,
            'posts_per_page' => $numberOfListings,
            //'tax_query' => $tax_query
        );

        $listings = new WP_Query($args);

        //$listings->query('post_type='.$post_types.'&posts_per_page=' . $numberOfListings . $new_var );
        if($listings->found_posts > 0) {
            echo '<ul class="custom_latest_post_Widget">';

            while ($listings->have_posts()) {
                $listings->the_post();
                $image = (has_post_thumbnail($post->ID)) ? get_the_post_thumbnail($post->ID, 'realty_widget_size') : '<div class="noThumb"></div>';
                $listItem = '<li>';
                if(!empty($thumbnail_image)){
                    $listItem .= '<div class="list_left_thumb">';
                    $listItem .= $image;
                    $listItem .= '</div>';
                }
                $listItem .= '<div class="list_right_thumb">';
                $listItem .= '<a href="' . get_permalink() . '">';
                $listItem .= get_the_title() . '</a>';
                if(!empty($enable_excerpt)){
                    if(!empty($excerpt_length)){
                        $length = $excerpt_length;
                    }else{
                        $length = 100;
                    }
                    $listItem .= '<div class="list_excerpt">';
                    $listItem .= substr(get_the_excerpt(), 0, $length).'...';
                    $listItem .= '</div>';
                }
                if(!empty($publish_date)){
                    $listItem .= '<div class="list_publish_date">'.date('M d Y', strtotime(get_the_date())).'</div>';
                }
                if(!empty($read_more_link)){
                    $listItem .= '<div class="list_link"><a href="'.get_the_permalink().'">';
                    if(!empty($read_more_text)){
                        $listItem .= $read_more_text;
                    }else{
                        $listItem .= 'Read More';
                    }
                    $listItem .= '</a></div>';
                }
                $listItem .= '</div>';
                $listItem .= '</li>'; 
                echo $listItem; 
            }

            echo '</ul>';
            wp_reset_postdata();
        }else{
            echo '<p style="padding:25px;">No listing found</p>';
        } 
    }

} //end class custom_latest_post_Widget
register_widget('Custom_latest_post_Widget');
?>

Tuesday, 3 October 2017

Pay with PayPal and get transaction Detail using simple HTML Form

Pay with PayPal and get transaction Detail using simple HTML Form



<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['invoice_payment']) && !empty($_POST['invoice_payment'])) {
    //$paypal_email = 'sanjay@gmail.com.com';  //DUMMY
    $paypal_email = 'sunil@gmail.com.com';    //LIVE
 
    $return_url = site_url().'/pay-by-paypal/?type=pay_now&invoiceno='.$_GET['invoiceno'].'&paystatus=completed';
    $cancel_url = site_url().'/pay-by-paypal/?type=pay_now&invoiceno='.$_GET['invoiceno'].'&paystatus=canceled';
    $notify_url = '';

    $item_name = 'Pay for Invoice id : '.$_GET['invoiceno'];
    $item_amount = $total_amount;
    $querystring = '';

    // Firstly Append paypal account to querystring
    $querystring .= "?business=".urlencode($paypal_email)."&";

    // Append amount& currency (£) to quersytring so it cannot be edited in html

    //The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.
    $querystring .= "item_name=".urlencode($item_name)."&";
    $querystring .= "amount=".urlencode($item_amount)."&";

    //loop for posted values and append to querystring
    foreach($_POST as $key => $value){
            $value = urlencode(stripslashes($value));
            $querystring .= "$key=$value&";
    }

    // Append paypal return addresses
    $querystring .= "return=".urlencode(stripslashes($return_url))."&";
    $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
    $querystring .= "notify_url=".urlencode($notify_url);

    // Append querystring with custom field
    //$querystring .= "&custom=".USERID;

    // Redirect to paypal IPN
    //header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);   // Dummy Sandbox paypal Payment
    header('location:https://www.paypal.com/cgi-bin/webscr'.$querystring);  //Live Paypal Payment
    exit();
} ?>
<?php
$item_number = mt_rand(100000000000000,999999999999999);
$invoiceno = 9087786546;
$current_userid = get_current_user_id();
?>
<form class="paypal" action="" method="post" id="paypal_form">
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="lc" value="US" />
    <input type="hidden" name="currency_code" value="USD" />
    <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
    <input type="hidden" name="first_name" value="Sunil"  />
    <input type="hidden" name="last_name" value="Sharma"  />
    <input type="hidden" name="payer_email" value="sunil.sharma@gmail.com"  />  <!-- PayPal ID -->
    <input type="hidden" name="paid_by" value="<?php echo $current_userid;?>"  />
    <input type="hidden" name="paid_to" value="<?php echo $writer_id;?>"  />
    <input type="hidden" name="pay_for_invoiceid" value="<?php echo $invoiceno;?>"  />
    <input type="hidden" name="invoice_payment" value="writer_invoice"  />
    <input type="hidden" name="item_number" value="<?php echo $item_number;?>" / >
    <input type='hidden' name='rm' value='2'>
    <input type="submit" name="submit" class="paypal_paynow" value="PAY NOW"/>
</form>


And get response on return URL "$return_url" using $_REQUEST

Thursday, 31 August 2017

Add Event on Google And Outlook Calendar

Add Event on Google And Outlook Calendar


<?php
function google_outlook_calender_event($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location, $title){

    $domain = 'google.com';

    //Create Email Headers
    $mime_boundary = "----Meeting Booking----".MD5(TIME());

    $headers = "From: ".$from_name." <".$from_address.">\n";
    $headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
    $headers .= "Content-class: urn:content-classes:calendarmessage\n";
    
    //Create Email Body (HTML)
    $message = "--$mime_boundary\r\n";
    $message .= "Content-Type: text/html; charset=UTF-8\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= "<html>\n";
    $message .= "<body>\n";
    $message .= '<p>Dear '.$to_name.',</p>';
    $message .= '<p>'.$description.'</p>';
    $message .= "</body>\n";
    $message .= "</html>\n";
    $message .= "--$mime_boundary\r\n";
    
    date_default_timezone_set('America/Denver');

    $ical = 'BEGIN:VCALENDAR' . "\r\n" .
    'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
    'VERSION:2.0' . "\r\n" .
    'METHOD:REQUEST' . "\r\n" .
    'BEGIN:VTIMEZONE' . "\r\n" .
    'TZID:America/Denver Time' . "\r\n" .
    'BEGIN:STANDARD' . "\r\n" .
    'DTSTART:20170701T000000' . "\r\n" .
    'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
    'TZOFFSETFROM:-0300' . "\r\n" .
    'TZOFFSETTO:-0400' . "\r\n" .
    'TZNAME:EST' . "\r\n" .
    'END:STANDARD' . "\r\n" .
    'BEGIN:DAYLIGHT' . "\r\n" .
    'DTSTART:20170701T000000' . "\r\n" .
    'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
    'TZOFFSETFROM:-0800' . "\r\n" .
    'TZOFFSETTO:-0700' . "\r\n" .
    'TZNAME:EDST' . "\r\n" .
    'END:DAYLIGHT' . "\r\n" .
    'END:VTIMEZONE' . "\r\n" .
    'BEGIN:VEVENT' . "\r\n" .
    'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
    'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
    'LAST-MODIFIED:' . date("YmdTHis") . "\r\n" .
    'UID:'.date("Ymd\THis", strtotime($startTime)).rand()."@".$domain."\r\n" .
    'DTSTAMP:20170905T000000' . "\r\n" .
    //'DTSTART;TZID="America/Denver Time":'.date("YmdTHis", strtotime($startTime)). "\r\n" .
    //'DTEND;TZID="America/Denver Time":'.date("YmdTHis", strtotime($endTime)). "\r\n" .
            
    'DTSTART;TZID="America/Denver Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
    'DTEND;TZID="America/Denver Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
    
    //'DTSTART;TZID="America/Denver Time":20170906T000000' . "\r\n" .
    //'DTEND;TZID="America/Denver Time":20170907T000000' . "\r\n" . 
    
    //'DTSTART;TZID="America/New_York Time":20170905' . "\r\n" .  //For Full Day Event on Google
    //'DTEND;TZID="America/New_York Time":20170905' . "\r\n" .    //For full day event on Google
    'TRANSP:OPAQUE'. "\r\n" .
    'SEQUENCE:1'. "\r\n" .
    'SUMMARY:' . $title . '\n' .
    'LOCATION:' . $location . "\r\n" .
    'CLASS:PUBLIC'. "\r\n" .
    'PRIORITY:5'. "\r\n" .
    'BEGIN:VALARM' . "\r\n" .
    'TRIGGER:-PT15M' . "\r\n" .
    'ACTION:DISPLAY' . "\r\n" .
    'DESCRIPTION:Reminder' . "\r\n" .
    'END:VALARM' . "\r\n" .
    'END:VEVENT'. "\r\n" .
    'END:VCALENDAR'. "\r\n";
    $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= $ical;

    $mailsent = mail($to_address, $subject, $message, $headers);
    
    return ($mailsent)?(true):(false);
}


$from_name = "Admin";
$from_address = "sunil.sharma27783@gmail.com";
$to_name = "Sunil";        
//$to_address = "sunilsharma.it7@gmail.com";
$to_address = "sunilsharma.it7@outlook.com";
$startTime = "13-09-2017";
$endTime = "14-09-2017";
$subject = "Post Due Date Event";        
$description = 'This is my custom Description. Link <a href="#">CONTENT LINK</a>';        
$location = "";
$title = 'Courtney: ACL Repair Washington DC';

google_outlook_calender_event($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location, $title);

?>

Thursday, 10 August 2017

Custom Code to create Captcha

Custom Code to create Captcha :- 



<html>
   <head>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
   </head>
   <body>
      <form method="post" action="http://astro-global.blogspot.in/" onsubmit="return checkform(this);">
         <!-- START CAPTCHA -->
         <br>
         <div class="capbox">
            <div id="CaptchaDiv"></div>
            <div class="capbox-inner">
               Type the above number:<br>
               <input type="hidden" id="txtCaptcha">
               <input type="text" name="CaptchaInput" id="CaptchaInput" size="15"><br>
            </div>
         </div>
         <br><br>
         <!-- END CAPTCHA -->
<button type="button" class="refresh_captcha" onclick="refresh_captcha();" title="Refresh Captcha Code"><img src="https://cdn3.iconfinder.com/data/icons/faticons/32/sync-01-128.png"></button>
         <input type="submit" value="Test Captcha">
      </form>
      <script type="text/javascript">
jQuery( document ).ready(function() {
refresh_captcha();
});
         // Captcha Script
       
function checkform(theform){
var why = "";

if(theform.CaptchaInput.value == ""){
why += "- Please Enter CAPTCHA Code.\n";
}
if(theform.CaptchaInput.value != ""){
if(ValidCaptcha(theform.CaptchaInput.value) == false){
why += "- The CAPTCHA Code Does Not Match.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}

function refresh_captcha(){
var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';
var f = Math.ceil(Math.random() * 9)+ '';
var g = Math.ceil(Math.random() * 9)+ '';

var code = a + b + c + d + e + f + g;
jQuery("#CaptchaDiv").html(code);
jQuery("#txtCaptcha").val(code);
//document.getElementById("txtCaptcha").value = code;
//document.getElementById("CaptchaDiv").innerHTML = code;
}
       
       
       
         // Validate input against the generated number
         function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('CaptchaInput').value);
if (str1 == str2){
return true;
}else{
return false;
}
         }
       
         // Remove the spaces from the entered and generated code
         function removeSpaces(string){
         return string.split(' ').join('');
         }
      </script>
      <style>
         .capbox {
         background-color: #92D433;
         border: #B3E272 0px solid;
         border-width: 0px 12px 0px 0px;
         display: inline-block;
         *display: inline; zoom: 1; /* FOR IE7-8 */
         padding: 8px 40px 8px 8px;
         }
         .capbox-inner {
         font: bold 11px arial, sans-serif;
         color: #000000;
         background-color: #DBF3BA;
         margin: 5px auto 0px auto;
         padding: 3px;
         -moz-border-radius: 4px;
         -webkit-border-radius: 4px;
         border-radius: 4px;
         }
         #CaptchaDiv {
         font: bold 17px verdana, arial, sans-serif;
         font-style: italic;
         color: #000000;
         background-color: #FFFFFF;
         padding: 4px;
         -moz-border-radius: 4px;
         -webkit-border-radius: 4px;
         border-radius: 4px;
         }
         #CaptchaInput { margin: 1px 0px 1px 0px; width: 135px; }
button.refresh_captcha {
padding: 0;
border: none;
background: transparent;
/* width: 20px; */
cursor: pointer;
}
button.refresh_captcha img {
width: 30px;
height: 30px;
}
      </style>
   </body>
</html>

Thursday, 20 July 2017

How to get transaction details in notify_url page in paypal

How to get transaction details in notify_url page in paypal


<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST" name="_xclick" id="paypal_form">
   <input type="hidden" name="upload" value="1" />
   <input type="hidden" name="cmd" value="_xclick" />
   <!-- The business email address, where you want to receive the payment -->
   <!--<input type="hidden" name="business" value="yesidealpayment@gmail.com" />-->
   <input type="hidden" name="business" value="sunil@rudrainnovatives.com" />
   <!-- The customer email address -->
   <input type="hidden" name="item_name_1" value="Invoice payment" />
   <input type="hidden" name="amount_1" value="2" />
   <!--<input type="hidden" name="currency_code" value="AUD" />-->
   <input type="hidden" name="currency_code" value="USD" />
   <input type="hidden" name="amount" value="2" /> 
   <!-- Where you want to return after PayPal Payment -->
   <input type="hidden" name="return" value="http://localhost/paypals/response.php" />
   <!-- A back-end notification send to the specific page after successful payment  -->
   <!--<input type="hidden" name="notify_url" value="http://yes-i-deal.com.au/test/paypal.php" />-->
   <input type="hidden" name="notify_url" value="http://localhost/paypals/response.php" />
   <!-- Where you want to return after cancel the PayPal Payment  -->
   <input type="hidden" name="cancel_return" value="http://localhost/paypals/response.php" />
   <input type="hidden" name="custom" value="25" />  
   <input type="image" name="submit"   src="http://localhost/paypals/themes/green/images/Buy-Now-Button.png" />
</form>



In my notify_url page I am getting values as : 

<?php
echo "<pre>";
print_r($_REQUEST);
echo "<pre>";
?>

Wednesday, 28 September 2016

Codeignetor Code


https://drive.google.com/open?id=0B4i05RJ0-BFRZXhEWTVzWVBHblk

Thursday, 15 September 2016

Wordpress Custom Category Template WIth Custom Pagination

Wordpress Custom Category Template WIth Custom Pagination


1) Create new file for custom taxonomy and upload in wordpress theme taxonomy-(taxonomy-name).php
    Example : Id Taxonomy name is "vacancies_uts". Then file name is "taxonomy-vacancies_uts.php".


2) Add this code in functions.php file for pagination anywhere in website

 
<?php
/************ Pagination Function START *************/
function wp_pagination() {
    global $wp_query;
    $big = 12345678;
    $page_format = paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'type'  => 'array'
    ) );
    if( is_array($page_format) ) {
        $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
        echo '<div><ul>';
        echo '<li><span>'. $paged . ' of ' . $wp_query->max_num_pages .'</span></li>';
        foreach ( $page_format as $page ) {
                echo "<li>$page</li>";
        }
       echo '</ul></div>';
    }
}
/************ Pagination Function END *************/
?>
   
3) Add below code in "taxonomy-vacancies_uts.php" and upload in activated theme.

<?php
/**
 * The template for displaying all pages.
 *
*/


get_header(); ?>
<?php

$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$term_name = $queried_object->name;
?>
<div id="content" class="content" role="main">

<?php
$today = date('m/d/Y');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

query_posts(array(
//'posts_per_page' => 2,
'post_type' => 'vacancies', //Post Type
'post_status' => 'publish', //Post Status
'tax_query' => array(
    array(
        'taxonomy' => 'vacancies_uts', //Texonomy Name
        'field' => 'id',
        'terms' => $term_id
    )
),
'meta_query' => array(
    array(
        'key' => 'last_date',  //Meta Field name for compare
        'value' => $today,     //Meta Field Value compare with this value
        'compare' => '>='
    )
),
'paged' => $paged
)
);
?>
<?php if ( have_posts() ) : ?>
<div class="cat_heading"><div class="cat_name"><?php echo $term_name;?></div></div>
<table class="vacancies_tables">
<?php while ( have_posts() ) : the_post(); ?>
    <?php $vacancies_elgible = get_the_terms( get_the_ID(), 'vacancies_elgible' );?>
    <tr>
        <td class="vac_title" data-label="Exam"><a href="<?php echo get_the_permalink();?>"><?php echo get_the_title();?></a></td>
        <td class="detail_link" data-label="Details"><a class="home_viewmore" href="<?php echo get_the_permalink();?>">View More</a></td>
    </tr>
<?php endwhile; ?>
</table>
<div class="custom_pagination"><?php wp_pagination(); ?></div>
<?php else : ?>

<?php //get_template_part( 'no-results', 'page' ); ?>
<?php echo "Sorry, no vacancies available under this Category."; ?>

<?php endif;?>

</div><!-- #content -->

<?php get_footer(); ?>