Passed
Push — master ( 47344e...faf467 )
by Brian
09:39
created

edit_address_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 58
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 28
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 58
rs 9.472

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
                    'placeholder'  => '',
153
                    'value'        => '',
154
                    'label'        => __( 'Date', 'invoicing' ),
155
                    'description'  => '',
156
                    'required'     => false,
157
                )
158
            ),
159
160
            array( 
161
                'type' => 'time',
162
                'name' => __( 'Time', 'invoicing' ),
163
                'defaults' => array(
164
                    'placeholder'  => '',
165
                    'value'        => '',
166
                    'label'        => __( 'Time', 'invoicing' ),
167
                    'description'  => '',
168
                    'required'     => false,
169
                )
170
            ),
171
172
            array( 
173
                'type' => 'number',
174
                'name' => __( 'Number', 'invoicing' ),
175
                'defaults' => array(
176
                    'placeholder'  => '',
177
                    'value'        => '',
178
                    'label'        => __( 'Number', 'invoicing' ),
179
                    'description'  => '',
180
                    'required'     => false,
181
                )
182
            ),
183
184
            array( 
185
                'type' => 'website',
186
                'name' => __( 'Website', 'invoicing' ),
187
                'defaults' => array(
188
                    'placeholder'  => 'http://example.com',
189
                    'value'        => '',
190
                    'label'        => __( 'Website', 'invoicing' ),
191
                    'description'  => '',
192
                    'required'     => false,
193
                )
194
            ),
195
196
            array( 
197
                'type' => 'email',
198
                'name' => __( 'Email', 'invoicing' ),
199
                'defaults'  => array(
200
                    'placeholder'  => '[email protected]',
201
                    'value'        => '',
202
                    'label'        => __( 'Email Address', 'invoicing' ),
203
                    'description'  => '',
204
                    'required'     => false,
205
                )
206
            ),
207
208
            array( 
209
                'type' => 'address',
210
                'name' => __( 'Address', 'invoicing' ),
211
                'defaults'  => array(
212
213
                    'fields' => array(
214
                        array(
215
                            'placeholder'  => 'Jon',
216
                            'value'        => '',
217
                            'label'        => __( 'First Name', 'invoicing' ),
218
                            'description'  => '',
219
                            'required'     => false,
220
                            'visible'      => true,
221
                            'name'         => 'wpinv_first_name',
222
                        ),
223
224
                        array(
225
                            'placeholder'  => 'Snow',
226
                            'value'        => '',
227
                            'label'        => __( 'Last Name', 'invoicing' ),
228
                            'description'  => '',
229
                            'required'     => false,
230
                            'visible'      => true,
231
                            'name'         => 'wpinv_last_name',
232
                        ),
233
                    
234
                        array(
235
                            'placeholder'  => '',
236
                            'value'        => '',
237
                            'label'        => __( 'Address', 'invoicing' ),
238
                            'description'  => '',
239
                            'required'     => false,
240
                            'visible'      => true,
241
                            'name'         => 'wpinv_address',
242
                        ),
243
244
                        array(
245
                            'placeholder'  => '',
246
                            'value'        => '',
247
                            'label'        => __( 'City', 'invoicing' ),
248
                            'description'  => '',
249
                            'required'     => false,
250
                            'visible'      => true,
251
                            'name'         => 'wpinv_city',
252
                        ),
253
254
                        array(
255
                            'placeholder'  => '',
256
                            'value'        => '',
257
                            'label'        => __( 'Country', 'invoicing' ),
258
                            'description'  => '',
259
                            'required'     => false,
260
                            'visible'      => true,
261
                            'name'         => 'wpinv_country',
262
                        ),
263
264
                        array(
265
                            'placeholder'  => __( 'Choose a state', 'invoicing' ),
266
                            'value'        => '',
267
                            'label'        => __( 'State / Province', 'invoicing' ),
268
                            'description'  => '',
269
                            'required'     => false,
270
                            'visible'      => true,
271
                            'name'         => 'wpinv_state',
272
                        ),
273
274
                        array(
275
                            'placeholder'  => '',
276
                            'value'        => '',
277
                            'label'        => __( 'ZIP / Postcode', 'invoicing' ),
278
                            'description'  => '',
279
                            'required'     => false,
280
                            'visible'      => true,
281
                            'name'         => 'wpinv_zip',
282
                        ),
283
284
                        array(
285
                            'placeholder'  => '',
286
                            'value'        => '',
287
                            'label'        => __( 'Phone', 'invoicing' ),
288
                            'description'  => '',
289
                            'required'     => false,
290
                            'visible'      => true,
291
                            'name'         => 'wpinv_phone',
292
                        )
293
                    )
294
                )
295
            ),
296
297
            array( 
298
                'type' => 'billing_email',
299
                'name' => __( 'Billing Email', 'invoicing' ),
300
                'defaults'  => array(
301
                    'placeholder'  => '[email protected]',
302
                    'value'        => '',
303
                    'label'        => __( 'Billing Email', 'invoicing' ),
304
                    'description'  => '',
305
                    'premade'      => true,
306
                )
307
            ),
308
/*
309
            array( 
310
                'type' => 'discount',
311
                'name' => __( 'Discount Input', 'invoicing' ),
312
                'defaults'  => array(
313
                    'value'        => '',
314
                    'input_label'  => __( 'Coupon Code', 'invoicing' ),
315
                    'button_label' => __( 'Apply Coupon', 'invoicing' ),
316
                    'description'  => __( 'Have a discount code? Enter it above.', 'invoicing' ),
317
                )
318
            ),*/
319
320
            array( 
321
                'type' => 'items',
322
                'name' => __( 'Items', 'invoicing' ),
323
                'defaults'  => array(
324
                    'value'        => '',
325
                    'items_type'   => 'total',
326
                    'description'  => '',
327
                    'premade'      => true,
328
                )
329
            ),
330
331
            array( 
332
                'type'       => 'pay_button',
333
                'name'       => __( 'Payment Button', 'invoicing' ),
334
                'defaults'   => array(
335
                    'value'        => '',
336
                    'class'        => 'btn-primary',
337
                    'label'        => __( 'Pay Now »', 'invoicing' ),
338
                    'description'  => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
339
                    'premade'      => true,
340
                )
341
            )
342
        );
343
344
        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
345
        return $this->elements;
346
    }
347
348
    /**
349
     * Returns the restrict markup.
350
     */
351
    public function get_restrict_markup( $field, $field_type ) {
352
        $restrict = "$field.type=='$field_type'";
353
        return "v-if=\"$restrict\"";
354
    }
355
356
    /**
357
     * Renders the title element template.
358
     */
359
    public function render_heading_template( $field ) {
360
        $restrict = $this->get_restrict_markup( $field, 'heading' );
361
        echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
362
    }
363
364
    /**
365
     * Renders the title element on the frontend.
366
     */
367
    public function frontend_render_heading_template( $field ) {
368
        $tag = $field['level'];
369
        echo "<$tag>{$field['text']}</$tag>";
370
    }
371
372
    /**
373
     * Renders the edit title element template.
374
     */
375
    public function edit_heading_template( $field ) {
376
        $restrict = $this->get_restrict_markup( $field, 'heading' );
377
        $label    = __( 'Heading', 'invoicing' );
378
        $label2   = __( 'Select Heading Level', 'invoicing' );
379
        $id       = $field . '.id + "_edit"';
380
        $id2      = $field . '.id + "_edit2"';
381
382
        echo "
383
            <div $restrict>
384
                <div class='form-group'>
385
                    <label :for='$id'>$label</label>
386
                    <input class='form-control' :id='$id' v-model='$field.text' type='text' />
387
                </div>
388
389
                <div class='form-group'>
390
                    <label :for='$id2'>$label2</label>
391
392
                    <select class='form-control custom-select' :id='$id2' v-model='$field.level'>
393
                        <option value='h1'>H1</option>
394
                        <option value='h2'>H2</option>
395
                        <option value='h3'>H3</option>
396
                        <option value='h4'>H4</option>
397
                        <option value='h5'>H5</option>
398
                        <option value='h6'>H6</option>
399
                        <option value='h7'>H7</option>
400
                    </select>
401
                </div>
402
            </div>
403
        ";
404
405
    }
406
407
    /**
408
     * Renders a paragraph element template.
409
     */
410
    public function render_paragraph_template( $field ) {
411
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
412
        $label    = "$field.text";
413
        echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
414
    }
415
416
    /**
417
     * Renders the paragraph element on the frontend.
418
     */
419
    public function frontend_render_paragraph_template( $field ) {
420
        echo "<p>{$field['text']}</p>";
421
    }
422
423
    /**
424
     * Renders the edit paragraph element template.
425
     */
426
    public function edit_paragraph_template( $field ) {
427
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
428
        $label    = __( 'Enter your text', 'invoicing' );
429
        $id       = $field . '.id + "_edit"';
430
        echo "
431
            <div $restrict>
432
                <div class='form-group'>
433
                    <label :for='$id'>$label</label>
434
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
435
                </div>
436
            </div>
437
        ";
438
439
    }
440
441
    /**
442
     * Renders the text element template.
443
     */
444
    public function render_text_template( $field ) {
445
        $restrict = $this->get_restrict_markup( $field, 'text' );
446
        $label    = "$field.label";
447
        echo "
448
            <div $restrict>
449
                <label :for='$field.id'>{{" . $label . "}}</label>
450
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'>
451
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
452
            </div>    
453
        ";
454
    }
455
456
    /**
457
     * Renders the text element on the frontend.
458
     */
