Пример #1
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Member/BAO/MembershipType.php';
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes();
     if (!empty($membershipTypes)) {
         $this->addElement('checkbox', 'is_active', ts('Membership Section Enabled?'), null, array('onclick' => "memberBlock(this);"));
         $this->addElement('text', 'new_title', ts('Title - New Membership'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_title'));
         $this->addWysiwyg('new_text', ts('Introductory Message - New Memberships'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_text'));
         $this->addElement('text', 'renewal_title', ts('Title - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_title'));
         $this->addWysiwyg('renewal_text', ts('Introductory Message - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_text'));
         $this->addElement('checkbox', 'is_required', ts('Require Membership Signup'));
         $this->addElement('checkbox', 'display_min_fee', ts('Display Membership Fee'));
         $this->addElement('checkbox', 'is_separate_payment', ts('Separate Membership Payment'));
         $membership = array();
         $membershipDefault = array();
         foreach ($membershipTypes as $k => $v) {
             $membership[] = HTML_QuickForm::createElement('advcheckbox', $k, null, $v);
             $membershipDefault[] = HTML_QuickForm::createElement('radio', null, null, null, $k);
         }
         $this->addGroup($membership, 'membership_type', ts('Membership Types'));
         $this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default'));
         $this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id);
     }
     $session =& CRM_Core_Session::singleton();
     $single = $session->get('singleForm');
     if ($single) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '         ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     } else {
         parent::buildQuickForm();
     }
     //$session->set('single', false );
 }
Пример #2
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Member/BAO/MembershipType.php';
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes();
     if (!empty($membershipTypes)) {
         $this->addElement('checkbox', 'is_active', ts('Membership Section Enabled?'), null, array('onclick' => "memberBlock(this);"));
         $this->addElement('text', 'new_title', ts('Title - New Membership'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_title'));
         $this->addWysiwyg('new_text', ts('Introductory Message - New Memberships'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_text'));
         $this->addElement('text', 'renewal_title', ts('Title - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_title'));
         $this->addWysiwyg('renewal_text', ts('Introductory Message - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_text'));
         $this->addElement('checkbox', 'is_required', ts('Require Membership Signup'));
         $this->addElement('checkbox', 'display_min_fee', ts('Display Membership Fee'));
         $this->addElement('checkbox', 'is_separate_payment', ts('Separate Membership Payment'));
         $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(false, false, 'is_recur = 1');
         $paymentProcessorId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'payment_processor_id');
         $isRecur = false;
         $membership = array();
         $membershipDefault = array();
         foreach ($membershipTypes as $k => $v) {
             $membership[] = HTML_QuickForm::createElement('advcheckbox', $k, null, $v);
             $membershipDefault[] = HTML_QuickForm::createElement('radio', null, null, null, $k);
             if (is_array($paymentProcessor) && CRM_Utils_Array::value($paymentProcessorId, $paymentProcessor)) {
                 $isRecur = true;
                 $autoRenew = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $k, 'auto_renew');
                 $autoRenewOptions = array();
                 if ($autoRenew) {
                     $autoRenewOptions = array(ts('Not offered'), ts('Give option'), ts('Required'));
                     $this->addElement('select', "auto_renew_{$k}", ts('Auto-renew'), $autoRenewOptions);
                     $this->_renewOption[$k] = $autoRenew;
                 }
             } else {
                 $isRecur = false;
             }
         }
         $this->assign('is_recur', $isRecur);
         $this->assign('auto_renew', $this->_renewOption);
         $this->addGroup($membership, 'membership_type', ts('Membership Types'));
         $this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default'));
         $this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id);
     }
     $session = CRM_Core_Session::singleton();
     $single = $session->get('singleForm');
     if ($single) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '         ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     } else {
         parent::buildQuickForm();
     }
     //$session->set('single', false );
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::COPY)) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $element = $this->add('text', 'code', ts('Discount Code'), CRM_Core_DAO::getAttribute('CRM_CiviDiscount_DAO_Item', 'code'), TRUE);
     $this->addRule('code', ts('Code already exists in Database.'), 'objectExists', array('CRM_CiviDiscount_DAO_Item', $this->_id, 'code'));
     $this->addRule('code', ts('Code can only consist of alpha-numeric characters'), 'variable');
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $element->freeze();
     }
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_CiviDiscount_DAO_Item', 'description'));
     $this->addMoney('amount', ts('Discount Amount'), TRUE, CRM_Core_DAO::getAttribute('CRM_CiviDiscount_DAO_Item', 'amount'), FALSE);
     $this->add('select', 'amount_type', NULL, array(1 => ts('Percent'), 2 => ts('Fixed Amount')), TRUE);
     $this->add('text', 'count_max', ts('Usage Limit'), CRM_Core_DAO::getAttribute('CRM_CiviDiscount_DAO_Item', 'count_max') + array('min' => 1));
     $this->addRule('count_max', ts('Must be an integer'), 'integer');
     $this->addDate('active_on', ts('Activation Date'), FALSE);
     $this->addDate('expire_on', ts('Expiration Date'), FALSE);
     $this->addEntityRef('organization_id', ts('Organization'), array('api' => array('params' => array('contact_type' => 'Organization'))));
     // is this discount active ?
     $this->addElement('checkbox', 'is_active', ts('Is this discount active?'));
     $this->addElement('checkbox', 'discount_msg_enabled', ts('Display a message to users not eligible for this discount?'));
     $this->add('textarea', 'discount_msg', ts('Message to non-eligible users'), array('class' => 'big'));
     // add memberships, events, pricesets
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     if (!empty($membershipTypes)) {
         $this->add('select', 'memberships', ts('Memberships'), $membershipTypes, FALSE, $this->select2style);
     }
     $this->assignAutoDiscountFields();
     $this->addElement('text', 'advanced_autodiscount_filter_entity', ts('Specify entity for advanced autodiscount'));
     $this->addElement('text', 'advanced_autodiscount_filter_string', ts('Specify api string for advanced filter'), array('class' => 'huge'));
     $events = CRM_CiviDiscount_Utils::getEvents();
     if (!empty($events)) {
         $events = array(ts('--any event--')) + $events;
         $this->_multiValued['events'] = $events;
         $this->add('select', 'events', ts('Events'), $events, FALSE, $this->select2style);
         $eventTypes = $this->getOptions('event', 'event_type_id');
         $this->_multiValued['eventtypes'] = $eventTypes;
         $this->add('select', 'event_type_id', ts('Event Types'), $eventTypes, FALSE, $this->select2style);
     }
     $pricesets = CRM_CiviDiscount_Utils::getNestedPriceSets();
     if (!empty($pricesets)) {
         $this->_multiValued['pricesets'] = $pricesets;
         $this->add('select', 'pricesets', ts('Price Field Options'), $pricesets, FALSE, array('placeholder' => ts('- any -')) + $this->select2style);
     }
 }
