├── README.md
├── .gitignore
├── config.sample.php
├── importer.php
└── classes
├── NamiConnector.php
├── NamiCleverreachConnector.php
└── rest_client.php
/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | config.php
3 | index.php
4 | mailtest/
5 | wpcs/
--------------------------------------------------------------------------------
/config.sample.php:
--------------------------------------------------------------------------------
1 | compare_nami_and_cleverreach( 'pfadfinder', 958461 );
18 | $nami_cleverreach_connector->reset_members(); //Reset Stored data to get ready for next import
--------------------------------------------------------------------------------
/classes/NamiConnector.php:
--------------------------------------------------------------------------------
1 | https = $https;
14 | $this->url = $url;
15 | $this->Login = "API";
16 | //$this->username = $credentials["username"]"78175"; // NamiNumber
17 | //$this->password = $credentials["password"];
18 | $this->curlOptions = array("CURLOPT_COOKIEJAR" => COOKIE_PATH ,"CURLOPT_COOKIEFILE" => COOKIE_PATH);
19 | //$this->curlOptions = array("CURLOPT_COOKIEJAR" => "/www/htdocs/w00f0942/tmp/cookie.txt" ,"CURLOPT_COOKIEFILE" => "/www/htdocs/w00f0942/tmp/cookie.txt");
20 |
21 | //$this->gid = $this->get_groupid();
22 | $this->gid = "070901";
23 | }
24 |
25 | function call_api($service,$fields = null) {
26 |
27 | if ($this->https == true) {
28 | $serviceurl = "https://" . $this->url . $service;
29 | } else {
30 | $serviceurl = "http://" . $this->url . $service;
31 | }
32 |
33 | $ch = curl_init();
34 |
35 | // setze die URL und andere Optionen
36 | curl_setopt($ch, CURLOPT_URL, $serviceurl);
37 |
38 | if (isset($fields)) {
39 | foreach ($fields as $key => $value)
40 | {
41 | $post_data[$key] = urlencode($value);
42 | }
43 |
44 | //url-ify the data for the POST
45 | $fields_string = '';
46 | foreach($post_data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; /*echo 'test';*/}
47 | rtrim($fields_string,'&');
48 |
49 | curl_setopt($ch, CURLOPT_POST, count($post_data));
50 | curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
51 | }
52 |
53 | curl_setopt($ch, CURLOPT_COOKIEFILE, $this->curlOptions["CURLOPT_COOKIEFILE"]);
54 | curl_setopt($ch, CURLOPT_COOKIEJAR, $this->curlOptions["CURLOPT_COOKIEJAR"]);
55 |
56 | //curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: JSESSIONID=gFUp0xsJeOFSo5e49w-Ryn9n.undefined"));
57 |
58 |
59 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
60 | curl_setopt($ch, CURLOPT_HEADER, false);
61 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
62 |
63 | if ($this->https == true) {
64 | // These options are for https!!!
65 | // Turns off certificate verification --- be carefull!
66 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
67 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
68 | curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
69 | curl_setopt($ch, CURLOPT_PORT , 443);
70 | }
71 |
72 | if(curl_exec($ch) === false)
73 | {
74 | $error ='Curl-Fehler: ' . curl_error($ch);
75 | }
76 | else
77 | {
78 | // führe die Aktion aus und gebe die Daten an den Browser weiter
79 | $result = curl_exec($ch);
80 | //var_dump($result);
81 | $result = json_decode($result , true);
82 | //print_r($result);
83 | $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
84 | //print_r($http_status);
85 | if ( isset($result["statusCode"] ) && $result["statusCode"] <> 0 ) { $error = 'Api-Fehler: ' . $result["statusMessage"];}
86 | }
87 | // var_dump($result);
88 |
89 | if (isset($error)) {echo $error; echo 'error';}
90 | else {return($result);}
91 |
92 | // schließe den cURL-Handle und gebe die Systemresourcen frei
93 | curl_close($ch);
94 | }
95 |
96 | function login($credentials) {
97 |
98 | // preparing the post data
99 | $fields = array(
100 | 'Login' => $this->Login,
101 | 'username' => $credentials["username"],
102 | 'password' => $credentials["password"],
103 | 'redirectTo' => 'app.jsp',
104 |
105 | );
106 |
107 | return $this->call_api("/ica/rest/nami/auth/manual/sessionStartup",$fields);
108 | }
109 |
110 | function get_groups() {
111 | //$result = $this->call_api("/ica/rest/orgadmin/gruppierung/flist?_dc=1353416298860&page=1&start=0&limit=4000");
112 | $result = $this->call_api("/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root?_dc=1477418659231&sort=%5B%7B%22property%22%3A%22leaf%22%2C%22direction%22%3A%22ASC%22%7D%5D&node=root");
113 | //return $result;
114 | //var_dump($result);
115 | $response = $result;
116 | if ($response["responseType"] == "EXCEPTION") {echo $response["message"];} else {
117 | return $response;
118 | }
119 | }
120 |
121 |
122 | function get_groupid() {
123 | // Holt die Gruppierungs-ID des Stammes aus der Nami
124 | $response = $this->get_groups();
125 | $gruppierungen = $response["data"];
126 |
127 | print_r($gruppierungen);
128 |
129 | /*foreach($gruppierungen as $gruppierung) {
130 | if (substr_count($gruppierung["descriptor"],"Essen-Stoppenberg, St. Nikolaus") == 1) {
131 | return $gruppierung["id"];
132 | } else {
133 | echo "Fehler: Der Stamm konnte in der Nami nicht gefunden werden.";
134 | }
135 | }*/
136 | }
137 |
138 | function get_members( $filterString = '', $searchString = '' ) {
139 | $result = $this->call_api("/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/". $this->gid ."/flist?_dc=1477420805317&page=1&start=0&limit=500&filterString=" . $filterString . "&searchString=" . $searchString);
140 | //var_dump($result);
141 | $response = $result;
142 | if ($response["responseType"] == "EXCEPTION") {echo $response["message"];} else {return $response["data"];}
143 | }
144 |
145 | function get_memberdata($name) {
146 | $members = $this->get_members();
147 |
148 | foreach ($members as $member) {
149 | if (substr_count($member["descriptor"],$name) == 1) {
150 | $data = $member["entries"];
151 | return $data;
152 | }
153 | }
154 | }
155 |
156 | function get_membernumber($name) {
157 | $data = $this->get_memberdata($name);
158 | return $data["mitgliedsNummer"];
159 | }
160 | }
161 | ?>
--------------------------------------------------------------------------------
/classes/NamiCleverreachConnector.php:
--------------------------------------------------------------------------------
1 | nami_password = $nami_password;
25 | $this->nami_username = $nami_username;
26 | $this->cleverreach_client_id = $cleverreach_client_id;
27 | $this->cleverreach_login = $cleverreach_login;
28 | $this->cleverreach_password = $cleverreach_password;
29 |
30 | $this->connect_to_apis();
31 | }
32 |
33 | private function connect_to_apis(){
34 |
35 | $this->nami_login();
36 | $this->cleverreach_login();
37 |
38 | }
39 |
40 |
41 | private function cleverreach_login() {
42 |
43 | $this->cleverReachConnector = new CR\tools\rest("https://rest.cleverreach.com/v1");
44 | $this->cleverReachConnector->throwExceptions = true; //default
45 |
46 | $token = $this->cleverReachConnector->post('/login',
47 | array(
48 | "client_id"=> $this->cleverreach_client_id,
49 | "login"=> $this->cleverreach_login,
50 | "password"=>$this->cleverreach_password
51 | )
52 | );
53 | //no error, lets use the key
54 | $this->cleverReachConnector->setAuthMode("jwt", $token);
55 |
56 | }
57 |
58 | private function nami_login() {
59 |
60 | $this->nami = new NamiConnector( true, 'nami.dpsg.de' );
61 | $this->nami->login( array(
62 | "username" => $this->nami_username,
63 | "password" => $this->nami_password
64 | )
65 | );
66 |
67 | }
68 |
69 | private function get_group_receivers( $group_id ) {
70 |
71 | //echo "### Return all receivers from group ###\n";
72 | $receivers = $this->cleverReachConnector->get("/groups/" . $group_id . "/receivers");
73 | foreach ($receivers as $receiver) {
74 | $this->cleverreach_group_receivers[] = $receiver->email;
75 | }
76 |
77 | //var_dump( $this->cleverreach_group_receivers );
78 |
79 | }
80 |
81 |
82 | private function get_nami_members( $filterString, $searchString ) {
83 | $this->nami_members = $this->nami->get_members( $filterString, $searchString );
84 |
85 | foreach ($this->nami_members as $member) {
86 | echo $member['descriptor'] . '
';
87 | }
88 | }
89 |
90 | public function compare_nami_and_cleverreach( $filter, $searchString = '', $groupid ) {
91 | $this->get_group_receivers( $groupid );
92 | $this->get_nami_members($filter, $searchString);
93 |
94 | foreach ( $this->nami_members as $member ) {
95 |
96 | if (!empty($member["entries"]["emailVertretungsberechtigter"])) {
97 |
98 | /*$this->all_nami_member_mails[] = $member["entries"]["emailVertretungsberechtigter"];
99 |
100 | // Check "Vertretungsberechtigter"
101 | if ( in_array( $member["entries"]["emailVertretungsberechtigter"], $this->cleverreach_group_receivers ) ) {
102 | $this->updated_reveivers[] = array(
103 |
104 | "email" => $member["entries"]["emailVertretungsberechtigter"],
105 | );
106 | }else{
107 | $this->new_reveivers[] = array(
108 |
109 | "email" => $member["entries"]["emailVertretungsberechtigter"],
110 | "registered" => time(), //current date
111 | "activated" => time(),
112 | "global_attributes" => array(
113 | "mitgliedsNummer" => $member["entries"]["mitgliedsNummer"],
114 | "Vertretungsberechtigter" => "0",
115 | ),
116 | );
117 | }*/
118 | }
119 |
120 | // Check Mitglied
121 |
122 | if ( !empty( $member["entries"]["email"] ) ) {
123 |
124 | $this->all_nami_member_mails[] = $member["entries"]["email"];
125 |
126 | if ( in_array( $member["entries"]["email"] , $this->cleverreach_group_receivers ) ) {
127 | $this->updated_reveivers[] = array(
128 | "email" => $member["entries"]["email"],
129 | );
130 | }else{
131 |
132 | $this->new_reveivers[] = array(
133 | "email" => $member["entries"]["email"],
134 | "registered" => time(), //current date
135 | "activated" => time(),
136 | "attributes" => array(
137 | "firstname" => $member["entries"]["vorname"],
138 | "lastname" => $member["entries"]["nachname"],
139 | ),
140 | "global_attributes" => array(
141 | "mitgliedsNummer" => $member["entries"]["mitgliedsNummer"],
142 | "Vertretungsberechtigter" => "0",
143 | ),
144 | );
145 | }
146 |
147 | } //check if mail is empty
148 |
149 | }
150 |
151 | echo "