示例#1
0
 /**
  *  Test civicrm_activity_create() with valid parameters,
  *  using a text status_id
  */
 function testActivityCreateTextStatus()
 {
     //  Insert a row in civicrm_option_group creating
     //  an activity_status option group
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/option_group_activity_status.xml'));
     //  Insert rows in civicrm_option_value defining activity status
     //  values of 'Scheduled', 'Completed', 'Cancelled'
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/option_value_activity_status.xml'));
     $params = array('source_contact_id' => 17, 'subject' => 'Discussion on Apis for v2', 'activity_date_time' => date('Ymd'), 'duration' => 120, 'location' => 'Pensulvania', 'details' => 'a test activity', 'status_id' => 'Scheduled', 'activity_name' => 'Test activity type');
     $result =& civicrm_activity_create($params);
     $this->assertEquals($result['is_error'], 0, "Error message: " . $result['error_message']);
     $this->assertEquals($result['source_contact_id'], 17);
     $this->assertEquals($result['duration'], 120);
     $this->assertEquals($result['subject'], 'Discussion on Apis for v2');
     $this->assertEquals($result['activity_date_time'], date('Ymd'));
     $this->assertEquals($result['location'], 'Pensulvania');
     $this->assertEquals($result['details'], 'a test activity');
     $this->assertEquals($result['status_id'], 1);
 }
示例#2
0
 /** 
  * Function to send Acknowledgment and create activity.
  * 
  * @param object $form form object.
  * @param array  $params (reference ) an assoc array of name/value pairs.
  * @access public 
  * @return None.
  */
 function sendAcknowledgment(&$form, $params)
 {
     //handle Acknowledgment.
     $allPayments = $payments = array();
     //get All Payments status types.
     require_once 'CRM/Contribute/PseudoConstant.php';
     $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name');
     $returnProperties = array('status_id', 'scheduled_amount', 'scheduled_date', 'contribution_id');
     //get all paymnets details.
     CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_Payment', 'pledge_id', $params['id'], $allPayments, $returnProperties);
     if (!empty($allPayments)) {
         foreach ($allPayments as $payID => $values) {
             $contributionValue = $contributionStatus = array();
             if (isset($values['contribution_id'])) {
                 $contributionParams = array('id' => $values['contribution_id']);
                 $returnProperties = array('contribution_status_id', 'receive_date');
                 CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_Contribution', $contributionParams, $contributionStatus, $returnProperties);
                 $contributionValue = array('status' => CRM_Utils_Array::value('contribution_status_id', $contributionStatus), 'receive_date' => CRM_Utils_Array::value('receive_date', $contributionStatus));
             }
             $payments[$payID] = array_merge($contributionValue, array('amount' => CRM_Utils_Array::value('scheduled_amount', $values), 'due_date' => CRM_Utils_Array::value('scheduled_date', $values)));
             //get the first valid payment id.
             if (!$form->paymentId && ($paymentStatusTypes[$values['status_id']] == 'Pending' || $paymentStatusTypes[$values['status_id']] == 'Overdue')) {
                 $form->paymentId = $values['id'];
             }
         }
     }
     //end
     //assign pledge fields value to template.
     $pledgeFields = array('create_date', 'total_pledge_amount', 'frequency_interval', 'frequency_unit', 'installments', 'frequency_day', 'scheduled_amount');
     foreach ($pledgeFields as $field) {
         if (CRM_Utils_Array::value($field, $params)) {
             $form->assign($field, $params[$field]);
         }
     }
     //assign all payments details.
     if ($payments) {
         $form->assign('payments', $payments);
     }
     //assign honor fields.
     $honor_block_is_active = false;
     //make sure we have values for it
     if (CRM_Utils_Array::value('honor_type_id', $params) && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) {
         $honor_block_is_active = true;
         require_once "CRM/Core/PseudoConstant.php";
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $form->assign("honor_type", $honor[$params["honor_type_id"]]);
         $form->assign("honor_prefix", $prefix[$params["honor_prefix_id"]]);
         $form->assign("honor_first_name", $params["honor_first_name"]);
         $form->assign("honor_last_name", $params["honor_last_name"]);
         $form->assign("honor_email", $params["honor_email"]);
     }
     $form->assign('honor_block_is_active', $honor_block_is_active);
     //handle domain token values
     require_once 'CRM/Core/BAO/Domain.php';
     $domain =& CRM_Core_BAO_Domain::getDomain();
     $tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
     require_once 'CRM/Utils/Token.php';
     $domainValues = array();
     foreach ($tokens['domain'] as $token) {
         $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
     }
     $form->assign('domain', $domainValues);
     //handle contact token values.
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $ids = array($params['contact_id']);
     $fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()), array('display_name', 'checksum', 'contact_id'));
     foreach ($fields as $key => $val) {
         $returnProperties[$val] = true;
     }
     $details = CRM_Mailing_BAO_Mailing::getDetails($ids, $returnProperties);
     $form->assign('contact', $details[0][$params['contact_id']]);
     //handle custom data.
     if (CRM_Utils_Array::value('hidden_custom', $params)) {
         require_once 'CRM/Core/BAO/CustomGroup.php';
         $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']);
         $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0));
         $customGroup = array();
         // retrieve custom data
         require_once "CRM/Core/BAO/UFGroup.php";
         foreach ($groupTree as $groupID => $group) {
             $customFields = $customValues = array();
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
             //to build array of customgroup & customfields in it
             CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, false, $pledgeParams);
             $customGroup[$group['title']] = $customValues;
         }
         $form->assign('customGroup', $customGroup);
     }
     //handle acknowledgment email stuff.
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     list($pledgerDisplayName, $pledgerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
     //check for online pledge.
     $session = CRM_Core_Session::singleton();
     if (CRM_Utils_Array::value('receipt_from_email', $params)) {
         $userName = CRM_Utils_Array::value('receipt_from_name', $params);
         $userEmail = CRM_Utils_Array::value('receipt_from_email', $params);
     } else {
         if ($userID = $session->get('userID')) {
             //check for loged in user.
             list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
         } else {
             //set the domain values.
             $userName = CRM_Utils_Array::value('name', $domainValues);
             $userEmail = CRM_Utils_Array::value('email', $domainValues);
         }
     }
     $receiptFrom = "{$userName} <{$userEmail}>";
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_pledge', 'valueName' => 'pledge_acknowledge', 'contactId' => $params['contact_id'], 'from' => $receiptFrom, 'toName' => $pledgerDisplayName, 'toEmail' => $pledgerEmail));
     //check if activity record exist for this pledge
     //Acknowledgment, if exist do not add activity.
     require_once "CRM/Activity/DAO/Activity.php";
     $activityType = 'Pledge Acknowledgment';
     $activity = new CRM_Activity_DAO_Activity();
     $activity->source_record_id = $params['id'];
     $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name');
     $config = CRM_Core_Config::singleton();
     $money = $config->defaultCurrencySymbol;
     $details = 'Total Amount ' . $money . $params['total_pledge_amount'] . ' To be paid in ' . $params['installments'] . ' installments of ' . $money . $params['scheduled_amount'] . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)';
     if (!$activity->find()) {
         $activityParams = array('subject' => $subject, 'source_contact_id' => $params['contact_id'], 'source_record_id' => $params['id'], 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($params['acknowledge_date']), 'is_test' => $params['is_test'], 'status_id' => 2, 'details' => $details);
         require_once 'api/v2/Activity.php';
         if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) {
             CRM_Core_Error::fatal("Failed creating Activity for acknowledgment");
         }
     }
 }
