PluginProbe
Mailrelay / 1.6
Mailrelay v1.6
3.0 3.0.1 3.0.2 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 2.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.1.3
mailrelay / sync_users.php

sync_users.php in Mailrelay 1.6, at sync_users.php

107 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!function_exists('is_admin') || !is_admin()) {
3 die('Invalid access.');
4 }
5
6 global $message;
7
8 if (!empty($message)) {
9 echo _e($message, 'mailrelay');
10 }
11
12 $mailrelay_host = get_option('mailrelay_host');
13 $mailrelay_api_key = get_option('mailrelay_api_key');
14
15 ?>
16
17 <div class="wrap">
18
19 <?php
20 screen_icon('options-general');
21 echo '<h2 id="mailrelay_settings">';
22 echo _e('Sync Users', 'mailrelay') . '</h2>';
23 if ($mailrelay_host == '' || $mailrelay_api_key == '') {
24 wp_die('Please fill first the connection settings.');
25 }
26
27 // First thing, init
28 $url = 'https://'. $mailrelay_host .'/ccm/admin/api/version/2/&type=json';
29 $curl = curl_init($url);
30
31 // Call getGroups
32 $params = array(
33 'function' => 'getGroups',
34 'apiKey' => $mailrelay_api_key,
35 'sortField' => 'name',
36 'sortOrder' => 'ASC'
37 );
38 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
39 curl_setopt($curl, CURLOPT_POST, 1);
40 curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
41 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
42 curl_setopt($curl, CURLOPT_SSLVERSION, 3);
43
44 $headers = array(
45 'X-Request-Origin: Wordpress|'. MAILRELAY_PLUGIN_VERSION .'|'. get_bloginfo('version')
46 );
47 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
48
49 $result = curl_exec($curl);
50 $jsonResult = json_decode($result);
51
52 if (!$jsonResult || trim($jsonResult->status) != 1) {
53 global $message;
54 if (is_object($jsonResult)) {
55 if ($jsonResult->error != '') {
56 $message = '<div class="error"><p>' . $jsonResult->error . '</p></div>';
57 } else {
58 $message = '<div class="error"><p>Your account does not have an API key. Please, generate one in your Mailrelay\'s account: Settings -> API access -> Generate new API key.</p></div>';
59 }
60 } else {
61 $message = '<div class="error"><p>Invalid host. Please Retry.</p></div>';
62 }
63 } else {
64 $data = $jsonResult->data;
65 }
66 ?>
67
68 <form name="webservices_form" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
69 <input type="hidden" name="action" value="mailrelay_sync_users_group" />
70
71 <table class="form-table">
72 <tr><th scope="row">
73 <label for="group"><?php _e('Please Select Group', 'mailrelay'); ?></label></th>
74 <td>
75 <select multiple="multiple" name="group[]" size="5" style="height:auto;">
76 <?php foreach($data as $key => $value) { ?>
77 <option value="<?php echo $data[$key]->id; ?>"><?php echo $data[$key]->name; ?></option>
78 <?php } ?>
79 </select>
80 <p><?php _e('All your Wordpress users will be synced with the groups you are choosing now.', 'mailrelay'); ?><br />
81 <?php _e('To create new groups in Mailrelay, you must login into the control panel and click into the Mail Relay > Subscribers groups', 'mailrelay'); ?><br />
82 <?php _e('Once there you can add a new group for your Wordpress users, or edit an existing one', 'mailrelay'); ?></p>
83 </td></tr>
84 </table>
85
86 <p class="submit">
87 <input type="button" onclick="return chk_form();" name="Select groups" value="<?php _e('Start Sync', 'mailrelay') ?>" class="button-primary" />
88 </p>
89 </form>
90
91 </div>
92 <script type="text/javascript">
93 function chk_form() {
94 var chk = check();
95 if (chk != false) {
96 document.webservices_form.submit();
97 document.webservices_form.action = '';
98 }
99 }
100 function check() {
101 if(document.webservices_form['group[]'].value == '') {
102 alert("<?php echo _e('Please select at least one Group.', 'mailrelay'); ?>");
103 return false;
104 }
105 return true;
106 }
107 </script>