First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,374 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for processing a pcp page.
*/
class CRM_PCP_Form_Campaign extends CRM_Core_Form {
public $_context;
public $_component;
/**
* Pre-process form.
*/
public function preProcess() {
// we do not want to display recently viewed items, so turn off
$this->assign('displayRecent', FALSE);
// component null in controller object - fix? dgg
// $this->_component = $this->controller->get('component');
$this->_component = CRM_Utils_Request::retrieve('component', 'String', $this);
$this->assign('component', $this->_component);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
$this->assign('context', $this->_context);
$this->_pageId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
$title = ts('Setup a Personal Campaign Page - Step 2');
if ($this->_pageId) {
$title = ts('Edit Your Personal Campaign Page');
}
CRM_Utils_System::setTitle($title);
parent::preProcess();
}
/**
* Set default form values.
*
* @return array
* Default values for the form.
*/
public function setDefaultValues() {
$defaults = array();
$dao = new CRM_PCP_DAO_PCP();
if ($this->_pageId) {
$dao->id = $this->_pageId;
if ($dao->find(TRUE)) {
CRM_Core_DAO::storeValues($dao, $defaults);
}
// fix the display of the monetary value, CRM-4038
if (isset($defaults['goal_amount'])) {
$defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], NULL, '%a');
}
$defaults['pcp_title'] = CRM_Utils_Array::value('title', $defaults);
$defaults['pcp_intro_text'] = CRM_Utils_Array::value('intro_text', $defaults);
}
if ($this->get('action') & CRM_Core_Action::ADD) {
$defaults['is_active'] = 1;
$defaults['is_honor_roll'] = 1;
$defaults['is_thermometer'] = 1;
$defaults['is_notify'] = 1;
}
$this->_contactID = CRM_Utils_Array::value('contact_id', $defaults);
$this->_contriPageId = CRM_Utils_Array::value('page_id', $defaults);
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->add('text', 'pcp_title', ts('Title'), NULL, TRUE);
$this->add('textarea', 'pcp_intro_text', ts('Welcome'), NULL, TRUE);
$this->add('text', 'goal_amount', ts('Your Goal'), NULL, TRUE);
$this->addRule('goal_amount', ts('Goal Amount should be a numeric value'), 'money');
$attributes = array();
if ($this->_component == 'event') {
if ($this->get('action') & CRM_Core_Action::ADD) {
$attributes = array('value' => ts('Join Us'), 'onClick' => 'select();');
}
$this->add('text', 'donate_link_text', ts('Sign up Button'), $attributes);
}
else {
if ($this->get('action') & CRM_Core_Action::ADD) {
$attributes = array('value' => ts('Donate Now'), 'onClick' => 'select();');
}
$this->add('text', 'donate_link_text', ts('Donation Button'), $attributes);
}
$attrib = array('rows' => 8, 'cols' => 60);
$this->add('textarea', 'page_text', ts('Your Message'), NULL, FALSE);
$maxAttachments = 1;
CRM_Core_BAO_File::buildAttachment($this, 'civicrm_pcp', $this->_pageId, $maxAttachments);
$this->addElement('checkbox', 'is_thermometer', ts('Progress Bar'));
$this->addElement('checkbox', 'is_honor_roll', ts('Honor Roll'), NULL);
if ($this->_pageId) {
$params = array('id' => $this->_pageId);
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
$owner_notification_option = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id');
}
else {
$owner_notification_option = CRM_PCP_BAO_PCP::getOwnerNotificationId($this->controller->get('component_page_id'), $this->_component ? $this->_component : 'contribute');
}
if ($owner_notification_option == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name')) {
$this->assign('owner_notification_option', TRUE);
$this->addElement('checkbox', 'is_notify', ts('Notify me via email when someone donates to my page'), NULL);
}
$this->addElement('checkbox', 'is_active', ts('Active'));
if ($this->_context == 'dashboard') {
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1'));
}
$this->addButtons(
array(
array(
'type' => 'upload',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
$this->addFormRule(array('CRM_PCP_Form_Campaign', 'formRule'), $this);
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param $self
*
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
$errors = array();
if ($fields['goal_amount'] <= 0) {
$errors['goal_amount'] = ts('Goal Amount should be a numeric value greater than zero.');
}
if (strlen($fields['donate_link_text']) >= 64) {
$errors['donate_link_text'] = ts('Button Text must be less than 64 characters.');
}
return $errors;
}
/**
* Process the form submission.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
$checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active', 'is_notify');
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['title'] = $params['pcp_title'];
$params['intro_text'] = $params['pcp_intro_text'];
$params['contact_id'] = $contactID;
$params['page_id'] = $this->get('component_page_id') ? $this->get('component_page_id') : $this->_contriPageId;
$params['page_type'] = $this->_component;
// since we are allowing html input from the user
// we also need to purify it, so lets clean it up
$htmlFields = array('intro_text', 'page_text', 'title');
foreach ($htmlFields as $field) {
if (!empty($params[$field])) {
$params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
}
}
$entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
$pcpBlock = new CRM_PCP_DAO_PCPBlock();
$pcpBlock->entity_table = $entity_table;
$pcpBlock->entity_id = $params['page_id'];
$pcpBlock->find(TRUE);
$params['pcp_block_id'] = $pcpBlock->id;
$params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
$approval_needed = $pcpBlock->is_approval_needed;
$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 promoting your campaign. You will receive an email confirmation shortly which includes a link to return to this page.') : ts('and is ready to use.');
}
$params['id'] = $this->_pageId;
$pcp = CRM_PCP_BAO_PCP::create($params);
// 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_PCP_DAO_PCP', $pcp->id, 'status_id');
//send notification of PCP create/update.
$pcpParams = array('entity_table' => $entity_table, 'entity_id' => $pcp->page_id);
$notifyParams = array();
$notifyStatus = "";
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
if ($emails = $pcpBlock->notify_email) {
$this->assign('pcpTitle', $pcp->title);
if ($this->_pageId) {
$this->assign('mode', 'Update');
}
else {
$this->assign('mode', 'Add');
}
$pcpStatus = CRM_Core_PseudoConstant::getLabel('CRM_PCP_DAO_PCP', 'status_id', $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, FALSE,
FALSE
);
$this->assign('supporterUrl', $supporterUrl);
$supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name');
$this->assign('supporterName', $supporterName);
if ($this->_component == 'contribute') {
$pageUrl = CRM_Utils_System::url('civicrm/contribute/transact',
"reset=1&id={$pcpBlock->entity_id}",
TRUE, NULL, FALSE,
TRUE
);
$contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcpBlock->entity_id, 'title');
}
elseif ($this->_component == 'event') {
$pageUrl = CRM_Utils_System::url('civicrm/event',
"reset=1&id={$pcpBlock->entity_id}",
TRUE, NULL, FALSE,
TRUE
);
$contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $pcpBlock->entity_id, 'title');
}
$this->assign('contribPageUrl', $pageUrl);
$this->assign('contribPageTitle', $contribPageTitle);
$managePCPUrl = CRM_Utils_System::url('civicrm/admin/pcp',
"reset=1",
TRUE, NULL, FALSE,
FALSE
);
$this->assign('managePCPUrl', $managePCPUrl);
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
$fixUrl = CRM_Utils_System::url('civicrm/admin/domain', 'action=update&reset=1');
CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
}
//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);
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::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_PCP_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, TRUE, $this->_component);
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)
), '', 'info');
if (!$this->_pageId) {
$session->pushUserContext(CRM_Utils_System::url('civicrm/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}"));
}
elseif ($this->_context == 'dashboard') {
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1'));
}
}
}

View file

@ -0,0 +1,184 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class generates form components for Tell A Friend
*
*/
class CRM_PCP_Form_Contribute extends CRM_Contribute_Form_ContributionPage {
/**
* The type of pcp component.
*
* @var int
*/
public $_component = 'contribute';
public function preProcess() {
parent::preProcess();
}
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
*
* @return void
*/
public function setDefaultValues() {
$defaults = array();
if (isset($this->_id)) {
$params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_contribution_page');
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $defaults);
$defaults['pcp_active'] = CRM_Utils_Array::value('is_active', $defaults);
// Assign contribution page ID to pageId for referencing in PCP.hlp - since $id is overwritten there. dgg
$this->assign('pageId', $this->_id);
}
if (empty($defaults['id'])) {
$defaults['target_entity_type'] = 'contribute';
$defaults['is_approval_needed'] = 1;
$defaults['is_tellfriend_enabled'] = 1;
$defaults['tellfriend_limit'] = 5;
$defaults['link_text'] = ts('Create your own fundraising page');
$defaults['owner_notify_id'] = CRM_Core_OptionGroup::getDefaultValue('pcp_owner_notify');
if ($ccReceipt = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'cc_receipt')) {
$defaults['notify_email'] = $ccReceipt;
}
}
return $defaults;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
$this->_last = TRUE;
CRM_PCP_BAO_PCP::buildPCPForm($this);
$this->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages? (for this contribution page)'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','table-row','radio',false);"));
parent::buildQuickForm();
$this->addFormRule(array('CRM_PCP_Form_Contribute', 'formRule'), $this);
}
/**
* Validation.
*
* @param array $params
* (ref.) an assoc array of name/value pairs.
*
* @param $files
* @param $self
*
* @return bool|array
* mixed true or array of errors
*/
public static function formRule($params, $files, $self) {
$errors = array();
if (!empty($params['is_active'])) {
if (!empty($params['is_tellfriend_enabled']) &&
(CRM_Utils_Array::value('tellfriend_limit', $params) <= 0)
) {
$errors['tellfriend_limit'] = ts('if Tell Friend is enabled, Maximum recipients limit should be greater than zero.');
}
if (empty($params['supporter_profile_id'])) {
$errors['supporter_profile_id'] = ts('Supporter profile is a required field.');
}
else {
if (CRM_PCP_BAO_PCP::checkEmailProfile($params['supporter_profile_id'])) {
$errors['supporter_profile_id'] = ts('Profile is not configured with Email address.');
}
}
if ($emails = CRM_Utils_Array::value('notify_email', $params)) {
$emailArray = explode(',', $emails);
foreach ($emailArray as $email) {
if ($email && !CRM_Utils_Rule::email(trim($email))) {
$errors['notify_email'] = ts('A valid Notify Email address must be specified');
}
}
}
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess() {
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
// Source
$params['entity_table'] = 'civicrm_contribution_page';
$params['entity_id'] = $this->_id;
// Target
$params['target_entity_type'] = CRM_Utils_Array::value('target_entity_type', $params, 'contribute');
$params['target_entity_id'] = $this->_id;
$dao = new CRM_PCP_DAO_PCPBlock();
$dao->entity_table = $params['entity_table'];
$dao->entity_id = $this->_id;
$dao->find(TRUE);
$params['id'] = $dao->id;
$params['is_active'] = CRM_Utils_Array::value('pcp_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);
CRM_PCP_BAO_PCPBlock::create($params);
parent::endPostProcess();
}
/**
* Return a descriptive name for the page, used in wizard header
*
* @return string
*/
public function getTitle() {
return ts('Enable Personal Campaign Pages');
}
}

View file

@ -0,0 +1,226 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class generates form components for PCP
*
*/
class CRM_PCP_Form_Event extends CRM_Event_Form_ManageEvent {
/**
* The type of pcp component.
*
* @var int
*/
public $_component = 'event';
public function preProcess() {
parent::preProcess();
}
/**
* Set default values for the form.
*
*
* @return void
*/
public function setDefaultValues() {
$defaults = array();
$defaults = array();
if (isset($this->_id)) {
$title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title');
CRM_Utils_System::setTitle(ts('Personal Campaign Page Settings (%1)', array(1 => $title)));
$params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $defaults);
$defaults['pcp_active'] = CRM_Utils_Array::value('is_active', $defaults);
// Assign contribution page ID to pageId for referencing in PCP.hlp - since $id is overwritten there. dgg
$this->assign('pageId', $this->_id);
}
if (empty($defaults['id'])) {
$defaults['target_entity_type'] = 'event';
$defaults['is_approval_needed'] = 1;
$defaults['is_tellfriend_enabled'] = 1;
$defaults['tellfriend_limit'] = 5;
$defaults['link_text'] = ts('Promote this event with a personal campaign page');
$defaults['owner_notify_id'] = CRM_Core_OptionGroup::getDefaultValue('pcp_owner_notify');
if ($this->_id &&
$ccReceipt = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'cc_receipt')
) {
$defaults['notify_email'] = $ccReceipt;
}
}
return $defaults;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
CRM_PCP_BAO_PCP::buildPCPForm($this);
$this->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages? (for this event)'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','table-row','radio',false);"));
$this->add('select', 'target_entity_type', ts('Campaign Type'),
array('' => ts('- select -'), 'event' => ts('Event'), 'contribute' => ts('Contribution')),
NULL, array('onchange' => "return showHideByValue('target_entity_type','contribute','pcpDetailFields','block','select',false);")
);
$this->add('select', 'target_entity_id',
ts('Online Contribution Page'),
array(
'' => ts('- select -'),
) +
CRM_Contribute_PseudoConstant::contributionPage()
);
parent::buildQuickForm();
// If at least one PCP has been created, don't allow changing the target
$pcpBlock = new CRM_PCP_DAO_PCPBlock();
$pcpBlock->entity_table = 'civicrm_event';
$pcpBlock->entity_id = $this->_id;
$pcpBlock->find(TRUE);
if (!empty($pcpBlock->id) && CRM_PCP_BAO_PCP::getPcpBlockInUse($pcpBlock->id)) {
foreach (array(
'target_entity_type',
'target_entity_id',
) as $element_name) {
$element = $this->getElement($element_name);
$element->freeze();
}
}
$this->addFormRule(array('CRM_PCP_Form_Event', 'formRule'), $this);
}
/**
* Validation.
*
* @param array $params
* (ref.) an assoc array of name/value pairs.
*
* @param $files
* @param $self
*
* @return bool|array
* mixed true or array of errors
*/
public static function formRule($params, $files, $self) {
$errors = array();
if (!empty($params['is_active'])) {
if (!empty($params['is_tellfriend_enabled']) &&
(CRM_Utils_Array::value('tellfriend_limit', $params) <= 0)
) {
$errors['tellfriend_limit'] = ts('if Tell Friend is enable, Maximum recipients limit should be greater than zero.');
}
if (empty($params['supporter_profile_id'])) {
$errors['supporter_profile_id'] = ts('Supporter profile is a required field.');
}
else {
if (CRM_PCP_BAO_PCP::checkEmailProfile($params['supporter_profile_id'])) {
$errors['supporter_profile_id'] = ts('Profile is not configured with Email address.');
}
}
if ($emails = CRM_Utils_Array::value('notify_email', $params)) {
$emailArray = explode(',', $emails);
foreach ($emailArray as $email) {
if ($email && !CRM_Utils_Rule::email(trim($email))) {
$errors['notify_email'] = ts('A valid Notify Email address must be specified');
}
}
}
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess() {
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
// Source
$params['entity_table'] = 'civicrm_event';
$params['entity_id'] = $this->_id;
// Target
$params['target_entity_type'] = CRM_Utils_Array::value('target_entity_type', $params, 'event');
if ($params['target_entity_type'] == 'event') {
$params['target_entity_id'] = $this->_id;
}
else {
$params['target_entity_id'] = CRM_Utils_Array::value('target_entity_id', $params, $this->_id);
}
$dao = new CRM_PCP_DAO_PCPBlock();
$dao->entity_table = $params['entity_table'];
$dao->entity_id = $this->_id;
$dao->find(TRUE);
$params['id'] = $dao->id;
$params['is_active'] = CRM_Utils_Array::value('pcp_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);
CRM_PCP_BAO_PCPBlock::create($params);
// Update tab "disabled" css class
$this->ajaxResponse['tabValid'] = !empty($params['is_active']);
parent::endPostProcess();
}
/**
* Return a descriptive name for the page, used in wizard header
*
* @return string
*/
public function getTitle() {
return ts('Enable Personal Campaign Pages');
}
}

View file

@ -0,0 +1,222 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Administer Personal Campaign Pages - Search form
*/
class CRM_PCP_Form_PCP extends CRM_Core_Form {
public $_context;
/**
* Set variables up before form is built.
*/
public function preProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
//check permission for action.
if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_title = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'title');
$this->assign('title', $this->_title);
parent::preProcess();
}
if (!$this->_action) {
$this->_action = CRM_Utils_Array::value('action', $_GET);
$this->_id = CRM_Utils_Array::value('id', $_GET);
}
else {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
}
//give the context.
if (!isset($this->_context)) {
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
}
$this->assign('context', $this->_context);
$session = CRM_Core_Session::singleton();
$context = $session->popUserContext();
$userID = $session->get('userID');
//do not allow destructive actions without permissions
$permission = FALSE;
if (CRM_Core_Permission::check('administer CiviCRM') ||
($userID && (CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
$this->_id,
'contact_id'
) == $userID))
) {
$permission = TRUE;
}
if ($permission && $this->_id) {
$this->_title = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'title');
switch ($this->_action) {
case CRM_Core_Action::DELETE:
case 'delete':
CRM_PCP_BAO_PCP::deleteById($this->_id);
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success');
break;
case CRM_Core_Action::DISABLE:
case 'disable':
CRM_PCP_BAO_PCP::setDisable($this->_id, '0');
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been disabled.", array(1 => $this->_title)), ts('Page Disabled'), 'success');
break;
case CRM_Core_Action::ENABLE:
case 'enable':
CRM_PCP_BAO_PCP::setDisable($this->_id, '1');
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been enabled.", array(1 => $this->_title)), ts('Page Enabled'), 'success');
break;
}
if ($context) {
CRM_Utils_System::redirect($context);
}
}
}
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
* @return array
* array of default values
*/
public function setDefaultValues() {
$defaults = array();
$pageType = CRM_Utils_Request::retrieve('page_type', 'String', $this);
$defaults['page_type'] = !empty($pageType) ? $pageType : '';
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
if ($this->_action & CRM_Core_Action::DELETE) {
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Delete Campaign'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
else {
$status = array('' => ts('- select -')) + CRM_Core_OptionGroup::values("pcp_status");
$types = array(
'' => ts('- select -'),
'contribute' => ts('Contribution'),
'event' => ts('Event'),
);
$contribPages = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage();
$eventPages = array('' => ts('- select -')) + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
$this->addElement('select', 'status_id', ts('Status'), $status);
$this->addElement('select', 'page_type', ts('Source Type'), $types);
$this->addElement('select', 'page_id', ts('Contribution Page'), $contribPages);
$this->addElement('select', 'event_id', ts('Event Page'), $eventPages);
$this->addButtons(array(
array(
'type' => 'refresh',
'name' => ts('Search'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
)
);
parent::buildQuickForm();
}
}
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
* @param array $files
* @param CRM_Core_Form $form
*
* @return array|NULL
* list of errors to be posted back to the form
*/
public static function formRule($fields, $files, $form) {
return NULL;
}
/**
* Process the form.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_PCP_BAO_PCP::deleteById($this->_id);
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success');
}
else {
$params = $this->controller->exportValues($this->_name);
$parent = $this->controller->getParent();
if (!empty($params)) {
$fields = array('status_id', 'page_id');
foreach ($fields as $field) {
if (isset($params[$field]) &&
!CRM_Utils_System::isNull($params[$field])
) {
$parent->set($field, $params[$field]);
}
else {
$parent->set($field, NULL);
}
}
}
}
}
}

View file

@ -0,0 +1,280 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class generates form components for processing a contribution.
*/
class CRM_PCP_Form_PCPAccount extends CRM_Core_Form {
/**
* Variable defined for Contribution Page Id.
*/
public $_pageId = NULL;
public $_id = NULL;
public $_component = NULL;
/**
* Are we in single form mode or wizard mode?
*
* @var boolean
*/
public $_single;
public function preProcess() {
$session = CRM_Core_Session::singleton();
$config = CRM_Core_Config::singleton();
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
$this->_pageId = CRM_Utils_Request::retrieve('pageId', 'Positive', $this);
$this->_component = CRM_Utils_Request::retrieve('component', 'String', $this);
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
if (!$this->_pageId && $config->userFramework == 'Joomla' && $config->userFrameworkFrontend) {
$this->_pageId = $this->_id;
}
if ($this->_id) {
$contactID = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'contact_id');
}
$this->_contactID = isset($contactID) ? $contactID : $session->get('userID');
if (!$this->_pageId) {
if (!$this->_id) {
$msg = ts('We can\'t load the requested web page due to an incomplete link. This can be caused by using your browser\'s Back button or by using an incomplete or invalid link.');
CRM_Core_Error::fatal($msg);
}
else {
$this->_pageId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'page_id');
}
}
if (!$this->_pageId) {
CRM_Core_Error::fatal(ts('Could not find source page id.'));
}
$this->_single = $this->get('single');
if (!$this->_single) {
$this->_single = $session->get('singleForm');
}
$this->set('action', $this->_action);
$this->set('page_id', $this->_id);
$this->set('component_page_id', $this->_pageId);
// we do not want to display recently viewed items, so turn off
$this->assign('displayRecent', FALSE);
$this->assign('pcpComponent', $this->_component);
if ($this->_single) {
CRM_Utils_System::setTitle(ts('Update Contact Information'));
}
}
/**
* @return array
*/
public function setDefaultValues() {
$this->_defaults = array();
if ($this->_contactID) {
foreach ($this->_fields as $name => $dontcare) {
$fields[$name] = 1;
}
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
}
//set custom field defaults
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
if (!isset($this->_defaults[$name])) {
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults,
NULL, CRM_Profile_Form::MODE_REGISTER
);
}
}
}
return $this->_defaults;
}
/**
* Build the form object.
*
* @return void
*/
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);
$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' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
);
}
else {
$button[] = array(
'type' => 'next',
'name' => ts('Continue'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
);
}
$this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
$this->addButtons($button);
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param $self
*
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
$errors = array();
foreach ($fields as $key => $value) {
if (strpos($key, 'email-') !== FALSE && !empty($value)) {
$ufContactId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFMatch', $value, 'contact_id', 'uf_name');
if ($ufContactId && $ufContactId != $self->_contactID) {
$errors[$key] = ts('There is already an user associated with this email address. Please enter different email address.');
}
}
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess() {
$params = $this->controller->exportValues($this->getName());
if (!$this->_contactID && isset($params['cms_create_account'])) {
foreach ($params as $key => $value) {
if (substr($key, 0, 5) == 'email' && !empty($value)) {
list($fieldName, $locTypeId) = CRM_Utils_System::explode('-', $key, 2);
$isPrimary = 0;
if ($locTypeId == 'Primary') {
$locTypeDefault = CRM_Core_BAO_LocationType::getDefault();
$locTypeId = NULL;
if ($locTypeDefault) {
$locTypeId = $locTypeDefault->id;
}
$isPrimary = 1;
}
$params['email'] = array();
$params['email'][1]['email'] = $value;
$params['email'][1]['location_type_id'] = $locTypeId;
$params['email'][1]['is_primary'] = $isPrimary;
}
}
}
$this->_contactID = CRM_Contact_BAO_Contact::getFirstDuplicateContact($params, 'Individual', 'Unsupervised', array(), FALSE);
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_contactID);
$this->set('contactID', $contactID);
if (!empty($params['email'])) {
$params['email'] = $params['email'][1]['email'];
}
CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params, $contactID, 'email');
}
}