Пример #1
0
/**
 * create a contribution page
 *
 * @param  array   $params           (reference ) input parameters - need id and contribution_type_id
 *
 * @return array (reference )        contributionType id and other fields
 * @static void
 * @access public
 */
function &civicrm_payment_dodirectpayment( &$params ) {
    _civicrm_initialize( );

    if( ! is_array($params) ) {
        return civicrm_create_error( 'Params need to be of type array!' );
    }	
	
    civicrm_verify_mandatory ($params,null,array ('mode', 'component'));
    
    $mode               = CRM_Utils_Array::value( 'mode', $params );
    $component          = CRM_Utils_Array::value( 'component', $params ); // 'Contribute'
    unset($params['mode']);
    unset($params['component']);
    $paymentProcessor   = $params['paymentProcessor'];
    unset($params['paymentProcessor']);

    $form               = NULL; // todo add that in later
    
    $payment            =& CRM_Core_Payment::singleton($mode, $paymentProcessor, $form);
    $result             =& $payment->doDirectPayment( $params );
    
    if(is_object($result) && get_class($result) == 'CRM_Core_Error') {
        return civicrm_create_error($result->_errors[0]['code']);
    }

    return $result;
}
Пример #2
0
/**
 * Deletes an existing contact membership
 * 
 * This API is used for deleting a contact membership
 * 
 * @param  Int  $membershipID   Id of the contact membership to be deleted
 * 
 * @return null if successfull, object of CRM_Core_Error otherwise
 * @access public
 */
function civicrm_membership_delete(&$membershipID)
{
    _civicrm_initialize();
    if (empty($membershipID)) {
        return civicrm_create_error('Membership ID cannot be empty.');
    }
    require_once 'CRM/Member/BAO/Membership.php';
    CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipID);
    $membership = new CRM_Member_BAO_Membership();
    $result = $membership->deleteMembership($membershipID);
    return $result ? civicrm_create_success() : civicrm_create_error('Error while deleting Membership');
}
Пример #3
0
/**
 * Create a new domain
 *
 * @param array $params
 * @return array
 */
function civicrm_domain_create($params)
{
    require_once 'CRM/Core/BAO/Domain.php';
    if (!is_array($params)) {
        return civicrm_create_error('Params need to be of type array!');
    }
    if (empty($params)) {
        return civicrm_create_error('Params cannot be empty!');
    }
    $domain = CRM_Core_BAO_Domain::create($params);
    $domain_array = array();
    _civicrm_object_to_array($domain, $domain_array);
    return $domain_array;
}
Пример #4
0
/**
 * create a contribution page
 *
 * @param  array   $params           (reference ) input parameters - need id and contribution_type_id
 *
 * @return array (reference )        contributionType id and other fields
 * @static void
 * @access public
 */
function &civicrm_paymentprocessor_getpayment( &$params ) {
    _civicrm_initialize( );

    if( ! is_array($params) ) {
        return civicrm_create_error( 'Params need to be of type array!' );
    }	
	
	civicrm_verify_mandatory ($params,null,array ('id', 'mode'));
	$id		= CRM_Utils_Array::value( 'id', $params );
	$mode	= CRM_Utils_Array::value( 'mode', $params );

	$paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($id, $mode);

    return $paymentProcessor;
}
Пример #5
0
/**
 * Retrieve a set of activities, specific to given input params.
 *
 * @param  array  $params (reference ) input parameters.
 *
 * @return array (reference)  array of activities / error message.
 * @access public
 */
function civicrm_activity_contact_get($params)
{
    _civicrm_initialize();
    $contactId = CRM_Utils_Array::value('contact_id', $params);
    if (empty($contactId)) {
        return civicrm_create_error(ts("Required parameter not found"));
    }
    if (!is_numeric($contactId)) {
        return civicrm_create_error(ts("Invalid contact Id"));
    }
    $activities =& _civicrm_activities_get($contactId);
    if ($activities) {
        return civicrm_create_success($activities);
    } else {
        return civicrm_create_error(ts('Invalid Data'));
    }
}
Пример #6
0
/**
 * Function to create activity type
 * @param array   $params  associated array of fields
 *                 $params['option_value_id'] is required for updation of activity type
 * @return array $activityType created / updated activity type
 *
 * @access public
 */
function civicrm_activity_type_create($params)
{
    require_once 'CRM/Core/OptionGroup.php';
    if (!isset($params['label']) || !isset($params['weight'])) {
        return civicrm_create_error(ts('Required parameter "label / weight" not found'));
    }
    $action = 1;
    $groupParams = array('name' => 'activity_type');
    if ($optionValueID = CRM_Utils_Array::value('option_value_id', $params)) {
        $action = 2;
    }
    require_once 'CRM/Core/OptionValue.php';
    $activityObject = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $action, $optionValueID);
    $activityType = array();
    _civicrm_object_to_array($activityObject, $activityType);
    return $activityType;
}
Пример #7
0
/**
 * create a friend
 *
 * @param  array   $params           (reference ) input parameters - need id and contribution_type_id
 *
 * @return (none)
 * @static void
 * @access public
 */
function &civicrm_friend_create( &$params ) {
    _civicrm_initialize( );
	
    $values  = array( );
   
    require_once 'CRM/Contribute/BAO/ContributionType.php';

    $ids     = array( );
    if ( CRM_Utils_Array::value( 'id', $params ) ) {
    
	}
	
    $friend = CRM_Friend_BAO_Friend::create( $params );
    if ( is_a( $friend, 'CRM_Core_Error' ) ) {
        return civicrm_create_error( ts( 'Failed to create Friend' ) );
    }

    _civicrm_object_to_array($friend, $friendArray);
    
    return array('message' => 'Friend Added');
}
/**
 * Get the list of signatories
 *
 * @param  array   $params           (reference ) input parameters
 *
 * @return array (reference )        contribution_id of created or updated record
 * @static void
 * @access public
 */
