From 1b77725d52b62a154ef2ea579621ba7a02178996 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Sun, 30 Dec 2007 00:34:29 +0000 Subject: [PATCH] Added a variable, $print_invoice_no, in config.php for printing the invoice number instead of invoice reference. Changed the PDF presentation to deleting the Javascript cache before presentation. Fixed a bug when exporting database. Exported NULL field values from NO to empty field (from mysql version 5.0.32). Also fixed a unneccessary str_replace when importing sql scripts. --- CHANGELOG.txt | 10 ++ admin/db/maintenance_db.inc | 252 +++++++++++++++--------------- config.php | 5 +- reporting/includes/pdf_report.inc | 164 ++++++++++--------- 4 files changed, 228 insertions(+), 203 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 05243b00..2c3c3559 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,16 @@ Legend: ! -> Note $ -> Affected files +29-Dec-2007 Joe Hunt + ! Added a variable, $print_invoice_no, in config.sys for printing the invoice number instead of invoice reference. + $ config.php + + # Fixed a bug when exporting database. Exported NULL field values from NO to empty field (from mysql version 5.0.32). + Also fixed a unneccessary str_replace when importing sql scripts. + ! Changed the PDF presentation to deleting the Javascript cache before presentation. + $ /admin/db/maintenance_db.inc + /reporting/includes/pdf_report.inc + 13-Dec-2007 Joe Hunt # Still bugs in trial balances and account inquiry on screen when selecting non balance accounts. Fixed. $ /gl/inquiry/gl_trial_balance.php diff --git a/admin/db/maintenance_db.inc b/admin/db/maintenance_db.inc index 2d233d87..840b493b 100644 --- a/admin/db/maintenance_db.inc +++ b/admin/db/maintenance_db.inc @@ -18,8 +18,8 @@ function write_config_db($new = false) $msg .= "- DatabaseName is the name of the database as defined in the RDMS being used. Typically RDMS allow many databases to be maintained under the same server.\n"; $msg .= " The scripts for MySQL provided use the name logicworks */\n\n\n"; - $msg .= "\$def_coy = " . $def_coy . ";\n\n"; - $msg .= "\$tb_pref_counter = " . $tb_pref_counter . ";\n\n"; + $msg .= "\$def_coy = " . $def_coy . ";\n\n"; + $msg .= "\$tb_pref_counter = " . $tb_pref_counter . ";\n\n"; $msg .= "\$db_connections = array (\n"; $msg .= "\t0 => "; for ($i = 0; $i < $n; $i++) @@ -42,15 +42,15 @@ function write_config_db($new = false) $filename = $path_to_root . "/config_db.php"; // Check if the file exists and is writable first. - if (file_exists($filename) && is_writable($filename)) + if (file_exists($filename) && is_writable($filename)) { - if (!$zp = fopen($filename, 'w')) + if (!$zp = fopen($filename, 'w')) { return -1; - } - else + } + else { - if (!fwrite($zp, $msg)) + if (!fwrite($zp, $msg)) { fclose($zp); return -2; @@ -58,8 +58,8 @@ function write_config_db($new = false) // Close file fclose($zp); } - } - else + } + else { return -3; } @@ -75,8 +75,8 @@ function db_create_db($connection) $sql = "CREATE DATABASE " . $connection["dbname"] . ""; if (!mysql_query($sql)) return 0; - mysql_select_db($connection["dbname"], $db); - } + mysql_select_db($connection["dbname"], $db); + } return $db; } @@ -91,10 +91,10 @@ function db_drop_db($connection) { $res = db_query("show table status"); $all_tables = array(); - while($row = db_fetch($res)) + while($row = db_fetch($res)) $all_tables[] = $row; // get table structures - foreach ($all_tables as $table) + foreach ($all_tables as $table) { if (strpos($table['Name'], $connection["tbpref"]) !== false) db_query("DROP TABLE `".$table['Name'] . "`"); @@ -102,9 +102,9 @@ function db_drop_db($connection) //deleting the tables, how?? return true; } -} +} -function db_import($filename, $connection) +function db_import($filename, $connection) { $data_queries = array(); $drop_queries = array(); @@ -115,7 +115,7 @@ function db_import($filename, $connection) $lines = db_ungzip("lines", $filename); elseif (strpos($filename, ".zip") || strpos($filename, ".ZIP")) $lines = db_unzip("lines", $filename); - else + else $lines = file("". $filename); // divide insert and create sql queries @@ -126,37 +126,37 @@ function db_import($filename, $connection) $line = trim($line); $line = str_replace("0_", $connection["tbpref"], $line); - $line = str_replace("Y_", "0_", $line); + // $line = str_replace("Y_", "0_", $line); // the last line did not belong to a 'create' sql query - if (!$table) + if (!$table) { // this line does not, too - if (strtolower(substr($line,0,6)) == "insert") + if (strtolower(substr($line,0,6)) == "insert") { $data_queries[] = substr($line, 0, strlen($line) - 1); // this line does not, too - } - elseif (strtolower(substr($line, 0, 20)) == "drop table if exists") + } + elseif (strtolower(substr($line, 0, 20)) == "drop table if exists") { $drop_queries[] = substr($line, 0, strlen($line) - 1); // this line does! - } - elseif (strtolower(substr($line, 0, 6)) == "create") + } + elseif (strtolower(substr($line, 0, 6)) == "create") { $table = true; $table_queries[] = $line . "\n"; } // the current line belongs to a create sql query - } - else + } + else { // create sql query ending in this line - if (strtolower(substr($line, 0, 1)) == ")") + if (strtolower(substr($line, 0, 1)) == ")") $table = false; $table_queries[count($table_queries) - 1] .= $line . "\n"; } @@ -165,12 +165,12 @@ function db_import($filename, $connection) $sql_error = false; // execute drop tables if exists queries - if (is_array($drop_queries)) + if (is_array($drop_queries)) { - foreach($drop_queries as $drop_query) + foreach($drop_queries as $drop_query) { $sql_error = false; - if (!db_query($drop_query)) + if (!db_query($drop_query)) { $sql_error = true; //if ($CONF['import_error']) echo nl2br($drop_query)."\n
".mysql_error()."

