c59c56c7ec44d51e6b8846c05a6c6b3d1fc35d9e
[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                                 echo "<h1>$SysPrefs->power_by $version<span style='padding-left:300px;'><img id='ajaxmark' src='$indicator' align='center' style='visibility:hidden;'></span></h1>\n";
97                                 echo "</div>\n"; // header
98                                                                 
99                                 echo "<div id='cssmenu'>\n";
100                                 echo "<ul>\n";
101                                 $i = 0;
102                                 $account = $this->wa_get_apps($title, $applications, $sel_app);
103                                 foreach($applications as $app)
104                                 {
105                     if ($_SESSION["wa_current_user"]->check_application_access($app))
106                     {
107                                                 $acc = access_string($app->name);
108                                                 $class = ($account[3] == $app->id ? "active" : "");
109                                                 $n = count($app->modules);
110                                                 if ($n)
111                                                         $class .= " has-sub";
112                                                 $dashboard = "";        
113                                             $u_agent = $_SERVER['HTTP_USER_AGENT']; 
114                                         if (preg_match('/android/i', $u_agent) && preg_match('/mobile/i', $u_agent)) {
115                                                 $link = "#'";
116                                                         $dashboard = "$local_path_to_root/index.php?application=$app->id";
117                                                 }
118                                         else
119                                                 $link = "$local_path_to_root/index.php?application=$app->id '$acc[1]";
120                                                 echo "  <li class ='$class'><a href='$link><span>" . $acc[0] . "</span></a>\n";
121                                                 if (!$n)
122                                                 {
123                                                         echo "  </li>\n";
124                                                         continue;
125                                                 }       
126                                                 echo "    <ul>\n";
127                                                 if ($dashboard !="")
128                                                         echo "      <li><a href='$dashboard'><span><font color='red'>"._("Dashboard")."</font></span></a></li>\n";
129                                                 foreach ($app->modules as $module)
130                                                 {
131                                                 if (!$_SESSION["wa_current_user"]->check_module_access($module))
132                                                         continue;
133                                                         echo "      <li class='has-sub'><a href='#'><span>$module->name</span></a>\n"; 
134                                                         $apps2 = array();
135                                                         foreach ($module->lappfunctions as $appfunction)
136                                                                 $apps2[] = $appfunction;
137                                                         foreach ($module->rappfunctions as $appfunction)
138                                                                 $apps2[] = $appfunction;
139                                                         $application = array(); 
140                                                 $n = count($apps2);
141                                                 $class = "";
142                                                 if ($i > 5)
143                                                         $class = "class='align_right'";
144                                                         if ($n)
145                                                                 echo "        <ul $class>\n";
146                                                         else
147                                                         {
148                                                                 echo "      </li>\n";
149                                                                 continue;
150                                                         }       
151                                                         foreach ($apps2 as $application)        
152                                                         {
153                                                                 $lnk = access_string($application->label);
154                                                                 if ($_SESSION["wa_current_user"]->can_access_page($application->access))
155                                                                 {
156                                                                         if ($application->label != "")
157                                                                         {
158                                                                                 echo "          <li><a href='$path_to_root/$application->link'><span>$lnk[0]</span></a></li>\n";
159                                                                         }
160                                                                 }
161                                                                 elseif (!$_SESSION["wa_current_user"]->hide_inaccessible_menu_items())  
162                                                                         echo "          <li><a href='#'><span><font color='gray'>$lnk[0]</font></span></a></li>\n";
163                                                         }
164                                                         if ($n)
165                                                                 echo "        </ul>\n"; 
166                                                         echo "      </li>\n";
167                                                 }
168                                                 echo "    </ul>\n"; // menu
169                                         }
170                                         echo"  </li>\n";
171                                         $i++;
172                                 }       
173                                 echo "</ul>\n"; 
174                                 echo "</div>\n"; // menu
175                         }
176                         echo "<div class='fa-body'>\n";
177                         if ($no_menu)
178                                 echo "<br>";
179                         elseif ($title && !$no_menu && !$is_index)
180                         {
181                                 echo "<div class='fa-content'>\n";
182                                 echo "<center><table id='title'><tr><td width='100%' class='titletext'>$title</td>"
183                                 ."<td align=right>"
184                                 .(user_hints() ? "<span id='hints'></span>" : '')
185                                 ."</td>"
186                                 ."</tr></table></center>";
187                         }
188                 }
189
190                 function menu_footer($no_menu, $is_index)
191                 {
192                         global $path_to_root, $SysPrefs, $version, $db_connections;
193                         include_once($path_to_root . "/includes/date_functions.inc");
194
195                         if (!$no_menu && !$is_index)
196                                 echo "</div>\n"; // fa-content
197                         echo "</div>\n"; // fa-body
198                         if (!$no_menu)
199                         {
200                                 echo "<script type='text/javascript'>if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
201                                        {document.getElementById('cssmenu').style.position = 'fixed';}</script>\n";
202                                 echo "<div class='fa-footer'>\n";
203                                 if (isset($_SESSION['wa_current_user']))
204                                 {
205                                         echo "<span class='power'><a target='_blank' href='$SysPrefs->power_url'>$SysPrefs->power_by $version</a></span>\n";
206                                         echo "<span class='date'>".Today() . "&nbsp;" . Now()."</span>\n";
207                                         echo "<span class='date'>" . $db_connections[$_SESSION["wa_current_user"]->company]["name"] . "</span>\n";
208                                         echo "<span class='date'>" . $_SERVER['SERVER_NAME'] . "</span>\n";
209                                         echo "<span class='date'>" . $_SESSION["wa_current_user"]->name . "</span>\n";
210                                         echo "<span class='date'>" . _("Theme:") . " " . user_theme() . "</span>\n";
211                                         echo "<span class='date'>".show_users_online()."</span>\n";
212                                 }
213                                 echo "</div>\n"; // footer
214                         }
215                         echo "</div>\n"; // fa-main
216                 }
217
218                 function display_applications(&$waapp)
219                 {
220                         global $path_to_root;
221
222                         $sel = $waapp->get_selected_application();
223                         meta_forward("$path_to_root/admin/dashboard.php", "sel_app=$sel->id");  
224                 end_page();
225                 exit;
226                 }       
227         }
228