function pcpteams_civicrm_post($op, $objectName, $objectId, &$objectRef)
{
    if ($objectName == 'ContributionSoft' && $op == 'create' && $objectRef->pcp_id) {
        // switch to event's campaign id where the pcp is related to while contribution is created where contribution has contribution page's campaign id
        $updateQuery = "\n      UPDATE civicrm_contribution cc\n      INNER JOIN civicrm_contribution_soft cs ON cs.contribution_id = cc.id\n      INNER JOIN civicrm_pcp cp ON cp.id = cs.pcp_id\n      INNER JOIN civicrm_event ce ON ce.id = cp.page_id\n      SET cc.campaign_id = ce.campaign_id, cc.source = %3\n      WHERE cp.page_type = %1 AND cs.id = %2 ";
        $queryParams = array(1 => array('event', 'String'), 2 => array($objectId, 'Int'), 3 => array('PCP', 'String'));
        CRM_Core_DAO::executeQuery($updateQuery, $queryParams);
        $query = "SELECT pcp.contact_id, cs.tribute_contact_id, cs.org_id \n      FROM civicrm_value_pcp_custom_set cs\n      INNER JOIN civicrm_pcp pcp ON cs.team_pcp_id = pcp.id \n      WHERE cs.entity_id = %1";
        $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($objectRef->pcp_id, 'Integer')));
        $dao->fetch();
        if ($dao->contact_id) {
            $newSoft = clone $objectRef;
            $newSoft->contact_id = $dao->contact_id;
            // $newSoft->pcp_personal_note = "Created From Hook";
            unset($newSoft->id);
            $newSoft->save();
        }
        if ($dao->tribute_contact_id) {
            $newSoft = clone $objectRef;
            $newSoft->contact_id = $dao->tribute_contact_id;
            // $newSoft->pcp_personal_note = "Created From Hook";
            unset($newSoft->id);
            $newSoft->save();
        }
        if ($dao->org_id) {
            $newSoft = clone $objectRef;
            $newSoft->contact_id = $dao->org_id;
            // $newSoft->pcp_personal_note = "Created From Hook";
            unset($newSoft->id);
            $newSoft->save();
        }
    }
    if ($op == 'create' && $objectName == 'Participant') {
        $pcpBlockId = CRM_Pcpteams_Utils::getPcpBlockId($objectRef->event_id);
        if ($pcpBlockId) {
            // Auto create default PCP
            CRM_Pcpteams_Utils::getPcpId($objectRef->event_id, 'event', TRUE, $objectRef->contact_id);
        }
    }
    if ($objectName == 'PCP' && $op == 'edit') {
        CRM_Pcpteams_Utils::adjustTeamTarget($objectId);
    }
}
 /**
  * class constructor
  *
  * @param object $controller
  * @param \const|int $action
  *
  * @internal param \CRM_Contact_Import_Controller $object
  * @return \CRM_PCP_StateMachine_PCP CRM_Contact_Import_StateMachine
  */
 function __construct($controller, $action = CRM_Core_Action::NONE)
 {
     parent::__construct($controller, $action);
     $session = CRM_Core_Session::singleton();
     $session->set('singleForm', FALSE);
     $pages = array('cpfeq' => 'CRM_Pcpteams_Form_EventQuery', 'cpfer' => 'CRM_Pcpteams_Form_EventReact', 'cpfec' => 'CRM_Pcpteams_Form_EventConfirm', 'cpfere' => 'CRM_Pcpteams_Form_EventRegister', 'cpftq' => 'CRM_Pcpteams_Form_TeamQuery', 'cpftn' => 'CRM_Pcpteams_Form_TeamReact', 'cpftc' => 'CRM_Pcpteams_Form_TeamConfirm', 'cpftt' => 'CRM_Pcpteams_Form_TeamThankYou', 'cpfgq' => 'CRM_Pcpteams_Form_GroupQuery', 'cpfgj' => 'CRM_Pcpteams_Form_GroupJoin', 'cpftrq' => 'CRM_Pcpteams_Form_TributeQuery', 'cpftrj' => 'CRM_Pcpteams_Form_TributeJoin');
     $step = CRM_Utils_Request::retrieve('code', 'String', $controller);
     $pcpId = CRM_Utils_Request::retrieve('id', 'Positive', $controller);
     $pageId = CRM_Utils_Request::retrieve('pageId', 'Positive', $controller);
     $component = CRM_Utils_Request::retrieve('component', 'String', $controller);
     $teamPcpId = CRM_Utils_Request::retrieve('tpId', 'Positive', $controller);
     $workflowTeam = $controller->get('workflowTeam');
     // DS: for now we skipping branch and tribute screens. We might enable them back later.
     $controller->set('workflowGroup', 'skip');
     // remove me later
     $controller->set('workflowTribute', 'skip');
     // remove me later
     $workflowGroup = $controller->get('workflowGroup');
     $workflowTribute = $controller->get('workflowTribute');
     // check if contact is already registered
     // get pcp id
     if ('event' == $controller->get('component') && $pageId) {
         $eventId = $pageId;
         if (is_null($controller->get('participantId'))) {
             $participantId = CRM_Pcpteams_Utils::isaParticipantFor($eventId);
             // store in session so we not checking everytime
             $controller->set('participantId', $participantId);
         }
         if (!$pcpId) {
             $pcpId = CRM_Pcpteams_Utils::getPcpId($pageId, $component, TRUE);
             $controller->set('id', $pcpId);
             // in PCPAccount.php this gets retrieved & set as page_id
             $controller->set('page_id', $pcpId);
             // set it anyway
         }
     }
     // if team pages need skipping
     // FIXME: we 'll need to keep pcp info laoded ad stored in static cache?
     // so we not making this check everytime
     if ($controller->get('page_id') && (empty($workflowTeam) || empty($workflowGroup) || empty($workflowTribute) || $teamPcpId)) {
         $result = civicrm_api('Pcpteams', 'get', array('version' => 3, 'sequential' => 1, 'pcp_id' => $controller->get('page_id')));
         if (empty($workflowTeam) || $teamPcpId) {
             // $cfid = CRM_Pcpteams_Utils::getTeamPcpCustomFieldId();
             if (!empty($result['values'][0]["team_pcp_id"])) {
                 $controller->set('workflowTeam', 'skip');
             }
         }
         if (empty($workflowGroup)) {
             // $cfid = CRM_Pcpteams_Utils::getBranchorPartnerCustomFieldId();
             if (!empty($result['values'][0]["org_id"])) {
                 $controller->set('workflowGroup', 'skip');
             }
         }
         if (empty($workflowTribute)) {
             // $cfid = CRM_Pcpteams_Utils::getPcpTypeContactCustomFieldId();
             if (!empty($result['values'][0]["tribute_contact_id"])) {
                 $controller->set('workflowTribute', 'skip');
             }
         }
     }
     // if need jumping to invite page
     if (!$workflowTeam) {
         if (empty($teamPcpId)) {
             $teamPcpId = CRM_Core_Session::singleton()->get('pcpteams_tpid');
         }
         if ($teamPcpId) {
             $controller->set('tpId', $teamPcpId);
             $controller->set('workflowTeam', 'invite');
         }
     }
     // unset pages per workflow
     if (in_array($controller->get('workflowTeam'), array('invite', 2))) {
         // team invite or join
         unset($pages['cpftc'], $pages['cpftt']);
     }
     if ('skip' == $controller->get('workflowTeam')) {
         // unset all team pages
         unset($pages['cpftq'], $pages['cpftn'], $pages['cpftc'], $pages['cpftt']);
     }
     if ('skip' == $controller->get('workflowGroup')) {
         // unset all group pages
         unset($pages['cpfgq'], $pages['cpfgj']);
     }
     if ('skip' == $controller->get('workflowTribute')) {
         // unset all group pages
         unset($pages['cpftrq'], $pages['cpftrj']);
     }
     // if no event or already registered, skip event pages
     if (!$eventId || $controller->get('participantId')) {
         unset($pages['cpfec'], $pages['cpfere']);
     }
     if ('cpfeq' != $step) {
         unset($pages['cpfeq'], $pages['cpfer']);
     }
     if (!$step) {
         // if no code, set it true, so we consider all pages
         $stepFound = true;
     } else {
         // otherwise set it to false, we consider all pages starting from the code
         $stepFound = false;
         // DS: we now using drupal's account page
         //if (!$session->get('userID')) {
         // if user not logged in, inject the account page anyway
         //$this->_pages[$pages['cpfpa']] = NULL;
         //}
     }
     foreach ($pages as $pCode => $page) {
         if ($pCode == $step) {
             $stepFound = true;
         }
         if ($stepFound) {
             $this->_pages[$page] = NULL;
         }
     }
     if (empty($this->_pages)) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/pcp/manage', 'id=' . $controller->get('page_id')));
     }
     $this->addSequentialPages($this->_pages, $action);
 }