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('Individual');
558 $customFieldsAddress = CRM_Core_BAO_CustomField
::getFields('Address');
559 $customFields = $customFields +
$customFieldsAddress;
560 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
562 foreach ($values as $val) {
563 if (in_array($val, $skipTokens)) {
566 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
567 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
568 $tokens["{contact.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
571 // Support legacy token names
572 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
573 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
577 // might as well get all the hook tokens to
578 $hookTokens = array();
579 CRM_Utils_Hook
::tokens($hookTokens);
580 foreach ($hookTokens as $tokenValues) {
581 foreach ($tokenValues as $key => $value) {
582 if (is_numeric($key)) {
585 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
586 $key = '{' . $key . '}';
588 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
589 $value = $matches[1];
591 $tokens[$key] = $value;
600 * different type of Participant Tokens
605 static function participantTokens() {
606 static $tokens = NULL;
608 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
610 $values = array_merge(array_keys($exportFields));
613 // skipping some tokens for time being.
615 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
616 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
619 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
621 foreach ($values as $key => $val) {
622 if (in_array($val, $skipTokens)) {
625 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
626 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
627 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
630 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
638 * CiviCRM supported date input formats
640 static function getDatePluginInputFormats() {
641 $dateInputFormats = array(
642 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
643 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
644 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
645 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
646 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
647 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
648 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
649 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
650 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
651 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
652 "mm/dd" => ts('mm/dd (12/31)'),
653 "dd-mm" => ts('dd-mm (31-12)'),
654 "yy-mm" => ts('yyyy-mm (2009-12)'),
655 'M yy' => ts('M yyyy (Dec 2009)'),
656 "yy" => ts('yyyy (2009)'),
660 Year greater than 2000 get wrong result for following format
661 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
662 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
664 expected :: 2001-11-07
667 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
668 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
673 return $dateInputFormats;
677 * Map date plugin and actual format that is used by PHP
679 static function datePluginToPHPFormats() {
680 $dateInputFormats = array(
681 "mm/dd/yy" => 'm/d/Y',
682 "dd/mm/yy" => 'd/m/Y',
683 "yy-mm-dd" => 'Y-m-d',
684 "dd-mm-yy" => 'd-m-Y',
685 "dd.mm.yy" => 'd.m.Y',
686 "M d, yy" => 'M j, Y',
688 "MM d, yy" => 'F j, Y',
689 "d MM yy" => 'j F Y',
690 "DD, d MM yy" => 'l, j F Y',
697 return $dateInputFormats;
703 static function getTimeFormats() {
705 '1' => ts('12 Hours'),
706 '2' => ts('24 Hours'),
711 * Function to get numeric options
716 public static function getNumericOptions($start = 0, $end = 10) {
717 $numericOptions = array();
718 for ($i = $start; $i <= $end; $i++
) {
719 $numericOptions[$i] = $i;
721 return $numericOptions;
728 static function getBarcodeTypes() {
730 'barcode' => ts('Linear (1D)'),
731 'qrcode' => ts('QR code'),
738 static function getDedupeRuleTypes() {
740 'Unsupervised' => ts('Unsupervised'),
741 'Supervised' => ts('Supervised'),
742 'General' => ts('General'),
747 * campaign group types
749 static function getCampaignGroupTypes() {
751 'Include' => ts('Include'),
752 'Exclude' => ts('Exclude'),
757 * subscription history method
759 static function getSubscriptionHistoryMethods() {
761 'Admin' => ts('Admin'),
762 'Email' => ts('Email'),
771 static function getPremiumUnits() {
774 'week' => ts('Week'),
775 'month' => ts('Month'),
776 'year' => ts('Year'),
783 static function getExtensionTypes() {
785 'payment' => ts('Payment'),
786 'search' => ts('Search'),
787 'report' => ts('Report'),
788 'module' => ts('Module'),
796 static function getJobFrequency() {
798 'Daily' => ts('Daily'),
799 'Hourly' => ts('Hourly'),
800 'Always' => ts('Every time cron job is run'),
805 * Search builder operators
807 static function getSearchBuilderOperators() {
816 'LIKE' => ts('Like'),
817 'RLIKE' => ts('Regex'),
818 'IS EMPTY' => ts('Is Empty'),
819 'IS NOT EMPTY' => ts('Not Empty'),
820 'IS NULL' => ts('Is Null'),
821 'IS NOT NULL' => ts('Not Null'),
826 * profile group types
830 static function getProfileGroupType() {
831 $profileGroupType = array(
832 'Activity' => ts('Activities'),
833 'Contribution' => ts('Contributions'),
834 'Membership' => ts('Memberships'),
835 'Participant' => ts('Participants'),
837 $contactTypes = self
::contactType();
838 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
839 $profileGroupType = array_merge($contactTypes, $profileGroupType );
841 return $profileGroupType;
846 * word replacement match type
848 static function getWordReplacementMatchType() {
850 'exactMatch' => ts('Exact Match'),
851 'wildcardMatch' => ts('Wildcard Match'),
856 * mailing group types
858 static function getMailingGroupTypes() {
860 'Include' => ts('Include'),
861 'Exclude' => ts('Exclude'),
862 'Base' => ts('Base'),
869 static function getMailingJobStatus() {
871 'Scheduled' => ts('Scheduled'),
872 'Running' => ts('Running'),
873 'Complete' => ts('Complete'),
874 'Paused' => ts('Paused'),
875 'Canceled' => ts('Canceled'),
880 * Frequency unit for schedule reminders
882 static function getScheduleReminderFrequencyUnits() {
883 //@todo update schema to refer to option group direct & remove this
884 static $scheduleReminderFrequencyUnits = NULL;
885 if (!$scheduleReminderFrequencyUnits) {
886 $scheduleReminderFrequencyUnits = array(
887 'hour' => ts('hour')) + CRM_Core_OptionGroup
::values('recur_frequency_units');
890 return $scheduleReminderFrequencyUnits;