Wednesday 31 March 2010

Check out who else current user is logged in?

<?php
if ($GLOBALS['user']->uid
{
 
  echo $GLOBALS['user']->uid;
 
} ?>
 
 
Enjoy Drupaling.
Cheers!
 

How to make search enginers compatible URL in drupal?

Use PathAuto and Path Redirect together to redirect old aliases to the new ones.
Search engines will use each page as a single page.

Enjoy Drupaling!

Cheers!

Tuesday 30 March 2010

Admin login problem exist after installation in magento?

Hi All,
 
Use the following URL to login 
http://localhost/magento/index.php/admin 
 
if does not work then use the another way to login 
 
 

OR 
 
Open Varien.php file using the following path: 
 
app\code\core\Mage\Core\Model\Session\Abstract\Varien.php
 
find the below given code in above file:
if (isset($cookieParams['domain'])) {
    $cookieParams['domain'] = $cookie->getDomain();
}
 


Replace If condition with the below if condition:

if (isset($cookieParams['domain']) && !in_array("127.0.0.1", self::getValidatorData())) {







 
And done!
 
 

Cheers!

 


How to enable CURL extension in your PHP?

There are few steps through which you can find CURL extension is enbaled in your PHP or not:

These are the steps to take:

1. open a blank text document.

2. copy and paste this code into notepad and save it as test.php

<?php
echo '<pre>';
var_dump(curl_version());
echo '</pre>';
?>

4. If there was an error, then it means that you do not have this extension enabled. and you will see an error similar to this one:
Fatal error: Call to undefined function curl_version() in test.php on line 2

5. Open your php.ini file and look for this line:
;extension=php_curl.dll

path: php > php.ini

Remove ; before the extension word and done!

your curl has been enabled.

Restart your server.

Cheers!

How to restart Apache and Mysql using Putty?

Apache Restart
/etc/init.d/httpd restart

# To Start MySQL Server
/sbin/service mysqld start

# To Stop MySQL Server
/sbin/service mysqld stop


Cheers!

How to turn off, restart, and shut down Linux using Putty?

Following are the listing of each of the commands that will enable a user to shut down, turn off, reboot, etc.

1.) halt
2.) poweroff
3.) reboot
4.) shutdown

Cheers!

Monday 29 March 2010

HOW to set up CRON JOB file using putty?

Using following step, you can set cronjob

1.) SSH or telnet into your account.
2.) At the prompt, type in 'crontab -e'. This will open up your crontab file, or create a new one if it doesn't exist.
When this file opens, you will see other cron jobs listed in here, or if you haven't any - you'll see a bunch of lines with '~' on them.
3.) Use the cursor to go down until you can't move the cursor down any more. This is where you start your new line. Press 'o' to insert a new line.
4.) Press 'o' to insert a new line. If you want to edit a line, press 'i'.
5.) Copy the code above, then right click into your SSH or telnet client to paste the above code in. This should all go in as a new line.
6.) Press the 'esc' key to exit out of edit mode.
7.) To save the changes and exit, type the following in: ZZ
If you want to exit without saving changes, type in: :q!




# Minute   Hour   Day of Month       Month          Day of Week        Command    
# (0-59)  (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)                
    0        2          12             *               0,6           /usr/bin/php /vr/www/html/vpe/mail.php
30 23 * * * /usr/bin/php /var/www/html/vpe/mail.php  

that means above cron will run daily at 23:30 i.e., 11:30 PM 
and you'r done.

Cheers!

How to copy file from local to online server using putty?

Go to the directory form where you want to copy file/folder.

cd /var/www/html

html> cd testdir

testdir> scp test.txt vpedev@dge.great.net:/var/www/html/vpe/testdir

ask password then

give it password and done!


Here vpedev is a username and dge.great.net is hostname

Cheers!

How to give permission to the folder using putty?

Type the following command.

Chmod 777 –R foldername

Ex: chmod 777 –R /var/www/html/testdir

Cheers!

How to Connect to a MySQL database using putty?

Just a simple exercise for this one. At the command prompt, type
mysql -u username -p -- dbname

where username is the username associated with your MySQL database
and dbname is the database name.

You'll then be prompted for your password.
This prompt should then appear, indicating you are now connected to the database.

