Passed
Pull Request — master (#375)
by Brian
82:58
created

render_email_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
    exit; // Exit if accessed directly
5
}
6
7
class WPInv_Payment_Form_Elements {
8
9
    /**
10
     * @param array payment form elements
11
     */
12
    protected $elements;
13
14
    public function __construct() {
15
16
        foreach( $this->get_elements() as $element ) {
17
            $element = $element['type'];
18
19
            if ( method_exists( $this, "render_{$element}_template" ) ) {
20
                add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 );
21
            }
22
23
            if ( method_exists( $this, "edit_{$element}_template" ) ) {
24
                add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 );
25
            }
26
27
28
        }
29
        
30
    }
31
32
    /**
33
     * Returns all the elements that can be added to a form.
34
     */
35
    public function get_elements() {
36
37
        if ( ! empty( $this->elements ) ) {
38
            return $this->elements;
39
        }
40
41
        $this->elements = wpinv_get_data( 'payment-form-elements' );
42
43
        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
44
        return $this->elements;
45
    }
46
47
    /**
48
     * Returns the restrict markup.
49
     */
50
    public function get_restrict_markup( $field, $field_type ) {
51
        $restrict = "$field.type=='$field_type'";
52
        return "v-if=\"$restrict\"";
53
    }
54
55
    /**
56
     * Renders the title element template.
57
     */
58
    public function render_heading_template( $field ) {
59
        $restrict = $this->get_restrict_markup( $field, 'heading' );
60
        echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
61
    }
62
63
    /**
64
     * Renders the edit title element template.
65
     */
66
    public function edit_heading_template( $field ) {
67
        $restrict = $this->get_restrict_markup( $field, 'heading' );
68
        $label    = __( 'Heading', 'invoicing' );
69
        $label2   = __( 'Select Heading Level', 'invoicing' );
70
        $id       = $field . '.id + "_edit"';
71
        $id2      = $field . '.id + "_edit2"';
72
73
        echo "
74
            <div $restrict>
75
                <div class='form-group'>
76
                    <label :for='$id'>$label</label>
77
                    <input class='form-control' :id='$id' v-model='$field.text' type='text' />
78
                </div>
79
80
                <div class='form-group'>
81
                    <label :for='$id2'>$label2</label>
82
83
                    <select class='form-control custom-select' :id='$id2' v-model='$field.level'>
84
                        <option value='h1'>H1</option>
85
                        <option value='h2'>H2</option>
86
                        <option value='h3'>H3</option>
87
                        <option value='h4'>H4</option>
88
                        <option value='h5'>H5</option>
89
                        <option value='h6'>H6</option>
90
                        <option value='h7'>H7</option>
91
                    </select>
92
                </div>
93
            </div>
94
        ";
95
96
    }
97
98
    /**
99
     * Renders a paragraph element template.
100
     */
101
    public function render_paragraph_template( $field ) {
102
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
103
        $label    = "$field.text";
104
        echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
105
    }
106
107
    /**
108
     * Renders the edit paragraph element template.
109
     */
110
    public function edit_paragraph_template( $field ) {
111
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
112
        $label    = __( 'Enter your text', 'invoicing' );
113
        $id       = $field . '.id + "_edit"';
114
        echo "
115
            <div $restrict>
116
                <div class='form-group'>
117
                    <label :for='$id'>$label</label>
118
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
119
                </div>
120
            </div>
121
        ";
122
123
    }
124
125
    /**
126
     * Renders the text element template.
127
     */
128
    public function render_text_template( $field ) {
129
        $restrict = $this->get_restrict_markup( $field, 'text' );
130
        $label    = "$field.label";
131
        echo "
132
            <div $restrict class='wpinv-payment-form-field-preview'>
133
                <div class='wpinv-payment-form-field-preview-overlay'></div>
134
                <label :for='$field.id'>{{" . $label . "}}</label>
135
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'>
136
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
137
            </div>    
138
        ";
139
    }
140
141
    /**
142
     * Renders the price select element template.
143
     */
144
    public function render_price_select_template( $field ) {
145
        $restrict = $this->get_restrict_markup( $field, 'price_select' );
146
        ?>
147
            <div <?php echo $restrict; ?> class='wpinv-payment-form-field-preview'>
148
                <div class='wpinv-payment-form-field-preview-overlay'></div>
149
150
                <label>{{<?php echo $field; ?>.label}}</label>
151
152
                <!-- Buttons -->
153
                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="buttons"' class="getpaid-price-buttons">
154
                    <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
155
                        <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" />
156
                        <label :for="<?php echo esc_attr( $field ); ?>.id + index" class="rounded">{{option | optionize}}</label>
157
                    </span>
158
                </div>
159
160
                <!-- Circles -->
161
                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="circles"' class="getpaid-price-buttons getpaid-price-circles">
162
                    <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
163
                        <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" />
164
                        <label :for="<?php echo esc_attr( $field ); ?>.id + index"><span>{{option | optionize}}</span></label>
165
                    </span>
166
                </div>
167
168
                <!-- Radios -->
169
                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="radios"'>
170
                    <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
171
                        <label>
172
                            <input type="radio" :checked="index==0" />
173
                            <span>{{option | optionize}}</span>
174
                        </label>
175
                    </div>
176
                </div>
177
178
                <!-- Checkboxes -->
179
                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="checkboxes"'>
180
                    <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
181
                        <label>
182
                            <input type="checkbox" :checked="index==0" />
183
                            <span>{{option | optionize}}</span>
184
                        </label>
185
                    </div>
186
                </div>
187
188
                <!-- Select -->
189
                <select v-if='<?php echo esc_attr( $field ); ?>.select_type=="select"' class='form-control custom-select'>
190
                    <option v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
191
                        {{option | optionize}}
192
                    </option>
193
                </select>
194
                <small v-if='<?php echo esc_attr( $field ); ?>.description' class='form-text text-muted' v-html='<?php echo esc_attr( $field ); ?>.description'></small>
195
            </div>
196
197
        <?php
198
    }
199
200
    /**
201
     * Renders the edit price input element template.
202
     */
203
    public function edit_price_input_template( $field ) {
204
        $restrict = $this->get_restrict_markup( $field, 'price_input' );
205
        $label    = __( 'Field Label', 'invoicing' );
206
        $id       = $field . '.id + "_edit"';
207
        $label2   = __( 'Placeholder text', 'invoicing' );
208
        $id2      = $field . '.id + "_edit2"';
209
        $label3   = __( 'Help text', 'invoicing' );
210
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
211
        $id3      = $field . '.id + "_edit3"';
212
        $label5   = __( 'The amount that users add to this field will be added to the total amount', 'invoicing' );
213
        $label6   = __( 'Default Amount', 'invoicing' );
214
        $id6      = $field . '.id + "_edit5"';
215
        echo "
216
            <div $restrict>
217
                <small class='form-text text-muted mb-2'>$label5</small>
218
                <div class='form-group'>
219
                    <label :for='$id'>$label</label>
220
                    <input :id='$id' v-model='$field.label' class='form-control' />
221
                </div>
222
                <div class='form-group'>
223
                    <label :for='$id6'>$label6</label>
224
                    <input :id='$id6' v-model='$field.value' class='form-control' />
225
                </div>
226
                <div class='form-group'>
227
                    <label :for='$id2'>$label2</label>
228
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
229
                </div>
230
                <div class='form-group'>
231
                    <label :for='$id3'>$label3</label>
232
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
233
                </div>
234
            </div>
235
        ";
236
    }
237
238
    /**
239
     * Renders the edit text element template.
240
     */
241
    public function edit_text_template( $field ) {
242
        $restrict = $this->get_restrict_markup( $field, 'text' );
243
        $label    = __( 'Field Label', 'invoicing' );
244
        $id       = $field . '.id + "_edit"';
245
        $label2   = __( 'Placeholder text', 'invoicing' );
246
        $id2      = $field . '.id + "_edit2"';
247
        $label3   = __( 'Help text', 'invoicing' );
248
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
249
        $id3      = $field . '.id + "_edit3"';
250
        $label5   = __( 'Is this field required?', 'invoicing' );
251
        $id4      = $field . '.id + "_edit4"';
252
        echo "
253
            <div $restrict>
254
                <div class='form-group'>
255
                    <label :for='$id'>$label</label>
256
                    <input :id='$id' v-model='$field.label' class='form-control' />
257
                </div>
258
                <div class='form-group'>
259
                    <label :for='$id2'>$label2</label>
260
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
261
                </div>
262
                <div class='form-group'>
263
                    <label :for='$id3'>$label3</label>
264
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
265
                </div>
266
                <div class='form-group form-check'>
267
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
268
                    <label class='form-check-label' :for='$id4'>$label5</label>
269
                </div>
270
            </div>
271
        ";
272
273
    }
