r514: - Now three different ID's that can be logged (bug, comment, attachment)
[bugdar.git] / includes / class_history.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 class History
14 {
15 var $bugid = 0;
16 var $attachmentid = 0;
17 var $commentid = 0;
18 var $allowempty = false;
19
20 // -------------------------------------------------------------------
21 // -- Create a log entry
22 // -------------------------------------------------------------------
23 function log($diffdata = null)
24 {
25 global $bugsys;
26
27 $this->bugid = intval($this->bugid);
28 $this->attachmentid = intval($this->attachmentid);
29 $this->commentid = intval($this->commentid);
30
31 if ($diffdata == -1)
32 {
33 return;
34 }
35
36 if (!$diffdata)
37 {
38 return;
39 }
40
41 $bugsys->db->query("
42 INSERT INTO " . TABLE_PREFIX . "history
43 (bugid, attachmentid, commentid, dateline, userid, field, original, changed)
44 VALUES
45 (" . $this->bugid . ", " . $this->attachmentid . ", " . $this->commentid . ", " . TIMENOW . ",
46 " . $bugsys->userinfo['userid'] . ", '" . $bugsys->escape($diffdata['field']) . "',
47 '" . $bugsys->escape($diffdata['initial']) . "', '" . $bugsys->escape($diffdata['final']) . "'
48 )"
49 );
50 }
51
52 // -------------------------------------------------------------------
53 // -- Do a diff
54 // -------------------------------------------------------------------
55 function diff($field, $initial, $final)
56 {
57 if (empty($initial) AND empty($final))
58 {
59 if (!$this->allowempty)
60 {
61 return -1;
62 }
63 }
64
65 if (!$this->allowempty)
66 {
67 if ($initial === $final)
68 {
69 return -1;
70 }
71 }
72
73 return array('field' => $field, 'initial' => $initial, 'final' => $final);
74 }
75 }
76
77 /*=====================================================================*\
78 || ###################################################################
79 || # $HeadURL$
80 || # $Id$
81 || ###################################################################
82 \*=====================================================================*/
83 ?>