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, $type_no=0, $trans_no=0)
54 if (!$is_index && !$hide_back_link && function_exists('hyperlink_back'))
55 hyperlink_back(true, $no_menu, $type_no, $trans_no);
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 cache_js_file($fpath, $text)
66 if(!$go_debug) $text = js_compress($text);
68 $file = fopen($fpath, 'w');
69 if (!$file) return false;
70 if (!fwrite($file, $text)) return false;
75 function add_js_file($filename)
79 $search = array_search($filename, $js_static);
80 if ($search === false || $search === null) // php>4.2.0 returns null
81 $js_static[] = $filename;
84 function add_js_ufile($filename)
88 $search = array_search($filename, $js_userlib);
89 if ($search === false || $search === null) // php>4.2.0 returns null
90 $js_userlib[] = $filename;
93 function add_js_source($text)
97 $search = array_search($text, $js_lib);
98 if ($search === false || $search === null) // php>4.2.0 returns null
103 * Compresses the Javascript code for more efficient delivery.
104 * copyright (c) 2005 by Jared White & J. Max Wilson
105 * http://www.xajaxproject.org
106 * Added removing comments from output.
107 * Warning: Fails on RegExp with quotes - use new RegExp() in this case.
109 function js_compress($sJS)
111 //remove windows cariage returns
112 $sJS = str_replace("\r","",$sJS);
114 //array to store replaced literal strings
115 $literal_strings = array();
117 //explode the string into lines
118 $lines = explode("\n",$sJS);
119 //loop through all the lines, building a new string at the same time as removing literal strings
127 for($i=0;$i<count($lines);$i++)
130 $inNormalComment = false;
132 //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
133 $len = strlen($line);
134 for($j=0;$j<$len;$j++)
136 $c = $line[$j]; // this is _really_ faster than subst
139 //look for start of quote
140 if(!$inQuote && !$inComment)
142 //is this character a quote or a comment
143 if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
151 else if($d=="/*" && !$inNormalComment)
160 else if($d=="//") //ignore string markers that are found inside comments
162 $inNormalComment = true;
170 else //allready in a string so find end quote
172 if($c == $quoteChar && !$escaped && !$inComment)
177 //subsitute in a marker for the string
178 $clean .= "___" . count($literal_strings) . "___";
180 //push the string onto our array
181 array_push($literal_strings,$literal);
184 else if($inComment && $d=="*/")
189 //subsitute in a marker for the string
190 $clean .= "___" . count($literal_strings) . "___";
192 //push the string onto our array
193 array_push($literal_strings,$literal);
197 else if($c == "\\" && !$escaped)
205 if($inComment) $literal .= "\n";
208 //explode the clean string into lines again
209 $lines = explode("\n",$clean);
211 //now process each line at a time
212 for($i=0;$i<count($lines);$i++)
217 $line = preg_replace("/\/\/(.*)/","",$line);
219 //strip leading and trailing whitespace
222 //remove all whitespace with a single space
223 $line = preg_replace("/\s+/"," ",$line);
225 //remove any whitespace that occurs after/before an operator
226 $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
232 $sJS = implode("\n",$lines);
234 //make sure there is a max of 1 \n after each line
235 $sJS = preg_replace("/[\n]+/","\n",$sJS);
237 //strip out line breaks that immediately follow a semi-colon
238 $sJS = preg_replace("/;\n/",";",$sJS);
240 //curly brackets aren't on their own
241 $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
243 //finally loop through and replace all the literal strings:
244 for($i=0;$i<count($literal_strings);$i++) {
245 if (strpos($literal_strings[$i],"/*")!==false)
246 $literal_strings[$i]= '';
247 $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
253 Check if file can be updated, restoring subdirectories
254 if needed. Returns 1 when no confilcts, -1 when file exists and is writable
256 function check_write($path)
258 if ($path == ''//|| $path == '.' || $path == '..'
261 return is_writable($path) ? (is_dir($path) ? 1 : -1)
262 : ($path =='.' ? 0 : check_write(dirname($path)));
266 Copies set of files. When $strict is set
267 also removes files from the $to which
268 does not exists in $from directory but arelisted in $flist.
270 function copy_files($flist, $from, $to, $strict=false)
272 foreach ($flist as $file) {
273 if (file_exists($from.'/'.$file))
274 if (!copy_file($file, $from, $to))
276 if ($strict && !is_file($from.'/'.$file)) // if
277 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.
307 Returns found file path or null.
309 function find_custom_file($rep)
311 global $installed_extensions, $comp_path, $path_to_root;
313 // customized per company version
314 $path = company_path();
315 $file = $path.'/'.$rep;
316 if (file_exists($file)) {
317 // add local include path
318 set_include_path($path.PATH_SEPARATOR.get_include_path());
321 // file added by active extension modules
322 if (count($installed_extensions) > 0)
324 $extensions = $installed_extensions;
325 foreach ($extensions as $ext)
326 if (($ext['active'] && $ext['type'] == 'extension')) {
327 $path = $path_to_root.'/'.$ext['path'];
329 if (file_exists($file)) {
330 set_include_path($path.PATH_SEPARATOR.get_include_path());
336 $file = $path_to_root.$rep;
337 if (file_exists($file))