forked from wp-premium/gravityforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_columns.php
300 lines (258 loc) · 8.68 KB
/
select_columns.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php
// For backwards compatibility, load WordPress if it hasn't been loaded yet
// Will be used if this file is being called directly
if ( ! class_exists( 'RGForms' ) ) {
for ( $i = 0; $i < $depth = 10; $i ++ ) {
$wp_root_path = str_repeat( '../', $i );
if ( file_exists( "{$wp_root_path}wp-load.php" ) ) {
require_once( "{$wp_root_path}wp-load.php" );
require_once( "{$wp_root_path}wp-admin/includes/admin.php" );
break;
}
}
auth_redirect();
}
/**
* Class GFSelectColumns
*
* Handles the changing of what columns are shown on the Entry page
*
* @since Unknown
*/
class GFSelectColumns {
/**
* Renders the column selection page.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::get_form_meta()
* @uses GFFormsModel::get_grid_columns()
* @uses GFSelectColumns::get_selectable_entry_meta()
* @uses GFFormsModel::convert_field_objects()
* @uses GFFormsModel::get_input_type()
* @uses GF_Field::get_entry_inputs()
* @uses GFCommon::get_label()
*
* @return void
*/
public static function select_columns_page() {
$form_id = absint( $_GET['id'] );
if ( empty( $form_id ) ) {
echo __( 'Oops! We could not locate your form. Please try again.', 'gravityforms' );
exit;
}
?>
<html>
<head>
<?php
wp_print_styles( array( 'wp-admin', 'colors-fresh' ) );
wp_print_scripts( array( 'jquery-ui-sortable' ) );
//adds touchscreen support on mobile devices
if ( wp_is_mobile() ) {
wp_print_scripts( array( 'jquery-touch-punch' ) );
}
?>
<style type="text/css">
body {
font-family: "Lucida Grande", Verdana, Arial, sans-serif;
}
#sortable_available, #sortable_selected {
list-style-type: none;
margin: 0;
padding: 2px;
height: 250px;
border: 1px solid #eaeaea;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-khtml-border-radius: 4px;
border-radius: 4px;
background-color: #FFF;
overflow: auto;
}
#sortable_available li, #sortable_selected li {
margin: 0 2px 2px 2px;
padding: 2px;
width: 96%;
border: 1px solid white;
cursor: pointer;
font-size: 13px;
}
.field_hover {
border: 1px dashed #2175A9 !important;
}
.placeholder {
background-color: #FFF0A5;
height: 20px;
}
.gcolumn_wrapper {
height: 290px;
padding: 0 20px;
}
.gcolumn_container_left, .gcolumn_container_right {
width: 46%;
}
.gcolumn_container_left {
float: left;
}
.gcolumn_container_right {
float: right;
}
.gform_select_column_heading {
font-weight: bold;
padding-bottom: 7px;
font-size: 13px;
}
.column-arrow-mid {
float: left;
width: 45px;
height: 250px;
background-image: url(<?php echo GFCommon::get_base_url(); ?>/images/arrow-rightleft.png);
background-repeat: no-repeat;
background-position: center center;
margin-top: 26px;
}
.panel-instructions {
border-bottom: 1px solid #dfdfdf;
color: #555;
font-size: 11px;
padding: 10px 20px;
margin-bottom: 6px
}
div.panel-buttons {
margin-top: 8px;
padding: 0 20px;
}
div.panel-buttons {
*margin-top: 0px
}
/* ie specific */
</style>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#sortable_available, #sortable_selected").sortable({connectWith: '.sortable_connected', placeholder: 'placeholder'});
jQuery(".sortable_connected li").hover(
function () {
jQuery(this).addClass("field_hover");
},
function () {
jQuery(this).removeClass("field_hover");
}
);
});
var columns = new Array();
function SelectColumns() {
jQuery("#sortable_selected li").each(function () {
columns.push(this.id);
});
self.parent.parent.ChangeColumns(columns);
}
</script>
</head>
<body>
<?php
$columns = RGFormsModel::get_grid_columns( $form_id );
$field_ids = array_keys( $columns );
$form = RGFormsModel::get_form_meta( $form_id );
array_push( $form['fields'], array( 'id' => 'id', 'label' => __( 'Entry Id', 'gravityforms' ) ) );
array_push( $form['fields'], array( 'id' => 'date_created', 'label' => __( 'Entry Date', 'gravityforms' ) ) );
array_push( $form['fields'], array( 'id' => 'ip', 'label' => __( 'User IP', 'gravityforms' ) ) );
array_push( $form['fields'], array( 'id' => 'source_url', 'label' => __( 'Source Url', 'gravityforms' ) ) );
array_push( $form['fields'], array( 'id' => 'payment_status', 'label' => __( 'Payment Status', 'gravityforms' ) ) );
array_push( $form['fields'], array( 'id' => 'transaction_id', 'label' => __( 'Transaction Id', 'gravityforms' ) ) );
array_push( $form['fields'], array( 'id' => 'payment_amount', 'label' => __( 'Payment Amount', 'gravityforms' ) ) );
array_push( $form['fields'], array( 'id' => 'payment_date', 'label' => __( 'Payment Date', 'gravityforms' ) ) );
array_push( $form['fields'], array( 'id' => 'created_by', 'label' => __( 'User', 'gravityforms' ) ) );
$form = self::get_selectable_entry_meta( $form );
$form = GFFormsModel::convert_field_objects( $form );
?>
<div class="panel-instructions"><?php esc_html_e( 'Drag & drop to order and select which columns are displayed in the entries table.', 'gravityforms' ) ?></div>
<div class="gcolumn_wrapper">
<div class="gcolumn_container_left">
<div class="gform_select_column_heading"><?php esc_html_e( 'Active Columns', 'gravityforms' ); ?></div>
<ul id="sortable_selected" class="sortable_connected">
<?php
foreach ( $columns as $field_id => $field_info ) {
?>
<li id="<?php echo esc_attr( $field_id ) ?>"><?php echo esc_html( $field_info['label'] ) ?></li>
<?php
}
?>
</ul>
</div>
<div class="column-arrow-mid"></div>
<div class="gcolumn_container_right" id="available_column">
<div class="gform_select_column_heading"> <?php esc_html_e( 'Inactive Columns', 'gravityforms' ); ?></div>
<ul id="sortable_available" class="sortable_connected">
<?php
foreach ( $form['fields'] as $field ) {
/* @var GF_Field $field */
if ( RGFormsModel::get_input_type( $field ) == 'checkbox' && ! in_array( $field->id, $field_ids ) ) {
?>
<li id="<?php echo esc_attr( $field->id ); ?>"><?php echo esc_html( GFCommon::get_label( $field ) ) ?></li>
<?php
}
$inputs = $field->get_entry_inputs();
$input_type = GFFormsModel::get_input_type( $field );
$display = ! in_array( $input_type, array( 'list', 'repeater' ) );
/**
* Allows fields to be added or removed from the select columns UI on the entry list.
*
* @since 2.4
*
* @param bool $display Whether the field will be available for selection.
* @param GF_Field $field
* @param array $form
*/
$display = gf_apply_filters( array( 'gform_display_field_select_columns_entry_list', $form_id, $field->id ), $display, $field, $form );
if ( is_array( $inputs ) ) {
foreach ( $inputs as $input ) {
if ( rgar( $input, 'isHidden' ) ) {
continue;
}
if ( ! in_array( $input['id'], $field_ids ) && ! ( $field->type == 'creditcard' && in_array( $input['id'], array( floatval( "{$field->id}.2" ), floatval( "{$field->id}.3" ), floatval( "{$field->id}.5" ) ) ) ) ) {
?>
<li id="<?php echo esc_attr( $input['id'] ); ?>"><?php echo esc_html( GFCommon::get_label( $field, $input['id'] ) ); ?></li>
<?php
}
}
} else if ( ! $field->displayOnly && ! in_array( $field->id, $field_ids ) && $display ) {
?>
<li id="<?php echo $field->id ?>"><?php echo esc_html( GFCommon::get_label( $field ) ); ?></li>
<?php
}
}
?>
</ul>
</div>
</div>
<div class="panel-buttons">
<input type="button" value=" <?php esc_attr_e( 'Save', 'gravityforms' ); ?> " class="button-primary" onclick="SelectColumns();" onkeypress="SelectColumns();" />
<input type="button" value="<?php esc_attr_e( 'Cancel', 'gravityforms' ); ?>" class="button" onclick="self.parent.tb_remove();" onkeypress="self.parent.tb_remove();" />
</div>
</body>
</html>
<?php
}
/**
* Adds the entry meta to the Form object.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::get_entry_meta()
*
* @param array $form The Form object.
*
* @return array $form The Form object.
*/
public static function get_selectable_entry_meta( $form ) {
$entry_meta = GFFormsModel::get_entry_meta( $form['id'] );
$keys = array_keys( $entry_meta );
foreach ( $keys as $key ) {
array_push( $form['fields'], array( 'id' => $key, 'label' => $entry_meta[ $key ]['label'] ) );
}
return $form;
}
}
GFSelectColumns::select_columns_page();