function &civicrm_survey_respondant_get(&$params)
{
    _civicrm_initialize();
    if (empty($params)) {
        return civicrm_create_error(ts('No input parameters present'));
    }
    if (!is_array($params)) {
        return civicrm_create_error(ts('Input parameters is not an array'));
    }
    if (!array_key_exists('survey_id', $params)) {
        return civicrm_create_error('survey_id mandatory');
    }
    if (array_key_exists('status_id', $params)) {
        $status_id = $params['status_id'];
    } else {
        $status_id = NULL;
    }
    $petition = new CRM_Campaign_BAO_Petition();
    $signatures = $petition->getPetitionSignature($params['survey_id'], $status_id);
    return $signatures;
}
Пример #9
0
/**
 * Add a contribution type
 *
 * @param  array   $params           (reference ) input parameters
 *
 * @return array (reference )        contributionType id and other fields
 * @static void
 * @access public
 */
function &civicrm_contributiontype_add( &$params ) {
    _civicrm_initialize( );
	
    $values  = array( );
   
    require_once 'CRM/Contribute/BAO/ContributionType.php';

    $ids     = array( );
    if ( CRM_Utils_Array::value( 'id', $params ) ) {
        $ids['contributionType'] = $params['id'];
		unset($params['id']); // we don't need it in params
	}
	
    $contributionType = CRM_Contribute_BAO_ContributionType::add( $params, $ids );
    if ( is_a( $contributionType, 'CRM_Core_Error' ) ) {
        return civicrm_create_error( ts( 'Failed to add contribution type' ) );
    }

    _civicrm_object_to_array($contributionType, $contributeArray);
    
    return $contributeArray;
}
Пример #10
0
/**
 * Retrieve a set of activities, specific to given input params.
 *
 * @param  array  $params (reference ) input parameters.
 *
 * @return array (reference)  array of activities / error message.
 * @access public
 */
function civicrm_activity_contact_get($params)
{
    _civicrm_initialize();
    $contactId = CRM_Utils_Array::value('contact_id', $params);
    if (empty($contactId)) {
        return civicrm_create_error(ts("Required parameter not found"));
    }
    //check if $contactId is valid
    if (!is_numeric($contactId) || !preg_match('/^\\d+$/', $contactId)) {
        return civicrm_create_error(ts("Invalid contact Id"));
    }
    $activities =& _civicrm_activities_get($contactId);
    //show success for empty $activities array
    if (empty($activities)) {
        return civicrm_create_success(ts("0 activity record matching input params"));
    }
    if ($activities) {
        return civicrm_create_success($activities);
    } else {
        return civicrm_create_error(ts('Invalid Data'));
    }
}
Пример #11
0
/**
 * Delete a relationship type delete
 *
 * @param  id of relationship type  $id
 *
 * @return boolean  true if success, else false
 * @static void
 * @access public
 */
function civicrm_relationship_type_delete(&$params)
{
    if (!CRM_Utils_Array::value('id', $params)) {
        return civicrm_create_error('Missing required parameter');
    }
    require_once 'CRM/Utils/Rule.php';
    if ($params['id'] != null && !CRM_Utils_Rule::integer($params['id'])) {
        return civicrm_create_error('Invalid value for relationship type ID');
    }
    $relationTypeBAO = new CRM_Contact_BAO_RelationshipType();
    return $relationTypeBAO->del($params['id']) ? civicrm_create_success(ts('Deleted relationship type successfully')) : civicrm_create_error(ts('Could not delete relationship type'));
}
Пример #12
0
/**
 * take the input parameter list as specified in the data model and 
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *
 * @param array  $create       Is the formatted Values array going to
 *                             be used for CRM_Member_BAO_Membership:create()
 *
 * @return array|error
 * @access public
 */
