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