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
44 public static function pmf() {
56 public 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 public static function contactType() {
72 static $contactType = NULL;
74 $contactType = CRM_Contact_BAO_ContactType
::basicTypePairs();
80 * Various pre defined unit list
83 public static function unitList($unitType = NULL) {
86 'month' => ts('month'),
89 if ($unitType == 'duration') {
90 $unitList['lifetime'] = ts('lifetime');
96 * Membership type unit
99 public static function membershipTypeUnitList() {
100 return self
::unitList('duration');
104 * Various pre defined period types
107 public static function periodType() {
109 'rolling' => ts('Rolling'),
110 'fixed' => ts('Fixed'),
115 * Various pre defined email selection methods
118 public 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 public static function memberVisibility() {
133 'Public' => ts('Public'),
134 'Admin' => ts('Admin'),
139 * Member auto-renew options
142 public static function memberAutoRenew() {
144 ts('No auto-renew option'),
145 ts('Give option, but not required'),
146 ts('Auto-renew required'),
151 * Various pre defined event dates
154 public static function eventDate() {
156 'start_date' => ts('start date'),
157 'end_date' => ts('end date'),
158 'join_date' => ts('member since'),
163 * Custom form field types
166 public static function customHtmlType() {
168 'Text' => ts('Single-line input field (text or numeric)'),
169 'TextArea' => ts('Multi-line text box (textarea)'),
170 'Select' => ts('Drop-down (select list)'),
171 'Radio' => ts('Radio buttons'),
172 'CheckBox' => ts('Checkbox(es)'),
173 'Select Date' => ts('Select Date'),
174 'File' => ts('File'),
175 'Select State/Province' => ts('Select State/Province'),
176 'Multi-Select State/Province' => ts('Multi-Select State/Province'),
177 'Select Country' => ts('Select Country'),
178 'Multi-Select Country' => ts('Multi-Select Country'),
179 'RichTextEditor' => ts('Rich Text Editor'),
180 'Autocomplete-Select' => ts('Autocomplete-Select'),
181 'Multi-Select' => ts('Multi-Select'),
182 'AdvMulti-Select' => ts('AdvMulti-Select'),
183 'Link' => ts('Link'),
184 'ContactReference' => ts('Autocomplete-Select'),
189 * Various pre defined extensions for dynamic properties and groups
193 public static function customGroupExtends() {
194 $customGroupExtends = array(
195 'Activity' => ts('Activities'),
196 'Relationship' => ts('Relationships'),
197 'Contribution' => ts('Contributions'),
198 'Group' => ts('Groups'),
199 'Membership' => ts('Memberships'),
200 'Event' => ts('Events'),
201 'Participant' => ts('Participants'),
202 'ParticipantRole' => ts('Participants (Role)'),
203 'ParticipantEventName' => ts('Participants (Event Name)'),
204 'ParticipantEventType' => ts('Participants (Event Type)'),
205 'Pledge' => ts('Pledges'),
206 'Grant' => ts('Grants'),
207 'Address' => ts('Addresses'),
208 'Campaign' => ts('Campaigns'),
210 $contactTypes = self
::contactType();
211 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
212 $extendObjs = CRM_Core_OptionGroup
::values('cg_extend_objects');
213 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
214 return $customGroupExtends;
218 * Styles for displaying the custom data group
222 public static function customGroupStyle() {
225 'Inline' => ts('Inline'),
226 'Tab with table' => ts('Tab with table'),
231 * For displaying the uf group types
235 public static function ufGroupTypes() {
236 $ufGroupType = array(
237 'Profile' => ts('Standalone Form or Directory'),
238 'Search Profile' => ts('Search Views'),
241 if (CRM_Core_Config
::singleton()->userSystem
->supports_form_extensions
) {
242 $ufGroupType +
= array(
243 'User Registration' => ts('Drupal User Registration'),
244 'User Account' => ts('View/Edit Drupal User Account'),
251 * The status of a contact within a group
255 public static function groupContactStatus() {
257 'Added' => ts('Added'),
258 'Removed' => ts('Removed'),
259 'Pending' => ts('Pending'),
264 * List of Group Types
267 public static function groupType() {
269 'query' => ts('Dynamic'),
270 'static' => ts('Static'),
275 * Compose the parameters for a date select object
277 * @param string|NULL $type the type of date
278 * @param string|NULL $format date format ( QF format)
280 * @param null $minOffset
281 * @param null $maxOffset
287 public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
290 'addEmptyOption' => TRUE,
291 'emptyOptionText' => ts('- select -'),
292 'emptyOptionValue' => '',
296 $date['format'] = $format;
300 $dao = new CRM_Core_DAO_PreferencesDate();
302 if (!$dao->find(TRUE)) {
303 CRM_Core_Error
::fatal();
307 if ($type == 'creditCard') {
308 $minOffset = $dao->start
;
309 $maxOffset = $dao->end
;
310 $date['format'] = $dao->date_format
;
311 $date['addEmptyOption'] = TRUE;
312 $date['emptyOptionText'] = ts('- select -');
313 $date['emptyOptionValue'] = '';
316 if (empty($date['format'])) {
317 $date['format'] = 'M d';
322 $date['minYear'] = $year - $minOffset;
323 $date['maxYear'] = $year +
$maxOffset;
328 * Values for UF form visibility options
332 public static function ufVisibility() {
334 'User and User Admin Only' => ts('User and User Admin Only'),
335 'Public Pages' => ts('Public Pages'),
336 'Public Pages and Listings' => ts('Public Pages and Listings'),
341 * Values for group form visibility options
345 public static function groupVisibility() {
347 'User and User Admin Only' => ts('User and User Admin Only'),
348 'Public Pages' => ts('Public Pages'),
353 * Different type of Mailing Components
358 public static function mailingComponents() {
360 'Header' => ts('Header'),
361 'Footer' => ts('Footer'),
362 'Reply' => ts('Reply Auto-responder'),
363 'OptOut' => ts('Opt-out Message'),
364 'Subscribe' => ts('Subscription Confirmation Request'),
365 'Welcome' => ts('Welcome Message'),
366 'Unsubscribe' => ts('Unsubscribe Message'),
367 'Resubscribe' => ts('Resubscribe Message'),
377 public function getHours() {
379 for ($i = 0; $i <= 6; $i++
) {
391 public function getMinutes() {
393 for ($i = 0; $i < 60; $i = $i +
15) {
400 * Get the Map Provider
403 * array of map providers
406 public static function mapProvider() {
409 $map = CRM_Utils_System
::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
415 * Get the Geocoding Providers from available plugins
418 * array of geocoder providers
421 public static function geoProvider() {
424 $geo = CRM_Utils_System
::getPluginList('CRM/Utils/Geocode');
430 * Get the Address Standardization Providers from available
434 * array of address standardization providers
437 public static function addressProvider() {
440 $addr = CRM_Utils_System
::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate'));
446 * Different type of Mailing Tokens
451 public static function mailingTokens() {
453 '{action.unsubscribe}' => ts('Unsubscribe via email'),
454 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
455 '{action.resubscribe}' => ts('Resubscribe via email'),
456 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
457 '{action.optOut}' => ts('Opt out via email'),
458 '{action.optOutUrl}' => ts('Opt out via web page'),
459 '{action.forward}' => ts('Forward this email (link)'),
460 '{action.reply}' => ts('Reply to this email (link)'),
461 '{action.subscribeUrl}' => ts('Subscribe via web page'),
462 '{domain.name}' => ts('Domain name'),
463 '{domain.address}' => ts('Domain (organization) address'),
464 '{domain.phone}' => ts('Domain (organization) phone'),
465 '{domain.email}' => ts('Domain (organization) email'),
466 '{mailing.name}' => ts('Mailing name'),
467 '{mailing.group}' => ts('Mailing group'),
468 '{mailing.viewUrl}' => ts('Mailing permalink'),
473 * Different type of Activity Tokens
478 public static function activityTokens() {
480 '{activity.activity_id}' => ts('Activity ID'),
481 '{activity.subject}' => ts('Activity Subject'),
482 '{activity.details}' => ts('Activity Details'),
483 '{activity.activity_date_time}' => ts('Activity Date Time'),
488 * Different type of Membership Tokens
493 public static function membershipTokens() {
495 '{membership.id}' => ts('Membership ID'),
496 '{membership.status}' => ts('Membership Status'),
497 '{membership.type}' => ts('Membership Type'),
498 '{membership.start_date}' => ts('Membership Start Date'),
499 '{membership.join_date}' => ts('Membership Join Date'),
500 '{membership.end_date}' => ts('Membership End Date'),
501 '{membership.fee}' => ts('Membership Fee'),
506 * Different type of Event Tokens
511 public static function eventTokens() {
513 '{event.event_id}' => ts('Event ID'),
514 '{event.title}' => ts('Event Title'),
515 '{event.start_date}' => ts('Event Start Date'),
516 '{event.end_date}' => ts('Event End Date'),
517 '{event.event_type}' => ts('Event Type'),
518 '{event.summary}' => ts('Event Summary'),
519 '{event.contact_email}' => ts('Event Contact Email'),
520 '{event.contact_phone}' => ts('Event Contact Phone'),
521 '{event.description}' => ts('Event Description'),
522 '{event.location}' => ts('Event Location'),
523 '{event.fee_amount}' => ts('Event Fees'),
524 '{event.info_url}' => ts('Event Info URL'),
525 '{event.registration_url}' => ts('Event Registration URL'),
526 '{event.balance}' => ts('Event Balance'),
531 * Different type of Event Tokens
536 public static function contributionTokens() {
538 '{contribution.contribution_id}' => ts('Contribution ID'),
539 '{contribution.total_amount}' => ts('Total Amount'),
540 '{contribution.fee_amount}' => ts('Fee Amount'),
541 '{contribution.net_amount}' => ts('Net Amount'),
542 '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
543 '{contribution.receive_date}' => ts('Contribution Receive Date'),
544 '{contribution.payment_instrument}' => ts('Payment Instrument'),
545 '{contribution.trxn_id}' => ts('Transaction ID'),
546 '{contribution.invoice_id}' => ts('Invoice ID'),
547 '{contribution.currency}' => ts('Currency'),
548 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
549 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
550 '{contribution.receipt_date}' => ts('Receipt Date'),
551 '{contribution.thankyou_date}' => ts('Thank You Date'),
552 '{contribution.contribution_source}' => ts('Contribution Source'),
553 '{contribution.amount_level}' => ts('Amount Level'),
554 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
555 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
556 '{contribution.contribution_status_id}' => ts('Contribution Status'),
557 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
558 //'{contribution.address_id}' => ts('Address ID'),
559 '{contribution.check_number}' => ts('Check Number'),
560 '{contribution.campaign}' => ts('Contribution Campaign'),
565 * Different type of Contact Tokens
570 public static function contactTokens() {
571 static $tokens = NULL;
573 $additionalFields = array(
574 'checksum' => array('title' => ts('Checksum')),
575 'contact_id' => array('title' => ts('Internal Contact ID')),
577 $exportFields = array_merge(CRM_Contact_BAO_Contact
::exportableFields(), $additionalFields);
579 $values = array_merge(array_keys($exportFields));
582 //FIXME:skipping some tokens for time being.
596 $customFields = CRM_Core_BAO_CustomField
::getFields(array('Individual', 'Address'));
597 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
599 foreach ($values as $val) {
600 if (in_array($val, $skipTokens)) {
603 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
604 $customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val);
605 if ($customFieldId) {
606 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
607 if (!empty($customFields[$customFieldId])) {
608 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
612 // Support legacy token names
613 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
614 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
618 // might as well get all the hook tokens to
619 $hookTokens = array();
620 CRM_Utils_Hook
::tokens($hookTokens);
621 foreach ($hookTokens as $tokenValues) {
622 foreach ($tokenValues as $key => $value) {
623 if (is_numeric($key)) {
626 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
627 $key = '{' . $key . '}';
629 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
630 $value = $matches[1];
632 $tokens[$key] = $value;
641 * Different type of Participant Tokens
646 public static function participantTokens() {
647 static $tokens = NULL;
649 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
651 $values = array_merge(array_keys($exportFields));
654 // skipping some tokens for time being.
657 'participant_is_pay_later',
658 'participant_is_test',
659 'participant_contact_id',
660 'participant_fee_currency',
661 'participant_campaign_id',
662 'participant_status',
663 'participant_discount_name',
666 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
668 foreach ($values as $key => $val) {
669 if (in_array($val, $skipTokens)) {
672 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
673 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
674 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
677 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
685 * CiviCRM supported date input formats
687 public static function getDatePluginInputFormats() {
688 $dateInputFormats = array(
689 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
690 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
691 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
692 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
693 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
694 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
695 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
696 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
697 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
698 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
699 "mm/dd" => ts('mm/dd (12/31)'),
700 "dd-mm" => ts('dd-mm (31-12)'),
701 "yy-mm" => ts('yyyy-mm (2009-12)'),
702 'M yy' => ts('M yyyy (Dec 2009)'),
703 "yy" => ts('yyyy (2009)'),
707 Year greater than 2000 get wrong result for following format
708 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
709 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
711 expected :: 2001-11-07
714 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
715 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
719 return $dateInputFormats;
723 * Map date plugin and actual format that is used by PHP
725 public static function datePluginToPHPFormats() {
726 $dateInputFormats = array(
727 "mm/dd/yy" => 'm/d/Y',
728 "dd/mm/yy" => 'd/m/Y',
729 "yy-mm-dd" => 'Y-m-d',
730 "dd-mm-yy" => 'd-m-Y',
731 "dd.mm.yy" => 'd.m.Y',
732 "M d, yy" => 'M j, Y',
734 "MM d, yy" => 'F j, Y',
735 "d MM yy" => 'j F Y',
736 "DD, d MM yy" => 'l, j F Y',
743 return $dateInputFormats;
749 public static function getTimeFormats() {
751 '1' => ts('12 Hours'),
752 '2' => ts('24 Hours'),
757 * Get numeric options
762 public static function getNumericOptions($start = 0, $end = 10) {
763 $numericOptions = array();
764 for ($i = $start; $i <= $end; $i++
) {
765 $numericOptions[$i] = $i;
767 return $numericOptions;
774 public static function getBarcodeTypes() {
776 'barcode' => ts('Linear (1D)'),
777 'qrcode' => ts('QR code'),
784 public static function getDedupeRuleTypes() {
786 'Unsupervised' => ts('Unsupervised'),
787 'Supervised' => ts('Supervised'),
788 'General' => ts('General'),
793 * Campaign group types
795 public static function getCampaignGroupTypes() {
797 'Include' => ts('Include'),
798 'Exclude' => ts('Exclude'),
803 * Subscription history method
805 public static function getSubscriptionHistoryMethods() {
807 'Admin' => ts('Admin'),
808 'Email' => ts('Email'),
817 public static function getPremiumUnits() {
820 'week' => ts('Week'),
821 'month' => ts('Month'),
822 'year' => ts('Year'),
829 public static function getExtensionTypes() {
831 'payment' => ts('Payment'),
832 'search' => ts('Search'),
833 'report' => ts('Report'),
834 'module' => ts('Module'),
842 public static function getJobFrequency() {
844 'Daily' => ts('Daily'),
845 'Hourly' => ts('Hourly'),
846 'Always' => ts('Every time cron job is run'),
851 * Search builder operators
853 public static function getSearchBuilderOperators() {
862 'NOT IN' => ts('Not In'),
863 'LIKE' => ts('Like'),
864 'NOT LIKE' => ts('Not Like'),
865 'RLIKE' => ts('Regex'),
866 'IS EMPTY' => ts('Is Empty'),
867 'IS NOT EMPTY' => ts('Not Empty'),
868 'IS NULL' => ts('Is Null'),
869 'IS NOT NULL' => ts('Not Null'),
874 * Profile group types
878 public static function getProfileGroupType() {
879 $profileGroupType = array(
880 'Activity' => ts('Activities'),
881 'Contribution' => ts('Contributions'),
882 'Membership' => ts('Memberships'),
883 'Participant' => ts('Participants'),
885 $contactTypes = self
::contactType();
886 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
887 $profileGroupType = array_merge($contactTypes, $profileGroupType);
889 return $profileGroupType;
894 * Word replacement match type
896 public static function getWordReplacementMatchType() {
898 'exactMatch' => ts('Exact Match'),
899 'wildcardMatch' => ts('Wildcard Match'),
904 * Mailing group types
906 public static function getMailingGroupTypes() {
908 'Include' => ts('Include'),
909 'Exclude' => ts('Exclude'),
910 'Base' => ts('Base'),
917 public static function getMailingJobStatus() {
919 'Scheduled' => ts('Scheduled'),
920 'Running' => ts('Running'),
921 'Complete' => ts('Complete'),
922 'Paused' => ts('Paused'),
923 'Canceled' => ts('Canceled'),
927 public static function billingMode() {
929 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
930 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
931 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
936 * Frequency unit for schedule reminders
938 public static function getScheduleReminderFrequencyUnits() {
939 //@todo update schema to refer to option group direct & remove this
940 static $scheduleReminderFrequencyUnits = NULL;
941 if (!$scheduleReminderFrequencyUnits) {
942 $scheduleReminderFrequencyUnits = array(
944 ) + CRM_Core_OptionGroup
::values('recur_frequency_units');
947 return $scheduleReminderFrequencyUnits;