Hex Artifact Content
Not logged in

Artifact 98960a5cdcbfe35e3a27719a526eeb6c61ac0d6f:

File src/tkt.c part of check-in [7a2c37063a] - merge trunk into creole branch by bob on 2009-09-22 07:49:39. Also file src/tkt.c part of check-in [0b76ce7b6b] - Treat NULL ticket fields as empty strings when appending new text. Ticket f6747f854ba62b3 by drh on 2009-09-19 14:33:04.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65  .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75   contains code u
0380: 73 65 64 20 72 65 6e 64 65 72 20 61 6e 64 20 63  sed render and c
0390: 6f 6e 74 72 6f 6c 20 74 69 63 6b 65 74 20 65 6e  ontrol ticket en
03a0: 74 72 79 0a 2a 2a 20 61 6e 64 20 64 69 73 70 6c  try.** and displ
03b0: 61 79 20 70 61 67 65 73 2e 0a 2a 2f 0a 23 69 6e  ay pages..*/.#in
03c0: 63 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68 22  clude "config.h"
03d0: 0a 23 69 6e 63 6c 75 64 65 20 22 74 6b 74 2e 68  .#include "tkt.h
03e0: 22 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 73 65  ".#include <asse
03f0: 72 74 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 54 68 65  rt.h>../*.** The
0400: 20 6c 69 73 74 20 6f 66 20 64 61 74 61 62 61 73   list of databas
0410: 65 20 75 73 65 72 2d 64 65 66 69 6e 65 64 20 66  e user-defined f
0420: 69 65 6c 64 73 20 69 6e 20 74 68 65 20 54 49 43  ields in the TIC
0430: 4b 45 54 20 74 61 62 6c 65 2e 0a 2a 2a 20 54 68  KET table..** Th
0440: 65 20 72 65 61 6c 20 74 61 62 6c 65 20 61 6c 73  e real table als
0450: 6f 20 63 6f 6e 74 61 69 6e 73 20 73 6f 6d 65 20  o contains some 
0460: 61 64 64 69 74 69 6f 6e 20 66 69 65 6c 64 73 20  addition fields 
0470: 66 6f 72 20 69 6e 74 65 72 6e 61 6c 0a 2a 2a 20  for internal.** 
0480: 75 73 65 64 2e 20 20 54 68 65 20 69 6e 74 65 72  used.  The inter
0490: 6e 61 6c 2d 75 73 65 20 66 69 65 6c 64 73 20 62  nal-use fields b
04a0: 65 67 69 6e 20 77 69 74 68 20 22 74 6b 74 5f 22  egin with "tkt_"
04b0: 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20  ..*/.static int 
04c0: 6e 46 69 65 6c 64 20 3d 20 30 3b 0a 73 74 61 74  nField = 0;.stat
04d0: 69 63 20 63 68 61 72 20 2a 2a 61 7a 46 69 65 6c  ic char **azFiel
04e0: 64 20 3d 20 30 3b 20 20 20 20 2f 2a 20 4e 61 6d  d = 0;    /* Nam
04f0: 65 73 20 6f 66 20 64 61 74 61 62 61 73 65 20 66  es of database f
0500: 69 65 6c 64 73 20 2a 2f 0a 73 74 61 74 69 63 20  ields */.static 
0510: 63 68 61 72 20 2a 2a 61 7a 56 61 6c 75 65 20 3d  char **azValue =
0520: 20 30 3b 20 20 20 20 2f 2a 20 4f 72 69 67 69 6e   0;    /* Origin
0530: 61 6c 20 76 61 6c 75 65 73 20 2a 2f 0a 73 74 61  al values */.sta
0540: 74 69 63 20 63 68 61 72 20 2a 2a 61 7a 41 70 70  tic char **azApp
0550: 65 6e 64 20 3d 20 30 3b 20 20 20 2f 2a 20 56 61  end = 0;   /* Va
0560: 6c 75 65 20 74 6f 20 62 65 20 61 70 70 65 6e 64  lue to be append
0570: 65 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6d  ed */../*.** Com
0580: 70 61 72 65 20 74 77 6f 20 65 6e 74 72 69 65 73  pare two entries
0590: 20 69 6e 20 61 7a 46 69 65 6c 64 20 66 6f 72 20   in azField for 
05a0: 73 6f 72 74 69 6e 67 20 70 75 72 70 6f 73 65 73  sorting purposes
05b0: 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 6e  .*/.static int n
05c0: 61 6d 65 43 6d 70 72 28 63 6f 6e 73 74 20 76 6f  ameCmpr(const vo
05d0: 69 64 20 2a 61 2c 20 63 6f 6e 73 74 20 76 6f 69  id *a, const voi
05e0: 64 20 2a 62 29 7b 0a 20 20 72 65 74 75 72 6e 20  d *b){.  return 
05f0: 73 74 72 63 6d 70 28 2a 28 63 68 61 72 2a 2a 29  strcmp(*(char**)
0600: 61 2c 20 2a 28 63 68 61 72 2a 2a 29 62 29 3b 0a  a, *(char**)b);.
0610: 7d 0a 0a 2f 2a 0a 2a 2a 20 4f 62 74 61 69 6e 20  }../*.** Obtain 
0620: 61 20 6c 69 73 74 20 6f 66 20 61 6c 6c 20 66 69  a list of all fi
0630: 65 6c 64 73 20 6f 66 20 74 68 65 20 54 49 43 4b  elds of the TICK
0640: 45 54 20 74 61 62 6c 65 2e 20 20 50 75 74 20 74  ET table.  Put t
0650: 68 65 6d 20 0a 2a 2a 20 69 6e 20 73 6f 72 74 65  hem .** in sorte
0660: 64 20 6f 72 64 65 72 20 69 6e 20 61 7a 46 69 65  d order in azFie
0670: 6c 64 5b 5d 2e 0a 2a 2a 0a 2a 2a 20 41 6c 73 6f  ld[]..**.** Also
0680: 20 61 6c 6c 6f 63 61 74 65 20 73 70 61 63 65 20   allocate space 
0690: 66 6f 72 20 61 7a 56 61 6c 75 65 5b 5d 20 61 6e  for azValue[] an
06a0: 64 20 61 7a 41 70 70 65 6e 64 5b 5d 20 61 6e 64  d azAppend[] and
06b0: 20 69 6e 69 74 69 61 6c 69 7a 65 0a 2a 2a 20 61   initialize.** a
06c0: 6c 6c 20 74 68 65 20 76 61 6c 75 65 73 20 74 68  ll the values th
06d0: 65 72 65 20 74 6f 20 7a 65 72 6f 2e 0a 2a 2f 0a  ere to zero..*/.
06e0: 73 74 61 74 69 63 20 76 6f 69 64 20 67 65 74 41  static void getA
06f0: 6c 6c 54 69 63 6b 65 74 46 69 65 6c 64 73 28 76  llTicketFields(v
0700: 6f 69 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a  oid){.  Stmt q;.
0710: 20 20 69 6e 74 20 69 3b 0a 20 20 69 66 28 20 6e    int i;.  if( n
0720: 46 69 65 6c 64 3e 30 20 29 20 72 65 74 75 72 6e  Field>0 ) return
0730: 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26  ;.  db_prepare(&
0740: 71 2c 20 22 50 52 41 47 4d 41 20 74 61 62 6c 65  q, "PRAGMA table
0750: 5f 69 6e 66 6f 28 74 69 63 6b 65 74 29 22 29 3b  _info(ticket)");
0760: 0a 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65  .  while( db_ste
0770: 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f  p(&q)==SQLITE_RO
0780: 57 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63  W ){.    const c
0790: 68 61 72 20 2a 7a 46 69 65 6c 64 20 3d 20 64 62  har *zField = db
07a0: 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c  _column_text(&q,
07b0: 20 31 29 3b 0a 20 20 20 20 69 66 28 20 73 74 72   1);.    if( str
07c0: 6e 63 6d 70 28 7a 46 69 65 6c 64 2c 22 74 6b 74  ncmp(zField,"tkt
07d0: 5f 22 2c 34 29 3d 3d 30 20 29 20 63 6f 6e 74 69  _",4)==0 ) conti
07e0: 6e 75 65 3b 0a 20 20 20 20 69 66 28 20 6e 46 69  nue;.    if( nFi
07f0: 65 6c 64 25 31 30 3d 3d 30 20 29 7b 0a 20 20 20  eld%10==0 ){.   
0800: 20 20 20 61 7a 46 69 65 6c 64 20 3d 20 72 65 61     azField = rea
0810: 6c 6c 6f 63 28 61 7a 46 69 65 6c 64 2c 20 73 69  lloc(azField, si
0820: 7a 65 6f 66 28 61 7a 46 69 65 6c 64 29 2a 33 2a  zeof(azField)*3*
0830: 28 6e 46 69 65 6c 64 2b 31 30 29 20 29 3b 0a 20  (nField+10) );. 
0840: 20 20 20 20 20 69 66 28 20 61 7a 46 69 65 6c 64       if( azField
0850: 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20 66  ==0 ){.        f
0860: 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 6f 75 74  ossil_fatal("out
0870: 20 6f 66 20 6d 65 6d 6f 72 79 22 29 3b 0a 20 20   of memory");.  
0880: 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20      }.    }.    
0890: 61 7a 46 69 65 6c 64 5b 6e 46 69 65 6c 64 5d 20  azField[nField] 
08a0: 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20  = mprintf("%s", 
08b0: 7a 46 69 65 6c 64 29 3b 0a 20 20 20 20 6e 46 69  zField);.    nFi
08c0: 65 6c 64 2b 2b 3b 0a 20 20 7d 0a 20 20 64 62 5f  eld++;.  }.  db_
08d0: 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20  finalize(&q);.  
08e0: 71 73 6f 72 74 28 61 7a 46 69 65 6c 64 2c 20 6e  qsort(azField, n
08f0: 46 69 65 6c 64 2c 20 73 69 7a 65 6f 66 28 61 7a  Field, sizeof(az
0900: 46 69 65 6c 64 5b 30 5d 29 2c 20 6e 61 6d 65 43  Field[0]), nameC
0910: 6d 70 72 29 3b 0a 20 20 61 7a 41 70 70 65 6e 64  mpr);.  azAppend
0920: 20 3d 20 26 61 7a 46 69 65 6c 64 5b 6e 46 69 65   = &azField[nFie
0930: 6c 64 5d 3b 0a 20 20 6d 65 6d 73 65 74 28 61 7a  ld];.  memset(az
0940: 41 70 70 65 6e 64 2c 20 30 2c 20 73 69 7a 65 6f  Append, 0, sizeo
0950: 66 28 61 7a 41 70 70 65 6e 64 5b 30 5d 29 2a 6e  f(azAppend[0])*n
0960: 46 69 65 6c 64 29 3b 0a 20 20 61 7a 56 61 6c 75  Field);.  azValu
0970: 65 20 3d 20 26 61 7a 41 70 70 65 6e 64 5b 6e 46  e = &azAppend[nF
0980: 69 65 6c 64 5d 3b 0a 20 20 66 6f 72 28 69 3d 30  ield];.  for(i=0
0990: 3b 20 69 3c 6e 46 69 65 6c 64 3b 20 69 2b 2b 29  ; i<nField; i++)
09a0: 7b 0a 20 20 20 20 61 7a 56 61 6c 75 65 5b 69 5d  {.    azValue[i]
09b0: 20 3d 20 22 22 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a   = "";.  }.}../*
09c0: 0a 2a 2a 20 52 65 74 75 72 6e 20 74 68 65 20 69  .** Return the i
09d0: 6e 64 65 78 20 69 6e 74 6f 20 61 7a 46 69 65 6c  ndex into azFiel
09e0: 64 5b 5d 20 6f 66 20 74 68 65 20 67 69 76 65 6e  d[] of the given
09f0: 20 66 69 65 6c 64 20 6e 61 6d 65 2e 0a 2a 2a 20   field name..** 
0a00: 52 65 74 75 72 6e 20 2d 31 20 69 66 20 7a 46 69  Return -1 if zFi
0a10: 65 6c 64 20 69 73 20 6e 6f 74 20 69 6e 20 61 7a  eld is not in az
0a20: 46 69 65 6c 64 5b 5d 2e 0a 2a 2f 0a 73 74 61 74  Field[]..*/.stat
0a30: 69 63 20 69 6e 74 20 66 69 65 6c 64 49 64 28 63  ic int fieldId(c
0a40: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 69 65 6c  onst char *zFiel
0a50: 64 29 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 66  d){.  int i;.  f
0a60: 6f 72 28 69 3d 30 3b 20 69 3c 6e 46 69 65 6c 64  or(i=0; i<nField
0a70: 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 69 66 28 20  ; i++){.    if( 
0a80: 73 74 72 63 6d 70 28 61 7a 46 69 65 6c 64 5b 69  strcmp(azField[i
0a90: 5d 2c 20 7a 46 69 65 6c 64 29 3d 3d 30 20 29 20  ], zField)==0 ) 
0aa0: 72 65 74 75 72 6e 20 69 3b 0a 20 20 7d 0a 20 20  return i;.  }.  
0ab0: 72 65 74 75 72 6e 20 2d 31 3b 0a 7d 0a 0a 2f 2a  return -1;.}../*
0ac0: 0a 2a 2a 20 51 75 65 72 79 20 74 68 65 20 64 61  .** Query the da
0ad0: 74 61 62 61 73 65 20 66 6f 72 20 61 6c 6c 20 54  tabase for all T
0ae0: 49 43 4b 45 54 20 66 69 65 6c 64 73 20 66 6f 72  ICKET fields for
0af0: 20 74 68 65 20 73 70 65 63 69 66 69 63 0a 2a 2a   the specific.**
0b00: 20 74 69 63 6b 65 74 20 77 68 6f 73 65 20 6e 61   ticket whose na
0b10: 6d 65 20 69 73 20 67 69 76 65 6e 20 62 79 20 74  me is given by t
0b20: 68 65 20 22 6e 61 6d 65 22 20 43 47 49 20 70 61  he "name" CGI pa
0b30: 72 61 6d 65 74 65 72 2e 0a 2a 2a 20 4c 6f 61 64  rameter..** Load
0b40: 20 74 68 65 20 76 61 6c 75 65 73 20 66 6f 72 20   the values for 
0b50: 61 6c 6c 20 66 69 65 6c 64 73 20 69 6e 74 6f 20  all fields into 
0b60: 74 68 65 20 69 6e 74 65 72 70 72 65 74 65 72 2e  the interpreter.
0b70: 0a 2a 2a 0a 2a 2a 20 4f 6e 6c 79 20 6c 6f 61 64  .**.** Only load
0b80: 20 74 68 6f 73 65 20 66 69 65 6c 64 73 20 77 68   those fields wh
0b90: 69 63 68 20 64 6f 20 6e 6f 74 20 61 6c 72 65 61  ich do not alrea
0ba0: 64 79 20 65 78 69 73 74 20 61 73 0a 2a 2a 20 76  dy exist as.** v
0bb0: 61 72 69 61 62 6c 65 73 2e 0a 2a 2a 0a 2a 2a 20  ariables..**.** 
0bc0: 46 69 65 6c 64 73 20 6f 66 20 74 68 65 20 54 49  Fields of the TI
0bd0: 43 4b 45 54 20 74 61 62 6c 65 20 74 68 61 74 20  CKET table that 
0be0: 62 65 67 69 6e 20 77 69 74 68 20 22 70 72 69 76  begin with "priv
0bf0: 61 74 65 5f 22 20 61 72 65 0a 2a 2a 20 65 78 70  ate_" are.** exp
0c00: 61 6e 64 65 64 20 75 73 69 6e 67 20 74 68 65 20  anded using the 
0c10: 64 62 5f 72 65 76 65 61 6c 28 29 20 66 75 6e 63  db_reveal() func
0c20: 74 69 6f 6e 2e 20 20 49 66 20 67 2e 6f 6b 52 64  tion.  If g.okRd
0c30: 41 64 64 72 20 69 73 0a 2a 2a 20 74 72 75 65 2c  Addr is.** true,
0c40: 20 74 68 65 6e 20 74 68 65 20 64 62 5f 72 65 76   then the db_rev
0c50: 65 61 6c 28 29 20 66 75 6e 63 74 69 6f 6e 20 77  eal() function w
0c60: 69 6c 6c 20 64 65 63 6f 64 65 20 74 68 65 20 63  ill decode the c
0c70: 6f 6e 74 65 6e 74 0a 2a 2a 20 75 73 69 6e 67 20  ontent.** using 
0c80: 74 68 65 20 43 4f 4e 43 45 41 4c 45 44 20 74 61  the CONCEALED ta
0c90: 62 6c 65 20 73 6f 20 74 68 61 74 20 74 68 65 20  ble so that the 
0ca0: 63 6f 6e 74 65 6e 74 20 6c 65 67 61 62 6c 65 2e  content legable.
0cb0: 0a 2a 2a 20 4f 74 68 65 72 77 69 73 65 2c 20 64  .** Otherwise, d
0cc0: 62 5f 72 65 76 65 61 6c 28 29 20 69 73 20 61 20  b_reveal() is a 
0cd0: 6e 6f 2d 6f 70 20 61 6e 64 20 74 68 65 20 63 6f  no-op and the co
0ce0: 6e 74 65 6e 74 20 72 65 6d 61 69 6e 73 0a 2a 2a  ntent remains.**
0cf0: 20 6f 62 73 63 75 72 65 64 2e 0a 2a 2f 0a 73 74   obscured..*/.st
0d00: 61 74 69 63 20 76 6f 69 64 20 69 6e 69 74 69 61  atic void initia
0d10: 6c 69 7a 65 56 61 72 69 61 62 6c 65 73 46 72 6f  lizeVariablesFro
0d20: 6d 44 62 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e  mDb(void){.  con
0d30: 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 0a  st char *zName;.
0d40: 20 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20    Stmt q;.  int 
0d50: 69 2c 20 6e 2c 20 73 69 7a 65 2c 20 6a 3b 0a 0a  i, n, size, j;..
0d60: 20 20 7a 4e 61 6d 65 20 3d 20 50 44 28 22 6e 61    zName = PD("na
0d70: 6d 65 22 2c 22 2d 6e 6f 6e 65 2d 22 29 3b 0a 20  me","-none-");. 
0d80: 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20   db_prepare(&q, 
0d90: 22 53 45 4c 45 43 54 20 64 61 74 65 74 69 6d 65  "SELECT datetime
0da0: 28 74 6b 74 5f 6d 74 69 6d 65 29 20 41 53 20 74  (tkt_mtime) AS t
0db0: 6b 74 5f 64 61 74 65 74 69 6d 65 2c 20 2a 22 0a  kt_datetime, *".
0dc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0dd0: 20 22 20 20 46 52 4f 4d 20 74 69 63 6b 65 74 20   "  FROM ticket 
0de0: 57 48 45 52 45 20 74 6b 74 5f 75 75 69 64 20 47  WHERE tkt_uuid G
0df0: 4c 4f 42 20 27 25 71 2a 27 22 2c 20 7a 4e 61 6d  LOB '%q*'", zNam
0e00: 65 29 3b 0a 20 20 69 66 28 20 64 62 5f 73 74 65  e);.  if( db_ste
0e10: 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f  p(&q)==SQLITE_RO
0e20: 57 20 29 7b 0a 20 20 20 20 6e 20 3d 20 64 62 5f  W ){.    n = db_
0e30: 63 6f 6c 75 6d 6e 5f 63 6f 75 6e 74 28 26 71 29  column_count(&q)
0e40: 3b 0a 20 20 20 20 66 6f 72 28 69 3d 30 3b 20 69  ;.    for(i=0; i
0e50: 3c 6e 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20  <n; i++){.      
0e60: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c  const char *zVal
0e70: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78   = db_column_tex
0e80: 74 28 26 71 2c 20 69 29 3b 0a 20 20 20 20 20 20  t(&q, i);.      
0e90: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d  const char *zNam
0ea0: 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 6e 61  e = db_column_na
0eb0: 6d 65 28 26 71 2c 20 69 29 3b 0a 20 20 20 20 20  me(&q, i);.     
0ec0: 20 63 68 61 72 20 2a 7a 52 65 76 65 61 6c 65 64   char *zRevealed
0ed0: 20 3d 20 30 3b 0a 20 20 20 20 20 20 69 66 28 20   = 0;.      if( 
0ee0: 7a 56 61 6c 3d 3d 30 20 29 7b 0a 20 20 20 20 20  zVal==0 ){.     
0ef0: 20 20 20 7a 56 61 6c 20 3d 20 22 22 3b 0a 20 20     zVal = "";.  
0f00: 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 73 74      }else if( st
0f10: 72 6e 63 6d 70 28 7a 4e 61 6d 65 2c 20 22 70 72  rncmp(zName, "pr
0f20: 69 76 61 74 65 5f 22 2c 20 38 29 3d 3d 30 20 29  ivate_", 8)==0 )
0f30: 7b 0a 20 20 20 20 20 20 20 20 7a 56 61 6c 20 3d  {.        zVal =
0f40: 20 7a 52 65 76 65 61 6c 65 64 20 3d 20 64 62 5f   zRevealed = db_
0f50: 72 65 76 65 61 6c 28 7a 56 61 6c 29 3b 0a 20 20  reveal(zVal);.  
0f60: 20 20 20 20 7d 0a 20 20 20 20 20 20 66 6f 72 28      }.      for(
0f70: 6a 3d 30 3b 20 6a 3c 6e 46 69 65 6c 64 3b 20 6a  j=0; j<nField; j
0f80: 2b 2b 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28  ++){.        if(
0f90: 20 73 74 72 63 6d 70 28 61 7a 46 69 65 6c 64 5b   strcmp(azField[
0fa0: 6a 5d 2c 7a 4e 61 6d 65 29 3d 3d 30 20 29 7b 0a  j],zName)==0 ){.
0fb0: 20 20 20 20 20 20 20 20 20 20 61 7a 56 61 6c 75            azValu
0fc0: 65 5b 6a 5d 20 3d 20 6d 70 72 69 6e 74 66 28 22  e[j] = mprintf("
0fd0: 25 73 22 2c 20 7a 56 61 6c 29 3b 0a 20 20 20 20  %s", zVal);.    
0fe0: 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20        break;.   
0ff0: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20       }.      }. 
1000: 20 20 20 20 20 69 66 28 20 54 68 5f 46 65 74 63       if( Th_Fetc
1010: 68 28 7a 4e 61 6d 65 2c 20 26 73 69 7a 65 29 3d  h(zName, &size)=
1020: 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20 54 68  =0 ){.        Th
1030: 5f 53 74 6f 72 65 28 7a 4e 61 6d 65 2c 20 7a 56  _Store(zName, zV
1040: 61 6c 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20  al);.      }.   
1050: 20 20 20 66 72 65 65 28 7a 52 65 76 65 61 6c 65     free(zReveale
1060: 64 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65 6c 73  d);.    }.  }els
1070: 65 7b 0a 20 20 20 20 64 62 5f 66 69 6e 61 6c 69  e{.    db_finali
1080: 7a 65 28 26 71 29 3b 0a 20 20 20 20 64 62 5f 70  ze(&q);.    db_p
1090: 72 65 70 61 72 65 28 26 71 2c 20 22 50 52 41 47  repare(&q, "PRAG
10a0: 4d 41 20 74 61 62 6c 65 5f 69 6e 66 6f 28 74 69  MA table_info(ti
10b0: 63 6b 65 74 29 22 29 3b 0a 20 20 20 20 69 66 28  cket)");.    if(
10c0: 20 54 68 5f 46 65 74 63 68 28 22 74 6b 74 5f 75   Th_Fetch("tkt_u
10d0: 75 69 64 22 2c 26 73 69 7a 65 29 3d 3d 30 20 29  uid",&size)==0 )
10e0: 7b 0a 20 20 20 20 20 20 54 68 5f 53 74 6f 72 65  {.      Th_Store
10f0: 28 22 74 6b 74 5f 75 75 69 64 22 2c 7a 4e 61 6d  ("tkt_uuid",zNam
1100: 65 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 77 68  e);.    }.    wh
1110: 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29  ile( db_step(&q)
1120: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a  ==SQLITE_ROW ){.
1130: 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72        const char
1140: 20 2a 7a 46 69 65 6c 64 20 3d 20 64 62 5f 63 6f   *zField = db_co
1150: 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 31 29  lumn_text(&q, 1)
1160: 3b 0a 20 20 20 20 20 20 69 66 28 20 54 68 5f 46  ;.      if( Th_F
1170: 65 74 63 68 28 7a 46 69 65 6c 64 2c 20 26 73 69  etch(zField, &si
1180: 7a 65 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20  ze)==0 ){.      
1190: 20 20 54 68 5f 53 74 6f 72 65 28 7a 46 69 65 6c    Th_Store(zFiel
11a0: 64 2c 20 22 22 29 3b 0a 20 20 20 20 20 20 7d 0a  d, "");.      }.
11b0: 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 54 68      }.    if( Th
11c0: 5f 46 65 74 63 68 28 22 74 6b 74 5f 64 61 74 65  _Fetch("tkt_date
11d0: 74 69 6d 65 22 2c 26 73 69 7a 65 29 3d 3d 30 20  time",&size)==0 
11e0: 29 7b 0a 20 20 20 20 20 20 54 68 5f 53 74 6f 72  ){.      Th_Stor
11f0: 65 28 22 74 6b 74 5f 64 61 74 65 74 69 6d 65 22  e("tkt_datetime"
1200: 2c 22 22 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a  ,"");.    }.  }.
1210: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71    db_finalize(&q
1220: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 72 61 6e  );.}../*.** Tran
1230: 73 66 65 72 20 61 6c 6c 20 43 47 49 20 70 61 72  sfer all CGI par
1240: 61 6d 65 74 65 72 73 20 74 6f 20 76 61 72 69 61  ameters to varia
1250: 62 6c 65 73 20 69 6e 20 74 68 65 20 69 6e 74 65  bles in the inte
1260: 72 70 72 65 74 65 72 2e 0a 2a 2f 0a 73 74 61 74  rpreter..*/.stat
1270: 69 63 20 76 6f 69 64 20 69 6e 69 74 69 61 6c 69  ic void initiali
1280: 7a 65 56 61 72 69 61 62 6c 65 73 46 72 6f 6d 43  zeVariablesFromC
1290: 47 49 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20  GI(void){.  int 
12a0: 69 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  i;.  const char 
12b0: 2a 7a 3b 0a 0a 20 20 66 6f 72 28 69 3d 30 3b 20  *z;..  for(i=0; 
12c0: 28 7a 20 3d 20 63 67 69 5f 70 61 72 61 6d 65 74  (z = cgi_paramet
12d0: 65 72 5f 6e 61 6d 65 28 69 29 29 21 3d 30 3b 20  er_name(i))!=0; 
12e0: 69 2b 2b 29 7b 0a 20 20 20 20 54 68 5f 53 74 6f  i++){.    Th_Sto
12f0: 72 65 28 7a 2c 20 50 28 7a 29 29 3b 0a 20 20 7d  re(z, P(z));.  }
1300: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 62 75 69 6c  .}../*.** Rebuil
1310: 64 20 61 6c 6c 20 74 69 63 6b 65 74 73 20 6e 61  d all tickets na
1320: 6d 65 64 20 69 6e 20 74 68 65 20 5f 70 65 6e 64  med in the _pend
1330: 69 6e 67 5f 74 69 63 6b 65 74 20 74 61 62 6c 65  ing_ticket table
1340: 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 72 6f 75  ..**.** This rou
1350: 74 69 6e 65 20 69 73 20 63 61 6c 6c 65 64 20 6a  tine is called j
1360: 75 73 74 20 70 72 69 6f 72 20 74 6f 20 63 6f 6d  ust prior to com
1370: 6d 69 74 20 61 66 74 65 72 20 6e 65 77 0a 2a 2a  mit after new.**
1380: 20 6f 75 74 2d 6f 66 2d 73 65 71 75 65 6e 63 65   out-of-sequence
1390: 20 74 69 63 6b 65 74 20 63 68 61 6e 67 65 73 20   ticket changes 
13a0: 68 61 76 65 20 62 65 65 6e 20 61 64 64 65 64 2e  have been added.
13b0: 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 74  .*/.static int t
13c0: 69 63 6b 65 74 5f 72 65 62 75 69 6c 64 5f 61 74  icket_rebuild_at
13d0: 5f 63 6f 6d 6d 69 74 28 76 6f 69 64 29 7b 0a 20  _commit(void){. 
13e0: 20 53 74 6d 74 20 71 3b 0a 20 20 64 62 5f 6d 75   Stmt q;.  db_mu
13f0: 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 22 44  lti_exec(.    "D
1400: 45 4c 45 54 45 20 46 52 4f 4d 20 74 69 63 6b 65  ELETE FROM ticke
1410: 74 20 57 48 45 52 45 20 74 6b 74 5f 75 75 69 64  t WHERE tkt_uuid
1420: 20 49 4e 20 5f 70 65 6e 64 69 6e 67 5f 74 69 63   IN _pending_tic
1430: 6b 65 74 22 0a 20 20 29 3b 0a 20 20 64 62 5f 70  ket".  );.  db_p
1440: 72 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45  repare(&q, "SELE
1450: 43 54 20 75 75 69 64 20 46 52 4f 4d 20 5f 70 65  CT uuid FROM _pe
1460: 6e 64 69 6e 67 5f 74 69 63 6b 65 74 22 29 3b 0a  nding_ticket");.
1470: 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70    while( db_step
1480: 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57  (&q)==SQLITE_ROW
1490: 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68   ){.    const ch
14a0: 61 72 20 2a 7a 55 75 69 64 20 3d 20 64 62 5f 63  ar *zUuid = db_c
14b0: 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30  olumn_text(&q, 0
14c0: 29 3b 0a 20 20 20 20 74 69 63 6b 65 74 5f 72 65  );.    ticket_re
14d0: 62 75 69 6c 64 5f 65 6e 74 72 79 28 7a 55 75 69  build_entry(zUui
14e0: 64 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d 75 6c  d);.  }.  db_mul
14f0: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 22 44 45  ti_exec(.    "DE
1500: 4c 45 54 45 20 46 52 4f 4d 20 5f 70 65 6e 64 69  LETE FROM _pendi
1510: 6e 67 5f 74 69 63 6b 65 74 22 0a 20 20 29 3b 0a  ng_ticket".  );.
1520: 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a 2f    return 0;.}../
1530: 2a 0a 2a 2a 20 55 70 64 61 74 65 20 61 6e 20 65  *.** Update an e
1540: 6e 74 72 79 20 6f 66 20 74 68 65 20 54 49 43 4b  ntry of the TICK
1550: 45 54 20 74 61 62 6c 65 20 61 63 63 6f 72 64 69  ET table accordi
1560: 6e 67 20 74 6f 20 74 68 65 20 69 6e 66 6f 72 6d  ng to the inform
1570: 61 74 69 6f 6e 0a 2a 2a 20 69 6e 20 74 68 65 20  ation.** in the 
1580: 63 6f 6e 74 72 6f 6c 20 66 69 6c 65 20 67 69 76  control file giv
1590: 65 6e 20 69 6e 20 70 2e 20 20 41 74 74 65 6d 70  en in p.  Attemp
15a0: 74 20 74 6f 20 63 72 65 61 74 65 20 74 68 65 20  t to create the 
15b0: 61 70 70 72 6f 70 72 69 61 74 65 0a 2a 2a 20 54  appropriate.** T
15c0: 49 43 4b 45 54 20 74 61 62 6c 65 20 65 6e 74 72  ICKET table entr
15d0: 79 20 69 66 20 63 72 65 61 74 65 46 6c 61 67 20  y if createFlag 
15e0: 69 73 20 74 72 75 65 2e 20 20 49 66 20 63 72 65  is true.  If cre
15f0: 61 74 65 46 6c 61 67 20 69 73 20 66 61 6c 73 65  ateFlag is false
1600: 2c 0a 2a 2a 20 74 68 61 74 20 6d 65 61 6e 73 20  ,.** that means 
1610: 77 65 20 61 6c 72 65 61 64 79 20 6b 6e 6f 77 20  we already know 
1620: 74 68 65 20 65 6e 74 72 79 20 65 78 69 73 74 73  the entry exists
1630: 20 61 6e 64 20 73 6f 20 77 65 20 63 61 6e 20 73   and so we can s
1640: 61 76 65 20 74 68 65 0a 2a 2a 20 77 6f 72 6b 20  ave the.** work 
1650: 6f 66 20 74 72 79 69 6e 67 20 74 6f 20 63 72 65  of trying to cre
1660: 61 74 65 20 69 74 2e 0a 2a 2a 0a 2a 2a 20 52 65  ate it..**.** Re
1670: 74 75 72 6e 20 54 52 55 45 20 69 66 20 61 20 6e  turn TRUE if a n
1680: 65 77 20 54 49 43 4b 45 54 20 65 6e 74 72 79 20  ew TICKET entry 
1690: 77 61 73 20 63 72 65 61 74 65 64 20 61 6e 64 20  was created and 
16a0: 46 41 4c 53 45 20 69 66 20 61 6e 0a 2a 2a 20 65  FALSE if an.** e
16b0: 78 69 73 74 69 6e 67 20 65 6e 74 72 79 20 77 61  xisting entry wa
16c0: 73 20 72 65 76 69 73 65 64 2e 0a 2a 2f 0a 69 6e  s revised..*/.in
16d0: 74 20 74 69 63 6b 65 74 5f 69 6e 73 65 72 74 28  t ticket_insert(
16e0: 63 6f 6e 73 74 20 4d 61 6e 69 66 65 73 74 20 2a  const Manifest *
16f0: 70 2c 20 69 6e 74 20 63 72 65 61 74 65 46 6c 61  p, int createFla
1700: 67 2c 20 69 6e 74 20 63 68 65 63 6b 54 69 6d 65  g, int checkTime
1710: 29 7b 0a 20 20 42 6c 6f 62 20 73 71 6c 3b 0a 20  ){.  Blob sql;. 
1720: 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20 69   Stmt q;.  int i
1730: 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  ;.  const char *
1740: 7a 53 65 70 3b 0a 20 20 69 6e 74 20 72 63 20 3d  zSep;.  int rc =
1750: 20 30 3b 0a 0a 20 20 67 65 74 41 6c 6c 54 69 63   0;..  getAllTic
1760: 6b 65 74 46 69 65 6c 64 73 28 29 3b 0a 20 20 69  ketFields();.  i
1770: 66 28 20 63 72 65 61 74 65 46 6c 61 67 20 29 7b  f( createFlag ){
1780: 20 20 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f    .    db_multi_
1790: 65 78 65 63 28 22 49 4e 53 45 52 54 20 4f 52 20  exec("INSERT OR 
17a0: 49 47 4e 4f 52 45 20 49 4e 54 4f 20 74 69 63 6b  IGNORE INTO tick
17b0: 65 74 28 74 6b 74 5f 75 75 69 64 2c 20 74 6b 74  et(tkt_uuid, tkt
17c0: 5f 6d 74 69 6d 65 29 20 22 0a 20 20 20 20 20 20  _mtime) ".      
17d0: 20 20 20 20 20 20 20 20 20 20 20 20 22 56 41 4c              "VAL
17e0: 55 45 53 28 25 51 2c 20 30 29 22 2c 20 70 2d 3e  UES(%Q, 0)", p->
17f0: 7a 54 69 63 6b 65 74 55 75 69 64 29 3b 0a 20 20  zTicketUuid);.  
1800: 20 20 72 63 20 3d 20 64 62 5f 63 68 61 6e 67 65    rc = db_change
1810: 73 28 29 3b 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f  s();.  }.  blob_
1820: 7a 65 72 6f 28 26 73 71 6c 29 3b 0a 20 20 62 6c  zero(&sql);.  bl
1830: 6f 62 5f 61 70 70 65 6e 64 66 28 26 73 71 6c 2c  ob_appendf(&sql,
1840: 20 22 55 50 44 41 54 45 20 4f 52 20 52 45 50 4c   "UPDATE OR REPL
1850: 41 43 45 20 74 69 63 6b 65 74 20 53 45 54 20 74  ACE ticket SET t
1860: 6b 74 5f 6d 74 69 6d 65 3d 3a 6d 74 69 6d 65 22  kt_mtime=:mtime"
1870: 29 3b 0a 20 20 7a 53 65 70 20 3d 20 22 53 45 54  );.  zSep = "SET
1880: 22 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c  ";.  for(i=0; i<
1890: 70 2d 3e 6e 46 69 65 6c 64 3b 20 69 2b 2b 29 7b  p->nField; i++){
18a0: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20  .    const char 
18b0: 2a 7a 4e 61 6d 65 20 3d 20 70 2d 3e 61 46 69 65  *zName = p->aFie
18c0: 6c 64 5b 69 5d 2e 7a 4e 61 6d 65 3b 0a 20 20 20  ld[i].zName;.   
18d0: 20 69 66 28 20 7a 4e 61 6d 65 5b 30 5d 3d 3d 27   if( zName[0]=='
18e0: 2b 27 20 29 7b 0a 20 20 20 20 20 20 7a 4e 61 6d  +' ){.      zNam
18f0: 65 2b 2b 3b 0a 20 20 20 20 20 20 69 66 28 20 66  e++;.      if( f
1900: 69 65 6c 64 49 64 28 7a 4e 61 6d 65 29 3c 30 20  ieldId(zName)<0 
1910: 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20  ) continue;.    
1920: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26    blob_appendf(&
1930: 73 71 6c 2c 22 2c 20 25 73 3d 63 6f 61 6c 65 73  sql,", %s=coales
1940: 63 65 28 25 73 2c 27 27 29 20 7c 7c 20 25 51 22  ce(%s,'') || %Q"
1950: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
1960: 20 20 20 20 20 7a 4e 61 6d 65 2c 20 7a 4e 61 6d       zName, zNam
1970: 65 2c 20 70 2d 3e 61 46 69 65 6c 64 5b 69 5d 2e  e, p->aField[i].
1980: 7a 56 61 6c 75 65 29 3b 0a 20 20 20 20 7d 65 6c  zValue);.    }el
1990: 73 65 7b 0a 20 20 20 20 20 20 69 66 28 20 66 69  se{.      if( fi
19a0: 65 6c 64 49 64 28 7a 4e 61 6d 65 29 3c 30 20 29  eldId(zName)<0 )
19b0: 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20   continue;.     
19c0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73   blob_appendf(&s
19d0: 71 6c 2c 22 2c 20 25 73 3d 25 51 22 2c 20 7a 4e  ql,", %s=%Q", zN
19e0: 61 6d 65 2c 20 70 2d 3e 61 46 69 65 6c 64 5b 69  ame, p->aField[i
19f0: 5d 2e 7a 56 61 6c 75 65 29 3b 0a 20 20 20 20 7d  ].zValue);.    }
1a00: 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 61 70 70 65  .  }.  blob_appe
1a10: 6e 64 66 28 26 73 71 6c 2c 20 22 20 57 48 45 52  ndf(&sql, " WHER
1a20: 45 20 74 6b 74 5f 75 75 69 64 3d 27 25 73 27 20  E tkt_uuid='%s' 
1a30: 41 4e 44 20 74 6b 74 5f 6d 74 69 6d 65 3c 3a 6d  AND tkt_mtime<:m
1a40: 74 69 6d 65 22 2c 0a 20 20 20 20 20 20 20 20 20  time",.         
1a50: 20 20 20 20 20 20 20 20 20 20 20 20 70 2d 3e 7a              p->z
1a60: 54 69 63 6b 65 74 55 75 69 64 29 3b 0a 20 20 64  TicketUuid);.  d
1a70: 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 22 25  b_prepare(&q, "%
1a80: 73 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 73 71  s", blob_str(&sq
1a90: 6c 29 29 3b 0a 20 20 64 62 5f 62 69 6e 64 5f 64  l));.  db_bind_d
1aa0: 6f 75 62 6c 65 28 26 71 2c 20 22 3a 6d 74 69 6d  ouble(&q, ":mtim
1ab0: 65 22 2c 20 70 2d 3e 72 44 61 74 65 29 3b 0a 20  e", p->rDate);. 
1ac0: 20 64 62 5f 73 74 65 70 28 26 71 29 3b 0a 20 20   db_step(&q);.  
1ad0: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b  db_finalize(&q);
1ae0: 0a 20 20 69 66 28 20 63 68 65 63 6b 54 69 6d 65  .  if( checkTime
1af0: 20 26 26 20 64 62 5f 63 68 61 6e 67 65 73 28 29   && db_changes()
1b00: 3d 3d 30 20 29 7b 0a 20 20 20 20 73 74 61 74 69  ==0 ){.    stati
1b10: 63 20 69 6e 74 20 69 73 49 6e 69 74 20 3d 20 30  c int isInit = 0
1b20: 3b 0a 20 20 20 20 69 66 28 20 21 69 73 49 6e 69  ;.    if( !isIni
1b30: 74 20 29 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75  t ){.      db_mu
1b40: 6c 74 69 5f 65 78 65 63 28 22 43 52 45 41 54 45  lti_exec("CREATE
1b50: 20 54 45 4d 50 20 54 41 42 4c 45 20 5f 70 65 6e   TEMP TABLE _pen
1b60: 64 69 6e 67 5f 74 69 63 6b 65 74 28 75 75 69 64  ding_ticket(uuid
1b70: 20 54 45 58 54 20 55 4e 49 51 55 45 29 22 29 3b   TEXT UNIQUE)");
1b80: 0a 20 20 20 20 20 20 64 62 5f 63 6f 6d 6d 69 74  .      db_commit
1b90: 5f 68 6f 6f 6b 28 74 69 63 6b 65 74 5f 72 65 62  _hook(ticket_reb
1ba0: 75 69 6c 64 5f 61 74 5f 63 6f 6d 6d 69 74 2c 20  uild_at_commit, 
1bb0: 31 29 3b 0a 20 20 20 20 20 20 69 73 49 6e 69 74  1);.      isInit
1bc0: 20 3d 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20   = 1;.    }.    
1bd0: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 49  db_multi_exec("I
1be0: 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45 20  NSERT OR IGNORE 
1bf0: 49 4e 54 4f 20 5f 70 65 6e 64 69 6e 67 5f 74 69  INTO _pending_ti
1c00: 63 6b 65 74 20 22 0a 20 20 20 20 20 20 20 20 20  cket ".         
1c10: 20 20 20 20 20 20 20 20 20 22 56 41 4c 55 45 53           "VALUES
1c20: 28 25 51 29 22 2c 20 70 2d 3e 7a 54 69 63 6b 65  (%Q)", p->zTicke
1c30: 74 55 75 69 64 29 3b 0a 20 20 7d 0a 20 20 62 6c  tUuid);.  }.  bl
1c40: 6f 62 5f 72 65 73 65 74 28 26 73 71 6c 29 3b 0a  ob_reset(&sql);.
1c50: 20 20 72 65 74 75 72 6e 20 72 63 3b 0a 7d 0a 0a    return rc;.}..
1c60: 2f 2a 0a 2a 2a 20 52 65 62 75 69 6c 64 20 61 6e  /*.** Rebuild an
1c70: 20 65 6e 74 69 72 65 20 65 6e 74 72 79 20 69 6e   entire entry in
1c80: 20 74 68 65 20 54 49 43 4b 45 54 20 74 61 62 6c   the TICKET tabl
1c90: 65 0a 2a 2f 0a 76 6f 69 64 20 74 69 63 6b 65 74  e.*/.void ticket
1ca0: 5f 72 65 62 75 69 6c 64 5f 65 6e 74 72 79 28 63  _rebuild_entry(c
1cb0: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 6b 74 55  onst char *zTktU
1cc0: 75 69 64 29 7b 0a 20 20 63 68 61 72 20 2a 7a 54  uid){.  char *zT
1cd0: 61 67 20 3d 20 6d 70 72 69 6e 74 66 28 22 74 6b  ag = mprintf("tk
1ce0: 74 2d 25 73 22 2c 20 7a 54 6b 74 55 75 69 64 29  t-%s", zTktUuid)
1cf0: 3b 0a 20 20 69 6e 74 20 74 61 67 69 64 20 3d 20  ;.  int tagid = 
1d00: 74 61 67 5f 66 69 6e 64 69 64 28 7a 54 61 67 2c  tag_findid(zTag,
1d10: 20 31 29 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 20   1);.  Stmt q;. 
1d20: 20 4d 61 6e 69 66 65 73 74 20 6d 61 6e 69 66 65   Manifest manife
1d30: 73 74 3b 0a 20 20 42 6c 6f 62 20 63 6f 6e 74 65  st;.  Blob conte
1d40: 6e 74 3b 0a 20 20 69 6e 74 20 63 72 65 61 74 65  nt;.  int create
1d50: 46 6c 61 67 20 3d 20 31 3b 0a 20 20 0a 20 20 64  Flag = 1;.  .  d
1d60: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20  b_multi_exec(.  
1d70: 20 20 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20     "DELETE FROM 
1d80: 74 69 63 6b 65 74 20 57 48 45 52 45 20 74 6b 74  ticket WHERE tkt
1d90: 5f 75 75 69 64 3d 25 51 22 2c 20 7a 54 6b 74 55  _uuid=%Q", zTktU
1da0: 75 69 64 0a 20 20 29 3b 0a 20 20 64 62 5f 70 72  uid.  );.  db_pr
1db0: 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43  epare(&q, "SELEC
1dc0: 54 20 72 69 64 20 46 52 4f 4d 20 74 61 67 78 72  T rid FROM tagxr
1dd0: 65 66 20 57 48 45 52 45 20 74 61 67 69 64 3d 25  ef WHERE tagid=%
1de0: 64 20 4f 52 44 45 52 20 42 59 20 6d 74 69 6d 65  d ORDER BY mtime
1df0: 22 2c 74 61 67 69 64 29 3b 0a 20 20 77 68 69 6c  ",tagid);.  whil
1e00: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d  e( db_step(&q)==
1e10: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20  SQLITE_ROW ){.  
1e20: 20 20 69 6e 74 20 72 69 64 20 3d 20 64 62 5f 63    int rid = db_c
1e30: 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29  olumn_int(&q, 0)
1e40: 3b 0a 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65  ;.    content_ge
1e50: 74 28 72 69 64 2c 20 26 63 6f 6e 74 65 6e 74 29  t(rid, &content)
1e60: 3b 0a 20 20 20 20 6d 61 6e 69 66 65 73 74 5f 70  ;.    manifest_p
1e70: 61 72 73 65 28 26 6d 61 6e 69 66 65 73 74 2c 20  arse(&manifest, 
1e80: 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20 74  &content);.    t
1e90: 69 63 6b 65 74 5f 69 6e 73 65 72 74 28 26 6d 61  icket_insert(&ma
1ea0: 6e 69 66 65 73 74 2c 20 63 72 65 61 74 65 46 6c  nifest, createFl
1eb0: 61 67 2c 20 30 29 3b 0a 20 20 20 20 6d 61 6e 69  ag, 0);.    mani
1ec0: 66 65 73 74 5f 74 69 63 6b 65 74 5f 65 76 65 6e  fest_ticket_even
1ed0: 74 28 72 69 64 2c 20 26 6d 61 6e 69 66 65 73 74  t(rid, &manifest
1ee0: 2c 20 63 72 65 61 74 65 46 6c 61 67 2c 20 74 61  , createFlag, ta
1ef0: 67 69 64 29 3b 0a 20 20 20 20 6d 61 6e 69 66 65  gid);.    manife
1f00: 73 74 5f 63 6c 65 61 72 28 26 6d 61 6e 69 66 65  st_clear(&manife
1f10: 73 74 29 3b 0a 20 20 20 20 63 72 65 61 74 65 46  st);.    createF
1f20: 6c 61 67 20 3d 20 30 3b 0a 20 20 7d 0a 20 20 64  lag = 0;.  }.  d
1f30: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a  b_finalize(&q);.
1f40: 7d 0a 0a 2f 2a 0a 2a 2a 20 43 72 65 61 74 65 20  }../*.** Create 
1f50: 74 68 65 20 73 75 62 73 63 72 69 70 74 20 69 6e  the subscript in
1f60: 74 65 72 70 72 65 74 65 72 20 61 6e 64 20 6c 6f  terpreter and lo
1f70: 61 64 20 74 68 65 20 22 63 6f 6d 6d 6f 6e 22 20  ad the "common" 
1f80: 63 6f 64 65 2e 0a 2a 2f 0a 76 6f 69 64 20 74 69  code..*/.void ti
1f90: 63 6b 65 74 5f 69 6e 69 74 28 76 6f 69 64 29 7b  cket_init(void){
1fa0: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
1fb0: 43 6f 6e 66 69 67 3b 0a 20 20 54 68 5f 46 6f 73  Config;.  Th_Fos
1fc0: 73 69 6c 49 6e 69 74 28 29 3b 0a 20 20 7a 43 6f  silInit();.  zCo
1fd0: 6e 66 69 67 20 3d 20 74 69 63 6b 65 74 5f 63 6f  nfig = ticket_co
1fe0: 6d 6d 6f 6e 5f 63 6f 64 65 28 29 3b 0a 20 20 54  mmon_code();.  T
1ff0: 68 5f 45 76 61 6c 28 67 2e 69 6e 74 65 72 70 2c  h_Eval(g.interp,
2000: 20 30 2c 20 7a 43 6f 6e 66 69 67 2c 20 2d 31 29   0, zConfig, -1)
2010: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 63 72 65  ;.}../*.** Recre
2020: 61 74 65 20 74 68 65 20 74 69 63 6b 65 74 20 74  ate the ticket t
2030: 61 62 6c 65 2e 0a 2a 2f 0a 76 6f 69 64 20 74 69  able..*/.void ti
2040: 63 6b 65 74 5f 63 72 65 61 74 65 5f 74 61 62 6c  cket_create_tabl
2050: 65 28 69 6e 74 20 73 65 70 61 72 61 74 65 43 6f  e(int separateCo
2060: 6e 6e 65 63 74 69 6f 6e 29 7b 0a 20 20 63 6f 6e  nnection){.  con
2070: 73 74 20 63 68 61 72 20 2a 7a 53 71 6c 3b 0a 0a  st char *zSql;..
2080: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28    db_multi_exec(
2090: 22 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20 45  "DROP TABLE IF E
20a0: 58 49 53 54 53 20 74 69 63 6b 65 74 3b 22 29 3b  XISTS ticket;");
20b0: 0a 20 20 7a 53 71 6c 20 3d 20 74 69 63 6b 65 74  .  zSql = ticket
20c0: 5f 74 61 62 6c 65 5f 73 63 68 65 6d 61 28 29 3b  _table_schema();
20d0: 0a 20 20 69 66 28 20 73 65 70 61 72 61 74 65 43  .  if( separateC
20e0: 6f 6e 6e 65 63 74 69 6f 6e 20 29 7b 0a 20 20 20  onnection ){.   
20f0: 20 64 62 5f 69 6e 69 74 5f 64 61 74 61 62 61 73   db_init_databas
2100: 65 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e  e(g.zRepositoryN
2110: 61 6d 65 2c 20 7a 53 71 6c 2c 20 30 29 3b 0a 20  ame, zSql, 0);. 
2120: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 64 62 5f 6d   }else{.    db_m
2130: 75 6c 74 69 5f 65 78 65 63 28 22 25 73 22 2c 20  ulti_exec("%s", 
2140: 7a 53 71 6c 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a  zSql);.  }.}../*
2150: 0a 2a 2a 20 52 65 70 6f 70 75 6c 61 74 65 20 74  .** Repopulate t
2160: 68 65 20 74 69 63 6b 65 74 20 74 61 62 6c 65 0a  he ticket table.
2170: 2a 2f 0a 76 6f 69 64 20 74 69 63 6b 65 74 5f 72  */.void ticket_r
2180: 65 62 75 69 6c 64 28 76 6f 69 64 29 7b 0a 20 20  ebuild(void){.  
2190: 53 74 6d 74 20 71 3b 0a 20 20 74 69 63 6b 65 74  Stmt q;.  ticket
21a0: 5f 63 72 65 61 74 65 5f 74 61 62 6c 65 28 31 29  _create_table(1)
21b0: 3b 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61  ;.  db_begin_tra
21c0: 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 64 62  nsaction();.  db
21d0: 5f 70 72 65 70 61 72 65 28 26 71 2c 22 53 45 4c  _prepare(&q,"SEL
21e0: 45 43 54 20 74 61 67 6e 61 6d 65 20 46 52 4f 4d  ECT tagname FROM
21f0: 20 74 61 67 20 57 48 45 52 45 20 74 61 67 6e 61   tag WHERE tagna
2200: 6d 65 20 47 4c 4f 42 20 27 74 6b 74 2d 2a 27 22  me GLOB 'tkt-*'"
2210: 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 5f 73  );.  while( db_s
2220: 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f  tep(&q)==SQLITE_
2230: 52 4f 57 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74  ROW ){.    const
2240: 20 63 68 61 72 20 2a 7a 4e 61 6d 65 20 3d 20 64   char *zName = d
2250: 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71  b_column_text(&q
2260: 2c 20 30 29 3b 0a 20 20 20 20 69 6e 74 20 6c 65  , 0);.    int le
2270: 6e 3b 0a 20 20 20 20 7a 4e 61 6d 65 20 2b 3d 20  n;.    zName += 
2280: 34 3b 0a 20 20 20 20 6c 65 6e 20 3d 20 73 74 72  4;.    len = str
2290: 6c 65 6e 28 7a 4e 61 6d 65 29 3b 0a 20 20 20 20  len(zName);.    
22a0: 69 66 28 20 6c 65 6e 3c 32 30 20 7c 7c 20 21 76  if( len<20 || !v
22b0: 61 6c 69 64 61 74 65 31 36 28 7a 4e 61 6d 65 2c  alidate16(zName,
22c0: 20 6c 65 6e 29 20 29 20 63 6f 6e 74 69 6e 75 65   len) ) continue
22d0: 3b 0a 20 20 20 20 74 69 63 6b 65 74 5f 72 65 62  ;.    ticket_reb
22e0: 75 69 6c 64 5f 65 6e 74 72 79 28 7a 4e 61 6d 65  uild_entry(zName
22f0: 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61  );.  }.  db_fina
2300: 6c 69 7a 65 28 26 71 29 3b 0a 20 20 64 62 5f 65  lize(&q);.  db_e
2310: 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30  nd_transaction(0
2320: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50  );.}../*.** WEBP
2330: 41 47 45 3a 20 74 6b 74 76 69 65 77 0a 2a 2a 20  AGE: tktview.** 
2340: 55 52 4c 3a 20 20 74 6b 74 76 69 65 77 3f 6e 61  URL:  tktview?na
2350: 6d 65 3d 55 55 49 44 0a 2a 2a 0a 2a 2a 20 56 69  me=UUID.**.** Vi
2360: 65 77 20 61 20 74 69 63 6b 65 74 2e 0a 2a 2f 0a  ew a ticket..*/.
2370: 76 6f 69 64 20 74 6b 74 76 69 65 77 5f 70 61 67  void tktview_pag
2380: 65 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74  e(void){.  const
2390: 20 63 68 61 72 20 2a 7a 53 63 72 69 70 74 3b 0a   char *zScript;.
23a0: 20 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72    login_check_cr
23b0: 65 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69  edentials();.  i
23c0: 66 28 20 21 67 2e 6f 6b 52 64 54 6b 74 20 29 7b  f( !g.okRdTkt ){
23d0: 20 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28 29 3b   login_needed();
23e0: 20 72 65 74 75 72 6e 3b 20 7d 0a 20 20 69 66 28   return; }.  if(
23f0: 20 67 2e 6f 6b 57 72 54 6b 74 20 7c 7c 20 67 2e   g.okWrTkt || g.
2400: 6f 6b 41 70 6e 64 54 6b 74 20 29 7b 0a 20 20 20  okApndTkt ){.   
2410: 20 73 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65   style_submenu_e
2420: 6c 65 6d 65 6e 74 28 22 45 64 69 74 22 2c 20 22  lement("Edit", "
2430: 45 64 69 74 20 54 68 65 20 54 69 63 6b 65 74 22  Edit The Ticket"
2440: 2c 20 22 25 73 2f 74 6b 74 65 64 69 74 3f 6e 61  , "%s/tktedit?na
2450: 6d 65 3d 25 54 22 2c 0a 20 20 20 20 20 20 20 20  me=%T",.        
2460: 67 2e 7a 54 6f 70 2c 20 50 44 28 22 6e 61 6d 65  g.zTop, PD("name
2470: 22 2c 22 22 29 29 3b 0a 20 20 7d 0a 20 20 69 66  ",""));.  }.  if
2480: 28 20 67 2e 6f 6b 48 69 73 74 6f 72 79 20 29 7b  ( g.okHistory ){
2490: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20  .    const char 
24a0: 2a 7a 55 75 69 64 20 3d 20 50 44 28 22 6e 61 6d  *zUuid = PD("nam
24b0: 65 22 2c 22 22 29 3b 0a 20 20 20 20 73 74 79 6c  e","");.    styl
24c0: 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e  e_submenu_elemen
24d0: 74 28 22 48 69 73 74 6f 72 79 22 2c 20 22 48 69  t("History", "Hi
24e0: 73 74 6f 72 79 20 4f 66 20 54 68 69 73 20 54 69  story Of This Ti
24f0: 63 6b 65 74 22 2c 20 0a 20 20 20 20 20 20 20 20  cket", .        
2500: 22 25 73 2f 74 6b 74 68 69 73 74 6f 72 79 2f 25  "%s/tkthistory/%
2510: 54 22 2c 20 67 2e 7a 54 6f 70 2c 20 7a 55 75 69  T", g.zTop, zUui
2520: 64 29 3b 0a 20 20 20 20 73 74 79 6c 65 5f 73 75  d);.    style_su
2530: 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 54  bmenu_element("T
2540: 69 6d 65 6c 69 6e 65 22 2c 20 22 54 69 6d 65 6c  imeline", "Timel
2550: 69 6e 65 20 4f 66 20 54 68 69 73 20 54 69 63 6b  ine Of This Tick
2560: 65 74 22 2c 20 0a 20 20 20 20 20 20 20 20 22 25  et", .        "%
2570: 73 2f 74 6b 74 74 69 6d 65 6c 69 6e 65 2f 25 54  s/tkttimeline/%T
2580: 22 2c 20 67 2e 7a 54 6f 70 2c 20 7a 55 75 69 64  ", g.zTop, zUuid
2590: 29 3b 0a 20 20 7d 0a 20 20 73 74 79 6c 65 5f 68  );.  }.  style_h
25a0: 65 61 64 65 72 28 22 56 69 65 77 20 54 69 63 6b  eader("View Tick
25b0: 65 74 22 29 3b 0a 20 20 69 66 28 20 67 2e 74 68  et");.  if( g.th
25c0: 54 72 61 63 65 20 29 20 54 68 5f 54 72 61 63 65  Trace ) Th_Trace
25d0: 28 22 42 45 47 49 4e 5f 54 4b 54 56 49 45 57 3c  ("BEGIN_TKTVIEW<
25e0: 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a 20  br />\n", -1);. 
25f0: 20 74 69 63 6b 65 74 5f 69 6e 69 74 28 29 3b 0a   ticket_init();.
2600: 20 20 69 6e 69 74 69 61 6c 69 7a 65 56 61 72 69    initializeVari
2610: 61 62 6c 65 73 46 72 6f 6d 44 62 28 29 3b 0a 20  ablesFromDb();. 
2620: 20 7a 53 63 72 69 70 74 20 3d 20 74 69 63 6b 65   zScript = ticke
2630: 74 5f 76 69 65 77 70 61 67 65 5f 63 6f 64 65 28  t_viewpage_code(
2640: 29 3b 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61  );.  if( g.thTra
2650: 63 65 20 29 20 54 68 5f 54 72 61 63 65 28 22 42  ce ) Th_Trace("B
2660: 45 47 49 4e 5f 54 4b 54 56 49 45 57 5f 53 43 52  EGIN_TKTVIEW_SCR
2670: 49 50 54 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31  IPT<br />\n", -1
2680: 29 3b 0a 20 20 54 68 5f 52 65 6e 64 65 72 28 7a  );.  Th_Render(z
2690: 53 63 72 69 70 74 29 3b 0a 20 20 69 66 28 20 67  Script);.  if( g
26a0: 2e 74 68 54 72 61 63 65 20 29 20 54 68 5f 54 72  .thTrace ) Th_Tr
26b0: 61 63 65 28 22 45 4e 44 5f 54 4b 54 56 49 45 57  ace("END_TKTVIEW
26c0: 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a  <br />\n", -1);.
26d0: 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29    style_footer()
26e0: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 48 20 63 6f  ;.}../*.** TH co
26f0: 6d 6d 61 6e 64 3a 20 20 20 61 70 70 65 6e 64 5f  mmand:   append_
2700: 66 69 65 6c 64 20 46 49 45 4c 44 20 53 54 52 49  field FIELD STRI
2710: 4e 47 0a 2a 2a 0a 2a 2a 20 46 49 45 4c 44 20 69  NG.**.** FIELD i
2720: 73 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 61 20  s the name of a 
2730: 64 61 74 61 62 61 73 65 20 63 6f 6c 75 6d 6e 20  database column 
2740: 74 6f 20 77 68 69 63 68 20 77 65 20 6d 69 67 68  to which we migh
2750: 74 20 77 61 6e 74 0a 2a 2a 20 74 6f 20 61 70 70  t want.** to app
2760: 65 6e 64 20 74 65 78 74 2e 20 20 53 54 52 49 4e  end text.  STRIN
2770: 47 20 69 73 20 74 68 65 20 74 65 78 74 20 74 6f  G is the text to
2780: 20 62 65 20 61 70 70 65 6e 64 65 64 20 74 6f 20   be appended to 
2790: 74 68 61 74 0a 2a 2a 20 63 6f 6c 75 6d 6e 2e 20  that.** column. 
27a0: 20 54 68 65 20 61 70 70 65 6e 64 20 64 6f 65 73   The append does
27b0: 20 6e 6f 74 20 61 63 74 75 61 6c 6c 79 20 6f 63   not actually oc
27c0: 63 75 72 20 75 6e 74 69 6c 20 74 68 65 0a 2a 2a  cur until the.**
27d0: 20 73 75 62 6d 69 74 5f 74 69 63 6b 65 74 20 63   submit_ticket c
27e0: 6f 6d 6d 61 6e 64 20 69 73 20 72 75 6e 2e 0a 2a  ommand is run..*
27f0: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70  /.static int app
2800: 65 6e 64 52 65 6d 61 72 6b 43 6d 64 28 0a 20 20  endRemarkCmd(.  
2810: 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  Th_Interp *inter
2820: 70 2c 20 0a 20 20 76 6f 69 64 20 2a 70 2c 20 0a  p, .  void *p, .
2830: 20 20 69 6e 74 20 61 72 67 63 2c 20 0a 20 20 63    int argc, .  c
2840: 6f 6e 73 74 20 63 68 61 72 20 2a 2a 61 72 67 76  onst char **argv
2850: 2c 20 0a 20 20 69 6e 74 20 2a 61 72 67 6c 0a 29  , .  int *argl.)
2860: 7b 0a 20 20 69 6e 74 20 69 64 78 3b 0a 0a 20 20  {.  int idx;..  
2870: 69 66 28 20 61 72 67 63 21 3d 33 20 29 7b 0a 20  if( argc!=3 ){. 
2880: 20 20 20 72 65 74 75 72 6e 20 54 68 5f 57 72 6f     return Th_Wro
2890: 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70  ngNumArgs(interp
28a0: 2c 20 22 61 70 70 65 6e 64 5f 66 69 65 6c 64 20  , "append_field 
28b0: 46 49 45 4c 44 20 53 54 52 49 4e 47 22 29 3b 0a  FIELD STRING");.
28c0: 20 20 7d 0a 20 20 69 66 28 20 67 2e 74 68 54 72    }.  if( g.thTr
28d0: 61 63 65 20 29 7b 0a 20 20 20 20 54 68 5f 54 72  ace ){.    Th_Tr
28e0: 61 63 65 28 22 61 70 70 65 6e 64 5f 66 69 65 6c  ace("append_fiel
28f0: 64 20 25 23 68 20 7b 25 23 68 7d 3c 62 72 20 2f  d %#h {%#h}<br /
2900: 3e 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 20 20  >\n",.          
2910: 20 20 20 20 61 72 67 6c 5b 31 5d 2c 20 61 72 67      argl[1], arg
2920: 76 5b 31 5d 2c 20 61 72 67 6c 5b 32 5d 2c 20 61  v[1], argl[2], a
2930: 72 67 76 5b 32 5d 29 3b 0a 20 20 7d 0a 20 20 66  rgv[2]);.  }.  f
2940: 6f 72 28 69 64 78 3d 30 3b 20 69 64 78 3c 6e 46  or(idx=0; idx<nF
2950: 69 65 6c 64 3b 20 69 64 78 2b 2b 29 7b 0a 20 20  ield; idx++){.  
2960: 20 20 69 66 28 20 73 74 72 6e 63 6d 70 28 61 7a    if( strncmp(az
2970: 46 69 65 6c 64 5b 69 64 78 5d 2c 20 61 72 67 76  Field[idx], argv
2980: 5b 31 5d 2c 20 61 72 67 6c 5b 31 5d 29 3d 3d 30  [1], argl[1])==0
2990: 0a 20 20 20 20 20 20 20 20 26 26 20 61 7a 46 69  .        && azFi
29a0: 65 6c 64 5b 69 64 78 5d 5b 61 72 67 6c 5b 31 5d  eld[idx][argl[1]
29b0: 5d 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 62 72  ]==0 ){.      br
29c0: 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20  eak;.    }.  }. 
29d0: 20 69 66 28 20 69 64 78 3e 3d 6e 46 69 65 6c 64   if( idx>=nField
29e0: 20 29 7b 0a 20 20 20 20 54 68 5f 45 72 72 6f 72   ){.    Th_Error
29f0: 4d 65 73 73 61 67 65 28 67 2e 69 6e 74 65 72 70  Message(g.interp
2a00: 2c 20 22 6e 6f 20 73 75 63 68 20 54 49 43 4b 45  , "no such TICKE
2a10: 54 20 63 6f 6c 75 6d 6e 3a 20 22 2c 20 61 72 67  T column: ", arg
2a20: 76 5b 31 5d 2c 20 61 72 67 6c 5b 31 5d 29 3b 0a  v[1], argl[1]);.
2a30: 20 20 20 20 72 65 74 75 72 6e 20 54 48 5f 45 52      return TH_ER
2a40: 52 4f 52 3b 0a 20 20 7d 0a 20 20 61 7a 41 70 70  ROR;.  }.  azApp
2a50: 65 6e 64 5b 69 64 78 5d 20 3d 20 6d 70 72 69 6e  end[idx] = mprin
2a60: 74 66 28 22 25 2e 2a 73 22 2c 20 61 72 67 6c 5b  tf("%.*s", argl[
2a70: 32 5d 2c 20 61 72 67 76 5b 32 5d 29 3b 0a 20 20  2], argv[2]);.  
2a80: 72 65 74 75 72 6e 20 54 48 5f 4f 4b 3b 0a 7d 0a  return TH_OK;.}.
2a90: 0a 2f 2a 0a 2a 2a 20 53 75 62 73 63 72 69 70 74  ./*.** Subscript
2aa0: 20 63 6f 6d 6d 61 6e 64 3a 20 20 20 73 75 62 6d   command:   subm
2ab0: 69 74 5f 74 69 63 6b 65 74 0a 2a 2a 0a 2a 2a 20  it_ticket.**.** 
2ac0: 43 6f 6e 73 74 72 75 63 74 20 61 6e 64 20 73 75  Construct and su
2ad0: 62 6d 69 74 20 61 20 6e 65 77 20 74 69 63 6b 65  bmit a new ticke
2ae0: 74 20 61 72 74 69 66 61 63 74 2e 20 20 54 68 65  t artifact.  The
2af0: 20 66 69 65 6c 64 73 20 6f 66 20 74 68 65 20 61   fields of the a
2b00: 72 74 69 66 61 63 74 0a 2a 2a 20 61 72 65 20 74  rtifact.** are t
2b10: 68 65 20 6e 61 6d 65 73 20 6f 66 20 74 68 65 20  he names of the 
2b20: 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 65 20 54  columns in the T
2b30: 49 43 4b 45 54 20 74 61 62 6c 65 2e 20 20 54 68  ICKET table.  Th
2b40: 65 20 63 6f 6e 74 65 6e 74 20 69 73 0a 2a 2a 20  e content is.** 
2b50: 74 61 6b 65 6e 20 66 72 6f 6d 20 54 48 20 76 61  taken from TH va
2b60: 72 69 61 62 6c 65 73 2e 20 20 49 66 20 74 68 65  riables.  If the
2b70: 20 63 6f 6e 74 65 6e 74 20 69 73 20 75 6e 63 68   content is unch
2b80: 61 6e 67 65 64 2c 20 74 68 65 20 66 69 65 6c 64  anged, the field
2b90: 20 69 73 0a 2a 2a 20 6f 6d 69 74 74 65 64 20 66   is.** omitted f
2ba0: 72 6f 6d 20 74 68 65 20 61 72 74 69 66 61 63 74  rom the artifact
2bb0: 2e 20 20 46 69 65 6c 64 73 20 77 68 6f 73 65 20  .  Fields whose 
2bc0: 6e 61 6d 65 73 20 62 65 67 69 6e 20 77 69 74 68  names begin with
2bd0: 20 22 70 72 69 76 61 74 65 5f 22 0a 2a 2a 20 61   "private_".** a
2be0: 72 65 20 63 6f 6e 63 65 61 6c 65 64 20 75 73 69  re concealed usi
2bf0: 6e 67 20 74 68 65 20 64 62 5f 63 6f 6e 63 65 61  ng the db_concea
2c00: 6c 28 29 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2f  l() function..*/
2c10: 0a 73 74 61 74 69 63 20 69 6e 74 20 73 75 62 6d  .static int subm
2c20: 69 74 54 69 63 6b 65 74 43 6d 64 28 0a 20 20 54  itTicketCmd(.  T
2c30: 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70  h_Interp *interp
2c40: 2c 20 0a 20 20 76 6f 69 64 20 2a 70 55 75 69 64  , .  void *pUuid
2c50: 2c 20 0a 20 20 69 6e 74 20 61 72 67 63 2c 20 0a  , .  int argc, .
2c60: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2a 61    const char **a
2c70: 72 67 76 2c 20 0a 20 20 69 6e 74 20 2a 61 72 67  rgv, .  int *arg
2c80: 6c 0a 29 7b 0a 20 20 63 68 61 72 20 2a 7a 44 61  l.){.  char *zDa
2c90: 74 65 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72  te;.  const char
2ca0: 20 2a 7a 55 75 69 64 3b 0a 20 20 69 6e 74 20 69   *zUuid;.  int i
2cb0: 3b 0a 20 20 69 6e 74 20 72 69 64 3b 0a 20 20 42  ;.  int rid;.  B
2cc0: 6c 6f 62 20 74 6b 74 63 68 6e 67 2c 20 63 6b 73  lob tktchng, cks
2cd0: 75 6d 3b 0a 0a 20 20 6c 6f 67 69 6e 5f 76 65 72  um;..  login_ver
2ce0: 69 66 79 5f 63 73 72 66 5f 73 65 63 72 65 74 28  ify_csrf_secret(
2cf0: 29 3b 0a 20 20 7a 55 75 69 64 20 3d 20 28 63 6f  );.  zUuid = (co
2d00: 6e 73 74 20 63 68 61 72 20 2a 29 70 55 75 69 64  nst char *)pUuid
2d10: 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 74  ;.  blob_zero(&t
2d20: 6b 74 63 68 6e 67 29 3b 0a 20 20 7a 44 61 74 65  ktchng);.  zDate
2d30: 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53   = db_text(0, "S
2d40: 45 4c 45 43 54 20 64 61 74 65 74 69 6d 65 28 27  ELECT datetime('
2d50: 6e 6f 77 27 29 22 29 3b 0a 20 20 7a 44 61 74 65  now')");.  zDate
2d60: 5b 31 30 5d 20 3d 20 27 54 27 3b 0a 20 20 62 6c  [10] = 'T';.  bl
2d70: 6f 62 5f 61 70 70 65 6e 64 66 28 26 74 6b 74 63  ob_appendf(&tktc
2d80: 68 6e 67 2c 20 22 44 20 25 73 5c 6e 22 2c 20 7a  hng, "D %s\n", z
2d90: 44 61 74 65 29 3b 0a 20 20 66 72 65 65 28 7a 44  Date);.  free(zD
2da0: 61 74 65 29 3b 0a 20 20 66 6f 72 28 69 3d 30 3b  ate);.  for(i=0;
2db0: 20 69 3c 6e 46 69 65 6c 64 3b 20 69 2b 2b 29 7b   i<nField; i++){
2dc0: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20  .    const char 
2dd0: 2a 7a 56 61 6c 75 65 3b 0a 20 20 20 20 69 6e 74  *zValue;.    int
2de0: 20 6e 56 61 6c 75 65 3b 0a 20 20 20 20 69 66 28   nValue;.    if(
2df0: 20 61 7a 41 70 70 65 6e 64 5b 69 5d 20 29 7b 0a   azAppend[i] ){.
2e00: 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e        blob_appen
2e10: 64 66 28 26 74 6b 74 63 68 6e 67 2c 20 22 4a 20  df(&tktchng, "J 
2e20: 2b 25 73 20 25 7a 5c 6e 22 2c 20 61 7a 46 69 65  +%s %z\n", azFie
2e30: 6c 64 5b 69 5d 2c 0a 20 20 20 20 20 20 20 20 20  ld[i],.         
2e40: 20 20 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c            fossil
2e50: 69 7a 65 28 61 7a 41 70 70 65 6e 64 5b 69 5d 2c  ize(azAppend[i],
2e60: 20 2d 31 29 29 3b 0a 20 20 20 20 7d 65 6c 73 65   -1));.    }else
2e70: 7b 0a 20 20 20 20 20 20 7a 56 61 6c 75 65 20 3d  {.      zValue =
2e80: 20 54 68 5f 46 65 74 63 68 28 61 7a 46 69 65 6c   Th_Fetch(azFiel
2e90: 64 5b 69 5d 2c 20 26 6e 56 61 6c 75 65 29 3b 0a  d[i], &nValue);.
2ea0: 20 20 20 20 20 20 69 66 28 20 7a 56 61 6c 75 65        if( zValue
2eb0: 20 29 7b 0a 20 20 20 20 20 20 20 20 77 68 69 6c   ){.        whil
2ec0: 65 28 20 6e 56 61 6c 75 65 3e 30 20 26 26 20 69  e( nValue>0 && i
2ed0: 73 73 70 61 63 65 28 7a 56 61 6c 75 65 5b 6e 56  sspace(zValue[nV
2ee0: 61 6c 75 65 2d 31 5d 29 20 29 7b 20 6e 56 61 6c  alue-1]) ){ nVal
2ef0: 75 65 2d 2d 3b 20 7d 0a 20 20 20 20 20 20 20 20  ue--; }.        
2f00: 69 66 28 20 73 74 72 6e 63 6d 70 28 7a 56 61 6c  if( strncmp(zVal
2f10: 75 65 2c 20 61 7a 56 61 6c 75 65 5b 69 5d 2c 20  ue, azValue[i], 
2f20: 6e 56 61 6c 75 65 29 20 7c 7c 20 73 74 72 6c 65  nValue) || strle
2f30: 6e 28 61 7a 56 61 6c 75 65 5b 69 5d 29 21 3d 6e  n(azValue[i])!=n
2f40: 56 61 6c 75 65 20 29 7b 0a 20 20 20 20 20 20 20  Value ){.       
2f50: 20 20 20 69 66 28 20 73 74 72 6e 63 6d 70 28 61     if( strncmp(a
2f60: 7a 46 69 65 6c 64 5b 69 5d 2c 20 22 70 72 69 76  zField[i], "priv
2f70: 61 74 65 5f 22 2c 20 38 29 3d 3d 30 20 29 7b 0a  ate_", 8)==0 ){.
2f80: 20 20 20 20 20 20 20 20 20 20 20 20 7a 56 61 6c              zVal
2f90: 75 65 20 3d 20 64 62 5f 63 6f 6e 63 65 61 6c 28  ue = db_conceal(
2fa0: 7a 56 61 6c 75 65 2c 20 6e 56 61 6c 75 65 29 3b  zValue, nValue);
2fb0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 62 6c 6f  .            blo
2fc0: 62 5f 61 70 70 65 6e 64 66 28 26 74 6b 74 63 68  b_appendf(&tktch
2fd0: 6e 67 2c 20 22 4a 20 25 73 20 25 73 5c 6e 22 2c  ng, "J %s %s\n",
2fe0: 20 61 7a 46 69 65 6c 64 5b 69 5d 2c 20 7a 56 61   azField[i], zVa
2ff0: 6c 75 65 29 3b 0a 20 20 20 20 20 20 20 20 20 20  lue);.          
3000: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 20  }else{.         
3010: 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28     blob_appendf(
3020: 26 74 6b 74 63 68 6e 67 2c 20 22 4a 20 25 73 20  &tktchng, "J %s 
3030: 25 23 46 5c 6e 22 2c 20 61 7a 46 69 65 6c 64 5b  %#F\n", azField[
3040: 69 5d 2c 20 6e 56 61 6c 75 65 2c 20 7a 56 61 6c  i], nValue, zVal
3050: 75 65 29 3b 0a 20 20 20 20 20 20 20 20 20 20 7d  ue);.          }
3060: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20  .        }.     
3070: 20 7d 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69   }.    }.  }.  i
3080: 66 28 20 2a 28 63 68 61 72 2a 2a 29 70 55 75 69  f( *(char**)pUui
3090: 64 20 29 7b 0a 20 20 20 20 7a 55 75 69 64 20 3d  d ){.    zUuid =
30a0: 20 64 62 5f 74 65 78 74 28 30 2c 20 0a 20 20 20   db_text(0, .   
30b0: 20 20 20 20 22 53 45 4c 45 43 54 20 74 6b 74 5f      "SELECT tkt_
30c0: 75 75 69 64 20 46 52 4f 4d 20 74 69 63 6b 65 74  uuid FROM ticket
30d0: 20 57 48 45 52 45 20 74 6b 74 5f 75 75 69 64 20   WHERE tkt_uuid 
30e0: 47 4c 4f 42 20 27 25 73 2a 27 22 2c 20 50 28 22  GLOB '%s*'", P("
30f0: 6e 61 6d 65 22 29 0a 20 20 20 20 29 3b 0a 20 20  name").    );.  
3100: 7d 65 6c 73 65 7b 0a 20 20 20 20 7a 55 75 69 64  }else{.    zUuid
3110: 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53   = db_text(0, "S
3120: 45 4c 45 43 54 20 6c 6f 77 65 72 28 68 65 78 28  ELECT lower(hex(
3130: 72 61 6e 64 6f 6d 62 6c 6f 62 28 32 30 29 29 29  randomblob(20)))
3140: 22 29 3b 0a 20 20 7d 0a 20 20 2a 28 63 6f 6e 73  ");.  }.  *(cons
3150: 74 20 63 68 61 72 2a 2a 29 70 55 75 69 64 20 3d  t char**)pUuid =
3160: 20 7a 55 75 69 64 3b 0a 20 20 62 6c 6f 62 5f 61   zUuid;.  blob_a
3170: 70 70 65 6e 64 66 28 26 74 6b 74 63 68 6e 67 2c  ppendf(&tktchng,
3180: 20 22 4b 20 25 73 5c 6e 22 2c 20 7a 55 75 69 64   "K %s\n", zUuid
3190: 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64  );.  blob_append
31a0: 66 28 26 74 6b 74 63 68 6e 67 2c 20 22 55 20 25  f(&tktchng, "U %
31b0: 46 5c 6e 22 2c 20 67 2e 7a 4c 6f 67 69 6e 20 3f  F\n", g.zLogin ?
31c0: 20 67 2e 7a 4c 6f 67 69 6e 20 3a 20 22 22 29 3b   g.zLogin : "");
31d0: 0a 20 20 6d 64 35 73 75 6d 5f 62 6c 6f 62 28 26  .  md5sum_blob(&
31e0: 74 6b 74 63 68 6e 67 2c 20 26 63 6b 73 75 6d 29  tktchng, &cksum)
31f0: 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66  ;.  blob_appendf
3200: 28 26 74 6b 74 63 68 6e 67 2c 20 22 5a 20 25 62  (&tktchng, "Z %b
3210: 5c 6e 22 2c 20 26 63 6b 73 75 6d 29 3b 0a 20 20  \n", &cksum);.  
3220: 69 66 28 20 67 2e 74 68 54 72 61 63 65 20 29 7b  if( g.thTrace ){
3230: 0a 20 20 20 20 54 68 5f 54 72 61 63 65 28 22 73  .    Th_Trace("s
3240: 75 62 6d 69 74 5f 74 69 63 6b 65 74 20 7b 5c 6e  ubmit_ticket {\n
3250: 3c 62 6c 6f 63 6b 71 75 6f 74 65 3e 3c 70 72 65  <blockquote><pre
3260: 3e 5c 6e 25 68 5c 6e 3c 2f 70 72 65 3e 3c 2f 62  >\n%h\n</pre></b
3270: 6c 6f 63 6b 71 75 6f 74 65 3e 5c 6e 22 0a 20 20  lockquote>\n".  
3280: 20 20 20 20 20 20 20 20 20 20 20 22 7d 3c 62 72             "}<br
3290: 20 2f 3e 5c 6e 22 2c 0a 20 20 20 20 20 20 20 62   />\n",.       b
32a0: 6c 6f 62 5f 73 74 72 28 26 74 6b 74 63 68 6e 67  lob_str(&tktchng
32b0: 29 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  ));.  }else{.   
32c0: 20 72 69 64 20 3d 20 63 6f 6e 74 65 6e 74 5f 70   rid = content_p
32d0: 75 74 28 26 74 6b 74 63 68 6e 67 2c 20 30 2c 20  ut(&tktchng, 0, 
32e0: 30 29 3b 0a 20 20 20 20 69 66 28 20 72 69 64 3d  0);.    if( rid=
32f0: 3d 30 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73  =0 ){.      foss
3300: 69 6c 5f 70 61 6e 69 63 28 22 74 72 6f 75 62 6c  il_panic("troubl
3310: 65 20 63 6f 6d 6d 69 74 74 69 6e 67 20 74 69 63  e committing tic
3320: 6b 65 74 3a 20 25 73 22 2c 20 67 2e 7a 45 72 72  ket: %s", g.zErr
3330: 4d 73 67 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  Msg);.    }.    
3340: 6d 61 6e 69 66 65 73 74 5f 63 72 6f 73 73 6c 69  manifest_crossli
3350: 6e 6b 5f 62 65 67 69 6e 28 29 3b 0a 20 20 20 20  nk_begin();.    
3360: 6d 61 6e 69 66 65 73 74 5f 63 72 6f 73 73 6c 69  manifest_crossli
3370: 6e 6b 28 72 69 64 2c 20 26 74 6b 74 63 68 6e 67  nk(rid, &tktchng
3380: 29 3b 0a 20 20 20 20 6d 61 6e 69 66 65 73 74 5f  );.    manifest_
3390: 63 72 6f 73 73 6c 69 6e 6b 5f 65 6e 64 28 29 3b  crosslink_end();
33a0: 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 54 48  .  }.  return TH
33b0: 5f 52 45 54 55 52 4e 3b 0a 7d 0a 0a 0a 2f 2a 0a  _RETURN;.}.../*.
33c0: 2a 2a 20 57 45 42 50 41 47 45 3a 20 74 6b 74 6e  ** WEBPAGE: tktn
33d0: 65 77 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 64  ew.** WEBPAGE: d
33e0: 65 62 75 67 5f 74 6b 74 6e 65 77 0a 2a 2a 0a 2a  ebug_tktnew.**.*
33f0: 2a 20 45 6e 74 65 72 20 61 20 6e 65 77 20 74 69  * Enter a new ti
3400: 63 6b 65 74 2e 20 20 74 68 65 20 74 6b 74 6e 65  cket.  the tktne
3410: 77 5f 74 65 6d 70 6c 61 74 65 20 73 63 72 69 70  w_template scrip
3420: 74 20 69 6e 20 74 68 65 20 74 69 63 6b 65 74 0a  t in the ticket.
3430: 2a 2a 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e  ** configuration
3440: 20 69 73 20 75 73 65 64 2e 20 20 54 68 65 20 2f   is used.  The /
3450: 74 6b 74 6e 65 77 20 70 61 67 65 20 69 73 20 74  tktnew page is t
3460: 68 65 20 6f 66 66 69 63 69 61 6c 20 74 69 63 6b  he official tick
3470: 65 74 0a 2a 2a 20 65 6e 74 72 79 20 70 61 67 65  et.** entry page
3480: 2e 20 20 54 68 65 20 2f 64 65 62 75 67 5f 74 6b  .  The /debug_tk
3490: 74 6e 65 77 20 70 61 67 65 20 69 73 20 75 73 65  tnew page is use
34a0: 64 20 66 6f 72 20 64 65 62 75 67 67 69 6e 67 20  d for debugging 
34b0: 74 68 65 0a 2a 2a 20 74 6b 74 6e 65 77 5f 74 65  the.** tktnew_te
34c0: 6d 70 6c 61 74 65 20 69 6e 20 74 68 65 20 74 69  mplate in the ti
34d0: 63 6b 65 74 20 63 6f 6e 66 69 67 75 72 61 74 69  cket configurati
34e0: 6f 6e 2e 20 20 2f 64 65 62 75 67 5f 74 6b 74 6e  on.  /debug_tktn
34f0: 65 77 20 77 6f 72 6b 73 0a 2a 2a 20 6a 75 73 74  ew works.** just
3500: 20 6c 69 6b 65 20 2f 74 6b 74 6e 65 77 20 65 78   like /tktnew ex
3510: 63 65 70 74 20 74 68 61 74 20 69 74 20 64 6f 65  cept that it doe
3520: 73 20 6e 6f 74 20 72 65 61 6c 6c 79 20 73 61 76  s not really sav
3530: 65 20 74 68 65 20 6e 65 77 20 74 69 63 6b 65 74  e the new ticket
3540: 0a 2a 2a 20 77 68 65 6e 20 79 6f 75 20 70 72 65  .** when you pre
3550: 73 73 20 73 75 62 6d 69 74 20 2d 20 69 74 20 6a  ss submit - it j
3560: 75 73 74 20 70 72 69 6e 74 73 20 74 68 65 20 74  ust prints the t
3570: 69 63 6b 65 74 20 61 72 74 69 66 61 63 74 20 61  icket artifact a
3580: 74 20 74 68 65 0a 2a 2a 20 74 6f 70 20 6f 66 20  t the.** top of 
3590: 74 68 65 20 73 63 72 65 65 6e 2e 0a 2a 2f 0a 76  the screen..*/.v
35a0: 6f 69 64 20 74 6b 74 6e 65 77 5f 70 61 67 65 28  oid tktnew_page(
35b0: 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63  void){.  const c
35c0: 68 61 72 20 2a 7a 53 63 72 69 70 74 3b 0a 20 20  har *zScript;.  
35d0: 63 68 61 72 20 2a 7a 4e 65 77 55 75 69 64 20 3d  char *zNewUuid =
35e0: 20 30 3b 0a 0a 20 20 6c 6f 67 69 6e 5f 63 68 65   0;..  login_che
35f0: 63 6b 5f 63 72 65 64 65 6e 74 69 61 6c 73 28 29  ck_credentials()
3600: 3b 0a 20 20 69 66 28 20 21 67 2e 6f 6b 4e 65 77  ;.  if( !g.okNew
3610: 54 6b 74 20 29 7b 20 6c 6f 67 69 6e 5f 6e 65 65  Tkt ){ login_nee
3620: 64 65 64 28 29 3b 20 72 65 74 75 72 6e 3b 20 7d  ded(); return; }
3630: 0a 20 20 69 66 28 20 50 28 22 63 61 6e 63 65 6c  .  if( P("cancel
3640: 22 29 20 29 7b 0a 20 20 20 20 63 67 69 5f 72 65  ") ){.    cgi_re
3650: 64 69 72 65 63 74 28 22 68 6f 6d 65 22 29 3b 0a  direct("home");.
3660: 20 20 7d 0a 20 20 73 74 79 6c 65 5f 68 65 61 64    }.  style_head
3670: 65 72 28 22 4e 65 77 20 54 69 63 6b 65 74 22 29  er("New Ticket")
3680: 3b 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61 63  ;.  if( g.thTrac
3690: 65 20 29 20 54 68 5f 54 72 61 63 65 28 22 42 45  e ) Th_Trace("BE
36a0: 47 49 4e 5f 54 4b 54 4e 45 57 3c 62 72 20 2f 3e  GIN_TKTNEW<br />
36b0: 5c 6e 22 2c 20 2d 31 29 3b 0a 20 20 74 69 63 6b  \n", -1);.  tick
36c0: 65 74 5f 69 6e 69 74 28 29 3b 0a 20 20 67 65 74  et_init();.  get
36d0: 41 6c 6c 54 69 63 6b 65 74 46 69 65 6c 64 73 28  AllTicketFields(
36e0: 29 3b 0a 20 20 69 6e 69 74 69 61 6c 69 7a 65 56  );.  initializeV
36f0: 61 72 69 61 62 6c 65 73 46 72 6f 6d 44 62 28 29  ariablesFromDb()
3700: 3b 0a 20 20 69 6e 69 74 69 61 6c 69 7a 65 56 61  ;.  initializeVa
3710: 72 69 61 62 6c 65 73 46 72 6f 6d 43 47 49 28 29  riablesFromCGI()
3720: 3b 0a 20 20 40 20 3c 66 6f 72 6d 20 6d 65 74 68  ;.  @ <form meth
3730: 6f 64 3d 22 50 4f 53 54 22 20 61 63 74 69 6f 6e  od="POST" action
3740: 3d 22 25 73 28 67 2e 7a 42 61 73 65 55 52 4c 29  ="%s(g.zBaseURL)
3750: 2f 25 73 28 67 2e 7a 50 61 74 68 29 22 3e 0a 20  /%s(g.zPath)">. 
3760: 20 6c 6f 67 69 6e 5f 69 6e 73 65 72 74 5f 63 73   login_insert_cs
3770: 72 66 5f 73 65 63 72 65 74 28 29 3b 0a 20 20 7a  rf_secret();.  z
3780: 53 63 72 69 70 74 20 3d 20 74 69 63 6b 65 74 5f  Script = ticket_
3790: 6e 65 77 70 61 67 65 5f 63 6f 64 65 28 29 3b 0a  newpage_code();.
37a0: 20 20 54 68 5f 53 74 6f 72 65 28 22 6c 6f 67 69    Th_Store("logi
37b0: 6e 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20  n", g.zLogin);. 
37c0: 20 54 68 5f 53 74 6f 72 65 28 22 64 61 74 65 22   Th_Store("date"
37d0: 2c 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45  , db_text(0, "SE
37e0: 4c 45 43 54 20 64 61 74 65 74 69 6d 65 28 27 6e  LECT datetime('n
37f0: 6f 77 27 29 22 29 29 3b 0a 20 20 54 68 5f 43 72  ow')"));.  Th_Cr
3800: 65 61 74 65 43 6f 6d 6d 61 6e 64 28 67 2e 69 6e  eateCommand(g.in
3810: 74 65 72 70 2c 20 22 73 75 62 6d 69 74 5f 74 69  terp, "submit_ti
3820: 63 6b 65 74 22 2c 20 73 75 62 6d 69 74 54 69 63  cket", submitTic
3830: 6b 65 74 43 6d 64 2c 0a 20 20 20 20 20 20 20 20  ketCmd,.        
3840: 20 20 20 20 20 20 20 20 20 20 20 28 76 6f 69 64             (void
3850: 2a 29 26 7a 4e 65 77 55 75 69 64 2c 20 30 29 3b  *)&zNewUuid, 0);
3860: 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61 63 65  .  if( g.thTrace
3870: 20 29 20 54 68 5f 54 72 61 63 65 28 22 42 45 47   ) Th_Trace("BEG
3880: 49 4e 5f 54 4b 54 4e 45 57 5f 53 43 52 49 50 54  IN_TKTNEW_SCRIPT
3890: 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a  <br />\n", -1);.
38a0: 20 20 69 66 28 20 54 68 5f 52 65 6e 64 65 72 28    if( Th_Render(
38b0: 7a 53 63 72 69 70 74 29 3d 3d 54 48 5f 52 45 54  zScript)==TH_RET
38c0: 55 52 4e 20 26 26 20 21 67 2e 74 68 54 72 61 63  URN && !g.thTrac
38d0: 65 20 26 26 20 7a 4e 65 77 55 75 69 64 20 29 7b  e && zNewUuid ){
38e0: 0a 20 20 20 20 63 67 69 5f 72 65 64 69 72 65 63  .    cgi_redirec
38f0: 74 28 6d 70 72 69 6e 74 66 28 22 25 73 2f 74 6b  t(mprintf("%s/tk
3900: 74 76 69 65 77 2f 25 73 22 2c 20 67 2e 7a 42 61  tview/%s", g.zBa
3910: 73 65 55 52 4c 2c 20 7a 4e 65 77 55 75 69 64 29  seURL, zNewUuid)
3920: 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20  );.    return;. 
3930: 20 7d 0a 20 20 40 20 3c 2f 66 6f 72 6d 3e 0a 20   }.  @ </form>. 
3940: 20 69 66 28 20 67 2e 74 68 54 72 61 63 65 20 29   if( g.thTrace )
3950: 20 54 68 5f 54 72 61 63 65 28 22 45 4e 44 5f 54   Th_Trace("END_T
3960: 4b 54 56 49 45 57 3c 62 72 20 2f 3e 5c 6e 22 2c  KTVIEW<br />\n",
3970: 20 2d 31 29 3b 0a 20 20 73 74 79 6c 65 5f 66 6f   -1);.  style_fo
3980: 6f 74 65 72 28 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a  oter();.}../*.**
3990: 20 57 45 42 50 41 47 45 3a 20 74 6b 74 65 64 69   WEBPAGE: tktedi
39a0: 74 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 64 65  t.** WEBPAGE: de
39b0: 62 75 67 5f 74 6b 74 65 64 69 74 0a 2a 2a 0a 2a  bug_tktedit.**.*
39c0: 2a 20 45 64 69 74 20 61 20 74 69 63 6b 65 74 2e  * Edit a ticket.
39d0: 20 20 54 68 65 20 74 69 63 6b 65 74 20 69 73 20    The ticket is 
39e0: 69 64 65 6e 74 69 66 69 65 64 20 62 79 20 74 68  identified by th
39f0: 65 20 6e 61 6d 65 20 43 47 49 20 70 61 72 61 6d  e name CGI param
3a00: 65 74 65 72 2e 0a 2a 2a 20 2f 74 6b 74 65 64 69  eter..** /tktedi
3a10: 74 20 69 73 20 74 68 65 20 6f 66 66 69 63 69 61  t is the officia
3a20: 6c 20 70 61 67 65 2e 20 20 54 68 65 20 2f 64 65  l page.  The /de
3a30: 62 75 67 5f 74 6b 74 65 64 69 74 20 70 61 67 65  bug_tktedit page
3a40: 20 64 6f 65 73 20 74 68 65 20 73 61 6d 65 0a 2a   does the same.*
3a50: 2a 20 74 68 69 6e 67 20 65 78 63 65 70 74 20 74  * thing except t
3a60: 68 61 74 20 69 74 20 64 6f 65 73 20 6e 6f 74 20  hat it does not 
3a70: 73 61 76 65 20 74 68 65 20 74 69 63 6b 65 74 20  save the ticket 
3a80: 63 68 61 6e 67 65 20 72 65 63 6f 72 64 20 77 68  change record wh
3a90: 65 6e 20 79 6f 75 0a 2a 2a 20 70 72 65 73 73 20  en you.** press 
3aa0: 73 75 62 6d 69 74 20 2d 20 69 74 20 69 6e 73 74  submit - it inst
3ab0: 65 61 64 20 70 72 69 6e 74 73 20 74 68 65 20 74  ead prints the t
3ac0: 69 63 6b 65 74 20 63 68 61 6e 67 65 20 72 65 63  icket change rec
3ad0: 6f 72 64 20 61 74 20 74 68 65 20 74 6f 70 0a 2a  ord at the top.*
3ae0: 2a 20 6f 66 20 74 68 65 20 70 61 67 65 2e 20 20  * of the page.  
3af0: 54 68 65 20 2f 64 65 62 75 67 5f 74 6b 74 65 64  The /debug_tkted
3b00: 69 74 20 70 61 67 65 20 69 73 20 69 6e 74 65 6e  it page is inten
3b10: 64 65 64 20 74 6f 20 62 65 20 75 73 65 64 20 77  ded to be used w
3b20: 68 65 6e 0a 2a 2a 20 64 65 62 75 67 67 69 6e 67  hen.** debugging
3b30: 20 74 69 63 6b 65 74 20 63 6f 6e 66 69 67 75 72   ticket configur
3b40: 61 74 69 6f 6e 73 2e 0a 2a 2f 0a 76 6f 69 64 20  ations..*/.void 
3b50: 74 6b 74 65 64 69 74 5f 70 61 67 65 28 76 6f 69  tktedit_page(voi
3b60: 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72  d){.  const char
3b70: 20 2a 7a 53 63 72 69 70 74 3b 0a 20 20 69 6e 74   *zScript;.  int
3b80: 20 6e 4e 61 6d 65 3b 0a 20 20 63 6f 6e 73 74 20   nName;.  const 
3b90: 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 0a 20 20 69  char *zName;.  i
3ba0: 6e 74 20 6e 52 65 63 3b 0a 0a 20 20 6c 6f 67 69  nt nRec;..  logi
3bb0: 6e 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69  n_check_credenti
3bc0: 61 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67 2e  als();.  if( !g.
3bd0: 6f 6b 41 70 6e 64 54 6b 74 20 26 26 20 21 67 2e  okApndTkt && !g.
3be0: 6f 6b 57 72 54 6b 74 20 29 7b 20 6c 6f 67 69 6e  okWrTkt ){ login
3bf0: 5f 6e 65 65 64 65 64 28 29 3b 20 72 65 74 75 72  _needed(); retur
3c00: 6e 3b 20 7d 0a 20 20 7a 4e 61 6d 65 20 3d 20 50  n; }.  zName = P
3c10: 28 22 6e 61 6d 65 22 29 3b 0a 20 20 69 66 28 20  ("name");.  if( 
3c20: 50 28 22 63 61 6e 63 65 6c 22 29 20 29 7b 0a 20  P("cancel") ){. 
3c30: 20 20 20 63 67 69 5f 72 65 64 69 72 65 63 74 66     cgi_redirectf
3c40: 28 22 74 6b 74 76 69 65 77 3f 6e 61 6d 65 3d 25  ("tktview?name=%
3c50: 54 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 7d 0a  T", zName);.  }.
3c60: 20 20 73 74 79 6c 65 5f 68 65 61 64 65 72 28 22    style_header("
3c70: 45 64 69 74 20 54 69 63 6b 65 74 22 29 3b 0a 20  Edit Ticket");. 
3c80: 20 69 66 28 20 7a 4e 61 6d 65 3d 3d 30 20 7c 7c   if( zName==0 ||
3c90: 20 28 6e 4e 61 6d 65 20 3d 20 73 74 72 6c 65 6e   (nName = strlen
3ca0: 28 7a 4e 61 6d 65 29 29 3c 34 20 7c 7c 20 6e 4e  (zName))<4 || nN
3cb0: 61 6d 65 3e 55 55 49 44 5f 53 49 5a 45 0a 20 20  ame>UUID_SIZE.  
3cc0: 20 20 20 20 20 20 20 20 7c 7c 20 21 76 61 6c 69          || !vali
3cd0: 64 61 74 65 31 36 28 7a 4e 61 6d 65 2c 6e 4e 61  date16(zName,nNa
3ce0: 6d 65 29 20 29 7b 0a 20 20 20 20 40 20 3c 66 6f  me) ){.    @ <fo
3cf0: 6e 74 20 63 6f 6c 6f 72 3d 22 72 65 64 22 3e 3c  nt color="red"><
3d00: 62 3e 4e 6f 74 20 61 20 76 61 6c 69 64 20 74 69  b>Not a valid ti
3d10: 63 6b 65 74 20 69 64 3a 20 5c 22 25 68 28 7a 4e  cket id: \"%h(zN
3d20: 61 6d 65 29 5c 22 3c 2f 62 3e 3c 2f 66 6f 6e 74  ame)\"</b></font
3d30: 3e 0a 20 20 20 20 73 74 79 6c 65 5f 66 6f 6f 74  >.    style_foot
3d40: 65 72 28 29 3b 0a 20 20 20 20 72 65 74 75 72 6e  er();.    return
3d50: 3b 0a 20 20 7d 0a 20 20 6e 52 65 63 20 3d 20 64  ;.  }.  nRec = d
3d60: 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54  b_int(0, "SELECT
3d70: 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74   count(*) FROM t
3d80: 69 63 6b 65 74 20 57 48 45 52 45 20 74 6b 74 5f  icket WHERE tkt_
3d90: 75 75 69 64 20 47 4c 4f 42 20 27 25 71 2a 27 22  uuid GLOB '%q*'"
3da0: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
3db0: 20 20 7a 4e 61 6d 65 29 3b 0a 20 20 69 66 28 20    zName);.  if( 
3dc0: 6e 52 65 63 3d 3d 30 20 29 7b 0a 20 20 20 20 40  nRec==0 ){.    @
3dd0: 20 3c 66 6f 6e 74 20 63 6f 6c 6f 72 3d 22 72 65   <font color="re
3de0: 64 22 3e 3c 62 3e 4e 6f 20 73 75 63 68 20 74 69  d"><b>No such ti
3df0: 63 6b 65 74 3a 20 5c 22 25 68 28 7a 4e 61 6d 65  cket: \"%h(zName
3e00: 29 5c 22 3c 2f 62 3e 3c 2f 66 6f 6e 74 3e 0a 20  )\"</b></font>. 
3e10: 20 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28     style_footer(
3e20: 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20  );.    return;. 
3e30: 20 7d 0a 20 20 69 66 28 20 6e 52 65 63 3e 31 20   }.  if( nRec>1 
3e40: 29 7b 0a 20 20 20 20 40 20 3c 66 6f 6e 74 20 63  ){.    @ <font c
3e50: 6f 6c 6f 72 3d 22 72 65 64 22 3e 3c 62 3e 25 64  olor="red"><b>%d
3e60: 28 6e 52 65 63 29 20 74 69 63 6b 65 74 73 20 62  (nRec) tickets b
3e70: 65 67 69 6e 20 77 69 74 68 3a 20 5c 22 25 68 28  egin with: \"%h(
3e80: 7a 4e 61 6d 65 29 5c 22 3c 2f 62 3e 3c 2f 66 6f  zName)\"</b></fo
3e90: 6e 74 3e 0a 20 20 20 20 73 74 79 6c 65 5f 66 6f  nt>.    style_fo
3ea0: 6f 74 65 72 28 29 3b 0a 20 20 20 20 72 65 74 75  oter();.    retu
3eb0: 72 6e 3b 0a 20 20 7d 0a 20 20 69 66 28 20 67 2e  rn;.  }.  if( g.
3ec0: 74 68 54 72 61 63 65 20 29 20 54 68 5f 54 72 61  thTrace ) Th_Tra
3ed0: 63 65 28 22 42 45 47 49 4e 5f 54 4b 54 45 44 49  ce("BEGIN_TKTEDI
3ee0: 54 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b  T<br />\n", -1);
3ef0: 0a 20 20 74 69 63 6b 65 74 5f 69 6e 69 74 28 29  .  ticket_init()
3f00: 3b 0a 20 20 67 65 74 41 6c 6c 54 69 63 6b 65 74  ;.  getAllTicket
3f10: 46 69 65 6c 64 73 28 29 3b 0a 20 20 69 6e 69 74  Fields();.  init
3f20: 69 61 6c 69 7a 65 56 61 72 69 61 62 6c 65 73 46  ializeVariablesF
3f30: 72 6f 6d 43 47 49 28 29 3b 0a 20 20 69 6e 69 74  romCGI();.  init
3f40: 69 61 6c 69 7a 65 56 61 72 69 61 62 6c 65 73 46  ializeVariablesF
3f50: 72 6f 6d 44 62 28 29 3b 0a 20 20 40 20 3c 66 6f  romDb();.  @ <fo
3f60: 72 6d 20 6d 65 74 68 6f 64 3d 22 50 4f 53 54 22  rm method="POST"
3f70: 20 61 63 74 69 6f 6e 3d 22 25 73 28 67 2e 7a 42   action="%s(g.zB
3f80: 61 73 65 55 52 4c 29 2f 25 73 28 67 2e 7a 50 61  aseURL)/%s(g.zPa
3f90: 74 68 29 22 3e 0a 20 20 40 20 3c 69 6e 70 75 74  th)">.  @ <input
3fa0: 20 74 79 70 65 3d 22 68 69 64 64 65 6e 22 20 6e   type="hidden" n
3fb0: 61 6d 65 3d 22 6e 61 6d 65 22 20 76 61 6c 75 65  ame="name" value
3fc0: 3d 22 25 73 28 7a 4e 61 6d 65 29 22 3e 0a 20 20  ="%s(zName)">.  
3fd0: 6c 6f 67 69 6e 5f 69 6e 73 65 72 74 5f 63 73 72  login_insert_csr
3fe0: 66 5f 73 65 63 72 65 74 28 29 3b 0a 20 20 7a 53  f_secret();.  zS
3ff0: 63 72 69 70 74 20 3d 20 74 69 63 6b 65 74 5f 65  cript = ticket_e
4000: 64 69 74 70 61 67 65 5f 63 6f 64 65 28 29 3b 0a  ditpage_code();.
4010: 20 20 54 68 5f 53 74 6f 72 65 28 22 6c 6f 67 69    Th_Store("logi
4020: 6e 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20  n", g.zLogin);. 
4030: 20 54 68 5f 53 74 6f 72 65 28 22 64 61 74 65 22   Th_Store("date"
4040: 2c 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45  , db_text(0, "SE
4050: 4c 45 43 54 20 64 61 74 65 74 69 6d 65 28 27 6e  LECT datetime('n
4060: 6f 77 27 29 22 29 29 3b 0a 20 20 54 68 5f 43 72  ow')"));.  Th_Cr
4070: 65 61 74 65 43 6f 6d 6d 61 6e 64 28 67 2e 69 6e  eateCommand(g.in
4080: 74 65 72 70 2c 20 22 61 70 70 65 6e 64 5f 66 69  terp, "append_fi
4090: 65 6c 64 22 2c 20 61 70 70 65 6e 64 52 65 6d 61  eld", appendRema
40a0: 72 6b 43 6d 64 2c 20 30 2c 20 30 29 3b 0a 20 20  rkCmd, 0, 0);.  
40b0: 54 68 5f 43 72 65 61 74 65 43 6f 6d 6d 61 6e 64  Th_CreateCommand
40c0: 28 67 2e 69 6e 74 65 72 70 2c 20 22 73 75 62 6d  (g.interp, "subm
40d0: 69 74 5f 74 69 63 6b 65 74 22 2c 20 73 75 62 6d  it_ticket", subm
40e0: 69 74 54 69 63 6b 65 74 43 6d 64 2c 20 28 76 6f  itTicketCmd, (vo
40f0: 69 64 2a 29 26 7a 4e 61 6d 65 2c 30 29 3b 0a 20  id*)&zName,0);. 
4100: 20 69 66 28 20 67 2e 74 68 54 72 61 63 65 20 29   if( g.thTrace )
4110: 20 54 68 5f 54 72 61 63 65 28 22 42 45 47 49 4e   Th_Trace("BEGIN
4120: 5f 54 4b 54 45 44 49 54 5f 53 43 52 49 50 54 3c  _TKTEDIT_SCRIPT<
4130: 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a 20  br />\n", -1);. 
4140: 20 69 66 28 20 54 68 5f 52 65 6e 64 65 72 28 7a   if( Th_Render(z
4150: 53 63 72 69 70 74 29 3d 3d 54 48 5f 52 45 54 55  Script)==TH_RETU
4160: 52 4e 20 26 26 20 21 67 2e 74 68 54 72 61 63 65  RN && !g.thTrace
4170: 20 26 26 20 7a 4e 61 6d 65 20 29 7b 0a 20 20 20   && zName ){.   
4180: 20 63 67 69 5f 72 65 64 69 72 65 63 74 28 6d 70   cgi_redirect(mp
4190: 72 69 6e 74 66 28 22 25 73 2f 74 6b 74 76 69 65  rintf("%s/tktvie
41a0: 77 2f 25 73 22 2c 20 67 2e 7a 42 61 73 65 55 52  w/%s", g.zBaseUR
41b0: 4c 2c 20 7a 4e 61 6d 65 29 29 3b 0a 20 20 20 20  L, zName));.    
41c0: 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 40 20  return;.  }.  @ 
41d0: 3c 2f 66 6f 72 6d 3e 0a 20 20 69 66 28 20 67 2e  </form>.  if( g.
41e0: 74 68 54 72 61 63 65 20 29 20 54 68 5f 54 72 61  thTrace ) Th_Tra
41f0: 63 65 28 22 42 45 47 49 4e 5f 54 4b 54 45 44 49  ce("BEGIN_TKTEDI
4200: 54 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b  T<br />\n", -1);
4210: 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28  .  style_footer(
4220: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 68 65 63  );.}../*.** Chec
4230: 6b 20 74 68 65 20 74 69 63 6b 65 74 20 74 61 62  k the ticket tab
4240: 6c 65 20 73 63 68 65 6d 61 20 69 6e 20 7a 53 63  le schema in zSc
4250: 68 65 6d 61 20 74 6f 20 73 65 65 20 69 66 20 69  hema to see if i
4260: 74 20 61 70 70 65 61 72 73 20 74 6f 0a 2a 2a 20  t appears to.** 
4270: 62 65 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 2e 20  be well-formed. 
4280: 20 49 66 20 65 76 65 72 79 74 68 69 6e 67 20 69   If everything i
4290: 73 20 4f 4b 2c 20 72 65 74 75 72 6e 20 4e 55 4c  s OK, return NUL
42a0: 4c 2e 20 20 49 66 20 73 6f 6d 65 74 68 69 6e 67  L.  If something
42b0: 20 69 73 0a 2a 2a 20 61 6d 69 73 73 2c 20 74 68   is.** amiss, th
42c0: 65 6e 20 72 65 74 75 72 6e 20 61 20 70 6f 69 6e  en return a poin
42d0: 74 65 72 20 74 6f 20 61 20 73 74 72 69 6e 67 20  ter to a string 
42e0: 28 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d 20 6d  (obtained from m
42f0: 61 6c 6c 6f 63 29 20 74 68 61 74 0a 2a 2a 20 64  alloc) that.** d
4300: 65 73 63 72 69 62 65 73 20 74 68 65 20 70 72 6f  escribes the pro
4310: 62 6c 65 6d 2e 0a 2a 2f 0a 63 68 61 72 20 2a 74  blem..*/.char *t
4320: 69 63 6b 65 74 5f 73 63 68 65 6d 61 5f 63 68 65  icket_schema_che
4330: 63 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  ck(const char *z
4340: 53 63 68 65 6d 61 29 7b 0a 20 20 63 68 61 72 20  Schema){.  char 
4350: 2a 7a 45 72 72 20 3d 20 30 3b 0a 20 20 69 6e 74  *zErr = 0;.  int
4360: 20 72 63 3b 0a 20 20 73 71 6c 69 74 65 33 20 2a   rc;.  sqlite3 *
4370: 64 62 3b 0a 20 20 72 63 20 3d 20 73 71 6c 69 74  db;.  rc = sqlit
4380: 65 33 5f 6f 70 65 6e 28 22 3a 6d 65 6d 6f 72 79  e3_open(":memory
4390: 3a 22 2c 20 26 64 62 29 3b 0a 20 20 69 66 28 20  :", &db);.  if( 
43a0: 72 63 3d 3d 53 51 4c 49 54 45 5f 4f 4b 20 29 7b  rc==SQLITE_OK ){
43b0: 0a 20 20 20 20 72 63 20 3d 20 73 71 6c 69 74 65  .    rc = sqlite
43c0: 33 5f 65 78 65 63 28 64 62 2c 20 7a 53 63 68 65  3_exec(db, zSche
43d0: 6d 61 2c 20 30 2c 20 30 2c 20 26 7a 45 72 72 29  ma, 0, 0, &zErr)
43e0: 3b 0a 20 20 20 20 69 66 28 20 72 63 21 3d 53 51  ;.    if( rc!=SQ
43f0: 4c 49 54 45 5f 4f 4b 20 29 7b 0a 20 20 20 20 20  LITE_OK ){.     
4400: 20 73 71 6c 69 74 65 33 5f 63 6c 6f 73 65 28 64   sqlite3_close(d
4410: 62 29 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e  b);.      return
4420: 20 7a 45 72 72 3b 0a 20 20 20 20 7d 0a 20 20 20   zErr;.    }.   
4430: 20 72 63 20 3d 20 73 71 6c 69 74 65 33 5f 65 78   rc = sqlite3_ex
4440: 65 63 28 64 62 2c 20 22 53 45 4c 45 43 54 20 74  ec(db, "SELECT t
4450: 6b 74 5f 69 64 2c 20 74 6b 74 5f 75 75 69 64 2c  kt_id, tkt_uuid,
4460: 20 74 6b 74 5f 6d 74 69 6d 65 20 46 52 4f 4d 20   tkt_mtime FROM 
4470: 74 69 63 6b 65 74 22 2c 0a 20 20 20 20 20 20 20  ticket",.       
4480: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30                 0
4490: 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 73 71 6c  , 0, 0);.    sql
44a0: 69 74 65 33 5f 63 6c 6f 73 65 28 64 62 29 3b 0a  ite3_close(db);.
44b0: 20 20 20 20 69 66 28 20 72 63 21 3d 53 51 4c 49      if( rc!=SQLI
44c0: 54 45 5f 4f 4b 20 29 7b 0a 20 20 20 20 20 20 7a  TE_OK ){.      z
44d0: 45 72 72 20 3d 20 6d 70 72 69 6e 74 66 28 22 73  Err = mprintf("s
44e0: 63 68 65 6d 61 20 66 61 69 6c 73 20 74 6f 20 64  chema fails to d
44f0: 65 66 69 6e 65 20 61 20 76 61 6c 69 64 20 74 69  efine a valid ti
4500: 63 6b 65 74 20 74 61 62 6c 65 20 22 0a 20 20 20  cket table ".   
4510: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
4520: 20 20 22 63 6f 6e 74 61 69 6e 69 6e 67 20 61 6c    "containing al
4530: 6c 20 72 65 71 75 69 72 65 64 20 66 69 65 6c 64  l required field
4540: 73 22 29 3b 0a 20 20 20 20 20 20 72 65 74 75 72  s");.      retur
4550: 6e 20 7a 45 72 72 3b 0a 20 20 20 20 7d 0a 20 20  n zErr;.    }.  
4560: 7d 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a  }.  return 0;.}.
4570: 0a 2f 2a 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20  ./*.** WEBPAGE: 
4580: 74 6b 74 74 69 6d 65 6c 69 6e 65 0a 2a 2a 20 55  tkttimeline.** U
4590: 52 4c 3a 20 2f 74 6b 74 74 69 6d 65 6c 69 6e 65  RL: /tkttimeline
45a0: 3f 6e 61 6d 65 3d 54 49 43 4b 45 54 55 55 49 44  ?name=TICKETUUID
45b0: 0a 2a 2a 0a 2a 2a 20 53 68 6f 77 20 74 68 65 20  .**.** Show the 
45c0: 63 68 61 6e 67 65 20 68 69 73 74 6f 72 79 20 66  change history f
45d0: 6f 72 20 61 20 73 69 6e 67 6c 65 20 74 69 63 6b  or a single tick
45e0: 65 74 20 69 6e 20 74 69 6d 65 6c 69 6e 65 20 66  et in timeline f
45f0: 6f 72 6d 61 74 2e 0a 2a 2f 0a 76 6f 69 64 20 74  ormat..*/.void t
4600: 6b 74 74 69 6d 65 6c 69 6e 65 5f 70 61 67 65 28  kttimeline_page(
4610: 76 6f 69 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b  void){.  Stmt q;
4620: 0a 20 20 63 68 61 72 20 2a 7a 54 69 74 6c 65 3b  .  char *zTitle;
4630: 0a 20 20 63 68 61 72 20 2a 7a 53 51 4c 3b 0a 20  .  char *zSQL;. 
4640: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 55 75   const char *zUu
4650: 69 64 3b 0a 20 20 69 6e 74 20 74 61 67 69 64 3b  id;.  int tagid;
4660: 0a 0a 20 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f  ..  login_check_
4670: 63 72 65 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20  credentials();. 
4680: 20 69 66 28 20 21 67 2e 6f 6b 48 69 73 74 6f 72   if( !g.okHistor
4690: 79 20 7c 7c 20 21 67 2e 6f 6b 52 64 54 6b 74 20  y || !g.okRdTkt 
46a0: 29 7b 20 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28  ){ login_needed(
46b0: 29 3b 20 72 65 74 75 72 6e 3b 20 7d 0a 20 20 7a  ); return; }.  z
46c0: 55 75 69 64 20 3d 20 50 44 28 22 6e 61 6d 65 22  Uuid = PD("name"
46d0: 2c 22 22 29 3b 0a 20 20 73 74 79 6c 65 5f 73 75  ,"");.  style_su
46e0: 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 48  bmenu_element("H
46f0: 69 73 74 6f 72 79 22 2c 20 22 48 69 73 74 6f 72  istory", "Histor
4700: 79 22 2c 0a 20 20 20 20 22 25 73 2f 74 6b 74 68  y",.    "%s/tkth
4710: 69 73 74 6f 72 79 2f 25 73 22 2c 20 67 2e 7a 54  istory/%s", g.zT
4720: 6f 70 2c 20 7a 55 75 69 64 29 3b 0a 20 20 73 74  op, zUuid);.  st
4730: 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d  yle_submenu_elem
4740: 65 6e 74 28 22 53 74 61 74 75 73 22 2c 20 22 53  ent("Status", "S
4750: 74 61 74 75 73 22 2c 0a 20 20 20 20 22 25 73 2f  tatus",.    "%s/
4760: 69 6e 66 6f 2f 25 73 22 2c 20 67 2e 7a 54 6f 70  info/%s", g.zTop
4770: 2c 20 7a 55 75 69 64 29 3b 0a 20 20 7a 54 69 74  , zUuid);.  zTit
4780: 6c 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 54 69  le = mprintf("Ti
4790: 6d 65 6c 69 6e 65 20 4f 66 20 54 69 63 6b 65 74  meline Of Ticket
47a0: 20 25 68 22 2c 20 7a 55 75 69 64 29 3b 0a 20 20   %h", zUuid);.  
47b0: 73 74 79 6c 65 5f 68 65 61 64 65 72 28 7a 54 69  style_header(zTi
47c0: 74 6c 65 29 3b 0a 20 20 66 72 65 65 28 7a 54 69  tle);.  free(zTi
47d0: 74 6c 65 29 3b 0a 0a 20 20 74 61 67 69 64 20 3d  tle);..  tagid =
47e0: 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45   db_int(0, "SELE
47f0: 43 54 20 74 61 67 69 64 20 46 52 4f 4d 20 74 61  CT tagid FROM ta
4800: 67 20 57 48 45 52 45 20 74 61 67 6e 61 6d 65 20  g WHERE tagname 
4810: 47 4c 4f 42 20 27 74 6b 74 2d 25 71 2a 27 22 2c  GLOB 'tkt-%q*'",
4820: 7a 55 75 69 64 29 3b 0a 20 20 69 66 28 20 74 61  zUuid);.  if( ta
4830: 67 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 40 20  gid==0 ){.    @ 
4840: 4e 6f 20 73 75 63 68 20 74 69 63 6b 65 74 3a 20  No such ticket: 
4850: 25 68 28 7a 55 75 69 64 29 0a 20 20 20 20 73 74  %h(zUuid).    st
4860: 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 20 20  yle_footer();.  
4870: 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20    return;.  }.  
4880: 7a 53 51 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22  zSQL = mprintf("
4890: 25 73 20 41 4e 44 20 65 76 65 6e 74 2e 6f 62 6a  %s AND event.obj
48a0: 69 64 20 49 4e 20 22 0a 20 20 20 20 20 20 20 20  id IN ".        
48b0: 20 20 20 20 20 20 20 20 20 22 20 20 28 53 45 4c           "  (SEL
48c0: 45 43 54 20 72 69 64 20 46 52 4f 4d 20 74 61 67  ECT rid FROM tag
48d0: 78 72 65 66 20 57 48 45 52 45 20 74 61 67 69 64  xref WHERE tagid
48e0: 3d 25 64 29 20 22 0a 20 20 20 20 20 20 20 20 20  =%d) ".         
48f0: 20 20 20 20 20 20 20 20 22 4f 52 44 45 52 20 42          "ORDER B
4900: 59 20 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20  Y mtime DESC",. 
4910: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
4920: 74 69 6d 65 6c 69 6e 65 5f 71 75 65 72 79 5f 66  timeline_query_f
4930: 6f 72 5f 77 77 77 28 29 2c 20 74 61 67 69 64 29  or_www(), tagid)
4940: 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26  ;.  db_prepare(&
4950: 71 2c 20 7a 53 51 4c 29 3b 0a 20 20 66 72 65 65  q, zSQL);.  free
4960: 28 7a 53 51 4c 29 3b 0a 20 20 77 77 77 5f 70 72  (zSQL);.  www_pr
4970: 69 6e 74 5f 74 69 6d 65 6c 69 6e 65 28 26 71 2c  int_timeline(&q,
4980: 20 54 49 4d 45 4c 49 4e 45 5f 41 52 54 49 44 2c   TIMELINE_ARTID,
4990: 20 30 29 3b 0a 20 20 64 62 5f 66 69 6e 61 6c 69   0);.  db_finali
49a0: 7a 65 28 26 71 29 3b 0a 20 20 73 74 79 6c 65 5f  ze(&q);.  style_
49b0: 66 6f 6f 74 65 72 28 29 3b 0a 7d 0a 0a 2f 2a 0a  footer();.}../*.
49c0: 2a 2a 20 57 45 42 50 41 47 45 3a 20 74 6b 74 68  ** WEBPAGE: tkth
49d0: 69 73 74 6f 72 79 0a 2a 2a 20 55 52 4c 3a 20 2f  istory.** URL: /
49e0: 74 6b 74 68 69 73 74 6f 72 79 3f 6e 61 6d 65 3d  tkthistory?name=
49f0: 54 49 43 4b 45 54 55 55 49 44 0a 2a 2a 0a 2a 2a  TICKETUUID.**.**
4a00: 20 53 68 6f 77 20 74 68 65 20 63 6f 6d 70 6c 65   Show the comple
4a10: 74 65 20 63 68 61 6e 67 65 20 68 69 73 74 6f 72  te change histor
4a20: 79 20 66 6f 72 20 61 20 73 69 6e 67 6c 65 20 74  y for a single t
4a30: 69 63 6b 65 74 0a 2a 2f 0a 76 6f 69 64 20 74 6b  icket.*/.void tk
4a40: 74 68 69 73 74 6f 72 79 5f 70 61 67 65 28 76 6f  thistory_page(vo
4a50: 69 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a 20  id){.  Stmt q;. 
4a60: 20 63 68 61 72 20 2a 7a 54 69 74 6c 65 3b 0a 20   char *zTitle;. 
4a70: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 55 75   const char *zUu
4a80: 69 64 3b 0a 20 20 69 6e 74 20 74 61 67 69 64 3b  id;.  int tagid;
4a90: 0a 0a 20 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f  ..  login_check_
4aa0: 63 72 65 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20  credentials();. 
4ab0: 20 69 66 28 20 21 67 2e 6f 6b 48 69 73 74 6f 72   if( !g.okHistor
4ac0: 79 20 7c 7c 20 21 67 2e 6f 6b 52 64 54 6b 74 20  y || !g.okRdTkt 
4ad0: 29 7b 20 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28  ){ login_needed(
4ae0: 29 3b 20 72 65 74 75 72 6e 3b 20 7d 0a 20 20 7a  ); return; }.  z
4af0: 55 75 69 64 20 3d 20 50 44 28 22 6e 61 6d 65 22  Uuid = PD("name"
4b00: 2c 22 22 29 3b 0a 20 20 7a 54 69 74 6c 65 20 3d  ,"");.  zTitle =
4b10: 20 6d 70 72 69 6e 74 66 28 22 48 69 73 74 6f 72   mprintf("Histor
4b20: 79 20 4f 66 20 54 69 63 6b 65 74 20 25 68 22 2c  y Of Ticket %h",
4b30: 20 7a 55 75 69 64 29 3b 0a 20 20 73 74 79 6c 65   zUuid);.  style
4b40: 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74  _submenu_element
4b50: 28 22 53 74 61 74 75 73 22 2c 20 22 53 74 61 74  ("Status", "Stat
4b60: 75 73 22 2c 0a 20 20 20 20 22 25 73 2f 69 6e 66  us",.    "%s/inf
4b70: 6f 2f 25 73 22 2c 20 67 2e 7a 54 6f 70 2c 20 7a  o/%s", g.zTop, z
4b80: 55 75 69 64 29 3b 0a 20 20 73 74 79 6c 65 5f 73  Uuid);.  style_s
4b90: 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 22  ubmenu_element("
4ba0: 54 69 6d 65 6c 69 6e 65 22 2c 20 22 54 69 6d 65  Timeline", "Time
4bb0: 6c 69 6e 65 22 2c 0a 20 20 20 20 22 25 73 2f 74  line",.    "%s/t
4bc0: 6b 74 74 69 6d 65 6c 69 6e 65 3f 6e 61 6d 65 3d  kttimeline?name=
4bd0: 25 73 22 2c 20 67 2e 7a 54 6f 70 2c 20 7a 55 75  %s", g.zTop, zUu
4be0: 69 64 29 3b 0a 20 20 73 74 79 6c 65 5f 68 65 61  id);.  style_hea
4bf0: 64 65 72 28 7a 54 69 74 6c 65 29 3b 0a 20 20 66  der(zTitle);.  f
4c00: 72 65 65 28 7a 54 69 74 6c 65 29 3b 0a 0a 20 20  ree(zTitle);..  
4c10: 74 61 67 69 64 20 3d 20 64 62 5f 69 6e 74 28 30  tagid = db_int(0
4c20: 2c 20 22 53 45 4c 45 43 54 20 74 61 67 69 64 20  , "SELECT tagid 
4c30: 46 52 4f 4d 20 74 61 67 20 57 48 45 52 45 20 74  FROM tag WHERE t
4c40: 61 67 6e 61 6d 65 20 47 4c 4f 42 20 27 74 6b 74  agname GLOB 'tkt
4c50: 2d 25 71 2a 27 22 2c 7a 55 75 69 64 29 3b 0a 20  -%q*'",zUuid);. 
4c60: 20 69 66 28 20 74 61 67 69 64 3d 3d 30 20 29 7b   if( tagid==0 ){
4c70: 0a 20 20 20 20 40 20 4e 6f 20 73 75 63 68 20 74  .    @ No such t
4c80: 69 63 6b 65 74 3a 20 25 68 28 7a 55 75 69 64 29  icket: %h(zUuid)
4c90: 0a 20 20 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65  .    style_foote
4ca0: 72 28 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b  r();.    return;
4cb0: 0a 20 20 7d 0a 20 20 64 62 5f 70 72 65 70 61 72  .  }.  db_prepar
4cc0: 65 28 26 71 2c 0a 20 20 20 20 22 53 45 4c 45 43  e(&q,.    "SELEC
4cd0: 54 20 6f 62 6a 69 64 2c 20 75 75 69 64 20 46 52  T objid, uuid FR
4ce0: 4f 4d 20 65 76 65 6e 74 2c 20 62 6c 6f 62 22 0a  OM event, blob".
4cf0: 20 20 20 20 22 20 57 48 45 52 45 20 6f 62 6a 69      " WHERE obji
4d00: 64 20 49 4e 20 28 53 45 4c 45 43 54 20 72 69 64  d IN (SELECT rid
4d10: 20 46 52 4f 4d 20 74 61 67 78 72 65 66 20 57 48   FROM tagxref WH
4d20: 45 52 45 20 74 61 67 69 64 3d 25 64 29 22 0a 20  ERE tagid=%d)". 
4d30: 20 20 20 22 20 20 20 41 4e 44 20 62 6c 6f 62 2e     "   AND blob.
4d40: 72 69 64 3d 65 76 65 6e 74 2e 6f 62 6a 69 64 22  rid=event.objid"
4d50: 0a 20 20 20 20 22 20 4f 52 44 45 52 20 42 59 20  .    " ORDER BY 
4d60: 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20 20 20  mtime DESC",.   
4d70: 20 74 61 67 69 64 0a 20 20 29 3b 0a 20 20 77 68   tagid.  );.  wh
4d80: 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29  ile( db_step(&q)
4d90: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a  ==SQLITE_ROW ){.
4da0: 20 20 20 20 42 6c 6f 62 20 63 6f 6e 74 65 6e 74      Blob content
4db0: 3b 0a 20 20 20 20 4d 61 6e 69 66 65 73 74 20 6d  ;.    Manifest m
4dc0: 3b 0a 20 20 20 20 69 6e 74 20 72 69 64 20 3d 20  ;.    int rid = 
4dd0: 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71  db_column_int(&q
4de0: 2c 20 30 29 3b 0a 20 20 20 20 63 6f 6e 73 74 20  , 0);.    const 
4df0: 63 68 61 72 20 2a 7a 43 68 6e 67 55 75 69 64 20  char *zChngUuid 
4e00: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74  = db_column_text
4e10: 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 63 6f 6e  (&q, 1);.    con
4e20: 74 65 6e 74 5f 67 65 74 28 72 69 64 2c 20 26 63  tent_get(rid, &c
4e30: 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20 69 66 28  ontent);.    if(
4e40: 20 6d 61 6e 69 66 65 73 74 5f 70 61 72 73 65 28   manifest_parse(
4e50: 26 6d 2c 20 26 63 6f 6e 74 65 6e 74 29 20 26 26  &m, &content) &&
4e60: 20 6d 2e 74 79 70 65 3d 3d 43 46 54 59 50 45 5f   m.type==CFTYPE_
4e70: 54 49 43 4b 45 54 20 29 7b 0a 20 20 20 20 20 20  TICKET ){.      
4e80: 63 68 61 72 20 2a 7a 44 61 74 65 20 3d 20 64 62  char *zDate = db
4e90: 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54  _text(0, "SELECT
4ea0: 20 64 61 74 65 74 69 6d 65 28 25 2e 31 32 66 29   datetime(%.12f)
4eb0: 22 2c 20 6d 2e 72 44 61 74 65 29 3b 0a 20 20 20  ", m.rDate);.   
4ec0: 20 20 20 63 68 61 72 20 7a 55 75 69 64 5b 31 32     char zUuid[12
4ed0: 5d 3b 0a 20 20 20 20 20 20 6d 65 6d 63 70 79 28  ];.      memcpy(
4ee0: 7a 55 75 69 64 2c 20 7a 43 68 6e 67 55 75 69 64  zUuid, zChngUuid
4ef0: 2c 20 31 30 29 3b 0a 20 20 20 20 20 20 7a 55 75  , 10);.      zUu
4f00: 69 64 5b 31 30 5d 20 3d 20 30 3b 0a 20 20 20 20  id[10] = 0;.    
4f10: 20 20 40 0a 20 20 20 20 20 20 40 20 54 69 63 6b    @.      @ Tick
4f20: 65 74 20 63 68 61 6e 67 65 0a 20 20 20 20 20 20  et change.      
4f30: 40 20 5b 3c 61 20 68 72 65 66 3d 22 25 73 28 67  @ [<a href="%s(g
4f40: 2e 7a 54 6f 70 29 2f 61 72 74 69 66 61 63 74 2f  .zTop)/artifact/
4f50: 25 54 28 7a 43 68 6e 67 55 75 69 64 29 22 3e 25  %T(zChngUuid)">%
4f60: 73 28 7a 55 75 69 64 29 3c 2f 61 3e 5d 3c 2f 61  s(zUuid)</a>]</a
4f70: 3e 0a 20 20 20 20 20 20 40 20 28 72 69 64 20 25  >.      @ (rid %
4f80: 64 28 72 69 64 29 29 20 62 79 0a 20 20 20 20 20  d(rid)) by.     
4f90: 20 68 79 70 65 72 6c 69 6e 6b 5f 74 6f 5f 75 73   hyperlink_to_us
4fa0: 65 72 28 6d 2e 7a 55 73 65 72 2c 7a 44 61 74 65  er(m.zUser,zDate
4fb0: 2c 22 20 6f 6e 22 29 3b 0a 20 20 20 20 20 20 68  ," on");.      h
4fc0: 79 70 65 72 6c 69 6e 6b 5f 74 6f 5f 64 61 74 65  yperlink_to_date
4fd0: 28 7a 44 61 74 65 2c 20 22 3a 22 29 3b 0a 20 20  (zDate, ":");.  
4fe0: 20 20 20 20 66 72 65 65 28 7a 44 61 74 65 29 3b      free(zDate);
4ff0: 0a 20 20 20 20 20 20 74 69 63 6b 65 74 5f 6f 75  .      ticket_ou
5000: 74 70 75 74 5f 63 68 61 6e 67 65 5f 61 72 74 69  tput_change_arti
5010: 66 61 63 74 28 26 6d 29 3b 0a 20 20 20 20 7d 0a  fact(&m);.    }.
5020: 20 20 20 20 6d 61 6e 69 66 65 73 74 5f 63 6c 65      manifest_cle
5030: 61 72 28 26 6d 29 3b 0a 20 20 7d 0a 20 20 64 62  ar(&m);.  }.  db
5040: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20  _finalize(&q);. 
5050: 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b   style_footer();
5060: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e  .}../*.** Return
5070: 20 54 52 55 45 20 69 66 20 74 68 65 20 67 69 76   TRUE if the giv
5080: 65 6e 20 42 4c 4f 42 20 63 6f 6e 74 61 69 6e 73  en BLOB contains
5090: 20 61 20 6e 65 77 6c 69 6e 65 20 63 68 61 72 61   a newline chara
50a0: 63 74 65 72 2e 0a 2a 2f 0a 73 74 61 74 69 63 20  cter..*/.static 
50b0: 69 6e 74 20 63 6f 6e 74 61 69 6e 73 5f 6e 65 77  int contains_new
50c0: 6c 69 6e 65 28 42 6c 6f 62 20 2a 70 29 7b 0a 20  line(Blob *p){. 
50d0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 20 3d   const char *z =
50e0: 20 62 6c 6f 62 5f 73 74 72 28 70 29 3b 0a 20 20   blob_str(p);.  
50f0: 77 68 69 6c 65 28 20 2a 7a 20 29 7b 0a 20 20 20  while( *z ){.   
5100: 20 69 66 28 20 2a 7a 3d 3d 27 5c 6e 27 20 29 20   if( *z=='\n' ) 
5110: 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 7a 2b  return 1;.    z+
5120: 2b 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20  +;.  }.  return 
5130: 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20  0;.}../*.** The 
5140: 70 54 6b 74 20 6f 62 6a 65 63 74 20 69 73 20 61  pTkt object is a
5150: 20 74 69 63 6b 65 74 20 63 68 61 6e 67 65 20 61   ticket change a
5160: 72 74 69 66 61 63 74 2e 20 20 4f 75 74 70 75 74  rtifact.  Output
5170: 20 61 20 64 65 74 61 69 6c 65 64 0a 2a 2a 20 64   a detailed.** d
5180: 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 20 74 68  escription of th
5190: 69 73 20 6f 62 6a 65 63 74 2e 0a 2a 2f 0a 76 6f  is object..*/.vo
51a0: 69 64 20 74 69 63 6b 65 74 5f 6f 75 74 70 75 74  id ticket_output
51b0: 5f 63 68 61 6e 67 65 5f 61 72 74 69 66 61 63 74  _change_artifact
51c0: 28 4d 61 6e 69 66 65 73 74 20 2a 70 54 6b 74 29  (Manifest *pTkt)
51d0: 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 40 20 3c  {.  int i;.  @ <
51e0: 6f 6c 3e 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69  ol>.  for(i=0; i
51f0: 3c 70 54 6b 74 2d 3e 6e 46 69 65 6c 64 3b 20 69  <pTkt->nField; i
5200: 2b 2b 29 7b 0a 20 20 20 20 42 6c 6f 62 20 76 61  ++){.    Blob va
5210: 6c 3b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61  l;.    const cha
5220: 72 20 2a 7a 3b 0a 20 20 20 20 7a 20 3d 20 70 54  r *z;.    z = pT
5230: 6b 74 2d 3e 61 46 69 65 6c 64 5b 69 5d 2e 7a 4e  kt->aField[i].zN
5240: 61 6d 65 3b 0a 20 20 20 20 62 6c 6f 62 5f 73 65  ame;.    blob_se
5250: 74 28 26 76 61 6c 2c 20 70 54 6b 74 2d 3e 61 46  t(&val, pTkt->aF
5260: 69 65 6c 64 5b 69 5d 2e 7a 56 61 6c 75 65 29 3b  ield[i].zValue);
5270: 0a 20 20 20 20 69 66 28 20 7a 5b 30 5d 3d 3d 27  .    if( z[0]=='
5280: 2b 27 20 29 7b 0a 20 20 20 20 20 20 40 20 3c 6c  +' ){.      @ <l
5290: 69 3e 41 70 70 65 6e 64 65 64 20 74 6f 20 25 68  i>Appended to %h
52a0: 28 26 7a 5b 31 5d 29 3a 3c 62 6c 6f 63 6b 71 75  (&z[1]):<blockqu
52b0: 6f 74 65 3e 0a 20 20 20 20 20 20 77 69 6b 69 5f  ote>.      wiki_
52c0: 63 6f 6e 76 65 72 74 28 26 76 61 6c 2c 20 30 2c  convert(&val, 0,
52d0: 20 30 29 3b 0a 20 20 20 20 20 20 40 20 3c 2f 62   0);.      @ </b
52e0: 6c 6f 63 6b 71 75 6f 74 65 3e 3c 2f 6c 69 3e 0a  lockquote></li>.
52f0: 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 62 6c      }else if( bl
5300: 6f 62 5f 73 69 7a 65 28 26 76 61 6c 29 3c 3d 35  ob_size(&val)<=5
5310: 30 20 26 26 20 63 6f 6e 74 61 69 6e 73 5f 6e 65  0 && contains_ne
5320: 77 6c 69 6e 65 28 26 76 61 6c 29 20 29 7b 0a 20  wline(&val) ){. 
5330: 20 20 20 20 20 40 20 3c 6c 69 3e 43 68 61 6e 67       @ <li>Chang
5340: 65 20 25 68 28 7a 29 20 74 6f 3a 3c 62 6c 6f 63  e %h(z) to:<bloc
5350: 6b 71 75 6f 74 65 3e 0a 20 20 20 20 20 20 77 69  kquote>.      wi
5360: 6b 69 5f 63 6f 6e 76 65 72 74 28 26 76 61 6c 2c  ki_convert(&val,
5370: 20 30 2c 20 30 29 3b 0a 20 20 20 20 20 20 40 20   0, 0);.      @ 
5380: 3c 2f 62 6c 6f 63 6b 71 75 6f 74 65 3e 3c 2f 6c  </blockquote></l
5390: 69 3e 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20  i>.    }else{.  
53a0: 20 20 20 20 40 20 3c 6c 69 3e 43 68 61 6e 67 65      @ <li>Change
53b0: 20 25 68 28 7a 29 20 74 6f 20 22 25 68 28 62 6c   %h(z) to "%h(bl
53c0: 6f 62 5f 73 74 72 28 26 76 61 6c 29 29 22 3c 2f  ob_str(&val))"</
53d0: 6c 69 3e 0a 20 20 20 20 7d 0a 20 20 20 20 62 6c  li>.    }.    bl
53e0: 6f 62 5f 72 65 73 65 74 28 26 76 61 6c 29 3b 0a  ob_reset(&val);.
53f0: 20 20 7d 0a 20 20 40 20 3c 2f 6f 6c 3e 0a 7d 0a    }.  @ </ol>.}.