MDL-19488 - allow the creation of a "Public" feedback

This commit is contained in:
Andreas Grabs 2011-10-11 22:37:47 +02:00
parent e70dab0646
commit 7b1126fd20
5 changed files with 161 additions and 73 deletions

View file

@ -11,6 +11,7 @@
require_once("../../config.php");
require_once("lib.php");
require_once('delete_template_form.php');
require_once($CFG->libdir.'/tablelib.php');
// $SESSION->feedback->current_tab = 'templates';
$current_tab = 'templates';
@ -77,13 +78,24 @@ if ($mform->is_cancelled()) {
}
if(isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1){
feedback_delete_template($formdata->deletetempl);
if(!$template = $DB->get_record("feedback_template", array("id"=>$deletetempl))) {
print_error('error');
}
if($template->ispublic) {
$systemcontext = get_system_context();
require_capability('mod/feedback:createpublictemplate', $systemcontext);
require_capability('mod/feedback:deletetemplate', $systemcontext);
}
feedback_delete_template($template);
redirect($deleteurl->out(false));
}
/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback");
$str_delete_feedback = get_string('delete_template','feedback');
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_title(format_string($feedback->name));
@ -96,7 +108,7 @@ include('tabs.php');
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->heading(get_string('delete_template','feedback'));
echo $OUTPUT->heading($str_delete_feedback);
if($shoulddelete == 1) {
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
@ -104,37 +116,94 @@ if($shoulddelete == 1) {
$mform->display();
echo $OUTPUT->box_end();
}else {
//first we get the own templates
$templates = feedback_get_template_list($course, 'own');
echo '<div class="mdl-align">';
if(!is_array($templates)) {
echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter');
}else {
echo '<table width="30%">';
echo '<tr><th>'.get_string('templates', 'feedback').'</th><th>&nbsp;</th></tr>';
echo $OUTPUT->heading(get_string('course'), 3);
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
$tablecolumns = array('template', 'action');
$tableheaders = array(get_string('template', 'feedback'), '');
$table_course = new flexible_table('feedback_template_course_table');
$table_course->define_columns($tablecolumns);
$table_course->define_headers($tableheaders);
$table_course->define_baseurl($deleteurl);
$table_course->column_style('action', 'width', '10%');
$table_course->sortable(false);
$table_course->set_attribute('width', '100%');
$table_course->set_attribute('class', 'generaltable');
$table_course->setup();
foreach($templates as $template) {
$suffix = $template->ispublic ? (' ('.get_string('public', 'feedback').')') : '';
echo '<tr><td align="left">'.$template->name.$suffix.'</td>';
echo '<td align="center">';
echo '<form action="delete_template.php" method="post">';
echo '<input title="'.get_string('delete_template','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/delete') . '" hspace="1" height="11" width="11" border="0" />';
echo '<input type="hidden" name="deletetempl" value="'.$template->id.'" />';
echo '<input type="hidden" name="shoulddelete" value="1" />';
echo '<input type="hidden" name="id" value="'.$id.'" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '</form>';
echo '</td></tr>';
$data = array();
$data[] = $template->name;
$url = new moodle_url($deleteurl, array(
'id'=>$id,
'deletetempl'=>$template->id,
'shoulddelete'=>1,
));
$data[] = $OUTPUT->single_button($url, $str_delete_feedback, 'post');
$table_course->add_data($data);
}
echo '</table>';
$table_course->finish_output();
echo $OUTPUT->box_end();
}
?>
<form name="frm" action="delete_template.php" method="post">
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
<input type="hidden" name="id" value="<?php echo $id;?>" />
<input type="hidden" name="canceldelete" value="0" />
<button type="button" onclick="this.form.canceldelete.value=1;this.form.submit();"><?php print_string('cancel');?></button>
</form>
</div>
<?php
//now we get the public templates if it is permitted
$systemcontext = get_system_context();
if(has_capability('mod/feedback:createpublictemplate', $systemcontext) AND
has_capability('mod/feedback:deletetemplate', $systemcontext)) {
$templates = feedback_get_template_list($course, 'public');
if(!is_array($templates)) {
echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter');
}else {
echo $OUTPUT->heading(get_string('public', 'feedback'), 3);
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
$tablecolumns = $tablecolumns = array('template', 'action');
$tableheaders = array(get_string('template', 'feedback'), '');
$table_public = new flexible_table('feedback_template_public_table');
$table_public->define_columns($tablecolumns);
$table_public->define_headers($tableheaders);
$table_public->define_baseurl($deleteurl);
$table_public->column_style('action', 'width', '10%');
$table_public->sortable(false);
$table_public->set_attribute('width', '100%');
$table_public->set_attribute('class', 'generaltable');
$table_public->setup();
// echo $OUTPUT->heading(get_string('public', 'feedback'), 3);
// echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
foreach($templates as $template) {
$data = array();
$data[] = $template->name;
$url = new moodle_url($deleteurl, array(
'id'=>$id,
'deletetempl'=>$template->id,
'shoulddelete'=>1,
));
$data[] = $OUTPUT->single_button($url, $str_delete_feedback, 'post');
$table_public->add_data($data);
}
$table_public->finish_output();
echo $OUTPUT->box_end();
}
}
echo $OUTPUT->box_start('boxaligncenter boxwidthnormal');
$url = new moodle_url($deleteurl, array(
'id'=>$id,
'canceldelete'=>1,
));
echo $OUTPUT->single_button($url, get_string('back'), 'post');
echo $OUTPUT->box_end();
}
echo $OUTPUT->footer();