Added Attachment of Documents and a couple of links from supplier invoice/crfedit...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 16 Nov 2008 16:48:03 +0000 (16:48 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 16 Nov 2008 16:48:03 +0000 (16:48 +0000)
CHANGELOG.txt
admin/attachments.php [new file with mode: 0644]
admin/view_print_transaction.php
applications/setup.php
purchasing/supplier_credit.php
purchasing/supplier_invoice.php
sql/alter2.1.sql

index d8119744d6c547a42c412c02617de024659e3934..035b0e00410b78fa652e10ef8566e05fe701468d 100644 (file)
@@ -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 (file)
index 0000000..a36801d
--- /dev/null
@@ -0,0 +1,224 @@
+<?php
+
+$path_to_root="..";
+$page_security = 8;
+
+include_once($path_to_root . "/includes/session.inc");
+
+include_once($path_to_root . "/includes/date_functions.inc");
+include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/includes/data_checks.inc");
+
+$view_id = find_submit('view');
+if ($view_id != -1)
+{
+       $row = get_attachment($view_id);
+       if ($row['filename'] != "")
+       {
+               $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream';     
+       header("Content-type: ".$type);
+       header('Content-Length: '.$row['filesize']);
+       if ($type == 'application/octet-stream')
+               header('Content-Disposition: attachment; filename='.$row['filename']);
+       else
+                       header("Content-Disposition: inline");
+       echo $row["bin_data"];
+       exit();
+       }       
+}
+
+$download_id = find_submit('download');
+if ($download_id != -1)
+{
+       $row = get_attachment($download_id);
+       if ($row['filename'] != "")
+       {
+               $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream';     
+       header("Content-type: ".$type);
+       header('Content-Length: '.$row['filesize']);
+       header('Content-Disposition: attachment; filename='.$row['filename']);
+       echo $row["bin_data"];
+       exit();
+       }       
+}
+
+$js = "";
+if ($use_popup_windows)
+       $js .= get_js_open_window(800, 500);
+page(_("Attach Documents"), false, false, "", $js);
+
+simple_page_mode(true);
+//----------------------------------------------------------------------------------------
+if (isset($_GET['filterType'])) // catch up external links
+       $_POST['filterType'] = $_GET['filterType'];
+if (isset($_GET['trans_no']))
+       $_POST['trans_no'] = $_GET['trans_no'];
+       
+if ($Mode == 'ADD_ITEM' || $Mode == 'UPDATE_ITEM')
+{
+       if (isset($_FILES['filename']) && $_FILES['filename']['size'] > 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") . ":", "<input type='file' id='filename' name='filename'>");
+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();
+
+?>
index 48a0e176c2aa5b0e2b11599ad47a19b8595477a4..69a52f4350eb5b98651c18b5526ed0ac75ae4ffa 100644 (file)
@@ -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'];
index 95164fd2f023ca16c8873b1728cd4e88fefb6238..de752454324d9c8c5288453307c74ddac5797811 100644 (file)
@@ -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);
index 8ee6eff78945ec935104bff7a5a9c02f1187834c..e7ddde0752131a789dd7cef8ef0d92d660f10f8e 100644 (file)
@@ -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();
 }
 
index 9341a11cc1f403771899605fd9dd0d2bc726fc16..28f7f33b982c9846f6e4f2e1759e751b901e1532 100644 (file)
@@ -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();
 }
 
index 48f286ef50c2769155129cc42a12c4037173cfa4..7560011f364f5e3f6790e5c466dc4ce794397319 100644 (file)
@@ -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` (