You'r Done.

Cheers!

How to exit from putty?

Using 'exit' keyword, we can go out from putty.

Cheers!

How to use PUTTY?

Using the follow step, you can use putty:

1.) After download the putty, ensure the port setting is 22, which is the secure option.

2.) Type in the host name or IP address - the host name will usually be your site name, but check with your web host first to make sure.

3.) Click the Open button

4.) A window should appear and after a few seconds, a prompt stating "login as" will display

5.) Type in the username, usually your account username

6.) A password prompt should then appear after a few seconds. Type in your account password .

and done!

Cheers!

What is SSH?

SSH (Secure Shell) was developed as a secure alternative to Telnet or Putty.


Putty is a protocol allowing for command line access to a Unix, Linux or FreeBSD based remote computer. If you've ever used DOS, you'd be familiar with the black screen. Some of the DOS command set will also work . If you're asking what DOS is, then you're probably a lot younger than I.


DOS was Microsoft's Disk Operating System; the precursor to Windows.

Friday 26 March 2010

How to use ajax call using jquery?

Please use the following code to call ajax:  
 
function updateStatus() {
     $.ajax({
         url: 'getStatus.php',
         success: function(response) {
             // update status element
             $('#status').html(response);
         }
     });
 }
 
 
 
Cheers!

How do I disable/enable an element?

You can disable/enable an element by setting the 'disabled' attribute to 'disabled' (to disable it) or "" (to enable it). The result of which looks something like this:

// Disable #divID
$("#divID").attr("disabled","disabled");
 
// Enable #divID
$("#divID").removeAttr("disabled");
Cheers!

How do I determine the state of a toggled element?

You can check the state using the :visible or :hidden selectors.

var isVisible = $('#myDiv').is(':visible');
var isHidden = $('#myDiv').is(':hidden');
 
 
Here is() function is used to check whether  div is visible or not.
Cheers!

How do test whether an element exists or not?

You can use the length() function of the jQuery:

if( $('#myDiv').length > 0 )
  $('#myDiv').show();


Cheers!

How to give effect using jquery?

<div id="divId">
           <a href="javascript:void(0);" class="red">Ashwani Kumar</a>

 </div>
<script>
$("#divId").hide("slow");
$("#divId").slow("slow");
$("#divId").toggle("slow");
</script>

Cheers!

How to change CSS using jquery?

<style>
a.red{
color:RED;
}
a.blue{
color:BLUE;
font-weight:bold;
}
</style

<div>
       <a href="javascript:void(0);" class="red">Ashwani Kumar</a>
</div>

$(document).ready(function(){
    $("a").click(function(event)
    {
        $("a").addClass('BLUE');
    }
    )
}
)

Cheers!

How code run after doucment loaded properly?

 
$(document).ready(function(){
   // Your code here
 });
$(document).ready(function() {
$("a").click(function(event){
     alert("Thanks for visiting!");
   });
}); 
This function will work until or unless page will be loaded properly.

How onload functon works in javascript?

Write below code in your page

<script>
window.onload = function(){ alert("welcome"); }
</script>


As soon as page will load, an alert will be popuped with 'welcome' message.

Cheers!

What is jquery?

jQuery is a kind of JavaScript Library.

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.
jQuery is designed to change the way that you write JavaScript.

How to add js in drupal?

Use the following code to add js in drupal:
 
<?php
 
// This will add a JS file to your head (specifically the $scripts variable in page.tpl.php)
 
drupal_add_js(drupal_get_path('module', 'my_module') . '/my_module.js');

 
// This add inline JS to the head of the document
 
drupal_add_js('alert("Hello!")', 'inline');

 
// This will add variables in the Drupal.settings object
 
drupal_add_js(array('my_module' => array('my_setting' => 'this_value')), 'setting');?>
 
Enjoy Drupaling!
Cheers!

PHP Interview Questions And Answers Set - 1

Please click at the following link to see the PHP Interview Questions and Answers Set - I

http://phpinterview-questions.blogspot.com/2009/03/php-interview-questions-and-answers-set.html

How to setup zend framework?

mysite
    /application
        /controllers
            IndexController.php
        /models
            IndexModel.php
        /forms
            LoginForm.php
        /views
            /scripts
                /index
                    index.phtml
    /libaray
        /Zend
