22
33class dashlet_limits
44{
5- public function show ()
5+ public function show ($ limit_to_client_id = 0 )
66 {
77 global $ app , $ conf ;
88
@@ -147,33 +147,35 @@ public function show()
147147 }
148148 $ tpl ->setVar ($ wb );
149149
150- if ($ app ->auth ->is_admin ()) {
151- $ user_is_admin = true ;
150+ if ($ limit_to_client_id == 0 ) {
151+ $ client_id = $ _SESSION ['s ' ]['user ' ]['client_id ' ];
152+ $ user_is_admin = true ;
152153 } else {
153- $ user_is_admin = false ;
154+ $ client_id = $ limit_to_client_id ;
155+ $ user_is_admin = false ;
154156 }
155- $ tpl ->setVar ('is_admin ' , $ user_is_admin );
156157
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- }
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+
161161
162162 $ rows = array ();
163163 foreach ($ limits as $ limit ) {
164164 $ field = $ limit ['field ' ];
165+ $ value = $ client [$ field ];
165166 if ($ user_is_admin ) {
166167 $ value = $ wb ['unlimited_txt ' ];
167168 } else {
168169 $ value = $ client [$ field ];
169170 }
171+
170172 if ($ value != 0 || $ value == $ wb ['unlimited_txt ' ]) {
171173 $ value_formatted = ($ value == '-1 ' )?$ wb ['unlimited_txt ' ]:$ value ;
172174 if (isset ($ limit ['q_type ' ]) && $ limit ['q_type ' ] != '' ) {
173- $ usage = $ this ->_get_assigned_quota ($ limit ) . " MB " ;
175+ $ usage = $ this ->_get_assigned_quota ($ limit, $ client_id ) . " MB " ;
174176 $ value_formatted = ($ value == '-1 ' )?$ wb ['unlimited_txt ' ]:$ value . " MB " ;
175177 } else {
176- $ usage = $ this ->_get_limit_usage ($ limit );
178+ $ usage = $ this ->_get_limit_usage ($ limit, $ client_id );
177179 }
178180 $ percentage = ($ value == '-1 ' || intval ($ value ) == 0 || trim ($ value ) == '' ? -1 : round (100 * (int )$ usage / (int )$ value ));
179181 $ progressbar = $ percentage > 100 ? 100 : $ percentage ;
@@ -195,28 +197,31 @@ public function show()
195197 return $ tpl ->grab ();
196198 }
197199
198- public function _get_limit_usage ($ limit )
200+ public function _get_limit_usage ($ limit, $ limit_to_client_id )
199201 {
200202 global $ app ;
201203
202204 $ sql = "SELECT count(sys_userid) as number FROM ?? WHERE " ;
203205 if ($ limit ['db_where ' ] != '' ) {
204206 $ sql .= $ limit ['db_where ' ]." AND " ;
205207 }
206- $ sql .= $ app ->tform ->getAuthSQL ('r ' );
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;
207212 $ rec = $ app ->db ->queryOneRecord ($ sql , $ limit ['db_table ' ]);
208213 return $ rec ['number ' ];
209214 }
210215
211- public function _get_assigned_quota ($ limit )
216+ public function _get_assigned_quota ($ limit, $ limit_to_client_id )
212217 {
213218 global $ app ;
214219
215220 $ sql = "SELECT sum(??) as number FROM ?? WHERE " ;
216221 if ($ limit ['db_where ' ] != '' ) {
217222 $ sql .= $ limit ['db_where ' ]." AND " ;
218223 }
219- $ sql .= $ app ->tform ->getAuthSQL ('r ' );
224+ $ sql .= $ app ->tform ->getAuthSQL ('r ' , '' , $ limit_to_client_id );
220225 $ rec = $ app ->db ->queryOneRecord ($ sql , $ limit ['q_type ' ], $ limit ['db_table ' ]);
221226 if ($ limit ['db_table ' ]=='mail_user ' ) {
222227 $ quotaMB = $ rec ['number ' ] / 1048576 ;
0 commit comments