Passed
Push — master ( c90a51...25dd78 )
by Brian
05:26
created

render_alert_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
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
            if ( method_exists( $this, "frontend_render_{$element}_template" ) ) {
28
                add_action( "wpinv_frontend_render_payment_form_$element", array( $this, "frontend_render_{$element}_template" ), 10, 3 );
29
            }
30
31
        }
32
        
33
    }
34
35
    /**
36
     * Returns all the elements that can be added to a form.
37
     */
38
    public function get_elements() {
39
40
        if ( ! empty( $this->elements ) ) {
41
            return $this->elements;
42
        }
43
44
        $this->elements = array(
45
46
            array(
47
                'type'     => 'heading',
48
                'name'     => __( 'Heading', 'invoicing' ),
49
                'defaults' => array(
50
                    'level' => 'h2',
51
                    'text'  => __( 'Heading', 'invoicing' ),
52
                )
53
            ),
54
55
            array(
56
                'type' => 'paragraph',
57
                'name' => __( 'Paragraph', 'invoicing' ),
58
                'defaults'  => array(
59
                    'text'  => __( 'Paragraph text', 'invoicing' ),
60
                )
61
            ),
62
63
            array( 
64
                'type' => 'alert',
65
                'name' => __( 'Alert', 'invoicing' ),
66
                'defaults'  => array(
67
                    'value'        => '',
68
                    'class'        => 'alert-warning',
69
                    'text'         => __( 'Alert', 'invoicing' ),
70
                    'dismissible'  => false,
71
                )
72
            ),
73
74
            /*array( 
75
                'type' => 'separator',
76
                'name' => __( 'Separator', 'invoicing' ),
77
                'defaults'  => array(
78
                    'value'        => '',
79
                    'dismissible'  => false,
80
                )
81
            ),*/
82
83
            array(
84
                'type' => 'text',
85
                'name' => __( 'Text Input', 'invoicing' ),
86
                'defaults'  => array(
87
                    'placeholder'  => __( 'Enter some text', 'invoicing' ),
88
                    'value'        => '',
89
                    'label'        => __( 'Field Label', 'invoicing' ),
90
                    'description'  => '',
91
                    'required'     => false,
92
                )
93
            ),
94
95
            array(
96
                'type' => 'textarea',
97
                'name' => __( 'Textarea', 'invoicing' ),
98
                'defaults'         => array(
99
                    'placeholder'  => __( 'Enter your text hear', 'invoicing' ),
100
                    'value'        => '',
101
                    'label'        => __( 'Textarea Label', 'invoicing' ),
102
                    'description'  => '',
103
                    'required'     => false,
104
                )
105
            ),
106
107
            array(
108
                'type' => 'select',
109
                'name' => __( 'Dropdown', 'invoicing' ),
110
                'defaults'         => array(
111
                    'placeholder'  => __( 'Select a value', 'invoicing' ),
112
                    'value'        => '',
113
                    'label'        => __( 'Dropdown Label', 'invoicing' ),
114
                    'description'  => '',
115
                    'required'     => false,
116
                    'options'      => array(
117
                        esc_attr__( 'Option One', 'invoicing' ),
118
                        esc_attr__( 'Option Two', 'invoicing' ),
119
                        esc_attr__( 'Option Three', 'invoicing' )
120
                    ),
121
                )
122
            ),
123
124
            array(
125
                'type' => 'checkbox',
126
                'name' => __( 'Checkbox', 'invoicing' ),
127
                'defaults'         => array(
128
                    'value'        => '',
129
                    'label'        => __( 'Checkbox Label', 'invoicing' ),
130
                    'description'  => '',
131
                    'required'     => false,
132
                )
133
            ),
134
135
            array( 
136
                'type' => 'radio',
137
                'name' => __( 'Multiple Choice', 'invoicing' ),
138
                'defaults'     => array(
139
                    'label'    => __( 'Select one choice', 'invoicing' ),
140
                    'options'  => array(
141
                        esc_attr__( 'Choice One', 'invoicing' ),
142
                        esc_attr__( 'Choice Two', 'invoicing' ),
143
                        esc_attr__( 'Choice Three', 'invoicing' )
144
                    ),
145
                )
146
            ),
147
148
            array( 
149
                'type' => 'date',
150
                'name' => __( 'Date', 'invoicing' ),
151
                'defaults' => array(
152
                    'value'        => '',
153
                    'label'        => __( 'Date', 'invoicing' ),
154
                    'description'  => '',
155
                    'required'     => false,
156
                )
157
            ),
158
159
            array( 
160
                'type' => 'time',
161
                'name' => __( 'Time', 'invoicing' ),
162
                'defaults' => array(
163
                    'value'        => '',
164
                    'label'        => __( 'Time', 'invoicing' ),
165
                    'description'  => '',
166
                    'required'     => false,
167
                )
168
            ),
169
170
            array( 
171
                'type' => 'number',
172
                'name' => __( 'Number', 'invoicing' ),
173
                'defaults' => array(
174
                    'placeholder'  => '',
175
                    'value'        => '',
176
                    'label'        => __( 'Number', 'invoicing' ),
177
                    'description'  => '',
178
                    'required'     => false,
179
                )
180
            ),
181
182
            array( 
183
                'type' => 'website',
184
                'name' => __( 'Website', 'invoicing' ),
185
                'defaults' => array(
186
                    'placeholder'  => 'http://example.com',
187
                    'value'        => '',
188
                    'label'        => __( 'Website', 'invoicing' ),
189
                    'description'  => '',
190
                    'required'     => false,
191
                )
192
            ),
193
194
            array( 
195
                'type' => 'email',
196
                'name' => __( 'Email', 'invoicing' ),
197
                'defaults'  => array(
198
                    'placeholder'  => '[email protected]',
199
                    'value'        => '',
200
                    'label'        => __( 'Email Address', 'invoicing' ),
201
                    'description'  => '',
202
                    'required'     => false,
203
                )
204
            ),
205
206
            array( 
207
                'type' => 'address',
208
                'name' => __( 'Address', 'invoicing' ),
209
                'defaults'  => array(
210
211
                    'fields' => array(
212
                        array(
213
                            'placeholder'  => 'Jon',
214
                            'value'        => '',
215
                            'label'        => __( 'First Name', 'invoicing' ),
216
                            'description'  => '',
217
                            'required'     => false,
218
                            'visible'      => true,
219
                            'name'         => 'wpinv_first_name',
220
                        ),
221
222
                        array(
223
                            'placeholder'  => 'Snow',
224
                            'value'        => '',
225
                            'label'        => __( 'Last Name', 'invoicing' ),
226
                            'description'  => '',
227
                            'required'     => false,
228
                            'visible'      => true,
229
                            'name'         => 'wpinv_last_name',
230
                        ),
231
                    
232
                        array(
233
                            'placeholder'  => '',
234
                            'value'        => '',
235
                            'label'        => __( 'Address', 'invoicing' ),
236
                            'description'  => '',
237
                            'required'     => false,
238
                            'visible'      => true,
239
                            'name'         => 'wpinv_address',
240
                        ),
241
242
                        array(
243
                            'placeholder'  => '',
244
                            'value'        => '',
245
                            'label'        => __( 'City', 'invoicing' ),
246
                            'description'  => '',
247
                            'required'     => false,
248
                            'visible'      => true,
249
                            'name'         => 'wpinv_city',
250
                        ),
251
252
                        array(
253
                            'placeholder'  => __( 'Select your country' ),
254
                            'value'        => '',
255
                            'label'        => __( 'Country', 'invoicing' ),
256
                            'description'  => '',
257
                            'required'     => false,
258
                            'visible'      => true,
259
                            'name'         => 'wpinv_country',
260
                        ),
261
262
                        array(
263
                            'placeholder'  => __( 'Choose a state', 'invoicing' ),
264
                            'value'        => '',
265
                            'label'        => __( 'State / Province', 'invoicing' ),
266
                            'description'  => '',
267
                            'required'     => false,
268
                            'visible'      => true,
269
                            'name'         => 'wpinv_state',
270
                        ),
271
272
                        array(
273
                            'placeholder'  => '',
274
                            'value'        => '',
275
                            'label'        => __( 'ZIP / Postcode', 'invoicing' ),
276
                            'description'  => '',
277
                            'required'     => false,
278
                            'visible'      => true,
279
                            'name'         => 'wpinv_zip',
280
                        ),
281
282
                        array(
283
                            'placeholder'  => '',
284
                            'value'        => '',
285
                            'label'        => __( 'Phone', 'invoicing' ),
286
                            'description'  => '',
287
                            'required'     => false,
288
                            'visible'      => true,
289
                            'name'         => 'wpinv_phone',
290
                        ),
291
292
                        array(
293
                            'placeholder'  => '',
294
                            'value'        => '',
295
                            'label'        => __( 'Company', 'invoicing' ),
296
                            'description'  => '',
297
                            'required'     => false,
298
                            'visible'      => false,
299
                            'name'         => 'wpinv_company',
300
                        ),
301
302
                        array(
303
                            'placeholder'  => '',
304
                            'value'        => '',
305
                            'label'        => __( 'VAT Number', 'invoicing' ),
306
                            'description'  => '',
307
                            'required'     => false,
308
                            'visible'      => false,
309
                            'name'         => 'wpinv_vat_number',
310
                        )
311
                    )
312
                )
313
            ),
314
315
            array( 
316
                'type' => 'billing_email',
317
                'name' => __( 'Billing Email', 'invoicing' ),
318
                'defaults'  => array(
319
                    'placeholder'  => '[email protected]',
320
                    'value'        => '',
321
                    'label'        => __( 'Billing Email', 'invoicing' ),
322
                    'description'  => '',
323
                    'premade'      => true,
324
                )
325
            ),
326
/*
327
            array( 
328
                'type' => 'discount',
329
                'name' => __( 'Discount Input', 'invoicing' ),
330
                'defaults'  => array(
331
                    'value'        => '',
332
                    'input_label'  => __( 'Coupon Code', 'invoicing' ),
333
                    'button_label' => __( 'Apply Coupon', 'invoicing' ),
334
                    'description'  => __( 'Have a discount code? Enter it above.', 'invoicing' ),
335
                )
336
            ),*/
337
338
            array( 
339
                'type' => 'items',
340
                'name' => __( 'Items', 'invoicing' ),
341
                'defaults'  => array(
342
                    'value'        => '',
343
                    'items_type'   => 'total',
344
                    'description'  => '',
345
                    'premade'      => true,
346
                )
347
            ),
348
349
            array(
350
                'type' => 'terms',
351
                'name' => __( 'Terms', 'invoicing' ),
352
                'defaults'         => array(
353
                    'value'        => '',
354
                    'text'         => __( 'I\'ve read and accept the <a href="" target="_blank">terms &amp; conditions</a>', 'invoicing' ),
355
                    'description'  => '',
356
                    'required'     => true,
357
                )
358
            ),
359
360
            array(
361
                'type' => 'privacy',
362
                'name' => __( 'Privacy', 'invoicing' ),
363
                'defaults'         => array(
364
                    'value'        => '',
365
                    'text'         => __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our privacy policy.', 'invoicing' ),
366
                )
367
            ),
368
369
            array( 
370
                'type'       => 'pay_button',
371
                'name'       => __( 'Payment Button', 'invoicing' ),
372
                'defaults'   => array(
373
                    'value'        => '',
374
                    'class'        => 'btn-primary',
375
                    'label'        => __( 'Pay Now »', 'invoicing' ),
376
                    'description'  => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
377
                    'premade'      => true,
378
                )
379
            )
380
        );
381
382
        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
383
        return $this->elements;
384
    }
385
386
    /**
387
     * Returns the restrict markup.
388
     */
389
    public function get_restrict_markup( $field, $field_type ) {
390
        $restrict = "$field.type=='$field_type'";
391
        return "v-if=\"$restrict\"";
392
    }
393
394
    /**
395
     * Renders the title element template.
396
     */
397
    public function render_heading_template( $field ) {
398
        $restrict = $this->get_restrict_markup( $field, 'heading' );
399
        echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
400
    }
401
402
    /**
403
     * Renders the title element on the frontend.
404
     */
405
    public function frontend_render_heading_template( $field ) {
406
        $tag = $field['level'];
407
        echo "<$tag>{$field['text']}</$tag>";
408
    }
409
410
    /**
411
     * Renders the edit title element template.
412
     */
