From 1273d798e494986d5d35b885ccbd0ccaaa0c2695 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 25 Mar 2008 10:37:39 +0000 Subject: [PATCH] Moving company data storage to company subdirectory --- admin/backups.php | 14 +++--- admin/create_coy.php | 77 ++++++++++++++++++++++--------- admin/db/maintenance_db.inc | 14 +++--- install/index.php | 18 +++----- inventory/manage/items.php | 8 ++-- reporting/includes/pdf_report.inc | 10 ++-- reporting/pdf_files/index.php | 3 -- reporting/rep102.php | 6 +-- reporting/rep104.php | 4 +- reporting/rep202.php | 4 +- reporting/rep303.php | 4 +- reporting/rep706.php | 4 +- reporting/rep707.php | 4 +- 13 files changed, 99 insertions(+), 71 deletions(-) delete mode 100644 reporting/pdf_files/index.php diff --git a/admin/backups.php b/admin/backups.php index dd73be6d..3286f48c 100644 --- a/admin/backups.php +++ b/admin/backups.php @@ -46,7 +46,7 @@ echo " alert('" . _('This extension can not be be viewed: ') . "' + ext) return } - window.open('" . $path_to_root . BACKUP_PATH . "'+pFilename, '', 'toolbar=no,scrollbars=yes') + window.open('" . BACKUP_PATH . "'+pFilename, '', 'toolbar=no,scrollbars=yes') } function deleteBackup() { pFilename = document.forms[0].cmb_backups.options[document.forms[0].cmb_backups.selectedIndex].value @@ -128,14 +128,14 @@ function handle_form($conn) //Download the file if ($_GET['c']=='d') { - download_file($path_to_root . BACKUP_PATH . $_GET['fn']); + download_file(BACKUP_PATH . $_GET['fn']); exit; } //Delete the file if ($_GET['c']=='df') { $filename = $_GET['fn']; - @unlink($path_to_root . BACKUP_PATH . $filename); + @unlink(BACKUP_PATH . $filename); header("Location: backups.php?c=dff&fn=" . urlencode($filename)); return ""; } @@ -166,7 +166,7 @@ function handle_form($conn) if ($_GET['c']=='r') { $filename=$_GET['fn']; - restore_backup($path_to_root . BACKUP_PATH . $filename, $conn); + restore_backup(BACKUP_PATH . $filename, $conn); header("Location: backups.php?c=rs&fn=" . urlencode($filename)); return ""; } @@ -217,7 +217,7 @@ function get_backup_file_combo() global $path_to_root; $ar_files = array(); - $dh = opendir($path_to_root . BACKUP_PATH); + $dh = opendir(BACKUP_PATH); while (($file = readdir($dh)) !== false) $ar_files[] = $file; closedir($dh); @@ -266,8 +266,8 @@ function valid_paths() global $path_to_root; $st = ""; - if (!file_exists($path_to_root . BACKUP_PATH)) - $st .= "   - " . _("cannot find backup directory") . " - " . $path_to_root . BACKUP_PATH . "
"; + if (!file_exists(BACKUP_PATH)) + $st .= "   - " . _("cannot find backup directory") . " - " . BACKUP_PATH . "
"; return $st; } diff --git a/admin/create_coy.php b/admin/create_coy.php index 2730b7cf..b43224ab 100644 --- a/admin/create_coy.php +++ b/admin/create_coy.php @@ -11,6 +11,7 @@ include_once($path_to_root . "/includes/ui.inc"); page(_("Create/Update Company")); +$comp_subdirs = array('images', 'pdf_files', 'backup','js_cache'); //--------------------------------------------------------------------------------------------- @@ -34,9 +35,24 @@ function check_data() //--------------------------------------------------------------------------------------------- +function remove_connection($id) { + global $db_connections; + + $dbase = $db_connections[$id]['dbname']; + $err = db_drop_db($db_connections[$id]); + + unset($db_connections[$id]); + $conn = array_values($db_connections); + $db_connections = $conn; + //$$db_connections = array_values($db_connections); + return $err; +} +//--------------------------------------------------------------------------------------------- + function handle_submit() { - global $db_connections, $def_coy, $tb_pref_counter, $db; + global $db_connections, $def_coy, $tb_pref_counter, $db, + $comp_path, $comp_subdirs; $new = false; @@ -64,21 +80,13 @@ function handle_submit() } if ((bool)$_POST['def'] == true) $def_coy = $id; - $error = write_config_db($new); - if ($error == -1) - display_error(_("Cannot open the configuration file - ") . $path_to_root . "/config_db.php"); - else if ($error == -2) - display_error(_("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php"); - else if ($error == -3) - display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation.")); - if ($error != 0) - return false; if (isset($_GET['ul']) && $_GET['ul'] == 1) { $conn = $db_connections[$id]; if (($db = db_create_db($conn)) == 0) { display_error(_("Error creating Database: ") . $conn['dbname'] . _(", Please create it manually")); + remove_connection($id); set_global_connection(); return false; } @@ -98,6 +106,28 @@ function handle_submit() } set_global_connection(); } + $error = write_config_db($new); + if ($error == -1) + display_error(_("Cannot open the configuration file - ") . $path_to_root . "/config_db.php"); + else if ($error == -2) + display_error(_("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php"); + else if ($error == -3) + display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation.")); + if ($error != 0) { + return false; + } + $index = ""; + + if ($new) { + $cdir = $comp_path.'/'.($tb_pref_counter-1); + @mkdir($cdir); + save_to_file($cdir.'/'.'index.php', 0, $index); + + foreach($comp_subdirs as $dir) { + @mkdir($cdir.'/'.$dir); + save_to_file($cdir.'/'.$dir.'/'.'index.php', 0, $index); + } + } return true; } @@ -105,18 +135,18 @@ function handle_submit() function handle_delete() { - global $def_coy, $db_connections; + global $comp_path, $def_coy, $db_connections, $comp_subdirs; $id = $_GET['id']; - $dbase = $db_connections[$id]['dbname']; - $err = db_drop_db($db_connections[$id]); + $pref = $db_connections[$id]['tbpref']; + if($pref!='') + $pref = substr($pref, 0, strlen($pref)-1); - unset($db_connections[$id]); - $conn = array_values($db_connections); - $db_connections = $conn; + $err = remove_connection($id); + if ($err == 0) + display_error(_("Error removing Database: ") . $dbase . _(", please remove it manuallly")); - //$$db_connections = array_values($db_connections); if ($def_coy == $id) $def_coy = 0; $error = write_config_db(); @@ -128,10 +158,15 @@ function handle_delete() display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation.")); if ($error != 0) return; - if ($err == 0) - display_error(_("Error removing Database: ") . $dbase . _(", please remove it manuallly")); - else - meta_forward($_SERVER['PHP_SELF']); + + $cdir = $comp_path.'/'.$pref; + flush_dir($cdir); + if (!rmdir($cdir)) { + display_error(_("Cannot remove company data directory ") . $cdir); + return; + } + + meta_forward($_SERVER['PHP_SELF']); } //--------------------------------------------------------------------------------------------- diff --git a/admin/db/maintenance_db.inc b/admin/db/maintenance_db.inc index 8ed6b7df..49073666 100644 --- a/admin/db/maintenance_db.inc +++ b/admin/db/maintenance_db.inc @@ -96,7 +96,7 @@ function db_drop_db($connection) // get table structures foreach ($all_tables as $table) { - if (strpos($table['Name'], $connection["tbpref"]) !== false) + if (strpos($table['Name'], $connection["tbpref"]) === 0) db_query("DROP TABLE `".$table['Name'] . "`"); } //deleting the tables, how?? @@ -435,7 +435,7 @@ function db_export($conn, $filename, $zip='no', $comment='') } elseif ($error) { - @unlink($path_to_root . BACKUP_PATH . $backupfile); + @unlink(BACKUP_PATH . $backupfile); return false; } @@ -453,7 +453,7 @@ function db_export($conn, $filename, $zip='no', $comment='') } else { - @unlink($path_to_root . BACKUP_PATH . $backupfile); + @unlink(BACKUP_PATH . $backupfile); return false; } @@ -468,7 +468,7 @@ function db_export($conn, $filename, $zip='no', $comment='') } else { - @unlink($path_to_root . BACKUP_PATH . $backupfile); + @unlink(BACKUP_PATH . $backupfile); return false; } return $backupfile; @@ -531,7 +531,7 @@ function save_to_file($backupfile, $zip, $fileData) if ($zip == "gzip") { - if ($zp = @gzopen($path_to_root . BACKUP_PATH . $backupfile, "a9")) + if ($zp = @gzopen(BACKUP_PATH . $backupfile, "a9")) { @gzwrite($zp, $fileData); @gzclose($zp); @@ -607,7 +607,7 @@ function save_to_file($backupfile, $zip, $fileData) // total # of entries "on this disk", total # of entries overall, size of central dir, offset to start of central dir, .zip file comment length $fileData .= pack('v', 1) . pack('v', 1) . pack('V', strlen($cdrec)) . pack('V', strlen($fr)) . "\x00\x00"; - if ($zp = @fopen($path_to_root . BACKUP_PATH . $backupfile, "a")) + if ($zp = @fopen(BACKUP_PATH . $backupfile, "a")) { @fwrite($zp, $fileData); @fclose($zp); @@ -622,7 +622,7 @@ function save_to_file($backupfile, $zip, $fileData) } else { - if ($zp = @fopen($path_to_root . BACKUP_PATH . $backupfile, "a")) + if ($zp = @fopen(BACKUP_PATH . $backupfile, "a")) { @fwrite($zp, $fileData); @fclose($zp); diff --git a/install/index.php b/install/index.php index 65ce6668..68f3b354 100644 --- a/install/index.php +++ b/install/index.php @@ -1,5 +1,4 @@ @@ -128,20 +128,16 @@ function change_os(type) { config_db.php Writeable'; } elseif(!file_exists($path_to_root.'/config_db.php')) { echo 'File Not Found'; } else { echo 'Unwriteable'; } ?> - inventory/manage/image/ - Writeable'; } elseif(!file_exists($path_to_root.'/inventory/manage/image/')) { echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> + modules/ + Writeable'; } elseif(!file_exists($path_to_root.'/lang/')) { echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> lang/ Writeable'; } elseif(!file_exists($path_to_root.'/lang/')) { echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> - reporting/pdf_files/ - Writeable'; } elseif(!file_exists($path_to_root.'/reporting/pdf_files/')) { echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> - - - modules/ - Writeable'; } elseif(!file_exists($path_to_root.'/lang/')) { echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> - admin/backup/ - Writeable'; } elseif(!file_exists($path_to_root.'/admin/backup/')) { echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> + + Writeable'; } elseif(!file_exists($comp_path)) { + echo 'Directory Not Found'; } else { echo 'Unwriteable'; } ?> diff --git a/inventory/manage/items.php b/inventory/manage/items.php index 486a3d16..4a954d34 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -39,7 +39,7 @@ if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') { $result = $_FILES['pic']['error']; $upload_file = 'Yes'; //Assume all is well to start off with - $filename = $path_to_root . "/inventory/manage/image/$user_comp/"; + $filename = $comp_path . "/$user_comp/images"; if (!file_exists($filename)) { mkdir($filename); @@ -206,7 +206,7 @@ if (isset($_POST['delete']) && strlen($_POST['delete']) > 1) $stock_id = $_POST['NewStockID']; delete_item($stock_id); - $filename = $path_to_root . "/inventory/manage/image/$user_comp/$stock_id.jpg"; + $filename = $comp_path . "/$user_comp/images/$stock_id.jpg"; if (file_exists($filename)) unlink($filename); meta_forward($_SERVER['PHP_SELF']); @@ -300,9 +300,9 @@ start_table("$table_style2 width=40%"); start_row(); label_cells(_("Image File (.jpg)") . ":", ""); // Add Image upload for New Item - by Joe -if (isset($_POST['NewStockID']) && file_exists("$path_to_root/inventory/manage/image/$user_comp/".$_POST['NewStockID'].".jpg")) +if (isset($_POST['NewStockID']) && file_exists("$comp_path/$user_comp/images/".$_POST['NewStockID'].".jpg")) { - $stock_img_link = ""; + $stock_img_link = ""; } else { diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index 05bb203e..71589758 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -3,7 +3,7 @@ $page_security = 8; include_once($path_to_root . "reporting/includes/class.pdf.inc"); include_once($path_to_root . "admin/db/company_db.inc"); - +include_once($path_to_root . "config.php"); class FrontReport extends Cpdf { var $size; @@ -265,7 +265,7 @@ class FrontReport extends Cpdf function Header2($myrow, $branch, $sales_order, $bankaccount, $doctype) { - global $path_to_root, $print_as_quote, $print_invoice_no; + global $comp_path, $path_to_root, $print_as_quote, $print_invoice_no; $this->pageNumber++; if ($this->pageNumber > 1) @@ -325,7 +325,7 @@ class FrontReport extends Cpdf $this->row = $upper - 2 * $this->lineHeight - 2; if ($this->company['coy_logo'] != '') { - $logo = $path_to_root . "themes/default/images/" . $this->company['coy_logo']; + $logo = $comp_path .'/'. user_company() . "/images/" . $this->company['coy_logo']; $this->AddImage($logo, $ccol, $iline1 + 5, 250, 40); } else @@ -604,7 +604,7 @@ class FrontReport extends Cpdf function End($email=0, $subject=null, $myrow=null, $doctype = 0) { - global $go_debug, $path_to_root; + global $go_debug, $path_to_root, $comp_path; // this is no good in IE so has been replaced, see down under // but good for debugging purposes in IE @@ -631,7 +631,7 @@ class FrontReport extends Cpdf { $buf = $this->output(); $len = strlen($buf); - $dir = './pdf_files'; + $dir = $comp_path.'/'.user_company(). '/pdf_files'; //save the file if (!file_exists($dir)) { diff --git a/reporting/pdf_files/index.php b/reporting/pdf_files/index.php deleted file mode 100644 index 763940a7..00000000 --- a/reporting/pdf_files/index.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/reporting/rep102.php b/reporting/rep102.php index ffe022f8..508844da 100644 --- a/reporting/rep102.php +++ b/reporting/rep102.php @@ -98,7 +98,7 @@ function get_invoices($costomer_id, $to) function print_aged_customer_analysis() { - global $path_to_root; + global $comp_path, $path_to_root; include_once($path_to_root . "reporting/includes/pdf_report.inc"); @@ -228,7 +228,7 @@ function print_aged_customer_analysis() $rep->Line($rep->row + 4); $rep->NewLine(); } - $rep->fontSize += 2; + $rep->fontSize += 2; $rep->TextCol(0, 3, _('Grand Total')); $rep->fontSize -= 2; for ($i = 0; $i < count($total); $i++) @@ -253,7 +253,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 = $path_to_root . "reporting/pdf_files/test.png"; + $filename = $comp_path .'/'. user_company(). "/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 dd30a316..899da054 100644 --- a/reporting/rep104.php +++ b/reporting/rep104.php @@ -54,7 +54,7 @@ function get_prices($category=0, $salestype=0) function print_price_listing() { - global $path_to_root, $pic_height, $pic_width; + global $comp_path, $path_to_root, $pic_height, $pic_width; include_once($path_to_root . "reporting/includes/pdf_report.inc"); @@ -145,7 +145,7 @@ function print_price_listing() } if ($pictures) { - $image = $path_to_root . "inventory/manage/image/" . $user_comp . "/" . $myrow['stock_id'] . ".jpg"; + $image = $comp_path . '/'. $user_comp . "/images/" . $myrow['stock_id'] . ".jpg"; if (file_exists($image)) { $rep->NewLine(); diff --git a/reporting/rep202.php b/reporting/rep202.php index 6c23b634..ce39dd86 100644 --- a/reporting/rep202.php +++ b/reporting/rep202.php @@ -107,7 +107,7 @@ function get_invoices($supplier_id, $to) function print_aged_supplier_analysis() { - global $path_to_root; + global $comp_path, $path_to_root; include_once($path_to_root . "reporting/includes/pdf_report.inc"); @@ -268,7 +268,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 = $path_to_root . "reporting/pdf_files/test.png"; + $filename = $comp_path.'/'.user_company(). "/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 801561f1..bb0fc86d 100644 --- a/reporting/rep303.php +++ b/reporting/rep303.php @@ -94,7 +94,7 @@ function getDemandAsmQty($stockid, $location) function print_stock_check() { - global $path_to_root, $pic_height, $pic_width; + global $comp_path, $path_to_root, $pic_height, $pic_width; include_once($path_to_root . "reporting/includes/pdf_report.inc"); @@ -166,7 +166,7 @@ function print_stock_check() $rep->TextCol(4, 5, number_format2($trans['QtyOnHand'] - $demandqty, $dec)); if ($pictures) { - $image = $path_to_root . "inventory/manage/image/" . $user_comp . "/" . $trans['stock_id'] . ".jpg"; + $image = $comp_path .'/'. $user_comp . '/images/' . $trans['stock_id'] . '.jpg'; if (file_exists($image)) { $rep->NewLine(); diff --git a/reporting/rep706.php b/reporting/rep706.php index 9f20eb6b..68b52f98 100644 --- a/reporting/rep706.php +++ b/reporting/rep706.php @@ -24,7 +24,7 @@ print_balance_sheet(); function print_balance_sheet() { - global $path_to_root; + global $comp_path, $path_to_root; include_once($path_to_root . "reporting/includes/pdf_report.inc"); $dim = get_company_pref('use_dimension'); @@ -259,7 +259,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 = $path_to_root . "reporting/pdf_files/test.png"; + $filename = $comp_path.'/'.user_company()."/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 7059d837..1228e10b 100644 --- a/reporting/rep707.php +++ b/reporting/rep707.php @@ -37,7 +37,7 @@ function Achieve($d1, $d2) function print_profit_and_loss_statement() { - global $path_to_root; + global $comp_path, $path_to_root; include_once($path_to_root . "reporting/includes/pdf_report.inc"); $dim = get_company_pref('use_dimension'); @@ -295,7 +295,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 = $path_to_root . "reporting/pdf_files/test.png"; + $filename = $comp_path.'/'.user_company(). ."/pdf_files/test.png"; $pg->display($filename, true); $w = $pg->width / 1.5; $h = $pg->height / 1.5; -- 2.30.2