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