413
    public function edit_heading_template( $field ) {
414
        $restrict = $this->get_restrict_markup( $field, 'heading' );
415
        $label    = __( 'Heading', 'invoicing' );
416
        $label2   = __( 'Select Heading Level', 'invoicing' );
417
        $id       = $field . '.id + "_edit"';
418
        $id2      = $field . '.id + "_edit2"';
419
420
        echo "
421
            <div $restrict>
422
                <div class='form-group'>
423
                    <label :for='$id'>$label</label>
424
                    <input class='form-control' :id='$id' v-model='$field.text' type='text' />
425
                </div>
426
427
                <div class='form-group'>
428
                    <label :for='$id2'>$label2</label>
429
430
                    <select class='form-control custom-select' :id='$id2' v-model='$field.level'>
431
                        <option value='h1'>H1</option>
432
                        <option value='h2'>H2</option>
433
                        <option value='h3'>H3</option>
434
                        <option value='h4'>H4</option>
435
                        <option value='h5'>H5</option>
436
                        <option value='h6'>H6</option>
437
                        <option value='h7'>H7</option>
438
                    </select>
439
                </div>
440
            </div>
441
        ";
442
443
    }
444
445
    /**
446
     * Renders a paragraph element template.
447
     */
448
    public function render_paragraph_template( $field ) {
449
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
450
        $label    = "$field.text";
451
        echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
452
    }
453
454
    /**
455
     * Renders a privacy element template.
456
     */
457
    public function render_privacy_template( $field ) {
458
        $restrict = $this->get_restrict_markup( $field, 'privacy' );
459
        $label    = "$field.text";
460
        echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
461
    }
462
463
    /**
464
     * Renders the paragraph element on the frontend.
465
     */
466
    public function frontend_render_paragraph_template( $field ) {
467
        echo "<p>{$field['text']}</p>";
468
    }
469
470
    /**
471
     * Renders the privacy element on the frontend.
472
     */
473
    public function frontend_render_privacy_template( $field ) {
474
        echo "<p>{$field['text']}</p>";
475
    }
476
477
    /**
478
     * Renders the edit paragraph element template.
479
     */
480
    public function edit_paragraph_template( $field ) {
481
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
482
        $label    = __( 'Enter your text', 'invoicing' );
483
        $id       = $field . '.id + "_edit"';
484
        echo "
485
            <div $restrict>
486
                <div class='form-group'>
487
                    <label :for='$id'>$label</label>
488
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
489
                </div>
490
            </div>
491
        ";
492
493
    }
494
495
    /**
496
     * Renders the edit privacy element template.
497
     */
498
    public function edit_privacy_template( $field ) {
499
        $restrict = $this->get_restrict_markup( $field, 'privacy' );
500
        $label    = __( 'Privacy Text', 'invoicing' );
501
        $id       = $field . '.id + "_edit"';
502
        echo "
503
            <div $restrict>
504
                <div class='form-group'>
505
                    <label :for='$id'>$label</label>
506
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
507
                </div>
508
            </div>
509
        ";
510
511
    }
512
513
    /**
514
     * Renders the text element template.
515
     */
516
    public function render_text_template( $field ) {
517
        $restrict = $this->get_restrict_markup( $field, 'text' );
518
        $label    = "$field.label";
519
        echo "
520
            <div $restrict class='wpinv-payment-form-field-preview'>
521
                <div class='wpinv-payment-form-field-preview-overlay'></div>
522
                <label :for='$field.id'>{{" . $label . "}}</label>
523
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'>
524
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
525
            </div>    
526
        ";
527
    }
528
529
    /**
530
     * Renders the text element on the frontend.
531
     */
532
    public function frontend_render_text_template( $field ) {
533
        
534
        echo "<div class='form-group'>";
535
536
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

536
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
537
            array(
538
                'name'       => esc_attr( $field['id'] ),
539
                'id'         => esc_attr( $field['id'] ),
540
                'placeholder'=> esc_attr( $field['placeholder'] ),
541
                'required'   => (bool) $field['required'],
542
                'label'      => wp_kses_post( $field['label'] ),
543
                'no_wrap'    => true,
544
            )
545
        );
546
547
        if ( ! empty( $field['description'] ) ) {
548
            $description = wp_kses_post( $field['description'] );
549
            echo "<small class='form-text text-muted'>$description</small>";
550
        }
551
552
        echo '</div>';
553
554
    }
555
556
    /**
557
     * Renders the edit text element template.
558
     */
559
    public function edit_text_template( $field ) {
560
        $restrict = $this->get_restrict_markup( $field, 'text' );
561
        $label    = __( 'Field Label', 'invoicing' );
562
        $id       = $field . '.id + "_edit"';
563
        $label2   = __( 'Placeholder text', 'invoicing' );
564
        $id2      = $field . '.id + "_edit2"';
565
        $label3   = __( 'Help text', 'invoicing' );
566
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
567
        $id3      = $field . '.id + "_edit3"';
568
        $label5   = __( 'Is this field required?', 'invoicing' );
569
        $id4      = $field . '.id + "_edit4"';
570
        echo "
571
            <div $restrict>
572
                <div class='form-group'>
573
                    <label :for='$id'>$label</label>
574
                    <input :id='$id' v-model='$field.label' class='form-control' />
575
                </div>
576
                <div class='form-group'>
577
                    <label :for='$id2'>$label2</label>
578
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
579
                </div>
580
                <div class='form-group'>
581
                    <label :for='$id3'>$label3</label>
582
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
583
                </div>
584
                <div class='form-group form-check'>
585
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
586
                    <label class='form-check-label' :for='$id4'>$label5</label>
587
                </div>
588
            </div>
589
        ";
590
591
    }
592
593
    /**
594
     * Renders the textarea element template.
595
     */
596
    public function render_textarea_template( $field ) {
597
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
598
        $label    = "$field.label";
599
        echo "
600
            <div $restrict class='wpinv-payment-form-field-preview'>
601
                <div class='wpinv-payment-form-field-preview-overlay'></div>
602
                <label :for='$field.id'>{{" . $label . "}}</label>
603
                <textarea  :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea>
604
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
605
            </div>    
606
        ";
607
    }
608
609
    /**
610
     * Renders the textarea element on the frontend.
611
     */
612
    public function frontend_render_textarea_template( $field ) {
613
        
614
        echo "<div class='form-group'>";
615
616
        echo aui()->textarea(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

616
        echo /** @scrutinizer ignore-call */ aui()->textarea(
Loading history...
617
            array(
618
                'name'       => esc_attr( $field['id'] ),
619
                'id'         => esc_attr( $field['id'] ),
620
                'placeholder'=> esc_attr( $field['placeholder'] ),
621
                'required'   => (bool) $field['required'],
622
                'label'      => wp_kses_post( $field['label'] ),
623
                'no_wrap'    => true,
624
                'rows'       => 3,
625
            )
626
        );
627
628
        if ( ! empty( $field['description'] ) ) {
629
            $description = wp_kses_post( $field['description'] );
630
            echo "<small class='form-text text-muted'>$description</small>";
631
        }
632
633
        echo '</div>';
634
635
    }
636
637
    /**
638
     * Renders the edit textarea element template.
639
     */
640
    public function edit_textarea_template( $field ) {
641
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
642
        $label    = __( 'Field Label', 'invoicing' );
643
        $id       = $field . '.id + "_edit"';
644
        $label2   = __( 'Placeholder text', 'invoicing' );
645
        $id2      = $field . '.id + "_edit2"';
646
        $label3   = __( 'Help text', 'invoicing' );
647
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
648
        $id3      = $field . '.id + "_edit3"';
649
        $label5   = __( 'Is this field required?', 'invoicing' );
650
        $id4      = $field . '.id + "_edit4"';
651
        echo "
652
            <div $restrict>
653
                <div class='form-group'>
654
                    <label :for='$id'>$label</label>
655
                    <input :id='$id' v-model='$field.label' class='form-control' />
656
                </div>
657
                <div class='form-group'>
658
                    <label :for='$id2'>$label2</label>
659
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
660
                </div>
661
                <div class='form-group'>
662
                    <label :for='$id3'>$label3</label>
663
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
664
                </div>
665
                <div class='form-group form-check'>
666
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
667
                    <label class='form-check-label' :for='$id4'>$label5</label>
668
                </div>
669
            </div>
670
        ";
671
672
    }
673
674
    /**
675
     * Renders the select element template.
676
     */
677
    public function render_select_template( $field ) {
678
        $restrict    = $this->get_restrict_markup( $field, 'select' );
679
        $label       = "$field.label";
680
        $placeholder = "$field.placeholder";
681
        $id          = $field . '.id';
682
        echo "
683
            <div $restrict class='wpinv-payment-form-field-preview'>
684
                <div class='wpinv-payment-form-field-preview-overlay'></div>
685
                <label :for='$id'>{{" . $label . "}}</label>
686
                <select id='$id' class='form-control custom-select'  v-model='$field.value'>
687
                    <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option>
688
                    <option v-for='option in $field.options' value='option'>{{option}}</option>
689
                </select>
690
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
691
            </div>
692
        ";
693
    }
694
695
    /**
696
     * Renders the select element on the frontend.
697
     */
698
    public function frontend_render_select_template( $field ) {
699
        
700
        echo "<div class='form-group'>";
701
702
        echo aui()->select(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

702
        echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
703
            array(
704
                'name'       => esc_attr( $field['id'] ),
705
                'id'         => esc_attr( $field['id'] ),
706
                'placeholder'=> esc_attr( $field['placeholder'] ),
707
                'required'   => (bool) $field['required'],
708
                'label'      => wp_kses_post( $field['label'] ),
709
                'no_wrap'    => true,
710
                'options'    => array_combine( $field['options'], $field['options'] ),
711
            )
712
        );
713
714
        if ( ! empty( $field['description'] ) ) {
715
            $description = wp_kses_post( $field['description'] );
716
            echo "<small class='form-text text-muted'>$description</small>";
717
        }
718
719
        echo '</div>';
720
721
    }
722
723
    /**
724
     * Renders the edit select element template.
725
     */
726
    public function edit_select_template( $field ) {
727
        $restrict = $this->get_restrict_markup( $field, 'select' );
728
        $label    = __( 'Field Label', 'invoicing' );
729
        $id       = $field . '.id + "_edit"';
730
        $label2   = __( 'Placeholder text', 'invoicing' );
731
        $id2      = $field . '.id + "_edit2"';
732
        $label3   = __( 'Help text', 'invoicing' );
733
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
734
        $id3      = $field . '.id + "_edit3"';
735
        $label5   = __( 'Is this field required?', 'invoicing' );
736
        $id4      = $field . '.id + "_edit4"';
737
        $label6   = __( 'Available Options', 'invoicing' );
738
        echo "
739
            <div $restrict>
740
                <div class='form-group'>
741
                    <label :for='$id'>$label</label>
742
                    <input :id='$id' v-model='$field.label' class='form-control' />
743
                </div>
744
                <div class='form-group'>
745
                    <label :for='$id2'>$label2</label>
746
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
747
                </div>
748
                <div class='form-group'>
749
                    <label :for='$id3'>$label3</label>
750
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
751
                </div>
752
                <div class='form-group form-check'>
753
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
754
                    <label class='form-check-label' :for='$id4'>$label5</label>
755
                </div>
756
                <hr class='featurette-divider mt-4'>
757
                <h5>$label6</h5>
758
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
759
                    <input type='text' class='form-control' v-model='$field.options[index]'>
760
                    <div class='input-group-append'>
761
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
762
                    </div>
763
                </div>
764
                <div class='form-group'>
765
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
766
                </div>
767
            </div>
768
        ";
769
770
    }
771
772
    /**
773
     * Renders the checkbox element template.
774
     */
775
    public function render_checkbox_template( $field ) {
776
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
777
        echo "
778
            <div class='form-check' $restrict>
779
                <div class='wpinv-payment-form-field-preview-overlay'></div>
780
                <input  :id='$field.id' class='form-check-input' type='checkbox' />
781
                <label class='form-check-label' :for='$field.id' v-html='$field.label'></label>
782
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
783
            </div>    
784
        ";
785
    }
786
787
    /**
788
     * Renders the terms element template.
789
     */
790
    public function render_terms_template( $field ) {
791
        $restrict = $this->get_restrict_markup( $field, 'terms' );
792
        echo "
793
            <div class='form-check' $restrict>
794
                <div class='wpinv-payment-form-field-preview-overlay'></div>
795
                <input  :id='$field.id' class='form-check-input' type='checkbox' />
796
                <label class='form-check-label' :for='$field.id' v-html='$field.text'></label>
797
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
798
            </div>    
799
        ";
800
    }
801
802
    /**
803
     * Renders the checkbox element on the frontend.
804
     */
805
    public function frontend_render_checkbox_template( $field ) {
806
        
807
        echo "<div class='form-group'>";
808
809
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

809
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
810
            array(
811
                'name'       => esc_attr( $field['id'] ),
812
                'id'         => esc_attr( $field['id'] ),
813
                'required'   => (bool) $field['required'],
814
                'label'      => wp_kses_post( $field['label'] ),
815
                'no_wrap'    => true,
816
                'value'      => esc_attr__( 'Yes', 'invoicing' ),
817
                'type'       => 'checkbox',
818
            )
819
        );
820
821
        if ( ! empty( $field['description'] ) ) {
822
            $description = wp_kses_post( $field['description'] );
823
            echo "<small class='form-text text-muted'>$description</small>";
824
        }
825
826
        echo '</div>';
827
828
    }
