Example #1
1
/**
 * Common setup for all pages for editing questions.
 * @param string $edittab code for this edit tab
 * @param boolean $requirecmid require cmid? default false
 * @param boolean $requirecourseid require courseid, if cmid is not given? default true
 * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars
 */
function question_edit_setup($edittab, $requirecmid = false, $requirecourseid = true)
{
    global $COURSE, $QUESTION_EDITTABCAPS;
    //$thispageurl is used to construct urls for all question edit pages we link to from this page. It contains an array
    //of parameters that are passed from page to page.
    $thispageurl = new moodle_url();
    if ($requirecmid) {
        $cmid = required_param('cmid', PARAM_INT);
    } else {
        $cmid = optional_param('cmid', 0, PARAM_INT);
    }
    if ($cmid) {
        list($module, $cm) = get_module_from_cmid($cmid);
        $courseid = $cm->course;
        $thispageurl->params(compact('cmid'));
        require_login($courseid, false, $cm);
        $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid);
    } else {
        $module = null;
        $cm = null;
        if ($requirecourseid) {
            $courseid = required_param('courseid', PARAM_INT);
        } else {
            $courseid = optional_param('courseid', 0, PARAM_INT);
        }
        if ($courseid) {
            $thispageurl->params(compact('courseid'));
            require_login($courseid, false);
            $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid);
        } else {
            $thiscontext = null;
        }
    }
    if ($thiscontext) {
        $contexts = new question_edit_contexts($thiscontext);
        $contexts->require_one_edit_tab_cap($edittab);
    } else {
        $contexts = null;
    }
    $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT);
    //pass 'cat' from page to page and when 'category' comes from a drop down menu
    //then we also reset the qpage so we go to page 1 of
    //a new cat.
    $pagevars['cat'] = optional_param('cat', 0, PARAM_SEQUENCE);
    // if empty will be set up later
    if ($category = optional_param('category', 0, PARAM_SEQUENCE)) {
        if ($pagevars['cat'] != $category) {
            // is this a move to a new category?
            $pagevars['cat'] = $category;
            $pagevars['qpage'] = 0;
        }
    }
    if ($pagevars['cat']) {
        $thispageurl->param('cat', $pagevars['cat']);
    }
    if ($pagevars['qpage'] > -1) {
        $thispageurl->param('qpage', $pagevars['qpage']);
    } else {
        $pagevars['qpage'] = 0;
    }
    $pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT);
    if ($pagevars['qperpage'] > -1) {
        $thispageurl->param('qperpage', $pagevars['qperpage']);
    } else {
        $pagevars['qperpage'] = DEFAULT_QUESTIONS_PER_PAGE;
    }
    $sortoptions = array('alpha' => 'name, qtype ASC', 'typealpha' => 'qtype, name ASC', 'age' => 'id ASC');
    if ($sortorder = optional_param('qsortorder', '', PARAM_ALPHA)) {
        $pagevars['qsortorderdecoded'] = $sortoptions[$sortorder];
        $pagevars['qsortorder'] = $sortorder;
        $thispageurl->param('qsortorder', $sortorder);
    } else {
        $pagevars['qsortorderdecoded'] = $sortoptions['typealpha'];
        $pagevars['qsortorder'] = 'typealpha';
    }
    $defaultcategory = question_make_default_categories($contexts->all());
    $contextlistarr = array();
    foreach ($contexts->having_one_edit_tab_cap($edittab) as $context) {
        $contextlistarr[] = "'{$context->id}'";
    }
    $contextlist = join($contextlistarr, ' ,');
    if (!empty($pagevars['cat'])) {
        $catparts = explode(',', $pagevars['cat']);
        if (!$catparts[0] || FALSE !== array_search($catparts[1], $contextlistarr) || !count_records_select("question_categories", "id = '" . $catparts[0] . "' AND contextid = {$catparts['1']}")) {
            print_error('invalidcategory', 'quiz');
        }
    } else {
        $category = $defaultcategory;
        $pagevars['cat'] = "{$category->id},{$category->contextid}";
    }
    if (($recurse = optional_param('recurse', -1, PARAM_BOOL)) != -1) {
        $pagevars['recurse'] = $recurse;
        $thispageurl->param('recurse', $recurse);
    } else {
        $pagevars['recurse'] = 1;
    }
    if (($showhidden = optional_param('showhidden', -1, PARAM_BOOL)) != -1) {
        $pagevars['showhidden'] = $showhidden;
        $thispageurl->param('showhidden', $showhidden);
    } else {
        $pagevars['showhidden'] = 0;
    }
    if (($showquestiontext = optional_param('showquestiontext', -1, PARAM_BOOL)) != -1) {
        $pagevars['showquestiontext'] = $showquestiontext;
        $thispageurl->param('showquestiontext', $showquestiontext);
    } else {
        $pagevars['showquestiontext'] = 0;
    }
    //category list page
    $pagevars['cpage'] = optional_param('cpage', 1, PARAM_INT);
    if ($pagevars['cpage'] < 1) {
        $pagevars['cpage'] = 1;
    }
    if ($pagevars['cpage'] != 1) {
        $thispageurl->param('cpage', $pagevars['cpage']);
    }
    return array($thispageurl, $contexts, $cmid, $cm, $module, $pagevars);
}
 function get_content()
 {
     global $CFG, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (!defined('FEEDBACK_BLOCK_LIB_IS_OK')) {
         $this->content->items = array(get_string('missing_feedback_module', 'block_feedback'));
         return $this->content;
     }
     $courseid = $this->page->course->id;
     if ($courseid <= 0) {
         $courseid = SITEID;
     }
     $icon = '<img src="' . $OUTPUT->pix_url('icon', 'feedback') . '" class="icon" alt="" />';
     if (empty($this->instance->pageid)) {
         $this->instance->pageid = SITEID;
     }
     if ($feedbacks = feedback_get_feedbacks_from_sitecourse_map($courseid)) {
         $baseurl = new moodle_url('/mod/feedback/view.php');
         foreach ($feedbacks as $feedback) {
             $url = new moodle_url($baseurl);
             $url->params(array('id' => $feedback->cmid, 'courseid' => $courseid));
             $this->content->items[] = '<a href="' . $url->out() . '">' . $icon . $feedback->name . '</a>';
         }
     }
     return $this->content;
 }
 public function destination_courses_selector(moodle_url $nextstageurl, destination_courses_search $courses = null, $courseid)
 {
     $html = html_writer::start_tag('div', array('class' => 'import-course-selector backup-restore'));
     $html .= html_writer::start_tag('form', array('method' => 'post', 'action' => $nextstageurl->out_omit_querystring()));
     foreach ($nextstageurl->params() as $key => $value) {
         $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value));
     }
     $html .= html_writer::start_tag('div', array('class' => 'ics-existing-group backup-section'));
     $html .= $this->output->heading(get_string('selectgroups', 'local_syncgroups'), 2, array('class' => 'header'));
     $html .= html_writer::start_tag('ul');
     $groups = groups_get_all_groups($courseid, 0, 0, 'g.id, g.name');
     foreach ($groups as $group) {
         $html .= html_writer::start_tag('li') . html_writer::checkbox('groups[]', $group->id, false, $group->name) . html_writer::end_tag('li');
     }
     $html .= html_writer::end_tag('ul');
     $html .= html_writer::end_tag('div');
     // We only allow import adding for now. Enforce it here.
     $html .= html_writer::start_tag('div', array('class' => 'ics-existing-course backup-section'));
     $html .= $this->output->heading(get_string('syncgroupsto', 'local_syncgroups'), 2, array('class' => 'header'));
     $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
     $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('continue'))));
     $html .= html_writer::end_tag('div');
     $html .= html_writer::end_tag('form');
     $html .= html_writer::end_tag('div');
     return $html;
 }
 /**
  * set up the class for the view page
  *
  * @param string $baseurl the base url of the page
  */
 public function setup_page($baseurl)
 {
     global $PAGE, $CFG, $DB;
     $this->pagevars = array();
     $this->pageurl = new \moodle_url($baseurl);
     $this->pageurl->remove_all_params();
     $id = optional_param('id', false, PARAM_INT);
     $quizid = optional_param('quizid', false, PARAM_INT);
     // get necessary records from the DB
     if ($id) {
         $cm = get_coursemodule_from_id('activequiz', $id, 0, false, MUST_EXIST);
         $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
         $quiz = $DB->get_record('activequiz', array('id' => $cm->instance), '*', MUST_EXIST);
     } else {
         $quiz = $DB->get_record('activequiz', array('id' => $quizid), '*', MUST_EXIST);
         $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
         $cm = get_coursemodule_from_instance('activequiz', $quiz->id, $course->id, false, MUST_EXIST);
     }
     $this->get_parameters();
     // get the rest of the parameters and set them in the class
     require_login($course->id, false, $cm);
     $this->pageurl->param('id', $cm->id);
     $this->pageurl->param('quizid', $quiz->id);
     $this->pageurl->params($this->pagevars);
     // add the page vars variable to the url
     $this->pagevars['pageurl'] = $this->pageurl;
     $this->RTQ = new \mod_activequiz\activequiz($cm, $course, $quiz, $this->pagevars);
     $this->RTQ->require_capability('mod/activequiz:viewownattempts');
     // set up renderer
     $this->RTQ->get_renderer()->init($this->RTQ, $this->pageurl, $this->pagevars);
     $PAGE->set_pagelayout('popup');
     $PAGE->set_context($this->RTQ->getContext());
     $PAGE->set_title(strip_tags($course->shortname . ': ' . get_string("modulename", "activequiz") . ': ' . format_string($quiz->name, true)));
     $PAGE->set_heading($course->fullname);
     $PAGE->set_url($this->pageurl);
 }
