コード例 #1
0
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 static function buildQuickForm(&$form)
 {
     //Added for CRM-12682: Add activity subject and campaign fields
     CRM_Campaign_BAO_Campaign::addCampaign($form);
     $form->add('text', 'subject', ts('Activity Subject'), array('size' => 45, 'maxlength' => 255), FALSE);
     $form->add('static', 'pdf_format_header', NULL, ts('Page Format'));
     $form->add('select', 'format_id', ts('Select Format'), array(0 => ts('- default -')) + CRM_Core_BAO_PdfFormat::getList(TRUE), FALSE, array('onChange' => "selectFormat( this.value, false );"));
     $form->add('select', 'paper_size', ts('Paper Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();"));
     $form->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
     $form->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();"));
     $form->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );"));
     $form->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
     $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));
     $form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?'));
     $form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?'));
     $form->assign('totalSelectedContacts', count($form->_contactIds));
     CRM_Mailing_BAO_Mailing::commonLetterCompose($form);
     if ($form->_single) {
         $cancelURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$form->_cid}&selectedChild=activity", FALSE, NULL, FALSE);
         if ($form->get('action') == CRM_Core_Action::VIEW) {
             $form->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
         } else {
             $form->addButtons(array(array('type' => 'submit', 'name' => ts('Make PDF Letter'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Done'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
         }
     } else {
         $form->addButtons(array(array('type' => 'submit', 'name' => ts('Make PDF Letters'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Done'))));
     }
     $form->addFormRule(array('CRM_Contact_Form_Task_PDFLetterCommon', 'formRule'), $form);
 }
コード例 #2
0
 /**
  * Build the form
  *
  * @var CRM_Core_Form $form
  *
  * @return void
  */
 static function buildQuickForm(&$form)
 {
     // This form outputs a file so should never be submitted via ajax
     $form->preventAjaxSubmit();
     //Added for CRM-12682: Add activity subject and campaign fields
     CRM_Campaign_BAO_Campaign::addCampaign($form);
     $form->add('text', 'subject', ts('Activity Subject'), array('size' => 45, 'maxlength' => 255), FALSE);
     $form->add('static', 'pdf_format_header', NULL, ts('Page Format: %1', array(1 => '<span class="pdf-format-header-label"></span>')));
     $form->addSelect('format_id', array('label' => ts('Select Format'), 'placeholder' => ts('Default'), 'entity' => 'message_template', 'field' => 'pdf_format_id', 'option_url' => 'civicrm/admin/pdfFormats'));
     $form->add('select', 'paper_size', ts('Paper Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();"));
     $form->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
     $form->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();"));
     $form->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );"));
     $form->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $config = CRM_Core_Config::singleton();
     if ($config->wkhtmltopdfPath == false) {
         $form->add('text', 'stationery', ts('Stationery (relative path to PDF you wish to use as the background)'), array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"), FALSE);
     }
     $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
     $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));
     $form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?'));
     $form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?'));
     $form->assign('totalSelectedContacts', count($form->_contactIds));
     CRM_Mailing_BAO_Mailing::commonLetterCompose($form);
     $buttons = array();
     if ($form->get('action') != CRM_Core_Action::VIEW) {
         $buttons[] = array('type' => 'submit', 'name' => $form->_single ? ts('Make PDF') : ts('Make PDFs'), 'isDefault' => TRUE);
     }
     $buttons[] = array('type' => 'cancel', 'name' => $form->get('action') == CRM_Core_Action::VIEW ? ts('Done') : ts('Cancel'));
     $form->addButtons($buttons);
     $form->addFormRule(array('CRM_Contact_Form_Task_PDFLetterCommon', 'formRule'), $form);
 }
コード例 #3
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();
     }
 }
コード例 #4
0
ファイル: Participant.php プロジェクト: hguru/224Civi
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1;
             if ($additionalParticipant) {
                 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.'));
                 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
                 $this->setDefaults(array('delete_participant' => 1));
                 $this->assign('additionalParticipant', $additionalParticipant);
             }
         }
         $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->_single) {
         $urlPath = 'civicrm/contact/view/participant';
         $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
         if ($this->_context == 'standalone') {
             CRM_Contact_Form_NewContact::buildQuickForm($this);
             $urlParams = 'reset=1&context=standalone';
             $urlPath = 'civicrm/participant/add';
         }
         if ($this->_id) {
             $urlParams .= "&action=update&id={$this->_id}";
         } else {
             $urlParams .= "&action=add";
         }
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $url = CRM_Utils_System::url($urlPath, $urlParams, FALSE, NULL, FALSE);
     } else {
         $currentPath = CRM_Utils_System::currentPath();
         $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', FALSE, NULL, FALSE);
     }
     $this->assign('refreshURL', $url);
     $this->add('hidden', 'past_event');
     $events = array();
     if ($this->_eID) {
         $eventEndDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID, 'end_date');
     }
     $this->assign('past', 0);
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $events = CRM_Event_BAO_Event::getEvents(1, FALSE, FALSE);
     } elseif ($this->getElementValue('past_event') || isset($eventEndDate) && CRM_Utils_Date::currentDBDate() > CRM_Utils_Date::processDate($eventEndDate)) {
         $pastval = $this->getElementValue('past_event');
         $events = CRM_Event_BAO_Event::getEvents($pastval);
         $this->assign('past', $pastval);
     } else {
         $events = CRM_Event_BAO_Event::getEvents();
     }
     if ($this->_mode) {
         //unset the event which are not monetary when credit card
         //event registration is used
         foreach ($events as $key => $val) {
             $isPaid = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary');
             if (!$isPaid) {
                 unset($events[$key]);
             }
         }
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
     }
     // build array(event -> eventType) mapper
     $query = "\nSELECT     civicrm_event.id as id, civicrm_event.event_type_id as event_type_id\nFROM       civicrm_event\nWHERE      civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0";
     $dao = CRM_Core_DAO::executeQuery($query);
     $eventAndTypeMapping = array();
     while ($dao->fetch()) {
         $eventAndTypeMapping[$dao->id] = $dao->event_type_id;
     }
     $eventAndTypeMapping = json_encode($eventAndTypeMapping);
     // building of mapping ends --
     //inherit the campaign from event.
     $eventCampaigns = array();
     $allEventIds = array_keys($events);
     if (!empty($allEventIds)) {
         CRM_Core_PseudoConstant::populate($eventCampaigns, 'CRM_Event_DAO_Event', TRUE, 'campaign_id');
     }
     $eventCampaigns = json_encode($eventCampaigns);
     $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, TRUE, array('onchange' => "buildFeeBlock( this.value ); CRM.buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' ); loadCampaign( this.value, {$eventCampaigns} );", 'class' => 'huge'));
     // CRM-6111
     // note that embedding JS within PHP files is quite awful, IMO
     // but we do the same for the onChange element and this form is complex
     // and i did not want to break it late in the 3.2 cycle
     $preloadJSSnippet = NULL;
     if (CRM_Utils_Array::value('reset', $_GET) && $this->_eID) {
         $preloadJSSnippet = "\ncj(function() {\ncj('#event_id').val( '{$this->_eID}' );\nbuildFeeBlock( {$this->_eID} );\nCRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );\nbuildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );\nloadCampaign( {$this->_eID}, {$eventCampaigns} );\n});\n";
     }
     $this->assign('preloadJSSnippet', $preloadJSSnippet);
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id');
     }
     if (!$campaignId) {
         $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
         if ($eventId) {
             $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
     if ($this->_id) {
         $this->assign('entityID', $this->_id);
     }
     $roleids = CRM_Event_PseudoConstant::participantRole();
     foreach ($roleids as $rolekey => $rolevalue) {
         $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue, array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );"));
     }
     $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
     $this->addRule('role_id', ts('Role is required'), 'required');
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     $confirmJS = NULL;
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     // get the participant status names to build special status array which is used to show notification
     // checkbox below participant status select
     $participantStatusName = CRM_Event_PseudoConstant::participantStatus();
     $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired');
     // get the required status and then implode only ids
     $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
     $this->assign('notificationStatusIds', $notificationStatusIds);
     $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
     $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $this->_participantStatuses, TRUE, $checkCancelledJs);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS);
     $path = CRM_Utils_System::currentPath();
     $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search');
     if (!in_array($path, $excludeForPaths)) {
         $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS);
     }
     $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'));
     $this->addButtons($buttons);
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
コード例 #5
0
ファイル: Settings.php プロジェクト: rollox/civicrm-core
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->_first = TRUE;
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
     // financial Type
     $this->addSelect('financial_type_id', array(), TRUE);
     // name
     $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     $this->add('wysiwyg', 'intro_text', ts('Introductory Message'), $attributes['intro_text']);
     $this->add('wysiwyg', 'footer_text', ts('Footer Message'), $attributes['footer_text']);
     //Register schema which will be used for OnBehalOf and HonorOf profile Selector
     CRM_UF_Page_ProfileEditor::registerSchemas(array('OrganizationModel', 'HouseholdModel'));
     // is on behalf of an organization ?
     $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
     //CRM-15787 - If applicable, register 'membership_1'
     $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
     $coreTypes = array('Contact', 'Organization');
     $entities[] = array('entity_name' => array('contact_1'), 'entity_type' => 'OrganizationModel');
     if ($member && $member['is_active']) {
         $coreTypes[] = 'Membership';
         $entities[] = array('entity_name' => array('membership_1'), 'entity_type' => 'MembershipModel');
     }
     $allowCoreTypes = array_merge($coreTypes, CRM_Contact_BAO_ContactType::subTypes('Organization'));
     $allowSubTypes = array();
     $this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities);
     $options = array();
     $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
     $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
     $this->addGroup($options, 'is_for_organization', '');
     $this->add('textarea', 'for_organization', ts('On behalf of Label'), array('rows' => 2, 'cols' => 50));
     // collect goal amount
     $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
     $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     // is confirmation page enabled?
     $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
     // is this page shareable through social media ?
     $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
     // is this page active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
     // should the honor be enabled
     $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
     $this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45));
     $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50));
     $this->addSelect('soft_credit_types', array('label' => ts('Honor Types'), 'entity' => 'ContributionSoft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, 'class' => 'huge'));
     $entities = array(array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'));
     $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType::subTypes('Individual'));
     $allowSubTypes = array();
     $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
     if (!empty($this->_submitValues['honor_block_is_active'])) {
         $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
         $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required');
     }
     // add optional start and end dates
     $this->addDateTime('start_date', ts('Start Date'));
     $this->addDateTime('end_date', ts('End Date'));
     $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);
     parent::buildQuickForm();
 }
