index c188e981257e630c1755e7904e6806e544a993e0..b1ee8224726524993d36f576a5a0143750d94b8a 100644 (file)
class userFilter extends plugin
{
class userFilter extends plugin
{
- protected $filters = array();
- protected $availableCategories = array();
+ public $pathTitle= "Filter";
+
+ public $filters = array();
public $objectclasses = array('gosaProperties');
public $attributes = array('gosaUserDefinedFilter');
public $gosaUserDefinedFilter = array();
public $objectclasses = array('gosaProperties');
public $attributes = array('gosaUserDefinedFilter');
public $gosaUserDefinedFilter = array();
-
private $listing = NULL;
private $listing = NULL;
- private $fixedFilter = NULL;
/*! \brief Returns true if we are able to read and write userFilters
* (schema has to be present, gosaProperties)
/*! \brief Returns true if we are able to read and write userFilters
* (schema has to be present, gosaProperties)
plugin::plugin($config, $ui->dn);
$this->listing = &$listing;
$filter= $this->listing->getFilter();
plugin::plugin($config, $ui->dn);
$this->listing = &$listing;
$filter= $this->listing->getFilter();
- $this->fixedFilter = $filter->getFixedFilters();
-
- // Keep list of currently managed categories.
- $this->availableCategories = array_unique($this->listing->categories);
// Load list of filters
if(isset($this->attrs['gosaUserDefinedFilter'])){
for($i=0; $i< $this->attrs['gosaUserDefinedFilter']['count']; $i++){
$tmp = userFilter::explodeFilterString($this->attrs['gosaUserDefinedFilter'][$i]);
// Load list of filters
if(isset($this->attrs['gosaUserDefinedFilter'])){
for($i=0; $i< $this->attrs['gosaUserDefinedFilter']['count']; $i++){
$tmp = userFilter::explodeFilterString($this->attrs['gosaUserDefinedFilter'][$i]);
- if(isset($tmp['name'])){
- $this->filters[$tmp['name']]= $tmp;
+ if(isset($tmp['tag'])){
+ $this->filters[$tmp['tag']]= $tmp;
}
}
}
// Create the filter list
}
}
}
// Create the filter list
- $this->filterWidget= new sortableListing();
+ $this->filterWidget= new sortableListing($this->filters, $this->convertFilterList());
$this->filterWidget->setDeleteable(true);
$this->filterWidget->setEditable(true);
$this->filterWidget->setWidth("100%");
$this->filterWidget->setDeleteable(true);
$this->filterWidget->setEditable(true);
$this->filterWidget->setWidth("100%");
$this->filterWidget->setHeader(array(_("Parent filter"),_("Name"),_("Description"),_("Category"),_("Options"),""));
$this->filterWidget->setColspecs(array('80px', '100px', '200px', '120px','150px'));
$this->filterWidget->setAcl($ui->get_permissions($ui->dn,'users/user','gosaUserDefinedFilter'));
$this->filterWidget->setHeader(array(_("Parent filter"),_("Name"),_("Description"),_("Category"),_("Options"),""));
$this->filterWidget->setColspecs(array('80px', '100px', '200px', '120px','150px'));
$this->filterWidget->setAcl($ui->get_permissions($ui->dn,'users/user','gosaUserDefinedFilter'));
- $this->filterWidget->setListData($this->filters, $this->convertFilterList());
}
/*! \brief Parses a filter string into an array.
*/
}
/*! \brief Parses a filter string into an array.
*/
- static function explodeFilterString($filter)
+ static function explodeFilterString($filterStr)
{
{
- list($parent,$categories, $name, $description, $filter, $flags) = split(";", $filter);
+ list($parent,$categories, $name, $description, $filterList, $flags) = preg_split('/;/', $filterStr);
// Ensure that we no empty category in our category list.
if(empty($categories)){
$categories = array();
}else{
// Ensure that we no empty category in our category list.
if(empty($categories)){
$categories = array();
}else{
- $categories = split(',', $categories);
+ $categories = preg_split('/,/', $categories);
}
// Ensure that we no empty entry in out flags list.
if(empty($flags)){
$flags = array();
}else{
}
// Ensure that we no empty entry in out flags list.
if(empty($flags)){
$flags = array();
}else{
- $flags = split(',', $flags);
+ $flags = preg_split('/,/', $flags);
+ }
+
+ // Get filters and their backends
+ $queries = array();
+ foreach(preg_split('/,/', $filterList) as $data){
+ if(!empty($data)){
+ list($filter, $backend) = preg_split('/:/', $data);
+ $queries[] = array('backend' => $backend, 'filter' => base64_decode($filter));
+ }
}
// build up filter entry.
$tmp = array(
'parent' => $parent,
}
// build up filter entry.
$tmp = array(
'parent' => $parent,
- 'name' => $name,
+ 'tag' => $name,
'categories' => $categories,
'description' => base64_decode($description),
'categories' => $categories,
'description' => base64_decode($description),
- 'filter' => base64_decode($filter),
+ 'query' => $queries,
'flags' => $flags);
return($tmp);
'flags' => $flags);
return($tmp);
$data[$name] = array('data' =>
array(
$filter['parent'],
$data[$name] = array('data' =>
array(
$filter['parent'],
- $filter['name'],
- $filter['description'],
+ $filter['tag'],
+ htmlentities($filter['description'], ENT_COMPAT, 'UTF-8'),
implode(", ",$filter['categories']),
implode(", ",$filter['flags'])));
}
implode(", ",$filter['categories']),
implode(", ",$filter['flags'])));
}
function execute()
{
plugin::execute();
function execute()
{
plugin::execute();
+
+ // Let the filter widget update itself
+ $this->filterWidget->update();
// Cancel filter modifications (edit dialog)
if(isset($_POST['cancelFilterSettings'])){
// Cancel filter modifications (edit dialog)
if(isset($_POST['cancelFilterSettings'])){
if($action['action'] == 'edit' && count($action['targets']) == 1){
$key= $this->filterWidget->getKey($action['targets'][0]);
if(isset($this->filters[$key])){
if($action['action'] == 'edit' && count($action['targets']) == 1){
$key= $this->filterWidget->getKey($action['targets'][0]);
if(isset($this->filters[$key])){
- $this->dialog=new userFilterEditor($this->filters[$key], $this->availableCategories, $this->fixedFilter);
+ $this->dialog=new userFilterEditor($this->filters[$key], $this->listing);
}
}
// Act on new requests
if(isset($_POST['addFilter'])){
}
}
// Act on new requests
if(isset($_POST['addFilter'])){
- $this->dialog=new userFilterEditor(array(), $this->availableCategories, $this->fixedFilter);
+ $this->dialog=new userFilterEditor(array(), $this->listing);
}
// Act on remove requests
}
// Act on remove requests
static function getFilter($category=array())
{
global $config;
static function getFilter($category=array())
{
global $config;
+
$ldap=$config->get_ldap_link();
$ui = get_userinfo();
$ldap->cd($config->current['BASE']);
$ldap=$config->get_ldap_link();
$ui = get_userinfo();
$ldap->cd($config->current['BASE']);
while($attrs = $ldap->fetch()){
for($i=0; $i < $attrs['gosaUserDefinedFilter']['count']; $i++){
$tmp = userFilter::explodeFilterString($attrs['gosaUserDefinedFilter'][$i]);
while($attrs = $ldap->fetch()){
for($i=0; $i < $attrs['gosaUserDefinedFilter']['count']; $i++){
$tmp = userFilter::explodeFilterString($attrs['gosaUserDefinedFilter'][$i]);
- if(!isset($tmp['name'])) continue;
+ if(!isset($tmp['tag'])) continue;
// Remove line breaks from the filter, which may were added for better reading.
// Remove line breaks from the filter, which may were added for better reading.
- $c = preg_split('/\n/',$tmp['filter']);
-
- foreach($c as $key => $str) $c[$key] = trim($str);
- $tmp['filter'] = implode($c);
+ foreach($tmp['query'] as $key => $query){
+ $c = preg_split('/\n/',$query['filter']);
+ foreach($c as $cKey => $str) $c[$cKey] = trim($str);
+ $tmp['query'][$key]['filter'] = mb_convert_encoding(implode($c),'UTF-8');
+ }
// The filter is visible if it is shared or if is one of our own creations.
// ... and enabled.
$visible = in_array('enable', $tmp['flags']) &&
($attrs['dn'] == $ui->dn || in_array('share', $tmp['flags']));
// The filter is visible if it is shared or if is one of our own creations.
// ... and enabled.
$visible = in_array('enable', $tmp['flags']) &&
($attrs['dn'] == $ui->dn || in_array('share', $tmp['flags']));
- // Convert filter encoding
- $tmp['filter'] = mb_convert_encoding($tmp['filter'], 'UTF-8');
-
// Add filter if it matches the category list
if($visible && (count($category) == 0 || array_intersect($category, $tmp['categories']))){
// Add filter if it matches the category list
if($visible && (count($category) == 0 || array_intersect($category, $tmp['categories']))){
- $filter[$tmp['name']] = $tmp;
+ $filter[$tmp['tag']] = $tmp;
}
}
}
}
}
}
foreach($this->filters as $filter){
$tmp = $filter['parent'].";";
$tmp.= implode(',', $filter['categories']).";";
foreach($this->filters as $filter){
$tmp = $filter['parent'].";";
$tmp.= implode(',', $filter['categories']).";";
- $tmp.= $filter['name'].";";
+ $tmp.= $filter['tag'].";";
$tmp.= base64_encode($filter['description']).";";
$tmp.= base64_encode($filter['description']).";";
- $tmp.= base64_encode($filter['filter']).";";
+
+ // Add queries
+ foreach($filter['query'] as $query){
+ $tmp.= base64_encode($query['filter']).":".$query['backend'].",";
+ }
+ $tmp = trim($tmp,",").";";
$tmp.= implode(',', $filter['flags']);
$attrs[] = $tmp;
}
$tmp.= implode(',', $filter['flags']);
$attrs[] = $tmp;
}