Documentation Source Text

Check-in [ef7dae4ce8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update the checklist.tcl script to align with the latest code on the website.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ef7dae4ce8709cac7478175d16d3f5887c57ea144dd4e5d1777c8484a52f5c83
User & Date: drh 2019-07-26 20:22:22
Context
2019-07-27
15:13
Fixes to the checklist CGI so that it works better as a Fossil CGI extension. check-in: 41933da084 user: drh tags: trunk
2019-07-26
20:22
Update the checklist.tcl script to align with the latest code on the website. check-in: ef7dae4ce8 user: drh tags: trunk
2019-07-17
13:02
Preliminary documentation for the enhancements to index_info and index_xinfo to support viewing the on-disk representation of WITHOUT ROWID tables. check-in: 296e23a4b8 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to misc/checklist.tcl.

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
...
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
...
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
...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
...
505
506
507
508
509
510
511




512
513
514
515
516
517
518
519
...
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
...
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
...
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
...
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
...
843
844
845
846
847
848
849

850
851
852
853

854
855
856
857
858
859
#            local machine.
#       (4b) Run "wapptclsh checklist.tcl --server 8080" for an HTTP server.
#       (4c) Make this script a CGI script according to however CGI works
#            on your web server
#       (4d) Run "wapptclsh checklist.tcl --scgi 9000" to start an SCGI
#            server, then configure Nginx to relay requests to TCP port 9000.
#
# This particular version of the checklist.tcl script has been customized for
# the SQLite website.


#
set DATADIR /checklist  ;# Edit to be the directory holding checklist databases

package require wapp

proc sqlite-header-text {} {
  wapp-content-security-policy "default-src 'self' 'unsafe-inline'"
  wapp-trim {
    <html><head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link href="/sqlite.css" rel="stylesheet">
  }
  wapp-trim {
    <style>
    h1 { text-align: center; }
    div.ckcom {
      font-size: 80%;
      font-style: italic;
      white-space: pre;
    }
    span.ckuid {
      font-size: 80%;
      cursor: pointer;
    }
    div.cklstmenu {
      text-align: center;
      border: 1px solid black;
      padding: 2ex;
    }
    div.cklstmenu a {
      margin: 0 1.5ex;
    }
    p.error {
      font-weight: bold;
      color: red;
    }
    #editBox {
      display: none;
      border: 1px solid black;
    }
    </style>
  }
  wapp-trim {
    <title>SQLite Release Checklist</title>
    </head>
    <body>
    <div class=nosearch>
    <a href="index.html">
    <img class="logo" src="/images/sqlite370_banner.gif" alt="SQLite" border="0">
    </a>
    <div><!-- IE hack to prevent disappearing logo --></div>
    <div class="tagline desktoponly">
    Small. Fast. Reliable.<br>Choose any three.
    </div>
    <div class="menu mainmenu">
    <ul>
    <li><a href="index.html">Home</a>
    <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
    <li class='wideonly'><a href='/about.html'>About</a>
    <li class='desktoponly'><a href="/docs.html">Documentation</a>
    <li class='desktoponly'><a href="/download.html">Download</a>
    <li class='wideonly'><a href='/copyright.html'>License</a>
    <li class='desktoponly'><a href="/support.html">Support</a>
    <li class='desktoponly'><a href="/prosupport.html">Purchase</a>
    <li class='search' id='search_menubutton'>
    <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
    </ul>
    </div>
    <div class="menu submenu" id="submenu">
    <ul>
    <li><a href='/about.html'>About</a>
    <li><a href='/docs.html'>Documentation</a>
    <li><a href='/download.html'>Download</a>
    <li><a href='/support.html'>Support</a>
    <li><a href='/prosupport.html'>Purchase</a>
    </ul>
    </div>
    <div class="searchmenu" id="searchmenu">
    <form method="GET" action="/search">
    <select name="s" id="searchtype">
    <option value="d">Search Documentation</option>
    <option value="c">Search Changelog</option>
    </select>
    <input type="text" name="q" id="searchbox" value="">
    <input type="submit" value="Go">
    </form>
    </div>
    </div>
    <script>
    function toggle_div(nm) {
    var w = document.getElementById(nm);
    if( w.style.display=="block" ){
    w.style.display = "none";
    }else{
    w.style.display = "block";
    }
    }
    function toggle_search() {
    var w = document.getElementById("searchmenu");
    if( w.style.display=="block" ){
    w.style.display = "none";
    } else {
    w.style.display = "block";
    setTimeout(function(){
    document.getElementById("searchbox").focus()
    }, 30);
    }
    }
    function div_off(nm){document.getElementById(nm).style.display="none";}
    window.onbeforeunload = function(e){div_off("submenu");}
    /* Disable the Search feature if we are not operating from CGI, since */
    /* Search is accomplished using CGI and will not work without it. */
    if( !location.origin.match || !location.origin.match(/http/) ){
    document.getElementById("search_menubutton").style.display = "none";
    }
    /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
    function hideorshow(btn,obj){
    var x = document.getElementById(obj);
    var b = document.getElementById(btn);
    if( x.style.display!='none' ){
    x.style.display = 'none';
    b.innerHTML='show';
    }else{
    x.style.display = '';
    b.innerHTML='hide';
    }
    return false;
    }
    </script>
    </div>
  }

}

# Any unknown URL dispatches to this routine.  List all available
# checklists.
#
proc wapp-default {} {
  wapp-page-listing
}

# List all available checklists.
#
proc wapp-page-listing {} {
  global DATADIR
  sqlite-header-text
  wapp-trim {
    <h1 align='center'>Release Checklist Catalog</h1>
    <ol>

  }

  foreach dbfile [lsort -decreasing [glob -nocomplain $DATADIR/*.db]] {
    set name [file rootname [file tail $dbfile]]
    if {[regexp {^3(\d\d)(\d\d)(\d\d)$} $name all v1 v2 v3]} {
      foreach x {v1 v2 v3} {
        set $x [string trimleft [set $x] 0]
        if {[set $x]==""} {set $x 0}
      }
      set dname "Version 3.$v1.$v2"
      if {$v3!="0"} {
        append dname .$v3
      }
    } elseif {$name=="0demo"} {
      set dname "Test Checklist"
    } else {
      continue
    }
    set url [wapp-param BASE_URL]/$name/index
    wapp-subst {<li><a href='%url($url)'>%html($dname)</a>\n}
  }
  wapp-subst {</ol>\n}
}

# Show the CGI environment for testing purposes.
#
proc wapp-page-env {} {
  wapp-subst {<h1>Environment</h1>\n}




  wapp-subst {<pre>%html([wapp-debug-env])</pre>\n}







}

# Check user permissions by looking at the login/password in the
# checklist-login cookie.  Set the following environment variables:
#
#     CKLIST_USER      Name of the user.  Empty string if not logged in
#     CKLIST_WRITE     True if the user is allowed to make updates
#     CKLIST_ADMIN     True if the user is an administrator.
#
# The database should already be open.
#
proc checklist-verify-login {} {
  set x [wapp-param checklist-login]
  set user {}
  set write 0
  set admin 0
  set u {}
  set p {}
  foreach {u p} [split $x ,] {
    if {[db exists {SELECT 1 FROM config
                     WHERE name=('user-'||$u)
                       AND hex(value)=$p}]} {
      set write 1
      set user $u
      if {[db exists {SELECT 1 FROM config WHERE name=('admin-'||$u)}]} {
        set admin 1
      }




    }
    break;
  }
  wapp-set-param CKLIST_ADMIN $admin
  wapp-set-param CKLIST_WRITE $write
  wapp-set-param CKLIST_USER $user
}

# Print the common header shown on all pages
#
# Return 1 to abort.  Return 0 to continue with page generation.
#
proc checklist-common-header {} {
................................................................................
    wapp-redirect listing
    return 1
  }
  sqlite3 db $dbfile -create 0
  db timeout 1000
  db eval BEGIN
  set title [db one {SELECT value FROM config WHERE name='title'}]
  sqlite-header-text
  wapp-trim {
    <h1>%html($title)</h1>
  }
  checklist-verify-login
  wapp-subst {<div class="cklstmenu">\n}

  set this [wapp-param PATH_HEAD]
  if {$this!="index"} {
    wapp-subst {<a href='index'>checklist</a>\n}
  }
  set write [wapp-param CKLIST_WRITE 0]
  if {$write==0 && $this!="login"} {
    wapp-subst {<a href='login'>login</a>\n}
  }
  if {$write==1 && $this!="logout"} {
    wapp-subst {<a href='logout'>%html([wapp-param CKLIST_USER])-logout</a>\n}
  }
  set admin [wapp-param CKLIST_ADMIN 0]
  if {$admin} {
    if {$this!="sql"} {
      wapp-subst {<a href='sql'>sql</a>\n}
    }
    if {$this!="cklistedit"} {
      wapp-subst {<a href='cklistedit'>edit-checklist</a>\n}
    }
  }
  wapp-subst {<a href='../listing'>catalog</a>\n}
  wapp-subst {</div>\n}
  return 0
}

# Close out a web page.  Close the database connection that was opened
# by checklist-common-header.
#
proc checklist-common-footer {} {
  wapp-subst {</body></html>}
  catch {db close}
}

# Draw the login screen
#
proc wapp-page-login {} {
  if {[checklist-common-header]} return
  if {[string match https:* [wapp-param BASE_URL]]==0
       && [wapp-param REMOTE_ADDR]!="127.0.0.1"} {
    wapp-subst {<p class="error">Login via HTTPS only</p>}
    checklist-common-footer
    return
  }
  if {[wapp-param SAME_ORIGIN]
   && [wapp-param-exists u]
   && [wapp-param-exists p]
  } {
    set u [wapp-param u]
    set p [wapp-param p]
    set px [db one {SELECT hex($p)}]
    set ok [db exists {SELECT 1 FROM config
                        WHERE name=('user-'||$u)
                          AND hex(value)=$px}]
    if {$ok} {
      wapp-set-cookie checklist-login $u,$px
      wapp-redirect index
      return
    }
    wapp-subst {<p class='error'>Invalid username or password</p>\n}
  }
  if {![wapp-param-exists HTTP_REFERER]} {
    wapp-trim {
       <h2>Warning: No "Referer" header</h2>
       <p> As a defense against cross-site request forgeries, this website
       ignores all POST requests that omit the "Referer:" from the header.
       The request that resulted in this page has no "Referer:" entry 
       in the header.
       So, unless something changes, you won't be able to log in.</p>
    }
  }
  wapp-trim {
    <form method='POST' action='login'>
    <table border="0">
    <tr><td align='right'>Login:&nbsp;</td>
        <td><input type='text' name='u' width='20'></td></tr>
    <tr><td align='right'>Password:&nbsp;</td>
        <td><input type='password' name='p' width='20'></td></tr>
    <tr><td><td><input type='submit' value='Login'></td></tr>
    </table></form>
  }
  checklist-common-footer
}

# Draw the logout screen
#
proc wapp-page-logout {} {
  if {[checklist-common-header]} return
  if {![wapp-param CKLIST_WRITE] || [wapp-param-exists logout]} {
    wapp-clear-cookie checklist-login
    wapp-redirect index
    return
  }
  if {[wapp-param-exists cancel]} {
    wapp-redirect index
    return
  }
  set u [wapp-param CKLIST_USER]
  wapp-trim {
    <form method='POST' action='logout'>
    <input type='submit' name='logout' value='%html($u) Logout'>
    <input type='submit' name='cancel' value='Cancel'>
    </form>
  }
  checklist-common-footer
}

# Show the main checklist page
#
proc wapp-page-index {} {
  if {[checklist-common-header]} return
  set level 0
  db eval {SELECT seq, printf('%016llx',itemid) AS itemid, txt
           FROM checklist ORDER BY seq} {
................................................................................
    wapp-subst {{"user":"","canWrite":0,"isAdmin":0}}
  } else {
    set u [wapp-param CKLIST_USER]
    set ia [wapp-param CKLIST_ADMIN]
    wapp-subst {{"user":"%string($u)","canWrite":1,"isAdmin":%qp($ia)}}
  }
  wapp-subst {</script>\n}


  wapp-subst {<script src='cklist.js'></script>\n}
  checklist-common-footer
}




































# The javascript for the main checklist page goes here
#
proc wapp-page-cklist.js {} {
  wapp-mimetype text/javascript
  wapp-cache-control max-age=86400

  wapp {
    function cklistAjax(uri,data,callback){
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function(){
        if(xhttp.readyState!=4) return
        if(!xhttp.responseText) return
        var jx = JSON.parse(xhttp.responseText);
        callback(jx);
................................................................................
        xhttp.send(data)
      }else{
        xhttp.open("GET",uri,true);
        xhttp.send();
      }
    }
    function cklistClr(stat){
      stat = stat.replace(/\++/g,'');
      if(stat=="ok") return '#00a000';
      if(stat=="prelim") return '#0080ff';
      if(stat=="fail") return '#a00028';
      if(stat=="review") return '#007088';
      if(stat=="pending") return '#4f0080';
      if(stat=="retest") return '#904800';
      return '#000000';
................................................................................
        }
        if( editItem && editItem.id==name ){
          document.getElementById("editStatus").value = x.status;
          document.getElementById("editCom").value = x.comment;
        }
      }
    }




    cklistAjax('jstat',null,cklistApplyJstat);
    var userNode = document.getElementById("cklistUser");
    var userInfo = JSON.parse(userNode.textContent||userNode.innerText);
    if(userInfo.canWrite){
      var allItem = document.getElementsByClassName("ckitem");
      for(var i=0; i<allItem.length; i++){
        allItem[i].style.cursor = "pointer";
      }
................................................................................
        editItem = null;
        return;
      }
      editBox.style.display = "block";
      editItem = e;
      historyOff(e.id.substr(5))
      editItem.appendChild(editBox);


      cklistAjax("jstat?itemid="+e.id.substr(5),null,cklistApplyJstat);
      document.getElementById("cancelBtn").onclick = function(event){
        event.stopPropagation();
        editItem.removeChild(editBox);
        editItem = null;
      }
      document.getElementById("applyBtn").onclick = function(event){
        var data = "update=" + editItem.id.substr(5);
        var e = document.getElementById("editStatus");
        data += "&status=" + escape(e.value);
        e = document.getElementById("editCom");
        data += "&comment=" + escape(e.value);
        cklistAjax("jstat",data,cklistApplyJstat);
        editItem.removeChild(editBox);
        editItem = null;
        event.stopPropagation();
      }
      document.getElementById("editForm").onsubmit = function(){
        return false;
      }
................................................................................
  # wapp-subst {window.alert("Javascript loaded");\n}
}

# The /jstat page returns JSON that describes the current
# status of all elements of the checklist.
#
# If the update query parameter exists and is not an empty string,
# and if checklist-login is a valid login for a writer, then revise
# the ckitem entry where itemid=$update using query parameters
# {update->itemid,status,comment} and with owner set to the login user,
# before returning the results.
#
# If the itemid query parameter exists and is not an empty string,
# then return only the status to that one checklist item.  Otherwise,
# return the status of all checklist items.
................................................................................
  sqlite3 db $dbfile
  db eval BEGIN
  set update [wapp-param update]
  if {$update!=""} {
    checklist-verify-login
    if {[wapp-param CKLIST_WRITE 0] && [scan $update %x update]==1} {
      set status [wapp-param status]
      set comment [wapp-param comment]
      set owner [wapp-param CKLIST_USER]
      db eval {
         REPLACE INTO ckitem(itemid,mtime,status,owner,comment)
          VALUES($update,julianday('now'),$status,$owner,$comment);
         INSERT INTO history(itemid,mtime,status,owner,comment)
          VALUES($update,julianday('now'),$status,$owner,$comment);
      }
................................................................................
  if {[checklist-common-header]} return
  if {![wapp-param CKLIST_ADMIN 0]} {
    wapp-redirect index
    return
  }
  set sql [string trimright [wapp-param sql]]
  wapp-trim {
    <form method="POST" action="sql"><table border="0">
    <tr><td valign="top">SQL:&nbsp;
    <td><textarea name="sql" rows="5" cols="60">%html($sql)</textarea>
    <tr><td><td><input type="submit" value="Run">
    </table></form>
  }
  if {$sql!=""} { 
    set i 0
................................................................................
      wapp-set-param PATH_HEAD $head
      wapp-set-param PATH_TAIL [string trimleft $tail /]
      wapp-set-param SELF_URL /$head
    } else {
      wapp-set-param PATH_HEAD {}
      wapp-set-param PATH_TAIL {}
    }

  } else {
    # Not a valid database.  Change the method to list all available
    # databases.
    wapp-set-param OBJECT {}

    if {$dbname!="env"} {wapp-set-param PATH_HEAD listing}
  }
}

# Start up the web-server
wapp-start $::argv







|
|
>
>





<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<











<

<
<
>

>


<
<
<
<
<
<
<
<
<
<
<
<
<
<

|

|





|
>
>
>
>
|
>
>
>
>
>
>
>












|
|
|
|
|
<
<
<
<
<
<
<
<
<
|
>
>
>
>
|
<
<
<
|
|







 







<

|


|
>


<
<
<
<
|
<
<
<




|


|


|








|



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
>
|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
|







 







|







 







>
>
>
>
|







 







>
>
|











|







 







|







 







|







 







|







 







>




>






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
...
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
...
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
...
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
...
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
...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
...
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
#            local machine.
#       (4b) Run "wapptclsh checklist.tcl --server 8080" for an HTTP server.
#       (4c) Make this script a CGI script according to however CGI works
#            on your web server
#       (4d) Run "wapptclsh checklist.tcl --scgi 9000" to start an SCGI
#            server, then configure Nginx to relay requests to TCP port 9000.
#
# Update 2019-07-26:
# The script has been revised to run as a Fossil extension.  It now uses
# Fossil for login and user credentials.  Anyone with check-in privilege
# can edit.  Anyone with Setup privilege can be a checklist admin.
#
set DATADIR /checklist  ;# Edit to be the directory holding checklist databases

package require wapp



































































































































# Any unknown URL dispatches to this routine.  List all available
# checklists.
#
proc wapp-default {} {
  wapp-page-listing
}

# List all available checklists.
#
proc wapp-page-listing {} {
  global DATADIR

  wapp-trim {


    <div class='fossil-doc' data-title='Available Checklists'>
  }
  wapp-subst {<ol>\n}
  foreach dbfile [lsort -decreasing [glob -nocomplain $DATADIR/*.db]] {
    set name [file rootname [file tail $dbfile]]














    set url [wapp-param BASE_URL]/$name/index
    wapp-subst {<li><a href='%url($url)'>%html($name)</a>\n}
  }
  wapp-subst {</ol>\n</html>\n}
}

# Show the CGI environment for testing purposes.
#
proc wapp-page-env {} {
  sqlite3 db :memory:
  set v [db one {SELECT sqlite_source_id()}]
  checklist-verify-login
  wapp-trim {
     <div class='fossil-doc' data-title='Wapp Environment'>
     <pre>%html([wapp-debug-env])}
  global env
  foreach e [array names env] {
    if {![string match FOSSIL* $e]} continue
    set txt "$e = [list $env($e)]\n"
    wapp-subst {%html($txt)}
  }
  wapp-subst {SQLite = %html($v)</pre>\n</div>\n}
}

# Check user permissions by looking at the login/password in the
# checklist-login cookie.  Set the following environment variables:
#
#     CKLIST_USER      Name of the user.  Empty string if not logged in
#     CKLIST_WRITE     True if the user is allowed to make updates
#     CKLIST_ADMIN     True if the user is an administrator.
#
# The database should already be open.
#
proc checklist-verify-login {} {
  global env
  if {[info exists env(FOSSIL_USER)]} {
    wapp-set-param CKLIST_USER $env(FOSSIL_USER)
  } else {
    wapp-set-param CKLIST_USER {}









  }
  if {[info exists env(FOSSIL_CAPABILITIES)]} {
    set perm $env(FOSSIL_CAPABILITIES)
  } else {
    set perm {}
  }



  wapp-set-param CKLIST_WRITE [string match {*i*} $perm]
  wapp-set-param CKLIST_ADMIN [string match {*[as]*} $perm]
}

# Print the common header shown on all pages
#
# Return 1 to abort.  Return 0 to continue with page generation.
#
proc checklist-common-header {} {
................................................................................
    wapp-redirect listing
    return 1
  }
  sqlite3 db $dbfile -create 0
  db timeout 1000
  db eval BEGIN
  set title [db one {SELECT value FROM config WHERE name='title'}]

  wapp-trim {
    <div class='fossil-doc' data-title='%html($title)'>
  }
  checklist-verify-login
  wapp-subst {<div class="submenu">\n}
  set base [wapp-param BASE]
  set this [wapp-param PATH_HEAD]
  if {$this!="index"} {




    wapp-subst {<a href='%html($base/index)'>checklist</a>\n}



  }
  set admin [wapp-param CKLIST_ADMIN 0]
  if {$admin} {
    if {$this!="sql"} {
      wapp-subst {<a href='%html($base/sql)'>sql</a>\n}
    }
    if {$this!="cklistedit"} {
      wapp-subst {<a href='%html($base/cklistedit)'>edit-checklist</a>\n}
    }
  }
  wapp-subst {<a href='%html([file dir $base]/listing)'>catalog</a>\n}
  wapp-subst {</div>\n}
  return 0
}

# Close out a web page.  Close the database connection that was opened
# by checklist-common-header.
#
proc checklist-common-footer {} {
  wapp-subst {</div>}
  catch {db close}
}










































































# Show the main checklist page
#
proc wapp-page-index {} {
  if {[checklist-common-header]} return
  set level 0
  db eval {SELECT seq, printf('%016llx',itemid) AS itemid, txt
           FROM checklist ORDER BY seq} {
................................................................................
    wapp-subst {{"user":"","canWrite":0,"isAdmin":0}}
  } else {
    set u [wapp-param CKLIST_USER]
    set ia [wapp-param CKLIST_ADMIN]
    wapp-subst {{"user":"%string($u)","canWrite":1,"isAdmin":%qp($ia)}}
  }
  wapp-subst {</script>\n}

  set base [wapp-param BASE]
  wapp-subst {<script src='%html($base/cklist.js)'></script>\n}
  checklist-common-footer
}

# The CSS for the main checklist page goes here
#
proc wapp-page-style.css {} {
  wapp-mimetype text/css
  wapp-cache-control max-age=86400
  wapp {
    h1 { text-align: center; }
    div.ckcom {
      font-size: 80%;
      font-style: italic;
      white-space: pre;
    }
    span.ckuid {
      font-size: 80%;
      cursor: pointer;
    }
    div.mainmenu {
      text-align: center;
      border: 1px solid black;
      padding: 2ex;
    }
    div.mainmenu a {
      margin: 0 1.5ex;
    }
    p.error {
      font-weight: bold;
      color: red;
    }
    #editBox {
      display: none;
      border: 1px solid black;
    }
  }
}

# The javascript for the main checklist page goes here
#
proc wapp-page-cklist.js {} {
  wapp-mimetype text/javascript
  wapp-cache-control max-age=86400
  set base [wapp-param BASE]
  wapp-trim {
    function cklistAjax(uri,data,callback){
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function(){
        if(xhttp.readyState!=4) return
        if(!xhttp.responseText) return
        var jx = JSON.parse(xhttp.responseText);
        callback(jx);
................................................................................
        xhttp.send(data)
      }else{
        xhttp.open("GET",uri,true);
        xhttp.send();
      }
    }
    function cklistClr(stat){
      stat = stat.replace(/\\++/g,'');
      if(stat=="ok") return '#00a000';
      if(stat=="prelim") return '#0080ff';
      if(stat=="fail") return '#a00028';
      if(stat=="review") return '#007088';
      if(stat=="pending") return '#4f0080';
      if(stat=="retest") return '#904800';
      return '#000000';
................................................................................
        }
        if( editItem && editItem.id==name ){
          document.getElementById("editStatus").value = x.status;
          document.getElementById("editCom").value = x.comment;
        }
      }
    }
    function clearEditBox(){
      document.getElementById("editStatus").value = 'ok';
      document.getElementById("editCom").value = '';
    }
    cklistAjax("%string($base/jstat)",null,cklistApplyJstat);
    var userNode = document.getElementById("cklistUser");
    var userInfo = JSON.parse(userNode.textContent||userNode.innerText);
    if(userInfo.canWrite){
      var allItem = document.getElementsByClassName("ckitem");
      for(var i=0; i<allItem.length; i++){
        allItem[i].style.cursor = "pointer";
      }
................................................................................
        editItem = null;
        return;
      }
      editBox.style.display = "block";
      editItem = e;
      historyOff(e.id.substr(5))
      editItem.appendChild(editBox);
      clearEditBox();
      var u = "%string($base)/jstat?itemid=" + e.id.substr(5);
      cklistAjax(u,null,cklistApplyJstat);
      document.getElementById("cancelBtn").onclick = function(event){
        event.stopPropagation();
        editItem.removeChild(editBox);
        editItem = null;
      }
      document.getElementById("applyBtn").onclick = function(event){
        var data = "update=" + editItem.id.substr(5);
        var e = document.getElementById("editStatus");
        data += "&status=" + escape(e.value);
        e = document.getElementById("editCom");
        data += "&comment=" + escape(e.value);
        cklistAjax("%string($base)/jstat",data,cklistApplyJstat);
        editItem.removeChild(editBox);
        editItem = null;
        event.stopPropagation();
      }
      document.getElementById("editForm").onsubmit = function(){
        return false;
      }
................................................................................
  # wapp-subst {window.alert("Javascript loaded");\n}
}

# The /jstat page returns JSON that describes the current
# status of all elements of the checklist.
#
# If the update query parameter exists and is not an empty string,
# and if the login is valid for a writer, then revise
# the ckitem entry where itemid=$update using query parameters
# {update->itemid,status,comment} and with owner set to the login user,
# before returning the results.
#
# If the itemid query parameter exists and is not an empty string,
# then return only the status to that one checklist item.  Otherwise,
# return the status of all checklist items.
................................................................................
  sqlite3 db $dbfile
  db eval BEGIN
  set update [wapp-param update]
  if {$update!=""} {
    checklist-verify-login
    if {[wapp-param CKLIST_WRITE 0] && [scan $update %x update]==1} {
      set status [wapp-param status]
      set comment [string trim [wapp-param comment]]
      set owner [wapp-param CKLIST_USER]
      db eval {
         REPLACE INTO ckitem(itemid,mtime,status,owner,comment)
          VALUES($update,julianday('now'),$status,$owner,$comment);
         INSERT INTO history(itemid,mtime,status,owner,comment)
          VALUES($update,julianday('now'),$status,$owner,$comment);
      }
................................................................................
  if {[checklist-common-header]} return
  if {![wapp-param CKLIST_ADMIN 0]} {
    wapp-redirect index
    return
  }
  set sql [string trimright [wapp-param sql]]
  wapp-trim {
    <form method="POST"><table border="0">
    <tr><td valign="top">SQL:&nbsp;
    <td><textarea name="sql" rows="5" cols="60">%html($sql)</textarea>
    <tr><td><td><input type="submit" value="Run">
    </table></form>
  }
  if {$sql!=""} { 
    set i 0
................................................................................
      wapp-set-param PATH_HEAD $head
      wapp-set-param PATH_TAIL [string trimleft $tail /]
      wapp-set-param SELF_URL /$head
    } else {
      wapp-set-param PATH_HEAD {}
      wapp-set-param PATH_TAIL {}
    }
    wapp-set-param BASE [wapp-param BASE_URL]/$dbname
  } else {
    # Not a valid database.  Change the method to list all available
    # databases.
    wapp-set-param OBJECT {}
    wapp-set-param BASE [wapp-param SCRIPT_NAME]
    if {$dbname!="env"} {wapp-set-param PATH_HEAD listing}
  }
}

# Start up the web-server
wapp-start $::argv