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/db/comments_db.inc");
19 include_once($path_to_root . "/includes/db/sql_functions.inc");
20 include_once($path_to_root . "/includes/db/audit_trail_db.inc");
21 //include_once($path_to_root . "/includes/validation.inc");
23 include_once($path_to_root . "/admin/db/users_db.inc");
24 include_once($path_to_root . "/includes/ui/ui_view.inc");
25 include_once($path_to_root . "/includes/ui/ui_controls.inc");
27 function page($title, $no_menu=false, $is_index=false, $onload="", $js="", $script_only=false)
30 global $path_to_root, $page_security;
33 $hide_menu = $no_menu;
35 include($path_to_root . "/includes/page/header.inc");
37 page_header($title, $no_menu, $is_index, $onload, $js);
38 check_page_security($page_security);
42 echo display_heading(_('This page is usable only with javascript enabled browsers.'));
44 div_start('_page_body', null, true);
46 div_start('_page_body'); // whole page content for ajax reloading
50 function end_page($no_menu=false, $is_index=false, $hide_back_link=false)
54 if (!$is_index && !$hide_back_link && function_exists('hyperlink_back'))
55 hyperlink_back(true, $no_menu);
56 div_end(); // end of _page_body section
58 include($path_to_root . "/includes/page/footer.inc");
59 page_footer($no_menu, $is_index, $hide_back_link);
62 function flush_dir($path, $wipe = false)
64 $dir = opendir($path);
65 while(false !== ($fname = readdir($dir))) {
66 if($fname=='.' || $fname=='..' || $fname=='CVS' || (!$wipe && $fname=='index.php')) continue;
67 if(is_dir($path.'/'.$fname)) {
68 flush_dir($path.'/'.$fname, $wipe);
69 if ($wipe) @rmdir($path.'/'.$fname);
71 @unlink($path.'/'.$fname);
75 function cache_js_file($fpath, $text)
79 if(!$go_debug) $text = js_compress($text);
81 $file = fopen($fpath, 'w');
82 if (!$file) return false;
83 if (!fwrite($file, $text)) return false;
88 function add_js_file($filename)
92 $search = array_search($filename, $js_static);
93 if ($search === false || $search === null) // php>4.2.0 returns null
94 $js_static[] = $filename;
97 function add_js_ufile($filename)
101 $search = array_search($filename, $js_userlib);
102 if ($search === false || $search === null) // php>4.2.0 returns null
103 $js_userlib[] = $filename;
106 function add_js_source($text)
110 $search = array_search($text, $js_lib);
111 if ($search === false || $search === null) // php>4.2.0 returns null
116 * Compresses the Javascript code for more efficient delivery.
117 * copyright (c) 2005 by Jared White & J. Max Wilson
118 * http://www.xajaxproject.org
119 * Added removing comments from output.
120 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
122 function js_compress($sJS)
124 //remove windows cariage returns
125 $sJS = str_replace("\r","",$sJS);
127 //array to store replaced literal strings
128 $literal_strings = array();
130 //explode the string into lines
131 $lines = explode("\n",$sJS);
132 //loop through all the lines, building a new string at the same time as removing literal strings
140 for($i=0;$i<count($lines);$i++)
143 $inNormalComment = false;
145 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
146 $len = strlen($line);
147 for($j=0;$j<$len;$j++)
149 $c = $line[$j]; // this is _really_ faster than subst
152 //look for start of quote
153 if(!$inQuote && !$inComment)
155 //is this character a quote or a comment
156 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
164 else if($d=="/*" && !$inNormalComment)
173 else if($d=="//") //ignore string markers that are found inside comments
175 $inNormalComment = true;
183 else //allready in a string so find end quote
185 if($c == $quoteChar && !$escaped && !$inComment)
190 //subsitute in a marker for the string
191 $clean .= "___" . count($literal_strings) . "___";
193 //push the string onto our array
194 array_push($literal_strings,$literal);
197 else if($inComment && $d=="*/")
202 //subsitute in a marker for the string
203 $clean .= "___" . count($literal_strings) . "___";
205 //push the string onto our array
206 array_push($literal_strings,$literal);
210 else if($c == "\\" && !$escaped)
218 if($inComment) $literal .= "\n";
221 //explode the clean string into lines again
222 $lines = explode("\n",$clean);
224 //now process each line at a time
225 for($i=0;$i<count($lines);$i++)
230 $line = preg_replace("/\/\/(.*)/","",$line);
232 //strip leading and trailing whitespace
235 //remove all whitespace with a single space
236 $line = preg_replace("/\s+/"," ",$line);
238 //remove any whitespace that occurs after/before an operator
239 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
245 $sJS = implode("\n",$lines);
247 //make sure there is a max of 1 \n after each line
248 $sJS = preg_replace("/[\n]+/","\n",$sJS);
250 //strip out line breaks that immediately follow a semi-colon
251 $sJS = preg_replace("/;\n/",";",$sJS);
253 //curly brackets aren't on their own
254 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
256 //finally loop through and replace all the literal strings:
257 for($i=0;$i<count($literal_strings);$i++) {
258 if (strpos($literal_strings[$i],"/*")!==false)
259 $literal_strings[$i]= '';
260 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
266 Check if file can be updated, restoring subdirectories
267 if needed. Returns 1 when no confilcts, -1 when file exists and is writable
269 function check_write($path)
271 if ($path == ''//|| $path == '.' || $path == '..'
274 return is_writable($path) ? (is_dir($path) ? 1 : -1)
275 : ($path =='.' ? 0 : check_write(dirname($path)));
279 Copies set of files. When $strict is set
280 also removes files from the $to which
281 does not exists in $from directory but arelisted in $flist.
283 function copy_files($flist, $from, $to, $strict=false)
285 foreach ($flist as $file) {
286 if (file_exists($from.'/'.$file))
287 if (!copy_file($file, $from, $to))
289 if ($strict && !is_file($from.'/'.$file)) // if
290 unlink($to.'/'.$file);
296 Copies file from base to target directory, restoring subdirectories
299 function copy_file($file, $from, $to)
302 if (!is_dir(dirname($file=='.' ? $to : ($to.'/'.$file)))) {
303 if (!copy_file(dirname($file), null, $to))
307 // error_log( 'dodanie katalogu '.$to.'/'.$file);
308 return @mkdir($file=='.' ? $to : ($to.'/'.$file));
311 // error_log( 'skopiowanie '.$to.'/'.$file);
312 return @copy($from.'/'.$file, $to.'/'.$file);
317 Search for file, looking first for company specific version, then for
318 version provided by any extension module, finally in main FA directory.
319 Also adds include path for any related files.
321 Returns found file path or null.
323 function find_custom_file($rep)
325 global $installed_extensions, $comp_path, $path_to_root;
327 // customized per company version
328 $path = $comp_path.'/'.user_company();
330 if (file_exists($file)) {
331 // add local include path
332 set_include_path($path.PATH_SEPARATOR.get_include_path());
335 // file added by active extension modules
336 if (count($installed_extensions) > 0)
338 $extensions = $installed_extensions;
339 foreach ($extensions as $ext)
340 if (($ext['active'] && $ext['type'] == 'extension')) {
341 $path = $path_to_root.'/'.$ext['path'];
343 if (file_exists($file)) {
344 set_include_path($path.PATH_SEPARATOR.get_include_path());
350 $file = $path_to_root.$rep;
351 if (file_exists($file))