31 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
55 public $errors = array();
80 if (defined(
"ADHERENT_USE_SPIP") && (ADHERENT_USE_SPIP == 1)) {
94 if (defined(
'ADHERENT_SPIP_SERVEUR') && defined(
'ADHERENT_SPIP_USER') && defined(
'ADHERENT_SPIP_PASS') && defined(
'ADHERENT_SPIP_DB')) {
95 if (ADHERENT_SPIP_SERVEUR !=
'' && ADHERENT_SPIP_USER !=
'' && ADHERENT_SPIP_PASS !=
'' && ADHERENT_SPIP_DB !=
'') {
110 $resource =
getDoliDBInstance(
'mysql', ADHERENT_SPIP_SERVEUR, ADHERENT_SPIP_USER, ADHERENT_SPIP_PASS, ADHERENT_SPIP_DB, ADHERENT_SPIP_PORT);
116 dol_syslog(
'Error when connecting to SPIP '.ADHERENT_SPIP_SERVEUR.
' '.ADHERENT_SPIP_USER.
' '.ADHERENT_SPIP_PASS.
' '.ADHERENT_SPIP_DB, LOG_ERR);
144 $conf->global->ADHERENT_MAILMAN_ADMINPW
147 $curl_url = str_replace($patterns, $replace, $url);
152 return $result[
'content'];
172 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
174 $htpass = crypt($object->pass,
makesalt());
175 $query =
"INSERT INTO spip_auteurs (nom, email, login, pass, htpass, alea_futur, statut) VALUES(\"".dolGetFirstLastname($object->firstname, $object->lastname).
"\",\"".$object->email.
"\",\"".$object->login.
"\",\"$mdpass\",\"$htpass\",FLOOR(32000*RAND()),\"1comite\")";
177 $result = $mydb->query($query);
184 $this->error = $mydb->lasterror();
187 $this->error =
'Failed to connect to SPIP';
190 $this->error =
'BadSPIPConfiguration';
193 $this->error =
'SPIPNotEnabled';
216 $query =
"DELETE FROM spip_auteurs WHERE login = '".$mydb->escape($object->login).
"'";
218 $result = $mydb->query($query);
225 $this->error = $mydb->lasterror();
228 $this->error =
'Failed to connect to SPIP';
231 $this->error =
'BadSPIPConfiguration';
234 $this->error =
'SPIPNotEnabled';
255 $query =
"SELECT login FROM spip_auteurs WHERE login = '".$mydb->escape($object->login).
"'";
257 $result = $mydb->query($query);
260 if ($mydb->num_rows($result)) {
270 $this->error = $mydb->lasterror();
274 $this->error =
'Failed to connect to SPIP';
277 $this->error =
'BadSPIPConfiguration';
280 $this->error =
'SPIPNotEnabled';
297 global $conf, $langs, $user;
299 dol_syslog(get_class($this).
"::add_to_mailman");
301 $this->mladded_ok = array();
302 $this->mladded_ko = array();
304 if (!function_exists(
"curl_init")) {
305 $langs->load(
"errors");
306 $this->error = $langs->trans(
"ErrorFunctionNotAvailableInPHP",
"curl_init");
310 if ($conf->adherent->enabled) {
311 if (!empty($conf->global->ADHERENT_MAILMAN_URL)) {
312 if ($listes ==
'' && !empty($conf->global->ADHERENT_MAILMAN_LISTS)) {
313 $lists = explode(
',', $conf->global->ADHERENT_MAILMAN_LISTS);
315 $lists = explode(
',', $listes);
320 foreach ($lists as $list) {
322 $tmp = explode(
':', $list);
323 if (!empty($tmp[2])) {
325 if ($object->element ==
'member' && $tmp[0] ==
'TYPE' && $object->type != $tmp[1]) {
326 dol_syslog(
"We ignore list ".$list.
" because object member type ".$object->type.
" does not match ".$tmp[1], LOG_DEBUG);
329 if ($object->element ==
'member' && $tmp[0] ==
'CATEG' && !in_array($tmp[1], $categstatic->containing($object->id,
'member',
'label'))) {
330 dol_syslog(
"We ignore list ".$list.
" because object member is not into category ".$tmp[1], LOG_DEBUG);
336 $result = $this->
callMailman($object, $conf->global->ADHERENT_MAILMAN_URL, $list);
338 if ($result ===
false) {
339 $this->mladded_ko[$list] = $object->email;
342 $this->mladded_ok[$list] = $object->email;
345 return count($lists);
347 $this->error =
"ADHERENT_MAILMAN_URL not defined";
365 global $conf, $langs, $user;
367 dol_syslog(get_class($this).
"::del_to_mailman");
369 $this->mlremoved_ok = array();
370 $this->mlremoved_ko = array();
372 if (!function_exists(
"curl_init")) {
373 $langs->load(
"errors");
374 $this->error = $langs->trans(
"ErrorFunctionNotAvailableInPHP",
"curl_init");
378 if ($conf->adherent->enabled) {
379 if (!empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL)) {
380 if ($listes ==
'' && !empty($conf->global->ADHERENT_MAILMAN_LISTS)) {
381 $lists = explode(
',', $conf->global->ADHERENT_MAILMAN_LISTS);
383 $lists = explode(
',', $listes);
388 foreach ($lists as $list) {
390 $tmp = explode(
':', $list);
391 if (!empty($tmp[2])) {
393 if ($object->element ==
'member' && $tmp[0] ==
'TYPE' && $object->type != $tmp[1]) {
394 dol_syslog(
"We ignore list ".$list.
" because object member type ".$object->type.
" does not match ".$tmp[1], LOG_DEBUG);
397 if ($object->element ==
'member' && $tmp[0] ==
'CATEG' && !in_array($tmp[1], $categstatic->containing($object->id,
'member',
'label'))) {
398 dol_syslog(
"We ignore list ".$list.
" because object member is not into category ".$tmp[1], LOG_DEBUG);
404 $result = $this->
callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL, $list);
406 if ($result ===
false) {
407 $this->mlremoved_ko[$list] = $object->email;
410 $this->mlremoved_ok[$list] = $object->email;
413 return count($lists);
415 $this->error =
"ADHERENT_MAILMAN_UNSUB_URL not defined";
dol_hash($chain, $type= '0')
Returns a hash of a string.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
__construct($db)
Constructor.
connectSpip()
Function used to connect to SPIP.
$conf db
API class for accounts.
del_to_mailman($object, $listes= '')
Unsubscribe an email from all mailing-lists Used when a user is resiliated.
if(!function_exists('dol_loginfunction')) makesalt($type=CRYPT_SALT_LENGTH)
Fonction pour initialiser un salt pour la fonction crypt.
isSpipEnabled()
Function used to check if SPIP is enabled on the system.
getURLContent($url, $postorget= 'GET', $param= '', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
Class to manage categories.
callMailman($object, $url, $list)
Function used to connect to Mailman.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
add_to_spip($object)
Fonction qui donne les droits redacteurs dans spip.
checkSpipConfig()
Function used to check if the SPIP config is correct.
del_to_spip($object)
Fonction qui enleve les droits redacteurs dans spip.
is_in_spip($object)
Fonction qui dit si cet utilisateur est un redacteur existant dans spip.
add_to_mailman($object, $listes= '')
Subscribe an email to all mailing-lists.
Class to manage mailman and spip.