Changed context help organization to enable use of central, multilanguage wiki.
[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 $help_base_url, $help_context, $old_style_help;
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 (@$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 $help_base_url.urlencode(str_replace(' ', '', ucwords($help_page_url))).'&lang='.$country;
44 }
45
46 function send_scripts()
47 {
48     global $js_lib, $js_static, $js_path, $js_userlib, $comp_path,
49         $path_to_root, $go_debug;
50
51         $js ='';
52         foreach($js_static as $jsfile)
53         {
54             $fpath = $comp_path.'/'.user_company().'/js_cache/'.$jsfile;
55             // compress also static files
56                 if (!file_exists($fpath) || $go_debug)
57                         cache_js_file($fpath, file_get_contents($js_path.$jsfile));
58
59                 $js .= '<script language="javascript" type="text/javascript" src="'.
60                         $fpath . '"></script>';
61         }
62         foreach($js_userlib as $jsfile)
63         {
64                 $js .= '<script language="javascript" type="text/javascript" src="'.
65                 $jsfile . '"></script>';
66         }
67
68     echo $js;
69 }
70
71 function page_header($title, $no_menu=false, $is_index=false, $onload="", $js="")
72 {
73         // titles and screen header
74         global $path_to_root, $def_app, $use_popup_windows, $help_base_url;
75
76         if (in_ajax())
77                 return; // just for speed up
78
79 //      $jsext = substr_replace($_SERVER['PHP_SELF'], '.js', -4);
80
81 //      if (file_exists($_SERVER['DOCUMENT_ROOT'].$jsext))
82 //              add_js_ufile($jsext);
83
84         $theme = user_theme();
85         $local_path_to_root = $path_to_root;
86
87         if ($help_base_url != null && $use_popup_windows && $js == '')
88         {
89                 if (!function_exists('get_js_open_window'))
90                 {
91                         include_once($path_to_root.'/includes/ui/ui_view.inc');
92                 }
93                 add_js_source(get_js_open_window(900, 500));
94         }
95         if ($js!='')
96           add_js_source($js);
97
98         if (!isset($no_menu))
99         {
100                 $no_menu = false;
101         }
102         if (!isset($_SESSION["sel_app"]))
103                 session_register("sel_app");
104         if (isset($_SESSION["App"]) && is_object($_SESSION["App"]) && isset($_SESSION["App"]->selected_application) &&
105                 $_SESSION["App"]->selected_application != "")
106                 $sel_app = $_SESSION["App"]->selected_application;
107         elseif (isset($_SESSION["sel_app"]) && $_SESSION["sel_app"] != "")
108                 $sel_app = $_SESSION["sel_app"];
109         else
110                 $sel_app = user_startup_tab();
111         $_SESSION["sel_app"] = $sel_app;
112
113         // When startup tab for current user was set to already 
114         // removed/inactivated extension module select Sales tab as default.
115         if (isset($_SESSION["App"]) && is_object($_SESSION["App"]))
116                 $_SESSION["App"]->selected_application = 
117                         isset($_SESSION["App"]->applications[$sel_app]) ? $sel_app : 'orders';
118                         
119         $encoding = $_SESSION['language']->encoding;
120
121         if (!headers_sent()){
122                 header("Content-type: text/html; charset='$encoding'");
123         }
124         echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
125         echo "<html dir='" . $_SESSION['language']->dir . "' >\n";
126         echo "<head><title>$title</title>";
127         echo "<meta http-equiv='Content-type' content='text/html; charset=$encoding'>";
128         echo "<link href='$local_path_to_root/themes/$theme/default.css' rel='stylesheet' type='text/css'> \n";
129         send_scripts($js);
130
131         echo "</head> \n";
132         if ($onload == "")
133                 echo "<body>";
134         else
135                 echo "<body onload=\"$onload\">";
136         include_once($local_path_to_root."/themes/".user_theme()."/renderer.php");
137         $rend = new renderer();
138         $rend->menu_header($title, $no_menu, $is_index);
139         error_box();
140 }
141
142 ?>