Hex Artifact Content
Not logged in

Artifact bc233f791c238a170adf7bf9c11b3aa7bab16ba0:

File src/tkt.c part of check-in [95f5520a09] - Construct event records for tickets correctly even when the ticket change artifacts arrive out of order. by drh on 2009-09-14 14:08:35.

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 25 73 20 7c 7c 20  sql,", %s=%s || 
1940: 25 51 22 2c 20 7a 4e 61 6d 65 2c 20 7a 4e 61 6d  %Q", zName, zNam
1950: 65 2c 20 70 2d 3e 61 46 69 65 6c 64 5b 69 5d 2e  e, p->aField[i].
1960: 7a 56 61 6c 75 65 29 3b 0a 20 20 20 20 7d 65 6c  zValue);.    }el
1970: 73 65 7b 0a 20 20 20 20 20 20 69 66 28 20 66 69  se{.      if( fi
1980: 65 6c 64 49 64 28 7a 4e 61 6d 65 29 3c 30 20 29  eldId(zName)<0 )
1990: 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20   continue;.     
19a0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73   blob_appendf(&s
19b0: 71 6c 2c 22 2c 20 25 73 3d 25 51 22 2c 20 7a 4e  ql,", %s=%Q", zN
19c0: 61 6d 65 2c 20 70 2d 3e 61 46 69 65 6c 64 5b 69  ame, p->aField[i
19d0: 5d 2e 7a 56 61 6c 75 65 29 3b 0a 20 20 20 20 7d  ].zValue);.    }
19e0: 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 61 70 70 65  .  }.  blob_appe
19f0: 6e 64 66 28 26 73 71 6c 2c 20 22 20 57 48 45 52  ndf(&sql, " WHER
1a00: 45 20 74 6b 74 5f 75 75 69 64 3d 27 25 73 27 20  E tkt_uuid='%s' 
1a10: 41 4e 44 20 74 6b 74 5f 6d 74 69 6d 65 3c 3a 6d  AND tkt_mtime<:m
1a20: 74 69 6d 65 22 2c 0a 20 20 20 20 20 20 20 20 20  time",.         
1a30: 20 20 20 20 20 20 20 20 20 20 20 20 70 2d 3e 7a              p->z
1a40: 54 69 63 6b 65 74 55 75 69 64 29 3b 0a 20 20 64  TicketUuid);.  d
1a50: 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 22 25  b_prepare(&q, "%
1a60: 73 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 73 71  s", blob_str(&sq
1a70: 6c 29 29 3b 0a 20 20 64 62 5f 62 69 6e 64 5f 64  l));.  db_bind_d
1a80: 6f 75 62 6c 65 28 26 71 2c 20 22 3a 6d 74 69 6d  ouble(&q, ":mtim
1a90: 65 22 2c 20 70 2d 3e 72 44 61 74 65 29 3b 0a 20  e", p->rDate);. 
1aa0: 20 64 62 5f 73 74 65 70 28 26 71 29 3b 0a 20 20   db_step(&q);.  
1ab0: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b  db_finalize(&q);
1ac0: 0a 20 20 69 66 28 20 63 68 65 63 6b 54 69 6d 65  .  if( checkTime
1ad0: 20 26 26 20 64 62 5f 63 68 61 6e 67 65 73 28 29   && db_changes()
1ae0: 3d 3d 30 20 29 7b 0a 20 20 20 20 73 74 61 74 69  ==0 ){.    stati
1af0: 63 20 69 6e 74 20 69 73 49 6e 69 74 20 3d 20 30  c int isInit = 0
1b00: 3b 0a 20 20 20 20 69 66 28 20 21 69 73 49 6e 69  ;.    if( !isIni
1b10: 74 20 29 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75  t ){.      db_mu
1b20: 6c 74 69 5f 65 78 65 63 28 22 43 52 45 41 54 45  lti_exec("CREATE
1b30: 20 54 45 4d 50 20 54 41 42 4c 45 20 5f 70 65 6e   TEMP TABLE _pen
1b40: 64 69 6e 67 5f 74 69 63 6b 65 74 28 75 75 69 64  ding_ticket(uuid
1b50: 20 54 45 58 54 20 55 4e 49 51 55 45 29 22 29 3b   TEXT UNIQUE)");
1b60: 0a 20 20 20 20 20 20 64 62 5f 63 6f 6d 6d 69 74  .      db_commit
1b70: 5f 68 6f 6f 6b 28 74 69 63 6b 65 74 5f 72 65 62  _hook(ticket_reb
1b80: 75 69 6c 64 5f 61 74 5f 63 6f 6d 6d 69 74 2c 20  uild_at_commit, 
1b90: 31 29 3b 0a 20 20 20 20 20 20 69 73 49 6e 69 74  1);.      isInit
1ba0: 20 3d 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20   = 1;.    }.    
1bb0: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 49  db_multi_exec("I
1bc0: 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45 20  NSERT OR IGNORE 
1bd0: 49 4e 54 4f 20 5f 70 65 6e 64 69 6e 67 5f 74 69  INTO _pending_ti
1be0: 63 6b 65 74 20 22 0a 20 20 20 20 20 20 20 20 20  cket ".         
1bf0: 20 20 20 20 20 20 20 20 20 22 56 41 4c 55 45 53           "VALUES
1c00: 28 25 51 29 22 2c 20 70 2d 3e 7a 54 69 63 6b 65  (%Q)", p->zTicke
1c10: 74 55 75 69 64 29 3b 0a 20 20 7d 0a 20 20 62 6c  tUuid);.  }.  bl
1c20: 6f 62 5f 72 65 73 65 74 28 26 73 71 6c 29 3b 0a  ob_reset(&sql);.
1c30: 20 20 72 65 74 75 72 6e 20 72 63 3b 0a 7d 0a 0a    return rc;.}..
1c40: 2f 2a 0a 2a 2a 20 52 65 62 75 69 6c 64 20 61 6e  /*.** Rebuild an
1c50: 20 65 6e 74 69 72 65 20 65 6e 74 72 79 20 69 6e   entire entry in
1c60: 20 74 68 65 20 54 49 43 4b 45 54 20 74 61 62 6c   the TICKET tabl
1c70: 65 0a 2a 2f 0a 76 6f 69 64 20 74 69 63 6b 65 74  e.*/.void ticket
1c80: 5f 72 65 62 75 69 6c 64 5f 65 6e 74 72 79 28 63  _rebuild_entry(c
1c90: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 6b 74 55  onst char *zTktU
1ca0: 75 69 64 29 7b 0a 20 20 63 68 61 72 20 2a 7a 54  uid){.  char *zT
1cb0: 61 67 20 3d 20 6d 70 72 69 6e 74 66 28 22 74 6b  ag = mprintf("tk
1cc0: 74 2d 25 73 22 2c 20 7a 54 6b 74 55 75 69 64 29  t-%s", zTktUuid)
1cd0: 3b 0a 20 20 69 6e 74 20 74 61 67 69 64 20 3d 20  ;.  int tagid = 
1ce0: 74 61 67 5f 66 69 6e 64 69 64 28 7a 54 61 67 2c  tag_findid(zTag,
1cf0: 20 31 29 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 20   1);.  Stmt q;. 
1d00: 20 4d 61 6e 69 66 65 73 74 20 6d 61 6e 69 66 65   Manifest manife
1d10: 73 74 3b 0a 20 20 42 6c 6f 62 20 63 6f 6e 74 65  st;.  Blob conte
1d20: 6e 74 3b 0a 20 20 69 6e 74 20 63 72 65 61 74 65  nt;.  int create
1d30: 46 6c 61 67 20 3d 20 31 3b 0a 20 20 0a 20 20 64  Flag = 1;.  .  d
1d40: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20  b_multi_exec(.  
1d50: 20 20 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20     "DELETE FROM 
1d60: 74 69 63 6b 65 74 20 57 48 45 52 45 20 74 6b 74  ticket WHERE tkt
1d70: 5f 75 75 69 64 3d 25 51 22 2c 20 7a 54 6b 74 55  _uuid=%Q", zTktU
1d80: 75 69 64 0a 20 20 29 3b 0a 20 20 64 62 5f 70 72  uid.  );.  db_pr
1d90: 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43  epare(&q, "SELEC
1da0: 54 20 72 69 64 20 46 52 4f 4d 20 74 61 67 78 72  T rid FROM tagxr
1db0: 65 66 20 57 48 45 52 45 20 74 61 67 69 64 3d 25  ef WHERE tagid=%
1dc0: 64 20 4f 52 44 45 52 20 42 59 20 6d 74 69 6d 65  d ORDER BY mtime
1dd0: 22 2c 74 61 67 69 64 29 3b 0a 20 20 77 68 69 6c  ",tagid);.  whil
1de0: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d  e( db_step(&q)==
1df0: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20  SQLITE_ROW ){.  
1e00: 20 20 69 6e 74 20 72 69 64 20 3d 20 64 62 5f 63    int rid = db_c
1e10: 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29  olumn_int(&q, 0)
1e20: 3b 0a 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65  ;.    content_ge
1e30: 74 28 72 69 64 2c 20 26 63 6f 6e 74 65 6e 74 29  t(rid, &content)
1e40: 3b 0a 20 20 20 20 6d 61 6e 69 66 65 73 74 5f 70  ;.    manifest_p
1e50: 61 72 73 65 28 26 6d 61 6e 69 66 65 73 74 2c 20  arse(&manifest, 
1e60: 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20 74  &content);.    t
1e70: 69 63 6b 65 74 5f 69 6e 73 65 72 74 28 26 6d 61  icket_insert(&ma
1e80: 6e 69 66 65 73 74 2c 20 63 72 65 61 74 65 46 6c  nifest, createFl
1e90: 61 67 2c 20 30 29 3b 0a 20 20 20 20 6d 61 6e 69  ag, 0);.    mani
1ea0: 66 65 73 74 5f 74 69 63 6b 65 74 5f 65 76 65 6e  fest_ticket_even
1eb0: 74 28 72 69 64 2c 20 26 6d 61 6e 69 66 65 73 74  t(rid, &manifest
1ec0: 2c 20 63 72 65 61 74 65 46 6c 61 67 29 3b 0a 20  , createFlag);. 
1ed0: 20 20 20 6d 61 6e 69 66 65 73 74 5f 63 6c 65 61     manifest_clea
1ee0: 72 28 26 6d 61 6e 69 66 65 73 74 29 3b 0a 20 20  r(&manifest);.  
1ef0: 20 20 63 72 65 61 74 65 46 6c 61 67 20 3d 20 30    createFlag = 0
1f00: 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c  ;.  }.  db_final
1f10: 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  ize(&q);.}../*.*
1f20: 2a 20 43 72 65 61 74 65 20 74 68 65 20 73 75 62  * Create the sub
1f30: 73 63 72 69 70 74 20 69 6e 74 65 72 70 72 65 74  script interpret
1f40: 65 72 20 61 6e 64 20 6c 6f 61 64 20 74 68 65 20  er and load the 
1f50: 22 63 6f 6d 6d 6f 6e 22 20 63 6f 64 65 2e 0a 2a  "common" code..*
1f60: 2f 0a 76 6f 69 64 20 74 69 63 6b 65 74 5f 69 6e  /.void ticket_in
1f70: 69 74 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73  it(void){.  cons
1f80: 74 20 63 68 61 72 20 2a 7a 43 6f 6e 66 69 67 3b  t char *zConfig;
1f90: 0a 20 20 54 68 5f 46 6f 73 73 69 6c 49 6e 69 74  .  Th_FossilInit
1fa0: 28 29 3b 0a 20 20 7a 43 6f 6e 66 69 67 20 3d 20  ();.  zConfig = 
1fb0: 74 69 63 6b 65 74 5f 63 6f 6d 6d 6f 6e 5f 63 6f  ticket_common_co
1fc0: 64 65 28 29 3b 0a 20 20 54 68 5f 45 76 61 6c 28  de();.  Th_Eval(
1fd0: 67 2e 69 6e 74 65 72 70 2c 20 30 2c 20 7a 43 6f  g.interp, 0, zCo
1fe0: 6e 66 69 67 2c 20 2d 31 29 3b 0a 7d 0a 0a 2f 2a  nfig, -1);.}../*
1ff0: 0a 2a 2a 20 52 65 63 72 65 61 74 65 20 74 68 65  .** Recreate the
2000: 20 74 69 63 6b 65 74 20 74 61 62 6c 65 2e 0a 2a   ticket table..*
2010: 2f 0a 76 6f 69 64 20 74 69 63 6b 65 74 5f 63 72  /.void ticket_cr
2020: 65 61 74 65 5f 74 61 62 6c 65 28 69 6e 74 20 73  eate_table(int s
2030: 65 70 61 72 61 74 65 43 6f 6e 6e 65 63 74 69 6f  eparateConnectio
2040: 6e 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72  n){.  const char
2050: 20 2a 7a 53 71 6c 3b 0a 0a 20 20 64 62 5f 6d 75   *zSql;..  db_mu
2060: 6c 74 69 5f 65 78 65 63 28 22 44 52 4f 50 20 54  lti_exec("DROP T
2070: 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 74  ABLE IF EXISTS t
2080: 69 63 6b 65 74 3b 22 29 3b 0a 20 20 7a 53 71 6c  icket;");.  zSql
2090: 20 3d 20 74 69 63 6b 65 74 5f 74 61 62 6c 65 5f   = ticket_table_
20a0: 73 63 68 65 6d 61 28 29 3b 0a 20 20 69 66 28 20  schema();.  if( 
20b0: 73 65 70 61 72 61 74 65 43 6f 6e 6e 65 63 74 69  separateConnecti
20c0: 6f 6e 20 29 7b 0a 20 20 20 20 64 62 5f 69 6e 69  on ){.    db_ini
20d0: 74 5f 64 61 74 61 62 61 73 65 28 67 2e 7a 52 65  t_database(g.zRe
20e0: 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c 20 7a 53  positoryName, zS
20f0: 71 6c 2c 20 30 29 3b 0a 20 20 7d 65 6c 73 65 7b  ql, 0);.  }else{
2100: 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78  .    db_multi_ex
2110: 65 63 28 22 25 73 22 2c 20 7a 53 71 6c 29 3b 0a  ec("%s", zSql);.
2120: 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 70    }.}../*.** Rep
2130: 6f 70 75 6c 61 74 65 20 74 68 65 20 74 69 63 6b  opulate the tick
2140: 65 74 20 74 61 62 6c 65 0a 2a 2f 0a 76 6f 69 64  et table.*/.void
2150: 20 74 69 63 6b 65 74 5f 72 65 62 75 69 6c 64 28   ticket_rebuild(
2160: 76 6f 69 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b  void){.  Stmt q;
2170: 0a 20 20 74 69 63 6b 65 74 5f 63 72 65 61 74 65  .  ticket_create
2180: 5f 74 61 62 6c 65 28 31 29 3b 0a 20 20 64 62 5f  _table(1);.  db_
2190: 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f  begin_transactio
21a0: 6e 28 29 3b 0a 20 20 64 62 5f 70 72 65 70 61 72  n();.  db_prepar
21b0: 65 28 26 71 2c 22 53 45 4c 45 43 54 20 74 61 67  e(&q,"SELECT tag
21c0: 6e 61 6d 65 20 46 52 4f 4d 20 74 61 67 20 57 48  name FROM tag WH
21d0: 45 52 45 20 74 61 67 6e 61 6d 65 20 47 4c 4f 42  ERE tagname GLOB
21e0: 20 27 74 6b 74 2d 2a 27 22 29 3b 0a 20 20 77 68   'tkt-*'");.  wh
21f0: 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29  ile( db_step(&q)
2200: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a  ==SQLITE_ROW ){.
2210: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a      const char *
2220: 7a 4e 61 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 6d  zName = db_colum
2230: 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 3b 0a 20  n_text(&q, 0);. 
2240: 20 20 20 69 6e 74 20 6c 65 6e 3b 0a 20 20 20 20     int len;.    
2250: 7a 4e 61 6d 65 20 2b 3d 20 34 3b 0a 20 20 20 20  zName += 4;.    
2260: 6c 65 6e 20 3d 20 73 74 72 6c 65 6e 28 7a 4e 61  len = strlen(zNa
2270: 6d 65 29 3b 0a 20 20 20 20 69 66 28 20 6c 65 6e  me);.    if( len
2280: 3c 32 30 20 7c 7c 20 21 76 61 6c 69 64 61 74 65  <20 || !validate
2290: 31 36 28 7a 4e 61 6d 65 2c 20 6c 65 6e 29 20 29  16(zName, len) )
22a0: 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 74   continue;.    t
22b0: 69 63 6b 65 74 5f 72 65 62 75 69 6c 64 5f 65 6e  icket_rebuild_en
22c0: 74 72 79 28 7a 4e 61 6d 65 29 3b 0a 20 20 7d 0a  try(zName);.  }.
22d0: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71    db_finalize(&q
22e0: 29 3b 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e  );.  db_end_tran
22f0: 73 61 63 74 69 6f 6e 28 30 29 3b 0a 7d 0a 0a 2f  saction(0);.}../
2300: 2a 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 74 6b  *.** WEBPAGE: tk
2310: 74 76 69 65 77 0a 2a 2a 20 55 52 4c 3a 20 20 74  tview.** URL:  t
2320: 6b 74 76 69 65 77 3f 6e 61 6d 65 3d 55 55 49 44  ktview?name=UUID
2330: 0a 2a 2a 0a 2a 2a 20 56 69 65 77 20 61 20 74 69  .**.** View a ti
2340: 63 6b 65 74 2e 0a 2a 2f 0a 76 6f 69 64 20 74 6b  cket..*/.void tk
2350: 74 76 69 65 77 5f 70 61 67 65 28 76 6f 69 64 29  tview_page(void)
2360: 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  {.  const char *
2370: 7a 53 63 72 69 70 74 3b 0a 20 20 6c 6f 67 69 6e  zScript;.  login
2380: 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69 61  _check_credentia
2390: 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67 2e 6f  ls();.  if( !g.o
23a0: 6b 52 64 54 6b 74 20 29 7b 20 6c 6f 67 69 6e 5f  kRdTkt ){ login_
23b0: 6e 65 65 64 65 64 28 29 3b 20 72 65 74 75 72 6e  needed(); return
23c0: 3b 20 7d 0a 20 20 69 66 28 20 67 2e 6f 6b 57 72  ; }.  if( g.okWr
23d0: 54 6b 74 20 7c 7c 20 67 2e 6f 6b 41 70 6e 64 54  Tkt || g.okApndT
23e0: 6b 74 20 29 7b 0a 20 20 20 20 73 74 79 6c 65 5f  kt ){.    style_
23f0: 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28  submenu_element(
2400: 22 45 64 69 74 22 2c 20 22 45 64 69 74 20 54 68  "Edit", "Edit Th
2410: 65 20 54 69 63 6b 65 74 22 2c 20 22 25 73 2f 74  e Ticket", "%s/t
2420: 6b 74 65 64 69 74 3f 6e 61 6d 65 3d 25 54 22 2c  ktedit?name=%T",
2430: 0a 20 20 20 20 20 20 20 20 67 2e 7a 54 6f 70 2c  .        g.zTop,
2440: 20 50 44 28 22 6e 61 6d 65 22 2c 22 22 29 29 3b   PD("name",""));
2450: 0a 20 20 7d 0a 20 20 69 66 28 20 67 2e 6f 6b 48  .  }.  if( g.okH
2460: 69 73 74 6f 72 79 20 29 7b 0a 20 20 20 20 63 6f  istory ){.    co
2470: 6e 73 74 20 63 68 61 72 20 2a 7a 55 75 69 64 20  nst char *zUuid 
2480: 3d 20 50 44 28 22 6e 61 6d 65 22 2c 22 22 29 3b  = PD("name","");
2490: 0a 20 20 20 20 73 74 79 6c 65 5f 73 75 62 6d 65  .    style_subme
24a0: 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 48 69 73 74  nu_element("Hist
24b0: 6f 72 79 22 2c 20 22 48 69 73 74 6f 72 79 20 4f  ory", "History O
24c0: 66 20 54 68 69 73 20 54 69 63 6b 65 74 22 2c 20  f This Ticket", 
24d0: 0a 20 20 20 20 20 20 20 20 22 25 73 2f 74 6b 74  .        "%s/tkt
24e0: 68 69 73 74 6f 72 79 2f 25 54 22 2c 20 67 2e 7a  history/%T", g.z
24f0: 54 6f 70 2c 20 7a 55 75 69 64 29 3b 0a 20 20 20  Top, zUuid);.   
2500: 20 73 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65   style_submenu_e
2510: 6c 65 6d 65 6e 74 28 22 54 69 6d 65 6c 69 6e 65  lement("Timeline
2520: 22 2c 20 22 54 69 6d 65 6c 69 6e 65 20 4f 66 20  ", "Timeline Of 
2530: 54 68 69 73 20 54 69 63 6b 65 74 22 2c 20 0a 20  This Ticket", . 
2540: 20 20 20 20 20 20 20 22 25 73 2f 74 6b 74 74 69         "%s/tktti
2550: 6d 65 6c 69 6e 65 2f 25 54 22 2c 20 67 2e 7a 54  meline/%T", g.zT
2560: 6f 70 2c 20 7a 55 75 69 64 29 3b 0a 20 20 7d 0a  op, zUuid);.  }.
2570: 20 20 73 74 79 6c 65 5f 68 65 61 64 65 72 28 22    style_header("
2580: 56 69 65 77 20 54 69 63 6b 65 74 22 29 3b 0a 20  View Ticket");. 
2590: 20 69 66 28 20 67 2e 74 68 54 72 61 63 65 20 29   if( g.thTrace )
25a0: 20 54 68 5f 54 72 61 63 65 28 22 42 45 47 49 4e   Th_Trace("BEGIN
25b0: 5f 54 4b 54 56 49 45 57 3c 62 72 20 2f 3e 5c 6e  _TKTVIEW<br />\n
25c0: 22 2c 20 2d 31 29 3b 0a 20 20 74 69 63 6b 65 74  ", -1);.  ticket
25d0: 5f 69 6e 69 74 28 29 3b 0a 20 20 69 6e 69 74 69  _init();.  initi
25e0: 61 6c 69 7a 65 56 61 72 69 61 62 6c 65 73 46 72  alizeVariablesFr
25f0: 6f 6d 44 62 28 29 3b 0a 20 20 7a 53 63 72 69 70  omDb();.  zScrip
2600: 74 20 3d 20 74 69 63 6b 65 74 5f 76 69 65 77 70  t = ticket_viewp
2610: 61 67 65 5f 63 6f 64 65 28 29 3b 0a 20 20 69 66  age_code();.  if
2620: 28 20 67 2e 74 68 54 72 61 63 65 20 29 20 54 68  ( g.thTrace ) Th
2630: 5f 54 72 61 63 65 28 22 42 45 47 49 4e 5f 54 4b  _Trace("BEGIN_TK
2640: 54 56 49 45 57 5f 53 43 52 49 50 54 3c 62 72 20  TVIEW_SCRIPT<br 
2650: 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a 20 20 54 68  />\n", -1);.  Th
2660: 5f 52 65 6e 64 65 72 28 7a 53 63 72 69 70 74 29  _Render(zScript)
2670: 3b 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61 63  ;.  if( g.thTrac
2680: 65 20 29 20 54 68 5f 54 72 61 63 65 28 22 45 4e  e ) Th_Trace("EN
2690: 44 5f 54 4b 54 56 49 45 57 3c 62 72 20 2f 3e 5c  D_TKTVIEW<br />\
26a0: 6e 22 2c 20 2d 31 29 3b 0a 20 20 73 74 79 6c 65  n", -1);.  style
26b0: 5f 66 6f 6f 74 65 72 28 29 3b 0a 7d 0a 0a 2f 2a  _footer();.}../*
26c0: 0a 2a 2a 20 54 48 20 63 6f 6d 6d 61 6e 64 3a 20  .** TH command: 
26d0: 20 20 61 70 70 65 6e 64 5f 66 69 65 6c 64 20 46    append_field F
26e0: 49 45 4c 44 20 53 54 52 49 4e 47 0a 2a 2a 0a 2a  IELD STRING.**.*
26f0: 2a 20 46 49 45 4c 44 20 69 73 20 74 68 65 20 6e  * FIELD is the n
2700: 61 6d 65 20 6f 66 20 61 20 64 61 74 61 62 61 73  ame of a databas
2710: 65 20 63 6f 6c 75 6d 6e 20 74 6f 20 77 68 69 63  e column to whic
2720: 68 20 77 65 20 6d 69 67 68 74 20 77 61 6e 74 0a  h we might want.
2730: 2a 2a 20 74 6f 20 61 70 70 65 6e 64 20 74 65 78  ** to append tex
2740: 74 2e 20 20 53 54 52 49 4e 47 20 69 73 20 74 68  t.  STRING is th
2750: 65 20 74 65 78 74 20 74 6f 20 62 65 20 61 70 70  e text to be app
2760: 65 6e 64 65 64 20 74 6f 20 74 68 61 74 0a 2a 2a  ended to that.**
2770: 20 63 6f 6c 75 6d 6e 2e 20 20 54 68 65 20 61 70   column.  The ap
2780: 70 65 6e 64 20 64 6f 65 73 20 6e 6f 74 20 61 63  pend does not ac
2790: 74 75 61 6c 6c 79 20 6f 63 63 75 72 20 75 6e 74  tually occur unt
27a0: 69 6c 20 74 68 65 0a 2a 2a 20 73 75 62 6d 69 74  il the.** submit
27b0: 5f 74 69 63 6b 65 74 20 63 6f 6d 6d 61 6e 64 20  _ticket command 
27c0: 69 73 20 72 75 6e 2e 0a 2a 2f 0a 73 74 61 74 69  is run..*/.stati
27d0: 63 20 69 6e 74 20 61 70 70 65 6e 64 52 65 6d 61  c int appendRema
27e0: 72 6b 43 6d 64 28 0a 20 20 54 68 5f 49 6e 74 65  rkCmd(.  Th_Inte
27f0: 72 70 20 2a 69 6e 74 65 72 70 2c 20 0a 20 20 76  rp *interp, .  v
2800: 6f 69 64 20 2a 70 2c 20 0a 20 20 69 6e 74 20 61  oid *p, .  int a
2810: 72 67 63 2c 20 0a 20 20 63 6f 6e 73 74 20 63 68  rgc, .  const ch
2820: 61 72 20 2a 2a 61 72 67 76 2c 20 0a 20 20 69 6e  ar **argv, .  in
2830: 74 20 2a 61 72 67 6c 0a 29 7b 0a 20 20 69 6e 74  t *argl.){.  int
2840: 20 69 64 78 3b 0a 0a 20 20 69 66 28 20 61 72 67   idx;..  if( arg
2850: 63 21 3d 33 20 29 7b 0a 20 20 20 20 72 65 74 75  c!=3 ){.    retu
2860: 72 6e 20 54 68 5f 57 72 6f 6e 67 4e 75 6d 41 72  rn Th_WrongNumAr
2870: 67 73 28 69 6e 74 65 72 70 2c 20 22 61 70 70 65  gs(interp, "appe
2880: 6e 64 5f 66 69 65 6c 64 20 46 49 45 4c 44 20 53  nd_field FIELD S
2890: 54 52 49 4e 47 22 29 3b 0a 20 20 7d 0a 20 20 69  TRING");.  }.  i
28a0: 66 28 20 67 2e 74 68 54 72 61 63 65 20 29 7b 0a  f( g.thTrace ){.
28b0: 20 20 20 20 54 68 5f 54 72 61 63 65 28 22 61 70      Th_Trace("ap
28c0: 70 65 6e 64 5f 66 69 65 6c 64 20 25 23 68 20 7b  pend_field %#h {
28d0: 25 23 68 7d 3c 62 72 20 2f 3e 5c 6e 22 2c 0a 20  %#h}<br />\n",. 
28e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 61 72 67               arg
28f0: 6c 5b 31 5d 2c 20 61 72 67 76 5b 31 5d 2c 20 61  l[1], argv[1], a
2900: 72 67 6c 5b 32 5d 2c 20 61 72 67 76 5b 32 5d 29  rgl[2], argv[2])
2910: 3b 0a 20 20 7d 0a 20 20 66 6f 72 28 69 64 78 3d  ;.  }.  for(idx=
2920: 30 3b 20 69 64 78 3c 6e 46 69 65 6c 64 3b 20 69  0; idx<nField; i
2930: 64 78 2b 2b 29 7b 0a 20 20 20 20 69 66 28 20 73  dx++){.    if( s
2940: 74 72 6e 63 6d 70 28 61 7a 46 69 65 6c 64 5b 69  trncmp(azField[i
2950: 64 78 5d 2c 20 61 72 67 76 5b 31 5d 2c 20 61 72  dx], argv[1], ar
2960: 67 6c 5b 31 5d 29 3d 3d 30 0a 20 20 20 20 20 20  gl[1])==0.      
2970: 20 20 26 26 20 61 7a 46 69 65 6c 64 5b 69 64 78    && azField[idx
2980: 5d 5b 61 72 67 6c 5b 31 5d 5d 3d 3d 30 20 29 7b  ][argl[1]]==0 ){
2990: 0a 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20  .      break;.  
29a0: 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20 69 64    }.  }.  if( id
29b0: 78 3e 3d 6e 46 69 65 6c 64 20 29 7b 0a 20 20 20  x>=nField ){.   
29c0: 20 54 68 5f 45 72 72 6f 72 4d 65 73 73 61 67 65   Th_ErrorMessage
29d0: 28 67 2e 69 6e 74 65 72 70 2c 20 22 6e 6f 20 73  (g.interp, "no s
29e0: 75 63 68 20 54 49 43 4b 45 54 20 63 6f 6c 75 6d  uch TICKET colum
29f0: 6e 3a 20 22 2c 20 61 72 67 76 5b 31 5d 2c 20 61  n: ", argv[1], a
2a00: 72 67 6c 5b 31 5d 29 3b 0a 20 20 20 20 72 65 74  rgl[1]);.    ret
2a10: 75 72 6e 20 54 48 5f 45 52 52 4f 52 3b 0a 20 20  urn TH_ERROR;.  
2a20: 7d 0a 20 20 61 7a 41 70 70 65 6e 64 5b 69 64 78  }.  azAppend[idx
2a30: 5d 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 2e 2a  ] = mprintf("%.*
2a40: 73 22 2c 20 61 72 67 6c 5b 32 5d 2c 20 61 72 67  s", argl[2], arg
2a50: 76 5b 32 5d 29 3b 0a 20 20 72 65 74 75 72 6e 20  v[2]);.  return 
2a60: 54 48 5f 4f 4b 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  TH_OK;.}../*.** 
2a70: 53 75 62 73 63 72 69 70 74 20 63 6f 6d 6d 61 6e  Subscript comman
2a80: 64 3a 20 20 20 73 75 62 6d 69 74 5f 74 69 63 6b  d:   submit_tick
2a90: 65 74 0a 2a 2a 0a 2a 2a 20 43 6f 6e 73 74 72 75  et.**.** Constru
2aa0: 63 74 20 61 6e 64 20 73 75 62 6d 69 74 20 61 20  ct and submit a 
2ab0: 6e 65 77 20 74 69 63 6b 65 74 20 61 72 74 69 66  new ticket artif
2ac0: 61 63 74 2e 20 20 54 68 65 20 66 69 65 6c 64 73  act.  The fields
2ad0: 20 6f 66 20 74 68 65 20 61 72 74 69 66 61 63 74   of the artifact
2ae0: 0a 2a 2a 20 61 72 65 20 74 68 65 20 6e 61 6d 65  .** are the name
2af0: 73 20 6f 66 20 74 68 65 20 63 6f 6c 75 6d 6e 73  s of the columns
2b00: 20 69 6e 20 74 68 65 20 54 49 43 4b 45 54 20 74   in the TICKET t
2b10: 61 62 6c 65 2e 20 20 54 68 65 20 63 6f 6e 74 65  able.  The conte
2b20: 6e 74 20 69 73 0a 2a 2a 20 74 61 6b 65 6e 20 66  nt is.** taken f
2b30: 72 6f 6d 20 54 48 20 76 61 72 69 61 62 6c 65 73  rom TH variables
2b40: 2e 20 20 49 66 20 74 68 65 20 63 6f 6e 74 65 6e  .  If the conten
2b50: 74 20 69 73 20 75 6e 63 68 61 6e 67 65 64 2c 20  t is unchanged, 
2b60: 74 68 65 20 66 69 65 6c 64 20 69 73 0a 2a 2a 20  the field is.** 
2b70: 6f 6d 69 74 74 65 64 20 66 72 6f 6d 20 74 68 65  omitted from the
2b80: 20 61 72 74 69 66 61 63 74 2e 20 20 46 69 65 6c   artifact.  Fiel
2b90: 64 73 20 77 68 6f 73 65 20 6e 61 6d 65 73 20 62  ds whose names b
2ba0: 65 67 69 6e 20 77 69 74 68 20 22 70 72 69 76 61  egin with "priva
2bb0: 74 65 5f 22 0a 2a 2a 20 61 72 65 20 63 6f 6e 63  te_".** are conc
2bc0: 65 61 6c 65 64 20 75 73 69 6e 67 20 74 68 65 20  ealed using the 
2bd0: 64 62 5f 63 6f 6e 63 65 61 6c 28 29 20 66 75 6e  db_conceal() fun
2be0: 63 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 61 74 69 63  ction..*/.static
2bf0: 20 69 6e 74 20 73 75 62 6d 69 74 54 69 63 6b 65   int submitTicke
2c00: 74 43 6d 64 28 0a 20 20 54 68 5f 49 6e 74 65 72  tCmd(.  Th_Inter
2c10: 70 20 2a 69 6e 74 65 72 70 2c 20 0a 20 20 76 6f  p *interp, .  vo
2c20: 69 64 20 2a 70 55 75 69 64 2c 20 0a 20 20 69 6e  id *pUuid, .  in
2c30: 74 20 61 72 67 63 2c 20 0a 20 20 63 6f 6e 73 74  t argc, .  const
2c40: 20 63 68 61 72 20 2a 2a 61 72 67 76 2c 20 0a 20   char **argv, . 
2c50: 20 69 6e 74 20 2a 61 72 67 6c 0a 29 7b 0a 20 20   int *argl.){.  
2c60: 63 68 61 72 20 2a 7a 44 61 74 65 3b 0a 20 20 63  char *zDate;.  c
2c70: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 55 75 69 64  onst char *zUuid
2c80: 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 69 6e 74  ;.  int i;.  int
2c90: 20 72 69 64 3b 0a 20 20 42 6c 6f 62 20 74 6b 74   rid;.  Blob tkt
2ca0: 63 68 6e 67 2c 20 63 6b 73 75 6d 3b 0a 0a 20 20  chng, cksum;..  
2cb0: 6c 6f 67 69 6e 5f 76 65 72 69 66 79 5f 63 73 72  login_verify_csr
2cc0: 66 5f 73 65 63 72 65 74 28 29 3b 0a 20 20 7a 55  f_secret();.  zU
2cd0: 75 69 64 20 3d 20 28 63 6f 6e 73 74 20 63 68 61  uid = (const cha
2ce0: 72 20 2a 29 70 55 75 69 64 3b 0a 20 20 62 6c 6f  r *)pUuid;.  blo
2cf0: 62 5f 7a 65 72 6f 28 26 74 6b 74 63 68 6e 67 29  b_zero(&tktchng)
2d00: 3b 0a 20 20 7a 44 61 74 65 20 3d 20 64 62 5f 74  ;.  zDate = db_t
2d10: 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 64  ext(0, "SELECT d
2d20: 61 74 65 74 69 6d 65 28 27 6e 6f 77 27 29 22 29  atetime('now')")
2d30: 3b 0a 20 20 7a 44 61 74 65 5b 31 30 5d 20 3d 20  ;.  zDate[10] = 
2d40: 27 54 27 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65  'T';.  blob_appe
2d50: 6e 64 66 28 26 74 6b 74 63 68 6e 67 2c 20 22 44  ndf(&tktchng, "D
2d60: 20 25 73 5c 6e 22 2c 20 7a 44 61 74 65 29 3b 0a   %s\n", zDate);.
2d70: 20 20 66 72 65 65 28 7a 44 61 74 65 29 3b 0a 20    free(zDate);. 
2d80: 20 66 6f 72 28 69 3d 30 3b 20 69 3c 6e 46 69 65   for(i=0; i<nFie
2d90: 6c 64 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 63 6f  ld; i++){.    co
2da0: 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65  nst char *zValue
2db0: 3b 0a 20 20 20 20 69 6e 74 20 6e 56 61 6c 75 65  ;.    int nValue
2dc0: 3b 0a 20 20 20 20 69 66 28 20 61 7a 41 70 70 65  ;.    if( azAppe
2dd0: 6e 64 5b 69 5d 20 29 7b 0a 20 20 20 20 20 20 62  nd[i] ){.      b
2de0: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 74 6b 74  lob_appendf(&tkt
2df0: 63 68 6e 67 2c 20 22 4a 20 2b 25 73 20 25 7a 5c  chng, "J +%s %z\
2e00: 6e 22 2c 20 61 7a 46 69 65 6c 64 5b 69 5d 2c 0a  n", azField[i],.
2e10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2e20: 20 20 20 66 6f 73 73 69 6c 69 7a 65 28 61 7a 41     fossilize(azA
2e30: 70 70 65 6e 64 5b 69 5d 2c 20 2d 31 29 29 3b 0a  ppend[i], -1));.
2e40: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20      }else{.     
2e50: 20 7a 56 61 6c 75 65 20 3d 20 54 68 5f 46 65 74   zValue = Th_Fet
2e60: 63 68 28 61 7a 46 69 65 6c 64 5b 69 5d 2c 20 26  ch(azField[i], &
2e70: 6e 56 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 69  nValue);.      i
2e80: 66 28 20 7a 56 61 6c 75 65 20 29 7b 0a 20 20 20  f( zValue ){.   
2e90: 20 20 20 20 20 77 68 69 6c 65 28 20 6e 56 61 6c       while( nVal
2ea0: 75 65 3e 30 20 26 26 20 69 73 73 70 61 63 65 28  ue>0 && isspace(
2eb0: 7a 56 61 6c 75 65 5b 6e 56 61 6c 75 65 2d 31 5d  zValue[nValue-1]
2ec0: 29 20 29 7b 20 6e 56 61 6c 75 65 2d 2d 3b 20 7d  ) ){ nValue--; }
2ed0: 0a 20 20 20 20 20 20 20 20 69 66 28 20 73 74 72  .        if( str
2ee0: 6e 63 6d 70 28 7a 56 61 6c 75 65 2c 20 61 7a 56  ncmp(zValue, azV
2ef0: 61 6c 75 65 5b 69 5d 2c 20 6e 56 61 6c 75 65 29  alue[i], nValue)
2f00: 20 7c 7c 20 73 74 72 6c 65 6e 28 61 7a 56 61 6c   || strlen(azVal
2f10: 75 65 5b 69 5d 29 21 3d 6e 56 61 6c 75 65 20 29  ue[i])!=nValue )
2f20: 7b 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 20  {.          if( 
2f30: 73 74 72 6e 63 6d 70 28 61 7a 46 69 65 6c 64 5b  strncmp(azField[
2f40: 69 5d 2c 20 22 70 72 69 76 61 74 65 5f 22 2c 20  i], "private_", 
2f50: 38 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 20  8)==0 ){.       
2f60: 20 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 64 62       zValue = db
2f70: 5f 63 6f 6e 63 65 61 6c 28 7a 56 61 6c 75 65 2c  _conceal(zValue,
2f80: 20 6e 56 61 6c 75 65 29 3b 0a 20 20 20 20 20 20   nValue);.      
2f90: 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e        blob_appen
2fa0: 64 66 28 26 74 6b 74 63 68 6e 67 2c 20 22 4a 20  df(&tktchng, "J 
2fb0: 25 73 20 25 73 5c 6e 22 2c 20 61 7a 46 69 65 6c  %s %s\n", azFiel
2fc0: 64 5b 69 5d 2c 20 7a 56 61 6c 75 65 29 3b 0a 20  d[i], zValue);. 
2fd0: 20 20 20 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a           }else{.
2fe0: 20 20 20 20 20 20 20 20 20 20 20 20 62 6c 6f 62              blob
2ff0: 5f 61 70 70 65 6e 64 66 28 26 74 6b 74 63 68 6e  _appendf(&tktchn
3000: 67 2c 20 22 4a 20 25 73 20 25 23 46 5c 6e 22 2c  g, "J %s %#F\n",
3010: 20 61 7a 46 69 65 6c 64 5b 69 5d 2c 20 6e 56 61   azField[i], nVa
3020: 6c 75 65 2c 20 7a 56 61 6c 75 65 29 3b 0a 20 20  lue, zValue);.  
3030: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20          }.      
3040: 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 20 20    }.      }.    
3050: 7d 0a 20 20 7d 0a 20 20 69 66 28 20 2a 28 63 68  }.  }.  if( *(ch
3060: 61 72 2a 2a 29 70 55 75 69 64 20 29 7b 0a 20 20  ar**)pUuid ){.  
3070: 20 20 7a 55 75 69 64 20 3d 20 64 62 5f 74 65 78    zUuid = db_tex
3080: 74 28 30 2c 20 0a 20 20 20 20 20 20 20 22 53 45  t(0, .       "SE
3090: 4c 45 43 54 20 74 6b 74 5f 75 75 69 64 20 46 52  LECT tkt_uuid FR
30a0: 4f 4d 20 74 69 63 6b 65 74 20 57 48 45 52 45 20  OM ticket WHERE 
30b0: 74 6b 74 5f 75 75 69 64 20 47 4c 4f 42 20 27 25  tkt_uuid GLOB '%
30c0: 73 2a 27 22 2c 20 50 28 22 6e 61 6d 65 22 29 0a  s*'", P("name").
30d0: 20 20 20 20 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a      );.  }else{.
30e0: 20 20 20 20 7a 55 75 69 64 20 3d 20 64 62 5f 74      zUuid = db_t
30f0: 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 6c  ext(0, "SELECT l
3100: 6f 77 65 72 28 68 65 78 28 72 61 6e 64 6f 6d 62  ower(hex(randomb
3110: 6c 6f 62 28 32 30 29 29 29 22 29 3b 0a 20 20 7d  lob(20)))");.  }
3120: 0a 20 20 2a 28 63 6f 6e 73 74 20 63 68 61 72 2a  .  *(const char*
3130: 2a 29 70 55 75 69 64 20 3d 20 7a 55 75 69 64 3b  *)pUuid = zUuid;
3140: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28  .  blob_appendf(
3150: 26 74 6b 74 63 68 6e 67 2c 20 22 4b 20 25 73 5c  &tktchng, "K %s\
3160: 6e 22 2c 20 7a 55 75 69 64 29 3b 0a 20 20 62 6c  n", zUuid);.  bl
3170: 6f 62 5f 61 70 70 65 6e 64 66 28 26 74 6b 74 63  ob_appendf(&tktc
3180: 68 6e 67 2c 20 22 55 20 25 46 5c 6e 22 2c 20 67  hng, "U %F\n", g
3190: 2e 7a 4c 6f 67 69 6e 20 3f 20 67 2e 7a 4c 6f 67  .zLogin ? g.zLog
31a0: 69 6e 20 3a 20 22 22 29 3b 0a 20 20 6d 64 35 73  in : "");.  md5s
31b0: 75 6d 5f 62 6c 6f 62 28 26 74 6b 74 63 68 6e 67  um_blob(&tktchng
31c0: 2c 20 26 63 6b 73 75 6d 29 3b 0a 20 20 62 6c 6f  , &cksum);.  blo
31d0: 62 5f 61 70 70 65 6e 64 66 28 26 74 6b 74 63 68  b_appendf(&tktch
31e0: 6e 67 2c 20 22 5a 20 25 62 5c 6e 22 2c 20 26 63  ng, "Z %b\n", &c
31f0: 6b 73 75 6d 29 3b 0a 20 20 69 66 28 20 67 2e 74  ksum);.  if( g.t
3200: 68 54 72 61 63 65 20 29 7b 0a 20 20 20 20 54 68  hTrace ){.    Th
3210: 5f 54 72 61 63 65 28 22 73 75 62 6d 69 74 5f 74  _Trace("submit_t
3220: 69 63 6b 65 74 20 7b 5c 6e 3c 62 6c 6f 63 6b 71  icket {\n<blockq
3230: 75 6f 74 65 3e 3c 70 72 65 3e 5c 6e 25 68 5c 6e  uote><pre>\n%h\n
3240: 3c 2f 70 72 65 3e 3c 2f 62 6c 6f 63 6b 71 75 6f  </pre></blockquo
3250: 74 65 3e 5c 6e 22 0a 20 20 20 20 20 20 20 20 20  te>\n".         
3260: 20 20 20 20 22 7d 3c 62 72 20 2f 3e 5c 6e 22 2c      "}<br />\n",
3270: 0a 20 20 20 20 20 20 20 62 6c 6f 62 5f 73 74 72  .       blob_str
3280: 28 26 74 6b 74 63 68 6e 67 29 29 3b 0a 20 20 7d  (&tktchng));.  }
3290: 65 6c 73 65 7b 0a 20 20 20 20 72 69 64 20 3d 20  else{.    rid = 
32a0: 63 6f 6e 74 65 6e 74 5f 70 75 74 28 26 74 6b 74  content_put(&tkt
32b0: 63 68 6e 67 2c 20 30 2c 20 30 29 3b 0a 20 20 20  chng, 0, 0);.   
32c0: 20 69 66 28 20 72 69 64 3d 3d 30 20 29 7b 0a 20   if( rid==0 ){. 
32d0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69       fossil_pani
32e0: 63 28 22 74 72 6f 75 62 6c 65 20 63 6f 6d 6d 69  c("trouble commi
32f0: 74 74 69 6e 67 20 74 69 63 6b 65 74 3a 20 25 73  tting ticket: %s
3300: 22 2c 20 67 2e 7a 45 72 72 4d 73 67 29 3b 0a 20  ", g.zErrMsg);. 
3310: 20 20 20 7d 0a 20 20 20 20 6d 61 6e 69 66 65 73     }.    manifes
3320: 74 5f 63 72 6f 73 73 6c 69 6e 6b 5f 62 65 67 69  t_crosslink_begi
3330: 6e 28 29 3b 0a 20 20 20 20 6d 61 6e 69 66 65 73  n();.    manifes
3340: 74 5f 63 72 6f 73 73 6c 69 6e 6b 28 72 69 64 2c  t_crosslink(rid,
3350: 20 26 74 6b 74 63 68 6e 67 29 3b 0a 20 20 20 20   &tktchng);.    
3360: 6d 61 6e 69 66 65 73 74 5f 63 72 6f 73 73 6c 69  manifest_crossli
3370: 6e 6b 5f 65 6e 64 28 29 3b 0a 20 20 7d 0a 20 20  nk_end();.  }.  
3380: 72 65 74 75 72 6e 20 54 48 5f 52 45 54 55 52 4e  return TH_RETURN
3390: 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50  ;.}.../*.** WEBP
33a0: 41 47 45 3a 20 74 6b 74 6e 65 77 0a 2a 2a 20 57  AGE: tktnew.** W
33b0: 45 42 50 41 47 45 3a 20 64 65 62 75 67 5f 74 6b  EBPAGE: debug_tk
33c0: 74 6e 65 77 0a 2a 2a 0a 2a 2a 20 45 6e 74 65 72  tnew.**.** Enter
33d0: 20 61 20 6e 65 77 20 74 69 63 6b 65 74 2e 20 20   a new ticket.  
33e0: 74 68 65 20 74 6b 74 6e 65 77 5f 74 65 6d 70 6c  the tktnew_templ
33f0: 61 74 65 20 73 63 72 69 70 74 20 69 6e 20 74 68  ate script in th
3400: 65 20 74 69 63 6b 65 74 0a 2a 2a 20 63 6f 6e 66  e ticket.** conf
3410: 69 67 75 72 61 74 69 6f 6e 20 69 73 20 75 73 65  iguration is use
3420: 64 2e 20 20 54 68 65 20 2f 74 6b 74 6e 65 77 20  d.  The /tktnew 
3430: 70 61 67 65 20 69 73 20 74 68 65 20 6f 66 66 69  page is the offi
3440: 63 69 61 6c 20 74 69 63 6b 65 74 0a 2a 2a 20 65  cial ticket.** e
3450: 6e 74 72 79 20 70 61 67 65 2e 20 20 54 68 65 20  ntry page.  The 
3460: 2f 64 65 62 75 67 5f 74 6b 74 6e 65 77 20 70 61  /debug_tktnew pa
3470: 67 65 20 69 73 20 75 73 65 64 20 66 6f 72 20 64  ge is used for d
3480: 65 62 75 67 67 69 6e 67 20 74 68 65 0a 2a 2a 20  ebugging the.** 
3490: 74 6b 74 6e 65 77 5f 74 65 6d 70 6c 61 74 65 20  tktnew_template 
34a0: 69 6e 20 74 68 65 20 74 69 63 6b 65 74 20 63 6f  in the ticket co
34b0: 6e 66 69 67 75 72 61 74 69 6f 6e 2e 20 20 2f 64  nfiguration.  /d
34c0: 65 62 75 67 5f 74 6b 74 6e 65 77 20 77 6f 72 6b  ebug_tktnew work
34d0: 73 0a 2a 2a 20 6a 75 73 74 20 6c 69 6b 65 20 2f  s.** just like /
34e0: 74 6b 74 6e 65 77 20 65 78 63 65 70 74 20 74 68  tktnew except th
34f0: 61 74 20 69 74 20 64 6f 65 73 20 6e 6f 74 20 72  at it does not r
3500: 65 61 6c 6c 79 20 73 61 76 65 20 74 68 65 20 6e  eally save the n
3510: 65 77 20 74 69 63 6b 65 74 0a 2a 2a 20 77 68 65  ew ticket.** whe
3520: 6e 20 79 6f 75 20 70 72 65 73 73 20 73 75 62 6d  n you press subm
3530: 69 74 20 2d 20 69 74 20 6a 75 73 74 20 70 72 69  it - it just pri
3540: 6e 74 73 20 74 68 65 20 74 69 63 6b 65 74 20 61  nts the ticket a
3550: 72 74 69 66 61 63 74 20 61 74 20 74 68 65 0a 2a  rtifact at the.*
3560: 2a 20 74 6f 70 20 6f 66 20 74 68 65 20 73 63 72  * top of the scr
3570: 65 65 6e 2e 0a 2a 2f 0a 76 6f 69 64 20 74 6b 74  een..*/.void tkt
3580: 6e 65 77 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a  new_page(void){.
3590: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53    const char *zS
35a0: 63 72 69 70 74 3b 0a 20 20 63 68 61 72 20 2a 7a  cript;.  char *z
35b0: 4e 65 77 55 75 69 64 20 3d 20 30 3b 0a 0a 20 20  NewUuid = 0;..  
35c0: 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64  login_check_cred
35d0: 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69 66 28  entials();.  if(
35e0: 20 21 67 2e 6f 6b 4e 65 77 54 6b 74 20 29 7b 20   !g.okNewTkt ){ 
35f0: 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28 29 3b 20  login_needed(); 
3600: 72 65 74 75 72 6e 3b 20 7d 0a 20 20 69 66 28 20  return; }.  if( 
3610: 50 28 22 63 61 6e 63 65 6c 22 29 20 29 7b 0a 20  P("cancel") ){. 
3620: 20 20 20 63 67 69 5f 72 65 64 69 72 65 63 74 28     cgi_redirect(
3630: 22 68 6f 6d 65 22 29 3b 0a 20 20 7d 0a 20 20 73  "home");.  }.  s
3640: 74 79 6c 65 5f 68 65 61 64 65 72 28 22 4e 65 77  tyle_header("New
3650: 20 54 69 63 6b 65 74 22 29 3b 0a 20 20 69 66 28   Ticket");.  if(
3660: 20 67 2e 74 68 54 72 61 63 65 20 29 20 54 68 5f   g.thTrace ) Th_
3670: 54 72 61 63 65 28 22 42 45 47 49 4e 5f 54 4b 54  Trace("BEGIN_TKT
3680: 4e 45 57 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31  NEW<br />\n", -1
3690: 29 3b 0a 20 20 74 69 63 6b 65 74 5f 69 6e 69 74  );.  ticket_init
36a0: 28 29 3b 0a 20 20 67 65 74 41 6c 6c 54 69 63 6b  ();.  getAllTick
36b0: 65 74 46 69 65 6c 64 73 28 29 3b 0a 20 20 69 6e  etFields();.  in
36c0: 69 74 69 61 6c 69 7a 65 56 61 72 69 61 62 6c 65  itializeVariable
36d0: 73 46 72 6f 6d 44 62 28 29 3b 0a 20 20 69 6e 69  sFromDb();.  ini
36e0: 74 69 61 6c 69 7a 65 56 61 72 69 61 62 6c 65 73  tializeVariables
36f0: 46 72 6f 6d 43 47 49 28 29 3b 0a 20 20 40 20 3c  FromCGI();.  @ <
3700: 66 6f 72 6d 20 6d 65 74 68 6f 64 3d 22 50 4f 53  form method="POS
3710: 54 22 20 61 63 74 69 6f 6e 3d 22 25 73 28 67 2e  T" action="%s(g.
3720: 7a 42 61 73 65 55 52 4c 29 2f 25 73 28 67 2e 7a  zBaseURL)/%s(g.z
3730: 50 61 74 68 29 22 3e 0a 20 20 6c 6f 67 69 6e 5f  Path)">.  login_
3740: 69 6e 73 65 72 74 5f 63 73 72 66 5f 73 65 63 72  insert_csrf_secr
3750: 65 74 28 29 3b 0a 20 20 7a 53 63 72 69 70 74 20  et();.  zScript 
3760: 3d 20 74 69 63 6b 65 74 5f 6e 65 77 70 61 67 65  = ticket_newpage
3770: 5f 63 6f 64 65 28 29 3b 0a 20 20 54 68 5f 53 74  _code();.  Th_St
3780: 6f 72 65 28 22 6c 6f 67 69 6e 22 2c 20 67 2e 7a  ore("login", g.z
3790: 4c 6f 67 69 6e 29 3b 0a 20 20 54 68 5f 53 74 6f  Login);.  Th_Sto
37a0: 72 65 28 22 64 61 74 65 22 2c 20 64 62 5f 74 65  re("date", db_te
37b0: 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 64 61  xt(0, "SELECT da
37c0: 74 65 74 69 6d 65 28 27 6e 6f 77 27 29 22 29 29  tetime('now')"))
37d0: 3b 0a 20 20 54 68 5f 43 72 65 61 74 65 43 6f 6d  ;.  Th_CreateCom
37e0: 6d 61 6e 64 28 67 2e 69 6e 74 65 72 70 2c 20 22  mand(g.interp, "
37f0: 73 75 62 6d 69 74 5f 74 69 63 6b 65 74 22 2c 20  submit_ticket", 
3800: 73 75 62 6d 69 74 54 69 63 6b 65 74 43 6d 64 2c  submitTicketCmd,
3810: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
3820: 20 20 20 20 28 76 6f 69 64 2a 29 26 7a 4e 65 77      (void*)&zNew
3830: 55 75 69 64 2c 20 30 29 3b 0a 20 20 69 66 28 20  Uuid, 0);.  if( 
3840: 67 2e 74 68 54 72 61 63 65 20 29 20 54 68 5f 54  g.thTrace ) Th_T
3850: 72 61 63 65 28 22 42 45 47 49 4e 5f 54 4b 54 4e  race("BEGIN_TKTN
3860: 45 57 5f 53 43 52 49 50 54 3c 62 72 20 2f 3e 5c  EW_SCRIPT<br />\
3870: 6e 22 2c 20 2d 31 29 3b 0a 20 20 69 66 28 20 54  n", -1);.  if( T
3880: 68 5f 52 65 6e 64 65 72 28 7a 53 63 72 69 70 74  h_Render(zScript
3890: 29 3d 3d 54 48 5f 52 45 54 55 52 4e 20 26 26 20  )==TH_RETURN && 
38a0: 21 67 2e 74 68 54 72 61 63 65 20 26 26 20 7a 4e  !g.thTrace && zN
38b0: 65 77 55 75 69 64 20 29 7b 0a 20 20 20 20 63 67  ewUuid ){.    cg
38c0: 69 5f 72 65 64 69 72 65 63 74 28 6d 70 72 69 6e  i_redirect(mprin
38d0: 74 66 28 22 25 73 2f 74 6b 74 76 69 65 77 2f 25  tf("%s/tktview/%
38e0: 73 22 2c 20 67 2e 7a 42 61 73 65 55 52 4c 2c 20  s", g.zBaseURL, 
38f0: 7a 4e 65 77 55 75 69 64 29 29 3b 0a 20 20 20 20  zNewUuid));.    
3900: 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 40 20  return;.  }.  @ 
3910: 3c 2f 66 6f 72 6d 3e 0a 20 20 69 66 28 20 67 2e  </form>.  if( g.
3920: 74 68 54 72 61 63 65 20 29 20 54 68 5f 54 72 61  thTrace ) Th_Tra
3930: 63 65 28 22 45 4e 44 5f 54 4b 54 56 49 45 57 3c  ce("END_TKTVIEW<
3940: 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a 20  br />\n", -1);. 
3950: 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b   style_footer();
3960: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50 41 47  .}../*.** WEBPAG
3970: 45 3a 20 74 6b 74 65 64 69 74 0a 2a 2a 20 57 45  E: tktedit.** WE
3980: 42 50 41 47 45 3a 20 64 65 62 75 67 5f 74 6b 74  BPAGE: debug_tkt
3990: 65 64 69 74 0a 2a 2a 0a 2a 2a 20 45 64 69 74 20  edit.**.** Edit 
39a0: 61 20 74 69 63 6b 65 74 2e 20 20 54 68 65 20 74  a ticket.  The t
39b0: 69 63 6b 65 74 20 69 73 20 69 64 65 6e 74 69 66  icket is identif
39c0: 69 65 64 20 62 79 20 74 68 65 20 6e 61 6d 65 20  ied by the name 
39d0: 43 47 49 20 70 61 72 61 6d 65 74 65 72 2e 0a 2a  CGI parameter..*
39e0: 2a 20 2f 74 6b 74 65 64 69 74 20 69 73 20 74 68  * /tktedit is th
39f0: 65 20 6f 66 66 69 63 69 61 6c 20 70 61 67 65 2e  e official page.
3a00: 20 20 54 68 65 20 2f 64 65 62 75 67 5f 74 6b 74    The /debug_tkt
3a10: 65 64 69 74 20 70 61 67 65 20 64 6f 65 73 20 74  edit page does t
3a20: 68 65 20 73 61 6d 65 0a 2a 2a 20 74 68 69 6e 67  he same.** thing
3a30: 20 65 78 63 65 70 74 20 74 68 61 74 20 69 74 20   except that it 
3a40: 64 6f 65 73 20 6e 6f 74 20 73 61 76 65 20 74 68  does not save th
3a50: 65 20 74 69 63 6b 65 74 20 63 68 61 6e 67 65 20  e ticket change 
3a60: 72 65 63 6f 72 64 20 77 68 65 6e 20 79 6f 75 0a  record when you.
3a70: 2a 2a 20 70 72 65 73 73 20 73 75 62 6d 69 74 20  ** press submit 
3a80: 2d 20 69 74 20 69 6e 73 74 65 61 64 20 70 72 69  - it instead pri
3a90: 6e 74 73 20 74 68 65 20 74 69 63 6b 65 74 20 63  nts the ticket c
3aa0: 68 61 6e 67 65 20 72 65 63 6f 72 64 20 61 74 20  hange record at 
3ab0: 74 68 65 20 74 6f 70 0a 2a 2a 20 6f 66 20 74 68  the top.** of th
3ac0: 65 20 70 61 67 65 2e 20 20 54 68 65 20 2f 64 65  e page.  The /de
3ad0: 62 75 67 5f 74 6b 74 65 64 69 74 20 70 61 67 65  bug_tktedit page
3ae0: 20 69 73 20 69 6e 74 65 6e 64 65 64 20 74 6f 20   is intended to 
3af0: 62 65 20 75 73 65 64 20 77 68 65 6e 0a 2a 2a 20  be used when.** 
3b00: 64 65 62 75 67 67 69 6e 67 20 74 69 63 6b 65 74  debugging ticket
3b10: 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 73 2e   configurations.
3b20: 0a 2a 2f 0a 76 6f 69 64 20 74 6b 74 65 64 69 74  .*/.void tktedit
3b30: 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 20 63  _page(void){.  c
3b40: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 63 72 69  onst char *zScri
3b50: 70 74 3b 0a 20 20 69 6e 74 20 6e 4e 61 6d 65 3b  pt;.  int nName;
3b60: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
3b70: 4e 61 6d 65 3b 0a 20 20 69 6e 74 20 6e 52 65 63  Name;.  int nRec
3b80: 3b 0a 0a 20 20 6c 6f 67 69 6e 5f 63 68 65 63 6b  ;..  login_check
3b90: 5f 63 72 65 64 65 6e 74 69 61 6c 73 28 29 3b 0a  _credentials();.
3ba0: 20 20 69 66 28 20 21 67 2e 6f 6b 41 70 6e 64 54    if( !g.okApndT
3bb0: 6b 74 20 26 26 20 21 67 2e 6f 6b 57 72 54 6b 74  kt && !g.okWrTkt
3bc0: 20 29 7b 20 6c 6f 67 69 6e 5f 6e 65 65 64 65 64   ){ login_needed
3bd0: 28 29 3b 20 72 65 74 75 72 6e 3b 20 7d 0a 20 20  (); return; }.  
3be0: 7a 4e 61 6d 65 20 3d 20 50 28 22 6e 61 6d 65 22  zName = P("name"
3bf0: 29 3b 0a 20 20 69 66 28 20 50 28 22 63 61 6e 63  );.  if( P("canc
3c00: 65 6c 22 29 20 29 7b 0a 20 20 20 20 63 67 69 5f  el") ){.    cgi_
3c10: 72 65 64 69 72 65 63 74 66 28 22 74 6b 74 76 69  redirectf("tktvi
3c20: 65 77 3f 6e 61 6d 65 3d 25 54 22 2c 20 7a 4e 61  ew?name=%T", zNa
3c30: 6d 65 29 3b 0a 20 20 7d 0a 20 20 73 74 79 6c 65  me);.  }.  style
3c40: 5f 68 65 61 64 65 72 28 22 45 64 69 74 20 54 69  _header("Edit Ti
3c50: 63 6b 65 74 22 29 3b 0a 20 20 69 66 28 20 7a 4e  cket");.  if( zN
3c60: 61 6d 65 3d 3d 30 20 7c 7c 20 28 6e 4e 61 6d 65  ame==0 || (nName
3c70: 20 3d 20 73 74 72 6c 65 6e 28 7a 4e 61 6d 65 29   = strlen(zName)
3c80: 29 3c 34 20 7c 7c 20 6e 4e 61 6d 65 3e 55 55 49  )<4 || nName>UUI
3c90: 44 5f 53 49 5a 45 0a 20 20 20 20 20 20 20 20 20  D_SIZE.         
3ca0: 20 7c 7c 20 21 76 61 6c 69 64 61 74 65 31 36 28   || !validate16(
3cb0: 7a 4e 61 6d 65 2c 6e 4e 61 6d 65 29 20 29 7b 0a  zName,nName) ){.
3cc0: 20 20 20 20 40 20 3c 66 6f 6e 74 20 63 6f 6c 6f      @ <font colo
3cd0: 72 3d 22 72 65 64 22 3e 3c 62 3e 4e 6f 74 20 61  r="red"><b>Not a
3ce0: 20 76 61 6c 69 64 20 74 69 63 6b 65 74 20 69 64   valid ticket id
3cf0: 3a 20 5c 22 25 68 28 7a 4e 61 6d 65 29 5c 22 3c  : \"%h(zName)\"<
3d00: 2f 62 3e 3c 2f 66 6f 6e 74 3e 0a 20 20 20 20 73  /b></font>.    s
3d10: 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 20  tyle_footer();. 
3d20: 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20     return;.  }. 
3d30: 20 6e 52 65 63 20 3d 20 64 62 5f 69 6e 74 28 30   nRec = db_int(0
3d40: 2c 20 22 53 45 4c 45 43 54 20 63 6f 75 6e 74 28  , "SELECT count(
3d50: 2a 29 20 46 52 4f 4d 20 74 69 63 6b 65 74 20 57  *) FROM ticket W
3d60: 48 45 52 45 20 74 6b 74 5f 75 75 69 64 20 47 4c  HERE tkt_uuid GL
3d70: 4f 42 20 27 25 71 2a 27 22 2c 0a 20 20 20 20 20  OB '%q*'",.     
3d80: 20 20 20 20 20 20 20 20 20 20 20 7a 4e 61 6d 65             zName
3d90: 29 3b 0a 20 20 69 66 28 20 6e 52 65 63 3d 3d 30  );.  if( nRec==0
3da0: 20 29 7b 0a 20 20 20 20 40 20 3c 66 6f 6e 74 20   ){.    @ <font 
3db0: 63 6f 6c 6f 72 3d 22 72 65 64 22 3e 3c 62 3e 4e  color="red"><b>N
3dc0: 6f 20 73 75 63 68 20 74 69 63 6b 65 74 3a 20 5c  o such ticket: \
3dd0: 22 25 68 28 7a 4e 61 6d 65 29 5c 22 3c 2f 62 3e  "%h(zName)\"</b>
3de0: 3c 2f 66 6f 6e 74 3e 0a 20 20 20 20 73 74 79 6c  </font>.    styl
3df0: 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 20 20 20 20  e_footer();.    
3e00: 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 69 66  return;.  }.  if
3e10: 28 20 6e 52 65 63 3e 31 20 29 7b 0a 20 20 20 20  ( nRec>1 ){.    
3e20: 40 20 3c 66 6f 6e 74 20 63 6f 6c 6f 72 3d 22 72  @ <font color="r
3e30: 65 64 22 3e 3c 62 3e 25 64 28 6e 52 65 63 29 20  ed"><b>%d(nRec) 
3e40: 74 69 63 6b 65 74 73 20 62 65 67 69 6e 20 77 69  tickets begin wi
3e50: 74 68 3a 20 5c 22 25 68 28 7a 4e 61 6d 65 29 5c  th: \"%h(zName)\
3e60: 22 3c 2f 62 3e 3c 2f 66 6f 6e 74 3e 0a 20 20 20  "</b></font>.   
3e70: 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b   style_footer();
3e80: 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d  .    return;.  }
3e90: 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61 63 65  .  if( g.thTrace
3ea0: 20 29 20 54 68 5f 54 72 61 63 65 28 22 42 45 47   ) Th_Trace("BEG
3eb0: 49 4e 5f 54 4b 54 45 44 49 54 3c 62 72 20 2f 3e  IN_TKTEDIT<br />
3ec0: 5c 6e 22 2c 20 2d 31 29 3b 0a 20 20 74 69 63 6b  \n", -1);.  tick
3ed0: 65 74 5f 69 6e 69 74 28 29 3b 0a 20 20 67 65 74  et_init();.  get
3ee0: 41 6c 6c 54 69 63 6b 65 74 46 69 65 6c 64 73 28  AllTicketFields(
3ef0: 29 3b 0a 20 20 69 6e 69 74 69 61 6c 69 7a 65 56  );.  initializeV
3f00: 61 72 69 61 62 6c 65 73 46 72 6f 6d 43 47 49 28  ariablesFromCGI(
3f10: 29 3b 0a 20 20 69 6e 69 74 69 61 6c 69 7a 65 56  );.  initializeV
3f20: 61 72 69 61 62 6c 65 73 46 72 6f 6d 44 62 28 29  ariablesFromDb()
3f30: 3b 0a 20 20 40 20 3c 66 6f 72 6d 20 6d 65 74 68  ;.  @ <form meth
3f40: 6f 64 3d 22 50 4f 53 54 22 20 61 63 74 69 6f 6e  od="POST" action
3f50: 3d 22 25 73 28 67 2e 7a 42 61 73 65 55 52 4c 29  ="%s(g.zBaseURL)
3f60: 2f 25 73 28 67 2e 7a 50 61 74 68 29 22 3e 0a 20  /%s(g.zPath)">. 
3f70: 20 40 20 3c 69 6e 70 75 74 20 74 79 70 65 3d 22   @ <input type="
3f80: 68 69 64 64 65 6e 22 20 6e 61 6d 65 3d 22 6e 61  hidden" name="na
3f90: 6d 65 22 20 76 61 6c 75 65 3d 22 25 73 28 7a 4e  me" value="%s(zN
3fa0: 61 6d 65 29 22 3e 0a 20 20 6c 6f 67 69 6e 5f 69  ame)">.  login_i
3fb0: 6e 73 65 72 74 5f 63 73 72 66 5f 73 65 63 72 65  nsert_csrf_secre
3fc0: 74 28 29 3b 0a 20 20 7a 53 63 72 69 70 74 20 3d  t();.  zScript =
3fd0: 20 74 69 63 6b 65 74 5f 65 64 69 74 70 61 67 65   ticket_editpage
3fe0: 5f 63 6f 64 65 28 29 3b 0a 20 20 54 68 5f 53 74  _code();.  Th_St
3ff0: 6f 72 65 28 22 6c 6f 67 69 6e 22 2c 20 67 2e 7a  ore("login", g.z
4000: 4c 6f 67 69 6e 29 3b 0a 20 20 54 68 5f 53 74 6f  Login);.  Th_Sto
4010: 72 65 28 22 64 61 74 65 22 2c 20 64 62 5f 74 65  re("date", db_te
4020: 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 64 61  xt(0, "SELECT da
4030: 74 65 74 69 6d 65 28 27 6e 6f 77 27 29 22 29 29  tetime('now')"))
4040: 3b 0a 20 20 54 68 5f 43 72 65 61 74 65 43 6f 6d  ;.  Th_CreateCom
4050: 6d 61 6e 64 28 67 2e 69 6e 74 65 72 70 2c 20 22  mand(g.interp, "
4060: 61 70 70 65 6e 64 5f 66 69 65 6c 64 22 2c 20 61  append_field", a
4070: 70 70 65 6e 64 52 65 6d 61 72 6b 43 6d 64 2c 20  ppendRemarkCmd, 
4080: 30 2c 20 30 29 3b 0a 20 20 54 68 5f 43 72 65 61  0, 0);.  Th_Crea
4090: 74 65 43 6f 6d 6d 61 6e 64 28 67 2e 69 6e 74 65  teCommand(g.inte
40a0: 72 70 2c 20 22 73 75 62 6d 69 74 5f 74 69 63 6b  rp, "submit_tick
40b0: 65 74 22 2c 20 73 75 62 6d 69 74 54 69 63 6b 65  et", submitTicke
40c0: 74 43 6d 64 2c 20 28 76 6f 69 64 2a 29 26 7a 4e  tCmd, (void*)&zN
40d0: 61 6d 65 2c 30 29 3b 0a 20 20 69 66 28 20 67 2e  ame,0);.  if( g.
40e0: 74 68 54 72 61 63 65 20 29 20 54 68 5f 54 72 61  thTrace ) Th_Tra
40f0: 63 65 28 22 42 45 47 49 4e 5f 54 4b 54 45 44 49  ce("BEGIN_TKTEDI
4100: 54 5f 53 43 52 49 50 54 3c 62 72 20 2f 3e 5c 6e  T_SCRIPT<br />\n
4110: 22 2c 20 2d 31 29 3b 0a 20 20 69 66 28 20 54 68  ", -1);.  if( Th
4120: 5f 52 65 6e 64 65 72 28 7a 53 63 72 69 70 74 29  _Render(zScript)
4130: 3d 3d 54 48 5f 52 45 54 55 52 4e 20 26 26 20 21  ==TH_RETURN && !
4140: 67 2e 74 68 54 72 61 63 65 20 26 26 20 7a 4e 61  g.thTrace && zNa
4150: 6d 65 20 29 7b 0a 20 20 20 20 63 67 69 5f 72 65  me ){.    cgi_re
4160: 64 69 72 65 63 74 28 6d 70 72 69 6e 74 66 28 22  direct(mprintf("
4170: 25 73 2f 74 6b 74 76 69 65 77 2f 25 73 22 2c 20  %s/tktview/%s", 
4180: 67 2e 7a 42 61 73 65 55 52 4c 2c 20 7a 4e 61 6d  g.zBaseURL, zNam
4190: 65 29 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b  e));.    return;
41a0: 0a 20 20 7d 0a 20 20 40 20 3c 2f 66 6f 72 6d 3e  .  }.  @ </form>
41b0: 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61 63 65  .  if( g.thTrace
41c0: 20 29 20 54 68 5f 54 72 61 63 65 28 22 42 45 47   ) Th_Trace("BEG
41d0: 49 4e 5f 54 4b 54 45 44 49 54 3c 62 72 20 2f 3e  IN_TKTEDIT<br />
41e0: 5c 6e 22 2c 20 2d 31 29 3b 0a 20 20 73 74 79 6c  \n", -1);.  styl
41f0: 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 7d 0a 0a 2f  e_footer();.}../
4200: 2a 0a 2a 2a 20 43 68 65 63 6b 20 74 68 65 20 74  *.** Check the t
4210: 69 63 6b 65 74 20 74 61 62 6c 65 20 73 63 68 65  icket table sche
4220: 6d 61 20 69 6e 20 7a 53 63 68 65 6d 61 20 74 6f  ma in zSchema to
4230: 20 73 65 65 20 69 66 20 69 74 20 61 70 70 65 61   see if it appea
4240: 72 73 20 74 6f 0a 2a 2a 20 62 65 20 77 65 6c 6c  rs to.** be well
4250: 2d 66 6f 72 6d 65 64 2e 20 20 49 66 20 65 76 65  -formed.  If eve
4260: 72 79 74 68 69 6e 67 20 69 73 20 4f 4b 2c 20 72  rything is OK, r
4270: 65 74 75 72 6e 20 4e 55 4c 4c 2e 20 20 49 66 20  eturn NULL.  If 
4280: 73 6f 6d 65 74 68 69 6e 67 20 69 73 0a 2a 2a 20  something is.** 
4290: 61 6d 69 73 73 2c 20 74 68 65 6e 20 72 65 74 75  amiss, then retu
42a0: 72 6e 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20  rn a pointer to 
42b0: 61 20 73 74 72 69 6e 67 20 28 6f 62 74 61 69 6e  a string (obtain
42c0: 65 64 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 29 20  ed from malloc) 
42d0: 74 68 61 74 0a 2a 2a 20 64 65 73 63 72 69 62 65  that.** describe
42e0: 73 20 74 68 65 20 70 72 6f 62 6c 65 6d 2e 0a 2a  s the problem..*
42f0: 2f 0a 63 68 61 72 20 2a 74 69 63 6b 65 74 5f 73  /.char *ticket_s
4300: 63 68 65 6d 61 5f 63 68 65 63 6b 28 63 6f 6e 73  chema_check(cons
4310: 74 20 63 68 61 72 20 2a 7a 53 63 68 65 6d 61 29  t char *zSchema)
4320: 7b 0a 20 20 63 68 61 72 20 2a 7a 45 72 72 20 3d  {.  char *zErr =
4330: 20 30 3b 0a 20 20 69 6e 74 20 72 63 3b 0a 20 20   0;.  int rc;.  
4340: 73 71 6c 69 74 65 33 20 2a 64 62 3b 0a 20 20 72  sqlite3 *db;.  r
4350: 63 20 3d 20 73 71 6c 69 74 65 33 5f 6f 70 65 6e  c = sqlite3_open
4360: 28 22 3a 6d 65 6d 6f 72 79 3a 22 2c 20 26 64 62  (":memory:", &db
4370: 29 3b 0a 20 20 69 66 28 20 72 63 3d 3d 53 51 4c  );.  if( rc==SQL
4380: 49 54 45 5f 4f 4b 20 29 7b 0a 20 20 20 20 72 63  ITE_OK ){.    rc
4390: 20 3d 20 73 71 6c 69 74 65 33 5f 65 78 65 63 28   = sqlite3_exec(
43a0: 64 62 2c 20 7a 53 63 68 65 6d 61 2c 20 30 2c 20  db, zSchema, 0, 
43b0: 30 2c 20 26 7a 45 72 72 29 3b 0a 20 20 20 20 69  0, &zErr);.    i
43c0: 66 28 20 72 63 21 3d 53 51 4c 49 54 45 5f 4f 4b  f( rc!=SQLITE_OK
43d0: 20 29 7b 0a 20 20 20 20 20 20 73 71 6c 69 74 65   ){.      sqlite
43e0: 33 5f 63 6c 6f 73 65 28 64 62 29 3b 0a 20 20 20  3_close(db);.   
43f0: 20 20 20 72 65 74 75 72 6e 20 7a 45 72 72 3b 0a     return zErr;.
4400: 20 20 20 20 7d 0a 20 20 20 20 72 63 20 3d 20 73      }.    rc = s
4410: 71 6c 69 74 65 33 5f 65 78 65 63 28 64 62 2c 20  qlite3_exec(db, 
4420: 22 53 45 4c 45 43 54 20 74 6b 74 5f 69 64 2c 20  "SELECT tkt_id, 
4430: 74 6b 74 5f 75 75 69 64 2c 20 74 6b 74 5f 6d 74  tkt_uuid, tkt_mt
4440: 69 6d 65 20 46 52 4f 4d 20 74 69 63 6b 65 74 22  ime FROM ticket"
4450: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
4460: 20 20 20 20 20 20 20 20 30 2c 20 30 2c 20 30 29          0, 0, 0)
4470: 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 63 6c  ;.    sqlite3_cl
4480: 6f 73 65 28 64 62 29 3b 0a 20 20 20 20 69 66 28  ose(db);.    if(
4490: 20 72 63 21 3d 53 51 4c 49 54 45 5f 4f 4b 20 29   rc!=SQLITE_OK )
44a0: 7b 0a 20 20 20 20 20 20 7a 45 72 72 20 3d 20 6d  {.      zErr = m
44b0: 70 72 69 6e 74 66 28 22 73 63 68 65 6d 61 20 66  printf("schema f
44c0: 61 69 6c 73 20 74 6f 20 64 65 66 69 6e 65 20 61  ails to define a
44d0: 20 76 61 6c 69 64 20 74 69 63 6b 65 74 20 74 61   valid ticket ta
44e0: 62 6c 65 20 22 0a 20 20 20 20 20 20 20 20 20 20  ble ".          
44f0: 20 20 20 20 20 20 20 20 20 20 20 22 63 6f 6e 74             "cont
4500: 61 69 6e 69 6e 67 20 61 6c 6c 20 72 65 71 75 69  aining all requi
4510: 72 65 64 20 66 69 65 6c 64 73 22 29 3b 0a 20 20  red fields");.  
4520: 20 20 20 20 72 65 74 75 72 6e 20 7a 45 72 72 3b      return zErr;
4530: 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 72 65 74  .    }.  }.  ret
4540: 75 72 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  urn 0;.}../*.** 
4550: 57 45 42 50 41 47 45 3a 20 74 6b 74 74 69 6d 65  WEBPAGE: tkttime
4560: 6c 69 6e 65 0a 2a 2a 20 55 52 4c 3a 20 2f 74 6b  line.** URL: /tk
4570: 74 74 69 6d 65 6c 69 6e 65 3f 6e 61 6d 65 3d 54  ttimeline?name=T
4580: 49 43 4b 45 54 55 55 49 44 0a 2a 2a 0a 2a 2a 20  ICKETUUID.**.** 
4590: 53 68 6f 77 20 74 68 65 20 63 68 61 6e 67 65 20  Show the change 
45a0: 68 69 73 74 6f 72 79 20 66 6f 72 20 61 20 73 69  history for a si
45b0: 6e 67 6c 65 20 74 69 63 6b 65 74 20 69 6e 20 74  ngle ticket in t
45c0: 69 6d 65 6c 69 6e 65 20 66 6f 72 6d 61 74 2e 0a  imeline format..
45d0: 2a 2f 0a 76 6f 69 64 20 74 6b 74 74 69 6d 65 6c  */.void tkttimel
45e0: 69 6e 65 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a  ine_page(void){.
45f0: 20 20 53 74 6d 74 20 71 3b 0a 20 20 63 68 61 72    Stmt q;.  char
4600: 20 2a 7a 54 69 74 6c 65 3b 0a 20 20 63 68 61 72   *zTitle;.  char
4610: 20 2a 7a 53 51 4c 3b 0a 20 20 63 6f 6e 73 74 20   *zSQL;.  const 
4620: 63 68 61 72 20 2a 7a 55 75 69 64 3b 0a 20 20 69  char *zUuid;.  i
4630: 6e 74 20 74 61 67 69 64 3b 0a 0a 20 20 6c 6f 67  nt tagid;..  log
4640: 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74  in_check_credent
4650: 69 61 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67  ials();.  if( !g
4660: 2e 6f 6b 48 69 73 74 6f 72 79 20 7c 7c 20 21 67  .okHistory || !g
4670: 2e 6f 6b 52 64 54 6b 74 20 29 7b 20 6c 6f 67 69  .okRdTkt ){ logi
4680: 6e 5f 6e 65 65 64 65 64 28 29 3b 20 72 65 74 75  n_needed(); retu
4690: 72 6e 3b 20 7d 0a 20 20 7a 55 75 69 64 20 3d 20  rn; }.  zUuid = 
46a0: 50 44 28 22 6e 61 6d 65 22 2c 22 22 29 3b 0a 20  PD("name","");. 
46b0: 20 73 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65   style_submenu_e
46c0: 6c 65 6d 65 6e 74 28 22 48 69 73 74 6f 72 79 22  lement("History"
46d0: 2c 20 22 48 69 73 74 6f 72 79 22 2c 0a 20 20 20  , "History",.   
46e0: 20 22 25 73 2f 74 6b 74 68 69 73 74 6f 72 79 2f   "%s/tkthistory/
46f0: 25 73 22 2c 20 67 2e 7a 54 6f 70 2c 20 7a 55 75  %s", g.zTop, zUu
4700: 69 64 29 3b 0a 20 20 73 74 79 6c 65 5f 73 75 62  id);.  style_sub
4710: 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 53 74  menu_element("St
4720: 61 74 75 73 22 2c 20 22 53 74 61 74 75 73 22 2c  atus", "Status",
4730: 0a 20 20 20 20 22 25 73 2f 69 6e 66 6f 2f 25 73  .    "%s/info/%s
4740: 22 2c 20 67 2e 7a 54 6f 70 2c 20 7a 55 75 69 64  ", g.zTop, zUuid
4750: 29 3b 0a 20 20 7a 54 69 74 6c 65 20 3d 20 6d 70  );.  zTitle = mp
4760: 72 69 6e 74 66 28 22 54 69 6d 65 6c 69 6e 65 20  rintf("Timeline 
4770: 4f 66 20 54 69 63 6b 65 74 20 25 68 22 2c 20 7a  Of Ticket %h", z
4780: 55 75 69 64 29 3b 0a 20 20 73 74 79 6c 65 5f 68  Uuid);.  style_h
4790: 65 61 64 65 72 28 7a 54 69 74 6c 65 29 3b 0a 20  eader(zTitle);. 
47a0: 20 66 72 65 65 28 7a 54 69 74 6c 65 29 3b 0a 0a   free(zTitle);..
47b0: 20 20 74 61 67 69 64 20 3d 20 64 62 5f 69 6e 74    tagid = db_int
47c0: 28 30 2c 20 22 53 45 4c 45 43 54 20 74 61 67 69  (0, "SELECT tagi
47d0: 64 20 46 52 4f 4d 20 74 61 67 20 57 48 45 52 45  d FROM tag WHERE
47e0: 20 74 61 67 6e 61 6d 65 20 47 4c 4f 42 20 27 74   tagname GLOB 't
47f0: 6b 74 2d 25 71 2a 27 22 2c 7a 55 75 69 64 29 3b  kt-%q*'",zUuid);
4800: 0a 20 20 69 66 28 20 74 61 67 69 64 3d 3d 30 20  .  if( tagid==0 
4810: 29 7b 0a 20 20 20 20 40 20 4e 6f 20 73 75 63 68  ){.    @ No such
4820: 20 74 69 63 6b 65 74 3a 20 25 68 28 7a 55 75 69   ticket: %h(zUui
4830: 64 29 0a 20 20 20 20 73 74 79 6c 65 5f 66 6f 6f  d).    style_foo
4840: 74 65 72 28 29 3b 0a 20 20 20 20 72 65 74 75 72  ter();.    retur
4850: 6e 3b 0a 20 20 7d 0a 20 20 7a 53 51 4c 20 3d 20  n;.  }.  zSQL = 
4860: 6d 70 72 69 6e 74 66 28 22 25 73 20 41 4e 44 20  mprintf("%s AND 
4870: 65 76 65 6e 74 2e 6f 62 6a 69 64 20 49 4e 20 22  event.objid IN "
4880: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
4890: 20 20 22 20 20 28 53 45 4c 45 43 54 20 72 69 64    "  (SELECT rid
48a0: 20 46 52 4f 4d 20 74 61 67 78 72 65 66 20 57 48   FROM tagxref WH
48b0: 45 52 45 20 74 61 67 69 64 3d 25 64 29 20 22 0a  ERE tagid=%d) ".
48c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
48d0: 20 22 4f 52 44 45 52 20 42 59 20 6d 74 69 6d 65   "ORDER BY mtime
48e0: 20 44 45 53 43 22 2c 0a 20 20 20 20 20 20 20 20   DESC",.        
48f0: 20 20 20 20 20 20 20 20 20 74 69 6d 65 6c 69 6e           timelin
4900: 65 5f 71 75 65 72 79 5f 66 6f 72 5f 77 77 77 28  e_query_for_www(
4910: 29 2c 20 74 61 67 69 64 29 3b 0a 20 20 64 62 5f  ), tagid);.  db_
4920: 70 72 65 70 61 72 65 28 26 71 2c 20 7a 53 51 4c  prepare(&q, zSQL
4930: 29 3b 0a 20 20 66 72 65 65 28 7a 53 51 4c 29 3b  );.  free(zSQL);
4940: 0a 20 20 77 77 77 5f 70 72 69 6e 74 5f 74 69 6d  .  www_print_tim
4950: 65 6c 69 6e 65 28 26 71 2c 20 54 49 4d 45 4c 49  eline(&q, TIMELI
4960: 4e 45 5f 41 52 54 49 44 2c 20 30 29 3b 0a 20 20  NE_ARTID, 0);.  
4970: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b  db_finalize(&q);
4980: 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28  .  style_footer(
4990: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50  );.}../*.** WEBP
49a0: 41 47 45 3a 20 74 6b 74 68 69 73 74 6f 72 79 0a  AGE: tkthistory.
49b0: 2a 2a 20 55 52 4c 3a 20 2f 74 6b 74 68 69 73 74  ** URL: /tkthist
49c0: 6f 72 79 3f 6e 61 6d 65 3d 54 49 43 4b 45 54 55  ory?name=TICKETU
49d0: 55 49 44 0a 2a 2a 0a 2a 2a 20 53 68 6f 77 20 74  UID.**.** Show t
49e0: 68 65 20 63 6f 6d 70 6c 65 74 65 20 63 68 61 6e  he complete chan
49f0: 67 65 20 68 69 73 74 6f 72 79 20 66 6f 72 20 61  ge history for a
4a00: 20 73 69 6e 67 6c 65 20 74 69 63 6b 65 74 0a 2a   single ticket.*
4a10: 2f 0a 76 6f 69 64 20 74 6b 74 68 69 73 74 6f 72  /.void tkthistor
4a20: 79 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 20  y_page(void){.  
4a30: 53 74 6d 74 20 71 3b 0a 20 20 63 68 61 72 20 2a  Stmt q;.  char *
4a40: 7a 54 69 74 6c 65 3b 0a 20 20 63 6f 6e 73 74 20  zTitle;.  const 
4a50: 63 68 61 72 20 2a 7a 55 75 69 64 3b 0a 20 20 69  char *zUuid;.  i
4a60: 6e 74 20 74 61 67 69 64 3b 0a 0a 20 20 6c 6f 67  nt tagid;..  log
4a70: 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74  in_check_credent
4a80: 69 61 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67  ials();.  if( !g
4a90: 2e 6f 6b 48 69 73 74 6f 72 79 20 7c 7c 20 21 67  .okHistory || !g
4aa0: 2e 6f 6b 52 64 54 6b 74 20 29 7b 20 6c 6f 67 69  .okRdTkt ){ logi
4ab0: 6e 5f 6e 65 65 64 65 64 28 29 3b 20 72 65 74 75  n_needed(); retu
4ac0: 72 6e 3b 20 7d 0a 20 20 7a 55 75 69 64 20 3d 20  rn; }.  zUuid = 
4ad0: 50 44 28 22 6e 61 6d 65 22 2c 22 22 29 3b 0a 20  PD("name","");. 
4ae0: 20 7a 54 69 74 6c 65 20 3d 20 6d 70 72 69 6e 74   zTitle = mprint
4af0: 66 28 22 48 69 73 74 6f 72 79 20 4f 66 20 54 69  f("History Of Ti
4b00: 63 6b 65 74 20 25 68 22 2c 20 7a 55 75 69 64 29  cket %h", zUuid)
4b10: 3b 0a 20 20 73 74 79 6c 65 5f 73 75 62 6d 65 6e  ;.  style_submen
4b20: 75 5f 65 6c 65 6d 65 6e 74 28 22 53 74 61 74 75  u_element("Statu
4b30: 73 22 2c 20 22 53 74 61 74 75 73 22 2c 0a 20 20  s", "Status",.  
4b40: 20 20 22 25 73 2f 69 6e 66 6f 2f 25 73 22 2c 20    "%s/info/%s", 
4b50: 67 2e 7a 54 6f 70 2c 20 7a 55 75 69 64 29 3b 0a  g.zTop, zUuid);.
4b60: 20 20 73 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f    style_submenu_
4b70: 65 6c 65 6d 65 6e 74 28 22 54 69 6d 65 6c 69 6e  element("Timelin
4b80: 65 22 2c 20 22 54 69 6d 65 6c 69 6e 65 22 2c 0a  e", "Timeline",.
4b90: 20 20 20 20 22 25 73 2f 74 6b 74 74 69 6d 65 6c      "%s/tkttimel
4ba0: 69 6e 65 3f 6e 61 6d 65 3d 25 73 22 2c 20 67 2e  ine?name=%s", g.
4bb0: 7a 54 6f 70 2c 20 7a 55 75 69 64 29 3b 0a 20 20  zTop, zUuid);.  
4bc0: 73 74 79 6c 65 5f 68 65 61 64 65 72 28 7a 54 69  style_header(zTi
4bd0: 74 6c 65 29 3b 0a 20 20 66 72 65 65 28 7a 54 69  tle);.  free(zTi
4be0: 74 6c 65 29 3b 0a 0a 20 20 74 61 67 69 64 20 3d  tle);..  tagid =
4bf0: 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45   db_int(0, "SELE
4c00: 43 54 20 74 61 67 69 64 20 46 52 4f 4d 20 74 61  CT tagid FROM ta
4c10: 67 20 57 48 45 52 45 20 74 61 67 6e 61 6d 65 20  g WHERE tagname 
4c20: 47 4c 4f 42 20 27 74 6b 74 2d 25 71 2a 27 22 2c  GLOB 'tkt-%q*'",
4c30: 7a 55 75 69 64 29 3b 0a 20 20 69 66 28 20 74 61  zUuid);.  if( ta
4c40: 67 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 40 20  gid==0 ){.    @ 
4c50: 4e 6f 20 73 75 63 68 20 74 69 63 6b 65 74 3a 20  No such ticket: 
4c60: 25 68 28 7a 55 75 69 64 29 0a 20 20 20 20 73 74  %h(zUuid).    st
4c70: 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 20 20  yle_footer();.  
4c80: 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20    return;.  }.  
4c90: 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 0a 20  db_prepare(&q,. 
4ca0: 20 20 20 22 53 45 4c 45 43 54 20 6f 62 6a 69 64     "SELECT objid
4cb0: 2c 20 75 75 69 64 20 46 52 4f 4d 20 65 76 65 6e  , uuid FROM even
4cc0: 74 2c 20 62 6c 6f 62 22 0a 20 20 20 20 22 20 57  t, blob".    " W
4cd0: 48 45 52 45 20 6f 62 6a 69 64 20 49 4e 20 28 53  HERE objid IN (S
4ce0: 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d 20 74  ELECT rid FROM t
4cf0: 61 67 78 72 65 66 20 57 48 45 52 45 20 74 61 67  agxref WHERE tag
4d00: 69 64 3d 25 64 29 22 0a 20 20 20 20 22 20 20 20  id=%d)".    "   
4d10: 41 4e 44 20 62 6c 6f 62 2e 72 69 64 3d 65 76 65  AND blob.rid=eve
4d20: 6e 74 2e 6f 62 6a 69 64 22 0a 20 20 20 20 22 20  nt.objid".    " 
4d30: 4f 52 44 45 52 20 42 59 20 6d 74 69 6d 65 20 44  ORDER BY mtime D
4d40: 45 53 43 22 2c 0a 20 20 20 20 74 61 67 69 64 0a  ESC",.    tagid.
4d50: 20 20 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62    );.  while( db
4d60: 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54  _step(&q)==SQLIT
4d70: 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 42 6c 6f  E_ROW ){.    Blo
4d80: 62 20 63 6f 6e 74 65 6e 74 3b 0a 20 20 20 20 4d  b content;.    M
4d90: 61 6e 69 66 65 73 74 20 6d 3b 0a 20 20 20 20 69  anifest m;.    i
4da0: 6e 74 20 72 69 64 20 3d 20 64 62 5f 63 6f 6c 75  nt rid = db_colu
4db0: 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a 20  mn_int(&q, 0);. 
4dc0: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a     const char *z
4dd0: 43 68 6e 67 55 75 69 64 20 3d 20 64 62 5f 63 6f  ChngUuid = db_co
4de0: 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 31 29  lumn_text(&q, 1)
4df0: 3b 0a 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65  ;.    content_ge
4e00: 74 28 72 69 64 2c 20 26 63 6f 6e 74 65 6e 74 29  t(rid, &content)
4e10: 3b 0a 20 20 20 20 69 66 28 20 6d 61 6e 69 66 65  ;.    if( manife
4e20: 73 74 5f 70 61 72 73 65 28 26 6d 2c 20 26 63 6f  st_parse(&m, &co
4e30: 6e 74 65 6e 74 29 20 26 26 20 6d 2e 74 79 70 65  ntent) && m.type
4e40: 3d 3d 43 46 54 59 50 45 5f 54 49 43 4b 45 54 20  ==CFTYPE_TICKET 
4e50: 29 7b 0a 20 20 20 20 20 20 63 68 61 72 20 2a 7a  ){.      char *z
4e60: 44 61 74 65 20 3d 20 64 62 5f 74 65 78 74 28 30  Date = db_text(0
4e70: 2c 20 22 53 45 4c 45 43 54 20 64 61 74 65 74 69  , "SELECT dateti
4e80: 6d 65 28 25 2e 31 32 66 29 22 2c 20 6d 2e 72 44  me(%.12f)", m.rD
4e90: 61 74 65 29 3b 0a 20 20 20 20 20 20 63 68 61 72  ate);.      char
4ea0: 20 7a 55 75 69 64 5b 31 32 5d 3b 0a 20 20 20 20   zUuid[12];.    
4eb0: 20 20 6d 65 6d 63 70 79 28 7a 55 75 69 64 2c 20    memcpy(zUuid, 
4ec0: 7a 43 68 6e 67 55 75 69 64 2c 20 31 30 29 3b 0a  zChngUuid, 10);.
4ed0: 20 20 20 20 20 20 7a 55 75 69 64 5b 31 30 5d 20        zUuid[10] 
4ee0: 3d 20 30 3b 0a 20 20 20 20 20 20 40 0a 20 20 20  = 0;.      @.   
4ef0: 20 20 20 40 20 54 69 63 6b 65 74 20 63 68 61 6e     @ Ticket chan
4f00: 67 65 0a 20 20 20 20 20 20 40 20 5b 3c 61 20 68  ge.      @ [<a h
4f10: 72 65 66 3d 22 25 73 28 67 2e 7a 54 6f 70 29 2f  ref="%s(g.zTop)/
4f20: 61 72 74 69 66 61 63 74 2f 25 54 28 7a 43 68 6e  artifact/%T(zChn
4f30: 67 55 75 69 64 29 22 3e 25 73 28 7a 55 75 69 64  gUuid)">%s(zUuid
4f40: 29 3c 2f 61 3e 5d 3c 2f 61 3e 0a 20 20 20 20 20  )</a>]</a>.     
4f50: 20 40 20 28 72 69 64 20 25 64 28 72 69 64 29 29   @ (rid %d(rid))
4f60: 20 62 79 0a 20 20 20 20 20 20 68 79 70 65 72 6c   by.      hyperl
4f70: 69 6e 6b 5f 74 6f 5f 75 73 65 72 28 6d 2e 7a 55  ink_to_user(m.zU
4f80: 73 65 72 2c 7a 44 61 74 65 2c 22 20 6f 6e 22 29  ser,zDate," on")
4f90: 3b 0a 20 20 20 20 20 20 68 79 70 65 72 6c 69 6e  ;.      hyperlin
4fa0: 6b 5f 74 6f 5f 64 61 74 65 28 7a 44 61 74 65 2c  k_to_date(zDate,
4fb0: 20 22 3a 22 29 3b 0a 20 20 20 20 20 20 66 72 65   ":");.      fre
4fc0: 65 28 7a 44 61 74 65 29 3b 0a 20 20 20 20 20 20  e(zDate);.      
4fd0: 74 69 63 6b 65 74 5f 6f 75 74 70 75 74 5f 63 68  ticket_output_ch
4fe0: 61 6e 67 65 5f 61 72 74 69 66 61 63 74 28 26 6d  ange_artifact(&m
4ff0: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6d 61 6e  );.    }.    man
5000: 69 66 65 73 74 5f 63 6c 65 61 72 28 26 6d 29 3b  ifest_clear(&m);
5010: 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69  .  }.  db_finali
5020: 7a 65 28 26 71 29 3b 0a 20 20 73 74 79 6c 65 5f  ze(&q);.  style_
5030: 66 6f 6f 74 65 72 28 29 3b 0a 7d 0a 0a 2f 2a 0a  footer();.}../*.
5040: 2a 2a 20 52 65 74 75 72 6e 20 54 52 55 45 20 69  ** Return TRUE i
5050: 66 20 74 68 65 20 67 69 76 65 6e 20 42 4c 4f 42  f the given BLOB
5060: 20 63 6f 6e 74 61 69 6e 73 20 61 20 6e 65 77 6c   contains a newl
5070: 69 6e 65 20 63 68 61 72 61 63 74 65 72 2e 0a 2a  ine character..*
5080: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 63 6f 6e  /.static int con
5090: 74 61 69 6e 73 5f 6e 65 77 6c 69 6e 65 28 42 6c  tains_newline(Bl
50a0: 6f 62 20 2a 70 29 7b 0a 20 20 63 6f 6e 73 74 20  ob *p){.  const 
50b0: 63 68 61 72 20 2a 7a 20 3d 20 62 6c 6f 62 5f 73  char *z = blob_s
50c0: 74 72 28 70 29 3b 0a 20 20 77 68 69 6c 65 28 20  tr(p);.  while( 
50d0: 2a 7a 20 29 7b 0a 20 20 20 20 69 66 28 20 2a 7a  *z ){.    if( *z
50e0: 3d 3d 27 5c 6e 27 20 29 20 72 65 74 75 72 6e 20  =='\n' ) return 
50f0: 31 3b 0a 20 20 20 20 7a 2b 2b 3b 0a 20 20 7d 0a  1;.    z++;.  }.
5100: 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a 2f    return 0;.}../
5110: 2a 0a 2a 2a 20 54 68 65 20 70 54 6b 74 20 6f 62  *.** The pTkt ob
5120: 6a 65 63 74 20 69 73 20 61 20 74 69 63 6b 65 74  ject is a ticket
5130: 20 63 68 61 6e 67 65 20 61 72 74 69 66 61 63 74   change artifact
5140: 2e 20 20 4f 75 74 70 75 74 20 61 20 64 65 74 61  .  Output a deta
5150: 69 6c 65 64 0a 2a 2a 20 64 65 73 63 72 69 70 74  iled.** descript
5160: 69 6f 6e 20 6f 66 20 74 68 69 73 20 6f 62 6a 65  ion of this obje
5170: 63 74 2e 0a 2a 2f 0a 76 6f 69 64 20 74 69 63 6b  ct..*/.void tick
5180: 65 74 5f 6f 75 74 70 75 74 5f 63 68 61 6e 67 65  et_output_change
5190: 5f 61 72 74 69 66 61 63 74 28 4d 61 6e 69 66 65  _artifact(Manife
51a0: 73 74 20 2a 70 54 6b 74 29 7b 0a 20 20 69 6e 74  st *pTkt){.  int
51b0: 20 69 3b 0a 20 20 40 20 3c 6f 6c 3e 0a 20 20 66   i;.  @ <ol>.  f
51c0: 6f 72 28 69 3d 30 3b 20 69 3c 70 54 6b 74 2d 3e  or(i=0; i<pTkt->
51d0: 6e 46 69 65 6c 64 3b 20 69 2b 2b 29 7b 0a 20 20  nField; i++){.  
51e0: 20 20 42 6c 6f 62 20 76 61 6c 3b 0a 20 20 20 20    Blob val;.    
51f0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 3b 0a 20  const char *z;. 
5200: 20 20 20 7a 20 3d 20 70 54 6b 74 2d 3e 61 46 69     z = pTkt->aFi
5210: 65 6c 64 5b 69 5d 2e 7a 4e 61 6d 65 3b 0a 20 20  eld[i].zName;.  
5220: 20 20 62 6c 6f 62 5f 73 65 74 28 26 76 61 6c 2c    blob_set(&val,
5230: 20 70 54 6b 74 2d 3e 61 46 69 65 6c 64 5b 69 5d   pTkt->aField[i]
5240: 2e 7a 56 61 6c 75 65 29 3b 0a 20 20 20 20 69 66  .zValue);.    if
5250: 28 20 7a 5b 30 5d 3d 3d 27 2b 27 20 29 7b 0a 20  ( z[0]=='+' ){. 
5260: 20 20 20 20 20 40 20 3c 6c 69 3e 41 70 70 65 6e       @ <li>Appen
5270: 64 65 64 20 74 6f 20 25 68 28 26 7a 5b 31 5d 29  ded to %h(&z[1])
5280: 3a 3c 62 6c 6f 63 6b 71 75 6f 74 65 3e 0a 20 20  :<blockquote>.  
5290: 20 20 20 20 77 69 6b 69 5f 63 6f 6e 76 65 72 74      wiki_convert
52a0: 28 26 76 61 6c 2c 20 30 2c 20 30 29 3b 0a 20 20  (&val, 0, 0);.  
52b0: 20 20 20 20 40 20 3c 2f 62 6c 6f 63 6b 71 75 6f      @ </blockquo
52c0: 74 65 3e 3c 2f 6c 69 3e 0a 20 20 20 20 7d 65 6c  te></li>.    }el
52d0: 73 65 20 69 66 28 20 62 6c 6f 62 5f 73 69 7a 65  se if( blob_size
52e0: 28 26 76 61 6c 29 3c 3d 35 30 20 26 26 20 63 6f  (&val)<=50 && co
52f0: 6e 74 61 69 6e 73 5f 6e 65 77 6c 69 6e 65 28 26  ntains_newline(&
5300: 76 61 6c 29 20 29 7b 0a 20 20 20 20 20 20 40 20  val) ){.      @ 
5310: 3c 6c 69 3e 43 68 61 6e 67 65 20 25 68 28 7a 29  <li>Change %h(z)
5320: 20 74 6f 3a 3c 62 6c 6f 63 6b 71 75 6f 74 65 3e   to:<blockquote>
5330: 0a 20 20 20 20 20 20 77 69 6b 69 5f 63 6f 6e 76  .      wiki_conv
5340: 65 72 74 28 26 76 61 6c 2c 20 30 2c 20 30 29 3b  ert(&val, 0, 0);
5350: 0a 20 20 20 20 20 20 40 20 3c 2f 62 6c 6f 63 6b  .      @ </block
5360: 71 75 6f 74 65 3e 3c 2f 6c 69 3e 0a 20 20 20 20  quote></li>.    
5370: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 40 20 3c  }else{.      @ <
5380: 6c 69 3e 43 68 61 6e 67 65 20 25 68 28 7a 29 20  li>Change %h(z) 
5390: 74 6f 20 22 25 68 28 62 6c 6f 62 5f 73 74 72 28  to "%h(blob_str(
53a0: 26 76 61 6c 29 29 22 3c 2f 6c 69 3e 0a 20 20 20  &val))"</li>.   
53b0: 20 7d 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 65   }.    blob_rese
53c0: 74 28 26 76 61 6c 29 3b 0a 20 20 7d 0a 20 20 40  t(&val);.  }.  @
53d0: 20 3c 2f 6f 6c 3e 0a 7d 0a                        </ol>.}.