829
830
        /**
831
     * Renders the terms element on the frontend.
832
     */
833
    public function frontend_render_terms_template( $field ) {
834
        
835
        echo "<div class='form-group'>";
836
837
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

837
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
838
            array(
839
                'name'       => esc_attr( $field['id'] ),
840
                'id'         => esc_attr( $field['id'] ),
841
                'required'   => (bool) $field['required'],
842
                'label'      => wp_kses_post( $field['text'] ),
843
                'no_wrap'    => true,
844
                'value'      => esc_attr__( 'Yes', 'invoicing' ),
845
                'type'       => 'checkbox',
846
            )
847
        );
848
849
        if ( ! empty( $field['description'] ) ) {
850
            $description = wp_kses_post( $field['description'] );
851
            echo "<small class='form-text text-muted'>$description</small>";
852
        }
853
854
        echo '</div>';
855
856
    }
857
858
    /**
859
     * Renders the edit checkbox element template.
860
     */
861
    public function edit_checkbox_template( $field ) {
862
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
863
        $label    = __( 'Field Label', 'invoicing' );
864
        $id       = $field . '.id + "_edit"';
865
        $label2   = __( 'Help text', 'invoicing' );
866
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
867
        $id2      = $field . '.id + "_edit2"';
868
        $label4   = __( 'Is this field required?', 'invoicing' );
869
        $id3      = $field . '.id + "_edit3"';
870
        echo "
871
            <div $restrict>
872
                <div class='form-group'>
873
                    <label :for='$id'>$label</label>
874
                    <input :id='$id' v-model='$field.label' class='form-control' />
875
                </div>
876
                <div class='form-group'>
877
                    <label :for='$id2'>$label2</label>
878
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
879
                </div>
880
                <div class='form-group form-check'>
881
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
882
                    <label class='form-check-label' :for='$id3'>$label4</label>
883
                </div>
884
            </div>
885
        ";
886
887
    }
888
889
    /**
890
     * Renders the edit terms element template.
891
     */
892
    public function edit_terms_template( $field ) {
893
        $restrict = $this->get_restrict_markup( $field, 'terms' );
894
        $label    = __( 'Field Label', 'invoicing' );
895
        $id       = $field . '.id + "_edit"';
896
        $label2   = __( 'Help text', 'invoicing' );
897
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
898
        $id2      = $field . '.id + "_edit2"';
899
        $label4   = __( 'Is this field required?', 'invoicing' );
900
        $id3      = $field . '.id + "_edit3"';
901
        echo "
902
            <div $restrict>
903
                <div class='form-group'>
904
                    <label :for='$id'>$label</label>
905
                    <input :id='$id' v-model='$field.text' class='form-control' />
906
                </div>
907
                <div class='form-group'>
908
                    <label :for='$id2'>$label2</label>
909
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
910
                </div>
911
                <div class='form-group form-check'>
912
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
913
                    <label class='form-check-label' :for='$id3'>$label4</label>
914
                </div>
915
            </div>
916
        ";
917
918
    }
919
920
    /**
921
     * Renders the radio element template.
922
     */
923
    public function render_radio_template( $field ) {
924
        $restrict    = $this->get_restrict_markup( $field, 'radio' );
925
        $label       = "$field.label";
926
        $id          = $field . '.id';
927
        echo "
928
            <div $restrict class='wpinv-payment-form-field-preview'>
929
                <div class='wpinv-payment-form-field-preview-overlay'></div>
930
                <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend>
931
                <div class='form-check' v-for='(option, index) in $field.options'>
932
                    <input class='form-check-input' type='radio' :id='$id + index'>
933
                    <label class='form-check-label' :for='$id + index'>{{option}}</label>
934
                </div>
935
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
936
            </div>
937
        ";
938
    }
939
940
    /**
941
     * Renders the radio element on the frontend.
942
     */
943
    public function frontend_render_radio_template( $field ) {
944
        
945
        echo "<div class='form-group'>";
946
947
        if ( ! empty( $field['label'] ) ) {
948
            $label = wp_kses_post( $field['label'] );
949
            echo "<legend class='col-form-label'>$label</legend>";
950
        }
951
952
        foreach( $field['options'] as $index => $option ) {
953
            $id    = $field['id'] . $index;
954
            $name  = $field['id'];
955
            $value = esc_attr( $option );
956
            $label = wp_kses_post( $option );
957
958
            echo "
959
                <div class='form-check'>
960
                    <input class='form-check-input' type='radio' name='$name' id='$id' value='$value'>
961
                    <label class='form-check-label' for='$id'>$label</label>
962
                </div>
963
            ";
964
        }
965
966
        if ( ! empty( $field['description'] ) ) {
967
            $description = wp_kses_post( $field['description'] );
968
            echo "<small class='form-text text-muted'>$description</small>";
969
        }
970
971
        echo '</div>';
972
973
    }
974
975
    /**
976
     * Renders the edit radio element template.
977
     */
978
    public function edit_radio_template( $field ) {
979
        $restrict = $this->get_restrict_markup( $field, 'radio' );
980
        $label    = __( 'Field Label', 'invoicing' );
981
        $id       = $field . '.id + "_edit"';
982
        $label2   = __( 'Help text', 'invoicing' );
983
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
984
        $id2      = $field . '.id + "_edit3"';
985
        $label4   = __( 'Is this field required?', 'invoicing' );
986
        $id3      = $field . '.id + "_edit4"';
987
        $label5   = __( 'Available Options', 'invoicing' );
988
        echo "
989
            <div $restrict>
990
                <div class='form-group'>
991
                    <label :for='$id'>$label</label>
992
                    <input :id='$id' v-model='$field.label' class='form-control' />
993
                </div>
994
                <div class='form-group'>
995
                    <label :for='$id2'>$label2</label>
996
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
997
                </div>
998
                <div class='form-group form-check'>
999
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
1000
                    <label class='form-check-label' :for='$id3'>$label4</label>
1001
                </div>
1002
                <hr class='featurette-divider mt-4'>
1003
                <h5>$label5</h5>
1004
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
1005
                    <input type='text' class='form-control' v-model='$field.options[index]'>
1006
                    <div class='input-group-append'>
1007
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
1008
                    </div>
1009
                </div>
1010
                <div class='form-group'>
1011
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
1012
                </div>
1013
            </div>
1014
        ";
1015
1016
    }
1017
1018
    /**
1019
     * Renders the address element template.
1020
     */
1021
    public function render_address_template( $field ) {
1022
        $restrict    = $this->get_restrict_markup( $field, 'address' );
1023
1024
        echo "
1025
            <div class='wpinv-address-wrapper' $restrict>
1026
                <draggable v-model='$field.fields' group='address_fields_preview'>
1027
                    <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'>
1028
                        <div class='wpinv-payment-form-field-preview-overlay'></div>
1029
                        <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label>
1030
                        <input v-if='field.name !== \"wpinv_country\" && field.name !== \"wpinv_state\"' class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'>
1031
                        <select v-else class='form-control' :id='field.name'>
1032
                            <option v-if='field.placeholder'>{{field.placeholder}}</option>
1033
                        </select>
1034
                        <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small>
1035
                    </div>
1036
                </draggable>
1037
            </div>
1038
        ";
1039
    }
1040
1041
    /**
1042
     * Renders the address element on the frontend.
1043
     */
