summaryrefslogtreecommitdiffstats
path: root/buglist.cgi
blob: 61e7cac15e2c1fb048aa20b8a64a4b661c82ba88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
#! /usr/bonsaitools/bin/mysqltcl
# -*- Mode: tcl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code is the Bugzilla Bug Tracking System.
# 
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are Copyright (C) 1998
# Netscape Communications Corporation. All Rights Reserved.
# 
# Contributor(s): Terry Weissman <terry@mozilla.org>

puts "Content-type: multipart/x-mixed-replace;boundary=ThisRandomString"
puts ""
puts "--ThisRandomString"


# The below "if catch" stuff, if uncommented, will trap any error, and
# mail the error messages to terry.  What a hideous, horrible
# debugging hack.

# if {[catch {


source "CGI.tcl"

ConnectToDatabase

if {![info exists FORM(cmdtype)]} {
    # This can happen if there's an old bookmark to a query...
    set FORM(cmdtype) doit
}

switch $FORM(cmdtype) {
    runnamed {
        set buffer $COOKIE(QUERY_$FORM(namedcmd))
        ProcessFormFields $buffer
    }
    editnamed {
        puts "Content-type: text/html
Refresh: 0; URL=query.cgi?$COOKIE(QUERY_$FORM(namedcmd))

<TITLE>What a hack.</TITLE>
Loading your query named <B>$FORM(namedcmd)</B>..."
        exit
    }
    forgetnamed {
        puts "Set-Cookie: QUERY_$FORM(namedcmd)= ; path=/ ; expires=Sun, 30-Jun-99 00:00:00 GMT
Content-type: text/html

<HTML>
<TITLE>Forget what?</TITLE>
OK, the <B>$FORM(namedcmd)</B> query is gone.
<P>
<A HREF=query.cgi>Go back to the query page.</A>"
    exit
    }
    asnamed {
        if {[regexp {^[a-zA-Z0-9_ ]+$} $FORM(newqueryname)]} {
    puts "Set-Cookie: QUERY_$FORM(newqueryname)=$buffer ; path=/ ; expires=Sun, 30-Jun-99 00:00:00 GMT
Content-type: text/html

<HTML>
<TITLE>OK, done.</TITLE>
OK, you now have a new query named <B>$FORM(newqueryname)</B>.

<P>

<A HREF=query.cgi>Go back to the query page.</A>"
        } else {
            puts "Content-type: text/html

<HTML>
<TITLE>Picky, picky.</TITLE>
Query names can only have letters, digits, spaces, or underbars.  You entered 
\"<B>$FORM(newqueryname)</B>\", which doesn't cut it.
<P>
Click the <B>Back</B> button and type in a valid name for this query."
        }
        exit
    }
    asdefault {
        puts "Set-Cookie: DEFAULTQUERY=$buffer ; path=/ ; expires=Sun, 30-Jun-99 00:00:00 GMT
Content-type: text/html

<HTML>
<TITLE>OK, default is set.</TITLE>
OK, you now have a new default query.

<P>

<A HREF=query.cgi>Go back to the query page, using the new default.</A>"
        exit
    }
}

proc qadd { item } {
  global query
  append query "$item"
}


proc DefCol {name k t {s ""} {q 0}} {
    global key title sortkey needquote
    set key($name) $k
    set title($name) $t
    if {![cequal $s ""]} {
        set sortkey($name) $s
    }
    set needquote($name) $q
}

DefCol opendate "date_format(bugs.creation_ts,'Y-m-d')" Opened bugs.creation_ts
DefCol changeddate "date_format(bugs.delta_ts,'Y-m-d')" Changed bugs.delta_ts
DefCol severity "substring(bugs.bug_severity, 1, 3)" Sev bugs.bug_severity
DefCol priority "substring(bugs.priority, 1, 3)" Pri bugs.priority
DefCol platform "substring(bugs.rep_platform, 1, 3)" Plt bugs.rep_platform
DefCol owner "assign.login_name" Owner assign.login_name
DefCol reporter "report.login_name" Reporter report.login_name
DefCol status "substring(bugs.bug_status,1,4)" State bugs.bug_status
DefCol resolution "substring(bugs.resolution,1,4)" Res bugs.resolution
DefCol summary "substring(bugs.short_desc, 1, 60)" Summary {} 1
DefCol summaryfull "bugs.short_desc" Summary {} 1
DefCol component "substring(bugs.component, 1, 8)" Comp bugs.component
DefCol product "substring(bugs.product, 1, 8)" Product bugs.product
DefCol version "substring(bugs.version, 1, 5)" Vers bugs.version
DefCol os "substring(bugs.op_sys, 1, 4)" OS bugs.op_sys

if {[info exists COOKIE(COLUMNLIST)]} {
    set collist $COOKIE(COLUMNLIST)
} else {
    set collist $default_column_list
}

