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/types.inc");
15 include_once($path_to_root . "/includes/systypes.inc");
16 include_once($path_to_root . "/includes/references.inc");
17 include_once($path_to_root . "/includes/db/comments_db.inc");
18 include_once($path_to_root . "/includes/db/sql_functions.inc");
19 include_once($path_to_root . "/includes/db/audit_trail_db.inc");
20 //include_once($path_to_root . "/includes/validation.inc");
22 include_once($path_to_root . "/admin/db/users_db.inc");
23 include_once($path_to_root . "/includes/ui/ui_view.inc");
24 include_once($path_to_root . "/includes/ui/ui_controls.inc");
26 function page($title, $no_menu=false, $is_index=false, $onload="", $js="", $script_only=false, $css='')
29 global $path_to_root, $page_security;
32 $hide_menu = $no_menu;
34 include($path_to_root . "/includes/page/header.inc");
36 page_header($title, $no_menu, $is_index, $onload, $js, $css);
37 check_page_security($page_security);
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, $hide_back_link=false, $type_no=0, $trans_no=0)
53 if (!$is_index && !$hide_back_link && function_exists('hyperlink_back'))
54 hyperlink_back(true, $no_menu, $type_no, $trans_no);
55 div_end(); // end of _page_body section
57 include($path_to_root . "/includes/page/footer.inc");
58 page_footer($no_menu, $is_index, $hide_back_link);
61 function cache_js_file($fpath, $text)
65 if(!$go_debug) $text = js_compress($text);
67 $file = fopen($fpath, 'w');
68 if (!$file) return false;
69 if (!fwrite($file, $text)) return false;
74 function add_js_file($filename)
78 $search = array_search($filename, $js_static);
79 if ($search === false || $search === null) // php>4.2.0 returns null
80 $js_static[] = $filename;
83 function add_js_ufile($filename)
87 $search = array_search($filename, $js_userlib);
88 if ($search === false || $search === null) // php>4.2.0 returns null
89 $js_userlib[] = $filename;
92 function add_js_source($text)
96 $search = array_search($text, $js_lib);
97 if ($search === false || $search === null) // php>4.2.0 returns null
102 * Compresses the Javascript code for more efficient delivery.
103 * copyright (c) 2005 by Jared White & J. Max Wilson
104 * http://www.xajaxproject.org
105 * Added removing comments from output.
106 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
108 function js_compress($sJS)
110 //remove windows cariage returns
111 $sJS = str_replace("\r","",$sJS);
113 //array to store replaced literal strings
114 $literal_strings = array();
116 //explode the string into lines
117 $lines = explode("\n",$sJS);
118 //loop through all the lines, building a new string at the same time as removing literal strings
126 for($i=0;$i<count($lines);$i++)
129 $inNormalComment = false;
131 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
132 $len = strlen($line);
133 for($j=0;$j<$len;$j++)
135 $c = $line[$j]; // this is _really_ faster than subst
138 //look for start of quote
139 if(!$inQuote && !$inComment)
141 //is this character a quote or a comment
142 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
150 else if($d=="/*" && !$inNormalComment)
159 else if($d=="//") //ignore string markers that are found inside comments
161 $inNormalComment = true;
169 else //allready in a string so find end quote
171 if($c == $quoteChar && !$escaped && !$inComment)
176 //subsitute in a marker for the string
177 $clean .= "___" . count($literal_strings) . "___";
179 //push the string onto our array
180 array_push($literal_strings,$literal);
183 else if($inComment && $d=="*/")
188 //subsitute in a marker for the string
189 $clean .= "___" . count($literal_strings) . "___";
191 //push the string onto our array
192 array_push($literal_strings,$literal);
196 else if($c == "\\" && !$escaped)
204 if($inComment) $literal .= "\n";
207 //explode the clean string into lines again
208 $lines = explode("\n",$clean);
210 //now process each line at a time
211 for($i=0;$i<count($lines);$i++)
216 $line = preg_replace("/\/\/(.*)/","",$line);
218 //strip leading and trailing whitespace
221 //remove all whitespace with a single space
222 $line = preg_replace("/\s+/"," ",$line);
224 //remove any whitespace that occurs after/before an operator
225 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
231 $sJS = implode("\n",$lines);
233 //make sure there is a max of 1 \n after each line
234 $sJS = preg_replace("/[\n]+/","\n",$sJS);
236 //strip out line breaks that immediately follow a semi-colon
237 $sJS = preg_replace("/;\n/",";",$sJS);
239 //curly brackets aren't on their own
240 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
242 //finally loop through and replace all the literal strings:
243 for($i=0;$i<count($literal_strings);$i++) {
244 if (strpos($literal_strings[$i],"/*")!==false)
245 $literal_strings[$i]= '';
246 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
252 Check if file can be updated, restoring subdirectories
253 if needed. Returns 1 when no confilcts, -1 when file exists and is writable
255 function check_write($path)
257 if ($path == ''//|| $path == '.' || $path == '..'
260 return is_writable($path) ? (is_dir($path) ? 1 : -1)
261 : (is_file($path) ? 0 : ($path == '.' ? 0 : check_write(dirname($path))));
265 Copies set of files. When $strict is set
266 also removes files from the $to which
267 does not exists in $from directory but arelisted in $flist.
269 function copy_files($flist, $from, $to, $strict=false)
271 foreach ($flist as $file) {
272 if (file_exists($from.'/'.$file)) {
273 if (!copy_file($file, $from, $to))
275 } else if ($strict) {
276 unlink($to.'/'.$file);
283 Copies file from base to target directory, restoring subdirectories
286 function copy_file($file, $from, $to)
289 if (!is_dir(dirname($file=='.' ? $to : ($to.'/'.$file)))) {
290 if (!copy_file(dirname($file), null, $to))
294 // error_log( 'dodanie katalogu '.$to.'/'.$file);
295 return @mkdir($file=='.' ? $to : ($to.'/'.$file));
298 // error_log( 'skopiowanie '.$to.'/'.$file);
299 return @copy($from.'/'.$file, $to.'/'.$file);
303 Search for file, looking first for company specific version, then for
304 version provided by any extension module, finally in main FA directory.
305 Also adds include path for any related files, and sets $local_path_to_root
306 to enable local translation domains.
308 Returns found file path or null.
310 function find_custom_file($rep)
312 global $installed_extensions, $path_to_root, $local_path_to_root;
314 // customized per company version
315 $path = company_path();
317 if (file_exists($file)) {
318 // add local include path
319 $local_path_to_root = $path;
320 set_include_path(dirname($file).PATH_SEPARATOR.get_include_path());
323 // file added by active extension modules
324 if (count($installed_extensions) > 0)
326 $extensions = $installed_extensions;
327 foreach ($extensions as $ext)
328 if (($ext['active'] && $ext['type'] == 'extension')) {
329 $path = $path_to_root.'/'.$ext['path'];
331 if (file_exists($file)) {
332 set_include_path($path.PATH_SEPARATOR.get_include_path());
333 $local_path_to_root = $path;
339 $file = $path_to_root.$rep;
340 if (file_exists($file))
347 Protect against directory traversal.
348 Changes all not POSIX compatible chars to underscore.
350 function clean_file_name($filename) {
351 return preg_replace('/[^a-zA-Z0-9.\-_]/', '_', $filename);