removed all calls to feedback_load_capabilities()

This commit is contained in:
Andreas Grabs 2010-04-02 11:34:28 +00:00
parent 2ecf267ccb
commit c987dbad0e
23 changed files with 176 additions and 149 deletions

View File

@ -37,7 +37,9 @@ if ($id) {
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
if($course->id == SITEID) {
require_login($course->id, true);
@ -55,7 +57,9 @@ if($courseid AND $courseid != SITEID) {
}
}
if( !( ((intval($feedback->publish_stats) == 1) AND $capabilities->viewanalysepage) || $capabilities->viewreports)) {
if( !( ((intval($feedback->publish_stats) == 1) AND
has_capability('mod/feedback:viewanalysepage', $context)) OR
has_capability('mod/feedback:viewreports', $context))) {
print_error('error');
}
@ -78,7 +82,7 @@ echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
$groupselect = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/feedback/analysis.php?id=' . $cm->id.'&do_show=analysis', true);
$mygroupid = groups_get_activity_group($cm);
if( $capabilities->viewreports ) {
if( has_capability('mod/feedback:viewreports', $context) ) {
echo isset($groupselect) ? $groupselect : '';
echo '<div class="clearer"></div>';

View File

@ -57,11 +57,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if( !( (intval($feedback->publish_stats) == 1) || $capabilities->viewreports)) {
if( !( (intval($feedback->publish_stats) == 1) OR has_capability('mod/feedback:viewreports', $context))) {
print_error('error');
}
@ -81,7 +84,7 @@ include('tabs.php');
//print the analysed items
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
if( $capabilities->viewreports ) {
if( has_capability('mod/feedback:viewreports', $context) ) {
//button "export to excel"
echo $OUTPUT->container_start('mdl-align');
$aurl = new moodle_url('analysis_to_excel.php', array('sesskey'=>sesskey(), 'id'=>$id, 'coursefilter'=>$coursefilter));

View File

@ -39,11 +39,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->viewreports){
if(!has_capability('mod/feedback:viewreports', $context)){
print_error('error');
}

View File

@ -72,13 +72,20 @@ if ($id) {
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
$feedback_complete_cap = false;
if(has_capability('mod/feedback:complete', $context)) {
$feedback_complete_cap = true;
}
if(isset($CFG->feedback_allowfullanonymous)
AND $CFG->feedback_allowfullanonymous
AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
$capabilities->complete = true;
$feedback_complete_cap = true;
}
//check whether the feedback is located and! started from the mainsite
@ -87,7 +94,7 @@ if($course->id == SITEID AND !$courseid) {
}
//check whether the feedback is mapped to the given courseid
if($course->id == SITEID AND !$capabilities->edititems) {
if($course->id == SITEID AND !has_capability('mod/feedback:edititems', $context)) {
if($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
if(!$DB->get_record('feedback_sitecourse_map', array('feedbackid'=>$feedback->id, 'courseid'=>$courseid))){
print_error('notavailable', 'feedback');
@ -119,7 +126,7 @@ if($courseid AND $courseid != SITEID) {
}
}
if(!$capabilities->complete) {
if(!$feedback_complete_cap) {
print_error('error');
}
@ -134,13 +141,17 @@ echo $OUTPUT->header();
//ishidden check.
//feedback in courses
if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $course->id != SITEID) {
if ((empty($cm->visible) AND
!has_capability('moodle/course:viewhiddenactivities', $context)) AND
$course->id != SITEID) {
notice(get_string("activityiscurrentlyhidden"));
}
//ishidden check.
//feedback on mainsite
if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $courseid == SITEID) {
if ((empty($cm->visible) AND
!has_capability('moodle/course:viewhiddenactivities', $context)) AND
$courseid == SITEID) {
notice(get_string("activityiscurrentlyhidden"));
}
@ -284,7 +295,9 @@ if($feedback_can_submit) {
}
echo $OUTPUT->heading(format_text($feedback->name));
if( (intval($feedback->publish_stats) == 1) AND ( $capabilities->viewanalysepage) AND !( $capabilities->viewreports) ) {
if( (intval($feedback->publish_stats) == 1) AND
( has_capability('mod/feedback:viewanalysepage', $context)) AND
!( has_capability('mod/feedback:viewreports', $context)) ) {
if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
echo get_string('completed_feedbacks', 'feedback').'</a>';

View File

@ -93,13 +93,21 @@ if ($id) {
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
$feedback_complete_cap = false;
if(has_capability('mod/feedback:complete', $context)) {
$feedback_complete_cap = true;
}
//check whether the feedback is anonymous
if(isset($CFG->feedback_allowfullanonymous)
AND $CFG->feedback_allowfullanonymous
AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
$capabilities->complete = true;
$feedback_complete_cap = true;
}
if($feedback->anonymous != FEEDBACK_ANONYMOUS_YES) {
print_error('feedback_is_not_for_anonymous', 'feedback');
@ -121,7 +129,7 @@ if($courseid AND $courseid != SITEID) {
$course = $DB->get_record("course", array("id"=>$cm->course)); // the workaround
}
if(!$capabilities->complete) {
if(!$feedback_complete_cap) {
print_error('error');
}
@ -137,7 +145,9 @@ $PAGE->set_title(format_string($feedback->name));
echo $OUTPUT->header();
//ishidden check. hidden feedbacks except feedbacks on mainsite are only accessible with related capabilities
if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $course->id != SITEID) {
if ((empty($cm->visible) AND
!has_capability('moodle/course:viewhiddenactivities', $context)) AND
$course->id != SITEID) {
notice(get_string("activityiscurrentlyhidden"));
}
@ -253,7 +263,9 @@ if($feedback_can_submit) {
}
echo $OUTPUT->heading(format_text($feedback->name));
if( (intval($feedback->publish_stats) == 1) AND ( $capabilities->viewanalysepage) AND !( $capabilities->viewreports) ) {
if( (intval($feedback->publish_stats) == 1) AND
( has_capability('mod/feedback:viewanalysepage', $context)) AND
!( has_capability('mod/feedback:viewreports', $context)) ) {
echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
echo get_string('completed_feedbacks', 'feedback').'</a>';
echo '</div>';

View File

@ -34,11 +34,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->deletesubmissions){
if(!has_capability('mod/feedback:deletesubmissions', $context)){
print_error('error');
}

View File

@ -29,11 +29,14 @@
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->edititems){
if(!has_capability('mod/feedback:edititems', $context)){
print_error('error');
}

View File

@ -55,11 +55,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->deletetemplate){
if(!has_capability('mod/feedback:deletetemplate', $context)){
print_error('error');
}

View File

@ -45,11 +45,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->edititems){
if(!has_capability('mod/feedback:edititems', $context)){
print_error('error');
}
@ -86,20 +89,21 @@ if($switchitemrequired) {
//the create_template-form
$create_template_form = new feedback_edit_create_template_form();
$create_template_form->set_feedbackdata(array('capabilities' => $capabilities));
$create_template_form->set_feedbackdata(array('context' => $context));
$create_template_form->set_form_elements();
$create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates'));
$create_template_formdata = $create_template_form->get_data();
if(isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) {
//check the capabilities to create templates
if(!$capabilities->createprivatetemplate AND !$capabilities->createpublictemplate) {
if(!has_capability('mod/feedback:createprivatetemplate', $context) AND
!has_capability('mod/feedback:createpublictemplate', $context)) {
print_error('cannotsavetempl', 'feedback');
}
if(trim($create_template_formdata->templatename) == '')
{
$savereturn = 'notsaved_name';
}else {
if($capabilities->createpublictemplate) {
if(has_capability('mod/feedback:createpublictemplate', $context)) {
$create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
}else {
$create_template_formdata->ispublic = 0;
@ -186,7 +190,8 @@ if($do_show == 'templates') {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
$use_template_form->display();
if($capabilities->createprivatetemplate OR $capabilities->createpublictemplate) {
if(has_capability('mod/feedback:createprivatetemplate', $context) OR
has_capability('mod/feedback:createpublictemplate', $context)) {
$deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
$create_template_form->display();
echo '<p><a href="'.$deleteurl->out().'">'.get_string('delete_templates', 'feedback').'</a></p>';
@ -194,7 +199,7 @@ if($do_show == 'templates') {
echo '&nbsp;';
}
if($capabilities->edititems) {
if(has_capability('mod/feedback:edititems', $context)) {
$exporturl = new moodle_url('/mod/feedback/export.php', array('action'=>'exportfile', 'id'=>$id));
$importurl = new moodle_url('/mod/feedback/import.php', array('id'=>$id));
echo '<p>

View File

@ -111,7 +111,7 @@ class feedback_edit_create_template_form extends moodleform {
function set_form_elements(){
$mform =& $this->_form;
$capabilities = $this->feedbackdata->capabilities;
// $capabilities = $this->feedbackdata->capabilities;
// hidden elements
$mform->addElement('hidden', 'id');
@ -129,7 +129,7 @@ class feedback_edit_create_template_form extends moodleform {
$elementgroup[] =& $mform->createElement('static', 'templatenamelabel', get_string('name', 'feedback'));
$elementgroup[] =& $mform->createElement('text', 'templatename', get_string('name', 'feedback'), array('size'=>'40', 'maxlength'=>'200'));
if($capabilities->createpublictemplate) {
if(has_capability('mod/feedback:createpublictemplate', $this->feedbackdata->context)) {
$elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback'));
}

View File

@ -51,11 +51,14 @@ if ($cmid) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->edititems){
if(!has_capability('mod/feedback:edititems', $context)){
print_error('error');
}

View File

@ -34,11 +34,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->edititems){
if(!has_capability('mod/feedback:edititems', $context)){
print_error('invalidaction');
}

View File

@ -42,11 +42,14 @@
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->edititems){
if(!has_capability('mod/feedback:edititems', $context)){
print_error('invalidaction');
}

View File

@ -20,7 +20,10 @@ $PAGE->set_url($url);
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}
$capabilities = feedback_load_course_capabilities($course->id);
if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
print_error('badcontext');
}
require_login($course->id);
$PAGE->set_pagelayout('incourse');
@ -54,7 +57,7 @@ $strresponses = get_string('responses', 'feedback');
$table = new html_table();
if ($course->format == "weeks") {
if($capabilities->viewreports) {
if(has_capability('mod/feedback:viewreports', $context)) {
$table->head = array ($strweek, $strname, $strresponses);
$table->align = array ("center", "left", 'center');
}else{
@ -62,7 +65,7 @@ if ($course->format == "weeks") {
$table->align = array ("center", "left");
}
} else if ($course->format == "topics") {
if($capabilities->viewreports) {
if(has_capability('mod/feedback:viewreports', $context)) {
$table->head = array ($strtopic, $strname, $strresponses);
$table->align = array ("center", "left", "center");
}else{
@ -70,7 +73,7 @@ if ($course->format == "weeks") {
$table->align = array ("center", "left");
}
} else {
if($capabilities->viewreports) {
if(has_capability('mod/feedback:viewreports', $context)) {
$table->head = array ($strname, $strresponses);
$table->align = array ("left", "center");
}else{
@ -84,7 +87,7 @@ foreach ($feedbacks as $feedback) {
//get the responses of each feedback
$viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$feedback->coursemodule));
if($capabilities->viewreports) {
if(has_capability('mod/feedback:viewreports', $context)) {
$completedFeedbackCount = intval(feedback_get_completeds_group_count($feedback));
}
@ -96,7 +99,7 @@ foreach ($feedbacks as $feedback) {
} else {
$tabledata = array ($link);
}
if($capabilities->viewreports) {
if(has_capability('mod/feedback:viewreports', $context)) {
$tabledata[] = $completedFeedbackCount;
}

View File

@ -612,73 +612,6 @@ function feedback_get_context($cmid) {
return $context;
}
/**
* get the capabilities for the feedback
*
* @staticvar object $cb
* @param int $cmid
* @return object the available capabilities from current user
*/
function feedback_load_capabilities($cmid) {
static $cb;
if(isset($cb)) return $cb;
$context = feedback_get_context($cmid);
$cb = new object;
$cb->view = has_capability('mod/feedback:view', $context, NULL, false);
$cb->complete = has_capability('mod/feedback:complete', $context, NULL, false);
$cb->viewanalysepage = has_capability('mod/feedback:viewanalysepage', $context, NULL, false);
$cb->deletesubmissions = has_capability('mod/feedback:deletesubmissions', $context, NULL, false);
$cb->mapcourse = has_capability('mod/feedback:mapcourse', $context, NULL, false);
$cb->edititems = has_capability('mod/feedback:edititems', $context, NULL, false);
$cb->viewreports = has_capability('mod/feedback:viewreports', $context, NULL, false);
$cb->receivemail = has_capability('mod/feedback:receivemail', $context, NULL, false);
$cb->createprivatetemplate = has_capability('mod/feedback:createprivatetemplate', $context, NULL, false);
$cb->createpublictemplate = has_capability('mod/feedback:createpublictemplate', $context, NULL, false);
$cb->deletetemplate = has_capability('mod/feedback:deletetemplate', $context, NULL, false);
$cb->viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context, NULL, false);
return $cb;
}
/**
* get the capabilities for the course.
* this is used by feedback/index.php
*
* @staticvar object $ccb
* @param int $courseid
* @return object the available capabilities from current user
*/
function feedback_load_course_capabilities($courseid) {
static $ccb;
if(isset($ccb)) return $ccb;
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$ccb = new object;
$ccb->view = has_capability('mod/feedback:view', $context, NULL, false);
$ccb->complete = has_capability('mod/feedback:complete', $context, NULL, false);
$ccb->viewanalysepage = has_capability('mod/feedback:viewanalysepage', $context, NULL, false);
$ccb->deletesubmissions = has_capability('mod/feedback:deletesubmissions', $context, NULL, false);
$ccb->mapcourse = has_capability('mod/feedback:mapcourse', $context, NULL, false);
$ccb->edititems = has_capability('mod/feedback:edititems', $context, NULL, false);
$ccb->viewreports = has_capability('mod/feedback:viewreports', $context, NULL, false);
$ccb->receivemail = has_capability('mod/feedback:receivemail', $context, NULL, false);
$ccb->createprivatetemplate = has_capability('mod/feedback:createprivatetemplate', $context, NULL, false);
$ccb->createpublictemplate = has_capability('mod/feedback:createpublictemplate', $context, NULL, false);
$ccb->deletetemplate = has_capability('mod/feedback:deletetemplate', $context, NULL, false);
$ccb->viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context, NULL, false);
return $ccb;
}
/**
* returns true if the current role is faked by switching role feature
*
@ -2337,9 +2270,14 @@ function feedback_encode_target_url($url) {
function feedback_extend_settings_navigation(settings_navigation $settings, navigation_node $feedbacknode) {
global $PAGE, $DB;
$capabilities = feedback_load_capabilities($PAGE->cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id)) {
print_error('badcontext');
}
if($capabilities->edititems) {
// $capabilities = feedback_load_capabilities($PAGE->cm->id);
// if($capabilities->edititems) {
if(has_capability('mod/feedback:edititems', $context)) {
$qkey = $feedbacknode->add(get_string('questions', 'feedback'));
$feedbacknode->get($qkey)->add(get_string('edit_items', 'feedback'), new moodle_url('/mod/feedback/edit.php', array('id'=>$PAGE->cm->id, 'do_show'=>'edit')));
$feedbacknode->get($qkey)->add(get_string('export_questions', 'feedback'), new moodle_url('/mod/feedback/export.php', array('id'=>$PAGE->cm->id, 'action'=>'exportfile')));
@ -2347,19 +2285,18 @@ function feedback_extend_settings_navigation(settings_navigation $settings, navi
$feedbacknode->get($qkey)->add(get_string('templates', 'feedback'), new moodle_url('/mod/feedback/edit.php', array('id'=>$PAGE->cm->id, 'do_show'=>'templates')));
}
if($capabilities->viewreports) {
// if($capabilities->viewreports) {
if(has_capability('mod/feedback:viewreports', $context)) {
$feedback = $DB->get_record('feedback', array('id'=>$PAGE->cm->instance));
if($feedback->course == SITEID){
$feedbacknode->add(get_string('analysis', 'feedback'), new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$PAGE->cm->id, 'course'=>$PAGE->course->id,'do_show'=>'analysis')));
}else {
$feedbacknode->add(get_string('analysis', 'feedback'), new moodle_url('/mod/feedback/analysis.php', array('id'=>$PAGE->cm->id, 'course'=>$PAGE->course->id,'do_show'=>'analysis')));
}
}
if($capabilities->viewreports) {
$feedbacknode->add(get_string('show_entries', 'feedback'), new moodle_url('/mod/feedback/show_entries.php', array('id'=>$PAGE->cm->id, 'do_show'=>'showentries')));
}
}
}
function feedback_init_feedback_session() {
//initialize the feedback-Session - not nice at all!!

View File

@ -49,11 +49,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if (!$capabilities->mapcourse) {
if (!has_capability('mod/feedback:mapcourse', $context)) {
print_error('invalidaccess');
}

View File

@ -30,11 +30,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->edititems){
if(!has_capability('mod/feedback:edititems', $context)){
print_error('error');
}

View File

@ -44,7 +44,9 @@ $url = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$cm->id, 'do
$PAGE->set_url($url);
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
@ -52,7 +54,7 @@ if(($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey');
}
if(!$capabilities->viewreports){
if(!has_capability('mod/feedback:viewreports', $context)){
print_error('error');
}
@ -85,7 +87,7 @@ include('tabs.php');
////////////////////////////////////////////////////////
if($do_show == 'showentries'){
//print the link to analysis
if($capabilities->viewreports) {
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;
@ -125,7 +127,7 @@ if($do_show == 'showentries'){
}
//####### viewreports-start
if($capabilities->viewreports) {
if(has_capability('mod/feedback:viewreports', $context)) {
//print the list of students
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo isset($groupselect) ? $groupselect : '';
@ -160,7 +162,7 @@ if($do_show == 'showentries'){
?>
</td>
<?php
if($capabilities->deletesubmissions) {
if(has_capability('mod/feedback:deletesubmissions', $context)) {
?>
<td align="right">
<?php

View File

@ -40,11 +40,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->viewreports){
if(!has_capability('mod/feedback:viewreports', $context)){
print_error('error');
}

View File

@ -20,6 +20,10 @@
$usedid = $id;
}
if (!$context = get_context_instance(CONTEXT_MODULE, $usedid)) {
print_error('badcontext');
}
$courseid = optional_param('courseid', false, PARAM_INT);
// $current_tab = $SESSION->feedback->current_tab;
@ -30,7 +34,7 @@
$viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$usedid, 'do_show'=>'view'));
$row[] = new tabobject('view', $viewurl->out(), get_string('overview', 'feedback'));
if($capabilities->edititems) {
if(has_capability('mod/feedback:edititems', $context)) {
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$usedid, 'do_show'=>'edit'));
$row[] = new tabobject('edit', $editurl->out(), get_string('edit_items', 'feedback'));
@ -38,7 +42,7 @@
$row[] = new tabobject('templates', $templateurl->out(), get_string('templates', 'feedback'));
}
if($capabilities->viewreports) {
if(has_capability('mod/feedback:viewreports', $context)) {
if($feedback->course == SITEID){
$analysisurl = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis'));
$row[] = new tabobject('analysis', $analysisurl->out(), get_string('analysis', 'feedback'));
@ -46,9 +50,7 @@
$analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis'));
$row[] = new tabobject('analysis', $analysisurl->out(), get_string('analysis', 'feedback'));
}
}
if($capabilities->viewreports) {
$reporturl = new moodle_url('/mod/feedback/show_entries.php', array('id'=>$usedid, 'do_show'=>'showentries'));
$row[] = new tabobject('showentries', $reporturl->out(), get_string('show_entries', 'feedback'));
}

View File

@ -33,9 +33,12 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$capabilities->mapcourse) {
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
if (!has_capability('mod/feedback:mapcourse', $context)) {
print_error('invalidaccess');
}

View File

@ -39,11 +39,14 @@ if ($id) {
print_error('invalidcoursemodule');
}
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
require_login($course->id, true, $cm);
if(!$capabilities->edititems){
if(!has_capability('mod/feedback:edititems', $context)){
print_error('error');
}

View File

@ -28,12 +28,20 @@ if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
print_error('invalidcoursemodule');
}
$capabilities = feedback_load_capabilities($cm->id);
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
$feedback_complete_cap = false;
if(has_capability('mod/feedback:complete', $context)) {
$feedback_complete_cap = true;
}
if(isset($CFG->feedback_allowfullanonymous)
AND $CFG->feedback_allowfullanonymous
AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
$capabilities->complete = true;
$feedback_complete_cap = true;
}
//check whether the feedback is located and! started from the mainsite
@ -42,7 +50,7 @@ if($course->id == SITEID AND !$courseid) {
}
//check whether the feedback is mapped to the given courseid
if($course->id == SITEID AND !$capabilities->edititems) {
if($course->id == SITEID AND !has_capability('mod/feedback:edititems', $context)) {
if($DB->get_records('feedback_sitecourse_map', array('feedbackid'=>$feedback->id))) {
if(!$DB->get_record('feedback_sitecourse_map', array('feedbackid'=>$feedback->id, 'courseid'=>$courseid))){
print_error('invalidcoursemodule');
@ -88,13 +96,13 @@ echo $OUTPUT->header();
//ishidden check.
//feedback in courses
if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $course->id != SITEID) {
if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) AND $course->id != SITEID) {
notice(get_string("activityiscurrentlyhidden"));
}
//ishidden check.
//feedback on mainsite
if ((empty($cm->visible) and !$capabilities->viewhiddenactivities) AND $courseid == SITEID) {
if ((empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) AND $courseid == SITEID) {
notice(get_string("activityiscurrentlyhidden"));
}
@ -113,14 +121,16 @@ $options = (object)array('noclean'=>true);
echo format_module_intro('feedback', $feedback, $cm->id);
echo $OUTPUT->box_end();
if($capabilities->edititems) {
if(has_capability('mod/feedback:edititems', $context)) {
echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 4);
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo format_text($feedback->page_after_submit);
echo $OUTPUT->box_end();
}
if( (intval($feedback->publish_stats) == 1) AND ( $capabilities->viewanalysepage) AND !( $capabilities->viewreports) ) {
if( (intval($feedback->publish_stats) == 1) AND
( has_capability('mod/feedback:viewanalysepage', $context)) AND
!( has_capability('mod/feedback:viewreports', $context)) ) {
if($multiple_count = $DB->count_records('feedback_tracking', array('userid'=>$USER->id, 'feedback'=>$feedback->id))) {
$analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id, 'courseid'=>$courseid));
echo '<div class="mdl-align"><a href="'.$analysisurl->out().'">';
@ -131,7 +141,7 @@ if( (intval($feedback->publish_stats) == 1) AND ( $capabilities->viewanalysepage
echo '<p>';
//####### mapcourse-start
if($capabilities->mapcourse) {
if($feedback_complete_cap) {
if($feedback->course == SITEID) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo '<div class="mdl-align">';
@ -149,7 +159,7 @@ if($capabilities->mapcourse) {
//####### mapcourse-end
//####### completed-start
if($capabilities->complete) {
if($feedback_complete_cap) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
//check, whether the feedback is open (timeopen, timeclose)
$checktime = time();