274
275
    /**
276
     * Renders the textarea element template.
277
     */
278
    public function render_textarea_template( $field ) {
279
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
280
        $label    = "$field.label";
281
        echo "
282
            <div $restrict class='wpinv-payment-form-field-preview'>
283
                <div class='wpinv-payment-form-field-preview-overlay'></div>
284
                <label :for='$field.id'>{{" . $label . "}}</label>
285
                <textarea  :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea>
286
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
287
            </div>    
288
        ";
289
    }
290
291
    /**
292
     * Renders the edit textarea element template.
293
     */
294
    public function edit_textarea_template( $field ) {
295
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
296
        $label    = __( 'Field Label', 'invoicing' );
297
        $id       = $field . '.id + "_edit"';
298
        $label2   = __( 'Placeholder text', 'invoicing' );
299
        $id2      = $field . '.id + "_edit2"';
300
        $label3   = __( 'Help text', 'invoicing' );
301
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
302
        $id3      = $field . '.id + "_edit3"';
303
        $label5   = __( 'Is this field required?', 'invoicing' );
304
        $id4      = $field . '.id + "_edit4"';
305
        echo "
306
            <div $restrict>
307
                <div class='form-group'>
308
                    <label :for='$id'>$label</label>
309
                    <input :id='$id' v-model='$field.label' class='form-control' />
310
                </div>
311
                <div class='form-group'>
312
                    <label :for='$id2'>$label2</label>
313
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
314
                </div>
315
                <div class='form-group'>
316
                    <label :for='$id3'>$label3</label>
317
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
318
                </div>
319
                <div class='form-group form-check'>
320
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
321
                    <label class='form-check-label' :for='$id4'>$label5</label>
322
                </div>
323
            </div>
324
        ";
325
326
    }
327
328
    /**
329
     * Renders the select element template.
330
     */
331
    public function render_select_template( $field ) {
332
        $restrict    = $this->get_restrict_markup( $field, 'select' );
333
        $label       = "$field.label";
334
        $placeholder = "$field.placeholder";
335
        $id          = $field . '.id';
336
        echo "
337
            <div $restrict class='wpinv-payment-form-field-preview'>
338
                <div class='wpinv-payment-form-field-preview-overlay'></div>
339
                <label :for='$id'>{{" . $label . "}}</label>
340
                <select id='$id' class='form-control custom-select'  v-model='$field.value'>
341
                    <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option>
342
                    <option v-for='option in $field.options' value='option'>{{option}}</option>
343
                </select>
344
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
345
            </div>
346
        ";
347
    }
348
349
    /**
350
     * Renders the edit select element template.
351
     */
352
    public function edit_select_template( $field ) {
353
        $restrict = $this->get_restrict_markup( $field, 'select' );
354
        $label    = __( 'Field Label', 'invoicing' );
355
        $id       = $field . '.id + "_edit"';
356
        $label2   = __( 'Placeholder text', 'invoicing' );
357
        $id2      = $field . '.id + "_edit2"';
358
        $label3   = __( 'Help text', 'invoicing' );
359
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
360
        $id3      = $field . '.id + "_edit3"';
361
        $label5   = __( 'Is this field required?', 'invoicing' );
362
        $id4      = $field . '.id + "_edit4"';
363
        $label6   = __( 'Available Options', 'invoicing' );
364
        echo "
365
            <div $restrict>
366
                <div class='form-group'>
367
                    <label :for='$id'>$label</label>
368
                    <input :id='$id' v-model='$field.label' class='form-control' />
369
                </div>
370
                <div class='form-group'>
371
                    <label :for='$id2'>$label2</label>
372
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
373
                </div>
374
                <div class='form-group'>
375
                    <label :for='$id3'>$label3</label>
376
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
377
                </div>
378
                <div class='form-group form-check'>
379
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
380
                    <label class='form-check-label' :for='$id4'>$label5</label>
381
                </div>
382
                <hr class='featurette-divider mt-4'>
383
                <h5>$label6</h5>
384
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
385
                    <input type='text' class='form-control' v-model='$field.options[index]'>
386
                    <div class='input-group-append'>
387
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
388
                    </div>
389
                </div>
390
                <div class='form-group'>
391
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
392
                </div>
393
            </div>
394
        ";
395
396
    }
397
398
    /**
399
     * Renders the checkbox element template.
400
     */
401
    public function render_checkbox_template( $field ) {
402
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
403
        echo "
404
            <div class='form-check' $restrict>
405
                <div class='wpinv-payment-form-field-preview-overlay'></div>
406
                <input  :id='$field.id' class='form-check-input' type='checkbox' />
407
                <label class='form-check-label' :for='$field.id' v-html='$field.label'></label>
408
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
409
            </div>    
410
        ";
411
    }
412
413
    /**
414
     * Renders the edit checkbox element template.
415
     */
416
    public function edit_checkbox_template( $field ) {
417
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
418
        $label    = __( 'Field Label', 'invoicing' );
419
        $id       = $field . '.id + "_edit"';
420
        $label2   = __( 'Help text', 'invoicing' );
421
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
422
        $id2      = $field . '.id + "_edit2"';
423
        $label4   = __( 'Is this field required?', 'invoicing' );
424
        $id3      = $field . '.id + "_edit3"';
425
        echo "
426
            <div $restrict>
427
                <div class='form-group'>
428
                    <label :for='$id'>$label</label>
429
                    <input :id='$id' v-model='$field.label' class='form-control' />
430
                </div>
431
                <div class='form-group'>
432
                    <label :for='$id2'>$label2</label>
433
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
434
                </div>
435
                <div class='form-group form-check'>
436
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
437
                    <label class='form-check-label' :for='$id3'>$label4</label>
438
                </div>
439
            </div>
440
        ";
441
442
    }
443
444
    /**
445
     * Renders the radio element template.
446
     */
447
    public function render_radio_template( $field ) {
448
        $restrict    = $this->get_restrict_markup( $field, 'radio' );
449
        $label       = "$field.label";
450
        $id          = $field . '.id';
451
        echo "
452
            <div $restrict class='wpinv-payment-form-field-preview'>
453
                <div class='wpinv-payment-form-field-preview-overlay'></div>
454
                <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend>
455
                <div class='form-check' v-for='(option, index) in $field.options'>
456
                    <input class='form-check-input' type='radio' :id='$id + index'>
457
                    <label class='form-check-label' :for='$id + index'>{{option}}</label>
458
                </div>
459
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
460
            </div>
461
        ";
462
    }
463
464
    /**
465
     * Renders the edit radio element template.
466
     */
467
    public function edit_radio_template( $field ) {
468
        $restrict = $this->get_restrict_markup( $field, 'radio' );
469
        $label    = __( 'Field Label', 'invoicing' );
470
        $id       = $field . '.id + "_edit"';
471
        $label2   = __( 'Help text', 'invoicing' );
472
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
473
        $id2      = $field . '.id + "_edit3"';
474
        $label4   = __( 'Is this field required?', 'invoicing' );
475
        $id3      = $field . '.id + "_edit4"';
476
        $label5   = __( 'Available Options', 'invoicing' );
477
        echo "
478
            <div $restrict>
479
                <div class='form-group'>
480
                    <label :for='$id'>$label</label>
481
                    <input :id='$id' v-model='$field.label' class='form-control' />
482
                </div>
483
                <div class='form-group'>
484
                    <label :for='$id2'>$label2</label>
485
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
486
                </div>
487
                <div class='form-group form-check'>
488
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
489
                    <label class='form-check-label' :for='$id3'>$label4</label>
490
                </div>
491
                <hr class='featurette-divider mt-4'>
492
                <h5>$label5</h5>
493
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
494
                    <input type='text' class='form-control' v-model='$field.options[index]'>
495
                    <div class='input-group-append'>
496
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
497
                    </div>
498
                </div>
499
                <div class='form-group'>
500
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
501
                </div>
502
            </div>
503
        ";
504
505
    }
506
507
    /**
508
     * Renders the address element template.
509
     */
510
    public function render_address_template( $field ) {
511
        $restrict    = $this->get_restrict_markup( $field, 'address' );
512
513
        echo "
514
            <div class='wpinv-address-wrapper' $restrict>
515
                <draggable v-model='$field.fields' group='address_fields_preview'>
516
                    <div class='form-group address-field-preview wpinv-payment-form-field-preview' v-for='(field, index) in $field.fields' :key='field.name' v-show='field.visible'>
517
                        <div class='wpinv-payment-form-field-preview-overlay'></div>
518
                        <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label>
519
                        <input v-if='field.name !== \"wpinv_country\" && field.name !== \"wpinv_state\"' class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'>
520
                        <select v-else class='form-control' :id='field.name'>
521
                            <option v-if='field.placeholder'>{{field.placeholder}}</option>
522
                        </select>
523
                        <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small>
524
                    </div>
525
                </draggable>
526
            </div>
527
        ";
528
    }
