ticket_create

one of the documented procedures in this installation of the ACS
Usage:
ticket_create { -msg_html plain -new_msg_id {} -public_p t -notify_p t -severity_id null -priority_id null -cause_id null -status_id null -source_id null -type_id null -assignee {} -deadline null -from_url null -from_query null -from_project null -from_host null -from_ip null -from_user_agent null -version null -code_set ad } db user_id project_id domain_id one_line message
What it does:
generate a new ticket and take all standard actions
Defined in: /web/philip/tcl/ticket-defs.tcl

Source code:

arg_parser_for_ticket_create $args

    ############################################################
    ##Setup the defaults
    ############################################################
    ##Generate good values for each code if it doesn't exist
    if {[string compare $status_id null] == 0} {
        set status_id [database_to_tcl_string $db "select code_id as status_id from ticket_codes_i where code = 'open' and code_type = 'status'"]
    }
    set codes {severity priority type cause}
    foreach code $codes {
        set code_id "${code}_id"
        if {[string compare [set $code_id] null] == 0} {
            set where_clause "code_type = '$code' and code_set = '$code_set'"
            set ret [database_to_tcl_string_or_null $db "
            select code_id from ticket_codes where $where_clause and code_seq = (select min(code_seq) from ticket_codes where $where_clause) and rownum = 1"]
            if {![empty_string_p $ret]} {
                set $code_id $ret
            }
        }
    }
    ## assignee
    if {[empty_string_p $assignee]} {
        set assignee [database_to_tcl_string_or_null $db "select tm.default_assignee from ticket_domain_project_map tm where tm.project_id = $project_id and tm.domain_id = $domain_id"]
        ##What do we do if we don't get anything here????
    }

    if {[empty_string_p $new_msg_id]} {
        set new_msg_id [database_to_tcl_string $db "select ticket_issue_id_sequence.nextval from dual"]
    }

    set selection [ns_db 1row $db "select to_char(sysdate,'Month, DD YYYY ') || sysdate as when_saved, email, first_names || ' ' || last_name as username from users where user_id = $user_id"]
    set_variables_after_query        
    ##########################################################
    ## Do DB inserts into general comments/ticket_issues_i
    ##########################################################
    set indexed_stuff "TR\#$new_msg_id\n$email\n$username\n$when_saved\n$message"
    util_dbq -null_is_null_p t {version one_line public_p notify_p 
        from_url from_query from_host from_project deadline from_ip from_user_agent}

    with_transaction $db {
        set comment_id [database_to_tcl_string $db "
        select general_comment_id_sequence.nextval from dual"]
        if { $msg_html == "pre" } {
            regsub "\[ \012\015\]+\$" $message {} message
            set message "<pre>[ns_quotehtml $message]</pre>"
            set html_p t
        } elseif { $msg_html == "html" } { 
            set html_p t
        } else { 
            set html_p f
        }
        ad_general_comment_add $db $comment_id {ticket_issues_i} $new_msg_id  "\#$new_msg_id $one_line" $message $user_id [peeraddr] {t}  $html_p $one_line

        # create the ticket
        ns_db dml $db "insert into ticket_issues_i
        (msg_id, project_id, version, domain_id, user_id, one_line,
        comment_id,
        ticket_type_id, priority_id, severity_id, source_id, cause_id, status_id,
        posting_time, deadline, public_p, notify_p, 
        from_host, from_url, from_query, from_project, from_ip, from_user_agent, 
        last_modified, last_modifying_user, modified_ip_address
        ) values (
        $new_msg_id,$project_id,$DBQversion,$domain_id, $user_id,$DBQone_line,
        $comment_id,
        $type_id, $priority_id, $severity_id, $source_id, $cause_id, $status_id,
        sysdate, $DBQdeadline, $DBQpublic_p, $DBQnotify_p, 
        $DBQfrom_host, $DBQfrom_url, $DBQfrom_query, $DBQfrom_project, $DBQfrom_ip,
        $DBQfrom_user_agent, 
        sysdate, $user_id, '[DoubleApos [peeraddr]]')"

        if { ![empty_string_p $assignee]} { 
            ns_db dml $db "insert into ticket_issue_assignments (msg_id, user_id, active_p)
                           values ($new_msg_id, $assignee, 't')"
        }

        ns_ora clob_dml $db "insert into ticket_index (msg_id, indexed_stuff, last_modified
 ) values ($new_msg_id, empty_clob(), sysdate) returning indexed_stuff into :1" $indexed_stuff
    } {
        # something went a bit wrong during the insert
        error "<li>Here was the bad news from the database:
               <pre>$errmsg</pre>"
    }
    ##############################
    ##Now send out some email
    ##############################
    set returned_text ""
    if { $notify_p == "t"} {

        set selection [ns_db 0or1row $db "select td.title_long as domain_title, tp.title_long as project_title, priority_long, status_long, one_line as one_line from ticket_issues ti, ticket_domains td, ticket_projects tp where msg_id = $new_msg_id and td.domain_id = ti.domain_id and tp.project_id = ti.project_id"]
        set_variables_after_query
        set status_msg "STATUS: $status_long"
        set body "\n\nACTION BY: $username ($email)\nPRIORITY: $priority_long  $status_msg\n\n----------------------------------------\nTicket #$new_msg_id $one_line\n\n"
        
        if {$msg_html == "plain" } { 
            append body [wrap_string $message 80]
        } else { 
            append body [util_striphtml $message]
        }
        append body "\n\nProject $project_title - $domain_title\n"
        append returned_text [ticket_notify $db new_ticket $new_msg_id $one_line $body]
    } 
    return $returned_text


philg@mit.edu