public function __construct($label, $name, $value, $with_none = false, $onchange = "", $desc = "")
 {
     parent::__construct($label, $name, $value, $with_none, $onchange, $desc);
     require_once 'common/tracker/ArtifactFieldFactory.class.php';
     require_once 'common/tracker/ArtifactType.class.php';
     $at = new ArtifactType($GLOBALS['ath']->Group, $GLOBALS['ath']->getID(), false);
     $aff = new ArtifactFieldFactory($at);
     foreach ($aff->getAllUsedFields() as $field) {
         if ($field->userCanRead($GLOBALS['group_id'], $GLOBALS['ath']->getID(), user_getid())) {
             if ($field->isdateField()) {
                 $selected = $this->value == $field->getName();
                 $this->addOption(new HTML_Element_Option($field->getLabel(), $field->getName(), $selected));
             }
         }
     }
 }
 /**
  *  fetchData - re-fetch the data for this ArtifactFieldSet from the database.
  *
  *  @return boolean	success.
  */
 function fetchData()
 {
     global $Language;
     $sql = "SELECT * \n                FROM artifact_field_set \n                WHERE artifact_field_set_id=" . db_ei($this->getID()) . "";
     $res = db_query($sql);
     if (!$res || db_numrows($res) < 1) {
         $this->setError('ArtifactFieldSet: ' . $Language->getText('tracker_common_fieldset', 'invalid_at'));
         return false;
     }
     // set the attributes of this fieldset
     $this->setFromArray($res);
     // attach the fields of this fieldset
     $art_field_fact = new ArtifactFieldFactory($ArtifactType);
     $this->ArtifactFields = $art_field_fact->getFieldsContainedInFieldSet($this->getID());
     db_free_result($res);
     return true;
 }
 /**
  * Add artifact to artifact_date_reminder_processing table
  * 
  *  @param field_id: the field id
  *  @param artifact_id: the artifact id
  *  @param group_artifact_id: the tracker id
  * 
  * @return nothing
  */
 function addArtifactToDateReminderProcessing($field_id, $artifact_id, $group_artifact_id)
 {
     $art_field_fact = new ArtifactFieldFactory($this->at);
     if ($field_id != 0) {
         $sql = sprintf('SELECT reminder_id, field_id FROM artifact_date_reminder_settings' . ' WHERE group_artifact_id=%d' . ' AND field_id=%d', db_ei($group_artifact_id), db_ei($field_id));
     } else {
         $sql = sprintf('SELECT reminder_id, field_id FROM artifact_date_reminder_settings' . ' WHERE group_artifact_id=%d', db_ei($group_artifact_id));
     }
     $res = db_query($sql);
     if (db_numrows($res) > 0) {
         while ($rows = db_fetch_array($res)) {
             $reminder_id = $rows['reminder_id'];
             $fid = $rows['field_id'];
             $field = $art_field_fact->getFieldFromId($fid);
             $sql1 = sprintf('SELECT valueDate FROM artifact_field_value' . ' WHERE artifact_id=%d' . ' AND field_id=%d', db_ei($artifact_id), db_ei($fid));
             $res1 = db_query($sql1);
             if (!$field->isStandardField()) {
                 if (db_numrows($res1) > 0) {
                     $valueDate = db_result($res1, 0, 'valueDate');
                     if ($valueDate != 0 && $valueDate != NULL) {
                         //the date field is not special (value is stored in 'artifact_field_value' table)
                         $ins = sprintf('INSERT INTO artifact_date_reminder_processing' . ' (reminder_id,artifact_id,field_id,group_artifact_id,notification_sent)' . ' VALUES(%d,%d,%d,%d,%d)', db_ei($reminder_id), db_ei($artifact_id), db_ei($fid), db_ei($group_artifact_id), 0);
                         $result = db_query($ins);
                     }
                 }
             } else {
                 //End Date
                 $sql2 = sprintf('SELECT close_date FROM artifact' . ' WHERE artifact_id=%d' . ' AND group_artifact_id=%d', db_ei($artifact_id), db_ei($group_artifact_id));
                 $res2 = db_query($sql2);
                 if (db_numrows($res2) > 0) {
                     $close_date = db_result($res2, 0, 'close_date');
                     if ($close_date != 0 && $close_date != NULL) {
                         $ins = sprintf('INSERT INTO artifact_date_reminder_processing' . ' (reminder_id,artifact_id,field_id,group_artifact_id,notification_sent)' . ' VALUES(%d,%d,%d,%d,%d)', db_ei($reminder_id), db_ei($artifact_id), db_ei($fid), db_ei($group_artifact_id), 0);
                         $result = db_query($ins);
                     }
                 }
             }
         }
     }
 }
