Bug 21526: Use the 'url' filter when needed
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / usage_statistics.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% SET footerjs = 1 %]
4 [% USE Koha %]
5 [% USE KohaDates %]
6 [% USE Price %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>Koha &rsaquo; Administration &rsaquo; Koha usage statistics</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10 [% Asset.css("lib/leaflet/leaflet.css") | $raw %]
11 </head>
12
13 <body id="admin_usage_statistics" class="admin">
14 [% INCLUDE 'header.inc' %]
15 [% INCLUDE 'cat-search.inc' %]
16
17 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Usage statistics</div>
18
19 <div class="main container-fluid">
20     <div class="row">
21         <div class="col-sm-10 col-sm-push-2">
22             <main>
23
24 [% FOR m IN messages %]
25     <div class="dialog [% m.type | html %]">
26         [% SWITCH m.code %]
27         [% CASE 'error_on_update' %]
28             An error occurred when updating this patron category. Perhaps it already exists.
29         [% CASE 'error_on_insert' %]
30             An error occurred when inserting this patron category. The patron category might already exist.
31         [% CASE 'error_on_delete' %]
32             An error occurred when deleting this patron category. Check the logs.
33         [% CASE 'success_on_update' %]
34             Patron category updated successfully.
35         [% CASE 'success_on_insert' %]
36             Patron category inserted successfully.
37         [% CASE 'success_on_delete' %]
38             Patron category deleted successfully.
39         [% CASE 'already_exists' %]
40             This patron category already exists.
41         [% CASE %]
42             [% m.code | html %]
43         [% END %]
44     </div>
45 [% END %]
46
47 [% IF NOT Koha.Preference('UsageStats') %]
48     <div class="dialog message">You are not sharing any data with the Koha community</div>
49 [% END %]
50
51     <form id="category_form" action="/cgi-bin/koha/admin/usage_statistics.pl" method="post">
52         <h1>Modify the statistics you share with the Koha community</h1>
53         <div class="row">
54             <div class="col-xs-12 col-sm-6">
55                 <fieldset class="rows">
56                     <ol>
57                         <li>
58                             <label for="UsageStats">Share my Koha usage statistics: </label>
59                             <select name="UsageStats" id="UsageStats">
60                             [% IF Koha.Preference('UsageStats') %]
61                                 <option value="1" selected="selected">Yes</option>
62                                 <option value="0">No</option>
63                             [% ELSE %]
64                                 <option value="1">Yes</option>
65                                 <option value="0" selected="selected">No</option>
66                             [% END %]
67                             </select>
68                         </li>
69                         <li>
70                             <label for="UsageStatsCountry">Your country: </label>
71                             [% SET UsageStatsCountry = Koha.Preference('UsageStatsCountry') %]
72                             [% SET IsUsageStatsCountryValid = 0 %]
73                             [% IF NOT UsageStatsCountry %]
74                                 [% SET IsUsageStatsCountryValid = 1 %]
75                             [% END %]
76                             [% PROCESS 'country-list.inc' %]
77                             <select name="UsageStatsCountry" id="UsageStatsCountry">
78                                 <option value="">&nbsp;</option>
79                                 [% FOR country IN countries %]
80                                     [% IF country == UsageStatsCountry %]
81                                         <option value="[% country | html %]" selected="selected">[% country | html %]</option>
82                                         [% SET IsUsageStatsCountryValid = 1 %]
83                                     [% ELSE %]
84                                         <option value="[% country | html %]">[% country | html %]</option>
85                                     [% END %]
86                                 [% END %]
87                             </select>
88                             [% UNLESS IsUsageStatsCountryValid %]
89                                 Note: The value of your system preference 'UsageStatsCountry' is not valid ([% UsageStatsCountry | html %]).
90                                 Please select a valid one.
91                             [% END %]
92                         </li>
93                         <li>
94                             <label for="UsageStatsLibraryName">Library name: </label>
95                             <input type="text" value="[% Koha.Preference('UsageStatsLibraryName') | html %]" name="UsageStatsLibraryName" id="UsageStatsLibraryName" />
96                         </li>
97                         <li>
98                             <label for="UsageStatsLibraryType">Library type: </label>
99                             [% SET UsageStatsLibraryType = Koha.Preference('UsageStatsLibraryType') %]
100                             <select name="UsageStatsLibraryType" id="UsageStatsLibraryType">
101                                 <option value="">&nbsp;</option>
102                                 [% IF UsageStatsLibraryType == 'public' %]
103                                     <option value="public" selected="selected">Public</option>
104                                 [% ELSE %]
105                                     <option value="public">Public</option>
106                                 [% END %]
107
108                                 [% IF UsageStatsLibraryType == 'school' %]
109                                     <option value="school" selected="selected">School</option>
110                                 [% ELSE %]
111                                     <option value="school">School</option>
112                                 [% END %]
113                                 [% IF UsageStatsLibraryType == 'academic' %]
114                                     <option value="academic" selected="selected">Academic</option>
115                                 [% ELSE %]
116                                     <option value="academic">Academic</option>
117                                 [% END %]
118                                 [% IF UsageStatsLibraryType == 'research' %]
119                                     <option value="research" selected="selected">Research</option>
120                                 [% ELSE %]
121                                     <option value="research">Research</option>
122                                 [% END %]
123                                 [% IF UsageStatsLibraryType == 'private' %]
124                                     <option value="private" selected="selected">Private</option>
125                                 [% ELSE %]
126                                     <option value="private">Private</option>
127                                 [% END %]
128                                 [% IF UsageStatsLibraryType == 'societyAssociation' %]
129                                     <option value="societyAssociation" selected="selected">Society or association</option>
130                                 [% ELSE %]
131                                     <option value="societyAssociation">Society or association</option>
132                                 [% END %]
133                                 [% IF UsageStatsLibraryType == 'corporate' %]
134                                     <option value="corporate" selected="selected">Corporate</option>
135                                 [% ELSE %]
136                                     <option value="corporate">Corporate</option>
137                                 [% END %]
138                                 [% IF UsageStatsLibraryType == 'government' %]
139                                     <option value="government" selected="selected">Government</option>
140                                 [% ELSE %]
141                                     <option value="government">Government</option>
142                                 [% END %]
143                                 [% IF UsageStatsLibraryType == 'religiousOrg' %]
144                                     <option value="religiousOrg" selected="selected">Religious organization</option>
145                                 [% ELSE %]
146                                     <option value="religiousOrg">Religious organization</option>
147                                 [% END %]
148                                 [% IF UsageStatsLibraryType == 'subscription' %]
149                                     <option value="subscription" selected="selected">Subscription</option>
150                                 [% ELSE %]
151                                     <option value="subscription">Subscription</option>
152                                 [% END %]
153                             </select>
154                         </li>
155                         <li>
156                             <label for="UsageStatsLibraryUrl">Library URL: </label>
157                             <input type="text" name="UsageStatsLibraryUrl" value="[% Koha.Preference('UsageStatsLibraryUrl') | html %]" id="UsageStatsLibraryUrl" />
158                         </li>
159                         <li>
160                             <span class="label">Last update: </span>
161                             [% IF UsageStatsLastUpdateTime %]
162                                 [% UsageStatsLastUpdateTime | html %]
163                             [% ELSE %]
164                                 Your data have never been shared
165                             [% END %]
166                         </li>
167                         <li>
168                             <label for="UsageStatsGeolocation">Geolocation: </label>
169                             <input id="UsageStatsGeolocation" name="UsageStatsGeolocation" value="[% Koha.Preference('UsageStatsGeolocation') | html %]" type="text" value="[% Koha.Preference('UsageStatsLibrariesInfo') | html %]" size="35" readonly="readonly" />
170                             <a href="#" class="change_geolocation" data-branchname="" data-id="UsageStatsGeolocation"><img src="[% interface | html %]/lib/leaflet/images/marker-icon.png" title="Set geolocation" style="max-height: 2em;" /></a>
171                         </li>
172                         <li>
173                             <label for="UsageStatsLibrariesInfo">Libraries informations: </label>
174                             <select name="UsageStatsLibrariesInfo" id="UsageStatsLibrariesInfo">
175                                 [% IF Koha.Preference('UsageStatsLibrariesInfo') %]
176                                     <option value="1" selected="selected">Yes</option>
177                                     <option value="0">No</option>
178                                 [% ELSE %]
179                                     <option value="1">Yes</option>
180                                     <option value="0" selected="selected">No</option>
181                                 [% END %]
182                             </select>
183                         </li>
184
185                         <li id="libraries_info">
186                             <fieldset class="rows">
187                             <legend>Libraries</legend>
188                             <ol>
189                                 [% FOR l IN libraries %]
190                                 <li>
191                                     <label for="[% l.branchcode | html %]">[% l.branchname | html %]: </label>
192                                     <div style="float:left;">
193                                         <div>Country: [% l.branchcountry | html %]</div>
194                                         <div>Url: [% l.branchurl | html %]</div>
195                                         <div>
196                                             Geolocation: <input type="text" id="geolocation_[% l.branchcode | html %]" name="geolocation_[% l.branchcode | html %]" value="[% l.geolocation | html %]" size="35" readonly="readonly" />
197                                             <a href="#" class="change_geolocation" data-branchname="[% l.branchname | html %]" data-id="geolocation_[% l.branchcode | html %]"><img src="[% interface | html %]/lib/leaflet/images/marker-icon.png" title="Set geolocation for [% l.branchname | html %]" style="max-height: 2em;" /></a>
198                                         </div>
199                                     </div>
200                                 </li>
201                                 [% END %]
202                             </ol>
203                             </fieldset>
204                         </li>
205                         <li>
206                             <label for="MyPublicLink">See your public page: </label>
207                             [% IF Koha.Preference('UsageStatsPublicID') %]
208                                 [% SET my_url = 'https://hea.koha-community.org/libraries/' _  Koha.Preference('UsageStatsPublicID') %]
209                                 <a href="[% my_url | url %]">[% my_url | html %]</a>
210                             [% ELSE %]
211                                 You do not have anything public yet.
212                             [% END %]
213                         </li>
214
215                     </ol>
216                 </fieldset>
217             </div>
218             <div class="col-xs-12 col-sm-6">
219                 <div>
220                     <div id="mapid" style="width:100%;height: 400px;"></div>
221                 </div>
222             </div>
223
224         </div>
225
226         <fieldset class="action">
227             <input type="hidden" name="op" value="update" />
228             <input type="submit" value="Update your statistics usage" />
229             <a class="cancel" href="/cgi-bin/koha/admin/usage_statistics.pl">Cancel</a>
230         </fieldset>
231     </form>
232
233             </main>
234         </div> <!-- /.col-sm-10.col-sm-push-2 -->
235
236         <div class="col-sm-2 col-sm-pull-10">
237             <aside>
238                 [% INCLUDE 'admin-menu.inc' %]
239             </aside>
240         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
241      </div> <!-- /.row -->
242
243 [% MACRO jsinclude BLOCK %]
244     [% INCLUDE 'calendar.inc' %]
245     [% Asset.js("js/admin-menu.js") | $raw %]
246     [% Asset.js("/lib/leaflet/leaflet.js") | $raw %]
247     <script>
248         function positionMap() {
249             var tbh = $("#mapid");
250             var mapContainer = tbh.parent();
251             mapContainer.css('position', 'relative');
252             mapContainer.css('min-height', tbh.outerHeight(true));
253             tbh.css('position', 'absolute');
254             tbh.css('right', 0);
255
256             var offsetTop = mapContainer.offset().top;
257             var s = parseInt($(window).scrollTop(), 10);
258             tbh.css('top', '').css('bottom', '');
259             if (s > offsetTop) {
260                 var mapContainerOffsetBottom = offsetTop + mapContainer.innerHeight();
261                 if (s + tbh.outerHeight(true) > mapContainerOffsetBottom) {
262                     tbh.css('bottom', 0);
263                 } else {
264                     tbh.css('top', s - offsetTop);
265                 }
266             } else {
267                 tbh.css('top', 0);
268             }
269         }
270
271         $(document).ready(function() {
272             $(window).scroll(positionMap);
273             positionMap();
274         });
275
276         var map = L.map('mapid').setView([0,0], 1);
277
278         L.tileLayer('https://a.tile.openstreetmap.org/{z}/{x}/{y}.png', {
279             maxZoom: 18,
280             attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
281                 '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
282         }).addTo(map);
283
284         var default_elt = { 'text': _("Main library"), 'id': 'UsageStatsGeolocation' };
285         var current_elt = default_elt;
286
287         // Add the title
288         var title = L.control({position: 'topright'});
289         title.onAdd = function (map) {
290             this._div = L.DomUtil.create('div', 'title');
291             this.update();
292             return this._div;
293         };
294         title.update = function (props) {
295             this._div.innerHTML = '<h4>' + _("Click on the map to set the geolocation for %s").format(current_elt.text) + '</h4>';
296         };
297         title.addTo(map);
298
299         var markers = {};
300         function add_to_map(elt, latlng) {
301             var marker = markers[elt.id];
302             if (marker) map.removeLayer(marker);
303             marker = L.marker(latlng).addTo(map);
304             marker.bindPopup(elt.text);
305             marker.on('mouseover', function (e) {this.openPopup(); });
306             marker.on('mouseout',  function (e) {this.closePopup();});
307             markers[elt.id] = marker;
308         }
309
310         // Init the map
311         [% IF Koha.Preference('UsageStatsGeolocation') %]
312             var latlng = [ [% Koha.Preference('UsageStatsGeolocation') | html %] ];
313             add_to_map( current_elt, latlng );
314         [% END %]
315         [% FOR l IN libraries %]
316             [% NEXT UNLESS l.geolocation %]
317             add_to_map( { 'text': "[% l.branchname | html %]", 'id': "geolocation_[% l.branchcode | html %]" }, [ [% l.geolocation | html %] ] );
318         [% END %]
319
320         // On click, update the geolocation and the marker
321         map.on('click', function(e){
322             add_to_map( current_elt, e.latlng );
323             $("#" + current_elt.id).val(e.latlng.lat + ',' + e.latlng.lng);
324         });
325
326         // Auto zoom
327         var group = new L.featureGroup(Object.keys(markers).map(function(key){return markers[key]}));
328         if ( group.getBounds().isValid() ) map.fitBounds(group.getBounds());
329
330         // On click on the marker icons, update the title of the map
331         $(document).ready(function(){
332             $(".change_geolocation").on('click', function(e){
333                 e.preventDefault();
334                 if ( $(this).data('branchname') ) {
335                     current_elt = { 'text': $(this).data('branchname'), 'id': $(this).data('id') };
336                 } else {
337                     current_elt = default_elt;
338                 }
339                 title.update();
340             });
341             $("#UsageStatsLibrariesInfo").change();
342         });
343
344         $("#UsageStatsLibrariesInfo").on('change', function(){
345             if ( $(this).val() == 1 ) $("#libraries_info").show()
346             else $("#libraries_info").hide();
347             positionMap();
348         });
349
350     </script>
351 [% END %]
352 [% INCLUDE 'intranet-bottom.inc' %]