$params = array('enrolid' => $ue->enrolid);
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
context_instance_preload($course);
if ($course->id == SITEID) {
    redirect(new moodle_url('/'));
}
require_login($course);
require_capability("enrol/invitation:unenrol", context_course::instance($course->id, MUST_EXIST));
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
// The URL of the enrolled users page for the course.
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
// The URl to return the user too after this screen.
$returnurl = new moodle_url($usersurl, $manager->get_url_params() + $table->get_url_params());
// The URL of this page.
$url = new moodle_url('/enrol/invitation/unenroluser.php', $returnurl->params());
$url->param('ue', $ueid);
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'invitation' || !$plugin instanceof enrol_invitation_plugin) {
    print_error('erroreditenrolment', 'enrol');
}
// If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) {
    redirect($returnurl);
}
$yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unenroluser', 'enrol_invitation', array('user' => fullname($user, true), 'course' => format_string($course->fullname)));
$fullname = fullname($user);
////////////////////////////////////////////////////////
if ($do_show == 'showentries') {
    //print the link to analysis
    if (has_capability('mod/feedback:viewreports', $context)) {
        //get the effective groupmode of this course and module
        if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
            $groupmode = $cm->groupmode;
        } else {
            $groupmode = $course->groupmode;
        }
        // $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/show_entries.php?id=' . $cm->id.'&do_show=showentries', true);
        $groupselect = groups_print_activity_menu($cm, $url->out(), true);
        $mygroupid = groups_get_activity_group($cm);
        // preparing the table for output
        $baseurl = new moodle_url('/mod/feedback/show_entries.php');
        $baseurl->params(array('id' => $id, 'do_show' => $do_show, 'showall' => $showall));
        $tablecolumns = array('userpic', 'fullname', 'c.timemodified');
        $tableheaders = array(get_string('userpic'), get_string('fullnameuser'), get_string('date'));
        if (has_capability('mod/feedback:deletesubmissions', $context)) {
            $tablecolumns[] = 'deleteentry';
            $tableheaders[] = '';
        }
        $table = new flexible_table('feedback-showentry-list-' . $course->id);
        $table->define_columns($tablecolumns);
        $table->define_headers($tableheaders);
        $table->define_baseurl($baseurl);
        $table->sortable(true, 'lastname', SORT_DESC);
        $table->set_attribute('cellspacing', '0');
        $table->set_attribute('id', 'showentrytable');
        $table->set_attribute('class', 'generaltable generalbox');
        $table->set_control_variables(array(TABLE_VAR_SORT => 'ssort', TABLE_VAR_IFIRST => 'sifirst', TABLE_VAR_ILAST => 'silast', TABLE_VAR_PAGE => 'spage'));
 /**
  * Renders the process stage screen
  *
  * @throws restore_ui_exception
  * @param core_backup_renderer $renderer renderer instance to use
  * @return string HTML code
  */
 public function display(core_backup_renderer $renderer)
 {
     global $PAGE;
     $html = '';
     $haserrors = false;
     $url = new moodle_url($PAGE->url, array('restore' => $this->get_uniqueid(), 'stage' => restore_ui::STAGE_PROCESS, 'substage' => $this->substage, 'sesskey' => sesskey()));
     $html .= html_writer::start_tag('form', array('action' => $url->out_omit_querystring(), 'class' => 'backup-restore', 'enctype' => 'application/x-www-form-urlencoded', 'method' => 'post'));
     foreach ($url->params() as $name => $value) {
         $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name, 'value' => $value));
     }
     switch ($this->substage) {
         case self::SUBSTAGE_PRECHECKS:
             $results = $this->ui->get_controller()->get_precheck_results();
             $info = $this->ui->get_controller()->get_info();
             $haserrors = !empty($results['errors']);
             $html .= $renderer->precheck_notices($results);
             if (!empty($info->role_mappings->mappings)) {
                 $context = context_course::instance($this->ui->get_controller()->get_courseid());
                 $assignableroles = get_assignable_roles($context, ROLENAME_ALIAS, false);
                 $html .= $renderer->role_mappings($info->role_mappings->mappings, $assignableroles);
             }
             break;
         default:
             throw new restore_ui_exception('backup_ui_must_execute_first');
     }
     $html .= $renderer->substage_buttons($haserrors);
     $html .= html_writer::end_tag('form');
     return $html;
 }
Example #8
0
 /**
  * Renders a text with icons to sort by the given column
  *
  * This is intended for table headings.
  *
  * @param string $text    The heading text
  * @param string $sortid  The column id used for sorting
  * @param string $sortby  Currently sorted by (column id)
  * @param string $sorthow Currently sorted how (ASC|DESC)
  *
  * @return string
  */
 protected function helper_sortable_heading($text, $sortid = null, $sortby = null, $sorthow = null)
 {
     $out = html_writer::tag('span', $text, array('class' => 'text'));
     if (!is_null($sortid)) {
         if ($sortby !== $sortid || $sorthow !== 'ASC') {
             $url = new moodle_url($this->page->url);
             $url->params(array('sort' => $sortid, 'dir' => 'ASC'));
             $out .= $this->output->action_icon($url, new pix_icon('t/sort_asc', get_string('sortbyx', 'core', s($text)), null, array('class' => 'iconsort')));
         }
         if ($sortby !== $sortid || $sorthow !== 'DESC') {
             $url = new moodle_url($this->page->url);
             $url->params(array('sort' => $sortid, 'dir' => 'DESC'));
             $out .= $this->output->action_icon($url, new pix_icon('t/sort_desc', get_string('sortbyxreverse', 'core', s($text)), null, array('class' => 'iconsort')));
         }
     }
     return $out;
 }
