5 * Copyright 2004, Anthony J. Pugliese
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 require_once $gfcommon.'include/Error.class.php';
27 class ArtifactBoxOptions extends Error {
30 * The artifact type object.
32 * @var object $ArtifactType.
34 var $ArtifactType; //object
37 * Array of artifact data.
39 * @var array $data_array.
43 * ArtifactSelectionBox - Constructer
45 * @param object ArtifactType object.
46 * @param array (all fields from artifact_file_user_vw) OR id from database.
47 * @return boolean success.
49 function ArtifactBoxOptions(&$ArtifactType,$data=false) {
52 //was ArtifactType legit?
53 if (!$ArtifactType || !is_object($ArtifactType)) {
54 $this->setError('ArtifactSelectionBox: No Valid ArtifactType');
57 //did ArtifactType have an error?
58 if ($ArtifactType->isError()) {
59 $this->setError('ArtifactSelectionBox: '.$Artifact->getErrorMessage());
62 $this->ArtifactType =& $ArtifactType;
64 if (is_array($data)) {
65 $this->data_array =& $data;
68 if (!$this->fetchData($data)) {
78 * create - create a new row in the table used to store the
79 * choices for selection boxes. This function is only used for
80 * extra fields and boxes configured by the admin
82 * @param string Name of the choice
83 * @param int Id the box that contains the choice.
84 * @return true on success / false on failure.
87 function create($name,$id) {
88 //settype($id,"integer");
93 $this->setError(_('an element name is required'));
96 if (!$this->ArtifactType->userIsAdmin()) {
97 $this->setPermissionDeniedError();
100 $sql="INSERT INTO artifact_group_selection_box_options (artifact_box_id,box_options_name)
101 VALUES ('$id','".htmlspecialchars($name)."')";
103 $result=db_query($sql);
104 if ($result && db_affected_rows($result) > 0) {
108 $this->setError(db_error());
114 // Now set up our internal data structures
116 if (!$this->fetchData($id)) {
124 * fetchData - re-fetch the data for this ArtifactBoxOptions from the database.
126 * @param int ID of the Box.
127 * @return boolean success.
129 function fetchData($id) {
130 $res=db_query("SELECT * FROM artifact_group_selection_box_options WHERE id='$id'");
131 if (!$res || db_numrows($res) < 1) {
132 $this->setError('ArtifactSelectionBox: Invalid Artifact ID');
135 $this->data_array =& db_fetch_array($res);
136 db_free_result($res);
141 * getArtifactType - get the ArtifactType Object this ArtifactSelectionBox is associated with.
143 * @return object ArtifactType.
145 function &getArtifactType() {
146 return $this->ArtifactType;
150 * getID - get this ArtifactSelectionBox ID.
152 * @return int The id #.
155 return $this->data_array['id'];
159 * getBoxID - get this artifact box id.
161 * @return int The id #.
163 function getBoxID() {
164 return $this->data_array['artifact_box_id'];
168 * getName - get the name.
170 * @return string The name.
173 return $this->data_array['box_options_name'];
178 * update - update rows in the table used to store the choices
179 * for a selection box. This function is used only for extra
180 * boxes and fields configured by the admin
182 * @param string Name of the choice in a box.
183 * @param int Id of the box
184 * @param int id of the row
185 * @return boolean success.
187 function update($name,$boxid,$id) {
188 if (!$this->ArtifactType->userIsAdmin()) {
189 $this->setPermissionDeniedError();
193 $this->setMissingParamsError();
196 $sql="UPDATE artifact_group_selection_box_options
197 SET box_options_name='".htmlspecialchars($name)."'
199 // AND artifact_box_id='$boxid'";
200 $result=db_query($sql);
201 if ($result && db_affected_rows($result) > 0) {
204 $this->setError(db_error());
212 // c-file-style: "bsd"