From 4c6e98d2be0e39b947842ad731363bb418d8fb6f Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 19 Jul 2006 09:08:22 +0000 Subject: [PATCH] Excluded add/remove part in seperate function. User/Group deletion is now possible with multiple users git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@4231 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/systems/class_printGeneric.inc | 82 +++++++++++++++----- plugins/admin/systems/printer.tpl | 4 +- 2 files changed, 64 insertions(+), 22 deletions(-) diff --git a/plugins/admin/systems/class_printGeneric.inc b/plugins/admin/systems/class_printGeneric.inc index 736172021..026870745 100644 --- a/plugins/admin/systems/class_printGeneric.inc +++ b/plugins/admin/systems/class_printGeneric.inc @@ -399,28 +399,28 @@ class printgeneric extends plugin } } - /* Member management, delete user / group / admin ..*/ + /* Member management, delete user / group / admin ..*/ if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ - if(isset($this->member['AddUser'][$_POST['UserMember']])){ - unset($this->member['AddUser'][$_POST['UserMember']]); + foreach($_POST['UserMember'] as $mem){ + $this->DelMember('AddUser',$mem); } } if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){ - if(isset($this->member['AddGroup'][$_POST['UserMember']])){ - unset($this->member['AddGroup'][$_POST['UserMember']]); + foreach($_POST['UserMember'] as $mem){ + $this->DelMember('AddGroup',$mem); } } if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ - if(isset($this->member['AddAdminUser'][$_POST['AdminMember']])){ - unset($this->member['AddAdminUser'][$_POST['AdminMember']]); + foreach($_POST['AdminMember'] as $mem){ + $this->DelMember('AddAdminUser',$mem); } } if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){ - if(isset($this->member['AddAdminGroup'][$_POST['AdminMember']])){ - unset($this->member['AddAdminGroup'][$_POST['AdminMember']]); + foreach($_POST['AdminMember'] as $mem){ + $this->DelMember('AddAdminGroup',$mem); } } @@ -438,21 +438,13 @@ class printgeneric extends plugin print_red($msg); } }else{ - $new = $this->dialog->save(); - $data = $new; + $data= $new = $this->dialog->save(); unset($data['type']); - - if(preg_match("/User/",$new['type'])){ - $use = "uid"; - }else{ - $use = "cn"; - } - foreach($data as $mem){ - $this->member[$new['type']][$mem[$use][0]]=$mem; + $this->AddMember($new['type'], $mem['dn']); } unset($this->dialog); - $this->dialog=NULL; + $this->dialog=NULL; } } @@ -788,6 +780,56 @@ class printgeneric extends plugin } + /* Delete member */ + function DelMember($type,$id) + { + if(isset($this->member[$type][$id])){ + unset($this->member[$type][$id]); + } + } + + + /* Add given obejct to members */ + function AddMember($type,$dn) + { + $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup"); + if(!in_array_ics($type, $types)){ + print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type)); + return; + } + + /* Get name of index attributes */ + if(preg_match("/user/i",$type)){ + $var = "uid"; + }else{ + $var = "cn"; + } + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($dn); + $ldap->cat($dn,array("cn","uid")); + if($ldap->count()){ + + $attrs = $ldap->fetch(); + + /* Check if this uid/cn is already assigned to any permission */ + foreach($types as $ctype){ + if($type == $ctype) continue; + + if(in_array($attrs[$var][0],$this->member[$ctype])){ + print_red(sprintf(_("Can't add '%s' to members it is already used in another category."),$attrs[$var][0])); + return; + } + } + + /* Everything is fine. So add the given object to members */ + $this->member[$type][$attrs[$var][0]] = $attrs ; + }else{ + print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn)); + } + } + + } diff --git a/plugins/admin/systems/printer.tpl b/plugins/admin/systems/printer.tpl index 808d47f74..876ae22ba 100644 --- a/plugins/admin/systems/printer.tpl +++ b/plugins/admin/systems/printer.tpl @@ -68,7 +68,7 @@ {t}Users which are allowed to use this printer{/t}
- {html_options options=$UserMembers values=$UserMemberKeys}
@@ -84,7 +84,7 @@ {t}Users which are allowed to administrate this printer{/t}
- {html_options options=$AdminMembers values=$AdminMemberKeys}
-- 2.30.2