Пример #1
0
 /**
  * Prints the page header.
  */
 function print_header()
 {
     global $CFG, $USER, $PAGE;
     require_once $CFG->libdir . '/blocklib.php';
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/my/pagelib.php';
     /// My Moodle arguments:
     $edit = optional_param('edit', -1, PARAM_BOOL);
     $blockaction = optional_param('blockaction', '', PARAM_ALPHA);
     $mymoodlestr = get_string('mymoodle', 'my');
     if (isguest()) {
         $wwwroot = $CFG->wwwroot . '/login/index.php';
         if (!empty($CFG->loginhttps)) {
             $wwwroot = str_replace('http:', 'https:', $wwwroot);
         }
         print_header($mymoodlestr);
         notice_yesno(get_string('noguest', 'my') . '<br /><br />' . get_string('liketologin'), $wwwroot, $CFG->wwwroot);
         print_footer();
         die;
     }
     /// Add curriculum stylesheets...
     if (file_exists($CFG->dirroot . '/curriculum/styles.css')) {
         $CFG->stylesheets[] = $CFG->wwwroot . '/curriculum/styles.css';
     }
     /// Fool the page library into thinking we're in My Moodle.
     $CFG->pagepath = $CFG->wwwroot . '/my/index.php';
     $PAGE = page_create_instance($USER->id);
     if ($section = optional_param('section', '', PARAM_ALPHAEXT)) {
         $PAGE->section = $section;
     }
     $this->pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
     /// Make sure that the curriculum block is actually on this
     /// user's My Moodle page instance.
     if ($cablockid = get_field('block', 'id', 'name', 'curr_admin')) {
         if (!record_exists('block_pinned', 'blockid', $cablockid, 'pagetype', 'my-index')) {
             blocks_execute_action($PAGE, $this->pageblocks, 'add', (int) $cablockid, true, false);
         }
     }
     if ($edit != -1 and $PAGE->user_allowed_editing()) {
         $USER->editing = $edit;
     }
     //$PAGE->print_header($mymoodlestr);
     $title = $this->get_title();
     print_header($title, $title, build_navigation($this->get_navigation()));
     echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
     echo '<tr valign="top">';
     $blocks_preferred_width = bounded_number(180, blocks_preferred_width($this->pageblocks[BLOCK_POS_LEFT]), 210);
     if (blocks_have_content($this->pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) {
         echo '<td style="vertical-align: top; width: ' . $blocks_preferred_width . 'px;" id="left-column">';
         blocks_print_group($PAGE, $this->pageblocks, BLOCK_POS_LEFT);
         echo '</td>';
     }
     echo '<td valign="top" id="middle-column">';
     if (blocks_have_content($this->pageblocks, BLOCK_POS_CENTRE) || $PAGE->user_is_editing()) {
         blocks_print_group($PAGE, $this->pageblocks, BLOCK_POS_CENTRE);
     }
 }
Пример #2
0
function blocks_execute_url_action(&$PAGE, &$pageblocks, $pinned = false)
{
    $blockaction = optional_param('blockaction', '', PARAM_ALPHA);
    if (empty($blockaction) || !$PAGE->user_allowed_editing() || !confirm_sesskey()) {
        return;
    }
    $instanceid = optional_param('instanceid', 0, PARAM_INT);
    $blockid = optional_param('blockid', 0, PARAM_INT);
    if (!empty($blockid)) {
        blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $blockid, $pinned);
    } else {
        if (!empty($instanceid)) {
            $instance = blocks_find_instance($instanceid, $pageblocks);
            blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance, $pinned);
        }
    }
}
Пример #3
0
                     $newcourse = new object();
                     $newcourse->id = $course->id;
                     $newcourse->marker = $value;
                     if (!update_record('course', $newcourse)) {
                         error_log('AJAX commands.php: Failed to update course marker for course ' . $newcourse->id);
                         die;
                     }
                     break;
             }
             break;
     }
     break;
 case 'DELETE':
     switch ($class) {
         case 'block':
             blocks_execute_action($PAGE, $pageblocks, 'delete', $blockinstance);
             break;
         case 'resource':
             if (!($cm = get_record('course_modules', 'id', $id, 'course', $course->id))) {
                 error_log('AJAX rest.php: Bad course module ID ' . $id);
                 die;
             }
             if (!($mod = get_record('modules', 'id', $cm->module))) {
                 error_log('AJAX rest.php: Bad module ID ' . $cm->module);
                 die;
             }
             $mod->name = clean_param($mod->name, PARAM_SAFEDIR);
             // For safety
             $modlib = "{$CFG->dirroot}/mod/{$mod->name}/lib.php";
             if (file_exists($modlib)) {
                 include_once $modlib;
Пример #4
0
if (empty($CFG->adminblocks_initialised)) {
    require_once "{$CFG->dirroot}/{$CFG->admin}/pagelib.php";
    require_once $CFG->libdir . '/blocklib.php';
    page_map_class(PAGE_ADMIN, 'page_admin');
    $page = page_create_object(PAGE_ADMIN, 0);
    // there must be some id number
    blocks_repopulate_page($page);
    //add admin_tree block to site if not already present
    if ($admintree = get_record('block', 'name', 'admin_tree')) {
        $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
        $pageblocks = blocks_get_by_page($page);
        blocks_execute_action($page, $pageblocks, 'add', (int) $admintree->id, false, false);
        if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
            $pageblocks = blocks_get_by_page($page);
            // Needs to be re-got, since has just changed
            blocks_execute_action($page, $pageblocks, 'moveleft', $admintreeinstance, false, false);
        }
    }
    set_config('adminblocks_initialised', 1);
}
/// Define the unique site ID code if it isn't already set. This getter does that as a side-effect.
get_site_identifier();
/// Check if the guest user exists.  If not, create one.
if (!record_exists("user", "username", "guest")) {
    if (!($guest = create_guest_record())) {
        notify("Could not create guest user record !!!");
    }
}
/// Set up the admin user
if (empty($CFG->rolesactive)) {
    build_context_path();
Пример #5
0
if ($PAGE->user_allowed_editing()) {
    $editing = $PAGE->user_is_editing();
}
// Calculate the preferred width for left, right and center (both center positions will use the same)
$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH);
// Display the blocks and allow blocklib to handle any block action requested
$pageblocks = blocks_get_by_page($PAGE);
if ($editing) {
    if (!empty($blockaction) && confirm_sesskey()) {
        if (!empty($blockid)) {
            blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
        } else {
            if (!empty($instanceid)) {
                $instance = blocks_find_instance($instanceid, $pageblocks);
                blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
            }
        }
        // This re-query could be eliminated by judicious programming in blocks_execute_action(),
        // but I'm not sure if it's worth the complexity increase...
        $pageblocks = blocks_get_by_page($PAGE);
    }
    $missingblocks = blocks_get_missing($PAGE, $pageblocks);
}
if (!empty($tagid)) {
    $taginstance = get_record('tag', 'id', $tagid);
} elseif (!empty($tag)) {
    $taginstance = tag_id($tag);
}
/// navigations
/// site blogs - sitefullname -> blogs -> (?tag)
Пример #6
0
    }
}
// initialise default blocks on admin and site page if needed
if (empty($CFG->adminblocks_initialised)) {
    require_once "{$CFG->dirroot}/{$CFG->admin}/pagelib.php";
    require_once $CFG->libdir . '/blocklib.php';
    page_map_class(PAGE_ADMIN, 'page_admin');
    $page = page_create_object(PAGE_ADMIN, 0);
    // there must be some id number
    blocks_repopulate_page($page);
    //add admin_tree block to site if not already present
    if ($admintree = get_record('block', 'name', 'admin_tree')) {
        $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
        blocks_execute_action($page, blocks_get_by_page($page), 'add', (int) $admintree->id, false, false);
        if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
            blocks_execute_action($page, blocks_get_by_page($page), 'moveleft', $admintreeinstance, false, false);
        }
    }
    set_config('adminblocks_initialised', 1);
}
/// Define the unique site ID code if it isn't already
if (empty($CFG->siteidentifier)) {
    // Unique site identification code
    set_config('siteidentifier', random_string(32) . $_SERVER['HTTP_HOST']);
}
/// Check if the guest user exists.  If not, create one.
if (!record_exists("user", "username", "guest")) {
    if (!($guest = create_guest_record())) {
        notify("Could not create guest user record !!!");
    }
}
Пример #7
0
    $CFG->stylesheets[] = $CFG->wwwroot . '/curriculum/styles.css';
}
/// Fool the page library into thinking we're in My Moodle.
$CFG->pagepath = $CFG->wwwroot . '/my/index.php';
$PAGE = page_create_instance($USER->id);
if ($section = optional_param('section', '', PARAM_ALPHAEXT)) {
    $PAGE->section = $section;
}
$pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
/// Make sure that the curriculum block is actually on this user's My Moodle page instance.
if ($cablockid = get_field('block', 'id', 'name', 'curr_admin')) {
    //        if (!record_exists('block_instance', 'blockid', $cablockid, 'pageid', $USER->id,
    //                           'pagetype', 'my-index')) {
    if (!record_exists('block_pinned', 'blockid', $cablockid, 'pagetype', 'my-index')) {
        //print_object('cablockid: ' . $cablockid);
        blocks_execute_action($PAGE, $pageblocks, 'add', (int) $cablockid, true, false);
    }
}
if ($edit != -1 and $PAGE->user_allowed_editing()) {
    $USER->editing = $edit;
}
$PAGE->print_header($mymoodlestr);
echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
echo '<tr valign="top">';
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) {
    echo '<td style="vertical-align: top; width: ' . $blocks_preferred_width . 'px;" id="left-column">';
    blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
    echo '</td>';
}
echo '<td valign="top" id="middle-column">';