Thursday, December 22, 2011

Dyanamically add textbox and remove through jquery

$(document).ready(function(){
var counter = 2;
//to add text box
$('#add-textbox').click(function () {
var newTextBoxDiv = $(document.createElement('div'))
.attr('id', 'edit-child-' + counter +'-wrapper');

newTextBoxDiv.after().html('' + '');

newTextBoxDiv.appendTo('#major-id');

counter++;


});

// to remove text box
$('#remove-textbox').click(function () {
counter--;
$('#edit-child-' + counter +'-wrapper').remove();

});

});

Thursday, September 22, 2011

How to show different images in different page using single block

step1:write the block title

step2:write the following php code in body
<?
global $base_url;//give the base url path link "http://www.fando.in"
$url =  $_SERVER['REQUEST_URI'];//it return the  argument of url like "http://www.fando.in/photo" then this while return "photo"
switch($url){
case '/photo':
$img="<img alt='' src = '{$base_url}/sites/default/files/about-us-image.jpg' />";
print $img;
break;
case '/image' :
$img="<img alt='' src = '{$base_url}/sites/default/files/IDW_In_63_0.jpg' />";
print $img;
break;
}
?>
step3:select the "php code " input format.
step4:Show block on specific pages,in that user need to write where this block display
eg:photo
step5:select the region,for proper display block.
eg:leftside,rightside etc

Tuesday, September 20, 2011

target "_blank" opens two windows (Means link open in New window as well as same window)

step1)suppose you add html code in a page of drupal using FCK EDITOR , In that one facebook link is there and after clicking that link,that link open in new window as well as same window.
Here is the code :
<a target="_blank" href="http://www.facebook.com/pages/The-Ideal-School-of-Manhattan/156013431088499">facebook</a>
step2:This problem occurs from "Google Analytic" module

step3:To solve this problem U have three ways:

 1st way->upgrade google analytic module to google_analytics 6.x-3.x-dev(here is link  http://drupal.org/node/807234 )
2nd way->disabled "Track outbound links" in google analytic module(In Site configuration -> google analytic)
3rd way ->Add this patch to the "googleanalytics.js" file
// Track all external links as page views after URL cleanup.
             // Currently required, if click should be tracked as goal.
             _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
+            if(this.target == '_blank'){
+                return true;
+            }
+            else{
             setTimeout('document.location = "' + this.href + '"', 100);
           }
+          }
           else {
             // External link clicked.
             _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
@@ -51,10 +56,15 @@
             // that a user can click on the outbound link before the tracking code loads,
             // in which case the event will not be recorded.
             // See http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55527
+            if(this.target == '_blank'){
+                return true;
+            }
+            else{
             setTimeout('document.location = "' + this.href + '"', 100);
           }
         }
       }
+      }
     });
   });
 });
 
MORE REFERENCE VISIT BELOW LINK
        http://drupal.org/node/1057688

 

Friday, July 29, 2011

Add Separate CSS for IE - Drupal 6

There are THREE ways by which we can include css for IE with respective to the versions of IE.

1)From active Themes .info file.
2)From active Themes template file (page.tpl.php).

1)From active Themes .info file. (Eg: Zen theme)

 In Themes .info file, there is a section adds CSS files to your theme, there we can include our custom css file for different IE versions.

Code:

; Set the conditional stylesheets that are processed by IE.

;For all versions of IE browser
conditional-stylesheets[if IE][all][]  = css/ie.css

;For  lte (less than or equal to) IE 7 browser - applies to all versions less than or equal to IE 7 (IE7, IE6, IE5 ,.....)
conditional-stylesheets[if lt IE 7][all][] = css/ie.css

;For  lt (less than) IE 7 browser - applies to all versions less than IE 7 (IE6, IE5 ,.....)
conditional-stylesheets[if lte IE 7][all][] = css/ie.css

;For  gte (greater than or equal to) IE 7 browser - applies to all versions greater than IE 7 (IE7, IE8 , IE9,.....)
conditional-stylesheets[if gte IE 7][all][] = css/ie.css


;For  gt (greater than) IE 7 browser - applies to all versions greater than IE 7 (IE8 , IE9,.....)
conditional-stylesheets[if gt IE 7][all][] = css/ie.css 

 ;For only IE 7 browser - applies to only IE 7
conditional-stylesheets[if IE 7][all][] = css/ie7.css 

For More Information -  Click Here


2)From active Theme template file (page.tpl.php).

 Code to be included in <head> </head> tag.

