Пример #1
0
/**
 * this function handles all of the necessary session hacks needed by the page course format
 *
 * @param int $courseid course id (used to ensure user has proper capabilities)
 * @param string the action the user is performing
 * @uses $SESSION
 * @uses $USER
 */
function page_handle_session_hacks($courseid, $action)
{
    global $SESSION, $USER, $CFG;
    // load up the context for calling has_capability later
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    // handle any actions that need to push a little state data to the session
    switch ($action) {
        case 'deletemod':
            if (!confirm_sesskey()) {
                error(get_string('confirmsesskeybad', 'error'));
            }
            if (!isloggedin()) {
                // If on site page, then require_login may not be called
                // At this point, we make sure the user is logged in
                require_login($course->id);
            }
            if (has_capability('moodle/course:manageactivities', $context)) {
                // set some session stuff so we can find our way back to where we were
                $SESSION->cfp = new stdClass();
                $SESSION->cfp->action = 'finishdeletemod';
                $SESSION->cfp->deletemod = required_param('cmid', PARAM_INT);
                $SESSION->cfp->id = $courseid;
                // redirect to delete mod
                redirect($CFG->wwwroot . '/course/mod.php?delete=' . $SESSION->cfp->deletemod . '&sesskey=' . sesskey());
            }
            break;
    }
    // handle any cleanup as a result of session being pushed from above block
    if (isset($SESSION->cfp)) {
        // the user did something we need to clean up after
        if (!empty($SESSION->cfp->action)) {
            switch ($SESSION->cfp->action) {
                case 'finishdeletemod':
                    if (!isloggedin()) {
                        // If on site page, then require_login may not be called
                        // At this point, we make sure the user is logged in
                        require_login($course->id);
                    }
                    if (has_capability('moodle/course:manageactivities', $context)) {
                        // Get what we need from session then unset it
                        $sessioncourseid = $SESSION->cfp->id;
                        $deletecmid = $SESSION->cfp->deletemod;
                        unset($SESSION->cfp);
                        // See if the user deleted a module
                        if (!record_exists('course_modules', 'id', $deletecmid)) {
                            // Looks like the user deleted this so clear out corresponding entries in format_page_items
                            if ($pageitems = get_records('format_page_items', 'cmid', $deletecmid)) {
                                foreach ($pageitems as $pageitem) {
                                    page_block_delete($pageitem);
                                }
                            }
                        }
                        if ($courseid == $sessioncourseid and empty($action) and !optional_param('page', 0, PARAM_INT)) {
                            // We are in same course and not performing another action or
                            // looking at a specific page, so redirect back to manage modules
                            // for a nice workflow
                            $action = 'activities';
                        }
                    }
                    break;
                default:
                    // Doesn't match one of our handled session action hacks
                    unset($SESSION->cfp);
                    break;
            }
        }
    }
    return $action;
}
Пример #2
0
/**
 * This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
 * function inorder to decode contents of this block from the backup 
 * format to destination site/course in order to mantain inter-activities 
 * working in the backup/restore process. 
 * 
 * This is called from {@link restore_decode_content_links()}
 * function in the restore process.  This function is called regarless of
 * the return value from {@link backuprestore_enabled()}.
 *
 * @param object $restore Standard restore object
 * @return boolean
 **/
function learning_decode_format_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    // Only need to run this when the restore to course is being
    // deleted and created anew or when creating a new one
    if ($restore->restoreto == 0 || $restore->restoreto == 2 || $restore->course_format == 1) {
        require_once $CFG->dirroot . '/course/format/page/lib.php';
        $pageitems = get_records_sql("SELECT i.*\n                                        FROM {$CFG->prefix}format_page p,\n                                             {$CFG->prefix}format_page_items i\n                                       WHERE p.id = i.pageid\n                                         AND p.courseid = {$restore->course_id}\n                                         AND i.blockinstance != 0");
        if (!empty($pageitems)) {
            foreach ($pageitems as $pageitem) {
                $blockinstance = backup_getid($restore->backup_unique_code, 'block_instance', $pageitem->blockinstance);
                if (!empty($blockinstance)) {
                    set_field('format_page_items', 'blockinstance', $blockinstance->new_id, 'id', $pageitem->id);
                } else {
                    // Delete page item
                    if (page_block_delete($pageitem)) {
                        if (debugging() and !defined('RESTORE_SILENTLY')) {
                            echo '<br /><hr />Failed to remap block instance ID and successfully deleted page item ID: ' . $pageitem->id . '<hr /><br />';
                        }
                    } else {
                        if (debugging() and !defined('RESTORE_SILENTLY')) {
                            echo '<br /><hr />Failed to remap block instance ID and failed to delete page item ID: ' . $pageitem->id . '<hr /><br />';
                        }
                    }
                }
            }
        }
    }
    return $status;
}
/**
 * This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
 * function inorder to decode contents of this block from the backup 
 * format to destination site/course in order to mantain inter-activities 
 * working in the backup/restore process. 
 * 
 * This is called from {@link restore_decode_content_links()}
 * function in the restore process.  This function is called regarless of
 * the return value from {@link backuprestore_enabled()}.
 *
 * @param object $restore Standard restore object
 * @return boolean
 **/
function page_decode_format_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    // not sure what to do with this function, yet. (nadavkav 10-5-2011)
    return $status;
    // Only need to run this when the restore to course is being
    // deleted and created anew or when creating a new one
    if ($restore->restoreto == 0 || $restore->restoreto == 2) {
        require_once $CFG->dirroot . '/course/format/page/lib.php';
        $pageitems = get_records_sql("SELECT i.*\n                                        FROM {$CFG->prefix}format_page p,\n                                             {$CFG->prefix}format_page_items i\n                                       WHERE p.id = i.pageid\n                                         AND p.courseid = {$restore->course_id}\n                                         AND i.blockinstance != 0");
        if (!empty($pageitems)) {
            foreach ($pageitems as $pageitem) {
                $blockinstance = backup_getid($restore->backup_unique_code, 'block_instance', $pageitem->blockinstance);
                if (!empty($blockinstance)) {
                    set_field('format_page_items', 'blockinstance', $blockinstance->new_id, 'id', $pageitem->id);
                } else {
                    // Delete page item
                    if (page_block_delete($pageitem)) {
                        if (debugging() and !defined('RESTORE_SILENTLY')) {
                            echo '<br /><hr />Failed to remap block instance ID and successfully deleted page item ID: ' . $pageitem->id . '<hr /><br />';
                        }
                    } else {
                        if (debugging() and !defined('RESTORE_SILENTLY')) {
                            echo '<br /><hr />Failed to remap block instance ID and failed to delete page item ID: ' . $pageitem->id . '<hr /><br />';
                        }
                    }
                }
            }
        }
        // Relink locks (might be activity based, etc)
        $pages = get_records_sql("SELECT p.id, p.locks\n                                    FROM {$CFG->prefix}format_page p\n                                   WHERE p.courseid = {$restore->course_id}\n                                     AND p.locks != ''");
        if (!empty($pages)) {
            foreach ($pages as $page) {
                if (!empty($page->locks)) {
                    $newlocks = format_page_lock::restore($restore, $page->locks);
                    if ($newlocks != $page->locks) {
                        set_field('format_page', 'locks', $newlocks, 'id', $page->id);
                    }
                }
            }
        }
    }
    return $status;
}