Friday 29 November 2013

Reload the Page via AJAX using Jquery

/** Reload the Page via AJAX using Jquery. */
(function () {
 $('#dvLoading').fadeOut(10); // To Switch Off the loader..

 location.reload();
 
} ()); 

Wednesday 27 November 2013

To serialise the Input Form field by ID using Jquery

/** To serialise the Input Form field by ID using Jquery. */
var formData = new FormData(document.getElementById("fieldId"));
alert(formData);

Wednesday 20 November 2013

Jquery function to auto scroll to the page to any position in Javascript

Please find the below function to make auto scroll of the page based on the parameter provided.

/** Auto Scroll to Top. */
var autoScrollToTop = function (value) { 
 
 //var scrollTopVal = 90; 
 if (typeof value == 'undefined') { 
  var scrollTopVal = 90;
 }
 else if ((value != "") && isNaN(value)) {
  scrollTopVal = $(value).offset().top;
 }
 else if (value > 0 ) {
  scrollTopVal = value;
 }
 //alert(scrollTopVal);
 $('html, body').animate({ scrollTop: scrollTopVal }, 500); // 500 (mili second) or 'slow'
};

// The function can be called as below;
autoScrollToTop() // Type: Blank, (Default:90)-> Scroll to 90px from top.
autoScrollToTop(0) // Type: Zero -> Top scroll to very top
autoScrollToTop(150) // Type: Numeric -> Scroll to Provided Numeric value(150px) from top.
autoScrollToTop('.className'); // Type: 'className' -> Auto calculate the distance from top to that className component
autoScrollToTop('#elementID'); // Type: 'elementID' -> Auto calculate the distance from top to that elementIDcomponent


Wednesday 30 October 2013

Codeigniter Pagination problem to locate the current page (if using CI default Library), AJAX Pagination Calls

If you are using default CI Pagination library then it would be chances of displaying the current page active although results status is displaying correctly.

In particular, when you are using config/routes.php to rewrite the URLs.

Well, if that case, you can resolve that issue by adding the uri_segment's value while initializing the pagination as below;

PS:  First find which segment of URI carries the page value, then add the segment value (not page value coz once you provide segment value then, it will use it to pull out the page value)
// Locate the uri_segment to locate the current page value.
$pagination['uri_segment'] = 3; 
Also, if you are wondering how to find the uri_segment value, then use below code to print all uri_segments array
$segments = $this->uri->segment_array();
print_r($segments);
Please find the sample pagination code as below;
$pagination = array();
$pagination['start']  = $start+1;
$pagination['limit']  = $limit;
$pagination['per_page'] = $limit;
$pagination['ipage']  = $ipage;
$pagination['total_rows'] = $this->m_yourmodel->function_result_count($where=array()); // only pull the approved ones.
$pagination['anchor_class'] = 'class="loadAjaxPage" '; // This class is added to make a AJAX Call if you want to load the pages via AJAX
$pagination['offset']  = ($start+$limit); // This is just for the View;

$pagination['uri_segment'] = 3; // Locate the uri_segment to locate the current page value.

$this->load->library('pagination');
$this->pagination->initialize($pagination);
a$pagination['page_links'] = $this->pagination->create_links();

To Load the Page from AJAX Call
Also I have added the loadAjaxPage class name on anchor_class pagination variable to load the page from AJAX calls.
// This class is added to make a AJAX Call if you want to load the pages via 
$pagination['anchor_class'] = 'class="loadAjaxPage" ';

Friday 25 October 2013

How to configure WorldPay Payment System with WooCommerce

To configure WorldPay Payment System with WooCommerce
Please configure the WorldPay setting as per below image.

The Pay Back Response URL should the URL of the website where you want to revert/redirect back once the Payment is Successful or Failure.

Also, on that response page, you can use $_POST / $_REQUEST variables to collect the payment response data and manipulate it as per your needs.

Tuesday 1 October 2013

