3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
38 class CRM_Core_SelectValues
{
40 /**CRM/Core/SelectValues.php
41 * different types of phones
44 static function &phoneType() {
45 static $phoneType = NULL;
48 '' => ts('- select -'),
49 'Phone' => ts('Phone'),
50 'Mobile' => ts('Mobile'),
52 'Pager' => ts('Pager'),
59 * preferred mail format
62 static function &pmf() {
78 static function &privacy() {
79 static $privacy = NULL;
82 'do_not_phone' => ts('Do not phone'),
83 'do_not_email' => ts('Do not email'),
84 'do_not_mail' => ts('Do not mail'),
85 'do_not_sms' => ts('Do not sms'),
86 'do_not_trade' => ts('Do not trade'),
87 'is_opt_out' => ts('No bulk emails (User Opt Out)'),
94 * various pre defined contact super types
97 static function &contactType() {
98 static $contactType = NULL;
100 $contactType = CRM_Contact_BAO_ContactType
::basicTypePairs();
106 * various pre defined unit list
109 static function &unitList($unitType = NULL) {
110 static $unitList = NULL;
113 '' => ts('- select -'),
115 'month' => ts('month'),
116 'year' => ts('year'),
118 if ($unitType == 'duration') {
120 'lifetime' => ts('lifetime'),
122 $unitList = array_merge($unitList, $unitAdd);
129 * various pre defined period types
132 static function &periodType() {
133 static $periodType = NULL;
136 '' => ts('- select -'),
137 'rolling' => ts('Rolling'),
138 'fixed' => ts('Fixed'),
145 * various pre defined member visibility options
148 static function &memberVisibility() {
149 static $visible = NULL;
152 'Public' => ts('Public'),
153 'Admin' => ts('Admin'),
160 * various pre defined event dates
163 static function &eventDate() {
164 static $eventDate = NULL;
167 '' => ts('- select -'),
168 'start_date' => ts('start date'),
169 'end_date' => ts('end date'),
170 'join_date' => ts('member since'),
177 * Extended property (custom field) data types
180 static function &customDataType() {
181 static $customDataType = NULL;
182 if (!$customDataType) {
183 $customDataType = array(
184 '' => ts('- select -'),
185 'String' => ts('Text'),
186 'Int' => ts('Integer'),
187 'Float' => ts('Decimal Number'),
188 'Money' => ts('Money'),
189 'Text' => ts('Memo'),
190 'Date' => ts('Date'),
191 'File' => ts('File'),
192 'Boolean' => ts('Yes/No'),
193 'Link' => ts('Link'),
194 'Auto-complete' => ts('Auto-complete'),
197 return $customDataType;
201 * Custom form field types
204 static function &customHtmlType() {
205 static $customHtmlType = NULL;
206 if (!$customHtmlType) {
207 $customHtmlType = array(
208 '' => ts('- select -'),
209 'Text' => ts('Single-line input field (text or numeric)'),
210 'TextArea' => ts('Multi-line text box (textarea)'),
211 'Select' => ts('Drop-down (select list)'),
212 'Radio' => ts('Radio buttons'),
213 'Checkbox' => ts('Checkbox(es)'),
214 'Select Date' => ts('Date selector'),
215 'File' => ts('File'),
216 'Select State / Province' => ts('State / Province selector'),
217 'Select Country' => ts('Country selector'),
218 'RichTextEditor' => ts('Rich Text Editor'),
219 'Auto-complete' => ts('Contact Reference'),
222 return $customHtmlType;
226 * various pre defined extensions for dynamic properties and groups
230 static function &customGroupExtends() {
231 static $customGroupExtends = NULL;
232 if (!$customGroupExtends) {
233 $customGroupExtends = array(
234 'Activity' => ts('Activities'),
235 'Relationship' => ts('Relationships'),
236 'Contribution' => ts('Contributions'),
237 'Group' => ts('Groups'),
238 'Membership' => ts('Memberships'),
239 'Event' => ts('Events'),
240 'Participant' => ts('Participants'),
241 'ParticipantRole' => ts('Participants (Role)'),
242 'ParticipantEventName' => ts('Participants (Event Name)'),
243 'ParticipantEventType' => ts('Participants (Event Type)'),
244 'Pledge' => ts('Pledges'),
245 'Grant' => ts('Grants'),
246 'Address' => ts('Addresses'),
247 'Campaign' => ts('Campaigns'),
249 $contactTypes = self
::contactType();
250 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
251 $extendObjs = CRM_Core_OptionGroup
::values('cg_extend_objects');
252 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
254 return $customGroupExtends;
258 * styles for displaying the custom data group
262 static function &customGroupStyle() {
263 static $customGroupStyle = NULL;
264 if (!$customGroupStyle) {
265 $customGroupStyle = array(
267 'Inline' => ts('Inline'),
270 return $customGroupStyle;
274 * for displaying the uf group types
278 static function &ufGroupTypes() {
279 static $ufGroupType = NULL;
281 $ufGroupType = array(
282 'Profile' => ts('Standalone Form or Directory'),
283 'Search Profile' => ts('Search Views'),
285 $config = CRM_Core_Config
::singleton();
286 if ($config->userSystem
->supports_form_extensions
) {
287 $ufGroupType +
= array(
288 'User Registration' => ts('Drupal User Registration'),
289 'User Account' => ts('View/Edit Drupal User Account'),
297 * the status of a contact within a group
301 static function &groupContactStatus() {
302 static $groupContactStatus = NULL;
303 if (!$groupContactStatus) {
304 $groupContactStatus = array(
305 'Added' => ts('Added'),
306 'Removed' => ts('Removed'),
307 'Pending' => ts('Pending'),
310 return $groupContactStatus;
314 * list of Group Types
317 static function &groupType() {
318 static $groupType = NULL;
321 'query' => ts('Dynamic'),
322 'static' => ts('Static'),
329 * compose the parameters for a date select object
331 * @param $type the type of date
332 * @param $format date format ( QF format)
334 * @return array the date array
337 static function &date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
340 'addEmptyOption' => TRUE,
341 'emptyOptionText' => ts('- select -'),
342 'emptyOptionValue' => '',
346 $date['format'] = $format;
350 $dao = new CRM_Core_DAO_PreferencesDate();
352 if (!$dao->find(TRUE)) {
353 CRM_Core_Error
::fatal();
357 if ($type == 'creditCard') {
358 $minOffset = $dao->start
;
359 $maxOffset = $dao->end
;
360 $date['format'] = $dao->date_format
;
361 $date['addEmptyOption'] = TRUE;
362 $date['emptyOptionText'] = ts('- select -');
363 $date['emptyOptionValue'] = '';
366 if (empty($date['format'])) {
367 $date['format'] = 'M d';
372 $date['minYear'] = $year - $minOffset;
373 $date['maxYear'] = $year +
$maxOffset;
378 * values for UF form visibility options
382 static function ufVisibility($isGroup = FALSE) {
383 static $_visibility = NULL;
385 $_visibility = array(
386 'User and User Admin Only' => ts('User and User Admin Only'),
387 'Public Pages' => ts('Public Pages'),
388 'Public Pages and Listings' => ts('Public Pages and Listings'),
391 unset($_visibility['Public Pages and Listings']);
398 * different type of Mailing Components
403 static function &mailingComponents() {
404 static $components = NULL;
407 $components = array('Header' => ts('Header'),
408 'Footer' => ts('Footer'),
409 'Reply' => ts('Reply Auto-responder'),
410 'OptOut' => ts('Opt-out Message'),
411 'Subscribe' => ts('Subscription Confirmation Request'),
412 'Welcome' => ts('Welcome Message'),
413 'Unsubscribe' => ts('Unsubscribe Message'),
414 'Resubscribe' => ts('Resubscribe Message'),
421 * Function to get hours
426 function getHours() {
427 for ($i = 0; $i <= 6; $i++
) {
434 * Function to get minutes
439 function getMinutes() {
440 for ($i = 0; $i < 60; $i = $i +
15) {
447 * Function to get the Map Provider
449 * @return array $map array of map providers
452 static function mapProvider() {
455 return CRM_Utils_System
::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
461 * Function to get the Geocoding Providers from available plugins
463 * @return array $geo array of geocoder providers
466 static function geoProvider() {
469 return CRM_Utils_System
::getPluginList('CRM/Utils/Geocode');
475 * Function to get the Address Standardization Providers from available
478 * @return array $addr array of address standardization providers
481 static function addressProvider() {
484 return CRM_Utils_System
::getPluginList('CRM/Utils/Address',
493 * different type of Mailing Tokens
498 static function &mailingTokens() {
499 static $tokens = NULL;
502 $tokens = array('{action.unsubscribe}' => ts('Unsubscribe via email'),
503 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
504 '{action.resubscribe}' => ts('Resubscribe via email'),
505 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
506 '{action.optOut}' => ts('Opt out via email'),
507 '{action.optOutUrl}' => ts('Opt out via web page'),
508 '{action.forward}' => ts('Forward this email (link)'),
509 '{action.reply}' => ts('Reply to this email (link)'),
510 '{action.subscribeUrl}' => ts('Subscribe via web page'),
511 '{domain.name}' => ts('Domain name'),
512 '{domain.address}' => ts('Domain (organization) address'),
513 '{domain.phone}' => ts('Domain (organization) phone'),
514 '{domain.email}' => ts('Domain (organization) email'),
515 '{mailing.name}' => ts('Mailing name'),
516 '{mailing.group}' => ts('Mailing group'),
517 '{mailing.viewUrl}' => ts('Mailing permalink'),
524 * different type of Activity Tokens
529 static function &activityTokens() {
530 static $tokens = NULL;
534 '{activity.activity_id}' => ts('Activity ID'),
535 '{activity.subject}' => ts('Activity Subject'),
536 '{activity.details}' => ts('Activity Details'),
537 '{activity.activity_date_time}' => ts('Activity Date Time'),
544 * different type of Membership Tokens
549 static function &membershipTokens() {
550 static $tokens = NULL;
554 '{membership.id}' => ts('Membership ID'),
555 '{membership.status}' => ts('Membership Status'),
556 '{membership.type}' => ts('Membership Type'),
557 '{membership.start_date}' => ts('Membership Start Date'),
558 '{membership.join_date}' => ts('Membership Join Date'),
559 '{membership.end_date}' => ts('Membership End Date'),
560 '{membership.fee}' => ts('Membership Fee'),
567 * different type of Event Tokens
572 static function &eventTokens() {
573 static $tokens = NULL;
577 '{event.event_id}' => ts('Event ID'),
578 '{event.title}' => ts('Event Title'),
579 '{event.start_date}' => ts('Event Start Date'),
580 '{event.end_date}' => ts('Event End Date'),
581 '{event.event_type}' => ts('Event Type'),
582 '{event.summary}' => ts('Event Summary'),
583 '{event.description}' => ts('Event Description'),
584 '{event.contact_email}' => ts('Event Contact Email'),
585 '{event.contact_phone}' => ts('Event Contact Phone'),
586 '{event.location}' => ts('Event Location'),
587 '{event.description}' => ts('Event Description'),
588 '{event.location}' => ts('Event Location'),
589 '{event.fee_amount}' => ts('Event Fees'),
590 '{event.info_url}' => ts('Event Info URL'),
591 '{event.registration_url}' => ts('Event Registration URL'),
592 '{event.balance}' => ts('Event Balance')
599 * different type of Event Tokens
604 static function &contributionTokens() {
605 static $tokens = NULL;
609 '{contribution.contribution_id}' => ts('Contribution ID'),
610 '{contribution.total_amount}' => ts('Total Amount'),
611 '{contribution.fee_amount}' => ts('Fee Amount'),
612 '{contribution.net_amount}' => ts('Net Amount'),
613 '{contribution.non_deductible_amount}' => ts('Non Deductible Amount'),
614 '{contribution.receive_date}' => ts('Contribution Receive Date'),
615 '{contribution.payment_instrument}' => ts('Payment Instrument'),
616 '{contribution.trxn_id}' => ts('Transaction ID'),
617 '{contribution.invoice_id}' => ts('Invoice ID'),
618 '{contribution.currency}' => ts('Currency'),
619 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
620 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
621 '{contribution.receipt_date}' => ts('Receipt Date'),
622 '{contribution.thankyou_date}' => ts('Thank You Date'),
623 '{contribution.contribution_source}' => ts('Contribution Source'),
624 '{contribution.amount_level}' => ts('Amount Level'),
625 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
626 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
627 '{contribution.contribution_status_id}' => ts('Contribution Status'),
628 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
629 //'{contribution.address_id}' => ts('Address ID'),
630 '{contribution.check_number}' => ts('Check Number'),
631 '{contribution.campaign}' => ts('Contribution Campaign'),
638 * different type of Contact Tokens
643 static function &contactTokens() {
644 static $tokens = NULL;
646 $additionalFields = array('checksum' => array('title' => ts('Checksum')),
647 'contact_id' => array('title' => ts('Internal Contact ID')),
649 $exportFields = array_merge(CRM_Contact_BAO_Contact
::exportableFields(), $additionalFields);
651 $values = array_merge(array_keys($exportFields));
654 //FIXME:skipping some tokens for time being.
656 'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
657 'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
660 $customFields = CRM_Core_BAO_CustomField
::getFields('Individual');
661 $customFieldsAddress = CRM_Core_BAO_CustomField
::getFields('Address');
662 $customFields = $customFields +
$customFieldsAddress;
663 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
665 foreach ($values as $val) {
666 if (in_array($val, $skipTokens)) {
669 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
670 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
671 $tokens["{contact.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
674 // Support legacy token names
675 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
676 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
680 // might as well get all the hook tokens to
681 $hookTokens = array();
682 CRM_Utils_Hook
::tokens($hookTokens);
683 foreach ($hookTokens as $category => $tokenValues) {
684 foreach ($tokenValues as $key => $value) {
685 if (is_numeric($key)) {
688 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
689 $key = '{' . $key . '}';
691 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
692 $value = $matches[1];
694 $tokens[$key] = $value;
703 * different type of Participant Tokens
708 static function &participantTokens() {
709 static $tokens = NULL;
711 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
713 $values = array_merge(array_keys($exportFields));
716 // skipping some tokens for time being.
718 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
719 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
722 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
724 foreach ($values as $key => $val) {
725 if (in_array($val, $skipTokens)) {
728 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
729 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
730 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
733 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
741 * get qf mappig for all date parts.
744 static function &qfDatePartsMapping() {
745 static $qfDatePartsMapping = NULL;
746 if (!$qfDatePartsMapping) {
747 $qfDatePartsMapping = array(
766 return $qfDatePartsMapping;
770 * CiviCRM supported date input formats
772 static function getDatePluginInputFormats() {
773 $dateInputFormats = array(
774 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
775 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
776 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
777 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
778 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
779 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
780 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
781 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
782 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
783 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
784 "mm/dd" => ts('mm/dd (12/31)'),
785 "dd-mm" => ts('dd-mm (31-12)'),
786 "yy-mm" => ts('yyyy-mm (2009-12)'),
787 'M yy' => ts('M yyyy (Dec 2009)'),
788 "yy" => ts('yyyy (2009)'),
792 Year greater than 2000 get wrong result for following format
793 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
794 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
796 expected :: 2001-11-07
799 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
800 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
805 return $dateInputFormats;
809 * Map date plugin and actual format that is used by PHP
811 static function datePluginToPHPFormats() {
812 $dateInputFormats = array(
813 "mm/dd/yy" => 'm/d/Y',
814 "dd/mm/yy" => 'd/m/Y',
815 "yy-mm-dd" => 'Y-m-d',
816 "dd-mm-yy" => 'd-m-Y',
817 "dd.mm.yy" => 'd.m.Y',
818 "M d, yy" => 'M j, Y',
820 "MM d, yy" => 'F j, Y',
821 "d MM yy" => 'j F Y',
822 "DD, d MM yy" => 'l, j F Y',
829 return $dateInputFormats;
835 static function getTimeFormats() {
836 $timeFormats = array('1' => ts('12 Hours'),
837 '2' => ts('24 Hours'),
843 * Function to get numeric options
848 public static function getNumericOptions($start = 0, $end = 10) {
849 for ($i = $start; $i <= $end; $i++
) {
850 $numericOptions[$i] = $i;
852 return $numericOptions;
859 static function getBarcodeTypes() {
860 static $barcodeTypes = NULL;
861 if (!$barcodeTypes) {
862 $barcodeTypes = array(
863 'barcode' => ts('Linear (1D)'),
864 'qrcode' => ts('QR code'),
867 return $barcodeTypes;
873 static function getDedupeRuleTypes() {
874 static $dedupeRuleTypes = NULL;
875 if (!$dedupeRuleTypes) {
876 $dedupeRuleTypes = array(
877 'Unsupervised' => ts('Unsupervised'),
878 'Supervised' => ts('Supervised'),
879 'General' => ts('General'),
882 return $dedupeRuleTypes;
886 * campaign group types
888 static function getCampaignGroupTypes() {
889 static $campaignGroupTypes = NULL;
890 if (!$campaignGroupTypes) {
891 $campaignGroupTypes = array(
892 'Include' => ts('Include'),
893 'Exclude' => ts('Exclude'),
896 return $campaignGroupTypes;
900 * subscription history method
902 static function getSubscriptionHistoryMethods() {
903 static $subscriptionHistoryMethods = NULL;
904 if (!$subscriptionHistoryMethods) {
905 $subscriptionHistoryMethods = array(
906 'Admin' => ts('Admin'),
907 'Email' => ts('Email'),
913 return $subscriptionHistoryMethods;
919 static function getPremiumUnits() {
920 static $premiumUnits = NULL;
921 if (!$premiumUnits) {
922 $premiumUnits = array(
924 'week' => ts('Week'),
925 'month' => ts('Month'),
926 'year' => ts('Year'),
930 return $premiumUnits;
936 static function getExtensionTypes() {
937 static $extensionTypes = NULL;
938 if (!$extensionTypes) {
939 $extensionTypes = array(
940 'payment' => ts('Payment'),
941 'search' => ts('Search'),
942 'report' => ts('Report'),
943 'module' => ts('Module'),
948 return $extensionTypes;
954 static function getJobFrequency() {
955 static $jobFrequency = NULL;
956 if (!$jobFrequency) {
957 $jobFrequency = array(
958 'Daily' => ts('Daily'),
959 'Hourly' => ts('Hourly'),
960 'Always' => ts('Every time cron job is run'),
964 return $jobFrequency;
968 * Search builder operators
970 static function getSearchBuilderOperators() {
971 static $searchBuilderOperators = NULL;
972 if (!$searchBuilderOperators) {
973 $searchBuilderOperators = array(
981 'LIKE' => ts('Like'),
982 'RLIKE' => ts('Regex'),
983 'IS EMPTY' => ts('Is Empty'),
984 'IS NOT EMPTY' => ts('Not Empty'),
985 'IS NULL' => ts('Is Null'),
986 'IS NOT NULL' => ts('Not Null'),
990 return $searchBuilderOperators;
994 * profile group types
998 static function getProfileGroupType() {
999 static $profileGroupType = NULL;
1000 if (!$profileGroupType) {
1001 $profileGroupType = array(
1002 'Activity' => ts('Activities'),
1003 'Contribution' => ts('Contributions'),
1004 'Membership' => ts('Memberships'),
1005 'Participant' => ts('Participants'),
1007 $contactTypes = self
::contactType();
1008 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
1009 $profileGroupType = array_merge($contactTypes, $profileGroupType );
1011 return $profileGroupType;
1016 * word replacement match type
1018 static function getWordReplacementMatchType() {
1019 static $wordReplacementMatchType = NULL;
1020 if (!$wordReplacementMatchType) {
1021 $wordReplacementMatchType = array(
1022 'exactMatch' => ts('Exact Match'),
1023 'wildcardMatch' => ts('Wildcard Match'),
1027 return $jobFrequency;