459
    public function frontend_render_text_template( $field ) {
460
        
461
        echo "<div class='form-group'>";
462
463
        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

463
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
464
            array(
465
                'name'       => esc_attr( $field['id'] ),
466
                'id'         => esc_attr( $field['id'] ),
467
                'placeholder'=> esc_attr( $field['placeholder'] ),
468
                'required'   => (bool) $field['required'],
469
                'label'      => wp_kses_post( $field['label'] ),
470
                'no_wrap'    => true,
471
            )
472
        );
473
474
        if ( ! empty( $field['description'] ) ) {
475
            $description = wp_kses_post( $field['description'] );
476
            echo "<small class='form-text text-muted'>$description</small>";
477
        }
478
479
        echo '</div>';
480
481
    }
482
483
    /**
484
     * Renders the edit text element template.
485
     */
486
    public function edit_text_template( $field ) {
487
        $restrict = $this->get_restrict_markup( $field, 'text' );
488
        $label    = __( 'Field Label', 'invoicing' );
489
        $id       = $field . '.id + "_edit"';
490
        $label2   = __( 'Placeholder text', 'invoicing' );
491
        $id2      = $field . '.id + "_edit2"';
492
        $label3   = __( 'Help text', 'invoicing' );
493
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
494
        $id3      = $field . '.id + "_edit3"';
495
        $label5   = __( 'Is this field required?', 'invoicing' );
496
        $id4      = $field . '.id + "_edit4"';
497
        echo "
498
            <div $restrict>
499
                <div class='form-group'>
500
                    <label :for='$id'>$label</label>
501
                    <input :id='$id' v-model='$field.label' class='form-control' />
502
                </div>
503
                <div class='form-group'>
504
                    <label :for='$id2'>$label2</label>
505
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
506
                </div>
507
                <div class='form-group'>
508
                    <label :for='$id3'>$label3</label>
509
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
510
                </div>
511
                <div class='form-group form-check'>
512
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
513
                    <label class='form-check-label' :for='$id4'>$label5</label>
514
                </div>
515
            </div>
516
        ";
517
518
    }
519
520
    /**
521
     * Renders the textarea element template.
522
     */
523
    public function render_textarea_template( $field ) {
524
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
525
        $label    = "$field.label";
526
        echo "
527
            <div $restrict>
528
                <label :for='$field.id'>{{" . $label . "}}</label>
529
                <textarea  :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea>
530
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
531
            </div>    
532
        ";
533
    }
534
535
    /**
536
     * Renders the textarea element on the frontend.
537
     */
538
    public function frontend_render_textarea_template( $field ) {
539
        
540
        echo "<div class='form-group'>";
541
542
        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

542
        echo /** @scrutinizer ignore-call */ aui()->textarea(
Loading history...
543
            array(
544
                'name'       => esc_attr( $field['id'] ),
545
                'id'         => esc_attr( $field['id'] ),
546
                'placeholder'=> esc_attr( $field['placeholder'] ),
547
                'required'   => (bool) $field['required'],
548
                'label'      => wp_kses_post( $field['label'] ),
549
                'no_wrap'    => true,
550
                'rows'       => 3,
551
            )
552
        );
553
554
        if ( ! empty( $field['description'] ) ) {
555
            $description = wp_kses_post( $field['description'] );
556
            echo "<small class='form-text text-muted'>$description</small>";
557
        }
558
559
        echo '</div>';
560
561
    }
562
563
    /**
564
     * Renders the edit textarea element template.
565
     */
566
    public function edit_textarea_template( $field ) {
567
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
568
        $label    = __( 'Field Label', 'invoicing' );
569
        $id       = $field . '.id + "_edit"';
570
        $label2   = __( 'Placeholder text', 'invoicing' );
571
        $id2      = $field . '.id + "_edit2"';
572
        $label3   = __( 'Help text', 'invoicing' );
573
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
574
        $id3      = $field . '.id + "_edit3"';
575
        $label5   = __( 'Is this field required?', 'invoicing' );
576
        $id4      = $field . '.id + "_edit4"';
577
        echo "
578
            <div $restrict>
579
                <div class='form-group'>
580
                    <label :for='$id'>$label</label>
581
                    <input :id='$id' v-model='$field.label' class='form-control' />
582
                </div>
583
                <div class='form-group'>
584
                    <label :for='$id2'>$label2</label>
585
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
586
                </div>
587
                <div class='form-group'>
588
                    <label :for='$id3'>$label3</label>
589
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
590
                </div>
591
                <div class='form-group form-check'>
592
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
593
                    <label class='form-check-label' :for='$id4'>$label5</label>
594
                </div>
595
            </div>
596
        ";
597
598
    }
599
600
    /**
601
     * Renders the select element template.
602
     */
603
    public function render_select_template( $field ) {
604
        $restrict    = $this->get_restrict_markup( $field, 'select' );
605
        $label       = "$field.label";
606
        $placeholder = "$field.placeholder";
607
        $id          = $field . '.id';
608
        echo "
609
            <div $restrict>
610
                <label :for='$id'>{{" . $label . "}}</label>
611
                <select id='$id' class='form-control custom-select'  v-model='$field.value'>
612
                    <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option>
613
                    <option v-for='option in $field.options' value='option'>{{option}}</option>
614
                </select>
615
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
616
            </div>
617
        ";
618
    }
619
620
    /**
621
     * Renders the select element on the frontend.
622
     */
623
    public function frontend_render_select_template( $field ) {
624
        
625
        echo "<div class='form-group'>";
626
627
        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

627
        echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
628
            array(
629
                'name'       => esc_attr( $field['id'] ),
630
                'id'         => esc_attr( $field['id'] ),
631
                'placeholder'=> esc_attr( $field['placeholder'] ),
632
                'required'   => (bool) $field['required'],
633
                'label'      => wp_kses_post( $field['label'] ),
634
                'no_wrap'    => true,
635
                'options'    => array_combine( $field['options'], $field['options'] ),
636
            )
637
        );
638
639
        if ( ! empty( $field['description'] ) ) {
640
            $description = wp_kses_post( $field['description'] );
641
            echo "<small class='form-text text-muted'>$description</small>";
642
        }
643
644
        echo '</div>';
645
646
    }
647
648
    /**
649
     * Renders the edit select element template.
650
     */
651
    public function edit_select_template( $field ) {
652
        $restrict = $this->get_restrict_markup( $field, 'select' );
653
        $label    = __( 'Field Label', 'invoicing' );
654
        $id       = $field . '.id + "_edit"';
655
        $label2   = __( 'Placeholder text', 'invoicing' );
656
        $id2      = $field . '.id + "_edit2"';
657
        $label3   = __( 'Help text', 'invoicing' );
658
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
659
        $id3      = $field . '.id + "_edit3"';
660
        $label5   = __( 'Is this field required?', 'invoicing' );
661
        $id4      = $field . '.id + "_edit4"';
662
        $label6   = __( 'Available Options', 'invoicing' );
663
        echo "
664
            <div $restrict>
665
                <div class='form-group'>
666
                    <label :for='$id'>$label</label>
667
                    <input :id='$id' v-model='$field.label' class='form-control' />
668
                </div>
669
                <div class='form-group'>
670
                    <label :for='$id2'>$label2</label>
671
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
672
                </div>
673
                <div class='form-group'>
674
                    <label :for='$id3'>$label3</label>
675
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
676
                </div>
677
                <div class='form-group form-check'>
678
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
679
                    <label class='form-check-label' :for='$id4'>$label5</label>
680
                </div>
681
                <hr class='featurette-divider mt-4'>
682
                <h5>$label6</h5>
683
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
684
                    <input type='text' class='form-control' v-model='$field.options[index]'>
685
                    <div class='input-group-append'>
686
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
687
                    </div>
688
                </div>
689
                <div class='form-group'>
690
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
691
                </div>
692
            </div>
693
        ";
694
695
    }
696
697
    /**
698
     * Renders the checkbox element template.
699
     */
700
    public function render_checkbox_template( $field ) {
701
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
702
        $label    = "$field.label";
703
        echo "
704
            <div class='form-check' $restrict>
705
                <input  :id='$field.id' class='form-check-input' type='checkbox' />
706
                <label class='form-check-label' :for='$field.id'>{{" . $label . "}}</label>
707
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
708
            </div>    
709
        ";
710
    }
711
712
    /**
713
     * Renders the checkbox element on the frontend.
714
     */
715
    public function frontend_render_checkbox_template( $field ) {
716
        
717
        echo "<div class='form-group'>";
718
719
        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

719
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
720
            array(
721
                'name'       => esc_attr( $field['id'] ),
722
                'id'         => esc_attr( $field['id'] ),
723
                'required'   => (bool) $field['required'],
724
                'label'      => wp_kses_post( $field['label'] ),
725
                'no_wrap'    => true,
726
                'value'      => esc_attr__( 'Yes', 'invoicing' ),
727
                'type'       => 'checkbox',
728
            )
729
        );
730
731
        if ( ! empty( $field['description'] ) ) {
732
            $description = wp_kses_post( $field['description'] );
733
            echo "<small class='form-text text-muted'>$description</small>";
734
        }
735
736
        echo '</div>';
737
738
    }
739
740
    /**
741
     * Renders the edit checkbox element template.
742
     */
