-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
174 lines (150 loc) · 6.8 KB
/
Copy pathindex.php
File metadata and controls
174 lines (150 loc) · 6.8 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
<?php
include_once 'config.php';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://api.workflowmax.com/client.api/list?apiKey=" . WORKFLOWMAX_API_KEY . "&accountKey=" . WORKFLOWMAX_ACCOUNT_KEY,
CURLOPT_USERAGENT => 'Mailchimp Connector'
));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
if(!$resp){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
$workflowMaxResponse=json_decode(json_encode(simplexml_load_string($resp)),true);
if($workflowMaxResponse['Status'] != 'OK'){
die('Error: "' . $workflowMaxResponse['Error'] );
}
$workflowMaxClients = array();
foreach ($workflowMaxResponse['Clients']['Client'] as $client) {
$email = (array_key_exists('Email', $client) ? $client['Email']: '');
array_push($workflowMaxClients, array('name' => $client['Name'], 'email' => $email));
}
$mailchimp = new Drewm\MailChimp(MAILCHIMP_API_KEY);
$mailchimpLists = $mailchimp->call('lists/list')['data'];
$lists = array();
foreach ($mailchimpLists as $list) {
$emails = array();
foreach ($mailchimp->call('lists/members', array('id' => $list['id']))['data'] as $subscriber) {
array_push($emails, $subscriber['email']);
}
array_push($lists, array('name' => $list['name'], 'id' => $list['id'], 'emails' => $emails));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>WorkflowMax to Mailchimp</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<h1>WorkflowMax to Mailchimp</h1>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<h2>WorkflowMax Clients</h2>
<table class="table table-bordered" id="clientTable">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>In Selected Mailchimp List?</th>
<th>
<select class="form-control" id="mailchimpList">
<?php foreach($lists as $list){ ?>
<option value="<?php echo $list['id']; ?>"><?php echo $list['name']; ?></option>
<?php } ?>
</select>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($workflowMaxClients as $id=>$details) { ?>
<tr id="<?php echo $id; ?>">
<td id="name_field_<?php echo $id; ?>"><?php echo $details['name']; ?></td>
<td id="email_field_<?php echo $id; ?>"><?php echo $details['email']; ?></td>
<td id="in_mc_field_<?php echo $id; ?>"></td>
<td><button class="btn btn-sm btn-primary" onclick="transfer(<?php echo $id; ?>)">Transfer</button></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript">
var mailchimpLists = <?php echo json_encode($lists); ?>;
$(document).ready(function(){
refreshInMailchimpListColumn();
});
$('#mailchimpList').change(function(){
refreshInMailchimpListColumn();
});
function refreshInMailchimpListColumn(){
var selectedList = $('#mailchimpList').val();
var emails = [];
for(var i = 0; i < mailchimpLists.length; i++){
if(mailchimpLists[i].id == selectedList){
emails = mailchimpLists[i].emails;
}
}
for(var i = 0; i < emails.length; i++){
emails[i] = emails[i].toLowerCase();
}
console.info(emails);
$('#clientTable > tbody > tr').each(function() {
var clientId = $(this).attr('id');
var email = $('#email_field_' + clientId).text().toLowerCase();
var html = '';
console.info(email);
if($.inArray(email, emails) !== -1){
html = 'Yes';
}else{
html = 'No';
}
$('#in_mc_field_' + clientId).html(html);
});
}
function transfer(id){
var name = $('#name_field_' + id).text();
var email = $('#email_field_' + id).text();
var list_id = $('#mailchimpList').val();
$.ajax({
url: 'transfer.php',
type: 'POST',
data: {name: name, email: email, list_id: list_id},
dataType: 'json',
success: function(data){
if(data.success == 1){
for(var i = 0; i < mailchimpLists.length; i++){
if(mailchimpLists[i].id == list_id){
mailchimpLists[i].emails.push(email.toLowerCase());
}
}
refreshInMailchimpListColumn();
}else{
alert('Error occurred: ' + data.error);
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
alert('Error occurred: ' + textStatus);
}
});
}
</script>
</body>
</html>