3 * ArtifactCanned.class.php - 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 $gfcommon.'include/Error.class.php';
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) {
92 if (!$title || !$body) {
93 $this->setError(_('ArtifactCanned: name and assignee are Required'));
96 if (!$this->ArtifactType->userIsAdmin()) {
97 $this->setPermissionDeniedError();
101 $sql="INSERT INTO artifact_canned_responses (group_artifact_id,title,body)
102 VALUES ('".$this->ArtifactType->getID()."',
103 '". htmlspecialchars($title) ."','". htmlspecialchars($body) ."')";
105 $result=db_query($sql);
107 if ($result && db_affected_rows($result) > 0) {
111 $this->setError(db_error());
117 // Now set up our internal data structures
119 if (!$this->fetchData($id)) {
126 * fetchData - re-fetch the data for this ArtifactCanned from the database.
128 * @param int The ID number.
129 * @return boolean success.
131 function fetchData($id) {
132 $res=db_query("SELECT * FROM artifact_canned_responses WHERE id='$id'");
133 if (!$res || db_numrows($res) < 1) {
134 $this->setError('ArtifactCanned: Invalid ArtifactCanned ID');
137 $this->data_array =& db_fetch_array($res);
138 db_free_result($res);
143 * getArtifactType - get the ArtifactType Object this ArtifactCanned message is associated with.
145 * @return ArtifactType.
147 function &getArtifactType() {
148 return $this->ArtifactType;
152 * getID - get this ArtifactCanned message's ID.
154 * @return int The id #.
157 return $this->data_array['id'];
161 * getTitle - get the title.
163 * @return string The title.
165 function getTitle() {
166 return $this->data_array['title'];
170 * getBody - get the body of this message.
172 * @return string The message body.
175 return $this->data_array['body'];
179 * update - update an ArtifactCanned message.
181 * @param string Title of the message.
182 * @param string Body of the message.
183 * @return boolean success.
185 function update($title,$body) {
186 if (!$this->ArtifactType->userIsAdmin()) {
187 $this->setPermissionDeniedError();
190 if (!$title || !$body) {
191 $this->setMissingParamsError();
195 $sql="UPDATE artifact_canned_responses
196 SET title='". htmlspecialchars($title) ."',body='". htmlspecialchars($body) ."'
197 WHERE group_artifact_id='". $this->ArtifactType->getID() ."' AND id='". $this->getID() ."'";
199 $result=db_query($sql);
201 if ($result && db_affected_rows($result) > 0) {
204 $this->setError(db_error());
212 // c-file-style: "bsd"