1044
    public function frontend_render_address_template( $field ) {
1045
        
1046
        echo "<div class='wpinv-address-fields'>";
1047
1048
        foreach( $field['fields'] as $address_field ) {
1049
1050
            if ( empty( $address_field['visible'] ) ) {
1051
                continue;
1052
            }
1053
1054
            $class = esc_attr( $address_field['name'] );
1055
            echo "<div class='form-group $class'>";
1056
1057
            $label = $address_field['label'];
1058
1059
            if ( ! empty( $address_field['required'] ) ) {
1060
                $label .= "<span class='text-danger'> *</span>";
1061
            }
1062
1063
            if ( 'wpinv_country' == $address_field['name'] ) {
1064
1065
                echo aui()->select( array(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1065
                echo /** @scrutinizer ignore-call */ aui()->select( array(
Loading history...
1066
                    'options'          => wpinv_get_country_list(),
1067
                    'name'             => esc_attr( $address_field['name'] ),
1068
                    'id'               => esc_attr( $address_field['name'] ),
1069
                    'value'            => wpinv_get_default_country(),
1070
                    'placeholder'      => esc_attr( $address_field['placeholder'] ),
1071
                    'required'         => (bool) $address_field['required'],
1072
                    'no_wrap'          => true,
1073
                    'label'            => wp_kses_post( $label ),
1074
                    'select2'          => false,
1075
                ));
1076
    
1077
            } else if ( 'wpinv_state' == $address_field['name'] ) {
1078
1079
                $states = wpinv_get_country_states( wpinv_get_default_country() );
1080
                $state  = wpinv_get_default_state();
1081
1082
                if ( ! empty( $states ) ) {
1083
1084
                    echo aui()->select( array(
1085
                        'options'          => $states,
1086
                        'name'             => esc_attr( $address_field['name'] ),
1087
                        'id'               => esc_attr( $address_field['name'] ),
1088
                        'value'            => $state,
1089
                        'placeholder'      => esc_attr( $address_field['placeholder'] ),
1090
                        'required'         => (bool) $address_field['required'],
1091
                        'no_wrap'          => true,
1092
                        'label'            => wp_kses_post( $label ),
1093
                        'select2'          => false,
1094
                    ));
1095
1096
                } else {
1097
1098
                    echo aui()->input(
1099
                        array(
1100
                            'name'       => esc_attr( $address_field['name'] ),
1101
                            'id'         => esc_attr( $address_field['name'] ),
1102
                            'required'   => (bool) $address_field['required'],
1103
                            'label'      => wp_kses_post( $label ),
1104
                            'no_wrap'    => true,
1105
                            'type'       => 'text',
1106
                        )
1107
                    );
1108
1109
                }
1110
1111
            } else {
1112
1113
                echo aui()->input(
1114
                    array(
1115
                        'name'       => esc_attr( $address_field['name'] ),
1116
                        'id'         => esc_attr( $address_field['name'] ),
1117
                        'required'   => (bool) $address_field['required'],
1118
                        'label'      => wp_kses_post( $label ),
1119
                        'no_wrap'    => true,
1120
                        'placeholder' => esc_attr( $address_field['placeholder'] ),
1121
                        'type'       => 'text',
1122
                    )
1123
                );
1124
1125
            }
1126
            
1127
1128
            if ( ! empty( $address_field['description'] ) ) {
1129
                $description = wp_kses_post( $address_field['description'] );
1130
                echo "<small class='form-text text-muted'>$description</small>";
1131
            }
1132
    
1133
            echo '</div>';
1134
1135
        }
1136
1137
        echo '</div>';
1138
1139
    }
1140
1141
    /**
1142
     * Renders the edit address element template.
1143
     */
1144
    public function edit_address_template( $field ) {
1145
        $restrict  = $this->get_restrict_markup( $field, 'address' );
1146
        $label     = __( 'Field Label', 'invoicing' );
1147
        $label2    = __( 'Placeholder', 'invoicing' );
1148
        $label3    = __( 'Description', 'invoicing' );
1149
        $label4    = __( 'Is required', 'invoicing' );
1150
        $label5    = __( 'Is visible', 'invoicing' );
1151
        $id        = $field . '.id + "_edit_label"';
1152
        $id2       = $field . '.id + "_edit_placeholder"';
1153
        $id3       = $field . '.id + "_edit_description"';
1154
        $id4       = $field . '.id + "_edit_required"';
1155
        $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...
1156
        $id5       = $field . '.id + "_edit_visible"';
1157
        $id_main   = $field . '.id';
1158
1159
        echo "
1160
            <div $restrict :id='$id_main'>
1161
                <draggable v-model='$field.fields' group='address_fields'>
1162
                    <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'>
1163
1164
                        <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'>
1165
                            <span class='label'>{{field.label}}</span>
1166
                            <span class='toggle-visibility-icon' @click.stop='field.visible = !field.visible;'>
1167
                                <span class='dashicons dashicons-hidden'></span>
1168
                                <span class='dashicons dashicons-visibility'></span>
1169
                            </span>
1170
                            <span class='toggle-icon'>
1171
                                <span class='dashicons dashicons-arrow-down'></span>
1172
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
1173
                            </span>
1174
                        </div>
1175
1176
                        <div class='wpinv-form-address-field-editor-editor-body'>
1177
                            <div class='p-2'>
1178
1179
                                <div class='form-group'>
1180
                                    <label :for='$id + index'>$label</label>
1181
                                    <input :id='$id + index' v-model='field.label' class='form-control' />
1182
                                </div>
1183
1184
                                <div class='form-group'>
1185
                                    <label :for='$id2 + index'>$label2</label>
1186
                                    <input :id='$id2 + index' v-model='field.placeholder' class='form-control' />
1187
                                </div>
1188
1189
                                <div class='form-group'>
1190
                                    <label :for='$id3 + index'>$label3</label>
1191
                                    <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea>
1192
                                </div>
1193
1194
                                <div class='form-group form-check'>
1195
                                    <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' />
1196
                                    <label class='form-check-label' :for='$id4 + index'>$label4</label>
1197
                                </div>
1198
1199
                                <div class='form-group form-check'>
1200
                                    <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' />
1201
                                    <label class='form-check-label' :for='$id5 + index'>$label5</label>
1202
                                </div>
1203
1204
                            </div>
1205
                        </div>
1206
1207
                    </div>
1208
                </draggable>
1209
1210
            </div>
1211
        ";
1212
1213
    }
1214
1215
    /**
1216
     * Renders the email element template.
1217
     */
1218
    public function render_email_template( $field ) {
1219
        $restrict = $this->get_restrict_markup( $field, 'email' );
1220
        $label    = "$field.label";
1221
        echo "
1222
            <div $restrict class='wpinv-payment-form-field-preview'>
1223
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1224
                <label :for='$field.id'>{{" . $label . "}}</label>
1225
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
1226
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1227
            </div>    
1228
        ";
1229
    }
1230
1231
    /**
1232
     * Renders the billing_email element template.
1233
     */
1234
    public function render_billing_email_template( $field ) {
1235
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1236
        $label    = "$field.label";
1237
        echo "
1238
            <div $restrict>
1239
                <label :for='$field.id'>{{" . $label . "}}</label>
1240
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
1241
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1242
            </div>    
1243
        ";
1244
    }
1245
1246
    /**
1247
     * Renders the email element on the frontend.
1248
     */
1249
    public function frontend_render_email_template( $field ) {
1250
        
1251
        echo "<div class='form-group'>";
1252
1253
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1253
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1254
            array(
1255
                'name'       => esc_attr( $field['id'] ),
1256
                'id'         => esc_attr( $field['id'] ),
1257
                'required'   => (bool) $field['required'],
1258
                'label'      => wp_kses_post( $field['label'] ),
1259
                'no_wrap'    => true,
1260
                'placeholder' => esc_attr( $field['placeholder'] ),
1261
                'type'       => 'email',
1262
            )
1263
        );
1264
1265
        if ( ! empty( $field['description'] ) ) {
1266
            $description = wp_kses_post( $field['description'] );
1267
            echo "<small class='form-text text-muted'>$description</small>";
1268
        }
1269
1270
        echo '</div>';
1271
1272
    }
1273
1274
    /**
1275
     * Renders the billing email element on the frontend.
1276
     */
1277
    public function frontend_render_billing_email_template( $field ) {
1278
        
1279
        echo "<div class='form-group'>";
1280
        $value = '';
1281
1282
        if ( is_user_logged_in() ) {
1283
            $user  = wp_get_current_user();
1284
            $value = sanitize_email( $user->user_email );
1285
        }
1286
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1286
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1287
            array(
1288
                'name'       => 'billing_email',
1289
                'value'      => $value,
1290
                'id'         => esc_attr( $field['id'] ),
1291
                'required'   => true,
1292
                'label'      => wp_kses_post( $field['label'] ),
1293
                'no_wrap'    => true,
1294
                'placeholder' => esc_attr( $field['placeholder'] ),
1295
                'type'       => 'email',
1296
            )
1297
        );
1298
1299
        if ( ! empty( $field['description'] ) ) {
1300
            $description = wp_kses_post( $field['description'] );
1301
            echo "<small class='form-text text-muted'>$description</small>";
1302
        }
1303
1304
        echo '</div>';
1305
1306
    }
1307
1308
    /**
1309
     * Renders the edit email element template.
1310
     */
1311
    public function edit_email_template( $field ) {
1312
        $restrict = $this->get_restrict_markup( $field, 'email' );
1313
        $label    = __( 'Field Label', 'invoicing' );
1314
        $id       = $field . '.id + "_edit"';
1315
        $label2   = __( 'Placeholder text', 'invoicing' );
1316
        $id2      = $field . '.id + "_edit2"';
1317
        $label3   = __( 'Help text', 'invoicing' );
1318
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1319
        $id3      = $field . '.id + "_edit3"';
1320
        $label5   = __( 'Is this field required?', 'invoicing' );
1321
        $id4      = $field . '.id + "_edit4"';
1322
        echo "
1323
            <div $restrict>
1324
                <div class='form-group'>
1325
                    <label :for='$id'>$label</label>
1326
                    <input :id='$id' v-model='$field.label' class='form-control' />
1327
                </div>
1328
                <div class='form-group'>
1329
                    <label :for='$id2'>$label2</label>
1330
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1331
                </div>
1332
                <div class='form-group'>
1333
                    <label :for='$id3'>$label3</label>
1334
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1335
                </div>
1336
                <div class='form-group form-check'>
1337
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1338
                    <label class='form-check-label' :for='$id4'>$label5</label>
1339
                </div>
1340
            </div>
1341
        ";
1342
1343
    }
1344
1345
    /**
1346
     * Renders the edit billing_email element template.
1347
     */
1348
    public function edit_billing_email_template( $field ) {
1349
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1350
        $label    = __( 'Field Label', 'invoicing' );
1351
        $id       = $field . '.id + "_edit"';
1352
        $label2   = __( 'Placeholder text', 'invoicing' );
1353
        $id2      = $field . '.id + "_edit2"';
1354
        $label3   = __( 'Help text', 'invoicing' );
1355
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1356
        $id3      = $field . '.id + "_edit3"';
1357
        $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...
1358
        $id4      = $field . '.id + "_edit4"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id4 is dead and can be removed.
Loading history...
1359
        echo "
1360
            <div $restrict>
1361
                <div class='form-group'>
1362
                    <label :for='$id'>$label</label>
1363
                    <input :id='$id' v-model='$field.label' class='form-control' />
1364
                </div>
1365
                <div class='form-group'>
1366
                    <label :for='$id2'>$label2</label>
1367
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1368
                </div>
1369
                <div class='form-group'>
1370
                    <label :for='$id3'>$label3</label>
1371
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1372
                </div>
1373
            </div>
1374
        ";
1375
1376
    }
1377
1378
    /**
1379
     * Renders the website element template.
1380
     */
1381
    public function render_website_template( $field ) {
1382
        $restrict = $this->get_restrict_markup( $field, 'website' );
1383
        $label    = "$field.label";
1384
        echo "
1385
            <div $restrict class='wpinv-payment-form-field-preview'>
1386
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1387
                <label :for='$field.id'>{{" . $label . "}}</label>
1388
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'>
1389
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1390
            </div>    
1391
        ";
1392
    }
1393
1394
    /**
1395
     * Renders the website element on the frontend.
1396
     */
1397
    public function frontend_render_website_template( $field ) {
1398
        
1399
        echo "<div class='form-group'>";
1400
1401
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1401
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1402
            array(
1403
                'name'       => esc_attr( $field['id'] ),
1404
                'id'         => esc_attr( $field['id'] ),
1405
                'required'   => (bool) $field['required'],
1406
                'label'      => wp_kses_post( $field['label'] ),
1407
                'no_wrap'    => true,
1408
                'placeholder' => esc_attr( $field['placeholder'] ),
1409
                'type'       => 'url',
1410
            )
1411
        );
1412
1413
        if ( ! empty( $field['description'] ) ) {
1414
            $description = wp_kses_post( $field['description'] );
1415
            echo "<small class='form-text text-muted'>$description</small>";
1416
        }
1417
1418
        echo '</div>';
1419
1420
    }
1421
1422
    /**
1423
     * Renders the edit website element template.
1424
     */
1425
    public function edit_website_template( $field ) {
1426
        $restrict = $this->get_restrict_markup( $field, 'website' );
1427
        $label    = __( 'Field Label', 'invoicing' );
1428
        $id       = $field . '.id + "_edit"';
1429
        $label2   = __( 'Placeholder text', 'invoicing' );
1430
        $id2      = $field . '.id + "_edit2"';
1431
        $label3   = __( 'Help text', 'invoicing' );
1432
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1433
        $id3      = $field . '.id + "_edit3"';
1434
        $label5   = __( 'Is this field required?', 'invoicing' );
1435
        $id4      = $field . '.id + "_edit4"';
1436
        echo "
1437
            <div $restrict>
1438
                <div class='form-group'>
1439
                    <label :for='$id'>$label</label>
1440
                    <input :id='$id' v-model='$field.label' class='form-control' />
1441
                </div>
1442
                <div class='form-group'>
1443
                    <label :for='$id2'>$label2</label>
1444
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1445
                </div>
1446
                <div class='form-group'>
1447
                    <label :for='$id3'>$label3</label>
1448
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1449
                </div>
1450
                <div class='form-group form-check'>
1451
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1452
                    <label class='form-check-label' :for='$id4'>$label5</label>
1453
                </div>
1454
            </div>
1455
        ";
1456
1457
    }
1458
1459
    /**
1460
     * Renders the date element template.
1461
     */
1462
    public function render_date_template( $field ) {
1463
        $restrict = $this->get_restrict_markup( $field, 'date' );
1464
        $label    = "$field.label";
1465
        echo "
1466
            <div $restrict class='wpinv-payment-form-field-preview'>
1467
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1468
                <label :for='$field.id'>{{" . $label . "}}</label>
1469
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'>
1470
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1471
            </div>    
1472
        ";
1473
    }
1474
1475
    /**
1476
     * Renders the date element on the frontend.
1477
     */
1478
    public function frontend_render_date_template( $field ) {
1479
        
1480
        echo "<div class='form-group'>";
1481
1482
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1482
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1483
            array(
1484
                'name'       => esc_attr( $field['id'] ),
1485
                'id'         => esc_attr( $field['id'] ),
1486
                'required'   => (bool) $field['required'],
1487
                'label'      => wp_kses_post( $field['label'] ),
1488
                'no_wrap'    => true,
1489
                'type'       => 'date',
1490
            )
1491
        );
1492
1493
        if ( ! empty( $field['description'] ) ) {
1494
            $description = wp_kses_post( $field['description'] );
1495
            echo "<small class='form-text text-muted'>$description</small>";
1496
        }
1497
1498
        echo '</div>';
1499
1500
    }
1501
1502
    /**
1503
     * Renders the edit date element template.
1504
     */
