7777dae422e66241483f09f5f2800e6160442949
[fa-stable.git] / includes / page / header.inc
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         If no context is set current page/menu screen is selected.
14 */
15 function help_url($context=null)
16 {
17
18         global $SysPrefs, $help_context;
19
20         $country = $_SESSION['language']->code;
21         $clean = 0;
22         
23         if ($context!=null)
24         {
25                 $help_page_url = $context;
26         }
27         elseif (isset($help_context))
28         {
29                 $help_page_url = $help_context;
30         } else // main menu
31         {
32                 $app = $_SESSION['sel_app'];
33                 $help_page_url = $_SESSION['App']->applications[$app]->help_context;
34                 $clean = 1;
35         }
36
37         if (@$SysPrefs->old_style_help)
38                 $help_page_url = _($help_page_url);
39
40         if ($clean)
41                 $help_page_url = access_string($help_page_url, true);
42
43         return html_specials_encode(
44                 $SysPrefs->help_base_url
45                 .urlencode(strtr(ucwords($help_page_url), array(' '=>'', '/'=>'', '&'=>'And')))
46                 .'&ctxhelp=1&lang='.$country);
47 }
48
49 function send_css($css = '')
50 {
51         global $css_files;
52
53         css_files_ensure_init();
54
55         foreach ($css_files as $css_file)
56         {
57                 echo "<link href='$css_file' rel='stylesheet' type='text/css'> \n";
58         }
59         if ($css)
60         {
61                 echo "<link href='$css' rel='stylesheet' type='text/css'> \n";
62         }
63 }
64
65 function send_scripts()
66 {
67     global $SysPrefs, $path_to_root, $js_static, $js_path, $js_userlib;
68
69         $js ='';
70         foreach($js_static as $jsfile)
71         {
72                 $cached_name = basename($jsfile);
73                 $fpath = user_js_cache().'/'.$cached_name;
74             // compress also static files
75                 if (!file_exists($fpath) || $SysPrefs->go_debug)
76                         cache_js_file($fpath, file_get_contents($js_path.$jsfile));
77
78                 $js .= '<script language="javascript" type="text/javascript" src="'.
79                         $fpath . '"></script>';
80         }
81         foreach($js_userlib as $jsfile)
82         {
83                 $js .= '<script language="javascript" type="text/javascript" src="'.
84                 $jsfile . '"></script>';
85         }
86
87     echo $js;
88 }
89
90 function page_header($title, $no_menu=false, $is_index=false, $onload="", $js="", $css='')
91 {
92         // titles and screen header
93         global $path_to_root, $SysPrefs, $db_connections;
94
95         if (in_ajax())
96                 return; // just for speed up
97
98         $theme = user_theme();
99
100         if ($SysPrefs->help_base_url != null && $SysPrefs->use_popup_windows && $js == '')
101         {
102                 if (!function_exists('get_js_open_window'))
103                 {
104                         include_once($path_to_root.'/includes/ui/ui_view.inc');
105                 }
106                 add_js_source(get_js_open_window(900, 500));
107         }
108         if ($js!='')
109                 add_js_source($js);
110
111         if (!isset($no_menu))
112         {
113                 $no_menu = false;
114         }
115         if (isset($_SESSION["App"]) && is_object($_SESSION["App"]) && isset($_SESSION["App"]->selected_application) &&
116                 $_SESSION["App"]->selected_application != "")
117                 $sel_app = $_SESSION["App"]->selected_application;
118         elseif (isset($_SESSION["sel_app"]) && $_SESSION["sel_app"] != "")
119                 $sel_app = $_SESSION["sel_app"];
120         else
121                 $sel_app = user_startup_tab();
122         $_SESSION["sel_app"] = $sel_app;
123
124         // When startup tab for current user was set to already 
125         // removed/inactivated extension module select Sales tab as default.
126         if (isset($_SESSION["App"]) && is_object($_SESSION["App"]))
127                 $_SESSION["App"]->selected_application = 
128                         isset($_SESSION["App"]->applications[$sel_app]) ? $sel_app : 'orders';
129
130         $page_header_args = func_get_args();
131         if(isset($db_connections))      // skip before installation
132                 hook_invoke_all('pre_header', $page_header_args);
133
134         $encoding = $_SESSION['language']->encoding;
135
136         if (!headers_sent()){
137                 header("Content-type: text/html; charset=$encoding");
138         }
139         echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
140         echo "<html dir='" . $_SESSION['language']->dir . "' >\n";
141         echo "<head profile=\"http://www.w3.org/2005/10/profile\"><title>$title</title>";
142         if (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') != -1) // IE 11 doesn't work with input file type in form.
143                 echo "<meta http-equiv='X-UA-Compatible' content='IE=10'>\n";
144         echo "<meta http-equiv='Content-type' content='text/html; charset=$encoding'>";
145         echo "<link href='$path_to_root/themes/default/images/favicon.ico' rel='icon' type='image/x-icon'> \n";
146
147         send_css($css);
148
149         send_scripts();
150
151         echo "</head> \n";
152         if ($onload == "")
153                 echo "<body>";
154         else
155                 echo "<body onload=\"$onload\">";
156
157         include_once($path_to_root . "/themes/$theme/renderer.php");
158         $rend = new renderer();
159         $rend->menu_header($title, $no_menu, $is_index);
160         error_box();
161 }
162