22
33class dashlet_limits
44{
5- public function show ($ limit_to_client_id = 0 )
5+ public function show ()
66 {
77 global $ app , $ conf ;
88
@@ -147,35 +147,33 @@ public function show($limit_to_client_id = 0)
147147 }
148148 $ tpl ->setVar ($ wb );
149149
150- if ($ limit_to_client_id == 0 ) {
151- $ client_id = $ _SESSION ['s ' ]['user ' ]['client_id ' ];
152- $ user_is_admin = true ;
150+ if ($ app ->auth ->is_admin ()) {
151+ $ user_is_admin = true ;
153152 } else {
154- $ client_id = $ limit_to_client_id ;
155- $ user_is_admin = false ;
153+ $ user_is_admin = false ;
156154 }
155+ $ tpl ->setVar ('is_admin ' , $ user_is_admin );
157156
158- $ client_group_id = $ app ->functions ->intval ($ _SESSION ["s " ]["user " ]["default_group " ]);
159- $ client = $ app ->db ->queryOneRecord ("SELECT * FROM client WHERE client_id = ? " , $ client_id );
160-
157+ if ($ user_is_admin == false ) {
158+ $ client_group_id = $ app ->functions ->intval ($ _SESSION ["s " ]["user " ]["default_group " ]);
159+ $ client = $ app ->db ->queryOneRecord ("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ client_group_id );
160+ }
161161
162162 $ rows = array ();
163163 foreach ($ limits as $ limit ) {
164164 $ field = $ limit ['field ' ];
165- $ value = $ client [$ field ];
166165 if ($ user_is_admin ) {
167166 $ value = $ wb ['unlimited_txt ' ];
168167 } else {
169168 $ value = $ client [$ field ];
170169 }
171-
172170 if ($ value != 0 || $ value == $ wb ['unlimited_txt ' ]) {
173171 $ value_formatted = ($ value == '-1 ' )?$ wb ['unlimited_txt ' ]:$ value ;
174172 if (isset ($ limit ['q_type ' ]) && $ limit ['q_type ' ] != '' ) {
175- $ usage = $ this ->_get_assigned_quota ($ limit, $ client_id ) . " MB " ;
173+ $ usage = $ this ->_get_assigned_quota ($ limit ) . " MB " ;
176174 $ value_formatted = ($ value == '-1 ' )?$ wb ['unlimited_txt ' ]:$ value . " MB " ;
177175 } else {
178- $ usage = $ this ->_get_limit_usage ($ limit, $ client_id );
176+ $ usage = $ this ->_get_limit_usage ($ limit );
179177 }
180178 $ percentage = ($ value == '-1 ' || intval ($ value ) == 0 || trim ($ value ) == '' ? -1 : round (100 * (int )$ usage / (int )$ value ));
181179 $ progressbar = $ percentage > 100 ? 100 : $ percentage ;
@@ -197,31 +195,28 @@ public function show($limit_to_client_id = 0)
197195 return $ tpl ->grab ();
198196 }
199197
200- public function _get_limit_usage ($ limit, $ limit_to_client_id )
198+ public function _get_limit_usage ($ limit )
201199 {
202200 global $ app ;
203201
204202 $ sql = "SELECT count(sys_userid) as number FROM ?? WHERE " ;
205203 if ($ limit ['db_where ' ] != '' ) {
206204 $ sql .= $ limit ['db_where ' ]." AND " ;
207205 }
208- $ sql .= $ app ->tform ->getAuthSQL ('r ' , '' , $ limit_to_client_id );
209- // TEST to show reseller data.
210- //$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39');
211- //echo $sql;
206+ $ sql .= $ app ->tform ->getAuthSQL ('r ' );
212207 $ rec = $ app ->db ->queryOneRecord ($ sql , $ limit ['db_table ' ]);
213208 return $ rec ['number ' ];
214209 }
215210
216- public function _get_assigned_quota ($ limit, $ limit_to_client_id )
211+ public function _get_assigned_quota ($ limit )
217212 {
218213 global $ app ;
219214
220215 $ sql = "SELECT sum(??) as number FROM ?? WHERE " ;
221216 if ($ limit ['db_where ' ] != '' ) {
222217 $ sql .= $ limit ['db_where ' ]." AND " ;
223218 }
224- $ sql .= $ app ->tform ->getAuthSQL ('r ' , '' , $ limit_to_client_id );
219+ $ sql .= $ app ->tform ->getAuthSQL ('r ' );
225220 $ rec = $ app ->db ->queryOneRecord ($ sql , $ limit ['q_type ' ], $ limit ['db_table ' ]);
226221 if ($ limit ['db_table ' ]=='mail_user ' ) {
227222 $ quotaMB = $ rec ['number ' ] / 1048576 ;
0 commit comments