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