示例#3
0
 /**
  * Function to send mail and create activity 
  * when participant status changed.
  *      
  * @param  int     $participantId      participant id.
  * @param  array   $participantValues  participant detail values. status id for participants 
  * @param  array   $eventDetails       required event details
  * @param  array   $contactDetails     required contact details
  * @param  array   $domainValues       required domain values.
  * @param  string  $mailType           (eg 'approval', 'confirm', 'expired' ) 
  *
  * return  void
  * @access public
  * @static
  */
 function sendTransitionParticipantMail($participantId, $participantValues, $eventDetails, $contactDetails, &$domainValues, $mailType)
 {
     //send emails.
     $mailSent = false;
     //don't send confirmation mail to additional
     //since only primary able to confirm registration.
     if (CRM_Utils_Array::value('registered_by_id', $participantValues) && $mailType == 'Confirm') {
         return $mailSent;
     }
     if ($toEmail = CRM_Utils_Array::value('email', $contactDetails)) {
         $contactId = $participantValues['contact_id'];
         $participantName = $contactDetails['display_name'];
         //calculate the checksum value.
         $checksumValue = null;
         if ($mailType == 'Confirm' && !$participantValues['registered_by_id']) {
             require_once 'CRM/Utils/Date.php';
             require_once 'CRM/Contact/BAO/Contact/Utils.php';
             $checksumLife = 'inf';
             if ($endDate = CRM_Utils_Array::value('end_date', $eventDetails)) {
                 $checksumLife = (CRM_Utils_Date::unixTime($endDate) - time()) / (60 * 60);
             }
             $checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactId, null, $checksumLife);
         }
         //take a receipt from as event else domain.
         $receiptFrom = $domainValues['name'] . ' <' . $domainValues['email'] . '>';
         if (CRM_Utils_Array::value('confirm_from_name', $eventDetails) && CRM_Utils_Array::value('confirm_from_email', $eventDetails)) {
             $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>';
         }
         require_once 'CRM/Core/BAO/MessageTemplates.php';
         list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'participant_' . strtolower($mailType), 'contactId' => $contactId, 'tplParams' => array('contact' => $contactDetails, 'domain' => $domainValues, 'participant' => $participantValues, 'event' => $eventDetails, 'paidEvent' => CRM_Utils_Array::value('is_monetary', $eventDetails), 'isShowLocation' => CRM_Utils_Array::value('is_show_location', $eventDetails), 'isAdditional' => $participantValues['registered_by_id'], 'isExpired' => $mailType == 'Expired', 'isConfirm' => $mailType == 'Confirm', 'checksumValue' => $checksumValue), 'from' => $receiptFrom, 'toName' => $participantName, 'toEmail' => $toEmail, 'cc' => CRM_Utils_Array::value('cc_confirm', $eventDetails), 'bcc' => CRM_Utils_Array::value('bcc_confirm', $eventDetails)));
         // 3. create activity record.
         if ($mailSent) {
             $now = date('YmdHis');
             $activityType = 'Event Registration';
             $activityParams = array('subject' => $subject, 'source_contact_id' => $contactId, 'source_record_id' => $participantId, 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($now), 'due_date_time' => CRM_Utils_Date::isoToMysql($participantValues['register_date']), 'is_test' => $participantValues['is_test'], 'status_id' => 2);
             require_once 'api/v2/Activity.php';
             if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) {
                 CRM_Core_Error::fatal("Failed creating Activity for expiration mail");
             }
         }
     }
     return $mailSent;
 }
示例#4
0
/**
 * Update an existing contact membership
 *
 * This api is used for updating an existing contact membership.
 * Required parrmeters : id of a membership
 * 
 * @param  Array   $params  an associative array of name/value property values of civicrm_membership
 * 
 * @return array of updated membership property values
 * @access public
 */
