Recurrent Invoices: fixed buggy call to non existing function and payment terms type...
[fa-stable.git] / admin / db / attachments_db.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12
13 //----------------------------------------------------------------------------------------
14
15 function add_attachment($filterType, $trans_no, $description,
16         $filename, $unique_name, $filesize, $filetype)
17 {
18         begin_transaction(__FUNCTION__, func_get_args());
19
20         $date = date2sql(Today());
21         $sql = "INSERT INTO ".TB_PREF."attachments (type_no, trans_no, description, filename, unique_name,
22                 filesize, filetype, tran_date) VALUES (".db_escape($filterType).","
23                 .db_escape($trans_no).",".db_escape($description).", "
24                 .db_escape($filename).", ".db_escape($unique_name).", ".db_escape($filesize)
25                 .", ".db_escape($filetype).", '$date')";
26         db_query($sql, "Attachment could not be inserted");             
27
28         commit_transaction();
29 }
30 //----------------------------------------------------------------------------------------
31
32 function update_attachment($selected_id, $filterType, $trans_no, $description,
33         $filename, $unique_name, $filesize, $filetype)
34 {
35         begin_transaction(__FUNCTION__, func_get_args());
36
37         $date = date2sql(Today());
38         $sql = "UPDATE ".TB_PREF."attachments SET
39                 type_no=".db_escape($filterType).",
40                 trans_no=".db_escape($trans_no).",
41                 description=".db_escape($description).", ";
42         if ($filename != "")
43         {
44                 $sql .= "filename=".db_escape($filename).",
45                 unique_name=".db_escape($unique_name).",
46                 filesize=".db_escape($filesize).",
47                 filetype=".db_escape($filetype).",";
48         }       
49         $sql .= "tran_date='$date' WHERE id=".db_escape($selected_id);
50         db_query($sql, "Attachment could not be updated");              
51
52         commit_transaction();
53 }
54
55 //----------------------------------------------------------------------------------------
56
57 function delete_attachment($id)
58 {
59         begin_transaction(__FUNCTION__, func_get_args());
60
61         $sql = "DELETE FROM ".TB_PREF."attachments WHERE id = ".db_escape($id);
62         db_query($sql, "Could not delete attachment");
63
64         commit_transaction();
65 }
66
67 //----------------------------------------------------------------------------------------
68
69 function get_attachment_string($type, $id)
70 {
71         global $path_to_root;
72     $str_return = "";    
73     $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type)." AND trans_no=".db_escape($id)." ORDER BY trans_no";
74     $return = db_query($sql, "Could not retrieve attachments");
75     while ($attachment = db_fetch($return))
76     {
77         if (strlen($str_return))
78             $str_return = $str_return . " \n";    
79         $str_return .= _("Attached File:")." <a href='$path_to_root/admin/attachments.php?vw=".$attachment["id"]." ' target='blanc_'> ". 
80                 $attachment["id"] . " " . $attachment["description"]. " - ". $attachment["filename"]."</a><br>";
81     }
82     return $str_return . "<br>";
83 }
84
85 //----------------------------------------------------------------------------------------
86
87 function get_attached_documents($type)
88 {
89         $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type)
90         ." ORDER BY trans_no";
91         return db_query($sql, "Could not retrieve attachments");
92 }
93
94 function get_attachment($id)
95 {
96         $sql = "SELECT * FROM ".TB_PREF."attachments WHERE id=".db_escape($id);
97         $result = db_query($sql, "Could not retrieve attachments");
98         return db_fetch($result);
99 }
100
101 function has_attachment($type, $id)
102 {
103         $sql = "SELECT DISTINCT * FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type)." AND trans_no=".db_escape($id);
104         $result = db_query($sql, "Could not retrieve attachments");
105         $myrow = db_fetch($result);
106         if ($myrow === false)
107                 return 0;
108         else
109                 return $myrow['id'];
110 }
111
112 function get_sql_for_attached_documents($type)
113 {
114         return "SELECT trans_no, description, filename, filesize, filetype, tran_date, id, type_no FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type)
115         ." ORDER BY trans_no DESC";
116 }
117
118 function move_trans_attachments($type, $trans_from, $trans_to)
119 {
120         $sql = "UPDATE ".TB_PREF."attachments SET trans_no=".db_escape($trans_to)
121                 ." WHERE type_no=".db_escape($type)." AND trans_no=".db_escape($trans_from);
122         db_query($sql, 'cannot move atachments');
123 }
124
125