function _civicrm_membership_format_params(&$params, &$values, $create = false)
{
    require_once "CRM/Member/DAO/Membership.php";
    $fields =& CRM_Member_DAO_Membership::fields();
    _civicrm_store_values($fields, $params, $values);
    foreach ($params as $key => $value) {
        // ignore empty values or empty arrays etc
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        switch ($key) {
            case 'membership_contact_id':
                if (!CRM_Utils_Rule::integer($value)) {
                    return civicrm_create_error("contact_id not valid: {$value}");
                }
                $dao =& new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                $values['contact_id'] = $values['membership_contact_id'];
                unset($values['membership_contact_id']);
                break;
            case 'join_date':
            case 'membership_start_date':
            case 'membership_end_date':
                if (!CRM_Utils_Rule::date($value)) {
                    return civicrm_create_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'membership_type_id':
                $id = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_MembershipType", $value, 'id', 'name');
                $values[$key] = $id;
                break;
            case 'status_id':
                $id = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_MembershipStatus", $value, 'id', 'name');
                $values[$key] = $id;
                break;
            default:
                break;
        }
    }
    _civicrm_custom_format_params($params, $values, 'Membership');
    if ($create) {
        // CRM_Member_BAO_Membership::create() handles membership_start_date,
        // membership_end_date and membership_source. So, if $values contains
        // membership_start_date, membership_end_date  or membership_source,
        // convert it to start_date, end_date or source
        $changes = array('membership_start_date' => 'start_date', 'membership_end_date' => 'end_date', 'membership_source' => 'source');
        foreach ($changes as $orgVal => $changeVal) {
            if (isset($values[$orgVal])) {
                $values[$changeVal] = $values[$orgVal];
                unset($values[$orgVal]);
            }
        }
    }
    return null;
}
Пример #13
0
 static function fatal($pearError)
 {
     return civicrm_create_error($pearError->getMessage(), $pearError->getDebugInfo());
 }
Пример #14
0
/**
 * Get a Tag.
 * 
 * This api is used for finding an existing tag.
 * Either id or name of tag are required parameters for this api.
 * 
 * @param  array $params  an associative array of name/value pairs.
 *
 * @return  array details of found tag else error
 * @access public
 */
function civicrm_tag_get($params)
{
    _civicrm_initialize();
    require_once 'CRM/Core/BAO/Tag.php';
    $tagBAO =& new CRM_Core_BAO_Tag();
    if (!is_array($params)) {
        return civicrm_create_error('Params is not an array.');
    }
    if (!isset($params['id']) && !isset($params['name'])) {
        return civicrm_create_error('Required parameters missing.');
    }
    $properties = array('id', 'name', 'description', 'parent_id');
    foreach ($properties as $name) {
        if (array_key_exists($name, $params)) {
            $tagBAO->{$name} = $params[$name];
        }
    }
    if (!$tagBAO->find(true)) {
        return civicrm_create_error('Exact match not found.');
    }
    _civicrm_object_to_array($tagBAO, $tag);
    return $tag;
}
Пример #15
0
/**
 * @todo Move this to ContactFormat.php 
 */
function civicrm_contact_format_create(&$params)
{
    _civicrm_initialize();
    CRM_Core_DAO::freeResult();
    // return error if we have no params
    if (empty($params)) {
        return civicrm_create_error('Input Parameters empty');
    }
    $error = _civicrm_required_formatted_contact($params);
    if (civicrm_error($error, 'CRM_Core_Error')) {
        return $error;
    }
    $error = _civicrm_validate_formatted_contact($params);
    if (civicrm_error($error, 'CRM_Core_Error')) {
        return $error;
    }
    //get the prefix id etc if exists
    require_once 'CRM/Contact/BAO/Contact.php';
    CRM_Contact_BAO_Contact::resolveDefaults($params, true);
    require_once 'CRM/Import/Parser.php';
    if ($params['onDuplicate'] != CRM_Import_Parser::DUPLICATE_NOCHECK) {
        CRM_Core_Error::reset();
        $error = _civicrm_duplicate_formatted_contact($params);
        if (civicrm_error($error, 'CRM_Core_Error')) {
            return $error;
        }
    }
    $contact = CRM_Contact_BAO_Contact::create($params, CRM_Utils_Array::value('fixAddress', $params));
    _civicrm_object_to_array($contact, $contactArray);
    return $contactArray;
}
/**
 * Deletes an existing Participant Payment
 *
 * This API is used for deleting a Participant Payment
 *
 * @param  Int  $participantPaymentID   Id of the Participant Payment to be deleted
 *
 * @return null if successfull, array with is_error=1 otherwise
 * @access public
 */
function civicrm_participant_payment_delete(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        $error = civicrm_create_error('Params is not an array');
        return $error;
    }
    if (!CRM_Utils_Array::value('id', $params)) {
        $error = civicrm_create_error('Invalid or no value for Participant payment ID');
        return $error;
    }
    require_once 'CRM/Event/BAO/ParticipantPayment.php';
    $participant = new CRM_Event_BAO_ParticipantPayment();
    return $participant->deleteParticipantPayment($params) ? civicrm_create_success() : civicrm_create_error('Error while deleting participantPayment');
}
/**
 *
 * @param <type> $params
 * @param <type> $op
 *
 * @return <type>
 */
function civicrm_entity_tag_common(&$params, $op = 'add')
{
    $entityIDs = array();
    $tagsIDs = array();
    $entityTable = 'civicrm_contact';
    if (is_array($params)) {
        foreach ($params as $n => $v) {
            if (substr($n, 0, 10) == 'contact_id' || substr($n, 0, 9) == 'entity_id') {
                $entityIDs[] = $v;
            } elseif (substr($n, 0, 6) == 'tag_id') {
                $tagIDs[] = $v;
            } elseif (substr($n, 0, 12) == 'entity_table') {
                $entityTable = $v;
            }
        }
    }
    if (empty($entityIDs)) {
        return civicrm_create_error(ts('contact_id is a required field'));
    }
    if (empty($tagIDs)) {
        return civicrm_create_error(ts('tag_id is a required field'));
    }
    require_once 'CRM/Core/BAO/EntityTag.php';
    $values = array('is_error' => 0);
    if ($op == 'add') {
        $values['total_count'] = $values['added'] = $values['not_added'] = 0;
        foreach ($tagIDs as $tagID) {
            list($te, $a, $na) = CRM_Core_BAO_EntityTag::addEntitiesToTag($entityIDs, $tagID, $entityTable);
            $values['total_count'] += $te;
            $values['added'] += $a;
            $values['not_added'] += $na;
        }
    } else {
        $values['total_count'] = $values['removed'] = $values['not_removed'] = 0;
        foreach ($tagIDs as $tagID) {
            list($te, $r, $nr) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($entityIDs, $tagID, $entityTable);
            $values['total_count'] += $te;
            $values['removed'] += $r;
            $values['not_removed'] += $nr;
        }
    }
    return $values;
}
Пример #18
0
/**
 * Derives the Membership Status of a given Membership Reocrd
 * 
 * This API is used for deriving Membership Status of a given Membership 
 * record using the rules encoded in the membership_status table.
 * 
 * @param  Int     $membershipID  Id of a membership
 * @param  String  $statusDate    
 * 
 * @return Array  Array of status id and status name 
 * @public
 */
function civicrm_membership_status_calc($membershipParams)
{
    if (!is_array($membershipParams)) {
        return civicrm_create_error(ts('membershipParams is not an array'));
    }
    if (!($membershipID = CRM_Utils_Array::value('membership_id', $membershipParams))) {
        return civicrm_create_error('membershipParams do not contain membership_id');
    }
    $query = "\nSELECT start_date, end_date, join_date\n  FROM civicrm_membership\n WHERE id = %1\n";
    $params = array(1 => array($membershipID, 'Integer'));
    $dao =& CRM_Core_DAO::executeQuery($query, $params);
    if ($dao->fetch()) {
        require_once 'CRM/Member/BAO/MembershipStatus.php';
        $result =& CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dao->start_date, $dao->end_date, $dao->join_date);
        //make is error zero only when valid status found.
        if (CRM_Utils_Array::value('id', $result)) {
            $result['is_error'] = 0;
        }
    } else {
        $result = civicrm_create_error('did not find a membership record');
    }
    $dao->free();
    return $result;
}
Пример #19
0
/**
 * take the input parameter list as specified in the data model and
 * convert it into the same format that we use in QF and BAO object
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new contact.
 * @param array  $values       The reformatted properties that we can use internally
 *                            '
 *
 * @return array|CRM_Error
 * @access public
 */
