From eededf73e8ef7a794ea5e76c1051c37e89b156d2 Mon Sep 17 00:00:00 2001 From: dradon Date: Wed, 20 Apr 2011 10:19:29 +0000 Subject: [PATCH] Changed ACL member-list to use sortableListing instead of HTML select. Also fixed behavior of sortableListing for multiple posts. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20754 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/ihtml/themes/default/acl.tpl | 62 ++------- gosa-core/include/class_acl.inc | 142 +++++++++++++++++++- gosa-core/include/class_sortableListing.inc | 101 +++++++------- 3 files changed, 203 insertions(+), 102 deletions(-) diff --git a/gosa-core/ihtml/themes/default/acl.tpl b/gosa-core/ihtml/themes/default/acl.tpl index 15ad1983b..f5ed778a9 100644 --- a/gosa-core/ihtml/themes/default/acl.tpl +++ b/gosa-core/ihtml/themes/default/acl.tpl @@ -50,59 +50,15 @@
-

{t}Members{/t}

- - - - - - - - - - -
- {t}Use members from{/t} - - {if $javascript eq 'false'}{/if} -  {t}Members{/t}
- {if !$acl_writeable} - - {else} - - {/if} - - - {if $acl_writeable} - - -

- - - {/if} -
- {if !$acl_writeable} - - - {else} - - {/if} -
+

{t}Members{/t}