How to change the Folder/File permissions from Plesk Control Panel for Windows Server

To change the Folder/File permissions from Plesk Control Panel for Windows Server

For users on Plesk for Windows:
  1. Login to Plesk control panel using the URL  https://webX.3essentials.com:8443 X=10,12,14,16,18 (Refer welcome email for credentials)
  2. Click on the domain name for which you want to change the permission.
  3. Click on the File Manager icon, You will see a few folders like private,httpdocs,httpsdocs These are base folders and if you need to give permissions to any of these as a whole, you need to submit a support request.
  4. Click on the httpdocs folder.You will mostly need to set permission for the files/folders inside the httpdocs folder, which is the root folder of your domain
  5. Decide the file/folder you want to set permission,and towards the right side of that you will see a 'lock' symbol  ,Click on that
  6. You'll see a list of Group or user names (like those listed in the follow bullets) and towards the right side of that you'll see permissions for that user:
    • Administrators
    • SYSTEM
    • Plesk Domain User (number)
    • FPSE_number
    • Plesk IIS User (IUSR_number)
    • Plesk IIS WP User (IWPD_number(number))
  7. This is where you need to set permissions.
    • For php scripts add MODIFY to your IUSR account
    • For asp: add MODIFY to your IWPD account
    • For asp.net: It  will run under your IWPD account by default unless you have impersonation enabled in your web.config (which you should use if using asp.net), in which case it will impersonate the IUSR account - add MODIFY to the appropriate account.
    • For access databases(.mdb files), you might need to give write/modify permission to the file/folder depending on the scripting technology that you're using as given above.
  8. Setting up Access Permissions
    • Allow inheritable permissions from the parent to propagate to this object and all child objects. Include these with entries explicitly defined here --> This check  box will allow you to inherit the permission to child objects from the parent folder.
    • Replace permission entries on all child objects with entries shown here that apply to child objects. -> This will propagate the permission from the current folder to the child folders
  9. Click on  Advanced Options for changing the permissions to allow/deny a user.(For advanced users only)
  10. Click OK to save the change after every action.

Wednesday 18 September 2013

Show cart contents or total items on Woocommerce (Wordpress)

Show cart contents or total items on Woocommerce (Wordpress)
// To display the cart contents and total in your template use something like:
// To ajaxify your cart viewer so it updates when an item is added (via ajax) use:
global $woocommerce; 

echo '< a class="cart-contents" href="http://www.blogger.com/'.$woocommerce-%3Ecart-%3Eget_cart_url().'" 
title="'. _e('View your shopping cart', 'woothemes').'" >'. sprintf(_n('%d item', '%d items',
$woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count)
.' - '. $woocommerce->cart->get_cart_total().'< /a>
- How to use WooCommerce without a Products Page
- Express Lane Shopping: Improving the WooCommerce add to cart button

Tuesday 10 September 2013

CSS classes selecter [class*=“span”] [class^="classname"][class$="classname"]

CSS classes selecter [class*=“span”] [class^="classname"][class$="classname"] examples below;
.show-grid [class*="span"] {
    background-color: #eee;
    text-align: center;
    border-radius: 3px;
    min-height: 30px;
    line-height: 30px;
}
It's an attribute wildcard selector. In the sample you've given, it looks for any child element under.show-grid that has a class that CONTAINS span.
So would select the  element in this example:
< div class="show-grid">
     class="span6">Blah blah
< /div>
You can also do searches for 'begins with...'
div[class^="something"] { }
which would work on something like this:-
< div class="something-else-class">< /div>
and 'ends with...'
div[class$="something"] { }
which would work on
< div class="you-are-something">< /div>

Wednesday 28 August 2013

Javascript function to print the selected Div Tag content