$params = array('enrolid' => $ue->enrolid);
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
context_instance_preload($course);
if ($course->id == SITEID) {
    redirect(new moodle_url('/'));
}
require_login($course);
require_capability("enrol/manual:unenrol", get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST));
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
// The URL of the enrolled users page for the course.
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
// The URl to return the user too after this screen.
$returnurl = new moodle_url($usersurl, $manager->get_url_params() + $table->get_url_params());
// The URL of this page
$url = new moodle_url('/enrol/manual/unenroluser.php', $returnurl->params());
$url->param('ue', $ueid);
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'manual' || !$plugin instanceof enrol_manual_plugin) {
    print_error('erroreditenrolment', 'enrol');
}
// If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) {
    redirect($returnurl);
}
$yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unenroluser', 'enrol_manual', array('user' => fullname($user, true), 'course' => format_string($course->fullname)));
$fullname = fullname($user);
Example #10
0
/**
 * Outputs the forum post indicated by $activity.
 *
 * @param object $activity      the activity object the forum resides in
 * @param int    $courseid      the id of the course the forum resides in
 * @param bool   $detail        not used, but required for compatibilty with other modules
 * @param int    $modnames      not used, but required for compatibilty with other modules
 * @param bool   $viewfullnames not used, but required for compatibilty with other modules
 */
function forum_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames)
{
    global $OUTPUT;
    $content = $activity->content;
    if ($content->parent) {
        $class = 'reply';
    } else {
        $class = 'discussion';
    }
    $tableoptions = ['border' => '0', 'cellpadding' => '3', 'cellspacing' => '0', 'class' => 'forum-recent'];
    $output = html_writer::start_tag('table', $tableoptions);
    $output .= html_writer::start_tag('tr');
    $post = (object) ['parent' => $content->parent];
    $forum = (object) ['type' => $content->forumtype];
    $authorhidden = forum_is_author_hidden($post, $forum);
    // Show user picture if author should not be hidden.
    if (!$authorhidden) {
        $pictureoptions = ['courseid' => $courseid, 'link' => $authorhidden, 'alttext' => $authorhidden];
        $picture = $OUTPUT->user_picture($activity->user, $pictureoptions);
        $output .= html_writer::tag('td', $picture, ['class' => 'userpicture', 'valign' => 'top']);
    }
    // Discussion title and author.
    $output .= html_writer::start_tag('td', ['class' => $class]);
    if ($content->parent) {
        $class = 'title';
    } else {
        // Bold the title of new discussions so they stand out.
        $class = 'title bold';
    }
    $output .= html_writer::start_div($class);
    if ($detail) {
        $aname = s($activity->name);
        $output .= html_writer::img($OUTPUT->pix_url('icon', $activity->type), $aname, ['class' => 'icon']);
    }
    $discussionurl = new moodle_url('/mod/forum/discuss.php', ['d' => $content->discussion]);
    $discussionurl->set_anchor('p' . $activity->content->id);
    $output .= html_writer::link($discussionurl, $content->subject);
    $output .= html_writer::end_div();
    $timestamp = userdate($activity->timestamp);
    if ($authorhidden) {
        $authornamedate = $timestamp;
    } else {
        $fullname = fullname($activity->user, $viewfullnames);
        $userurl = new moodle_url('/user/view.php');
        $userurl->params(['id' => $activity->user->id, 'course' => $courseid]);
        $by = new stdClass();
        $by->name = html_writer::link($userurl, $fullname);
        $by->date = $timestamp;
        $authornamedate = get_string('bynameondate', 'forum', $by);
    }
    $output .= html_writer::div($authornamedate, 'user');
    $output .= html_writer::end_tag('td');
    $output .= html_writer::end_tag('tr');
    $output .= html_writer::end_tag('table');
    echo $output;
}
Example #11
0
    echo html_writer::end_tag('form');
    echo html_writer::empty_tag('br');
}

echo html_writer::start_tag('div', array('class' => 'buttons'));
if ($canmanage and $numcourses > 1 && empty($searchcriteria)) {
    // Print button to re-sort courses by name.
    $url = new moodle_url('/course/manage.php', array('categoryid' => $id, 'resort' => 'name', 'sesskey' => sesskey()));
    echo $OUTPUT->single_button($url, get_string('resortcoursesbyname'), 'get');
}

