/** * Validates the Attach Tags group action. * Checks if a user can attach the requested tags to a given bug. * @param integer $p_bug_id Bug ID * @return string|null On failure: the reason for tags failing validation for the given bug. On success: null. */ function action_attach_tags_validate($p_bug_id) { global $g_action_attach_tags_tags; global $g_action_attach_tags_attach; global $g_action_attach_tags_create; $t_can_attach = access_has_bug_level(config_get('tag_attach_threshold'), $p_bug_id); if (!$t_can_attach) { return lang_get('tag_attach_denied'); } if (!isset($g_action_attach_tags_tags)) { if (!isset($g_action_attach_tags_attach)) { $g_action_attach_tags_attach = array(); $g_action_attach_tags_create = array(); } $g_action_attach_tags_tags = tag_parse_string(gpc_get_string('tag_string')); foreach ($g_action_attach_tags_tags as $t_tag_row) { if ($t_tag_row['id'] == -1) { $g_action_attach_tags_create[$t_tag_row['name']] = $t_tag_row; } else { if ($t_tag_row['id'] >= 0) { $g_action_attach_tags_attach[$t_tag_row['name']] = $t_tag_row; } } } } $t_can_create = access_has_bug_level(config_get('tag_create_threshold'), $p_bug_id); if (count($g_action_attach_tags_create) > 0 && !$t_can_create) { return lang_get('tag_create_denied'); } if (count($g_action_attach_tags_create) == 0 && count($g_action_attach_tags_attach) == 0) { return lang_get('tag_none_attached'); } return null; }
/** * Validates the Attach Tags group action. * Gets called for every bug, but performs the real tag validation only * the first time. Any invalid tags will be skipped, as there is no simple * or clean method of presenting these errors to the user. * @param integer Bug ID * @return boolean True */ function action_attach_tags_validate($p_bug_id) { global $g_action_attach_tags_valid; if (!isset($g_action_attach_tags_valid)) { $f_tag_string = gpc_get_string('tag_string'); $f_tag_select = gpc_get_string('tag_select'); global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; $g_action_attach_tags_attach = array(); $g_action_attach_tags_create = array(); $g_action_attach_tags_failed = array(); $t_tags = tag_parse_string($f_tag_string); $t_can_create = access_has_global_level(config_get('tag_create_threshold')); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { if ($t_can_create) { $g_action_attach_tags_create[] = $t_tag_row; } else { $g_action_attach_tags_failed[] = $t_tag_row; } } elseif (-2 == $t_tag_row['id']) { $g_action_attach_tags_failed[] = $t_tag_row; } else { $g_action_attach_tags_attach[] = $t_tag_row; } } if (0 < $f_tag_select && tag_exists($f_tag_select)) { $g_action_attach_tags_attach[] = tag_get($f_tag_select); } } global $g_action_attach_tags_attach, $g_action_attach_tags_create, $g_action_attach_tags_failed; return true; }
* @package MantisBT * @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net * @link http://www.mantisbt.org * * @uses core.php * @uses authentication_api.php * @uses form_api.php * @uses gpc_api.php * @uses print_api.php * @uses tag_api.php */ require_once 'core.php'; require_api('authentication_api.php'); require_api('form_api.php'); require_api('gpc_api.php'); require_api('print_api.php'); require_api('tag_api.php'); form_security_validate('tag_create'); $f_tag_name = gpc_get_string('name'); $f_tag_description = gpc_get_string('description'); $t_tag_user = auth_get_current_user_id(); if (!is_null($f_tag_name)) { $t_tags = tag_parse_string($f_tag_name); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { tag_create($t_tag_row['name'], $t_tag_user, $f_tag_description); } } } form_security_purge('tag_create'); print_successful_redirect('manage_tags_page.php');
require_api('lang_api.php'); require_api('print_api.php'); require_api('string_api.php'); require_api('tag_api.php'); require_api('utility_api.php'); form_security_validate('tag_attach'); $f_bug_id = gpc_get_int('bug_id'); $f_tag_select = gpc_get_int('tag_select'); $f_tag_string = gpc_get_string('tag_string'); $t_user_id = auth_get_current_user_id(); access_ensure_bug_level(config_get('tag_attach_threshold'), $f_bug_id, $t_user_id); /** @todo The handling of tag strings which can include multiple tags should be moved * to the APIs. This is to allow other clients of the API to support such * functionality. The access level checks should also be moved to the API. */ $t_tags = tag_parse_string($f_tag_string); $t_can_create = access_has_global_level(config_get('tag_create_threshold')); $t_tags_create = array(); $t_tags_attach = array(); $t_tags_failed = array(); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { if ($t_can_create) { $t_tags_create[] = $t_tag_row; } else { $t_tags_failed[] = $t_tag_row; } } else { if (-2 == $t_tag_row['id']) { $t_tags_failed[] = $t_tag_row; } else {
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Mantis. If not, see <http://www.gnu.org/licenses/>. # -------------------------------------------------------- # $Id: tag_attach.php,v 1.2.2.2 2007-10-18 15:33:22 nuclear_eclipse Exp $ # -------------------------------------------------------- require_once 'core.php'; $t_core_path = config_get('core_path'); require_once $t_core_path . 'tag_api.php'; form_security_validate('tag_attach'); $f_bug_id = gpc_get_int('bug_id'); $f_tag_select = gpc_get_int('tag_select'); $t_user_id = auth_get_current_user_id(); access_ensure_bug_level(config_get('tag_attach_threshold'), $f_bug_id, $t_user_id); $t_tags = tag_parse_string(gpc_get_string('tag_string')); $t_can_create = access_has_global_level(config_get('tag_create_threshold')); $t_tags_create = array(); $t_tags_attach = array(); $t_tags_failed = array(); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { if ($t_can_create) { $t_tags_create[] = $t_tag_row; } else { $t_tags_failed[] = $t_tag_row; } } elseif (-2 == $t_tag_row['id']) { $t_tags_failed[] = $t_tag_row; } else { $t_tags_attach[] = $t_tag_row;
/** * Attaches a bunch of tags to the specified issue. * * @param int $p_bug_id The bug id. * @param string $p_tag_string String of tags separated by configured separator. * @param int $p_tag_id Tag id to add or 0 to skip. * @return array|bool true for success, otherwise array of failures. The array elements follow the tag_parse_string() * format. */ function tag_attach_many($p_bug_id, $p_tag_string, $p_tag_id = 0) { # If no work, then there is no need to do access check. if ($p_tag_id === 0 && is_blank($p_tag_string)) { return true; } access_ensure_bug_level(config_get('tag_attach_threshold'), $p_bug_id); $t_tags = tag_parse_string($p_tag_string); $t_can_create = access_has_global_level(config_get('tag_create_threshold')); $t_tags_create = array(); $t_tags_attach = array(); $t_tags_failed = array(); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { if ($t_can_create) { $t_tags_create[] = $t_tag_row; } else { $t_tags_failed[] = $t_tag_row; } } else { if (-2 == $t_tag_row['id']) { $t_tags_failed[] = $t_tag_row; } else { $t_tags_attach[] = $t_tag_row; } } } if (0 < $p_tag_id && tag_exists($p_tag_id)) { $t_tags_attach[] = tag_get($p_tag_id); } # failed to attach at least one tag if (count($t_tags_failed) > 0) { return $t_tags_failed; } foreach ($t_tags_create as $t_tag_row) { $t_tag_row['id'] = tag_create($t_tag_row['name']); $t_tags_attach[] = $t_tag_row; } foreach ($t_tags_attach as $t_tag_row) { if (!tag_bug_is_attached($t_tag_row['id'], $p_bug_id)) { tag_bug_attach($t_tag_row['id'], $p_bug_id); } } event_signal('EVENT_TAG_ATTACHED', array($p_bug_id, $t_tags_attach)); return true; }