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 include_once($path_to_root . "/includes/db/connect_db.inc");
14 include_once($path_to_root . "/includes/errors.inc");
15 include_once($path_to_root . "/includes/types.inc");
16 include_once($path_to_root . "/includes/systypes.inc");
17 include_once($path_to_root . "/includes/references.inc");
18 include_once($path_to_root . "/includes/prefs/sysprefs.inc");
19 include_once($path_to_root . "/includes/db/comments_db.inc");
20 include_once($path_to_root . "/includes/db/sql_functions.inc");
21 include_once($path_to_root . "/includes/db/audit_trail_db.inc");
22 //include_once($path_to_root . "/includes/validation.inc");
24 include_once($path_to_root . "/admin/db/users_db.inc");
25 include_once($path_to_root . "/includes/ui/ui_view.inc");
26 include_once($path_to_root . "/includes/ui/ui_controls.inc");
28 function page($title, $no_menu=false, $is_index=false, $onload="", $js="", $script_only=false)
31 global $path_to_root, $page_security;
34 $hide_menu = $no_menu;
36 include($path_to_root . "/includes/page/header.inc");
38 page_header($title, $no_menu, $is_index, $onload, $js);
39 check_page_security($page_security);
43 echo display_heading(_('This page is usable only with javascript enabled browsers.'));
45 div_start('_page_body', null, true);
47 div_start('_page_body'); // whole page content for ajax reloading
51 function end_page($no_menu=false, $is_index=false, $hide_back_link=false)
55 if (!$is_index && !$hide_back_link && function_exists('hyperlink_back'))
57 div_end(); // end of _page_body section
59 include($path_to_root . "/includes/page/footer.inc");
60 page_footer($no_menu, $is_index, $hide_back_link);
63 function flush_dir($path, $wipe = false)
65 $dir = opendir($path);
66 while(false !== ($fname = readdir($dir))) {
67 if($fname=='.' || $fname=='..' || $fname=='CVS' || (!$wipe && $fname=='index.php')) continue;
68 if(is_dir($path.'/'.$fname)) {
69 flush_dir($path.'/'.$fname, $wipe);
70 if ($wipe) @rmdir($path.'/'.$fname);
72 @unlink($path.'/'.$fname);
76 function cache_js_file($fpath, $text)
80 if(!$go_debug) $text = js_compress($text);
82 $file = fopen($fpath, 'w');
83 if (!$file) return false;
84 if (!fwrite($file, $text)) return false;
89 function add_js_file($filename)
93 $search = array_search($filename, $js_static);
94 if ($search === false || $search === null) // php>4.2.0 returns null
95 $js_static[] = $filename;
98 function add_js_ufile($filename)
102 $search = array_search($filename, $js_userlib);
103 if ($search === false || $search === null) // php>4.2.0 returns null
104 $js_userlib[] = $filename;
107 function add_js_source($text)
111 $search = array_search($text, $js_lib);
112 if ($search === false || $search === null) // php>4.2.0 returns null
117 * Compresses the Javascript code for more efficient delivery.
118 * copyright (c) 2005 by Jared White & J. Max Wilson
119 * http://www.xajaxproject.org
120 * Added removing comments from output.
121 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
123 function js_compress($sJS)
125 //remove windows cariage returns
126 $sJS = str_replace("\r","",$sJS);
128 //array to store replaced literal strings
129 $literal_strings = array();
131 //explode the string into lines
132 $lines = explode("\n",$sJS);
133 //loop through all the lines, building a new string at the same time as removing literal strings
141 for($i=0;$i<count($lines);$i++)
144 $inNormalComment = false;
146 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
147 $len = strlen($line);
148 for($j=0;$j<$len;$j++)
150 $c = $line[$j]; // this is _really_ faster than subst
153 //look for start of quote
154 if(!$inQuote && !$inComment)
156 //is this character a quote or a comment
157 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
165 else if($d=="/*" && !$inNormalComment)
174 else if($d=="//") //ignore string markers that are found inside comments
176 $inNormalComment = true;
184 else //allready in a string so find end quote
186 if($c == $quoteChar && !$escaped && !$inComment)
191 //subsitute in a marker for the string
192 $clean .= "___" . count($literal_strings) . "___";
194 //push the string onto our array
195 array_push($literal_strings,$literal);
198 else if($inComment && $d=="*/")
203 //subsitute in a marker for the string
204 $clean .= "___" . count($literal_strings) . "___";
206 //push the string onto our array
207 array_push($literal_strings,$literal);
211 else if($c == "\\" && !$escaped)
219 if($inComment) $literal .= "\n";
222 //explode the clean string into lines again
223 $lines = explode("\n",$clean);
225 //now process each line at a time
226 for($i=0;$i<count($lines);$i++)
231 $line = preg_replace("/\/\/(.*)/","",$line);
233 //strip leading and trailing whitespace
236 //remove all whitespace with a single space
237 $line = preg_replace("/\s+/"," ",$line);
239 //remove any whitespace that occurs after/before an operator
240 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
246 $sJS = implode("\n",$lines);
248 //make sure there is a max of 1 \n after each line
249 $sJS = preg_replace("/[\n]+/","\n",$sJS);
251 //strip out line breaks that immediately follow a semi-colon
252 $sJS = preg_replace("/;\n/",";",$sJS);
254 //curly brackets aren't on their own
255 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
257 //finally loop through and replace all the literal strings:
258 for($i=0;$i<count($literal_strings);$i++) {
259 if (strpos($literal_strings[$i],"/*")!==false)
260 $literal_strings[$i]= '';
261 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);