1505
    public function edit_date_template( $field ) {
1506
        $restrict = $this->get_restrict_markup( $field, 'date' );
1507
        $label    = __( 'Field Label', 'invoicing' );
1508
        $id       = $field . '.id + "_edit"';
1509
        $label3   = __( 'Help text', 'invoicing' );
1510
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1511
        $id3      = $field . '.id + "_edit3"';
1512
        $label5   = __( 'Is this field required?', 'invoicing' );
1513
        $id4      = $field . '.id + "_edit4"';
1514
        echo "
1515
            <div $restrict>
1516
                <div class='form-group'>
1517
                    <label :for='$id'>$label</label>
1518
                    <input :id='$id' v-model='$field.label' class='form-control' />
1519
                </div>
1520
                <div class='form-group'>
1521
                    <label :for='$id3'>$label3</label>
1522
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1523
                </div>
1524
                <div class='form-group form-check'>
1525
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1526
                    <label class='form-check-label' :for='$id4'>$label5</label>
1527
                </div>
1528
            </div>
1529
        ";
1530
1531
    }
1532
1533
    /**
1534
     * Renders the time element template.
1535
     */
1536
    public function render_time_template( $field ) {
1537
        $restrict = $this->get_restrict_markup( $field, 'time' );
1538
        $label    = "$field.label";
1539
        echo "
1540
            <div $restrict class='wpinv-payment-form-field-preview'>
1541
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1542
                <label :for='$field.id'>{{" . $label . "}}</label>
1543
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'>
1544
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1545
            </div>    
1546
        ";
1547
    }
1548
1549
    /**
1550
     * Renders the time element on the frontend.
1551
     */
1552
    public function frontend_render_time_template( $field ) {
1553
        
1554
        echo "<div class='form-group'>";
1555
1556
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1556
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1557
            array(
1558
                'name'       => esc_attr( $field['id'] ),
1559
                'id'         => esc_attr( $field['id'] ),
1560
                'required'   => (bool) $field['required'],
1561
                'label'      => wp_kses_post( $field['label'] ),
1562
                'no_wrap'    => true,
1563
                'type'       => 'time',
1564
            )
1565
        );
1566
1567
        if ( ! empty( $field['description'] ) ) {
1568
            $description = wp_kses_post( $field['description'] );
1569
            echo "<small class='form-text text-muted'>$description</small>";
1570
        }
1571
1572
        echo '</div>';
1573
1574
    }
1575
1576
    /**
1577
     * Renders the edit time element template.
1578
     */
1579
    public function edit_time_template( $field ) {
1580
        $restrict = $this->get_restrict_markup( $field, 'time' );
1581
        $label    = __( 'Field Label', 'invoicing' );
1582
        $id       = $field . '.id + "_edit"';
1583
        $label3   = __( 'Help text', 'invoicing' );
1584
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1585
        $id3      = $field . '.id + "_edit3"';
1586
        $label5   = __( 'Is this field required?', 'invoicing' );
1587
        $id4      = $field . '.id + "_edit4"';
1588
        echo "
1589
            <div $restrict>
1590
                <div class='form-group'>
1591
                    <label :for='$id'>$label</label>
1592
                    <input :id='$id' v-model='$field.label' class='form-control' />
1593
                </div>
1594
                <div class='form-group'>
1595
                    <label :for='$id3'>$label3</label>
1596
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1597
                </div>
1598
                <div class='form-group form-check'>
1599
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1600
                    <label class='form-check-label' :for='$id4'>$label5</label>
1601
                </div>
1602
            </div>
1603
        ";
1604
1605
    }
1606
1607
    /**
1608
     * Renders the number element template.
1609
     */
1610
    public function render_number_template( $field ) {
1611
        $restrict = $this->get_restrict_markup( $field, 'number' );
1612
        $label    = "$field.label";
1613
        echo "
1614
            <div $restrict class='wpinv-payment-form-field-preview'>
1615
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1616
                <label :for='$field.id'>{{" . $label . "}}</label>
1617
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'>
1618
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1619
            </div>    
1620
        ";
1621
    }
1622
1623
    /**
1624
     * Renders the number element on the frontend.
1625
     */
1626
    public function frontend_render_number_template( $field ) {
1627
        
1628
        echo "<div class='form-group'>";
1629
1630
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1630
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1631
            array(
1632
                'name'       => esc_attr( $field['id'] ),
1633
                'id'         => esc_attr( $field['id'] ),
1634
                'required'   => (bool) $field['required'],
1635
                'label'      => wp_kses_post( $field['label'] ),
1636
                'placeholder' => esc_attr( $field['placeholder'] ),
1637
                'no_wrap'    => true,
1638
                'type'       => 'number',
1639
            )
1640
        );
1641
1642
        if ( ! empty( $field['description'] ) ) {
1643
            $description = wp_kses_post( $field['description'] );
1644
            echo "<small class='form-text text-muted'>$description</small>";
1645
        }
1646
1647
        echo '</div>';
1648
1649
    }
1650
1651
    /**
1652
     * Renders the edit number element template.
1653
     */
1654
    public function edit_number_template( $field ) {
1655
        $restrict = $this->get_restrict_markup( $field, 'number' );
1656
        $label    = __( 'Field Label', 'invoicing' );
1657
        $id       = $field . '.id + "_edit"';
1658
        $label2   = __( 'Placeholder text', 'invoicing' );
1659
        $id2      = $field . '.id + "_edit2"';
1660
        $label3   = __( 'Help text', 'invoicing' );
1661
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1662
        $id3      = $field . '.id + "_edit3"';
1663
        $label5   = __( 'Is this field required?', 'invoicing' );
1664
        $id4      = $field . '.id + "_edit4"';
1665
        echo "
1666
            <div $restrict>
1667
                <div class='form-group'>
1668
                    <label :for='$id'>$label</label>
1669
                    <input :id='$id' v-model='$field.label' class='form-control' />
1670
                </div>
1671
                <div class='form-group'>
1672
                    <label :for='$id2'>$label2</label>
1673
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1674
                </div>
1675
                <div class='form-group'>
1676
                    <label :for='$id3'>$label3</label>
1677
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1678
                </div>
1679
                <div class='form-group form-check'>
1680
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1681
                    <label class='form-check-label' :for='$id4'>$label5</label>
1682
                </div>
1683
            </div>
1684
        ";
1685
1686
    }
1687
1688
    /**
1689
     * Renders the separator element template.
1690
     */
1691
    public function render_separator_template( $field ) {
1692
        $restrict = $this->get_restrict_markup( $field, 'separator' );
1693
        echo "<hr class='featurette-divider mt-0 mb-2' $restrict>";
1694
    }
1695
1696
    /**
1697
     * Renders the separator element on the frontend.
1698
     */
1699
    public function frontend_render_separator_template( $field ) {
1700
        echo '<hr class="featurette-divider mt-0 mb-2" />';
1701
    }
1702
1703
    /**
1704
     * Renders the pay button element template.
1705
     */
1706
    public function render_pay_button_template( $field ) {
1707
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1708
        $label    = "$field.label";
1709
        echo "
1710
            <div $restrict>
1711
                <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button>
1712
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1713
            </div>    
1714
        ";
1715
    }
1716
1717
    /**
1718
     * Renders the pay_button element on the frontend.
1719
     */
1720
    public function frontend_render_pay_button_template( $field ) {
1721
1722
        echo "<div class='mt-4 mb-4'>";
1723
            do_action( 'wpinv_payment_mode_select' );
1724
        echo "</div>";
1725
1726
        echo "<div class='form-group'>";
1727
1728
        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1729
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1729
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1730
            array(
1731
                'name'       => esc_attr( $field['id'] ),
1732
                'id'         => esc_attr( $field['id'] ),
1733
                'value'      => esc_attr( $field['label'] ),
1734
                'no_wrap'    => true,
1735
                'type'       => 'submit',
1736
                'class'      => $class,
1737
            )
1738
        );
1739
1740
        if ( ! empty( $field['description'] ) ) {
1741
            $description = wp_kses_post( $field['description'] );
1742
            echo "<small class='form-text text-muted'>$description</small>";
1743
        }
1744
1745
        echo '</div>';
1746
1747
    }
1748
1749
    /**
1750
     * Renders the pay button element template.
1751
     */
1752
    public function edit_pay_button_template( $field ) {
1753
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1754
        $label    = __( 'Button Text', 'invoicing' );
1755
        $id       = $field . '.id + "_edit"';
1756
        $label2   = __( 'Help text', 'invoicing' );
1757
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1758
        $id2      = $field . '.id + "_edit2"';
1759
        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1760
        $id3      = $field . '.id + "_edit3"';
1761
        echo "
1762
            <div $restrict>
1763
                <div class='form-group'>
1764
                    <label :for='$id'>$label</label>
1765
                    <input :id='$id' v-model='$field.label' class='form-control' />
1766
                </div>
1767
                <div class='form-group'>
1768
                    <label :for='$id2'>$label2</label>
1769
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
1770
                </div>
1771
                <div class='form-group'>
1772
                    <label :for='$id3'>$label4</label>
1773
1774
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1775
                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1776
                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1777
                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1778
                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1779
                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1780
                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1781
                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1782
                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1783
                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1784
                    </select>
1785
                </div>
1786
            </div>
1787
        ";
1788
1789
    }
1790
1791
    /**
1792
     * Renders the alert element template.
1793
     */
1794
    public function render_alert_template( $field ) {
1795
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1796
        $text     = "$field.text";
1797
        echo "
1798
            <div $restrict class='alert' :class='$field.class' role='alert'>
1799
                <span v-html='$text'></span>
1800
                <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''>
1801
                    <span aria-hidden='true'>&times;</span>
1802
                </button>
1803
            </div>    
1804
        ";
1805
    }
1806
1807
    /**
1808
     * Renders the alert element on the frontend.
1809
     */
