Пример #1
0
 function __construct()
 {
     // Check if CiviCampaign is a) enabled and b) has active campaigns
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE), 'postal_greeting_display' => array('title' => ts('Postal Greeting')), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact SubType'))), 'grouping' => 'contact-fields', 'group_bys' => array('id' => array('title' => ts('Contact ID')), 'sort_name' => array('title' => ts('Contact Name')))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_financial_type' => array('dao' => 'CRM_Financial_DAO_FinancialType', 'fields' => array('financial_type' => null), 'grouping' => 'contri-fields', 'group_bys' => array('financial_type' => array('title' => ts('Financial Type')))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_source' => array('title' => ts('Source')), 'currency' => array('required' => TRUE, 'no_display' => TRUE), 'total_amount' => array('title' => ts('Contribution Amount Stats'), 'default' => TRUE, 'statistics' => array('sum' => ts('Contributions Aggregate'), 'count' => ts('Contributions'), 'avg' => ts('Contributions Avg')))), 'grouping' => 'contri-fields', 'filters' => array('receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'contribution_status_id' => array('title' => ts('Donation Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1), 'type' => CRM_Utils_Type::T_INT), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialType(), 'type' => CRM_Utils_Type::T_INT), 'contribution_page_id' => array('title' => ts('Contribution Page'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionPage(), 'type' => CRM_Utils_Type::T_INT), 'total_amount' => array('title' => ts('Contribution Amount')), 'total_sum' => array('title' => ts('Contributions Aggregate'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_sum', 'having' => TRUE), 'total_count' => array('title' => ts('Contributions Count'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_count', 'having' => TRUE), 'total_avg' => array('title' => ts('Contributions Avg'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_avg', 'having' => TRUE)), 'group_bys' => array('receive_date' => array('frequency' => TRUE, 'default' => TRUE, 'chart' => TRUE), 'contribution_source' => NULL)), 'civicrm_contribution_soft' => array('dao' => 'CRM_Contribute_DAO_ContributionSoft', 'fields' => array('soft_amount' => array('title' => ts('Soft Credit Amount Stats'), 'name' => 'amount', 'statistics' => array('sum' => ts('Soft Credit Aggregate'), 'count' => ts('Soft Credits'), 'avg' => ts('Soft Credit Avg')))), 'grouping' => 'contri-fields', 'filters' => array('amount' => array('title' => ts('Soft Credit Amount')), 'soft_sum' => array('title' => ts('Soft Credit Aggregate'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_sum', 'having' => TRUE), 'soft_count' => array('title' => ts('Soft Credits Count'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_count', 'having' => TRUE), 'soft_avg' => array('title' => ts('Soft Credit Avg'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_avg', 'having' => TRUE))), 'civicrm_group' => array('dao' => 'CRM_Contact_DAO_GroupContact', 'alias' => 'cgroup', 'filters' => array('gid' => array('name' => 'group_id', 'title' => ts('Group'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'group' => TRUE, 'options' => CRM_Core_PseudoConstant::group(), 'type' => CRM_Utils_Type::T_INT)))) + $this->addAddressFields();
     // If we have a campaign, build out the relevant elements
     $this->_tagFilter = TRUE;
     if ($campaignEnabled && !empty($this->activeCampaigns)) {
         $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => 'Campaign', 'default' => 'false');
         $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns);
         $this->_columns['civicrm_contribution']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
     }
     $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
 }
Пример #2
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     $session =& CRM_Core_Session::singleton();
     $config =& CRM_Core_Config::singleton();
     $permissionCheck = false;
     $statusMessage = '';
     if ($config->userFramework != 'Joomla') {
         $permissionCheck = CRM_Core_Permission::check('administer CiviCRM');
     }
     //get the pcp id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false);
     $prms = array('id' => $this->_id);
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCP', $prms, $pcpInfo);
     if (empty($pcpInfo)) {
         $statusMessage = ts('The personal campaign page you requested is currently unavailable.');
         CRM_Core_Error::statusBounce($statusMessage, $config->userFrameworkBaseURL);
     }
     CRM_Utils_System::setTitle($pcpInfo['title']);
     $this->assign('pcp', $pcpInfo);
     require_once 'CRM/Contribute/PseudoConstant.php';
     require_once 'CRM/Core/OptionGroup.php';
     $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
     $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name');
     // check if PCP is created by anonymous user
     $anonymousPCP = CRM_Utils_Request::retrieve('ap', 'Boolean', $this);
     if ($anonymousPCP) {
         $loginUrl = $config->userFrameworkBaseURL;
         switch (ucfirst($config->userFramework)) {
             case 'Joomla':
                 $loginUrl = str_replace('administrator/', '', $loginUrl);
                 $loginUrl .= 'index.php?option=com_user&view=login';
                 break;
             case 'Drupal':
                 $loginUrl .= 'user';
                 break;
         }
         $anonMessage = ts('Once you\'ve received your new account welcome email, you can <a href=%1>click here</a> to login and promote your campaign page.', array(1 => $loginUrl));
         CRM_Core_Session::setStatus($anonMessage);
     } else {
         $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.');
     }
     if (!$pcpInfo['is_active']) {
         // form is inactive, forward to main contribution page
         CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
     } else {
         if ($pcpInfo['status_id'] != $approvedId && !$permissionCheck) {
             if ($pcpInfo['contact_id'] != $session->get('userID')) {
                 // PCP not approved. Forward everyone except admin and owner to main contribution page
                 CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
             }
         } else {
             $getStatus = CRM_Contribute_BAO_PCP::getStatus($this->_id);
             if (!$getStatus) {
                 // PCP not enabled for this contribution page. Forward everyone to main contribution page
                 CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true));
             }
         }
     }
     $default = array();
     CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pcpInfo['contribution_page_id'], $default, array('start_date', 'end_date'));
     require_once "CRM/Contribute/PseudoConstant.php";
     $this->assign('pageName', CRM_Contribute_PseudoConstant::contributionPage($pcpInfo['contribution_page_id'], true));
     if ($pcpInfo['contact_id'] == $session->get('userID')) {
         $owner = $default[$pcpInfo['contribution_page_id']];
         $owner['status'] = CRM_Utils_Array::value($pcpInfo['status_id'], $pcpStatus);
         $this->assign('owner', $owner);
         require_once 'CRM/Contribute/BAO/PCP.php';
         $link = CRM_Contribute_BAO_PCP::pcpLinks();
         unset($link['all'][CRM_Core_Action::ENABLE]);
         $hints = array(CRM_Core_Action::UPDATE => ts('Change the content and appearance of your page'), CRM_Core_Action::DETACH => ts('Send emails inviting your friends to support your campaign!'), CRM_Core_Action::BROWSE => ts('Update your personal contact information'), CRM_Core_Action::DISABLE => ts('De-activate the page (you can re-activate it later)'), CRM_Core_Action::DELETE => ts('Remove the page (this cannot be undone!)'));
         CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_PCPBlock', $pcpInfo['contribution_page_id'], 'entity_id', $blockValues, array('is_tellfriend_enabled'));
         $blockId = array_pop($blockValues);
         $replace = array('id' => $this->_id, 'block' => $blockId['id']);
         if (!CRM_Utils_Array::value('is_tellfriend_enabled', $blockId) || CRM_Utils_Array::value('status_id', $pcpInfo) != $approvedId) {
             unset($link['all'][CRM_Core_Action::DETACH]);
         }
         $this->assign('links', $link['all']);
         $this->assign('hints', $hints);
         $this->assign('replace', $replace);
     }
     $honor = CRM_Contribute_BAO_PCP::honorRoll($this->_id);
     if ($file_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $this->_id, 'file_id', 'entity_id')) {
         $image = '<img src="' . CRM_Utils_System::url('civicrm/file', "reset=1&id={$file_id}&eid={$this->_id}") . '" />';
         $this->assign('image', $image);
     }
     $totalAmount = CRM_Contribute_BAO_PCP::thermoMeter($this->_id);
     $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2);
     if ($linkText = CRM_Contribute_BAO_PCP::getPcpBlockStatus($pcpInfo['contribution_page_id'])) {
         $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$pcpInfo['contribution_page_id']}", true, null, true, true);
         $this->assign('linkTextUrl', $linkTextUrl);
         $this->assign('linkText', $linkText);
     }
     $this->assign('honor', $honor);
     $this->assign('total', $totalAmount ? $totalAmount : '0.0');
     $this->assign('achieved', $achieved <= 100 ? $achieved : 100);
     if ($achieved <= 100) {
         $this->assign('remaining', 100 - $achieved);
     }
     // make sure that we are between  registration start date and registration end date
     $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $owner));
     $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $owner));
     $now = time();
     $validDate = true;
     if ($startDate && $startDate >= $now) {
         $validDate = false;
     }
     if ($endDate && $endDate < $now) {
         $validDate = false;
     }
     $this->assign('validDate', true);
     if ($validDate) {
         $contributionText = ts('Contribute Now');
         if (CRM_Utils_Array::value('donate_link_text', $pcpInfo)) {
             $contributionText = $pcpInfo['donate_link_text'];
         }
         $this->assign('contributionText', $contributionText);
         // we always generate urls for the front end in joomla
         if ($action == CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url('civicrm/contribute/transact', "id={$pcpInfo['contribution_page_id']}&pcpId={$this->_id}&reset=1&action=preview", true, null, true, true);
         } else {
             $url = CRM_Utils_System::url('civicrm/contribute/transact', "id={$pcpInfo['contribution_page_id']}&pcpId={$this->_id}&reset=1", true, null, true, true);
         }
         $this->assign('contributeURL', $url);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', false);
     $single = $permission = false;
     switch ($action) {
         case CRM_Core_Action::BROWSE:
             $subForm = 'PCPAccount';
             $form = "CRM_Contribute_Form_PCP_{$subForm}";
             $single = true;
             break;
         case CRM_Core_Action::UPDATE:
             $subForm = 'Campaign';
             $form = "CRM_Contribute_Form_PCP_{$subForm}";
             $single = true;
             break;
     }
     $userID = $session->get('userID');
     //make sure the user has "administer CiviCRM" permission
     //OR has created the PCP
     if (CRM_Core_Permission::check('administer CiviCRM') || $userID && CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $this->_id, 'contact_id') == $userID) {
         $permission = true;
     }
     if ($single && $permission) {
         require_once 'CRM/Core/Controller/Simple.php';
         $controller =& new CRM_Core_Controller_Simple($form, $subForm, $action);
         $controller->set('id', $this->_id);
         $controller->set('single', true);
         $controller->process();
         return $controller->run();
     }
     $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&id=' . $this->_id));
     parent::run();
 }
Пример #3
0
 /**
  * Browse all custom data groups.
  *  
  * 
  * @return void
  * @access public
  * @static
  */
 function browse($action = null)
 {
     require_once 'CRM/Contact/BAO/GroupNesting.php';
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
     if ($this->_sortByCharacter == 1 || !empty($_POST)) {
         $this->_sortByCharacter = '';
     }
     require_once 'CRM/Contribute/PseudoConstant.php';
     $status = CRM_Contribute_PseudoConstant::pcpstatus();
     $contribution_page = CRM_Contribute_PseudoConstant::contributionPage();
     $pcpSummary = $params = array();
     $whereClause = null;
     if (!empty($_POST)) {
         if ($_POST['status_id'] != 0) {
             $whereClause = ' AND cp.status_id = %1';
             $params['1'] = array($_POST['status_id'], 'Integer');
         }
         if ($_POST['contibution_page_id'] != 0) {
             $whereClause .= ' AND cp.contribution_page_id = %2';
             $params['2'] = array($_POST['contibution_page_id'], 'Integer');
         }
         if ($_POST['status_id'] != 0 || $_POST['contibution_page_id'] != 0) {
             $this->set('whereClause', $whereClause);
             $this->set('params', $params);
         } else {
             $this->set('whereClause', null);
             $this->set('params', null);
         }
     }
     $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name');
     //check for delete CRM-4418
     require_once 'CRM/Core/Permission.php';
     $allowToDelete = CRM_Core_Permission::check('delete in CiviContribute');
     $params = $this->get('params') ? $this->get('params') : array();
     $title = ' AND cp.title LIKE %3';
     $params['3'] = array($this->_sortByCharacter . '%', 'String');
     $query = "\n        SELECT cp.id as id, contact_id , status_id, cp.title as title, contribution_page_id, start_date, end_date, cp.is_active as active\n        FROM civicrm_pcp cp, civicrm_contribution_page cpp\n        WHERE cp.contribution_page_id = cpp.id {$title}" . $this->get('whereClause') . " ORDER BY status_id";
     $dao = CRM_Core_DAO::executeQuery($query, $params, true, 'CRM_Contribute_DAO_PCP');
     while ($dao->fetch()) {
         $pcpSummary[$dao->id] = array();
         $action = array_sum(array_keys($this->links()));
         CRM_Core_DAO::storeValues($dao, $pcpSummary[$dao->id]);
         require_once 'CRM/Contact/BAO/Contact.php';
         $contact = CRM_Contact_BAO_Contact::getDisplayAndImage($dao->contact_id);
         $class = '';
         if ($dao->status_id != $approvedId || $dao->active != 1) {
             $class = 'disabled';
         }
         switch ($dao->status_id) {
             case 2:
                 $action -= CRM_Core_Action::RENEW;
                 break;
             case 3:
                 $action -= CRM_Core_Action::REVERT;
                 break;
         }
         if (!$allowToDelete) {
             $action -= CRM_Core_Action::DELETE;
         }
         $pcpSummary[$dao->id]['id'] = $dao->id;
         $pcpSummary[$dao->id]['start_date'] = $dao->start_date;
         $pcpSummary[$dao->id]['end_date'] = $dao->end_date;
         $pcpSummary[$dao->id]['supporter'] = $contact['0'];
         $pcpSummary[$dao->id]['supporter_id'] = $dao->contact_id;
         $pcpSummary[$dao->id]['status_id'] = $status[$dao->status_id];
         $pcpSummary[$dao->id]['contribution_page_id'] = $dao->contribution_page_id;
         $pcpSummary[$dao->id]['contribution_page_title'] = $contribution_page[$dao->contribution_page_id];
         $pcpSummary[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id));
         $pcpSummary[$dao->id]['class'] = $class;
     }
     $this->search();
     $this->pagerAToZ($this->get('whereClause'), $params);
     if ($pcpSummary) {
         $this->assign('rows', $pcpSummary);
     }
     // Let template know if user has run a search or not
     if ($this->get('whereClause')) {
         $this->assign('isSearch', 1);
     } else {
         $this->assign('isSearch', 0);
     }
 }
