How to Enable SSL in Drupal?

STEPS:

  1. Download & Install “SMTP Authentication Supportmodule from http://drupal.org/project/smtp
  2. Configure the SMTP settings in Admin -> Configuration -> System -> SMTP Authentication Support
  3. Gmail SMTP server address: smtp.gmail.com
  4. Gmail SMTP user name: Your full Gmail address (e.g. me@gmail.com)
  5. Gmail SMTP password: Your Gmail password
  6. Gmail SMTP port: 465
  7. Gmail SMTP TLS/SSL required: yes

In Use encrypted protocol select Use SSL

–     If  Use SSL is not  appeared in drop-down, enable extension=php_openssl.dll in php.ini

8. In SEND TEST E-MAIL, Enter the mail address to test. We will get a test mail if SMTP is configured perfectly.

Categories: Drupal

Microsoft (SQL Server 2.0) Drivers for PHP!! using SQLSRV

December 9, 2011 2 comments

STEPS:
1. First we need to install SQL Server Native Client before installing SQL driver for PHP  in your System.
My System Configuration is,
Operating System: Windows 7
System Type: 32-bit Operating System

Install from the http://technet.microsoft.com/en-us/library/cc296170.aspx

— We will get a page titles System Requirements
— We can see a link “Download the X86 package” (If 64-bit OS download X64 package)
— Click the link will download the required file.
— Install it into our system.

2. Download SQLSRV30.EXE OR SQLSRV20.EXE  from http://www.microsoft.com/download/en/details.aspx?id=17308
as per our system requirements.
Check php.ini – If

Compiler MSVC9 (Visual C++ 2008)

Then download php_sqlsrv_53_ts_vc9.dll and include in php.ini as STEP 5.

3.Run the SQLSRV30.EXE OR SQLSRV20.EXE file will ask path for placing the files. Select the PHP extension Directory.
Ex: D:\wamp\bin\php\php5.3.8\ext

4. Also check in php.ini
extension_dir = “D:/wamp/bin/php/php5.3.8/ext/”

5. Include in php.ini as,
extension=php_sqlsrv_53_ts.dll

OR

extension=php_sqlsrv_53_ts_vc6.dll
OR

extension=php_sqlsrv_53_ts_vc9.dll

See the configuration of your system and enable it in php.ini

6. Restart the wampp Server. If not reflected in phpinfo(), restart the sytem.

PHP Code to Connect
=================

<?php//phpinfo();/*Connect to the local server using Windows Authentication and specifythe AdventureWorks database as the database in use. To connect usingSQL Server Authentication, set values for the “UID” and “PWD”attributes in the $connectionInfo parameter. For example:$connectionInfo = array(“UID” => $uid, “PWD” => $pwd, “Database”=>”AdventureWorks”);*/$serverName = “10.18.1.254\SQL2000”;

$connectionInfo = array( “Database”=>”MCMS”, “UID”=>”sa”, “PWD”=>”Defiance123”);

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn )

{

//echo “Connection established.\n”;

/* Get the product picture for a given product ID. */

$tsql = “SELECT  [BlobData] FROM [MCMS].[dbo].[BlobTable] WHERE BlobId = ?”;

$params = array(24);

/* Execute the query. */

$stmt = sqlsrv_query($conn, $tsql, $params);

if( $stmt === false )

{

echo “Error in statement execution.</br>”;

die( print_r( sqlsrv_errors(), true));

}

/* Retrieve the image as a binary stream. */

$getAsType = SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY);

if ( sqlsrv_fetch( $stmt ) )

{

$image = sqlsrv_get_field( $stmt, 0, $getAsType);

fpassthru($image);

}

else

{

echo “Error in retrieving data.</br>”;

die(print_r( sqlsrv_errors(), true));

}

/* Free the statement and connectin resources. */

sqlsrv_free_stmt( $stmt );

sqlsrv_close( $conn );

}

else

{

echo “Connection could not be established.\n”;

die( print_r( sqlsrv_errors(), true));

}

?>

Categories: PHP, SQL Server

Microsoft SQL Server ODBC Driver Configuration

Steps:
1. Click Control Panel -> All Control Panel Items -> Administrative Tools -> Data Sources (ODBC)

