Code

Removed temporary file for w3c testings.
[gosa.git] / html / main.php
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 /* Basic setup, remove eventually registered sessions */
22 $timing= array();
23 require_once ("../include/php_setup.inc");
24 require_once ("functions.inc");
25 header("Content-type: text/html; charset=UTF-8");
27 /* Find all class files and include them */
28 get_dir_list("$BASE_DIR/plugins");
30 /* Set the text domain as 'messages' */
31 $domain = 'messages';
32 bindtextdomain($domain, "$BASE_DIR/locale");
33 textdomain($domain);
35 /* Remember everything we did after the last click */
36 session_set_cookie_params(2*60*60);
37 session_start ();
38 if ($_SERVER["REQUEST_METHOD"] == "POST"){
39   @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
40 }
41 @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_SESSION, "_SESSION");
43 /* Logged in? Simple security check */
44 if (!isset($_SESSION['config'])){
45   gosa_log ("main.php called without session - logging out");
46   header ("Location: logout.php");
47   exit;
48
50 /* Reset errors */
51 $_SESSION['errors']= "";
53 /* Check for uniqe ip address */
54 $ui= $_SESSION["ui"];
55 if ($_SERVER['REMOTE_ADDR'] != $ui->ip){
56   gosa_log ("main.php called with session which has a changed IP address.", 3);
57   header ("Location: logout.php");
58   exit;
59 }
60 $config= $_SESSION['config'];
62 @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
64 /* Set template compile directory */
65 if (isset ($config->data['MAIN']['COMPILE'])){
66   $smarty->compile_dir= $config->data['MAIN']['COMPILE'];
67 } else {
68   $smarty->compile_dir= '/var/spool/gosa/';
69 }
71 /* Set default */
72 $reload_navigation = false;
74 /* Set last initialised language to current, browser settings */
75 if((!isset($_SESSION['Last_init_lang']))){
76   $reload_navigation = true;
77   $_SESSION['Last_init_lang'] = get_browser_language();
78 }
80 /* Language setup */
81 if ($config->data['MAIN']['LANG'] == ""){
82   
83   /* If last language != current force navi reload */
84   if($_SESSION['Last_init_lang'] != get_browser_language()){
85     $reload_navigation = true;
86   }
87   $lang= get_browser_language();
88   $_SESSION['Last_init_lang'] = $lang;
89 } else {
90   $lang= $config->data['MAIN']['LANG'];
91 }
93 $lang.=".UTF-8";
94 putenv("LANGUAGE=");
95 putenv("LANG=$lang");
96 setlocale(LC_ALL, $lang);
97 $GLOBALS['t_language']= $lang;
98 $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
100 /* Set the text domain as 'messages' */
101 $domain = 'messages';
102 bindtextdomain($domain, "$BASE_DIR/locale");
103 textdomain($domain);
104 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
106 /* Prepare plugin list */
107 if (!isset($_SESSION['plist'])){
108   $_SESSION['plist']= new pluglist($config, $ui);
110 $plist= $_SESSION['plist'];
112 /* Check for register globals */
113 if (isset($global_check) && $config->data['MAIN']['FORCEGLOBALS'] == 'true'){
114   print_red (_("Register globals is on. GOsa will refuse to login unless this is fixed by an administrator."));
115   echo $_SESSION['errors'];
116   gosa_log ("Register globals is on. For security reasons, this should be turned off.");
117   session_destroy ();
118   exit ();
121 /* Check Plugin variable */
122 if (isset($_SESSION['plugin_dir'])){
123   $old_plugin_dir= $_SESSION['plugin_dir'];
124 } else {
125   $old_plugin_dir= "";
127 if (isset($_GET['plug'])){
128   $plug= validate($_GET['plug']);
129   $plugin_dir= $plist->get_path($plug);
130   $_SESSION['plugin_dir']= $plugin_dir;
131   if ($plugin_dir == ""){
132     gosa_log ("main.php called with invalid plug parameter \"$plug\"", 3);
133     header ("Location: logout.php");
134     exit;
135   }
136 } else {
137   /* set to welcome page as default plugin */
138   $_SESSION['plugin_dir']= "welcome";
139   $plugin_dir= "$BASE_DIR/plugins/generic/welcome";
142 /* Check if we need to delete a lock */
143 if ($old_plugin_dir != $plugin_dir){
144   if (is_file("$old_plugin_dir/main.inc")){
145     $remove_lock= true;
146     require_once ("$old_plugin_dir/main.inc");
147   }
149 $remove_lock= false;
151 /* Check for sizelimits */
152 eval_sizelimit();
154 /* Check for memory */
155 if (function_exists("memory_get_usage")){
156   if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )){
157     print_red(_("Warning: memory is getting low - please increase the memory_limit!"));
158   }
161 /* Redirect on back event */
162 if ($_SERVER["REQUEST_METHOD"] == "POST"){
164   /* Look for button events that match /^back[0-9]+$/,
165      extract the number and step the correct plugin. */
166   foreach ($_POST as $key => $value){
167     if (preg_match("/^back[0-9]+$/", $key)){
168       $back= substr($key, 4);
169       header ("Location: main.php?plug=$back");
170       exit;
171     }
172   }
175 /* Redirect on password back event */
176 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])){
177   header ("Location: main.php");
178   exit;
181 /* Check for multiple windows logout */
182 if ($_SERVER["REQUEST_METHOD"] == "POST"){
183   if (isset($_POST['reset_session'])){
184     header ("Location: logout.php");
185     exit;
186   }
188   if (isset($_POST['cancel_lock'])){
189     unset ($_SESSION['dn']);
190   }
194 /* Load department list when plugin has changed. That is some kind of
195    compromise between speed and beeing up to date */
196 if (isset($_GET['reset'])){
197   $config->departments= get_departments();
198   $config->make_idepartments ();
199   if (isset($_SESSION['objectinfo'])){
200     unset ($_SESSION['objectinfo']);
201   }
204 /* Install eGOsa hooks, convert _POST to _SESSION['POST'] */
205 if(isset($_GET['explorer'])){
206   $_SESSION{'eGosa'}=1;
208 if(isset($_SESSION['POST'])){
209   $_SERVER["REQUEST_METHOD"] = "POST";
210   foreach ($_SESSION['POST'] as $key => $dummy){
211     $_POST[$key]=$_SESSION['POST'][$key];
212   }
213   unset($_SESSION['POST']);
216 /* show web frontend */
217 $smarty->assign ("date", date("l, dS F Y H:i:s O"));
218 $smarty->assign ("must", "<font class=\"must\">*</font>");
219 if (isset($plug)){
220   $plug= "?plug=$plug";
221 } else {
222   $plug= "";
224 if ($_SESSION['js']==FALSE){
225   $smarty->assign("javascript", "false");
226   $smarty->assign("help_method", "href='helpviewer.php$plug' target='_blank'");
227 } else {
228   $smarty->assign("javascript", "true");
229   $smarty->assign("help_method"," onclick=\"return popup('helpviewer.php$plug','GOsa help');\"");
232 $smarty->assign ("username", $ui->username);
233 $smarty->assign ("go_logo", get_template_path('images/go_logo.png'));
234 $smarty->assign ("go_base", get_template_path('images/dtree.png'));
235 $smarty->assign ("go_home", get_template_path('images/gohome.png'));
236 $smarty->assign ("go_out", get_template_path('images/stop.png'));
237 $smarty->assign ("go_top", get_template_path('images/go_top.png'));
238 $smarty->assign ("go_corner", get_template_path('images/go_corner.png'));
239 $smarty->assign ("go_left", get_template_path('images/go_left.png'));
240 $smarty->assign ("go_help", get_template_path('images/help.png'));
242 /* reload navigation if language changed*/  
243 if($reload_navigation){
244   $plist->menu="";;
246 $plist->gen_headlines();
247 $plist->gen_menu();
248 $smarty->assign ("menu", $plist->menu);
249 $smarty->assign ("plug", "$plug");
251 $header= "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
254 /* React on clicks */
255 if ($_SERVER["REQUEST_METHOD"] == "POST"){
257   /* 'delete_lock' is set by the lock removal dialog. We should remove the
258      lock at this point globally. Plugins do not need to remove it. */
259   if (isset($_POST['delete_lock']) && isset($_SESSION['dn'])){
260     del_lock ($_SESSION['dn']);
261     sess_del ('dn');
262   }
265   /* I don't want multiple browser windows open. One way to check it is
266      to count a hidden field and warn the user if SESSION and INPUT count
267      differ. */
268   if (isset($_POST['session_cnt'])){
269     if ($_POST['session_cnt'] != $_SESSION['session_cnt']){
270       $smarty->display(get_template_path('conflict.tpl'));
271       exit ();
272     }
273     $_SESSION['session_cnt']= $_SESSION['session_cnt'] + 1;
274     $_SESSION['post_cnt']= validate($_POST['session_cnt']) + 1;
275   }
278 /* Only generate hidden click counter, if post_cnt is defined */
279 if (isset ($_SESSION['post_cnt'])){
280   echo "<input type=\"hidden\" name=\"session_cnt\" value=\"".$_SESSION['post_cnt']."\">\n";
283 /* Load plugin */
284 if (is_file("$plugin_dir/main.inc")){
285   require_once ("$plugin_dir/main.inc");
286 } else {
287   print_red(sprintf(_("Can't find any plugin definitions for plugin '%s'!"), $plug));
288   echo $_SESSION['errors'];
289   exit();
292 /* Close div/tables */
293 $smarty->assign("contents", $display);
294 if (isset($_SESSION['errors'])){
295   $smarty->assign("errors", $_SESSION['errors']);
297 if ($error_collector != ""){
298   $smarty->assign("php_errors", $error_collector."</div>");
299 } else {
300   $smarty->assign("php_errors", "");
302 $display= $header.$smarty->fetch(get_template_path('framework.tpl'));
304 /*if (isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST'])) {
305   $tidy = new tidy();
306   $config = array('indent' => TRUE,
307       'output-xhtml' => TRUE,
308       'wrap' => 200);
309   $display = tidy_parse_string($display, $config, 'UTF8');
310   tidy_clean_repair($display);
311   $cnt =  (tidy_error_count($display))+(tidy_warning_count($display));
312   if($cnt != 0){
313     echo "<table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black'><tr><td><img alt=\"W3C\" align=\"middle\" src='images/warning.png'>&nbsp;<font style='font-size:14px;font-weight:bold'>"._("Generating this page caused the W3C conformance checker to raise some errors!")."</font></td><td align=right><button onClick='toggle(\"w3cbox\")'>"._("Toggle information")."</button></td></tr></table><div id='w3cbox' style='width:100%; position:absolute; z-index:0; visibility: hidden; background-color:white; border-bottom:1px solid black;'>";
315     echo nl2br(htmlentities($display->errorBuffer))."</div>";
316   }
317   tidy_clean_repair($display);
319 */
321 if ((isset($config->data['MAIN']['W3CTEST']) && preg_match('/true/i', $config->data['MAIN']['W3CTEST']))&&(!empty($display))) {
322   tidy_parse_string(utf8_decode($display));
323   $err = nl2br(htmlentities(tidy_get_error_buffer()));
324   
325   if($err){
326     echo "<table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black'><tr><td><img alt=\"W3C\"            align=\"middle\" src='images/warning.png'>&nbsp;<font style='font-size:14px;font-weight:bold'>"._("Generating this page caused the W3C          conformance checker to raise some errors!")."</font></td><td align=right><button onClick='toggle(\"w3cbox\")'>"._("Toggle information")."</     button></td></tr></table><div id='w3cbox' style='width:100%; position:absolute; z-index:0; visibility: hidden; background-color:white; border-  bottom:1px solid black;'>";
327   }
329   echo $err."</div>";
330   tidy_clean_repair($display);
333 /* Show page... */
334 echo $display;
336 /* Save plist */
337 $_SESSION['plist']= $plist;
339 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
340 ?>