コード例 #1
0
ファイル: ApiRouter.php プロジェクト: rameshrr99/civicrm-core
 /**
  * @param array $cxn
  * @param string $entity
  * @param string $action
  * @param array $params
  * @return mixed
  */
 public static function route($cxn, $entity, $action, $params)
 {
     $SUPER_PERM = array('administer CiviCRM');
     require_once 'api/v3/utils.php';
     // FIXME: Shouldn't the X-Forwarded-Proto check be part of CRM_Utils_System::isSSL()?
     if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL') && !CRM_Utils_System::isSSL() && strtolower(CRM_Utils_Array::value('X_FORWARDED_PROTO', CRM_Utils_System::getRequestHeaders())) != 'https') {
         return civicrm_api3_create_error('System policy requires HTTPS.');
     }
     // Note: $cxn and cxnId are authenticated before router is called.
     $dao = new CRM_Cxn_DAO_Cxn();
     $dao->cxn_id = $cxn['cxnId'];
     if (empty($cxn['cxnId']) || !$dao->find(TRUE) || !$dao->cxn_id) {
         return civicrm_api3_create_error('Failed to lookup connection authorizations.');
     }
     if (!$dao->is_active) {
         return civicrm_api3_create_error('Connection is inactive.');
     }
     if (!is_string($entity) || !is_string($action) || !is_array($params)) {
         return civicrm_api3_create_error('API parameters are malformed.');
     }
     if (empty($cxn['perm']['api']) || !is_array($cxn['perm']['api']) || empty($cxn['perm']['grant']) || !(is_array($cxn['perm']['grant']) || is_string($cxn['perm']['grant']))) {
         return civicrm_api3_create_error('Connection has no permissions.');
     }
     $whitelist = \Civi\API\WhitelistRule::createAll($cxn['perm']['api']);
     \Civi::service('dispatcher')->addSubscriber(new \Civi\API\Subscriber\WhitelistSubscriber($whitelist));
     CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp();
     if ($cxn['perm']['grant'] === '*') {
         CRM_Core_Config::singleton()->userPermissionTemp->grant($SUPER_PERM);
     } else {
         CRM_Core_Config::singleton()->userPermissionTemp->grant($cxn['perm']['grant']);
     }
     $params['check_permissions'] = 'whitelist';
     return civicrm_api($entity, $action, $params);
 }
コード例 #2
0
ファイル: Prevem.php プロジェクト: utkarshsharma/civicrm-core
/**
+--------------------------------------------------------------------+
| CiviCRM version 4.6                                                |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015                                |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM.                                    |
|                                                                    |
| CiviCRM is free software; you can copy, modify, and distribute it  |
| under the terms of the GNU Affero General Public License           |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
|                                                                    |
| CiviCRM is distributed in the hope that it will be useful, but     |
| WITHOUT ANY WARRANTY; without even the implied warranty of         |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
| See the GNU Affero General Public License for more details.        |
|                                                                    |
| You should have received a copy of the GNU Affero General Public   |
| License and the CiviCRM Licensing Exception along                  |
| with this program; if not, contact CiviCRM LLC                     |
| at info[AT]civicrm[DOT]org. If you have questions about the        |
| GNU Affero General Public License or the licensing of CiviCRM,     |
| see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+--------------------------------------------------------------------+
*/
function civicrm_api3_prevem_login($params)
{
    $prevemUrl = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'prevem_url');
    $prevemURL = !empty($prevemUrl) ? CRM_Utils_URL::mask($prevemUrl, array('user', 'pass')) : NULL;
    if (!$prevemURL) {
        return civicrm_api3_create_error("prevemURL is not configured. Go to Administer>CiviMail>CiviMail Component Settings to configure prevemURL");
    }
    $prevemConsumer = parse_url($prevemUrl, PHP_URL_USER);
    $prevemSecret = parse_url($prevemUrl, PHP_URL_PASS);
    /** TODO Parse $prevemUrl. Send login request to get token. **/
    /** To send login request, see eg http://stackoverflow.com/questions/2445276/how-to-post-data-in-php-using-file-get-contents **/
    $postdata = http_build_query(array('email' => $prevemConsumer . "@foo.com", 'password' => $prevemSecret));
    $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
    $context = stream_context_create($opts);
    $result = file_get_contents($prevemURL . '/api/Users/login', FALSE, $context);
    if ($result === FALSE) {
        return civicrm_api3_create_error("Failed to login. Check if Preview Manager is running on " . $prevemURL);
    } else {
        $accessToken = json_decode($result)->{'id'};
        if (!$accessToken) {
            return civicrm_api3_create_error("Failed to parse access token. Check if Preview Manager is running on " . $prevemURL);
        }
        $returnValues = array('url' => $prevemURL, 'consumerId' => $prevemConsumer, 'token' => $accessToken, 'password' => $prevemSecret);
        return civicrm_api3_create_success($returnValues, $params, 'Prevem', 'login');
    }
}
コード例 #3
0
/**
 * Delete an existing participant_status.
 *
 * This method is used to delete any existing participant_status given its id.
 *
 * @param array $params
 *   [id]
 *
 * @return array
 *   api result array
 */