529
530
    /**
531
     * Renders the edit address element template.
532
     */
533
    public function edit_address_template( $field ) {
534
        $restrict  = $this->get_restrict_markup( $field, 'address' );
535
        $label     = __( 'Field Label', 'invoicing' );
536
        $label2    = __( 'Placeholder', 'invoicing' );
537
        $label3    = __( 'Description', 'invoicing' );
538
        $label4    = __( 'Is required', 'invoicing' );
539
        $label5    = __( 'Is visible', 'invoicing' );
540
        $id        = $field . '.id + "_edit_label"';
541
        $id2       = $field . '.id + "_edit_placeholder"';
542
        $id3       = $field . '.id + "_edit_description"';
543
        $id4       = $field . '.id + "_edit_required"';
544
        $id5       = $field . '.id + "_edit_visible"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id5 is dead and can be removed.
Loading history...
545
        $id5       = $field . '.id + "_edit_visible"';
546
        $id_main   = $field . '.id';
547
548
        echo "
549
            <div $restrict :id='$id_main'>
550
                <draggable v-model='$field.fields' group='address_fields'>
551
                    <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'>
552
553
                        <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'>
554
                            <span class='label'>{{field.label}}</span>
555
                            <span class='toggle-visibility-icon' @click.stop='field.visible = !field.visible;'>
556
                                <span class='dashicons dashicons-hidden'></span>
557
                                <span class='dashicons dashicons-visibility'></span>
558
                            </span>
559
                            <span class='toggle-icon'>
560
                                <span class='dashicons dashicons-arrow-down'></span>
561
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
562
                            </span>
563
                        </div>
564
565
                        <div class='wpinv-form-address-field-editor-editor-body'>
566
                            <div class='p-2'>
567
568
                                <div class='form-group'>
569
                                    <label :for='$id + index'>$label</label>
570
                                    <input :id='$id + index' v-model='field.label' class='form-control' />
571
                                </div>
572
573
                                <div class='form-group'>
574
                                    <label :for='$id2 + index'>$label2</label>
575
                                    <input :id='$id2 + index' v-model='field.placeholder' class='form-control' />
576
                                </div>
577
578
                                <div class='form-group'>
579
                                    <label :for='$id3 + index'>$label3</label>
580
                                    <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea>
581
                                </div>
582
583
                                <div class='form-group form-check'>
584
                                    <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' />
585
                                    <label class='form-check-label' :for='$id4 + index'>$label4</label>
586
                                </div>
587
588
                                <div class='form-group form-check'>
589
                                    <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' />
590
                                    <label class='form-check-label' :for='$id5 + index'>$label5</label>
591
                                </div>
592
593
                            </div>
594
                        </div>
595
596
                    </div>
597
                </draggable>
598
599
            </div>
600
        ";
601
602
    }
603
604
    /**
605
     * Renders the email element template.
606
     */
607
    public function render_email_template( $field ) {
608
        $restrict = $this->get_restrict_markup( $field, 'email' );
609
        $label    = "$field.label";
610
        echo "
611
            <div $restrict class='wpinv-payment-form-field-preview'>
612
                <div class='wpinv-payment-form-field-preview-overlay'></div>
613
                <label :for='$field.id'>{{" . $label . "}}</label>
614
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
615
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
616
            </div>    
617
        ";
618
    }
619
620
    /**
621
     * Renders the billing_email element template.
622
     */
623
    public function render_billing_email_template( $field ) {
624
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
625
        $label    = "$field.label";
626
        echo "
627
            <div $restrict>
628
                <label :for='$field.id'>{{" . $label . "}}</label>
629
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
630
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
631
            </div>    
632
        ";
633
    }
634
635
    /**
636
     * Renders the edit email element template.
637
     */
638
    public function edit_email_template( $field ) {
639
        $restrict = $this->get_restrict_markup( $field, 'email' );
640
        $label    = __( 'Field Label', 'invoicing' );
641
        $id       = $field . '.id + "_edit"';
642
        $label2   = __( 'Placeholder text', 'invoicing' );
643
        $id2      = $field . '.id + "_edit2"';
644
        $label3   = __( 'Help text', 'invoicing' );
645
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
646
        $id3      = $field . '.id + "_edit3"';
647
        $label5   = __( 'Is this field required?', 'invoicing' );
648
        $id4      = $field . '.id + "_edit4"';
649
        echo "
650
            <div $restrict>
651
                <div class='form-group'>
652
                    <label :for='$id'>$label</label>
653
                    <input :id='$id' v-model='$field.label' class='form-control' />
654
                </div>
655
                <div class='form-group'>
656
                    <label :for='$id2'>$label2</label>
657
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
658
                </div>
659
                <div class='form-group'>
660
                    <label :for='$id3'>$label3</label>
661
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
662
                </div>
663
                <div class='form-group form-check'>
664
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
665
                    <label class='form-check-label' :for='$id4'>$label5</label>
666
                </div>
667
            </div>
668
        ";
669
670
    }
671
672
    /**
673
     * Renders the edit billing_email element template.
674
     */