Click Data Sources (ODBC)

Click Data Sources (ODBC)

2. Opens the ODBC Data Source Administrator Pop-up.

3. Select the User DSN -> Click the ADD button to add new DSN

Click the ADD Button

Click the ADD Button

4. Opens a Create New Data Source Pop-up. Select SQL Server and click Finish.

5. Now opens another Pop-up for Database Connection
6. Enter Name, Description for the connection.
7. In SERVER: field provide the server name/ IP and Instance Name

Ex:   10.10.10.20/SQL2005

SQLExpress/SQL2005

Click Next

Click Next

8. Click Next will ask for DB Mapping.

Check the Change the default database to.

In the Change the default database to box, use the pull down list to select the SQL database name that you created using SQL SERVER 2005 MANAGEMENT STUDIO.

Select the required DB.

Select the reruired DB

Select the reruired DB

9. Check Use ANSI quoted identifiers.

Check Use ANSI nulls, paddings and warnings.

   Click Next.

10.  Select Use regional settings…… and click Finish.

11. Click the Test Data Source and Test it.

12. We will get the following successful message dialog box.

13.   Select OK 3 times (one for each dialog box) to exit ODBC configuration.

If it did not Test Successfully.

Try these steps:

–  If the SQL Server is a remote node, verify that TCP port 1433 is open on the SQL Server Node (i.e. check any firewalls or Windows Firewall).

–  Verify the SA Login Password or whatever Login ID you used to configure this DSN.

– Verify the Database name.

– Verify that SQL Server is running.

13. Now we will get the connection Name in the User DSN.

We can see the created DSN name here

We can see the created DSN name here

10. Thats It. Connection has been successfully created for SQL Server through ODBC

We will see how we can access through PHP,

<?php/*

PHP MSSQL Example

Replace data_source_name with the name of your data source.

Replace database_username and database_password

with the SQL Server database username and password.

*/

$data_source=”Driver={SQL Server};Server=10.10.10.20\SQL2005;Database=Name of the DB;”;

$user=’sa’; // Username of the SQL server

$password=’Xxxxxx456′; // Password of the SQL server

// Connect to the data source and get a handle for that connection.

$conn=odbc_connect($data_source,$user,$password);

if($conn)

echo ‘success’;

else

echo ‘failed’;

?>

Categories: PHP, SQL Server

Clear Drupal Cache Manually

DRUPAL 7

If we want clear the cache by default, without admin user action. Normaly we use to clear the cache by admin/performance/.
This can be indirectly achieved for nodes as below,

function [module_name]_node_update($node){cache_clear_all(‘*’, ‘cache_views_data’, TRUE);
}

For Blocks,

While creating blocks for the module we can write as,

function [module_name]_block_info() {$blocks[‘product_filter’] = array(
‘info’ => t(‘Product Filter’),
‘cache’ => DRUPAL_NO_CACHE,
);

return $blocks;
}

Categories: Drupal

Drupal – video popout option as vimeo

Steps for integration:
1. Add the below code where you have video link,

<?phpecho

‘<link href=”‘.$base_url.’/sites/all/themes/scaccarium/jquery-ui.css” rel=”stylesheet” type=”text/css”/>

<script src=”‘.$base_url.’/sites/all/themes/scaccarium/js/jquery.min.js”></script>

<script src=”‘.$base_url.’/sites/all/themes/scaccarium/js/jquery-ui.min.js”></script>

<script type=”text/javascript” src=”‘.$base_url.’/sites/all/themes/scaccarium/js/fancybox/jquery.fancybox-1.3.4.js”></script>

<link rel=”stylesheet” type=”text/css” href=”‘.$base_url.’/sites/all/themes/scaccarium/js/fancybox/jquery.fancybox-1.3.4.css” media=”screen” />

<script type=”text/javascript”>

$(document).ready(function() {

$(“.videolist”).fancybox({

“width” : “48%”,

“height” : “44%”,

“autoScale” : false,

“transitionIn” : “none”,

“transitionOut” : “none”,

“type” : “iframe”

});

});

</script>’;

$bpath = $base_url.”/keyarticle/flowplayer?href=”.$base_url.”/”.$vidval[“filepath”].”&width=540&height=304″;

