8e9d263216c9ec7d571352356a6a82a5da0b5a24
1 <?php
2 class appgroup2 extends plugin
3 {
4 /* CLI vars */
5 var $cli_summary= "Manage application groups";
6 var $cli_description= "Some longer text\nfor help";
7 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 var $config;
12 /* Contains the menu structure in an array.
13 */
14 var $a_Structure= array();
15 var $a_Structure_on_load = array();
17 public function __construct(&$config, $dn= NULL, $parent= NULL)
18 {
19 plugin::plugin($config,$dn,$parent);
20 $this->dn = $dn;
21 $this->_load_menu_structure();
22 $this->a_Structure_on_load = $this->a_Structure;
23 }
26 function _load_menu_structure()
27 {
28 $this->a_Structure = array();
29 $ldap = $this->config->get_ldap_link();
30 $ldap->cd($this->dn);
31 $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*"));
32 $parent_id = 0;
33 while($attrs = $ldap->fetch()){
34 $cur = &$this->a_Structure;
35 $sub_dn = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
36 $sub_dn_array = split("\,",$sub_dn);
37 for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
38 $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]);
39 if($i != 0){
40 foreach($cur as $key => $entry){
41 if($entry['NAME'] == $name){
42 $cur = &$cur[$key]['ENTRIES'];
43 $parent_id = $entry['UNIQID'];
44 }
45 }
46 }else{
48 $priority = -1;
49 if(isset($attrs['gosaApplicationPriority'])){
50 $priority= $attrs['gosaApplicationPriority'][0];
51 }
52 while(isset($cur[$priority])){
53 $priority ++;
54 }
56 if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){
57 $type = "FOLDER";
58 }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
59 $type = "ENTRY";
60 }elseif(in_array("FAIbranch",$attrs['objectClass'])){
61 $type = "RELEASE";
62 }
64 $data = array();
65 $data['DN'] = $attrs['dn'];
66 $data['NAME'] = $name;
67 $data['TYPE'] = $type;
68 $data['PRIORITY'] = $priority;
69 $data['ENTRIES'] = array();
70 $data['UNIQID'] = uniqid();
71 $data['PARENT'] = $parent_id;
72 $cur[$priority] = $data;
73 ksort($cur);
74 }
75 }
76 }
77 }
80 function execute()
81 {
82 /* Call parent execute */
83 plugin::execute();
85 if(isset($_GET['r']))
86 $this->__construct($this->config,$this->dn);
88 $smarty = get_smarty();
89 $smarty->assign("entries",$this->_get_all_entries(TRUE));
90 $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
91 return($display);
92 }
95 /* !\brief Remove the given id from the menu structure.
96 @param String ID to of the entry we want to remove.
97 @return Boolean TRUE on success
98 */
99 function _remove_entry_id($id,$start = NULL)
100 {
101 if($start == NULL){
102 $start = &$this->a_Structure;
103 }
104 foreach($start as $name => $entry){
105 if($entry['UNIQID'] == $id){
106 unset($start[$name]);
107 return(TRUE);
108 }
109 if(isset($entry['ENTRIES']) && count($start[$name]['ENTRIES'])){
110 if($this->_remove_entry_id($id,&$start[$name]['ENTRIES'])){
111 return(TRUE);
112 }
113 }
114 }
115 return(FALSE);
116 }
120 /* !\brief Handle ui POSTS, like sort up/down/delete
121 */
122 function save_object()
123 {
124 foreach($_POST as $name => $value){
125 if(preg_match("/del_/",$name)){
126 $id = preg_replace("/^del_/","",$name);
127 $id = preg_replace("/_(x|y)$/","",$id);
128 $this->_remove_entry_id($id);
129 break;
130 }
131 if(preg_match("/edit_/",$name)){
132 $id = preg_replace("/^edit_/","",$name);
133 $id = preg_replace("/_(x|y)$/","",$id);
134 $this->_edit_entry_edit($id);
135 break;
136 }
137 if(preg_match("/up_/",$name)){
138 $id = preg_replace("/^up_/","",$name);
139 $id = preg_replace("/_(x|y)$/","",$id);
140 $this->_move_entry_up($id);
141 break;
142 }
143 if(preg_match("/down_/",$name)){
144 $id = preg_replace("/^down_/","",$name);
145 $id = preg_replace("/_(x|y)$/","",$id);
146 $this->_move_entry_down($id);
147 break;
148 }
149 }
150 }
153 function _edit_entry_edit($id)
154 {
155 }
158 /* !\brief Switch one entry with another
159 @param String from The source ID.
160 @param String type "up"/"down" type switched.
161 @param String to The destination ID.
162 return Boolean TRUE on success
163 */
164 function __switch_entries($from,$type,$to)
165 {
166 $all = $this->_get_all_entries();
168 $o_to = &$all[$to];
169 $o_from = &$all[$from];
171 /***********************
172 * Source == Destination
173 * Move into next parent.
174 ************************/
175 if($to == $from){
176 $to = $o_to['PARENT'];
177 $o_to = &$all[$to];
178 }
180 /***********************
181 * Target is container
182 ************************/
183 if(in_array($o_to['TYPE'],array("FOLDER","RELEASE"))){
185 /***********************
186 * Move into parent folder
187 * + Target
188 * |-> Source
189 ************************/
190 if($to == $o_from['PARENT']){
192 /* Check if source is a folder object
193 */
194 $o_to_sub = &$all[$o_to['PARENT']];
195 if(in_array($o_to_sub['TYPE'],array("FOLDER","RELEASE"))){
197 /* Removing old */
198 $tmp = array();
199 foreach($o_to['ENTRIES'] as $key => $entry){
200 if($entry['UNIQID'] == $from){
201 if(!$this->_remove_entry_id($from)){
202 return(FALSE);
203 }
204 }
205 }
207 /* Adding new */
208 $tmp2 = array();
209 foreach($o_to_sub['ENTRIES'] as $key => $entry){
211 if($type == "up"){
212 if($entry['UNIQID'] == $to){
213 $o_from['PARENT'] = $o_to_sub['UNIQID'];
214 $tmp2[] = &$o_from;
215 }
216 $tmp2[] = &$o_to_sub['ENTRIES'][$key];
217 }else{
219 $tmp2[] = &$o_to_sub['ENTRIES'][$key];
220 if($entry['UNIQID'] == $to){
221 $o_from['PARENT'] = $o_to_sub['UNIQID'];
222 $tmp2[] = &$o_from;
223 }
224 }
225 }
226 $all[$o_to_sub['UNIQID']]['ENTRIES'] = $tmp2;
227 }
228 }else{
230 /***********************
231 * Target is NOT parent container
232 * + Parent Folder
233 * |-> Source
234 * + Destination
235 ************************/
237 /* Removing old */
238 $o_to = &$all[$to];
239 $o_from = &$all[$from];
240 $this->_remove_entry_id($from);
241 $o_from['PARENT'] = $to;
242 $o_to['ENTRIES'][] = $o_from;
244 }
245 }else{
247 /***********************
248 * Source and Destination in some Folder.
249 * + Parent folder
250 * |-> Source
251 * |-> Destination
252 ************************/
253 $o_to = &$all[$to];
254 $o_from = &$all[$from];
256 if($o_to['PARENT'] == $o_from['PARENT']){
257 $tmp = $all[$to];
258 $all[$to] = $o_from;
259 $all[$from] = $tmp;
260 }
261 }
262 }
265 function _move_entry_up($id)
266 {
267 $all = $this->_get_all_entries(TRUE);
268 $parent = FALSE;
269 foreach($all as $entry){
270 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
271 if($parent != FALSE){
272 $this->__switch_entries($id,"up",$parent);
273 return;
274 }
275 }else{
276 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
277 $parent = $entry['PARENT'];
278 }else{
279 $parent = $entry['UNIQID'];
280 }
281 }
282 }
283 }
286 function _move_entry_down($id)
287 {
288 $all = $this->_get_all_entries(TRUE);
289 $found = FALSE;
290 foreach($all as $entry){
291 if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
292 $found = TRUE;
293 continue;
294 }else{
295 if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
296 $parent = $entry['PARENT'];
297 }else{
298 $parent = $entry['UNIQID'];
299 }
300 if($found){
301 $this->__switch_entries($id,"down",$parent);
302 return;
303 }
304 }
305 }
306 }
310 function _get_all_entries($add_tags = FALSE,$cur = NULL,$depth = 0)
311 {
312 $ret = array();
313 $depth ++;
314 if($cur == NULL){
315 $cur = &$this->a_Structure;
316 }
317 foreach($cur as $key => $entry){
319 $tmp = $entry;
320 if(!$add_tags){
321 $ret[$tmp['UNIQID']] = &$cur[$key];
322 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
323 $ret = array_merge($ret,$this->_get_all_entries($add_tags,&$cur[$key]['ENTRIES'],$depth));
324 }
325 }else{
326 if(isset($tmp['ENTRIES'])){
327 unset($tmp['ENTRIES']);
328 }
329 $ret[] = $tmp;
330 if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
331 $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']);
332 $ret = array_merge($ret,$this->_get_all_entries($add_tags,&$cur[$key]['ENTRIES'],$depth));
333 $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']);
334 }
335 }
336 }
337 return($ret);
338 }
341 function remove_from_parent()
342 {
343 }
346 function save()
347 {
348 }
351 function check()
352 {
353 }
357 function PrepareForCopyPaste($source)
358 {
359 }
362 /* Return plugin informations for acl handling */
363 static function plInfo()
364 {
365 return (array(
366 "plShortName" => _("Applications"),
367 "plDescription" => _("Group applications"),
368 "plSelfModify" => FALSE,
369 "plDepends" => array(),
370 "plPriority" => 0,
371 "plSection" => array("admin"),
372 "plCategory" => array("groups"),
373 "plProvidedAcls"=> array(
374 "gosaMemberApplication" => _("Application"),
375 "FAIrelease" => _("Release"),
376 "gosaApplicationParameter" => _("Application parameter"))
377 ));
378 }
381 function multiple_save_object()
382 {
383 if(isset($_POST['group_apps_multi'])){
384 $this->save_object();
385 plugin::multiple_save_object();
387 /* Get posts */
388 foreach(array("apps") as $attr){
389 if(isset($_POST['use_'.$attr])) {
390 $this->multi_boxes[] = $attr;
391 }
392 }
393 }
394 }
396 function multiple_execute()
397 {
398 return($this->execute());
399 }
401 function init_multiple_support($attrs,$all)
402 {
403 // Do nothing here
404 }
406 function get_multi_edit_values()
407 {
408 $ret = plugin::get_multi_edit_values();
410 if(in_array("apps",$this->multi_boxes)){
411 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
412 $ret['Categories'] = $this->Categories;
413 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
414 $ret['FAIrelease'] = $this->FAIrelease;
415 $ret['appoption'] = $this->appoption;
416 }
417 return($ret);
418 }
419 }
420 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
421 ?>