Пример #4
0
 public function preProcess()
 {
     CRM_Utils_System::setTitle(ts('CiviMember Component Settings'));
     $this->_varNames = array(CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME => array('default_renewal_contribution_page' => array('html_type' => 'select', 'title' => ts('Default online membership renewal page'), 'option_values' => array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), 'weight' => 1, 'description' => ts('If you select a default online contribution page for self-service membership renewals, a "renew" link pointing to that page will be displayed on the Contact Dashboard for memberships which were entered offline. You will need to ensure that the membership block for the selected online contribution page includes any currently available memberships.'))));
     parent::preProcess();
 }
Пример #5
0
 /**
  * Add profile field to a form.
  *
  * @param CRM_Core_Form $form
  * @param array $field
  *   Properties.
  * @param int $mode
  *   Profile mode.
  * @param int $contactId
  * @param bool $online
  * @param string $usedFor
  *   For building up prefixed fieldname for special cases (e.g. onBehalf, Honor).
  * @param int $rowNumber
  * @param string $prefix
  *
  * @return null
  */
 public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $rowNumber = NULL, $prefix = '')
 {
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE;
     $isShared = CRM_Utils_Array::value('is_shared', $field, 0);
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return NULL;
     }
     if ($usedFor == 'onbehalf') {
         $name = "onbehalf[{$fieldName}]";
     } elseif ($usedFor == 'honor') {
         $name = "honor[{$fieldName}]";
     } elseif ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } elseif ($rowNumber) {
         $name = "field[{$rowNumber}][{$fieldName}]";
     } elseif (!empty($prefix)) {
         $name = $prefix . "[{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE);
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = json_encode(ts('Are you sure you want to delete contact image.'));
         $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&confirmed=1'; else return false;") . '"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id'));
         $form->assign('deleteURL', $deleteURL);
     }
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->addChainSelect($name, array('label' => $title, 'required' => $required));
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) {
             $defaultValues[$name] = $config->defaultContactStateProvince;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
             $defaultValues[$name] = $config->defaultContactCountry;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 6) === 'county') {
         if ($addressOptions['county']) {
             $form->addChainSelect($name, array('label' => $title, 'required' => $required));
         }
     } elseif (substr($fieldName, 0, 9) === 'image_URL') {
         $form->add('file', $name, $title, $attributes, $required);
         $form->addUploadElement($name);
     } elseif (substr($fieldName, 0, 2) === 'im') {
         $form->add('text', $name, $title, $attributes, $required);
         if (!$contactId) {
             if ($usedFor) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
             }
             if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                 $form->freeze($name . '-provider_id');
             }
         }
     } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
     } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
         $form->addDate($name, $title, $required, array('formatType' => 'activityDate'));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         if (count($orgInfo) == 1 && $field['is_required']) {
             // we only have one org - so we should default to it. Not sure about defaulting to first type
             // as it could be missed - so adding a select
             // however, possibly that is more similar to the membership form
             if (count($types[1]) > 1) {
                 $types[1] = $select + $types[1];
             }
         } else {
             $orgInfo = $select + $orgInfo;
         }
         $sel->setOptions(array($orgInfo, $types));
     } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) {
         $options = array();
         $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName);
         foreach ($pseudoValues as $key => $var) {
             $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key);
         }
         $group = $form->addGroup($options, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         } else {
             $group->setAttribute('allowClear', TRUE);
         }
     } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
         $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         if ($usedFor == 'onbehalf') {
             $profileType = 'Organization';
         } elseif ($usedFor == 'honor') {
             $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
             if ($profileType == 'Contact') {
                 $profileType = 'Individual';
             }
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE));
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language'));
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
         $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
     } elseif ($fieldName === 'group') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
     } elseif ($fieldName === 'tag') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
     } elseif (substr($fieldName, 0, 4) === 'url-') {
         $form->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required);
         $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
     } elseif (substr($fieldName, -4) == 'note') {
         $form->add('textarea', $name, $title, $attributes, $required);
     } elseif (substr($fieldName, 0, 6) === 'custom') {
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (substr($fieldName, 0, 14) === 'address_custom') {
         list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'send_receipt') {
         $form->addElement('checkbox', $name, $title);
     } elseif ($fieldName == 'soft_credit') {
         $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE));
         $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
     } elseif ($fieldName == 'product_name') {
         list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $products = array('0' => ts('- select -')) + $products;
         $sel->setOptions(array($products, $options));
     } elseif ($fieldName == 'payment_instrument') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
     } elseif ($fieldName == 'financial_type') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required);
     } elseif ($fieldName == 'contribution_status_id') {
         $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
         $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) {
             unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]);
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required);
     } elseif ($fieldName == 'soft_credit_type') {
         $name = "soft_credit_type[{$rowNumber}]";
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type"));
         //CRM-15350: choose SCT field default value as 'Gift' for membership use
         //else (for contribution), use configured SCT default value
         $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type");
         if ($field['field_type'] == 'Membership') {
             $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
         }
         $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id'));
     } elseif ($fieldName == 'currency') {
         $form->addCurrency($name, $title, $required);
     } elseif ($fieldName == 'contribution_page_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"');
     } elseif ($fieldName == 'participant_register_date') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'activity_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
     } elseif ($fieldName == 'activity_engagement_level') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required);
     } elseif ($fieldName == 'activity_date_time') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'participant_status') {
         $cond = NULL;
         if ($online == TRUE) {
             $cond = 'visibility_id = 1';
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required);
     } elseif ($fieldName == 'participant_role') {
         if (!empty($field['is_multiple'])) {
             $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
         } else {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
         }
     } elseif ($fieldName == 'world_region') {
         $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes);
     } elseif ($fieldName == 'signature_html') {
         $form->add('wysiwyg', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif ($fieldName == 'signature_text') {
         $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif (substr($fieldName, -11) == 'campaign_id') {
         if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
             $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns));
             $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"');
         }
     } elseif ($fieldName == 'activity_details') {
         $form->add('wysiwyg', $fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
     } elseif ($fieldName == 'activity_duration') {
         $form->add('text', $name, $title, $attributes, $required);
         $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     } else {
         if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
             $form->add('advcheckbox', $name, $title, $attributes, $required);
         } else {
             $form->add('text', $name, $title, $attributes, $required);
         }
     }
     static $hiddenSubtype = FALSE;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         if ($usedFor) {
             $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']);
         } else {
             $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         }
         $hiddenSubtype = TRUE;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
Пример #6
0
 /**
  * Alter display of rows.
  *
  * Iterate through the rows retrieved via SQL and make changes for display purposes,
  * such as rendering contacts as links.
  *
  * @param array $rows
  *   Rows generated by SQL, with an array for each row.
  */
 public function alterDisplay(&$rows)
 {
     $checkList = array();
     $entryFound = FALSE;
     $display_flag = $prev_cid = $cid = 0;
     $contributionTypes = CRM_Contribute_PseudoConstant::financialType();
     $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument();
     $contributionPages = CRM_Contribute_PseudoConstant::contributionPage();
     foreach ($rows as $rowNum => $row) {
         if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') {
             // don't repeat contact details if its same as the previous row
             if (array_key_exists('civicrm_contact_id', $row)) {
                 if ($cid = $row['civicrm_contact_id']) {
                     if ($rowNum == 0) {
                         $prev_cid = $cid;
                     } else {
                         if ($prev_cid == $cid) {
                             $display_flag = 1;
                             $prev_cid = $cid;
                         } else {
                             $display_flag = 0;
                             $prev_cid = $cid;
                         }
                     }
                     if ($display_flag) {
                         foreach ($row as $colName => $colVal) {
                             // Hide repeats in no-repeat columns, but not if the field's a section header
                             if (in_array($colName, $this->_noRepeats) && !array_key_exists($colName, $this->_sections)) {
                                 unset($rows[$rowNum][$colName]);
                             }
                         }
                     }
                     $entryFound = TRUE;
                 }
             }
         }
         if (CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) == 'Contribution') {
             unset($rows[$rowNum]['civicrm_contribution_soft_soft_credit_type_id']);
         }
         // convert donor sort name to link
         if (array_key_exists('civicrm_contact_sort_name', $row) && !empty($rows[$rowNum]['civicrm_contact_sort_name']) && array_key_exists('civicrm_contact_id', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact.");
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value];
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value];
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_page_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_contribution_page_id'] = $contributionPages[$value];
             $entryFound = TRUE;
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_payment_instrument_id', $row)) {
             $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value];
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_batch_batch_id', $row)) {
             if ($value = $row['civicrm_batch_batch_id']) {
                 $rows[$rowNum]['civicrm_batch_batch_id'] = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $value, 'title');
             }
             $entryFound = TRUE;
         }
         // Contribution amount links to viewing contribution
         if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount_sum', $row)) && CRM_Core_Permission::check('access CiviContribute')) {
             $url = CRM_Utils_System::url("civicrm/contact/view/contribution", "reset=1&id=" . $row['civicrm_contribution_contribution_id'] . "&cid=" . $row['civicrm_contact_id'] . "&action=view&context=contribution&selectedChild=contribute", $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contribution_total_amount_sum_link'] = $url;
             $rows[$rowNum]['civicrm_contribution_total_amount_sum_hover'] = ts("View Details of this Contribution.");
             $entryFound = TRUE;
         }
         // convert campaign_id to campaign title
         if (array_key_exists('civicrm_contribution_campaign_id', $row)) {
             if ($value = $row['civicrm_contribution_campaign_id']) {
                 $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value];
                 $entryFound = TRUE;
             }
         }
         // soft credits
         if (array_key_exists('civicrm_contribution_soft_credits', $row) && 'Contribution' == CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) && array_key_exists('civicrm_contribution_contribution_id', $row)) {
             $query = "\nSELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount_sum, civicrm_contribution_currency\nFROM   civireport_contribution_detail_temp2\nWHERE  civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}";
             $dao = CRM_Core_DAO::executeQuery($query);
             $string = '';
             $separator = $this->_outputMode !== 'csv' ? "<br/>" : ' ';
             while ($dao->fetch()) {
                 $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $dao->civicrm_contact_id);
                 $string = $string . ($string ? $separator : '') . "<a href='{$url}'>{$dao->civicrm_contact_sort_name}</a> " . CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->civicrm_contribution_currency);
             }
             $rows[$rowNum]['civicrm_contribution_soft_credits'] = $string;
         }
         if (array_key_exists('civicrm_contribution_soft_credit_for', $row) && 'Soft Credit' == CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) && array_key_exists('civicrm_contribution_contribution_id', $row)) {
             $query = "\nSELECT civicrm_contact_id, civicrm_contact_sort_name\nFROM   civireport_contribution_detail_temp1\nWHERE  civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}";
             $dao = CRM_Core_DAO::executeQuery($query);
             $string = '';
             while ($dao->fetch()) {
                 $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $dao->civicrm_contact_id);
                 $string = $string . "\n<a href='{$url}'>{$dao->civicrm_contact_sort_name}</a>";
             }
             $rows[$rowNum]['civicrm_contribution_soft_credit_for'] = $string;
         }
         //convert soft_credit_type_id into label
         if (array_key_exists('civicrm_contribution_soft_soft_credit_type_id', $rows[$rowNum])) {
             $rows[$rowNum]['civicrm_contribution_soft_soft_credit_type_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', $row['civicrm_contribution_soft_soft_credit_type_id']);
         }
         $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ? TRUE : $entryFound;
         //handle gender
         if (array_key_exists('civicrm_contact_gender_id', $row)) {
             if ($value = $row['civicrm_contact_gender_id']) {
                 $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
                 $rows[$rowNum]['civicrm_contact_gender_id'] = $gender[$value];
             }
             $entryFound = TRUE;
         }
         // display birthday in the configured custom format
         if (array_key_exists('civicrm_contact_birth_date', $row)) {
             $birthDate = $row['civicrm_contact_birth_date'];
             if ($birthDate) {
                 $rows[$rowNum]['civicrm_contact_birth_date'] = CRM_Utils_Date::customFormat($birthDate, '%Y%m%d');
             }
             $entryFound = TRUE;
         }
         // skip looking further in rows, if first row itself doesn't
         // have the column we need
         if (!$entryFound) {
             break;
         }
         $lastKey = $rowNum;
     }
 }
