/**
  *	Delete a tracker
  *
  *  @aparam atid: the artifact type id
  *
  *	@return	boolean
  */
 function deleteArtifactType($atid)
 {
     // Delete artifact_canned_responses
     $sql = "DELETE FROM artifact_canned_responses \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // Delete artifact_notification
     $sql = "DELETE FROM artifact_notification  \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // Delete artifact_notification_event
     $sql = "DELETE FROM artifact_notification_event   \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // Delete artifact_notification_role
     $sql = "DELETE FROM artifact_notification_role   \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // Delete artifact_perm
     $sql = "DELETE FROM artifact_perm   \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // We need to instanciate an artifactType to instanciate the factories
     $artifactType = new ArtifactType($this->getGroup(), $atid, false);
     $art_field_fact = new ArtifactFieldFactory($artifactType);
     $art_fieldset_fact = new ArtifactFieldSetFactory($artifactType);
     // Delete the fields of this tracker
     $art_field_fact->deleteFields($atid);
     // Delete the field sets of this tracker
     $art_fieldset_fact->deleteFieldSets();
     // Delete the artifact_report
     $art_report_fact = new ArtifactReportFactory();
     $art_report_fact->deleteReports($atid);
     //Generate an event
     $em =& EventManager::instance();
     $pref_params = array('atid' => $atid);
     $em->processEvent('artifactType_deleted', $pref_params);
     // Delete the artifact rules
     $art_rule_fact = ArtifactRuleFactory::instance();
     $art_rule_fact->deleteRulesByArtifactType($atid);
     // Delete artifact_watcher (be carefull, the column is named artifact_group_id)
     $sql = "DELETE FROM artifact_watcher   \n\t\t\t    WHERE artifact_group_id=" . db_ei($atid);
     db_query($sql);
     // Delete all records linked to artifact_id
     $sql_artifacts = 'SELECT artifact_id ' . 'FROM artifact ' . 'WHERE group_artifact_id=' . db_ei($atid);
     //echo $sql_artifacts;
     $res = db_query($sql_artifacts);
     while ($artifacts_array = db_fetch_array($res)) {
         $id = $artifacts_array["artifact_id"];
         // Delete artifact_cc records
         $sql = "DELETE FROM artifact_cc WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact_dependencies records
         $sql = "DELETE FROM artifact_dependencies WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact_field_value records
         $sql = "DELETE FROM artifact_field_value WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact_file records
         $sql = "DELETE FROM artifact_file WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact_history records
         $sql = "DELETE FROM artifact_history WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact records
         $sql = "DELETE FROM artifact WHERE artifact_id = " . db_ei($id);
         db_query($sql);
     }
     // while
     // Delete artifact_group_list
     $sql = "DELETE FROM artifact_group_list\n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     //echo $sql;
     $result = db_query($sql);
     if (!$result || db_affected_rows($result) <= 0) {
         $this->setError('Error: deleteArtifactType ' . db_error());
         return false;
     }
     //Remove permissions
     permission_clear_all_tracker($this->Group->getID(), $atid);
     $em = EventManager::instance();
     $em->processEvent("artifact_type_factory_delete_artifact_type", array('tracker_id' => $atid));
     return true;
 }
 function _getArtifactRuleFactory()
 {
     return ArtifactRuleFactory::instance();
 }