function crm_update_contact_membership($params)
{
    _crm_initialize();
    if (!is_array($params)) {
        return _crm_error('Params is not an array');
    }
    if (!isset($params['id'])) {
        return _crm_error('Required parameter missing');
    }
    $changeFields = array('membership_start_date' => 'start_date', 'membership_end_date' => 'end_date', 'membership_source' => 'source');
    foreach ($changeFields as $field => $requiredField) {
        if (array_key_exists($field, $params)) {
            $params[$requiredField] = $params[$field];
            unset($params[$field]);
        }
    }
    require_once 'CRM/Member/BAO/Membership.php';
    $membershipBAO =& new CRM_Member_BAO_Membership();
    $membershipBAO->id = $params['id'];
    $membershipBAO->find(true);
    $oldStatusID = $membershipBAO->status_id;
    $membershipBAO->copyValues($params);
    $datefields = array('start_date', 'end_date', 'join_date', 'reminder_date');
    //fix the dates
    foreach ($datefields as $value) {
        $membershipBAO->{$value} = CRM_Utils_Date::customFormat($membershipBAO->{$value}, '%Y%m%d');
        // Handle resetting date to 'null' (which is converted to 00000 by customFormat)
        if ($membershipBAO->{$value} == '00000') {
            $membershipBAO->{$value} = 'null';
        }
        $params[$value] = $membershipBAO->{$value};
    }
    $membershipBAO->save();
    require_once "CRM/Core/Action.php";
    // Check and add membership for related contacts
    $relatedContacts = CRM_Member_BAO_Membership::checkMembershipRelationship($membershipBAO->id, (int) $membershipBAO->contact_id, CRM_Core_Action::UPDATE);
    //delete all the related membership records before creating
    CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipBAO->id);
    $params['membership_type_id'] = $membershipBAO->membership_type_id;
    foreach ($relatedContacts as $contactId => $relationshipStatus) {
        if ($relationshipStatus & CRM_Contact_BAO_Relationship::CURRENT) {
            $params['contact_id'] = $contactId;
            $params['owner_membership_id'] = $membershipBAO->id;
            unset($params['id']);
            CRM_Member_BAO_Membership::create($params, CRM_Core_DAO::$_nullArray);
        }
    }
    // Create activity history record.
    require_once "CRM/Member/PseudoConstant.php";
    $membershipType = CRM_Member_PseudoConstant::membershipType($membershipBAO->membership_type_id);
    if (!$membershipType) {
        $membershipType = ts('Membership');
    }
    $activitySummary = $membershipType;
    if ($membershipBAO->source != 'null') {
        $activitySummary .= " - {$membershipBAO->source}";
    }
    if ($membershipBAO->owner_membership_id) {
        $cid = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $membershipBAO->owner_membership_id, 'contact_id');
        $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name');
        $activitySummary .= " (by {$displayName})";
    }
    // create activity record only if there is change in the statusID (CRM-2521).
    if ($oldStatusID != $membershipBAO->status_id) {
        $activityParams = array('source_contact_id' => $membershipBAO->contact_id, 'source_record_id' => $membershipBAO->id, 'activity_type_id' => array_search('Membership Signup', CRM_Core_PseudoConstant::activityType()), 'subject' => $activitySummary, 'activity_date_time' => $params['join_date'], 'is_test' => $membershipBAO->is_test, 'status_id' => 2);
        require_once 'api/v2/Activity.php';
        if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) {
            return false;
        }
    }
    $membership = array();
    _crm_object_to_array($membershipBAO, $membership);
    $membershipBAO->free();
    return $membership;
}
示例#5
0
/**
 * Convert an email file to an activity
 */
