Unnecesary direct access to user setting superseded by calls to user_* functions.
[fa-stable.git] / themes / default / renderer.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
13         class renderer
14         {
15                 function get_icon($category)
16                 {
17                         global  $path_to_root, $SysPrefs;
18
19                         if ($SysPrefs->show_menu_category_icons)
20                                 $img = $category == '' ? 'right.gif' : $category.'.png';
21                         else    
22                                 $img = 'right.gif';
23                         return "<img src='$path_to_root/themes/default/images/$img' style='vertical-align:middle;' border='0'>&nbsp;&nbsp;";
24                 }
25
26                 function wa_header()
27                 {
28                         page(_($help_context = "Main Menu"), false, true);
29                 }
30
31                 function wa_footer()
32                 {
33                         end_page(false, true);
34                 }
35
36                 function menu_header($title, $no_menu, $is_index)
37                 {
38                         global $path_to_root, $SysPrefs, $db_connections;
39                         echo "<table class='callout_main' border='0' cellpadding='0' cellspacing='0'>\n";
40                         echo "<tr>\n";
41                         echo "<td colspan='2' rowspan='2'>\n";
42
43                         echo "<table class='main_page' border='0' cellpadding='0' cellspacing='0'>\n";
44                         echo "<tr>\n";
45                         echo "<td>\n";
46                         echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
47                         echo "<tr>\n";
48                         echo "<td class='quick_menu'>\n"; // tabs
49                         if (!$no_menu)
50                         {
51                                 $applications = $_SESSION['App']->applications;
52                                 $local_path_to_root = $path_to_root;
53                                 $sel_app = $_SESSION['sel_app'];
54                                 echo "<table cellpadding=0 cellspacing=0 width='100%'><tr><td>";
55                                 echo "<div class=tabs>";
56                                 foreach($applications as $app)
57                                 {
58                     if ($_SESSION["wa_current_user"]->check_application_access($app))
59                     {
60                         $acc = access_string($app->name);
61                         echo "<a class='".($sel_app == $app->id ? 'selected' : 'menu_tab')
62                             ."' href='$local_path_to_root/index.php?application=".$app->id
63                             ."'$acc[1]>" .$acc[0] . "</a>";
64                     }
65                                 }
66                                 echo "</div>";
67                                 echo "</td></tr></table>";
68
69                                 // top status bar
70                                 $img = "<img src='$local_path_to_root/themes/default/images/login.gif' width='14' height='14' border='0' alt='"._('Logout')."'>&nbsp;&nbsp;";
71                                 $himg = "<img src='$local_path_to_root/themes/default/images/help.gif' width='14' height='14' border='0' alt='"._('Help')."'>&nbsp;&nbsp;";
72                                 echo "<table class=logoutBar>";
73                                 echo "<tr><td class=headingtext3>" . $db_connections[user_company()]["name"] . " | " . $_SERVER['SERVER_NAME'] . " | " . $_SESSION["wa_current_user"]->name . "</td>";
74                                 $indicator = "$path_to_root/themes/".user_theme(). "/images/ajax-loader.gif";
75                                 echo "<td class='logoutBarRight'><img id='ajaxmark' src='$indicator' align='center' style='visibility:hidden;'></td>";
76                                 echo "  <td class='logoutBarRight'><a class='shortcut' href='$path_to_root/admin/display_prefs.php?'>" . _("Preferences") . "</a>&nbsp;&nbsp;&nbsp;\n";
77                                 echo "  <a class='shortcut' href='$path_to_root/admin/change_current_user_password.php?selected_id=" . $_SESSION["wa_current_user"]->username . "'>" . _("Change password") . "</a>&nbsp;&nbsp;&nbsp;\n";
78
79                                 if ($SysPrefs->help_base_url != null)
80                                 {
81                                         echo "$himg<a target = '_blank' onclick=" .'"'."javascript:openWindow(this.href,this.target); return false;".'" '. "href='". help_url()."'>" . _("Help") . "</a>&nbsp;&nbsp;&nbsp;";
82                                 }
83                                 echo "$img<a class='shortcut' href='$local_path_to_root/access/logout.php?'>" . _("Logout") . "</a>&nbsp;&nbsp;&nbsp;";
84                                 echo "</td></tr><tr><td colspan=3>";
85                                 echo "</td></tr></table>";
86                         }
87                         echo "</td></tr></table>";
88
89                         if ($no_menu)
90                                 echo "<br>";
91                         elseif ($title && !$is_index)
92                         {
93                                 echo "<center><table id='title'><tr><td width='100%' class='titletext'>$title</td>"
94                                 ."<td align=right>"
95                                 .(user_hints() ? "<span id='hints'></span>" : '')
96                                 ."</td>"
97                                 ."</tr></table></center>";
98                         }
99                 }
100
101                 function menu_footer($no_menu, $is_index)
102                 {
103                         global $version, $path_to_root, $Pagehelp, $Ajax, $SysPrefs;
104                         include_once($path_to_root . "/includes/date_functions.inc");
105
106                         echo "</td></tr></table>\n"; // 'main_page'
107                         if ($no_menu == false) // bottom status line
108                         {
109                                 if ($is_index)
110                                         echo "<table class=bottomBar>\n";
111                                 else
112                                         echo "<table class=bottomBar2>\n";
113                                 echo "<tr>";
114                                 if (isset($_SESSION['wa_current_user'])) {
115                                         $phelp = implode('; ', $Pagehelp);
116                                         echo "<td class=bottomBarCell>" . Today() . " | " . Now() . "</td>\n";
117                                         $Ajax->addUpdate(true, 'hotkeyshelp', $phelp);
118                                         echo "<td id='hotkeyshelp'>".$phelp."</td>";
119                                 }
120                                 echo "</td></tr></table>\n";
121                         }
122                         echo "</td></tr> </table>\n"; // 'callout_main'
123                         echo "</table>\n";
124                         if ($no_menu == false)
125                         {
126                                 echo "<table align='center' id='footer'>\n";
127                                 echo "<tr>\n";
128                                 echo "<td align='center' class='footer'><a target='_blank' href='".$SysPrefs->power_url."' tabindex='-1'><font color='#ffffff'>".$SysPrefs->app_title
129                                         ." $version - " . _("Theme:") . " " . user_theme() . " - ".show_users_online()."</font></a></td>\n";
130                                 echo "</tr>\n";
131                                 echo "<tr>\n";
132                                 echo "<td align='center' class='footer'><a target='_blank' href='".$SysPrefs->power_url
133                                         ."' tabindex='-1'><font color='#ffff00'>".$SysPrefs->power_by."</font></a></td>\n";
134                                 echo "</tr>\n";
135                                 echo "</table><br><br>\n";
136                         }
137                 }
138
139                 function display_applications(&$waapp)
140                 {
141                         global $path_to_root;
142
143                         $selected_app = $waapp->get_selected_application();
144                         if (!$_SESSION["wa_current_user"]->check_application_access($selected_app))
145                                 return;
146
147                         if (method_exists($selected_app, 'render_index'))
148                         {
149                                 $selected_app->render_index();
150                                 return;
151                         }
152
153                         echo "<table width=100% cellpadding='0' cellspacing='0'>";
154                         foreach ($selected_app->modules as $module)
155                         {
156                         if (!$_SESSION["wa_current_user"]->check_module_access($module))
157                                 continue;
158                                 // image
159                                 echo "<tr>";
160                                 // values
161                                 echo "<td valign='top' class='menu_group'>";
162                                 echo "<table border=0 width='100%'>";
163                                 echo "<tr><td class='menu_group'>";
164                                 echo $module->name;
165                                 echo "</td></tr><tr>";
166                                 echo "<td class='menu_group_items'>";
167
168                                 foreach ($module->lappfunctions as $appfunction)
169                                 {
170                                         $img = $this->get_icon($appfunction->category);
171                                         if ($appfunction->label == "")
172                                                 echo "&nbsp;<br>";
173                                         elseif ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) 
174                                         {
175                                                         echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
176                                         }
177                                         elseif (!$_SESSION["wa_current_user"]->hide_inaccessible_menu_items())
178                                         {
179                                                         echo $img.'<span class="inactive">'
180                                                                 .access_string($appfunction->label, true)
181                                                                 ."</span><br>\n";
182                                         }
183                                 }
184                                 echo "</td>";
185                                 if (sizeof($module->rappfunctions) > 0)
186                                 {
187                                         echo "<td width='50%' class='menu_group_items'>";
188                                         foreach ($module->rappfunctions as $appfunction)
189                                         {
190                                                 $img = $this->get_icon($appfunction->category);
191                                                 if ($appfunction->label == "")
192                                                         echo "&nbsp;<br>";
193                                                 elseif ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) 
194                                                 {
195                                                                 echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
196                                                 }
197                                                 elseif (!$_SESSION["wa_current_user"]->hide_inaccessible_menu_items())
198                                                 {
199                                                                 echo $img.'<span class="inactive">'
200                                                                         .access_string($appfunction->label, true)
201                                                                         ."</span><br>\n";
202                                                 }
203                                         }
204                                         echo "</td>";
205                                 }
206
207                                 echo "</tr></table></td></tr>";
208                         }
209                         echo "</table>";
210         }
211 }