if (has_capability('moodle/course:create', $context) && empty($searchcriteria)) {
    // Print button to create a new course.
    $url = new moodle_url('/course/edit.php');
    if ($coursecat->id) {
        $url->params(array('category' => $coursecat->id, 'returnto' => 'catmanage'));
    } else {
        $url->params(array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcatmanage'));
    }
    echo $OUTPUT->single_button($url, get_string('addnewcourse'), 'get');
}

if (!empty($CFG->enablecourserequests) && $id == $CFG->defaultrequestcategory) {
    print_course_request_buttons(context_system::instance());
}
echo html_writer::end_tag('div');

echo $courserenderer->course_search_form();

echo $OUTPUT->footer();
Example #12
0
    public function wiki_print_subwiki_selector($wiki, $subwiki, $page, $pagetype = 'view') {
        global $CFG, $USER;
        require_once($CFG->dirroot . '/user/lib.php');
        switch ($pagetype) {
        case 'files':
            $baseurl = new moodle_url('/mod/wiki/files.php');
            break;
        case 'view':
        default:
            $baseurl = new moodle_url('/mod/wiki/view.php');
            break;
        }

        $cm = get_coursemodule_from_instance('wiki', $wiki->id);
        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
        // @TODO: A plenty of duplicated code below this lines.
        // Create private functions.
        switch (groups_get_activity_groupmode($cm)) {
        case NOGROUPS:
            if ($wiki->wikimode == 'collaborative') {
                // No need to print anything
                return;
            } else if ($wiki->wikimode == 'individual') {
                // We have private wikis here

                $view = has_capability('mod/wiki:viewpage', $context);
                $manage = has_capability('mod/wiki:managewiki', $context);

                // Only people with these capabilities can view all wikis
                if ($view && $manage) {
                    // @TODO: Print here a combo that contains all users.
                    $users = get_enrolled_users($context);
                    $options = array();
                    foreach ($users as $user) {
                        $options[$user->id] = fullname($user);
                    }

                    echo $this->output->container_start('wiki_right');
                    $params = array('wid' => $wiki->id, 'title' => $page->title);
                    if ($pagetype == 'files') {
                        $params['pageid'] = $page->id;
                    }
                    $baseurl->params($params);
                    $name = 'uid';
                    $selected = $subwiki->userid;
                    echo $this->output->single_select($baseurl, $name, $options, $selected);
                    echo $this->output->container_end();
                }
                return;
            } else {
                // error
                return;
            }
        case SEPARATEGROUPS:
            if ($wiki->wikimode == 'collaborative') {
                // We need to print a select to choose a course group

                $params = array('wid'=>$wiki->id, 'title'=>$page->title);
                if ($pagetype == 'files') {
                    $params['pageid'] = $page->id;
                }
                $baseurl->params($params);

                echo $this->output->container_start('wiki_right');
                groups_print_activity_menu($cm, $baseurl->out());
                echo $this->output->container_end();
                return;
            } else if ($wiki->wikimode == 'individual') {
                //  @TODO: Print here a combo that contains all users of that subwiki.
                $view = has_capability('mod/wiki:viewpage', $context);
                $manage = has_capability('mod/wiki:managewiki', $context);

                // Only people with these capabilities can view all wikis
                if ($view && $manage) {
                    $users = get_enrolled_users($context);
                    $options = array();
                    foreach ($users as $user) {
                        $groups = groups_get_all_groups($cm->course, $user->id);
                        if (!empty($groups)) {
                            foreach ($groups as $group) {
                                $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
                            }
                        } else {
                            $name = get_string('notingroup', 'wiki');
                            $options[0][$name]['0' . '-' . $user->id] = fullname($user);
                        }
                    }
                } else {
                    $group = groups_get_group($subwiki->groupid);
                    $users = groups_get_members($subwiki->groupid);
                    foreach ($users as $user) {
                        $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
                    }
                }
                echo $this->output->container_start('wiki_right');
                $params = array('wid' => $wiki->id, 'title' => $page->title);
                if ($pagetype == 'files') {
                    $params['pageid'] = $page->id;
                }
                $baseurl->params($params);
                $name = 'groupanduser';
                $selected = $subwiki->groupid . '-' . $subwiki->userid;
                echo $this->output->single_select($baseurl, $name, $options, $selected);
                echo $this->output->container_end();

                return;

            } else {
                // error
                return;
            }
        CASE VISIBLEGROUPS:
            if ($wiki->wikimode == 'collaborative') {
                // We need to print a select to choose a course group
                $params = array('wid'=>$wiki->id, 'title'=>urlencode($page->title));
                if ($pagetype == 'files') {
                    $params['pageid'] = $page->id;
                }
                $baseurl->params($params);

                echo $this->output->container_start('wiki_right');
                groups_print_activity_menu($cm, $baseurl->out());
                echo $this->output->container_end();
                return;

            } else if ($wiki->wikimode == 'individual') {
                $users = get_enrolled_users($context);
                $options = array();
                foreach ($users as $user) {
                    $groups = groups_get_all_groups($cm->course, $user->id);
                    if (!empty($groups)) {
                        foreach ($groups as $group) {
                            $options[$group->id][$group->name][$group->id . '-' . $user->id] = fullname($user);
                        }
                    } else {
                        $name = get_string('notingroup', 'wiki');
                        $options[0][$name]['0' . '-' . $user->id] = fullname($user);
                    }
                }

                echo $this->output->container_start('wiki_right');
                $params = array('wid' => $wiki->id, 'title' => $page->title);
                if ($pagetype == 'files') {
                    $params['pageid'] = $page->id;
                }
                $baseurl->params($params);
                $name = 'groupanduser';
                $selected = $subwiki->groupid . '-' . $subwiki->userid;
                echo $this->output->single_select($baseurl, $name, $options, $selected);
                echo $this->output->container_end();

                return;

            } else {
                // error
                return;
            }
        default:
            // error
            return;

        }

    }
// Obviously.
require_login($course);
// Make sure the user can manage invitation enrolments for this course.
require_capability("enrol/invitation:manage", context_course::instance($course->id, MUST_EXIST));
// Get the enrolment manager for this course.
$manager = new course_enrolment_manager($PAGE, $course, $filter);
// Get an enrolment users table object. Doign this will automatically retrieve the the URL params
// relating to table the user was viewing before coming here, and allows us to return the user to the
// exact page of the users screen they can from.
$table = new course_enrolment_users_table($manager, $PAGE);
// The URL of the enrolled users page for the course.
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
// The URl to return the user too after this screen.
$returnurl = new moodle_url($usersurl, $manager->get_url_params() + $table->get_url_params());
// The URL of this page.
$url = new moodle_url('/enrol/invitation/editenrolment.php', $returnurl->params());
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if (!$plugin->allow_manage($instance) || $instance->enrol != 'invitation' || !$plugin instanceof enrol_invitation_plugin) {
    print_error('erroreditenrolment', 'enrol');
}
$mform = new enrol_invitation_user_enrolment_form($url, array('user' => $user, 'course' => $course, 'ue' => $ue));
$mform->set_data($PAGE->url->params());
// Check the form hasn't been cancelled.
if ($mform->is_cancelled()) {
    redirect($returnurl);
} else {
    if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) {
        // The forms been submit, validated and the sesskey has been checked ... edit the enrolment.
Example #14
0
    /**
     * Set the action and parameters that can be used to return to the current page.
     *
     * @param string $action The action for the current page
     * @param array $params An array of name value pairs which form the parameters
     *                      to return to the current page.
     * @return void
     */
    public function register_return_link($action, $params) {
        global $PAGE;
        $params['action'] = $action;
        $cm = $this->get_course_module();
        if ($cm) {
            $currenturl = new moodle_url('/mod/assign/view.php', array('id' => $cm->id));
        } else {
            $currenturl = new moodle_url('/mod/assign/index.php', array('id' => $this->get_course()->id));
        }

        $currenturl->params($params);
        $PAGE->set_url($currenturl);
    }
    }
} else {
    if (!($qcreate = get_record("qcreate", "id", $a))) {
        error("Course module is incorrect");
    }
    if (!($course = get_record("course", "id", $qcreate->course))) {
        error("Course is misconfigured");
    }
    if (!($cm = get_coursemodule_from_instance("qcreate", $qcreate->id, $course->id))) {
        error("Course Module ID was incorrect");
    }
}
$qcreate->cmidnumber = $cm->id;
$requireds = get_records('qcreate_required', 'qcreateid', $qcreate->id, 'qtype', 'qtype, no, id');
$thisurl = new moodle_url($CFG->wwwroot . '/mod/qcreate/view.php');
$thisurl->params(array('id' => $cm->id));
$modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
//modedit.php forwards to this page after creating coursemodule record.
//this is the first chance we get to set capabilities in the newly created
//context.
qcreate_student_q_access_sync($qcreate, $modulecontext, $course);
require_login($course->id);
if (has_capability('mod/qcreate:grade', $modulecontext)) {
    redirect($CFG->wwwroot . '/mod/qcreate/edit.php?cmid=' . $cm->id);
}
/// Print the page header
$strqcreates = get_string("modulenameplural", "qcreate");
$strqcreate = get_string("modulename", "qcreate");
$navlinks = array();
$navlinks[] = array('name' => $strqcreates, 'link' => "index.php?id={$course->id}", 'type' => 'activity');
$navlinks[] = array('name' => format_string($qcreate->name), 'link' => '', 'type' => 'activityinstance');
/**
 * Common setup for all pages for editing questions.
 * @param string $baseurl the name of the script calling this funciton. For examle 'qusetion/edit.php'.
 * @param string $edittab code for this edit tab
 * @param bool $requirecmid require cmid? default false
 * @param bool $requirecourseid require courseid, if cmid is not given? default true
 * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars
 */