function _civicrm_pledge_format_params(&$params, &$values, $create = FALSE)
{
    // based on contribution apis - copy all the pledge fields - this function filters out non -valid fields but unfortunately
    // means we have to put them back where there are 2 names for the field (name in table & unique name)
    // since there is no clear std to use one or the other. Generally either works ? but not for create date
    // perhaps we should just copy $params across rather than run it through the 'filter'?
    // but at least the filter forces anomalies into the open. In several cases it turned out the unique names wouldn't work
    // even though they are 'generally' what is returned in the GET - implying they should
    $fields = CRM_Pledge_DAO_Pledge::fields();
    _civicrm_store_values($fields, $params, $values);
    //add back the fields we know of that got dropped by the previous function
    if ($params['pledge_create_date']) {
        //pledge_create_date will not be formatted by the format params function so change back to create_date
        $values['create_date'] = $params['pledge_create_date'];
    }
    if ($params['create_date']) {
        //create_date may have been dropped by the $fields function so retrieve it
        $values['create_date'] = $params['create_date'];
    }
    if (array_key_exists('installment_amount', $params)) {
        //field has been renamed - don't lose it! Note that this must be called
        // installment amount not pledge_installment_amount, pledge_original_installment_amount
        // or original_installment_amount to avoid error
        // Division by zero in CRM\Pledge\BAO\PledgePayment.php:162
        // but we should accept the variant because they are all 'logical assumptions' based on the
        // 'standards'
        $values['installment_amount'] = $params['installment_amount'];
    }
    if (array_key_exists('original_installment_amount', $params)) {
        $values['installment_amount'] = $params['original_installment_amount'];
    }
    if (array_key_exists('pledge_original_installment_amount', $params)) {
        $values['installment_amount'] = $params['pledge_original_installment_amount'];
    }
    if (array_key_exists('status_id', $params)) {
        $values['pledge_status_id'] = $params['status_id'];
    }
    if ($params['contact_id']) {
        //this is validity checked further down to make sure the contact exists
        $values['pledge_contact_id'] = $params['contact_id'];
    }
    if (array_key_exists('id', $params)) {
        //retrieve the id key dropped from params. Note we can't use pledge_id because it
        //causes an error in CRM_Pledge_BAO_PledgePayment - approx line 302
        $values['id'] = $params['id'];
    }
    if (array_key_exists('pledge_id', $params)) {
        //retrieve the id key dropped from params. Note we can't use pledge_id because it
        //causes an error in CRM_Pledge_BAO_PledgePayment - approx line 302
        $values['id'] = $params['pledge_id'];
        unset($values['pledge_id']);
    }
    if (array_key_exists('status_id', $params)) {
        $values['pledge_status_id'] = $params['status_id'];
    }
    if (empty($values['id'])) {
        //at this point both should be the same so unset both if not set - passing in empty
        //value causes crash rather creating new - do it before next section as null values ignored in 'switch'
        unset($values['id']);
    }
    if (!empty($params['scheduled_date'])) {
        //scheduled date is required to set next payment date - defaults to start date
        $values['scheduled_date'] = $params['scheduled_date'];
    } elseif (array_key_exists('start_date', $params)) {
        $values['scheduled_date'] = $params['start_date'];
    }
    if (CRM_Utils_Array::value('contribution_type_id', $params)) {
        $values['contribution_type_id'] = $params['contribution_type_id'];
    }
    foreach ($values as $key => $value) {
        // ignore empty values or empty arrays etc
        if (CRM_Utils_System::isNull($value)) {
            continue;
        }
        switch ($key) {
            case 'pledge_contact_id':
                if (!CRM_Utils_Rule::integer($value)) {
                    return civicrm_create_error("contact_id not valid: {$value}");
                }
                $dao = new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                $values['contact_id'] = $values['pledge_contact_id'];
                unset($values['pledge_contact_id']);
                break;
            case 'pledge_id':
                if (!CRM_Utils_Rule::integer($value)) {
                    return civicrm_create_error("contact_id not valid: {$value}");
                }
                $dao = new CRM_Core_DAO();
                $qParams = array();
                $svq = $dao->singleValueQuery("SELECT id FROM civicrm_pledge WHERE id = {$value}", $qParams);
                if (!$svq) {
                    return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
                }
                break;
            case 'create_date':
            case 'scheduled_date':
            case 'start_date':
                if (!CRM_Utils_Rule::datetime($value)) {
                    return civicrm_create_error("{$key} not a valid date: {$value}");
                }
                break;
            case 'installment_amount':
            case 'amount':
                if (!CRM_Utils_Rule::money($value)) {
                    return civicrm_create_error("{$key} not a valid amount: {$value}");
                }
                break;
            case 'currency':
                if (!CRM_Utils_Rule::currencyCode($value)) {
                    return civicrm_create_error("currency not a valid code: {$value}");
                }
                break;
            case 'contribution_type_id':
                require_once 'CRM/Contribute/PseudoConstant.php';
                $typeId = CRM_Contribute_PseudoConstant::contributionType($value);
                if (!CRM_Utils_Rule::integer($value) || !$typeId) {
                    return civicrm_create_error("contribution type id is not valid: {$value}");
                }
            default:
                break;
        }
    }
    //format the parameters
    _civicrm_custom_format_params($params, $values, 'Pledge');
    return array();
}
Пример #20
0
/**
 * Function to check for required params
 *
 * @param array   $params  associated array of fields
 * @param boolean $addMode true for add mode
 *
 * @return array $error array with errors
 */
