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();
19 var $menu_pointer = NULL;
21 public function __construct(&$config, $dn= NULL, $parent= NULL)
22 {
23 plugin::plugin($config,$dn,$parent);
24 $this->dn = $dn;
25 $this->_load_menu_structure();
26 }
29 function _load_menu_structure()
30 {
31 $this->a_Structure = array();
32 $this->a_Releases = array();
33 $this->a_Entries = array();
34 $this->a_Folders = array();
36 $this->menu_pointer = &$this->a_Structure;
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 $date['ENTRIES'] = array();
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();
90 $this->__construct($this->config, $this->dn,NULL);
91 $smarty = get_smarty();
92 $smarty->assign("entries",$this->_get_all_entries());
93 $display= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
94 return($display);
95 }
98 function _get_all_entries($cur = NULL,$depth = 0)
99 {
100 $ret = array();
101 $depth ++;
102 if($cur == NULL){
103 $cur = &$this->a_Structure;
104 }
105 $ret[] = array("TYPE" => "OPEN");
106 foreach($cur as $entry){
107 $tmp = $entry;
108 if(isset($tmp['ENTRIES'])){
109 unset($tmp['ENTRIES']);
110 }
111 $ret[] = $tmp;
112 if(isset($entry['ENTRIES'])){
113 $ret = array_merge($ret,$this->_get_all_entries(&$entry['ENTRIES'],$depth));
114 }
115 }
116 $ret[] = array("TYPE" => "CLOSE");
117 return($ret);
118 }
121 function remove_from_parent()
122 {
123 }
126 function save()
127 {
128 }
131 function check()
132 {
133 }
137 function PrepareForCopyPaste($source)
138 {
139 }
142 /* Return plugin informations for acl handling */
143 static function plInfo()
144 {
145 return (array(
146 "plShortName" => _("Applications"),
147 "plDescription" => _("Group applications"),
148 "plSelfModify" => FALSE,
149 "plDepends" => array(),
150 "plPriority" => 0,
151 "plSection" => array("admin"),
152 "plCategory" => array("groups"),
153 "plProvidedAcls"=> array(
154 "gosaMemberApplication" => _("Application"),
155 "FAIrelease" => _("Release"),
156 "gosaApplicationParameter" => _("Application parameter"))
157 ));
158 }
161 function multiple_save_object()
162 {
163 if(isset($_POST['group_apps_multi'])){
164 $this->save_object();
165 plugin::multiple_save_object();
167 /* Get posts */
168 foreach(array("apps") as $attr){
169 if(isset($_POST['use_'.$attr])) {
170 $this->multi_boxes[] = $attr;
171 }
172 }
173 }
174 }
176 function multiple_execute()
177 {
178 return($this->execute());
179 }
181 function init_multiple_support($attrs,$all)
182 {
183 // Do nothing here
184 }
186 function get_multi_edit_values()
187 {
188 $ret = plugin::get_multi_edit_values();
190 if(in_array("apps",$this->multi_boxes)){
191 $ret['gosaApplicationParameter'] = $this->gosaApplicationParameter;
192 $ret['Categories'] = $this->Categories;
193 $ret['gosaMemberApplication'] = $this->gosaMemberApplication;
194 $ret['FAIrelease'] = $this->FAIrelease;
195 $ret['appoption'] = $this->appoption;
196 }
197 return($ret);
198 }
199 }
200 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
201 ?>