5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2002-2004, GForge, LLC
7 * Copyright 2009, Roland Mas
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/Error.class.php';
27 class ArtifactCanned extends Error {
30 * The artifact type object.
32 * @var object $ArtifactType.
37 * Array of artifact data.
39 * @var array $data_array.
44 * ArtifactCanned - constructor.
46 * @param object The Artifact Type object.
47 * @param array (all fields from artifact_file_user_vw) OR id from database.
48 * @return boolean success.
50 function __construct(&$ArtifactType, $data=false) {
53 //was ArtifactType legit?
54 if (!$ArtifactType || !is_object($ArtifactType)) {
55 $this->setError('ArtifactCanned: No Valid ArtifactType');
58 //did ArtifactType have an error?
59 if ($ArtifactType->isError()) {
60 $this->setError('ArtifactCanned: '.$Artifact->getErrorMessage());
63 $this->ArtifactType =& $ArtifactType;
66 if (is_array($data)) {
67 $this->data_array =& $data;
70 if (!$this->fetchData($data)) {
80 * create - create a new item in the database.
82 * @param string The item title.
83 * @param string The item body.
84 * @return id on success / false on failure.
86 function create($title, $body) {
90 if (!$title || !$body) {
91 $this->setError(_('Title and Message Body are required'));
94 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
95 $this->setPermissionDeniedError();
98 $result = db_query_params ('INSERT INTO artifact_canned_responses (group_artifact_id,title,body) VALUES ($1,$2,$3)',
99 array ($this->ArtifactType->getID(),
100 htmlspecialchars($title),
101 htmlspecialchars($body))) ;
103 if ($result && db_affected_rows($result) > 0) {
107 $this->setError(db_error());
113 // Now set up our internal data structures
115 if (!$this->fetchData($id)) {
122 * fetchData - re-fetch the data for this ArtifactCanned from the database.
124 * @param int The ID number.
125 * @return boolean success.
127 function fetchData($id) {
128 $res = db_query_params ('SELECT * FROM artifact_canned_responses WHERE id=$1',
130 if (!$res || db_numrows($res) < 1) {
131 $this->setError('ArtifactCanned: Invalid ArtifactCanned ID');
134 $this->data_array = db_fetch_array($res);
135 db_free_result($res);
140 * getArtifactType - get the ArtifactType Object this ArtifactCanned message is associated with.
142 * @return ArtifactType.
144 function &getArtifactType() {
145 return $this->ArtifactType;
149 * getID - get this ArtifactCanned message's ID.
151 * @return int The id #.
154 return $this->data_array['id'];
158 * getTitle - get the title.
160 * @return string The title.
162 function getTitle() {
163 return $this->data_array['title'];
167 * getBody - get the body of this message.
169 * @return string The message body.
172 return $this->data_array['body'];
176 * update - update an ArtifactCanned message.
178 * @param string Title of the message.
179 * @param string Body of the message.
180 * @return boolean success.
182 function update($title,$body) {
183 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
184 $this->setPermissionDeniedError();
187 if (!$title || !$body) {
188 $this->setMissingParamsError();
192 $result = db_query_params ('UPDATE artifact_canned_responses
194 WHERE group_artifact_id=$3 AND id=$4',
195 array (htmlspecialchars($title),
196 htmlspecialchars($body),
197 $this->ArtifactType->getID(),
200 if ($result && db_affected_rows($result) > 0) {
203 $this->setError(db_error());
209 * delete - delete an ArtifactCanned message.
211 * @return boolean success.
214 if (!forge_check_perm ('tracker_admin', $this->ArtifactType->Group->getID())) {
215 $this->setPermissionDeniedError();
218 if (!$this->getID()) {
219 $this->setError('Internal error: No ID given');
223 $result = db_query_params('DELETE FROM artifact_canned_responses WHERE ID=$1',
224 array ($this->getID()));
226 if ($result && db_affected_rows($result) > 0) {
229 $this->setError(db_error());
237 // c-file-style: "bsd"