/js
    /css
    /images
    /index.phtm
 
 <?php
define('ROOT_DIR', dirname(__FILE__));

set_include_path('.'
. PATH_SEPARATOR . ROOT_DIR . '/library'
. PATH_SEPARATOR . ROOT_DIR . '/application/models'
. PATH_SEPARATOR . ROOT_DIR . '/application/forms'
. PATH_SEPARATOR . get_include_path()
);

require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();

$frontController = Zend_Controller_Front::getInstance();

$frontController->throwExceptions(true);

$frontController->setControllerDirectory(ROOT_DIR.'/application/controllers');
$frontController->dispatch();
?>
 
 <?php
class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
    }
}
 
 Now if you browse
http://localhost/mysite/

You will see
Hello World 
If you don’t see “Hello world” printed, read the above guide lines again.
As
we have now successfully created directory structure and bootstrap
file, its time to make other necessary configuration for database.

4. Configuration for working with database
How
a web application can be completed without usage of database. Different
web application uses different database. Some uses Mysql, other SQLite,
SQL server and Oracle. One of the nice thing about Zend Framework is
that it support multiple database servers. 
Here we are going to making configuration for Mysql server.
For database configuration, first create config.ini in mysite/application/ and write the following code in it.
 
 [general]
db.adapter = PDO_MYSQL
db.params.host = localhost
db.params.username = root
db.params.password = 
db.params.dbname = zend_framework
 
<?php
define('ROOT_DIR', dirname(__FILE__));

set_include_path('.'
. PATH_SEPARATOR . ROOT_DIR . '/library'
. PATH_SEPARATOR . ROOT_DIR . '/application/models'
. PATH_SEPARATOR . ROOT_DIR . '/application/forms'
. PATH_SEPARATOR . get_include_path()
);

require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();

$config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'general');
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);

$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory(ROOT_DIR.'/application/controllers');
$frontController->dispatch();
?> 
 

Wednesday 24 March 2010

How to fetch query parameters?

Suppose, following link in a address bar:

http://localhost/drupal/?q=user/1


to fetch query parameters, we will use argument methods.

print arg(0); // this will print 'user'
print arg(1); // this will print '1'

Keep Drupaling!

Cheers!

Tuesday 23 March 2010

How to setup/customize offline site page?

Go to Administer -> Site Configuration -> Site Maintenance

Select Site status:off - line

and give the content which you want to show.

If you want to customize this page. create maintenance-page.tpl.php and keep this file into theme folder which you using.

Keep Drupaling!

Cheers!

Search is not working properly?

To make search workable, you just go through the following:

set up your cron file or run manually.

you can find cron file at:

http://localhost/drupal_latest/cron.php

run this file from address bar and your search will start working.

Enjoy Drupaling!

Cheers!

How to create Custom Block?

Following is a simple example of custom block. For more information on blocks in general,
see the Blocks page of the handbook.
Adding A 'Contact Information' Block
A business or support group should always let people know how to contact them. One easy
thing is to include your mailing address on your pages. This is about the easiest kind of
block to start with.
1. Go to Administer>>Site building>>Blocks. It should already be sitting on your default theme, but if not, select the right one.

2. Click on the "Add block" tab.

3. Fill in the "Description" and "Body." Here's a sample body:
Example Organization<br>
The Drupal Cookbook (for beginners) http://drupal.org/book/export/html/120612
19 of 39 25.10.2008 18:42
123 Main St.<br>
Mytown, State Zip<br>
USA<br>
(123) 456-7890

4. Save the block.

5. Now you can "Configure" the block to add the block's title and define it's "Visibility".

6. Follow the Configure link next to the block and enter "Contact Information" as the Block's title.

7. Decide if you want to allow users to turn the block on or off, and, if so, which roles should have that ability. You can leave this with no changes to allow everyone to see it. Then choose which pages it will be shown on; Leave this empty to show the block on all pages.

8. Save the block.

9. Now you're back on the block list. Find the block you just created in the list and choose a "Region". You can use the "Weight" parameter to set its position with in the selected area; again, I like the address at the bottom, so I use a heavier weight.

