--- civicrm_subscribe.module.php	2007-12-23 09:16:04.000000000 -0600
+++ civicrm_subscribe.module	2009-04-03 16:13:31.000000000 -0500
@@ -1,5 +1,6 @@
 <?php
 // $Id: civicrm_subscribe.module,v 1.2.2.4 2007/12/23 15:16:04 douggreen Exp $
+// Edited by EvanDonovan 2009/04/03
 /**
  * CiviCRM Subscribe Module
  */
@@ -31,16 +32,18 @@ function civicrm_subscribe_menu() {
 
 function civicrm_subscribe_admin_settings() {
   if (module_exists('civicrm')) {
-    civicrm_initialize(true);
+    civicrm_initialize();
+	require_once('api/v2/Group.php');
     $options = array();
     $params = array();
     $return_properties = array('id', 'title');
-    $groups = crm_get_groups($params, $return_properties);
+    $groups = civicrm_group_get($params);
 
-    $options[0] = '-- Select One --';
-    foreach ($groups as $group) {
-      $options[$group->id] = $group->title;
-    }
+    if (!$groups['is_error']) {
+      foreach ($groups as $group) {
+        $options[$group["id"]] = $group["title"];
+      }
+	}
     asort($options);
 
     $form['civicrm_subscribe_groups'] = array(
@@ -49,7 +52,7 @@ function civicrm_subscribe_admin_setting
       '#options' => $options,
       '#multiple' => 1,
       '#default_value' => variable_get('civicrm_subscribe_groups', 0),
-      '#description' => t("Select the CiviCRM group's users can subscribe to.")
+      '#description' => t("Select the CiviCRM groups users can subscribe to.")
     );
   }
   $form['civicrm_subscribe_drupal_account'] = array(
@@ -127,18 +130,21 @@ function civicrm_subscribe_form() {
   if (count($groups)) {
     $group_name = 'this group';
     if (module_exists('civicrm')) {
-      civicrm_initialize(true);
+      civicrm_initialize();
+	  require_once('api/v2/Group.php');
+	  
       $group_names = array();
       foreach ($groups as $group_id) {
-        $ccrm_groups =& crm_get_groups(array('id' => $group_id));
-        $group_names[] = _civicrm_subscribe_get_group_name($ccrm_groups[0]);
+        $params = array('id' => $group_id);
+        $ccrm_groups =& civicrm_group_get($params);
+        $group_names[] = _civicrm_subscribe_get_group_name(current($ccrm_groups));
       }
       $group_name = implode(', ', $group_names);
     }
     $help = t('Enter your email address to subscribe to %group_name.', array('%group_name' => $group_name));
 
     return array(
-      '#action' => url('user/subscribe', 'destination='. $_GET['q']),
+      '#action' => url('user/subscribe', array('query' => 'destination='. $_GET['q'])),
       '#submit' => array('civicrm_subscribe_form_submit' => array()),
       '#validate' => array('civicrm_subscribe_form_validate' => array()),
 
@@ -240,7 +246,7 @@ function civicrm_subscribe_form_validate
  * Subscribe the user to a CiviCRM group
  * This function is intended to be used by other modules, for example:
  *
- *   if (functions_exists('civicrm_subscribe')) {
+ *   if (function_exists('civicrm_subscribe')) {
  *     drupal_set_message(civicrm_subscribe($email));
  *   }
  *
@@ -261,48 +267,50 @@ function civicrm_subscribe_form_validate
  */
 function civicrm_subscribe($email, $params = array(), $groups = array()) {
   if (module_exists('civicrm')) {
-    civicrm_initialize(true);
-
-    // if groups specified, then get the default group(s)
+	civicrm_initialize();
+    require_once('api/v2/Group.php');
+	require_once('api/v2/Contact.php');
+	
+    // if no groups specified, then get the default group(s)
     if (count($groups) == 0) {
       $groups = _civicrm_subscribe_get_groups();
     }
 
     // get (or create) the contact
-    $contact =& crm_get_contact(array('email' => $email));
-    if ($contact && isset($contact->id)) {
+    $contact =& civicrm_contact_get(array('email' => $email));
+    if ($contact && isset($contact['id'])) {
       // update first and last name only if we don't already have a value
-      if (isset($contact->first_name) || !isset($params['first_name'])) {
+      if (isset($contact['first_name']) || !isset($params['first_name'])) {
         unset($params['first_name']);
       }
-      if (isset($contact->last_name) || !isset($params['last_name'])) {
+      if (isset($contact['last_name']) || !isset($params['last_name'])) {
         unset($params['last_name']);
       }
       if (count($params)) {
-        crm_update_contact($contact, $params);
+        civicrm_contact_add($contact, $params);
       }
     }
     else {
       $params['email'] = $email;
       $params['do_not_email'] = true;
-      $contact =& crm_create_contact($params);
+      $contact =& civicrm_contact_add($params);
     }
-    if ($contact && isset($contact->id)) {
+    if ($contact && isset($contact['id'])) {
       // if this is a new record
-      if ($contact->do_not_email) {
+      if ($contact['do_not_email']) {
         // NOTE: we can not search on the CCRM hash value, so it must be saved in our own table
-        _civicrm_subscribe_insert($contact->id, $contact->hash);
-        $contact =& crm_get_contact(array('id' => $contact->id));
+        _civicrm_subscribe_insert($contact['id'], $contact['hash']);
+        $contact =& civicrm_contact_get(array('id' => $contact['id']));
       }
 
       // loop through valid groups and add the user
       $group_names = array();
       foreach ($groups as $group_id) {
-        $ccrm_groups =& crm_get_groups(array('id' => $group_id));
+        $ccrm_groups =& civicrm_group_get(array('id' => $group_id));
         if ($ccrm_groups && count($ccrm_groups) == 1) {
-          $group = $ccrm_groups[0];
-          $contacts = array($contact);
-          if ($error = crm_add_group_contacts($group, $contacts)) {
+          // $group = $ccrm_groups[0];
+          // $contacts = array($contact);
+          if ($error = crm_group_contact_add(array('group_id' => $group_id, 'contact_id' => $contact['id']))) {
             $messages[] = _civicrm_subscribe_error($error);
           }
           else {
@@ -343,13 +351,15 @@ function _civicrm_subscribe_error($error
 function civicrm_subscribe_confirm_page() {
   if (module_exists('civicrm')) {
     if ($ccid = db_result(db_query("SELECT ccid FROM {civicrm_subscribe} WHERE hash='%s'", arg(2)))) {
-      civicrm_initialize(true);
-
-      $contact =& crm_get_contact(array('id' => $ccid));
+      civicrm_initialize();
+	  require_once('api/v2/Contact.php');
+	
+      $contact =& civicrm_contact_get(array('id' => $ccid));
 
-      if ($contact && isset($contact->id)) {
+      if ($contact && isset($contact['id'])) {
         // enable emailing now that this contact's email has been confirmed
-        $contact = crm_update_contact($contact, array('do_not_email' => 0));
+		$params = array('contact_id' => $contact['id'], 'contact_type' => $contact['contact_type'], 'do_not_email' => 0);
+        $contact = civicrm_contact_add($params);
         $confirmed = 1;
 
         // if we need to create a Drupal user, 
@@ -402,7 +412,7 @@ function _civicrm_subscribe_send_confirm
   // replace common values
   // @TODO: use token.module?
   $search = array('%confirm_link', '%group_name', '%email');
-  $confirm_link = url('user/confirm/'. $hash, NULL, NULL, TRUE);
+  $confirm_link = url('user/confirm/'. $hash, array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE));
   $replace = array($confirm_link, $group_name, $email);
   $body = str_replace($search, $replace, $body);
 
@@ -418,7 +428,7 @@ function _civicrm_subscribe_send_reconfi
   // replace common values
   // @TODO: use token.module?
   $search = array('%confirm_link', '%email');
-  $confirm_link = url('user/confirm/'. $hash, NULL, NULL, TRUE);
+  $confirm_link = url('user/confirm/'. $hash, array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE));
   $replace = array($confirm_link, $email);
   $body = str_replace($search, $replace, $body);
 
@@ -450,7 +460,7 @@ function _civicrm_subscribe_variable_get
 }
 
 function _civicrm_subscribe_variable_get_page_submitted($group_name = NULL) {
-  $submitted = variable_get('civicrm_subscribe_page_submitted', t('Thank You for subscribing to %group_name.  You will receive a confirmation email shortly.'));
+  $submitted = variable_get('civicrm_subscribe_page_submitted', t('Thank you for subscribing to %group_name.  You will receive a confirmation email shortly.'));
 
   if ($group_name) {
     $submitted = str_replace('%group_name', $group_name, $submitted);
@@ -460,11 +470,11 @@ function _civicrm_subscribe_variable_get
 }
 
 function _civicrm_subscribe_variable_get_page_reconfirm_submitted() {
-  return variable_get('civicrm_subscribe_page_reconfirm_submitted', t('Thank You for updating your email with us.  You will receive a confirmation email shortly.'));
+  return variable_get('civicrm_subscribe_page_reconfirm_submitted', t('Thank you for updating your email with us.  You will receive a confirmation email shortly.'));
 }
 
 function _civicrm_subscribe_get_group_name($group) {
-  return isset($group->title) ? $group->title : $groups->name;
+  return isset($group['title']) ? $group['title'] : $group['name'];
 }
 
 function _civicrm_subscribe_variable_get_page_confirmed() {
@@ -480,15 +490,19 @@ function civicrm_subscribe_user($type, &
   global $user;
   if (module_exists('civicrm') && $type == 'submit' && $category == 'account' && $edituser->mail != $edit['mail'] && $user->uid == $edituser->uid) {
     // find the existing civicrm contact record
-    civicrm_initialize(true);
-    $contact =& crm_get_contact(array('email' => $edituser->mail));
-    if (isset($contact->id)) {
+    civicrm_initialize();
+	require_once('api/v2/Contact.php');
+	
+    $contact =& civicrm_contact_get(array('email' => $edituser->mail));
+    if (isset($contact['id'])) {
       // change the civicrm email, and set the flag to do not email while we confirm the new email address
       $params = array(
+	  	'contact_id' => $contact['contact_id'],
+		'contact_type' => $contact['contact_type'],
         'email' => $edit['mail'],
         'do_not_email' => true,
       );
-      $contact =& crm_update_contact($contact, $params);
+      $contact =& civicrm_contact_add($params);
 
       // send the re-confirmation email
       _civicrm_subscribe_send_reconfirm_email($edit['mail'], $contact->hash);
