Force membership auto-renew on by default
[civicrm-core.git] / templates / CRM / Contribute / Form / Contribution / MembershipBlock.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
fee14197 3 | CiviCRM version 5 |
6a488035 4 +--------------------------------------------------------------------+
6b83d5bd 5 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*}
26{if !empty($useForMember) AND !$is_quick_config}
a7aa881c
MWMC
27 <div id="membership" class="crm-group membership-group">
28 {if $context EQ "makeContribution"}
29 <div id="priceset">
6a488035 30 <fieldset>
a7aa881c 31 {if $renewal_mode}
6a488035 32 {if $membershipBlock.renewal_title}
a7aa881c 33 <legend>{$membershipBlock.renewal_title}</legend>
6a488035
TO
34 {/if}
35 {if $membershipBlock.renewal_text}
a7aa881c
MWMC
36 <div id="membership-intro" class="crm-section membership_renewal_intro-section">
37 {$membershipBlock.renewal_text}
38 </div>
6a488035 39 {/if}
a7aa881c
MWMC
40 {else}
41 {if $membershipBlock.new_title}
6a488035 42 <legend>{$membershipBlock.new_title}</legend>
a7aa881c
MWMC
43 {/if}
44 {if $membershipBlock.new_text}
6a488035 45 <div id="membership-intro" class="crm-section membership_new_intro-section">
a7aa881c 46 {$membershipBlock.new_text}
6a488035 47 </div>
a7aa881c 48 {/if}
6a488035 49 {/if}
a7aa881c 50 {if !empty($membershipTypes)}
6a488035 51 {foreach from=$membershipTypes item=row}
a7aa881c
MWMC
52 {if array_key_exists( 'current_membership', $row )}
53 <div id='help'>
54 {* Lifetime memberships have no end-date so current_membership array key exists but is NULL *}
55 {if $row.current_membership}
56 {if $row.current_membership|date_format:"%Y%m%d" LT $smarty.now|date_format:"%Y%m%d"}
57 {ts 1=$row.current_membership|crmDate 2=$row.name}Your <strong>%2</strong> membership expired on %1.{/ts}<br />
6a488035 58 {else}
a7aa881c 59 {ts 1=$row.current_membership|crmDate 2=$row.name}Your <strong>%2</strong> membership expires on %1.{/ts}<br />
6a488035 60 {/if}
a7aa881c
MWMC
61 {else}
62 {ts 1=$row.name}Your <strong>%1</strong> membership does not expire (you do not need to renew that membership).{/ts}<br />
63 {/if}
64 </div>
65 {/if}
6a488035 66 {/foreach}
a7aa881c 67 {/if}
6a488035 68
a7aa881c 69 {include file="CRM/Price/Form/PriceSet.tpl" extends="Membership"}
6a488035 70 </fieldset>
a7aa881c
MWMC
71 </div>
72 {elseif $lineItem and $priceSetID AND !$is_quick_config}
73 {assign var="totalAmount" value=$amount}
74 <div class="header-dark">
75 {ts}Membership Fee{/ts}
76 </div>
77 <div class="display-block">
78 {include file="CRM/Price/Page/LineItem.tpl" context="Membership"}
79 </div>
80 {/if}
6a488035 81 </div>
6a488035 82{literal}
a7aa881c
MWMC
83 <script type="text/javascript">
84 CRM.$(function($) {
85 //if price set is set we use below below code to show for showing auto renew
86 var autoRenewOption = {/literal}'{$autoRenewOption}'{literal};
87 var autoRenew = $("#auto_renew_section");
88 var autoRenewCheckbox = $("#auto_renew");
89 var forceRenew = $("#force_renew");
90 autoRenew.hide();
91 forceRenew.hide();
92 if ( autoRenewOption == 1 ) {
c843169c 93 autoRenew.show();
a7aa881c 94 } else if ( autoRenewOption == 2 ) {
81308445
JP
95 autoRenewCheckbox.prop('checked', true );
96 autoRenewCheckbox.attr( 'readonly', true );
c843169c
MW
97 autoRenew.hide();
98 forceRenew.show();
a7aa881c
MWMC
99 }
100 });
101 </script>
6a488035
TO
102{/literal}
103{elseif $membershipBlock AND !$is_quick_config}
a7aa881c
MWMC
104 <div id="membership" class="crm-group membership-group">
105 {if $context EQ "makeContribution"}
106 <fieldset>
6a488035
TO
107 {if $renewal_mode }
108 {if $membershipBlock.renewal_title}
a7aa881c 109 <legend>{$membershipBlock.renewal_title}</legend>
6a488035
TO
110 {/if}
111 {if $membershipBlock.renewal_text}
a7aa881c
MWMC
112 <div id="membership-intro" class="crm-section membership_renewal_intro-section">
113 <p>{$membershipBlock.renewal_text}</p>
114 </div>
6a488035
TO
115 {/if}
116
117 {else}
118 {if $membershipBlock.new_title}
a7aa881c 119 <legend>{$membershipBlock.new_title}</legend>
6a488035
TO
120 {/if}
121 {if $membershipBlock.new_text}
a7aa881c
MWMC
122 <div id="membership-intro" class="crm-section membership_new_intro-section">
123 <p>{$membershipBlock.new_text}</p>
124 </div>
6a488035
TO
125 {/if}
126 {/if}
a7aa881c
MWMC
127 {/if}
128 {if $context neq "makeContribution" }
6a488035 129 <div class="header-dark">
a7aa881c
MWMC
130 {if $renewal_mode }
131 {if $membershipBlock.renewal_title}
132 {$membershipBlock.renewal_title}
133 {else}
134 {ts}Select a Membership Renewal Level{/ts}
135 {/if}
6a488035 136
a7aa881c
MWMC
137 {else}
138 {if $membershipBlock.new_title}
139 {$membershipBlock.new_title}
6a488035 140 {else}
a7aa881c 141 {ts}Select a Membership Level{/ts}
6a488035 142 {/if}
a7aa881c 143 {/if}
6a488035 144 </div>
a7aa881c 145 {/if}
6a488035 146
a7aa881c
MWMC
147 {if $context EQ "makeContribution"}
148 </fieldset>
6a488035 149 {/if}
a7aa881c 150 </div>
6a488035
TO
151
152{/if}{* membership block end here *}
153
154{if $membershipBlock AND $is_quick_config}
a7aa881c
MWMC
155 {if $context neq "makeContribution" }
156 <div class="header-dark">
157 {if $renewal_mode }
158 {if $membershipBlock.renewal_title}
159 {$membershipBlock.renewal_title}
160 {else}
161 {ts}Select a Membership Renewal Level{/ts}
162 {/if}
163 {else}
164 {if $membershipBlock.new_title}
165 {$membershipBlock.new_title}
166 {else}
167 {ts}Select a Membership Level{/ts}
6a488035 168 {/if}
a7aa881c 169 {/if}
6a488035 170 </div>
a7aa881c
MWMC
171 {/if}
172 {strip}
173 <table id="membership-listings">
174 {foreach from=$membershipTypes item=row}
6a488035 175 <tr {if $context EQ "makeContribution"}class="odd-row" {/if}valign="top">
a7aa881c
MWMC
176 {if $showRadio }
177 {assign var="pid" value=$row.id}
178 <td style="width: 1em;">{$form.selectMembership.$pid.html}</td>
179 {else}
180 <td>&nbsp;</td>
181 {/if}
182 <td style="width: auto;">
6a488035
TO
183 <span class="bold">{$row.name} &nbsp;
184 {if ($membershipBlock.display_min_fee AND $context EQ "makeContribution") AND $row.minimum_fee GT 0 }
a7aa881c
MWMC
185 {if $is_separate_payment OR ! $form.amount.label}
186 &ndash; {$row.minimum_fee|crmMoney}
187 {else}
188 {ts 1=$row.minimum_fee|crmMoney}(contribute at least %1 to be eligible for this membership){/ts}
189 {/if}
6a488035
TO
190 {/if}
191 </span><br />
a7aa881c
MWMC
192 {$row.description} &nbsp;
193 </td>
6a488035 194
a7aa881c
MWMC
195 <td style="width: auto;">
196 {* Check if there is an existing membership of this type (current_membership NOT empty) and if the end-date is prior to today. *}
197 {if array_key_exists( 'current_membership', $row ) AND $context EQ "makeContribution" }
198 {if $row.current_membership}
199 {if $row.current_membership|date_format:"%Y%m%d" LT $smarty.now|date_format:"%Y%m%d"}
200 <br /><em>{ts 1=$row.current_membership|crmDate 2=$row.name}Your <strong>%2</strong> membership expired on %1.{/ts}</em>
201 {else}
202 <br /><em>{ts 1=$row.current_membership|crmDate 2=$row.name}Your <strong>%2</strong> membership expires on %1.{/ts}</em>
203 {/if}
6a488035 204 {else}
a7aa881c 205 {ts 1=$row.name}Your <strong>%1</strong> membership does not expire (you do not need to renew that membership).{/ts}<br />
6a488035 206 {/if}
a7aa881c
MWMC
207 {else}
208 &nbsp;
209 {/if}
210 </td>
6a488035
TO
211 </tr>
212
a7aa881c 213 {/foreach}
6a488035 214 {if isset($form.auto_renew) }
a7aa881c 215 <tr id="allow_auto_renew">
6a488035
TO
216 <td style="width: auto;">{$form.auto_renew.html}</td>
217 <td style="width: auto;">
a7aa881c 218 {$form.auto_renew.label}
6a488035 219 </td>
a7aa881c
MWMC
220 </tr>
221 {/if}
222 {if $showRadio}
223 {if $showRadioNoThanks } {* Provide no-thanks option when Membership signup is not required - per membership block configuration. *}
224 <tr class="odd-row">
225 <td>{$form.selectMembership.no_thanks.html}</td>
226 <td colspan="2"><strong>{ts}No thank you{/ts}</strong></td>
6a488035
TO
227 </tr>
228 {/if}
a7aa881c
MWMC
229 {/if}
230 </table>
231 {/strip}
6a488035
TO
232{/if}
233{* Include JS for auto renew membership if priceset is Quick Config*}
dfa81da9 234{if $membershipBlock}
6a488035 235{literal}
a7aa881c
MWMC
236 <script type="text/javascript">
237 CRM.$(function($) {
238 showHideAutoRenew( null );
239 });
240 function showHideAutoRenew( memTypeId )
241 {
242 var priceSetName = "price_"+{/literal}'{$membershipFieldID}'{literal};
243 var considerUserInput = {/literal}'{$takeUserSubmittedAutoRenew}'{literal};
244 if ( memTypeId ) considerUserInput = false;
245 if ( !memTypeId ) memTypeId = cj('input:radio[name='+priceSetName+']:checked').attr('membership-type');
6a488035 246
a7aa881c
MWMC
247 //does this page has only one membership type.
248 var singleMembership = {/literal}'{$singleMembership}'{literal};
249 if ( !memTypeId && singleMembership ) memTypeId = cj("input:radio[name="+priceSetName+"]").attr('membership-type');
250 var renewOptions = {/literal}{$autoRenewMembershipTypeOptions}{literal};
251 var currentOption = eval( "renewOptions." + 'autoRenewMembershipType_' + memTypeId );
252 var autoRenew = cj('#auto_renew_section');
253 var autoRenewC = cj('input[name="auto_renew"]');
254 var forceRenew = cj("#force_renew");
6a488035 255
a7aa881c
MWMC
256 var readOnly = false;
257 var isChecked = false;
258 if ( currentOption == 0 ) {
259 isChecked = false;
260 forceRenew.hide();
261 autoRenew.hide();
262 }
263 if ( currentOption == 1 ) {
264 forceRenew.hide();
265 autoRenew.show();
6a488035 266
a7aa881c
MWMC
267 //uncomment me, if we'd like
268 //to load auto_renew checked.
269 //isChecked = true;
270 } else if ( currentOption == 2 || currentOption == 4) {
271 autoRenew.hide();
272 forceRenew.show();
273 isChecked = readOnly = true;
274 }
6a488035 275
ae4058fe
RR
276 // quidam Wed Feb 12 17:48:40 EST 2020
277 isChecked = true;
278
a7aa881c 279 if ( considerUserInput ) isChecked = autoRenew.prop('checked' );
6a488035 280
a7aa881c
MWMC
281 //its a normal recur contribution.
282 if ( cj( "is_recur" ) &&
283 ( cj( 'input:radio[name="is_recur"]:checked').val() == 1 ) ) {
284 isChecked = false;
285 autoRenew.hide();
286 forceRenew.hide();
287 }
6a488035 288
a7aa881c
MWMC
289 autoRenewC.attr( 'readonly', readOnly );
290 autoRenewC.prop('checked', isChecked );
291 }
6a488035 292
a7aa881c
MWMC
293 {/literal}{if $allowAutoRenewMembership}{literal}
294 CRM.$(function($) {
295 //keep read only always checked.
296 cj( "#auto_renew" ).click(function( ) {
6a488035 297 if ( cj(this).attr( 'readonly' ) ) {
a7aa881c 298 cj(this).prop('checked', true );
6a488035 299 }
a7aa881c
MWMC
300 });
301 });
302 {/literal}{/if}{literal}
303 </script>
6a488035
TO
304{/literal}
305{/if}