From 0517097815894f0221e3755a2d14612f69f72b86 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Sun, 16 Nov 2008 16:48:03 +0000 Subject: [PATCH] Added Attachment of Documents and a couple of links from supplier invoice/crfedit note --- CHANGELOG.txt | 10 ++ admin/attachments.php | 224 +++++++++++++++++++++++++++++++ admin/view_print_transaction.php | 6 +- applications/setup.php | 1 + purchasing/supplier_credit.php | 3 +- purchasing/supplier_invoice.php | 4 +- sql/alter2.1.sql | 16 +++ 7 files changed, 259 insertions(+), 5 deletions(-) create mode 100644 admin/attachments.php diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d8119744..035b0e00 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,16 @@ Legend: ! -> Note $ -> Affected files +16-Nov-2008 Joe Hunt ++ Added Attachment of Documents and a couple of links from supplier invoice/crfedit note +$ /admin/attachments.php (new file) + /applications/setup.php + /purchasing/supplier_credit,php + /purchasing/supplier_invoice.php + /sql/alter2.1.sql +# Minor bug in view_print_transactions.php +$ /admin/view_print_transactions.php + 15-Nov-2008 Joe Hunt + Added Quick Entries in GL Journal Entry and changed some needed fixes. $ /gl/gl_bank.php diff --git a/admin/attachments.php b/admin/attachments.php new file mode 100644 index 00000000..a36801d4 --- /dev/null +++ b/admin/attachments.php @@ -0,0 +1,224 @@ + 0) + { + //$content = base64_encode(file_get_contents($_FILES['filename']['tmp_name'])); + $tmpname = $_FILES['filename']['tmp_name']; + $fp = fopen($tmpname, 'r'); + $content = fread($fp, filesize($tmpname)); + $content = addslashes($content); + fclose($fp); + + //$content = addslashes(file_get_contents($_FILES['filename']['tmp_name'])); + $filename = $_FILES['filename']['name']; + $filesize = $_FILES['filename']['size']; + $filetype = $_FILES['filename']['type']; + } + else + { + $content = $filename = $filetype = ""; + $filesize = 0; + } + $date = date2sql(Today()); + if ($Mode == 'ADD_ITEM') + { + $sql = "INSERT INTO ".TB_PREF."attachments (type_no, trans_no, description, bin_data, filename, + filesize, filetype, tran_date) VALUES (".$_POST['filterType'].",".$_POST['trans_no'].",". + db_escape($_POST['description']).",'$content', '$filename', '$filesize', '$filetype', '$date')"; + db_query($sql, "Attachment could not be inserted"); + display_notification(_("Attachment has been inserted.")); + } + else + { + $sql = "UPDATE ".TB_PREF."attachments SET + type_no=".$_POST['filterType'].", + trans_no=".$_POST['trans_no'].", + description=".db_escape($_POST['description']).", "; + if ($filename != "") + { + $sql .= "bin_data='$content', + filename='$filename', + filesize='$filesize', + filetype='$filetype', "; + } + $sql .= "tran_date='$date' WHERE id=$selected_id"; + db_query($sql, "Attachment could not be updated"); + display_notification(_("Attachment has been updated.")); + } + $Mode = 'RESET'; +} + +if ($Mode == 'Delete') +{ + $sql = "DELETE FROM ".TB_PREF."attachments WHERE id = $selected_id"; + db_query($sql, "Could not delete attachment"); + display_notification(_("Attachment has been deleted.")); + $Mode = 'RESET'; +} + +if ($Mode == 'RESET') +{ + unset($_POST['trans_no']); + unset($_POST['description']); + $selected_id = -1; +} + +function viewing_controls() +{ + start_form(false, true); + + start_table("class='tablestyle_noborder'"); + + systypes_list_row(_("Type:"), 'filterType', null, true); + + end_table(1); + + end_form(); +} + +//---------------------------------------------------------------------------------------- + +function get_attached_documents($type) +{ + $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no=$type ORDER BY trans_no"; + return db_query($sql, "Could not retrieve attachments"); +} + +function get_attachment($id) +{ + $sql = "SELECT * FROM ".TB_PREF."attachments WHERE id=$id"; + $result = db_query($sql, "Could not retrieve attachments"); + return db_fetch($result); +} + +function display_rows($type) +{ + global $table_style; + + $rows = get_attached_documents($type); + $th = array(_("#"), _("Description"), _("Filename"), _("Size"), _("Filetype"), _("Date Uploaded"), "", "", "", ""); + + div_start('transactions'); + start_form(); + start_table($table_style); + table_header($th); + $k = 0; + while ($row = db_fetch($rows)) + { + alt_table_row_color($k); + + label_cell(get_trans_view_str($type, $row['trans_no'])); + label_cell($row['description']); + label_cell($row['filename']); + label_cell($row['filesize']); + label_cell($row['filetype']); + label_cell(sql2date($row['tran_date'])); + edit_button_cell("Edit".$row['id'], _("Edit")); + edit_button_cell("view".$row['id'], _("View")); + edit_button_cell("download".$row['id'], _("Download")); + edit_button_cell("Delete".$row['id'], _("Delete")); + end_row(); + } + end_table(1); + hidden('filterType', $type); + end_form(); + div_end(); +} + +//---------------------------------------------------------------------------------------- + +viewing_controls(); + +if (isset($_POST['filterType'])) + display_rows($_POST['filterType']); + +start_form(true); + +start_table("$table_style2 width=30%"); + +if ($selected_id != -1) +{ + if ($Mode == 'Edit') + { + $row = get_attachment($selected_id); + $_POST['trans_no'] = $row["trans_no"]; + $_POST['description'] = $row["description"]; + hidden('trans_no', $row['trans_no']); + label_row(_("Transaction #"), $row['trans_no']); + } + hidden('selected_id', $selected_id); +} +else + text_row_ex(_("Transaction #").':', 'trans_no', 10); +text_row_ex(_("Description").':', 'description', 40); +start_row(); +label_cells(_("Attached File") . ":", ""); +end_row(); + +end_table(1); +if (isset($_POST['filterType'])) + hidden('filterType', $_POST['filterType']); + +submit_add_or_update_center($selected_id == -1, '', true); + +end_form(); + +end_page(); + +?> diff --git a/admin/view_print_transaction.php b/admin/view_print_transaction.php index 48a0e176..69a52f43 100644 --- a/admin/view_print_transaction.php +++ b/admin/view_print_transaction.php @@ -50,13 +50,13 @@ function check_valid_entries() { if (!is_numeric($_POST['FromTransNo']) OR $_POST['FromTransNo'] <= 0) { - display_note(_("The starting transaction number is expected to be numeric and greater than zero.")); + display_error(_("The starting transaction number is expected to be numeric and greater than zero.")); return false; } if (!is_numeric($_POST['ToTransNo']) OR $_POST['ToTransNo'] <= 0) { - echo _("The ending transaction number is expected to be numeric and greater than zero."); + display_error(_("The ending transaction number is expected to be numeric and greater than zero.")); return false; } if (!isset($_POST['filterType']) || $_POST['filterType'] == "") @@ -100,7 +100,7 @@ function handle_search() if (db_num_rows($result) == 0) { - echo _("There are no transactions for the given parameters."); + display_notification(_("There are no transactions for the given parameters.")); return; } $print_type = $_POST['filterType']; diff --git a/applications/setup.php b/applications/setup.php index 95164fd2..de752454 100644 --- a/applications/setup.php +++ b/applications/setup.php @@ -30,6 +30,7 @@ $this->add_module(_("Maintanance")); $this->add_lapp_function(2, _("&Void a Transaction"),"admin/void_transaction.php?"); $this->add_lapp_function(2, _("View or &Print Transactions"),"admin/view_print_transaction.php?"); + $this->add_lapp_function(2, _("Attach Documents"),"admin/attachments.php?filterType=20"); $this->add_rapp_function(2, _("&Backup and Restore"),"admin/backups.php?", 15); $this->add_rapp_function(2, _("Create/Update &Companies"),"admin/create_coy.php?", 14); $this->add_rapp_function(2, _("Install/Update &Languages"),"admin/inst_lang.php?", 14); diff --git a/purchasing/supplier_credit.php b/purchasing/supplier_credit.php index 8ee6eff7..e7ddde07 100644 --- a/purchasing/supplier_credit.php +++ b/purchasing/supplier_credit.php @@ -50,7 +50,8 @@ if (isset($_GET['AddedID'])) display_note(get_gl_view_str($trans_type, $invoice_no, _("View the GL Journal Entries for this Credit Note")), 1); hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Credit Note"), "New=1"); - + hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"), "filterType=$trans_type&trans_no=$invoice_no"); + display_footer_exit(); } diff --git a/purchasing/supplier_invoice.php b/purchasing/supplier_invoice.php index 9341a11c..28f7f33b 100644 --- a/purchasing/supplier_invoice.php +++ b/purchasing/supplier_invoice.php @@ -49,8 +49,10 @@ if (isset($_GET['AddedID'])) display_note(get_gl_view_str($trans_type, $invoice_no, _("View the GL Journal Entries for this Invoice")), 1); - hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Invoice"), "New=1"); + hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Invoice"), "New=1"); + hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"), "filterType=$trans_type&trans_no=$invoice_no"); + display_footer_exit(); } diff --git a/sql/alter2.1.sql b/sql/alter2.1.sql index 48f286ef..7560011f 100644 --- a/sql/alter2.1.sql +++ b/sql/alter2.1.sql @@ -1,3 +1,19 @@ +DROP TABLE IF EXISTS `0_attachments`; + +CREATE TABLE `0_attachments` ( + `id` int(11) NOT NULL auto_increment, + `description` varchar(60) NOT NULL default '', + `type_no` int(11) NOT NULL default '0', + `trans_no` int(11) NOT NULL default '0', + `bin_data` mediumblob NOT NULL, + `tran_date` date NOT NULL default '0000-00-00', + `filename` varchar(60) NOT NULL default '', + `filesize` int(11) NOT NULL default '0', + `filetype` varchar(60) NOT NULL default '', + PRIMARY KEY (`id`), + KEY `type_no` (`type_no`,`trans_no`) +) TYPE=MyISAM AUTO_INCREMENT=1 ; + DROP TABLE IF EXISTS `0_groups`; CREATE TABLE `0_groups` ( -- 2.30.2