コード例 #6
0
 function buildQuickForm()
 {
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     // add form elements
     $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE);
     //get the mailing groups.
     $groups = CRM_Core_PseudoConstant::group('Mailing');
     $this->add('select', 'includeGroups', 'Select Group', array('' => '- select -') + $groups, true);
     // Add campaign
     // Start
     $mailingId = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL);
     $campaignId = NULL;
     if ($mailingId) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingId, 'campaign_id');
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     // End
     // Add email subject and and template elements
     // Start
     $this->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', TRUE);
     CRM_Mailing_BAO_Mailing::commonCompose($this);
     // End
     // Advanced options - Tracking options
     // Start
     $this->addElement('checkbox', 'override_verp', ts('Track Replies?'));
     $defaults['override_verp'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies', NULL, FALSE);
     $this->add('checkbox', 'url_tracking', ts('Track Click-throughs?'));
     $defaults['url_tracking'] = TRUE;
     $this->add('checkbox', 'open_tracking', ts('Track Opens?'));
     //$this->add('checkbox', 'open_tracking', ts('Track Opens?'), '', array('value' => '1'), array('checked' => 'checked'));
     $defaults['open_tracking'] = TRUE;
     $this->add('checkbox', 'forward_replies', ts('Forward Replies?'));
     $defaults['forward_replies'] = FALSE;
     $this->add('checkbox', 'auto_responder', ts('Auto-respond to Replies?'));
     $defaults['auto_responder'] = FALSE;
     $this->add('select', 'reply_id', ts('Auto-responder'), CRM_Mailing_PseudoConstant::component('Reply'), TRUE);
     // End
     // From email address and reply to options
     // Start
     $options = array();
     // this seems so hacky, not sure what we are doing here and why. Need to investigate and fix
     $session->getVars($options, "CRM_Mailing_Controller_Send_{$this->controller->_key}");
     $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address');
     if (empty($fromEmailAddress)) {
         //redirect user to enter from email address.
         $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'group=from_email_address&action=add&reset=1');
         $status = ts("There is no valid from email address present. You can add here <a href='%1'>Add From Email Address.</a>", array(1 => $url));
         $session->setStatus($status);
     } else {
         foreach ($fromEmailAddress as $key => $email) {
             $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]);
         }
     }
     $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $fromEmailAddress, TRUE);
     //echo "<pre>";print_r ($config);echo "</pre>";
     //Added code to add custom field as Reply-To on form when it is enabled from Mailer settings
     if (isset($config->replyTo) && !empty($config->replyTo) && !CRM_Utils_Array::value('override_verp', $options)) {
         $this->add('select', 'reply_to_address', ts('Reply-To'), array('' => '- select -') + $fromEmailAddress);
     } elseif (CRM_Utils_Array::value('override_verp', $options)) {
         $trackReplies = TRUE;
         $this->assign('trackReplies', $trackReplies);
     }
     // Mailing Header and footer
     // Start
     $this->add('select', 'header_id', ts('Mailing Header'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header'));
     $this->add('select', 'footer_id', ts('Mailing Footer'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer'));
     // End
     #@madav getting default header na footer id to tpl
     #start
     $this->assign('headerId', key(CRM_Mailing_PseudoConstant::component('Header')));
     $this->assign('footerId', key(CRM_Mailing_PseudoConstant::component('Footer')));
     #end
     // Exclude from groups, Innclude/Exclude mailings
     // Start
     $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
     $outG->setButtonAttributes('add', array('value' => ts('Add >>')));
     $outG->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $mailings = CRM_Mailing_PseudoConstant::completed();
     if (!$mailings) {
         $mailings = array();
     }
     $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
     $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
     $inM->setButtonAttributes('add', array('value' => ts('Add >>')));
     $outM->setButtonAttributes('add', array('value' => ts('Add >>')));
     $inM->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $outM->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $this->assign('mailingCount', count($mailings));
     // End
     $this->addFormRule(array('CRM_Quickbulkemail_Form_QuickBulkEmail', 'formRule'));
     // Schedule or send
     // Start
     //$this->addDateTime('start_date', ts('Schedule Mailing'), FALSE, array('formatType' => 'mailing'));
     //$this->addElement('checkbox', 'now', ts('Send Immediately'));
     // End
     $buttons = array(array('type' => 'next', 'name' => ts('Schedule & Send >>'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')));
     $this->addButtons($buttons);
     // export form elements
     // $this->assign('elementNames', $this->getRenderableElementNames());
     parent::buildQuickForm();
 }
コード例 #7
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     //get the context
     $context = $this->get('context');
     if ($this->_searchBasedMailing) {
         $context = 'search';
     }
     $this->assign('context', $context);
     $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE);
     $hiddenMailingGroup = NULL;
     $campaignId = NULL;
     //CRM-7362 --add campaigns.
     if ($this->_mailingID) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'campaign_id');
         $hiddenMailingGroup = CRM_Mailing_BAO_Mailing::hiddenMailingGroup($this->_mailingID);
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     //dedupe on email option
     $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?'));
     //get the mailing groups.
     $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing');
     //   asort($groups);
     if ($hiddenMailingGroup) {
         $groups[$hiddenMailingGroup] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $hiddenMailingGroup, 'title');
     }
     $mailings = CRM_Mailing_PseudoConstant::completed();
     if (!$mailings) {
         $mailings = array();
     }
     // run the groups through a hook so users can trim it if needed
     CRM_Utils_Hook::mailingGroups($this, $groups, $mailings);
     //when the context is search add base group's.
     if ($this->_searchBasedMailing) {
         //CRM-16600 Include Smart Groups in Unsubscribe list as that matches
         //all other practices in CiviMail
         $this->add('select', 'baseGroup', ts('Unsubscription Group'), array('' => ts('- select -')) + $groups, TRUE);
     }
     if (count($groups) <= 10) {
         // setting minimum height to 2 since widget looks strange when size (height) is 1
         $groupSize = max(count($groups), 2);
     } else {
         $groupSize = 10;
     }
     $inG =& $this->addElement('advmultiselect', 'includeGroups', ts('Include Group(s)') . ' ', $groups, array('size' => $groupSize, 'style' => 'width:auto; min-width:240px;', 'class' => 'advmultiselect'));
     //as we are having hidden smart group so no need.
     if (!$this->_searchBasedMailing) {
         $this->addRule('includeGroups', ts('Please select a group to be mailed.'), 'required');
     }
     $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => $groupSize, 'style' => 'width:auto; min-width:240px;', 'class' => 'advmultiselect'));
     $inG->setButtonAttributes('add', array('value' => ts('Add >>')));
     $outG->setButtonAttributes('add', array('value' => ts('Add >>')));
     $inG->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $outG->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     if (count($mailings) <= 10) {
         // setting minimum height to 2 since widget looks strange when size (height) is 1
         $mailingSize = max(count($mailings), 2);
     } else {
         $mailingSize = 10;
     }
     $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => $mailingSize, 'style' => 'width:auto; min-width:240px;', 'class' => 'advmultiselect'));
     $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => $mailingSize, 'style' => 'width:auto; min-width:240px;', 'class' => 'advmultiselect'));
     $inM->setButtonAttributes('add', array('value' => ts('Add >>')));
     $outM->setButtonAttributes('add', array('value' => ts('Add >>')));
     $inM->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $outM->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $urls = array('' => ts('- select -'), -1 => ts('CiviCRM Search')) + CRM_Contact_Page_CustomSearch::info();
     $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule'));
     $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel')));
     $this->addButtons($buttons);
     $this->assign('groupCount', count($groups));
     $this->assign('mailingCount', count($mailings));
     if (count($groups) == 0 && count($mailings) == 0 && !$this->_searchBasedMailing) {
         CRM_Core_Error::statusBounce("To send a mailing, you must have a valid group of recipients - either at least one group that's a Mailing List or at least one previous mailing or start from a search");
     }
 }
