diff --git a/ChangeLog b/ChangeLog index c0305ee0a1d..1a1e738da68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,16 +4,18 @@ English Dolibarr ChangeLog ***** ChangeLog for 3.5 compared to 3.4 ***** For users: -- New: [ task #877 ] Reorganize menus -- 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 #531 ] Add a workload on tasks +- New: [ task #877 ] Reorganize menus. +- 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 #531 ] Add a workload on tasks. - New: Add graph of bank account input/output into input-output report page. - 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.* -- New: [ task #901 ] Add Extrafeild on Fiche Inter -- New: Show process id in all command line scripts +- New: [ task #901 ] Add Extrafeild on Fiche Inter. +- New: Show process id in all command line scripts. +- New: Module mailman can subscribe/unsubscribe to ML according to categories of member. + For developers: - New: DolGraph can build graph with three lines. diff --git a/htdocs/adherents/admin/mailman.php b/htdocs/admin/mailman.php similarity index 96% rename from htdocs/adherents/admin/mailman.php rename to htdocs/admin/mailman.php index 9e0b859db67..34d0fae56e5 100644 --- a/htdocs/adherents/admin/mailman.php +++ b/htdocs/admin/mailman.php @@ -22,12 +22,12 @@ */ /** - * \file htdocs/adherents/admin/mailman.php + * \file htdocs/admin/mailman.php * \ingroup mailmanspip * \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/mailmanspip.lib.php'; @@ -58,10 +58,10 @@ if ($action == 'update' || $action == 'add') $consttype=$_POST["consttype"][$key]; $constnote=$_POST["constnote"][$key]; $res=dolibarr_set_const($db,$constname,$constvalue,$type[$consttype],0,$constnote,$conf->entity); - + if (! $res > 0) $error++; } - + if (! $error) { $mesg = '
'.$langs->trans("SetupSaved").'
'; @@ -181,11 +181,12 @@ if (! empty($conf->global->ADHERENT_USE_MAILMAN)) print_fiche_titre($langs->trans('MailmanTitle'), $lien,''); print '
'; - + // JQuery activity print ''; form_constantes($constantes,1); diff --git a/htdocs/adherents/admin/spip.php b/htdocs/admin/spip.php similarity index 98% rename from htdocs/adherents/admin/spip.php rename to htdocs/admin/spip.php index 9bbb95c2697..ae7601fb611 100644 --- a/htdocs/adherents/admin/spip.php +++ b/htdocs/admin/spip.php @@ -22,12 +22,12 @@ */ /** - * \file htdocs/adherents/admin/spip.php + * \file htdocs/admin/spip.php * \ingroup mailmanspip * \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/mailmanspip.lib.php'; diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index f8091fa8fa6..19e8b1a9f5d 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -372,19 +372,19 @@ class Categorie * Link an object to the category * * @param Object $obj Object to link to category - * @param string $type Type of category - * @return int 1 : OK, -1 : erreur SQL, -2 : id non renseign, -3 : Already linked + * @param string $type Type of category (member, supplier, product, customer) + * @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked */ function add_type($obj,$type) { - if ($this->id == -1) - { - return -2; - } + if ($this->id == -1) return -2; + if ($type == 'company') $type='societe'; + 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.")"; + dol_syslog(get_class($this).'::add_type sql='.$sql); if ($this->db->query($sql)) { 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 $typeid Type id of link (0,1,2,3...) - * @return array List of category objects + * @param int $id Id of element + * @param int $typeid Type of link (0 or 'product', 1 or 'supplier', 2 or 'customer', 3 or 'member', ...) + * @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=''; - if ($typeid == 0) { $table='product'; $type='product'; } - if ($typeid == 1) { $table='societe'; $type='fournisseur'; } - if ($typeid == 2) { $table='societe'; $type='societe'; } - if ($typeid == 3) { $table='member'; $type='member'; } + if ($typeid == 0 || $typeid == 'product') { $typeid=0; $table='product'; $type='product'; } + else if ($typeid == 1 || $typeid == 'supplier') { $typeid=1; $table='societe'; $type='fournisseur'; } + else if ($typeid == 2 || $typeid == 'customer') { $typeid=2; $table='societe'; $type='societe'; } + else if ($typeid == 3 || $typeid == 'member') { $typeid=3; $table='member'; $type='member'; } - $sql = "SELECT ct.fk_categorie"; - $sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON ct.fk_categorie = c.rowid"; - $sql.= " WHERE ct.fk_".$table." = ".$id." AND c.type = ".$typeid; + $sql = "SELECT ct.fk_categorie, c.label"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct, ".MAIN_DB_PREFIX."categorie as c"; + $sql.= " WHERE ct.fk_categorie = c.rowid AND ct.fk_".$table." = ".$id." AND c.type = ".$typeid; $sql.= " AND c.entity IN (".getEntity('category',1).")"; + dol_syslog(get_class($this).'::containing sql='.$sql); $res = $this->db->query($sql); if ($res) { - while ($rec = $this->db->fetch_array($res)) + while ($obj = $this->db->fetch_object($res)) { - $cat = new Categorie($this->db); - $cat->fetch($rec['fk_categorie']); - $cats[] = $cat; + if ($mode == 'label') + { + $cats[] = $obj->label; + } + else { + $cat = new Categorie($this->db); + $cat->fetch($obj->fk_categorie); + $cats[] = $cat; + } } return $cats; diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 434ffc7d7fb..6e302fa9806 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1011,7 +1011,7 @@ function form_constantes($tableau,$strictw3c=0) $form = new Form($db); if (! empty($strictw3c)) print "\n".'
'; - + print ''; print ''; print ''; @@ -1076,6 +1076,16 @@ function form_constantes($tableau,$strictw3c=0) print ''; //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").': '.img_down().'
'; + print ''; + //print 'http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%'; + } print "\n"; @@ -1129,14 +1139,14 @@ function form_constantes($tableau,$strictw3c=0) print '"; - } + } print "\n"; if (empty($strictw3c)) print "\n"; } } print '
'.$langs->trans("Description").''; print ''; print "
'; - if (! empty($strictw3c)) + if (! empty($strictw3c)) { print '
'; print "\n"; diff --git a/htdocs/core/lib/mailmanspip.lib.php b/htdocs/core/lib/mailmanspip.lib.php index 47caced472c..eb57f4b6163 100644 --- a/htdocs/core/lib/mailmanspip.lib.php +++ b/htdocs/core/lib/mailmanspip.lib.php @@ -32,12 +32,12 @@ function mailmanspip_admin_prepare_head() return array( array( - DOL_URL_ROOT.'/adherents/admin/mailman.php', + DOL_URL_ROOT.'/admin/mailman.php', $langs->trans('Mailman'), 'mailman' ), array( - DOL_URL_ROOT.'/adherents/admin/spip.php', + DOL_URL_ROOT.'/admin/spip.php', $langs->trans('SPIP'), 'spip' ) diff --git a/htdocs/core/modules/modMailmanSpip.class.php b/htdocs/core/modules/modMailmanSpip.class.php index 6877b230fca..4a4c39f3c02 100644 --- a/htdocs/core/modules/modMailmanSpip.class.php +++ b/htdocs/core/modules/modMailmanSpip.class.php @@ -62,14 +62,14 @@ class modMailmanSpip extends DolibarrModules $this->requiredby = array(); // Config pages - $this->config_page_url = array('mailman.php@adherents'); + $this->config_page_url = array('mailman.php'); // Constants $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[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"); - + // Boxes $this->boxes = array(); diff --git a/htdocs/mailmanspip/class/mailmanspip.class.php b/htdocs/mailmanspip/class/mailmanspip.class.php index 5a015ba1c64..26c9cb3a24b 100644 --- a/htdocs/mailmanspip/class/mailmanspip.class.php +++ b/htdocs/mailmanspip/class/mailmanspip.class.php @@ -314,46 +314,51 @@ class MailmanSpip return -1; } - if (! empty($conf->global->ADHERENT_MAILMAN_URL)) + if ($conf->adherent->enabled) // Synchro for members { - if ($listes == '' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS)) - { - $lists=explode(',',$conf->global->ADHERENT_MAILMAN_LISTS); - } - 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; - } - } + if (! empty($conf->global->ADHERENT_MAILMAN_URL)) + { + if ($listes == '' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS)) $lists=explode(',',$conf->global->ADHERENT_MAILMAN_LISTS); + else $lists=explode(',',$listes); - //We call Mailman to subscribe the user - $result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_URL, $list); + $categstatic=new Categorie($this->db); - 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; + foreach ($lists as $list) + { + // Filter on type something (ADHERENT_MAILMAN_LISTS = "mailinglist0,TYPE:typevalue:mailinglist1,CATEG:categvalue:mailinglist2") + $tmp=explode(':',$list); + if (! empty($tmp[2])) + { + $list=$tmp[2]; + if ($object->element == 'member' && $tmp[0] == 'TYPE' && $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[1], LOG_DEBUG); + continue; + } + 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; } - if (! empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL)) + if ($conf->adherent->enabled) // Synchro for members { - if ($listes=='' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS)) - { - $lists=explode(',',$conf->global->ADHERENT_MAILMAN_LISTS); - } - 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; - } - } + if (! empty($conf->global->ADHERENT_MAILMAN_UNSUB_URL)) + { + if ($listes=='' && ! empty($conf->global->ADHERENT_MAILMAN_LISTS)) $lists=explode(',',$conf->global->ADHERENT_MAILMAN_LISTS); + else $lists=explode(',',$listes); - //We call Mailman to unsubscribe the user - $result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL, $list); + 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; + } + } - if ($result === false) - { - $this->mlremoved_ko[$list]=$object->email; - return -2; - } - else $this->mlremoved_ok[$list]=$object->email; - } - return count($lists); - } - else - { - $this->error="ADHERENT_MAILMAN_UNSUB_URL not defined"; - return -1; + //We call Mailman to unsubscribe the user + $result = $this->callMailman($object, $conf->global->ADHERENT_MAILMAN_UNSUB_URL, $list); + + if ($result === false) + { + $this->mlremoved_ko[$list]=$object->email; + return -2; + } + else $this->mlremoved_ok[$list]=$object->email; + } + return count($lists); + } + else + { + $this->error="ADHERENT_MAILMAN_UNSUB_URL not defined"; + return -1; + } } } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index e628b097fe5..c44b8907be5 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -336,19 +336,7 @@ class Product extends CommonObject $result = $this->_log_price($user); if ($result > 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 + if ($this->update($id, $user, true, 'add') <= 0) { $error++; $this->error='ErrorFailedToUpdateRecord'; @@ -673,7 +661,7 @@ class Product extends CommonObject } } } - + // Remove extrafields if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index 501781b309d..e48fa7739ff 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -184,16 +184,23 @@ class CategorieTest extends PHPUnit_Framework_TestCase print __METHOD__." catid=".$catid."\n"; $this->assertGreaterThan(0, $catid); - // Category + // Try to create product linked to category $localobject2=new Product($this->savdb); $localobject2->initAsSpecimen(); $localobject2->ref.='-CATEG'; $localobject2->tva_npr=1; - $localobject2->catid=$catid; $result=$localobject2->create($user); + $cat = new Categorie($this->savdb); + $cat->id = $catid; + $result=$cat->add_type($localobject2,"product"); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + print __METHOD__." result=".$result."\n"; + $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; }