function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirecourseid = true)
{
    global $DB, $PAGE;
    $thispageurl = new moodle_url($baseurl);
    $thispageurl->remove_all_params();
    // We are going to explicity add back everything important - this avoids unwanted params from being retained.
    if ($requirecmid) {
        $cmid = required_param('cmid', PARAM_INT);
    } else {
        $cmid = optional_param('cmid', 0, PARAM_INT);
    }
    if ($cmid) {
        list($module, $cm) = get_module_from_cmid($cmid);
        $courseid = $cm->course;
        $thispageurl->params(compact('cmid'));
        require_login($courseid, false, $cm);
        $thiscontext = context_module::instance($cmid);
    } else {
        $module = null;
        $cm = null;
        if ($requirecourseid) {
            $courseid = required_param('courseid', PARAM_INT);
        } else {
            $courseid = optional_param('courseid', 0, PARAM_INT);
        }
        if ($courseid) {
            $thispageurl->params(compact('courseid'));
            require_login($courseid, false);
            $thiscontext = context_course::instance($courseid);
        } else {
            $thiscontext = null;
        }
    }
    if ($thiscontext) {
        $contexts = new question_edit_contexts($thiscontext);
        $contexts->require_one_edit_tab_cap($edittab);
    } else {
        $contexts = null;
    }
    $PAGE->set_pagelayout('admin');
    $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT);
    //pass 'cat' from page to page and when 'category' comes from a drop down menu
    //then we also reset the qpage so we go to page 1 of
    //a new cat.
    $pagevars['cat'] = optional_param('cat', 0, PARAM_SEQUENCE);
    // if empty will be set up later
    if ($category = optional_param('category', 0, PARAM_SEQUENCE)) {
        if ($pagevars['cat'] != $category) {
            // is this a move to a new category?
            $pagevars['cat'] = $category;
            $pagevars['qpage'] = 0;
        }
    }
    if ($pagevars['cat']) {
        $thispageurl->param('cat', $pagevars['cat']);
    }
    if (strpos($baseurl, '/question/') === 0) {
        navigation_node::override_active_url($thispageurl);
    }
    if ($pagevars['qpage'] > -1) {
        $thispageurl->param('qpage', $pagevars['qpage']);
    } else {
        $pagevars['qpage'] = 0;
    }
    $pagevars['qperpage'] = question_get_display_preference('qperpage', DEFAULT_QUESTIONS_PER_PAGE, PARAM_INT, $thispageurl);
    for ($i = 1; $i <= question_bank_view::MAX_SORTS; $i++) {
        $param = 'qbs' . $i;
        if (!($sort = optional_param($param, '', PARAM_TEXT))) {
            break;
        }
        $thispageurl->param($param, $sort);
    }
    $defaultcategory = question_make_default_categories($contexts->all());
    $contextlistarr = array();
    foreach ($contexts->having_one_edit_tab_cap($edittab) as $context) {
        $contextlistarr[] = "'{$context->id}'";
    }
    $contextlist = join($contextlistarr, ' ,');
    if (!empty($pagevars['cat'])) {
        $catparts = explode(',', $pagevars['cat']);
        if (!$catparts[0] || false !== array_search($catparts[1], $contextlistarr) || !$DB->count_records_select("question_categories", "id = ? AND contextid = ?", array($catparts[0], $catparts[1]))) {
            print_error('invalidcategory', 'question');
        }
    } else {
        $category = $defaultcategory;
        $pagevars['cat'] = "{$category->id},{$category->contextid}";
    }
    // Display options.
    $pagevars['recurse'] = question_get_display_preference('recurse', 1, PARAM_BOOL, $thispageurl);
    $pagevars['showhidden'] = question_get_display_preference('showhidden', 0, PARAM_BOOL, $thispageurl);
    $pagevars['qbshowtext'] = question_get_display_preference('qbshowtext', 0, PARAM_BOOL, $thispageurl);
    // Category list page.
    $pagevars['cpage'] = optional_param('cpage', 1, PARAM_INT);
    if ($pagevars['cpage'] != 1) {
        $thispageurl->param('cpage', $pagevars['cpage']);
    }
    return array($thispageurl, $contexts, $cmid, $cm, $module, $pagevars);
}
Example #17
0
 /**
  * Outputs all the blog entries aggregated by this blog listing.
  *
  * @return void
  */
 public function print_entries()
 {
     global $CFG, $USER, $DB, $OUTPUT, $PAGE;
     $sitecontext = context_system::instance();
     // Blog renderer.
     $output = $PAGE->get_renderer('blog');
     $page = optional_param('blogpage', 0, PARAM_INT);
     $limit = optional_param('limit', get_user_preferences('blogpagesize', 10), PARAM_INT);
     $start = $page * $limit;
     $morelink = '<br />&nbsp;&nbsp;';
     $entries = $this->get_entries($start, $limit);
     $totalentries = $this->count_entries();
     $pagingbar = new paging_bar($totalentries, $page, $limit, $this->get_baseurl());
     $pagingbar->pagevar = 'blogpage';
     $blogheaders = blog_get_headers();
     echo $OUTPUT->render($pagingbar);
     if (has_capability('moodle/blog:create', $sitecontext)) {
         // The user's blog is enabled and they are viewing their own blog.
         $userid = optional_param('userid', null, PARAM_INT);
         if (empty($userid) || !empty($userid) && $userid == $USER->id) {
             $courseid = optional_param('courseid', null, PARAM_INT);
             $modid = optional_param('modid', null, PARAM_INT);
             $addurl = new moodle_url("{$CFG->wwwroot}/blog/edit.php");
             $urlparams = array('action' => 'add', 'userid' => $userid, 'courseid' => $courseid, 'groupid' => optional_param('groupid', null, PARAM_INT), 'modid' => $modid, 'tagid' => optional_param('tagid', null, PARAM_INT), 'tag' => optional_param('tag', null, PARAM_INT), 'search' => optional_param('search', null, PARAM_INT));
             $urlparams = array_filter($urlparams);
             $addurl->params($urlparams);
             $addlink = '<div class="addbloglink">';
             $addlink .= '<a href="' . $addurl->out() . '">' . $blogheaders['stradd'] . '</a>';
             $addlink .= '</div>';
             echo $addlink;
         }
     }
     if ($entries) {
         $count = 0;
         foreach ($entries as $entry) {
             $blogentry = new blog_entry(null, $entry);
             // Get the required blog entry data to render it.
             $blogentry->prepare_render();
             echo $output->render($blogentry);
             $count++;
         }
         echo $OUTPUT->render($pagingbar);
         if (!$count) {
             print '<br /><div style="text-align:center">' . get_string('noentriesyet', 'blog') . '</div><br />';
         }
         print $morelink . '<br />' . "\n";
         return;
     }
 }
 /**
  * Return the URL for a font
  *
  * @param string $font the name of the font (including extension).
  * @param string $component specification of one plugin like in get_string()
  * @return moodle_url
  */
 public function font_url($font, $component)
 {
     global $CFG;
     $params = array('theme' => $this->name);
     if (empty($component) or $component === 'moodle' or $component === 'core') {
         $params['component'] = 'core';
     } else {
         $params['component'] = $component;
     }
     $rev = theme_get_revision();
     if ($rev != -1) {
         $params['rev'] = $rev;
     }
     $params['font'] = $font;
     $url = new moodle_url("{$CFG->httpswwwroot}/theme/font.php");
     if (!empty($CFG->slasharguments) and $rev > 0) {
         $path = '/' . $params['theme'] . '/' . $params['component'] . '/' . $params['rev'] . '/' . $params['font'];
         $url->set_slashargument($path, 'noparam', true);
     } else {
         $url->params($params);
     }
     return $url;
 }
Example #19
0
         $buttontitle = get_string('switch_item_to_not_required', 'feedback');
         $buttonimg = $OUTPUT->pix_url('required', 'feedback');
     } else {
         $buttontitle = get_string('switch_item_to_required', 'feedback');
         $buttonimg = $OUTPUT->pix_url('notrequired', 'feedback');
     }
     $urlparams = array('switchitemrequired' => $feedbackitem->id);
     $requiredurl = new moodle_url($url, $urlparams);
     $buttonlink = $requiredurl->out();
     echo '<a class="icon ' . 'feedback_switchrequired" ' . 'title="' . $buttontitle . '" ' . 'href="' . $buttonlink . '">' . '<img alt="' . $buttontitle . '" src="' . $buttonimg . '" />' . '</a>';
     echo '</span>';
 }
 //print the delete-button
 echo '<span class="feedback_item_command_toggle">';
 $deleteitemurl = new moodle_url('/mod/feedback/delete_item.php');
 $deleteitemurl->params(array('id' => $id, 'do_show' => $do_show, 'deleteitem' => $feedbackitem->id));
 $buttonlink = $deleteitemurl->out();
 $strbutton = get_string('delete_item', 'feedback');
 $src = $OUTPUT->pix_url('t/delete');
 echo '<a class="icon delete" title="' . $strbutton . '" href="' . $buttonlink . '">
         <img alt="' . $strbutton . '" src="' . $src . '" />
       </a>';
 echo '</span>';
 echo $OUTPUT->box_end();
 if ($feedbackitem->typ != 'pagebreak') {
     feedback_print_item_preview($feedbackitem);
 } else {
     echo $OUTPUT->box_start('feedback_pagebreak');
     echo get_string('pagebreak', 'feedback') . '<hr class="feedback_pagebreak" />';
     echo $OUTPUT->box_end();
 }
Example #20
0
 /**
  * Build the form required to do the pre-flight checks.
  * @param moodle_url $url the form action URL.
  * @param int|null $attemptid the id of the current attempt, if there is one,
  *      otherwise null.
  * @return mod_quiz_preflight_check_form the form.
  */
 public function get_preflight_check_form(moodle_url $url, $attemptid) {
     return new mod_quiz_preflight_check_form($url->out_omit_querystring(),
             array('rules' => $this->rules, 'quizobj' => $this->quizobj,
                   'attemptid' => $attemptid, 'hidden' => $url->params()));
 }
Example #21
0
 /**
  * Recursive function for building the table holding the grade categories and items,
  * with CSS indentation and styles.
  *
  * @param array   $element The current tree element being rendered
  * @param boolean $totals Whether or not to print category grade items (category totals)
  * @param array   $parents An array of parent categories for the current element (used for indentation and row classes)
  *
  * @return string HTML
  */
 public function build_html_tree($element, $totals, $parents, $level, &$row_count)
 {
     global $CFG, $COURSE, $PAGE, $OUTPUT;
     $object = $element['object'];
     $eid = $element['eid'];
     $object->name = $this->gtree->get_element_header($element, true, true, true, true, true);
     $object->stripped_name = $this->gtree->get_element_header($element, false, false, false);
     $is_category_item = false;
     if ($element['type'] == 'categoryitem' || $element['type'] == 'courseitem') {
         $is_category_item = true;
     }
     $rowclasses = array();
     foreach ($parents as $parent_eid) {
         $rowclasses[] = $parent_eid;
     }
     $moveaction = '';
     $actionsmenu = new action_menu();
     $actionsmenu->set_menu_trigger(get_string('edit'));
     $actionsmenu->set_owner_selector('grade-item-' . $eid);
     $actionsmenu->set_alignment(action_menu::TL, action_menu::BL);
     if (!$is_category_item && ($icon = $this->gtree->get_edit_icon($element, $this->gpr, true))) {
         $actionsmenu->add($icon);
     }
     // MDL-49281 if grade_item already has calculation, it should be editable even if global setting is off.
     $type = $element['type'];
     $iscalculated = ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') && $object->is_calculated();
     $icon = $this->gtree->get_calculation_icon($element, $this->gpr, true);
     if ($iscalculated || $this->show_calculations && $icon) {
         $actionsmenu->add($icon);
     }
     if ($element['type'] == 'item' or $element['type'] == 'category' and $element['depth'] > 1) {
         if ($this->element_deletable($element)) {
             $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey()));
             $icon = new action_menu_link_secondary($aurl, new pix_icon('t/delete', get_string('delete')), get_string('delete'));
             $actionsmenu->add($icon);
         }
         $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey()));
         $moveaction .= $OUTPUT->action_icon($aurl, new pix_icon('t/move', get_string('move')));
     }
     if ($icon = $this->gtree->get_hiding_icon($element, $this->gpr, true)) {
         $actionsmenu->add($icon);
     }
     if ($icon = $this->gtree->get_reset_icon($element, $this->gpr, true)) {
         $actionsmenu->add($icon);
     }
     $actions = $OUTPUT->render($actionsmenu);
     $returnrows = array();
     $root = false;
     $id = required_param('id', PARAM_INT);
     /// prepare move target if needed
     $last = '';
     /// print the list items now
     if ($this->moving == $eid) {
         // do not diplay children
         $cell = new html_table_cell();
         $cell->colspan = 12;
         $cell->attributes['class'] = $element['type'] . ' moving column-name level' . ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd');
         $cell->text = $object->name . ' (' . get_string('move') . ')';
         return array(new html_table_row(array($cell)));
     }
     if ($element['type'] == 'category') {
         $level++;
         $this->categories[$object->id] = $object->stripped_name;
         $category = grade_category::fetch(array('id' => $object->id));
         $item = $category->get_grade_item();
         // Add aggregation coef input if not a course item and if parent category has correct aggregation type
         $dimmed = $item->is_hidden() ? 'dimmed_text' : '';
         // Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan)
         $aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
         $category_total_data = null;
         // Used if aggregationposition is set to "last", so we can print it last
         $html_children = array();
         $row_count = 0;
         foreach ($element['children'] as $child_el) {
             $moveto = null;
             if (empty($child_el['object']->itemtype)) {
                 $child_el['object']->itemtype = false;
             }
             if (($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) {
                 continue;
             }
             $child_eid = $child_el['eid'];
             $first = '';
             if ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 $first = array('first' => 1);
                 $child_eid = $eid;
             }
             if ($this->moving && $this->moving != $child_eid) {
                 $strmove = get_string('move');
                 $strmovehere = get_string('movehere');
                 $actions = $moveaction = '';
                 // no action icons when moving
                 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey()));
                 if ($first) {
                     $aurl->params($first);
                 }
                 $cell = new html_table_cell();
                 $cell->colspan = 12;
                 $cell->attributes['class'] = 'movehere level' . ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd');
                 $icon = new pix_icon('movehere', $strmovehere, null, array('class' => 'movetarget'));
                 $cell->text = $OUTPUT->action_icon($aurl, $icon);
                 $moveto = new html_table_row(array($cell));
             }
             $newparents = $parents;
             $newparents[] = $eid;
             $row_count++;
             $child_row_count = 0;
             // If moving, do not print course and category totals, but still print the moveto target box
             if ($this->moving && ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category')) {
                 $html_children[] = $moveto;
             } elseif ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 // We don't build the item yet because we first need to know the deepest level of categories (for category/name colspans)
                 $category_total_item = $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count);
                 if (!$aggregation_position) {
                     $html_children = array_merge($html_children, $category_total_item);
                 }
             } else {
                 $html_children = array_merge($html_children, $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count));
                 if (!empty($moveto)) {
                     $html_children[] = $moveto;
                 }
                 if ($this->moving) {
                     $row_count++;
                 }
             }
             $row_count += $child_row_count;
             // If the child is a category, increment row_count by one more (for the extra coloured row)
             if ($child_el['type'] == 'category') {
                 $row_count++;
             }
         }
         // Print category total at the end if aggregation position is "last" (1)
         if (!empty($category_total_item) && $aggregation_position) {
             $html_children = array_merge($html_children, $category_total_item);
         }
         // Determine if we are at the root
         if (isset($element['object']->grade_item) && $element['object']->grade_item->is_course_item()) {
             $root = true;
         }
         $levelclass = "level{$level} level" . ($level % 2 ? 'odd' : 'even');
         $courseclass = '';
         if ($level == 1) {
             $courseclass = 'coursecategory';
         }
         $row = new html_table_row();
         $row->id = 'grade-item-' . $eid;
         $row->attributes['class'] = $courseclass . ' category ' . $dimmed;
         $row->attributes['data-category'] = $eid;
         $row->attributes['data-itemid'] = $category->get_grade_item()->id;
         foreach ($rowclasses as $class) {
             $row->attributes['class'] .= ' ' . $class;
         }
         $headercell = new html_table_cell();
         $headercell->header = true;
         $headercell->scope = 'row';
         $headercell->attributes['title'] = $object->stripped_name;
         $headercell->attributes['class'] = 'cell column-rowspan rowspan ' . $levelclass;
         $headercell->rowspan = $row_count + 1;
         $row->cells[] = $headercell;
         foreach ($this->columns as $column) {
             if (!($this->moving && $column->hide_when_moving)) {
                 $row->cells[] = $column->get_category_cell($category, $levelclass, ['id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'moveaction' => $moveaction, 'eid' => $eid]);
             }
         }
         $returnrows[] = $row;
         $returnrows = array_merge($returnrows, $html_children);
         // Print a coloured row to show the end of the category across the table
         $endcell = new html_table_cell();
         $endcell->colspan = 19 - $level;
         $endcell->attributes['class'] = 'emptyrow colspan ' . $levelclass;
         $returnrows[] = new html_table_row(array($endcell));
     } else {
         // Dealing with a grade item
         $item = grade_item::fetch(array('id' => $object->id));
         $element['type'] = 'item';
         $element['object'] = $item;
         $categoryitemclass = '';
         if ($item->itemtype == 'category') {
             $categoryitemclass = 'categoryitem';
         }
         if ($item->itemtype == 'course') {
             $categoryitemclass = 'courseitem';
         }
         $dimmed = $item->is_hidden() ? "dimmed_text" : "";
         $gradeitemrow = new html_table_row();
         $gradeitemrow->id = 'grade-item-' . $eid;
         $gradeitemrow->attributes['class'] = $categoryitemclass . ' item ' . $dimmed;
         $gradeitemrow->attributes['data-itemid'] = $object->id;
         foreach ($rowclasses as $class) {
             $gradeitemrow->attributes['class'] .= ' ' . $class;
         }
         foreach ($this->columns as $column) {
             if (!($this->moving && $column->hide_when_moving)) {
                 $gradeitemrow->cells[] = $column->get_item_cell($item, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'element' => $element, 'eid' => $eid, 'moveaction' => $moveaction, 'itemtype' => $object->itemtype));
             }
         }
         $returnrows[] = $gradeitemrow;
     }
     return $returnrows;
 }
