Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2012-08-28 09:33:58 +02:00
commit 562e2b6a7b
6 changed files with 245 additions and 172 deletions

View File

@ -3,6 +3,7 @@
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -40,7 +41,7 @@ $langs->load("companies");
$langs->load("bills"); $langs->load("bills");
$langs->load("members"); $langs->load("members");
$langs->load("users"); $langs->load("users");
$langs->load('other');
$action=GETPOST('action','alpha'); $action=GETPOST('action','alpha');
$backtopage=GETPOST('backtopage','alpha'); $backtopage=GETPOST('backtopage','alpha');
@ -53,6 +54,15 @@ $socid=GETPOST('socid','int');
// Security check // Security check
$result=restrictedArea($user,'adherent',$rowid); $result=restrictedArea($user,'adherent',$rowid);
if ($conf->mailmanspip->enabled)
{
include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
$langs->load('mailmanspip');
$mailmanspip = new MailmanSpip($db);
}
$object = new Adherent($db); $object = new Adherent($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
@ -632,9 +642,9 @@ if ($user->rights->adherent->supprimer && $action == 'confirm_del_spip' && $conf
{ {
if (! count($object->errors)) if (! count($object->errors))
{ {
if(!$object->del_to_spip()) if (!$mailmanspip->del_to_spip($object))
{ {
$errmsg.="Echec de la suppression de l'utilisateur dans spip: ".$object->error."<BR>\n"; $errmsg.= $langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error."<BR>\n";
} }
} }
} }
@ -643,9 +653,9 @@ if ($user->rights->adherent->creer && $action == 'confirm_add_spip' && $confirm
{ {
if (! count($object->errors)) if (! count($object->errors))
{ {
if (!$object->add_to_spip()) if (!$mailmanspip->add_to_spip($object))
{ {
$errmsg.="Echec du rajout de l'utilisateur dans spip: ".$object->error."<BR>\n"; $errmsg.= $langs->trans('AddIntoSpipError').': '.$mailmanspip->error."<BR>\n";
} }
} }
} }
@ -1194,8 +1204,8 @@ if ($rowid && $action != 'edit')
// Cree un tableau formulaire // Cree un tableau formulaire
$formquestion=array(); $formquestion=array();
if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => ($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL?true:false)); if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => ($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL?true:false));
if ($conf->global->ADHERENT_USE_MAILMAN) { $langs->load("mailmanspip"); $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroMailManEnabled"),'value'=>''); } if ($conf->global->ADHERENT_USE_MAILMAN) { $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroMailManEnabled"),'value'=>''); }
if ($conf->global->ADHERENT_USE_SPIP) { $langs->load("mailmanspip"); $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroSpipEnabled"),'value'=>''); } if ($conf->global->ADHERENT_USE_SPIP) { $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroSpipEnabled"),'value'=>''); }
print $form->formconfirm("fiche.php?rowid=".$rowid,$langs->trans("ValidateMember"),$langs->trans("ConfirmValidateMember"),"confirm_valid",$formquestion,1); print $form->formconfirm("fiche.php?rowid=".$rowid,$langs->trans("ValidateMember"),$langs->trans("ConfirmValidateMember"),"confirm_valid",$formquestion,1);
} }
@ -1251,8 +1261,7 @@ if ($rowid && $action != 'edit')
*/ */
if ($action == 'add_spip') if ($action == 'add_spip')
{ {
$langs->load("mailmanspip"); $ret=$form->form_confirm("fiche.php?rowid=".$rowid, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip');
$ret=$form->form_confirm("fiche.php?rowid=".$rowid,"Add to spip","Etes-vous sur de vouloir ajouter cet adherent dans spip ? (serveur : ".ADHERENT_SPIP_SERVEUR.")","confirm_add_spip");
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -1261,8 +1270,7 @@ if ($rowid && $action != 'edit')
*/ */
if ($action == 'del_spip') if ($action == 'del_spip')
{ {
$langs->load("mailmanspip"); $ret=$form->form_confirm("fiche.php?rowid=$rowid", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip');
$ret=$form->form_confirm("fiche.php?rowid=$rowid","Supprimer dans spip","Etes-vous sur de vouloir effacer cet adherent dans spip ? (serveur : ".ADHERENT_SPIP_SERVEUR.")","confirm_del_spip");
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -1564,10 +1572,8 @@ if ($rowid && $action != 'edit')
// Action SPIP // Action SPIP
if ($conf->mailmanspip->enabled && $conf->global->ADHERENT_USE_SPIP) if ($conf->mailmanspip->enabled && $conf->global->ADHERENT_USE_SPIP)
{ {
include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php'; $isinspip = $mailmanspip->is_in_spip($object);
$mailmanspip=new MailmanSpip($db);
$isinspip=$mailmanspip->is_in_spip($object);
if ($isinspip == 1) if ($isinspip == 1)
{ {
print "<a class=\"butAction\" href=\"fiche.php?rowid=$object->id&action=del_spip\">".$langs->trans("DeleteIntoSpip")."</a>\n"; print "<a class=\"butAction\" href=\"fiche.php?rowid=$object->id&action=del_spip\">".$langs->trans("DeleteIntoSpip")."</a>\n";
@ -1578,7 +1584,7 @@ if ($rowid && $action != 'edit')
} }
if ($isinspip == -1) if ($isinspip == -1)
{ {
print '<br><br><font class="error">Failed to connect to SPIP: '.$object->error.'</font>'; print '<br><br><font class="error">'.$langs->trans('SPIPConnectionFailed').': '.$mailmanspip->error.'</font>';
} }
} }

View File

@ -218,7 +218,9 @@ $(document).ready(function() {
$('#service_duration_area').hide(); $('#service_duration_area').hide();
$('#idprod').change(function() { $('#idprod').change(function() {
if ($(this).val() > 0) { if ($(this).val() > 0) {
if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') { if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') {
// We use CKEditor // We use CKEditor
CKEDITOR.instances['product_desc'].focus(); CKEDITOR.instances['product_desc'].focus();
@ -226,6 +228,7 @@ $(document).ready(function() {
// We use a simple textarea // We use a simple textarea
$('#product_desc').focus(); $('#product_desc').focus();
} }
// For compatibility with combobox // For compatibility with combobox
<?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?> <?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
$.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php', { $.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php', {
@ -235,13 +238,13 @@ $(document).ready(function() {
}, },
function(data) { function(data) {
if (typeof data != 'undefined') { if (typeof data != 'undefined') {
$('#select_type').val(data.type).attr('disabled','disabled'); $('#select_type').val(data.type).attr('disabled','disabled').trigger('change');
$('#product_ref').val(data.ref); $('#product_ref').val(data.ref);
$('#product_label').val(data.label).attr('disabled','disabled'); $('#product_label').val(data.label).attr('disabled','disabled');
$('#origin_label_cache').val(data.label); $('#origin_label_cache').val(data.label);
$('#origin_desc_cache').val(data.desc); $('#origin_desc_cache').val(data.desc);
$('#price_base_type').val(data.pricebasetype); $('#price_base_type').val(data.pricebasetype);
$('#price_ht').val(data.price_ht).attr('disabled','disabled'); $('#price_ht').val(data.price_ht);
$('#origin_price_ht_cache').val(data.price_ht); $('#origin_price_ht_cache').val(data.price_ht);
$('#update_label_area').show().trigger('show'); $('#update_label_area').show().trigger('show');
$('#update_desc_area').show().trigger('show'); $('#update_desc_area').show().trigger('show');
@ -249,23 +252,28 @@ $(document).ready(function() {
} }
}, 'json'); }, 'json');
<?php } ?> <?php } ?>
} else { } else {
$('#update_desc_checkbox').removeAttr('checked').trigger('change'); $('#update_desc_checkbox').removeAttr('checked').trigger('change');
$('#update_price_checkbox').removeAttr('checked').trigger('change'); $('#update_price_checkbox').removeAttr('checked');
$('#price_ttc').val('');
// For compatibility with combobox // For compatibility with combobox
<?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?> <?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
$('#select_type').val('').removeAttr('disabled'); $('#select_type').val('').removeAttr('disabled').trigger('change');
$('#product_ref').val(''); $('#product_ref').val('');
$('#product_label').val('').removeAttr('disabled'); $('#product_label').val('').removeAttr('disabled');
$('#origin_label_cache').val(''); $('#origin_label_cache').val('');
$('#origin_desc_cache').val(''); $('#origin_desc_cache').val('');
$('#price_base_type').val(''); $('#price_ht').val('').trigger('change');
$('#price_ht').val('').removeAttr('disabled');
$('#origin_price_ht_cache').val(''); $('#origin_price_ht_cache').val('');
$('#price_base_type').val('');
$('#update_label_area').hide().trigger('hide'); $('#update_label_area').hide().trigger('hide');
$('#update_desc_area').hide().trigger('hide'); $('#update_desc_area').hide().trigger('hide');
$('#update_price_area').hide().trigger('hide'); $('#update_price_area').hide().trigger('hide');
<?php } ?> <?php } ?>
} }
}); });
@ -285,7 +293,7 @@ $(document).ready(function() {
$('#service_duration_area').show(); $('#service_duration_area').show();
} }
//$('#add_product_area').show(); // TODO for add product card //$('#add_product_area').show(); // TODO for add product card
if (($('#price_ht').val().length > 0) || ($('#price_ttc').val().length > 0)) { if ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0) {
$('#addlinebutton').removeAttr('disabled'); $('#addlinebutton').removeAttr('disabled');
} else { } else {
$('#addlinebutton').attr('disabled','disabled'); $('#addlinebutton').attr('disabled','disabled');
@ -411,7 +419,7 @@ $(document).ready(function() {
}); });
$('#price_ht').bind('change keyup input', function() { $('#price_ht').bind('change keyup input', function() {
if ($('#tva_tx').val() > 0 && ($('#idprod').val().length == 0 && $('#price_base_type').val() == 'HT') || $('#idprod').val().length > 0) { if ($('#tva_tx').val() > 0 && (($('#idprod').val() == 0 && $('#price_base_type').val() == 'HT') || $('#idprod').val() > 0)) {
update_price('price_ht', 'price_ttc'); update_price('price_ht', 'price_ttc');
} }
}); });
@ -435,7 +443,7 @@ $(document).ready(function() {
$('#price_ttc').attr('disabled','disabled'); $('#price_ttc').attr('disabled','disabled');
$('#price_ttc').val(''); $('#price_ttc').val('');
} else { } else {
if ($('#idprod').val().length == 0 || ($('#idprod').val().length > 0 && $('#update_price_checkbox').attr('checked') == 'checked')) { if ($('#idprod').val() == 0 || ($('#idprod').val() > 0 && $('#update_price_checkbox').attr('checked') == 'checked')) {
$('#price_ttc').removeAttr('disabled'); $('#price_ttc').removeAttr('disabled');
} }
if ($('#price_base_type').val() == 'HT') { if ($('#price_base_type').val() == 'HT') {

View File

@ -17,3 +17,10 @@ DescADHERENT_SPIP_SERVEUR=SPIP Server
DescADHERENT_SPIP_DB=SPIP database name DescADHERENT_SPIP_DB=SPIP database name
DescADHERENT_SPIP_USER=SPIP database login DescADHERENT_SPIP_USER=SPIP database login
DescADHERENT_SPIP_PASS=SPIP database password DescADHERENT_SPIP_PASS=SPIP database password
AddIntoSpip=Add into SPIP
AddIntoSpipConfirmation=Are you sure you want to add this member into SPIP?
AddIntoSpipError=Failed to add the user in SPIP
DeleteIntoSpip=Remove from SPIP
DeleteIntoSpipConfirmation=Are you sure you want to remove this member from SPIP?
DeleteIntoSpipError=Failed to suppress the user from SPIP
SPIPConnectionFailed=Failed to connect to SPIP

View File

@ -17,3 +17,10 @@ DescADHERENT_SPIP_SERVEUR=Servidor SPIP
DescADHERENT_SPIP_DB=Nombre de la base de datos de SPIP DescADHERENT_SPIP_DB=Nombre de la base de datos de SPIP
DescADHERENT_SPIP_USER=Usuario de la base de datos de SPIP DescADHERENT_SPIP_USER=Usuario de la base de datos de SPIP
DescADHERENT_SPIP_PASS=Contraseña de la base de datos de SPIP DescADHERENT_SPIP_PASS=Contraseña de la base de datos de SPIP
AddIntoSpip=Añadir a SPIP
AddIntoSpipConfirmation=¿Está seguro de querer añadir este miembro a SPIP?
AddIntoSpipError=Ha ocurrido un error al añadir el miembro a SPIP
DeleteIntoSpip=Borrar de SPIP
DeleteIntoSpipConfirmation=¿Está seguro de querer borrar este miembro de SPIP?
DeleteIntoSpipError=Ha ocurrido un error al borrar el miembro de SPIP
SPIPConnectionFailed=Error al conectar con SPIP

View File

@ -16,3 +16,10 @@ DescADHERENT_SPIP_SERVEUR=Serveur SPIP
DescADHERENT_SPIP_DB=Nom base SPIP DescADHERENT_SPIP_DB=Nom base SPIP
DescADHERENT_SPIP_USER=Login connexion base SPIP DescADHERENT_SPIP_USER=Login connexion base SPIP
DescADHERENT_SPIP_PASS=Mot de passe connexion base SPIP DescADHERENT_SPIP_PASS=Mot de passe connexion base SPIP
AddIntoSpip=Ajouter dans SPIP
AddIntoSpipConfirmation=Êtes-vous sur de vouloir ajouter cet adhérent dans SPIP?
AddIntoSpipError=Echec du rajout de l'utilisateur dans SPIP
DeleteIntoSpip=Supprimer de spip
DeleteIntoSpipConfirmation=Êtes-vous sur de vouloir effacer cet adhérent de SPIP?
DeleteIntoSpipError=Échec de la suppression de l'utilisateur de SPIP
SPIPConnectionFailed=Échec de connexion à SPIP

View File

@ -5,6 +5,7 @@
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -50,6 +51,104 @@ class MailmanSpip
$this->db = $db; $this->db = $db;
} }
/**
* Function used to check if SPIP is enabled on the system
* @return boolean
*/
function isSpipEnabled()
{
if (defined("ADHERENT_USE_SPIP") && (ADHERENT_USE_SPIP == 1))
{
return true;
}
return false;
}
/**
* Function used to check if the SPIP config is correct
* @return boolean
*/
function checkSpipConfig()
{
if (defined('ADHERENT_SPIP_SERVEUR') && defined('ADHERENT_SPIP_USER') && defined('ADHERENT_SPIP_PASS') && defined('ADHERENT_SPIP_DB'))
{
if (ADHERENT_SPIP_SERVEUR != '' && ADHERENT_SPIP_USER != '' && ADHERENT_SPIP_PASS != '' && ADHERENT_SPIP_DB != '')
{
return true;
}
}
return false;
}
/**
* Function used to connect to SPIP
* @return boolean|DoliDB
*/
function connectSpip()
{
$resource = getDoliDBInstance('mysql', ADHERENT_SPIP_SERVEUR, ADHERENT_SPIP_USER, ADHERENT_SPIP_PASS, ADHERENT_SPIP_DB, ADHERENT_SPIP_PORT);
if ($resource->ok)
{
return $resource;
}
dol_syslog('Error when connecting to SPIP '.ADHERENT_SPIP_SERVEUR.' '.ADHERENT_SPIP_USER.' '.ADHERENT_SPIP_PASS.' '.ADHERENT_SPIP_DB, LOG_ERR);
return false;
}
/**
* Function used to connect to Mailman
* @param object $object Object with the data
* @param string $url Mailman URL to be called with patterns
* @return boolean|string
*/
function callMailman($object, $url)
{
global $conf;
//Patterns that are going to be replaced with their original value
$patterns = array(
'%LISTE%',
'%EMAIL%',
'%PASSWORD%',
'%MAILMAN_ADMINPW%'
);
$replace = array(
$list,
$object->email,
$object->pass,
$conf->global->ADHERENT_MAILMAN_ADMINPW
);
$curl_url = str_replace($patterns, $replace, $url);
dol_syslog('Calling Mailman: '.$curl_url);
$ch = curl_init($curl_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$result = curl_exec($ch);
dol_syslog('result curl_exec='.$result);
//An error was found, we store it in $this->error for later
if ($result === false || curl_errno($ch) > 0)
{
$this->error = curl_errno($ch).' '.curl_error($ch);
dol_syslog('Error using curl '.$this->error, LOG_ERR);
}
curl_close($ch);
return $result;
}
/** /**
* Fonction qui donne les droits redacteurs dans spip * Fonction qui donne les droits redacteurs dans spip
* *
@ -60,38 +159,36 @@ class MailmanSpip
{ {
dol_syslog(get_class($this)."::add_to_spip"); dol_syslog(get_class($this)."::add_to_spip");
if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && if ($this->isSpipEnabled())
defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' &&
defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != ''
)
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; if ($this->checkSpipConfig())
$mdpass=dol_hash($object->pass);
$htpass=crypt($object->pass,makesalt());
$query = "INSERT INTO spip_auteurs (nom, email, login, pass, htpass, alea_futur, statut) VALUES(\"".$object->firstname." ".$object->lastname."\",\"".$object->email."\",\"".$object->login."\",\"$mdpass\",\"$htpass\",FLOOR(32000*RAND()),\"1comite\")";
$mydb=getDoliDBInstance('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB,ADHERENT_SPIP_PORT);
if (! $mydb->ok)
{ {
$this->error=$mydb->lasterror(); $mydb = $this->connectSpip();
return 0;
}
$result = $mydb->query($query); if ($mydb)
if ($result) {
{ require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
$mydb->close(); $mdpass=dol_hash($object->pass);
return 1; $htpass=crypt($object->pass,makesalt());
} $query = "INSERT INTO spip_auteurs (nom, email, login, pass, htpass, alea_futur, statut) VALUES(\"".$object->firstname." ".$object->lastname."\",\"".$object->email."\",\"".$object->login."\",\"$mdpass\",\"$htpass\",FLOOR(32000*RAND()),\"1comite\")";
else
{ $result = $mydb->query($query);
$this->error=$mydb->lasterror();
return 0; $mydb->close();
if ($result)
{
return 1;
}
else $this->error = $mydb->lasterror();
}
else $this->error = 'Failed to connect to SPIP';
} }
else $this->error = 'BadSPIPConfiguration';
} }
else $this->error = 'SPIPNotEnabled';
return 0;
} }
/** /**
@ -102,30 +199,35 @@ class MailmanSpip
*/ */
function del_to_spip($object) function del_to_spip($object)
{ {
if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && dol_syslog(get_class($this)."::del_to_spip");
defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' && if ($this->isSpipEnabled())
defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != ''
)
{ {
$query = "DELETE FROM spip_auteurs WHERE login='".$object->login."'"; if ($this->checkSpipConfig())
$mydb=getDoliDBInstance('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB,ADHERENT_SPIP_PORT);
$result = $mydb->query($query);
if ($result)
{ {
$mydb->close(); $mydb = $this->connectSpip();
return 1;
} if ($mydb)
else {
{ $query = "DELETE FROM spip_auteurs WHERE login='".$object->login."'";
$this->error=$mydb->lasterror();
$mydb->close(); $result = $mydb->query($query);
return 0;
$mydb->close();
if ($result)
{
return 1;
}
else $this->error = $mydb->lasterror();
}
else $this->error = 'Failed to connect to SPIP';
} }
else $this->error = 'BadSPIPConfiguration';
} }
else $this->error = 'SPIPNotEnabled';
return 0;
} }
/** /**
@ -136,48 +238,46 @@ class MailmanSpip
*/ */
function is_in_spip($object) function is_in_spip($object)
{ {
if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP ==1 && if ($this->isSpipEnabled())
defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' &&
defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' &&
defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' &&
defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '')
{ {
$query = "SELECT login FROM spip_auteurs WHERE login='".$object->login."'"; if ($this->checkSpipConfig())
$mydb=getDoliDBInstance('mysql',ADHERENT_SPIP_SERVEUR,ADHERENT_SPIP_USER,ADHERENT_SPIP_PASS,ADHERENT_SPIP_DB,ADHERENT_SPIP_PORT);
if ($mydb->ok)
{ {
$result = $mydb->query($query); $mydb = $this->connectSpip();
if ($result) if ($mydb)
{ {
if ($mydb->num_rows($result)) $query = "SELECT login FROM spip_auteurs WHERE login='".$object->login."'";
$result = $mydb->query($query);
if ($result)
{ {
// nous avons au moins une reponse if ($mydb->num_rows($result))
$mydb->close($result); {
return 1; // nous avons au moins une reponse
$mydb->close($result);
return 1;
}
else
{
// nous n'avons pas de reponse => n'existe pas
$mydb->close($result);
return 0;
}
} }
else else
{ {
// nous n'avons pas de reponse => n'existe pas $this->error = $mydb->lasterror();
$mydb->close($result); $mydb->close();
return 0;
} }
} }
else else $this->error = 'Failed to connect to SPIP';
{
$this->error=$mydb->lasterror();
$mydb->close();
return -1;
}
}
else
{
$this->error="Failed to connect ".ADHERENT_SPIP_SERVEUR." ".ADHERENT_SPIP_USER." ".ADHERENT_SPIP_PASS." ".ADHERENT_SPIP_DB;
return -1;
} }
else $this->error = 'BadSPIPConfiguration';
} }
else $this->error = 'SPIPNotEnabled';
return -1;
} }
/** /**
@ -224,44 +324,13 @@ class MailmanSpip
} }
} }
// on remplace dans l'url le nom de la liste ainsi //We call Mailman to subscribe the user
// que l'email et le mot de passe $result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_URL);
$patterns = array (
'/%LISTE%/',
'/%EMAIL%/',
'/%PASSWORD%/',
'/%MAILMAN_ADMINPW%/'
);
$replace = array (
$list,
$object->email,
$object->pass,
$conf->global->ADHERENT_MAILMAN_ADMINPW
);
$curl_url = preg_replace($patterns, $replace, $conf->global->ADHERENT_MAILMAN_URL);
dol_syslog("Call URL to subscribe : ".$curl_url); if ($result === false)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$curl_url");
//curl_setopt($ch, CURLOPT_URL,"http://www.j1b.org/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
//curl_setopt($ch, CURLOPT_POST, 0);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5");
//--- Start buffering
$result=curl_exec($ch);
dol_syslog('result curl_exec='.$result);
//--- End buffering and clean output
if ($result === false || curl_errno($ch) > 0)
{ {
// error
$this->error=curl_errno($ch).' '.curl_error($ch);
dol_syslog('Error using curl '.$this->error, LOG_ERR);
return -2; return -2;
} }
curl_close($ch);
} }
return count($lists); return count($lists);
} }
@ -306,44 +375,13 @@ class MailmanSpip
} }
} }
// on remplace dans l'url le nom de la liste ainsi //We call Mailman to unsubscribe the user
// que l'email et le mot de passe $result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL);
$patterns = array (
'/%LISTE%/',
'/%EMAIL%/',
'/%PASSWORD%/',
'/%MAILMAN_ADMINPW%/'
);
$replace = array (
trim($list),
$object->email,
$object->pass,
$conf->global->ADHERENT_MAILMAN_ADMINPW
);
$curl_url = preg_replace($patterns, $replace, $conf->global->ADHERENT_MAILMAN_UNSUB_URL);
dol_syslog("Call URL to unsubscribe : ".$curl_url); if ($result === false)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$curl_url");
//curl_setopt($ch, CURLOPT_URL,"http://www.j1b.org/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
//curl_setopt($ch, CURLOPT_POST, 0);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5");
//--- Start buffering
$result=curl_exec($ch);
dol_syslog($result);
//--- End buffering and clean output
if ($result === false || curl_errno($ch) > 0)
{ {
$this->error=curl_errno($ch).' '.curl_error($ch);
dol_syslog('Error using curl '.$this->error, LOG_ERR);
// error
return -2; return -2;
} }
curl_close($ch);
} }
return count($lists); return count($lists);
} }