675
    public function edit_billing_email_template( $field ) {
676
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
677
        $label    = __( 'Field Label', 'invoicing' );
678
        $id       = $field . '.id + "_edit"';
679
        $label2   = __( 'Placeholder text', 'invoicing' );
680
        $id2      = $field . '.id + "_edit2"';
681
        $label3   = __( 'Help text', 'invoicing' );
682
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
683
        $id3      = $field . '.id + "_edit3"';
684
        $label5   = __( 'Is this field required?', 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The assignment to $label5 is dead and can be removed.
Loading history...
685
        $id4      = $field . '.id + "_edit4"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id4 is dead and can be removed.
Loading history...
686
        echo "
687
            <div $restrict>
688
                <div class='form-group'>
689
                    <label :for='$id'>$label</label>
690
                    <input :id='$id' v-model='$field.label' class='form-control' />
691
                </div>
692
                <div class='form-group'>
693
                    <label :for='$id2'>$label2</label>
694
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
695
                </div>
696
                <div class='form-group'>
697
                    <label :for='$id3'>$label3</label>
698
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
699
                </div>
700
            </div>
701
        ";
702
703
    }
704
705
    /**
706
     * Renders the website element template.
707
     */
708
    public function render_website_template( $field ) {
709
        $restrict = $this->get_restrict_markup( $field, 'website' );
710
        $label    = "$field.label";
711
        echo "
712
            <div $restrict class='wpinv-payment-form-field-preview'>
713
                <div class='wpinv-payment-form-field-preview-overlay'></div>
714
                <label :for='$field.id'>{{" . $label . "}}</label>
715
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'>
716
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
717
            </div>    
718
        ";
719
    }
720
721
    /**
722
     * Renders the edit website element template.
723
     */
724
    public function edit_website_template( $field ) {
725
        $restrict = $this->get_restrict_markup( $field, 'website' );
726
        $label    = __( 'Field Label', 'invoicing' );
727
        $id       = $field . '.id + "_edit"';
728
        $label2   = __( 'Placeholder text', 'invoicing' );
729
        $id2      = $field . '.id + "_edit2"';
730
        $label3   = __( 'Help text', 'invoicing' );
731
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
732
        $id3      = $field . '.id + "_edit3"';
733
        $label5   = __( 'Is this field required?', 'invoicing' );
734
        $id4      = $field . '.id + "_edit4"';
735
        echo "
736
            <div $restrict>
737
                <div class='form-group'>
738
                    <label :for='$id'>$label</label>
739
                    <input :id='$id' v-model='$field.label' class='form-control' />
740
                </div>
741
                <div class='form-group'>
742
                    <label :for='$id2'>$label2</label>
743
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
744
                </div>
745
                <div class='form-group'>
746
                    <label :for='$id3'>$label3</label>
747
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
748
                </div>
749
                <div class='form-group form-check'>
750
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
751
                    <label class='form-check-label' :for='$id4'>$label5</label>
752
                </div>
753
            </div>
754
        ";
755
756
    }
757
758
    /**
759
     * Renders the date element template.
760
     */
761
    public function render_date_template( $field ) {
762
        $restrict = $this->get_restrict_markup( $field, 'date' );
763
        $label    = "$field.label";
764
        echo "
765
            <div $restrict class='wpinv-payment-form-field-preview'>
766
                <div class='wpinv-payment-form-field-preview-overlay'></div>
767
                <label :for='$field.id'>{{" . $label . "}}</label>
768
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'>
769
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
770
            </div>    
771
        ";
772
    }
773
774
    /**
775
     * Renders the edit date element template.
776
     */
777
    public function edit_date_template( $field ) {
778
        $restrict = $this->get_restrict_markup( $field, 'date' );
779
        $label    = __( 'Field Label', 'invoicing' );
780
        $id       = $field . '.id + "_edit"';
781
        $label3   = __( 'Help text', 'invoicing' );
782
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
783
        $id3      = $field . '.id + "_edit3"';
784
        $label5   = __( 'Is this field required?', 'invoicing' );
785
        $id4      = $field . '.id + "_edit4"';
786
        echo "
787
            <div $restrict>
788
                <div class='form-group'>
789
                    <label :for='$id'>$label</label>
790
                    <input :id='$id' v-model='$field.label' class='form-control' />
791
                </div>
792
                <div class='form-group'>
793
                    <label :for='$id3'>$label3</label>
794
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
795
                </div>
796
                <div class='form-group form-check'>
797
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
798
                    <label class='form-check-label' :for='$id4'>$label5</label>
799
                </div>
800
            </div>
801
        ";
802
803
    }
804
805
    /**
806
     * Renders the time element template.
807
     */
808
    public function render_time_template( $field ) {
809
        $restrict = $this->get_restrict_markup( $field, 'time' );
810
        $label    = "$field.label";
811
        echo "
812
            <div $restrict class='wpinv-payment-form-field-preview'>
813
                <div class='wpinv-payment-form-field-preview-overlay'></div>
814
                <label :for='$field.id'>{{" . $label . "}}</label>
815
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'>
816
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
817
            </div>    
818
        ";
819
    }
820
821
    /**
822
     * Renders the edit time element template.
823
     */
824
    public function edit_time_template( $field ) {
825
        $restrict = $this->get_restrict_markup( $field, 'time' );
826
        $label    = __( 'Field Label', 'invoicing' );
827
        $id       = $field . '.id + "_edit"';
828
        $label3   = __( 'Help text', 'invoicing' );
829
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
830
        $id3      = $field . '.id + "_edit3"';
831
        $label5   = __( 'Is this field required?', 'invoicing' );
832
        $id4      = $field . '.id + "_edit4"';
833
        echo "
834
            <div $restrict>
835
                <div class='form-group'>
836
                    <label :for='$id'>$label</label>
837
                    <input :id='$id' v-model='$field.label' class='form-control' />
838
                </div>
839
                <div class='form-group'>
840
                    <label :for='$id3'>$label3</label>
841
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
842
                </div>
843
                <div class='form-group form-check'>
844
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
845
                    <label class='form-check-label' :for='$id4'>$label5</label>
846
                </div>
847
            </div>
848
        ";
849
850
    }
851
852
    /**
853
     * Renders the number element template.
854
     */
855
    public function render_number_template( $field ) {
856
        $restrict = $this->get_restrict_markup( $field, 'number' );
857
        $label    = "$field.label";
858
        echo "
859
            <div $restrict class='wpinv-payment-form-field-preview'>
860
                <div class='wpinv-payment-form-field-preview-overlay'></div>
861
                <label :for='$field.id'>{{" . $label . "}}</label>
862
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'>
863
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
864
            </div>    
865
        ";
866
    }
867
868
    /**
869
     * Renders the edit number element template.
870
     */
871
    public function edit_number_template( $field ) {
872
        $restrict = $this->get_restrict_markup( $field, 'number' );
873
        $label    = __( 'Field Label', 'invoicing' );
874
        $id       = $field . '.id + "_edit"';
875
        $label2   = __( 'Placeholder text', 'invoicing' );
876
        $id2      = $field . '.id + "_edit2"';
877
        $label3   = __( 'Help text', 'invoicing' );
878
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
879
        $id3      = $field . '.id + "_edit3"';
880
        $label5   = __( 'Is this field required?', 'invoicing' );
881
        $id4      = $field . '.id + "_edit4"';
882
        echo "
883
            <div $restrict>
884
                <div class='form-group'>
885
                    <label :for='$id'>$label</label>
886
                    <input :id='$id' v-model='$field.label' class='form-control' />
887
                </div>
888
                <div class='form-group'>
889
                    <label :for='$id2'>$label2</label>
890
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
891
                </div>
892
                <div class='form-group'>
893
                    <label :for='$id3'>$label3</label>
894
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
895
                </div>
896
                <div class='form-group form-check'>
897
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
898
                    <label class='form-check-label' :for='$id4'>$label5</label>
899
                </div>
900
            </div>
901
        ";
902
903
    }
904
905
    /**
906
     * Renders the separator element template.
907
     */
908
    public function render_separator_template( $field ) {
909
        $restrict = $this->get_restrict_markup( $field, 'separator' );
910
        echo "<hr class='featurette-divider' $restrict>";
911
    }
912
913
    /**
914
     * Renders the pay button element template.
915
     */
916
    public function render_pay_button_template( $field ) {
917
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
918
        $label    = "$field.label";
919
        echo "
920
            <div $restrict>
921
                <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button>
922
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
923
            </div>    
924
        ";
925
    }
926
927
    /**
928
     * Renders the pay button element template.
929
     */
930
    public function edit_pay_button_template( $field ) {
931
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
932
        $label    = __( 'Button Text', 'invoicing' );
933
        $id       = $field . '.id + "_edit"';
934
        $label2   = __( 'Help text', 'invoicing' );
935
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
936
        $id2      = $field . '.id + "_edit2"';
937
        $label4   = esc_attr__( 'Button Type', 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The assignment to $label4 is dead and can be removed.
Loading history...
938
        $id3      = $field . '.id + "_edit3"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id3 is dead and can be removed.
Loading history...
939
        $label4   = esc_attr__( 'Select Gateway Text', 'invoicing' );
940
        $id3      = $field . '.id + "_edit4"';
941
942
        echo "
943
            <div $restrict>
944
                <div class='form-group'>
945
                    <label :for='$id'>$label</label>
946
                    <input :id='$id' v-model='$field.label' class='form-control' />
947
                </div>
948
                <div class='form-group'>
949
                    <label :for='$id3'>$label4</label>
950
                    <input :id='$id3' v-model='$field.gateway_select' class='form-control' />
951
                </div>
952
                <div class='form-group'>
953
                    <label :for='$id2'>$label2</label>
954
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
955
                </div>
956
                <div class='form-group'>
957
                    <label :for='$id3'>$label4</label>
958
959
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
960
                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
961
                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
962
                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
963
                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
964
                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
965
                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
966
                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
967
                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
968
                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
969
                    </select>
970
                </div>
971
            </div>
972
        ";
973
974
    }
975
976
    /**
977
     * Renders the alert element template.
978
     */
979
    public function render_alert_template( $field ) {
980
        $restrict = $this->get_restrict_markup( $field, 'alert' );
981
        $text     = "$field.text";
982
        echo "
983
            <div $restrict class='alert' :class='$field.class' role='alert'>
984
                <span v-html='$text'></span>
985
                <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''>
986
                    <span aria-hidden='true'>&times;</span>
987
                </button>
988
            </div>    
989
        ";
990
    }
991
992
    /**
993
     * Renders the alert element template.
994
     */
995
    public function edit_alert_template( $field ) {
996
        $restrict = $this->get_restrict_markup( $field, 'alert' );
997
        $label    = __( 'Alert Text', 'invoicing' );
998
        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
999
        $id       = $field . '.id + "_edit"';
1000
        $label3   = __( 'Is Dismissible?', 'invoicing' );
1001
        $id2      = $field . '.id + "_edit2"';
1002
        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1003
        $id3      = $field . '.id + "_edit3"';
1004
        echo "
1005
            <div $restrict>
1006
                <div class='form-group'>
1007
                    <label :for='$id'>$label</label>
1008
                    <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
1009
                </div>
1010
                <div class='form-group form-check'>
1011
                    <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' />
1012
                    <label class='form-check-label' :for='$id2'>$label3</label>
1013
                </div>
1014
                <div class='form-group'>
1015
                    <label :for='$id3'>$label4</label>
1016
1017
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1018
                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1019
                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1020
                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1021
                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1022
                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1023
                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1024
                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1025
                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1026
                    </select>
1027
                </div>
1028
            </div>
1029
        ";
1030
1031
    }
1032
1033
    /**
1034
     * Renders the discount element template.
1035
     */
1036
    public function render_discount_template( $field ) {
1037
        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1038
        ?>
1039
1040
            <div <?php echo $restrict; ?> class="discount_field border rounded p-3 wpinv-payment-form-field-preview">
1041
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1042
                <div class="discount_field_inner d-flex flex-column flex-md-row">
1043
                    <input  :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1044
                    <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button>
1045
                </div>
1046
                <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small>
1047
            </div>
1048
1049
        <?php
1050
    }
1051
1052
    /**
1053
     * Renders the discount element template.
1054
     */
1055
    public function edit_discount_template( $field ) {
1056
        $restrict = $this->get_restrict_markup( $field, 'discount' );
1057
        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1058
        $label2   = __( 'Help Text', 'invoicing' );
1059
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1060
        $label4   = __( 'Button Text', 'invoicing' );
1061
        $id       = $field . '.id + "_edit"';
1062
        $id2      = $field . '.id + "_edit2"';
1063
        $id3      = $field . '.id + "_edit3"';
1064
        echo "
1065
            <div $restrict>
1066
                <div class='form-group'>
1067
                    <label :for='$id'>$label</label>
1068
                    <input :id='$id' v-model='$field.input_label' class='form-control' />
1069
                </div>
1070
1071
                <div class='form-group'>
1072
                    <label :for='$id2'>$label4</label>
1073
                    <input :id='$id2' v-model='$field.button_label' class='form-control' />
1074
                </div>
1075
1076
                <div class='form-group'>
1077
                    <label :for='$id3'>$label2</label>
1078
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1079
                </div>
1080
1081
            </div>
1082
        ";
1083
1084
    }
1085
1086
    /**
1087
     * Renders the items element template.
1088
     */
1089
    public function render_items_template( $field ) {
1090
        $restrict  = $this->get_restrict_markup( $field, 'items' );
1091
        ?>
1092
1093
        <div <?php echo $restrict; ?> class='item_totals text-center'>
1094
            <div v-if='!is_default'>
1095
                <div v-if='! canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='p-4 bg-warning text-light'><?php _e( 'Item totals will appear here. Click to set items.', 'invoicing' ) ?></div>
1096
                <div v-if='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='p-4 bg-danger'><?php _e( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' ); _e( 'To prevent this, limit customers to selecting a single item.', 'invoicing' ); ?></div>
1097
            </div>
1098
                <div v-if='is_default'>
1099
                    <div class='p-4 bg-warning'><?php _e( 'Item totals will appear here.', 'invoicing' ) ?></div>
1100
                </div>
1101
            </div>
1102
1103
        <?php
1104
    }
1105
1106
    /**
1107
     * Renders the items element on the frontend.
1108
     */
1109
    public function frontend_render_items_template( $field, $items ) {
1110
        $tax       = 0;
1111
        $sub_total = 0;
1112
        $total     = 0;
1113
1114
        ?>
1115
1116
        <?php
1117
        echo "<div class='form-group item_totals'>";
1118
        
1119
        $id = esc_attr( $field['id'] );
1120
1121
        if ( empty( $field[ 'items_type' ] ) ) {
1122
            $field[ 'items_type' ] = 'total';
1123
        }
1124
1125
        if ( 'radio' == $field[ 'items_type' ] ) { ?>
1126
            <div class="item_totals_type_radio">
1127
1128
                <?php
1129
                    foreach( $items as $index => $item ) {
1130
1131
                        if ( ! empty( $item['required'] ) ) {
1132
                            continue;
1133
                        }
1134
                ?>
1135
                    <div  class="form-check">
1136
                        <input class='form-check-input wpinv-items-selector' <?php checked( ! isset( $selected_radio_item ) ); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'>
1137
                        <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?>&nbsp;<strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) ); ?></strong></label>
1138
                    </div>
1139
                    <?php if ( ! empty( $item['description'] )) { ?>
1140
                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1141
                    <?php } ?>
1142
                <?php } ?>
1143
1144
                <div class="mt-3 border item_totals_type_radio_totals">
1145
1146
                    <?php
1147
1148
                        $total     = 0;
1149
                        $tax       = 0;
1150
                        $sub_total = 0;
1151
1152
                        foreach ( $items as $item ) {
1153
1154
                            $class  = 'col-8';
1155
                            $class2 = '';
1156
1157
                            if ( ! empty( $item['allow_quantities'] ) ) {
1158
                                $class = 'col-6 pt-2';
1159
                                $class2 = 'pt-2';
1160
                            }
1161
1162
                            if ( ! empty( $item['custom_price'] ) ) {
1163
                                $class .= ' pt-2';
1164
                            }
1165
1166
                            $class3 = 'd-none';
1167
                            $name   = '';
1168
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) {
1169
1170
                                $amount = floatval( $item['price'] );
1171
1172
                                if ( wpinv_use_taxes() ) {
1173
1174
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1175
1176
                                    if ( wpinv_prices_include_tax() ) {
1177
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1178
                                        $item_tax = $amount - $pre_tax;
1179
                                    } else {
1180
                                        $pre_tax  = $amount;
1181
                                        $item_tax = $amount * $rate * 0.01;
1182
                                    }
1183
1184
                                    $tax       = $tax + $item_tax;
1185
                                    $sub_total = $sub_total + $pre_tax;
1186
                                    $total     = $sub_total + $tax;
1187
1188
                                } else {
1189
                                    $total  = $total + $amount;
1190
                                }
1191
1192
                                $class3 = '';
1193
                                $name   = "wpinv-items[{$item['id']}]";
1194
1195
                                if ( empty( $item['required'] ) ) {
1196
                                    $totals_selected_radio_item = 1;
1197
                                }
1198
1199
                            }
1200
1201
                            $class3 .= " wpinv_item_{$item['id']}";
1202
1203
                    ?>
1204
1205
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
1206
                        <div class='row pl-2 pr-2 pt-2'>
1207
                            <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div>
1208
1209
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1210
1211
                                <div class='col-2'>
1212
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
1213
                                </div>
1214
1215
                            <?php } else { ?>
1216
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1217
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1218
1219
                                <div class='col-4 <?php echo $class2; ?>'>
1220
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1221
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1222
                                </div>
1223
1224
                            <?php } else {?>
1225
1226
                                <div class='col-4'>
1227
                                    <div class='input-group'>
1228
1229
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1230
                                            <div class='input-group-prepend'>
1231
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1232
                                            </div>
1233
                                        <?php } ?>
1234
1235
                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
1236
                                    
1237
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1238
                                            <div class='input-group-append'>
1239
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1240
                                            </div>
1241
                                        <?php } ?>
1242
1243
                                    </div>
1244
                                </div>
1245
                            <?php } ?>
1246
1247
                        </div>
1248
                        <?php if ( ! empty( $item['description'] )) { ?>
1249
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1250
                        <?php } ?>
1251
                    </div>
1252
                <?php } ?>
1253
1254
                <div class='mt-4 border-top item_totals_total p-2'>
1255
1256
                    <div class='row'>
1257
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
1258
                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
1259
                    </div>
1260
1261
                    <div class='row' style='display: none;'>
1262
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
1263
                        <div class='col-4'><strong class='wpinv-items-discount'></strong></div>
1264
                    </div>
1265
1266
                    <?php if ( wpinv_use_taxes() ) { ?>
1267
                        <div class='row'>
1268
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
1269
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
1270
                        </div>
1271
                    <?php } ?>
1272
1273
                    <div class='row'>
1274
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1275
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
1276
                    </div>
1277
                </div>
1278
1279
            </div>
1280
            </div>
1281
        <?php } ?>
1282
1283
        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
1284
1285
            <div class="item_totals_type_checkbox">
1286
1287
                <?php
1288
                    foreach ( $items as $index => $item ) {
1289
1290
                        if ( ! empty( $item['required'] ) ) {
1291
                            continue;
1292
                        }
1293
1294
                        $title = sanitize_text_field(  $item['title'] );
1295
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
1296
                        $item_id    = esc_attr( $id . "_$index" );
1297
                        $value = esc_attr( $item['id'] );
1298
                        $checked = checked( ! isset( $selected_checkbox_item ), true, false );
1299
                        $selected_checkbox_item = 1;
1300
1301
                        echo "
1302
                            <div class='custom-control custom-checkbox'>
1303
                                <input type='checkbox' name='payment-form-items[]' id='$item_id' value='$value' class='wpi-payment-form-items-select-checkbox form-control custom-control-input' $checked>
1304
                                <label for='$item_id' class='custom-control-label'>$title &nbsp; ($price)</label>
1305
                            </div>";
1306
1307
                        if ( ! empty( $item['description'] ) ) {
1308
                            echo "<small class='form-text text-muted'>{$item['description']}</small>";
1309
                        }
1310
                    }
1311
                ?>
1312
1313
                <div class="mt-3 border item_totals_type_checkbox_totals">
1314
1315
                    <?php
1316
1317
                        $total     = 0;
1318
                        $tax       = 0;
1319
                        $sub_total = 0;
1320
1321
                        foreach ( $items as $item ) {
1322
1323
                            $class  = 'col-8';
1324
                            $class2 = '';
1325
1326
                            if ( ! empty( $item['allow_quantities'] ) ) {
1327
                                $class = 'col-6 pt-2';
1328
                                $class2 = 'pt-2';
1329
                            }
1330
1331
                            if ( ! empty( $item['custom_price'] ) ) {
1332
                                $class .= ' pt-2';
1333
                            }
1334
1335
                            $class3 = 'd-none';
1336
                            $name  = '';
1337
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) {
1338
1339
                                $amount = floatval( $item['price'] );
1340
                                if ( wpinv_use_taxes() ) {
1341
1342
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1343
1344
                                    if ( wpinv_prices_include_tax() ) {
1345
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1346
                                        $item_tax = $amount - $pre_tax;
1347
                                    } else {
1348
                                        $pre_tax  = $amount;
1349
                                        $item_tax = $amount * $rate * 0.01;
1350
                                    }
1351
1352
                                    $tax       = $tax + $item_tax;
1353
                                    $sub_total = $sub_total + $pre_tax;
1354
                                    $total     = $sub_total + $tax;
1355
1356
                                } else {
1357
                                    $total  = $total + $amount;
1358
                                }
1359
1360
                                $class3 = '';
1361
                                $name  = "wpinv-items[{$item['id']}]";
1362
1363
                                if ( empty( $item['required'] ) ) {
1364
                                    $totals_selected_checkbox_item = 1;
1365
                                }
1366
1367
                            }
1368
1369
                            $class3 .= " wpinv_item_{$item['id']}";
1370
1371
                    ?>
1372
1373
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
1374
                        <div class='row pl-2 pr-2 pt-2'>
1375
                            <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div>
1376
1377
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1378
1379
                                <div class='col-2'>
1380
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
1381
                                </div>
1382
1383
                            <?php } else { ?>
1384
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1385
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1386
1387
                                <div class='col-4 <?php echo $class2; ?>'>
1388
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1389
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1390
                                </div>
1391
1392
                            <?php } else {?>
1393
1394
                                <div class='col-4'>
1395
                                    <div class='input-group'>
1396
1397
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1398
                                            <div class='input-group-prepend'>
1399
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1400
                                            </div>
1401
                                        <?php } ?>
1402
1403
                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
1404
                                    
1405
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1406
                                            <div class='input-group-append'>
1407
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1408
                                            </div>
1409
                                        <?php } ?>
1410
1411
                                    </div>
1412
                                </div>
1413
                            <?php } ?>
1414
1415
                        </div>
1416
                        <?php if ( ! empty( $item['description'] )) { ?>
1417
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1418
                        <?php } ?>
1419
                    </div>
1420
                <?php } ?>
1421
1422
                <div class='mt-4 border-top item_totals_total p-2'>
1423
1424
                    <div class='row'>
1425
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
1426
                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
1427
                    </div>
1428
1429
                    <div class='row' style='display: none;'>
1430
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
1431
                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div>
1432
                    </div>
1433
1434
                    <?php if ( wpinv_use_taxes() ) { ?>
1435
                        <div class='row'>
1436
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
1437
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
1438
                        </div>
1439
                    <?php } ?>
1440
1441
                    <div class='row'>
1442
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1443
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
1444
                    </div>
1445
                </div>
1446
            </div>
1447
            </div>
1448
        <?php } ?>
1449
1450
        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
1451
1452
            <div class="item_totals_type_select">
1453
1454
                <?php
1455
1456
                    $options  = array();
1457
                    $selected = '';
1458
                    foreach ( $items as $index => $item ) {
1459
1460
                        if ( ! empty( $item['required'] ) ) {
1461
                            continue;
1462
                        }
1463
1464
                        $title = sanitize_text_field(  $item['title'] );
1465
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
1466
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
1467
1468
                        if ( ! isset( $selected_item ) ) {
1469
                            $selected = $item['id'];
1470
                            $selected_item = 1;
1471
                        }
1472
                        
1473
                    }
1474
1475
                    echo aui()->select(
1476
                        array(
1477
                                'name'        => 'payment-form-items',
1478
                                'id'          => $id,
1479
                                'placeholder' => __( 'Select an item', 'invoicing' ),
1480
                                'no_wrap'     => true,
1481
                                'options'     => $options,
1482
                                'class'       => 'wpi_select2 wpinv-items-select-selector',
1483
                                'value'       => $selected,
1484
                        )
1485
                    );
1486
                ?>
1487
1488
                <div class="mt-3 border item_totals_type_select_totals">
1489
1490
                    <?php
1491
1492
                        $total     = 0;
1493
                        $tax       = 0;
1494
                        $sub_total = 0;
1495
1496
                        foreach ( $items as $item ) {
1497
1498
                            $class  = 'col-8';
1499
                            $class2 = '';
1500
1501
                            if ( ! empty( $item['allow_quantities'] ) ) {
1502
                                $class = 'col-6 pt-2';
1503
                                $class2 = 'pt-2';
1504
                            }
1505
1506
                            if ( ! empty( $item['custom_price'] ) ) {
1507
                                $class .= ' pt-2';
1508
                            }
1509
1510
                            $class3 = 'd-none';
1511
                            $name  = '';
1512
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
1513
1514
                                $amount = floatval( $item['price'] );
1515
                                if ( wpinv_use_taxes() ) {
1516
1517
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1518
1519
                                    if ( wpinv_prices_include_tax() ) {
1520
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1521
                                        $item_tax = $amount - $pre_tax;
1522
                                    } else {
1523
                                        $pre_tax  = $amount;
1524
                                        $item_tax = $amount * $rate * 0.01;
1525
                                    }
1526
1527
                                    $tax       = $tax + $item_tax;
1528
                                    $sub_total = $sub_total + $pre_tax;
1529
                                    $total     = $sub_total + $tax;
1530
1531
                                } else {
1532
                                    $total  = $total + $amount;
1533
                                }
1534
1535
                                $class3 = '';
1536
                                $name  = "wpinv-items[{$item['id']}]";
1537
1538
                                if ( empty( $item['required'] ) ) {
1539
                                    $totals_selected_select_item = 1;
1540
                                }
1541
1542
                            }
1543
1544
                            $class3 .= " wpinv_item_{$item['id']}";
1545
1546
                    ?>
1547
1548
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
1549
                        <div class='row pl-2 pr-2 pt-2'>
1550
                            <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div>
1551
1552
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1553
1554
                                <div class='col-2'>
1555
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
1556
                                </div>
1557
1558
                            <?php } else { ?>
1559
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1560
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1561
1562
                                <div class='col-4 <?php echo $class2; ?>'>
1563
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1564
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1565
                                </div>
1566
1567
                            <?php } else {?>
1568
1569
                                <div class='col-4'>
1570
                                    <div class='input-group'>
1571
1572
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1573
                                            <div class='input-group-prepend'>
1574
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1575
                                            </div>
1576
                                        <?php } ?>
1577
1578
                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
1579
                                    
1580
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1581
                                            <div class='input-group-append'>
1582
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1583
                                            </div>
1584
                                        <?php } ?>
1585
1586
                                    </div>
1587
                                </div>
1588
                            <?php } ?>
1589
1590
                        </div>
1591
                        <?php if ( ! empty( $item['description'] )) { ?>
1592
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1593
                        <?php } ?>
1594
                    </div>
1595
                <?php } ?>
1596
1597
                <div class='mt-4 border-top item_totals_total p-2'>
1598
1599
                    <div class='row'>
1600
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
1601
                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
1602
                    </div>
1603
1604
                    <div class='row' style='display: none;'>
1605
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
1606
                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div>
1607
                    </div>
1608
1609
                    <?php if ( wpinv_use_taxes() ) { ?>
1610
                        <div class='row'>
1611
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
1612
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
1613
                        </div>
1614
                    <?php } ?>
1615
                    <div class='row'>
1616
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1617
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
1618
                    </div>
1619
                </div>
1620
1621
            </div>
1622
        <?php } ?>
1623
1624
        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
1625
1626
            <div class="item_totals_type_multi_select">
1627
1628
                <?php
1629
1630
                    $options  = array();
1631
                    $selected = array();
1632
1633
                    foreach ( $items as $index => $item ) {
1634
1635
                        if ( ! empty( $item['required'] ) ) {
1636
                            continue;
1637
                        }
1638
1639
                        $title = sanitize_text_field(  $item['title'] );
1640
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
1641
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
1642
1643
                        if ( ! isset( $selected_item ) ) {
1644
                            $selected = array( $item['id'] );
1645
                            $selected_item = 1;
1646
                        }
1647
1648
                    }
1649
1650
                    echo aui()->select(
1651
                        array(
1652
                                'name'        => 'payment-form-items',
1653
                                'id'          => $id,
1654
                                'no_wrap'     => true,
1655
                                'options'     => $options,
1656
                                'multiple'    => true,
1657
                                'class'       => 'wpi_select2 wpinv-items-multiselect-selector',
1658
                                'value'       => $selected,
1659
                        )
1660
                    );
1661
                ?>
1662
1663
                <div class="mt-3 border item_totals_type_select_totals">
1664
1665
                    <?php
1666
1667
                        $total     = 0;
1668
                        $tax       = 0;
1669
                        $sub_total = 0;
1670
1671
                        foreach ( $items as $item ) {
1672
1673
                            $class  = 'col-8';
1674
                            $class2 = '';
1675
1676
                            if ( ! empty( $item['allow_quantities'] ) ) {
1677
                                $class = 'col-6 pt-2';
1678
                                $class2 = 'pt-2';
1679
                            }
1680
1681
                            if ( ! empty( $item['custom_price'] ) ) {
1682
                                $class .= ' pt-2';
1683
                            }
1684
1685
                            $class3 = 'd-none';
1686
                            $name  = '';
1687
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
1688
1689
                                $amount = floatval( $item['price'] );
1690
                                if ( wpinv_use_taxes() ) {
1691
1692
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1693
1694
                                    if ( wpinv_prices_include_tax() ) {
1695
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1696
                                        $item_tax = $amount - $pre_tax;
1697
                                    } else {
1698
                                        $pre_tax  = $amount;
1699
                                        $item_tax = $amount * $rate * 0.01;
1700
                                    }
1701
1702
                                    $tax       = $tax + $item_tax;
1703
                                    $sub_total = $sub_total + $pre_tax;
1704
                                    $total     = $sub_total + $tax;
1705
1706
                                } else {
1707
                                    $total  = $total + $amount;
1708
                                }
1709
1710
                                $class3 = '';
1711
                                $name  = "wpinv-items[{$item['id']}]";
1712
1713
                                if ( empty( $item['required'] ) ) {
1714
                                    $totals_selected_select_item = 1;
1715
                                }
1716
1717
                            }
1718
1719
                            $class3 .= " wpinv_item_{$item['id']}";
1720
1721
                    ?>
1722
1723
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
1724
                        <div class='row pl-2 pr-2 pt-2'>
1725
                            <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div>
1726
1727
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1728
1729
                                <div class='col-2'>
1730
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
1731
                                </div>
1732
1733
                            <?php } else { ?>
1734
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1735
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1736
1737
                                <div class='col-4 <?php echo $class2; ?>'>
1738
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1739
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1740
                                </div>
1741
1742
                            <?php } else {?>
1743
1744
                                <div class='col-4'>
1745
                                    <div class='input-group'>
1746
1747
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1748
                                            <div class='input-group-prepend'>
1749
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1750
                                            </div>
1751
                                        <?php } ?>
1752
1753
                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
1754
                                    
1755
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1756
                                            <div class='input-group-append'>
1757
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1758
                                            </div>
1759
                                        <?php } ?>
1760
1761
                                    </div>
1762
                                </div>
1763
                            <?php } ?>
1764
1765
                        </div>
1766
                        <?php if ( ! empty( $item['description'] )) { ?>
1767
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1768
                        <?php } ?>
1769
                    </div>
1770
                <?php } ?>
1771
1772
                <div class='mt-4 border-top item_totals_total p-2'>
1773
1774
                    <div class='row'>
1775
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
1776
                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
1777
                    </div>
1778
1779
                    <div class='row' style='display: none;'>
1780
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
1781
                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div>
1782
                    </div>
1783
1784
                    <?php if ( wpinv_use_taxes() ) { ?>
1785
                        <div class='row'>
1786
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
1787
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
1788
                        </div>
1789
                    <?php } ?>
1790
1791
                    <div class='row'>
1792
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1793
                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
1794
                    </div>
1795
                </div>
1796
1797
            </div>
1798
        <?php } ?>
1799
        <?php if ( ! empty( $field[ 'description' ] ) ) { ?>
1800
            <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small>
1801
        <?php } ?>
1802
        </div>
1803
        <?php
1804
    }
1805
1806
    /**
1807
     * Renders the items element template.
1808
     */
1809
    public function edit_items_template( $field ) {
1810
        global $wpinv_euvat, $post;
1811
1812
        $restrict = $this->get_restrict_markup( $field, 'items' );
1813
        $id2      = $field . '.id + "_edit2"';
1814
        $id3      = $field . '.id + "_edit3"';
1815
1816
        // Item types.
1817
        $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
1818
1819
        ?>
1820
        <div <?php echo $restrict; ?>>
1821
            <div v-if="!is_default">
1822
                <label class='form-group'>
1823
                    <input v-model='<?php echo $field; ?>.hide_cart' type='checkbox' />
1824
                    <span class='form-check-label'><?php _e( 'Hide cart details', 'invoicing' ); ?></span>
1825
                </label>
1826
1827
                <div class="mb-1"><?php _e( 'Form Items', 'invoicing' ); ?></div>
1828
                <draggable v-model='form_items' group='selectable_form_items'>
1829
                    <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class="'item_' + item.id" :key="item.id">
1830
1831
                        <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'>
1832
                            <span class='label'>{{item.title}}</span>
1833
                            <span class='price'>({{formatPrice(item.price)}})</span>
1834
                            <span class='toggle-icon'>
1835
                                <span class='dashicons dashicons-arrow-down'></span>
1836
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
1837
                            </span>
1838
                        </div>
1839
1840
                        <div class='wpinv-available-items-editor-body'>
1841
                            <div class='p-3'>
1842
1843
                                <div class="form-group" v-if="! item.new">
1844
                                    <span class='form-text'>
1845
                                        <a target="_blank" :href="'<?php echo esc_url( admin_url( '/post.php?action=edit&post' ) ) ?>=' + item.id">
1846
                                            <?php _e( 'Edit the item name, price and other details', 'invoicing' ); ?>
1847
                                        </a>
1848
                                    </span>
1849
                                </div>
1850
1851
                                <div class='form-group' v-if="item.new">
1852
                                    <label class='mb-0 w-100'>
1853
                                        <span><?php _e( 'Item Name', 'invoicing' ); ?></span>
1854
                                        <input v-model='item.title' type='text' class='w-100'/>
1855
                                    </label>
1856
                                </div>
1857
1858
                                <div class='form-group'  v-if="item.new">
1859
                                    <label class='mb-0 w-100'>
1860
                                        <span v-if='!item.custom_price'><?php _e( 'Item Price', 'invoicing' ); ?></span>
1861
                                        <span v-if='item.custom_price'><?php _e( 'Recommended Price', 'invoicing' ); ?></span>
1862
                                        <input v-model='item.price' type='text' class='w-100'/>
1863
                                    </label>
1864
                                </div>
1865
1866
                                <div class='form-group' v-if='item.new'>
1867
                                    <label :for="'edit_item_type' + item.id" class='mb-0 w-100'>
1868
                                        <span><?php _e( 'Item Type', 'invoicing' ); ?></span>
1869
                                        <select class='w-100' v-model='item.type'>
1870
                                            <?php
1871
                                                foreach ( $item_types as $type => $_label ) {
1872
                                                    $type  = esc_attr( $type );
1873
                                                    $_label = esc_html( $_label );
1874
                                                    echo "<option value='$type'>$_label</type>";
1875
                                                }
1876
                                            ?>
1877
                                        </select>
1878
                                    </label>
1879
                                </div>
1880
1881
                                <div v-if='item.new'>
1882
                                    <?php if ( $wpinv_euvat->allow_vat_rules() ) : ?>
1883
                                        <div class='form-group'>
1884
                                            <label class='w-100 mb-0'><?php _e( 'VAT Rule', 'invoicing' ) ; ?>
1885
                                                <select class='w-100' v-model='item.rule'>
1886
                                                    <?php
1887
                                                        foreach ( $wpinv_euvat->get_rules() as $type => $_label ) {
1888
                                                            $type  = esc_attr( $type );
1889
                                                            $_label = esc_html( $_label );
1890
                                                            echo "<option value='$type'>$_label</type>";
1891
                                                        }
1892
                                                    ?>
1893
                                                </select>
1894
                                            </label>
1895
                                        </div>
1896
                                    <?php endif;?>
1897
1898
                                    <?php if ( $wpinv_euvat->allow_vat_classes() ) : ?>
1899
                                        <div class='form-group'>
1900
                                            <label class='w-100 mb-0'><?php _e( 'VAT class', 'invoicing' ) ; ?>
1901
                                                <select class='w-100' v-model='item.class'>
1902
                                                    <?php
1903
                                                        foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) {
1904
                                                            $type  = esc_attr( $type );
1905
                                                            $_label = esc_html( $_label );
1906
                                                            echo "<option value='$type'>$_label</type>"; 
1907
                                                        }
