Fossil

Diff
Login

Differences From Artifact [9edb9c555b]:

To Artifact [5cf854bdf5]:


450
451
452
453
454
455
456
457

458
459
460
461
462
463
464
  const char *zOwner;           /* Owner of the report */
  const char *zClrKey;          /* Color key - used to add colors to lines */
  char *zSQL;                   /* The SQL text that gnerates the report */
  char *zErr = 0;               /* An error message */
  const char *zDesc;            /* Extra descriptive text about the report */
  const char *zMimetype;        /* Mimetype for zDesc */
  const char *zTag;             /* Symbolic name for this report */
  int dflt = P("dflt") ? 1 : 0;


  login_check_credentials();
  if( !g.perm.TktFmt ){
    login_needed(g.anon.TktFmt);
    return;
  }
  style_set_current_feature("report");







|
>







450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
  const char *zOwner;           /* Owner of the report */
  const char *zClrKey;          /* Color key - used to add colors to lines */
  char *zSQL;                   /* The SQL text that gnerates the report */
  char *zErr = 0;               /* An error message */
  const char *zDesc;            /* Extra descriptive text about the report */
  const char *zMimetype;        /* Mimetype for zDesc */
  const char *zTag;             /* Symbolic name for this report */
  int dflt = P("dflt") ? 1 : 0; /* Is this the default report */
  int quickfilter = P("quickfilter") ? 1 : 0; /* Show the quickfilter */

  login_check_credentials();
  if( !g.perm.TktFmt ){
    login_needed(g.anon.TktFmt);
    return;
  }
  style_set_current_feature("report");
519
520
521
522
523
524
525
526

527
528
529
530
531
532
533

