5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2002-2004, GForge, LLC
7 * Copyright 2009, Roland Mas
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 require_once $gfcommon.'include/Error.class.php';
28 require_once $gfcommon.'tracker/ArtifactExtraFieldElement.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 class ArtifactType extends Error {
64 var $Group; //group object
67 * extra_fields 3d array - the IDs and Names of the extra fields
69 * @var array extra_fields;
71 var $extra_fields = array();
74 * extra_field[extra_field_id] array - the IDs and Names of elements on the extra fields
76 * @var array extra_field
81 * Options db resource ID.
83 * @var int $options_res.
88 * Choice name db resource ID.
90 * @var int $choice_name_res.
95 * Current user permissions.
97 * @var int $current_user_perm.
99 var $current_user_perm;
102 * Technicians db resource ID.
104 * @var int $technicians_res.
106 var $technicians_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 ArtifactType(&$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 (!$this->userCanView()) {
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 $perm =& $this->Group->getPermission( session_get_user() );
207 if (!$perm || !is_object($perm) || !$perm->isArtifactAdmin()) {
208 $this->setPermissionDeniedError();
212 if (!$name || !$description || !$due_period) {
213 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
217 if ($email_address) {
218 $invalid_emails = validate_emails($email_address);
219 if (count($invalid_emails) > 0) {
220 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
225 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
226 $is_public = ((!$is_public) ? 0 : $is_public);
227 $allow_anon = ((!$allow_anon) ? 0 : $allow_anon);
228 $email_all = ((!$email_all) ? 0 : $email_all);
232 $res = db_query_params ('INSERT INTO
247 ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)',
248 array ($this->Group->getID(),
249 htmlspecialchars($name),
250 htmlspecialchars($description),
255 $due_period*(60*60*24),
257 htmlspecialchars($submit_instructions),
258 htmlspecialchars($browse_instructions),
261 $id = db_insertid($res,'artifact_group_list','group_artifact_id');
264 $this->setError('ArtifactType: '.db_error());
268 if (!$this->fetchData($id)) {
273 $this->Group->normalizeAllRoles () ;
280 * fetchData - re-fetch the data for this ArtifactType from the database.
282 * @param int The artifact type ID.
283 * @return boolean success.
285 function fetchData($artifact_type_id) {
286 $res = db_query_params ('SELECT * FROM artifact_group_list_vw
287 WHERE group_artifact_id=$1
289 array ($artifact_type_id,
290 $this->Group->getID())) ;
291 if (!$res || db_numrows($res) < 1) {
292 $this->setError('ArtifactType: Invalid ArtifactTypeID');
295 $this->data_array =& db_fetch_array($res);
296 db_free_result($res);
301 * getGroup - get the Group object this ArtifactType is associated with.
303 * @return Object The Group object.
305 function &getGroup() {
310 * getID - get this ArtifactTypeID.
312 * @return int The group_artifact_id #.
315 return $this->data_array['group_artifact_id'];
319 * getOpenCount - get the count of open tracker items in this tracker type.
321 * @return int The count.
323 function getOpenCount() {
324 return $this->data_array['open_count'];
328 * getTotalCount - get the total number of tracker items in this tracker type.
330 * @return int The total count.
332 function getTotalCount() {
333 return $this->data_array['count'];
337 * allowsAnon - determine if non-logged-in users can post.
339 * @return boolean allow_anonymous_submissions.
341 function allowsAnon() {
342 return $this->data_array['allow_anon'];
346 * getSubmitInstructions - get the free-form string strings.
348 * @return string instructions.
350 function getSubmitInstructions() {
351 return $this->data_array['submit_instructions'];
355 * getBrowseInstructions - get the free-form string strings.
357 * @return string instructions.
359 function getBrowseInstructions() {
360 return $this->data_array['browse_instructions'];
364 * emailAll - determine if we're supposed to email on every event.
366 * @return boolean email_all.
368 function emailAll() {
369 return $this->data_array['email_all_updates'];
373 * emailAddress - defined email address to send events to.
375 * @return string email.
377 function getEmailAddress() {
378 return $this->data_array['email_address'];
382 * isPublic - whether non-group-members can view.
384 * @return boolean is_public.
386 function isPublic() {
387 return $this->data_array['is_public'];
391 * getName - the name of this ArtifactType.
393 * @return string name.
396 return $this->data_array['name'];
400 * getFormattedName - formatted name of this ArtifactType
402 * @return string formatted name
404 function getFormattedName() {
405 $name = preg_replace('/[^[:alnum:]]/','',$this->getName());
406 $name = strtolower($name);
411 * getUnixName - returns the name used by email gateway
413 * @return string unix name
415 function getUnixName() {
416 return strtolower($this->Group->getUnixName()).'-'.$this->getFormattedName();
420 * getReturnEmailAddress() - return the return email address for notification emails
422 * @return string return email address
424 function getReturnEmailAddress() {
427 if(forge_get_config('use_gateways')) {
428 $address .= strtolower($this->getUnixName());
430 $address .= 'noreply';
432 $address .= '@'.forge_get_config('web_host');
437 * getDescription - the description of this ArtifactType.
439 * @return string description.
441 function getDescription() {
442 return $this->data_array['description'];
446 * getDuePeriod - how many seconds until it's considered overdue.
448 * @return int seconds.
450 function getDuePeriod() {
451 return $this->data_array['due_period'];
455 * getStatusTimeout - how many seconds until an item is stale.
457 * @return int seconds.
459 function getStatusTimeout() {
460 return $this->data_array['status_timeout'];
464 * getCustomStatusField - return the extra_field_id of the field containing the custom status.
466 * @return int extra_field_id.
468 function getCustomStatusField() {
469 return $this->data_array['custom_status_field'];
473 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
474 * @param int The extra field id.
475 * @return boolean success.
477 function setCustomStatusField($extra_field_id) {
478 $res = db_query_params ('UPDATE artifact_group_list SET custom_status_field=$1
479 WHERE group_artifact_id=$2',
480 array ($extra_field_id,
486 * usesCustomStatuses - boolean
488 * @return boolean use_custom_statues.
490 function usesCustomStatuses() {
491 return $this->getCustomStatusField();
495 * remap status - pass the extra_fields array and return the status_id, either open/closed
496 * @param int The status_id
497 * @param array Complex array of extra_field_data
498 * @return int status_id.
500 function remapStatus($status_id,$extra_fields) {
501 if ($this->usesCustomStatuses()) {
502 //get the selected element for the extra_field_status element
503 $csfield = $this->getCustomStatusField();
504 if (array_key_exists($csfield, $extra_fields)) {
505 $element_id=$extra_fields[$csfield];
507 //convert that element_id into the status_id
508 $res = db_query_params ('SELECT status_id FROM artifact_extra_field_elements WHERE element_id=$1',
509 array ($element_id)) ;
511 $this->setError('Error Remapping Status: '.db_error());
514 $status_id=db_result($res,0,'status_id');
516 // custom status was not passed... use the first status from the database
517 $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',
519 if (db_numrows($res) == 0) { // No values available
520 $this->setError('Error Remapping Status');
523 $status_id=db_result($res,0,'status_id');
526 if ($status_id < 1 || $status_id > 4) {
527 echo "INVALID STATUS REMAP: $status_id FROM SELECTED ELEMENT: $element_id";
537 * getDataType - flag that is generally unused but can mark the difference between bugs, patches, etc.
539 * @return int The type (1) bug (2) support (3) patch (4) feature (0) other.
541 function getDataType() {
542 return $this->data_array['datatype'];
546 * setMonitor - user can monitor this artifact.
548 * @return false - always false - always use the getErrorMessage() for feedback
550 function setMonitor ($user_id = -1) {
551 if ($user_id == -1) {
552 if (!session_loggedin()) {
553 $this->setError(_('You can only monitor if you are logged in'));
556 $user_id = user_getid() ;
559 $res = db_query_params ('SELECT * FROM artifact_type_monitor WHERE group_artifact_id=$1 AND user_id=$2',
560 array ($this->getID(),
562 if (!$res || db_numrows($res) < 1) {
564 $res = db_query_params ('INSERT INTO artifact_type_monitor (group_artifact_id,user_id) VALUES ($1,$2)',
565 array ($this->getID(),
568 $this->setError(db_error());
571 $this->setError(_('Now Monitoring Tracker'));
575 //already monitoring - remove their monitor
576 db_query_params ('DELETE FROM artifact_type_monitor
577 WHERE group_artifact_id=$1
579 array ($this->getID(),
581 $this->setError(_('Tracker Monitoring Deactivated'));
586 function isMonitoring() {
587 if (!session_loggedin()) {
590 $result = db_query_params ('SELECT count(*) AS count FROM artifact_type_monitor
591 WHERE user_id=$1 AND group_artifact_id=$2',
594 $row_count = db_fetch_array($result);
595 return $result && $row_count['count'] > 0;
599 * getMonitorIds - array of email addresses monitoring this Artifact.
601 * @return array of email addresses monitoring this Artifact.
603 function &getMonitorIds() {
604 $res = db_query_params ('SELECT user_id FROM artifact_type_monitor WHERE group_artifact_id=$1',
605 array ($this->getID())) ;
606 return util_result_column_to_array($res);
610 * getExtraFields - List of possible user built extra fields
611 * set up for this artifact type.
613 * @return arrays of data;
615 function getExtraFields($filter='') {
616 if (!isset($this->extra_fields["$filter"])) {
617 $this->extra_fields["$filter"] = array();
619 $res = db_query_params ('SELECT *
620 FROM artifact_extra_field_list
621 WHERE group_artifact_id=$1
622 AND field_type = ANY ($2)
623 ORDER BY field_type ASC',
624 array ($this->getID(),
625 db_int_array_to_any_clause (explode (',', $filter)))) ;
627 $res = db_query_params ('SELECT *
628 FROM artifact_extra_field_list
629 WHERE group_artifact_id=$1
630 ORDER BY field_type ASC',
631 array ($this->getID())) ;
633 while($arr = db_fetch_array($res)) {
634 $this->extra_fields["$filter"][$arr['extra_field_id']] = $arr;
638 return $this->extra_fields["$filter"];
642 * cloneFieldsFrom - clone all the fields and elements from another tracker
644 * @return boolean true/false on success
646 function cloneFieldsFrom($clone_tracker_id) {
647 global $sys_template_group;
648 $g =& group_get_object($sys_template_group);
649 if (!$g || !is_object($g)) {
650 $this->setError('Could Not Get Template Group');
652 } elseif ($g->isError()) {
653 $this->setError('Template Group Error '.$g->getErrorMessage());
656 $at =& new ArtifactType($g,$clone_tracker_id);
657 if (!$at || !is_object($at)) {
658 $this->setError('Could Not Get Tracker To Clone');
660 } elseif ($at->isError()) {
661 $this->setError('Clone Tracker Error '.$at->getErrorMessage());
664 $efs =& $at->getExtraFields();
668 // Iterate list of extra fields
671 foreach ($efs as $ef) {
672 //new field in this tracker
673 $nef = new ArtifactExtraField($this);
674 if (!$nef->create( addslashes(util_unconvert_htmlspecialchars($ef['field_name'])), $ef['field_type'], $ef['attribute1'], $ef['attribute2'], $ef['is_required'], $ef['alias'])) {
676 $this->setError('Error Creating New Extra Field: '.$nef->getErrorMessage());
680 // Iterate the elements
682 $resel = db_query_params ('SELECT * FROM artifact_extra_field_elements WHERE extra_field_id=$1',
683 array ($ef['extra_field_id'])) ;
684 while ($el =& db_fetch_array($resel)) {
686 $nel = new ArtifactExtraFieldElement($nef);
687 if (!$nel->create( addslashes(util_unconvert_htmlspecialchars($el['element_name'])), $el['status_id'] )) {
689 $this->setError('Error Creating New Extra Field Element: '.$nel->getErrorMessage());
700 * getExtraFieldName - Get a box name using the box ID
702 * @param int id of an extra field.
703 * @return string name of extra field.
705 function getExtraFieldName($extra_field_id) {
706 $arr = $this->getExtraFields();
707 return $arr[$extra_field_id]['field_name'];
711 * getExtraFieldElements - List of possible admin configured
712 * extra field elements. This function is used to
713 * present the boxes and choices on the main Add/Update page.
715 * @param int id of the extra field
716 * @return array of elements for this extra field.
718 function getExtraFieldElements($id) {
723 if (!isset($this->extra_field[$id])) {
724 $this->extra_field[$id] = array();
725 $res = db_query_params ('SELECT element_id,element_name,status_id
726 FROM artifact_extra_field_elements
727 WHERE extra_field_id = $1
728 ORDER BY element_pos ASC, element_id ASC',
731 while($arr =& db_fetch_array($res)) {
732 $this->extra_field[$id][$i++] = $arr;
734 // if (count($this->extra_field[$id]) == 0) {
739 return $this->extra_field[$id];
743 * getElementName - get the name of a particular element.
745 * @return string The name.
747 function getElementName($choiceid) {
751 if (is_array($choiceid)) {
752 $choiceid=implode(',', array_map('intval', $choiceid));
754 $choiceid=intval($choiceid);
756 if ($choiceid == 100) {
759 if (!isset($this->element_name["$choiceid"])) {
760 $res = db_query_params ('SELECT element_id,extra_field_id,element_name
761 FROM artifact_extra_field_elements
762 WHERE element_id = ANY ($1)',
763 array (db_int_array_to_any_clause (explode (',', $choiceid)))) ;
764 if (db_numrows($res) > 1) {
765 $arr=util_result_column_to_array($res,2);
766 $this->element_name["$choiceid"]=implode(',',$arr);
768 $this->element_name["$choiceid"]=db_result($res,0,'element_name');
771 return $this->element_name["$choiceid"];
775 * getElementStatusID - get the status of a particular element.
777 * @return int The status
779 function getElementStatusID($choiceid) {
783 if (is_array($choiceid)) {
784 $choiceid=implode(',',$choiceid);
786 if ($choiceid == 100) {
789 if (!$this->element_status["$choiceid"]) {
790 $res = db_query_params ('SELECT element_id,extra_field_id,status_id
791 FROM artifact_extra_field_elements
792 WHERE element_id = ANY ($1)',
793 array (db_int_array_to_any_clause (explode (',', $choiceid)))) ;
794 if (db_numrows($res) > 1) {
795 $arr=util_result_column_to_array($res,2);
796 $this->element_status["$choiceid"]=implode(',',$arr);
798 $this->element_status["$choiceid"]=db_result($res,0,'status_id');
801 return $this->element_status["$choiceid"];
806 * delete - delete this tracker and all its related data.
808 * @param bool I'm Sure.
809 * @param bool I'm REALLY sure.
810 * @return bool true/false;
812 function delete($sure, $really_sure) {
813 if (!$sure || !$really_sure) {
814 $this->setMissingParamsError();
817 if (!$this->userIsAdmin()) {
818 $this->setPermissionDeniedError();
822 db_query_params ('DELETE FROM artifact_extra_field_data
823 WHERE EXISTS (SELECT artifact_id FROM artifact
824 WHERE group_artifact_id=$1
825 AND artifact.artifact_id=artifact_extra_field_data.artifact_id)',
826 array ($this->getID())) ;
827 //echo '0.1'.db_error();
828 db_query_params ('DELETE FROM artifact_extra_field_elements
829 WHERE EXISTS (SELECT extra_field_id FROM artifact_extra_field_list
830 WHERE group_artifact_id=$1
831 AND artifact_extra_field_list.extra_field_id = artifact_extra_field_elements.extra_field_id)',
832 array ($this->getID())) ;
833 //echo '0.2'.db_error();
834 db_query_params ('DELETE FROM artifact_extra_field_list
835 WHERE group_artifact_id=$1',
836 array ($this->getID())) ;
837 //echo '0.3'.db_error();
838 db_query_params ('DELETE FROM artifact_canned_responses
839 WHERE group_artifact_id=$1',
840 array ($this->getID())) ;
841 //echo '1'.db_error();
842 db_query_params ('DELETE FROM artifact_counts_agg
843 WHERE group_artifact_id=$1',
844 array ($this->getID())) ;
845 //echo '5'.db_error();
846 db_query_params ('DELETE FROM artifact_file
847 WHERE EXISTS (SELECT artifact_id FROM artifact
848 WHERE group_artifact_id=$1
849 AND artifact.artifact_id=artifact_file.artifact_id)',
850 array ($this->getID())) ;
851 //echo '6'.db_error();
852 db_query_params ('DELETE FROM artifact_message
853 WHERE EXISTS (SELECT artifact_id FROM artifact
854 WHERE group_artifact_id=$1
855 AND artifact.artifact_id=artifact_message.artifact_id)',
856 array ($this->getID())) ;
857 //echo '7'.db_error();
858 db_query_params ('DELETE FROM artifact_history
859 WHERE EXISTS (SELECT artifact_id FROM artifact
860 WHERE group_artifact_id=$1
861 AND artifact.artifact_id=artifact_history.artifact_id)',
862 array ($this->getID())) ;
863 //echo '8'.db_error();
864 db_query_params ('DELETE FROM artifact_monitor
865 WHERE EXISTS (SELECT artifact_id FROM artifact
866 WHERE group_artifact_id=$1
867 AND artifact.artifact_id=artifact_monitor.artifact_id)',
868 array ($this->getID())) ;
869 //echo '9'.db_error();
870 db_query_params ('DELETE FROM artifact
871 WHERE group_artifact_id=$1',
872 array ($this->getID())) ;
873 //echo '4'.db_error();
874 db_query_params ('DELETE FROM role_setting WHERE ref_id=$1 AND section_name=$2 AND role_id IN (SELECT role_id FROM role WHERE group_id=$3)',
875 array ($this->getID(),
877 $this->Group->getID())) ;
878 db_query_params ('DELETE FROM artifact_group_list
879 WHERE group_artifact_id=$1',
880 array ($this->getID())) ;
881 //echo '11'.db_error();
885 $this->Group->normalizeAllRoles () ;
891 * getTechnicians - returns a result set of technicians.
893 * @return database result set.
895 function getTechnicians() {
896 if (!isset($this->technicians_res)) {
897 $this->technicians_res = db_query_params ('SELECT user_id,realname
898 FROM artifactperm_user_vw
899 WHERE group_artifact_id=$1
900 AND perm_level in (1,2)
902 array ($this->getID())) ;
904 return $this->technicians_res;
908 * getTechnicianObjects - Array of User objects set up for this artifact type.
910 * @return array Of User objects.
912 function &getTechnicianObjects() {
913 $res = $this->getTechnicians();
914 $arr =& util_result_column_to_array($res,0);
915 return user_get_objects($arr);
919 * getCannedResponses - returns a result set of canned responses.
921 * @return database result set.
923 function getCannedResponses() {
924 if (!isset($this->cannedresponses_res)) {
925 $this->cannedresponses_res = db_query_params ('SELECT id,title
926 FROM artifact_canned_responses
927 WHERE group_artifact_id=$1',
928 array ($this->getID()));
930 return $this->cannedresponses_res;
934 * getStatuses - returns a result set of statuses.
936 * These statuses are either the default open/closed or any number of
937 * custom statuses that are stored in the extra fields. On insert/update
938 * to an artifact the status_id is remapped from the extra_field_element_id to
939 * the standard open/closed id.
941 * @param boolean Whether to show the real statuses or not.
942 * @return database result set.
944 function getStatuses() {
945 if (!isset($this->status_res)) {
946 $this->status_res = db_query_params ('SELECT * FROM artifact_status',array());
948 return $this->status_res;
952 * getStatusName - returns the name of this status.
954 * @param int The status ID.
955 * @return string name.
957 function getStatusName($id) {
958 $result = db_query_params ('select status_name from artifact_status WHERE id=$1',
960 if ($result && db_numrows($result) > 0) {
961 return db_result($result,0,'status_name');
963 return 'Error - Not Found';
969 USER PERMISSION FUNCTIONS
974 * userCanView - determine if the user can view this artifact type.
976 * @return boolean user_can_view.
978 function userCanView() {
979 if ($this->isPublic()) {
982 if (!session_loggedin()) {
986 // You must have a role in the project if this tracker is not public
988 $perm = $this->getCurrentUserPerm();
989 if ($this->userIsAdmin() || (strlen($perm) && $perm >= 0)) {
999 * userIsAdmin - see if the logged-in user's perms are >= 2 or Group ArtifactAdmin.
1001 * @return boolean user_is_admin.
1003 function userIsAdmin() {
1004 if (!session_loggedin()) {
1007 $perm =& $this->Group->getPermission( session_get_user() );
1009 if (($this->getCurrentUserPerm() >= 2) || ($perm->isArtifactAdmin())) {
1018 * userIsTechnician - see if the logged-in user's perms are >= 1 or Group ArtifactAdmin.
1020 * @return boolean user_is_technician.
1022 function userIsTechnician() {
1023 if (!session_loggedin()) {
1026 $perm =& $this->Group->getPermission( session_get_user() );
1028 if (($this->getCurrentUserPerm() >= 1) || ($perm->isArtifactAdmin())) {
1037 * getCurrentUserPerm - get the logged-in user's perms from his role
1039 * @return int perm level for the logged-in user.
1041 function getCurrentUserPerm() {
1042 if (!session_loggedin()) {
1045 if (!isset($this->current_user_perm)) {
1046 $this->current_user_perm=db_result(db_query_params ('SELECT role_setting.value::integer
1047 FROM role_setting, user_group
1048 WHERE role_setting.ref_id=$1
1049 AND user_group.role_id=role_setting.role_id
1050 AND user_group.user_id=$2
1051 AND role_setting.section_name=$3',
1052 array ($this->getID(),
1056 return $this->current_user_perm;
1061 * update - use this to update this ArtifactType in the database.
1063 * @param string The item name.
1064 * @param string The item description.
1065 * @param bool (1) true (0) false - whether to email on all updates.
1066 * @param string The address to send new entries and updates to.
1067 * @param int Days before this item is considered overdue.
1068 * @param int Days before stale items time out.
1069 * @param bool (1) true (0) false - whether the resolution box should be shown.
1070 * @param string Free-form string that project admins can place on the submit page.
1071 * @param string Free-form string that project admins can place on the browse page.
1072 * @return true on success, false on failure.
1074 function update($name,$description,$email_all,$email_address,
1075 $due_period, $status_timeout,$use_resolution,$submit_instructions,$browse_instructions) {
1077 if (!$this->userIsAdmin()) {
1078 $this->setPermissionDeniedError();
1082 if ($this->getDataType()) {
1083 $name=$this->getName();
1084 $description=$this->getDescription();
1087 if (!$name || !$description || !$due_period || !$status_timeout) {
1088 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
1092 if ($email_address) {
1093 $invalid_emails = validate_emails($email_address);
1094 if (count($invalid_emails) > 0) {
1095 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
1100 $email_all = ((!$email_all) ? 0 : $email_all);
1101 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
1103 $res = db_query_params ('UPDATE artifact_group_list SET
1106 email_all_updates=$3,
1110 submit_instructions=$7,
1111 browse_instructions=$8
1112 WHERE group_artifact_id=$9 AND group_id=$10',
1114 htmlspecialchars($name),
1115 htmlspecialchars($description),
1118 $due_period * (60*60*24),
1119 $status_timeout * (60*60*24),
1120 htmlspecialchars($submit_instructions),
1121 htmlspecialchars($browse_instructions),
1123 $this->Group->getID())) ;
1125 if (!$res || db_affected_rows($res) < 1) {
1126 $this->setError('ArtifactType::Update(): '.db_error());
1129 $this->fetchData($this->getID());
1135 * getBrowseList - get the free-form string strings.
1137 * @return string instructions.
1139 function getBrowseList() {
1140 $list = $this->data_array['browse_list'];
1142 // remove status_id in the browse list if a custom status exists
1143 if (count($this->getExtraFields(ARTIFACT_EXTRAFIELDTYPE_STATUS)) > 0) {
1144 $arr = explode(',', $list);
1145 $idx = array_search('status_id', $arr);
1146 if($idx !== False) {
1147 array_splice($arr, $idx, 1);
1149 return join(',', $arr);
1156 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
1157 * @param int The extra field id.
1158 * @return boolean success.
1160 function setBrowseList($list) {
1161 $res=db_query_params ('UPDATE artifact_group_list
1163 WHERE group_artifact_id=$2',
1166 $this->fetchData($this->getID());
1174 // c-file-style: "bsd"