3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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.
45 public static function pmf() {
58 public static function privacy() {
60 'do_not_phone' => ts('Do not phone'),
61 'do_not_email' => ts('Do not email'),
62 'do_not_mail' => ts('Do not mail'),
63 'do_not_sms' => ts('Do not sms'),
64 'do_not_trade' => ts('Do not trade'),
65 'is_opt_out' => ts('No bulk emails (User Opt Out)'),
70 * Various pre defined contact super types.
74 public static function contactType() {
75 static $contactType = NULL;
77 $contactType = CRM_Contact_BAO_ContactType
::basicTypePairs();
83 * Various pre defined unit list.
85 * @param string $unitType
88 public static function unitList($unitType = NULL) {
91 'month' => ts('month'),
94 if ($unitType == 'duration') {
95 $unitList['lifetime'] = ts('lifetime');
101 * Membership type unit.
105 public static function membershipTypeUnitList() {
106 return self
::unitList('duration');
110 * Various pre defined period types.
114 public static function periodType() {
116 'rolling' => ts('Rolling'),
117 'fixed' => ts('Fixed'),
122 * Various pre defined email selection methods.
126 public static function emailSelectMethods() {
128 'automatic' => ts("Automatic"),
129 'location-only' => ts("Only send to email addresses assigned to the specified location"),
130 'location-prefer' => ts("Prefer email addresses assigned to the specified location"),
131 'location-exclude' => ts("Exclude email addresses assigned to the specified location"),
136 * Various pre defined member visibility options.
140 public static function memberVisibility() {
142 'Public' => ts('Public'),
143 'Admin' => ts('Admin'),
148 * Member auto-renew options
152 public static function memberAutoRenew() {
154 ts('No auto-renew option'),
155 ts('Give option, but not required'),
156 ts('Auto-renew required'),
161 * Various pre defined event dates.
165 public static function eventDate() {
167 'start_date' => ts('start date'),
168 'end_date' => ts('end date'),
169 'join_date' => ts('member since'),
174 * Custom form field types.
178 public static function customHtmlType() {
180 'Text' => ts('Single-line input field (text or numeric)'),
181 'TextArea' => ts('Multi-line text box (textarea)'),
182 'Select' => ts('Drop-down (select list)'),
183 'Radio' => ts('Radio buttons'),
184 'CheckBox' => ts('Checkbox(es)'),
185 'Select Date' => ts('Select Date'),
186 'File' => ts('File'),
187 'Select State/Province' => ts('Select State/Province'),
188 'Multi-Select State/Province' => ts('Multi-Select State/Province'),
189 'Select Country' => ts('Select Country'),
190 'Multi-Select Country' => ts('Multi-Select Country'),
191 'RichTextEditor' => ts('Rich Text Editor'),
192 'Autocomplete-Select' => ts('Autocomplete-Select'),
193 'Multi-Select' => ts('Multi-Select'),
194 'AdvMulti-Select' => ts('AdvMulti-Select'),
195 'Link' => ts('Link'),
196 'ContactReference' => ts('Autocomplete-Select'),
201 * Various pre defined extensions for dynamic properties and groups.
206 public static function customGroupExtends() {
207 $customGroupExtends = array(
208 'Activity' => ts('Activities'),
209 'Relationship' => ts('Relationships'),
210 'Contribution' => ts('Contributions'),
211 'Group' => ts('Groups'),
212 'Membership' => ts('Memberships'),
213 'Event' => ts('Events'),
214 'Participant' => ts('Participants'),
215 'ParticipantRole' => ts('Participants (Role)'),
216 'ParticipantEventName' => ts('Participants (Event Name)'),
217 'ParticipantEventType' => ts('Participants (Event Type)'),
218 'Pledge' => ts('Pledges'),
219 'Grant' => ts('Grants'),
220 'Address' => ts('Addresses'),
221 'Campaign' => ts('Campaigns'),
223 $contactTypes = self
::contactType();
224 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
225 $extendObjs = CRM_Core_OptionGroup
::values('cg_extend_objects');
226 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
227 return $customGroupExtends;
231 * Styles for displaying the custom data group.
236 public static function customGroupStyle() {
239 'Inline' => ts('Inline'),
240 'Tab with table' => ts('Tab with table'),
245 * For displaying the uf group types.
249 public static function ufGroupTypes() {
250 $ufGroupType = array(
251 'Profile' => ts('Standalone Form or Directory'),
252 'Search Profile' => ts('Search Views'),
255 if (CRM_Core_Config
::singleton()->userSystem
->supports_form_extensions
) {
256 $ufGroupType +
= array(
257 'User Registration' => ts('Drupal User Registration'),
258 'User Account' => ts('View/Edit Drupal User Account'),
265 * The status of a contact within a group.
270 public static function groupContactStatus() {
272 'Added' => ts('Added'),
273 'Removed' => ts('Removed'),
274 'Pending' => ts('Pending'),
279 * List of Group Types.
283 public static function groupType() {
285 'query' => ts('Dynamic'),
286 'static' => ts('Static'),
291 * Compose the parameters for a date select object.
293 * @param string|NULL $type
295 * @param string|NULL $format
296 * date format (QF format)
297 * @param null $minOffset
298 * @param null $maxOffset
303 public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
305 'addEmptyOption' => TRUE,
306 'emptyOptionText' => ts('- select -'),
307 'emptyOptionValue' => '',
311 $date['format'] = $format;
315 $dao = new CRM_Core_DAO_PreferencesDate();
317 if (!$dao->find(TRUE)) {
318 CRM_Core_Error
::fatal();
322 if ($type == 'creditCard') {
323 $minOffset = $dao->start
;
324 $maxOffset = $dao->end
;
325 $date['format'] = $dao->date_format
;
326 $date['addEmptyOption'] = TRUE;
327 $date['emptyOptionText'] = ts('- select -');
328 $date['emptyOptionValue'] = '';
331 if (empty($date['format'])) {
332 $date['format'] = 'M d';
337 $date['minYear'] = $year - $minOffset;
338 $date['maxYear'] = $year +
$maxOffset;
343 * Values for UF form visibility options.
347 public static function ufVisibility() {
349 'User and User Admin Only' => ts('User and User Admin Only'),
350 'Public Pages' => ts('Public Pages'),
351 'Public Pages and Listings' => ts('Public Pages and Listings'),
356 * Values for group form visibility options.
360 public static function groupVisibility() {
362 'User and User Admin Only' => ts('User and User Admin Only'),
363 'Public Pages' => ts('Public Pages'),
368 * Different type of Mailing Components.
372 public static function mailingComponents() {
374 'Header' => ts('Header'),
375 'Footer' => ts('Footer'),
376 'Reply' => ts('Reply Auto-responder'),
377 'OptOut' => ts('Opt-out Message'),
378 'Subscribe' => ts('Subscription Confirmation Request'),
379 'Welcome' => ts('Welcome Message'),
380 'Unsubscribe' => ts('Unsubscribe Message'),
381 'Resubscribe' => ts('Resubscribe Message'),
390 public function getHours() {
392 for ($i = 0; $i <= 6; $i++
) {
403 public function getMinutes() {
405 for ($i = 0; $i < 60; $i = $i +
15) {
412 * Get the Map Provider.
415 * array of map providers
417 public static function mapProvider() {
420 $map = CRM_Utils_System
::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
426 * Get the Geocoding Providers from available plugins.
429 * array of geocoder providers
431 public static function geoProvider() {
434 $geo = CRM_Utils_System
::getPluginList('CRM/Utils/Geocode');
440 * Get the Address Standardization Providers from available plugins.
443 * array of address standardization providers
445 public static function addressProvider() {
448 $addr = CRM_Utils_System
::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate'));
454 * Different type of Mailing Tokens.
458 public static function mailingTokens() {
460 '{action.unsubscribe}' => ts('Unsubscribe via email'),
461 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
462 '{action.resubscribe}' => ts('Resubscribe via email'),
463 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
464 '{action.optOut}' => ts('Opt out via email'),
465 '{action.optOutUrl}' => ts('Opt out via web page'),
466 '{action.forward}' => ts('Forward this email (link)'),
467 '{action.reply}' => ts('Reply to this email (link)'),
468 '{action.subscribeUrl}' => ts('Subscribe via web page'),
469 '{domain.name}' => ts('Domain name'),
470 '{domain.address}' => ts('Domain (organization) address'),
471 '{domain.phone}' => ts('Domain (organization) phone'),
472 '{domain.email}' => ts('Domain (organization) email'),
473 '{mailing.name}' => ts('Mailing name'),
474 '{mailing.group}' => ts('Mailing group'),
475 '{mailing.viewUrl}' => ts('Mailing permalink'),
480 * Different type of Activity Tokens.
484 public static function activityTokens() {
486 '{activity.activity_id}' => ts('Activity ID'),
487 '{activity.subject}' => ts('Activity Subject'),
488 '{activity.details}' => ts('Activity Details'),
489 '{activity.activity_date_time}' => ts('Activity Date Time'),
494 * Different type of Membership Tokens.
498 public static function membershipTokens() {
500 '{membership.id}' => ts('Membership ID'),
501 '{membership.status}' => ts('Membership Status'),
502 '{membership.type}' => ts('Membership Type'),
503 '{membership.start_date}' => ts('Membership Start Date'),
504 '{membership.join_date}' => ts('Membership Join Date'),
505 '{membership.end_date}' => ts('Membership End Date'),
506 '{membership.fee}' => ts('Membership Fee'),
511 * Different type of Event Tokens.
515 public static function eventTokens() {
517 '{event.event_id}' => ts('Event ID'),
518 '{event.title}' => ts('Event Title'),
519 '{event.start_date}' => ts('Event Start Date'),
520 '{event.end_date}' => ts('Event End Date'),
521 '{event.event_type}' => ts('Event Type'),
522 '{event.summary}' => ts('Event Summary'),
523 '{event.contact_email}' => ts('Event Contact Email'),
524 '{event.contact_phone}' => ts('Event Contact Phone'),
525 '{event.description}' => ts('Event Description'),
526 '{event.location}' => ts('Event Location'),
527 '{event.fee_amount}' => ts('Event Fees'),
528 '{event.info_url}' => ts('Event Info URL'),
529 '{event.registration_url}' => ts('Event Registration URL'),
530 '{event.balance}' => ts('Event Balance'),
535 * Different type of Event Tokens.
539 public static function contributionTokens() {
541 '{contribution.contribution_id}' => ts('Contribution ID'),
542 '{contribution.total_amount}' => ts('Total Amount'),
543 '{contribution.fee_amount}' => ts('Fee Amount'),
544 '{contribution.net_amount}' => ts('Net Amount'),
545 '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
546 '{contribution.receive_date}' => ts('Contribution Receive Date'),
547 '{contribution.payment_instrument}' => ts('Payment Instrument'),
548 '{contribution.trxn_id}' => ts('Transaction ID'),
549 '{contribution.invoice_id}' => ts('Invoice ID'),
550 '{contribution.currency}' => ts('Currency'),
551 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
552 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
553 '{contribution.receipt_date}' => ts('Receipt Date'),
554 '{contribution.thankyou_date}' => ts('Thank You Date'),
555 '{contribution.contribution_source}' => ts('Contribution Source'),
556 '{contribution.amount_level}' => ts('Amount Level'),
557 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
558 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
559 '{contribution.contribution_status_id}' => ts('Contribution Status'),
560 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
561 //'{contribution.address_id}' => ts('Address ID'),
562 '{contribution.check_number}' => ts('Check Number'),
563 '{contribution.campaign}' => ts('Contribution Campaign'),
568 * Different type of Contact Tokens.
572 public static function contactTokens() {
573 static $tokens = NULL;
575 $additionalFields = array(
576 'checksum' => array('title' => ts('Checksum')),
577 'contact_id' => array('title' => ts('Internal Contact ID')),
579 $exportFields = array_merge(CRM_Contact_BAO_Contact
::exportableFields(), $additionalFields);
581 $values = array_merge(array_keys($exportFields));
584 //FIXME:skipping some tokens for time being.
598 $customFields = CRM_Core_BAO_CustomField
::getFields(array('Individual', 'Address'));
599 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
601 foreach ($values as $val) {
602 if (in_array($val, $skipTokens)) {
605 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
606 $customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val);
607 if ($customFieldId) {
608 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
609 if (!empty($customFields[$customFieldId])) {
610 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
614 // Support legacy token names
615 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
616 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
620 // Get all the hook tokens too
621 $hookTokens = array();
622 CRM_Utils_Hook
::tokens($hookTokens);
623 foreach ($hookTokens as $tokenValues) {
624 foreach ($tokenValues as $key => $value) {
625 if (is_numeric($key)) {
628 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
629 $key = '{' . $key . '}';
631 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
632 $value = $matches[1];
634 $tokens[$key] = $value;
643 * Different type of Participant Tokens.
647 public static function participantTokens() {
648 static $tokens = NULL;
650 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
652 $values = array_merge(array_keys($exportFields));
655 // skipping some tokens for time being.
658 'participant_is_pay_later',
659 'participant_is_test',
660 'participant_contact_id',
661 'participant_fee_currency',
662 'participant_campaign_id',
663 'participant_status',
664 'participant_discount_name',
667 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
669 foreach ($values as $key => $val) {
670 if (in_array($val, $skipTokens)) {
673 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
674 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
675 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
678 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
686 * CiviCRM supported date input formats.
690 public static function getDatePluginInputFormats() {
691 $dateInputFormats = array(
692 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
693 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
694 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
695 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
696 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
697 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
698 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
699 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
700 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
701 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
702 "mm/dd" => ts('mm/dd (12/31)'),
703 "dd-mm" => ts('dd-mm (31-12)'),
704 "yy-mm" => ts('yyyy-mm (2009-12)'),
705 'M yy' => ts('M yyyy (Dec 2009)'),
706 "yy" => ts('yyyy (2009)'),
710 Year greater than 2000 get wrong result for following format
711 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
712 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
714 expected :: 2001-11-07
717 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
718 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
722 return $dateInputFormats;
726 * Map date plugin and actual format that is used by PHP.
730 public static function datePluginToPHPFormats() {
731 $dateInputFormats = array(
732 "mm/dd/yy" => 'm/d/Y',
733 "dd/mm/yy" => 'd/m/Y',
734 "yy-mm-dd" => 'Y-m-d',
735 "dd-mm-yy" => 'd-m-Y',
736 "dd.mm.yy" => 'd.m.Y',
737 "M d, yy" => 'M j, Y',
739 "MM d, yy" => 'F j, Y',
740 "d MM yy" => 'j F Y',
741 "DD, d MM yy" => 'l, j F Y',
748 return $dateInputFormats;
756 public static function getTimeFormats() {
758 '1' => ts('12 Hours'),
759 '2' => ts('24 Hours'),
764 * Get numeric options.
771 public static function getNumericOptions($start = 0, $end = 10) {
772 $numericOptions = array();
773 for ($i = $start; $i <= $end; $i++
) {
774 $numericOptions[$i] = $i;
776 return $numericOptions;
784 public static function getBarcodeTypes() {
786 'barcode' => ts('Linear (1D)'),
787 'qrcode' => ts('QR code'),
796 public static function getDedupeRuleTypes() {
798 'Unsupervised' => ts('Unsupervised'),
799 'Supervised' => ts('Supervised'),
800 'General' => ts('General'),
805 * Campaign group types.
809 public static function getCampaignGroupTypes() {
811 'Include' => ts('Include'),
812 'Exclude' => ts('Exclude'),
817 * Subscription history method.
821 public static function getSubscriptionHistoryMethods() {
823 'Admin' => ts('Admin'),
824 'Email' => ts('Email'),
835 public static function getPremiumUnits() {
838 'week' => ts('Week'),
839 'month' => ts('Month'),
840 'year' => ts('Year'),
849 public static function getExtensionTypes() {
851 'payment' => ts('Payment'),
852 'search' => ts('Search'),
853 'report' => ts('Report'),
854 'module' => ts('Module'),
864 public static function getJobFrequency() {
866 'Daily' => ts('Daily'),
867 'Hourly' => ts('Hourly'),
868 'Always' => ts('Every time cron job is run'),
873 * Search builder operators.
877 public static function getSearchBuilderOperators() {
886 'NOT IN' => ts('Not In'),
887 'LIKE' => ts('Like'),
888 'NOT LIKE' => ts('Not Like'),
889 'RLIKE' => ts('Regex'),
890 'IS EMPTY' => ts('Is Empty'),
891 'IS NOT EMPTY' => ts('Not Empty'),
892 'IS NULL' => ts('Is Null'),
893 'IS NOT NULL' => ts('Not Null'),
898 * Profile group types.
902 public static function getProfileGroupType() {
903 $profileGroupType = array(
904 'Activity' => ts('Activities'),
905 'Contribution' => ts('Contributions'),
906 'Membership' => ts('Memberships'),
907 'Participant' => ts('Participants'),
909 $contactTypes = self
::contactType();
910 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
911 $profileGroupType = array_merge($contactTypes, $profileGroupType);
913 return $profileGroupType;
918 * Word replacement match type.
922 public static function getWordReplacementMatchType() {
924 'exactMatch' => ts('Exact Match'),
925 'wildcardMatch' => ts('Wildcard Match'),
930 * Mailing group types.
934 public static function getMailingGroupTypes() {
936 'Include' => ts('Include'),
937 'Exclude' => ts('Exclude'),
938 'Base' => ts('Base'),
943 * Mailing Job Status.
947 public static function getMailingJobStatus() {
949 'Scheduled' => ts('Scheduled'),
950 'Running' => ts('Running'),
951 'Complete' => ts('Complete'),
952 'Paused' => ts('Paused'),
953 'Canceled' => ts('Canceled'),
960 public static function billingMode() {
962 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
963 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
964 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
969 * Frequency unit for schedule reminders.
973 public static function getScheduleReminderFrequencyUnits() {
974 //@todo update schema to refer to option group direct & remove this
975 static $scheduleReminderFrequencyUnits = NULL;
976 if (!$scheduleReminderFrequencyUnits) {
977 $scheduleReminderFrequencyUnits = array(
978 'hour' => ts('hour'),
979 ) + CRM_Core_OptionGroup
::values('recur_frequency_units');
982 return $scheduleReminderFrequencyUnits;