function _civicrm_activity_check_params(&$params, $addMode = false)
{
    // return error if we do not get any params
    if (empty($params)) {
        return civicrm_create_error(ts('Input Parameters empty'));
    }
    // check for activity subject if add mode
    if ($addMode && !isset($params['subject'])) {
        return civicrm_create_error(ts('Missing Subject'));
    }
    if (!$addMode && !isset($params['id'])) {
        return civicrm_create_error(ts('Required parameter "id" not found'));
    }
    if (!$addMode && $params['id'] && !is_numeric($params['id'])) {
        return civicrm_create_error(ts('Invalid activity "id"'));
    }
    // check if activity type_id is passed in
    if (!isset($params['activity_name']) && !isset($params['activity_type_id'])) {
        //when name AND id are both absent
        return civicrm_create_error(ts('Missing Activity'));
    } else {
        if (isset($params['activity_name']) && isset($params['activity_type_id'])) {
            //when name AND id are both present - check for the match
            $activityTypes =& CRM_Core_PseudoConstant::activityType();
            $activityId = array_search($params['activity_name'], $activityTypes);
            if ($activityId != $params['activity_type_id']) {
                return civicrm_create_error(ts('Mismatch in Activity'));
            }
        } else {
            //either name OR id is present
            if (isset($params['activity_name'])) {
                require_once "CRM/Core/PseudoConstant.php";
                $activityTypes =& CRM_Core_PseudoConstant::activityType(true, false, true);
                $activityId = array_search($params['activity_name'], $activityTypes);
                if (!$activityId) {
                    return civicrm_create_error(ts('Invalid Activity Name'));
                } else {
                    $params['activity_type_id'] = $activityId;
                }
            } else {
                if (!is_numeric($params['activity_type_id'])) {
                    return civicrm_create_error(ts('Invalid Activity Type ID'));
                } else {
                    $activityTypes =& CRM_Core_PseudoConstant::activityType();
                    if (!array_key_exists($params['activity_type_id'], $activityTypes)) {
                        return civicrm_create_error(ts('Invalid Activity Type ID'));
                    }
                }
            }
        }
    }
    // check for activity status is passed in
    if (isset($params['status_id']) && !is_numeric($params['status_id'])) {
        require_once "CRM/Core/PseudoConstant.php";
        $activityStatus =& CRM_Core_PseudoConstant::activityStatus();
        $activityStatusId = array_search($params['status_id'], $activityStatus);
        if (!$activityStatusId) {
            return civicrm_create_error(ts('Invalid Activity Status'));
        } else {
            $params['status_id'] = $activityStatusId;
        }
    }
    // check for activity duration minutes
    if (isset($params['duration_minutes']) && !is_numeric($params['duration_minutes'])) {
        return civicrm_create_error(ts('Invalid Activity Duration (in minutes)'));
    }
    // check for source contact id
    if ($addMode && empty($params['source_contact_id'])) {
        return civicrm_create_error(ts('Missing Source Contact'));
    }
    if (isset($params['source_contact_id']) && !is_numeric($params['source_contact_id'])) {
        return civicrm_create_error(ts('Invalid Source Contact'));
    }
    return null;
}
/**
 * This function ensures that we have the right input parameters
 *
 * We also need to make sure we run all the form rules on the params list
 * to ensure that the params are valid
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new relationship.
 *
 * @return bool|CRM_Utils_Error
 * @access private
 */
function _civicrm_relationship_check_params(&$params)
{
    static $required = array('contact_id_a' => NULL, 'contact_id_b' => NULL, 'relationship_type_id' => 'relationship_type');
    // params should be an array
    if (!is_array($params)) {
        return civicrm_create_error('Input parameter is not an array');
    }
    // cannot create with empty params
    if (empty($params)) {
        return civicrm_create_error('Input Parameters empty');
    }
    // check params for validity of Relationship id
    if (CRM_Utils_Array::value('id', $params)) {
        require_once 'CRM/Contact/BAO/Relationship.php';
        $relation = new CRM_Contact_BAO_Relationship();
        $relation->id = $params['id'];
        if (!$relation->find(TRUE)) {
            return civicrm_create_error('Relationship id is not valid');
        } else {
            if ($params['contact_id_a'] != $relation->contact_id_a || $params['contact_id_b'] != $relation->contact_id_b) {
                return civicrm_create_error('Cannot change the contacts once relationship has been created');
            }
        }
    }
    $valid = TRUE;
    $error = '';
    foreach ($required as $field => $eitherField) {
        if (!CRM_Utils_Array::value($field, $params)) {
            if ($eitherField && CRM_Utils_Array::value($eitherField, $params)) {
                continue;
            }
            $valid = FALSE;
            $error .= " {$field}";
        }
    }
    if (!$valid) {
        return civicrm_create_error('Required fields not found' . $error);
    }
    return array();
}
Пример #22
0
/**
 * delete an existing group
 *
 * This method is used to delete any existing group. id of the group
 * to be deleted is required field in $params array
 *
 * @param array $params  (referance) array containing id of the group
 *                       to be deleted
 *
 * @return array  (referance) returns flag true if successfull, error
 *                message otherwise
 *
 * @access public
 */
function civicrm_group_delete(&$params)
{
    _civicrm_initialize();
    if (is_null($params) || !is_array($params) || !CRM_Utils_Array::value('id', $params)) {
        return civicrm_create_error('Required parameter missing');
    }
    CRM_Contact_BAO_Group::discard($params['id']);
    return civicrm_create_success(TRUE);
}
Пример #23
0
/**
 * function convert params to v3.0 format before add location.
 */
