From d23b97ed26bc0608c9ba1037b66058c709e83765 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Sun, 4 Apr 2010 12:11:22 +0000 Subject: [PATCH] company_path() helper used. --- admin/attachments.php | 8 ++++---- admin/company_preferences.php | 6 ++---- admin/create_coy.php | 13 +++++++------ admin/db/fiscalyears_db.inc | 3 +-- admin/display_prefs.php | 2 +- admin/print_profiles.php | 4 ++-- admin/system_diagnostics.php | 17 +++++++++-------- includes/lang/language.php | 4 ++-- includes/page/header.inc | 5 ++--- includes/ui/ui_view.inc | 4 ++-- inventory/manage/items.php | 14 +++++++------- reporting/includes/excel_report.inc | 4 ++-- reporting/includes/header2.inc | 2 +- reporting/rep102.php | 4 ++-- reporting/rep104.php | 4 ++-- reporting/rep202.php | 4 ++-- reporting/rep303.php | 4 ++-- reporting/rep706.php | 4 ++-- reporting/rep707.php | 4 ++-- 19 files changed, 54 insertions(+), 56 deletions(-) diff --git a/admin/attachments.php b/admin/attachments.php index a97843ca..ce4498f6 100644 --- a/admin/attachments.php +++ b/admin/attachments.php @@ -38,7 +38,7 @@ if ($view_id != -1) header('Content-Disposition: attachment; filename='.$row['filename']); else header("Content-Disposition: inline"); - echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']); + echo file_get_contents(company_path(). "/attachments/".$row['unique_name']); exit(); } } @@ -60,7 +60,7 @@ if ($download_id != -1) header("Content-type: ".$type); header('Content-Length: '.$row['filesize']); header('Content-Disposition: attachment; filename='.$row['filename']); - echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']); + echo file_get_contents(company_path()."/attachments/".$row['unique_name']); exit(); } } @@ -85,7 +85,7 @@ if ($Mode == 'ADD_ITEM' || $Mode == 'UPDATE_ITEM') //$content = base64_encode(file_get_contents($_FILES['filename']['tmp_name'])); $tmpname = $_FILES['filename']['tmp_name']; - $dir = $comp_path."/".user_company(). "/attachments"; + $dir = company_path()."/attachments"; if (!file_exists($dir)) { mkdir ($dir,0777); @@ -127,7 +127,7 @@ if ($Mode == 'ADD_ITEM' || $Mode == 'UPDATE_ITEM') if ($Mode == 'Delete') { $row = get_attachment($selected_id); - $dir = $comp_path."/".user_company(). "/attachments"; + $dir = company_path()."/attachments"; if (file_exists($dir."/".$row['unique_name'])) unlink($dir."/".$row['unique_name']); delete_attachment($selected_id); diff --git a/admin/company_preferences.php b/admin/company_preferences.php index 4acb8074..bc550789 100644 --- a/admin/company_preferences.php +++ b/admin/company_preferences.php @@ -40,9 +40,8 @@ if (isset($_POST['update']) && $_POST['update'] != "") } if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') { - $user_comp = user_company(); $result = $_FILES['pic']['error']; - $filename = $comp_path . "/$user_comp/images"; + $filename = company_path()."/images"; if (!file_exists($filename)) { mkdir($filename); @@ -86,8 +85,7 @@ if (isset($_POST['update']) && $_POST['update'] != "") } if (check_value('del_coy_logo')) { - $user_comp = user_company(); - $filename = $comp_path . "/$user_comp/images/".$_POST['coy_logo']; + $filename = company_path()."/images/".$_POST['coy_logo']; if (file_exists($filename)) { $result = unlink($filename); diff --git a/admin/create_coy.php b/admin/create_coy.php index 29acd007..aa765395 100644 --- a/admin/create_coy.php +++ b/admin/create_coy.php @@ -80,7 +80,7 @@ function remove_connection($id) { function handle_submit() { global $db_connections, $def_coy, $tb_pref_counter, $db, - $comp_path, $comp_subdirs, $path_to_root; + $comp_subdirs, $path_to_root; $new = false; $error = false; @@ -165,7 +165,7 @@ function handle_submit() if ($new) { - create_comp_dirs("$comp_path/$id", $comp_subdirs); + create_comp_dirs(company_path($id), $comp_subdirs); } $exts = get_company_extensions(); write_extensions($exts, $id); @@ -177,13 +177,14 @@ function handle_submit() function handle_delete() { - global $comp_path, $def_coy, $db_connections, $comp_subdirs, $path_to_root; + global $def_coy, $db_connections, $comp_subdirs, $path_to_root; $id = $_GET['id']; // First make sure all company directories from the one under removal are writable. // Without this after operation we end up with changed per-company owners! for($i = $id; $i < count($db_connections); $i++) { + $comp_path = company_path($i); if (!is_dir($comp_path.'/'.$i) || !is_writable($comp_path.'/'.$i)) { display_error(_('Broken company subdirectories system. You have to remove this company manually.')); return; @@ -198,15 +199,15 @@ function handle_delete() // rename directory to temporary name to ensure all // other subdirectories will have right owners even after // unsuccessfull removal. - $cdir = $comp_path.'/'.$id; - $tmpname = $comp_path.'/old_'.$id; + $cdir = company_path($id); + $tmpname = company_path('/old_'.$id); if (!@rename($cdir, $tmpname)) { display_error(_('Cannot rename subdirectory to temporary name.')); return; } // 'shift' company directories names for ($i = $id+1; $i < count($db_connections); $i++) { - if (!rename($comp_path.'/'.$i, $comp_path.'/'.($i-1))) { + if (!rename(company_path($i), company_path($i-1))) { display_error(_("Cannot rename company subdirectory")); return; } diff --git a/admin/db/fiscalyears_db.inc b/admin/db/fiscalyears_db.inc index cbd4784e..4dc32b69 100644 --- a/admin/db/fiscalyears_db.inc +++ b/admin/db/fiscalyears_db.inc @@ -159,13 +159,12 @@ function open_year($year) //--------------------------------------------------------------------------------------------- function delete_attachments_and_comments($type_no, $trans_no) { - global $comp_path; $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no"; $result = db_query($sql, "Could not retrieve attachments"); while ($row = db_fetch($result)) { - $dir = $comp_path."/".user_company(). "/attachments"; + $dir = company_path(). "/attachments"; if (file_exists($dir."/".$row['unique_name'])) unlink($dir."/".$row['unique_name']); $sql = "DELETE FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no"; diff --git a/admin/display_prefs.php b/admin/display_prefs.php index fb7004da..78809c0c 100644 --- a/admin/display_prefs.php +++ b/admin/display_prefs.php @@ -45,7 +45,7 @@ if (isset($_POST['setprefs'])) $_SESSION['language']->set_language($_POST['language']); // refresh main menu - flush_dir($comp_path.'/'.user_company().'/js_cache'); + flush_dir(company_path().'/js_cache'); if ($chg_theme || $chg_lang) meta_forward($_SERVER['PHP_SELF']); diff --git a/admin/print_profiles.php b/admin/print_profiles.php index 59f9ec80..f9972980 100644 --- a/admin/print_profiles.php +++ b/admin/print_profiles.php @@ -23,13 +23,13 @@ $selected_id = get_post('profile_id',''); // Returns array of defined reports // function get_reports() { - global $path_to_root, $comp_path, $go_debug; + global $path_to_root, $go_debug; if ($go_debug || !isset($_SESSION['reports'])) { // to save time, store in session. $paths = array ( $path_to_root.'/reporting/', - $comp_path .'/'. user_company() . '/reporting/'); + company_path(). '/reporting/'); $reports = array( '' => _('Default printing destination')); foreach($paths as $dirno => $path) { diff --git a/admin/system_diagnostics.php b/admin/system_diagnostics.php index 3b2bfbb8..44cd37ce 100644 --- a/admin/system_diagnostics.php +++ b/admin/system_diagnostics.php @@ -160,25 +160,26 @@ function tst_dbversion() function tst_subdirs() { - global $db_connections, $comp_path; + global $db_connections; $comp_subdirs = array('images', 'pdf_files', 'backup','js_cache'); $test['descr'] = _('Company subdirectories consistency'); $test['type'] = 3; - $test['test'] = array($comp_path.'/*'); + $test['test'] = array(company_path().'/*'); foreach($comp_subdirs as $sub) { - $test['test'][] = $comp_path.'/*/'.$sub; + $test['test'][] = company_path().'/*/'.$sub; } $test['result'] = true; - + + $comp_path = company_path(); if (!is_dir($comp_path) || !is_writable($comp_path) ) { $test['result'] = false; $test['comments'][] = sprintf(_("'%s' is not writeable"), $comp_path); return $test; }; foreach ($db_connections as $n => $comp) { - $path = "$comp_path/$n"; + $path = company_path($n); if (!is_dir($path) || !is_writable($path) ) { $test['result'] = false; $test['comments'][] = sprintf(_("'%s' is not writeable"), $path); @@ -272,17 +273,17 @@ function tst_dbconfig() function tst_extconfig() { - global $path_to_root, $db_connections, $comp_path; + global $path_to_root, $db_connections; $test['descr'] = _('Extensions configuration files'); $test['type'] = 3; $test['test'] = $path_to_root.'/installed_extensions.php'; $test['result'] = is_file($test['test']) && is_writable($test['test']); - $test['test'] . ','.$comp_path.'/*/installed_extensions.php'; + $test['test'] . ','.company_path().'/*/installed_extensions.php'; $test['comments'][] = sprintf(_("'%s' file should be writeable"), $test['test']); foreach ($db_connections as $n => $comp) { - $path = "$comp_path/$n"; + $path = company_path($n); if (!is_dir($path)) continue; $path .= "/installed_extensions.php"; diff --git a/includes/lang/language.php b/includes/lang/language.php index 824a528c..0b8ba215 100644 --- a/includes/lang/language.php +++ b/includes/lang/language.php @@ -47,7 +47,7 @@ class language function set_language($code) { - global $comp_path, $path_to_root, $installed_languages; + global $path_to_root, $installed_languages; $changed = $this->code != $code; $lang = array_search_value($code, $installed_languages, 'code'); @@ -55,7 +55,7 @@ class language if ($lang && $changed) { // flush cache as we can use several languages in one account - flush_dir($comp_path.'/'.user_company().'/js_cache'); + flush_dir(company_path().'/js_cache'); $this->name = $lang['name']; $this->code = $lang['code']; diff --git a/includes/page/header.inc b/includes/page/header.inc index b0364cbe..6d6fbdb8 100644 --- a/includes/page/header.inc +++ b/includes/page/header.inc @@ -47,13 +47,12 @@ function help_url($context=null) function send_scripts() { - global $js_lib, $js_static, $js_path, $js_userlib, $comp_path, - $path_to_root, $go_debug; + global $js_lib, $js_static, $js_path, $js_userlib, $path_to_root, $go_debug; $js =''; foreach($js_static as $jsfile) { - $fpath = $comp_path.'/'.user_company().'/js_cache/'.$jsfile; + $fpath = company_path().'/js_cache/'.$jsfile; // compress also static files if (!file_exists($fpath) || $go_debug) cache_js_file($fpath, file_get_contents($js_path.$jsfile)); diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index f2dc7646..fe54a261 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -799,8 +799,8 @@ function get_js_png_fix() function get_js_date_picker() { - global $comp_path, $go_debug; - $fpath = $comp_path.'/'.user_company().'/js_cache/'.'date_picker.js'; + global $go_debug; + $fpath = company_path().'/js_cache/'.'date_picker.js'; if (!file_exists($fpath) || $go_debug) { diff --git a/inventory/manage/items.php b/inventory/manage/items.php index 250b6578..900641ec 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -56,7 +56,7 @@ if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') $stock_id = $_POST['NewStockID']; $result = $_FILES['pic']['error']; $upload_file = 'Yes'; //Assume all is well to start off with - $filename = $comp_path . "/$user_comp/images"; + $filename = company_path().'/images'; if (!file_exists($filename)) { mkdir($filename); @@ -155,7 +155,7 @@ if (isset($_POST['addupdate'])) { if (check_value('del_image')) { - $filename = $comp_path . "/$user_comp/images/".item_img_name($_POST['NewStockID']).".jpg"; + $filename = company_path().'/images/'.item_img_name($_POST['NewStockID']).".jpg"; if (file_exists($filename)) unlink($filename); } @@ -228,7 +228,7 @@ if (isset($_POST['delete']) && strlen($_POST['delete']) > 1) $stock_id = $_POST['NewStockID']; delete_item($stock_id); - $filename = $comp_path . "/$user_comp/images/".item_img_name($stock_id).".jpg"; + $filename = company_path().'/images/'.item_img_name($stock_id).".jpg"; if (file_exists($filename)) unlink($filename); display_notification(_("Selected item has been deleted.")); @@ -388,14 +388,14 @@ file_row(_("Image File (.jpg)") . ":", 'pic', 'pic'); // Add Image upload for New Item - by Joe $stock_img_link = ""; $check_remove_image = false; -if (isset($_POST['NewStockID']) && file_exists("$comp_path/$user_comp/images/" +if (isset($_POST['NewStockID']) && file_exists(company_path().'/images/' .item_img_name($_POST['NewStockID']).".jpg")) { // 31/08/08 - rand() call is necessary here to avoid caching problems. Thanks to Peter D. $stock_img_link .= "[".$_POST["; - $check_remove_image = true; + "]' src='".company_path().'images/'.item_img_name($_POST['NewStockID']). + ".jpg?nocache=".rand()."'"." height='$pic_height' border='0'>"; + $check_remove_image = true; } else { diff --git a/reporting/includes/excel_report.inc b/reporting/includes/excel_report.inc index aca0e2c7..ceadc52f 100644 --- a/reporting/includes/excel_report.inc +++ b/reporting/includes/excel_report.inc @@ -58,7 +58,7 @@ class FrontReport extends Spreadsheet_Excel_Writer_Workbook function FrontReport($title, $filename, $size = 'A4', $fontsize = 9, $orientation = 'P', $margins = NULL, $excelColWidthFactor = 6.5) { - global $comp_path, $dateseps, $page_security; + global $dateseps, $page_security; if (!$_SESSION["wa_current_user"]->can_access_page($page_security)) { display_error(_("The security settings on your account do not permit you to print this report")); @@ -78,7 +78,7 @@ class FrontReport extends Spreadsheet_Excel_Writer_Workbook $this->code = strtolower($_SESSION['language']->encoding); $this->filename = $filename.".xls"; $this->unique_name = uniqid('').".xls"; - $this->path = $comp_path.'/'.user_company(). '/pdf_files'; + $this->path = company_path(). '/pdf_files'; $this->Spreadsheet_Excel_Writer_Workbook($this->path."/".$this->unique_name); //$this->setCountry(48); if ($this->code != "iso-8859-1") diff --git a/reporting/includes/header2.inc b/reporting/includes/header2.inc index 42d99bac..14188101 100644 --- a/reporting/includes/header2.inc +++ b/reporting/includes/header2.inc @@ -59,7 +59,7 @@ $this->NewLine(); if ($this->company['coy_logo'] != '') { - $logo = $comp_path .'/'. user_company() . "/images/" . $this->company['coy_logo']; + $logo = company_path() . "/images/" . $this->company['coy_logo']; $this->AddImage($logo, $ccol, $this->row, 0, 40); } else diff --git a/reporting/rep102.php b/reporting/rep102.php index a2f938c0..62128b50 100644 --- a/reporting/rep102.php +++ b/reporting/rep102.php @@ -64,7 +64,7 @@ function get_invoices($customer_id, $to) function print_aged_customer_analysis() { - global $comp_path, $path_to_root, $systypes_array; + global $path_to_root, $systypes_array; $to = $_POST['PARAM_0']; $fromcust = $_POST['PARAM_1']; @@ -228,7 +228,7 @@ function print_aged_customer_analysis() $pg->built_in = false; $pg->fontfile = $path_to_root . "/reporting/fonts/Vera.ttf"; $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != "."); - $filename = $comp_path .'/'. user_company(). "/images/test.png"; + $filename = company_path(). "/images/test.png"; $pg->display($filename, true); $w = $pg->width / 1.5; $h = $pg->height / 1.5; diff --git a/reporting/rep104.php b/reporting/rep104.php index 2c34f63a..e952eacb 100644 --- a/reporting/rep104.php +++ b/reporting/rep104.php @@ -66,7 +66,7 @@ function get_kits($category=0) function print_price_listing() { - global $comp_path, $path_to_root, $pic_height, $pic_width; + global $path_to_root, $pic_height, $pic_width; $currency = $_POST['PARAM_0']; $category = $_POST['PARAM_1']; @@ -159,7 +159,7 @@ function print_price_listing() } if ($pictures) { - $image = $comp_path . '/'. $user_comp . "/images/" + $image = company_path(). "/images/" . item_img_name($myrow['stock_id']) . ".jpg"; if (file_exists($image)) { diff --git a/reporting/rep202.php b/reporting/rep202.php index b443e6d7..2915fc8f 100644 --- a/reporting/rep202.php +++ b/reporting/rep202.php @@ -65,7 +65,7 @@ function get_invoices($supplier_id, $to) function print_aged_supplier_analysis() { - global $comp_path, $path_to_root, $systypes_array; + global $path_to_root, $systypes_array; $to = $_POST['PARAM_0']; $fromsupp = $_POST['PARAM_1']; @@ -230,7 +230,7 @@ function print_aged_supplier_analysis() $pg->built_in = false; $pg->fontfile = $path_to_root . "/reporting/fonts/Vera.ttf"; $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != "."); - $filename = $comp_path.'/'.user_company(). "/pdf_files/test.png"; + $filename = company_path(). "/pdf_files/test.png"; $pg->display($filename, true); $w = $pg->width / 1.5; $h = $pg->height / 1.5; diff --git a/reporting/rep303.php b/reporting/rep303.php index 1cd151a6..73f58ee5 100644 --- a/reporting/rep303.php +++ b/reporting/rep303.php @@ -61,7 +61,7 @@ function getTransactions($category, $location) function print_stock_check() { - global $comp_path, $path_to_root, $pic_height, $pic_width; + global $path_to_root, $pic_height, $pic_width; $category = $_POST['PARAM_0']; $location = $_POST['PARAM_1']; @@ -174,7 +174,7 @@ function print_stock_check() } if ($pictures) { - $image = $comp_path .'/'. $user_comp . '/images/' + $image = company_path() . '/images/' . item_img_name($trans['stock_id']) . '.jpg'; if (file_exists($image)) { diff --git a/reporting/rep706.php b/reporting/rep706.php index 529893d7..6f36b2f3 100644 --- a/reporting/rep706.php +++ b/reporting/rep706.php @@ -122,7 +122,7 @@ print_balance_sheet(); function print_balance_sheet() { - global $comp_path, $path_to_root; + global $path_to_root; $dim = get_company_pref('use_dimension'); $dimension = $dimension2 = 0; @@ -297,7 +297,7 @@ function print_balance_sheet() $pg->built_in = false; $pg->fontfile = $path_to_root . "/reporting/fonts/Vera.ttf"; $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != "."); - $filename = $comp_path.'/'.user_company(). "/pdf_files/test.png"; + $filename = company_path(). "/pdf_files/test.png"; $pg->display($filename, true); $w = $pg->width / 1.5; $h = $pg->height / 1.5; diff --git a/reporting/rep707.php b/reporting/rep707.php index c4ef3b6d..55bf0aa9 100644 --- a/reporting/rep707.php +++ b/reporting/rep707.php @@ -144,7 +144,7 @@ function Achieve($d1, $d2) function print_profit_and_loss_statement() { - global $comp_path, $path_to_root; + global $path_to_root; $dim = get_company_pref('use_dimension'); $dimension = $dimension2 = 0; @@ -316,7 +316,7 @@ function print_profit_and_loss_statement() $pg->built_in = false; $pg->fontfile = $path_to_root . "/reporting/fonts/Vera.ttf"; $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != "."); - $filename = $comp_path.'/'.user_company(). "/pdf_files/test.png"; + $filename = company_path(). "/pdf_files/test.png"; $pg->display($filename, true); $w = $pg->width / 1.5; $h = $pg->height / 1.5; -- 2.30.2