Merge branch 'w24_MDL-33670_m21_ofadmin' of git://github.com/skodak/moodle into MOODL...
[moodle.git] / cohort / index.php
blob157b65a176f4dce5bb125ad7e1e6539faa058e5a
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Cohort related management functions, this file needs to be included manually.
21 * @package core
22 * @subpackage cohort
23 * @copyright 2010 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require('../config.php');
28 require_once($CFG->libdir.'/adminlib.php');
30 $contextid = optional_param('contextid', 0, PARAM_INT);
32 require_login();
34 if ($contextid) {
35 $context = get_context_instance_by_id($contextid, MUST_EXIST);
36 } else {
37 $context = get_context_instance(CONTEXT_SYSTEM);
40 if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
41 print_error('invalidcontext');
44 $category = null;
45 if ($context->contextlevel == CONTEXT_COURSECAT) {
46 $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
49 $manager = has_capability('moodle/cohort:manage', $context);
50 $canassign = has_capability('moodle/cohort:assign', $context);
51 if (!$manager) {
52 require_capability('moodle/cohort:view', $context);
55 $strcohorts = get_string('cohorts', 'cohort');
57 if ($category) {
58 $PAGE->set_pagelayout('report');
59 $PAGE->set_context($context);
60 $PAGE->set_url('/cohort/index.php', array('contextid'=>$context->id));
61 $PAGE->set_title($strcohorts);
62 $PAGE->set_heading($COURSE->fullname);
63 $PAGE->navbar->add($category->name, new moodle_url('/course/index.php', array('categoryedit'=>'1')));
64 $PAGE->navbar->add($strcohorts);
65 } else {
66 admin_externalpage_setup('cohorts', '', null, '', array('pagelayout'=>'report'));
69 echo $OUTPUT->header();
71 echo $OUTPUT->heading(get_string('cohortsin', 'cohort', print_context_name($context)));
73 $cohorts = $DB->get_records('cohort', array('contextid'=>$context->id));
75 $data = array();
76 foreach($cohorts as $cohort) {
77 $line = array();
78 $line[] = format_string($cohort->name);
79 $line[] = s($cohort->idnumber); // plain text
80 $line[] = format_text($cohort->description, $cohort->descriptionformat);
82 $line[] = $DB->count_records('cohort_members', array('cohortid'=>$cohort->id));
84 if (empty($cohort->component)) {
85 $line[] = get_string('nocomponent', 'cohort');
86 } else {
87 $line[] = get_string('pluginname', $cohort->component);
90 $buttons = array();
91 if (empty($cohort->component)) {
92 if ($manager) {
93 $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id, 'delete'=>1)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>get_string('delete'), 'class'=>'iconsmall')));
94 $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/edit'), 'alt'=>get_string('edit'), 'class'=>'iconsmall')));
96 if ($manager or $canassign) {
97 $buttons[] = html_writer::link(new moodle_url('/cohort/assign.php', array('id'=>$cohort->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/users'), 'alt'=>get_string('assign', 'core_cohort'), 'class'=>'iconsmall')));
100 $line[] = implode(' ', $buttons);
102 $data[] = $line;
104 $table = new html_table();
105 $table->head = array(get_string('name', 'cohort'), get_string('idnumber', 'cohort'), get_string('description', 'cohort'),
106 get_string('memberscount', 'cohort'), get_string('component', 'cohort'), get_string('edit'));
107 $table->size = array('20%', '10%', '40%', '10%', '10%', '10%');
108 $table->align = array('left', 'left', 'left', 'left','center', 'center');
109 $table->width = '80%';
110 $table->data = $data;
111 echo html_writer::table($table);
113 if ($manager) {
114 echo $OUTPUT->single_button(new moodle_url('/cohort/edit.php', array('contextid'=>$context->id)), get_string('add'));
117 echo $OUTPUT->footer();