Example #22
0
 /**
  * Renders a text with icons to sort by the given column
  *
  * This is intended for table headings.
  *
  * @param string $text    The heading text
  * @param string $sortid  The column id used for sorting
  * @param string $sortby  Currently sorted by (column id)
  * @param string $sorthow Currently sorted how (ASC|DESC)
  *
  * @return string
  */
 protected function helper_sortable_heading($text, $sortid = null, $sortby = null, $sorthow = null)
 {
     global $PAGE;
     $out = html_writer::tag('span', $text, array('class' => 'text'));
     if (!is_null($sortid)) {
         if ($sortby !== $sortid or $sorthow !== 'ASC') {
             $url = new moodle_url($PAGE->url);
             $url->params(array('sortby' => $sortid, 'sorthow' => 'ASC'));
             $out .= $this->output->action_icon($url, new pix_icon('t/up', get_string('sortasc', 'workshop')), null, array('class' => 'sort asc'));
         }
         if ($sortby !== $sortid or $sorthow !== 'DESC') {
             $url = new moodle_url($PAGE->url);
             $url->params(array('sortby' => $sortid, 'sorthow' => 'DESC'));
             $out .= $this->output->action_icon($url, new pix_icon('t/down', get_string('sortdesc', 'workshop')), null, array('class' => 'sort desc'));
         }
     }
     return $out;
 }
 /**
  * Displays the import course selector
  *
  * @param moodle_url $nextstageurl
  * @param import_course_search $courses
  * @return string
  */
 public function import_course_selector(moodle_url $nextstageurl, import_course_search $courses = null)
 {
     $html = html_writer::start_tag('div', array('class' => 'import-course-selector backup-restore'));
     $html .= html_writer::start_tag('form', array('method' => 'post', 'action' => $nextstageurl->out_omit_querystring()));
     foreach ($nextstageurl->params() as $key => $value) {
         $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value));
     }
     // We only allow import adding for now. Enforce it here.
     $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'target', 'value' => backup::TARGET_CURRENT_ADDING));
     $html .= html_writer::start_tag('div', array('class' => 'ics-existing-course backup-section'));
     $html .= $this->output->heading(get_string('importdatafrom'), 2, array('class' => 'header'));
     $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
     $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('continue'))));
     $html .= html_writer::end_tag('div');
     $html .= html_writer::end_tag('form');
     $html .= html_writer::end_tag('div');
     return $html;
 }
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package questionbank
 */
// Includes.
require_once dirname(__FILE__) . '/../config.php';
require_once dirname(__FILE__) . '/editlib.php';
require_once $CFG->dirroot . '/question/contextmoveq_form.php';
$ids = required_param('ids', PARAM_SEQUENCE);
// question ids
if (!($cmid = optional_param('cmid', 0, PARAM_INT))) {
    $courseid = required_param('courseid', PARAM_INT);
}
$tocatid = required_param('tocatid', PARAM_INT);
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
$thispageurl = new moodle_url();
$thispageurl->params(compact('tocatid', 'ids', 'returnurl'));
if ($cmid) {
    list($module, $cm) = get_module_from_cmid($cmid);
    require_login($cm->course, false, $cm);
    $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid);
    if (!$returnurl) {
        $returnurl = "{$CFG->wwwroot}/question/edit.php?cmid={$cm->id}";
    }
    $thispageurl->param('cmid', $cmid);
} elseif ($courseid) {
    require_login($courseid, false);
    $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid);
    $module = null;
    $cm = null;
    if (!$returnurl) {
        $returnurl = "{$CFG->wwwroot}/question/edit.php?courseid={$COURSE->id}";
Example #25
0
 /**
  * Outputs all the blog entries aggregated by this blog listing.
  *
  * @return void
  */
 public function print_entries()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     $sitecontext = get_context_instance(CONTEXT_SYSTEM);
     $page = optional_param('blogpage', 0, PARAM_INT);
     $limit = optional_param('limit', get_user_preferences('blogpagesize', 10), PARAM_INT);
     $start = $page * $limit;
     $morelink = '<br />&nbsp;&nbsp;';
     if ($sqlarray = $this->get_entry_fetch_sql(true)) {
         $totalentries = $DB->count_records_sql($sqlarray['sql'], $sqlarray['params']);
     } else {
         $totalentries = 0;
     }
     $entries = $this->get_entries($start, $limit);
     $pagingbar = new paging_bar($totalentries, $page, $limit, $this->get_baseurl());
     $pagingbar->pagevar = 'blogpage';
     $blogheaders = blog_get_headers();
     echo $OUTPUT->render($pagingbar);
     if (has_capability('moodle/blog:create', $sitecontext)) {
         //the user's blog is enabled and they are viewing their own blog
         $userid = optional_param('userid', null, PARAM_INT);
         if (empty($userid) || !empty($userid) && $userid == $USER->id) {
             $addurl = new moodle_url("{$CFG->wwwroot}/blog/edit.php");
             $urlparams = array('action' => 'add', 'userid' => $userid, 'courseid' => optional_param('courseid', null, PARAM_INT), 'groupid' => optional_param('groupid', null, PARAM_INT), 'modid' => optional_param('modid', null, PARAM_INT), 'tagid' => optional_param('tagid', null, PARAM_INT), 'tag' => optional_param('tag', null, PARAM_INT), 'search' => optional_param('search', null, PARAM_INT));
             foreach ($urlparams as $var => $val) {
                 if (empty($val)) {
                     unset($urlparams[$var]);
                 }
             }
             $addurl->params($urlparams);
             $addlink = '<div class="addbloglink">';
             $addlink .= '<a href="' . $addurl->out() . '">' . $blogheaders['stradd'] . '</a>';
             $addlink .= '</div>';
             echo $addlink;
         }
     }
     if ($entries) {
         $count = 0;
         foreach ($entries as $entry) {
             $blogentry = new blog_entry(null, $entry);
             $blogentry->print_html();
             $count++;
         }
         echo $OUTPUT->render($pagingbar);
         if (!$count) {
             print '<br /><div style="text-align:center">' . get_string('noentriesyet', 'blog') . '</div><br />';
         }
         print $morelink . '<br />' . "\n";
         return;
     }
 }
 function definition()
 {
     global $CFG, $USER, $DB, $COURSE, $OUTPUT;
     $mform =& $this->_form;
     // Don't forget the underscore!
     //add_enrolled_users($this->context);
     $mform->addElement('header', 'general', get_string('manageworkers', 'block_timetracker'));
     $mform->addHelpButton('general', 'manageworkers', 'block_timetracker');
     $stractive = get_string('active', 'block_timetracker');
     $strfirstname = get_string('firstname', 'block_timetracker');
     $strlastname = get_string('lastname', 'block_timetracker');
     $stremail = get_string('email', 'block_timetracker');
     $me = new moodle_url(qualified_me());
     $me->params(array('reload' => true));
     $canview = false;
     if (has_capability('block/timetracker:viewonly', $this->context)) {
         $canview = true;
     }
     $canmanage = false;
     if (has_capability('block/timetracker:manageworkers', $this->context)) {
         $canmanage = true;
     }
     if ($canmanage) {
         $reloadaction = $OUTPUT->action_icon($me, new pix_icon('refresh', 'Refresh worker list', 'block_timetracker'));
         $mform->addElement('html', $reloadaction . ' ' . $OUTPUT->action_link($me, 'Refresh worker list'));
     }
     $mform->addElement('html', '<table align="center" border="1" cellspacing="10px" ' . 'cellpadding="5px" width="75%">');
     $mform->addElement('html', '<tr>
             <td style="font-weight: bold">' . $stractive . '</td>
             <td style="font-weight: bold">Worker name</td>
             <td style="font-weight: bold">' . $stremail . '</td>
             <td style="font-weight: bold; text-align: center">' . get_string('action') . '</td>
          </tr>');
     if (!($workers = $DB->get_records('block_timetracker_workerinfo', array('courseid' => $COURSE->id), 'lastname ASC, firstname ASC'))) {
         $mform->addElement('html', '<tr><td colspan="4" style="text-align: center">No workers registered' . '</td></tr></table>');
     } else {
         $canactivate = false;
         if (has_capability('block/timetracker:activateworkers', $this->context)) {
             $canactivate = true;
         }
         foreach ($workers as $worker) {
             $mform->addElement('html', '<tr><td>');
             if ($worker->active) {
                 if ($canactivate) {
                     $mform->addElement('advcheckbox', 'activeid[' . $worker->id . ']', '', null, array('checked="checked"', 'group' => 1));
                 } else {
                     $mform->addElement('advcheckbox', 'activeid[' . $worker->id . ']', '', null, array('checked="checked"', 'disabled="disabled"', 'group' => 1));
                 }
             } else {
                 if ($canactivate) {
                     $mform->addElement('advcheckbox', 'activeid[' . $worker->id . ']', '', null, array('group' => 1));
                 } else {
                     $mform->addElement('advcheckbox', 'activeid[' . $worker->id . ']', '', null, array('disabled="disabled"', 'group' => 1));
                 }
             }
             $row = '</td>';
             $row .= '<td>' . $worker->lastname . ', ' . $worker->firstname . '</td>';
             $row .= '<td>' . $worker->email . '</td>';
             $baseurl = $CFG->wwwroot . '/blocks/timetracker';
             $urlparams['id'] = $COURSE->id;
             $urlparams['userid'] = $worker->id;
             $urlparams['sesskey'] = sesskey();
             $deleteurl = new moodle_url($baseurl . '/deleteworker.php', $urlparams);
             $deleteicon = new pix_icon('user_delete', get_string('delete'), 'block_timetracker');
             $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action('Are you sure you want to delete this worker and all this worker\'s' . ' work units?'));
             //don't need anymore
             unset($urlparams['sesskey']);
             $editurl = new moodle_url($baseurl . '/updateworkerinfo.php', $urlparams);
             $editaction = $OUTPUT->action_icon($editurl, new pix_icon('user_edit', get_string('edit'), 'block_timetracker'));
             $reportsurl = new moodle_url($baseurl . '/reports.php', $urlparams);
             $reportsaction = $OUTPUT->action_icon($reportsurl, new pix_icon('report', 'Reports', 'block_timetracker'));
             $adduniturl = new moodle_url($baseurl . '/addunit.php', $urlparams);
             $addunitaction = $OUTPUT->action_icon($adduniturl, new pix_icon('clock_add', get_string('addentry', 'block_timetracker'), 'block_timetracker'));
             $timesheetsurl = new moodle_url($baseurl . '/viewtimesheets.php', $urlparams);
             $timesheetaction = $OUTPUT->action_icon($timesheetsurl, new pix_icon('date', 'View signed timesheets', 'block_timetracker'));
             $row .= '<td style="text-align: center">';
             if ($canmanage) {
                 $row .= $editaction . ' ' . $addunitaction . ' ' . $reportsaction . $timesheetaction;
             } else {
                 $row .= $editaction . ' ' . $reportsaction . ' ' . $timesheetaction;
                 //$row .= '&nbsp;';
             }
             $row .= '</td>';
             $row .= '</tr>';
             $mform->addElement('html', $row);
             $mform->addElement('hidden', 'workerid[' . $worker->id . ']', $worker->id);
         }
         if ($canactivate) {
             $this->add_checkbox_controller(1, null, null, 1);
         }
         $mform->addElement('html', '</table>');
         $mform->addElement('hidden', 'id', $COURSE->id);
         if ($canmanage) {
             $this->add_action_buttons(false, 'Save Activation Changes');
         }
     }
 }