743
    public function edit_checkbox_template( $field ) {
744
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
745
        $label    = __( 'Field Label', 'invoicing' );
746
        $id       = $field . '.id + "_edit"';
747
        $label2   = __( 'Help text', 'invoicing' );
748
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
749
        $id2      = $field . '.id + "_edit2"';
750
        $label4   = __( 'Is this field required?', 'invoicing' );
751
        $id3      = $field . '.id + "_edit3"';
752
        echo "
753
            <div $restrict>
754
                <div class='form-group'>
755
                    <label :for='$id'>$label</label>
756
                    <input :id='$id' v-model='$field.label' class='form-control' />
757
                </div>
758
                <div class='form-group'>
759
                    <label :for='$id2'>$label2</label>
760
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
761
                </div>
762
                <div class='form-group form-check'>
763
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
764
                    <label class='form-check-label' :for='$id3'>$label4</label>
765
                </div>
766
            </div>
767
        ";
768
769
    }
770
771
    /**
772
     * Renders the radio element template.
773
     */
774
    public function render_radio_template( $field ) {
775
        $restrict    = $this->get_restrict_markup( $field, 'radio' );
776
        $label       = "$field.label";
777
        $id          = $field . '.id';
778
        echo "
779
            <div $restrict>
780
                <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend>
781
                <div class='form-check' v-for='(option, index) in $field.options'>
782
                    <input class='form-check-input' type='radio' :id='$id + index'>
783
                    <label class='form-check-label' :for='$id + index'>{{option}}</label>
784
                </div>
785
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
786
            </div>
787
        ";
788
    }
789
790
    /**
791
     * Renders the radio element on the frontend.
792
     */
793
    public function frontend_render_radio_template( $field ) {
794
        
795
        echo "<div class='form-group'>";
796
797
        if ( ! empty( $field['label'] ) ) {
798
            $label = wp_kses_post( $field['label'] );
799
            echo "<legend class='col-form-label'>$label</legend>";
800
        }
801
802
        foreach( $field['options'] as $index => $option ) {
803
            $id    = $field['id'] . $index;
804
            $name  = $field['id'];
805
            $value = esc_attr( $option );
806
            $label = wp_kses_post( $option );
807
808
            echo "
809
                <div class='form-check'>
810
                    <input class='form-check-input' type='radio' name='$name' id='$id' value='$value'>
811
                    <label class='form-check-label' for='$id'>$label</label>
812
                </div>
813
            ";
814
        }
815
816
        if ( ! empty( $field['description'] ) ) {
817
            $description = wp_kses_post( $field['description'] );
818
            echo "<small class='form-text text-muted'>$description</small>";
819
        }
820
821
        echo '</div>';
822
823
    }
824
825
    /**
826
     * Renders the edit radio element template.
827
     */
828
    public function edit_radio_template( $field ) {
829
        $restrict = $this->get_restrict_markup( $field, 'radio' );
830
        $label    = __( 'Field Label', 'invoicing' );
831
        $id       = $field . '.id + "_edit"';
832
        $label2   = __( 'Help text', 'invoicing' );
833
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
834
        $id2      = $field . '.id + "_edit3"';
835
        $label4   = __( 'Is this field required?', 'invoicing' );
836
        $id3      = $field . '.id + "_edit4"';
837
        $label5   = __( 'Available Options', 'invoicing' );
838
        echo "
839
            <div $restrict>
840
                <div class='form-group'>
841
                    <label :for='$id'>$label</label>
842
                    <input :id='$id' v-model='$field.label' class='form-control' />
843
                </div>
844
                <div class='form-group'>
845
                    <label :for='$id2'>$label2</label>
846
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
847
                </div>
848
                <div class='form-group form-check'>
849
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
850
                    <label class='form-check-label' :for='$id3'>$label4</label>
851
                </div>
852
                <hr class='featurette-divider mt-4'>
853
                <h5>$label5</h5>
854
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
855
                    <input type='text' class='form-control' v-model='$field.options[index]'>
856
                    <div class='input-group-append'>
857
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
858
                    </div>
859
                </div>
860
                <div class='form-group'>
861
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
862
                </div>
863
            </div>
864
        ";
865
866
    }
867
868
    /**
869
     * Renders the address element template.
870
     */
871
    public function render_address_template( $field ) {
872
        $restrict    = $this->get_restrict_markup( $field, 'address' );
873
874
        echo "
875
            <div class='wpinv-address-wrapper' $restrict>
876
                <draggable v-model='$field.fields' group='address_fields_preview'>
877
                    <div class='form-group address-field-preview' v-for='(field, index) in $field.fields' :key='field.name' v-show='field.visible'>
878
                        <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label>
879
                        <input class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'>
880
                        <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small>
881
                    </div>
882
                </draggable>
883
            </div>
884
        ";
885
    }
886
887
    /**
888
     * Renders the address element on the frontend.
889
     */
890
    public function frontend_render_address_template( $field ) {
891
        
892
        echo "<div class='wpinv-address-fields'>";
893
894
        foreach( $field['fields'] as $address_field ) {
895
896
            if ( empty( $address_field['visible'] ) ) {
897
                continue;
898
            }
899
900
            $class = esc_attr( $address_field['name'] );
901
            echo "<div class='form-group $class'>";
902
903
            $label = $address_field['label'];
904
905
            if ( ! empty( $address_field['required'] ) ) {
906
                $label .= "<span class='text-danger'> *</span>";
907
            }
908
            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

908
            echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
909
                array(
910
                    'name'       => esc_attr( $address_field['name'] ),
911
                    'id'         => esc_attr( $address_field['name'] ),
912
                    'required'   => (bool) $address_field['required'],
913
                    'label'      => wp_kses_post( $label ),
914
                    'no_wrap'    => true,
915
                    'placeholder' => esc_attr( $address_field['placeholder'] ),
916
                    'type'       => 'text',
917
                )
918
            );
919
920
            if ( ! empty( $address_field['description'] ) ) {
921
                $description = wp_kses_post( $address_field['description'] );
922
                echo "<small class='form-text text-muted'>$description</small>";
923
            }
924
    
925
            echo '</div>';
926
927
        }
928
929
        echo '</div>';
930
931
    }
932
933
    /**
934
     * Renders the edit address element template.
935
     */
936
    public function edit_address_template( $field ) {
937
        $restrict  = $this->get_restrict_markup( $field, 'address' );
938
        $label     = __( 'Field Label', 'invoicing' );
939
        $label2    = __( 'Placeholder', 'invoicing' );
940
        $label3    = __( 'Description', 'invoicing' );
941
        $label4    = __( 'Is required', 'invoicing' );
942
        $label5    = __( 'Is visible', 'invoicing' );
943
        $id        = $field . '.id + "_edit_label"';
944
        $id2       = $field . '.id + "_edit_placeholder"';
945
        $id3       = $field . '.id + "_edit_description"';
946
        $id4       = $field . '.id + "_edit_required"';
947
        $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...
948
        $id5       = $field . '.id + "_edit_visible"';
949
        $id_main   = $field . '.id';
950
951
        echo "
952
            <div $restrict :id='$id_main'>
953
                <draggable v-model='$field.fields' group='address_fields'>
954
                    <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'>
955
956
                        <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'>
957
                            <span class='label'>{{field.label}}</span>
958
                            <span class='toggle-visibility-icon' @click.prevent='field.visible = !field.visible;'>
959
                                <span class='dashicons dashicons-hidden'></span>
960
                                <span class='dashicons dashicons-visibility'></span>
961
                            </span>
962
                            <span class='toggle-icon'>
963
                                <span class='dashicons dashicons-arrow-down'></span>
964
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
965
                            </span>
966
                        </div>
967
968
                        <div class='wpinv-form-address-field-editor-editor-body'>
969
                            <div class='p-2'>
970
971
                                <div class='form-group'>
972
                                    <label :for='$id + index'>$label</label>
973
                                    <input :id='$id + index' v-model='field.label' class='form-control' />
974
                                </div>
975
976
                                <div class='form-group'>
977
                                    <label :for='$id2 + index'>$label2</label>
978
                                    <input :id='$id2 + index' v-model='field.placeholder' class='form-control' />
979
                                </div>
980
981
                                <div class='form-group'>
982
                                    <label :for='$id3 + index'>$label3</label>
983
                                    <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea>
984
                                </div>
985
986
                                <div class='form-group form-check'>
987
                                    <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' />
988
                                    <label class='form-check-label' :for='$id4 + index'>$label4</label>
989
                                </div>
990
991
                                <div class='form-group form-check'>
992
                                    <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' />
993
                                    <label class='form-check-label' :for='$id5 + index'>$label5</label>
994
                                </div>
995
996
                            </div>
997
                        </div>
998
999
                    </div>
1000
                </draggable>
1001
1002
            </div>
1003
        ";
1004
1005
    }
1006
1007
    /**
1008
     * Renders the email element template.
1009
     */
1010
    public function render_email_template( $field ) {
1011
        $restrict = $this->get_restrict_markup( $field, 'email' );
1012
        $label    = "$field.label";
1013
        echo "
1014
            <div $restrict>
1015
                <label :for='$field.id'>{{" . $label . "}}</label>
1016
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
1017
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1018
            </div>    
1019
        ";
1020
    }
1021
1022
    /**
1023
     * Renders the billing_email element template.
1024
     */
1025
    public function render_billing_email_template( $field ) {
1026
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1027
        $label    = "$field.label";
1028
        echo "
1029
            <div $restrict>
1030
                <label :for='$field.id'>{{" . $label . "}}</label>
1031
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
1032
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1033
            </div>    
1034
        ";
1035
    }
1036
1037
    /**
1038
     * Renders the email element on the frontend.
1039
     */