Exemple #4
0
 //
 //      Create the ArtifactType object
 //
 $ath = new ArtifactTypeHtml($group, $atid);
 if (!$ath || !is_object($ath)) {
     exit_error($Language->getText('global', 'error'), $Language->getText('global', 'error'));
 }
 if ($ath->isError()) {
     exit_error($Language->getText('global', 'error'), $ath->getErrorMessage());
 }
 // Check if this tracker is valid (not deleted)
 if (!$ath->isValid()) {
     exit_error($Language->getText('global', 'error'), $Language->getText('global', 'error'));
 }
 // Create field factory
 $art_field_fact = new ArtifactFieldFactory($ath);
 $params = array('title' => $group->getPublicName() . ': \'' . $ath->getName() . '\' ' . $Language->getText('tracker_browse', 'search_report'), 'titlevals' => array($ath->getName()), 'pagename' => 'tracker_browse', 'atid' => $ath->getID(), 'sectionvals' => array($group->getPublicName()), 'pv' => 0, 'help' => 'ArtifactBrowsing.html');
 $ath->header($params);
 echo '<div id="tracker_toolbar_clear"></div>';
 $array = explode(" ", $words);
 $words1 = implode($array, "%' {$crit} artifact.details LIKE '%");
 $words2 = implode($array, "%' {$crit} artifact.summary LIKE '%");
 $words3 = implode($array, "%' {$crit} artifact_history.new_value LIKE '%");
 $sql = "SELECT SQL_CALC_FOUND_ROWS artifact.artifact_id,\n                   artifact.summary,\n                   artifact.open_date,\n                   user.user_name\n           FROM artifact INNER JOIN user ON user.user_id=artifact.submitted_by \n              LEFT JOIN artifact_history ON artifact_history.artifact_id=artifact.artifact_id \n              LEFT JOIN permissions ON (permissions.object_id = CAST(artifact.artifact_id AS CHAR) AND permissions.permission_type = 'TRACKER_ARTIFACT_ACCESS')\n           WHERE artifact.group_artifact_id='" . db_ei($atid) . "' \n             AND (\n                   artifact.use_artifact_permissions = 0\n                   OR \n                   (\n                       permissions.ugroup_id IN (" . implode(',', UserManager::instance()->getCurrentUser()->getUgroups($group_id, $atid)) . ")\n                   )\n             )\n             AND (\n                   (artifact.details LIKE '%" . db_es($words1) . "%') \n                   OR \n                   (artifact.summary LIKE '%" . db_es($words2) . "%') \n                   OR \n                   (artifact_history.field_name='comment' AND (artifact_history.new_value LIKE '%" . db_es($words3) . "%'))\n             ) \n           GROUP BY open_date DESC \n           LIMIT " . db_ei($offset) . ", 25";
 $result = db_query($sql);
 $rows_returned = db_result(db_query('SELECT FOUND_ROWS() as nb'), 0, 'nb');
 if (!$result || $rows_returned < 1) {
     $no_rows = 1;
     echo '<H2>' . $Language->getText('search_index', 'no_match_found', htmlentities(stripslashes($words), ENT_QUOTES, 'UTF-8')) . '</H2>';
     echo db_error();
 } else {
Exemple #5
0
     }
     $field_id = $request->getValidated('field_id', 'uint', 0);
     $field = $art_field_fact->getFieldFromId($field_id);
     if ($field) {
         $em = EventManager::instance();
         $em->processEvent('tracker_admin_field_delete', array('field' => $field, 'ath' => $ath));
         //clear permissions
         permission_clear_all_fields_tracker($group_id, $atid, $field->getID());
         if (!$field->delete($atid)) {
             exit_error($Language->getText('global', 'error'), $field->getErrorMessage());
         } else {
             require_once 'common/tracker/ArtifactRulesManager.class.php';
             $arm = new ArtifactRulesManager();
             $arm->deleteRulesByFieldId($atid, $field_id);
             // Reload the field factory
             $art_field_fact = new ArtifactFieldFactory($ath);
             // Reload the fieldset factory
             $art_fieldset_fact = new ArtifactFieldSetFactory($ath);
             $GLOBALS['Response']->addFeedback('info', $Language->getText('tracker_admin_index', 'field_deleted'));
         }
     }
     require './field_usage.php';
     break;
 case 'display_field_update':
     if (!user_isloggedin()) {
         exit_not_logged_in();
         return;
     }
     if (!$ath->userIsAdmin()) {
         exit_permission_denied();
         return;
     db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_name);
     db_project_query($dbname, 'DROP TABLE IF EXISTS ' . "artifact_struct_" . $at_arr[$j]->getItemName());
     continue;
 }
 //
 //      Create the ArtifactTypeHtml object - needed in ArtifactField.getFieldPredefinedValues()
 //
 $ath = new ArtifactTypeHtml($group, $atid);
 if (!$ath || !is_object($ath)) {
     exit_error($Language->getText('global', 'error'), $Language->getText('project_export_artifact_export', 'ath_not_created'));
 }
 if ($ath->isError()) {
     exit_error($Language->getText('global', 'error'), $ath->getErrorMessage());
 }
 // Create field factory
 $art_field_fact = new ArtifactFieldFactory($at);
 if ($art_field_fact->isError()) {
     exit_error($Language->getText('global', 'error'), $art_field_fact->getErrorMessage());
 }
 $art_fieldset_fact = new ArtifactFieldSetFactory($at);
 if ($art_fieldset_fact->isError()) {
     exit_error($Language->getText('global', 'error'), $art_fieldset_fact->getErrorMessage());
 }
 $col_list = array();
 $sql = $at->buildExportQuery($fields, $col_list, $lbl_list, $dsc_list, $select, $from, $where, $multiple_queries, $all_queries);
 $col_list[] = 'follow_ups';
 $col_list[] = 'is_dependent_on';
 // Let's create the project database if it does not exist
 // Drop the existing table and create a fresh one
 db_project_create($dbname);
 db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_name);
 /**
  * Send the notification mail, about an event
  *
  * @return boolean
  */
 function handleNotification()
 {
     global $art_field_fact;
     $logger = new TrackerDateReminder_Logger_Prefix($this->logger, '[handleNotification]');
     $logger->info("Start");
     $group = ProjectManager::instance()->getProject($this->getGroupId());
     $at = new ArtifactType($group, $this->getGroupArtifactId());
     $art_field_fact = new ArtifactFieldFactory($at);
     $field = $art_field_fact->getFieldFromId($this->getFieldId());
     $art = new Artifact($at, $this->getArtifactId(), false);
     $logger->info("tracker: " . $this->getGroupArtifactId());
     $logger->info("artifact: " . $this->getArtifactId());
     $sent = true;
     $week = date("W", $this->getDateValue());
     $mail = new Mail();
     $mail->setFrom($GLOBALS['sys_noreply']);
     $mail->setSubject("[" . $this->getTrackerName() . "] " . $GLOBALS['Language']->getText('plugin_tracker_date_reminder', 'reminder_mail_subject', array($field->getLabel(), date("j F Y", $this->getDateValue()), $art->getSummary())));
     $body = "\n" . $GLOBALS['Language']->getText('plugin_tracker_date_reminder', 'reminder_mail_body_header', array($field->getLabel(), date("l j F Y", $this->getDateValue()), $week)) . "\n\n" . $GLOBALS['Language']->getText('plugin_tracker_date_reminder', 'reminder_mail_body_project', array($group->getPublicName())) . "\n" . $GLOBALS['Language']->getText('plugin_tracker_date_reminder', 'reminder_mail_body_tracker', array($this->getTrackerName())) . "\n" . $GLOBALS['Language']->getText('plugin_tracker_date_reminder', 'reminder_mail_body_art', array($art->getSummary())) . "\n" . $field->getLabel() . ": " . date("D j F Y", $this->getDateValue()) . "\n\n" . $GLOBALS['Language']->getText('plugin_tracker_date_reminder', 'reminder_mail_body_art_link') . "\n" . get_server_url() . "/tracker/?func=detail&aid=" . $this->getArtifactId() . "&atid=" . $this->getGroupArtifactId() . "&group_id=" . $this->getGroupId() . "\n\n______________________________________________________________________" . "\n" . $GLOBALS['Language']->getText('plugin_tracker_date_reminder', 'reminder_mail_footer') . "\n";
     $mail->setBody($body);
     $allNotified = $this->getNotifiedPeople();
     $logger->info("notify: " . implode(', ', $allNotified));
     foreach ($allNotified as $notified) {
         $mail->setTo($notified);
         if (!$mail->send()) {
             $logger->error("faild to notify {$notified}");
             $sent = false;
         }
     }
     $logger->info("End");
     return $sent;
 }
 function saveFromRequest(&$request)
 {
     //TODO: Valid the request
     switch ($request->get('direction_type')) {
         case 'source':
             // 1 source -> n targets
             $this->deleteRuleValueBySource($this->artifact_type->getId(), $request->get('source_field'), $request->get('value'), $request->get('target_field'));
             //get target values
             $art_field_fact = new ArtifactFieldFactory($this->artifact_type);
             $target_field = $art_field_fact->getFieldFromId($request->get('target_field'));
             $target_values = $target_field->getFieldPredefinedValues($this->artifact_type->getID());
             while ($row = db_fetch_array($target_values)) {
                 if ($request->exist('target_' . $request->get('source_field') . '_' . $request->get('target_field') . '_' . $row[0] . '_chk')) {
                     $this->saveRuleValue($this->artifact_type->getId(), $request->get('source_field'), $request->get('value'), $request->get('target_field'), $row[0]);
                 }
             }
             $GLOBALS['Response']->addFeedback('info', '<span class="feedback_field_dependencies">' . $GLOBALS['Language']->getText('tracker_field_dependencies', 'saved') . '</span>', CODENDI_PURIFIER_DISABLED);
             $this->displayRules($request->get('source_field'), $request->get('target_field'), $request->get('value'), false);
             break;
         case 'target':
             // n sources -> 1 target
             $this->deleteRuleValueByTarget($this->artifact_type->getId(), $request->get('source_field'), $request->get('target_field'), $request->get('value'));
             //get source values
             $art_field_fact = new ArtifactFieldFactory($this->artifact_type);
             $source_field =& $art_field_fact->getFieldFromId($request->get('source_field'));
             $source_values = $source_field->getFieldPredefinedValues($this->artifact_type->getID());
             while ($row = db_fetch_array($source_values)) {
                 if ($request->exist('source_' . $request->get('source_field') . '_' . $request->get('target_field') . '_' . $row[0] . '_chk')) {
                     $this->saveRuleValue($this->artifact_type->getId(), $request->get('source_field'), $row[0], $request->get('target_field'), $request->get('value'));
                 }
             }
             $GLOBALS['Response']->addFeedback('info', '<span class="feedback_field_dependencies">' . $GLOBALS['Language']->getText('tracker_field_dependencies', 'saved') . '</span>', CODENDI_PURIFIER_DISABLED);
             $this->displayRules($request->get('source_field'), $request->get('target_field'), false, $request->get('value'));
             break;
         default:
             $this->badRequest();
             break;
     }
 }
