Passed
Push — master ( a86610...a56393 )
by Brian
04:15
created

render_select_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 9.9
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='mt-4 mb-4'>";
1524
            do_action( 'wpinv_payment_mode_select' );
1525
        echo "</div>";
1526
1527
        echo "<div class='form-group'>";
1528
1529
        $class = 'btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1530
        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

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

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

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

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

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

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

Loading history...
2585
2586
    }
2587
2588
}
2589