Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-19488_master_wip' of git://github.com/grabs/moodle

  • Loading branch information...
commit 629aa44873c4546ecab97d257434be14a3db0e53 2 parents e02ddb9 + 7b1126f
@samhemelryk samhemelryk authored
View
122 mod/feedback/delete_template.php
@@ -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(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 @@
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
-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,36 +116,94 @@
$mform->display();
echo $OUTPUT->box_end();
}else {
- $templates = feedback_get_template_list($course, true);
- echo '<div class="mdl-align">';
+ //first we get the own templates
+ $templates = feedback_get_template_list($course, 'own');
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) {
- echo '<tr><td align="center">'.$template->name.'</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();
View
20 mod/feedback/edit.php
@@ -85,28 +85,26 @@
//the create_template-form
$create_template_form = new feedback_edit_create_template_form();
-$create_template_form->set_feedbackdata(array('context' => $context));
+$create_template_form->set_feedbackdata(array('context'=>$context, 'course'=>$course));
$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(!has_capability('mod/feedback:createprivatetemplate', $context) AND
- !has_capability('mod/feedback:createpublictemplate', $context)) {
+ !has_capability('mod/feedback:createpublictemplate', $context)) {
print_error('cannotsavetempl', 'feedback');
}
- if(trim($create_template_formdata->templatename) == '')
- {
+ if(trim($create_template_formdata->templatename) == '') {
$savereturn = 'notsaved_name';
}else {
- //public templates are currently deaktivated
- // if(has_capability('mod/feedback:createpublictemplate', $context)) {
- // $create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
- // }else {
+ //if the feedback is located on the frontpage then templates can be public
+ if(has_capability('mod/feedback:createpublictemplate', get_system_context())) {
+ $create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
+ }else {
$create_template_formdata->ispublic = 0;
- // }
- if(!feedback_save_as_template($feedback, $create_template_formdata->templatename, $create_template_formdata->ispublic))
- {
+ }
+ if(!feedback_save_as_template($feedback, $create_template_formdata->templatename, $create_template_formdata->ispublic)) {
$savereturn = 'failed';
}else {
$savereturn = 'saved';
View
38 mod/feedback/edit_form.php
@@ -77,14 +77,31 @@ function set_form_elements(){
// visible elements
$templates_options = array();
- if($templates = feedback_get_template_list($this->feedbackdata->course)){//get the templates
- $templates_options[' '] = get_string('select');
- foreach($templates as $template) {
- $templates_options[$template->id] = $template->name;
+ $owntemplates = feedback_get_template_list($this->feedbackdata->course, 'own');
+ $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
+
+ $options = array();
+ if($owntemplates or $publictemplates) {
+ $options[''] = array('' => get_string('choose'));
+
+ if($owntemplates) {
+ $courseoptions = array();
+ foreach($owntemplates as $template) {
+ $courseoptions[$template->id] = $template->name;
+ }
+ $options[get_string('course')] = $courseoptions;
}
+
+ if($publictemplates) {
+ $publicoptions = array();
+ foreach($publictemplates as $template) {
+ $publicoptions[$template->id] = $template->name;
+ }
+ $options[get_string('public', 'feedback')] = $publicoptions;
+ }
+
$attributes = 'onChange="this.form.submit()"';
- $elementgroup[] =& $mform->createElement('select', 'templateid', '', $templates_options, $attributes);
- // buttons
+ $elementgroup[] =& $mform->createElement('selectgroups', 'templateid', '', $options, $attributes);
$elementgroup[] =& $mform->createElement('submit', 'use_template', get_string('use_this_template', 'feedback'));
}else {
$mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
@@ -114,6 +131,8 @@ function set_feedbackdata($data) {
}
function set_form_elements(){
+ global $CFG;
+
$mform =& $this->_form;
// $capabilities = $this->feedbackdata->capabilities;
@@ -134,10 +153,9 @@ function set_form_elements(){
$elementgroup[] =& $mform->createElement('static', 'templatenamelabel', get_string('name', 'feedback'));
$elementgroup[] =& $mform->createElement('text', 'templatename', get_string('name', 'feedback'), array('size'=>'40', 'maxlength'=>'200'));
- //public templates are currently deactivated
- // if(has_capability('mod/feedback:createpublictemplate', $this->feedbackdata->context)) {
- // $elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback'));
- // }
+ if(has_capability('mod/feedback:createpublictemplate', get_system_context())) {
+ $elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback'));
+ }
// buttons
$elementgroup[] =& $mform->createElement('submit', 'create_template', get_string('save_as_new_template', 'feedback'));
View
6 mod/feedback/item/label/lib.php
@@ -123,7 +123,11 @@ function print_item($item){
//is the item a template?
if(!$item->feedback AND $item->template) {
$template = $DB->get_record('feedback_template', array('id'=>$item->template));
- $context = get_context_instance(CONTEXT_COURSE, $template->course);
+ if($template->ispublic) {
+ $context = get_system_context();
+ }else {
+ $context = get_context_instance(CONTEXT_COURSE, $template->course);
+ }
$filearea = 'template';
}else {
$cm = get_coursemodule_from_instance('feedback', $item->feedback);
View
149 mod/feedback/lib.php
@@ -138,6 +138,9 @@ function feedback_update_instance($feedback) {
/**
* Serves the files included in feedback items like label. Implements needed access control ;-)
*
+ * There are two situations in general where the files will be sent.
+ * 1) filearea = item, 2) filearea = template
+ *
* @param object $course
* @param object $cm
* @param object $context
@@ -149,17 +152,59 @@ function feedback_update_instance($feedback) {
function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG, $DB;
- require_login($course, false, $cm);
-
$itemid = (int)array_shift($args);
- require_course_login($course, true, $cm);
-
+ //get the item what includes the file
if (!$item = $DB->get_record('feedback_item', array('id'=>$itemid))) {
return false;
}
+
+ //if the filearea is "item" so we check the permissions like view/complete the feedback
+ if($filearea === 'item') {
+ //get the feedback
+ if(!$feedback = $DB->get_record('feedback', array('id'=>$item->feedback))) {
+ return false;
+ }
- if (!has_capability('mod/feedback:view', $context)) {
+ $canload = false;
+ //first check whether the user has the complete capability
+ if(has_capability('mod/feedback:complete', $context)) {
+ $canload = true;
+ }
+
+ //now we check whether the user has the view capability
+ if(has_capability('mod/feedback:view', $context)) {
+ $canload = true;
+ }
+
+ //if the feedback is on frontpage and anonymous and the fullanonymous is allowed
+ //so the file can be loaded too.
+ if(isset($CFG->feedback_allowfullanonymous)
+ AND $CFG->feedback_allowfullanonymous
+ AND $course->id == SITEID
+ AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
+ $canload = true;
+ }
+
+ if(!$canload) {
+ return false;
+ }
+ }else if($filearea === 'template') { //now we check files in templates
+ if(!$template = $DB->get_record('feedback_template', array('id'=>$item->template))) {
+ return false;
+ }
+
+ //if the file is not public so the capability edititems has to be there
+ if(!$template->ispublic) {
+ if(!has_capability('mod/feedback:edititems', $context)) {
+ return false;
+ }
+ }else { //on public templates, at least the user has to be logged in
+ if(!isloggedin()) {
+ return false;
+ }
+ }
+ }else {
return false;
}
@@ -195,7 +240,6 @@ function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
return false;
}
-
/**
* this will delete a given instance.
* all referenced data also will be deleted
@@ -945,7 +989,7 @@ function feedback_create_template($courseid, $name, $ispublic = 0) {
global $DB;
$templ = new stdClass();
- $templ->course = $courseid;
+ $templ->course = ($ispublic ? 0 : $courseid);
$templ->name = $name;
$templ->ispublic = $ispublic;
@@ -978,9 +1022,14 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
return false;
}
- //files in the template_item are in the context of the current course
+ //files in the template_item are in the context of the current course or
+ //if the template is public the files are in the system context
//files in the feedback_item are in the feedback_context of the feedback
- $c_context = get_context_instance(CONTEXT_COURSE, $newtempl->course);
+ if($ispublic) {
+ $s_context = get_system_context();
+ }else {
+ $s_context = get_context_instance(CONTEXT_COURSE, $newtempl->course);
+ }
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
$f_context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -1001,7 +1050,7 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
if ($itemfiles = $fs->get_area_files($f_context->id, 'mod_feedback', 'item', $item->id, "id", false)) {
foreach($itemfiles as $ifile) {
$file_record = new stdClass();
- $file_record->contextid = $c_context->id;
+ $file_record->contextid = $s_context->id;
$file_record->component = 'mod_feedback';
$file_record->filearea = 'template';
$file_record->itemid = $t_item->id;
@@ -1031,27 +1080,19 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
*
* @global object
* @uses CONTEXT_COURSE
- * @param int $id the templateid
+ * @param object $template the template
* @return void
*/
-function feedback_delete_template($id) {
+function feedback_delete_template($template) {
global $DB;
- $template = $DB->get_record("feedback_template", array("id"=>$id));
-
- //deleting the files from the item
- $fs = get_file_storage();
- $context = get_context_instance(CONTEXT_COURSE, $template->course);
-
-
- if($t_items = $DB->get_records("feedback_item", array("template"=>$id))) {
+ //deleting the files from the item is done by feedback_delete_item
+ if($t_items = $DB->get_records("feedback_item", array("template"=>$template->id))) {
foreach($t_items as $t_item) {
- if ($templatefiles = $fs->get_area_files($context->id, 'mod_feedback', 'template', $t_item->id, "id", false)) {
- $fs->delete_area_files($context->id, 'mod_feedback', 'template', $t_item->id);
- }
+ feedback_delete_item($t_item->id, false, $template);
}
}
- $DB->delete_records("feedback_template", array("id"=>$id));
+ $DB->delete_records("feedback_template", array("id"=>$template->id));
}
/**
@@ -1073,6 +1114,9 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
$fs = get_file_storage();
+ if(!$template = $DB->get_record('feedback_template', array('id'=>$templateid))) {
+ return false;
+ }
//get all templateitems
if(!$templitems = $DB->get_records('feedback_item', array('template'=>$templateid))) {
return false;
@@ -1080,7 +1124,11 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
//files in the template_item are in the context of the current course
//files in the feedback_item are in the feedback_context of the feedback
- $c_context = get_context_instance(CONTEXT_COURSE, $feedback->course);
+ if($template->ispublic) {
+ $s_context = get_system_context();
+ }else {
+ $s_context = get_context_instance(CONTEXT_COURSE, $feedback->course);
+ }
$course = $DB->get_record('course', array('id'=>$feedback->course));
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
$f_context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -1128,9 +1176,9 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
$item->position = $item->position + $positionoffset;
$item->id = $DB->insert_record('feedback_item', $item);
-
+
//TODO: moving the files to the new items
- if ($templatefiles = $fs->get_area_files($c_context->id, 'mod_feedback', 'template', $t_item->id, "id", false)) {
+ if ($templatefiles = $fs->get_area_files($s_context->id, 'mod_feedback', 'template', $t_item->id, "id", false)) {
foreach($templatefiles as $tfile) {
$file_record = new stdClass();
$file_record->contextid = $f_context->id;
@@ -1162,16 +1210,22 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
*
* @global object
* @param object $course
- * @param boolean $onlyown
+ * @param string $onlyownorpublic
* @return array the template recordsets
*/
-function feedback_get_template_list($course, $onlyown = false) {
- global $DB;
+function feedback_get_template_list($course, $onlyownorpublic = '') {
+ global $DB, $CFG;
- if ($onlyown) {
- $templates = $DB->get_records('feedback_template', array('course'=>$course->id));
- } else {
- $templates = $DB->get_records_select('feedback_template', 'course = ? OR ispublic = 1', array($course->id));
+ switch($onlyownorpublic) {
+ case '':
+ $templates = $DB->get_records_select('feedback_template', 'course = ? OR ispublic = 1', array($course->id), 'name');
+ break;
+ case 'own':
+ $templates = $DB->get_records('feedback_template', array('course'=>$course->id), 'name');
+ break;
+ case 'public':
+ $templates = $DB->get_records('feedback_template', array('ispublic'=>1), 'name');
+ break;
}
return $templates;
}
@@ -1344,9 +1398,10 @@ function feedback_update_item($item){
* @uses CONTEXT_MODULE
* @param int $itemid
* @param boolean $renumber should the kept items renumbered Yes/No
+ * @param object $template if the template is given so the items are bound to it
* @return void
*/
-function feedback_delete_item($itemid, $renumber = true){
+function feedback_delete_item($itemid, $renumber = true, $template = false){
global $DB;
@@ -1354,13 +1409,25 @@ function feedback_delete_item($itemid, $renumber = true){
//deleting the files from the item
$fs = get_file_storage();
- if (!$cm = get_coursemodule_from_instance('feedback', $item->feedback)) {
- return false;
- }
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ if($template) {
+ if($template->ispublic) {
+ $context = get_system_context();
+ }else {
+ $context = get_context_instance(CONTEXT_COURSE, $template->course);
+ }
+ if ($templatefiles = $fs->get_area_files($context->id, 'mod_feedback', 'template', $item->id, "id", false)) {
+ $fs->delete_area_files($context->id, 'mod_feedback', 'template', $item->id);
+ }
+ }else {
+ if (!$cm = get_coursemodule_from_instance('feedback', $item->feedback)) {
+ return false;
+ }
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- if ($itemfiles = $fs->get_area_files($context->id, 'mod_feedback', 'item', $item->id, "id", false)) {
- $fs->delete_area_files($context->id, 'mod_feedback', 'item', $item->id);
+ if ($itemfiles = $fs->get_area_files($context->id, 'mod_feedback', 'item', $item->id, "id", false)) {
+ $fs->delete_area_files($context->id, 'mod_feedback', 'item', $item->id);
+ }
}
$DB->delete_records("feedback_value", array("item"=>$itemid));
View
2  mod/feedback/version.php
@@ -9,7 +9,7 @@
*/
- $module->version = 2011051600; // The current module version (Date: YYYYMMDDXX)
+ $module->version = 2011100800; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2010080300; // Requires this Moodle version
$feedback_version_intern = 1; //this version is used for restore older backups
$module->cron = 0; // Period for cron to check this module (secs)
Please sign in to comment.
Something went wrong with that request. Please try again.