set dotweak [info exists FORM(tweak)]

if {$dotweak} {
    confirm_login
}


puts "Content-type: text/html\n"

set query "
select
        bugs.bug_id"


foreach c $collist {
    if {[info exists needquote($c)] } {
        append query ",
\t$key($c)"
    }
}


if {$dotweak} {
    append query ",
bugs.product,
bugs.bug_status"
}

append query "
from   bugs,
       profiles assign,
       profiles report,
       versions projector
where  bugs.assigned_to = assign.userid 
and    bugs.reporter = report.userid
and    bugs.product = projector.program
and    bugs.version = projector.value
"

if {[info exists FORM(sql)]} {
  append query "and (\n[join [url_decode $FORM(sql)] { }]\n)"
} else {


  set legal_fields { bug_id product version rep_platform op_sys bug_status
                     resolution priority bug_severity assigned_to reporter
                     bug_file_loc component}

  foreach field [array names FORM] {
    if { [ lsearch $legal_fields $field ] != -1 && ![cequal $FORM($field) ""]} {
      qadd "\tand (\n"
      set or ""
      if { $field == "assigned_to" || $field == "reporter"} {
        foreach p [split $FORM($field) ","] {
          qadd "\t\t${or}bugs.$field = [DBNameToIdAndCheck $p]\n"
          set or "or "
        }
      } else {
        foreach v $MFORM($field) {
          if {[cequal $v "(empty)"]} {
              qadd "\t\t${or}bugs.$field is null\n"
          } else {
              qadd "\t\t${or}bugs.$field = '$v'\n"
          }
          set or "or "
        }
      }
      qadd "\t)\n"
    }
  }

  if {[lookup FORM changedin] != ""} {
      set c [string trim $FORM(changedin)]
      if {$c != ""} {
          if {![regexp {^[0-9]*$} $c]} {
              puts "
The 'changed in last ___ days' field must be a simple number.  You entered 
\"$c\", which doesn't cut it.
<P>
Click the <B>Back</B> button and try again."
              exit
          }
          qadd "and to_days(now()) - to_days(bugs.delta_ts) <= $FORM(changedin) "
      }
  }

  foreach f {short_desc long_desc} {
      set s [SqlQuote [string trim [lookup FORM $f]]]
      if {$s != ""} {
          if {[lookup FORM [set f]_type] == "regexp"} {
              qadd "and $f regexp '$s' "
          } else {
              qadd "and instr($f, '$s') "
          }
      }
  }


}


if {[info exists FORM(order)]} {
    qadd "order by "
    switch -glob $FORM(order) {
        *.* {}
        *Number* {
            set FORM(order) bugs.bug_id
        }
        *Import* {
            set FORM(order) bugs.priority
        }
        *Assign* {
            set FORM(order) "assign.login_name, bugs.bug_status, priority, bugs.bug_id"
        }
        default {
            set FORM(order) "bugs.bug_status, priorities.rank, assign.login_name, bugs.bug_id"
        }
    }
    if {[cequal [cindex $FORM(order) 0] "\{"]} {
        # I don't know why this happens, but...
        set FORM(order) [lindex $FORM(order) 0]
    }
    qadd $FORM(order)
}

puts "Please stand by ... <p>"
if {[info exists FORM(debug)]} {
    puts "<pre>$query</pre>"
}
flush stdout
SendSQL $query

set count 0
set bugl ""
proc pnl { str } {
  global bugl
  append bugl "$str"
}

regsub -all {[&?]order=[^&]*} $buffer {} fields
regsub -all {[&?]cmdtype=[^&]*} $fields {} fields


if {[info exists FORM(order)]} {
    regsub -all { } ", $FORM(order)" "%20" oldorder
} else {
    set oldorder ""
}

if {$dotweak} {
    pnl "<FORM NAME=changeform METHOD=POST ACTION=\"process_bug.cgi\">"
}

set tablestart "<TABLE CELLSPACING=0 CELLPADDING=2>
<TR ALIGN=LEFT><TH>
<A HREF=\"buglist.cgi?[set fields]&order=bugs.bug_id\">ID</A>"


foreach c $collist {
    if { [info exists needquote($c)] } {
        if {$needquote($c)} {
            append tablestart "<TH WIDTH=100% valigh=left>"
        } else {
            append tablestart "<TH valign=left>"
        }
        if {[info exists sortkey($c)]} {
            append tablestart "<A HREF=\"buglist.cgi?[set fields]&order=$sortkey($c)$oldorder\">$title($c)</A>"
        } else {
            append tablestart $title($c)
        }
    }
}

append tablestart "\n"

set dotweak [info exists FORM(tweak)]

set p_true 1

while { $p_true } {
    set result [FetchSQLData]
    set p_true [MoreSQLData]
    if { $result != "" } { 
        set bug_id [lvarpop result]
        if {![info exists seen($bug_id)]} {
            set seen($bug_id) 1
            incr count
            if {($count % 200) == 0} {
                # Too big tables take too much browser memory...
                pnl "</TABLE>$tablestart"
            }
            if {[info exists buglist]} {
                append buglist ":$bug_id"
            } else {
                set buglist $bug_id
            }
            pnl "<TR VALIGN=TOP ALIGN=LEFT><TD>"
            if {$dotweak} {
                pnl "<input type=checkbox name=id_$bug_id>"
            }
            pnl "<A HREF=\"show_bug.cgi?id=$bug_id\">"
            pnl "$bug_id</A> "
            foreach c $collist {
                set value [lvarpop result]
                set nowrap {} 

                #-- This cursor is used to pick the login_name to be
                #   displayed on the query list as the field value may or
                #   maynot have vales associated to it

                if { $c == "qa_assigned_to"} {
                     set dml_cur [ oraopen $lhandle ]

                     orasql $dml_cur "select login_name 
                                      from   profiles 
                                      where  userid = $value"

                     set cur_resultset [orafetch $dml_cur]

                     if {$cur_resultset != ""} { 
                         set  value $cur_resultset 
                         set nowrap {nowrap}
                     } else {
                         set  value ""
                     }

                     oraclose $dml_cur

                } 

                if { [info exists needquote($c)] && $needquote($c)} {
                    set value [html_quote $value]
                } else {
                    set value "<nobr>$value</nobr>"
                }
                pnl "<td $nowrap>$value"
            }
            if {$dotweak} {
                set value [lvarpop result]
                set prodarray($value) 1
                set value [lvarpop result]
                set statusarray($value) 1
            }
            pnl "\n"
        }
    }
}
puts ""
puts "--ThisRandomString"

set toolong 0
puts "Content-type: text/html"
if { [info exists buglist] } {
    if {[clength $buglist] < 4000} {
        puts "Set-Cookie: BUGLIST=$buglist"
    } else {
        puts "Set-Cookie: BUGLIST="
        set toolong 1
    }
}
puts ""
set env(TZ) PST8PDT

PutHeader "Bug List" "Bug List"

puts -nonewline "
<CENTER>
<B>[fmtclock [getclock ]]</B>"
if {[info exists FORM(debug)]} { puts "<PRE>$query</PRE>" }

if {$toolong} {
    puts "<h2>This list is too long for bugzilla's little mind; the"
    puts "Next/Prev/First/Last buttons won't appear.</h2>"
}

set cdata [ split [read_file -nonewline "comments"] "\n" ]
random seed
puts {<HR><I><A HREF="newquip.html">}
puts [lindex $cdata [random [llength $cdata]]]</I></A></CENTER>
puts "<HR SIZE=10>$tablestart"
puts $bugl
puts "</TABLE>"

switch $count {
    0 {
        puts "Zarro Boogs found."
    }
    1 {
        puts "One bug found."
    }
    default {
        puts "$count bugs found."
    }
}