Please find the javascript (no JQuery) function below to print the selected content below;
// To print selected portion of HTML content
function printDivContents(divId) {    
 var divToPrint = document.getElementById(divId);
 var popupWin = window.open('', '_blank', 'width=500,height=500,scrollbars=yes');
 popupWin.document.open();
 popupWin.document.write('< html>< body onload="window.print()">' + divToPrint.innerHTML + '');
 popupWin.document.close();
}

Thursday 22 August 2013

Reloading/Refreshing the image element(same filename) via Jquery AJAX

How to reload/refresh an element(image) in jQuery : Reloading/Refreshing the image element(same filename) via Jquery AJAX
$("#image1").attr("src", "{$base_url}tmp/survey/image1.png?ts=" + new Date().getTime());
$("#image2").attr("src", "{$base_url}tmp/survey/image2.png?ts=" + new Date().getTime());
Please check below the example of deployed function via AJAX...

function viewReportBtn(id) 
{  
 $('#survey_id').val(id);
 $('#dvLoading').show(); // Loader On
 
 var formData = $("#thisForm").serialize();
 
 $.ajax({ url: '{$base_url}school/reports/view',
  data: formData,
  type: 'post',
  complete: function(output) {
   var str = output.responseText;
   resultStatus = str.substr(0,7);
   resultText = str.substr(7,(str.length));
   
   if (resultStatus == 'success') {
    $('#searchResult').show().html(resultText); // show the result list on a search result container
    $("#lineChart").attr("src", "{$base_url}tmp/survey/linechart.png?ts=" + new Date().getTime());
    $("#pieChart").attr("src", "{$base_url}tmp/survey/piechart.png?ts=" + new Date().getTime());
   } else {
       $('#searchResult').html('').hide(); // hiding the search result container
   }
   $('#dvLoading').fadeOut(10); // To Switch Off the loader..
  }
 });
}

Monday 29 July 2013

Create the N-level Categories tree with single SQL query using CI

To create the N-level Categories tree with single SQL query using CI
class Category_model extends Model {

 private $table = 'categories';
 private $selectTreeOptions_data = null;
 private $selectTreeOptions_index = null;
 
 public function get_categories() {
  $this->db->select('c.id, c.parent_id, c.name');
  $this->db->from($this->table .' AS c');
  $this->db->where('c.status', '1');
  
  $query = $this->db->get();
  //$str = $this->db->last_query();
  
  return $query->result_array();
 }
 
 /*
  * Recursive top-down tree traversal example:
  * Indent and print child nodes
  */
 function getSelectTreeOptions($parent_id, $level, $selected_id='')
 {
  $html = '';
     $data = $this->selectTreeOptions_data;
     $index = $this->selectTreeOptions_index;
     $parent_id = $parent_id === NULL ? 0 : $parent_id;
    
     if (isset($index[$parent_id])) {
         foreach ($index[$parent_id] as $id) {
          $selected = isset($selected_id) && ($selected_id==$data[$id]["id"]) ? 'selected="selected"' : '';
             $html .= '\n";
             $html .= $this->getSelectTreeOptions($id, $level + 1, $selected_id);
         }
     }
          
     return $html;
 }

 // Get the category tree with select options.
 function get_categories_tree_options($selected_id='')
 {
   $categories = $this->get_categories();
  $this->data = '';
  $this->index = '';
  
  foreach ($categories as $row) :
      $id = $row["id"];
      $parent_id = $row["parent_id"] === NULL ? "NULL" : $row["parent_id"];
      $this->selectTreeOptions_data[$id] = $row;
      $this->selectTreeOptions_index[$parent_id][] = $id;
  endforeach;
  
  $items = $this->getSelectTreeOptions(NULL, 0, $selected_id);
  
  return $items;  
 }
 
}

Category_model::get_categories_tree_options($selected_id='');

Monday 22 July 2013

Joomla + GROUP_CONCAT (ORDER BY, SEPARATOR)

To fetch the Joomla Categories in sorted order, GROUP_CONCAT and order by with seperator.