コード例 #8
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
     $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
     $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1;
             if ($additionalParticipant) {
                 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.'));
                 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
                 $this->setDefaults(array('delete_participant' => 1));
                 $this->assign('additionalParticipant', $additionalParticipant);
             }
         }
         $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->_single && $this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $eventFieldParams = array('entity' => 'event', 'select' => array('minimumInputLength' => 0), 'api' => array('extra' => array('campaign_id', 'default_role_id', 'event_type_id')));
     if ($this->_mode) {
         // exclude events which are not monetary when credit card registration is used
         $eventFieldParams['api']['params']['is_monetary'] = 1;
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
     }
     $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id');
     }
     if (!$campaignId) {
         $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
         if ($eventId) {
             $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
     if ($this->_id) {
         $this->assign('entityID', $this->_id);
     }
     $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     $confirmJS = NULL;
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     // get the participant status names to build special status array which is used to show notification
     // checkbox below participant status select
     $participantStatusName = CRM_Event_PseudoConstant::participantStatus();
     $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired');
     // get the required status and then implode only ids
     $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
     $this->assign('notificationStatusIds', $notificationStatusIds);
     $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create');
     // Only show refund status when editing
     if ($this->_action & CRM_Core_Action::ADD) {
         $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
         if ($pendingRefundStatusId) {
             unset($statusOptions[$pendingRefundStatusId]);
         }
     }
     $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS);
     $path = CRM_Utils_System::currentPath();
     $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search');
     if (!in_array($path, $excludeForPaths)) {
         $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS);
     }
     $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'));
     $this->addButtons($buttons);
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
コード例 #9
0
ファイル: Contribution.php プロジェクト: hyebahi/civicrm-core
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // FIXME: This probably needs to be done in preprocess
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::UPDATE && CRM_Utils_Array::value('financial_type_id', $this->_values)) {
         $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']);
         CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($this->_id, 'edit');
         if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     $allPanes = array();
     $recurJs = NULL;
     //tax rate from financialType
     $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
     $this->assign('currencies', json_encode(CRM_Core_OptionGroup::values('currencies_enabled')));
     // build price set form.
     $buildPriceSet = FALSE;
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $this->assign('invoicing', $invoicing);
     // display tax amount on edit contribution page
     if ($invoicing && $this->_action & CRM_Core_Action::UPDATE && isset($this->_values['tax_amount'])) {
         $this->assign('totalTaxAmount', $this->_values['tax_amount']);
     }
     if (empty($this->_lineItems) && ($this->_priceSetId || !empty($_POST['price_set_id']))) {
         $buildPriceSet = TRUE;
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     $defaults = $this->_values;
     $additionalDetailFields = array('note', 'thankyou_date', 'invoice_id', 'non_deductible_amount', 'fee_amount', 'net_amount');
     foreach ($additionalDetailFields as $key) {
         if (!empty($defaults[$key])) {
             $defaults['hidden_AdditionalDetail'] = 1;
             break;
         }
     }
     if ($this->_productDAO) {
         if ($this->_productDAO->product_id) {
             $defaults['hidden_Premium'] = 1;
         }
     }
     if ($this->_noteID && isset($this->_values['note'])) {
         $defaults['hidden_AdditionalDetail'] = 1;
     }
     $paneNames = array(ts('Additional Details') => 'AdditionalDetail');
     //Add Premium pane only if Premium is exists.
     $dao = new CRM_Contribute_DAO_Product();
     $dao->is_active = 1;
     if ($dao->find(TRUE)) {
         $paneNames[ts('Premium Information')] = 'Premium';
     }
     if ($this->_mode) {
         if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE) == TRUE) {
             if (!empty($this->_recurPaymentProcessors)) {
                 $buildRecurBlock = TRUE;
                 if ($this->_ppID) {
                     // ppID denotes a pledge payment.
                     foreach ($this->_paymentProcessors as $processor) {
                         if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('recurContributionsForPledges')) {
                             $buildRecurBlock = TRUE;
                             break;
                         }
                         $buildRecurBlock = FALSE;
                     }
                 }
                 if ($buildRecurBlock) {
                     CRM_Contribute_Form_Contribution_Main::buildRecur($this);
                     $this->setDefaults(array('is_recur' => 0));
                     $this->assign('buildRecurBlock', TRUE);
                     $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
                 }
             }
         }
     }
     foreach ($paneNames as $name => $type) {
         $allPanes[$name] = $this->generatePane($type, $defaults);
     }
     $qfKey = $this->controller->_key;
     $this->assign('qfKey', $qfKey);
     $this->assign('allPanes', $allPanes);
     $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     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;
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Contribution');
     $this->assign('customDataSubType', $this->_contributionType);
     $this->assign('entityID', $this->_id);
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     // Check permissions for financial type first
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action);
     if (empty($financialTypes)) {
         CRM_Core_Error::statusBounce(ts('You do not have all the permissions needed for this page.'));
     }
     $financialType = $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialTypes, TRUE, array('onChange' => "CRM.buildCustomData( 'Contribution', this.value );"));
     $paymentInstrument = FALSE;
     if (!$this->_mode) {
         $paymentInstrument = $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
     }
     $trxnId = $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
     //add receipt for offline contribution
     $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $status = CRM_Contribute_PseudoConstant::contributionStatus();
     // suppressing contribution statuses that are NOT relevant to pledges (CRM-5169)
     $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if ($this->_ppID) {
         foreach (array('Cancelled', 'Failed', 'In Progress') as $suppress) {
             unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
         }
     } elseif (!$this->_ppID && $this->_id || !$this->_id) {
         $suppressFlag = FALSE;
         if ($this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
                 $suppressFlag = TRUE;
             }
         }
         if (!$suppressFlag) {
             foreach (array('Overdue', 'In Progress') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
         } else {
             unset($status[CRM_Utils_Array::key('Overdue', $statusName)]);
         }
     }
     if ($this->_id) {
         $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id');
         $name = CRM_Utils_Array::value($contributionStatus, $statusName);
         switch ($name) {
             case 'Completed':
             case 'Cancelled':
             case 'Refunded':
                 unset($status[CRM_Utils_Array::key('In Progress', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Pending', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Failed', $statusName)]);
                 break;
             case 'Pending':
             case 'In Progress':
                 unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
                 break;
             case 'Failed':
                 foreach (array('Pending', 'Refunded', 'Completed', 'In Progress', 'Cancelled') as $suppress) {
                     unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
                 }
                 break;
         }
     } else {
         unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
     }
     $this->add('select', 'contribution_status_id', ts('Contribution Status'), $status, FALSE);
     // add various dates
     $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
     if ($this->_online) {
         $this->assign('hideCalender', TRUE);
     }
     $checkNumber = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']);
     $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
     $element = $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL, $recurJs);
     if ($this->_online) {
         $element->freeze();
     }
     $totalAmount = NULL;
     if (empty($this->_lineItems)) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute');
         if (!empty($priceSets) && !$this->_ppID) {
             $buildPriceSet = TRUE;
         }
         // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
         // and if we already have line items for that participant. CRM-5095
         if ($buildPriceSet && $this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'id', 'contribution_id');
             if ($pledgePaymentId) {
                 $buildPriceSet = FALSE;
             }
             if ($participantID = CRM_Utils_Array::value('participant', $componentDetails)) {
                 $participantLI = CRM_Price_BAO_LineItem::getLineItems($participantID);
                 if (!CRM_Utils_System::isNull($participantLI)) {
                     $buildPriceSet = FALSE;
                 }
             }
         }
         $hasPriceSets = FALSE;
         if ($buildPriceSet) {
             $hasPriceSets = TRUE;
             // CRM-16451: set financial type of 'Price Set' in back office contribution
             // instead of selecting manually
             $financialTypeIds = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute', 'financial_type_id');
             $element = $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value, " . json_encode($financialTypeIds) . ");"));
             if ($this->_online && !($this->_action & CRM_Core_Action::UPDATE)) {
                 $element->freeze();
             }
         }
         $this->assign('hasPriceSets', $hasPriceSets);
         $currencyFreeze = FALSE;
         if (!($this->_action & CRM_Core_Action::UPDATE)) {
             if ($this->_online || $this->_ppID) {
                 $attributes['total_amount'] = array_merge($attributes['total_amount'], array('READONLY' => TRUE, 'style' => "background-color:#EBECE4"));
                 $optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?'));
                 $this->addRadio('option_type', NULL, $optionTypes, array(), '<br/>');
                 $currencyFreeze = TRUE;
             }
         }
         $totalAmount = $this->addMoney('total_amount', ts('Total Amount'), $hasPriceSets ? FALSE : TRUE, $attributes['total_amount'], TRUE, 'currency', NULL, $currencyFreeze);
     }
     $this->add('text', 'source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     // CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     CRM_Contribute_Form_SoftCredit::buildQuickForm($this);
     $js = NULL;
     if (!$this->_mode) {
         $js = array('onclick' => "return verify( );");
     }
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => $js, 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
     // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
     if ($this->_id && $this->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) {
         if ($totalAmount) {
             $totalAmount->freeze();
         }
         $checkNumber->freeze();
         $paymentInstrument->freeze();
         $trxnId->freeze();
         $financialType->freeze();
     }
     // if contribution is related to membership or participant freeze Financial Type, Amount
     if ($this->_id && isset($this->_values['tax_amount'])) {
         $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
         if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
             if ($totalAmount) {
                 $totalAmount->freeze();
             }
             $financialType->freeze();
             $this->assign('freezeFinancialType', TRUE);
         }
     }
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
コード例 #10
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->_first = TRUE;
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
     // name
     $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), CRM_Contribute_PseudoConstant::contributionType(), TRUE);
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     $this->addWysiwyg('intro_text', ts('Introductory Message'), $attributes['intro_text']);
     $this->addWysiwyg('footer_text', ts('Footer Message'), $attributes['footer_text']);
     // is on behalf of an organization ?
     $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
     $required = array('Contact', 'Organization');
     $optional = array('Contribution', 'Membership');
     $profiles = CRM_Core_BAO_UFGroup::getValidProfiles($required, $optional);
     //Check profiles for Organization subtypes
     $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
     foreach ($contactSubType as $type) {
         $required = array('Contact', $type);
         $subTypeProfiles = CRM_Core_BAO_UFGroup::getValidProfiles($required, $optional);
         foreach ($subTypeProfiles as $profileId => $profileName) {
             $profiles[$profileId] = $profileName;
         }
     }
     $requiredProfileFields = array('organization_name', 'email');
     if (!empty($profiles)) {
         foreach ($profiles as $id => $dontCare) {
             $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($id, $requiredProfileFields);
             if (!$validProfile) {
                 unset($profiles[$id]);
             }
         }
     }
     if (empty($profiles)) {
         $invalidProfiles = TRUE;
         $this->assign('invalidProfiles', $invalidProfiles);
     }
     $this->add('select', 'onbehalf_profile_id', ts('Organization Profile'), array('' => ts('- select -')) + $profiles);
     $options = array();
     $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
     $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
     $this->addGroup($options, 'is_for_organization', ts(''));
     $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']);
     // collect goal amount
     $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
     $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     // is confirmation page enabled?
     $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
     // is this page shareable through social media ?
     $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
     // is this page active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
     // should the honor be enabled
     $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
     $this->add('text', 'honor_block_title', ts('Honoree Section Title'), $attributes['honor_block_title']);
     $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), $attributes['honor_block_text']);
     // add optional start and end dates
     $this->addDateTime('start_date', ts('Start Date'));
     $this->addDateTime('end_date', ts('End Date'));
     $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'));
     parent::buildQuickForm();
 }