$attributes = array(‘attributes’ => array(‘id’ => ‘various3’, “class”=>”videolist”));

$cont = “<li>”.l($vidval[“filename”], $bpath, $attributes).”</li>”;

?>

2.  Include all the relevant files appropriately

3. Customize the jquery.fancybox-1.3.4.js as below,

$(document).ready(function() {

$.fancybox.init();

$( “#fancybox-wrap” ).draggable();

$( “#fancybox-wrap” ).resizable();

$(“#fancybox-wrap”).resize(function() {

var height = $(“#fancybox-wrap”).height();

var width = $(“#fancybox-wrap”).width();

var height = height-0;

var width = width-0;

var newheight = height-40;

var newwidth = width-40;

var newheight = newheight + “px”;

var newwidth = newwidth + “px”;

var height = height + “px”;

var width = width + “px”;

var framename = document.getElementById(‘fancybox-frame’);

var frmname = (framename.contentDocument) ? framename.contentDocument :framename.contentWindow.document;

frmname.getElementById(‘player’).style.height = newheight;

frmname.getElementById(‘player’).style.width = newwidth;

document.getElementById(‘fancybox-frame’).style.height = height;

document.getElementById(‘fancybox-frame’).style.width = width;

document.getElementById(‘fancybox-content’).style.height = height;

document.getElementById(‘fancybox-content’).style.width = width;

});

});

4.  Also the jquery.fancybox-1.3.4.css to fix our own style,

#fancybox-wrap {

position: absolute;

top: 0;

left: 0;

padding: 20px;

z-index: 1101;

outline: none;

display: none;

background:#0B183B;

-moz-border-radius:10px;

cursor:pointer

}

#fancybox-outer {

position: relative;

width: auto;

height: auto;

padding:10px

}

#fancybox-content {

width: 0;

height: 0;

padding: 0;

outline: none;

position: relative;

overflow: hidden;

z-index: 1102;

}

#fancybox-frame {

overflow:hidden;

border: none;

display: block;

}

5. Now click the video link, we will get a popout option with draggable & resizable.

Categories: Drupal

Drupal, webform and Dynamic Checkboxes

Create a new file in the webform/components directory called dynamicselect.inc and added the function below.

<?php
function _webform_help_dynamicselect($section) {
switch ($section) {
case ‘admin/settings/webform#dynamicselect_description’:
$output = t(“A dynamic list of upcoming events.”);
break;
}return $output;} // end function _webform_help_dynamicselect($section)
?>

The form that makes the form

Next, I had to build the form element that would be used by the webform module to set up my dynamicselect element…

 This is somewhat complicated. Here is what happens:

When you create a webform you have to fill out a form with things like the form’s name and description and any other fields you might fill out to create any type of node.

In addition, you have to add the form elements, like textfields and markup. When you add the element, you are redirected to another form that asks about the element’s properties, like its key value and whether or not it is mandatory. When you create a new component you have to create the form that asks these questions…

 Maybe it would be better if I just showed you the function.

