Audit trail added.
[fa-stable.git] / includes / db / audit_trail_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 function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
14 {
15         $sql = "INSERT INTO ".TB_PREF."audit_trail"
16                 . " (type, trans_no, user, fiscal_year, gl_date, description)
17                         VALUES($trans_type, $trans_no,"
18                         . $_SESSION["wa_current_user"]->user. ","
19                         . get_company_pref('f_year') .","
20                         . "'". date2sql($trans_date) ."',"
21                         . db_escape($descr). ")";
22
23         db_query($sql, "Cannot add audit info");
24 }
25
26 function get_audit_trail_all($trans_type, $trans_no)
27 {
28         $sql = "SELECT * FROM ".TB_PREF."audit_trail"
29                 ." WHERE type=$trans_type AND trans_no=$trans_no";
30
31         return db_query($sql, "Cannot get all audit info for transaction");
32 }
33
34 function get_audit_trail_last($trans_type, $trans_no)
35 {
36         $sql = "SELECT * FROM ".TB_PREF."audit_trail"
37                 ." WHERE type=$trans_type AND trans_no=$trans_no ORDER BY id desc";
38
39         $res = db_query($sql, "Cannot get last audit info for transaction");
40         if ($res)
41                 $row = db_fetch($res);
42
43         return $row;
44 }
45
46 ?>