Пример #7
0
 /**
  * add all the elements shared between contribute search and advnaced search
  *
  * @access public 
  * @return void
  * @static
  */
 static function buildSearchForm(&$form)
 {
     require_once 'CRM/Utils/Money.php';
     //added contribution source
     $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source'));
     $form->addDate('contribution_date_low', ts('Contribution Dates - From'), false, array('formatType' => 'searchDate'));
     $form->addDate('contribution_date_high', ts('To'), false, array('formatType' => 'searchDate'));
     $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money');
     $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     require_once 'CRM/Contribute/PseudoConstant.php';
     $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType());
     $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage());
     $form->add('select', 'contribution_payment_instrument_id', ts('Payment Instrument'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument());
     $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::pcPage());
     $status = array();
     require_once "CRM/Core/OptionGroup.php";
     $statusValues = CRM_Core_OptionGroup::values("contribution_status");
     // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue).
     unset($statusValues['5']);
     unset($statusValues['6']);
     foreach ($statusValues as $key => $val) {
         $status[] = $form->createElement('advcheckbox', $key, null, $val);
     }
     $form->addGroup($status, 'contribution_status_id', ts('Contribution Status'));
     // add null checkboxes for thank you and receipt
     $form->addElement('checkbox', 'contribution_thankyou_date_isnull', ts('Thank-you date not set?'));
     $form->addElement('checkbox', 'contribution_receipt_date_isnull', ts('Receipt not sent?'));
     //add fields for honor search
     $form->addElement('text', 'contribution_in_honor_of', ts("In Honor Of"));
     $form->addElement('checkbox', 'contribution_test', ts('Find Test Contributions?'));
     $form->addElement('checkbox', 'contribution_pay_later', ts('Find Pay Later Contributions?'));
     //add field for transaction ID search
     $form->addElement('text', 'contribution_transaction_id', ts("Transaction ID"));
     $form->addElement('checkbox', 'contribution_recurring', ts('Find Recurring Contributions?'));
     $form->addElement('text', 'contribution_check_number', ts('Check Number'));
     //add field for pcp display in roll search
     $form->addYesNo('contribution_pcp_display_in_roll', ts('Display In Roll ?'));
     // add all the custom  searchable fields
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $contribution = array('Contribution');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $contribution);
     if ($groupDetails) {
         require_once 'CRM/Core/BAO/CustomField.php';
         $form->assign('contributeGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'custom_' . $fieldId;
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true);
             }
         }
     }
     $form->assign('validCiviContribute', true);
 }
 /**
  * Send the emails.
  *
  * @param int $contactID
  *   Contact id.
  * @param array $values
  *   Associated array of fields.
  * @param bool $isTest
  *   If in test mode.
  * @param bool $returnMessageText
  *   Return the message text instead of sending the mail.
  *
  * @param null $fieldTypes
  *
  * @return void
  */
 public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL)
 {
     $gIds = $params = array();
     $email = NULL;
     if (isset($values['custom_pre_id'])) {
         $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']);
         if ($preProfileType == 'Membership' && !empty($values['membership_id'])) {
             $params['custom_pre_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0));
         } elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) {
             $params['custom_pre_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0));
         }
         $gIds['custom_pre_id'] = $values['custom_pre_id'];
     }
     if (isset($values['custom_post_id'])) {
         $postProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_post_id']);
         if ($postProfileType == 'Membership' && !empty($values['membership_id'])) {
             $params['custom_post_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0));
         } elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) {
             $params['custom_post_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0));
         }
         $gIds['custom_post_id'] = $values['custom_post_id'];
     }
     if (!empty($values['is_for_organization'])) {
         if (!empty($values['membership_id'])) {
             $params['onbehalf_profile'] = array(array('member_id', '=', $values['membership_id'], 0, 0));
         } elseif (!empty($values['contribution_id'])) {
             $params['onbehalf_profile'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0));
         }
     }
     //check whether it is a test drive
     if ($isTest && !empty($params['custom_pre_id'])) {
         $params['custom_pre_id'][] = array('contribution_test', '=', 1, 0, 0);
     }
     if ($isTest && !empty($params['custom_post_id'])) {
         $params['custom_post_id'][] = array('contribution_test', '=', 1, 0, 0);
     }
     if (!$returnMessageText && !empty($gIds)) {
         //send notification email if field values are set (CRM-1941)
         foreach ($gIds as $key => $gId) {
             if ($gId) {
                 $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
                 if ($email) {
                     $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array::value($key, $params), TRUE);
                     CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val);
                 }
             }
         }
     }
     if (!empty($values['is_email_receipt']) || !empty($values['onbehalf_dupe_alert']) || $returnMessageText) {
         $template = CRM_Core_Smarty::singleton();
         // get the billing location type
         if (!array_key_exists('related_contact', $values)) {
             $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
             $billingLocationTypeId = array_search('Billing', $locationTypes);
         } else {
             // presence of related contact implies onbehalf of org case,
             // where location type is set to default.
             $locType = CRM_Core_BAO_LocationType::getDefault();
             $billingLocationTypeId = $locType->id;
         }
         if (!array_key_exists('related_contact', $values)) {
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, $billingLocationTypeId);
         }
         // get primary location email if no email exist( for billing location).
         if (!$email) {
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         }
         if (empty($displayName)) {
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         }
         //for display profile need to get individual contact id,
         //hence get it from related_contact if on behalf of org true CRM-3767
         //CRM-5001 Contribution/Membership:: On Behalf of Organization,
         //If profile GROUP contain the Individual type then consider the
         //profile is of Individual ( including the custom data of membership/contribution )
         //IF Individual type not present in profile then it is consider as Organization data.
         $userID = $contactID;
         if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) {
             if (!empty($values['related_contact'])) {
                 $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID);
                 //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test
                 if (in_array('Individual', $preProfileTypes) || in_array('Contact', $postProfileTypes)) {
                     //Take Individual contact ID
                     $userID = CRM_Utils_Array::value('related_contact', $values);
                 }
             }
             self::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']);
         }
         $userID = $contactID;
         if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) {
             if (!empty($values['related_contact'])) {
                 $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID);
                 if (in_array('Individual', $postProfileTypes) || in_array('Contact', $postProfileTypes)) {
                     //Take Individual contact ID
                     $userID = CRM_Utils_Array::value('related_contact', $values);
                 }
             }
             self::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']);
         }
         if (isset($values['honor'])) {
             $honorValues = $values['honor'];
             CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($template, $honorValues['honor_profile_values'], $honorValues['honor_profile_id'], $honorValues['honor_id']);
         }
         $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']);
         // set email in the template here
         $tplParams = array('email' => $email, 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), 'contactID' => $contactID, 'displayName' => $displayName, 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), 'lineItem' => CRM_Utils_Array::value('lineItem', $values), 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), 'title' => $title, 'isShare' => CRM_Utils_Array::value('is_share', $values), 'thankyou_title' => CRM_Utils_Array::value('thankyou_title', $values));
         if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) {
             $tplParams['contributionTypeId'] = $contributionTypeId;
             $tplParams['contributionTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionTypeId);
         }
         if ($contributionPageId = CRM_Utils_Array::value('id', $values)) {
             $tplParams['contributionPageId'] = $contributionPageId;
         }
         // address required during receipt processing (pdf and email receipt)
         if ($displayAddress = CRM_Utils_Array::value('address', $values)) {
             $tplParams['address'] = $displayAddress;
         }
         // CRM-6976
         $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values);
         // cc to related contacts of contributor OR the one who
         // signs up. Is used for cases like - on behalf of
         // contribution / signup ..etc
         if (array_key_exists('related_contact', $values)) {
             list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']);
             $ccMailId = "{$ccDisplayName} <{$ccEmail}>";
             //@todo - this is the only place in this function where  $values is altered - but I can't find any evidence it is used
             $values['cc_receipt'] = !empty($values['cc_receipt']) ? $values['cc_receipt'] . ',' . $ccMailId : $ccMailId;
             // reset primary-email in the template
             $tplParams['email'] = $ccEmail;
             $tplParams['onBehalfName'] = $displayName;
             $tplParams['onBehalfEmail'] = $email;
             $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $values['id']);
             $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
             $profileId = $OnBehalfProfile[0];
             $userID = $contactID;
             self::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes);
         }
         // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not
         $sendTemplateParams = array('groupName' => !empty($values['isMembership']) ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', 'valueName' => !empty($values['isMembership']) ? 'membership_online_receipt' : 'contribution_online_receipt', 'contactId' => $contactID, 'tplParams' => $tplParams, 'isTest' => $isTest, 'PDFFilename' => 'receipt.pdf');
         if ($returnMessageText) {
             list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
             return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html);
         }
         if ($values['is_email_receipt']) {
             $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>';
             $sendTemplateParams['toName'] = $displayName;
             $sendTemplateParams['toEmail'] = $email;
             $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values);
             $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values);
             //send email with pdf invoice
             $template = CRM_Core_Smarty::singleton();
             $taxAmt = $template->get_template_vars('dataArray');
             $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
             $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
             if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
                 $sendTemplateParams['isEmailPdf'] = TRUE;
                 $sendTemplateParams['contributionId'] = $values['contribution_id'];
             }
             list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         }
         // send duplicate alert, if dupe match found during on-behalf-of processing.
         if (!empty($values['onbehalf_dupe_alert'])) {
             $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution';
             $sendTemplateParams['valueName'] = 'contribution_dupalert';
             $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>";
             $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values);
             $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values);
             $sendTemplateParams['tplParams']['onBehalfID'] = $contactID;
             $sendTemplateParams['tplParams']['receiptMessage'] = $message;
             // fix cc and reset back to original, CRM-6976
             $sendTemplateParams['cc'] = $originalCCReceipt;
             CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         }
     }
 }