534
535
536
537
538
539
540
541
      if( zTag && zTag[0]==0 ) zTag = 0;
      if( zDesc && zDesc[0]==0 ){ zDesc = 0; zMimetype = 0; }
      if( zMimetype && zMimetype[0]==0 ){ zDesc = 0; zMimetype = 0; }
      if( rn>0 ){
        db_multi_exec(
            "UPDATE reportfmt SET title=%Q, sqlcode=%Q,"
            " owner=%Q, cols=%Q, mtime=now(), "
            " jx=json_patch(jx,json_object('desc',%Q,'descmt',%Q,'tag',%Q))"

            " WHERE rn=%d",
           zTitle, zSQL, zOwner, zClrKey, zDesc, zMimetype, zTag, rn);
      }else{
        db_multi_exec(
           "INSERT INTO reportfmt(title,sqlcode,owner,cols,mtime,jx) "
           "VALUES(%Q,%Q,%Q,%Q,now(),"
                  "json_object('desc',%Q,'descmt',%Q,'tag',%Q))",

           zTitle, zSQL, zOwner, zClrKey, zDesc, zMimetype, zTag);
        rn = db_last_insert_rowid();
      }
      if( dflt ){
        db_set("ticket-default-report", zTitle, 0);
      }else{
        char *defaultReport = db_get("ticket-default-report", 0);
        if( fossil_strcmp(zTitle, defaultReport)==0 ){







|
>

|




|
>
|







520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
      if( zTag && zTag[0]==0 ) zTag = 0;
      if( zDesc && zDesc[0]==0 ){ zDesc = 0; zMimetype = 0; }
      if( zMimetype && zMimetype[0]==0 ){ zDesc = 0; zMimetype = 0; }
      if( rn>0 ){
        db_multi_exec(
            "UPDATE reportfmt SET title=%Q, sqlcode=%Q,"
            " owner=%Q, cols=%Q, mtime=now(), "
            " jx=json_patch(jx,json_object('desc',%Q,'descmt',%Q,'tag',%Q,"
            " 'quickfilter',%d))"
            " WHERE rn=%d",
           zTitle, zSQL, zOwner, zClrKey, zDesc, zMimetype, zTag, quickfilter, rn);
      }else{
        db_multi_exec(
           "INSERT INTO reportfmt(title,sqlcode,owner,cols,mtime,jx) "
           "VALUES(%Q,%Q,%Q,%Q,now(),"
                  "json_object('desc',%Q,'descmt',%Q,'tag',%Q,"
                  "'quickfilter',%d))",
           zTitle, zSQL, zOwner, zClrKey, zDesc, zMimetype, zTag, quickfilter);
        rn = db_last_insert_rowid();
      }
      if( dflt ){
        db_set("ticket-default-report", zTitle, 0);
      }else{
        char *defaultReport = db_get("ticket-default-report", 0);
        if( fossil_strcmp(zTitle, defaultReport)==0 ){
564
565
566
567
568
569
570
571

572
573
574
575
576

577
578
579
580
581
582
583
      zOwner = db_column_malloc(&q, 2);
      zClrKey = db_column_malloc(&q, 3);
      dflt = fossil_strcmp(zTitle, defaultReport)==0;
      hasJx = db_column_int(&q, 4);
    }
    db_finalize(&q);
    if( hasJx ){
      db_prepare(&q, "SELECT jx->>'desc', jx->>'descmt', jx->>'tag'"

                     "  FROM reportfmt WHERE rn=%d", rn);
      if( db_step(&q)==SQLITE_ROW ){
        zDesc = db_column_malloc(&q, 0);
        zMimetype = db_column_malloc(&q, 1);
        zTag = db_column_malloc(&q, 2);

      }
      db_finalize(&q);
    }
    if( P("copy") ){
      rn = 0;
      zTitle = mprintf("Copy Of %s", zTitle);
      zOwner = g.zLogin;







|
>





>







567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
      zOwner = db_column_malloc(&q, 2);
      zClrKey = db_column_malloc(&q, 3);
      dflt = fossil_strcmp(zTitle, defaultReport)==0;
      hasJx = db_column_int(&q, 4);
    }
    db_finalize(&q);
    if( hasJx ){
      db_prepare(&q, "SELECT jx->>'desc', jx->>'descmt', jx->>'tag',"
                     "  jx->>'quickfilter'"
                     "  FROM reportfmt WHERE rn=%d", rn);
      if( db_step(&q)==SQLITE_ROW ){
        zDesc = db_column_malloc(&q, 0);
        zMimetype = db_column_malloc(&q, 1);
        zTag = db_column_malloc(&q, 2);
        quickfilter = db_column_int(&q, 3);
      }
      db_finalize(&q);
    }
    if( P("copy") ){
      rn = 0;
      zTitle = mprintf("Copy Of %s", zTitle);
      zOwner = g.zLogin;
625
626
627
628
629
630
631




632
633
634
635
636
637
638
  mimetype_option_menu(zMimetype, "m");
  @ <br><textarea aria-label="Description:" name="d" class="wikiedit" \
  @ cols="80" rows="15" wrap="virtual">%h(zDesc)</textarea>
  @ </p>

  @ <p><label><input type="checkbox" name="dflt" %s(dflt?"checked":"")> \
  @ Make this the default report</label></p>




  if( !g.perm.Admin && fossil_strcmp(zOwner,g.zLogin)!=0 ){
    @ <p>This report format is owned by %h(zOwner).  You are not allowed
    @ to change it.</p>
    @ </form>
    report_format_hints();
    style_finish_page();
    return;







>
>
>
>







630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
  mimetype_option_menu(zMimetype, "m");
  @ <br><textarea aria-label="Description:" name="d" class="wikiedit" \
  @ cols="80" rows="15" wrap="virtual">%h(zDesc)</textarea>
  @ </p>

  @ <p><label><input type="checkbox" name="dflt" %s(dflt?"checked":"")> \
  @ Make this the default report</label></p>

  @ <p><label><input type="checkbox" name="quickfilter" %s(quickfilter?"checked":"")> \
  @ Show the quickfilter for this report.</label></p>

  if( !g.perm.Admin && fossil_strcmp(zOwner,g.zLogin)!=0 ){
    @ <p>This report format is owned by %h(zOwner).  You are not allowed
    @ to change it.</p>
    @ </form>
    report_format_hints();
    style_finish_page();
    return;
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165

1166
1167
1168
1169
1170
1171
1172
  int rn, rc;
  char *zSql;
  char *zTitle;
  char *zOwner;
  char *zClrKey;
  char *zDesc;
  char *zMimetype;
  int tabs;
  Stmt q;
  char *zErr1 = 0;
  char *zErr2 = 0;

  login_check_credentials();
  if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; }
  report_update_reportfmt_table();
  rn = report_number();
  tabs = P("tablist")!=0;
  db_prepare(&q,
    "SELECT title, sqlcode, owner, cols, rn, jx->>'desc', jx->>'descmt'"
    "  FROM reportfmt WHERE rn=%d", rn);
  rc = db_step(&q);
  if( rc!=SQLITE_ROW ){
    const char *titleSearch =
      defaultTitleSearch==0 || trim_string(defaultTitleSearch)[0]==0 ?
        P("title") : defaultTitleSearch;
    db_finalize(&q);
    db_prepare(&q,
      "SELECT title, sqlcode, owner, cols, rn, jx->>'desc', jx->>'descmt'"
      "  FROM reportfmt WHERE title GLOB %Q",
      titleSearch);
    rc = db_step(&q);
  }
  if( rc!=SQLITE_ROW ){
    db_finalize(&q);
    if( redirectMissing ) {
      cgi_redirect("reportlist");
    }
    return;
  }
  zTitle = db_column_malloc(&q, 0);
  zSql = db_column_malloc(&q, 1);
  zOwner = db_column_malloc(&q, 2);
  zClrKey = db_column_malloc(&q, 3);
  rn = db_column_int(&q,4);
  zDesc = db_column_malloc(&q, 5);
  zMimetype = db_column_malloc(&q, 6);

  db_finalize(&q);

  if( P("order_by") ){
    /*
    ** If the user wants to do a column sort, wrap the query into a sub
    ** query and then sort the results. This is a whole lot easier than
    ** trying to insert an ORDER BY into the query itself, especially







|










|
|







|
|

















>







1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
  int rn, rc;
  char *zSql;
  char *zTitle;
  char *zOwner;
  char *zClrKey;
  char *zDesc;
  char *zMimetype;
  int tabs, quickfilter;
  Stmt q;
  char *zErr1 = 0;
  char *zErr2 = 0;

  login_check_credentials();
  if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; }
  report_update_reportfmt_table();
  rn = report_number();
  tabs = P("tablist")!=0;
  db_prepare(&q,
    "SELECT title, sqlcode, owner, cols, rn, jx->>'desc', jx->>'descmt',"
    "  jx->>'quickfilter' FROM reportfmt WHERE rn=%d", rn);
  rc = db_step(&q);
  if( rc!=SQLITE_ROW ){
    const char *titleSearch =
      defaultTitleSearch==0 || trim_string(defaultTitleSearch)[0]==0 ?
        P("title") : defaultTitleSearch;
    db_finalize(&q);
    db_prepare(&q,
      "SELECT title, sqlcode, owner, cols, rn, jx->>'desc', jx->>'descmt',"
      "  jx->>'quickfilter' FROM reportfmt WHERE title GLOB %Q",
      titleSearch);
    rc = db_step(&q);
  }
  if( rc!=SQLITE_ROW ){
    db_finalize(&q);
    if( redirectMissing ) {
      cgi_redirect("reportlist");
    }
    return;
  }
  zTitle = db_column_malloc(&q, 0);
  zSql = db_column_malloc(&q, 1);
  zOwner = db_column_malloc(&q, 2);
  zClrKey = db_column_malloc(&q, 3);
  rn = db_column_int(&q,4);
  zDesc = db_column_malloc(&q, 5);
  zMimetype = db_column_malloc(&q, 6);
  quickfilter = db_column_int(&q, 7);
  db_finalize(&q);

  if( P("order_by") ){
    /*
    ** If the user wants to do a column sort, wrap the query into a sub
    ** query and then sort the results. This is a whole lot easier than
    ** trying to insert an ORDER BY into the query itself, especially
1222
1223
1224
1225
1226
1227
1228

1229

1230
1231
1232
1233
1234
1235
1236
1237

1238

1239
1240
1241
1242
1243
1244
1245
      blob_init(&src, zDesc, -1);
      wiki_render_by_mimetype(&src, zMimetype);
      blob_reset(&src);
      @ <br>
    }
    output_color_key(zClrKey, 1,
        "border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\"");

    @ <input type="text" id="quickfilter" placeholder="filter ticket list..." style="display: none">

    @ <table border="1" cellpadding="2" cellspacing="0" class="report sortable filterlist"
    @  data-column-types='' data-init-sort='0'>
    sState.rn = rn;
    sState.nCount = 0;
    report_restrict_sql(&zErr1);
    db_exec_readonly(g.db, zSql, generate_html, &sState, &zErr2);
    report_unrestrict_sql();
    @ </tbody></table>

    style_quickfilter();

    if( zErr1 ){
      @ <p class="reportError">Error: %h(zErr1)</p>
    }else if( zErr2 ){
      @ <p class="reportError">Error: %h(zErr2)</p>
    }
    style_table_sorter();
    if( pageWrap ) {







>
|
>








>
|
>







1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
      blob_init(&src, zDesc, -1);
      wiki_render_by_mimetype(&src, zMimetype);
      blob_reset(&src);
      @ <br>
    }
    output_color_key(zClrKey, 1,
        "border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\"");
    if( quickfilter ){
      @ <input type="text" id="quickfilter" placeholder="filter ticket list...">
    }
    @ <table border="1" cellpadding="2" cellspacing="0" class="report sortable filterlist"
    @  data-column-types='' data-init-sort='0'>
    sState.rn = rn;
    sState.nCount = 0;
    report_restrict_sql(&zErr1);
    db_exec_readonly(g.db, zSql, generate_html, &sState, &zErr2);
    report_unrestrict_sql();
    @ </tbody></table>
    if( quickfilter ){
      style_quickfilter();
    }
    if( zErr1 ){
      @ <p class="reportError">Error: %h(zErr1)</p>
    }else if( zErr2 ){
      @ <p class="reportError">Error: %h(zErr2)</p>
    }
    style_table_sorter();
    if( pageWrap ) {