function civicrm_activity_processemail($file, $activityTypeID, $result = array())
{
    // do not parse if result array already passed (towards EmailProcessor..)
    if (empty($result)) {
        // might want to check that email is ok here
        if (!file_exists($file) || !is_readable($file)) {
            return CRM_Core_Error::createAPIError(ts('File %1 does not exist or is not readable', array(1 => $file)));
        }
    }
    require_once 'CRM/Utils/Mail/Incoming.php';
    $result = CRM_Utils_Mail_Incoming::parse($file);
    if ($result['is_error']) {
        return $result;
    }
    $params = _civicrm_activity_buildmailparams($result, $activityTypeID);
    return civicrm_activity_create($params);
}
示例#6
0
 /**
  * handle the values in import mode
  *
  * @param int $onDuplicate the code for what action to take on duplicates
  * @param array $values the array of values belonging to this line
  *
  * @return boolean      the result of this processing
  * @access public
  */
 function import($onDuplicate, &$values)
 {
     // first make sure this is a valid line
     $response = $this->summary($values);
     if ($response != CRM_Activity_Import_Parser::VALID) {
         return $response;
     }
     $params =& $this->getActiveFieldParams();
     $activityName = array_search('activity_name', $this->_mapperKeys);
     if ($activityName) {
         $params = array_merge($params, array('activity_name' => $values[$activityName]));
     }
     //for date-Formats
     $session =& CRM_Core_Session::singleton();
     $dateType = $session->get("dateTypes");
     $params['source_contact_id'] = $session->get('userID');
     $formatted = array();
     $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $params));
     foreach ($params as $key => $val) {
         if ($key == 'activity_date_time') {
             if ($val) {
                 if ($dateType == 1) {
                     $params[$key] = CRM_Utils_Date::customFormat($val, '%Y%m%d%H%i');
                     //hack to add seconds
                     $params[$key] = $params[$key] . '00';
                 } else {
                     CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
                 }
             }
         } elseif ($key == 'duration') {
             $params['duration_minutes'] = $params['duration'];
             unset($params['duration']);
         }
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
             if ($customFields[$customFieldID]['data_type'] == 'Date') {
                 CRM_Import_Parser_Contact::formatCustomDate($params, $params, $dateType, $key);
             } else {
                 if ($customFields[$customFieldID]['data_type'] == 'Boolean') {
                     $params[$key] = CRM_Utils_String::strtoboolstr($val);
                 }
             }
         }
     }
     //date-Format part ends
     $formatError = _civicrm_activity_formatted_param($params, $params, true);
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, CRM_Core_DAO::$_nullObject, null, 'Activity');
     if ($this->_contactIdIndex < 0) {
         //retrieve contact id using contact dedupe rule.
         //since we are support only individual's activity import.
         $params['contact_type'] = 'Individual';
         $error = civicrm_check_contact_dedupe($params);
         if (civicrm_duplicate($error)) {
             $matchedIDs = explode(',', $error['error_message']['params'][0]);
             if (count($matchedIDs) > 1) {
                 array_unshift($values, "Multiple matching contact records detected for this row. The activity was not imported");
                 return CRM_Activity_Import_Parser::ERROR;
             } else {
                 $cid = $matchedIDs[0];
                 $params['target_contact_id'] = $cid;
                 $newActivity = civicrm_activity_create($params);
                 if (CRM_Utils_Array::value('is_error', $newActivity)) {
                     array_unshift($values, $newActivity['error_message']);
                     return CRM_Activity_Import_Parser::ERROR;
                 }
                 $this->_newActivity[] = $newActivity['id'];
                 return CRM_Activity_Import_Parser::VALID;
             }
         } else {
             // Using new Dedupe rule.
             $ruleParams = array('contact_type' => 'Individual', 'level' => 'Strict');
             require_once 'CRM/Dedupe/BAO/Rule.php';
             $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
             foreach ($fieldsArray as $value) {
                 if (array_key_exists(trim($value), $params)) {
                     $paramValue = $params[trim($value)];
                     if (is_array($paramValue)) {
                         $disp .= $params[trim($value)][0][trim($value)] . " ";
                     } else {
                         $disp .= $params[trim($value)] . " ";
                     }
                 }
             }
             if (CRM_Utils_Array::value('external_identifier', $params)) {
                 if ($disp) {
                     $disp .= "AND {$params['external_identifier']}";
                 } else {
                     $disp = $params['external_identifier'];
                 }
             }
             array_unshift($values, "No matching Contact found for (" . $disp . ")");
             return CRM_Activity_Import_Parser::ERROR;
         }
     } else {
         if (CRM_Utils_Array::value('external_identifier', $params)) {
             $targetContactId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['external_identifier'], 'id', 'external_identifier');
             if (CRM_Utils_Array::value('target_contact_id', $params) && $params['target_contact_id'] != $targetContactId) {
                 array_unshift($values, "Mismatch of External identifier :" . $params['external_identifier'] . " and Contact Id:" . $params['target_contact_id']);
                 return CRM_Activity_Import_Parser::ERROR;
             } else {
                 if ($targetContactId) {
                     $params['target_contact_id'] = $targetContactId;
                 } else {
                     array_unshift($values, "No Matching Contact for External identifier :" . $params['external_identifier']);
                     return CRM_Activity_Import_Parser::ERROR;
                 }
             }
         }
         $newActivity = civicrm_activity_create($params);
         if (CRM_Utils_Array::value('is_error', $newActivity)) {
             array_unshift($values, $newActivity['error_message']);
             return CRM_Activity_Import_Parser::ERROR;
         }
         $this->_newActivity[] = $newActivity['id'];
         return CRM_Activity_Import_Parser::VALID;
     }
 }
示例#7
0
文件: Job.php 项目: bhirsch/voipdev
 public function deliverGroup(&$fields, &$mailing, &$mailer, &$job_date, &$attachments)
 {
     // get the return properties
     $returnProperties = $mailing->getReturnProperties();
     $params = array();
     $targetParams = array();
     foreach ($fields as $key => $field) {
         $params[] = $field['contact_id'];
     }
     $details = $mailing->getDetails($params, $returnProperties);
     foreach ($fields as $key => $field) {
         $contactID = $field['contact_id'];
         /* Compose the mailing */
         $recipient = null;
         $message =& $mailing->compose($this->id, $field['id'], $field['hash'], $field['contact_id'], $field['email'], $recipient, false, $details[0][$contactID], $attachments);
         /* Send the mailing */
         $body =& $message->get();
         $headers =& $message->headers();
         // make $recipient actually be the *encoded* header, so as not to baffle Mail_RFC822, CRM-5743
         $recipient = $headers['To'];
         $result = null;
         /* TODO: when we separate the content generator from the delivery
          * engine, maybe we should dump the messages into a table */
         // disable error reporting on real mailings (but leave error reporting for tests), CRM-5744
         if ($job_date) {
             CRM_Core_Error::ignoreException();
         }
         if (is_object($mailer)) {
             // hack to stop mailing job at run time, CRM-4246.
             $mailingJob = new CRM_Mailing_DAO_Job();
             $mailingJob->mailing_id = $mailing->id;
             if ($mailingJob->find(true)) {
                 // mailing have been canceled at run time.
                 if ($mailingJob->status == 'Canceled') {
                     return false;
                 }
             } else {
                 // mailing have been deleted at run time.
                 return false;
             }
             $mailingJob->free();
             $result = $mailer->send($recipient, $headers, $body, $this->id);
             CRM_Core_Error::setCallback();
         }
         $params = array('event_queue_id' => $field['id'], 'job_id' => $this->id, 'hash' => $field['hash']);
         if (is_a($result, 'PEAR_Error')) {
             /* Register the bounce event */
             require_once 'CRM/Mailing/BAO/BouncePattern.php';
             require_once 'CRM/Mailing/Event/BAO/Bounce.php';
             $params = array_merge($params, CRM_Mailing_BAO_BouncePattern::match($result->getMessage()));
             CRM_Mailing_Event_BAO_Bounce::create($params);
         } else {
             /* Register the delivery event */
             CRM_Mailing_Event_BAO_Delivered::create($params);
         }
         $targetParams[] = $field['contact_id'];
         unset($result);
     }
     if (!empty($targetParams)) {
         // add activity record for every mail that is send
         $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name');
         $activity = array('source_contact_id' => $mailing->scheduled_id, 'target_contact_id' => $targetParams, 'activity_type_id' => $activityTypeID, 'source_record_id' => $this->mailing_id, 'activity_date_time' => $job_date, 'subject' => $mailing->subject, 'status_id' => 2, 'deleteActivityTarget' => false);
         //check whether activity is already created for this mailing.
         //if yes then create only target contact record.
         $query = "\nSELECT id \nFROM   civicrm_activity\nWHERE  civicrm_activity.activity_type_id = %1\nAND    civicrm_activity.source_record_id = %2";
         $queryParams = array(1 => array($activityTypeID, 'Integer'), 2 => array($this->mailing_id, 'Integer'));
         $activityID = CRM_Core_DAO::singleValueQuery($query, $queryParams);
         if ($activityID) {
             $activity['id'] = $activityID;
         }
         require_once 'api/v2/Activity.php';
         if (is_a(civicrm_activity_create($activity, 'Email'), 'CRM_Core_Error')) {
             return false;
         }
     }
     return true;
 }
