50c562521d2e72d7d277b42a463aecef03d4d6b4
[fa-stable.git] / includes / page / header.inc
1 <?php
2
3 function help_url($title, $app)
4 {
5
6         global $help_page_url, $help_base_url, $applications, $help_page_title;
7
8         if (isset($help_page_url))
9         {
10                 return $help_base_url.$help_page_url;
11         }
12
13         $help_page_url = '';
14         if (isset($help_page_title))
15         {
16                 $help_page_url = $help_page_title;
17         }
18         elseif ($title==_("Main Menu"))
19         {
20                 $help_page_url = $applications[$app];
21         }
22         else
23         {
24                 $help_page_url = $title;
25         }
26
27         return $help_base_url.urlencode(str_replace(' ', '', ucwords($help_page_url)));
28 }
29
30 function send_scripts() 
31 {
32     global $js_lib, $js_static, $js_path, $js_userlib, $comp_path,
33         $path_to_root, $go_debug;
34     
35         add_user_js_data();
36
37         $js ='';
38         foreach($js_static as $jsfile) {
39             $fpath = $comp_path.'/'.user_company().'/js_cache/'.$jsfile;
40             // compress also static files
41           if (!file_exists($fpath) || $go_debug)
42                 cache_js_file($fpath, file_get_contents($js_path.$jsfile));
43         
44           $js .= '<script language="javascript" type="text/javascript" src="'.
45                 $fpath . '"></script>';
46         }
47         foreach($js_userlib as $jsfile) {
48           $js .= '<script language="javascript" type="text/javascript" src="'.
49             $jsfile . '"></script>';
50         }
51
52         foreach($js_lib as $text) {
53           $js .= $text;
54         }
55         echo $js;
56 }
57
58 function page_header($title, $no_menu=false, $is_index=false, $onload="", $js="")
59 {
60         // titles and screen header
61         global $db_connections, $path_to_root, $def_app, $applications,
62                 $help_base_url, $help_page_url, $use_popup_windows;
63
64         if (in_ajax()) return; // just for speed up
65
66         $theme = user_theme();
67         $local_path_to_root = $path_to_root;
68
69         if ($help_base_url != null && $use_popup_windows && $js == '')
70         {
71                 if (!function_exists('get_js_open_window'))
72                 {
73                         include_once($path_to_root.'/includes/ui/ui_view.inc');
74                 }
75                 add_js_source(get_js_open_window(900, 500));
76         }
77         if ($js!='')
78           add_js_source($js);
79
80         if (!isset($no_menu))
81         {
82                 $no_menu = false;
83         }
84         if (!isset($_SESSION["sel_app"]))
85                 session_register("sel_app");
86         if (isset($_SESSION["App"]) && is_object($_SESSION["App"]) && isset($_SESSION["App"]->selected_application) &&
87                 $_SESSION["App"]->selected_application != "")
88                 $sel_app = $_SESSION["App"]->selected_application;
89         elseif (isset($_SESSION["sel_app"]) && $_SESSION["sel_app"] != "")
90                 $sel_app = $_SESSION["sel_app"];
91         else
92                 $sel_app = $def_app;
93         $_SESSION["sel_app"] = $sel_app;
94         $encoding = $_SESSION['language']->encoding;
95
96         if (!headers_sent()){
97                 header("Content-type: text/html; charset='$encoding'");
98         }
99         echo "<html dir='" . $_SESSION['language']->dir . "' >\n";
100         echo "<head><title>$title</title>";
101         $local_stylesheet = $_SESSION['language']->get_stylesheet();
102         echo "<meta http-equiv='Content-type' content='text/html'; charset='$encoding'>";
103         echo "<link href='$local_path_to_root/themes/$theme/default.css' rel='stylesheet' type='text/css' /> \n";
104         if (file_exists($local_path_to_root. "/".$local_stylesheet))
105                 echo "<link href='$local_path_to_root/$local_stylesheet' rel='stylesheet' type='text/css' /> \n";
106         send_scripts($js);
107
108         echo "</head> \n";
109         if ($onload == "")
110                 echo "<body>";
111         else
112                 echo "<body onload=\"$onload\">";
113
114         echo "<table class='callout_main' border='0' cellpadding='0' cellspacing='0'>\n";
115         echo "<tr>\n";
116         echo "<td colspan='2' rowspan='2'>\n";
117
118         echo "<table class='main_page' border='0' cellpadding='0' cellspacing='0'>\n";
119         echo "<tr>\n";
120         echo "<td>\n";
121         echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
122         echo "<tr>\n";
123         echo "<td class='quick_menu'>\n";
124         if (!$no_menu)
125         {
126                 echo "<table cellpadding=0 cellspacing=0 width='100%'><tr><td>";
127                 echo "<div class=tabs>";
128                 foreach($applications as $app => $name)
129                 {
130                         echo "<a ".($sel_app == $app ? "class='selected' " : "").
131                         "href='$local_path_to_root/index.php?application=".$app.
132                                 SID ."'>" .$name . "</a>";
133                 }
134                 echo "</div>";
135
136                 echo "</td></tr></table>";
137
138                 echo "<table class=logoutBar>";
139                 echo "<tr><td class=headingtext3>" . $db_connections[$_SESSION["wa_current_user"]->company]["name"] . " | " . $_SERVER['SERVER_NAME'] . " | " . $_SESSION["wa_current_user"]->name . "</td>";
140                 if ($help_base_url != null)
141                 {
142
143                         echo "<td align=right ><a target = '_blank' onclick=" .'"'."javascript:openWindow(this.href,this.target); return false;".'" '. "href='". help_url($title, $sel_app)."'>" . _("Help") . "</a></td>";
144                 }
145                 echo "<td class=logoutBarRight><a href='$local_path_to_root/access/logout.php?'>" . _("Logout") . "</a>";
146                 echo "</td></tr></table>";
147         }
148
149         echo "</td></tr></table>";
150
151         if ($title && !$no_menu && !$is_index)
152         {
153                 echo "<center><table width='100%'><tr><td width='100%' class='titletext'>$title</td></tr></table></center>";
154         }
155
156         if (!$is_index)
157                 echo "<br>";
158 }
159
160 ?>