Optimized extensions related code.
[fa-stable.git] / applications / application.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12         class menu_item 
13         {
14                 var $label;
15                 var $link;
16                 
17                 function menu_item($label, $link) 
18                 {
19                         $this->label = $label;
20                         $this->link = $link;
21                 }
22         }
23
24         class menu 
25         {
26                 var $title;
27                 var $items;
28                 
29                 function menu($title) 
30                 {
31                         $this->title = $title;
32                         $this->items = array();
33                 }
34                 
35                 function add_item($label, $link) 
36                 {
37                         $item = new menu_item($label,$link);
38                         array_push($this->items,$item);
39                         return $item;
40                 }
41                 
42         }
43
44         class app_function 
45         {
46                 var $label;
47                 var $link;
48                 var $access;
49                 
50                 function app_function($label,$link,$access='SA_OPEN') 
51                 {
52                         $this->label = $label;
53                         $this->link = $link;
54                         $this->access = $access;
55                 }
56         }
57
58         class module 
59         {
60                 var $name;
61                 var $icon;
62                 var $lappfunctions;
63                 var $rappfunctions;
64                 
65                 function module($name,$icon = null) 
66                 {
67                         $this->name = $name;
68                         $this->icon = $icon;
69                         $this->lappfunctions = array();
70                         $this->rappfunctions = array();
71                 }
72                 
73                 function add_lapp_function($label,$link="",$access='SA_OPEN') 
74                 {
75                         $appfunction = new app_function($label,$link,$access);
76                         //array_push($this->lappfunctions,$appfunction);
77                         $this->lappfunctions[] = $appfunction;
78                         return $appfunction;
79                 }
80
81                 function add_rapp_function($label,$link="",$access='SA_OPEN') 
82                 {
83                         $appfunction = new app_function($label,$link,$access);
84                         //array_push($this->rappfunctions,$appfunction);
85                         $this->rappfunctions[] = $appfunction;
86                         return $appfunction;
87                 }
88                 
89                 
90         }
91
92         class application 
93         {
94                 var $id;
95                 var $name;
96                 var $help_context;
97                 var $modules;
98                 var $enabled;
99                 
100                 function application($id, $name, $enabled=true) 
101                 {
102                         $this->id = $id;
103                         $this->name = $name;
104                         $this->enabled = $enabled;
105                         $this->modules = array();
106                 }
107                 
108                 function add_module($name, $icon = null) 
109                 {
110                         $module = new module($name,$icon);
111                         //array_push($this->modules,$module);
112                         $this->modules[] = $module;
113                         return $module;
114                 }
115                 
116                 function add_lapp_function($level, $label,$link="",$access='SA_OPEN') 
117                 {
118                         $this->modules[$level]->lappfunctions[] = new app_function($label, $link, $access);
119                 }
120                 
121                 function add_rapp_function($level, $label,$link="",$access='SA_OPEN') 
122                 {
123                         $this->modules[$level]->rappfunctions[] = new app_function($label, $link, $access);
124                 }
125                 
126                 function add_extensions()
127                 {
128                         global $installed_extensions, $path_to_root;
129
130                         foreach ($installed_extensions as $mod)
131                         {
132                                 if (@$mod['active'] && isset($mod['entries']))
133                                         foreach($mod['entries'] as $entry) {
134                                                 if ($entry['tab_id'] == $this->id)
135                                                         $this->add_rapp_function(
136                                                                 isset($entry['section']) ? $entry['section'] : 2,
137                                                                 $entry['title'], $path_to_root.'/'.$mod['path'].'/'.$entry['url'],
138                                                                 isset($entry["access"]) ? $entry["access"] : 'SA_OPEN' );
139                                         }
140                         }
141                 }
142                 //
143                 // Helper returning link to report class added by extension module.
144                 //
145                 function report_class_url($class)
146                 {
147                         global $installed_extensions;
148
149                         // TODO : konwencja lub ?
150                         $classno = 7;
151 //                      if (file_exists($path_to_root.'/'.$mod['path'].'/'.$entry['url']
152 //                                      .'/'.'reporting/reports_custom.php'))
153                                 return "reporting/reports_main.php?Class=".$class;
154 //                      else
155 //                              return '';
156                 }
157         }
158
159
160 ?>