1040
    public function frontend_render_email_template( $field ) {
1041
        
1042
        echo "<div class='form-group'>";
1043
1044
        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

1044
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1045
            array(
1046
                'name'       => esc_attr( $field['id'] ),
1047
                'id'         => esc_attr( $field['id'] ),
1048
                'required'   => (bool) $field['required'],
1049
                'label'      => wp_kses_post( $field['label'] ),
1050
                'no_wrap'    => true,
1051
                'placeholder' => esc_attr( $field['placeholder'] ),
1052
                'type'       => 'email',
1053
            )
1054
        );
1055
1056
        if ( ! empty( $field['description'] ) ) {
1057
            $description = wp_kses_post( $field['description'] );
1058
            echo "<small class='form-text text-muted'>$description</small>";
1059
        }
1060
1061
        echo '</div>';
1062
1063
    }
1064
1065
    /**
1066
     * Renders the billing email element on the frontend.
1067
     */
1068
    public function frontend_render_billing_email_template( $field ) {
1069
        
1070
        echo "<div class='form-group'>";
1071
        $value = '';
1072
1073
        if ( is_user_logged_in() ) {
1074
            $user  = wp_get_current_user();
1075
            $value = sanitize_email( $user->user_email );
1076
        }
1077
        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

1077
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1078
            array(
1079
                'name'       => 'billing_email',
1080
                'value'      => $value,
1081
                'id'         => esc_attr( $field['id'] ),
1082
                'required'   => true,
1083
                'label'      => wp_kses_post( $field['label'] ),
1084
                'no_wrap'    => true,
1085
                'placeholder' => esc_attr( $field['placeholder'] ),
1086
                'type'       => 'email',
1087
            )
1088
        );
1089
1090
        if ( ! empty( $field['description'] ) ) {
1091
            $description = wp_kses_post( $field['description'] );
1092
            echo "<small class='form-text text-muted'>$description</small>";
1093
        }
1094
1095
        echo '</div>';
1096
1097
    }
1098
1099
    /**
1100
     * Renders the edit email element template.
1101
     */
1102
    public function edit_email_template( $field ) {
1103
        $restrict = $this->get_restrict_markup( $field, 'email' );
1104
        $label    = __( 'Field Label', 'invoicing' );
1105
        $id       = $field . '.id + "_edit"';
1106
        $label2   = __( 'Placeholder text', 'invoicing' );
1107
        $id2      = $field . '.id + "_edit2"';
1108
        $label3   = __( 'Help text', 'invoicing' );
1109
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1110
        $id3      = $field . '.id + "_edit3"';
1111
        $label5   = __( 'Is this field required?', 'invoicing' );
1112
        $id4      = $field . '.id + "_edit4"';
1113
        echo "
1114
            <div $restrict>
1115
                <div class='form-group'>
1116
                    <label :for='$id'>$label</label>
1117
                    <input :id='$id' v-model='$field.label' class='form-control' />
1118
                </div>
1119
                <div class='form-group'>
1120
                    <label :for='$id2'>$label2</label>
1121
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1122
                </div>
1123
                <div class='form-group'>
1124
                    <label :for='$id3'>$label3</label>
1125
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1126
                </div>
1127
                <div class='form-group form-check'>
1128
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1129
                    <label class='form-check-label' :for='$id4'>$label5</label>
1130
                </div>
1131
            </div>
1132
        ";
1133
1134
    }
1135
1136
    /**
1137
     * Renders the edit billing_email element template.
1138
     */
1139
    public function edit_billing_email_template( $field ) {
1140
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1141
        $label    = __( 'Field Label', 'invoicing' );
1142
        $id       = $field . '.id + "_edit"';
1143
        $label2   = __( 'Placeholder text', 'invoicing' );
1144
        $id2      = $field . '.id + "_edit2"';
1145
        $label3   = __( 'Help text', 'invoicing' );
1146
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1147
        $id3      = $field . '.id + "_edit3"';
1148
        $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...
1149
        $id4      = $field . '.id + "_edit4"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id4 is dead and can be removed.
Loading history...
1150
        echo "
1151
            <div $restrict>
1152
                <div class='form-group'>
1153
                    <label :for='$id'>$label</label>
1154
                    <input :id='$id' v-model='$field.label' class='form-control' />
1155
                </div>
1156
                <div class='form-group'>
1157
                    <label :for='$id2'>$label2</label>
1158
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1159
                </div>
1160
                <div class='form-group'>
1161
                    <label :for='$id3'>$label3</label>
1162
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1163
                </div>
1164
            </div>
1165
        ";
1166
1167
    }
1168
1169
    /**
1170
     * Renders the website element template.
1171
     */
1172
    public function render_website_template( $field ) {
1173
        $restrict = $this->get_restrict_markup( $field, 'website' );
1174
        $label    = "$field.label";
1175
        echo "
1176
            <div $restrict>
1177
                <label :for='$field.id'>{{" . $label . "}}</label>
1178
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'>
1179
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1180
            </div>    
1181
        ";
1182
    }
1183
1184
    /**
1185
     * Renders the website element on the frontend.
1186
     */
1187
    public function frontend_render_website_template( $field ) {
1188
        
1189
        echo "<div class='form-group'>";
1190
1191
        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

1191
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1192
            array(
1193
                'name'       => esc_attr( $field['id'] ),
1194
                'id'         => esc_attr( $field['id'] ),
1195
                'required'   => (bool) $field['required'],
1196
                'label'      => wp_kses_post( $field['label'] ),
1197
                'no_wrap'    => true,
1198
                'placeholder' => esc_attr( $field['placeholder'] ),
1199
                'type'       => 'url',
1200
            )
1201
        );
1202
1203
        if ( ! empty( $field['description'] ) ) {
1204
            $description = wp_kses_post( $field['description'] );
1205
            echo "<small class='form-text text-muted'>$description</small>";
1206
        }
1207
1208
        echo '</div>';
1209
1210
    }
1211
1212
    /**
1213
     * Renders the edit website element template.
1214
     */
1215
    public function edit_website_template( $field ) {
1216
        $restrict = $this->get_restrict_markup( $field, 'website' );
1217
        $label    = __( 'Field Label', 'invoicing' );
1218
        $id       = $field . '.id + "_edit"';
1219
        $label2   = __( 'Placeholder text', 'invoicing' );
1220
        $id2      = $field . '.id + "_edit2"';
1221
        $label3   = __( 'Help text', 'invoicing' );
1222
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1223
        $id3      = $field . '.id + "_edit3"';
1224
        $label5   = __( 'Is this field required?', 'invoicing' );
1225
        $id4      = $field . '.id + "_edit4"';
1226
        echo "
1227
            <div $restrict>
1228
                <div class='form-group'>
1229
                    <label :for='$id'>$label</label>
1230
                    <input :id='$id' v-model='$field.label' class='form-control' />
1231
                </div>
1232
                <div class='form-group'>
1233
                    <label :for='$id2'>$label2</label>
1234
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1235
                </div>
1236
                <div class='form-group'>
1237
                    <label :for='$id3'>$label3</label>
1238
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1239
                </div>
1240
                <div class='form-group form-check'>
1241
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1242
                    <label class='form-check-label' :for='$id4'>$label5</label>
1243
                </div>
1244
            </div>
1245
        ";
1246
1247
    }
1248
1249
    /**
1250
     * Renders the date element template.
1251
     */
1252
    public function render_date_template( $field ) {
1253
        $restrict = $this->get_restrict_markup( $field, 'date' );
1254
        $label    = "$field.label";
1255
        echo "
1256
            <div $restrict>
1257
                <label :for='$field.id'>{{" . $label . "}}</label>
1258
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'>
1259
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1260
            </div>    
1261
        ";
1262
    }
1263
1264
    /**
1265
     * Renders the date element on the frontend.
1266
     */
1267
    public function frontend_render_date_template( $field ) {
1268
        
1269
        echo "<div class='form-group'>";
1270
1271
        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

1271
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1272
            array(
1273
                'name'       => esc_attr( $field['id'] ),
1274
                'id'         => esc_attr( $field['id'] ),
1275
                'required'   => (bool) $field['required'],
1276
                'label'      => wp_kses_post( $field['label'] ),
1277
                'placeholder' => esc_attr( $field['placeholder'] ),
1278
                'no_wrap'    => true,
1279
                'type'       => 'date',
1280
            )
1281
        );
1282
1283
        if ( ! empty( $field['description'] ) ) {
1284
            $description = wp_kses_post( $field['description'] );
1285
            echo "<small class='form-text text-muted'>$description</small>";
1286
        }
1287
1288
        echo '</div>';
1289
1290
    }
1291
1292
    /**
1293
     * Renders the edit date element template.
1294
     */
1295
    public function edit_date_template( $field ) {
1296
        $restrict = $this->get_restrict_markup( $field, 'date' );
1297
        $label    = __( 'Field Label', 'invoicing' );
1298
        $id       = $field . '.id + "_edit"';
1299
        $label2   = __( 'Placeholder text', 'invoicing' );
1300
        $id2      = $field . '.id + "_edit2"';
1301
        $label3   = __( 'Help text', 'invoicing' );
1302
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1303
        $id3      = $field . '.id + "_edit3"';
1304
        $label5   = __( 'Is this field required?', 'invoicing' );
1305
        $id4      = $field . '.id + "_edit4"';
1306
        echo "
1307
            <div $restrict>
1308
                <div class='form-group'>
1309
                    <label :for='$id'>$label</label>
1310
                    <input :id='$id' v-model='$field.label' class='form-control' />
1311
                </div>
1312
                <div class='form-group'>
1313
                    <label :for='$id2'>$label2</label>
1314
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1315
                </div>
1316
                <div class='form-group'>
1317
                    <label :for='$id3'>$label3</label>
1318
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1319
                </div>
1320
                <div class='form-group form-check'>
1321
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1322
                    <label class='form-check-label' :for='$id4'>$label5</label>
1323
                </div>
1324
            </div>
1325
        ";
1326
1327
    }
