It would be nice to have this module linked to the IP2CC module to display the flags of the countries selected automatically.
Another similar (but more limited module): Petition Node has that option. Please see the attached image.

CommentFileSizeAuthor
report.jpg212.39 KBvako

Comments

jimbullington’s picture

I've just added a PHP Code option in the 6.x-2.x-dev version. You may be able to use that do what you want.

vako’s picture

Probably I'm one of the users who don't know how to use the PHP code option. Can this module just borrow the code from the other module and incorporate it? No need to 're-invent the wheel', the code is already working in the Petition Node module.

jimbullington’s picture

Sorry, I just don't think this option has a place in a general purpose module like this one - which is why I added the PHP Code option.
If you can email me (jimb at jrbcs dot com) a screen shot of your report criteria, I can probably help you come up with the PHP code you need.

vako’s picture

Hi Jim, thanks for the quick response and offer for help. However I don't want you to invest too much time on it. I was hoping that it can become a feature of the module itself and not just a code for a single person like me...;)

What I want to do is put the flag of the country of each person who fills a form, provided they select their country from a pull-down list or better yet, according to their IP address the flag should automatically be generated. This is already done in the Petition Module that I indicated before and the capture of the IP address is done in the IP2CC module. you can see the report of the Petition module on the attached image to my initial post above.

I prefer to use Webform Report since it can serve many purposes and not just petitions.

jimbullington’s picture

I think this feature is just too specialized for the module. This is why I put in the PHP code option. I think over time we can develop some code examples that will help people use this option successfully.

Here is some example code that would address your requirement:

if (function_exists('ip2cc_get_country') && function_exists('theme_countryicons_icon')) {
  $headers[5] = 'Country Name';
  $headers[6] = 'Country Code';
  $headers[7] = 'Country Icon';
  foreach($rows as $i => $row) {
    $ip = $row[4]['data'];
    $c = ip2cc_get_country($ip);
    $rows[$i][5]['data'] = $c->country_name;
    $rows[$i][6]['data'] = $c->country_code2;
    $rows[$i][7]['data'] = theme_countryicons_icon($c->country_code2);
  }
}

In this example I have a report with 5 columns (indexes 0 through 4), the last column being the Submitters IP Address. I get the ip address from this column $row[4]['data'] and feed it into ip2cc_get_country, which returns the country. Then I'm feeding the code into theme_countryicons_icon(), which returns the icon(flag). I'm adding three columns to the report, Country Name, Country Code, and the icon (flag). The example could be reworked to add the flag icon to an existing column, etc.

Hope this helps.

jimbullington’s picture

I think this feature is just too specialized for the module. This is why I put in the PHP code option. I think over time we can develop some code examples that will help people use this option successfully.

Here is some example code that would address your requirement:

if (function_exists('ip2cc_get_country') && function_exists('theme_countryicons_icon')) {
  $headers[5] = 'Country Name';
  $headers[6] = 'Country Code';
  $headers[7] = 'Country Icon';
  foreach($rows as $i => $row) {
    $ip = $row[4]['data'];
    $c = ip2cc_get_country($ip);
    $rows[$i][5]['data'] = $c->country_name;
    $rows[$i][6]['data'] = $c->country_code2;
    $rows[$i][7]['data'] = theme_countryicons_icon($c->country_code2);
  }
}

In this example I have a report with 5 columns (indexes 0 through 4), the last column being the Submitters IP Address. I get the ip address from this column $row[4]['data'] and feed it into ip2cc_get_country, which returns the country. Then I'm feeding the code into theme_countryicons_icon(), which returns the icon(flag). I'm adding three columns to the report, Country Name, Country Code, and the icon (flag). The example could be reworked to add the flag icon to an existing column, etc.

Hope this helps.

jimbullington’s picture

I think this feature is just too specialized for the module. This is why I put in the PHP code option. I think over time we can develop some code examples that will help people use this option successfully.

Here is some example code that would address your requirement:

if (function_exists('ip2cc_get_country') && function_exists('theme_countryicons_icon')) {
  $headers[5] = 'Country Name';
  $headers[6] = 'Country Code';
  $headers[7] = 'Country Icon';
  foreach($rows as $i => $row) {
    $ip = $row[4]['data'];
    $c = ip2cc_get_country($ip);
    $rows[$i][5]['data'] = $c->country_name;
    $rows[$i][6]['data'] = $c->country_code2;
    $rows[$i][7]['data'] = theme_countryicons_icon($c->country_code2);
  }
}

In this example I have a report with 5 columns (indexes 0 through 4), the last column being the Submitters IP Address. I get the ip address from this column $row[4]['data'] and feed it into ip2cc_get_country, which returns the country. Then I'm feeding the code into theme_countryicons_icon(), which returns the icon(flag). I'm adding three columns to the report, Country Name, Country Code, and the icon (flag). The example could be reworked to add the flag icon to an existing column, etc.

Hope this helps.

jimbullington’s picture

Sorry about the repeated posts - my browser locked up...

vako’s picture

Thanks Jim, I added this code and made sure the IP2CC module is installed, what else needs to be done on Webform and Webform Report modules? i.e.: I already have the Country field but nothing showing up yet.

jimbullington’s picture

I had to enable Country API, IP to Country, and Country Icons. If you have a select for country, however, the code will have to be modified. As I said before, a screenshot of your Report Criteria would help.

vako’s picture

When I use this PHP code, the search option generates an error related to this code. please see the http://drupal.org/node/299414#comment-4050338

jimbullington’s picture

The PHP code needs to start with and end with .

vako’s picture

Thanks a lot Jim, your support is fantastic and I salute your knowledge with Drupal. We are lucky to have someone like you in this forum.
You are one of the best of the support groups here.

My issue is resolved and all your quick and efficient help is much appreciated.

jimbullington’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.