Пример #4
0
 /**
  * Browse all custom data groups.
  *
  * @param string $action   the action to be invoked
  *
  * @return void
  * @access public
  */
 function browse($action = NULL)
 {
     // get all custom groups sorted by weight
     $customGroup = array();
     $dao = new CRM_Core_DAO_CustomGroup();
     $dao->orderBy('weight, title');
     $dao->find();
     while ($dao->fetch()) {
         $customGroup[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $customGroup[$dao->id]);
         // form all action links
         $action = array_sum(array_keys($this->actionLinks()));
         // update enable/disable links depending on custom_group properties.
         if ($dao->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $customGroup[$dao->id]['order'] = $customGroup[$dao->id]['weight'];
         $customGroup[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
     }
     $customGroupExtends = CRM_Core_SelectValues::customGroupExtends();
     foreach ($customGroup as $key => $array) {
         CRM_Core_DAO_CustomGroup::addDisplayEnums($customGroup[$key]);
         $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']];
     }
     //fix for Displaying subTypes
     $subTypes = array();
     $subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
     $subTypes['Contribution'] = CRM_Contribute_PseudoConstant::contributionType();
     $subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     $subTypes['Event'] = CRM_Core_OptionGroup::values('event_type');
     $subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type');
     $subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType();
     $subTypes['Participant'] = array();
     $subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role');
     $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event();
     $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type');
     $subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
     $subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
     $subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household');
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $relSubType = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($relSubType as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $subTypes['Relationship'] = $allRelationshipType;
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     $contactSubTypes = array();
     foreach ($cSubTypes as $key => $value) {
         $contactSubTypes[$key] = $key;
     }
     $subTypes['Contact'] = $contactSubTypes;
     CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes);
     foreach ($customGroup as $key => $values) {
         $subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]);
         $subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]);
         $type = CRM_Utils_Array::value('extends', $customGroup[$key]);
         if ($subValue) {
             $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subValue, 1, -1));
             $colValue = NULL;
             foreach ($subValue as $sub) {
                 if ($sub) {
                     if ($type == 'Participant') {
                         if ($subName == 1) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
                         } elseif ($subName == 2) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
                         } elseif ($subName == 3) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
                         }
                     } elseif ($type == 'Relationship') {
                         $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b'];
                         if (isset($subTypes[$type][$sub . '_b_a'])) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a'];
                         }
                     } else {
                         $colValue = $colValue ? $colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '') : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : '');
                     }
                 }
             }
             $customGroup[$key]["extends_entity_column_value"] = $colValue;
         } else {
             if (is_array(CRM_Utils_Array::value($type, $subTypes))) {
                 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
             }
         }
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse");
     CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup', 'id', $returnURL);
     $this->assign('rows', $customGroup);
 }
 public function preProcess()
 {
     //custom data related code
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
     $this->assign('cdType', FALSE);
     if ($this->_cdType) {
         $this->assign('cdType', TRUE);
         return CRM_Custom_Form_CustomData::preProcess($this);
     }
     // get price set id.
     $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
     $this->set('priceSetId', $this->_priceSetId);
     $this->assign('priceSetId', $this->_priceSetId);
     // action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_processors = array();
     CRM_Core_Resources::singleton()->addSetting(array('ids' => array('contact' => $this->_contactID)));
     // check for edit permission
     if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         $contributionID = CRM_Member_BAO_Membership::getMembershipContributionId($this->_id);
         // check delete permission for contribution
         if ($this->_id && $contributionID && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
             CRM_Core_Error::fatal(ts("This Membership is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
         }
     }
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     if ($this->_id) {
         $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
         $this->_membershipIDs[] = $this->_id;
     }
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('membershipMode', $this->_mode);
     if ($this->_mode) {
         $this->_paymentProcessor = array('billing_mode' => 1);
         $validProcessors = array();
         $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'billing_mode IN ( 1, 3 )');
         foreach ($processors as $ppID => $label) {
             $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
                 continue;
             } elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
                 continue;
             } else {
                 $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this);
                 $error = $paymentObject->checkConfig();
                 if (empty($error)) {
                     $validProcessors[$ppID] = $label;
                 }
                 $paymentObject = NULL;
             }
         }
         if (empty($validProcessors)) {
             CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page'));
         } else {
             $this->_processors = $validProcessors;
         }
         // also check for billing information
         // get the billing location type
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
         // CRM-8108 remove ts around Billing location type
         //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
         $this->_bltID = array_search('Billing', $locationTypes);
         if (!$this->_bltID) {
             CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
         }
         $this->set('bltID', $this->_bltID);
         $this->assign('bltID', $this->_bltID);
         $this->_fields = array();
         CRM_Core_Payment_Form::setCreditCardFields($this);
         // this required to show billing block
         $this->assign_by_ref('paymentProcessor', $paymentProcessor);
         $this->assign('hidePayPalExpress', TRUE);
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         if (!CRM_Member_BAO_Membership::statusAvailabilty($this->_contactID)) {
             // all possible statuses are disabled - redirect back to contact form
             CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured'));
         }
         if ($this->_contactID) {
             //check whether contact has a current membership so we can alert user that they may want to do a renewal instead
             $contactMemberships = array();
             $memParams = array('contact_id' => $this->_contactID);
             CRM_Member_BAO_Membership::getValues($memParams, $contactMemberships, TRUE);
             $cMemTypes = array();
             foreach ($contactMemberships as $mem) {
                 $cMemTypes[] = $mem['membership_type_id'];
             }
             if (count($cMemTypes) > 0) {
                 $memberorgs = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($cMemTypes);
                 $mems_by_org = array();
                 foreach ($contactMemberships as $memid => $mem) {
                     $mem['member_of_contact_id'] = CRM_Utils_Array::value($mem['membership_type_id'], $memberorgs);
                     if (CRM_Utils_Array::value('membership_end_date', $mem)) {
                         $mem['membership_end_date'] = CRM_Utils_Date::customformat($mem['membership_end_date']);
                     }
                     $mem['membership_type'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $mem['membership_type_id'], 'name', 'id');
                     $mem['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $mem['status_id'], 'label', 'id');
                     if ($this->_mode) {
                         $mem['renewUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$mem['id']}&context=membership&selectedChild=member&mode=live");
                     } else {
                         $mem['renewUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$mem['id']}&context=membership&selectedChild=member");
                     }
                     $mem['membershipTab'] = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=member");
                     $mems_by_org[$mem['member_of_contact_id']] = $mem;
                 }
                 $resources = CRM_Core_Resources::singleton();
                 $resources->addSetting(array('existingMems' => array('memberorgs' => $mems_by_org)));
                 $resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/Membership.js');
             }
         } else {
             $resources = CRM_Core_Resources::singleton();
             $resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/MembershipStandalone.js');
             $statuses = array();
             $membershipStatus = new CRM_Member_DAO_MembershipStatus();
             $membershipStatus->is_current_member = 1;
             $membershipStatus->find();
             $membershipStatus->selectAdd();
             $membershipStatus->selectAdd('id');
             while ($membershipStatus->fetch()) {
                 $statuses[$membershipStatus->id] = $membershipStatus->label;
             }
             $membershipStatus->free();
             $passthru = array('typeorgs' => CRM_Member_BAO_MembershipType::getMembershipTypeOrganization(), 'memtypes' => CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE), 'statuses' => $statuses);
             $resources->addSetting(array('existingMems' => $passthru));
         }
     }
     // when custom data is included in this page
     if (CRM_Utils_Array::value('hidden_custom', $_POST)) {
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // CRM-4395, get the online pending contribution id.
     $this->_onlinePendingContributionId = NULL;
     if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) {
         $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Membership');
     }
     $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId);
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     // Set title
     if ($this->_contactID) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
         // Check if this is default domain contact CRM-10482
         if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactID)) {
             $displayName .= ' (' . ts('default organization') . ')';
         }
         // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
         CRM_Utils_System::setTitle(ts('Membership for') . ' ' . $displayName);
     }
     parent::preProcess();
 }
