Added retry after ajax request timeout, preparation for client-side
[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 function help_url($title, $app)
13 {
14
15         global $help_page_url, $help_base_url, $applications, $help_page_title;
16
17         if (isset($help_page_url))
18         {
19                 return $help_base_url.$help_page_url;
20         }
21
22         $help_page_url = '';
23         if (isset($help_page_title))
24         {
25                 $help_page_url = $help_page_title;
26         }
27         elseif ($title==_("Main Menu"))
28         {
29                 $help_page_url = access_string($applications[$app], true);
30         }
31         else
32         {
33                 $help_page_url = $title;
34         }
35
36         return $help_base_url.urlencode(str_replace(' ', '', ucwords($help_page_url)));
37 }
38
39 function send_scripts()
40 {
41     global $js_lib, $js_static, $js_path, $js_userlib, $comp_path,
42         $path_to_root, $go_debug;
43
44         $js ='';
45         foreach($js_static as $jsfile)
46         {
47             $fpath = $comp_path.'/'.user_company().'/js_cache/'.$jsfile;
48             // compress also static files
49                 if (!file_exists($fpath) || $go_debug)
50                         cache_js_file($fpath, file_get_contents($js_path.$jsfile));
51
52                 $js .= '<script language="javascript" type="text/javascript" src="'.
53                         $fpath . '"></script>';
54         }
55         foreach($js_userlib as $jsfile)
56         {
57                 $js .= '<script language="javascript" type="text/javascript" src="'.
58                 $jsfile . '"></script>';
59         }
60
61     echo $js;
62 }
63
64 function page_header($title, $no_menu=false, $is_index=false, $onload="", $js="")
65 {
66         // titles and screen header
67         global $path_to_root, $def_app, $use_popup_windows, $help_base_url;
68
69         if (in_ajax())
70                 return; // just for speed up
71
72 //      $jsext = substr_replace($_SERVER['PHP_SELF'], '.js', -4);
73
74 //      if (file_exists($_SERVER['DOCUMENT_ROOT'].$jsext))
75 //              add_js_ufile($jsext);
76
77         $theme = user_theme();
78         $local_path_to_root = $path_to_root;
79
80         if ($help_base_url != null && $use_popup_windows && $js == '')
81         {
82                 if (!function_exists('get_js_open_window'))
83                 {
84                         include_once($path_to_root.'/includes/ui/ui_view.inc');
85                 }
86                 add_js_source(get_js_open_window(900, 500));
87         }
88         if ($js!='')
89           add_js_source($js);
90
91         if (!isset($no_menu))
92         {
93                 $no_menu = false;
94         }
95         if (!isset($_SESSION["sel_app"]))
96                 session_register("sel_app");
97         if (isset($_SESSION["App"]) && is_object($_SESSION["App"]) && isset($_SESSION["App"]->selected_application) &&
98                 $_SESSION["App"]->selected_application != "")
99                 $sel_app = $_SESSION["App"]->selected_application;
100         elseif (isset($_SESSION["sel_app"]) && $_SESSION["sel_app"] != "")
101                 $sel_app = $_SESSION["sel_app"];
102         else
103                 $sel_app = $def_app;
104         $_SESSION["sel_app"] = $sel_app;
105         if (isset($_SESSION["App"]) && is_object($_SESSION["App"]))
106                 $_SESSION["App"]->selected_application = $sel_app;
107         $encoding = $_SESSION['language']->encoding;
108
109         if (!headers_sent()){
110                 header("Content-type: text/html; charset='$encoding'");
111         }
112         echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
113         echo "<html dir='" . $_SESSION['language']->dir . "' >\n";
114         echo "<head><title>$title</title>";
115         echo "<meta http-equiv='Content-type' content='text/html; charset=$encoding'>";
116         echo "<link href='$local_path_to_root/themes/$theme/default.css' rel='stylesheet' type='text/css'> \n";
117         send_scripts($js);
118
119         echo "</head> \n";
120         if ($onload == "")
121                 echo "<body>";
122         else
123                 echo "<body onload=\"$onload\">";
124         include_once($local_path_to_root."/themes/".user_theme()."/renderer.php");
125         $rend = new renderer();
126         $rend->menu_header($title, $no_menu, $is_index);
127 }
128
129 ?>