1328
1329
    /**
1330
     * Renders the time element template.
1331
     */
1332
    public function render_time_template( $field ) {
1333
        $restrict = $this->get_restrict_markup( $field, 'time' );
1334
        $label    = "$field.label";
1335
        echo "
1336
            <div $restrict>
1337
                <label :for='$field.id'>{{" . $label . "}}</label>
1338
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'>
1339
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1340
            </div>    
1341
        ";
1342
    }
1343
1344
    /**
1345
     * Renders the time element on the frontend.
1346
     */
1347
    public function frontend_render_time_template( $field ) {
1348
        
1349
        echo "<div class='form-group'>";
1350
1351
        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

1351
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1352
            array(
1353
                'name'       => esc_attr( $field['id'] ),
1354
                'id'         => esc_attr( $field['id'] ),
1355
                'required'   => (bool) $field['required'],
1356
                'label'      => wp_kses_post( $field['label'] ),
1357
                'no_wrap'    => true,
1358
                'placeholder' => esc_attr( $field['placeholder'] ),
1359
                'type'       => 'time',
1360
            )
1361
        );
1362
1363
        if ( ! empty( $field['description'] ) ) {
1364
            $description = wp_kses_post( $field['description'] );
1365
            echo "<small class='form-text text-muted'>$description</small>";
1366
        }
1367
1368
        echo '</div>';
1369
1370
    }
1371
1372
    /**
1373
     * Renders the edit time element template.
1374
     */
1375
    public function edit_time_template( $field ) {
1376
        $restrict = $this->get_restrict_markup( $field, 'time' );
1377
        $label    = __( 'Field Label', 'invoicing' );
1378
        $id       = $field . '.id + "_edit"';
1379
        $label2   = __( 'Placeholder text', 'invoicing' );
1380
        $id2      = $field . '.id + "_edit2"';
1381
        $label3   = __( 'Help text', 'invoicing' );
1382
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1383
        $id3      = $field . '.id + "_edit3"';
1384
        $label5   = __( 'Is this field required?', 'invoicing' );
1385
        $id4      = $field . '.id + "_edit4"';
1386
        echo "
1387
            <div $restrict>
1388
                <div class='form-group'>
1389
                    <label :for='$id'>$label</label>
1390
                    <input :id='$id' v-model='$field.label' class='form-control' />
1391
                </div>
1392
                <div class='form-group'>
1393
                    <label :for='$id2'>$label2</label>
1394
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1395
                </div>
1396
                <div class='form-group'>
1397
                    <label :for='$id3'>$label3</label>
1398
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1399
                </div>
1400
                <div class='form-group form-check'>
1401
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1402
                    <label class='form-check-label' :for='$id4'>$label5</label>
1403
                </div>
1404
            </div>
1405
        ";
1406
1407
    }
1408
1409
    /**
1410
     * Renders the number element template.
1411
     */
1412
    public function render_number_template( $field ) {
1413
        $restrict = $this->get_restrict_markup( $field, 'number' );
1414
        $label    = "$field.label";
1415
        echo "
1416
            <div $restrict>
1417
                <label :for='$field.id'>{{" . $label . "}}</label>
1418
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'>
1419
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1420
            </div>    
1421
        ";
1422
    }
1423
1424
    /**
1425
     * Renders the number element on the frontend.
1426
     */
1427
    public function frontend_render_number_template( $field ) {
1428
        
1429
        echo "<div class='form-group'>";
1430
1431
        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

1431
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1432
            array(
1433
                'name'       => esc_attr( $field['id'] ),
1434
                'id'         => esc_attr( $field['id'] ),
1435
                'required'   => (bool) $field['required'],
1436
                'label'      => wp_kses_post( $field['label'] ),
1437
                'placeholder' => esc_attr( $field['placeholder'] ),
1438
                'no_wrap'    => true,
1439
                'type'       => 'number',
1440
            )
1441
        );
1442
1443
        if ( ! empty( $field['description'] ) ) {
1444
            $description = wp_kses_post( $field['description'] );
1445
            echo "<small class='form-text text-muted'>$description</small>";
1446
        }
1447
1448
        echo '</div>';
1449
1450
    }
1451
1452
    /**
1453
     * Renders the edit number element template.
1454
     */
1455
    public function edit_number_template( $field ) {
1456
        $restrict = $this->get_restrict_markup( $field, 'number' );
1457
        $label    = __( 'Field Label', 'invoicing' );
1458
        $id       = $field . '.id + "_edit"';
1459
        $label2   = __( 'Placeholder text', 'invoicing' );
1460
        $id2      = $field . '.id + "_edit2"';
1461
        $label3   = __( 'Help text', 'invoicing' );
1462
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1463
        $id3      = $field . '.id + "_edit3"';
1464
        $label5   = __( 'Is this field required?', 'invoicing' );
1465
        $id4      = $field . '.id + "_edit4"';
1466
        echo "
1467
            <div $restrict>
1468
                <div class='form-group'>
1469
                    <label :for='$id'>$label</label>
1470
                    <input :id='$id' v-model='$field.label' class='form-control' />
1471
                </div>
1472
                <div class='form-group'>
1473
                    <label :for='$id2'>$label2</label>
1474
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1475
                </div>
1476
                <div class='form-group'>
1477
                    <label :for='$id3'>$label3</label>
1478
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1479
                </div>
1480
                <div class='form-group form-check'>
1481
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1482
                    <label class='form-check-label' :for='$id4'>$label5</label>
1483
                </div>
1484
            </div>
1485
        ";
1486
1487
    }
1488
1489
    /**
1490
     * Renders the separator element template.
1491
     */
1492
    public function render_separator_template( $field ) {
1493
        $restrict = $this->get_restrict_markup( $field, 'separator' );
1494
        echo "<hr class='featurette-divider mt-0 mb-2' $restrict>";
1495
    }
1496
1497
    /**
1498
     * Renders the separator element on the frontend.
1499
     */
1500
    public function frontend_render_separator_template( $field ) {
1501
        echo '<hr class="featurette-divider mt-0 mb-2" />';
1502
    }
1503
1504
    /**
1505
     * Renders the pay button element template.
1506
     */
1507
    public function render_pay_button_template( $field ) {
1508
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1509
        $label    = "$field.label";
1510
        echo "
1511
            <div $restrict>
1512
                <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button>
1513
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1514
            </div>    
1515
        ";
1516
    }
1517
1518
    /**
1519
     * Renders the pay_button element on the frontend.
1520
     */
1521
    public function frontend_render_pay_button_template( $field ) {
1522
        
1523
        echo "<div class='form-group'>";
1524
1525
        $class = 'btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1526
        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

1526
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1527
            array(
1528
                'name'       => esc_attr( $field['id'] ),
1529
                'id'         => esc_attr( $field['id'] ),
1530
                'value'      => esc_attr( $field['label'] ),
1531
                'no_wrap'    => true,
1532
                'type'       => 'submit',
1533
                'class'      => $class,
1534
            )
1535
        );
1536
1537
        if ( ! empty( $field['description'] ) ) {
1538
            $description = wp_kses_post( $field['description'] );
1539
            echo "<small class='form-text text-muted'>$description</small>";
1540
        }
1541
1542
        echo '</div>';
1543
1544
    }
1545
1546
    /**
1547
     * Renders the pay button element template.
1548
     */
1549
    public function edit_pay_button_template( $field ) {
1550
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1551
        $label    = __( 'Button Text', 'invoicing' );
1552
        $id       = $field . '.id + "_edit"';
1553
        $label2   = __( 'Help text', 'invoicing' );
1554
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1555
        $id2      = $field . '.id + "_edit2"';
1556
        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1557
        $id3      = $field . '.id + "_edit3"';
1558
        echo "
1559
            <div $restrict>
1560
                <div class='form-group'>
1561
                    <label :for='$id'>$label</label>
1562
                    <input :id='$id' v-model='$field.label' class='form-control' />
1563
                </div>
1564
                <div class='form-group'>
1565
                    <label :for='$id2'>$label2</label>
1566
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
1567
                </div>
1568
                <div class='form-group'>
1569
                    <label :for='$id3'>$label4</label>
1570
1571
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1572
                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1573
                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1574
                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1575
                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1576
                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1577
                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1578
                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1579
                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1580
                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1581
                    </select>
1582
                </div>
1583
            </div>
1584
        ";
1585
1586
    }
1587
1588
    /**
1589
     * Renders the alert element template.
1590
     */
1591
    public function render_alert_template( $field ) {
1592
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1593
        $text     = "$field.text";
1594
        echo "
1595
            <div $restrict class='alert' :class='$field.class' role='alert'>
1596
                <span v-html='$text'></span>
1597
                <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''>
1598
                    <span aria-hidden='true'>&times;</span>
1599
                </button>
1600
            </div>    
1601
        ";
1602
    }
1603
1604
    /**
1605
     * Renders the alert element on the frontend.
1606
     */
1607
    public function frontend_render_alert_template( $field ) {
1608
        
1609
        echo "<div class='form-group'>";
1610
1611
        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

1611
        echo /** @scrutinizer ignore-call */ aui()->alert(
Loading history...
1612
            array(
1613
                'content'     => wp_kses_post( $field['text'] ),
1614
                'dismissible' => $field['dismissible'],
1615
                'type'        => str_replace( 'alert-', '', $field['class'] ),
1616
            )
1617
        );
1618
1619
        echo '</div>';
1620
1621
    }