1810
    public function frontend_render_alert_template( $field ) {
1811
        
1812
        echo "<div class='form-group'>";
1813
1814
        echo aui()->alert(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1814
        echo /** @scrutinizer ignore-call */ aui()->alert(
Loading history...
1815
            array(
1816
                'content'     => wp_kses_post( $field['text'] ),
1817
                'dismissible' => $field['dismissible'],
1818
                'type'        => str_replace( 'alert-', '', $field['class'] ),
1819
            )
1820
        );
1821
1822
        echo '</div>';
1823
1824
    }
1825
1826
    /**
1827
     * Renders the alert element template.
1828
     */
1829
    public function edit_alert_template( $field ) {
1830
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1831
        $label    = __( 'Alert Text', 'invoicing' );
1832
        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1833
        $id       = $field . '.id + "_edit"';
1834
        $label3   = __( 'Is Dismissible?', 'invoicing' );
1835
        $id2      = $field . '.id + "_edit2"';
1836
        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1837
        $id3      = $field . '.id + "_edit3"';
1838
        echo "
1839
            <div $restrict>
1840
                <div class='form-group'>
1841
                    <label :for='$id'>$label</label>
1842
                    <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
1843
                </div>
1844
                <div class='form-group form-check'>
1845
                    <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' />
1846
                    <label class='form-check-label' :for='$id2'>$label3</label>
1847
                </div>
1848
                <div class='form-group'>
1849
                    <label :for='$id3'>$label4</label>
1850
1851
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1852
                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1853
                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1854
                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1855
                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1856
                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1857
                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1858
                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1859
                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1860
                    </select>
1861
                </div>
1862
            </div>
1863
        ";
1864
1865
    }
1866
1867
    /**
1868
     * Renders the discount element template.
1869
     */
1870
    public function render_discount_template( $field ) {
1871
        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1872
        ?>
1873
1874
            <div <?php echo $restrict; ?> class="discount_field  border rounded p-3">
1875
                <div class="discount_field_inner d-flex flex-column flex-md-row">
1876
                    <input  :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1877
                    <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button>
1878
                </div>
1879
                <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small>
1880
            </div>
1881
1882
        <?php
1883
    }
1884
1885
    /**
1886
     * Renders the discount element on the frontend.
1887
     */
1888
    public function frontend_render_discount_template( $field ) {
1889
        
1890
        $placeholder = esc_attr( $field['input_label'] );
1891
        $label       = sanitize_text_field( $field['button_label'] );
1892
        $description = '';
1893
1894
        if ( ! empty( $field['description'] ) ) {
1895
            $description = "<small class='form-text text-muted'>{$field['description']}</small>";
1896
        }
1897
?>
1898
1899
    <div class="form-group">
1900
        <div class="discount_field  border rounded p-3">
1901
            <div class="discount_field_inner d-flex flex-column flex-md-row">
1902
                <input  placeholder="<?php echo $placeholder; ?>" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1903
                <a href="#" class="btn btn-secondary submit-button mb-2 wpinv-payment-form-coupon-button"><?php echo $label; ?></a>
1904
            </div>
1905
            <?php echo $description ?>
1906
        </div>
1907
    </div>
1908
1909
<?php
1910
    }
1911
1912
    /**
1913
     * Renders the discount element template.
1914
     */
1915
    public function edit_discount_template( $field ) {
1916
        $restrict = $this->get_restrict_markup( $field, 'discount' );
1917
        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1918
        $label2   = __( 'Help Text', 'invoicing' );
1919
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1920
        $label4   = __( 'Button Text', 'invoicing' );
1921
        $id       = $field . '.id + "_edit"';
1922
        $id2      = $field . '.id + "_edit2"';
1923
        $id3      = $field . '.id + "_edit3"';
1924
        echo "
1925
            <div $restrict>
1926
                <div class='form-group'>
1927
                    <label :for='$id'>$label</label>
1928
                    <input :id='$id' v-model='$field.input_label' class='form-control' />
1929
                </div>
1930
1931
                <div class='form-group'>
1932
                    <label :for='$id2'>$label4</label>
1933
                    <input :id='$id2' v-model='$field.button_label' class='form-control' />
1934
                </div>
1935
1936
                <div class='form-group'>
1937
                    <label :for='$id3'>$label2</label>
1938
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1939
                </div>
1940
1941
            </div>
1942
        ";
1943
1944
    }
1945
1946
    /**
1947
     * Renders the items element template.
1948
     */
1949
    public function render_items_template( $field ) {
1950
        $restrict  = $this->get_restrict_markup( $field, 'items' );
1951
        $label     = __( 'Item totals will appear here. Click to set items.', 'invoicing' );
1952
        $label2    = __( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' );
1953
        $label2   .= ' ' . __( 'To prevent this, limit customers to selecting a single item.', 'invoicing' );
1954
        $label3    = __( 'Item totals will appear here.', 'invoicing' );
1955
        echo "
1956
            <div $restrict class='item_totals text-center'>
1957
                <div v-if='!is_default'>
1958
                    <div v-if='canCheckoutSeveralSubscriptions($field)' class='p-4 bg-danger text-light'>$label2</div>
1959
                    <div v-if='! canCheckoutSeveralSubscriptions($field)' class='p-4 bg-warning'>$label</div>
1960
                </div>
1961
                <div v-if='is_default'>
1962
                    <div class='p-4 bg-warning'>$label3</div>
1963
                </div>
1964
            </div>
1965
        ";
1966
    }
1967
1968
    /**
1969
     * Renders the items element on the frontend.
1970
     */
1971
    public function frontend_render_items_template( $field, $items ) {
1972
1973
        echo "<div class='form-group item_totals'>";
1974
        
1975
        $id = esc_attr( $field['id'] );
1976
1977
        if ( empty( $field[ 'items_type' ] ) ) {
1978
            $field[ 'items_type' ] = 'total';
1979
        }
1980
1981
        if ( 'total' == $field[ 'items_type' ] ) {
1982
            $total     = 0;
1983
            $tax       = 0;
1984
            $sub_total = 0;
1985
1986
            ?>
1987
            <div class="border item_totals_type_total">
1988
1989
                <?php
1990
                    foreach( $items as $item ) {
1991
1992
                        $amount = floatval( $item['price'] );
1993
1994
                        if ( wpinv_use_taxes() ) {
1995
1996
                            $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1997
1998
                            if ( wpinv_prices_include_tax() ) {
1999
                                $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2000
                                $item_tax = $amount - $pre_tax;
2001
                            } else {
2002
                                $pre_tax  = $amount;
2003
                                $item_tax = $amount * $rate * 0.01;
2004
                            }
2005
2006
                            $tax       = $tax + $item_tax;
2007
                            $sub_total = $sub_total + $pre_tax;
2008
                            $total     = $sub_total + $tax;
2009
2010
                        } else {
2011
                            $total  = $total + $amount;
2012
                        }
2013
2014
                        $class  = 'col-8';
2015
                        $class2 = '';
2016
2017
                        if ( ! empty( $item['allow_quantities'] ) ) {
2018
                            $class = 'col-6 pt-2';
2019
                            $class2 = 'pt-2';
2020
                        }
2021
2022
                        if ( ! empty( $item['custom_price'] ) ) {
2023
                            $class .= ' pt-2';
2024
                        }
2025
2026
                        $quantity = 1;
2027
                        if ( ! empty( $item['quantity'] ) ) {
2028
                            $quantity = absint( $item['quantity'] );
2029
                        }
2030
            
2031
                ?>
2032
                    <div  class="item_totals_item">
2033
                        <div class='row pl-2 pr-2 pt-2'>
2034
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2035
2036
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2037
2038
                                <div class='col-2'>
2039
                                    <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='<?php echo $quantity ?>' min='1' required>
2040
                                </div>
2041
2042
                            <?php } else { ?>
2043
                                <input type='hidden' class='wpinv-item-quantity-input' value='<?php echo $quantity ?>'>
2044
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2045
2046
                                <div class='col-4 <?php echo $class2; ?>'>
2047
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2048
                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2049
                                </div>
2050
2051
                            <?php } else {?>
2052
2053
                                <div class='col-4'>
2054
                                    <div class='input-group'>
2055
2056
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2057
                                            <div class='input-group-prepend'>
2058
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2059
                                            </div>
2060
                                        <?php } ?>
2061
2062
                                        <input type='number' name='wpinv-items[<?php echo (int) $item['id']; ?>]' 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'] ); ?>'>
2063
                                    
2064
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2065
                                            <div class='input-group-append'>
2066
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2067
                                            </div>
2068
                                        <?php } ?>
2069
2070
                                    </div>
2071
                                </div>
2072
                            <?php } ?>
2073
2074
                        </div>
2075
                        <?php if ( ! empty( $item['description'] )) { ?>
2076
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2077
                        <?php } ?>
2078
                    </div>
2079
                <?php } ?>
2080
2081
                <div class='mt-4 border-top item_totals_total p-2'>
2082
2083
                    <?php if ( wpinv_use_taxes() ) { ?>
2084
                        <div class='row'>
2085
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2086
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2087
                        </div>
2088
                        <div class='row'>
2089
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2090
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2091
                        </div>
2092
                    <?php } ?>
2093
2094
                    <div class='row'>
2095
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2096
                        <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>
2097
                    </div>
2098
2099
                </div>
2100
2101
            </div>
2102
        <?php } ?>
2103
2104
        <?php if ( 'radio' == $field[ 'items_type' ] ) { ?>
2105
            <div class="item_totals_type_radio">
2106
2107
                <?php
2108
                    foreach( $items as $index => $item ) {
2109
2110
                        if ( ! empty( $item['required'] ) ) {
2111
                            continue;
2112
                        }
2113
                ?>
2114
                    <div  class="form-check">
2115
                        <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'>
2116
                        <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>
2117
                    </div>
2118
                    <?php if ( ! empty( $item['description'] )) { ?>
2119
                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2120
                    <?php } ?>
2121
                <?php } ?>
2122
2123
                <div class="mt-3 border item_totals_type_radio_totals">
2124
2125
                    <?php
2126
2127
                        $total     = 0;
2128
                        $tax       = 0;
2129
                        $sub_total = 0;
2130
2131
                        foreach ( $items as $item ) {
2132
2133
                            $class  = 'col-8';
2134
                            $class2 = '';
2135
2136
                            if ( ! empty( $item['allow_quantities'] ) ) {
2137
                                $class = 'col-6 pt-2';
2138
                                $class2 = 'pt-2';
2139
                            }
2140
2141
                            if ( ! empty( $item['custom_price'] ) ) {
2142
                                $class .= ' pt-2';
2143
                            }
2144
2145
                            $class3 = 'd-none';
2146
                            $name   = '';
2147
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) {
2148
2149
                                $amount = floatval( $item['price'] );
2150
2151
                                if ( wpinv_use_taxes() ) {
2152
2153
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2154
2155
                                    if ( wpinv_prices_include_tax() ) {
2156
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2157
                                        $item_tax = $amount - $pre_tax;
2158
                                    } else {
2159
                                        $pre_tax  = $amount;
2160
                                        $item_tax = $amount * $rate * 0.01;
2161
                                    }
2162
2163
                                    $tax       = $tax + $item_tax;
2164
                                    $sub_total = $sub_total + $pre_tax;
2165
                                    $total     = $sub_total + $tax;
2166
2167
                                } else {
2168
                                    $total  = $total + $amount;
2169
                                }
2170
2171
                                $class3 = '';
2172
                                $name   = "wpinv-items[{$item['id']}]";
2173
2174
                                if ( empty( $item['required'] ) ) {
2175
                                    $totals_selected_radio_item = 1;
2176
                                }
2177
2178
                            }
2179
2180
                            $class3 .= " wpinv_item_{$item['id']}";
2181
2182
                    ?>
2183
2184
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2185
                        <div class='row pl-2 pr-2 pt-2'>
2186
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2187
2188
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2189
2190
                                <div class='col-2'>
2191
                                    <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>
2192
                                </div>
2193
2194
                            <?php } else { ?>
2195
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2196
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2197
2198
                                <div class='col-4 <?php echo $class2; ?>'>
2199
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2200
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2201
                                </div>
2202
2203
                            <?php } else {?>
2204
2205
                                <div class='col-4'>
2206
                                    <div class='input-group'>
2207
2208
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2209
                                            <div class='input-group-prepend'>
2210
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2211
                                            </div>
2212
                                        <?php } ?>
2213
2214
                                        <input type='number' 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'] ); ?>'>
2215
                                    
2216
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2217
                                            <div class='input-group-append'>
2218
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2219
                                            </div>
2220
                                        <?php } ?>
2221
2222
                                    </div>
2223
                                </div>
2224
                            <?php } ?>
2225
2226
                        </div>
2227
                        <?php if ( ! empty( $item['description'] )) { ?>
2228
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2229
                        <?php } ?>
2230
                    </div>
2231
                <?php } ?>
2232
2233
                <div class='mt-4 border-top item_totals_total p-2'>
2234
                    <?php if ( wpinv_use_taxes() ) { ?>
2235
                        <div class='row'>
2236
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2237
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2238
                        </div>
2239
                        <div class='row'>
2240
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2241
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2242
                        </div>
2243
                    <?php } ?>
2244
2245
                    <div class='row'>
2246
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2247
                        <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>
2248
                    </div>
2249
                </div>
2250
2251
            </div>
2252
            </div>
2253
        <?php } ?>
2254
2255
        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
2256
2257
            <div class="item_totals_type_checkbox">
2258
2259
                <?php
2260
                    foreach ( $items as $index => $item ) {
2261
2262
                        if ( ! empty( $item['required'] ) ) {
2263
                            continue;
2264
                        }
2265
2266
                        $title = sanitize_text_field(  $item['title'] );
2267
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2268
                        $item_id    = esc_attr( $id . "_$index" );
2269
                        $value = esc_attr( $item['id'] );
2270
                        $checked = checked( ! isset( $selected_checkbox_item ), true, false );
2271
                        $selected_checkbox_item = 1;
2272
2273
                        echo "
2274
                            <div class='custom-control custom-checkbox'>
2275
                                <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>
2276
                                <label for='$item_id' class='custom-control-label'>$title &nbsp; ($price)</label>
2277
                            </div>";
2278
2279
                        if ( ! empty( $item['description'] ) ) {
2280
                            echo "<small class='form-text text-muted'>{$item['description']}</small>";
2281
                        }
2282
                    }
2283
                ?>
2284
2285
                <div class="mt-3 border item_totals_type_checkbox_totals">
2286
2287
                    <?php
2288
2289
                        $total     = 0;
2290
                        $tax       = 0;
2291
                        $sub_total = 0;