+ {$aclMemberList} +   + +   {if $aclType ne 'reset'} {if $aclType ne 'role'} diff --git a/gosa-core/include/class_acl.inc b/gosa-core/include/class_acl.inc index 60a4e65be..4d24dbda6 100644 --- a/gosa-core/include/class_acl.inc +++ b/gosa-core/include/class_acl.inc @@ -58,6 +58,7 @@ class acl extends plugin var $sectionList = NULL; var $roleList = NULL; + var $aclMemberList = NULL; function acl (&$config, $parent, $dn= NULL) { @@ -264,6 +265,18 @@ class acl extends plugin $this->roleList->setHeader(array(_("Used"),_("Name"),_("Description"))); $this->roleList->setDefaultSortColumn(1); $this->roleList->setAcl('rwcdm'); // All ACLs, we filter on our own here. + + $this->aclMemberList = new sortableListing(array(), array(), false); + $this->aclMemberList->setEditable(false); + $this->aclMemberList->setDeleteable(true); + $this->aclMemberList->setInstantDelete(false); + $this->aclMemberList->sortingEnabled(true); + $this->aclMemberList->setWidth("100%"); + $this->aclMemberList->setHeight("150px"); + //$this->aclMemberList->setColspecs(array('20px','*','*')); + $this->aclMemberList->setHeader(array(_("~"),_("Name"),_("Description"))); + $this->aclMemberList->setDefaultSortColumn(1); + $this->aclMemberList->setAcl('rwcdm'); // All ACLs, we filter on our own here. } @@ -337,7 +350,7 @@ class acl extends plugin $this->dialog= TRUE; $this->loadAclEntry(); } - + foreach($_POST as $name => $post){ $post =get_post($name); @@ -515,12 +528,92 @@ class acl extends plugin } /* Remove from list? */ - if (isset($_POST['del']) && isset($_POST['recipient'])){ - foreach ($_POST['recipient'] as $key){ + if (isset($_POST['del']) && isset($_POST['recipient'])) { + foreach ($_POST['recipient'] as $key) { unset($this->recipients[$key]); } } + $this->aclMemberList->save_object(); + $actionL = $this->aclMemberList->getAction(); + if($actionL['action'] == "delete") { + $key = $this->aclMemberList->getData($actionL['targets'][0]); + unset($this->recipients[$key]); + $this->aclMemberList->deleteEntry($actionL['targets'][0]); + } + + /* Adds the 'all-users' peudo-group to the acl */ + if(isset($_POST['add_all_users'])) { + if(!isset($this->recipients['G:*'])) { + $this->recipients['G:*'] = _("All users"); + + $key = "G:*"; + $vData = array("data" => array(image("plugins/groups/images/select_group.png"), + _("All users"), + _("Pseudo-group for all users."))); + + $this->aclMemberList->addEntry($key, $vData, $key); + } + } + + /* Show User/Group-Add-Dialog */ + if(isset($_POST['add_user_or_group'])) { + $this->dialog = new userGroupSelect($this->config, get_userinfo()); + } + + /* If dialog is confirmed */ + if(isset($_POST['userGroupSelect_save']) && + $this->dialog instanceof userGroupSelect) { + + $groupIcon = image("plugins/groups/images/select_group.png"); + $userIcon = image("plugins/users/images/select_user.png"); + + if($this->acl_is_writeable("")) { + foreach($this->dialog->save() as $entry) { + if(in_array("posixGroup", $entry['objectClass'])) { + $key = "G:" . $entry['dn']; + $vData = array("data" => array($groupIcon, $entry['cn'][0], $entry['description'][0])); + + $this->recipients[$key] = $entry['cn'][0]; + } + else if(isset($entry['uid'])) { + $key = "U:" . $entry['dn']; + $vData = array("data" => array($userIcon, $entry['uid'][0], $entry['cn'][0])); + + $lData = array($key => $key); + $this->recipients["U:" . $entry['dn']] = $entry['uid'][0]; + } + else { + // Error + break; + } + + $this->aclMemberList->addEntry($key, $vData, $key); + } + } + + unset($this->dialog); + $this->dialog = true; + } + + /* If dialog is canceled */ + if(isset($_POST['userGroupSelect_cancel']) && + $this->dialog instanceof userGroupSelect) { + unset($this->dialog); + $this->dialog = true; + } + + if($this->dialog instanceof userGroupSelect) { + // filter current members out + $used = array(); + foreach(array_keys($this->recipients) as $key) { + $used['dn'][] = substr($key, 2); + } + + session::set('filterBlacklist', $used); + return $this->dialog->execute(); + } + /* Create templating instance */ $smarty= get_smarty(); @@ -624,6 +717,16 @@ class acl extends plugin $smarty->assign('sources', set_post($tmp)); $smarty->assign('recipients', set_post($this->recipients)); + /* Generate ACL member list */ + if($this->acl_is_writeable("")) { + $this->aclMemberList->setDeleteable(true); + } else { + $this->aclMemberList->setDeleteable(false); + } + + $this->aclMemberList->update(); + $smarty->assign("aclMemberList", $this->aclMemberList->render()); + /* Acl selector if scope is base */ if ($this->aclType == 'base'){ $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects)); @@ -1138,6 +1241,39 @@ class acl extends plugin $this->recipients= $acl['members']; $this->aclContents= (isset($acl['acl'])) ? $acl['acl'] :""; $this->aclFilter= $acl['filter']; + + /* Add members to aclMemberList */ + $vData = array(); + $lData = array(); + foreach($this->recipients as $key => $val) { + // split name and description + $match = NULL; + preg_match_all("/^([^\[]+)( \[(.*)\])?$/", $val, $match); + + $name = ""; + $desc = ""; + $icon = NULL; + if($key == "G:*") { + $name = _("All users"); + $desc = _("Pseudo-group for all users."); + $icon = image("plugins/groups/images/select_group.png"); + } + else if($key[0] == 'U') { // is user? + $name = $match[3][0]; + $desc = $match[1][0]; + $icon = image("plugins/users/images/select_user.png"); + } + else { // or group? + $name = $match[1][0]; + $desc = $match[3][0]; + $icon = image("plugins/groups/images/select_group.png"); + } + + $lData[$key] = $key; + $vData[$key] = array("data" => array($icon, $name, $desc)); + } + + $this->aclMemberList->setListData($lData, $vData); } $this->wasNewEntry= $new; diff --git a/gosa-core/include/class_sortableListing.inc b/gosa-core/include/class_sortableListing.inc index 8e03f08b1..a8b627c89 100644 --- a/gosa-core/include/class_sortableListing.inc +++ b/gosa-core/include/class_sortableListing.inc @@ -25,36 +25,36 @@ define ('LIST_MARKED', 1); define ('LIST_DISABLED', 2); class sortableListing { - private $header= null; - private $colspecs= null; - private $reorderable= true; - private $width= "400px"; - private $height= "100px"; - private $cssclass= ""; - private $id; - - private $sortingEnabled= true; - private $data= array(); - private $keys= array(); - private $modes= array(); - private $displayData= array(); - private $columns= 0; - private $deleteable= false; - private $editable= false; - private $colorAlternate= false; - private $instantDelete= true; - private $action; - private $mapping; - private $current_mapping; - private $active_index; - private $scrollPosition= 0; - private $sortColumn= 0; - private $sortDirection= array(); - - private $acl= ""; - private $modified= false; - - + public $header= null; + public $colspecs= null; + public $reorderable= true; + public $width= "400px"; + public $height= "100px"; + public $cssclass= ""; + public $id; + + public $sortingEnabled= true; + public $data= array(); + public $keys= array(); + public $modes= array(); + public $displayData= array(); + public $columns= 0; + public $deleteable= false; + public $editable= false; + public $colorAlternate= false; + public $instantDelete= true; + public $action; + public $mapping; + public $current_mapping; + public $active_index; + public $scrollPosition= 0; + public $sortColumn= 0; + public $sortDirection= array(); + + public $acl= ""; + public $modified= false; + + public function sortableListing($data= array(), $displayData= null, $reorderable= false) { global $config; @@ -101,17 +101,17 @@ class sortableListing { $this->sortColumn = $id; } - /* - * - * Examples - * DatenARray ($data) - * @param: array( arbitrary object, arbitrary object) - * Datenarray will be manipulated by add, del and sort operations. According to this it will be returned from this widget. - * The index of a data entry must correspond to the entry of the "display array" following. - * DisplayArray ($displyData) - * @param: array("eins" array( "data"=> array("Uno", "2", "x" ) , "zwei" array( "data"=> array("Due", "3", "y" ))) ; - * label pointing on a list of columns that will be shown in the list. - */ + /* + * + * Examples + * DatenARray ($data) + * @param: array( arbitrary object, arbitrary object) + * Datenarray will be manipulated by add, del and sort operations. According to this it will be returned from this widget. + * The index of a data entry must correspond to the entry of the "display array" following. + * DisplayArray ($displyData) + * @param: array("eins" array( "data"=> array("Uno", "2", "x" ) , "zwei" array( "data"=> array("Due", "3", "y" ))) ; + * label pointing on a list of columns that will be shown in the list. + */ public function setListData($data, $displayData= null) { // Save data to display @@ -125,13 +125,13 @@ class sortableListing { $this->setDisplayData($displayData); } - //setting flat data + //setting flat data private function setData($data) { $this->data= $data; } - // collecting the display data - + // collecting the display data - private function setDisplayData($data) { if (!is_array($data)) { @@ -229,7 +229,7 @@ class sortableListing { public function render() - { + { $result= "
\n"; $result.= "cssclass)?" class='".$this->cssclass."'":"").">\n"; $action_width= 0; @@ -427,6 +427,10 @@ class sortableListing { foreach ($_POST as $key => $value) { $value = get_post($key); if (preg_match('/^del_'.$this->id.'_([0-9]+)$/', $key, $matches)) { + + + if(!isset($this->mapping[$matches[1]])) return; + $this->active_index= $this->mapping[$matches[1]]; // Ignore request if mode requests it @@ -451,6 +455,9 @@ class sortableListing { foreach ($_POST as $key => $value) { $value = get_post($key); if (preg_match('/^edit_'.$this->id.'_([0-9]+)$/', $key, $matches)) { + + if(!isset($this->mapping[$matches[1]])) return; + $this->active_index= $this->mapping[$matches[1]]; // Ignore request if mode requests it @@ -485,16 +492,18 @@ class sortableListing { } - private function deleteEntry($id) + public function deleteEntry($id) { // Remove mapping $index= array_search($id, $this->mapping); if ($index !== false) { $target = $this->mapping[$index]; + $key = $this->keys[$target]; + unset($this->mapping[$index]); if(isset($this->displayData[$target])){ unset($this->displayData[$target]); - unset($this->data[$target]); + unset($this->data[$key]); unset($this->keys[$target]); } $this->mapping= array_values($this->mapping); -- 2.30.2