CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Membership validation
Pages: [1]

Author Topic: Membership validation  (Read 3033 times)

sjthespian

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 3
    • The League of Professional System Administrators
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.28
  • MySQL version: 5.1.66
  • PHP version: 5.3.3
Membership validation
July 27, 2011, 07:09:31 am
I have been running across various situations where we need to verify someone's membership but either don't want to give an individual full CiviCRM access to do it or need to do it from a script or remotely. It can be as simple as needing to verify membership status for someone trying to join our LinkedIn group, or validating membership for a partner discount.

Before I head off to write my own tools, has anyone written anything to do this? My initial though is to throw together a quick script that can run as a CGI and take firstname, lastname, and e-mail address as inputs, but I would like to get other's thoughts on this.

Thanks!
Dan Rich <drich@lopsa.org>
    Director, LOPSA - http://lopsa.org/

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Membership validation
July 27, 2011, 10:02:53 am
Yes, a script would be the right approach. See here:

http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+Public+APIs

for details about the CiviCRM APIs.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Membership validation
July 27, 2011, 11:27:16 am
If access control via Drupal Roles can be used to handle some / most / all of your requirements - then you should check out the civicrm member roles module that is included in the Civi codebase. It will set Drupal roles based on membership type and status.

BTW good idea to update your forum profile to indicate which CMS you are using (drupal vs joomla) and what versions of the CMS and Civi.
Protect your investment in CiviCRM by  becoming a Member!

sjthespian

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 3
    • The League of Professional System Administrators
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.28
  • MySQL version: 5.1.66
  • PHP version: 5.3.3
Re: Membership validation
July 27, 2011, 01:01:17 pm
Dave, I added the info to my profile, thank's for pointing that out! I didn't realize there was space for it there. Of course, I'm running two different sites with Civi, one on drupal and one on joomla so that just makes it even more fun! :)

We do use the drupal roles modules currently, and they work well for what they are meant for. The challenge is that I need to validate membership from outside organizations. For example, we work regularly with outside conferences to get our members discounts. They need a way that they can plug in a persons name and e-mail address and get back the type of membership and whether or not it is current.

I'm thinking along the lines of:
  http://mysite.org/validatemember.php?Dan&Foobar&[email]dfoobar@whereami.org[/email]
which might return:
  Dan Foobar <dfoobar@whereami.org> : Founding Member - Current

As Hershel suggested I will probably just build something using the existing APIs, I was just hoping someone had beat me to it already. I have already done a bit of custom coding that I need to write up one of these days (unfortunately most of it goes directly against the db, not via. the API), this one should at least be fairly straight forward.
« Last Edit: July 27, 2011, 03:32:05 pm by sjthespian »
Dan Rich <drich@lopsa.org>
    Director, LOPSA - http://lopsa.org/

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Membership validation
July 27, 2011, 04:51:01 pm
Yeah - you'll need to build something with the rest api. If you get something up, a quick blog post w/ code (on CiviCRM.org) would be great. Do use the new api explorer - should help a bit.

http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+Public+APIs

You'll need to think about permissions a bit in terms of what you're exposing "to the world".
Protect your investment in CiviCRM by  becoming a Member!

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Re: Membership validation via views?
July 29, 2011, 08:07:56 am
I am wondering if something would be possible using the civicrm CCK fields and Views  (OK warning I am new to setting up views :-)

I can create a view that gives a link to the user, their current status, membership type and end date.  So far it makes a page with all users.  How can I use  filters or arguments to  limit the view to the current logged in user?   

I would like to make a block that is displayed that would show the users membership status  when they first log in and  on our membership overview page, since we have three membership type signup pages.

(if this needs to be a new thread let me know)
Thanks!
Merlise
Merlise Clyde

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Membership validation
July 29, 2011, 06:57:14 pm
Merlise - one of of our clients has a Drupal block for logged in users that shows following
Quote
Membership
Member ID: 39611
You are an XXXXXX member until 16th January 2011.
Click here to renew.

Your yyyyyyy membership expired on 10th October 2010.
Click here to renew.

Or click here to re-join with a different membership type.

If that sounds useful I can check with them - not sure which bits of the code would need sorting for your site as we didn't do that coding.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Re: Membership validation
July 30, 2011, 06:44:54 am
Hi Pete

That would be perfect!  (hopefully it will work if there are multiple memberships/contact).  For historical reasons we have 1, 3, or lifetime memberships and with the addition of sections we do not have any way of forcing members to purchase 2 years of a section of their regular membership expires  in 2 years time.     So while they can navigate to their membership tab having a block on the main page when they log in or on the membership page would be really useful.   Course we are running out of space for blocks so we may need to get a new theme!

best,
Merlise
Merlise Clyde

