Code

Updated application modifikations
[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();
16   var $a_Releases = array();
17   var $a_Entries  = array();
18   var $a_Folders  = array();
22   public function __construct(&$config, $dn= NULL, $parent= NULL)
23   {
24     plugin::plugin($config,$dn,$parent);
25     $this->dn = $dn; 
26     $this->_load_menu_structure();
27   }
30   function _load_menu_structure()
31   {
32     $this->a_Structure  = array();
33     $this->a_Releases   = array();
34     $this->a_Entries    = array();
35     $this->a_Folders    = array();
37     $ldap = $this->config->get_ldap_link();
38     $ldap->cd($this->dn);
39     $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*"));
40     while($attrs = $ldap->fetch()){
41       $cur = &$this->a_Structure;
42       $sub_dn       = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
43       $sub_dn_array = split("\,",$sub_dn);
45       for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
46         
47         $name = preg_replace("/^ou=/","",$sub_dn_array[$i]);
48         if($i != 0){
49           $cur = &$cur[$name]['ENTRIES'];
50         }else{
52           $priority = -1;
53           if(isset($attrs['gosaApplicationPriority'])){
54             $priority= $attrs['gosaApplicationPriority'][0];
55           }
57           if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){
58             $type = "FOLDER";
59           }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
60             $type = "ENTRY";
61           }elseif(in_array("FAIbranch",$attrs['objectClass'])){
62             $type = "RELEASE";
63           }
65           $data = array();
66           $data['DN']       = $attrs['dn'];
67           $data['NAME']     = $name;
68           $data['TYPE']     = $type;
69           $data['PRIORITY'] = $priority;
70           $data['ENTRIES']  = array();
71           $data['UNIQID']   = uniqid();
72           $cur[$name]       = $data;
74           switch($type){
75             case 'RELEASE': $this->a_Releases[$name] = &$cur[$name];break;
76             case 'ENTRY':   $this->a_Entries[$name] = &$cur[$name];break;
77             case 'FOLDER':  $this->a_Folders[$name] = &$cur[$name];break;
78           }
79         }
80       }
81     }
82   } 
85   function execute()
86   {
87     /* Call parent execute */
88     plugin::execute();
91 #    $this->__construct($this->config, $this->dn,NULL);
92     $smarty = get_smarty();
93     $smarty->assign("entries",$this->_get_all_entries());
94     $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
95     return($display);
96   }
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   }
119   
120   function save_object()
121   {
122     foreach($_POST as $name => $value){
123       if(preg_match("/del_/",$name)){
124         $id = preg_replace("/^del_/","",$name);
125         $id = preg_replace("/_(x|y)$/","",$id);
126         $this->_remove_entry_id($id);
127         break;
128       }
129       if(preg_match("/edit_/",$name)){
130         $id = preg_replace("/^del_/","",$name);
131         $id = preg_replace("/_(x|y)$/","",$id);
132         $this->_edit_entry_edit($id);
133         break;
134       }
135       if(preg_match("/up_/",$name)){
136         $id = preg_replace("/^del_/","",$name);
137         $id = preg_replace("/_(x|y)$/","",$id);
138         $this->_move_entry_up($id);
139         break;
140       }
141       if(preg_match("/down_/",$name)){
142         $id = preg_replace("/^del_/","",$name);
143         $id = preg_replace("/_(x|y)$/","",$id);
144         $this->_move_entry_down($id);
145         break;
146       }
147     }
148   }
150   
151   function _edit_entry_edit($id)
152   {
153     echo "Editing: ".$id;
154   }
156   function _move_entry_up($id)
157   {
158     echo "Up: ".$id;
159   }
161   function _move_entry_down($id)
162   {
163     echo "Down: ".$id;
164   }
167   function _get_all_entries($cur = NULL,$depth = 0)
168   {
169     $ret = array();
170     $depth ++;
171     if($cur == NULL){
172       $cur = &$this->a_Structure;
173     }
174     $ret[] = array("TYPE" => "OPEN");
175     foreach($cur as $entry){
176       $tmp = $entry;
177       if(isset($tmp['ENTRIES'])){
178         unset($tmp['ENTRIES']);
179       }
180       $ret[] = $tmp;
181       if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
182         $ret = array_merge($ret,$this->_get_all_entries(&$entry['ENTRIES'],$depth));
183       }
184     }
185     $ret[] = array("TYPE" => "CLOSE");
186     return($ret);
187   } 
188  
190   function remove_from_parent()
191   {
192   }
195   function save()
196   {
197   }
200   function check()
201   {
202   }
206   function PrepareForCopyPaste($source)
207   {
208   }
211   /* Return plugin informations for acl handling  */ 
212   static function plInfo()
213   {
214     return (array(
215           "plShortName"   => _("Applications"),
216           "plDescription" => _("Group applications"),
217           "plSelfModify"  => FALSE,
218           "plDepends"     => array(),
219           "plPriority"    => 0,
220           "plSection"     => array("admin"),
221           "plCategory"    => array("groups"),
222           "plProvidedAcls"=> array(
223             "gosaMemberApplication"     => _("Application"),
224             "FAIrelease"                => _("Release"),
225             "gosaApplicationParameter"  => _("Application parameter"))
226           ));
227   }
230   function multiple_save_object()
231   {
232     if(isset($_POST['group_apps_multi'])){
233       $this->save_object(); 
234       plugin::multiple_save_object();    
235   
236       /* Get posts */
237       foreach(array("apps") as $attr){
238         if(isset($_POST['use_'.$attr])) {
239           $this->multi_boxes[] = $attr;
240         }
241       }
242     }
243   }
244   
245   function multiple_execute()
246   {
247     return($this->execute());
248   }
250   function init_multiple_support($attrs,$all)
251   {
252     // Do nothing here
253   }
255   function get_multi_edit_values()
256   {
257     $ret = plugin::get_multi_edit_values();
259     if(in_array("apps",$this->multi_boxes)){
260       $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
261       $ret['Categories']               = $this->Categories;
262       $ret['gosaMemberApplication']    = $this->gosaMemberApplication;
263       $ret['FAIrelease']               = $this->FAIrelease;
264       $ret['appoption']                = $this->appoption;
265     }
266     return($ret);
267   }
269 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
270 ?>