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 the "Notes" column in the user table |
---|
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 = ' <!-- email adress --> |
---|
56 | <div class="user-header-col user-header-email not-in-selection-mode"> |
---|
57 | <span>{\'Email Adress\'|@translate}</span> |
---|
58 | </div>'; |
---|
59 | $content = str_replace($search, $search.'<!-- Notes --> |
---|
60 | <div class="user-header-col user-header-notes"> |
---|
61 | <span>{\'Notes\'|@translate}</th></span> |
---|
62 | </div>' |
---|
63 | , $content); |
---|
64 | |
---|
65 | // add the "Notes" |
---|
66 | $search = '<div class="user-col user-container-registration">'; |
---|
67 | $replace = ' <div class="user-col user-container-usernotes"> |
---|
68 | <span><!-- usernotes --></span> |
---|
69 | </div>'; |
---|
70 | $content = str_replace($search, $replace.$search, $content); |
---|
71 | |
---|
72 | // add the "Notes" field in user profile form |
---|
73 | $search = '<div class="user-property-group-container"> |
---|
74 | <p class="user-property-label">{\'Groups\'|@translate}</p> |
---|
75 | <div class="user-property-select-container user-property-group"> |
---|
76 | <select class="user-property-select" data-selectize="groups" placeholder="{\'Select groups or type them\'|translate}" |
---|
77 | name="group_id[]" multiple style="box-sizing:border-box;"></select> |
---|
78 | </div> |
---|
79 | </div>'; |
---|
80 | $replace = '<p class="user-property-label">{\'Notes\'|@translate}</p> |
---|
81 | <div class="user-property-usernotes"> |
---|
82 | <span class="usernotes-title"><!-- usernotes --></span> |
---|
83 | <span class="edit-usernotes icon-pencil"></span> |
---|
84 | </div> |
---|
85 | <div class="user-property-usernotes-change"> |
---|
86 | <div class="summary-input-container"> |
---|
87 | <input class="usernotes-property-input user-property-input-usernotes" value="" placeholder="{\'Notes\'|@translate}" /> |
---|
88 | </div> |
---|
89 | <span class="icon-ok edit-usernotes-validate"></span> |
---|
90 | <span class="icon-cancel-circled edit-usernotes-cancel"></span> |
---|
91 | </div> |
---|
92 | '; |
---|
93 | $content = str_replace($search, $search.$replace, $content); |
---|
94 | |
---|
95 | //css |
---|
96 | $search = '</style>'; |
---|
97 | $replace = ' |
---|
98 | .user-property-usernotes-change { |
---|
99 | justify-content:center; |
---|
100 | align-items:center; |
---|
101 | display:none; |
---|
102 | margin-bottom:25px; |
---|
103 | } |
---|
104 | |
---|
105 | .user-property-usernotes { |
---|
106 | margin-bottom:34px; |
---|
107 | height:30px; |
---|
108 | } |
---|
109 | |
---|
110 | .edit-usernotes-validate { |
---|
111 | display: block; |
---|
112 | margin: auto 5px; |
---|
113 | cursor: pointer; |
---|
114 | background-color: #ffa744; |
---|
115 | color: #3c3c3c; |
---|
116 | font-size: 17px; |
---|
117 | font-weight: 700; |
---|
118 | padding: 7px; |
---|
119 | } |
---|
120 | |
---|
121 | .edit-usernotes-validate:hover { |
---|
122 | background-color: #f70; |
---|
123 | color: #000; |
---|
124 | cursor: pointer; |
---|
125 | } |
---|
126 | .edit-usernotes { |
---|
127 | font-size:1.4em; |
---|
128 | cursor:pointer; |
---|
129 | } |
---|
130 | .edit-usernotes-cancel { |
---|
131 | cursor:pointer; |
---|
132 | font-size:22px; |
---|
133 | padding-top: 4px; |
---|
134 | } |
---|
135 | .usernotes-property-input { |
---|
136 | width: 100%; |
---|
137 | box-sizing:border-box; |
---|
138 | font-size:1.1em; |
---|
139 | padding:8px 16px; |
---|
140 | border:none; |
---|
141 | } |
---|
142 | .edit-usernotes-title { |
---|
143 | font-size:1.4em; |
---|
144 | } |
---|
145 | .usernotes-property-input.user-property-input-usernotes { |
---|
146 | border: solid 2px #ffa744; |
---|
147 | padding: 9px; |
---|
148 | } |
---|
149 | '; |
---|
150 | $content = str_replace($search, $replace.$search, $content); |
---|
151 | |
---|
152 | return $content; |
---|
153 | } |
---|
154 | |
---|
155 | add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
156 | function usernotes_ws_users_setInfo($res, $methodName, $params){ |
---|
157 | if ($methodName != 'pwg.users.setInfo'){ |
---|
158 | return $res; |
---|
159 | } |
---|
160 | if (!isset($_POST['usernotes'])){ |
---|
161 | return $res; |
---|
162 | } |
---|
163 | if (count($params['user_id']) == 0){ |
---|
164 | return $res; |
---|
165 | } |
---|
166 | |
---|
167 | $updates = array(); |
---|
168 | |
---|
169 | foreach ($params['user_id'] as $user_id){ |
---|
170 | $updates[] = array( |
---|
171 | 'user_id' => $user_id, |
---|
172 | 'usernotes' => $_POST['usernotes'], |
---|
173 | ); |
---|
174 | } |
---|
175 | if (count($updates) > 0){ |
---|
176 | mass_updates( |
---|
177 | USER_INFOS_TABLE, |
---|
178 | array( |
---|
179 | 'primary' => array('user_id'), |
---|
180 | 'update' => array('usernotes') |
---|
181 | ), |
---|
182 | $updates |
---|
183 | ); |
---|
184 | } |
---|
185 | return $res; |
---|
186 | } |
---|
187 | |
---|
188 | add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
189 | function usernotes_ws_users_getList($users){ |
---|
190 | $user_ids = array(); |
---|
191 | foreach ($users as $user_id => $user){ |
---|
192 | $user_ids[] = $user_id; |
---|
193 | } |
---|
194 | if (count($user_ids) == 0){ |
---|
195 | return $users; |
---|
196 | } |
---|
197 | $query = ' |
---|
198 | SELECT |
---|
199 | user_id, |
---|
200 | usernotes |
---|
201 | FROM '.USER_INFOS_TABLE.' |
---|
202 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
203 | ;'; |
---|
204 | $result = pwg_query($query); |
---|
205 | while ($row = pwg_db_fetch_assoc($result)){ |
---|
206 | $users[$row['user_id']]['usernotes'] = $row['usernotes']; |
---|
207 | } |
---|
208 | return $users; |
---|
209 | } |
---|
210 | |
---|
211 | ?> |
---|