08d015abf77720543ab536995768f780b45cff2f
[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, $show_menu_category_icons;
18
19                         if ($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, $help_base_url, $db_connections, $show_inaccessible_menu_items;
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";
49                         if (!$no_menu)
50                         {
51                                 $applications = $_SESSION['App']->applications;
52                                 $local_path_to_root = $path_to_root;
53                                 $img = "<img src='$local_path_to_root/themes/default/images/login.gif' width='14' height='14' border='0' alt='"._('Logout')."'>&nbsp;&nbsp;";
54                                 $himg = "<img src='$local_path_to_root/themes/default/images/help.gif' width='14' height='14' border='0' alt='"._('Help')."'>&nbsp;&nbsp;";
55                                 $sel_app = $_SESSION['sel_app'];
56                                 echo "<table cellpadding=0 cellspacing=0 width='100%'><tr><td>";
57                                 echo "<div class=tabs>";
58                                 foreach($applications as $app)
59                                 {
60                     if ($this->check_application_access($app))
61                     {
62                         $acc = access_string($app->name);
63                         echo "<a class='".($sel_app == $app->id ? 'selected' : 'menu_tab')
64                             ."' href='$local_path_to_root/index.php?application=".$app->id
65                             ."'$acc[1]>" .$acc[0] . "</a>";
66                     }
67                                 }
68                                 echo "</div>";
69                                 echo "</td></tr></table>";
70
71                                 echo "<table class=logoutBar>";
72                                 echo "<tr><td class=headingtext3>" . $db_connections[$_SESSION["wa_current_user"]->company]["name"] . " | " . $_SERVER['SERVER_NAME'] . " | " . $_SESSION["wa_current_user"]->name . "</td>";
73                                 $indicator = "$path_to_root/themes/".user_theme(). "/images/ajax-loader.gif";
74                                 echo "<td class='logoutBarRight'><img id='ajaxmark' src='$indicator' align='center' style='visibility:hidden;'></td>";
75                                 echo "  <td class='logoutBarRight'><a class='shortcut' href='$path_to_root/admin/display_prefs.php?'>" . _("Preferences") . "</a>&nbsp;&nbsp;&nbsp;\n";
76                                 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";
77
78                                 if ($help_base_url != null)
79                                 {
80                                         echo "$himg<a target = '_blank' onclick=" .'"'."javascript:openWindow(this.href,this.target); return false;".'" '. "href='". help_url()."'>" . _("Help") . "</a>&nbsp;&nbsp;&nbsp;";
81                                 }
82                                 echo "$img<a class='shortcut' href='$local_path_to_root/access/logout.php?'>" . _("Logout") . "</a>&nbsp;&nbsp;&nbsp;";
83                                 echo "</td></tr><tr><td colspan=3>";
84                                 echo "</td></tr></table>";
85                         }
86                         echo "</td></tr></table>";
87
88                         if ($no_menu)
89                                 echo "<br>";
90                         elseif ($title && !$is_index)
91                         {
92                                 echo "<center><table id='title'><tr><td width='100%' class='titletext'>$title</td>"
93                                 ."<td align=right>"
94                                 .(user_hints() ? "<span id='hints'></span>" : '')
95                                 ."</td>"
96                                 ."</tr></table></center>";
97                         }
98                 }
99
100                 function menu_footer($no_menu, $is_index)
101                 {
102                         global $version, $allow_demo_mode, $app_title, $power_url, 
103                                 $power_by, $path_to_root, $Pagehelp, $Ajax;
104                         include_once($path_to_root . "/includes/date_functions.inc");
105
106                         if ($no_menu == false)
107                         {
108                                 if ($is_index)
109                                         echo "<table class=bottomBar>\n";
110                                 else
111                                         echo "<table class=bottomBar2>\n";
112                                 echo "<tr>";
113                                 if (isset($_SESSION['wa_current_user'])) {
114                                         $phelp = implode('; ', $Pagehelp);
115                                         echo "<td class=bottomBarCell>" . Today() . " | " . Now() . "</td>\n";
116                                         $Ajax->addUpdate(true, 'hotkeyshelp', $phelp);
117                                         echo "<td id='hotkeyshelp'>".$phelp."</td>";
118                                 }
119                                 echo "</tr></table>\n";
120                         }
121                         echo "</td></tr></table></td>\n";
122                         echo "</table>\n";
123                         if ($no_menu == false)
124                         {
125                                 echo "<table align='center' id='footer'>\n";
126                                 echo "<tr>\n";
127                                 echo "<td align='center' class='footer'><a target='_blank' href='$power_url' tabindex='-1'><font color='#ffffff'>$app_title $version - " . _("Theme:") . " " . user_theme() . " - ".show_users_online()."</font></a></td>\n";
128                                 echo "</tr>\n";
129                                 echo "<tr>\n";
130                                 echo "<td align='center' class='footer'><a target='_blank' href='$power_url' tabindex='-1'><font color='#ffff00'>$power_by</font></a></td>\n";
131                                 echo "</tr>\n";
132                                 if ($allow_demo_mode==true)
133                                 {
134                                         echo "<tr>\n";
135                                         //echo "<td><br><div align='center'><a href='http://sourceforge.net'><img src='http://sourceforge.net/sflogo.php?group_id=89967&amp;type=5' alt='SourceForge.net Logo' width='210' height='62' border='0' align='middle' /></a></div></td>\n";
136                                         echo "</tr>\n";
137                                 }
138                                 echo "</table><br><br>\n";
139                         }
140                 }
141
142                 function display_applications(&$waapp)
143                 {
144                         global $path_to_root;
145
146                         $selected_app = $waapp->get_selected_application();
147                         if (!$this->check_application_access($selected_app))
148                                 return;
149                         foreach ($selected_app->modules as $module)
150                         {
151                         if (!$this->check_module_access($module))
152                                 continue;
153                                 // image
154                                 echo "<tr>";
155                                 // values
156                                 echo "<td valign='top' class='menu_group'>";
157                                 echo "<table border=0 width='100%'>";
158                                 echo "<tr><td class='menu_group'>";
159                                 echo $module->name;
160                                 echo "</td></tr><tr>";
161                                 echo "<td class='menu_group_items'>";
162
163                                 foreach ($module->lappfunctions as $appfunction)
164                                 {
165                                         $img = $this->get_icon($appfunction->category);
166                                         if ($appfunction->label == "")
167                                                 echo "&nbsp;<br>";
168                                         elseif ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) 
169                                         {
170                                                         echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
171                                         }
172                                         elseif (!$this->hide_inaccessible_menu_items())
173                                         {
174                                                         echo $img.'<span class="inactive">'
175                                                                 .access_string($appfunction->label, true)
176                                                                 ."</span><br>\n";
177                                         }
178                                 }
179                                 echo "</td>";
180                                 if (sizeof($module->rappfunctions) > 0)
181                                 {
182                                         echo "<td width='50%' class='menu_group_items'>";
183                                         foreach ($module->rappfunctions as $appfunction)
184                                         {
185                                                 $img = $this->get_icon($appfunction->category);
186                                                 if ($appfunction->label == "")
187                                                         echo "&nbsp;<br>";
188                                                 elseif ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) 
189                                                 {
190                                                                 echo $img.menu_link($appfunction->link, $appfunction->label)."<br>\n";
191                                                 }
192                                                 elseif (!$this->hide_inaccessible_menu_items())
193                                                 {
194                                                                 echo $img.'<span class="inactive">'
195                                                                         .access_string($appfunction->label, true)
196                                                                         ."</span><br>\n";
197                                                 }
198                                         }
199                                         echo "</td>";
200                                 }
201
202                                 echo "</tr></table></td></tr>";
203                         }       
204                         echo "</table>";
205                 }
206         
207         function check_application_access($waapp)
208         {
209             if (!$this->hide_inaccessible_menu_items())
210             {
211                 return true;
212             }
213             
214             foreach ($waapp->modules as $module)
215             {
216                 if ($this->check_module_access($module))
217                 {
218                     return true;
219                 }
220             }
221             
222             return false;
223                     
224         }
225         
226         function check_module_access($module)
227         {
228             
229             if (!$this->hide_inaccessible_menu_items())
230             {
231                 return true;
232             }
233             
234             if (sizeof($module->lappfunctions) > 0)
235             {
236                 foreach ($module->lappfunctions as $appfunction)
237                 {
238                     if ($appfunction->label != "" && $_SESSION["wa_current_user"]->can_access_page($appfunction->access))
239                     {
240                         return true;
241                     }
242                 }
243             }
244             
245             if (sizeof($module->rappfunctions) > 0)
246             {
247                 foreach ($module->rappfunctions as $appfunction)
248                 {
249                     if ($appfunction->label != "" && $_SESSION["wa_current_user"]->can_access_page($appfunction->access))
250                     {
251                         return true;
252                     }
253                 }
254             }
255             
256             return false;
257             
258         }
259         
260         function hide_inaccessible_menu_items()
261         {
262             global $hide_inaccessible_menu_items;
263             
264             if (!isset($hide_inaccessible_menu_items) || $hide_inaccessible_menu_items == 0)
265             {
266                 return false;
267             }
268             
269             else
270             {
271                 return true;
272             }
273         }
274     }
275                 
276
277
278 ?>