forked from Wavyzz/dolibarr
Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
|
||||
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
|
||||
* Copyright (C) 2012-2016 Philippe Grand <philippe.grand@atoo-net.com>
|
||||
* Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
||||
@@ -833,6 +833,7 @@ else
|
||||
print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
if ($backtopage) print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
|
||||
|
||||
dol_fiche_head('');
|
||||
|
||||
@@ -976,8 +977,15 @@ else
|
||||
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" name="button" class="button" value="'.$langs->trans("AddMember").'">';
|
||||
print ' ';
|
||||
print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'" onclick="history.go(-1)" />';
|
||||
print ' ';
|
||||
if (! empty($backtopage))
|
||||
{
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
print "</form>\n";
|
||||
@@ -1245,7 +1253,7 @@ else
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'" onclick="history.go(-1)" />';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
print '</div>';
|
||||
|
||||
print '</form>';
|
||||
|
||||
@@ -419,7 +419,7 @@ class Adherent extends CommonObject
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
|
||||
$sql.= " civility = ".(!is_null($this->civility_id)?$this->db->escape($this->civility_id):"null");
|
||||
$sql.= " civility = ".($this->civility_id>0?$this->db->escape($this->civility_id):"null");
|
||||
$sql.= ", firstname = ".($this->firstname?"'".$this->db->escape($this->firstname)."'":"null");
|
||||
$sql.= ", lastname = ".($this->lastname?"'".$this->db->escape($this->lastname)."'":"null");
|
||||
$sql.= ", login = ".($this->login?"'".$this->db->escape($this->login)."'":"null");
|
||||
@@ -720,7 +720,6 @@ class Adherent extends CommonObject
|
||||
$error++;
|
||||
$this->error .= $this->db->lasterror();
|
||||
$errorflag=-1;
|
||||
|
||||
}
|
||||
|
||||
// Remove subscription
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
* \file htdocs/adherents/class/adherent_type.class.php
|
||||
* \ingroup member
|
||||
* \brief File of class to manage members types
|
||||
* \author Rodolphe Quiedeville
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||
@@ -62,6 +61,8 @@ class AdherentType extends CommonObject
|
||||
public $vote;
|
||||
/** @var bool Email sent during validation */
|
||||
public $mail_valid;
|
||||
/** @var array Array of members */
|
||||
public $members=array();
|
||||
|
||||
|
||||
/**
|
||||
@@ -80,14 +81,19 @@ class AdherentType extends CommonObject
|
||||
* Fonction qui permet de creer le status de l'adherent
|
||||
*
|
||||
* @param User $user User making creation
|
||||
* @param int $notrigger 1=do not execute triggers, 0 otherwise
|
||||
* @return int >0 if OK, < 0 if KO
|
||||
*/
|
||||
function create($user)
|
||||
function create($user,$notrigger=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$error=0;
|
||||
|
||||
$this->statut=(int) $this->statut;
|
||||
$this->label=(!empty($this->libelle)?trim($this->libelle):trim($this->label));
|
||||
$this->label=trim($this->label);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type (";
|
||||
$sql.= "libelle";
|
||||
@@ -102,29 +108,58 @@ class AdherentType extends CommonObject
|
||||
if ($result)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type");
|
||||
return $this->update($user);
|
||||
|
||||
$result = $this->update($user,1);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (! $notrigger)
|
||||
{
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('MEMBER_TYPE_CREATE',$user);
|
||||
if ($result < 0) { $error++; }
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error().' sql='.$sql;
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Met a jour en base donnees du type
|
||||
*
|
||||
* @param User $user Object user making change
|
||||
* @param int $notrigger 1=do not execute triggers, 0 otherwise
|
||||
* @return int >0 if OK, < 0 if KO
|
||||
*/
|
||||
function update($user)
|
||||
function update($user,$notrigger=0)
|
||||
{
|
||||
global $hookmanager,$conf;
|
||||
global $conf, $hookmanager;
|
||||
|
||||
$error=0;
|
||||
|
||||
$this->label=(!empty($this->libelle)?trim($this->libelle):trim($this->label));
|
||||
$this->label=trim($this->label);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type ";
|
||||
$sql.= "SET ";
|
||||
@@ -158,12 +193,30 @@ class AdherentType extends CommonObject
|
||||
}
|
||||
else if ($reshook < 0) $error++;
|
||||
|
||||
if (! $error && ! $notrigger)
|
||||
{
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('MEMBER_TYPE_MODIFY',$user);
|
||||
if ($result < 0) { $error++; }
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error().' sql='.$sql;
|
||||
$this->db->rollback();
|
||||
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
|
||||
return -$error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -171,31 +224,31 @@ class AdherentType extends CommonObject
|
||||
/**
|
||||
* Fonction qui permet de supprimer le status de l'adherent
|
||||
*
|
||||
* @param int $rowid Id of member type to delete
|
||||
* @return int >0 if OK, 0 if not found, < 0 if KO
|
||||
*/
|
||||
function delete($rowid='')
|
||||
function delete()
|
||||
{
|
||||
if (empty($rowid)) $rowid=$this->id;
|
||||
global $user;
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type WHERE rowid = ".$rowid;
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type";
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->affected_rows($resql))
|
||||
{
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('MEMBER_TYPE_DELETE',$user);
|
||||
if ($result < 0) { $error++; $this->db->rollback(); return -2; }
|
||||
// End call triggers
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Err : ".$this->db->error();
|
||||
return 0;
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,13 +276,13 @@ class AdherentType extends CommonObject
|
||||
$this->id = $obj->rowid;
|
||||
$this->ref = $obj->rowid;
|
||||
$this->label = $obj->label;
|
||||
$this->libelle = $obj->label; // For backward compatibility
|
||||
$this->statut = $obj->statut;
|
||||
$this->subscription = $obj->subscription;
|
||||
$this->mail_valid = $obj->mail_valid;
|
||||
$this->note = $obj->note;
|
||||
$this->vote = $obj->vote;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -250,7 +303,7 @@ class AdherentType extends CommonObject
|
||||
|
||||
$adherenttypes = array();
|
||||
|
||||
$sql = "SELECT rowid, libelle";
|
||||
$sql = "SELECT rowid, libelle as label";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type";
|
||||
$sql.= " WHERE entity IN (".getEntity('adherent').")";
|
||||
|
||||
@@ -266,7 +319,7 @@ class AdherentType extends CommonObject
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$adherenttypes[$obj->rowid] = $langs->trans($obj->libelle);
|
||||
$adherenttypes[$obj->rowid] = $langs->trans($obj->label);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
@@ -278,12 +331,61 @@ class AdherentType extends CommonObject
|
||||
return $adherenttypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of Member objects for member type this->id (or all if this->id not defined)
|
||||
*
|
||||
* @param string $excludefilter Filter to exclude
|
||||
* @param int $mode 0=Return array of member instance, 1=Return array of members id only
|
||||
* @return mixed Array of members or -1 on error
|
||||
*/
|
||||
function listMembersForMemberType($excludefilter='', $mode=0)
|
||||
{
|
||||
global $conf, $user;
|
||||
|
||||
$ret=array();
|
||||
|
||||
$sql = "SELECT a.rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
|
||||
$sql.= " WHERE a.entity IN (".getEntity('member').")";
|
||||
$sql.= " AND a.fk_adherent_type = ".$this->id;
|
||||
if (! empty($excludefilter)) $sql.=' AND ('.$excludefilter.')';
|
||||
|
||||
dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
while ($obj = $this->db->fetch_object($resql))
|
||||
{
|
||||
if (! array_key_exists($obj->rowid, $ret))
|
||||
{
|
||||
if ($mode != 1)
|
||||
{
|
||||
$memberstatic=new Adherent($this->db);
|
||||
$memberstatic->fetch($obj->rowid);
|
||||
$ret[$obj->rowid]=$memberstatic;
|
||||
}
|
||||
else $ret[$obj->rowid]=$obj->rowid;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
$this->members=$ret;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return clicable name (with picto eventually)
|
||||
*
|
||||
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
|
||||
* @param int $maxlen length max libelle
|
||||
* @param int $maxlen length max label
|
||||
* @return string String with URL
|
||||
*/
|
||||
function getNomUrl($withpicto=0,$maxlen=0)
|
||||
@@ -291,7 +393,7 @@ class AdherentType extends CommonObject
|
||||
global $langs;
|
||||
|
||||
$result='';
|
||||
$label=$langs->trans("ShowTypeCard",$this->libelle);
|
||||
$label=$langs->trans("ShowTypeCard",$this->label);
|
||||
|
||||
$link = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
|
||||
$linkend='</a>';
|
||||
@@ -300,11 +402,10 @@ class AdherentType extends CommonObject
|
||||
|
||||
if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
|
||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||
$result.=$link.($maxlen?dol_trunc($this->libelle,$maxlen):$this->libelle).$linkend;
|
||||
$result.=$link.($maxlen?dol_trunc($this->label,$maxlen):$this->label).$linkend;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getLibStatut
|
||||
*
|
||||
@@ -315,6 +416,88 @@ class AdherentType extends CommonObject
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne chaine DN complete dans l'annuaire LDAP pour l'objet
|
||||
*
|
||||
* @param array $info Info array loaded by _load_ldap_info
|
||||
* @param int $mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb)
|
||||
* 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb)
|
||||
* 2=Return key only (uid=qqq)
|
||||
* @return string DN
|
||||
*/
|
||||
function _load_ldap_dn($info,$mode=0)
|
||||
{
|
||||
global $conf;
|
||||
$dn='';
|
||||
if ($mode==0) $dn=$conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].",".$conf->global->LDAP_MEMBER_TYPE_DN;
|
||||
if ($mode==1) $dn=$conf->global->LDAP_MEMBER_TYPE_DN;
|
||||
if ($mode==2) $dn=$conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES];
|
||||
return $dn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the info array (array of LDAP values) that will be used to call LDAP functions
|
||||
*
|
||||
* @return array Tableau info des attributs
|
||||
*/
|
||||
function _load_ldap_info()
|
||||
{
|
||||
global $conf,$langs;
|
||||
|
||||
$info=array();
|
||||
|
||||
// Object classes
|
||||
$info["objectclass"]=explode(',',$conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS);
|
||||
|
||||
// Champs
|
||||
if ($this->label && ! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label;
|
||||
if ($this->note && ! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION] = $this->note;
|
||||
if (! empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS))
|
||||
{
|
||||
$valueofldapfield=array();
|
||||
foreach($this->members as $key=>$val) // This is array of users for group into dolibarr database.
|
||||
{
|
||||
$member=new Adherent($this->db);
|
||||
$member->fetch($val->id);
|
||||
$info2 = $member->_load_ldap_info();
|
||||
$valueofldapfield[] = $member->_load_ldap_dn($info2);
|
||||
}
|
||||
$info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield)?$valueofldapfield:'');
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise an instance with random values.
|
||||
* Used to build previews or test instances.
|
||||
* id must be 0 if object instance is a specimen.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function initAsSpecimen()
|
||||
{
|
||||
global $conf, $user, $langs;
|
||||
|
||||
// Initialise parametres
|
||||
$this->id = 0;
|
||||
$this->ref = 0;
|
||||
$this->specimen=1;
|
||||
|
||||
$this->label='MEMBERS TYPE SPECIMEN';
|
||||
$this->note='This is a note';
|
||||
$this->mail_valid='This is welcome email';
|
||||
$this->subscription=1;
|
||||
$this->vote=0;
|
||||
|
||||
$this->statut=1;
|
||||
|
||||
// Members of this member type is just me
|
||||
$this->members=array(
|
||||
$user->id => $user
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* getMailOnValid
|
||||
*
|
||||
@@ -342,6 +525,7 @@ class AdherentType extends CommonObject
|
||||
function getMailOnSubscription()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// mail_subscription not defined so never used
|
||||
if (! empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) // Property not yet defined
|
||||
{
|
||||
@@ -361,6 +545,7 @@ class AdherentType extends CommonObject
|
||||
function getMailOnResiliate()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// NOTE mail_resiliate not defined so never used
|
||||
if (! empty($this->mail_resiliate) && trim(dol_htmlentitiesbr_decode($this->mail_resiliate))) // Property not yet defined
|
||||
{
|
||||
@@ -371,4 +556,5 @@ class AdherentType extends CommonObject
|
||||
return $conf->global->ADHERENT_MAIL_RESIL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -272,7 +272,6 @@ class MembersTypes extends DolibarrApi
|
||||
$object = parent::_cleanObjectDatas($object);
|
||||
|
||||
unset($object->cotisation);
|
||||
unset($object->libelle);
|
||||
|
||||
unset($object->array_options);
|
||||
unset($object->linkedObjectsIds);
|
||||
|
||||
@@ -59,7 +59,7 @@ $AdherentsResilies=array();
|
||||
$AdherentType=array();
|
||||
|
||||
// Liste les adherents
|
||||
$sql = "SELECT t.rowid, t.libelle, t.subscription,";
|
||||
$sql = "SELECT t.rowid, t.libelle as label, t.subscription,";
|
||||
$sql.= " d.statut, count(d.rowid) as somme";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d";
|
||||
@@ -81,7 +81,7 @@ if ($result)
|
||||
$adhtype=new AdherentType($db);
|
||||
$adhtype->id=$objp->rowid;
|
||||
$adhtype->subscription=$objp->subscription;
|
||||
$adhtype->libelle=$objp->libelle;
|
||||
$adhtype->label=$objp->label;
|
||||
$AdherentType[$objp->rowid]=$adhtype;
|
||||
|
||||
if ($objp->statut == -1) { $MemberToValidate[$objp->rowid]=$objp->somme; }
|
||||
@@ -273,7 +273,7 @@ $max=5;
|
||||
|
||||
$sql = "SELECT a.rowid, a.statut, a.lastname, a.firstname, a.societe as company, a.fk_soc,";
|
||||
$sql.= " a.tms as datem, datefin as date_end_subscription,";
|
||||
$sql.= " ta.rowid as typeid, ta.libelle, ta.subscription";
|
||||
$sql.= " ta.rowid as typeid, ta.libelle as label, ta.subscription";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a, ".MAIN_DB_PREFIX."adherent_type as ta";
|
||||
$sql.= " WHERE a.entity IN (".getEntity('adherent').")";
|
||||
$sql.= " AND a.fk_adherent_type = ta.rowid";
|
||||
@@ -310,7 +310,7 @@ if ($resql)
|
||||
}
|
||||
$staticmember->ref=$staticmember->getFullName($langs);
|
||||
$statictype->id=$obj->typeid;
|
||||
$statictype->libelle=$obj->libelle;
|
||||
$statictype->label=$obj->label;
|
||||
print '<td>'.$staticmember->getNomUrl(1,32).'</td>';
|
||||
print '<td>'.$statictype->getNomUrl(1,32).'</td>';
|
||||
print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2006-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* 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
|
||||
@@ -218,13 +218,11 @@ if ($result > 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error('',$ldap->error);
|
||||
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
||||
}
|
||||
|
||||
|
||||
print '</table>';
|
||||
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
|
||||
@@ -315,7 +315,7 @@ if ($search_type > 0)
|
||||
{
|
||||
$membertype=new AdherentType($db);
|
||||
$result=$membertype->fetch(GETPOST("type",'int'));
|
||||
$titre.=" (".$membertype->libelle.")";
|
||||
$titre.=" (".$membertype->label.")";
|
||||
}
|
||||
|
||||
$param='';
|
||||
@@ -698,7 +698,7 @@ while ($i < min($num, $limit))
|
||||
if (! empty($arrayfields['t.libelle']['checked']))
|
||||
{
|
||||
$membertypestatic->id=$obj->type_id;
|
||||
$membertypestatic->libelle=$obj->type;
|
||||
$membertypestatic->label=$obj->type;
|
||||
print '<td class="nowrap">';
|
||||
print $membertypestatic->getNomUrl(1,32);
|
||||
print '</td>';
|
||||
|
||||
@@ -37,6 +37,7 @@ $langs->load("members");
|
||||
$rowid = GETPOST('rowid','int');
|
||||
$action = GETPOST('action','alpha');
|
||||
$cancel = GETPOST('cancel','alpha');
|
||||
$backtopage = GETPOST('backtopage','alpha');
|
||||
|
||||
$search_lastname = GETPOST('search_lastname','alpha');
|
||||
$search_login = GETPOST('search_login','alpha');
|
||||
@@ -64,6 +65,8 @@ $mail_valid=GETPOST("mail_valid");
|
||||
// Security check
|
||||
$result=restrictedArea($user,'adherent',$rowid,'adherent_type');
|
||||
|
||||
$object = new AdherentType($db);
|
||||
|
||||
$extrafields = new ExtraFields($db);
|
||||
|
||||
// fetch optionals attributes and labels
|
||||
@@ -87,23 +90,47 @@ $hookmanager->initHooks(array('membertypecard','globalcard'));
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($cancel) {
|
||||
|
||||
$action='';
|
||||
|
||||
if (! empty($backtopage))
|
||||
{
|
||||
header("Location: ".$backtopage);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'add' && $user->rights->adherent->configurer)
|
||||
{
|
||||
if (! $cancel)
|
||||
{
|
||||
$object = new AdherentType($db);
|
||||
|
||||
$object->label = trim($label);
|
||||
$object->subscription = (int) trim($subscription);
|
||||
$object->note = trim($comment);
|
||||
$object->mail_valid = (boolean) trim($mail_valid);
|
||||
$object->mail_valid = trim($mail_valid);
|
||||
$object->vote = (boolean) trim($vote);
|
||||
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||
if ($ret < 0) $error++;
|
||||
|
||||
if ($object->label)
|
||||
if (empty($object->label)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")), null, 'errors');
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."adherent_type WHERE libelle='".$db->escape($object->label)."'";
|
||||
$result = $db->query($sql);
|
||||
if ($result) {
|
||||
$num = $db->num_rows($result);
|
||||
}
|
||||
if ($num) {
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorLabelAlreadyExists",$login), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$id=$object->create($user);
|
||||
if ($id > 0)
|
||||
@@ -113,48 +140,64 @@ if ($action == 'add' && $user->rights->adherent->configurer)
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$object->error;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
|
||||
$action = 'create';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'update' && $user->rights->adherent->configurer)
|
||||
{
|
||||
if (! $cancel)
|
||||
{
|
||||
$object = new AdherentType($db);
|
||||
$object->id = $rowid;
|
||||
$object->fetch($rowid);
|
||||
|
||||
$object->oldcopy = clone $object;
|
||||
|
||||
$object->label = trim($label);
|
||||
$object->subscription = (int) trim($subscription);
|
||||
$object->note = trim($comment);
|
||||
$object->mail_valid = (boolean) trim($mail_valid);
|
||||
$object->mail_valid = trim($mail_valid);
|
||||
$object->vote = (boolean) trim($vote);
|
||||
|
||||
// Fill array 'array_options' with data from add form
|
||||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
|
||||
if ($ret < 0) $error++;
|
||||
|
||||
$object->update($user);
|
||||
$ret=$object->update($user);
|
||||
|
||||
header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$_POST["rowid"]);
|
||||
if ($ret >= 0 && ! count($object->errors))
|
||||
{
|
||||
setEventMessages($langs->trans("MemberTypeModified"), null, 'mesgs');
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
|
||||
header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$object->id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'delete' && $user->rights->adherent->configurer)
|
||||
if ($action == 'confirm_delete' && $user->rights->adherent->configurer)
|
||||
{
|
||||
$object = new AdherentType($db);
|
||||
$object->delete($rowid);
|
||||
$object->fetch($rowid);
|
||||
$res=$object->delete();
|
||||
|
||||
if ($res > 0)
|
||||
{
|
||||
setEventMessages($langs->trans("MemberTypeDeleted"), null, 'mesgs');
|
||||
header("Location: ".$_SERVER["PHP_SELF"]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($langs->trans("MemberTypeCanNotBeDeleted"), null, 'errors');
|
||||
$action='';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@@ -308,7 +351,15 @@ if ($rowid > 0)
|
||||
{
|
||||
$object = new AdherentType($db);
|
||||
$object->fetch($rowid);
|
||||
$object->fetch_optionals($rowid,$extralabels);
|
||||
$object->fetch_optionals($object->id,$extralabels);
|
||||
|
||||
/*
|
||||
* Confirmation suppression
|
||||
*/
|
||||
if ($action == 'delete')
|
||||
{
|
||||
print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".$object->id,$langs->trans("DeleteAMemberType"),$langs->trans("ConfirmDeleteMemberType",$object->label),"confirm_delete", '',0,1);
|
||||
}
|
||||
|
||||
$head = member_type_prepare_head($object);
|
||||
|
||||
@@ -345,7 +396,6 @@ if ($rowid > 0)
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
|
||||
/*
|
||||
* Buttons
|
||||
*/
|
||||
@@ -359,7 +409,7 @@ if ($rowid > 0)
|
||||
}
|
||||
|
||||
// Add
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=create&typeid='.$object->id.'">'.$langs->trans("AddMember").'</a></div>';
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=create&typeid='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?rowid='.$object->id).'">'.$langs->trans("AddMember").'</a></div>';
|
||||
|
||||
// Delete
|
||||
if ($user->rights->adherent->configurer)
|
||||
@@ -459,7 +509,7 @@ if ($rowid > 0)
|
||||
$titre.=" (".$membertype->label.")";
|
||||
}
|
||||
|
||||
$param="&rowid=".$rowid;
|
||||
$param="&rowid=".$object->id;
|
||||
if (! empty($status)) $param.="&status=".$status;
|
||||
if (! empty($search_lastname)) $param.="&search_lastname=".$search_lastname;
|
||||
if (! empty($search_firstname)) $param.="&search_firstname=".$search_firstname;
|
||||
@@ -473,7 +523,7 @@ if ($rowid > 0)
|
||||
}
|
||||
|
||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input class="flat" type="hidden" name="rowid" value="'.$rowid.'" size="12"></td>';
|
||||
print '<input class="flat" type="hidden" name="rowid" value="'.$object->id.'" size="12"></td>';
|
||||
|
||||
print '<br>';
|
||||
print_barre_liste('',$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords);
|
||||
@@ -593,12 +643,12 @@ if ($rowid > 0)
|
||||
print '<td align="center">';
|
||||
if ($user->rights->adherent->creer)
|
||||
{
|
||||
print '<a href="card.php?rowid='.$objp->rowid.'&action=edit&return=list.php">'.img_edit().'</a>';
|
||||
print '<a href="card.php?rowid='.$objp->rowid.'&action=edit&backtopage='.urlencode($_SERVER["PHP_SELF"].'?rowid='.$object->id).'">'.img_edit().'</a>';
|
||||
}
|
||||
print ' ';
|
||||
if ($user->rights->adherent->supprimer)
|
||||
{
|
||||
print '<a href="card.php?rowid='.$objp->rowid.'&action=resign&return=list.php">'.img_picto($langs->trans("Resiliate"),'disable.png').'</a>';
|
||||
print '<a href="card.php?rowid='.$objp->rowid.'&action=resign">'.img_picto($langs->trans("Resiliate"),'disable.png').'</a>';
|
||||
}
|
||||
print "</td>";
|
||||
|
||||
@@ -631,15 +681,14 @@ if ($rowid > 0)
|
||||
if ($action == 'edit')
|
||||
{
|
||||
$object = new AdherentType($db);
|
||||
$object->id = $rowid;
|
||||
$object->fetch($rowid);
|
||||
$object->fetch_optionals($rowid,$extralabels);
|
||||
$object->fetch_optionals($object->id,$extralabels);
|
||||
|
||||
$head = member_type_prepare_head($object);
|
||||
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'">';
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="rowid" value="'.$rowid.'">';
|
||||
print '<input type="hidden" name="rowid" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
|
||||
dol_fiche_head($head, 'card', $langs->trans("MemberType"), 0, 'group');
|
||||
@@ -706,7 +755,7 @@ if ($rowid > 0)
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
|
||||
print ' ';
|
||||
print '<input type="submit" name="button" class="button" value="'.$langs->trans("Cancel").'">';
|
||||
print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
|
||||
print '</div>';
|
||||
|
||||
print "</form>";
|
||||
|
||||
191
htdocs/adherents/type_ldap.php
Normal file
191
htdocs/adherents/type_ldap.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/adherents/type_ldap.php
|
||||
* \ingroup ldap
|
||||
* \brief Page fiche LDAP members types
|
||||
*/
|
||||
|
||||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
|
||||
|
||||
$langs->load("members");
|
||||
$langs->load("admin");
|
||||
$langs->load("ldap");
|
||||
|
||||
$id = GETPOST('rowid', 'int');
|
||||
$action = GETPOST('action','alpha');
|
||||
|
||||
// Security check
|
||||
$result=restrictedArea($user,'adherent',$id,'adherent_type');
|
||||
|
||||
$object = new AdherentType($db);
|
||||
$object->fetch($id);
|
||||
|
||||
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
|
||||
$hookmanager->initHooks(array('membertypeldapcard','globalcard'));
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
|
||||
$parameters=array();
|
||||
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||
|
||||
if (empty($reshook))
|
||||
{
|
||||
if ($action == 'dolibarr2ldap')
|
||||
{
|
||||
$ldap = new Ldap();
|
||||
$result = $ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$object->listMembersForMemberType();
|
||||
|
||||
$info = $object->_load_ldap_info();
|
||||
$dn = $object->_load_ldap_dn($info);
|
||||
$olddn = $dn; // We can say that old dn = dn as we force synchro
|
||||
|
||||
$result = $ldap->update($dn, $info, $user, $olddn);
|
||||
}
|
||||
|
||||
if ($result >= 0) {
|
||||
setEventMessages($langs->trans("MemberTypeSynchronized"), null, 'mesgs');
|
||||
}
|
||||
else {
|
||||
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader();
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
$head = member_type_prepare_head($object);
|
||||
|
||||
dol_fiche_head($head, 'ldap', $langs->trans("MemberType"), -1, 'group');
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
dol_banner_tab($object, 'rowid', $linkback);
|
||||
|
||||
print '<div class="fichecenter">';
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// LDAP DN
|
||||
print '<tr><td>LDAP '.$langs->trans("LDAPMemberTypeDn").'</td><td class="valeur">'.$conf->global->LDAP_MEMBER_TYPE_DN."</td></tr>\n";
|
||||
|
||||
// LDAP Cle
|
||||
print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_MEMBERS_TYPES."</td></tr>\n";
|
||||
|
||||
// LDAP Server
|
||||
print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
|
||||
print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
|
||||
print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
|
||||
print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
|
||||
print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
/*
|
||||
* Barre d'actions
|
||||
*/
|
||||
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
if ($conf->global->LDAP_MEMBER_TYPE_ACTIVE == 1)
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
|
||||
}
|
||||
|
||||
print "</div>\n";
|
||||
|
||||
if ($conf->global->LDAP_MEMBER_TYPE_ACTIVE == 1) print "<br>\n";
|
||||
|
||||
|
||||
|
||||
// Affichage attributs LDAP
|
||||
print load_fiche_titre($langs->trans("LDAPInformationsForThisMemberType"));
|
||||
|
||||
print '<table width="100%" class="noborder">';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("LDAPAttributes").'</td>';
|
||||
print '<td>'.$langs->trans("Value").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Lecture LDAP
|
||||
$ldap=new Ldap();
|
||||
$result=$ldap->connect_bind();
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info,1);
|
||||
$search = "(".$object->_load_ldap_dn($info,2).")";
|
||||
$records = $ldap->getAttribute($dn,$search);
|
||||
|
||||
//print_r($records);
|
||||
|
||||
// Affichage arbre
|
||||
if ((! is_numeric($records) || $records != 0) && (! isset($records['count']) || $records['count'] > 0))
|
||||
{
|
||||
if (! is_array($records))
|
||||
{
|
||||
print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$result=show_ldap_content($records,0,$records['count'],true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
|
||||
}
|
||||
|
||||
$ldap->unbind();
|
||||
$ldap->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
@@ -68,6 +68,7 @@ if (empty($reshook))
|
||||
if (! dolibarr_set_const($db, 'LDAP_SYNCHRO_ACTIVE',GETPOST("activesynchro"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_CONTACT_ACTIVE',GETPOST("activecontact"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_MEMBER_ACTIVE',GETPOST("activemembers"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_ACTIVE',GETPOST("activememberstypes"),'chaine',0,'',$conf->entity)) $error++;
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
@@ -135,7 +136,6 @@ print '</td></tr>';
|
||||
// Synchro contact active
|
||||
if (! empty($conf->societe->enabled))
|
||||
{
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("LDAPDnContactActive").'</td><td>';
|
||||
$arraylist=array();
|
||||
$arraylist['0']=$langs->trans("No");
|
||||
@@ -147,7 +147,6 @@ if (! empty($conf->societe->enabled))
|
||||
// Synchro member active
|
||||
if (! empty($conf->adherent->enabled))
|
||||
{
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("LDAPDnMemberActive").'</td><td>';
|
||||
$arraylist=array();
|
||||
$arraylist['0']=$langs->trans("No");
|
||||
@@ -157,6 +156,18 @@ if (! empty($conf->adherent->enabled))
|
||||
print '</td><td>'.$langs->trans("LDAPDnMemberActiveExample").'</td></tr>';
|
||||
}
|
||||
|
||||
// Synchro member type active
|
||||
if (! empty($conf->adherent->enabled))
|
||||
{
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("LDAPDnMemberTypeActive").'</td><td>';
|
||||
$arraylist=array();
|
||||
$arraylist['0']=$langs->trans("No");
|
||||
$arraylist['1']=$langs->trans("DolibarrToLDAP");
|
||||
$arraylist['ldap2dolibarr']=$langs->trans("LDAPToDolibarr").' ('.$langs->trans("SupportedForLDAPImportScriptOnly").')';
|
||||
print $form->selectarray('activememberstypes',$arraylist,$conf->global->LDAP_MEMBER_TYPE_ACTIVE);
|
||||
print '</td><td>'.$langs->trans("LDAPDnMemberTypeActiveExample").'</td></tr>';
|
||||
}
|
||||
|
||||
// Fields from hook
|
||||
$parameters=array();
|
||||
$reshook=$hookmanager->executeHooks('addAdminLdapOptions',$parameters); // Note that $action and $object may have been modified by hook
|
||||
|
||||
@@ -220,8 +220,9 @@ if (function_exists("ldap_connect"))
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
// Get a gid number for objectclass PosixGroup
|
||||
if(in_array('posixGroup',$info['objectclass']))
|
||||
$info['gidNumber'] = $ldap->getNextGroupGid();
|
||||
if (in_array('posixGroup',$info['objectclass'])) {
|
||||
$info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
|
||||
}
|
||||
|
||||
$result1=$ldap->delete($dn); // To be sure to delete existing records
|
||||
$result2=$ldap->add($dn,$info,$user); // Now the test
|
||||
|
||||
252
htdocs/admin/ldap_members_types.php
Normal file
252
htdocs/admin/ldap_members_types.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
||||
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
||||
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/admin/ldap_members_types.php
|
||||
* \ingroup ldap
|
||||
* \brief Page to setup LDAP synchronization for members types
|
||||
*/
|
||||
|
||||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
|
||||
|
||||
$langs->load("admin");
|
||||
$langs->load("errors");
|
||||
|
||||
if (!$user->admin)
|
||||
accessforbidden();
|
||||
|
||||
$action = GETPOST('action','aZ09');
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($action == 'setvalue' && $user->admin)
|
||||
{
|
||||
$error=0;
|
||||
$db->begin();
|
||||
|
||||
if (! dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_DN',GETPOST("membertype"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_OBJECT_CLASS',GETPOST("objectclass"),'chaine',0,'',$conf->entity)) $error++;
|
||||
|
||||
if (! dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_FULLNAME',GETPOST("fieldfullname"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_DESCRIPTION',GETPOST("fielddescription"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS',GETPOST("fieldmembertypemembers"),'chaine',0,'',$conf->entity)) $error++;
|
||||
|
||||
// This one must be after the others
|
||||
$valkey='';
|
||||
$key=GETPOST("key");
|
||||
if ($key) $valkey=$conf->global->$key;
|
||||
if (! dolibarr_set_const($db, 'LDAP_KEY_MEMBERS_TYPES',$valkey,'chaine',0,'',$conf->entity)) $error++;
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader('',$langs->trans("LDAPSetup"),'EN:Module_LDAP_En|FR:Module_LDAP|ES:Módulo_LDAP');
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
|
||||
print load_fiche_titre($langs->trans("LDAPSetup"),$linkback,'title_setup');
|
||||
|
||||
$head = ldap_prepare_head();
|
||||
|
||||
// Test si fonction LDAP actives
|
||||
if (! function_exists("ldap_connect"))
|
||||
{
|
||||
setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
|
||||
}
|
||||
|
||||
dol_fiche_head($head, 'memberstypes', $langs->trans("LDAPSetup"), -1);
|
||||
|
||||
|
||||
print $langs->trans("LDAPDescMembersTypes").'<br>';
|
||||
print '<br>';
|
||||
|
||||
|
||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
$var=true;
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td colspan="4">'.$langs->trans("LDAPSynchronizeMembersTypes").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
// DN pour les types de membres
|
||||
|
||||
print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPMemberTypeDn").'</span></td><td>';
|
||||
print '<input size="48" type="text" name="membertype" value="'.$conf->global->LDAP_MEMBER_TYPE_DN.'">';
|
||||
print '</td><td>'.$langs->trans("LDAPMemberTypepDnExample").'</td>';
|
||||
print '<td> </td>';
|
||||
print '</tr>';
|
||||
|
||||
// List of object class used to define attributes in structure
|
||||
|
||||
print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPMemberTypeObjectClassList").'</span></td><td>';
|
||||
print '<input size="48" type="text" name="objectclass" value="'.$conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS.'">';
|
||||
print '</td><td>'.$langs->trans("LDAPMemberTypeObjectClassListExample").'</td>';
|
||||
print '<td> </td>';
|
||||
print '</tr>';
|
||||
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
$var=true;
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="25%">'.$langs->trans("LDAPDolibarrMapping").'</td>';
|
||||
print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
|
||||
print '<td align="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
// Filtre
|
||||
|
||||
// Common name
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
|
||||
print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME.'">';
|
||||
print '</td><td>'.$langs->trans("LDAPFieldCommonNameExample").'</td>';
|
||||
print '<td align="right"><input type="radio" name="key" value="LDAP_MEMBER_TYPE_FIELD_FULLNAME"'.(($conf->global->LDAP_KEY_MEMBERS_TYPES && $conf->global->LDAP_KEY_MEMBERS_TYPES==$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)?' checked':'')."></td>";
|
||||
print '</tr>';
|
||||
|
||||
// Description
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldDescription").'</td><td>';
|
||||
print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION.'">';
|
||||
print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
|
||||
print '<td align="right"><input type="radio" name="key" value="LDAP_MEMBER_TYPE_FIELD_DESCRIPTION"'.(($conf->global->LDAP_KEY_MEMBERS_TYPES && $conf->global->LDAP_KEY_MEMBER_TYPES==$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)?' checked':'')."></td>";
|
||||
print '</tr>';
|
||||
|
||||
// User group
|
||||
|
||||
print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupMembers").'</td><td>';
|
||||
print '<input size="25" type="text" name="fieldmembertypemembers" value="'.$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS.'">';
|
||||
print '</td><td>'.$langs->trans("LDAPFieldGroupMembersExample").'</td>';
|
||||
print '<td align="right"><input type="radio" name="key" value="LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS"'.(($conf->global->LDAP_KEY_MEMBERS_TYPES && $conf->global->LDAP_KEY_MEMBERS_TYPES==$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)?' checked':'')."></td>";
|
||||
print '</tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print info_admin($langs->trans("LDAPDescValues"));
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
|
||||
|
||||
print '</form>';
|
||||
|
||||
|
||||
/*
|
||||
* Test de la connexion
|
||||
*/
|
||||
if ($conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
|
||||
{
|
||||
$butlabel=$langs->trans("LDAPTestSynchroMemberType");
|
||||
$testlabel='testmembertype';
|
||||
$key=$conf->global->LDAP_KEY_MEMBERS_TYPES;
|
||||
$dn=$conf->global->LDAP_MEMBER_TYPE_DN;
|
||||
$objectclass=$conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS;
|
||||
|
||||
show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
|
||||
}
|
||||
|
||||
if (function_exists("ldap_connect"))
|
||||
{
|
||||
if ($_GET["action"] == 'testmembertype')
|
||||
{
|
||||
// Creation objet
|
||||
$object=new AdherentType($db);
|
||||
$object->initAsSpecimen();
|
||||
|
||||
// Test synchro
|
||||
$ldap=new Ldap();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
// Get a gid number for objectclass PosixGroup
|
||||
if (in_array('posixGroup',$info['objectclass'])) {
|
||||
$info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPES');
|
||||
}
|
||||
|
||||
$result1=$ldap->delete($dn); // To be sure to delete existing records
|
||||
$result2=$ldap->add($dn,$info,$user); // Now the test
|
||||
$result3=$ldap->delete($dn); // Clean what we did
|
||||
|
||||
if ($result2 > 0)
|
||||
{
|
||||
print img_picto('','info').' ';
|
||||
print '<font class="ok">'.$langs->trans("LDAPSynchroOK").'</font><br>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print img_picto('','error').' ';
|
||||
print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
|
||||
print ': '.$ldap->error;
|
||||
print '</font><br>';
|
||||
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
|
||||
}
|
||||
|
||||
print "<br>\n";
|
||||
print "LDAP input file used for test:<br><br>\n";
|
||||
print nl2br($ldap->dump_content($dn,$info));
|
||||
print "\n<br>";
|
||||
}
|
||||
else
|
||||
{
|
||||
print img_picto('','error').' ';
|
||||
print '<font class="error">'.$langs->trans("LDAPSynchroKO");
|
||||
print ': '.$ldap->error;
|
||||
print '</font><br>';
|
||||
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2006-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* 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
|
||||
@@ -196,15 +196,11 @@ if ($result > 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error('',$ldap->error);
|
||||
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
||||
}
|
||||
|
||||
|
||||
print '</table>';
|
||||
|
||||
|
||||
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
|
||||
@@ -254,6 +254,7 @@ class Conf
|
||||
if (! isset($this->global->LDAP_KEY_GROUPS)) $this->global->LDAP_KEY_GROUPS=$this->global->LDAP_FIELD_FULLNAME;
|
||||
if (! isset($this->global->LDAP_KEY_CONTACTS)) $this->global->LDAP_KEY_CONTACTS=$this->global->LDAP_FIELD_FULLNAME;
|
||||
if (! isset($this->global->LDAP_KEY_MEMBERS)) $this->global->LDAP_KEY_MEMBERS=$this->global->LDAP_FIELD_FULLNAME;
|
||||
if (! isset($this->global->LDAP_KEY_MEMBERS_TYPES)) $this->global->LDAP_KEY_MEMBERS_TYPES=$this->global->LDAP_FIELD_FULLNAME;
|
||||
|
||||
// Load translation object with current language
|
||||
if (empty($this->global->MAIN_LANG_DEFAULT)) $this->global->MAIN_LANG_DEFAULT="en_US";
|
||||
@@ -286,6 +287,8 @@ class Conf
|
||||
if (! empty($this->modules_parts['dir']))
|
||||
{
|
||||
foreach($this->modules_parts['dir'] as $module => $dirs)
|
||||
{
|
||||
if (! empty($this->$module->enabled))
|
||||
{
|
||||
foreach($dirs as $type => $name)
|
||||
{
|
||||
@@ -299,6 +302,7 @@ class Conf
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For mycompany storage
|
||||
$this->mycompany->dir_output=$rootfordata."/mycompany";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
||||
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -179,12 +179,18 @@ class Ldap
|
||||
|
||||
if (preg_match('/^ldap/',$host))
|
||||
{
|
||||
if ($this->serverPing($host) === true) {
|
||||
$this->connection = ldap_connect($host);
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->serverPing($host, $this->serverPort) === true) {
|
||||
$this->connection = ldap_connect($host,$this->serverPort);
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
|
||||
if (is_resource($this->connection))
|
||||
{
|
||||
@@ -662,6 +668,24 @@ class Ldap
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ping a server before ldap_connect for avoid waiting
|
||||
*
|
||||
* @param string $host Server host or address
|
||||
* @param int $port Server port (default 389)
|
||||
* @param int $timeout Timeout in second (default 1s)
|
||||
* @return boolean true or false
|
||||
*/
|
||||
function serverPing($host, $port=389, $timeout=1)
|
||||
{
|
||||
$op = @fsockopen($host, $port, $errno, $errstr, $timeout);
|
||||
if (!$op) return false; //DC is N/A
|
||||
else {
|
||||
fclose($op); //explicitly close open socket connection
|
||||
return true; //DC is up & running, we can safely connect with ldap_connect
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Attribute methods -----------------------------------------------------
|
||||
|
||||
@@ -1387,13 +1411,16 @@ class Ldap
|
||||
/**
|
||||
* Return available value of group GID
|
||||
*
|
||||
* @param string $keygroup Key of group
|
||||
* @return int gid number
|
||||
*/
|
||||
function getNextGroupGid()
|
||||
function getNextGroupGid($keygroup='LDAP_KEY_GROUPS')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$search='('.$conf->global->LDAP_KEY_GROUPS.'=*)';
|
||||
if (empty($keygroup)) $keygroup='LDAP_KEY_GROUPS';
|
||||
|
||||
$search='('.$conf->global->$keygroup.'=*)';
|
||||
$result = $this->search($this->groups,$search);
|
||||
if($result)
|
||||
{
|
||||
@@ -1411,5 +1438,3 @@ class Ldap
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -75,6 +75,14 @@ function ldap_prepare_head()
|
||||
$h++;
|
||||
}
|
||||
|
||||
if (! empty($conf->adherent->enabled) && ! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE))
|
||||
{
|
||||
$head[$h][0] = DOL_URL_ROOT."/admin/ldap_members_types.php";
|
||||
$head[$h][1] = $langs->trans("LDAPMembersTypesSynchro");
|
||||
$head[$h][2] = 'memberstypes';
|
||||
$h++;
|
||||
}
|
||||
|
||||
// Show more tabs from modules
|
||||
// Entries must be declared in modules descriptor with line
|
||||
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
|
||||
|
||||
@@ -124,6 +124,16 @@ function member_type_prepare_head(AdherentType $object)
|
||||
$head[$h][2] = 'card';
|
||||
$h++;
|
||||
|
||||
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE))
|
||||
{
|
||||
$langs->load("ldap");
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/adherents/type_ldap.php?rowid='.$object->id;
|
||||
$head[$h][1] = $langs->trans("LDAPCard");
|
||||
$head[$h][2] = 'ldap';
|
||||
$h++;
|
||||
}
|
||||
|
||||
// Show more tabs from modules
|
||||
// Entries must be declared in modules descriptor with line
|
||||
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -58,6 +59,8 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
return 0;
|
||||
}
|
||||
|
||||
$result=0;
|
||||
|
||||
// Users
|
||||
if ($action == 'USER_CREATE')
|
||||
{
|
||||
@@ -65,17 +68,17 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn,$info,$user);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'USER_MODIFY')
|
||||
@@ -84,8 +87,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if (empty($object->oldcopy) || ! is_object($object->oldcopy))
|
||||
{
|
||||
dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
|
||||
@@ -108,11 +113,9 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'USER_NEW_PASSWORD')
|
||||
@@ -121,8 +124,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if (empty($object->oldcopy) || ! is_object($object->oldcopy))
|
||||
{
|
||||
dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
|
||||
@@ -145,11 +150,9 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'USER_ENABLEDISABLE')
|
||||
@@ -162,17 +165,17 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->delete($dn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'USER_SETINGROUP')
|
||||
@@ -181,8 +184,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
// Must edit $object->newgroupid
|
||||
$usergroup=new UserGroup($this->db);
|
||||
if ($object->newgroupid > 0)
|
||||
@@ -205,12 +210,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
$dn=$usergroup->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'USER_REMOVEFROMGROUP')
|
||||
@@ -219,8 +222,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
// Must edit $object->newgroupid
|
||||
$usergroup=new UserGroup($this->db);
|
||||
if ($object->oldgroupid > 0)
|
||||
@@ -243,12 +248,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
$dn=$usergroup->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,21 +262,22 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
// Get a gid number for objectclass PosixGroup
|
||||
if(in_array('posixGroup',$info['objectclass']))
|
||||
$info['gidNumber'] = $ldap->getNextGroupGid();
|
||||
if (in_array('posixGroup',$info['objectclass'])) {
|
||||
$info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
|
||||
}
|
||||
|
||||
$result=$ldap->add($dn,$info,$user);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'GROUP_MODIFY')
|
||||
@@ -282,8 +286,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if (empty($object->oldcopy) || ! is_object($object->oldcopy))
|
||||
{
|
||||
dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
|
||||
@@ -306,11 +312,9 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'GROUP_DELETE')
|
||||
@@ -319,17 +323,17 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->delete($dn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,17 +344,17 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn,$info,$user);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'CONTACT_MODIFY')
|
||||
@@ -359,8 +363,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if (empty($object->oldcopy) || ! is_object($object->oldcopy))
|
||||
{
|
||||
dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
|
||||
@@ -383,11 +389,9 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'CONTACT_DELETE')
|
||||
@@ -396,17 +400,17 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->delete($dn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,17 +421,45 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn,$info,$user);
|
||||
if ($result < 0)
|
||||
|
||||
// For member type
|
||||
if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
$membertype=new AdherentType($this->db);
|
||||
if ($object->typeid > 0)
|
||||
{
|
||||
$membertype->fetch($object->typeid);
|
||||
$membertype->listMembersForMemberType();
|
||||
|
||||
$oldinfo=$membertype->_load_ldap_info();
|
||||
$olddn=$membertype->_load_ldap_dn($oldinfo);
|
||||
|
||||
// Verify if entry exist
|
||||
$container=$membertype->_load_ldap_dn($oldinfo,1);
|
||||
$search = "(".$membertype->_load_ldap_dn($oldinfo,2).")";
|
||||
$records=$ldap->search($container,$search);
|
||||
if (count($records) && $records['count'] == 0)
|
||||
{
|
||||
$olddn = '';
|
||||
}
|
||||
return $result;
|
||||
|
||||
$info=$membertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call)
|
||||
$dn=$membertype->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'MEMBER_VALIDATE')
|
||||
@@ -439,18 +471,18 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS))
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
$olddn=$dn; // We know olddn=dn as we change only status
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -467,18 +499,18 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
|| $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
$olddn=$dn; // We know olddn=dn as we change only subscriptions
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,8 +520,10 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if (empty($object->oldcopy) || ! is_object($object->oldcopy))
|
||||
{
|
||||
dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
|
||||
@@ -512,11 +546,64 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
|
||||
// For member type
|
||||
if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
/*
|
||||
* Change member info
|
||||
*/
|
||||
$newmembertype=new AdherentType($this->db);
|
||||
$newmembertype->fetch($object->typeid);
|
||||
$newmembertype->listMembersForMemberType();
|
||||
|
||||
$oldinfo=$newmembertype->_load_ldap_info();
|
||||
$olddn=$newmembertype->_load_ldap_dn($oldinfo);
|
||||
|
||||
// Verify if entry exist
|
||||
$container=$newmembertype->_load_ldap_dn($oldinfo,1);
|
||||
$search = "(".$newmembertype->_load_ldap_dn($oldinfo,2).")";
|
||||
$records=$ldap->search($container,$search);
|
||||
if (count($records) && $records['count'] == 0)
|
||||
{
|
||||
$olddn = '';
|
||||
}
|
||||
return $result;
|
||||
|
||||
$info=$newmembertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call)
|
||||
$dn=$newmembertype->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
|
||||
if ($object->oldcopy->typeid != $object->typeid)
|
||||
{
|
||||
/*
|
||||
* Remove member in old member type
|
||||
*/
|
||||
$oldmembertype=new AdherentType($this->db);
|
||||
$oldmembertype->fetch($object->oldcopy->typeid);
|
||||
$oldmembertype->listMembersForMemberType();
|
||||
|
||||
$oldinfo=$oldmembertype->_load_ldap_info();
|
||||
$olddn=$oldmembertype->_load_ldap_dn($oldinfo);
|
||||
|
||||
// Verify if entry exist
|
||||
$container=$oldmembertype->_load_ldap_dn($oldinfo,1);
|
||||
$search = "(".$oldmembertype->_load_ldap_dn($oldinfo,2).")";
|
||||
$records=$ldap->search($container,$search);
|
||||
if (count($records) && $records['count'] == 0)
|
||||
{
|
||||
$olddn = '';
|
||||
}
|
||||
|
||||
$info=$oldmembertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call)
|
||||
$dn=$oldmembertype->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'MEMBER_NEW_PASSWORD')
|
||||
@@ -528,18 +615,18 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED)
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
$olddn=$dn; // We know olddn=dn as we change only password
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -552,18 +639,18 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS))
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
$olddn=$dn; // We know olddn=dn as we change only status
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
return $result;
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -573,29 +660,138 @@ class InterfaceLdapsynchro extends DolibarrTriggers
|
||||
if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->delete($dn);
|
||||
if ($result < 0)
|
||||
|
||||
// For member type
|
||||
if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
if ($object->typeid > 0)
|
||||
{
|
||||
/*
|
||||
* Remove member in member type
|
||||
*/
|
||||
$membertype=new AdherentType($this->db);
|
||||
$membertype->fetch($object->typeid);
|
||||
$membertype->listMembersForMemberType('a.rowid != ' . $object->id); // remove deleted member from the list
|
||||
|
||||
$oldinfo=$membertype->_load_ldap_info();
|
||||
$olddn=$membertype->_load_ldap_dn($oldinfo);
|
||||
|
||||
// Verify if entry exist
|
||||
$container=$membertype->_load_ldap_dn($oldinfo,1);
|
||||
$search = "(".$membertype->_load_ldap_dn($oldinfo,2).")";
|
||||
$records=$ldap->search($container,$search);
|
||||
if (count($records) && $records['count'] == 0)
|
||||
{
|
||||
$olddn = '';
|
||||
}
|
||||
|
||||
$info=$membertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call)
|
||||
$dn=$membertype->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
|
||||
// Members types
|
||||
elseif ($action == 'MEMBER_TYPE_CREATE')
|
||||
{
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||
if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
// Get a gid number for objectclass PosixGroup
|
||||
if (in_array('posixGroup',$info['objectclass'])) {
|
||||
$info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPE');
|
||||
}
|
||||
|
||||
$result=$ldap->add($dn,$info,$user);
|
||||
}
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'MEMBER_TYPE_MODIFY')
|
||||
{
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||
if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if (empty($object->oldcopy) || ! is_object($object->oldcopy))
|
||||
{
|
||||
dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
|
||||
$object->oldcopy = clone $object;
|
||||
}
|
||||
|
||||
$object->oldcopy->listMembersForMemberType();
|
||||
|
||||
$oldinfo=$object->oldcopy->_load_ldap_info();
|
||||
$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
|
||||
|
||||
// Verify if entry exist
|
||||
$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
|
||||
$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
|
||||
$records=$ldap->search($container,$search);
|
||||
if (count($records) && $records['count'] == 0)
|
||||
{
|
||||
$olddn = '';
|
||||
}
|
||||
|
||||
$object->listMembersForMemberType();
|
||||
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
}
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'MEMBER_TYPE_DELETE')
|
||||
{
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||
if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->delete($dn);
|
||||
}
|
||||
|
||||
if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// If not found
|
||||
/*
|
||||
else
|
||||
{
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1253,6 +1253,7 @@ LDAPUsersSynchro=Users
|
||||
LDAPGroupsSynchro=Groups
|
||||
LDAPContactsSynchro=Contacts
|
||||
LDAPMembersSynchro=Members
|
||||
LDAPMembersTypesSynchro=Members types
|
||||
LDAPSynchronization=LDAP synchronisation
|
||||
LDAPFunctionsNotAvailableOnPHP=LDAP functions are not available on your PHP
|
||||
LDAPToDolibarr=LDAP -> Dolibarr
|
||||
@@ -1262,6 +1263,7 @@ LDAPSynchronizeUsers=Organization of users in LDAP
|
||||
LDAPSynchronizeGroups=Organization of groups in LDAP
|
||||
LDAPSynchronizeContacts=Organization of contacts in LDAP
|
||||
LDAPSynchronizeMembers=Organization of foundation's members in LDAP
|
||||
LDAPSynchronizeMembersTypes=Organization of foundation's members types in LDAP
|
||||
LDAPPrimaryServer=Primary server
|
||||
LDAPSecondaryServer=Secondary server
|
||||
LDAPServerPort=Server port
|
||||
@@ -1285,12 +1287,18 @@ LDAPDnContactActive=Contacts' synchronization
|
||||
LDAPDnContactActiveExample=Activated/Unactivated synchronization
|
||||
LDAPDnMemberActive=Members' synchronization
|
||||
LDAPDnMemberActiveExample=Activated/Unactivated synchronization
|
||||
LDAPDnMemberTypeActive=Members types' synchronization
|
||||
LDAPDnMemberTypeActiveExample=Activated/Unactivated synchronization
|
||||
LDAPContactDn=Dolibarr contacts' DN
|
||||
LDAPContactDnExample=Complete DN (ex: ou=contacts,dc=example,dc=com)
|
||||
LDAPMemberDn=Dolibarr members DN
|
||||
LDAPMemberDnExample=Complete DN (ex: ou=members,dc=example,dc=com)
|
||||
LDAPMemberObjectClassList=List of objectClass
|
||||
LDAPMemberObjectClassListExample=List of objectClass defining record attributes (ex: top,inetOrgPerson or top,user for active directory)
|
||||
LDAPMemberTypeDn=Dolibarr members types DN
|
||||
LDAPMemberTypepDnExample=Complete DN (ex: ou=memberstypes,dc=example,dc=com)
|
||||
LDAPMemberTypeObjectClassList=List of objectClass
|
||||
LDAPMemberTypeObjectClassListExample=List of objectClass defining record attributes (ex: top,groupOfUniqueNames)
|
||||
LDAPUserObjectClassList=List of objectClass
|
||||
LDAPUserObjectClassListExample=List of objectClass defining record attributes (ex: top,inetOrgPerson or top,user for active directory)
|
||||
LDAPGroupObjectClassList=List of objectClass
|
||||
@@ -1302,6 +1310,7 @@ LDAPTestSynchroContact=Test contacts synchronization
|
||||
LDAPTestSynchroUser=Test user synchronization
|
||||
LDAPTestSynchroGroup=Test group synchronization
|
||||
LDAPTestSynchroMember=Test member synchronization
|
||||
LDAPTestSynchroMemberType=Test member type synchronization
|
||||
LDAPTestSearch= Test a LDAP search
|
||||
LDAPSynchroOK=Synchronization test successful
|
||||
LDAPSynchroKO=Failed synchronization test
|
||||
@@ -1367,6 +1376,7 @@ LDAPDescContact=This page allows you to define LDAP attributes name in LDAP tree
|
||||
LDAPDescUsers=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr users.
|
||||
LDAPDescGroups=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr groups.
|
||||
LDAPDescMembers=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr members module.
|
||||
LDAPDescMembersTypes=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr members types.
|
||||
LDAPDescValues=Example values are designed for <b>OpenLDAP</b> with following loaded schemas: <b>core.schema, cosine.schema, inetorgperson.schema</b>). If you use thoose values and OpenLDAP, modify your LDAP config file <b>slapd.conf</b> to have all thoose schemas loaded.
|
||||
ForANonAnonymousAccess=For an authenticated access (for a write access for example)
|
||||
PerfDolibarr=Performance setup/optimizing report
|
||||
|
||||
@@ -104,6 +104,7 @@ ErrorForbidden2=Permission for this login can be defined by your Dolibarr admini
|
||||
ErrorForbidden3=It seems that Dolibarr is not used through an authenticated session. Take a look at Dolibarr setup documentation to know how to manage authentications (htaccess, mod_auth or other...).
|
||||
ErrorNoImagickReadimage=Class Imagick is not found in this PHP. No preview can be available. Administrators can disable this tab from menu Setup - Display.
|
||||
ErrorRecordAlreadyExists=Record already exists
|
||||
ErrorLabelAlreadyExists=This label already exists
|
||||
ErrorCantReadFile=Failed to read file '%s'
|
||||
ErrorCantReadDir=Failed to read directory '%s'
|
||||
ErrorBadLoginPassword=Bad value for login or password
|
||||
|
||||
@@ -6,6 +6,7 @@ LDAPInformationsForThisContact=Information in LDAP database for this contact
|
||||
LDAPInformationsForThisUser=Information in LDAP database for this user
|
||||
LDAPInformationsForThisGroup=Information in LDAP database for this group
|
||||
LDAPInformationsForThisMember=Information in LDAP database for this member
|
||||
LDAPInformationsForThisMemberType=Information in LDAP database for this member type
|
||||
LDAPAttributes=LDAP attributes
|
||||
LDAPCard=LDAP card
|
||||
LDAPRecordNotFound=Record not found in LDAP database
|
||||
@@ -20,6 +21,7 @@ LDAPFieldSkypeExample=Example : skypeName
|
||||
UserSynchronized=User synchronized
|
||||
GroupSynchronized=Group synchronized
|
||||
MemberSynchronized=Member synchronized
|
||||
MemberTypeSynchronized=Member type synchronized
|
||||
ContactSynchronized=Contact synchronized
|
||||
ForceSynchronize=Force synchronizing Dolibarr -> LDAP
|
||||
ErrorFailedToReadLDAP=Failed to read LDAP database. Check LDAP module setup and database accessibility.
|
||||
|
||||
@@ -57,6 +57,11 @@ NewCotisation=New contribution
|
||||
PaymentSubscription=New contribution payment
|
||||
SubscriptionEndDate=Subscription's end date
|
||||
MembersTypeSetup=Members type setup
|
||||
MemberTypeModified=Member type modified
|
||||
DeleteAMemberType=Delete a member type
|
||||
ConfirmDeleteMemberType=Are you sure you want to delete this member type?
|
||||
MemberTypeDeleted=Member type deleted
|
||||
MemberTypeCanNotBeDeleted=Member type can not be deleted
|
||||
NewSubscription=New subscription
|
||||
NewSubscriptionDesc=This form allows you to record your subscription as a new member of the foundation. If you want to renew your subscription (if already a member), please contact foundation board instead by email %s.
|
||||
Subscription=Subscription
|
||||
|
||||
@@ -63,30 +63,31 @@ $object->getrights();
|
||||
|
||||
if ($action == 'dolibarr2ldap')
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
$ldap=new Ldap();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$info=$object->_load_ldap_info();
|
||||
|
||||
// Get a gid number for objectclass PosixGroup
|
||||
if(in_array('posixGroup',$info['objectclass']))
|
||||
$info['gidNumber'] = $ldap->getNextGroupGid();
|
||||
if (in_array('posixGroup',$info['objectclass'])) {
|
||||
$info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
|
||||
}
|
||||
|
||||
$dn=$object->_load_ldap_dn($info);
|
||||
$olddn=$dn; // We can say that old dn = dn as we force synchro
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
}
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
setEventMessages($langs->trans("GroupSynchronized"), null, 'mesgs');
|
||||
$db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
||||
$db->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,12 +207,10 @@ if ($result > 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error('',$ldap->error);
|
||||
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006-2015 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2006-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* 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
|
||||
@@ -214,7 +214,7 @@ if ($result > 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error('',$ldap->error);
|
||||
setEventMessages($ldap->error, $ldap->errors, 'errors');
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
131
scripts/members/sync_members_types_dolibarr2ldap.php
Executable file
131
scripts/members/sync_members_types_dolibarr2ldap.php
Executable file
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/user/sync_members_types_dolibarr2ldap.php
|
||||
* \ingroup ldap core
|
||||
* \brief Script de mise a jour des types de membres dans LDAP depuis base Dolibarr
|
||||
*/
|
||||
|
||||
$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(-1);
|
||||
}
|
||||
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: ".$script_file." now\n";
|
||||
exit(-1);
|
||||
}
|
||||
$now=$argv[1];
|
||||
|
||||
require_once($path."../../htdocs/master.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php");
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',',$argv));
|
||||
|
||||
/*
|
||||
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
|
||||
{
|
||||
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
|
||||
exit(-1);
|
||||
}
|
||||
*/
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
|
||||
$ldap=new Ldap();
|
||||
$result=$ldap->connect_bind();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
while ($i < $num)
|
||||
{
|
||||
$ldap->error="";
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$membertype = new AdherentType($db);
|
||||
$membertype->id = $obj->rowid;
|
||||
$membertype->fetch($membertype->id);
|
||||
|
||||
print $langs->trans("UpdateMemberType")." rowid=".$membertype->id." ".$membertype-label;
|
||||
|
||||
$oldobject=$membertype;
|
||||
|
||||
$oldinfo=$membertype->_load_ldap_info();
|
||||
$olddn=$membertype->_load_ldap_dn($oldinfo);
|
||||
|
||||
$info=$membertype->_load_ldap_info();
|
||||
$dn=$membertype->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->add($dn,$info,$user); // Wil fail if already exists
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result > 0)
|
||||
{
|
||||
print " - ".$langs->trans("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print " - ".$langs->trans("KO").' - '.$ldap->error;
|
||||
}
|
||||
print "\n";
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$ldap->unbind();
|
||||
$ldap->close();
|
||||
}
|
||||
else {
|
||||
print $ldap->error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
exit($error);
|
||||
221
scripts/members/sync_members_types_ldap2dolibarr.php
Executable file
221
scripts/members/sync_members_types_ldap2dolibarr.php
Executable file
@@ -0,0 +1,221 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013 Maxime Kohlhaas <maxime@atm-consulting.fr>
|
||||
* Copyright (C) 2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file scripts/user/sync_members_types_ldap2dolibarr.php
|
||||
* \ingroup ldap member
|
||||
* \brief Script to update members types 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(-1);
|
||||
}
|
||||
|
||||
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."/adherents/class/adherent_type.class.php");
|
||||
|
||||
$langs->load("main");
|
||||
$langs->load("errors");
|
||||
|
||||
|
||||
// Global variables
|
||||
$version=DOL_VERSION;
|
||||
$error=0;
|
||||
$forcecommit=0;
|
||||
$confirmed=0;
|
||||
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
@set_time_limit(0);
|
||||
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
|
||||
dol_syslog($script_file." launched with arg ".join(',',$argv));
|
||||
|
||||
// List of fields to get from LDAP
|
||||
$required_fields = array(
|
||||
$conf->global->LDAP_KEY_MEMBERS_TYPES,
|
||||
$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME,
|
||||
$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION,
|
||||
$conf->global->LDAP_MEMBER_TYPE_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 (! isset($argv[1])) {
|
||||
//print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n";
|
||||
print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
foreach($argv as $key => $val)
|
||||
{
|
||||
if ($val == 'commitiferror') $forcecommit=1;
|
||||
if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
|
||||
if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
|
||||
if (preg_match('/-y$/',$val,$reg)) $confirmed=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_MEMBER_TYPE_DN."\n";
|
||||
print 'Filter=('.$conf->global->LDAP_KEY_MEMBERS_TYPES.'=*)'."\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";
|
||||
|
||||
if (! $confirmed)
|
||||
{
|
||||
print "Hit Enter to continue or CTRL+C to stop...\n";
|
||||
$input = trim(fgets(STDIN));
|
||||
}
|
||||
|
||||
if (empty($conf->global->LDAP_MEMBER_TYPE_DN))
|
||||
{
|
||||
print $langs->trans("Error").': '.$langs->trans("LDAP setup for members types 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_MEMBER_TYPE_ACTIVE=0;
|
||||
|
||||
$ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_TYPE_DN, $conf->global->LDAP_KEY_MEMBERS_TYPES, $required_fields, 0, array($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS));
|
||||
if (is_array($ldaprecords))
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
// Warning $ldapuser has a key in lowercase
|
||||
foreach ($ldaprecords as $key => $ldapgroup)
|
||||
{
|
||||
$membertype = new AdherentType($db);
|
||||
$membertype->fetch('', $ldapgroup[$conf->global->LDAP_KEY_MEMBERS_TYPES]);
|
||||
$membertype->label = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME];
|
||||
$membertype->description = $ldapgroup[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION];
|
||||
$membertype->entity = $conf->entity;
|
||||
|
||||
//print_r($ldapgroup);
|
||||
|
||||
if ($membertype->id > 0) { // Member type update
|
||||
print $langs->transnoentities("MemberTypeUpdate").' # '.$key.': name='.$membertype->label;
|
||||
$res=$membertype->update($user);
|
||||
|
||||
if ($res > 0)
|
||||
{
|
||||
print ' --> Updated member type id='.$membertype->id.' name='.$membertype->label;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$res.' '.$membertype->error;
|
||||
}
|
||||
print "\n";
|
||||
} else { // Member type creation
|
||||
print $langs->transnoentities("MemberTypeCreate").' # '.$key.': name='.$membertype->label;
|
||||
$res=$membertype->create($user);
|
||||
|
||||
if ($res > 0)
|
||||
{
|
||||
print ' --> Created member type id='.$membertype->id.' name='.$membertype->label;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
print ' --> '.$res.' '.$membertype->error;
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
//print_r($membertype);
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
|
||||
exit($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) != '');
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ class AdherentTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$localobject=new AdherentType($this->savdb);
|
||||
$localobject->statut=1;
|
||||
$localobject->libelle='Adherent type test';
|
||||
$localobject->cotisation=1;
|
||||
$localobject->label='Adherent type test';
|
||||
$localobject->subscription=1;
|
||||
$localobject->vote=1;
|
||||
$result=$localobject->create($user);
|
||||
print __METHOD__." result=".$result."\n";
|
||||
|
||||
Reference in New Issue
Block a user