コード例 #11
0
 /**
  * Actually build the components of the form.
  */
 public function buildQuickForm()
 {
     // CRM-16398: If current recurring contribution got > 1 lineitems then make amount field readonly
     $amtAttr = array('size' => 20);
     $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($this->_coid);
     if (count($lineItems) > 1) {
         $amtAttr += array('readonly' => TRUE);
     }
     $this->addMoney('amount', ts('Recurring Contribution Amount'), TRUE, $amtAttr, TRUE, 'currency', $this->_subscriptionDetails->currency, TRUE);
     $this->add('text', 'installments', ts('Number of Installments'), array('size' => 20), FALSE);
     if ($this->_donorEmail) {
         $this->add('checkbox', 'is_notify', ts('Notify Contributor?'));
     }
     if (CRM_Core_Permission::check('edit contributions')) {
         CRM_Campaign_BAO_Campaign::addCampaign($this, $this->_subscriptionDetails->campaign_id);
     }
     if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($this->contributionRecurID)) {
         $this->addEntityRef('financial_type_id', ts('Financial Type'), array('entity' => 'FinancialType'), TRUE);
     }
     $type = 'next';
     if ($this->_selfService) {
         $type = 'submit';
     }
     // define the buttons
     $this->addButtons(array(array('type' => $type, 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
コード例 #12
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Event');
     if ($this->_eventType) {
         $this->assign('customDataSubType', $this->_eventType);
     }
     $this->assign('entityId', $this->_id);
     $this->_first = TRUE;
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event');
     if ($this->_isTemplate) {
         $this->add('text', 'template_title', ts('Template Title'), $attributes['template_title'], TRUE);
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $eventTemplates = CRM_Event_PseudoConstant::eventTemplates();
         if (CRM_Utils_System::isNull($eventTemplates)) {
             $this->assign('noEventTemplates', TRUE);
         } else {
             $this->add('select', 'template_id', ts('From Template'), array('' => ts('- select -')) + $eventTemplates, FALSE, array('onchange' => "reloadWindow( this.value );"));
         }
     }
     // add event title, make required if this is not a template
     $this->add('text', 'title', ts('Event Title'), $attributes['event_title'], !$this->_isTemplate);
     $event = CRM_Core_OptionGroup::values('event_type');
     $this->add('select', 'event_type_id', ts('Event Type'), array('' => ts('- select -')) + $event, TRUE, array('onChange' => "buildCustomData( 'Event', this.value );"));
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'campaign_id');
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     $participantRole = CRM_Core_OptionGroup::values('participant_role');
     $this->add('select', 'default_role_id', ts('Participant Role'), $participantRole, TRUE);
     $participantListing = CRM_Core_OptionGroup::values('participant_listing');
     $this->add('select', 'participant_listing_id', ts('Participant Listing'), array('' => ts('Disabled')) + $participantListing, FALSE);
     $this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']);
     $this->addWysiwyg('description', ts('Complete Description'), $attributes['event_description']);
     $this->addElement('checkbox', 'is_public', ts('Public Event?'));
     $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
     $this->addElement('checkbox', 'is_map', ts('Include Map to Event Location?'));
     $this->addDateTime('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('end_date', ts('End Date / Time'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('text', 'max_participants', ts('Max Number of Participants'), array('onchange' => "if (this.value != '') {show('id-waitlist','table-row'); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false); showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); return;} else {hide('id-event_full','table-row'); hide('id-waitlist','table-row'); hide('id-waitlist-text','table-row'); return;}"));
     $this->addRule('max_participants', ts('Max participants should be a positive number'), 'positiveInteger');
     $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
     if (in_array('On waitlist', $participantStatuses) and in_array('Pending from waitlist', $participantStatuses)) {
         $this->addElement('checkbox', 'has_waitlist', ts('Offer a Waitlist?'), NULL, array('onclick' => "showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false);"));
         $this->add('textarea', 'waitlist_text', ts('Waitlist Message'), $attributes['waitlist_text']);
     }
     $this->add('textarea', 'event_full_text', ts('Message if Event Is Full'), $attributes['event_full_text']);
     $this->addElement('checkbox', 'is_active', ts('Is this Event Active?'));
     $this->addFormRule(array('CRM_Event_Form_ManageEvent_EventInfo', 'formRule'));
     parent::buildQuickForm();
 }
コード例 #13
0
ファイル: Activity.php プロジェクト: hguru/224Civi
 public function buildQuickForm()
 {
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) {
         //enable form element (ActivityLinks sets this true)
         $this->assign('suppressForm', FALSE);
         $button = ts('Delete');
         if ($this->_action & CRM_Core_Action::RENEW) {
             $button = ts('Restore');
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $button, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (!$this->_single && !empty($this->_contactIds)) {
         $withArray = array();
         foreach ($this->_contactIds as $contactId) {
             $withDisplayName = self::_getDisplayNameById($contactId);
             $withArray[] = "\"{$withDisplayName}\" ";
         }
         $this->assign('with', implode(', ', $withArray));
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //build other activity links
     CRM_Activity_Form_ActivityLinks::commonBuildQuickForm($this);
     //enable form element (ActivityLinks sets this true)
     $this->assign('suppressForm', FALSE);
     $element =& $this->add('select', 'activity_type_id', ts('Activity Type'), $this->_fields['followup_activity_type_id']['attributes'], FALSE, array('onchange' => "CRM.buildCustomData( 'Activity', this.value );"));
     //freeze for update mode.
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $element->freeze();
     }
     foreach ($this->_fields as $field => $values) {
         if (CRM_Utils_Array::value($field, $this->_fields)) {
             $attribute = NULL;
             if (CRM_Utils_Array::value('attributes', $values)) {
                 $attribute = $values['attributes'];
             }
             $required = FALSE;
             if (CRM_Utils_Array::value('required', $values)) {
                 $required = TRUE;
             }
             if ($values['type'] == 'wysiwyg') {
                 $this->addWysiwyg($field, $values['label'], $attribute, $required);
             } else {
                 $this->add($values['type'], $field, $values['label'], $attribute, $required);
             }
         }
     }
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     //add engagement level CRM-7775
     $buildEngagementLevel = FALSE;
     if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) {
         $buildEngagementLevel = TRUE;
         $this->add('select', 'engagement_level', ts('Engagement Index'), array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel());
         $this->addRule('engagement_level', ts('Please enter the engagement index as a number (integers only).'), 'positiveInteger');
     }
     $this->assign('buildEngagementLevel', $buildEngagementLevel);
     // check for survey activity
     $this->_isSurveyActivity = FALSE;
     if ($this->_activityId && CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) {
         $this->_isSurveyActivity = CRM_Campaign_BAO_Survey::isSurveyActivity($this->_activityId);
         if ($this->_isSurveyActivity) {
             $surveyId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'source_record_id');
             $responseOptions = CRM_Campaign_BAO_Survey::getResponsesOptions($surveyId);
             if ($responseOptions) {
                 $this->add('select', 'result', ts('Result'), array('' => ts('- select -')) + array_combine($responseOptions, $responseOptions));
             }
             $surveyTitle = NULL;
             if ($surveyId) {
                 $surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'title');
             }
             $this->assign('surveyTitle', $surveyTitle);
         }
     }
     $this->assign('surveyActivity', $this->_isSurveyActivity);
     // this option should be available only during add mode
     if ($this->_action != CRM_Core_Action::UPDATE) {
         $this->add('advcheckbox', 'is_multi_activity', ts('Create a separate activity for each contact.'));
     }
     $this->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     $this->addDateTime('activity_date_time', ts('Date'), TRUE, array('formatType' => 'activityDateTime'));
     //add followup date
     $this->addDateTime('followup_date', ts('in'), FALSE, array('formatType' => 'activityDateTime'));
     //autocomplete url
     $dataUrl = CRM_Utils_System::url("civicrm/ajax/rest", "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1", FALSE, NULL, FALSE);
     $this->assign('dataUrl', $dataUrl);
     //tokeninput url
     $tokenUrl = CRM_Utils_System::url("civicrm/ajax/checkemail", "noemail=1", FALSE, NULL, FALSE);
     $this->assign('tokenUrl', $tokenUrl);
     $admin = CRM_Core_Permission::check('administer CiviCRM');
     //allow to edit source contact field field if context is civicase.
     if ($this->_context == 'caseActivity') {
         $admin = TRUE;
     }
     $this->assign('admin', $admin);
     $sourceContactField =& $this->add($this->_fields['source_contact_id']['type'], 'source_contact_id', $this->_fields['source_contact_id']['label'], NULL, $admin);
     $this->add('hidden', 'source_contact_qid', '', array('id' => 'source_contact_qid'));
     CRM_Contact_Form_NewContact::buildQuickForm($this);
     $this->add('text', 'assignee_contact_id', ts('assignee'));
     if ($sourceContactField->getValue()) {
         $this->assign('source_contact', $sourceContactField->getValue());
     } elseif ($this->_currentUserId) {
         // we're setting currently LOGGED IN user as source for this activity
         $this->assign('source_contact_value', self::_getDisplayNameById($this->_currentUserId));
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Activity');
     $this->assign('customDataSubType', $this->_activityTypeId);
     $this->assign('entityID', $this->_activityId);
     $tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
     if (!empty($tags)) {
         $this->add('select', 'tag', ts('Tags'), $tags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'title' => ts('- select -')));
     }
     // we need to hide activity tagset for special activities
     $specialActivities = array('Open Case');
     if (!in_array($this->_activityTypeName, $specialActivities)) {
         // build tag widget
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
         CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity', $this->_activityId, TRUE, TRUE);
     }
     // if we're viewing, we're assigning different buttons than for adding/editing
     if ($this->_action & CRM_Core_Action::VIEW) {
         if (isset($this->_groupTree)) {
             CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $this->_groupTree);
         }
         $buttons = array();
         // do check for permissions
         if (CRM_Case_BAO_Case::checkPermission($this->_activityId, 'File On Case', $this->_activityTypeId)) {
             $buttons[] = array('type' => 'cancel', 'name' => ts('File on case'), 'subName' => 'file_on_case', 'js' => array('onClick' => "javascript:fileOnCase( \"file\", {$this->_activityId} ); return false;"));
         }
         // form should be frozen for view mode
         $this->freeze();
         $buttons[] = array('type' => 'cancel', 'name' => ts('Done'));
         $this->addButtons($buttons);
     } else {
         $message = array('completed' => ts('Are you sure? This is a COMPLETED activity with the DATE in the FUTURE. Click Cancel to change the date / status. Otherwise, click OK to save.'), 'scheduled' => ts('Are you sure? This is a SCHEDULED activity with the DATE in the PAST. Click Cancel to change the date / status. Otherwise, click OK to save.'));
         $js = array('onclick' => "return activityStatus(" . json_encode($message) . ");");
         $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     }
     if ($this->_activityTypeFile) {
         $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
         $className::buildQuickForm($this);
         $this->addFormRule(array($className, 'formRule'), $this);
     }
     $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this);
     if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) {
         $this->assign('activityAssigneeNotification', TRUE);
     } else {
         $this->assign('activityAssigneeNotification', FALSE);
     }
 }
