[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/feedback/ -> use_templ.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * print the confirm dialog to use template and create new items from template
  19   *
  20   * @author Andreas Grabs
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  22   * @package mod_feedback
  23   */
  24  
  25  require_once("../../config.php");
  26  require_once ("lib.php");
  27  require_once ('use_templ_form.php');
  28  
  29  $id = required_param('id', PARAM_INT);
  30  $templateid = optional_param('templateid', false, PARAM_INT);
  31  $deleteolditems = optional_param('deleteolditems', 0, PARAM_INT);
  32  
  33  if (!$templateid) {
  34      redirect('edit.php?id='.$id);
  35  }
  36  
  37  $url = new moodle_url('/mod/feedback/use_templ.php', array('id'=>$id, 'templateid'=>$templateid));
  38  if ($deleteolditems !== 0) {
  39      $url->param('deleteolditems', $deleteolditems);
  40  }
  41  $PAGE->set_url($url);
  42  
  43  if (! $cm = get_coursemodule_from_id('feedback', $id)) {
  44      print_error('invalidcoursemodule');
  45  }
  46  
  47  if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
  48      print_error('coursemisconf');
  49  }
  50  
  51  if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
  52      print_error('invalidcoursemodule');
  53  }
  54  
  55  $context = context_module::instance($cm->id);
  56  
  57  require_login($course, true, $cm);
  58  
  59  require_capability('mod/feedback:edititems', $context);
  60  
  61  $mform = new mod_feedback_use_templ_form();
  62  $newformdata = array('id'=>$id,
  63                      'templateid'=>$templateid,
  64                      'confirmadd'=>'1',
  65                      'deleteolditems'=>'1',
  66                      'do_show'=>'edit');
  67  $mform->set_data($newformdata);
  68  $formdata = $mform->get_data();
  69  
  70  if ($mform->is_cancelled()) {
  71      redirect('edit.php?id='.$id.'&do_show=templates');
  72  }
  73  
  74  if (isset($formdata->confirmadd) AND $formdata->confirmadd == 1) {
  75      feedback_items_from_template($feedback, $templateid, $deleteolditems);
  76      redirect('edit.php?id=' . $id);
  77  }
  78  
  79  /// Print the page header
  80  $strfeedbacks = get_string("modulenameplural", "feedback");
  81  $strfeedback  = get_string("modulename", "feedback");
  82  
  83  $PAGE->navbar->add($strfeedbacks, new moodle_url('/mod/feedback/index.php', array('id'=>$course->id)));
  84  $PAGE->navbar->add(format_string($feedback->name));
  85  $PAGE->set_heading($course->fullname);
  86  $PAGE->set_title($feedback->name);
  87  echo $OUTPUT->header();
  88  
  89  /// Print the main part of the page
  90  ///////////////////////////////////////////////////////////////////////////
  91  ///////////////////////////////////////////////////////////////////////////
  92  ///////////////////////////////////////////////////////////////////////////
  93  echo $OUTPUT->heading(format_string($feedback->name));
  94  
  95  echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
  96  echo $OUTPUT->heading(get_string('confirmusetemplate', 'feedback'), 3);
  97  
  98  $mform->display();
  99  
 100  echo $OUTPUT->box_end();
 101  
 102  $templateitems = $DB->get_records('feedback_item', array('template'=>$templateid), 'position');
 103  if (is_array($templateitems)) {
 104      $templateitems = array_values($templateitems);
 105  }
 106  
 107  if (is_array($templateitems)) {
 108      $itemnr = 0;
 109      $align = right_to_left() ? 'right' : 'left';
 110      echo $OUTPUT->box_start('feedback_items');
 111      foreach ($templateitems as $templateitem) {
 112          echo $OUTPUT->box_start('feedback_item_box_'.$align);
 113          if ($templateitem->hasvalue == 1 AND $feedback->autonumbering) {
 114              $itemnr++;
 115              echo $OUTPUT->box_start('feedback_item_number_'.$align);
 116              echo $itemnr;
 117              echo $OUTPUT->box_end();
 118          }
 119          echo $OUTPUT->box_start('box generalbox boxalign_'.$align);
 120          if ($templateitem->typ != 'pagebreak') {
 121              // echo '<div class="feedback_item_'.$align.'">';
 122              feedback_print_item_preview($templateitem);
 123          } else {
 124              echo $OUTPUT->box_start('feedback_pagebreak');
 125              echo get_string('pagebreak', 'feedback').'<hr class="feedback_pagebreak" />';
 126              echo $OUTPUT->box_end();
 127          }
 128          echo $OUTPUT->box_end();
 129          echo $OUTPUT->box_end();
 130      }
 131      echo $OUTPUT->box_end();
 132  } else {
 133      echo $OUTPUT->box(get_string('no_items_available_at_this_template', 'feedback'),
 134                      'generalbox boxaligncenter boxwidthwide');
 135  }
 136  
 137  echo $OUTPUT->footer();
 138  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1