diff --git a/plugins/admin/groups/class_groupGeneric.inc b/plugins/admin/groups/class_groupGeneric.inc
index d009a6f1e49e965a11491ddb5c3b0821c9013e6b..f25a036f113d683530f88d3b50aa3349dc4d83cf 100644 (file)
<?php
<?php
+
class group extends plugin
{
/* CLI vars */
class group extends plugin
{
/* CLI vars */
var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
var $objectclasses= array("top", "posixGroup");
var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
var $objectclasses= array("top", "posixGroup");
- function group ($config, $dn= NULL)
+ function group ($config, $dn= NULL, $parent= NULL)
{
{
- plugin::plugin ($config, $dn);
+ plugin::plugin ($config, $dn, $parent);
/* Load attributes depending on the samba version */
$this->samba3= ($config->current['SAMBAVERSION'] == 3);
/* Load attributes depending on the samba version */
$this->samba3= ($config->current['SAMBAVERSION'] == 3);
$gufilter= get_global('gufilter');
$gufilter['SubSearchGroup'] = false;
$gufilter= get_global('gufilter');
$gufilter['SubSearchGroup'] = false;
- $gufilter['dselect'] = $_SESSION['groupfilter']['depselect'];
+ $gufilter['dselect'] = $_SESSION['gufilter']['dselect'];
register_global('gufilter',$gufilter);
register_global('gufilter',$gufilter);
- /* Bases / Departments */
-
- if(isset($_SESSION['groupfilter']['depselect'])){
- $this->base = $_SESSION['groupfilter']['depselect'];
- }else{
- if ($this->dn == "new"){
+ if ($this->dn == "new"){
+ if(isset($_SESSION['CurrentMainBase'])){
+ $this->base= $_SESSION['CurrentMainBase'];
+ }else{
$ui= get_userinfo();
$this->base= dn2base($ui->dn);
$ui= get_userinfo();
$this->base= dn2base($ui->dn);
- } else {
- $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
}
}
+ } else {
+ $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
}
}
-
/* This is always an account */
$this->is_account= TRUE;
/* This is always an account */
$this->is_account= TRUE;
}
$gufilter['regex']= $s;
}
}
$gufilter['regex']= $s;
}
- $regex= preg_replace('/[*]/', ".*", $gufilter['regex']);
register_global("gufilter", $gufilter);
$this->reload();
register_global("gufilter", $gufilter);
$this->reload();
$smarty->assign("$type", $gufilter[$type]);
}
$smarty->assign("hint", print_sizelimit_warning());
$smarty->assign("$type", $gufilter[$type]);
}
$smarty->assign("hint", print_sizelimit_warning());
-
- $users= array();
- foreach ($this->allusers as $key => $value){
- if (!array_key_exists($key, $this->members)){
- if (preg_match("/^$regex/i", $key)){
- $users[$key]= $value;
- }
- }
- }
- $smarty->assign("users", $users);
+ $smarty->assign("users", $this->displayUsers);
$smarty->assign("apply", apply_filter());
$display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
return ($display);
$smarty->assign("apply", apply_filter());
$display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
return ($display);
/* Reload data */
function reload()
{
/* Reload data */
function reload()
{
- /* Generate userlists */
- $this->last_sorting= "invalid";
- $this->users= array();
+ /* Fix regex string */
+ $gufilter = get_global("gufilter");
+ $regex = normalizeLdap($gufilter['regex']);
+ $MaxUser = $this->OnlyShowFirstEntries;
+
+ /* Prepare ldap link */
$ldap= $this->config->get_ldap_link();
$ldap= $this->config->get_ldap_link();
+ $ldap->cd($gufilter['dselect']);
- $MaxUser = $this->OnlyShowFirstEntries;
- $gufilter= get_global("gufilter");
- $ldap->cd ($this->config->current['BASE']);
+ /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
+ (Store gathered sn/givenName informations in $this->allusers too,
+ to be prepared when adding/deleting users)
+ */
+ $filter = "";
+ foreach ($this->memberUid as $value){
+ if(!isset($this->members[$value])){
+ $filter .= "(uid=".normalizeLdap($value).")";
+ }
+ }
+ if(!empty($filter)){
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
+ while($attrs = $ldap->fetch()){
+ $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
+ $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
+ }
+ }
+
+ /* check if all uids are resolved */
+ foreach ($this->memberUid as $value){
+ if(!isset($this->members[$value])){
+ $this->members[$value] = _("! unknown id")." [".$value."]";
+ }
+ }
+
+ /* Create display list of users matching regex & filter
+ */
+ $this->displayUsers = array();
+
+ /* Set tag attribute if we've tagging activated */
+ $tag= "";
+ $ui= get_userinfo();
+ if ($ui->gosaUnitTag != "" && isset($this->config->current['STRICT_UNITS']) &&
+ preg_match('/TRUE/i', $this->config->current['STRICT_UNITS'])){
+ $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
+ }
+
+ $filter = "(&(objectClass=gosaAccount)$tag(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
+
+ /* Search in current tree or within subtrees depending on the checkbox from filter section */
if($gufilter['SubSearchGroup']){
if($gufilter['SubSearchGroup']){
- $ldap->cd ($gufilter['dselect']);
- $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",array("uid", "sn","givenName"));
+ $ldap->search($filter, array("uid", "sn","givenName"));
}else{
}else{
- $ldap->cd (get_people_ou().$gufilter['dselect']);
- $ldap->ls ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
+ $ldap->ls ($filter, get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
}
}
- $this->allusers= array();
+ $i = 0;
- $i = 0 ;
- while (($attrs= $ldap->fetch()) && ($i < $MaxUser)){
+ /* Fetch all users and skip already used users */
+ while($attrs = $ldap->fetch()){
+ if(in_array($attrs['uid'][0], $this->memberUid)) {
+ continue;
+ }
$i ++;
$i ++;
- if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
- $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
- $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
- } else {
- $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
+ if($i > $MaxUser) {
+ break;
}
}
+ $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
+ $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
}
}
+ /* If more than max users are found, display a message to warn the user */
if(($i == $MaxUser)){
print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
}
if(($i == $MaxUser)){
print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
}
- natcasesort ($this->allusers);
- reset ($this->allusers);
-
- /* Fill memberlist */
- $this->members= array();
- foreach ($this->memberUid as $value){
- if (isset($this->allusers[$value])){
- $this->members[$value]= $this->allusers[$value];
- } else {
- $ldap->cd($this->config->current['BASE']);
- $ldap->search("(&(objectClass=gosaAccount)(uid=".$value."))",array("uid", "sn","givenName"));
- $attrs = $ldap->fetch();
-
- if(!$attrs){
- $this->members[$value] = _("! unknown id")." [".$value."]";
- }else{
-
- if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
- $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
- $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
- } else {
- $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
- }
- if (isset($this->allusers[$value])){
- $this->members[$value]= $this->allusers[$value];
- } else {
- $this->members[$value] = "[".$value."]";
- }
- }
- }
- }
- asort($this->members);
+ /* Sort lists */
+ natcasesort($this->members);
reset($this->members);
reset($this->members);
+ natcasesort ($this->displayUsers);
+ reset ($this->displayUsers);
}
}
+ /* Create display name, this was used so often that it is excluded into a seperate function */
+ function createResultName($attrs)
+ {
+ if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
+ $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
+ } else {
+ $ret= $attrs['uid'][0];
+ }
+ return($ret);
+ }
+
function remove_from_parent()
{
function remove_from_parent()
{
$ldap= $this->config->get_ldap_link();
$ldap->rmdir($this->dn);
$ldap= $this->config->get_ldap_link();
$ldap->rmdir($this->dn);
- show_ldap_error($ldap->get_error());
+ show_ldap_error($ldap->get_error(), _("Removing group failed"));
/* Delete references to object groups */
$ldap->cd ($this->config->current['BASE']);
/* Delete references to object groups */
$ldap->cd ($this->config->current['BASE']);
/* Save additional values for possible next step */
if (isset($_POST['groupedit'])){
/* Save additional values for possible next step */
if (isset($_POST['groupedit'])){
-
plugin::save_object();
$this->force_gid= 0;
plugin::save_object();
$this->force_gid= 0;
/* Save to LDAP */
function save()
{
/* Save to LDAP */
function save()
{
+
/* ID handling */
if ($this->force_gid == 0){
if ($this->saved_gidNumber != ""){
/* ID handling */
if ($this->force_gid == 0){
if ($this->saved_gidNumber != ""){
$this->gidNumber= $this->get_next_id("gidNumber");
}
}
$this->gidNumber= $this->get_next_id("gidNumber");
}
}
-
+
plugin::save();
/* Remove objectClass for samba/phone support */
plugin::save();
/* Remove objectClass for samba/phone support */
/* Save data. Using 'modify' implies that the entry is already present, use 'add' for
new entries. So do a check first... */
/* Save data. Using 'modify' implies that the entry is already present, use 'add' for
new entries. So do a check first... */
- $ldap->cat ($this->dn);
+ $ldap->cat ($this->dn, array('dn'));
if ($ldap->fetch()){
/* Modify needs array() to remove values :-( */
if (!count ($this->memberUid)){
if ($ldap->fetch()){
/* Modify needs array() to remove values :-( */
if (!count ($this->memberUid)){
$ldap->$mode($this->attrs);
$ret= 0;
$ldap->$mode($this->attrs);
$ret= 0;
- if (show_ldap_error($ldap->get_error())){
+ if (show_ldap_error($ldap->get_error(), _("Saving group failed"))){
$ret= 1;
}
$ret= 1;
}
function check()
{
function check()
{
- $message= array();
+ /* Call common method to give check the hook */
+ $message= plugin::check();
/* Permissions for that base? */
if ($this->base != ""){
/* Permissions for that base? */
if ($this->base != ""){
$ldap= $this->config->get_ldap_link();
if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
$ldap->cd("ou=groups,".$this->base);
$ldap= $this->config->get_ldap_link();
if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
$ldap->cd("ou=groups,".$this->base);
- $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))","ou=groups,".$this->base,array("cn"));
+ $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
if ($ldap->count() != 0){
$message[]= _("Value specified as 'Name' is already used.");
}
if ($ldap->count() != 0){
$message[]= _("Value specified as 'Name' is already used.");
}
$dis = " disabled ";
}
$dis = " disabled ";
}
- $str =" <table>
- <tr>
- <td>".
- _("Group name").
- "</td>
- <td>
- <input id='cn' name='cn' size='35' maxlength='60'
- value='".$this->cn."'
- title='"._("Posix name of the group")."'>
- </td>
- </tr>
- <tr>
- <td colspan=2>
- <input type=checkbox name='force_gid' value='1' ".$used."
- title='"._("Normally IDs are autogenerated, select to specify manually")."'
- onclick='changeState(\"gidNumber\")'
- <LABEL for='gidNumber'>"._("Force GID")."</LABEL>
-
- <input name='gidNumber' size=5 maxlength=5 id='gidNumber' ".$dis."
- value='".$this->gidNumber."' title='"._("Forced ID number")."'>
- </td>
- </tr>
-
- </table>";
-
- return($str);
+ $smarty = get_smarty();
+ $smarty->assign("used",$used);
+ $smarty->assign("dis" ,$dis);
+ $smarty->assign("cn" ,$this->cn);
+ $smarty->assign("gidNumber",$this->gidNumber);
+ $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
+ $ret = array();
+ $ret['string'] = $str;
+ $ret['status'] = "";
+ return($ret);
}
function saveCopyDialog()
}
function saveCopyDialog()
$this->cn = $_POST['cn'];
}
if(isset($_POST['force_gid'])){
$this->cn = $_POST['cn'];
}
if(isset($_POST['force_gid'])){
- $this->force_gid = true;
+ $this->force_gid = 1;
$this->gidNumber= $_POST['gidNumber'];
}else{
$this->gidNumber= $_POST['gidNumber'];
}else{
- $this->force_gid = false;
+ $this->force_gid = 0;
$this->gidNumber = false;
}
}
$this->gidNumber = false;
}
}