From 6e569fe19f40fce9785099a24c986a21b412529f Mon Sep 17 00:00:00 2001
From: Evan Donovan <evan@evandonovan.org>
Date: Tue, 22 Mar 2011 09:18:39 -0400
Subject: [PATCH] Issue #[235939] by anniekin, EvanDonovan: 5.x compatibility with CiviCRM 2.0

---
 civicrm_activeuser.module |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/civicrm_activeuser.module b/civicrm_activeuser.module
index d29c814..1cf16f0 100644
--- a/civicrm_activeuser.module
+++ b/civicrm_activeuser.module
@@ -41,15 +41,15 @@ function civicrm_activeuser_menu($may_cache) {
  * Implementation of hook_settings().
  */
 function civicrm_activeuser_admin_settings() {
-  civicrm_initialize(true);
-  $options = array();
+  civicrm_initialize();
+  require_once 'api/v2/Group.php';
   $params = array();
-  $return_properties = array('id', 'title');
-  $groups = crm_get_groups($params, $return_properties);
+  $groups =& civicrm_groups_get($params);
 
+  $options = array();
   $options[0] = '-- Select One --';
   foreach ($groups as $group) {
-    $options[$group->id] = $group->title;
+    $options[$group[id]] = $group[title];
   }
   asort($options);
 
@@ -70,10 +70,14 @@ function civicrm_activeuser_user($op, $edit, &$user, $category = null) {
   if ($op == 'login') {
     $group_id = variable_get('civicrm_activeuser_group', 0);
     if ($group_id) { /* make sure that the group is set */
-      civicrm_initialize(true);
+      civicrm_initialize();
+      require_once 'api/v2/Contact.php';
+      require_once 'api/v2/Group.php';
+      require_once 'api/v2/GroupContact.php';
       global $user;
       $params = array('email' => $user->mail);
-      $contact =& crm_get_contact($params);
+      $contact =& civicrm_contact_get($params);
+      $contact_id = $contact[contact_id];
 
       /* NOTE: don't use document error checking:
        *
@@ -81,17 +85,18 @@ function civicrm_activeuser_user($op, $edit, &$user, $category = null) {
        * because is_a() is deprecated in php5
        *
        * http://wiki.civicrm.org/confluence/display/CRM/Group+APIs
-       * because crm_get_groups returns all groups when match not found???
+       * because civicrm_groups_get returns all groups when match not found?
        */
       /* NOTE: civicrm_activeuser is too long for watchdog() */
 
-      if ($contact && isset($contact->id)) {
+      if ($contact && isset($contact[contact_id])) {
         $params = array('id' => $group_id);
-        $groups =& crm_get_groups($params);
+        $groups =& civicrm_groups_get($params);
         if ($groups && count($groups) == 1) {
           $group = $groups[0];
           $contacts = array($contact);
-          if ($error = crm_add_group_contacts($group, $contacts)) {
+          $gparams = array('group_id' => $group_id, 'contact_id' => $contact_id);
+          if ($error = civicrm_group_contact_add($gparams)) {
             foreach ($error->_errors as $err) {
               $msgs[] = $err['code'] .': '. $err['message'];
             }
-- 
1.7.4

