2
0
forked from Wavyzz/dolibarr

New: Module mailman can subscribe/unsubscribe to ML according to

categories of member.
This commit is contained in:
Laurent Destailleur
2013-06-05 15:44:42 +02:00
parent 7bae064415
commit eac4aa7e28
10 changed files with 161 additions and 139 deletions

View File

@@ -4,16 +4,18 @@ English Dolibarr ChangeLog
***** ChangeLog for 3.5 compared to 3.4 ***** ***** ChangeLog for 3.5 compared to 3.4 *****
For users: For users:
- New: [ task #877 ] Reorganize menus - New: [ task #877 ] Reorganize menus.
- New: [ task #858 ] Holiday module: note on manual holiday assignation - New: [ task #858 ] Holiday module: note on manual holiday assignation.
- New: [ task #892 ] Add option in thridparty customer/supplier admin to hide non active in select_company method - New: [ task #892 ] Add option in thridparty customer/supplier admin to hide non active in select_company method.
- New: [ task #531 ] Add a workload on tasks - New: [ task #531 ] Add a workload on tasks.
- New: Add graph of bank account input/output into input-output report page. - New: Add graph of bank account input/output into input-output report page.
- New: Add script export-bank-receipts. - New: Add script export-bank-receipts.
- New: Add option "filter=bank" onto script rebuild_merge_pdf.php to merge - New: Add option "filter=bank" onto script rebuild_merge_pdf.php to merge.
PDF that has one payment on a specific bank account.* PDF that has one payment on a specific bank account.*
- New: [ task #901 ] Add Extrafeild on Fiche Inter - New: [ task #901 ] Add Extrafeild on Fiche Inter.
- New: Show process id in all command line scripts - New: Show process id in all command line scripts.
- New: Module mailman can subscribe/unsubscribe to ML according to categories of member.
For developers: For developers:
- New: DolGraph can build graph with three lines. - New: DolGraph can build graph with three lines.

View File

@@ -22,12 +22,12 @@
*/ */
/** /**
* \file htdocs/adherents/admin/mailman.php * \file htdocs/admin/mailman.php
* \ingroup mailmanspip * \ingroup mailmanspip
* \brief Page to setup the module MailmanSpip (Mailman) * \brief Page to setup the module MailmanSpip (Mailman)
*/ */
require '../../main.inc.php'; require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php';
@@ -58,10 +58,10 @@ if ($action == 'update' || $action == 'add')
$consttype=$_POST["consttype"][$key]; $consttype=$_POST["consttype"][$key];
$constnote=$_POST["constnote"][$key]; $constnote=$_POST["constnote"][$key];
$res=dolibarr_set_const($db,$constname,$constvalue,$type[$consttype],0,$constnote,$conf->entity); $res=dolibarr_set_const($db,$constname,$constvalue,$type[$consttype],0,$constnote,$conf->entity);
if (! $res > 0) $error++; if (! $res > 0) $error++;
} }
if (! $error) if (! $error)
{ {
$mesg = '<div class="ok">'.$langs->trans("SetupSaved").'</div>'; $mesg = '<div class="ok">'.$langs->trans("SetupSaved").'</div>';
@@ -181,11 +181,12 @@ if (! empty($conf->global->ADHERENT_USE_MAILMAN))
print_fiche_titre($langs->trans('MailmanTitle'), $lien,''); print_fiche_titre($langs->trans('MailmanTitle'), $lien,'');
print '<br>'; print '<br>';
// JQuery activity // JQuery activity
print '<script type="text/javascript"> print '<script type="text/javascript">
var i1=0; var i1=0;
var i2=0; var i2=0;
var i3=0;
jQuery(document).ready(function(){ jQuery(document).ready(function(){
jQuery("#exampleclick1").click(function(event){ jQuery("#exampleclick1").click(function(event){
if (i1 == 0) { jQuery("#example1").show(); i1=1; } if (i1 == 0) { jQuery("#example1").show(); i1=1; }
@@ -195,7 +196,11 @@ if (! empty($conf->global->ADHERENT_USE_MAILMAN))
if (i2 == 0) { jQuery("#example2").show(); i2=1; } if (i2 == 0) { jQuery("#example2").show(); i2=1; }
else if (i2 == 1) { jQuery("#example2").hide(); i2=0; } else if (i2 == 1) { jQuery("#example2").hide(); i2=0; }
}); });
}); jQuery("#exampleclick3").click(function(){
if (i3 == 0) { jQuery("#example3").show(); i3=1; }
else if (i3 == 1) { jQuery("#example3").hide(); i3=0; }
});
});
</script>'; </script>';
form_constantes($constantes,1); form_constantes($constantes,1);

View File

@@ -22,12 +22,12 @@
*/ */
/** /**
* \file htdocs/adherents/admin/spip.php * \file htdocs/admin/spip.php
* \ingroup mailmanspip * \ingroup mailmanspip
* \brief Page to setup the module MailmanSpip (SPIP) * \brief Page to setup the module MailmanSpip (SPIP)
*/ */
require '../../main.inc.php'; require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php';

View File

@@ -372,19 +372,19 @@ class Categorie
* Link an object to the category * Link an object to the category
* *
* @param Object $obj Object to link to category * @param Object $obj Object to link to category
* @param string $type Type of category * @param string $type Type of category (member, supplier, product, customer)
* @return int 1 : OK, -1 : erreur SQL, -2 : id non renseign, -3 : Already linked * @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked
*/ */
function add_type($obj,$type) function add_type($obj,$type)
{ {
if ($this->id == -1) if ($this->id == -1) return -2;
{ if ($type == 'company') $type='societe';
return -2; if ($type == 'fournisseur') $type='societe';
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".$type." (fk_categorie, fk_".($type=='fournisseur'?'societe':$type).")"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".$type." (fk_categorie, fk_".$type.")";
$sql .= " VALUES (".$this->id.", ".$obj->id.")"; $sql .= " VALUES (".$this->id.", ".$obj->id.")";
dol_syslog(get_class($this).'::add_type sql='.$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
return 1; return 1;
@@ -956,36 +956,43 @@ class Categorie
} }
/** /**
* Return list of categories linked to element of type $type with id $typeid * Return list of categories linked to element of id $id and type $typeid
* *
* @param int $id Id of element * @param int $id Id of element
* @param int $typeid Type id of link (0,1,2,3...) * @param int $typeid Type of link (0 or 'product', 1 or 'supplier', 2 or 'customer', 3 or 'member', ...)
* @return array List of category objects * @param string $mode 'object'=Get array of categories, 'label'=Get array of category labels
* @return mixed Array of category objects or < 0 if KO
*/ */
function containing($id,$typeid) function containing($id,$typeid,$mode='object')
{ {
$cats = array (); $cats = array();
$table=''; $type=''; $table=''; $type='';
if ($typeid == 0) { $table='product'; $type='product'; } if ($typeid == 0 || $typeid == 'product') { $typeid=0; $table='product'; $type='product'; }
if ($typeid == 1) { $table='societe'; $type='fournisseur'; } else if ($typeid == 1 || $typeid == 'supplier') { $typeid=1; $table='societe'; $type='fournisseur'; }
if ($typeid == 2) { $table='societe'; $type='societe'; } else if ($typeid == 2 || $typeid == 'customer') { $typeid=2; $table='societe'; $type='societe'; }
if ($typeid == 3) { $table='member'; $type='member'; } else if ($typeid == 3 || $typeid == 'member') { $typeid=3; $table='member'; $type='member'; }
$sql = "SELECT ct.fk_categorie"; $sql = "SELECT ct.fk_categorie, c.label";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct, ".MAIN_DB_PREFIX."categorie as c";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON ct.fk_categorie = c.rowid"; $sql.= " WHERE ct.fk_categorie = c.rowid AND ct.fk_".$table." = ".$id." AND c.type = ".$typeid;
$sql.= " WHERE ct.fk_".$table." = ".$id." AND c.type = ".$typeid;
$sql.= " AND c.entity IN (".getEntity('category',1).")"; $sql.= " AND c.entity IN (".getEntity('category',1).")";
dol_syslog(get_class($this).'::containing sql='.$sql);
$res = $this->db->query($sql); $res = $this->db->query($sql);
if ($res) if ($res)
{ {
while ($rec = $this->db->fetch_array($res)) while ($obj = $this->db->fetch_object($res))
{ {
$cat = new Categorie($this->db); if ($mode == 'label')
$cat->fetch($rec['fk_categorie']); {
$cats[] = $cat; $cats[] = $obj->label;
}
else {
$cat = new Categorie($this->db);
$cat->fetch($obj->fk_categorie);
$cats[] = $cat;
}
} }
return $cats; return $cats;

View File

@@ -1011,7 +1011,7 @@ function form_constantes($tableau,$strictw3c=0)
$form = new Form($db); $form = new Form($db);
if (! empty($strictw3c)) print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; if (! empty($strictw3c)) print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>'; print '<td>'.$langs->trans("Description").'</td>';
@@ -1076,6 +1076,16 @@ function form_constantes($tableau,$strictw3c=0)
print '</div>'; print '</div>';
//print 'http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%'; //print 'http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
} }
if ($const == 'ADHERENT_MAILMAN_LISTS')
{
print '. '.$langs->trans("Example").': <a href="#" id="exampleclick3">'.img_down().'</a><br>';
print '<div id="example3" class="hidden">';
print 'mymailmanlist<br>';
print 'mymailmanlist1,mymailmanlist2<br>';
if ($conf->categorie->enabled) print 'CATEG:Categ1:mymailmanlist1,CATEG:Categ2:mymailmanlist2<br>';
print '</div>';
//print 'http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
}
print "</td>\n"; print "</td>\n";
@@ -1129,14 +1139,14 @@ function form_constantes($tableau,$strictw3c=0)
print '<td align="center">'; print '<td align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Update").'" name="Button">'; print '<input type="submit" class="button" value="'.$langs->trans("Update").'" name="Button">';
print "</td>"; print "</td>";
} }
print "</tr>\n"; print "</tr>\n";
if (empty($strictw3c)) print "</form>\n"; if (empty($strictw3c)) print "</form>\n";
} }
} }
print '</table>'; print '</table>';
if (! empty($strictw3c)) if (! empty($strictw3c))
{ {
print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>'; print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
print "</form>\n"; print "</form>\n";

View File

@@ -32,12 +32,12 @@ function mailmanspip_admin_prepare_head()
return array( return array(
array( array(
DOL_URL_ROOT.'/adherents/admin/mailman.php', DOL_URL_ROOT.'/admin/mailman.php',
$langs->trans('Mailman'), $langs->trans('Mailman'),
'mailman' 'mailman'
), ),
array( array(
DOL_URL_ROOT.'/adherents/admin/spip.php', DOL_URL_ROOT.'/admin/spip.php',
$langs->trans('SPIP'), $langs->trans('SPIP'),
'spip' 'spip'
) )

View File

@@ -62,14 +62,14 @@ class modMailmanSpip extends DolibarrModules
$this->requiredby = array(); $this->requiredby = array();
// Config pages // Config pages
$this->config_page_url = array('mailman.php@adherents'); $this->config_page_url = array('mailman.php');
// Constants // Constants
$this->const = array(); $this->const = array();
$this->const[1] = array("ADHERENT_MAILMAN_UNSUB_URL","chaine","http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&user=%EMAIL%","Url de désinscription aux listes mailman"); $this->const[1] = array("ADHERENT_MAILMAN_UNSUB_URL","chaine","http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&user=%EMAIL%","Url de désinscription aux listes mailman");
$this->const[2] = array("ADHERENT_MAILMAN_URL","chaine","http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&send_welcome_msg_to_this_batch=1&subscribees=%EMAIL%","Url pour les inscriptions mailman"); $this->const[2] = array("ADHERENT_MAILMAN_URL","chaine","http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&send_welcome_msg_to_this_batch=1&subscribees=%EMAIL%","Url pour les inscriptions mailman");
$this->const[3] = array("ADHERENT_MAILMAN_LISTS","chaine","","Mailing-list to subscribe new members to"); $this->const[3] = array("ADHERENT_MAILMAN_LISTS","chaine","","Mailing-list to subscribe new members to");
// Boxes // Boxes
$this->boxes = array(); $this->boxes = array();

View File

@@ -314,46 +314,51 @@ class MailmanSpip
return -1; return -1;
} }
if (! empty($conf->global->ADHERENT_MAILMAN_URL)) if ($conf->adherent->enabled) // Synchro for members
{ {
if ($listes == '' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS)) if (! empty($conf->global->ADHERENT_MAILMAN_URL))
{ {
$lists=explode(',',$conf->global->ADHERENT_MAILMAN_LISTS); if ($listes == '' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS)) $lists=explode(',',$conf->global->ADHERENT_MAILMAN_LISTS);
} else $lists=explode(',',$listes);
else
{
$lists=explode(',',$listes);
}
foreach ($lists as $list)
{
// Filter on type something (ADHERENT_MAILMAN_LISTS = "filtervalue:mailinglist1,filtervalue2:mailinglist2,mailinglist3")
$tmp=explode(':',$list);
if (! empty($tmp[1]))
{
$list=$tmp[1];
if ($object->element == 'member' && $object->type != $tmp[0]) // Filter on member type label
{
dol_syslog("We ignore list ".$list." because object member type ".$object->type." does not match ".$tmp[0], LOG_DEBUG);
continue;
}
}
//We call Mailman to subscribe the user $categstatic=new Categorie($this->db);
$result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_URL, $list);
if ($result === false) foreach ($lists as $list)
{ {
$this->mladded_ko[$list]=$object->email; // Filter on type something (ADHERENT_MAILMAN_LISTS = "mailinglist0,TYPE:typevalue:mailinglist1,CATEG:categvalue:mailinglist2")
return -2; $tmp=explode(':',$list);
} if (! empty($tmp[2]))
else $this->mladded_ok[$list]=$object->email; {
} $list=$tmp[2];
return count($lists); if ($object->element == 'member' && $tmp[0] == 'TYPE' && $object->type != $tmp[1]) // Filter on member type label
} {
else dol_syslog("We ignore list ".$list." because object member type ".$object->type." does not match ".$tmp[1], LOG_DEBUG);
{ continue;
$this->error="ADHERENT_MAILMAN_URL not defined"; }
return -1; if ($object->element == 'member' && $tmp[0] == 'CATEG' && ! in_array($tmp[1], $categstatic->containing($object->id, 'member', 'label'))) // Filter on member category
{
dol_syslog("We ignore list ".$list." because object member is not into category ".$tmp[1], LOG_DEBUG);
continue;
}
}
//We call Mailman to subscribe the user
$result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_URL, $list);
if ($result === false)
{
$this->mladded_ko[$list]=$object->email;
return -2;
}
else $this->mladded_ok[$list]=$object->email;
}
return count($lists);
}
else
{
$this->error="ADHERENT_MAILMAN_URL not defined";
return -1;
}
} }
} }
@@ -381,46 +386,44 @@ class MailmanSpip
return -1; return -1;
} }
if (! empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL)) if ($conf->adherent->enabled) // Synchro for members
{ {
if ($listes=='' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS)) if (! empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL))
{ {
$lists=explode(',',$conf->global->ADHERENT_MAILMAN_LISTS); if ($listes=='' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS)) $lists=explode(',',$conf->global->ADHERENT_MAILMAN_LISTS);
} else $lists=explode(',',$listes);
else
{
$lists=explode(',',$listes);
}
foreach ($lists as $list)
{
// Filter on type something (ADHERENT_MAILMAN_LISTS = "filtervalue:mailinglist1,filtervalue2:mailinglist2,mailinglist3")
$tmp=explode(':',$list);
if (! empty($tmp[1]))
{
$list=$tmp[1];
if ($object->element == 'member' && $object->type != $tmp[1]) // Filter on member type label
{
dol_syslog("We ignore list ".$list." because object member type ".$object->type." does not match ".$tmp[0], LOG_DEBUG);
continue;
}
}
//We call Mailman to unsubscribe the user foreach ($lists as $list)
$result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL, $list); {
// Filter on type something (ADHERENT_MAILMAN_LISTS = "filtervalue:mailinglist1,filtervalue2:mailinglist2,mailinglist3")
$tmp=explode(':',$list);
if (! empty($tmp[1]))
{
$list=$tmp[1];
if ($object->element == 'member' && $object->type != $tmp[1]) // Filter on member type label
{
dol_syslog("We ignore list ".$list." because object member type ".$object->type." does not match ".$tmp[0], LOG_DEBUG);
continue;
}
}
if ($result === false) //We call Mailman to unsubscribe the user
{ $result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL, $list);
$this->mlremoved_ko[$list]=$object->email;
return -2; if ($result === false)
} {
else $this->mlremoved_ok[$list]=$object->email; $this->mlremoved_ko[$list]=$object->email;
} return -2;
return count($lists); }
} else $this->mlremoved_ok[$list]=$object->email;
else }
{ return count($lists);
$this->error="ADHERENT_MAILMAN_UNSUB_URL not defined"; }
return -1; else
{
$this->error="ADHERENT_MAILMAN_UNSUB_URL not defined";
return -1;
}
} }
} }