10. Click on the "Save blocks" button.


and done.

Enjoy Drupaling !

Cheers!

How to create pages for "Page Not Found" and "Access Denied"?

Just go to "Create content" and select "Page." I title them "Access Denied" and "Page Not
Found
" but you can call them whatever makes sense to you and your users. When you
submit them, note the node ids. Then go to Administer >> Site Configuration >> Error Reporting  and
enter "node/__" in the appropriate boxes.

Suppose for Access Denied page node id is 8 and I give content as follows:

<p>We're sorry, but you must have permission to view the page you requested.</p>
<p>&nbsp;</p>
<p>If you are already a registered member of this site, please try <a href="user">logging in</a>.</p>
<p>&nbsp;</p>
<p>If you are not a member, you need to <a href="/join_us">join us</a>.</p>
<p>&nbsp;</p>
<p>If you have any questions about our site or group, please feel free to <a href="/contact">contact us</a>.</p>
<p>&nbsp;</p>
<p>--Webmistress</p>


And for Page Not Found page node id is 9 and I give content as follows:

<p>Sorry! The page you were looking for no longer exists. We redesigned our site and many of the pages have
changed.</p>
<p>&nbsp;</p>
<p>If you are unable to find something on our new site or have a question about our site or services feel free to
<a href="/contact">contact us</a>.</p>
<p>&nbsp;</p>
<p>--Webmistress</p>

Now go to Administer >> Site Configuration >> Error Reporting
Here, assign your content node id and Save Configuration.


So, we will give node/8 for Access denied and node/9 for Page Not Found.


Also, you can create page for both :

Page Not Found: page-node-8.tpl.php

Access Denied: page-node-9.tpl.php

Enjoy Drupaling !

Cheers!

How to Assign different template for Admin?

Go to Administer -> Site Configuration -> Administration Theme

Administration Theme window will be opened and select Administration Theme from the dropdown and done.

Enjoying Drupaling..

Cheers !

How to setup WYSIWYG editor in admin section?

First download WYSIWYG Module and install it from Administer -> Site Building -> Module section.

Now go to the Administer -> Site Configuration -> Wysiwyg

When you click on it, you will see the following screen:

















Here you will see a link TinyMCE (Download)

Click on it and download TinyMce editor and keep it the following location:

Extract the archive and copy its contents into a new folder in the following location:
sites/all/llibraries/tinymce

So the actual library can be found at:
sites/all/llibraries/tinymce/jscripts/tiny_mce/tiny_mce.js

Once, you do the above, you will see the another screen look likes:





















select tinymce from dropdown for both the dropdown and then click on SAVE button.

and done your editor is now working...

Enjoyin Drupaling

Cheers!

Monday 22 March 2010

How to create front page for drupal site?

Suppose you are using garland theme. So you have to create a file name page-front.tpl.php and keep it in garland folder.

Now whenever you will call your site address like http://www.yoursite.com
page-front.tpl.php will be invoked.

You can enter whatever you want to write into it. //$content

How to create a page specificaly for a particular node type?

Suppose you have create a content type name 'calendar-event'. You have lots of content added into it.
All content will be displayed from node.tpl.php file .

But if you want to create another page for this, you just will have to create a page which name will be node-calendar-event.tpl.php

following code you have to enter into it.

<?php
/*echo "<pre>";
print_r($node);
echo "</pre>";*/

echo $node->type;
echo "<br/>";
echo $node->title;
echo "<br/>";
echo $node->content['body']['#value'];
?>

How to change Forgot Password html

first take view source of Request New Password page and find form_id which is user_pass.
write the following functions in your template.php file which you will find under your theme folder.
here I am using garland theme.

function garland_theme()
{
'user_pass' => array(
'template' => 'user-pass',
'arguments' => array('form' => NULL),
),

);
}

function garland_preprocess_user_pass(&$vars)
{
/*print '


';
   print_r($vars);
   print '
';*/

$tempVar = $vars['form'];
   
$tempVar['name']['#title'] = 'User Name or Email Address';
    $tempVar['submit']['#value'] = 'E-mail new password';
   
    $vars['username'] = drupal_render($tempVar['name']);       
    $vars['submit_button'] = drupal_render($tempVar['submit']);
   
    $vars['tempForm'] = drupal_render($tempVar);


}

