Bug 34478: Add 'op' to reports/guided_reports - WIP

Bug 34478: [TO SQUASH] Add 'op' to reports/guided_reports

Found bug 36071 when working on this. This is not a regression from this
patch.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2024-02-09 12:23:59 +01:00
parent c16e579d48
commit 8a20e0cb6a
Signed by: jonathan.druart
GPG key ID: A085E712BEF0E0F0
7 changed files with 378 additions and 391 deletions

View file

@ -4,7 +4,7 @@
<h5>Run reports</h5> <h5>Run reports</h5>
<ul> <ul>
[% IF ( CAN_user_reports_execute_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a></li>[% END %] [% IF ( CAN_user_reports_execute_reports ) %]<li><a href="/cgi-bin/koha/reports/guided_reports.pl?op=list">Saved reports</a></li>[% END %]
</ul> </ul>
<h5>Reports dictionary</h5> <h5>Reports dictionary</h5>
<ul> <ul>

View file

@ -7,13 +7,13 @@
<ul> <ul>
<li><a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports</a></li> <li><a href="/cgi-bin/koha/reports/guided_reports.pl">Guided reports</a></li>
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build new</a></li> <li><a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form">Build new</a></li>
[% END %] [% END %]
[% IF ( CAN_user_reports_execute_reports ) %] [% IF ( CAN_user_reports_execute_reports ) %]
<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Use saved</a></li> <li><a href="/cgi-bin/koha/reports/guided_reports.pl?op=list">Use saved</a></li>
[% END %] [% END %]
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
<li><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create%20report%20from%20SQL">Create from SQL</a></li> <li><a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form_sql">Create from SQL</a></li>
[% END %] [% END %]
</ul> </ul>

View file

@ -3,8 +3,8 @@
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-plus"></i> New report <span class="caret"></span></button> <button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-plus"></i> New report <span class="caret"></span></button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li id="newmenuc"><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">New guided report</a> </li> <li id="newmenuc"><a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form">New guided report</a> </li>
<li id="newsql"><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create%20report%20from%20SQL">New SQL report</a> </li> <li id="newsql"><a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form_sql">New SQL report</a> </li>
[% IF Koha.Preference('Mana')==1 %] [% IF Koha.Preference('Mana')==1 %]
<li id="new_mana_sql"><a href="#" data-toggle="modal" data-target="#mana_search_result">New SQL from Mana</a> </li> <li id="new_mana_sql"><a href="#" data-toggle="modal" data-target="#mana_search_result">New SQL from Mana</a> </li>
[% END %] [% END %]
@ -15,9 +15,13 @@
[% IF ( showsql || execute || editsql || save_successful ) %] [% IF ( showsql || execute || editsql || save_successful ) %]
[% IF ( CAN_user_reports_delete_reports && !CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_delete_reports && !CAN_user_reports_create_reports ) %]
<div class="btn-group"> <div class="btn-group">
<a class="delete btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&phase=Delete%20Saved"> <form>
<i class="fa fa-trash-can"></i> Delete <input type="hidden" name="op" value="cud-delete" />
</a> <input type="hidden" name="id" value="[% id | html %]" />
<button type="submit" class="delete btn btn-default">
<i class="fa fa-trash-can"></i> Delete
</button>
</form>
</div> </div>
[% ELSE %] [% ELSE %]
[% IF ( CAN_user_reports_create_reports || CAN_user_reports_delete_reports ) %] [% IF ( CAN_user_reports_create_reports || CAN_user_reports_delete_reports ) %]
@ -30,13 +34,13 @@
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
[% UNLESS ( editsql ) # Do not show edit button on edit page %] [% UNLESS ( editsql ) # Do not show edit button on edit page %]
<li> <li>
<a id="editreport" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&amp;phase=Edit%20SQL"> <a id="editreport" href="/cgi-bin/koha/reports/guided_reports.pl?id=[% id | html %]&amp;op=edit_form">
Edit Edit
</a> </a>
</li> </li>
[% END %] [% END %]
<li> <li>
<a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=[% id | uri %]"> <a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?op=duplicate&amp;id=[% id | uri %]">
Duplicate Duplicate
</a> </a>
</li> </li>
@ -44,9 +48,12 @@
[% IF ( CAN_user_reports_delete_reports ) %] [% IF ( CAN_user_reports_delete_reports ) %]
<li> <li>
<a class="delete" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&phase=Delete%20Saved"> <form method="post" action="/cgi-bin/koha/reports/guided_reports.pl">
Delete [% INCLUDE 'csrf-token.inc' %]
</a> <input type="hidden" name="op" value="cud-delete" />
<input type="hidden" name="id" value="[% id | html %]" />
</form>
<a href="#" class="delete">Delete</button>
</li> </li>
[% END %] [% END %]
</ul> </ul>
@ -58,7 +65,7 @@
[% IF ( showsql || execute || editsql || save_successful ) %] [% IF ( showsql || execute || editsql || save_successful ) %]
[% UNLESS ( errors ) # Unless there are errors saving a report %] [% UNLESS ( errors ) # Unless there are errors saving a report %]
<div class="btn-group"> <div class="btn-group">
<a id="runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&amp;phase=Run%20this%20report"> <a id="runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?id=[% id | html %]&amp;op=run">
<i class="fa fa-play"></i> Run report <i class="fa fa-play"></i> Run report
</a> </a>
</div> </div>
@ -71,7 +78,7 @@
<ul class="dropdown-menu"> <ul class="dropdown-menu">
[% FOREACH t IN templates %] [% FOREACH t IN templates %]
<li> <li>
<a id="runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&amp;phase=Run%20this%20report&amp;template=[% t.id | html %][% PROCESS params %]"> <a id="runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?id=[% id | html %]&amp;op=run&amp;template=[% t.id | html %][% PROCESS params %]">
[% t.name | html %] [% t.name | html %]
</a> </a>
</li> </li>
@ -130,11 +137,11 @@
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-default dropdown-toggle" aria-haspopup="menu" aria-label="Select format and download report results" data-toggle="dropdown" id="format"><i class="fa fa-download"></i> Download <span class="caret"></span></button> <button class="btn btn-default dropdown-toggle" aria-haspopup="menu" aria-label="Select format and download report results" data-toggle="dropdown" id="format"><i class="fa fa-download"></i> Download <span class="caret"></span></button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=csv&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">[% PROCESS 'delimiter_text.inc' %]</a></li> <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?op=export&amp;format=csv&amp;id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">[% PROCESS 'delimiter_text.inc' %]</a></li>
<li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=tab&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Tab separated text</a></li> <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?op=export&amp;format=tab&amp;id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Tab separated text</a></li>
<li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=ods&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li> <li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?op=export&amp;format=ods&amp;id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li>
[% IF processed_notice_title %] [% IF processed_notice_title %]
<li><a id="template" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=template&amp;report_id=[% id | html %]&amp;template=[% template_id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Rendered template ([% processed_notice_title | html %])</a></li> <li><a id="template" href="/cgi-bin/koha/reports/guided_reports.pl?op=export&amp;format=template&amp;id=[% id | html %]&amp;template=[% template_id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Rendered template ([% processed_notice_title | html %])</a></li>
[% END %] [% END %]
[% IF (results.json) %] [% IF (results.json) %]
<li><a id="download-chart" href="#">Chart (.svg)</a></li> <li><a id="download-chart" href="#">Chart (.svg)</a></li>
@ -151,7 +158,7 @@
<a class="btn btn-default" href="#" data-toggle="modal" data-target="#chartModal"><i class="fa fa-chart-bar"></i> Create chart</a> <a class="btn btn-default" href="#" data-toggle="modal" data-target="#chartModal"><i class="fa fa-chart-bar"></i> Create chart</a>
[% ELSE %] [% ELSE %]
<a class="btn btn-default" href="#" data-toggle="modal" data-target="#chartModal"><i class="fa fa-chart-bar"></i> Create chart</a> <a class="btn btn-default" href="#" data-toggle="modal" data-target="#chartModal"><i class="fa fa-chart-bar"></i> Create chart</a>
<a class="btn btn-default fetch_chart_data" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | html %]&amp;phase=Run this report&amp;reportname=[% name |uri %][% PROCESS params %]&amp;want_full_chart=1"><i class="fa fa-chart-bar"></i> Fetch all data for chart</a> <a class="btn btn-default fetch_chart_data" href="/cgi-bin/koha/reports/guided_reports.pl?id=[% id | html %]&amp;op=run&amp;reportname=[% name |uri %][% PROCESS params %]&amp;want_full_chart=1"><i class="fa fa-chart-bar"></i> Fetch all data for chart</a>
[% END %] [% END %]
</div> </div>

View file

@ -94,7 +94,7 @@
[% END %] [% END %]
[% IF ( showsql || editsql || execute ) %] [% IF ( showsql || editsql || execute ) %]
[% WRAPPER breadcrumb_item %] [% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved">Saved reports</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=list">Saved reports</a>
[% END %] [% END %]
[% END %] [% END %]
[% IF ( saved1 ) %] [% IF ( saved1 ) %]
@ -111,21 +111,21 @@
[% END %] [% END %]
[% ELSIF ( editsql ) %] [% ELSIF ( editsql ) %]
[% WRAPPER breadcrumb_item %] [% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% reportname | html %] ([% id | html %])</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?id=[% id | uri %]&amp;op=show">[% reportname | html %] ([% id | html %])</a>
[% END %] [% END %]
[% WRAPPER breadcrumb_item bc_active= 1 %] [% WRAPPER breadcrumb_item bc_active= 1 %]
<span>Edit</span> <span>Edit</span>
[% END %] [% END %]
[% ELSIF ( execute ) %] [% ELSIF ( execute ) %]
[% WRAPPER breadcrumb_item %] [% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% id | uri %]&amp;phase=Show%20SQL">[% name | html %] ([% id | html %])</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?id=[% id | uri %]&amp;op=show">[% name | html %] ([% id | html %])</a>
[% END %] [% END %]
[% WRAPPER breadcrumb_item bc_active= 1 %] [% WRAPPER breadcrumb_item bc_active= 1 %]
<span>Run</span> <span>Run</span>
[% END %] [% END %]
[% ELSIF ( build1 || build2 || build3 || build4 || build5 || build6 ) %] [% ELSIF ( build1 || build2 || build3 || build4 || build5 || build6 ) %]
[% WRAPPER breadcrumb_item %] [% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a report</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form">Build a report</a>
[% END %] [% END %]
[% WRAPPER breadcrumb_item bc_active= 1 %] [% WRAPPER breadcrumb_item bc_active= 1 %]
[% IF ( build1 ) %] [% IF ( build1 ) %]
@ -179,32 +179,20 @@
<h3>Build and run reports</h3> <h3>Build and run reports</h3>
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
<form method="get" action="/cgi-bin/koha/reports/guided_reports.pl"> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form" class="btn btn-primary"/>Build new</a>
<input type="hidden" name="phase" value="Build new" />
<input type="submit" name="submit" class="btn btn-primary" value="Build new" />
</form>
[% END %] [% END %]
[% IF ( CAN_user_reports_execute_reports ) %] [% IF ( CAN_user_reports_execute_reports ) %]
<form method="get" action="/cgi-bin/koha/reports/guided_reports.pl"> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=list" class="btn btn-primary"/>Used saved</a>
<input type="hidden" name="phase" value="Use saved"/>
<input type="submit" name="submit" class="btn btn-primary" value="Use saved" />
</form>
[% END %] [% END %]
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
<form method="get" action="/cgi-bin/koha/reports/guided_reports.pl"> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form_sql" class="btn btn-primary"/>Create report from SQL</a>
<input type="hidden" name="phase" value="Create report from SQL"/>
<input type="submit" name="submit" class="btn btn-primary" value="Create report from SQL" />
</form>
[% END %] [% END %]
<h3>Reports Dictionary</h3> <h3>Reports Dictionary</h3>
<p>Use the reports dictionary to define custom criteria to use in your reports</p> <p>Use the reports dictionary to define custom criteria to use in your reports</p>
<form method="get" action="/cgi-bin/koha/reports/dictionary.pl"> <a href="/cgi-bin/koha/reports/dictionary.pl?op=list" class="btn btn-primary"/>View dictionary</a>
<input type="hidden" name="phase" value="View Dictionary"/>
<input type="submit" name="submit" class="btn btn-primary" value="View dictionary" />
</form>
[% END # /IF (start) %] [% END # /IF (start) %]
[% IF report_converted %] [% IF report_converted %]
@ -235,7 +223,7 @@
[% IF ( filters.keyword ) %] [% IF ( filters.keyword ) %]
<span class="filter_keyword"><strong>Keyword:</strong> [% filters.keyword | html %]</span> <span class="filter_keyword"><strong>Keyword:</strong> [% filters.keyword | html %]</span>
[% END %] [% END %]
<a class="clear_filter" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&clear_filters=1"><i class="fa fa-times"></i> Clear</a> <a class="clear_filter" href="/cgi-bin/koha/reports/guided_reports.pl?op=list&clear_filters=1"><i class="fa fa-times"></i> Clear</a>
</span> </span>
</p> </p>
[% END %] [% END %]
@ -268,7 +256,7 @@
<form action="/cgi-bin/koha/reports/guided_reports.pl" id="reports_form" method="post"> <form action="/cgi-bin/koha/reports/guided_reports.pl" id="reports_form" method="post">
[% INCLUDE 'csrf-token.inc' %] [% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="phase" value="Delete Multiple" /> <input type="hidden" name="op" value="cud-delete" />
<table id="table_reports"> <table id="table_reports">
<thead> <thead>
<tr> <tr>
@ -304,12 +292,12 @@
[% UNLESS ( loop.odd ) %]<tr class="odd">[% ELSE %]<tr>[% END %] [% UNLESS ( loop.odd ) %]<tr class="odd">[% ELSE %]<tr>[% END %]
<td class="report_checkbox"> <td class="report_checkbox">
[% IF ( CAN_user_reports_delete_reports ) %] <!-- not break CSS --> [% IF ( CAN_user_reports_delete_reports ) %] <!-- not break CSS -->
<input type="checkbox" name="ids" id="ids[% savedreport.id | html %]" value="[% savedreport.id | html %]" /> <input type="checkbox" name="id" id="id_[% savedreport.id | html %]" value="[% savedreport.id | html %]" />
[% END %] [% END %]
<input type="hidden" class="report_sql" value="[% savedreport.savedsql |html %]"> <input type="hidden" class="report_sql" value="[% savedreport.savedsql |html %]">
</td> </td>
<td class="report_id"> <td class="report_id">
<label for="ids[% savedreport.id | html %]">[% savedreport.id | html %]</label> <label for="id_[% savedreport.id | html %]">[% savedreport.id | html %]</label>
</td> </td>
<td class="report_name"> <td class="report_name">
[% IF ( savedreport.report_name ) %] [% IF ( savedreport.report_name ) %]
@ -362,41 +350,48 @@
</td> </td>
<td> <td>
[% FOR result IN savedreport.results %] [% FOR result IN savedreport.results %]
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&amp;id=[% result.id | uri %]">[% result.date_run | html %]</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=retrieve_results&amp;id=[% result.id | uri %]">[% result.date_run | html %]</a>
<br/> <br/>
[% END %] [% END %]
</td> </td>
<td> <td>
[% IF savedreport.seems_obsolete %] [% IF savedreport.seems_obsolete %]
This report seems obsolete, it uses biblioitems.marcxml field. This report seems obsolete, it uses biblioitems.marcxml field.
<a href="/cgi-bin/koha/svc/convert_report?report_id=[% savedreport.id | uri %]" data-report_id="[% savedreport.id | html %]" class="update_sql btn btn-default btn-xs" title="Update SQL"><i class="fa-solid fa-eye"></i> Update SQL</a> <a href="/cgi-bin/koha/svc/convert_report?id=[% savedreport.id | uri %]" data-report_id="[% savedreport.id | html %]" class="update_sql btn btn-default btn-xs" title="Update SQL"><i class="fa-solid fa-eye"></i> Update SQL</a>
[% END %] [% END %]
</td> </td>
<td> <td>
<div class="btn-group dropup"> <div class="btn-group dropup">
[%# There should be no space between these two buttons, it would render badly %] [%# There should be no space between these two buttons, it would render badly %]
<a class="btn btn-default btn-xs" role="button" <a class="btn btn-default btn-xs" role="button"
href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&amp;phase=Run%20this%20report"><i href="/cgi-bin/koha/reports/guided_reports.pl?id=[% savedreport.id | html %]&amp;op=run"><i
class="fa fa-play"></i> Run</a><a class="fa fa-play"></i> Run</a><a
class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-toggle="dropdown" class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-toggle="dropdown"
href="#"><b class="caret"></b></a> href="#"><b class="caret"></b></a>
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]"> <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]">
<li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&amp;phase=Show%20SQL"><i class="fa fa-search"></i> View</a></li> <li><a href="/cgi-bin/koha/reports/guided_reports.pl?id=[% savedreport.id | uri %]&amp;op=show"><i class="fa fa-search"></i> View</a></li>
<li> <li>
<a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&phase=Show%20SQL" class="preview_sql" data-reportid="[% savedreport.id | html %]"> <a href="/cgi-bin/koha/reports/guided_reports.pl?id=[% savedreport.id | uri %]&op=show" class="preview_sql" data-reportid="[% savedreport.id | html %]">
<i class="fa-solid fa-eye"></i> Preview SQL <i class="fa-solid fa-eye"></i> Preview SQL
</a> </a>
</li> </li>
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
<li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&amp;phase=Edit%20SQL"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a></li> <li><a href="/cgi-bin/koha/reports/guided_reports.pl?id=[% savedreport.id | uri %]&amp;op=edit_form"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a></li>
<li><a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=[% savedreport.id | uri %]"><i class="fa fa-copy"></i> Duplicate</a></li> <li><a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?op=duplicate&amp;id=[% savedreport.id | uri %]"><i class="fa fa-copy"></i> Duplicate</a></li>
[% END %] [% END %]
[% IF (Koha.Preference('Mana') == 1) %] [% IF (Koha.Preference('Mana') == 1) %]
<li><a class="ShareButton" data-toggle="modal" href="#mana_share_report" title="Share your report with Mana Knowledge Base"><i class="fa fa-share-alt"></i> Share</a></li> <li><a class="ShareButton" data-toggle="modal" href="#mana_share_report" title="Share your report with Mana Knowledge Base"><i class="fa fa-share-alt"></i> Share</a></li>
[% END %] [% END %]
<li><a href="/cgi-bin/koha/tools/scheduler.pl?id=[% savedreport.id | uri %]"><i class="fa-solid fa-clock"></i> Schedule</a></li> <li><a href="/cgi-bin/koha/tools/scheduler.pl?id=[% savedreport.id | uri %]"><i class="fa-solid fa-clock"></i> Schedule</a></li>
[% IF ( CAN_user_reports_delete_reports ) %] [% IF ( CAN_user_reports_delete_reports ) %]
<li><a class="confirmdelete" title="Delete this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&amp;phase=Delete%20Saved"><i class="fa fa-trash-can"></i> Delete</a></li> <li>
<form method="post" action="/cgi-bin/koha/reports/guided_reports.pl">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-delete" />
<input type="hidden" name="id" value="[% savedreport.id | html %]" />
</form>
<a href="#" class="delete" title="Delete this saved report"><i class="fa fa-trash-can"></i> Delete</a>
</li>
[% END %] [% END %]
</ul> </ul>
</div> </div>
@ -425,27 +420,16 @@
[% IF (filter_set || filters.date || filters.author || filters.keyword) %] [% IF (filter_set || filters.date || filters.author || filters.keyword) %]
<h4>No saved reports match your criteria. </h4> <h4>No saved reports match your criteria. </h4>
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
<form action="/cgi-bin/koha/reports/guided_reports.pl" method="get"> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form" class="new btn btn-default"><i class="fa fa-plus"></i> New guided report</a>
<input type="hidden" name="phase" value="Build new" />
<button type="submit" class="new"><i class="fa fa-plus"></i> New guided report</button>
</form>
<form action="/cgi-bin/koha/reports/guided_reports.pl" method="get"> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form_sql" class="new btn btn-default"><i class="fa fa-plus"></i> New SQL report</a>
<input type="hidden" name="phase" value="Create report from SQL" />
<button type="submit" class="new"><i class="fa fa-plus"></i> New SQL report</button>
</form>
<form action="/cgi-bin/koha/reports/guided_reports.pl" method="get"> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=list&filter_set=1&filter_keywork=" class="deny btn btn-default"><i class="fa fa-fw fa-times"></i> Cancel filter</a>
<input type="hidden" name="phase" value="Use saved" />
<input type="hidden" name="filter_set" value="1" />
<input type="hidden" name="filter_keyword" value="" />
<button type="submit" class="deny"><i class="fa fa-fw fa-times"></i> Cancel filter</button>
</form>
[% END %] [% END %]
[% ELSE %] [% ELSE %]
<h4>There are no saved reports. </h4> <h4>There are no saved reports. </h4>
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">Build a new report?</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form">Build a new report?</a>
[% END %] [% END %]
[% END # IF (filter_set || filters.date || filters.author || filters.keyword) %] [% END # IF (filter_set || filters.date || filters.author || filters.keyword) %]
</div> <!-- /.dialog.message --> </div> <!-- /.dialog.message -->
@ -462,7 +446,8 @@
[% END %] [% END %]
<h1>Build a report</h1> <h1>Build a report</h1>
<form method="get" action="/cgi-bin/koha/reports/guided_reports.pl"> <form method="post" action="/cgi-bin/koha/reports/guided_reports.pl">
[% INCLUDE 'csrf-token.inc' %]
<fieldset class="rows"> <fieldset class="rows">
<legend>Step 1 of 6: Choose a module to report on,[% IF (usecache) %] Set cache expiry, [% END %] and choose report visibility </legend> <legend>Step 1 of 6: Choose a module to report on,[% IF (usecache) %] Set cache expiry, [% END %] and choose report visibility </legend>
<ol> <ol>
@ -507,8 +492,8 @@
</ol> </ol>
</fieldset> <!-- /.rows --> </fieldset> <!-- /.rows -->
<fieldset class="action"> <fieldset class="action">
<input type="hidden" name="phase" value="Report on this Area" /> <input type="hidden" name="op" value="cud-report" />
<input type="submit" name="submit" value="Next &gt;&gt;" /> <button type="submit" class="btn btn-primary" />Next &gt;&gt;</button>
</fieldset> </fieldset>
</form> </form>
[% END # /build1 %] [% END # /build1 %]
@ -535,9 +520,9 @@
</fieldset> </fieldset>
<fieldset class="action"> <fieldset class="action">
<input type="hidden" name="phase" value="Choose this type" /> <input type="hidden" name="op" value="cud-choose_type" />
<input type="button" name="back" value="&lt;&lt; Back" class="goback" /> <button type="submit" class="btn btn-default goback" name="back">&lt;&lt; Back</button>
<input type="submit" name="submit" value="Next &gt;&gt;" /> <button type="submit" class="btn btn-primary" />Next &gt;&gt;</button>
</fieldset> </fieldset>
</form> </form>
[% END # /IF (build2 ) %] [% END # /IF (build2 ) %]
@ -591,9 +576,9 @@
</div> <!-- /.row --> </div> <!-- /.row -->
</fieldset> </fieldset>
<fieldset class="action"> <fieldset class="action">
<input type="hidden" name="phase" value="Choose these columns" /> <input type="hidden" name="op" value="cud-choose_columns" />
<input type="button" name="back" value="&lt;&lt; Back" class="goback" /> <button type="submit" class="btn btn-default goback" name="back">&lt;&lt; Back</button>
<input type="submit" name="submit" value="Next &gt;&gt;" /> <button type="submit" class="btn btn-primary" />Next &gt;&gt;</button>
</fieldset> </fieldset>
</form> <!-- /#column_submit --> </form> <!-- /#column_submit -->
[% END # /IF ( build3 ) %] [% END # /IF ( build3 ) %]
@ -679,9 +664,9 @@
[% END %] [% END %]
<fieldset class="action"> <fieldset class="action">
<input type="hidden" name="phase" value="Choose these criteria" /> <input type="hidden" name="op" value="cud-choose_criteria" />
<input type="button" name="back" value="&lt;&lt; Back" class="goback" /> <button type="submit" class="btn btn-default goback" name="back">&lt;&lt; Back</button>
<input type="submit" name="submit" value="Next &gt;&gt;" /> <button type="submit" class="btn btn-primary" />Next &gt;&gt;</button>
</fieldset> </fieldset>
</form> </form>
[% END # /IF ( build4 ) %] [% END # /IF ( build4 ) %]
@ -718,9 +703,9 @@
</table> </table>
</fieldset> </fieldset>
<fieldset class="action"><input type="hidden" name="phase" value="Choose these operations" /> <fieldset class="action"><input type="hidden" name="op" value="cud-choose_operations" />
<input type="button" name="back" value="&lt;&lt; Back" class="goback" /> <button type="submit" class="btn btn-default goback" name="back">&lt;&lt; Back</button>
<input type="submit" name="submit" value="Next &gt;&gt;" /> <button type="submit" class="btn btn-primary" />Next &gt;&gt;</button>
</fieldset> </fieldset>
</form> </form>
[% END # /IF ( build5 ) %] [% END # /IF ( build5 ) %]
@ -758,7 +743,7 @@
</table> </table>
</fieldset> </fieldset>
<fieldset class="action"> <fieldset class="action">
<input type="hidden" name="phase" value="Build report" /> <input type="hidden" name="op" value="cud-build_report" />
<input type="submit" name="submit" class="btn btn-primary" value="Finish" /> <input type="submit" name="submit" class="btn btn-primary" value="Finish" />
</fieldset> </fieldset>
</form> </form>
@ -778,7 +763,7 @@
<input type="hidden" name="public" value="[% public | html %]" /> <input type="hidden" name="public" value="[% public | html %]" />
<input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" /> <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
<p>You will need to save the report before you can execute it</p> <p>You will need to save the report before you can execute it</p>
<fieldset class="action"><input type="hidden" name="phase" value="Save" /> <fieldset class="action"><input type="hidden" name="op" value="cud-save" />
<input type="submit" name="submit" class="btn btn-primary" value="Next" /> <input type="submit" name="submit" class="btn btn-primary" value="Next" />
</fieldset> </fieldset>
</form> </form>
@ -807,7 +792,7 @@
</li> </li>
</ol> </ol>
</fieldset> </fieldset>
<fieldset class="action"><input type="hidden" name="phase" value="Save Report" /> <fieldset class="action"><input type="hidden" name="op" value="cud-save" />
<input type="submit" name="submit" class="btn btn-primary" value="Save report" /> <input type="submit" name="submit" class="btn btn-primary" value="Save report" />
</fieldset> </fieldset>
</form> </form>
@ -835,39 +820,38 @@
<input type='hidden' name='cache_expiry' value='[% cache_expiry | html %]' /> <input type='hidden' name='cache_expiry' value='[% cache_expiry | html %]' />
<input type='hidden' name='cache_expiry_units' value='[% cache_expiry_units | html %]' /> <input type='hidden' name='cache_expiry_units' value='[% cache_expiry_units | html %]' />
<input type='hidden' name='public' value='[% public | html %]' /> <input type='hidden' name='public' value='[% public | html %]' />
[% IF ( phase_update) %] [% IF ( op == 'update') %]
<input type='hidden' name='phase' value='update_sql' /> <input type='hidden' name='op' value='cud-update' />
<button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button> <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
[% ELSIF ( phase_save) %] [% ELSIF ( op == 'save') %]
<input type='hidden' name='area' value='[% area | html %]' /> <input type='hidden' name='area' value='[% area | html %]' />
<input type='hidden' name='phase' value='Save Report' /> <input type='hidden' name='op' value='cud-save' />
<button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button> <button type="submit" name="save_anyway" value="Save anyway" class="approve"><i class="fa fa-fw fa-check"></i> Save anyway</button>
[% END %] [% END %]
</form> </form>
<!-- Go back to editing --> <!-- Go back to editing -->
<form method="get" action='/cgi-bin/koha/reports/guided_reports.pl'> <a href="/cgi-bin/koha/reports/guided_reports.pl" class="btn btn-default new goback"><i class="fa-fw fa-solid fa-pencil" aria-hidden="true"></i> Edit SQL</a>
<button type="button" class="new goback"><i class="fa-fw fa-solid fa-pencil" aria-hidden="true"></i> Edit SQL</button>
</form>
</div> </div>
[% END # /IF ( warn_authval_problem )%] [% END # /IF ( warn_authval_problem )%]
[% IF ( enter_params ) %] [% IF ( enter_params ) %]
<form method="get" action='/cgi-bin/koha/reports/guided_reports.pl'> [% IF ( auth_val_error ) %]
<input type='hidden' name='reports' value="[% reports | html %]" /> <div class="dialog alert">
[% IF ( auth_val_error ) %] <h3>Errors found when processing parameters for report: [% name | html %]</h3>
<input type='hidden' name='phase' value='Edit SQL' /> [% FOREACH auth_val_error IN auth_val_errors %]
<div class="dialog alert"> <p>
<h3>Errors found when processing parameters for report: [% name | html %]</h3> <strong>[% auth_val_error.entry | html %]:</strong> The authorized value category (<strong>[% auth_val_error.auth_val | html %]</strong>)
[% FOREACH auth_val_error IN auth_val_errors %] you selected does not exist.
<p> </p>
<strong>[% auth_val_error.entry | html %]:</strong> The authorized value category (<strong>[% auth_val_error.auth_val | html %]</strong>) [% END %]
you selected does not exist. </div>
</p> <fieldset class="action">
[% END %] <a href="/cgi-bin/koha/reports/guided_reports.pl?op=edit_formid=[% id | uri %]" class="btn btn-primary">Edit SQL</a>
</div> </fieldset>
<fieldset class="action"><input type="submit" class="btn btn-primary" value="Edit SQL" /></fieldset> [% ELSE # IF ( auth_val_error ) %]
[% ELSE # IF ( auth_val_error ) %] <form method="post" action='/cgi-bin/koha/reports/guided_reports.pl'>
<input type='hidden' name='phase' value='Run this report' /> <input type='hidden' name='id' value="[% id | html %]" />
<input type='hidden' name='op' value='cud-run' />
<h1>Enter parameters for report [% name | html %]:</h1> <h1>Enter parameters for report [% name | html %]:</h1>
[% IF ( notes ) %] [% IF ( notes ) %]
<p>[% notes | html %]</p> <p>[% notes | html %]</p>
@ -907,10 +891,11 @@
</ol> </ol>
</fieldset> <!-- /.rows --> </fieldset> <!-- /.rows -->
<fieldset class="action"> <fieldset class="action">
<input type="submit" class="btn btn-primary" value="Run the report" /> <input type="hidden" name="op" value="cud-run" />
<button type="submit" class="btn btn-primary">Run the report</button>
</fieldset> </fieldset>
[% END # / IF ( auth_val_error ) %] </form>
</form> [% END # / IF ( auth_val_error ) %]
[% END # /IF ( enter_params ) %] [% END # /IF ( enter_params ) %]
[% IF processed_notice %] [% IF processed_notice %]
@ -1011,9 +996,9 @@
[% END %] [% END %]
</form> </form>
<form method="POST" action="/cgi-bin/koha/tools/modborrowers.pl" id="batch_patron_modification" target="_blank"> <form method="get" action="/cgi-bin/koha/tools/modborrowers.pl" id="batch_patron_modification" target="_blank">
[% INCLUDE 'csrf-token.inc' %] [% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-show" /> <input type="hidden" name="op" value="show" />
[% # Preserve the whitespace of the following textarea in order to format the values correctly %] [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
<textarea style="display:none" name="cardnumberlist" id="cardnumberlist"> <textarea style="display:none" name="cardnumberlist" id="cardnumberlist">
[%- cardnumbers = PROCESS batch_list results=results batch_type='cardnumber' | trim | html %][% IF cardnumbers %][% SET batch_cardnumbers = 1 %][% cardnumbers | html %][% END -%] [%- cardnumbers = PROCESS batch_list results=results batch_type='cardnumber' | trim | html %][% IF cardnumbers %][% SET batch_cardnumbers = 1 %][% cardnumbers | html %][% END -%]
@ -1041,9 +1026,9 @@
[%- END -%] [%- END -%]
[% END %] [% END %]
<form action="/cgi-bin/koha/reports/guided_reports.pl" method="get" id="limitselect"> <form action="/cgi-bin/koha/reports/guided_reports.pl" method="post" id="limitselect">
<input type="hidden" name="phase" value="Run this report"/> <input type="hidden" name="op" value="cud-run"/>
<input type="hidden" name="reports" value="[% report_id | html %]"/> <input type="hidden" name="reports" value="[% id | html %]"/>
[% FOREACH p IN sql_params %] [% FOREACH p IN sql_params %]
<input type="hidden" name="sql_params" value="[% p | html %]"/> <input type="hidden" name="sql_params" value="[% p | html %]"/>
[% END %] [% END %]
@ -1309,9 +1294,9 @@
</fieldset> </fieldset>
<fieldset class="action"> <fieldset class="action">
<input type="hidden" name="phase" value="Save Report" /> <input type="hidden" name="op" value="cud-save" />
<input type="submit" name="submit" class="btn btn-primary" value="Save report" /> <input type="submit" name="submit" class="btn btn-primary" value="Save report" />
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=list" class="cancel">Cancel</a>
</fieldset> </fieldset>
</form> </form>
@ -1422,9 +1407,9 @@
</fieldset> </fieldset>
<fieldset class="action"> <fieldset class="action">
<button class="btn btn-primary" type="submit" name="phase" value="update_sql">Update SQL</button> <button class="btn btn-primary" type="submit" name="op" value="cud-update_sql">Update SQL</button>
<button class="btn btn-default" type="submit" name="phase" value="update_and_run_sql">Update and run SQL</button> <button class="btn btn-default" type="submit" name="op" value="cud-update_and_run_sql">Update and run SQL</button>
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved" class="cancel">Cancel</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=list" class="cancel">Cancel</a>
</fieldset> </fieldset>
</form> </form>
[% END # /IF ( editsql ) %] [% END # /IF ( editsql ) %]
@ -1452,7 +1437,7 @@
[% END %] [% END %]
</div> </div>
<fieldset class="action"> <fieldset class="action">
<input type="hidden" name="phase" value="Use saved" /> <input type="hidden" name="op" value="list" />
<input type="submit" name="submit" class="btn btn-primary" value="Saved reports" /> <input type="submit" name="submit" class="btn btn-primary" value="Saved reports" />
</fieldset> </fieldset>
</form> </form>
@ -1466,7 +1451,7 @@
[% IF ( saved1 ) %] [% IF ( saved1 ) %]
<div id="saved-reports-filter"> <div id="saved-reports-filter">
<form action="/cgi-bin/koha/reports/guided_reports.pl" method="get"> <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
<input type="hidden" name="phase" value="Use saved" /> <input type="hidden" name="op" value="list" />
<input type="hidden" name="filter_set" value="1" /> <input type="hidden" name="filter_set" value="1" />
<fieldset class="brief"> <fieldset class="brief">
<h3>Filter</h3> <h3>Filter</h3>
@ -1488,7 +1473,7 @@
</fieldset> <!-- /.brief --> </fieldset> <!-- /.brief -->
<fieldset class="action"> <fieldset class="action">
<input type="submit" class="btn btn-primary" value="Apply filter" /> <input type="submit" class="btn btn-primary" value="Apply filter" />
<a id="resetReportsFilter" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&clear_filters=1">Clear</a> <a id="resetReportsFilter" href="/cgi-bin/koha/reports/guided_reports.pl?op=list&clear_filters=1">Clear</a>
</fieldset> </fieldset>
</form> </form>
</div> <!-- /#saved-reports-filter --> </div> <!-- /#saved-reports-filter -->
@ -1997,7 +1982,7 @@
}); });
$("#reports_form").submit(function(){ $("#reports_form").submit(function(){
var checkedItems = $("input[name=ids]:checked"); var checkedItems = $("input[name=id]:checked");
if ($(checkedItems).size() == 0) { if ($(checkedItems).size() == 0) {
alert(_("You must select one or more reports to delete")); alert(_("You must select one or more reports to delete"));
return false; return false;
@ -2023,7 +2008,7 @@
$("#col1 .show_sql,#col2 .show_sql").html(diffs); $("#col1 .show_sql,#col2 .show_sql").html(diffs);
}); });
$('#update_sql').modal('show'); $('#update_sql').modal('show');
$("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?phase=Use saved&op=convert&report_id=" + report_id); $("#update_sql_button").attr("href", "/cgi-bin/koha/reports/guided_reports.pl?op=convert&id=" + report_id);
}); });
$("#update_sql").on("hidden.bs.modal", function(){ $("#update_sql").on("hidden.bs.modal", function(){
@ -2060,16 +2045,6 @@
$("#chart, #toggle_chart_settings_hid, #toggle_chart_settings_vis").toggle(); $("#chart, #toggle_chart_settings_hid, #toggle_chart_settings_vis").toggle();
}); });
$("#table_reports").delegate(".confirmdelete", 'click', function(){
$(this).parents('tr').attr("class","warn");
if(confirm(_("Are you sure you want to delete this saved report?"))){
return true;
} else {
$(this).parents('tr').attr("class","");
return false;
}
});
[% IF (create || editsql || save) %] [% IF (create || editsql || save) %]
var validated_form = $("#sql_report_form").validate({ var validated_form = $("#sql_report_form").validate({
@ -2212,8 +2187,11 @@
[% END %] [% END %]
$(".delete").on("click",function(){ $(".delete").on("click",function(e){
return confirmDelete(MSG_CONFIRM_DELETE); e.preventDefault();
if ( confirmDelete(MSG_CONFIRM_DELETE) ) {
return $(this).siblings('form').submit();
}
}); });
$("#mana_search_form").submit(function(e){ $("#mana_search_form").submit(function(e){
@ -2266,7 +2244,6 @@
$("#limit").val( limit ); $("#limit").val( limit );
$("#limitselect").submit(); $("#limitselect").submit();
}); });
}); });
$("#toggle_auto_links").on("click", function(e){ $("#toggle_auto_links").on("click", function(e){
@ -2341,7 +2318,7 @@
alert( result.errmsg ); alert( result.errmsg );
} }
else{ else{
window.location = ("/cgi-bin/koha/reports/guided_reports.pl?reports=").concat(result.id).concat("&phase=Show%20SQL&mana_success=1"); window.location = ("/cgi-bin/koha/reports/guided_reports.pl?id=").concat(result.id).concat("&op=show&mana_success=1");
} }
}) })
.fail(function( error ) { .fail(function( error ) {
@ -2430,11 +2407,16 @@
<div class="modal-body"><textarea id="code' + reportid + '">' + message + '</textarea>\ <div class="modal-body"><textarea id="code' + reportid + '">' + message + '</textarea>\
</div>\ </div>\
<div class="modal-footer">\ <div class="modal-footer">\
<a id="preview-modal-editreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Edit%20SQL"><i class="fa-solid fa-pencil" aria-hidden="true"></i> ' + _("Edit") + '</a>\ <a id="preview-modal-editreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?id=' + reportid + '&amp;op=edit_form"><i class="fa-solid fa-pencil" aria-hidden="true"></i> ' + _("Edit") + '</a>\
<a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from existing&amp;report_id=' + reportid + '"><i class="fa fa-copy"></i> ' + _("Duplicate") + '</a>\ <a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?op=duplicate&amp;id=' + reportid + '"><i class="fa fa-copy"></i> ' + _("Duplicate") + '</a>\
<a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/tools/scheduler.pl?id=' + reportid + '"><i class="fa-solid fa-clock"></i> ' + _("Schedule") + '</a>\ <a id="preview-modal-duplicate" class="btn btn-default" href="/cgi-bin/koha/tools/scheduler.pl?id=' + reportid + '"><i class="fa-solid fa-clock"></i> ' + _("Schedule") + '</a>\
<a id="preview-modal-delete" class="delete btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Delete%20Saved"><i class="fa fa-trash-can"></i> ' + _("Delete") + '</a>\ <form method="post" action="/cgi-bin/koha/reports/guided_reports.pl">\
<a id="preview-modal-runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?reports=' + reportid + '&amp;phase=Run%20this%20report"><i class="fa fa-play"></i> ' + _("Run report") + '</a>\ [% INCLUDE 'csrf-token.inc' | collapse %]\
<input type="hidden" name="op" value="cud-delete" />\
<input type="hidden" name="id" value="' + reportid + '" />\
</form>\
<a id="preview-modal-delete"href="#" class="btn btn-default" title="Delete this saved report"><i class="fa fa-trash-can"></i> ' + _("Delete") + '</a>\
<a id="preview-modal-runreport" class="btn btn-default" href="/cgi-bin/koha/reports/guided_reports.pl?id=' + reportid + '&amp;op=run"><i class="fa fa-play"></i> ' + _("Run report") + '</a>\
<a href="#" id="preview-sql-modal-cancel" data-dismiss="modal" class="btn btn-default"><i class="fa fa-times" aria-hidden="true"></i> ' + _("Close") + '</a>\ <a href="#" id="preview-sql-modal-cancel" data-dismiss="modal" class="btn btn-default"><i class="fa fa-times" aria-hidden="true"></i> ' + _("Close") + '</a>\
</div>\ </div>\
</div>\ </div>\
@ -2448,6 +2430,13 @@
lineWrapping: true, lineWrapping: true,
readOnly: true readOnly: true
}); });
$("#preview-modal-delete").on("click",function(e){
e.preventDefault();
if ( confirmDelete(MSG_CONFIRM_DELETE) ) {
return $(this).siblings('form').submit();
}
});
} }
</script> </script>
[% END %] [% END %]

View file

@ -30,25 +30,27 @@
<div class="col-xs-6"> <div class="col-xs-6">
[% IF ( CAN_user_reports_execute_reports || CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_execute_reports || CAN_user_reports_create_reports ) %]
<form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
<fieldset class="brief"> <fieldset class="brief">
<h2>Guided reports</h2> <h2>Guided reports</h2>
<input name="phase" value="Use saved" type="hidden">
<input name="filter_set" value="1" type="hidden">
[% IF ( CAN_user_reports_create_reports ) %] [% IF ( CAN_user_reports_create_reports ) %]
<p> <p>
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new"><i class="fa-solid fa-code-branch"></i> Create guided report</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form"><i class="fa-solid fa-code-branch"></i> Create guided report</a>
</p> </p>
<p> <p>
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create%20report%20from%20SQL"><i class="fa fa-plus"></i> Create from SQL</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=add_form_sql"><i class="fa fa-plus"></i> Create from SQL</a>
</p> </p>
[% END %] [% END %]
<p> <p>
<a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved"><i class="fa fa-list"></i> Use saved</a> <a href="/cgi-bin/koha/reports/guided_reports.pl?op=list"><i class="fa fa-list"></i> Use saved</a>
</p> </p>
<label for="filter_keyword">Search by keyword:</label> <input id="filter_keyword" name="filter_keyword" value="" size="16" type="text" /> <input type="submit" class="btn btn-primary" value="Search" /> <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get">
<input name="op" value="list" type="hidden">
<input name="filter_set" value="1" type="hidden">
<label for="filter_keyword">Search by keyword:</label>
<input id="filter_keyword" name="filter_keyword" value="" size="16" type="text" />
<input type="submit" class="btn btn-primary" value="Search" />
</form>
</fieldset> </fieldset>
</form>
[% END %] [% END %]
<h5>Reports dictionary</h5> <h5>Reports dictionary</h5>

View file

@ -54,16 +54,16 @@ Script to control the guided report creation
my $input = CGI->new; my $input = CGI->new;
my $usecache = Koha::Caches->get_instance->memcached_cache; my $usecache = Koha::Caches->get_instance->memcached_cache;
my $phase = $input->param('phase') // ''; my $op = $input->param('op') // '';
my $flagsrequired; my $flagsrequired;
if ( ( $phase eq 'Build new' ) || ( $phase eq 'Create report from SQL' ) || ( $phase eq 'Edit SQL' ) if ( ( $op eq 'add_form' ) || ( $op eq 'add_form_sql' ) || ( $op eq 'edit_form' )
|| ( $phase eq 'Build new from existing' ) ) { || ( $op eq 'duplicate' ) ) {
$flagsrequired = 'create_reports'; $flagsrequired = 'create_reports';
} }
elsif ( $phase eq 'Use saved' ) { elsif ( $op eq 'list' ) {
$flagsrequired = 'execute_reports'; $flagsrequired = 'execute_reports';
} }
elsif ( $phase eq 'Delete Saved' ) { elsif ( $op eq 'delete' ) {
$flagsrequired = 'delete_reports'; $flagsrequired = 'delete_reports';
} }
else { else {
@ -94,14 +94,12 @@ elsif ($session and not $input->param('clear_filters')) {
$filter = $session->param('report_filter'); $filter = $session->param('report_filter');
} }
my $op = $input->param('op') || q||;
my @errors = (); my @errors = ();
if ( !$phase ) { if ( !$op ) {
$template->param( 'start' => 1 ); $template->param( 'start' => 1 );
# show welcome page # show welcome page
} }
elsif ( $phase eq 'Build new' ) { elsif ( $op eq 'add_form' ) {
# build a new report # build a new report
$template->param( 'build1' => 1 ); $template->param( 'build1' => 1 );
$template->param( $template->param(
@ -110,74 +108,16 @@ elsif ( $phase eq 'Build new' ) {
'cache_expiry' => 300, 'cache_expiry' => 300,
'public' => '0', 'public' => '0',
); );
} elsif ( $phase eq 'Use saved' ) {
if ( $op eq 'convert' ) {
my $report_id = $input->param('report_id');
my $report = Koha::Reports->find($report_id);
if ($report) {
my $updated_sql = C4::Reports::Guided::convert_sql( $report->savedsql );
C4::Reports::Guided::update_sql(
$report_id,
{
sql => $updated_sql,
name => $report->report_name,
group => $report->report_group,
subgroup => $report->report_subgroup,
notes => $report->notes,
public => $report->public,
cache_expiry => $report->cache_expiry,
}
);
$template->param( report_converted => $report->report_name );
}
}
# use a saved report
# get list of reports and display them
my $group = $input->param('group');
my $subgroup = $input->param('subgroup');
$filter->{group} = $group;
$filter->{subgroup} = $subgroup;
my $reports = get_saved_reports($filter);
my $has_obsolete_reports;
for my $report ( @$reports ) {
$report->{results} = C4::Reports::Guided::get_results( $report->{id} );
if ( $report->{savedsql} =~ m|biblioitems| and $report->{savedsql} =~ m|marcxml| ) {
$report->{seems_obsolete} = 1;
$has_obsolete_reports++;
}
}
$template->param(
'manamsg' => $input->param('manamsg') || '',
'saved1' => 1,
'savedreports' => $reports,
'usecache' => $usecache,
'groups_with_subgroups' => groups_with_subgroups( $group, $subgroup ),
filters => $filter,
has_obsolete_reports => $has_obsolete_reports,
);
} }
elsif ( $op eq 'cud-delete') {
elsif ( $phase eq 'Delete Multiple') { my @ids = $input->multi_param('id');
my @ids = $input->multi_param('ids');
delete_report( @ids ); delete_report( @ids );
print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved"); $op = 'list';
exit;
} }
elsif ( $phase eq 'Delete Saved') { elsif ( $op eq 'show'){
# delete a report from the saved reports list my $id = $input->param('id');
my $ids = $input->param('reports');
delete_report($ids);
print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved");
exit;
}
elsif ( $phase eq 'Show SQL'){
my $id = $input->param('reports');
my $report = Koha::Reports->find($id); my $report = Koha::Reports->find($id);
$template->param( $template->param(
'id' => $id, 'id' => $id,
@ -191,8 +131,8 @@ elsif ( $phase eq 'Show SQL'){
); );
} }
elsif ( $phase eq 'Edit SQL'){ elsif ( $op eq 'edit_form'){
my $id = $input->param('reports'); my $id = $input->param('id');
my $report = Koha::Reports->find($id); my $report = Koha::Reports->find($id);
my $group = $report->report_group; my $group = $report->report_group;
my $subgroup = $report->report_subgroup; my $subgroup = $report->report_subgroup;
@ -213,7 +153,7 @@ elsif ( $phase eq 'Edit SQL'){
); );
} }
elsif ( $phase eq 'update_sql' || $phase eq 'update_and_run_sql' ){ elsif ( $op eq 'cud-update_sql' || $op eq 'cud-update_and_run_sql' ){
my $id = $input->param('id'); my $id = $input->param('id');
my $sql = $input->param('sql'); my $sql = $input->param('sql');
my $reportname = $input->param('reportname'); my $reportname = $input->param('reportname');
@ -305,13 +245,13 @@ elsif ( $phase eq 'update_sql' || $phase eq 'update_and_run_sql' ){
cache_expiry_units => $cache_expiry_units, cache_expiry_units => $cache_expiry_units,
); );
} }
if ( $phase eq 'update_and_run_sql' ) { if ( $op eq 'cud-update_and_run_sql' ) {
print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?reports=$id&phase=Run%20this%20report"); $op = 'cud-run';
} }
} }
} }
elsif ($phase eq 'retrieve results') { elsif ($op eq 'retrieve_results') {
my $id = $input->param('id'); my $id = $input->param('id');
my $result = format_results( $id ); my $result = format_results( $id );
$template->param( $template->param(
@ -322,7 +262,7 @@ elsif ($phase eq 'retrieve results') {
); );
} }
elsif ( $phase eq 'Report on this Area' ) { elsif ( $op eq 'cud-report' ) {
my $cache_expiry_units = $input->param('cache_expiry_units'), my $cache_expiry_units = $input->param('cache_expiry_units'),
my $cache_expiry = $input->param('cache_expiry'); my $cache_expiry = $input->param('cache_expiry');
@ -357,7 +297,7 @@ elsif ( $phase eq 'Report on this Area' ) {
} }
} }
elsif ( $phase eq 'Choose this type' ) { elsif ( $op eq 'cud-choose_type' ) {
# they have chosen type and area # they have chosen type and area
# get area and type and pass them to the template # get area and type and pass them to the template
my $area = $input->param('area'); my $area = $input->param('area');
@ -372,7 +312,7 @@ elsif ( $phase eq 'Choose this type' ) {
); );
} }
elsif ( $phase eq 'Choose these columns' ) { elsif ( $op eq 'cud-choose_columns' ) {
# we now know type, area, and columns # we now know type, area, and columns
# next step is the constraints # next step is the constraints
my $area = $input->param('area'); my $area = $input->param('area');
@ -398,7 +338,7 @@ elsif ( $phase eq 'Choose these columns' ) {
} }
elsif ( $phase eq 'Choose these criteria' ) { elsif ( $op eq 'cud-choose_criteria' ) {
my $area = $input->param('area'); my $area = $input->param('area');
my $type = $input->param('type'); my $type = $input->param('type');
my $column = $input->param('column'); my $column = $input->param('column');
@ -452,14 +392,14 @@ elsif ( $phase eq 'Choose these criteria' ) {
foreach my $col (@columns) { foreach my $col (@columns) {
my %total = (name => $col); my %total = (name => $col);
my @selects = map {+{ value => $_ }} (qw(sum min max avg count)); my @selects = map {+{ value => $_ }} (qw(sum min max avg count));
$total{'cud-select'} = \@selects; $total{'select'} = \@selects;
push @total_by, \%total; push @total_by, \%total;
} }
$template->param( 'total_by' => \@total_by ); $template->param( 'total_by' => \@total_by );
} }
elsif ( $phase eq 'Choose these operations' ) { elsif ( $op eq 'cud-choose_operations' ) {
my $area = $input->param('area'); my $area = $input->param('area');
my $type = $input->param('type'); my $type = $input->param('type');
my $column = $input->param('column'); my $column = $input->param('column');
@ -493,14 +433,14 @@ elsif ( $phase eq 'Choose these operations' ) {
foreach my $col (@columns) { foreach my $col (@columns) {
my %order = (name => $col); my %order = (name => $col);
my @selects = map {+{ value => $_ }} (qw(asc desc)); my @selects = map {+{ value => $_ }} (qw(asc desc));
$order{'cud-select'} = \@selects; $order{'select'} = \@selects;
push @order_by, \%order; push @order_by, \%order;
} }
$template->param( 'order_by' => \@order_by ); $template->param( 'order_by' => \@order_by );
} }
elsif ( $phase eq 'Build report' ) { elsif ( $op eq 'cud-build_report' ) {
# now we have all the info we need and can build the sql # now we have all the info we need and can build the sql
my $area = $input->param('area'); my $area = $input->param('area');
@ -538,13 +478,13 @@ elsif ( $phase eq 'Build report' ) {
); );
} }
elsif ( $phase eq 'Save' ) { elsif ( $op eq 'save' ) {
# Save the report that has just been built # Save the report that has just been built
my $area = $input->param('area'); my $area = $input->param('area');
my $sql = $input->param('sql'); my $sql = $input->param('sql');
my $type = $input->param('type'); my $type = $input->param('type');
$template->param( $template->param(
'cud-save' => 1, 'save' => 1,
'area' => $area, 'area' => $area,
'sql' => $sql, 'sql' => $sql,
'type' => $type, 'type' => $type,
@ -554,7 +494,7 @@ elsif ( $phase eq 'Save' ) {
); );
} }
elsif ( $phase eq 'Save Report' ) { elsif ( $op eq 'cud-save' ) {
# save the sql pasted in by a user # save the sql pasted in by a user
my $area = $input->param('area'); my $area = $input->param('area');
my $group = $input->param('group'); my $group = $input->param('group');
@ -658,21 +598,169 @@ elsif ( $phase eq 'Save Report' ) {
} }
} }
elsif ($phase eq 'Share'){ elsif ($op eq 'share'){
my $lang = $input->param('mana_language') || ''; my $lang = $input->param('mana_language') || '';
my $reportid = $input->param('reportid'); my $reportid = $input->param('reportid');
my $result = Koha::SharedContent::send_entity($lang, $borrowernumber, $reportid, 'report'); my $result = Koha::SharedContent::send_entity($lang, $borrowernumber, $reportid, 'report');
if ( $result ) { if ( $result ) {
print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=".$result->{msg}); print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?op=listmanamsg=".$result->{msg});
}else{ }else{
print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=noanswer"); print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?op=list&manamsg=noanswer");
} }
} }
elsif ($phase eq 'Run this report'){
elsif ($op eq 'export'){
# export results to tab separated text or CSV
my $report_id = $input->param('id');
my $report = Koha::Reports->find($report_id);
my $sql = $report->savedsql;
my @param_names = $input->multi_param('param_name');
my @sql_params = $input->multi_param('sql_params');
my $format = $input->param('format');
my $reportname = $input->param('reportname');
my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ;
($sql, undef) = $report->prep_report( \@param_names, \@sql_params );
my ( $sth, $q_errors ) = execute_query( { sql => $sql, report_id => $report_id } );
unless ($q_errors and @$q_errors) {
my ( $type, $content );
if ($format eq 'tab') {
$type = 'application/octet-stream';
$content .= join("\t", header_cell_values($sth)) . "\n";
$content = Encode::decode('UTF-8', $content);
while (my $row = $sth->fetchrow_arrayref()) {
$content .= join("\t", map { $_ // '' } @$row) . "\n";
}
} else {
if ( $format eq 'csv' ) {
my $delimiter = C4::Context->csv_delimiter;
$type = 'application/csv';
my $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter});
$csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag();
if ($csv->combine(header_cell_values($sth))) {
$content .= Encode::decode('UTF-8', $csv->string()) . "\n";
} else {
push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ;
}
while (my $row = $sth->fetchrow_arrayref()) {
if ($csv->combine(@$row)) {
$content .= $csv->string() . "\n";
} else {
push @$q_errors, { combine => $csv->error_diag() } ;
}
}
}
elsif ( $format eq 'ods' ) {
$type = 'application/vnd.oasis.opendocument.spreadsheet';
my $ods_fh = File::Temp->new( UNLINK => 0 );
my $ods_filepath = $ods_fh->filename;
my $ods_content;
# First line is headers
my @headers = header_cell_values($sth);
push @$ods_content, \@headers;
# Other line in Unicode
my $sql_rows = $sth->fetchall_arrayref();
foreach my $sql_row ( @$sql_rows ) {
my @content_row;
foreach my $sql_cell ( @$sql_row ) {
push @content_row, Encode::encode( 'UTF8', $sql_cell );
}
push @$ods_content, \@content_row;
}
# Process
generate_ods($ods_filepath, $ods_content);
# Output
binmode(STDOUT);
open $ods_fh, '<', $ods_filepath;
$content .= $_ while <$ods_fh>;
unlink $ods_filepath;
}
elsif ( $format eq 'template' ) {
my $template_id = $input->param('template');
my $notice_template = Koha::Notice::Templates->find($template_id);
my $data = $sth->fetchall_arrayref( {} );
$content = process_tt(
$notice_template->content,
{
data => $data,
report_id => $report_id,
for_download => 1,
}
);
$reportfilename = process_tt(
$notice_template->title,
{
data => $data,
report_id => $report_id,
}
);
}
}
print $input->header(
-type => $type,
-attachment=> $reportfilename
);
print $content;
foreach my $err (@$q_errors, @errors) {
print "# ERROR: " . (map {$_ . ": " . $err->{$_}} keys %$err) . "\n";
} # here we print all the non-fatal errors at the end. Not super smooth, but better than nothing.
exit;
}
$template->param(
'sql' => $sql,
'execute' => 1,
'name' => 'Error exporting report!',
'notes' => '',
'errors' => $q_errors,
);
}
elsif ( $op eq 'add_form_sql' || $op eq 'duplicate' ) {
my ($group, $subgroup, $sql, $reportname, $notes);
if ( $input->param('sql') ) {
$group = $input->param('report_group');
$subgroup = $input->param('report_subgroup');
$sql = $input->param('sql') // '';
$reportname = $input->param('reportname') // '';
$notes = $input->param('notes') // '';
}
elsif ( my $report_id = $input->param('id') ) {
my $report = Koha::Reports->find($report_id);
$group = $report->report_group;
$subgroup = $report->report_subgroup;
$sql = $report->savedsql // '';
$reportname = $report->report_name // '';
$notes = $report->notes // '';
}
my $tables = get_tables();
$template->param(
sql => $sql,
reportname => $reportname,
notes => $notes,
'create' => 1,
'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
'public' => '0',
'cache_expiry' => 300,
'usecache' => $usecache,
'tables' => $tables,
);
}
if ($op eq 'cud-run'){
# execute a saved report # execute a saved report
my $limit = $input->param('limit') || 20; my $limit = $input->param('limit') || 20;
my $offset = 0; my $offset = 0;
my $report_id = $input->param('reports'); my $report_id = $input->param('id');
my @sql_params = $input->multi_param('sql_params'); my @sql_params = $input->multi_param('sql_params');
my @param_names = $input->multi_param('param_name'); my @param_names = $input->multi_param('param_name');
my $template_id = $input->param('template'); my $template_id = $input->param('template');
@ -685,8 +773,8 @@ elsif ($phase eq 'Run this report'){
} }
$template->param( $template->param(
'limit' => $limit, 'limit' => $limit,
'report_id' => $report_id, 'id' => $report_id,
); );
my ( $sql, $original_sql, $type, $name, $notes ); my ( $sql, $original_sql, $type, $name, $notes );
@ -837,7 +925,7 @@ elsif ($phase eq 'Run this report'){
'sql_params' => \@tmpl_parameters, 'sql_params' => \@tmpl_parameters,
'auth_val_errors' => \@authval_errors, 'auth_val_errors' => \@authval_errors,
'enter_params' => 1, 'enter_params' => 1,
'reports' => $report_id, 'id' => $report_id,
); );
} else { } else {
my ($sql,$header_types) = $report->prep_report( \@param_names, \@sql_params ); my ($sql,$header_types) = $report->prep_report( \@param_names, \@sql_params );
@ -870,7 +958,7 @@ elsif ($phase eq 'Run this report'){
} }
my $totpages = int($total/$limit) + (($total % $limit) > 0 ? 1 : 0); my $totpages = int($total/$limit) + (($total % $limit) > 0 ? 1 : 0);
my $url = "/cgi-bin/koha/reports/guided_reports.pl?reports=$report_id&amp;phase=Run%20this%20report&amp;limit=$limit&amp;want_full_chart=$want_full_chart"; my $url = "/cgi-bin/koha/reports/guided_reports.pl?id=$report_id&amp;op=run&amp;limit=$limit&amp;want_full_chart=$want_full_chart";
if (@param_names) { if (@param_names) {
$url = join('&amp;param_name=', $url, map { URI::Escape::uri_escape_utf8($_) } @param_names); $url = join('&amp;param_name=', $url, map { URI::Escape::uri_escape_utf8($_) } @param_names);
} }
@ -918,153 +1006,54 @@ elsif ($phase eq 'Run this report'){
} }
} }
elsif ($phase eq 'Export'){ if ( $op eq 'list' || $op eq 'convert') {
# export results to tab separated text or CSV if ( $op eq 'convert' ) {
my $report_id = $input->param('report_id'); my $report_id = $input->param('id');
my $report = Koha::Reports->find($report_id); my $report = Koha::Reports->find($report_id);
my $sql = $report->savedsql; if ($report) {
my @param_names = $input->multi_param('param_name'); my $updated_sql = C4::Reports::Guided::convert_sql( $report->savedsql );
my @sql_params = $input->multi_param('sql_params'); C4::Reports::Guided::update_sql(
my $format = $input->param('format'); $report_id,
my $reportname = $input->param('reportname'); {
my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ; sql => $updated_sql,
name => $report->report_name,
($sql, undef) = $report->prep_report( \@param_names, \@sql_params ); group => $report->report_group,
my ( $sth, $q_errors ) = execute_query( { sql => $sql, report_id => $report_id } ); subgroup => $report->report_subgroup,
unless ($q_errors and @$q_errors) { notes => $report->notes,
my ( $type, $content ); public => $report->public,
if ($format eq 'tab') { cache_expiry => $report->cache_expiry,
$type = 'application/octet-stream';
$content .= join("\t", header_cell_values($sth)) . "\n";
$content = Encode::decode('UTF-8', $content);
while (my $row = $sth->fetchrow_arrayref()) {
$content .= join("\t", map { $_ // '' } @$row) . "\n";
}
} else {
if ( $format eq 'csv' ) {
my $delimiter = C4::Context->csv_delimiter;
$type = 'application/csv';
my $csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter});
$csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag();
if ($csv->combine(header_cell_values($sth))) {
$content .= Encode::decode('UTF-8', $csv->string()) . "\n";
} else {
push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ;
} }
while (my $row = $sth->fetchrow_arrayref()) { );
if ($csv->combine(@$row)) { $template->param( report_converted => $report->report_name );
$content .= $csv->string() . "\n";
} else {
push @$q_errors, { combine => $csv->error_diag() } ;
}
}
}
elsif ( $format eq 'ods' ) {
$type = 'application/vnd.oasis.opendocument.spreadsheet';
my $ods_fh = File::Temp->new( UNLINK => 0 );
my $ods_filepath = $ods_fh->filename;
my $ods_content;
# First line is headers
my @headers = header_cell_values($sth);
push @$ods_content, \@headers;
# Other line in Unicode
my $sql_rows = $sth->fetchall_arrayref();
foreach my $sql_row ( @$sql_rows ) {
my @content_row;
foreach my $sql_cell ( @$sql_row ) {
push @content_row, Encode::encode( 'UTF8', $sql_cell );
}
push @$ods_content, \@content_row;
}
# Process
generate_ods($ods_filepath, $ods_content);
# Output
binmode(STDOUT);
open $ods_fh, '<', $ods_filepath;
$content .= $_ while <$ods_fh>;
unlink $ods_filepath;
}
elsif ( $format eq 'template' ) {
my $template_id = $input->param('template');
my $notice_template = Koha::Notice::Templates->find($template_id);
my $data = $sth->fetchall_arrayref( {} );
$content = process_tt(
$notice_template->content,
{
data => $data,
report_id => $report_id,
for_download => 1,
}
);
$reportfilename = process_tt(
$notice_template->title,
{
data => $data,
report_id => $report_id,
}
);
}
} }
print $input->header( }
-type => $type,
-attachment=> $reportfilename
);
print $content;
foreach my $err (@$q_errors, @errors) { # use a saved report
print "# ERROR: " . (map {$_ . ": " . $err->{$_}} keys %$err) . "\n"; # get list of reports and display them
} # here we print all the non-fatal errors at the end. Not super smooth, but better than nothing. my $group = $input->param('group');
exit; my $subgroup = $input->param('subgroup');
$filter->{group} = $group;
$filter->{subgroup} = $subgroup;
my $reports = get_saved_reports($filter);
my $has_obsolete_reports;
for my $report ( @$reports ) {
$report->{results} = C4::Reports::Guided::get_results( $report->{id} );
if ( $report->{savedsql} =~ m|biblioitems| and $report->{savedsql} =~ m|marcxml| ) {
$report->{seems_obsolete} = 1;
$has_obsolete_reports++;
}
} }
$template->param( $template->param(
'sql' => $sql, 'manamsg' => $input->param('manamsg') || '',
'execute' => 1, 'saved1' => 1,
'name' => 'Error exporting report!', 'savedreports' => $reports,
'notes' => '', 'usecache' => $usecache,
'errors' => $q_errors, 'groups_with_subgroups' => groups_with_subgroups( $group, $subgroup ),
filters => $filter,
has_obsolete_reports => $has_obsolete_reports,
); );
} }
elsif ( $phase eq 'Create report from SQL' || $phase eq 'Create report from existing' ) {
my ($group, $subgroup, $sql, $reportname, $notes);
if ( $input->param('sql') ) {
$group = $input->param('report_group');
$subgroup = $input->param('report_subgroup');
$sql = $input->param('sql') // '';
$reportname = $input->param('reportname') // '';
$notes = $input->param('notes') // '';
}
elsif ( my $report_id = $input->param('report_id') ) {
my $report = Koha::Reports->find($report_id);
$group = $report->report_group;
$subgroup = $report->report_subgroup;
$sql = $report->savedsql // '';
$reportname = $report->report_name // '';
$notes = $report->notes // '';
}
my $tables = get_tables();
$template->param(
sql => $sql,
reportname => $reportname,
notes => $notes,
'create' => 1,
'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
'public' => '0',
'cache_expiry' => 300,
'usecache' => $usecache,
'tables' => $tables,
);
}
# pass $sth, get back an array of names for the column headers # pass $sth, get back an array of names for the column headers
sub header_cell_values { sub header_cell_values {
my $sth = shift or return (); my $sth = shift or return ();

View file

@ -26,7 +26,7 @@ use C4::Output qw( output_html_with_http_headers );
use CGI qw ( -utf8 ); use CGI qw ( -utf8 );
my $query = CGI->new(); my $query = CGI->new();
my $report_id = $query->param('report_id'); my $report_id = $query->param('id');
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ {