[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 | */ |
---|
[32693] | 30 | function usernotes_init(){ |
---|
[27697] | 31 | load_language('plugin.lang', USERNOTES_PATH); |
---|
[32697] | 32 | global $template; |
---|
[32693] | 33 | $template->assign( |
---|
| 34 | array( |
---|
| 35 | 'USERNOTES_PATH2'=> get_root_url().USERNOTES_PATH, |
---|
| 36 | ) |
---|
| 37 | ); |
---|
[12447] | 38 | } |
---|
| 39 | |
---|
[27697] | 40 | add_event_handler('loc_begin_admin_page', 'usernotes_add_column'); |
---|
[32693] | 41 | function usernotes_add_column(){ |
---|
[27697] | 42 | global $template; |
---|
| 43 | $template->set_prefilter('user_list', 'usernotes_add_column_prefilter'); |
---|
| 44 | } |
---|
| 45 | |
---|
[32693] | 46 | function usernotes_add_column_prefilter($content){ |
---|
[32697] | 47 | // add js link |
---|
[32693] | 48 | $search = '<div class="selection-mode-group-manager" style="right:30px">'; |
---|
| 49 | $replace = '{combine_script id="jquery.usersnotes" load=\'footer\' path="$USERNOTES_PATH2/js/usersnotes.js"}'; |
---|
| 50 | $content = str_replace($search, $replace.$search, $content); |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | // add the "Notes" column in the user table |
---|
[32695] | 55 | $search = '<!-- groups --> |
---|
| 56 | <div class="user-header-col user-header-groups"> |
---|
| 57 | <span>{\'Groups\'|@translate}</span> |
---|
| 58 | </div>'; |
---|
[32693] | 59 | $content = str_replace($search, $search.'<!-- Notes --> |
---|
[32695] | 60 | <div class="user-header-col user-header-usernotes"> |
---|
[32693] | 61 | <span>{\'Notes\'|@translate}</th></span> |
---|
| 62 | </div>' |
---|
| 63 | , $content); |
---|
[27697] | 64 | |
---|
[32693] | 65 | // add the "Notes" |
---|
[32695] | 66 | $search = '<div class="user-col user-container-groups"> |
---|
| 67 | <!-- groups --> |
---|
| 68 | </div>'; |
---|
[32693] | 69 | $replace = ' <div class="user-col user-container-usernotes"> |
---|
| 70 | <span><!-- usernotes --></span> |
---|
| 71 | </div>'; |
---|
[32695] | 72 | $content = str_replace($search, $search.$replace, $content); |
---|
[32693] | 73 | |
---|
[27697] | 74 | // add the "Notes" field in user profile form |
---|
[32694] | 75 | $search = '<div id="UserList" class="UserListPopIn"> |
---|
| 76 | |
---|
| 77 | <div class="UserListPopInContainer"> |
---|
| 78 | |
---|
| 79 | <a class="icon-cancel CloseUserList"></a> |
---|
| 80 | <div class="summary-properties-update-container"> |
---|
| 81 | <div class="summary-properties-container"> |
---|
| 82 | <div class="summary-container"> |
---|
| 83 | <div class="user-property-initials"> |
---|
| 84 | <div> |
---|
| 85 | <span class="icon-blue"><!-- Initials (JP) --></span> |
---|
| 86 | </div> |
---|
| 87 | </div> |
---|
| 88 | <div class="user-property-username"> |
---|
| 89 | <span class="edit-username-title"><!-- Name (Jessy Pinkman) --></span> |
---|
| 90 | <span class="edit-username-specifier"><!-- You specifire (you) --></span> |
---|
| 91 | <span class="edit-username icon-pencil"></span> |
---|
| 92 | </div> |
---|
| 93 | <div class="user-property-username-change"> |
---|
| 94 | <div class="summary-input-container"> |
---|
| 95 | <input class="user-property-input user-property-input-username" value="" placeholder="{\'Username\'|@translate}" /> |
---|
| 96 | </div> |
---|
| 97 | <span class="icon-ok edit-username-validate"></span> |
---|
| 98 | <span class="icon-cancel-circled edit-username-cancel"></span> |
---|
| 99 | </div> |
---|
| 100 | <div class="user-property-password-container"> |
---|
| 101 | <div class="user-property-password edit-password"> |
---|
| 102 | <p class="user-property-button"><span class="icon-key user-edit-icon"> </span>{\'Change Password\'|@translate}</p> |
---|
| 103 | </div> |
---|
| 104 | <div class="user-property-password-change"> |
---|
| 105 | <div class="summary-input-container"> |
---|
| 106 | <input class="user-property-input user-property-input-password" value="" placeholder="{\'Password\'|@translate}" /> |
---|
| 107 | </div> |
---|
| 108 | <span class="icon-ok edit-password-validate"></span> |
---|
| 109 | <span class="icon-cancel-circled edit-password-cancel"></span> |
---|
| 110 | </div> |
---|
| 111 | <div class="user-property-permissions"> |
---|
| 112 | <p class="user-property-button"> <span class="icon-lock user-edit-icon"> </span><a href="#" >{\'Permissions\'|@translate}</a></p> |
---|
| 113 | </div> |
---|
| 114 | </div> |
---|
| 115 | <div class="user-property-register-visit"> |
---|
| 116 | <span class="user-property-register"><!-- Registered date XX/XX/XXXX --></span> |
---|
| 117 | <span class="icon-calendar"></span> |
---|
| 118 | <span class="user-property-last-visit"><!-- Last Visit date XX/XX/XXXX --></span> |
---|
| 119 | </div> |
---|
| 120 | </div> |
---|
| 121 | <div class="properties-container"> |
---|
| 122 | <div class="user-property-column-title"> |
---|
| 123 | <p>{\'Properties\'|@translate}</p> |
---|
| 124 | </div> |
---|
| 125 | <div class="user-property-email"> |
---|
| 126 | <p class="user-property-label">{\'Email Adress\'|@translate}</p> |
---|
| 127 | <input type="text" class="user-property-input" value="contact@jessy-pinkman.com" disabled="false"/> |
---|
| 128 | </div> |
---|
| 129 | <div class="user-property-status"> |
---|
| 130 | <p class="user-property-label">{\'Status\'|@translate} |
---|
| 131 | <span class="icon-help-circled" |
---|
| 132 | title="<div class=\'tooltip-status-content\'> |
---|
| 133 | <div class=\'tooltip-status-row\'><span class=\'tooltip-col1\'>{\'user_status_webmaster\'|translate}</span><span class=\'tooltip-col2\'>{\'Has access to all administration functionnalities. Can manage both configuration and content.\'|translate}</span></div> |
---|
| 134 | <div class=\'tooltip-status-row\'><span class=\'tooltip-col1\'>{\'user_status_admin\'|translate}</span><span class=\'tooltip-col2\'>{\'Has access to administration. Can only manage content: photos/albums/users/tags/groups.\'|translate}</span></div> |
---|
| 135 | <div class=\'tooltip-status-row\'><span class=\'tooltip-col1\'>{\'user_status_normal\'|translate}</span><span class=\'tooltip-col2\'>{\'No access to administration, can see private content with appropriate permissions.\'|translate}</span></div> |
---|
| 136 | <div class=\'tooltip-status-row\'><span class=\'tooltip-col1\'>{\'user_status_generic\'|translate}</span><span class=\'tooltip-col2\'>{\'Can be shared by several individuals without conflict (they cannot change the password).\'|translate}</span></div> |
---|
| 137 | <div class=\'tooltip-status-row\'><span class=\'tooltip-col1\'>{\'user_status_guest\'|translate}</span><span class=\'tooltip-col2\'>{\'Equivalent to deactivation. The user is still in the list, but can no longer log in.\'|translate}</span></div> |
---|
| 138 | </div"> |
---|
| 139 | </span> |
---|
| 140 | </p> |
---|
| 141 | <div class="user-property-select-container"> |
---|
| 142 | <select name="status" class="user-property-select"> |
---|
| 143 | <option value="webmaster">{\'user_status_webmaster\'|@translate}</option> |
---|
| 144 | <option value="admin">{\'user_status_admin\'|@translate}</option> |
---|
| 145 | <option value="normal">{\'user_status_normal\'|@translate}</option> |
---|
| 146 | <option value="generic">{\'user_status_generic\'|@translate}</option> |
---|
| 147 | <option value="guest">{\'user_status_guest\'|@translate} ({\'Deactivated\'|@translate})</option> |
---|
| 148 | </select> |
---|
| 149 | </div> |
---|
| 150 | </div> |
---|
| 151 | <div class="user-property-level"> |
---|
| 152 | <p class="user-property-label">{\'Privacy level\'|@translate}</p> |
---|
| 153 | <div class="user-property-select-container"> |
---|
| 154 | <select name="privacy" class="user-property-select"> |
---|
| 155 | <option value="0">{\'Level 0\'|@translate}</option> |
---|
| 156 | <option value="1">{\'Level 1\'|@translate}</option> |
---|
| 157 | <option value="2">{\'Level 2\'|@translate}</option> |
---|
| 158 | <option value="4">{\'Level 4\'|@translate}</option> |
---|
| 159 | <option value="8">{\'Level 8\'|@translate}</option> |
---|
| 160 | </select> |
---|
| 161 | </div> |
---|
| 162 | </div> |
---|
| 163 | <div class="user-property-group-container"> |
---|
[32693] | 164 | <p class="user-property-label">{\'Groups\'|@translate}</p> |
---|
| 165 | <div class="user-property-select-container user-property-group"> |
---|
| 166 | <select class="user-property-select" data-selectize="groups" placeholder="{\'Select groups or type them\'|translate}" |
---|
| 167 | name="group_id[]" multiple style="box-sizing:border-box;"></select> |
---|
| 168 | </div> |
---|
| 169 | </div>'; |
---|
| 170 | $replace = '<p class="user-property-label">{\'Notes\'|@translate}</p> |
---|
| 171 | <div class="user-property-usernotes"> |
---|
| 172 | <span class="usernotes-title"><!-- usernotes --></span> |
---|
| 173 | <span class="edit-usernotes icon-pencil"></span> |
---|
| 174 | </div> |
---|
| 175 | <div class="user-property-usernotes-change"> |
---|
| 176 | <div class="summary-input-container"> |
---|
| 177 | <input class="usernotes-property-input user-property-input-usernotes" value="" placeholder="{\'Notes\'|@translate}" /> |
---|
| 178 | </div> |
---|
| 179 | <span class="icon-ok edit-usernotes-validate"></span> |
---|
| 180 | <span class="icon-cancel-circled edit-usernotes-cancel"></span> |
---|
| 181 | </div> |
---|
| 182 | '; |
---|
| 183 | $content = str_replace($search, $search.$replace, $content); |
---|
| 184 | |
---|
| 185 | //css |
---|
| 186 | $search = '</style>'; |
---|
| 187 | $replace = ' |
---|
| 188 | .user-property-usernotes-change { |
---|
| 189 | justify-content:center; |
---|
| 190 | align-items:center; |
---|
| 191 | display:none; |
---|
| 192 | margin-bottom:25px; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | .user-property-usernotes { |
---|
| 196 | margin-bottom:34px; |
---|
| 197 | height:30px; |
---|
| 198 | } |
---|
[27697] | 199 | |
---|
[32693] | 200 | .edit-usernotes-validate { |
---|
| 201 | display: block; |
---|
| 202 | margin: auto 5px; |
---|
| 203 | cursor: pointer; |
---|
| 204 | background-color: #ffa744; |
---|
| 205 | color: #3c3c3c; |
---|
| 206 | font-size: 17px; |
---|
| 207 | font-weight: 700; |
---|
| 208 | padding: 7px; |
---|
[27697] | 209 | } |
---|
| 210 | |
---|
[32693] | 211 | .edit-usernotes-validate:hover { |
---|
| 212 | background-color: #f70; |
---|
| 213 | color: #000; |
---|
| 214 | cursor: pointer; |
---|
[27697] | 215 | } |
---|
[32693] | 216 | .edit-usernotes { |
---|
| 217 | font-size:1.4em; |
---|
| 218 | cursor:pointer; |
---|
| 219 | } |
---|
| 220 | .edit-usernotes-cancel { |
---|
| 221 | cursor:pointer; |
---|
| 222 | font-size:22px; |
---|
| 223 | padding-top: 4px; |
---|
| 224 | } |
---|
| 225 | .usernotes-property-input { |
---|
| 226 | width: 100%; |
---|
| 227 | box-sizing:border-box; |
---|
| 228 | font-size:1.1em; |
---|
| 229 | padding:8px 16px; |
---|
| 230 | border:none; |
---|
| 231 | } |
---|
| 232 | .edit-usernotes-title { |
---|
| 233 | font-size:1.4em; |
---|
| 234 | } |
---|
| 235 | .usernotes-property-input.user-property-input-usernotes { |
---|
| 236 | border: solid 2px #ffa744; |
---|
| 237 | padding: 9px; |
---|
| 238 | } |
---|
[32695] | 239 | |
---|
| 240 | .user-header-usernotes{ |
---|
| 241 | width: 20%; |
---|
| 242 | max-width: 195px; |
---|
| 243 | } |
---|
| 244 | .user-container-usernotes { |
---|
| 245 | width: 20%; |
---|
| 246 | max-width: 195px; |
---|
| 247 | white-space: nowrap; |
---|
| 248 | overflow: hidden; |
---|
| 249 | text-overflow: ellipsis; |
---|
| 250 | } |
---|
| 251 | .user-container-usernotes span { |
---|
| 252 | max-width: 100%; |
---|
| 253 | |
---|
| 254 | overflow: hidden; |
---|
| 255 | text-overflow: ellipsis; |
---|
| 256 | } |
---|
| 257 | |
---|
[32693] | 258 | '; |
---|
| 259 | $content = str_replace($search, $replace.$search, $content); |
---|
| 260 | |
---|
| 261 | return $content; |
---|
| 262 | } |
---|
[27697] | 263 | |
---|
| 264 | add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
[32693] | 265 | function usernotes_ws_users_setInfo($res, $methodName, $params){ |
---|
| 266 | if ($methodName != 'pwg.users.setInfo'){ |
---|
[27697] | 267 | return $res; |
---|
| 268 | } |
---|
[32693] | 269 | if (!isset($_POST['usernotes'])){ |
---|
[27697] | 270 | return $res; |
---|
| 271 | } |
---|
[32693] | 272 | if (count($params['user_id']) == 0){ |
---|
[27697] | 273 | return $res; |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | $updates = array(); |
---|
| 277 | |
---|
[32693] | 278 | foreach ($params['user_id'] as $user_id){ |
---|
[27697] | 279 | $updates[] = array( |
---|
| 280 | 'user_id' => $user_id, |
---|
| 281 | 'usernotes' => $_POST['usernotes'], |
---|
[32693] | 282 | ); |
---|
[27697] | 283 | } |
---|
[32693] | 284 | if (count($updates) > 0){ |
---|
[27697] | 285 | mass_updates( |
---|
| 286 | USER_INFOS_TABLE, |
---|
| 287 | array( |
---|
| 288 | 'primary' => array('user_id'), |
---|
| 289 | 'update' => array('usernotes') |
---|
[32693] | 290 | ), |
---|
[27697] | 291 | $updates |
---|
[32693] | 292 | ); |
---|
[27697] | 293 | } |
---|
| 294 | return $res; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
[32693] | 298 | function usernotes_ws_users_getList($users){ |
---|
[27697] | 299 | $user_ids = array(); |
---|
[32693] | 300 | foreach ($users as $user_id => $user){ |
---|
[27697] | 301 | $user_ids[] = $user_id; |
---|
| 302 | } |
---|
[32693] | 303 | if (count($user_ids) == 0){ |
---|
[27697] | 304 | return $users; |
---|
| 305 | } |
---|
| 306 | $query = ' |
---|
[32693] | 307 | SELECT |
---|
| 308 | user_id, |
---|
| 309 | usernotes |
---|
| 310 | FROM '.USER_INFOS_TABLE.' |
---|
| 311 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
| 312 | ;'; |
---|
[27697] | 313 | $result = pwg_query($query); |
---|
[32693] | 314 | while ($row = pwg_db_fetch_assoc($result)){ |
---|
[27697] | 315 | $users[$row['user_id']]['usernotes'] = $row['usernotes']; |
---|
| 316 | } |
---|
| 317 | return $users; |
---|
| 318 | } |
---|
[32693] | 319 | |
---|
[12447] | 320 | ?> |
---|