1622
1623
    /**
1624
     * Renders the alert element template.
1625
     */
1626
    public function edit_alert_template( $field ) {
1627
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1628
        $label    = __( 'Alert Text', 'invoicing' );
1629
        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1630
        $id       = $field . '.id + "_edit"';
1631
        $label3   = __( 'Is Dismissible?', 'invoicing' );
1632
        $id2      = $field . '.id + "_edit2"';
1633
        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1634
        $id3      = $field . '.id + "_edit3"';
1635
        echo "
1636
            <div $restrict>
1637
                <div class='form-group'>
1638
                    <label :for='$id'>$label</label>
1639
                    <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
1640
                </div>
1641
                <div class='form-group form-check'>
1642
                    <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' />
1643
                    <label class='form-check-label' :for='$id2'>$label3</label>
1644
                </div>
1645
                <div class='form-group'>
1646
                    <label :for='$id3'>$label4</label>
1647
1648
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1649
                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1650
                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1651
                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1652
                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1653
                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1654
                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1655
                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1656
                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1657
                    </select>
1658
                </div>
1659
            </div>
1660
        ";
1661
1662
    }
1663
1664
    /**
1665
     * Renders the discount element template.
1666
     */
1667
    public function render_discount_template( $field ) {
1668
        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1669
        ?>
1670
1671
            <div <?php echo $restrict; ?> class="discount_field  border rounded p-3">
1672
                <div class="discount_field_inner d-flex flex-column flex-md-row">
1673
                    <input  :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1674
                    <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button>
1675
                </div>
1676
                <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small>
1677
            </div>
1678
1679
        <?php
1680
    }
1681
1682
    /**
1683
     * Renders the discount element on the frontend.
1684
     */
1685
    public function frontend_render_discount_template( $field ) {
1686
        
1687
        $placeholder = esc_attr( $field['input_label'] );
1688
        $label       = sanitize_text_field( $field['button_label'] );
1689
        $description = '';
1690
1691
        if ( ! empty( $field['description'] ) ) {
1692
            $description = "<small class='form-text text-muted'>{$field['description']}</small>";
1693
        }
1694
?>
1695
1696
    <div class="form-group">
1697
        <div class="discount_field  border rounded p-3">
1698
            <div class="discount_field_inner d-flex flex-column flex-md-row">
1699
                <input  placeholder="<?php echo $placeholder; ?>" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1700
                <a href="#" class="btn btn-secondary submit-button mb-2 wpinv-payment-form-coupon-button"><?php echo $label; ?></a>
1701
            </div>
1702
            <?php echo $description ?>
1703
        </div>
1704
    </div>
1705
1706
<?php
1707
    }
1708
1709
    /**
1710
     * Renders the discount element template.
1711
     */
1712
    public function edit_discount_template( $field ) {
1713
        $restrict = $this->get_restrict_markup( $field, 'discount' );
1714
        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1715
        $label2   = __( 'Help Text', 'invoicing' );
1716
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1717
        $label4   = __( 'Button Text', 'invoicing' );
1718
        $id       = $field . '.id + "_edit"';
1719
        $id2      = $field . '.id + "_edit2"';
1720
        $id3      = $field . '.id + "_edit3"';
1721
        echo "
1722
            <div $restrict>
1723
                <div class='form-group'>
1724
                    <label :for='$id'>$label</label>
1725
                    <input :id='$id' v-model='$field.input_label' class='form-control' />
1726
                </div>
1727
1728
                <div class='form-group'>
1729
                    <label :for='$id2'>$label4</label>
1730
                    <input :id='$id2' v-model='$field.button_label' class='form-control' />
1731
                </div>
1732
1733
                <div class='form-group'>
1734
                    <label :for='$id3'>$label2</label>
1735
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1736
                </div>
1737
1738
            </div>
1739
        ";
1740
1741
    }
1742
1743
    /**
1744
     * Renders the items element template.
1745
     */
1746
    public function render_items_template( $field ) {
1747
        $restrict  = $this->get_restrict_markup( $field, 'items' );
1748
        $label     = __( 'Item totals placeholder. Item totals will appear here. Click to set items.', 'invoicing' );
1749
        echo "<div $restrict class='item_totals p-4 bg-warning'>$label</div>";
1750
    }
1751
1752
    /**
1753
     * Renders the items element on the frontend.
1754
     */
1755
    public function frontend_render_items_template( $field, $items ) {
1756
        
1757
        echo "<div class='form-group item_totals'>";
1758
        
1759
        $id = esc_attr( $field['id'] );
1760
        if ( 'total' == $field[ 'items_type' ] ) {
1761
            $total = 0;
1762
1763
            ?>
1764
            <div class="border item_totals_type_total">
1765
1766
                <?php
1767
                    foreach( $items as $item ) {
1768
                        $total = $total + floatval( $item['price'] );
1769
1770
                        $class  = 'col-8';
1771
                        $class2 = '';
1772
1773
                        if ( ! empty( $item['allow_quantities'] ) ) {
1774
                            $class = 'col-6 pt-2';
1775
                            $class2 = 'pt-2';
1776
                        }
1777
1778
                        if ( ! empty( $item['custom_price'] ) ) {
1779
                            $class .= ' pt-2';
1780
                        }
1781
            
1782
                ?>
1783
                    <div  class="item_totals_item">
1784
                        <div class='row pl-2 pr-2 pt-2'>
1785
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
1786
1787
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1788
1789
                                <div class='col-2'>
1790
                                    <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>
1791
                                </div>
1792
1793
                            <?php } else { ?>
1794
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1795
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1796
1797
                                <div class='col-4 <?php echo $class2; ?>'>
1798
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1799
                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1800
                                </div>
1801
1802
                            <?php } else {?>
1803
1804
                                <div class='col-4'>
1805
                                    <div class='input-group'>
1806
1807
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1808
                                            <div class='input-group-prepend'>
1809
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1810
                                            </div>
1811
                                        <?php } ?>
1812
1813
                                        <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'] ); ?>'>
1814
                                    
1815
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1816
                                            <div class='input-group-append'>
1817
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1818
                                            </div>
1819
                                        <?php } ?>
1820
1821
                                    </div>
1822
                                </div>
1823
                            <?php } ?>
1824
1825
                        </div>
1826
                        <?php if ( ! empty( $item['description'] )) { ?>
1827
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1828
                        <?php } ?>
1829
                    </div>
1830
                <?php } ?>
1831
1832
                <div class='mt-4 border-top item_totals_total'>
1833
                    <div class='row p-2'>
1834
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1835
                        <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>
1836
                    </div>
1837
                </div>
1838
1839
            </div>
1840
        <?php } ?>
1841
1842
        <?php if ( 'radio' == $field[ 'items_type' ] ) { ?>
1843
            <div class="item_totals_type_radio">
1844
1845
                <?php
1846
                    foreach( $items as $index => $item ) {
1847
                
1848
                        if ( ! empty( $item['required'] ) ) {
1849
                            continue;
1850
                        }
1851
                ?>
1852
                    <div  class="form-check">
1853
                        <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'>
1854
                        <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>
1855
                    </div>
1856
                    <?php if ( ! empty( $item['description'] )) { ?>
1857
                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1858
                    <?php } ?>
1859
                <?php } ?>
1860
1861
                <div class="mt-3 border item_totals_type_radio_totals">
1862
1863
                    <?php
1864
1865
                        $total = 0;
1866
1867
                        foreach ( $items as $item ) {
1868
1869
                            $class  = 'col-8';
1870
                            $class2 = '';
1871
1872
                            if ( ! empty( $item['allow_quantities'] ) ) {
1873
                                $class = 'col-6 pt-2';
1874
                                $class2 = 'pt-2';
1875
                            }
1876
1877
                            if ( ! empty( $item['custom_price'] ) ) {
1878
                                $class .= ' pt-2';
1879
                            }
1880
1881
                            $class3 = 'd-none';
1882
                            $name   = '';
1883
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) {
1884
1885
                                $total = $total + floatval( $item['price'] );
1886
                                $class3 = '';
1887
                                $name   = "wpinv-items[{$item['id']}]";
1888
1889
                                if ( empty( $item['required'] ) ) {
1890
                                    $totals_selected_radio_item = 1;
1891
                                }
1892
1893
                            }
1894
1895
                            $class3 .= " wpinv_item_{$item['id']}";
1896
1897
                    ?>
1898
1899
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
1900
                        <div class='row pl-2 pr-2 pt-2'>
1901
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
1902
1903
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1904
1905
                                <div class='col-2'>
1906
                                    <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>
1907
                                </div>
1908
1909
                            <?php } else { ?>
1910
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1911
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1912
1913
                                <div class='col-4 <?php echo $class2; ?>'>
1914
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1915
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1916
                                </div>
1917
1918
                            <?php } else {?>
1919
1920
                                <div class='col-4'>
1921
                                    <div class='input-group'>
1922
1923
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1924
                                            <div class='input-group-prepend'>
1925
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1926
                                            </div>
1927
                                        <?php } ?>
1928
1929
                                        <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'] ); ?>'>
1930
                                    
1931
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1932
                                            <div class='input-group-append'>
1933
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1934
                                            </div>
1935
                                        <?php } ?>
1936
1937
                                    </div>
1938
                                </div>
1939
                            <?php } ?>
1940
1941
                        </div>
1942
                        <?php if ( ! empty( $item['description'] )) { ?>
1943
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1944
                        <?php } ?>
1945
                    </div>
1946
                <?php } ?>
