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 | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | // | Define plugin constants | |
---|
17 | // +-----------------------------------------------------------------------+ |
---|
18 | |
---|
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(){ |
---|
31 | load_language('plugin.lang', USERNOTES_PATH); |
---|
32 | global $template; |
---|
33 | $template->assign( |
---|
34 | array( |
---|
35 | 'USERNOTES_PATH2'=> get_root_url().USERNOTES_PATH, |
---|
36 | ) |
---|
37 | ); |
---|
38 | } |
---|
39 | |
---|
40 | add_event_handler('loc_begin_admin_page', 'usernotes_add_column'); |
---|
41 | function usernotes_add_column(){ |
---|
42 | global $template; |
---|
43 | $template->set_prefilter('user_list', 'usernotes_add_column_prefilter'); |
---|
44 | } |
---|
45 | |
---|
46 | function usernotes_add_column_prefilter($content){ |
---|
47 | // add js link |
---|
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 |
---|
55 | $search = '<!-- groups --> |
---|
56 | <div class="user-header-col user-header-groups"> |
---|
57 | <span>{\'Groups\'|@translate}</span> |
---|
58 | </div>'; |
---|
59 | $content = str_replace($search, $search.'<!-- Notes --> |
---|
60 | <div class="user-header-col user-header-usernotes"> |
---|
61 | <span>{\'Notes\'|@translate}</th></span> |
---|
62 | </div>' |
---|
63 | , $content); |
---|
64 | |
---|
65 | // add the "Notes" |
---|
66 | $search = '<div class="user-col user-container-groups"> |
---|
67 | <!-- groups --> |
---|
68 | </div>'; |
---|
69 | $replace = ' <div class="user-col user-container-usernotes"> |
---|
70 | <span><!-- usernotes --></span> |
---|
71 | </div>'; |
---|
72 | $content = str_replace($search, $search.$replace, $content); |
---|
73 | |
---|
74 | // add the "Notes" field in user profile form |
---|
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"> |
---|
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 | } |
---|
199 | |
---|
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; |
---|
209 | } |
---|
210 | |
---|
211 | .edit-usernotes-validate:hover { |
---|
212 | background-color: #f70; |
---|
213 | color: #000; |
---|
214 | cursor: pointer; |
---|
215 | } |
---|
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 | } |
---|
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 | |
---|
258 | '; |
---|
259 | $content = str_replace($search, $replace.$search, $content); |
---|
260 | |
---|
261 | return $content; |
---|
262 | } |
---|
263 | |
---|
264 | add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
265 | function usernotes_ws_users_setInfo($res, $methodName, $params){ |
---|
266 | if ($methodName != 'pwg.users.setInfo'){ |
---|
267 | return $res; |
---|
268 | } |
---|
269 | if (!isset($_POST['usernotes'])){ |
---|
270 | return $res; |
---|
271 | } |
---|
272 | if (count($params['user_id']) == 0){ |
---|
273 | return $res; |
---|
274 | } |
---|
275 | |
---|
276 | $updates = array(); |
---|
277 | |
---|
278 | foreach ($params['user_id'] as $user_id){ |
---|
279 | $updates[] = array( |
---|
280 | 'user_id' => $user_id, |
---|
281 | 'usernotes' => $_POST['usernotes'], |
---|
282 | ); |
---|
283 | } |
---|
284 | if (count($updates) > 0){ |
---|
285 | mass_updates( |
---|
286 | USER_INFOS_TABLE, |
---|
287 | array( |
---|
288 | 'primary' => array('user_id'), |
---|
289 | 'update' => array('usernotes') |
---|
290 | ), |
---|
291 | $updates |
---|
292 | ); |
---|
293 | } |
---|
294 | return $res; |
---|
295 | } |
---|
296 | |
---|
297 | add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
298 | function usernotes_ws_users_getList($users){ |
---|
299 | $user_ids = array(); |
---|
300 | foreach ($users as $user_id => $user){ |
---|
301 | $user_ids[] = $user_id; |
---|
302 | } |
---|
303 | if (count($user_ids) == 0){ |
---|
304 | return $users; |
---|
305 | } |
---|
306 | $query = ' |
---|
307 | SELECT |
---|
308 | user_id, |
---|
309 | usernotes |
---|
310 | FROM '.USER_INFOS_TABLE.' |
---|
311 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
312 | ;'; |
---|
313 | $result = pwg_query($query); |
---|
314 | while ($row = pwg_db_fetch_assoc($result)){ |
---|
315 | $users[$row['user_id']]['usernotes'] = $row['usernotes']; |
---|
316 | } |
---|
317 | return $users; |
---|
318 | } |
---|
319 | |
---|
320 | ?> |
---|