Pages

Monday 21 December 2015

Show data form database table, Format in Drupal 7

//Create Menu

function ajax_form_menu(){
$item['regislist'] = array(
'title' => 'List of regis User',
'access callback' => TRUE,
'page callback' => 'drupal_get_form',
'page arguments' => array('list_regis_user'),
'file' => 'ajax_form.inc',
);

return $item;
}

Create ajax_form.inc file in module folder.

<?php

function list_regis_user(){

 $form = array();

$query = db_select('ajax_form', 'n');
     $query ->fields('n', array('ajid', 'first_name', 'last_name', 'email', 'gender', 'number'));
     //$query ->condition ('first_name', '','!='); 
     $result = $query->execute();
     
      $form['requests'] = array(
    '#prefix' => '<div id="interview-request">',
                            '#suffix' => '</div>',
                            '#tree' => TRUE,
                            '#theme' => 'table',
                            '#header' => array(t('Sr no.'), t('First name'), t('Last NAme'), t('Email'), t('Gender'), t('Number')),
                            '#rows' => array(),
                            );
     
        while($record = $result->fetchAssoc()) {

if($record['first_name'])
 {
    $nid = array('#id' => 'id',
                 '#type' => 'markup',
                 '#markup' =>$record['ajid'],
                 );
    $first = array('#id' => 'first',
                     '#type' => 'markup',
                    '#markup' => $record['first_name'] ,
                 );
   $last = array('#id' => 'last',
                 '#type' => 'markup',
                 '#markup' =>  $record['last_name'],
                 );

    $email = array('#id' => 'email',
                     '#type' => 'markup',
                    '#markup' => '<b>' . $record['email'] . '</b>',
                 );
    $gender = array('#id' => 'gender',
                     '#type' => 'markup',
                    '#markup' => $record['gender'],
                 );
    $number = array('#id' => 'number',
                     '#type' => 'markup',
                    '#markup' =>  $record['number'] ,
                 );
                 
                              
    $form['requests'][] = array('nid' => &$ajid,
                                'first' => &$first,
                                'last' => &$last,
                                'email' => &$email,
                                'gender' => &$gender,
                                'number' => &$number,
                                );
    $form['requests']['#rows'][] = array(array('data' => &$ajid),
                                         array('data' => &$first),
                                         array('data' => &$last),
                                        array('data' => &$email),
                                         array('data' => &$gender),
                                         array('data' => &$number),
                                         );
                                  
                                          
    unset($ajid);
    unset($first);
    unset($last);
    unset($email);
     unset($gender);
unset($number);
}
    } 
    return $form;
}

Monday 7 December 2015

Drupal Import and export database in ubuntu plateform


Export Database -

mysqldump -u username -ppassword Databasename | gzip -9 > database.sql.gz


Import Database -

gunzip < databasename.sql.gz | mysql -u root -ppassword databasename


Install Netbeans in Ubuntu.

1 - Download netbeans from link -  https://netbeans.org/downloads/

2 - Go to Terminal run this command

chmod +x ~/Downloads/netbeans-8.1-php-linux-x86.sh

3 - Then run this
 
cd ~/Downloads && ./netbeans-8.1-php-linux-x86.sh

Sunday 2 August 2015

Wordpress Basic Links to Start up

Create a child theme in Wordpress

Go to this Link - https://codex.wordpress.org/Child_Themes


Register Menu In Wordpress
Code in functions.php file
Go to this Link - https://codex.wordpress.org/Navigation_Menus


Show Menu Front of Wordpress

Header footer or index where you want to show.
Go to this Link - https://codex.wordpress.org/Function_Reference/wp_nav_menu


Monday 6 July 2015

After logged out, clicking browser go back button still brings back the previous visited page

After logged out, clicking browser go back button still brings back the previous visited page


<?php
drupal_add_http_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate, post-check=0, pre-check=0');
?>


Work offline page open through history page

<script type="text/javascript">
jQuery(document).ready(function() {
var a=navigator.onLine;
    if(a){
    //alert('online');
    }else{
    alert('offline');
    window.location='index.php';
    }
    })