function _civicrm_format_params_v2_to_v3(&$params, $locationTypeId = null)
{
    // get the loc type id.
    if (!$locationTypeId) {
        // get location type.
        $locationTypeId = CRM_Utils_Array::value('location_type_id', $params);
        if (!$locationTypeId && array_key_exists('location_type', $params)) {
            require_once 'CRM/Core/PseudoConstant.php';
            $locTypes =& CRM_Core_PseudoConstant::locationType();
            $locType = $params['location_type'];
            if (is_array($params['location_type'])) {
                $locType = array_pop($params['location_type']);
            }
            $locationTypeId = CRM_Utils_Array::key($locType, $locTypes);
        }
    }
    // convert params into v3.0 format.
    $primary = $billing = array();
    $blocks = array('Email', 'Phone', 'IM', 'OpenID');
    // format params array.
    $firstBlockCount = null;
    foreach ($blocks as $block) {
        require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_DAO_" . $block) . ".php";
        eval('$fields =& CRM_Core_DAO_' . $block . '::fields( );');
        $name = strtolower($block);
        $blockCount = 0;
        if (CRM_Utils_Array::value($name, $params)) {
            if (is_array($params[$name])) {
                $values = $params[$name];
                $params[$name] = array();
                foreach ($values as $val) {
                    _civicrm_store_values($fields, $val, $params[$name][++$blockCount]);
                    // check for primary and billing.
                    if (CRM_Utils_Array::value('is_primary', $val)) {
                        $primary[$name][$blockCount] = true;
                    }
                    if (CRM_Utils_Array::value('is_billing', $val)) {
                        $primary[$name][$blockCount] = true;
                    }
                    if (!$firstBlockCount) {
                        $firstBlockCount = $blockCount;
                    }
                }
            } else {
                //need to get ids.
                if (in_array($name, array('im', 'phone'))) {
                    require_once 'CRM/Core/PseudoConstant.php';
                    if ($name == 'im') {
                        CRM_Utils_Array::lookupValue($params, 'provider', CRM_Core_PseudoConstant::IMProvider(), true);
                    } else {
                        CRM_Utils_Array::lookupValue($params, 'phone_type', CRM_Core_PseudoConstant::phoneType(), true);
                    }
                }
                $locValues[$name] = array();
                _civicrm_store_values($fields, $params, $locValues[$name][++$blockCount]);
                $params[$name] = $locValues[$name];
                $firstBlockCount = $blockCount;
                unset($locValues[$name]);
            }
            // make first block as default primary when is_primary
            // is not set in sub array and set in main params array.
            if (!CRM_Utils_Array::value($name, $primary) && CRM_Utils_Array::value('is_primary', $params)) {
                $primary[$name][$firstBlockCount] = true;
                $params[$name][$firstBlockCount]['is_primary'] = true;
            }
            if (!CRM_Utils_Array::value($name, $billing) && CRM_Utils_Array::value('is_billing', $params)) {
                $billing[$name][$firstBlockCount] = true;
                $params[$name][$firstBlockCount]['is_billing'] = true;
            }
        }
    }
    //get the address fields.
    $addressCount = 1;
    $ids = array('county', 'country_id', 'country', 'state_province_id', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name', 'city', 'street_address');
    $addressTaken = false;
    foreach ($ids as $id) {
        if (array_key_exists($id, $params)) {
            if (!$addressTaken) {
                require_once 'CRM/Core/DAO/Address.php';
                $fields =& CRM_Core_DAO_Address::fields();
                _civicrm_store_values($fields, $params, $params['address'][$addressCount]);
                $addressTaken = true;
            }
            $params['address'][$addressCount][$id] = $params[$id];
            unset($params[$id]);
        }
    }
    // format state and country.
    foreach (array('state_province', 'country') as $field) {
        $fName = $field == 'state_province' ? 'stateProvinceAbbreviation' : 'countryIsoCode';
        if (CRM_Utils_Array::value('address', $params) && CRM_Utils_Array::value($field, $params['address'][$addressCount]) && is_numeric($params['address'][$addressCount][$field])) {
            $fValue =& $params['address'][$addressCount][$field];
            eval('$fValue = CRM_Core_PseudoConstant::' . $fName . '( $fValue );');
            //kill the reference.
            unset($fValue);
        }
    }
    // check for primary address.
    if (CRM_Utils_Array::value('is_primary', $params)) {
        if ($addressTaken) {
            $primary['address'][$addressCount] = true;
            $params['address'][$addressCount]['is_primary'] = true;
        }
        unset($params['is_primary']);
    }
    if (CRM_Utils_Array::value('is_billing', $params)) {
        if ($addressTaken) {
            $billing['address'][$addressCount] = true;
            $params['address'][$addressCount]['is_billing'] = true;
        }
        unset($params['is_billing']);
    }
    // handle primary and billing reset.
    foreach (array('email', 'phone', 'im', 'address', 'openid') as $name) {
        if (!array_key_exists($name, $params) || CRM_Utils_System::isNull($params[$name])) {
            continue;
        }
        $errorMsg = null;
        $primaryBlockIndex = $billingBlockIndex = 0;
        if (array_key_exists($name, $primary)) {
            if (count($primary[$name]) > 1) {
                $errorMsg .= ts("<br />Multiple Primary %1.", array(1 => $block));
            } else {
                $primaryBlockIndex = key($primary[$name]);
            }
        }
        if (array_key_exists($name, $billing)) {
            if (count($billing[$name]) > 1) {
                $errorMsg .= ts("<br />Multiple Billing %1.", array(1 => $block));
            } else {
                $billingBlockIndex = key($billing[$name]);
            }
        }
        if ($errorMsg) {
            return civicrm_create_error($errorMsg);
        }
        foreach ($params[$name] as $count => &$values) {
            if ($primaryBlockIndex && $count != $primaryBlockIndex) {
                $values['is_primary'] = false;
            }
            if ($billingBlockIndex && $count != $billingBlockIndex) {
                $values['is_billing'] = false;
            }
            // get location type if not present in sub array.
            if (!CRM_Utils_Array::value('location_type_id', $values)) {
                $values['location_type_id'] = $locationTypeId;
            }
            //kill the reference.
            unset($values);
        }
    }
    // finally unset location_type and location type id.
    foreach (array('location_type', 'location_type_id') as $f) {
        if (isset($params[$f])) {
            unset($params[$f]);
        }
    }
    return $params;
}
function civicrm_group_contact_update_status(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error(ts('input parameter should be an array'));
    }
    if (empty($params['contact_id'])) {
        return civicrm_create_error(ts('contact_id is a required field'));
    } else {
        $contactID = $params['contact_id'];
    }
    if (empty($params['group_id'])) {
        return civicrm_create_error(ts('group_id is a required field'));
    } else {
        $groupID = $params['group_id'];
    }
    $method = CRM_Utils_Array::value('method', $params, 'API');
    $tracking = CRM_Utils_Array::value('tracking', $params);
    require_once 'CRM/Contact/BAO/GroupContact.php';
    CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contactID, $groupID, $method, $tracking);
    return TRUE;
}
Пример #25
0
/**
 * Deletes an existing Group Organization
 * 
 * This API is used for deleting a Group Organization
 * 
 * @param  Array  $params  ID of the Group Organization to be deleted
 * 
 * @return null if successfull, array with is_error = 1 otherwise
 * @access public
 */