function civicrm_api3_participant_status_type_delete($params)
{
    if (CRM_Event_BAO_ParticipantStatusType::deleteParticipantStatusType($params['id'])) {
        return civicrm_api3_create_success(TRUE);
    }
    return civicrm_api3_create_error(TRUE);
}
コード例 #4
0
/**
 * Creates a new household according to the specs
 */
function civicrm_api3_contact_create_household($params)
{
    if (empty($params['mode'])) {
        $params['mode'] = CRM_Householdmerge_Logic_Configuration::getHouseholdMode();
    }
    $head_id = NULL;
    switch ($params['mode']) {
        case 'hierarchy':
            $head_id = (int) $params['head_id'];
        case 'link':
            // get member IDs
            $member_ids = $params['member_ids'];
            if (is_string($member_ids)) {
                $member_ids = explode(',', $member_ids);
            }
            // sanitise member IDs
            $sanitised_member_ids = array();
            foreach ($member_ids as $member_id) {
                $sanitised_member_id = (int) $member_id;
                if ($sanitised_member_id) {
                    $sanitised_member_ids[] = $sanitised_member_id;
                }
            }
            // now pass the work on the the worker
            $worker = new CRM_Householdmerge_Logic_Worker();
            $household_id = $worker->createLinkedHousehold($params['household_name'], $sanitised_member_ids, $params['address'], $head_id);
            return civicrm_api3_create_success();
        default:
            return civicrm_api3_create_error("Contact.create_household cannot process mode '{$params['mode']}'.");
    }
}
コード例 #5
0
/**
 * Update function is basically a hack to get around issues listed in
 * http://issues.civicrm.org/jira/browse/CRM-12144
 *
 * It is not recommended & if update doesn't work & fix does then update will not be fixed
 *
 * To do this, perform a 'get' action to load the existing values, then merge in the updates
 * and call 'create' to save the revised entity.
 *
 * @param array $apiRequest array with keys:
 *  - entity: string
 *  - action: string
 *  - version: string
 *  - function: callback (mixed)
 *  - params: array, varies
 *
 * @return array|int|mixed
 */
function civicrm_api3_generic_update($apiRequest)
{
    //$key_id = strtolower ($apiRequest['entity'])."_id";
    $key_id = "id";
    if (!array_key_exists($key_id, $apiRequest['params'])) {
        return civicrm_api3_create_error("Mandatory parameter missing {$key_id}");
    }
    // @fixme
    // tests show that contribution works better with create
    // this is horrible but to make it work we'll just handle it separately
    if (strtolower($apiRequest['entity']) == 'contribution') {
        return civicrm_api($apiRequest['entity'], 'create', $apiRequest['params']);
    }
    $seek = array($key_id => $apiRequest['params'][$key_id], 'version' => $apiRequest['version']);
    $existing = civicrm_api($apiRequest['entity'], 'get', $seek);
    if ($existing['is_error']) {
        return $existing;
    }
    if ($existing['count'] > 1) {
        return civicrm_api3_create_error("More than one " . $apiRequest['entity'] . " with id " . $apiRequest['params'][$key_id]);
    }
    if ($existing['count'] == 0) {
        return civicrm_api3_create_error("No " . $apiRequest['entity'] . " with id " . $apiRequest['params'][$key_id]);
    }
    $existing = array_pop($existing['values']);
    $p = array_merge($existing, $apiRequest['params']);
    return civicrm_api($apiRequest['entity'], 'create', $p);
}
コード例 #6
0
/**
 * params must contain at least id=xx & {one of the fields from getfields}=value
 */
