Function add_access_extension was missing. Fixed.
[fa-stable.git] / themes / dropdown / 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 // Author: Joe Hunt, 17/11/2015. Upgraded to release 2.4. 10/11/2015.
13
14         class renderer
15         {
16                 function wa_get_apps($title, $applications, $sel_app)
17                 {
18                         foreach($applications as $app)
19                         {
20                                 foreach ($app->modules as $module)
21                                 {
22                                         $apps = array();
23                                         foreach ($module->lappfunctions as $appfunction)
24                                                 $apps[] = $appfunction;
25                                         foreach ($module->rappfunctions as $appfunction)
26                                                 $apps[] = $appfunction;
27                                         $application = array(); 
28                                         foreach ($apps as $application) 
29                                         {
30                                                 $url = explode('?', $application->link);
31                                                 $app_lnk = $url[0];                                     
32                                                 $pos = strrpos($app_lnk, "/");
33                                                 if ($pos > 0)
34                                                 {
35                                                         $app_lnk = substr($app_lnk, $pos + 1);
36                                                         $lnk = $_SERVER['REQUEST_URI'];
37                                                         $url = explode('?', $lnk);
38                                                         $asset = false;
39                                                         if (isset($url[1]))
40                                                                 $asset = strstr($url[1], "FixedAsset");
41                                                         $lnk = $url[0];                                 
42                                                         $pos = strrpos($lnk, "/");
43                                                         $lnk = substr($lnk, $pos + 1);
44                                                         if ($app_lnk == $lnk)  
45                                                         {
46                                                                 $acc = access_string($app->name);
47                                                                 $app_id = ($asset != false ? "assets" : $app->id);
48                                                                 return array($acc[0], $module->name, $application->label, $app_id);
49                                                         }       
50                                                 }       
51                                         }
52                                 }
53                         }
54                         return array("", "", "", $sel_app);
55                 }
56                 
57                 function wa_header()
58                 {
59                         page(_($help_context = "Main Menu"), false, true);
60                 }
61
62                 function wa_footer()
63                 {
64                         end_page(false, true);
65                 }
66                 function shortcut($url, $label) 
67                 {
68                         echo "<li>";
69                         echo menu_link($url, $label);
70                         echo "</li>";
71                 }
72                 function menu_header($title, $no_menu, $is_index)
73                 {
74                         global $path_to_root, $SysPrefs, $version;
75
76                         $sel_app = $_SESSION['sel_app'];
77                         echo "<div class='fa-main'>\n";
78                         if (!$no_menu)
79                         {
80                                 $applications = $_SESSION['App']->applications;
81                                 $local_path_to_root = $path_to_root;
82                                 $pimg = "<img src='$local_path_to_root/themes/".user_theme()."/images/preferences.gif' style='width:14px;height:14px;border:0;vertical-align:middle;padding-bottom:3px;' alt='"._('Preferences')."'>&nbsp;&nbsp;";
83                                 $limg = "<img src='$local_path_to_root/themes/".user_theme()."/images/lock.gif' style='width:14px;height:14px;border:0;vertical-align:middle;padding-bottom:3px;' alt='"._('Change Password')."'>&nbsp;&nbsp;";
84                                 $img = "<img src='$local_path_to_root/themes/".user_theme()."/images/on_off.png' style='width:14px;height:14px;border:0;vertical-align:middle;padding-bottom:3px;' alt='"._('Logout')."'>&nbsp;&nbsp;";
85                                 $himg = "<img src='$local_path_to_root/themes/".user_theme()."/images/help.gif' style='width:14px;height:14px;border:0;vertical-align:middle;padding-bottom:3px;' alt='"._('Help')."'>&nbsp;&nbsp;";
86                                 echo "<div id='header'>\n";
87                                 echo "<ul>\n";
88                                 echo "  <li><a href='$local_path_to_root/admin/display_prefs.php?'>$pimg" . _("Preferences") . "</a></li>\n";
89                                 echo "  <li><a href='$local_path_to_root/admin/change_current_user_password.php?selected_id=" . $_SESSION["wa_current_user"]->username . "'>$limg" . _("Change password") . "</a></li>\n";
90                                 if ($SysPrefs->help_base_url != null)
91                                         echo "  <li><a target = '_blank' onclick=" .'"'."javascript:openWindow(this.href,this.target); return false;".'" '. "href='". 
92                                                 help_url()."'>$himg" . _("Help") . "</a></li>";
93                                 echo "  <li><a href='$path_to_root/access/logout.php?'>$img" . _("Logout") . "</a></li>";
94                                 echo "</ul>\n";
95                                 $indicator = "$path_to_root/themes/".user_theme(). "/images/ajax-loader.gif";
96                                 add_access_extensions();
97                                 echo "<h1>$SysPrefs->power_by $version<span style='padding-left:300px;'><img id='ajaxmark' src='$indicator' align='center' style='visibility:hidden;'></span></h1>\n";
98                                 echo "</div>\n"; // header
99                                                                 
100                                 echo "<div id='cssmenu'>\n";
101                                 echo "<ul>\n";
102                                 $i = 0;
103                                 $account = $this->wa_get_apps($title, $applications, $sel_app);
104                                 foreach($applications as $app)
105                                 {
106                     if ($_SESSION["wa_current_user"]->check_application_access($app))
107                     {
108                                                 $acc = access_string($app->name);
109                                                 $class = ($account[3] == $app->id ? "active" : "");
110                                                 $n = count($app->modules);
111                                                 if ($n)
112                                                         $class .= " has-sub";
113                                                 $dashboard = "";        
114                                             $u_agent = $_SERVER['HTTP_USER_AGENT']; 
115                                         if (preg_match('/android/i', $u_agent) && preg_match('/mobile/i', $u_agent)) {
116                                                 $link = "#'";
117                                                         $dashboard = "$local_path_to_root/index.php?application=$app->id";
118                                                 }
119                                         else
120                                                 $link = "$local_path_to_root/index.php?application=$app->id '$acc[1]";
121                                                 echo "  <li class ='$class'><a href='$link><span>" . $acc[0] . "</span></a>\n";
122                                                 if (!$n)
123                                                 {
124                                                         echo "  </li>\n";
125                                                         continue;
126                                                 }       
127                                                 echo "    <ul>\n";
128                                                 if ($dashboard !="")
129                                                         echo "      <li><a href='$dashboard'><span><font color='red'>"._("Dashboard")."</font></span></a></li>\n";
130                                                 foreach ($app->modules as $module)
131                                                 {
132                                                 if (!$_SESSION["wa_current_user"]->check_module_access($module))
133                                                         continue;
134                                                         echo "      <li class='has-sub'><a href='#'><span>$module->name</span></a>\n"; 
135                                                         $apps2 = array();
136                                                         foreach ($module->lappfunctions as $appfunction)
137                                                                 $apps2[] = $appfunction;
138                                                         foreach ($module->rappfunctions as $appfunction)
139                                                                 $apps2[] = $appfunction;
140                                                         $application = array(); 
141                                                 $n = count($apps2);
142                                                 $class = "";
143                                                 if ($i > 5)
144                                                         $class = "class='align_right'";
145                                                         if ($n)
146                                                                 echo "        <ul $class>\n";
147                                                         else
148                                                         {
149                                                                 echo "      </li>\n";
150                                                                 continue;
151                                                         }       
152                                                         foreach ($apps2 as $application)        
153                                                         {
154                                                                 $lnk = access_string($application->label);
155                                                                 if ($_SESSION["wa_current_user"]->can_access_page($application->access))
156                                                                 {
157                                                                         if ($application->label != "")
158                                                                         {
159                                                                                 echo "          <li><a href='$path_to_root/$application->link'><span>$lnk[0]</span></a></li>\n";
160                                                                         }
161                                                                 }
162                                                                 elseif (!$_SESSION["wa_current_user"]->hide_inaccessible_menu_items())  
163                                                                         echo "          <li><a href='#'><span><font color='gray'>$lnk[0]</font></span></a></li>\n";
164                                                         }
165                                                         if ($n)
166                                                                 echo "        </ul>\n"; 
167                                                         echo "      </li>\n";
168                                                 }
169                                                 echo "    </ul>\n"; // menu
170                                         }
171                                         echo"  </li>\n";
172                                         $i++;
173                                 }       
174                                 echo "</ul>\n"; 
175                                 echo "</div>\n"; // menu
176                         }
177                         echo "<div class='fa-body'>\n";
178                         if ($no_menu)
179                                 echo "<br>";
180                         elseif ($title && !$no_menu && !$is_index)
181                         {
182                                 echo "<div class='fa-content'>\n";
183                                 echo "<center><table id='title'><tr><td width='100%' class='titletext'>$title</td>"
184                                 ."<td align=right>"
185                                 .(user_hints() ? "<span id='hints'></span>" : '')
186                                 ."</td>"
187                                 ."</tr></table></center>";
188                         }
189                 }
190
191                 function menu_footer($no_menu, $is_index)
192                 {
193                         global $path_to_root, $SysPrefs, $version, $db_connections;
194                         include_once($path_to_root . "/includes/date_functions.inc");
195
196                         if (!$no_menu && !$is_index)
197                                 echo "</div>\n"; // fa-content
198                         echo "</div>\n"; // fa-body
199                         if (!$no_menu)
200                         {
201                                 echo "<script type='text/javascript'>if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
202                                        {document.getElementById('cssmenu').style.position = 'fixed';}</script>\n";
203                                 echo "<div class='fa-footer'>\n";
204                                 if (isset($_SESSION['wa_current_user']))
205                                 {
206                                         echo "<span class='power'><a target='_blank' href='$SysPrefs->power_url'>$SysPrefs->power_by $version</a></span>\n";
207                                         echo "<span class='date'>".Today() . "&nbsp;" . Now()."</span>\n";
208                                         echo "<span class='date'>" . $db_connections[$_SESSION["wa_current_user"]->company]["name"] . "</span>\n";
209                                         echo "<span class='date'>" . $_SERVER['SERVER_NAME'] . "</span>\n";
210                                         echo "<span class='date'>" . $_SESSION["wa_current_user"]->name . "</span>\n";
211                                         echo "<span class='date'>" . _("Theme:") . " " . user_theme() . "</span>\n";
212                                         echo "<span class='date'>".show_users_online()."</span>\n";
213                                 }
214                                 echo "</div>\n"; // footer
215                         }
216                         echo "</div>\n"; // fa-main
217                 }
218
219                 function display_applications(&$waapp)
220                 {
221                         global $path_to_root;
222
223                         $sel = $waapp->get_selected_application();
224                         meta_forward("$path_to_root/admin/dashboard.php", "sel_app=$sel->id");  
225                 end_page();
226                 exit;
227                 }       
228         }
229