chriscant

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 4
    • PHDCC
  • CiviCRM version: 4.2.19
Re: Membership validation
August 05, 2011, 03:00:01 am
I attach a version of the code I put together to show the membership messages that Pete mentioned.
The code goes in a Drupal block.
The code pretty long and cannot be used as is because it uses our specific membership types.
It also does some other status testing.
There are some comments.
The code searches through all the available memberships looking for the best one.
It then displays the best one.
The membership status types and the membership type ids are just hardcoded.
We have two main membership types which are handled slightly differently in the code.
For simpler scenarios you can probably pare the code down.

I'm out of the office from the end of play today for a week or so, but I will help if you need any thing more.

Chris

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Re: Membership validation
August 05, 2011, 06:40:34 am
Thanks!

I'll see about modifying it to our needs, but that is exactly the type of thing that we wanted!     
Merlise Clyde

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Membership validation
August 05, 2011, 02:50:57 pm
thanks for putting that out to the community chris
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

sjthespian

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 3
    • The League of Professional System Administrators
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.28
  • MySQL version: 5.1.66
  • PHP version: 5.3.3
Re: Membership validation
August 08, 2011, 11:09:51 am
Chris, thanks for the code!

I just spent a bit of time making it more generic, below is what I am going to be installing shortly in a block on lopsa.org. I also added calls to the API to get the membership type and status to remove the hard-coded values. I also took out the MemType1/2 and employer check code as I don't need that here.

If you are running multiple domains you may have to update the line "$params = array ('domain_id' => 1);" with your domain_id -- there doesn't appear to be a way to get civicrm_membership_types_get() to return a full list of all types, you have to pass it at least one parameter.

Code: [Select]
civicrm_initialize(TRUE);
require_once 'api/v2/UFGroup.php';
require_once 'api/v2/Contact.php';
require_once 'api/v2/Membership.php';
require_once 'CRM/Contact/BAO/Relationship.php';
echo "<style type='text/css'>";
echo ".lhn { line-height:normal; }";
echo "</style>";

