diff --git a/admin/include/add_core_tabs.inc.php b/admin/include/add_core_tabs.inc.php index 7b0146fd8..74cae9ca3 100644 --- a/admin/include/add_core_tabs.inc.php +++ b/admin/include/add_core_tabs.inc.php @@ -35,6 +35,12 @@ function add_core_tabs($sheets, $tab_id) $sheets['permalinks'] = array('caption' => ''.l10n('Permalinks'), 'url' => $my_base_url.'permalinks'); $sheets['search'] = array('caption' => ''.l10n('Search'), 'url' => $my_base_url.'cat_search'); break; + + case 'users': + global $my_base_url; + $sheets['user_list'] = array('caption' => ''.l10n('User list'), 'url' => $my_base_url.'user_list'); + $sheets['user_activity'] = array('caption' => ''.l10n('Activity'), 'url' => $my_base_url.'user_activity'); + break; case 'batch_manager': global $manager_link; diff --git a/admin/include/user_tabs.inc.php b/admin/include/user_tabs.inc.php new file mode 100644 index 000000000..b83b9b50f --- /dev/null +++ b/admin/include/user_tabs.inc.php @@ -0,0 +1,18 @@ +set_id('users'); +$tabsheet->select($page['tab']); +$tabsheet->assign(); + +?> \ No newline at end of file diff --git a/admin/themes/default/template/user_activity.tpl b/admin/themes/default/template/user_activity.tpl new file mode 100644 index 000000000..1432228f9 --- /dev/null +++ b/admin/themes/default/template/user_activity.tpl @@ -0,0 +1,907 @@ +{include file='include/colorbox.inc.tpl'} +{combine_script id='common' load='footer' path='admin/themes/default/js/common.js'} + +{combine_script id='jquery.selectize' load='footer' path='themes/default/js/plugins/selectize.min.js'} +{combine_css id='jquery.selectize' path="themes/default/js/plugins/selectize.{$themeconf.colorscheme}.css"} + +{combine_script id='LocalStorageCache' load='footer' path='admin/themes/default/js/LocalStorageCache.js'} +{combine_css path="admin/themes/default/fontello/css/animation.css" order=10} {* order 10 is required, see issue 1080 *} +{footer_script} +{* *} +var usersCache = new UsersCache({ + serverKey: '{$CACHE_KEYS.users}', + serverId: '{$CACHE_KEYS._hash}', + rootUrl: '{$ROOT_URL}' +}); + +usersCache.selectize(jQuery('[data-selectize=users]')); + +jQuery(".cancel-icon").click(function() { + jQuery(".user-selecter")[0].selectize.setValue(null); + return false; +}); + +const color_icons = ["icon-red", "icon-blue", "icon-yellow", "icon-purple", "icon-green"]; + +{*<-- Translation keys -->*} + +var actionType_add = "{'add'|translate}"; +var actionType_delete = "{'deletion'|translate}"; +var actionType_move = "{'move'|translate}"; +var actionType_edit = "{'edit'|translate}"; +var actionType_log = "{'log'|translate}"; + +{* Album keys *} + +var actionInfos_album_added = "{'%d album added'|translate}"; +var actionInfos_album_deleted = "{'%d album deleted'|translate}"; +var actionInfos_album_edited = "{'%d album edited'|translate}"; +var actionInfos_album_moved = "{'%d album moved'|translate}"; + +var actionInfos_albums_added = "{'%d albums added'|translate}"; +var actionInfos_albums_deleted = "{'%d albums deleted'|translate}"; +var actionInfos_albums_edited = "{'%d albums edited'|translate}"; +var actionInfos_albums_moved = "{'%d albums moved'|translate}"; + +{* User keys *} + +var actionInfos_user_added = "{'%d user added'|translate}"; +var actionInfos_user_deleted = "{'%d user deleted'|translate}"; +var actionInfos_user_edited = "{'%d user edited'|translate}"; +var actionInfos_user_logged_in = "{'%d user logged in'|translate}"; +var actionInfos_user_logged_out = "{'%d user logged out'|translate}"; + +var actionInfos_users_added = "{'%d users added'|translate}"; +var actionInfos_users_deleted = "{'%d users deleted'|translate}"; +var actionInfos_users_edited = "{'%d users edited'|translate}"; +var actionInfos_users_logged_in = "{'%d users logged in'|translate}"; +var actionInfos_users_logged_out = "{'%d users logged out'|translate}"; + +{* Photo keys *} + +var actionInfos_photo_added = "{'%d photo added'|translate}"; +var actionInfos_photo_deleted = "{'%d photo deleted'|translate}"; +var actionInfos_photo_edited = "{'%d photo edited'|translate}"; +var actionInfos_photo_moved = "{'%d photo moved'|translate}"; + +var actionInfos_photos_added = "{'%d photos added'|translate}"; +var actionInfos_photos_deleted = "{'%d photos deleted'|translate}"; +var actionInfos_photos_edited = "{'%d photos edited'|translate}"; +var actionInfos_photos_moved = "{'%d photos moved'|translate}"; + +{* Group keys *} + +var actionInfos_group_added = "{'%d group added'|translate}"; +var actionInfos_group_deleted = "{'%d group deleted'|translate}"; +var actionInfos_group_edited = "{'%d group edited'|translate}"; +var actionInfos_group_moved = "{'%d group moved'|translate}"; + +var actionInfos_groups_added = "{'%d groups added'|translate}"; +var actionInfos_groups_deleted = "{'%d groups deleted'|translate}"; +var actionInfos_groups_edited = "{'%d groups edited'|translate}"; +var actionInfos_groups_moved = "{'%d groups moved'|translate}"; + +{* Tags keys *} + +var actionInfos_tag_added = "{'%d tag added'|translate}"; +var actionInfos_tag_deleted = "{'%d tag deleted'|translate}"; +var actionInfos_tag_edited = "{'%d tag edited'|translate}"; +var actionInfos_tag_moved = "{'%d tag moved'|translate}"; + +var actionInfos_tags_added = "{'%d tags added'|translate}"; +var actionInfos_tags_deleted = "{'%d tags deleted'|translate}"; +var actionInfos_tags_edited = "{'%d tags edited'|translate}"; +var actionInfos_tags_moved = "{'%d tags moved'|translate}"; + +{*<-- Getting and Displaying Activities -->*} + +get_user_activity(); + +function get_user_activity() { + $.ajax({ + url: "ws.php?format=json&method=pwg.activity.getList", + type: "POST", + dataType: "json", + data: { + a: 1, + b: 2 + }, + success: (data) => { + /* console log to help debug */ + {* console.log(data); *} + + setCreationDate(data.result[data.result.length-1].date, data.result[0].date); + $(".loading").hide(); + + data.result.forEach(line => { + lineConstructor(line); + }); + displayLine(data); + }, + error: (e) => { + console.log("ajax call failed"); + console.log(e); + } + + }) +} + +function lineConstructor(line) { + let newLine = $("#-1").clone(); + + newLine.removeClass("hide"); + + /* console log to help debug */ + {* console.log(line); *} + newLine.attr("id", line.id); + + var final_albumInfos; + + {* Determines wich string need to be placed in the line constructed *} + + if (line.counter > 1) { + // pluriel + switch (line.action) { + case "edit": + newLine.find(".action-type").addClass("icon-blue"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-pencil"); + + newLine.find(".action-name").html(actionType_edit); + switch (line.object) { + case "user": + final_albumInfos = actionInfos_users_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-user-1"); + + break; + case "album": + final_albumInfos = actionInfos_albums_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-folder-open"); + + break; + case "group": + final_albumInfos = actionInfos_groups_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-users-1"); + + break; + case "photo": + final_albumInfos = actionInfos_photos_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-picture"); + + break; + case "tag": + final_albumInfos = actionInfos_tags_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-tags"); + + break; + default: + final_albumInfos = line.counter + " " +line.object + " " + line.action; + break; + } + + break; + + case "add": + newLine.find(".action-type").addClass("icon-green"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-plus"); + + newLine.find(".action-name").html(actionType_add); + switch (line.object) { + case "user": + final_albumInfos = actionInfos_users_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-user-1"); + + break; + case "album": + final_albumInfos = actionInfos_albums_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-folder-open"); + + break; + case "group": + final_albumInfos = actionInfos_groups_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-users-1"); + + break; + case "photo": + final_albumInfos = actionInfos_photos_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-picture"); + + break; + case "tag": + final_albumInfos = actionInfos_tags_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-tags"); + + break; + default: + final_albumInfos = line.counter + " " +line.object + " " + line.action; + break; + } + + break; + + case "delete": + newLine.find(".action-type").addClass("icon-red"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-trash-1"); + + newLine.find(".action-name").html(actionType_delete); + switch (line.object) { + case "user": + final_albumInfos = actionInfos_users_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-user-1"); + + break; + case "album": + final_albumInfos = actionInfos_albums_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-folder-open"); + + break; + case "group": + final_albumInfos = actionInfos_groups_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-users-1"); + + break; + case "photo": + final_albumInfos = actionInfos_photos_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-picture"); + + break; + case "tag": + final_albumInfos = actionInfos_tags_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-tags"); + + break; + default: + final_albumInfos = line.counter + " " +line.object + " " + line.action; + break; + } + + break; + + case "move": + newLine.find(".action-type").addClass("icon-yellow"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-move"); + + newLine.find(".action-name").html(actionType_move); + switch (line.object) { + case "album": + final_albumInfos = actionInfos_albums_moved.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-folder-open"); + + break; + case "group": + final_albumInfos = actionInfos_groups_moved.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-users-1"); + + break; + case "photo": + final_albumInfos = actionInfos_photos_moved.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-picture"); + + break; + case "tag": + final_albumInfos = actionInfos_tags_moved.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-tags"); + + break; + default: + final_albumInfos = line.counter + " " +line.object + " " + line.action; + break; + } + + break; + + case "login": + newLine.find(".action-type").addClass("icon-purple"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-key"); + newLine.find(".action-section").addClass("icon-user-1"); + + newLine.find(".action-name").html(actionType_log); + + console.log("userS Logged in"); + final_albumInfos = actionInfos_users_logged_in.replace('%d', line.counter); + + break; + + case "logout": + newLine.find(".action-type").addClass("icon-purple"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-key"); + newLine.find(".action-section").addClass("icon-user-1"); + + newLine.find(".action-name").html(actionType_log); + + console.log("userS Logged in"); + final_albumInfos = actionInfos_users_logged_out.replace('%d', line.counter); + + break; + + default: + newLine.find(".action-type").addClass("icon-purple"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + break; + } + } else { + // singulier + switch (line.action) { + case "edit": + newLine.find(".action-type").addClass("icon-blue"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-pencil"); + + newLine.find(".action-name").html(actionType_edit); + switch (line.object) { + case "user": + final_albumInfos = actionInfos_user_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-user-1"); + + break; + case "album": + final_albumInfos = actionInfos_album_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-folder-open"); + + break; + case "group": + final_albumInfos = actionInfos_group_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-users-1"); + + break; + case "photo": + final_albumInfos = actionInfos_photo_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-picture"); + + break; + case "tag": + final_albumInfos = actionInfos_tag_edited.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-tags"); + + break; + default: + final_albumInfos = line.counter + " " +line.object + " " + line.action; + break; + } + + + break; + case "add": + newLine.find(".action-type").addClass("icon-green"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-plus"); + + newLine.find(".action-name").html(actionType_add); + switch (line.object) { + case "user": + final_albumInfos = actionInfos_user_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-user-1"); + + break; + case "album": + final_albumInfos = actionInfos_album_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-folder-open"); + + break; + case "group": + final_albumInfos = actionInfos_group_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-users-1"); + + break; + case "photo": + final_albumInfos = actionInfos_photo_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-picture"); + + break; + case "tag": + final_albumInfos = actionInfos_tag_added.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-tags"); + + break; + default: + final_albumInfos = line.counter + " " +line.object + " " + line.action; + + break; + } + + break; + case "delete": + newLine.find(".action-type").addClass("icon-red"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-trash-1"); + + newLine.find(".action-name").html(actionType_delete); + switch (line.object) { + case "user": + final_albumInfos = actionInfos_user_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-user-1"); + + break; + case "album": + final_albumInfos = actionInfos_album_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-folder-open"); + + break; + case "group": + final_albumInfos = actionInfos_group_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-users-1"); + + break; + case "photo": + final_albumInfos = actionInfos_photo_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-picture"); + + break; + case "tag": + final_albumInfos = actionInfos_tag_deleted.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-tags"); + + break; + default: + final_albumInfos = line.counter + " " +line.object + " " + line.action; + break; + } + + break; + case "move": + newLine.find(".action-type").addClass("icon-yellow"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-move"); + + newLine.find(".action-name").html(actionType_move); + switch (line.object) { + case "album": + final_albumInfos = actionInfos_album_moved.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-folder-open"); + + break; + case "group": + final_albumInfos = actionInfos_group_moved.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-users-1"); + + break; + case "photo": + final_albumInfos = actionInfos_photo_moved.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-picture"); + + break; + case "tag": + final_albumInfos = actionInfos_tag_moved.replace('%d', line.counter); + newLine.find(".action-section").addClass("icon-tags"); + + break; + default: + final_albumInfos = line.counter + " " +line.object + " " + line.action; + break; + } + + break; + case "login": + newLine.find(".action-type").addClass("icon-purple"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-key"); + newLine.find(".action-section").addClass("icon-user-1"); + + newLine.find(".action-name").html(actionType_log); + + final_albumInfos = actionInfos_user_logged_in.replace('%d', line.counter); + + break; + case "logout": + newLine.find(".action-type").addClass("icon-purple"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + newLine.find(".action-icon").addClass("icon-key"); + newLine.find(".action-section").addClass("icon-user-1"); + + newLine.find(".action-name").html(actionType_log); + + final_albumInfos = actionInfos_user_logged_out.replace('%d', line.counter); + + break; + + default: + newLine.find(".action-type").addClass("icon-purple"); + newLine.find(".user-pic").addClass(color_icons[line.user_id % 5]); + break; + } + } + + newLine.find(".action-infos-test").html(final_albumInfos); + + /* Action_section */ + newLine.find(".nb_items").html(line.counter); + + /* Date_section */ + newLine.find(".date-day").html(line.date); + newLine.find(".date-hour").html(line.hour); + + /* User _Section */ + newLine.find(".user-pic").html(get_initials(line.username)); + newLine.find(".user-name").html(line.username); + + /* Detail_section */ + newLine.find(".detail-item-1").html(line.ip_address); + newLine.find(".detail-item-1").attr("title", "IP"); + + if (line.detailsType == "script") { + newLine.find(".detail-item-2").html(line.details.script); + newLine.find(".detail-item-2").attr('title', 'Script'); + } else if (line.detailsType == "method") { + newLine.find(".detail-item-2").html(line.details.method); + newLine.find(".detail-item-2").attr('title', 'API Method'); + } + + if (line.details.agent) { + newLine.find(".detail-item-3").html(line.details.agent); + newLine.find(".detail-item-3").attr('title', line.details.agent); + } else { + newLine.find(".detail-item-3").remove(); + } + + displayLine(newLine); +} + +function displayLine(line) { + $(".tab").append(line); +} + +function get_initials(username) { + let words = username.toUpperCase().split(" "); + let res = words[0][0]; + + if (words.length > 1 && words[1][0] !== undefined ) { + res += words[1][0]; + } + return res; +} + +function filterUsers(username) { + let lines = $(".line"); + + showAllLines() + let resultLines = []; + + for (let index = 1; index < lines.length; index++) { + + if (username != lines[index].children[2].children[1].innerHTML) { + $("#" + lines[index].id).hide(); + } else { + resultLines.push(lines[index].getElementsByClassName("date-day")[0].textContent) + } + } + setCreationDate((!resultLines[resultLines.length-1]) ? "{'N/A'|translate}" : resultLines[resultLines.length-1], (!resultLines[0]) ? "{'N/A'|translate}" : resultLines[0]) +} + +function showAllLines() { + let lines = $(".line"); + for (let index = 1; index < lines.length; index++) { + $("#" + lines[index].id).show(); + } + + $("#-1").hide(); +} + +function setCreationDate(startDate, endDate) { + $(".start-date").html(startDate) + + $(".end-date").html(endDate) +} + +$(document).ready(function () { + + $('select').on('change', function (user) { + try { + filterUsers($(".selectize-input .item")[0].innerHTML); + } catch (error) { + showAllLines(); + let lines = $(".line"); + let resultLines = []; + for (let index = 1; index < lines.length; index++) { + resultLines.push(lines[index].getElementsByClassName("date-day")[0].textContent) + } + setCreationDate((!resultLines[resultLines.length-1]) ? "-" : resultLines[resultLines.length-1], (!resultLines[0]) ? "-" : resultLines[0]) + } + }); +}); + +{/footer_script} + +