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('common/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) {
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);
246 ('". $this->Group->getID() ."',
247 '". htmlspecialchars($name) ."',
248 '". htmlspecialchars($description) ."',
253 '". ($due_period*(60*60*24)) ."',
255 '".htmlspecialchars($submit_instructions)."',
256 '".htmlspecialchars($browse_instructions)."',
261 $res = db_query($sql);
263 $id = db_insertid($res,'artifact_group_list','group_artifact_id');
266 $this->setError('ArtifactType: '.db_error());
270 if (!$this->fetchData($id)) {
274 if (!$this->addAllUsers()) {
286 * fetchData - re-fetch the data for this ArtifactType from the database.
288 * @param int The artifact type ID.
289 * @return boolean success.
291 function fetchData($artifact_type_id) {
292 $res=db_query("SELECT * FROM artifact_group_list_vw
293 WHERE group_artifact_id='$artifact_type_id'
294 AND group_id='". $this->Group->getID() ."'");
295 if (!$res || db_numrows($res) < 1) {
296 $this->setError('ArtifactType: Invalid ArtifactTypeID');
299 $this->data_array =& db_fetch_array($res);
300 db_free_result($res);
305 * getGroup - get the Group object this ArtifactType is associated with.
307 * @return Object The Group object.
309 function &getGroup() {
314 * getID - get this ArtifactTypeID.
316 * @return int The group_artifact_id #.
319 return $this->data_array['group_artifact_id'];
323 * getOpenCount - get the count of open tracker items in this tracker type.
325 * @return int The count.
327 function getOpenCount() {
328 return $this->data_array['open_count'];
332 * getTotalCount - get the total number of tracker items in this tracker type.
334 * @return int The total count.
336 function getTotalCount() {
337 return $this->data_array['count'];
341 * allowsAnon - determine if non-logged-in users can post.
343 * @return boolean allow_anonymous_submissions.
345 function allowsAnon() {
346 return $this->data_array['allow_anon'];
350 * getSubmitInstructions - get the free-form string strings.
352 * @return string instructions.
354 function getSubmitInstructions() {
355 return $this->data_array['submit_instructions'];
359 * getBrowseInstructions - get the free-form string strings.
361 * @return string instructions.
363 function getBrowseInstructions() {
364 return $this->data_array['browse_instructions'];
368 * emailAll - determine if we're supposed to email on every event.
370 * @return boolean email_all.
372 function emailAll() {
373 return $this->data_array['email_all_updates'];
377 * emailAddress - defined email address to send events to.
379 * @return string email.
381 function getEmailAddress() {
382 return $this->data_array['email_address'];
386 * isPublic - whether non-group-members can view.
388 * @return boolean is_public.
390 function isPublic() {
391 return $this->data_array['is_public'];
395 * getName - the name of this ArtifactType.
397 * @return string name.
400 return $this->data_array['name'];
404 * getFormattedName - formatted name of this ArtifactType
406 * @return string formatted name
408 function getFormattedName() {
409 $name = preg_replace('/[^[:alnum:]]/','',$this->getName());
410 $name = strtolower($name);
415 * getUnixName - returns the name used by email gateway
417 * @return string unix name
419 function getUnixName() {
420 return strtolower($this->Group->getUnixName()).'-'.$this->getFormattedName();
424 * getReturnEmailAddress() - return the return email address for notification emails
426 * @return string return email address
428 function getReturnEmailAddress() {
429 global $sys_default_domain,$sys_use_gateways;
431 if($sys_use_gateways) {
432 $address .= strtolower($this->getUnixName());
434 $address .= 'noreply';
436 $address .= '@'.$sys_default_domain;
441 * getDescription - the description of this ArtifactType.
443 * @return string description.
445 function getDescription() {
446 return $this->data_array['description'];
450 * getDuePeriod - how many seconds until it's considered overdue.
452 * @return int seconds.
454 function getDuePeriod() {
455 return $this->data_array['due_period'];
459 * getStatusTimeout - how many seconds until an item is stale.
461 * @return int seconds.
463 function getStatusTimeout() {
464 return $this->data_array['status_timeout'];
468 * getCustomStatusField - return the extra_field_id of the field containing the custom status.
470 * @return int extra_field_id.
472 function getCustomStatusField() {
473 return $this->data_array['custom_status_field'];
477 * setCustomStatusField - set the extra_field_id of the field containing the custom status.
478 * @param int The extra field id.
479 * @return boolean success.
481 function setCustomStatusField($extra_field_id) {
482 $res=db_query("UPDATE artifact_group_list SET custom_status_field='$extra_field_id'
483 WHERE group_artifact_id='".$this->getID()."'");
488 * usesCustomStatuses - boolean
490 * @return boolean use_custom_statues.
492 function usesCustomStatuses() {
493 return $this->getCustomStatusField();
497 * remap status - pass the extra_fields array and return the status_id, either open/closed
498 * @param int The status_id
499 * @param array Complex array of extra_field_data
500 * @return int status_id.
502 function remapStatus($status_id,$extra_fields) {
503 if ($this->usesCustomStatuses()) {
504 //get the selected element for the extra_field_status element
505 $csfield = $this->getCustomStatusField();
506 if (array_key_exists($csfield, $extra_fields)) {
507 $element_id=$extra_fields[$csfield];
509 //convert that element_id into the status_id
510 $res=db_query("SELECT status_id FROM artifact_extra_field_elements WHERE element_id='$element_id'");
512 $this->setError('Error Remapping Status: '.db_error());
515 $status_id=db_result($res,0,'status_id');
517 // custom status was not passed... use the first status from the database
518 $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");
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() {
552 if (session_loggedin()) {
554 $user_id=user_getid();
555 $user =& user_get_object(user_getid());
559 $this->setError(_('SetMonitor::Valid Email Address Required'));
564 $res=db_query("SELECT * FROM artifact_type_monitor
565 WHERE group_artifact_id='". $this->getID() ."'
566 AND user_id='$user_id'");
568 if (!$res || db_numrows($res) < 1) {
570 $res=db_query("INSERT INTO artifact_type_monitor (group_artifact_id,user_id)
571 VALUES ('". $this->getID() ."','$user_id')");
573 $this->setError(db_error());
576 $this->setError(_('Now Monitoring Tracker'));
580 //already monitoring - remove their monitor
581 db_query("DELETE FROM artifact_type_monitor
582 WHERE group_artifact_id='". $this->getID() ."'
583 AND user_id='$user_id'");
584 $this->setError(_('Tracker Monitoring Deactivated'));
589 function isMonitoring() {
590 if (!session_loggedin()) {
593 $sql="SELECT count(*) AS count FROM artifact_type_monitor
594 WHERE user_id='".user_getid()."' AND group_artifact_id='".$this->getID()."';";
595 $result = db_query($sql);
596 $row_count = db_fetch_array($result);
597 return $result && $row_count['count'] > 0;
601 * getMonitorIds - array of email addresses monitoring this Artifact.
603 * @return array of email addresses monitoring this Artifact.
605 function &getMonitorIds() {
606 $res=db_query("SELECT user_id
607 FROM artifact_type_monitor
608 WHERE group_artifact_id='". $this->getID() ."'");
609 return util_result_column_to_array($res);
613 * getExtraFields - List of possible user built extra fields
614 * set up for this artifact type.
616 * @return arrays of data;
618 function getExtraFields($filter='') {
619 if (!isset($this->extra_fields["$filter"])) {
620 $this->extra_fields["$filter"] = array();
622 $filter_str=" AND field_type IN ($filter) ";
627 FROM artifact_extra_field_list
628 WHERE group_artifact_id='".$this->getID() ."'
630 ORDER BY field_type ASC";
632 while($arr = db_fetch_array($res)) {
633 $this->extra_fields["$filter"][$arr['extra_field_id']] = $arr;
637 return $this->extra_fields["$filter"];
641 * cloneFieldsFrom - clone all the fields and elements from another tracker
643 * @return boolean true/false on success
645 function cloneFieldsFrom($clone_tracker_id) {
646 global $sys_template_group;
647 $g =& group_get_object($sys_template_group);
648 if (!$g || !is_object($g)) {
649 $this->setError('Could Not Get Template Group');
651 } elseif ($g->isError()) {
652 $this->setError('Template Group Error '.$g->getErrorMessage());
655 $at =& new ArtifactType($g,$clone_tracker_id);
656 if (!$at || !is_object($at)) {
657 $this->setError('Could Not Get Tracker To Clone');
659 } elseif ($at->isError()) {
660 $this->setError('Clone Tracker Error '.$at->getErrorMessage());
663 $efs =& $at->getExtraFields();
667 // Iterate list of extra fields
670 foreach ($efs as $ef) {
671 //new field in this tracker
672 $nef = new ArtifactExtraField($this);
673 if (!$nef->create( addslashes(util_unconvert_htmlspecialchars($ef['field_name'])), $ef['field_type'], $ef['attribute1'], $ef['attribute2'], $ef['is_required'], $ef['alias'])) {
675 $this->setError('Error Creating New Extra Field: '.$nef->getErrorMessage());
679 // Iterate the elements
681 $resel=db_query("SELECT * FROM artifact_extra_field_elements WHERE extra_field_id='".$ef['extra_field_id']."'");
682 while ($el =& db_fetch_array($resel)) {
684 $nel = new ArtifactExtraFieldElement($nef);
685 if (!$nel->create( addslashes(util_unconvert_htmlspecialchars($el['element_name'])), $el['status_id'] )) {
687 $this->setError('Error Creating New Extra Field Element: '.$nel->getErrorMessage());
698 * getExtraFieldName - Get a box name using the box ID
700 * @param int id of an extra field.
701 * @return string name of extra field.
703 function getExtraFieldName($extra_field_id) {
704 $arr = $this->getExtraFields();
705 return $arr[$extra_field_id]['field_name'];
709 * getExtraFieldElements - List of possible admin configured
710 * extra field elements. This function is used to
711 * present the boxes and choices on the main Add/Update page.
713 * @param int id of the extra field
714 * @return array of elements for this extra field.
716 function getExtraFieldElements($id) {
721 if (!isset($this->extra_field[$id])) {
722 $this->extra_field[$id] = array();
723 $sql="select element_id,element_name,status_id
724 FROM artifact_extra_field_elements
725 WHERE extra_field_id ='".$id."'
726 ORDER BY element_id ASC";
730 while($arr =& db_fetch_array($res)) {
731 $this->extra_field[$id][$i++] = $arr;
733 // if (count($this->extra_field[$id]) == 0) {
738 return $this->extra_field[$id];
742 * getElementName - get the name of a particular element.
744 * @return string The name.
746 function getElementName($choiceid) {
750 if (is_array($choiceid)) {
751 $choiceid=implode(',',$choiceid);
753 if ($choiceid == 100) {
756 if (!$this->element_name["$choiceid"]) {
757 $sql="select element_id,extra_field_id,element_name
758 FROM artifact_extra_field_elements
759 WHERE element_id IN ($choiceid)";
761 if (db_numrows($res) > 1) {
762 $arr=util_result_column_to_array($res,2);
763 $this->element_name["$choiceid"]=implode(',',$arr);
765 $this->element_name["$choiceid"]=db_result($res,0,'element_name');
768 return $this->element_name["$choiceid"];
772 * getElementStatusID - get the status of a particular element.
774 * @return int The status
776 function getElementStatusID($choiceid) {
780 if (is_array($choiceid)) {
781 $choiceid=implode(',',$choiceid);
783 if ($choiceid == 100) {
786 if (!$this->element_status["$choiceid"]) {
787 $sql="select element_id,extra_field_id,status_id
788 FROM artifact_extra_field_elements
789 WHERE element_id IN ($choiceid)";
791 if (db_numrows($res) > 1) {
792 $arr=util_result_column_to_array($res,2);
793 $this->element_status["$choiceid"]=implode(',',$arr);
795 $this->element_status["$choiceid"]=db_result($res,0,'status_id');
798 return $this->element_status["$choiceid"];
803 * delete - delete this tracker and all its related data.
805 * @param bool I'm Sure.
806 * @param bool I'm REALLY sure.
807 * @return bool true/false;
809 function delete($sure, $really_sure) {
810 if (!$sure || !$really_sure) {
811 $this->setMissingParamsError();
814 if (!$this->userIsAdmin()) {
815 $this->setPermissionDeniedError();
819 db_query("DELETE FROM artifact_extra_field_data
820 WHERE EXISTS (SELECT artifact_id FROM artifact
821 WHERE group_artifact_id='".$this->getID()."'
822 AND artifact.artifact_id=artifact_extra_field_data.artifact_id)");
823 //echo '0.1'.db_error();
824 db_query("DELETE FROM artifact_extra_field_elements
825 WHERE EXISTS (SELECT extra_field_id FROM artifact_extra_field_list
826 WHERE group_artifact_id='".$this->getID()."'
827 AND artifact_extra_field_list.extra_field_id = artifact_extra_field_elements.extra_field_id)");
828 //echo '0.2'.db_error();
829 db_query ("DELETE FROM artifact_extra_field_list
830 WHERE group_artifact_id='".$this->getID()."'");
831 //echo '0.3'.db_error();
832 db_query("DELETE FROM artifact_canned_responses
833 WHERE group_artifact_id='".$this->getID()."'");
834 //echo '1'.db_error();
835 db_query("DELETE FROM artifact_perm
836 WHERE group_artifact_id='".$this->getID()."'");
837 //echo '3'.db_error();
838 db_query("DELETE FROM artifact_counts_agg
839 WHERE group_artifact_id='".$this->getID()."'");
840 //echo '5'.db_error();
841 db_query("DELETE FROM artifact_file
842 WHERE EXISTS (SELECT artifact_id FROM artifact
843 WHERE group_artifact_id='".$this->getID()."'
844 AND artifact.artifact_id=artifact_file.artifact_id)");
845 //echo '6'.db_error();
846 db_query("DELETE FROM artifact_message
847 WHERE EXISTS (SELECT artifact_id FROM artifact
848 WHERE group_artifact_id='".$this->getID()."'
849 AND artifact.artifact_id=artifact_message.artifact_id)");
850 //echo '7'.db_error();
851 db_query("DELETE FROM artifact_history
852 WHERE EXISTS (SELECT artifact_id FROM artifact
853 WHERE group_artifact_id='".$this->getID()."'
854 AND artifact.artifact_id=artifact_history.artifact_id)");
855 //echo '8'.db_error();
856 db_query("DELETE FROM artifact_monitor
857 WHERE EXISTS (SELECT artifact_id FROM artifact
858 WHERE group_artifact_id='".$this->getID()."'
859 AND artifact.artifact_id=artifact_monitor.artifact_id)");
860 //echo '9'.db_error();
861 db_query("DELETE FROM artifact
862 WHERE group_artifact_id='".$this->getID()."'");
863 //echo '4'.db_error();
864 db_query("DELETE FROM artifact_group_list
865 WHERE group_artifact_id='".$this->getID()."'");
866 //echo '11'.db_error();
873 * getTechnicians - returns a result set of technicians.
875 * @return database result set.
877 function getTechnicians() {
878 if (!isset($this->technicians_res)) {
879 $sql="SELECT user_id,realname
880 FROM artifactperm_user_vw
881 WHERE group_artifact_id='". $this->getID() ."'
882 AND perm_level in (1,2)
884 $this->technicians_res = db_query($sql);
886 return $this->technicians_res;
890 * getTechnicianObjects - Array of User objects set up for this artifact type.
892 * @return array Of User objects.
894 function &getTechnicianObjects() {
895 $res = $this->getTechnicians();
896 $arr =& util_result_column_to_array($res,0);
897 return user_get_objects($arr);
901 * getCannedResponses - returns a result set of canned responses.
903 * @return database result set.
905 function getCannedResponses() {
906 if (!isset($this->cannedresponses_res)) {
907 $sql="SELECT id,title
908 FROM artifact_canned_responses
909 WHERE group_artifact_id='". $this->getID() ."'";
910 $this->cannedresponses_res = db_query($sql);
912 return $this->cannedresponses_res;
916 * getStatuses - returns a result set of statuses.
918 * These statuses are either the default open/closed or any number of
919 * custom statuses that are stored in the extra fields. On insert/update
920 * to an artifact the status_id is remapped from the extra_field_element_id to
921 * the standard open/closed id.
923 * @param boolean Whether to show the real statuses or not.
924 * @return database result set.
926 function getStatuses() {
927 if (!isset($this->status_res)) {
928 $sql="select * from artifact_status";
929 $this->status_res=db_query($sql);
931 return $this->status_res;
935 * getStatusName - returns the name of this status.
937 * @param int The status ID.
938 * @return string name.
940 function getStatusName($id) {
941 $sql="select status_name from artifact_status WHERE id='$id'";
942 $result=db_query($sql);
943 if ($result && db_numrows($result) > 0) {
944 return db_result($result,0,'status_name');
946 return 'Error - Not Found';
951 * addAllUsers - add all users to this artifact.
953 * @return boolean success.
955 function addAllUsers() {
956 if (!$this->userIsAdmin()) {
957 $this->setPermissionDeniedError();
960 $sql="INSERT INTO artifact_perm (group_artifact_id,user_id,perm_level)
961 SELECT '".$this->getID()."',user_id,artifact_flags
964 group_id='".$this->Group->getID()."'
965 AND NOT EXISTS (SELECT user_id FROM artifact_perm
966 WHERE group_artifact_id='".$this->getID()."'
967 AND user_id=user_group.user_id);";
968 $res= db_query($sql);
970 $this->setError(db_error());
978 * addUser - add a user to this ArtifactType.
980 * @param int user_id of the new user.
981 * @return boolean success.
983 function addUser($id) {
984 if (!$this->userIsAdmin()) {
985 $this->setPermissionDeniedError();
989 $this->setMissingParamsError();
992 $sql="SELECT * FROM artifact_perm
993 WHERE group_artifact_id='".$this->getID()."'
995 $result=db_query($sql);
996 if (db_numrows($result) > 0) {
999 $sql="INSERT INTO artifact_perm (group_artifact_id,user_id,perm_level)
1000 VALUES ('".$this->getID()."','$id',0)";
1001 $result=db_query($sql);
1002 if ($result && db_affected_rows($result) > 0) {
1005 $this->setError(db_error());
1012 * updateUser - update a user's permissions.
1014 * @param int user_id of the user to update.
1015 * @param int (0) read only, (1) tech only, (2) admin & tech (3) admin only.
1016 * @return boolean success.
1018 function updateUser($id,$perm_level) {
1019 if (!$this->userIsAdmin()) {
1020 $this->setPermissionDeniedError();
1024 $this->setMissingParamsError();
1027 $sql="UPDATE artifact_perm SET perm_level='$perm_level'
1028 WHERE user_id='$id' AND group_artifact_id='".$this->getID()."'";
1029 $result=db_query($sql);
1030 if (db_affected_rows($result) < 1) {
1032 // If not, insert it.
1034 $sql="INSERT INTO artifact_perm (group_artifact_id,user_id,perm_level) VALUES
1035 ('".$this->getID()."','$id','$perm_level')";
1036 $result=db_query($sql);
1038 $this->setError(db_error());
1049 * deleteUser - delete a user's permissions.
1051 * @param int user_id of the user who's permissions to delete.
1052 * @return boolean success.
1054 function deleteUser($id) {
1055 if (!$this->userIsAdmin()) {
1056 $this->setPermissionDeniedError();
1060 $this->setMissingParamsError();
1063 $sql="DELETE FROM artifact_perm
1064 WHERE user_id='$id' AND group_artifact_id='".$this->getID()."'";
1065 $result=db_query($sql);
1069 $this->setError(db_error());
1076 USER PERMISSION FUNCTIONS
1081 * userCanView - determine if the user can view this artifact type.
1083 * @return boolean user_can_view.
1085 function userCanView() {
1086 if ($this->isPublic()) {
1089 if (!session_loggedin()) {
1093 // You must have an entry in artifact_perm if this tracker is not public
1095 if ($this->userIsAdmin() || $this->getCurrentUserPerm() >= 0) {
1105 * userIsAdmin - see if the logged-in user's perms are >= 2 or Group ArtifactAdmin.
1107 * @return boolean user_is_admin.
1109 function userIsAdmin() {
1110 if (!session_loggedin()) {
1113 $perm =& $this->Group->getPermission( session_get_user() );
1115 if (($this->getCurrentUserPerm() >= 2) || ($perm->isArtifactAdmin())) {
1124 * userIsTechnician - see if the logged-in user's perms are >= 1 or Group ArtifactAdmin.
1126 * @return boolean user_is_technician.
1128 function userIsTechnician() {
1129 if (!session_loggedin()) {
1132 $perm =& $this->Group->getPermission( session_get_user() );
1134 if (($this->getCurrentUserPerm() >= 1) || ($perm->isArtifactAdmin())) {
1143 * getCurrentUserPerm - get the logged-in user's perms from artifact_perm.
1145 * @return int perm level for the logged-in user.
1147 function getCurrentUserPerm() {
1148 if (!session_loggedin()) {
1151 if (!isset($this->current_user_perm)) {
1152 $sql="select perm_level
1154 WHERE group_artifact_id='". $this->getID() ."'
1155 AND user_id='".user_getid()."'";
1156 $this->current_user_perm=db_result(db_query($sql),0,0);
1158 return $this->current_user_perm;
1163 * update - use this to update this ArtifactType in the database.
1165 * @param string The item name.
1166 * @param string The item description.
1167 * @param bool (1) true (0) false - whether to email on all updates.
1168 * @param string The address to send new entries and updates to.
1169 * @param int Days before this item is considered overdue.
1170 * @param int Days before stale items time out.
1171 * @param bool (1) true (0) false - whether the resolution box should be shown.
1172 * @param string Free-form string that project admins can place on the submit page.
1173 * @param string Free-form string that project admins can place on the browse page.
1174 * @return true on success, false on failure.
1176 function update($name,$description,$email_all,$email_address,
1177 $due_period, $status_timeout,$use_resolution,$submit_instructions,$browse_instructions) {
1181 if (!$this->userIsAdmin()) {
1182 $this->setPermissionDeniedError();
1186 if ($this->getDataType()) {
1187 $name=$this->getName();
1188 $description=$this->getDescription();
1191 if (!$name || !$description || !$due_period || !$status_timeout) {
1192 $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
1196 if ($email_address) {
1197 $invalid_emails = validate_emails($email_address);
1198 if (count($invalid_emails) > 0) {
1199 $this->SetError(_('E-mail address(es) appeared invalid').': '.implode(',',$invalid_emails));
1204 $email_all = ((!$email_all) ? 0 : $email_all);
1205 $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
1207 $sql="UPDATE artifact_group_list SET
1208 name='". htmlspecialchars($name). "',
1209 description='". htmlspecialchars($description) ."',
1210 email_all_updates='$email_all',
1211 email_address='$email_address',
1212 due_period='". ($due_period * (60*60*24)) ."',
1213 status_timeout='". ($status_timeout * (60*60*24)) . "',
1214 submit_instructions='". htmlspecialchars($submit_instructions)."',
1215 browse_instructions='" .htmlspecialchars($browse_instructions)."'
1217 group_artifact_id='". $this->getID() ."'
1218 AND group_id='". $this->Group->getID() ."'";
1220 $res=db_query($sql);
1221 if (!$res || db_affected_rows($res) < 1) {
1222 $this->setError('ArtifactType::Update(): '.db_error());
1225 $this->fetchData($this->getID());