Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-03-20-15-52-17
[civicrm-core.git] / CRM / Core / SelectValues.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
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
32 *
33 * @package CRM
34 * @copyright CiviCRM LLC (c) 2004-2013
35 * $Id$
36 *
37 */
38 class CRM_Core_SelectValues {
39
40 /**CRM/Core/SelectValues.php
41 * different types of phones
42 * @static
43 */
44 static function &phoneType() {
45 static $phoneType = NULL;
46 if (!$phoneType) {
47 $phoneType = array(
48 '' => ts('- select -'),
49 'Phone' => ts('Phone'),
50 'Mobile' => ts('Mobile'),
51 'Fax' => ts('Fax'),
52 'Pager' => ts('Pager'),
53 );
54 }
55 return $phoneType;
56 }
57
58 /**
59 * preferred mail format
60 * @static
61 */
62 static function &pmf() {
63 static $pmf = NULL;
64 if (!$pmf) {
65 $pmf = array(
66 'Both' => ts('Both'),
67 'HTML' => ts('HTML'),
68 'Text' => ts('Text'),
69 );
70 }
71 return $pmf;
72 }
73
74 /**
75 * privacy options
76 * @static
77 */
78 static function &privacy() {
79 static $privacy = NULL;
80 if (!$privacy) {
81 $privacy = array(
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)'),
88 );
89 }
90 return $privacy;
91 }
92
93 /**
94 * various pre defined contact super types
95 * @static
96 */
97 static function &contactType() {
98 static $contactType = NULL;
99 if (!$contactType) {
100 $contactType = CRM_Contact_BAO_ContactType::basicTypePairs();
101 }
102 return $contactType;
103 }
104
105 /**
106 * various pre defined unit list
107 * @static
108 */
109 static function &unitList($unitType = NULL) {
110 static $unitList = NULL;
111 if (!$unitList) {
112 $unitList = array(
113 '' => ts('- select -'),
114 'day' => ts('day'),
115 'month' => ts('month'),
116 'year' => ts('year'),
117 );
118 if ($unitType == 'duration') {
119 $unitAdd = array(
120 'lifetime' => ts('lifetime'),
121 );
122 $unitList = array_merge($unitList, $unitAdd);
123 }
124 }
125 return $unitList;
126 }
127
128 /**
129 * membership type unit
130 * @static
131 */
132 static function membershipTypeUnitList( ) {
133 static $membershipTypeUnitList = NULL;
134 if (!$membershipTypeUnitList) {
135 $membershipTypeUnitList = self::unitList('duration');
136 }
137 return $membershipTypeUnitList;
138 }
139
140 /**
141 * various pre defined period types
142 * @static
143 */
144 static function &periodType() {
145 static $periodType = NULL;
146 if (!$periodType) {
147 $periodType = array(
148 '' => ts('- select -'),
149 'rolling' => ts('Rolling'),
150 'fixed' => ts('Fixed'),
151 );
152 }
153 return $periodType;
154 }
155
156 /**
157 * various pre defined member visibility options
158 * @static
159 */
160 static function &memberVisibility() {
161 static $visible = NULL;
162 if (!$visible) {
163 $visible = array(
164 'Public' => ts('Public'),
165 'Admin' => ts('Admin'),
166 );
167 }
168 return $visible;
169 }
170
171 /**
172 * various pre defined event dates
173 * @static
174 */
175 static function &eventDate() {
176 static $eventDate = NULL;
177 if (!$eventDate) {
178 $eventDate = array(
179 '' => ts('- select -'),
180 'start_date' => ts('start date'),
181 'end_date' => ts('end date'),
182 'join_date' => ts('member since'),
183 );
184 }
185 return $eventDate;
186 }
187
188 /**
189 * Custom form field types
190 * @static
191 */
192 static function &customHtmlType() {
193 static $customHtmlType = NULL;
194 if (!$customHtmlType) {
195 $customHtmlType = array(
196 '' => ts('- select -'),
197 'Text' => ts('Single-line input field (text or numeric)'),
198 'TextArea' => ts('Multi-line text box (textarea)'),
199 'Select' => ts('Drop-down (select list)'),
200 'Radio' => ts('Radio buttons'),
201 'CheckBox' => ts('Checkbox(es)'),
202 'Select Date' => ts('Select Date'),
203 'File' => ts('File'),
204 'Select State/Province' => ts('Select State/Province'),
205 'Multi-Select State/Province' => ts('Multi-Select State/Province'),
206 'Select Country' => ts('Select Country'),
207 'Multi-Select Country' => ts('Multi-Select Country'),
208 'RichTextEditor' => ts('Rich Text Editor'),
209 'Autocomplete-Select' => ts('Autocomplete-Select'),
210 'Multi-Select' => ts('Multi-Select'),
211 'AdvMulti-Select' => ts('AdvMulti-Select'),
212 'Link' => ts('Link'),
213 'ContactReference' => ts('Autocomplete Select'),
214 );
215 }
216 return $customHtmlType;
217 }
218
219 /**
220 * various pre defined extensions for dynamic properties and groups
221 *
222 * @static
223 */
224 static function &customGroupExtends() {
225 static $customGroupExtends = NULL;
226 if (!$customGroupExtends) {
227 $customGroupExtends = array(
228 'Activity' => ts('Activities'),
229 'Relationship' => ts('Relationships'),
230 'Contribution' => ts('Contributions'),
231 'Group' => ts('Groups'),
232 'Membership' => ts('Memberships'),
233 'Event' => ts('Events'),
234 'Participant' => ts('Participants'),
235 'ParticipantRole' => ts('Participants (Role)'),
236 'ParticipantEventName' => ts('Participants (Event Name)'),
237 'ParticipantEventType' => ts('Participants (Event Type)'),
238 'Pledge' => ts('Pledges'),
239 'Grant' => ts('Grants'),
240 'Address' => ts('Addresses'),
241 'Campaign' => ts('Campaigns'),
242 );
243 $contactTypes = self::contactType();
244 $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
245 $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects');
246 $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs);
247 }
248 return $customGroupExtends;
249 }
250
251 /**
252 * styles for displaying the custom data group
253 *
254 * @static
255 */
256 static function &customGroupStyle() {
257 static $customGroupStyle = NULL;
258 if (!$customGroupStyle) {
259 $customGroupStyle = array(
260 'Tab' => ts('Tab'),
261 'Inline' => ts('Inline'),
262 'Tab with table' => ts('Tab with table'),
263 );
264 }
265 return $customGroupStyle;
266 }
267
268 /**
269 * for displaying the uf group types
270 *
271 * @static
272 */
273 static function &ufGroupTypes() {
274 static $ufGroupType = NULL;
275 if (!$ufGroupType) {
276 $ufGroupType = array(
277 'Profile' => ts('Standalone Form or Directory'),
278 'Search Profile' => ts('Search Views'),
279 );
280 $config = CRM_Core_Config::singleton();
281 if ($config->userSystem->supports_form_extensions) {
282 $ufGroupType += array(
283 'User Registration' => ts('Drupal User Registration'),
284 'User Account' => ts('View/Edit Drupal User Account'),
285 );
286 }
287 }
288 return $ufGroupType;
289 }
290
291 /**
292 * the status of a contact within a group
293 *
294 * @static
295 */
296 static function &groupContactStatus() {
297 static $groupContactStatus = NULL;
298 if (!$groupContactStatus) {
299 $groupContactStatus = array(
300 'Added' => ts('Added'),
301 'Removed' => ts('Removed'),
302 'Pending' => ts('Pending'),
303 );
304 }
305 return $groupContactStatus;
306 }
307
308 /**
309 * list of Group Types
310 * @static
311 */
312 static function &groupType() {
313 static $groupType = NULL;
314 if (!$groupType) {
315 $groupType = array(
316 'query' => ts('Dynamic'),
317 'static' => ts('Static'),
318 );
319 }
320 return $groupType;
321 }
322
323 /**
324 * compose the parameters for a date select object
325 *
326 * @param $type the type of date
327 * @param $format date format ( QF format)
328 *
329 * @return array the date array
330 * @static
331 */
332 static function &date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL) {
333
334 $date = array(
335 'addEmptyOption' => TRUE,
336 'emptyOptionText' => ts('- select -'),
337 'emptyOptionValue' => '',
338 );
339
340 if ($format) {
341 $date['format'] = $format;
342 }
343 else {
344 if ($type) {
345 $dao = new CRM_Core_DAO_PreferencesDate();
346 $dao->name = $type;
347 if (!$dao->find(TRUE)) {
348 CRM_Core_Error::fatal();
349 }
350 }
351
352 if ($type == 'creditCard') {
353 $minOffset = $dao->start;
354 $maxOffset = $dao->end;
355 $date['format'] = $dao->date_format;
356 $date['addEmptyOption'] = TRUE;
357 $date['emptyOptionText'] = ts('- select -');
358 $date['emptyOptionValue'] = '';
359 }
360
361 if (empty($date['format'])) {
362 $date['format'] = 'M d';
363 }
364 }
365
366 $year = date('Y');
367 $date['minYear'] = $year - $minOffset;
368 $date['maxYear'] = $year + $maxOffset;
369 return $date;
370 }
371
372 /**
373 * values for UF form visibility options
374 *
375 * @static
376 */
377 static function ufVisibility() {
378 static $_visibility = array();
379 if (!$_visibility) {
380 $_visibility = array(
381 'User and User Admin Only' => ts('User and User Admin Only'),
382 'Public Pages' => ts('Public Pages'),
383 'Public Pages and Listings' => ts('Public Pages and Listings'),
384 );
385 }
386 return $_visibility;
387 }
388
389 /**
390 * values for group form visibility options
391 *
392 * @static
393 */
394 static function groupVisibility() {
395 static $_groupVisibility = NULL;
396 if (!$_groupVisibility) {
397 $_groupVisibility = array(
398 'User and User Admin Only' => ts('User and User Admin Only'),
399 'Public Pages' => ts('Public Pages'),
400 );
401 }
402 return $_groupVisibility;
403 }
404
405 /**
406 * different type of Mailing Components
407 *
408 * @static
409 * return array
410 */
411 static function &mailingComponents() {
412 static $components = NULL;
413
414 if (!$components) {
415 $components = array('Header' => ts('Header'),
416 'Footer' => ts('Footer'),
417 'Reply' => ts('Reply Auto-responder'),
418 'OptOut' => ts('Opt-out Message'),
419 'Subscribe' => ts('Subscription Confirmation Request'),
420 'Welcome' => ts('Welcome Message'),
421 'Unsubscribe' => ts('Unsubscribe Message'),
422 'Resubscribe' => ts('Resubscribe Message'),
423 );
424 }
425 return $components;
426 }
427
428 /**
429 * Function to get hours
430 *
431 *
432 * @static
433 */
434 function getHours() {
435 for ($i = 0; $i <= 6; $i++) {
436 $hours[$i] = $i;
437 }
438 return $hours;
439 }
440
441 /**
442 * Function to get minutes
443 *
444 *
445 * @static
446 */
447 function getMinutes() {
448 for ($i = 0; $i < 60; $i = $i + 15) {
449 $minutes[$i] = $i;
450 }
451 return $minutes;
452 }
453
454 /**
455 * Function to get the Map Provider
456 *
457 * @return array $map array of map providers
458 * @static
459 */
460 static function mapProvider() {
461 static $map = NULL;
462 if (!$map) {
463 return CRM_Utils_System::getPluginList('templates/CRM/Contact/Form/Task/Map', ".tpl");
464 }
465 return $map;
466 }
467
468 /**
469 * Function to get the Geocoding Providers from available plugins
470 *
471 * @return array $geo array of geocoder providers
472 * @static
473 */
474 static function geoProvider() {
475 static $geo = NULL;
476 if (!$geo) {
477 return CRM_Utils_System::getPluginList('CRM/Utils/Geocode');
478 }
479 return $geo;
480 }
481
482 /**
483 * Function to get the Address Standardization Providers from available
484 * plugins
485 *
486 * @return array $addr array of address standardization providers
487 * @static
488 */
489 static function addressProvider() {
490 static $addr = NULL;
491 if (!$addr) {
492 return CRM_Utils_System::getPluginList('CRM/Utils/Address',
493 '.php',
494 array('BatchUpdate')
495 );
496 }
497 return $addr;
498 }
499
500 /**
501 * different type of Mailing Tokens
502 *
503 * @static
504 * return array
505 */
506 static function &mailingTokens() {
507 static $tokens = NULL;
508
509 if (!$tokens) {
510 $tokens = array('{action.unsubscribe}' => ts('Unsubscribe via email'),
511 '{action.unsubscribeUrl}' => ts('Unsubscribe via web page'),
512 '{action.resubscribe}' => ts('Resubscribe via email'),
513 '{action.resubscribeUrl}' => ts('Resubscribe via web page'),
514 '{action.optOut}' => ts('Opt out via email'),
515 '{action.optOutUrl}' => ts('Opt out via web page'),
516 '{action.forward}' => ts('Forward this email (link)'),
517 '{action.reply}' => ts('Reply to this email (link)'),
518 '{action.subscribeUrl}' => ts('Subscribe via web page'),
519 '{domain.name}' => ts('Domain name'),
520 '{domain.address}' => ts('Domain (organization) address'),
521 '{domain.phone}' => ts('Domain (organization) phone'),
522 '{domain.email}' => ts('Domain (organization) email'),
523 '{mailing.name}' => ts('Mailing name'),
524 '{mailing.group}' => ts('Mailing group'),
525 '{mailing.viewUrl}' => ts('Mailing permalink'),
526 );
527 }
528 return $tokens;
529 }
530
531 /**
532 * different type of Activity Tokens
533 *
534 * @static
535 * return array
536 */
537 static function &activityTokens() {
538 static $tokens = NULL;
539
540 if (!$tokens) {
541 $tokens = array(
542 '{activity.activity_id}' => ts('Activity ID'),
543 '{activity.subject}' => ts('Activity Subject'),
544 '{activity.details}' => ts('Activity Details'),
545 '{activity.activity_date_time}' => ts('Activity Date Time'),
546 );
547 }
548 return $tokens;
549 }
550
551 /**
552 * different type of Membership Tokens
553 *
554 * @static
555 * return array
556 */
557 static function &membershipTokens() {
558 static $tokens = NULL;
559
560 if (!$tokens) {
561 $tokens = array(
562 '{membership.id}' => ts('Membership ID'),
563 '{membership.status}' => ts('Membership Status'),
564 '{membership.type}' => ts('Membership Type'),
565 '{membership.start_date}' => ts('Membership Start Date'),
566 '{membership.join_date}' => ts('Membership Join Date'),
567 '{membership.end_date}' => ts('Membership End Date'),
568 '{membership.fee}' => ts('Membership Fee'),
569 );
570 }
571 return $tokens;
572 }
573
574 /**
575 * different type of Event Tokens
576 *
577 * @static
578 * return array
579 */
580 static function &eventTokens() {
581 static $tokens = NULL;
582
583 if (!$tokens) {
584 $tokens = array(
585 '{event.event_id}' => ts('Event ID'),
586 '{event.title}' => ts('Event Title'),
587 '{event.start_date}' => ts('Event Start Date'),
588 '{event.end_date}' => ts('Event End Date'),
589 '{event.event_type}' => ts('Event Type'),
590 '{event.summary}' => ts('Event Summary'),
591 '{event.description}' => ts('Event Description'),
592 '{event.contact_email}' => ts('Event Contact Email'),
593 '{event.contact_phone}' => ts('Event Contact Phone'),
594 '{event.location}' => ts('Event Location'),
595 '{event.description}' => ts('Event Description'),
596 '{event.location}' => ts('Event Location'),
597 '{event.fee_amount}' => ts('Event Fees'),
598 '{event.info_url}' => ts('Event Info URL'),
599 '{event.registration_url}' => ts('Event Registration URL'),
600 '{event.balance}' => ts('Event Balance')
601 );
602 }
603 return $tokens;
604 }
605
606 /**
607 * different type of Event Tokens
608 *
609 * @static
610 * return array
611 */
612 static function &contributionTokens() {
613 static $tokens = NULL;
614
615 if (!$tokens) {
616 $tokens = array(
617 '{contribution.contribution_id}' => ts('Contribution ID'),
618 '{contribution.total_amount}' => ts('Total Amount'),
619 '{contribution.fee_amount}' => ts('Fee Amount'),
620 '{contribution.net_amount}' => ts('Net Amount'),
621 '{contribution.non_deductible_amount}' => ts('Non Deductible Amount'),
622 '{contribution.receive_date}' => ts('Contribution Receive Date'),
623 '{contribution.payment_instrument}' => ts('Payment Instrument'),
624 '{contribution.trxn_id}' => ts('Transaction ID'),
625 '{contribution.invoice_id}' => ts('Invoice ID'),
626 '{contribution.currency}' => ts('Currency'),
627 '{contribution.cancel_date}' => ts('Contribution Cancel Date'),
628 '{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
629 '{contribution.receipt_date}' => ts('Receipt Date'),
630 '{contribution.thankyou_date}' => ts('Thank You Date'),
631 '{contribution.contribution_source}' => ts('Contribution Source'),
632 '{contribution.amount_level}' => ts('Amount Level'),
633 //'{contribution.contribution_recur_id}' => ts('Contribution Recurring ID'),
634 //'{contribution.honor_contact_id}' => ts('Honor Contact ID'),
635 '{contribution.contribution_status_id}' => ts('Contribution Status'),
636 //'{contribution.honor_type_id}' => ts('Honor Type ID'),
637 //'{contribution.address_id}' => ts('Address ID'),
638 '{contribution.check_number}' => ts('Check Number'),
639 '{contribution.campaign}' => ts('Contribution Campaign'),
640 );
641 }
642 return $tokens;
643 }
644
645 /**
646 * different type of Contact Tokens
647 *
648 * @static
649 * return array
650 */
651 static function &contactTokens() {
652 static $tokens = NULL;
653 if (!$tokens) {
654 $additionalFields = array('checksum' => array('title' => ts('Checksum')),
655 'contact_id' => array('title' => ts('Internal Contact ID')),
656 );
657 $exportFields = array_merge(CRM_Contact_BAO_Contact::exportableFields(), $additionalFields);
658
659 $values = array_merge(array_keys($exportFields));
660 unset($values[0]);
661
662 //FIXME:skipping some tokens for time being.
663 $skipTokens = array(
664 'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
665 'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
666 );
667
668 $customFields = CRM_Core_BAO_CustomField::getFields('Individual');
669 $customFieldsAddress = CRM_Core_BAO_CustomField::getFields('Address');
670 $customFields = $customFields + $customFieldsAddress;
671 $legacyTokenNames = array_flip(CRM_Utils_Token::legacyContactTokens());
672
673 foreach ($values as $val) {
674 if (in_array($val, $skipTokens)) {
675 continue;
676 }
677 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
678 if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
679 $tokens["{contact.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
680 }
681 else {
682 // Support legacy token names
683 $tokenName = CRM_Utils_Array::value($val, $legacyTokenNames, $val);
684 $tokens["{contact.$tokenName}"] = $exportFields[$val]['title'];
685 }
686 }
687
688 // might as well get all the hook tokens to
689 $hookTokens = array();
690 CRM_Utils_Hook::tokens($hookTokens);
691 foreach ($hookTokens as $category => $tokenValues) {
692 foreach ($tokenValues as $key => $value) {
693 if (is_numeric($key)) {
694 $key = $value;
695 }
696 if (!preg_match('/^\{[^\}]+\}$/', $key)) {
697 $key = '{' . $key . '}';
698 }
699 if (preg_match('/^\{([^\}]+)\}$/', $value, $matches)) {
700 $value = $matches[1];
701 }
702 $tokens[$key] = $value;
703 }
704 }
705 }
706
707 return $tokens;
708 }
709
710 /**
711 * different type of Participant Tokens
712 *
713 * @static
714 * return array
715 */
716 static function &participantTokens() {
717 static $tokens = NULL;
718 if (!$tokens) {
719 $exportFields = CRM_Event_BAO_Participant::exportableFields();
720
721 $values = array_merge(array_keys($exportFields));
722 unset($values[0]);
723
724 // skipping some tokens for time being.
725 $skipTokens = array(
726 'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
727 'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
728 );
729
730 $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
731
732 foreach ($values as $key => $val) {
733 if (in_array($val, $skipTokens)) {
734 continue;
735 }
736 //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
737 if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
738 $tokens["{participant.$val}"] = !empty($customFields[$customFieldId]) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
739 }
740 else {
741 $tokens["{participant.$val}"] = $exportFields[$val]['title'];
742 }
743 }
744 }
745 return $tokens;
746 }
747
748 /**
749 * get qf mappig for all date parts.
750 *
751 */
752 static function &qfDatePartsMapping() {
753 static $qfDatePartsMapping = NULL;
754 if (!$qfDatePartsMapping) {
755 $qfDatePartsMapping = array(
756 '%b' => 'M',
757 '%B' => 'F',
758 '%d' => 'd',
759 '%e' => 'j',
760 '%E' => 'j',
761 '%f' => 'S',
762 '%H' => 'H',
763 '%I' => 'h',
764 '%k' => 'G',
765 '%l' => 'g',
766 '%m' => 'm',
767 '%M' => 'i',
768 '%p' => 'a',
769 '%P' => 'A',
770 '%Y' => 'Y',
771 );
772 }
773
774 return $qfDatePartsMapping;
775 }
776
777 /**
778 * CiviCRM supported date input formats
779 */
780 static function getDatePluginInputFormats() {
781 $dateInputFormats = array(
782 "mm/dd/yy" => ts('mm/dd/yyyy (12/31/2009)'),
783 "dd/mm/yy" => ts('dd/mm/yyyy (31/12/2009)'),
784 "yy-mm-dd" => ts('yyyy-mm-dd (2009-12-31)'),
785 "dd-mm-yy" => ts('dd-mm-yyyy (31-12-2009)'),
786 'dd.mm.yy' => ts('dd.mm.yyyy (31.12.2009)'),
787 "M d, yy" => ts('M d, yyyy (Dec 31, 2009)'),
788 'd M yy' => ts('d M yyyy (31 Dec 2009)'),
789 "MM d, yy" => ts('MM d, yyyy (December 31, 2009)'),
790 'd MM yy' => ts('d MM yyyy (31 December 2009)'),
791 "DD, d MM yy" => ts('DD, d MM yyyy (Thursday, 31 December 2009)'),
792 "mm/dd" => ts('mm/dd (12/31)'),
793 "dd-mm" => ts('dd-mm (31-12)'),
794 "yy-mm" => ts('yyyy-mm (2009-12)'),
795 'M yy' => ts('M yyyy (Dec 2009)'),
796 "yy" => ts('yyyy (2009)'),
797 );
798
799 /*
800 Year greater than 2000 get wrong result for following format
801 echo date( 'Y-m-d', strtotime( '7 Nov, 2001') );
802 echo date( 'Y-m-d', strtotime( '7 November, 2001') );
803 Return current year
804 expected :: 2001-11-07
805 output :: 2009-11-07
806 However
807 echo date( 'Y-m-d', strtotime( 'Nov 7, 2001') );
808 echo date( 'Y-m-d', strtotime( 'November 7, 2001') );
809 gives proper result
810 */
811
812
813 return $dateInputFormats;
814 }
815
816 /**
817 * Map date plugin and actual format that is used by PHP
818 */
819 static function datePluginToPHPFormats() {
820 $dateInputFormats = array(
821 "mm/dd/yy" => 'm/d/Y',
822 "dd/mm/yy" => 'd/m/Y',
823 "yy-mm-dd" => 'Y-m-d',
824 "dd-mm-yy" => 'd-m-Y',
825 "dd.mm.yy" => 'd.m.Y',
826 "M d, yy" => 'M j, Y',
827 "d M yy" => 'j M Y',
828 "MM d, yy" => 'F j, Y',
829 "d MM yy" => 'j F Y',
830 "DD, d MM yy" => 'l, j F Y',
831 "mm/dd" => 'm/d',
832 "dd-mm" => 'd-m',
833 "yy-mm" => 'Y-m',
834 "M yy" => 'M Y',
835 "yy" => 'Y',
836 );
837 return $dateInputFormats;
838 }
839
840 /**
841 * Time formats
842 */
843 static function getTimeFormats() {
844 $timeFormats = array('1' => ts('12 Hours'),
845 '2' => ts('24 Hours'),
846 );
847 return $timeFormats;
848 }
849
850 /**
851 * Function to get numeric options
852 *
853 *
854 * @static
855 */
856 public static function getNumericOptions($start = 0, $end = 10) {
857 for ($i = $start; $i <= $end; $i++) {
858 $numericOptions[$i] = $i;
859 }
860 return $numericOptions;
861 }
862
863 /**
864 * barcode types
865 * @static
866 */
867 static function getBarcodeTypes() {
868 static $barcodeTypes = NULL;
869 if (!$barcodeTypes) {
870 $barcodeTypes = array(
871 'barcode' => ts('Linear (1D)'),
872 'qrcode' => ts('QR code'),
873 );
874 }
875 return $barcodeTypes;
876 }
877
878 /**
879 * dedupe rule types
880 */
881 static function getDedupeRuleTypes() {
882 static $dedupeRuleTypes = NULL;
883 if (!$dedupeRuleTypes) {
884 $dedupeRuleTypes = array(
885 'Unsupervised' => ts('Unsupervised'),
886 'Supervised' => ts('Supervised'),
887 'General' => ts('General'),
888 );
889 }
890 return $dedupeRuleTypes;
891 }
892
893 /**
894 * campaign group types
895 */
896 static function getCampaignGroupTypes() {
897 static $campaignGroupTypes = NULL;
898 if (!$campaignGroupTypes) {
899 $campaignGroupTypes = array(
900 'Include' => ts('Include'),
901 'Exclude' => ts('Exclude'),
902 );
903 }
904 return $campaignGroupTypes;
905 }
906
907 /**
908 * subscription history method
909 */
910 static function getSubscriptionHistoryMethods() {
911 static $subscriptionHistoryMethods = NULL;
912 if (!$subscriptionHistoryMethods) {
913 $subscriptionHistoryMethods = array(
914 'Admin' => ts('Admin'),
915 'Email' => ts('Email'),
916 'Web' => ts('Web'),
917 'API' => ts('API'),
918 );
919 }
920
921 return $subscriptionHistoryMethods;
922 }
923
924 /**
925 * premium units
926 */
927 static function getPremiumUnits() {
928 static $premiumUnits = NULL;
929 if (!$premiumUnits) {
930 $premiumUnits = array(
931 'day' => ts('Day'),
932 'week' => ts('Week'),
933 'month' => ts('Month'),
934 'year' => ts('Year'),
935 );
936 }
937
938 return $premiumUnits;
939 }
940
941 /**
942 * extension types
943 */
944 static function getExtensionTypes() {
945 static $extensionTypes = NULL;
946 if (!$extensionTypes) {
947 $extensionTypes = array(
948 'payment' => ts('Payment'),
949 'search' => ts('Search'),
950 'report' => ts('Report'),
951 'module' => ts('Module'),
952 'sms' => ts('SMS'),
953 );
954 }
955
956 return $extensionTypes;
957 }
958
959 /**
960 * job frequency
961 */
962 static function getJobFrequency() {
963 static $jobFrequency = NULL;
964 if (!$jobFrequency) {
965 $jobFrequency = array(
966 'Daily' => ts('Daily'),
967 'Hourly' => ts('Hourly'),
968 'Always' => ts('Every time cron job is run'),
969 );
970 }
971
972 return $jobFrequency;
973 }
974
975 /**
976 * Search builder operators
977 */
978 static function getSearchBuilderOperators() {
979 static $searchBuilderOperators = NULL;
980 if (!$searchBuilderOperators) {
981 $searchBuilderOperators = array(
982 '=' => '=',
983 '!=' => '≠',
984 '>' => '>',
985 '<' => '<',
986 '>=' => '≥',
987 '<=' => '≤',
988 'IN' => ts('In'),
989 'LIKE' => ts('Like'),
990 'RLIKE' => ts('Regex'),
991 'IS EMPTY' => ts('Is Empty'),
992 'IS NOT EMPTY' => ts('Not Empty'),
993 'IS NULL' => ts('Is Null'),
994 'IS NOT NULL' => ts('Not Null'),
995 );
996 }
997
998 return $searchBuilderOperators;
999 }
1000
1001 /**
1002 * profile group types
1003 *
1004 * @static
1005 */
1006 static function getProfileGroupType() {
1007 static $profileGroupType = NULL;
1008 if (!$profileGroupType) {
1009 $profileGroupType = array(
1010 'Activity' => ts('Activities'),
1011 'Contribution' => ts('Contributions'),
1012 'Membership' => ts('Memberships'),
1013 'Participant' => ts('Participants'),
1014 );
1015 $contactTypes = self::contactType();
1016 $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
1017 $profileGroupType = array_merge($contactTypes, $profileGroupType );
1018 }
1019 return $profileGroupType;
1020 }
1021
1022
1023 /**
1024 * word replacement match type
1025 */
1026 static function getWordReplacementMatchType() {
1027 static $wordReplacementMatchType = NULL;
1028 if (!$wordReplacementMatchType) {
1029 $wordReplacementMatchType = array(
1030 'exactMatch' => ts('Exact Match'),
1031 'wildcardMatch' => ts('Wildcard Match'),
1032 );
1033 }
1034
1035 return $jobFrequency;
1036 }
1037
1038 /**
1039 * mailing group types
1040 */
1041 static function getMailingGroupTypes() {
1042 static $mailingGroupTypes = NULL;
1043 if (!$mailingGroupTypes) {
1044 $mailingGroupTypes = array(
1045 'Include' => ts('Include'),
1046 'Exclude' => ts('Exclude'),
1047 'Base' => ts('Base'),
1048 );
1049 }
1050 return $mailingGroupTypes;
1051 }
1052
1053 /**
1054 * Mailing Job Status
1055 */
1056 static function getMailingJobStatus() {
1057 static $mailingJobStatus = NULL;
1058 if (!$mailingJobStatus) {
1059 $mailingJobStatus = array(
1060 'Scheduled' => ts('Scheduled'),
1061 'Running' => ts('Running'),
1062 'Complete' => ts('Complete'),
1063 'Paused' => ts('Paused'),
1064 'Canceled' => ts('Canceled'),
1065 );
1066 }
1067
1068 return $mailingJobStatus;
1069 }
1070
1071 /**
1072 * Frequency unit for schedule reminders
1073 */
1074 static function getScheduleReminderFrequencyUnits() {
1075 static $scheduleReminderFrequencyUnits = NULL;
1076 if (!$scheduleReminderFrequencyUnits) {
1077 $scheduleReminderFrequencyUnits = array(
1078 'hour' => ts('hour')) + CRM_Core_OptionGroup::values('recur_frequency_units');
1079 }
1080
1081 return $scheduleReminderFrequencyUnits;
1082 }
1083 }
1084