Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/edit/scale/index.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 require_once '../../../config.php';
00019 require_once $CFG->dirroot.'/grade/lib.php';
00020 require_once $CFG->libdir.'/gradelib.php';
00021 
00022 $courseid = optional_param('id', 0, PARAM_INT);
00023 $action   = optional_param('action', '', PARAM_ALPHA);
00024 
00025 $PAGE->set_url('/grade/edit/scale/index.php', array('id' => $courseid));
00026 
00028 if ($courseid) {
00029     if (!$course = $DB->get_record('course', array('id' => $courseid))) {
00030         print_error('nocourseid');
00031     }
00032     require_login($course);
00033     $context = get_context_instance(CONTEXT_COURSE, $course->id);
00034     require_capability('moodle/course:managescales', $context);
00035     $PAGE->set_pagelayout('admin');
00036 } else {
00037     require_once $CFG->libdir.'/adminlib.php';
00038     admin_externalpage_setup('scales');
00039 }
00040 
00042 $gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
00043 
00044 $strscale          = get_string('scale');
00045 $strstandardscale  = get_string('scalesstandard');
00046 $strcustomscales   = get_string('scalescustom');
00047 $strname           = get_string('name');
00048 $strdelete         = get_string('delete');
00049 $stredit           = get_string('edit');
00050 $srtcreatenewscale = get_string('scalescustomcreate');
00051 $strused           = get_string('used');
00052 $stredit           = get_string('edit');
00053 
00054 switch ($action) {
00055     case 'delete':
00056         if (!confirm_sesskey()) {
00057             break;
00058         }
00059         $scaleid = required_param('scaleid', PARAM_INT);
00060         if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) {
00061             break;
00062         }
00063 
00064         if (empty($scale->courseid)) {
00065             require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM));
00066         } else if ($scale->courseid != $courseid) {
00067             print_error('invalidcourseid');
00068         }
00069 
00070         if (!$scale->can_delete()) {
00071             break;
00072         }
00073 
00074         $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL);
00075 
00076         if (!$deleteconfirmed) {
00077             $strdeletescale = get_string('delete'). ' '. get_string('scale');
00078             $PAGE->navbar->add($strdeletescale);
00079             $PAGE->set_title($strdeletescale);
00080             $PAGE->set_heading($COURSE->fullname);
00081             echo $OUTPUT->header();
00082             $confirmurl = new moodle_url('index.php', array(
00083                     'id' => $courseid, 'scaleid' => $scale->id,
00084                     'action'=> 'delete',
00085                     'sesskey' =>  sesskey(),
00086                     'deleteconfirmed'=> 1));
00087 
00088             echo $OUTPUT->confirm(get_string('scaleconfirmdelete', 'grades', $scale->name), $confirmurl, "index.php?id={$courseid}");
00089             echo $OUTPUT->footer();
00090             die;
00091         } else {
00092             $scale->delete();
00093         }
00094         break;
00095 }
00096 
00097 if (!$courseid) {
00098     echo $OUTPUT->header();
00099 }
00100 
00101 $table = new html_table();
00102 $table2 = new html_table();
00103 $heading = '';
00104 
00105 if ($courseid and $scales = grade_scale::fetch_all_local($courseid)) {
00106     $heading = $strcustomscales;
00107 
00108     $data = array();
00109     foreach($scales as $scale) {
00110         $line = array();
00111         $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
00112 
00113         $used = $scale->is_used();
00114         $line[] = $used ? get_string('yes') : get_string('no');
00115 
00116         $buttons = "";
00117         $buttons .= grade_button('edit', $courseid, $scale);
00118         if (!$used) {
00119             $buttons .= grade_button('delete', $courseid, $scale);
00120         }
00121         $line[] = $buttons;
00122         $data[] = $line;
00123     }
00124     $table->head  = array($strscale, $strused, $stredit);
00125     $table->size  = array('70%', '20%', '10%');
00126     $table->align = array('left', 'center', 'center');
00127     $table->attributes['class'] = 'scaletable localscales generaltable';
00128     $table->data  = $data;
00129 }
00130 
00131 if ($scales = grade_scale::fetch_all_global()) {
00132     $heading = $strstandardscale;
00133 
00134     $data = array();
00135     foreach($scales as $scale) {
00136         $line = array();
00137         $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
00138 
00139         $used = $scale->is_used();
00140         $line[] = $used ? get_string('yes') : get_string('no');
00141 
00142         $buttons = "";
00143         if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
00144             $buttons .= grade_button('edit', $courseid, $scale);
00145         }
00146         if (!$used and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
00147             $buttons .= grade_button('delete', $courseid, $scale);
00148         }
00149         $line[] = $buttons;
00150         $data[] = $line;
00151     }
00152     $table2->head  = array($strscale, $strused, $stredit);
00153     $table->attributes['class'] = 'scaletable globalscales generaltable';
00154     $table2->size  = array('70%', '20%', '10%');
00155     $table2->align = array('left', 'center', 'center');
00156     $table2->data  = $data;
00157 }
00158 
00159 
00160 if ($courseid) {
00161     print_grade_page_head($courseid, 'scale', 'scale', get_string('coursescales', 'grades'));
00162 }
00163 
00164 echo $OUTPUT->heading($strcustomscales, 3, 'main');
00165 echo html_writer::table($table);
00166 echo $OUTPUT->heading($strstandardscale, 3, 'main');
00167 echo html_writer::table($table2);
00168 echo $OUTPUT->container_start('buttons');
00169 echo $OUTPUT->single_button(new moodle_url('edit.php', array('courseid'=>$courseid)), $srtcreatenewscale);
00170 echo $OUTPUT->container_end();
00171 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations