From 1e69b1e298c56c9f19a6ce775e7acec9995464f2 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 9 Mar 2010 12:02:07 +0000 Subject: [PATCH] Added new filterEditor git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@16360 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../ihtml/themes/modern/filterEditor.tpl | 14 ++ .../ihtml/themes/modern/filterEditorEntry.tpl | 61 +++++++ gosa-core/include/class_filterEditor.inc | 168 ++++++++++++++++++ gosa-core/include/class_filterEditorEntry.inc | 101 +++++++++++ gosa-core/plugins/personal/myaccount/main.inc | 2 +- 5 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 gosa-core/ihtml/themes/modern/filterEditor.tpl create mode 100644 gosa-core/ihtml/themes/modern/filterEditorEntry.tpl create mode 100644 gosa-core/include/class_filterEditor.inc create mode 100644 gosa-core/include/class_filterEditorEntry.inc diff --git a/gosa-core/ihtml/themes/modern/filterEditor.tpl b/gosa-core/ihtml/themes/modern/filterEditor.tpl new file mode 100644 index 000000000..66c6442eb --- /dev/null +++ b/gosa-core/ihtml/themes/modern/filterEditor.tpl @@ -0,0 +1,14 @@ +

{t}Filter editor{/t}

+ +
+ +{t}List of configured filters{/t} +{$list} + + +
+ +
+ + +
diff --git a/gosa-core/ihtml/themes/modern/filterEditorEntry.tpl b/gosa-core/ihtml/themes/modern/filterEditorEntry.tpl new file mode 100644 index 000000000..54855f018 --- /dev/null +++ b/gosa-core/ihtml/themes/modern/filterEditorEntry.tpl @@ -0,0 +1,61 @@ +

{t}Filter editor{/t}