Пример #6
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes();
     if (!empty($membershipTypes)) {
         $this->addElement('checkbox', 'member_is_active', ts('Membership Section Enabled?'));
         $this->addElement('text', 'new_title', ts('Title - New Membership'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_title'));
         $this->add('wysiwyg', 'new_text', ts('Introductory Message - New Memberships'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'new_text'));
         $this->addElement('text', 'renewal_title', ts('Title - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_title'));
         $this->add('wysiwyg', 'renewal_text', ts('Introductory Message - Renewals'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipBlock', 'renewal_text'));
         $this->addElement('checkbox', 'is_required', ts('Require Membership Signup'));
         $this->addElement('checkbox', 'display_min_fee', ts('Display Membership Fee'));
         $this->addElement('checkbox', 'is_separate_payment', ts('Separate Membership Payment'));
         $this->addElement('text', 'membership_type_label', ts('Membership Types Label'), array('placeholder' => ts('Membership')));
         $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
         $paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'payment_processor');
         $paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds);
         $isRecur = TRUE;
         foreach ($paymentProcessorId as $dontCare => $id) {
             if (!array_key_exists($id, $paymentProcessor)) {
                 $isRecur = FALSE;
                 continue;
             }
         }
         $membership = $membershipDefault = $params = array();
         foreach ($membershipTypes as $k => $v) {
             $membership[] = $this->createElement('advcheckbox', $k, NULL, $v);
             $membershipDefault[] = $this->createElement('radio', NULL, NULL, NULL, $k);
             $membershipRequired[$k] = NULL;
             if ($isRecur) {
                 $autoRenew = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $k, 'auto_renew');
                 $membershipRequired[$k] = $autoRenew;
                 $autoRenewOptions = array();
                 if ($autoRenew) {
                     $autoRenewOptions = array(ts('Not offered'), ts('Give option'), ts('Required'));
                     $this->addElement('select', "auto_renew_{$k}", ts('Auto-renew'), $autoRenewOptions);
                     //CRM-15573
                     if ($autoRenew == 2) {
                         $this->freeze("auto_renew_{$k}");
                         $params['id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipBlock', $this->_id, 'id', 'entity_id');
                     }
                     $this->_renewOption[$k] = $autoRenew;
                 }
             }
         }
         //CRM-15573
         if (!empty($params['id'])) {
             $params['membership_types'] = serialize($membershipRequired);
             CRM_Member_BAO_MembershipBlock::create($params);
         }
         $this->add('hidden', "mem_price_field_id", '', array('id' => "mem_price_field_id"));
         $this->assign('is_recur', $isRecur);
         if (isset($this->_renewOption)) {
             $this->assign('auto_renew', $this->_renewOption);
         }
         $this->addGroup($membership, 'membership_type', ts('Membership Types'));
         $this->addGroup($membershipDefault, 'membership_type_default', ts('Membership Types Default'))->setAttribute('allowClear', TRUE);
         $this->addFormRule(array('CRM_Member_Form_MembershipBlock', 'formRule'), $this->_id);
     }
     $price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
     if (CRM_Utils_System::isNull($price)) {
         $this->assign('price', FALSE);
     } else {
         $this->assign('price', TRUE);
     }
     $this->add('select', 'member_price_set_id', ts('Membership Price Set'), array('' => ts('- none -')) + $price);
     $session = CRM_Core_Session::singleton();
     $single = $session->get('singleForm');
     if ($single) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '         ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     } else {
         parent::buildQuickForm();
     }
 }
