CluesShop.com

Friday, 31 October 2014

add class to drupal 7

$form['myboxes']['foo'] = array(
 
'#attributes' => array('class' => array('ok')),
);

Thursday, 30 October 2014

Active search get rebuild the form using drupal 7 seach


function specialoffers_manage_validate($form, &$form_state) {
 drupal_set_title('Special  Offers');
   
   drupal_add_css(drupal_get_path('module', 'specialoffers') .'/css/specialoffers.css');
 
   $acitiveinactive = '';
   

    $form['#method'] = 'post';
       
      $acitiveinactive = isset($_POST['filterset']['filteroptions']) ? $_POST['filterset']['filteroptions'] : 1;
 
   
       if(($acitiveinactive == '1') || ($acitiveinactive == '0') ){
               $offerstatusresult =  new  offersoverview();
               $offerstatusresult->status = $acitiveinactive;
             
               $result =   $offerstatusresult->getoffersOrderbyPosition();
       } else{
              $offersall =  new  offersoverview();
              $offersall->status = $acitiveinactive;
              $result =   $offersall->getoffersAll();
       }
   
   global $base_url;
   $form['filterset'] = array(
          '#type' => 'fieldset',
         '#prefix' => '<div class="fleetviewcontain">',
       
       );
     $form['filterset']['filteroptions'] = array(
'#id' => 'filteroptions',
'#type' => 'select',
'#options' => array( 'All' => 'All' ,'1'=>'Active','0'=>'Inactive'),
"#limit_validation_errors" => array(),
'#default_value' => $acitiveinactive,
);

$form['filterset']['btn'] = array(
'#type' => 'submit',
'#value' => 'Go',
                     

);






function specialoffers_manage_validate($form, &$form_state) {

 
if ($form_state['triggering_element']['#value'] == 'Go') {
$form_state['rebuild'] = TRUE;
return;
}

}

Tuesday, 28 October 2014

get role id from role name in drupal 7?

This is quite straightforward with user_roles() and array_search(). Below is a function which will return the role ID if there is a role matching the name and FALSE otherwise.
function get_role_by_name($name) {
  $roles = user_roles();
  return array_search($name, $roles);
}

// Sample usage
$rid = get_role_by_name('administrator');
One liner would be:
$rid = array_search('administrator', user_roles());

Create new user in drupal 7

public function createNewUser(){
        $result=true;
        try{
            $roles = user_roles();
           
            $selectedRole=array();
            foreach($roles as $key => $value){
                if($key==$this->role_id){
                    $selectedRole[$key]=$value;
                }
            }
           
           
            $newUserData = array(
                    'name' => $this->user_name,
                    'pass' => $this->password, // note: do not md5 the password
                    'mail' => $this->mail,
                    'status' => $this->status,
                    'timezone' => variable_get('date_default_timezone'),
                    'init' => $this->mail,
//                     'roles' => array(
//                             DRUPAL_AUTHENTICATED_RID => 'authenticated user',
//                             $this->role_id='tess',
//                     ),
                    'roles'=>$selectedRole,
                    'data' => '',
            );
            //Step 1 : Save the User Details in Drupal built in function user_save
            //The Data stored in users and user_roles table
            $new_user = user_save(@$account, $newUserData);
           
            //Success
            if($new_user){
                //Step 2 : Save the User Details in user_details Table
                try {
                    $query=db_insert('user_accounts');
                    $query->fields(array(
                            'uid'=>$new_user->uid,
                            'first_name'=>$this->firstname,
                            'last_name'=>$this->last_name,
                            'company_name'=>$this->company_name,
                            'phone'=>$this->phone,
                            'address'=>$this->address,
                    ));
                    $userid=$query->execute();
                   
                    if($userid){
                        $result=$new_user->uid;
                        //return $userid;
                        //success
                    }else{
                        $result=false;
                        //failed
                        watchdog("userdetails", 'userdetails record insertion failed');
                    }
                }catch (Exception $e){
                    $result=false;
                    watchdog("userdetails", $e);
                }
            }
        }catch(Exception $e){
            $result=false;
            watchdog("userdetails", $e);
        }
       
        return $result;
    }

Include files in drupal 7 .info

; $Id$
name = fleet management
description = Fleet Management Back End
core = 7.x
package = LSN Software Services

dependencies[] = ckeditor

files[] = classes/hide_show.inc
files[] = classes/fleetoverview.class.inc
files[] = classes/fleetvirtualtour.class.inc
files[] = classes/fleetmiddlecontain.class.inc
files[] = classes/fleetgallery.class.inc
files[] = classes/fleetnav.class.inc
files[] = classes/fleetdelete.class.inc


Insert delete drupal 7 classs

<?php

class Fooandbarcat{
   
    public static $tableName="foodandbarcat";
    public $catName='';
    public $catId='';
    public $status;
    public $position;
   
    public function insertFoodandBarCategoriesData(){
        try{
        $record = array( 'catName' => $this->catName);
        $results= db_insert(self::$tableName)
                ->fields($record)
->execute();
return $results;
            }catch(Exception $e){

               
            }
}
       
      public  function getFoodandBarategoriesData(){
          try{
$result = db_select(self::$tableName, 'g')
->fields('g')
->condition('catId', $this->catId, '=')
->execute()->fetchObject();
return $result;
          }catch(Exception $e){
              drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
          }
}
       
        public  function getActiveFoodandbarEvents(){
            try{
$result = db_select(self::$tableName, 'p')
->fields('p')
                ->condition('status',$this->status ,'=')
                ->orderBy('position', 'ASC')      
->execute()->fetchAll();
return $result;
                }catch(Exception $e){
              drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
            }

}
        public  function getAllFoodandbarEvents()
        {
         try{
            $result=db_select('foodandbarcat','h')
                ->fields('h')
                ->orderBy('h.position')
                ->execute()
                ->fetchAll();
            return $result;
             }catch(Exception $e){
              drupal_set_message(t('db_select failed. Message = %message, query= %query',array('%message' => $e->getMessage(), '%query' =>$e->query_string)), 'error');
            }
        }
       
       
         public  function getFoodandBarUpdateData(){
                  db_update(self::$tableName)
->fields(array('catName' => $this->catName))
->condition('catId', $this->catId, '=')
->execute();

        }
       
         public function deleteDataFromwwcfoodandbarcat(){
                       db_delete(self::$tableName)
                           ->condition('catId', $this->catId)    
                          ->execute();
      }
     
         public function updateFoodandBarStatus(){
                     db_update(self::$tableName)
                            ->fields(array('status' => $this->status))
                            ->condition('catId', $this->catId, '=')
                            ->execute();

}
       
       
        public function orderbyPositionfoodandbar(){
                     $results= db_update('foodandbarcat')
                                ->fields(array('position' => $this->position))
                                ->condition('catId', $this->catId, '=')
                                ->execute();
                       return $results;
        }
     
}

Drupal 7 form for every one

function agentregistration_menu(){
    $items = array();
    $items['agentregistration'] = array(
         'title' => 'Agent Registration',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('agent_registration'),
        'file' => 'inc/agentregistration.inc',
        'access callback' => 'user_access',
'access arguments' => array('access content'),
       
    );
   
     return $items;
}