示例#8
0
 /**
  * Function to add activity for Membership/Event/Contribution
  *
  * @param object  $activity   (reference) perticular component object
  * @param string  $activityType for Membership Signup or Renewal
  *
  *  
  * @static
  * @access public
  */
 static function addActivity(&$activity, $activityType = 'Membership Signup', $targetContactID = null)
 {
     if ($activity->__table == 'civicrm_membership') {
         require_once "CRM/Member/PseudoConstant.php";
         $membershipType = CRM_Member_PseudoConstant::membershipType($activity->membership_type_id);
         if (!$membershipType) {
             $membershipType = ts('Membership');
         }
         $subject = "{$membershipType}";
         if ($activity->source != 'null') {
             $subject .= " - {$activity->source}";
         }
         if ($activity->owner_membership_id) {
             $query = "\nSELECT  display_name \n  FROM  civicrm_contact, civicrm_membership  \n WHERE  civicrm_contact.id    = civicrm_membership.contact_id\n   AND  civicrm_membership.id = {$activity->owner_membership_id}\n";
             $displayName = CRM_Core_DAO::singleValueQuery($query);
             $subject .= " (by {$displayName})";
         }
         require_once 'CRM/Member/DAO/MembershipStatus.php';
         $subject .= " - Status: " . CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $activity->status_id);
         $date = $activity->start_date;
         $component = 'Membership';
     } else {
         if ($activity->__table == 'civicrm_participant') {
             require_once "CRM/Event/BAO/Event.php";
             $event = CRM_Event_BAO_Event::getEvents(true, $activity->event_id);
             require_once "CRM/Event/PseudoConstant.php";
             $roles = CRM_Event_PseudoConstant::participantRole();
             $status = CRM_Event_PseudoConstant::participantStatus();
             $subject = $event[$activity->event_id];
             if (CRM_Utils_Array::value($activity->role_id, $roles)) {
                 $subject .= ' - ' . $roles[$activity->role_id];
             }
             if (CRM_Utils_Array::value($activity->status_id, $status)) {
                 $subject .= ' - ' . $status[$activity->status_id];
             }
             $date = date('YmdHis');
             $activityType = 'Event Registration';
             $component = 'Event';
         } else {
             if ($activity->__table == 'civicrm_contribution') {
                 //create activity record only for Completed Contributions
                 if ($activity->contribution_status_id != 1) {
                     return;
                 }
                 $subject = null;
                 require_once "CRM/Utils/Money.php";
                 $subject .= CRM_Utils_Money::format($activity->total_amount, $activity->currency);
                 if ($activity->source != 'null') {
                     $subject .= " - {$activity->source}";
                 }
                 $date = CRM_Utils_Date::isoToMysql($activity->receive_date);
                 $activityType = $component = 'Contribution';
             }
         }
     }
     require_once "CRM/Core/OptionGroup.php";
     $activityParams = array('source_contact_id' => $activity->contact_id, 'source_record_id' => $activity->id, 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'subject' => $subject, 'activity_date_time' => $date, 'is_test' => $activity->is_test, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'), 'skipRecentView' => true);
     //CRM-4027
     if ($targetContactID) {
         $activityParams['target_contact_id'] = $targetContactID;
     }
     require_once 'api/v2/Activity.php';
     if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) {
         CRM_Core_Error::fatal("Failed creating Activity for {$component} of id {$activity->id}");
         return false;
     }
 }
 static function _process($civiMail, $dao)
 {
     // 0 = activities; 1 = bounce;
     $usedfor = $dao->is_default;
     require_once 'CRM/Core/OptionGroup.php';
     $emailActivityTypeId = defined('EMAIL_ACTIVITY_TYPE_ID') && EMAIL_ACTIVITY_TYPE_ID ? EMAIL_ACTIVITY_TYPE_ID : CRM_Core_OptionGroup::getValue('activity_type', 'Inbound Email', 'name');
     if (!$emailActivityTypeId) {
         CRM_Core_Error::fatal(ts('Could not find a valid Activity Type ID for Inbound Email'));
     }
     // FIXME: legacy regexen to handle CiviCRM 2.1 address patterns, with domain id and possible VERP part
     $commonRegex = '/^' . preg_quote($dao->localpart) . '(b|bounce|c|confirm|o|optOut|r|reply|re|e|resubscribe|u|unsubscribe)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\.([0-9a-f]{16})(-.*)?@' . preg_quote($dao->domain) . '$/';
     $subscrRegex = '/^' . preg_quote($dao->localpart) . '(s|subscribe)\\.(\\d+)\\.(\\d+)@' . preg_quote($dao->domain) . '$/';
     // a common-for-all-actions regex to handle CiviCRM 2.2 address patterns
     $regex = '/^' . preg_quote($dao->localpart) . '(b|c|e|o|r|u)\\.(\\d+)\\.(\\d+)\\.([0-9a-f]{16})@' . preg_quote($dao->domain) . '$/';
     // retrieve the emails
     require_once 'CRM/Mailing/MailStore.php';
     $store = CRM_Mailing_MailStore::getStore($dao->name);
     require_once 'api/v2/Mailer.php';
     // process fifty at a time, CRM-4002
     while ($mails = $store->fetchNext(MAIL_BATCH_SIZE)) {
         foreach ($mails as $key => $mail) {
             // for every addressee: match address elements if it's to CiviMail
             $matches = array();
             if ($usedfor == 1) {
                 foreach ($mail->to as $address) {
                     if (preg_match($regex, $address->email, $matches)) {
                         list($match, $action, $job, $queue, $hash) = $matches;
                         break;
                         // FIXME: the below elseifs should be dropped when we drop legacy support
                     } elseif (preg_match($commonRegex, $address->email, $matches)) {
                         list($match, $action, $_, $job, $queue, $hash) = $matches;
                         break;
                     } elseif (preg_match($subscrRegex, $address->email, $matches)) {
                         list($match, $action, $_, $job) = $matches;
                         break;
                     }
                 }
             }
             // preseve backward compatibility
             if ($usedfor == 0 || !$civiMail) {
                 // if its the activities that needs to be processed ..
                 require_once 'CRM/Utils/Mail/Incoming.php';
                 $mailParams = CRM_Utils_Mail_Incoming::parseMailingObject($mail, $dao->name);
                 require_once 'api/v2/Activity.php';
                 $params = _civicrm_activity_buildmailparams($mailParams, $emailActivityTypeId);
                 $result = civicrm_activity_create($params);
                 if ($result['is_error']) {
                     $matches = false;
                     echo "Failed Processing: {$mail->subject}. Reason: {$result['error_message']}\n";
                 } else {
                     $matches = true;
                     echo "Processed as Activity: {$mail->subject}\n";
                 }
             }
             // if $matches is empty, this email is not CiviMail-bound
             if (!$matches) {
                 $store->markIgnored($key);
                 continue;
             }
             // get $replyTo from either the Reply-To header or from From
             // FIXME: make sure it works with Reply-Tos containing non-email stuff
             $replyTo = $mail->getHeader('Reply-To') ? $mail->getHeader('Reply-To') : $mail->from->email;
             // handle the action by passing it to the proper API call
             // FIXME: leave only one-letter cases when dropping legacy support
             if (!empty($action)) {
                 switch ($action) {
                     case 'b':
                     case 'bounce':
                         $text = '';
                         if ($mail->body instanceof ezcMailText) {
                             $text = $mail->body->text;
                         } elseif ($mail->body instanceof ezcMailMultipart) {
                             foreach ($mail->body->getParts() as $part) {
                                 if (isset($part->subType) and $part->subType == 'plain') {
                                     $text = $part->text;
                                     break;
                                 }
                             }
                         }
                         $params = array('job_id' => $job, 'event_queue_id' => $queue, 'hash' => $hash, 'body' => $text);
                         civicrm_mailer_event_bounce($params);
                         break;
                     case 'c':
                     case 'confirm':
                         $params = array('job_id' => $job, 'event_queue_id' => $queue, 'hash' => $hash);
                         civicrm_mailer_event_confirm($params);
                         break;
                     case 'o':
                     case 'optOut':
                         $params = array('job_id' => $job, 'event_queue_id' => $queue, 'hash' => $hash);
                         civicrm_mailer_event_domain_unsubscribe($params);
                         break;
                     case 'r':
                     case 'reply':
                         // instead of text and HTML parts (4th and 6th params) send the whole email as the last param
                         $params = array('job_id' => $job, 'event_queue_id' => $queue, 'hash' => $hash, 'bodyTxt' => null, 'replyTo' => $replyTo, 'bodyHTML' => null, 'fullEmail' => $mail->generate());
                         civicrm_mailer_event_reply($params);
                         break;
                     case 'e':
                     case 're':
                     case 'resubscribe':
                         $params = array('job_id' => $job, 'event_queue_id' => $queue, 'hash' => $hash);
                         civicrm_mailer_event_resubscribe($params);
                         break;
                     case 's':
                     case 'subscribe':
                         $params = array('email' => $mail->from->email, 'group_id' => $job);
                         civicrm_mailer_event_subscribe($params);
                         break;
                     case 'u':
                     case 'unsubscribe':
                         civicrm_mailer_event_unsubscribe($job, $queue, $hash);
                         break;
                 }
             }
             $store->markProcessed($key);
         }
     }
 }