</script>

Saturday 6 June 2015

Update Language Field of the single Content type

//print_r(allowips_for_role(5));
//$type= node_type_get_types();
//$fields = field_info_fields("node", "document");
 //echo "<pre>";
 //print_r($fields);
 //print_r($type);

$lang = und; // Replace with ISO639-2 code if localizing
$node_type = 'document'; // Machine name of the content type

$query = new EntityFieldQuery;
$result = $query
  ->entityCondition('entity_type', 'node')
  ->propertyCondition('type', $node_type)
  ->execute();

if (!empty($result['node'])) {
  $nodes = entity_load('node', array_keys($result['node']));

  foreach($nodes as $node) {
    // Replace field_foo with the machine name of the field to update.
    // - 0 refers to specific within the field array, for when the field contains
    //    multiple values. If the field only has one value, it should be 0.
//echo "<pre>";
//print_r($node->language);
     $node->language = 'en';
    node_save($node);
  }
}

Get information about node types

node_type_get_names()
returns an array of names
Array ( 
    [article] => Article 
    [page] => Basic page 
) 
node_type_get_types() returns an array of objects
Array (
  [article] => stdClass Object
        (
            [type] => article
            [name] => Article
            [base] => node_content
            [module] => node
            [description] => Use articles for time-sensitive content like news, press releases or blog posts.
            [help] => 
            [has_title] => 1
            [title_label] => Title
            [custom] => 1
            [modified] => 1
            [locked] => 0
            [disabled] => 0
            [orig_type] => article
            [disabled_changed] => 
        )

    [page] => stdClass Object
        (
           ..
        )
    ) 

<?php
  $type = $node->type;
  $types = node_type_get_types();
  $name = $types[$type]->name; 
  $description = $types[$type]->description;   
?>
<?php
$name = node_type_get_name($node);
?>
Returns all field definitions.
$var = field_info_fields("node", "node_type");

Reads in fields that match an array of conditions.
$var = field_read_fields(array('type') => 'node_type');

Sunday 17 May 2015

Recovering the Administrator Password for Drupal 7


//Firstly open your website folder and open index.php file
// these three lines of code paste to your index file as its is.
//Go to Browser and type yur site url--- localhost/drupal/index.php
//Password will show as hash format paste to your database in 'users' table and paste to pass column


<?php
define(‘DRUPAL_ROOT’, getcwd());
require_once DRUPAL_ROOT . ‘/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

require_once ‘includes/password.inc';
echo user_hash_password(‘typeyourpassword‘);
die();

menu_execute_active_handler();
?>

Thursday 14 May 2015

Value return Count in Mysql


Select count (*) + count (5) from table name

If 4 row present in table then print 8 because count(*) will return  4 and count (5) will also return  4.
Output - 8

Select count (*)+count (5)

If Table name is not define count(*) will return  1 and count(5) will also return  1
Output - 2

Wednesday 13 May 2015

How to alter captcha title in drupal 7

function web_register_form_alter(&$form,&$form_state,$form_id) {
switch($form_id){

case 'webform_client_form_81':     // this is form_id
    //drupal_set_message('<pre>'.print_r($form,TRUE));  
    $form['#after_build'][] = 'captch_title_change';      
 // captch_title_change func is define below, (#after_build) it runs after the form or element is built for display(#pre_render as same as).

$form['#validate'][] = 'webform_client_15_dev_form';
 // webform_client_15_dev_form func is define below, (#validate) it validate the form after submit.
    break;

case 'webform_client_form_65':
    //drupal_set_message('<pre>'.print_r($form,TRUE));
    $form['#after_build'][] = 'captch_title_change_hindi';     // another function define below
break;
}
}
function captch_title_change_hindi($form, &$form_state){
    $form['captcha']['captcha_widgets']['captcha_response']['#title'] ='सत्यापन इमेज';
    return $form;
}

function captch_title_change($form, &$form_state){
    $form['captcha']['captcha_widgets']['captcha_response']['#title'] ='Verification Image';
    return $form;
}

Tuesday 12 May 2015

How to Customize the Block Search Form

