diff --git a/htdocs/admin/ldap_groups.php b/htdocs/admin/ldap_groups.php index 0cd05a53a74..13532474681 100644 --- a/htdocs/admin/ldap_groups.php +++ b/htdocs/admin/ldap_groups.php @@ -57,7 +57,9 @@ if ($action == 'setvalue' && $user->admin) { if (!dolibarr_set_const($db, 'LDAP_GROUP_OBJECT_CLASS', GETPOST("objectclass", 'alphanohtml'), 'chaine', 0, '', $conf->entity)) { $error++; } - + if (!dolibarr_set_const($db, 'LDAP_GROUP_FILTER', GETPOST("filter"), 'chaine', 0, '', $conf->entity)) { + $error++; + } if (!dolibarr_set_const($db, 'LDAP_GROUP_FIELD_FULLNAME', GETPOST("fieldfullname", 'alphanohtml'), 'chaine', 0, '', $conf->entity)) { $error++; } @@ -141,6 +143,13 @@ print ''.$langs->trans("LDAPGroupObjectClassListExample").''; print ' '; print ''; +// Filter, used to filter search +print ''.$langs->trans("LDAPFilterConnection").''; +print ''; +print ''.$langs->trans("LDAPGroupFilterExample").''; +print ''; +print ''; + print ''; print '
'; print ''; @@ -211,11 +220,18 @@ if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') { $dn = $conf->global->LDAP_GROUP_DN; $objectclass = $conf->global->LDAP_GROUP_OBJECT_CLASS; + show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass); +} elseif ($conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') { + $butlabel = $langs->trans("LDAPTestSearch"); + $testlabel = 'testsearchgroup'; + $key = $conf->global->LDAP_KEY_GROUPS; + $dn = $conf->global->LDAP_GROUP_DN; + $objectclass = $conf->global->LDAP_GROUP_OBJECT_CLASS; show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass); } if (function_exists("ldap_connect")) { - if ($_GET["action"] == 'testgroup') { + if ($action == 'testgroup') { // Creation objet $object = new UserGroup($db); $object->initAsSpecimen(); @@ -260,6 +276,62 @@ if (function_exists("ldap_connect")) { print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'
'; } } + + if ($action == 'testsearchgroup') { + // TODO Mutualize code following with other ldap_xxxx.php pages + + // Test synchro + $ldap = new Ldap(); + $result = $ldap->connect_bind(); + + if ($result > 0) { + $required_fields = array( + $conf->global->LDAP_KEY_GROUPS, + // $conf->global->LDAP_GROUP_FIELD_NAME, + $conf->global->LDAP_GROUP_FIELD_DESCRIPTION, + $conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS, + $conf->global->LDAP_GROUP_FIELD_GROUPID + ); + + // Remove from required_fields all entries not configured in LDAP (empty) and duplicated + $required_fields = array_unique(array_values(array_filter($required_fields, "dol_validElement"))); + + // Get from LDAP database an array of results + $ldapgroups = $ldap->getRecords('*', $conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 'group'); + //$ldapgroups = $ldap->getRecords('*', $conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, '', 'group'); + + if (is_array($ldapgroups)) { + $liste = array(); + foreach ($ldapgroups as $key => $ldapgroup) { + // Define the label string for this group + $label = ''; + foreach ($required_fields as $value) { + if ($value) { + $label .= $value."=".$ldapgroup[$value]." "; + } + } + $liste[$key] = $label; + } + } else { + setEventMessages($ldap->error, $ldap->errors, 'errors'); + } + + print "
\n"; + print "LDAP search for group:
\n"; + print "search: *
\n"; + print "userDN: ".$conf->global->LDAP_GROUP_DN."
\n"; + print "useridentifier: ".$conf->global->LDAP_KEY_GROUPS."
\n"; + print "required_fields: ".implode(',', $required_fields)."
\n"; + print "=> ".count($liste)." records
\n"; + print "\n
"; + } else { + print img_picto('', 'error').' '; + print ''.$langs->trans("LDAPSynchroKO"); + print ': '.$ldap->error; + print '
'; + print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'
'; + } + } } // End of page diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index e71ec49da38..db1abb28c42 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -92,8 +92,8 @@ class BOM extends CommonObject 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5), 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'noteditable'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of BOM", 'showoncombobox'=>'1',), 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'notnull'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'autofocusoncreate'=>1), - //'bomtype' => array('type'=>'integer', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'position'=>10, 'notnull'=>1, 'default'=>'0', 'arrayofkeyval'=>array(0=>'Manufacturing', 1=>'Disassembly')), - 'bomtype' => array('type'=>'integer', 'label'=>'Type', 'enabled'=>1, 'visible'=>-1, 'position'=>32, 'notnull'=>1, 'default'=>'0', 'arrayofkeyval'=>array(0=>'Manufacturing')), + 'bomtype' => array('type'=>'integer', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'position'=>33, 'notnull'=>1, 'default'=>'0', 'arrayofkeyval'=>array(0=>'Manufacturing', 1=>'Disassemble')), + //'bomtype' => array('type'=>'integer', 'label'=>'Type', 'enabled'=>1, 'visible'=>-1, 'position'=>32, 'notnull'=>1, 'default'=>'0', 'arrayofkeyval'=>array(0=>'Manufacturing')), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:1:(finished IS NULL or finished <> 0)', 'label'=>'Product', 'picto'=>'product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'help'=>'ProductBOMHelp', 'css'=>'maxwidth500'), 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'notnull'=>-1,), 'qty' => array('type'=>'real', 'label'=>'Quantity', 'enabled'=>1, 'visible'=>1, 'default'=>1, 'position'=>55, 'notnull'=>1, 'isameasure'=>'1', 'css'=>'maxwidth75imp'), diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index 9963a178d1b..0f97ed878cf 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -139,6 +139,7 @@ class Ldap $this->groups = $conf->global->LDAP_GROUP_DN; $this->filter = $conf->global->LDAP_FILTER_CONNECTION; // Filter on user + $this->filtergroup = $conf->global->LDAP_GROUP_FILTER; // Filter on groups $this->filtermember = $conf->global->LDAP_MEMBER_FILTER; // Filter on member // Users @@ -935,7 +936,7 @@ class Ldap * @param string $userDn DN (Ex: ou=adherents,ou=people,dc=parinux,dc=org) * @param string $useridentifier Name of key field (Ex: uid) * @param array $attributeArray Array of fields required. Note this array must also contains field $useridentifier (Ex: sn,userPassword) - * @param int $activefilter '1' or 'user'=use field this->filter as filter instead of parameter $search, 'member'=use field this->filtermember as filter + * @param int $activefilter '1' or 'user'=use field this->filter as filter instead of parameter $search, 'group'=use field this->filtergroup as filter, 'member'=use field this->filtermember as filter * @param array $attributeAsArray Array of fields wanted as an array not a string * @return array Array of [id_record][ldap_field]=value */ @@ -955,6 +956,8 @@ class Ldap if (!empty($activefilter)) { if (((string) $activefilter == '1' || (string) $activefilter == 'user') && $this->filter) { $filter = '('.$this->filter.')'; + } elseif (((string) $activefilter == 'group') && $this->filtergroup ) { + $filter = '('.$this->filtergroup.')'; } elseif (((string) $activefilter == 'member') && $this->filter) { $filter = '('.$this->filtermember.')'; } else { diff --git a/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php b/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php index 82d61a41943..797530a6c13 100644 --- a/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php +++ b/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php @@ -449,7 +449,7 @@ class doc_generic_shipment_odt extends ModelePdfExpedition } // Replace tags of object + external modules - $tmparray = $this->get_substitutionarray_shipment($object, $outputlangs); + $tmparray = array_merge($tmparray, $this->get_substitutionarray_shipment($object, $outputlangs)); complete_substitutions_array($tmparray, $outputlangs, $object); // Call the ODTSubstitution hook diff --git a/htdocs/core/modules/modLdap.class.php b/htdocs/core/modules/modLdap.class.php index 5f4860d0149..8e3463ff4d4 100644 --- a/htdocs/core/modules/modLdap.class.php +++ b/htdocs/core/modules/modLdap.class.php @@ -85,6 +85,7 @@ class modLdap extends DolibarrModules 11=>array('LDAP_FIELD_PHONE', 'chaine', 'telephonenumber', '', 0), 12=>array('LDAP_FIELD_FAX', 'chaine', 'facsimiletelephonenumber', '', 0), 13=>array('LDAP_FIELD_MOBILE', 'chaine', 'mobile', '', 0), + 14=>array('LDAP_GROUP_FILTER', 'chaine', '&(objectClass=groupOfNames)', '', 0), ); // Boxes diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index 9e65e1d82ff..36fccbb7b2d 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -171,7 +171,7 @@ create table llx_payment_vat ALTER TABLE llx_tva ADD COLUMN paye smallint default 1 NOT NULL; ALTER TABLE llx_tva ADD COLUMN fk_account integer; ---INSERT INTO llx_payment_vat (fk_tva, datec, datep, amount, fk_typepaiement, num_paiement, note, fk_bank, fk_user_creat, fk_user_modif) SELECT rowid, NOW(), datep, amount, COALESCE(fk_typepayment, 0), num_payment, '', fk_bank, fk_user_creat, fk_user_modif FROM llx_tva; +INSERT INTO llx_payment_vat (rowid, fk_tva, datec, datep, amount, fk_typepaiement, num_paiement, note, fk_bank, fk_user_creat, fk_user_modif) SELECT rowid, rowid, NOW(), datep, amount, COALESCE(fk_typepayment, 0), num_payment, 'Created automatically by migration v13 to v14', fk_bank, fk_user_creat, fk_user_modif FROM llx_tva WHERE fk_bank IS NOT NULL; --UPDATE llx_bank_url as url INNER JOIN llx_tva tva ON tva.rowid = url.url_id SET url.type = 'vat', url.label = CONCAT('(', tva.label, ')') WHERE type = 'payment_vat'; --INSERT INTO llx_bank_url (fk_bank, url_id, url, label, type) SELECT b.fk_bank, ptva.rowid, REPLACE(b.url, 'tva/card.php', 'payment_vat/card.php'), '(paiement)', 'payment_vat' FROM llx_bank_url b INNER JOIN llx_tva tva ON (tva.fk_bank = b.fk_bank) INNER JOIN llx_payment_vat ptva on (ptva.fk_bank = b.fk_bank) WHERE type = 'vat'; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 6b481e1357b..a94eaa75dcf 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1512,6 +1512,7 @@ LDAPFieldLoginUnix=Login (unix) LDAPFieldLoginExample=Example: uid LDAPFilterConnection=Search filter LDAPFilterConnectionExample=Example: &(objectClass=inetOrgPerson) +LDAPGroupFilterExample=Example: &(objectClass=groupOfUsers) LDAPFieldLoginSamba=Login (samba, activedirectory) LDAPFieldLoginSambaExample=Example: samaccountname LDAPFieldFullname=Full name diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index b22a6c389dd..d911a53ef5e 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -632,9 +632,21 @@ class Mo extends CommonObject $moline->fk_mo = $this->id; $moline->qty = $this->qty; $moline->fk_product = $this->fk_product; - $moline->role = 'toproduce'; $moline->position = 1; + if ($this->fk_bom > 0) { // If a BOM is defined, we know what to consume. + include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; + $bom = new Bom($this->db); + $bom->fetch($this->fk_bom); + if ($bom->bomtype == 1) { + $role = 'toproduce'; + $moline->role = 'toconsume'; + } else { + $role = 'toconsume'; + $moline->role = 'toproduce'; + } + } + $resultline = $moline->create($user, false); // Never use triggers here if ($resultline <= 0) { $error++; @@ -644,9 +656,6 @@ class Mo extends CommonObject } if ($this->fk_bom > 0) { // If a BOM is defined, we know what to consume. - include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; - $bom = new Bom($this->db); - $bom->fetch($this->fk_bom); if ($bom->id > 0) { // Lines to consume if (!$error) { @@ -667,7 +676,7 @@ class Mo extends CommonObject break; } else { $moline->fk_product = $line->fk_product; - $moline->role = 'toconsume'; + $moline->role = $role; $moline->position = $line->position; $moline->qty_frozen = $line->qty_frozen; $moline->disable_stock_change = $line->disable_stock_change; diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index 9b58ea1bc5d..a7ef895041e 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -4,6 +4,7 @@ * Copyright (C) 2013-2015 Juanjo Menent * Copyright (C) 2015 Marcos García * Copyright (C) 2015-2017 Ferran Marcet + * Copyright (C) 2021 Frédéric France * * 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 @@ -472,6 +473,7 @@ if ($sql_select) { $documentstatic->statut = $objp->status; $documentstatic->status = $objp->status; $documentstatic->paye = $objp->paid; + $documentstatic->alreadypaid = $objp->paid; if (is_object($documentstaticline)) { $documentstaticline->statut = $objp->status; @@ -487,6 +489,8 @@ if ($sql_select) { print '
'; if ($type_element == 'contract') { print $documentstaticline->getLibStatut(5); + } elseif ($type_element == 'invoice') { + print $documentstatic->getLibStatut(5, $objp->paid); } else { print $documentstatic->getLibStatut(5); } @@ -496,7 +500,9 @@ if ($sql_select) { print ''; // Define text, description and type - $text = ''; $description = ''; $type = 0; + $text = ''; + $description = ''; + $type = 0; // Code to show product duplicated from commonobject->printObjectLine if ($objp->fk_product > 0) { diff --git a/scripts/user/sync_groups_ldap2dolibarr.php b/scripts/user/sync_groups_ldap2dolibarr.php index af0b117bb5e..67c14a4ee5d 100755 --- a/scripts/user/sync_groups_ldap2dolibarr.php +++ b/scripts/user/sync_groups_ldap2dolibarr.php @@ -97,7 +97,11 @@ print "port=".$conf->global->LDAP_SERVER_PORT."\n"; print "login=".$conf->global->LDAP_ADMIN_DN."\n"; print "pass=".preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)."\n"; print "DN to extract=".$conf->global->LDAP_GROUP_DN."\n"; -print 'Filter=('.$conf->global->LDAP_KEY_GROUPS.'=*)'."\n"; +if (!empty($conf->global->LDAP_GROUP_FILTER)) { + print 'Filter=('.$conf->global->LDAP_GROUP_FILTER.')'."\n"; // Note: filter is defined into function getRecords +} else { + print 'Filter=('.$conf->global->LDAP_KEY_GROUPS.'=*)'."\n"; +} print "----- To Dolibarr database:\n"; print "type=".$conf->db->type."\n"; print "host=".$conf->db->host."\n"; @@ -127,7 +131,7 @@ if ($result >= 0) { // We disable synchro Dolibarr-LDAP $conf->global->LDAP_SYNCHRO_ACTIVE = 0; - $ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)); + $ldaprecords = $ldap->getRecords('*', $conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 'group', array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)); if (is_array($ldaprecords)) { $db->begin();