Code

6fdb361eac6a57ca547fb0a1d7868e8fdd0fc940
[gosa.git] / gosa-plugins / goto / admin / groups / apps / class_groupApplication2.inc
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();
30     $ldap = $this->config->get_ldap_link();
31     $ldap->cd($this->dn);
32     $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*"));
33     $parent_id = 0;
34     while($attrs = $ldap->fetch()){
35       $cur = &$this->a_Structure;
36       $sub_dn       = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
37       $sub_dn_array = split("\,",$sub_dn);
39       for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
40         
41         $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]);
44         if($i != 0){
45           foreach($cur as $key => $entry){
46             if($entry['NAME'] == $name){
47               $cur = &$cur[$key]['ENTRIES'];
48               $parent_id = $entry['UNIQID'];
49             }
50           }
51         }else{
53           $priority = -1;
54           if(isset($attrs['gosaApplicationPriority'])){
55             $priority= $attrs['gosaApplicationPriority'][0];
56           }
57           while(isset($cur[$priority])){
58             $priority ++;
59           }
61           if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){
62             $type = "FOLDER";
63           }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
64             $type = "ENTRY";
65           }elseif(in_array("FAIbranch",$attrs['objectClass'])){
66             $type = "RELEASE";
67           }
69           $data = array();
70           $data['DN']       = $attrs['dn'];
71           $data['NAME']     = $name;
72           $data['TYPE']     = $type;
73           $data['PRIORITY'] = $priority;
74           $data['ENTRIES']  = array();
75           $data['UNIQID']   = uniqid();
76           $data['PARENT']   = $parent_id;
77           $cur[$priority]   = $data;
78           ksort($cur);
79         }
80       }
81     }
82   } 
85   function execute()
86   {
87     /* Call parent execute */
88     plugin::execute();
90     if(isset($_GET['r']))
91     $this->__construct($this->config,$this->dn);
93     $smarty = get_smarty();
94     $smarty->assign("entries",$this->_get_all_entries(TRUE));
95     $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
96     return($display);
97   }
100   function _remove_entry_id($id,$start = NULL)
101   {
102     if($start == NULL){
103       $start = &$this->a_Structure;
104     }
105     foreach($start as $name => $entry){
106       if($entry['UNIQID'] == $id){
107         unset($start[$name]);
108         return(TRUE);
109       }
110       if(isset($entry['ENTRIES']) && count($start[$name]['ENTRIES'])){
111         if($this->_remove_entry_id($id,&$start[$name]['ENTRIES'])){
112           return(TRUE);
113         }
114       }
115     }
116     return(FALSE);
117   }
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   }
152   
153   function _edit_entry_edit($id)
154   {
155   }
158   function __switch_entries($from,$type,$to)
159   {
160     $all = $this->_get_all_entries();
162     $o_to   = &$all[$to];
163     $o_from = &$all[$from];
165     /* Move into next folder */
166     if(in_array($o_to['TYPE'],array("FOLDER","RELEASE"))){
168       /* Check if we are already in this folder */
169       if($to == $o_from['PARENT']){
170  
171         /* Check if there if we are a subfolder */
172         $o_to_sub = &$all[$o_to['PARENT']]; 
173         if(in_array($o_to_sub['TYPE'],array("FOLDER","RELEASE"))){
175           /* Removing old */
176           $tmp = array();
177           foreach($o_to['ENTRIES'] as $key => $entry){
178             if($entry['UNIQID'] == $from){
179               $this->_remove_entry_id($from);
180             }
181           }
183           /* Adding new */
184           $tmp2 = array();
185           foreach($o_to_sub['ENTRIES'] as $key => $entry){
187             if($type == "up"){
188               if($entry['UNIQID'] == $to){
189                 $o_from['PARENT'] = $o_to_sub['UNIQID'];
190                 $tmp2[] = &$o_from;
191               }
192               $tmp2[] = &$o_to_sub['ENTRIES'][$key];
193             }else{
195               $tmp2[] = &$o_to_sub['ENTRIES'][$key];
196               if($entry['UNIQID'] == $to){
197                 $o_from['PARENT'] = $o_to_sub['UNIQID'];
198                 $tmp2[] = &$o_from;
199               }
200             }
201           }
202       
203           $all[$o_to_sub['UNIQID']]['ENTRIES'] = $tmp2;
204         } 
205       }else{
207         /* Check if we want to move into ourselfs */
208         if($to == $from && $o_from['TYPE'] == "FOLDER"){
209         }else{
211           /* Removing old */
212           $o_to   = &$all[$to];
213           $o_from = &$all[$from];
214           $tmp = array();
215           $this->_remove_entry_id($from);
216           $o_from['PARENT'] = $to;
217           $o_to['ENTRIES'][]   = $o_from;
218           
219         }
220       }
221     }else{
222       $o_to   = &$all[$to];
223       $o_from = &$all[$from];
225       if($o_to['PARENT'] == $o_from['PARENT']){
226         $tmp = $all[$to];
227         $all[$to]   = $o_from;
228         $all[$from] = $tmp;
229       }
230     }
231   }
234   function _move_entry_up($id)
235   {
236     $all = $this->_get_all_entries(TRUE);
237     $parent = FALSE;
238     foreach($all as $entry){
239       if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
240         if($parent != FALSE){
241           $this->__switch_entries($id,"up",$parent);
242           return;
243         }
244       }else{
245         if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
246           $parent = $entry['PARENT'];
247         }else{
248           $parent = $entry['UNIQID'];
249         }
250       }
251     }
252   }
255   function _move_entry_down($id)
256   {
257     $all = $this->_get_all_entries(TRUE);
258     $found = FALSE;
259     foreach($all as $entry){
260       if(isset($entry['UNIQID']) && $entry['UNIQID'] == $id){
261         $found = TRUE;
262         continue;
263       }else{
264         if(in_array($entry['TYPE'],array("CLOSE","OPEN"))){
265           $parent = $entry['PARENT'];
266         }else{
267           $parent = $entry['UNIQID'];
268         }
269         if($found){
270           $this->__switch_entries($id,"down",$parent);
271           return;
272         }
273       }
274     }
275   }
278    
279   function _get_all_entries($add_tags = FALSE,$cur = NULL,$depth = 0)
280   {
281     $ret = array();
282     $depth ++;
283     if($cur == NULL){
284       $cur = &$this->a_Structure;
285     }
286     foreach($cur as $key => $entry){
288       $tmp = $entry;
289       if(!$add_tags){
290         $ret[$tmp['UNIQID']] = &$cur[$key];
291         if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
292           $ret = array_merge($ret,$this->_get_all_entries($add_tags,&$cur[$key]['ENTRIES'],$depth));
293         }
294       }else{
295       if(isset($tmp['ENTRIES'])){
296         unset($tmp['ENTRIES']);
297       }
298         $ret[] = $tmp;
299         if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
300           $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']);
301           $ret = array_merge($ret,$this->_get_all_entries($add_tags,&$cur[$key]['ENTRIES'],$depth));
302           $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']);
303         }
304       }
305     }
306     return($ret);
307   }
310   function remove_from_parent()
311   {
312   }
315   function save()
316   {
317   }
320   function check()
321   {
322   }
326   function PrepareForCopyPaste($source)
327   {
328   }
331   /* Return plugin informations for acl handling  */ 
332   static function plInfo()
333   {
334     return (array(
335           "plShortName"   => _("Applications"),
336           "plDescription" => _("Group applications"),
337           "plSelfModify"  => FALSE,
338           "plDepends"     => array(),
339           "plPriority"    => 0,
340           "plSection"     => array("admin"),
341           "plCategory"    => array("groups"),
342           "plProvidedAcls"=> array(
343             "gosaMemberApplication"     => _("Application"),
344             "FAIrelease"                => _("Release"),
345             "gosaApplicationParameter"  => _("Application parameter"))
346           ));
347   }
350   function multiple_save_object()
351   {
352     if(isset($_POST['group_apps_multi'])){
353       $this->save_object(); 
354       plugin::multiple_save_object();    
355   
356       /* Get posts */
357       foreach(array("apps") as $attr){
358         if(isset($_POST['use_'.$attr])) {
359           $this->multi_boxes[] = $attr;
360         }
361       }
362     }
363   }
364   
365   function multiple_execute()
366   {
367     return($this->execute());
368   }
370   function init_multiple_support($attrs,$all)
371   {
372     // Do nothing here
373   }
375   function get_multi_edit_values()
376   {
377     $ret = plugin::get_multi_edit_values();
379     if(in_array("apps",$this->multi_boxes)){
380       $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
381       $ret['Categories']               = $this->Categories;
382       $ret['gosaMemberApplication']    = $this->gosaMemberApplication;
383       $ret['FAIrelease']               = $this->FAIrelease;
384       $ret['appoption']                = $this->appoption;
385     }
386     return($ret);
387   }
389 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
390 ?>