function MembershipAutoRenewal()
{
    global $debug;
    $config =& CRM_Core_Config::singleton();
    require_once 'CRM/Utils/System.php';
    require_once 'CRM/Utils/Hook.php';
    require_once 'api/v2/Contribution.php';
    require_once 'api/v2/MembershipContributionLink.php';
    // Select all membership types which are 'auto-renew' required (table field `auto_renew` = 2)
    $membershipTypeArray = array();
    $membershipTypeFeeArray = array();
    $query = "SELECT * FROM civicrm_membership_type WHERE auto_renew = '2'";
    $dao = CRM_Core_DAO::executeQuery($query);
    while ($dao->fetch()) {
        $membershipTypeArray[] = $dao->id;
        $membershipTypeFeeArray[$dao->id] = $dao->minimum_fee;
    }
    $membershipTypes = @implode(',', $membershipTypeArray);
    //echo $membershipTypes;
    //$current_date = date("Y-m-d");
    //$temp_date = strtotime($current_date);
    $count = 0;
    $contactArray = array();
    if ($membershipTypes) {
        // Select all memberships which are auto-renew membership types
        // And status is grace (table field `status_id` = 3)
        //$dtFirstDay = date("YmdHis", mktime(0, 0, 0, date("m") , 1, date("Y")));
        //$dtLastDay = date('YmdHis',strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00'))));
        $dtFirstDay = '20111001000000';
        $dtLastDay = '20111031235959';
        $member_sql = "SELECT cm.id as membership_id , cm.contact_id as contact_id , cm.membership_type_id as membership_type_id ,cm.end_date as end_date ,\n                      cmt.duration_interval as duration_interval , cmt.duration_unit as duration_unit     \n                      FROM civicrm_membership cm \n                      JOIN civicrm_membership_type cmt ON cm.membership_type_id = cmt.id\n                      LEFT JOIN civicrm_value_payment_method cpm ON cm.id = cpm.entity_id\n                      WHERE cm.membership_type_id IN ({$membershipTypes}) AND cm.end_date >= '{$dtFirstDay}' AND cm.end_date <= '{$dtLastDay}'\n                      AND cm.status_id IN (2,3,8) AND cpm.direct_debit = 1";
        //AND cm.status_id = 3
        //echo $member_sql;exit;
        $member_dao = CRM_Core_DAO::executeQuery($member_sql);
        $count = 0;
        while ($member_dao->fetch()) {
            //print_r ($member_dao);exit;
            $membership_id = $member_dao->membership_id;
            $contact_id = $member_dao->contact_id;
            $mem_end_date = $member_dao->end_date;
            $temp_date = strtotime($mem_end_date);
            //print_r ($member_dao);echo "<hr />";
            //$temp_sql = "SELECT cmp.contribution_id as contribution_id FROM civicrm_membership_payment cmp WHERE cmp.membership_id = '$membership_id' ORDER BY cmp.contribution_id DESC";
            //$temp_dao = CRM_Core_DAO::executeQuery( $temp_sql );
            //$temp_dao->fetch();
            //$source_contribution_id = $temp_dao->contribution_id;
            //require_once 'CRM/Contribute/DAO/Contribution.php';
            //$cdao = new CRM_Contribute_DAO_Contribution();
            //$cdao->id = $source_contribution_id;
            //$cdao->find(true);
            //receive_date
            $params = array();
            $total_amount = $membershipTypeFeeArray[$member_dao->membership_type_id];
            $params = array('contact_id' => $member_dao->contact_id, 'receive_date' => date('YmdHis'), 'total_amount' => $total_amount, 'fee_amount' => $total_amount, 'source' => 'Auto-Renewal for Membership Id :' . $membership_id, 'contribution_status_id' => 2, 'note' => 'Auto-Renewal for Membership Id :' . $membership_id, 'contribution_type_id' => 2);
            $contribution =& civicrm_contribution_add($params);
            //print_r( $contribution );
            $contribution_id = $contribution['id'];
            $duration_interval = $member_dao->duration_interval;
            $duration_unit = $member_dao->duration_unit;
            $next_collectionDate = strtotime("+{$duration_interval} {$duration_unit}", $temp_date);
            $next_collectionDate = date('YmdHis', $next_collectionDate);
            $update_sql = "UPDATE civicrm_membership SET end_date = '{$next_collectionDate}' , status_id = '2' WHERE id = '{$membership_id}'";
            CRM_Core_DAO::executeQuery($update_sql);
            //Create membership Payment
            $params = array('contribution_id' => $contribution_id, 'membership_id' => $membership_id);
            $membershipPayment = civicrm_membershipcontributionlink_create($params);
            //$contribution_sql = "SELECT * FROM civicrm_value_direct_debit_details WHERE entity_id = '$source_contribution_id'";
            //$contribution_dao = CRM_Core_DAO::executeQuery( $contribution_sql );
            //$contribution_dao->fetch();
            //$mandate_id = $contribution_dao->mandate_id;
            //$contributionTypeName = CRM_Contribute_PseudoConstant::contributionType($cdao->contribution_type_id);
            //$mandate_sql = "SELECT * FROM civicrm_value_bank_details WHERE entity_id = '$contact_id' AND is_default = '1'";
            $mandate_sql = "SELECT * FROM civicrm_value_bank_details WHERE entity_id = '{$contact_id}'";
            $mandate_dao = CRM_Core_DAO::executeQuery($mandate_sql);
            $mandate_dao->fetch();
            $mandate_id = $mandate_dao->id;
            //$mandate_sql = "SELECT * FROM civicrm_value_bank_details WHERE id = '$mandate_id'";
            //$mandate_dao = CRM_Core_DAO::executeQuery( $mandate_sql );
            //$mandate_dao->fetch();
            if ($mandate_dao->collection_day) {
                $collection_day = $mandate_dao->collection_day;
            } else {
                $collection_day = 20;
            }
            //$next_collectionDate = get_valid_next_collection_date($collection_day , date("m") , 'YmdHis' );
            $next_collectionDate = '20111020000000';
            require_once 'api/v2/Activity.php';
            $params = array('activity_type_id' => CIVICRM_DIRECT_DEBIT_STANDARD_PAYMENT_ACTIVITY_ID, 'source_contact_id' => $contact_id, 'target_contact_id' => $contact_id, 'subject' => "Member Dues, Mandate Id - " . $mandate_id, 'status_id' => 1, 'activity_date_time' => $next_collectionDate);
            $act = civicrm_activity_create($params);
            $activity_id = $act['id'];
            if ($mandate_id != null) {
                $sql = "INSERT INTO civicrm_value_activity_bank_relationship SET entity_id = '{$activity_id}', bank_id = '{$mandate_id}'";
                $dao = CRM_Core_DAO::executeQuery($sql);
                $sql = "INSERT INTO civicrm_value_direct_debit_details SET activity_id = '{$activity_id}' , entity_id = '{$contribution_id}' , mandate_id = '{$mandate_id}'";
                $dao = CRM_Core_DAO::executeQuery($sql);
            }
            //CRM_Core_DAO::executeQuery( "UPDATE civicrm_value_bank_details SET bacs_code = '17' WHERE id = '$mandate_id'" );
            //$log_note = "Auto Renewal: Contact Id - $contact_id, Membership Id - $membership_id , Created Contribtion Id - $contribution_id";
            //$log_date = date("jS F Y - h:i:s A");
            //$log_query = "INSERT INTO civicrm_auto_renewal_log SET log_date = '$log_date' , log_summary = '$log_note'";
            //CRM_Core_DAO::executeQuery( $log_query );
            $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contact_id}");
            $contactArray[] = " Contact ID: " . $contact_id . "  - <a href =\"{$url}\"> " . $contact_id . " </a> ";
            $count++;
        }
        //exit;
    }
    echo "Membership renewed: " . $count . "<br />";
    if (count($contactArray) > 0) {
        echo $status = implode('<br/>', $contactArray);
    }
}
示例#11
0
 /**
  * Function to create Activity 
  * 
  * @param int $contactId
  */
 function activityCreate($params = null)
 {
     if ($params === null) {
         $individualSourceID = $this->individualCreate();
         $contactParams = array('first_name' => 'Julia', 'Last_name' => 'Anderson', 'prefix' => 'Ms', 'email' => '*****@*****.**', 'contact_type' => 'Individual');
         $individualTargetID = $this->individualCreate($contactParams);
         $params = array('source_contact_id' => $individualSourceID, 'target_contact_id' => array($individualTargetID), 'subject' => 'Discussion on Apis for v2', 'activity_date_time' => date('Ymd'), 'duration_hours' => 30, 'duration_minutes' => 20, 'location' => 'Baker Street', 'details' => 'Lets schedule a meeting', 'status_id' => 1, 'activity_name' => 'Meeting');
     }
     $result =& civicrm_activity_create($params, true);
     $result['target_contact_id'] = $individualTargetID;
     return $result;
 }
