php - Additional web page with flexible access control in Moodle -


in moodle 2.6 created new web page external.php , copied root folder on server. web page contains activity (my own html , javascript) must accessible participants of definite courses. have 3 courses (let's call them a, b , c) , want content of web page visible participants of , b, not participants of c.

so far managed limit access isloggedin() , works fine, compromise.

so question is: possible limit access web page (it not part of course , not intended be) participants of course , b, not c?

this code of external.php:

<?php require_once('config.php'); // open page if user logged in if (isloggedin()) {     $page->set_context(get_system_context());     $page->set_pagelayout('standart');     $page->set_title("experimental page");     $page->set_heading("external");     $page->set_url($cfg->wwwroot . '/external.php');      // adding navbar     $page->navbar->ignore_active();     $strhome = "important";     $page->navbar->add($strhome, new moodle_url('external.php'));      echo $output->header();      // variables content (html , javascript)     $jscr = ""; // code     $htmlscr = ""; // code      // actual content goes here     echo $htmlscr;     echo $jscr;     echo $output->footer(); } // else output error message else {     echo "<h2>please log in procede</h2>"; } ?> 

thank much!

after days of searching in documentation , asking experienced people find solution.

i replaced:

if (isloggedin()) {     code inside } 

with:

if ((is_enrolled(context_course::instance(18), $user)) or (is_enrolled(context_course::instance(20), $user)) or is_siteadmin()) {     code inside } 

this code gives access code inside students enrolled courses id 18 , 20 , administrator.

the course id can found in browser address bar when course main page open.

i hope helpful other moodle administrators.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -