From e6cc6fdc51d2c2632bc348fbd90f4674945af4aa Mon Sep 17 00:00:00 2001
From: Coleman Watts <coleman@civicrm.org>
Date: Tue, 30 Apr 2013 17:11:42 -0700
Subject: [PATCH] Remove v2 api CRM-9794

----------------------------------------
* CRM-9794: Remove API v2
  http://issues.civicrm.org/jira/browse/CRM-9794
---
 api/v2/Activity.php                   |  554 ---------
 api/v2/ActivityContact.php            |  117 --
 api/v2/ActivityType.php               |  113 --
 api/v2/Case.php                       |  626 ----------
 api/v2/Constant.php                   |  113 --
 api/v2/Contact.php                    |  855 -------------
 api/v2/Contribute.php                 |   41 -
 api/v2/Contribution.php               |  578 ---------
 api/v2/CustomGroup.php                |  247 ----
 api/v2/Domain.php                     |  107 --
 api/v2/EntityTag.php                  |  230 ----
 api/v2/Event.php                      |  264 ----
 api/v2/File.php                       |  331 -----
 api/v2/Group.php                      |  153 ---
 api/v2/GroupContact.php               |  199 ---
 api/v2/GroupNesting.php               |  155 ---
 api/v2/GroupOrganization.php          |  148 ---
 api/v2/Location.php                   |  978 ---------------
 api/v2/Mailer.php                     |  389 ------
 api/v2/Membership.php                 |  129 --
 api/v2/MembershipContact.php          |  418 -------
 api/v2/MembershipContributionLink.php |  131 --
 api/v2/MembershipStatus.php           |  260 ----
 api/v2/MembershipType.php             |  211 ----
 api/v2/Note.php                       |  221 ----
 api/v2/Participant.php                |  362 ------
 api/v2/ParticipantPayment.php         |  146 ---
 api/v2/Pledge.php                     |  470 --------
 api/v2/PledgePayment.php              |  483 --------
 api/v2/Relationship.php               |  470 --------
 api/v2/RelationshipType.php           |  194 ---
 api/v2/SurveyRespondant.php           |   91 --
 api/v2/Tag.php                        |  165 ---
 api/v2/UFGroup.php                    |  464 -------
 api/v2/UFJoin.php                     |  154 ---
 api/v2/utils.php                      |    8 -
 api/v2/utils.v2.php                   | 1599 -------------------------
 37 files changed, 12174 deletions(-)
 delete mode 100644 api/v2/Activity.php
 delete mode 100644 api/v2/ActivityContact.php
 delete mode 100644 api/v2/ActivityType.php
 delete mode 100644 api/v2/Case.php
 delete mode 100644 api/v2/Constant.php
 delete mode 100644 api/v2/Contact.php
 delete mode 100644 api/v2/Contribute.php
 delete mode 100644 api/v2/Contribution.php
 delete mode 100644 api/v2/CustomGroup.php
 delete mode 100644 api/v2/Domain.php
 delete mode 100644 api/v2/EntityTag.php
 delete mode 100644 api/v2/Event.php
 delete mode 100644 api/v2/File.php
 delete mode 100644 api/v2/Group.php
 delete mode 100644 api/v2/GroupContact.php
 delete mode 100644 api/v2/GroupNesting.php
 delete mode 100644 api/v2/GroupOrganization.php
 delete mode 100644 api/v2/Location.php
 delete mode 100644 api/v2/Mailer.php
 delete mode 100644 api/v2/Membership.php
 delete mode 100644 api/v2/MembershipContact.php
 delete mode 100644 api/v2/MembershipContributionLink.php
 delete mode 100644 api/v2/MembershipStatus.php
 delete mode 100644 api/v2/MembershipType.php
 delete mode 100644 api/v2/Note.php
 delete mode 100644 api/v2/Participant.php
 delete mode 100644 api/v2/ParticipantPayment.php
 delete mode 100644 api/v2/Pledge.php
 delete mode 100644 api/v2/PledgePayment.php
 delete mode 100644 api/v2/Relationship.php
 delete mode 100644 api/v2/RelationshipType.php
 delete mode 100644 api/v2/SurveyRespondant.php
 delete mode 100644 api/v2/Tag.php
 delete mode 100644 api/v2/UFGroup.php
 delete mode 100644 api/v2/UFJoin.php
 delete mode 100644 api/v2/utils.php
 delete mode 100644 api/v2/utils.v2.php

diff --git a/api/v2/Activity.php b/api/v2/Activity.php
deleted file mode 100644
index b7a84cadf4..0000000000
--- a/api/v2/Activity.php
+++ /dev/null
@@ -1,554 +0,0 @@
-<?php
-// $Id: Activity.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 activity functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Activity
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Activity.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Include common API util functions
- */
-require_once 'api/v2/utils.php';
-
-require_once 'CRM/Activity/BAO/Activity.php';
-require_once 'CRM/Core/DAO/OptionGroup.php';
-
-// require these to call new function names from deprecated ones in here
-require_once 'api/v2/ActivityType.php';
-require_once 'api/v2/ActivityContact.php';
-
-/**
- * Create a new Activity.
- *
- * Creates a new Activity record and returns the newly created
- * activity object (including the contact_id property). Minimum
- * required data values for the various contact_type are:
- *
- * Properties which have administratively assigned sets of values
- * If an unrecognized value is passed, an error
- * will be returned.
- *
- * Modules may invoke crm_get_contact_values($contactID) to
- * retrieve a list of currently available values for a given
- * property.
- *
- * @param array  $params       Associative array of property name/value
- *                             pairs to insert in new contact.
- * @param string $activity_type Which class of contact is being created.
- *            Valid values = 'SMS', 'Meeting', 'Event', 'PhoneCall'.
- * {@schema Activity/Activity.xml}
- *
- * @return CRM_Activity|CRM_Error Newly created Activity object
- */
-function &civicrm_activity_create(&$params) {
-  _civicrm_initialize();
-
-  $errors = array();
-
-  // check for various error and required conditions
-  $errors = _civicrm_activity_check_params($params, TRUE);
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  // processing for custom data
-  $values = array();
-  _civicrm_custom_format_params($params, $values, 'Activity');
-  if (!empty($values['custom'])) {
-    $params['custom'] = $values['custom'];
-  }
-
-  // create activity
-  $activity = CRM_Activity_BAO_Activity::create($params);
-
-  if (!is_a($activity, 'CRM_Core_Error') && isset($activity->id)) {
-    $activityArray = array('is_error' => 0);
-  }
-  else {
-    $activityArray = array('is_error' => 1);
-  }
-
-  _civicrm_object_to_array($activity, $activityArray);
-
-  return $activityArray;
-}
-
-/**
- *
- * @param <type> $params
- * @param <type> $returnCustom
- *
- * @return <type>
- */
-function civicrm_activity_get($params, $returnCustom = FALSE) {
-  _civicrm_initialize();
-
-  $activityId = CRM_Utils_Array::value('activity_id', $params);
-  if (empty($activityId)) {
-    return civicrm_create_error(ts("Required parameter not found"));
-  }
-
-  if (!is_numeric($activityId)) {
-    return civicrm_create_error(ts("Invalid activity Id"));
-  }
-
-  $activity = _civicrm_activity_get($activityId, $returnCustom);
-
-  if ($activity) {
-    return civicrm_create_success($activity);
-  }
-  else {
-    return civicrm_create_error(ts('Invalid Data'));
-  }
-}
-
-/**
- * Wrapper to make this function compatible with the REST API
- *
- * Obsolete now; if no one is using this, it should be removed. -- Wes Morgan
- */
-function civicrm_activity_get_contact($params) {
-  // TODO: Spit out deprecation warning here
-  return civicrm_activities_get_contact($params);
-}
-
-/**
- * Retrieve a set of activities, specific to given input params.
- *
- * @param  array  $params (reference ) input parameters.
- * @deprecated from 3.4 - use civicrm_activity_contact_get
- *
- * @return array (reference)  array of activities / error message.
- * @access public
- */
-function civicrm_activities_get_contact($params) {
-  // TODO: Spit out deprecation warning here
-  return civicrm_activity_contact_get($params);
-}
-
-/**
- * Update a specified activity.
- *
- * Updates activity with the values passed in the 'params' array. An
- * error is returned if an invalid id or activity Name is passed
- *
- * @param CRM_Activity $activity A valid Activity object
- * @param array       $params  Associative array of property
- *                             name/value pairs to be updated.
- *
- * @return CRM_Activity|CRM_Core_Error  Return the updated ActivtyType Object else
- *                                Error Object (if integrity violation)
- *
- * @access public
- *
- */
-function &civicrm_activity_update(&$params) {
-  $errors = array();
-  //check for various error and required conditions
-  $errors = _civicrm_activity_check_params($params);
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  // processing for custom data
-  $values = array();
-  _civicrm_custom_format_params($params, $values, 'Activity');
-  if (!empty($values['custom'])) {
-    $params['custom'] = $values['custom'];
-  }
-
-  $activity = CRM_Activity_BAO_Activity::create($params);
-  $activityArray = array();
-  _civicrm_object_to_array($activity, $activityArray);
-
-  return $activityArray;
-}
-
-/**
- * Delete a specified Activity.
- *
- * @param CRM_Activity $activity Activity object to be deleted
- *
- * @return void|CRM_Core_Error  An error if 'activityName or ID' is invalid,
- *                         permissions are insufficient, etc.
- *
- * @access public
- *
- */
-function civicrm_activity_delete(&$params) {
-  _civicrm_initialize();
-
-  $errors = array();
-
-  //check for various error and required conditions
-  $errors = _civicrm_activity_check_params($params);
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  if (CRM_Activity_BAO_Activity::deleteActivity($params)) {
-    return civicrm_create_success();
-  }
-  else {
-    return civicrm_create_error(ts('Could not delete activity'));
-  }
-}
-
-/**
- * Retrieve a specific Activity by Id.
- *
- * @param int $activityId
- *
- * @return array (reference)  activity object
- * @access public
- */
-function _civicrm_activity_get($activityId, $returnCustom = FALSE) {
-  $dao = new CRM_Activity_BAO_Activity();
-  $dao->id = $activityId;
-  if ($dao->find(TRUE)) {
-    $activity = array();
-    _civicrm_object_to_array($dao, $activity);
-
-    //also return custom data if needed.
-    if ($returnCustom && !empty($activity)) {
-      $customdata = civicrm_activity_custom_get(array(
-        'activity_id' => $activityId,
-          'activity_type_id' => $activity['activity_type_id'],
-        ));
-      $activity = array_merge($activity, $customdata);
-    }
-
-    return $activity;
-  }
-  else {
-    return FALSE;
-  }
-}
-
-/**
- * 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 (is_numeric($id)) {
-          $valueIds[$id] = $id;
-        }
-      }
-    }
-    elseif (!is_numeric($value)) {
-      return civicrm_create_error(ts('Invalid %1 Contact Id', array(
-        1 => ucfirst(
-              $key
-            ))));
-    }
-
-    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))));
-    }
-  }
-
-  if (!$addMode && !isset($params['id'])) {
-    return civicrm_create_error(ts('Required parameter "id" not found'));
-  }
-
-  // check for source contact id
-  if ($addMode && empty($params['source_contact_id'])) {
-    return civicrm_create_error(ts('Missing Source Contact'));
-  }
-
-  // check for activity subject if add mode
-  if ($addMode && !isset($params['subject'])) {
-    return civicrm_create_error(ts('Missing Subject'));
-  }
-
-  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'));
-      }
-      elseif ($activityTypeId && ($activityTypeId != $activityNameId)) {
-        return civicrm_create_error(ts('Mismatch in Activity'));
-      }
-      $params['activity_type_id'] = $activityNameId;
-    }
-    elseif ($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'], $activityPriority)) {
-      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)'));
-  }
-
-  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;
-}
-
-/**
- * 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);
-}
-
-/**
- *
- * @param <type> $result
- * @param <type> $activityTypeID
- *
- * @return <type>
- */
-function _civicrm_activity_buildmailparams($result, $activityTypeID) {
-  // get ready for collecting data about activity to be created
-  $params = array();
-
-  $params['activity_type_id'] = $activityTypeID;
-  $params['status_id'] = 2;
-  $params['source_contact_id'] = $params['assignee_contact_id'] = $result['from']['id'];
-  $params['target_contact_id'] = array();
-  $keys = array('to', 'cc', 'bcc');
-  foreach ($keys as $key) {
-    if (is_array($result[$key])) {
-      foreach ($result[$key] as $key => $keyValue) {
-        if (!empty($keyValue['id'])) {
-          $params['target_contact_id'][] = $keyValue['id'];
-        }
-      }
-    }
-  }
-  $params['subject'] = $result['subject'];
-  $params['activity_date_time'] = $result['date'];
-  $params['details'] = $result['body'];
-
-  for ($i = 1; $i <= 5; $i++) {
-    if (isset($result["attachFile_$i"])) {
-      $params["attachFile_$i"] = $result["attachFile_$i"];
-    }
-  }
-
-  return $params;
-}
-
-/**
- *
- * @param <type> $file
- * @param <type> $activityTypeID
- *
- * @return <type>
- * @deprecated since 3.4 use civicrm_activity_processemail
- */
-function civicrm_activity_process_email($file, $activityTypeID) {
-  // TODO: Spit out deprecation warning here
-  return civicrm_activity_processemail($file, $activityTypeID);
-}
-
-/**
- * @deprecated since 3.4 use civicrm_activity_type_get
- *
- * @return <type>
- */
-function civicrm_activity_get_types() {
-  // TODO: Spit out deprecation warning here
-  return civicrm_activity_type_get();
-}
-
-/**
- * Function retrieve activity custom data.
- *
- * @param  array  $params key => value array.
- *
- * @return array  $customData activity custom data
- *
- * @access public
- */
-function civicrm_activity_custom_get($params) {
-
-  $customData = array();
-  if (!CRM_Utils_Array::value('activity_id', $params)) {
-    return $customData;
-  }
-
-  require_once 'CRM/Core/BAO/CustomGroup.php';
-  $groupTree = &CRM_Core_BAO_CustomGroup::getTree('Activity',
-    CRM_Core_DAO::$_nullObject,
-    $params['activity_id'],
-    NULL,
-    CRM_Utils_Array::value('activity_type_id', $params)
-  );
-  //get the group count.
-  $groupCount = 0;
-  foreach ($groupTree as $key => $value) {
-    if ($key === 'info') {
-      continue;
-    }
-    $groupCount++;
-  }
-  $formattedGroupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree,
-    $groupCount,
-    CRM_Core_DAO::$_nullObject
-  );
-  $defaults = array();
-  CRM_Core_BAO_CustomGroup::setDefaults($formattedGroupTree, $defaults);
-  if (!empty($defaults)) {
-    foreach ($defaults as $key => $val) {
-      $customData[$key] = $val;
-    }
-  }
-
-  return $customData;
-}
-
diff --git a/api/v2/ActivityContact.php b/api/v2/ActivityContact.php
deleted file mode 100644
index 2eeb33e329..0000000000
--- a/api/v2/ActivityContact.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-// $Id: ActivityContact.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 activity contact functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Activity
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: ActivityContact.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-
-require_once 'CRM/Activity/BAO/Activity.php';
-
-/**
- * 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'));
-  }
-}
-
-/**
- * Retrieve a set of Activities specific to given contact Id.
- *
- * @param int $contactID.
- *
- * @return array (reference)  array of activities.
- * @access public
-
- */
-function &_civicrm_activities_get($contactID, $type = 'all') {
-  $activities = CRM_Activity_BAO_Activity::getContactActivity($contactID);
-
-  //get the custom data.
-  if (is_array($activities) && !empty($activities)) {
-    require_once 'api/v2/Activity.php';
-    foreach ($activities as $activityId => $values) {
-      $customParams = array(
-        'activity_id' => $activityId,
-        'activity_type_id' => CRM_Utils_Array::value('activity_type_id', $values),
-      );
-
-      $customData = civicrm_activity_custom_get($customParams);
-
-      if (is_array($customData) && !empty($customData)) {
-        $activities[$activityId] = array_merge($activities[$activityId], $customData);
-      }
-    }
-  }
-
-  return $activities;
-}
-
diff --git a/api/v2/ActivityType.php b/api/v2/ActivityType.php
deleted file mode 100644
index 3698bcc1b3..0000000000
--- a/api/v2/ActivityType.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-// $Id: ActivityType.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * Definition of the ActivityType part of the CRM API.
- * More detailed documentation can be found
- * {@link http://objectledge.org/confluence/display/CRM/CRM+v1.0+Public+APIs
- * here}
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Activity
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * $Id: ActivityType.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Include common API util functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Function to retrieve activity types
- *
- * @return array $activityTypes activity types keyed by id
- * @access public
- */
-function civicrm_activity_type_get() {
-  require_once 'CRM/Core/OptionGroup.php';
-  $activityTypes = CRM_Core_OptionGroup::values('activity_type');
-  return $activityTypes;
-}
-
-/**
- * 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;
-}
-
-/**
- * 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);
-}
-
diff --git a/api/v2/Case.php b/api/v2/Case.php
deleted file mode 100644
index 8836376a3f..0000000000
--- a/api/v2/Case.php
+++ /dev/null
@@ -1,626 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 Case functions
- * Developed by woolman.org
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Case
- * @copyright CiviCRM LLC (c) 2004-2013
- *
- */
-
-require_once 'api/v2/utils.php';
-require_once 'CRM/Case/BAO/Case.php';
-require_once 'CRM/Case/PseudoConstant.php';
-
-/**
- * Open a new case, add client and manager roles, and add standard timeline
- *
- * @param  array(
-    //REQUIRED:
- *                  'case_type_id'     => int OR 'case_type' => str (provide one or the other)
- *                  'contact_id'       => int // case client
- *                  'creator_id'       => int // case manager
- *                  'subject'          => str
- *                  'medium_id'        => int // see civicrm option values for possibilities
- *
- *                //OPTIONAL
- *                  'status_id'        => int // defaults to 1 "ongoing"
- *                  'location'         => str
- *                  'start_date'       => str datestamp // defaults to: date('YmdHis')
- *                  'duration'         => int // in minutes
- *                  'details'          => str // html format
- *
- * @return sucessfully opened case
- *
- * @access public
- */
-function civicrm_case_create(&$params) {
-  _civicrm_initialize();
-
-  //check parameters
-  $errors = _civicrm_case_check_params($params, 'create');
-
-  if ($errors) {
-
-    return $errors;
-  }
-
-  _civicrm_case_format_params($params, 'create');
-  // If format_params didn't find what it was looking for, return error
-  if (!$params['case_type_id']) {
-    return civicrm_create_error(ts('Invalid case_type. No such case type exists.'));
-  }
-  if (!$params['case_type']) {
-    return civicrm_create_error(ts('Invalid case_type_id. No such case type exists.'));
-  }
-
-  // format input with value separators
-  $sep = CRM_Core_DAO::VALUE_SEPARATOR;
-  $newParams = array(
-    'case_type_id' => $sep . $params['case_type_id'] . $sep,
-    'creator_id' => $params['creator_id'],
-    'status_id' => $params['status_id'],
-    'start_date' => $params['start_date'],
-    'subject' => $params['subject'],
-  );
-
-  $case = CRM_Case_BAO_Case::create($newParams);
-
-  if (!$case) {
-    return civicrm_create_error(ts('Case not created. Please check your input params.'));
-  }
-
-  // Add client role
-  $contactParams = array(
-    'case_id' => $case->id,
-    'contact_id' => $params['contact_id'],
-  );
-
-  CRM_Case_BAO_Case::addCaseToContact($contactParams);
-
-  // Initialize XML processor with $params
-  require_once 'CRM/Case/XMLProcessor/Process.php';
-  $xmlProcessor = new CRM_Case_XMLProcessor_Process();
-  $xmlProcessorParams = array(
-    'clientID' => $params['contact_id'],
-    'creatorID' => $params['creator_id'],
-    'standardTimeline' => 1,
-    'activityTypeName' => 'Open Case',
-    'caseID' => $case->id,
-    'subject' => $params['subject'],
-    'location' => $params['location'],
-    'activity_date_time' => $params['start_date'],
-    'duration' => $params['duration'],
-    'medium_id' => $params['medium_id'],
-    'details' => $params['details'],
-    'custom' => array(),
-  );
-
-  // Do it! :-D
-  $xmlProcessor->run($params['case_type'], $xmlProcessorParams);
-
-  // status msg
-  $params['statusMsg'] = ts('Case opened successfully.');
-
-  // return case
-  $details = _civicrm_case_read($case->id);
-  return civicrm_create_success($details);
-}
-
-/**
- * Get details of a particular case, or search for cases, depending on params
- *
- * Please provide one (and only one) of the four get/search parameters:
- *
- * @param array(
-    'case_id'    => if set, will get all available info about a case, including contacts and activities
- *
- *                // if no case_id provided, this function will use one of the following search parameters:
- *               'client_id'   => finds all cases with a specific client
- *               'activity_id' => returns the case containing a specific activity
- *               'contact_id'  => finds all cases associated with a contact (in any role, not just client)
- *
- *
- * @return (get mode, case_id provided): Array with case details, case roles, case activity ids, (search mode, case_id not provided): Array of cases found
- * @access public
- */
-function civicrm_case_get(&$params) {
-  _civicrm_initialize();
-
-  //get mode
-  if ($caseId = $params['case_id']) {
-    //validate param
-    if (!is_numeric($caseId)) {
-      return civicrm_create_error(ts('Invalid parameter: case_id. Must provide a numeric value.'));
-    }
-
-    $case = _civicrm_case_read($caseId);
-
-    if ($case) {
-      //get case contacts
-      $contacts         = CRM_Case_BAO_Case::getcontactNames($caseId);
-      $relations        = CRM_Case_BAO_Case::getRelatedContacts($caseId);
-      $case['contacts'] = array_merge($contacts, $relations);
-
-      //get case activities
-
-      $query = "SELECT activity_id FROM civicrm_case_activity WHERE case_id = $caseId";
-      $dao = CRM_Core_DAO::executeQuery($query);
-
-      $case['activities'] = array();
-
-      while ($dao->fetch()) {
-        $case['activities'][] = $dao->activity_id;
-      }
-
-      return civicrm_create_success($case);
-    }
-    else {
-      return civicrm_create_success(array());
-    }
-  }
-
-  //search by client
-  if ($client = $params['client_id']) {
-
-    if (!is_numeric($client)) {
-      return civicrm_create_error(ts('Invalid parameter: client_id. Must provide a numeric value.'));
-    }
-
-    $ids = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($client, TRUE);
-
-    if (empty($ids)) {
-
-      return civicrm_create_success(array());
-    }
-
-    $cases = array();
-
-    foreach ($ids as $id) {
-      $cases[$id] = _civicrm_case_read($id);
-    }
-    return civicrm_create_success($cases);
-  }
-
-  //search by activity
-  if ($act = $params['activity_id']) {
-
-    if (!is_numeric($act)) {
-      return civicrm_create_error(ts('Invalid parameter: activity_id. Must provide a numeric value.'));
-    }
-
-    $sql = "SELECT case_id FROM civicrm_case_activity WHERE activity_id = $act";
-
-    $caseId = CRM_Core_DAO::singleValueQuery($sql);
-
-    if (!$caseId) {
-      return civicrm_create_success(array());
-    }
-
-    $case = array($caseId => _civicrm_case_read($caseId));
-
-    return civicrm_create_success($case);
-  }
-
-  //search by contacts
-  if ($contact = $params['contact_id']) {
-    if (!is_numeric($contact)) {
-      return civicrm_create_error(ts('Invalid parameter: contact_id.  Must provide a numeric value.'));
-    }
-
-    $sql = "
-SELECT DISTINCT case_id
-  FROM civicrm_relationship
- WHERE (contact_id_a = $contact
-    OR contact_id_b = $contact)
-   AND case_id IS NOT NULL";
-    $dao = CRM_Core_DAO::executeQuery($sql);
-
-    $cases = array();
-
-    while ($dao->fetch()) {
-      $cases[$dao->case_id] = _civicrm_case_read($dao->case_id);
-    }
-
-    return civicrm_create_success($cases);
-  }
-
-  return civicrm_create_error(ts('Missing required parameter. Must provide case_id, client_id, activity_id, or contact_id.'));
-}
-
-/**
- * Create new activity for a case
- *
- * @param array(
-    //REQUIRED:
- *                         'case_id'                     => int
- *                         'activity_type_id'            => int
- *                         'source_contact_id'           => int
- *                         'status_id'                   => int
- *                         'medium_id'                   => int // see civicrm option values for possibilities
- *
- *               //OPTIONAL
- *                         'subject'                     => str
- *                         'activity_date_time'          => date string // defaults to: date('YmdHis')
- *                         'details                      => str
- *
- * @return activity id
- *
- * NOTE: For other case activity functions (update, delete, etc) use the Activity API
- *
- */
-function civicrm_case_activity_create(&$params) {
-  _civicrm_initialize();
-
-  //check parameters
-  $errors = _civicrm_case_check_params($params, 'activity');
-
-  _civicrm_case_format_params($params, 'activity');
-
-  if ($errors) {
-    return $errors;
-  }
-  require_once 'CRM/Activity/BAO/Activity.php';
-
-  $activity = CRM_Activity_BAO_Activity::create($params);
-
-  $caseParams = array(
-    'activity_id' => $activity->id,
-    'case_id' => $params['case_id'],
-  );
-
-  CRM_Case_BAO_Case::processCaseActivity($caseParams);
-
-  return civicrm_create_success($activity->id);
-}
-
-/**
- * Update a specified case.
- *
- * @param  array(
-    //REQUIRED:
- *                  'case_id'          => int
- *
- *                //OPTIONAL
- *                  'status_id'        => int
- *                  'start_date'       => str datestamp
- *                  'contact_id'       => int // case client
- *                  'creator_id'       => int // case manager
- *
- * @return Updated case
- *
- * @access public
- *
- */
-function civicrm_case_update(&$params) {
-  _civicrm_initialize();
-
-  $errors = array();
-  //check for various error and required conditions
-  $errors = _civicrm_case_check_params($params, 'update');
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  // return error if modifing creator id
-  if (array_key_exists('creator_id', $params)) {
-    return civicrm_create_error(ts('You have no provision to update creator id'));
-  }
-
-  $mCaseId = array();
-  $origContactIds = array();
-
-  // get original contact id and creator id of case
-  if ($params['contact_id']) {
-    $origContactIds = CRM_Case_BAO_Case::retrieveContactIdsByCaseId($params['case_id']);
-    $origContactId = $origContactIds[1];
-  }
-
-  if (count($origContactIds) > 1) {
-    // check valid orig contact id
-    if ($params['orig_contact_id'] && !in_array($params['orig_contact_id'], $origContactIds)) {
-      return civicrm_create_error(ts('Invalid case contact id (orig_contact_id)'));
-    }
-    elseif (!$params['orig_contact_id']) {
-      return civicrm_create_error(ts('Case is linked with more than one contact id. Provide the required params orig_contact_id to be replaced'));
-    }
-    $origContactId = $params['orig_contact_id'];
-  }
-
-  // check for same contact id for edit Client
-  if ($params['contact_id'] && !in_array($params['contact_id'], $origContactIds)) {
-    $mCaseId = CRM_Case_BAO_Case::mergeCases($params['contact_id'], $params['case_id'],
-      $origContactId, NULL, TRUE
-    );
-  }
-
-  if (CRM_Utils_Array::value('0', $mCaseId)) {
-    $params['case_id'] = $mCaseId[0];
-  }
-
-  $dao = new CRM_Case_BAO_Case();
-  $dao->id = $params['case_id'];
-
-  $dao->copyValues($params);
-  $dao->save();
-
-  $case = array();
-
-  _civicrm_object_to_array($dao, $case);
-
-  return civicrm_create_success($case);
-}
-
-/**
- * Delete a specified case.
- *
- * @param  array(
-    //REQUIRED:
- *                  'case_id'           => int
- *
- *                //OPTIONAL
- *                  'move_to_trash'     => bool (defaults to false)
- *
- * @return boolean: true if success, else false
- *
- * @access public
- */
-function civicrm_case_delete(&$params) {
-  _civicrm_initialize();
-
-  //check parameters
-  $errors = _civicrm_case_check_params($params, 'delete');
-
-  if ($errors) {
-
-    return $errors;
-  }
-
-  if (CRM_Case_BAO_Case::deleteCase($params['case_id'], $params['move_to_trash'])) {
-    return civicrm_create_success(ts('Case Deleted'));
-  }
-  else {
-    return civicrm_create_error(ts('Could not delete case.'));
-  }
-}
-
-/***********************************/
-/*                                 */
-
-
-/*     INTERNAL FUNCTIONS          */
-
-
-/*                                 */
-
-/***********************************/
-
-/**
- * Internal function to retrieve a case.
- *
- * @param int $caseId
- *
- * @return array (reference) case object
- *
- */
-function _civicrm_case_read($caseId) {
-
-  $dao = new CRM_Case_BAO_Case();
-  $dao->id = $caseId;
-  if ($dao->find(TRUE)) {
-    $case = array();
-    _civicrm_object_to_array($dao, $case);
-
-    //handle multi-value case type
-    $sep = CRM_Core_DAO::VALUE_SEPARATOR;
-    $case['case_type_id'] = trim(str_replace($sep, ',', $case['case_type_id']), ',');
-
-    return $case;
-  }
-  else {
-    return FALSE;
-  }
-}
-
-/**
- * Internal function to format params for processing
- */
-function _civicrm_case_format_params(&$params, $mode) {
-  switch ($mode) {
-    case 'create':
-      // set defaults
-      if (!$params['status_id']) {
-        $params['status_id'] = 1;
-      }
-      if (!$params['start_date']) {
-        $params['start_date'] = date('YmdHis');
-      }
-
-      // figure out case type id, if not supplied
-      if (!$params['case_type_id']) {
-        $sql = "
-SELECT  ov.value
-  FROM  civicrm_option_value ov
-  JOIN  civicrm_option_group og ON og.id = ov.option_group_id
- WHERE  ov.label = %1 AND og.name = 'case_type'";
-
-        $values = array(1 => array($params['case_type'], 'String'));
-        $params['case_type_id'] = CRM_Core_DAO::singleValueQuery($sql, $values);
-      }
-      elseif (!$params['case_type']) {
-        // figure out case type, if not supplied
-        $sql = "
-SELECT  ov.name
-  FROM  civicrm_option_value ov
-  JOIN  civicrm_option_group og ON og.id = ov.option_group_id
- WHERE  ov.value = %1 AND og.name = 'case_type'";
-
-        $values = array(1 => array($params['case_type_id'], 'Integer'));
-        $params['case_type'] = CRM_Core_DAO::singleValueQuery($sql, $values);
-      }
-      break;
-
-    case 'activity':
-      //set defaults
-      if (!$params['activity_date_time']) {
-        $params['activity_date_time'] = date('YmdHis');
-      }
-      break;
-  }
-}
-
-/**
- * Internal function to check for valid parameters
- */
-function _civicrm_case_check_params(&$params, $mode = NULL) {
-
-  // return error if we do not get any params
-  if (is_null($params) || !is_array($params) || empty($params)) {
-    return civicrm_create_error(ts('Invalid or missing input parameters. Must provide an associative array.'));
-  }
-
-  switch ($mode) {
-    case 'create':
-
-      if (!$params['case_type_id'] && !$params['case_type']) {
-
-        return civicrm_create_error(ts('Missing input parameters. Must provide case_type or case_type_id.'));
-      }
-
-      $required = array(
-        'contact_id' => 'num',
-        'status_id' => 'num',
-        'medium_id' => 'num',
-        'creator_id' => 'num',
-        'subject' => 'str',
-      );
-
-      if (!$params['case_type']) {
-
-        $required['case_type_id'] = 'num';
-      }
-      if (!$params['case_type_id']) {
-        $required['case_type'] = 'str';
-      }
-      break;
-
-    case 'activity':
-
-      $required = array(
-        'case_id' => 'num',
-        'activity_type_id' => 'num',
-        'source_contact_id' => 'num',
-        'status_id' => 'num',
-        'medium_id' => 'num',
-      );
-      break;
-
-    case 'update':
-    case 'delete':
-      $required = array('case_id' => 'num');
-      break;
-
-    default:
-      return NULL;
-  }
-
-  foreach ($required as $req => $type) {
-
-    if (!$params[$req]) {
-
-      return civicrm_create_error(ts('Missing required parameter: %1.', array(1 => $req)));
-    }
-
-    if ($type == 'num' && !is_numeric($params[$req])) {
-
-      return civicrm_create_error(ts('Invalid parameter: %1. Must provide a numeric value.', array(1 => $req)));
-    }
-
-    if ($type == 'str' && !is_string($params[$req])) {
-
-      return civicrm_create_error(ts('Invalid parameter: %1. Must provide a string.', array(1 => $req)));
-    }
-  }
-
-  $caseTypes = CRM_Case_PseudoConstant::caseType();
-
-  if (CRM_Utils_Array::value('case_type', $params) && !in_array($params['case_type'], $caseTypes)) {
-    return civicrm_create_error(ts('Invalid Case Type'));
-  }
-
-  if (CRM_Utils_Array::value('case_type_id', $params)) {
-    if (!array_key_exists($params['case_type_id'], $caseTypes)) {
-      return civicrm_create_error(ts('Invalid Case Type Id'));
-    }
-
-    // check case type miss match error
-    if (CRM_Utils_Array::value('case_type', $params) &&
-      $params['case_type_id'] != array_search($params['case_type'], $caseTypes)
-    ) {
-      return civicrm_create_error(ts('Case type and case type id mismatch'));
-    }
-
-    $sep = CRM_Case_BAO_Case::VALUE_SEPARATOR;
-    $params['case_type'] = $caseTypes[$params['case_type_id']];
-    $params['case_type_id'] = $sep . $params['case_type_id'] . $sep;
-  }
-
-  // check for valid status id
-  $caseStatusIds = CRM_Case_PseudoConstant::caseStatus();
-  if (CRM_Utils_Array::value('status_id', $params) &&
-    !array_key_exists($params['status_id'], $caseStatusIds) &&
-    $mode != 'activity'
-  ) {
-    return civicrm_create_error(ts('Invalid Case Status Id'));
-  }
-
-  // check for valid medium id
-  $encounterMedium = CRM_Core_OptionGroup::values('encounter_medium');
-  if (CRM_Utils_Array::value('medium_id', $params) &&
-    !array_key_exists($params['medium_id'], $encounterMedium)
-  ) {
-    return civicrm_create_error(ts('Invalid Case Medium Id'));
-  }
-
-  $contactIds = array('creator' => CRM_Utils_Array::value('creator_id', $params),
-    'contact' => CRM_Utils_Array::value('contact_id', $params),
-  );
-  foreach ($contactIds as $key => $value) {
-    if ($value &&
-      !CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'id')
-    ) {
-      return civicrm_create_error(ts('Invalid %1 Id', array(1 => ucfirst($key))));
-    }
-  }
-}
-
diff --git a/api/v2/Constant.php b/api/v2/Constant.php
deleted file mode 100644
index 963315661a..0000000000
--- a/api/v2/Constant.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-// $Id: Constant.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for CiviCRM APIv2 pseudoconstants
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Constant
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Constant.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- * 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'));
-}
-
diff --git a/api/v2/Contact.php b/api/v2/Contact.php
deleted file mode 100644
index 44aa1adedb..0000000000
--- a/api/v2/Contact.php
+++ /dev/null
@@ -1,855 +0,0 @@
-<?php
-// $Id: Contact.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * new version of civicrm apis. See blog post at
- * http://civicrm.org/node/131
- * @todo Write sth
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Contact
- * @copyright CiviCRM LLC (c) 2004-2013
- * $Id: Contact.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Include common API util functions
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Contact/BAO/Contact.php';
-
-/**
- * @todo Write sth
- *
- * @param  array   $params           (reference ) input parameters
- *
- * Allowed @params array keys are:
- * {@schema Contact/Contact.xml}
- * {@schema Core/Address.xml}}
- *
- * @return array (reference )        contact_id of created or updated contact
- *
- * @static void
- * @access public
- */
-function civicrm_contact_create(&$params) {
-  // call update and tell it to create a new contact
-  _civicrm_initialize();
-  $errorScope = CRM_Core_TemporaryErrorScope::useException();
-  try {
-    civicrm_api_check_permission(__FUNCTION__, $params, TRUE);
-    $create_new = TRUE;
-    return civicrm_contact_update($params, $create_new);
-  }
-  catch(Exception$e) {
-    return civicrm_create_error($e->getMessage());
-  }
-}
-
-/**
- * @todo Write sth
- * @todo Serious FIXMES in the code! File issues.
- */
-function civicrm_contact_update(&$params, $create_new = FALSE) {
-  _civicrm_initialize();
-  try {
-    civicrm_api_check_permission(__FUNCTION__, $params, TRUE);
-  }
-  catch(Exception$e) {
-    return civicrm_create_error($e->getMessage());
-  }
-  require_once 'CRM/Utils/Array.php';
-  $entityId = CRM_Utils_Array::value('contact_id', $params, NULL);
-  if (!CRM_Utils_Array::value('contact_type', $params) &&
-    $entityId
-  ) {
-    $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($entityId);
-  }
-  $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE);
-  $values = civicrm_contact_check_params($params, $dupeCheck);
-  if ($values) {
-    return $values;
-  }
-
-  if ($create_new) {
-    // Make sure nothing is screwed up before we create a new contact
-    if (!empty($entityId)) {
-      return civicrm_create_error('Cannot create new contact when contact_id is present');
-    }
-    if (empty($params['contact_type'])) {
-      return civicrm_create_error('Contact Type not specified');
-    }
-
-    // If we get here, we're ready to create a new contact
-    if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
-      require_once 'CRM/Core/BAO/LocationType.php';
-      $defLocType = CRM_Core_BAO_LocationType::getDefault();
-      $params['email'] = array(
-        1 => array('email' => $email,
-          'is_primary' => 1,
-          'location_type_id' => ($defLocType->id) ? $defLocType->id : 1,
-        ),
-      );
-    }
-  }
-
-  if ($homeUrl = CRM_Utils_Array::value('home_url', $params)) {
-    require_once 'CRM/Core/PseudoConstant.php';
-    $websiteTypes = CRM_Core_PseudoConstant::websiteType();
-    $params['website'] = array(1 => array('website_type_id' => key($websiteTypes),
-        'url' => $homeUrl,
-      ),
-    );
-  }
-  // FIXME: Some legacy support cruft, should get rid of this in 3.1
-  $change = array(
-    'individual_prefix' => 'prefix',
-    'prefix' => 'prefix_id',
-    'individual_suffix' => 'suffix',
-    'suffix' => 'suffix_id',
-    'gender' => 'gender_id',
-  );
-
-  foreach ($change as $field => $changeAs) {
-    if (array_key_exists($field, $params)) {
-      $params[$changeAs] = $params[$field];
-      unset($params[$field]);
-    }
-  }
-  // End legacy support cruft
-
-  if (isset($params['suffix_id']) &&
-    !(is_numeric($params['suffix_id']))
-  ) {
-    $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix());
-  }
-
-  if (isset($params['prefix_id']) &&
-    !(is_numeric($params['prefix_id']))
-  ) {
-    $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix());
-  }
-
-  if (isset($params['gender_id'])
-    && !(is_numeric($params['gender_id']))
-  ) {
-    $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender());
-  }
-
-  $error = _civicrm_greeting_format_params($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $values = array();
-
-  if (!($csType = CRM_Utils_Array::value('contact_sub_type', $params)) &&
-    $entityId
-  ) {
-    require_once 'CRM/Contact/BAO/Contact.php';
-    $csType = CRM_Contact_BAO_Contact::getContactSubType($entityId);
-  }
-
-  $customValue = civicrm_contact_check_custom_params($params, $csType);
-
-  if ($customValue) {
-    return $customValue;
-  }
-  _civicrm_custom_format_params($params, $values, $params['contact_type'], $entityId);
-
-  $params = array_merge($params, $values);
-
-  $contact = &_civicrm_contact_update($params, $entityId);
-
-  if (is_a($contact, 'CRM_Core_Error')) {
-    return civicrm_create_error($contact->_errors[0]['message']);
-  }
-  else {
-    $values = array();
-    $values['contact_id'] = $contact->id;
-    $values['is_error'] = 0;
-  }
-
-  return $values;
-}
-
-/**
- * Add or update a contact. If a dupe is found, check for
- * ignoreDupe flag to ignore or return error
- *
- * @deprecated deprecated since version 2.2.3; use civicrm_contact_create or civicrm_contact_update instead
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        contact_id of created or updated contact
- * @static void
- * @access public
- */
-function &civicrm_contact_add(&$params) {
-  _civicrm_initialize();
-
-  $contactID = CRM_Utils_Array::value('contact_id', $params);
-
-  if (!empty($contactID)) {
-    $result = civicrm_contact_update($params);
-  }
-  else {
-    $result = civicrm_contact_create($params);
-  }
-  return $result;
-}
-
-/**
- * Validate the addressee or email or postal greetings
- *
- * @param  $params                   Associative array of property name/value
- *                                   pairs to insert in new contact.
- *
- * @return array (reference )        null on success, error message otherwise
- *
- * @access public
- */
-function _civicrm_greeting_format_params(&$params) {
-  $greetingParams = array('', '_id', '_custom');
-  foreach (array(
-    'email', 'postal', 'addressee') as $key) {
-    $greeting = '_greeting';
-    if ($key == 'addressee') {
-      $greeting = '';
-    }
-
-    $formatParams = FALSE;
-    // unset display value from params.
-    if (isset($params["{$key}{$greeting}_display"])) {
-      unset($params["{$key}{$greeting}_display"]);
-    }
-
-    // check if greetings are present in present
-    foreach ($greetingParams as $greetingValues) {
-      if (array_key_exists("{$key}{$greeting}{$greetingValues}", $params)) {
-        $formatParams = TRUE;
-        break;
-      }
-    }
-
-    if (!$formatParams) {
-
-      continue;
-    }
-
-    // format params
-    if (CRM_Utils_Array::value('contact_type', $params) == 'Organization' && $key != 'addressee') {
-      return civicrm_create_error(ts('You cannot use email/postal greetings for contact type %1.',
-          array(1 => $params['contact_type'])
-        ));
-    }
-
-    $nullValue = FALSE;
-    $filter = array(
-      'contact_type' => $params['contact_type'],
-      'greeting_type' => "{$key}{$greeting}",
-    );
-
-    $greetings      = CRM_Core_PseudoConstant::greeting($filter);
-    $greetingId     = CRM_Utils_Array::value("{$key}{$greeting}_id", $params);
-    $greetingVal    = CRM_Utils_Array::value("{$key}{$greeting}", $params);
-    $customGreeting = CRM_Utils_Array::value("{$key}{$greeting}_custom", $params);
-
-    if (!$greetingId && $greetingVal) {
-      $params["{$key}{$greeting}_id"] = CRM_Utils_Array::key($params["{$key}{$greeting}"], $greetings);
-    }
-
-    if ($customGreeting && $greetingId &&
-      ($greetingId != array_search('Customized', $greetings))
-    ) {
-      return civicrm_create_error(ts('Provide either %1 greeting id and/or %1 greeting or custom %1 greeting',
-          array(1 => $key)
-        ));
-    }
-
-    if ($greetingVal && $greetingId &&
-      ($greetingId != CRM_Utils_Array::key($greetingVal, $greetings))
-    ) {
-      return civicrm_create_error(ts('Mismatch in %1 greeting id and %1 greeting',
-          array(1 => $key)
-        ));
-    }
-
-    if ($greetingId) {
-
-      if (!array_key_exists($greetingId, $greetings)) {
-        return civicrm_create_error(ts('Invalid %1 greeting Id', array(1 => $key)));
-      }
-
-      if (!$customGreeting && ($greetingId == array_search('Customized', $greetings))) {
-        return civicrm_create_error(ts('Please provide a custom value for %1 greeting',
-            array(1 => $key)
-          ));
-      }
-    }
-    elseif ($greetingVal) {
-
-      if (!in_array($greetingVal, $greetings)) {
-        return civicrm_create_error(ts('Invalid %1 greeting', array(1 => $key)));
-      }
-
-      $greetingId = CRM_Utils_Array::key($greetingVal, $greetings);
-    }
-
-    if ($customGreeting) {
-      $greetingId = CRM_Utils_Array::key('Customized', $greetings);
-    }
-
-    $customValue = $params['contact_id'] ? CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
-      $params['contact_id'],
-      "{$key}{$greeting}_custom"
-    ) : FALSE;
-
-    if (array_key_exists("{$key}{$greeting}_id", $params) && empty($params["{$key}{$greeting}_id"])) {
-      $nullValue = TRUE;
-    }
-    elseif (array_key_exists("{$key}{$greeting}", $params) && empty($params["{$key}{$greeting}"])) {
-      $nullValue = TRUE;
-    }
-    elseif ($customValue && array_key_exists("{$key}{$greeting}_custom", $params)
-      && empty($params["{$key}{$greeting}_custom"])
-    ) {
-      $nullValue = TRUE;
-    }
-
-    $params["{$key}{$greeting}_id"] = $greetingId;
-
-    if (!$customValue && !$customGreeting && array_key_exists("{$key}{$greeting}_custom", $params)) {
-      unset($params["{$key}{$greeting}_custom"]);
-    }
-
-    if ($nullValue) {
-      $params["{$key}{$greeting}_id"] = '';
-      $params["{$key}{$greeting}_custom"] = '';
-    }
-
-    if (isset($params["{$key}{$greeting}"])) {
-      unset($params["{$key}{$greeting}"]);
-    }
-  }
-}
-
-/**
- * Retrieve one or more contacts, given a set of search params
- *
- * @param  mixed[]  (reference ) input parameters
- * @param  bool  follow the pre-2.2.3 behavior of this function
- *
- * @return array (reference )        array of properties, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function civicrm_contact_get(&$params, $deprecated_behavior = FALSE) {
-  _civicrm_initialize();
-
-  if ($deprecated_behavior) {
-    return _civicrm_contact_get_deprecated($params);
-  }
-
-  // fix for CRM-7384 cater for soft deleted contacts
-  $params['contact_is_deleted'] = 0;
-  if (isset($params['showAll'])) {
-    if (strtolower($params['showAll']) == "active") {
-      $params['contact_is_deleted'] = 0;
-    }
-    if (strtolower($params['showAll']) == "trash") {
-      $params['contact_is_deleted'] = 1;
-    }
-    if (strtolower($params['showAll']) == "all" && isset($params['contact_is_deleted'])) {
-      unset($params['contact_is_deleted']);
-    }
-  }
-
-  $inputParams      = array();
-  $returnProperties = array();
-  $otherVars        = array('sort', 'offset', 'rowCount', 'smartGroupCache');
-
-  $sort            = NULL;
-  $offset          = 0;
-  $rowCount        = 25;
-  $smartGroupCache = FALSE;
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 6) == 'return') {
-      $returnProperties[substr($n, 7)] = $v;
-    }
-    elseif (in_array($n, $otherVars)) {
-      $$n = $v;
-    }
-    else {
-      $inputParams[$n] = $v;
-    }
-  }
-
-  if (empty($returnProperties)) {
-    $returnProperties = NULL;
-  }
-
-  require_once 'CRM/Contact/BAO/Query.php';
-  $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
-  list($contacts, $options) = CRM_Contact_BAO_Query::apiQuery($newParams,
-    $returnProperties,
-    NULL,
-    $sort,
-    $offset,
-    $rowCount,
-    $smartGroupCache
-  );
-  return $contacts;
-}
-
-/**
- * Retrieve a specific contact, given a set of search params
- *
- * @deprecated deprecated since version 2.2.3
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        array of properties, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function _civicrm_contact_get_deprecated(&$params) {
-  $values = array();
-  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'));
-  }
-
-  $contacts = &civicrm_contact_search($params);
-  if (civicrm_error($contacts)) {
-    return $contacts;
-  }
-
-  if (count($contacts) != 1 &&
-    !CRM_Utils_Array::value('returnFirst', $params)
-  ) {
-    return civicrm_create_error(ts('%1 contacts matching input params', array(1 => count($contacts))));
-  }
-  elseif (count($contacts) == 0) {
-    return civicrm_create_error(ts('No contacts match the input params'));
-  }
-
-  $contacts = array_values($contacts);
-  return $contacts[0];
-}
-
-/**
- * Delete a contact with given contact id
- *
- * @param  array       $params (reference ) input parameters, contact_id element required
- *
- * @return boolean        true if success, else false
- * @static void
- * @access public
- */
-function civicrm_contact_delete(&$params) {
-  require_once 'CRM/Contact/BAO/Contact.php';
-
-  $contactID = CRM_Utils_Array::value('contact_id', $params);
-  if (!$contactID) {
-    return civicrm_create_error(ts('Could not find contact_id in input parameters'));
-  }
-
-  $session = CRM_Core_Session::singleton();
-  if ($contactID == $session->get('userID')) {
-    return civicrm_create_error(ts('This contact record is linked to the currently logged in user account - and cannot be deleted.'));
-  }
-  $restore = CRM_Utils_Array::value('restore', $params) ? $params['restore'] : FALSE;
-  $skipUndelete = CRM_Utils_Array::value('skip_undelete', $params) ? $params['skip_undelete'] : FALSE;
-  if (CRM_Contact_BAO_Contact::deleteContact($contactID, $restore, $skipUndelete)) {
-    return civicrm_create_success();
-  }
-  else {
-    return civicrm_create_error(ts('Could not delete contact'));
-  }
-}
-
-/**
- * Retrieve a set of contacts, given a set of input params
- *
- * @deprecated deprecated since version 2.2.3
- *
- * @param  array   $params           (reference ) input parameters
- * @param array    $returnProperties Which properties should be included in the
- *                                   returned Contact object. If NULL, the default
- *                                   set of properties will be included.
- *
- * @return array (reference )        array of contacts, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function &civicrm_contact_search(&$params) {
-  _civicrm_initialize();
-
-  $inputParams = $returnProperties = array();
-  $otherVars = array('sort', 'offset', 'rowCount', 'smartGroupCache');
-
-  $sort            = NULL;
-  $offset          = 0;
-  $rowCount        = 25;
-  $smartGroupCache = FALSE;
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 6) == 'return') {
-      $returnProperties[substr($n, 7)] = $v;
-    }
-    elseif (in_array($n, $otherVars)) {
-      $$n = $v;
-    }
-    else {
-      $inputParams[$n] = $v;
-    }
-  }
-
-  // explicitly suppress all deleted contacts
-  // this is fixed in api v3
-  // CRM-8809
-  $inputParams['contact_is_deleted'] = 0;
-
-  if (empty($returnProperties)) {
-    $returnProperties = NULL;
-  }
-
-  require_once 'CRM/Contact/BAO/Query.php';
-  $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
-  list($contacts, $options) = CRM_Contact_BAO_Query::apiQuery($newParams,
-    $returnProperties,
-    NULL,
-    $sort,
-    $offset,
-    $rowCount,
-    $smartGroupCache
-  );
-  return $contacts;
-}
-
-/**
- * Ensure that we have the right input parameters
- *
- * @todo 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 contact.
- * @param boolean $dupeCheck       Should we check for duplicate contacts
- * @param boolean $dupeErrorArray  Should we return values of error
- *                                 object in array foramt
- * @param boolean $requiredCheck   Should we check if required params
- *                                 are present in params array
- * @param int   $dedupeRuleGroupID - the dedupe rule ID to use if present
- *
- * @return null on success, error message otherwise
- * @access public
- */
-function civicrm_contact_check_params(&$params,
-  $dupeCheck         = TRUE,
-  $dupeErrorArray    = FALSE,
-  $requiredCheck     = TRUE,
-  $dedupeRuleGroupID = NULL
-) {
-  if ($requiredCheck) {
-    $required = array(
-      'Individual' => array(
-        array('first_name', 'last_name'),
-        'email',
-      ),
-      'Household' => array(
-        'household_name',
-      ),
-      'Organization' => array(
-        'organization_name',
-      ),
-    );
-
-    // cannot create a contact with empty params
-    if (empty($params)) {
-      return civicrm_create_error('Input Parameters empty');
-    }
-
-    if (!array_key_exists('contact_type', $params)) {
-      return civicrm_create_error('Contact Type not specified');
-    }
-
-    // contact_type has a limited number of valid values
-    $fields = CRM_Utils_Array::value($params['contact_type'], $required);
-    if ($fields == NULL) {
-      return civicrm_create_error("Invalid Contact Type: {$params['contact_type']}");
-    }
-
-    if ($csType = CRM_Utils_Array::value('contact_sub_type', $params)) {
-      if (!(CRM_Contact_BAO_ContactType::isExtendsContactType($csType, $params['contact_type']))) {
-        return civicrm_create_error("Invalid or Mismatched Contact SubType: " . implode(', ', (array)$csType));
-      }
-    }
-
-    if (!CRM_Utils_Array::value('contact_id', $params)) {
-      $valid = FALSE;
-      $error = '';
-      foreach ($fields as $field) {
-        if (is_array($field)) {
-          $valid = TRUE;
-          foreach ($field as $element) {
-            if (!CRM_Utils_Array::value($element, $params)) {
-              $valid = FALSE;
-              $error .= $element;
-              break;
-            }
-          }
-        }
-        else {
-          if (CRM_Utils_Array::value($field, $params)) {
-            $valid = TRUE;
-          }
-        }
-        if ($valid) {
-          break;
-        }
-      }
-
-      if (!$valid) {
-        return civicrm_create_error("Required fields not found for {$params['contact_type']} : $error");
-      }
-    }
-  }
-
-  if ($dupeCheck) {
-    // check for record already existing
-    require_once 'CRM/Dedupe/Finder.php';
-    $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
-
-    // CRM-6431
-    // setting 'check_permission' here means that the dedupe checking will be carried out even if the
-    // person does not have permission to carry out de-dupes
-    // this is similar to the front end form
-    if (isset($params['check_permission'])) {
-      $dedupeParams['check_permission'] = $fields['check_permission'];
-    }
-
-    $ids = implode(',',
-      CRM_Dedupe_Finder::dupesByParams($dedupeParams,
-        $params['contact_type'],
-        'Strict',
-        array(),
-        $dedupeRuleGroupID
-      )
-    );
-
-    if ($ids != NULL) {
-      if ($dupeErrorArray) {
-        $error = CRM_Core_Error::createError("Found matching contacts: $ids",
-          CRM_Core_Error::DUPLICATE_CONTACT,
-          'Fatal', $ids
-        );
-        return civicrm_create_error($error->pop());
-      }
-
-      return civicrm_create_error("Found matching contacts: $ids", array($ids));
-    }
-  }
-
-  //check for organisations with same name
-  if (CRM_Utils_Array::value('current_employer', $params)) {
-    $organizationParams = array();
-    $organizationParams['organization_name'] = $params['current_employer'];
-
-    require_once 'CRM/Dedupe/Finder.php';
-    $dedupParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
-
-    $dedupParams['check_permission'] = FALSE;
-    $dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupParams, 'Organization', 'Fuzzy');
-
-    // check for mismatch employer name and id
-    if (CRM_Utils_Array::value('employer_id', $params)
-      && !in_array($params['employer_id'], $dupeIds)
-    ) {
-      return civicrm_create_error('Employer name and Employer id Mismatch');
-    }
-
-    // show error if multiple organisation with same name exist
-    if (!CRM_Utils_Array::value('employer_id', $params)
-      && (count($dupeIds) > 1)
-    ) {
-      return civicrm_create_error('Found more than one Organisation with same Name.');
-    }
-  }
-
-  return NULL;
-}
-
-/**
- * @todo What does this do? If it's still useful, figure out where it should live and what it should be named.
- *
- * @deprecated deprecated since version 2.2.3
- */
-function civicrm_replace_contact_formatted($contactId, &$params, &$fields) {
-  //$contact = civcrm_get_contact(array('contact_id' => $contactId));
-
-  $delContact = array('contact_id' => $contactId);
-
-  civicrm_contact_delete($delContact);
-
-  $cid = CRM_Contact_BAO_Contact::createProfileContact($params, $fields,
-    NULL, NULL, NULL,
-    $params['contact_type']
-  );
-  return civicrm_create_success($cid);
-}
-
-/**
- * Takes an associative array and creates a contact object and all the associated
- * derived objects (i.e. individual, location, email, phone etc)
- *
- * @param array $params (reference ) an assoc array of name/value pairs
- * @param  int     $contactID        if present the contact with that ID is updated
- *
- * @return object CRM_Contact_BAO_Contact object
- * @access public
- * @static
- */
-function _civicrm_contact_update(&$params, $contactID = NULL) {
-  require_once 'CRM/Core/Transaction.php';
-  $transaction = new CRM_Core_Transaction();
-
-  if ($contactID) {
-    $params['contact_id'] = $contactID;
-  }
-  require_once 'CRM/Contact/BAO/Contact.php';
-
-  $contact = CRM_Contact_BAO_Contact::create($params);
-
-  $transaction->commit();
-
-  return $contact;
-}
-
-/**
- * @todo Move this to ContactFormat.php
- * @deprecated
- */
-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)) {
-    return $error;
-  }
-
-  $error = _civicrm_validate_formatted_contact($params);
-  if (civicrm_error($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 (CRM_Utils_Array::value('onDuplicate', $params) != CRM_Import_Parser::DUPLICATE_NOCHECK) {
-    CRM_Core_Error::reset();
-    $error = _civicrm_duplicate_formatted_contact($params);
-    if (civicrm_error($error)) {
-      return $error;
-    }
-  }
-
-  $contact = CRM_Contact_BAO_Contact::create($params,
-    CRM_Utils_Array::value('fixAddress', $params)
-  );
-
-  _civicrm_object_to_array($contact, $contactArray);
-  return $contactArray;
-}
-
-/**
- * Returns the number of Contact objects which match the search criteria specified in $params.
- *
- * @deprecated deprecated since version 2.2.3; civicrm_contact_get now returns a record_count value
- *
- * @param array  $params
- *
- * @return int
- * @access public
- */
-function civicrm_contact_search_count(&$params) {
-  // convert the params to new format
-  require_once 'CRM/Contact/Form/Search.php';
-  $newP = CRM_Contact_BAO_Query::convertFormValues($params);
-  $query = new CRM_Contact_BAO_Query($newP);
-  return $query->searchQuery(0, 0, NULL, TRUE);
-}
-
-/**
- * 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);
-      }
-    }
-  }
-}
-
diff --git a/api/v2/Contribute.php b/api/v2/Contribute.php
deleted file mode 100644
index c12eddc1f0..0000000000
--- a/api/v2/Contribute.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * CRM-6241
- * Creating this file to maintain backward compatibility
- * We should plan on deprecating this in 4.0
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Contact
- * @copyright CiviCRM LLC (c) 2004-2013
- * $Id: Contact.php 30415 2010-10-29 12:02:47Z shot $
- */
-require_once 'api/v2/Contribution.php';
-
diff --git a/api/v2/Contribution.php b/api/v2/Contribution.php
deleted file mode 100644
index bde6fcdc47..0000000000
--- a/api/v2/Contribution.php
+++ /dev/null
@@ -1,578 +0,0 @@
-<?php
-// $Id: Contribution.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 Contribution functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Contribute
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Contribution.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Utils/Rule.php';
-require_once 'CRM/Contribute/PseudoConstant.php';
-
-/**
- * Add or update a contribution
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        contribution_id of created or updated record
- * @static void
- * @access public
- */
-function &civicrm_contribution_create(&$params) {
-  _civicrm_initialize();
-
-  $error = _civicrm_contribute_check_params($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $values = array();
-
-  require_once 'CRM/Contribute/BAO/Contribution.php';
-  $error = _civicrm_contribute_format_params($params, $values);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $values['contact_id'] = $params['contact_id'];
-  $values['source'] = CRM_Utils_Array::value('source', $params);
-  $values['skipRecentView'] = TRUE;
-  $ids = array();
-  if (CRM_Utils_Array::value('id', $params)) {
-    $ids['contribution'] = $params['id'];
-  }
-  $contribution = CRM_Contribute_BAO_Contribution::create($values, $ids);
-  if (is_a($contribution, 'CRM_Core_Error')) {
-    return civicrm_create_error(ts($contribution->_errors[0]['message']));
-  }
-
-  _civicrm_object_to_array($contribution, $contributeArray);
-
-  return $contributeArray;
-}
-/*
- * Deprecated wrapper function
- * @deprecated
- */
-function civicrm_contribution_add(&$params) {
-  $result = civicrm_contribution_create($params);
-  return $result;
-}
-
-/**
- * Retrieve a specific contribution, given a set of input params
- * If more than one contribution exists, return an error, unless
- * the client has requested to return the first found contact
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        array of properties, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function &civicrm_contribution_get(&$params) {
-  _civicrm_initialize();
-
-  $values = array();
-  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'));
-  }
-
-  $contributions = &civicrm_contribution_search($params);
-  if (civicrm_error($contributions)) {
-    return $contributions;
-  }
-
-  if (count($contributions) != 1 &&
-    !$params['returnFirst']
-  ) {
-    return civicrm_create_error(ts('%1 contributions matching input params', array(1 => count($contributions))),
-      $contributions
-    );
-  }
-
-  $contributions = array_values($contributions);
-  return $contributions[0];
-}
-
-/**
- * Delete a contribution
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return boolean        true if success, else false
- * @static void
- * @access public
- */
-function civicrm_contribution_delete(&$params) {
-  _civicrm_initialize();
-  $contributionID = CRM_Utils_Array::value('contribution_id', $params);
-  if (!$contributionID) {
-    return civicrm_create_error(ts('Could not find contribution_id in input parameters'));
-  }
-
-  require_once 'CRM/Contribute/BAO/Contribution.php';
-  if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionID)) {
-    return civicrm_create_success();
-  }
-  else {
-    return civicrm_create_error(ts('Could not delete contribution'));
-  }
-}
-
-/**
- * Retrieve a set of contributions, given a set of input params
- *
- * @param  array   $params           (reference ) input parameters
- * @param array    $returnProperties Which properties should be included in the
- *                                   returned Contribution object. If NULL, the default
- *                                   set of properties will be included.
- *
- * @return array (reference )        array of contributions, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function &civicrm_contribution_search(&$params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Input parameters is not an array'));
-  }
-
-  $inputParams      = array();
-  $returnProperties = array();
-  $otherVars        = array('sort', 'offset', 'rowCount');
-
-  $sort     = NULL;
-  $offset   = 0;
-  $rowCount = 25;
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 7) == 'return.') {
-      $returnProperties[substr($n, 7)] = $v;
-    }
-    elseif (in_array($n, $otherVars)) {
-      $$n = $v;
-    }
-    else {
-      $inputParams[$n] = $v;
-    }
-  }
-
-  // add is_test to the clause if not present
-  if (!array_key_exists('contribution_test', $inputParams)) {
-    $inputParams['contribution_test'] = 0;
-  }
-
-  require_once 'CRM/Contribute/BAO/Query.php';
-  require_once 'CRM/Contact/BAO/Query.php';
-  if (empty($returnProperties)) {
-    $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
-  }
-
-  $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
-
-  $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL);
-  list($select, $from, $where, $having) = $query->query();
-
-  $sql = "$select $from $where $having";
-
-  if (!empty($sort)) {
-    $sql .= " ORDER BY $sort ";
-  }
-  $sql .= " LIMIT $offset, $rowCount ";
-  $dao = CRM_Core_DAO::executeQuery($sql);
-
-  $contribution = array();
-  while ($dao->fetch()) {
-    $contribution[$dao->contribution_id] = $query->store($dao);
-  }
-  $dao->free();
-
-  return $contribution;
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- * @deprecated
- */
-function &civicrm_contribution_format_create(&$params) {
-  _civicrm_initialize();
-
-  // return error if we have no params
-  if (empty($params)) {
-    return civicrm_create_error('Input Parameters empty');
-  }
-
-  $error = _civicrm_contribute_check_params($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-  $values = array();
-  $error = _civicrm_contribute_format_params($params, $values);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $error = _civicrm_contribute_duplicate_check($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-  $ids = array();
-
-  CRM_Contribute_BAO_Contribution::resolveDefaults($params, TRUE);
-
-  $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
-  _civicrm_object_to_array($contribution, $contributeArray);
-  return $contributeArray;
-}
-
-/**
- * This function ensures that we have the right input contribution 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 contribution.
- *
- * @return bool|CRM_Utils_Error
- * @access private
- */
-function _civicrm_contribute_check_params(&$params) {
-  static $required = array('contact_id' => NULL,
-    'total_amount' => NULL,
-    'financial_type_id' => 'financial_type',
-  );
-
-  // params should be an array
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Input parameters is not an array'));
-  }
-
-  // cannot create a contribution with empty params
-  if (empty($params)) {
-    return civicrm_create_error('Input Parameters empty');
-  }
-
-  $valid = TRUE;
-  $error = '';
-
-  // check params for contribution id during update
-  if (CRM_Utils_Array::value('id', $params)) {
-    require_once 'CRM/Contribute/BAO/Contribution.php';
-    $contributor = new CRM_Contribute_BAO_Contribution();
-    $contributor->id = $params['id'];
-    if (!$contributor->find(TRUE)) {
-      return civicrm_create_error(ts('Contribution id is not valid'));
-    }
-    // do not check other field during update
-    return array();
-  }
-
-  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;
-      break;
-    }
-  }
-
-  if (!$valid) {
-    return civicrm_create_error("Required fields not found for contribution $error");
-  }
-
-  return array();
-}
-
-/**
- * Check if there is a contribution with the same trxn_id or invoice_id
- *
- * @param array  $params       Associative array of property name/value
- *                             pairs to insert in new contribution.
- *
- * @return array|CRM_Error
- * @access private
- */
-function _civicrm_contribute_duplicate_check(&$params) {
-  require_once 'CRM/Contribute/BAO/Contribution.php';
-  $duplicates = array();
-  $result = CRM_Contribute_BAO_Contribution::checkDuplicate($params, $duplicates);
-  if ($result) {
-    $d = implode(', ', $duplicates);
-    $error = CRM_Core_Error::createError("Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: $d", CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', $d);
-    return civicrm_create_error($error->pop(),
-      $d
-    );
-  }
-  else {
-    return array();
-  }
-}
-
-/**
- * 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_contribute_format_params(&$params, &$values, $create = FALSE) {
-  // copy all the contribution fields as is
-
-  $fields = CRM_Contribute_DAO_Contribution::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 'contribution_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['contribution_contact_id'];
-        unset($values['contribution_contact_id']);
-        break;
-
-      case 'receive_date':
-      case 'cancel_date':
-      case 'receipt_date':
-      case 'thankyou_date':
-        if (!CRM_Utils_Rule::dateTime($value)) {
-          return civicrm_create_error("$key not a valid date: $value");
-        }
-        break;
-
-      case 'non_deductible_amount':
-      case 'total_amount':
-      case 'fee_amount':
-      case 'net_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 'financial_type_id' :
-        if (!CRM_Utils_Array::value($value, CRM_Contribute_PseudoConstant::financialType())) {
-          return civicrm_create_error('Invalid Financial Type Id');
-        }
-        break;
-
-      case 'financial_type':
-        $contributionTypeId = CRM_Utils_Array::key(ucfirst($value),
-          CRM_Contribute_PseudoConstant::financialType()
-        );
-        if ($contributionTypeId) {
-          if (CRM_Utils_Array::value('financial_type_id', $values) &&
-            $contributionTypeId != $values['financial_type_id']
-          ) {
-            return civicrm_create_error('Mismatched Financial Type and Financial Type Id');
-          }
-          $values['financial_type_id'] = $contributionTypeId;
-        }
-        else {
-          return civicrm_create_error('Invalid Financial Type');
-        }
-        break;
-
-      case 'payment_instrument':
-        require_once 'CRM/Core/OptionGroup.php';
-        $values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
-        break;
-
-      case 'soft_credit_to':
-        if (!CRM_Utils_Rule::integer($value)) {
-          return civicrm_create_error("$key not a valid Id: $value");
-        }
-        $values['soft_credit_to'] = $value;
-        break;
-
-      default:
-        break;
-    }
-  }
-
-  if (array_key_exists('note', $params)) {
-    $values['note'] = $params['note'];
-  }
-
-  _civicrm_custom_format_params($params, $values, 'Contribution');
-
-  if ($create) {
-    // CRM_Contribute_BAO_Contribution::add() handles contribution_source
-    // So, if $values contains contribution_source, convert it to source
-    $changes = array('contribution_source' => 'source');
-
-    foreach ($changes as $orgVal => $changeVal) {
-      if (isset($values[$orgVal])) {
-        $values[$changeVal] = $values[$orgVal];
-        unset($values[$orgVal]);
-      }
-    }
-  }
-
-  return array();
-}
-
-/**
- * Process a transaction and record it against the contact.
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        contribution of created or updated record (or a civicrm error)
- * @static void
- * @access public
- *
- */
-function civicrm_contribute_transact($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'));
-  }
-
-  $values = array();
-
-  require_once 'CRM/Contribute/BAO/Contribution.php';
-  $error = _civicrm_contribute_format_params($params, $values);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $required = array(
-    'amount',
-  );
-  foreach ($required as $key) {
-    if (!isset($params[$key])) {
-      return civicrm_create_error("Missing parameter $key: civicrm_contribute_transact() requires a parameter '$key'.");
-    }
-  }
-
-  // allow people to omit some values for convenience
-  $defaults = array(
-    // 'payment_processor_id' => NULL /* we could retrieve the default processor here, but only if it's missing to avoid an extra lookup */
-    'payment_processor_mode' => 'live',
-  );
-  $params = array_merge($defaults, $params);
-
-  // clean up / adjust some values which
-  if (!isset($params['total_amount'])) {
-    $params['total_amount'] = $params['amount'];
-  }
-  if (!isset($params['net_amount'])) {
-    $params['net_amount'] = $params['amount'];
-  }
-  if (!isset($params['receive_date'])) {
-    $params['receive_date'] = date('Y-m-d');
-  }
-  if (!isset($params['invoiceID']) && isset($params['invoice_id'])) {
-    $params['invoiceID'] = $params['invoice_id'];
-  }
-
-  require_once 'CRM/Financial/BAO/PaymentProcessor.php';
-  $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($params['payment_processor_id'],
-    $params['payment_processor_mode']
-  );
-  if (civicrm_error($paymentProcessor)) {
-    return $paymentProcessor;
-  }
-
-  require_once 'CRM/Core/Payment.php';
-  $payment = CRM_Core_Payment::singleton($params['payment_processor_mode'], $paymentProcessor);
-  if (civicrm_error($payment)) {
-    return $payment;
-  }
-
-  $transaction = $payment->doDirectPayment($params);
-  if (civicrm_error($transaction)) {
-    return $transaction;
-  }
-
-  // but actually, $payment->doDirectPayment() doesn't return a
-  // CRM_Core_Error by itself
-  if (get_class($transaction) == 'CRM_Core_Error') {
-    $errs = $transaction->getErrors();
-    if (!empty($errs)) {
-      $last_error = array_shift($errs);
-      return CRM_Core_Error::createApiError($last_error['message']);
-    }
-  }
-
-  $contribution = civicrm_contribution_add($params);
-  return $contribution;
-}
-
diff --git a/api/v2/CustomGroup.php b/api/v2/CustomGroup.php
deleted file mode 100644
index 8b486b8db5..0000000000
--- a/api/v2/CustomGroup.php
+++ /dev/null
@@ -1,247 +0,0 @@
-<?php
-// $Id: CustomGroup.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 custom group functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_CustomGroup
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: CustomGroup.php 45502 2013-02-08 13:32:55Z kurund $
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Most API functions take in associative arrays ( name => value pairs
- * as parameters. Some of the most commonly used parameters are
- * described below
- *
- * @param array $params           an associative array used in construction
- * retrieval of the object
- *
- *
- */
-
-/**
- * Use this API to create a new group. See the CRM Data Model for custom_group property definitions
- * $params['class_name'] is a required field, class being extended.
- *
- * @param $params     array   Associative array of property name/value pairs to insert in group.
- *
- *
- * @return   Newly create custom_group object
- *
- * @access public
- */
-function civicrm_custom_group_create($params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error("params is not an array");
-  }
-
-  // Require either param['class_name'] (string) - for backwards compatibility - OR parm['extends'] (array)
-  // If passing extends array - set class_name (e.g. 'Contact', 'Participant'...) as extends[0]. You may optionally
-  // pass an extends_entity_column_value as extends[1] (e.g. an Activity Type ID).
-  if (isset($params['class_name']) && trim($params['class_name'])) {
-    $params['extends'][0] = trim($params['class_name']);
-  }
-  else {
-    if (!isset($params['extends']) || !is_array($params['extends'])) {
-      return civicrm_create_error("Params must include either 'class_name' (string) or 'extends' (array).");
-    }
-    else {
-      if (!isset($params['extends'][0]) || !trim($params['extends'][0])) {
-        return civicrm_create_error("First item in params['extends'] must be a class name (e.g. 'Contact').");
-      }
-    }
-  }
-
-  $error = _civicrm_check_required_fields($params, 'CRM_Core_DAO_CustomGroup');
-
-  require_once 'CRM/Utils/String.php';
-  if (!isset($params['title']) ||
-    !trim($params['title'])
-  ) {
-    return civicrm_create_error("Title parameter is required.");
-  }
-
-  if (!isset($params['style']) || !trim($params['style'])) {
-    $params['style'] = 'Inline';
-  }
-
-  if (is_a($error, 'CRM_Core_Error')) {
-    return civicrm_create_error($error->_errors[0]['message']);
-  }
-
-  require_once 'CRM/Core/BAO/CustomGroup.php';
-  $customGroup = CRM_Core_BAO_CustomGroup::create($params);
-
-  _civicrm_object_to_array($customGroup, $values);
-
-  if (is_a($customGroup, 'CRM_Core_Error')) {
-    return civicrm_create_error($customGroup->_errors[0]['message']);
-  }
-  else {
-    $values['is_error'] = 0;
-  }
-  if (CRM_Utils_Array::value('html_type', $params)) {
-    $params['custom_group_id'] = $customGroup->id;
-    $fieldValues = civicrm_custom_field_create($params);
-    $values = array_merge($values, $fieldValues['result']);
-  }
-  return $values;
-}
-
-/**
- * Use this API to delete an existing group.
- *
- * @param array id of the group to be deleted
- *
- * @return Null if success
- * @access public
- **/
-function civicrm_custom_group_delete($params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array');
-  }
-
-  if (!CRM_Utils_Array::value('id', $params)) {
-    return civicrm_create_error('Invalid or no value for Custom group ID');
-  }
-  // convert params array into Object
-  require_once 'CRM/Core/DAO/CustomGroup.php';
-  $values = new CRM_Core_DAO_CustomGroup();
-  $values->id = $params['id'];
-  $values->find(TRUE);
-
-  require_once 'CRM/Core/BAO/CustomGroup.php';
-  $result = CRM_Core_BAO_CustomGroup::deleteGroup($values);
-  return $result ? civicrm_create_success() : civicrm_error('Error while deleting custom group');
-}
-
-/**
- * Defines 'custom field' within a group.
- *
- *
- * @param $params       array  Associative array of property name/value pairs to create new custom field.
- *
- * @return Newly created custom_field id array
- *
- * @access public
- *
- */
-function civicrm_custom_field_create($params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error("params is not an array ");
-  }
-
-  if (!CRM_Utils_Array::value('custom_group_id', $params)) {
-    return civicrm_create_error("Missing Required field :custom_group_id");
-  }
-
-  if (!(CRM_Utils_Array::value('label', $params))) {
-    return civicrm_create_error("Missing Required field :label");
-  }
-
-  if (!(CRM_Utils_Array::value('option_type', $params))) {
-    if (CRM_Utils_Array::value('id', $params)) {
-      $params['option_type'] = 2;
-    }
-    else {
-      $params['option_type'] = 1;
-    }
-  }
-
-  $error = _civicrm_check_required_fields($params, 'CRM_Core_DAO_CustomField');
-  if (is_a($error, 'CRM_Core_Error')) {
-    return civicrm_create_error($error->_errors[0]['message']);
-  }
-
-  // Array created for passing options in params
-  if (isset($params['option_values']) && is_array($params['option_values'])) {
-    foreach ($params['option_values'] as $key => $value) {
-      $params['option_label'][$value['weight']] = $value['label'];
-      $params['option_value'][$value['weight']] = $value['value'];
-      $params['option_status'][$value['weight']] = $value['is_active'];
-      $params['option_weight'][$value['weight']] = $value['weight'];
-    }
-  }
-  require_once 'CRM/Core/BAO/CustomField.php';
-  $customField = CRM_Core_BAO_CustomField::create($params);
-
-  $values['customFieldId'] = $customField->id;
-
-  if (is_a($customField, 'CRM_Core_Error') && is_a($column, 'CRM_Core_Error')) {
-    return civicrm_create_error($customField->_errors[0]['message']);
-  }
-  else {
-    return civicrm_create_success($values);
-  }
-}
-
-/**
- * Use this API to delete an existing custom group field.
- *
- * @param $params     Array id of the field to be deleted
- *
- *
- * @access public
- **/
-function civicrm_custom_field_delete($params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array');
-  }
-
-  if (!CRM_Utils_Array::value('id', $params)) {
-    return civicrm_create_error('Invalid or no value for Custom Field ID');
-  }
-
-  require_once 'CRM/Core/DAO/CustomField.php';
-  $field = new CRM_Core_DAO_CustomField();
-  $field->id = $params['id'];
-  $field->find(TRUE);
-
-  require_once 'CRM/Core/BAO/CustomField.php';
-  $customFieldDelete = CRM_Core_BAO_CustomField::deleteField($field);
-  return $customFieldDelete ? civicrm_create_error('Error while deleting custom field') : civicrm_create_success();
-}
-
diff --git a/api/v2/Domain.php b/api/v2/Domain.php
deleted file mode 100644
index c7e2b6c1ed..0000000000
--- a/api/v2/Domain.php
+++ /dev/null
@@ -1,107 +0,0 @@
-<?php
-// $Id: Domain.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 domain functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Domain
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Domain.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Generic file to retrieve all the constants and
- * pseudo constants used in CiviCRM
- *
- */
-function civicrm_domain_get() {
-  require_once 'CRM/Core/BAO/Domain.php';
-  $dao    = CRM_Core_BAO_Domain::getDomain();
-  $values = array();
-  $params = array(
-    'entity_id' => $dao->id,
-    'entity_table' => 'civicrm_domain',
-  );
-  require_once 'CRM/Core/BAO/Location.php';
-  $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
-  $address_array = array(
-    'street_address', 'supplemental_address_1', 'supplemental_address_2',
-    'city', 'state_province_id', 'postal_code', 'country_id', 'geo_code_1', 'geo_code_2',
-  );
-  require_once 'CRM/Core/OptionGroup.php';
-  $domain[$dao->id] = array(
-    'id' => $dao->id,
-    'domain_name' => $dao->name,
-    'description' => $dao->description,
-    'domain_email' => CRM_Utils_Array::value('email', $values['location']['email'][1]),
-    'domain_phone' => array(
-      'phone_type' => CRM_Core_OptionGroup::getLabel('phone_type', CRM_Utils_Array::value('phone_type_id', $values['location']['phone'][1])),
-      'phone' => CRM_Utils_Array::value('phone', $values['location']['phone'][1]),
-    ),
-  );
-  foreach ($address_array as $value) {
-    $domain[$dao->id]['domain_address'][$value] = CRM_Utils_Array::value($value, $values['location']['address'][1]);
-  }
-  list($domain[$dao->id]['from_name'], $domain[$dao->id]['from_email']) = CRM_Core_BAO_Domain::getNameAndEmail();
-  return $domain;
-}
-
-/**
- * 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;
-}
-
diff --git a/api/v2/EntityTag.php b/api/v2/EntityTag.php
deleted file mode 100644
index 2c858cfe48..0000000000
--- a/api/v2/EntityTag.php
+++ /dev/null
@@ -1,230 +0,0 @@
-<?php
-// $Id: EntityTag.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 entity tag functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_EntityTag
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: EntityTag.php 45502 2013-02-08 13:32:55Z kurund $
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_entity_tag_get(&$params) {
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('params should be an array.'));
-  }
-
-  $entityID = NULL;
-  $entityTable = 'civicrm_contact';
-
-  if (!($entityID = CRM_Utils_Array::value('entity_id', $params))) {
-    $entityID = CRM_Utils_Array::value('contact_id', $params);
-  }
-
-  if (empty($entityID)) {
-    return civicrm_create_error(ts('entity_id is a required field.'));
-  }
-
-  if (CRM_Utils_Array::value('entity_table', $params)) {
-    $entityTable = $params['entity_table'];
-  }
-
-  require_once 'CRM/Core/BAO/EntityTag.php';
-  $values = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable);
-  $result = array();
-  foreach ($values as $v) {
-    $result[] = array('tag_id' => $v);
-  }
-  return $result;
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_entity_tag_display(&$params) {
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('params should be an array.'));
-  }
-
-  $entityID = NULL;
-  $entityTable = 'civicrm_contact';
-
-  if (!($entityID = CRM_Utils_Array::value('entity_id', $params))) {
-    $entityID = CRM_Utils_Array::value('contact_id', $params);
-  }
-
-  if (empty($entityID)) {
-    return civicrm_create_error(ts('entity_id is a required field.'));
-  }
-
-  if (CRM_Utils_Array::value('entity_table', $params)) {
-    $entityTable = $params['entity_table'];
-  }
-
-  require_once 'CRM/Core/BAO/EntityTag.php';
-  $values = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable);
-  $result = array();
-  $tags   = CRM_Core_PseudoConstant::tag();
-  foreach ($values as $v) {
-    $result[] = $tags[$v];
-  }
-  return implode(',', $result);
-}
-
-/**
- * Returns all entities assigned to a specific Tag.
- *
- * @param  $params      Array   an array valid Tag id
- *
- * @return $entities    Array   An array of entity ids.
- * @access public
- */
-function civicrm_tag_entities_get(&$params) {
-  require_once 'CRM/Core/BAO/Tag.php';
-  require_once 'CRM/Core/BAO/EntityTag.php';
-  $tag      = new CRM_Core_BAO_Tag();
-  $tag->id  = CRM_Utils_Array::value('tag_id', $params) ? $params['tag_id'] : NULL;
-  $entities = CRM_Core_BAO_EntityTag::getEntitiesByTag($tag);
-  return $entities;
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- * @deprecated
- */
-function civicrm_entity_tag_add(&$params) {
-  return civicrm_entity_tag_common($params, 'add');
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_entity_tag_create(&$params) {
-  return civicrm_entity_tag_common($params, 'add');
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- * @deprecated
- */
-function civicrm_entity_tag_remove(&$params) {
-  return civicrm_entity_tag_common($params, 'remove');
-}
-
-/**
- *
- * @param array $params
- *
- * @return <type>
- */
-function civicrm_entity_tag_delete(&$params) {
-  return civicrm_entity_tag_common($params, 'remove');
-}
-
-/**
- *
- * @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;
-}
-
diff --git a/api/v2/Event.php b/api/v2/Event.php
deleted file mode 100644
index 78f170aa22..0000000000
--- a/api/v2/Event.php
+++ /dev/null
@@ -1,264 +0,0 @@
-<?php
-// $Id: Event.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- *
- * File for the CiviCRM APIv2 event functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Event
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Event.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Create a Event
- *
- * This API is used for creating a Event
- *
- * @param  array   $params           (reference ) input parameters
- * Allowed @params array keys are:
- * {@schema Event/Event.xml}
- *
- * @return array of newly created event property values.
- * @access public
- */
-function civicrm_event_create(&$params) {
-  _civicrm_initialize();
-  $errorScope = CRM_Core_TemporaryErrorScope::useException();
-  try {
-    civicrm_api_check_permission(__FUNCTION__, $params, TRUE);
-    civicrm_verify_mandatory($params, 'CRM_Event_DAO_Event', array('start_date', 'event_type_id', 'title'));
-
-    // Do we really want $params[id], even if we have
-    // $params[event_id]? if yes then please uncomment the below line
-
-    //$ids['event'      ] = $params['id'];
-
-    $ids['eventTypeId'] = (int) $params['event_type_id'];
-    $ids['startDate']   = $params['start_date'];
-    $ids['event_id']    = CRM_Utils_Array::value('event_id', $params);
-
-    require_once 'CRM/Event/BAO/Event.php';
-    $eventBAO = CRM_Event_BAO_Event::create($params, $ids);
-
-    if (is_a($eventBAO, 'CRM_Core_Error')) {
-      return civicrm_create_error("Event is not created");
-    }
-    else {
-      $event = array();
-      _civicrm_object_to_array($eventBAO, $event);
-      $values             = array();
-      $values['event_id'] = $event['id'];
-      $values['is_error'] = 0;
-    }
-
-    return $values;
-  }
-  catch(Exception$e) {
-    return civicrm_create_error($e->getMessage());
-  }
-}
-
-/**
- * Get an Event.
- *
- * This api is used to retrieve all data for an existing Event.
- * Required parameters : id of event
- *
- * @param  array $params  an associative array of title/value property values of civicrm_event
- *
- * @return  If successful array of event data; otherwise object of CRM_Core_Error.
- * @access public
- */
-function civicrm_event_get(&$params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Input parameters is not an array.');
-  }
-
-  if (empty($params)) {
-    return civicrm_create_error('Params cannot be empty.');
-  }
-
-  $event = &civicrm_event_search($params);
-
-  if (count($event) != 1 &&
-    !CRM_Utils_Array::value('returnFirst', $params)
-  ) {
-    return civicrm_create_error(ts('%1 events matching input params', array(1 => count($event))));
-  }
-
-  if (civicrm_error($event)) {
-    return $event;
-  }
-
-  $event = array_values($event);
-  $event[0]['is_error'] = 0;
-  return $event[0];
-}
-
-/**
- * Get Event record.
- *
- *
- * @param  array  $params     an associative array of name/value property values of civicrm_event
- *
- * @return  Array of all found event property values.
- * @access public
- */
-function civicrm_event_search(&$params) {
-
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Input parameters is not an array.'));
-  }
-
-  $inputParams = array();
-  $returnProperties = array();
-  $returnCustomProperties = array();
-  $otherVars = array('sort', 'offset', 'rowCount', 'isCurrent');
-
-  $sort = array_key_exists('return.sort', $params) ? $params['return.sort'] : FALSE;
-
-  // don't check if empty, more meaningful error for API user instead of silent defaults
-  $offset    = array_key_exists('return.offset', $params) ? $params['return.offset'] : 0;
-  $rowCount  = array_key_exists('return.max_results', $params) ? $params['return.max_results'] : 25;
-  $isCurrent = array_key_exists('isCurrent', $params) ? $params['isCurrent'] : 0;
-
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 7) == 'return.') {
-      if (substr($n, 0, 14) == 'return.custom_') {
-        //take custom return properties separate
-        $returnCustomProperties[] = substr($n, 7);
-      }
-      elseif (!in_array(substr($n, 7), array(
-        'sort', 'offset', 'max_results'))) {
-        $returnProperties[] = substr($n, 7);
-      }
-    }
-    elseif (in_array($n, $otherVars)) {
-      $$n = $v;
-    }
-    else {
-      $inputParams[$n] = $v;
-    }
-  }
-
-  if (!empty($returnProperties)) {
-    $returnProperties[] = 'id';
-    $returnProperties[] = 'event_type_id';
-  }
-
-  require_once 'CRM/Core/BAO/CustomGroup.php';
-  require_once 'CRM/Event/BAO/Event.php';
-  $eventDAO = new CRM_Event_BAO_Event();
-  $eventDAO->copyValues($inputParams);
-  $event = array();
-  if (!empty($returnProperties)) {
-    $eventDAO->selectAdd();
-    $eventDAO->selectAdd(implode(',', $returnProperties));
-  }
-  $eventDAO->whereAdd('( is_template IS NULL ) OR ( is_template = 0 )');
-  if ($isCurrent) {
-    $eventDAO->whereAdd('(start_date >= CURDATE() || end_date >= CURDATE())');
-  }
-
-  $eventDAO->orderBy($sort);
-  $eventDAO->limit((int)$offset, (int)$rowCount);
-  $eventDAO->find();
-  while ($eventDAO->fetch()) {
-    $event[$eventDAO->id] = array();
-    CRM_Core_DAO::storeValues($eventDAO, $event[$eventDAO->id]);
-    $groupTree = &CRM_Core_BAO_CustomGroup::getTree('Event',
-      CRM_Core_DAO::$_nullObject,
-      $eventDAO->id,
-      FALSE,
-      $eventDAO->event_type_id
-    );
-    $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
-    $defaults = array();
-    CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
-
-    if (!empty($defaults)) {
-      foreach ($defaults as $key => $val) {
-        if (!empty($returnCustomProperties)) {
-          $customKey = explode('_', $key);
-          //show only return properties
-          if (in_array('custom_' . $customKey['1'], $returnCustomProperties)) {
-            $event[$eventDAO->id][$key] = $val;
-          }
-        }
-        else {
-          $event[$eventDAO->id][$key] = $val;
-        }
-      }
-    }
-  }
-  //end of the loop
-  $eventDAO->free();
-  return $event;
-}
-
-/**
- * Deletes an existing event
- *
- * This API is used for deleting a event
- *
- * @param  Array  $params    array containing event_id to be deleted
- *
- * @return boolean        true if success, error otherwise
- * @access public
- */
-function civicrm_event_delete(&$params) {
-  if (empty($params)) {
-    return civicrm_create_error(ts('No input parameters present'));
-  }
-
-  $eventID = NULL;
-
-  $eventID = CRM_Utils_Array::value('event_id', $params);
-
-  if (!isset($eventID)) {
-    return civicrm_create_error(ts('Invalid value for eventID'));
-  }
-
-  require_once 'CRM/Event/BAO/Event.php';
-
-  return CRM_Event_BAO_Event::del($eventID) ? civicrm_create_success() : civicrm_create_error(ts('Error while deleting event'));
-}
-
diff --git a/api/v2/File.php b/api/v2/File.php
deleted file mode 100644
index 086d3ecc23..0000000000
--- a/api/v2/File.php
+++ /dev/null
@@ -1,331 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- *
- * Definition of the Tag of the CRM API.
- * More detailed documentation can be found
- * {@link http://objectledge.org/confluence/display/CRM/CRM+v1.0+Public+APIs
- * here}
- *
- * @package CiviCRM_APIv2
- * @subpackage API_File
- * @copyright CiviCRM LLC (c) 2004-2013
- * $Id: $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Create a file
- *
- * This API is used for creating a file
- *
- * @param   array  $params  an associative array of name/value property values of civicrm_file
- *
- * @return array of newly created file property values.
- * @access public
- */
-function civicrm_file_create($params) {
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array.');
-  }
-
-  if (!isset($params['file_type_id'])) {
-    return civicrm_create_error('Required parameter missing.');
-  }
-
-  if (!isset($params['upload_date'])) {
-    $params['upload_date'] = date("Ymd");
-  }
-
-  require_once 'CRM/Core/DAO/File.php';
-
-  $fileDAO = new CRM_Core_DAO_File();
-  $properties = array('id', 'file_type_id', 'mime_type', 'uri', 'document', 'description', 'upload_date');
-
-  foreach ($properties as $name) {
-    if (array_key_exists($name, $params)) {
-      $fileDAO->$name = $params[$name];
-    }
-  }
-
-  $fileDAO->save();
-
-  $file = array();
-  _civicrm_object_to_array($fileDAO, $file);
-
-  return $file;
-}
-
-/**
- * Get a file.
- *
- * This api is used for finding an existing file.
- * Required parameters : id OR file_type_id of a file
- *
- * @param  array $params  an associative array of name/value property values of civicrm_file
- *
- * @return  Array of all found file object property values.
- * @access public
- */
-function civicrm_file_get($params) {
-  if (!is_array($params)) {
-    return civicrm_create_error('params is not an array.');
-  }
-
-  if (!isset($params['id']) && !isset($params['file_type_id'])) {
-    return civicrm_create_error('Required parameters missing.');
-  }
-
-  require_once 'CRM/Core/DAO/File.php';
-  $fileDAO = new CRM_Core_DAO_File();
-
-  $properties = array('id', 'file_type_id', 'mime_type', 'uri', 'document', 'description', 'upload_date');
-
-  foreach ($properties as $name) {
-    if (array_key_exists($name, $params)) {
-      $fileDAO->$name = $params[$name];
-    }
-  }
-
-  if ($fileDAO->find()) {
-    $file = array();
-    while ($fileDAO->fetch()) {
-      _civicrm_object_to_array(clone($fileDAO), $file);
-      $files[$fileDAO->id] = $file;
-    }
-  }
-  else {
-    return civicrm_create_error('Exact match not found');
-  }
-  return $files;
-}
-
-/**
- * Update an existing file
- *
- * This api is used for updating an existing file.
- * Required parrmeters : id of a file
- *
- * @param  Array   $params  an associative array of name/value property values of civicrm_file
- *
- * @return array of updated file object property values
- * @access public
- */
-function &civicrm_file_update(&$params) {
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array');
-  }
-
-  if (!isset($params['id'])) {
-    return civicrm_create_error('Required parameter missing');
-  }
-
-  require_once 'CRM/Core/DAO/File.php';
-  $fileDAO = new CRM_Core_DAO_File();
-  $fileDAO->id = $params['id'];
-  if ($fileDAO->find(TRUE)) {
-    $fileDAO->copyValues($params);
-    if (!$params['upload_date'] && !$fileDAO->upload_date) {
-      $fileDAO->upload_date = date("Ymd");
-    }
-    $fileDAO->save();
-  }
-  $file = array();
-  _civicrm_object_to_array(clone($fileDAO), $file);
-  return $file;
-}
-
-/**
- * Deletes an existing file
- *
- * This API is used for deleting a file
- * Required parameters : id of a file
- *
- * @param  Int  $fileId  Id of the file to be deleted
- *
- * @return null if successfull, object of CRM_Core_Error otherwise
- * @access public
- */
-function &civicrm_file_delete($fileId) {
-  if (empty($fileId)) {
-    return civicrm_create_error('Required parameter missing');
-  }
-
-  $check = FALSE;
-
-  require_once 'CRM/Core/DAO/EntityFile.php';
-  $entityFileDAO = new CRM_Core_DAO_EntityFile();
-  $entityFileDAO->file_id = $fileId;
-  if ($entityFileDAO->find()) {
-    $check = $entityFileDAO->delete();
-  }
-
-  require_once 'CRM/Core/DAO/File.php';
-  $fileDAO = new CRM_Core_DAO_File();
-  $fileDAO->id = $fileId;
-  if ($fileDAO->find(TRUE)) {
-    $check = $fileDAO->delete();
-  }
-
-  return $check ? NULL : civicrm_create_error('Error while deleting a file.');
-}
-
-/**
- * Assigns an entity to a file
- *
- * @param object  $file            id of a file
- * @param object  $entity          id of a entity
- * @param string  $entity_table
- *
- * @return array of newly created entity-file object properties
- * @access public
- */
-function civicrm_entity_file_create(&$fileID, &$entityID, $entity_table = 'civicrm_contact') {
-  require_once 'CRM/Core/DAO/EntityFile.php';
-
-  if (!$fileID || !$entityID) {
-    return civicrm_create_error('Required parameters missing');
-  }
-
-  $params = array(
-    'entity_id' => $entityID,
-    'file_id' => $fileID,
-    'entity_table' => $entity_table,
-  );
-
-  $entityFileDAO = new CRM_Core_DAO_EntityFile();
-  $entityFileDAO->copyValues($params);
-  $entityFileDAO->save();
-
-  $entityFile = array();
-  _civicrm_object_to_array($entityFileDAO, $entityFile);
-
-  return $entityFile;
-}
-
-/**
- * Attach a file to a given entity
- *
- * @param string   $name          filename
- * @param object   $entityID      id of the supported entity.
- * @param string   $entity_table
- *
- * @access public
- */
-function civicrm_file_by_entity_add($name, $entityID, $entityTable = 'civicrm_contact', $params) {
-  require_once 'CRM/Core/BAO/File.php';
-  CRM_Core_BAO_File::filePostProcess($name, NULL, $entityTable, $entityID, NULL, FALSE, $params);
-}
-
-/**
- * Returns all files assigned to a single entity instance.
- *
- * @param object $entityID         id of the supported entity.
- * @param string $entity_table
- *
- * @return array   nested array of entity-file property values.
- * @access public
- */
-function civicrm_files_by_entity_get($entityID, $entityTable = 'civicrm_contact', $fileID = NULL) {
-  if (!$entityID) {
-    return civicrm_create_error('Required parameters missing');
-  }
-
-  require_once 'CRM/Core/DAO/EntityFile.php';
-  require_once 'CRM/Core/DAO/File.php';
-
-  $entityFileDAO = new CRM_Core_DAO_EntityFile();
-  $entityFileDAO->entity_table = $entityTable;
-  $entityFileDAO->entity_id = $entityID;
-  if ($fileID) {
-    $entityFileDAO->file_id = $fileID;
-  }
-  if ($entityFileDAO->find()) {
-    $entityFile = array();
-    while ($entityFileDAO->fetch()) {
-      _civicrm_object_to_array($entityFileDAO, $entityFile);
-      $files[$entityFileDAO->file_id] = $entityFile;
-
-      if (array_key_exists('file_id', $files[$entityFileDAO->file_id])) {
-        $fileDAO = new CRM_Core_DAO_File();
-        $fileDAO->id = $entityFile['file_id'];
-        $fileDAO->find(TRUE);
-        _civicrm_object_to_array($fileDAO, $files[$entityFileDAO->file_id]);
-      }
-
-      if (CRM_Utils_Array::value('file_type_id', $files[$entityFileDAO->file_id])) {
-        $files[$entityFileDAO->file_id]['file_type'] = CRM_Core_OptionGroup::getLabel('file_type',
-          $files[$entityFileDAO->file_id]['file_type_id']
-        );
-      }
-    }
-  }
-  else {
-    return civicrm_create_error('Exact match not found');
-  }
-
-  return $files;
-}
-
-/**
- * Deletes an existing entity file assignment.
- * Required parameters : 1.  id of an entity-file
- *                       2.  entity_id and entity_table of an entity-file
- *
- * @param   array $params   an associative array of name/value property values of civicrm_entity_file.
- *
- * @return  null if successfull, object of CRM_Core_Error otherwise
- * @access public
- */
-function civicrm_entity_file_delete(&$params) {
-  require_once 'CRM/Core/DAO/EntityFile.php';
-
-  //if ( ! isset($params['id']) && ( !isset($params['entity_id']) || !isset($params['entity_file']) ) ) {
-  if (!isset($params['id']) && (!isset($params['entity_id']) || !isset($params['entity_table']))) {
-    return civicrm_create_error('Required parameters missing');
-  }
-
-  $entityFileDAO = new CRM_Core_DAO_EntityFile();
-
-  $properties = array('id', 'entity_id', 'entity_table', 'file_id');
-  foreach ($properties as $name) {
-    if (array_key_exists($name, $params)) {
-      $entityFileDAO->$name = $params[$name];
-    }
-  }
-
-  return $entityFileDAO->delete() ? NULL : civicrm_create_error('Error while deleting');
-}
-
diff --git a/api/v2/Group.php b/api/v2/Group.php
deleted file mode 100644
index 7aac363df7..0000000000
--- a/api/v2/Group.php
+++ /dev/null
@@ -1,153 +0,0 @@
-<?php
-// $Id: Group.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 group functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Group
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Group.php 45502 2013-02-08 13:32:55Z kurund $
- */
-
-/**
- * Include utility functions
- */
-require_once 'CRM/Contact/BAO/Group.php';
-require_once 'api/v2/utils.php';
-
-/**
- * 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
- *
- * @access public
- */
-function civicrm_group_add(&$params) {
-  _civicrm_initialize();
-  if (is_null($params) || !is_array($params) || empty($params)) {
-    return civicrm_create_error('Required parameter missing');
-  }
-
-  if (!CRM_Utils_Array::value('title', $params)) {
-    return civicrm_create_error('Required parameter title missing');
-  }
-
-  $group = CRM_Contact_BAO_Group::create($params);
-
-  if (is_null($group)) {
-    return civicrm_create_error('Group not created');
-  }
-  else {
-    return civicrm_create_success($group);
-  }
-}
-/*
- * Wrapper for civicrm_group_add so function can take new (v3) name
- */
-function civicrm_group_create(&$params) {
-  $result = civicrm_group_add($params);
-  return $result;
-}
-
-/**
- * Returns array of groups  matching a set of one or more group properties
- *
- * @param array $params  (referance) Array of one or more valid
- *                       property_name=>value pairs. If $params is set
- *                       as null, all groups will be returned
- *
- * @return array  (referance) Array of matching groups
- * @access public
- */
-function civicrm_group_get(&$params) {
-  _civicrm_initialize();
-  if (!is_null($params) && !is_array($params)) {
-    return civicrm_create_error('Params should be array');
-  }
-
-  $returnProperties = array();
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 7) == 'return.') {
-      $returnProperties[] = substr($n, 7);
-    }
-  }
-
-  if (!empty($returnProperties)) {
-    $returnProperties[] = 'id';
-  }
-
-  $groupObjects = CRM_Contact_BAO_Group::getGroups($params, $returnProperties);
-
-  if (count($groupObjects) == 0) {
-    return civicrm_create_error('No such group exists');
-  }
-
-  $groups = array();
-  foreach ($groupObjects as $group) {
-    _civicrm_object_to_array($group, $groups[$group->id]);
-  }
-
-  return $groups;
-}
-
-/**
- * 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);
-}
-
diff --git a/api/v2/GroupContact.php b/api/v2/GroupContact.php
deleted file mode 100644
index cc2c49ad6c..0000000000
--- a/api/v2/GroupContact.php
+++ /dev/null
@@ -1,199 +0,0 @@
-<?php
-// $Id: GroupContact.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 group contact functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Group
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: GroupContact.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- * This API will give list of the groups for particular contact
- * Particualr status can be sent in params array
- * If no status mentioned in params, by default 'added' will be used
- * to fetch the records
- *
- * @param  array $params  name value pair of contact information
- *
- * @return  array  list of groups, given contact subsribed to
- */
-function civicrm_group_contact_get(&$params) {
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('input parameter should be an array'));
-  }
-
-  if (!array_key_exists('contact_id', $params)) {
-    return civicrm_create_error(ts('contact_id is a required field'));
-  }
-
-  $status = CRM_Utils_Array::value('status', $params, 'Added');
-  require_once 'CRM/Contact/BAO/GroupContact.php';
-  $values = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'], $status, NULL, FALSE, TRUE);
-  return $values;
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_group_contact_add(&$params) {
-  return civicrm_group_contact_common($params, 'add');
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_group_contact_remove(&$params) {
-  return civicrm_group_contact_common($params, 'remove');
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_group_contact_pending(&$params) {
-  return civicrm_group_contact_common($params, 'pending');
-}
-
-/**
- *
- * @param <type> $params
- * @param <type> $op
- *
- * @return <type>
- */
-function civicrm_group_contact_common(&$params, $op = 'add') {
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('input parameter should be an array'));
-  }
-
-  $contactIDs = array();
-  $groupIDs = array();
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 10) == 'contact_id') {
-      $contactIDs[] = $v;
-    }
-    elseif (substr($n, 0, 8) == 'group_id') {
-      $groupIDs[] = $v;
-    }
-  }
-
-  if (empty($contactIDs)) {
-    return civicrm_create_error(ts('contact_id is a required field'));
-  }
-
-  if (empty($groupIDs)) {
-    return civicrm_create_error(ts('group_id is a required field'));
-  }
-
-  $method = CRM_Utils_Array::value('method', $params, 'API');
-  if ($op == 'add') {
-    $status = CRM_Utils_Array::value('status', $params, 'Added');
-  }
-  elseif ($op == 'pending') {
-    $status = CRM_Utils_Array::value('status', $params, 'Pending');
-  }
-  else {
-    $status = CRM_Utils_Array::value('status', $params, 'Removed');
-  }
-  $tracking = CRM_Utils_Array::value('tracking', $params);
-
-  require_once 'CRM/Contact/BAO/GroupContact.php';
-  $values = array('is_error' => 0);
-  if ($op == 'add' || $op == 'pending') {
-    $values['total_count'] = $values['added'] = $values['not_added'] = 0;
-    foreach ($groupIDs as $groupID) {
-      list($tc, $a, $na) = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIDs, $groupID,
-        $method, $status, $tracking
-      );
-      $values['total_count'] += $tc;
-      $values['added'] += $a;
-      $values['not_added'] += $na;
-    }
-  }
-  else {
-    $values['total_count'] = $values['removed'] = $values['not_removed'] = 0;
-    foreach ($groupIDs as $groupID) {
-      list($tc, $r, $nr) = CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIDs, $groupID,
-        $method, $status, $tracking
-      );
-      $values['total_count'] += $tc;
-      $values['removed'] += $r;
-      $values['not_removed'] += $nr;
-    }
-  }
-  return $values;
-}
-
-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;
-}
-
diff --git a/api/v2/GroupNesting.php b/api/v2/GroupNesting.php
deleted file mode 100644
index 02d46f7575..0000000000
--- a/api/v2/GroupNesting.php
+++ /dev/null
@@ -1,155 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 group nesting functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Group
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: GroupNesting.php 21624 2009-08-07 22:02:55Z wmorgan $
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Provides group nesting record(s) given parent and/or child id.
- *
- * @param  array $params  an array containing at least child_group_id or parent_group_id
- *
- * @return  array  list of group nesting records
- */
-function civicrm_group_nesting_get(&$params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-
-  if (!array_key_exists('child_group_id', $params) &&
-    !array_key_exists('parent_group_id', $params)
-  ) {
-    return civicrm_create_error(ts('At least one of child_group_id or parent_group_id is a required field'));
-  }
-
-  require_once 'CRM/Contact/DAO/GroupNesting.php';
-  $dao = new CRM_Contact_DAO_GroupNesting();
-  if (array_key_exists('child_group_id', $params)) {
-    $dao->child_group_id = $params['child_group_id'];
-  }
-  if (array_key_exists('parent_group_id', $params)) {
-    $dao->parent_group_id = $params['parent_group_id'];
-  }
-
-  $values = array();
-
-  if ($dao->find()) {
-    while ($dao->fetch()) {
-      $temp = array();
-      _civicrm_object_to_array($dao, $temp);
-      $values[$dao->id] = $temp;
-    }
-    $values['is_error'] = 0;
-  }
-  else {
-    return civicrm_create_error('No records found.');
-  }
-
-  return $values;
-}
-
-/**
- * Creates group nesting record for given parent and child id.
- * Parent and child groups need to exist.
- *
- * @param array &$params parameters array - allowed array keys include:
- * {@schema Contact/GroupNesting.xml}
- *
- * @return array TBD
- *
- * @todo Work out the return value.
- */
-function civicrm_group_nesting_create(&$params) {
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-
-  require_once 'CRM/Contact/BAO/GroupNesting.php';
-
-  if (!array_key_exists('child_group_id', $params) &&
-    !array_key_exists('parent_group_id', $params)
-  ) {
-    return civicrm_create_error(ts('You need to define parent_group_id and child_group_id in params.'));
-  }
-
-  CRM_Contact_BAO_GroupNesting::add($params['parent_group_id'], $params['child_group_id']);
-
-  // FIXME: CRM_Contact_BAO_GroupNesting requires some work
-  $result = array('is_error' => 0);
-  return $result;
-}
-
-/**
- * Removes specific nesting records.
- *
- * @param array &$params parameters array - allowed array keys include:
- * {@schema Contact/GroupNesting.xml}
- *
- * @return array TBD
- *
- * @todo Work out the return value.
- */
-function civicrm_group_nesting_remove(&$params) {
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-
-  if (!array_key_exists('child_group_id', $params) ||
-    !array_key_exists('parent_group_id', $params)
-  ) {
-    return civicrm_create_error(ts('You need to define parent_group_id and child_group_id in params.'));
-  }
-
-  require_once 'CRM/Contact/DAO/GroupNesting.php';
-  $dao = new CRM_Contact_DAO_GroupNesting();
-  $dao->copyValues($params);
-
-  if ($dao->delete()) {
-    $result = array('is_error' => 0);
-  }
-  return $result;
-}
-
diff --git a/api/v2/GroupOrganization.php b/api/v2/GroupOrganization.php
deleted file mode 100644
index ae5b0f9e22..0000000000
--- a/api/v2/GroupOrganization.php
+++ /dev/null
@@ -1,148 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 group contact functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Group
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: GroupContact.php 21624 2009-06-04 22:02:55Z mover $
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- * This API will give list of the groups for particular contact
- * Particualr status can be sent in params array
- * If no status mentioned in params, by default 'added' will be used
- * to fetch the records
- *
- * @param  array $params  name value pair of contact information
- *
- * @return  array  list of groups, given contact subsribed to
- */
-function civicrm_group_organization_get(&$params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Input parameter is not an array'));
-  }
-
-  if (empty($params)) {
-    return civicrm_create_error('No input parameter present');
-  }
-
-  if (!array_key_exists('organization_id', $params) &&
-    !array_key_exists('group_id', $params)
-  ) {
-    return civicrm_create_error(ts('at least one of organization_id or group_id is a required field'));
-  }
-
-  require_once 'CRM/Contact/DAO/GroupOrganization.php';
-  $dao = new CRM_Contact_DAO_GroupOrganization();
-  if (array_key_exists('organization_id', $params)) {
-    $dao->organization_id = $params['organization_id'];
-  }
-  if (array_key_exists('group_id', $params)) {
-    $dao->group_id = $params['group_id'];
-  }
-  $dao->find();
-  $values = array();
-  _civicrm_object_to_array($dao, $values);
-  return civicrm_create_success($values);
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_group_organization_create(&$params) {
-
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Input parameter is not an array'));
-  }
-
-  if (empty($params)) {
-    return civicrm_create_error('No input parameter present');
-  }
-
-  if (!array_key_exists('organization_id', $params) ||
-    !array_key_exists('group_id', $params)
-  ) {
-    return civicrm_create_error(ts('organization_id and group_id are required field'));
-  }
-
-  require_once 'CRM/Contact/BAO/GroupOrganization.php';
-  $groupOrgBAO = CRM_Contact_BAO_GroupOrganization::add($params);
-  if (is_a($groupOrgBAO, 'CRM_Core_Error') || is_null($groupOrgBAO)) {
-    return civicrm_create_error("Group Organization can not be created");
-  }
-  _civicrm_object_to_array($groupOrgBAO, $values);
-  return civicrm_create_success($values);
-}
-
-/**
- * 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['id']);
-  return $result ? civicrm_create_success(ts('Deleted Group Organization successfully')) : civicrm_create_error(ts('Could not delete Group Organization'));
-}
-
diff --git a/api/v2/Location.php b/api/v2/Location.php
deleted file mode 100644
index 14fe867dae..0000000000
--- a/api/v2/Location.php
+++ /dev/null
@@ -1,978 +0,0 @@
-<?php
-// $Id: Location.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 location functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Location
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Location.php 45502 2013-02-08 13:32:55Z kurund $
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Create an additional location for an existing contact
- *
- * @param array $params  input properties
- *
- * @return array  the created location's params
- *
- * @access public
- */
-function civicrm_location_add(&$params) {
-  _civicrm_initialize();
-
-  $error = _civicrm_location_check_params($params);
-
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $locationTypeId = CRM_Utils_Array::value('location_type_id', $params);
-  if (!$locationTypeId &&
-    '2.0' == CRM_Utils_Array::value('location_format', $params)
-  ) {
-    require_once 'CRM/Core/DAO/LocationType.php';
-    $locationTypeDAO = new CRM_Core_DAO_LocationType();
-    $locationTypeDAO->name = $params['location_type'];
-    $locationTypeDAO->find(TRUE);
-    $locationTypeId = $locationTypeDAO->id;
-
-    CRM_Core_PseudoConstant::flush('locationType');
-
-    if (!isset($locationTypeId)) {
-      return civicrm_create_error(ts('$location_type is not valid one'));
-    }
-  }
-
-  $location = &_civicrm_location_add($params, $locationTypeId);
-  return $location;
-}
-/*
- * Correctly named wrapper for 'add' function
- */
-function civicrm_location_create($params) {
-  $result = civicrm_location_add($params);
-  return $result;
-}
-
-/**
- *  Update a specified location with the provided property values.
- *
- *  @param  object  $contact        A valid Contact object (passed by reference).
- *  @param  string  $location_id    Valid (db-level) id for location to be updated.
- *  @param  Array   $params         Associative array of property name/value pairs to be updated
- *
- *  @return Location object with updated property values
- *
- *  @access public
- *
- */
-function civicrm_location_update($params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-
-  if (!isset($params['contact_id'])) {
-    return civicrm_create_error(ts('$contact is not valid contact datatype'));
-  }
-
-  $unsetVersion     = FALSE;
-  $locationTypes    = array();
-  $hasLocBlockId    = FALSE;
-  $allLocationTypes = CRM_Core_PseudoConstant::locationType(TRUE);
-  if ('2.0' == CRM_Utils_Array::value('location_format', $params)) {
-    //force to use 3.0 location_format for get location api's.
-    $params['location_format'] = '3.0';
-    $unsetVersion = TRUE;
-
-    if (!($locationTypeId = CRM_Utils_Array::value('location_type_id', $params)) &&
-      !(CRM_Utils_Rule::integer($locationTypeId))
-    ) {
-      return civicrm_create_error(ts('missing or invalid location_type_id'));
-    }
-    $locationTypes = CRM_Utils_Array::value('location_type', $params);
-
-    //if location_type array absent and location_type_id pass build array.
-    if ((!is_array($locationTypes) || !count($locationTypes)) && $locationTypeId) {
-      require_once 'CRM/Core/PseudoConstant.php';
-      if ($locName = CRM_Utils_Array::value($locationTypeId, $allLocationTypes)) {
-        $locationTypes = array($locName);
-      }
-    }
-  }
-  else {
-    $locTypeIds = array();
-    foreach (array(
-      'email', 'phone', 'im', 'address', 'openid') as $name) {
-      if (isset($params[$name]) && is_array($params[$name])) {
-        foreach ($params[$name] as $count => & $values) {
-          $locName = CRM_Utils_Array::value('location_type', $values);
-          $LocTypeId = CRM_Utils_Array::value('location_type_id', $values);
-          if ($locName && !in_array($locName, $locationTypes)) {
-            $locationTypes[] = $locName;
-          }
-          if ($LocTypeId) {
-            $locTypeIds[$LocTypeId] = $LocTypeId;
-          }
-          elseif (in_array($locName, $allLocationTypes)) {
-            $values['location_type_id'] = array_search($locName, $allLocationTypes);
-          }
-          if (!$hasLocBlockId && CRM_Utils_Array::value('id', $values)) {
-            $hasLocBlockId = TRUE;
-          }
-        }
-      }
-    }
-
-    //get all location types.
-    foreach ($locTypeIds as $locId) {
-      $name = CRM_Utils_Array::value($locId, $allLocationTypes);
-      if (!$name) {
-        return civicrm_create_error(ts('Invalid Location Type Id : %1', array(1 => $locId)));
-      }
-      if (!in_array($name, $locationTypes)) {
-        $locationTypes[] = $name;
-      }
-    }
-  }
-
-  $invalidTypes = array();
-  foreach ($locationTypes as $name) {
-    if (!in_array($name, $allLocationTypes)) {
-      $invalidTypes[$name] = $name;
-    }
-  }
-  if (!empty($invalidTypes)) {
-    return civicrm_create_error(ts("Invalid Location Type(s) : %1", array(1 => implode(', ', $invalidTypes))));
-  }
-
-  //allow to swap locations.
-  if ($hasLocBlockId) {
-    $locationTypes = $allLocationTypes;
-  }
-
-  if (!empty($locationTypes)) {
-    $params['location_type'] = $locationTypes;
-  }
-  else {
-    return civicrm_create_error(ts('missing or invalid location_type_id'));
-  }
-
-  //get location filter by loc type.
-  $locations = &civicrm_location_get($params);
-
-  if ($unsetVersion) {
-    unset($params['location_format']);
-  }
-
-  if (CRM_Utils_System::isNull($locations)) {
-    return civicrm_create_error(ts("Invalid Location Type(s) : %1",
-        array(1 => implode(', ', CRM_Utils_Array::value('location_type', $params)))
-      ));
-  }
-
-  $location = &_civicrm_location_update($params, $locations);
-  return $location;
-}
-
-/**
- * Deletes a contact location.
- *
- * @param object $contact        A valid Contact object (passed by reference).
- * @param string $location_id    A valid location ID.
- *
- * @return  null, if successful. CRM error object, if 'contact' or 'location_id' is invalid, permissions are insufficient, etc.
- *
- * @access public
- *
- */
-function civicrm_location_delete(&$contact) {
-  _civicrm_initialize();
-
-  if (!is_array($contact)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-
-  if (!isset($contact['contact_id'])) {
-    return civicrm_create_error(ts('$contact is not valid contact datatype'));
-  }
-
-  require_once 'CRM/Utils/Rule.php';
-  $locationTypeID = CRM_Utils_Array::value('location_type', $contact);
-  if (!$locationTypeID ||
-    !CRM_Utils_Rule::integer($locationTypeID)
-  ) {
-    return civicrm_create_error(ts('missing or invalid location'));
-  }
-
-  $result = &_civicrm_location_delete($contact);
-
-  return $result;
-}
-
-/**
- * Returns array of location(s) for a contact
- *
- * @param array $contact  a valid array of contact parameters
- *
- * @return array  an array of location parameters arrays
- *
- * @access public
- */
-function civicrm_location_get($contact) {
-  _civicrm_initialize();
-
-  if (!is_array($contact)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-
-  if (!isset($contact['contact_id'])) {
-    return civicrm_create_error('$contact is not valid contact datatype');
-  }
-
-  $locationTypes = CRM_Utils_Array::value('location_type', $contact);
-
-  if (is_array($locationTypes) && !count($locationTypes)) {
-    return civicrm_create_error('Location type array can not be empty');
-  }
-
-  $location = &_civicrm_location_get($contact, $locationTypes);
-
-  return $location;
-}
-
-/**
- *
- * @param <type> $params
- * @param <type> $locationTypeId
- *
- * @return <type>
- */
-function _civicrm_location_add(&$params, $locationTypeId = NULL) {
-  // convert api params to 3.0 format.
-  if ('2.0' == CRM_Utils_Array::value('location_format', $params)) {
-    _civicrm_format_params_v2_to_v3($params, $locationTypeId);
-  }
-
-  // Get all existing location blocks.
-  $blockParams = array(
-    'contact_id' => $params['contact_id'],
-    'entity_id' => $params['contact_id'],
-  );
-
-  require_once 'CRM/Core/BAO/Location.php';
-  $allBlocks = CRM_Core_BAO_Location::getValues($blockParams);
-
-  // get all blocks in contact array.
-  $contact = array_merge(array('contact_id' => $params['contact_id']), $allBlocks);
-
-  // copy params value in contact array.
-  $primary = $billing = array();
-  foreach (array(
-    'email', 'phone', 'im', 'openid') as $name) {
-    if (CRM_Utils_Array::value($name, $params)) {
-      if (!isset($contact[$name]) ||
-        !is_array($contact[$name])
-      ) {
-        $contact[$name] = array();
-      }
-
-      $blockCount = count($contact[$name]);
-      if (is_array($params[$name])) {
-        foreach ($params[$name] as $val) {
-          $contact[$name][++$blockCount] = $val;
-          // 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;
-          }
-        }
-      }
-    }
-  }
-
-  // get loc type id from params.
-  if (!$locationTypeId) {
-    $locationTypeId = CRM_Utils_Array::value('location_type_id', $params['address'][1]);
-  }
-
-  // address having 1-1 ( loc type - address ) mapping.
-  $addressCount = 1;
-  if (array_key_exists('address', $contact) && is_array($contact['address'])) {
-    foreach ($contact['address'] as $addCount => $values) {
-      if ($locationTypeId == CRM_Utils_Array::value('location_type_id', $values)) {
-        $addressCount = $addCount;
-        break;
-      }
-      $addressCount++;
-    }
-  }
-
-  if (CRM_Utils_Array::value('1', $params['address']) && !empty($params['address'][1])) {
-    $contact['address'][$addressCount] = $params['address'][1];
-
-    // check for primary and billing address.
-    if (CRM_Utils_Array::value('is_primary', $params['address'][1])) {
-      $primary['address'][$addressCount] = TRUE;
-    }
-    if (CRM_Utils_Array::value('is_billing', $params['address'][1])) {
-      $billing['address'][$addressCount] = TRUE;
-    }
-
-    // format state and country.
-    foreach (array(
-      'state_province', 'country') as $field) {
-      $fName = ($field == 'state_province') ? 'stateProvinceAbbreviation' : 'countryIsoCode';
-      if (CRM_Utils_Array::value($field, $contact['address'][$addressCount]) &&
-        is_numeric($contact['address'][$addressCount][$field])
-      ) {
-        $fValue = &$contact['address'][$addressCount][$field];
-        eval('$fValue = CRM_Core_PseudoConstant::' . $fName . '( $fValue );');
-
-        //kill the reference.
-        unset($fValue);
-      }
-    }
-  }
-
-  //handle primary and billing reset.
-  foreach (array(
-    'email', 'phone', 'im', 'address', 'openid') as $name) {
-    if (!array_key_exists($name, $contact) || CRM_Utils_System::isNull($contact[$name])) {
-      continue;
-    }
-
-    $errorMsg = NULL;
-    $primaryBlockIndex = $billingBlockIndex = 0;
-    if (array_key_exists($name, $primary)) {
-      if (count($primary[$name]) > 1) {
-        $errorMsg .= ts("Multiple primary %1.", array(1 => $name));
-      }
-      else {
-        $primaryBlockIndex = key($primary[$name]);
-      }
-    }
-
-    if (array_key_exists($name, $billing)) {
-      if (count($billing[$name]) > 1) {
-        $errorMsg .= ts("Multiple billing %1.", array(1 => $name));
-      }
-      else {
-        $billingBlockIndex = key($billing[$name]);
-      }
-    }
-
-    if ($errorMsg) {
-      return civicrm_create_error($errorMsg);
-    }
-
-    foreach ($contact[$name] as $count => & $values) {
-      if ($primaryBlockIndex && ($count != $primaryBlockIndex)) {
-        $values['is_primary'] = FALSE;
-      }
-      if ($billingBlockIndex && ($count != $billingBlockIndex)) {
-        $values['is_billing'] = FALSE;
-      }
-
-      //kill the reference.
-      unset($values);
-    }
-  }
-
-  // get all ids if not present.
-  require_once 'CRM/Contact/BAO/Contact.php';
-  CRM_Contact_BAO_Contact::resolveDefaults($contact, TRUE);
-
-  require_once 'CRM/Core/BAO/Location.php';
-  $result = CRM_Core_BAO_Location::create($contact);
-
-  if (empty($result)) {
-    return civicrm_create_error(ts("Location not created"));
-  }
-
-  $blocks = array('address', 'phone', 'email', 'im', 'openid');
-  foreach ($blocks as $block) {
-    for ($i = 0; $i < count($result[$block]); $i++) {
-      $locArray[$block][$i] = $result[$block][$i]->id;
-    }
-  }
-
-  // CRM-4800
-  if (2.0 == CRM_Utils_Array::value('location_format', $params)) {
-    $locArray['location_type_id'] = $locationTypeId;
-  }
-
-  return civicrm_create_success($locArray);
-}
-
-/**
- *
- * @param <type> $params
- * @param <type> $locationArray
- *
- * @return <type>
- */
-function _civicrm_location_update($params, $locations) {
-  // convert api params to 3.0 format.
-  if ('2.0' == CRM_Utils_Array::value('location_format', $params)) {
-    _civicrm_format_params_v2_to_v3($params);
-  }
-
-  $contact = array('contact_id' => $params['contact_id']);
-  $primary = $billing = array();
-
-  // copy params value in contact array.
-  foreach (array(
-    'email', 'phone', 'im', 'openid') as $name) {
-    if (CRM_Utils_Array::value($name, $params) && is_array($params[$name])) {
-      $blockCount = 0;
-      $contact[$name] = array();
-      foreach ($params[$name] as $val) {
-        $contact[$name][++$blockCount] = $val;
-        // 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;
-        }
-      }
-    }
-    else {
-      // get values from db blocks so we dont lose them.
-      if (!CRM_Utils_Array::value($name, $locations) || !is_array($locations[$name])) {
-        continue;
-      }
-      $contact[$name] = $locations[$name];
-    }
-  }
-
-  $addressCount = 1;
-  if (CRM_Utils_Array::value(1, $params['address']) && !empty($params['address'][1])) {
-    $contact['address'][$addressCount] = $params['address'][1];
-
-    // check for primary and billing address.
-    if (CRM_Utils_Array::value('is_primary', $params['address'][1])) {
-      $primary['address'][$addressCount] = TRUE;
-    }
-    if (CRM_Utils_Array::value('is_billing', $params['address'][1])) {
-      $billing['address'][$addressCount] = TRUE;
-    }
-
-    // format state and country.
-    foreach (array(
-      'state_province', 'country') as $field) {
-      $fName = ($field == 'state_province') ? 'stateProvinceAbbreviation' : 'countryIsoCode';
-      if (CRM_Utils_Array::value($field, $contact['address'][$addressCount]) &&
-        is_numeric($contact['address'][$addressCount][$field])
-      ) {
-        $fValue = &$contact['address'][$addressCount][$field];
-        eval('$fValue = CRM_Core_PseudoConstant::' . $fName . '( $fValue );');
-
-        //kill the reference.
-        unset($fValue);
-      }
-    }
-  }
-
-  //handle primary and billing reset.
-  foreach (array(
-    'email', 'phone', 'im', 'address', 'openid') as $name) {
-    if (!array_key_exists($name, $contact) || CRM_Utils_System::isNull($contact[$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 => $name));
-      }
-      else {
-        $primaryBlockIndex = key($primary[$name]);
-      }
-    }
-
-    if (array_key_exists($name, $billing)) {
-      if (count($billing[$name]) > 1) {
-        $errorMsg .= ts("<br />Multiple Billing %1.", array(1 => $name));
-      }
-      else {
-        $billingBlockIndex = key($billing[$name]);
-      }
-    }
-
-    if ($errorMsg) {
-      return civicrm_create_error($errorMsg);
-    }
-
-    foreach ($contact[$name] as $count => & $values) {
-      if ($primaryBlockIndex && ($count != $primaryBlockIndex)) {
-        $values['is_primary'] = FALSE;
-      }
-      if ($billingBlockIndex && ($count != $billingBlockIndex)) {
-        $values['is_billing'] = FALSE;
-      }
-      // kill the reference.
-      unset($values);
-    }
-  }
-
-  // get all ids if not present.
-  require_once 'CRM/Contact/BAO/Contact.php';
-  CRM_Contact_BAO_Contact::resolveDefaults($contact, TRUE);
-
-  $location = CRM_Core_BAO_Location::create($contact);
-
-  if (empty($location)) {
-    return civicrm_create_error(ts("Location not created"));
-  }
-
-  $locArray = array();
-
-  $blocks = array('address', 'phone', 'email', 'im', 'openid');
-  $locationTypeId = NULL;
-  foreach ($blocks as $block) {
-    for ($i = 0; $i < count($location[$block]); $i++) {
-      $locArray[$block][$i] = $location[$block][$i]->id;
-      $locationTypeId = $location[$block][$i]->location_type_id;
-    }
-  }
-
-  // CRM-4800
-  if (2.0 == CRM_Utils_Array::value('location_format', $params)) {
-    $locArray['location_type_id'] = $locationTypeId;
-  }
-
-  return civicrm_create_success($locArray);
-}
-
-/**
- *
- * @param <type> $contact
- *
- * @return <type>
- */
-function _civicrm_location_delete(&$contact) {
-  require_once 'CRM/Core/DAO/LocationType.php';
-  $locationTypeDAO = new CRM_Core_DAO_LocationType();
-  $locationTypeDAO->id = $contact['location_type'];
-
-  if (!$locationTypeDAO->find()) {
-    return civicrm_create_error(ts('invalid location type'));
-  }
-
-  require_once 'CRM/Core/BAO/Location.php';
-  CRM_Core_BAO_Location::deleteLocationBlocks($contact['contact_id'], $contact['location_type']);
-
-  return NULL;
-}
-
-/**
- *
- * @param <type> $contact
- * @param <type> $locationTypes = array(
-    'Home', 'Work' ) else empty.
- *
- * @return <type>
- */
-function &_civicrm_location_get($contact, $locationTypes = array(
-  )) {
-  $params = array(
-    'contact_id' => $contact['contact_id'],
-    'entity_id' => $contact['contact_id'],
-  );
-
-  require_once 'CRM/Core/BAO/Location.php';
-  $locations = CRM_Core_BAO_Location::getValues($params);
-
-  $locValues = array();
-
-  // filter the blocks return only those from given loc type.
-  if (is_array($locationTypes) && !empty($locationTypes)) {
-    foreach ($locationTypes as $locName) {
-      if (!$locName) {
-        continue;
-      }
-      if ($locTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', $locName, 'id', 'name')) {
-        foreach (array(
-          'email', 'im', 'phone', 'address', 'openid') as $name) {
-          if (!array_key_exists($name, $locations) || !is_array($locations[$name])) {
-            continue;
-          }
-          $blkCount = 0;
-          if (array_key_exists($name, $locValues)) {
-            $blkCount = count($locValues[$name]);
-          }
-          foreach ($locations[$name] as $count => $values) {
-            if ($locTypeId == $values['location_type_id']) {
-              $locValues[$name][++$blkCount] = $values;
-            }
-          }
-        }
-      }
-    }
-  }
-  else {
-    $locValues = $locations;
-  }
-
-
-  // CRM-4800
-  if ('2.0' == CRM_Utils_Array::value('location_format', $contact)) {
-    _civicrm_location_get_v3_to_v2($locValues);
-  }
-
-  return $locValues;
-}
-
-/**
- * This function ensures that we have the right input location 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 location.
- *
- * @return bool|CRM_Utils_Error
- * @access public
- */
-function _civicrm_location_check_params(&$params) {
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-
-  // cannot create a location with empty params
-  if (empty($params)) {
-    return civicrm_create_error('Input Parameters empty');
-  }
-
-  $errorField = NULL;
-  if (!CRM_Utils_Array::value('contact_id', $params)) {
-    $errorField = 'contact_id';
-  }
-
-  //lets have user option to send location type id or location type.
-  if (!$errorField &&
-    '2.0' == CRM_Utils_Array::value('location_format', $params) &&
-    !CRM_Utils_Array::value('location_type_id', $params) &&
-    !CRM_Utils_Array::value('location_type', $params)
-  ) {
-    $errorField = 'location_type';
-  }
-
-  if (!$errorField) {
-    $blocks = array('address', 'email', 'phone', 'im', 'website');
-    $emptyAddressBlock = TRUE;
-    foreach ($blocks as $block) {
-      if (isset($params[$block]) && !empty($params[$block])) {
-        $emptyAddressBlock = FALSE;
-        break;
-      }
-    }
-
-    if ($emptyAddressBlock) {
-      return civicrm_create_error('Please set atleast one location block. ( address or email or phone or im or website)');
-    }
-  }
-
-  if ($errorField) {
-    return civicrm_create_error("Required fields not found for location $errorField");
-  }
-
-  return array();
-}
-
-/**
- * This function provide interface between v3.0 => v2.2 location blocks.
- */
-function _civicrm_location_get_v3_to_v2(&$locations) {
-  $locValues = $blockCounts = array();
-  $primaryLoc = $billingLoc = FALSE;
-  foreach ($locations as $blockName => $blockValues) {
-    if (!is_array($blockValues) || empty($blockValues)) {
-      continue;
-    }
-    foreach ($blockValues as $count => $values) {
-      $locTypeId = $values['location_type_id'];
-
-      if (!array_key_exists($locTypeId, $locValues)) {
-        $locValues[$locTypeId] = array('location_type_id' => $locTypeId);
-      }
-      if (!array_key_exists($blockName, $locValues[$locTypeId])) {
-        $locValues[$locTypeId][$blockName] = array();
-      }
-      if ($blockName == 'address') {
-        $locValues[$locTypeId][$blockName] = $values;
-      }
-      else {
-        if (!array_key_exists($blockName, $blockCounts) ||
-          !array_key_exists($locTypeId, $blockCounts[$blockName])
-        ) {
-          $blockCounts[$blockName][$locTypeId] = 1;
-        }
-        $blkCount = &$blockCounts[$blockName][$locTypeId];
-        $locValues[$locTypeId][$blockName][$blkCount++] = $values;
-      }
-
-      if (!$primaryLoc && CRM_Utils_Array::value('is_primary', $values)) {
-        $primaryLoc = TRUE;
-        $locValues[$locTypeId]['is_primary'] = TRUE;
-      }
-      if (!$billingLoc && CRM_Utils_Array::value('is_billing', $values)) {
-        $billingLoc = TRUE;
-        $locValues[$locTypeId]['is_billing'] = TRUE;
-      }
-    }
-  }
-
-  foreach (array(
-    'email', 'phone', 'im', 'address', 'openid') as $field) {
-    if (array_key_exists($field, $locations))unset($locations[$field]);
-  }
-  $locations = $locValues;
-
-  return $locValues;
-}
-
-/**
- * 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;
-}
-
diff --git a/api/v2/Mailer.php b/api/v2/Mailer.php
deleted file mode 100644
index 4a9e0c9fa1..0000000000
--- a/api/v2/Mailer.php
+++ /dev/null
@@ -1,389 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- *
- * APIv2 functions for registering/processing mailer events.
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Mailer
- * @copyright CiviCRM LLC (c) 2004-2013
- * $Id$
- *
- */
-
-/**
- * Files required for this package
- */
-
-
-require_once 'api/v2/utils.php';
-
-require_once 'CRM/Contact/BAO/Group.php';
-
-require_once 'CRM/Mailing/BAO/BouncePattern.php';
-require_once 'CRM/Mailing/Event/BAO/Bounce.php';
-require_once 'CRM/Mailing/Event/BAO/Confirm.php';
-require_once 'CRM/Mailing/Event/BAO/Opened.php';
-require_once 'CRM/Mailing/Event/BAO/Queue.php';
-require_once 'CRM/Mailing/Event/BAO/Reply.php';
-require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
-require_once 'CRM/Mailing/Event/BAO/Unsubscribe.php';
-require_once 'CRM/Mailing/Event/BAO/Resubscribe.php';
-require_once 'CRM/Mailing/Event/BAO/Forward.php';
-require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php';
-
-/**
- * Process a bounce event by passing through to the BAOs.
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_bounce($params) {
-  $errors = _civicrm_mailer_check_params($params, array('job_id', 'event_queue_id', 'hash', 'body'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $body = $params['body'];
-  unset($params['body']);
-
-  $params += CRM_Mailing_BAO_BouncePattern::match($body);
-
-  if (CRM_Mailing_Event_BAO_Bounce::create($params)) {
-    return civicrm_create_success();
-  }
-
-  return civicrm_create_error(ts('Queue event could not be found'));
-}
-
-/**
- * Handle an unsubscribe event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_unsubscribe($params) {
-  $errors = _civicrm_mailer_check_params($params, array('job_id', 'event_queue_id', 'hash'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $job   = $params['job_id'];
-  $queue = $params['event_queue_id'];
-  $hash  = $params['hash'];
-
-  $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job, $queue, $hash);
-
-  if (count($groups)) {
-    CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue, $groups, FALSE, $job);
-    return civicrm_create_success();
-  }
-
-  return civicrm_create_error(ts('Queue event could not be found'));
-}
-
-/**
- * Handle a site-level unsubscribe event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_domain_unsubscribe($params) {
-  $errors = _civicrm_mailer_check_params($params, array('job_id', 'event_queue_id', 'hash'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $job   = $params['job_id'];
-  $queue = $params['event_queue_id'];
-  $hash  = $params['hash'];
-
-  $unsubs = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job, $queue, $hash);
-
-  if (!$unsubs) {
-    return civicrm_create_error(ts('Queue event could not be found'));
-  }
-
-  CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue, NULL, TRUE, $job);
-  return civicrm_create_success();
-}
-
-/**
- * Handle a resubscription event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_resubscribe($params) {
-  $errors = _civicrm_mailer_check_params($params, array('job_id', 'event_queue_id', 'hash'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $job   = $params['job_id'];
-  $queue = $params['event_queue_id'];
-  $hash  = $params['hash'];
-
-  $groups = CRM_Mailing_Event_BAO_Resubscribe::resub_to_mailing($job, $queue, $hash);
-
-  if (count($groups)) {
-    CRM_Mailing_Event_BAO_Resubscribe::send_resub_response($queue, $groups, FALSE, $job);
-    return civicrm_create_success();
-  }
-
-  return civicrm_create_error(ts('Queue event could not be found'));
-}
-
-/**
- * Handle a subscription event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_subscribe($params) {
-  $errors = _civicrm_mailer_check_params($params, array('email', 'group_id'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $email      = $params['email'];
-  $group_id   = $params['group_id'];
-  $contact_id = CRM_Utils_Array::value('contact_id', $params);
-
-  $group            = new CRM_Contact_DAO_Group();
-  $group->is_active = 1;
-  $group->id        = (int)$group_id;
-  if (!$group->find(TRUE)) {
-    return civicrm_create_error(ts('Invalid Group id'));
-  }
-
-  $subscribe = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $email, $contact_id);
-
-  if ($subscribe !== NULL) {
-    /* Ask the contact for confirmation */
-
-
-    $subscribe->send_confirm_request($email);
-
-    $values = array();
-    $values['contact_id'] = $subscribe->contact_id;
-    $values['subscribe_id'] = $subscribe->id;
-    $values['hash'] = $subscribe->hash;
-    $values['is_error'] = 0;
-
-    return $values;
-  }
-
-  return civicrm_create_error(ts('Subscription failed'));
-}
-
-/**
- * Handle a confirm event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_confirm($params) {
-  $errors = _civicrm_mailer_check_params($params, array('contact_id', 'subscribe_id', 'hash'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $contact_id   = $params['contact_id'];
-  $subscribe_id = $params['subscribe_id'];
-  $hash         = $params['hash'];
-
-  $confirm = CRM_Mailing_Event_BAO_Confirm::confirm($contact_id, $subscribe_id, $hash) !== FALSE;
-
-  if (!$confirm) {
-    return civicrm_create_error(ts('Confirmation failed'));
-  }
-
-  return civicrm_create_success();
-}
-
-/**
- * Handle a reply event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_reply($params) {
-  $errors = _civicrm_mailer_check_params($params, array('job_id', 'event_queue_id', 'hash', 'replyTo'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  // CRM-7333: we can’t require fullEmail for backwards compatibility, but we should require either it or bodyTxt
-  if (empty($params['fullEmail']) and empty($params['bodyTxt'])) {
-    return civicrm_create_error('Required parameter missing: either "fullEmail" or "bodyTxt" is required');
-  }
-
-  $job       = $params['job_id'];
-  $queue     = $params['event_queue_id'];
-  $hash      = $params['hash'];
-  $bodyTxt   = $params['bodyTxt'];
-  $replyto   = $params['replyTo'];
-  $bodyHTML  = CRM_Utils_Array::value('bodyHTML', $params);
-  $fullEmail = CRM_Utils_Array::value('fullEmail', $params);
-
-  $mailing = CRM_Mailing_Event_BAO_Reply::reply($job, $queue, $hash, $replyto);
-
-  if (empty($mailing)) {
-    return civicrm_create_error(ts('Queue event could not be found'));
-  }
-
-  CRM_Mailing_Event_BAO_Reply::send($queue, $mailing, $bodyTxt, $replyto, $bodyHTML, $fullEmail);
-
-  return civicrm_create_success();
-}
-
-/**
- * Handle a forward event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_forward($params) {
-  $errors = _civicrm_mailer_check_params($params, array('job_id', 'event_queue_id', 'hash', 'email'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $job       = $params['job_id'];
-  $queue     = $params['event_queue_id'];
-  $hash      = $params['hash'];
-  $email     = $params['email'];
-  $fromEmail = CRM_Utils_Array::value('fromEmail', $params);
-  $params    = CRM_Utils_Array::value('params', $params);
-
-  $forward = CRM_Mailing_Event_BAO_Forward::forward($job, $queue, $hash, $email, $fromEmail, $params);
-
-  if ($forward) {
-    return civicrm_create_success();
-  }
-
-  return civicrm_create_error(ts('Queue event could not be found'));
-}
-
-/**
- * Handle a click event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_click($params) {
-  $errors = _civicrm_mailer_check_params($params, array('event_queue_id', 'url_id'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $url_id = $params['url_id'];
-  $queue = $params['event_queue_id'];
-
-  $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($queue, $url_id);
-
-  $values             = array();
-  $values['url']      = $url;
-  $values['is_error'] = 0;
-
-  return $values;
-}
-
-/**
- * Handle an open event
- *
- * @param array $params
- *
- * @return array
- */
-function civicrm_mailer_event_open($params) {
-  $errors = _civicrm_mailer_check_params($params, array('event_queue_id'));
-
-  if (!empty($errors)) {
-    return $errors;
-  }
-
-  $queue = $params['event_queue_id'];
-
-  $success = CRM_Mailing_Event_BAO_Opened::open($queue);
-
-  if (!$success) {
-    return civicrm_create_error(ts('mailer open event failed'));
-  }
-
-  return civicrm_create_success();
-}
-
-/**
- * Helper function to check for required params
- *
- * @param array   $params       associated array of fields
- * @param array   $required     array of required fields
- *
- * @return array  $error        array with errors, null if none
- */
-function _civicrm_mailer_check_params(&$params, $required) {
-  // return error if we do not get any params
-  if (empty($params)) {
-    return civicrm_create_error(ts('Input Parameters empty'));
-  }
-
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Input parameter is not an array'));
-  }
-
-  foreach ($required as $name) {
-    if (!array_key_exists($name, $params) || !$params[$name]) {
-      return civicrm_create_error(ts('Required parameter missing: "%1"', array(1 => $name)));
-    }
-  }
-
-  return NULL;
-}
-
diff --git a/api/v2/Membership.php b/api/v2/Membership.php
deleted file mode 100644
index 5bbce1b522..0000000000
--- a/api/v2/Membership.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-// $Id: Membership.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 membership functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Membership
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Membership.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Utils/Rule.php';
-require_once 'api/v2/MembershipContact.php';
-require_once 'api/v2/MembershipType.php';
-require_once 'api/v2/MembershipStatus.php';
-
-/**
- * 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.');
-  }
-
-  // membershipID should be numeric
-  if (!is_numeric($membershipID)) {
-    return civicrm_create_error('Input parameter should be numeric');
-  }
-
-  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');
-}
-
-/**
- *
- * @param <type> $contactID
- *
- * @return <type>
- * @deprecated compatilibility wrappers
- */
-function civicrm_contact_memberships_get(&$contactID) {
-  return civicrm_membership_contact_get($contactID);
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_contact_membership_create(&$params) {
-  return civicrm_membership_contact_create($params);
-}
-
-/**
- * wrapper function according to new api standards
- */
-function civicrm_membership_create(&$params) {
-  return civicrm_membership_contact_create($params);
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_membership_types_get(&$params) {
-  return civicrm_membership_type_get($params);
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_membership_statuses_get(&$params) {
-  return civicrm_membership_status_get($params);
-}
-
diff --git a/api/v2/MembershipContact.php b/api/v2/MembershipContact.php
deleted file mode 100644
index 219ba353e6..0000000000
--- a/api/v2/MembershipContact.php
+++ /dev/null
@@ -1,418 +0,0 @@
-<?php
-// $Id: MembershipContact.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- *
- * File for the CiviCRM APIv2 membership contact functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Membership
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: MembershipContact.php 45502 2013-02-08 13:32:55Z kurund $
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Utils/Rule.php';
-require_once 'CRM/Utils/Array.php';
-
-/**
- * Create a Contact Membership
- *
- * This API is used for creating a Membership for a contact.
- * Required parameters : membership_type_id and status_id.
- *
- * @param   array  $params     an associative array of name/value property values of civicrm_membership
- *
- * @return array of newly created membership property values.
- * @access public
- */
-function civicrm_membership_contact_create(&$params) {
-  _civicrm_initialize();
-
-  $error = _civicrm_membership_check_params($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $values = array();
-  $error = _civicrm_membership_format_params($params, $values);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $params = array_merge($params, $values);
-
-  require_once 'CRM/Core/Action.php';
-  $action = CRM_Core_Action::ADD;
-  // we need user id during add mode
-  $ids = array('userId' => $params['contact_id']);
-
-  //for edit membership id should be present
-  if (CRM_Utils_Array::value('id', $params)) {
-    $ids = array(
-      'membership' => $params['id'],
-      'userId' => $params['contact_id'],
-    );
-    $action = CRM_Core_Action::UPDATE;
-  }
-
-  //need to pass action to handle related memberships.
-  $params['action'] = $action;
-
-  require_once 'CRM/Member/BAO/Membership.php';
-  $membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);
-
-  if (array_key_exists('is_error', $membershipBAO)) {
-    // In case of no valid status for given dates, $membershipBAO
-    // is going to contain 'is_error' => "Error Message"
-    return civicrm_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
-  }
-
-  $membership = array();
-  _civicrm_object_to_array($membershipBAO, $membership);
-  $values             = array();
-  $values['id']       = $membership['id'];
-  $values['is_error'] = 0;
-
-  return $values;
-}
-
-/**
- * Get contact membership record.
- *
- * This api is used for finding an existing membership record.
- * This api will also return the mebership records for the contacts
- * having mebership based on the relationship with the direct members.
- *
- * @param  Array $params key/value pairs for contact_id and some
- *          options affecting the desired results; has legacy support
- *          for just passing the contact_id itself as the argument
- *
- * @return  Array of all found membership property values.
- * @access public
- */
-function civicrm_membership_contact_get(&$params) {
-  _civicrm_initialize();
-
-  $contactID = $activeOnly = $membershipTypeId = $membershipType = NULL;
-  if (is_array($params)) {
-    $contactID        = CRM_Utils_Array::value('contact_id', $params);
-    $activeOnly       = CRM_Utils_Array::value('active_only', $params, FALSE);
-    $membershipTypeId = CRM_Utils_Array::value('membership_type_id', $params);
-    if (!$membershipTypeId) {
-      $membershipType = CRM_Utils_Array::value('membership_type', $params);
-      if ($membershipType) {
-        require_once 'CRM/Member/DAO/MembershipType.php';
-        $membershipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
-          $membershipType, 'id', 'name'
-        );
-      }
-    }
-  }
-  elseif (CRM_Utils_Rule::integer($params)) {
-    $contactID = $params;
-  }
-  else {
-    return civicrm_create_error('Parameters can be only of type array or integer');
-  }
-
-  if (empty($contactID)) {
-    return civicrm_create_error('Invalid value for ContactID.');
-  }
-
-  // get the membership for the given contact ID
-  require_once 'CRM/Member/BAO/Membership.php';
-  $membershipParams = array('contact_id' => $contactID);
-  if ($membershipTypeId) {
-    $membershipParams['membership_type_id'] = $membershipTypeId;
-  }
-  $membershipValues = array();
-  CRM_Member_BAO_Membership::getValues($membershipParams, $membershipValues, $activeOnly);
-
-  $recordCount = 0;
-
-  if (empty($membershipValues)) {
-    # No results is NOT an error!
-    # return civicrm_create_error('No memberships for this contact.');
-    $membershipValues['record_count'] = $recordCount;
-    return $membershipValues;
-  }
-
-  $members[$contactID] = array();
-  $relationships = array();;
-  foreach ($membershipValues as $membershipId => $values) {
-    // populate the membership type name for the membership type id
-    require_once 'CRM/Member/BAO/MembershipType.php';
-    $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
-
-    $membershipValues[$membershipId]['membership_name'] = $membershipType['name'];
-
-    if (CRM_Utils_Array::value('relationship_type_id', $membershipType)) {
-      $relationships[$membershipType['relationship_type_id']] = $membershipId;
-    }
-
-    // populating relationship type name.
-    require_once 'CRM/Contact/BAO/RelationshipType.php';
-    $relationshipType = new CRM_Contact_BAO_RelationshipType();
-    $relationshipType->id = CRM_Utils_Array::value('relationship_type_id', $membershipType);
-    if ($relationshipType->find(TRUE)) {
-      $membershipValues[$membershipId]['relationship_name'] = $relationshipType->name_a_b;
-    }
-    require_once 'CRM/Core/BAO/CustomGroup.php';
-    $groupTree = &CRM_Core_BAO_CustomGroup::getTree('Membership', CRM_Core_DAO::$_nullObject, $membershipId, FALSE,
-      $values['membership_type_id']
-    );
-    $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
-
-    $defaults = array();
-    CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
-
-    if (!empty($defaults)) {
-      foreach ($defaults as $key => $val) {
-        $membershipValues[$membershipId][$key] = $val;
-      }
-    }
-
-    $recordCount++;
-  }
-
-  $members[$contactID] = $membershipValues;
-
-  // populating contacts in members array based on their relationship with direct members.
-  require_once 'CRM/Contact/BAO/Relationship.php';
-  if (!empty($relationships)) {
-    foreach ($relationships as $relTypeId => $membershipId) {
-      // As members are not direct members, there should not be
-      // membership id in the result array.
-      unset($membershipValues[$membershipId]['id']);
-      $relationship = new CRM_Contact_BAO_Relationship();
-      $relationship->contact_id_b = $contactID;
-      $relationship->relationship_type_id = $relTypeId;
-      if ($relationship->find()) {
-        while ($relationship->fetch()) {
-          clone($relationship);
-          $membershipValues[$membershipId]['contact_id'] = $relationship->contact_id_a;
-          $members[$contactID][$relationship->contact_id_a] = $membershipValues[$membershipId];
-        }
-      }
-      $recordCount++;
-    }
-  }
-  $members['record_count'] = $recordCount;
-  return $members;
-}
-
-/**
- * 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";
-  require_once "CRM/Member/PseudoConstant.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 'start_date':
-      case 'end_date':
-      case 'reminder_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");
-        }
-
-        // make sure we format dates to mysql friendly format
-        $values[$key] = CRM_Utils_Date::processDate($value, NULL, FALSE, 'Ymd');
-        break;
-
-      case 'membership_type_id':
-        if (!CRM_Utils_Array::value($value, CRM_Member_PseudoConstant::membershipType())) {
-          return civicrm_create_error('Invalid Membership Type Id');
-        }
-        $values[$key] = $value;
-        break;
-
-      case 'membership_type':
-        $membershipTypeId = CRM_Utils_Array::key(ucfirst($value),
-          CRM_Member_PseudoConstant::membershipType()
-        );
-        if ($membershipTypeId) {
-          if (CRM_Utils_Array::value('membership_type_id', $values) &&
-            $membershipTypeId != $values['membership_type_id']
-          ) {
-            return civicrm_create_error('Mismatched membership Type and Membership Type Id');
-          }
-        }
-        else {
-          return civicrm_create_error('Invalid Membership Type');
-        }
-        $values['membership_type_id'] = $membershipTypeId;
-        break;
-
-      case 'status_id':
-        if (!CRM_Utils_Array::value($value, CRM_Member_PseudoConstant::membershipStatus())) {
-          return civicrm_create_error('Invalid Membership Status Id');
-        }
-        $values[$key] = $value;
-        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;
-}
-
-/**
- * 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();
-}
-
diff --git a/api/v2/MembershipContributionLink.php b/api/v2/MembershipContributionLink.php
deleted file mode 100644
index c31a070cc0..0000000000
--- a/api/v2/MembershipContributionLink.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-// $Id: MembershipContributionLink.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 membership contribution link functions
- *
- * @todo Probably needs renaming
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Membership
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: MembershipContributionLink.php 45502 2013-02-08 13:32:55Z kurund $
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- * 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
- * @static void
- * @access public
- */
-function &civicrm_membershipcontributionlink_create(&$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 (!isset($params['contribution_id']) ||
-    !isset($params['membership_id'])
-  ) {
-    return civicrm_create_error(ts('Required parameters missing'));
-  }
-
-  require_once 'CRM/Core/Transaction.php';
-  $transaction = new CRM_Core_Transaction();
-
-  require_once 'CRM/Member/DAO/MembershipPayment.php';
-  $mpDAO = new CRM_Member_DAO_MembershipPayment();
-  $mpDAO->copyValues($params);
-  $result = $mpDAO->save();
-
-  if (is_a($result, 'CRM_Core_Error')) {
-    $transaction->rollback();
-    return civicrm_create_error($result->_errors[0]['message']);
-  }
-
-  $transaction->commit();
-
-  _civicrm_object_to_array($mpDAO, $mpArray);
-
-  return $mpArray;
-}
-
-/**
- * Retrieve one / all contribution(s) / membership(s) linked to a
- * membership / contrbution.
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        array of properties, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function &civicrm_membershipcontributionlink_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'));
-  }
-
-  require_once 'CRM/Member/DAO/MembershipPayment.php';
-  $mpDAO = new CRM_Member_DAO_MembershipPayment();
-  $mpDAO->copyValues($params);
-  $mpDAO->id = CRM_Utils_Array::value('membership_contribution_id', $params);
-  $mpDAO->find();
-
-  $values = array();
-  while ($mpDAO->fetch()) {
-    _civicrm_object_to_array($mpDAO, $mpArray);
-    $mpArray['membership_contribution_id'] = $mpDAO->id;
-    unset($mpArray['id']);
-    $values[$mpDAO->id] = $mpArray;
-  }
-
-  return $values;
-}
-
diff --git a/api/v2/MembershipStatus.php b/api/v2/MembershipStatus.php
deleted file mode 100644
index 598d78e818..0000000000
--- a/api/v2/MembershipStatus.php
+++ /dev/null
@@ -1,260 +0,0 @@
-<?php
-// $Id: MembershipStatus.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 membership status functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Membership
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: MembershipStatus.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Create a Membership Status
- *
- * This API is used for creating a Membership Status
- *
- * @param   array  $params  an associative array of name/value property values of civicrm_membership_status
- *
- * @return array of newly created membership status property values.
- * @access public
- */
-function civicrm_membership_status_create(&$params) {
-  _civicrm_initialize();
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array.');
-  }
-
-  if (empty($params)) {
-    return civicrm_create_error('Params can not be empty.');
-  }
-
-  $name = CRM_Utils_Array::value('name', $params);
-  if (!$name) {
-    $name = CRM_Utils_Array::value('label', $params);
-  }
-  if (!$name) {
-    return civicrm_create_error('Missing required fields');
-  }
-
-  //don't allow duplicate names.
-  require_once 'CRM/Member/DAO/MembershipStatus.php';
-  $status = new CRM_Member_DAO_MembershipStatus();
-  $status->name = $name;
-  if ($status->find(TRUE)) {
-    return civicrm_create_error(ts('A membership status with this name already exists.'));
-  }
-
-  require_once 'CRM/Member/BAO/MembershipStatus.php';
-  $ids = array();
-  $membershipStatusBAO = CRM_Member_BAO_MembershipStatus::add($params, $ids);
-  if (is_a($membershipStatusBAO, 'CRM_Core_Error')) {
-    return civicrm_create_error("Membership is not created");
-  }
-  else {
-    $values             = array();
-    $values['id']       = $membershipStatusBAO->id;
-    $values['is_error'] = 0;
-    return $values;
-  }
-}
-
-/**
- * Get a membership status.
- *
- * This api is used for finding an existing membership status.
- *
- * @param  array $params  an associative array of name/value property values of civicrm_membership_status
- *
- * @return  Array of all found membership status property values.
- * @access public
- */
-function civicrm_membership_status_get(&$params) {
-  _civicrm_initialize();
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array.');
-  }
-
-  require_once 'CRM/Member/BAO/MembershipStatus.php';
-  $membershipStatusBAO = new CRM_Member_BAO_MembershipStatus();
-
-  $properties = array_keys($membershipStatusBAO->fields());
-
-  foreach ($properties as $name) {
-    if (array_key_exists($name, $params)) {
-      $membershipStatusBAO->$name = $params[$name];
-    }
-  }
-
-  if ($membershipStatusBAO->find()) {
-    $membershipStatus = array();
-    while ($membershipStatusBAO->fetch()) {
-      _civicrm_object_to_array(clone($membershipStatusBAO), $membershipStatus);
-      $membershipStatuses[$membershipStatusBAO->id] = $membershipStatus;
-    }
-  }
-  else {
-    return civicrm_create_error('Exact match not found');
-  }
-  return $membershipStatuses;
-}
-
-/**
- * Update an existing membership status
- *
- * This api is used for updating an existing membership status.
- * Required parrmeters : id of a membership status
- *
- * @param  Array   $params  an associative array of name/value property values of civicrm_membership_status
- *
- * @return array of updated membership status property values
- * @access public
- */
-function &civicrm_membership_status_update(&$params) {
-  _civicrm_initialize();
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array');
-  }
-
-  if (!isset($params['id'])) {
-    return civicrm_create_error('Required parameter missing');
-  }
-
-  //don't allow duplicate names.
-  $name = CRM_Utils_Array::value('name', $params);
-  if ($name) {
-    require_once 'CRM/Member/DAO/MembershipStatus.php';
-    $status = new CRM_Member_DAO_MembershipStatus();
-    $status->name = $params['name'];
-    if ($status->find(TRUE) && $status->id != $params['id']) {
-      return civicrm_create_error(ts('A membership status with this name already exists.'));
-    }
-  }
-
-  require_once 'CRM/Member/BAO/MembershipStatus.php';
-  $membershipStatusBAO = new CRM_Member_BAO_MembershipStatus();
-  $membershipStatusBAO->id = $params['id'];
-  if ($membershipStatusBAO->find(TRUE)) {
-    $fields = $membershipStatusBAO->fields();
-    foreach ($fields as $name => $field) {
-      if (array_key_exists($name, $params)) {
-        $membershipStatusBAO->$name = $params[$name];
-      }
-    }
-    $membershipStatusBAO->save();
-  }
-  $membershipStatus = array();
-  _civicrm_object_to_array(clone($membershipStatusBAO), $membershipStatus);
-  $membershipStatus['is_error'] = 0;
-  return $membershipStatus;
-}
-
-/**
- * Deletes an existing membership status
- *
- * This API is used for deleting a membership status
- *
- * @param  Int  $membershipStatusID   Id of the membership status to be deleted
- *
- * @return null if successfull, object of CRM_Core_Error otherwise
- * @access public
- */
-function civicrm_membership_status_delete(&$params) {
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array');
-  }
-
-  if (!CRM_Utils_Array::value('id', $params)) {
-    return civicrm_create_error('Invalid or no value for membershipStatusID');
-  }
-
-  require_once 'CRM/Member/BAO/MembershipStatus.php';
-  $memberStatusDelete = CRM_Member_BAO_MembershipStatus::del($params['id']);
-  return $memberStatusDelete ? civicrm_create_error('Error while deleting membership type Status') : civicrm_create_success();
-}
-
-/**
- * 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, $excludeIsAdmin = FALSE) {
-  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 = "
-SELECT start_date, end_date, join_date
-  FROM civicrm_membership
- WHERE id = %1
-";
-  $params = array(1 => array($membershipID, 'Integer'));
-  $dao = CRM_Core_DAO::executeQuery($query, $params);
-  if ($dao->fetch()) {
-    require_once 'CRM/Member/BAO/MembershipStatus.php';
-    // CRM-7248 added $excludeIsAdmin to this function, also 'today' param
-    $result = &CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dao->start_date,
-      $dao->end_date,
-      $dao->join_date,
-      'today',
-      $excludeIsAdmin
-    );
-
-    //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;
-}
-
diff --git a/api/v2/MembershipType.php b/api/v2/MembershipType.php
deleted file mode 100644
index c7dffb5e5a..0000000000
--- a/api/v2/MembershipType.php
+++ /dev/null
@@ -1,211 +0,0 @@
-<?php
-// $Id: MembershipType.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 membership type functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Membership
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: MembershipType.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-
-/**
- * Create a Membership Type
- *
- * This API is used for creating a Membership Type
- *
- * @param   array  $params  an associative array of name/value property values of civicrm_membership_type
- *
- * @return array of newly created membership type property values.
- * @access public
- */
-function civicrm_membership_type_create(&$params) {
-  _civicrm_initialize();
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-  if (empty($params)) {
-    return civicrm_create_error('No input parameters present');
-  }
-
-  if (!isset($params['name']) ||
-    !isset($params['duration_unit']) ||
-    !isset($params['duration_interval'])
-  ) {
-    return civicrm_create_error('Missing require fileds ( name, duration unit,duration interval)');
-  }
-
-  $error = _civicrm_check_required_fields($params, 'CRM_Member_DAO_MembershipType');
-  if ($error['is_error']) {
-    return civicrm_create_error($error['error_message']);
-  }
-
-  $ids['membershipType'] = CRM_Utils_Array::value('id', $params);
-  $ids['memberOfContact'] = CRM_Utils_Array::value('member_of_contact_id', $params);
-  $ids['contributionType'] = CRM_Utils_Array::value('financial_type_id', $params);
-
-  require_once 'CRM/Member/BAO/MembershipType.php';
-  $membershipTypeBAO = CRM_Member_BAO_MembershipType::add($params, $ids);
-
-  if (is_a($membershipTypeBAO, 'CRM_Core_Error')) {
-    return civicrm_create_error("Membership is not created");
-  }
-  else {
-    $membershipType = array();
-    _civicrm_object_to_array($membershipTypeBAO, $membershipType);
-    $values             = array();
-    $values['id']       = $membershipType['id'];
-    $values['is_error'] = 0;
-  }
-
-  return $values;
-}
-
-/**
- * Get a Membership Type.
- *
- * This api is used for finding an existing membership type.
- *
- * @param  array $params  an associative array of name/value property values of civicrm_membership_type
- *
- * @return  Array of all found membership type property values.
- * @access public
- */
-function civicrm_membership_type_get(&$params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-  if (empty($params)) {
-    return civicrm_create_error('No input parameters present');
-  }
-  require_once 'CRM/Member/BAO/MembershipType.php';
-  $membershipTypeBAO = new CRM_Member_BAO_MembershipType();
-
-  $properties = array_keys($membershipTypeBAO->fields());
-
-  foreach ($properties as $name) {
-    if (array_key_exists($name, $params)) {
-      $membershipTypeBAO->$name = $params[$name];
-    }
-  }
-
-  if ($membershipTypeBAO->find()) {
-    $membershipType = array();
-    while ($membershipTypeBAO->fetch()) {
-      _civicrm_object_to_array(clone($membershipTypeBAO), $membershipType);
-      $membershipTypes[$membershipTypeBAO->id] = $membershipType;
-    }
-  }
-  else {
-    return civicrm_create_error('Exact match not found');
-  }
-  return $membershipTypes;
-}
-
-/**
- * Update an existing membership type
- *
- * This api is used for updating an existing membership type.
- * Required parrmeters : id of a membership type
- *
- * @param  Array   $params  an associative array of name/value property values of civicrm_membership_type
- *
- * @return array of updated membership type property values
- * @access public
- */
-function &civicrm_membership_type_update(&$params) {
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-  if (empty($params)) {
-    return civicrm_create_error('No input parameters present');
-  }
-  if (!isset($params['id'])) {
-    return civicrm_create_error('Required parameter missing');
-  }
-
-  require_once 'CRM/Member/BAO/MembershipType.php';
-  $membershipTypeBAO = new CRM_Member_BAO_MembershipType();
-  $membershipTypeBAO->id = $params['id'];
-  if ($membershipTypeBAO->find(TRUE)) {
-    $fields = $membershipTypeBAO->fields();
-
-    foreach ($fields as $name => $field) {
-      if (array_key_exists($field['name'], $params)) {
-        $membershipTypeBAO->$field['name'] = $params[$field['name']];
-      }
-    }
-    $membershipTypeBAO->save();
-  }
-
-  $membershipType = array();
-  _civicrm_object_to_array($membershipTypeBAO, $membershipType);
-  $membershipTypeBAO->free();
-  return $membershipType;
-}
-
-/**
- * Deletes an existing membership type
- *
- * This API is used for deleting a membership type
- * Required parrmeters : id of a membership type
- *
- * @param  Array   $params  an associative array of name/value property values of civicrm_membership_type
- *
- * @return boolean        true if success, else false
- * @access public
- */
-function civicrm_membership_type_delete(&$params) {
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-  if (empty($params)) {
-    return civicrm_create_error('No input parameters present');
-  }
-  if (!CRM_Utils_Array::value('id', $params)) {
-    return civicrm_create_error('Invalid or no value for membershipTypeID');
-  }
-
-  require_once 'CRM/Member/BAO/MembershipType.php';
-  $memberDelete = CRM_Member_BAO_MembershipType::del($params['id']);
-
-  return $memberDelete ? civicrm_create_success("Given Membership Type have been deleted") : civicrm_create_error('Error while deleting membership type');
-}
-
diff --git a/api/v2/Note.php b/api/v2/Note.php
deleted file mode 100644
index 692d9bdbfe..0000000000
--- a/api/v2/Note.php
+++ /dev/null
@@ -1,221 +0,0 @@
-<?php
-// $Id: Note.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 note functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Note
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Note.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Core/BAO/Note.php';
-
-/**
- * Create Note
- *
- * This API is used for creating a note.
- * Required parameters : entity_id AND note
- *
- * @param   array  $params  an associative array of name/value property values of civicrm_note
- *
- * @return array note id if note is created otherwise is_error = 1
- * @access public
- */
-function &civicrm_note_create(&$params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params is not an array');
-  }
-
-  if (!CRM_Utils_Array::value('id', $params)) {
-    if (!isset($params['entity_table']) ||
-      !isset($params['entity_id']) ||
-      !isset($params['note']) ||
-      !isset($params['contact_id'])
-    ) {
-      return civicrm_create_error('Required parameter missing');
-    }
-  }
-  elseif (!isset($params['id']) && !isset($params['contact_id'])) {
-    return civicrm_create_error('Required parameter missing');
-  }
-
-  $contactID = CRM_Utils_Array::value('contact_id', $params);
-
-  if (!isset($params['modified_date'])) {
-    $params['modified_date'] = date("Ymd");
-  }
-
-  $ids     = array();
-  $ids     = array('id' => CRM_Utils_Array::value('id', $params));
-  $noteBAO = CRM_Core_BAO_Note::add($params, $ids);
-
-  if (is_a($noteBAO, 'CRM_Core_Error')) {
-    $error = civicrm_create_error("Note could not be created");
-    return $error;
-  }
-  else {
-    $note = array();
-    _civicrm_object_to_array($noteBAO, $note);
-    $note['is_error'] = 0;
-  }
-  return $note;
-}
-
-/**
- * Updates an existing note with information
- *
- * @params  array  $params   Params array
- *
- * @return null
- * @access public
- *
- * @todo Probably needs some work
- */
-function &civicrm_note_update(&$params) {
-  return civicrm_note_create($params);
-}
-
-/**
- * Deletes an existing note
- *
- * This API is used for deleting a note
- *
- * @param  Int  $noteID   Id of the note to be deleted
- *
- * @return null
- * @access public
- */
-function civicrm_note_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 Note ID');
-    return $error;
-  }
-
-  $result = new CRM_Core_BAO_Note();
-  return $result->del($params['id']) ? civicrm_create_success() : civicrm_create_error('Error while deleting Note');
-}
-
-/**
- * Retrieve a specific note, given a set of input params
- *
- * @param  array   $params (reference ) input parameters
- *
- * @return array (reference ) array of properties,
- * if error an array with an error id and error message
- *
- * @static void
- * @access public
- */
-function &civicrm_note_get(&$params) {
-  _civicrm_initialize();
-
-  $values = array();
-  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 (!CRM_Utils_Array::value('entity_id', $params) || (CRM_Utils_Array::value('entity_id', $params) && (!is_numeric($params['entity_id'])))) {
-    return civicrm_create_error(ts("Invalid entity ID"));
-  }
-
-  if (!isset($params['entity_id']) && !isset($params['entity_table'])) {
-    return civicrm_create_error('Required parameters missing.');
-  }
-
-  $note = CRM_Core_BAO_Note::getNote($params['entity_id'], $params['entity_table']);
-
-  if (civicrm_error($note)) {
-    return $note;
-  }
-
-  if (count($note) < 1) {
-    return civicrm_create_error(ts('%1 notes matching the input parameters', array(1 => count($note))));
-  }
-
-  $note = array_values($note);
-  $note['is_error'] = 0;
-  return $note;
-}
-
-/**
- * Get all descendents of given note
- *
- * @param array $params Associative array; only required 'id' parameter is used
- *
- * @return array Nested associative array beginning with direct children of given note.
- */
-function &civicrm_note_tree_get(&$params) {
-
-  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 (!isset($params['id'])) {
-    return civicrm_create_error('Required parameter ("id") missing.');
-  }
-
-  if (!is_numeric($params['id'])) {
-    return civicrm_create_error(ts("Invalid note ID"));
-  }
-  if (!isset($params['max_depth'])) {
-    $params['max_depth'] = 0;
-  }
-  if (!isset($params['snippet'])) {
-    $params['snippet'] = FALSE;
-  }
-  $noteTree = CRM_Core_BAO_Note::getNoteTree($params['id'], $params['max_depth'], $params['snippet']);
-  return $noteTree;
-}
-
diff --git a/api/v2/Participant.php b/api/v2/Participant.php
deleted file mode 100644
index f734550719..0000000000
--- a/api/v2/Participant.php
+++ /dev/null
@@ -1,362 +0,0 @@
-<?php
-// $Id: Participant.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 participant functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Participant
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Participant.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-require_once 'api/v2/ParticipantPayment.php';
-
-/**
- * Create an Event Participant
- *
- * This API is used for creating a participants in an event.
- * Required parameters : event_id AND contact_id for new creation
- *                     : participant as name/value with participantid for edit
- *
- * @param   array  $params     an associative array of name/value property values of civicrm_participant
- *
- * @return array participant id if participant is created/edited otherwise is_error = 1
- * @access public
- */
-function civicrm_participant_create(&$params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    $error = civicrm_create_error('Parameters is not an array');
-    return $error;
-  }
-
-  if (!isset($params['event_id']) || !isset($params['contact_id'])) {
-    $error = civicrm_create_error('Required parameter missing');
-    return $error;
-  }
-
-  if (!isset($params['status_id'])) {
-    $params['status_id'] = 1;
-  }
-
-  if (!isset($params['register_date'])) {
-    $params['register_date'] = date('YmdHis');
-  }
-  $errors = civicrm_participant_check_params($params);
-  if (civicrm_error($errors)) {
-    return $errors;
-  }
-
-  require_once 'CRM/Event/BAO/Participant.php';
-  $participant = CRM_Event_BAO_Participant::create($params);
-
-  if (is_a($participant, 'CRM_Core_Error')) {
-    return civicrm_create_error("Participant is not created");
-  }
-  else {
-    return civicrm_create_success($participant->id);
-  }
-}
-
-/**
- * Retrieve a specific participant, given a set of input params
- * If more than one matching participant exists, return an error, unless
- * the client has requested to return the first found contact
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        array of properties, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function &civicrm_participant_get(&$params) {
-  _civicrm_initialize();
-
-  $values = array();
-  if (empty($params)) {
-    $error = civicrm_create_error(ts('No input parameters present'));
-    return $error;
-  }
-
-  if (!is_array($params)) {
-    $error = civicrm_create_error(ts('Input parameters is not an array'));
-    return $error;
-  }
-
-  if (isset($params['id'])) {
-    $params['participant_id'] = $params['id'];
-    unset($params['id']);
-  }
-
-  $participant = &civicrm_participant_search($params);
-
-
-  if (count($participant) != 1 &&
-    !CRM_Utils_Array::value('returnFirst', $params)
-  ) {
-    $error = civicrm_create_error(ts('%1 participant matching input params', array(1 => count($participant))),
-      $participant
-    );
-    return $error;
-  }
-
-  if (civicrm_error($participant)) {
-    return $participant;
-  }
-
-  $participant = array_values($participant);
-  return $participant[0];
-}
-
-/**
- * Get contact participant record.
- *
- * This api is used for finding an existing participant record.
- *
- * @param  array  $params     an associative array of name/value property values of civicrm_participant
- *
- * @return  participant property values.
- * @access public
- */
-function &civicrm_participant_search(&$params) {
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Params need to be of type array!');
-  }
-
-  $inputParams      = array();
-  $returnProperties = array();
-  $otherVars        = array('sort', 'offset', 'rowCount');
-
-  $sort     = NULL;
-  $offset   = 0;
-  $rowCount = 25;
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 7) == 'return.') {
-      $returnProperties[substr($n, 7)] = $v;
-    }
-    elseif (in_array($n, $otherVars)) {
-      $$n = $v;
-    }
-    else {
-      $inputParams[$n] = $v;
-    }
-  }
-
-  // add is_test to the clause if not present
-  if (!array_key_exists('participant_test', $inputParams)) {
-    $inputParams['participant_test'] = 0;
-  }
-
-  require_once 'CRM/Contact/BAO/Query.php';
-  require_once 'CRM/Event/BAO/Query.php';
-  if (empty($returnProperties)) {
-    $returnProperties = CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT);
-  }
-
-  $newParams = CRM_Contact_BAO_Query::convertFormValues($params);
-  $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL);
-  list($select, $from, $where, $having) = $query->query();
-
-  $sql = "$select $from $where $having";
-
-  if (!empty($sort)) {
-    $sql .= " ORDER BY $sort ";
-  }
-  $sql .= " LIMIT $offset, $rowCount ";
-  $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
-
-  $participant = array();
-  while ($dao->fetch()) {
-    $participant[$dao->participant_id] = $query->store($dao);
-  }
-  $dao->free();
-
-  return $participant;
-}
-
-/**
- * Update an existing contact participant
- *
- * This api is used for updating an existing contact participant.
- * Required parrmeters : id of a participant
- *
- * @param  Array   $params  an associative array of name/value property values of civicrm_participant
- *
- * @return array of updated participant property values
- * @access public
- */
-function &civicrm_participant_update(&$params) {
-  _civicrm_initialize();
-  if (!is_array($params)) {
-    return civicrm_create_error('Parameters is not an array');
-  }
-
-  if (!isset($params['id'])) {
-    $error = civicrm_create_error('Required parameter missing');
-    return $error;
-  }
-  $errors = civicrm_participant_check_params($params);
-  if (civicrm_error($errors)) {
-    return $errors;
-  }
-  require_once 'CRM/Event/BAO/Participant.php';
-  $participantBAO = CRM_Event_BAO_Participant::create($params);
-
-  $participant = array();
-  _civicrm_object_to_array($participantBAO, $participant);
-  return $participant;
-}
-
-/**
- * Deletes an existing contact participant
- *
- * This API is used for deleting a contact participant
- *
- * @param  Int  $participantID   Id of the contact participant to be deleted
- *
- * @return boolean        true if success, else false
- * @access public
- */
-function &civicrm_participant_delete(&$params) {
-  _civicrm_initialize();
-
-  if (!is_array($params)) {
-    $error = civicrm_create_error('Params is not an array');
-    return $error;
-  }
-
-  if (!isset($params['id'])) {
-    $error = civicrm_create_error('Required parameter missing');
-    return $error;
-  }
-  require_once 'CRM/Event/BAO/Participant.php';
-  $participant = new CRM_Event_BAO_Participant();
-  $result = $participant->deleteParticipant($params['id']);
-
-  if ($result) {
-    $values = civicrm_create_success();
-  }
-  else {
-    $values = civicrm_create_error('Error while deleting participant');
-  }
-  return $values;
-}
-
-/**
- *
- * @param <type> $params
- * @param <type> $onDuplicate
- *
- * @return <type>
- */
-function civicrm_create_participant_formatted(&$params, $onDuplicate) {
-  _civicrm_initialize();
-
-  // return error if we have no params
-  if (empty($params)) {
-    return civicrm_create_error('Input Parameters empty');
-  }
-
-  require_once 'CRM/Event/Import/Parser.php';
-  if ($onDuplicate != CRM_Event_Import_Parser::DUPLICATE_NOCHECK) {
-    CRM_Core_Error::reset();
-    $error = civicrm_participant_check_params($params, TRUE);
-    if (civicrm_error($error)) {
-      return $error;
-    }
-  }
-
-  return civicrm_participant_create($params);
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function civicrm_participant_check_params(&$params, $checkDuplicate = FALSE) {
-  require_once 'CRM/Event/BAO/Participant.php';
-  //check if participant id is valid or not
-  if (CRM_Utils_Array::value('id', $params)) {
-    $participant = new CRM_Event_BAO_Participant();
-    $participant->id = $params['id'];
-    if (!$participant->find(TRUE)) {
-      return civicrm_create_error(ts('Participant  id is not valid'));
-    }
-  }
-  require_once 'CRM/Contact/BAO/Contact.php';
-  //check if contact id is valid or not
-  if (CRM_Utils_Array::value('contact_id', $params)) {
-    $contact = new CRM_Contact_BAO_Contact();
-    $contact->id = $params['contact_id'];
-    if (!$contact->find(TRUE)) {
-      return civicrm_create_error(ts('Contact id is not valid'));
-    }
-  }
-
-  //check that event id is not an template
-  if (CRM_Utils_Array::value('event_id', $params)) {
-    $isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template');
-    if (!empty($isTemplate)) {
-      return civicrm_create_error(ts('Event templates are not meant to be registered'));
-    }
-  }
-
-  $result = array();
-  if ($checkDuplicate) {
-    if (CRM_Event_BAO_Participant::checkDuplicate($params, $result)) {
-      $participantID = array_pop($result);
-
-      $error = CRM_Core_Error::createError("Found matching participant record.",
-        CRM_Core_Error::DUPLICATE_PARTICIPANT,
-        'Fatal', $participantID
-      );
-
-      return civicrm_create_error($error->pop(),
-        array(
-          'contactID' => $params['contact_id'],
-          'participantID' => $participantID,
-        )
-      );
-    }
-  }
-  return TRUE;
-}
-
diff --git a/api/v2/ParticipantPayment.php b/api/v2/ParticipantPayment.php
deleted file mode 100644
index 35eb5b4ff7..0000000000
--- a/api/v2/ParticipantPayment.php
+++ /dev/null
@@ -1,146 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- *
- * Creating this file to make unit testing the 2 versions smoother
- * v2 series are to be deprecated but this is where the participant_payment functions should go
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Contact
- * @copyright CiviCRM LLC (c) 2004-2013
- * $Id: Contact.php 30415 2010-10-29 12:02:47Z shot $
- */
-require_once 'api/v2/Participant.php';
-
-/**
- * Create a Event Participant Payment
- *
- * This API is used for creating a Participant Payment of Event.
- * Required parameters : participant_id, contribution_id.
- *
- * @param   array  $params     an associative array of name/value property values of civicrm_participant_payment
- *
- * @return array of newly created payment property values.
- * @access public
- */
-function &civicrm_participant_payment_create(&$params) {
-  _civicrm_initialize();
-  if (!is_array($params)) {
-    $error = civicrm_create_error('Params is not an array');
-    return $error;
-  }
-
-  if (!isset($params['participant_id']) || !isset($params['contribution_id'])) {
-    $error = civicrm_create_error('Required parameter missing');
-    return $error;
-  }
-
-  $ids = array();
-  if (CRM_Utils_Array::value('id', $params)) {
-    $ids['id'] = $params['id'];
-  }
-  require_once 'CRM/Event/BAO/ParticipantPayment.php';
-  $participantPayment = CRM_Event_BAO_ParticipantPayment::create($params, $ids);
-
-  if (is_a($participantPayment, 'CRM_Core_Error')) {
-    $error = civicrm_create_error("Participant payment could not be created");
-    return $error;
-  }
-  else {
-    $payment             = array();
-    $payment['id']       = $participantPayment->id;
-    $payment['is_error'] = 0;
-  }
-  return $payment;
-}
-
-/**
- * Update an existing contact participant payment
- *
- * This api is used for updating an existing contact participant payment
- * Required parameters : id of a participant_payment
- *
- * @param  Array   $params  an associative array of name/value property values of civicrm_participant_payment
- *
- * @return array of updated participant_payment property values
- * @access public
- */
-function &civicrm_participant_payment_update(&$params) {
-  _civicrm_initialize();
-  if (!is_array($params)) {
-    $error = civicrm_create_error('Params is not an array');
-    return $error;
-  }
-
-  if (!isset($params['id'])) {
-    $error = civicrm_create_error('Required parameter missing');
-    return $error;
-  }
-
-  $ids = array();
-  $ids['id'] = $params['id'];
-
-  require_once 'CRM/Event/BAO/ParticipantPayment.php';
-  $payment = CRM_Event_BAO_ParticipantPayment::create($params, $ids);
-
-  $participantPayment = array();
-  _civicrm_object_to_array($payment, $participantPayment);
-
-  return $participantPayment;
-}
-
-/**
- * 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');
-}
-
diff --git a/api/v2/Pledge.php b/api/v2/Pledge.php
deleted file mode 100644
index 4500519af8..0000000000
--- a/api/v2/Pledge.php
+++ /dev/null
@@ -1,470 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-
-
-/*
-*DRAFT CODE WRITTEN BY EILEEN still dev version 
-*Starting point was Contribute API. I tried to use the format params from 
-*contribute API to handle incorrect data prior to hitting core & help
-*prevent CORE errors (the bane of API users since there is a proper API
-*error format). However, I found many fields needed to be manipulated after 
-*doing the field rationalisation in the contribute module. The way I have done it
-*is cumbersome from a coding point of view in order to allow a lot of commenting / clarity
-* I concluded that in the absence
-*of a clear standard to say when the fields unique name & when it's table name should
-*be used I should facilitate both as much as possible as either would be a reasonable 
-*expectation from a developer and I know from experience what huge amounts of developer
-*time go into 'trial and error' & 'guessing' what the paramaters might be for the api
-*Also, the version of a variable that is returned is a bit variable - ie. pledge_ vs not so
-*acceptable params should reflect that
-*Note my attempt at a couple of things that have been discussed:
-*1) interrogate function - feedback on possible variables (I presume that 'check_permissions' or similar might
-*be relevant here too)? What should default for check_permissions be?
-*2) $params['sequential'] - array not indexed by id
-*Would be nice to keep explanatory
-*notes in - I know 'dumb comments' normally get removed by core team when committing
-*but they do help dumb developers:-)
-*/
-
-/**
- * File for the CiviCRM APIv2 Pledge functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Pledge
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Pledge.php
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Utils/Rule.php';
-function &civicrm_pledge_add(&$params) {
-  $result = civicrm_pledge_create($params);
-  return $result;
-}
-
-/**
- * Add or update a plege
- *
- * @param  array   $params           (reference ) input parameters. Fields from interogate function should all work
- *
- * @return array (reference )        array representing created pledge
- * @static void
- * @access public
- */
-function &civicrm_pledge_create(&$params) {
-  _civicrm_initialize();
-  if (empty($params)) {
-    return civicrm_create_error('No input parameters present');
-  }
-
-  if (!is_array($params)) {
-    return civicrm_create_error('Input parameters is not an array');
-  }
-  //check for required fields
-  $error = _civicrm_pledge_check_params($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $values = array();
-  require_once 'CRM/Pledge/BAO/Pledge.php';
-  //check that fields are in appropriate format. Dates will be formatted (within reason) by this function
-  $error = _civicrm_pledge_format_params($params, $values, TRUE);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $pledge = CRM_Pledge_BAO_Pledge::create($values);
-  if (is_a($pledge, 'CRM_Core_Error')) {
-    return civicrm_create_error($pledge->_errors[0]['message']);
-  }
-  else {
-    _civicrm_object_to_array($pledge, $pledgeArray);
-    $pledgeArray['is_error'] = 0;
-  }
-  _civicrm_object_to_array($pledge, $pledgeArray);
-
-  return $pledgeArray;
-}
-
-/**
- * Delete a pledge
- *
- * @param  array   $params           array included 'pledge_id' of pledge to delete
- *
- * @return boolean        true if success, else false
- * @static void
- * @access public
- */
-function civicrm_pledge_delete(&$params) {
-  if (!empty($params['id'])) {
-    //handle field name or unique db name
-    $params['pledge_id'] = $params['id'];
-  }
-
-  $pledgeID = CRM_Utils_Array::value('pledge_id', $params);
-  if (!$pledgeID) {
-    return civicrm_create_error('Could not find pledge_id in input parameters');
-  }
-
-  require_once 'CRM/Pledge/BAO/Pledge.php';
-  if (CRM_Pledge_BAO_Pledge::deletePledge($pledgeID)) {
-    return civicrm_create_success();
-  }
-  else {
-    return civicrm_create_error('Could not delete pledge');
-  }
-}
-
-/**
- * Retrieve a set of pledges, given a set of input params
- *
- * @param  array   $params           (reference ) input parameters. Use interogate for possible fields
- *
- * @return array (reference )        array of pledges, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function &civicrm_pledge_get(&$params) {
-  _civicrm_initialize();
-  if (!is_array($params)) {
-    return civicrm_create_error('Input parameters is not an array');
-  }
-
-
-
-  $inputParams      = array();
-  $returnProperties = array();
-  $otherVars        = array('sort', 'offset', 'rowCount');
-
-  $sort     = NULL;
-  $offset   = 0;
-  $rowCount = 25;
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 7) == 'return.') {
-      $returnProperties[substr($n, 7)] = $v;
-    }
-    elseif (in_array($n, $otherVars)) {
-      $$n = $v;
-    }
-    else {
-      $inputParams[$n] = $v;
-    }
-  }
-
-  // add is_test to the clause if not present
-  if (!array_key_exists('pledge_test', $inputParams)) {
-    $inputParams['pledge_test'] = 0;
-  }
-
-  require_once 'CRM/Pledge/BAO/Query.php';
-  require_once 'CRM/Contact/BAO/Query.php';
-  if (empty($returnProperties)) {
-    $returnProperties = CRM_Pledge_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_PLEDGE);
-  }
-  else {
-    $returnProperties['pledge_id'] = 1;
-  }
-
-  $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
-
-  $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL);
-  list($select, $from, $where) = $query->query();
-
-
-  $sql = "$select $from $where";
-
-  if (!empty($sort)) {
-    $sql .= " ORDER BY $sort ";
-  }
-  $sql .= " LIMIT $offset, $rowCount ";
-  $dao = CRM_Core_DAO::executeQuery($sql);
-
-
-
-  $pledge = array();
-  while ($dao->fetch()) {
-    if ($params['sequential']) {
-      $pledge[] = $query->store($dao);
-    }
-    else {
-      $pledge[$dao->pledge_id] = $query->store($dao);
-    }
-  }
-  $dao->free();
-
-  return $pledge;
-}
-
-/**
- * This function ensures that we have the required input pledge parameters
- *
- * We also run format the parameters with the format_params function
- *
- * @param array  $params       Associative array of property name/value
- *                             pairs to insert in new pledge.
- *
- * @return bool|CRM_Utils_Error
- * @access private
- */
-function _civicrm_pledge_check_params(&$params) {
-    static $required = array( 'contact_id', 'amount', 'financial_type_id' , 'installments','start_date');
-  if ($params['pledge_amount']) {
-    //can be in unique format or DB format but change to unique format here
-    $params['amount'] = $params['pledge_amount'];
-  }
-
-  // cannot create a pledge with empty params
-  if (empty($params)) {
-    return civicrm_create_error('Input Parameters empty');
-  }
-
-  $valid = TRUE;
-  $error = '';
-  foreach ($required as $field) {
-    if (!CRM_Utils_Array::value($field, $params)) {
-      $valid = FALSE;
-      $error .= $field;
-      break;
-    }
-  }
-
-  if (!$valid) {
-    return civicrm_create_error("Required fields not found for pledge $error");
-  }
-
-  return array();
-}
-
-/**
- * This function returns possible values for this api
- *
- * @return array  $result       Associative array of possible values for the api
- *
- * @access public
- */
-//having an 'interogate function to find what can be returned from an API would be SUPER useful. Ideally it would also advise which fields are required too. I
-// imaging the most useful format would be to be like the $params array you need to pass in but the value for each field would be information about it. Ideally the
-// function that sets which parameters are required would be accessible from this function to add them in
-// function at the moment doesn't have custom fields
-function civicrm_pledge_interogate($params) {
-  require_once 'CRM/Pledge/DAO/Pledge.php';
-  $fields = CRM_Pledge_DAO_Pledge::fields();
-  $fields['sort'] = "(GET only)(Optional) Sort String in SQL format eg. 'display_name ASC'";
-  $fields['rowCount'] = "(GET only)(Optional)(default =25) number of records to return";
-  $fields['offset'] = "(GET only)(Optional)(default =0) result record to start from";
-  $fields['return.display_name'] = "(GET only)(Optional)specify to return only display_name field (and contact_id). Substitute display_name for other field";
-  $fields['version'] = "(Recommended - provide version -currently '3.0'";
-  $fields['sequential'] = "(GET only)(Optional)(default =0). Return sequential array not id indexed array";
-  $fields['scheduled_date'] = "(Add only)(Optional)(default= start date) next payment date";
-  $fieldsarr = array_keys($fields);
-
-  foreach ($fieldsarr as $field) {
-    $result[$field] = $fields[$field]['type'];
-    // todo change type to say what it is - e.g. integer
-  }
-  // and get the custom fields
-  require_once 'CRM/Core/BAO/CustomField.php';
-  $customDataType = 'Pledge';
-  $customFields   = CRM_Core_BAO_CustomField::getFields($customDataType);
-  $fieldIDs       = array_keys($customFields);
-  foreach ($fieldIDs as $key) {
-    $result['custom_' . $key] = $customFields[$key]['data_type'] . " : " . $customFields[$key]['label'];
-  }
-
-  $arrfields = db_query($sql);
-  while ($field = db_fetch_array($arrfields)) {
-    $result[$field['Field']] = $field['Field'];
-  }
-  return $result;
-}
-
-/**
- * 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( 'financial_type_id', $params ) ) {
-        $values['financial_type_id'] = $params['financial_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");
-        }
-      case 'financial_type_id':
-        require_once 'CRM/Contribute/PseudoConstant.php';
-            $typeId = CRM_Contribute_PseudoConstant::financialType( $value );
-        if (!CRM_Utils_Rule::integer($value) || !$typeId) {
-                return civicrm_create_error( "financial type id is not valid: $value" );
-        }
-      default:
-        break;
-    }
-  }
-
-  //format the parameters
-  _civicrm_custom_format_params($params, $values, 'Pledge');
-
-
-  return array();
-}
-
diff --git a/api/v2/PledgePayment.php b/api/v2/PledgePayment.php
deleted file mode 100644
index 54f8ea0edb..0000000000
--- a/api/v2/PledgePayment.php
+++ /dev/null
@@ -1,483 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-
-
-/*
-*DRAFT CODE WRITTEN BY EILEEN still dev version (pre-ALPHA)
-*Starting point was Contribute API & some portions are still just that with 
-*contribute replaced by pledge & not yet tested
-* have only been using create, delete functionality
-*/
-
-/**
- * File for the CiviCRM APIv2 Pledge functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Pledge_Payment
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: PledgePayment.php
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Utils/Rule.php';
-function &civicrm_pledge_payment_add(&$params) {
-  $result = civicrm_pledge_create($params);
-  return $result;
-}
-
-/**
- * Add or update a plege payment
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        pledge_id of created or updated record
- * @static void
- * @access public
- */
-function &civicrm_pledge_payment_create(&$params) {
-  _civicrm_initialize();
-  //GAP - update doesn't recalculate payment dates on existing payment schedule  - not the sure the code is in Civi to leverage
-  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'));
-  }
-
-  $error = _civicrm_pledgepayment_check_params($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $values = array();
-
-  require_once 'CRM/Pledge/BAO/PledgePayment.php';
-  $error = _civicrm_pledgepayment_format_params($params, $values);
-
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $pledge = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($params['pledge_id']);
-  $params['id'] = $pledge['id'];
-
-  //params ID needs to be pledge payment ID
-  // pledge payment isn't retrieved if only one exists - the status is not set correctly causing this so let's get it for now as a cludgey make it work
-  // copied from getOldestPayment function
-  if (!$params['id']) {
-    $query = "
-SELECT civicrm_pledge_payment.id id, civicrm_pledge_payment.scheduled_amount amount
-FROM civicrm_pledge, civicrm_pledge_payment
-WHERE civicrm_pledge.id = civicrm_pledge_payment.pledge_id
-  AND civicrm_pledge.id = %1
-LIMIT 0, 1  
-";
-    $params[1]      = array($params['pledge_id'], 'Integer');
-    $payment        = CRM_Core_DAO::executeQuery($query, $params);
-    $paymentDetails = NULL;
-    if ($payment->fetch()) {
-      $params['id'] = $payment->id;
-    }
-  }
-  CRM_Pledge_BAO_PledgePayment::add($params);
-
-  //update pledge status
-  CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($params['pledge_id']);
-  return $errors;
-}
-
-/**
- * Retrieve a specific pledge, given a set of input params
- * If more than one pledge exists, return an error, unless
- * the client has requested to return the first found contact
- *
- * @param  array   $params           (reference ) input parameters
- *
- * @return array (reference )        array of properties, if error an array with an error id and error message
- * @static void
- * @access public
-
- function &civicrm_pledge_payment_get( &$params ) {
- _civicrm_initialize( );
- // copied from contribute code - not touched at all to make work for pledge or tested
- $values = array( );
- 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' ) );
- }
-
- $pledges =& civicrm_pledge_search( $params );
- if ( civicrm_error( $pledges ) ) {
- return $pledges;
- }
-
- if ( count( $pledges ) != 1 &&
- ! $params['returnFirst'] ) {
- return civicrm_create_error( ts( '%1 pledges matching input params', array( 1 => count( $pledges ) ) ),
- $pledges );
- }
-
- $payments = array_values( $pledges );
- return $pledges[0];
- }
-
-
- /**
- * Retrieve a set of pledges, given a set of input params
- *
- * @param  array   $params           (reference ) input parameters
- * @param array    $returnProperties Which properties should be included in the
- *                                   returned pledge object. If NULL, the default
- *                                   set of properties will be included.
- *
- * @return array (reference )        array of pledges, if error an array with an error id and error message
- * @static void
- * @access public
- */
-function &civicrm_pledge_payment_search(&$params) {
-  _civicrm_initialize();
-  // copied from contribute code - not touched at all to make work for pledge or tested
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Input parameters is not an array'));
-  }
-
-  $inputParams      = array();
-  $returnProperties = array();
-  $otherVars        = array('sort', 'offset', 'rowCount');
-
-  $sort     = NULL;
-  $offset   = 0;
-  $rowCount = 25;
-  foreach ($params as $n => $v) {
-    if (substr($n, 0, 7) == 'return.') {
-      $returnProperties[substr($n, 7)] = $v;
-    }
-    elseif (in_array($n, $otherVars)) {
-      $$n = $v;
-    }
-    else {
-      $inputParams[$n] = $v;
-    }
-  }
-
-  // add is_test to the clause if not present
-  if (!array_key_exists('pledge_test', $inputParams)) {
-    $inputParams['pledge_test'] = 0;
-  }
-
-  require_once 'CRM/Pledge/BAO/Query.php';
-  require_once 'CRM/Contact/BAO/Query.php';
-  if (empty($returnProperties)) {
-    $returnProperties = CRM_Pledge_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_PLEDGE);
-  }
-
-  $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
-
-  $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL);
-  list($select, $from, $where) = $query->query();
-
-  $sql = "$select $from $where";
-
-  if (!empty($sort)) {
-    $sql .= " ORDER BY $sort ";
-  }
-  $sql .= " LIMIT $offset, $rowCount ";
-  $dao = CRM_Core_DAO::executeQuery($sql);
-
-  $pledge = array();
-  while ($dao->fetch()) {
-    $pledge[$dao->pledge_id] = $query->store($dao);
-  }
-  $dao->free();
-
-  return $pledge;
-}
-
-/**
- *
- * @param <type> $params
- *
- * @return <type>
- */
-function &civicrm_pledge_payment_format_create(&$params) {
-  _civicrm_initialize();
-
-  // return error if we have no params
-  if (empty($params)) {
-    return civicrm_create_error('Input Parameters empty');
-  }
-
-  $error = _civicrm_pledge_check_params($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-  $values = array();
-  $error = _civicrm_pledge_format_params($params, $values);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $error = _civicrm_pledge_duplicate_check($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-  $ids = array();
-
-  CRM_Pledge_BAO_Pledge::resolveDefaults($params, TRUE);
-
-  $pledge = CRM_Pledge_BAO_Pledge::create($params, $ids);
-  _civicrm_object_to_array($pledge, $pledgeArray);
-  return $pledgeArray;
-}
-
-/**
- * This function ensures that we have the right input pledge 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 pledge.
- *
- * @return bool|CRM_Utils_Error
- * @access private
- */
-function _civicrm_pledgepayment_check_params(&$params) {
-  static $required = array(
-    'pledge_id',
-  );
-
-  // cannot create a pledge with empty params
-  if (empty($params)) {
-    return civicrm_create_error('Input Parameters empty');
-  }
-
-  $valid = TRUE;
-  $error = '';
-  foreach ($required as $field) {
-    if (!CRM_Utils_Array::value($field, $params)) {
-      $valid = FALSE;
-      $error .= $field;
-      break;
-    }
-  }
-
-  if (!$valid) {
-    return civicrm_create_error("Required fields not found for pledge $error");
-  }
-
-  return array();
-}
-
-/**
- * Check if there is a pledge with the same trxn_id or invoice_id
- *
- * @param array  $params       Associative array of property name/value
- *                             pairs to insert in new pledge.
- *
- * @return array|CRM_Error
- * @access private
- */
-
-
-/* not yet looked at
- * function _civicrm_pledge_duplicate_check( &$params ) {
-    require_once 'CRM/Pledge/BAO/Pledge.php';
-    $duplicates = array( );
-    $result = CRM_Pledge_BAO_Pledge::checkDuplicate( $params,$duplicates ); 
-    if ( $result ) {
-        $d = implode( ', ', $duplicates );
-        $error = CRM_Core_Error::createError( "Duplicate error - existing pledge record(s) have a matching Transaction ID or Invoice ID. pledge record ID(s) are: $d", CRM_Core_Error::DUPLICATE_pledge, 'Fatal', $d);
-        return civicrm_create_error( $error->pop( ),
-                                     $d );
-    } else {
-        return array();
-    }
-}
-*/
-
-/**
- * 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_pledgepayment_format_params(&$params, &$values, $create = FALSE) {
-  // copy all the pledge fields as is
-  require_once 'CRM/Pledge/BAO/PledgePayment.php';
-  require_once 'CRM/Pledge/DAO/Pledge.php';
-  $fields = CRM_Pledge_DAO_Pledge::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 '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 'receive_date':
-      case 'end_date':
-      case 'pledge_create_date':
-      case 'cancel_date':
-      case 'receipt_date':
-      case 'thankyou_date':
-        if (!CRM_Utils_Rule::date($value)) {
-          return civicrm_create_error("$key not a valid date: $value");
-        }
-        break;
-
-      case 'non_deductible_amount':
-      case 'total_amount':
-      case 'fee_amount':
-      case 'net_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 'pledge_type':
-        $values['pledge_type_id'] = CRM_Utils_Array::key(ucfirst($value),
-          CRM_Pledge_PseudoConstant::pledgeType()
-        );
-        break;
-
-      case 'payment_instrument':
-        require_once 'CRM/Core/OptionGroup.php';
-        $values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
-        break;
-
-      default:
-        break;
-    }
-  }
-
-  if (array_key_exists('note', $params)) {
-    $values['note'] = $params['note'];
-  }
-
-  if (array_key_exists('installment_amount', $params)) {
-    $values['installment_amount'] = $params['installment_amount'];
-  }
-  // testing testing - how do I make it take a create_date? It needs $values['create_date'] set but doesn't seem to like it because $fields calls it $pledge_create_date
-  //ditto scheduled date. I don't know why this is needs to be done because I don't fully understand the code above
-  if (array_key_exists('pledge_create_date', $params)) {
-    $values['create_date'] = $params['pledge_create_date'];
-  }
-  if (array_key_exists('pledge_scheduled_date', $params)) {
-    $values['scheduled_date'] = $params['pledge_scheduled_date'];
-  }
-  if (array_key_exists('pledge_create_date', $params)) {
-    $values['create_date'] = $params['pledge_create_date'];
-  }
-  if (array_key_exists('status_id', $params)) {
-    $values['status_id'] = $params['status_id'];
-    $values['pledge_status_id'] = $params['status_id'];
-  }
-
-  _civicrm_custom_format_params($params, $values, 'Pledge');
-
-  if ($create) {
-    // CRM_pledge_BAO_Pledge::add() handles Pledge_source
-    // So, if $values contains Pledge_source, convert it to source
-    $changes = array('pledge_source' => 'source');
-
-    foreach ($changes as $orgVal => $changeVal) {
-      if (isset($values[$orgVal])) {
-        $values[$changeVal] = $values[$orgVal];
-        unset($values[$orgVal]);
-      }
-    }
-  }
-
-  return array();
-}
-
-
-//having an 'interogate function to find what can be returned from an API would be SUPER useful. Ideally it would also advise which fields are required too. I
-// imaging the most useful format would be to be like the $params array you need to pass in but the value for each field would be information about it. Ideally the
-// function that sets which parameters are required would be accessible from this function to add them in
-// function at the moment doesn't have custom fields
-function civicrm_pledge_payment_interogate($params) {
-  $fields = CRM_Pledge_DAO_Pledge::fields();
-  $fields['installment_amount'] = array(
-    'name' => 'installment_amount',
-    'title' => ts('Installment Amount'),
-  );
-  unset($fields['amount']);
-  return $fields;
-}
-
-// this one should probably go in a pledge payment API
-function updatePledgePayments($pledgeId, $paymentStatusId, $paymentIds) {
-  require_once 'CRM/Pledge/BAO/Pledge.php';
-  $result = updatePledgePayments($pledgeId, $paymentStatusId, $paymentIds = NULL);
-  return $result;
-}
-
diff --git a/api/v2/Relationship.php b/api/v2/Relationship.php
deleted file mode 100644
index e4e1ce699e..0000000000
--- a/api/v2/Relationship.php
+++ /dev/null
@@ -1,470 +0,0 @@
-<?php
-// $Id: Relationship.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 relationship functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Relationship
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Relationship.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Contact/BAO/Relationship.php';
-require_once 'CRM/Contact/BAO/RelationshipType.php';
-
-/**
- * Add or update a relationship
- *
- * @param  array   $params   (reference ) input parameters
- *
- * @return array (reference) id of created or updated record
- * @static void
- * @access public
- */
-function civicrm_relationship_create(&$params) {
-  _civicrm_initialize();
-
-  // check params for required fields (add/update)
-  $error = _civicrm_relationship_check_params($params);
-  if (civicrm_error($error)) {
-    return $error;
-  }
-  $values = array();
-  require_once 'CRM/Contact/BAO/Relationship.php';
-  $error = _civicrm_relationship_format_params($params, $values);
-
-  if (civicrm_error($error)) {
-    return $error;
-  }
-
-  $ids = array();
-  $action = CRM_Core_Action::ADD;
-  require_once 'CRM/Utils/Array.php';
-
-  if (CRM_Utils_Array::value('id', $params)) {
-    $ids['relationship'] = $params['id'];
-    $ids['contactTarget'] = $params['contact_id_b'];
-    $action = CRM_Core_Action::UPDATE;
-  }
-
-  $values['relationship_type_id'] = $params['relationship_type_id'] . '_a_b';
-  $values['contact_check'] = array($params['contact_id_b'] => $params['contact_id_b']);
-  $ids['contact'] = $params['contact_id_a'];
-
-  $relationshipBAO = CRM_Contact_BAO_Relationship::create($values, $ids);
-
-  if (is_a($relationshipBAO, 'CRM_Core_Error')) {
-    return civicrm_create_error('Relationship can not be created');
-  }
-  elseif ($relationshipBAO[1]) {
-    return civicrm_create_error('Relationship is not valid');
-  }
-  elseif ($relationshipBAO[2]) {
-    return civicrm_create_error('Relationship already exists');
-  }
-  CRM_Contact_BAO_Relationship::relatedMemberships($params['contact_id_a'], $values, $ids, $action);
-
-  return civicrm_create_success(array('id' => implode(',', $relationshipBAO[4])));
-}
-
-/**
- * Delete a relationship
- *
- * @param  id of relationship  $id
- *
- * @return boolean  true if success, else false
- * @static void
- * @access public
- */
-function civicrm_relationship_delete(&$params) {
-
-  if (empty($params)) {
-    return civicrm_create_error('No input parameter present');
-  }
-
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Input parameter is not an array'));
-  }
-
-  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 ID');
-  }
-
-  $relationBAO = new CRM_Contact_BAO_Relationship();
-  $relationBAO->id = $params['id'];
-  if (!$relationBAO->find(TRUE)) {
-    return civicrm_create_error(ts('Relationship id is not valid'));
-  }
-  else {
-    $relationBAO->del($params['id']);
-    return civicrm_create_success(ts('Deleted relationship successfully'));
-  }
-}
-
-/**
- * Function to update relationship
- *
- * @param  array $params   Associative array of property name/value pairs to update the relationship
- *
- * @return array Array with relationship information
- *
- * @access public
- *
- */
-function civicrm_relationship_update($params) {
-  try {
-    _civicrm_initialize();
-    $errorScope = CRM_Core_TemporaryErrorScope::useException();
-
-    /*
-        * Erik Hommel, 5 Oct 2010 : fix for CRM-6895
-        * check if required field relationship_id is in the parms. As the
-        * CRM_Contact_BAO_Relationship::getRelatonship throws up some issues
-        * (CRM-6905) the relationship is retrieved with a direct query
-        */
-
-
-    civicrm_verify_mandatory($params, 'CRM_Contact_DAO_Relationship', array('relationship_id'));
-
-    $names = array(
-      'id', 'contact_id_a', 'contact_id_b',
-      'relationship_type_id', 'start_date', 'end_date', 'is_active',
-      'description', 'is_permission_a_b', 'is_permission_b_a', 'case_id',
-    );
-
-    $relationship_id = (int) $params['relationship_id'];
-    $query           = "SELECT * FROM civicrm_relationship WHERE id = $relationship_id";
-    $daoRelations    = CRM_Core_DAO::executeQuery($query);
-    while ($daoRelations->fetch()) {
-      foreach ($names as $name) {
-        $current_values[$name] = $daoRelations->$name;
-      }
-    }
-    $params = array_merge($current_values, $params);
-    $params['start_date'] = date("Ymd", strtotime($params['start_date']));
-    $params['end_date'] = date("Ymd", strtotime($params['end_date']));
-
-    return civicrm_relationship_create($params);
-  }
-  catch(PEAR_Exception$e) {
-    return civicrm_create_error($e->getMessage());
-  }
-  catch(Exception$e) {
-    return civicrm_create_error($e->getMessage());
-  }
-}
-
-/**
- * Function to get the relationship
- *
- * @param array   $params          (reference ) input parameters
- param['contact_id'] is mandatory
- *
- * @return        Array of all relationship.
- *
- * @access  public
- */
-function civicrm_relationship_get($params) {
-  if (!isset($params['contact_id'])) {
-    return civicrm_create_error(ts('Could not find contact_id in input parameters.'));
-  }
-
-  return civicrm_contact_relationship_get($params);
-}
-
-/**
- * backward compatibility function to match broken naming convention in v2.2.1 and prior
- */
-function civicrm_get_relationships($contact_a, $contact_b = NULL, $relationshipTypes = NULL, $sort = NULL) {
-  return civicrm_contact_relationship_get($contact_a, $contact_b, $relationshipTypes, $sort);
-}
-
-/**
- * Function to get the relationship
- *
- * @param array   $contact_a          (reference ) input parameters.
- * @param array   $contact_b          (reference ) input parameters.
- * @param array   $relationshipTypes  an array of Relationship Type Name.
- * @param string  $sort               sort all relationship by relationshipId (eg asc/desc)
- *
- * @return        Array of all relationship.
- *
- * @access  public
- */
-function civicrm_contact_relationship_get($contact_a, $contact_b = NULL, $relationshipTypes = NULL, $sort = NULL) {
-  if (!is_array($contact_a)) {
-    return civicrm_create_error(ts('Input parameter is not an array'));
-  }
-
-  if (!isset($contact_a['contact_id'])) {
-    return civicrm_create_error(ts('Could not find contact_id in input parameters.'));
-  }
-  require_once 'CRM/Contact/BAO/Relationship.php';
-  $contactID = $contact_a['contact_id'];
-  $relationships = CRM_Contact_BAO_Relationship::getRelationship($contactID);
-
-  if (!empty($relationshipTypes)) {
-    $result = array();
-    foreach ($relationshipTypes as $relationshipName) {
-      foreach ($relationships as $key => $relationship) {
-        if ($relationship['relation'] == $relationshipName) {
-          $result[$key] = $relationship;
-        }
-      }
-    }
-    $relationships = $result;
-  }
-
-  if (isset($contact_b['contact_id'])) {
-    $cid = $contact_b['contact_id'];
-    $result = array();
-
-    foreach ($relationships as $key => $relationship) {
-      if ($relationship['cid'] == $cid) {
-        $result[$key] = $relationship;
-      }
-    }
-    $relationships = $result;
-  }
-
-  //sort by relationship id
-  if ($sort) {
-    if (strtolower($sort) == 'asc') {
-      ksort($relationships);
-    }
-    elseif (strtolower($sort) == 'desc') {
-      krsort($relationships);
-    }
-  }
-
-  //handle custom data.
-  require_once 'CRM/Core/BAO/CustomGroup.php';
-
-  foreach ($relationships as $relationshipId => $values) {
-    $groupTree = &CRM_Core_BAO_CustomGroup::getTree('Relationship', CRM_Core_DAO::$_nullObject, $relationshipId, FALSE,
-      $values['civicrm_relationship_type_id']
-    );
-    $formatTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject);
-
-    $defaults = array();
-    CRM_Core_BAO_CustomGroup::setDefaults($formatTree, $defaults);
-
-    if (!empty($defaults)) {
-      foreach ($defaults as $key => $val) {
-        $relationships[$relationshipId][$key] = $val;
-      }
-    }
-  }
-
-  if ($relationships) {
-    return civicrm_create_success($relationships);
-  }
-  else {
-    return civicrm_create_error(ts('Invalid Data'));
-  }
-}
-
-/**
- * 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_relationship_format_params(&$params, &$values) {
-  // copy all the relationship fields as is
-
-  $fields = CRM_Contact_DAO_Relationship::fields();
-  _civicrm_store_values($fields, $params, $values);
-
-  $relationTypes = CRM_Core_PseudoConstant::relationshipType('name', TRUE);
-
-  foreach ($params as $key => $value) {
-    // ignore empty values or empty arrays etc
-    require_once 'CRM/Utils/System.php';
-    if (CRM_Utils_System::isNull($value)) {
-      continue;
-    }
-
-    switch ($key) {
-      case 'contact_id_a':
-      case 'contact_id_b':
-        require_once 'CRM/Utils/Rule.php';
-        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.");
-        }
-        break;
-
-      case 'start_date':
-      case 'end_date':
-        if (!CRM_Utils_Rule::qfDate($value)) {
-          return civicrm_create_error("$key not a valid date: $value");
-        }
-        break;
-
-      case 'relationship_type':
-        foreach ($relationTypes as $relTypId => $relValue) {
-          if (CRM_Utils_Array::key(ucfirst($value), $relValue)) {
-            $relationshipTypeId = $relTypId;
-            break;
-          }
-        }
-
-        if ($relationshipTypeId) {
-          if (CRM_Utils_Array::value('relationship_type_id', $values) &&
-            $relationshipTypeId != $values['relationship_type_id']
-          ) {
-            return civicrm_create_error('Mismatched Relationship Type and Relationship Type Id');
-          }
-          $values['relationship_type_id'] = $params['relationship_type_id'] = $relationshipTypeId;
-        }
-        else {
-          return civicrm_create_error('Invalid Relationship Type');
-        }
-      case 'relationship_type_id':
-        if ($key == 'relationship_type_id' && !array_key_exists($value, $relationTypes)) {
-          return civicrm_create_error("$key not a valid: $value");
-        }
-
-        // execute for both relationship_type and relationship_type_id
-        $relation = $relationTypes[$params['relationship_type_id']];
-        require_once 'CRM/Contact/BAO/Contact.php';
-        if ($relation['contact_type_a'] &&
-          $relation['contact_type_a'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_a'])
-        ) {
-          return civicrm_create_error("Contact ID :{$params['contact_id_a']} is not of contact type {$relation['contact_type_a']}");
-        }
-        if ($relation['contact_type_b'] &&
-          $relation['contact_type_b'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_b'])
-        ) {
-          return civicrm_create_error("Contact ID :{$params['contact_id_b']} is not of contact type {$relation['contact_type_b']}");
-        }
-        break;
-
-      default:
-        break;
-    }
-  }
-
-  if (array_key_exists('note', $params)) {
-    $values['note'] = $params['note'];
-  }
-  _civicrm_custom_format_params($params, $values, 'Relationship');
-
-  return array();
-}
-
-/**
- * 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();
-}
-
diff --git a/api/v2/RelationshipType.php b/api/v2/RelationshipType.php
deleted file mode 100644
index 8850cf936b..0000000000
--- a/api/v2/RelationshipType.php
+++ /dev/null
@@ -1,194 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * new version of civicrm apis. See blog post at
- * http://civicrm.org/node/131
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Contact
- * @copyright CiviCRM LLC (c) 2004-2013
- * $Id: Contact.php 30415 2010-10-29 12:02:47Z shot $
- *
- */
-
-/**
- * Include common API util functions
- */
-require_once 'api/v2/utils.php';
-
-//require ("api/v2/Relationship.php");
-
-/**
- * Function to update relationship type
- *
- * @param  array $params   Associative array of property name/value pairs to update the relationship type.
- *
- * @return array Array with relationship type information
- *
- * @access public
- *
- * @todo Requires some work
- */
-function civicrm_relationship_type_update($params) {
-  return civicrm_relationship_type_add($params);
-}
-/*
- * Deprecated function to create relationship type
- * 
- * @param  array $params   Associative array of property name/value pairs to insert in new relationship type.
- *
- * @return Newly created Relationship_type object
- *
- * @access public
- * 
- * @deprecated
- */
-function civicrm_relationship_type_add($params) {
-  $result = civicrm_relationship_type_create($params);
-  return $result;
-}
-
-/**
- * Function to create relationship type
- *
- * @param  array $params   Associative array of property name/value pairs to insert in new relationship type.
- *
- * @return Newly created Relationship_type object
- *
- * @access public
- *
- */
-function civicrm_relationship_type_create($params) {
-
-  if (empty($params)) {
-    return civicrm_create_error(ts('No input parameters present'));
-  }
-
-  if (!is_array($params)) {
-    return civicrm_create_error(ts('Parameter is not an array'));
-  }
-
-  if (!isset($params['contact_types_a']) &&
-    !isset($params['contact_types_b']) &&
-    !isset($params['name_a_b']) &&
-    !isset($params['name_b_a'])
-  ) {
-
-    return civicrm_create_error(ts('Missing some required parameters (contact_types_a contact_types_b name_a_b name b_a)'));
-  }
-
-  if (!isset($params['label_a_b'])) {
-
-    $params['label_a_b'] = $params['name_a_b'];
-  }
-
-  if (!isset($params['label_b_a'])) {
-
-    $params['label_b_a'] = $params['name_b_a'];
-  }
-
-  require_once 'CRM/Utils/Rule.php';
-
-  $ids = array();
-  if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
-    return civicrm_create_error('Invalid value for relationship type ID');
-  }
-  else {
-    $ids['relationshipType'] = CRM_Utils_Array::value('id', $params);
-  }
-
-  require_once 'CRM/Contact/BAO/RelationshipType.php';
-  $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids);
-
-  $relType = array();
-  _civicrm_object_to_array($relationType, $relType);
-
-  return $relType;
-}
-
-/**
- * Function to get all relationship type
- * retruns  An array of Relationship_type
- * * @access  public
- */
-function civicrm_relationship_types_get($params = NULL) {
-  _civicrm_initialize();
-  require_once 'CRM/Contact/DAO/RelationshipType.php';
-  $relationshipTypes = array();
-  $relationshipType  = array();
-  $relationType      = new CRM_Contact_DAO_RelationshipType();
-  if (!empty($params) && is_array($params)) {
-    $properties = array_keys($relationType->fields());
-    foreach ($properties as $name) {
-      if (array_key_exists($name, $params)) {
-        $relationType->$name = $params[$name];
-      }
-    }
-  }
-  $relationType->find();
-  while ($relationType->fetch()) {
-    _civicrm_object_to_array(clone($relationType), $relationshipType);
-    $relationshipTypes[] = $relationshipType;
-  }
-  return $relationshipTypes;
-}
-
-/**
- * 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'));
-}
-
-/**
- * Wrapper to support rest calls, CRM-6860
- * return An array of Relationship_type
- * * @access  public
- */
-function civicrm_relationshipType_get($params = NULL) {
-  return civicrm_relationship_types_get($params);
-}
-
diff --git a/api/v2/SurveyRespondant.php b/api/v2/SurveyRespondant.php
deleted file mode 100644
index e2c7054e8e..0000000000
--- a/api/v2/SurveyRespondant.php
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright Tech To The People (c) 2010                              |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 Petition Signatures functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Contribute
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Utils/Rule.php';
-require_once 'CRM/Campaign/BAO/Petition.php';
-
-/**
- * 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);
-}
-
-function &civicrm_survey_respondant_count(&$params) {
-  _civicrm_initialize();
-  $petition = new CRM_Campaign_BAO_Petition();
-  if (array_key_exists('groupby', $params) && $params['groupby'] == 'country') {
-    $signaturesCount = $petition->getPetitionSignatureTotalbyCountry($params['survey_id']);
-  }
-  else {
-    $signaturesCount = $petition->getPetitionSignatureTotal($params['survey_id']);
-  }
-  return ($signaturesCount);
-}
-
diff --git a/api/v2/Tag.php b/api/v2/Tag.php
deleted file mode 100644
index c0b75fb396..0000000000
--- a/api/v2/Tag.php
+++ /dev/null
@@ -1,165 +0,0 @@
-<?php
-// $Id: Tag.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 tag functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_Tag
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: Tag.php 45502 2013-02-08 13:32:55Z kurund $
- * @todo Erik Hommel 15/12/2010 version to be implemented
- */
-
-/**
- * Include utility functions
- */
-require_once 'api/v2/utils.php';
-
-/**
- *  Add a Tag. Tags are used to classify CRM entities (including Contacts, Groups and Actions).
- *
- * @param   array   $params          an associative array used in
- *                                   construction / retrieval of the
- *                                   object
- *
- * @return array of newly created tag property values.
- * @access public
- * @todo Erik Hommel 15/12/2010 : check if function is ok for update
- */
-function civicrm_tag_create(&$params) {
-  _civicrm_initialize();
-  $errorScope = CRM_Core_TemporaryErrorScope::useException();
-  try {
-
-    civicrm_verify_mandatory($params, 'CRM_Core_DAO_Tag', array('name'));
-
-    if (!array_key_exists('used_for', $params)) {
-      $params['used_for'] = "civicrm_contact";
-    }
-
-    require_once 'CRM/Core/BAO/Tag.php';
-    $ids = array('tag' => CRM_Utils_Array::value('tag', $params));
-    if (CRM_Utils_Array::value('tag', $params)) {
-      $ids['tag'] = $params['tag'];
-    }
-
-    $tagBAO = CRM_Core_BAO_Tag::add($params, $ids);
-
-    if (is_a($tagBAO, 'CRM_Core_Error')) {
-      return civicrm_create_error("Tag is not created");
-    }
-    else {
-      $values = array();
-      _civicrm_object_to_array($tagBAO, $values);
-      $tag             = array();
-      $tag['tag_id']   = $values['id'];
-      $tag['name']     = $values['name'];
-      $tag['is_error'] = 0;
-    }
-    return $tag;
-  }
-  catch(PEAR_Exception$e) {
-    return civicrm_create_error($e->getMessage());
-  }
-  catch(Exception$e) {
-    return civicrm_create_error($e->getMessage());
-  }
-}
-
-/**
- * Deletes an existing Tag
- *
- * @param  array  $params
- *
- * @return boolean | error  true if successfull, error otherwise
- * @access public
- */
-function civicrm_tag_delete(&$params) {
-  _civicrm_initialize();
-  $errorScope = CRM_Core_TemporaryErrorScope::useException();
-  try {
-    civicrm_verify_mandatory($params, NULL, array('tag_id'));
-    $tagID = CRM_Utils_Array::value('tag_id', $params);
-
-    require_once 'CRM/Core/BAO/Tag.php';
-    return CRM_Core_BAO_Tag::del($tagID) ? civicrm_create_success() : civicrm_create_error(ts('Could not delete tag'));
-  }
-  catch(Exception$e) {
-    if (CRM_Core_Error::$modeException) {
-      throw $e;
-    }
-    return civicrm_create_error($e->getMessage());
-  }
-}
-
-/**
- * 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', 'is_selectable', 'is_hidden',
-    'is_reserved', 'used_for',
-  );
-  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);
-  $tag['is_error'] = 0;
-  return $tag;
-}
-
diff --git a/api/v2/UFGroup.php b/api/v2/UFGroup.php
deleted file mode 100644
index 5506cd074e..0000000000
--- a/api/v2/UFGroup.php
+++ /dev/null
@@ -1,464 +0,0 @@
-<?php
-// $Id: UFGroup.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 user framework group functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_UF
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: UFGroup.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-require_once 'CRM/Core/BAO/UFGroup.php';
-
-/**
- * Most API functions take in associative arrays ( name => value pairs
- * as parameters. Some of the most commonly used parameters are
- * described below
- *
- * @param array $params           an associative array used in construction
- *                                / retrieval of the object
- * @param array $returnProperties the limited set of object properties that
- *                                need to be returned to the caller
- *
- */
-
-/**
- * Get all the user framework groups
- *
- * @access public
- *
- * @return array - array reference of all groups.
- * @static
- */
-function &civicrm_uf_profile_groups_get() {
-  return CRM_Core_PseudoConstant::ufGroup();
-}
-
-/**
- * Get the form title.
- *
- * @param int $id id of uf_form
- *
- * @return string title
- *
- * @access public
- * @static
- *
- */
-function civicrm_uf_profile_title_get($id) {
-  if ((int) $id > 0) {
-    return CRM_Core_BAO_UFGroup::getTitle($id);
-  }
-  else {
-    return civicrm_create_error('Param needs to be a positive integer.');
-  }
-}
-
-/**
- * get all the fields that belong to the group with the named title
- *
- * @param int $id       the id of the UF group
- * @param int $register are we interested in registration fields
- * @param int $action   what action are we doing
- * @param string $visibility visibility of fields we are interested in
- *
- * @return array the fields that belong to this title
- * @static
- * @access public
- */
-function civicrm_uf_profile_fields_get($id, $register = FALSE, $action = NULL, $visibility = NULL) {
-  if ((int) $id > 0) {
-    return CRM_Core_BAO_UFGroup::getFields($id, $register, $action, NULL, $visibility, FALSE, NULL, TRUE);
-  }
-  else {
-    return civicrm_create_error('Param needs to be a positive integer.');
-  }
-}
-
-/**
- * get the html for the form that represents this particular group
- *
- * @param int     $userID   the user id that we are actually editing
- * @param string  $title    the title of the group we are interested in
- * @param int     $action   the action of the form
- * @param boolean $register is this the registration form
- * @param boolean $reset    should we reset the form?
- *
- * @return string       the html for the form
- * @static
- * @access public
- */
-function civicrm_uf_profile_html_get($userID, $title, $action = NULL, $register = FALSE, $reset = FALSE) {
-  if ((int) $userID > 0 and is_string($title)) {
-    return CRM_Core_BAO_UFGroup::getEditHTML($userID, $title, $action, $register, $reset);
-  }
-  else {
-    return civicrm_create_error('Params need to be a positive integer and a string.');
-  }
-}
-
-/**
- * get the html for the form that represents this particular group
- *
- * @param int     $userID    the user id that we are actually editing
- * @param int     $profileID the id of the group we are interested in
- * @param int     $action    the action of the form
- * @param boolean $register  is this the registration form
- * @param boolean $reset     should we reset the form?
- *
- * @return string            the html for the form
- * @static
- * @access public
- */
-function civicrm_uf_profile_html_by_id_get($userID, $profileID, $action = NULL, $register = FALSE, $reset = FALSE) {
-  if ((int) $userID > 0 and (int) $profileID > 0) {
-    return CRM_Core_BAO_UFGroup::getEditHTML($userID, NULL, $action, $register, $reset, $profileID);
-  }
-  else {
-    return civicrm_create_error('Params need to be positive integers.');
-  }
-}
-
-/**
- * get the html for the form for profile creation
- *
- * @param int     $gid      group id
- * @param boolean $reset    should we reset the form?
- *
- * @return string       the html for the form
- * @static
- * @access public
- */
-function civicrm_uf_create_html_get($gid, $reset = FALSE) {
-  if ((int) $gid < 1) {
-    return civicrm_create_error('Param needs to be a positive integer.');
-  }
-
-  require_once 'CRM/Core/Controller/Simple.php';
-  $session = CRM_Core_Session::singleton();
-  $controller = new CRM_Core_Controller_Simple('CRM_Profile_Form_Edit', '', CRM_Core_Action::ADD);
-  if ($reset) {
-    unset($_POST['_qf_default']);
-    unset($_REQUEST['_qf_default']);
-  }
-  $controller->set('gid', $gid);
-  $controller->set('skipPermission', 1);
-  $controller->process();
-  $controller->setEmbedded(TRUE);
-  $controller->run();
-
-  $template = CRM_Core_Smarty::singleton();
-  return trim($template->fetch('CRM/Profile/Form/Dynamic.tpl'));
-}
-
-/**
- * get the contact_id given a uf_id
- *
- * @param int $ufID
- *
- * @return int contact_id
- * @access public
- * @static
- */
-function civicrm_uf_match_id_get($ufID) {
-  if ((int) $ufID > 0) {
-    require_once 'CRM/Core/BAO/UFMatch.php';
-    return CRM_Core_BAO_UFMatch::getContactId($ufID);
-  }
-  else {
-    return civicrm_create_error('Param needs to be a positive integer.');
-  }
-}
-
-/**
- * get the uf_id given a contact_id
- *
- * @param int $contactID
- *
- * @return int ufID
- * @access public
- * @static
- */
-function civicrm_uf_id_get($contactID) {
-  if ((int) $contactID > 0) {
-    require_once 'CRM/Core/BAO/UFMatch.php';
-    return CRM_Core_BAO_UFMatch::getUFId($contactID);
-  }
-  else {
-    return civicrm_create_error('Param needs to be a positive integer.');
-  }
-}
-
-/*******************************************************************/
-
-/**
- * Use this API to create a new group. See the CRM Data Model for uf_group property definitions
- *
- * @param $params  array   Associative array of property name/value pairs to insert in group.
- *
- * @return   Newly create $ufGroupArray array
- *
- * @access public
- */
-function civicrm_uf_group_create($params) {
-  if (!is_array($params) or empty($params) or !isset($params['title'])) {
-    return civicrm_create_error('Params must be an array and have a title field.');
-  }
-
-  _civicrm_initialize();
-
-  $ids = array();
-  require_once 'CRM/Core/BAO/UFGroup.php';
-
-  $ufGroup = CRM_Core_BAO_UFGroup::add($params, $ids);
-  _civicrm_object_to_array($ufGroup, $ufGroupArray);
-
-  return $ufGroupArray;
-}
-
-/**
- * Use this API to update  group. See the CRM Data Model for uf_group property definitions
- *
- * @param $params  array   Associative array of property name/value pairs to insert in group.
- *
- * @param $groupId int  A valid UF Group ID that to be updated.
- *
- * @return  updated  $ufGroupArray array
- *
- * @access public
- */
-function civicrm_uf_group_update($params, $groupId) {
-  if (!is_array($params) or empty($params) or (int) $groupId < 1) {
-    return civicrm_create_error('Params must be a non-empty array and a positive integer.');
-  }
-
-  _civicrm_initialize();
-
-  $ids = array();
-  $ids['ufgroup'] = $groupId;
-
-  require_once 'CRM/Core/BAO/UFGroup.php';
-
-  $ufGroup = CRM_Core_BAO_UFGroup::add($params, $ids);
-  _civicrm_object_to_array($ufGroup, $ufGroupArray);
-
-  return $ufGroupArray;
-}
-
-/**
- * Defines 'uf field' within a group.
- *
- * @param $groupId int Valid uf_group id
- *
- * @param $params  array  Associative array of property name/value pairs to create new uf field.
- *
- * @return Newly created $ufFieldArray array
- *
- * @access public
- *
- */
-function civicrm_uf_field_create($groupId, $params) {
-  if (!is_array($params) or !isset($params['field_name']) or (int) $groupId < 1) {
-    return civicrm_create_error('Params must be a field_name-carrying array and a positive integer.');
-  }
-
-  _civicrm_initialize();
-
-  $field_type       = CRM_Utils_Array::value('field_type', $params);
-  $field_name       = CRM_Utils_Array::value('field_name', $params);
-  $location_type_id = CRM_Utils_Array::value('location_type_id', $params);
-  $phone_type       = CRM_Utils_Array::value('phone_type', $params);
-
-  $params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
-
-  if (!(CRM_Utils_Array::value('group_id', $params))) {
-    $params['group_id'] = $groupId;
-  }
-
-  $ids = array();
-  $ids['uf_group'] = $groupId;
-
-  require_once 'CRM/Core/BAO/UFField.php';
-  if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
-    return civicrm_create_error("The field was not added. It already exists in this profile.");
-  }
-
-  $params['weight'] = CRM_Core_BAO_UFField::autoWeight($params);
-  $ufField = CRM_Core_BAO_UFField::add($params, $ids);
-  _civicrm_object_to_array($ufField, $ufFieldArray);
-
-  return $ufFieldArray;
-}
-
-/**
- * Use this API to update uf field . See the CRM Data Model for uf_field property definitions
- *
- * @param $params  array   Associative array of property name/value pairs to update in field.
- *
- * @param $fieldId int  A valid uf field id that to be updated.
- *
- * @return  updated  $ufFieldArray array
- *
- * @access public
- */
-function civicrm_uf_field_update($params, $fieldId) {
-
-  _civicrm_initialize();
-
-  if (!isset($fieldId)) {
-    return civicrm_create_error("parameter fieldId is not set");
-  }
-
-  if (!is_array($params)) {
-    return civicrm_create_error("params is not an array ");
-  }
-
-  $field_type       = CRM_Utils_Array::value('field_type', $params);
-  $field_name       = CRM_Utils_Array::value('field_name', $params);
-  $location_type_id = CRM_Utils_Array::value('location_type_id', $params);
-  $phone_type       = CRM_Utils_Array::value('phone_type', $params);
-
-  $params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
-
-  require_once 'CRM/Core/BAO/UFField.php';
-  $UFField = new CRM_core_BAO_UFField();
-  $UFField->id = $fieldId;
-
-  if (!(CRM_Utils_Array::value('group_id', $params)) && $UFField->find(TRUE)) {
-    $params['group_id'] = $UFField->uf_group_id;
-  }
-
-  $ids = array();
-
-  if ($UFField->find(TRUE)) {
-    $ids['uf_group'] = $UFField->uf_group_id;
-  }
-  else {
-    return civicrm_create_error("there is no field for this fieldId");
-  }
-  $ids['uf_field'] = $fieldId;
-
-  if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
-    return civicrm_create_error("The field was not added. It already exists in this profile.");
-  }
-
-  $params['weight'] = CRM_Core_BAO_UFField::autoWeight($params);
-  $ufField = CRM_Core_BAO_UFField::add($params, $ids);
-  _civicrm_object_to_array($ufField, $ufFieldArray);
-
-  return $ufFieldArray;
-}
-
-/**
- * Delete uf group
- *
- * @param $groupId int  Valid uf_group id that to be deleted
- *
- * @return true on successful delete or return error
- *
- * @access public
- *
- */
-function civicrm_uf_group_delete($groupId) {
-  _civicrm_initialize();
-
-  if (!isset($groupId)) {
-    return civicrm_create_error("provide a valid groupId.");
-  }
-
-  require_once 'CRM/Core/BAO/UFGroup.php';
-  return CRM_Core_BAO_UFGroup::del($groupId);
-}
-
-/**
- * Delete uf field
- *
- * @param $fieldId int  Valid uf_field id that to be deleted
- *
- * @return true on successful delete or return error
- *
- * @access public
- *
- */
-function civicrm_uf_field_delete($fieldId) {
-  _civicrm_initialize();
-
-  if (!isset($fieldId)) {
-    return civicrm_create_error("provide a valid fieldId.");
-  }
-
-  require_once 'CRM/Core/BAO/UFField.php';
-  return CRM_Core_BAO_UFField::del($fieldId);
-}
-
-/**
- * check the data validity
- *
- * @param int    $userID    the user id
- * @param string $title     the title of the group we are interested in
- * @param  boolean $register is this the registrtion form
- * @param int    $action  the action of the form
- *
- * @return error   if data not valid
- *
- * @access public
- */
-function civicrm_profile_html_validate($userID, $title, $action = NULL, $register = FALSE) {
-  return CRM_Core_BAO_UFGroup::isValid($userID, $title, $register, $action);
-}
-
-/**
- * used to edit uf field
- *
- * @param array as key value pair
-
- *
- * @return error   if updation fails else array of updated data
- *
- * @access public
- */
-function civicrm_uf_group_weight($params) {
-  unset($params['fnName']);
-  require_once 'CRM/Core/DAO/UFField.php';
-  foreach ($params as $key => $value) {
-    $value['is_active'] = 1;
-    $result[] = civicrm_uf_field_update($value, $key);
-  }
-  return $result;
-}
-
diff --git a/api/v2/UFJoin.php b/api/v2/UFJoin.php
deleted file mode 100644
index 44703335e0..0000000000
--- a/api/v2/UFJoin.php
+++ /dev/null
@@ -1,154 +0,0 @@
-<?php
-// $Id: UFJoin.php 45502 2013-02-08 13:32:55Z kurund $
-
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for the CiviCRM APIv2 user framework join functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_UF
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: UFJoin.php 45502 2013-02-08 13:32:55Z kurund $
- *
- */
-
-/**
- * Files required for this package
- */
-require_once 'api/v2/utils.php';
-
-require_once 'CRM/Core/BAO/UFJoin.php';
-
-/**
- * takes an associative array and creates a uf join array
- *
- * @param array $params assoc array of name/value pairs
- *
- * @return array CRM_Core_DAO_UFJoin Array
- * @access public
- *
- */
-function civicrm_uf_join_add($params) {
-  if (!is_array($params)) {
-    return civicrm_create_error("params is not an array");
-  }
-
-  if (empty($params)) {
-    return civicrm_create_error("params is an empty array");
-  }
-
-  if (!isset($params['uf_group_id'])) {
-    return civicrm_create_error("uf_group_id is required field");
-  }
-
-  $ufJoin = CRM_Core_BAO_UFJoin::create($params);
-  _civicrm_object_to_array($ufJoin, $ufJoinArray);
-  return $ufJoinArray;
-}
-
-/**
- * takes an associative array and updates a uf join array
- *
- * @param array $params assoc array of name/value pairs
- *
- * @return array  updated CRM_Core_DAO_UFJoin Array
- * @access public
- *
- */
-function civicrm_uf_join_edit($params) {
-  if (!is_array($params)) {
-    return civicrm_create_error("params is not an array");
-  }
-
-  if (empty($params)) {
-    return civicrm_create_error("params is an empty array");
-  }
-
-  if (!isset($params['uf_group_id'])) {
-    return civicrm_create_error("uf_group_id is required field");
-  }
-
-  $ufJoin = CRM_Core_BAO_UFJoin::create($params);
-  _civicrm_object_to_array($ufJoin, $ufJoinArray);
-  return $ufJoinArray;
-}
-
-/**
- * Given an assoc list of params, finds if there is a record
- * for this set of params
- *
- * @param array $params (reference) an assoc array of name/value pairs
- *
- * @return int or null
- * @access public
- *
- */
-function civicrm_uf_join_id_find(&$params) {
-  if (!is_array($params) || empty($params)) {
-    return civicrm_create_error("$params is not valid array");
-  }
-
-  if (!isset($params['id']) &&
-    (!isset($params['entity_table']) &&
-      !isset($params['entity_id']) &&
-      !isset($params['weight'])
-    )
-  ) {
-    return civicrm_create_error("$param should have atleast entity_table or entiy_id or weight");
-  }
-
-  return CRM_Core_BAO_UFJoin::findJoinEntryId($params);
-}
-
-/**
- * Given an assoc list of params, find if there is a record
- * for this set of params and return the group id
- *
- * @param array $params (reference) an assoc array of name/value pairs
- *
- * @return int or null
- * @access public
- *
- */
-function civicrm_uf_join_UFGroupId_find(&$params) {
-  if (!is_array($params) || empty($params)) {
-    return civicrm_create_error("$params is not valid array");
-  }
-
-  if (!isset($params['entity_table']) &&
-    !isset($params['entity_id']) &&
-    !isset($params['weight'])
-  ) {
-    return civicrm_create_error("$param should have atleast entity_table or entiy_id or weight");
-  }
-
-  return CRM_Core_BAO_UFJoin::findUFGroupId($params);
-}
-
diff --git a/api/v2/utils.php b/api/v2/utils.php
deleted file mode 100644
index 0c49691231..0000000000
--- a/api/v2/utils.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-// $Id: utils.php 40328 2012-05-11 23:06:13Z allen $
-
-
-if (!function_exists('_civicrm_initialize')) {
-  require_once 'api/v2/utils.v2.php';
-}
-
diff --git a/api/v2/utils.v2.php b/api/v2/utils.v2.php
deleted file mode 100644
index 40721c2baf..0000000000
--- a/api/v2/utils.v2.php
+++ /dev/null
@@ -1,1599 +0,0 @@
-<?php
-// $Id$
-
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*/
-
-/**
- * File for CiviCRM APIv2 utilitity functions
- *
- * @package CiviCRM_APIv2
- * @subpackage API_utils
- *
- * @copyright CiviCRM LLC (c) 2004-2013
- * @version $Id: utils.php 31877 2011-01-19 04:23:54Z shot $
- *
- */
-require_once 'api/api.php';
-
-/**
- * @todo Write documentation
- *
- */
-function _civicrm_initialize() {
-  require_once 'CRM/Core/Config.php';
-  $config = CRM_Core_Config::singleton();
-  }
-
-function civicrm_verify_mandatory(&$params, $daoName = NULL, $keys = array(
-  )) {
-  if (!is_array($params)) {
-    throw new Exception('Input parameters is not an array');
-  }
-
-  if ($daoName != NULL) {
-    _civicrm_check_required_fields($params, $daoName, TRUE);
-  }
-
-  foreach ($keys as $key) {
-    if (!array_key_exists($key, $params)) {
-      throw new Exception("Mandatory param missing: " . $key);
-    }
-  }
-}
-
-/**
- *
- * @param <type> $msg
- * @param <type> $data
- *
- * @return <type>
- */
-function &civicrm_create_error($msg, $data = NULL) {
-  return CRM_Core_Error::createAPIError($msg, $data);
-}
-
-/**
- *
- * @param <type> $result
- *
- * @return <type>
- */
-function civicrm_create_success($result = 1) {
-
-  $values = array();
-
-  $values['is_error'] = 0;
-  $values['result'] = $result;
-
-  return $values;
-}
-
-/**
- *  function to check if an error is actually a duplicate contact error
- *
- *  @param array $error (array of) valid Error values
- *
- *  @return true if error is duplicate contact error, false otherwise
- *
- *  @access public
- */
-function civicrm_duplicate($error) {
-  if (is_array($error) && civicrm_error($error)) {
-    $code = $error['error_message']['code'];
-    if ($code == CRM_Core_Error::DUPLICATE_CONTACT) {
-      return TRUE;
-    }
-  }
-  return FALSE;
-}
-
-/**
- *
- * @param <type> $fields
- * @param <type> $params
- * @param <type> $values
- *
- * @return <type>
- */
-function _civicrm_store_values(&$fields, &$params, &$values) {
-  $valueFound = FALSE;
-
-  $keys = array_intersect_key($params, $fields);
-  foreach ($fields as $name => $field) {
-    // ignore all ids for now
-    if ($name === 'id' || substr($name, -1, 3) === '_id') {
-      continue;
-    }
-    if (CRM_Utils_Array::value($name, $params)) {
-      $values[$name] = $params[$name];
-      $valueFound = TRUE;
-    }
-  }
-  return $valueFound;
-}
-
-/**
- * Converts an object to an array
- *
- * @param  object   $dao           (reference )object to convert
- * @param  array    $dao           (reference )array
- *
- * @return array
- * @static void
- * @access public
- */
-function _civicrm_object_to_array(&$dao, &$values) {
-  $tmpFields = $dao->fields();
-  $fields = array();
-  //rebuild $fields array to fix unique name of the fields
-  foreach ($tmpFields as $key => $val) {
-    $fields[$val["name"]] = $val;
-  }
-
-  foreach ($fields as $key => $value) {
-    if (array_key_exists($key, $dao)) {
-      $values[$key] = $dao->$key;
-    }
-  }
-}
-
-/**
- * This function adds the contact variable in $values to the
- * parameter list $params.  For most cases, $values should have length 1.  If
- * the variable being added is a child of Location, a location_type_id must
- * also be included.  If it is a child of phone, a phone_type must be included.
- *
- * @param array  $values    The variable(s) to be added
- * @param array  $params    The structured parameter list
- *
- * @return bool|CRM_Utils_Error
- * @access public
- */
-function _civicrm_add_formatted_param(&$values, &$params) {
-  /* Crawl through the possible classes: 
-     * Contact 
-     *      Individual 
-     *      Household
-     *      Organization
-     *          Location 
-     *              Address 
-     *              Email 
-     *              Phone 
-     *              IM 
-     *      Note
-     *      Custom 
-     */
-
-
-
-  /* Cache the various object fields */
-
-
-  static $fields = NULL;
-
-  if ($fields == NULL) {
-    $fields = array();
-  }
-
-  //first add core contact values since for other Civi modules they are not added
-  require_once 'CRM/Contact/BAO/Contact.php';
-  $contactFields = CRM_Contact_DAO_Contact::fields();
-  _civicrm_store_values($contactFields, $values, $params);
-
-  if (isset($values['contact_type'])) {
-    /* we're an individual/household/org property */
-
-
-
-    $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields();
-
-    _civicrm_store_values($fields[$values['contact_type']], $values, $params);
-    return TRUE;
-  }
-
-  if (isset($values['individual_prefix'])) {
-    if (CRM_Utils_Array::value('prefix_id', $params)) {
-      $prefixes         = array();
-      $prefixes         = CRM_Core_PseudoConstant::individualPrefix();
-      $params['prefix'] = $prefixes[$params['prefix_id']];
-    }
-    else {
-      $params['prefix'] = $values['individual_prefix'];
-    }
-    return TRUE;
-  }
-
-  if (isset($values['individual_suffix'])) {
-    if (CRM_Utils_Array::value('suffix_id', $params)) {
-      $suffixes         = array();
-      $suffixes         = CRM_Core_PseudoConstant::individualSuffix();
-      $params['suffix'] = $suffixes[$params['suffix_id']];
-    }
-    else {
-      $params['suffix'] = $values['individual_suffix'];
-    }
-    return TRUE;
-  }
-
-  //CRM-4575
-  if (isset($values['email_greeting'])) {
-    if (CRM_Utils_Array::value('email_greeting_id', $params)) {
-      $emailGreetings = array();
-      $emailGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params),
-        'greeting_type' => 'email_greeting',
-      );
-      $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter);
-      $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']];
-    }
-    else {
-      $params['email_greeting'] = $values['email_greeting'];
-    }
-
-    return TRUE;
-  }
-
-  if (isset($values['postal_greeting'])) {
-    if (CRM_Utils_Array::value('postal_greeting_id', $params)) {
-      $postalGreetings = array();
-      $postalGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params),
-        'greeting_type' => 'postal_greeting',
-      );
-      $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter);
-      $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']];
-    }
-    else {
-      $params['postal_greeting'] = $values['postal_greeting'];
-    }
-    return TRUE;
-  }
-
-  if (isset($values['addressee'])) {
-    if (CRM_Utils_Array::value('addressee_id', $params)) {
-      $addressee = array();
-      $addresseeFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params),
-        'greeting_type' => 'addressee',
-      );
-      $addressee = CRM_Core_PseudoConstant::addressee($addresseeFilter);
-      $params['addressee'] = $addressee[$params['addressee_id']];
-    }
-    else {
-      $params['addressee'] = $values['addressee'];
-    }
-    return TRUE;
-  }
-
-  if (isset($values['gender'])) {
-    if (CRM_Utils_Array::value('gender_id', $params)) {
-      $genders          = array();
-      $genders          = CRM_Core_PseudoConstant::gender();
-      $params['gender'] = $genders[$params['gender_id']];
-    }
-    else {
-      $params['gender'] = $values['gender'];
-    }
-    return TRUE;
-  }
-
-  if (isset($values['preferred_communication_method'])) {
-    $comm      = array();
-    $preffComm = array();
-    $pcm       = array();
-    $pcm       = array_change_key_case(array_flip(CRM_Core_PseudoConstant::pcm()), CASE_LOWER);
-
-    $preffComm = explode(',', $values['preferred_communication_method']);
-    foreach ($preffComm as $v) {
-      $v = strtolower(trim($v));
-      if (array_key_exists($v, $pcm)) {
-        $comm[$pcm[$v]] = 1;
-      }
-    }
-
-    $params['preferred_communication_method'] = $comm;
-    return TRUE;
-  }
-
-  //format the website params.
-  if (CRM_Utils_Array::value('url', $values)) {
-    static $websiteFields;
-    if (!is_array($websiteFields)) {
-      require_once 'CRM/Core/DAO/Website.php';
-      $websiteFields = CRM_Core_DAO_Website::fields();
-    }
-    if (!array_key_exists('website', $params) ||
-      !is_array($params['website'])
-    ) {
-      $params['website'] = array();
-    }
-
-    $websiteCount = count($params['website']);
-    _civicrm_store_values($websiteFields, $values,
-      $params['website'][++$websiteCount]
-    );
-
-    return TRUE;
-  }
-
-  // get the formatted location blocks into params - w/ 3.0 format, CRM-4605
-  if (CRM_Utils_Array::value('location_type_id', $values)) {
-    _civicrm_add_formatted_location_blocks($values, $params);
-    return TRUE;
-  }
-
-  if (isset($values['note'])) {
-    /* add a note field */
-
-
-    if (!isset($params['note'])) {
-      $params['note'] = array();
-    }
-    $noteBlock = count($params['note']) + 1;
-
-    $params['note'][$noteBlock] = array();
-    if (!isset($fields['Note'])) {
-      $fields['Note'] = CRM_Core_DAO_Note::fields();
-    }
-
-    // get the current logged in civicrm user
-    $session = CRM_Core_Session::singleton();
-    $userID = $session->get('userID');
-
-    if ($userID) {
-      $values['contact_id'] = $userID;
-    }
-
-    _civicrm_store_values($fields['Note'], $values, $params['note'][$noteBlock]);
-
-    return TRUE;
-  }
-
-  /* Check for custom field values */
-
-
-  if (!CRM_Utils_Array::value('custom', $fields)) {
-    $fields['custom'] = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values));
-  }
-
-  foreach ($values 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, $fields['custom'])) {
-        return civicrm_create_error('Invalid custom field ID');
-      }
-      else {
-        $params[$key] = $value;
-      }
-    }
-  }
-}
-
-/**
- * This function format location blocks w/ v3.0 format.
- *
- * @param array  $values    The variable(s) to be added
- * @param array  $params    The structured parameter list
- *
- * @return bool
- * @access public
- */
-function _civicrm_add_formatted_location_blocks(&$values, &$params) {
-  static $fields = NULL;
-  if ($fields == NULL) {
-    $fields = array();
-  }
-
-  foreach (array(
-    'Phone', 'Email', 'IM', 'OpenID') as $block) {
-    $name = strtolower($block);
-    if (!array_key_exists($name, $values)) {
-      continue;
-    }
-
-    // block present in value array.
-    if (!array_key_exists($name, $params) || !is_array($params[$name])) {
-      $params[$name] = array();
-    }
-
-    if (!array_key_exists($block, $fields)) {
-      require_once (str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_DAO_" . $block) . ".php");
-      eval('$fields[$block] =& CRM_Core_DAO_' . $block . '::fields( );');
-    }
-
-    $blockCnt = count($params[$name]);
-
-    // copy value to dao field name.
-    if ($name == 'im') {
-      $values['name'] = $values[$name];
-    }
-
-    _civicrm_store_values($fields[$block], $values,
-      $params[$name][++$blockCnt]
-    );
-
-    if (!CRM_Utils_Array::value('id', $params) && ($blockCnt == 1)) {
-      $params[$name][$blockCnt]['is_primary'] = TRUE;
-    }
-
-    // we only process single block at a time.
-    return TRUE;
-  }
-
-  // handle address fields.
-  if (!array_key_exists('address', $params) || !is_array($params['address'])) {
-    $params['address'] = array();
-  }
-
-  $addressCnt = 1;
-  foreach ($params['address'] as $cnt => $addressBlock) {
-    if (CRM_Utils_Array::value('location_type_id', $values) ==
-      CRM_Utils_Array::value('location_type_id', $addressBlock)
-    ) {
-      $addressCnt = $cnt;
-      break;
-    }
-    $addressCnt++;
-  }
-
-  if (!array_key_exists('Address', $fields)) {
-    require_once 'CRM/Core/DAO/Address.php';
-    $fields['Address'] = CRM_Core_DAO_Address::fields();
-  }
-  _civicrm_store_values($fields['Address'], $values, $params['address'][$addressCnt]);
-
-  $addressFields = array(
-    'county', 'country', 'state_province',
-    'supplemental_address_1', 'supplemental_address_2',
-    'StateProvince.name',
-  );
-
-  foreach ($addressFields as $field) {
-    if (array_key_exists($field, $values)) {
-      if (!array_key_exists('address', $params)) {
-        $params['address'] = array();
-      }
-      $params['address'][$addressCnt][$field] = $values[$field];
-    }
-  }
-  //Handle Address Custom data
-  $fields['address_custom'] = CRM_Core_BAO_CustomField::getFields('Address');
-  foreach ($values 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, $fields['address_custom'])) {
-        $type = $fields['address_custom'][$customFieldID]['html_type'];
-        _civicrm_add_custom_formatted_param($customFieldID, $key, $value, $params['address'][$addressCnt], $type);
-      }
-      else {
-        return civicrm_create_error('Invalid custom field ID');
-      }
-    }
-  }
-
-  if ($addressCnt == 1) {
-
-    $params['address'][$addressCnt]['is_primary'] = TRUE;
-  }
-
-  return TRUE;
-}
-
-/**
- * Check a formatted parameter list for required fields.  Note that this
- * function does no validation or dupe checking.
- *
- * @param array $params  Structured parameter list (as in crm_format_params)
- *
- * @return bool|CRM_core_Error  Parameter list has all required fields
- * @access public
- */
-function _civicrm_required_formatted_contact(&$params) {
-
-  if (!isset($params['contact_type'])) {
-    return civicrm_create_error('No contact type specified');
-  }
-
-  switch ($params['contact_type']) {
-    case 'Individual':
-      if (isset($params['first_name']) && isset($params['last_name'])) {
-        return civicrm_create_success(TRUE);
-      }
-
-      if (array_key_exists('email', $params) &&
-        is_array($params['email']) &&
-        !CRM_Utils_System::isNull($params['email'])
-      ) {
-        return civicrm_create_success(TRUE);
-      }
-      break;
-
-    case 'Household':
-      if (isset($params['household_name'])) {
-        return civicrm_create_success(TRUE);
-      }
-      break;
-
-    case 'Organization':
-      if (isset($params['organization_name'])) {
-        return civicrm_create_success(TRUE);
-      }
-      break;
-
-    default:
-      return civicrm_create_error('Invalid Contact Type: ' . $params['contact_type']);
-  }
-
-  return civicrm_create_error('Missing required fields');
-}
-
-/**
- *
- * @param array $params
- * @param int   $dedupeRuleGroupID - the dedupe rule ID to use if present
- *
- */
-function _civicrm_duplicate_formatted_contact(&$params,
-  $dedupeRuleGroupID = NULL
-) {
-  $id = CRM_Utils_Array::value('id', $params);
-  $externalId = CRM_Utils_Array::value('external_identifier', $params);
-  if ($id || $externalId) {
-    $contact = new CRM_Contact_DAO_Contact();
-
-    $contact->id = $id;
-    $contact->external_identifier = $externalId;
-
-    if ($contact->find(TRUE)) {
-      if ($params['contact_type'] != $contact->contact_type) {
-        return civicrm_create_error("Mismatched contact IDs OR Mismatched contact Types");
-      }
-
-      $error = CRM_Core_Error::createError("Found matching contacts: $contact->id",
-        CRM_Core_Error::DUPLICATE_CONTACT,
-        'Fatal', $contact->id
-      );
-      return civicrm_create_error($error->pop());
-    }
-  }
-  else {
-    require_once 'CRM/Dedupe/Finder.php';
-    $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']);
-    $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams,
-      $params['contact_type'],
-      'Strict',
-      array(),
-      $dedupeRuleGroupID
-    );
-
-    if (!empty($ids)) {
-      $ids = implode(',', $ids);
-      $error = CRM_Core_Error::createError("Found matching contacts: $ids",
-        CRM_Core_Error::DUPLICATE_CONTACT,
-        'Fatal', $ids
-      );
-      return civicrm_create_error($error->pop());
-    }
-  }
-  return civicrm_create_success(TRUE);
-}
-
-/**
- * Validate a formatted contact parameter list.
- *
- * @param array $params  Structured parameter list (as in crm_format_params)
- *
- * @return bool|CRM_Core_Error
- * @access public
- */
-function _civicrm_validate_formatted_contact(&$params) {
-  /* Look for offending email addresses */
-
-
-  if (array_key_exists('email', $params)) {
-    foreach ($params['email'] as $count => $values) {
-      if (!is_array($values)) {
-        continue;
-      }
-      if ($email = CRM_Utils_Array::value('email', $values)) {
-        //validate each email
-        if (!CRM_Utils_Rule::email($email)) {
-          return civicrm_create_error('No valid email address');
-        }
-
-        //check for loc type id.
-        if (!CRM_Utils_Array::value('location_type_id', $values)) {
-          return civicrm_create_error('Location Type Id missing.');
-        }
-      }
-    }
-  }
-
-  /* Validate custom data fields */
-
-
-  if (array_key_exists('custom', $params) && is_array($params['custom'])) {
-    foreach ($params['custom'] as $key => $custom) {
-      if (is_array($custom)) {
-        $valid = CRM_Core_BAO_CustomValue::typecheck(
-          $custom['type'], $custom['value']
-        );
-        if (!$valid) {
-          return civicrm_create_error('Invalid value for custom field \'' .
-            $custom['name'] . '\''
-          );
-        }
-        if ($custom['type'] == 'Date') {
-          $params['custom'][$key]['value'] = str_replace('-', '', $params['custom'][$key]['value']);
-        }
-      }
-    }
-  }
-
-  return civicrm_create_success(TRUE);
-}
-
-/**
- *
- * @param array $params
- * @param array $values
- * @param string $extends entity that this custom field extends (e.g. contribution, event, contact)
- * @param string $entityId ID of entity per $extends
- */
-function _civicrm_custom_format_params(&$params, &$values, $extends, $entityId = NULL) {
-  $values['custom'] = array();
-
-  require_once 'CRM/Core/BAO/CustomField.php';
-  foreach ($params as $key => $value) {
-    list($customFieldID, $customValueID) = CRM_Core_BAO_CustomField::getKeyID($key, TRUE);
-    if ($customFieldID) {
-      CRM_Core_BAO_CustomField::formatCustomField($customFieldID, $values['custom'],
-        $value, $extends, $customValueID, $entityId
-      );
-    }
-  }
-}
-
-/**
- * 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 history.
- *
- *
- * @return bool true if success false otherwise
- * @access public
- */
-function _civicrm_check_required_fields(&$params, $daoName, $throwException = FALSE) {
-  if (isset($params['extends'])) {
-    if (($params['extends'] == 'Activity' ||
-        $params['extends'] == 'Phonecall' ||
-        $params['extends'] == 'Meeting' ||
-        $params['extends'] == 'Group' ||
-        $params['extends'] == 'Contribution'
-      ) &&
-      ($params['style'] == 'Tab')
-    ) {
-      return civicrm_create_error(ts("Can not create Custom Group in Tab for " . $params['extends']));
-    }
-  }
-
-  require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php");
-
-  $dao = new $daoName();
-  $fields = $dao->fields();
-
-  $missing = array();
-  foreach ($fields as $k => $v) {
-    if ($k == 'id') {
-      continue;
-    }
-
-    if (isset($v['required'])) {
-      if ($v['required'] && !(isset($params[$k]))) {
-        $missing[] = $k;
-      }
-    }
-  }
-
-  if (!empty($missing)) {
-    if ($throwException) {
-      throw new Exception("Required fields " . implode(',', $missing) . " for $daoName are not found");
-    }
-    return civicrm_create_error(ts("Required fields " . implode(',', $missing) . " for $daoName are not found"));
-  }
-
-  return TRUE;
-}
-
-/**
- * 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_Event_BAO_Participant:create()
- *
- * @return array|CRM_Error
- * @access public
- */
-function _civicrm_participant_formatted_param(&$params, &$values, $create = FALSE) {
-  $fields = CRM_Event_DAO_Participant::fields();
-  _civicrm_store_values($fields, $params, $values);
-
-  require_once 'CRM/Core/OptionGroup.php';
-  $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
-
-  foreach ($params as $key => $value) {
-    // ignore empty values or empty arrays etc
-    if (CRM_Utils_System::isNull($value)) {
-      continue;
-    }
-
-    //Handling Custom Data
-    _civicrm_generic_handle_custom_data($key, $value, $values, $customFields);
-
-    switch ($key) {
-      case 'participant_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['participant_contact_id'];
-        unset($values['participant_contact_id']);
-        break;
-
-      case 'participant_register_date':
-        if (!CRM_Utils_Rule::date($value)) {
-          return civicrm_create_error("$key not a valid date: $value");
-        }
-        break;
-
-      case 'event_title':
-        $id = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $value, 'id', 'title');
-        $values['event_id'] = $id;
-        break;
-
-      case 'event_id':
-        if (!CRM_Utils_Rule::integer($value)) {
-          return civicrm_create_error("Event ID is not valid: $value");
-        }
-        $dao     = new CRM_Core_DAO();
-        $qParams = array();
-        $svq     = $dao->singleValueQuery("SELECT id FROM civicrm_event WHERE id = $value",
-          $qParams
-        );
-        if (!$svq) {
-          return civicrm_create_error("Invalid Event ID: There is no event record with event_id = $value.");
-        }
-        break;
-
-      case 'participant_status':
-        $values['status_id'] = $values['participant_status_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $value, 'id', 'label');
-        break;
-
-      case 'participant_status_id':
-        if ((int) $value) {
-          $values['status_id'] = $values[$key] = $value;
-        }
-        else {
-          $id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $value, 'id', 'label');
-          $values['status_id'] = $values[$key] = $id;
-        }
-        break;
-
-      case 'participant_role_id':
-      case 'participant_role':
-        $role = CRM_Event_PseudoConstant::participantRole();
-        $participantRoles = explode(",", $value);
-        foreach ($participantRoles as $k => $v) {
-          $v = trim($v);
-          if ($key == 'participant_role') {
-            $participantRoles[$k] = CRM_Utils_Array::key($v, $role);
-          }
-          else {
-            $participantRoles[$k] = $v;
-          }
-        }
-        require_once 'CRM/Core/DAO.php';
-        $values['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $participantRoles);
-        unset($values[$key]);
-        break;
-
-      default:
-        break;
-    }
-  }
-
-  if (array_key_exists('participant_note', $params)) {
-    $values['participant_note'] = $params['participant_note'];
-  }
-
-  if ($create) {
-    // CRM_Event_BAO_Participant::create() handles register_date,
-    // status_id and source. So, if $values contains
-    // participant_register_date, participant_status_id or participant_source,
-    // convert it to register_date, status_id or source
-    $changes = array(
-      'participant_register_date' => 'register_date',
-      'participant_source' => 'source',
-      'participant_status_id' => 'status_id',
-      'participant_role_id' => 'role_id',
-      'participant_fee_level' => 'fee_level',
-      'participant_fee_amount' => 'fee_amount',
-      'participant_id' => 'id',
-    );
-
-    foreach ($changes as $orgVal => $changeVal) {
-      if (isset($values[$orgVal])) {
-        $values[$changeVal] = $values[$orgVal];
-        unset($values[$orgVal]);
-      }
-    }
-  }
-
-  return NULL;
-}
-
-/**
- * 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_contribute_formatted_param(&$params, &$values, $create = FALSE) {
-  // copy all the contribution fields as is
-
-  $fields = CRM_Contribute_DAO_Contribution::fields();
-
-  _civicrm_store_values($fields, $params, $values);
-
-  require_once 'CRM/Core/OptionGroup.php';
-  $customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
-
-  foreach ($params as $key => $value) {
-    // ignore empty values or empty arrays etc
-    if (CRM_Utils_System::isNull($value)) {
-      continue;
-    }
-
-    //Handling Custom Data
-    _civicrm_generic_handle_custom_data($key, $value, $values, $customFields);
-
-    switch ($key) {
-      case 'contribution_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['contribution_contact_id'];
-        unset($values['contribution_contact_id']);
-        break;
-
-      case 'contact_type':
-        //import contribution record according to select contact type
-        require_once 'CRM/Contact/DAO/Contact.php';
-        $contactType = new CRM_Contact_DAO_Contact();
-        //when insert mode check contact id or external identifire
-        if ($params['contribution_contact_id'] || $params['external_identifier']) {
-          if ($params['contribution_contact_id']) {
-            $contactType->id = $params['contribution_contact_id'];
-          }
-          elseif ($params['external_identifier']) {
-            $contactType->external_identifier = $params['external_identifier'];
-          }
-          if ($contactType->find(TRUE)) {
-            if ($params['contact_type'] != $contactType->contact_type) {
-              return civicrm_create_error("Contact Type is wrong: $contactType->contact_type");
-            }
-          }
-        }
-        elseif ($params['contribution_id'] || $params['trxn_id'] || $params['invoice_id']) {
-          //when update mode check contribution id or trxn id or
-          //invoice id
-          $contactId = new CRM_Contribute_DAO_Contribution();
-          if ($params['contribution_id']) {
-            $contactId->id = $params['contribution_id'];
-          }
-          elseif ($params['trxn_id']) {
-            $contactId->trxn_id = $params['trxn_id'];
-          }
-          elseif ($params['invoice_id']) {
-            $contactId->invoice_id = $params['invoice_id'];
-          }
-          if ($contactId->find(TRUE)) {
-            $contactType->id = $contactId->contact_id;
-            if ($contactType->find(TRUE)) {
-              if ($params['contact_type'] != $contactType->contact_type) {
-                return civicrm_create_error("Contact Type is wrong: $contactType->contact_type");
-              }
-            }
-          }
-        }
-        break;
-
-      case 'receive_date':
-      case 'cancel_date':
-      case 'receipt_date':
-      case 'thankyou_date':
-        if (!CRM_Utils_Rule::date($value)) {
-          return civicrm_create_error("$key not a valid date: $value");
-        }
-        break;
-
-      case 'non_deductible_amount':
-      case 'total_amount':
-      case 'fee_amount':
-      case 'net_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 'financial_type':
-        require_once 'CRM/Contribute/PseudoConstant.php';
-            $contriTypes = CRM_Contribute_PseudoConstant::financialType( );
-        foreach ($contriTypes as $val => $type) {
-          if (strtolower($value) == strtolower($type)) {
-                    $values['financial_type_id'] = $val;
-            break;
-          }
-        }
-        if (!CRM_Utils_Array::value('financial_type_id', $values)) {
-          return civicrm_create_error("Financial Type is not valid: $value");
-        }
-        break;
-
-      case 'payment_instrument':
-        require_once 'CRM/Core/OptionGroup.php';
-        $values['payment_instrument_id'] = CRM_Core_OptionGroup::getValue('payment_instrument', $value);
-        if (!CRM_Utils_Array::value('payment_instrument_id', $values)) {
-          return civicrm_create_error("Payment Instrument is not valid: $value");
-        }
-        break;
-
-      case 'contribution_status_id':
-        require_once 'CRM/Core/OptionGroup.php';
-        if (!$values['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', $value)) {
-          return civicrm_create_error("Contribution Status is not valid: $value");
-        }
-        break;
-
-      case 'honor_type_id':
-        require_once 'CRM/Core/OptionGroup.php';
-        $values['honor_type_id'] = CRM_Core_OptionGroup::getValue('honor_type', $value);
-        if (!CRM_Utils_Array::value('honor_type_id', $values)) {
-          return civicrm_create_error("Honor Type is not valid: $value");
-        }
-        break;
-
-      case 'soft_credit':
-        //import contribution record according to select contact type
-
-        // validate contact id and external identifier.
-        $contactId = CRM_Utils_Array::value('contact_id', $params['soft_credit']);
-        $externalId = CRM_Utils_Array::value('external_identifier', $params['soft_credit']);
-        if ($contactId || $externalId) {
-          require_once 'CRM/Contact/DAO/Contact.php';
-          $contact = new CRM_Contact_DAO_Contact();
-          $contact->id = $contactId;
-          $contact->external_identifier = $externalId;
-
-          $errorMsg = NULL;
-          if (!$contact->find(TRUE)) {
-            $errorMsg = ts("No match found for specified Soft Credit contact data. Row was skipped.");
-          }
-          elseif ($params['contact_type'] != $contact->contact_type) {
-            $errorMsg = ts("Soft Credit Contact Type is wrong: %1", array(1 => $contact->contact_type));
-          }
-
-          if ($errorMsg) {
-            return civicrm_create_error($errorMsg, 'soft_credit');
-          }
-
-          // finally get soft credit contact id.
-          $values['soft_credit_to'] = $contact->id;
-        }
-        else {
-          // get the contact id from dupicate contact rule, if more than one contact is returned
-          // we should return error, since current interface allows only one-one mapping
-
-          $softParams = $params['soft_credit'];
-          $softParams['contact_type'] = $params['contact_type'];
-
-          $error = _civicrm_duplicate_formatted_contact($softParams);
-
-          if (isset($error['error_message']['params'][0])) {
-            $matchedIDs = explode(',', $error['error_message']['params'][0]);
-
-            // check if only one contact is found
-            if (count($matchedIDs) > 1) {
-              return civicrm_create_error($error['error_message']['message'], 'soft_credit');
-            }
-            else {
-              $values['soft_credit_to'] = $matchedIDs[0];
-            }
-          }
-          else {
-            return civicrm_create_error('No match found for specified Soft Credit contact data. Row was skipped.', 'soft_credit');
-          }
-        }
-        break;
-
-      case 'pledge_payment':
-      case 'pledge_id':
-
-        //giving respect to pledge_payment flag.
-        if (!CRM_Utils_Array::value('pledge_payment', $params)) {
-          continue;
-        }
-
-        //get total amount of from import fields
-        $totalAmount = CRM_Utils_Array::value('total_amount', $params);
-
-        $onDuplicate = CRM_Utils_Array::value('onDuplicate', $params);
-
-        //we need to get contact id $contributionContactID to
-        //retrieve pledge details as well as to validate pledge ID
-
-        //first need to check for update mode
-        if ($onDuplicate == CRM_Contribute_Import_Parser::DUPLICATE_UPDATE &&
-          ($params['contribution_id'] || $params['trxn_id'] || $params['invoice_id'])
-        ) {
-          $contribution = new CRM_Contribute_DAO_Contribution();
-          if ($params['contribution_id']) {
-            $contribution->id = $params['contribution_id'];
-          }
-          elseif ($params['trxn_id']) {
-            $contribution->trxn_id = $params['trxn_id'];
-          }
-          elseif ($params['invoice_id']) {
-            $contribution->invoice_id = $params['invoice_id'];
-          }
-
-          if ($contribution->find(TRUE)) {
-            $contributionContactID = $contribution->contact_id;
-            if (!$totalAmount) {
-              $totalAmount = $contribution->total_amount;
-            }
-          }
-          else {
-            return civicrm_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
-          }
-        }
-        else {
-          // first get the contact id for given contribution record.
-          if (CRM_Utils_Array::value('contribution_contact_id', $params)) {
-            $contributionContactID = $params['contribution_contact_id'];
-          }
-          elseif (CRM_Utils_Array::value('external_identifier', $params)) {
-            require_once 'CRM/Contact/DAO/Contact.php';
-            $contact = new CRM_Contact_DAO_Contact();
-            $contact->external_identifier = $params['external_identifier'];
-            if ($contact->find(TRUE)) {
-              $contributionContactID = $params['contribution_contact_id'] = $values['contribution_contact_id'] = $contact->id;
-            }
-            else {
-              return civicrm_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
-            }
-          }
-          else {
-            // we  need to get contribution contact using de dupe
-            $error = civicrm_check_contact_dedupe($params);
-
-            if (isset($error['error_message']['params'][0])) {
-              $matchedIDs = explode(',', $error['error_message']['params'][0]);
-
-              // check if only one contact is found
-              if (count($matchedIDs) > 1) {
-                return civicrm_create_error($error['error_message']['message'], 'pledge_payment');
-              }
-              else {
-                $contributionContactID = $params['contribution_contact_id'] = $values['contribution_contact_id'] = $matchedIDs[0];
-              }
-            }
-            else {
-              return civicrm_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
-            }
-          }
-        }
-
-        if (CRM_Utils_Array::value('pledge_id', $params)) {
-          if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $params['pledge_id'], 'contact_id') != $contributionContactID) {
-            return civicrm_create_error('Invalid Pledge ID provided. Contribution row was skipped.', 'pledge_payment');
-          }
-          $values['pledge_id'] = $params['pledge_id'];
-        }
-        else {
-          //check if there are any pledge related to this contact, with payments pending or in progress
-          require_once 'CRM/Pledge/BAO/Pledge.php';
-          $pledgeDetails = CRM_Pledge_BAO_Pledge::getContactPledges($contributionContactID);
-
-          if (empty($pledgeDetails)) {
-            return civicrm_create_error('No open pledges found for this contact. Contribution row was skipped.', 'pledge_payment');
-          }
-          elseif (count($pledgeDetails) > 1) {
-            return civicrm_create_error('This contact has more than one open pledge. Unable to determine which pledge to apply the contribution to. Contribution row was skipped.', 'pledge_payment');
-          }
-
-          // this mean we have only one pending / in progress pledge
-          $values['pledge_id'] = $pledgeDetails[0];
-        }
-
-        //we need to check if oldest payment amount equal to contribution amount
-        require_once 'CRM/Pledge/BAO/PledgePayment.php';
-        $pledgePaymentDetails = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($values['pledge_id']);
-
-        if ($pledgePaymentDetails['amount'] == $totalAmount) {
-          $values['pledge_payment_id'] = $pledgePaymentDetails['id'];
-        }
-        else {
-          return civicrm_create_error('Contribution and Pledge Payment amount mismatch for this record. Contribution row was skipped.', 'pledge_payment');
-        }
-        break;
-
-      default:
-        break;
-    }
-  }
-
-  if (array_key_exists('note', $params)) {
-    $values['note'] = $params['note'];
-  }
-
-  if ($create) {
-    // CRM_Contribute_BAO_Contribution::add() handles contribution_source
-    // So, if $values contains contribution_source, convert it to source
-    $changes = array('contribution_source' => 'source');
-
-    foreach ($changes as $orgVal => $changeVal) {
-      if (isset($values[$orgVal])) {
-        $values[$changeVal] = $values[$orgVal];
-        unset($values[$orgVal]);
-      }
-    }
-  }
-
-  return NULL;
-}
-
-/**
- * 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
- *
- * @todo shouldn't it be moved to Membership.php?
- *
- * @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|CRM_Error
- * @access public
- */
-function _civicrm_membership_formatted_param(&$params, &$values, $create = FALSE) {
-  require_once "CRM/Member/DAO/Membership.php";
-  $fields = CRM_Member_DAO_Membership::fields();
-
-  _civicrm_store_values($fields, $params, $values);
-
-  require_once 'CRM/Core/OptionGroup.php';
-  $customFields = CRM_Core_BAO_CustomField::getFields('Membership');
-
-  foreach ($params as $key => $value) {
-    // ignore empty values or empty arrays etc
-    if (CRM_Utils_System::isNull($value)) {
-      continue;
-    }
-
-    //Handling Custom Data
-    _civicrm_generic_handle_custom_data($key, $value, $values, $customFields);
-
-    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;
-
-      case 'member_is_test':
-        $values['is_test'] = CRM_Utils_Array::value($key, $params, FALSE);
-        unset($values['member_is_test']);
-        break;
-
-      default:
-        break;
-    }
-  }
-
-  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;
-}
-
-/**
- * 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_Activity_BAO_Activity::create()
- *
- * @return array|CRM_Error
- * @access public
- */
-function _civicrm_activity_formatted_param(&$params, &$values, $create = FALSE) {
-  $fields = CRM_Activity_DAO_Activity::fields();
-  _civicrm_store_values($fields, $params, $values);
-
-  require_once 'CRM/Core/OptionGroup.php';
-  $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
-
-  foreach ($params as $key => $value) {
-    // ignore empty values or empty arrays etc
-    if (CRM_Utils_System::isNull($value)) {
-      continue;
-    }
-
-    //Handling Custom Data
-    _civicrm_generic_handle_custom_data($key, $value, $values, $customFields);
-
-    if ($key == 'target_contact_id') {
-      if (!CRM_Utils_Rule::integer($value)) {
-        return civicrm_create_error("contact_id not valid: $value");
-      }
-      $contactID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contact WHERE id = $value");
-      if (!$contactID) {
-        return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = $value.");
-      }
-    }
-  }
-  return NULL;
-}
-
-/**
- *  Function to check duplicate contacts based on de-deupe parameters
- */
-function civicrm_check_contact_dedupe(&$params) {
-  static $cIndieFields = NULL;
-  static $defaultLocationId = NULL;
-
-  $contactType = $params['contact_type'];
-  if ($cIndieFields == NULL) {
-    require_once 'CRM/Contact/BAO/Contact.php';
-    $cTempIndieFields = CRM_Contact_BAO_Contact::importableFields($contactType);
-    $cIndieFields = $cTempIndieFields;
-
-    require_once "CRM/Core/BAO/LocationType.php";
-    $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
-
-    //set the value to default location id else set to 1
-    if (!$defaultLocationId = (int)$defaultLocation->id) {
-      $defaultLocationId = 1;
-    }
-  }
-
-  require_once 'CRM/Contact/BAO/Query.php';
-  $locationFields = CRM_Contact_BAO_Query::$_locationSpecificFields;
-
-  $contactFormatted = array();
-  foreach ($params as $key => $field) {
-    if ($field == NULL || $field === '') {
-      continue;
-    }
-    if (is_array($field)) {
-      foreach ($field as $value) {
-        $break = FALSE;
-        if (is_array($value)) {
-          foreach ($value as $name => $testForEmpty) {
-            if ($name !== 'phone_type' &&
-              ($testForEmpty === '' || $testForEmpty == NULL)
-            ) {
-              $break = TRUE;
-              break;
-            }
-          }
-        }
-        else {
-          $break = TRUE;
-        }
-        if (!$break) {
-          _civicrm_add_formatted_param($value, $contactFormatted);
-        }
-      }
-      continue;
-    }
-
-    $value = array($key => $field);
-
-    // check if location related field, then we need to add primary location type
-    if (in_array($key, $locationFields)) {
-      $value['location_type_id'] = $defaultLocationId;
-    }
-    elseif (array_key_exists($key, $cIndieFields)) {
-      $value['contact_type'] = $contactType;
-    }
-
-    _civicrm_add_formatted_param($value, $contactFormatted);
-  }
-
-  $contactFormatted['contact_type'] = $contactType;
-
-  return _civicrm_duplicate_formatted_contact($contactFormatted);
-}
-
-/**
- * Check permissions for a given API call.
- *
- * @param $api string    API method being called
- * @param $params array  params of the API call
- * @param $throw bool    whether to throw exception instead of returning false
- *
- * @return bool whether the current API user has the permission to make the call
- */
-function civicrm_api_check_permission($api, $params, $throw = FALSE) {
-  // return early if we’re to skip the permission check or if it’s unset
-  if (!isset($params['check_permissions']) or !$params['check_permissions']) {
-    return TRUE;
-  }
-
-  require_once 'CRM/Core/Permission.php';
-  $requirements = array(
-    'civicrm_contact_create' => array('access CiviCRM', 'add contacts'),
-    'civicrm_contact_update' => array('access CiviCRM', 'add contacts'),
-    'civicrm_event_create' => array('access CiviEvent'),
-  );
-  foreach ($requirements[$api] as $perm) {
-    if (!CRM_Core_Permission::check($perm)) {
-      if ($throw) {
-        throw new Exception("API permission check failed for $api call; missing permission: $perm.");
-      }
-      else {
-        return FALSE;
-      }
-    }
-  }
-  return TRUE;
-}
-
-
-// at some point we should unify this with
-// _civicrm_custom_format_params
-// seems like there are some differences that i dont understand, so taking the first
-// step in a cleanup: CRM-7337
-function _civicrm_generic_handle_custom_data($key, $value, &$values, &$customFields) {
-
-  //Handling Custom Data
-  if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
-    $values[$key] = $value;
-    $type = $customFields[$customFieldID]['html_type'];
-    if ($type == 'CheckBox' || $type == 'Multi-Select') {
-      $mulValues    = explode(',', $value);
-      $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
-      $values[$key] = array();
-      foreach ($mulValues as $v1) {
-        foreach ($customOption as $customValueID => $customLabel) {
-          $customValue = $customLabel['value'];
-          if ((strtolower(trim($customLabel['label'])) == strtolower(trim($v1))) ||
-            (strtolower(trim($customValue)) == strtolower(trim($v1)))
-          ) {
-            if ($type == 'CheckBox') {
-              $values[$key][$customValue] = 1;
-            }
-            else {
-              $values[$key][] = $customValue;
-            }
-          }
-        }
-      }
-    }
-    elseif ($type == 'Select' || $type == 'Radio') {
-      $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
-      foreach ($customOption as $customFldID => $customValue) {
-        $val   = CRM_Utils_Array::value('value', $customValue);
-        $label = CRM_Utils_Array::value('label', $customValue);
-        $label = strtolower($label);
-        $value = strtolower(trim($value));
-        if (($value == $label) || ($value == strtolower($val))) {
-          $values[$key] = $val;
-        }
-      }
-    }
-  }
-}
-
-function _civicrm_add_custom_formatted_param($customFieldID, $key, $field, &$formatted, $type) {
-  require_once 'CRM/Core/BAO/CustomOption.php';
-  require_once 'CRM/Core/PseudoConstant.php';
-
-  if (empty($type)) {
-    return;
-  }
-  switch ($type) {
-    case 'Text':
-      $formatted[$key] = $field;
-      break;
-
-    case 'CheckBox':
-    case 'AdvMulti-Select':
-    case 'Multi-Select':
-
-      $mulValues       = explode(',', $field);
-      $customOption    = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
-      $formatted[$key] = array();
-      foreach ($mulValues as $v1) {
-        foreach ($customOption as $v2) {
-          if ((strtolower($v2['label']) == strtolower(trim($v1))) ||
-            (strtolower($v2['value']) == strtolower(trim($v1)))
-          ) {
-            if ($type == 'CheckBox') {
-              $formatted[$key][$v2['value']] = 1;
-            }
-            else {
-              $formatted[$key][] = $v2['value'];
-            }
-          }
-        }
-      }
-      break;
-
-    case 'Select':
-    case 'Radio':
-
-      $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
-      foreach ($customOption as $v2) {
-        if ((strtolower($v2['label']) == strtolower(trim($field))) ||
-          (strtolower($v2['value']) == strtolower(trim($field)))
-        ) {
-          $formatted[$key] = $v2['value'];
-        }
-      }
-      break;
-
-    case 'Multi-Select State/Province':
-
-      $mulValues       = explode(',', $field);
-      $stateAbbr       = CRM_Core_PseudoConstant::stateProvinceAbbreviation();
-      $stateName       = CRM_Core_PseudoConstant::stateProvince();
-      $formatted[$key] = $stateValues = array();
-      foreach ($mulValues as $values) {
-        if ($val = CRM_Utils_Array::key($values, $stateAbbr)) {
-          $formatted[$key][] = $val;
-        }
-        elseif ($val = CRM_Utils_Array::key($values, $stateName)) {
-          $formatted[$key][] = $val;
-        }
-      }
-      break;
-
-    case 'Multi-Select Country':
-
-      $config          = CRM_Core_Config::singleton();
-      $limitCodes      = $config->countryLimit();
-      $mulValues       = explode(',', $field);
-      $formatted[$key] = array();
-      CRM_Core_PseudoConstant::populate($countryNames, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
-      CRM_Core_PseudoConstant::populate($countryIsoCodes, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
-      foreach ($mulValues as $values) {
-        if ($val = CRM_Utils_Array::key($values, $countryNames)) {
-          $formatted[$key][] = $val;
-        }
-        elseif ($val = CRM_Utils_Array::key($values, $countryIsoCodes)) {
-          $formatted[$key][] = $val;
-        }
-        elseif ($val = CRM_Utils_Array::key($values, $limitCodes)) {
-          $formatted[$key][] = $val;
-        }
-      }
-      break;
-  }
-}
-
-- 
GitLab