Example #27
0
 /**
  * Returns hidden input fields created from url parameters.
  *
  * @param moodle_url $url
  * @param array $exclude list of excluded parameters
  * @return string HTML fragment
  */
 public static function input_hidden_params(moodle_url $url, array $exclude = null)
 {
     $exclude = (array) $exclude;
     $params = $url->params();
     foreach ($exclude as $key) {
         unset($params[$key]);
     }
     $output = '';
     foreach ($params as $key => $value) {
         $attributes = array('type' => 'hidden', 'name' => $key, 'value' => $value);
         $output .= self::empty_tag('input', $attributes) . "\n";
     }
     return $output;
 }
Example #28
0
 /**
  * Compares this moodle_url with another
  * See documentation of constants for an explanation of the comparison flags.
  * @param moodle_url $url The moodle_url object to compare
  * @param int $matchtype The type of comparison (URL_MATCH_BASE, URL_MATCH_PARAMS, URL_MATCH_EXACT)
  * @return boolean
  */
 public function compare(moodle_url $url, $matchtype = URL_MATCH_EXACT)
 {
     $baseself = $this->out_omit_querystring();
     $baseother = $url->out_omit_querystring();
     // Append index.php if there is no specific file
     if (substr($baseself, -1) == '/') {
         $baseself .= 'index.php';
     }
     if (substr($baseother, -1) == '/') {
         $baseother .= 'index.php';
     }
     // Compare the two base URLs
     if ($baseself != $baseother) {
         return false;
     }
     if ($matchtype == URL_MATCH_BASE) {
         return true;
     }
     $urlparams = $url->params();
     foreach ($this->params() as $param => $value) {
         if ($param == 'sesskey') {
             continue;
         }
         if (!array_key_exists($param, $urlparams) || $urlparams[$param] != $value) {
             return false;
         }
     }
     if ($matchtype == URL_MATCH_PARAMS) {
         return true;
     }
     foreach ($urlparams as $param => $value) {
         if ($param == 'sesskey') {
             continue;
         }
         if (!array_key_exists($param, $this->params()) || $this->param($param) != $value) {
             return false;
         }
     }
     return true;
 }
$params = array('enrolid' => $ue->enrolid);
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
context_instance_preload($course);
if ($course->id == SITEID) {
    redirect(new moodle_url('/'));
}
require_login($course);
require_capability("enrol/globalclassroom:unenrol", get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST));
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
// The URL of the enrolled users page for the course.
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
// The URl to return the user too after this screen.
$returnurl = new moodle_url($usersurl, $manager->get_url_params() + $table->get_url_params());
// The URL of this page
$url = new moodle_url('/enrol/globalclassroom/unenroluser.php', $returnurl->params());
$url->param('ue', $ueid);
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'globalclassroom' || !$plugin instanceof enrol_globalclassroom_plugin) {
    print_error('erroreditenrolment', 'enrol');
}
// If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) {
    redirect($returnurl);
}
$yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unenroluser', 'enrol_globalclassroom', array('user' => fullname($user, true), 'course' => format_string($course->fullname)));
$fullname = fullname($user);
 function get_content()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     require_once $CFG->dirroot . '/mod/elluminate/lib.php';
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (!isloggedin() || empty($this->instance)) {
         return $this->content;
     }
     if ($recordings = elluminate_recent_recordings()) {
         $this->content->items[] = '<b>' . get_string('recentrecordings', 'block_elluminate') . ':</b>';
         $this->content->icons[] = '';
         $baseurl = new moodle_url('/mod/elluminate/view.php');
         foreach ($recordings as $recording) {
             $elluminate = $DB->get_record('elluminate', array('meetingid' => $recording->meetingid));
             $url = new moodle_url($baseurl);
             $url->params(array('a' => $elluminate->id, 'group' => $elluminate->groupid));
             $icon = '<img src="' . $OUTPUT->pix_url('icon', 'feedback') . '" class="icon" alt="" />&nbsp;';
             $this->content->text = ' <a href="' . $url->out() . '">' . $recording->name . '</a>';
         }
     }
     return $this->content;
 }