Pages

Thursday 29 September 2016

Sending a mail with attachment in drupal

/* function for generate a CSV file  in drupal*/
 
function exportMobileCsv($filename, $column, $data) {
  $handle = fopen($filename, 'w+');
  fputcsv($handle, $column, ',');
  foreach ($data as $row) {
    fputcsv($handle, (Array)$row, ',');
  }
  file_save_data($handle, $filename);
  fclose($handle);
}


/* function for sending a mail in drupal*/

function mobileapp_mail_csv($from, $subject, $body, $filename) {
  $attachment = array(
    'filepath' => drupal_realpath($filename),
  );
  $mydate =  date('Y-m-d');
  $body = "<html><body>
    <p>
        Hi,
        <br/><br/><br/>Please find attached $mydate . <br />"."
    </p>
    <br/><br/>Regards,
    </body></html>";

  $to = 'hello@gmail.com';
  $headers['Cc'] = 'sumit.prajapati@rediff.com';
  $params = array(
    'to' => $to,
    'attachment' => $attachment,
    'body' => $body,
    'subject' => 'save',
    'headers' => $headers,
  );
  drupal_mail('mobileapp', 'mobileapp_mail_csv', $params['to'], language_default(), $params);
}



/* Function for attachemnt of file. */

function mobileapp_mail($key, &$message, $params) {
  switch ($key) {
    case 'mobileapp_mail_csv':
        $message['subject'] = $params['subject'];
        $message['body'][] = $params['body'];
      if (isset($params['attachment'])) {
        $message['params']['attachments'][] = $params['attachment'];
      }
      $message['headers'] += $params['headers'];
  }
}

Monday 26 September 2016

Display single column data break in multiple columns Mysql


Example Table -



nid sid cid data
938 6 1 Sumit
938 6 2 sau@gmail.com
938 6 3 9878990677
938 7 1 Priya
938 7 2 priya@gmail .com
938 7 3 9878990677
938 8 1 kishan
938 8 2 kishan@gmail.com
938 8 3 9878990677
938 9 1 Sunil
938 9 2 sunil@gmail.com
938 9 3 9878990677
938 10 1 Vika
938 10 2 vik@gmail.com
938 10 3 9878990677
938 11 1 Jain
938 11 2 sab@gmail.com
938 11 3 9878990677
938 12 1 Johari
938 12 2 Johari@gmail.com
938 12 3 9878990677

Now we want to


 sid Name Email Mobile
6 Sumit sau@gmail.com 9878990677
7 Priya priya@gmail .com 9878990677
8 kishan kishan@gmail.com 9878990677
9 Sunil sunil@gmail.com 9878990677
10 Vika vik@gmail.com 9878990677
11 Jain sab@gmail.com 9878990677
12 Johari Johari@gmail.com 9878990677

SELECT wsd.sid,
MAX( IF( wsd.cid =1, wsd.data, NULL ) ) AS `Name` ,
MAX( IF( wsd.cid =2, wsd.data, NULL ) ) AS `Email` ,
MAX( IF( wsd.cid =3, wsd.data, NULL ) ) AS `Mobile` FROM webform_submitted_data wsd WHERE nid =938 Group By sid

Explanation- 

IF(condition, value1, value2) 

if condition = value met than its print single value in row other two value will be null
Null value is zero
So we use max for highest value its print all value in single row 


Tuesday 3 May 2016

Unzip/extract a .tar.gz file?

Unzip/extract a .tar.gz file?

tar -xvzf community_images.tar.gz

sql.gz file to my database? (importing)

gunzip < myfile.sql.gz | mysql -u root -p mydb


ubuntu command to move a directory

mv -if html/backup /var/www/hep


Copy Content Local to Remote Server Command

rdesktop -r clipboard:CLIPBOARD -f -u'username' -p'password' IP

Wednesday 9 March 2016

Create custom Token for Password

/**
 * Implements hook_token_info().
 */
function module_name_token_info() {
  $info['tokens']['user']['password'] = array(
    'name' => t('Password'),
    'description' => t('The password by the user'),
  );
  return $info;
}

/**
 * Implements hook_tokens().
 */
function module_name_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  $url_options = array('absolute' => TRUE);
  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
  }

  if ($type == 'user' && !empty($data['user'])) {
    $account = $data['user'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'password':
          $replacements[$original] = $account->password;
          break;
      }
    }
  }

  return $replacements;
}

Friday 19 February 2016

Adding “Unblock user” option in Views Bulk Operations field

In drupal 7-

We need a Rules module, after enable Rules module and Rules UI go to

Configuration -> Workflow-> Rules-> Component-> Add Component

In Component plugin dropdown-> select Action Set
then add next page 
Fill the mandatory field Name as (Ex: Unblock user) shown in image


Select Data type from list User ---Label Unblock user ---machine name unblock_user -- usage parameter 
then click on continue button
then click on Add Action Link (highlighted)



then Select the action to add User ->Unblock User
Select Data Selector -> unblock-user and Save


Now go to- Views Page add field Bulk operations there will be present Unblock user option as image shown following-

In setting option you can set Permission roles wise as image shown below-