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.
1.8.37, php 8.2, please see if you can recreate this.

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.

As soon as dateuploaded>1500 is a selection criteria, on the first pass the query looks like
string(35) "1=1 AND a.dateuploaded<'1576523035'" 
This is being reported by adding a debug line at 793
			echo '<pre>'.var_dump($search_sql).'</pre>'; echo "\n";

However, when selecting a second page the query runs again. But the query is different, resulting in "No results found."

The link to 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=1500&dateuploaded_dir=less_than&filesize_dir=greater_than&page=2

Clicking on the link for page 2, the query is run again.
Question 1: should it be, it already returned results?
Question 2: why does the query change to
string(29) "1=1 AND a.dateuploaded<'1500'" 

The second time around it 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;
		}

The first query uses an actual timestamp value, the second query does not.

Looking at the conditions where request_method needs to be evaluated, in line 658 the truth table is:
request_method != "post and results !=1 on first pass to display form, nothing to query;
request_method = "post" and results !=1 on first query to find attachments;
request_method != "post" and results =1 on showing subsequent pages.

Results=1 is the trigger to evaluate subsequent pages, request_method="post" only occurs on first query.

Fix the numerical conditions for dateuploaded and filesize by dropping the test for request_method because the initial query and the multipage queries should be 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 selected attachments are deleted, the form resets.