| | @@ -27,10 +27,19 @@ |
| 27 | 27 | |
| 28 | 28 | #ifndef SQLITE_RECURSIVE |
| 29 | 29 | # define SQLITE_RECURSIVE 33 |
| 30 | 30 | #endif |
| 31 | 31 | |
| 32 | +/* Settings that can be used to control ticket reports */ |
| 33 | +/* |
| 34 | +** SETTING: ticket-search-empty-report-number width=10 default=0 |
| 35 | +** |
| 36 | +** If this setting has an integer value of N, then when the ticket |
| 37 | +** search page query is blank, the report with rn=N is shown. |
| 38 | +** If N is zero, then no report is shown. |
| 39 | +*/ |
| 40 | + |
| 32 | 41 | /* |
| 33 | 42 | ** WEBPAGE: reportlist |
| 34 | 43 | ** |
| 35 | 44 | ** Main menu for Tickets. |
| 36 | 45 | */ |
| | @@ -982,12 +991,23 @@ |
| 982 | 991 | ** corresponding to REPORTFMT.RN. If the tablist query parameter exists, |
| 983 | 992 | ** then the output consists of lines of tab-separated fields instead of |
| 984 | 993 | ** an HTML table. |
| 985 | 994 | */ |
| 986 | 995 | void rptview_page(void){ |
| 996 | + rptview_page_content(0, 1, 1); |
| 997 | +} |
| 998 | + |
| 999 | +/* |
| 1000 | +** Render a report. |
| 1001 | +*/ |
| 1002 | +void rptview_page_content( |
| 1003 | + int rn, /* Report number. If 0, retrieve from rn query parameter. */ |
| 1004 | + int pageWrap, /* If true, render full page; otherwise, just the report */ |
| 1005 | + int redirectMissing /* If true and report not found, go to reportlist */ |
| 1006 | +){ |
| 987 | 1007 | int count = 0; |
| 988 | | - int rn, rc; |
| 1008 | + int rc; |
| 989 | 1009 | char *zSql; |
| 990 | 1010 | char *zTitle; |
| 991 | 1011 | char *zOwner; |
| 992 | 1012 | char *zClrKey; |
| 993 | 1013 | int tabs; |
| | @@ -996,13 +1016,16 @@ |
| 996 | 1016 | char *zErr2 = 0; |
| 997 | 1017 | |
| 998 | 1018 | login_check_credentials(); |
| 999 | 1019 | if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; } |
| 1000 | 1020 | tabs = P("tablist")!=0; |
| 1021 | + if ( rn==0 ) { |
| 1022 | + rn = atoi(PD("rn","0")); |
| 1023 | + } |
| 1001 | 1024 | db_prepare(&q, |
| 1002 | 1025 | "SELECT title, sqlcode, owner, cols, rn FROM reportfmt WHERE rn=%d", |
| 1003 | | - atoi(PD("rn","0"))); |
| 1026 | + rn); |
| 1004 | 1027 | rc = db_step(&q); |
| 1005 | 1028 | if( rc!=SQLITE_ROW ){ |
| 1006 | 1029 | db_finalize(&q); |
| 1007 | 1030 | db_prepare(&q, |
| 1008 | 1031 | "SELECT title, sqlcode, owner, cols, rn FROM reportfmt WHERE title GLOB %Q", |
| | @@ -1009,11 +1032,13 @@ |
| 1009 | 1032 | P("title")); |
| 1010 | 1033 | rc = db_step(&q); |
| 1011 | 1034 | } |
| 1012 | 1035 | if( rc!=SQLITE_ROW ){ |
| 1013 | 1036 | db_finalize(&q); |
| 1014 | | - cgi_redirect("reportlist"); |
| 1037 | + if (redirectMissing) { |
| 1038 | + cgi_redirect("reportlist"); |
| 1039 | + } |
| 1015 | 1040 | return; |
| 1016 | 1041 | } |
| 1017 | 1042 | zTitle = db_column_malloc(&q, 0); |
| 1018 | 1043 | zSql = db_column_malloc(&q, 1); |
| 1019 | 1044 | zOwner = db_column_malloc(&q, 2); |
| | @@ -1041,29 +1066,31 @@ |
| 1041 | 1066 | struct GenerateHTML sState = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 1042 | 1067 | const char *zQS = PD("QUERY_STRING",""); |
| 1043 | 1068 | |
| 1044 | 1069 | db_multi_exec("PRAGMA empty_result_callbacks=ON"); |
| 1045 | 1070 | style_set_current_feature("report"); |
| 1046 | | - /* style_finish_page() should provide escaping via %h formatting */ |
| 1047 | | - if( zQS[0] ){ |
| 1048 | | - style_submenu_element("Raw","%R/%s?tablist=1&%s",g.zPath,zQS); |
| 1049 | | - style_submenu_element("Reports","%R/reportlist?%s",zQS); |
| 1050 | | - } else { |
| 1051 | | - style_submenu_element("Raw","%R/%s?tablist=1",g.zPath); |
| 1052 | | - style_submenu_element("Reports","%R/reportlist"); |
| 1053 | | - } |
| 1054 | | - if( g.perm.Admin |
| 1055 | | - || (g.perm.TktFmt && g.zLogin && fossil_strcmp(g.zLogin,zOwner)==0) ){ |
| 1056 | | - style_submenu_element("Edit", "rptedit?rn=%d", rn); |
| 1057 | | - } |
| 1058 | | - if( g.perm.TktFmt ){ |
| 1059 | | - style_submenu_element("SQL", "rptsql?rn=%d",rn); |
| 1060 | | - } |
| 1061 | | - if( g.perm.NewTkt ){ |
| 1062 | | - style_submenu_element("New Ticket", "%R/tktnew"); |
| 1063 | | - } |
| 1064 | | - style_header("%s", zTitle); |
| 1071 | + if ( pageWrap ) { |
| 1072 | + /* style_finish_page() should provide escaping via %h formatting */ |
| 1073 | + if( zQS[0] ){ |
| 1074 | + style_submenu_element("Raw","%R/%s?tablist=1&%s",g.zPath,zQS); |
| 1075 | + style_submenu_element("Reports","%R/reportlist?%s",zQS); |
| 1076 | + } else { |
| 1077 | + style_submenu_element("Raw","%R/%s?tablist=1",g.zPath); |
| 1078 | + style_submenu_element("Reports","%R/reportlist"); |
| 1079 | + } |
| 1080 | + if( g.perm.Admin |
| 1081 | + || (g.perm.TktFmt && g.zLogin && fossil_strcmp(g.zLogin,zOwner)==0) ){ |
| 1082 | + style_submenu_element("Edit", "rptedit?rn=%d", rn); |
| 1083 | + } |
| 1084 | + if( g.perm.TktFmt ){ |
| 1085 | + style_submenu_element("SQL", "rptsql?rn=%d",rn); |
| 1086 | + } |
| 1087 | + if( g.perm.NewTkt ){ |
| 1088 | + style_submenu_element("New Ticket", "%R/tktnew"); |
| 1089 | + } |
| 1090 | + style_header("%s", zTitle); |
| 1091 | + } |
| 1065 | 1092 | output_color_key(zClrKey, 1, |
| 1066 | 1093 | "border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\""); |
| 1067 | 1094 | @ <table border="1" cellpadding="2" cellspacing="0" class="report sortable" |
| 1068 | 1095 | @ data-column-types='' data-init-sort='0'> |
| 1069 | 1096 | sState.rn = rn; |
| | @@ -1076,11 +1103,13 @@ |
| 1076 | 1103 | @ <p class="reportError">Error: %h(zErr1)</p> |
| 1077 | 1104 | }else if( zErr2 ){ |
| 1078 | 1105 | @ <p class="reportError">Error: %h(zErr2)</p> |
| 1079 | 1106 | } |
| 1080 | 1107 | style_table_sorter(); |
| 1081 | | - style_finish_page(); |
| 1108 | + if ( pageWrap ) { |
| 1109 | + style_finish_page(); |
| 1110 | + } |
| 1082 | 1111 | }else{ |
| 1083 | 1112 | report_restrict_sql(&zErr1); |
| 1084 | 1113 | db_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2); |
| 1085 | 1114 | report_unrestrict_sql(); |
| 1086 | 1115 | cgi_set_content_type("text/plain"); |
| 1087 | 1116 | |