function civicrm_group_organization_remove(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        $error = civicrm_create_error('Input parameter is not an array');
        return $error;
    }
    if (empty($params)) {
        return civicrm_create_error('No input parameter present');
    }
    if (!CRM_Utils_Array::value('id', $params)) {
        $error = civicrm_create_error('Invalid or no value for Group Organization ID');
        return $error;
    }
    require_once 'CRM/Contact/BAO/GroupOrganization.php';
    $result = CRM_Contact_BAO_GroupOrganization::delete($params);
    return $result ? civicrm_create_success(ts('Deleted Group Organization successfully')) : civicrm_create_error(ts('Could not delete Group Organization'));
}
Пример #26
0
/**
 * Function to check for required params
 *
 * @param array   $params  associated array of fields
 * @param boolean $addMode true for add mode
 *
 * @return array $error array with errors
 */
function _civicrm_activity_check_params(&$params, $addMode = false)
{
    // return error if we do not get any params
    if (empty($params)) {
        return civicrm_create_error(ts('Input Parameters empty'));
    }
    $contactIds = array('source' => CRM_Utils_Array::value('source_contact_id', $params), 'assignee' => CRM_Utils_Array::value('assignee_contact_id', $params), 'target' => CRM_Utils_Array::value('target_contact_id', $params));
    foreach ($contactIds as $key => $value) {
        if (empty($value)) {
            continue;
        }
        $valueIds = array($value);
        if (is_array($value)) {
            $valueIds = array();
            foreach ($value as $id) {
                if ($id) {
                    $valueIds[$id] = $id;
                }
            }
        }
        if (empty($valueIds)) {
            continue;
        }
        $sql = '
SELECT  count(*) 
  FROM  civicrm_contact 
 WHERE  id IN (' . implode(', ', $valueIds) . ' )';
        if (count($valueIds) != CRM_Core_DAO::singleValueQuery($sql)) {
            return civicrm_create_error(ts('Invalid %1 Contact Id', array(1 => ucfirst($key))));
        }
    }
    $activityIds = array('activity' => CRM_Utils_Array::value('id', $params), 'parent' => CRM_Utils_Array::value('parent_id', $params), 'original' => CRM_Utils_Array::value('original_id', $params));
    foreach ($activityIds as $id => $value) {
        if ($value && !CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $value, 'id')) {
            return civicrm_create_error(ts('Invalid %1 Id', array(1 => ucfirst($id))));
        }
    }
    // check for activity subject if add mode
    if ($addMode && !isset($params['subject'])) {
        return civicrm_create_error(ts('Missing Subject'));
    }
    if (!$addMode && !isset($params['id'])) {
        return civicrm_create_error(ts('Required parameter "id" not found'));
    }
    if (!$addMode && $params['id'] && !is_numeric($params['id'])) {
        return civicrm_create_error(ts('Invalid activity "id"'));
    }
    require_once 'CRM/Core/PseudoConstant.php';
    $activityTypes = CRM_Core_PseudoConstant::activityType(true, true, true, 'name');
    // check if activity type_id is passed in
    if ($addMode && !isset($params['activity_name']) && !isset($params['activity_type_id'])) {
        //when name AND id are both absent
        return civicrm_create_error(ts('Missing Activity Type'));
    } else {
        $activityName = CRM_Utils_Array::value('activity_name', $params);
        $activityTypeId = CRM_Utils_Array::value('activity_type_id', $params);
        if ($activityName) {
            $activityNameId = array_search(ucfirst($activityName), $activityTypes);
            if (!$activityNameId) {
                return civicrm_create_error(ts('Invalid Activity Name'));
            } else {
                if ($activityTypeId && $activityTypeId != $activityNameId) {
                    return civicrm_create_error(ts('Mismatch in Activity'));
                }
            }
            $params['activity_type_id'] = $activityNameId;
        } else {
            if ($activityTypeId && !array_key_exists($activityTypeId, $activityTypes)) {
                return civicrm_create_error(ts('Invalid Activity Type ID'));
            }
        }
    }
    // check for activity status is passed in
    if (isset($params['status_id'])) {
        require_once "CRM/Core/PseudoConstant.php";
        $activityStatus = CRM_Core_PseudoConstant::activityStatus();
        if (is_numeric($params['status_id']) && !array_key_exists($params['status_id'], $activityStatus)) {
            return civicrm_create_error(ts('Invalid Activity Status'));
        } elseif (!is_numeric($params['status_id'])) {
            $statusId = array_search($params['status_id'], $activityStatus);
            if (!is_numeric($statusId)) {
                return civicrm_create_error(ts('Invalid Activity Status'));
            }
        }
    }
    if (isset($params['priority_id']) && is_numeric($params['priority_id'])) {
        require_once "CRM/Core/PseudoConstant.php";
        $activityPriority = CRM_Core_PseudoConstant::priority();
        if (!array_key_exists($params['priority_id'], $activityStatus)) {
            return civicrm_create_error(ts('Invalid Priority'));
        }
    }
    // check for activity duration minutes
    if (isset($params['duration_minutes']) && !is_numeric($params['duration_minutes'])) {
        return civicrm_create_error(ts('Invalid Activity Duration (in minutes)'));
    }
    // check for source contact id
    if ($addMode && empty($params['source_contact_id'])) {
        return civicrm_create_error(ts('Missing Source Contact'));
    }
    if ($addMode && !CRM_Utils_Array::value('activity_date_time', $params)) {
        $params['activity_date_time'] = CRM_Utils_Date::processDate(date('Y-m-d H:i:s'));
    } else {
        if (CRM_Utils_Array::value('activity_date_time', $params)) {
            $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time']);
        }
    }
    return null;
}
Пример #27
0
/**
 * Generic file to retrieve all the constants and
 * pseudo constants used in CiviCRM
 *
 *  @param  string  Name of a public static method of
 *                  CRM_Core_PseudoContant: one of 
 *  <ul>
 *    <li>activityStatus</li>
 *    <li>activityType</li>
 *    <li>addressee</li>
 *    <li>allGroup</li>
 *    <li>country</li>
 *    <li>countryIsoCode</li>
 *    <li>county</li>
 *    <li>currencyCode</li>
 *    <li>currencySymbols</li>
 *    <li>customGroup</li>
 *    <li>emailGreeting</li>
 *    <li>fromEmailAddress</li>
 *    <li>gender</li>
 *    <li>group</li>
 *    <li>groupIterator</li>
 *    <li>honor</li>
 *    <li>IMProvider</li>
 *    <li>individualPrefix</li>
 *    <li>individualSuffix</li>
 *    <li>locationType</li>
 *    <li>locationVcardName</li>
 *    <li>mailProtocol</li>
 *    <li>mappingTypes</li>
 *    <li>paymentProcessor</li>
 *    <li>paymentProcessorType</li>
 *    <li>pcm</li>
 *    <li>phoneType</li>
 *    <li>postalGreeting</li>
 *    <li>priority</li>
 *    <li>relationshipType</li>
 *    <li>stateProvince</li>
 *    <li>stateProvinceAbbreviation</li>
 *    <li>stateProvinceForCountry</li>
 *    <li>staticGroup</li>
 *    <li>tag</li>
 *    <li>tasks</li>
 *    <li>ufGroup</li>
 *    <li>visibility</li>
 *    <li>worldRegion</li>
 *    <li>wysiwygEditor</li>
 *  </ul>
 */
