r765: Say hello to the GPL
[bugdar.git] / includes / class_history.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 class History
23 {
24 /**
25 * Bug ID
26 * @var integer
27 */
28 var $bugid = 0;
29
30 /**
31 * Attachment ID
32 * @var integer
33 */
34 var $attachmentid = 0;
35
36 /**
37 * Comment ID
38 * @var integer
39 */
40 var $commentid = 0;
41
42 /**
43 * Allow diff's that have an empty result (no change)
44 * @var bool
45 */
46 var $allowempty = false;
47
48 /**
49 * Logs a field change into the database
50 *
51 * @param array Diff data produced by diff()
52 */
53 function log($diffdata = null)
54 {
55 global $bugsys;
56
57 $this->bugid = intval($this->bugid);
58 $this->attachmentid = intval($this->attachmentid);
59 $this->commentid = intval($this->commentid);
60
61 if ($diffdata == -1)
62 {
63 return;
64 }
65
66 if (!$diffdata)
67 {
68 return;
69 }
70
71 $bugsys->db->query("
72 INSERT INTO " . TABLE_PREFIX . "history
73 (bugid, attachmentid, commentid, dateline, userid, field, original, changed)
74 VALUES
75 (" . $this->bugid . ", " . $this->attachmentid . ", " . $this->commentid . ", " . TIMENOW . ",
76 " . $bugsys->userinfo['userid'] . ", '" . $bugsys->escape($diffdata['field']) . "',
77 '" . $bugsys->escape($diffdata['initial']) . "', '" . $bugsys->escape($diffdata['final']) . "'
78 )"
79 );
80 }
81
82 /**
83 * Compares two values and creates a report of their differences
84 *
85 * @param string Name of the field
86 * @param mixed Initial value
87 * @param mixed Final value
88 *
89 * @return array Difference report
90 */
91 function diff($field, $initial, $final)
92 {
93 $field = trim($field);
94 $initial = trim($initial);
95 $final = trim($final);
96
97 if (empty($field))
98 {
99 return -1;
100 }
101
102 if (empty($initial) AND empty($final))
103 {
104 if (!$this->allowempty)
105 {
106 return -1;
107 }
108 }
109
110 if (!$this->allowempty)
111 {
112 if ($initial === $final)
113 {
114 return -1;
115 }
116 }
117
118 return array('field' => $field, 'initial' => $initial, 'final' => $final);
119 }
120 }
121
122 /*=====================================================================*\
123 || ###################################################################
124 || # $HeadURL$
125 || # $Id$
126 || ###################################################################
127 \*=====================================================================*/
128 ?>