/** * Get the custom field id given an object ref. The id is set based on the following algorithm: * - id from objectref (if not zero). * - id corresponding to name in object ref. * - 0, if object ref doesn't contain an id or a name. * * @param ObjectRef $p_object_ref An associate array with "id" and "name" keys. */ function mci_get_custom_field_id_from_objectref($p_object_ref) { if ((int) $p_object_ref['id'] != 0) { $t_id = (int) $p_object_ref['id']; } else { if (!is_blank($p_object_ref['name'])) { $t_id = custom_field_get_id_from_name($p_object_ref['name']); } else { $t_id = 0; } } return $t_id; }
/** * Get the custom field id given an object ref. The id is set based on the following algorithm: * - id from objectref (if not zero). * - id corresponding to name in object ref. * - 0, if object ref doesn't contain an id or a name. * * @param stdClass $p_object_ref An associate array with "id" and "name" keys. * @return integer */ function mci_get_custom_field_id_from_objectref(stdClass $p_object_ref) { $p_object_ref = SoapObjectsFactory::unwrapObject($p_object_ref); if (isset($p_object_ref['id']) && (int) $p_object_ref['id'] != 0) { $t_id = (int) $p_object_ref['id']; } else { if (!is_blank($p_object_ref['name'])) { $t_id = custom_field_get_id_from_name($p_object_ref['name']); } else { $t_id = 0; } } return $t_id; }
public function process(XMLreader $reader) { //print "\nImportIssue process()\n"; $t_project_id = helper_get_current_project(); // TODO: category_get_id_by_name could work by default on current project $userId = auth_get_current_user_id(); $t_custom_fields = array(); $t_bugnotes = array(); $t_attachments = array(); $depth = $reader->depth; while ($reader->read() && ($reader->depth > $depth || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { switch ($reader->localName) { case 'reporter': $t_old_id = $reader->getAttribute('id'); $reader->read(); $this->newbug_->reporter_id = $this->get_user_id($reader->value, $userId); //echo "reporter: old id = $t_old_id - new id = {$this->newbug_->reporter_id}\n"; break; case 'handler': $t_old_id = $reader->getAttribute('id'); $reader->read(); $this->newbug_->handler_id = $this->get_user_id($reader->value, $userId); //echo "handler: old id = $t_old_id - new id = {$this->newbug_->handler_id}\n"; break; case 'category': $this->newbug_->category_id = $this->defaultCategory_; if (version_compare(MANTIS_VERSION, '1.2', '>') === true) { $reader->read(); if ($this->keepCategory_) { # Check for the category's existence in the current project # well as its parents (if any) $t_projects_hierarchy = project_hierarchy_inheritance($t_project_id); foreach ($t_projects_hierarchy as $t_project) { $t_category_id = category_get_id_by_name($reader->value, $t_project, false); if ($t_category_id !== false) { $this->newbug_->category_id = $t_category_id; break; } } } // echo "new id = {$this->newbug_->category_id}\n"; } break; case 'eta': case 'priority': case 'projection': case 'reproducibility': case 'resolution': case 'severity': case 'status': case 'view_state': $t_field = $reader->localName; $t_id = $reader->getAttribute('id'); $reader->read(); $t_value = $reader->value; // Here we assume ids have the same meaning in both installations // TODO add a check for customized values $this->newbug_->{$t_field} = $t_id; break; case 'id': $reader->read(); $this->old_id_ = $reader->value; break; case 'project': // ignore original value, use current project $this->newbug_->project_id = $t_project_id; break; case 'custom_fields': // store custom fields $i = -1; $depth_cf = $reader->depth; while ($reader->read() && ($reader->depth > $depth_cf || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { if ($reader->localName == 'custom_field') { $t_custom_fields[++$i] = new stdClass(); } switch ($reader->localName) { default: $field = $reader->localName; $reader->read(); $t_custom_fields[$i]->{$field} = $reader->value; } } } break; case 'bugnotes': // store bug notes $i = -1; $depth_bn = $reader->depth; while ($reader->read() && ($reader->depth > $depth_bn || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { if ($reader->localName == 'bugnote') { $t_bugnotes[++$i] = new stdClass(); } switch ($reader->localName) { case 'reporter': $t_old_id = $reader->getAttribute('id'); $reader->read(); $t_bugnotes[$i]->reporter_id = $this->get_user_id($reader->value, $userId); break; case 'view_state': $t_old_id = $reader->getAttribute('id'); $reader->read(); $t_bugnotes[$i]->private = $reader->value == VS_PRIVATE ? true : false; break; default: $field = $reader->localName; $reader->read(); $t_bugnotes[$i]->{$field} = $reader->value; } } } break; case 'attachments': // store attachments $i = -1; $depth_att = $reader->depth; while ($reader->read() && ($reader->depth > $depth_att || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { if ($reader->localName == 'attachment') { $t_attachments[++$i] = new stdClass(); } switch ($reader->localName) { default: $field = $reader->localName; $reader->read(); $t_attachments[$i]->{$field} = $reader->value; } } } break; default: $field = $reader->localName; //echo "using default handler for field: $field\n"; $reader->read(); $this->newbug_->{$field} = $reader->value; } } } // now save the new bug $this->new_id_ = $this->newbug_->create(); // add custom fields if ($this->new_id_ > 0 && is_array($t_custom_fields) && count($t_custom_fields) > 0) { foreach ($t_custom_fields as $t_custom_field) { $t_custom_field_id = custom_field_get_id_from_name($t_custom_field->name); if (custom_field_ensure_exists($t_custom_field_id) && custom_field_is_linked($t_custom_field_id, $t_project_id)) { custom_field_set_value($t_custom_field->id, $this->new_id_, $t_custom_field->value); } else { error_parameters($t_custom_field->name, $t_custom_field_id); trigger_error(ERROR_CUSTOM_FIELD_NOT_LINKED_TO_PROJECT, ERROR); } } } // add bugnotes if ($this->new_id_ > 0 && is_array($t_bugnotes) && count($t_bugnotes) > 0) { foreach ($t_bugnotes as $t_bugnote) { bugnote_add($this->new_id_, $t_bugnote->note, $t_bugnote->time_tracking, $t_bugnote->private, $t_bugnote->note_type, $t_bugnote->note_attr, $t_bugnote->reporter_id, false, $t_bugnote->date_submitted, $t_bugnote->last_modified, true); } } // add attachments if ($this->new_id_ > 0 && is_array($t_attachments) && count($t_attachments) > 0) { foreach ($t_attachments as $t_attachment) { // Create a temporary file in the temporary files directory using sys_get_temp_dir() $temp_file_name = tempnam(sys_get_temp_dir(), 'MantisImport'); file_put_contents($temp_file_name, base64_decode($t_attachment->content)); $file_data = array('name' => $t_attachment->filename, 'type' => $t_attachment->file_type, 'tmp_name' => $temp_file_name, 'size' => filesize($temp_file_name), 'error' => UPLOAD_ERR_OK); // unfortunately we have no clue who has added the attachment (this could only be fetched from history -> feel free to implement this) // also I have no clue where description should come from... file_add($this->new_id_, $file_data, 'bug', $t_attachment->title, $p_desc = '', $p_user_id = null, $t_attachment->date_added, true); unlink($temp_file_name); } } //echo "\nnew bug: $this->new_id_\n"; }
$writer->writeAttribute('id', $t_value); $writer->text($t_element_data); $writer->endElement(); break; default: $writer->writeElement($t_element, $t_value); } } # fetch and export custom fields $t_custom_fields = custom_field_get_all_linked_fields($t_row->id); if (is_array($t_custom_fields) && count($t_custom_fields) > 0) { $writer->startElement('custom_fields'); foreach ($t_custom_fields as $custom_field_name => $t_custom_field) { $writer->startElement('custom_field'); # id $writer->writeElement('id', custom_field_get_id_from_name($custom_field_name)); # title $writer->writeElement('name', $custom_field_name); # filename $writer->writeElement('type', $t_custom_field['type']); # filesize $writer->writeElement('value', $t_custom_field['value']); # file_type $writer->writeElement('access_level_r', $t_custom_field['access_level_r']); $writer->endElement(); # custom_field } $writer->endElement(); # custom_fields } # fetch and export bugnotes
/** * Print the value of the custom field (if the field is applicable to the project of * the specified issue and the current user has read access to it. * see custom_function_default_print_column_title() for rules about column names. * @param string $p_column Name of field to show in the column. * @param BugData $p_bug Bug object. * @param integer $p_columns_target See COLUMNS_TARGET_* in constant_inc.php. * @return void */ function custom_function_default_print_column_value($p_column, BugData $p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE) { if (COLUMNS_TARGET_CSV_PAGE == $p_columns_target) { $t_column_start = ''; $t_column_end = ''; $t_column_empty = ''; } else { $t_column_start = '<td class="column-%s">'; $t_column_end = '</td>'; $t_column_empty = ' '; } $t_custom_field = column_get_custom_field_name($p_column); if ($t_custom_field !== null) { printf($t_column_start, 'custom-' . $t_custom_field); $t_field_id = custom_field_get_id_from_name($t_custom_field); if ($t_field_id === false) { echo '@', $t_custom_field, '@'; } else { $t_issue_id = $p_bug->id; $t_project_id = $p_bug->project_id; if (custom_field_is_linked($t_field_id, $t_project_id)) { $t_def = custom_field_get_definition($t_field_id); print_custom_field_value($t_def, $t_field_id, $t_issue_id); } else { # field is not linked to project echo $t_column_empty; } } echo $t_column_end; } else { $t_plugin_columns = columns_get_plugin_columns(); if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) { $t_function = 'print_column_' . $p_column; } else { $t_function = 'csv_format_' . $p_column; } if (function_exists($t_function)) { if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) { $t_function($p_bug, $p_columns_target); } else { $t_function($p_bug); } } else { if (isset($t_plugin_columns[$p_column])) { $t_column_object = $t_plugin_columns[$p_column]; print_column_plugin($t_column_object, $p_bug, $p_columns_target); } else { printf($t_column_start, $p_column); if (isset($p_bug->{$p_column})) { echo string_display_line($p_bug->{$p_column}) . $t_column_end; } else { echo '@' . $p_column . '@' . $t_column_end; } } } } }
/** * Localizes one raw history item specified by set the next parameters: $p_field_name, $p_type, $p_old_value, $p_new_value * Returns array with two elements indexed as 'note' and 'change' * @param string $p_field_name The field name of the field being localized. * @param integer $p_type The type of the history entry. * @param string $p_old_value The old value of the field. * @param string $p_new_value The new value of the field. * @param boolean $p_linkify Whether to return a string containing hyperlinks. * @return array */ function history_localize_item($p_field_name, $p_type, $p_old_value, $p_new_value, $p_linkify = true) { $t_note = ''; $t_change = ''; $t_field_localized = $p_field_name; $t_raw = true; if (PLUGIN_HISTORY == $p_type) { $t_note = lang_get_defaulted('plugin_' . $p_field_name, $p_field_name); $t_change = isset($p_new_value) ? $p_old_value . ' => ' . $p_new_value : $p_old_value; return array('note' => $t_note, 'change' => $t_change, 'raw' => true); } switch ($p_field_name) { case 'category': $t_field_localized = lang_get('category'); break; case 'status': $p_old_value = get_enum_element('status', $p_old_value); $p_new_value = get_enum_element('status', $p_new_value); $t_field_localized = lang_get('status'); break; case 'severity': $p_old_value = get_enum_element('severity', $p_old_value); $p_new_value = get_enum_element('severity', $p_new_value); $t_field_localized = lang_get('severity'); break; case 'reproducibility': $p_old_value = get_enum_element('reproducibility', $p_old_value); $p_new_value = get_enum_element('reproducibility', $p_new_value); $t_field_localized = lang_get('reproducibility'); break; case 'resolution': $p_old_value = get_enum_element('resolution', $p_old_value); $p_new_value = get_enum_element('resolution', $p_new_value); $t_field_localized = lang_get('resolution'); break; case 'priority': $p_old_value = get_enum_element('priority', $p_old_value); $p_new_value = get_enum_element('priority', $p_new_value); $t_field_localized = lang_get('priority'); break; case 'eta': $p_old_value = get_enum_element('eta', $p_old_value); $p_new_value = get_enum_element('eta', $p_new_value); $t_field_localized = lang_get('eta'); break; case 'view_state': $p_old_value = get_enum_element('view_state', $p_old_value); $p_new_value = get_enum_element('view_state', $p_new_value); $t_field_localized = lang_get('view_status'); break; case 'projection': $p_old_value = get_enum_element('projection', $p_old_value); $p_new_value = get_enum_element('projection', $p_new_value); $t_field_localized = lang_get('projection'); break; case 'sticky': $p_old_value = gpc_string_to_bool($p_old_value) ? lang_get('yes') : lang_get('no'); $p_new_value = gpc_string_to_bool($p_new_value) ? lang_get('yes') : lang_get('no'); $t_field_localized = lang_get('sticky_issue'); break; case 'project_id': if (project_exists($p_old_value)) { $p_old_value = project_get_field($p_old_value, 'name'); } else { $p_old_value = '@' . $p_old_value . '@'; } # Note that the new value maybe an intermediately project and not the # current one. if (project_exists($p_new_value)) { $p_new_value = project_get_field($p_new_value, 'name'); } else { $p_new_value = '@' . $p_new_value . '@'; } $t_field_localized = lang_get('email_project'); break; case 'handler_id': $t_field_localized = lang_get('assigned_to'); case 'reporter_id': if ('reporter_id' == $p_field_name) { $t_field_localized = lang_get('reporter'); } if (0 == $p_old_value) { $p_old_value = ''; } else { $p_old_value = user_get_name($p_old_value); } if (0 == $p_new_value) { $p_new_value = ''; } else { $p_new_value = user_get_name($p_new_value); } break; case 'version': $t_field_localized = lang_get('product_version'); break; case 'fixed_in_version': $t_field_localized = lang_get('fixed_in_version'); break; case 'target_version': $t_field_localized = lang_get('target_version'); break; case 'date_submitted': $p_old_value = date(config_get('normal_date_format'), $p_old_value); $p_new_value = date(config_get('normal_date_format'), $p_new_value); $t_field_localized = lang_get('date_submitted'); break; case 'last_updated': $p_old_value = date(config_get('normal_date_format'), $p_old_value); $p_new_value = date(config_get('normal_date_format'), $p_new_value); $t_field_localized = lang_get('last_update'); break; case 'os': $t_field_localized = lang_get('os'); break; case 'os_build': $t_field_localized = lang_get('os_version'); break; case 'build': $t_field_localized = lang_get('build'); break; case 'platform': $t_field_localized = lang_get('platform'); break; case 'summary': $t_field_localized = lang_get('summary'); break; case 'duplicate_id': $t_field_localized = lang_get('duplicate_id'); break; case 'sponsorship_total': $t_field_localized = lang_get('sponsorship_total'); break; case 'due_date': if ($p_old_value !== '') { $p_old_value = date(config_get('normal_date_format'), (int) $p_old_value); } if ($p_new_value !== '') { $p_new_value = date(config_get('normal_date_format'), (int) $p_new_value); } $t_field_localized = lang_get('due_date'); break; default: # assume it's a custom field name $t_field_id = custom_field_get_id_from_name($p_field_name); if (false !== $t_field_id) { $t_cf_type = custom_field_type($t_field_id); if ('' != $p_old_value) { $p_old_value = string_custom_field_value_for_email($p_old_value, $t_cf_type); } $p_new_value = string_custom_field_value_for_email($p_new_value, $t_cf_type); $t_field_localized = lang_get_defaulted($p_field_name); } } if (NORMAL_TYPE != $p_type) { switch ($p_type) { case NEW_BUG: $t_note = lang_get('new_bug'); break; case BUGNOTE_ADDED: $t_note = lang_get('bugnote_added') . ': ' . $p_old_value; break; case BUGNOTE_UPDATED: $t_note = lang_get('bugnote_edited') . ': ' . $p_old_value; $t_old_value = (int) $p_old_value; $t_new_value = (int) $p_new_value; if ($p_linkify && bug_revision_exists($t_new_value)) { if (bugnote_exists($t_old_value)) { $t_bug_revision_view_page_argument = 'bugnote_id=' . $t_old_value . '#r' . $t_new_value; } else { $t_bug_revision_view_page_argument = 'rev_id=' . $t_new_value; } $t_change = '<a href="bug_revision_view_page.php?' . $t_bug_revision_view_page_argument . '">' . lang_get('view_revisions') . '</a>'; $t_raw = false; } break; case BUGNOTE_DELETED: $t_note = lang_get('bugnote_deleted') . ': ' . $p_old_value; break; case DESCRIPTION_UPDATED: $t_note = lang_get('description_updated'); $t_old_value = (int) $p_old_value; if ($p_linkify && bug_revision_exists($t_old_value)) { $t_change = '<a href="bug_revision_view_page.php?rev_id=' . $t_old_value . '#r' . $t_old_value . '">' . lang_get('view_revisions') . '</a>'; $t_raw = false; } break; case ADDITIONAL_INFO_UPDATED: $t_note = lang_get('additional_information_updated'); $t_old_value = (int) $p_old_value; if ($p_linkify && bug_revision_exists($t_old_value)) { $t_change = '<a href="bug_revision_view_page.php?rev_id=' . $t_old_value . '#r' . $t_old_value . '">' . lang_get('view_revisions') . '</a>'; $t_raw = false; } break; case STEP_TO_REPRODUCE_UPDATED: $t_note = lang_get('steps_to_reproduce_updated'); $t_old_value = (int) $p_old_value; if ($p_linkify && bug_revision_exists($t_old_value)) { $t_change = '<a href="bug_revision_view_page.php?rev_id=' . $t_old_value . '#r' . $t_old_value . '">' . lang_get('view_revisions') . '</a>'; $t_raw = false; } break; case FILE_ADDED: $t_note = lang_get('file_added') . ': ' . $p_old_value; break; case FILE_DELETED: $t_note = lang_get('file_deleted') . ': ' . $p_old_value; break; case BUGNOTE_STATE_CHANGED: $p_old_value = get_enum_element('view_state', $p_old_value); $t_note = lang_get('bugnote_view_state') . ': ' . $p_new_value . ': ' . $p_old_value; break; case BUG_MONITOR: $p_old_value = user_get_name($p_old_value); $t_note = lang_get('bug_monitor') . ': ' . $p_old_value; break; case BUG_UNMONITOR: if ($p_old_value !== '') { $p_old_value = user_get_name($p_old_value); } $t_note = lang_get('bug_end_monitor') . ': ' . $p_old_value; break; case BUG_DELETED: $t_note = lang_get('bug_deleted') . ': ' . $p_old_value; break; case BUG_ADD_SPONSORSHIP: $t_note = lang_get('sponsorship_added'); $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value); break; case BUG_UPDATE_SPONSORSHIP: $t_note = lang_get('sponsorship_updated'); $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value); break; case BUG_DELETE_SPONSORSHIP: $t_note = lang_get('sponsorship_deleted'); $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value); break; case BUG_PAID_SPONSORSHIP: $t_note = lang_get('sponsorship_paid'); $t_change = user_get_name($p_old_value) . ': ' . get_enum_element('sponsorship', $p_new_value); break; case BUG_ADD_RELATIONSHIP: $t_note = lang_get('relationship_added'); $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value); break; case BUG_REPLACE_RELATIONSHIP: $t_note = lang_get('relationship_replaced'); $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value); break; case BUG_DEL_RELATIONSHIP: $t_note = lang_get('relationship_deleted'); # Fix for #7846: There are some cases where old value is empty, this may be due to an old bug. if (!is_blank($p_old_value) && $p_old_value > 0) { $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value); } else { $t_change = bug_format_id($p_new_value); } break; case BUG_CLONED_TO: $t_note = lang_get('bug_cloned_to') . ': ' . bug_format_id($p_new_value); break; case BUG_CREATED_FROM: $t_note = lang_get('bug_created_from') . ': ' . bug_format_id($p_new_value); break; case TAG_ATTACHED: $t_note = lang_get('tag_history_attached') . ': ' . $p_old_value; break; case TAG_DETACHED: $t_note = lang_get('tag_history_detached') . ': ' . $p_old_value; break; case TAG_RENAMED: $t_note = lang_get('tag_history_renamed'); $t_change = $p_old_value . ' => ' . $p_new_value; break; case BUG_REVISION_DROPPED: $t_note = lang_get('bug_revision_dropped_history') . ': ' . bug_revision_get_type_name($p_new_value) . ': ' . $p_old_value; break; case BUGNOTE_REVISION_DROPPED: $t_note = lang_get('bugnote_revision_dropped_history') . ': ' . $p_new_value . ': ' . $p_old_value; break; } } # output special cases if (NORMAL_TYPE == $p_type) { $t_note = $t_field_localized; $t_change = $p_old_value . ' => ' . $p_new_value; } # end if DEFAULT return array('note' => $t_note, 'change' => $t_change, 'raw' => $t_raw); }
/** * Get all issue rows matching the custom filter. * * @param integer $p_user_id The user id. * @param FilterSearchData $p_filter_search The custom filter. * @param integer $p_page_number Start with the given page number (zero-based). * @param integer $p_per_page Number of issues to display per page. * @return array of issue rows */ function mci_filter_search_get_rows($p_user_id, $p_filter_search, $p_page_number, $p_per_page) { global $g_soap_api_to_filter_names; // object to array if (is_object($p_filter_search)) { $p_filter_search = get_object_vars($p_filter_search); } $t_project_id = array(); if (isset($p_filter_search['project_id'])) { // check access right to all projects foreach ($p_filter_search['project_id'] as $t_id) { if (mci_has_readonly_access($p_user_id, $t_id)) { $t_project_id[] = $t_id; } else { error_log('User: '******' has not access right to project: ' . $t_id . '.'); } } // user has not access right to any project if (count($t_project_id) < 1) { return mci_soap_fault_access_denied($p_user_id); } } else { if (!mci_has_readonly_access($p_user_id, ALL_PROJECTS)) { return mci_soap_fault_access_denied($p_user_id); } $t_project_id = array(ALL_PROJECTS); } $t_filter = array('_view_type' => 'advanced'); $t_filter['project_id'] = $t_project_id; // default fields foreach ($g_soap_api_to_filter_names as $t_soap_name => $t_filter_name) { if (isset($p_filter_search[$t_soap_name])) { $t_value = $p_filter_search[$t_soap_name]; $t_filter[$t_filter_name] = $t_value; } } // custom fields if (isset($p_filter_search['custom_fields'])) { foreach ($p_filter_search['custom_fields'] as $t_custom_field) { // object to array if (is_object($t_custom_field)) { $t_custom_field = get_object_vars($t_custom_field); } $t_field = $t_custom_field['field']; if (is_object($t_field)) { $t_field = get_object_vars($t_field); } // if is set custom_field's id, use it primary if (isset($t_field['id'])) { $t_custom_field_id = $t_field['id']; } else { $t_custom_field_id = custom_field_get_id_from_name($t_field['name']); } $t_value = $t_custom_field['value']; $t_filter['custom_fields'][$t_custom_field_id] = $t_value; } } $t_filter = filter_ensure_valid_filter($t_filter); $t_result = array(); $t_page_number = $p_page_number < 1 ? 1 : $p_page_number; $t_page_count = 0; $t_bug_count = 0; return filter_get_bug_rows($t_page_number, $p_per_page, $t_page_count, $t_bug_count, $t_filter); }
/** * Add sort parameters to the query clauses * @param array $p_filter * @param bool $p_show_sticky * @param array $p_query_clauses * @return array $p_query_clauses */ function filter_get_query_sort_data(&$p_filter, $p_show_sticky, $p_query_clauses) { $t_bug_table = db_get_table('bug'); $t_custom_field_string_table = db_get_table('custom_field_string'); # if sort is blank then default the sort and direction. This is to fix the # symptoms of #3953. Note that even if the main problem is fixed, we may # have to keep this code for a while to handle filters saved with this blank field. if (is_blank($p_filter[FILTER_PROPERTY_SORT_FIELD_NAME])) { $p_filter[FILTER_PROPERTY_SORT_FIELD_NAME] = 'last_updated'; $p_filter[FILTER_PROPERTY_SORT_DIRECTION] = 'DESC'; } $p_query_clauses['order'] = array(); $t_sort_fields = explode(',', $p_filter[FILTER_PROPERTY_SORT_FIELD_NAME]); $t_dir_fields = explode(',', $p_filter[FILTER_PROPERTY_SORT_DIRECTION]); $t_plugin_columns = columns_get_plugin_columns(); if (gpc_string_to_bool($p_filter[FILTER_PROPERTY_STICKY]) && NULL !== $p_show_sticky) { $p_query_clauses['order'][] = "{$t_bug_table}.sticky DESC"; } $t_count = count($t_sort_fields); for ($i = 0; $i < $t_count; $i++) { $c_sort = db_prepare_string($t_sort_fields[$i]); $c_dir = 'DESC' == $t_dir_fields[$i] ? 'DESC' : 'ASC'; if (!in_array($t_sort_fields[$i], array_slice($t_sort_fields, $i + 1))) { # if sorting by a custom field if (strpos($c_sort, 'custom_') === 0) { $t_custom_field = utf8_substr($c_sort, utf8_strlen('custom_')); $t_custom_field_id = custom_field_get_id_from_name($t_custom_field); $t_def = custom_field_get_definition($t_custom_field_id); $t_value_field = $t_def['type'] == CUSTOM_FIELD_TYPE_TEXTAREA ? 'text' : 'value'; $c_cf_alias = 'custom_field_' . $t_custom_field_id; $t_cf_table_alias = $t_custom_field_string_table . '_' . $t_custom_field_id; $t_cf_select = "{$t_cf_table_alias}.{$t_value_field} {$c_cf_alias}"; # check to be sure this field wasn't already added to the query. if (!in_array($t_cf_select, $p_query_clauses['select'])) { $p_query_clauses['select'][] = $t_cf_select; $p_query_clauses['join'][] = "LEFT JOIN {$t_custom_field_string_table} {$t_cf_table_alias} ON {$t_bug_table}.id = {$t_cf_table_alias}.bug_id AND {$t_cf_table_alias}.field_id = {$t_custom_field_id}"; } $p_query_clauses['order'][] = "{$c_cf_alias} {$c_dir}"; # if sorting by plugin columns } else { if (isset($t_plugin_columns[$t_sort_fields[$i]])) { $t_column_object = $t_plugin_columns[$t_sort_fields[$i]]; if ($t_column_object->sortable) { $t_clauses = $t_column_object->sortquery($c_dir); if (is_array($t_clauses)) { if (isset($t_clauses['join'])) { $p_query_clauses['join'][] = $t_clauses['join']; } if (isset($t_clauses['order'])) { $p_query_clauses['order'][] = $t_clauses['order']; } } } # standard column } else { if ('last_updated' == $c_sort) { $c_sort = "last_updated"; } $p_query_clauses['order'][] = "{$t_bug_table}.{$c_sort} {$c_dir}"; } } } } # add basic sorting if necessary if (!in_array('last_updated', $t_sort_fields)) { $p_query_clauses['order'][] = "{$t_bug_table}.last_updated DESC"; } if (!in_array('date_submitted', $t_sort_fields)) { $p_query_clauses['order'][] = "{$t_bug_table}.date_submitted DESC"; } return $p_query_clauses; }
function removeCustomField($p_field_name) { $t_field_id = custom_field_get_id_from_name($p_field_name); $t_projects = project_get_all_rows(); foreach ($t_projects as $t_row) { custom_field_unlink($t_field_id, $t_row['id']); } }
function custom_function_default_print_column_value($p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE) { if (COLUMNS_TARGET_CSV_PAGE == $p_columns_target) { $t_column_start = ''; $t_column_end = ''; $t_column_empty = ''; } else { $t_column_start = '<td>'; $t_column_end = '</td>'; $t_column_empty = ' '; } if (strpos($p_column, 'custom_') === 0) { echo $t_column_start; $t_custom_field = substr($p_column, 7); $t_field_id = custom_field_get_id_from_name($t_custom_field); if ($t_field_id === false) { echo '@', $t_custom_field, '@'; } else { $t_issue_id = $p_issue_row['id']; $t_project_id = $p_issue_row['project_id']; if (custom_field_is_linked($t_field_id, $t_project_id)) { $t_def = custom_field_get_definition($t_field_id); print_custom_field_value($t_def, $t_field_id, $t_issue_id); } else { // field is not linked to project echo $t_column_empty; } } echo $t_column_end; } else { if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) { $t_function = 'print_column_' . $p_column; } else { $t_function = 'csv_format_' . $p_column; } if (function_exists($t_function)) { if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) { $t_function($p_issue_row, $p_columns_target); } else { $t_function($p_issue_row[$p_column]); } } else { if (isset($p_issue_row[$p_column])) { echo $t_column_start . $p_issue_row[$p_column] . $t_column_end; } else { echo $t_column_start . '@' . $p_column . '@' . $t_column_end; } } } }
function filter_ensure_valid_filter($p_filter_arr) { # extend current filter to add information passed via POST if (!isset($p_filter_arr['_version'])) { $p_filter_arr['_version'] = config_get('cookie_version'); } $t_cookie_vers = (int) substr($p_filter_arr['_version'], 1); if (substr(config_get('cookie_version'), 1) > $t_cookie_vers) { # if the version is old, update it $p_filter_arr['_version'] = config_get('cookie_version'); } if (!isset($p_filter_arr['_view_type'])) { $p_filter_arr['_view_type'] = gpc_get_string('view_type', 'simple'); } if (!isset($p_filter_arr['per_page'])) { $p_filter_arr['per_page'] = gpc_get_int('per_page', config_get('default_limit_view')); } if (!isset($p_filter_arr['highlight_changed'])) { $p_filter_arr['highlight_changed'] = config_get('default_show_changed'); } if (!isset($p_filter_arr['sticky_issues'])) { $p_filter_arr['sticky_issues'] = config_get('show_sticky_issues'); } if (!isset($p_filter_arr['sort'])) { $p_filter_arr['sort'] = "last_updated"; } if (!isset($p_filter_arr['dir'])) { $p_filter_arr['dir'] = "DESC"; } if (!isset($p_filter_arr['platform'])) { $p_filter_arr['platform'] = array(0 => META_FILTER_ANY); } if (!isset($p_filter_arr['os'])) { $p_filter_arr['os'] = array(0 => META_FILTER_ANY); } if (!isset($p_filter_arr['os_build'])) { $p_filter_arr['os_build'] = array(0 => META_FILTER_ANY); } if (!isset($p_filter_arr['project_id'])) { $p_filter_arr['project_id'] = array(0 => META_FILTER_CURRENT); } if (!isset($p_filter_arr['start_month'])) { $p_filter_arr['start_month'] = gpc_get_string('start_month', date('m')); } if (!isset($p_filter_arr['start_day'])) { $p_filter_arr['start_day'] = gpc_get_string('start_day', 1); } if (!isset($p_filter_arr['start_year'])) { $p_filter_arr['start_year'] = gpc_get_string('start_year', date('Y')); } if (!isset($p_filter_arr['end_month'])) { $p_filter_arr['end_month'] = gpc_get_string('end_month', date('m')); } if (!isset($p_filter_arr['end_day'])) { $p_filter_arr['end_day'] = gpc_get_string('end_day', date('d')); } if (!isset($p_filter_arr['end_year'])) { $p_filter_arr['end_year'] = gpc_get_string('end_year', date('Y')); } if (!isset($p_filter_arr['search'])) { $p_filter_arr['search'] = ''; } if (!isset($p_filter_arr['and_not_assigned'])) { $p_filter_arr['and_not_assigned'] = gpc_get_bool('and_not_assigned', false); } if (!isset($p_filter_arr['do_filter_by_date'])) { $p_filter_arr['do_filter_by_date'] = gpc_get_bool('do_filter_by_date', false); } if (!isset($p_filter_arr['view_state'])) { $p_filter_arr['view_state'] = gpc_get('view_state', ''); } else { if ($p_filter_arr['view_state'] == 'any' || $p_filter_arr['view_state'] == 0) { $p_filter_arr['view_state'] = META_FILTER_ANY; } } if (!isset($p_filter_arr['relationship_type'])) { $p_filter_arr['relationship_type'] = gpc_get_int('relationship_type', -1); } if (!isset($p_filter_arr['relationship_bug'])) { $p_filter_arr['relationship_bug'] = gpc_get_int('relationship_bug', 0); } if (!isset($p_filter_arr['target_version'])) { $p_filter_arr['target_version'] = META_FILTER_ANY; } if (!isset($p_filter_arr['tag_string'])) { $p_filter_arr['tag_string'] = gpc_get_string('tag_string', ''); } if (!isset($p_filter_arr['tag_select'])) { $p_filter_arr['tag_select'] = gpc_get_string('tag_select', ''); } $t_custom_fields = custom_field_get_ids(); # @@@ (thraxisp) This should really be the linked ids, but we don't know the project $f_custom_fields_data = array(); if (is_array($t_custom_fields) && sizeof($t_custom_fields) > 0) { foreach ($t_custom_fields as $t_cfid) { if (is_array(gpc_get('custom_field_' . $t_cfid, null))) { $f_custom_fields_data[$t_cfid] = gpc_get_string_array('custom_field_' . $t_cfid, META_FILTER_ANY); } else { $f_custom_fields_data[$t_cfid] = gpc_get_string('custom_field_' . $t_cfid, META_FILTER_ANY); $f_custom_fields_data[$t_cfid] = array($f_custom_fields_data[$t_cfid]); } } } #validate sorting $t_fields = helper_get_columns_to_view(); $t_n_fields = count($t_fields); for ($i = 0; $i < $t_n_fields; $i++) { if (isset($t_fields[$i]) && in_array($t_fields[$i], array('selection', 'edit', 'bugnotes_count', 'attachment'))) { unset($t_fields[$i]); } } $t_sort_fields = split(',', $p_filter_arr['sort']); $t_dir_fields = split(',', $p_filter_arr['dir']); for ($i = 0; $i < 2; $i++) { if (isset($t_sort_fields[$i])) { $t_drop = false; $t_sort = $t_sort_fields[$i]; if (strpos($t_sort, 'custom_') === 0) { if (false === custom_field_get_id_from_name(substr($t_sort, strlen('custom_')))) { $t_drop = true; } } else { if (!in_array($t_sort, $t_fields)) { $t_drop = true; } } if (!in_array($t_dir_fields[$i], array("ASC", "DESC"))) { $t_drop = true; } if ($t_drop) { unset($t_sort_fields[$i]); unset($t_dir_fields[$i]); } } } if (count($t_sort_fields) > 0) { $p_filter_arr['sort'] = implode(',', $t_sort_fields); $p_filter_arr['dir'] = implode(',', $t_dir_fields); } else { $p_filter_arr['sort'] = "last_updated"; $p_filter_arr['dir'] = "DESC"; } # validate or filter junk from other fields $t_multi_select_list = array('show_category' => 'string', 'show_severity' => 'int', 'show_status' => 'int', 'reporter_id' => 'int', 'handler_id' => 'int', 'show_resolution' => 'int', 'show_priority' => 'int', 'show_build' => 'string', 'show_version' => 'string', 'hide_status' => 'int', 'fixed_in_version' => 'string', 'target_version' => 'string', 'user_monitor' => 'int', 'show_profile' => 'int'); foreach ($t_multi_select_list as $t_multi_field_name => $t_multi_field_type) { if (!isset($p_filter_arr[$t_multi_field_name])) { if ('hide_status' == $t_multi_field_name) { $p_filter_arr[$t_multi_field_name] = array(config_get('hide_status_default')); } else { if ('custom_fields' == $t_multi_field_name) { $p_filter_arr[$t_multi_field_name] = array($f_custom_fields_data); } else { $p_filter_arr[$t_multi_field_name] = array(META_FILTER_ANY); } } } else { if (!is_array($p_filter_arr[$t_multi_field_name])) { $p_filter_arr[$t_multi_field_name] = array($p_filter_arr[$t_multi_field_name]); } $t_checked_array = array(); foreach ($p_filter_arr[$t_multi_field_name] as $t_filter_value) { $t_filter_value = stripslashes($t_filter_value); if ($t_filter_value === 'any' || $t_filter_value === '[any]') { $t_filter_value = META_FILTER_ANY; } if ($t_filter_value === 'none' || $t_filter_value === '[none]') { $t_filter_value = META_FILTER_NONE; } if ('string' == $t_multi_field_type) { $t_checked_array[] = db_prepare_string($t_filter_value); } else { if ('int' == $t_multi_field_type) { $t_checked_array[] = db_prepare_int($t_filter_value); } else { if ('array' == $t_multi_field_type) { $t_checked_array[] = $t_filter_value; } } } } $p_filter_arr[$t_multi_field_name] = $t_checked_array; } } if (is_array($t_custom_fields) && sizeof($t_custom_fields) > 0) { foreach ($t_custom_fields as $t_cfid) { if (!isset($p_filter_arr['custom_fields'][$t_cfid])) { $p_filter_arr['custom_fields'][$t_cfid] = array(META_FILTER_ANY); } else { if (!is_array($p_filter_arr['custom_fields'][$t_cfid])) { $p_filter_arr['custom_fields'][$t_cfid] = array($p_filter_arr['custom_fields'][$t_cfid]); } $t_checked_array = array(); foreach ($p_filter_arr['custom_fields'][$t_cfid] as $t_filter_value) { $t_filter_value = stripslashes($t_filter_value); if ($t_filter_value === 'any' || $t_filter_value === '[any]') { $t_filter_value = META_FILTER_ANY; } $t_checked_array[] = db_prepare_string($t_filter_value); } $p_filter_arr['custom_fields'][$t_cfid] = $t_checked_array; } } } # all of our filter values are now guaranteed to be there, and correct. return $p_filter_arr; }
function custom_function_override_print_column_value($p_column, $p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE) { if (COLUMNS_TARGET_CSV_PAGE == $p_columns_target) { $t_column_start = ''; $t_column_end = ''; $t_column_empty = ''; } else { $t_column_start = '<td class="center">'; $t_column_end = '</td>'; $t_column_empty = ' '; } $t_custom_field = column_get_custom_field_name($p_column); if ($t_custom_field !== null) { echo $t_column_start; $t_field_id = custom_field_get_id_from_name($t_custom_field); if ($t_field_id === false) { echo '@', $t_custom_field, '@'; } else { $t_issue_id = $p_bug->id; $t_project_id = $p_bug->project_id; if (custom_field_is_linked($t_field_id, $t_project_id)) { $t_def = custom_field_get_definition($t_field_id); if (strpos($p_column, 'custom_Deadline') === 0 && $t_def['type'] == CUSTOM_FIELD_TYPE_DATE) { $deadline_date = custom_field_get_value($t_field_id, $t_issue_id); if ($p_issue_row['status'] < 80) { $current_date = strtotime(date("Y-m-d")); if ($current_date >= $deadline_date) { echo '<b><font color="red">'; print_custom_field_value($t_def, $t_field_id, $t_issue_id); echo '</font></b>'; } else { print_custom_field_value($t_def, $t_field_id, $t_issue_id); } } elseif ($deadline_date) { if (lang_get_current() == 'german') { echo '<b>ERLEDIGT!</b>'; } else { echo '<b>DONE!</b>'; } } } else { print_custom_field_value($t_def, $t_field_id, $t_issue_id); } } else { // field is not linked to project echo $t_column_empty; } } echo $t_column_end; } else { $t_plugin_columns = columns_get_plugin_columns(); if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) { if ($p_column == 'summary') { $t_function = 'print_column_summary_BFE'; } else { $t_function = 'print_column_' . $p_column; } } else { $t_function = 'csv_format_' . $p_column; } if (function_exists($t_function)) { if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) { $t_function($p_bug, $p_columns_target); } else { $t_function($p_bug); } } else { if (isset($t_plugin_columns[$p_column])) { $t_column_object = $t_plugin_columns[$p_column]; print_column_plugin($t_column_object, $p_bug, $p_columns_target); } else { if (isset($p_bug->{$p_column})) { echo $t_column_start . string_display_line($p_bug->{$p_column}) . $t_column_end; } else { echo $t_column_start . '@' . $p_column . '@' . $t_column_end; } } } } }
/** * Gets the formatted value for the specified issue id, project and custom field. * @param integer $p_issue_id The issue id. * @param integer $p_project_id The project id. * @param string $p_custom_field The custom field name (without 'custom_' prefix). * @return string The custom field value. */ function excel_format_custom_field($p_issue_id, $p_project_id, $p_custom_field) { $t_field_id = custom_field_get_id_from_name($p_custom_field); if ($t_field_id === false) { return excel_prepare_string('@' . $p_custom_field . '@'); } if (custom_field_is_linked($t_field_id, $p_project_id)) { $t_def = custom_field_get_definition($t_field_id); if ($t_def['type'] == CUSTOM_FIELD_TYPE_NUMERIC) { return excel_prepare_number(string_custom_field_value($t_def, $t_field_id, $p_issue_id)); } return excel_prepare_string(string_custom_field_value($t_def, $t_field_id, $p_issue_id)); } # field is not linked to project return excel_prepare_string(''); }
function history_localize_item($p_field_name, $p_type, $p_old_value, $p_new_value) { $t_note = ''; $t_change = ''; $t_field_localized = $p_field_name; switch ($p_field_name) { case 'category': $t_field_localized = lang_get('category'); break; case 'status': $p_old_value = get_enum_element('status', $p_old_value); $p_new_value = get_enum_element('status', $p_new_value); $t_field_localized = lang_get('status'); break; case 'severity': $p_old_value = get_enum_element('severity', $p_old_value); $p_new_value = get_enum_element('severity', $p_new_value); $t_field_localized = lang_get('severity'); break; case 'reproducibility': $p_old_value = get_enum_element('reproducibility', $p_old_value); $p_new_value = get_enum_element('reproducibility', $p_new_value); $t_field_localized = lang_get('reproducibility'); break; case 'resolution': $p_old_value = get_enum_element('resolution', $p_old_value); $p_new_value = get_enum_element('resolution', $p_new_value); $t_field_localized = lang_get('resolution'); break; case 'priority': $p_old_value = get_enum_element('priority', $p_old_value); $p_new_value = get_enum_element('priority', $p_new_value); $t_field_localized = lang_get('priority'); break; case 'eta': $p_old_value = get_enum_element('eta', $p_old_value); $p_new_value = get_enum_element('eta', $p_new_value); $t_field_localized = lang_get('eta'); break; case 'view_state': $p_old_value = get_enum_element('view_state', $p_old_value); $p_new_value = get_enum_element('view_state', $p_new_value); $t_field_localized = lang_get('view_status'); break; case 'projection': $p_old_value = get_enum_element('projection', $p_old_value); $p_new_value = get_enum_element('projection', $p_new_value); $t_field_localized = lang_get('projection'); break; case 'sticky': $p_old_value = gpc_string_to_bool($p_old_value) ? lang_get('yes') : lang_get('no'); $p_new_value = gpc_string_to_bool($p_new_value) ? lang_get('yes') : lang_get('no'); $t_field_localized = lang_get('sticky_issue'); break; case 'project_id': if (project_exists($p_old_value)) { $p_old_value = project_get_field($p_old_value, 'name'); } else { $p_old_value = '@' . $p_old_value . '@'; } # Note that the new value maybe an intermediately project and not the # current one. if (project_exists($p_new_value)) { $p_new_value = project_get_field($p_new_value, 'name'); } else { $p_new_value = '@' . $p_new_value . '@'; } $t_field_localized = lang_get('email_project'); break; case 'handler_id': $t_field_localized = lang_get('assigned_to'); case 'reporter_id': if ('reporter_id' == $p_field_name) { $t_field_localized = lang_get('reporter'); } if (0 == $p_old_value) { $p_old_value = ''; } else { $p_old_value = user_get_name($p_old_value); } if (0 == $p_new_value) { $p_new_value = ''; } else { $p_new_value = user_get_name($p_new_value); } break; case 'fixed_in_version': $t_field_localized = lang_get('fixed_in_version'); break; case 'date_submitted': $t_field_localized = lang_get('date_submitted'); break; case 'last_updated': $t_field_localized = lang_get('last_update'); break; case 'summary': $t_field_localized = lang_get('summary'); break; case 'duplicate_id': $t_field_localized = lang_get('duplicate_id'); break; case 'sponsorship_total': $t_field_localized = lang_get('sponsorship_total'); break; default: # assume it's a custom field name $t_field_id = custom_field_get_id_from_name($p_field_name); if (false !== $t_field_id) { $t_cf_type = custom_field_type($t_field_id); if ('' != $p_old_value) { $p_old_value = string_custom_field_value_for_email($p_old_value, $t_cf_type); } $p_new_value = string_custom_field_value_for_email($p_new_value, $t_cf_type); } } if (NORMAL_TYPE != $p_type) { switch ($p_type) { case NEW_BUG: $t_note = lang_get('new_bug'); break; case BUGNOTE_ADDED: $t_note = lang_get('bugnote_added') . ": " . $p_old_value; break; case BUGNOTE_UPDATED: $t_note = lang_get('bugnote_edited') . ": " . $p_old_value; break; case BUGNOTE_DELETED: $t_note = lang_get('bugnote_deleted') . ": " . $p_old_value; break; case DESCRIPTION_UPDATED: $t_note = lang_get('description_updated'); break; case ADDITIONAL_INFO_UPDATED: $t_note = lang_get('additional_information_updated'); break; case STEP_TO_REPRODUCE_UPDATED: $t_note = lang_get('steps_to_reproduce_updated'); break; case FILE_ADDED: $t_note = lang_get('file_added') . ": " . $p_old_value; break; case FILE_DELETED: $t_note = lang_get('file_deleted') . ": " . $p_old_value; break; case BUGNOTE_STATE_CHANGED: $p_old_value = get_enum_element('view_state', $p_old_value); $t_note = lang_get('bugnote_view_state') . ": " . $p_old_value . ": " . $p_new_value; break; case BUG_MONITOR: $p_old_value = user_get_name($p_old_value); $t_note = lang_get('bug_monitor') . ": " . $p_old_value; break; case BUG_UNMONITOR: $p_old_value = user_get_name($p_old_value); $t_note = lang_get('bug_end_monitor') . ": " . $p_old_value; break; case BUG_DELETED: $t_note = lang_get('bug_deleted') . ": " . $p_old_value; break; case BUG_ADD_SPONSORSHIP: $t_note = lang_get('sponsorship_added'); $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value); break; case BUG_UPDATE_SPONSORSHIP: $t_note = lang_get('sponsorship_updated'); $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value); break; case BUG_DELETE_SPONSORSHIP: $t_note = lang_get('sponsorship_deleted'); $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value); break; case BUG_PAID_SPONSORSHIP: $t_note = lang_get('sponsorship_paid'); $t_change = user_get_name($p_old_value) . ': ' . get_enum_element('sponsorship', $p_new_value); break; case BUG_ADD_RELATIONSHIP: $t_note = lang_get('relationship_added'); $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value); break; case BUG_REPLACE_RELATIONSHIP: $t_note = lang_get('relationship_replaced'); $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value); break; case BUG_DEL_RELATIONSHIP: $t_note = lang_get('relationship_deleted'); $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value); break; case BUG_CLONED_TO: $t_note = lang_get('bug_cloned_to'); $t_change = bug_format_id($p_new_value); break; case BUG_CREATED_FROM: $t_note = lang_get('bug_created_from'); $t_change = bug_format_id($p_new_value); break; case CHECKIN: $t_note = lang_get('checkin'); break; } } # output special cases if (NORMAL_TYPE == $p_type) { $t_note = $t_field_localized; $t_change = $p_old_value . ' => ' . $p_new_value; } # end if DEFAULT return array('note' => $t_note, 'change' => $t_change); }
/** * Add sort parameters to the query clauses * @param array &$p_filter Filter to sort. * @param boolean $p_show_sticky Whether to show sticky items. * @param array $p_query_clauses Array of query clauses. * @return array $p_query_clauses */ function filter_get_query_sort_data(array &$p_filter, $p_show_sticky, array $p_query_clauses) { # if sort is blank then default the sort and direction. This is to fix the # symptoms of #3953. Note that even if the main problem is fixed, we may # have to keep this code for a while to handle filters saved with this blank field. if (is_blank($p_filter[FILTER_PROPERTY_SORT_FIELD_NAME])) { $p_filter[FILTER_PROPERTY_SORT_FIELD_NAME] = 'last_updated'; $p_filter[FILTER_PROPERTY_SORT_DIRECTION] = 'DESC'; } $p_query_clauses['order'] = array(); $t_sort_fields = explode(',', $p_filter[FILTER_PROPERTY_SORT_FIELD_NAME]); $t_dir_fields = explode(',', $p_filter[FILTER_PROPERTY_SORT_DIRECTION]); $t_plugin_columns = columns_get_plugin_columns(); if (gpc_string_to_bool($p_filter[FILTER_PROPERTY_STICKY]) && null !== $p_show_sticky) { $p_query_clauses['order'][] = '{bug}.sticky DESC'; } $t_count = count($t_sort_fields); for ($i = 0; $i < $t_count; $i++) { $c_sort = $t_sort_fields[$i]; $c_dir = 'DESC' == $t_dir_fields[$i] ? 'DESC' : 'ASC'; if (!in_array($t_sort_fields[$i], array_slice($t_sort_fields, $i + 1))) { # if sorting by a custom field if (strpos($c_sort, 'custom_') === 0) { $t_custom_field = utf8_substr($c_sort, utf8_strlen('custom_')); $t_custom_field_id = custom_field_get_id_from_name($t_custom_field); $t_def = custom_field_get_definition($t_custom_field_id); $t_value_field = $t_def['type'] == CUSTOM_FIELD_TYPE_TEXTAREA ? 'text' : 'value'; $c_cf_alias = 'custom_field_' . $t_custom_field_id; # Distinguish filter table aliases from sort table aliases (see #19670) $t_cf_table_alias = 'cf_sort_' . $t_custom_field_id; $t_cf_select = $t_cf_table_alias . '.' . $t_value_field . ' ' . $c_cf_alias; # check to be sure this field wasn't already added to the query. if (!in_array($t_cf_select, $p_query_clauses['select'])) { $p_query_clauses['select'][] = $t_cf_select; $p_query_clauses['join'][] = 'LEFT JOIN {custom_field_string} ' . $t_cf_table_alias . ' ON {bug}.id = ' . $t_cf_table_alias . '.bug_id AND ' . $t_cf_table_alias . '.field_id = ' . $t_custom_field_id; } $p_query_clauses['order'][] = $c_cf_alias . ' ' . $c_dir; # if sorting by plugin columns } else { if (isset($t_plugin_columns[$t_sort_fields[$i]])) { $t_column_object = $t_plugin_columns[$t_sort_fields[$i]]; if ($t_column_object->sortable) { $t_clauses = $t_column_object->sortquery($c_dir); if (is_array($t_clauses)) { if (isset($t_clauses['join'])) { $p_query_clauses['join'][] = $t_clauses['join']; } if (isset($t_clauses['order'])) { $p_query_clauses['order'][] = $t_clauses['order']; } } } # standard column } else { $t_sort_col = '{bug}.' . $c_sort; # when sorting by due_date, always display undefined dates last if ('due_date' == $c_sort && 'ASC' == $c_dir) { $t_sort_due_date = $t_sort_col . ' = 1'; $p_query_clauses['select'][] = $t_sort_due_date; $t_sort_col = $t_sort_due_date . ', ' . $t_sort_col; } $p_query_clauses['order'][] = $t_sort_col . ' ' . $c_dir; } } } } # add basic sorting if necessary if (!in_array('last_updated', $t_sort_fields)) { $p_query_clauses['order'][] = '{bug}.last_updated DESC'; } if (!in_array('date_submitted', $t_sort_fields)) { $p_query_clauses['order'][] = '{bug}.date_submitted DESC'; } return $p_query_clauses; }
/** * Gets the formatted value for the specified issue id, project and custom field. * @param $p_issue_id The issue id. * @param $p_project_id The project id. * @param $p_custom_field The custom field name (without 'custom_' prefix). * @returns The custom field value. */ function excel_format_custom_field($p_issue_id, $p_project_id, $p_custom_field) { $t_field_id = custom_field_get_id_from_name($p_custom_field); if ($t_field_id === false) { return excel_prepare_string('@' . $p_custom_field . '@'); } if (custom_field_is_linked($t_field_id, $p_project_id)) { $t_def = custom_field_get_definition($t_field_id); return excel_prepare_string(string_custom_field_value($t_def, $t_field_id, $p_issue_id)); } // field is not linked to project return excel_prepare_string(''); }
/** * Gets the localized title for the specified column. The column can be native or custom. * The custom fields must contain the 'custom_' prefix. * * @param string $p_column - The column name. * @return string The column localized name. * @access public */ function column_get_title($p_column) { $t_custom_field = column_get_custom_field_name($p_column); if ($t_custom_field !== null) { $t_field_id = custom_field_get_id_from_name($t_custom_field); if ($t_field_id === false) { $t_custom_field = '@' . $t_custom_field . '@'; } else { $t_def = custom_field_get_definition($t_field_id); $t_custom_field = lang_get_defaulted($t_def['name']); } return $t_custom_field; } $t_plugin_columns = columns_get_plugin_columns(); if (isset($t_plugin_columns[$p_column])) { $t_column_object = $t_plugin_columns[$p_column]; return $t_column_object->title; } switch ($p_column) { case 'attachment_count': return lang_get('attachments'); case 'bugnotes_count': return '#'; case 'category_id': return lang_get('category'); case 'edit': return ''; case 'handler_id': return lang_get('assigned_to'); case 'last_updated': return lang_get('updated'); case 'os_build': return lang_get('os_version'); case 'project_id': return lang_get('email_project'); case 'reporter_id': return lang_get('reporter'); case 'selection': return ''; case 'sponsorship_total': return sponsorship_get_currency(); case 'version': return lang_get('product_version'); case 'view_state': return lang_get('view_status'); default: return lang_get_defaulted($p_column); } }
/** * Creates a custom field if it does not exist. * The settings of the custom field will be updates in any case. * * @param unknown $p_field_name Name of the * @param unknown $p_def_array */ function create_custom_field($p_field_name, $p_def_array) { $p_def_array['name'] = $p_field_name; $p_def_array['default_value'] = ''; $p_def_array['access_level_r'] = '55'; $p_def_array['access_level_rw'] = '55'; $p_def_array['display_report'] = '0'; $p_def_array['display_update'] = '0'; $p_def_array['filter_by'] = '1'; $t_field_id = custom_field_get_id_from_name($p_field_name); if (!$t_field_id) { // Field does not exist yet, create it. $t_field_id = custom_field_create($p_field_name); // Update field settings custom_field_update($t_field_id, $p_def_array); } }