<?php
function _webform_edit_dynamicselect($currfield) {
 
  $edit_fields = array();
  $edit_fields[‘value’] = array(
    ‘#type’          => “textfield”,
    ‘#title’         => t(“Default value”),
    ‘#default_value’ => $currfield[‘default’],
    ‘#description’   => t(“The default value of the field.”) .
      “<br />” . webform_help(“webform/helptext#variables”),
    ‘#size’          => 60,
    ‘#maxlength’     => 255,
    ‘#weight’        => 0,
  );
 
  return $edit_fields;

} // end function _webform_edit_dynamicselect($currfield)
?>

That’s it. Actually, all of this is just cut and pasted from the select component. All I am doing is setting up a field where you can enter a default value for your instance of the dynamicselect component. All the other form items like key, name, description, etc. are added later by the webform module.

Just in case you are wondering, I did not make a_webform_edit_validate_dynamicselect() function because I did not need to do anything beyond the built-in validation.

Rendering the dynamicselect element

Now, I need the code to actually build the dynamicselect element when the webform is displayed.

<?php
function _webform_render_dynamicselect($component, $data = false) {
 
  $form_item = array(
    ‘#title’       => htmlspecialchars($component[‘name’], ENT_QUOTES),
    ‘#required’    => $component[‘mandatory’],
    ‘#weight’      => $component[‘weight’],
    ‘#description’ => _webform_filtervalues($component[‘extra’][‘description’]),
    ‘#prefix’      => “<div class=’webform-component-” .
      $component[‘type’] . “‘ id=’webform-component-” .
      $component[‘form_key’] . “‘>”,
    ‘#suffix’      => “</div>”,
  );
 
  // set the default value
  $default_value = _webform_filtervalues($component[‘value’]);
  if ($default_value) {
    $form_item[‘#default_value’] = $default_value;
  }
 
  // set the component options
  if ($data) { // $data is set
    $options = _dynamicselect_display_options($data);
  } else { // $data is not set
    $options = _dynamicselect_load_options();
  }
  $form_item[‘#options’] = $options;

  // set display as a checkbox set
  $form_item[‘#type’] = “checkboxes”;
 
  return $form_item;

} // end function _webform_render_dynamicselect($component)
?> 

 
Again, almost all of the code above is stripped out of the select component and simplified. If you need to build a different type of select, like a drop-down or radio buttons, you will need to change the code here.

Experienced Drupal developers may have noticed two things. First, I stripped the code that handles multiple default values. This is because I am only ever planning on setting the default value to %get[id]. Obviously, a more modular version of this component would not skip this step.

Second, you may have noticed that I added a second, optional parameter to the function:$data = false. This will make sense later when we display submission results. For now, the important line in the code above is this one.

<?php
    $options = _dynamicselect_load_options();
?>

Dynamically loading the options

The _dyanmicselect_load_options() function is what makes this component unique. It dynamically generates a list of options each time the form is loaded. Here it is.

<?php
/**
* dynamically load events that are happening in the next 13
* weeks excluding events that are not published or not open
* for registration
*/
function _dynamicselect_load_options() {$options = array();
$options[-1] = “Other”;$one_quarter = 7 * 13 * 24 * 60 * 60;
$query = “SELECT * FROM {countries}”;

$results = db_query($query, OMI_OPEN_STRING, $one_quarter, $default_value);

while ($result = db_fetch_array($results)) {
//$start = format_date($result[‘event_start’], “custom”, “n/j”);
$ccode = $result[‘ccode’];
$option = $ccode .’ – ‘. $result[‘name’];
$options[$result[‘id’]] = $option;
} // end while

return $options;

} // end function _dynamic_select_load_options()
?>

 
As you can see this function is unique to my needs. This would need to be re-written if you need to filter your options differently. In addition, you may not want to do everything inside a query. In fact, if someone was really ambitious they could turn this into a “real” webform component by implementing filters and fields, like the views module.

In the end the code above returns an associative array that becomes the checkboxes on the webform. It looks something like this.

Array
(
[-1] => Other
[1] => IND - INDIA
...
)

That’s all there is to creating the element. I don’t even have to write a custom_webform_submit_dynamicselect() function because I don’t need to change the values created by the default form functions.

Displaying the results

A very useful feature of the webform module is the fact that it stores all submissions in the database, and you can look at them in a variety of ways. However when the options are generated dynamically, displaying the submissions becomes more complicated. Here is the function for viewing one single submission.

<?php
function _webform_submission_display_dynamicselect($data,$component) {$form_item = _webform_render_dynamicselect($component,$data);// set the selected values as checked, i.e. default
foreach ((array)$data[‘value’] as $value) {
if ($value) {
$form_item[‘#default_value’][] = $value;
}
}

$form_item[‘#attributes’] = array(“disabled” => “disabled”);

return $form_item;

} // function _webform_submission_display_dynamicselect()
?>

 
Again, most of this is just a simplified version of what is done in the select component, but, as you can see, this is where the second argument, $data, for_webform_render_dynamicselect() is used. This causes the rendering function to switch tracks when building the options.
<?php
if ($data) { // $data is set
//$options = _dynamicselect_display_options($data); // customize this according to ur requirement

    $options = _dynamicselect_load_options();

  } else { // $data is not set
$options = _dynamicselect_load_options();
}
?>

 
There are several reasons that I want to display the options differently when I am showing submission results. First, I only want to show the events that were selected, not every open event in the next 13 weeks. Especially since I might be viewing the submission after the start date has passed or the event has been closed for registration. Also, I need to handle invalid data that might have gotten into the database, including events that have been deleted. Here is how I dealt with that.
<?php
function _dynamicselect_display_options($data) {$options = array();foreach ($data[‘value’] as $key => $val) {
if ($val == -1) {
$options[-1] = “Other”;
} else if ($val && ctype_digit((string)$val)) {
$event_node = node_load($val);
if ($event_node->type == “event”) {
$start = format_date($event_node->event_start,”custom”, “n/j/Y”);
$end = format_date($event_node->event_end, “custom”,”n/j/Y”);
$option = $event_node->title . ” $start – $end”;
$options[$val] = $option;
} else { // deal with deleted events
$options[$val] = “non-event id: $val”;
}
} else if ($val) { // deal with invalid values
$options[] = “invalid value: ” . check_plain($val);
}
}

return $options;

} // end function _dynamicselect_display_options($data)
?>

 

Of course, there are other ways to display the submissions, and last but definitely not least, the submission can be sent as an email. Each of these has to be handled in a similar fashion to the function above. I will not include each of those functions here, but I will include them in the code below…

PHP webform.module code
======================

In webform.module include the below code in

Function Name: function webform_webform_component_info()

Code to write :

‘dynamicselect’ => array(
‘label’ => t(‘Dynamic Select options’),
‘description’ => t(‘Allows creation of checkboxes, radio buttons, or select menus.’),
‘file’ => ‘components/dynamicselect.inc’,
‘features’ => array(
’email_address’ => TRUE,
’email_name’ => TRUE,
),
),

PHP dynamicselect.inc code
========================

In webform/components include the below code with filename dynamicselect.inc

<?php

// TODO: add CSV output someday

define(“OMI_OPEN_STRING”, “Open”);

/**
* Creates a “default value” form item to be displayed on the form for
* editing an instance of the dynamicselect component.  Other form items
* like key, name, description, etc. are added later by the webform module.
* @return
*   An array of form items to be displayed on the edit component page.
*/
function _webform_edit_dynamicselect($currfield) {

 $edit_fields = array();
 $edit_fields[‘value’] = array(
      ‘#type’          => “textfield”,
      ‘#title’         => t(“Default value”),
      ‘#default_value’ => $currfield[‘default’],
      ‘#description’   => t(“The default value of the field.”).”<br />”. webform_help(“webform/helptext#variables”),
      ‘#size’          => 60,
      ‘#maxlength’     => 255,
      ‘#weight’        => 0,
      );

 return $edit_fields;

} // end function _webform_edit_dynamicselect($currfield)

/**
* Build a form item array containing all the properties of this component.
* @param $component
*   An array of information describing the component, directly correlating to
*   the webform_component database schema.
* @return
*   An array of a form item to be displayed on the client-side webform.
*/
function _webform_render_dynamicselect($component, $data = false) {

 $form_item = array(
  ‘#title’       => htmlspecialchars($component[‘name’], ENT_QUOTES),
  ‘#required’    => $component[‘mandatory’],
  ‘#weight’      => $component[‘weight’],
  //’#description’ => $component[‘extra’][‘description’],
  ‘#prefix’      => “<div class=’webform-component-” .
   $component[‘type’] . “‘ id=’webform-component-” .
   $component[‘form_key’] . “‘>”,
  ‘#suffix’      => “</div>”,
  );
 
 // set the default value
 $default_value = $component[‘value’];
 if ($default_value) {
  $form_item[‘#default_value’] = $default_value;
 }
 
 // set the component options
 if ($data) { // $data is set
  //$options = _dynamicselect_display_options($data);
  $options = _dynamicselect_load_options($data);
 
 } else { // $data is not set
  $options = _dynamicselect_load_options($default_value);
 }
 $form_item[‘#options’] = $options;
 
 // set display as a checkbox set
 $form_item[‘#type’] = “select”;
 
 return $form_item;

} // end function _webform_render_dynamicselect($component)

/**
* Display the results of a dynamicselect submission.
* @param $data
*   An array of information containing the submission result, directly
*   correlating to the webform_submitted_data database schema.
* @param $component
*   An array of information describing the component, directly correlating to
*   the webform_component database schema.
* @return
*   Textual output formatted for human reading.
*/
function _webform_submission_display_dynamicselect($data, $component) {

 $form_item = _webform_render_dynamicselect($component, $data);
 
 // set the selected values as checked, i.e. default
 foreach ((array)$data[‘value’] as $value) {
  if ($value) {
   $form_item[‘#default_value’][] = $value;
  }
 }
 
 $form_item[‘#attributes’] = array(“disabled” => “disabled”);
 
 return $form_item;

} // function _webform_submission_display_dynamicselect()

/**
* instance of hook_help().
*/
function _webform_help_dynamicselect($section) {

 switch ($section) {
  case ‘admin/settings/webform#dynamicselect_description’:
   $output = t(“A dynamic list of upcoming events.”);
  break;
 }
 
 return $output;

} // end function _webform_help_dynamicselect($section)

/**
* dynamically load events that are happening in the next 13
* weeks excluding events that are not published or not open
* for registration
*/
function _dynamicselect_load_options($default_value) {

 $options = array();
 $options[-1] = “Other”;

 $one_quarter = 7 * 13 * 24 * 60 * 60;
 $query = “SELECT * FROM {states1}”;

 //$results = db_query($query, OMI_OPEN_STRING, $one_quarter, $default_value);
 $results = db_query($query);

 foreach ($results as $result) {
  $ccode = $result -> code;
  $option = $ccode .’ – ‘. $result -> state;
  $options[$result -> id] = $option;
 }

 /* DRUPAL 6
 while ($result = db_fetch_array($results)) {
  //$start = format_date($result[‘event_start’], “custom”, “n/j”);
  $ccode = $result[‘code’];
  $option = $ccode .’ – ‘. $result[‘state’];
  $options[$result[‘id’]] = $option;
 } // end while */
 
 return $options;

} // end function _dynamic_select_load_options()

function _dynamicselect_display_options($data) {

 $options = array();

 foreach ($data[‘value’] as $val) {
  _dynamicselect_format_option($options, $val);
 }

 return $options;

} // end function _dynamicselect_display_options($data)

function _dynamicselect_format_option(&$options, $val) {

 if ($val == -1) {
  $options[-1] = “Other”;
 } else if ($val && ctype_digit((string)$val)) {
  $event_node = node_load($val);
  //if ($event_node->type == “event”) {
  //$start = format_date($event_node->event_start, “custom”, “n/j”);
  // $end = format_date($event_node->event_end, “custom”, “n/j”);
  $option = $event_node->title . “$start – $end”;
  $options[$val] = $option;
  //} else { // deal with deleted events
  //  $options[$val] = “non-event id: $val”;
  //}
 } else if ($val && $val != “”) { // deal with invalid values
  $options[] = “invalid value: ” . check_plain($val);
 }

} // end function _dynamicselect_format_option($val)

/**
* Format the output of emailed data for this component.
*
* @param $data
*   A string or array of the submitted data.
* @param $component
*   An array of information describing the component, directly correlating to
*   the webform_component database schema.
* @return
*   Textual output to be included in the email.
*/
function theme_webform_mail_dynamicselect($data, $component) {

// NOTE: this is slightly redundant, but it is easy to
//       plug in to existing functions
 $options = array();
 foreach ($data as $val) {
  _dynamicselect_format_option($options, $val);
 }
 $output = $component[‘name’] .”:\n”;
 foreach ($data as $value) {
  if ($value) {
   $output .= ”    • ” . $options[$value] .”\n”;
  }
 }
 
 return $output;

} // end function theme_webform_mail_dynamicselect()

/**
* Return the result of this component’s submission for display in a table. The
* output of this function will be displayed under the “results” tab then “table”.
* @param $data
*   An array of information containing the submission result, directly
*   correlating to the webform_submitted_data database schema
* @return
*   Textual output formatted for human reading.
*/
function _webform_table_data_dynamicselect($data) {

 // TODO: refactor
 $options = array();
 foreach ($data[‘value’] as $val) {
  _dynamicselect_format_option($options, $val);
 }
 $output = “”;
 foreach ($data[‘value’] as $value) {
  if ($value) {
   $output .= ”    • ” . $options[$value] .”<br />\n”;
  }
 }
 
 return $output;

}

/**
* Calculate and returns statistics about results for this component from all
* submission to this webform. The output of this function will be displayed
* under the “results” tab then “analysis”.
* @param $component
*   An array of information describing the component, directly correlating to
*   the webform_component database schema
* @return
*   An array of data rows, each containing a statistic for this component’s
*   submissions.
*/
function _webform_analysis_rows_dynamicselect($component) {

// NOTE: this isn’t very informative, but since I’ve never
//       used it I’m not going to do any more work on it

 $query = ‘SELECT data, count(data) as datacount FROM {webform_submitted_data} WHERE nid = %d AND cid = %d ‘.
 ” AND data != ‘0’ AND data != ‘ ‘ GROUP BY data”;
 $result = db_query($query, $component[‘nid’], $component[‘cid’]);
 $rows = array();
 while ($data = db_fetch_array($result)) {
  $rows[] = array($data[‘data’], $data[‘datacount’]);
 }
 
 return $rows;

}

 

Categories: Drupal

Tweet the content into Twitter

Following steps to create twitter apps In CakePHP :

 

Step 1 : Create a twitter A/C

Step 2 : CURL Must be enabled in your server

Step 3 : Log in to twitter A/C to create an API

a. https://dev.twitter.com/user/login?destination=home

b. Click username on top menu you have one sub menu named My applications

c. Click My application menu

d. Click Create a new application

e. Fill up the application details

f. Callback URL must have .php extenstion

g. Website must be a valid website. we can give our localhost url also

h. Callback URL means after verification of username and password the page redirect into which page

i. click the submit you get the API informations.

j. Under Details->OAuth settings we get Consumer key,Consumer secret and etc.,

 

Step 4 : Go ot Setting Tab in your apps, in Application type you must select the Read and Write or Read, Write and Access direct messages for your apps.

Step 5 : Download the twitter API from online

a. Go to http://www.jaisenmathai.com/articles/twitter-php-sign-in.html and click the link for available for download

b. UnZIP the downloaded package, place the library files into app/vendors/ folder create on folder twitter inside this folder create twitter.php file

c. In twitter.php we include the library files

include ‘EpiCurl.php’;

include ‘EpiOAuth.php’;

include ‘EpiTwitter.php’;

d. In app_controller top we include the following line, App::import(‘Vendor’, ‘twitter/twitter’);

e. Declare these variable as globally

var $consumer_key = ”;

var $consumer_secret = ”;

f. Create an Object for

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

$twitterObj->getAuthenticateUrl() get the login url if user not login than

check whether session $this -> Session -> read(“oauth_token”) exists or not if its not exists than

$twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret);

 

Object to connect the twitter API

$twitterObj->setToken($_GET[‘oauth_token’]);

 

twitter return a access token

$token = $twitterObj->getAccessToken();

 

$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);

set the Token into twitter object, the token is valid than we create a session for that token and secret

// save to cookies

if(isset($_GET[‘oauth_token’])){

$this -> Session -> write(“oauth_token”, $token->oauth_token);

$this -> Session -> write(“oauth_token_secret”, $token->oauth_token_secret);

}

 

$twitterInfo= $twitterObj->get_accountVerify_credentials();

 

Finally we get the twiter user A/C credentials

 

Check one more condition for session exists $this -> Session -> read(“oauth_token”). If its exists than, we create a Object for $twitterObj = new EpiTwitter($this->consumer_key, $this->consumer_secret, $this -> Session -> read(“oauth_token”), $this -> Session -> read(“oauth_token_secret”));

$twitterInfo= $twitterObj->get_accountVerify_credentials();

Now we get the user credentials.

Step 5 : To post content in your twitter A/C the following scripts used to post it

$msg = ‘The message which one you want for it’;

$update_status = $twitterObj->post_statusesUpdate(array(‘status’ => $msg));

 

$temp = $update_status->response;

// Update the status of the twitter object post the conetent and publish it

 

Step 6 : When user can logout we destroy the session.

Categories: CakePHP, PHP