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
283 * @return array the date array
286 public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
289 'addEmptyOption' => TRUE,
290 'emptyOptionText' => ts('- select -'),
291 'emptyOptionValue' => '',
295 $date['format'] = $format;
299 $dao = new CRM_Core_DAO_PreferencesDate();
301 if (!$dao->find(TRUE)) {
302 CRM_Core_Error
::fatal();
306 if ($type == 'creditCard') {
307 $minOffset = $dao->start
;
308 $maxOffset = $dao->end
;
309 $date['format'] = $dao->date_format
;
310 $date['addEmptyOption'] = TRUE;
311 $date['emptyOptionText'] = ts('- select -');
312 $date['emptyOptionValue'] = '';
315 if (empty($date['format'])) {
316 $date['format'] = 'M d';
321 $date['minYear'] = $year - $minOffset;
322 $date['maxYear'] = $year +
$maxOffset;
327 * Values for UF form visibility options
331 public static function ufVisibility() {
333 'User and User Admin Only' => ts('User and User Admin Only'),
334 'Public Pages' => ts('Public Pages'),
335 'Public Pages and Listings' => ts('Public Pages and Listings'),
340 * Values for group form visibility options
344 public static function groupVisibility() {
346 'User and User Admin Only' => ts('User and User Admin Only'),
347 'Public Pages' => ts('Public Pages'),
352 * Different type of Mailing Components
357 public static function mailingComponents() {
359 'Header' => ts('Header'),
360 'Footer' => ts('Footer'),
361 'Reply' => ts('Reply Auto-responder'),
362 'OptOut' => ts('Opt-out Message'),
363 'Subscribe' => ts('Subscription Confirmation Request'),
364 'Welcome' => ts('Welcome Message'),
365 'Unsubscribe' => ts('Unsubscribe Message'),
366 'Resubscribe' => ts('Resubscribe Message'),
376 public function getHours() {
378 for ($i = 0; $i <= 6; $i++
) {
390 public function getMinutes() {
392 for ($i = 0; $i < 60; $i = $i +
15) {
399 * Get the Map Provider
401 * @return array $map array of map providers
404 public static function mapProvider() {
407 $map = CRM_Utils_System
::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
413 * Get the Geocoding Providers from available plugins
415 * @return array $geo array of geocoder providers
418 public static function geoProvider() {
421 $geo = CRM_Utils_System
::getPluginList('CRM/Utils/Geocode');
427 * Get the Address Standardization Providers from available
430 * @return array $addr array of address standardization providers
433 public static function addressProvider() {
436 $addr = CRM_Utils_System
::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate'));
442 * Different type of Mailing Tokens
447 public static function mailingTokens() {
449 '{action.unsubscribe}' => ts('Unsubscribe via email'),
450 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
451 '{action.resubscribe}' => ts('Resubscribe via email'),
452 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
453 '{action.optOut}' => ts('Opt out via email'),
454 '{action.optOutUrl}' => ts('Opt out via web page'),
455 '{action.forward}' => ts('Forward this email (link)'),
456 '{action.reply}' => ts('Reply to this email (link)'),
457 '{action.subscribeUrl}' => ts('Subscribe via web page'),
458 '{domain.name}' => ts('Domain name'),
459 '{domain.address}' => ts('Domain (organization) address'),
460 '{domain.phone}' => ts('Domain (organization) phone'),
461 '{domain.email}' => ts('Domain (organization) email'),
462 '{mailing.name}' => ts('Mailing name'),
463 '{mailing.group}' => ts('Mailing group'),
464 '{mailing.viewUrl}' => ts('Mailing permalink'),
469 * Different type of Activity Tokens
474 public static function activityTokens() {
476 '{activity.activity_id}' => ts('Activity ID'),
477 '{activity.subject}' => ts('Activity Subject'),
478 '{activity.details}' => ts('Activity Details'),
479 '{activity.activity_date_time}' => ts('Activity Date Time'),
484 * Different type of Membership Tokens
489 public static function membershipTokens() {
491 '{membership.id}' => ts('Membership ID'),
492 '{membership.status}' => ts('Membership Status'),
493 '{membership.type}' => ts('Membership Type'),
494 '{membership.start_date}' => ts('Membership Start Date'),
495 '{membership.join_date}' => ts('Membership Join Date'),
496 '{membership.end_date}' => ts('Membership End Date'),
497 '{membership.fee}' => ts('Membership Fee'),
502 * Different type of Event Tokens
507 public static function eventTokens() {
509 '{event.event_id}' => ts('Event ID'),
510 '{event.title}' => ts('Event Title'),
511 '{event.start_date}' => ts('Event Start Date'),
512 '{event.end_date}' => ts('Event End Date'),
513 '{event.event_type}' => ts('Event Type'),
514 '{event.summary}' => ts('Event Summary'),
515 '{event.contact_email}' => ts('Event Contact Email'),
516 '{event.contact_phone}' => ts('Event Contact Phone'),
517 '{event.description}' => ts('Event Description'),
518 '{event.location}' => ts('Event Location'),
519 '{event.fee_amount}' => ts('Event Fees'),
520 '{event.info_url}' => ts('Event Info URL'),
521 '{event.registration_url}' => ts('Event Registration URL'),
522 '{event.balance}' => ts('Event Balance'),
527 * Different type of Event Tokens
532 public static function contributionTokens() {
534 '{contribution.contribution_id}' => ts('Contribution ID'),
535 '{contribution.total_amount}' => ts('Total Amount'),
536 '{contribution.fee_amount}' => ts('Fee Amount'),
537 '{contribution.net_amount}' => ts('Net Amount'),
538 '{contribution.non_deductible_amount}' => ts('Non-deductible Amount'),
539 '{contribution.receive_date}' => ts('Contribution Receive Date'),
540 '{contribution.payment_instrument}' => ts('Payment Instrument'),
541 '{contribution.trxn_id}' => ts('Transaction ID'),
542 '{contribution.invoice_id}' => ts('Invoice ID'),
543 '{contribution.currency}' => ts('Currency'),
544 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
545 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
546 '{contribution.receipt_date}' => ts('Receipt Date'),
547 '{contribution.thankyou_date}' => ts('Thank You Date'),
548 '{contribution.contribution_source}' => ts('Contribution Source'),
549 '{contribution.amount_level}' => ts('Amount Level'),
550 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
551 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
552 '{contribution.contribution_status_id}' => ts('Contribution Status'),
553 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
554 //'{contribution.address_id}' => ts('Address ID'),
555 '{contribution.check_number}' => ts('Check Number'),
556 '{contribution.campaign}' => ts('Contribution Campaign'),
561 * Different type of Contact Tokens
566 public static function contactTokens() {
567 static $tokens = NULL;
569 $additionalFields = array(
570 'checksum' => array('title' => ts('Checksum')),
571 'contact_id' => array('title' => ts('Internal Contact ID')),
573 $exportFields = array_merge(CRM_Contact_BAO_Contact
::exportableFields(), $additionalFields);
575 $values = array_merge(array_keys($exportFields));
578 //FIXME:skipping some tokens for time being.
580 'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
581 'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
584 $customFields = CRM_Core_BAO_CustomField
::getFields(array('Individual', 'Address'));
585 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
587 foreach ($values as $val) {
588 if (in_array($val, $skipTokens)) {
591 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
592 $customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val);
593 if ($customFieldId) {
594 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
595 if (!empty($customFields[$customFieldId])) {
596 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
600 // Support legacy token names
601 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
602 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
606 // might as well get all the hook tokens to
607 $hookTokens = array();
608 CRM_Utils_Hook
::tokens($hookTokens);
609 foreach ($hookTokens as $tokenValues) {
610 foreach ($tokenValues as $key => $value) {
611 if (is_numeric($key)) {
614 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
615 $key = '{' . $key . '}';
617 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
618 $value = $matches[1];
620 $tokens[$key] = $value;
629 * Different type of Participant Tokens
634 public static function participantTokens() {
635 static $tokens = NULL;
637 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
639 $values = array_merge(array_keys($exportFields));
642 // skipping some tokens for time being.
644 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
645 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
648 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
650 foreach ($values as $key => $val) {
651 if (in_array($val, $skipTokens)) {
654 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
655 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
656 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
659 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
667 * CiviCRM supported date input formats
669 public static function getDatePluginInputFormats() {
670 $dateInputFormats = array(
671 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
672 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
673 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
674 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
675 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
676 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
677 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
678 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
679 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
680 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
681 "mm/dd" => ts('mm/dd (12/31)'),
682 "dd-mm" => ts('dd-mm (31-12)'),
683 "yy-mm" => ts('yyyy-mm (2009-12)'),
684 'M yy' => ts('M yyyy (Dec 2009)'),
685 "yy" => ts('yyyy (2009)'),
689 Year greater than 2000 get wrong result for following format
690 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
691 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
693 expected :: 2001-11-07
696 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
697 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
701 return $dateInputFormats;
705 * Map date plugin and actual format that is used by PHP
707 public static function datePluginToPHPFormats() {
708 $dateInputFormats = array(
709 "mm/dd/yy" => 'm/d/Y',
710 "dd/mm/yy" => 'd/m/Y',
711 "yy-mm-dd" => 'Y-m-d',
712 "dd-mm-yy" => 'd-m-Y',
713 "dd.mm.yy" => 'd.m.Y',
714 "M d, yy" => 'M j, Y',
716 "MM d, yy" => 'F j, Y',
717 "d MM yy" => 'j F Y',
718 "DD, d MM yy" => 'l, j F Y',
725 return $dateInputFormats;
731 public static function getTimeFormats() {
733 '1' => ts('12 Hours'),
734 '2' => ts('24 Hours'),
739 * Get numeric options
744 public static function getNumericOptions($start = 0, $end = 10) {
745 $numericOptions = array();
746 for ($i = $start; $i <= $end; $i++
) {
747 $numericOptions[$i] = $i;
749 return $numericOptions;
756 public static function getBarcodeTypes() {
758 'barcode' => ts('Linear (1D)'),
759 'qrcode' => ts('QR code'),
766 public static function getDedupeRuleTypes() {
768 'Unsupervised' => ts('Unsupervised'),
769 'Supervised' => ts('Supervised'),
770 'General' => ts('General'),
775 * Campaign group types
777 public static function getCampaignGroupTypes() {
779 'Include' => ts('Include'),
780 'Exclude' => ts('Exclude'),
785 * Subscription history method
787 public static function getSubscriptionHistoryMethods() {
789 'Admin' => ts('Admin'),
790 'Email' => ts('Email'),
799 public static function getPremiumUnits() {
802 'week' => ts('Week'),
803 'month' => ts('Month'),
804 'year' => ts('Year'),
811 public static function getExtensionTypes() {
813 'payment' => ts('Payment'),
814 'search' => ts('Search'),
815 'report' => ts('Report'),
816 'module' => ts('Module'),
824 public static function getJobFrequency() {
826 'Daily' => ts('Daily'),
827 'Hourly' => ts('Hourly'),
828 'Always' => ts('Every time cron job is run'),
833 * Search builder operators
835 public static function getSearchBuilderOperators() {
844 'LIKE' => ts('Like'),
845 'RLIKE' => ts('Regex'),
846 'IS EMPTY' => ts('Is Empty'),
847 'IS NOT EMPTY' => ts('Not Empty'),
848 'IS NULL' => ts('Is Null'),
849 'IS NOT NULL' => ts('Not Null'),
854 * Profile group types
858 public static function getProfileGroupType() {
859 $profileGroupType = array(
860 'Activity' => ts('Activities'),
861 'Contribution' => ts('Contributions'),
862 'Membership' => ts('Memberships'),
863 'Participant' => ts('Participants'),
865 $contactTypes = self
::contactType();
866 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
867 $profileGroupType = array_merge($contactTypes, $profileGroupType);
869 return $profileGroupType;
874 * Word replacement match type
876 public static function getWordReplacementMatchType() {
878 'exactMatch' => ts('Exact Match'),
879 'wildcardMatch' => ts('Wildcard Match'),
884 * Mailing group types
886 public static function getMailingGroupTypes() {
888 'Include' => ts('Include'),
889 'Exclude' => ts('Exclude'),
890 'Base' => ts('Base'),
897 public static function getMailingJobStatus() {
899 'Scheduled' => ts('Scheduled'),
900 'Running' => ts('Running'),
901 'Complete' => ts('Complete'),
902 'Paused' => ts('Paused'),
903 'Canceled' => ts('Canceled'),
907 public static function billingMode() {
909 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
910 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
911 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
916 * Frequency unit for schedule reminders
918 public static function getScheduleReminderFrequencyUnits() {
919 //@todo update schema to refer to option group direct & remove this
920 static $scheduleReminderFrequencyUnits = NULL;
921 if (!$scheduleReminderFrequencyUnits) {
922 $scheduleReminderFrequencyUnits = array(
923 'hour' => ts('hour')) + CRM_Core_OptionGroup
::values('recur_frequency_units');
926 return $scheduleReminderFrequencyUnits;