Update from usntable branch.
[fa-stable.git] / frontaccounting.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 if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
13         die("Restricted access");
14         include_once($path_to_root . '/applications/application.php');
15         include_once($path_to_root . '/applications/customers.php');
16         include_once($path_to_root . '/applications/suppliers.php');
17         include_once($path_to_root . '/applications/inventory.php');
18         include_once($path_to_root . '/applications/manufacturing.php');
19         include_once($path_to_root . '/applications/dimensions.php');
20         include_once($path_to_root . '/applications/generalledger.php');
21         include_once($path_to_root . '/applications/setup.php');
22         include_once($path_to_root . '/installed_extensions.php');
23         if (count($installed_extensions) > 0)
24         {
25                 foreach ($installed_extensions as $ext)
26                 {
27                         if ($ext['type'] == 'module')
28                                 include_once($path_to_root."/".$ext['path']."/".$ext['filename']);
29                 }
30         }       
31
32         class front_accounting
33                 {
34                 var $user;
35                 var $settings;
36                 var $applications;
37                 var $selected_application;
38                 // GUI
39                 var $menu;
40                 //var $renderer;
41                 function front_accounting()
42                 {
43                         //$this->renderer =& new renderer();
44                 }
45                 function add_application(&$app)
46                                 {       
47                                         if ($app->enabled) // skip inactive modules
48                                                 $this->applications[$app->id] = &$app;
49                                 }
50                 function get_application($id)
51                                 {
52                                  if (isset($this->applications[$id]))
53                                         return $this->applications[$id];
54                                  return null;
55                                 }
56                 function get_selected_application()
57                 {
58                         if (isset($this->selected_application))
59                                  return $this->applications[$this->selected_application];
60                         foreach ($this->applications as $application)
61                                 return $application;
62                         return null;
63                 }
64                 function display()
65                 {
66                         global $path_to_root;
67                         include($path_to_root . "/themes/".user_theme()."/renderer.php");
68                         $this->init();
69                         $rend = new renderer();
70                         $rend->wa_header();
71                         //$rend->menu_header($this->menu);
72                         $rend->display_applications($this);
73                         //$rend->menu_footer($this->menu);
74                         $rend->wa_footer();
75                 }
76                 function init()
77                 {
78                         global $installed_extensions, $path_to_root;
79
80                         $this->menu = new menu(_("Main  Menu"));
81                         $this->menu->add_item(_("Main  Menu"), "index.php");
82                         $this->menu->add_item(_("Logout"), "/account/access/logout.php");
83                         $this->applications = array();
84                         $this->add_application(new customers_app());
85                         $this->add_application(new suppliers_app());
86                         $this->add_application(new inventory_app());
87                         $this->add_application(new manufacturing_app());
88                         $this->add_application(new dimensions_app());
89                         $this->add_application(new general_ledger_app());
90                         if (count($installed_extensions) > 0)
91                         {
92                                 // Do not use global array directly here, or you suffer 
93                                 // from buggy php behaviour (unexpected loop break 
94                                 // because of same var usage in class constructor).
95                                 $extensions = $installed_extensions;
96                                 foreach ($extensions as $ext)
97                                 {
98                                         if (@($ext['active'] && $ext['type'] == 'module')) // supressed warnings before 2.2 upgrade
99                                         { 
100                                                 $_SESSION['get_text']->add_domain($_SESSION['language']->code, 
101                                                         $ext['path']."/lang");
102                                                 $class = $ext['tab']."_app";
103                                                 if (class_exists($class))
104                                                         $this->add_application(new $class());
105                                                 $_SESSION['get_text']->add_domain($_SESSION['language']->code, 
106                                                         $path_to_root."/lang");
107                                         }
108                                 }
109                         }       
110                         
111                         $this->add_application(new setup_app());
112                 }
113 }
114 ?>