feeds.php
8.58 KB
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
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} ?> <style type="text/css">
.user-list tr {
cursor: move;
}
.user-list tr td a {
cursor: pointer;
}
.user-list tr:nth-child(even) {
background-color: #f5f5f5;
}
.vx_col{
width: 35px; padding-top: 12px !important; text-align: center; cursor: auto;
}
.vx_date{
width: 18%;
}
.ui-sortable-helper {
display: table;
background: #eee;
}
</style>
<div class="vx_wrap">
<h2 class="vx_img_head"><img alt="<?php esc_html_e("Mailchimp Feeds", 'contact-form-mailchimp-crm') ?>" title="<?php esc_html_e("Mailchimp Feeds", 'contact-form-mailchimp-crm') ?>" src="<?php echo $this->get_base_url()?>images/mailchimp-crm-logo.png?ver=1" /> <?php esc_html_e("Mailchimp Feeds", 'contact-form-mailchimp-crm'); ?> <a class="page-title-action" href="<?php echo $new_feed_link?>">
<?php esc_html_e("Add New", 'contact-form-mailchimp-crm') ?>
</a> </h2>
<div class="clear"></div>
<?php
if(!$valid_accounts){
?>
<div class="error below-h2" id="message" style="margin-top:20px;">
<p><?php echo sprintf( esc_html__("To get started, please configure your %s Mailchimp Settings %s.", 'contact-form-mailchimp-crm'), '<a href="'.esc_url($page_link).'">', "</a>") ?></p>
</div>
<?php
}
?>
<form id="feed_form" method="post">
<?php wp_nonce_field('vx_crm_ajax') ?>
<input type="hidden" id="action" name="action"/>
<input type="hidden" id="action_argument" name="action_argument"/>
<div class="tablenav">
<div class="alignleft actions" style="padding:8px 0 7px; ">
<label class="hidden" for="bulk_action">
<?php esc_html_e("Bulk action", 'contact-form-mailchimp-crm') ?>
</label>
<select name="bulk_action" id="bulk_action" style="width: 200px">
<option value=''>
<?php esc_html_e("Bulk action", 'contact-form-mailchimp-crm') ?>
</option>
<option value='delete'>
<?php esc_html_e("Delete", 'contact-form-mailchimp-crm') ?>
</option>
</select>
<button type="submit" title="<?php esc_html_e("Apply Action", 'contact-form-mailchimp-crm') ?>" class="button" id="vx_bulk_actions_submit">
<?php esc_html_e("Apply", 'contact-form-mailchimp-crm') ?>
</button>
</div>
</div>
<table class="widefat fixed sort" cellspacing="0">
<thead>
<tr>
<td id="cb" class="column-cb check-column" style=""><input type="checkbox" /></td>
<th id="active" class="vx_col"></th>
<th><?php esc_html_e("Name", 'contact-form-mailchimp-crm') ?></th>
<th><?php esc_html_e("Mailchimp Object", 'contact-form-mailchimp-crm') ?></th>
<th><?php esc_html_e("Primary Key", 'contact-form-mailchimp-crm'); ?></th>
<th class="vx_date"><?php esc_html_e("Created", 'contact-form-mailchimp-crm') ?></th>
</tr>
</thead>
<tfoot>
<tr>
<td id="cb" class="column-cb check-column" style=""><input type="checkbox" /></td>
<th id="active" class="vx_col"></th>
<th><?php esc_html_e("Name", 'contact-form-mailchimp-crm') ?></th>
<th><?php esc_html_e("Mailchimp Object", 'contact-form-mailchimp-crm') ?></th>
<th><?php esc_html_e("Primary Key", 'contact-form-mailchimp-crm'); ?></th>
<th class="vx_date"><?php esc_html_e("Created", 'contact-form-mailchimp-crm') ?></th>
</tr>
</tfoot>
<tbody class="list:user user-list">
<?php
if(is_array($feeds) && !empty($feeds)){
$objects=$this->get_objects();
foreach($feeds as $feed){
$data=$this->post('data',$feed);
$meta=$this->post('meta',$feed);
$data=json_decode($data,true);
$fields=json_decode($meta,true);
$fields=$this->post('fields',$fields);
$primary_key=!empty($data['primary_key']) && isset($fields[$data['primary_key']]['label']) ? $fields[$data['primary_key']]['label'] : esc_html__('N/A','contact-form-mailchimp-crm');
$edit_link=$this->get_feed_link($feed['id']);
if(isset($objects[$feed['object']])){
$feed['object']=$objects[$feed['object']];
}else{
$feed['object']='';
}
?>
<tr class='author-self status-inherit' data-id="<?php echo $feed['id'] ?>">
<th scope="row" class="check-column"><input type="checkbox" class="vx_check" name="feed[]" value="<?php echo $feed["id"] ?>"/></th>
<td class="vx_col"><img src="<?php echo $this->get_base_url() ?>images/active<?php echo intval($feed["is_active"]) ?>.png" alt="<?php echo $feed["is_active"] ? esc_html__("Active", 'contact-form-mailchimp-crm') : esc_html__("Inactive", 'contact-form-mailchimp-crm');?>" title="<?php echo $feed["is_active"] ? esc_html__("Active", 'contact-form-mailchimp-crm') : esc_html__("Inactive", 'contact-form-mailchimp-crm');?>" class="vx_toggle_status" /></td>
<td><a href="<?php echo $edit_link ?>" title="<?php echo esc_html( $feed["name"] ) ?>"><?php echo esc_attr($feed["name"]) ?></a>
<div class="row-actions"> <span class="edit">
<a title="<?php esc_attr_e("Edit Settings", 'contact-form-mailchimp-crm') ?>" href="<?php echo $edit_link ?>">
<?php esc_html_e("Edit", 'contact-form-mailchimp-crm') ?>
</a> |
</span>
<span class="edit">
<a title="<?php esc_html_e("Delete", 'contact-form-mailchimp-crm') ?>" href="#" class="vx_del_feed">
<?php esc_html_e("Delete", 'contact-form-mailchimp-crm')?>
</a>
</span>
</div></td>
<td><p><?php echo $feed["object"]; ?></p></td>
<td><p><?php echo $primary_key; ?></p></td>
<td><p><?php echo date('M-d-Y H:i:s', strtotime($feed['time'])+$offset); ?></p></td>
</tr>
<?php
}
}
else {
if($valid_accounts){
?>
<tr>
<td colspan="4" style="padding:20px;"><?php echo sprintf(esc_html__("You don't have any Mailchimp feeds configured. Let's go %s create one %s!", 'contact-form-mailchimp-crm'), '<a href="'.$new_feed_link.'">', "</a>"); ?></td>
</tr>
<?php
}
else{
?>
<tr>
<td colspan="4" style="padding:20px;"><?php echo sprintf(esc_html__("To get started, please configure your %s Mailchimp Settings%s.", 'contact-form-mailchimp-crm'), '<a href="'.esc_url($page_link).'">', "</a>"); ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</form>
</div>
<?php
do_action('vx_plugin_upgrade_notice_'.$this->type);
?>
<script type="text/javascript">
var vx_crm_nonce='<?php echo wp_create_nonce("vx_crm_ajax") ?>';
(function( $ ) {
$(document).ready( function($) {
$(".vx_del_feed").click(function(e){
e.preventDefault();
if(!confirm("<?php esc_html_e("Delete this feed? 'Cancel' to stop, 'OK' to delete.", 'contact-form-mailchimp-crm') ?>")){
return;
}
var id=$(this).closest('tr').data('id');
jQuery("#action_argument").val(id);
jQuery("#action").val("delete");
jQuery("#feed_form")[0].submit();
});
$(".vx_toggle_status").click(function(e){
e.preventDefault();
var feed_id;
var img=this;
var is_active = img.src.indexOf("active1.png") >=0
var $img=$(this);
if(is_active){
img.src=img.src.replace("active1.png", "active0.png");
$img.attr('title','<?php esc_html_e("Inactive", 'contact-form-mailchimp-crm') ?>').attr('alt', '<?php esc_html_e("Inactive", 'contact-form-mailchimp-crm') ?>');
}
else{
img.src = img.src.replace("active0.png", "active1.png");
$img.attr('title','<?php esc_html_e("Active", 'contact-form-mailchimp-crm') ?>').attr('alt', '<?php esc_html_e("Active", 'contact-form-mailchimp-crm') ?>');
}
if(feed_id = $img.closest('tr').attr('data-id')) {
$.post(ajaxurl,{action:"update_feed_<?php echo esc_attr($this->id) ?>",vx_crm_ajax:vx_crm_nonce,feed_id:feed_id,is_active:is_active ? 0 : 1})
}
});
$("#vx_bulk_actions_submit").click(function(e){
if($("#bulk_action").val() == ""){
alert('<?php esc_html_e('Please Select Action','contact-form-mailchimp-crm') ?>');
return false;
}
if($(".vx_check:checked").length == 0){
alert('<?php esc_html_e('Please Select Feed','contact-form-mailchimp-crm') ?>');
return false;
}
if(!confirm('<?php esc_html_e("Are you sure to Delete selected feeds?",'contact-form-mailchimp-crm'); ?>' )){
return false;
}
})
$('.sort tbody').sortable({
axis: 'y',
helper: "clone",
helper: function(e, tr)
{
var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function(index)
{
// Set helper cell sizes to match the original sizes
$(this).width($originals.eq(index).width());
});
return $helper;
},
update: function(event, ui){
var data = {
'action': 'update_feed_sort_<?php echo esc_attr($this->id) ?>',
'sort': [],
'vx_crm_ajax': vx_crm_nonce,
};
$(this).children().each(function(index, element) {
var id = $(element).attr('data-id')
data.sort.push(id);
})
$.post( ajaxurl, data );
}
});
});
}(jQuery));
</script>