Пример #9
0
 /** 
  * Function to build the form for Additional Details. 
  * 
  * @access public 
  * @return None 
  */
 function buildAdditionalDetail(&$form)
 {
     //Additional information section
     $form->add('hidden', 'hidden_AdditionalDetail', 1);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     $this->addDateTime('thankyou_date', ts('Thank-you Sent'), false, array('formatType' => 'activityDateTime'));
     // add various amounts
     $element =& $form->add('text', 'non_deductible_amount', ts('Non-deductible Amount'), $attributes['non_deductible_amount']);
     $form->addRule('non_deductible_amount', ts('Please enter a valid amount.'), 'money');
     if ($form->_online) {
         $element->freeze();
     }
     $element =& $form->add('text', 'fee_amount', ts('Fee Amount'), $attributes['fee_amount']);
     $form->addRule('fee_amount', ts('Please enter a valid amount.'), 'money');
     if ($form->_online) {
         $element->freeze();
     }
     $element =& $form->add('text', 'net_amount', ts('Net Amount'), $attributes['net_amount']);
     $form->addRule('net_amount', ts('Please enter a valid amount.'), 'money');
     if ($form->_online) {
         $element->freeze();
     }
     $element =& $form->add('text', 'invoice_id', ts('Invoice ID'), $attributes['invoice_id']);
     if ($form->_online) {
         $element->freeze();
     } else {
         $form->addRule('invoice_id', ts('This Invoice ID already exists in the database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_id, 'invoice_id'));
     }
     $form->add('select', 'contribution_page_id', ts('Online Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage());
     $form->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60));
 }
Пример #10
0
 /**
  * Function to build profile form
  *
  * @params object  $form       form object
  * @params array   $field      array field properties
  * @params int     $mode       profile mode
  * @params int     $contactID  contact id
  *
  * @return null
  * @static
  * @access public
  */
 static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $onBehalf = FALSE, $rowNumber = NULL, $prefix = '')
 {
     $defaultValues = array();
     $fieldName = $field['name'];
     $title = $field['title'];
     $attributes = $field['attributes'];
     $rule = $field['rule'];
     $view = $field['is_view'];
     $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required'];
     $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE;
     $isShared = CRM_Utils_Array::value('is_shared', $field, 0);
     // do not display view fields in drupal registration form
     // CRM-4632
     if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
         return;
     }
     if ($onBehalf) {
         $name = "onbehalf[{$fieldName}]";
     } elseif ($contactId && !$online) {
         $name = "field[{$contactId}][{$fieldName}]";
     } elseif ($rowNumber) {
         $name = "field[{$rowNumber}][{$fieldName}]";
     } elseif (!empty($prefix)) {
         $name = $prefix . "[{$fieldName}]";
     } else {
         $name = $fieldName;
     }
     if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
         $deleteExtra = ts('Are you sure you want to delete contact image.');
         $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&amp;confirmed=1\'; else return false;"'));
         $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')));
         $form->assign('deleteURL', $deleteURL);
     }
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (substr($fieldName, 0, 14) === 'state_province') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
     } elseif (substr($fieldName, 0, 7) === 'country') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
         $config = CRM_Core_Config::singleton();
         if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
             $defaultValues[$name] = $config->defaultContactCountry;
             $form->setDefaults($defaultValues);
         }
     } elseif (substr($fieldName, 0, 6) === 'county') {
         if ($addressOptions['county']) {
             $form->add('select', $name, $title, array('' => ts('- select state -')), $required);
         }
     } elseif (substr($fieldName, 0, 9) === 'image_URL') {
         $form->add('file', $name, $title, $attributes, $required);
         $form->addUploadElement($name);
     } elseif (substr($fieldName, 0, 2) === 'im') {
         $form->add('text', $name, $title, $attributes, $required);
         if (!$contactId) {
             if ($onBehalf) {
                 if (substr($name, -1) == ']') {
                     $providerName = substr($name, 0, -1) . '-provider_id]';
                 }
                 $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
             } else {
                 $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required);
             }
             if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
                 $form->freeze($name . '-provider_id');
             }
         }
     } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
         $form->addDate($name, $title, $required, array('formatType' => 'birth'));
     } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
         $form->addDate($name, $title, $required, array('formatType' => 'custom'));
     } elseif ($field['name'] == 'membership_type') {
         list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $select = array('' => ts('- select -'));
         $sel->setOptions(array($select + $orgInfo, $types));
     } elseif ($field['name'] == 'membership_status') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
     } elseif ($fieldName === 'gender') {
         $genderOptions = array();
         $gender = CRM_Core_PseudoConstant::gender();
         foreach ($gender as $key => $var) {
             $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key);
         }
         $form->addGroup($genderOptions, $name, $title);
         if ($required) {
             $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
         }
     } elseif ($fieldName === 'individual_prefix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
     } elseif ($fieldName === 'individual_suffix') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
     } elseif ($fieldName === 'contact_sub_type') {
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]);
         if ($onBehalf) {
             $profileType = 'Organization';
         } else {
             $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
         }
         $setSubtype = FALSE;
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $setSubtype = $profileType;
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
         if ($setSubtype) {
             $subtypeList = array();
             $subtypeList[$setSubtype] = $subtypes[$setSubtype];
         } else {
             $subtypeList = $subtypes;
         }
         $sel = $form->add('select', $name, $title, $subtypeList, $required);
         $sel->setMultiple(TRUE);
     } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) {
         //add email greeting, postal greeting, addressee, CRM-4575
         $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
         $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE);
         if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) {
             $profileType = 'Individual';
         }
         if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
         }
         $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName);
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required);
         // add custom greeting element
         $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE);
     } elseif ($fieldName === 'preferred_communication_method') {
         $communicationFields = CRM_Core_PseudoConstant::pcm();
         foreach ($communicationFields as $key => $var) {
             if ($key == '') {
                 continue;
             }
             $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var);
         }
         $form->addGroup($communicationOptions, $name, $title, '<br/>');
     } elseif ($fieldName === 'preferred_mail_format') {
         $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     } elseif ($fieldName === 'preferred_language') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages());
     } elseif ($fieldName == 'external_identifier') {
         $form->add('text', $name, $title, $attributes, $required);
         $contID = $contactId;
         if (!$contID) {
             $contID = $form->get('id');
         }
         $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier'));
     } elseif ($fieldName === 'group') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name);
     } elseif ($fieldName === 'tag') {
         CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name);
     } elseif (substr($fieldName, 0, 4) === 'url-') {
         $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) {  this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') {  this.value='';} else return false")));
         $form->addRule($name, ts('Enter a valid Website.'), 'url');
         //Website type select
         if ($onBehalf) {
             if (substr($name, -1) == ']') {
                 $websiteTypeName = substr($name, 0, -1) . '-website_type_id]';
             }
             $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::websiteType());
         } else {
             $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::websiteType());
         }
         // added because note appeared as a standard text input
     } elseif ($fieldName == 'note') {
         $form->add('textarea', $name, $title, $attributes, $required);
     } elseif (substr($fieldName, 0, 6) === 'custom') {
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName);
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (substr($fieldName, 0, 14) === 'address_custom') {
         list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2);
         $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8));
         if ($customFieldID) {
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title);
         }
     } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'send_receipt') {
         $form->addElement('checkbox', $name, $title);
     } elseif ($fieldName == 'soft_credit') {
         CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_');
     } elseif ($fieldName == 'product_name') {
         list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
         $sel =& $form->addElement('hierselect', $name, $title);
         $products = array('0' => ts('- select -')) + $products;
         $sel->setOptions(array($products, $options));
     } elseif ($fieldName == 'payment_instrument') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
     } elseif ($fieldName == 'contribution_type') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
     } elseif ($fieldName == 'contribution_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required);
     } elseif ($fieldName == 'currency') {
         $form->addCurrency($name, $title, $required);
     } elseif ($fieldName == 'contribution_page_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"');
     } elseif ($fieldName == 'participant_register_date') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'activity_status_id') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required);
     } elseif ($fieldName == 'activity_engagement_level') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required);
     } elseif ($fieldName == 'activity_date_time') {
         $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
     } elseif ($fieldName == 'participant_status') {
         $cond = NULL;
         if ($online == TRUE) {
             $cond = 'visibility_id = 1';
         }
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required);
     } elseif ($fieldName == 'participant_role') {
         if (CRM_Utils_Array::value('is_multiple', $field)) {
             $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, '&nbsp', TRUE);
         } else {
             $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required);
         }
     } elseif ($fieldName == 'scholarship_type_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('scholarship_type', TRUE)));
     } elseif ($fieldName == 'applicant_status_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('applicant_status', TRUE)));
     } elseif ($fieldName == 'highschool_gpa_id') {
         $form->add('select', $name, $title, array('' => '-- Select -- ') + CRM_Core_OptionGroup::values('highschool_gpa'));
     } elseif ($fieldName == 'world_region') {
         $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required);
     } elseif ($fieldName == 'signature_html') {
         $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif ($fieldName == 'signature_text') {
         $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName));
     } elseif (substr($fieldName, -11) == 'campaign_id') {
         if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
             $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns));
             $campaign =& $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="big"');
         }
     } elseif ($fieldName == 'activity_details') {
         $form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required);
     } elseif ($fieldName == 'activity_duration') {
         $form->add('text', $fieldName, $title, $attributes, $required);
         $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     } else {
         $processed = FALSE;
         if (CRM_Core_Permission::access('Quest', FALSE)) {
             $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId);
         }
         if (!$processed) {
             if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') {
                 $form->add('advcheckbox', $name, $title, $attributes, $required);
             } else {
                 $form->add('text', $name, $title, $attributes, $required);
             }
         }
     }
     static $hiddenSubtype = FALSE;
     if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) {
         // In registration mode params are submitted via POST and we don't have any clue
         // about profile-id or the profile-type (which could be a subtype)
         // To generalize the  behavior and simplify the process,
         // lets always add the hidden
         //subtype value if there is any, and we won't have to
         // compute it while processing.
         if ($onBehalf) {
             $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']);
         } else {
             $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']);
         }
         $hiddenSubtype = TRUE;
     }
     if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) {
         $form->freeze($name);
     }
     //add the rules
     if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
         $form->addRule($name, ts('Please enter a valid amount.'), 'money');
     }
     if ($rule) {
         if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) {
             $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule);
         }
     }
 }
Пример #11
0
 /**
  * Function to actually build the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 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();
     }
 }
Пример #12
0
 /**
  * add all the elements shared between contribute search and advnaced search
  *
  * @access public
  *
  * @return void
  * @static
  */
 static function buildSearchForm(&$form)
 {
     //added contribution source
     $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source'));
     CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
     $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money');
     $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     //adding select option for curreny type -- CRM-4711
     $form->add('select', 'contribution_currency_type', ts('Currency Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::currencySymbols('name'));
     $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType());
     $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage());
     $form->add('select', 'contribution_payment_instrument_id', ts('Payment Instrument'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument());
     $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::pcPage());
     $status = array();
     $statusValues = CRM_Core_OptionGroup::values("contribution_status");
     // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue).
     unset($statusValues['5']);
     unset($statusValues['6']);
     foreach ($statusValues as $key => $val) {
         $status[] = $form->createElement('advcheckbox', $key, NULL, $val);
     }
     $form->addGroup($status, 'contribution_status_id', ts('Contribution Status'));
     // add null checkboxes for thank you and receipt
     $form->addElement('checkbox', 'contribution_thankyou_date_isnull', ts('Thank-you date not set?'));
     $form->addElement('checkbox', 'contribution_receipt_date_isnull', ts('Receipt not sent?'));
     //add fields for honor search
     $form->addElement('text', 'contribution_in_honor_of', ts("In Honor Of"));
     $form->addElement('checkbox', 'contribution_test', ts('Find Test Contributions?'));
     $form->addElement('checkbox', 'contribution_pay_later', ts('Find Pay Later Contributions?'));
     //add field for transaction ID search
     $form->addElement('text', 'contribution_transaction_id', ts("Transaction ID"));
     $form->addElement('checkbox', 'contribution_recurring', ts('Find Recurring Contributions?'));
     $form->addElement('checkbox', 'contribution_recurring_isnull', ts('Find Non Recurring Contributions?'));
     $form->addElement('text', 'contribution_check_number', ts('Check Number'));
     //add field for pcp display in roll search
     $form->addYesNo('contribution_pcp_display_in_roll', ts('Personal Campaign Page Honor Roll?'));
     // add all the custom  searchable fields
     $contribution = array('Contribution');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution);
     if ($groupDetails) {
         $form->assign('contributeGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'custom_' . $fieldId;
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
             }
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id');
     // add batch select
     $batches = CRM_Core_BAO_Batch::getBatches();
     if (!empty($batches)) {
         $form->add('select', 'contribution_batch_id', ts('Batch Name'), array('' => ts('- select -')) + $batches);
     }
     $form->assign('validCiviContribute', TRUE);
 }