function civicrm_api3_generic_setValue($apiRequest)
{
    $entity = $apiRequest['entity'];
    $params = $apiRequest['params'];
    // we can't use _spec, doesn't work with generic
    civicrm_api3_verify_mandatory($params, NULL, array('id', 'field', 'value'));
    $id = $params['id'];
    if (!is_numeric($id)) {
        return civicrm_api3_create_error(ts('Please enter a number'), array('error_code' => 'NaN', 'field' => "id"));
    }
    $field = CRM_Utils_String::munge($params['field']);
    $value = $params['value'];
    $fields = civicrm_api($entity, 'getFields', array("version" => 3, "sequential"));
    // getfields error, shouldn't happen.
    if ($fields['is_error']) {
        return $fields;
    }
    $fields = $fields['values'];
    if (!array_key_exists($field, $fields)) {
        return civicrm_api3_create_error("Param 'field' ({$field}) is invalid. must be an existing field", array("error_code" => "invalid_field", "fields" => array_keys($fields)));
    }
    $def = $fields[$field];
    if (array_key_exists('required', $def) && empty($value)) {
        return civicrm_api3_create_error(ts("This can't be empty, please provide a value"), array("error_code" => "required", "field" => $field));
    }
    switch ($def['type']) {
        case 1:
            //int
            if (!is_numeric($value)) {
                return civicrm_api3_create_error("Param '{$field}' must be a number", array('error_code' => 'NaN'));
            }
        case 2:
            //string
            require_once "CRM/Utils/Rule.php";
            if (!CRM_Utils_Rule::xssString($value)) {
                return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS'));
            }
            if (array_key_exists('maxlength', $def)) {
                $value = substr($value, 0, $def['maxlength']);
            }
            break;
        case 16:
            //boolean
            $value = (bool) $value;
            break;
        case 4:
            //date
        //date
        default:
            return civicrm_api3_create_error("Param '{$field}' is of a type not managed yet. Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED'));
    }
    if (CRM_Core_DAO::setFieldValue(_civicrm_api3_get_DAO($entity), $id, $field, $value)) {
        $entity = array('id' => $id, $field => $value);
        CRM_Utils_Hook::post('edit', $entity, $id, $entity);
        return civicrm_api3_create_success($entity);
    } else {
        return civicrm_api3_create_error("error assigning {$field}={$value} for {$entity} (id={$id})");
    }
}
コード例 #7
0
ファイル: SubSlot.php プロジェクト: sushantpaste/civibooking
/**
 * Slot.Delete API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_sub_slot_delete($params)
{
    if (CRM_Booking_BAO_SubSlot::del($params['id'])) {
        return civicrm_api3_create_success($params, $params, 'SubSlot', 'delete');
    } else {
        return civicrm_api3_create_error('Could not delete SubSlot.');
    }
}
コード例 #8
0
/**
 * Slot.Delete API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_adhoc_charges_delete($params)
{
    if (CRM_Booking_BAO_AdhocCharges::del($params['id'])) {
        return civicrm_api3_create_success($params, $params, 'AdhocCharges', 'delete');
    } else {
        return civicrm_api3_create_error('Could not delete adhoc charges.');
    }
}
コード例 #9
0
ファイル: Booking.php プロジェクト: sushantpaste/civibooking
/**
 * Booking.Delete API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_Booking_delete($params)
{
    if (CRM_Booking_BAO_Booking::del($params['id'])) {
        return civicrm_api3_create_success($params, $params, 'booking', 'delete');
    } else {
        return civicrm_api3_create_error('Could not delete booking.');
    }
}
コード例 #10
0
/**
 * Create or update a volunteer assignment
 *
 * @param array $params  Associative array of property
 *                       name/value pairs to insert in new 'assignment'
 * @example AssignmentCreate.php Std Create example
 *
 * @return array api result array
 * {@getfields volunteer_assignment create}
 * @access public
 */
function civicrm_api3_volunteer_assignment_create($params)
{
    $result = CRM_Volunteer_BAO_Assignment::createVolunteerActivity($params);
    if ($result) {
        return civicrm_api3('volunteer_assignment', 'get', array('id' => $result));
    }
    return civicrm_api3_create_error('unable to create activity');
}
コード例 #11
0
ファイル: Dashboard.php プロジェクト: kidaa30/yes
/**
 * Delete a specified Dashlet.
 *
 * @param array $params
 *   Array holding 'id' of dashlet to be deleted.
 *
 * @return array
 */
function civicrm_api3_dashboard_delete($params)
{
    if (CRM_Core_BAO_Dashboard::deleteDashlet($params['id'])) {
        return civicrm_api3_create_success(1, $params, 'Dashboard', 'delete');
    } else {
        return civicrm_api3_create_error('Could not delete dashlet');
    }
}
コード例 #12
0
/**
 * Delete a pledge
 *
 * @param  array   $params           array included 'pledge_id' of pledge to delete
 *
 * @return boolean        true if success, else false
 * @static void
 * {@getfields pledge_delete}
 * @example PledgeDelete.php
 * @access public
 */
function civicrm_api3_pledge_delete($params)
{
    if (CRM_Pledge_BAO_Pledge::deletePledge($params['id'])) {
        return civicrm_api3_create_success(array('id' => $params['id']), $params, 'pledge', 'delete');
    } else {
        return civicrm_api3_create_error('Could not delete pledge');
    }
}
コード例 #13
0
ファイル: Save.php プロジェクト: robbrandt/civicrm-workflow
/**
 * PriceSet.FetchSection API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_workflow_save($params)
{
    if (!array_key_exists("data", $params) || !$params['data']) {
        throw new API_Exception('Missing parameter: data', 170);
    }
    if (!array_key_exists("wid", $params) || !$params['wid']) {
        throw new API_Exception('Missing parameter: wid', 170);
    }
    $wid = $params['wid'];
    $d = urldecode($params['data']);
    $data = parse_str($d);
    //I don't know why this is important, but it made things work.
    $try2 = parse_str($params['data']);
    //Hook in case someone wants to alter the data
    CRM_Workflow_hook::beforeSave($wid, $data);
    $transaction = new CRM_Core_Transaction();
    $dsql = "DELETE FROM civicrm_workflow_detail WHERE workflow_id = {$wid}";
    $dao =& CRM_Core_DAO::executeQuery($dsql);
    if (!empty($data)) {
        $sql = "INSERT INTO civicrm_workflow_detail ( workflow_id, entity_table, entity_id, `order`, breadcrumb, `next`, title) VALUES ";
        $i = 1;
        $vals = array();
        foreach ($data as $key => $d) {
            //$did = (strpos($id, ":")) ? 0 : $id;
            $eid = $d['entity_id'];
            $e_type = $d['entity_table'];
            $order = $d['order'];
            $breadcrumb = $d['breadcrumb'];
            $next = $d['next'];
            $title = $d['title'];
            $sql = $sql . "( %" . ($i + 0) . ", %" . ($i + 1) . ", %" . ($i + 2) . ", %" . ($i + 3) . ", %" . ($i + 4) . ", %" . ($i + 5) . ", %" . ($i + 6) . "),";
            //$vals[$i++] = array($did, 'Integer');
            $vals[$i++] = array($wid, 'Integer');
            $vals[$i++] = array($e_type, 'String');
            $vals[$i++] = array($eid, 'String');
            $vals[$i++] = array($order, 'Integer');
            $vals[$i++] = array($breadcrumb, 'String');
            $vals[$i++] = array($next, 'String');
            $vals[$i++] = array($title, 'String');
        }
        $sql = substr($sql, 0, -1);
        try {
            $dao =& CRM_Core_DAO::executeQuery($sql, $vals);
        } catch (Exception $e) {
            $transaction->rollback();
            return civicrm_api3_create_error($e . message);
        }
        //TODO: Better error checking?
        if ($dao->_lastError) {
            $transaction->rollback();
        } else {
            $transaction->commit();
            CRM_Workflow_hook::afterSave($wid, $data);
        }
    }
    $returnValues = array();
    return civicrm_api3_create_success($returnValues, $params, 'PriceSet', 'FetchSection');
}
コード例 #14
0
function civicrm_api3_training_get($params)
{
    $result = CRM_Training_BAO_Settings::getValues($params);
    if ($result['is_error'] == 0) {
        return civicrm_api3_create_success();
    } else {
        return civicrm_api3_create_error();
    }
}
コード例 #15
0
/**
 * Subscribe from mailing group.
 *
 * @param array $params
 *
 * @return array
 *   api result array
 */
function civicrm_api3_mailing_event_resubscribe_create($params)
{
    $groups = CRM_Mailing_Event_BAO_Resubscribe::resub_to_mailing($params['job_id'], $params['event_queue_id'], $params['hash']);
    if (count($groups)) {
        CRM_Mailing_Event_BAO_Resubscribe::send_resub_response($params['event_queue_id'], $groups, FALSE, $params['job_id']);
        return civicrm_api3_create_success($params);
    }
    return civicrm_api3_create_error('Queue event could not be found');
}
コード例 #16
0
function civicrm_api3_main_activity_debriefingcc($params)
{
    if (!isset($params['case_id'])) {
        return civicrm_api3_create_error('case_id is required');
    }
    $debriefing_cc = CRM_Mainactivity_DebriefingCC::singleton();
    $return = $debriefing_cc->getSummaryAndFollowUpByCaseId($params['case_id']);
    return $return;
}
function civicrm_api3_simple_mail_inline_attachment_getall($params)
{
    try {
        $result = CRM_Simplemail_BAO_SimpleMailInlineAttachment::getAll($params);
        return array('values' => $result);
    } catch (CRM_Extension_Exception $e) {
        $errorData = $e->getErrorData();
        return civicrm_api3_create_error($e->getMessage(), array(), $errorData['dao']);
    }
}
コード例 #18
0
ファイル: Group.php プロジェクト: hguru/224Civi
/**
 * create/update group
 *
 * This API is used to create new group or update any of the existing
 * In case of updating existing group, id of that particular grop must
 * be in $params array. Either id or name is required field in the
 * $params array
 *
 * @param array $params  (referance) Associative array of property
 *                       name/value pairs to insert in new 'group'
 *
 * @return array   returns id of the group created if success,
 *                 error message otherwise
 *@example GroupCreate.php
 *{@getfields group_create}
 * @access public
 */
function civicrm_api3_group_create($params)
{
    $group = CRM_Contact_BAO_Group::create($params);
    if (is_null($group)) {
        return civicrm_api3_create_error('Group not created');
    } else {
        $values = array();
        _civicrm_api3_object_to_array_unique_fields($group, $values[$group->id]);
        return civicrm_api3_create_success($values, $params, 'group', 'create', $group);
    }
}
コード例 #19
0
ファイル: OptionValue.php プロジェクト: hguru/224Civi
/**
 * Deletes an existing OptionValue
 *
 * @param  array  $params
 *
 * {@example OptionValueDelete.php 0}
 *
 * @return array Api result
 * {@getfields OptionValue_create}
 * @access public
 */
function civicrm_api3_option_value_delete($params)
{
    // we will get the option group id before deleting so we can flush pseudoconstants
    $optionGroupID = civicrm_api('option_value', 'getvalue', array('version' => 3, 'id' => $params['id'], 'return' => 'option_group_id'));
    if (CRM_Core_BAO_OptionValue::del((int) $params['id'])) {
        civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $optionGroupID));
        return civicrm_api3_create_success();
    } else {
        civicrm_api3_create_error('Could not delete OptionValue ' . $params['id']);
    }
}
コード例 #20
0
ファイル: DashboardContact.php プロジェクト: hguru/224Civi
function _civicrm_api3_dashboard_contact_check_params(&$params)
{
    $dashboard_id = CRM_Utils_Array::value('dashboard_id', $params);
    if ($dashboard_id) {
        $allDashlets = CRM_Core_BAO_Dashboard::getDashlets(TRUE, CRM_Utils_Array::value('check_permissions', $params, 0));
        if (!isset($allDashlets[$dashboard_id])) {
            return civicrm_api3_create_error('Invalid or inaccessible dashboard ID');
        }
    }
    return NULL;
}
コード例 #21
0
/**
 * @author Jaap Jansma (CiviCooP) <*****@*****.**>
 * @license http://www.gnu.org/licenses/agpl-3.0.html
 */
function civicrm_api3_my_emma_account_Syncgroup($params)
{
    if (!isset($params['id'])) {
        return civicrm_api3_create_error(ts('No ID given'));
    }
    $sync = new CRM_Myemma_Sync($params['id']);
    $sync->syncGroup($params['member_group_id']);
    $value['synchronisedGroups'] = $sync->synchronisedGroups;
    $values[] = $value;
    return civicrm_api3_create_success($values, $params, 'MyEmmaAccount', 'Synccontacts');
}
コード例 #22
0
/**
 * CiviRuleRule.Create API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 *
 *
 */
function civicrm_api3_civi_rule_rule_create($params)
{
    if (empty($params['twitter_name'])) {
        return civicrm_api3_create_error('Twitter_name can not be empty');
    }
    if (empty($params['description'])) {
        return civicrm_api3_create_error('Description can not be empty');
    }
    $returnValues = CRM_Civirules_BAO_Rule::add($params);
    return civicrm_api3_create_success($returnValues, $params, 'CiviRuleRule', 'Create');
}
コード例 #23
0
/**
 * create/update survey
 *
 * This API is used to create new survey or update any of the existing
 * In case of updating existing survey, id of that particular survey must
 * be in $params array.
 *
 * @param array $params  (referance) Associative array of property
 *                       name/value pairs to insert in new 'survey'
 *
 * @return array   survey array
 *
 * @access public
 */