function ProcessRecurringContributions()
{
    global $debug;
    $config =& CRM_Core_Config::singleton();
    require_once 'CRM/Utils/System.php';
    require_once 'CRM/Utils/Hook.php';
    $dtCurrentDay = date("Ymd", mktime(0, 0, 0, date("m"), date("d"), date("Y")));
    //$dtCurrentDayStart  = $dtCurrentDay."000000";
    //$dtCurrentDayEnd = $dtCurrentDay."235959";
    $dtCurrentDayStart = '20111001000000';
    $dtCurrentDayEnd = '20111031235959';
    $sql = "SELECT * FROM civicrm_contribution_recur ccr \n                    WHERE ccr.end_date IS NULL AND ccr.next_sched_contribution >= {$dtCurrentDayStart} AND ccr.next_sched_contribution <= {$dtCurrentDayEnd}";
    //AND cm.status_id = 3
    //echo $sql;exit;
    $dao = CRM_Core_DAO::executeQuery($sql);
    $count = 0;
    while ($dao->fetch()) {
        $contact_id = $dao->contact_id;
        $hash = md5(uniqid(rand(), true));
        $total_amount = $dao->amount;
        $contribution_recur_id = $dao->id;
        $contribution_type_id = 1;
        $source = "Recurring Contribution from Contact Id - " . $contact_id;
        $receive_date = date("YmdHis");
        //echo $receive_date;exit;
        $contribution_status_id = 2;
        require_once 'CRM/Contribute/PseudoConstant.php';
        $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
        $payment_instrument_id = CIVICRM_DIRECT_DEBIT_PAYMENT_INSTRUMENT_ID;
        require_once 'api/v2/Contribution.php';
        $params = array('contact_id' => $contact_id, 'receive_date' => $receive_date, 'total_amount' => $total_amount, 'payment_instrument_id' => $payment_instrument_id, 'trxn_id' => $hash, 'invoice_id' => $hash, 'source' => $source, 'contribution_status_id' => $contribution_status_id, 'contribution_type_id' => $contribution_type_id, 'contribution_recur_id' => $contribution_recur_id, 'contribution_page_id' => $entity_id);
        //print_r ($params);
        $contributionArray =& civicrm_contribution_add($params);
        //print_r ($contributionArray);echo "<br />";
        $contribution_id = $contributionArray['id'];
        $mem_end_date = $member_dao->end_date;
        $temp_date = strtotime($dao->next_sched_contribution);
        $next_collectionDate = strtotime("+{$dao->frequency_interval} {$dao->frequency_unit}", $temp_date);
        $next_collectionDate = date('YmdHis', $next_collectionDate);
        $next_collectionDate = '20111020000000';
        $update_sql = "UPDATE civicrm_contribution_recur SET next_sched_contribution = '{$next_collectionDate}' WHERE id = '" . $dao->id . "'";
        CRM_Core_DAO::executeQuery($update_sql);
        $mandate_id = $dao->processor_id;
        require_once 'api/v2/Activity.php';
        $params = array('activity_type_id' => CIVICRM_DIRECT_DEBIT_STANDARD_PAYMENT_ACTIVITY_ID, 'source_contact_id' => $contact_id, 'target_contact_id' => $contact_id, 'subject' => "Donation, Mandate Id - " . $mandate_id, 'status_id' => 1, 'activity_date_time' => $next_collectionDate);
        $act = civicrm_activity_create($params);
        //print_r ($act);echo "<br />";
        $activity_id = $act['id'];
        if ($mandate_id && $activity_id) {
            $update_sql = "INSERT INTO civicrm_value_activity_bank_relationship SET entity_id = '{$activity_id}', bank_id = '{$mandate_id}'";
            CRM_Core_DAO::executeQuery($update_sql);
            $update_sql = "INSERT INTO civicrm_value_direct_debit_details SET activity_id = '{$activity_id}' , entity_id = '{$contribution_id}' , mandate_id = '{$mandate_id}'";
            CRM_Core_DAO::executeQuery($update_sql);
        }
        $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contact_id}");
        $contactArray[] = " Contact ID: " . $contact_id . "  - <a href =\"{$url}\"> " . $contact_id . " </a> ";
        //echo "<hr />";
        $count++;
    }
    echo "Contributions Created: " . $count . "<br />";
    if (count($contactArray) > 0) {
        echo $status = implode('<br/>', $contactArray);
    }
}