My problem is on a page I wanted to get the course module id. The page was accessed off the Activity Module settings menu by clicking Permissions. The url of this page is WEBROOTadmin/roles/permissions.php?contextid=31. The course module id is not passed in the url so I can't get it with optional_param. However I can still obtain it from $PAGE->cm->id on this page.
Can someone tell me what $PAGE is? i have searched the docs and can't see it. The var_dump of it produces a 37 Mb file which is a bit difficult to understand.