コード例 #14
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Event');
     if ($this->_eventType) {
         $this->assign('customDataSubType', $this->_eventType);
     }
     $this->assign('entityId', $this->_id);
     $this->_first = TRUE;
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event');
     if ($this->_isTemplate) {
         $this->add('text', 'template_title', ts('Template Title'), $attributes['template_title'], TRUE);
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $eventTemplates = CRM_Event_PseudoConstant::eventTemplates();
         if (CRM_Utils_System::isNull($eventTemplates) && !$this->_isTemplate) {
             $url = CRM_Utils_System::url('civicrm/admin/eventTemplate', array('reset' => 1));
             CRM_Core_Session::setStatus(ts('If you find that you are creating multiple events with similar settings, you may want to use the <a href="%1">Event Templates</a> feature to streamline your workflow.', array(1 => $url)), ts('Tip'), 'info');
         }
         if (!CRM_Utils_System::isNull($eventTemplates)) {
             $this->add('select', 'template_id', ts('From Template'), array('' => ts('- select -')) + $eventTemplates, FALSE, array('class' => 'crm-select2 huge'));
         }
         // Make sure this form redirects properly
         $this->preventAjaxSubmit();
     }
     // add event title, make required if this is not a template
     $this->add('text', 'title', ts('Event Title'), $attributes['event_title'], !$this->_isTemplate);
     $this->addSelect('event_type_id', array('onChange' => "CRM.buildCustomData( 'Event', this.value );"), TRUE);
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'campaign_id');
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     $this->addSelect('default_role_id', array(), TRUE);
     $this->addSelect('participant_listing_id', array('placeholder' => ts('Disabled'), 'option_url' => NULL));
     $this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']);
     $this->add('wysiwyg', 'description', ts('Complete Description'), $attributes['event_description']);
     $this->addElement('checkbox', 'is_public', ts('Public Event'));
     $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
     $this->addElement('checkbox', 'is_map', ts('Include Map to Event Location'));
     $this->addDateTime('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('end_date', ts('End Date / Time'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('text', 'max_participants', ts('Max Number of Participants'), array('onchange' => "if (this.value != '') {cj('#id-waitlist').show(); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false); showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); return;} else {cj('#id-event_full, #id-waitlist, #id-waitlist-text').hide(); return;}"));
     $this->addRule('max_participants', ts('Max participants should be a positive number'), 'positiveInteger');
     $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
     $waitlist = 0;
     if (in_array('On waitlist', $participantStatuses) and in_array('Pending from waitlist', $participantStatuses)) {
         $this->addElement('checkbox', 'has_waitlist', ts('Offer a Waitlist?'), NULL, array('onclick' => "showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false);"));
         $this->add('textarea', 'waitlist_text', ts('Waitlist Message'), $attributes['waitlist_text']);
         $waitlist = 1;
     }
     $this->assign('waitlist', $waitlist);
     $this->add('textarea', 'event_full_text', ts('Message if Event Is Full'), $attributes['event_full_text']);
     $this->addElement('checkbox', 'is_active', ts('Is this Event Active?'));
     $this->addFormRule(array('CRM_Event_Form_ManageEvent_EventInfo', 'formRule'));
     parent::buildQuickForm();
 }
コード例 #15
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
     $this->assign('currency', CRM_Core_Config::singleton()->defaultCurrencySymbol);
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     if (isset($invoicing)) {
         $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
     }
     // build price set form.
     $buildPriceSet = FALSE;
     if ($this->_priceSetId || !empty($_POST['price_set_id'])) {
         if (!empty($_POST['price_set_id'])) {
             $buildPriceSet = TRUE;
         }
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         $optionsMembershipTypes = array();
         foreach ($this->_priceSet['fields'] as $pField) {
             if (empty($pField['options'])) {
                 continue;
             }
             foreach ($pField['options'] as $opId => $opValues) {
                 $optionsMembershipTypes[$opId] = CRM_Utils_Array::value('membership_type_id', $opValues, 0);
             }
         }
         $this->assign('autoRenewOption', CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId));
         $this->assign('optionsMembershipTypes', $optionsMembershipTypes);
         $this->assign('contributionType', CRM_Utils_Array::value('financial_type_id', $this->_priceSet));
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     if ($this->_action & CRM_Core_Action::ADD) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
         if (!empty($priceSets)) {
             $buildPriceSet = TRUE;
         }
         if ($buildPriceSet) {
             $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
         }
         $this->assign('hasPriceSets', $buildPriceSet);
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Membership');
     $this->assign('customDataSubType', $this->_memType);
     $this->assign('entityID', $this->_id);
     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);
     }
     $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
     // Throw status bounce when no Membership type or priceset is present
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && empty($this->allMembershipTypeDetails) && empty($priceSets)) {
         CRM_Core_Error::statusBounce(ts('You do not have all the permissions needed for this page.'));
     }
     // retrieve all memberships
     $allMembershipInfo = array();
     foreach ($this->allMembershipTypeDetails as $key => $values) {
         if ($this->_mode && empty($values['minimum_fee'])) {
             continue;
         } else {
             $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
             if (empty($selMemTypeOrg[$memberOfContactId])) {
                 $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id');
                 $selOrgMemType[$memberOfContactId][0] = ts('- select -');
             }
             if (empty($selOrgMemType[$memberOfContactId][$key])) {
                 $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
             }
         }
         $totalAmount = CRM_Utils_Array::value('minimum_fee', $values);
         //CRM-18827 - override the default value if total_amount is submitted
         if (!empty($this->_submitValues['total_amount'])) {
             $totalAmount = $this->_submitValues['total_amount'];
         }
         // build membership info array, which is used when membership type is selected to:
         // - set the payment information block
         // - set the max related block
         $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'), 'total_amount_numeric' => $totalAmount, 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values), 'has_related' => isset($values['relationship_type_id']), 'max_related' => CRM_Utils_Array::value('max_related', $values));
     }
     $this->assign('allMembershipInfo', json_encode($allMembershipInfo));
     // show organization by default, if only one organization in
     // the list
     if (count($selMemTypeOrg) == 2) {
         unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
     }
     //sort membership organization and type, CRM-6099
     natcasesort($selMemTypeOrg);
     foreach ($selOrgMemType as $index => $orgMembershipType) {
         natcasesort($orgMembershipType);
         $selOrgMemType[$index] = $orgMembershipType;
     }
     $memTypeJs = array('onChange' => "buildMaxRelated(this.value,true); CRM.buildCustomData('Membership', this.value);");
     if (!empty($this->_recurPaymentProcessors)) {
         $memTypeJs['onChange'] = "" . $memTypeJs['onChange'] . "buildAutoRenew(this.value, null, '{$this->_mode}');";
     }
     $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related'));
     $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs);
     $sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
     $elements = array();
     if ($sel) {
         $elements[] = $sel;
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::ADD) {
         $this->add('text', 'num_terms', ts('Number of Terms'), array('size' => 6));
     }
     $this->addDate('join_date', ts('Member Since'), FALSE, array('formatType' => 'activityDate'));
     $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDate'));
     $endDate = $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDate'));
     if ($endDate) {
         $elements[] = $endDate;
     }
     $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source'));
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'campaign_id');
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     if (!$this->_mode) {
         $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'));
         $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), NULL, array('onClick' => 'showHideMemberStatus()'));
         if ($statusOverride) {
             $elements[] = $statusOverride;
         }
         $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?'));
         $this->add('text', 'total_amount', ts('Amount'));
         $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
         $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
         $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
         $this->add('text', 'trxn_id', ts('Transaction ID'));
         $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
         $allowStatuses = array();
         $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
         if ($this->_onlinePendingContributionId) {
             $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach ($statusNames as $val => $name) {
                 if (in_array($name, array('In Progress', 'Overdue'))) {
                     continue;
                 }
                 $allowStatuses[$val] = $statuses[$val];
             }
         } else {
             $allowStatuses = $statuses;
         }
         $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses);
         $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
     } else {
         //add field for amount to allow an amount to be entered that differs from minimum
         $this->add('text', 'total_amount', ts('Amount'));
     }
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action));
     $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
     $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
     $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
     $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showEmailOptions()"));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $this->add('textarea', 'receipt_text', ts('Receipt Message'));
     // Retrieve the name and email of the contact - this will be the TO for receipt email
     if ($this->_contactID) {
         list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('emailExists', $this->_memberEmail);
         $this->assign('displayName', $this->_memberDisplayName);
     }
     $isRecur = FALSE;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id');
         if ($recurContributionId && !CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id)) {
             $isRecur = TRUE;
             if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
                 $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}"));
             }
             foreach ($elements as $elem) {
                 $elem->freeze();
             }
         }
     }
     $this->assign('isRecur', $isRecur);
     $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this);
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('isEmailEnabledForSite', $mailingInfo['outBound_option'] != 2);
     parent::buildQuickForm();
 }
コード例 #16
0
 public function buildQuickForm()
 {
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) {
         //enable form element (ActivityLinks sets this true)
         $this->assign('suppressForm', FALSE);
         $button = ts('Delete');
         if ($this->_action & CRM_Core_Action::RENEW) {
             $button = ts('Restore');
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $button, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     // Build other activity links.
     CRM_Activity_Form_ActivityLinks::commonBuildQuickForm($this);
     // Enable form element (ActivityLinks sets this true).
     $this->assign('suppressForm', FALSE);
     $element =& $this->add('select', 'activity_type_id', ts('Activity Type'), array('' => '- ' . ts('select') . ' -') + $this->_fields['followup_activity_type_id']['attributes'], FALSE, array('onchange' => "CRM.buildCustomData( 'Activity', this.value );", 'class' => 'crm-select2 required'));
     // Freeze for update mode.
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $element->freeze();
     }
     // Call to RecurringEntity buildQuickForm for add/update mode.
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         CRM_Core_Form_RecurringEntity::buildQuickForm($this);
     }
     foreach ($this->_fields as $field => $values) {
         if (!empty($this->_fields[$field])) {
             $attribute = CRM_Utils_Array::value('attributes', $values);
             $required = !empty($values['required']);
             if ($values['type'] == 'select' && empty($attribute)) {
                 $this->addSelect($field, array('entity' => 'activity'), $required);
             } elseif ($values['type'] == 'entityRef') {
                 $this->addEntityRef($field, $values['label'], $attribute, $required);
             } else {
                 $this->add($values['type'], $field, $values['label'], $attribute, $required, CRM_Utils_Array::value('extra', $values));
             }
         }
     }
     // CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     // Add engagement level CRM-7775
     $buildEngagementLevel = FALSE;
     if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) {
         $buildEngagementLevel = TRUE;
         $this->addSelect('engagement_level', array('entity' => 'activity'));
         $this->addRule('engagement_level', ts('Please enter the engagement index as a number (integers only).'), 'positiveInteger');
     }
     $this->assign('buildEngagementLevel', $buildEngagementLevel);
     // check for survey activity
     $this->_isSurveyActivity = FALSE;
     if ($this->_activityId && CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) {
         $this->_isSurveyActivity = CRM_Campaign_BAO_Survey::isSurveyActivity($this->_activityId);
         if ($this->_isSurveyActivity) {
             $surveyId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'source_record_id');
             $responseOptions = CRM_Campaign_BAO_Survey::getResponsesOptions($surveyId);
             if ($responseOptions) {
                 $this->add('select', 'result', ts('Result'), array('' => ts('- select -')) + array_combine($responseOptions, $responseOptions));
             }
             $surveyTitle = NULL;
             if ($surveyId) {
                 $surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'title');
             }
             $this->assign('surveyTitle', $surveyTitle);
         }
     }
     $this->assign('surveyActivity', $this->_isSurveyActivity);
     // this option should be available only during add mode
     if ($this->_action != CRM_Core_Action::UPDATE) {
         $this->add('advcheckbox', 'is_multi_activity', ts('Create a separate activity for each contact.'));
     }
     $this->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
     $this->addDateTime('activity_date_time', ts('Date'), TRUE, array('formatType' => 'activityDateTime'));
     // Add followup date.
     $this->addDateTime('followup_date', ts('in'), FALSE, array('formatType' => 'activityDateTime'));
     // Only admins and case-workers can change the activity source
     if (!CRM_Core_Permission::check('administer CiviCRM') && $this->_context != 'caseActivity') {
         $this->getElement('source_contact_id')->freeze();
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Activity');
     $this->assign('customDataSubType', $this->_activityTypeId);
     $this->assign('entityID', $this->_activityId);
     CRM_Core_BAO_Tag::getTags('civicrm_activity', $tags, NULL, '&nbsp;&nbsp;', TRUE);
     if (!empty($tags)) {
         $this->add('select', 'tag', ts('Tags'), $tags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2 huge'));
     }
     // we need to hide activity tagset for special activities
     $specialActivities = array('Open Case');
     if (!in_array($this->_activityTypeName, $specialActivities)) {
         // build tag widget
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
         CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity', $this->_activityId);
     }
     // if we're viewing, we're assigning different buttons than for adding/editing
     if ($this->_action & CRM_Core_Action::VIEW) {
         if (isset($this->_groupTree)) {
             CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $this->_groupTree);
         }
         // form should be frozen for view mode
         $this->freeze();
         $buttons = array();
         $buttons[] = array('type' => 'cancel', 'name' => ts('Done'));
         $this->addButtons($buttons);
     } else {
         $message = array('completed' => ts('Are you sure? This is a COMPLETED activity with the DATE in the FUTURE. Click Cancel to change the date / status. Otherwise, click OK to save.'), 'scheduled' => ts('Are you sure? This is a SCHEDULED activity with the DATE in the PAST. Click Cancel to change the date / status. Otherwise, click OK to save.'));
         $js = array('onclick' => "return activityStatus(" . json_encode($message) . ");");
         $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     }
     if ($this->_activityTypeFile) {
         $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
         $className::buildQuickForm($this);
         $this->addFormRule(array($className, 'formRule'), $this);
     }
     $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this);
     if (Civi::settings()->get('activity_assignee_notification')) {
         $this->assign('activityAssigneeNotification', TRUE);
     } else {
         $this->assign('activityAssigneeNotification', FALSE);
     }
 }
