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();
142 $conf->global->ADHERENT_MAILMAN_ADMIN_PASSWORD
145 $curl_url = str_replace($patterns, $replace, $url);
150 return $result[
'content'];
170 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
172 $htpass = crypt($object->pass,
makesalt());
173 $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\")";
175 $result = $mydb->query($query);
182 $this->error = $mydb->lasterror();
185 $this->error =
'Failed to connect to SPIP';
188 $this->error =
'BadSPIPConfiguration';
191 $this->error =
'SPIPNotEnabled';
214 $query =
"DELETE FROM spip_auteurs WHERE login = '".$mydb->escape($object->login).
"'";
216 $result = $mydb->query($query);
223 $this->error = $mydb->lasterror();
226 $this->error =
'Failed to connect to SPIP';
229 $this->error =
'BadSPIPConfiguration';
232 $this->error =
'SPIPNotEnabled';
253 $query =
"SELECT login FROM spip_auteurs WHERE login = '".$mydb->escape($object->login).
"'";
255 $result = $mydb->query($query);
258 if ($mydb->num_rows($result)) {
268 $this->error = $mydb->lasterror();
272 $this->error =
'Failed to connect to SPIP';
275 $this->error =
'BadSPIPConfiguration';
278 $this->error =
'SPIPNotEnabled';
295 global $conf, $langs, $user;
297 dol_syslog(get_class($this).
"::add_to_mailman");
299 $this->mladded_ok = array();
300 $this->mladded_ko = array();
302 if (!function_exists(
"curl_init")) {
303 $langs->load(
"errors");
304 $this->error = $langs->trans(
"ErrorFunctionNotAvailableInPHP",
"curl_init");
308 if ($conf->adherent->enabled) {
309 if (!empty($conf->global->ADHERENT_MAILMAN_URL)) {
310 if ($listes ==
'' && !empty($conf->global->ADHERENT_MAILMAN_LISTS)) {
311 $lists = explode(
',', $conf->global->ADHERENT_MAILMAN_LISTS);
313 $lists = explode(
',', $listes);
318 foreach ($lists as $list) {
320 $tmp = explode(
':', $list);
321 if (!empty($tmp[2])) {
323 if ($object->element ==
'member' && $tmp[0] ==
'TYPE' && $object->type != $tmp[1]) {
324 dol_syslog(
"We ignore list ".$list.
" because object member type ".$object->type.
" does not match ".$tmp[1], LOG_DEBUG);
327 if ($object->element ==
'member' && $tmp[0] ==
'CATEG' && !in_array($tmp[1], $categstatic->containing($object->id,
'member',
'label'))) {
328 dol_syslog(
"We ignore list ".$list.
" because object member is not into category ".$tmp[1], LOG_DEBUG);
334 $result = $this->
callMailman($object, $conf->global->ADHERENT_MAILMAN_URL, $list);
336 if ($result ===
false) {
337 $this->mladded_ko[$list] = $object->email;
340 $this->mladded_ok[$list] = $object->email;
343 return count($lists);
345 $this->error =
"ADHERENT_MAILMAN_URL not defined";
363 global $conf, $langs, $user;
365 dol_syslog(get_class($this).
"::del_to_mailman");
367 $this->mlremoved_ok = array();
368 $this->mlremoved_ko = array();
370 if (!function_exists(
"curl_init")) {
371 $langs->load(
"errors");
372 $this->error = $langs->trans(
"ErrorFunctionNotAvailableInPHP",
"curl_init");
376 if ($conf->adherent->enabled) {
377 if (!empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL)) {
378 if ($listes ==
'' && !empty($conf->global->ADHERENT_MAILMAN_LISTS)) {
379 $lists = explode(
',', $conf->global->ADHERENT_MAILMAN_LISTS);
381 $lists = explode(
',', $listes);
386 foreach ($lists as $list) {
388 $tmp = explode(
':', $list);
389 if (!empty($tmp[2])) {
391 if ($object->element ==
'member' && $tmp[0] ==
'TYPE' && $object->type != $tmp[1]) {
392 dol_syslog(
"We ignore list ".$list.
" because object member type ".$object->type.
" does not match ".$tmp[1], LOG_DEBUG);
395 if ($object->element ==
'member' && $tmp[0] ==
'CATEG' && !in_array($tmp[1], $categstatic->containing($object->id,
'member',
'label'))) {
396 dol_syslog(
"We ignore list ".$list.
" because object member is not into category ".$tmp[1], LOG_DEBUG);
402 $result = $this->
callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL, $list);
404 if ($result ===
false) {
405 $this->mlremoved_ko[$list] = $object->email;
408 $this->mlremoved_ok[$list] = $object->email;
411 return count($lists);
413 $this->error =
"ADHERENT_MAILMAN_UNSUB_URL not defined";
Class to manage categories.
Class to manage mailman and spip.
del_to_mailman($object, $listes='')
Unsubscribe an email from all mailing-lists Used when a user is resiliated.
add_to_mailman($object, $listes='')
Subscribe an email to all mailing-lists.
del_to_spip($object)
Fonction qui enleve les droits redacteurs dans spip.
connectSpip()
Function used to connect to SPIP.
checkSpipConfig()
Function used to check if the SPIP config is correct.
callMailman($object, $url, $list)
Function used to connect to Mailman.
add_to_spip($object)
Fonction qui donne les droits redacteurs dans spip.
__construct($db)
Constructor.
isSpipEnabled()
Function used to check if SPIP is enabled on the system.
is_in_spip($object)
Fonction qui dit si cet utilisateur est un redacteur existant dans spip.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
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).
if(!function_exists('dol_loginfunction')) makesalt($type=CRYPT_SALT_LENGTH)
Fonction pour initialiser un salt pour la fonction crypt.
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.
$conf db
API class for accounts.