[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 | |
---|
| 22 | // init the plugin |
---|
| 23 | add_event_handler('init', 'usernotes_init'); |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | * plugin initialization |
---|
| 27 | * - check for upgrades |
---|
| 28 | * - load language |
---|
| 29 | */ |
---|
| 30 | function usernotes_init() |
---|
[12447] | 31 | { |
---|
[27697] | 32 | // load plugin language file |
---|
| 33 | load_language('plugin.lang', USERNOTES_PATH); |
---|
[12447] | 34 | } |
---|
| 35 | |
---|
[27697] | 36 | add_event_handler('loc_begin_admin_page', 'usernotes_add_column'); |
---|
| 37 | function usernotes_add_column() |
---|
| 38 | { |
---|
| 39 | global $template; |
---|
| 40 | |
---|
| 41 | $template->set_prefilter('user_list', 'usernotes_add_column_prefilter'); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | function usernotes_add_column_prefilter($content, &$smarty) |
---|
| 45 | { |
---|
| 46 | // add the "Notes" column in the user table |
---|
| 47 | $search = '<th>{\'registration date\'|@translate}</th>'; |
---|
| 48 | $content = str_replace($search, $search.'<th>{\'Notes\'|@translate}</th>', $content); |
---|
| 49 | |
---|
| 50 | // add the "Notes" field in user profile form |
---|
| 51 | $search = '#</div>\s*<div class="userPropertiesSet userPrefs">#ms'; |
---|
| 52 | $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">'; |
---|
| 53 | $content = preg_replace($search, $replace, $content); |
---|
| 54 | |
---|
| 55 | return $content; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | add_event_handler('user_list_columns', 'usernotes_user_list_columns', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
| 59 | function usernotes_user_list_columns($aColumns) |
---|
| 60 | { |
---|
| 61 | $aColumns[] = 'usernotes'; |
---|
| 62 | |
---|
| 63 | return $aColumns; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
| 67 | function usernotes_ws_users_setInfo($res, $methodName, $params) |
---|
| 68 | { |
---|
| 69 | if ($methodName != 'pwg.users.setInfo') |
---|
| 70 | { |
---|
| 71 | return $res; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | if (!isset($_POST['usernotes'])) |
---|
| 75 | { |
---|
| 76 | return $res; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | if (count($params['user_id']) == 0) |
---|
| 80 | { |
---|
| 81 | return $res; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | $updates = array(); |
---|
| 85 | |
---|
| 86 | foreach ($params['user_id'] as $user_id) |
---|
| 87 | { |
---|
| 88 | $updates[] = array( |
---|
| 89 | 'user_id' => $user_id, |
---|
| 90 | 'usernotes' => $_POST['usernotes'], |
---|
| 91 | ); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | if (count($updates) > 0) |
---|
| 95 | { |
---|
| 96 | mass_updates( |
---|
| 97 | USER_INFOS_TABLE, |
---|
| 98 | array( |
---|
| 99 | 'primary' => array('user_id'), |
---|
| 100 | 'update' => array('usernotes') |
---|
| 101 | ), |
---|
| 102 | $updates |
---|
| 103 | ); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | return $res; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
| 110 | function usernotes_ws_users_getList($users) |
---|
| 111 | { |
---|
| 112 | $user_ids = array(); |
---|
| 113 | foreach ($users as $user_id => $user) |
---|
| 114 | { |
---|
| 115 | $user_ids[] = $user_id; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | if (count($user_ids) == 0) |
---|
| 119 | { |
---|
| 120 | return $users; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | $query = ' |
---|
| 124 | SELECT |
---|
| 125 | user_id, |
---|
| 126 | usernotes |
---|
| 127 | FROM '.USER_INFOS_TABLE.' |
---|
| 128 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
| 129 | ;'; |
---|
| 130 | $result = pwg_query($query); |
---|
| 131 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 132 | { |
---|
| 133 | $users[$row['user_id']]['usernotes'] = $row['usernotes']; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | return $users; |
---|
| 137 | } |
---|
[12447] | 138 | ?> |
---|