r665: Renaming product from "BugStrike" to "Bugdar"
[bugdar.git] / includes / class_history.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]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 /**
16 * Bug ID
17 * @var integer
18 */
19 var $bugid = 0;
20
21 /**
22 * Attachment ID
23 * @var integer
24 */
25 var $attachmentid = 0;
26
27 /**
28 * Comment ID
29 * @var integer
30 */
31 var $commentid = 0;
32
33 /**
34 * Allow diff's that have an empty result (no change)
35 * @var bool
36 */
37 var $allowempty = false;
38
39 /**
40 * Logs a field change into the database
41 *
42 * @param array Diff data produced by diff()
43 */
44 function log($diffdata = null)
45 {
46 global $bugsys;
47
48 $this->bugid = intval($this->bugid);
49 $this->attachmentid = intval($this->attachmentid);
50 $this->commentid = intval($this->commentid);
51
52 if ($diffdata == -1)
53 {
54 return;
55 }
56
57 if (!$diffdata)
58 {
59 return;
60 }
61
62 $bugsys->db->query("
63 INSERT INTO " . TABLE_PREFIX . "history
64 (bugid, attachmentid, commentid, dateline, userid, field, original, changed)
65 VALUES
66 (" . $this->bugid . ", " . $this->attachmentid . ", " . $this->commentid . ", " . TIMENOW . ",
67 " . $bugsys->userinfo['userid'] . ", '" . $bugsys->escape($diffdata['field']) . "',
68 '" . $bugsys->escape($diffdata['initial']) . "', '" . $bugsys->escape($diffdata['final']) . "'
69 )"
70 );
71 }
72
73 /**
74 * Compares two values and creates a report of their differences
75 *
76 * @param string Name of the field
77 * @param mixed Initial value
78 * @param mixed Final value
79 *
80 * @return array Difference report
81 */
82 function diff($field, $initial, $final)
83 {
84 $field = trim($field);
85 $initial = trim($initial);
86 $final = trim($final);
87
88 if (empty($field))
89 {
90 return -1;
91 }
92
93 if (empty($initial) AND empty($final))
94 {
95 if (!$this->allowempty)
96 {
97 return -1;
98 }
99 }
100
101 if (!$this->allowempty)
102 {
103 if ($initial === $final)
104 {
105 return -1;
106 }
107 }
108
109 return array('field' => $field, 'initial' => $initial, 'final' => $final);
110 }
111 }
112
113 /*=====================================================================*\
114 || ###################################################################
115 || # $HeadURL$
116 || # $Id$
117 || ###################################################################
118 \*=====================================================================*/
119 ?>