<?php
# Mantis Plugin : Set Severity group action
# By: Daniel Carr, 2007
# Available to the Mantis project under the Mantis license 
#
# -- Requires the following in custom_strings_inc.php:
#    $s_set_severity_title = 'Update Severity';
#    $s_set_severity_msg = 'Choose the new severity of the issue(s)';
#    $s_set_severity_button = 'Update Severity';
#    $s_actiongroup_menu_set_severity = 'Update Severity';
	
	/**
	 * Prints the title for the custom action page.	 
	 */
	function action_set_severity_print_title() {
        echo '<tr class="form-title">';
        echo '<td colspan="2">';
        echo lang_get( 'set_severity_title' );
        echo '</td></tr>';		
	}
	
	/**
	 * Prints the field within the custom action form.  This has an entry for
	 * every field the user need to supply + the submit button.  The fields are
	 * added as rows in a table that is already created by the calling code.
	 * A row has two columns.         	 
	 */
	function action_set_severity_print_fields() {
?>
	<tr class="row-1" valign="top"><td class="category">
<?php echo lang_get( 'set_severity_msg' ); ?>
	</td>
	<!-- Severity -->
	<td>
	<select name="severity">
	<?php print_enum_string_option_list( 'severity', $t_bug->severity) ?>
	</select>
	</td>
	</tr>
	<?php
		echo '<tr><td colspan="2"><center><input type="submit" class="button" value="' . lang_get( 'set_severity_button' ) . ' " /></center></td></tr>';
	}

	/**
	 * Validates the action on the specified bug id.
	 * 
	 * @returns true    Action can be applied.
	 * @returns array( bug_id => reason for failure )	 
	 */
	function action_set_severity_validate( $p_bug_id ) {
		$f_severity = gpc_get_string( 'severity' );

		$t_failed_validation_ids = array();

		$t_set_severity_threshold = config_get( 'update_bug_threshold' );
		$t_bug_id = $p_bug_id;

		if ( bug_is_readonly( $t_bug_id ) ) {
			$t_failed_validation_ids[$t_bug_id] = lang_get( 'actiongroup_error_issue_is_readonly' );
			return $t_failed_validation_ids;
		}

		if ( !access_has_bug_level( $t_set_severity_threshold, $t_bug_id ) ) {
			$t_failed_validation_ids[$t_bug_id] = lang_get( 'access_denied' );
			return $t_failed_validation_ids;
		}

		return true;
	}

	/**
	 * Executes the custom action on the specified bug id.
	 * 
	 * @param $p_bug_id  The bug id to execute the custom action on.
	 * 
	 * @returns true   Action executed successfully.
	 * @returns array( bug_id => reason for failure )               	 
	 */
	function action_set_severity_process( $p_bug_id ) {
		$f_severity = gpc_get_string( 'severity' );
		bug_set_field( $p_bug_id, 'severity', $f_severity );
        return true;
    }
?>