Пример #13
0
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     $this->add('select', 'default_renewal_contribution_page', ts('Default Online Membership Renewal Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage());
     parent::buildQuickForm();
 }
Пример #14
0
 /**
  * Function to actually build the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 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 {
         require_once 'CRM/Contribute/PseudoConstant.php';
         $status = array_merge(array(ts('- select -')), CRM_Contribute_PseudoConstant::pcpstatus());
         $contribution_page = array_merge(array(ts('- select -')), CRM_Contribute_PseudoConstant::contributionPage());
         $this->addElement('select', 'status_id', ts('Personal Campaign Pages Status'), $status);
         $this->addElement('select', 'contibution_page_id', ts('Contribution Page'), $contribution_page);
         $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Show'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true)));
         parent::buildQuickForm();
     }
 }
Пример #15
0
 /**
  * Function to build the form
  *
  * @return None
  * @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);
         $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);
 }
Пример #16
0
 /**
  * Browse all custom data groups.
  *
  *
  * @return void
  * @access public
  * @static
  */
 function browse($action = NULL)
 {
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
     if ($this->_sortByCharacter == 1 || !empty($_POST)) {
         $this->_sortByCharacter = '';
     }
     $status = CRM_PCP_PseudoConstant::pcpstatus();
     $cpages = CRM_Contribute_PseudoConstant::contributionPage();
     $epages = CRM_Event_PseudoConstant::event();
     $pcpSummary = $params = array();
     $whereClause = NULL;
     if (!empty($_POST) || !empty($_GET['page_type'])) {
         if (CRM_Utils_Array::value('status_id', $_POST)) {
             $whereClause = ' AND cp.status_id = %1';
             $params['1'] = array($_POST['status_id'], 'Integer');
         }
         if (CRM_Utils_Array::value('page_type', $_POST)) {
             $whereClause .= ' AND cp.page_type = %2';
             $params['2'] = array($_POST['page_type'], 'String');
         } elseif (CRM_Utils_Array::value('page_type', $_GET)) {
             $whereClause .= ' AND cp.page_type = %2';
             $params['2'] = array($_GET['page_type'], 'String');
         }
         if (CRM_Utils_Array::value('page_id', $_POST)) {
             $whereClause .= ' AND cp.page_id = %4 AND cp.page_type = "contribute"';
             $params['4'] = array($_POST['page_id'], 'Integer');
         }
         if (CRM_Utils_Array::value('event_id', $_POST)) {
             $whereClause .= ' AND cp.page_id = %5 AND cp.page_type = "event"';
             $params['5'] = array($_POST['event_id'], 'Integer');
         }
         if ($whereClause) {
             $this->set('whereClause', $whereClause);
             $this->set('params', $params);
         } else {
             $this->set('whereClause', NULL);
             $this->set('params', NULL);
         }
     }
     $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name');
     //check for delete CRM-4418
     $allowToDelete = CRM_Core_Permission::check('delete in CiviContribute');
     // get all contribution pages
     $query = "SELECT id, title, start_date, end_date FROM civicrm_contribution_page WHERE (1)";
     $cpages = CRM_Core_DAO::executeQuery($query);
     while ($cpages->fetch()) {
         $pages['contribute'][$cpages->id]['id'] = $cpages->id;
         $pages['contribute'][$cpages->id]['title'] = $cpages->title;
         $pages['contribute'][$cpages->id]['start_date'] = $cpages->start_date;
         $pages['contribute'][$cpages->id]['end_date'] = $cpages->end_date;
     }
     // get all event pages. pcp campaign start and end dates for event related pcp's use the online registration start and end dates,
     // altho if target is contribution page this might not be correct. fixme? dgg
     $query = "SELECT id, title, start_date, end_date, registration_start_date, registration_end_date \n                  FROM civicrm_event \n                  WHERE is_template IS NULL OR is_template != 1";
     $epages = CRM_Core_DAO::executeQuery($query);
     while ($epages->fetch()) {
         $pages['event'][$epages->id]['id'] = $epages->id;
         $pages['event'][$epages->id]['title'] = $epages->title;
         $pages['event'][$epages->id]['start_date'] = $epages->registration_start_date;
         $pages['event'][$epages->id]['end_date'] = $epages->registration_end_date;
     }
     $params = $this->get('params') ? $this->get('params') : array();
     $title = '1';
     if ($this->_sortByCharacter !== NULL) {
         $clauses[] = "cp.title LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'";
     }
     $query = "\n        SELECT cp.id, cp.contact_id , cp.status_id, cp.title, cp.is_active, cp.page_type, cp.page_id\n        FROM civicrm_pcp cp\n        WHERE {$title}" . $this->get('whereClause') . " ORDER BY cp.status_id";
     $pcp = CRM_Core_DAO::executeQuery($query, $params);
     while ($pcp->fetch()) {
         $action = array_sum(array_keys($this->links()));
         $contact = CRM_Contact_BAO_Contact::getDisplayAndImage($pcp->contact_id);
         $class = '';
         if ($pcp->status_id != $approvedId || $pcp->is_active != 1) {
             $class = 'disabled';
         }
         switch ($pcp->status_id) {
             case 2:
                 $action -= CRM_Core_Action::RENEW;
                 break;
             case 3:
                 $action -= CRM_Core_Action::REVERT;
                 break;
         }
         switch ($pcp->is_active) {
             case 1:
                 $action -= CRM_Core_Action::ENABLE;
                 break;
             case 0:
                 $action -= CRM_Core_Action::DISABLE;
                 break;
         }
         if (!$allowToDelete) {
             $action -= CRM_Core_Action::DELETE;
         }
         $page_type = $pcp->page_type;
         $page_id = (int) $pcp->page_id;
         if ($pages[$page_type][$page_id]['title'] == '' || $pages[$page_type][$page_id]['title'] == NULL) {
             $title = '(no title found for ' . $page_type . ' id ' . $page_id . ')';
         } else {
             $title = $pages[$page_type][$page_id]['title'];
         }
         if ($pcp->page_type == 'contribute') {
             $pageUrl = CRM_Utils_System::url('civicrm/' . $page_type . '/transact', 'reset=1&id=' . $pcp->page_id);
         } else {
             $pageUrl = CRM_Utils_System::url('civicrm/' . $page_type . '/register', 'reset=1&id=' . $pcp->page_id);
         }
         $pcpSummary[$pcp->id] = array('id' => $pcp->id, 'start_date' => $pages[$page_type][$page_id]['start_date'], 'end_date' => $pages[$page_type][$page_id]['end_date'], 'supporter' => $contact['0'], 'supporter_id' => $pcp->contact_id, 'status_id' => $status[$pcp->status_id], 'page_id' => $page_id, 'page_title' => $title, 'page_url' => $pageUrl, 'page_type' => $page_type, 'action' => CRM_Core_Action::formLink(self::links(), $action, array('id' => $pcp->id)), 'title' => $pcp->title, 'class' => $class);
     }
     $this->search();
     $this->pagerAToZ($this->get('whereClause'), $params);
     $this->assign('rows', $pcpSummary);
     // Let template know if user has run a search or not
     if ($this->get('whereClause')) {
         $this->assign('isSearch', 1);
     } else {
         $this->assign('isSearch', 0);
     }
 }
Пример #17
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_context == 'standalone') {
         require_once 'CRM/Contact/Form/NewContact.php';
         CRM_Contact_Form_NewContact::buildQuickForm($this);
     }
     $showAdditionalInfo = false;
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
     //fix to load honoree pane on edit.
     $defaults = array();
     if ($this->_honorID) {
         $defaults['hidden_Honoree'] = 1;
     }
     $paneNames = array('Honoree Information' => 'Honoree', 'Payment Reminders' => 'PaymentReminders');
     foreach ($paneNames as $name => $type) {
         $urlParams = "snippet=4&formType={$type}";
         $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/view/pledge', $urlParams), 'open' => 'false', 'id' => $type);
         //see if we need to include this paneName in the current form
         if ($this->_formType == $type || CRM_Utils_Array::value("hidden_{$type}", $_POST) || CRM_Utils_Array::value("hidden_{$type}", $defaults)) {
             $showAdditionalInfo = true;
             $allPanes[$name]['open'] = 'true';
         }
         eval('CRM_Contribute_Form_AdditionalInfo::build' . $type . '( $this );');
     }
     $this->assign('allPanes', $allPanes);
     $this->assign('showAdditionalInfo', $showAdditionalInfo);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     //pledge fields.
     $attributes = CRM_Core_DAO::getAttribute('CRM_Pledge_DAO_Pledge');
     $this->assign('isPending', $this->_isPending);
     $js = array('onblur' => "calculatedPaymentAmount( );", 'onkeyup' => "calculatedPaymentAmount( );");
     $element =& $this->add('text', 'amount', ts('Total Pledge Amount'), array_merge($attributes['pledge_amount'], $js), true);
     $this->addRule('amount', ts('Please enter a valid monetary amount.'), 'money');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'installments', ts('To be paid in'), array_merge($attributes['installments'], $js), true);
     $this->addRule('installments', ts('Please enter a valid number of installments.'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'frequency_interval', ts('every'), $attributes['frequency_interval'], true);
     $this->addRule('frequency_interval', ts('Please enter a number for frequency (e.g. every "3" months).'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     // Fix frequency unit display for use with frequency_interval
     $freqUnitsDisplay = array();
     foreach ($this->_freqUnits as $val => $label) {
         $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $val));
     }
     $element =& $this->add('select', 'frequency_unit', ts('Frequency'), array('' => ts('- select -')) + $freqUnitsDisplay, true);
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'frequency_day', ts('Payments are due on the'), $attributes['frequency_day'], true);
     $this->addRule('frequency_day', ts('Please enter a valid payment due day.'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $this->add('text', 'eachPaymentAmount', ts('each'), array('size' => 10, 'style' => "background-color:#EBECE4", 'READONLY'));
     //add various dates
     if (!$this->_id || $this->_isPending) {
         $this->addDate('create_date', ts('Pledge Made'));
         $this->addDate('start_date', ts('Payments Start'));
     }
     if ($this->_id && !$this->_isPending) {
         $eachPaymentAmount = floor($this->_values['amount'] / $this->_values['installments']);
         $this->assign("eachPaymentAmount", $eachPaymentAmount);
         $this->assign("hideCalender", true);
     }
     if (CRM_Utils_Array::value('status_id', $this->_values) != array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus())) {
         $this->addElement('checkbox', 'is_acknowledge', ts('Send Acknowledgment?'), null, array('onclick' => "return showHideByValue('is_acknowledge','','acknowledgeDate','table-row','radio',true);"));
     }
     $this->addDate('acknowledge_date', ts('Acknowledgment Date'));
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), true);
     $pageIds = array();
     CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgeBlock', 'entity_table', 'civicrm_contribution_page', $pageIds, array('entity_id'));
     $pages = CRM_Contribute_PseudoConstant::contributionPage();
     $pledgePages = array();
     foreach ($pageIds as $key => $value) {
         $pledgePages[$value['entity_id']] = $pages[$value['entity_id']];
     }
     $ele = $this->add('select', 'contribution_page_id', ts('Self-service Payments Page'), array('' => ts('- select -')) + $pledgePages);
     require_once "CRM/Core/BAO/Preferences.php";
     $mailingInfo =& CRM_Core_BAO_Preferences::mailingPreferences();
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     //build custom data
     CRM_Custom_Form_Customdata::buildQuickForm($this);
     // make this form an upload since we dont know if the custom data injected dynamically
     // is of type file etc $uploadNames = $this->get( 'uploadNames' );
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => array('onclick' => "return verify( );"), 'isDefault' => true), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => array('onclick' => "return verify( );"), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Pledge_Form_Pledge', 'formRule'), $this);
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $id = $this->get('id');
     $values = $ids = array();
     $params = array('id' => $id);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
     $softParams = array('contribution_id' => $values['contribution_id']);
     if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams, TRUE)) {
         $values = array_merge($values, $softContribution);
     }
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
     if (CRM_Utils_Array::value('contribution_page_id', $values)) {
         $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE);
         $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages);
     }
     if (CRM_Utils_Array::value('honor_contact_id', $values)) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = %1";
         $params = array(1 => array($values['honor_contact_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values['honor_display'] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::honor();
         $values['honor_type'] = CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $values), $honor);
     }
     if (CRM_Utils_Array::value('contribution_recur_id', $values)) {
         $sql = "SELECT  installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
         $params = array(1 => array($values['contribution_recur_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $values['recur_installments'] = $dao->installments;
             $values['recur_frequency_unit'] = $dao->frequency_unit;
             $values['recur_frequency_interval'] = $dao->frequency_interval;
         }
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, $values['contribution_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $premiumId = NULL;
     if ($id) {
         $dao = new CRM_Contribute_DAO_ContributionProduct();
         $dao->contribution_id = $id;
         if ($dao->find(TRUE)) {
             $premiumId = $dao->id;
             $productID = $dao->product_id;
         }
     }
     if ($premiumId) {
         $productDAO = new CRM_Contribute_DAO_Product();
         $productDAO->id = $productID;
         $productDAO->find(TRUE);
         $this->assign('premium', $productDAO->name);
         $this->assign('option', $dao->product_option);
         $this->assign('fulfilled', $dao->fulfilled_date);
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote($values['id'], 'civicrm_contribution');
     $values['note'] = array_values($noteValue);
     // show billing address location details, if exists
     if (CRM_Utils_Array::value('address_id', $values)) {
         $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values));
         $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
         $addressDetails = array_values($addressDetails);
         $values['billing_address'] = $addressDetails[0]['display'];
     }
     //get soft credit record if exists.
     if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams)) {
         $softContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softContribution['soft_credit_to'], 'display_name');
         //hack to avoid dispalyName conflict
         //for viewing softcredit record.
         $softContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $values = array_merge($values, $softContribution);
     }
     $lineItems = array();
     if ($id) {
         $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1);
         empty($lineItem) ? null : ($lineItems[] = $lineItem);
     }
     $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems);
     $values['totalAmount'] = $values['total_amount'];
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     // assign values to the template
     $this->assign($values);
     // add viewed contribution to recent items list
     $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['contribution_type'] . ')';
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], NULL, $recentOther);
 }