2292
2293
                        foreach ( $items as $item ) {
2294
2295
                            $class  = 'col-8';
2296
                            $class2 = '';
2297
2298
                            if ( ! empty( $item['allow_quantities'] ) ) {
2299
                                $class = 'col-6 pt-2';
2300
                                $class2 = 'pt-2';
2301
                            }
2302
2303
                            if ( ! empty( $item['custom_price'] ) ) {
2304
                                $class .= ' pt-2';
2305
                            }
2306
2307
                            $class3 = 'd-none';
2308
                            $name  = '';
2309
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) {
2310
2311
                                $amount = floatval( $item['price'] );
2312
                                if ( wpinv_use_taxes() ) {
2313
2314
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2315
2316
                                    if ( wpinv_prices_include_tax() ) {
2317
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2318
                                        $item_tax = $amount - $pre_tax;
2319
                                    } else {
2320
                                        $pre_tax  = $amount;
2321
                                        $item_tax = $amount * $rate * 0.01;
2322
                                    }
2323
2324
                                    $tax       = $tax + $item_tax;
2325
                                    $sub_total = $sub_total + $pre_tax;
2326
                                    $total     = $sub_total + $tax;
2327
2328
                                } else {
2329
                                    $total  = $total + $amount;
2330
                                }
2331
2332
                                $class3 = '';
2333
                                $name  = "wpinv-items[{$item['id']}]";
2334
2335
                                if ( empty( $item['required'] ) ) {
2336
                                    $totals_selected_checkbox_item = 1;
2337
                                }
2338
2339
                            }
2340
2341
                            $class3 .= " wpinv_item_{$item['id']}";
2342
2343
                    ?>
2344
2345
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2346
                        <div class='row pl-2 pr-2 pt-2'>
2347
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2348
2349
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2350
2351
                                <div class='col-2'>
2352
                                    <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>
2353
                                </div>
2354
2355
                            <?php } else { ?>
2356
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2357
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2358
2359
                                <div class='col-4 <?php echo $class2; ?>'>
2360
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2361
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2362
                                </div>
2363
2364
                            <?php } else {?>
2365
2366
                                <div class='col-4'>
2367
                                    <div class='input-group'>
2368
2369
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2370
                                            <div class='input-group-prepend'>
2371
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2372
                                            </div>
2373
                                        <?php } ?>
2374
2375
                                        <input type='number' 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'] ); ?>'>
2376
                                    
2377
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2378
                                            <div class='input-group-append'>
2379
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2380
                                            </div>
2381
                                        <?php } ?>
2382
2383
                                    </div>
2384
                                </div>
2385
                            <?php } ?>
2386
2387
                        </div>
2388
                        <?php if ( ! empty( $item['description'] )) { ?>
2389
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2390
                        <?php } ?>
2391
                    </div>
2392
                <?php } ?>
2393
2394
                <div class='mt-4 border-top item_totals_total p-2'>
2395
2396
                    <?php if ( wpinv_use_taxes() ) { ?>
2397
                        <div class='row'>
2398
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2399
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2400
                        </div>
2401
                        <div class='row'>
2402
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2403
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2404
                        </div>
2405
                    <?php } ?>
2406
2407
                    <div class='row'>
2408
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2409
                        <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>
2410
                    </div>
2411
                </div>
2412
            </div>
2413
            </div>
2414
        <?php } ?>
2415
2416
        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
2417
2418
            <div class="item_totals_type_select">
2419
2420
                <?php
2421
2422
                    $options  = array();
2423
                    $selected = '';
2424
                    foreach ( $items as $index => $item ) {
2425
2426
                        if ( ! empty( $item['required'] ) ) {
2427
                            continue;
2428
                        }
2429
2430
                        $title = sanitize_text_field(  $item['title'] );
2431
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2432
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2433
2434
                        if ( ! isset( $selected_item ) ) {
2435
                            $selected = $item['id'];
2436
                            $selected_item = 1;
2437
                        }
2438
                        
2439
                    }
2440
2441
                    echo aui()->select(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2441
                    echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
2442
                        array(
2443
                                'name'        => 'payment-form-items',
2444
                                'id'          => $id,
2445
                                'placeholder' => __( 'Select an item', 'invoicing' ),
2446
                                'no_wrap'     => true,
2447
                                'options'     => $options,
2448
                                'class'       => 'wpi_select2 wpinv-items-select-selector',
2449
                                'value'       => $selected,
2450
                        )
2451
                    );
2452
                ?>
2453
2454
                <div class="mt-3 border item_totals_type_select_totals">
2455
2456
                    <?php
2457
2458
                        $total     = 0;
2459
                        $tax       = 0;
2460
                        $sub_total = 0;
2461
2462
                        foreach ( $items as $item ) {
2463
2464
                            $class  = 'col-8';
2465
                            $class2 = '';
2466
2467
                            if ( ! empty( $item['allow_quantities'] ) ) {
2468
                                $class = 'col-6 pt-2';
2469
                                $class2 = 'pt-2';
2470
                            }
2471
2472
                            if ( ! empty( $item['custom_price'] ) ) {
2473
                                $class .= ' pt-2';
2474
                            }
2475
2476
                            $class3 = 'd-none';
2477
                            $name  = '';
2478
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2479
2480
                                $amount = floatval( $item['price'] );
2481
                                if ( wpinv_use_taxes() ) {
2482
2483
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2484
2485
                                    if ( wpinv_prices_include_tax() ) {
2486
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2487
                                        $item_tax = $amount - $pre_tax;
2488
                                    } else {
2489
                                        $pre_tax  = $amount;
2490
                                        $item_tax = $amount * $rate * 0.01;
2491
                                    }
2492
2493
                                    $tax       = $tax + $item_tax;
2494
                                    $sub_total = $sub_total + $pre_tax;
2495
                                    $total     = $sub_total + $tax;
2496
2497
                                } else {
2498
                                    $total  = $total + $amount;
2499
                                }
2500
2501
                                $class3 = '';
2502
                                $name  = "wpinv-items[{$item['id']}]";
2503
2504
                                if ( empty( $item['required'] ) ) {
2505
                                    $totals_selected_select_item = 1;
2506
                                }
2507
2508
                            }
2509
2510
                            $class3 .= " wpinv_item_{$item['id']}";
2511
2512
                    ?>
2513
2514
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2515
                        <div class='row pl-2 pr-2 pt-2'>
2516
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2517
2518
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2519
2520
                                <div class='col-2'>
2521
                                    <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>
2522
                                </div>
2523
2524
                            <?php } else { ?>
2525
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2526
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2527
2528
                                <div class='col-4 <?php echo $class2; ?>'>
2529
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2530
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2531
                                </div>
2532
2533
                            <?php } else {?>
2534
2535
                                <div class='col-4'>
2536
                                    <div class='input-group'>
2537
2538
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2539
                                            <div class='input-group-prepend'>
2540
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2541
                                            </div>
2542
                                        <?php } ?>
2543
2544
                                        <input type='number' 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'] ); ?>'>
2545
                                    
2546
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2547
                                            <div class='input-group-append'>
2548
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2549
                                            </div>
2550
                                        <?php } ?>
2551
2552
                                    </div>
2553
                                </div>
2554
                            <?php } ?>
2555
2556
                        </div>
2557
                        <?php if ( ! empty( $item['description'] )) { ?>
2558
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2559
                        <?php } ?>
2560
                    </div>
2561
                <?php } ?>
2562
2563
                <div class='mt-4 border-top item_totals_total p-2'>
2564
2565
                    <?php if ( wpinv_use_taxes() ) { ?>
2566
                        <div class='row'>
2567
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2568
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2569
                        </div>
2570
                        <div class='row'>
2571
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2572
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2573
                        </div>
2574
                    <?php } ?>
2575
                    <div class='row'>
2576
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2577
                        <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>
2578
                    </div>
2579
                </div>
2580
2581
            </div>
2582
        <?php } ?>
2583
2584
        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
2585
2586
            <div class="item_totals_type_multi_select">
2587
2588
                <?php
2589
2590
                    $options  = array();
2591
                    $selected = array();
2592
2593
                    foreach ( $items as $index => $item ) {
2594
2595
                        if ( ! empty( $item['required'] ) ) {
2596
                            continue;
2597
                        }
2598
2599
                        $title = sanitize_text_field(  $item['title'] );
2600
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2601
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2602
2603
                        if ( ! isset( $selected_item ) ) {
2604
                            $selected = array( $item['id'] );
2605
                            $selected_item = 1;
2606
                        }
2607
2608
                    }
2609
2610
                    echo aui()->select(
2611
                        array(
2612
                                'name'        => 'payment-form-items',
2613
                                'id'          => $id,
2614
                                'no_wrap'     => true,
2615
                                'options'     => $options,
2616
                                'multiple'    => true,
2617
                                'class'       => 'wpi_select2 wpinv-items-multiselect-selector',
2618
                                'value'       => $selected,
2619
                        )
2620
                    );
2621
                ?>
2622
2623
                <div class="mt-3 border item_totals_type_select_totals">
2624
2625
                    <?php
2626
2627
                        $total     = 0;
2628
                        $tax       = 0;
2629
                        $sub_total = 0;
2630
2631
                        foreach ( $items as $item ) {
2632
2633
                            $class  = 'col-8';
2634
                            $class2 = '';
2635
2636
                            if ( ! empty( $item['allow_quantities'] ) ) {
2637
                                $class = 'col-6 pt-2';
2638
                                $class2 = 'pt-2';
2639
                            }
2640
2641
                            if ( ! empty( $item['custom_price'] ) ) {
2642
                                $class .= ' pt-2';
2643
                            }
2644
2645
                            $class3 = 'd-none';
2646
                            $name  = '';
2647
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2648
2649
                                $amount = floatval( $item['price'] );
2650
                                if ( wpinv_use_taxes() ) {
2651
2652
                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2653
2654
                                    if ( wpinv_prices_include_tax() ) {
2655
                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2656
                                        $item_tax = $amount - $pre_tax;
2657
                                    } else {
2658
                                        $pre_tax  = $amount;
2659
                                        $item_tax = $amount * $rate * 0.01;
2660
                                    }
2661
2662
                                    $tax       = $tax + $item_tax;
2663
                                    $sub_total = $sub_total + $pre_tax;
2664
                                    $total     = $sub_total + $tax;
2665
2666
                                } else {
2667
                                    $total  = $total + $amount;
2668
                                }
2669
2670
                                $class3 = '';
2671
                                $name  = "wpinv-items[{$item['id']}]";
2672
2673
                                if ( empty( $item['required'] ) ) {
2674
                                    $totals_selected_select_item = 1;
2675
                                }
2676
2677
                            }
2678
2679
                            $class3 .= " wpinv_item_{$item['id']}";
2680
2681
                    ?>
2682
2683
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2684
                        <div class='row pl-2 pr-2 pt-2'>
2685
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2686
2687
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2688
2689
                                <div class='col-2'>
2690
                                    <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>
2691
                                </div>
2692
2693
                            <?php } else { ?>
2694
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2695
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2696
2697
                                <div class='col-4 <?php echo $class2; ?>'>
2698
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2699
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2700
                                </div>
2701
2702
                            <?php } else {?>
2703
2704
                                <div class='col-4'>
2705
                                    <div class='input-group'>
2706
2707
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2708
                                            <div class='input-group-prepend'>
2709
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2710
                                            </div>
2711
                                        <?php } ?>
2712
2713
                                        <input type='number' 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'] ); ?>'>
2714
                                    
2715
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2716
                                            <div class='input-group-append'>
2717
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2718
                                            </div>
2719
                                        <?php } ?>
2720
2721
                                    </div>
2722
                                </div>
2723
                            <?php } ?>
2724
2725
                        </div>
2726
                        <?php if ( ! empty( $item['description'] )) { ?>
2727
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2728
                        <?php } ?>
2729
                    </div>
2730
                <?php } ?>
2731
2732
                <div class='mt-4 border-top item_totals_total p-2'>
2733
2734
                    <?php if ( wpinv_use_taxes() ) { ?>
2735
                        <div class='row'>
2736
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2737
                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2738
                        </div>
2739
                        <div class='row'>
2740
                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2741
                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2742
                        </div>
2743
                    <?php } ?>
2744
2745
                    <div class='row'>
2746
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2747
                        <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>
2748
                    </div>
2749
                </div>
2750
2751
            </div>
2752
        <?php } ?>
2753
        <?php if ( ! empty( $field[ 'description' ] ) ) { ?>
2754
            <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small>
2755
        <?php } ?>
2756
        </div>
2757
        <?php
2758
    }
2759
2760
    /**
2761
     * Renders the items element template.
2762
     */
