php code in Resources

php code in Resources

by Bill Burgos -
Number of replies: 6
Greetings all,

I am wondering if one can enter php code in the HTML choice of Resources?

I have tried, but it seems to not parse at all.

Thanks in advance.

Bill
Average of ratings: -
In reply to Bill Burgos

Re: php code in Resources

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
No, not possible ... that would be a massive security risk.

Perhaps that might be an optional feature to add sometime, though, for admins only, perhaps.
In reply to Martin Dougiamas

Re: php code in Resources

by Bill Burgos -
Martin,

Thanks for your reply.

I asked the question because I am writing material in html and php format. Right now I am using resource to link to the 'web page' option. The problem is that when displayed, anyone can open the nested frame in a new window which allows anyone to see the material and/or bookmark to the same. This could allow anyone outside of the course to view the material.

I thought that if I can include the php code within the resource module, the material would only be viewed within the platform.

Any ideas on how to protect the material within the Moodle platform and use php.... and keep it safe?

Thanks in advance.

Bill
In reply to Bill Burgos

Re: php code in Resources

by Greg Barnett -
in your php, include the moodle config file. use moodle functions such as isadmin, isguest, etc to validate users.

I do variations on the above for lots of pages. I find that using my makeclass utility (found in contrib, which you can get from moodle cvs) makes integrating moodle code with existing code much easier.
In reply to Greg Barnett

Re: php code in Resources

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Yep, what Greg said.

To be more specific, add:
      require("location/moodle/config.php");
at the top of each of your PHP scripts, and then:
      require_login(); 
followed by your code. All this does is check that the person is logged in to the server - it does not do a check for enrolment in a course (sadly this isn't currently possible in normal resources).

Another way is to use the "Program" resource type. This passes url, username, password etc to the external resource (as part of the URL, ie GET). You can get more details on the format by looking in mod/resource/view.php (must document it some day). The Program type probably needs some work to pass information in a less convoluted way, but it should be usable enough.
In reply to Martin Dougiamas

Re: php code in Resources

by Greg Barnett -
For a complete sample of something I put together that ties in to moodle:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/moodle/moodle/contrib/crown_college/userDirectory/