Пример #7
0
 /**
  * Heart of the viewing process. The runner gets all the meta data for
  * the contact and calls the appropriate type of page to view.
  *
  * @return void
  * @access public
  *
  */
 function preProcess()
 {
     //CRM-13901 don't show dashboard to contacts with limited view writes & it does not relect
     //what they have access to
     //@todo implement acls on dashboard querys (preferably via api to enhance that at the same time)
     if (!CRM_Core_Permission::check(array('view all contacts', 'edit all contacts'))) {
         $this->showMembershipSummary = FALSE;
         $this->assign('membershipSummary', FALSE);
         return;
     }
     $this->assign('membershipSummary', TRUE);
     CRM_Utils_System::setTitle(ts('CiviMember'));
     $membershipSummary = array();
     $preMonth = date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
     $preMonthEnd = date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y")));
     $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
     $today = getdate();
     $date = CRM_Utils_Date::getToday();
     $isCurrentMonth = 0;
     // You can force the dashboard to display based upon a certain date
     $ym = CRM_Utils_Array::value('date', $_GET);
     if ($ym) {
         if (preg_match('/^\\d{6}$/', $ym) == 0 || !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || substr($ym, 0, 1) == 0) {
             CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
         }
         $isPreviousMonth = 0;
         $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
         $ymd = date('Y-m-d', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4)));
         $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
         $current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d');
         $ym = substr($ym, 0, 4) . '-' . substr($ym, 4, 2);
     } else {
         $ym = sprintf("%04d-%02d", $today['year'], $today['mon']);
         $ymd = sprintf("%04d-%02d-%02d", $today['year'], $today['mon'], $today['mday']);
         $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
         $current = CRM_Utils_Date::customFormat($date, '%Y-%m-%d');
         $isCurrentMonth = 1;
         $isPreviousMonth = 1;
     }
     $monthStart = $ym . '-01';
     $yearStart = substr($ym, 0, 4) . '-01-01';
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     // added
     //$membership = new CRM_Member_BAO_Membership;
     foreach ($membershipTypes as $key => $value) {
         $membershipSummary[$key]['premonth']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $preMonth, $preMonthEnd), 'name' => $value);
         $membershipSummary[$key]['premonth']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $preMonth, $preMonthEnd), 'name' => $value);
         $membershipSummary[$key]['premonth']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), 'name' => $value);
         $membershipSummary[$key]['month']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $monthStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['month']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $monthStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['month']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['year']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $yearStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['year']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $yearStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['year']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['current']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), 'name' => $value);
         $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd));
         //LCD also get summary stats for membership owners
         $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1), 'name' => $value);
         $membershipSummary[$key]['month_owner']['month_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd, 0, 1), 'name' => $value);
         $membershipSummary[$key]['year_owner']['year_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd, 0, 1), 'name' => $value);
         $membershipSummary[$key]['current_owner']['current_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current, 0, 1), 'name' => $value);
         $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd, 0, 1));
         //LCD end
     }
     // LCD debug
     //CRM_Core_Error::debug($membershipSummary);
     $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
     $status = implode(',', $status);
     /* Disabled for lack of appropriate search
     
            The Membership search isn't able to properly filter by join or renewal events.
            Until that works properly, the subtotals shouldn't get links.
     
         foreach ($membershipSummary as $typeID => $details) {
           foreach ($details as $key => $value) {
             switch ($key) {
               case 'premonth':
                 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$preMonth&joinEnd=$preMonthEnd&start=$preMonth&end=$preMonthEnd");
                 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$prePreMonthEnd&start=$preMonth&end=$preMonthEnd");
                 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd");
                 break;
     
               case 'month':
                 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$monthStart&joinEnd=$ymd&start=$monthStart&end=$ymd");
                 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preMonthStart&start=$monthStart&end=$ymd");
                 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd");
                 break;
     
               case 'year':
                 $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&join=$yearStart&joinEnd=$ymd&start=$yearStart&end=$ymd");
                 $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&joinEnd=$preYearStart&start=$yearStart&end=$ymd");
                 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd");
                 break;
     
               case 'current':
                 $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID");
                 break;
     
               case 'total':
                 if (!$isCurrentMonth) {
                   $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
                     "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID"
                   );
                 }
                 else {
                   $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search',
                     "reset=1&force=1&status=$status"
                   );
                 }
                 break;
     
               //LCD add owner urls
     
               case 'premonth_owner':
                 $membershipSummary[$typeID][$key]['premonth_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$preMonth&end=$preMonthEnd&owner=1");
                 break;
     
               case 'month_owner':
                 $membershipSummary[$typeID][$key]['month_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$monthStart&end=$ymd&owner=1");
                 break;
     
               case 'year_owner':
                 $membershipSummary[$typeID][$key]['year_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&start=$yearStart&end=$ymd&owner=1");
                 break;
     
               case 'current_owner':
                 $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&type=$typeID&owner=1");
                 break;
     
               case 'total_owner':
                 if (!$isCurrentMonth) {
                   $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end=$ymd&status=$status&type=$typeID&owner=1");
                 }
                 else {
                   $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status=$status&owner=1");
                 }
                 break;
               //LCD end
             }
           }
         }
         */
     // Temporary replacement for current totals column
     foreach ($membershipSummary as $typeID => $details) {
         if (!$isCurrentMonth) {
             $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}");
             $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}&owner=1");
         } else {
             $membershipSummary[$typeID]['total']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}");
             $membershipSummary[$typeID]['total_owner']['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&owner=1");
         }
         $membershipSummary[$typeID]['current']['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}");
         $membershipSummary[$typeID]['current_owner']['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&owner=1");
     }
     $totalCount = array();
     $newCountPreMonth = $newCountMonth = $newCountYear = 0;
     $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
     $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
     $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
     foreach ($membershipSummary as $key => $value) {
         $newCountPreMonth = $newCountPreMonth + $value['premonth']['new']['count'];
         $renewCountPreMonth = $renewCountPreMonth + $value['premonth']['renew']['count'];
         $totalCountPreMonth = $totalCountPreMonth + $value['premonth']['total']['count'];
         $newCountMonth = $newCountMonth + $value['month']['new']['count'];
         $renewCountMonth = $renewCountMonth + $value['month']['renew']['count'];
         $totalCountMonth = $totalCountMonth + $value['month']['total']['count'];
         $newCountYear = $newCountYear + $value['year']['new']['count'];
         $renewCountYear = $renewCountYear + $value['year']['renew']['count'];
         $totalCountYear = $totalCountYear + $value['year']['total']['count'];
         $totalCountCurrent = $totalCountCurrent + $value['current']['total']['count'];
         $totalCountTotal = $totalCountTotal + $value['total']['total']['count'];
         //LCD add owner values
         $totalCountPreMonth_owner = $totalCountPreMonth_owner + $value['premonth_owner']['premonth_owner']['count'];
         $totalCountMonth_owner = $totalCountMonth_owner + $value['month_owner']['month_owner']['count'];
         $totalCountYear_owner = $totalCountYear_owner + $value['year_owner']['year_owner']['count'];
         $totalCountCurrent_owner = $totalCountCurrent_owner + $value['current_owner']['current_owner']['count'];
         $totalCountTotal_owner = $totalCountTotal_owner + $value['total_owner']['total_owner']['count'];
     }
     $totalCount['premonth']['new'] = array('count' => $newCountPreMonth);
     $totalCount['premonth']['renew'] = array('count' => $renewCountPreMonth);
     $totalCount['premonth']['total'] = array('count' => $totalCountPreMonth);
     $totalCount['month']['new'] = array('count' => $newCountMonth);
     $totalCount['month']['renew'] = array('count' => $renewCountMonth);
     $totalCount['month']['total'] = array('count' => $totalCountMonth);
     $totalCount['year']['new'] = array('count' => $newCountYear);
     $totalCount['year']['renew'] = array('count' => $renewCountYear);
     $totalCount['year']['total'] = array('count' => $totalCountYear);
     $totalCount['current']['total'] = array('count' => $totalCountCurrent, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"));
     $totalCount['total']['total'] = array('count' => $totalCountTotal, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"));
     if (!$isCurrentMonth) {
         $totalCount['total']['total'] = array('count' => $totalCountTotal, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}"));
     }
     // Activity search also unable to handle owner vs. inherited
     //LCD add owner values
     $totalCount['premonth_owner']['premonth_owner'] = array('count' => $totalCountPreMonth_owner);
     $totalCount['month_owner']['month_owner'] = array('count' => $totalCountMonth_owner);
     $totalCount['year_owner']['year_owner'] = array('count' => $totalCountYear_owner);
     $totalCount['current_owner']['current_owner'] = array('count' => $totalCountCurrent_owner);
     $totalCount['total_owner']['total_owner'] = array('count' => $totalCountTotal_owner);
     if (!$isCurrentMonth) {
         $totalCount['total_owner']['total_owner'] = array('count' => $totalCountTotal_owner);
     }
     //LCD end
     $this->assign('membershipSummary', $membershipSummary);
     $this->assign('totalCount', $totalCount);
     $this->assign('month', date('F', $monthStartTs));
     $this->assign('year', date('Y', $monthStartTs));
     $this->assign('premonth', date('F', strtotime($preMonth)));
     $this->assign('currentMonth', date('F'));
     $this->assign('currentYear', date('Y'));
     $this->assign('isCurrent', $isCurrentMonth);
     $this->assign('preMonth', $isPreviousMonth);
 }
Пример #8
0
 /**
  * check function getMembershipTypes( )
  *
  */
 public function testGetMembershipTypes()
 {
     $ids = array();
     $params = array('name' => 'General', 'description' => NULL, 'minimum_fee' => 100, 'domain_id' => 1, 'duration_unit' => 'year', 'member_of_contact_id' => $this->_orgContactID, 'period_type' => 'fixed', 'duration_interval' => 1, 'financial_type_id' => $this->_financialTypeId, 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1);
     $membership = CRM_Member_BAO_MembershipType::add($params, $ids);
     $result = CRM_Member_BAO_MembershipType::getMembershipTypes();
     $this->assertEquals($result[$membership->id], 'General', 'Verify membership types.');
     $this->membershipTypeDelete(array('id' => $membership->id));
 }
Пример #9
0
 /**
  * Build the form object.
  *
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup');
     //title
     $this->add('text', 'title', ts('Set Name'), $attributes['title'], TRUE);
     //Fix for code alignment, CRM-3058
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $this->assign('contactTypes', json_encode($contactTypes));
     $sel1 = array("" => ts("- select -")) + CRM_Core_SelectValues::customGroupExtends();
     $sel2 = array();
     $activityType = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
     $eventType = CRM_Core_OptionGroup::values('event_type');
     $grantType = CRM_Core_OptionGroup::values('grant_type');
     $campaignTypes = CRM_Campaign_PseudoConstant::campaignType();
     $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     $participantRole = CRM_Core_OptionGroup::values('participant_role');
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household');
     ksort($sel1);
     asort($activityType);
     asort($eventType);
     asort($grantType);
     asort($membershipType);
     asort($participantRole);
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $sel2['Event'] = $eventType;
     $sel2['Grant'] = $grantType;
     $sel2['Activity'] = $activityType;
     $sel2['Campaign'] = $campaignTypes;
     $sel2['Membership'] = $membershipType;
     $sel2['ParticipantRole'] = $participantRole;
     $sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
     $sel2['ParticipantEventType'] = $eventType;
     $sel2['Contribution'] = CRM_Contribute_PseudoConstant::financialType();
     $sel2['Relationship'] = $allRelationshipType;
     $sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
     $sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
     $sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);
     CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($sel2);
     foreach ($sel2 as $main => $sub) {
         if (!empty($sel2[$main])) {
             if ($main == 'Relationship') {
                 $relName = self::getFormattedList($sel2[$main]);
                 $sel2[$main] = array('' => ts("- Any -")) + $relName;
             } else {
                 $sel2[$main] = array('' => ts("- Any -")) + $sel2[$main];
             }
         }
     }
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     if (!empty($cSubTypes)) {
         $contactSubTypes = array();
         foreach ($cSubTypes as $key => $value) {
             $contactSubTypes[$key] = $key;
         }
         $sel2['Contact'] = array("" => "- Any -") + $contactSubTypes;
     } else {
         if (!isset($this->_id)) {
             $formName = 'document.forms.' . $this->_name;
             $js = "<script type='text/javascript'>\n";
             $js .= "{$formName}['extends_1'].style.display = 'none';\n";
             $js .= "</script>";
             $this->assign('initHideBlocks', $js);
         }
     }
     $sel =& $this->add('hierselect', 'extends', ts('Used For'), array('name' => 'extends[0]', 'style' => 'vertical-align: top;'), TRUE);
     $sel->setOptions(array($sel1, $sel2));
     if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
         // make second selector a multi-select -
         $sel->_elements[1]->setMultiple(TRUE);
         $sel->_elements[1]->setSize(5);
     }
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $subName = CRM_Utils_Array::value('extends_entity_column_id', $this->_defaults);
         if ($this->_defaults['extends'] == 'Participant') {
             if ($subName == 1) {
                 $this->_defaults['extends'] = 'ParticipantRole';
             } elseif ($subName == 2) {
                 $this->_defaults['extends'] = 'ParticipantEventName';
             } elseif ($subName == 3) {
                 $this->_defaults['extends'] = 'ParticipantEventType';
             }
         }
         //allow to edit settings if custom set is empty CRM-5258
         $this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id);
         if (!$this->_isGroupEmpty) {
             if (!empty($this->_subtypes)) {
                 // we want to allow adding / updating subtypes for this case,
                 // and therefore freeze the first selector only.
                 $sel->_elements[0]->freeze();
             } else {
                 // freeze both the selectors
                 $sel->freeze();
             }
         }
         $this->assign('isCustomGroupEmpty', $this->_isGroupEmpty);
         $this->assign('gid', $this->_id);
     }
     $this->assign('defaultSubtypes', json_encode($this->_subtypes));
     // help text
     $this->add('wysiwyg', 'help_pre', ts('Pre-form Help'), $attributes['help_pre']);
     $this->add('wysiwyg', 'help_post', ts('Post-form Help'), $attributes['help_post']);
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // display style
     $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle());
     // is this set collapsed or expanded ?
     $this->addElement('checkbox', 'collapse_display', ts('Collapse this set on initial display'));
     // is this set collapsed or expanded ? in advanced search
     $this->addElement('checkbox', 'collapse_adv_display', ts('Collapse this set in Advanced Search'));
     // is this set active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Set active?'));
     // does this set have multiple record?
     $multiple = $this->addElement('checkbox', 'is_multiple', ts('Does this Custom Field Set allow multiple records?'), NULL);
     // $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] );
     // $this->addRule('min_multiple', ts('is a numeric field') , 'numeric');
     $max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']);
     $this->addRule('max_multiple', ts('is a numeric field'), 'numeric');
     //allow to edit settings if custom set is empty CRM-5258
     $this->assign('isGroupEmpty', $this->_isGroupEmpty);
     if (!$this->_isGroupEmpty) {
         $multiple->freeze();
         //$min_multiple->freeze();
         $max_multiple->freeze();
     }
     $this->assign('showStyle', FALSE);
     $this->assign('showMultiple', FALSE);
     $buttons = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     if (!$this->_isGroupEmpty && !empty($this->_subtypes)) {
         $buttons[0]['class'] = 'crm-warnDataLoss';
     }
     $this->addButtons($buttons);
     // TODO: Is this condition ever true? Can this code be removed?
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
     }
 }
 /**
  * Heart of the viewing process. The runner gets all the meta data for
  * the contact and calls the appropriate type of page to view.
  *
  * @return void
  * @access public
  *
  */
 function preProcess()
 {
     CRM_Utils_System::setTitle(ts('CiviMember'));
     $membershipSummary = array();
     $preMonth = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d');
     $preMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d');
     $prePreMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 2, 01, date("Y"))), '%Y%m%d');
     $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
     $today = getdate();
     $date = CRM_Utils_Date::getToday();
     $isCurrentMonth = 0;
     $ym = CRM_Utils_Array::value('date', $_GET);
     if ($ym) {
         if (preg_match('/^\\d{6}$/', $ym) == 0 || !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || substr($ym, 0, 1) == 0) {
             CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
         }
         $isPreviousMonth = 0;
         $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
         $ymd = date('Ymd', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4)));
         $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
         $current = CRM_Utils_Date::customFormat($date, '%Y%m%d');
     } else {
         $ym = sprintf("%04d%02d", $today['year'], $today['mon']);
         $ymd = sprintf("%04d%02d%02d", $today['year'], $today['mon'], $today['mday']);
         $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
         $current = NULL;
         $isCurrentMonth = 1;
         $isPreviousMonth = 1;
     }
     $monthStart = $ym . '01';
     $yearStart = substr($ym, 0, 4) . '0101';
     // $preMonthStart is the day before $monthStart
     $preMonthStart = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, substr($ym, 4, 2) - 1, 01, substr($ym, 0, 4))), '%Y%m%d');
     // $preYearStart is the day before $yearStart
     $preYearStart = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, 12, 31, substr($ym, 0, 4) - 1)), '%Y%m%d');
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     // added
     //$membership = new CRM_Member_BAO_Membership;
     foreach ($membershipTypes as $key => $value) {
         $membershipSummary[$key]['premonth']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $preMonth, $preMonthEnd), 'name' => $value);
         $membershipSummary[$key]['premonth']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $preMonth, $preMonthEnd), 'name' => $value);
         $membershipSummary[$key]['premonth']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), 'name' => $value);
         $membershipSummary[$key]['month']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $monthStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['month']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $monthStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['month']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['year']['new'] = array('count' => CRM_Member_BAO_Membership::getMembershipJoins($key, $yearStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['year']['renew'] = array('count' => CRM_Member_BAO_Membership::getMembershipRenewals($key, $yearStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['year']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['current']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), 'name' => $value);
         $membershipSummary[$key]['total']['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd));
         //LCD also get summary stats for membership owners
         $membershipSummary[$key]['premonth_owner']['premonth_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd, 0, 1), 'name' => $value);
         $membershipSummary[$key]['month_owner']['month_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd, 0, 1), 'name' => $value);
         $membershipSummary[$key]['year_owner']['year_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd, 0, 1), 'name' => $value);
         $membershipSummary[$key]['current_owner']['current_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current, 0, 1), 'name' => $value);
         $membershipSummary[$key]['total_owner']['total_owner'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd, 0, 1));
         //LCD end
     }
     // LCD debug
     //CRM_Core_Error::debug($membershipSummary);
     $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
     $status = implode(',', $status);
     foreach ($membershipSummary as $typeID => $details) {
         foreach ($details as $key => $value) {
             switch ($key) {
                 case 'premonth':
                     $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$preMonth}&joinEnd={$preMonthEnd}&start={$preMonth}&end={$preMonthEnd}");
                     $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$prePreMonthEnd}&start={$preMonth}&end={$preMonthEnd}");
                     $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$preMonth}&end={$preMonthEnd}");
                     break;
                 case 'month':
                     $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$monthStart}&joinEnd={$ymd}&start={$monthStart}&end={$ymd}");
                     $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$preMonthStart}&start={$monthStart}&end={$ymd}");
                     $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$monthStart}&end={$ymd}");
                     break;
                 case 'year':
                     $membershipSummary[$typeID][$key]['new']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&join={$yearStart}&joinEnd={$ymd}&start={$yearStart}&end={$ymd}");
                     $membershipSummary[$typeID][$key]['renew']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&joinEnd={$preYearStart}&start={$yearStart}&end={$ymd}");
                     $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$yearStart}&end={$ymd}");
                     break;
                 case 'current':
                     $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}");
                     break;
                 case 'total':
                     if (!$isCurrentMonth) {
                         $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}");
                     } else {
                         $membershipSummary[$typeID][$key]['total']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}");
                     }
                     break;
                     //LCD add owner urls
                 //LCD add owner urls
                 case 'premonth_owner':
                     $membershipSummary[$typeID][$key]['premonth_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$preMonth}&end={$preMonthEnd}&owner=1");
                     break;
                 case 'month_owner':
                     $membershipSummary[$typeID][$key]['month_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$monthStart}&end={$ymd}&owner=1");
                     break;
                 case 'year_owner':
                     $membershipSummary[$typeID][$key]['year_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$yearStart}&end={$ymd}&owner=1");
                     break;
                 case 'current_owner':
                     $membershipSummary[$typeID][$key]['current_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&owner=1");
                     break;
                 case 'total_owner':
                     if (!$isCurrentMonth) {
                         $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}&owner=1");
                     } else {
                         $membershipSummary[$typeID][$key]['total_owner']['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&owner=1");
                     }
                     break;
                     //LCD end
             }
         }
     }
     // LCD debug
     //CRM_Core_Error::debug($membershipSummary);
     $totalCount = array();
     $newCountPreMonth = $newCountMonth = $newCountYear = 0;
     $renewCountPreMonth = $renewCountMonth = $renewCountYear = 0;
     $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
     $totalCountPreMonth_owner = $totalCountMonth_owner = $totalCountYear_owner = $totalCountCurrent_owner = $totalCountTotal_owner = 0;
     foreach ($membershipSummary as $key => $value) {
         $newCountPreMonth = $newCountPreMonth + $value['premonth']['new']['count'];
         $renewCountPreMonth = $renewCountPreMonth + $value['premonth']['renew']['count'];
         $totalCountPreMonth = $totalCountPreMonth + $value['premonth']['total']['count'];
         $newCountMonth = $newCountMonth + $value['month']['new']['count'];
         $renewCountMonth = $renewCountMonth + $value['month']['renew']['count'];
         $totalCountMonth = $totalCountMonth + $value['month']['total']['count'];
         $newCountYear = $newCountYear + $value['year']['new']['count'];
         $renewCountYear = $renewCountYear + $value['year']['renew']['count'];
         $totalCountYear = $totalCountYear + $value['year']['total']['count'];
         $totalCountCurrent = $totalCountCurrent + $value['current']['total']['count'];
         $totalCountTotal = $totalCountTotal + $value['total']['total']['count'];
         //LCD add owner values
         $totalCountPreMonth_owner = $totalCountPreMonth_owner + $value['premonth_owner']['premonth_owner']['count'];
         $totalCountMonth_owner = $totalCountMonth_owner + $value['month_owner']['month_owner']['count'];
         $totalCountYear_owner = $totalCountYear_owner + $value['year_owner']['year_owner']['count'];
         $totalCountCurrent_owner = $totalCountCurrent_owner + $value['current_owner']['current_owner']['count'];
         $totalCountTotal_owner = $totalCountTotal_owner + $value['total_owner']['total_owner']['count'];
     }
     $totalCount['premonth']['new'] = array('count' => $newCountPreMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&join={$preMonth}&joinEnd={$preMonthEnd}&start={$preMonth}&end={$preMonthEnd}"));
     $totalCount['premonth']['renew'] = array('count' => $renewCountPreMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&joinEnd={$prePreMonthEnd}&start={$preMonth}&end={$preMonthEnd}"));
     $totalCount['premonth']['total'] = array('count' => $totalCountPreMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$preMonth}&end={$preMonthEnd}"));
     $totalCount['month']['new'] = array('count' => $newCountMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&join={$monthStart}&joinEnd={$ymd}&start={$monthStart}&end={$ymd}"));
     $totalCount['month']['renew'] = array('count' => $renewCountMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&joinEnd={$preMonthStart}&start={$monthStart}&end={$ymd}"));
     $totalCount['month']['total'] = array('count' => $totalCountMonth, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$monthStart}&end={$ymd}"));
     $totalCount['year']['new'] = array('count' => $newCountYear, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&join={$yearStart}&joinEnd={$ymd}&start={$yearStart}&end={$ymd}"));
     $totalCount['year']['renew'] = array('count' => $renewCountYear, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&joinEnd={$preYearStart}&start={$yearStart}&end={$ymd}"));
     $totalCount['year']['total'] = array('count' => $totalCountYear, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$yearStart}&end={$ymd}"));
     $totalCount['current']['total'] = array('count' => $totalCountCurrent, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"));
     $totalCount['total']['total'] = array('count' => $totalCountTotal, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"));
     if (!$isCurrentMonth) {
         $totalCount['total']['total'] = array('count' => $totalCountTotal, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}"));
     }
     //LCD add owner values
     $totalCount['premonth_owner']['premonth_owner'] = array('count' => $totalCountPreMonth_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$preMonth}&end={$preMonthEnd}&owner=1"));
     $totalCount['month_owner']['month_owner'] = array('count' => $totalCountMonth_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$monthStart}&end={$ymd}&owner=1"));
     $totalCount['year_owner']['year_owner'] = array('count' => $totalCountYear_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$yearStart}&end={$ymd}&owner=1"));
     $totalCount['current_owner']['current_owner'] = array('count' => $totalCountCurrent_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&owner=1"));
     $totalCount['total_owner']['total_owner'] = array('count' => $totalCountTotal_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&owner=1"));
     if (!$isCurrentMonth) {
         $totalCount['total_owner']['total_owner'] = array('count' => $totalCountTotal_owner, 'url' => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}&owner=1"));
     }
     //LCD end
     $this->assign('membershipSummary', $membershipSummary);
     $this->assign('totalCount', $totalCount);
     $this->assign('month', date('F', $monthStartTs));
     $this->assign('year', date('Y', $monthStartTs));
     $this->assign('premonth', date('F', $preMonthYear));
     $this->assign('currentMonth', date('F'));
     $this->assign('currentYear', date('Y'));
     $this->assign('isCurrent', $isCurrentMonth);
     $this->assign('preMonth', $isPreviousMonth);
 }
Пример #11
0
 /** 
  * Heart of the viewing process. The runner gets all the meta data for 
  * the contact and calls the appropriate type of page to view. 
  * 
  * @return void 
  * @access public 
  * 
  */
 function preProcess()
 {
     require_once "CRM/Member/BAO/MembershipType.php";
     require_once "CRM/Member/BAO/Membership.php";
     CRM_Utils_System::setTitle(ts('CiviMember'));
     $membershipSummary = array();
     $preMonth = CRM_Utils_Date::customFormat(date("Y-m-d", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d');
     $preMonthEnd = CRM_Utils_Date::customFormat(date("Y-m-t", mktime(0, 0, 0, date("m") - 1, 01, date("Y"))), '%Y%m%d');
     $preMonthYear = mktime(0, 0, 0, substr($preMonth, 4, 2), 1, substr($preMonth, 0, 4));
     $today = getdate();
     $date = CRM_Utils_Date::getToday();
     $isCurrentMonth = 0;
     if ($ym = CRM_Utils_Array::value('date', $_GET)) {
         if (preg_match('/^\\d{6}$/', $ym) == 0 || !checkdate(substr($ym, 4, 2), 1, substr($ym, 0, 4)) || substr($ym, 0, 1) == 0) {
             CRM_Core_Error::fatal(ts('Invalid date query "%1" in URL (valid syntax is yyyymm).', array(1 => $ym)));
         }
         $isPreviousMonth = 0;
         $isCurrentMonth = substr($ym, 0, 4) == $today['year'] && substr($ym, 4, 2) == $today['mon'];
         $ymd = date('Ymd', mktime(0, 0, -1, substr($ym, 4, 2) + 1, 1, substr($ym, 0, 4)));
         $monthStartTs = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
         $current = CRM_Utils_Date::customFormat($date, '%Y%m%d');
     } else {
         $ym = sprintf("%04d%02d", $today['year'], $today['mon']);
         $ymd = sprintf("%04d%02d%02d", $today['year'], $today['mon'], $today['mday']);
         $monthStartTs = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
         $current = null;
         $isCurrentMonth = 1;
         $isPreviousMonth = 1;
     }
     $monthStart = $ym . '01';
     $yearStart = substr($ym, 0, 4) . '0101';
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(false);
     //$membership = new CRM_Member_BAO_Membership;//added
     foreach ($membershipTypes as $key => $value) {
         $membershipSummary[$key]['premonth'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $preMonth, $preMonthEnd), 'name' => $value);
         $membershipSummary[$key]['month'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $monthStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['year'] = array('count' => CRM_Member_BAO_Membership::getMembershipStarts($key, $yearStart, $ymd), 'name' => $value);
         $membershipSummary[$key]['current'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $current), 'name' => $value);
         $membershipSummary[$key]['total'] = array('count' => CRM_Member_BAO_Membership::getMembershipCount($key, $ymd));
     }
     require_once "CRM/Member/BAO/MembershipStatus.php";
     $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
     $status = implode(',', $status);
     foreach ($membershipSummary as $typeID => $details) {
         foreach ($details as $key => $value) {
             switch ($key) {
                 case 'premonth':
                     $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$preMonth}&end={$preMonthEnd}");
                     break;
                 case 'month':
                     $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$monthStart}&end={$ymd}");
                     break;
                 case 'year':
                     $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}&start={$yearStart}&end={$ymd}");
                     break;
                 case 'current':
                     $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&type={$typeID}");
                     break;
                 case 'total':
                     if (!$isCurrentMonth) {
                         $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&start=&end={$ymd}&status={$status}&type={$typeID}");
                     } else {
                         $membershipSummary[$typeID][$key]['url'] = CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}");
                     }
                     break;
             }
         }
     }
     $totalCount = array();
     $totalCountPreMonth = $totalCountMonth = $totalCountYear = $totalCountCurrent = $totalCountTotal = 0;
     foreach ($membershipSummary as $key => $value) {
         $totalCountPreMonth = $totalCountPreMonth + $value['premonth']['count'];
         $totalCountMonth = $totalCountMonth + $value['month']['count'];
         $totalCountYear = $totalCountYear + $value['year']['count'];
         $totalCountCurrent = $totalCountCurrent + $value['current']['count'];
         $totalCountTotal = $totalCountTotal + $value['total']['count'];
     }
     $totalCount['premonth'] = array("count" => $totalCountPreMonth, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$preMonth}&end={$preMonthEnd}"));
     $totalCount['month'] = array("count" => $totalCountMonth, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$monthStart}&end={$ymd}"));
     $totalCount['year'] = array("count" => $totalCountYear, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start={$yearStart}&end={$ymd}"));
     $totalCount['current'] = array("count" => $totalCountCurrent, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"));
     $totalCount['total'] = array("count" => $totalCountTotal, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}"));
     if (!$isCurrentMonth) {
         $totalCount['total'] = array("count" => $totalCountTotal, "url" => CRM_Utils_System::url('civicrm/member/search', "reset=1&force=1&status={$status}&start=&end={$ymd}"));
     }
     $this->assign('membershipSummary', $membershipSummary);
     $this->assign('totalCount', $totalCount);
     $this->assign('month', date('F', $monthStartTs));
     $this->assign('year', date('Y', $monthStartTs));
     $this->assign('premonth', date('F', $preMonthYear));
     $this->assign('currentMonth', date('F'));
     $this->assign('currentYear', date('Y'));
     $this->assign('isCurrent', $isCurrentMonth);
     $this->assign('preMonth', $isPreviousMonth);
 }
 function preProcess()
 {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
     require_once 'CRM/Utils/Rule.php';
     if (!CRM_Utils_Rule::positiveInteger($this->_id)) {
         CRM_Core_Error::fatal(ts('We need a valid discount ID for view'));
     }
     $this->assign('id', $this->_id);
     $defaults = array();
     $params = array('id' => $this->_id);
     require_once 'CRM/CiviDiscount/BAO/Item.php';
     CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults);
     $this->assign('code_id', $defaults['id']);
     $this->assign('code', $defaults['code']);
     $this->assign('description', $defaults['description']);
     $this->assign('amount', $defaults['amount']);
     $this->assign('amount_type', $defaults['amount_type']);
     $this->assign('count_use', $defaults['count_use']);
     $this->assign('count_max', $defaults['count_max']);
     $this->assign('is_active', $defaults['is_active']);
     $this->assign('discount_term', $defaults['discount_term']);
     if (array_key_exists('expire_on', $defaults)) {
         $this->assign('expire_on', $defaults['expire_on']);
     }
     if (array_key_exists('active_on', $defaults)) {
         $this->assign('active_on', $defaults['active_on']);
     }
     if (array_key_exists('organization_id', $defaults)) {
         $this->assign('organization_id', $defaults['organization_id']);
         require_once 'CRM/Contact/BAO/Contact.php';
         $orgname = CRM_Contact_BAO_Contact::displayName($defaults['organization_id']);
         $this->assign('organization', $orgname);
     }
     $this->_multiValued = array('autodiscount' => NULL, 'memberships' => NULL, 'events' => NULL, 'pricesets' => NULL, 'pp_types' => NULL);
     foreach ($this->_multiValued as $mv => $info) {
         if (!empty($defaults[$mv])) {
             $v = substr($defaults[$mv], 1, -1);
             $values = explode(CRM_Core_DAO::VALUE_SEPARATOR, $v);
             $defaults[$mv] = array();
             if (!empty($values)) {
                 foreach ($values as $val) {
                     $defaults[$mv][] = $val;
                 }
             }
         }
     }
     require_once 'CRM/CiviDiscount/Utils.php';
     require_once 'CRM/Member/BAO/MembershipType.php';
     if (array_key_exists('pp_types', $defaults)) {
         $pp_types = CRM_CiviDiscount_Utils::getPaymentProcessorTypes();
         $defaults['pp_types'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['pp_types'], $pp_types);
         $this->assign('pp_types', $defaults['pp_types']);
     }
     if (array_key_exists('events', $defaults)) {
         $events = CRM_CiviDiscount_Utils::getEvents();
         $defaults['events'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['events'], $events);
         $this->assign('events', $defaults['events']);
     }
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     if (array_key_exists('memberships', $defaults)) {
         $defaults['memberships'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['memberships'], $membershipTypes);
         $this->assign('memberships', $defaults['memberships']);
     }
     if (array_key_exists('autodiscount', $defaults)) {
         $defaults['autodiscount'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['autodiscount'], $membershipTypes);
         $this->assign('autodiscount', $defaults['autodiscount']);
     }
     if (array_key_exists('pricesets', $defaults)) {
         $priceSets = CRM_CiviDiscount_Utils::getPriceSets();
         $defaults['pricesets'] = CRM_CiviDiscount_Utils::getIdsTitles($defaults['pricesets'], $priceSets);
         $this->assign('pricesets', $defaults['pricesets']);
     }
     CRM_Utils_System::setTitle($defaults['code']);
 }
Пример #13
0
 /**
  * Function to actually build the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup');
     //title
     $this->add('text', 'title', ts('Group Name'), $attributes['title'], true);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_CustomGroup', $this->_id, 'title'));
     //Fix for code alignment, CRM-3058
     require_once "CRM/Contribute/PseudoConstant.php";
     require_once "CRM/Member/BAO/MembershipType.php";
     require_once 'CRM/Event/PseudoConstant.php';
     require_once "CRM/Contact/BAO/Relationship.php";
     require_once 'CRM/Core/OptionGroup.php';
     require_once 'CRM/Contact/BAO/ContactType.php';
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $this->assign('contactTypes', json_encode($contactTypes));
     $sel1 = array("" => "- select -") + CRM_Core_SelectValues::customGroupExtends();
     $sel2 = array();
     $activityType = CRM_Core_PseudoConstant::activityType(false, true);
     $eventType = CRM_Core_OptionGroup::values('event_type');
     $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(false);
     $participantRole = CRM_Core_OptionGroup::values('participant_role');
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Household');
     ksort($sel1);
     asort($activityType);
     asort($eventType);
     asort($membershipType);
     asort($participantRole);
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $val['parent'], false, 'label', true, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $sel2['Event'] = $eventType;
     $sel2['Activity'] = $activityType;
     $sel2['Membership'] = $membershipType;
     $sel2['ParticipantRole'] = $participantRole;
     $sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(null, false, "( is_template IS NULL OR is_template != 1 )");
     $sel2['ParticipantEventType'] = $eventType;
     $sel2['Contribution'] = CRM_Contribute_PseudoConstant::contributionType();
     $sel2['Relationship'] = $allRelationshipType;
     $sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', false, null);
     $sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', false, null);
     $sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', false, null);
     foreach ($sel2 as $main => $sub) {
         if (!empty($sel2[$main])) {
             $sel2[$main] = array('' => ts("- Any -")) + $sel2[$main];
         }
     }
     require_once "CRM/Core/Component.php";
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     if (!empty($cSubTypes)) {
         $contactSubTypes = array();
         foreach ($cSubTypes as $key => $value) {
             $contactSubTypes[$key] = $key;
         }
         $sel2['Contact'] = array("" => "-- Any --") + $contactSubTypes;
     } else {
         if (!isset($this->_id)) {
             $formName = 'document.forms.' . $this->_name;
             $js = "<script type='text/javascript'>\n";
             $js .= "{$formName}['extends[1]'].style.display = 'none';\n";
             $js .= "</script>";
             $this->assign('initHideBlocks', $js);
         }
     }
     $sel =& $this->add('hierselect', 'extends', ts('Used For'), array('onClick' => 'showHideStyle();', 'name' => 'extends[0]', 'style' => 'vertical-align: top;'), true);
     $sel->setOptions(array($sel1, $sel2));
     if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
         // make second selector a multi-select -
         $sel->_elements[1]->setMultiple(true);
         $sel->_elements[1]->setSize(5);
     }
     if ($this->_action == CRM_Core_Action::UPDATE) {
         //allow to edit settings if custom group is empty CRM-5258
         $this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id);
         if (!$this->_isGroupEmpty) {
             if (!empty($this->_subtypes) && count(array_intersect($this->_subtypes, $sel2[$this->_defaults['extends']])) < count($sel2[$this->_defaults['extends']])) {
                 // we want to allow adding subtypes for this case,
                 // and therefore freeze the first selector only.
                 $sel->_elements[0]->freeze();
             } else {
                 // freeze both the selectors
                 $sel->freeze();
             }
         }
         $this->assign('gid', $this->_id);
     }
     // help text
     $this->addWysiwyg('help_pre', ts('Pre-form Help'), $attributes['help_pre']);
     $this->addWysiwyg('help_post', ts('Post-form Help'), $attributes['help_post']);
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // display style
     $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle());
     // is this group collapsed or expanded ?
     $this->addElement('checkbox', 'collapse_display', ts('Collapse this group on initial display'));
     // is this group collapsed or expanded ? in advanced search
     $this->addElement('checkbox', 'collapse_adv_display', ts('Collapse this group in Advanced Search'));
     // is this group active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Group active?'));
     // does this group have multiple record?
     $multiple = $this->addElement('checkbox', 'is_multiple', ts('Does this Custom Data Group allow multiple records?'), null, array('onclick' => "showRange();"));
     // $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] );
     // $this->addRule('min_multiple', ts('is a numeric field') , 'numeric');
     $max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']);
     $this->addRule('max_multiple', ts('is a numeric field'), 'numeric');
     //allow to edit settings if custom group is empty CRM-5258
     $this->assign('isGroupEmpty', $this->_isGroupEmpty);
     if (!$this->_isGroupEmpty) {
         $multiple->freeze();
         //$min_multiple->freeze();
         $max_multiple->freeze();
     }
     $this->assign('showStyle', false);
     $this->assign('showMultiple', false);
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // views are implemented as frozen form
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
     }
 }
Пример #14
0
 function testGetMembershipTypes()
 {
     $ids = array('memberOfContact' => $this->_orgContactID);
     $params = array('name' => 'General', 'description' => null, 'minimum_fee' => 100, 'duration_unit' => 'year', 'period_type' => 'fixed', 'duration_interval' => 1, 'contribution_type_id' => $this->_contributionTypeId, 'relationship_type_id' => $this->_relationshipTypeId, 'visibility' => 'Public', 'is_active' => 1);
     $membership = CRM_Member_BAO_MembershipType::add($params, $ids);
     $result = CRM_Member_BAO_MembershipType::getMembershipTypes();
     $this->assertEquals($result[$membership->id], 'General', 'Verify membership types.');
 }