[ Index ]

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

title

Body

[close]

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

   1  <?php // $Id: index.php,v 1.10.2.5 2008/02/26 07:28:01 scyrma Exp $
   2        // Allows a creator to edit custom outcomes, and also display help about outcomes
   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.'/lib/formslib.php');
  29  require_once $CFG->dirroot.'/grade/lib.php';
  30  require_once $CFG->libdir.'/gradelib.php';
  31  
  32  $courseid = optional_param('id', 0, PARAM_INT);
  33  $action   = optional_param('action', '', PARAM_ALPHA);
  34  
  35  /// Make sure they can even access this course
  36  if ($courseid) {
  37      if (!$course = get_record('course', 'id', $courseid)) {
  38          print_error('nocourseid');
  39      }
  40      require_login($course);
  41      $context = get_context_instance(CONTEXT_COURSE, $course->id);
  42      require_capability('moodle/grade:manageoutcomes', $context);
  43  
  44      if (empty($CFG->enableoutcomes)) {
  45          redirect('../../index.php?id='.$courseid);
  46      }
  47  
  48  } else {
  49      require_once $CFG->libdir.'/adminlib.php';
  50      admin_externalpage_setup('outcomes');
  51  }
  52  
  53  /// return tracking object
  54  $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcome', 'courseid'=>$courseid));
  55  
  56  require_once ('import_outcomes_form.php');
  57  $upload_form = new import_outcomes_form();
  58  
  59  if ($upload_form_data = $upload_form->get_data()) {
  60      require_once ('import.php');
  61      exit();
  62  }
  63  
  64  
  65  $strgrades = get_string('grades');
  66  $pagename  = get_string('outcomes', 'grades');
  67  
  68  $navigation = grade_build_nav(__FILE__, $pagename, $courseid);
  69  
  70  $strshortname        = get_string('shortname');
  71  $strfullname         = get_string('fullname');
  72  $strscale            = get_string('scale');
  73  $strstandardoutcome  = get_string('outcomesstandard', 'grades');
  74  $strcustomoutcomes   = get_string('outcomescustom', 'grades');
  75  $strdelete           = get_string('delete');
  76  $stredit             = get_string('edit');
  77  $strcreatenewoutcome = get_string('outcomecreate', 'grades');
  78  $stritems            = get_string('items', 'grades');
  79  $strcourses          = get_string('courses');
  80  $stredit             = get_string('edit');
  81  
  82  switch ($action) {
  83      case 'delete':
  84          if (!confirm_sesskey()) {
  85              break;
  86          }
  87          $outcomeid = required_param('outcomeid', PARAM_INT);
  88          if (!$outcome = grade_outcome::fetch(array('id'=>$outcomeid))) {
  89              break;
  90          }
  91  
  92          if (empty($outcome->courseid)) {
  93              require_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM));
  94          } else if ($outcome->courseid != $courseid) {
  95              error('Incorrect courseid!');
  96          }
  97  
  98          if (!$outcome->can_delete()) {
  99              break;
 100          }
 101  
 102          $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL);
 103  
 104          if(!$deleteconfirmed){
 105              print_header(get_string('outcomedelete', 'grades'));
 106              notice_yesno(get_string('outcomeconfirmdelete', 'grades', $outcome->fullname), 
 107                      "index.php?id={$courseid}", "index.php?id={$courseid}",
 108                      array('outcomeid' => $outcome->id, 
 109                          'action'=> 'delete', 
 110                          'sesskey' =>  $USER->sesskey, 
 111                          'deleteconfirmed'=> 1)
 112                      );
 113              print_footer();
 114              die;
 115          }else{
 116              $outcome->delete();
 117          }
 118          break;
 119  }
 120  
 121  $systemcontext = get_context_instance(CONTEXT_SYSTEM);
 122  $caneditsystemscales = has_capability('moodle/course:managescales', $systemcontext);
 123  
 124  if ($courseid) {
 125      /// Print header
 126      print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation, '', '', true, '', navmenu($course));
 127      /// Print the plugin selector at the top
 128      print_grade_plugin_selector($courseid, 'edit', 'outcome');
 129  
 130      $caneditcoursescales = has_capability('moodle/course:managescales', $context);
 131  
 132      $currenttab = 'outcomes';
 133      require ('tabs.php');
 134  
 135  } else {
 136      admin_externalpage_print_header();
 137      $caneditcoursescales = $caneditsystemscales;
 138  }
 139  
 140  
 141  $outcomes_tables = array();
 142  
 143  if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
 144  
 145      $return = print_heading($strcustomoutcomes, '', 2, 'main', true);
 146      $data = array();
 147      foreach($outcomes as $outcome) {
 148          $line = array();
 149          $line[] = $outcome->get_name();
 150          $line[] = $outcome->get_shortname();
 151  
 152          $scale = $outcome->load_scale();
 153          if (empty($scale->id)) {   // hopefully never happens
 154              $line[] = $scale->get_name();
 155          } else {
 156              if (empty($scale->courseid)) {
 157                  $caneditthisscale = $caneditsystemscales;
 158              } else if ($scale->courseid == $courseid) {
 159                  $caneditthisscale = $caneditcoursescales;
 160              } else {
 161                  $context = get_context_instance(CONTEXT_COURSE, $scale->courseid);
 162                  $caneditthisscale = has_capability('moodle/course:managescales', $context);
 163              }
 164              if ($caneditthisscale) {
 165                  $url = $CFG->wwwroot.'/grade/edit/scale/edit.php?courseid='.$courseid.'&amp;id='.$scale->id;
 166                  $url = $gpr->add_url_params($url);
 167                  $line[] = '<a href="'.$url.'">'.$scale->get_name().'</a>';
 168              } else {
 169                  $line[] = $scale->get_name();
 170              }
 171          }
 172  
 173          $line[] = $outcome->get_item_uses_count();
 174  
 175          $buttons = "";
 176          $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$outcome->id\"><img".
 177                      " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
 178          if ($outcome->can_delete()) {
 179              $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;outcomeid=$outcome->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
 180                          " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
 181          }
 182          $line[] = $buttons;
 183          
 184          $data[] = $line;
 185      }
 186      $table = new object();
 187      $table->head  = array($strfullname, $strshortname, $strscale, $stritems, $stredit);
 188      $table->size  = array('30%', '20%', '20%', '20%', '10%' );
 189      $table->align = array('left', 'left', 'left', 'center', 'center');
 190      $table->width = '90%';
 191      $table->data  = $data;
 192      $return .= print_table($table, true);
 193      $outcomes_tables[] = $return;
 194  }
 195  
 196  
 197  if ($outcomes = grade_outcome::fetch_all_global()) {
 198  
 199      $return = print_heading($strstandardoutcome, '', 2, 'main', true); 
 200      $data = array();
 201      foreach($outcomes as $outcome) {
 202          $line = array();
 203          $line[] = $outcome->get_name();
 204          $line[] = $outcome->get_shortname();
 205  
 206          $scale = $outcome->load_scale();
 207          if (empty($scale->id)) {   // hopefully never happens
 208              $line[] = $scale->get_name();
 209          } else {
 210              if (empty($scale->courseid)) {
 211                  $caneditthisscale = $caneditsystemscales;
 212              } else if ($scale->courseid == $courseid) {
 213                  $caneditthisscale = $caneditcoursescales;
 214              } else {
 215                  $context = get_context_instance(CONTEXT_COURSE, $scale->courseid);
 216                  $caneditthisscale = has_capability('moodle/course:managescales', $context);
 217              }
 218              if ($caneditthisscale) {
 219                  $url = $CFG->wwwroot.'/grade/edit/scale/edit.php?courseid='.$courseid.'&amp;id='.$scale->id;
 220                  $url = $gpr->add_url_params($url);
 221                  $line[] = '<a href="'.$url.'">'.$scale->get_name().'</a>';
 222              } else {
 223                  $line[] = $scale->get_name();
 224              }
 225          }
 226  
 227          $line[] = $outcome->get_course_uses_count();
 228          $line[] = $outcome->get_item_uses_count();
 229  
 230          $buttons = "";
 231          if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
 232              $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&amp;id=$outcome->id\"><img".
 233                          " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
 234          }
 235          if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM)) and $outcome->can_delete()) {
 236              $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&amp;outcomeid=$outcome->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
 237                          " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
 238          }
 239          $line[] = $buttons;
 240  
 241          $data[] = $line;
 242      }
 243      $table = new object();
 244      $table->head  = array($strfullname, $strshortname, $strscale, $strcourses, $stritems, $stredit);
 245      $table->size  = array('30%', '20%', '20%', '10%', '10%', '10%');
 246      $table->align = array('left', 'left', 'left', 'center', 'center', 'center');
 247      $table->width = '90%';
 248      $table->data  = $data;
 249      $return .= print_table($table, true);
 250      $outcomes_tables[] = $return;
 251  }
 252  
 253  foreach($outcomes_tables as $table) {
 254      print($table);
 255  }
 256  
 257  echo '<div class="buttons">';
 258  print_single_button('edit.php', array('courseid'=>$courseid), $strcreatenewoutcome);
 259  if ( !empty($outcomes_tables) ) {
 260      print_single_button('export.php', array('id'=>$courseid, 'sesskey'=>sesskey()),  get_string('exportalloutcomes', 'grades'));
 261  }
 262  echo '</div>';
 263  
 264  $upload_form->display();
 265  
 266  if ($courseid) {
 267      print_footer($course);
 268  } else {
 269      admin_externalpage_print_footer();
 270  }
 271  
 272  ?>


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