Wednesday 26 July 2017

How to print using jquery


Simply just add print.js Library and configure as

JQuery:

    jQuery(".print-button a").on('click', function() {
                  
        jQuery(this).parent().find('.maincontainertoprint').print({

            globalStyles : true,
            mediaPrint : true,
            stylesheet : 'yourstyle.css',
            iframe : false,
            noPrintSelector : ".button, .printbtn",
            deferred: jQuery.Deferred().done(function() { console.log('Printing done', arguments); })
        });
    });


Html:


<div class="maincontainer">
    <div class="print-button">
        <a href="javascript:void(0)" class="">Print</a>
    </div>
    <div class="maincontainertoprint">
        <table>
            <tr>
                <th>S.No.</th>
                <th>Name</th>
                <th>Email</th>
            </tr>
            <tr>
                <td>1</td>
                <td>Bharat</td>
                <td>bharat@gmail.com</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Ravi</td>
                <td>ravi@gmail.com</td>
            </tr>
            <tr>
                <td>3</td>
                <td>Ajay</td>
                <td>ajay@gmail.com</td>
            </tr>
            <tr>
                <td>4</td>
                <td>Gagan</td>
                <td>gagam@gmail.com</td>
            </tr>
        </table>
    </div>
</div>

Library

Monday 17 July 2017

How to hide date picker on button click

How to hide date picker on button click

#ui-datepicker-div is parent div in which calendar is shown
<input type="button" id="edit-field-date-value-value-datepicker-popup-1" value="close" onclick="return dtPickerClose()" />

function dtPickerClose(){
    jQuery('#ui-datepicker-div').hide();
    jQuery("#edit-field-date-value-value-datepicker-popup-1").attr("class","");
}

this also work in drupal

Monday 10 July 2017

Get Distance between Two Lat-Long

Get Distance between Two Lat-Long

Just simple use This script


function distance($lat1, $lon1, $lat2, $lon2, $unit) {

  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = round($dist * 60 * 1.1515);
  $unit = strtoupper($unit);

  if ($unit == "K") {
    return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}

echo distance(51.49094, -2.692207, 51.452775, -2.417631, "M") . " Miles<br>";
echo distance(51.49094, -2.692207, 51.452775, -2.417631, "K") . " Kilometers<br>";
echo distance(51.49094, -2.692207, 51.452775, -2.417631, "N") . " Nautical Miles<br>";

Friday 7 July 2017

How to create HMVC(Hierarchical Model View Controller)?

How to create HMVC(Hierarchical Model View Controller)?

Download HMVC Library from https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads/

It contains two folder folder core & third_party. Put files from those folder to your application/config/core & application/config/third_party

now check your site if it show error "Fatal error: Call to undefined method MY_Loader::_ci_object_to_array() in" then change Line 300 in third_party/MX/Loader.php
        
         return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
     with
        if (method_exists($this, '_ci_object_to_array'))
        {
                return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
        } else {
                return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
        }
Now create Folder in application/config/modules/foo/views/yourview.php & application/config/modules/foo/controllers/Foo.php
create same way for another  application/config/modules/bar/views/yourview.php & application/config/modules/bar/controllers/Boo.php

now access
http://localhost/yourproject/index.php/foo
http://localhost/yourproject/index.php/bar

Now if you want to access bar controller in foo view you can call as

<?php
    // syntax Modules::run("module/controller/function");
    echo Modules::run("bar/bar/index");
   
?>


Codeigniter Route

$route['what-will-typed-in-url']='what-action-to-perform';

//ex. url will like http://localhost/ci_testing/index.php/user/123

for this kind of url we don't have any 123 function in user controller but if this kind of url comes so we have to call user/myprofile function which means myprofile function of user controller. so for this we will create a route as:

$route['user/:num']='user/myprofile/$1';



here :num indicates any number after user and $1 will pass that number to myprofile function

we have to define this route in routes.php in config folder

Monday 3 July 2017

How to replace mysql select query parameter in query

table structure (tabme name= tbl_users)

id     name        image
1      Raju         raju.jpg
2      amar        amar.jpg
3      jay            jay.jpg


now I want to show full url to image like

id     name        image
1      Raju         http://localhost/uploads/raju.jpg
2      amar         http://localhost/uploads/amar.jpg
3      jay            http://localhost/uploads/jay.jpg


to achieve this we just have to write query as


$sql = "SELECT id, name, image, REPLACE( image, image, CONCATE( "http://localhost/uploads/", image ) ) AS newimage FROM `tbl_users`";


REPLACE(fieldname,'replace what', 'replace with')
CONCATE(field1,'field2' ..)