3 * ArtifactType.class.php - Class to artifact an type
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
11 * This file is part of GForge.
13 * GForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * GForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 require_once $gfcommon.'include/Error.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("SELECT * FROM artifact_group_list_vw
43 WHERE group_artifact_id='$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 class ArtifactType extends Error {
63 var $Group; //group object
66 * extra_fields 3d array - the IDs and Names of the extra fields
68 * @var array extra_fields;
70 var $extra_fields = array();
73 * extra_field[extra_field_id] array - the IDs and Names of elements on the extra fields
75 * @var array extra_field
80 * Options db resource ID.
82 * @var int $options_res.
87 * Choice name db resource ID.
89 * @var int $choice_name_res.
94 * Current user permissions.
96 * @var int $current_user_perm.
98 var $current_user_perm;
101 * Technicians db resource ID.
103 * @var int $technicians_res.
105 var $technicians_res;
108 * Status db resource ID.
110 * @var int $status_res.
115 * Canned responses resource ID.
117 * @var int $cannecresponses_res.
119 var $cannedresponses_res;
122 * Array of artifact data.
124 * @var array $data_array.
129 * Array of element names so they only have to be fetched once from db.
131 * @var array $data_array.
136 * Array of element status so they only have to be fetched once from db.
138 * @var array $data_array.
143 * ArtifactType - constructor.
145 * @param object The Group object.
146 * @param int The id # assigned to this artifact type in the db.
147 * @param array The associative array of data.
148 * @return boolean success.
150 function ArtifactType(&$Group,$artifact_type_id=false, $arr=false) {
152 if (!$Group || !is_object($Group)) {
153 $this->setError('No Valid Group Object');
156 if ($Group->isError()) {
157 $this->setError('ArtifactType: '.$Group->getErrorMessage());
160 $this->Group =& $Group;
161 if ($artifact_type_id) {
162 if (!$arr || !is_array($arr)) {
163 if (!$this->fetchData($artifact_type_id)) {
167 $this->data_array =& $arr;
168 if ($this->data_array['group_id'] != $this->Group->getID()) {
169 $this->setError('Group_id in db result does not match Group Object');
170 $this->data_array = null;
175 // Make sure they can even access this object
177 if (!$this->userCanView()) {
178 $this->setPermissionDeniedError();
179 $this->data_array = null;
186 * create - use this to create a new ArtifactType in the database.
188 * @param string The type name.
189 * @param string The type description.
190 * @param bool (1) true (0) false - viewable by general public.
191 * @param bool (1) true (0) false - whether non-logged-in users can submit.
192 * @param bool (1) true (0) false - whether to email on all updates.
193 * @param string The address to send new entries and updates to.
194 * @param int Days before this item is considered overdue.
195 * @param bool (1) trye (0) false - whether the resolution box should be shown.
196 * @param string Free-form string that project admins can place on the submit page.
197 * @param string Free-form string that project admins can place on the browse page.
198 * @param int (1) bug tracker, (2) Support Tracker, (3) Patch Tracker, (4) features (0) other.
199 * @return id on success, false on failure.
201 function create($name,$description,$is_public,$allow_anon,$email_all,$email_address,
202 $due_period,$use_resolution,$submit_instructions,$browse_instructions,$datatype=0) {
204 $perm =& $this->Group->getPermission( session_get_user() );
206 if (!$perm || !is_object($perm) || !$perm->isArtifactAdmin()) {
207 $this->setPermissionDeniedError();
211 if (!$name || !$description || !$due_period) {
212 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
216 if ($email_address) {
217 $invalid_emails = validate_emails($email_address);
218 if (count($invalid_emails) > 0) {
219 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
224 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
225 $is_public = ((!$is_public) ? 0 : $is_public);
226 $allow_anon = ((!$allow_anon) ? 0 : $allow_anon);
227 $email_all = ((!$email_all) ? 0 : $email_all);
245 ('". $this->Group->getID() ."',
246 '". htmlspecialchars($name) ."',
247 '". htmlspecialchars($description) ."',
252 '". ($due_period*(60*60*24)) ."',
254 '".htmlspecialchars($submit_instructions)."',
255 '".htmlspecialchars($browse_instructions)."',
260 $res = db_query($sql);
262 $id = db_insertid($res,'artifact_group_list','group_artifact_id');
265 $this->setError('ArtifactType: '.db_error());
269 if (!$this->fetchData($id)) {
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("SELECT * FROM artifact_group_list_vw
287 WHERE group_artifact_id='$artifact_type_id'
288 AND group_id='". $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() {
423 global $sys_default_domain,$sys_use_gateways;
425 if($sys_use_gateways) {
426 $address .= strtolower($this->getUnixName());
428 $address .= 'noreply';
430 $address .= '@'.$sys_default_domain;
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("UPDATE artifact_group_list SET custom_status_field='$extra_field_id'
477 WHERE group_artifact_id='".$this->getID()."'");
482 * usesCustomStatuses - boolean
484 * @return boolean use_custom_statues.
486 function usesCustomStatuses() {
487 return $this->getCustomStatusField();
491 * remap status - pass the extra_fields array and return the status_id, either open/closed
492 * @param int The status_id
493 * @param array Complex array of extra_field_data
494 * @return int status_id.
496 function remapStatus($status_id,$extra_fields) {
497 if ($this->usesCustomStatuses()) {
498 //get the selected element for the extra_field_status element
499 $csfield = $this->getCustomStatusField();
500 if (array_key_exists($csfield, $extra_fields)) {
501 $element_id=$extra_fields[$csfield];
503 //convert that element_id into the status_id
504 $res=db_query("SELECT status_id FROM artifact_extra_field_elements WHERE element_id='$element_id'");
506 $this->setError('Error Remapping Status: '.db_error());
509 $status_id=db_result($res,0,'status_id');
511 // custom status was not passed... use the first status from the database
512 $res = db_query("SELECT status_id FROM artifact_extra_field_elements WHERE extra_field_id='".$csfield."' ORDER BY element_id ASC LIMIT 1 OFFSET 0");
513 if (db_numrows($res) == 0) { // No values available
514 $this->setError('Error Remapping Status');
517 $status_id=db_result($res,0,'status_id');
520 if ($status_id < 1 || $status_id > 4) {
521 echo "INVALID STATUS REMAP: $status_id FROM SELECTED ELEMENT: $element_id";
531 * getDataType - flag that is generally unused but can mark the difference between bugs, patches, etc.
533 * @return int The type (1) bug (2) support (3) patch (4) feature (0) other.
535 function getDataType() {
536 return $this->data_array['datatype'];
540 * setMonitor - user can monitor this artifact.
542 * @return false - always false - always use the getErrorMessage() for feedback
544 function setMonitor() {
545 if (session_loggedin()) {
547 $user_id=user_getid();
548 $user =& user_get_object(user_getid());
552 $this->setError(_('SetMonitor::Valid Email Address Required'));
557 $res=db_query("SELECT * FROM artifact_type_monitor
558 WHERE group_artifact_id='". $this->getID() ."'
559 AND user_id='$user_id'");
561 if (!$res || db_numrows($res) < 1) {
563 $res=db_query("INSERT INTO artifact_type_monitor (group_artifact_id,user_id)
564 VALUES ('". $this->getID() ."','$user_id')");
566 $this->setError(db_error());
569 $this->setError(_('Now Monitoring Tracker'));
573 //already monitoring - remove their monitor
574 db_query("DELETE FROM artifact_type_monitor
575 WHERE group_artifact_id='". $this->getID() ."'
576 AND user_id='$user_id'");
577 $this->setError(_('Tracker Monitoring Deactivated'));
582 function isMonitoring() {
583 if (!session_loggedin()) {
586 $sql="SELECT count(*) AS count FROM artifact_type_monitor
587 WHERE user_id='".user_getid()."' AND group_artifact_id='".$this->getID()."';";
588 $result = db_query($sql);
589 $row_count = db_fetch_array($result);
590 return $result && $row_count['count'] > 0;
594 * getMonitorIds - array of email addresses monitoring this Artifact.
596 * @return array of email addresses monitoring this Artifact.
598 function &getMonitorIds() {
599 $res=db_query("SELECT user_id
600 FROM artifact_type_monitor
601 WHERE group_artifact_id='". $this->getID() ."'");
602 return util_result_column_to_array($res);
606 * getExtraFields - List of possible user built extra fields
607 * set up for this artifact type.
609 * @return arrays of data;
611 function getExtraFields($filter='') {
612 if (!isset($this->extra_fields["$filter"])) {
613 $this->extra_fields["$filter"] = array();
615 $filter_str=" AND field_type IN ($filter) ";
620 FROM artifact_extra_field_list
621 WHERE group_artifact_id='".$this->getID() ."'
623 ORDER BY field_type ASC";
625 while($arr = db_fetch_array($res)) {
626 $this->extra_fields["$filter"][$arr['extra_field_id']] = $arr;
630 return $this->extra_fields["$filter"];
634 * cloneFieldsFrom - clone all the fields and elements from another tracker
636 * @return boolean true/false on success
638 function cloneFieldsFrom($clone_tracker_id) {
639 global $sys_template_group;
640 $g =& group_get_object($sys_template_group);
641 if (!$g || !is_object($g)) {
642 $this->setError('Could Not Get Template Group');
644 } elseif ($g->isError()) {
645 $this->setError('Template Group Error '.$g->getErrorMessage());
648 $at =& new ArtifactType($g,$clone_tracker_id);
649 if (!$at || !is_object($at)) {
650 $this->setError('Could Not Get Tracker To Clone');
652 } elseif ($at->isError()) {
653 $this->setError('Clone Tracker Error '.$at->getErrorMessage());
656 $efs =& $at->getExtraFields();
660 // Iterate list of extra fields
663 foreach ($efs as $ef) {
664 //new field in this tracker
665 $nef = new ArtifactExtraField($this);
666 if (!$nef->create( addslashes(util_unconvert_htmlspecialchars($ef['field_name'])), $ef['field_type'], $ef['attribute1'], $ef['attribute2'], $ef['is_required'], $ef['alias'])) {
668 $this->setError('Error Creating New Extra Field: '.$nef->getErrorMessage());
672 // Iterate the elements
674 $resel=db_query("SELECT * FROM artifact_extra_field_elements WHERE extra_field_id='".$ef['extra_field_id']."'");
675 while ($el =& db_fetch_array($resel)) {
677 $nel = new ArtifactExtraFieldElement($nef);
678 if (!$nel->create( addslashes(util_unconvert_htmlspecialchars($el['element_name'])), $el['status_id'] )) {
680 $this->setError('Error Creating New Extra Field Element: '.$nel->getErrorMessage());
691 * getExtraFieldName - Get a box name using the box ID
693 * @param int id of an extra field.
694 * @return string name of extra field.
696 function getExtraFieldName($extra_field_id) {
697 $arr = $this->getExtraFields();
698 return $arr[$extra_field_id]['field_name'];
702 * getExtraFieldElements - List of possible admin configured
703 * extra field elements. This function is used to
704 * present the boxes and choices on the main Add/Update page.
706 * @param int id of the extra field
707 * @return array of elements for this extra field.
709 function getExtraFieldElements($id) {
714 if (!isset($this->extra_field[$id])) {
715 $this->extra_field[$id] = array();
716 $sql="select element_id,element_name,status_id
717 FROM artifact_extra_field_elements
718 WHERE extra_field_id ='".$id."'
719 ORDER BY element_id ASC";
723 while($arr =& db_fetch_array($res)) {
724 $this->extra_field[$id][$i++] = $arr;
726 // if (count($this->extra_field[$id]) == 0) {
731 return $this->extra_field[$id];
735 * getElementName - get the name of a particular element.
737 * @return string The name.
739 function getElementName($choiceid) {
743 if (is_array($choiceid)) {
744 $choiceid=implode(',',$choiceid);
746 if ($choiceid == 100) {
749 if (!$this->element_name["$choiceid"]) {
750 $sql="select element_id,extra_field_id,element_name
751 FROM artifact_extra_field_elements
752 WHERE element_id IN ($choiceid)";
754 if (db_numrows($res) > 1) {
755 $arr=util_result_column_to_array($res,2);
756 $this->element_name["$choiceid"]=implode(',',$arr);
758 $this->element_name["$choiceid"]=db_result($res,0,'element_name');
761 return $this->element_name["$choiceid"];
765 * getElementStatusID - get the status of a particular element.
767 * @return int The status
769 function getElementStatusID($choiceid) {
773 if (is_array($choiceid)) {
774 $choiceid=implode(',',$choiceid);
776 if ($choiceid == 100) {
779 if (!$this->element_status["$choiceid"]) {
780 $sql="select element_id,extra_field_id,status_id
781 FROM artifact_extra_field_elements
782 WHERE element_id IN ($choiceid)";
784 if (db_numrows($res) > 1) {
785 $arr=util_result_column_to_array($res,2);
786 $this->element_status["$choiceid"]=implode(',',$arr);
788 $this->element_status["$choiceid"]=db_result($res,0,'status_id');
791 return $this->element_status["$choiceid"];
796 * delete - delete this tracker and all its related data.
798 * @param bool I'm Sure.
799 * @param bool I'm REALLY sure.
800 * @return bool true/false;
802 function delete($sure, $really_sure) {
803 if (!$sure || !$really_sure) {
804 $this->setMissingParamsError();
807 if (!$this->userIsAdmin()) {
808 $this->setPermissionDeniedError();
812 db_query("DELETE FROM artifact_extra_field_data
813 WHERE EXISTS (SELECT artifact_id FROM artifact
814 WHERE group_artifact_id='".$this->getID()."'
815 AND artifact.artifact_id=artifact_extra_field_data.artifact_id)");
816 //echo '0.1'.db_error();
817 db_query("DELETE FROM artifact_extra_field_elements
818 WHERE EXISTS (SELECT extra_field_id FROM artifact_extra_field_list
819 WHERE group_artifact_id='".$this->getID()."'
820 AND artifact_extra_field_list.extra_field_id = artifact_extra_field_elements.extra_field_id)");
821 //echo '0.2'.db_error();
822 db_query ("DELETE FROM artifact_extra_field_list
823 WHERE group_artifact_id='".$this->getID()."'");
824 //echo '0.3'.db_error();
825 db_query("DELETE FROM artifact_canned_responses
826 WHERE group_artifact_id='".$this->getID()."'");
827 //echo '1'.db_error();
828 db_query("DELETE FROM artifact_counts_agg
829 WHERE group_artifact_id='".$this->getID()."'");
830 //echo '5'.db_error();
831 db_query("DELETE FROM artifact_file
832 WHERE EXISTS (SELECT artifact_id FROM artifact
833 WHERE group_artifact_id='".$this->getID()."'
834 AND artifact.artifact_id=artifact_file.artifact_id)");
835 //echo '6'.db_error();
836 db_query("DELETE FROM artifact_message
837 WHERE EXISTS (SELECT artifact_id FROM artifact
838 WHERE group_artifact_id='".$this->getID()."'
839 AND artifact.artifact_id=artifact_message.artifact_id)");
840 //echo '7'.db_error();
841 db_query("DELETE FROM artifact_history
842 WHERE EXISTS (SELECT artifact_id FROM artifact
843 WHERE group_artifact_id='".$this->getID()."'
844 AND artifact.artifact_id=artifact_history.artifact_id)");
845 //echo '8'.db_error();
846 db_query("DELETE FROM artifact_monitor
847 WHERE EXISTS (SELECT artifact_id FROM artifact
848 WHERE group_artifact_id='".$this->getID()."'
849 AND artifact.artifact_id=artifact_monitor.artifact_id)");
850 //echo '9'.db_error();
851 db_query("DELETE FROM artifact
852 WHERE group_artifact_id='".$this->getID()."'");
853 //echo '4'.db_error();
854 db_query("DELETE FROM artifact_group_list
855 WHERE group_artifact_id='".$this->getID()."'");
856 //echo '11'.db_error();
863 * getTechnicians - returns a result set of technicians.
865 * @return database result set.
867 function getTechnicians() {
868 if (!isset($this->technicians_res)) {
869 $sql="SELECT user_id,realname
870 FROM artifactperm_user_vw
871 WHERE group_artifact_id='". $this->getID() ."'
872 AND perm_level in (1,2)
874 $this->technicians_res = db_query($sql);
876 return $this->technicians_res;
880 * getTechnicianObjects - Array of User objects set up for this artifact type.
882 * @return array Of User objects.
884 function &getTechnicianObjects() {
885 $res = $this->getTechnicians();
886 $arr =& util_result_column_to_array($res,0);
887 return user_get_objects($arr);
891 * getCannedResponses - returns a result set of canned responses.
893 * @return database result set.
895 function getCannedResponses() {
896 if (!isset($this->cannedresponses_res)) {
897 $sql="SELECT id,title
898 FROM artifact_canned_responses
899 WHERE group_artifact_id='". $this->getID() ."'";
900 $this->cannedresponses_res = db_query($sql);
902 return $this->cannedresponses_res;
906 * getStatuses - returns a result set of statuses.
908 * These statuses are either the default open/closed or any number of
909 * custom statuses that are stored in the extra fields. On insert/update
910 * to an artifact the status_id is remapped from the extra_field_element_id to
911 * the standard open/closed id.
913 * @param boolean Whether to show the real statuses or not.
914 * @return database result set.
916 function getStatuses() {
917 if (!isset($this->status_res)) {
918 $sql="select * from artifact_status";
919 $this->status_res=db_query($sql);
921 return $this->status_res;
925 * getStatusName - returns the name of this status.
927 * @param int The status ID.
928 * @return string name.
930 function getStatusName($id) {
931 $sql="select status_name from artifact_status WHERE id='$id'";
932 $result=db_query($sql);
933 if ($result && db_numrows($result) > 0) {
934 return db_result($result,0,'status_name');
936 return 'Error - Not Found';
942 USER PERMISSION FUNCTIONS
947 * userCanView - determine if the user can view this artifact type.
949 * @return boolean user_can_view.
951 function userCanView() {
952 if ($this->isPublic()) {
955 if (!session_loggedin()) {
959 // You must have a role in the project if this tracker is not public
961 if ($this->userIsAdmin() || $this->getCurrentUserPerm() >= 0) {
971 * userIsAdmin - see if the logged-in user's perms are >= 2 or Group ArtifactAdmin.
973 * @return boolean user_is_admin.
975 function userIsAdmin() {
976 if (!session_loggedin()) {
979 $perm =& $this->Group->getPermission( session_get_user() );
981 if (($this->getCurrentUserPerm() >= 2) || ($perm->isArtifactAdmin())) {
990 * userIsTechnician - see if the logged-in user's perms are >= 1 or Group ArtifactAdmin.
992 * @return boolean user_is_technician.
994 function userIsTechnician() {
995 if (!session_loggedin()) {
998 $perm =& $this->Group->getPermission( session_get_user() );
1000 if (($this->getCurrentUserPerm() >= 1) || ($perm->isArtifactAdmin())) {
1009 * getCurrentUserPerm - get the logged-in user's perms from his role
1011 * @return int perm level for the logged-in user.
1013 function getCurrentUserPerm() {
1014 if (!session_loggedin()) {
1017 if (!isset($this->current_user_perm)) {
1018 $sql="SELECT role_setting.value
1019 FROM role_setting, user_group
1020 WHERE role_setting.ref_id='". $this->getID() ."'
1021 AND user_group.role_id = role_setting.role_id
1022 AND user_group.user_id='".user_getid()."'
1023 AND role_setting.section_name='tracker'";
1024 $this->current_user_perm=db_result(db_query($sql),0,0);
1026 return $this->current_user_perm;
1031 * update - use this to update this ArtifactType in the database.
1033 * @param string The item name.
1034 * @param string The item description.
1035 * @param bool (1) true (0) false - whether to email on all updates.
1036 * @param string The address to send new entries and updates to.
1037 * @param int Days before this item is considered overdue.
1038 * @param int Days before stale items time out.
1039 * @param bool (1) true (0) false - whether the resolution box should be shown.
1040 * @param string Free-form string that project admins can place on the submit page.
1041 * @param string Free-form string that project admins can place on the browse page.
1042 * @return true on success, false on failure.
1044 function update($name,$description,$email_all,$email_address,
1045 $due_period, $status_timeout,$use_resolution,$submit_instructions,$browse_instructions) {
1047 if (!$this->userIsAdmin()) {
1048 $this->setPermissionDeniedError();
1052 if ($this->getDataType()) {
1053 $name=$this->getName();
1054 $description=$this->getDescription();
1057 if (!$name || !$description || !$due_period || !$status_timeout) {
1058 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
1062 if ($email_address) {
1063 $invalid_emails = validate_emails($email_address);
1064 if (count($invalid_emails) > 0) {
1065 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
1070 $email_all = ((!$email_all) ? 0 : $email_all);
1071 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
1073 $sql="UPDATE artifact_group_list SET
1074 name='". htmlspecialchars($name). "',
1075 description='". htmlspecialchars($description) ."',
1076 email_all_updates='$email_all',
1077 email_address='$email_address',
1078 due_period='". ($due_period * (60*60*24)) ."',
1079 status_timeout='". ($status_timeout * (60*60*24)) . "',
1080 submit_instructions='". htmlspecialchars($submit_instructions)."',
1081 browse_instructions='" .htmlspecialchars($browse_instructions)."'
1083 group_artifact_id='". $this->getID() ."'
1084 AND group_id='". $this->Group->getID() ."'";
1086 $res=db_query($sql);
1087 if (!$res || db_affected_rows($res) < 1) {
1088 $this->setError('ArtifactType::Update(): '.db_error());
1091 $this->fetchData($this->getID());
1100 // c-file-style: "bsd"