1 <?php
3 class userFilter extends plugin
4 {
5 protected $fitlers = array();
6 protected $availableCategories = array();
8 public $objectClass = array('gosaProperties');
9 public $attributes = array('gosaUserDefinedFilter');
10 public $gosaUserDefinedFilter = array();
13 /*! \brief Initiates the filter editing dialog.
14 */
15 function __construct($config, $categories)
16 {
17 // Initialize this plugin with the users dn to gather user defined filters.
18 $ui = get_userinfo();
19 plugin::plugin($config, $ui->dn);
21 // Keep list of currently managed categories.
22 $this->availableCategories = array_unique($categories);
23 $this->availableCategories[] = 'systems';
24 $this->availableCategories[] = 'phones';
25 $this->availableCategories[] = 'printer';
26 $this->availableCategories[] = 'component';
28 // Load list of filters
29 if(isset($this->attrs['gosaUserDefinedFilter'])){
30 for($i=0; $i< $this->attrs['gosaUserDefinedFilter']['count']; $i++){
31 list($categories, $name, $description, $filter, $flags) = split(";", $this->attrs['gosaUserDefinedFilter'][$i]);
33 // Ensure that we no empty category in our category list.
34 if(empty($categories)){
35 $categories = array();
36 }else{
37 $categories = split(',', $categories);
38 }
40 // Ensure that we no empty entry in out flags list.
41 if(empty($flags)){
42 $flags = array();
43 }else{
44 $flags = split(',', $flags);
45 }
47 // build up filter entry.
48 $tmp = array(
49 'name' => $name,
50 'categories' => $categories,
51 'description' => base64_decode($description),
52 'filter' => base64_decode($filter),
53 'flags' => $flags);
56 $this->filters[$name] = $tmp;
57 }
58 }
60 // Create the filter list
61 $this->filterWidget= new sortableListing();
62 $this->filterWidget->setDeleteable(true);
63 $this->filterWidget->setEditable(true);
64 $this->filterWidget->setWidth("100%");
65 $this->filterWidget->setHeight("270px");
66 $this->filterWidget->setColspecs(array('100px', '200px', '100px', '70px','150px'));
67 $this->filterWidget->setAcl($ui->get_permissions($ui->dn,'users/user','gosaUserDefinedFilter'));
68 $this->filterWidget->setListData($this->filters, $this->convertFilterList());
69 }
72 /*! \brief Converts the list of filters ($this->filters) into data which is useable
73 * for the sortableList object ($this->filterWidget).
74 * @return Array An array containg data useable for sortableLists ($this->filterWidget)
75 */
76 function convertFilterList()
77 {
78 $data = array();
79 foreach($this->filters as $name => $filter){
80 $data[$name] = array('data' =>
81 array(
82 $filter['name'],
83 $filter['description'],
84 implode(", ",$filter['categories']),
85 implode(", ",$filter['flags'])));
86 }
87 return($data);
88 }
91 /*! \brief Display the user-filter overview as HTML content.
92 * @return string HTML-content showing the user-filter editing dialog.
93 */
94 function execute()
95 {
96 plugin::execute();
98 // Cancel filter modifications (edit dialog)
99 if(isset($_POST['cancelFilterSettings'])){
100 $this->dialog = NULL;
101 }
103 // Save modified filter entries (edit dialog)
104 if(isset($_POST['saveFilterSettings']) && $this->dialog instanceOf userFilterEditor){
105 $this->dialog->save_object();
106 $msgs = $this->dialog->check();
107 if(count($msgs)){
108 msg_dialog::displayChecks($msgs);
109 }else{
110 $orig_name = $this->dialog->getOriginalName();
111 $new_name = $this->dialog->getCurrentName();
113 // The object was renamed and
114 if($orig_name != $new_name && isset($this->filters[$new_name])){
115 $msgs = array(msgPool::duplicated(_("Name")));
116 msg_dialog::displayChecks($msgs);
117 }else{
119 // Remove old entry if filter was renamed
120 if($orig_name != "" && isset($this->filters[$orig_name])){
121 unset($this->filters[$orig_name]);
122 }
124 // Now append the new filter object.
125 $this->filters[$new_name] = $this->dialog->save();
126 $this->dialog = NULL;
127 $this->filterWidget->setListData($this->filters, $this->convertFilterList());
128 $this->filterWidget->update();
129 }
130 }
131 }
133 // Act on edit requests
134 $this->filterWidget->save_object();
135 $action = $this->filterWidget->getAction();
136 if($action['action'] == 'edit' && count($action['targets']) == 1){
137 $key= $this->filterWidget->getKey($action['targets'][0]);
138 if(isset($this->filters[$key])){
139 $this->dialog=new userFilterEditor($this->filters[$key], $this->availableCategories);
140 }
141 }
143 // Act on new requests
144 if(isset($_POST['addFilter'])){
145 $this->dialog=new userFilterEditor(array(), $this->availableCategories);
146 }
148 // Act on remove requests
149 $action = $this->filterWidget->getAction();
150 if($action['action'] == 'delete' && count($action['targets']) == 1){
151 $key= $this->filterWidget->getKey($action['targets'][0]);
152 if(isset($this->filters[$key])){
153 unset($this->filters[$key]);
154 $this->filterWidget->update();
155 }
156 }
158 // Display edit dialog
159 if($this->dialog instanceOf userFilterEditor){
160 $this->dialog->save_object();
161 return($this->dialog->execute());
162 }
164 $smarty = get_smarty();
165 $smarty->assign("list", $this->filterWidget->render());
166 return($smarty->fetch(get_template_path('userFilter.tpl', FALSE)));
167 }
170 /*! \brief Write user-filter modifications back to the ldap.
171 */
172 function save()
173 {
174 // Build up new list of filters
175 $attrs = array();
176 foreach($this->filters as $filter){
177 $tmp = implode(',', $filter['categories']).";";
178 $tmp.= $filter['name'].";";
179 $tmp.= base64_encode($filter['description']).";";
180 $tmp.= base64_encode($filter['filter']).";";
181 $tmp.= implode(',', $filter['flags']);
182 $attrs[] = $tmp;
183 }
184 $this->gosaUserDefinedFilter = $attrs;
186 plugin::save();
188 $ldap = $this->config->get_ldap_link();
189 $ldap->cd($this->dn);
190 $ldap->modify($this->attrs);
192 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
194 if (!$ldap->success()){
195 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MODIFY, get_class()));
196 }
197 }
200 /*! \brief Do not save any posted values here.
201 */
202 function save_object(){}
203 }
205 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
206 ?>