Saturday, 23 May 2015


One day I got crazy sloving picture/number grid puzzle available in windows desktop gadget. Then suddenly why I can't try create the same puzzle of my own using html, js & css and the result is what you are seeing.

Getting started with CiviCRM

FSF-CiviCRM is a popular Customer Relationship Management (CRM) system. The first step in getting started is understanding the CiviCRM codebase. For better understanding, please download CiviCRM zip file from and install.

Object Oriented Programming

CiviCRM core is built using OOP singleton concept. Singleton framework is one which initiates one class object only once and reuses it afterwards.

Business logic

CiviCRM business logic is handled in directory 'CRM/' in the root of CiviCRM installation. In this directory, you can see core functionalities such as Groups, Contacts, Profiles etc. Each of them inturn has directories named DAO, BAO, Form, Page etc.


DAO stands for Data Access Object, which acts as wrapper layer around database. It is recommended to use DAO to interact/manage database data.


BAO is abbreviation of Business Access Object. Actually, BAO is used to extend the DAO for handling business logic.


Form in CiviCRM is implemented as a class extending CRM_Core_Form, which is done using the following methods: preProcess - retrieve data before processing form, buildForm - generate html form using QuickBuildForm helper functions, formRule - form validation rules and postProcess - form subit handler. Also, there will be separate template for each form, which can be found in 'templates/Form/' directory.


If the screen isn't Form, it will be Page. Page is also class similar to Form extended from CRM_Core_Page. The methods available for Page preProcess, run - which displays the page content. Template for the page can be found in the directory 'templates/Page/'.


xml directory contains menu structure of urls mapping to CRM form or page classes and controls access to these URLs using permissions.


Directory which contains templates of Form, Page etc.
Go through the CiviCRM core for better understanding. Also, before starting work on CiviCRM, please post your plan of work to civicrm forum OR consult other developers instantly on CiviCRM IRC

Saturday, 2 May 2015

Geany editor snippets for Drupal

This article discuss about setting snippets for Geany, a light weight IDE especially for Drupal 7 web developers as per coding standards. For those whom doesn't know, snippets are a small piece of source code which are meant for reuse. For example: while coding instead of typing full if conditional statement structure for each time we can just reuse them by the means of creating snippet for the same.

Creation of snippet is simple as like coding in any language. Before implementing custom snippets for Drupal 7 as per coding satandard we have to study about geany snippets.conf file structure, which can be found in '/home/user/.config/geany'.
Firstly we can look on the keywords available
  1. '\n' OR '%newline%': Used for new line.
  2. '\t' OR '%ws%': Used for one indentation step.
  3. '\s': Used for white space.
  4. '%key%': Keys defined in special section.
  5. '%cursor%': Defines where the cursor has to be placed. We can use multiple cursors in one snippet and can be jumped to next cursor position by using 'Move snippet cursor' keybinding.
Now we can look on important sections available in snippets.conf file.
  • Default is where we define snippets for files type other than the defined or known file types.
  • Special is where we can define our own special configuration keywords like

    # special keys to be used in other snippets, cannot be used "standalone"
    # can be used by %key%, e.g. %brace_open%
    # nesting of special keys is not supported (e.g. brace_open=\n{\n%brace_close% won't work)
    # key "wordchars" is very special, it defines the word delimiting characters when looking for
    # a word to auto complete, leave commented to use the default wordchars
  • Keybindings is where we can define keybindings or keyboard shortcut for snippets defined.

    # Optional keybindings to insert snippets
    # Note: these can be overridden by Geany's configurable keybindings
  • PHP is where we define snippets for php files.
For Drupal 7 snippets, we have to define snippets in php section like:


if=// Documentation.\nif (%cursor%)%block_cursor%
els=else%brace_open%// Documentation.%brace_close_cursor%
eli=elseif (%cursor%)%brace_open%// Documentation.%brace_close_cursor%
whi=// Documentation.\nwhile (%cursor%)%block_cursor%
do=// Documentation.\ndo%block% while (%cursor%);%cursor%
swi=// Documentation.\nswitch (%cursor%)%brace_open%case %cursor%:\n\t\t%cursor%\n\t\tbreak;\n\tdefault:\n\t\t%cursor%\n}%cursor%
try=// Documentation.\ntry%block%\ncatch (%cursor%)%brace_open%// Documentation.%brace_close_cursor%
for=// Documentation.\nfor (%cursor%; %cursor%; %cursor%)%block_cursor%
fun=\n/**\n * Documentation.\n */\nfunction %cursor%(%cursor%)%block_cursor%arr=array(\n\t%cursor%\n)%cursor%
foe=// Documentation.\nforeach (%cursor% as %cursor% => %cursor%)%block_cursor%
You can try these by copy and paste on snippets.conf file's PHP section. Save the file and type if and press tab to see the geany snippets magic. The following will create if conditional statement structure and cursor will be focused on first '%cursur%', to move next step press the keyboard shortcut for 'Move snippet cursor' which can be set in edit -> preferences -> keybindings -> editor Action section. In these snippets definition you have noticed the special keywords such as '%brace_open%', '%brace_close%' and '%block%' which are defined in Special section as explained above.
Like this you can create or customize already available snippets. Firstly using snippets take time, gradually on practice these will reduce the time of development. Hope this will help you using geany editor for Drupal development.

Set up Authorize.Net ARB to work with Drupal commerce is a popular alternative to Paypal for eCommerce websites especially its recurring transaction product - ARB (Automated Recurring Billing). Drupal support for Authnet ARB is available through Ubercart but it is not available for Drupal_commerce. However there is a workaround to setup ARB to work with Drupal commerce. Read on to know more.

There is no ARB module for Drupal commerce but there is a sandbox module - Authnet ARB This module does not work straight out of box but you need to make a few changes. But before that lets get familiar with the module
Drupal authnet_arb sandbox module uses SDK for ARB API request, so we have to install the sdk for using this module. First of all we can look on what else features the authnet_arb module provide and then we can look on how to integrate it with drupal commerce.

Features provided by authnet_arb module.

  1. Payment method for ARB:
    The sandbox module provides an additional payment method named 'Recurring payments with Authorize.Net ARB (with credit card)' along with default drupal commerce payement methods. Enabling this payment method, we get an option for choosing 'Recurring payments' method of payment in drupal commerce payment form.
     * Implements hook_commerce_payment_method_info().
    function authnet_arb_commerce_payment_method_info() {
     $payment_methods = array();
     $payment_methods['authnet_arb'] = array(
      'base' =>  'authnet_arb',
      'title' => t('Recurring payments with Authorize.Net ARB (with credit card)'),
      'short_title' => t('Authorize.Net ARB CC'),
      'display_title' => t('Recurring payments'),
      'description' => t('Integrates Authorize.Net ARB for transactions.'),
      'callbacks' => array(
        'settings_form' => 'authnet_arb_commerce_settings_pane',
        'submit_form' => 'authet_arb_payment_pane',
        'submit_form_submit' => 'authet_arb_payment_pane_submit',
        'submit_form_validate' => 'authet_arb_payment_pane_validate',
       'file' => '',
     return $payment_methods;
  2. Silent post URL:
    Silent post is the feature provided by Authorize.Net, which will post a http request to our domain silent url (which we need to configure in Authorize.Net account settings page) with the transaction details of ARB subscriptions payement as xml. Using this we can listen to the post request coming to our drupal site and do necessary business logic according to transaction status details.
     * Implements hook_menu().
    function authnet_arb_menu () {
      $items = array();
      $items['authnet-arb-silentpost'] = array(
        'type' => MENU_CALLBACK,
        'page callback' => 'authnet_arb_silentpost',
        'access callback' => TRUE,
      return $items;
  3. Authnet ARB settings:
    Admin config page for setting the API login Id and transaction key. This form also provide an option for sandbox transactions, which will be more useful while testing.
  4. ARB Subscription cancellation form:
    Using this subscribers can cancel their ARB subscription any time they want.
Since we are now familiar with the module, lets get to work on those changes to make this module production ready.

Making production ready

Before integration we have make some hack on the sandbox module to make it effectively work with drupal_commerce and bug free.
In Drupal organization hacking module and generating a patch is more oftenly done by all drupal contributors.
Basically to be a good drupal contributor before hacking a set of code we need to have clear idea of what is the cause of problem and why we need to fix it. Hence we can look on the problem, whenever creating ARB subscription or an API request is been to happen SDK will check for sandbox boolean value is true or false. Since authnet_arb is a sandbox module its not checking whether the payment method is been set as sandbox and then set the SDK sandbox boolean as proper. So we have to hack the sandbox module for this to work properly before each API request is to created or generated. Here come the sample code needed to set sandbox boolean of SDK.
    $request = new AuthorizeNetARB($settings['login'], $settings['tran_key']);
    if ($settings['sandbox']) {
    } else {
Another feature we needed while implementing Authorize.Net ARB is the option for update subscription details such as credit card. authnet_arb sandbox module doesn't provide this update feature, instead they says it need to be implemented. Here I havehack that also as follow:
    function authnet_arb_update_subscription ($update_values) {

      $settings = authnet_arb_settings();
      require_once authnet_arb_sdk_path().'/AuthorizeNet.php';

      $subscription = new AuthorizeNet_Subscription;
      $subscription->billToFirstName = $update_values['first_name'];
      $subscription->billToLastName = $update_values['last_name'];
      $subscription->billToAddress = $update_values['thoroughfare'] . ' ' . $update_values['premise'];
      $subscription->billToCity = $update_values['locality'];
      $subscription->billToState = $update_values['administrative_area'];
      $subscription->billToZip = $update_values['postal_code'];
      $subscription->billToCountry = 'US';

      $subscription->creditCardCardNumber = $update_values['card_number'];
      $subscription->creditCardExpirationDate = $update_values['expiration_date'];

      $request = new AuthorizeNetARB($settings['login'], $settings['tran_key']);
      if ($settings['sandbox']) {
      } else {
      $response = $request->updateSubscription($update_values['subscription_id'], $subscription);
      return $response;
There is one more feature need to implement delete subscription. That you can try. That's all enjoy coding and hacking.