コード例 #17
0
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_cdType) {
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         return;
     }
     $allPanes = array();
     // build price set form.
     $buildPriceSet = FALSE;
     if (empty($this->_lineItems) && ($this->_priceSetId || !empty($_POST['price_set_id']))) {
         $buildPriceSet = TRUE;
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     $showAdditionalInfo = FALSE;
     $defaults = $this->_values;
     $additionalDetailFields = array('note', 'thankyou_date', 'invoice_id', 'non_deductible_amount', 'fee_amount', 'net_amount');
     foreach ($additionalDetailFields as $key) {
         if (!empty($defaults[$key])) {
             $defaults['hidden_AdditionalDetail'] = 1;
             break;
         }
     }
     if ($this->_productDAO) {
         if ($this->_productDAO->product_id) {
             $defaults['hidden_Premium'] = 1;
         }
     }
     if ($this->_noteID && isset($this->_values['note'])) {
         $defaults['hidden_AdditionalDetail'] = 1;
     }
     $paneNames = array(ts('Additional Details') => 'AdditionalDetail');
     //Add Premium pane only if Premium is exists.
     $dao = new CRM_Contribute_DAO_Product();
     $dao->is_active = 1;
     if ($dao->find(TRUE)) {
         $paneNames[ts('Premium Information')] = 'Premium';
     }
     $ccPane = NULL;
     if ($this->_mode) {
         if (CRM_Utils_Array::value('payment_type', $this->_processors) & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
             $ccPane = array(ts('Direct Debit Information') => 'DirectDebit');
         } else {
             $ccPane = array(ts('Credit Card Information') => 'CreditCard');
         }
     }
     if (is_array($ccPane)) {
         $paneNames = array_merge($ccPane, $paneNames);
     }
     $buildRecurBlock = FALSE;
     foreach ($paneNames as $name => $type) {
         $urlParams = "snippet=4&formType={$type}";
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $open = 'false';
         if ($type == 'CreditCard' || $type == 'DirectDebit') {
             $open = 'true';
         }
         $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams), 'open' => $open, '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';
         }
         if ($type == 'CreditCard') {
             $buildRecurBlock = TRUE;
             $this->add('hidden', 'hidden_CreditCard', 1);
             CRM_Core_Payment_Form::buildCreditCard($this, TRUE);
         } elseif ($type == 'DirectDebit') {
             $buildRecurBlock = TRUE;
             $this->add('hidden', 'hidden_DirectDebit', 1);
             CRM_Core_Payment_Form::buildDirectDebit($this, TRUE);
         } else {
             $additionalInfoFormFunction = 'build' . $type;
             CRM_Contribute_Form_AdditionalInfo::$additionalInfoFormFunction($this);
         }
     }
     if (empty($this->_recurPaymentProcessors)) {
         $buildRecurBlock = FALSE;
     }
     if ($buildRecurBlock) {
         CRM_Contribute_Form_Contribution_Main::buildRecur($this);
         $this->setDefaults(array('is_recur' => 0));
     }
     $this->assign('buildRecurBlock', $buildRecurBlock);
     $qfKey = $this->controller->_key;
     $this->assign('qfKey', $qfKey);
     $this->assign('allPanes', $allPanes);
     $this->assign('showAdditionalInfo', $showAdditionalInfo);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     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;
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Contribution');
     $this->assign('customDataSubType', $this->_contributionType);
     $this->assign('entityID', $this->_id);
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     $financialType = $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), TRUE, array('onChange' => "CRM.buildCustomData( 'Contribution', this.value );"));
     $paymentInstrument = FALSE;
     if (!$this->_mode) {
         $paymentInstrument = $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
     }
     $trxnId = $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
     //add receipt for offline contribution
     $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $status = CRM_Contribute_PseudoConstant::contributionStatus();
     // suppressing contribution statuses that are NOT relevant to pledges (CRM-5169)
     $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if ($this->_ppID) {
         foreach (array('Cancelled', 'Failed', 'In Progress') as $suppress) {
             unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
         }
     } elseif (!$this->_ppID && $this->_id || !$this->_id) {
         $suppressFlag = FALSE;
         if ($this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
                 $suppressFlag = TRUE;
             }
         }
         if (!$suppressFlag) {
             foreach (array('Overdue', 'In Progress') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
         } else {
             unset($status[CRM_Utils_Array::key('Overdue', $statusName)]);
         }
     }
     if ($this->_id) {
         $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id');
         $name = CRM_Utils_Array::value($contributionStatus, $statusName);
         switch ($name) {
             case 'Completed':
             case 'Cancelled':
             case 'Refunded':
                 unset($status[CRM_Utils_Array::key('In Progress', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Pending', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Failed', $statusName)]);
                 break;
             case 'Pending':
             case 'In Progress':
                 unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
                 break;
             case 'Failed':
                 foreach (array('Pending', 'Refunded', 'Completed', 'In Progress', 'Cancelled') as $suppress) {
                     unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
                 }
                 break;
         }
     } else {
         unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
     }
     $this->add('select', 'contribution_status_id', ts('Contribution Status'), $status, FALSE);
     // add various dates
     $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
     if ($this->_online) {
         $this->assign('hideCalender', TRUE);
     }
     $checkNumber = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']);
     $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
     $recurJs = NULL;
     if ($buildRecurBlock) {
         $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
     }
     $element = $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL, $recurJs);
     if ($this->_online) {
         $element->freeze();
     }
     $totalAmount = NULL;
     if (empty($this->_lineItems)) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute');
         if (!empty($priceSets) && !$this->_ppID) {
             $buildPriceSet = TRUE;
         }
         // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
         // and if we already have line items for that participant. CRM-5095
         if ($buildPriceSet && $this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'id', 'contribution_id');
             if ($pledgePaymentId) {
                 $buildPriceSet = FALSE;
             }
             if ($participantID = CRM_Utils_Array::value('participant', $componentDetails)) {
                 $participantLI = CRM_Price_BAO_LineItem::getLineItems($participantID);
                 if (!CRM_Utils_System::isNull($participantLI)) {
                     $buildPriceSet = FALSE;
                 }
             }
         }
         $hasPriceSets = FALSE;
         if ($buildPriceSet) {
             $hasPriceSets = TRUE;
             $element = $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
             if ($this->_online && !($this->_action & CRM_Core_Action::UPDATE)) {
                 $element->freeze();
             }
         }
         $this->assign('hasPriceSets', $hasPriceSets);
         $currencyFreeze = FALSE;
         if (!($this->_action & CRM_Core_Action::UPDATE)) {
             if ($this->_online || $this->_ppID) {
                 $attributes['total_amount'] = array_merge($attributes['total_amount'], array('READONLY' => TRUE, 'style' => "background-color:#EBECE4"));
                 $optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?'));
                 $this->addRadio('option_type', NULL, $optionTypes, array(), '<br/>');
                 $currencyFreeze = TRUE;
             }
         }
         $totalAmount = $this->addMoney('total_amount', ts('Total Amount'), $hasPriceSets ? FALSE : TRUE, $attributes['total_amount'], TRUE, 'currency', NULL, $currencyFreeze);
     }
     $this->add('text', 'source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     CRM_Contribute_Form_SoftCredit::buildQuickForm($this);
     $js = NULL;
     if (!$this->_mode) {
         $js = array('onclick' => "return verify( );");
     }
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => $js, 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
     // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
     if ($this->_id && $this->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) {
         if ($totalAmount) {
             $totalAmount->freeze();
         }
         $checkNumber->freeze();
         $paymentInstrument->freeze();
         $trxnId->freeze();
         $financialType->freeze();
     }
     $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
コード例 #18
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     //get the context
     $context = $this->get('context');
     if ($this->_searchBasedMailing) {
         $context = 'search';
     }
     $this->assign('context', $context);
     $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE);
     //CRM-7362 --add campaigns.
     $mailingId = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL);
     $campaignId = NULL;
     if ($mailingId) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingId, 'campaign_id');
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     //dedupe on email option
     $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?'));
     //get the mailing groups.
     $groups = CRM_Core_PseudoConstant::group('Mailing');
     $mailings = CRM_Mailing_PseudoConstant::completed();
     if (!$mailings) {
         $mailings = array();
     }
     // run the groups through a hook so users can trim it if needed
     CRM_Utils_Hook::mailingGroups($this, $groups, $mailings);
     //when the context is search add base group's.
     if ($this->_searchBasedMailing) {
         //get the static groups
         $staticGroups = CRM_Core_PseudoConstant::staticGroup(FALSE, 'Mailing');
         $this->add('select', 'baseGroup', ts('Unsubscription Group'), array('' => ts('- select -')) + $staticGroups, TRUE);
     }
     $inG =& $this->addElement('advmultiselect', 'includeGroups', ts('Include Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
     //as we are having hidden smart group so no need.
     if (!$this->_searchBasedMailing) {
         $this->addRule('includeGroups', ts('Please select a group to be mailed.'), 'required');
     }
     $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
     $inG->setButtonAttributes('add', array('value' => ts('Add >>')));
     $outG->setButtonAttributes('add', array('value' => ts('Add >>')));
     $inG->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $outG->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
     $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
     $inM->setButtonAttributes('add', array('value' => ts('Add >>')));
     $outM->setButtonAttributes('add', array('value' => ts('Add >>')));
     $inM->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $outM->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $urls = array('' => ts('- select -'), -1 => ts('CiviCRM Search')) + CRM_Contact_Page_CustomSearch::info();
     $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule'));
     //FIXME : currently we are hiding save an continue later when
     //search base mailing, we should handle it when we fix CRM-3876
     $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel')));
     if ($this->_searchBasedMailing) {
         $buttons = array(array('type' => 'next', 'name' => ts('Next >>'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     }
     $this->addButtons($buttons);
     $this->assign('groupCount', count($groups));
     $this->assign('mailingCount', count($mailings));
 }
コード例 #19
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     //get the context
     $context = $this->get('context');
     if ($this->_searchBasedMailing) {
         $context = 'search';
     }
     $this->assign('context', $context);
     $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE);
     $hiddenMailingGroup = NULL;
     $campaignId = NULL;
     //CRM-7362 --add campaigns.
     if ($this->_mailingID) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'campaign_id');
         $hiddenMailingGroup = CRM_Mailing_BAO_Mailing::hiddenMailingGroup($this->_mailingID);
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     //dedupe on email option
     $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?'));
     // location types
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('id' => 'display_name'));
     $this->addElement('select', 'location_type_id', ts("Location Type"), array('' => ts('Automatic')) + $locationTypes);
     $methods = CRM_Core_SelectValues::emailSelectMethods();
     $this->addElement('select', 'email_selection_method', ts("Email Selection Method"), $methods);
     //get the mailing groups.
     $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing');
     if ($hiddenMailingGroup) {
         $groups[$hiddenMailingGroup] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $hiddenMailingGroup, 'title');
     }
     $mailings = CRM_Mailing_PseudoConstant::completed();
     if (!$mailings) {
         $mailings = array();
     }
     // run the groups through a hook so users can trim it if needed
     CRM_Utils_Hook::mailingGroups($this, $groups, $mailings);
     //when the context is search add base group's.
     if ($this->_searchBasedMailing) {
         //get the static groups
         $staticGroups = CRM_Core_PseudoConstant::staticGroup(FALSE, 'Mailing');
         $this->add('select', 'baseGroup', ts('Unsubscription Group'), array('' => ts('- select -')) + CRM_Contact_BAO_Group::getGroupsHierarchy($staticGroups, NULL, '&nbsp;&nbsp;', TRUE), TRUE, array('class' => 'crm-select2 huge'));
     }
     $select2style = array('multiple' => TRUE, 'style' => 'width: 100%; max-width: 60em;', 'class' => 'crm-select2', 'placeholder' => ts('- select -'));
     $this->add('select', 'includeGroups', ts('Include Group(s)'), $groups, !$this->_searchBasedMailing, $select2style);
     $this->add('select', 'excludeGroups', ts('Exclude Group(s)'), $groups, FALSE, $select2style);
     $this->add('select', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, FALSE, $select2style);
     $this->add('select', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, FALSE, $select2style);
     $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule'));
     $buttons = array(array('type' => 'next', 'name' => ts('Next'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel')));
     $this->addButtons($buttons);
     $this->assign('groupCount', count($groups));
     $this->assign('mailingCount', count($mailings));
     if (count($groups) == 0 && count($mailings) == 0 && !$this->_searchBasedMailing) {
         CRM_Core_Error::statusBounce("To send a mailing, you must have a valid group of recipients - either at least one group that's a Mailing List or at least one previous mailing or start from a search");
     }
 }
コード例 #20
0
ファイル: Membership.php プロジェクト: indydas/civi-demo
    /**
     * Build the form object.
     *
     * @return void
     */
    public function buildQuickForm()
    {
        if ($this->_cdType) {
            return CRM_Custom_Form_CustomData::buildQuickForm($this);
        }
        $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
        $config = CRM_Core_Config::singleton();
        $this->assign('currency', $config->defaultCurrencySymbol);
        $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
        $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
        if (isset($invoicing)) {
            $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
        }
        // build price set form.
        $buildPriceSet = FALSE;
        if ($this->_priceSetId || !empty($_POST['price_set_id'])) {
            if (!empty($_POST['price_set_id'])) {
                $buildPriceSet = TRUE;
            }
            $getOnlyPriceSetElements = TRUE;
            if (!$this->_priceSetId) {
                $this->_priceSetId = $_POST['price_set_id'];
                $getOnlyPriceSetElements = FALSE;
            }
            $this->set('priceSetId', $this->_priceSetId);
            CRM_Price_BAO_PriceSet::buildPriceSet($this);
            $optionsMembershipTypes = array();
            foreach ($this->_priceSet['fields'] as $pField) {
                if (empty($pField['options'])) {
                    continue;
                }
                foreach ($pField['options'] as $opId => $opValues) {
                    $optionsMembershipTypes[$opId] = CRM_Utils_Array::value('membership_type_id', $opValues, 0);
                }
            }
            $this->assign('autoRenewOption', CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId));
            $this->assign('optionsMembershipTypes', $optionsMembershipTypes);
            $this->assign('contributionType', CRM_Utils_Array::value('financial_type_id', $this->_priceSet));
            // get only price set form elements.
            if ($getOnlyPriceSetElements) {
                return;
            }
        }
        // use to build form during form rule.
        $this->assign('buildPriceSet', $buildPriceSet);
        if ($this->_action & CRM_Core_Action::ADD) {
            $buildPriceSet = FALSE;
            $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
            if (!empty($priceSets)) {
                $buildPriceSet = TRUE;
            }
            if ($buildPriceSet) {
                $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
            }
            $this->assign('hasPriceSets', $buildPriceSet);
        }
        //need to assign custom data type and subtype to the template
        $this->assign('customDataType', 'Membership');
        $this->assign('customDataSubType', $this->_memType);
        $this->assign('entityID', $this->_id);
        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);
        }
        $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
        $dao = new CRM_Member_DAO_MembershipType();
        $dao->domain_id = CRM_Core_Config::domainID();
        $dao->find();
        // retrieve all memberships
        $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this);
        $allMembershipInfo = $membershipType = array();
        foreach ($allMemberships as $key => $values) {
            if (!empty($values['is_active'])) {
                $membershipType[$key] = CRM_Utils_Array::value('name', $values);
                if ($this->_mode && empty($values['minimum_fee'])) {
                    continue;
                } else {
                    $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
                    if (empty($selMemTypeOrg[$memberOfContactId])) {
                        $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id');
                        $selOrgMemType[$memberOfContactId][0] = ts('- select -');
                    }
                    if (empty($selOrgMemType[$memberOfContactId][$key])) {
                        $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
                    }
                }
                // build membership info array, which is used when membership type is selected to:
                // - set the payment information block
                // - set the max related block
                $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($values['minimum_fee'], NULL, '%a'), 'total_amount_numeric' => CRM_Utils_Array::value('minimum_fee', $values), 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values), 'has_related' => isset($values['relationship_type_id']), 'max_related' => CRM_Utils_Array::value('max_related', $values));
            }
        }
        $this->assign('allMembershipInfo', json_encode($allMembershipInfo));
        // show organization by default, if only one organization in
        // the list
        if (count($selMemTypeOrg) == 2) {
            unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
        }
        //sort membership organization and type, CRM-6099
        natcasesort($selMemTypeOrg);
        foreach ($selOrgMemType as $index => $orgMembershipType) {
            natcasesort($orgMembershipType);
            $selOrgMemType[$index] = $orgMembershipType;
        }
        $memTypeJs = array('onChange' => "CRM.buildCustomData( 'Membership', this.value );");
        //build the form for auto renew.
        $recurProcessor = $autoRenew = array();
        if ($this->_mode || $this->_action & CRM_Core_Action::UPDATE) {
            $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), NULL, array('onclick' => "buildReceiptANDNotice( );"));
            if ($this->_mode) {
                //get the valid recurring processors.
                $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE;
                $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1');
                $recurProcessor = array_intersect_key($this->_processors, $recurring);
                $autoRenew = array();
                if (!empty($recurProcessor)) {
                    if (!empty($membershipType)) {
                        $sql = '
SELECT  id,
        auto_renew,
        duration_unit,
        duration_interval
 FROM   civicrm_membership_type
WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
                        $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql);
                        while ($recurMembershipTypes->fetch()) {
                            $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew;
                            foreach (array('id', 'auto_renew', 'duration_unit', 'duration_interval') as $fld) {
                                $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->{$fld};
                            }
                        }
                    }
                    $memTypeJs = array('onChange' => "CRM.buildCustomData( 'Membership', this.value ); buildAutoRenew(this.value, null );");
                }
            }
        }
        $allowAutoRenew = FALSE;
        if ($this->_mode && !empty($recurProcessor)) {
            $allowAutoRenew = TRUE;
        }
        $this->assign('allowAutoRenew', $allowAutoRenew);
        $this->assign('autoRenewOptions', json_encode($autoRenew));
        $this->assign('recurProcessor', json_encode($recurProcessor));
        // for max_related: a little JS to show/hide & set default value
        $memTypeJs['onChange'] = "buildMaxRelated(this.value,true); " . $memTypeJs['onChange'];
        $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related'));
        $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs);
        $sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
        $elements = array();
        if ($sel) {
            $elements[] = $sel;
        }
        $this->applyFilter('__ALL__', 'trim');
        if ($this->_action & CRM_Core_Action::ADD) {
            $this->add('text', 'num_terms', ts('Number of Terms'), array('size' => 6));
        }
        $this->addDate('join_date', ts('Member Since'), FALSE, array('formatType' => 'activityDate'));
        $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDate'));
        $endDate = $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDate'));
        if ($endDate) {
            $elements[] = $endDate;
        }
        $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source'));
        //CRM-7362 --add campaigns.
        $campaignId = NULL;
        if ($this->_id) {
            $campaignId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'campaign_id');
        }
        CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
        if (!$this->_mode) {
            $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'));
            $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), NULL, array('onClick' => 'showHideMemberStatus()'));
            if ($statusOverride) {
                $elements[] = $statusOverride;
            }
            $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?'));
            $this->add('text', 'total_amount', ts('Amount'));
            $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
            $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
            $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
            $this->add('text', 'trxn_id', ts('Transaction ID'));
            $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
            $allowStatuses = array();
            $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
            if ($this->_onlinePendingContributionId) {
                $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
                foreach ($statusNames as $val => $name) {
                    if (in_array($name, array('In Progress', 'Overdue'))) {
                        continue;
                    }
                    $allowStatuses[$val] = $statuses[$val];
                }
            } else {
                $allowStatuses = $statuses;
            }
            $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses);
            $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
        } else {
            //add field for amount to allow an amount to be entered that differs from minimum
            $this->add('text', 'total_amount', ts('Amount'));
        }
        $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType());
        //CRM-10223 - allow contribution to be recorded against different contact
        // causes a conflict in standalone mode so skip in standalone for now
        $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
        $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
        $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
        $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio', false);"));
        $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
        $this->add('textarea', 'receipt_text_signup', ts('Receipt Message'));
        // Retrieve the name and email of the contact - this will be the TO for receipt email
        if ($this->_contactID) {
            list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
            $this->assign('emailExists', $this->_memberEmail);
            $this->assign('displayName', $this->_memberDisplayName);
        }
        $isRecur = FALSE;
        if ($this->_action & CRM_Core_Action::UPDATE) {
            $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id');
            if ($recurContributionId && !CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id)) {
                $isRecur = TRUE;
                if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
                    $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}"));
                }
                foreach ($elements as $elem) {
                    $elem->freeze();
                }
            }
        }
        $this->assign('isRecur', $isRecur);
        $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this);
        $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
        $this->assign('outBound_option', $mailingInfo['outBound_option']);
        parent::buildQuickForm();
    }