2763
    public function edit_items_template( $field ) {
2764
        global $wpinv_euvat, $post;
2765
2766
        $restrict = $this->get_restrict_markup( $field, 'items' );
2767
        $label    = __( 'Let customers...', 'invoicing' );
2768
        $label2   = __( 'Available Items', 'invoicing' );
2769
        $label3   = esc_attr__( 'Add some help text for this element', 'invoicing' );
2770
        $id       = $field . '.id + "_edit"';
2771
        $id2      = $field . '.id + "_edit2"';
2772
        $id3      = $field . '.id + "_edit3"';
2773
        $id4      = $field . '.id + "_edit4"';
2774
        $label4   = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' );
2775
        $label5   = esc_attr__( 'Allow users to pay what they want', 'invoicing' );
2776
        $label6   = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' );
2777
        $label7   = esc_attr__( 'Allow users to buy several quantities', 'invoicing' );
2778
        $label8   = esc_attr__( 'This item is required', 'invoicing' );
2779
2780
        // Item types.
2781
        $item_types      = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
2782
        $item_types_html = '';
2783
2784
        foreach ( $item_types as $type => $_label ) {
2785
            $type  = esc_attr( $type );
2786
            $_label = esc_html( $_label );
2787
            $item_types_html .= "<option value='$type'>$_label</type>";
2788
        }
2789
2790
        // Taxes.
2791
        $taxes = '';
2792
        if ( $wpinv_euvat->allow_vat_rules() ) {
2793
            $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"rule\"'>";
2794
            $taxes .= __( 'VAT rule type', 'invoicing' );
2795
            $taxes .= "</label><select :id='$id + item.id + \"rule\"' class='form-control custom-select' v-model='item.rule'>";
2796
2797
            foreach ( $wpinv_euvat->get_rules() as $type => $_label ) {
2798
                $type    = esc_attr( $type );
2799
                $_label  = esc_html( $_label );
2800
                $taxes  .= "<option value='$type'>$_label</type>";
2801
            }
2802
2803
            $taxes .= '</select></div>';
2804
        }
2805
2806
        if ( $wpinv_euvat->allow_vat_classes() ) {
2807
            $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"class\"'>";
2808
            $taxes .= __( 'VAT class', 'invoicing' );
2809
            $taxes .= "</label><select :id='$id + item.id + \"class\"' class='form-control custom-select' v-model='item.class'>";
2810
2811
            foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) {
2812
                $type    = esc_attr( $type );
2813
                $_label  = esc_html( $_label );
2814
                $taxes  .= "<option value='$type'>$_label</type>";
2815
            }
2816
2817
            $taxes .= '</select></div>';
2818
        }
2819
2820
        echo "<div $restrict>
2821
2822
                <label v-if='!is_default'>$label2</label>
2823
2824
                <draggable v-model='form_items' group='selectable_form_items'>
2825
                    <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class='\"item_\" + item.id' :key='item.id'>
2826
2827
                        <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'>
2828
                            <span class='label'>{{item.title}}</span>
2829
                            <span class='price'>({{formatPrice(item.price)}})</span>
2830
                            <span class='toggle-icon'>
2831
                                <span class='dashicons dashicons-arrow-down'></span>
2832
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
2833
                            </span>
2834
                        </div>
2835
2836
                        <div class='wpinv-available-items-editor-body'>
2837
                            <div class='p-2'>
2838
2839
                                <div class='form-group'>
2840
                                    <label :for='$id + item.id'>Item Name</label>
2841
                                    <input :id='$id + item.id' v-model='item.title' class='form-control' />
2842
                                </div>
2843
2844
                                <div class='form-group'>
2845
                                    <label :for='$id + item.id + \"price\"'>Item Price</label>
2846
                                    <input :id='$id + item.id + \"price\"' v-model='item.price' class='form-control' />
2847
                                    <small class='form-text text-muted' v-if='item.custom_price'>$label4</small>
2848
                                </div>
2849
2850
                                <div class='form-group' v-if='item.new'>
2851
                                    <label :for='$id + item.id + \"type\"'>Item Type</label>
2852
                                    <select class='form-control custom-select' v-model='item.type'>
2853
                                        $item_types_html
2854
                                    </select>
2855
                                </div>
2856
2857
                                <div v-if='item.new'>$taxes</div>
2858
2859
                                <div class='form-group form-check'>
2860
                                    <input :id='$id4 + item.id + \"custom_price\"' v-model='item.custom_price' type='checkbox' class='form-check-input' />
2861
                                    <label class='form-check-label' :for='$id4 + item.id + \"custom_price\"'>$label5</label>
2862
                                </div>
2863
2864
                                <div class='form-group' v-if='item.custom_price'>
2865
                                    <label :for='$id + item.id + \"minimum_price\"'>Minimum Price</label>
2866
                                    <input :id='$id + item.id + \"minimum_price\"' placeholder='0.00' v-model='item.minimum_price' class='form-control' />
2867
                                    <small class='form-text text-muted'>$label6</small>
2868
                                </div>
2869
2870
                                <div class='form-group form-check'>
2871
                                    <input :id='$id + item.id + \"quantities\"' v-model='item.allow_quantities' type='checkbox' class='form-check-input' />
2872
                                    <label class='form-check-label' :for='$id + item.id + \"quantities\"'>$label7</label>
2873
                                </div>
2874
2875
                                <div class='form-group form-check'>
2876
                                    <input :id='$id + item.id + \"required\"' v-model='item.required' type='checkbox' class='form-check-input' />
2877
                                    <label class='form-check-label' :for='$id + item.id + \"required\"'>$label8</label>
2878
                                </div>
2879
2880
                                <div class='form-group'>
2881
                                    <label :for='$id + item.id + \"description\"'>Item Description</label>
2882
                                    <textarea :id='$id + item.id + \"description\"' v-model='item.description' class='form-control'></textarea>
2883
                                </div>
2884
2885
                                <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'>Delete Item</button>
2886
2887
                            </div>
2888
                        </div>
2889
2890
                    </div>
2891
                </draggable>
2892
2893
                <small v-if='! form_items.length && !is_default' class='form-text text-danger'> You have not set up any items. Please select an item below or create a new item.</small>
2894
2895
                <div class='form-group mt-2' v-if='!is_default'>
2896
2897
                    <select class='form-control custom-select' v-model='selected_item' @change='addSelectedItem'>
2898
                        <option value=''>"        . __( 'Add an existing item to the form', 'invoicing' ) ."</option>
2899
                        <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
2900
                    </select>
2901
2902
                </div>
2903
2904
                <div class='form-group' v-if='!is_default'>
2905
                    <input type='button' value='Add item' class='button button-primary'  @click.prevent='addSelectedItem' :disabled='selected_item == \"\"'>
2906
                    <small>Or <a href='' @click.prevent='addNewItem'>create a new item</a>.</small>
2907
                </div>
2908
2909
                <div class='form-group mt-5' v-if='!is_default'>
2910
                    <label :for='$id2'>$label</label>
2911
2912
                    <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'>
2913
                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>"        . __( 'Buy all items on the list', 'invoicing' ) ."</option>
2914
                        <option value='radio'>"        . __( 'Select a single item from the list', 'invoicing' ) ."</option>
2915
                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>"     . __( 'Select one or more items on the list', 'invoicing' ) ."</option>
2916
                        <option value='select'>"       . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option>
2917
                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option>
2918
                    </select>
2919
2920
                </div>
2921
2922
                <div class='form-group'>
2923
                    <label :for='$id3'>Help Text</label>
2924
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
2925
                </div>
2926
2927
            </div>
2928
        ";
2929
2930
    }
2931
2932
    /**
2933
     * Returns an array of all published items.
2934
     */
2935
    public function get_published_items() {
2936
    
2937
        $item_args = array(
2938
            'post_type'      => 'wpi_item',
2939
            'orderby'        => 'title',
2940
            'order'          => 'ASC',
2941
            'posts_per_page' => -1,
2942
            'post_status'    => array( 'publish' ),
2943
            'meta_query'     => array(
2944
                array(
2945
                    'key'       => '_wpinv_type',
2946
                    'compare'   => '!=',
2947
                    'value'     => 'package'
2948
                )
2949
            )
2950
        );
2951
    
2952
        $items = get_posts( apply_filters( 'wpinv_payment_form_item_dropdown_query_args', $item_args ) );
2953
2954
        if ( empty( $items ) ) {
2955
            return array();
2956
        }
2957
2958
        $options    = array();
2959
        foreach ( $items as $item ) {
2960
            $title            = esc_html( $item->post_title );
2961
            $title           .= wpinv_get_item_suffix( $item->ID, false );
2962
            $id               = absint( $item->ID );
2963
            $price            = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) );
2964
            $recurring        = (bool) get_post_meta( $id, '_wpinv_is_recurring', true );
2965
            $description      = $item->post_excerpt;
2966
            $custom_price     = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true );
2967
            $minimum_price    = (float) get_post_meta( $id, '_minimum_price', true );
2968
            $allow_quantities = false;
2969
            $options[]        = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' );
2970
2971
        }
2972
        return $options;
2973
2974
    }
2975
2976
    /**
2977
     * Returns an array of items for the currently being edited form.
2978
     */
2979
    public function get_form_items( $id = false ) {
2980
        
2981
        if ( empty( $id ) ) {
2982
            return wpinv_get_data( 'sample-payment-form-items' );
2983
        }
2984
        
2985
        $form_elements = get_post_meta( $id, 'wpinv_form_items', true );
2986
2987
        if ( is_array( $form_elements ) ) {
2988
            return $form_elements;
2989
        }
2990
2991
        return wpinv_get_data( 'sample-payment-form-items' );
2992
2993
    }
2994
2995
    /**
2996
     * Converts form items for use.
2997
     */
2998
    public function convert_checkout_items( $items, $invoice ) {
2999
3000
        $converted = array();
3001
        foreach ( $items as $item ) {
3002
3003
            $item_id = $item['id'];
3004
            $_item   = new WPInv_Item( $item_id );
3005
3006
            if( ! $_item ) {
3007
                continue;
3008
            }
3009
3010
            $converted[] = array(
3011
                'title'            => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ),
3012
                'id'               => $item['id'],
3013
                'price'            => $item['subtotal'],
3014
                'custom_price'     => $_item->get_is_dynamic_pricing(),
3015
                'recurring'        => $_item->is_recurring(),
3016
                'description'      => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ),
3017
                'minimum_price'    => $_item->get_minimum_price(),
3018
                'allow_quantities' => false,
3019
                'quantity'         => $item['quantity'],
3020
                'required'         => true,
3021
            );
3022
        }
3023
        return $converted;
3024
3025
    }
3026
3027
    /**
3028
     * Converts an array of id => quantity for use.
3029
     */
3030
    public function convert_normal_items( $items ) {
3031
3032
        $converted = array();
3033
        foreach ( $items as $item_id => $quantity ) {
3034
3035
            $item   = new WPInv_Item( $item_id );
3036
3037
            if( ! $item ) {
3038
                continue;
3039
            }
3040
3041
            $converted[] = array(
3042
                'title'            => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ),
3043
                'id'               => $item_id,
3044
                'price'            => $item->get_price(),
3045
                'custom_price'     => $item->get_is_dynamic_pricing(),
3046
                'recurring'        => $item->is_recurring(),
3047
                'description'      => $item->get_summary(),
3048
                'minimum_price'    => $item->get_minimum_price(),
3049
                'allow_quantities' => ! empty( $quantity ),
3050
                'quantity'         => empty( $quantity ) ? 1 : $quantity,
3051
                'required'         => true,
3052
            );
3053
3054
        }
3055
3056
        return $converted;
3057
3058
    }
3059
3060
    /**
3061
     * Returns an array of elements for the currently being edited form.
3062
     */
3063
    public function get_form_elements( $id = false ) {
3064
3065
        if ( empty( $id ) ) {
3066
            return wpinv_get_data( 'sample-payment-form' );
3067
        }
3068
        
3069
        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
3070
3071
        if ( is_array( $form_elements ) ) {
3072
            return $form_elements;
3073
        }
3074
3075
        return wpinv_get_data( 'sample-payment-form' );
3076
    }
3077
3078
    /**
3079
     * Sends a redrect response to payment details.
3080
     *
3081
     */
3082
    public function send_redirect_response( $url ) {
3083
        $url = urlencode( $url );
3084
        wp_send_json_success( $url );
3085
    }
3086
3087
    /**
3088
     * Fired when a checkout error occurs
3089
     *
3090
     */
3091
    public function checkout_error() {
3092
3093
        $errors = wpinv_get_errors();
3094
3095
        if ( ! empty( $errors ) ) {
3096
            wpinv_print_errors();
3097
            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...
3098
        }
3099
3100
        wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
3101
        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...
3102
3103
    }
3104
3105
}
3106