Tuesday 18 December 2012

get custom option name in filter.phtml(layred navigation)

<?php echo $_item->getName() ?>

copy a file into another folder in asp .net

string targetFolder = Server.MapPath(“~/PDF”);
System.IO.FileInfo fi = new System.IO.FileInfo(Server.MapPath(“~/Bookmark.pdf”));
fi.CopyTo(System.IO.Path.Combine(targetFolder, fi.Name), true);

get product thumb images on view.phtml

<!–?<?php $_images = Mage::getModel(‘catalog/product’)->load($_product->getId())->getMediaGalleryImages(); ?>
<?php if($_images){?>
<?php $i=0; foreach($_images as $_image){ $i++; ?>
<a href=”#” onclick=”ig_lightbox_show(-1)”>

<img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘thumbnail’, $_image->getFile())->resize(108,90); ?>” alt=”<?php echo $this->htmlEscape($_image->getLabel());?>” title=”<?php $this->htmlEscape($_image->getLabel());?>” />
</a><?php } ?> <?php } ?>

how to check canvas is empty or not

<canvas11″ height=”200px” width=”200px”>
<asp:Button runat=”server” ID=”btn1″ Text=”Save”  OnClientClick=”checkcanvas();” />
<script type=”text/javascript”>
function checkcanvas() {
var i = isCanvasTransparent();
//i =true    if canvas empty
//i =false       if canvas has image
}
function isCanvasTransparent() {
var canvas1 = document.getElementById(‘canvas11′);
// true if all pixels Alpha equals to zero
var ctx = canvas1.getContext(“2d”);
var result;
var imageData = ctx.getImageData(0, 0, canvas1.offsetWidth, canvas1.offsetHeight);
for (var i = 0; i < imageData.data.length; i += 4)
if (imageData.data[i + 3] !== 0) return false;
return true;
}
</script>

countdown timer in php,

$dateFormat = “d F Y — g:i a”;
$targetDate = $futureDate;//Change the 25 to however many minutes you want to countdown change date in strtotime
$actualDate = $date1;
$secondsDiff = $targetDate – $actualDate;
$remainingDay     = floor($secondsDiff/60/60/24);
$remainingHour    = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
$actualDateDisplay = date($dateFormat,$actualDate);
$targetDateDisplay = date($dateFormat,$targetDate);
<script type=”text/javascript”>
var days = <?php echo $remainingDay; ?>
var hours = <?php echo $remainingHour; ?>
var minutes = <?php echo $remainingMinutes; ?>
var seconds = <?php echo $remainingSeconds; ?>
function setCountDown(statusfun)
{//alert(seconds);
var SD;
if(days >= 0 && minutes >= 0){
var dataReturn =  jQuery.ajax({
type: “GET”,
url: “<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).’index.php/countdowncont/’; ?>”,
async: true,
success: function(data){
var data = data.split(“/”);
day =  data[0];
hours =  data[1];
minutes =  data[2];
seconds =  data[3];
}
});
seconds–;
if (seconds < 0){
minutes–;
seconds = 59
}
if (minutes < 0){
hours–;
minutes = 59
}
if (hours < 0){
days–;
hours = 23
}
document.getElementById(“remain”).style.display = “block”;
document.getElementById(“remain”).innerHTML = ” Your Product Reverse For “+minutes+” minutes, “+seconds+” seconds”;
SD=window.setTimeout( “setCountDown()”, 1000 );
}else{
document.getElementById(“remain”).innerHTML = “”;
seconds = “00″; window.clearTimeout(SD);
jQuery.ajax({
type: “GET”,
url: “<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).’index.php/countdown/’; ?>”,
async: false,
success: function(html){
}
});
document.getElementById(“remain”).innerHTML = “”;
window.location = document.URL; // Add your redirect url
}
}
</script>
<?php
if($date1 < $futureDate &&  ($qtyCart > 0)){ ?>
<script type=”text/javascript”>
setCountDown();
</script>
<?php }else{ ?>
<style>
#remain{display:none;}
</style>
<?php }}?>
<div id=”remain”></div>

Friday 27 April 2012

Add module in artical in joomla

To insert a module inside an article, use the {loadposition xx} command, as follows:
Create a module and set its position to any value that doesn’t conflict with an existing template position. You can type in the position value instead of selecting it from the drop-down list. For example, use the position myposition.
Assign the module to the Menu Items that contain the articles that you want the module to show in. You can also just assign the module to all Menu Items.
Edit the articles where you want this module to appear and insert the text {loadposition myposition} in the article at the place where you want the module.

wysiwyg editor in Magento Custom Module

Step 1 – Go to app/code/local/Webkul/Faq/Block here webkul is namespace and faq is module name , under your _prepareLayout() function add this code
public function _prepareLayout()
{
if (Mage::getSingleton(‘cms/wysiwyg_config’)->isEnabled() && ($block = $this->getLayout()->getBlock(‘head’))) {
$block->setCanLoadTinyMce(true);
}
return parent::_prepareLayout();
}
Then go to app/code/local/Webkul/Faq/Block/Adminhtml/Faq/Edit/Tab
and add following code in your _prepareForm() function below your setform() . $this->setForm($form);
$wysiwygConfig = Mage::getSingleton(‘cms/wysiwyg_config’)->getConfig(array(‘add_variables’ => false, ‘add_widgets’ => false,’files_browser_window_url’=>$this->getBaseUrl().’admin/cms_wysiwyg_images/index/’));
then define this as $fieldset
$fieldset->addField(‘body’, ‘editor’, array(
‘name’ => ‘body’,
‘label’ => Mage::helper(‘faq’)->__(‘Content’),
‘title’ => Mage::helper(‘faq’)->__(‘Content’),
‘style’ => ‘width:700px; height:500px;’,
‘state’ => ‘html’,
‘config’ => $wysiwygConfig,
‘wysiwyg’ => true,
‘required’ => true,
));
This post is original on webkul

