3 * ArtifactCanned.class - Class to handle canned responses
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
11 * This file is part of GForge.
13 * GForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * GForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 require_once('common/include/Error.class');
29 class ArtifactCanned extends Error {
32 * The artifact type object.
34 * @var object $ArtifactType.
39 * Array of artifact data.
41 * @var array $data_array.
46 * ArtifactCanned - constructor.
48 * @param object The Artifact Type object.
49 * @param array (all fields from artifact_file_user_vw) OR id from database.
50 * @return boolean success.
52 function ArtifactCanned(&$ArtifactType, $data=false) {
55 //was ArtifactType legit?
56 if (!$ArtifactType || !is_object($ArtifactType)) {
57 $this->setError('ArtifactCanned: No Valid ArtifactType');
60 //did ArtifactType have an error?
61 if ($ArtifactType->isError()) {
62 $this->setError('ArtifactCanned: '.$Artifact->getErrorMessage());
65 $this->ArtifactType =& $ArtifactType;
68 if (is_array($data)) {
69 $this->data_array =& $data;
72 if (!$this->fetchData($data)) {
82 * create - create a new item in the database.
84 * @param string The item title.
85 * @param string The item body.
86 * @return id on success / false on failure.
88 function create($title, $body) {
93 if (!$title || !$body) {
94 $this->setError(_('ArtifactCanned: name and assignee are Required'));
97 if (!$this->ArtifactType->userIsAdmin()) {
98 $this->setPermissionDeniedError();
102 $sql="INSERT INTO artifact_canned_responses (group_artifact_id,title,body)
103 VALUES ('".$this->ArtifactType->getID()."',
104 '". htmlspecialchars($title) ."','". htmlspecialchars($body) ."')";
106 $result=db_query($sql);
108 if ($result && db_affected_rows($result) > 0) {
112 $this->setError(db_error());
118 // Now set up our internal data structures
120 if (!$this->fetchData($id)) {
127 * fetchData - re-fetch the data for this ArtifactCanned from the database.
129 * @param int The ID number.
130 * @return boolean success.
132 function fetchData($id) {
133 $res=db_query("SELECT * FROM artifact_canned_responses WHERE id='$id'");
134 if (!$res || db_numrows($res) < 1) {
135 $this->setError('ArtifactCanned: Invalid ArtifactCanned ID');
138 $this->data_array =& db_fetch_array($res);
139 db_free_result($res);
144 * getArtifactType - get the ArtifactType Object this ArtifactCanned message is associated with.
146 * @return ArtifactType.
148 function &getArtifactType() {
149 return $this->ArtifactType;
153 * getID - get this ArtifactCanned message's ID.
155 * @return int The id #.
158 return $this->data_array['id'];
162 * getTitle - get the title.
164 * @return string The title.
166 function getTitle() {
167 return $this->data_array['title'];
171 * getBody - get the body of this message.
173 * @return string The message body.
176 return $this->data_array['body'];
180 * update - update an ArtifactCanned message.
182 * @param string Title of the message.
183 * @param string Body of the message.
184 * @return boolean success.
186 function update($title,$body) {
187 if (!$this->ArtifactType->userIsAdmin()) {
188 $this->setPermissionDeniedError();
191 if (!$title || !$body) {
192 $this->setMissingParamsError();
196 $sql="UPDATE artifact_canned_responses
197 SET title='". htmlspecialchars($title) ."',body='". htmlspecialchars($body) ."'
198 WHERE group_artifact_id='". $this->ArtifactType->getID() ."' AND id='". $this->getID() ."'";
200 $result=db_query($sql);
202 if ($result && db_affected_rows($result) > 0) {
205 $this->setError(db_error());