1947
1948
                <div class='mt-4 border-top item_totals_total'>
1949
                    <div class='row p-2'>
1950
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1951
                        <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>
1952
                    </div>
1953
                </div>
1954
1955
            </div>
1956
            </div>
1957
        <?php } ?>
1958
1959
        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
1960
1961
            <div class="item_totals_type_checkbox">
1962
1963
                <?php
1964
                    foreach ( $items as $index => $item ) {
1965
1966
                        if ( ! empty( $item['required'] ) ) {
1967
                            continue;
1968
                        }
1969
1970
                        $title = sanitize_text_field(  $item['title'] );
1971
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
1972
                        $item_id    = esc_attr( $id . "_$index" );
1973
                        $value = esc_attr( $item['id'] );
1974
                        $checked = checked( ! isset( $selected_checkbox_item ), true, false );
1975
                        $selected_checkbox_item = 1;
1976
1977
                        echo "
1978
                            <div class='custom-control custom-checkbox'>
1979
                                <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>
1980
                                <label for='$item_id' class='custom-control-label'>$title &nbsp; ($price)</label>
1981
                            </div>";
1982
1983
                        if ( ! empty( $item['description'] ) ) {
1984
                            echo "<small class='form-text text-muted'>{$item['description']}</small>";
1985
                        }
1986
                    }
1987
                ?>
1988
1989
                <div class="mt-3 border item_totals_type_checkbox_totals">
1990
1991
                    <?php
1992
1993
                        $total = 0;
1994
1995
                        foreach ( $items as $item ) {
1996
1997
                            $class  = 'col-8';
1998
                            $class2 = '';
1999
2000
                            if ( ! empty( $item['allow_quantities'] ) ) {
2001
                                $class = 'col-6 pt-2';
2002
                                $class2 = 'pt-2';
2003
                            }
2004
2005
                            if ( ! empty( $item['custom_price'] ) ) {
2006
                                $class .= ' pt-2';
2007
                            }
2008
2009
                            $class3 = 'd-none';
2010
                            $name  = '';
2011
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) {
2012
2013
                                $total = $total + floatval( $item['price'] );
2014
                                $class3 = '';
2015
                                $name  = "wpinv-items[{$item['id']}]";
2016
2017
                                if ( empty( $item['required'] ) ) {
2018
                                    $totals_selected_checkbox_item = 1;
2019
                                }
2020
2021
                            }
2022
2023
                            $class3 .= " wpinv_item_{$item['id']}";
2024
2025
                    ?>
2026
2027
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2028
                        <div class='row pl-2 pr-2 pt-2'>
2029
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2030
2031
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2032
2033
                                <div class='col-2'>
2034
                                    <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>
2035
                                </div>
2036
2037
                            <?php } else { ?>
2038
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2039
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2040
2041
                                <div class='col-4 <?php echo $class2; ?>'>
2042
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2043
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2044
                                </div>
2045
2046
                            <?php } else {?>
2047
2048
                                <div class='col-4'>
2049
                                    <div class='input-group'>
2050
2051
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2052
                                            <div class='input-group-prepend'>
2053
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2054
                                            </div>
2055
                                        <?php } ?>
2056
2057
                                        <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'] ); ?>'>
2058
                                    
2059
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2060
                                            <div class='input-group-append'>
2061
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2062
                                            </div>
2063
                                        <?php } ?>
2064
2065
                                    </div>
2066
                                </div>
2067
                            <?php } ?>
2068
2069
                        </div>
2070
                        <?php if ( ! empty( $item['description'] )) { ?>
2071
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2072
                        <?php } ?>
2073
                    </div>
2074
                <?php } ?>
2075
2076
                <div class='mt-4 border-top item_totals_total'>
2077
                    <div class='row p-2'>
2078
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2079
                        <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>
2080
                    </div>
2081
                </div>
2082
            </div>
2083
            </div>
2084
        <?php } ?>
2085
2086
        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
2087
2088
            <div class="item_totals_type_select">
2089
2090
                <?php
2091
2092
                    $options  = array();
2093
                    $selected = '';
2094
                    foreach ( $items as $index => $item ) {
2095
2096
                        if ( ! empty( $item['required'] ) ) {
2097
                            continue;
2098
                        }
2099
2100
                        $title = sanitize_text_field(  $item['title'] );
2101
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2102
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2103
2104
                        if ( ! isset( $selected_item ) ) {
2105
                            $selected = $item['id'];
2106
                            $selected_item = 1;
2107
                        }
2108
                        
2109
                    }
2110
2111
                    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

2111
                    echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
2112
                        array(
2113
                                'name'        => 'payment-form-items',
2114
                                'id'          => $id,
2115
                                'placeholder' => __( 'Select an item', 'invoicing' ),
2116
                                'no_wrap'     => true,
2117
                                'options'     => $options,
2118
                                'class'       => 'wpi_select2 wpinv-items-select-selector',
2119
                                'value'       => $selected,
2120
                        )
2121
                    );
2122
                ?>
2123
2124
                <div class="mt-3 border item_totals_type_select_totals">
2125
2126
                    <?php
2127
2128
                        $total = 0;
2129
2130
                        foreach ( $items as $item ) {
2131
2132
                            $class  = 'col-8';
2133
                            $class2 = '';
2134
2135
                            if ( ! empty( $item['allow_quantities'] ) ) {
2136
                                $class = 'col-6 pt-2';
2137
                                $class2 = 'pt-2';
2138
                            }
2139
2140
                            if ( ! empty( $item['custom_price'] ) ) {
2141
                                $class .= ' pt-2';
2142
                            }
2143
2144
                            $class3 = 'd-none';
2145
                            $name  = '';
2146
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2147
2148
                                $total = $total + floatval( $item['price'] );
2149
                                $class3 = '';
2150
                                $name  = "wpinv-items[{$item['id']}]";
2151
2152
                                if ( empty( $item['required'] ) ) {
2153
                                    $totals_selected_select_item = 1;
2154
                                }
2155
2156
                            }
2157
2158
                            $class3 .= " wpinv_item_{$item['id']}";
2159
2160
                    ?>
2161
2162
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2163
                        <div class='row pl-2 pr-2 pt-2'>
2164
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2165
2166
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2167
2168
                                <div class='col-2'>
2169
                                    <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>
2170
                                </div>
2171
2172
                            <?php } else { ?>
2173
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2174
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2175
2176
                                <div class='col-4 <?php echo $class2; ?>'>
2177
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2178
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2179
                                </div>
2180
2181
                            <?php } else {?>
2182
2183
                                <div class='col-4'>
2184
                                    <div class='input-group'>
2185
2186
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2187
                                            <div class='input-group-prepend'>
2188
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2189
                                            </div>
2190
                                        <?php } ?>
2191
2192
                                        <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'] ); ?>'>
2193
                                    
2194
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2195
                                            <div class='input-group-append'>
2196
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2197
                                            </div>
2198
                                        <?php } ?>
2199
2200
                                    </div>
2201
                                </div>
2202
                            <?php } ?>
2203
2204
                        </div>
2205
                        <?php if ( ! empty( $item['description'] )) { ?>
2206
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2207
                        <?php } ?>
2208
                    </div>
2209
                <?php } ?>
2210
2211
                <div class='mt-4 border-top item_totals_total'>
2212
                    <div class='row p-2'>
2213
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2214
                        <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>
2215
                    </div>
2216
                </div>
2217
2218
            </div>
2219
        <?php } ?>
2220
2221
        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
2222
2223
            <div class="item_totals_type_multi_select">
2224
2225
                <?php
2226
2227
                    $options  = array();
2228
                    $selected = array();
2229
2230
                    foreach ( $items as $index => $item ) {
2231
2232
                        if ( ! empty( $item['required'] ) ) {
2233
                            continue;
2234
                        }
2235
                    
2236
                        $title = sanitize_text_field(  $item['title'] );
2237
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2238
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2239
2240
                        if ( ! isset( $selected_item ) ) {
2241
                            $selected = array( $item['id'] );
2242
                            $selected_item = 1;
2243
                        }
2244
2245
                    }
2246
2247
                    echo aui()->select(
2248
                        array(
2249
                                'name'        => 'payment-form-items',
2250
                                'id'          => $id,
2251
                                'no_wrap'     => true,
2252
                                'options'     => $options,
2253
                                'multiple'    => true,
2254
                                'class'       => 'wpi_select2 wpinv-items-multiselect-selector',
2255
                                'value'       => $selected,
2256
                        )
2257
                    );
2258
                ?>
2259
2260
                <div class="mt-3 border item_totals_type_select_totals">
2261
2262
                    <?php
2263
2264
                        $total = 0;
2265
2266
                        foreach ( $items as $item ) {
2267
2268
                            $class  = 'col-8';
2269
                            $class2 = '';
2270
2271
                            if ( ! empty( $item['allow_quantities'] ) ) {
2272
                                $class = 'col-6 pt-2';
2273
                                $class2 = 'pt-2';
2274
                            }
2275
2276
                            if ( ! empty( $item['custom_price'] ) ) {
2277
                                $class .= ' pt-2';
2278
                            }
2279
2280
                            $class3 = 'd-none';
2281
                            $name  = '';
2282
                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2283
2284
                                $total = $total + floatval( $item['price'] );
2285
                                $class3 = '';
2286
                                $name  = "wpinv-items[{$item['id']}]";
2287
2288
                                if ( empty( $item['required'] ) ) {
2289
                                    $totals_selected_select_item = 1;
2290
                                }
2291
2292
                            }
2293
2294
                            $class3 .= " wpinv_item_{$item['id']}";
