[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/grade/edit/scale/ -> index.php (source)

   1  <?php // $Id: index.php,v 1.6 2007/10/10 06:34:20 nicolasconnault Exp $
   2        // Allows a creator to edit custom scales, and also display help about scales
   3  
   4  ///////////////////////////////////////////////////////////////////////////
   5  //                                                                       //
   6  // NOTICE OF COPYRIGHT                                                   //
   7  //                                                                       //
   8  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   9  //          http://moodle.com                                            //
  10  //                                                                       //
  11  // Copyright (C) 1999 onwards  Martin Dougiamas  http://moodle.com       //
  12  //                                                                       //
  13  // This program is free software; you can redistribute it and/or modify  //
  14  // it under the terms of the GNU General Public License as published by  //
  15  // the Free Software Foundation; either version 2 of the License, or     //
  16  // (at your option) any later version.                                   //
  17  //                                                                       //
  18  // This program is distributed in the hope that it will be useful,       //
  19  // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  20  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  21  // GNU General Public License for more details:                          //
  22  //                                                                       //
  23  //          http://www.gnu.org/copyleft/gpl.html                         //
  24  //                                                                       //
  25  ///////////////////////////////////////////////////////////////////////////
  26  
  27  require_once '../../../config.php';
  28  require_once $CFG->dirroot.'/grade/lib.php';
  29  require_once $CFG->libdir.'/gradelib.php';
  30  
  31  $courseid = optional_param('id', 0, PARAM_INT);
  32  $action   = optional_param('action', '', PARAM_ALPHA);
  33  
  34  /// Make sure they can even access this course
  35  if ($courseid) {
  36      if (!$course = get_record('course', 'id', $courseid)) {
  37          print_error('nocourseid');
  38      }
  39      require_login($course);
  40      $context = get_context_instance(CONTEXT_COURSE, $course->id);
  41      require_capability('moodle/course:managescales', $context);
  42  } else {
  43      require_once $CFG->libdir.'/adminlib.php';
  44      admin_externalpage_setup('scales');
  45  }
  46  
  47  /// return tracking object
  48  $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
  49  
  50  
  51  $strgrades = get_string('grades');
  52  $pagename  = get_string('scales');
  53  
  54  $navigation = grade_build_nav(__FILE__, $pagename, array('courseid' => $courseid));
  55  
  56  $strscale          = get_string('scale');
  57  $strstandardscale  = get_string('scalesstandard');
  58  $strcustomscales   = get_string('scalescustom');
  59  $strname           = get_string('name');
  60  $strdelete         = get_string('delete');
  61  $stredit           = get_string('edit');
  62  $srtcreatenewscale = get_string('scalescustomcreate');
  63  $strused           = get_string('used');
  64  $stredit           = get_string('edit');
  65  
  66  switch ($action) {
  67      case 'delete':
  68          if (!confirm_sesskey()) {
  69              break;
  70          }
  71          $scaleid = required_param('scaleid', PARAM_INT);
  72          if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) {
  73              break;
  74          }
  75  
  76          if (empty($scale->courseid)) {
  77              require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM));
  78          } else if ($scale->courseid != $courseid) {
  79              error('Incorrect courseid!');
  80          }
  81  
  82          if (!$scale->can_delete()) {
  83              break;
  84          }
  85  
  86          //TODO: add confirmation
  87          $scale->delete();
  88          break;
  89  }
  90  
  91  if ($courseid) {
  92      /// Print header
  93      print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
  94      /// Print the plugin selector at the top
  95      print_grade_plugin_selector($courseid, 'edit', 'scale');
  96  
  97  } else {
  98      admin_externalpage_print_header();
  99  }
 100  
 101  if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) {
 102      print_heading($strcustomscales);
 103      $data = array();
 104      foreach($scales as $scale) {
 105          $line = array();
 106          $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
 107  
 108          $used = $scale->is_used();
 109          $line[] = $used ? get_string('yes') : get_string('no');
 110  
 111          $buttons = "";
 112          $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$scale->id\"><img".
 113                      " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
 114          if (!$used) {
 115              $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
 116                          " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
 117          }
 118          $line[] = $buttons;
 119          $data[] = $line;
 120      }
 121      $table->head  = array($strscale, $strused, $stredit);
 122      $table->size  = array('70%', '20%', '10%');
 123      $table->align = array('left', 'center', 'center');
 124      $table->width = '90%';
 125      $table->data  = $data;
 126      print_table($table);
 127  }
 128  
 129  if ($scales = grade_scale::fetch_all_global()) {
 130      print_heading($strstandardscale);
 131      $data = array();
 132      foreach($scales as $scale) {
 133          $line = array();
 134          $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
 135  
 136          $used = $scale->is_used();
 137          $line[] = $used ? get_string('yes') : get_string('no');
 138  
 139          $buttons = "";
 140          if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
 141              $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$scale->id\"><img".
 142                          " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
 143          }
 144          if (!$used and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
 145              $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
 146                          " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
 147          }
 148          $line[] = $buttons;
 149          $data[] = $line;
 150      }
 151      $table->head  = array($strscale, $strused, $stredit);
 152      $table->size  = array('70%', '20%', '10%');
 153      $table->align = array('left', 'center', 'center');
 154      $table->width = '90%';
 155      $table->data  = $data;
 156      print_table($table);
 157  }
 158  
 159  echo '<div class="buttons">';
 160  print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
 161  echo '</div>';
 162  
 163  if ($courseid) {
 164      print_footer($course);
 165  } else {
 166      admin_externalpage_print_footer();
 167  }
 168  
 169  
 170  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7