From 1eddf95d955b2b259081bbd4bdf49c122d22f749 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Mon, 25 Feb 2013 16:46:31 +0100 Subject: [PATCH 1/5] LDAP : update user sync + add groups sync and users associated to group + add fetch by name on group class --- htdocs/user/class/usergroup.class.php | 18 +- scripts/user/sync_groups_ldap2dolibarr.php | 247 +++++++++++++++++++++ scripts/user/sync_users_ldap2dolibarr.php | 6 +- 3 files changed, 264 insertions(+), 7 deletions(-) create mode 100755 scripts/user/sync_groups_ldap2dolibarr.php diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 206c8bffcf3..5876e05a213 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -66,18 +66,24 @@ class UserGroup extends CommonObject /** * Charge un objet group avec toutes ces caracteristiques (excpet ->members array) * - * @param int $id id du groupe a charger - * @return int <0 if KO, >0 if OK + * @param int $id id du groupe a charger + * @param string $groupname nom du groupe a charger + * @return int <0 if KO, >0 if OK */ - function fetch($id) + function fetch($id='', $groupname='') { global $conf; - $this->id = $id; - $sql = "SELECT g.rowid, g.entity, g.nom as name, g.note, g.datec, g.tms as datem"; $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as g"; - $sql.= " WHERE g.rowid = ".$this->id; + if ($groupname) + { + $sql.= " WHERE g.nom = '".$this->db->escape($groupname)."'"; + } + else + { + $sql.= " WHERE g.rowid = ".$id; + } dol_syslog(get_class($this)."::fetch sql=".$sql); $result = $this->db->query($sql); diff --git a/scripts/user/sync_groups_ldap2dolibarr.php b/scripts/user/sync_groups_ldap2dolibarr.php new file mode 100755 index 00000000000..c19999c755f --- /dev/null +++ b/scripts/user/sync_groups_ldap2dolibarr.php @@ -0,0 +1,247 @@ +#!/usr/bin/php + + * Copyright (C) 2006-2012 Laurent Destailleur + * Copyright (C) 2013 Maxime Kohlhaas + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file scripts/user/sync_groups_ldap2dolibarr.php + * \ingroup ldap member + * \brief Script to update groups into Dolibarr from LDAP + */ + +$sapi_type = php_sapi_name(); +$script_file = basename(__FILE__); +$path=dirname(__FILE__).'/'; + +// Test if batch mode +if (substr($sapi_type, 0, 3) == 'cgi') { + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit; +} + + + + +// Main + +$version='1.14'; +@set_time_limit(0); +$error=0; +$forcecommit=0; + +require_once($path."../../htdocs/master.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); +require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php"); +require_once(DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"); + +$langs->load("main"); +$langs->load("errors"); + +// List of fields to get from LDAP +$required_fields = array( + $conf->global->LDAP_KEY_GROUPS, + $conf->global->LDAP_GROUP_FIELD_FULLNAME, + $conf->global->LDAP_GROUP_FIELD_DESCRIPTION, + $conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS +); + +// Remove from required_fields all entries not configured in LDAP (empty) and duplicated +$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); + +if ($argv[2]) $conf->global->LDAP_SERVER_HOST=$argv[2]; + +print "***** $script_file ($version) *****\n"; + +if (! isset($argv[1])) { + //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; + print "Usage: $script_file (nocommitiferror|commitiferror) [ldapserverhost]\n"; + exit; +} +$groupid=$argv[3]; +if ($argv[1] == 'commitiferror') $forcecommit=1; + + +print "Mails sending disabled (useless in batch mode)\n"; +$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails +print "\n"; +print "----- Synchronize all records from LDAP database:\n"; +print "host=".$conf->global->LDAP_SERVER_HOST."\n"; +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"; +print "----- To Dolibarr database:\n"; +print "type=".$conf->db->type."\n"; +print "host=".$conf->db->host."\n"; +print "port=".$conf->db->port."\n"; +print "login=".$conf->db->user."\n"; +print "database=".$conf->db->name."\n"; +print "----- Options:\n"; +print "commitiferror=".$forcecommit."\n"; +print "Mapped LDAP fields=".join(',',$required_fields)."\n"; +print "\n"; +print "Press a key to confirm..."; +$input = trim(fgets(STDIN)); +print "Hit Enter to continue or CTRL+C to stop...\n"; +$input = trim(fgets(STDIN)); + + +if (empty($conf->global->LDAP_GROUP_DN)) +{ + print $langs->trans("Error").': '.$langs->trans("LDAP setup for groups not defined inside Dolibarr"); + exit(1); +} + + +$ldap = new Ldap(); +$result = $ldap->connect_bind(); +if ($result >= 0) +{ + $justthese=array(); + + + // 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)); + if (is_array($ldaprecords)) + { + $db->begin(); + + // Warning $ldapuser has a key in lowercase + foreach ($ldaprecords as $key => $ldapgroup) + { + $group = new UserGroup($db); + $group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]); + $group->nom = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME]; + $group->note = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION]; + $group->entity = $conf->entity; + + //print_r($ldapgroup); + + if($group->id > 0) { // Group update + print $langs->transnoentities("GroupUpdate").' # '.$key.': name='.$group->nom; + $res=$group->update(); + + if ($res > 0) + { + print ' --> Updated group id='.$group->id.' name='.$group->nom; + } + else + { + $error++; + print ' --> '.$res.' '.$group->error; + } + print "\n"; + } else { // Group creation + print $langs->transnoentities("GroupCreate").' # '.$key.': name='.$group->nom; + $res=$group->create(); + + if ($res > 0) + { + print ' --> Created group id='.$group->id.' name='.$group->nom; + } + else + { + $error++; + print ' --> '.$res.' '.$group->error; + } + print "\n"; + } + + //print_r($group); + + // Gestion des utilisateurs associés au groupe + // 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr + $userList = array(); + $userIdList = array(); + foreach($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) { + if($key == 'count') continue; + if(empty($userList[$userdn])) { // Récupération de l'utilisateur + $userFilter = explode(',', $userdn); + $userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS); + + $fuser = new User($db); + + if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { + $fuser->fetch('','',$userKey[0]); // Chargement du user concerné par le SID + } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { + $fuser->fetch('',$userKey[0]); // Chargement du user concerné par le login + } + + $userList[$userdn] = &$fuser; + } else { + $fuser = &$userList[$userdn]; + } + + $userIdList[$userdn] = $fuser->id; + + // Ajout de l'utilisateur dans le groupe + if(!in_array($fuser->id, array_keys($group->members))) $fuser->SetInGroup($group->id, $group->entity); + } + + // 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP + foreach ($group->members as $user_id => $infos) { + if(!in_array($user_id, $userIdList)) $fuser->RemoveFromGroup($group->id, $group->entity); + } + } + + if (! $error || $forcecommit) + { + if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n"; + else print $langs->transnoentities("ErrorButCommitIsDone")."\n"; + $db->commit(); + } + else + { + print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n"; + $db->rollback(); + } + print "\n"; + } + else + { + dol_print_error('',$ldap->error); + $error++; + } +} +else +{ + dol_print_error('',$ldap->error); + $error++; +} + + +return $error; + + +/** + * Function to say if a value is empty or not + * + * @param string $element Value to test + * @return boolean True of false + */ +function dolValidElement($element) +{ + return (trim($element) != ''); +} + +?> diff --git a/scripts/user/sync_users_ldap2dolibarr.php b/scripts/user/sync_users_ldap2dolibarr.php index 1f9360f013a..64bea3ca567 100755 --- a/scripts/user/sync_users_ldap2dolibarr.php +++ b/scripts/user/sync_users_ldap2dolibarr.php @@ -179,7 +179,11 @@ if ($result >= 0) { $fuser = new User($db); - $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné + if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) { + $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID + } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { + $fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login + } // Propriete membre $fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME]; From cd5bda27f4ea74bda5e2b0dc6823fee610d56c47 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Mon, 25 Feb 2013 16:56:37 +0100 Subject: [PATCH 2/5] Supplier dispatch : add new trigger called after order is dispatched --- htdocs/fourn/commande/dispatch.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index bdb41c091ec..911e6b7fd90 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -84,6 +84,19 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece } } } + + if (! $notrigger) + { + global $conf, $langs, $user; + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result_trigger=$interface->run_triggers('ORDER_SUPPLIER_DISPATCH',$this,$user,$langs,$conf); + if ($result_trigger < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + $this->db->commit(); + } if ($result > 0) { From 3d814c58e5a431833c79fe1d493a0cf20be9a1bd Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 26 Feb 2013 09:28:56 +0100 Subject: [PATCH 3/5] Bug # 736 : incorrect table name in migration script, muse be done in 3.3 branch too --- htdocs/install/mysql/migration/3.2.0-3.3.0.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index 3793e822102..b6ec2f66321 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -311,7 +311,7 @@ UPDATE llx_c_tva set localtax1 = 1, localtax1_type = '4', localtax2 = 0.4, local ALTER TABLE llx_c_tva DROP COLUMN accountancy_code; ALTER TABLE llx_c_tva ADD COLUMN accountancy_code_sell varchar(15) DEFAULT NULL AFTER active; ALTER TABLE llx_c_tva ADD COLUMN accountancy_code_buy varchar(15) DEFAULT NULL AFTER accountancy_code_sell; -ALTER TABLE llx_c_chargessociales ADD COLUMN accountancy_code varchar(15) DEFAULT NULL AFTER code; +ALTER TABLE llx_c_chargesociales ADD COLUMN accountancy_code varchar(15) DEFAULT NULL AFTER code; -- Tables for accountancy expert DROP TABLE llx_accountingaccount; From e208bdf88146cac91161e32dd3d7fc3c007bae22 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 26 Feb 2013 12:05:55 +0100 Subject: [PATCH 4/5] Theme : amarok was missing favicon, put eldy's one in place, to be replaced by a specific favicon --- htdocs/theme/amarok/img/favicon.ico | Bin 0 -> 3638 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 htdocs/theme/amarok/img/favicon.ico diff --git a/htdocs/theme/amarok/img/favicon.ico b/htdocs/theme/amarok/img/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..7d41c54d5bb98e9d5d6b1c8b359f0f2757b69230 GIT binary patch literal 3638 zcmdtk+jmse9S87lNL&+!w#JpNG^7{~33m~#LXkpX%T3BnNVqvOz%c{_#0Uf-VGUuE z3ss9yfkF%;oXkuxl9_>C2x>t$IItj1D|XrTp?x?{eIc$zR{<83LC61N{x3 z`JH`!d+)Q)Z32*ie#psz6YCxUhI7j>+;&?wu#fvjvZ=f1-5KCchRATz17GWwEy9WY z4T$cpL9}iM+8TlgzP1MC+c&^^>k#VR-H*Z%hBKzNp$4(~iKwp3LvT|8cF>{C`H0ob zL^QM*Z98Y<%*W?2q-Z!~T{VK0V;}>7TnW@ta0R_YYX_rd{SbWoX*-4vdjfLPSV$A7 zD+k_OP0S5zIc}96n~C6(Of((a$77Dg*7?9w)AAsEqcC~l7*rGko4Buz<7!vtqiy$S z?BKCum7@_{S%il25%4bn0{#tndi+#u+_f6D^RhYjFdlO#RwLXv z8r91SdE6qrwBQl=eC7D+Y%{iO%tg>=Am}&nX4Nnh4gikrtVY+{qYI}4P8N~i`5!$~E$IE9PR1F%qd%>Vfy<|F!YS@6Mh7)T=IB{5+%qRQsr&e~nxwXduTtk-RCx7nPQ|?WK#BE%#2JF>}@nPP=T*+1HSX!?=c?DdF-*= z?{k`d{rY7xva+&t%j?Y=%scC$Oycij7I}8lg>T_LU3dEFzIqJD>fc#|1f_pxWfmLh z&|`W-LVx(1=6v;SD5aqOu5hFC1Zxs0=L0^2?Bj4Z^fP(m-zh{biw6~Ck|f<$WV;Iy z2D2cOBw3`$227Aag4i%6S)|D3;y?xoGD(s}ifn+JunZDpk|c{1*#HxiL4r(@WRW5p z;6K;~2{K8NMT%?)aG5Yje@v2Oks=$y02w66BuN%2vfa~WCm{rxB*`L0wtGoTgISPC zk}OhWyO&EE%z{jkWRW7f=rTRks=$C z=PzN9K68`w$09|xdut4XS&&JREK+2TmNs>j1Y$%?;f;A8dC(Ow0xqC}TESf@pZpLElU-6Aw zVD?J6pY95r3{;->u%AtoL`8>UP&7{NJwk*U^)nrQIKY zV0`wPK%kMP=t=L3JN4^2 zB6_ttvJ(L=!QJO)-QDb~!;^^j?&KMy>+Sc(^PWAdel$J5Q}6Db-;?;d_fYrMJ&E)& z{j7IiZ)ZgAugBee?GYbXZ;$Bk_08|;W`BlLk3XcYi%uLxBHrz8_KnZ(Ek+_?UZ382 zI9>O|ea-0(%_-Jnk+2S*zk(4cE%h}!?Ql2}j`04Z>&-qVn$y)Vr@wt)y?0PwiiD$l z5$=ueE4W)+gZ}IHKk9mgx%wS=Xgv~%#bO=KEAroUUF`0TC)_uP_qv;%`=a}6zK!v? zGr6AscIx(n5s$aFCOr4v;noKu5LlDQ?W;oOcv8s8(5JGCrqW<~l=K3$Oh*nfSRq9= f-O$+Ek#6_aWX8R5?)davdR{%hKF%(QjMRSsa3SqU literal 0 HcmV?d00001 From 0de4fa09f13c5a0181495180cbe5c2b7688d4946 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 26 Feb 2013 12:52:37 +0100 Subject: [PATCH 5/5] Product price : updated always with HT base type after product import --- htdocs/product/price.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/price.php b/htdocs/product/price.php index cbd9bb585f9..2d0a1816982 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -680,7 +680,7 @@ if ($result) // Il doit au moins y avoir la ligne de prix initial. // On l'ajoute donc pour remettre a niveau (pb vieilles versions) - $object->updatePrice($object->id, $object->price, 'HT', $user, $newprice_min); + $object->updatePrice($object->id, $object->price, $object->price_base_type, $user, $newprice_min); $result = $db->query($sql); $num = $db->num_rows($result);