MyBB Community Forums

Full Version: AdminCP Find attachments multipage fails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
AdminCP / Forums & Posts / Attachments menu / Find attachments

In a query with no conditions, the link for page 2 looks like this.
https://domain.com/forum/admin/index.php?module=forum-attachments&results=1&perpage=20&sortby=filename&order=asc&downloads_dir=greater_than&dateuploaded_dir=less_than&filesize_dir=greater_than&page=2

Clicking on it produces warnings from admin/modules/forum/attachments.php:
line 696 undefined array key 'username'

Find line 696
		if($mybb->input['username'])
and replace with
		if(!empty($mybb->input['username']))

Also produces warnings from a loop
line 881 undefined array key 'filename'
line 881 undefined array key 'mimetype'
line 881 undefined array key 'username'
line 881 undefined array key 'downloads'
line 881 undefined array key 'dateuploaded'
line 881 undefined array key 'filesize'

Find line 881
					if($mybb->input[$var])
and replace with
					if($mybb->get_input($var))

These code changes fix the warnings. The first page of results is always accurate, no matter what combination of search criteria is used.

If a numerical criterion dateuploaded or filesize is used, on the first page the query is evaluated properly, but on subsequent pages the query is not processed correctly. The second time around dateuploaded does not pass the test at line 755
		if(!empty($mybb->input['dateuploaded']) && $mybb->request_method == "post")
		{
			$direction_fields['dateuploaded'] = TIME_NOW-$direction_fields['dateuploaded']*60*60*24;
		}
Consequently, the initial query uses an actual timestamp value, the subsequent query does not. Similarly, filesize is entered on the form in KB, and converted to bytes in the initial query, but the subsequent queries do not.

Fix the numerical conditions for dateuploaded and filesize by dropping the test for request_method because the initial query and the multipage queries are the same.

Find in line 755
if(!empty($mybb->input['dateuploaded']) && $mybb->request_method == "post")
and replace with
if(!empty($mybb->input['dateuploaded']))
Find in line 759
if(!empty($mybb->input['filesize']) && $mybb->request_method == "post")
and replace with
if(!empty($mybb->input['filesize']))

After deleting selected attachments, the form is reset to initial conditions again.