Moodle replaces questionmark in URL in query results for non-admin users

Moodle replaces questionmark in URL in query results for non-admin users

by Zoran Jančić -
Number of replies: 2
Picture of Particularly helpful Moodlers

Since templates are not working for a while, I embedded <A> tag with URL to my query to create URL's from query results. Works fine for admin user but for regular user Moodle replaces questionmark with %5B%5BQUESTIONMARK%5D%5D. So this brakes the link obviously. Does anyone hav an idea for a workaround or what capability do I have to add to the user's role so the Moodle doesn't replace the questionmark.

The query returns links to categories on which the user has Mentor role. It works perfectly for admins but Moodle break links for non-admin users. This is the query:

SELECT DISTINCT
concat('<a href="%%WWWROOT%%/course/index.php?categoryid=',cc.id,'">',cc.name,'</a>') AS Category
FROM prefix_course_categories cc
INNER JOIN prefix_context cx ON cc.id = cx.instanceid
INNER JOIN prefix_role_assignments ra ON cx.id = ra.contextid
INNER JOIN prefix_role r ON ra.roleid = r.id
INNER JOIN prefix_user usr ON ra.userid = usr.id
Where r.name='Mentor' and usr.id='%%USERID%%'
ORDER BY cc.depth, cc.path, usr.lastname, usr.firstname, r.name, cc.name

Average of ratings: -
In reply to Zoran Jančić

Re: Moodle replaces questionmark in URL in query results for non-admin users

by Zoran Jančić -
Picture of Particularly helpful Moodlers
Found out what it was. I was using "login as" option instead of the "real" login. Now it's working when I'm properly logged in. Sorry!
Average of ratings: Useful (1)
In reply to Zoran Jančić

Re: Moodle replaces questionmark in URL in query results for non-admin users

by Jim Wagner -

This caused us quite a lot of frustration. Not sure whether it's the new version of the plugin or Moodle 3.7. 

I made a change to moodle/blocks/configurable_reports/reports/sql/report.class.php at about line 130:

Before:
                    foreach ($arrayrow as $ii => $cell) {
                        $cell = format_text($cell, FORMAT_HTML, array('trusted' => true, 'noclean' => true, 'para' => false));
                        $arrayrow[$ii] = str_replace('QUESTIONMARK', '?', $cell);
                    }
After:
                    foreach ($arrayrow as $ii => $cell) {
                        $cell = format_text($cell, FORMAT_HTML, array('trusted' => true, 'noclean' => true, 'para' => false));
                        $cell = str_replace('%5B', '[', $cell); // NSO jjw - added
                        $cell = str_replace('%5D', ']', $cell); // NSO jjw - added
                        $arrayrow[$ii] = str_replace('QUESTIONMARK', '?', $cell);
                    }