コード例 #21
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     // build price set form.
     $buildPriceSet = FALSE;
     if (empty($this->_lineItems) && ($this->_priceSetId || CRM_Utils_Array::value('price_set_id', $_POST))) {
         $buildPriceSet = TRUE;
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_Set::buildPriceSet($this);
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     $showAdditionalInfo = FALSE;
     $defaults = $this->_values;
     $additionalDetailFields = array('note', 'thankyou_date', 'invoice_id', 'non_deductible_amount', 'fee_amount', 'net_amount');
     foreach ($additionalDetailFields as $key) {
         if (!empty($defaults[$key])) {
             $defaults['hidden_AdditionalDetail'] = 1;
             break;
         }
     }
     $honorFields = array('honor_type_id', 'honor_prefix_id', 'honor_first_name', 'honor_lastname', 'honor_email');
     foreach ($honorFields as $key) {
         if (!empty($defaults[$key])) {
             $defaults['hidden_Honoree'] = 1;
             break;
         }
     }
     //check for honoree pane.
     if ($this->_ppID && CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues)) {
         $defaults['hidden_Honoree'] = 1;
     }
     if ($this->_productDAO) {
         if ($this->_productDAO->product_id) {
             $defaults['hidden_Premium'] = 1;
         }
     }
     if ($this->_noteID && isset($this->_values['note'])) {
         $defaults['hidden_AdditionalDetail'] = 1;
     }
     $paneNames = array(ts('Additional Details') => 'AdditionalDetail', ts('Honoree Information') => 'Honoree');
     //Add Premium pane only if Premium is exists.
     $dao = new CRM_Contribute_DAO_Product();
     $dao->is_active = 1;
     if ($dao->find(TRUE)) {
         $paneNames[ts('Premium Information')] = 'Premium';
     }
     $ccPane = NULL;
     if ($this->_mode) {
         if (CRM_Utils_Array::value('payment_type', $this->_processors) & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
             $ccPane = array(ts('Direct Debit Information') => 'DirectDebit');
         } else {
             $ccPane = array(ts('Credit Card Information') => 'CreditCard');
         }
     }
     if (is_array($ccPane)) {
         $paneNames = array_merge($ccPane, $paneNames);
     }
     $buildRecurBlock = FALSE;
     foreach ($paneNames as $name => $type) {
         $urlParams = "snippet=4&formType={$type}";
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $open = 'false';
         if ($type == 'CreditCard' || $type == 'DirectDebit') {
             $open = 'true';
         }
         $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams), 'open' => $open, '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';
         }
         if ($type == 'CreditCard') {
             $buildRecurBlock = TRUE;
             $this->add('hidden', 'hidden_CreditCard', 1);
             CRM_Core_Payment_Form::buildCreditCard($this, TRUE);
         } elseif ($type == 'DirectDebit') {
             $buildRecurBlock = TRUE;
             $this->add('hidden', 'hidden_DirectDebit', 1);
             CRM_Core_Payment_Form::buildDirectDebit($this, TRUE);
         } else {
             eval('CRM_Contribute_Form_AdditionalInfo::build' . $type . '( $this );');
         }
     }
     if (empty($this->_recurPaymentProcessors)) {
         $buildRecurBlock = FALSE;
     }
     if ($buildRecurBlock) {
         CRM_Contribute_Form_Contribution_Main::buildRecur($this);
         $this->setDefaults(array('is_recur' => 0));
     }
     $this->assign('buildRecurBlock', $buildRecurBlock);
     $qfKey = $this->controller->_key;
     $this->assign('qfKey', $qfKey);
     $this->assign('allPanes', $allPanes);
     $this->assign('showAdditionalInfo', $showAdditionalInfo);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     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;
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Contribution');
     $this->assign('customDataSubType', $this->_contributionType);
     $this->assign('entityID', $this->_id);
     if ($this->_context == 'standalone') {
         CRM_Contact_Form_NewContact::buildQuickForm($this);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     $element = $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), TRUE, array('onChange' => "buildCustomData( 'Contribution', this.value );"));
     if ($this->_online) {
         $element->freeze();
     }
     if (!$this->_mode) {
         $element = $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
         if ($this->_online) {
             $element->freeze();
         }
     }
     $element = $this->add('text', 'trxn_id', ts('Transaction ID'), $attributes['trxn_id']);
     if ($this->_online) {
         $element->freeze();
     } else {
         $this->addRule('trxn_id', ts('This Transaction ID already exists in the database. Include the account number for checks.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
     }
     //add receipt for offline contribution
     $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $status = CRM_Contribute_PseudoConstant::contributionStatus();
     // supressing contribution statuses that are NOT relevant to pledges (CRM-5169)
     if ($this->_ppID) {
         $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         foreach (array('Cancelled', 'Failed', 'In Progress') as $supress) {
             unset($status[CRM_Utils_Array::key($supress, $statusName)]);
         }
     }
     $this->add('select', 'contribution_status_id', ts('Contribution Status'), $status, FALSE, array('onClick' => "if (this.value != 3) {  status();} else return false", 'onChange' => "return showHideByValue('contribution_status_id','3','cancelInfo','table-row','select',false);"));
     // add various dates
     $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
     if ($this->_online) {
         $this->assign('hideCalender', TRUE);
     }
     $element = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']);
     if ($this->_online) {
         $element->freeze();
     }
     $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('cancel_date', ts('Cancelled Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('textarea', 'cancel_reason', ts('Cancellation Reason'), $attributes['cancel_reason']);
     $recurJs = NULL;
     if ($buildRecurBlock) {
         $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
     }
     $element = $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL, $recurJs);
     if ($this->_online) {
         $element->freeze();
     }
     if (empty($this->_lineItems)) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_Set::getAssoc(FALSE, 'CiviContribute');
         if (!empty($priceSets) && !$this->_ppID) {
             $buildPriceSet = TRUE;
         }
         // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
         // and if we already have line items for that participant. CRM-5095
         if ($buildPriceSet && $this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'id', 'contribution_id');
             if ($pledgePaymentId) {
                 $buildPriceSet = FALSE;
             }
             if ($participantID = CRM_Utils_Array::value('participant', $componentDetails)) {
                 $participantLI = CRM_Price_BAO_LineItem::getLineItems($participantID);
                 if (!CRM_Utils_System::isNull($participantLI)) {
                     $buildPriceSet = FALSE;
                 }
             }
         }
         $hasPriceSets = FALSE;
         if ($buildPriceSet) {
             $hasPriceSets = TRUE;
             $element = $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
             if ($this->_online) {
                 $element->freeze();
             }
         }
         $this->assign('hasPriceSets', $hasPriceSets);
         $currencyFreeze = FALSE;
         if ($this->_online || $this->_ppID) {
             $attributes['total_amount'] = array_merge($attributes['total_amount'], array('READONLY' => TRUE, 'style' => "background-color:#EBECE4"));
             $optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?'));
             $element = $this->addRadio('option_type', NULL, $optionTypes, array(), '<br/>');
             $currencyFreeze = TRUE;
         }
         $element = $this->addMoney('total_amount', ts('Total Amount'), $hasPriceSets ? FALSE : TRUE, $attributes['total_amount'], TRUE, 'currency', NULL, $currencyFreeze);
     }
     $element = $this->add('text', 'source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     // CRM-7368 allow user to set or edit PCP link for contributions
     $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage();
     if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) {
         $this->assign('siteHasPCPs', 1);
         $pcpDataUrl = CRM_Utils_System::url('civicrm/ajax/rest', "className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1", FALSE, NULL, FALSE);
         $this->assign('pcpDataUrl', $pcpDataUrl);
         $this->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page'));
         $this->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id'));
         $this->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
         $this->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
         $this->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
     }
     $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest', "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&reset=1&context=softcredit&id={$this->_id}", FALSE, NULL, FALSE);
     $this->assign('dataUrl', $dataUrl);
     $this->addElement('text', 'soft_credit_to', ts('Soft Credit To'));
     // Tell tpl to hide Soft Credit field if contribution is linked directly to a PCP Page
     if (CRM_Utils_Array::value('pcp_made_through_id', $this->_values)) {
         $this->assign('pcpLinked', 1);
     }
     $this->addElement('hidden', 'soft_contact_id', '', array('id' => 'soft_contact_id'));
     $js = NULL;
     if (!$this->_mode) {
         $js = array('onclick' => "return verify( );");
     }
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => $js, 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }