3 * ArtifactCanned.class - Class to handle canned responses
5 * SourceForge: Breaking Down the Barriers to Open Source Development
6 * Copyright 1999-2001 (c) VA Linux Systems
7 * http://sourceforge.net
12 require_once('common/include/Error.class');
14 class ArtifactCanned extends Error {
17 * The artifact type object
19 * @var object $ArtifactType
24 * Array of artifact data
26 * @var array $data_array
31 * ArtifactCanned() - constructor
33 * Use this constructor if you are modifying an existing artifact
35 * @param object The Artifact Type object
36 * @param array (all fields from artifact_file_user_vw) OR id from database
39 function ArtifactCanned(&$ArtifactType, $data=false) {
42 //was ArtifactType legit?
43 if (!$ArtifactType || !is_object($ArtifactType)) {
44 $this->setError('ArtifactCanned: No Valid ArtifactType');
47 //did ArtifactType have an error?
48 if ($ArtifactType->isError()) {
49 $this->setError('ArtifactCanned: '.$Artifact->getErrorMessage());
52 $this->ArtifactType =& $ArtifactType;
55 if (is_array($data)) {
56 $this->data_array =& $data;
59 if (!$this->fetchData($data)) {
66 $this->setError('No ID Passed');
71 * create() - create a new item in the database
73 * @param string The item title
74 * @param string The item body
75 * @return id on success / false on failure
77 function create($title, $body) {
81 if (!$title || !$body) {
82 $this->setError('ArtifactCanned: name and assignee are Required');
85 if (!$this->ArtifactType->userIsAdmin()) {
86 $this->setError('Permission Denied');
90 $sql="INSERT INTO artifact_canned_responses (group_artifact_id,title,body)
91 VALUES ('".$this->ArtifactType->getID()."',
92 '". htmlspecialchars($title) ."','". htmlspecialchars($body) ."')";
94 $result=db_query($sql);
96 if ($result && db_affected_rows($result) > 0) {
100 $this->setError(db_error());
106 // Now set up our internal data structures
108 if (!$this->fetchData($id)) {
115 * fetchData() - re-fetch the data for this ArtifactCanned from the database
120 function fetchData($id) {
121 $res=db_query("SELECT * FROM artifact_canned_responses WHERE id='$id'");
122 if (!$res || db_numrows($res) < 1) {
123 $this->setError('ArtifactCanned: Invalid ArtifactCanned ID');
126 $this->data_array =& db_fetch_array($res);
127 db_free_result($res);
132 * getArtifactType() - get the ArtifactType Object this ArtifactCanned message is associated with
134 * @return ArtifactType
136 function &getArtifactType() {
137 return $this->ArtifactType;
141 * getID() - get this ArtifactCanned message's ID
146 return $this->data_array['id'];
150 * getTitle() - get the title
154 function getTitle() {
155 return $this->data_array['title'];
159 * getBody() - get the body of this message
161 * @return text message body
164 return $this->data_array['body'];
168 * update() - update an ArtifactCanned message
170 * @param string Title of the message
171 * @param string Body of the message
174 function update($title,$body) {
175 if (!$this->ArtifactType->userIsAdmin()) {
176 $this->setError('Permission Denied');
179 if (!$title || !$body) {
180 $this->setError('Missing Params');
184 $sql="UPDATE artifact_canned_responses
185 SET title='". htmlspecialchars($title) ."',body='". htmlspecialchars($body) ."'
186 WHERE group_artifact_id='". $this->ArtifactType->getID() ."' AND id='". $this->getID() ."'";
188 $result=db_query($sql);
190 if ($result && db_affected_rows($result) > 0) {
193 $this->setError(db_error());