}
}
+ public static function syncMailchimp() {
+ global $core;
+
+ set_time_limit(0);
+ $api = new CubeIT_Services_Mailchimp('2abe038d70806d50b23b7a37aa2f6067-us12');
+
+ $u = array();
+
+ $r = $core->con->select('SELECT * FROM utilisateurs');
+ while ($r->fetch()) {
+ $u[$r->utilisateur_id] = $r->row();
+ }
+
+ $r = $core->con->select("SELECT * FROM entreprises_ws WHERE revendeur='Cubedesigners' AND ws_grade<=4 AND ws_grade>0");
+ while ($r->fetch()) {
+ $e[$r->entreprise_id] = array('COUNTRY' => $r->pays, 'CONTACT' => date('d/m/Y', $r->date_creation), 'LASTACTION' => date('d/m/Y', $r->date_creation), 'COMPANY' => $r->nom, 'RESSELER' => ($r->ws_grade > 2) ? 1 : 0, 'FLUIDBOOKS' => 0, 'TURNOVER' => 0);
+ }
+
+ $r = $core->con->select("SELECT * FROM entreprises_vue");
+ while ($r->fetch()) {
+ if (isset($e[$r->entreprise_id])) {
+ $e[$r->entreprise_id]['TURNOVER'] = $r->ca;
+ }
+ }
+
+ $rr = $core->con->select('SELECT COUNT(*) AS nb,MAX(`date`) AS lastdate,facturable_id FROM books_vue WHERE status >= 0 GROUP BY facturable_id');
+ while ($rr->fetch()) {
+ $eid = $u[$rr->facturable_id]['entreprise'];
+ if (isset($e[$eid])) {
+ $e[$eid]['FLUIDBOOKS'] = $rr->nb;
+ $e[$eid]['LASTACTION'] = date('d/m/Y', $rr->lastdate);
+ }
+ }
+
+ $batch = array();
+ foreach ($u as $user) {
+ if (!isset($e[$user['entreprise']])) {
+ continue;
+ }
+ if (stristr($user['email'], 'extranet.cubedesigners.com')) {
+ continue;
+ }
+
+ $batch[] = array_merge($e[$user['entreprise']], array('email' => $user['email'], 'LOCALE' => $user['lang'], 'FNAME' => $user['prenom'], 'LNAME' => $user['nom']));
+ }
+
+ $res = $api->batchSubscribe('69f69a2bb8', $batch);
+ echo '<pre>' . print_r($res, true) . '</pre>';
+ }
+
}