Exemple #9
0
/**
 * Return the name of a given object
 */
function permission_get_object_name($permission_type, $object_id)
{
    global $Language, $group_id;
    $pm = ProjectManager::instance();
    if ($permission_type == 'NEWS_READ') {
        return get_news_name_from_forum_id($object_id);
    } else {
        if ($permission_type == 'PACKAGE_READ') {
            return file_get_package_name_from_id($object_id);
        } else {
            if ($permission_type == 'RELEASE_READ') {
                return file_get_release_name_from_id($object_id);
            } else {
                if ($permission_type == 'DOCUMENT_READ') {
                    return util_unconvert_htmlspecialchars(doc_get_title_from_id($object_id));
                } else {
                    if ($permission_type == 'DOCGROUP_READ') {
                        return doc_get_docgroupname_from_id($object_id);
                    } else {
                        if ($permission_type == 'WIKI_READ') {
                            return $Language->getText('project_admin_permissions', 'wiki');
                        } else {
                            if ($permission_type == 'WIKIPAGE_READ') {
                                #$wikipage= new WikiPage($object_id);
                                #return $wikipage->getPagename();
                                return "{$object_id}";
                            } else {
                                if ($permission_type == 'WIKIATTACHMENT_READ') {
                                    return $Language->getText('project_admin_permissions', 'wikiattachment');
                                } else {
                                    if (strpos($permission_type, 'TRACKER_ACCESS') === 0) {
                                        $group = $pm->getProject($group_id);
                                        $at = new ArtifactType($group, $object_id);
                                        return $at->getName();
                                    } else {
                                        if (strpos($permission_type, 'TRACKER_FIELD') === 0) {
                                            $ret = "{$object_id}";
                                            if ($group = $pm->getProject($group_id)) {
                                                $atid = permission_extract_atid($object_id);
                                                $at = new ArtifactType($group, $atid);
                                                $ret = $at->getName();
                                                if ($ath = new ArtifactTypeHtml($group, $atid)) {
                                                    if ($art_field_fact = new ArtifactFieldFactory($ath)) {
                                                        $field_id = permission_extract_field_id($object_id);
                                                        if ($field = $art_field_fact->getFieldFromId($field_id)) {
                                                            $ret = $field->getName() . ' (' . $ret . ')';
                                                        }
                                                    }
                                                }
                                            }
                                            return $ret;
                                        } else {
                                            if ($permission_type == 'TRACKER_ARTIFACT_ACCESS') {
                                                $ret = $object_id;
                                                $sql = "SELECT group_artifact_id FROM artifact WHERE artifact_id= " . db_ei($object_id);
                                                $result = db_query($sql);
                                                if (db_numrows($result) > 0) {
                                                    $row = db_fetch_array($result);
                                                    $atid = $row['group_artifact_id'];
                                                }
                                                $group = $pm->getProject($group_id);
                                                $at = new ArtifactType($group, $atid);
                                                $a = new Artifact($at, $object_id);
                                                return 'art #' . $a->getId() . ' - ' . util_unconvert_htmlspecialchars($a->getSummary());
                                            } else {
                                                $em =& EventManager::instance();
                                                $object_name = false;
                                                $em->processEvent('permission_get_object_name', array('permission_type' => $permission_type, 'object_id' => $object_id, 'object_name' => &$object_name));
                                                return $object_name ? $object_name : $object_id;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 public function search(Search_SearchQuery $query, Search_SearchResults $search_results)
 {
     include_once 'www/tracker/include/ArtifactTypeHtml.class.php';
     include_once 'www/tracker/include/ArtifactHtml.class.php';
     $project = $query->getProject();
     if ($project->isError()) {
         return;
     }
     $group_id = $project->getId();
     $words = $query->getWords();
     $exact = $query->getExact();
     $offset = $query->getOffset();
     $atid = $query->getTrackerV3Id();
     ob_start();
     //
     //      Create the ArtifactType object
     //
     $ath = new ArtifactTypeHtml($project, $atid);
     if (!$ath || !is_object($ath)) {
         exit_error($GLOBALS['Language']->getText('global', 'error'), $GLOBALS['Language']->getText('global', 'error'));
     }
     if ($ath->isError()) {
         exit_error($GLOBALS['Language']->getText('global', 'error'), $ath->getErrorMessage());
     }
     // Check if this tracker is valid (not deleted)
     if (!$ath->isValid()) {
         exit_error($GLOBALS['Language']->getText('global', 'error'), $GLOBALS['Language']->getText('global', 'error'));
     }
     $results = $this->dao->searchGlobalPaginated($words, $exact, $offset, $atid, UserManager::instance()->getCurrentUser()->getUgroups($group_id, $atid), $query->getNumberOfResults());
     $rows_returned = $this->dao->foundRows();
     $art_displayed = 0;
     if ($rows_returned < 1) {
         echo '<H2>' . $GLOBALS['Language']->getText('search_index', 'no_match_found', htmlentities(stripslashes($words), ENT_QUOTES, 'UTF-8')) . '</H2>';
     } else {
         // Create field factory
         $art_field_fact = new ArtifactFieldFactory($ath);
         echo '<H3>' . $GLOBALS['Language']->getText('search_index', 'search_res', array(htmlentities(stripslashes($words), ENT_QUOTES, 'UTF-8'), $rows_returned)) . "</H3><P>\n";
         $title_arr = array();
         $summary_field = $art_field_fact->getFieldFromName("summary");
         if ($summary_field->userCanRead($group_id, $atid)) {
             $title_arr[] = $GLOBALS['Language']->getText('search_index', 'artifact_summary');
         }
         $submitted_field = $art_field_fact->getFieldFromName("submitted_by");
         if ($submitted_field->userCanRead($group_id, $atid)) {
             $title_arr[] = $GLOBALS['Language']->getText('search_index', 'submitted_by');
         }
         $date_field = $art_field_fact->getFieldFromName("open_date");
         if ($date_field->userCanRead($group_id, $atid)) {
             $title_arr[] = $GLOBALS['Language']->getText('search_index', 'date');
         }
         $status_field = $art_field_fact->getFieldFromName("status_id");
         if ($status_field->userCanRead($group_id, $atid)) {
             $title_arr[] = $GLOBALS['Language']->getText('global', 'status');
         }
         echo html_build_list_table_top($title_arr);
         echo "\n";
         $rows = 0;
         foreach ($results as $arr) {
             $rows++;
             $curArtifact = new Artifact($ath, $arr['artifact_id']);
             if ($curArtifact->isStatusClosed($curArtifact->getStatusID())) {
                 $status = $GLOBALS['Language']->getText('global', 'closed');
             } else {
                 $status = $GLOBALS['Language']->getText('global', 'open');
             }
             // Only display artifacts that the user is allowed to see
             if ($curArtifact->userCanView(user_getid())) {
                 print "\n<TR class=\"" . html_get_alt_row_color($art_displayed) . "\">";
                 if ($summary_field->userCanRead($group_id, $atid)) {
                     print "<TD><A HREF=\"/tracker/?group_id={$group_id}&func=detail&atid={$atid}&aid=" . $arr['artifact_id'] . "\"><IMG SRC=\"" . util_get_image_theme('msg.png') . "\" BORDER=0 HEIGHT=12 WIDTH=10> " . $arr['summary'] . "</A></TD>";
                 }
                 if ($submitted_field->userCanRead($group_id, $atid)) {
                     print "<TD>" . $arr['user_name'] . "</TD>";
                 }
                 if ($date_field->userCanRead($group_id, $atid)) {
                     print "<TD>" . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $arr['open_date']) . "</TD>";
                 }
                 if ($status_field->userCanRead($group_id, $atid)) {
                     print "<TD>" . $status . "</TD>";
                 }
                 print "</TR>";
                 $art_displayed++;
                 if ($art_displayed > $query->getNumberOfResults()) {
                     break;
                 }
             }
         }
         echo "</TABLE>\n";
     }
     $maybe_more_results = $art_displayed < $query->getNumberOfResults() ? false : true;
     $search_results->setCountResults($art_displayed)->setHasMore($maybe_more_results);
     return new Search_SearchTrackerV3ResultPresenter(ob_get_clean());
 }
Exemple #11
0
 /**
  * Get permissions for all fields based on the ugroups the user is part of
  *
  */
 function getFieldPermissions($ugroups)
 {
     $art_field_fact = new ArtifactFieldFactory($this);
     $used_fields = $art_field_fact->getAllUsedFields();
     $field_perm = array();
     reset($used_fields);
     foreach ($used_fields as $field) {
         $perm = $field->getPermissionForUgroups($ugroups, $this->getID());
         if ($perm && !empty($perm)) {
             $field_perm[$field->getName()] = $perm;
         }
     }
     return $field_perm;
 }
 //	Create the ArtifactType object
 //
 $at = new ArtifactType($group, $atid);
 if (!$at || !is_object($at)) {
     exit_error($Language->getText('global', 'error'), $Language->getText('project_export_artifact_deps_export', 'at_not_created'));
 }
 if ($at->isError()) {
     exit_error($Language->getText('global', 'error'), $at->getErrorMessage());
 }
 // Check if this tracker is valid (not deleted) && the database has been exported
 if (!$at->isValid() && db_database_exist($dbname)) {
     db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_name);
     continue;
 }
 // Create field factory
 $art_field_fact = new ArtifactFieldFactory($at);
 if ($art_field_fact->isError()) {
     exit_error($Language->getText('global', 'error'), $art_field_fact->getErrorMessage());
 }
 // Let's create the project database if it does not exist
 // Drop the existing table and create a fresh one
 db_project_create($dbname);
 db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_name);
 $sql_create = "CREATE TABLE {$tbl_name} (" . 'artifact_id INTEGER, is_dependent_on_artifact_id INTEGER)';
 $res = db_project_query($dbname, $sql_create);
 // extract data from the bug table and insert them into
 // the project database table. Do it in one shot here.
 if ($res) {
     $sql = 'SELECT ad.artifact_id,' . 'ad.is_dependent_on_artifact_id ' . 'FROM artifact_dependencies ad, artifact a ' . 'WHERE ad.artifact_id = a.artifact_id AND a.group_artifact_id = ' . $atid . ' AND ' . 'ad.is_dependent_on_artifact_id <> 100';
     $result = db_query($sql);
     while ($arr = db_fetch_array($result)) {
Exemple #13
0
             if ($ath->isError()) {
                 exit_error($Language->getText('global', 'error'), $ath->getErrorMessage() . " | " . $Language->getText('tracker_admin_restore', 'delay_failed'));
             }
             exit_error($Language->getText('global', 'error'), $Language->getText('tracker_admin_restore', 'delay_failed'));
         } else {
             $feedback = $Language->getText('tracker_admin_restore', 'delayed_deletion');
         }
     }
     break;
 case 'delete':
     // Create field factory
     if ($group = $pm->getProject($request->getValidated('group_id', 'GroupId'))) {
         $atid = $request->getValidated('atid', 'uint');
         $ath = new ArtifactType($group, $atid);
         $atf = new ArtifactTypeFactory($group);
         $art_field_fact = new ArtifactFieldFactory($ath);
         // Then delete all the fields informations
         if (!$art_field_fact->deleteFields($atid)) {
             exit_error($Language->getText('global', 'error'), $art_field_fact->getErrorMessage());
             return false;
         }
         // Then delete all the reports informations
         // Create field factory
         $art_report_fact = new ArtifactReportFactory();
         if (!$art_report_fact->deleteReports($atid)) {
             exit_error($Language->getText('global', 'error'), $art_report_fact->getErrorMessage());
             return false;
         }
         // Delete the artifact type itself
         if (!$atf->deleteArtifactType($atid)) {
             exit_error($Language->getText('global', 'error'), $atf->getErrorMessage());
Exemple #14
0
 /**
  *  fetchData - re-fetch the data for this Artifact from the database.
  *
  *  @param  int             The artifact ID.
  *  @return boolean success.
  */
 function fetchData($artifact_id)
 {
     global $art_field_fact, $Language;
     if (!$art_field_fact) {
         $art_field_fact = new ArtifactFieldFactory($this->ArtifactType);
     }
     // first fetch values of standard fields
     $sql = "SELECT * FROM artifact WHERE artifact_id='" . db_ei($artifact_id) . "' AND group_artifact_id='" . db_ei($this->ArtifactType->getID()) . "'";
     $res = db_query($sql);
     if (!$res || db_numrows($res) < 1) {
         $this->setError('Artifact: ' . $Language->getText('tracker_common_artifact', 'invalid_id'));
         return false;
     }
     $this->data_array = db_fetch_array($res);
     db_free_result($res);
     // now get the values for generic fields if any
     $sql = "SELECT * FROM artifact_field_value WHERE artifact_id='" . db_ei($artifact_id) . "'";
     $res = db_query($sql);
     if (!$res || db_numrows($res) < 1) {
         // if no result then it is possible that there isn't any generic fields
         return true;
     }
     while ($row = db_fetch_array($res)) {
         $data_fields[$row['field_id']] = $row;
     }
     // Get the list of all fields used by this tracker and append
     // the values for these generic fields to data_array
     $fields = $art_field_fact->getAllUsedFields();
     while (list($key, $field) = each($fields)) {
         //echo $field->getName()."-".$field->getID()."<br>";
         // Skip! Standard field values fectched in previous query
         // and comment_type_id is not stored in artifact_field_value table
         if ($field->isStandardField() || $field->getName() == "comment_type_id") {
             continue;
         }
         $this->data_array[$field->getName()] = $data_fields[$field->getID()][$field->getValueFieldName()];
     }
     return true;
 }
 /**
  *	create - use this to create a new ArtifactType in the database.
  *
  *  @param  group_id: the group id of the new tracker
  *	@param	group_id_template: the template group id (used for the copy)
  *	@param	atid_template: the template artfact type id 
  *	@param	name: the name of the new tracker
  *	@param	description: the description of the new tracker
  *	@param	itemname: the itemname of the new tracker
  *	@return id on success, false on failure.
  */
 function create($group_id, $group_id_template, $atid_template, $name, $description, $itemname, $ugroup_mapping = false, &$report_mapping = array())
 {
     global $Language;
     if (!$name || !$description || !$itemname || trim($name) == "" || trim($description) == "" || trim($itemname) == "") {
         $this->setError('ArtifactTypeFactory: ' . $Language->getText('tracker_common_type', 'name_requ'));
         return false;
     }
     // Necessary test to avoid issues when exporting the tracker to a DB (e.g. '-' not supported as table name)
     if (!eregi("^[a-zA-Z0-9_]+\$", $itemname)) {
         $this->setError($Language->getText('tracker_common_type', 'invalid_shortname', $itemname));
         return false;
     }
     $reference_manager = ReferenceManager::instance();
     if ($reference_manager->_isKeywordExists($itemname, $group_id)) {
         $this->setError($Language->getText('tracker_common_type', 'shortname_already_exists', $itemname));
         return false;
     }
     if ($this->isNameExists($name, $group_id)) {
         $this->setError($Language->getText('tracker_common_type', 'name_already_exists', $name));
         return false;
     }
     //	get the template Group object
     $pm = ProjectManager::instance();
     $template_group = $pm->getProject($group_id_template);
     if (!$template_group || !is_object($template_group) || $template_group->isError()) {
         $this->setError('ArtifactTypeFactory: ' . $Language->getText('tracker_common_type', 'invalid_templ'));
     }
     // get the Group object of the new tracker
     $pm = ProjectManager::instance();
     $group = $pm->getProject($group_id);
     if (!$group || !is_object($group) || $group->isError()) {
         $this->setError('ArtifactTypeFactory: ' . $Language->getText('tracker_common_type', 'invalid_templ'));
     }
     // We retrieve allow_copy from template
     $at_template = new ArtifactType($template_group, $atid_template);
     $id_sharing = new TrackerIdSharingDao();
     if ($id = $id_sharing->generateTrackerId()) {
         // First, we create a new ArtifactType into artifact_group_list
         // By default, set 'instantiate_for_new_projects' to '1', so that a project that is not yet a
         // template will be able to have its trackers cloned by default when it becomes a template.
         $sql = "INSERT INTO \n                artifact_group_list \n                (group_artifact_id, group_id, name, description, item_name, allow_copy,\n                             submit_instructions,browse_instructions,instantiate_for_new_projects,stop_notification\n                             ) \n                VALUES \n                ({$id},\n                '" . db_ei($group_id) . "',\n                '" . db_es($name) . "',\n                '" . db_es($description) . "',\n                '" . db_es($itemname) . "',\n                            '" . db_ei($at_template->allowsCopy()) . "',\n                            '" . db_es($at_template->getSubmitInstructions()) . "',\n                            '" . db_es($at_template->getBrowseInstructions()) . "',1,0)";
         //echo $sql;
         $res = db_query($sql);
         if (!$res || db_affected_rows($res) <= 0) {
             $this->setError('ArtifactTypeFactory: ' . db_error());
             return false;
         } else {
             //No need to get the last insert id since we already know the id : $id
             //$id = db_insertid($res,'artifact_group_list','group_artifact_id');
             $at_new = new ArtifactType($group, $id);
             if (!$at_new->fetchData($id)) {
                 $this->setError('ArtifactTypeFactory: ' . $Language->getText('tracker_common_type', 'load_fail'));
                 return false;
             } else {
                 //create global notifications
                 $sql = "INSERT INTO artifact_global_notification (tracker_id, addresses, all_updates, check_permissions)\n                    SELECT " . db_ei($id) . ", addresses, all_updates, check_permissions\n                    FROM artifact_global_notification\n                    WHERE tracker_id = " . db_ei($atid_template);
                 $res = db_query($sql);
                 if (!$res || db_affected_rows($res) <= 0) {
                     $this->setError('ArtifactTypeFactory: ' . db_error());
                 }
                 // Create fieldset factory
                 $art_fieldset_fact = new ArtifactFieldSetFactory($at_template);
                 // Then copy all the field sets.
                 $mapping_field_set_array = $art_fieldset_fact->copyFieldSets($atid_template, $id);
                 if (!$mapping_field_set_array) {
                     $this->setError('ArtifactTypeFactory: ' . $art_fieldset_fact->getErrorMessage());
                     return false;
                 }
                 // Create field factory
                 $art_field_fact = new ArtifactFieldFactory($at_template);
                 // Then copy all the fields informations
                 if (!$art_field_fact->copyFields($id, $mapping_field_set_array, $ugroup_mapping)) {
                     $this->setError('ArtifactTypeFactory: ' . $art_field_fact->getErrorMessage());
                     return false;
                 }
                 // Then copy all the reports informations
                 // Create field factory
                 $art_report_fact = new ArtifactReportFactory();
                 if (!($report_mapping = $art_report_fact->copyReports($atid_template, $id))) {
                     $this->setError('ArtifactTypeFactory: ' . $art_report_fact->getErrorMessage());
                     return false;
                 }
                 $em =& EventManager::instance();
                 $pref_params = array('atid_source' => $atid_template, 'atid_dest' => $id);
                 $em->processEvent('artifactType_created', $pref_params);
                 // Copy artifact_notification_event and artifact_notification_role
                 if (!$at_new->copyNotificationEvent($id)) {
                     return false;
                 }
                 if (!$at_new->copyNotificationRole($id)) {
                     return false;
                 }
                 // Create user permissions: None for group members and Admin for group admin
                 if (!$at_new->createUserPerms($id)) {
                     return false;
                 }
                 // Create canned responses
                 $canned_new = new ArtifactCanned($at_new);
                 $canned_template = $at_template->getCannedResponses();
                 if ($canned_template && db_numrows($canned_template) > 0) {
                     while ($row = db_fetch_array($canned_template)) {
                         $canned_new->create($row['title'], $row['body']);
                     }
                 }
                 //Copy template permission
                 permission_copy_tracker_and_field_permissions($atid_template, $id, $group_id_template, $group_id, $ugroup_mapping);
                 //Copy Rules
                 require_once 'ArtifactRulesManager.class.php';
                 $arm = new ArtifactRulesManager();
                 $arm->copyRules($atid_template, $id);
             }
         }
     }
     return $id;
 }
 //	Create the ArtifactType object
 //
 $at = new ArtifactType($group, $atid);
 if (!$at || !is_object($at)) {
     exit_error($Language->getText('global', 'error'), $Language->getText('project_export_artifact_deps_export', 'at_not_created'));
 }
 if ($at->isError()) {
     exit_error($Language->getText('global', 'error'), $at->getErrorMessage());
 }
 // Check if this tracker is valid (not deleted) && the database has been exported
 if (!$at->isValid() && db_database_exist($dbname)) {
     db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_name);
     continue;
 }
 // Create field factory
 $art_field_fact = new ArtifactFieldFactory($at);
 if ($art_field_fact->isError()) {
     exit_error($Language->getText('global', 'error'), $art_field_fact->getErrorMessage());
 }
 // Let's create the project database if it does not exist
 // Drop the existing table and create a fresh one
 db_project_create($dbname);
 db_project_query($dbname, 'DROP TABLE IF EXISTS ' . $tbl_name);
 $sql_create = "CREATE TABLE {$tbl_name} (" . 'artifact_id INTEGER, field_name VARCHAR(255), ' . 'old_value TEXT, new_value TEXT, mod_by VARCHAR(255), email TEXT, date DATETIME, ' . 'type VARCHAR(255), ' . 'label VARCHAR(255) ' . ')';
 $res = db_project_query($dbname, $sql_create);
 // extract data from the bug table and insert them into
 // the project database table
 if ($res) {
     $result = extract_history($atid);
     while ($arr = db_fetch_array($result)) {
         prepare_artifact_history_record($at, $art_field_fact, $arr);
 /**
  *  Retrieve the fieldsets associated with an artifact type
  *
  *  @param int $group_artifact_id the artifact type id
  *	@return	boolean	success
  */
 function fetchData($group_artifact_id)
 {
     $sql = "SELECT * \n                FROM artifact_field_set \n                WHERE group_artifact_id=" . db_ei($group_artifact_id) . " \n                ORDER BY rank";
     //echo $sql;
     $res = db_query($sql);
     $this->ArtifactFieldSets = array();
     while ($fieldset_array = db_fetch_array($res)) {
         // create a new ArtifactFieldSet (empty)
         $fieldset = new ArtifactFieldSet();
         // set the datas
         $fieldset->setFromArray($fieldset_array);
         // set the fields contained inside the FieldSet
         $art_field_fact = new ArtifactFieldFactory($this->ArtifactType);
         $fields = $art_field_fact->getFieldsContainedInFieldSet($fieldset_array['field_set_id']);
         $fieldset->setArtifactFields($fields);
         $this->ArtifactFieldSets[] = $fieldset;
     }
     reset($this->ArtifactFieldSets);
 }