static function postProcess(&$form)
 {
     $values = $form->exportValues();
     $orgName = $values['organization_name'];
     $cSubType = CRM_Pcpteams_Constant::C_CONTACT_SUB_TYPE_TEAM;
     $params = array('version' => '1', 'contact_type' => 'Organization', 'contact_sub_type' => $cSubType, 'organization_name' => $orgName);
     $createTeam = civicrm_api3('Contact', 'create', $params);
     // Create Dummy Team PCP Page
     $teamPcpId = CRM_Pcpteams_Utils::createDefaultPcp($createTeam['id'], $form->get('component_page_id'));
     // Create/Update custom record with team pcp id and create relationship with user as Team Admin
     if ($teamPcpId) {
         $userId = CRM_Pcpteams_Utils::getloggedInUserId();
         CRM_Pcpteams_Utils::createTeamRelationship($userId, $createTeam['id'], $custom = array(), 'create');
         $params = array('version' => 3, 'entity_id' => $form->get('page_id'), "team_pcp_id" => $teamPcpId);
         $result = civicrm_api3('pcpteams', 'customcreate', $params);
         $form->set('teamName', $orgName);
         $form->set('teamContactID', $createTeam['id']);
         $form->set('teamPcpId', $teamPcpId);
         $actParams = array('target_contact_id' => $createTeam['id']);
         CRM_Pcpteams_Utils::createPcpActivity($actParams, CRM_Pcpteams_Constant::C_AT_TEAM_CREATE);
         CRM_Core_Session::setStatus(ts("Your Team %1 has been created, you can invite members from your team page.", array(1 => $orgName)), ts('New Team Created'));
     } else {
         CRM_Core_Session::setStatus(ts("Failed to Create Team \"{$orgName}\" ..."));
     }
 }
 static function postProcess(&$form)
 {
     $values = $form->exportValues();
     $teamId = $values['pcp_team_contact'];
     $teampcpId = CRM_Pcpteams_Utils::getPcpIdByContactAndEvent($form->get('component_page_id'), $teamId);
     $userId = CRM_Pcpteams_Utils::getloggedInUserId();
     // Create Team Member of relation to this Team
     $cfpcpab = CRM_Pcpteams_Utils::getPcpABCustomFieldId();
     $cfpcpba = CRM_Pcpteams_Utils::getPcpBACustomFieldId();
     $customParams = array("custom_{$cfpcpab}" => $form->get('page_id'), "custom_{$cfpcpba}" => $teampcpId);
     CRM_Pcpteams_Utils::createTeamRelationship($userId, $teamId, $customParams);
     $form->_teamName = CRM_Contact_BAO_Contact::displayName($teamId);
     $form->set('teamName', $form->_teamName);
     $form->set('teamContactID', $teamId);
     $form->set('teamPcpId', $teampcpId);
     $teamAdminId = CRM_Pcpteams_Utils::getTeamAdmin($teampcpId);
     // Team Join: create activity
     $actParams = array('target_contact_id' => $teamId, 'assignee_contact_id' => $teamAdminId);
     CRM_Pcpteams_Utils::createPcpActivity($actParams, CRM_Pcpteams_Constant::C_AT_REQ_MADE);
     CRM_Core_Session::setStatus(ts('A notification has been sent to the team. Once approved, team should be visible on your page.'), ts('Team Request Sent'));
     //send email once the team request has done.
     list($teamAdminName, $teamAdminEmail) = CRM_Contact_BAO_Contact::getContactDetails($teamAdminId);
     $contactDetails = civicrm_api('Contact', 'get', array('version' => 3, 'sequential' => 1, 'id' => $userId));
     $emailParams = array('tplParams' => array('teamAdminName' => $teamAdminName, 'userFirstName' => $contactDetails['values'][0]['first_name'], 'userlastName' => $contactDetails['values'][0]['last_name'], 'teamName' => $form->_teamName, 'pageURL' => CRM_Utils_System::url('civicrm/pcp/manage', "reset=1&id={$teampcpId}", TRUE, NULL, FALSE, TRUE)), 'email' => array($teamAdminName => array('first_name' => $teamAdminName, 'last_name' => $teamAdminName, 'email-Primary' => $teamAdminEmail, 'display_name' => $teamAdminName)), 'valueName' => CRM_Pcpteams_Constant::C_MSG_TPL_JOIN_REQUEST);
     $sendEmail = CRM_Pcpteams_Utils::sendMail($userId, $emailParams);
 }
 function buildQuickForm()
 {
     $eventDetails = CRM_Pcpteams_Utils::getEventDetailsbyEventId($this->controller->get('component_page_id'));
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Yes I do'), 'isDefault' => TRUE)));
     // export form elements
     $this->assign('eventDetails', $eventDetails);
     $this->assign('elementNames', $this->getRenderableElementNames());
     parent::buildQuickForm();
 }
 function postProcess()
 {
     $values = $this->exportValues();
     $branchId = $values['pcp_branch_contact'];
     if ($branchId && $this->get('page_id')) {
         // $branchCfId = CRM_Pcpteams_Utils::getBranchorPartnerCustomFieldId();
         $params = array('version' => 3, 'entity_id' => $this->get('page_id'), "org_id" => $branchId);
         $result = civicrm_api3('pcpteams', 'customcreate', $params);
         if (!civicrm_error($result)) {
             $branchName = CRM_Contact_BAO_Contact::displayName($branchId);
             // Group Join: create activity
             $actParams = array('target_contact_id' => $branchId);
             CRM_Pcpteams_Utils::createPcpActivity($actParams, CRM_Pcpteams_Constant::C_AT_GROUP_JOIN);
             CRM_Core_Session::setStatus(ts("Successfully added to the branch {$branchName}"), '', 'success');
         }
     }
 }
 function postProcess()
 {
     $values = $this->exportValues();
     $tributeId = $values['pcp_tribute_contact'];
     if ($tributeId && $this->_tributeReason) {
         // $tributeCfId        = CRM_Pcpteams_Utils::getPcpTypeCustomFieldId();
         // $tributeContactCfId = CRM_Pcpteams_Utils::getPcpTypeContactCustomFieldId();
         $selectedReason = CRM_Core_OptionGroup::getValue(CRM_Pcpteams_Constant::C_PCP_TYPE, $this->_tributeReason, 'name');
         $tributeContatparams = array('version' => 3, 'entity_id' => $this->get('page_id'), "tribute" => $selectedReason, "tribute_contact_id" => $tributeId);
         $result = civicrm_api3('pcpteams', 'customcreate', $tributeContatparams);
         if (!civicrm_error($result)) {
             $tributeName = CRM_Contact_BAO_Contact::displayName($tributeId);
             // Tribute Join: create activity
             $actParams = array('target_contact_id' => $tributeId, 'reason' => $this->_tributeReason);
             CRM_Pcpteams_Utils::createPcpActivity($actParams, CRM_Pcpteams_Constant::C_AT_TRIBUTE_JOIN);
             CRM_Core_Session::setStatus(ts("Successfully added to {$this->_tributeReason} of {$tributeName}"), '', 'success');
         }
     }
     //FIXME: need to discuss with DS, to redirect the after completed the form entries
     CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/pcp/page', 'reset=1&id=' . $this->get('page_id')));
 }
 function preProcess()
 {
     CRM_Core_Resources::singleton()->addScriptFile('uk.co.vedaconsulting.pcpteams', 'packages/jquery-circle-progress/dist/circle-progress.js', CRM_Core_Resources::DEFAULT_WEIGHT, 'html-header')->addStyleFile('uk.co.vedaconsulting.pcpteams', 'css/manage.css');
     $session = CRM_Core_Session::singleton();
     $this->_userID = $session->get('userID');
     if (!$this->_userID) {
         CRM_Core_Error::fatal(ts('You must be logged in to view this page.'));
     } else {
         $pcpId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullArray, TRUE);
         if (!CRM_Pcpteams_Utils::hasPermission($pcpId, $this->_userID, CRM_Core_Permission::VIEW)) {
             CRM_Core_Error::fatal(ts('You do not have permission to view this Page.'));
         }
     }
     //set user can edit or view page.
     $isEdit = CRM_Pcpteams_Utils::hasPermission($pcpId, $this->_userID, CRM_Core_Permission::EDIT);
     $isMember = CRM_Pcpteams_Utils::hasPermission($pcpId, $this->_userID, CRM_Pcpteams_Constant::C_PERMISSION_MEMBER);
     $this->assign("is_edit_page", $isEdit);
     $this->_isEditPermission = $isEdit;
     $this->assign("is_member", $isMember);
     $this->assign('userId', $this->_userID);
 }
 function preProcess()
 {
     parent::preProcess();
     $workflowTeam = CRM_Utils_Request::retrieve('op', 'String');
     $page_id = CRM_Utils_Request::retrieve('id', 'Positive');
     $component_page_id = CRM_Utils_Request::retrieve('pageId', 'Positive');
     $snippet = CRM_Utils_Request::retrieve('snippet', 'String');
     $this->set('component_page_id', $component_page_id);
     $this->set('page_id', $page_id);
     if ($workflowTeam) {
         $this->_reactToFile = $this->getTeamReactFile($workflowTeam);
     }
     if ($workflowTeam == 'invite') {
         $this->_contactID = CRM_Pcpteams_Utils::getloggedInUserId();
         //team contactName
         $teamContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $page_id, 'contact_id');
         $teamName = CRM_Contact_BAO_Contact::displayName($teamContactId);
         $this->set('teamName', $teamName);
     }
     $className = 'CRM_Pcpteams_Form_' . $this->_reactToFile;
     $className::preProcess($this);
     $this->assign('reactClass', $this->_reactToFile);
     $this->assign('snippet', $snippet);
 }
