index 91ae157ebf49301b3acb8f5f493aa2988764abd1..2c4a5649b1ee22ebe44782f8c7a6d40da5642d33 100644 (file)
class userFilter extends plugin
{
class userFilter extends plugin
{
- protected $fitlers = array();
- protected $availableCategories = array();
+ public $pathTitle= "Filter";
+
+ public $filters = array();
- public $objectClass = array('gosaProperties');
+ public $objectclasses = array('gosaProperties');
public $attributes = array('gosaUserDefinedFilter');
public $gosaUserDefinedFilter = array();
public $attributes = array('gosaUserDefinedFilter');
public $gosaUserDefinedFilter = array();
+ private $listing = NULL;
+
+ /*! \brief Returns true if we are able to read and write userFilters
+ * (schema has to be present, gosaProperties)
+ */
+ static function userFilteringAvailable()
+ {
+ if(!session::is_set('userFilter::userFilteringAvailable')){
+ global $config;
+ $ldap = $config->get_ldap_link();
+ $ocs = $ldap->get_objectclasses();
+ session::set('userFilter::userFilteringAvailable', isset($ocs['gosaProperties']));
+ }
+ return(session::get('userFilter::userFilteringAvailable'));
+ }
/*! \brief Initiates the filter editing dialog.
*/
/*! \brief Initiates the filter editing dialog.
*/
- function __construct($config, $categories)
+ function __construct($config, $listing)
{
// Initialize this plugin with the users dn to gather user defined filters.
$ui = get_userinfo();
plugin::plugin($config, $ui->dn);
{
// Initialize this plugin with the users dn to gather user defined filters.
$ui = get_userinfo();
plugin::plugin($config, $ui->dn);
-
- // Keep list of currently managed categories.
- $this->availableCategories = array_unique($categories);
- $this->availableCategories[] = 'systems';
- $this->availableCategories[] = 'phones';
- $this->availableCategories[] = 'printer';
- $this->availableCategories[] = 'component';
+ $this->listing = &$listing;
+ $filter= $this->listing->getFilter();
// Load list of filters
if(isset($this->attrs['gosaUserDefinedFilter'])){
for($i=0; $i< $this->attrs['gosaUserDefinedFilter']['count']; $i++){
// 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]);
-
- // Ensure that we no empty category in our category list.
- if(empty($categories)){
- $categories = array();
- }else{
- $categories = split(',', $categories);
- }
-
- // Ensure that we no empty entry in out flags list.
- if(empty($flags)){
- $flags = array();
- }else{
- $flags = split(',', $flags);
+ $tmp = userFilter::explodeFilterString($this->attrs['gosaUserDefinedFilter'][$i]);
+ if(isset($tmp['tag'])){
+ $this->filters[$tmp['tag']]= $tmp;
}
}
-
- // build up filter entry.
- $tmp = array(
- 'name' => $name,
- 'categories' => $categories,
- 'description' => base64_decode($description),
- 'filter' => base64_decode($filter),
- 'flags' => $flags);
-
-
- $this->filters[$name] = $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->setHeight("270px");
$this->filterWidget->setDeleteable(true);
$this->filterWidget->setEditable(true);
$this->filterWidget->setWidth("100%");
$this->filterWidget->setHeight("270px");
- $this->filterWidget->setColspecs(array('100px', '200px', '100px', '70px','150px'));
+ $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->setAcl($ui->get_permissions($ui->dn,'users/user','gosaUserDefinedFilter'));
- $this->filterWidget->setListData($this->filters, $this->convertFilterList());
}
}
+
+ /*! \brief Parses a filter string into an array.
+ */
+ static function explodeFilterString($filterStr)
+ {
+ list($parent,$categories, $name, $description, $filterList, $flags) = split(";", $filterStr);
+
+ // Ensure that we no empty category in our category list.
+ if(empty($categories)){
+ $categories = array();
+ }else{
+ $categories = split(',', $categories);
+ }
+
+ // Ensure that we no empty entry in out flags list.
+ if(empty($flags)){
+ $flags = array();
+ }else{
+ $flags = preg_split('/,/', $flags);
+ }
+
+ // Get filters and their backends
+ $queries = array();
+ foreach(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,
+ 'tag' => $name,
+ 'categories' => $categories,
+ 'description' => base64_decode($description),
+ 'query' => $queries,
+ 'flags' => $flags);
+
+ return($tmp);
+ }
+
/*! \brief Converts the list of filters ($this->filters) into data which is useable
* for the sortableList object ($this->filterWidget).
/*! \brief Converts the list of filters ($this->filters) into data which is useable
* for the sortableList object ($this->filterWidget).
foreach($this->filters as $name => $filter){
$data[$name] = array('data' =>
array(
foreach($this->filters as $name => $filter){
$data[$name] = array('data' =>
array(
- $filter['name'],
- $filter['description'],
+ $filter['parent'],
+ $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->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->dialog=new userFilterEditor(array(), $this->listing);
}
// Act on remove requests
}
// Act on remove requests
}
}
+ /*! \brief Returns user defined filter for a given list of categories,
+ * if no categories were specified all enabled filters will be returned.
+ */
+ static function getFilter($category=array())
+ {
+ global $config;
+
+ $ldap=$config->get_ldap_link();
+ $ui = get_userinfo();
+ $ldap->cd($config->current['BASE']);
+ $ldap->search("(&(objectClass=gosaProperties)(gosaUserDefinedFilter=*))",array('gosaUserDefinedFilter'));
+ $filter = array();
+ while($attrs = $ldap->fetch()){
+ for($i=0; $i < $attrs['gosaUserDefinedFilter']['count']; $i++){
+ $tmp = userFilter::explodeFilterString($attrs['gosaUserDefinedFilter'][$i]);
+ if(!isset($tmp['tag'])) continue;
+
+ // Remove line breaks from the filter, which may were added for better reading.
+ 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']));
+
+ // Add filter if it matches the category list
+ if($visible && (count($category) == 0 || array_intersect($category, $tmp['categories']))){
+ $filter[$tmp['tag']] = $tmp;
+ }
+ }
+ }
+ return($filter);
+ }
+
+
/*! \brief Write user-filter modifications back to the ldap.
*/
function save()
/*! \brief Write user-filter modifications back to the ldap.
*/
function save()
// Build up new list of filters
$attrs = array();
foreach($this->filters as $filter){
// Build up new list of filters
$attrs = array();
foreach($this->filters as $filter){
- $tmp = implode(',', $filter['categories']).";";
- $tmp.= $filter['name'].";";
+ $tmp = $filter['parent'].";";
+ $tmp.= implode(',', $filter['categories']).";";
+ $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;
}
new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
if (!$ldap->success()){
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()));
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
}
}
}
}