$GLOBALS['phpgw']->template->set_var('tts_head_transition_id', $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'transition_id', $order, '/tts/transitions.php', '#'));
$GLOBALS['phpgw']->template->set_var('tts_head_transition', $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'transition_name', $order, '/tts/transitions.php', lang('Transition')));
$GLOBALS['phpgw']->template->set_var('tts_head_description', $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'transition_description', $order, '/tts/transitions.php', lang('Description')));
$GLOBALS['phpgw']->template->set_var('tts_head_target_state', $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'transition_target_state', $order, '/tts/transitions.php', lang('Target State')));
$GLOBALS['phpgw']->template->set_var('tts_head_source_state', $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'transition_source_state', $order, '/tts/transitions.php', lang('Source State')));
$GLOBALS['phpgw']->template->set_var('lang_add', lang('Add'));
$GLOBALS['phpgw']->template->set_var('lang_edit', lang('Edit'));
$GLOBALS['phpgw']->template->set_var('lang_delete', lang('Delete'));
if ($db2->num_rows() == 0) {
    $GLOBALS['phpgw']->template->set_var('rows', '<p><center>' . lang('No transitions found') . '</center>');
} else {
    $i = 0;
    while ($db2->next_record()) {
        $GLOBALS['phpgw']->template->set_var('tts_col_status', '');
        $GLOBALS['phpgw']->template->set_var('row_class', ++$i & 1 ? 'row_on' : 'row_off');
        $GLOBALS['phpgw']->template->set_var('tts_transitionedit_link', $GLOBALS['phpgw']->link('/tts/edit_transition.php', 'transition_id=' . $db2->f('transition_id')));
        $GLOBALS['phpgw']->template->set_var('tts_transitiondelete_link', $GLOBALS['phpgw']->link('/tts/delete_transition.php', 'transition_id=' . $db2->f('transition_id')));
        $GLOBALS['phpgw']->template->set_var('transition_id', $db2->f('transition_id'));
        $GLOBALS['phpgw']->template->set_var('transition_name', try_lang($name = $db2->f('transition_name'), False, True));
        $GLOBALS['phpgw']->template->set_var('transition_description', try_lang($db2->f('transition_description'), try_lang(substr($name, 2))));
        $GLOBALS['phpgw']->template->set_var('transition_source_state', id2field('phpgw_tts_states', 'state_name', 'state_id', $db2->f('transition_source_state')));
        $GLOBALS['phpgw']->template->set_var('transition_target_state', id2field('phpgw_tts_states', 'state_name', 'state_id', $db2->f('transition_target_state')));
        $GLOBALS['phpgw']->template->parse('rows', 'transition_row', True);
    }
}
$GLOBALS['phpgw']->template->set_var('row_class', ++$i & 1 ? 'row_on' : 'row_off');
$GLOBALS['phpgw']->template->set_var('tts_transitionadd_link', $GLOBALS['phpgw']->link('/tts/edit_transition.php', 'transition_id=0'));
// this is a workaround to clear the subblocks autogenerated vars
$GLOBALS['phpgw']->template->set_var('transition_row', '');
$GLOBALS['phpgw']->template->pfp('out', 'transitions');
$GLOBALS['phpgw']->common->phpgw_footer();
    $GLOBALS['phpgw']->template->set_var('value_details', nl2br($ticket['details']));
    $GLOBALS['phpgw']->template->set_var('value_subject', $ticket['subject']);
    $GLOBALS['phpgw']->template->set_var('lang_additional_notes', lang('Additional notes'));
    $GLOBALS['phpgw']->template->set_var('lang_save', lang('Save'));
    $GLOBALS['phpgw']->template->set_var('lang_apply', lang('Apply'));
    $GLOBALS['phpgw']->template->set_var('lang_cancel', lang('Cancel'));
    $GLOBALS['phpgw']->template->set_var('lang_category', lang('Category'));
    $GLOBALS['phpgw']->template->set_var('value_category', $GLOBALS['phpgw']->categories->id2name($ticket['category']));
    $GLOBALS['phpgw']->template->set_var('options_select', '');
    $GLOBALS['phpgw']->template->set_var('lang_update_state', lang('Update ticket state'));
    $GLOBALS['phpgw']->template->set_var('lang_keep_present_state', lang('Keep the present state [%1].', id2field('phpgw_tts_states', 'state_name', 'state_id', $ticket['state'])));
    $db = clone $GLOBALS['phpgw']->db;
    $db->query("select * from phpgw_tts_transitions where transition_source_state=" . $ticket['state'], __LINE__, __FILE__);
    while ($db->next_record()) {
        $GLOBALS['phpgw']->template->set_var('update_state_value', $db->f('transition_target_state'));
        $GLOBALS['phpgw']->template->set_var('update_state_text', try_lang($db->f('transition_description'), id2field('phpgw_tts_states', 'state_name', 'state_id', $db->f('transition_target_state'))));
        $GLOBALS['phpgw']->template->parse('update_state_group', 'update_state_items', True);
    }
    $GLOBALS['phpgw']->template->pfp('out', 'form');
    $GLOBALS['phpgw']->common->phpgw_footer();
} else {
    $ticket = $_POST['ticket'];
    // DB Content is fresher than http posted value.
    $GLOBALS['phpgw']->db->query("select * from phpgw_tts_tickets where ticket_id='{$ticket_id}'", __LINE__, __FILE__);
    $GLOBALS['phpgw']->db->next_record();
    $oldassigned = $GLOBALS['phpgw']->db->f('ticket_assignedto');
    $oldpriority = $GLOBALS['phpgw']->db->f('ticket_priority');
    $oldcategory = $GLOBALS['phpgw']->db->f('ticket_category');
    $old_status = $GLOBALS['phpgw']->db->f('ticket_status');
    $old_billable_hours = $GLOBALS['phpgw']->db->f('ticket_billable_hours');
    $old_billable_rate = $GLOBALS['phpgw']->db->f('ticket_billable_rate');
        $GLOBALS['phpgw']->template->set_var('tts_t_timestampopened', $GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'] - 60 * 60 * $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset']));
        if ($GLOBALS['phpgw']->db->f('ticket_status') == 'X') {
            $history_values = $GLOBALS['phpgw']->historylog->return_array(array(), array('X'), 'history_timestamp', 'DESC', $GLOBALS['phpgw']->db->f('ticket_id'));
            $GLOBALS['phpgw']->template->set_var('tts_t_timestampclosed', $GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'] - 60 * 60 * $GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset']));
            $GLOBALS['phpgw']->template->parse('tts_col_status', 'tts_col_ifviewall', False);
        } else {
            //        if ($GLOBALS['phpgw']->db->f('ticket_assignedto') != -1)
            //        {
            //          $assigned_to = lang('Not assigned');
            //        }
            //        else
            //        {
            //          $assigned_to = $GLOBALS['phpgw']->accounts->id2name($GLOBALS['phpgw']->db->f('ticket_assignedto'));
            //        }
            //        $GLOBALS['phpgw']->template->set_var('tts_t_timestampclosed',$assigned_to);
            $GLOBALS['phpgw']->template->set_var('tts_t_timestampclosed', lang('Open'));
            $GLOBALS['phpgw']->template->parse('tts_col_status', 'tts_col_ifviewall', False);
        }
        $GLOBALS['phpgw']->template->set_var('tts_t_subject', $GLOBALS['phpgw']->db->f('ticket_subject'));
        $GLOBALS['phpgw']->template->set_var('tts_t_state', id2field('phpgw_tts_states', 'state_name', 'state_id', $GLOBALS['phpgw']->db->f('ticket_state')));
        $GLOBALS['phpgw']->template->parse('rows', 'tts_row', True);
    }
}
// this is a workaround to clear the subblocks autogenerated vars
$GLOBALS['phpgw']->template->set_var('tts_row', '');
$GLOBALS['phpgw']->template->set_var('tts_col_ifviewall', '');
$GLOBALS['phpgw']->template->set_var('tts_head_ifviewall', '');
$GLOBALS['phpgw']->template->set_var('tts_ticket_id_read', '');
$GLOBALS['phpgw']->template->set_var('tts_ticket_id_unread', '');
$GLOBALS['phpgw']->template->pfp('out', 'delete_state');
$GLOBALS['phpgw']->common->phpgw_footer();
 ** from phpgw_tts_tickets, phpgw_tts_groups where ticket_id = group_ticket_id and group_id in (14,15);
 */
