3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
38 class CRM_Core_SelectValues
{
45 public static function boolean() {
53 * Preferred mail format.
57 public static function pmf() {
70 public static function privacy() {
72 'do_not_phone' => ts('Do not phone'),
73 'do_not_email' => ts('Do not email'),
74 'do_not_mail' => ts('Do not mail'),
75 'do_not_sms' => ts('Do not sms'),
76 'do_not_trade' => ts('Do not trade'),
77 'is_opt_out' => ts('No bulk emails (User Opt Out)'),
82 * Various pre defined contact super types.
86 public static function contactType() {
87 static $contactType = NULL;
89 $contactType = CRM_Contact_BAO_ContactType
::basicTypePairs();
95 * Various pre defined unit list.
97 * @param string $unitType
100 public static function unitList($unitType = NULL) {
103 'month' => ts('month'),
104 'year' => ts('year'),
106 if ($unitType == 'duration') {
107 $unitList['lifetime'] = ts('lifetime');
113 * Membership type unit.
117 public static function membershipTypeUnitList() {
118 return self
::unitList('duration');
122 * Various pre defined period types.
126 public static function periodType() {
128 'rolling' => ts('Rolling'),
129 'fixed' => ts('Fixed'),
134 * Various pre defined email selection methods.
138 public static function emailSelectMethods() {
140 'automatic' => ts("Automatic"),
141 'location-only' => ts("Only send to email addresses assigned to the specified location"),
142 'location-prefer' => ts("Prefer email addresses assigned to the specified location"),
143 'location-exclude' => ts("Exclude email addresses assigned to the specified location"),
148 * Various pre defined member visibility options.
152 public static function memberVisibility() {
154 'Public' => ts('Public'),
155 'Admin' => ts('Admin'),
160 * Member auto-renew options
164 public static function memberAutoRenew() {
166 ts('No auto-renew option'),
167 ts('Give option, but not required'),
168 ts('Auto-renew required'),
173 * Various pre defined event dates.
177 public static function eventDate() {
179 'start_date' => ts('start date'),
180 'end_date' => ts('end date'),
181 'join_date' => ts('member since'),
186 * Custom form field types.
190 public static function customHtmlType() {
192 'Text' => ts('Single-line input field (text or numeric)'),
193 'TextArea' => ts('Multi-line text box (textarea)'),
194 'Select' => ts('Drop-down (select list)'),
195 'Radio' => ts('Radio buttons'),
196 'CheckBox' => ts('Checkbox(es)'),
197 'Select Date' => ts('Select Date'),
198 'File' => ts('File'),
199 'Select State/Province' => ts('Select State/Province'),
200 'Multi-Select State/Province' => ts('Multi-Select State/Province'),
201 'Select Country' => ts('Select Country'),
202 'Multi-Select Country' => ts('Multi-Select Country'),
203 'RichTextEditor' => ts('Rich Text Editor'),
204 'Autocomplete-Select' => ts('Autocomplete-Select'),
205 'Multi-Select' => ts('Multi-Select'),
206 'AdvMulti-Select' => ts('AdvMulti-Select'),
207 'Link' => ts('Link'),
208 'ContactReference' => ts('Autocomplete-Select'),
213 * Various pre defined extensions for dynamic properties and groups.
218 public static function customGroupExtends() {
219 $customGroupExtends = array(
220 'Activity' => ts('Activities'),
221 'Relationship' => ts('Relationships'),
222 'Contribution' => ts('Contributions'),
223 'Group' => ts('Groups'),
224 'Membership' => ts('Memberships'),
225 'Event' => ts('Events'),
226 'Participant' => ts('Participants'),
227 'ParticipantRole' => ts('Participants (Role)'),
228 'ParticipantEventName' => ts('Participants (Event Name)'),
229 'ParticipantEventType' => ts('Participants (Event Type)'),
230 'Pledge' => ts('Pledges'),
231 'Grant' => ts('Grants'),
232 'Address' => ts('Addresses'),
233 'Campaign' => ts('Campaigns'),
235 $contactTypes = self
::contactType();
236 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
237 $extendObjs = CRM_Core_OptionGroup
::values('cg_extend_objects');
238 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
239 return $customGroupExtends;
243 * Styles for displaying the custom data group.
247 public static function customGroupStyle() {
250 'Inline' => ts('Inline'),
251 'Tab with table' => ts('Tab with table'),
256 * For displaying the uf group types.
260 public static function ufGroupTypes() {
261 $ufGroupType = array(
262 'Profile' => ts('Standalone Form or Directory'),
263 'Search Profile' => ts('Search Views'),
266 if (CRM_Core_Config
::singleton()->userSystem
->supports_form_extensions
) {
267 $ufGroupType +
= array(
268 'User Registration' => ts('Drupal User Registration'),
269 'User Account' => ts('View/Edit Drupal User Account'),
276 * The status of a contact within a group.
280 public static function groupContactStatus() {
282 'Added' => ts('Added'),
283 'Removed' => ts('Removed'),
284 'Pending' => ts('Pending'),
289 * List of Group Types.
293 public static function groupType() {
295 'query' => ts('Dynamic'),
296 'static' => ts('Static'),
301 * Compose the parameters for a date select object.
303 * @param string|NULL $type
305 * @param string|NULL $format
306 * date format (QF format)
307 * @param null $minOffset
308 * @param null $maxOffset
313 public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
315 'addEmptyOption' => TRUE,
316 'emptyOptionText' => ts('- select -'),
317 'emptyOptionValue' => '',
321 $date['format'] = $format;
325 $dao = new CRM_Core_DAO_PreferencesDate();
327 if (!$dao->find(TRUE)) {
328 CRM_Core_Error
::fatal();
332 if ($type == 'creditCard') {
333 $minOffset = $dao->start
;
334 $maxOffset = $dao->end
;
335 $date['format'] = $dao->date_format
;
336 $date['addEmptyOption'] = TRUE;
337 $date['emptyOptionText'] = ts('- select -');
338 $date['emptyOptionValue'] = '';
341 if (empty($date['format'])) {
342 $date['format'] = 'M d';
347 $date['minYear'] = $year - $minOffset;
348 $date['maxYear'] = $year +
$maxOffset;
353 * Values for UF form visibility options.
357 public static function ufVisibility() {
359 'User and User Admin Only' => ts('User and User Admin Only'),
360 'Public Pages' => ts('Public Pages'),
361 'Public Pages and Listings' => ts('Public Pages and Listings'),
366 * Values for group form visibility options.
370 public static function groupVisibility() {
372 'User and User Admin Only' => ts('User and User Admin Only'),
373 'Public Pages' => ts('Public Pages'),
378 * Different type of Mailing Components.
382 public static function mailingComponents() {
384 'Header' => ts('Header'),
385 'Footer' => ts('Footer'),
386 'Reply' => ts('Reply Auto-responder'),
387 'OptOut' => ts('Opt-out Message'),
388 'Subscribe' => ts('Subscription Confirmation Request'),
389 'Welcome' => ts('Welcome Message'),
390 'Unsubscribe' => ts('Unsubscribe Message'),
391 'Resubscribe' => ts('Resubscribe Message'),
400 public function getHours() {
402 for ($i = 0; $i <= 6; $i++
) {
413 public function getMinutes() {
415 for ($i = 0; $i < 60; $i = $i +
15) {
422 * Get the Map Provider.
425 * array of map providers
427 public static function mapProvider() {
430 $map = CRM_Utils_System
::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
436 * Get the Geocoding Providers from available plugins.
439 * array of geocoder providers
441 public static function geoProvider() {
444 $geo = CRM_Utils_System
::getPluginList('CRM/Utils/Geocode');
450 * Get the Address Standardization Providers from available plugins.
453 * array of address standardization providers
455 public static function addressProvider() {
458 $addr = CRM_Utils_System
::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate'));
464 * Different type of Mailing Tokens.
468 public static function mailingTokens() {
470 '{action.unsubscribe}' => ts('Unsubscribe via email'),
471 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
472 '{action.resubscribe}' => ts('Resubscribe via email'),
473 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
474 '{action.optOut}' => ts('Opt out via email'),
475 '{action.optOutUrl}' => ts('Opt out via web page'),
476 '{action.forward}' => ts('Forward this email (link)'),
477 '{action.reply}' => ts('Reply to this email (link)'),
478 '{action.subscribeUrl}' => ts('Subscribe via web page'),
479 '{domain.name}' => ts('Domain name'),
480 '{domain.address}' => ts('Domain (organization) address'),
481 '{domain.phone}' => ts('Domain (organization) phone'),
482 '{domain.email}' => ts('Domain (organization) email'),
483 '{mailing.name}' => ts('Mailing name'),
484 '{mailing.group}' => ts('Mailing group'),
485 '{mailing.viewUrl}' => ts('Mailing permalink'),
490 * Different type of Activity Tokens.
494 public static function activityTokens() {
496 '{activity.activity_id}' => ts('Activity ID'),
497 '{activity.subject}' => ts('Activity Subject'),
498 '{activity.details}' => ts('Activity Details'),
499 '{activity.activity_date_time}' => ts('Activity Date Time'),
504 * Different type of Membership Tokens.
508 public static function membershipTokens() {
510 '{membership.id}' => ts('Membership ID'),
511 '{membership.status}' => ts('Membership Status'),
512 '{membership.type}' => ts('Membership Type'),
513 '{membership.start_date}' => ts('Membership Start Date'),
514 '{membership.join_date}' => ts('Membership Join Date'),
515 '{membership.end_date}' => ts('Membership End Date'),
516 '{membership.fee}' => ts('Membership Fee'),
521 * Different type of Event Tokens.
525 public static function eventTokens() {
527 '{event.event_id}' => ts('Event ID'),
528 '{event.title}' => ts('Event Title'),
529 '{event.start_date}' => ts('Event Start Date'),
530 '{event.end_date}' => ts('Event End Date'),
531 '{event.event_type}' => ts('Event Type'),
532 '{event.summary}' => ts('Event Summary'),
533 '{event.contact_email}' => ts('Event Contact Email'),
534 '{event.contact_phone}' => ts('Event Contact Phone'),
535 '{event.description}' => ts('Event Description'),
536 '{event.location}' => ts('Event Location'),
537 '{event.fee_amount}' => ts('Event Fees'),
538 '{event.info_url}' => ts('Event Info URL'),
539 '{event.registration_url}' => ts('Event Registration URL'),
540 '{event.balance}' => ts('Event Balance'),
545 * Different type of Event Tokens.
549 public static function contributionTokens() {
551 '{contribution.contribution_id}' => ts('Contribution ID'),
552 '{contribution.total_amount}' => ts('Total Amount'),
553 '{contribution.fee_amount}' => ts('Fee Amount'),
554 '{contribution.net_amount}' => ts('Net Amount'),
555 '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
556 '{contribution.receive_date}' => ts('Contribution Date Received'),
557 '{contribution.payment_instrument}' => ts('Payment Method'),
558 '{contribution.trxn_id}' => ts('Transaction ID'),
559 '{contribution.invoice_id}' => ts('Invoice ID'),
560 '{contribution.currency}' => ts('Currency'),
561 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
562 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
563 '{contribution.receipt_date}' => ts('Receipt Date'),
564 '{contribution.thankyou_date}' => ts('Thank You Date'),
565 '{contribution.contribution_source}' => ts('Contribution Source'),
566 '{contribution.amount_level}' => ts('Amount Level'),
567 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
568 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
569 '{contribution.contribution_status_id}' => ts('Contribution Status'),
570 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
571 //'{contribution.address_id}' => ts('Address ID'),
572 '{contribution.check_number}' => ts('Check Number'),
573 '{contribution.campaign}' => ts('Contribution Campaign'),
578 * Different type of Contact Tokens.
582 public static function contactTokens() {
583 static $tokens = NULL;
585 $additionalFields = array(
586 'checksum' => array('title' => ts('Checksum')),
587 'contact_id' => array('title' => ts('Internal Contact ID')),
589 $exportFields = array_merge(CRM_Contact_BAO_Contact
::exportableFields(), $additionalFields);
591 $values = array_merge(array_keys($exportFields));
594 //FIXME:skipping some tokens for time being.
608 $customFields = CRM_Core_BAO_CustomField
::getFields(array('Individual', 'Address'));
609 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
611 foreach ($values as $val) {
612 if (in_array($val, $skipTokens)) {
615 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
616 $customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val);
617 if ($customFieldId) {
618 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
619 if (!empty($customFields[$customFieldId])) {
620 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
624 // Support legacy token names
625 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
626 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
630 // Get all the hook tokens too
631 $hookTokens = array();
632 CRM_Utils_Hook
::tokens($hookTokens);
633 foreach ($hookTokens as $tokenValues) {
634 foreach ($tokenValues as $key => $value) {
635 if (is_numeric($key)) {
638 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
639 $key = '{' . $key . '}';
641 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
642 $value = $matches[1];
644 $tokens[$key] = $value;
653 * Different type of Participant Tokens.
657 public static function participantTokens() {
658 static $tokens = NULL;
660 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
662 $values = array_merge(array_keys($exportFields));
665 // skipping some tokens for time being.
668 'participant_is_pay_later',
669 'participant_is_test',
670 'participant_contact_id',
671 'participant_fee_currency',
672 'participant_campaign_id',
673 'participant_status',
674 'participant_discount_name',
677 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
679 foreach ($values as $key => $val) {
680 if (in_array($val, $skipTokens)) {
683 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
684 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
685 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
688 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
696 * CiviCRM supported date input formats.
700 public static function getDatePluginInputFormats() {
701 $dateInputFormats = array(
702 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
703 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
704 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
705 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
706 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
707 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
708 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
709 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
710 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
711 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
712 "mm/dd" => ts('mm/dd (12/31)'),
713 "dd-mm" => ts('dd-mm (31-12)'),
714 "yy-mm" => ts('yyyy-mm (2009-12)'),
715 'M yy' => ts('M yyyy (Dec 2009)'),
716 "yy" => ts('yyyy (2009)'),
720 Year greater than 2000 get wrong result for following format
721 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
722 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
724 expected :: 2001-11-07
727 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
728 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
732 return $dateInputFormats;
736 * Map date plugin and actual format that is used by PHP.
740 public static function datePluginToPHPFormats() {
741 $dateInputFormats = array(
742 "mm/dd/yy" => 'm/d/Y',
743 "dd/mm/yy" => 'd/m/Y',
744 "yy-mm-dd" => 'Y-m-d',
745 "dd-mm-yy" => 'd-m-Y',
746 "dd.mm.yy" => 'd.m.Y',
747 "M d, yy" => 'M j, Y',
749 "MM d, yy" => 'F j, Y',
750 "d MM yy" => 'j F Y',
751 "DD, d MM yy" => 'l, j F Y',
758 return $dateInputFormats;
766 public static function getTimeFormats() {
768 '1' => ts('12 Hours'),
769 '2' => ts('24 Hours'),
774 * Get numeric options.
781 public static function getNumericOptions($start = 0, $end = 10) {
782 $numericOptions = array();
783 for ($i = $start; $i <= $end; $i++
) {
784 $numericOptions[$i] = $i;
786 return $numericOptions;
794 public static function getBarcodeTypes() {
796 'barcode' => ts('Linear (1D)'),
797 'qrcode' => ts('QR code'),
806 public static function getDedupeRuleTypes() {
808 'Unsupervised' => ts('Unsupervised'),
809 'Supervised' => ts('Supervised'),
810 'General' => ts('General'),
815 * Campaign group types.
819 public static function getCampaignGroupTypes() {
821 'Include' => ts('Include'),
822 'Exclude' => ts('Exclude'),
827 * Subscription history method.
831 public static function getSubscriptionHistoryMethods() {
833 'Admin' => ts('Admin'),
834 'Email' => ts('Email'),
845 public static function getPremiumUnits() {
848 'week' => ts('Week'),
849 'month' => ts('Month'),
850 'year' => ts('Year'),
859 public static function getExtensionTypes() {
861 'payment' => ts('Payment'),
862 'search' => ts('Search'),
863 'report' => ts('Report'),
864 'module' => ts('Module'),
874 public static function getJobFrequency() {
876 '1stOfQtr' => ts('1st day of every quarter'),
877 '1stOfMth' => ts('1st day of every month'),
878 'Mondays' => ts('Monday of every week'),
879 'Daily' => ts('Daily'),
880 'Hourly' => ts('Hourly'),
881 'Always' => ts('Every time cron job is run'),
886 * Search builder operators.
890 public static function getSearchBuilderOperators() {
899 'NOT IN' => ts('Not In'),
900 'LIKE' => ts('Like'),
901 'NOT LIKE' => ts('Not Like'),
902 'RLIKE' => ts('Regex'),
903 'IS EMPTY' => ts('Is Empty'),
904 'IS NOT EMPTY' => ts('Not Empty'),
905 'IS NULL' => ts('Is Null'),
906 'IS NOT NULL' => ts('Not Null'),
911 * Profile group types.
915 public static function getProfileGroupType() {
916 $profileGroupType = array(
917 'Activity' => ts('Activities'),
918 'Contribution' => ts('Contributions'),
919 'Membership' => ts('Memberships'),
920 'Participant' => ts('Participants'),
922 $contactTypes = self
::contactType();
923 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
924 $profileGroupType = array_merge($contactTypes, $profileGroupType);
926 return $profileGroupType;
931 * Word replacement match type.
935 public static function getWordReplacementMatchType() {
937 'exactMatch' => ts('Exact Match'),
938 'wildcardMatch' => ts('Wildcard Match'),
943 * Mailing group types.
947 public static function getMailingGroupTypes() {
949 'Include' => ts('Include'),
950 'Exclude' => ts('Exclude'),
951 'Base' => ts('Base'),
956 * Mailing Job Status.
960 public static function getMailingJobStatus() {
962 'Scheduled' => ts('Scheduled'),
963 'Running' => ts('Running'),
964 'Complete' => ts('Complete'),
965 'Paused' => ts('Paused'),
966 'Canceled' => ts('Canceled'),
973 public static function billingMode() {
975 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
976 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
977 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
982 * Frequency unit for schedule reminders.
988 public static function getRecurringFrequencyUnits($count = 1) {
989 // @todo this used to refer to the 'recur_frequency_unit' option_values which
990 // is for recurring payments and probably not good to re-use for recurring entities.
991 // If something other than a hard-coded list is desired, add a new option_group.
993 'hour' => ts('hour', array('plural' => 'hours', 'count' => $count)),
994 'day' => ts('day', array('plural' => 'days', 'count' => $count)),
995 'week' => ts('week', array('plural' => 'weeks', 'count' => $count)),
996 'month' => ts('month', array('plural' => 'months', 'count' => $count)),
997 'year' => ts('year', array('plural' => 'years', 'count' => $count)),
1002 * Relative Date Terms.
1006 public static function getRelativeDateTerms() {
1008 'previous' => ts('Previous'),
1009 'previous_2' => ts('Previous 2'),
1010 'previous_before' => ts('Prior to Previous'),
1011 'before_previous' => ts('All Prior to Previous'),
1012 'earlier' => ts('To End of Previous'),
1013 'greater_previous' => ts('From End of Previous'),
1014 'greater' => ts('From Start Of Current'),
1015 'current' => ts('Current'),
1016 'ending_3' => ts('Last 3'),
1017 'ending_2' => ts('Last 2'),
1018 'ending' => ts('Last'),
1019 'this' => ts('This'),
1020 'starting' => ts('Upcoming'),
1021 'less' => ts('To End of'),
1022 'next' => ts('Next'),
1027 * Relative Date Units.
1031 public static function getRelativeDateUnits() {
1033 'year' => ts('Years'),
1034 'fiscal_year' => ts('Fiscal Years'),
1035 'quarter' => ts('Quarters'),
1036 'month' => ts('Months'),
1037 'week' => ts('Weeks'),
1038 'day' => ts('Days'),