Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       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   * prints the form to edit a dedicated item
      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  
      28  feedback_init_feedback_session();
      29  
      30  $cmid = required_param('cmid', PARAM_INT);
      31  $typ = optional_param('typ', false, PARAM_ALPHA);
      32  $id = optional_param('id', false, PARAM_INT);
      33  $action = optional_param('action', false, PARAM_ALPHA);
      34  
      35  $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cmid));
      36  
      37  if (!$typ) {
      38      redirect($editurl->out(false));
      39  }
      40  
      41  $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid'=>$cmid));
      42  if ($typ !== false) {
      43      $url->param('typ', $typ);
      44  }
      45  if ($id !== false) {
      46      $url->param('id', $id);
      47  }
      48  $PAGE->set_url($url);
      49  
      50  // set up some general variables
      51  
      52  
      53  if (($formdata = data_submitted()) AND !confirm_sesskey()) {
      54      print_error('invalidsesskey');
      55  }
      56  
      57  if (! $cm = get_coursemodule_from_id('feedback', $cmid)) {
      58      print_error('invalidcoursemodule');
      59  }
      60  
      61  if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
      62      print_error('coursemisconf');
      63  }
      64  
      65  if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
      66      print_error('invalidcoursemodule');
      67  }
      68  
      69  $context = context_module::instance($cm->id);
      70  
      71  require_login($course, true, $cm);
      72  
      73  require_capability('mod/feedback:edititems', $context);
      74  
      75  //if the typ is pagebreak so the item will be saved directly
      76  if ($typ == 'pagebreak') {
      77      feedback_create_pagebreak($feedback->id);
      78      redirect($editurl->out(false));
      79      exit;
      80  }
      81  
      82  //get the existing item or create it
      83  // $formdata->itemid = isset($formdata->itemid) ? $formdata->itemid : NULL;
      84  if ($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) {
      85      $typ = $item->typ;
      86  } else {
      87      $item = new stdClass();
      88      $item->id = null;
      89      $item->position = -1;
      90      if (!$typ) {
      91          print_error('typemissing', 'feedback', $editurl->out(false));
      92      }
      93      $item->typ = $typ;
      94      $item->options = '';
      95  }
      96  
      97  require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php');
      98  
      99  $itemobj = feedback_get_item_class($typ);
     100  
     101  $itemobj->build_editform($item, $feedback, $cm);
     102  
     103  if ($itemobj->is_cancelled()) {
     104      redirect($editurl->out(false));
     105      exit;
     106  }
     107  if ($itemobj->get_data()) {
     108      if ($item = $itemobj->save_item()) {
     109          feedback_move_item($item, $item->position);
     110          redirect($editurl->out(false));
     111      }
     112  }
     113  
     114  ////////////////////////////////////////////////////////////////////////////////////
     115  /// Print the page header
     116  $strfeedbacks = get_string("modulenameplural", "feedback");
     117  $strfeedback  = get_string("modulename", "feedback");
     118  
     119  if ($item->id) {
     120      $PAGE->navbar->add(get_string('edit_item', 'feedback'));
     121  } else {
     122      $PAGE->navbar->add(get_string('add_item', 'feedback'));
     123  }
     124  $PAGE->set_heading($course->fullname);
     125  $PAGE->set_title($feedback->name);
     126  echo $OUTPUT->header();
     127  
     128  // Print the main part of the page.
     129  echo $OUTPUT->heading(format_string($feedback->name));
     130  
     131  /// print the tabs
     132  require ('tabs.php');
     133  
     134  //print errormsg
     135  if (isset($error)) {
     136      echo $error;
     137  }
     138  $itemobj->show_editform();
     139  
     140  if ($typ!='label') {
     141      $PAGE->requires->js('/mod/feedback/feedback.js');
     142      $PAGE->requires->js_function_call('set_item_focus', Array('id_itemname'));
     143  }
     144  
     145  /// Finish the page
     146  ///////////////////////////////////////////////////////////////////////////
     147  ///////////////////////////////////////////////////////////////////////////
     148  ///////////////////////////////////////////////////////////////////////////
     149  
     150  echo $OUTPUT->footer();
    

    Search This Site: