Diff
Not logged in

Differences From:

File src/tkt.c part of check-in [f394d84560] - Update SQLite to the latest build from CVS. Add in the FTS3 extension, though it is not yet being used. Additional work toward tickets. by drh on 2007-11-25 16:13:52. [view]

To:

File src/tkt.c part of check-in [5f3ddcc1b8] - Add ticket configuration editing capability. by drh on 2007-11-25 21:11:33. Also file src/tkt.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46. [view]

@@ -305,14 +305,20 @@
 }
 
 /*
 ** WEBPAGE: tktview
+**
+** View a ticket.
 */
 void tktview_page(void){
   char *zScript;
   int nScript;
   login_check_credentials();
   if( !g.okRdTkt ){ login_needed(); return; }
+  if( g.okWrTkt ){
+    style_submenu_element("Edit", "Edit The Ticket", "%s/tktedit?name=%T",
+        g.zTop, PD("name",""));
+  }
   style_header("View Ticket");
   ticket_init();
   initializeVariablesFromDb();
   zScript = (char*)SbS_Fetch(pInterp, "tktview_template", -1, &nScript);
@@ -422,8 +428,16 @@
 
 /*
 ** WEBPAGE: tktnew
 ** WEBPAGE: debug_tktnew
+**
+** Enter a new ticket.  the tktnew_template script in the ticket
+** configuration is used.  The /tktnew page is the official ticket
+** entry page.  The /debug_tktnew page is used for debugging the
+** tktnew_template in the ticket configuration.  /debug_tktnew works
+** just like /tktnew except that it does not really save the new ticket
+** when you press submit - it just prints the ticket artifact at the
+** top of the screen.
 */
 void tktnew_page(void){
   char *zScript;
   int nScript;
@@ -448,13 +462,18 @@
   @ </form>
   style_footer();
 }
 
-
-
 /*
 ** WEBPAGE: tktedit
 ** WEBPAGE: debug_tktedit
+**
+** Edit a ticket.  The ticket is identified by the name CGI parameter.
+** /tktedit is the official page.  The /debug_tktedit page does the same
+** thing except that it does not save the ticket change record when you
+** press submit - it instead prints the ticket change record at the top
+** of the page.  The /debug_tktedit page is intended to be used when
+** debugging ticket configurations.
 */
 void tktedit_page(void){
   char *zScript;
   int nScript;
@@ -501,5 +520,62 @@
     return;
   }
   @ </form>
   style_footer();
+}
+
+/*
+** Check the ticket configuration in zConfig to see if it appears to
+** be well-formed.  If everything is OK, return NULL.  If something is
+** amiss, then return a pointer to a string (obtained from malloc) that
+** describes the problem.
+*/
+char *ticket_config_check(const char *zConfig){
+  struct Subscript *p;
+  char *zErr = 0;
+  const char *z;
+  int n;
+  int i;
+  int rc;
+  sqlite3 *db;
+  static const char *azRequired[] = {
+     "tktnew_template",
+     "tktview_template",
+     "tktedit_template",
+  };
+
+  p = SbS_Create();
+  rc = SbS_Eval(p, zConfig, strlen(zConfig));
+  if( rc!=SBS_OK ){
+    zErr = mprintf("%s", SbS_GetErrorMessage(p));
+    SbS_Destroy(p);
+    return zErr;
+  }
+  for(i=0; i<sizeof(azRequired)/sizeof(azRequired[0]); i++){
+    z = SbS_Fetch(p, azRequired[i], -1, &n);
+    if( z==0 ){
+      zErr = mprintf("missing definition: %s", azRequired[i]);
+      SbS_Destroy(p);
+      return zErr;
+    }
+  }
+  z = SbS_Fetch(p, "ticket_sql", -1, &n);
+  if( z==0 ){
+    zErr = mprintf("missing definition: ticket_sql");
+    SbS_Destroy(p);
+    return zErr;
+  }
+  rc = sqlite3_open(":memory:", &db);
+  if( rc==SQLITE_OK ){
+    char *zSql = mprintf("%.*s", n, z);
+    rc = sqlite3_exec(db, zSql, 0, 0, &zErr);
+    if( rc!=SQLITE_OK ){
+      sqlite3_close(db);
+      SbS_Destroy(p);
+      return zErr;
+    }
+    /* TODO: verify that the TICKET table exists and has required fields */
+    sqlite3_close(db);
+  }
+  SbS_Destroy(p);
+  return 0;
 }