3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 static function pmf() {
56 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 static function contactType() {
72 static $contactType = NULL;
74 $contactType = CRM_Contact_BAO_ContactType
::basicTypePairs();
80 * various pre defined unit list
83 static function unitList($unitType = NULL) {
86 'month' => ts('month'),
89 if ($unitType == 'duration') {
90 $unitList['lifetime'] = ts('lifetime');
96 * membership type unit
99 static function membershipTypeUnitList( ) {
100 return self
::unitList('duration');
104 * various pre defined period types
107 static function periodType() {
109 'rolling' => ts('Rolling'),
110 'fixed' => ts('Fixed'),
115 * various pre defined member visibility options
118 static function memberVisibility() {
120 'Public' => ts('Public'),
121 'Admin' => ts('Admin'),
126 * various pre defined event dates
129 static function eventDate() {
131 'start_date' => ts('start date'),
132 'end_date' => ts('end date'),
133 'join_date' => ts('member since'),
138 * Custom form field types
141 static function customHtmlType() {
143 'Text' => ts('Single-line input field (text or numeric)'),
144 'TextArea' => ts('Multi-line text box (textarea)'),
145 'Select' => ts('Drop-down (select list)'),
146 'Radio' => ts('Radio buttons'),
147 'CheckBox' => ts('Checkbox(es)'),
148 'Select Date' => ts('Select Date'),
149 'File' => ts('File'),
150 'Select State/Province' => ts('Select State/Province'),
151 'Multi-Select State/Province' => ts('Multi-Select State/Province'),
152 'Select Country' => ts('Select Country'),
153 'Multi-Select Country' => ts('Multi-Select Country'),
154 'RichTextEditor' => ts('Rich Text Editor'),
155 'Autocomplete-Select' => ts('Autocomplete-Select'),
156 'Multi-Select' => ts('Multi-Select'),
157 'AdvMulti-Select' => ts('AdvMulti-Select'),
158 'Link' => ts('Link'),
159 'ContactReference' => ts('Autocomplete Select'),
164 * various pre defined extensions for dynamic properties and groups
168 static function customGroupExtends() {
169 $customGroupExtends = array(
170 'Activity' => ts('Activities'),
171 'Relationship' => ts('Relationships'),
172 'Contribution' => ts('Contributions'),
173 'Group' => ts('Groups'),
174 'Membership' => ts('Memberships'),
175 'Event' => ts('Events'),
176 'Participant' => ts('Participants'),
177 'ParticipantRole' => ts('Participants (Role)'),
178 'ParticipantEventName' => ts('Participants (Event Name)'),
179 'ParticipantEventType' => ts('Participants (Event Type)'),
180 'Pledge' => ts('Pledges'),
181 'Grant' => ts('Grants'),
182 'Address' => ts('Addresses'),
183 'Campaign' => ts('Campaigns'),
185 $contactTypes = self
::contactType();
186 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
187 $extendObjs = CRM_Core_OptionGroup
::values('cg_extend_objects');
188 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
189 return $customGroupExtends;
193 * styles for displaying the custom data group
197 static function customGroupStyle() {
200 'Inline' => ts('Inline'),
201 'Tab with table' => ts('Tab with table'),
206 * for displaying the uf group types
210 static function ufGroupTypes() {
211 $ufGroupType = array(
212 'Profile' => ts('Standalone Form or Directory'),
213 'Search Profile' => ts('Search Views'),
216 if (CRM_Core_Config
::singleton()->userSystem
->supports_form_extensions
) {
217 $ufGroupType +
= array(
218 'User Registration' => ts('Drupal User Registration'),
219 'User Account' => ts('View/Edit Drupal User Account'),
226 * the status of a contact within a group
230 static function groupContactStatus() {
232 'Added' => ts('Added'),
233 'Removed' => ts('Removed'),
234 'Pending' => ts('Pending'),
239 * list of Group Types
242 static function groupType() {
244 'query' => ts('Dynamic'),
245 'static' => ts('Static'),
250 * compose the parameters for a date select object
252 * @param string|NULL $type the type of date
253 * @param string|NULL $format date format ( QF format)
255 * @param null $minOffset
256 * @param null $maxOffset
258 * @return array the date array
261 static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
264 'addEmptyOption' => TRUE,
265 'emptyOptionText' => ts('- select -'),
266 'emptyOptionValue' => '',
270 $date['format'] = $format;
274 $dao = new CRM_Core_DAO_PreferencesDate();
276 if (!$dao->find(TRUE)) {
277 CRM_Core_Error
::fatal();
281 if ($type == 'creditCard') {
282 $minOffset = $dao->start
;
283 $maxOffset = $dao->end
;
284 $date['format'] = $dao->date_format
;
285 $date['addEmptyOption'] = TRUE;
286 $date['emptyOptionText'] = ts('- select -');
287 $date['emptyOptionValue'] = '';
290 if (empty($date['format'])) {
291 $date['format'] = 'M d';
296 $date['minYear'] = $year - $minOffset;
297 $date['maxYear'] = $year +
$maxOffset;
302 * values for UF form visibility options
306 static function ufVisibility() {
308 'User and User Admin Only' => ts('User and User Admin Only'),
309 'Public Pages' => ts('Public Pages'),
310 'Public Pages and Listings' => ts('Public Pages and Listings'),
315 * values for group form visibility options
319 static function groupVisibility() {
321 'User and User Admin Only' => ts('User and User Admin Only'),
322 'Public Pages' => ts('Public Pages'),
327 * different type of Mailing Components
332 static function mailingComponents() {
333 return array('Header' => ts('Header'),
334 'Footer' => ts('Footer'),
335 'Reply' => ts('Reply Auto-responder'),
336 'OptOut' => ts('Opt-out Message'),
337 'Subscribe' => ts('Subscription Confirmation Request'),
338 'Welcome' => ts('Welcome Message'),
339 'Unsubscribe' => ts('Unsubscribe Message'),
340 'Resubscribe' => ts('Resubscribe Message'),
345 * Function to get hours
350 function getHours() {
352 for ($i = 0; $i <= 6; $i++
) {
359 * Function to get minutes
364 function getMinutes() {
366 for ($i = 0; $i < 60; $i = $i +
15) {
373 * Function to get the Map Provider
375 * @return array $map array of map providers
378 static function mapProvider() {
381 $map = CRM_Utils_System
::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
387 * Function to get the Geocoding Providers from available plugins
389 * @return array $geo array of geocoder providers
392 static function geoProvider() {
395 $geo = CRM_Utils_System
::getPluginList('CRM/Utils/Geocode');
401 * Function to get the Address Standardization Providers from available
404 * @return array $addr array of address standardization providers
407 static function addressProvider() {
410 $addr = CRM_Utils_System
::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate'));
416 * different type of Mailing Tokens
421 static function mailingTokens() {
423 '{action.unsubscribe}' => ts('Unsubscribe via email'),
424 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
425 '{action.resubscribe}' => ts('Resubscribe via email'),
426 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
427 '{action.optOut}' => ts('Opt out via email'),
428 '{action.optOutUrl}' => ts('Opt out via web page'),
429 '{action.forward}' => ts('Forward this email (link)'),
430 '{action.reply}' => ts('Reply to this email (link)'),
431 '{action.subscribeUrl}' => ts('Subscribe via web page'),
432 '{domain.name}' => ts('Domain name'),
433 '{domain.address}' => ts('Domain (organization) address'),
434 '{domain.phone}' => ts('Domain (organization) phone'),
435 '{domain.email}' => ts('Domain (organization) email'),
436 '{mailing.name}' => ts('Mailing name'),
437 '{mailing.group}' => ts('Mailing group'),
438 '{mailing.viewUrl}' => ts('Mailing permalink'),
443 * different type of Activity Tokens
448 static function activityTokens() {
450 '{activity.activity_id}' => ts('Activity ID'),
451 '{activity.subject}' => ts('Activity Subject'),
452 '{activity.details}' => ts('Activity Details'),
453 '{activity.activity_date_time}' => ts('Activity Date Time'),
458 * different type of Membership Tokens
463 static function membershipTokens() {
465 '{membership.id}' => ts('Membership ID'),
466 '{membership.status}' => ts('Membership Status'),
467 '{membership.type}' => ts('Membership Type'),
468 '{membership.start_date}' => ts('Membership Start Date'),
469 '{membership.join_date}' => ts('Membership Join Date'),
470 '{membership.end_date}' => ts('Membership End Date'),
471 '{membership.fee}' => ts('Membership Fee'),
476 * different type of Event Tokens
481 static function eventTokens() {
483 '{event.event_id}' => ts('Event ID'),
484 '{event.title}' => ts('Event Title'),
485 '{event.start_date}' => ts('Event Start Date'),
486 '{event.end_date}' => ts('Event End Date'),
487 '{event.event_type}' => ts('Event Type'),
488 '{event.summary}' => ts('Event Summary'),
489 '{event.contact_email}' => ts('Event Contact Email'),
490 '{event.contact_phone}' => ts('Event Contact Phone'),
491 '{event.description}' => ts('Event Description'),
492 '{event.location}' => ts('Event Location'),
493 '{event.fee_amount}' => ts('Event Fees'),
494 '{event.info_url}' => ts('Event Info URL'),
495 '{event.registration_url}' => ts('Event Registration URL'),
496 '{event.balance}' => ts('Event Balance')
501 * different type of Event Tokens
506 static function contributionTokens() {
508 '{contribution.contribution_id}' => ts('Contribution ID'),
509 '{contribution.total_amount}' => ts('Total Amount'),
510 '{contribution.fee_amount}' => ts('Fee Amount'),
511 '{contribution.net_amount}' => ts('Net Amount'),
512 '{contribution.non_deductible_amount}' => ts('Non Deductible Amount'),
513 '{contribution.receive_date}' => ts('Contribution Receive Date'),
514 '{contribution.payment_instrument}' => ts('Payment Instrument'),
515 '{contribution.trxn_id}' => ts('Transaction ID'),
516 '{contribution.invoice_id}' => ts('Invoice ID'),
517 '{contribution.currency}' => ts('Currency'),
518 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
519 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
520 '{contribution.receipt_date}' => ts('Receipt Date'),
521 '{contribution.thankyou_date}' => ts('Thank You Date'),
522 '{contribution.contribution_source}' => ts('Contribution Source'),
523 '{contribution.amount_level}' => ts('Amount Level'),
524 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
525 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
526 '{contribution.contribution_status_id}' => ts('Contribution Status'),
527 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
528 //'{contribution.address_id}' => ts('Address ID'),
529 '{contribution.check_number}' => ts('Check Number'),
530 '{contribution.campaign}' => ts('Contribution Campaign'),
535 * different type of Contact Tokens
540 static function contactTokens() {
541 static $tokens = NULL;
543 $additionalFields = array('checksum' => array('title' => ts('Checksum')),
544 'contact_id' => array('title' => ts('Internal Contact ID')),
546 $exportFields = array_merge(CRM_Contact_BAO_Contact
::exportableFields(), $additionalFields);
548 $values = array_merge(array_keys($exportFields));
551 //FIXME:skipping some tokens for time being.
553 'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
554 'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
557 $customFields = CRM_Core_BAO_CustomField
::getFields(array('Individual', 'Address'));
558 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
560 foreach ($values as $val) {
561 if (in_array($val, $skipTokens)) {
564 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
565 $customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val);
566 if ($customFieldId) {
567 // CRM-15191 - if key is not in $customFields then the field is disabled and should be ignored
568 if (!empty($customFields[$customFieldId])) {
569 $tokens["{contact.$val}"] = $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'];
573 // Support legacy token names
574 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
575 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
579 // might as well get all the hook tokens to
580 $hookTokens = array();
581 CRM_Utils_Hook
::tokens($hookTokens);
582 foreach ($hookTokens as $tokenValues) {
583 foreach ($tokenValues as $key => $value) {
584 if (is_numeric($key)) {
587 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
588 $key = '{' . $key . '}';
590 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
591 $value = $matches[1];
593 $tokens[$key] = $value;
602 * different type of Participant Tokens
607 static function participantTokens() {
608 static $tokens = NULL;
610 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
612 $values = array_merge(array_keys($exportFields));
615 // skipping some tokens for time being.
617 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
618 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
621 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
623 foreach ($values as $key => $val) {
624 if (in_array($val, $skipTokens)) {
627 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
628 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
629 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
632 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
640 * CiviCRM supported date input formats
642 static function getDatePluginInputFormats() {
643 $dateInputFormats = array(
644 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
645 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
646 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
647 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
648 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
649 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
650 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
651 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
652 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
653 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
654 "mm/dd" => ts('mm/dd (12/31)'),
655 "dd-mm" => ts('dd-mm (31-12)'),
656 "yy-mm" => ts('yyyy-mm (2009-12)'),
657 'M yy' => ts('M yyyy (Dec 2009)'),
658 "yy" => ts('yyyy (2009)'),
662 Year greater than 2000 get wrong result for following format
663 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
664 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
666 expected :: 2001-11-07
669 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
670 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
675 return $dateInputFormats;
679 * Map date plugin and actual format that is used by PHP
681 static function datePluginToPHPFormats() {
682 $dateInputFormats = array(
683 "mm/dd/yy" => 'm/d/Y',
684 "dd/mm/yy" => 'd/m/Y',
685 "yy-mm-dd" => 'Y-m-d',
686 "dd-mm-yy" => 'd-m-Y',
687 "dd.mm.yy" => 'd.m.Y',
688 "M d, yy" => 'M j, Y',
690 "MM d, yy" => 'F j, Y',
691 "d MM yy" => 'j F Y',
692 "DD, d MM yy" => 'l, j F Y',
699 return $dateInputFormats;
705 static function getTimeFormats() {
707 '1' => ts('12 Hours'),
708 '2' => ts('24 Hours'),
713 * Function to get numeric options
718 public static function getNumericOptions($start = 0, $end = 10) {
719 $numericOptions = array();
720 for ($i = $start; $i <= $end; $i++
) {
721 $numericOptions[$i] = $i;
723 return $numericOptions;
730 static function getBarcodeTypes() {
732 'barcode' => ts('Linear (1D)'),
733 'qrcode' => ts('QR code'),
740 static function getDedupeRuleTypes() {
742 'Unsupervised' => ts('Unsupervised'),
743 'Supervised' => ts('Supervised'),
744 'General' => ts('General'),
749 * campaign group types
751 static function getCampaignGroupTypes() {
753 'Include' => ts('Include'),
754 'Exclude' => ts('Exclude'),
759 * subscription history method
761 static function getSubscriptionHistoryMethods() {
763 'Admin' => ts('Admin'),
764 'Email' => ts('Email'),
773 static function getPremiumUnits() {
776 'week' => ts('Week'),
777 'month' => ts('Month'),
778 'year' => ts('Year'),
785 static function getExtensionTypes() {
787 'payment' => ts('Payment'),
788 'search' => ts('Search'),
789 'report' => ts('Report'),
790 'module' => ts('Module'),
798 static function getJobFrequency() {
800 'Daily' => ts('Daily'),
801 'Hourly' => ts('Hourly'),
802 'Always' => ts('Every time cron job is run'),
807 * Search builder operators
809 static function getSearchBuilderOperators() {
818 'LIKE' => ts('Like'),
819 'RLIKE' => ts('Regex'),
820 'IS EMPTY' => ts('Is Empty'),
821 'IS NOT EMPTY' => ts('Not Empty'),
822 'IS NULL' => ts('Is Null'),
823 'IS NOT NULL' => ts('Not Null'),
828 * profile group types
832 static function getProfileGroupType() {
833 $profileGroupType = array(
834 'Activity' => ts('Activities'),
835 'Contribution' => ts('Contributions'),
836 'Membership' => ts('Memberships'),
837 'Participant' => ts('Participants'),
839 $contactTypes = self
::contactType();
840 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
841 $profileGroupType = array_merge($contactTypes, $profileGroupType );
843 return $profileGroupType;
848 * word replacement match type
850 static function getWordReplacementMatchType() {
852 'exactMatch' => ts('Exact Match'),
853 'wildcardMatch' => ts('Wildcard Match'),
858 * mailing group types
860 static function getMailingGroupTypes() {
862 'Include' => ts('Include'),
863 'Exclude' => ts('Exclude'),
864 'Base' => ts('Base'),
871 static function getMailingJobStatus() {
873 'Scheduled' => ts('Scheduled'),
874 'Running' => ts('Running'),
875 'Complete' => ts('Complete'),
876 'Paused' => ts('Paused'),
877 'Canceled' => ts('Canceled'),
881 static function billingMode() {
883 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
884 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
885 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
890 * Frequency unit for schedule reminders
892 static function getScheduleReminderFrequencyUnits() {
893 //@todo update schema to refer to option group direct & remove this
894 static $scheduleReminderFrequencyUnits = NULL;
895 if (!$scheduleReminderFrequencyUnits) {
896 $scheduleReminderFrequencyUnits = array(
897 'hour' => ts('hour')) + CRM_Core_OptionGroup
::values('recur_frequency_units');
900 return $scheduleReminderFrequencyUnits;