2295
2296
                    ?>
2297
2298
                    <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2299
                        <div class='row pl-2 pr-2 pt-2'>
2300
                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2301
2302
                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2303
2304
                                <div class='col-2'>
2305
                                    <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>
2306
                                </div>
2307
2308
                            <?php } else { ?>
2309
                                <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2310
                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2311
2312
                                <div class='col-4 <?php echo $class2; ?>'>
2313
                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2314
                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2315
                                </div>
2316
2317
                            <?php } else {?>
2318
2319
                                <div class='col-4'>
2320
                                    <div class='input-group'>
2321
2322
                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2323
                                            <div class='input-group-prepend'>
2324
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2325
                                            </div>
2326
                                        <?php } ?>
2327
2328
                                        <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'] ); ?>'>
2329
                                    
2330
                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2331
                                            <div class='input-group-append'>
2332
                                                <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2333
                                            </div>
2334
                                        <?php } ?>
2335
2336
                                    </div>
2337
                                </div>
2338
                            <?php } ?>
2339
2340
                        </div>
2341
                        <?php if ( ! empty( $item['description'] )) { ?>
2342
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2343
                        <?php } ?>
2344
                    </div>
2345
                <?php } ?>
2346
2347
                <div class='mt-4 border-top item_totals_total'>
2348
                    <div class='row p-2'>
2349
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2350
                        <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>
2351
                    </div>
2352
                </div>
2353
2354
            </div>
2355
        <?php } ?>
2356
        <?php if ( ! empty( $field[ 'description' ] ) ) { ?>
2357
            <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small>
2358
        <?php } ?>
2359
        </div>
2360
        <?php
2361
    }
2362
2363
    /**
2364
     * Renders the items element template.
2365
     */
2366
    public function edit_items_template( $field ) {
2367
        $restrict = $this->get_restrict_markup( $field, 'items' );
2368
        $label    = __( 'Let customers...', 'invoicing' );
2369
        $label2   = __( 'Available Items', 'invoicing' );
2370
        $label3   = esc_attr__( 'Add some help text for this element', 'invoicing' );
2371
        $id       = $field . '.id + "_edit"';
2372
        $id2      = $field . '.id + "_edit2"';
2373
        $id3      = $field . '.id + "_edit3"';
2374
        $id4      = $field . '.id + "_edit4"';
2375
        $label4   = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' );
2376
        $label5   = esc_attr__( 'Allow users to pay what they want', 'invoicing' );
2377
        $label6   = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' );
2378
        $label7   = esc_attr__( 'Allow users to buy several quantities', 'invoicing' );
2379
        $label8   = esc_attr__( 'This item is required', 'invoicing' );
2380
        echo "<div $restrict>
2381
2382
                <label>$label2</label>
2383
2384
                <draggable v-model='form_items' group='selectable_form_items'>
2385
                    <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class='\"item_\" + item.id' :key='item.id'>
2386
2387
                        <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'>
2388
                            <span class='label'>{{item.title}}</span>
2389
                            <span class='price'>({{formatPrice(item.price)}})</span>
2390
                            <span class='toggle-icon'>
2391
                                <span class='dashicons dashicons-arrow-down'></span>
2392
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
2393
                            </span>
2394
                        </div>
2395
2396
                        <div class='wpinv-available-items-editor-body'>
2397
                            <div class='p-2'>
2398
2399
                                <div class='form-group'>
2400
                                    <label :for='$id + item.id'>Item Name</label>
2401
                                    <input :id='$id + item.id' v-model='item.title' class='form-control' />
2402
                                </div>
2403
2404
                                <div class='form-group'>
2405
                                    <label :for='$id + item.id + \"price\"'>Item Price</label>
2406
                                    <input :id='$id + item.id + \"price\"' v-model='item.price' class='form-control' />
2407
                                    <small class='form-text text-muted' v-if='item.custom_price'>$label4</small>
2408
                                </div>
2409
2410
                                <div class='form-group form-check'>
2411
                                    <input :id='$id4 + item.id + \"custom_price\"' v-model='item.custom_price' type='checkbox' class='form-check-input' />
2412
                                    <label class='form-check-label' :for='$id4 + item.id + \"custom_price\"'>$label5</label>
2413
                                </div>
2414
2415
                                <div class='form-group' v-if='item.custom_price'>
2416
                                    <label :for='$id + item.id + \"minimum_price\"'>Minimum Price</label>
2417
                                    <input :id='$id + item.id + \"minimum_price\"' placeholder='0.00' v-model='item.minimum_price' class='form-control' />
2418
                                    <small class='form-text text-muted'>$label6</small>
2419
                                </div>
2420
2421
                                <div class='form-group form-check'>
2422
                                    <input :id='$id + item.id + \"quantities\"' v-model='item.allow_quantities' type='checkbox' class='form-check-input' />
2423
                                    <label class='form-check-label' :for='$id + item.id + \"quantities\"'>$label7</label>
2424
                                </div>
2425
2426
                                <div class='form-group form-check'>
2427
                                    <input :id='$id + item.id + \"required\"' v-model='item.required' type='checkbox' class='form-check-input' />
2428
                                    <label class='form-check-label' :for='$id + item.id + \"required\"'>$label8</label>
2429
                                </div>
2430
2431
                                <div class='form-group'>
2432
                                    <label :for='$id + item.id + \"description\"'>Item Description</label>
2433
                                    <textarea :id='$id + item.id + \"description\"' v-model='item.description' class='form-control'></textarea>
2434
                                </div>
2435
2436
                                <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'>Delete Item</button>
2437
2438
                            </div>
2439
                        </div>
2440
2441
                    </div>
2442
                </draggable>
2443
2444
                <small v-if='! form_items.length' class='form-text text-danger'> You have not set up any items. Please select an item below or create a new item.</small>
2445
2446
                <div class='form-group mt-2'>
2447
2448
                    <select class='form-control custom-select' v-model='selected_item'>
2449
                        <option value=''>"        . __( 'Add an existing item to the form', 'invoicing' ) ."</option>
2450
                        <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
2451
                    </select>
2452
2453
                </div>
2454
2455
                <div class='form-group'>
2456
                    <input type='button' value='Add item' class='button button-primary'  @click.prevent='addSelectedItem' :disabled='selected_item == \"\"'>
2457
                    <small>Or <a href='' @click.prevent='addNewItem'>create a new item</a>.</small>
2458
                </div>
2459
2460
                <div class='form-group mt-5'>
2461
                    <label :for='$id2'>$label</label>
2462
2463
                    <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'>
2464
                        <option value='total'>"        . __( 'Buy all items on the list', 'invoicing' ) ."</option>
2465
                        <option value='radio'>"        . __( 'Select a single item from the list', 'invoicing' ) ."</option>
2466
                        <option value='checkbox'>"     . __( 'Select one or more items on the list', 'invoicing' ) ."</option>
2467
                        <option value='select'>"       . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option>
2468
                        <option value='multi_select'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option>
2469
                    </select>
2470
2471
                </div>
2472
2473
                <div class='form-group'>
2474
                    <label :for='$id3'>Help Text</label>
2475
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
2476
                </div>
2477
2478
            </div>
2479
        ";
2480
2481
    }
2482
2483
    /**
2484
     * Returns an array of all published items.
2485
     */
2486
    public function get_published_items() {
2487
    
2488
        $item_args = array(
2489
            'post_type'      => 'wpi_item',
2490
            'orderby'        => 'title',
2491
            'order'          => 'ASC',
2492
            'posts_per_page' => -1,
2493
            'post_status'    => array( 'publish' ),
2494
        );
2495
    
2496
        $items      = get_posts( apply_filters( 'wpinv_item_dropdown_query_args', $item_args ) );
2497
2498
        if ( empty( $items ) ) {
2499
            return array();
2500
        }
2501
2502
        $options    = array();
2503
        foreach ( $items as $item ) {
2504
            $title            = esc_html( $item->post_title );
2505
            $title           .= wpinv_get_item_suffix( $item->ID, false );
2506
            $id               = absint( $item->ID );
2507
            $price            = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) );
2508
            $recurring        = (bool) get_post_meta( $id, '_wpinv_is_recurring', true );
2509
            $description      = $item->post_excerpt;
2510
            $custom_price     = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true );
2511
            $minimum_price    = (float) get_post_meta( $id, '_minimum_price', true );
2512
            $allow_quantities = false;
2513
            $options[]        = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' );
2514
2515
        }
2516
        return $options;
2517
2518
    }
2519
2520
    /**
2521
     * Returns an array of items for the currently being edited form.
2522
     */
2523
    public function get_form_items( $id = false ) {
2524
        
2525
        if ( empty( $id ) ) {
2526
            return wpinv_get_data( 'sample-payment-form-items' );
2527
        }
2528
        
2529
        $form_elements = get_post_meta( $id, 'wpinv_form_items', true );
2530
2531
        if ( is_array( $form_elements ) ) {
2532
            return $form_elements;
2533
        }
2534
2535
        return wpinv_get_data( 'sample-payment-form-items' );
2536
2537
    }
2538
2539
    /**
2540
     * Returns an array of elements for the currently being edited form.
2541
     */
2542
    public function get_form_elements( $id = false ) {
2543
2544
        if ( empty( $id ) ) {
2545
            return wpinv_get_data( 'sample-payment-form' );
2546
        }
2547
        
2548
        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
2549
2550
        if ( is_array( $form_elements ) ) {
2551
            return $form_elements;
2552
        }
2553
2554
        return wpinv_get_data( 'sample-payment-form' );
2555
    }
2556
2557
}
2558