/* ACL levels
 ** 1 - Read ticket within your group only
 ** 2 - Close ticket
 ** 4 - Allow to make changes to priority, billing hours, billing rate, category, and assigned to
 */
$GLOBALS['phpgw_info']['flags']['currentapp'] = 'tts';
$GLOBALS['phpgw_info']['flags']['enable_contacts_class'] = True;
$GLOBALS['phpgw_info']['flags']['enable_categories_class'] = True;
$GLOBALS['phpgw_info']['flags']['enable_nextmatchs_class'] = True;
$GLOBALS['phpgw_info']['flags']['noheader'] = True;
include '../header.inc.php';
// select what tickets to view
$transition_id = intval(get_var('transition_id', array('POST', 'GET')));
if ($_POST['delete'] && $transition_id) {
    $GLOBALS['phpgw']->db->query("delete from phpgw_tts_transitions where transition_id={$transition_id}", __LINE__, __FILE__);
}
if ($_POST['delete'] || $_POST['cancel'] || !$transition_id) {
    $GLOBALS['phpgw']->redirect_link('/tts/transitions.php');
}
$GLOBALS['phpgw']->template->set_file('delete_transition', 'delete_transition.tpl');
$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['tts']['title'] . ' - ' . lang('Deleting the transition');
$GLOBALS['phpgw']->common->phpgw_header();
$s = id2field('phpgw_tts_transitions', 'transition_name', 'transition_id', $transition_id);
$GLOBALS['phpgw']->template->set_var('lang_are_you_sure', lang('You want to delete the transition %1. Are you sure?', "'" . $s . "'"));
$GLOBALS['phpgw']->template->set_var('delete_transition_link', $GLOBALS['phpgw']->link('/tts/delete_transition.php', 'transition_id=' . $transition_id));
$GLOBALS['phpgw']->template->set_var('lang_delete', lang('Delete'));
$GLOBALS['phpgw']->template->set_var('lang_cancel', lang('Cancel'));
$GLOBALS['phpgw']->template->pfp('out', 'delete_transition');
$GLOBALS['phpgw']->common->phpgw_footer();