|
1
|
|
|
<?php |
|
2
|
|
|
// MUST have WordPress. |
|
3
|
|
|
if ( !defined( 'WPINC' ) ) { |
|
4
|
|
|
exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
class WPInv_Meta_Box_Form_Items { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Outputs the payment forms items select. |
|
11
|
|
|
* |
|
12
|
|
|
* @param WP_Post $post |
|
13
|
|
|
*/ |
|
14
|
|
|
public static function output( $post ) { |
|
15
|
|
|
|
|
16
|
|
|
$items = get_post_meta( $post->ID, 'wpinv_payment_form_items', true ); |
|
17
|
|
|
|
|
18
|
|
|
if ( empty( $items ) || ! is_array( $items ) ) { |
|
19
|
|
|
$items = array(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
?> |
|
23
|
|
|
|
|
24
|
|
|
<div class="wpinv-items-wrap-pending" id="wpinv_items_wrap"> |
|
25
|
|
|
<table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
|
26
|
|
|
|
|
27
|
|
|
<thead> |
|
28
|
|
|
<tr> |
|
29
|
|
|
<th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
30
|
|
|
<th class="title"><?php _e( 'Name', 'invoicing' );?></th> |
|
31
|
|
|
<th class="desc"><?php _e( 'Description', 'invoicing' );?></th> |
|
32
|
|
|
<th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
33
|
|
|
<th class="action"></th> |
|
34
|
|
|
</tr> |
|
35
|
|
|
</thead> |
|
36
|
|
|
|
|
37
|
|
|
<tbody class="wpinv-line-items"> |
|
38
|
|
|
<?php |
|
39
|
|
|
|
|
40
|
|
|
foreach ( $items as $item_data ) { |
|
41
|
|
|
|
|
42
|
|
|
$id = isset( $item_data['id'] ) ? (int) $item_data['id'] : 0; |
|
43
|
|
|
$item = new WPInv_Item( $id ); |
|
44
|
|
|
|
|
45
|
|
|
if ( empty( $item ) || $item->post_type != 'wpi_item' ) { |
|
|
|
|
|
|
46
|
|
|
continue; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$name = isset( $item_data['name'] ) ? sanitize_text_field( $item_data['name'] ) : $item->get_name(); |
|
50
|
|
|
$price = isset( $item_data['price'] ) ? wpinv_format_amount( $item_data['price'] ) : $item->get_price(); |
|
51
|
|
|
$description = isset( $item_data['description'] ) ? esc_textarea( $item_data['description'] ) : $item->get_summary(); |
|
52
|
|
|
|
|
53
|
|
|
?> |
|
54
|
|
|
|
|
55
|
|
|
<tr class="item" data-item-id="<?php echo $id; ?>"> |
|
56
|
|
|
<td class="id"><?php echo $id; ?></td> |
|
57
|
|
|
<td class="title"> |
|
58
|
|
|
<a href="<?php echo esc_url( get_edit_post_link( $id ) ); ?>" target="_blank"><?php echo $name ; ?></a> |
|
59
|
|
|
<?php echo wpinv_get_item_suffix( $id ); ?> |
|
60
|
|
|
</td> |
|
61
|
|
|
<td class="meta"> |
|
62
|
|
|
<?php echo $description ; ?> |
|
63
|
|
|
</td> |
|
64
|
|
|
<td class="price"> |
|
65
|
|
|
<?php echo $price ; ?> |
|
66
|
|
|
</td> |
|
67
|
|
|
</tr> |
|
68
|
|
|
|
|
69
|
|
|
<?php } ?> |
|
70
|
|
|
|
|
71
|
|
|
<tr class="item create-item" style="display:none;" id="wpinv-payment-form-quick-add"> |
|
72
|
|
|
<td class="id"></td> |
|
73
|
|
|
|
|
74
|
|
|
<td class="title"> |
|
75
|
|
|
<input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" id="wpinv_create_payment_form_item_name" /> |
|
76
|
|
|
|
|
77
|
|
|
<div class="wp-clearfix"> |
|
78
|
|
|
<label class="wpi-item-actions"> |
|
79
|
|
|
<span class="input-text-wrap"> |
|
80
|
|
|
<input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-payment-form-save-item"> |
|
81
|
|
|
<input type="button" value="Cancel" class="button button-secondary" id="wpinv-payment-form-cancel-item"> |
|
82
|
|
|
</span> |
|
83
|
|
|
</label> |
|
84
|
|
|
</div> |
|
85
|
|
|
</td> |
|
86
|
|
|
|
|
87
|
|
|
<td class="meta"> |
|
88
|
|
|
<textarea placeholder="<?php esc_attr_e( 'Item description', 'invoicing' ) ?>" id="wpinv_create_payment_form_item_description" class="large-text" rows="3"></textarea> |
|
89
|
|
|
</td> |
|
90
|
|
|
|
|
91
|
|
|
<td class="price"> |
|
92
|
|
|
<input type="text" placeholder="0.00" class="wpi-field-price wpi-price" id="wpinv_create_payment_form_item_price" /> |
|
93
|
|
|
</td> |
|
94
|
|
|
|
|
95
|
|
|
</tr> |
|
96
|
|
|
</tbody> |
|
97
|
|
|
</table> |
|
98
|
|
|
|
|
99
|
|
|
<div class="wpinv-actions"> |
|
100
|
|
|
|
|
101
|
|
|
<?php |
|
102
|
|
|
|
|
103
|
|
|
echo wpinv_item_dropdown( array( |
|
104
|
|
|
'name' => 'wpinv_payment_form_item', |
|
105
|
|
|
'id' => 'wpinv_payment_form_item', |
|
106
|
|
|
'show_recurring' => true, |
|
107
|
|
|
'class' => 'wpi_select2', |
|
108
|
|
|
) ); |
|
109
|
|
|
|
|
110
|
|
|
?> |
|
111
|
|
|
|
|
112
|
|
|
<input type="button" value="<?php esc_attr_e( 'Add item to form', 'invoicing'); ?>" class="button button-primary" id="wpinv-payment-form-add-item" /> |
|
113
|
|
|
<input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-payment-form-new-item" /> |
|
114
|
|
|
|
|
115
|
|
|
</div> |
|
116
|
|
|
</div> |
|
117
|
|
|
<?php |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Outputs the payment options. |
|
122
|
|
|
* |
|
123
|
|
|
* @param WP_Post $post |
|
124
|
|
|
*/ |
|
125
|
|
|
public static function output_options( $post ) { |
|
126
|
|
|
|
|
127
|
|
|
$post_id = ! empty( $post->ID ) ? $post->ID : 0; |
|
|
|
|
|
|
128
|
|
|
$success_page = get_post_meta( $post->ID, 'wpinv_success_page', true ); |
|
129
|
|
|
$button_text = get_post_meta( $post->ID, 'wpinv_button_text', true ); |
|
130
|
|
|
$processing_text = get_post_meta( $post->ID, 'wpinv_processing_text', true ); |
|
131
|
|
|
$supports_quantities = (int) get_post_meta( $post->ID, 'wpinv_form_supports_quantities', true ); |
|
132
|
|
|
$supports_discounts = (int) get_post_meta( $post->ID, 'wpinv_form_supports_discounts', true ); |
|
133
|
|
|
$enable_taxes = (int) get_post_meta( $post->ID, 'wpinv_form_supports_quantities', true ); |
|
134
|
|
|
|
|
135
|
|
|
$values = array( |
|
136
|
|
|
'success_page' => empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page, |
|
137
|
|
|
'button_text' => empty( $button_text ) ? __( 'Pay Now', 'invoicing' ) : $button_text, |
|
138
|
|
|
'processing_text' => empty( $processing_text ) ? __( 'Processing', 'invoicing' ) : $processing_text, |
|
139
|
|
|
'supports_quantities' => empty( $supports_quantities ) ? 0 : 1, |
|
140
|
|
|
'enable_taxes' => empty( $enable_taxes ) ? 0 : 1, |
|
141
|
|
|
'supports_discounts' => empty( $supports_discounts ) ? 0 : 1, |
|
142
|
|
|
); |
|
143
|
|
|
|
|
144
|
|
|
?> |
|
145
|
|
|
|
|
146
|
|
|
<div class="wpinv-items-wrap-pending" id="wpinv_options_wrap"> |
|
147
|
|
|
<table class="form-table"> |
|
148
|
|
|
<tbody> |
|
149
|
|
|
|
|
150
|
|
|
<tr class="form-field-success_page"> |
|
151
|
|
|
<th scope="row"><label for="field_success_page"><?php _e( 'Success Page', 'invoicing' ); ?></label></th> |
|
152
|
|
|
<td> |
|
153
|
|
|
<div> |
|
154
|
|
|
<input type="text" class="regular-text" name="success_page" id="field_success_page" value="<?php echo esc_attr( $values['success_page'] ); ?>"> |
|
|
|
|
|
|
155
|
|
|
<p class="description"><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></p> |
|
156
|
|
|
</div> |
|
157
|
|
|
</td> |
|
158
|
|
|
</tr> |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
</tbody> |
|
162
|
|
|
</table> |
|
163
|
|
|
</div> |
|
164
|
|
|
<?php |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Output fields. |
|
169
|
|
|
* |
|
170
|
|
|
* @param WP_Post $post |
|
171
|
|
|
*/ |
|
172
|
|
|
public static function form_design ( $post ) { |
|
173
|
|
|
?> |
|
174
|
|
|
|
|
175
|
|
|
<div id="wpinv-form-builder" style="display: flex; flex-flow: wrap;"> |
|
176
|
|
|
|
|
177
|
|
|
<div class="wpinv-form-builder-left" style="flex: 0 0 320px;"> |
|
178
|
|
|
<div class="wpinv-form-builder-tabs nav-tab-wrapper"> |
|
179
|
|
|
<a @click.prevent="active_tab='new_item'" class="nav-tab" :class="{ 'nav-tab-active': active_tab=='new_item' }" href="#"><?php _e( 'Add new element', 'invoicing' ); ?></a> |
|
180
|
|
|
<a @click.prevent="active_tab='edit_item'" class="nav-tab" :class="{ 'nav-tab-active': active_tab=='edit_item' }" href="#"><?php _e( 'Edit element', 'invoicing' ); ?></a> |
|
181
|
|
|
</div> |
|
182
|
|
|
|
|
183
|
|
|
<div class="wpinv-form-builder-tab-content bsui" style="margin-top: 16px;"> |
|
184
|
|
|
<div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
|
185
|
|
|
<div class="wpinv-form-builder-add-field-types"> |
|
186
|
|
|
|
|
187
|
|
|
<draggable class="section" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
|
188
|
|
|
<li v-for="element in elements" style="width: 49%; background-color: #fafafa; margin-bottom: 9px; cursor: move; border: 1px solid #eeeeee;" @click.prevent="addField(element)"> |
|
189
|
|
|
<button class="button btn" style="width: 100%; cursor: move;"> |
|
190
|
|
|
<span v-if="element.icon" class="dashicons dashicon-" :class="'dashicon-' + element.icon"></span> |
|
191
|
|
|
{{element.name}} |
|
192
|
|
|
</button> |
|
193
|
|
|
</li> |
|
194
|
|
|
</draggable> |
|
195
|
|
|
|
|
196
|
|
|
</div> |
|
197
|
|
|
</div> |
|
198
|
|
|
|
|
199
|
|
|
<div class="wpinv-form-builder-tab-pane bsui" v-if="active_tab=='edit_item'" style="font-size: 16px;"> |
|
200
|
|
|
<div class="wpinv-form-builder-edit-field-wrapper"> |
|
201
|
|
|
<?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
202
|
|
|
<div> |
|
203
|
|
|
<button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)"><?php _e( 'Delete Field', 'invoicing' ); ?></button> |
|
204
|
|
|
</div> |
|
205
|
|
|
</div> |
|
206
|
|
|
</div> |
|
207
|
|
|
|
|
208
|
|
|
</div> |
|
209
|
|
|
</div> |
|
210
|
|
|
|
|
211
|
|
|
<div class="wpinv-form-builder-right" style="flex: 1; padding-top: 40px;border-left: 1px solid #ddd;padding-left: 20px;min-height: 400px;margin-left: 10px;"> |
|
212
|
|
|
|
|
213
|
|
|
<draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;"> |
|
214
|
|
|
<div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element && active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
|
215
|
|
|
<?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
216
|
|
|
</div> |
|
217
|
|
|
</draggable> |
|
218
|
|
|
</div> |
|
219
|
|
|
|
|
220
|
|
|
</div> |
|
221
|
|
|
|
|
222
|
|
|
<?php |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
public static function save( $post_id, $data, $post ) { |
|
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|