Пример #19
0
 /**
  * @param $table
  *
  * @return array
  */
 public function titlesAndValuesForTable($table)
 {
     // static caches for subsequent calls with the same $table
     static $titles = array();
     static $values = array();
     // FIXME: split off the table → DAO mapping to a GenCode-generated class
     static $daos = array('civicrm_address' => 'CRM_Core_DAO_Address', 'civicrm_contact' => 'CRM_Contact_DAO_Contact', 'civicrm_email' => 'CRM_Core_DAO_Email', 'civicrm_im' => 'CRM_Core_DAO_IM', 'civicrm_openid' => 'CRM_Core_DAO_OpenID', 'civicrm_phone' => 'CRM_Core_DAO_Phone', 'civicrm_website' => 'CRM_Core_DAO_Website', 'civicrm_contribution' => 'CRM_Contribute_DAO_Contribution', 'civicrm_note' => 'CRM_Core_DAO_Note', 'civicrm_relationship' => 'CRM_Contact_DAO_Relationship', 'civicrm_activity' => 'CRM_Activity_DAO_Activity', 'civicrm_case' => 'CRM_Case_DAO_Case');
     if (!isset($titles[$table]) or !isset($values[$table])) {
         if (in_array($table, array_keys($daos))) {
             // FIXME: these should be populated with pseudo constants as they
             // were at the time of logging rather than their current values
             // FIXME: Use *_BAO:buildOptions() method rather than pseudoconstants & fetch programmatically
             $values[$table] = array('contribution_page_id' => CRM_Contribute_PseudoConstant::contributionPage(), 'contribution_status_id' => CRM_Contribute_PseudoConstant::contributionStatus(), 'financial_type_id' => CRM_Contribute_PseudoConstant::financialType(), 'country_id' => CRM_Core_PseudoConstant::country(), 'gender_id' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), 'location_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'payment_instrument_id' => CRM_Contribute_PseudoConstant::paymentInstrument(), 'phone_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), 'preferred_communication_method' => CRM_Contact_BAO_Contact::buildOptions('preferred_communication_method'), 'preferred_language' => CRM_Contact_BAO_Contact::buildOptions('preferred_language'), 'prefix_id' => CRM_Contact_BAO_Contact::buildOptions('prefix_id'), 'provider_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), 'state_province_id' => CRM_Core_PseudoConstant::stateProvince(), 'suffix_id' => CRM_Contact_BAO_Contact::buildOptions('suffix_id'), 'website_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'), 'activity_type_id' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE), 'case_type_id' => CRM_Case_PseudoConstant::caseType('title', FALSE), 'priority_id' => CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'));
             // for columns that appear in more than 1 table
             switch ($table) {
                 case 'civicrm_case':
                     $values[$table]['status_id'] = CRM_Case_PseudoConstant::caseStatus('label', FALSE);
                     break;
                 case 'civicrm_activity':
                     $values[$table]['status_id'] = CRM_Core_PseudoConstant::activityStatus();
                     break;
             }
             $dao = new $daos[$table]();
             foreach ($dao->fields() as $field) {
                 $titles[$table][$field['name']] = CRM_Utils_Array::value('title', $field);
                 if ($field['type'] == CRM_Utils_Type::T_BOOLEAN) {
                     $values[$table][$field['name']] = array('0' => ts('false'), '1' => ts('true'));
                 }
             }
         } elseif (substr($table, 0, 14) == 'civicrm_value_') {
             list($titles[$table], $values[$table]) = $this->titlesAndValuesForCustomDataTable($table);
         } else {
             $titles[$table] = $values[$table] = array();
         }
     }
     return array($titles[$table], $values[$table]);
 }
Пример #20
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Contribute/BAO/PCP.php';
     $id = CRM_Contribute_BAO_PCP::getSupporterProfileId($this->_pageId);
     if (CRM_Contribute_BAO_PCP::checkEmailProfile($id)) {
         $this->assign('profileDisplay', true);
     }
     $fields = null;
     require_once "CRM/Core/BAO/UFGroup.php";
     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_Contribute_Form_PCP_PCPAccount', 'formRule'), $this);
     } else {
         require_once 'CRM/Core/BAO/CMSUser.php';
         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;
             }
             require_once "CRM/Core/BAO/UFGroup.php";
             require_once "CRM/Profile/Form.php";
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $this->_fields[$key] = $field;
             if ($field['add_captcha']) {
                 $addCaptcha = true;
             }
         }
         if ($addCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
     require_once "CRM/Contribute/PseudoConstant.php";
     $this->assign('campaignName', CRM_Contribute_PseudoConstant::contributionPage($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_Contribute_Form_PCP_PCPAccount', 'formRule'), $this);
     $this->addButtons($button);
 }
Пример #21
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $showAdditionalInfo = FALSE;
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
     $defaults = array();
     $paneNames = array('Payment Reminders' => 'PaymentReminders');
     foreach ($paneNames as $name => $type) {
         $urlParams = "snippet=4&formType={$type}";
         $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/view/pledge', $urlParams), 'open' => 'false', 'id' => $type);
         // see if we need to include this paneName in the current form
         if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) || CRM_Utils_Array::value("hidden_{$type}", $defaults)) {
             $showAdditionalInfo = TRUE;
             $allPanes[$name]['open'] = 'true';
         }
         $fnName = "build{$type}";
         CRM_Contribute_Form_AdditionalInfo::$fnName($this);
     }
     $this->assign('allPanes', $allPanes);
     $this->assign('showAdditionalInfo', $showAdditionalInfo);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     // pledge fields.
     $attributes = CRM_Core_DAO::getAttribute('CRM_Pledge_DAO_Pledge');
     $this->assign('isPending', $this->_isPending);
     $js = array('onblur' => "calculatedPaymentAmount( );", 'onkeyup' => "calculatedPaymentAmount( );");
     $currencyFreeze = FALSE;
     if ($this->_id && !$this->_isPending) {
         $currencyFreeze = TRUE;
     }
     $element = $this->addMoney('amount', ts('Total Pledge Amount'), TRUE, array_merge($attributes['pledge_amount'], $js), TRUE, 'currency', NULL, $currencyFreeze);
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'installments', ts('To be paid in'), array_merge($attributes['installments'], $js), TRUE);
     $this->addRule('installments', ts('Please enter a valid number of installments.'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'frequency_interval', ts('every'), $attributes['pledge_frequency_interval'], TRUE);
     $this->addRule('frequency_interval', ts('Please enter a number for frequency (e.g. every "3" months).'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     // Fix frequency unit display for use with frequency_interval
     $freqUnitsDisplay = array();
     foreach ($this->_freqUnits as $val => $label) {
         $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
     }
     $element =& $this->add('select', 'frequency_unit', ts('Frequency'), array('' => ts('- select -')) + $freqUnitsDisplay, TRUE);
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $element =& $this->add('text', 'frequency_day', ts('Payments are due on the'), $attributes['frequency_day'], TRUE);
     $this->addRule('frequency_day', ts('Please enter a valid payment due day.'), 'positiveInteger');
     if ($this->_id && !$this->_isPending) {
         $element->freeze();
     }
     $this->add('text', 'eachPaymentAmount', ts('each'), array('size' => 10, 'style' => "background-color:#EBECE4", 0 => 'READONLY'));
     // add various dates
     if (!$this->_id || $this->_isPending) {
         $this->addDate('create_date', ts('Pledge Made'), TRUE);
         $this->addDate('start_date', ts('Payments Start'), TRUE);
     }
     if ($this->_id && !$this->_isPending) {
         $eachPaymentAmount = $this->_values['original_installment_amount'];
         $this->assign('currency', $this->_values['currency']);
         $this->assign('eachPaymentAmount', $eachPaymentAmount);
         $this->assign('hideCalender', TRUE);
     }
     if (CRM_Utils_Array::value('status_id', $this->_values) != array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) {
         $this->addElement('checkbox', 'is_acknowledge', ts('Send Acknowledgment?'), NULL, array('onclick' => "showHideByValue( 'is_acknowledge', '', 'acknowledgeDate', 'table-row', 'radio', true); showHideByValue( 'is_acknowledge', '', 'fromEmail', 'table-row', 'radio', false );"));
         $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     }
     $this->addDate('acknowledge_date', ts('Acknowledgment Date'));
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), TRUE);
     // CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     $pageIds = array();
     CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgeBlock', 'entity_table', 'civicrm_contribution_page', $pageIds, array('entity_id'));
     $pages = CRM_Contribute_PseudoConstant::contributionPage();
     $pledgePages = array();
     foreach ($pageIds as $key => $value) {
         $pledgePages[$value['entity_id']] = $pages[$value['entity_id']];
     }
     $ele = $this->add('select', 'contribution_page_id', ts('Self-service Payments Page'), array('' => ts('- select -')) + $pledgePages);
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     // build custom data
     CRM_Custom_Form_CustomData::buildQuickForm($this);
     // make this form an upload since we dont know if the custom data injected dynamically
     // is of type file etc $uploadNames = $this->get( 'uploadNames' );
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => array('onclick' => "return verify( );"), 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => array('onclick' => "return verify( );"), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Pledge_Form_Pledge', 'formRule'), $this);
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Пример #22
0
 static function buildSearchForm(&$form)
 {
     // pledge related dates
     $form->addDate('pledge_start_date_low', ts('Payments Start Date - From'), false, array('formatType' => 'relative'));
     $form->addDate('pledge_start_date_high', ts('To'), false, array('formatType' => 'relative'));
     $form->addDate('pledge_end_date_low', ts('Payments Ended Date - From'), false, array('formatType' => 'relative'));
     $form->addDate('pledge_end_date_high', ts('To'), false, array('formatType' => 'relative'));
     $form->addDate('pledge_create_date_low', ts('Pledge Made - From'), false, array('formatType' => 'relative'));
     $form->addDate('pledge_create_date_high', ts('To'), false, array('formatType' => 'relative'));
     // pledge payment related dates
     $form->addDate('pledge_payment_date_low', ts('Payment Scheduled - From'), false, array('formatType' => 'relative'));
     $form->addDate('pledge_payment_date_high', ts('To'), false, array('formatType' => 'relative'));
     $form->addElement('checkbox', 'pledge_test', ts('Find Test Pledges?'));
     require_once 'CRM/Utils/Money.php';
     $form->add('text', 'pledge_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money');
     $form->add('text', 'pledge_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     require_once 'CRM/Contribute/PseudoConstant.php';
     $statusValues = CRM_Contribute_PseudoConstant::contributionStatus();
     // Remove status values that are only used for recurring contributions for now (Failed and In Progress).
     unset($statusValues['4']);
     foreach ($statusValues as $key => $val) {
         $status[] = $form->createElement('advcheckbox', $key, null, $val);
     }
     $form->addGroup($status, 'pledge_status_id', ts('Pledge Status'));
     //unset in progress for payment
     unset($statusValues['5']);
     foreach ($statusValues as $key => $val) {
         $paymentStatus[] = $form->createElement('advcheckbox', $key, null, $val);
     }
     $form->addGroup($paymentStatus, 'pledge_payment_status_id', ts('Pledge Payment Status'));
     require_once 'CRM/Contribute/PseudoConstant.php';
     $form->add('select', 'pledge_contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType());
     $form->add('select', 'pledge_contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage());
     //add fields for honor search
     $form->addElement('text', 'pledge_in_honor_of', ts("In Honor Of"));
     // add all the custom  searchable fields
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $pledge = array('Pledge');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $pledge);
     if ($groupDetails) {
         require_once 'CRM/Core/BAO/CustomField.php';
         $form->assign('pledgeGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'custom_' . $fieldId;
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true);
             }
         }
     }
     $form->assign('validCiviPledge', true);
 }
Пример #23
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $id = $this->get('id');
     $values = $ids = array();
     $params = array('id' => $id);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
     $cancelledStatus = TRUE;
     $status = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if (CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Cancelled', $status)) {
         $cancelledStatus = FALSE;
     }
     $this->assign('cancelledStatus', $cancelledStatus);
     if (!empty($values['contribution_page_id'])) {
         $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE);
         $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages);
     }
     // get recieved into i.e to_financial_account_id from last trxn
     $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC');
     $values['to_financial_account'] = '';
     if (!empty($financialTrxnId['financialTrxnId'])) {
         $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
         if ($values['to_financial_account_id']) {
             $values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']);
         }
         $values['payment_processor_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id');
         if ($values['payment_processor_id']) {
             $values['payment_processor_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
         }
     }
     if (!empty($values['contribution_recur_id'])) {
         $sql = "SELECT  installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
         $params = array(1 => array($values['contribution_recur_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $values['recur_installments'] = $dao->installments;
             $values['recur_frequency_unit'] = $dao->frequency_unit;
             $values['recur_frequency_interval'] = $dao->frequency_interval;
         }
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values));
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $premiumId = NULL;
     if ($id) {
         $dao = new CRM_Contribute_DAO_ContributionProduct();
         $dao->contribution_id = $id;
         if ($dao->find(TRUE)) {
             $premiumId = $dao->id;
             $productID = $dao->product_id;
         }
     }
     if ($premiumId) {
         $productDAO = new CRM_Contribute_DAO_Product();
         $productDAO->id = $productID;
         $productDAO->find(TRUE);
         $this->assign('premium', $productDAO->name);
         $this->assign('option', $dao->product_option);
         $this->assign('fulfilled', $dao->fulfilled_date);
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution');
     $values['note'] = array_values($noteValue);
     // show billing address location details, if exists
     if (!empty($values['address_id'])) {
         $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values));
         $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
         $addressDetails = array_values($addressDetails);
         $values['billing_address'] = $addressDetails[0]['display'];
     }
     //assign soft credit record if exists.
     $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE);
     if (!empty($SCRecords['soft_credit'])) {
         $this->assign('softContributions', $SCRecords['soft_credit']);
         unset($SCRecords['soft_credit']);
     }
     //assign pcp record if exists
     foreach ($SCRecords as $name => $value) {
         $this->assign($name, $value);
     }
     $lineItems = array();
     if ($id) {
         $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1, TRUE, TRUE);
         if (!empty($lineItem)) {
             $lineItems[] = $lineItem;
         }
     }
     $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems);
     $values['totalAmount'] = $values['total_amount'];
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     // assign values to the template
     $this->assign($values);
     $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $this->assign('invoicing', $invoicing);
     if ($invoicing && isset($values['tax_amount'])) {
         $this->assign('totalTaxAmount', $values['tax_amount']);
     }
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     // Check if this is default domain contact CRM-10482
     if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
         $displayName .= ' (' . ts('default organization') . ')';
     }
     // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
     CRM_Utils_System::setTitle(ts('View Contribution from') . ' ' . $displayName);
     // add viewed contribution to recent items list
     $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')';
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], NULL, $recentOther);
 }
