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)) {
277 * fetchData - re-fetch the data for this ArtifactType from the database.
279 * @param int The artifact type ID.
280 * @return boolean success.
282 function fetchData($artifact_type_id) {
283 $res = db_query_params ('SELECT * FROM artifact_group_list_vw
284 WHERE group_artifact_id=$1
286 array ($artifact_type_id,
287 $this->Group->getID())) ;
288 if (!$res || db_numrows($res) < 1) {
289 $this->setError('ArtifactType: Invalid ArtifactTypeID');
292 $this->data_array = db_fetch_array($res);
293 db_free_result($res);
298 * getGroup - get the Group object this ArtifactType is associated with.
300 * @return Object The Group object.
302 function &getGroup() {
307 * getID - get this ArtifactTypeID.
309 * @return int The group_artifact_id #.
312 return $this->data_array['group_artifact_id'];
316 * getOpenCount - get the count of open tracker items in this tracker type.
318 * @return int The count.
320 function getOpenCount() {
321 return $this->data_array['open_count'];
325 * getTotalCount - get the total number of tracker items in this tracker type.
327 * @return int The total count.
329 function getTotalCount() {
330 return $this->data_array['count'];
334 * allowsAnon - determine if non-logged-in users can post.
336 * @return boolean allow_anonymous_submissions.
338 function allowsAnon() {
339 return $this->data_array['allow_anon'];
343 * getSubmitInstructions - get the free-form string strings.
345 * @return string instructions.
347 function getSubmitInstructions() {
348 return $this->data_array['submit_instructions'];
352 * getBrowseInstructions - get the free-form string strings.
354 * @return string instructions.
356 function getBrowseInstructions() {
357 return $this->data_array['browse_instructions'];
361 * emailAll - determine if we're supposed to email on every event.
363 * @return boolean email_all.
365 function emailAll() {
366 return $this->data_array['email_all_updates'];
370 * emailAddress - defined email address to send events to.
372 * @return string email.
374 function getEmailAddress() {
375 return $this->data_array['email_address'];
379 * isPublic - whether non-group-members can view.
381 * @return boolean is_public.
383 function isPublic() {
384 return $this->data_array['is_public'];
388 * getName - the name of this ArtifactType.
390 * @return string name.
393 return $this->data_array['name'];
397 * getFormattedName - formatted name of this ArtifactType
399 * @return string formatted name
401 function getFormattedName() {
402 $name = preg_replace('/[^[:alnum:]]/','',$this->getName());
403 $name = strtolower($name);
408 * getUnixName - returns the name used by email gateway
410 * @return string unix name
412 function getUnixName() {
413 return strtolower($this->Group->getUnixName()).'-'.$this->getFormattedName();
417 * getReturnEmailAddress() - return the return email address for notification emails
419 * @return string return email address
421 function getReturnEmailAddress() {
424 if(forge_get_config('use_gateways')) {
425 $address .= strtolower($this->getUnixName());
427 $address .= 'noreply';
429 $address .= '@'.forge_get_config('web_host');
434 * getDescription - the description of this ArtifactType.
436 * @return string description.
438 function getDescription() {
439 return $this->data_array['description'];
443 * getDuePeriod - how many seconds until it's considered overdue.
445 * @return int seconds.
447 function getDuePeriod() {
448 return $this->data_array['due_period'];
452 * getStatusTimeout - how many seconds until an item is stale.
454 * @return int seconds.
456 function getStatusTimeout() {
457 return $this->data_array['status_timeout'];
461 * getCustomStatusField - return the extra_field_id of the field containing the custom status.
463 * @return int extra_field_id.
465 function getCustomStatusField() {
466 return $this->data_array['custom_status_field'];
470 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
471 * @param int The extra field id.
472 * @return boolean success.
474 function setCustomStatusField($extra_field_id) {
475 $res = db_query_params ('UPDATE artifact_group_list SET custom_status_field=$1
476 WHERE group_artifact_id=$2',
477 array ($extra_field_id,
483 * usesCustomStatuses - boolean
485 * @return boolean use_custom_statues.
487 function usesCustomStatuses() {
488 return $this->getCustomStatusField();
492 * remap status - pass the extra_fields array and return the status_id, either open/closed
493 * @param int The status_id
494 * @param array Complex array of extra_field_data
495 * @return int status_id.
497 function remapStatus($status_id,$extra_fields) {
498 if ($this->usesCustomStatuses()) {
499 //get the selected element for the extra_field_status element
500 $csfield = $this->getCustomStatusField();
501 if (array_key_exists($csfield, $extra_fields)) {
502 $element_id=$extra_fields[$csfield];
504 //convert that element_id into the status_id
505 $res = db_query_params ('SELECT status_id FROM artifact_extra_field_elements WHERE element_id=$1',
506 array ($element_id)) ;
508 $this->setError('Error Remapping Status: '.db_error());
511 $status_id=db_result($res,0,'status_id');
513 // custom status was not passed... use the first status from the database
514 $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',
516 if (db_numrows($res) == 0) { // No values available
517 $this->setError('Error Remapping Status');
520 $status_id=db_result($res,0,'status_id');
523 if ($status_id < 1 || $status_id > 4) {
524 echo "INVALID STATUS REMAP: $status_id FROM SELECTED ELEMENT: $element_id";
534 * getDataType - flag that is generally unused but can mark the difference between bugs, patches, etc.
536 * @return int The type (1) bug (2) support (3) patch (4) feature (0) other.
538 function getDataType() {
539 return $this->data_array['datatype'];
543 * setMonitor - user can monitor this artifact.
545 * @return false - always false - always use the getErrorMessage() for feedback
547 function setMonitor ($user_id = -1) {
548 if ($user_id == -1) {
549 if (!session_loggedin()) {
550 $this->setError(_('You can only monitor if you are logged in'));
553 $user_id = user_getid() ;
556 $res = db_query_params ('SELECT * FROM artifact_type_monitor WHERE group_artifact_id=$1 AND user_id=$2',
557 array ($this->getID(),
559 if (!$res || db_numrows($res) < 1) {
561 $res = db_query_params ('INSERT INTO artifact_type_monitor (group_artifact_id,user_id) VALUES ($1,$2)',
562 array ($this->getID(),
565 $this->setError(db_error());
568 $this->setError(_('Now Monitoring Tracker'));
572 //already monitoring - remove their monitor
573 db_query_params ('DELETE FROM artifact_type_monitor
574 WHERE group_artifact_id=$1
576 array ($this->getID(),
578 $this->setError(_('Tracker Monitoring Deactivated'));
583 function isMonitoring() {
584 if (!session_loggedin()) {
587 $result = db_query_params ('SELECT count(*) AS count FROM artifact_type_monitor
588 WHERE user_id=$1 AND group_artifact_id=$2',
591 $row_count = db_fetch_array($result);
592 return $result && $row_count['count'] > 0;
596 * getMonitorIds - array of email addresses monitoring this Artifact.
598 * @return array of email addresses monitoring this Artifact.
600 function &getMonitorIds() {
601 $res = db_query_params ('SELECT user_id FROM artifact_type_monitor WHERE group_artifact_id=$1',
602 array ($this->getID())) ;
603 return util_result_column_to_array($res);
607 * getExtraFields - List of possible user built extra fields
608 * set up for this artifact type.
610 * @return arrays of data;
612 function getExtraFields($types=array()) {
614 $filter = implode(',', $types);
615 $types = explode(',', $filter);
619 if (!isset($this->extra_fields["$filter"])) {
620 $this->extra_fields["$filter"] = array();
622 $res = db_query_params ('SELECT *
623 FROM artifact_extra_field_list
624 WHERE group_artifact_id=$1
625 AND field_type = ANY ($2)
626 ORDER BY field_type ASC',
627 array ($this->getID(),
628 db_int_array_to_any_clause ($types))) ;
630 $res = db_query_params ('SELECT *
631 FROM artifact_extra_field_list
632 WHERE group_artifact_id=$1
633 ORDER BY field_type ASC',
634 array ($this->getID())) ;
636 while($arr = db_fetch_array($res)) {
637 $this->extra_fields["$filter"][$arr['extra_field_id']] = $arr;
641 return $this->extra_fields["$filter"];
645 * cloneFieldsFrom - clone all the fields and elements from another tracker
647 * @return boolean true/false on success
649 function cloneFieldsFrom($clone_tracker_id) {
651 $g =& group_get_object(forge_get_config('template_group'));
652 if (!$g || !is_object($g)) {
653 $this->setError('Could Not Get Template Group');
655 } elseif ($g->isError()) {
656 $this->setError('Template Group Error '.$g->getErrorMessage());
659 $at = new ArtifactType($g,$clone_tracker_id);
660 if (!$at || !is_object($at)) {
661 $this->setError('Could Not Get Tracker To Clone');
663 } elseif ($at->isError()) {
664 $this->setError('Clone Tracker Error '.$at->getErrorMessage());
667 $efs = $at->getExtraFields();
670 // Iterate list of extra fields
673 foreach ($efs as $ef) {
674 //new field in this tracker
675 $nef = new ArtifactExtraField($this);
676 if (!$nef->create( util_unconvert_htmlspecialchars($ef['field_name']), $ef['field_type'], $ef['attribute1'], $ef['attribute2'], $ef['is_required'], $ef['alias'])) {
677 $this->setError('Error Creating New Extra Field: '.$nef->getErrorMessage());
682 // Iterate the elements
684 $resel = db_query_params ('SELECT * FROM artifact_extra_field_elements WHERE extra_field_id=$1',
685 array ($ef['extra_field_id'])) ;
686 while ($el = db_fetch_array($resel)) {
688 $nel = new ArtifactExtraFieldElement($nef);
689 if (!$nel->create( util_unconvert_htmlspecialchars($el['element_name']), $el['status_id'] )) {
691 $this->setError('Error Creating New Extra Field Element: '.$nel->getErrorMessage());
702 * getExtraFieldName - Get a box name using the box ID
704 * @param int id of an extra field.
705 * @return string name of extra field.
707 function getExtraFieldName($extra_field_id) {
708 $arr = $this->getExtraFields();
709 return $arr[$extra_field_id]['field_name'];
713 * getExtraFieldElements - List of possible admin configured
714 * extra field elements. This function is used to
715 * present the boxes and choices on the main Add/Update page.
717 * @param int id of the extra field
718 * @return array of elements for this extra field.
720 function getExtraFieldElements($id) {
725 if (!isset($this->extra_field[$id])) {
726 $this->extra_field[$id] = array();
727 $res = db_query_params ('SELECT element_id,element_name,status_id
728 FROM artifact_extra_field_elements
729 WHERE extra_field_id = $1
730 ORDER BY element_pos ASC, element_id ASC',
733 while($arr = db_fetch_array($res)) {
734 $this->extra_field[$id][$i++] = $arr;
736 // if (count($this->extra_field[$id]) == 0) {
741 return $this->extra_field[$id];
745 * getElementName - get the name of a particular element.
747 * @return string The name.
749 function getElementName($choiceid) {
753 if (is_array($choiceid)) {
754 $choiceid=implode(',', array_map('intval', $choiceid));
756 $choiceid=intval($choiceid);
758 if ($choiceid == 100) {
761 if (!isset($this->element_name["$choiceid"])) {
762 $res = db_query_params ('SELECT element_id,extra_field_id,element_name
763 FROM artifact_extra_field_elements
764 WHERE element_id = ANY ($1)',
765 array (db_int_array_to_any_clause (explode (',', $choiceid)))) ;
766 if (db_numrows($res) > 1) {
767 $arr=util_result_column_to_array($res,2);
768 $this->element_name["$choiceid"]=implode(',',$arr);
770 $this->element_name["$choiceid"]=db_result($res,0,'element_name');
773 return $this->element_name["$choiceid"];
777 * getElementStatusID - get the status of a particular element.
779 * @return int The status
781 function getElementStatusID($choiceid) {
785 if (is_array($choiceid)) {
786 $choiceid=implode(',',$choiceid);
788 if ($choiceid == 100) {
791 if (!$this->element_status["$choiceid"]) {
792 $res = db_query_params ('SELECT element_id,extra_field_id,status_id
793 FROM artifact_extra_field_elements
794 WHERE element_id = ANY ($1)',
795 array (db_int_array_to_any_clause (explode (',', $choiceid)))) ;
796 if (db_numrows($res) > 1) {
797 $arr=util_result_column_to_array($res,2);
798 $this->element_status["$choiceid"]=implode(',',$arr);
800 $this->element_status["$choiceid"]=db_result($res,0,'status_id');
803 return $this->element_status["$choiceid"];
808 * delete - delete this tracker and all its related data.
810 * @param bool I'm Sure.
811 * @param bool I'm REALLY sure.
812 * @return bool true/false;
814 function delete($sure, $really_sure) {
815 if (!$sure || !$really_sure) {
816 $this->setMissingParamsError(_('Please tick all checkboxes.'));
819 if (!forge_check_perm ('tracker_admin', $this->Group->getID())) {
820 $this->setPermissionDeniedError();
824 db_query_params ('DELETE FROM artifact_extra_field_data
825 WHERE EXISTS (SELECT artifact_id FROM artifact
826 WHERE group_artifact_id=$1
827 AND artifact.artifact_id=artifact_extra_field_data.artifact_id)',
828 array ($this->getID())) ;
829 //echo '0.1'.db_error();
830 db_query_params ('DELETE FROM artifact_extra_field_elements
831 WHERE EXISTS (SELECT extra_field_id FROM artifact_extra_field_list
832 WHERE group_artifact_id=$1
833 AND artifact_extra_field_list.extra_field_id = artifact_extra_field_elements.extra_field_id)',
834 array ($this->getID())) ;
835 //echo '0.2'.db_error();
836 db_query_params ('DELETE FROM artifact_extra_field_list
837 WHERE group_artifact_id=$1',
838 array ($this->getID())) ;
839 //echo '0.3'.db_error();
840 db_query_params ('DELETE FROM artifact_canned_responses
841 WHERE group_artifact_id=$1',
842 array ($this->getID())) ;
843 //echo '1'.db_error();
844 db_query_params ('DELETE FROM artifact_counts_agg
845 WHERE group_artifact_id=$1',
846 array ($this->getID())) ;
847 //echo '5'.db_error();
848 db_query_params ('DELETE FROM artifact_file
849 WHERE EXISTS (SELECT artifact_id FROM artifact
850 WHERE group_artifact_id=$1
851 AND artifact.artifact_id=artifact_file.artifact_id)',
852 array ($this->getID())) ;
853 //echo '6'.db_error();
854 db_query_params ('DELETE FROM artifact_message
855 WHERE EXISTS (SELECT artifact_id FROM artifact
856 WHERE group_artifact_id=$1
857 AND artifact.artifact_id=artifact_message.artifact_id)',
858 array ($this->getID())) ;
859 //echo '7'.db_error();
860 db_query_params ('DELETE FROM artifact_history
861 WHERE EXISTS (SELECT artifact_id FROM artifact
862 WHERE group_artifact_id=$1
863 AND artifact.artifact_id=artifact_history.artifact_id)',
864 array ($this->getID())) ;
865 //echo '8'.db_error();
866 db_query_params ('DELETE FROM artifact_monitor
867 WHERE EXISTS (SELECT artifact_id FROM artifact
868 WHERE group_artifact_id=$1
869 AND artifact.artifact_id=artifact_monitor.artifact_id)',
870 array ($this->getID())) ;
871 //echo '9'.db_error();
872 db_query_params ('DELETE FROM artifact
873 WHERE group_artifact_id=$1',
874 array ($this->getID())) ;
875 //echo '4'.db_error();
876 db_query_params ('DELETE FROM artifact_group_list
877 WHERE group_artifact_id=$1',
878 array ($this->getID())) ;
879 //echo '11'.db_error();
883 $this->Group->normalizeAllRoles () ;
889 * getSubmitters - returns a result set of submitters.
891 * @return database result set.
893 function getSubmitters() {
894 if (!isset($this->submitters_res)) {
895 $this->submitters_res = db_query_params ('SELECT DISTINCT submitted_by, submitted_realname
897 WHERE group_artifact_id=$1
898 ORDER BY submitted_realname',
899 array ($this->getID()));
901 return $this->submitters_res;
905 * getCannedResponses - returns a result set of canned responses.
907 * @return database result set.
909 function getCannedResponses() {
910 if (!isset($this->cannedresponses_res)) {
911 $this->cannedresponses_res = db_query_params ('SELECT id,title
912 FROM artifact_canned_responses
913 WHERE group_artifact_id=$1',
914 array ($this->getID()));
916 return $this->cannedresponses_res;
920 * getStatuses - returns a result set of statuses.
922 * These statuses are either the default open/closed or any number of
923 * custom statuses that are stored in the extra fields. On insert/update
924 * to an artifact the status_id is remapped from the extra_field_element_id to
925 * the standard open/closed id.
927 * @param boolean Whether to show the real statuses or not.
928 * @return database result set.
930 function getStatuses() {
931 if (!isset($this->status_res)) {
932 $this->status_res = db_query_params ('SELECT * FROM artifact_status',array());
934 return $this->status_res;
938 * getStatusName - returns the name of this status.
940 * @param int The status ID.
941 * @return string name.
943 function getStatusName($id) {
944 $result = db_query_params ('select status_name from artifact_status WHERE id=$1',
946 if ($result && db_numrows($result) > 0) {
947 return db_result($result,0,'status_name');
949 return 'Error - Not Found';
954 * update - use this to update this ArtifactType in the database.
956 * @param string The item name.
957 * @param string The item description.
958 * @param bool (1) true (0) false - whether to email on all updates.
959 * @param string The address to send new entries and updates to.
960 * @param int Days before this item is considered overdue.
961 * @param int Days before stale items time out.
962 * @param bool (1) true (0) false - whether the resolution box should be shown.
963 * @param string Free-form string that project admins can place on the submit page.
964 * @param string Free-form string that project admins can place on the browse page.
965 * @return true on success, false on failure.
967 function update($name,$description,$email_all,$email_address,
968 $due_period, $status_timeout,$use_resolution,$submit_instructions,$browse_instructions) {
970 if (!forge_check_perm ('tracker_admin', $this->Group->getID())) {
971 $this->setPermissionDeniedError();
975 if ($this->getDataType()) {
976 $name=$this->getName();
977 $description=$this->getDescription();
980 if (!$name || !$description || !$due_period || !$status_timeout) {
981 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
985 $result = db_query_params('SELECT count(*) AS count FROM artifact_group_list WHERE group_id=$1 AND name=$2 AND group_artifact_id!=$3',
986 array ($this->Group->getID(), $name, $this->getID()));
988 $this->setError('ArtifactType::Update(): '.db_error());
991 if (db_result($result, 0, 'count')) {
992 $this->setError(_('Tracker name already used'));
996 if ($email_address) {
997 $invalid_emails = validate_emails($email_address);
998 if (count($invalid_emails) > 0) {
999 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
1004 $email_all = ((!$email_all) ? 0 : $email_all);
1005 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
1007 $res = db_query_params ('UPDATE artifact_group_list SET
1010 email_all_updates=$3,
1014 submit_instructions=$7,
1015 browse_instructions=$8
1016 WHERE group_artifact_id=$9 AND group_id=$10',
1018 htmlspecialchars($name),
1019 htmlspecialchars($description),
1022 $due_period * (60*60*24),
1023 $status_timeout * (60*60*24),
1024 htmlspecialchars($submit_instructions),
1025 htmlspecialchars($browse_instructions),
1027 $this->Group->getID())) ;
1029 if (!$res || db_affected_rows($res) < 1) {
1030 $this->setError('ArtifactType::Update(): '.db_error());
1033 $this->fetchData($this->getID());
1039 * getBrowseList - get the free-form string strings.
1041 * @return string instructions.
1043 function getBrowseList() {
1044 $list = $this->data_array['browse_list'];
1046 // remove status_id in the browse list if a custom status exists
1047 if (count($this->getExtraFields(array(ARTIFACT_EXTRAFIELDTYPE_STATUS))) > 0) {
1048 $arr = explode(',', $list);
1049 $idx = array_search('status_id', $arr);
1050 if($idx !== False) {
1051 array_splice($arr, $idx, 1);
1053 return join(',', $arr);
1060 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
1061 * @param int The extra field id.
1062 * @return boolean success.
1064 function setBrowseList($list) {
1065 $res=db_query_params ('UPDATE artifact_group_list
1067 WHERE group_artifact_id=$2',
1070 $this->fetchData($this->getID());
1078 // c-file-style: "bsd"