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 (!CRM_Utils_Array
::value('format', $date)) {
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'),
598 * different type of Event Tokens
603 static function &contributionTokens() {
604 static $tokens = NULL;
608 '{contribution.contribution_id}' => ts('Contribution ID'),
609 '{contribution.total_amount}' => ts('Total Amount'),
610 '{contribution.fee_amount}' => ts('Fee Amount'),
611 '{contribution.net_amount}' => ts('Net Amount'),
612 '{contribution.non_deductible_amount}' => ts('Non Deductible Amount'),
613 '{contribution.receive_date}' => ts('Contribution Receive Date'),
614 '{contribution.payment_instrument}' => ts('Payment Instrument'),
615 '{contribution.trxn_id}' => ts('Transaction ID'),
616 '{contribution.invoice_id}' => ts('Invoice ID'),
617 '{contribution.currency}' => ts('Currency'),
618 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
619 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
620 '{contribution.receipt_date}' => ts('Receipt Date'),
621 '{contribution.thankyou_date}' => ts('Thank You Date'),
622 '{contribution.contribution_source}' => ts('Contribution Source'),
623 '{contribution.amount_level}' => ts('Amount Level'),
624 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
625 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
626 '{contribution.contribution_status_id}' => ts('Contribution Status'),
627 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
628 //'{contribution.address_id}' => ts('Address ID'),
629 '{contribution.check_number}' => ts('Check Number'),
630 '{contribution.campaign}' => ts('Contribution Campaign'),
637 * different type of Contact Tokens
642 static function &contactTokens() {
643 static $tokens = NULL;
645 $additionalFields = array('checksum' => array('title' => ts('Checksum')),
646 'contact_id' => array('title' => ts('Internal Contact ID')),
648 $exportFields = array_merge(CRM_Contact_BAO_Contact
::exportableFields(), $additionalFields);
650 $values = array_merge(array_keys($exportFields));
653 //FIXME:skipping some tokens for time being.
655 'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
656 'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
659 $customFields = CRM_Core_BAO_CustomField
::getFields('Individual');
660 $customFieldsAddress = CRM_Core_BAO_CustomField
::getFields('Address');
661 $customFields = $customFields +
$customFieldsAddress;
662 $legacyTokenNames = array_flip(CRM_Utils_Token
::legacyContactTokens());
664 foreach ($values as $val) {
665 if (in_array($val, $skipTokens)) {
668 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
669 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
670 $tokens["{contact.$val}"] = CRM_Utils_Array
::value($customFieldId, $customFields) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
673 // Support legacy token names
674 $tokenName = CRM_Utils_Array
::value($val, $legacyTokenNames, $val);
675 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
679 // might as well get all the hook tokens to
680 $hookTokens = array();
681 CRM_Utils_Hook
::tokens($hookTokens);
682 foreach ($hookTokens as $category => $tokenValues) {
683 foreach ($tokenValues as $key => $value) {
684 if (is_numeric($key)) {
687 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
688 $key = '{' . $key . '}';
690 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
691 $value = $matches[1];
693 $tokens[$key] = $value;
702 * different type of Participant Tokens
707 static function &participantTokens() {
708 static $tokens = NULL;
710 $exportFields = CRM_Event_BAO_Participant
::exportableFields();
712 $values = array_merge(array_keys($exportFields));
715 // skipping some tokens for time being.
717 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
718 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
721 $customFields = CRM_Core_BAO_CustomField
::getFields('Participant');
723 foreach ($values as $key => $val) {
724 if (in_array($val, $skipTokens)) {
727 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
728 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($val)) {
729 $tokens["{participant.$val}"] = CRM_Utils_Array
::value($customFieldId, $customFields) ?
$customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
732 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
740 * get qf mappig for all date parts.
743 static function &qfDatePartsMapping() {
744 static $qfDatePartsMapping = NULL;
745 if (!$qfDatePartsMapping) {
746 $qfDatePartsMapping = array(
765 return $qfDatePartsMapping;
769 * CiviCRM supported date input formats
771 static function getDatePluginInputFormats() {
772 $dateInputFormats = array(
773 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
774 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
775 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
776 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
777 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
778 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
779 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
780 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
781 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
782 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
783 "mm/dd" => ts('mm/dd (12/31)'),
784 "dd-mm" => ts('dd-mm (31-12)'),
785 "yy-mm" => ts('yyyy-mm (2009-12)'),
786 'M yy' => ts('M yyyy (Dec 2009)'),
787 "yy" => ts('yyyy (2009)'),
791 Year greater than 2000 get wrong result for following format
792 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
793 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
795 expected :: 2001-11-07
798 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
799 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
804 return $dateInputFormats;
808 * Map date plugin and actual format that is used by PHP
810 static function datePluginToPHPFormats() {
811 $dateInputFormats = array(
812 "mm/dd/yy" => 'm/d/Y',
813 "dd/mm/yy" => 'd/m/Y',
814 "yy-mm-dd" => 'Y-m-d',
815 "dd-mm-yy" => 'd-m-Y',
816 "dd.mm.yy" => 'd.m.Y',
817 "M d, yy" => 'M j, Y',
819 "MM d, yy" => 'F j, Y',
820 "d MM yy" => 'j F Y',
821 "DD, d MM yy" => 'l, j F Y',
828 return $dateInputFormats;
834 static function getTimeFormats() {
835 $timeFormats = array('1' => ts('12 Hours'),
836 '2' => ts('24 Hours'),
842 * Function to get numeric options
847 public static function getNumericOptions($start = 0, $end = 10) {
848 for ($i = $start; $i <= $end; $i++
) {
849 $numericOptions[$i] = $i;
851 return $numericOptions;
858 static function getBarcodeTypes() {
859 static $barcodeTypes = NULL;
860 if (!$barcodeTypes) {
861 $barcodeTypes = array(
862 'barcode' => ts('Linear (1D)'),
863 'qrcode' => ts('QR code'),
866 return $barcodeTypes;