3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * One place to store frequently used values in Select Elements. Note that
30 * some of the below elements will be dynamic, so we'll probably have a
31 * smart caching scheme on a per domain basis
34 * @copyright CiviCRM LLC (c) 2004-2014
38 class CRM_Core_SelectValues
{
41 * preferred mail format
44 static function pmf() {
56 static function privacy() {
58 'do_not_phone' => ts('Do not phone'),
59 'do_not_email' => ts('Do not email'),
60 'do_not_mail' => ts('Do not mail'),
61 'do_not_sms' => ts('Do not sms'),
62 'do_not_trade' => ts('Do not trade'),
63 'is_opt_out' => ts('No bulk emails (User Opt Out)'),
68 * various pre defined contact super types
71 static function contactType() {
72 static $contactType = NULL;
74 $contactType = CRM_Contact_BAO_ContactType
::basicTypePairs();
80 * various pre defined unit list
83 static function unitList($unitType = NULL) {
86 'month' => ts('month'),
89 if ($unitType == 'duration') {
90 $unitList['lifetime'] = ts('lifetime');
96 * membership type unit
99 static function membershipTypeUnitList( ) {
100 return self
::unitList('duration');
104 * various pre defined period types
107 static function periodType() {
109 'rolling' => ts('Rolling'),
110 'fixed' => ts('Fixed'),
115 * various pre defined email selection methods
118 static function emailSelectMethods() {
120 'automatic' => ts("Automatic"),
121 'location-only' => ts("Only send to email addresses assigned to the specified location"),
122 'location-prefer' => ts("Prefer email addresses assigned to the specified location"),
123 'location-exclude' => ts("Exclude email addresses assigned to the specified location")
128 * various pre defined member visibility options
131 static function memberVisibility() {
133 'Public' => ts('Public'),
134 'Admin' => ts('Admin'),
139 * various pre defined event dates
142 static function eventDate() {
144 'start_date' => ts('start date'),
145 'end_date' => ts('end date'),
146 'join_date' => ts('member since'),
151 * Custom form field types
154 static function customHtmlType() {
156 'Text' => ts('Single-line input field (text or numeric)'),
157 'TextArea' => ts('Multi-line text box (textarea)'),
158 'Select' => ts('Drop-down (select list)'),
159 'Radio' => ts('Radio buttons'),
160 'CheckBox' => ts('Checkbox(es)'),
161 'Select Date' => ts('Select Date'),
162 'File' => ts('File'),
163 'Select State/Province' => ts('Select State/Province'),
164 'Multi-Select State/Province' => ts('Multi-Select State/Province'),
165 'Select Country' => ts('Select Country'),
166 'Multi-Select Country' => ts('Multi-Select Country'),
167 'RichTextEditor' => ts('Rich Text Editor'),
168 'Autocomplete-Select' => ts('Autocomplete-Select'),
169 'Multi-Select' => ts('Multi-Select'),
170 'AdvMulti-Select' => ts('AdvMulti-Select'),
171 'Link' => ts('Link'),
172 'ContactReference' => ts('Autocomplete Select'),
177 * various pre defined extensions for dynamic properties and groups
181 static function customGroupExtends() {
182 $customGroupExtends = array(
183 'Activity' => ts('Activities'),
184 'Relationship' => ts('Relationships'),
185 'Contribution' => ts('Contributions'),
186 'Group' => ts('Groups'),
187 'Membership' => ts('Memberships'),
188 'Event' => ts('Events'),
189 'Participant' => ts('Participants'),
190 'ParticipantRole' => ts('Participants (Role)'),
191 'ParticipantEventName' => ts('Participants (Event Name)'),
192 'ParticipantEventType' => ts('Participants (Event Type)'),
193 'Pledge' => ts('Pledges'),
194 'Grant' => ts('Grants'),
195 'Address' => ts('Addresses'),
196 'Campaign' => ts('Campaigns'),
198 $contactTypes = self
::contactType();
199 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
200 $extendObjs = CRM_Core_OptionGroup
::values('cg_extend_objects');
201 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
202 return $customGroupExtends;
206 * styles for displaying the custom data group
210 static function customGroupStyle() {
213 'Inline' => ts('Inline'),
214 'Tab with table' => ts('Tab with table'),
219 * for displaying the uf group types
223 static function ufGroupTypes() {
224 $ufGroupType = array(
225 'Profile' => ts('Standalone Form or Directory'),
226 'Search Profile' => ts('Search Views'),
229 if (CRM_Core_Config
::singleton()->userSystem
->supports_form_extensions
) {
230 $ufGroupType +
= array(
231 'User Registration' => ts('Drupal User Registration'),
232 'User Account' => ts('View/Edit Drupal User Account'),
239 * the status of a contact within a group
243 static function groupContactStatus() {
245 'Added' => ts('Added'),
246 'Removed' => ts('Removed'),
247 'Pending' => ts('Pending'),
252 * list of Group Types
255 static function groupType() {
257 'query' => ts('Dynamic'),
258 'static' => ts('Static'),
263 * compose the parameters for a date select object
265 * @param string|NULL $type the type of date
266 * @param string|NULL $format date format ( QF format)
268 * @param null $minOffset
269 * @param null $maxOffset
271 * @return array the date array
274 static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
277 'addEmptyOption' => TRUE,
278 'emptyOptionText' => ts('- select -'),
279 'emptyOptionValue' => '',
283 $date['format'] = $format;
287 $dao = new CRM_Core_DAO_PreferencesDate();
289 if (!$dao->find(TRUE)) {
290 CRM_Core_Error
::fatal();
294 if ($type == 'creditCard') {
295 $minOffset = $dao->start
;
296 $maxOffset = $dao->end
;
297 $date['format'] = $dao->date_format
;
298 $date['addEmptyOption'] = TRUE;
299 $date['emptyOptionText'] = ts('- select -');
300 $date['emptyOptionValue'] = '';
303 if (empty($date['format'])) {
304 $date['format'] = 'M d';
309 $date['minYear'] = $year - $minOffset;
310 $date['maxYear'] = $year +
$maxOffset;
315 * values for UF form visibility options
319 static function ufVisibility() {
321 'User and User Admin Only' => ts('User and User Admin Only'),
322 'Public Pages' => ts('Public Pages'),
323 'Public Pages and Listings' => ts('Public Pages and Listings'),
328 * values for group form visibility options
332 static function groupVisibility() {
334 'User and User Admin Only' => ts('User and User Admin Only'),
335 'Public Pages' => ts('Public Pages'),
340 * different type of Mailing Components
345 static function mailingComponents() {
346 return array('Header' => ts('Header'),
347 'Footer' => ts('Footer'),
348 'Reply' => ts('Reply Auto-responder'),
349 'OptOut' => ts('Opt-out Message'),
350 'Subscribe' => ts('Subscription Confirmation Request'),
351 'Welcome' => ts('Welcome Message'),
352 'Unsubscribe' => ts('Unsubscribe Message'),
353 'Resubscribe' => ts('Resubscribe Message'),
358 * Function to get hours
363 function getHours() {
365 for ($i = 0; $i <= 6; $i++
) {
372 * Function to get minutes
377 function getMinutes() {
379 for ($i = 0; $i < 60; $i = $i +
15) {
386 * Function to get the Map Provider
388 * @return array $map array of map providers
391 static function mapProvider() {
394 $map = CRM_Utils_System
::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
400 * Function to get the Geocoding Providers from available plugins
402 * @return array $geo array of geocoder providers
405 static function geoProvider() {
408 $geo = CRM_Utils_System
::getPluginList('CRM/Utils/Geocode');
414 * Function to get the Address Standardization Providers from available
417 * @return array $addr array of address standardization providers
420 static function addressProvider() {
423 $addr = CRM_Utils_System
::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate'));
429 * different type of Mailing Tokens
434 static function mailingTokens() {
436 '{action.unsubscribe}' => ts('Unsubscribe via email'),
437 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
438 '{action.resubscribe}' => ts('Resubscribe via email'),
439 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
440 '{action.optOut}' => ts('Opt out via email'),
441 '{action.optOutUrl}' => ts('Opt out via web page'),
442 '{action.forward}' => ts('Forward this email (link)'),
443 '{action.reply}' => ts('Reply to this email (link)'),
444 '{action.subscribeUrl}' => ts('Subscribe via web page'),
445 '{domain.name}' => ts('Domain name'),
446 '{domain.address}' => ts('Domain (organization) address'),
447 '{domain.phone}' => ts('Domain (organization) phone'),
448 '{domain.email}' => ts('Domain (organization) email'),
449 '{mailing.name}' => ts('Mailing name'),
450 '{mailing.group}' => ts('Mailing group'),
451 '{mailing.viewUrl}' => ts('Mailing permalink'),
456 * different type of Activity Tokens
461 static function activityTokens() {
463 '{activity.activity_id}' => ts('Activity ID'),
464 '{activity.subject}' => ts('Activity Subject'),
465 '{activity.details}' => ts('Activity Details'),
466 '{activity.activity_date_time}' => ts('Activity Date Time'),
471 * different type of Membership Tokens
476 static function membershipTokens() {
478 '{membership.id}' => ts('Membership ID'),
479 '{membership.status}' => ts('Membership Status'),
480 '{membership.type}' => ts('Membership Type'),
481 '{membership.start_date}' => ts('Membership Start Date'),
482 '{membership.join_date}' => ts('Membership Join Date'),
483 '{membership.end_date}' => ts('Membership End Date'),
484 '{membership.fee}' => ts('Membership Fee'),
489 * different type of Event Tokens
494 static function eventTokens() {
496 '{event.event_id}' => ts('Event ID'),
497 '{event.title}' => ts('Event Title'),
498 '{event.start_date}' => ts('Event Start Date'),
499 '{event.end_date}' => ts('Event End Date'),
500 '{event.event_type}' => ts('Event Type'),
501 '{event.summary}' => ts('Event Summary'),
502 '{event.contact_email}' => ts('Event Contact Email'),
503 '{event.contact_phone}' => ts('Event Contact Phone'),
504 '{event.description}' => ts('Event Description'),
505 '{event.location}' => ts('Event Location'),
506 '{event.fee_amount}' => ts('Event Fees'),
507 '{event.info_url}' => ts('Event Info URL'),
508 '{event.registration_url}' => ts('Event Registration URL'),
509 '{event.balance}' => ts('Event Balance')
514 * different type of Event Tokens
519 static function contributionTokens() {
521 '{contribution.contribution_id}' => ts('Contribution ID'),
522 '{contribution.total_amount}' => ts('Total Amount'),
523 '{contribution.fee_amount}' => ts('Fee Amount'),
524 '{contribution.net_amount}' => ts('Net Amount'),
525 '{contribution.non_deductible_amount}' => ts('Non Deductible Amount'),
526 '{contribution.receive_date}' => ts('Contribution Receive Date'),
527 '{contribution.payment_instrument}' => ts('Payment Instrument'),
528 '{contribution.trxn_id}' => ts('Transaction ID'),
529 '{contribution.invoice_id}' => ts('Invoice ID'),
530 '{contribution.currency}' => ts('Currency'),
531 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
532 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
533 '{contribution.receipt_date}' => ts('Receipt Date'),
534 '{contribution.thankyou_date}' => ts('Thank You Date'),
535 '{contribution.contribution_source}' => ts('Contribution Source'),
536 '{contribution.amount_level}' => ts('Amount Level'),
537 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
538 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
539 '{contribution.contribution_status_id}' => ts('Contribution Status'),
540 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
541 //'{contribution.address_id}' => ts('Address ID'),
542 '{contribution.check_number}' => ts('Check Number'),
543 '{contribution.campaign}' => ts('Contribution Campaign'),
548 * different type of Contact Tokens
553 static function contactTokens() {
554 static $tokens = NULL;
556 $additionalFields = array('checksum' => array('title' => ts('Checksum')),
557 'contact_id' => array('title' => ts('Internal Contact ID')),
559 $exportFields = array_merge(CRM_Contact_BAO_Contact
::exportableFields(), $additionalFields);
561 $values = array_merge(array_keys($exportFields));
564 //FIXME:skipping some tokens for time being.
566 'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
567 'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
570 $customFields = CRM_Core_BAO_CustomField
::getFields(array('Individual', 'Address'));
571 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
573 foreach ($values as $val) {
574 if (in_array($val, $skipTokens)) {
577 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
578 $customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val);
579 if ($customFieldId) {
580 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
581 if (!empty($customFields[$customFieldId])) {
582 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
586 // Support legacy token names
587 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
588 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
592 // might as well get all the hook tokens to
593 $hookTokens = array();
594 CRM_Utils_Hook
::tokens($hookTokens);
595 foreach ($hookTokens as $tokenValues) {
596 foreach ($tokenValues as $key => $value) {
597 if (is_numeric($key)) {
600 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
601 $key = '{' . $key . '}';
603 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
604 $value = $matches[1];
606 $tokens[$key] = $value;
615 * different type of Participant Tokens
620 static function participantTokens() {
621 static $tokens = NULL;
623 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
625 $values = array_merge(array_keys($exportFields));
628 // skipping some tokens for time being.
630 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
631 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
634 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
636 foreach ($values as $key => $val) {
637 if (in_array($val, $skipTokens)) {
640 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
641 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
642 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
645 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
653 * CiviCRM supported date input formats
655 static function getDatePluginInputFormats() {
656 $dateInputFormats = array(
657 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
658 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
659 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
660 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
661 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
662 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
663 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
664 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
665 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
666 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
667 "mm/dd" => ts('mm/dd (12/31)'),
668 "dd-mm" => ts('dd-mm (31-12)'),
669 "yy-mm" => ts('yyyy-mm (2009-12)'),
670 'M yy' => ts('M yyyy (Dec 2009)'),
671 "yy" => ts('yyyy (2009)'),
675 Year greater than 2000 get wrong result for following format
676 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
677 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
679 expected :: 2001-11-07
682 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
683 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
688 return $dateInputFormats;
692 * Map date plugin and actual format that is used by PHP
694 static function datePluginToPHPFormats() {
695 $dateInputFormats = array(
696 "mm/dd/yy" => 'm/d/Y',
697 "dd/mm/yy" => 'd/m/Y',
698 "yy-mm-dd" => 'Y-m-d',
699 "dd-mm-yy" => 'd-m-Y',
700 "dd.mm.yy" => 'd.m.Y',
701 "M d, yy" => 'M j, Y',
703 "MM d, yy" => 'F j, Y',
704 "d MM yy" => 'j F Y',
705 "DD, d MM yy" => 'l, j F Y',
712 return $dateInputFormats;
718 static function getTimeFormats() {
720 '1' => ts('12 Hours'),
721 '2' => ts('24 Hours'),
726 * Function to get numeric options
731 public static function getNumericOptions($start = 0, $end = 10) {
732 $numericOptions = array();
733 for ($i = $start; $i <= $end; $i++
) {
734 $numericOptions[$i] = $i;
736 return $numericOptions;
743 static function getBarcodeTypes() {
745 'barcode' => ts('Linear (1D)'),
746 'qrcode' => ts('QR code'),
753 static function getDedupeRuleTypes() {
755 'Unsupervised' => ts('Unsupervised'),
756 'Supervised' => ts('Supervised'),
757 'General' => ts('General'),
762 * campaign group types
764 static function getCampaignGroupTypes() {
766 'Include' => ts('Include'),
767 'Exclude' => ts('Exclude'),
772 * subscription history method
774 static function getSubscriptionHistoryMethods() {
776 'Admin' => ts('Admin'),
777 'Email' => ts('Email'),
786 static function getPremiumUnits() {
789 'week' => ts('Week'),
790 'month' => ts('Month'),
791 'year' => ts('Year'),
798 static function getExtensionTypes() {
800 'payment' => ts('Payment'),
801 'search' => ts('Search'),
802 'report' => ts('Report'),
803 'module' => ts('Module'),
811 static function getJobFrequency() {
813 'Daily' => ts('Daily'),
814 'Hourly' => ts('Hourly'),
815 'Always' => ts('Every time cron job is run'),
820 * Search builder operators
822 static function getSearchBuilderOperators() {
831 'LIKE' => ts('Like'),
832 'RLIKE' => ts('Regex'),
833 'IS EMPTY' => ts('Is Empty'),
834 'IS NOT EMPTY' => ts('Not Empty'),
835 'IS NULL' => ts('Is Null'),
836 'IS NOT NULL' => ts('Not Null'),
841 * profile group types
845 static function getProfileGroupType() {
846 $profileGroupType = array(
847 'Activity' => ts('Activities'),
848 'Contribution' => ts('Contributions'),
849 'Membership' => ts('Memberships'),
850 'Participant' => ts('Participants'),
852 $contactTypes = self
::contactType();
853 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
854 $profileGroupType = array_merge($contactTypes, $profileGroupType );
856 return $profileGroupType;
861 * word replacement match type
863 static function getWordReplacementMatchType() {
865 'exactMatch' => ts('Exact Match'),
866 'wildcardMatch' => ts('Wildcard Match'),
871 * mailing group types
873 static function getMailingGroupTypes() {
875 'Include' => ts('Include'),
876 'Exclude' => ts('Exclude'),
877 'Base' => ts('Base'),
884 static function getMailingJobStatus() {
886 'Scheduled' => ts('Scheduled'),
887 'Running' => ts('Running'),
888 'Complete' => ts('Complete'),
889 'Paused' => ts('Paused'),
890 'Canceled' => ts('Canceled'),
894 static function billingMode() {
896 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
897 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
898 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
903 * Frequency unit for schedule reminders
905 static function getScheduleReminderFrequencyUnits() {
906 //@todo update schema to refer to option group direct & remove this
907 static $scheduleReminderFrequencyUnits = NULL;
908 if (!$scheduleReminderFrequencyUnits) {
909 $scheduleReminderFrequencyUnits = array(
910 'hour' => ts('hour')) + CRM_Core_OptionGroup
::values('recur_frequency_units');
913 return $scheduleReminderFrequencyUnits;