if {$dotweak} {
    GetVersionTable
    puts "
<SCRIPT>
numelements = document.changeform.elements.length;
function SetCheckboxes(value) {
    for (var i=0 ; i<numelements ; i++) {
        item = document.changeform.elements\[i\];
        item.checked = value;
    }
}
document.write(\" <input type=button value=\\\"Uncheck All\\\" onclick=\\\"SetCheckboxes(false);\\\"> <input type=button value=\\\"Check All\\\" onclick=\\\"SetCheckboxes(true);\\\">\");
</SCRIPT>"
    set resolution_popup [make_options $legal_resolution_no_dup FIXED]
    GetVersionTable
    set prod_list [array names prodarray]
    set list $prod_list
    set legal_target_versions $versions([lvarpop list])
    foreach p $list {
        set legal_target_versions [intersect $legal_target_versions \
                                       $versions($p)]
    }
    set version_popup [make_options \
                              [concat "-blank-" $legal_target_versions] \
                              $dontchange]
    set platform_popup [make_options $legal_platform $dontchange]
    set priority_popup [make_options $legal_priority $dontchange]
    set sev_popup [make_options $legal_severity $dontchange]
    if {[llength $prod_list] == 1} {
        set prod_list [lindex $prod_list 0 ]
        set legal_component [linsert $components($prod_list) 0 { }]
    } else {
        set legal_component { }
    }

    set component_popup [make_options $legal_component $dontchange]

    set product_popup [make_options $legal_product $dontchange]


    puts "
<hr>
<TABLE>
<TR>
    <TD ALIGN=RIGHT><B>Product:</B></TD>
    <TD><SELECT NAME=product>$product_popup</SELECT></TD>
    <TD ALIGN=RIGHT><B>Version:</B></TD>
    <TD><SELECT NAME=version>$version_popup</SELECT></TD>
<TR>
    <TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#rep_platform\">Platform:</A></B></TD>
    <TD><SELECT NAME=rep_platform>$platform_popup</SELECT></TD>
    <TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#priority\">Priority:</A></B></TD>
    <TD><SELECT NAME=priority>$priority_popup</SELECT></TD>
</TR>
<TR>
    <TD ALIGN=RIGHT><B>Component:</B></TD>
    <TD><SELECT NAME=component>$component_popup</SELECT></TD>
    <TD ALIGN=RIGHT><B><A HREF=\"bug_status.html#severity\">Severity:</A></B></TD>
    <TD><SELECT NAME=bug_severity>$sev_popup</SELECT></TD>
</TR>
</TABLE>

<INPUT NAME=multiupdate value=Y TYPE=hidden>

<B>Additional Comments:</B>
<BR>
<TEXTAREA WRAP=HARD NAME=comment ROWS=5 COLS=80></TEXTAREA><BR>"

    # knum is which knob number we're generating, in javascript terms.

    set knum 0
    puts "
<INPUT TYPE=radio NAME=knob VALUE=none CHECKED>
        Do nothing else<br>"
    incr knum
    puts "
<INPUT TYPE=radio NAME=knob VALUE=accept>
        Accept bugs (change status to <b>ASSIGNED</b>)<br>"
    incr knum
    if {![info exists statusarray(CLOSED)] && \
            ![info exists statusarray(VERIFIED)] && \
            ![info exists statusarray(RESOLVED)]} {
        puts "
<INPUT TYPE=radio NAME=knob VALUE=clearresolution>
        Clear the resolution<br>"
        incr knum
        puts "
<INPUT TYPE=radio NAME=knob VALUE=resolve>
        Resolve bugs, changing <A HREF=\"bug_status.html\">resolution</A> to
        <SELECT NAME=resolution
          ONCHANGE=\"document.changeform.knob\[$knum\].checked=true\">
          $resolution_popup</SELECT><br>"
        incr knum
    }
    if {![info exists statusarray(NEW)] && \
            ![info exists statusarray(ASSIGNED)] && \
            ![info exists statusarray(REOPENED)]} {
        puts "
<INPUT TYPE=radio NAME=knob VALUE=reopen> Reopen bugs<br>"
        incr knum
    }
    if {[llength [array names statusarray]] == 1} {
        if {[info exists statusarray(RESOLVED)]} {
            puts "
<INPUT TYPE=radio NAME=knob VALUE=verify>
        Mark bugs as <b>VERIFIED</b><br>"
            incr knum
        }
        if {[info exists statusarray(VERIFIED)]} {
            puts "
<INPUT TYPE=radio NAME=knob VALUE=close>
        Mark bugs as <b>CLOSED</b><br>"
            incr knum
        }
    }
    puts "
<INPUT TYPE=radio NAME=knob VALUE=reassign> 
        <A HREF=\"bug_status.html#assigned_to\">Reassign</A> bugs to
        <INPUT NAME=assigned_to SIZE=32
          ONCHANGE=\"document.changeform.knob\[$knum\].checked=true\"
          VALUE=\"$COOKIE(Bugzilla_login)\"><br>"
    incr knum
    puts "<INPUT TYPE=radio NAME=knob VALUE=reassignbycomponent>
          Reassign bugs to owner of selected component<br>"
    incr knum

    puts "
<p>
<font size=-1>
To make changes to a bunch of bugs at once:
<ol>
<li> Put check boxes next to the bugs you want to change.
<li> Adjust above form elements.  (It's <b>always</b> a good idea to add some
     comment explaining what you're doing.)
<li> Click the below \"Commit\" button.
</ol></font>
<INPUT TYPE=SUBMIT VALUE=Commit>
</FORM><hr>"
}


if {$count > 0} {
  puts "<FORM METHOD=POST ACTION=\"long_list.cgi\">
<INPUT TYPE=HIDDEN NAME=buglist VALUE=$buglist>
<INPUT TYPE=SUBMIT VALUE=\"Long Format\">
<A HREF=\"query.cgi\">Query Page</A>
<A HREF=\"colchange.cgi?$buffer\">Change columns</A>
</FORM>"
    if {!$dotweak && $count > 1} {
        puts "<A HREF=\"buglist.cgi?[set fields]&tweak=1\">Make changes to several of these bugs at once.</A>"
    }
}
puts "--ThisRandomString--"
flush stdout

#
# Below is second part of hideous "if catch" stuff from above. 
#
#
# 
# }]} {
#     exec /usr/lib/sendmail -t << "To: terry@mozilla.org
# 
# 
# $query
# 
# $errorInfo
# "
# }