Now create  user-pass.tpl.php and paste the below code into it and done.

<div id="registration_form">
  <div class="field">
    <?php
      print $username;
    ?>   
  </div>
  <div class="field">
    <?php
        echo $tempForm;       
        print $submit_button;
      ?>
    </div>
  </div>
</div>

Note: do not forget to clear cache of drupal from Administer -> Site Configuration -> Performance

How to change User Login form

first take view source of user login page and find form_id which is user_login.
write the following functions in your template.php file which you will find under your theme folder.
here I am using garland theme.

function garland_theme()
{
'user_login' => array(
'template' => 'user-login',
'arguments' => array('form' => NULL),
),

);
}

function garland_preprocess_user_login(&$vars)
{
/*print '

';
   print_r($vars);
   print '
';*/

$tempVar = $vars['form'];

$tempVar['name']['#title'] = 'User Name';
$tempVar['submit']['#value'] = 'Log In';

$vars['username'] = drupal_render($tempVar['name']);
$vars['userpass'] = drupal_render($tempVar['pass']);
$vars['submit_button'] = drupal_render($tempVar['submit']);
$vars['tempForm'] = drupal_render($tempVar);


}

Now create  user-login.tpl.php and paste the below code into it and done.

<div id="registration_form">
  <div class="field">
    <?php
      print $username;
    ?>   
  </div>
  <div class="field">
    <?php
     print $userpass;
    ?>   
  </div>
  <div class="field">
    <?php
        echo $tempForm;       
        print $submit_button;
      ?>
    </div>
  </div>
</div>

Note: do not forget to clear cache of drupal from Administer -> Site Configuration -> Performance

How to change User Registration form

first take view source of your registration page and find form_id.
write the following functions in your template.php file which you will find under your theme folder.
here I am using garland theme.

function garland_theme()
{
return array(
'search_theme_form' => array(
'template' => 'search-theme-form',
'arguments' => array('form' => NULL),
),
'user_register' => array(
'template' => 'user-register',
'arguments' => array('form' => NULL),
),

);
}

function garland_preprocess_user_register(&$vars)
{
/*print '
';
   print_r($vars);
   print '
';*/

$tempVar = $vars['form'];

$tempVar['name']['#title'] = 'User Name';
$tempVar['submit']['#value'] = 'Create Account';

$vars['username'] = drupal_render($tempVar['name']);
$vars['useremail'] = drupal_render($tempVar['mail']);
$vars['submit_button'] = drupal_render($tempVar['submit']);
$vars['tempForm'] = drupal_render($tempVar);


}

Now create  user-register.tpl.php and paste the below code into it and done.

<div id="registration_form">
  <div class="field">
    <?php
      print $username; // print the password field
    ?>   
  </div>
  <div class="field">
    <?php
     print $useremail; // prints the username field
    ?>   
  </div>
  <div class="field">
    <?php
        echo $tempForm;       
        print $submit_button;
      ?>
    </div>
  </div>
</div>

so using the above way, you can change your user registration page template.

Note: do not forget to clear cache of drupal from Administer -> Site Configuration -> Performance

Ubercart shopping cart is not installing properly?

If you are facing problem to install Ubercart Shopping Cart in drupal, just check it out wether TOKEN module is installed or not.

Without Token Module Ubercart will not perform with its full features.

How to create category for content type?

If you want to keep your content in a category, you have to go through the following tutorial:

Go to the Administer -> Content Management -> Taxonomy

Here, list of all vocabulary will be displayed. vocabulary means category. so click on Add Vocabulary to create new category name. choose content type for which you are going to create categories.

Once, you add you will see a list of vocabulary. To add category item, click on Add Terms from the right hand side of a row where your new vocabulary is being displayed.

After adding category item and now when you go to add content from Create Content link. Select content type for which you have created category. Here you will see a list of category items which you have created ealier from the help of Add Terms.

How to add new Region to display Block

To add new region to display block, you must follow the following:

Suppose you are using garland theme. so there is a file name garland.info
open this file and copy the following content into it:

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[events] = Events


Note: Do not forget to clear cache using Adminster -> Site Informations -> Performances.