22
33class dashlet_limits {
44
5- function show () {
5+ function show ($ limit_to_client_id = 0 ) {
66 global $ app , $ conf ;
77
88 $ limits = array ();
@@ -148,6 +148,12 @@ function show() {
148148 $ client = $ app ->db ->queryOneRecord ("SELECT * FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? " , $ client_group_id );
149149 }
150150
151+ if ($ limit_to_client_id == 0 || !$ app ->auth ->is_admin ()) {
152+ $ client_id = $ _SESSION ['s ' ]['user ' ]['client_id ' ];
153+ } else {
154+ $ client_id = $ limit_to_client_id ;
155+ }
156+
151157 $ rows = array ();
152158 foreach ($ limits as $ limit ) {
153159 $ field = $ limit ['field ' ];
@@ -159,10 +165,10 @@ function show() {
159165 if ($ value != 0 || $ value == $ wb ['unlimited_txt ' ]) {
160166 $ value_formatted = ($ value == '-1 ' )?$ wb ['unlimited_txt ' ]:$ value ;
161167 if ($ limit ['q_type ' ]!='' ){
162- $ usage = $ this ->_get_assigned_quota ($ limit ) . " MB " ;
168+ $ usage = $ this ->_get_assigned_quota ($ limit, $ client_id ) . " MB " ;
163169 $ value_formatted = ($ value == '-1 ' )?$ wb ['unlimited_txt ' ]:$ value . " MB " ;
164170 }
165- else $ usage = $ this ->_get_limit_usage ($ limit );
171+ else $ usage = $ this ->_get_limit_usage ($ limit, $ client_id );
166172 $ percentage = ($ value == '-1 ' || $ value == 0 ? 0 : round (100 * $ usage / $ value ));
167173 $ rows [] = array ('field ' => $ field ,
168174 'field_txt ' => $ wb [$ field .'_txt ' ],
@@ -181,23 +187,26 @@ function show() {
181187
182188 }
183189
184- function _get_limit_usage ($ limit ) {
190+ function _get_limit_usage ($ limit, $ limit_to_client_id ) {
185191 global $ app ;
186192
187193 $ sql = "SELECT count(sys_userid) as number FROM ?? WHERE " ;
188194 if ($ limit ['db_where ' ] != '' ) $ sql .= $ limit ['db_where ' ]." AND " ;
189- $ sql .= $ app ->tform ->getAuthSQL ('r ' );
195+ $ sql .= $ app ->tform ->getAuthSQL ('r ' , '' , $ limit_to_client_id );
196+ // TEST to show reseller data.
197+ //$sql .= $app->tform->getAuthSQL('r', '', 0, '3,28,39');
198+ //echo $sql;
190199 $ rec = $ app ->db ->queryOneRecord ($ sql , $ limit ['db_table ' ]);
191200 return $ rec ['number ' ];
192201
193202 }
194203
195- function _get_assigned_quota ($ limit ) {
204+ function _get_assigned_quota ($ limit, $ limit_to_client_id ) {
196205 global $ app ;
197206
198207 $ sql = "SELECT sum(??) as number FROM ?? WHERE " ;
199208 if ($ limit ['db_where ' ] != '' ) $ sql .= $ limit ['db_where ' ]." AND " ;
200- $ sql .= $ app ->tform ->getAuthSQL ('r ' );
209+ $ sql .= $ app ->tform ->getAuthSQL ('r ' , '' , $ limit_to_client_id );
201210 $ rec = $ app ->db ->queryOneRecord ($ sql , $ limit ['q_type ' ], $ limit ['db_table ' ]);
202211 if ($ limit ['db_table ' ]=='mail_user ' ) $ quotaMB = $ rec ['number ' ] / 1048576 ; // Mail quota is in bytes, must be converted to MB
203212 else $ quotaMB = $ rec ['number ' ];
0 commit comments