function civicrm_api3_option_group_create($params)
{
    $ids = array();
    $bao = CRM_Core_BAO_OptionGroup::add($params, $ids);
    if (is_null($bao)) {
        return civicrm_api3_create_error('Entity not created');
    } else {
        $values = array();
        _civicrm_api3_object_to_array($bao, $values[$bao->id]);
        return civicrm_api3_create_success($values, $params, 'option_group', 'create', $bao);
    }
}
コード例 #24
0
ファイル: OptionValue.php プロジェクト: nielosz/civicrm-core
/**
 * Retrieve one or more option values.
 *
 * @param array $params
 *
 * @return array
 *   API result array
 */
function civicrm_api3_option_value_get($params)
{
    if (empty($params['option_group_id']) && !empty($params['option_group_name'])) {
        $opt = array('version' => 3, 'name' => $params['option_group_name']);
        $optionGroup = civicrm_api('OptionGroup', 'Get', $opt);
        if (empty($optionGroup['id'])) {
            return civicrm_api3_create_error("option group name does not correlate to a single option group");
        }
        $params['option_group_id'] = $optionGroup['id'];
    }
    return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
コード例 #25
0
ファイル: User.php プロジェクト: kewljuice/be.ctrl.nsynch
/**
 * Add an execute function for nsynch
 * http://booki.flossmanuals.net/civicrm-developer-guide/api/
 */
function civicrm_api3_nsynch_user($params)
{
    // execute function
    try {
        // execute
        CRM_Core_BAO_CMSUser::synchronize(FALSE);
        return civicrm_api3_create_success($values, $params);
    } catch (Exception $e) {
        // exception
        return civicrm_api3_create_error('Caught exception: ', $e->getMessage(), '\\n');
    }
}
コード例 #26
0
/**
 * @author Jaap Jansma (CiviCooP) <*****@*****.**>
 * @license http://www.gnu.org/licenses/agpl-3.0.html
 */
function civicrm_api3_my_emma_account_Synccontacts($params)
{
    if (!isset($params['id'])) {
        return civicrm_api3_create_error(ts('No ID given'));
    }
    $sync = new CRM_Myemma_Sync($params['id']);
    $sync->syncContacts($params['start'], $params['end']);
    $value['createdContacts'] = $sync->createdContacts;
    $value['updatedContacts'] = $sync->updatedContacts;
    $value['failedContacts'] = $sync->failedContacts;
    $value['removedContacts'] = $sync->removedContacts;
    $values[] = $value;
    return civicrm_api3_create_success($values, $params, 'MyEmmaAccount', 'Synccontacts');
}
コード例 #27
0
/**
 * YoteUp ProcessCounselor API
 *
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_nrm_processcounselor($params)
{
    // Get list of counselors
    $counsellorCount = civicrm_api3('Contact', 'getCount', array('contact_sub_type' => 'Counselors'));
    $counselorParams = array('contact_sub_type' => 'Counselors', 'return.email' => 1, 'return.custom_' . TERRITORY_COUNSELOR => 1, 'rowCount' => $counsellorCount);
    $counselors = civicrm_api3('Contact', 'get', $counselorParams);
    $ind = array();
    $is_error = 0;
    $messages = array("Report Mail Triggered...");
    if ($counselors['count'] >= 1) {
        $counselors = $counselors['values'];
        foreach ($counselors as $key => $value) {
            if (!empty($value['custom_' . TERRITORY_COUNSELOR])) {
                $ind[$key]['contact_id'] = $value['contact_id'];
                $ind[$key]['email'] = $value['email'];
            }
        }
        // Now email
        $instanceId = CRM_Utils_Array::value('instanceId', $params);
        $_REQUEST['instanceId'] = $instanceId;
        $_REQUEST['sendmail'] = CRM_Utils_Array::value('sendmail', $params, 1);
        // if cron is run from terminal --output is reserved, and therefore we would provide another name 'format'
        $_REQUEST['output'] = CRM_Utils_Array::value('format', $params, CRM_Utils_Array::value('output', $params, 'pdf'));
        $_REQUEST['reset'] = CRM_Utils_Array::value('reset', $params, 1);
        $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId);
        $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value');
        if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) {
            $obj = new CRM_Report_Page_Instance();
            $instanceInfo = array();
            CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo);
            if (!empty($instanceInfo['title'])) {
                $obj->assign('reportTitle', $instanceInfo['title']);
            } else {
                $obj->assign('reportTitle', $templateInfo['label']);
            }
            foreach ($ind as $key => $value) {
                $_REQUEST['email_to_send'] = $value['email'];
                $_GET['counsellor_id_value'] = $value['contact_id'];
                $wrapper = new CRM_Utils_Wrapper();
                $arguments = array('urlToSession' => array(array('urlVar' => 'instanceId', 'type' => 'Positive', 'sessionVar' => 'instanceId', 'default' => 'null')), 'ignoreKey' => TRUE);
                $messages[] = $wrapper->run($templateInfo['name'], NULL, $arguments);
            }
        }
    }
    if ($is_error == 0) {
        return civicrm_api3_create_success();
    } else {
        return civicrm_api3_create_error($messages);
    }
}
コード例 #28
0
/**
 * Delete a relationship.
 *
 * @param array $params
 *
 * @return array
 *   API Result Array
 */
function civicrm_api3_relationship_delete($params)
{
    if (!CRM_Utils_Rule::integer($params['id'])) {
        return civicrm_api3_create_error('Invalid value for relationship ID');
    }
    $relationBAO = new CRM_Contact_BAO_Relationship();
    $relationBAO->id = $params['id'];
    if (!$relationBAO->find(TRUE)) {
        return civicrm_api3_create_error('Relationship id is not valid');
    } else {
        $relationBAO->del($params['id']);
        return civicrm_api3_create_success('Deleted relationship successfully');
    }
}
/**
 * ContributionRecur.AmendDDAmount API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_contribution_recur_amendddamount($params)
{
    if (array_key_exists('contact_id', $params) && array_key_exists('amount', $params) && array_key_exists('contribution_recur_id', $params)) {
        $iContactId = $params['contact_id'];
        $iContributionRecurId = $params['contribution_recur_id'];
        $iAmount = $params['amount'];
        $iContributionPageId = null;
        $iRelatedContactId = null;
        $iOnBehalfDupeAlert = null;
        $aContribParam['contactID'] = $iContactId;
        $aContribParam['contributionRecurID'] = $iContributionRecurId;
        $aContribParam['contributionPageID'] = $iContributionPageId;
        $aContribParam['relatedContactID'] = $iRelatedContactID;
        $aContribParam['onBehalfDupeAlert'] = $iOnBehalfDupeAlert;
        $aParams = array('version' => '3', 'sequential' => '1', 'contact_id' => $iContactId);
        $aResult = civicrm_api('Membership', 'getsingle', $aParams);
        if (civicrm_error($aResult)) {
            $sMsg = "Error locating Membership record for contact id {$iContactId}";
            CRM_Core_Error::debug_log_message($sMsg);
            return civicrm_api3_create_error($sMsg);
        }
        $aContribParam['membershipID'] = $aResult['membership_id'];
        $aParams = array('version' => '3', 'sequential' => '1', 'contribution_recur_id' => $iContributionRecurId);
        $aResult = civicrm_api('Contribution', 'getsingle', $aParams);
        if (civicrm_error($aResult)) {
            $sMsg = "Error locating Contribution record for contribution_recur_id {$iContributionRecurId}";
            CRM_Core_Error::debug_log_message($sMsg);
            return civicrm_api3_create_error($sMsg);
        }
        $aContribParam['contributionID'] = $aResult['id'];
        $SmartDebitIPN = new CRM_Core_Payment_SmartDebitIPN();
        $oResult = $SmartDebitIPN->main('contribute', $aContribParam);
        if ($oResult === false) {
            $sMsg = "Error when changing DD Amount using Smart Debit.";
            CRM_Core_Error::debug_log_message($sMsg);
            return civicrm_api3_create_error($sMsg);
        }
        $aParams = array('version' => '3', 'sequential' => '1', 'id' => $iContributionRecurId, 'amount' => $iAmount);
        $aResult = civicrm_api('ContributionRecur', 'update', $aParams);
        if (civicrm_error($aResult)) {
            $sMsg = "Error when updating the Amount in ContributionRecur.";
            CRM_Core_Error::debug_log_message($sMsg);
            return civicrm_api3_create_error($sMsg);
        }
        return civicrm_api3_create_success();
    } else {
        throw new API_Exception('Missing Mandatory parameters: contact_id, contribution_id, and contribution_recur_id');
    }
}
コード例 #30
0
/**
 * Add or update a link between contribution and membership
 *
 * @param  array   $params           (reference ) input parameters
 *
 * @return array (reference )        membership_payment_id of created or updated record
 * {@getfields MembershipPayment_create}
 * @example MembershipPaymentCreate.php
 * @access public
 */
function civicrm_api3_membership_payment_create($params)
{
    require_once 'CRM/Core/Transaction.php';
    $transaction = new CRM_Core_Transaction();
    $mpDAO = new CRM_Member_DAO_MembershipPayment();
    $mpDAO->copyValues($params);
    $result = $mpDAO->save();
    if (is_a($result, 'CRM_Core_Error')) {
        $transaction->rollback();
        return civicrm_api3_create_error($result->_errors[0]['message']);
    }
    $transaction->commit();
    _civicrm_api3_object_to_array($mpDAO, $mpArray[$mpDAO->id]);
    return civicrm_api3_create_success($mpArray, $params);
}