/*For all IE browsers version less than or equal to IE7*/
<!--[if lte IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version less than  IE7*/
<!--[if lt IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version greater than or equal to IE7*/
<!--[if gte IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For all IE browsers version greater than IE7*/
<!--[if gt IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->

/*For only IE 7 browser - applies to only IE 7*/
<!--[if IE 7]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->


/*For all IE browser - applies to all IE versions*/
<!--[if IE]>
  <link type="text/css" rel="stylesheet" media="all" href="sites/all/themes/(name_of_the_theme)/css/ie7.css" />
<![endif]-->



Tuesday, July 26, 2011

how to covert OFC(drupal API "ofc_api") SWF OBJECT TO IMAGE

step1 : sites/all/modules/ofc_api/php-ofc-library/ofc_upload_image.php

Add following  code:
// default path for the image to be stored //
- $default_path = '../tmp-upload-images/';
+if( ! $_GET['defaultPath'] ) {
+    $default_path = '../tmp-upload-images/';
+} else {
 +   $default_path = $_GET['defaultPath'];
+}

step2 : display  chart area


/*************** display chart using area  start*************/
    
    $chart = new open_flash_chart();
    
    $title = new title( 'Future & Option Chart' );
    $title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" );
    $chart->set_title( $title );
    
    $area = new area();
    $area->set_colour( '#5B56B6' );
    $area->set_values( $call_buy );
    $area->set_key( 'Call_Buy', 13 );
    $area->on_show(new line_on_show($animation[0], $cascade[0], $delay[0]));
    $chart->add_element( $area );
    
    $call_write = new area();
    $call_write->set_colour( '#800517' );
    $call_write->set_values( $CallWrite );
    $call_write->set_key( 'Call_Write', 13 );
    $call_write->on_show(new line_on_show($animation[1], $cascade[1], $delay[1]));
    $chart->add_element( $call_write );
    
    $put_buy = new area();
    $put_buy->set_colour( '#00FFFF' );
    $put_buy->set_values( $putbuy );
    $put_buy->set_key( 'Put_Buy', 13 );
    $put_buy->on_show(new line_on_show($animation[2], $cascade[2], $delay[2]));
    $chart->add_element( $put_buy );
    
    $put_write = new area();
    $put_write->set_colour( '#52D017' );
    $put_write->set_values( $putwrite );
    $put_write->set_key( 'Put_Write', 13 );
    $put_write->on_show(new line_on_show($animation[3], $cascade[3], $delay[3]));
    $chart->add_element( $put_write );
    
    $future_buy = new area();
    $future_buy->set_colour( '#8D38C9' );
    $future_buy->set_values( $futureBuy );
    $future_buy->set_key( 'Future_Buy', 13 );
    $future_buy->on_show(new line_on_show($animation[4], $cascade[4], $delay[4]));
    $chart->add_element( $future_buy );
    
    $future_sell = new area();
    $future_sell->set_colour( '#F778A1' );
    $future_sell->set_values( $futureSell );
    $future_sell->set_key( 'Future_sell', 13 );
    $future_sell->on_show(new line_on_show($animation[5], $cascade[5], $delay[5]));
    $chart->add_element( $future_sell );

    // $average = new area();
    // $average->set_colour( '#0E440E' );
    // $average->set_values( $avg );
    // $average->set_key( 'Resultant Profit', 13 );
    // $average->on_show(new line_on_show($animation[6], $cascade[6], $delay[6]));
    // $chart->add_element( $average );
    
    $line_1_default_dot = new solid_dot();
    $line_1_default_dot->size(2)->halo_size(2)->colour('#0E440E');
    $average = new line();
    $average->set_default_dot_style($line_1_default_dot);
    $average->set_values( $avg  );
    $average->set_width( 1 );
    $average->set_key( 'Resultant Profit', 13 );
    $average->set_colour( '#0E440E' );
    $average->on_show(new line_on_show($animation[6], $cascade[6], $delay[6]));
    $chart->add_element( $average );

    $x_labels = new x_axis_labels();
    $x_labels->set_steps( 1 );
    $x_labels->set_vertical();
    $x_labels->set_colour( '#A2ACBA' );
    $x_labels->set_labels( $current_market );
    
    $x = new x_axis();
    $x->set_colour( '#A2ACBA' );
    $x->set_grid_colour( '#D7E4A3' );
    $x->set_offset( false );
    $x->set_steps(1);
    // Add the X Axis Labels to the X Axis
    $x->set_labels( $x_labels );
    
    $chart->set_x_axis( $x );
    
    $x_legend = new x_legend( $min . ' to ' . $max );
    $x_legend->set_style( '{font-size: 20px; color: #778877}' );
    $chart->set_x_legend( $x_legend );
    
    //
    // remove this when the Y Axis is smarter
    //
    $y = new y_axis();
    $y->set_range( $ymin, $ymax, $y_diff );
    $chart->add_y_axis( $y );
        
    
  step3: here jquery call to get unique id of swf
 
    /************** display chart using area end ***************/

    $displayChart = array();
    
    $displayChart['resultant'] = $resulant_lossprofit;


    $chartId = ofc_api_unique_id();
    $displayChart['chart_id'] = $chartId ;
    $displayChart['chart'] = fno_chart_api_render($chart, 800, 400, array(), $chartId);
    //here unique chart id set
    drupal_add_js("var open_chart_id = '{$chartId}'", 'inline');

    //on particular button click function this image stored in default path
  $js6 = "jQuery(document).ready(function(){
        jQuery('#chart-pdf1').bind('click', function(){         
         var url = 'http://192.168.2.74/stock_adv/sites/all/modules/ofc_api/php-ofc-library/ofc_upload_image.php';   //call ofc_upload_image.php
            url += '?name={$chartId}.png';    //append image name                               
            url += '&defaultPath=' + '/home/ajay/public_html/stock_adv/sites/default/files/';     //default path where image stored
         swfobject.getObjectById(open_chart_id).post_image(url,true, false );   //ofc method to get image stored in default path
 });     
                  });";
  drupal_add_js($js6, 'inline');

    return $displayChart;
}

 step 4: there chart api render function call to display swf object

function fno_chart_api_render($chart = 'ofc_api_sample', $width = 800, $height = 400, $params = array(), $id=false ) {
  $swf = url(drupal_get_path('module', 'ofc_api') . '/open-flash-chart.swf');
  if ( !$id ) {
      $id = ofc_api_unique_id();
  }
  // Call hook_ofc_api_data() to get all function names that will return chart data
  $charts = module_invoke_all('ofc_api_data');
  
  // $chart contains a function name
  if (in_array($chart, $charts, true) && function_exists($chart)) {
    $method = 'data-file';
    $source = url('ofc_api/data/' . $chart);
  }
  // $chart is a chart object
  elseif (is_object($chart) && isset($chart->elements)) {
    $method = 'get-data';
    $source = $id;
    $json = drupal_to_js(json_encode($chart));
  }
  // $chart contains the JSON string
  elseif (is_string($chart) && is_object(json_decode($chart))) {
    $method = 'get-data';
    $source = $id;
    $json = drupal_to_js($chart);
  }
  // $chart is in unknown format
  else {
    $method = 'data-file';
    $source = url('ofc_api/data/not-found');
  }
  
  $data = array(
    '@swf' => $swf,
    '@id' => $id,
    '@width' => check_plain($width),
    '@height' => check_plain($height),
    '@method' => $method,
    '@source' => $source,
    '@json' => $json,
  );
  
  return ofc_api_render_html($data, $params);
}

Adding PHP Code in Views - Drupal 6

Thanks to Views Custom Field module which allowed us to write custom php code in Views field.

Comes with three different fields
1) Markup
Field that allows usage of custom text and the input filter system.
2) PHP code
Field that allows usage of custom PHP code (with access to view's database result)
 $data: contains the retrieved record from the database (e.g. $data->nid).
 we can access the fields build in the database query , To know the fields see the build query shown in views preview or add a custom PHP field with <?php print_r($data); ?> will show the available database field, which can be used in our code.
 3) Rownumber
