/** * @param $authldap AuthLDAP object **/ private static function buildLdapFilter(AuthLdap $authldap) { //Build search filter $counter = 0; $filter = ''; if (!empty($_SESSION['ldap_import']['criterias']) && $_SESSION['ldap_import']['interface'] == self::SIMPLE_INTERFACE) { foreach ($_SESSION['ldap_import']['criterias'] as $criteria => $value) { if ($value != '') { $begin = 0; $end = 0; if (($length = strlen($value)) > 0) { if ($value[0] == '^') { $begin = 1; } if ($value[$length - 1] == '$') { $end = 1; } } if ($begin || $end) { // no Toolbox::substr, to be consistent with strlen result $value = substr($value, $begin, $length - $end - $begin); } $counter++; $filter .= '(' . $authldap->fields[$criteria] . '=' . ($begin ? '' : '*') . $value . ($end ? '' : '*') . ')'; } } } else { $filter = "(" . $authldap->getField("login_field") . "=*)"; } //If time restriction $begin_date = isset($_SESSION['ldap_import']['begin_date']) && !empty($_SESSION['ldap_import']['begin_date']) ? $_SESSION['ldap_import']['begin_date'] : NULL; $end_date = isset($_SESSION['ldap_import']['end_date']) && !empty($_SESSION['ldap_import']['end_date']) ? $_SESSION['ldap_import']['end_date'] : NULL; $filter .= self::addTimestampRestrictions($begin_date, $end_date); $ldap_condition = $authldap->getField('condition'); //Add entity filter and filter filled in directory's configuration form return "(&" . (isset($_SESSION['ldap_import']['entity_filter']) ? $_SESSION['ldap_import']['entity_filter'] : '') . " {$filter} {$ldap_condition})"; }
<?php include '../../../inc/includes.php'; Session::checkRight("config", "w"); $authldap = new AuthLdap(); $authldap->getFromDB($_POST['value']); $filter = "(" . $authldap->getField("login_field") . "=*)"; $ldap_condition = $authldap->getField('condition'); echo "(& {$filter} {$ldap_condition})";