function civicrm_constant_get($name, $params = array())
{
    require_once 'CRM/Core/PseudoConstant.php';
    $className = 'CRM_Core_PseudoConstant';
    $callable = "{$className}::{$name}";
    if (is_callable($callable)) {
        if (empty($params)) {
            $values = call_user_func(array($className, $name));
        } else {
            $values = call_user_func_array(array($className, $name), $params);
        }
        return $values;
    }
    return civicrm_create_error(ts('Unknown civicrm constant or method not callable'));
}
Пример #28
0
/**
 * Ensure that we have the right input parameters for custom data
 *
 * @param array   $params          Associative array of property name/value
 *                                 pairs to insert in new contact.
 * @param string  $csType          contact subtype if exists/passed.
 *
 * @return null on success, error message otherwise
 * @access public
 */
function civicrm_contact_check_custom_params($params, $csType = NULL)
{
    empty($csType) ? $onlyParent = TRUE : ($onlyParent = FALSE);
    require_once 'CRM/Core/BAO/CustomField.php';
    $customFields = CRM_Core_BAO_CustomField::getFields($params['contact_type'], FALSE, FALSE, $csType, NULL, $onlyParent);
    foreach ($params as $key => $value) {
        if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
            /* check if it's a valid custom field id */
            if (!array_key_exists($customFieldID, $customFields)) {
                $errorMsg = ts("Invalid Custom Field Contact Type: {$params['contact_type']}");
                if ($csType) {
                    $errorMsg .= ts(" or Mismatched SubType: " . implode(', ', (array) $csType));
                }
                return civicrm_create_error($errorMsg);
            }
        }
    }
}
/**
 * Function to delete activity type
 *
 * @param activityTypeId int   activity type id to delete
 *
 * @return boolen
 *
 * @access public
 */
function civicrm_activity_type_delete($params)
{
    if (!isset($params['activity_type_id'])) {
        return civicrm_create_error(ts('Required parameter "activity_type_id" not found'));
    }
    $activityTypeId = $params['activity_type_id'];
    require_once 'CRM/Core/BAO/OptionValue.php';
    return CRM_Core_BAO_OptionValue::del($activityTypeId);
}
/**
 * This function ensures that we have the right input membership parameters
 *
 *
 * @param array  $params       Associative array of property name/value
 *                             pairs to insert in new membership.
 *
 * @return bool|CRM_Utils_Error
 * @access private
 */
function _civicrm_membership_check_params(&$params)
{
    // params should be an array
    if (!is_array($params)) {
        return civicrm_create_error('Params is not an array');
    }
    // cannot create a membership with empty params
    if (empty($params)) {
        return civicrm_create_error('Input Parameters empty');
    }
    $valid = true;
    $error = '';
    // contact id is required for both add and update
    if (!CRM_Utils_Array::value('contact_id', $params)) {
        $valid = false;
        $error .= ' contact_id';
    }
    // check params for membership id during update
    if (CRM_Utils_Array::value('id', $params)) {
        require_once 'CRM/Member/BAO/Membership.php';
        $membership = new CRM_Member_BAO_Membership();
        $membership->id = $params['id'];
        if (!$membership->find(true)) {
            return civicrm_create_error(ts('Membership id is not valid'));
        }
    } else {
        // membership type id Or membership type is required during add
        if (!CRM_Utils_Array::value('membership_type_id', $params) && !CRM_Utils_Array::value('membership_type', $params)) {
            $valid = false;
            $error .= ' membership_type_id Or membership_type';
        }
    }
    // also check for status id if override is set (during add/update)
    if (isset($params['is_override']) && !CRM_Utils_Array::value('status_id', $params)) {
        $valid = false;
        $error .= ' status_id';
    }
    if (!$valid) {
        return civicrm_create_error("Required fields not found for membership {$error}");
    }
    return array();
}