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';
28 require_once $gfcommon.'tracker/ArtifactStorage.class.php';
31 * Gets an ArtifactType object from the artifact type id
33 * @param artType_id the ArtifactType id
34 * @param res the DB handle if passed in (optional)
35 * @return the ArtifactType object
37 function &artifactType_get_object($artType_id,$res=false) {
38 global $ARTIFACTTYPE_OBJ;
39 if (!isset($ARTIFACTTYPE_OBJ["_".$artType_id."_"])) {
41 //the db result handle was passed in
43 $res = db_query_params ('SELECT * FROM artifact_group_list_vw WHERE group_artifact_id=$1',
44 array ($artType_id)) ;
46 if (!$res || db_numrows($res) < 1 ){
47 $ARTIFACTTYPE_OBJ["_".$artType_id."_"]=false;
49 $data = db_fetch_array($res);
50 $Group = group_get_object($data["group_id"]);
51 $ARTIFACTTYPE_OBJ["_".$artType_id."_"]= new ArtifactType($Group,$data["group_artifact_id"],$data);
54 return $ARTIFACTTYPE_OBJ["_".$artType_id."_"];
57 function artifacttype_get_groupid ($artifact_type_id) {
58 global $ARTIFACTTYPE_OBJ;
59 if (isset($ARTIFACTTYPE_OBJ["_".$artifact_type_id."_"])) {
60 return $ARTIFACTTYPE_OBJ["_".$artifact_type_id."_"]->Group->getID() ;
63 $res = db_query_params ('SELECT group_id FROM artifact_group_list WHERE group_artifact_id=$1',
64 array ($artifact_type_id)) ;
65 if (!$res || db_numrows($res) < 1) {
68 $arr = db_fetch_array ($res);
69 return $arr['group_id'] ;
72 class ArtifactType extends Error {
79 var $Group; //group object
82 * extra_fields 3d array - the IDs and Names of the extra fields
84 * @var array extra_fields;
86 var $extra_fields = array();
89 * extra_field[extra_field_id] array - the IDs and Names of elements on the extra fields
91 * @var array extra_field
96 * Technicians db resource ID.
98 * @var int $technicians_res.
100 var $technicians_res;
103 * Submitters db resource ID.
105 * @var int $submitters_res.
110 * Status db resource ID.
112 * @var int $status_res.
117 * Canned responses resource ID.
119 * @var int $cannecresponses_res.
121 var $cannedresponses_res;
124 * Array of artifact data.
126 * @var array $data_array.
131 * Array of element names so they only have to be fetched once from db.
133 * @var array $data_array.
138 * Array of element status so they only have to be fetched once from db.
140 * @var array $data_array.
145 * ArtifactType - constructor.
147 * @param Group $Group The Group object.
148 * @param int|bool $artifact_type_id The id # assigned to this artifact type in the db.
149 * @param array|bool $arr The associative array of data.
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 - whether to email on all updates.
192 * @param string The address to send new entries and updates to.
193 * @param int Days before this item is considered overdue.
194 * @param bool (1) trye (0) false - whether the resolution box should be shown.
195 * @param string Free-form string that project admins can place on the submit page.
196 * @param string Free-form string that project admins can place on the browse page.
197 * @param int (1) bug tracker, (2) Support Tracker, (3) Patch Tracker, (4) features (0) other.
198 * @return id on success, false on failure.
200 function create($name,$description,$email_all,$email_address,
201 $due_period,$use_resolution,$submit_instructions,$browse_instructions,$datatype=0) {
203 if (!forge_check_perm('tracker_admin', $this->Group->getID())) {
204 $this->setPermissionDeniedError();
208 if (!$name || !$description || !$due_period) {
209 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
213 if ($email_address) {
214 $invalid_emails = validate_emails($email_address);
215 if (count($invalid_emails) > 0) {
216 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
221 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
222 $email_all = ((!$email_all) ? 0 : $email_all);
226 $res = db_query_params ('INSERT INTO
239 ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)',
240 array ($this->Group->getID(),
241 htmlspecialchars($name),
242 htmlspecialchars($description),
245 $due_period*(60*60*24),
247 htmlspecialchars($submit_instructions),
248 htmlspecialchars($browse_instructions),
251 $id = db_insertid($res,'artifact_group_list','group_artifact_id');
254 $this->setError('ArtifactType: '.db_error());
258 if (!$this->fetchData($id)) {
262 $this->Group->normalizeAllRoles ();
270 * fetchData - re-fetch the data for this ArtifactType from the database.
272 * @param int The artifact type ID.
273 * @return boolean success.
275 function fetchData($artifact_type_id) {
276 $res = db_query_params ('SELECT * FROM artifact_group_list_vw
277 WHERE group_artifact_id=$1
279 array ($artifact_type_id,
280 $this->Group->getID())) ;
281 if (!$res || db_numrows($res) < 1) {
282 $this->setError('ArtifactType: Invalid ArtifactTypeID');
285 $this->data_array = db_fetch_array($res);
286 db_free_result($res);
291 * getGroup - get the Group object this ArtifactType is associated with.
293 * @return Object The Group object.
295 function &getGroup() {
300 * getID - get this ArtifactTypeID.
302 * @return int The group_artifact_id #.
305 return $this->data_array['group_artifact_id'];
309 * getOpenCount - get the count of open tracker items in this tracker type.
311 * @return int The count.
313 function getOpenCount() {
314 return $this->data_array['open_count'];
318 * getTotalCount - get the total number of tracker items in this tracker type.
320 * @return int The total count.
322 function getTotalCount() {
323 return $this->data_array['count'];
327 * getSubmitInstructions - get the free-form string strings.
329 * @return string instructions.
331 function getSubmitInstructions() {
332 return $this->data_array['submit_instructions'];
336 * getBrowseInstructions - get the free-form string strings.
338 * @return string instructions.
340 function getBrowseInstructions() {
341 return $this->data_array['browse_instructions'];
345 * emailAll - determine if we're supposed to email on every event.
347 * @return boolean email_all.
349 function emailAll() {
350 return $this->data_array['email_all_updates'];
354 * emailAddress - defined email address to send events to.
356 * @return string email.
358 function getEmailAddress() {
359 return $this->data_array['email_address'];
363 * getName - the name of this ArtifactType.
365 * @return string name.
368 return $this->data_array['name'];
372 * getFormattedName - formatted name of this ArtifactType
374 * @return string formatted name
376 function getFormattedName() {
377 $name = preg_replace('/[^[:alnum:]]/','',$this->getName());
378 $name = strtolower($name);
383 * getUnixName - returns the name used by email gateway
385 * @return string unix name
387 function getUnixName() {
388 return strtolower($this->Group->getUnixName()).'-'.$this->getFormattedName();
392 * getReturnEmailAddress() - return the return email address for notification emails
394 * @return string return email address
396 function getReturnEmailAddress() {
399 if(forge_get_config('use_gateways')) {
400 $address .= strtolower($this->getUnixName());
402 $address .= 'noreply';
404 $address .= '@'.forge_get_config('web_host');
409 * getDescription - the description of this ArtifactType.
411 * @return string description.
413 function getDescription() {
414 return $this->data_array['description'];
418 * getDuePeriod - how many seconds until it's considered overdue.
420 * @return int seconds.
422 function getDuePeriod() {
423 return $this->data_array['due_period'];
427 * getStatusTimeout - how many seconds until an item is stale.
429 * @return int seconds.
431 function getStatusTimeout() {
432 return $this->data_array['status_timeout'];
436 * getCustomStatusField - return the extra_field_id of the field containing the custom status.
438 * @return int extra_field_id.
440 function getCustomStatusField() {
441 return $this->data_array['custom_status_field'];
445 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
446 * @param int The extra field id.
447 * @return boolean success.
449 function setCustomStatusField($extra_field_id) {
450 $res = db_query_params ('UPDATE artifact_group_list SET custom_status_field=$1
451 WHERE group_artifact_id=$2',
452 array ($extra_field_id,
458 * usesCustomStatuses - boolean
460 * @return boolean use_custom_statues.
462 function usesCustomStatuses() {
463 return $this->getCustomStatusField();
467 * remap status - pass the extra_fields array and return the status_id, either open/closed
468 * @param int The status_id
469 * @param array Complex array of extra_field_data
470 * @return int status_id.
472 function remapStatus($status_id,$extra_fields) {
473 if ($this->usesCustomStatuses()) {
474 //get the selected element for the extra_field_status element
475 $csfield = $this->getCustomStatusField();
476 if (array_key_exists($csfield, $extra_fields)) {
477 $element_id=$extra_fields[$csfield];
479 //convert that element_id into the status_id
480 $res = db_query_params ('SELECT status_id FROM artifact_extra_field_elements WHERE element_id=$1',
481 array ($element_id)) ;
483 $this->setError('Error Remapping Status: '.db_error());
486 $status_id=db_result($res,0,'status_id');
488 // custom status was not passed... use the first status from the database
489 $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',
491 if (db_numrows($res) == 0) { // No values available
492 $this->setError('Error Remapping Status');
495 $status_id=db_result($res,0,'status_id');
498 if ($status_id < 1 || $status_id > 4) {
499 echo "INVALID STATUS REMAP: $status_id FROM SELECTED ELEMENT: $element_id";
509 * getDataType - flag that is generally unused but can mark the difference between bugs, patches, etc.
511 * @return int The type (1) bug (2) support (3) patch (4) feature (0) other.
513 function getDataType() {
514 return $this->data_array['datatype'];
518 * setMonitor - user can monitor this artifact.
520 * @return false - always false - always use the getErrorMessage() for feedback
522 function setMonitor ($user_id = -1) {
523 if ($user_id == -1) {
524 if (!session_loggedin()) {
525 $this->setError(_('You can only monitor if you are logged in'));
528 $user_id = user_getid() ;
531 $res = db_query_params ('SELECT * FROM artifact_type_monitor WHERE group_artifact_id=$1 AND user_id=$2',
532 array ($this->getID(),
534 if (!$res || db_numrows($res) < 1) {
536 $res = db_query_params ('INSERT INTO artifact_type_monitor (group_artifact_id,user_id) VALUES ($1,$2)',
537 array ($this->getID(),
540 $this->setError(db_error());
543 $this->setError(_('Now Monitoring Tracker'));
547 //already monitoring - remove their monitor
548 db_query_params ('DELETE FROM artifact_type_monitor
549 WHERE group_artifact_id=$1
551 array ($this->getID(),
553 $this->setError(_('Tracker Monitoring Deactivated'));
558 function isMonitoring() {
559 if (!session_loggedin()) {
562 $result = db_query_params ('SELECT count(*) AS count FROM artifact_type_monitor
563 WHERE user_id=$1 AND group_artifact_id=$2',
566 $row_count = db_fetch_array($result);
567 return $result && $row_count['count'] > 0;
571 * getMonitorIds - array of email addresses monitoring this Artifact.
573 * @return array of email addresses monitoring this Artifact.
575 function &getMonitorIds() {
576 $res = db_query_params ('SELECT user_id FROM artifact_type_monitor WHERE group_artifact_id=$1',
577 array ($this->getID())) ;
578 return util_result_column_to_array($res);
582 * getExtraFields - List of possible user built extra fields
583 * set up for this artifact type.
585 * @return arrays of data;
587 function getExtraFields($types=array()) {
589 $filter = implode(',', $types);
590 $types = explode(',', $filter);
594 if (!isset($this->extra_fields["$filter"])) {
595 $this->extra_fields["$filter"] = array();
597 $res = db_query_params ('SELECT *
598 FROM artifact_extra_field_list
599 WHERE group_artifact_id=$1
600 AND field_type = ANY ($2)
601 ORDER BY field_type ASC',
602 array ($this->getID(),
603 db_int_array_to_any_clause ($types))) ;
605 $res = db_query_params ('SELECT *
606 FROM artifact_extra_field_list
607 WHERE group_artifact_id=$1
608 ORDER BY field_type ASC',
609 array ($this->getID())) ;
611 while($arr = db_fetch_array($res)) {
612 $this->extra_fields["$filter"][$arr['extra_field_id']] = $arr;
616 return $this->extra_fields["$filter"];
620 * cloneFieldsFrom - clone all the fields and elements from another tracker
622 * @return boolean true/false on success
624 function cloneFieldsFrom($clone_tracker_id) {
626 $g =& group_get_object(forge_get_config('template_group'));
627 if (!$g || !is_object($g)) {
628 $this->setError('Could Not Get Template Group');
630 } elseif ($g->isError()) {
631 $this->setError('Template Group Error '.$g->getErrorMessage());
634 $at = new ArtifactType($g,$clone_tracker_id);
635 if (!$at || !is_object($at)) {
636 $this->setError('Could Not Get Tracker To Clone');
638 } elseif ($at->isError()) {
639 $this->setError('Clone Tracker Error '.$at->getErrorMessage());
642 $efs = $at->getExtraFields();
645 // Iterate list of extra fields
648 foreach ($efs as $ef) {
649 //new field in this tracker
650 $nef = new ArtifactExtraField($this);
651 if (!$nef->create( util_unconvert_htmlspecialchars($ef['field_name']), $ef['field_type'], $ef['attribute1'], $ef['attribute2'], $ef['is_required'], $ef['alias'])) {
652 $this->setError('Error Creating New Extra Field: '.$nef->getErrorMessage());
657 // Iterate the elements
659 $resel = db_query_params ('SELECT * FROM artifact_extra_field_elements WHERE extra_field_id=$1',
660 array ($ef['extra_field_id'])) ;
661 while ($el = db_fetch_array($resel)) {
663 $nel = new ArtifactExtraFieldElement($nef);
664 if (!$nel->create( util_unconvert_htmlspecialchars($el['element_name']), $el['status_id'] )) {
666 $this->setError('Error Creating New Extra Field Element: '.$nel->getErrorMessage());
677 * getExtraFieldName - Get a box name using the box ID
679 * @param int id of an extra field.
680 * @return string name of extra field.
682 function getExtraFieldName($extra_field_id) {
683 $arr = $this->getExtraFields();
684 return $arr[$extra_field_id]['field_name'];
688 * getExtraFieldElements - List of possible admin configured
689 * extra field elements. This function is used to
690 * present the boxes and choices on the main Add/Update page.
692 * @param int id of the extra field
693 * @return array of elements for this extra field.
695 function getExtraFieldElements($id) {
700 if (!isset($this->extra_field[$id])) {
701 $this->extra_field[$id] = array();
702 $res = db_query_params ('SELECT element_id,element_name,status_id
703 FROM artifact_extra_field_elements
704 WHERE extra_field_id = $1
705 ORDER BY element_pos ASC, element_id ASC',
708 while($arr = db_fetch_array($res)) {
709 $this->extra_field[$id][$i++] = $arr;
711 // if (count($this->extra_field[$id]) == 0) {
716 return $this->extra_field[$id];
720 * getElementName - get the name of a particular element.
722 * @return string The name.
724 function getElementName($choiceid) {
728 if (is_array($choiceid)) {
729 $choiceid=implode(',', array_map('intval', $choiceid));
731 $choiceid=intval($choiceid);
733 if ($choiceid == 100) {
736 if (!isset($this->element_name["$choiceid"])) {
737 $res = db_query_params ('SELECT element_id,extra_field_id,element_name
738 FROM artifact_extra_field_elements
739 WHERE element_id = ANY ($1)',
740 array (db_int_array_to_any_clause (explode (',', $choiceid)))) ;
741 if (db_numrows($res) > 1) {
742 $arr=util_result_column_to_array($res,2);
743 $this->element_name["$choiceid"]=implode(',',$arr);
745 $this->element_name["$choiceid"]=db_result($res,0,'element_name');
748 return $this->element_name["$choiceid"];
752 * getElementStatusID - get the status of a particular element.
754 * @return int The status
756 function getElementStatusID($choiceid) {
760 if (is_array($choiceid)) {
761 $choiceid=implode(',',$choiceid);
763 if ($choiceid == 100) {
766 if (!$this->element_status["$choiceid"]) {
767 $res = db_query_params ('SELECT element_id,extra_field_id,status_id
768 FROM artifact_extra_field_elements
769 WHERE element_id = ANY ($1)',
770 array (db_int_array_to_any_clause (explode (',', $choiceid)))) ;
771 if (db_numrows($res) > 1) {
772 $arr=util_result_column_to_array($res,2);
773 $this->element_status["$choiceid"]=implode(',',$arr);
775 $this->element_status["$choiceid"]=db_result($res,0,'status_id');
778 return $this->element_status["$choiceid"];
783 * delete - delete this tracker and all its related data.
785 * @param bool I'm Sure.
786 * @param bool I'm REALLY sure.
787 * @return bool true/false;
789 function delete($sure, $really_sure) {
790 if (!$sure || !$really_sure) {
791 $this->setMissingParamsError(_('Please tick all checkboxes.'));
794 if (!forge_check_perm ('tracker_admin', $this->Group->getID())) {
795 $this->setPermissionDeniedError();
799 db_query_params ('DELETE FROM artifact_extra_field_data
800 WHERE EXISTS (SELECT artifact_id FROM artifact
801 WHERE group_artifact_id=$1
802 AND artifact.artifact_id=artifact_extra_field_data.artifact_id)',
803 array ($this->getID())) ;
804 //echo '0.1'.db_error();
805 db_query_params ('DELETE FROM artifact_extra_field_elements
806 WHERE EXISTS (SELECT extra_field_id FROM artifact_extra_field_list
807 WHERE group_artifact_id=$1
808 AND artifact_extra_field_list.extra_field_id = artifact_extra_field_elements.extra_field_id)',
809 array ($this->getID())) ;
810 //echo '0.2'.db_error();
811 db_query_params ('DELETE FROM artifact_extra_field_list
812 WHERE group_artifact_id=$1',
813 array ($this->getID())) ;
814 //echo '0.3'.db_error();
815 db_query_params ('DELETE FROM artifact_canned_responses
816 WHERE group_artifact_id=$1',
817 array ($this->getID())) ;
818 //echo '1'.db_error();
819 db_query_params ('DELETE FROM artifact_counts_agg
820 WHERE group_artifact_id=$1',
821 array ($this->getID())) ;
822 //echo '5'.db_error();
824 ArtifactStorage::instance()->deleteFromQuery('SELECT id FROM artifact_file
825 WHERE EXISTS (SELECT artifact_id FROM artifact
826 WHERE group_artifact_id=$1
827 AND artifact.artifact_id=artifact_file.artifact_id)',
828 array ($this->getID())) ;
830 db_query_params ('DELETE FROM artifact_file
831 WHERE EXISTS (SELECT artifact_id FROM artifact
832 WHERE group_artifact_id=$1
833 AND artifact.artifact_id=artifact_file.artifact_id)',
834 array ($this->getID())) ;
835 //echo '6'.db_error();
836 db_query_params ('DELETE FROM artifact_message
837 WHERE EXISTS (SELECT artifact_id FROM artifact
838 WHERE group_artifact_id=$1
839 AND artifact.artifact_id=artifact_message.artifact_id)',
840 array ($this->getID())) ;
841 //echo '7'.db_error();
842 db_query_params ('DELETE FROM artifact_history
843 WHERE EXISTS (SELECT artifact_id FROM artifact
844 WHERE group_artifact_id=$1
845 AND artifact.artifact_id=artifact_history.artifact_id)',
846 array ($this->getID())) ;
847 //echo '8'.db_error();
848 db_query_params ('DELETE FROM artifact_monitor
849 WHERE EXISTS (SELECT artifact_id FROM artifact
850 WHERE group_artifact_id=$1
851 AND artifact.artifact_id=artifact_monitor.artifact_id)',
852 array ($this->getID())) ;
853 //echo '9'.db_error();
854 db_query_params ('DELETE FROM artifact
855 WHERE group_artifact_id=$1',
856 array ($this->getID())) ;
857 //echo '4'.db_error();
858 db_query_params ('DELETE FROM artifact_group_list
859 WHERE group_artifact_id=$1',
860 array ($this->getID())) ;
861 //echo '11'.db_error();
864 ArtifactStorage::instance()->commit();
866 $this->Group->normalizeAllRoles () ;
872 * getSubmitters - returns a result set of submitters.
874 * @return database result set.
876 function getSubmitters() {
877 if (!isset($this->submitters_res)) {
878 $this->submitters_res = db_query_params ('SELECT DISTINCT submitted_by, submitted_realname
880 WHERE group_artifact_id=$1
881 ORDER BY submitted_realname',
882 array ($this->getID()));
884 return $this->submitters_res;
888 * getCannedResponses - returns a result set of canned responses.
890 * @return database result set.
892 function getCannedResponses() {
893 if (!isset($this->cannedresponses_res)) {
894 $this->cannedresponses_res = db_query_params ('SELECT id,title
895 FROM artifact_canned_responses
896 WHERE group_artifact_id=$1',
897 array ($this->getID()));
899 return $this->cannedresponses_res;
903 * getStatuses - returns a result set of statuses.
905 * These statuses are either the default open/closed or any number of
906 * custom statuses that are stored in the extra fields. On insert/update
907 * to an artifact the status_id is remapped from the extra_field_element_id to
908 * the standard open/closed id.
910 * @param boolean Whether to show the real statuses or not.
911 * @return database result set.
913 function getStatuses() {
914 if (!isset($this->status_res)) {
915 $this->status_res = db_query_params ('SELECT * FROM artifact_status',array());
917 return $this->status_res;
921 * getStatusName - returns the name of this status.
923 * @param int The status ID.
924 * @return string name.
926 function getStatusName($id) {
927 $result = db_query_params ('select status_name from artifact_status WHERE id=$1',
929 if ($result && db_numrows($result) > 0) {
930 return db_result($result,0,'status_name');
932 return 'Error - Not Found';
937 * update - use this to update this ArtifactType in the database.
939 * @param string The item name.
940 * @param string The item description.
941 * @param bool (1) true (0) false - whether to email on all updates.
942 * @param string The address to send new entries and updates to.
943 * @param int Days before this item is considered overdue.
944 * @param int Days before stale items time out.
945 * @param bool (1) true (0) false - whether the resolution box should be shown.
946 * @param string Free-form string that project admins can place on the submit page.
947 * @param string Free-form string that project admins can place on the browse page.
948 * @return true on success, false on failure.
950 function update($name,$description,$email_all,$email_address,
951 $due_period, $status_timeout,$use_resolution,$submit_instructions,$browse_instructions) {
953 if (!forge_check_perm ('tracker_admin', $this->Group->getID())) {
954 $this->setPermissionDeniedError();
958 if ($this->getDataType()) {
959 $name=$this->getName();
960 $description=$this->getDescription();
963 if (!$name || !$description || !$due_period || !$status_timeout) {
964 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
968 $result = db_query_params('SELECT count(*) AS count FROM artifact_group_list WHERE group_id=$1 AND name=$2 AND group_artifact_id!=$3',
969 array ($this->Group->getID(), $name, $this->getID()));
971 $this->setError('ArtifactType::Update(): '.db_error());
974 if (db_result($result, 0, 'count')) {
975 $this->setError(_('Tracker name already used'));
979 if ($email_address) {
980 $invalid_emails = validate_emails($email_address);
981 if (count($invalid_emails) > 0) {
982 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
987 $email_all = ((!$email_all) ? 0 : $email_all);
988 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
990 $res = db_query_params ('UPDATE artifact_group_list SET
993 email_all_updates=$3,
997 submit_instructions=$7,
998 browse_instructions=$8
999 WHERE group_artifact_id=$9 AND group_id=$10',
1001 htmlspecialchars($name),
1002 htmlspecialchars($description),
1005 $due_period * (60*60*24),
1006 $status_timeout * (60*60*24),
1007 htmlspecialchars($submit_instructions),
1008 htmlspecialchars($browse_instructions),
1010 $this->Group->getID())) ;
1012 if (!$res || db_affected_rows($res) < 1) {
1013 $this->setError('ArtifactType::Update(): '.db_error());
1016 $this->fetchData($this->getID());
1022 * getBrowseList - get the free-form string strings.
1024 * @return string instructions.
1026 function getBrowseList() {
1027 $list = $this->data_array['browse_list'];
1029 // remove status_id in the browse list if a custom status exists
1030 if (count($this->getExtraFields(array(ARTIFACT_EXTRAFIELDTYPE_STATUS))) > 0) {
1031 $arr = explode(',', $list);
1032 $idx = array_search('status_id', $arr);
1033 if($idx !== False) {
1034 array_splice($arr, $idx, 1);
1036 return join(',', $arr);
1043 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
1044 * @param int The extra field id.
1045 * @return boolean success.
1047 function setBrowseList($list) {
1048 $res=db_query_params ('UPDATE artifact_group_list
1050 WHERE group_artifact_id=$2',
1053 $this->fetchData($this->getID());
1061 // c-file-style: "bsd"