/* Fetching all the Childs skills into a list. */
$this->_db->setQuery($this->_db->getQuery(true)
 ->from('#__categories')
 ->select('GROUP_CONCAT(title ORDER BY lft ASC SEPARATOR ", ") as skills')
 ->where('parent_id="'.(int)$parent_id.'" AND published="1"')
 ->order('lft ASC'));
$child = $this->_db->loadObject();

Tuesday 16 July 2013

Reminiscence always leftovers

Why someone can do such a silly mistake 
by making away with oneself...

Why the other side of the surrounding couldn't be seen, 
though family and friend always there for good and either. 

Difficulties ever opted to be allotted for dissolution 
and none would be misfortunates. 

Certainly, it can't be unfasten, 
nevertheless reminiscence always leftovers. 

Alas! overwhelming compassion to those ones... :-(

~ in memory of someone

Wednesday 12 June 2013

Joomla Extension installation problem : "JFolder::create: Could not create directory"

If you are facing the problem to install any extensions under joomla (on live or local) with the following errors;
JFolder::create: Could not create directory
Warning: Failed to move file!

Then there would be following issues;

1. The PHP temporary directory is not set
( The PHP temporary directory is the directory that PHP uses to store an uploaded file before Joomla can access this file. )
Solution:
To resolve it
  • Go to your main Joomla directory and look for a folder called /tmp/ and if there isn't one, create it.
  • Check for its File Permission which should be 0755. If not set the folder permission to 0755. This is because the /tmp/ folder must be readable and writable. (To 
PS: To change the permission, go to Hosting Cpanel > File Manager > Select the directory (do right click it and Change Permissions ). For Window Hosting Panel, it can be slightly different, check for for that.

2. The /tmp/ folder path on the Global Configuration must be set correctly.
Solution:
  • In your Joomla Administrator area, go to Site > Global Configuration > Server.
  • Check to see that the Path to Temp Folder is the path to the one you found our created in the last step. This should be the server path not the URL (http://yoursite.com etc)
If you've transferred your site between servers this will definitely need to be checked. You can also change this by changing the configuration.php file. There is a complete tutorial on all the sections of the configuration.php file here.

Thursday 6 June 2013

To Install GIT on CentOS 5.2 server using WHM CPanel


It may be slightly different to install GIT on CentOS 5.2 server using WHM CPanel. However, I found below steps working for me to install it.

First, make sure you are logged in as ROOT via SSH using PUTTY application.
Then, do the following;
$ su // (login as root)
$ yum update

// To install yum fastest mirror plugin (yum-plugin-fastestmirror) you can use this command:-

$ yum install yum-fastestmirror

// OR

$ yum install yum-plugin-fastestmirror

Once the installation completed, check the plugins status by editing the file /etc/yum.conf and add the following line to the file:
$ plugins=1
// Install the dependencies

yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel

// Get the git source code ( http://distfiles.macports.org/git-core/ )
wget http://distfiles.macports.org/git-core/git-1.8.2.tar.gz


// untar/uncompress the git source code
tar xvfz git-1.6.1.tar.gz

// Install the files
cd git-1.6.1.tar.gz

make prefix=/usr/local all

make prefix=/usr/local install

Thursday 23 May 2013

How to Disable/Turn off magic quotes gpc for Joomla 3.0

In Joomla 3.0, if the magic quotes is ON on server, then it will add the slashes when we have quotation marks (double/single) or adding any images, and it will cause the content to display on the proper format.

To turn off/disable magic quotes gpc for Joomla 3, please follow the below steps.

For most Share Hosting Servers running a CGI-Webinterface 
1. Create a php.ini file and add following code:
# To turn off/disable magic quotes gpc for Joomla
magic_quotes_gpc = Off
extension=pdo.so
extension=pdo_mysql.so

2. Put it in your Joomla 3 root. Then change the htaccess.txt in your Joomla 3 root to .htaccess. Add the following lines to the .htaccess file (at the top) :
# To turn off/disable magic quotes gpc for Joomla

  suPHP_ConfigPath /home/username/public_html/yourJoomlaFolder
  
    order allow,deny
    deny from all
  

Change "username" and "yourJoomlaFolder" to your respective folders.
The "/home/myusername/public_html/yourJ3folder" can be found via the Global Configuration:

OR, if you have Joomla running under /public_html folder, then just add "/home/myusername/public_html" and it will work. .htaccess for some hosts.

 For some hosts, add "php_flag magic_quotes_gpc off" to the .htaccess file.

source: http://docs.joomla.org/How_to_turn_off_magic_quotes_gpc_for_Joomla_3

Friday 19 April 2013

Add POP-UP feature for Image and Video in Joomla 2.5/3.0

To add or enable the Pop UP feature in Joomla 2.5 or 3.0 for Images and Videos; Please follow the following steps;
  1. Login into Joomla/Administrator
  2. Go to Template Manager
  3. Click on Templates
  4. Click on [Template Name] Details and Files link of your template in the Templates List.
  5. Click on the Edit main page template link of the Template Master Files.
  6. And, add the below code on the top of the file and Save it.
defined ( '_JEXEC' ) or die ( 'Restricted access' ); 
// Add the below code underneath the above line.
JHtml::_('behavior.modal');
Once you have done with above steps, to use of POP-UP function; Just add the class="model" in the anchor tag
Link

And, To add the Pop-UP for Videos, please download the Rokbox joomla plugin and install it. And, to use it, please follow the below example.

 
Click to Play Video

Monday 15 April 2013

Customize the Page Title in your Component Joomla 2.5/3.0

To customize the any Page Title, please follow the below instructions.

// Create the document object.
$docHTML = JFactory::getDocument();

// Fetch the Default Page title.
$defaultPageTitle = $docHTML->getTitle();

// Change the New page title as per your needs.
$newPageTitle = $pageTitle . ' - '. $docHTML->getTitle()

// Set the New Page Title.
$docHTML->setTitle(  $newPageTitle );

// To display the above set new page title.
Please, Open the Index.php file from the selected templates folder e.g. root/templates/yourSelectedTemplate/index.php. Then, add the below code on the top.
//And the below codes just underneath the 
defined ( '_JEXEC' ) or die ( 'Restricted access' ); 

// Display the Page Title.
$app = JFactory::getApplication(); 
$this->setTitle( $this->getTitle()  . ' - ' . $app->getCfg( 'sitename' ) );

Monday 25 February 2013

Print the query string in Joomla

Print the query result into a string in Joomla
// Then the query result into a string.
print_r($query->dump()); die;

Monday 18 February 2013

301 Redirection from Multiple Domains

If you have domains: domain1.com, domain2.com and domain3.com and you want to do 301 redirection.
In this case, first:
  1. Just host the domain1.com into the server.
  2. Park the domain2.com and domain3.com under the domain1.com hosting account. 
  3. Then, create a .htaccess file on the domain1.com /public_html folder in the server. 
  4. And, the following code into the .htaccess file which is for making 301 redirection (page to page redirection) to domain1.com.
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain1\.co\.uk
RewriteRule (.*) http://www.domain1.co.uk/$1 [R=301,L]

Saturday 9 February 2013

PHP Code to Clear the Browser (Local) Cache

PHP Code to Clear the Browser (Local) Cache including Joomla and Wordpress CMS


Thursday 7 February 2013

Insert Multiple Records using Single Query in Joomla

Insert multi-record using single query in Joomla.

 /**
  * Insert the attributes into website.
  *
  * @return boolean If found return true else falase.
  */
 protected function saveAttributes($member_id, $data) 
 {
  // Build the values for multi-row insert.
  $values = array();
  foreach ($data as $attribute_id => $value)
  {
   $values[] = "('".$member_id."','".$attribute_id."','".$value."', '1')";
  }
  $values = implode(',', $values);
  
  // Build the insert query
  $sql = 'INSERT INTO #__bmember_attribute_vals (`mid`, `attribute_id`, `value`, `state`)
    VALUES'.$values;
  
  $db  = $this->getDbo();
  $query = $db->getQuery(true); // Reset the $query variable.
  $db->setQuery($sql);
  $db->query();
 }

Generate the Unique Alias or Unique string in PHP or Joomla

Generate the Unique Alias or Unique string in PHP or Joomla The below code is to check the Alias in joomla 2.8
/**
  * Find unique Alias name if current doesn't exist.
  * @param string $alias
  * 
  * @return string Return the unique alias value.
  */
 protected function getUniqueAlias($alias)
 {
  $alias_ini = $alias;
  $i = 0;
  
  while ($this->isAliasExist($alias))
  {
   $alias = $alias_ini .'-'.++$i;   
  }
  return $alias;
 }
 
 /**
  * Check the 'alais' in the database.
  *
  * @return boolean If found return true else falase.
  */
 protected function isAliasExist($alias) 
 {
  // Initialise variables.
  $db  = $this->getDbo();
  $query = $db->getQuery(true);
  
  $query->select('m.id, m.alias');
  $query->from('#__bmembers m');
  $query->where('m.alias="'.$alias.'"');
  $db->setQuery((string)$query);
  
  $results = $db->loadObjectList();
  
  return (count($results)>0) ? true : false;
 }


Tuesday 5 February 2013

To clear $query object, to dump the query and nesting loop in Joomla

To clear the previous values from the query var.
/* This needs to be added while using nesting loop to clear the previous query in Joomla Component Writing. */
$query = $db->getQuery(true);
This is to print the built query or dump query.
/* This is to print the built query or dump query. */
echo $query->dump();
Find the sample query as below;
  $data = array();       
  $query->select('c.id, c.alias, c.title');
  $query->from('#__categories c');
  $query->where('c.alias not in ("admin") and c.extension="com_bmember" and published="1"');
  $query->order('c.title asc');
  $db->setQuery((string)$query);
  $categories = $db->loadObjectList();
  
  if (is_array($categories) && ($categories)>0)
  {
   $i=0;
   foreach ($categories as $category)
   {
    $data[$i]['catid'] = $category->id;
    $data[$i]['category'] = $category->title;
    $data[$i]['attributes'] = array();
    
    $query = $db->getQuery(true); // This needs to be added while using nesting loop to clear the previous query.
    $query->select('af.id, af.attribute, af.alias');
    $query->from('#__bmember_attribute_fields af');
    $query->where('af.catid="'.$category->id.'" and af.state="1"');
    $db->setQuery((string)$query);
    $rows = $db->loadObjectList();
    $query->order('af.attributes asc');
    $i++;
   }
  }

Tuesday 15 January 2013

Enable Use Lightbox in Joomla 2.5/3.0


If you decided that you want to have a lightbox on your Joomla site, you probably know what is it about. But, let’s just mention that the Lightbox is a JavaScript technique to display images and content using modal dialogs. Why do you need this? Because it’s clean, nice looking, effective and easy for implementation.
We will learn how to display
  •     images in modal popup window
  •     external content
First thing we have to do is to add a bit of JavaScript support to our page.
To do this, paste the following code in the top of your main template file (ex. index.php) :


 When you did this, just use the link in the following format in your article or page.

< a href=”my-url” class=”modal”> Image or Text for a popup < /a>


For displaying content in the modal popup window you need a bit more code:

< a 
href="/sample/lightbox.html?map=1&act=3"
 class="modal" rel="{handler: 'iframe', size: {x: 575, y: 300}}">link
 to a modal popup with a dimension of 600px by 300px< /a> 

 It’s pretty much same as displaying images, expect we have “rel” attribute where we are saying that iframe should be used, and we also define exact size of the window were our content will be displayed.

source