Drupal 7

Add the following code snippet to template.php in your theme and you can:
  • change the submit button to an image
  • change the text of the submit button to 'Go!' (just remove the // in front of that line of code, and delete the image_button code below it)
  • add default 'Search this site' text in the input form and make it disappear when users click in the input form
  • <?phpfunction YOURTHEME_form_alter(&$form, &$form_state, $form_id) {
      if ($form_id == 'search_block_form') {
        $form['search_block_form']['#title'] = t('Search'); // Change the text on the label element
        $form['search_block_form']['#title_display'] = 'invisible'; // Toggle label visibilty
        $form['search_block_form']['#size'] = 40// define size of the textfield
        $form['search_block_form']['#default_value'] = t('Search'); // Set a default value for the textfield
        $form['actions']['submit']['#value'] = t('GO!'); // Change the text on the submit button
        $form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/search-button.png');
    
        // Add extra attributes to the text box
        $form['search_block_form']['#attributes']['onblur'] = "if (this.value == '') {this.value = 'Search';}";
        $form['search_block_form']['#attributes']['onfocus'] = "if (this.value == 'Search') {this.value = '';}";
        // Prevent user from searching the default text
        $form['#attributes']['onsubmit'] = "if(this.search_block_form.value=='Search'){ alert('Please enter a search'); return false; }";
    
        // Alternative (HTML5) placeholder attribute instead of using the javascript
        $form['search_block_form']['#attributes']['placeholder'] = t('Search');
      }
    } ?>
    Note: When you copy the above snippet to an existing template.php in your theme - you need to replace YOURTHEME with the name of your theme (sure - it's obvious ...). You also have to pay attention to the use of the php brackets - <?php and ?>. The first one <?php should already be at the top of an existing template.php file and the closing one might not be useful if you later add more snippets, etc.
    Alternatively and probably better practice is to add the brackets to each snippet individually - this would mean you may have to add a closing bracket ?> to an existing template.php file before adding the above snippet.

    Change drupal default search input type Format:

    type="text" to type="search"

    It's works well in D6 and D7:

    /**
    * Changes the search form to use the "search" input element of HTML5.
    */
    function YOURTHEME_preprocess_search_block_form(&$vars) {
    $vars['search_form'] = str_replace('type="text"', 'type="search"', $vars['search_form']);
    }

    This snippet goes into the template.php file of your theme. In my case it's tao, that is why the function starts with "tao_". You have to rename it to match it your theme name.

    Reference Node is--
    https://www.drupal.org/node/154137
    https://www.drupal.org/node/45295

    Monday 11 May 2015

    Copy folder and files by Command prompt

    Copies files and directory trees.
    
    XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                               [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U]
                               [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                               [/EXCLUDE:file1[+file2][+file3]...]
    Example---
     xcopy "E:\xampp\htdocs" "D:\xampp\htdocs\sumit /O/E/H/K
    
    
     /A           Copies only files with the archive attribute set,
                   doesn't change the attribute.
      /M           Copies only files with the archive attribute set,
                   turns off the archive attribute.
      /D:m-d-y     Copies files changed on or after the specified date.
                   If no date is given, copies only those files whose
                   source time is newer than the destination time.
      /EXCLUDE:file1[+file2][+file3]...
                   Specifies a list of files containing strings.  When any of the
                   strings match any part of the absolute path of the file to be
                   copied, that file will be excluded from being copied.  For
                   example, specifying a string like \obj\ or .obj will exclude
                   all files underneath the directory obj or all files with the
                   .obj extension respectively.
      /P           Prompts you before creating each destination file.
      /S           Copies directories and subdirectories except empty ones.
      /E           Copies directories and subdirectories, including empty ones.
                   Same as /S /E. May be used to modify /T.
      /V           Verifies each new file.
      /W           Prompts you to press a key before copying.
      /C           Continues copying even if errors occur.
      /I           If destination does not exist and copying more than one file,
                   assumes that destination must be a directory.
      /Q           Does not display file names while copying.
      /F           Displays full source and destination file names while copying.
      /L           Displays files that would be copied.
      /H           Copies hidden and system files also.
      /R           Overwrites read-only files.
      /T           Creates directory structure, but does not copy files. Does not
                   include empty directories or subdirectories. /T /E includes
                   empty directories and subdirectories.
      /U           Copies only files that already exist in destination.
      /K           Copies attributes. Normal Xcopy will reset read-only attributes.
      /N           Copies using the generated short names.
      /O           Copies file ownership and ACL information.
      /X           Copies file audit settings (implies /O).
      /Y           Suppresses prompting to confirm you want to overwrite an
                   existing destination file.
      /-Y          Causes prompting to confirm you want to overwrite an
                   existing destination file.
      /Z           Copies networked files in restartable mode.

    Monday 27 April 2015

    Drupal install by drush command

    E:\xampp\htdocs\drupal>cd\

    E:\>cd xampp

    E:\xampp>mysql
    ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: N
    O)

    E:\xampp>mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 9
    Server version: 5.1.41 Source distribution

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql> create database newdrupal;
    Query OK, 1 row affected (0.00 sec)

    mysql> ;
    ERROR:
    No query specified

    mysql> exit;
    Bye

    E:\xampp>cd htdocs

    E:\xampp\htdocs>cd drupal

    E:\xampp\htdocs\drupal>drush si standard --account-name=admin --account-pass=adm
    in --db-url=mysql://root:@localhost/newdrupal


    You are about to create a sites/default/files directory and create a sites/defau
    lt/settings.php file and DROP all tables in your 'newdrupal' database. Do you wa
    nt to continue? (y/n): y
    No tables to drop.                                                          [ok]

    Starting Drupal installation. This takes a few seconds ...                  [ok]

    Installation complete.  User name: admin  User password: admin              [ok]


    E:\xampp\htdocs\drupal>


    si = SITE-INSTALL
    standard = INSTALLATION mode (second is manual)
    account-name=admin
    account-pass=admin
    db-url=mysql://root:@localhost/newdrupal
     

    Saturday 25 April 2015

    SQL syntax for each of the SQL commands

    Select Statement

    SELECT "column_name" FROM "table_name"


    Distinct
    SELECT DISTINCT "column_name" FROM "table_name"


    Where
    SELECT "column_name" FROM "table_name" WHERE "condition"


    And/or
    SELECT "column_name" FROM "table_name" WHERE "simple condition" {[AND|OR] "simple condition"}


    In
    SELECT "column_name"
    FROM "table_name"
    WHERE "column_name" IN ('value1', 'value2', ...)


    Between
    SELECT "column_name"
    FROM "table_name"
    WHERE "column_name" BETWEEN 'value1' AND 'value2'


    Like
    SELECT "column_name"
    FROM "table_name"
    WHERE "column_name" LIKE {PATTERN}


    Order By
    SELECT "column_name"
    FROM "table_name"
    [WHERE "condition"]
    ORDER BY "column_name" [ASC, DESC]


    Count
    SELECT COUNT("column_name")
    FROM "table_name"


    Group By
    SELECT "column_name1", SUM("column_name2")
    FROM "table_name"
    GROUP BY "column_name1"


    Having
    SELECT "column_name1", SUM("column_name2") FROM "table_name" GROUP BY "column_name1" HAVING (arithmetic function condition)


    Create Table Statement
    CREATE TABLE "table_name" ("column 1" "data_type_for_column_1", "column 2" "data_type_for_column_2",... )


    Drop Table Statement
    DROP TABLE "table_name"


    Truncate Table Statement
    TRUNCATE TABLE "table_name"


    Insert Into Statement
    INSERT INTO "table_name" ("column1", "column2", ...) VALUES ("value1", "value2", ...)


    Update Statement
    UPDATE "table_name" SET "column_1" = [new value] WHERE {condition}



    Delete From Statement
    DELETE FROM "table_name" WHERE {condition}



    Copy only the structure of an existing table into new table:

    SELECT * INTO tbl_new FROM tbl_old WHERE 1=2;

    Copy the structure and data of an existing table into new table:

    SELECT * INTO tbl_new FROM tbl_old;