Ejemplo n.º 1
0
 function create($contributionPageId)
 {
     $profileParams = array('group_type' => 'Individual,Contact', 'title' => 'Test Supprorter Profile', 'help_pre' => 'Profle to PCP Contribution', 'is_active' => 1, 'is_cms_user' => 2);
     $ufGroup = civicrm_uf_group_create($profileParams);
     $profileId = $ufGroup['id'];
     $fieldsParams = array(array('field_name' => 'first_name', 'field_type' => 'Individual', 'visibility' => 'Public Pages and Listings', 'weight' => 1, 'label' => 'First Name', 'is_required' => 1, 'is_active' => 1), array('field_name' => 'last_name', 'field_type' => 'Individual', 'visibility' => 'Public Pages and Listings', 'weight' => 2, 'label' => 'Last Name', 'is_required' => 1, 'is_active' => 1), array('field_name' => 'email', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', 'weight' => 3, 'label' => 'Email', 'is_required' => 1, 'is_active' => 1));
     foreach ($fieldsParams as $value) {
         $ufField = civicrm_uf_field_create($profileId, $value);
     }
     $joinParams = array('module' => 'Profile', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => 1, 'weight' => 1, 'uf_group_id' => $profileId, 'is_active' => 1);
     require_once 'api/v2/UFJoin.php';
     $ufJoin = civicrm_uf_join_add($joinParams);
     $params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $contributionPageId, 'supporter_profile_id' => $profileId, 'is_approval_needed' => 0, 'is_tellfriend_enabled' => 0, 'tellfriend_limit' => 0, 'link_text' => 'Create your own Personal Campaign Page!', 'is_active' => 1, 'notify_email' => '*****@*****.**');
     require_once 'CRM/Contribute/BAO/PCP.php';
     $blockPCP = CRM_Contribute_BAO_PCP::add($params);
     return array('blockId' => $blockPCP->id, 'profileId' => $profileId);
 }
Ejemplo n.º 2
0
/**
 * create / update a PCP entry
 *
 * @param  array   $params           (reference ) input parameters - need id and contribution_type_id
 *
 * @return array (reference )        PCP / PCPBlock result
 * @static void
 * @access public
 */
function &civicrm_pcp_create( &$params ) {
    _civicrm_initialize( );
	
    $values  = array( );
   
    require_once 'CRM/Contribute/BAO/PCP.php';

    $pcpBlock = CRM_Utils_Array::value( 'pcpBlock', $params, TRUE );
	// true creates/updates a pcpBlock, false creates/updates a users pcp
	$pcp = CRM_Contribute_BAO_PCP::add( $params, $pcpBlock );	
	
    if ( is_a( $pcp, 'CRM_Core_Error' ) ) {
        return civicrm_create_error( ts( 'Failed to create pcp' ) );
    }

    _civicrm_object_to_array($pcp, $pcpArray);
    
    return $pcpArray;
}
Ejemplo n.º 3
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $params['entity_id'] = $this->_id;
     $params['entity_table'] = 'civicrm_contribution_page';
     $dao =& new CRM_Contribute_DAO_PCPBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->find(true);
     $params['id'] = $dao->id;
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     $params['is_approval_needed'] = CRM_Utils_Array::value('is_approval_needed', $params, false);
     $params['is_tellfriend_enabled'] = CRM_Utils_Array::value('is_tellfriend_enabled', $params, false);
     require_once 'CRM/Contribute/BAO/PCP.php';
     $dao = CRM_Contribute_BAO_PCP::add($params);
 }
Ejemplo n.º 4
0
 /** 
  * Function to process the form 
  * 
  * @access public 
  * @return None 
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues();
     $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active');
     foreach ($checkBoxes as $key) {
         if (!isset($params[$key])) {
             $params[$key] = 0;
         }
     }
     $session =& CRM_Core_Session::singleton();
     $contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID');
     if (!$contactID) {
         $contactID = $this->get('contactID');
     }
     $params['contact_id'] = $contactID;
     $params['contribution_page_id'] = $this->get('contribution_page_id') ? $this->get('contribution_page_id') : $this->_contriPageId;
     $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
     $approval_needed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCPBlock', $params['contribution_page_id'], 'is_approval_needed', 'entity_id');
     $approvalMessage = null;
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $params['status_id'] = $approval_needed ? 1 : 2;
         $approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin your fundraising efforts. You will receive an email confirmation shortly which includes a link to return to your fundraising page.') : ts('and is ready to use.');
     }
     $params['id'] = $this->_pageId;
     require_once 'CRM/Contribute/BAO/PCP.php';
     $pcp = CRM_Contribute_BAO_PCP::add($params, false);
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_pcp', $pcp->id);
     $pageStatus = isset($this->_pageId) ? ts('updated') : ts('created');
     $statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $pcp->id, 'status_id');
     //send notification of PCP create/update.
     $pcpParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $pcp->contribution_page_id);
     $notifyParams = array();
     $notifyStatus = "";
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
     if ($emails = CRM_Utils_Array::value('notify_email', $notifyParams)) {
         $this->assign('pcpTitle', $pcp->title);
         if ($this->_pageId) {
             $this->assign('mode', 'Update');
         } else {
             $this->assign('mode', 'Add');
         }
         require_once 'CRM/Core/OptionGroup.php';
         $pcpStatus = CRM_Core_OptionGroup::getLabel('pcp_status', $statusId);
         $this->assign('pcpStatus', $pcpStatus);
         $this->assign('pcpId', $pcp->id);
         $supporterUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid={$pcp->contact_id}", true, null, true, true);
         $this->assign('supporterUrl', $supporterUrl);
         $supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name');
         $this->assign('supporterName', $supporterName);
         $contribPageUrl = CRM_Utils_System::url("civicrm/contribute/transact", "reset=1&id={$pcp->contribution_page_id}", true, null, true, true);
         $this->assign('contribPageUrl', $contribPageUrl);
         $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcp->contribution_page_id, 'title');
         $this->assign('contribPageTitle', $contribPageTitle);
         $managePCPUrl = CRM_Utils_System::url("civicrm/admin/pcp", "reset=1", true, null, true, true);
         $this->assign('managePCPUrl', $managePCPUrl);
         //get the default domain email address.
         require_once 'CRM/Core/BAO/Domain.php';
         list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
         if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
             CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in Administer CiviCRM » Configure » Domain Information. The email address used may need to be a valid mail account with your email service provider.'));
         }
         //if more than one email present for PCP notification ,
         //first email take it as To and other as CC and First email
         //address should be sent in users email receipt for
         //support purpose.
         $emailArray = explode(',', $emails);
         $to = $emailArray[0];
         unset($emailArray[0]);
         $cc = implode(',', $emailArray);
         require_once 'CRM/Core/BAO/MessageTemplates.php';
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_notify', 'contactId' => $contactID, 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $to, 'cc' => $cc));
         if ($sent) {
             $notifyStatus = ts('A notification email has been sent to the site administrator.');
         }
     }
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_pcp', $pcp->id);
     // send email notification to supporter, if initial setup / add mode.
     if (!$this->_pageId) {
         CRM_Contribute_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, true);
         if ($approvalMessage && CRM_Utils_Array::value('status_id', $params) == 1) {
             $notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.');
         }
     }
     //check if pcp created by anonymous user
     $anonymousPCP = 0;
     if (!$session->get('userID')) {
         $anonymousPCP = 1;
     }
     CRM_Core_Session::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3", array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus)));
     if (!$this->_pageId) {
         $session->pushUserContext(CRM_Utils_System::url('civicrm/contribute/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}"));
     }
 }