31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
55 public $errors = array();
131 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
146 $curl_url = str_replace($patterns, $replace, $url);
151 return $result[
'content'];
171 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
173 $htpass = crypt($object->pass,
makesalt());
174 $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\")";
176 $result = $mydb->query($query);
183 $this->error = $mydb->lasterror();
186 $this->error =
'Failed to connect to SPIP';
189 $this->error =
'BadSPIPConfiguration';
192 $this->error =
'SPIPNotEnabled';
215 $query =
"DELETE FROM spip_auteurs WHERE login = '".$mydb->escape($object->login).
"'";
217 $result = $mydb->query($query);
224 $this->error = $mydb->lasterror();
227 $this->error =
'Failed to connect to SPIP';
230 $this->error =
'BadSPIPConfiguration';
233 $this->error =
'SPIPNotEnabled';
254 $query =
"SELECT login FROM spip_auteurs WHERE login = '".$mydb->escape($object->login).
"'";
256 $result = $mydb->query($query);
259 if ($mydb->num_rows($result)) {
269 $this->error = $mydb->lasterror();
273 $this->error =
'Failed to connect to SPIP';
276 $this->error =
'BadSPIPConfiguration';
279 $this->error =
'SPIPNotEnabled';
296 global $conf, $langs, $user;
298 dol_syslog(get_class($this).
"::add_to_mailman");
300 $this->mladded_ok = array();
301 $this->mladded_ko = array();
303 if (!function_exists(
"curl_init")) {
304 $langs->load(
"errors");
305 $this->error = $langs->trans(
"ErrorFunctionNotAvailableInPHP",
"curl_init");
309 if (isModEnabled(
'adherent')) {
310 if (!empty($conf->global->ADHERENT_MAILMAN_URL)) {
311 if ($listes ==
'' && !empty($conf->global->ADHERENT_MAILMAN_LISTS)) {
312 $lists = explode(
',', $conf->global->ADHERENT_MAILMAN_LISTS);
314 $lists = explode(
',', $listes);
319 foreach ($lists as $list) {
321 $tmp = explode(
':', $list);
322 if (!empty($tmp[2])) {
324 if ($object->element ==
'member' && $tmp[0] ==
'TYPE' && $object->type != $tmp[1]) {
325 dol_syslog(
"We ignore list ".$list.
" because object member type ".$object->type.
" does not match ".$tmp[1], LOG_DEBUG);
328 if ($object->element ==
'member' && $tmp[0] ==
'CATEG' && !in_array($tmp[1], $categstatic->containing($object->id,
'member',
'label'))) {
329 dol_syslog(
"We ignore list ".$list.
" because object member is not into category ".$tmp[1], LOG_DEBUG);
335 $result = $this->
callMailman($object, $conf->global->ADHERENT_MAILMAN_URL, $list);
337 if ($result ===
false) {
338 $this->mladded_ko[$list] = $object->email;
341 $this->mladded_ok[$list] = $object->email;
344 return count($lists);
346 $this->error =
"ADHERENT_MAILMAN_URL not defined";
366 global $conf, $langs, $user;
368 dol_syslog(get_class($this).
"::del_to_mailman");
370 $this->mlremoved_ok = array();
371 $this->mlremoved_ko = array();
373 if (!function_exists(
"curl_init")) {
374 $langs->load(
"errors");
375 $this->error = $langs->trans(
"ErrorFunctionNotAvailableInPHP",
"curl_init");
379 if (isModEnabled(
'adherent')) {
380 if (!empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL)) {
381 if ($listes ==
'' && !empty($conf->global->ADHERENT_MAILMAN_LISTS)) {
382 $lists = explode(
',', $conf->global->ADHERENT_MAILMAN_LISTS);
384 $lists = explode(
',', $listes);
389 foreach ($lists as $list) {
391 $tmp = explode(
':', $list);
392 if (!empty($tmp[2])) {
394 if ($object->element ==
'member' && $tmp[0] ==
'TYPE' && $object->type != $tmp[1]) {
395 dol_syslog(
"We ignore list ".$list.
" because object member type ".$object->type.
" does not match ".$tmp[1], LOG_DEBUG);
398 if ($object->element ==
'member' && $tmp[0] ==
'CATEG' && !in_array($tmp[1], $categstatic->containing($object->id,
'member',
'label'))) {
399 dol_syslog(
"We ignore list ".$list.
" because object member is not into category ".$tmp[1], LOG_DEBUG);
405 $result = $this->
callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL, $list);
407 if ($result ===
false) {
408 $this->mlremoved_ko[$list] = $object->email;
411 $this->mlremoved_ok[$list] = $object->email;
414 return count($lists);
416 $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.
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.