global $user;
//echo '$user->uid:'.$user->uid.'<br>';
if ($user->uid) { // Don't do anything if no uid
  $scontactID = civicrm_uf_match_id_get ($user->uid);
  $contactID = intval($scontactID);
 
  if( $contactID==0) { // if 1
    echo '<p class="lhn">Hmmm you do not have a contact id: '.$scontactID.'<br />Please contact us for more information. uid:'.$user->uid."</p>";
  } else {
    // Get contact name and e-mail
    $params = array ('contact_id' => $contactID);
    $contact = civicrm_contact_get($params);
    $contactName = $contact[$contactID]['display_name'] ." &lt;". $contact[$contactID]['email'] ."&gt;";
    if (!$contactName) { // If no display name, use first/last name
      $contactName = $contact[$contactID]['first_name'] . " ". $contact[$contactID]['last_name'] ." &lt;". $contact[$contactID]['email'] ."&gt;";
    }
    if (!$contactName) { // If no name, use e-mail addr
      $contactName = $contact[$contactID]['email'];
    }
   
    // Get membership types
    $params = array ('domain_id' => 1);
    $result = civicrm_membership_types_get($params);
    $memTypeName = array();
    foreach ($result as $key => $type) {
      $memTypeName[$type['id']] = $type['name'];
    }
   
    // Get membership statuses
    $params = array ();
    $result = civicrm_membership_statuses_get($params);
    $memStatusName = array();
    foreach ($result as $key => $type) {
      $memStatusName[$type['id']] = $type['name'];
    }

    // Get membership info
    $result = civicrm_contact_memberships_get($contactID);
   
    if ( civicrm_error ( $result )) { // if 2
      echo'<p class="lhn">FAILED: '. $result['error_message'] . "</p>";
    } else {
      $RenewUrl = '/civicrm/user?&amp;reset=1';
     
      // Look through all returned memberships
      $MemsCount = $result['record_count'];
      $Memberships = array();
      if( $MemsCount>0) {
$cid = $result[$contactID];
foreach($cid as $key => $mem) {
  //echo "<hr>key=$key<pre>";
  //print_r($mem);
  //echo "</pre>";
  if (! $mem['is_test']) {
    $memStatus = $memStatusName[$mem['status_id']];
    $StatusIsCurrent = ((strcmp($memStatus,'New') == 0) ||
(strcmp($memStatus,'Current') == 0));
    $StatusIsExpired = ((strcmp($memStatus,'Grace') == 0) ||
(strcmp($memStatus,'Expired') == 0));
    $StatusIsPending = ((strcmp($memStatus,'Pending') == 0));
    $ThisEndDate = $mem['membership_end_date'];
    $ThisTypeId = $mem['membership_type_id'];
    $ThisMemId = $mem['membership_id'];
    $BestMembership =& $Memberships[$ThisTypeId];
    if( !isset($BestMembership)) {
      $BestMembership = array();
      $Memberships[$ThisTypeId] =& $BestMembership;
    }
    if( !$BestMembership['Current']) {
      if( !($StatusIsCurrent || $StatusIsExpired)) {
if( $StatusIsPending) {
  $BestMembership['AtLeastOnePending'] = true;
} else
  $BestMembership['SomeOtherStatus'] = $memStatus;
      } else {
if( $StatusIsCurrent) {
  $BestMembership['Current'] = true;
  $BestMembership['EndDate'] = $ThisEndDate;
  $BestMembership['MemId'] = $ThisMemId;
} else {
  if( !isset($BestMembership['EndDate'])) {
    $BestMembership['EndDate'] = $ThisEndDate;
    $BestMembership['MemId'] = $ThisMemId;
  } else if( $ThisEndDate > $BestMembership['EndDate']) {
    $BestMembership['EndDate'] = $ThisEndDate;
    $BestMembership['MemId'] = $ThisMemId;
  }
}
      }
    }
  }
} // end foreach
     
unset($BestMembership);
foreach($Memberships as $MembershipType => $BestMembership) {
  echo "<p class='lhn'>$contactName<br/>\nMember ID: $contactID<br/>";
 
  $MembershipEndDate = $BestMembership['EndDate'];
  if( !isset($MembershipEndDate)) {
    if( isset($BestMembership['AtLeastOnePending']))
      echo 'You have a Pending '.$memTypenme[$MembershipType].' membership - have you sent in your payment?';
    else if( isset($BestMembership['SomeOtherStatus']))
      echo 'You have '.$memTypeName[$MembershipType].' membership status '.$BestMembership['SomeOtherStatus'];
  } else {
    $MEDts = strtotime($MembershipEndDate);
    if( $MEDts)
      $MembershipEndDate = date("jS F Y",$MEDts);
    if( $RenewUrl) {
      $MemId = $BestMembership['MemId'];
      if( $MemId)
$RenewUrl = "/civicrm/contribute/transact&amp;id=$MembershipType&amp;mid=$MemId&amp;reset=1";
    }
    if( isset($BestMembership['Current'])) {
      echo $memTypeName[$MembershipType]." member until $MembershipEndDate.<br/>";
      if( $RenewUrl)
echo "<a href='$RenewUrl' title='Renew now'>Click here to renew</a>.";
    } else {
      echo 'Your '.$memTypeName[$MembershipType].' membership expired on '.$MembershipEndDate.'.<br/>';
      if( $RenewUrl) {
echo "<a href='$RenewUrl' title='Renew now'>Click here to renew</a>.";
      }
    }
  }
  echo "</p>";
} // foreach $Memberships
      } else {
echo '<p class="lhn">You are not a member. If you think you should be, please contact us.</p>';
      } // if count
    } // endif 2
  }  // endif 1
 }
?>
Dan Rich <drich@lopsa.org>
    Director, LOPSA - http://lopsa.org/

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Re: Membership validation
August 08, 2011, 11:10:57 am
Hi - this probably can be answered by any one with more Drupal experience.

1) I enabled the PhP fileter under Crupal Core optional 
2) configured the php filter to be available to admin
3) created a block and added the code in the body with input format set to PhP  input code

I have it set to diplay the block on a test page that is c=visible to admin only

When I go to the page I see th php code displayed rather than being executed.  I am wondering if this is a conflict to how the text is being input (I use whizzywhig and its input format is being shown)?
Is that the problem or do I need to add the PhP code in a different way to have this execute?

TIA!
Merlise
Merlise Clyde

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Re: Membership validation
August 08, 2011, 11:39:31 am
Whizzywhig was the problem!  disabled it for blocks and now the code does evaluate.

Looks like I need to tweak a few things for the most recent  code post  (just posting in case anyone else will use)

1) doesn't display membership status if there is more than one current membership  (need to look more closely at Best Membership)
2) the  renew url is going to arbitrary contribution pages  (we have 3 membership pages and several donation pages - soon to be 1  yeah!!! :-)

In any case  this is a great start! 

Thanks!
m
Merlise Clyde

mclyde

  • I post frequently
  • ***
  • Posts: 171
  • Karma: 3
    • International Society for Bayesian Analysis
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.x
  • MySQL version: 5.136
  • PHP version: 5.2.16
Re: Membership validation
August 08, 2011, 12:58:33 pm
The problem with the multiple memberhips not displaying was due to all three being lifememberships so there is no end-date.  Will try to fix!
m
Merlise Clyde

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Membership validation

This forum was archived on 2017-11-26.