5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2002-2004, GForge, LLC
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 require_once $gfcommon.'include/Error.class.php';
28 class ArtifactCanned extends Error {
31 * The artifact type object.
33 * @var object $ArtifactType.
38 * Array of artifact data.
40 * @var array $data_array.
45 * ArtifactCanned - constructor.
47 * @param object The Artifact Type object.
48 * @param array (all fields from artifact_file_user_vw) OR id from database.
49 * @return boolean success.
51 function ArtifactCanned(&$ArtifactType, $data=false) {
54 //was ArtifactType legit?
55 if (!$ArtifactType || !is_object($ArtifactType)) {
56 $this->setError('ArtifactCanned: No Valid ArtifactType');
59 //did ArtifactType have an error?
60 if ($ArtifactType->isError()) {
61 $this->setError('ArtifactCanned: '.$Artifact->getErrorMessage());
64 $this->ArtifactType =& $ArtifactType;
67 if (is_array($data)) {
68 $this->data_array =& $data;
71 if (!$this->fetchData($data)) {
81 * create - create a new item in the database.
83 * @param string The item title.
84 * @param string The item body.
85 * @return id on success / false on failure.
87 function create($title, $body) {
91 if (!$title || !$body) {
92 $this->setError(_('ArtifactCanned: name and assignee are Required'));
95 if (!$this->ArtifactType->userIsAdmin()) {
96 $this->setPermissionDeniedError();
100 $sql="INSERT INTO artifact_canned_responses (group_artifact_id,title,body)
101 VALUES ('".$this->ArtifactType->getID()."',
102 '". htmlspecialchars($title) ."','". htmlspecialchars($body) ."')";
104 $result=db_query($sql);
106 if ($result && db_affected_rows($result) > 0) {
110 $this->setError(db_error());
116 // Now set up our internal data structures
118 if (!$this->fetchData($id)) {
125 * fetchData - re-fetch the data for this ArtifactCanned from the database.
127 * @param int The ID number.
128 * @return boolean success.
130 function fetchData($id) {
131 $res=db_query("SELECT * FROM artifact_canned_responses WHERE id='$id'");
132 if (!$res || db_numrows($res) < 1) {
133 $this->setError('ArtifactCanned: Invalid ArtifactCanned ID');
136 $this->data_array =& db_fetch_array($res);
137 db_free_result($res);
142 * getArtifactType - get the ArtifactType Object this ArtifactCanned message is associated with.
144 * @return ArtifactType.
146 function &getArtifactType() {
147 return $this->ArtifactType;
151 * getID - get this ArtifactCanned message's ID.
153 * @return int The id #.
156 return $this->data_array['id'];
160 * getTitle - get the title.
162 * @return string The title.
164 function getTitle() {
165 return $this->data_array['title'];
169 * getBody - get the body of this message.
171 * @return string The message body.
174 return $this->data_array['body'];
178 * update - update an ArtifactCanned message.
180 * @param string Title of the message.
181 * @param string Body of the message.
182 * @return boolean success.
184 function update($title,$body) {
185 if (!$this->ArtifactType->userIsAdmin()) {
186 $this->setPermissionDeniedError();
189 if (!$title || !$body) {
190 $this->setMissingParamsError();
194 $sql="UPDATE artifact_canned_responses
195 SET title='". htmlspecialchars($title) ."',body='". htmlspecialchars($body) ."'
196 WHERE group_artifact_id='". $this->ArtifactType->getID() ."' AND id='". $this->getID() ."'";
198 $result=db_query($sql);
200 if ($result && db_affected_rows($result) > 0) {
203 $this->setError(db_error());
211 // c-file-style: "bsd"