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