1908
                                                    ?>
1909
                                                </select>
1910
                                            </label>
1911
                                        </div>
1912
                                    <?php endif;?>
1913
                                                        
1914
                                </div>
1915
1916
                                <label v-if='item.new' class='form-group'>
1917
                                    <input v-model='item.custom_price' type='checkbox' />
1918
                                    <span class='form-check-label'><?php _e( 'Allow users to pay what they want', 'invoicing' ); ?></span>
1919
                                </label>
1920
1921
                                <div class='form-group' v-if='item.new && item.custom_price'>
1922
                                    <label class='mb-0 w-100'>
1923
                                        <span><?php _e( 'Minimum Price', 'invoicing' ); ?></span>
1924
                                        <input placeholder='0.00' v-model='item.minimum_price' class='w-100' />
1925
                                        <small class='form-text text-muted'><?php _e( 'Enter the minimum price that a user can pay', 'invoicing' ); ?></small>
1926
                                    </label>
1927
                                </div>
1928
1929
                                <label class='form-group'>
1930
                                    <input v-model='item.allow_quantities' type='checkbox' />
1931
                                    <span><?php _e( 'Allow users to buy several quantities', 'invoicing' ); ?></span>
1932
                                </label>
1933
1934
                                <label class='form-group'>
1935
                                    <input v-model='item.required' type='checkbox' />
1936
                                    <span><?php _e( 'This item is required', 'invoicing' ); ?></span>
1937
                                </label>
1938
1939
                                <div class='form-group'>
1940
                                    <label class="mb-0 w-100">
1941
                                        <span><?php _e( 'Item Description', 'invoicing' ); ?></span>
1942
                                        <textarea v-model='item.description' class='w-100'></textarea>
1943
                                    </label>
1944
                                </div>
1945
1946
                                    <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'><?php _e( 'Delete Item', 'invoicing' ); ?></button>
1947
1948
                                </div>
1949
                            </div>
1950
1951
                        </div>
1952
                </draggable>
1953
1954
                <small v-if='! form_items.length' class='form-text text-danger'><?php _e( 'You have not set up any items. Please select an item below or create a new item.', 'invoicing' ); ?></small>
1955
1956
                <div class='form-group mt-2'>
1957
1958
                    <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" v-model='selected_item' @change='addSelectedItem'>
1959
                        <option value=''><?php _e( 'Select an item to add...', 'invoicing' ) ?></option>
1960
                        <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
1961
                    </select>
1962
1963
                </div>
1964
1965
                <div class='form-group'>
1966
                    <button @click.prevent='addNewItem' class="button button-link"><?php _e( 'Or create a new item.', 'invoicing' ) ?></button>
1967
                </div>
1968
1969
                <div class='form-group mt-5'>
1970
                    <label :for='<?php echo $id2; ?>'><?php _e( 'Let customers...', 'invoicing' ) ?></label>
1971
1972
                    <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" :id='<?php echo $id2; ?>' v-model='<?php echo $field; ?>.items_type'>
1973
                        <option value='total' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Buy all items on the list', 'invoicing' ); ?></option>
1974
                        <option value='radio'><?php _e( 'Select a single item from the list', 'invoicing' ); ?></option>
1975
                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Select one or more items on the list', 'invoicing' ) ;?></option>
1976
                        <option value='select'><?php _e( 'Select a single item from a dropdown', 'invoicing' ); ?></option>
1977
                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Select a one or more items from a dropdown', 'invoicing' ) ;?></option>
1978
                    </select>
1979
1980
                </div>
1981
            </div>
1982
            <div class='form-group'>
1983
                <label :for='<?php echo $id3; ?>'><?php _e( 'Help Text', 'invoicing' ); ?></label>
1984
                <textarea placeholder='<?php esc_attr_e( 'Add some help text for this element', 'invoicing' ); ?>' :id='<?php echo $id3; ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea>
1985
            </div>
1986
1987
        </div>
1988
1989
        <?php
1990
1991
    }
1992
1993
    /**
1994
     * Returns an array of all published items.
1995
     */
1996
    public function get_published_items() {
1997
1998
        $item_args = array(
1999
            'post_type'      => 'wpi_item',
2000
            'orderby'        => 'title',
2001
            'order'          => 'ASC',
2002
            'posts_per_page' => -1,
2003
            'post_status'    => array( 'publish' ),
2004
            'meta_query'     => array(
2005
                array(
2006
                    'key'       => '_wpinv_type',
2007
                    'compare'   => '!=',
2008
                    'value'     => 'package'
2009
                )
2010
            )
2011
        );
2012
2013
        $items = get_posts( apply_filters( 'getpaid_payment_form_item_dropdown_query_args', $item_args ) );
2014
2015
        if ( empty( $items ) ) {
2016
            return array();
2017
        }
2018
2019
        $options    = array();
2020
        foreach ( $items as $item ) {
2021
            $item      = new GetPaid_Form_Item( $item );
2022
            $options[] = $item->prepare_data_for_use();
2023
        }
2024
        return $options;
2025
2026
    }
2027
2028
    /**
2029
     * Returns an array of items for the currently being edited form.
2030
     */
2031
    public function get_form_items( $id = false ) {
2032
        $form = new GetPaid_Payment_Form( $id );
2033
2034
        // Is this a default form?
2035
        if ( $form->is_default() ) {
2036
            return array();
2037
        }
2038
2039
        return $form->get_items( 'view', 'arrays' );
2040
    }
2041
2042
    /**
2043
     * Converts form items for use.
2044
     */
2045
    public function convert_checkout_items( $items, $invoice ) {
2046
2047
        $converted = array();
2048
        foreach ( $items as $item ) {
2049
2050
            $item_id = $item['id'];
2051
            $_item   = new WPInv_Item( $item_id );
2052
2053
            if( ! $_item ) {
2054
                continue;
2055
            }
2056
2057
            $converted[] = array(
2058
                'title'            => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ),
2059
                'id'               => $item['id'],
2060
                'price'            => $item['subtotal'],
2061
                'custom_price'     => $_item->get_is_dynamic_pricing(),
2062
                'recurring'        => $_item->is_recurring(),
2063
                'description'      => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ),
2064
                'minimum_price'    => $_item->get_minimum_price(),
2065
                'allow_quantities' => false,
2066
                'quantity'         => $item['quantity'],
2067
                'required'         => true,
2068
            );
2069
        }
2070
        return $converted;
2071
2072
    }
2073
2074
    /**
2075
     * Converts an array of id => quantity for use.
2076
     */
2077
    public function convert_normal_items( $items ) {
2078
2079
        $converted = array();
2080
        foreach ( $items as $item_id => $quantity ) {
2081
2082
            $item   = new WPInv_Item( $item_id );
2083
2084
            if( ! $item ) {
2085
                continue;
2086
            }
2087
2088
            $converted[] = array(
2089
                'title'            => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ),
2090
                'id'               => $item_id,
2091
                'price'            => $item->get_price(),
2092
                'custom_price'     => $item->get_is_dynamic_pricing(),
2093
                'recurring'        => $item->is_recurring(),
2094
                'description'      => $item->get_summary(),
2095
                'minimum_price'    => $item->get_minimum_price(),
2096
                'allow_quantities' => ! empty( $quantity ),
2097
                'quantity'         => empty( $quantity ) ? 1 : $quantity,
2098
                'required'         => true,
2099
            );
2100
2101
        }
2102
2103
        return $converted;
2104
2105
    }
2106
2107
    /**
2108
     * Returns an array of elements for the currently being edited form.
2109
     */
2110
    public function get_form_elements( $id = false ) {
2111
2112
        if ( empty( $id ) ) {
2113
            return wpinv_get_data( 'sample-payment-form' );
2114
        }
2115
        
2116
        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
2117
2118
        if ( is_array( $form_elements ) ) {
2119
            return $form_elements;
2120
        }
2121
2122
        return wpinv_get_data( 'sample-payment-form' );
2123
    }
2124
2125
    /**
2126
     * Sends a redrect response to payment details.
2127
     *
2128
     */
2129
    public function send_redirect_response( $url ) {
2130
        $url = urlencode( $url );
2131
        wp_send_json_success( $url );
2132
    }
2133
2134
    /**
2135
     * Fired when a checkout error occurs
2136
     *
2137
     */
2138
    public function checkout_error() {
2139
2140
        $errors = wpinv_get_errors();
2141
2142
        if ( ! empty( $errors ) ) {
2143
            wpinv_print_errors();
2144
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
2145
        }
2146
2147
        wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
2148
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
2149
2150
    }
2151
2152
}
2153