Пример #24
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     $session = CRM_Core_Session::singleton();
     $config = CRM_Core_Config::singleton();
     $permissionCheck = FALSE;
     $statusMessage = '';
     if ($config->userFramework != 'Joomla') {
         $permissionCheck = CRM_Core_Permission::check('administer CiviCRM');
     }
     //get the pcp id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     $prms = array('id' => $this->_id);
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
     $this->_component = $pcpInfo['page_type'];
     if (empty($pcpInfo)) {
         $statusMessage = ts('The personal campaign page you requested is currently unavailable.');
         CRM_Core_Error::statusBounce($statusMessage, $config->userFrameworkBaseURL);
     }
     CRM_Utils_System::setTitle($pcpInfo['title']);
     $this->assign('pcp', $pcpInfo);
     $pcpStatus = CRM_Core_OptionGroup::values("pcp_status");
     $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name');
     // check if PCP is created by anonymous user
     $anonymousPCP = CRM_Utils_Request::retrieve('ap', 'Boolean', $this);
     if ($anonymousPCP) {
         $loginURL = $config->userSystem->getLoginURL();
         $anonMessage = ts('Once you\'ve received your new account welcome email, you can <a href=%1>click here</a> to login and promote your campaign page.', array(1 => $loginURL));
         CRM_Core_Session::setStatus($anonMessage, ts('Success'), 'success');
     } else {
         $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.');
     }
     $pcpBlock = new CRM_PCP_DAO_PCPBlock();
     $pcpBlock->entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($pcpInfo['page_type']);
     $pcpBlock->entity_id = $pcpInfo['page_id'];
     $pcpBlock->find(TRUE);
     // Redirect back to source page in case of error.
     if ($pcpInfo['page_type'] == 'contribute') {
         $urlBase = 'civicrm/contribute/transact';
     } elseif ($pcpInfo['page_type'] == 'event') {
         $urlBase = 'civicrm/event/register';
     }
     if ($pcpInfo['status_id'] != $approvedId || !$pcpInfo['is_active']) {
         if ($pcpInfo['contact_id'] != $session->get('userID') && !$permissionCheck) {
             CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase, "reset=1&id=" . $pcpInfo['page_id'], FALSE, NULL, FALSE, TRUE));
         }
     } else {
         $getStatus = CRM_PCP_BAO_PCP::getStatus($this->_id, $this->_component);
         if (!$getStatus) {
             // PCP not enabled for this contribution page. Forward everyone to source page
             CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase, "reset=1&id=" . $pcpInfo['page_id'], FALSE, NULL, FALSE, TRUE));
         }
     }
     $default = array();
     if ($pcpBlock->target_entity_type == 'contribute') {
         $urlBase = 'civicrm/contribute/transact';
     } elseif ($pcpBlock->target_entity_type == 'event') {
         $urlBase = 'civicrm/event/register';
     }
     if ($pcpBlock->entity_table == 'civicrm_event') {
         $page_class = 'CRM_Event_DAO_Event';
         $this->assign('pageName', CRM_Event_PseudoConstant::event($pcpInfo['page_id']));
         CRM_Core_DAO::commonRetrieveAll($page_class, 'id', $pcpInfo['page_id'], $default, array('start_date', 'end_date', 'registration_start_date', 'registration_end_date'));
     } elseif ($pcpBlock->entity_table == 'civicrm_contribution_page') {
         $page_class = 'CRM_Contribute_DAO_ContributionPage';
         $this->assign('pageName', CRM_Contribute_PseudoConstant::contributionPage($pcpInfo['page_id'], TRUE));
         CRM_Core_DAO::commonRetrieveAll($page_class, 'id', $pcpInfo['page_id'], $default, array('start_date', 'end_date'));
     }
     $pageInfo = $default[$pcpInfo['page_id']];
     if ($pcpInfo['contact_id'] == $session->get('userID')) {
         $owner = $pageInfo;
         $owner['status'] = CRM_Utils_Array::value($pcpInfo['status_id'], $pcpStatus);
         $this->assign('owner', $owner);
         $link = CRM_PCP_BAO_PCP::pcpLinks();
         $hints = array(CRM_Core_Action::UPDATE => ts('Change the content and appearance of your page'), CRM_Core_Action::DETACH => ts('Send emails inviting your friends to support your campaign!'), CRM_Core_Action::VIEW => ts('Copy this link to share directly with your network!'), CRM_Core_Action::BROWSE => ts('Update your personal contact information'), CRM_Core_Action::DISABLE => ts('De-activate the page (you can re-activate it later)'), CRM_Core_Action::ENABLE => ts('Activate the page (you can de-activate it later)'), CRM_Core_Action::DELETE => ts('Remove the page (this cannot be undone!)'));
         $replace = array('id' => $this->_id, 'block' => $pcpBlock->id, 'pageComponent' => $this->_component);
         if (!$pcpBlock->is_tellfriend_enabled || CRM_Utils_Array::value('status_id', $pcpInfo) != $approvedId) {
             unset($link['all'][CRM_Core_Action::DETACH]);
         }
         switch ($pcpInfo['is_active']) {
             case 1:
                 unset($link['all'][CRM_Core_Action::ENABLE]);
                 break;
             case 0:
                 unset($link['all'][CRM_Core_Action::DISABLE]);
                 break;
         }
         $this->assign('links', $link['all']);
         $this->assign('hints', $hints);
         $this->assign('replace', $replace);
     }
     $honor = CRM_PCP_BAO_PCP::honorRoll($this->_id);
     $entityFile = CRM_Core_BAO_File::getEntityFile('civicrm_pcp', $this->_id);
     if (!empty($entityFile)) {
         $fileInfo = reset($entityFile);
         $fileId = $fileInfo['fileID'];
         $image = '<img src="' . CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$this->_id}") . '" />';
         $this->assign('image', $image);
     }
     $totalAmount = CRM_PCP_BAO_PCP::thermoMeter($this->_id);
     $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2);
     if ($pcpBlock->is_active == 1) {
         $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$pcpInfo['page_id']}&component={$pcpInfo['page_type']}", TRUE, NULL, TRUE, TRUE);
         $this->assign('linkTextUrl', $linkTextUrl);
         $this->assign('linkText', $pcpBlock->link_text);
     }
     $this->assign('honor', $honor);
     $this->assign('total', $totalAmount ? $totalAmount : '0.0');
     $this->assign('achieved', $achieved <= 100 ? $achieved : 100);
     if ($achieved <= 100) {
         $this->assign('remaining', 100 - $achieved);
     }
     // make sure that we are between contribution page start and end dates OR registration start date and end dates if they are set
     if ($pcpBlock->entity_table == 'civicrm_event') {
         $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $pageInfo));
         $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $pageInfo));
     } else {
         $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $pageInfo));
         $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $pageInfo));
     }
     $now = time();
     $validDate = TRUE;
     if ($startDate && $startDate >= $now) {
         $validDate = FALSE;
     }
     if ($endDate && $endDate < $now) {
         $validDate = FALSE;
     }
     $this->assign('validDate', $validDate);
     // form parent page url
     if ($action == CRM_Core_Action::PREVIEW) {
         $parentUrl = CRM_Utils_System::url($urlBase, "id={$pcpInfo['page_id']}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE);
     } else {
         $parentUrl = CRM_Utils_System::url($urlBase, "id={$pcpInfo['page_id']}&reset=1", TRUE, NULL, TRUE, TRUE);
     }
     $this->assign('parentURL', $parentUrl);
     if ($validDate) {
         $contributionText = ts('Contribute Now');
         if (!empty($pcpInfo['donate_link_text'])) {
             $contributionText = $pcpInfo['donate_link_text'];
         }
         $this->assign('contributionText', $contributionText);
         // we always generate urls for the front end in joomla
         if ($action == CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url($urlBase, "id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE);
         } else {
             $url = CRM_Utils_System::url($urlBase, "id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE);
         }
         $this->assign('contributeURL', $url);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     $single = $permission = FALSE;
     switch ($action) {
         case CRM_Core_Action::BROWSE:
             $subForm = 'PCPAccount';
             $form = "CRM_PCP_Form_{$subForm}";
             $single = TRUE;
             break;
         case CRM_Core_Action::UPDATE:
             $subForm = 'Campaign';
             $form = "CRM_PCP_Form_{$subForm}";
             $single = TRUE;
             break;
     }
     $userID = $session->get('userID');
     //make sure the user has "administer CiviCRM" permission
     //OR has created the PCP
     if (CRM_Core_Permission::check('administer CiviCRM') || $userID && CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'contact_id') == $userID) {
         $permission = TRUE;
     }
     if ($single && $permission) {
         $controller = new CRM_Core_Controller_Simple($form, $subForm, $action);
         $controller->set('id', $this->_id);
         $controller->set('single', TRUE);
         $controller->process();
         return $controller->run();
     }
     $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&id=' . $this->_id));
     parent::run();
 }
Пример #25
0
 /**
  * @param CRM_Core_Form $form
  */
 public static function buildSearchForm(&$form)
 {
     // pledge related dates
     CRM_Core_Form_Date::buildDateRange($form, 'pledge_start_date', 1, '_low', '_high', ts('From'), FALSE);
     CRM_Core_Form_Date::buildDateRange($form, 'pledge_end_date', 1, '_low', '_high', ts('From'), FALSE);
     CRM_Core_Form_Date::buildDateRange($form, 'pledge_create_date', 1, '_low', '_high', ts('From'), FALSE);
     // pledge payment related dates
     CRM_Core_Form_Date::buildDateRange($form, 'pledge_payment_date', 1, '_low', '_high', ts('From'), FALSE);
     $form->addYesNo('pledge_test', ts('Pledge is a Test?'), TRUE);
     $form->add('text', 'pledge_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money');
     $form->add('text', 'pledge_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     $statusValues = CRM_Contribute_PseudoConstant::contributionStatus();
     // Remove status values that are only used for recurring contributions for now (Failed and In Progress).
     unset($statusValues['4']);
     $form->add('select', 'pledge_status_id', ts('Pledge Status'), $statusValues, FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple'));
     //unset in progress for payment
     unset($statusValues['5']);
     $form->add('select', 'pledge_payment_status_id', ts('Pledge Payment Status'), $statusValues, FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple'));
     $form->add('select', 'pledge_financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), FALSE, array('class' => 'crm-select2'));
     $form->add('select', 'pledge_contribution_page_id', ts('Contribution Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::contributionPage(), FALSE, array('class' => 'crm-select2'));
     //add fields for pledge frequency
     $form->add('text', 'pledge_frequency_interval', ts('Every'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('pledge_frequency_interval', ts('Please enter valid Pledge Frequency Interval'), 'integer');
     $frequencies = CRM_Core_OptionGroup::values('recur_frequency_units');
     foreach ($frequencies as $val => $label) {
         $freqUnitsDisplay["'{$val}'"] = ts('%1(s)', array(1 => $label));
     }
     $form->add('select', 'pledge_frequency_unit', ts('Pledge Frequency'), array('' => ts('- any -')) + $freqUnitsDisplay);
     // add all the custom  searchable fields
     $pledge = array('Pledge');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $pledge);
     if ($groupDetails) {
         $form->assign('pledgeGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'custom_' . $fieldId;
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
             }
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'pledge_campaign_id');
     $form->assign('validCiviPledge', TRUE);
     $form->setDefaults(array('pledge_test' => 0));
 }
Пример #26
0
 /**
  * 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);
 }
Пример #27
0
 /**
  * Add all the elements shared between contribute search and advnaced search.
  *
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildSearchForm(&$form)
 {
     // Added contribution source
     $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source'));
     CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From:'), FALSE);
     $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money');
     $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     // Adding select option for curreny type -- CRM-4711
     $form->add('select', 'contribution_currency_type', ts('Currency Type'), array('' => ts('- any -')) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array('labelColumn' => 'name')), FALSE, array('class' => 'crm-select2'));
     // CRM-13848
     $form->addSelect('financial_type_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search'));
     $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::contributionPage(), FALSE, array('class' => 'crm-select2'));
     $form->addSelect('payment_instrument_id', array('entity' => 'contribution', 'label' => ts('Payment Method'), 'option_url' => NULL, 'placeholder' => ts('- any -')));
     $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::pcPage(), FALSE, array('class' => 'crm-select2'));
     $status = array();
     $statusValues = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status');
     // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue).
     unset($statusValues['5'], $statusValues['6']);
     $form->addSelect('contribution_status_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'label' => ts('Contribution Status(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -')));
     // Add fields for thank you and receipt
     $form->addYesNo('contribution_thankyou_date_is_not_null', ts('Thank-you sent?'), TRUE);
     $form->addYesNo('contribution_receipt_date_is_not_null', ts('Receipt sent?'), TRUE);
     $form->addYesNo('contribution_pay_later', ts('Contribution is Pay Later?'), TRUE);
     $form->addYesNo('contribution_recurring', ts('Contribution is Recurring?'), TRUE);
     // Recurring contribution fields
     foreach (self::getRecurringFields() as $key => $label) {
         CRM_Core_Form_Date::buildDateRange($form, $key, 1, '_low', '_high');
         // If data has been entered for a recurring field, tell the tpl layer to open the pane
         if (!empty($form->_formValues[$key . '_relative']) || !empty($form->_formValues[$key . '_low']) || !empty($form->_formValues[$key . '_high'])) {
             $form->assign('contribution_recur_pane_open', TRUE);
         }
     }
     $form->addYesNo('contribution_test', ts('Contribution is a Test?'), TRUE);
     // Add field for transaction ID search
     $form->addElement('text', 'contribution_trxn_id', ts("Transaction ID"));
     $form->addElement('text', 'contribution_check_number', ts('Check Number'));
     // Add field for pcp display in roll search
     $form->addYesNo('contribution_pcp_display_in_roll', ts('Personal Campaign Page Honor Roll?'), TRUE);
     // Soft credit related fields
     $options = array('only_contribs' => ts('Contributions Only'), 'only_scredits' => ts('Soft Credits Only'), 'both_related' => ts('Soft Credits with related Hard Credit'), 'both' => ts('Both'));
     $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, array('class' => "crm-select2"));
     $form->addSelect('contribution_soft_credit_type_id', array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, 'context' => 'search'));
     // Add all the custom searchable fields
     $contribution = array('Contribution');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution);
     if ($groupDetails) {
         $form->assign('contributeGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'custom_' . $fieldId;
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
             }
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id');
     // Add batch select
     $batches = CRM_Contribute_PseudoConstant::batch();
     if (!empty($batches)) {
         $form->add('select', 'contribution_batch_id', ts('Batch Name'), array('' => ts('- any -')) + $batches, FALSE, array('class' => 'crm-select2'));
     }
     $form->assign('validCiviContribute', TRUE);
     $form->setDefaults(array('contribution_test' => 0));
 }
Пример #28
0
 /**
  * Build the form object for Additional Details.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildAdditionalDetail(&$form)
 {
     //Additional information section
     $form->add('hidden', 'hidden_AdditionalDetail', 1);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     $form->addDateTime('thankyou_date', ts('Thank-you Sent'), FALSE, array('formatType' => 'activityDateTime'));
     // add various amounts
     $nonDeductAmount =& $form->add('text', 'non_deductible_amount', ts('Non-deductible Amount'), $attributes['non_deductible_amount']);
     $form->addRule('non_deductible_amount', ts('Please enter a valid monetary value for Non-deductible Amount.'), 'money');
     if ($form->_online) {
         $nonDeductAmount->freeze();
     }
     $feeAmount =& $form->add('text', 'fee_amount', ts('Fee Amount'), $attributes['fee_amount']);
     $form->addRule('fee_amount', ts('Please enter a valid monetary value for Fee Amount.'), 'money');
     if ($form->_online) {
         $feeAmount->freeze();
     }
     $netAmount =& $form->add('text', 'net_amount', ts('Net Amount'), $attributes['net_amount']);
     $form->addRule('net_amount', ts('Please enter a valid monetary value for Net Amount.'), 'money');
     if ($form->_online) {
         $netAmount->freeze();
     }
     $element =& $form->add('text', 'invoice_id', ts('Invoice ID'), $attributes['invoice_id']);
     if ($form->_online) {
         $element->freeze();
     } else {
         $form->addRule('invoice_id', ts('This Invoice ID already exists in the database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_id, 'invoice_id'));
     }
     $element = $form->add('text', 'creditnote_id', ts('Credit Note ID'), $attributes['creditnote_id']);
     if ($form->_online) {
         $element->freeze();
     } else {
         $form->addRule('creditnote_id', ts('This Credit Note ID already exists in the database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_id, 'creditnote_id'));
     }
     $form->add('select', 'contribution_page_id', ts('Online Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage());
     $form->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60));
     $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if ($form->_id && $form->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) {
         $netAmount->freeze();
         $feeAmount->freeze();
     }
 }
Пример #29
0
 /**
  * Return PCP  Block info for dashboard.
  *
  * @param int $contactId
  *
  * @return array
  *   array of Pcp if found
  */
 public static function getPcpDashboardInfo($contactId)
 {
     $links = self::pcpLinks();
     $query = "\nSELECT * FROM civicrm_pcp pcp\nWHERE pcp.is_active = 1\n  AND pcp.contact_id = %1\nORDER BY page_type, page_id";
     $params = array(1 => array($contactId, 'Integer'));
     $pcpInfoDao = CRM_Core_DAO::executeQuery($query, $params);
     $pcpInfo = array();
     $hide = $mask = array_sum(array_keys($links['all']));
     $contactPCPPages = array();
     $event = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
     $contribute = CRM_Contribute_PseudoConstant::contributionPage();
     $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
     $approved = CRM_Utils_Array::key('Approved', $pcpStatus);
     while ($pcpInfoDao->fetch()) {
         $mask = $hide;
         if ($links) {
             $replace = array('pcpId' => $pcpInfoDao->id, 'pcpBlock' => $pcpInfoDao->pcp_block_id, 'pageComponent' => $pcpInfoDao->page_type);
         }
         $pcpLink = $links['all'];
         $class = '';
         if ($pcpInfoDao->status_id != $approved || $pcpInfoDao->is_active != 1) {
             $class = 'disabled';
             if (!$pcpInfoDao->tellfriend) {
                 $mask -= CRM_Core_Action::DETACH;
             }
         }
         if ($pcpInfoDao->is_active == 1) {
             $mask -= CRM_Core_Action::ENABLE;
         } else {
             $mask -= CRM_Core_Action::DISABLE;
         }
         $action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'), FALSE, 'pcp.dashboard.active', 'PCP', $pcpInfoDao->id);
         $component = $pcpInfoDao->page_type;
         $pageTitle = CRM_Utils_Array::value($pcpInfoDao->page_id, ${$component});
         $pcpInfo[] = array('pageTitle' => $pageTitle, 'pcpId' => $pcpInfoDao->id, 'pcpTitle' => $pcpInfoDao->title, 'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id], 'action' => $action, 'class' => $class);
         $contactPCPPages[$pcpInfoDao->page_type][] = $pcpInfoDao->page_id;
     }
     $excludePageClause = $clause = NULL;
     if (!empty($contactPCPPages)) {
         foreach ($contactPCPPages as $component => $entityIds) {
             $excludePageClause[] = "\n( target_entity_type = '{$component}'\nAND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )";
         }
         $clause = ' AND ' . implode(' OR ', $excludePageClause);
     }
     $query = "\nSELECT *\nFROM civicrm_pcp_block block\nLEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id\nWHERE block.is_active = 1\n{$clause}\nGROUP BY block.id\nORDER BY target_entity_type, target_entity_id\n";
     $pcpBlockDao = CRM_Core_DAO::executeQuery($query);
     $pcpBlock = array();
     $mask = 0;
     while ($pcpBlockDao->fetch()) {
         if ($links) {
             $replace = array('pageId' => $pcpBlockDao->target_entity_id, 'pageComponent' => $pcpBlockDao->target_entity_type);
         }
         $pcpLink = $links['add'];
         $action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'), FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id);
         $component = $pcpBlockDao->target_entity_type;
         if ($pageTitle = CRM_Utils_Array::value($pcpBlockDao->target_entity_id, ${$component})) {
             $pcpBlock[] = array('pageId' => $pcpBlockDao->target_entity_id, 'pageTitle' => $pageTitle, 'action' => $action);
         }
     }
     return array($pcpBlock, $pcpInfo);
 }
Пример #30
0
 function titlesAndValuesForTable($table)
 {
     // static caches for subsequent calls with the same $table
     static $titles = array();
     static $values = array();
     // FIXME: split off the table → DAO mapping to a GenCode-generated class
     static $daos = array('civicrm_address' => 'CRM_Core_DAO_Address', 'civicrm_contact' => 'CRM_Contact_DAO_Contact', 'civicrm_email' => 'CRM_Core_DAO_Email', 'civicrm_im' => 'CRM_Core_DAO_IM', 'civicrm_openid' => 'CRM_Core_DAO_OpenID', 'civicrm_phone' => 'CRM_Core_DAO_Phone', 'civicrm_website' => 'CRM_Core_DAO_Website', 'civicrm_contribution' => 'CRM_Contribute_DAO_Contribution', 'civicrm_note' => 'CRM_Core_DAO_Note', 'civicrm_relationship' => 'CRM_Contact_DAO_Relationship');
     if (!isset($titles[$table]) or !isset($values[$table])) {
         if (in_array($table, array_keys($daos))) {
             // FIXME: these should be populated with pseudo constants as they
             // were at the time of logging rather than their current values
             $values[$table] = array('contribution_page_id' => CRM_Contribute_PseudoConstant::contributionPage(), 'contribution_status_id' => CRM_Contribute_PseudoConstant::contributionStatus(), 'contribution_type_id' => CRM_Contribute_PseudoConstant::contributionType(), 'country_id' => CRM_Core_PseudoConstant::country(), 'gender_id' => CRM_Core_PseudoConstant::gender(), 'location_type_id' => CRM_Core_PseudoConstant::locationType(), 'payment_instrument_id' => CRM_Contribute_PseudoConstant::paymentInstrument(), 'phone_type_id' => CRM_Core_PseudoConstant::phoneType(), 'preferred_communication_method' => CRM_Core_PseudoConstant::pcm(), 'preferred_language' => CRM_Core_PseudoConstant::languages(), 'prefix_id' => CRM_Core_PseudoConstant::individualPrefix(), 'provider_id' => CRM_Core_PseudoConstant::IMProvider(), 'state_province_id' => CRM_Core_PseudoConstant::stateProvince(), 'suffix_id' => CRM_Core_PseudoConstant::individualSuffix(), 'website_type_id' => CRM_Core_PseudoConstant::websiteType());
             require_once str_replace('_', DIRECTORY_SEPARATOR, $daos[$table]) . '.php';
             eval("\$dao = new {$daos[$table]};");
             foreach ($dao->fields() as $field) {
                 $titles[$table][$field['name']] = CRM_Utils_Array::value('title', $field);
                 if ($field['type'] == CRM_Utils_Type::T_BOOLEAN) {
                     $values[$table][$field['name']] = array('0' => ts('false'), '1' => ts('true'));
                 }
             }
         } elseif (substr($table, 0, 14) == 'civicrm_value_') {
             list($titles[$table], $values[$table]) = $this->titlesAndValuesForCustomDataTable($table);
         }
     }
     return array($titles[$table], $values[$table]);
 }