5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2002-2004, GForge, LLC
7 * Copyright 2009, Roland Mas
8 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'include/Error.class.php';
27 require_once $gfcommon.'tracker/ArtifactExtraFieldElement.class.php';
30 * Gets an ArtifactType object from the artifact type id
32 * @param artType_id the ArtifactType id
33 * @param res the DB handle if passed in (optional)
34 * @return the ArtifactType object
36 function &artifactType_get_object($artType_id,$res=false) {
37 global $ARTIFACTTYPE_OBJ;
38 if (!isset($ARTIFACTTYPE_OBJ["_".$artType_id."_"])) {
40 //the db result handle was passed in
42 $res = db_query_params ('SELECT * FROM artifact_group_list_vw WHERE group_artifact_id=$1',
43 array ($artType_id)) ;
45 if (!$res || db_numrows($res) < 1 ){
46 $ARTIFACTTYPE_OBJ["_".$artType_id."_"]=false;
48 $data = db_fetch_array($res);
49 $Group = group_get_object($data["group_id"]);
50 $ARTIFACTTYPE_OBJ["_".$artType_id."_"]= new ArtifactType($Group,$data["group_artifact_id"],$data);
53 return $ARTIFACTTYPE_OBJ["_".$artType_id."_"];
56 function artifacttype_get_groupid ($artifact_type_id) {
57 global $ARTIFACTTYPE_OBJ;
58 if (isset($ARTIFACTTYPE_OBJ["_".$artifact_type_id."_"])) {
59 return $ARTIFACTTYPE_OBJ["_".$artifact_type_id."_"]->Group->getID() ;
62 $res = db_query_params ('SELECT group_id FROM artifact_group_list WHERE group_artifact_id=$1',
63 array ($artifact_type_id)) ;
64 if (!$res || db_numrows($res) < 1) {
67 $arr = db_fetch_array ($res);
68 return $arr['group_id'] ;
71 class ArtifactType extends Error {
78 var $Group; //group object
81 * extra_fields 3d array - the IDs and Names of the extra fields
83 * @var array extra_fields;
85 var $extra_fields = array();
88 * extra_field[extra_field_id] array - the IDs and Names of elements on the extra fields
90 * @var array extra_field
95 * Technicians db resource ID.
97 * @var int $technicians_res.
102 * Submitters db resource ID.
104 * @var int $submitters_res.
109 * Status db resource ID.
111 * @var int $status_res.
116 * Canned responses resource ID.
118 * @var int $cannecresponses_res.
120 var $cannedresponses_res;
123 * Array of artifact data.
125 * @var array $data_array.
130 * Array of element names so they only have to be fetched once from db.
132 * @var array $data_array.
137 * Array of element status so they only have to be fetched once from db.
139 * @var array $data_array.
144 * ArtifactType - constructor.
146 * @param object The Group object.
147 * @param int The id # assigned to this artifact type in the db.
148 * @param array The associative array of data.
149 * @return boolean success.
151 function __construct($Group,$artifact_type_id=false, $arr=false) {
153 if (!$Group || !is_object($Group)) {
154 $this->setError('No Valid Group Object');
157 if ($Group->isError()) {
158 $this->setError('ArtifactType: '.$Group->getErrorMessage());
161 $this->Group = $Group;
162 if ($artifact_type_id) {
163 if (!$arr || !is_array($arr)) {
164 if (!$this->fetchData($artifact_type_id)) {
168 $this->data_array =& $arr;
169 if ($this->data_array['group_id'] != $this->Group->getID()) {
170 $this->setError('Group_id in db result does not match Group Object');
171 $this->data_array = null;
176 // Make sure they can even access this object
178 if (!forge_check_perm ('tracker', $this->getID(), 'read')) {
179 $this->setPermissionDeniedError();
180 $this->data_array = null;
187 * create - use this to create a new ArtifactType in the database.
189 * @param string The type name.
190 * @param string The type description.
191 * @param bool (1) true (0) false - viewable by general public.
192 * @param bool (1) true (0) false - whether non-logged-in users can submit.
193 * @param bool (1) true (0) false - whether to email on all updates.
194 * @param string The address to send new entries and updates to.
195 * @param int Days before this item is considered overdue.
196 * @param bool (1) trye (0) false - whether the resolution box should be shown.
197 * @param string Free-form string that project admins can place on the submit page.
198 * @param string Free-form string that project admins can place on the browse page.
199 * @param int (1) bug tracker, (2) Support Tracker, (3) Patch Tracker, (4) features (0) other.
200 * @return id on success, false on failure.
202 function create($name,$description,$is_public,$allow_anon,$email_all,$email_address,
203 $due_period,$use_resolution,$submit_instructions,$browse_instructions,$datatype=0) {
205 if (!forge_check_perm('tracker_admin', $this->Group->getID())) {
206 $this->setPermissionDeniedError();
210 if (!$name || !$description || !$due_period) {
211 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
215 if ($email_address) {
216 $invalid_emails = validate_emails($email_address);
217 if (count($invalid_emails) > 0) {
218 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
223 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
224 $is_public = ((!$is_public) ? 0 : $is_public);
225 $allow_anon = ((!$allow_anon) ? 0 : $allow_anon);
226 $email_all = ((!$email_all) ? 0 : $email_all);
230 $res = db_query_params ('INSERT INTO
245 ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)',
246 array ($this->Group->getID(),
247 htmlspecialchars($name),
248 htmlspecialchars($description),
253 $due_period*(60*60*24),
255 htmlspecialchars($submit_instructions),
256 htmlspecialchars($browse_instructions),
259 $id = db_insertid($res,'artifact_group_list','group_artifact_id');
262 $this->setError('ArtifactType: '.db_error());
266 if (!$this->fetchData($id)) {
270 $this->Group->normalizeAllRoles ();
278 * fetchData - re-fetch the data for this ArtifactType from the database.
280 * @param int The artifact type ID.
281 * @return boolean success.
283 function fetchData($artifact_type_id) {
284 $res = db_query_params ('SELECT * FROM artifact_group_list_vw
285 WHERE group_artifact_id=$1
287 array ($artifact_type_id,
288 $this->Group->getID())) ;
289 if (!$res || db_numrows($res) < 1) {
290 $this->setError('ArtifactType: Invalid ArtifactTypeID');
293 $this->data_array = db_fetch_array($res);
294 db_free_result($res);
299 * getGroup - get the Group object this ArtifactType is associated with.
301 * @return Object The Group object.
303 function &getGroup() {
308 * getID - get this ArtifactTypeID.
310 * @return int The group_artifact_id #.
313 return $this->data_array['group_artifact_id'];
317 * getOpenCount - get the count of open tracker items in this tracker type.
319 * @return int The count.
321 function getOpenCount() {
322 return $this->data_array['open_count'];
326 * getTotalCount - get the total number of tracker items in this tracker type.
328 * @return int The total count.
330 function getTotalCount() {
331 return $this->data_array['count'];
335 * allowsAnon - determine if non-logged-in users can post.
337 * @return boolean allow_anonymous_submissions.
339 function allowsAnon() {
340 return $this->data_array['allow_anon'];
344 * getSubmitInstructions - get the free-form string strings.
346 * @return string instructions.
348 function getSubmitInstructions() {
349 return $this->data_array['submit_instructions'];
353 * getBrowseInstructions - get the free-form string strings.
355 * @return string instructions.
357 function getBrowseInstructions() {
358 return $this->data_array['browse_instructions'];
362 * emailAll - determine if we're supposed to email on every event.
364 * @return boolean email_all.
366 function emailAll() {
367 return $this->data_array['email_all_updates'];
371 * emailAddress - defined email address to send events to.
373 * @return string email.
375 function getEmailAddress() {
376 return $this->data_array['email_address'];
380 * isPublic - whether non-group-members can view.
382 * @return boolean is_public.
384 function isPublic() {
385 return $this->data_array['is_public'];
389 * getName - the name of this ArtifactType.
391 * @return string name.
394 return $this->data_array['name'];
398 * getFormattedName - formatted name of this ArtifactType
400 * @return string formatted name
402 function getFormattedName() {
403 $name = preg_replace('/[^[:alnum:]]/','',$this->getName());
404 $name = strtolower($name);
409 * getUnixName - returns the name used by email gateway
411 * @return string unix name
413 function getUnixName() {
414 return strtolower($this->Group->getUnixName()).'-'.$this->getFormattedName();
418 * getReturnEmailAddress() - return the return email address for notification emails
420 * @return string return email address
422 function getReturnEmailAddress() {
425 if(forge_get_config('use_gateways')) {
426 $address .= strtolower($this->getUnixName());
428 $address .= 'noreply';
430 $address .= '@'.forge_get_config('web_host');
435 * getDescription - the description of this ArtifactType.
437 * @return string description.
439 function getDescription() {
440 return $this->data_array['description'];
444 * getDuePeriod - how many seconds until it's considered overdue.
446 * @return int seconds.
448 function getDuePeriod() {
449 return $this->data_array['due_period'];
453 * getStatusTimeout - how many seconds until an item is stale.
455 * @return int seconds.
457 function getStatusTimeout() {
458 return $this->data_array['status_timeout'];
462 * getCustomStatusField - return the extra_field_id of the field containing the custom status.
464 * @return int extra_field_id.
466 function getCustomStatusField() {
467 return $this->data_array['custom_status_field'];
471 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
472 * @param int The extra field id.
473 * @return boolean success.
475 function setCustomStatusField($extra_field_id) {
476 $res = db_query_params ('UPDATE artifact_group_list SET custom_status_field=$1
477 WHERE group_artifact_id=$2',
478 array ($extra_field_id,
484 * usesCustomStatuses - boolean
486 * @return boolean use_custom_statues.
488 function usesCustomStatuses() {
489 return $this->getCustomStatusField();
493 * remap status - pass the extra_fields array and return the status_id, either open/closed
494 * @param int The status_id
495 * @param array Complex array of extra_field_data
496 * @return int status_id.
498 function remapStatus($status_id,$extra_fields) {
499 if ($this->usesCustomStatuses()) {
500 //get the selected element for the extra_field_status element
501 $csfield = $this->getCustomStatusField();
502 if (array_key_exists($csfield, $extra_fields)) {
503 $element_id=$extra_fields[$csfield];
505 //convert that element_id into the status_id
506 $res = db_query_params ('SELECT status_id FROM artifact_extra_field_elements WHERE element_id=$1',
507 array ($element_id)) ;
509 $this->setError('Error Remapping Status: '.db_error());
512 $status_id=db_result($res,0,'status_id');
514 // custom status was not passed... use the first status from the database
515 $res = db_query_params ('SELECT status_id FROM artifact_extra_field_elements WHERE extra_field_id=$1 ORDER BY element_id ASC LIMIT 1 OFFSET 0',
517 if (db_numrows($res) == 0) { // No values available
518 $this->setError('Error Remapping Status');
521 $status_id=db_result($res,0,'status_id');
524 if ($status_id < 1 || $status_id > 4) {
525 echo "INVALID STATUS REMAP: $status_id FROM SELECTED ELEMENT: $element_id";
535 * getDataType - flag that is generally unused but can mark the difference between bugs, patches, etc.
537 * @return int The type (1) bug (2) support (3) patch (4) feature (0) other.
539 function getDataType() {
540 return $this->data_array['datatype'];
544 * setMonitor - user can monitor this artifact.
546 * @return false - always false - always use the getErrorMessage() for feedback
548 function setMonitor ($user_id = -1) {
549 if ($user_id == -1) {
550 if (!session_loggedin()) {
551 $this->setError(_('You can only monitor if you are logged in'));
554 $user_id = user_getid() ;
557 $res = db_query_params ('SELECT * FROM artifact_type_monitor WHERE group_artifact_id=$1 AND user_id=$2',
558 array ($this->getID(),
560 if (!$res || db_numrows($res) < 1) {
562 $res = db_query_params ('INSERT INTO artifact_type_monitor (group_artifact_id,user_id) VALUES ($1,$2)',
563 array ($this->getID(),
566 $this->setError(db_error());
569 $this->setError(_('Now Monitoring Tracker'));
573 //already monitoring - remove their monitor
574 db_query_params ('DELETE FROM artifact_type_monitor
575 WHERE group_artifact_id=$1
577 array ($this->getID(),
579 $this->setError(_('Tracker Monitoring Deactivated'));
584 function isMonitoring() {
585 if (!session_loggedin()) {
588 $result = db_query_params ('SELECT count(*) AS count FROM artifact_type_monitor
589 WHERE user_id=$1 AND group_artifact_id=$2',
592 $row_count = db_fetch_array($result);
593 return $result && $row_count['count'] > 0;
597 * getMonitorIds - array of email addresses monitoring this Artifact.
599 * @return array of email addresses monitoring this Artifact.
601 function &getMonitorIds() {
602 $res = db_query_params ('SELECT user_id FROM artifact_type_monitor WHERE group_artifact_id=$1',
603 array ($this->getID())) ;
604 return util_result_column_to_array($res);
608 * getExtraFields - List of possible user built extra fields
609 * set up for this artifact type.
611 * @return arrays of data;
613 function getExtraFields($types=array()) {
615 $filter = implode(',', $types);
616 $types = explode(',', $filter);
620 if (!isset($this->extra_fields["$filter"])) {
621 $this->extra_fields["$filter"] = array();
623 $res = db_query_params ('SELECT *
624 FROM artifact_extra_field_list
625 WHERE group_artifact_id=$1
626 AND field_type = ANY ($2)
627 ORDER BY field_type ASC',
628 array ($this->getID(),
629 db_int_array_to_any_clause ($types))) ;
631 $res = db_query_params ('SELECT *
632 FROM artifact_extra_field_list
633 WHERE group_artifact_id=$1
634 ORDER BY field_type ASC',
635 array ($this->getID())) ;
637 while($arr = db_fetch_array($res)) {
638 $this->extra_fields["$filter"][$arr['extra_field_id']] = $arr;
642 return $this->extra_fields["$filter"];
646 * cloneFieldsFrom - clone all the fields and elements from another tracker
648 * @return boolean true/false on success
650 function cloneFieldsFrom($clone_tracker_id) {
652 $g =& group_get_object(forge_get_config('template_group'));
653 if (!$g || !is_object($g)) {
654 $this->setError('Could Not Get Template Group');
656 } elseif ($g->isError()) {
657 $this->setError('Template Group Error '.$g->getErrorMessage());
660 $at = new ArtifactType($g,$clone_tracker_id);
661 if (!$at || !is_object($at)) {
662 $this->setError('Could Not Get Tracker To Clone');
664 } elseif ($at->isError()) {
665 $this->setError('Clone Tracker Error '.$at->getErrorMessage());
668 $efs = $at->getExtraFields();
671 // Iterate list of extra fields
674 foreach ($efs as $ef) {
675 //new field in this tracker
676 $nef = new ArtifactExtraField($this);
677 if (!$nef->create( util_unconvert_htmlspecialchars($ef['field_name']), $ef['field_type'], $ef['attribute1'], $ef['attribute2'], $ef['is_required'], $ef['alias'])) {
678 $this->setError('Error Creating New Extra Field: '.$nef->getErrorMessage());
683 // Iterate the elements
685 $resel = db_query_params ('SELECT * FROM artifact_extra_field_elements WHERE extra_field_id=$1',
686 array ($ef['extra_field_id'])) ;
687 while ($el = db_fetch_array($resel)) {
689 $nel = new ArtifactExtraFieldElement($nef);
690 if (!$nel->create( util_unconvert_htmlspecialchars($el['element_name']), $el['status_id'] )) {
692 $this->setError('Error Creating New Extra Field Element: '.$nel->getErrorMessage());
703 * getExtraFieldName - Get a box name using the box ID
705 * @param int id of an extra field.
706 * @return string name of extra field.
708 function getExtraFieldName($extra_field_id) {
709 $arr = $this->getExtraFields();
710 return $arr[$extra_field_id]['field_name'];
714 * getExtraFieldElements - List of possible admin configured
715 * extra field elements. This function is used to
716 * present the boxes and choices on the main Add/Update page.
718 * @param int id of the extra field
719 * @return array of elements for this extra field.
721 function getExtraFieldElements($id) {
726 if (!isset($this->extra_field[$id])) {
727 $this->extra_field[$id] = array();
728 $res = db_query_params ('SELECT element_id,element_name,status_id
729 FROM artifact_extra_field_elements
730 WHERE extra_field_id = $1
731 ORDER BY element_pos ASC, element_id ASC',
734 while($arr = db_fetch_array($res)) {
735 $this->extra_field[$id][$i++] = $arr;
737 // if (count($this->extra_field[$id]) == 0) {
742 return $this->extra_field[$id];
746 * getElementName - get the name of a particular element.
748 * @return string The name.
750 function getElementName($choiceid) {
754 if (is_array($choiceid)) {
755 $choiceid=implode(',', array_map('intval', $choiceid));
757 $choiceid=intval($choiceid);
759 if ($choiceid == 100) {
762 if (!isset($this->element_name["$choiceid"])) {
763 $res = db_query_params ('SELECT element_id,extra_field_id,element_name
764 FROM artifact_extra_field_elements
765 WHERE element_id = ANY ($1)',
766 array (db_int_array_to_any_clause (explode (',', $choiceid)))) ;
767 if (db_numrows($res) > 1) {
768 $arr=util_result_column_to_array($res,2);
769 $this->element_name["$choiceid"]=implode(',',$arr);
771 $this->element_name["$choiceid"]=db_result($res,0,'element_name');
774 return $this->element_name["$choiceid"];
778 * getElementStatusID - get the status of a particular element.
780 * @return int The status
782 function getElementStatusID($choiceid) {
786 if (is_array($choiceid)) {
787 $choiceid=implode(',',$choiceid);
789 if ($choiceid == 100) {
792 if (!$this->element_status["$choiceid"]) {
793 $res = db_query_params ('SELECT element_id,extra_field_id,status_id
794 FROM artifact_extra_field_elements
795 WHERE element_id = ANY ($1)',
796 array (db_int_array_to_any_clause (explode (',', $choiceid)))) ;
797 if (db_numrows($res) > 1) {
798 $arr=util_result_column_to_array($res,2);
799 $this->element_status["$choiceid"]=implode(',',$arr);
801 $this->element_status["$choiceid"]=db_result($res,0,'status_id');
804 return $this->element_status["$choiceid"];
809 * delete - delete this tracker and all its related data.
811 * @param bool I'm Sure.
812 * @param bool I'm REALLY sure.
813 * @return bool true/false;
815 function delete($sure, $really_sure) {
816 if (!$sure || !$really_sure) {
817 $this->setMissingParamsError(_('Please tick all checkboxes.'));
820 if (!forge_check_perm ('tracker_admin', $this->Group->getID())) {
821 $this->setPermissionDeniedError();
825 db_query_params ('DELETE FROM artifact_extra_field_data
826 WHERE EXISTS (SELECT artifact_id FROM artifact
827 WHERE group_artifact_id=$1
828 AND artifact.artifact_id=artifact_extra_field_data.artifact_id)',
829 array ($this->getID())) ;
830 //echo '0.1'.db_error();
831 db_query_params ('DELETE FROM artifact_extra_field_elements
832 WHERE EXISTS (SELECT extra_field_id FROM artifact_extra_field_list
833 WHERE group_artifact_id=$1
834 AND artifact_extra_field_list.extra_field_id = artifact_extra_field_elements.extra_field_id)',
835 array ($this->getID())) ;
836 //echo '0.2'.db_error();
837 db_query_params ('DELETE FROM artifact_extra_field_list
838 WHERE group_artifact_id=$1',
839 array ($this->getID())) ;
840 //echo '0.3'.db_error();
841 db_query_params ('DELETE FROM artifact_canned_responses
842 WHERE group_artifact_id=$1',
843 array ($this->getID())) ;
844 //echo '1'.db_error();
845 db_query_params ('DELETE FROM artifact_counts_agg
846 WHERE group_artifact_id=$1',
847 array ($this->getID())) ;
848 //echo '5'.db_error();
849 db_query_params ('DELETE FROM artifact_file
850 WHERE EXISTS (SELECT artifact_id FROM artifact
851 WHERE group_artifact_id=$1
852 AND artifact.artifact_id=artifact_file.artifact_id)',
853 array ($this->getID())) ;
854 //echo '6'.db_error();
855 db_query_params ('DELETE FROM artifact_message
856 WHERE EXISTS (SELECT artifact_id FROM artifact
857 WHERE group_artifact_id=$1
858 AND artifact.artifact_id=artifact_message.artifact_id)',
859 array ($this->getID())) ;
860 //echo '7'.db_error();
861 db_query_params ('DELETE FROM artifact_history
862 WHERE EXISTS (SELECT artifact_id FROM artifact
863 WHERE group_artifact_id=$1
864 AND artifact.artifact_id=artifact_history.artifact_id)',
865 array ($this->getID())) ;
866 //echo '8'.db_error();
867 db_query_params ('DELETE FROM artifact_monitor
868 WHERE EXISTS (SELECT artifact_id FROM artifact
869 WHERE group_artifact_id=$1
870 AND artifact.artifact_id=artifact_monitor.artifact_id)',
871 array ($this->getID())) ;
872 //echo '9'.db_error();
873 db_query_params ('DELETE FROM artifact
874 WHERE group_artifact_id=$1',
875 array ($this->getID())) ;
876 //echo '4'.db_error();
877 db_query_params ('DELETE FROM artifact_group_list
878 WHERE group_artifact_id=$1',
879 array ($this->getID())) ;
880 //echo '11'.db_error();
884 $this->Group->normalizeAllRoles () ;
890 * getSubmitters - returns a result set of submitters.
892 * @return database result set.
894 function getSubmitters() {
895 if (!isset($this->submitters_res)) {
896 $this->submitters_res = db_query_params ('SELECT DISTINCT submitted_by, submitted_realname
898 WHERE group_artifact_id=$1
899 ORDER BY submitted_realname',
900 array ($this->getID()));
902 return $this->submitters_res;
906 * getCannedResponses - returns a result set of canned responses.
908 * @return database result set.
910 function getCannedResponses() {
911 if (!isset($this->cannedresponses_res)) {
912 $this->cannedresponses_res = db_query_params ('SELECT id,title
913 FROM artifact_canned_responses
914 WHERE group_artifact_id=$1',
915 array ($this->getID()));
917 return $this->cannedresponses_res;
921 * getStatuses - returns a result set of statuses.
923 * These statuses are either the default open/closed or any number of
924 * custom statuses that are stored in the extra fields. On insert/update
925 * to an artifact the status_id is remapped from the extra_field_element_id to
926 * the standard open/closed id.
928 * @param boolean Whether to show the real statuses or not.
929 * @return database result set.
931 function getStatuses() {
932 if (!isset($this->status_res)) {
933 $this->status_res = db_query_params ('SELECT * FROM artifact_status',array());
935 return $this->status_res;
939 * getStatusName - returns the name of this status.
941 * @param int The status ID.
942 * @return string name.
944 function getStatusName($id) {
945 $result = db_query_params ('select status_name from artifact_status WHERE id=$1',
947 if ($result && db_numrows($result) > 0) {
948 return db_result($result,0,'status_name');
950 return 'Error - Not Found';
955 * update - use this to update this ArtifactType in the database.
957 * @param string The item name.
958 * @param string The item description.
959 * @param bool (1) true (0) false - whether to email on all updates.
960 * @param string The address to send new entries and updates to.
961 * @param int Days before this item is considered overdue.
962 * @param int Days before stale items time out.
963 * @param bool (1) true (0) false - whether the resolution box should be shown.
964 * @param string Free-form string that project admins can place on the submit page.
965 * @param string Free-form string that project admins can place on the browse page.
966 * @return true on success, false on failure.
968 function update($name,$description,$email_all,$email_address,
969 $due_period, $status_timeout,$use_resolution,$submit_instructions,$browse_instructions) {
971 if (!forge_check_perm ('tracker_admin', $this->Group->getID())) {
972 $this->setPermissionDeniedError();
976 if ($this->getDataType()) {
977 $name=$this->getName();
978 $description=$this->getDescription();
981 if (!$name || !$description || !$due_period || !$status_timeout) {
982 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
986 $result = db_query_params('SELECT count(*) AS count FROM artifact_group_list WHERE group_id=$1 AND name=$2 AND group_artifact_id!=$3',
987 array ($this->Group->getID(), $name, $this->getID()));
989 $this->setError('ArtifactType::Update(): '.db_error());
992 if (db_result($result, 0, 'count')) {
993 $this->setError(_('Tracker name already used'));
997 if ($email_address) {
998 $invalid_emails = validate_emails($email_address);
999 if (count($invalid_emails) > 0) {
1000 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
1005 $email_all = ((!$email_all) ? 0 : $email_all);
1006 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
1008 $res = db_query_params ('UPDATE artifact_group_list SET
1011 email_all_updates=$3,
1015 submit_instructions=$7,
1016 browse_instructions=$8
1017 WHERE group_artifact_id=$9 AND group_id=$10',
1019 htmlspecialchars($name),
1020 htmlspecialchars($description),
1023 $due_period * (60*60*24),
1024 $status_timeout * (60*60*24),
1025 htmlspecialchars($submit_instructions),
1026 htmlspecialchars($browse_instructions),
1028 $this->Group->getID())) ;
1030 if (!$res || db_affected_rows($res) < 1) {
1031 $this->setError('ArtifactType::Update(): '.db_error());
1034 $this->fetchData($this->getID());
1040 * getBrowseList - get the free-form string strings.
1042 * @return string instructions.
1044 function getBrowseList() {
1045 $list = $this->data_array['browse_list'];
1047 // remove status_id in the browse list if a custom status exists
1048 if (count($this->getExtraFields(array(ARTIFACT_EXTRAFIELDTYPE_STATUS))) > 0) {
1049 $arr = explode(',', $list);
1050 $idx = array_search('status_id', $arr);
1051 if($idx !== False) {
1052 array_splice($arr, $idx, 1);
1054 return join(',', $arr);
1061 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
1062 * @param int The extra field id.
1063 * @return boolean success.
1065 function setBrowseList($list) {
1066 $res=db_query_params ('UPDATE artifact_group_list
1068 WHERE group_artifact_id=$2',
1071 $this->fetchData($this->getID());
1079 // c-file-style: "bsd"