61 lines
1.8 KiB
Plaintext
61 lines
1.8 KiB
Plaintext
<?php
|
|
|
|
/* Implement hook_menu() */
|
|
function mon_agglo_exportjson_menu() {
|
|
$items['json/newsletters'] = array(
|
|
'page callback' => 'newsletter_export_view',
|
|
'access callback' => TRUE,
|
|
'access arguments' => array('Export json des newsletters'),
|
|
);
|
|
return $items;
|
|
}
|
|
|
|
|
|
function _get_newsletters($user) {
|
|
|
|
$allowedNewsletters = array("372","373","374","375","376","377");
|
|
|
|
$hashAlgo = 'sha1';
|
|
$hashSalt = 'mykey';
|
|
|
|
$form = array();
|
|
|
|
$paramsArray = array(
|
|
'action' => 'read',
|
|
'email' => $user->mail,
|
|
'hash' => hash($hashAlgo, $hashSalt.$user->mail)
|
|
);
|
|
|
|
$results = _mon_agglo_cron_do_post('https://emailingeco.montpellier-agglo.com/ws/index.php', $paramsArray, 'http://preview-preprod.montpellier-agglo.com');
|
|
|
|
|
|
if(strpos($results['header'], 'HTTP/1.1 200 OK') !== FALSE)
|
|
{
|
|
$content = json_decode($results['content']);
|
|
$newsletters = array();
|
|
foreach ($content->newsletter as $id => $name) {
|
|
if (in_array($id, $allowedNewsletters))
|
|
{
|
|
if (in_array($id, $content->subscriptions))
|
|
$newsletters[$name] = True;
|
|
else
|
|
$newsletters[$name] = False;
|
|
}
|
|
}
|
|
$content = array('uid' => $user->uid, 'newsletters' => $newsletters);
|
|
return $content;
|
|
}
|
|
}
|
|
|
|
function newsletter_export_view() {
|
|
if (!array_key_exists('nameid', $_GET))
|
|
return drupal_json_output(array("error" => "You must set param nameid"));
|
|
|
|
$nameid = $_GET['nameid'];
|
|
$ext_user = user_external_load($nameid);
|
|
if (!$ext_user)
|
|
return drupal_json_output(array("error" => "$nameid user not found"));
|
|
return drupal_json_output(_get_newsletters($ext_user));
|
|
}
|
|
|