Hex Artifact Content
Not logged in

Artifact d23217d9bb4153367c721faed9083e2d9cbe1942:

File src/tkt.c part of check-in [2664476fbc] - Make sure the tkt_uuid and tkt_datetime TH1 variables are initialized on a ticket display, even if no matching ticket is found. by drh on 2008-11-09 13:22:41.

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: 4d 61 6e 69 66 65 73 74 20 2a 70 2c 20 69 6e 74  Manifest *p, int
16f0: 20 63 72 65 61 74 65 46 6c 61 67 2c 20 69 6e 74   createFlag, int
1700: 20 63 68 65 63 6b 54 69 6d 65 29 7b 0a 20 20 42   checkTime){.  B
1710: 6c 6f 62 20 73 71 6c 3b 0a 20 20 53 74 6d 74 20  lob sql;.  Stmt 
1720: 71 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 63 6f  q;.  int i;.  co
1730: 6e 73 74 20 63 68 61 72 20 2a 7a 53 65 70 3b 0a  nst char *zSep;.
1740: 20 20 69 6e 74 20 72 63 20 3d 20 30 3b 0a 0a 20    int rc = 0;.. 
1750: 20 67 65 74 41 6c 6c 54 69 63 6b 65 74 46 69 65   getAllTicketFie
1760: 6c 64 73 28 29 3b 0a 20 20 69 66 28 20 63 72 65  lds();.  if( cre
1770: 61 74 65 46 6c 61 67 20 29 7b 20 20 0a 20 20 20  ateFlag ){  .   
1780: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22   db_multi_exec("
1790: 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45  INSERT OR IGNORE
17a0: 20 49 4e 54 4f 20 74 69 63 6b 65 74 28 74 6b 74   INTO ticket(tkt
17b0: 5f 75 75 69 64 2c 20 74 6b 74 5f 6d 74 69 6d 65  _uuid, tkt_mtime
17c0: 29 20 22 0a 20 20 20 20 20 20 20 20 20 20 20 20  ) ".            
17d0: 20 20 20 20 20 20 22 56 41 4c 55 45 53 28 25 51        "VALUES(%Q
17e0: 2c 20 30 29 22 2c 20 70 2d 3e 7a 54 69 63 6b 65  , 0)", p->zTicke
17f0: 74 55 75 69 64 29 3b 0a 20 20 20 20 72 63 20 3d  tUuid);.    rc =
1800: 20 64 62 5f 63 68 61 6e 67 65 73 28 29 3b 0a 20   db_changes();. 
1810: 20 7d 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26   }.  blob_zero(&
1820: 73 71 6c 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70  sql);.  blob_app
1830: 65 6e 64 66 28 26 73 71 6c 2c 20 22 55 50 44 41  endf(&sql, "UPDA
1840: 54 45 20 4f 52 20 52 45 50 4c 41 43 45 20 74 69  TE OR REPLACE ti
1850: 63 6b 65 74 20 53 45 54 20 74 6b 74 5f 6d 74 69  cket SET tkt_mti
1860: 6d 65 3d 3a 6d 74 69 6d 65 22 29 3b 0a 20 20 7a  me=:mtime");.  z
1870: 53 65 70 20 3d 20 22 53 45 54 22 3b 0a 20 20 66  Sep = "SET";.  f
1880: 6f 72 28 69 3d 30 3b 20 69 3c 70 2d 3e 6e 46 69  or(i=0; i<p->nFi
1890: 65 6c 64 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 63  eld; i++){.    c
18a0: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65  onst char *zName
18b0: 20 3d 20 70 2d 3e 61 46 69 65 6c 64 5b 69 5d 2e   = p->aField[i].
18c0: 7a 4e 61 6d 65 3b 0a 20 20 20 20 69 66 28 20 7a  zName;.    if( z
18d0: 4e 61 6d 65 5b 30 5d 3d 3d 27 2b 27 20 29 7b 0a  Name[0]=='+' ){.
18e0: 20 20 20 20 20 20 7a 4e 61 6d 65 2b 2b 3b 0a 20        zName++;. 
18f0: 20 20 20 20 20 69 66 28 20 66 69 65 6c 64 49 64       if( fieldId
1900: 28 7a 4e 61 6d 65 29 3c 30 20 29 20 63 6f 6e 74  (zName)<0 ) cont
1910: 69 6e 75 65 3b 0a 20 20 20 20 20 20 62 6c 6f 62  inue;.      blob
1920: 5f 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 22 2c  _appendf(&sql,",
1930: 20 25 73 3d 25 73 20 7c 7c 20 25 51 22 2c 20 7a   %s=%s || %Q", z
1940: 4e 61 6d 65 2c 20 7a 4e 61 6d 65 2c 20 70 2d 3e  Name, zName, p->
1950: 61 46 69 65 6c 64 5b 69 5d 2e 7a 56 61 6c 75 65  aField[i].zValue
1960: 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20  );.    }else{.  
1970: 20 20 20 20 69 66 28 20 66 69 65 6c 64 49 64 28      if( fieldId(
1980: 7a 4e 61 6d 65 29 3c 30 20 29 20 63 6f 6e 74 69  zName)<0 ) conti
1990: 6e 75 65 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f  nue;.      blob_
19a0: 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 22 2c 20  appendf(&sql,", 
19b0: 25 73 3d 25 51 22 2c 20 7a 4e 61 6d 65 2c 20 70  %s=%Q", zName, p
19c0: 2d 3e 61 46 69 65 6c 64 5b 69 5d 2e 7a 56 61 6c  ->aField[i].zVal
19d0: 75 65 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20  ue);.    }.  }. 
19e0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73   blob_appendf(&s
19f0: 71 6c 2c 20 22 20 57 48 45 52 45 20 74 6b 74 5f  ql, " WHERE tkt_
1a00: 75 75 69 64 3d 27 25 73 27 20 41 4e 44 20 74 6b  uuid='%s' AND tk
1a10: 74 5f 6d 74 69 6d 65 3c 3a 6d 74 69 6d 65 22 2c  t_mtime<:mtime",
1a20: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
1a30: 20 20 20 20 20 20 70 2d 3e 7a 54 69 63 6b 65 74        p->zTicket
1a40: 55 75 69 64 29 3b 0a 20 20 64 62 5f 70 72 65 70  Uuid);.  db_prep
1a50: 61 72 65 28 26 71 2c 20 22 25 73 22 2c 20 62 6c  are(&q, "%s", bl
1a60: 6f 62 5f 73 74 72 28 26 73 71 6c 29 29 3b 0a 20  ob_str(&sql));. 
1a70: 20 64 62 5f 62 69 6e 64 5f 64 6f 75 62 6c 65 28   db_bind_double(
1a80: 26 71 2c 20 22 3a 6d 74 69 6d 65 22 2c 20 70 2d  &q, ":mtime", p-
1a90: 3e 72 44 61 74 65 29 3b 0a 20 20 64 62 5f 73 74  >rDate);.  db_st
1aa0: 65 70 28 26 71 29 3b 0a 20 20 64 62 5f 66 69 6e  ep(&q);.  db_fin
1ab0: 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 69 66 28  alize(&q);.  if(
1ac0: 20 63 68 65 63 6b 54 69 6d 65 20 26 26 20 64 62   checkTime && db
1ad0: 5f 63 68 61 6e 67 65 73 28 29 3d 3d 30 20 29 7b  _changes()==0 ){
1ae0: 0a 20 20 20 20 73 74 61 74 69 63 20 69 6e 74 20  .    static int 
1af0: 69 73 49 6e 69 74 20 3d 20 30 3b 0a 20 20 20 20  isInit = 0;.    
1b00: 69 66 28 20 21 69 73 49 6e 69 74 20 29 7b 0a 20  if( !isInit ){. 
1b10: 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78       db_multi_ex
1b20: 65 63 28 22 43 52 45 41 54 45 20 54 45 4d 50 20  ec("CREATE TEMP 
1b30: 54 41 42 4c 45 20 5f 70 65 6e 64 69 6e 67 5f 74  TABLE _pending_t
1b40: 69 63 6b 65 74 28 75 75 69 64 20 54 45 58 54 20  icket(uuid TEXT 
1b50: 55 4e 49 51 55 45 29 22 29 3b 0a 20 20 20 20 20  UNIQUE)");.     
1b60: 20 64 62 5f 63 6f 6d 6d 69 74 5f 68 6f 6f 6b 28   db_commit_hook(
1b70: 74 69 63 6b 65 74 5f 72 65 62 75 69 6c 64 5f 61  ticket_rebuild_a
1b80: 74 5f 63 6f 6d 6d 69 74 2c 20 31 29 3b 0a 20 20  t_commit, 1);.  
1b90: 20 20 20 20 69 73 49 6e 69 74 20 3d 20 31 3b 0a      isInit = 1;.
1ba0: 20 20 20 20 7d 0a 20 20 20 20 64 62 5f 6d 75 6c      }.    db_mul
1bb0: 74 69 5f 65 78 65 63 28 22 49 4e 53 45 52 54 20  ti_exec("INSERT 
1bc0: 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 5f  OR IGNORE INTO _
1bd0: 70 65 6e 64 69 6e 67 5f 74 69 63 6b 65 74 20 22  pending_ticket "
1be0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
1bf0: 20 20 20 22 56 41 4c 55 45 53 28 25 51 29 22 2c     "VALUES(%Q)",
1c00: 20 70 2d 3e 7a 54 69 63 6b 65 74 55 75 69 64 29   p->zTicketUuid)
1c10: 3b 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 72 65 73  ;.  }.  blob_res
1c20: 65 74 28 26 73 71 6c 29 3b 0a 20 20 72 65 74 75  et(&sql);.  retu
1c30: 72 6e 20 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  rn rc;.}../*.** 
1c40: 52 65 62 75 69 6c 64 20 61 6e 20 65 6e 74 69 72  Rebuild an entir
1c50: 65 20 65 6e 74 72 79 20 69 6e 20 74 68 65 20 54  e entry in the T
1c60: 49 43 4b 45 54 20 74 61 62 6c 65 0a 2a 2f 0a 76  ICKET table.*/.v
1c70: 6f 69 64 20 74 69 63 6b 65 74 5f 72 65 62 75 69  oid ticket_rebui
1c80: 6c 64 5f 65 6e 74 72 79 28 63 6f 6e 73 74 20 63  ld_entry(const c
1c90: 68 61 72 20 2a 7a 54 6b 74 55 75 69 64 29 7b 0a  har *zTktUuid){.
1ca0: 20 20 63 68 61 72 20 2a 7a 54 61 67 20 3d 20 6d    char *zTag = m
1cb0: 70 72 69 6e 74 66 28 22 74 6b 74 2d 25 73 22 2c  printf("tkt-%s",
1cc0: 20 7a 54 6b 74 55 75 69 64 29 3b 0a 20 20 69 6e   zTktUuid);.  in
1cd0: 74 20 74 61 67 69 64 20 3d 20 74 61 67 5f 66 69  t tagid = tag_fi
1ce0: 6e 64 69 64 28 7a 54 61 67 2c 20 31 29 3b 0a 20  ndid(zTag, 1);. 
1cf0: 20 53 74 6d 74 20 71 3b 0a 20 20 4d 61 6e 69 66   Stmt q;.  Manif
1d00: 65 73 74 20 6d 61 6e 69 66 65 73 74 3b 0a 20 20  est manifest;.  
1d10: 42 6c 6f 62 20 63 6f 6e 74 65 6e 74 3b 0a 20 20  Blob content;.  
1d20: 69 6e 74 20 63 72 65 61 74 65 46 6c 61 67 20 3d  int createFlag =
1d30: 20 31 3b 0a 20 20 0a 20 20 64 62 5f 6d 75 6c 74   1;.  .  db_mult
1d40: 69 5f 65 78 65 63 28 0a 20 20 20 20 20 22 44 45  i_exec(.     "DE
1d50: 4c 45 54 45 20 46 52 4f 4d 20 74 69 63 6b 65 74  LETE FROM ticket
1d60: 20 57 48 45 52 45 20 74 6b 74 5f 75 75 69 64 3d   WHERE tkt_uuid=
1d70: 25 51 22 2c 20 7a 54 6b 74 55 75 69 64 0a 20 20  %Q", zTktUuid.  
1d80: 29 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28  );.  db_prepare(
1d90: 26 71 2c 20 22 53 45 4c 45 43 54 20 72 69 64 20  &q, "SELECT rid 
1da0: 46 52 4f 4d 20 74 61 67 78 72 65 66 20 57 48 45  FROM tagxref WHE
1db0: 52 45 20 74 61 67 69 64 3d 25 64 20 4f 52 44 45  RE tagid=%d ORDE
1dc0: 52 20 42 59 20 6d 74 69 6d 65 22 2c 74 61 67 69  R BY mtime",tagi
1dd0: 64 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 5f  d);.  while( db_
1de0: 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45  step(&q)==SQLITE
1df0: 5f 52 4f 57 20 29 7b 0a 20 20 20 20 69 6e 74 20  _ROW ){.    int 
1e00: 72 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f  rid = db_column_
1e10: 69 6e 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20  int(&q, 0);.    
1e20: 63 6f 6e 74 65 6e 74 5f 67 65 74 28 72 69 64 2c  content_get(rid,
1e30: 20 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20   &content);.    
1e40: 6d 61 6e 69 66 65 73 74 5f 70 61 72 73 65 28 26  manifest_parse(&
1e50: 6d 61 6e 69 66 65 73 74 2c 20 26 63 6f 6e 74 65  manifest, &conte
1e60: 6e 74 29 3b 0a 20 20 20 20 74 69 63 6b 65 74 5f  nt);.    ticket_
1e70: 69 6e 73 65 72 74 28 26 6d 61 6e 69 66 65 73 74  insert(&manifest
1e80: 2c 20 63 72 65 61 74 65 46 6c 61 67 2c 20 30 29  , createFlag, 0)
1e90: 3b 0a 20 20 20 20 6d 61 6e 69 66 65 73 74 5f 63  ;.    manifest_c
1ea0: 6c 65 61 72 28 26 6d 61 6e 69 66 65 73 74 29 3b  lear(&manifest);
1eb0: 0a 20 20 20 20 63 72 65 61 74 65 46 6c 61 67 20  .    createFlag 
1ec0: 3d 20 30 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69  = 0;.  }.  db_fi
1ed0: 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f  nalize(&q);.}../
1ee0: 2a 0a 2a 2a 20 43 72 65 61 74 65 20 74 68 65 20  *.** Create the 
1ef0: 73 75 62 73 63 72 69 70 74 20 69 6e 74 65 72 70  subscript interp
1f00: 72 65 74 65 72 20 61 6e 64 20 6c 6f 61 64 20 74  reter and load t
1f10: 68 65 20 22 63 6f 6d 6d 6f 6e 22 20 63 6f 64 65  he "common" code
1f20: 2e 0a 2a 2f 0a 76 6f 69 64 20 74 69 63 6b 65 74  ..*/.void ticket
1f30: 5f 69 6e 69 74 28 76 6f 69 64 29 7b 0a 20 20 63  _init(void){.  c
1f40: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 6f 6e 66  onst char *zConf
1f50: 69 67 3b 0a 20 20 54 68 5f 46 6f 73 73 69 6c 49  ig;.  Th_FossilI
1f60: 6e 69 74 28 29 3b 0a 20 20 7a 43 6f 6e 66 69 67  nit();.  zConfig
1f70: 20 3d 20 74 69 63 6b 65 74 5f 63 6f 6d 6d 6f 6e   = ticket_common
1f80: 5f 63 6f 64 65 28 29 3b 0a 20 20 54 68 5f 45 76  _code();.  Th_Ev
1f90: 61 6c 28 67 2e 69 6e 74 65 72 70 2c 20 30 2c 20  al(g.interp, 0, 
1fa0: 7a 43 6f 6e 66 69 67 2c 20 2d 31 29 3b 0a 7d 0a  zConfig, -1);.}.
1fb0: 0a 2f 2a 0a 2a 2a 20 52 65 63 72 65 61 74 65 20  ./*.** Recreate 
1fc0: 74 68 65 20 74 69 63 6b 65 74 20 74 61 62 6c 65  the ticket table
1fd0: 2e 0a 2a 2f 0a 76 6f 69 64 20 74 69 63 6b 65 74  ..*/.void ticket
1fe0: 5f 63 72 65 61 74 65 5f 74 61 62 6c 65 28 69 6e  _create_table(in
1ff0: 74 20 73 65 70 61 72 61 74 65 43 6f 6e 6e 65 63  t separateConnec
2000: 74 69 6f 6e 29 7b 0a 20 20 63 6f 6e 73 74 20 63  tion){.  const c
2010: 68 61 72 20 2a 7a 53 71 6c 3b 0a 0a 20 20 64 62  har *zSql;..  db
2020: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 52 4f  _multi_exec("DRO
2030: 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54  P TABLE IF EXIST
2040: 53 20 74 69 63 6b 65 74 3b 22 29 3b 0a 20 20 7a  S ticket;");.  z
2050: 53 71 6c 20 3d 20 74 69 63 6b 65 74 5f 74 61 62  Sql = ticket_tab
2060: 6c 65 5f 73 63 68 65 6d 61 28 29 3b 0a 20 20 69  le_schema();.  i
2070: 66 28 20 73 65 70 61 72 61 74 65 43 6f 6e 6e 65  f( separateConne
2080: 63 74 69 6f 6e 20 29 7b 0a 20 20 20 20 64 62 5f  ction ){.    db_
2090: 69 6e 69 74 5f 64 61 74 61 62 61 73 65 28 67 2e  init_database(g.
20a0: 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c  zRepositoryName,
20b0: 20 7a 53 71 6c 2c 20 30 29 3b 0a 20 20 7d 65 6c   zSql, 0);.  }el
20c0: 73 65 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69  se{.    db_multi
20d0: 5f 65 78 65 63 28 22 25 73 22 2c 20 7a 53 71 6c  _exec("%s", zSql
20e0: 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  );.  }.}../*.** 
20f0: 52 65 70 6f 70 75 6c 61 74 65 20 74 68 65 20 74  Repopulate the t
2100: 69 63 6b 65 74 20 74 61 62 6c 65 0a 2a 2f 0a 76  icket table.*/.v
2110: 6f 69 64 20 74 69 63 6b 65 74 5f 72 65 62 75 69  oid ticket_rebui
2120: 6c 64 28 76 6f 69 64 29 7b 0a 20 20 53 74 6d 74  ld(void){.  Stmt
2130: 20 71 3b 0a 20 20 74 69 63 6b 65 74 5f 63 72 65   q;.  ticket_cre
2140: 61 74 65 5f 74 61 62 6c 65 28 31 29 3b 0a 20 20  ate_table(1);.  
2150: 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63  db_begin_transac
2160: 74 69 6f 6e 28 29 3b 0a 20 20 64 62 5f 70 72 65  tion();.  db_pre
2170: 70 61 72 65 28 26 71 2c 22 53 45 4c 45 43 54 20  pare(&q,"SELECT 
2180: 74 61 67 6e 61 6d 65 20 46 52 4f 4d 20 74 61 67  tagname FROM tag
2190: 20 57 48 45 52 45 20 74 61 67 6e 61 6d 65 20 47   WHERE tagname G
21a0: 4c 4f 42 20 27 74 6b 74 2d 2a 27 22 29 3b 0a 20  LOB 'tkt-*'");. 
21b0: 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28   while( db_step(
21c0: 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20  &q)==SQLITE_ROW 
21d0: 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61  ){.    const cha
21e0: 72 20 2a 7a 4e 61 6d 65 20 3d 20 64 62 5f 63 6f  r *zName = db_co
21f0: 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29  lumn_text(&q, 0)
2200: 3b 0a 20 20 20 20 69 6e 74 20 6c 65 6e 3b 0a 20  ;.    int len;. 
2210: 20 20 20 7a 4e 61 6d 65 20 2b 3d 20 34 3b 0a 20     zName += 4;. 
2220: 20 20 20 6c 65 6e 20 3d 20 73 74 72 6c 65 6e 28     len = strlen(
2230: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 69 66 28 20  zName);.    if( 
2240: 6c 65 6e 3c 32 30 20 7c 7c 20 21 76 61 6c 69 64  len<20 || !valid
2250: 61 74 65 31 36 28 7a 4e 61 6d 65 2c 20 6c 65 6e  ate16(zName, len
2260: 29 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20  ) ) continue;.  
2270: 20 20 74 69 63 6b 65 74 5f 72 65 62 75 69 6c 64    ticket_rebuild
2280: 5f 65 6e 74 72 79 28 7a 4e 61 6d 65 29 3b 0a 20  _entry(zName);. 
2290: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65   }.  db_finalize
22a0: 28 26 71 29 3b 0a 20 20 64 62 5f 65 6e 64 5f 74  (&q);.  db_end_t
22b0: 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a 7d  ransaction(0);.}
22c0: 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50 41 47 45 3a  ../*.** WEBPAGE:
22d0: 20 74 6b 74 76 69 65 77 0a 2a 2a 20 55 52 4c 3a   tktview.** URL:
22e0: 20 20 74 6b 74 76 69 65 77 3f 6e 61 6d 65 3d 55    tktview?name=U
22f0: 55 49 44 0a 2a 2a 0a 2a 2a 20 56 69 65 77 20 61  UID.**.** View a
2300: 20 74 69 63 6b 65 74 2e 0a 2a 2f 0a 76 6f 69 64   ticket..*/.void
2310: 20 74 6b 74 76 69 65 77 5f 70 61 67 65 28 76 6f   tktview_page(vo
2320: 69 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61  id){.  const cha
2330: 72 20 2a 7a 53 63 72 69 70 74 3b 0a 20 20 6c 6f  r *zScript;.  lo
2340: 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e  gin_check_creden
2350: 74 69 61 6c 73 28 29 3b 0a 20 20 69 66 28 20 21  tials();.  if( !
2360: 67 2e 6f 6b 52 64 54 6b 74 20 29 7b 20 6c 6f 67  g.okRdTkt ){ log
2370: 69 6e 5f 6e 65 65 64 65 64 28 29 3b 20 72 65 74  in_needed(); ret
2380: 75 72 6e 3b 20 7d 0a 20 20 69 66 28 20 67 2e 6f  urn; }.  if( g.o
2390: 6b 57 72 54 6b 74 20 29 7b 0a 20 20 20 20 73 74  kWrTkt ){.    st
23a0: 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d  yle_submenu_elem
23b0: 65 6e 74 28 22 45 64 69 74 22 2c 20 22 45 64 69  ent("Edit", "Edi
23c0: 74 20 54 68 65 20 54 69 63 6b 65 74 22 2c 20 22  t The Ticket", "
23d0: 25 73 2f 74 6b 74 65 64 69 74 3f 6e 61 6d 65 3d  %s/tktedit?name=
23e0: 25 54 22 2c 0a 20 20 20 20 20 20 20 20 67 2e 7a  %T",.        g.z
23f0: 54 6f 70 2c 20 50 44 28 22 6e 61 6d 65 22 2c 22  Top, PD("name","
2400: 22 29 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 67  "));.  }.  if( g
2410: 2e 6f 6b 48 69 73 74 6f 72 79 20 29 7b 0a 20 20  .okHistory ){.  
2420: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 55    const char *zU
2430: 75 69 64 20 3d 20 50 44 28 22 6e 61 6d 65 22 2c  uid = PD("name",
2440: 22 22 29 3b 0a 20 20 20 20 73 74 79 6c 65 5f 73  "");.    style_s
2450: 75 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 22  ubmenu_element("
2460: 48 69 73 74 6f 72 79 22 2c 20 22 48 69 73 74 6f  History", "Histo
2470: 72 79 20 4f 66 20 54 68 69 73 20 54 69 63 6b 65  ry Of This Ticke
2480: 74 22 2c 20 0a 20 20 20 20 20 20 20 20 22 25 73  t", .        "%s
2490: 2f 74 6b 74 68 69 73 74 6f 72 79 2f 25 54 22 2c  /tkthistory/%T",
24a0: 20 67 2e 7a 54 6f 70 2c 20 7a 55 75 69 64 29 3b   g.zTop, zUuid);
24b0: 0a 20 20 20 20 73 74 79 6c 65 5f 73 75 62 6d 65  .    style_subme
24c0: 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 54 69 6d 65  nu_element("Time
24d0: 6c 69 6e 65 22 2c 20 22 54 69 6d 65 6c 69 6e 65  line", "Timeline
24e0: 20 4f 66 20 54 68 69 73 20 54 69 63 6b 65 74 22   Of This Ticket"
24f0: 2c 20 0a 20 20 20 20 20 20 20 20 22 25 73 2f 74  , .        "%s/t
2500: 6b 74 74 69 6d 65 6c 69 6e 65 2f 25 54 22 2c 20  kttimeline/%T", 
2510: 67 2e 7a 54 6f 70 2c 20 7a 55 75 69 64 29 3b 0a  g.zTop, zUuid);.
2520: 20 20 7d 0a 20 20 73 74 79 6c 65 5f 68 65 61 64    }.  style_head
2530: 65 72 28 22 56 69 65 77 20 54 69 63 6b 65 74 22  er("View Ticket"
2540: 29 3b 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61  );.  if( g.thTra
2550: 63 65 20 29 20 54 68 5f 54 72 61 63 65 28 22 42  ce ) Th_Trace("B
2560: 45 47 49 4e 5f 54 4b 54 56 49 45 57 3c 62 72 20  EGIN_TKTVIEW<br 
2570: 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a 20 20 74 69  />\n", -1);.  ti
2580: 63 6b 65 74 5f 69 6e 69 74 28 29 3b 0a 20 20 69  cket_init();.  i
2590: 6e 69 74 69 61 6c 69 7a 65 56 61 72 69 61 62 6c  nitializeVariabl
25a0: 65 73 46 72 6f 6d 44 62 28 29 3b 0a 20 20 7a 53  esFromDb();.  zS
25b0: 63 72 69 70 74 20 3d 20 74 69 63 6b 65 74 5f 76  cript = ticket_v
25c0: 69 65 77 70 61 67 65 5f 63 6f 64 65 28 29 3b 0a  iewpage_code();.
25d0: 20 20 69 66 28 20 67 2e 74 68 54 72 61 63 65 20    if( g.thTrace 
25e0: 29 20 54 68 5f 54 72 61 63 65 28 22 42 45 47 49  ) Th_Trace("BEGI
25f0: 4e 5f 54 4b 54 56 49 45 57 5f 53 43 52 49 50 54  N_TKTVIEW_SCRIPT
2600: 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a  <br />\n", -1);.
2610: 20 20 54 68 5f 52 65 6e 64 65 72 28 7a 53 63 72    Th_Render(zScr
2620: 69 70 74 29 3b 0a 20 20 69 66 28 20 67 2e 74 68  ipt);.  if( g.th
2630: 54 72 61 63 65 20 29 20 54 68 5f 54 72 61 63 65  Trace ) Th_Trace
2640: 28 22 45 4e 44 5f 54 4b 54 56 49 45 57 3c 62 72  ("END_TKTVIEW<br
2650: 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a 20 20 73   />\n", -1);.  s
2660: 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 7d  tyle_footer();.}
2670: 0a 0a 2f 2a 0a 2a 2a 20 54 48 20 63 6f 6d 6d 61  ../*.** TH comma
2680: 6e 64 3a 20 20 20 61 70 70 65 6e 64 5f 66 69 65  nd:   append_fie
2690: 6c 64 20 46 49 45 4c 44 20 53 54 52 49 4e 47 0a  ld FIELD STRING.
26a0: 2a 2a 0a 2a 2a 20 46 49 45 4c 44 20 69 73 20 74  **.** FIELD is t
26b0: 68 65 20 6e 61 6d 65 20 6f 66 20 61 20 64 61 74  he name of a dat
26c0: 61 62 61 73 65 20 63 6f 6c 75 6d 6e 20 74 6f 20  abase column to 
26d0: 77 68 69 63 68 20 77 65 20 6d 69 67 68 74 20 77  which we might w
26e0: 61 6e 74 0a 2a 2a 20 74 6f 20 61 70 70 65 6e 64  ant.** to append
26f0: 20 74 65 78 74 2e 20 20 53 54 52 49 4e 47 20 69   text.  STRING i
2700: 73 20 74 68 65 20 74 65 78 74 20 74 6f 20 62 65  s the text to be
2710: 20 61 70 70 65 6e 64 65 64 20 74 6f 20 74 68 61   appended to tha
2720: 74 0a 2a 2a 20 63 6f 6c 75 6d 6e 2e 20 20 54 68  t.** column.  Th
2730: 65 20 61 70 70 65 6e 64 20 64 6f 65 73 20 6e 6f  e append does no
2740: 74 20 61 63 74 75 61 6c 6c 79 20 6f 63 63 75 72  t actually occur
2750: 20 75 6e 74 69 6c 20 74 68 65 0a 2a 2a 20 73 75   until the.** su
2760: 62 6d 69 74 5f 74 69 63 6b 65 74 20 63 6f 6d 6d  bmit_ticket comm
2770: 61 6e 64 20 69 73 20 72 75 6e 2e 0a 2a 2f 0a 73  and is run..*/.s
2780: 74 61 74 69 63 20 69 6e 74 20 61 70 70 65 6e 64  tatic int append
2790: 52 65 6d 61 72 6b 43 6d 64 28 0a 20 20 54 68 5f  RemarkCmd(.  Th_
27a0: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20  Interp *interp, 
27b0: 0a 20 20 76 6f 69 64 20 2a 70 2c 20 0a 20 20 69  .  void *p, .  i
27c0: 6e 74 20 61 72 67 63 2c 20 0a 20 20 63 6f 6e 73  nt argc, .  cons
27d0: 74 20 63 68 61 72 20 2a 2a 61 72 67 76 2c 20 0a  t char **argv, .
27e0: 20 20 69 6e 74 20 2a 61 72 67 6c 0a 29 7b 0a 20    int *argl.){. 
27f0: 20 69 6e 74 20 69 64 78 3b 0a 0a 20 20 69 66 28   int idx;..  if(
2800: 20 61 72 67 63 21 3d 33 20 29 7b 0a 20 20 20 20   argc!=3 ){.    
2810: 72 65 74 75 72 6e 20 54 68 5f 57 72 6f 6e 67 4e  return Th_WrongN
2820: 75 6d 41 72 67 73 28 69 6e 74 65 72 70 2c 20 22  umArgs(interp, "
2830: 61 70 70 65 6e 64 5f 66 69 65 6c 64 20 46 49 45  append_field FIE
2840: 4c 44 20 53 54 52 49 4e 47 22 29 3b 0a 20 20 7d  LD STRING");.  }
2850: 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61 63 65  .  if( g.thTrace
2860: 20 29 7b 0a 20 20 20 20 54 68 5f 54 72 61 63 65   ){.    Th_Trace
2870: 28 22 61 70 70 65 6e 64 5f 66 69 65 6c 64 20 25  ("append_field %
2880: 23 68 20 7b 25 23 68 7d 3c 62 72 20 2f 3e 5c 6e  #h {%#h}<br />\n
2890: 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  ",.             
28a0: 20 61 72 67 6c 5b 31 5d 2c 20 61 72 67 76 5b 31   argl[1], argv[1
28b0: 5d 2c 20 61 72 67 6c 5b 32 5d 2c 20 61 72 67 76  ], argl[2], argv
28c0: 5b 32 5d 29 3b 0a 20 20 7d 0a 20 20 66 6f 72 28  [2]);.  }.  for(
28d0: 69 64 78 3d 30 3b 20 69 64 78 3c 6e 46 69 65 6c  idx=0; idx<nFiel
28e0: 64 3b 20 69 64 78 2b 2b 29 7b 0a 20 20 20 20 69  d; idx++){.    i
28f0: 66 28 20 73 74 72 6e 63 6d 70 28 61 7a 46 69 65  f( strncmp(azFie
2900: 6c 64 5b 69 64 78 5d 2c 20 61 72 67 76 5b 31 5d  ld[idx], argv[1]
2910: 2c 20 61 72 67 6c 5b 31 5d 29 3d 3d 30 0a 20 20  , argl[1])==0.  
2920: 20 20 20 20 20 20 26 26 20 61 7a 46 69 65 6c 64        && azField
2930: 5b 69 64 78 5d 5b 61 72 67 6c 5b 31 5d 5d 3d 3d  [idx][argl[1]]==
2940: 30 20 29 7b 0a 20 20 20 20 20 20 62 72 65 61 6b  0 ){.      break
2950: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66  ;.    }.  }.  if
2960: 28 20 69 64 78 3e 3d 6e 46 69 65 6c 64 20 29 7b  ( idx>=nField ){
2970: 0a 20 20 20 20 54 68 5f 45 72 72 6f 72 4d 65 73  .    Th_ErrorMes
2980: 73 61 67 65 28 67 2e 69 6e 74 65 72 70 2c 20 22  sage(g.interp, "
2990: 6e 6f 20 73 75 63 68 20 54 49 43 4b 45 54 20 63  no such TICKET c
29a0: 6f 6c 75 6d 6e 3a 20 22 2c 20 61 72 67 76 5b 31  olumn: ", argv[1
29b0: 5d 2c 20 61 72 67 6c 5b 31 5d 29 3b 0a 20 20 20  ], argl[1]);.   
29c0: 20 72 65 74 75 72 6e 20 54 48 5f 45 52 52 4f 52   return TH_ERROR
29d0: 3b 0a 20 20 7d 0a 20 20 61 7a 41 70 70 65 6e 64  ;.  }.  azAppend
29e0: 5b 69 64 78 5d 20 3d 20 6d 70 72 69 6e 74 66 28  [idx] = mprintf(
29f0: 22 25 2e 2a 73 22 2c 20 61 72 67 6c 5b 32 5d 2c  "%.*s", argl[2],
2a00: 20 61 72 67 76 5b 32 5d 29 3b 0a 20 20 72 65 74   argv[2]);.  ret
2a10: 75 72 6e 20 54 48 5f 4f 4b 3b 0a 7d 0a 0a 2f 2a  urn TH_OK;.}../*
2a20: 0a 2a 2a 20 53 75 62 73 63 72 69 70 74 20 63 6f  .** Subscript co
2a30: 6d 6d 61 6e 64 3a 20 20 20 73 75 62 6d 69 74 5f  mmand:   submit_
2a40: 74 69 63 6b 65 74 0a 2a 2a 0a 2a 2a 20 43 6f 6e  ticket.**.** Con
2a50: 73 74 72 75 63 74 20 61 6e 64 20 73 75 62 6d 69  struct and submi
2a60: 74 20 61 20 6e 65 77 20 74 69 63 6b 65 74 20 61  t a new ticket a
2a70: 72 74 69 66 61 63 74 2e 20 20 54 68 65 20 66 69  rtifact.  The fi
2a80: 65 6c 64 73 20 6f 66 20 74 68 65 20 61 72 74 69  elds of the arti
2a90: 66 61 63 74 0a 2a 2a 20 61 72 65 20 74 68 65 20  fact.** are the 
2aa0: 6e 61 6d 65 73 20 6f 66 20 74 68 65 20 63 6f 6c  names of the col
2ab0: 75 6d 6e 73 20 69 6e 20 74 68 65 20 54 49 43 4b  umns in the TICK
2ac0: 45 54 20 74 61 62 6c 65 2e 20 20 54 68 65 20 63  ET table.  The c
2ad0: 6f 6e 74 65 6e 74 20 69 73 0a 2a 2a 20 74 61 6b  ontent is.** tak
2ae0: 65 6e 20 66 72 6f 6d 20 54 48 20 76 61 72 69 61  en from TH varia
2af0: 62 6c 65 73 2e 20 20 49 66 20 74 68 65 20 63 6f  bles.  If the co
2b00: 6e 74 65 6e 74 20 69 73 20 75 6e 63 68 61 6e 67  ntent is unchang
2b10: 65 64 2c 20 74 68 65 20 66 69 65 6c 64 20 69 73  ed, the field is
2b20: 0a 2a 2a 20 6f 6d 69 74 74 65 64 20 66 72 6f 6d  .** omitted from
2b30: 20 74 68 65 20 61 72 74 69 66 61 63 74 2e 20 20   the artifact.  
2b40: 46 69 65 6c 64 73 20 77 68 6f 73 65 20 6e 61 6d  Fields whose nam
2b50: 65 73 20 62 65 67 69 6e 20 77 69 74 68 20 22 70  es begin with "p
2b60: 72 69 76 61 74 65 5f 22 0a 2a 2a 20 61 72 65 20  rivate_".** are 
2b70: 63 6f 6e 63 65 61 6c 65 64 20 75 73 69 6e 67 20  concealed using 
2b80: 74 68 65 20 64 62 5f 63 6f 6e 63 65 61 6c 28 29  the db_conceal()
2b90: 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a 73 74   function..*/.st
2ba0: 61 74 69 63 20 69 6e 74 20 73 75 62 6d 69 74 54  atic int submitT
2bb0: 69 63 6b 65 74 43 6d 64 28 0a 20 20 54 68 5f 49  icketCmd(.  Th_I
2bc0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 0a  nterp *interp, .
2bd0: 20 20 76 6f 69 64 20 2a 70 55 75 69 64 2c 20 0a    void *pUuid, .
2be0: 20 20 69 6e 74 20 61 72 67 63 2c 20 0a 20 20 63    int argc, .  c
2bf0: 6f 6e 73 74 20 63 68 61 72 20 2a 2a 61 72 67 76  onst char **argv
2c00: 2c 20 0a 20 20 69 6e 74 20 2a 61 72 67 6c 0a 29  , .  int *argl.)
2c10: 7b 0a 20 20 63 68 61 72 20 2a 7a 44 61 74 65 3b  {.  char *zDate;
2c20: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
2c30: 55 75 69 64 3b 0a 20 20 69 6e 74 20 69 3b 0a 20  Uuid;.  int i;. 
2c40: 20 69 6e 74 20 72 69 64 3b 0a 20 20 42 6c 6f 62   int rid;.  Blob
2c50: 20 74 6b 74 63 68 6e 67 2c 20 63 6b 73 75 6d 3b   tktchng, cksum;
2c60: 0a 0a 20 20 6c 6f 67 69 6e 5f 76 65 72 69 66 79  ..  login_verify
2c70: 5f 63 73 72 66 5f 73 65 63 72 65 74 28 29 3b 0a  _csrf_secret();.
2c80: 20 20 7a 55 75 69 64 20 3d 20 28 63 6f 6e 73 74    zUuid = (const
2c90: 20 63 68 61 72 20 2a 29 70 55 75 69 64 3b 0a 20   char *)pUuid;. 
2ca0: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 74 6b 74 63   blob_zero(&tktc
2cb0: 68 6e 67 29 3b 0a 20 20 7a 44 61 74 65 20 3d 20  hng);.  zDate = 
2cc0: 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45  db_text(0, "SELE
2cd0: 43 54 20 64 61 74 65 74 69 6d 65 28 27 6e 6f 77  CT datetime('now
2ce0: 27 29 22 29 3b 0a 20 20 7a 44 61 74 65 5b 31 30  ')");.  zDate[10
2cf0: 5d 20 3d 20 27 54 27 3b 0a 20 20 62 6c 6f 62 5f  ] = 'T';.  blob_
2d00: 61 70 70 65 6e 64 66 28 26 74 6b 74 63 68 6e 67  appendf(&tktchng
2d10: 2c 20 22 44 20 25 73 5c 6e 22 2c 20 7a 44 61 74  , "D %s\n", zDat
2d20: 65 29 3b 0a 20 20 66 72 65 65 28 7a 44 61 74 65  e);.  free(zDate
2d30: 29 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c  );.  for(i=0; i<
2d40: 6e 46 69 65 6c 64 3b 20 69 2b 2b 29 7b 0a 20 20  nField; i++){.  
2d50: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56    const char *zV
2d60: 61 6c 75 65 3b 0a 20 20 20 20 69 6e 74 20 6e 56  alue;.    int nV
2d70: 61 6c 75 65 3b 0a 20 20 20 20 69 66 28 20 61 7a  alue;.    if( az
2d80: 41 70 70 65 6e 64 5b 69 5d 20 29 7b 0a 20 20 20  Append[i] ){.   
2d90: 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28     blob_appendf(
2da0: 26 74 6b 74 63 68 6e 67 2c 20 22 4a 20 2b 25 73  &tktchng, "J +%s
2db0: 20 25 7a 5c 6e 22 2c 20 61 7a 46 69 65 6c 64 5b   %z\n", azField[
2dc0: 69 5d 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20  i],.            
2dd0: 20 20 20 20 20 20 20 66 6f 73 73 69 6c 69 7a 65         fossilize
2de0: 28 61 7a 41 70 70 65 6e 64 5b 69 5d 2c 20 2d 31  (azAppend[i], -1
2df0: 29 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20  ));.    }else{. 
2e00: 20 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 54 68       zValue = Th
2e10: 5f 46 65 74 63 68 28 61 7a 46 69 65 6c 64 5b 69  _Fetch(azField[i
2e20: 5d 2c 20 26 6e 56 61 6c 75 65 29 3b 0a 20 20 20  ], &nValue);.   
2e30: 20 20 20 69 66 28 20 7a 56 61 6c 75 65 20 29 7b     if( zValue ){
2e40: 0a 20 20 20 20 20 20 20 20 77 68 69 6c 65 28 20  .        while( 
2e50: 6e 56 61 6c 75 65 3e 30 20 26 26 20 69 73 73 70  nValue>0 && issp
2e60: 61 63 65 28 7a 56 61 6c 75 65 5b 6e 56 61 6c 75  ace(zValue[nValu
2e70: 65 2d 31 5d 29 20 29 7b 20 6e 56 61 6c 75 65 2d  e-1]) ){ nValue-
2e80: 2d 3b 20 7d 0a 20 20 20 20 20 20 20 20 69 66 28  -; }.        if(
2e90: 20 73 74 72 6e 63 6d 70 28 7a 56 61 6c 75 65 2c   strncmp(zValue,
2ea0: 20 61 7a 56 61 6c 75 65 5b 69 5d 2c 20 6e 56 61   azValue[i], nVa
2eb0: 6c 75 65 29 20 7c 7c 20 73 74 72 6c 65 6e 28 61  lue) || strlen(a
2ec0: 7a 56 61 6c 75 65 5b 69 5d 29 21 3d 6e 56 61 6c  zValue[i])!=nVal
2ed0: 75 65 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20  ue ){.          
2ee0: 69 66 28 20 73 74 72 6e 63 6d 70 28 61 7a 46 69  if( strncmp(azFi
2ef0: 65 6c 64 5b 69 5d 2c 20 22 70 72 69 76 61 74 65  eld[i], "private
2f00: 5f 22 2c 20 38 29 3d 3d 30 20 29 7b 0a 20 20 20  _", 8)==0 ){.   
2f10: 20 20 20 20 20 20 20 20 20 7a 56 61 6c 75 65 20           zValue 
2f20: 3d 20 64 62 5f 63 6f 6e 63 65 61 6c 28 7a 56 61  = db_conceal(zVa
2f30: 6c 75 65 2c 20 6e 56 61 6c 75 65 29 3b 0a 20 20  lue, nValue);.  
2f40: 20 20 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 61            blob_a
2f50: 70 70 65 6e 64 66 28 26 74 6b 74 63 68 6e 67 2c  ppendf(&tktchng,
2f60: 20 22 4a 20 25 73 20 25 73 5c 6e 22 2c 20 61 7a   "J %s %s\n", az
2f70: 46 69 65 6c 64 5b 69 5d 2c 20 7a 56 61 6c 75 65  Field[i], zValue
2f80: 29 3b 0a 20 20 20 20 20 20 20 20 20 20 7d 65 6c  );.          }el
2f90: 73 65 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20  se{.            
2fa0: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 74 6b  blob_appendf(&tk
2fb0: 74 63 68 6e 67 2c 20 22 4a 20 25 73 20 25 23 46  tchng, "J %s %#F
2fc0: 5c 6e 22 2c 20 61 7a 46 69 65 6c 64 5b 69 5d 2c  \n", azField[i],
2fd0: 20 6e 56 61 6c 75 65 2c 20 7a 56 61 6c 75 65 29   nValue, zValue)
2fe0: 3b 0a 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20  ;.          }.  
2ff0: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a        }.      }.
3000: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20      }.  }.  if( 
3010: 2a 28 63 68 61 72 2a 2a 29 70 55 75 69 64 20 29  *(char**)pUuid )
3020: 7b 0a 20 20 20 20 7a 55 75 69 64 20 3d 20 64 62  {.    zUuid = db
3030: 5f 74 65 78 74 28 30 2c 20 0a 20 20 20 20 20 20  _text(0, .      
3040: 20 22 53 45 4c 45 43 54 20 74 6b 74 5f 75 75 69   "SELECT tkt_uui
3050: 64 20 46 52 4f 4d 20 74 69 63 6b 65 74 20 57 48  d FROM ticket WH
3060: 45 52 45 20 74 6b 74 5f 75 75 69 64 20 47 4c 4f  ERE tkt_uuid GLO
3070: 42 20 27 25 73 2a 27 22 2c 20 50 28 22 6e 61 6d  B '%s*'", P("nam
3080: 65 22 29 0a 20 20 20 20 29 3b 0a 20 20 7d 65 6c  e").    );.  }el
3090: 73 65 7b 0a 20 20 20 20 7a 55 75 69 64 20 3d 20  se{.    zUuid = 
30a0: 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45  db_text(0, "SELE
30b0: 43 54 20 6c 6f 77 65 72 28 68 65 78 28 72 61 6e  CT lower(hex(ran
30c0: 64 6f 6d 62 6c 6f 62 28 32 30 29 29 29 22 29 3b  domblob(20)))");
30d0: 0a 20 20 7d 0a 20 20 2a 28 63 6f 6e 73 74 20 63  .  }.  *(const c
30e0: 68 61 72 2a 2a 29 70 55 75 69 64 20 3d 20 7a 55  har**)pUuid = zU
30f0: 75 69 64 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65  uid;.  blob_appe
3100: 6e 64 66 28 26 74 6b 74 63 68 6e 67 2c 20 22 4b  ndf(&tktchng, "K
3110: 20 25 73 5c 6e 22 2c 20 7a 55 75 69 64 29 3b 0a   %s\n", zUuid);.
3120: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26    blob_appendf(&
3130: 74 6b 74 63 68 6e 67 2c 20 22 55 20 25 46 5c 6e  tktchng, "U %F\n
3140: 22 2c 20 67 2e 7a 4c 6f 67 69 6e 20 3f 20 67 2e  ", g.zLogin ? g.
3150: 7a 4c 6f 67 69 6e 20 3a 20 22 22 29 3b 0a 20 20  zLogin : "");.  
3160: 6d 64 35 73 75 6d 5f 62 6c 6f 62 28 26 74 6b 74  md5sum_blob(&tkt
3170: 63 68 6e 67 2c 20 26 63 6b 73 75 6d 29 3b 0a 20  chng, &cksum);. 
3180: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 74   blob_appendf(&t
3190: 6b 74 63 68 6e 67 2c 20 22 5a 20 25 62 5c 6e 22  ktchng, "Z %b\n"
31a0: 2c 20 26 63 6b 73 75 6d 29 3b 0a 20 20 69 66 28  , &cksum);.  if(
31b0: 20 67 2e 74 68 54 72 61 63 65 20 29 7b 0a 20 20   g.thTrace ){.  
31c0: 20 20 54 68 5f 54 72 61 63 65 28 22 73 75 62 6d    Th_Trace("subm
31d0: 69 74 5f 74 69 63 6b 65 74 20 7b 5c 6e 3c 62 6c  it_ticket {\n<bl
31e0: 6f 63 6b 71 75 6f 74 65 3e 3c 70 72 65 3e 5c 6e  ockquote><pre>\n
31f0: 25 68 5c 6e 3c 2f 70 72 65 3e 3c 2f 62 6c 6f 63  %h\n</pre></bloc
3200: 6b 71 75 6f 74 65 3e 5c 6e 22 0a 20 20 20 20 20  kquote>\n".     
3210: 20 20 20 20 20 20 20 20 22 7d 3c 62 72 20 2f 3e          "}<br />
3220: 5c 6e 22 2c 0a 20 20 20 20 20 20 20 62 6c 6f 62  \n",.       blob
3230: 5f 73 74 72 28 26 74 6b 74 63 68 6e 67 29 29 3b  _str(&tktchng));
3240: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 72 69  .  }else{.    ri
3250: 64 20 3d 20 63 6f 6e 74 65 6e 74 5f 70 75 74 28  d = content_put(
3260: 26 74 6b 74 63 68 6e 67 2c 20 30 2c 20 30 29 3b  &tktchng, 0, 0);
3270: 0a 20 20 20 20 69 66 28 20 72 69 64 3d 3d 30 20  .    if( rid==0 
3280: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  ){.      fossil_
3290: 70 61 6e 69 63 28 22 74 72 6f 75 62 6c 65 20 63  panic("trouble c
32a0: 6f 6d 6d 69 74 74 69 6e 67 20 74 69 63 6b 65 74  ommitting ticket
32b0: 3a 20 25 73 22 2c 20 67 2e 7a 45 72 72 4d 73 67  : %s", g.zErrMsg
32c0: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6d 61 6e  );.    }.    man
32d0: 69 66 65 73 74 5f 63 72 6f 73 73 6c 69 6e 6b 28  ifest_crosslink(
32e0: 72 69 64 2c 20 26 74 6b 74 63 68 6e 67 29 3b 0a  rid, &tktchng);.
32f0: 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 54 48 5f    }.  return TH_
3300: 52 45 54 55 52 4e 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a  RETURN;.}.../*.*
3310: 2a 20 57 45 42 50 41 47 45 3a 20 74 6b 74 6e 65  * WEBPAGE: tktne
3320: 77 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 64 65  w.** WEBPAGE: de
3330: 62 75 67 5f 74 6b 74 6e 65 77 0a 2a 2a 0a 2a 2a  bug_tktnew.**.**
3340: 20 45 6e 74 65 72 20 61 20 6e 65 77 20 74 69 63   Enter a new tic
3350: 6b 65 74 2e 20 20 74 68 65 20 74 6b 74 6e 65 77  ket.  the tktnew
3360: 5f 74 65 6d 70 6c 61 74 65 20 73 63 72 69 70 74  _template script
3370: 20 69 6e 20 74 68 65 20 74 69 63 6b 65 74 0a 2a   in the ticket.*
3380: 2a 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20  * configuration 
3390: 69 73 20 75 73 65 64 2e 20 20 54 68 65 20 2f 74  is used.  The /t
33a0: 6b 74 6e 65 77 20 70 61 67 65 20 69 73 20 74 68  ktnew page is th
33b0: 65 20 6f 66 66 69 63 69 61 6c 20 74 69 63 6b 65  e official ticke
33c0: 74 0a 2a 2a 20 65 6e 74 72 79 20 70 61 67 65 2e  t.** entry page.
33d0: 20 20 54 68 65 20 2f 64 65 62 75 67 5f 74 6b 74    The /debug_tkt
33e0: 6e 65 77 20 70 61 67 65 20 69 73 20 75 73 65 64  new page is used
33f0: 20 66 6f 72 20 64 65 62 75 67 67 69 6e 67 20 74   for debugging t
3400: 68 65 0a 2a 2a 20 74 6b 74 6e 65 77 5f 74 65 6d  he.** tktnew_tem
3410: 70 6c 61 74 65 20 69 6e 20 74 68 65 20 74 69 63  plate in the tic
3420: 6b 65 74 20 63 6f 6e 66 69 67 75 72 61 74 69 6f  ket configuratio
3430: 6e 2e 20 20 2f 64 65 62 75 67 5f 74 6b 74 6e 65  n.  /debug_tktne
3440: 77 20 77 6f 72 6b 73 0a 2a 2a 20 6a 75 73 74 20  w works.** just 
3450: 6c 69 6b 65 20 2f 74 6b 74 6e 65 77 20 65 78 63  like /tktnew exc
3460: 65 70 74 20 74 68 61 74 20 69 74 20 64 6f 65 73  ept that it does
3470: 20 6e 6f 74 20 72 65 61 6c 6c 79 20 73 61 76 65   not really save
3480: 20 74 68 65 20 6e 65 77 20 74 69 63 6b 65 74 0a   the new ticket.
3490: 2a 2a 20 77 68 65 6e 20 79 6f 75 20 70 72 65 73  ** when you pres
34a0: 73 20 73 75 62 6d 69 74 20 2d 20 69 74 20 6a 75  s submit - it ju
34b0: 73 74 20 70 72 69 6e 74 73 20 74 68 65 20 74 69  st prints the ti
34c0: 63 6b 65 74 20 61 72 74 69 66 61 63 74 20 61 74  cket artifact at
34d0: 20 74 68 65 0a 2a 2a 20 74 6f 70 20 6f 66 20 74   the.** top of t
34e0: 68 65 20 73 63 72 65 65 6e 2e 0a 2a 2f 0a 76 6f  he screen..*/.vo
34f0: 69 64 20 74 6b 74 6e 65 77 5f 70 61 67 65 28 76  id tktnew_page(v
3500: 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68  oid){.  const ch
3510: 61 72 20 2a 7a 53 63 72 69 70 74 3b 0a 20 20 63  ar *zScript;.  c
3520: 68 61 72 20 2a 7a 4e 65 77 55 75 69 64 20 3d 20  har *zNewUuid = 
3530: 30 3b 0a 0a 20 20 6c 6f 67 69 6e 5f 63 68 65 63  0;..  login_chec
3540: 6b 5f 63 72 65 64 65 6e 74 69 61 6c 73 28 29 3b  k_credentials();
3550: 0a 20 20 69 66 28 20 21 67 2e 6f 6b 4e 65 77 54  .  if( !g.okNewT
3560: 6b 74 20 29 7b 20 6c 6f 67 69 6e 5f 6e 65 65 64  kt ){ login_need
3570: 65 64 28 29 3b 20 72 65 74 75 72 6e 3b 20 7d 0a  ed(); return; }.
3580: 20 20 69 66 28 20 50 28 22 63 61 6e 63 65 6c 22    if( P("cancel"
3590: 29 20 29 7b 0a 20 20 20 20 63 67 69 5f 72 65 64  ) ){.    cgi_red
35a0: 69 72 65 63 74 28 22 68 6f 6d 65 22 29 3b 0a 20  irect("home");. 
35b0: 20 7d 0a 20 20 73 74 79 6c 65 5f 68 65 61 64 65   }.  style_heade
35c0: 72 28 22 4e 65 77 20 54 69 63 6b 65 74 22 29 3b  r("New Ticket");
35d0: 0a 20 20 69 66 28 20 67 2e 74 68 54 72 61 63 65  .  if( g.thTrace
35e0: 20 29 20 54 68 5f 54 72 61 63 65 28 22 42 45 47   ) Th_Trace("BEG
35f0: 49 4e 5f 54 4b 54 4e 45 57 3c 62 72 20 2f 3e 5c  IN_TKTNEW<br />\
3600: 6e 22 2c 20 2d 31 29 3b 0a 20 20 74 69 63 6b 65  n", -1);.  ticke
3610: 74 5f 69 6e 69 74 28 29 3b 0a 20 20 67 65 74 41  t_init();.  getA
3620: 6c 6c 54 69 63 6b 65 74 46 69 65 6c 64 73 28 29  llTicketFields()
3630: 3b 0a 20 20 69 6e 69 74 69 61 6c 69 7a 65 56 61  ;.  initializeVa
3640: 72 69 61 62 6c 65 73 46 72 6f 6d 44 62 28 29 3b  riablesFromDb();
3650: 0a 20 20 69 6e 69 74 69 61 6c 69 7a 65 56 61 72  .  initializeVar
3660: 69 61 62 6c 65 73 46 72 6f 6d 43 47 49 28 29 3b  iablesFromCGI();
3670: 0a 20 20 40 20 3c 66 6f 72 6d 20 6d 65 74 68 6f  .  @ <form metho
3680: 64 3d 22 50 4f 53 54 22 20 61 63 74 69 6f 6e 3d  d="POST" action=
3690: 22 25 73 28 67 2e 7a 42 61 73 65 55 52 4c 29 2f  "%s(g.zBaseURL)/
36a0: 25 73 28 67 2e 7a 50 61 74 68 29 22 3e 0a 20 20  %s(g.zPath)">.  
36b0: 6c 6f 67 69 6e 5f 69 6e 73 65 72 74 5f 63 73 72  login_insert_csr
36c0: 66 5f 73 65 63 72 65 74 28 29 3b 0a 20 20 7a 53  f_secret();.  zS
36d0: 63 72 69 70 74 20 3d 20 74 69 63 6b 65 74 5f 6e  cript = ticket_n
36e0: 65 77 70 61 67 65 5f 63 6f 64 65 28 29 3b 0a 20  ewpage_code();. 
36f0: 20 54 68 5f 53 74 6f 72 65 28 22 6c 6f 67 69 6e   Th_Store("login
3700: 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20  ", g.zLogin);.  
3710: 54 68 5f 53 74 6f 72 65 28 22 64 61 74 65 22 2c  Th_Store("date",
3720: 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c   db_text(0, "SEL
3730: 45 43 54 20 64 61 74 65 74 69 6d 65 28 27 6e 6f  ECT datetime('no
3740: 77 27 29 22 29 29 3b 0a 20 20 54 68 5f 43 72 65  w')"));.  Th_Cre
3750: 61 74 65 43 6f 6d 6d 61 6e 64 28 67 2e 69 6e 74  ateCommand(g.int
3760: 65 72 70 2c 20 22 73 75 62 6d 69 74 5f 74 69 63  erp, "submit_tic
3770: 6b 65 74 22 2c 20 73 75 62 6d 69 74 54 69 63 6b  ket", submitTick
3780: 65 74 43 6d 64 2c 0a 20 20 20 20 20 20 20 20 20  etCmd,.         
3790: 20 20 20 20 20 20 20 20 20 20 28 76 6f 69 64 2a            (void*
37a0: 29 26 7a 4e 65 77 55 75 69 64 2c 20 30 29 3b 0a  )&zNewUuid, 0);.
37b0: 20 20 69 66 28 20 67 2e 74 68 54 72 61 63 65 20    if( g.thTrace 
37c0: 29 20 54 68 5f 54 72 61 63 65 28 22 42 45 47 49  ) Th_Trace("BEGI
37d0: 4e 5f 54 4b 54 4e 45 57 5f 53 43 52 49 50 54 3c  N_TKTNEW_SCRIPT<
37e0: 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a 20  br />\n", -1);. 
37f0: 20 69 66 28 20 54 68 5f 52 65 6e 64 65 72 28 7a   if( Th_Render(z
3800: 53 63 72 69 70 74 29 3d 3d 54 48 5f 52 45 54 55  Script)==TH_RETU
3810: 52 4e 20 26 26 20 21 67 2e 74 68 54 72 61 63 65  RN && !g.thTrace
3820: 20 26 26 20 7a 4e 65 77 55 75 69 64 20 29 7b 0a   && zNewUuid ){.
3830: 20 20 20 20 63 67 69 5f 72 65 64 69 72 65 63 74      cgi_redirect
3840: 28 6d 70 72 69 6e 74 66 28 22 25 73 2f 74 6b 74  (mprintf("%s/tkt
3850: 76 69 65 77 2f 25 73 22 2c 20 67 2e 7a 42 61 73  view/%s", g.zBas
3860: 65 55 52 4c 2c 20 7a 4e 65 77 55 75 69 64 29 29  eURL, zNewUuid))
3870: 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20  ;.    return;.  
3880: 7d 0a 20 20 40 20 3c 2f 66 6f 72 6d 3e 0a 20 20  }.  @ </form>.  
3890: 69 66 28 20 67 2e 74 68 54 72 61 63 65 20 29 20  if( g.thTrace ) 
38a0: 54 68 5f 54 72 61 63 65 28 22 45 4e 44 5f 54 4b  Th_Trace("END_TK
38b0: 54 56 49 45 57 3c 62 72 20 2f 3e 5c 6e 22 2c 20  TVIEW<br />\n", 
38c0: 2d 31 29 3b 0a 20 20 73 74 79 6c 65 5f 66 6f 6f  -1);.  style_foo
38d0: 74 65 72 28 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  ter();.}../*.** 
38e0: 57 45 42 50 41 47 45 3a 20 74 6b 74 65 64 69 74  WEBPAGE: tktedit
38f0: 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 64 65 62  .** WEBPAGE: deb
3900: 75 67 5f 74 6b 74 65 64 69 74 0a 2a 2a 0a 2a 2a  ug_tktedit.**.**
3910: 20 45 64 69 74 20 61 20 74 69 63 6b 65 74 2e 20   Edit a ticket. 
3920: 20 54 68 65 20 74 69 63 6b 65 74 20 69 73 20 69   The ticket is i
3930: 64 65 6e 74 69 66 69 65 64 20 62 79 20 74 68 65  dentified by the
3940: 20 6e 61 6d 65 20 43 47 49 20 70 61 72 61 6d 65   name CGI parame
3950: 74 65 72 2e 0a 2a 2a 20 2f 74 6b 74 65 64 69 74  ter..** /tktedit
3960: 20 69 73 20 74 68 65 20 6f 66 66 69 63 69 61 6c   is the official
3970: 20 70 61 67 65 2e 20 20 54 68 65 20 2f 64 65 62   page.  The /deb
3980: 75 67 5f 74 6b 74 65 64 69 74 20 70 61 67 65 20  ug_tktedit page 
3990: 64 6f 65 73 20 74 68 65 20 73 61 6d 65 0a 2a 2a  does the same.**
39a0: 20 74 68 69 6e 67 20 65 78 63 65 70 74 20 74 68   thing except th
39b0: 61 74 20 69 74 20 64 6f 65 73 20 6e 6f 74 20 73  at it does not s
39c0: 61 76 65 20 74 68 65 20 74 69 63 6b 65 74 20 63  ave the ticket c
39d0: 68 61 6e 67 65 20 72 65 63 6f 72 64 20 77 68 65  hange record whe
39e0: 6e 20 79 6f 75 0a 2a 2a 20 70 72 65 73 73 20 73  n you.** press s
39f0: 75 62 6d 69 74 20 2d 20 69 74 20 69 6e 73 74 65  ubmit - it inste
3a00: 61 64 20 70 72 69 6e 74 73 20 74 68 65 20 74 69  ad prints the ti
3a10: 63 6b 65 74 20 63 68 61 6e 67 65 20 72 65 63 6f  cket change reco
3a20: 72 64 20 61 74 20 74 68 65 20 74 6f 70 0a 2a 2a  rd at the top.**
3a30: 20 6f 66 20 74 68 65 20 70 61 67 65 2e 20 20 54   of the page.  T
3a40: 68 65 20 2f 64 65 62 75 67 5f 74 6b 74 65 64 69  he /debug_tktedi
3a50: 74 20 70 61 67 65 20 69 73 20 69 6e 74 65 6e 64  t page is intend
3a60: 65 64 20 74 6f 20 62 65 20 75 73 65 64 20 77 68  ed to be used wh
3a70: 65 6e 0a 2a 2a 20 64 65 62 75 67 67 69 6e 67 20  en.** debugging 
3a80: 74 69 63 6b 65 74 20 63 6f 6e 66 69 67 75 72 61  ticket configura
3a90: 74 69 6f 6e 73 2e 0a 2a 2f 0a 76 6f 69 64 20 74  tions..*/.void t
3aa0: 6b 74 65 64 69 74 5f 70 61 67 65 28 76 6f 69 64  ktedit_page(void
3ab0: 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  ){.  const char 
3ac0: 2a 7a 53 63 72 69 70 74 3b 0a 20 20 69 6e 74 20  *zScript;.  int 
3ad0: 6e 4e 61 6d 65 3b 0a 20 20 63 6f 6e 73 74 20 63  nName;.  const c
3ae0: 68 61 72 20 2a 7a 4e 61 6d 65 3b 0a 20 20 69 6e  har *zName;.  in
3af0: 74 20 6e 52 65 63 3b 0a 0a 20 20 6c 6f 67 69 6e  t nRec;..  login
3b00: 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69 61  _check_credentia
3b10: 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67 2e 6f  ls();.  if( !g.o
3b20: 6b 41 70 6e 64 54 6b 74 20 26 26 20 21 67 2e 6f  kApndTkt && !g.o
3b30: 6b 57 72 54 6b 74 20 29 7b 20 6c 6f 67 69 6e 5f  kWrTkt ){ login_
3b40: 6e 65 65 64 65 64 28 29 3b 20 72 65 74 75 72 6e  needed(); return
3b50: 3b 20 7d 0a 20 20 7a 4e 61 6d 65 20 3d 20 50 28  ; }.  zName = P(
3b60: 22 6e 61 6d 65 22 29 3b 0a 20 20 69 66 28 20 50  "name");.  if( P
3b70: 28 22 63 61 6e 63 65 6c 22 29 20 29 7b 0a 20 20  ("cancel") ){.  
3b80: 20 20 63 67 69 5f 72 65 64 69 72 65 63 74 66 28    cgi_redirectf(
3b90: 22 74 6b 74 76 69 65 77 3f 6e 61 6d 65 3d 25 54  "tktview?name=%T
3ba0: 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 7d 0a 20  ", zName);.  }. 
3bb0: 20 73 74 79 6c 65 5f 68 65 61 64 65 72 28 22 45   style_header("E
3bc0: 64 69 74 20 54 69 63 6b 65 74 22 29 3b 0a 20 20  dit Ticket");.  
3bd0: 69 66 28 20 7a 4e 61 6d 65 3d 3d 30 20 7c 7c 20  if( zName==0 || 
3be0: 28 6e 4e 61 6d 65 20 3d 20 73 74 72 6c 65 6e 28  (nName = strlen(
3bf0: 7a 4e 61 6d 65 29 29 3c 34 20 7c 7c 20 6e 4e 61  zName))<4 || nNa
3c00: 6d 65 3e 55 55 49 44 5f 53 49 5a 45 0a 20 20 20  me>UUID_SIZE.   
3c10: 20 20 20 20 20 20 20 7c 7c 20 21 76 61 6c 69 64         || !valid
3c20: 61 74 65 31 36 28 7a 4e 61 6d 65 2c 6e 4e 61 6d  ate16(zName,nNam
3c30: 65 29 20 29 7b 0a 20 20 20 20 40 20 3c 66 6f 6e  e) ){.    @ <fon
3c40: 74 20 63 6f 6c 6f 72 3d 22 72 65 64 22 3e 3c 62  t color="red"><b
3c50: 3e 4e 6f 74 20 61 20 76 61 6c 69 64 20 74 69 63  >Not a valid tic
3c60: 6b 65 74 20 69 64 3a 20 5c 22 25 68 28 7a 4e 61  ket id: \"%h(zNa
3c70: 6d 65 29 5c 22 3c 2f 62 3e 3c 2f 66 6f 6e 74 3e  me)\"</b></font>
3c80: 0a 20 20 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65  .    style_foote
3c90: 72 28 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b  r();.    return;
3ca0: 0a 20 20 7d 0a 20 20 6e 52 65 63 20 3d 20 64 62  .  }.  nRec = db
3cb0: 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20  _int(0, "SELECT 
3cc0: 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74 69  count(*) FROM ti
3cd0: 63 6b 65 74 20 57 48 45 52 45 20 74 6b 74 5f 75  cket WHERE tkt_u
3ce0: 75 69 64 20 47 4c 4f 42 20 27 25 71 2a 27 22 2c  uid GLOB '%q*'",
3cf0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
3d00: 20 7a 4e 61 6d 65 29 3b 0a 20 20 69 66 28 20 6e   zName);.  if( n
3d10: 52 65 63 3d 3d 30 20 29 7b 0a 20 20 20 20 40 20  Rec==0 ){.    @ 
3d20: 3c 66 6f 6e 74 20 63 6f 6c 6f 72 3d 22 72 65 64  <font color="red
3d30: 22 3e 3c 62 3e 4e 6f 20 73 75 63 68 20 74 69 63  "><b>No such tic
3d40: 6b 65 74 3a 20 5c 22 25 68 28 7a 4e 61 6d 65 29  ket: \"%h(zName)
3d50: 5c 22 3c 2f 62 3e 3c 2f 66 6f 6e 74 3e 0a 20 20  \"</b></font>.  
3d60: 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29    style_footer()
3d70: 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20  ;.    return;.  
3d80: 7d 0a 20 20 69 66 28 20 6e 52 65 63 3e 31 20 29  }.  if( nRec>1 )
3d90: 7b 0a 20 20 20 20 40 20 3c 66 6f 6e 74 20 63 6f  {.    @ <font co
3da0: 6c 6f 72 3d 22 72 65 64 22 3e 3c 62 3e 25 64 28  lor="red"><b>%d(
3db0: 6e 52 65 63 29 20 74 69 63 6b 65 74 73 20 62 65  nRec) tickets be
3dc0: 67 69 6e 20 77 69 74 68 3a 20 5c 22 25 68 28 7a  gin with: \"%h(z
3dd0: 4e 61 6d 65 29 5c 22 3c 2f 62 3e 3c 2f 66 6f 6e  Name)\"</b></fon
3de0: 74 3e 0a 20 20 20 20 73 74 79 6c 65 5f 66 6f 6f  t>.    style_foo
3df0: 74 65 72 28 29 3b 0a 20 20 20 20 72 65 74 75 72  ter();.    retur
3e00: 6e 3b 0a 20 20 7d 0a 20 20 69 66 28 20 67 2e 74  n;.  }.  if( g.t
3e10: 68 54 72 61 63 65 20 29 20 54 68 5f 54 72 61 63  hTrace ) Th_Trac
3e20: 65 28 22 42 45 47 49 4e 5f 54 4b 54 45 44 49 54  e("BEGIN_TKTEDIT
3e30: 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a  <br />\n", -1);.
3e40: 20 20 74 69 63 6b 65 74 5f 69 6e 69 74 28 29 3b    ticket_init();
3e50: 0a 20 20 67 65 74 41 6c 6c 54 69 63 6b 65 74 46  .  getAllTicketF
3e60: 69 65 6c 64 73 28 29 3b 0a 20 20 69 6e 69 74 69  ields();.  initi
3e70: 61 6c 69 7a 65 56 61 72 69 61 62 6c 65 73 46 72  alizeVariablesFr
3e80: 6f 6d 43 47 49 28 29 3b 0a 20 20 69 6e 69 74 69  omCGI();.  initi
3e90: 61 6c 69 7a 65 56 61 72 69 61 62 6c 65 73 46 72  alizeVariablesFr
3ea0: 6f 6d 44 62 28 29 3b 0a 20 20 40 20 3c 66 6f 72  omDb();.  @ <for
3eb0: 6d 20 6d 65 74 68 6f 64 3d 22 50 4f 53 54 22 20  m method="POST" 
3ec0: 61 63 74 69 6f 6e 3d 22 25 73 28 67 2e 7a 42 61  action="%s(g.zBa
3ed0: 73 65 55 52 4c 29 2f 25 73 28 67 2e 7a 50 61 74  seURL)/%s(g.zPat
3ee0: 68 29 22 3e 0a 20 20 40 20 3c 69 6e 70 75 74 20  h)">.  @ <input 
3ef0: 74 79 70 65 3d 22 68 69 64 64 65 6e 22 20 6e 61  type="hidden" na
3f00: 6d 65 3d 22 6e 61 6d 65 22 20 76 61 6c 75 65 3d  me="name" value=
3f10: 22 25 73 28 7a 4e 61 6d 65 29 22 3e 0a 20 20 6c  "%s(zName)">.  l
3f20: 6f 67 69 6e 5f 69 6e 73 65 72 74 5f 63 73 72 66  ogin_insert_csrf
3f30: 5f 73 65 63 72 65 74 28 29 3b 0a 20 20 7a 53 63  _secret();.  zSc
3f40: 72 69 70 74 20 3d 20 74 69 63 6b 65 74 5f 65 64  ript = ticket_ed
3f50: 69 74 70 61 67 65 5f 63 6f 64 65 28 29 3b 0a 20  itpage_code();. 
3f60: 20 54 68 5f 53 74 6f 72 65 28 22 6c 6f 67 69 6e   Th_Store("login
3f70: 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20  ", g.zLogin);.  
3f80: 54 68 5f 53 74 6f 72 65 28 22 64 61 74 65 22 2c  Th_Store("date",
3f90: 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c   db_text(0, "SEL
3fa0: 45 43 54 20 64 61 74 65 74 69 6d 65 28 27 6e 6f  ECT datetime('no
3fb0: 77 27 29 22 29 29 3b 0a 20 20 54 68 5f 43 72 65  w')"));.  Th_Cre
3fc0: 61 74 65 43 6f 6d 6d 61 6e 64 28 67 2e 69 6e 74  ateCommand(g.int
3fd0: 65 72 70 2c 20 22 61 70 70 65 6e 64 5f 66 69 65  erp, "append_fie
3fe0: 6c 64 22 2c 20 61 70 70 65 6e 64 52 65 6d 61 72  ld", appendRemar
3ff0: 6b 43 6d 64 2c 20 30 2c 20 30 29 3b 0a 20 20 54  kCmd, 0, 0);.  T
4000: 68 5f 43 72 65 61 74 65 43 6f 6d 6d 61 6e 64 28  h_CreateCommand(
4010: 67 2e 69 6e 74 65 72 70 2c 20 22 73 75 62 6d 69  g.interp, "submi
4020: 74 5f 74 69 63 6b 65 74 22 2c 20 73 75 62 6d 69  t_ticket", submi
4030: 74 54 69 63 6b 65 74 43 6d 64 2c 20 28 76 6f 69  tTicketCmd, (voi
4040: 64 2a 29 26 7a 4e 61 6d 65 2c 30 29 3b 0a 20 20  d*)&zName,0);.  
4050: 69 66 28 20 67 2e 74 68 54 72 61 63 65 20 29 20  if( g.thTrace ) 
4060: 54 68 5f 54 72 61 63 65 28 22 42 45 47 49 4e 5f  Th_Trace("BEGIN_
4070: 54 4b 54 45 44 49 54 5f 53 43 52 49 50 54 3c 62  TKTEDIT_SCRIPT<b
4080: 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a 20 20  r />\n", -1);.  
4090: 69 66 28 20 54 68 5f 52 65 6e 64 65 72 28 7a 53  if( Th_Render(zS
40a0: 63 72 69 70 74 29 3d 3d 54 48 5f 52 45 54 55 52  cript)==TH_RETUR
40b0: 4e 20 26 26 20 21 67 2e 74 68 54 72 61 63 65 20  N && !g.thTrace 
40c0: 26 26 20 7a 4e 61 6d 65 20 29 7b 0a 20 20 20 20  && zName ){.    
40d0: 63 67 69 5f 72 65 64 69 72 65 63 74 28 6d 70 72  cgi_redirect(mpr
40e0: 69 6e 74 66 28 22 25 73 2f 74 6b 74 76 69 65 77  intf("%s/tktview
40f0: 2f 25 73 22 2c 20 67 2e 7a 42 61 73 65 55 52 4c  /%s", g.zBaseURL
4100: 2c 20 7a 4e 61 6d 65 29 29 3b 0a 20 20 20 20 72  , zName));.    r
4110: 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 40 20 3c  eturn;.  }.  @ <
4120: 2f 66 6f 72 6d 3e 0a 20 20 69 66 28 20 67 2e 74  /form>.  if( g.t
4130: 68 54 72 61 63 65 20 29 20 54 68 5f 54 72 61 63  hTrace ) Th_Trac
4140: 65 28 22 42 45 47 49 4e 5f 54 4b 54 45 44 49 54  e("BEGIN_TKTEDIT
4150: 3c 62 72 20 2f 3e 5c 6e 22 2c 20 2d 31 29 3b 0a  <br />\n", -1);.
4160: 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29    style_footer()
4170: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 68 65 63 6b  ;.}../*.** Check
4180: 20 74 68 65 20 74 69 63 6b 65 74 20 74 61 62 6c   the ticket tabl
4190: 65 20 73 63 68 65 6d 61 20 69 6e 20 7a 53 63 68  e schema in zSch
41a0: 65 6d 61 20 74 6f 20 73 65 65 20 69 66 20 69 74  ema to see if it
41b0: 20 61 70 70 65 61 72 73 20 74 6f 0a 2a 2a 20 62   appears to.** b
41c0: 65 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 2e 20 20  e well-formed.  
41d0: 49 66 20 65 76 65 72 79 74 68 69 6e 67 20 69 73  If everything is
41e0: 20 4f 4b 2c 20 72 65 74 75 72 6e 20 4e 55 4c 4c   OK, return NULL
41f0: 2e 20 20 49 66 20 73 6f 6d 65 74 68 69 6e 67 20  .  If something 
4200: 69 73 0a 2a 2a 20 61 6d 69 73 73 2c 20 74 68 65  is.** amiss, the
4210: 6e 20 72 65 74 75 72 6e 20 61 20 70 6f 69 6e 74  n return a point
4220: 65 72 20 74 6f 20 61 20 73 74 72 69 6e 67 20 28  er to a string (
4230: 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d 20 6d 61  obtained from ma
4240: 6c 6c 6f 63 29 20 74 68 61 74 0a 2a 2a 20 64 65  lloc) that.** de
4250: 73 63 72 69 62 65 73 20 74 68 65 20 70 72 6f 62  scribes the prob
4260: 6c 65 6d 2e 0a 2a 2f 0a 63 68 61 72 20 2a 74 69  lem..*/.char *ti
4270: 63 6b 65 74 5f 73 63 68 65 6d 61 5f 63 68 65 63  cket_schema_chec
4280: 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53  k(const char *zS
4290: 63 68 65 6d 61 29 7b 0a 20 20 63 68 61 72 20 2a  chema){.  char *
42a0: 7a 45 72 72 20 3d 20 30 3b 0a 20 20 69 6e 74 20  zErr = 0;.  int 
42b0: 72 63 3b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64  rc;.  sqlite3 *d
42c0: 62 3b 0a 20 20 72 63 20 3d 20 73 71 6c 69 74 65  b;.  rc = sqlite
42d0: 33 5f 6f 70 65 6e 28 22 3a 6d 65 6d 6f 72 79 3a  3_open(":memory:
42e0: 22 2c 20 26 64 62 29 3b 0a 20 20 69 66 28 20 72  ", &db);.  if( r
42f0: 63 3d 3d 53 51 4c 49 54 45 5f 4f 4b 20 29 7b 0a  c==SQLITE_OK ){.
4300: 20 20 20 20 72 63 20 3d 20 73 71 6c 69 74 65 33      rc = sqlite3
4310: 5f 65 78 65 63 28 64 62 2c 20 7a 53 63 68 65 6d  _exec(db, zSchem
4320: 61 2c 20 30 2c 20 30 2c 20 26 7a 45 72 72 29 3b  a, 0, 0, &zErr);
4330: 0a 20 20 20 20 69 66 28 20 72 63 21 3d 53 51 4c  .    if( rc!=SQL
4340: 49 54 45 5f 4f 4b 20 29 7b 0a 20 20 20 20 20 20  ITE_OK ){.      
4350: 73 71 6c 69 74 65 33 5f 63 6c 6f 73 65 28 64 62  sqlite3_close(db
4360: 29 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20  );.      return 
4370: 7a 45 72 72 3b 0a 20 20 20 20 7d 0a 20 20 20 20  zErr;.    }.    
4380: 72 63 20 3d 20 73 71 6c 69 74 65 33 5f 65 78 65  rc = sqlite3_exe
4390: 63 28 64 62 2c 20 22 53 45 4c 45 43 54 20 74 6b  c(db, "SELECT tk
43a0: 74 5f 69 64 2c 20 74 6b 74 5f 75 75 69 64 2c 20  t_id, tkt_uuid, 
43b0: 74 6b 74 5f 6d 74 69 6d 65 20 46 52 4f 4d 20 74  tkt_mtime FROM t
43c0: 69 63 6b 65 74 22 2c 0a 20 20 20 20 20 20 20 20  icket",.        
43d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c                0,
43e0: 20 30 2c 20 30 29 3b 0a 20 20 20 20 73 71 6c 69   0, 0);.    sqli
43f0: 74 65 33 5f 63 6c 6f 73 65 28 64 62 29 3b 0a 20  te3_close(db);. 
4400: 20 20 20 69 66 28 20 72 63 21 3d 53 51 4c 49 54     if( rc!=SQLIT
4410: 45 5f 4f 4b 20 29 7b 0a 20 20 20 20 20 20 7a 45  E_OK ){.      zE
4420: 72 72 20 3d 20 6d 70 72 69 6e 74 66 28 22 73 63  rr = mprintf("sc
4430: 68 65 6d 61 20 66 61 69 6c 73 20 74 6f 20 64 65  hema fails to de
4440: 66 69 6e 65 20 61 20 76 61 6c 69 64 20 74 69 63  fine a valid tic
4450: 6b 65 74 20 74 61 62 6c 65 20 22 0a 20 20 20 20  ket table ".    
4460: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
4470: 20 22 63 6f 6e 74 61 69 6e 69 6e 67 20 61 6c 6c   "containing all
4480: 20 72 65 71 75 69 72 65 64 20 66 69 65 6c 64 73   required fields
4490: 22 29 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e  ");.      return
44a0: 20 7a 45 72 72 3b 0a 20 20 20 20 7d 0a 20 20 7d   zErr;.    }.  }
44b0: 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a  .  return 0;.}..
44c0: 2f 2a 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 74  /*.** WEBPAGE: t
44d0: 6b 74 74 69 6d 65 6c 69 6e 65 0a 2a 2a 20 55 52  kttimeline.** UR
44e0: 4c 3a 20 2f 74 6b 74 74 69 6d 65 6c 69 6e 65 3f  L: /tkttimeline?
44f0: 6e 61 6d 65 3d 54 49 43 4b 45 54 55 55 49 44 0a  name=TICKETUUID.
4500: 2a 2a 0a 2a 2a 20 53 68 6f 77 20 74 68 65 20 63  **.** Show the c
4510: 68 61 6e 67 65 20 68 69 73 74 6f 72 79 20 66 6f  hange history fo
4520: 72 20 61 20 73 69 6e 67 6c 65 20 74 69 63 6b 65  r a single ticke
4530: 74 20 69 6e 20 74 69 6d 65 6c 69 6e 65 20 66 6f  t in timeline fo
4540: 72 6d 61 74 2e 0a 2a 2f 0a 76 6f 69 64 20 74 6b  rmat..*/.void tk
4550: 74 74 69 6d 65 6c 69 6e 65 5f 70 61 67 65 28 76  ttimeline_page(v
4560: 6f 69 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a  oid){.  Stmt q;.
4570: 20 20 63 68 61 72 20 2a 7a 54 69 74 6c 65 3b 0a    char *zTitle;.
4580: 20 20 63 68 61 72 20 2a 7a 53 51 4c 3b 0a 20 20    char *zSQL;.  
4590: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 55 75 69  const char *zUui
45a0: 64 3b 0a 20 20 69 6e 74 20 74 61 67 69 64 3b 0a  d;.  int tagid;.
45b0: 0a 20 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63  .  login_check_c
45c0: 72 65 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20  redentials();.  
45d0: 69 66 28 20 21 67 2e 6f 6b 48 69 73 74 6f 72 79  if( !g.okHistory
45e0: 20 7c 7c 20 21 67 2e 6f 6b 52 64 54 6b 74 20 29   || !g.okRdTkt )
45f0: 7b 20 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28 29  { login_needed()
4600: 3b 20 72 65 74 75 72 6e 3b 20 7d 0a 20 20 7a 55  ; return; }.  zU
4610: 75 69 64 20 3d 20 50 44 28 22 6e 61 6d 65 22 2c  uid = PD("name",
4620: 22 22 29 3b 0a 20 20 73 74 79 6c 65 5f 73 75 62  "");.  style_sub
4630: 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 48 69  menu_element("Hi
4640: 73 74 6f 72 79 22 2c 20 22 48 69 73 74 6f 72 79  story", "History
4650: 22 2c 0a 20 20 20 20 22 25 73 2f 74 6b 74 68 69  ",.    "%s/tkthi
4660: 73 74 6f 72 79 2f 25 73 22 2c 20 67 2e 7a 54 6f  story/%s", g.zTo
4670: 70 2c 20 7a 55 75 69 64 29 3b 0a 20 20 73 74 79  p, zUuid);.  sty
4680: 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d 65  le_submenu_eleme
4690: 6e 74 28 22 53 74 61 74 75 73 22 2c 20 22 53 74  nt("Status", "St
46a0: 61 74 75 73 22 2c 0a 20 20 20 20 22 25 73 2f 69  atus",.    "%s/i
46b0: 6e 66 6f 2f 25 73 22 2c 20 67 2e 7a 54 6f 70 2c  nfo/%s", g.zTop,
46c0: 20 7a 55 75 69 64 29 3b 0a 20 20 7a 54 69 74 6c   zUuid);.  zTitl
46d0: 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 54 69 6d  e = mprintf("Tim
46e0: 65 6c 69 6e 65 20 4f 66 20 54 69 63 6b 65 74 20  eline Of Ticket 
46f0: 25 68 22 2c 20 7a 55 75 69 64 29 3b 0a 20 20 73  %h", zUuid);.  s
4700: 74 79 6c 65 5f 68 65 61 64 65 72 28 7a 54 69 74  tyle_header(zTit
4710: 6c 65 29 3b 0a 20 20 66 72 65 65 28 7a 54 69 74  le);.  free(zTit
4720: 6c 65 29 3b 0a 0a 20 20 74 61 67 69 64 20 3d 20  le);..  tagid = 
4730: 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43  db_int(0, "SELEC
4740: 54 20 74 61 67 69 64 20 46 52 4f 4d 20 74 61 67  T tagid FROM tag
4750: 20 57 48 45 52 45 20 74 61 67 6e 61 6d 65 20 47   WHERE tagname G
4760: 4c 4f 42 20 27 74 6b 74 2d 25 71 2a 27 22 2c 7a  LOB 'tkt-%q*'",z
4770: 55 75 69 64 29 3b 0a 20 20 69 66 28 20 74 61 67  Uuid);.  if( tag
4780: 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 40 20 4e  id==0 ){.    @ N
4790: 6f 20 73 75 63 68 20 74 69 63 6b 65 74 3a 20 25  o such ticket: %
47a0: 68 28 7a 55 75 69 64 29 0a 20 20 20 20 73 74 79  h(zUuid).    sty
47b0: 6c 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 20 20 20  le_footer();.   
47c0: 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 7a   return;.  }.  z
47d0: 53 51 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 25  SQL = mprintf("%
47e0: 73 20 41 4e 44 20 65 76 65 6e 74 2e 6f 62 6a 69  s AND event.obji
47f0: 64 20 49 4e 20 22 0a 20 20 20 20 20 20 20 20 20  d IN ".         
4800: 20 20 20 20 20 20 20 20 22 20 20 28 53 45 4c 45          "  (SELE
4810: 43 54 20 72 69 64 20 46 52 4f 4d 20 74 61 67 78  CT rid FROM tagx
4820: 72 65 66 20 57 48 45 52 45 20 74 61 67 69 64 3d  ref WHERE tagid=
4830: 25 64 29 20 22 0a 20 20 20 20 20 20 20 20 20 20  %d) ".          
4840: 20 20 20 20 20 20 20 22 4f 52 44 45 52 20 42 59         "ORDER BY
4850: 20 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20 20   mtime DESC",.  
4860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74                 t
4870: 69 6d 65 6c 69 6e 65 5f 71 75 65 72 79 5f 66 6f  imeline_query_fo
4880: 72 5f 77 77 77 28 29 2c 20 74 61 67 69 64 29 3b  r_www(), tagid);
4890: 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71  .  db_prepare(&q
48a0: 2c 20 7a 53 51 4c 29 3b 0a 20 20 66 72 65 65 28  , zSQL);.  free(
48b0: 7a 53 51 4c 29 3b 0a 20 20 77 77 77 5f 70 72 69  zSQL);.  www_pri
48c0: 6e 74 5f 74 69 6d 65 6c 69 6e 65 28 26 71 29 3b  nt_timeline(&q);
48d0: 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26  .  db_finalize(&
48e0: 71 29 3b 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74  q);.  style_foot
48f0: 65 72 28 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57  er();.}../*.** W
4900: 45 42 50 41 47 45 3a 20 74 6b 74 68 69 73 74 6f  EBPAGE: tkthisto
4910: 72 79 0a 2a 2a 20 55 52 4c 3a 20 2f 74 6b 74 68  ry.** URL: /tkth
4920: 69 73 74 6f 72 79 3f 6e 61 6d 65 3d 54 49 43 4b  istory?name=TICK
4930: 45 54 55 55 49 44 0a 2a 2a 0a 2a 2a 20 53 68 6f  ETUUID.**.** Sho
4940: 77 20 74 68 65 20 63 6f 6d 70 6c 65 74 65 20 63  w the complete c
4950: 68 61 6e 67 65 20 68 69 73 74 6f 72 79 20 66 6f  hange history fo
4960: 72 20 61 20 73 69 6e 67 6c 65 20 74 69 63 6b 65  r a single ticke
4970: 74 0a 2a 2f 0a 76 6f 69 64 20 74 6b 74 68 69 73  t.*/.void tkthis
4980: 74 6f 72 79 5f 70 61 67 65 28 76 6f 69 64 29 7b  tory_page(void){
4990: 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 63 68 61  .  Stmt q;.  cha
49a0: 72 20 2a 7a 54 69 74 6c 65 3b 0a 20 20 63 6f 6e  r *zTitle;.  con
49b0: 73 74 20 63 68 61 72 20 2a 7a 55 75 69 64 3b 0a  st char *zUuid;.
49c0: 20 20 69 6e 74 20 74 61 67 69 64 3b 0a 0a 20 20    int tagid;..  
49d0: 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64  login_check_cred
49e0: 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69 66 28  entials();.  if(
49f0: 20 21 67 2e 6f 6b 48 69 73 74 6f 72 79 20 7c 7c   !g.okHistory ||
4a00: 20 21 67 2e 6f 6b 52 64 54 6b 74 20 29 7b 20 6c   !g.okRdTkt ){ l
4a10: 6f 67 69 6e 5f 6e 65 65 64 65 64 28 29 3b 20 72  ogin_needed(); r
4a20: 65 74 75 72 6e 3b 20 7d 0a 20 20 7a 55 75 69 64  eturn; }.  zUuid
4a30: 20 3d 20 50 44 28 22 6e 61 6d 65 22 2c 22 22 29   = PD("name","")
4a40: 3b 0a 20 20 7a 54 69 74 6c 65 20 3d 20 6d 70 72  ;.  zTitle = mpr
4a50: 69 6e 74 66 28 22 48 69 73 74 6f 72 79 20 4f 66  intf("History Of
4a60: 20 54 69 63 6b 65 74 20 25 68 22 2c 20 7a 55 75   Ticket %h", zUu
4a70: 69 64 29 3b 0a 20 20 73 74 79 6c 65 5f 73 75 62  id);.  style_sub
4a80: 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 53 74  menu_element("St
4a90: 61 74 75 73 22 2c 20 22 53 74 61 74 75 73 22 2c  atus", "Status",
4aa0: 0a 20 20 20 20 22 25 73 2f 69 6e 66 6f 2f 25 73  .    "%s/info/%s
4ab0: 22 2c 20 67 2e 7a 54 6f 70 2c 20 7a 55 75 69 64  ", g.zTop, zUuid
4ac0: 29 3b 0a 20 20 73 74 79 6c 65 5f 73 75 62 6d 65  );.  style_subme
4ad0: 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 54 69 6d 65  nu_element("Time
4ae0: 6c 69 6e 65 22 2c 20 22 54 69 6d 65 6c 69 6e 65  line", "Timeline
4af0: 22 2c 0a 20 20 20 20 22 25 73 2f 74 6b 74 74 69  ",.    "%s/tktti
4b00: 6d 65 6c 69 6e 65 3f 6e 61 6d 65 3d 25 73 22 2c  meline?name=%s",
4b10: 20 67 2e 7a 54 6f 70 2c 20 7a 55 75 69 64 29 3b   g.zTop, zUuid);
4b20: 0a 20 20 73 74 79 6c 65 5f 68 65 61 64 65 72 28  .  style_header(
4b30: 7a 54 69 74 6c 65 29 3b 0a 20 20 66 72 65 65 28  zTitle);.  free(
4b40: 7a 54 69 74 6c 65 29 3b 0a 0a 20 20 74 61 67 69  zTitle);..  tagi
4b50: 64 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22 53  d = db_int(0, "S
4b60: 45 4c 45 43 54 20 74 61 67 69 64 20 46 52 4f 4d  ELECT tagid FROM
4b70: 20 74 61 67 20 57 48 45 52 45 20 74 61 67 6e 61   tag WHERE tagna
4b80: 6d 65 20 47 4c 4f 42 20 27 74 6b 74 2d 25 71 2a  me GLOB 'tkt-%q*
4b90: 27 22 2c 7a 55 75 69 64 29 3b 0a 20 20 69 66 28  '",zUuid);.  if(
4ba0: 20 74 61 67 69 64 3d 3d 30 20 29 7b 0a 20 20 20   tagid==0 ){.   
4bb0: 20 40 20 4e 6f 20 73 75 63 68 20 74 69 63 6b 65   @ No such ticke
4bc0: 74 3a 20 25 68 28 7a 55 75 69 64 29 0a 20 20 20  t: %h(zUuid).   
4bd0: 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b   style_footer();
4be0: 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d  .    return;.  }
4bf0: 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71  .  db_prepare(&q
4c00: 2c 0a 20 20 20 20 22 53 45 4c 45 43 54 20 6f 62  ,.    "SELECT ob
4c10: 6a 69 64 2c 20 75 75 69 64 20 46 52 4f 4d 20 65  jid, uuid FROM e
4c20: 76 65 6e 74 2c 20 62 6c 6f 62 22 0a 20 20 20 20  vent, blob".    
4c30: 22 20 57 48 45 52 45 20 6f 62 6a 69 64 20 49 4e  " WHERE objid IN
4c40: 20 28 53 45 4c 45 43 54 20 72 69 64 20 46 52 4f   (SELECT rid FRO
4c50: 4d 20 74 61 67 78 72 65 66 20 57 48 45 52 45 20  M tagxref WHERE 
4c60: 74 61 67 69 64 3d 25 64 29 22 0a 20 20 20 20 22  tagid=%d)".    "
4c70: 20 20 20 41 4e 44 20 62 6c 6f 62 2e 72 69 64 3d     AND blob.rid=
4c80: 65 76 65 6e 74 2e 6f 62 6a 69 64 22 0a 20 20 20  event.objid".   
4c90: 20 22 20 4f 52 44 45 52 20 42 59 20 6d 74 69 6d   " ORDER BY mtim
4ca0: 65 20 44 45 53 43 22 2c 0a 20 20 20 20 74 61 67  e DESC",.    tag
4cb0: 69 64 0a 20 20 29 3b 0a 20 20 77 68 69 6c 65 28  id.  );.  while(
4cc0: 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51   db_step(&q)==SQ
4cd0: 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20  LITE_ROW ){.    
4ce0: 42 6c 6f 62 20 63 6f 6e 74 65 6e 74 3b 0a 20 20  Blob content;.  
4cf0: 20 20 4d 61 6e 69 66 65 73 74 20 6d 3b 0a 20 20    Manifest m;.  
4d00: 20 20 69 6e 74 20 72 69 64 20 3d 20 64 62 5f 63    int rid = db_c
4d10: 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29  olumn_int(&q, 0)
4d20: 3b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72  ;.    const char
4d30: 20 2a 7a 43 68 6e 67 55 75 69 64 20 3d 20 64 62   *zChngUuid = db
4d40: 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c  _column_text(&q,
4d50: 20 31 29 3b 0a 20 20 20 20 63 6f 6e 74 65 6e 74   1);.    content
4d60: 5f 67 65 74 28 72 69 64 2c 20 26 63 6f 6e 74 65  _get(rid, &conte
4d70: 6e 74 29 3b 0a 20 20 20 20 69 66 28 20 6d 61 6e  nt);.    if( man
4d80: 69 66 65 73 74 5f 70 61 72 73 65 28 26 6d 2c 20  ifest_parse(&m, 
4d90: 26 63 6f 6e 74 65 6e 74 29 20 26 26 20 6d 2e 74  &content) && m.t
4da0: 79 70 65 3d 3d 43 46 54 59 50 45 5f 54 49 43 4b  ype==CFTYPE_TICK
4db0: 45 54 20 29 7b 0a 20 20 20 20 20 20 63 68 61 72  ET ){.      char
4dc0: 20 2a 7a 44 61 74 65 20 3d 20 64 62 5f 74 65 78   *zDate = db_tex
4dd0: 74 28 30 2c 20 22 53 45 4c 45 43 54 20 64 61 74  t(0, "SELECT dat
4de0: 65 74 69 6d 65 28 25 2e 31 32 66 29 22 2c 20 6d  etime(%.12f)", m
4df0: 2e 72 44 61 74 65 29 3b 0a 20 20 20 20 20 20 63  .rDate);.      c
4e00: 68 61 72 20 7a 55 75 69 64 5b 31 32 5d 3b 0a 20  har zUuid[12];. 
4e10: 20 20 20 20 20 6d 65 6d 63 70 79 28 7a 55 75 69       memcpy(zUui
4e20: 64 2c 20 7a 43 68 6e 67 55 75 69 64 2c 20 31 30  d, zChngUuid, 10
4e30: 29 3b 0a 20 20 20 20 20 20 7a 55 75 69 64 5b 31  );.      zUuid[1
4e40: 30 5d 20 3d 20 30 3b 0a 20 20 20 20 20 20 40 0a  0] = 0;.      @.
4e50: 20 20 20 20 20 20 40 20 3c 70 3e 25 73 28 7a 44        @ <p>%s(zD
4e60: 61 74 65 29 0a 20 20 20 20 20 20 40 20 5b 3c 61  ate).      @ [<a
4e70: 20 68 72 65 66 3d 22 25 73 28 67 2e 7a 54 6f 70   href="%s(g.zTop
4e80: 29 2f 61 72 74 69 66 61 63 74 2f 25 54 28 7a 43  )/artifact/%T(zC
4e90: 68 6e 67 55 75 69 64 29 22 3e 25 73 28 7a 55 75  hngUuid)">%s(zUu
4ea0: 69 64 29 3c 2f 61 3e 5d 3c 2f 61 3e 0a 20 20 20  id)</a>]</a>.   
4eb0: 20 20 20 40 20 62 79 20 25 68 28 6d 2e 7a 55 73     @ by %h(m.zUs
4ec0: 65 72 29 3a 3c 2f 70 3e 0a 20 20 20 20 20 20 40  er):</p>.      @
4ed0: 0a 20 20 20 20 20 20 66 72 65 65 28 7a 44 61 74  .      free(zDat
4ee0: 65 29 3b 0a 20 20 20 20 20 20 74 69 63 6b 65 74  e);.      ticket
4ef0: 5f 6f 75 74 70 75 74 5f 63 68 61 6e 67 65 5f 61  _output_change_a
4f00: 72 74 69 66 61 63 74 28 26 6d 29 3b 0a 20 20 20  rtifact(&m);.   
4f10: 20 7d 0a 20 20 20 20 6d 61 6e 69 66 65 73 74 5f   }.    manifest_
4f20: 63 6c 65 61 72 28 26 6d 29 3b 0a 20 20 7d 0a 20  clear(&m);.  }. 
4f30: 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29   db_finalize(&q)
4f40: 3b 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72  ;.  style_footer
4f50: 28 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74  ();.}../*.** Ret
4f60: 75 72 6e 20 54 52 55 45 20 69 66 20 74 68 65 20  urn TRUE if the 
4f70: 67 69 76 65 6e 20 42 4c 4f 42 20 63 6f 6e 74 61  given BLOB conta
4f80: 69 6e 73 20 61 20 6e 65 77 6c 69 6e 65 20 63 68  ins a newline ch
4f90: 61 72 61 63 74 65 72 2e 0a 2a 2f 0a 73 74 61 74  aracter..*/.stat
4fa0: 69 63 20 69 6e 74 20 63 6f 6e 74 61 69 6e 73 5f  ic int contains_
4fb0: 6e 65 77 6c 69 6e 65 28 42 6c 6f 62 20 2a 70 29  newline(Blob *p)
4fc0: 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  {.  const char *
4fd0: 7a 20 3d 20 62 6c 6f 62 5f 73 74 72 28 70 29 3b  z = blob_str(p);
4fe0: 0a 20 20 77 68 69 6c 65 28 20 2a 7a 20 29 7b 0a  .  while( *z ){.
4ff0: 20 20 20 20 69 66 28 20 2a 7a 3d 3d 27 5c 6e 27      if( *z=='\n'
5000: 20 29 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20   ) return 1;.   
5010: 20 7a 2b 2b 3b 0a 20 20 7d 0a 20 20 72 65 74 75   z++;.  }.  retu
5020: 72 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54  rn 0;.}../*.** T
5030: 68 65 20 70 54 6b 74 20 6f 62 6a 65 63 74 20 69  he pTkt object i
5040: 73 20 61 20 74 69 63 6b 65 74 20 63 68 61 6e 67  s a ticket chang
5050: 65 20 61 72 74 69 66 61 63 74 2e 20 20 4f 75 74  e artifact.  Out
5060: 70 75 74 20 61 20 64 65 74 61 69 6c 65 64 0a 2a  put a detailed.*
5070: 2a 20 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66  * description of
5080: 20 74 68 69 73 20 6f 62 6a 65 63 74 2e 0a 2a 2f   this object..*/
5090: 0a 76 6f 69 64 20 74 69 63 6b 65 74 5f 6f 75 74  .void ticket_out
50a0: 70 75 74 5f 63 68 61 6e 67 65 5f 61 72 74 69 66  put_change_artif
50b0: 61 63 74 28 4d 61 6e 69 66 65 73 74 20 2a 70 54  act(Manifest *pT
50c0: 6b 74 29 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20  kt){.  int i;.  
50d0: 40 20 3c 6f 6c 3e 0a 20 20 66 6f 72 28 69 3d 30  @ <ol>.  for(i=0
50e0: 3b 20 69 3c 70 54 6b 74 2d 3e 6e 46 69 65 6c 64  ; i<pTkt->nField
50f0: 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 42 6c 6f 62  ; i++){.    Blob
5100: 20 76 61 6c 3b 0a 20 20 20 20 63 6f 6e 73 74 20   val;.    const 
5110: 63 68 61 72 20 2a 7a 3b 0a 20 20 20 20 7a 20 3d  char *z;.    z =
5120: 20 70 54 6b 74 2d 3e 61 46 69 65 6c 64 5b 69 5d   pTkt->aField[i]
5130: 2e 7a 4e 61 6d 65 3b 0a 20 20 20 20 62 6c 6f 62  .zName;.    blob
5140: 5f 73 65 74 28 26 76 61 6c 2c 20 70 54 6b 74 2d  _set(&val, pTkt-
5150: 3e 61 46 69 65 6c 64 5b 69 5d 2e 7a 56 61 6c 75  >aField[i].zValu
5160: 65 29 3b 0a 20 20 20 20 69 66 28 20 7a 5b 30 5d  e);.    if( z[0]
5170: 3d 3d 27 2b 27 20 29 7b 0a 20 20 20 20 20 20 40  =='+' ){.      @
5180: 20 3c 6c 69 3e 41 70 70 65 6e 64 65 64 20 74 6f   <li>Appended to
5190: 20 25 68 28 26 7a 5b 31 5d 29 3a 3c 62 6c 6f 63   %h(&z[1]):<bloc
51a0: 6b 71 75 6f 74 65 3e 0a 20 20 20 20 20 20 77 69  kquote>.      wi
51b0: 6b 69 5f 63 6f 6e 76 65 72 74 28 26 76 61 6c 2c  ki_convert(&val,
51c0: 20 30 2c 20 30 29 3b 0a 20 20 20 20 20 20 40 20   0, 0);.      @ 
51d0: 3c 2f 62 6c 6f 63 6b 71 75 6f 74 65 3e 3c 2f 6c  </blockquote></l
51e0: 69 3e 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28  i>.    }else if(
51f0: 20 62 6c 6f 62 5f 73 69 7a 65 28 26 76 61 6c 29   blob_size(&val)
5200: 3c 3d 35 30 20 26 26 20 63 6f 6e 74 61 69 6e 73  <=50 && contains
5210: 5f 6e 65 77 6c 69 6e 65 28 26 76 61 6c 29 20 29  _newline(&val) )
5220: 7b 0a 20 20 20 20 20 20 40 20 3c 6c 69 3e 43 68  {.      @ <li>Ch
5230: 61 6e 67 65 20 25 68 28 7a 29 20 74 6f 3a 3c 62  ange %h(z) to:<b
5240: 6c 6f 63 6b 71 75 6f 74 65 3e 0a 20 20 20 20 20  lockquote>.     
5250: 20 77 69 6b 69 5f 63 6f 6e 76 65 72 74 28 26 76   wiki_convert(&v
5260: 61 6c 2c 20 30 2c 20 30 29 3b 0a 20 20 20 20 20  al, 0, 0);.     
5270: 20 40 20 3c 2f 62 6c 6f 63 6b 71 75 6f 74 65 3e   @ </blockquote>
5280: 3c 2f 6c 69 3e 0a 20 20 20 20 7d 65 6c 73 65 7b  </li>.    }else{
5290: 0a 20 20 20 20 20 20 40 20 3c 6c 69 3e 43 68 61  .      @ <li>Cha
52a0: 6e 67 65 20 25 68 28 7a 29 20 74 6f 20 22 25 68  nge %h(z) to "%h
52b0: 28 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 29 29  (blob_str(&val))
52c0: 22 3c 2f 6c 69 3e 0a 20 20 20 20 7d 0a 20 20 20  "</li>.    }.   
52d0: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76 61 6c   blob_reset(&val
52e0: 29 3b 0a 20 20 7d 0a 20 20 40 20 3c 2f 6f 6c 3e  );.  }.  @ </ol>
52f0: 0a 7d 0a                                         .}.