Friday 6 April 2012

magento display attribute in dropdown

Create a attribute
and then
edit app/code/core/Mage/Catalog/Block/Navigation.php

public function getAllManu()
{
$product = Mage::getModel(‘catalog/product’);
$attributes = Mage::getResourceModel(‘eav/entity_attribute_collection’)
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter(‘attribute_code’, ‘manufacturer’); //can be changed to any attribute
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
return $manufacturers;
}
and then
edit app/design/frontend/default/default/template/catalog/navigation/top.phtml

  1. <select id=“select-manufacturer” onchange=“window.location.href=this.value”>
  2. <option value=“#” selected=“selected”>–Select Manufacturer–</option>
  3.     <?php foreach ($this->getAllManu() as $manufacturer): ?>
  4.         <option value=“/catalogsearch/advanced/result/?manufacturer[]=<?php echo $manufacturer['value'] ?>”><?php echo $manufacturer['label'] ?></option>
  5.     <?php endforeach; ?>
  6.     </select>

captcha (alpha numeric) in php

<?php
$RandomStr = md5(microtime());// md5 to generate the random string
$ResultStr = substr($RandomStr,0,8);
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, $RandomStr, $text_color);
imagejpeg($im,$ResultStr.'.jpg');
imagedestroy($im);
//echo '’.$randval.”;
?>

ebooks of drupal 6 and drupal 7

magento free ebook download

Thursday 1 March 2012

add google translate with selected language, google translate api with selected language

function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: ‘en’,
includedLanguages: ‘ja’,
defaultLanguage: ‘ja’,
multilanguagePage: true
}, ‘google_translate_element’);
}

set google translater default language, google translate default language

We can set google translate default language
by working with cookies
for this first use google translate to translate your web page
then see what cookies he has created
(for this right click on your web page then page info
then security then view cookies and click on googtrans you see what is the translation he is using and what is the path and what is the domain or host name )
and put this all data in setcookies function
example
setcookie(“googtrans”, “/en/ja”, time()+3600, “/”, “www.example.com”);
//setcookie(“googtrans”, “en/ja”);
setcookie(“googtrans”, “/en/en”, time()+3600, “/”, “.example.com”);

call a function regularly , call a function after a particular time period, call function continue


function getdata(){
var langu = jQuery(“.goog-te-combo”).html(‘<option value=”">Select Lanugage</option><option value=”en”>English</option><option value=”ja”>Japanese</option>’);
jQuery(“.goog-te-gadget”).css({“margin-top”:”0px”});
intervaltime();
}
</script>



<script>
function intervaltime(){
window.setInterval(function(){
getdata();
}, 5000);
}
$(function() {
setTimeout(getdata, 3000);
});
</script>

drupal 6 basic form , create form in drupal

<?php
function test_myform($form_state) {
// Access log settings:
$options = array('1' => t('Enabled'), '0' => t('Disabled'));
$form['access'] = array(
'#type' => 'fieldset',
'#title' => t('Access log settings'),
'#tree' => TRUE,
);
$form['access']['log'] = array(
'#type' => 'radios',
'#title' => t('Log'),
'#default_value' =>  variable_get('log', 0),
'#options' => $options,
'#description' => t('The log.'),
);
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
$form['access']['timer'] = array(
'#type' => 'select',
'#title' => t('Discard logs older than'),
'#default_value' => variable_get('timer', 259200),
'#options' => $period,
'#description' => t('The timer.'),
);
// Description
$form['details'] = array(
'#type' => 'fieldset',
'#title' => t('Details'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['details']['description'] = array(
'#type' => 'textarea',
'#title' => t('Describe it'),
'#default_value' =>  variable_get('description', ''),
'#cols' => 60,
'#rows' => 5,
'#description' => t('Log description.'),
);
$form['details']['admin'] = array(
'#type' => 'checkbox',
'#title' => t('Only admin can view'),
'#default_value' => variable_get('admin', 0),
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#size' => 30,
'#maxlength' => 64,
'#description' => t('Enter the name for this group of settings'),
);
$form['hidden'] = array('#type' => 'value', '#value' => 'is_it_here');
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
function test_page() {
return drupal_get_form(‘test_myform’);
}
?>

Tuesday 17 January 2012

joomla add script and css in module

$document =& JFactory::getDocument();
$document->addStyleSheet(JURI::root().'media/system/css/calendar.css');
$document->addScript(JURI::root().'media/system/js/calendar_shift1.js');
$document->addScript(JURI::root().'media/system/js/validation.js');

joomla default error message popup, joomla error message popup , joomla username password not matching error message

ADD in head



 <?php
JHTML::_('behavior.mootools');
JHTML::_('behavior.modal');
?>
<?php
if ($this->getBuffer('message')) : ?>
<script type="text/javascript">
window.addEvent('domready', function() {
var myel = new Element('a',{'href':'#error_info'});
SqueezeBox.fromElement(myel,{
handler:'adopt',
adopt:'error_info',
});
});
</script>
<?php endif; ?>


ADD after body

<div style="display:none;">
<div id="error_info"><jdoc:include type="message" />
</div>

change password(admin) drupal

UPDATE users SET pass = MD5('newpassword') WHERE uid=1

Thursday 12 January 2012

redirect a site on www using .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.urbankingsinc\.com)?$
RewriteRule (.*) http://www.urbankingsinc.com/store/$1 [R=301,L]