+ +
+ + + + + + +
+ + + + + + + + + +
+ + + +
+ + + +
+ +
+ + + {t}Share this filter with others{/t} +
+
+ +
+ + + + +
+ +
+ + + +
+ + + +
+ + +
diff --git a/gosa-core/include/class_filterEditor.inc b/gosa-core/include/class_filterEditor.inc new file mode 100644 index 000000000..0cafbb480 --- /dev/null +++ b/gosa-core/include/class_filterEditor.inc @@ -0,0 +1,168 @@ +dn); + + // Keep list of currently managed categories. + $this->availableCategories = array_unique($categories); + $this->availableCategories[] = 'systems'; + $this->availableCategories[] = 'phones'; + $this->availableCategories[] = 'printer'; + $this->availableCategories[] = 'component'; + + // Load list of filters + if(isset($this->attrs['gosaUserDefinedFilter'])){ + for($i=0; $i< $this->attrs['gosaUserDefinedFilter']['count']; $i++){ + list($categories, $name, $description, $filter, $flags) = split(";", $this->attrs['gosaUserDefinedFilter'][$i]); + $tmp = array( + 'name' => $name, + 'categories' => split(',', $categories), + 'description' => base64_decode($description), + 'filter' => base64_decode($filter), + 'flags' => split(',',$flags)); + $this->filters[$name] = $tmp; + } + } + + $this->filterWidget= new sortableListing(); + $this->filterWidget->setDeleteable(true); + $this->filterWidget->setEditable(true); + $this->filterWidget->setWidth("100%"); + $this->filterWidget->setHeight("70px"); + $this->filterWidget->setColspecs(array('100px', '200px', '100px', '70px','150px')); + $this->filterWidget->setAcl($ui->get_permissions($ui->dn,'users/user','gosaUserDefinedFilter')); + $this->filterWidget->setListData($this->filters, $this->convertFilterList()); + } + + function convertFilterList() + { + $data = array(); + foreach($this->filters as $name => $filter){ + $data[$name] = array('data' => + array( + $filter['name'], + $filter['description'], + implode(", ",$filter['categories']), + implode(", ",$filter['flags']))); + } + return($data); + } + + function execute() + { + plugin::execute(); + + // Close edit dialog + if(isset($_POST['cancelFilterSettings'])){ + $this->dialog = NULL; + } + + // Close edit dialog + if(isset($_POST['saveFilterSettings']) && $this->dialog instanceOf filterEditEntry){ + $this->dialog->save_object(); + $msgs = $this->dialog->check(); + if(count($msgs)){ + msg_dialog::display_checks($msgs); + }else{ + $orig_name = $this->dialog->getOriginalName(); + $new_name = $this->dialog->getCurrentName(); + + // Remove old entry + if($orig_name != "") unset($this->filters[$orig_name]); + + $this->filters[$new_name] = $this->dialog->save(); + $this->dialog = NULL; + $this->filterWidget->setListData($this->filters, $this->convertFilterList()); + $this->filterWidget->update(); + } + } + + // Act on edit requests + $this->filterWidget->save_object(); + $action = $this->filterWidget->getAction(); + if($action['action'] == 'edit' && count($action['targets']) == 1){ + $key= $this->filterWidget->getKey($action['targets'][0]); + if(isset($this->filters[$key])){ + $this->dialog=new filterEditEntry($this->filters[$key], $this->availableCategories); + } + } + + // Act add requests + if(isset($_POST['addFilter'])){ + $this->dialog=new filterEditEntry(array(), $this->availableCategories); + } + + // Act on remove requests + $action = $this->filterWidget->getAction(); + if($action['action'] == 'delete' && count($action['targets']) == 1){ + $key= $this->filterWidget->getKey($action['targets'][0]); + if(isset($this->filters[$key])){ + unset($this->filters[$key]); + $this->filterWidget->update(); + } + } + + // Display edit dialog + if($this->dialog instanceOf filterEditEntry){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + + $smarty = get_smarty(); + $smarty->assign("list", $this->filterWidget->render()); + return($smarty->fetch(get_template_path('filterEditor.tpl', FALSE))); + } + + function enabled() + { + return(count($this->_parent->categories) != 0); + } + + function save_object() + { + + } + + function save() + { + $attrs = array(); + foreach($this->filters as $filter){ + $tmp = implode(',', $filter['categories']).";"; + $tmp.= $filter['name'].";"; + $tmp.= base64_encode($filter['description']).";"; + $tmp.= base64_encode($filter['filter']).";"; + $tmp.= implode(',', $filter['flags']); + $attrs[] = $tmp; + } + $this->gosaUserDefinedFilter = $attrs; + plugin::save(); + + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $ldap->modify($this->attrs); + + new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MODIFY, get_class())); + } + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-core/include/class_filterEditorEntry.inc b/gosa-core/include/class_filterEditorEntry.inc new file mode 100644 index 000000000..dce7cdebf --- /dev/null +++ b/gosa-core/include/class_filterEditorEntry.inc @@ -0,0 +1,101 @@ +availableCategories = $categories; + if($entry){ + $this->entry = $entry; + $this->name = $entry['name']; + $this->description = $entry['description']; + $this->selectedCategories = $entry['categories']; + $this->filter = $entry['filter']; + $this->share = in_array("share",$entry['flags']); + } + + $this->orig_name = $this->name; + } + + function getOriginalName() + { + return($this->orig_name); + } + + function getCurrentName() + { + return($this->name); + } + + function execute() + { + plugin::execute(); + $smarty = get_smarty(); + $smarty->assign('name', $this->name); + $smarty->assign('filter', $this->filter); + $smarty->assign('share', $this->share); + $smarty->assign('description', $this->description); + $smarty->assign('selectedCategories', $this->selectedCategories); + $smarty->assign('availableCategories', $this->availableCategories); + return($smarty->fetch(get_template_path('filterEditorEntry.tpl', FALSE))); + } + + function save_object() + { + if(isset($_POST['filterEditorEntry'])){ + + // Get posted strings + foreach(array('name','description','filter') as $attr){ + if(isset($_POST[$attr])){ + $this->$attr = get_post($attr); + } + } + + // Get posted flags + $this->share = isset($_POST['shareFilter']); + + // Get additional category + if(isset($_POST['addCategory'])){ + if(isset($_POST['manualCategory']) && !empty($_POST['manualCategory'])){ + $this->selectedCategories[] = get_post('manualCategory'); + }elseif(isset($_POST['availableCategory']) && !empty($_POST['availableCategory'])){ + $this->selectedCategories[] = get_post('availableCategory'); + } + } + + // Remove categories + if(isset($_POST['delCategory']) && isset($_POST['usedCategory'])){ + foreach($_POST['usedCategory'] as $cat){ + if(isset($this->selectedCategories[$cat])) unset($this->selectedCategories[$cat]); + } + } + } + } + + function save() + { + $ret= array(); + $ret['name'] = $this->name; + $ret['description'] = $this->description; + $ret['categories'] = $this->selectedCategories; + $ret['filter'] = $this->filter; + $ret['flags'] = array(); + if($this->share){ + $ret['flags'][] = "share"; + } + return($ret); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-core/plugins/personal/myaccount/main.inc b/gosa-core/plugins/personal/myaccount/main.inc index 142defd53..4854e5a80 100644 --- a/gosa-core/plugins/personal/myaccount/main.inc +++ b/gosa-core/plugins/personal/myaccount/main.inc @@ -111,7 +111,7 @@ if (! $cleanup ){ $display.= "\n"; $display.= "\n"; } else { - if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/MyAccountTabs"))){ + if(preg_match("/r/",$ui->get_category_permissions($ui->dn,"users"))){ $display.= "\n"; } $display.= "\n"; -- 2.30.2