]> git.mjollnir.org Git - moodle.git/commitdiff
added some capabilities
authortoyomoyo <toyomoyo>
Wed, 30 Aug 2006 08:43:17 +0000 (08:43 +0000)
committertoyomoyo <toyomoyo>
Wed, 30 Aug 2006 08:43:17 +0000 (08:43 +0000)
25 files changed:
mod/data/edit.php
mod/data/field.php
mod/data/field/latlong/field.class.php
mod/data/field/latlong/kml.php
mod/data/import.php
mod/data/index.php
mod/data/lib.php
mod/data/preset.php
mod/data/report.php
mod/glossary/lib.php
mod/glossary/showentry.php
mod/glossary/view.php
mod/hotpot/index.php
mod/hotpot/lib.php
mod/hotpot/report.php
mod/hotpot/report/click/report.php
mod/hotpot/report/fullstat/report.php
mod/hotpot/report/overview/report.php
mod/hotpot/report/simplestat/report.php
mod/hotpot/review.php
mod/hotpot/show.php
mod/hotpot/view.php
mod/survey/details.php
mod/survey/download.php
mod/survey/graph.php

index ef95f67d77598b690da776a3f17394fc02ff71b3..d000acb79748dfec91eb90d2828d3a6b76aa5545 100755 (executable)
     if (!isloggedin() or isguest()) {
         redirect('view.php?d='.$data->id);
     }
+    
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
 /// If it's hidden then it's don't show anything.  :)