\n"; @@ -179,12 +179,12 @@ function db_import($filename, $connection) } // execute create tables queries - if (is_array($table_queries)) + if (is_array($table_queries)) { - foreach($table_queries as $table_query) + foreach($table_queries as $table_query) { $sql_error = false; - if (!db_query($table_query)) + if (!db_query($table_query)) { $sql_error = true; //if ($CONF['import_error']) echo nl2br($table_query)."\n
".mysql_error()."

\n"; @@ -193,9 +193,9 @@ function db_import($filename, $connection) } // execute insert data queries - if (is_array($data_queries)) + if (is_array($data_queries)) { - foreach($data_queries as $data_query) + foreach($data_queries as $data_query) { $sql_error = false; if (!db_query($data_query)) @@ -207,10 +207,10 @@ function db_import($filename, $connection) } // show number successful executed querys or if an error did occur - if ($sql_error == 1) + if ($sql_error == 1) return false; //echo "
".IM_ERROR.".
\n"; - else + else return true; //echo "
".IM_SUCCESS." ".count($table_queries)." ".IM_TABLES." ".count($data_queries)." ".IM_ROWS." (".$import_file.")
\n"; //$shell_command = C_MYSQL_PATH . " -h $host -u $user -p{$password} $dbname < $filename"; @@ -218,18 +218,18 @@ function db_import($filename, $connection) } // returns the content of the gziped $path backup file. use of $mode see below -function db_ungzip($mode, $path) +function db_ungzip($mode, $path) { $file_data = gzfile($path); // returns one string or an array of lines - if ($mode != "lines") - return implode("",$file_data); - else + if ($mode != "lines") + return implode("",$file_data); + else return $file_data; } // returns the content of the ziped $path backup file. use of $mode see below -function db_unzip($mode, $path) +function db_unzip($mode, $path) { $all = false; $all = implode("", file($path)); @@ -237,23 +237,23 @@ function db_unzip($mode, $path) // convert path to name of ziped file $filename = ereg_replace(".*/", "", $path); $filename = substr($filename, 0, strlen($filename) - 4); - + // compare filname in zip and filename from $_GET - if (substr($all, 30, strlen($filename)) != $filename) + if (substr($all, 30, strlen($filename)) != $filename) { return ''; // exit if names differ //echo F_WRONG_FILE."."; //exit; - } - else + } + else { // get the suffix of the filename in hex $crc_bugfix = substr(substr($filename, 0, strlen($filename) - 4), strlen($filename) - 12 - 4); $suffix = false; // convert hex to ascii - for ($i=0; $i < 12; ) + for ($i=0; $i < 12; ) $suffix .= chr($crc_bugfix[$i++] . $crc_bugfix[$i++] . $crc_bugfix[$i++]); // remove central directory information (we have always just one ziped file) @@ -266,35 +266,35 @@ function db_unzip($mode, $path) } // returns one string or an array of lines - if ($mode != "lines") - return $file_data; - else + if ($mode != "lines") + return $file_data; + else return explode("\n", $file_data); } // generates a dump of $db database // $drop and $zip tell if to include the drop table statement or dry to pack -function db_export($conn, $filename, $zip='no', $comment='') +function db_export($conn, $filename, $zip='no', $comment='') { global $app_title, $version, $power_url, $path_to_root; - + $error = false; - + // set max string size before writing to file $max_size = 1048576 * 2; // 2 MB // changes max size if value can be retrieved - if (ini_get("memory_limit")) + if (ini_get("memory_limit")) $max_size = 900000 * ini_get("memory_limit"); - + // set backupfile name - if ($zip == "gzip") + if ($zip == "gzip") $backupfile = $filename . ".gz"; - elseif ($zip == "zip") + elseif ($zip == "zip") $backupfile = $filename . ".zip"; - else + else $backupfile = $filename; - $company = get_company_pref('coy_name'); + $company = get_company_pref('coy_name'); //create comment $out="# MySQL dump of database '".$conn["dbname"]."' on host '".$conn["host"]."'\n"; $out.="# Backup Date and Time: ".date("Y-m-d H:i")."\n"; @@ -304,28 +304,28 @@ function db_export($conn, $filename, $zip='no', $comment='') $out.="# User: ".$_SESSION["wa_current_user"]->name."\n\n"; // write users comment - if ($comment) + if ($comment) { $out .= "# Comment:\n"; $comment=preg_replace("'\n'","\n# ","# ".$comment); //$comment=str_replace("\n", "\n# ", $comment); - foreach(explode("\n",$comment) as $line) + foreach(explode("\n",$comment) as $line) $out .= $line."\n"; $out.="\n"; } - + //$out.="use ".$db.";\n"; we don't use this option. // get auto_increment values and names of all tables $res = db_query("show table status"); $all_tables = array(); - while($row = db_fetch($res)) + while($row = db_fetch($res)) { if ($conn["tbpref"] == "" || strpos($row['Name'], $conn["tbpref"]) !== false) $all_tables[] = $row; - } + } // get table structures - foreach ($all_tables as $table) + foreach ($all_tables as $table) { $res1 = db_query("SHOW CREATE TABLE `" . $table['Name'] . "`"); $tmp = db_fetch($res1); @@ -336,11 +336,11 @@ function db_export($conn, $filename, $zip='no', $comment='') $fks = array(); if (isset($table_sql)) { - foreach($table_sql as $tablenme=>$table) + foreach($table_sql as $tablenme=>$table) { $tmp_table=$table; // save all tables, needed for creating this table in $fks - while (($ref_pos = strpos($tmp_table, " REFERENCES ")) > 0) + while (($ref_pos = strpos($tmp_table, " REFERENCES ")) > 0) { $tmp_table = substr($tmp_table, $ref_pos + 12); $ref_pos = strpos($tmp_table, "("); @@ -352,10 +352,10 @@ function db_export($conn, $filename, $zip='no', $comment='') $all_tables = order_sql_tables($all_tables, $fks); // as long as no error occurred - if (!$error) + if (!$error) { - //while($row=@mysql_fetch_array($res)) - foreach ($all_tables as $row) + //while($row=@mysql_fetch_array($res)) + foreach ($all_tables as $row) { $tablename = $row['Name']; $auto_incr[$tablename] = $row['Auto_increment']; @@ -368,13 +368,13 @@ function db_export($conn, $filename, $zip='no', $comment='') $out.=$table_sql[$tablename]; // add auto_increment value - if ($auto_incr[$tablename]) + if ($auto_incr[$tablename]) $out.=" AUTO_INCREMENT=".$auto_incr[$tablename]; $out.=" ;"; $out.="\n\n\n"; // export data - if (!$error) + if (!$error) { $out.="### Data of table `".$tablename."` ###\n\n"; @@ -394,49 +394,49 @@ function db_export($conn, $filename, $zip='no', $comment='') $out .= "INSERT INTO `" . $tablename . "` VALUES ("; $row2 = db_fetch_row($res2); // run through each field - for ($k = 0; $k < $nf = db_num_fields($res2); $k++) + for ($k = 0; $k < $nf = db_num_fields($res2); $k++) { // identify null values and save them as null instead of '' - if ($field_type[$k] != "" && $row2[$k] == "") - $out .= "NULL"; - else + if ($field_type[$k] != "" && $field_type[$k] != "NO" && $row2[$k] == "") + $out .= "NULL"; + else $out .= "'" . db_escape($row2[$k]) . "'"; - if ($k < ($nf - 1)) + if ($k < ($nf - 1)) $out .= ", "; } $out .= ");\n"; // if saving is successful, then empty $out, else set error flag - if (strlen($out) > $max_size && $zip != "zip") + if (strlen($out) > $max_size && $zip != "zip") { - if (save_to_file($backupfile, $zip, $out)) - $out = ""; - else + if (save_to_file($backupfile, $zip, $out)) + $out = ""; + else $error = true; } } // an error occurred! Try to delete file and return error status - } - elseif ($error) + } + elseif ($error) { @unlink($path_to_root . BACKUP_PATH . $backupfile); return false; } // if saving is successful, then empty $out, else set error flag - if (strlen($out) > $max_size && $zip != "zip") + if (strlen($out) > $max_size && $zip != "zip") { - if (save_to_file($backupfile, $zip, $out)) - $out= ""; - else + if (save_to_file($backupfile, $zip, $out)) + $out= ""; + else $error = true; } } // an error occurred! Try to delete file and return error status - } - else + } + else { @unlink($path_to_root . BACKUP_PATH . $backupfile); return false; @@ -445,13 +445,13 @@ function db_export($conn, $filename, $zip='no', $comment='') // if (mysql_error()) return "DB_ERROR"; //@mysql_close($con); - //if ($zip == "zip") + //if ($zip == "zip") // $zip = $time; - if (save_to_file($backupfile, $zip, $out)) + if (save_to_file($backupfile, $zip, $out)) { $out = ""; - } - else + } + else { @unlink($path_to_root . BACKUP_PATH . $backupfile); return false; @@ -461,28 +461,28 @@ function db_export($conn, $filename, $zip='no', $comment='') // orders the tables in $tables according to the constraints in $fks // $fks musst be filled like this: $fks[tablename][0]=needed_table1; $fks[tablename][1]=needed_table2; ... -function order_sql_tables($tables, $fks) +function order_sql_tables($tables, $fks) { // do not order if no contraints exist - if (!count($fks)) + if (!count($fks)) return $tables; // order $new_tables = array(); $existing = array(); $modified = true; - while (count($tables) && $modified == true) + while (count($tables) && $modified == true) { $modified = false; - foreach ($tables as $key=>$row) + foreach ($tables as $key=>$row) { // delete from $tables and add to $new_tables - if (isset($fks[$row['Name']])) + if (isset($fks[$row['Name']])) { - foreach($fks[$row['Name']] as $needed) + foreach($fks[$row['Name']] as $needed) { // go to next table if not all needed tables exist in $existing - if (!in_array($needed,$existing)) + if (!in_array($needed,$existing)) continue 2; } } @@ -496,12 +496,12 @@ function order_sql_tables($tables, $fks) } } - if (count($tables)) + if (count($tables)) { // probably there are 'circles' in the constraints, bacause of that no proper backups can be created yet // TODO: this will be fixed sometime later through using 'alter table' commands to add the constraints after generating the tables // until now, just add the lasting tables to $new_tables, return them and print a warning - foreach($tables as $row) + foreach($tables as $row) $new_tables[] = $row; echo "
THIS DATABASE SEEMS TO CONTAIN 'RING CONSTRAINTS'. WA DOES NOT SUPPORT THEM. PROBABLY THE FOLOWING BACKUP IS DEFECT!
"; } @@ -510,30 +510,30 @@ function order_sql_tables($tables, $fks) // saves the string in $fileData to the file $backupfile as gz file or not ($zip) // returns backup file name if name has changed (zip), else TRUE. If saving failed, return value is FALSE -function save_to_file($backupfile, $zip, $fileData) +function save_to_file($backupfile, $zip, $fileData) { global $path_to_root; - - if ($zip == "gzip") + + if ($zip == "gzip") { - if ($zp = @gzopen($path_to_root . BACKUP_PATH . $backupfile, "a9")) + if ($zp = @gzopen($path_to_root . BACKUP_PATH . $backupfile, "a9")) { @gzwrite($zp, $fileData); @gzclose($zp); return true; - } - else + } + else { return false; } - + // $zip contains the timestamp - } - elseif ($zip == "zip") + } + elseif ($zip == "zip") { // based on zip.lib.php 2.2 from phpMyBackupAdmin // offical zip format: http://www.pkware.com/appnote.txt - + // End of central directory record $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; @@ -545,7 +545,7 @@ function save_to_file($backupfile, $zip, $fileData) // string needed for decoding (because of crc bug) //$name_suffix = substr($zdata, -4, 4); //$name_suffix2 = "_"; - //for ($i = 0; $i < 4; $i++) + //for ($i = 0; $i < 4; $i++) // $name_suffix2 .= sprintf("%03d", ord($name_suffix[$i])); //$backupfile = substr($backupfile, 0, strlen($backupfile) - 8) . $name_suffix2 . ".sql.zip"; $name = substr($backupfile, 0, strlen($backupfile) -4); @@ -567,9 +567,9 @@ function save_to_file($backupfile, $zip, $fileData) // crc32, compressed filesize, uncompressed filesize $sub2 = pack('V', $crc) . pack('V', $c_len) . pack('V', $unc_len); - + $fr = "\x50\x4b\x03\x04" . $sub1. $sub2; - + // length of filename, extra field length $fr .= pack('v', strlen($name)) . pack('v', 0); $fr .= $name; @@ -581,39 +581,39 @@ function save_to_file($backupfile, $zip, $fileData) $cdrec = "\x50\x4b\x01\x02"; $cdrec .= "\x00\x00"; // version made by $cdrec .= $sub1 . $sub2; - + // length of filename, extra field length, file comment length, disk number start, internal file attributes, external file attributes - 'archive' bit set, offset $cdrec .= pack('v', strlen($name)) . pack('v', 0) . pack('v', 0) . pack('v', 0) . pack('v', 0) . pack('V', 32) . pack('V',0); $cdrec .= $name; // combine data $fileData = $fr . $cdrec . $eof_ctrl_dir; - + // 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($path_to_root . BACKUP_PATH . $backupfile, "a")) { @fwrite($zp, $fileData); @fclose($zp); return true; - } - else + } + else { return false; } - + // uncompressed - } - else + } + else { - if ($zp = @fopen($path_to_root . BACKUP_PATH . $backupfile, "a")) + if ($zp = @fopen($path_to_root . BACKUP_PATH . $backupfile, "a")) { @fwrite($zp, $fileData); @fclose($zp); return true; - } - else + } + else { return false; } diff --git a/config.php b/config.php index 3a86c940..7e82af0f 100644 --- a/config.php +++ b/config.php @@ -56,7 +56,7 @@ $version = "1.15"; // Build for development purposes - $build_version = "32"; + $build_version = "55"; // Powered by $power_by = "FrontAccounting"; @@ -87,6 +87,9 @@ /* email stock location if order below reorder-level */ $loc_notification = 0; + /* print_invoice_no. 0 = print reference number, 1 = print invoice number */ + $print_invoice_no = 0; + $dateformats = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD"); $dateseps = array("/", ".", "-", " "); $thoseps = array(",", ".", " "); diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index c72fce92..4ccd6b4b 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -38,7 +38,7 @@ class FrontReport extends Cpdf function FrontReport($title, $filename, $size = 'A4', $fontsize = 9) { - switch ($size) + switch ($size) { case 'A4': @@ -133,7 +133,7 @@ class FrontReport extends Cpdf { $fontinclude = true; include($locale); - } + } //if ($this->rtl) // this is good for presentation only if (!$own) { @@ -141,14 +141,14 @@ class FrontReport extends Cpdf { $this->rtl = true; $path = $path_to_root . 'reporting/fonts/farsi_1.afm'; - } + } elseif ($style == 'italic') $path = $path_to_root . 'reporting/fonts/Helvetica-Oblique.afm'; elseif ($style == 'bold') $path = $path_to_root . 'reporting/fonts/Helvetica-Bold.afm'; else // even take misspelled styles $path = $path_to_root . 'reporting/fonts/Helvetica.afm'; - } + } $this->selectFont($path, 'WinAnsiEncoding'); } @@ -231,7 +231,7 @@ class FrontReport extends Cpdf $str .= " - " . $this->params[$i]['to']; $this->Text($this->titleCol, $str, $this->companyCol); } - } + } if ($this->params[0] != '') // Comments { $this->NewLine(); @@ -265,22 +265,22 @@ class FrontReport extends Cpdf function Header2($myrow, $branch, $sales_order, $bankaccount, $doctype) { - global $path_to_root, $print_as_quote; - + global $path_to_root, $print_as_quote, $print_invoice_no; + $this->pageNumber++; if ($this->pageNumber > 1) $this->newPage(); $header2type = true; if ($this->currency != $myrow['curr_code']) { - include($path_to_root . "reporting/includes/doctext2.inc"); - } + include($path_to_root . "reporting/includes/doctext2.inc"); + } else { - include($path_to_root . "reporting/includes/doctext.inc"); - } + include($path_to_root . "reporting/includes/doctext.inc"); + } $this->row = $this->pageHeight - $this->topMargin; - + $upper = $this->row - 2 * $this->lineHeight; $lower = $this->bottomMargin + 6 * $this->lineHeight; $iline1 = $upper - 4 * $this->lineHeight; @@ -316,7 +316,7 @@ class FrontReport extends Cpdf $this->Text($this->endLine - 35, _("Page") . ' ' . $this->pageNumber); $this->fontSize -= 4; $this->row = $upper - 5; - + $this->Text($mcol, $doc_Invoice_no, $mcol + 90); $this->Text($mcol + 90, $doc_Cust_no, $mcol + 180); $this->Text($mcol + 180, $doc_Date); @@ -340,12 +340,17 @@ class FrontReport extends Cpdf $this->Text($mcol, $myrow['order_no'], $mcol + 90); else if ($doctype == 9) // SO $this->Text($mcol, $myrow['order_no'] ." ".$myrow['customer_ref'], $mcol + 90); - else // INV/CRE/STA - $this->Text($mcol, $myrow['reference'], $mcol + 90); + else // INV/CRE/STA + { + if ($print_invoice_no == 1) + $this->Text($mcol, $myrow['trans_no'], $mcol + 90); + else + $this->Text($mcol, $myrow['reference'], $mcol + 90); + } $this->Text($mcol + 90, $myrow['debtor_no'], $mcol + 180); if ($doctype == 8 || $doctype == 9) $this->Text($mcol + 180, sql2date($myrow['ord_date'])); - else + else $this->Text($mcol + 180, sql2date($myrow['tran_date'])); $this->fontSize -= 4; @@ -353,24 +358,24 @@ class FrontReport extends Cpdf $this->Text($ccol, $doc_Charge_To, $icol); $this->Text($mcol, $doc_Delivered_To); $this->fontSize += 4; - + $this->NewLine(2); $temp = $this->row; if ($doctype == 9) { $this->Text($ccol, $myrow['name'], $icol); //$adr = ?; - } + } else { if ($doctype == 8) $this->Text($ccol, $myrow['supp_name'], $icol); - else + else $this->Text($ccol, $myrow['DebtorName'], $icol); $adr = explode("\n", $myrow['address']); - } + } for ($i = 0; $i < count($adr); $i++) - { + { $this->NewLine(); $this->Text($ccol, $adr[$i], $icol); } @@ -379,11 +384,11 @@ class FrontReport extends Cpdf $this->row = $temp; if ($doctype == 8) $this->Text($mcol, $this->company['coy_name']); - else + else $this->Text($mcol, $sales_order['deliver_to']); $adr = explode("\n", $sales_order['delivery_address']); for ($i = 0; $i < count($adr); $i++) - { + { $this->NewLine(); $this->Text($mcol, $adr[$i]); } @@ -395,7 +400,7 @@ class FrontReport extends Cpdf $this->Text($mcol, $doc_Due_Date . ":", $mcol2); if ($doctype == 9) $this->Text($mcol2, sql2date($myrow['delivery_date'])); - else if ($doctype != 8) + else if ($doctype != 8) $this->Text($mcol2, sql2date($myrow['due_date'])); if ($branch != null) { @@ -410,7 +415,7 @@ class FrontReport extends Cpdf $row = db_fetch($result); $this->Text($mcol2, $row['salesman_name']); - } + } $this->NewLine(); $this->Text($ccol, $doc_Your_VAT_no . ":", $ccol2); if ($doctype != 8) @@ -428,13 +433,13 @@ class FrontReport extends Cpdf $this->Text($ccol2, $row["terms"], $mcol); $this->Text($mcol, $doc_Our_Order_No . ":", $mcol2); $this->Text($mcol2, $myrow['order_']); - + $locale = $path_to_root . "lang/" . $_SESSION['language']->code . "/locale.inc"; if (file_exists($locale)) { $header2include = true; include($locale); - } + } $this->row = $iline3 - $this->lineHeight - 2; $this->Font('bold'); $count = count($this->headers); @@ -450,7 +455,7 @@ class FrontReport extends Cpdf if ($branch['disable_branch'] == 1) { $amt = number_format($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"], user_price_dec()); - $txt = $doc_Payment_Link . " PayPal: "; + $txt = $doc_Payment_Link . " PayPal: "; $name = urlencode($this->title . " " . $myrow['reference']); $url = "https://www.paypal.com/xclick/business=" . $this->company['email'] . "&item_name=" . $name . "&amount=" . $amt . "¤cy_code=" . $myrow['curr_code']; @@ -462,7 +467,7 @@ class FrontReport extends Cpdf $this->SetTextColor(0, 0, 0); $this->addLink($url, $ccol, $this->row, $this->pageWidth - $this->rightMargin, $this->row + $this->lineHeight); $this->fontSize += 2; - } + } } if ($this->params['comments'] != '') { @@ -471,41 +476,41 @@ class FrontReport extends Cpdf $this->Text($ccol, $this->params['comments']); $this->Font(); } - + $this->row = $lower - 5; $this->fontSize -= 4; - + $this->Text($ccol, $doc_Address, $ccol2 + 40); $this->Text($ccol2 + 30, $doc_Phone_Fax_Email, $mcol); $this->Text($mcol , $doc_Bank, $mcol2); $this->Text($mcol2, $doc_Bank_Account); $this->fontSize += 4; $this->NewLine(); - $adrline = $this->row; - + $adrline = $this->row; + $adr = explode("\n", $this->company['postal_address']); for ($i = 0; $i < count($adr); $i++) - { + { $this->Text($ccol, $adr[$i], $ccol2 + 40); $this->NewLine(); } - $this->row = $adrline; + $this->row = $adrline; $this->Text($ccol2 + 30, $this->company['phone'], $mcol); $this->NewLine(); $this->Text($ccol2 + 30, $this->company['fax'], $mcol); $this->NewLine(); $this->Text($ccol2 + 30, $this->company['email'], $mcol); // fetch this later - $this->row = $adrline; + $this->row = $adrline; $this->Text($mcol, $bankaccount['bank_name'], $mcol2); $adr = explode("\n", $bankaccount['bank_address']); for ($i = 0; $i < count($adr); $i++) - { + { $this->NewLine(); $this->Text($mcol, $adr[$i], $mcol2); } - - $this->row = $adrline; + + $this->row = $adrline; $this->Text($mcol2, $bankaccount['bank_account_name']); $this->NewLine(); $this->Text($mcol2, $bankaccount['bank_account_number']); @@ -520,13 +525,13 @@ class FrontReport extends Cpdf $this->addPngFromFile($logo, $x, $y, $w, $h); else $this->addJpegFromFile($logo, $x, $y, $w, $h); - } + } function SetDrawColor($r, $g, $b) { $this->setStrokeColor($r / 255, $g / 255, $b / 255); } - + function SetTextColor($r, $g, $b) { $this->setColor($r / 255, $g / 255, $b / 255); @@ -537,10 +542,10 @@ class FrontReport extends Cpdf if ($n == 0) $n = $this->pageWidth - $this->rightMargin; - return $this->TextWrap($c, $this->row - $r, $n - $c + $corr, $txt, 'left'); + return $this->TextWrap($c, $this->row - $r, $n - $c + $corr, $txt, 'left'); } - - function TextWrap($xpos, $ypos, $len, $str, $align = 'left') + + function TextWrap($xpos, $ypos, $len, $str, $align = 'left') { if ($this->rtl) { @@ -550,7 +555,7 @@ class FrontReport extends Cpdf $align = 'right'; elseif ($align == 'right') $align = 'left'; - } + } return $this->addTextWrap($xpos, $ypos, $len, $this->fontSize, $str, $align); } @@ -558,33 +563,33 @@ class FrontReport extends Cpdf { return $this->TextWrap($this->cols[$c], $this->row - $r, $this->cols[$n] - $this->cols[$c] + $corr, $txt, $this->aligns[$c]); } - + function TextCol2($c, $n, $txt, $corr=0, $r=0) { return $this->TextWrap($this->cols2[$c], $this->row - $r, $this->cols2[$n] - $this->cols2[$c] + $corr, $txt, $this->aligns2[$c]); } - + function TextColLines($c, $n, $txt, $corr=0) { $str = Explode("\n", $txt); for ($i = 0; $i < count($str); $i++) { $l = $str[$i]; - do + do { - $l = $this->TextCol($c, $n, $l, $corr); + $l = $this->TextCol($c, $n, $l, $corr); $this->NewLine(); } while ($l != ''); - } + } } - function LineTo($from, $row, $to, $row2) + function LineTo($from, $row, $to, $row2) { Cpdf::line($from, $row, $to, $row2); } - function Line($row, $height = 0) + function Line($row, $height = 0) { $this->setLineStyle($height + 1); Cpdf::line($this->pageWidth - $this->rightMargin, $row ,$this->leftMargin, $row); @@ -595,7 +600,7 @@ class FrontReport extends Cpdf $this->row -= ($l * $this->lineHeight); if ($np > 0 && $this->row < $this->bottomMargin + ($np * $this->lineHeight)) $this->Header(); - } + } function End($email=0, $subject=null, $myrow=null, $doctype = 0) { @@ -604,8 +609,8 @@ class FrontReport extends Cpdf // this is no good in IE so has been replaced, see down under // but good for debugging purposes in IE //session_write_close(); - - if ($go_debug == 1) + + if ($go_debug == 1) { $buf = $this->output(1); $len = strlen($buf); @@ -621,8 +626,8 @@ class FrontReport extends Cpdf //header('Pragma: public'); //$this->pdf->stream(); - } - else + } + else { $buf = $this->output(); $len = strlen($buf); @@ -641,29 +646,29 @@ class FrontReport extends Cpdf $emailtype = true; if ($this->currency != $myrow['curr_code']) { - include("doctext2.inc"); - } + include("doctext2.inc"); + } else { - include("doctext.inc"); - } + include("doctext.inc"); + } require_once($path_to_root . "reporting/includes/class.mail.inc"); $mail = new email($this->company['coy_name'], $this->company['email']); $from = $this->company['coy_name'] . " <" . $this->company['email'] . ">"; $to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">"; - $msg = $doc_Dear_Sirs . ",\n\n" . $doc_AttachedFile . " " . $subject . + $msg = $doc_Dear_Sirs . ",\n\n" . $doc_AttachedFile . " " . $subject . "\n\n"; if ($myrow['dimension_id'] > 0 && $doctype == 10) // helper for payment links { if ($myrow['dimension_id'] == 1) { $amt = number_format($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"], user_price_dec()); - $txt = $doc_Payment_Link . " PayPal: "; + $txt = $doc_Payment_Link . " PayPal: "; $nn = urlencode($this->title . " " . $myrow['reference']); $url = "https://www.paypal.com/xclick/business=" . $this->company['email'] . "&item_name=" . $nn . "&amount=" . $amt . "¤cy_code=" . $myrow['curr_code']; - $msg .= $txt . $url . "\n\n"; - } + $msg .= $txt . $url . "\n\n"; + } } $msg .= $doc_Kindest_regards . "\n\n"; $sender = $this->user . "\n" . $this->company['coy_name']; @@ -696,17 +701,24 @@ class FrontReport extends Cpdf } else { - echo ' - - - - - click here if you are not re-directed. - - '; - } + //echo ' + // + // + // + // + // click here if you are not re-directed. + // + // '; + header('Content-type: application/pdf'); + header("Content-Disposition: inline; filename=$this->filename"); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + $this->stream(); + + } // also have a look through the directory, and remove the files that are older than a week // rather want to save 'em /*if ($d = @opendir($dir)) { -- 2.30.2