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)
33 $hide_menu = $no_menu;
35 include($path_to_root . "/includes/page/header.inc");
37 page_header($title, $no_menu, $is_index, $onload, $js);
41 echo display_heading(_('This page is usable only with javascript enabled browsers.'));
43 div_start('_page_body', null, true);
45 div_start('_page_body'); // whole page content for ajax reloading
49 function end_page($no_menu=false, $is_index=false)
51 global $path_to_root, $Ajax;
52 $hide_menu = $no_menu;
53 div_end(); // _page_body section
54 include($path_to_root . "/includes/page/footer.inc");
55 page_footer($no_menu, $is_index);
58 function flush_dir($path, $wipe = false)
60 $dir = opendir($path);
61 while(false !== ($fname = readdir($dir))) {
62 if($fname=='.' || $fname=='..' || (!$wipe && $fname=='index.php')) continue;
63 if(is_dir($path.'/'.$fname)) {
64 flush_dir($path.'/'.$fname, $wipe);
65 if ($wipe) @rmdir($path.'/'.$fname);
67 @unlink($path.'/'.$fname);
71 function cache_js_file($fpath, $text)
75 if(!$go_debug) $text = js_compress($text);
77 $file = fopen($fpath, 'w');
78 if (!$file) return false;
79 if (!fwrite($file, $text)) return false;
84 function add_js_file($filename)
88 $search = array_search($filename, $js_static);
89 if ($search === false || $search === null) // php>4.2.0 returns null
90 $js_static[] = $filename;
93 function add_js_ufile($filename)
97 $search = array_search($filename, $js_userlib);
98 if ($search === false || $search === null) // php>4.2.0 returns null
99 $js_userlib[] = $filename;
102 function add_js_source($text)
106 $search = array_search($text, $js_lib);
107 if ($search === false || $search === null) // php>4.2.0 returns null
112 * Compresses the Javascript code for more efficient delivery.
113 * copyright (c) 2005 by Jared White & J. Max Wilson
114 * http://www.xajaxproject.org
115 * Added removing comments from output.
116 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
118 function js_compress($sJS)
120 //remove windows cariage returns
121 $sJS = str_replace("\r","",$sJS);
123 //array to store replaced literal strings
124 $literal_strings = array();
126 //explode the string into lines
127 $lines = explode("\n",$sJS);
128 //loop through all the lines, building a new string at the same time as removing literal strings
136 for($i=0;$i<count($lines);$i++)
139 $inNormalComment = false;
141 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
142 $len = strlen($line);
143 for($j=0;$j<$len;$j++)
145 $c = $line[$j]; // this is _really_ faster than subst
148 //look for start of quote
149 if(!$inQuote && !$inComment)
151 //is this character a quote or a comment
152 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
160 else if($d=="/*" && !$inNormalComment)
169 else if($d=="//") //ignore string markers that are found inside comments
171 $inNormalComment = true;
179 else //allready in a string so find end quote
181 if($c == $quoteChar && !$escaped && !$inComment)
186 //subsitute in a marker for the string
187 $clean .= "___" . count($literal_strings) . "___";
189 //push the string onto our array
190 array_push($literal_strings,$literal);
193 else if($inComment && $d=="*/")
198 //subsitute in a marker for the string
199 $clean .= "___" . count($literal_strings) . "___";
201 //push the string onto our array
202 array_push($literal_strings,$literal);
206 else if($c == "\\" && !$escaped)
214 if($inComment) $literal .= "\n";
217 //explode the clean string into lines again
218 $lines = explode("\n",$clean);
220 //now process each line at a time
221 for($i=0;$i<count($lines);$i++)
226 $line = preg_replace("/\/\/(.*)/","",$line);
228 //strip leading and trailing whitespace
231 //remove all whitespace with a single space
232 $line = preg_replace("/\s+/"," ",$line);
234 //remove any whitespace that occurs after/before an operator
235 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
241 $sJS = implode("\n",$lines);
243 //make sure there is a max of 1 \n after each line
244 $sJS = preg_replace("/[\n]+/","\n",$sJS);
246 //strip out line breaks that immediately follow a semi-colon
247 $sJS = preg_replace("/;\n/",";",$sJS);
249 //curly brackets aren't on their own
250 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
252 //finally loop through and replace all the literal strings:
253 for($i=0;$i<count($literal_strings);$i++) {
254 if (strpos($literal_strings[$i],"/*")!==false)
255 $literal_strings[$i]= '';
256 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
260 //-----------------------------------------------------------------------------
261 // Inserts $elements into $array at position $index.
262 // $elements is list of any objects
264 function array_insert(&$array, $index, $elements)
266 if (!is_array($elements)) $elements = array($elements);
268 $head = array_splice($array, 0, $index);
269 $array = array_merge($head, $elements, $array);
272 function array_remove(&$array, $index, $len=1)
274 array_splice($array, $index, $len);
277 function array_replace(&$array, $index, $len, $elements)
279 array_splice($array, $index, $len);
280 array_insert($array, $index, $elements);
283 function array_append(&$array, $elements)
285 foreach($elements as $key => $el) {