-    if (empty($cm->visible) and !isteacher($course->id)) {
+    if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
         $strdatabases = get_string("modulenameplural", "data");
         $navigation = "<a href=\"index.php?id=$course->id\">$strdatabases</a> ->";
         print_header_simple(format_string($data->name), "",
     }
     
 /// Can't use this if there are no fields
-    if (isteacher($course->id)) {
+    if (has_capability('mod/data:managetemplates', $context)) {
         if (!record_exists('data_fields','dataid',$data->id)) {      // Brand new database!
             redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id);  // Redirect to field entry
         }
     }
 
-/// Check access for participants
-    if ((!isteacher($course->id)) && $data->participants == DATA_TEACHERS_ONLY) {
-        error (get_string('noaccess','data'));
-    }
-
     if ($rid) {    // So do you have access?
-        if (!(isteacher($course->id) or data_isowner($rid)) or !confirm_sesskey() ) {
+        if (!(has_capability('mod/data:manageentries', $context) or data_isowner($rid)) or !confirm_sesskey() ) {
             error(get_string('noaccess','data'));
         }
     }
             /// All student edits are marked unapproved by default
             $record = get_record('data_records','id',$rid);
             
-            if ($data->approval == 1 || isteacher($course->id)) {
+            if ($data->approval == 1 || has_capability('mod/data:approve', $context)) {
                 $record->approved = 1;
             } else {
                 $record->approved = 0;
         /// Check if maximum number of entry as specified by this database is reached
         /// Of course, you can't be stopped if you are an editting teacher! =)
 
-            if (data_atmaxentries($data) and !isteacheredit($course->id)){
+            if (data_atmaxentries($data) and !has_capability('mod/data:manageentries',$context)){
                 notify (get_string('atmaxentry','data'));
                 print_footer($course);
                 exit;
     
 /// Upload records section. Only for teachers and the admin.
     
-    if (isteacher($course->id)) {
+    if (has_capability('mod/data:manageentries',$context)) {
         if ($import) {
             print_simple_box_start('center','80%');
             print_heading(get_string('uploadrecords', 'data'), '', 3);
index a8b492da46c0ac90d4d2615de627186f70afd960..8c0e55e0af1afd74bf0a111740515a203fee98d1 100755 (executable)
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     require_capability('mod/data:managetemplates', $context);
-
-
-    if (!isteacheredit($course->id)){
-        error(get_string('noaccess','data'));
-    }
-
-    
     
     /************************************
      *        Data Processing           *
index 2748bb74843d709c029f49158e412a4073b9d049..54f667b20c1a62548d6a7460667e7397b3d02ad6 100755 (executable)
@@ -1,4 +1,4 @@
-<?php 
+<?php 
 ///////////////////////////////////////////////////////////////////////////
 //                                                                       //
 // NOTICE OF COPYRIGHT                                                   //
index 5e00a2419fbc184408d29137bbe413aedbb50db6..9617f0506ee2f96ab9a43121bed3547a3a08fd47 100644 (file)
@@ -56,7 +56,7 @@ if ($rid) {
 require_course_login($course, true, $cm);
 
 /// If it's hidden then it's don't show anything.  :)
-if (empty($cm->visible) and !isteacher($course->id)) {
+if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities',get_context_instance(CONTEXT_MODULE, $cm->id))) {
        $strdatabases = get_string("modulenameplural", "data");
        $navigation = "<a href=\"index.php?id=$course->id\">$strdatabases</a> ->";
        print_header_simple(format_string($data->name), "",
@@ -65,7 +65,7 @@ if (empty($cm->visible) and !isteacher($course->id)) {
 }
 
 /// If we have an empty Database then redirect because this page is useless without data
-if (isteacher($course->id)) {
+if (has_capability('mod/data:managetemplates', $context)) {
        if (!record_exists('data_fields','dataid',$data->id)) {      // Brand new database!
                redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id);  // Redirect to field entry
        }
index d7cb6281b41d03d192ec97aaeeb3358ec1bc0a9b..d0216df3ddb7a207b1bb2a8a296fc159626ff979 100755 (executable)
         }
     }
 
-    ///checking for participants
-    // needs fixing?
-    /*
-    if ((!isteacher($course->id)) && $data->participants == DATA_TEACHERS_ONLY) {
-        error ('students are not allowed to participate in this activity');
-    }
-
     if ($rid){    //editting a record, do you have access to edit this?
-        if (!isteacher($course->id) or !data_isowner($rid) or !confirm_sesskey()){
+        if (!has_capability('mod/data:manageentries', $context) or !data_isowner($rid) or !confirm_sesskey()){
             error (get_string('noaccess','data'));
         }
-    }*/
+    }
   
 
 /// Print the page header
index 48eb31685017a6ee891ccdf8345e4fed7ff954a3..1880e0e5ead251701ee709991f09fb0421dba800 100755 (executable)
@@ -74,7 +74,7 @@
     }
 
     $currentgroup = get_current_group($course->id);
-    if ($currentgroup and isteacheredit($course->id)) {
+    if ($currentgroup and has_capability('mod/data:manageentries', $context)) {
         $group = get_record("groups", "id", $currentgroup);
         $groupname = " ($group->name)";
     } else {
index 3df1f8d3cc142edf73fdc076f864800b3ba3240f..3805b11fd28d24b48cad0584e44af7f358ddf323 100755 (executable)
@@ -557,7 +557,6 @@ function data_add_record($data, $groupid=0){
     $record->groupid = $groupid;
     $record->timecreated = $record->timemodified = time();
     if (has_capability('mod/data:approve', $context)) {
-    //if (isteacher($data->course)) {
         $record->approved = 1;
     } else {
         $record->approved = 0;
@@ -857,7 +856,7 @@ function data_print_template($template, $records, $data, $search='',$page=0, $re
         foreach ($fieldrecords as $fieldrecord) {
             $fields[]= data_get_field($fieldrecord, $data);
         }
-        $isteacher = isteacher($data->course);
+        $isteacher = has_capability('mod/data:managetemplates', $context);
     }
 
     if (empty($records)) {
index 91f4963318534b305ef349cc5ea4c82f9caf3eba..aef44602f033a1ac511f478654a27aad650b6bed 100644 (file)
@@ -42,10 +42,7 @@ if ($id) {
 
 require_login($course->id);
 
-if (!isteacher($course->id)) {
-    error('Must be a teacher to Import Database');
-}
-
+require_capability('mod/data:managetemplates', get_context_instance(CONTEXT_MODULE, $cm->id))
 
 /* get the list of standard presets found in /mod/data/preset */
 $presets = array();
index 12d01de1e6e99f7743a29ef8958341a3eee42dc0..2e0098d1e3356bea5d9ff9bfbc1bac269e5847db 100755 (executable)
@@ -40,7 +40,7 @@
         echo "<th><a href=\"report.php?id=$id&amp;sort=firstname\">$strname</a>";
         echo "<th width=\"100%\"><a href=\"report.php?id=$id&amp;sort=rating\">$strrating</a>";
         foreach ($ratings as $rating) {
-            if (isteacher($data->course)) {
+            if (has_capability('mod/data:manageentries', $context)) {
                 echo '<tr class="forumpostheadertopic">';
             } else {
                 echo '<tr class="forumpostheader">';
index 4578d12f28ffd7d88fe2ce6d8514685edf725dac..075f7e80dfea4bdf3c419b1975879f6f55372655 100644 (file)
@@ -504,7 +504,7 @@ function glossary_get_entries_search($concept, $courseid) {
 
     //Check if the user is a teacher 
     $bypassteacher = 1; //This means NO (by default)
-    if (isteacher($courseid)) {
+    if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_COURSE, $courseid))) {
         $bypassteacher = 0; //This means YES
     } 
 
@@ -947,7 +947,7 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
         $glos = $glossary->id;
     }
     
-    if (!isteacher($glossary->course)) {
+    if (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_COURSE, $glossary->course))) {
         $glossarymodule = get_record("modules", "name", "glossary");
         $onlyvisible = " AND g.id = cm.instance AND cm.visible = 1 AND cm.module = $glossarymodule->id";
         $onlyvisibletable = ", {$CFG->prefix}course_modules cm";
index 7c790f14f40a53d05fa968305a0df9cceed49f19..ced02327f3f3dddd2a3388b80368e7f55b3d7eb2 100644 (file)
@@ -18,7 +18,7 @@
         if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id)) {
             error("Could not determine which course module this belonged to!");
         }
-        if (!$cm->visible and !isteacher($cm->course)) {
+        if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
             redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
         }
         $entry->cmid = $cm->id;
index 0034958f7af35a28e7db5c91da04ae769d6fed2f..165a3ec526f5f467c771f1fb7a9e77819b89172f 100644 (file)
         $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
         require_login($course->id);
     }
-    if (!$cm->visible and !isteacher($course->id)) {
+    if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
         print_header();
         notice(get_string("activityiscurrentlyhidden"));
     }
     /// the "Print" icon
     $printicon = '';
     if ( $isuserframe and $mode != 'search') {
-        if (isteacher($course->id) or $glossary->allowprintview) {
+        if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) {
             $printicon = " <a title =\"". get_string("printerfriendly","glossary") . "\" target=\"printview\" href=\"print.php?id=$cm->id&amp;mode=$mode&amp;hook=$hook&amp;sortkey=$sortkey&amp;sortorder=$sortorder&amp;offset=$offset\"><img border=\"0\" src=\"print.gif\" alt=\"\" /></a>";
         }
     }
index e7226ac5a535a85bc3afd2a3466e5dd334ac162e..e771d5355e865e7aab68323c67b41c3e9af1a23f 100644 (file)
@@ -7,7 +7,8 @@
     require_once("lib.php");
 
     $id = required_param("id");   // course
-
+    $coursecontext = get_context_instance(CONTEXT_COURSE, $id);
+    
     if (! $course = get_record("course", "id", $id)) {
         error("Course ID is incorrect");
     }
         MAX(a.score) AS maxscore
     ";
     $select = "a.hotpot IN ($hotpotids)";
-    if (isteacher($course->id)) {
+    if (has_capability('mod/hotpot:viewreport', $coursecontext)) {
         // do nothing (=get all users)
     } else {
         // restrict results to this user only
         array_push($table->head, $title); 
         array_push($table->align, "center");
     }
-    if (isteacheredit($course->id)) {
+    if (has_capability('moodle/course:manageactivities', $coursecontext)) {
         array_push($table->head, $strupdate);
         array_push($table->align, "center");
     }
     array_push($table->align, 
         "left", "left", "center", "left"
     );
-    if (isadmin()) {
+    if (has_capability('mod/hotpot:grade', $coursecontext)) {
         array_push($table->head, $strregrade);
         array_push($table->align, "center");
     }
             $bestscore = "&nbsp;";
 
         } else {
+          
+            $cm = get_coursemodule_from_instance('hotpot', $hotpot->id);
             // report number of attempts and users
             $report = get_string("viewallreports","quiz", $totals[$hotpot->id]->attemptcount);
-            if (isteacher($course->id)) {
+            if (has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_MODULE, $cm->id))) {
                 $report .= " (".$totals[$hotpot->id]->usercount." $strusers)";
             }
             $report = '<a href="report.php?hp='.$hotpot->id.'">'.$report.'</a>';
             array_push($data, $printsection);
         }
 
-        if (isteacheredit($course->id)) {
+        if (has_capability('moodle/course:manageactivities', $coursecontext)) {
             $updatebutton = ''
             .   '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/course/mod.php">'
             .   '<input type="hidden" name="update" value="'.$hotpot->coursemodule.'" />'
index a7d2b4582bd2b485db4226b7ac4c6dbceca5ecef..133bd88c363052f52685727235152b973858b2d3 100644 (file)
@@ -707,7 +707,8 @@ function hotpot_get_all_instances_in_course($modulename, $course) {
     if ($rawmods = get_records_sql($query)) {
 
         // cache $isteacher setting
-        $isteacher = isteacher($course->id);
+        
+        $isteacher = has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_MODULE, $course->id));
 
         $explodesection = array();
         $order = array();
@@ -1018,7 +1019,7 @@ function hotpot_print_recent_mod_activity($activity, $course, $detail=false) {
         $href = "$CFG->wwwroot/mod/hotpot/view.php?hp=$activity->instance";
         print '<a href="'.$href.'">'.$activity->name.'</a> - ';
     }
-    if (isteacher($course)) {
+    if (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course))) {
         // score (with link to attempt details)
         $href = "$CFG->wwwroot/mod/hotpot/review.php?hp=$activity->instance&attempt=".$activity->content->attemptid;
         print '<a href="'.$href.'">('.hotpot_format_score($activity->content).')</a> ';
index 7ad0b12d92a5603e48caa2177e96543faada782c..ee97ff1fdc0956326189170aba02647cb0b38332 100644 (file)
         }
     }
 
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     // set homeurl of couse (for error messages)
     $course_homeurl = "$CFG->wwwroot/course/view.php?id=$course->id";
 
     require_login($course->id);
 
     // get report mode
-    if (isteacher($course->id)) {
+    if (has_capability('mod/hotpot:viewreport',$context)) {
         $mode = optional_param("mode", "overview");
     } else {
         // students have no choice
@@ -48,7 +49,7 @@
     $formdata = array(
         'mode' => $mode,
         'reportcourse'     => isadmin() ? optional_param('reportcourse', get_user_preferences('hotpot_reportcourse', 'this')) : 'this',
-        'reportusers'      => isteacher($course->id) ? optional_param('reportusers', get_user_preferences('hotpot_reportusers', 'all')) : 'this',
+        'reportusers'      => has_capability('mod/hotpot:viewreport',$context) ? optional_param('reportusers', get_user_preferences('hotpot_reportusers', 'all')) : 'this',
         'reportattempts'   => optional_param('reportattempts', get_user_preferences('hotpot_reportattempts', 'all')),
         'reportformat'     => optional_param('reportformat', 'htm'),
         'reportshowlegend' => optional_param('reportshowlegend', get_user_preferences('hotpot_reportshowlegend', '0')),
     // print page header. if required
     if ($formdata['reportformat']=='htm') {
         hotpot_print_report_heading($course, $cm, $hotpot, $mode);
-        if (isteacher($course->id)) {
+        if (has_capability('mod/hotpot:viewreport',$context)) {
             hotpot_print_report_selector($course, $hotpot, $formdata);
         }
     }
 
     // delete selected attempts, if any
-    if (isteacher($course->id)) {
+    if (has_capability('mod/hotpot:deleteattempt',$context)) {
         $del = optional_param("del", "");
         hotpot_delete_selected_attempts($hotpot, $del);
     }
@@ -384,7 +385,7 @@ function hotpot_print_report_heading(&$course, &$cm, &$hotpot, &$mode) {
 
     $navigation = "<a href=index.php?id=$course->id>$strmodulenameplural</a> -> ";
     $navigation .= "<a href=\"view.php?id=$cm->id\">$hotpot->name</a> -> ";
-    if (isteacher($course->id)) {
+    if (has_capability('mod/hotpot:viewreport',$context)) {
         if ($mode=='overview' || $mode=='simplestat' || $mode=='fullstat') {
             $module = "quiz";
         } else {
index 2bbc4163d74af92510ee51e56a83946355bfdf5d..9ca0dc58a314b41e7064d7d069df16a8148eaa89 100644 (file)
@@ -53,7 +53,7 @@ class hotpot_report extends hotpot_default_report {
                // set align and wrap\r
                $this->set_align_and_wrap($table);\r
                // is link to review allowed?\r
-               $allow_review = ($is_html && (isteacher($course->id) || $hotpot->review));\r
+               $allow_review = ($is_html && (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id)) || $hotpot->review));\r
                // initialize array of data values\r
                $this->data = array();\r
                // set exercise data values\r
index 7eafbae7c2602d69d9ddf0df7c28436ede717937..f038e9f4d80e64de1cdbb27a4e936b85f103b990 100644 (file)
@@ -26,7 +26,7 @@ class hotpot_report extends hotpot_default_report {
                $nobr_start = $is_html ? '<nobr>'  : '';
                $nobr_end   = $is_html ? '</nobr>' : '';
                // is review allowed? (do this once here, to save time later)
-               $allow_review = ($is_html && (isteacher($course->id) || $hotpot->review));
+               $allow_review = ($is_html && (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id)) || $hotpot->review));
                // assume penalties column is NOT required
                $show_penalties = false;
                // initialize $table
index f34c14759809e26fb6582b136dc9838de620b8cc..fd691c2a477b07f09caaa1eb40b7fc4fbee294f6 100644 (file)
@@ -82,11 +82,11 @@ class hotpot_report extends hotpot_default_report {
                                }\r
                                $attemptnumber = $attempt->attempt;\r
                                $starttime = trim(userdate($attempt->timestart, $strtimeformat));\r
-                               if ($is_html && isset($attempt->score) && (isteacher($course->id) || $hotpot->review)) {\r
+                               if ($is_html && isset($attempt->score) && (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id)) || $hotpot->review)) {\r
                                        $attemptnumber = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$attemptnumber.'</a>';\r
                                        $starttime = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$starttime.'</a>';\r
                                }\r
-                               if ($is_html && isteacher($course->id)) {\r
+                               if ($is_html && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course))) {\r
                                        $checkbox = '<input type=checkbox name="box'.$attempt->clickreportid.'" value="'.$attempt->clickreportid.'">'.$spacer;\r
                                } else {\r
                                        $checkbox = '';\r
@@ -111,7 +111,7 @@ class hotpot_report extends hotpot_default_report {
                // remove final 'hr' from data rows\r
                array_pop($table->data);\r
                // add the "delete" form to the table\r
-               if ($options['reportformat']=='htm' && isteacher($course->id)) {\r
+               if ($options['reportformat']=='htm' && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id))) {\r
                        $strdeletecheck = get_string('deleteattemptcheck','quiz');\r
                        $table->start = $this->deleteform_javascript();\r
                        $table->start .= '<form method="post" action="report.php" name="deleteform" onsubmit="'."return deletecheck('".$strdeletecheck."', 'selection')".'">'."\n";\r
index b5f1b80e369e48cdb7c7f11fa73b57c513d4660f..6df2e561e017eedaed0d87ec972e92be37752118 100644 (file)
@@ -15,7 +15,7 @@ class hotpot_report extends hotpot_default_report {
                $is_html = ($options['reportformat']=='htm');
                $blank = ($download ? '' : '&nbsp;');
                $no_value = ($download ? '' : '-');
-               $allow_review = true; // ($options['reportformat']=='htm' && (isteacher($course->id) || $hotpot->review));
+               $allow_review = true;
                // start the table
                unset($table);
                $table->border = 1;
index 06f1169654a70552f3b4c0995262298b8ee209f6..30e03fed3197986f98fb8b32cf6f3bd2ad76ef52 100644 (file)
     if (! $attempt = get_record("hotpot_attempts", "id", $attempt)) {
         error("Attempt ID was incorrect");
     }
+    
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     require_login($course->id);
-    if (!isteacher($course->id)) {
+    if (!has_capability('mod/hotpot:viewreport',$context)) {
         if (!$hotpot->review) {
             error(get_string("noreview", "quiz"));
         }
@@ -58,7 +60,7 @@
     print_heading($hotpot->name);
     hotpot_print_attempt_summary($hotpot, $attempt);
     hotpot_print_review_buttons($course, $hotpot, $attempt);
-    $action = isteacher($course->id) ? optional_param('action') : '';
+    $action = has_capability('mod/hotpot:viewreport',$context) ? optional_param('action') : '';
     if ($action) {
         $xml = get_field('hotpot_details', 'details', 'attempt', $attempt->id);
         print '<hr>';
@@ -130,7 +132,7 @@ function hotpot_print_review_buttons(&$course, &$hotpot, &$attempt) {
     print "\n".'<table border="0" align="center" cellpadding="2" cellspacing="2" class="generaltable">';
     print "\n<tr>\n".'<td align="center">';
     print_single_button("report.php?hp=$hotpot->id", NULL, get_string('continue'), 'post');
-    if (isteacher($course->id) && record_exists('hotpot_details', 'attempt', $attempt->id)) {
+    if (has_capability('mod/hotpot:viewreport',$context) && record_exists('hotpot_details', 'attempt', $attempt->id)) {
         print "</td>\n".'<td align="center">';
         print_single_button("review.php?hp=$hotpot->id&attempt=$attempt->id&action=showxmlsource", NULL, get_string('showxmlsource', 'hotpot'), 'post');
         print "</td>\n".'<td align="center">';
index 2905ec256f5071a2ee0e10d3778c221fc640550c..c7e2c4d1a405f1460364617b93601d457222c10e 100644 (file)
@@ -9,7 +9,7 @@
     $params->course = required_param('course');
     $params->reference = required_param('reference');
     require_login($params->course);
-    if (!isteacher($params->course)) {
+    if (!has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $params->course))) {
         error("You are not allowed to view this page!");
     }
     if (isadmin()) {
index 86b5d7332cc8d612d9578b371d2ea70c9df51da1..8e2d76f789675dbabed4551871abc1e2247e3a6b 100644 (file)
             if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
                 error("Course Module ID was incorrect");
             }
+        
         }
         require_login($course->id);
+        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     }
     // set nextpage (for error messages)
     $nextpage = "$CFG->wwwroot/course/view.php?id=$course->id";
@@ -49,7 +51,7 @@
     $loggedinas = '<span class="logininfo">'.user_login_string($course, $USER).'</span>';
     $time = time();
     $hppassword = optional_param('hppassword');
-    if (HOTPOT_FIRST_ATTEMPT && !isteacher($course->id)) {
+    if (HOTPOT_FIRST_ATTEMPT && !has_capability('mod/hotpot:grade', $context)) {
         // check this quiz is available to this student
         // error message, if quiz is unavailable
         $error = '';
index a785a64af18a9094a34d78fd32f8e2a6212a39a0..60d0d0e2220d09100dc9e1c747be46dfb9278080 100644 (file)
@@ -10,9 +10,7 @@
 
         require_login($course->id, false);
 
-        if (!isteacher($course->id)) {
-            error("You can't modify this course!");
-        }
+        require_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id));
 
         $streditingasurvey = get_string("editingasurvey", "survey");
         $strsurveys = get_string("modulenameplural", "survey");
index 51d8001a4feb5e3c071c28f22008c6a6babce823..1f48351dc0e35d264e1b062ef0057f08111aa389 100644 (file)
     }
 
     require_login($course->id, false);
-
-    if (!isteacher($course->id)) {
-        error("Sorry, only teachers can see this.");
-    }
+    require_capability('mod/survey:download', get_context_instance(CONTEXT_MODULE, $cm->id)) ;
 
     if (! $survey = get_record("survey", "id", $cm->instance)) {
         error("Survey ID was incorrect");
index 019261873c2fc5135e43640e8e614c03caf67378..5edc80ad23642074c56f6b7ffe8fcdb474159c7b 100644 (file)
@@ -21,8 +21,9 @@
     require_login($course->id, false, $cm);
 
     $groupmode = groupmode($course, $cm);   // Groups are being used
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
-    if (!isteacher($course->id)) {
+    if (!has_capability('mod/survey:readresponses', $context)) {
         if ($type != "student.png" or $sid != $USER->id ) {
             error("Sorry, you aren't allowed to see this.");
         } else if ($groupmode and !ismember($group)) {