View File

@@ -336,19 +336,7 @@ class Product extends CommonObject
$result = $this->_log_price($user); $result = $this->_log_price($user);
if ($result > 0) if ($result > 0)
{ {
if ($this->update($id, $user, true, 'add') > 0) if ($this->update($id, $user, true, 'add') <= 0)
{
// FIXME: not use here
/*
if ($this->catid > 0)
{
require_once DOL_DOCUMENT_ROOT .'/categories/class/categorie.class.php';
$cat = new Categorie($this->db, $this->catid);
$cat->add_type($this,"product");
}
*/
}
else
{ {
$error++; $error++;
$this->error='ErrorFailedToUpdateRecord'; $this->error='ErrorFailedToUpdateRecord';
@@ -673,7 +661,7 @@ class Product extends CommonObject
} }
} }
} }
// Remove extrafields // Remove extrafields
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{ {

View File

@@ -184,16 +184,23 @@ class CategorieTest extends PHPUnit_Framework_TestCase
print __METHOD__." catid=".$catid."\n"; print __METHOD__." catid=".$catid."\n";
$this->assertGreaterThan(0, $catid); $this->assertGreaterThan(0, $catid);
// Category // Try to create product linked to category
$localobject2=new Product($this->savdb); $localobject2=new Product($this->savdb);
$localobject2->initAsSpecimen(); $localobject2->initAsSpecimen();
$localobject2->ref.='-CATEG'; $localobject2->ref.='-CATEG';
$localobject2->tva_npr=1; $localobject2->tva_npr=1;
$localobject2->catid=$catid;
$result=$localobject2->create($user); $result=$localobject2->create($user);
$cat = new Categorie($this->savdb);
$cat->id = $catid;
$result=$cat->add_type($localobject2,"product");
print __METHOD__." result=".$result."\n"; print __METHOD__." result=".$result."\n";
$this->assertGreaterThan(0, $result); $this->assertGreaterThan(0, $result);
// Get list of categories for product
$localcateg=new Categorie($this->savdb);
$listofcateg=$localcateg->containing($localobject2->id, 'product', 'label');
$this->assertTrue(in_array('Specimen Category for product',$listofcateg), 'Categ not found linked to product when it should');
return $id; return $id;
} }