function civicrm_api3_pcpteams_customcreate($params)
{
    $customParams = array();
    $isEditPermission = CRM_Pcpteams_Utils::hasPermission($params['entity_id'], NULL, CRM_Core_Permission::EDIT);
    foreach ($params as $key => $value) {
        if ($key && !in_array($key, array('entity_id', 'version'))) {
            $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $key, 'id', 'column_name');
            if (!$customFieldId) {
                continue;
            }
            if ($key == 'team_pcp_id') {
                if ($value) {
                    // we don't want pcp-owners to control / update setting of team_pcp_id.
                    // Lets make sure its the admin who is doing it by checking if logged in user has edit permission on team_pcp_id ($value here)
                    if (!CRM_Pcpteams_Utils::hasPermission($value, NULL, CRM_Core_Permission::EDIT)) {
                        continue;
                    }
                } else {
                    if (!(CRM_Pcpteams_Utils::hasPermission($params['entity_id'], NULL, CRM_Pcpteams_Constant::C_PERMISSION_TEAM_ADMIN) || $isEditPermission)) {
                        // this is the case when somebody is setting team_pcp_id to NULL
                        // if the logged in user is (A) admin for pcp ($params['entity_id']) being updated OR (B) owner of pcp being updated,
                        // we allow it to unset
                        continue;
                    }
                }
            } else {
                if (!$isEditPermission) {
                    continue;
                }
            }
            $customParams["custom_{$customFieldId}"] = $value;
        }
    }
    if (empty($customParams)) {
        return civicrm_api3_create_error('insufficient permission to edit this record');
    }
    $customParams['version'] = 3;
    $customParams['entity_id'] = $params['entity_id'];
    return civicrm_api3('CustomValue', 'create', $customParams);
}
function pcpteams_civicrm_custom($op, $groupID, $entityID, &$params)
{
    if ($op != 'create' && $op != 'edit') {
        return;
    }
    $customFields = array();
    if ($groupID == CRM_Pcpteams_Utils::getPcpCustomSetId()) {
        foreach ($params as $key => $value) {
            $customFields[$value['column_name']] = $value['value'];
        }
        $teamContactId = CRM_Pcpteams_Utils::getcontactIdbyPcpId($entityID);
        if ('Team' == CRM_Pcpteams_Utils::checkPcpType($entityID)) {
            $cfpcpab = CRM_Pcpteams_Utils::getPcpABCustomFieldId();
            $customParams = array("custom_{$cfpcpab}" => $entityID);
            CRM_Pcpteams_Utils::reCreateRelationship($teamContactId, $customFields['org_id'], CRM_Pcpteams_Constant::C_CORPORATE_REL_TYPE, $customParams);
        }
    }
}
 static function deleteTeamPcp()
 {
     $pcp_id = CRM_Utils_Request::retrieve('pcp_id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
     $team_pcp_id = CRM_Utils_Request::retrieve('team_pcp_id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE);
     $contactId = CRM_Pcpteams_Utils::getcontactIdbyPcpId($pcp_id);
     $teamContactId = CRM_Pcpteams_Utils::getcontactIdbyPcpId($team_pcp_id);
     $relTypeAdmin = CRM_Pcpteams_Constant::C_TEAM_ADMIN_REL_TYPE;
     $adminRelTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $relTypeAdmin, 'id', 'name_a_b');
     $relationshipQuery = "SELECT id FROM civicrm_relationship where contact_id_a = %1 AND contact_id_b = %2 AND relationship_type_id = %3";
     $queryParams = array(1 => array($contactId, 'Integer'), 2 => array($teamContactId, 'Integer'), 3 => array($adminRelTypeId, 'Integer'));
     $relationship = CRM_Core_DAO::singleValueQuery($relationshipQuery, $queryParams);
     if (!empty($relationship)) {
         $params = array('version' => 3, 'id' => $team_pcp_id);
         $result = civicrm_api('pcpteams', 'delete', $params);
         echo 'Deleted';
     } else {
         echo 'Sorry!! You are not team Admin';
     }
     CRM_Utils_System::civiExit();
 }
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $id = CRM_PCP_BAO_PCP::getSupporterProfileId($this->_pageId, $this->_component);
     if (CRM_PCP_BAO_PCP::checkEmailProfile($id)) {
         $this->assign('profileDisplay', TRUE);
     }
     $fields = NULL;
     if ($this->_contactID) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $this->_contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
         }
         $this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
     } else {
         CRM_Core_BAO_CMSUser::buildForm($this, $id, TRUE);
         // Override LoginUrl
         CRM_Pcpteams_Utils::overrideLoginUrl($this);
         $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
     }
     if ($fields) {
         $this->assign('fields', $fields);
         $addCaptcha = FALSE;
         foreach ($fields as $key => $field) {
             if (isset($field['data_type']) && $field['data_type'] == 'File') {
                 // ignore file upload fields
                 continue;
             }
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $this->_fields[$key] = $field;
             // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
             if ($field['add_captcha'] && !$this->_contactID) {
                 $addCaptcha = TRUE;
             }
         }
         if ($addCaptcha) {
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign('isCaptcha', TRUE);
         }
     }
     if ($this->_component == 'contribute') {
         $this->assign('campaignName', CRM_Contribute_PseudoConstant::contributionPage($this->_pageId));
     } elseif ($this->_component == 'event') {
         $this->assign('campaignName', CRM_Event_PseudoConstant::event($this->_pageId));
     }
     if ($this->_single) {
         $button = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '         ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     } else {
         $button[] = array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '         ', 'isDefault' => TRUE);
     }
     $this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
     $this->addButtons($button);
 }
 static function reCreateRelationship($iContactIdA, $iContactIdB, $relationshipTypeName, $custom = array())
 {
     // Delete any old relationship on changing
     $query = "\n      DELETE cr FROM civicrm_relationship cr\n      INNER JOIN civicrm_relationship_type crt ON crt.id = cr.relationship_type_id";
     $where = " WHERE crt.name_a_b = %1 AND cr.contact_id_a = %2";
     $cfpcpab = CRM_Pcpteams_Utils::getPcpABCustomFieldId();
     if (CRM_Utils_Array::value('custom_' . $cfpcpab, $custom)) {
         $query .= " INNER JOIN civicrm_value_pcp_relationship_set crs ON crs.entity_id = cr.id";
         $where .= " AND crs.pcp_a_b = %3";
     }
     $sql = $query . $where;
     $queryParams = array(1 => array(CRM_Pcpteams_Constant::C_CORPORATE_REL_TYPE, 'String'), 2 => array($iContactIdA, 'Int'), 3 => array($custom['custom_' . $cfpcpab], 'Int'));
     CRM_Core_DAO::executeQuery($sql, $queryParams);
     // Create New Relationship against Team and Coporate
     self::createRelationship($iContactIdA, $iContactIdB, $relationshipTypeName, $custom);
 }
 /**
  * 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);
 }
 function postProcess()
 {
     //return TRUE;
     $values = $this->controller->exportValues($this->_name);
     // Find the msg_tpl ID of sample invite template
     $teampcpId = CRM_Pcpteams_Utils::getPcpIdByContactAndEvent($this->get('component_page_id'), $this->get('teamContactID'));
     //FIXME : Find the solution to check is empty array of invitees
     $isInviteeEmailFound = FALSE;
     foreach ($values['friend'] as $key => $value) {
         if ($value['email']) {
             $isInviteeEmailFound = TRUE;
         }
     }
     if ($isInviteeEmailFound) {
         // Send Invitation emails
         $pcpDetails = civicrm_api('pcpteams', 'get', array('version' => 3, 'sequential' => 1, 'pcp_id' => $this->get('page_id')));
         list($userName, $userEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_contactID);
         $values['tplParams'] = array('eventName' => $pcpDetails['values'][0]['page_title'], 'userName' => $userName, 'teamName' => $this->get('teamName'), 'pageURL' => CRM_Utils_System::url('civicrm/pcp/support', "reset=1&pageId={$this->get('component_page_id')}&component=event&tpId={$this->_invitedTeamPcpID}", TRUE, NULL, FALSE, TRUE));
         // As team contact id is set in the team join post process, team contact id is not available in this form if you are coming from manage page
         $teamContactId = $this->get('teamContactID');
         if (empty($teamContactId)) {
             $teamContactId = $pcpDetails['values'][0]['contact_id'];
         }
         // Create Team Invite activity
         $actParams = array('assignee_contact_id' => $teamContactId);
         $checkAdminParams = array('version' => 3, 'user_id' => $this->_contactID, 'team_contact_id' => $teamContactId);
         $chkTeamAdmin = civicrm_api('Pcpteams', 'checkTeamAdmin', $checkAdminParams);
         $isTeamAdmin = $chkTeamAdmin['is_team_admin'];
         $teamInviteActivityType = $isTeamAdmin ? CRM_Pcpteams_Constant::C_AT_INVITATION_FROM_ADMIN : CRM_Pcpteams_Constant::C_AT_INVITATION_FROM_MEMBER;
         $activity = CRM_Pcpteams_Utils::createPcpActivity($actParams, $teamInviteActivityType);
         $result = CRM_Pcpteams_Utils::sendInviteEmail(CRM_Pcpteams_Constant::C_MSG_TPL_INVITE_TEAM, $this->_contactID, $values, $teampcpId, $activity['id']);
         if ($result) {
             if ($_GET['snippet']) {
                 // from pcp edit screen
                 CRM_Core_Session::setStatus(ts('Invitation request(s) has been sent'), ts('Invite Team'));
             } else {
                 // from workflow (create team)
                 CRM_Core_Session::setStatus(ts('Your team has been created. We have emailed your team mates asking them to join you. You will receive and email when each of them accepts your invite Invitation request(s) has been sent'), ts('Team Join Request(s) Sent'));
             }
         } else {
             if ($_GET['snippet']) {
                 CRM_Core_Session::setStatus(ts('No invitation request was sent.'), ts('No Invites'));
             } else {
                 // from workflow (create team)
                 CRM_Core_Session::setStatus(ts('Your team has been created. You can invite members from your team page.'), ts('Invite Members From Your Team Page'));
             }
         }
     }
 }