[12447] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Add Users Notes |
---|
| 4 | Version: auto |
---|
| 5 | Description: Adds admin notes to users profiles |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=580 |
---|
| 7 | Author: ddtddt |
---|
| 8 | Author URI: |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | global $prefixeTable; |
---|
| 14 | |
---|
[27697] | 15 | // +-----------------------------------------------------------------------+ |
---|
| 16 | // | Define plugin constants | |
---|
| 17 | // +-----------------------------------------------------------------------+ |
---|
[12447] | 18 | |
---|
[27697] | 19 | define('USERNOTES_ID', basename(dirname(__FILE__))); |
---|
| 20 | define('USERNOTES_PATH', PHPWG_PLUGINS_PATH.USERNOTES_ID.'/'); |
---|
| 21 | define('USERNOTES_VERSION', 'auto'); |
---|
| 22 | |
---|
| 23 | // init the plugin |
---|
| 24 | add_event_handler('init', 'usernotes_init'); |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * plugin initialization |
---|
| 28 | * - check for upgrades |
---|
| 29 | * - load language |
---|
| 30 | */ |
---|
| 31 | function usernotes_init() |
---|
[12447] | 32 | { |
---|
[27697] | 33 | // apply upgrade if needed |
---|
| 34 | include_once(USERNOTES_PATH.'maintain.inc.php'); |
---|
| 35 | $maintain = new AddUsersNotes_maintain(USERNOTES_ID); |
---|
| 36 | $maintain->autoUpdate(USERNOTES_VERSION, 'install'); |
---|
| 37 | |
---|
| 38 | // load plugin language file |
---|
| 39 | load_language('plugin.lang', USERNOTES_PATH); |
---|
[12447] | 40 | } |
---|
| 41 | |
---|
[27697] | 42 | add_event_handler('loc_begin_admin_page', 'usernotes_add_column'); |
---|
| 43 | function usernotes_add_column() |
---|
| 44 | { |
---|
| 45 | global $template; |
---|
| 46 | |
---|
| 47 | $template->set_prefilter('user_list', 'usernotes_add_column_prefilter'); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | function usernotes_add_column_prefilter($content, &$smarty) |
---|
| 51 | { |
---|
| 52 | // add the "Notes" column in the user table |
---|
| 53 | $search = '<th>{\'registration date\'|@translate}</th>'; |
---|
| 54 | $content = str_replace($search, $search.'<th>{\'Notes\'|@translate}</th>', $content); |
---|
| 55 | |
---|
| 56 | // add the "Notes" field in user profile form |
---|
| 57 | $search = '#</div>\s*<div class="userPropertiesSet userPrefs">#ms'; |
---|
| 58 | $replace = '<div class="userProperty"><strong>{\'Notes\'|translate}</strong><br><input type="text" name="usernotes" value="<%- user.usernotes %>" style="width:338px;"></div></div><div class="userPropertiesSet userPrefs">'; |
---|
| 59 | $content = preg_replace($search, $replace, $content); |
---|
| 60 | |
---|
| 61 | return $content; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | add_event_handler('user_list_columns', 'usernotes_user_list_columns', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
| 65 | function usernotes_user_list_columns($aColumns) |
---|
| 66 | { |
---|
| 67 | $aColumns[] = 'usernotes'; |
---|
| 68 | |
---|
| 69 | return $aColumns; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
| 73 | function usernotes_ws_users_setInfo($res, $methodName, $params) |
---|
| 74 | { |
---|
| 75 | if ($methodName != 'pwg.users.setInfo') |
---|
| 76 | { |
---|
| 77 | return $res; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | if (!isset($_POST['usernotes'])) |
---|
| 81 | { |
---|
| 82 | return $res; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | if (count($params['user_id']) == 0) |
---|
| 86 | { |
---|
| 87 | return $res; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | $updates = array(); |
---|
| 91 | |
---|
| 92 | foreach ($params['user_id'] as $user_id) |
---|
| 93 | { |
---|
| 94 | $updates[] = array( |
---|
| 95 | 'user_id' => $user_id, |
---|
| 96 | 'usernotes' => $_POST['usernotes'], |
---|
| 97 | ); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | if (count($updates) > 0) |
---|
| 101 | { |
---|
| 102 | mass_updates( |
---|
| 103 | USER_INFOS_TABLE, |
---|
| 104 | array( |
---|
| 105 | 'primary' => array('user_id'), |
---|
| 106 | 'update' => array('usernotes') |
---|
| 107 | ), |
---|
| 108 | $updates |
---|
| 109 | ); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | return $res; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
| 116 | function usernotes_ws_users_getList($users) |
---|
| 117 | { |
---|
| 118 | $user_ids = array(); |
---|
| 119 | foreach ($users as $user_id => $user) |
---|
| 120 | { |
---|
| 121 | $user_ids[] = $user_id; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | if (count($user_ids) == 0) |
---|
| 125 | { |
---|
| 126 | return $users; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | $query = ' |
---|
| 130 | SELECT |
---|
| 131 | user_id, |
---|
| 132 | usernotes |
---|
| 133 | FROM '.USER_INFOS_TABLE.' |
---|
| 134 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
| 135 | ;'; |
---|
| 136 | $result = pwg_query($query); |
---|
| 137 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 138 | { |
---|
| 139 | $users[$row['user_id']]['usernotes'] = $row['usernotes']; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | return $users; |
---|
| 143 | } |
---|
[12447] | 144 | ?> |
---|