Field containing rownumber (respects pagers).
 Note:
Include <?php ?> delimiters when using PHP code. Available variables:
$static: can be used to store reusable data per row.

Now i am going to show you how Replacement Patterns can be used in Views Custom field.

For example:

<?php

$static = $this->view->display_handler->get_handlers('field');
if (!empty($static['drupal_id']->last_render)) {
echo "success";
}

?>
here drupal_id is the Replacement Pattern
[drupal_id] == Drupal ID

Alter Menu Title in drupal 6 using hooks

we can alter Menu Title in drupal 6 using hooks using phptemplate_menu_item_link($item) function in template.php file

for Eg:


function phptemplate_menu_item_link($item) {

    if( strpos($item['title'], 'Administer') === 0) {

         $item['title']='Administer Kapil';
           return l($item['title'], $item['link_path'], !empty($item['description']) ? array('title' => $item['description']) : array(), NULL, NULL, FALSE, FALSE);
    }
  
     return l($item['title'], $item['link_path'], !empty($item['description']) ? array('title' => $item['description']) : array());
}


This function will change "Administer" menu title in Navigation menu to 'Administer Kapil'. 

and we can also use html tags in Menu title if we set 7th parameter in return statement to TRUE...

Tuesday, June 28, 2011

Google's I'm feeling Lucky

Normally we do is enter some data to search in the textbox and click on "Google Search" button, which shows a listed of matching websites in page wise.

I'm Feeling Lucky
:

If we enter some data to search in the textbox and click on "I'm Feeling Lucky" button, it will directly takes you to the first website. First website means first site shown in the list if it is normally searched.

For more information:
http://google.about.com/od/searchingtheweb/qt/imfeelingluckyq.htm