function test_allowed_to_update()
{
    // TODO: Proper roles & capabilities
    global $cid;
    if (!isteacher($cid)) {
        error(get_string('pollwarning', 'block_poll'));
    }
}
Example #2
0
 function get_content()
 {
     global $CFG, $COURSE;
     $daysnb = $CFG->block_graph_stats_daysnb;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     if (empty($this->instance)) {
         $this->content->text = '';
         return $this->content;
     }
     $this->content->text = '<center><font size=1>' . get_string('graphtitle', 'block_graph_stats', $daysnb) . '</center>';
     if (isadmin() or isteacher($COURSE->id)) {
         $name = 'popup';
         $title = get_string('connectedtoday', 'block_graph_stats');
         $url = '/blocks/' . $this->name() . '/details.php';
         $options = 'menubar=0,location=0,scrollbars,resizable,width=400,height=500';
         $fullscreen = 0;
         $linkname = '<img src="' . $CFG->wwwroot . '/blocks/' . $this->name() . '/graph.php?course_id=' . $COURSE->id . '" alt="' . get_string('graphtitle', 'block_graph_stats', $daysnb) . '" />';
         $this->content->text .= '<center><a target="' . $name . '" title="' . $title . '" href="' . $CFG->wwwroot . $url . '" ' . "onclick=\"return openpopup('{$url}', '{$name}', '{$options}', {$fullscreen});\">{$linkname}</a></center>";
     } else {
         $this->content->text .= '<center><img src="' . $CFG->wwwroot . '/blocks/' . $this->name() . '/graph.php?course_id=' . $COURSE->id . '" alt="' . get_string('graphtitle', 'block_graph_stats', $daysnb) . '" /></center>';
     }
     // Check if we are in a course or on the first page
     if ($COURSE->id > 1) {
         // In a course
         $connections = count_records_select('log', 'time > ' . mktime(0, 0, 0, date("m"), date("d"), date("Y")) . ' AND action = "view" AND course = ' . $COURSE->id . ' ', 'COUNT(DISTINCT(userid))');
         $this->content->text .= '<center><font size=1>' . get_string('connectedtoday', 'block_graph_stats') . $connections . '</font></center>';
     } else {
         // On the first page
         $connections = count_records_select('log', 'time > ' . mktime(0, 0, 0, date("m"), date("d"), date("Y")) . ' AND action = "login"', 'COUNT(userid)');
         $this->content->text .= '<center><font size=1>' . get_string('connectedtoday', 'block_graph_stats') . $connections . '</font></center>';
         // Show details
         $users = count_records('user', 'deleted', 0, 'confirmed', 1);
         $courses = count_records('course', 'visible', 1);
         $this->content->text .= '<hr />';
         $this->content->text .= get_string('membersnb', 'block_graph_stats') . $users . '<br />';
         $this->content->text .= get_string('coursesnb', 'block_graph_stats') . $courses . '<br />';
     }
     return $this->content;
 }
Example #3
0
/**
 * Returns the display name of a user - the full name of the user 
 * prefixed by '#' for editing teachers and '-' for teachers.
 * @param int $userid The ID of the user.
 * @param int $courseid The ID of the related-course.
 * @return string The display name of the user.
 */
function groups_get_user_displayname($userid, $courseid)
{
    if ($courseid == false) {
        $fullname = false;
    } else {
        $user = groups_get_user($userid);
        $fullname = fullname($user, true);
        //TODO: isteacher, isteacheredit.
        if (isteacher($courseid, $userid)) {
            if (isteacheredit($courseid, $userid)) {
                $prefix = '# ';
            } else {
                $prefix = '- ';
            }
            $fullname = $prefix . $fullname;
        }
    }
    return $fullname;
}
 /**
  * PHP4 style class constructor.
  *
  * @param int $courseid
  */
 function tinymce($courseid)
 {
     parent::editorObject();
     $this->courseid = clean_param($courseid, PARAM_INT);
     $isteacher = isteacher($courseid);
     $this->defaults = array("mode" => "textareas", "theme" => $this->cfg->tinymcetheme, "language" => $this->__get_language(), "width" => "100%", "plugins" => !empty($this->cfg->tinymceplugins) ? $this->cfg->tinymceplugins : '', "content_css" => !empty($this->cfg->tinymcecontentcss) ? $this->cfg->tinymcecontentcss : '', "popup_css" => !empty($this->cfg->tinymcepopupcss) ? $this->cfg->tinymcepopupcss : '', "editor_css" => !empty($this->cfg->tinymceeditorcss) ? $this->cfg->tinymceeditorcss : '', "file_browser_callback" => has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid)) ? 'moodleFileBrowser' : '', "convert_urls" => false, "relative_urls" => false);
     if ($this->cfg->tinymcetheme == 'advanced') {
         $this->defaults['theme_advanced_buttons1_add'] = "fontselect,fontsizeselect";
         $this->defaults['theme_advanced_buttons2_add'] = "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor,liststyle";
         $this->defaults['theme_advanced_buttons2_add_before'] = "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator";
         $this->defaults['theme_advanced_buttons3_add_before'] = "tablecontrols,separator";
         $this->defaults['theme_advanced_buttons3_add'] = "emotions,iespell,flash,advhr,separator,print,separator,ltr,rtl,separator,fullscreen";
         $this->defaults['theme_advanced_toolbar_location'] = "top";
         $this->defaults['theme_advanced_toolbar_align'] = "left";
         $this->defaults['theme_advanced_statusbar_location'] = "bottom";
         $this->defaults['theme_advanced_resizing'] = true;
         $this->defaults['theme_advanced_resize_horizontal'] = true;
     }
     $this->printdialogs = has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid)) ? true : false;
 }
Example #5
0
     $new_course["can_edit"] = has_capability('moodle/course:manageactivities', $context);
 } else {
     if ($course->id != 1) {
         $new_course["can_edit"] = isteacher($course->id, $USER->id, true);
     }
 }
 $course_sections = get_all_sections($course->id, 'fullname ASC', 0, 1);
 $sections_array = array();
 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
 foreach ($course_sections as $section) {
     $show_hidden_sections = FALSE;
     if ($CFG->rolesactive) {
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
         $show_hidden_sections = has_capability('moodle/course:viewhiddensections', $context);
     } else {
         $show_hidden_sections = isteacher($course->id, $USER->id, true);
     }
     $showsection = ($section->visible or $show_hidden_sections);
     $new_section = array();
     $new_section[" id"] = $section->id;
     $new_section["sequence"] = $section->sequence;
     $new_section["section"] = $section->section;
     $new_section["visible"] = $section->visible;
     if ($showsection) {
         $new_section["summary"] = $section->summary;
         $section_modules = array();
         foreach ($mods as $mod) {
             if ($mod->section == $section->id or $mod->sectionnum == $section->id) {
                 $section_modules[] = $mod;
             }
         }
Example #6
0
/**
 * outputs HTML for picture item
 * 
 * Outputs HTML code to browser window showing the picture item,
 * item may have already a $value (a sumitted form has been received), and
 * it is possible to show only the selected picture ($readonly=true)
 * 
 * Radio button values are numbered starting from 1 ($index)
 * 
 * @param object $item contains the item data (a record from prefix_feedback_item table)
 * @param integer $value gives the index to the selected picture (if any)
 * @param boolean $readonly if true, only the selected picture is shown
 */
function print_feedback_picture($item, $value = false, $readonly = false)
{
    global $CFG;
    global $SESSION;
    $presentation = explode("|", $item->presentation);
    $requiredmark = $item->required == 1 ? '<font color="red">*</font>' : '';
    ?>
   <td valign="top" align="left" style="padding-right: 40px;"><?php 
    echo text_to_html(stripslashes_safe($item->name) . $requiredmark, true, false, false);
    ?>
</td>
   <td valign="top" align="left">
<?php 
    $index = 1;
    $checked = '';
    if ($readonly) {
        // here we want to show the selected picture only, $value must be provided
        // this is used by feedback/show_entries.php, for example
        foreach ($presentation as $pic) {
            if ($value == $index) {
                print_simple_box_start('left');
                echo '<img style="padding-left: 20px;" src="' . $CFG->wwwroot . feedback_PICTURE_FILES . '/' . $pic . '" />';
                print_simple_box_end();
                break;
            }
            $index++;
        }
    } else {
        // this is what we want most of the time, to show the picture item so that answering is possible
        // item may have already a value, after a failed saving attempt, say)
        $currentpic = 0;
        $piccount = count($presentation);
        $course_module = get_record('course_modules', 'id', $SESSION->feedback->coursemoduleid);
        foreach ($presentation as $pic) {
            // do we have somehting already selected?
            if ($value == $index) {
                $checked = 'checked="checked"';
            } else {
                $checked = '';
            }
            // generate the HTML for the item
            ?>
         <table><tr>
         <td valign="top"><input type="radio"
               name="<?php 
            echo $item->typ . '_' . $item->id;
            ?>
"
               value="<?php 
            echo $index;
            ?>
" <?php 
            echo $checked;
            ?>
 />
         </td><td><?php 
            echo '<img style="padding-left: 20px;" src="' . $CFG->wwwroot . feedback_PICTURE_FILES . '/' . $pic . '" />';
            ?>
&nbsp;
		 <?php 
            $currentpic++;
            if (isadmin() || isteacher($course_module->course)) {
                if ($currentpic != 1) {
                    echo '</td><td width="20"> ' . feedback_create_action_form('moveup_picture', array($item, $currentpic), 'up.gif');
                } else {
                    echo '</td><td width="20"> &nbsp;';
                }
                if ($currentpic < $piccount) {
                    echo '</td><td width="50"> ' . feedback_create_action_form('movedown_picture', array($item, $currentpic), 'down.gif');
                } else {
                    echo '</td><td width="50"> &nbsp;';
                }
            }
            ?>
         </td></tr></table>
<?php 
            $index++;
        }
    }
    ?>
   </td>
<?php 
}
 $section = 1;
 $weekofseconds = 604800;
 $course->enddate = $course->startdate + $weekofseconds * $course->numsections;
 $sectionmenu = array();
 //  Calculate the current week based on today's date and the starting date of the course.
 $currentweek = $timenow > $course->startdate ? (int) (($timenow - $course->startdate) / $weekofseconds + 1) : 0;
 $currentweek = min($currentweek, $course->numsections);
 $strftimedateshort = " " . get_string("strftimedateshort");
 /// If the selected_week variable is 0, all weeks are selected.
 if ($selected_week == -1 && $currentweek == 0) {
     $selected_week = 0;
     $section = $selected_week;
     $numsections = $course->numsections;
 } else {
     if ($selected_week == -1) {
         if (isteacher($course->id) || !empty($course->activitytracking) && ($selected_week = $cobject->first_unfinished_section()) === false) {
             $selected_week = $currentweek;
         }
         $selected_week = $selected_week > $currentweek ? $currentweek : $selected_week;
         $section = $selected_week;
         $numsections = MAX($section, 1);
     } else {
         if ($selected_week != 0) {
             /// Teachers can select a future week; students can't.
             if ($selected_week > $currentweek && !$isteacher) {
                 $section = $currentweek;
             } else {
                 $section = $selected_week;
             }
             $numsections = $section;
         } else {
Example #8
0
<?php

// $Id: report.php,v 1.34.6.2 2007/10/10 21:09:28 iarenaza Exp $
require_once "../../config.php";
require_once "lib.php";
$id = required_param('id', PARAM_INT);
// course module
if (!($cm = get_coursemodule_from_id('journal', $id))) {
    error("Course Module ID was incorrect");
}
if (!($course = get_record("course", "id", $cm->course))) {
    error("Course module is misconfigured");
}
require_login($course->id, false);
if (!isteacher($course->id)) {
    error("Only teachers can look at this page");
}
if (!($journal = get_record("journal", "id", $cm->instance))) {
    error("Course module is incorrect");
}
// make some easy ways to access the entries.
if ($eee = get_records("journal_entries", "journal", $journal->id)) {
    foreach ($eee as $ee) {
        $entrybyuser[$ee->userid] = $ee;
        $entrybyentry[$ee->id] = $ee;
    }
} else {
    $entrybyuser = array();
    $entrybyentry = array();
}
$strentries = get_string("entries", "journal");
/**
 * Returns all game graded users since a given time for specified game
 */
function game_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid = 0, $groupid = 0)
{
    global $CFG, $COURSE, $USER;
    if ($COURSE->id == $courseid) {
        $course = $COURSE;
    } else {
        $course = get_record('course', 'id', $courseid);
    }
    $modinfo =& get_fast_modinfo($course);
    $cm = $modinfo->cms[$cmid];
    if ($userid) {
        $userselect = "AND u.id = {$userid}";
    } else {
        $userselect = "";
    }
    if ($groupid) {
        $groupselect = "AND gm.groupid = {$groupid}";
        $groupjoin = "JOIN {$CFG->prefix}groups_members gm ON  gm.userid=u.id";
    } else {
        $groupselect = "";
        $groupjoin = "";
    }
    if (!($attempts = get_records_sql("SELECT qa.*, q.grade,\n                                             u.firstname, u.lastname, u.email, u.picture \n                                        FROM {$CFG->prefix}game_attempts qa\n                                             JOIN {$CFG->prefix}game q ON q.id = qa.gameid\n                                             JOIN {$CFG->prefix}user u ON u.id = qa.userid\n                                             {$groupjoin}\n                                       WHERE qa.timefinish > {$timestart} AND q.id = {$cm->instance}\n                                             {$userselect} {$groupselect}\n                                    ORDER BY qa.timefinish ASC"))) {
        return;
    }
    $cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
    $grader = has_capability('moodle/grade:viewall', $cm_context);
    $accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
    $viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
    //$grader          = has_capability('mod/game:grade', $cm_context);
    $grader = isteacher($courseid, $userid);
    $groupmode = groups_get_activity_groupmode($cm, $course);
    if (is_null($modinfo->groups)) {
        $modinfo->groups = groups_get_user_groups($course->id);
        // load all my groups and cache it in modinfo
    }
    $aname = format_string($cm->name, true);
    foreach ($attempts as $attempt) {
        if ($attempt->userid != $USER->id) {
            if (!$grader) {
                // grade permission required
                continue;
            }
            if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
                $usersgroups = groups_get_all_groups($course->id, $attempt->userid, $cm->groupingid);
                if (!is_array($usersgroups)) {
                    continue;
                }
                $usersgroups = array_keys($usersgroups);
                $interset = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
                if (empty($intersect)) {
                    continue;
                }
            }
        }
        $tmpactivity = new object();
        $tmpactivity->type = 'game';
        $tmpactivity->cmid = $cm->id;
        $tmpactivity->name = $aname;
        $tmpactivity->sectionnum = $cm->sectionnum;
        $tmpactivity->timestamp = $attempt->timefinish;
        $tmpactivity->content->attemptid = $attempt->id;
        $tmpactivity->content->sumgrades = $attempt->score * $attempt->grade;
        $tmpactivity->content->maxgrade = $attempt->grade;
        $tmpactivity->content->attempt = $attempt->attempt;
        $tmpactivity->user->userid = $attempt->userid;
        $tmpactivity->user->fullname = fullname($attempt, $viewfullnames);
        $tmpactivity->user->picture = $attempt->picture;
        $activities[$index++] = $tmpactivity;
    }
    return;
}
if (!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
    echo '<td style="width: ' . $blocks_preferred_width . 'px;" id="left-column">';
    blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
    echo '</td>';
}
echo '<td id="middle-column">';
// Print the main part of the page
// Print heading and tabs (if there is more than one).
$currenttab = 'info';
include 'tabs.php';
// Print game name
print_heading(format_string($game->name));
$available = true;
// Show number of attempts summary to those who can view reports.
//    if (has_capability('mod/game:viewreports', $context)) {
if (isteacher($game->course, $USER->id)) {
    if ($a->attemptnum = count_records('game_attempts', 'gameid', $game->id)) {
        $a->studentnum = count_records_select('game_attempts', "gameid = '{$game->id}' ", 'COUNT(DISTINCT userid)');
        $a->studentstring = $course->students;
        notify("<a href=\"report.php?mode=overview&amp;id={$cm->id}\">" . get_string('numattempts', 'game', $a) . '</a>');
    }
}
//    }
//if (has_capability('mod/game:attempt', $context)) {
if ($game->gamekind != '') {
    //Only if the teacher sets the parameters allow playing
    game_view_capability_attempt($game, $context, $course, $available, $cm);
} else {
    echo get_string('useeditgame', 'game');
}
//}
Example #11
0
function array_for_blocks($blocks)
{
    if (empty($blocks)) {
        return array();
    }
    $return_array = array();
    $block_types = blocks_get_record();
    foreach ($blocks as $block) {
        // Only use roles if they're enabled.
        $can_see_hidden_blocks = FALSE;
        if ($CFG->rolesactive) {
            $context = get_context_instance(CONTEXT_COURSE, $course->id);
            $can_see_hidden_blocks = (has_capability('moodle/site:manageblocks', $context) or $block->visible);
        } else {
            $can_see_hidden_blocks = isteacher($course->id, $USER->id, true);
        }
        $show_block = ($block->visible or $can_see_hidden_blocks);
        if ($show_block) {
            $this_block_type = $block_types[intval($block->blockid)];
            if ($this_block_type->name == "calendar_upcoming") {
                $block_array = array();
                $block_array["name"] = $this_block_type->name;
                $return_array[] = $block_array;
            } else {
                if ($this_block_type->name == "calendar_month") {
                    $block_array = array();
                    $block_array["name"] = $this_block_type->name;
                    $return_array[] = $block_array;
                }
            }
        }
    }
    return $return_array;
}
Example #12
0
function webquest_print_teams($webquest, $cm, $userid)
{
    if (isteacher($cm->course)) {
        print_heading_with_help(get_string("teams", "webquest"), "teams", "webquest");
        if ($webquest->teamsmode == 0) {
            print_simple_box_start('center', '70%');
            echo '<div align="center">';
            print_string("teamsnotifyteacher", "webquest");
            echo '</div>';
            print_simple_box_end();
        } else {
            webquest_print_teams_forteacher($webquest, $cm);
        }
    } else {
        print_heading_with_help(get_string("yourteam", "webquest"), "teams", "webquest");
        if ($webquest->teamsmode == 0) {
            print_simple_box_start('center', '70%');
            echo '<div align="center">';
            print_string("teamsnotifystudent", "webquest");
            echo '</div>';
            print_simple_box_end();
        } else {
            webquest_print_teams_forstudent($webquest, $userid);
        }
    }
}
Example #13
0
     }
 } else {
     if ($type == "chat") {
         echo "<h2>Chat:</h2><br />";
         echo '<a href="get_csv.php?id=' . $id . '&type=chat">Download CSV</a><br /><br />';
         if ($tf == 0) {
             $allstudents = get_course_students($course->id);
             foreach ($allstudents as $allstudent) {
                 if (isteacher($course->id) || $allstudent->id == $USER->id) {
                     echo '<a href="?id=' . $id . '&jid=' . $jid . '&type=chat&tf=1&student=' . $allstudent->id . '">' . fullname($allstudent) . '</a> count of posts:' . count_records("chat_messages", "userid", $allstudent->id) . '<br />';
                 }
             }
         } else {
             $chats = get_records("chat_messages", "userid", $student, "timestamp");
             foreach ($chats as $chat) {
                 if (isteacher($course->id) || $chat->userid == $USER->id) {
                     $text .= $chat->message . " ";
                 }
             }
             $userdata = get_record("user", "id", $student);
             $imagepath = textanalysis_getuserimage($student);
             echo '<table border="1" cellspacing="0" valign="top" cellpadding="10">';
             echo '<tr><td rowspan="2" width="35" valign="top"><a  href="' . $CFG->wwwroot . '/courses/user/view.php?id=' . $chat->userid . '&course=' . $course->id . '"><img class="userpicture" align="middle" src="' . $imagepath . '" border="0" width="35" height="35" alt="" /></a></td><td nowrap="nowrap" width="100%">' . fullname($userdata) . '</td></tr><tr><td width="100%"><hr />';
             textanalysis_printanalizeform($text);
             echo '</td></tr>';
             echo '</table>';
         }
     } else {
         if ($type == "gallery") {
             $alluserslink = "";
             if ($_POST['addselect']) {
 function poll_user_eligible()
 {
     // TODO: Proper roles & capabilities
     return $this->poll->eligible == 'all' || $this->poll->eligible == 'students' && isstudent($this->instance->pageid) || $this->poll->eligible == 'teachers' && isteacher($this->instance->pageid);
 }
/**
 * Function used by the site index page to display category specific information.
 */
function fn_display_category_content($course, $catid)
{
    global $USER, $CFG;
    $totcount = 99;
    $isteacher = isteacher($course->id);
    $isediting = isediting($course->id);
    $ismoving = ismoving($course->id);
    if (!($category = get_record('course_categories', 'id', $catid))) {
        error('Invalid category requested.');
    }
    $courses = get_courses_page($catid, 'c.sortorder ASC', 'c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible,c.teacher,c.guest,c.password', $totcount);
    /// Store a course section per category id. Code it by using the 'catid' plus 10 as the section number.
    $sectnum = $catid + 10;
    if (!($section = get_record('course_sections', 'course', $course->id, 'section', $sectnum))) {
        $section = new stdClass();
        $section->course = $course->id;
        $section->section = $sectnum;
        $section->summary = $category->name;
        $section->sequence = '';
        $section->visible = 1;
        if (!($section->id = insert_record('course_sections', $section))) {
            error('Could not create section for category ' . $category->name);
        }
    }
    if (!empty($section) || $isediting) {
        get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
    }
    $groupbuttons = $course->groupmode;
    $groupbuttonslink = !$course->groupmodeforce;
    if ($ismoving) {
        $strmovehere = get_string('movehere');
        $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
        $strcancel = get_string('cancel');
        $stractivityclipboard = $USER->activitycopyname;
    }
    $modinfo = unserialize($course->modinfo);
    $editbuttons = '';
    print_simple_box_start("center", "100%", '', 5, "coursebox");
    echo '<table class="topics" width="100%">';
    echo '<tr id="section-' . $section . '" class="section main">';
    echo '<td class="content">';
    print_heading_block('<div align="center">' . $category->name . '</div>');
    echo '<table class="section" width="100%">';
    if (!empty($section) && !empty($section->sequence)) {
        $sectionmods = explode(',', $section->sequence);
        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }
            $mod = $mods[$modnumber];
            if ($isediting && !$ismoving) {
                if ($groupbuttons) {
                    if (!($mod->groupmodelink = $groupbuttonslink)) {
                        $mod->groupmode = $course->groupmode;
                    }
                } else {
                    $mod->groupmode = false;
                }
                $editbuttons = '<br />' . make_editing_buttons($mod, true, true);
            } else {
                $editbuttons = '';
            }
            if ($mod->visible || $isteacher) {
                echo '<tr><td class="activity ' . $mod->modname . '">';
                if ($ismoving) {
                    if ($mod->id == $USER->activitycopy) {
                        continue;
                    }
                    echo '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img height="16" width="80" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" border="0" /></a>';
                }
                $instancename = urldecode($modinfo[$modnumber]->name);
                $instancename = format_string($instancename, true, $course->id);
                $linkcss = $mod->visible ? '' : ' class="dimmed" ';
                if (!empty($modinfo[$modnumber]->extra)) {
                    $extra = urldecode($modinfo[$modnumber]->extra);
                } else {
                    $extra = '';
                }
                if (!empty($modinfo[$modnumber]->icon)) {
                    $icon = $CFG->pixpath . '/' . urldecode($modinfo[$modnumber]->icon);
                } else {
                    $icon = $CFG->modpixpath . '/' . $mod->modname . '/icon.gif';
                }
                if ($mod->modname == 'label') {
                    echo format_text($extra, FORMAT_HTML) . $editbuttons;
                } else {
                    echo '<img src="' . $icon . '" height="16" width="16" alt="' . $mod->modfullname . '" /> ' . '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . $instancename . '</a>' . $editbuttons;
                }
                echo "</td>";
                echo "</tr>";
            }
        }
    } else {
        echo "<tr><td></td></tr>";
        // needed for XHTML compatibility
    }
    if ($ismoving) {
        echo '<tr><td><a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img height="16" width="80" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" border="0" /></a></td></tr>';
    }
    if ($isediting && $modnames) {
        echo '<tr><td>';
        print_section_add_menus($course, $section->section, $modnames, true);
        echo '</td></tr>';
    }
    echo "</table>\n\n";
    echo '</td></tr></table>';
    print_simple_box_end();
    if (empty($courses)) {
        print_heading(FN_translate_course_string(get_string("nocoursesyet")));
    } else {
        foreach ($courses as $course) {
            print_course($course);
        }
    }
}
Example #16
0
/**
* this function handles the access policy to contents indexed as searchable documents. If this 
* function does not exist, the search engine assumes access is allowed.
* When this point is reached, we already know that : 
* - user is legitimate in the surrounding context
* - user may be guest and guest access is allowed to the module
* - the function may perform local checks within the module information logic
* @param path the access path to the module script code
* @param entry_type the information subclassing (usefull for complex modules, defaults to 'standard')
* @param this_id the item id within the information class denoted by entry_type. In techprojects, this id 
* points to the techproject instance in which all resources are indexed.
* @param user the user record denoting the user who searches
* @param group_id the current group used by the user when searching
* @return true if access is allowed, false elsewhere
*/
function techproject_check_text_access($path, $entry_type, $this_id, $user, $group_id, $context_id)
{
    global $CFG;
    include_once "{$CFG->dirroot}/{$path}/lib.php";
    // get the techproject object and all related stuff
    $techproject = get_record('techproject', 'id', $this_id);
    $course = get_record('course', 'id', $techproject->course);
    $module_context = get_record('context', 'id', $context_id);
    $cm = get_record('course_modules', 'id', $module_context->instanceid);
    if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)) {
        return false;
    }
    //group consistency check : checks the following situations about groups
    // if user is guest check access capabilities for guests :
    // guests can see default project, and other records if groups are liberal
    // TODO : change guestsallowed in a capability
    if (isguest() && $techproject->guestsallowed) {
        if ($group_id && groupmode($course, $cm) == SEPARATEGROUPS) {
            return false;
        }
        return true;
    }
    // trap if user is not same group and groups are separated
    $current_group = get_current_group($course->id);
    if (groupmode($course) == SEPARATEGROUPS && $group_id != $current_group && $group_id) {
        return false;
    }
    //trap if ungroupedsees is off in strict access mode and user is not teacher
    if (groupmode($course) == SEPARATEGROUPS && !$techproject->ungroupedsees && !$group_id && isteacher($user->id)) {
        return false;
    }
    return true;
}
Example #17
0
function exercise_get_user_submissions($exercise, $user)
{
    // return submission of user oldest first, newest last
    // teachers submit "exercises"
    if (!($course = get_record("course", "id", $exercise->course))) {
        error("Course is misconfigured");
    }
    if (isteacher($course->id, $user->id)) {
        return get_records_select("exercise_submissions", "exerciseid = {$exercise->id} AND isexercise = 1", "timecreated");
    }
    return get_records_select("exercise_submissions", "exerciseid = {$exercise->id} AND userid = {$user->id}", "timecreated");
}
Example #18
0
        }
    } else {
        $graded = true;
    }
    print_heading_with_help(get_string("assessthissubmission", "webquest"), "grading", "webquest");
    $redirect = "view.php?id={$cm->id}&amp;action=evaluation";
    // show assessment and allow changes
    webquest_print_assessment($webquest, $graded, true, true, $redirect, $sid);
} elseif ($action == 'delete') {
    $submission = get_record("webquest_submissions", "id", $sid);
    if ($webquest->teamsmode) {
        $userid = get_record("webquest_team_members", "teamid", $submission->userid, "userid", $USER->id);
        $userid = $userid->teamid;
    } else {
        $userid = $USER->id;
    }
    if (!(isteacher($course->id) or $userid = $submission->userid and $timenow < $webquest->submissionend and $timenow < $submission->timecreated + $CFG->maxeditingtime)) {
        error("You are not authorized to delete submission");
    }
    if (count_records("webquest_grades", "sid", $submission->id)) {
        if (!delete_records("webquest_grades", "sid", $submission->id)) {
            error("Could not delete grades for this submission");
        }
    }
    webquest_delete_submitted_files($webquest, $submission);
    if (!delete_records("webquest_submissions", "id", $sid)) {
        error("Could not delete submission");
    }
    redirect("view.php?id={$cm->id}&amp;action=evaluation");
}
print_footer($course);
Example #19
0
/**
 * Indicates if a specified user has a particular type of permission for a 
 * particular group for this module instance.
 * @uses $USER      
 * @param int $cmid The id of the module instance. This is necessary because the 
 * same group can be used in different module instances with different 
 * permission setups. 
 * @param int $groupid The id of the group
 * @param int $permissiontype The permission type - see note on permission types 
 * above
 * @userid int $userid The id of the user, defaults to the current user
 * @return boolean True if the user has the specified permission type, false 
 * otherwise or if an error occurred. 
 */
function groups_m_has_permission($cm, $groupid, $permissiontype, $userid = null)
{
    if (!$userid) {
        global $USER;
        $userid = $USER->id;
    }
    $groupingid = groups_get_grouping_for_coursemodule($cm);
    if (!$groupingid || !is_object($cm) || !isset($cm->course)) {
        return false;
    }
    $courseid = $cm->course;
    $isstudent = isstudent($courseid, $userid);
    $isteacher = isteacher($courseid, $userid);
    $groupmember = groups_is_member($groupid, $userid);
    $memberofsomegroup = groups_is_member_of_some_group_in_grouping($userid, $groupingid);
    $groupingsettings = groups_get_grouping_settings($groupingid);
    $viewowngroup = $groupingsettings->viewowngroup;
    $viewallgroupsmembers = $groupingsettings->viewallgroupmembers;
    $viewallgroupsactivities = $groupingsettings->viewallgroupsactivities;
    $teachersgroupsmark = $groupingsettings->teachersgroupsmark;
    $teachersgroupsview = $groupingsettings->teachersgroupsview;
    $teachersgroupmark = $groupingsettings->teachersgroupmark;
    $teachersgroupview = $groupingsettings->teachersgroupview;
    $teachersoverride = $groupingsettings->teachersoverride;
    $permission = false;
    switch ($permissiontype) {
        case 'view':
            if ($isstudent and $groupmember or $isteacher and $groupmember or $isstudent and $viewallgroupsactivities or $isteacher and !$teachersgroupview or $isteacher and !$memberofsomegroup and $teachersoverride) {
                $permission = true;
            }
            break;
        case 'studentcontribute':
            if ($isstudent and $groupmember or $isteacher and $groupmember or $isteacher and !$memberofsomegroup and $teachersoverride) {
                $permission = true;
            }
            break;
        case 'teachermark':
            if ($isteacher and $groupmember or $isteacher and !$teachersgroupmark or $isteacher and !$memberofsomegroup and $teachersoverride) {
                $permission = true;
            }
            break;
        case 'viewmembers':
            if ($isstudent and $groupmember and $viewowngroup or $isstudent and $viewallgroupsmembers or $isteacher and $groupmember or $isteacher and !$teachersgroupview or $isteacher and !$memberofsomegroup and $teachersoverride or $isteacheredit) {
                $permission = true;
            }
            break;
    }
    return $permission;
}
Example #20
0
function slideshow_show_slide($p)
{
    //########## $CFG was missing,  edited Justin 20110514
    // global $id, $course, $USER, $searchtext;
    global $id, $course, $USER, $searchtext, $CFG;
    //############# End of edit 20110514
    print_simple_box_start('center', '800px', '#ffffff', 10);
    $data_ = get_record("slideshow_files", "id", $p);
    if (strstr($data_->text, "{FMS:SLIDESHOW=")) {
        $fmslink = explode("{FMS:SLIDESHOW=", $data_->text);
        $fmslink = $fmslink[1];
        $fmslink = explode("}", $fmslink);
        $fmslink = $fmslink[0];
        //$fmshtml = '<div style="margin: 10px;"><h3><a href="view.php?id='.$id.'&p='.$data_->id.'">'.$data_->name.'</a></h3></div><div style="clean:both;"></div><div style="border: 1px #666666 solid;float:left;width:500px;margin-right: 20px;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="500" height="428" id="audioplayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'.$fmslink.'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="'.$fmslink.'" quality="high" bgcolor="#ffffff" width="500" height="428" name="audioplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></div>';
        $fmslink2 = str_replace("{$CFG->wwwroot}/mod/slideshow/swfslideplayer.swf?xml_url={$CFG->wwwroot}/file.php", "html5slideshow.php?xml_url=", $fmslink);
        $fmshtml = '<iframe src="' . $fmslink2 . '" style="border: medium none;" height="433px" scrolling="no" width="508px">
  &lt;p&gt;Your browser does not support iframes.&lt;/p&gt;
           </iframe>';
        $height = "200px";
    } else {
        $fmshtml = '<div style="margin: 10px;"><h3><a href="view.php?id=' . $id . '&p=' . $data_->id . '">' . $data_->name . '</a></h3></div><div style="clean:both;"></div><div></div>';
        $height = "100px";
    }
    $fmshtml .= '<div style="background:#FFFFCC;padding:20px;">';
    $datauser = get_record("user", "id", $data_->userid);
    $picture = print_user_picture($data_->userid, $course->id, true, 0, true);
    $fmshtml .= '<div style="height:' . $height . ';float:left;margin-right:10px;"><strong><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $id . '&course=' . $course->id . '">' . fullname($datauser) . "({$datauser->username})</a></strong><br /><br />";
    if ($data_->userid == $USER->id) {
        $fmshtml .= '<a href="view.php?id=' . $id . '&delete=' . $data_->id . '" onclick="return confirm(\'Are you sure you want to delete?\')">' . get_string('slideshow_delete', 'slideshow') . '</a><br />
        <a href="edit.php?id=' . $id . '&idrec=' . $data_->id . '">' . get_string('slideshow_edit', 'slideshow') . '</a><br />';
    } else {
        if (isteacher($USER->id)) {
            $fmshtml .= '<a href="view.php?id=' . $id . '&delete=' . $data_->id . '" onclick="return confirm(\'Are you sure you want to delete?\')">' . get_string('slideshow_delete', 'slideshow') . '</a><br />';
        }
    }
    if ($data_->multiplechoicequestions != "no") {
        $fmshtml .= '<a href="question_test.php?id=' . $id . '&p=' . $data_->id . '" target="questionpreview" onclick="this.target=\'questionpreview\'; return openpopup(\'/mod/slideshow/question_test.php?id=' . $id . '&p=' . $data_->id . '\', \'questionpreview\', \'scrollbars=yes,resizable=yes,width=600,height=700\', 0);">' . get_string('slideshow_questions', 'slideshow') . '</a><br />';
    } else {
        if ($USER->id == $data_->userid) {
            $fmshtml .= '<a href="questions.php?id=' . $id . '&p=' . $data_->id . '">' . get_string('slideshow_questionsadd', 'slideshow') . '</a><br />';
        }
    }
    if ($data_->file != "no") {
        $fmshtml .= '<a href="' . $CFG->wwwroot . '/file.php/' . $course->id . '/presentation/' . $data_->id . '/' . $data_->file . '">' . get_string('slideshow_ppt', 'slideshow') . '</a><br />';
    }
    $comments = count_records("slideshow_comments", "fileid", $data_->id);
    $fmshtml .= '<a href="view.php?id=' . $id . '&p=' . $data_->id . '#comments">' . get_string('slideshow_comments', 'slideshow', $comments) . '</a><br />';
    $fmshtml .= '</div><div style="height:' . $height . ';">' . $picture . '</div></div><div style="clean:both;"></div>';
    $fmshtml .= print_simple_box_start('center', '760px', '#ffffff', 10, '', '', true);
    if (strstr($data_->text, "{FMS:SLIDESHOW=")) {
        $data_->text = str_replace("{FMS:SLIDESHOW=" . $fmslink . "}", $fmshtml, format_text($data_->text));
    } else {
        $data_->text = $fmshtml . "<br />" . format_text($data_->text);
    }
    $data_->text .= print_simple_box_end(true);
    //}
    if ($searchtext) {
        $data_->text = str_replace($searchtext, '<strong>' . $searchtext . '</strong>', $data_->text);
    }
    echo $data_->text;
    print_simple_box_end();
    print_simple_box_end();
}
    if ($action == 'tasks') {
        webquest_print_tasks($webquest, $cm);
    } else {
        if ($action == 'process') {
            webquest_print_process($webquest);
            if (isteacher($cm->course)) {
                echo "<b><a href=\"editpages.php?id={$cm->id}&amp;action=editprocess\">" . get_string("editprocess", 'webquest') . "</a></b>";
                webquest_print_editresources($webquest, $cm);
                echo "<b><a href=\"resources.php?id={$cm->id}&amp;action=editres\">" . get_string("insertresources", 'webquest') . "</a></b>";
            } else {
                webquest_print_resources($webquest);
            }
        } else {
            if ($action == 'conclussion') {
                webquest_print_conclussion($webquest);
                if (isteacher($cm->course)) {
                    echo "<b><a href=\"editpages.php?id={$cm->id}&amp;action=editconclussion\">" . get_string("editconclussion", 'webquest') . "</a></b>";
                }
            } else {
                if ($action == 'evaluation') {
                    webquest_print_evaluation($webquest, $USER->id, $cm);
                } else {
                    if ($action == 'teams') {
                        webquest_print_teams($webquest, $cm, $USER->id);
                    }
                }
            }
        }
    }
}
echo "</td>";
function getRoleForWimbaTools($courseId, $userId)
{
    global $CFG;
    global $USER;
    $role = "";
    if (strstr($CFG->release, "1.7")) {
        $context = get_context_instance(CONTEXT_COURSE, $courseId);
    }
    // the role of the current user is switched
    if (isset($USER->studentview) && $USER->studentview == 1 || isset($context) && isset($USER->switchrole) && !empty($USER->switchrole) && $USER->switchrole[$context->id] > 3) {
        $role = 'StudentBis';
    } else {
        if (isstudent($courseId)) {
            // Student
            $role = 'Student';
        } else {
            if (isadmin() || isteacher($courseId, $USER->id)) {
                // Admin, Teacher
                $role = 'Instructor';
            }
        }
        if (strstr($CFG->release, "1.7")) {
            // 1.7.* version
            if (iscreator()) {
                // Course Creator
                $role = 'Instructor';
            } else {
                if (!isteacheredit($courseId)) {
                    // Non-editing Teacher
                    $role = 'Student';
                }
            }
        }
    }
    return $role;
}
Example #23
0
    # this allows guests to view webwork (signed in as user guest)
    #FIXME  -- replace this with a method that uses the automatic guest sign in on webwork.
    // print_error('Guests cannot view WeBWorK Problem Sets');
}
//force login
$courseid = $course->id;
$wwassignmentid = $wwassignment->id;
require_login($courseid);
//webwork code
$wwcoursename = _wwassignment_mapped_course($courseid, false);
$wwusername = $USER->username;
$wwsetname = $wwassignment->webwork_set;
_wwassignment_mapcreate_user($wwcoursename, $wwusername);
_wwassignment_mapcreate_user_set($wwcoursename, $wwusername, $wwsetname);
$wwkey = _wwassignment_login_user($wwcoursename, $wwusername);
$wwsetlink = _wwassignment_link_to_set_auto_login($wwcoursename, $wwsetname, $wwusername, $wwkey);
add_to_log($course->id, "wwassignment", "view", "view.php?id={$cm->id}", "{$wwassignmentid}", _wwassignment_cmid());
/// Print the page header
if ($course->category) {
    $navigation = "<a href=\"../../course/view.php?id={$course->id}\">{$course->shortname}</a> ->";
}
$strwwassignments = get_string("modulenameplural", "wwassignment");
$strwwassignment = get_string("modulename", "wwassignment");
print_header("{$course->shortname}: {$wwassignment->name}", "{$course->fullname}", "{$navigation} <a href='index.php?id={$course->id}'>{$strwwassignments}</a> -> {$wwassignment->name}", "", "", true, update_module_button($cm->id, $course->id, $strwwassignment), navmenu($course, $cm));
/// Print the main part of the page
// Print webwork in iframe and link to escape to have webwork in a single window
print "<p style='font-size: smaller; color: #aaa;'>" . get_string("iframeNoShow-1", "wwassignment") . "<a href='{$wwsetlink}'>" . get_string("iframeNoShow-2", "wwassignment") . "</a><p align='center'></iframe></p>\n";
print "<iframe id='wwPage' src='{$wwsetlink}' frameborder='1' " . "width='" . $CFG->wwassignment_iframewidth . "' " . "height='" . $CFG->wwassignment_iframeheight . "'>";
print "<script>ww.Init(" . isteacher($course->id) . ")</script>";
/// Finish the page
print_footer($course);
Example #24
0
File: lib.php Project: r007/PMoodle
function journal_count_entries($journal, $groupid = 0)
{
    /// Counts all the journal entries (optionally in a given group)
    global $CFG, $db;
    if ($groupid) {
        /// How many in a particular group?
        return count_records_sql("SELECT COUNT(*) \n                                     FROM {$CFG->prefix}journal_entries j,\n                                          {$CFG->prefix}groups_members g\n                                    WHERE j.journal = {$journal->id} \n                                      AND g.groupid = '{$groupid}' \n                                      AND j.userid = g.userid");
    } else {
        /// Count all the entries from the whole course
        $journals = get_records_sql("SELECT u.*\n                                      FROM {$CFG->prefix}journal_entries j,\n                                           {$CFG->prefix}user u \n                                     WHERE j.userid = u.id\n                                       AND j.journal = {$journal->id}\n                                  ORDER BY j.modified DESC");
        if (empty($journals)) {
            return 0;
        }
        // remove unenrolled participants
        foreach ($journals as $key => $user) {
            if (!isteacher($journal->course, $user->id) and !isstudent($journal->course, $user->id)) {
                unset($journals[$key]);
            }
        }
        return count($journals);
    }
}
Example #25
0
if (!empty($formdata->id)) {
    $id = $formdata->id;
}
if ($id) {
    if (!($cm = get_record("course_modules", "id", $id))) {
        error("Course Module ID was incorrect");
    }
    if (!($course = get_record("course", "id", $cm->course))) {
        error("Course is misconfigured");
    }
    if (!($feedback = get_record("feedback", "id", $cm->instance))) {
        error("Course module is incorrect");
    }
}
require_login($course->id);
if (!(isteacher($course->id) || isadmin())) {
    error(get_string('error'));
}
$filename = "feedback.xls";
//Dem Browser mitteilen, dass jetzt eine Exceldatei zum Downloaden kommt
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename={$filename}");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
//get the groupid for this module
//get the groupid
$mygroupid = $SESSION->lstgroupid;
// Creating a workbook
$workbook = new EasyWorkbook("-");
// Creating the worksheets
Example #26
0
/**
* reworked faster version from /mod/forum/lib.php
* @param forum_id a forum identifier
* @return an array of posts
*/
function forum_get_discussions_fast($forum_id)
{
    global $CFG, $USER;
    $timelimit = '';
    if (!empty($CFG->forum_enabletimedposts)) {
        if (!((isadmin() and !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {
            $now = time();
            $timelimit = " AND ((d.timestart = 0 OR d.timestart <= '{$now}') AND (d.timeend = 0 OR d.timeend > '{$now}')";
            if (!empty($USER->id)) {
                $timelimit .= " OR d.userid = '{$USER->id}'";
            }
            $timelimit .= ')';
        }
    }
    $query = "\n        SELECT \n            p.id, \n            p.subject, \n            p.discussion, \n            p.message,\n            p.created,\n            d.groupid,\n            p.userid, \n            u.firstname, \n            u.lastname\n        FROM \n            {$CFG->prefix}forum_discussions d\n        JOIN \n            {$CFG->prefix}forum_posts p \n        ON \n            p.discussion = d.id\n        JOIN \n            {$CFG->prefix}user u \n        ON \n            p.userid = u.id\n        WHERE \n            d.forum = '{$forum_id}' AND \n            p.parent = 0\n            {$timelimit}\n        ORDER BY \n            d.timemodified DESC\n    ";
    return get_records_sql($query);
}
Example #27
0
        }
        $id = $cm->id;
    } else {
        error("Must specify mail ID or course module ID");
    }
}
if ($CFG->forcelogin) {
    require_login();
}
/// Processing standard security processes
$navigation = "";
if ($course->category) {
    $navigation = "<a href=\"../../course/view.php?id={$course->id}\">{$course->shortname}</a> ->";
    require_login($course->id);
}
if (!$cm->visible and !isteacher($course->id)) {
    print_header();
    notice(get_string("activityiscurrentlyhidden"));
}
add_to_log($course->id, "mail", "view", "view.php?id={$cm->id}", $mail->id, $cm->id);
/// Printing the heading
$strmails = get_string("modulenameplural", "mail");
$strmail = get_string("modulename", "mail");
$navigation = "<a href=\"index.php?id={$course->id}\">{$strmails}</a> ->";
print_header_simple(format_string($mail->name), "", "{$navigation} " . format_string($mail->name), "", "", true, update_module_button($cm->id, $course->id, $strmail), navmenu($course, $cm));
mail_start_print_table_main($mail, $cm, $course);
if ($mail->summary) {
    echo "<br />" . format_text($mail->summary);
} else {
    echo "<br />";
}
Example #28
0
function dimdim_print_recent_activity($course, $isteacher, $timestart)
{
    /// Given a course and a date, prints a summary of all dimdim rooms
    /// that currently have people in them.
    /// This function is called from course/lib.php: print_recent_activity()
    global $CFG;
    $timeold = time() - $CFG->dimdim_old_ping;
    $lastpingsearch = $CFG->dimdim_method == 'sockets' ? '' : 'AND cu.lastping > \'' . $timeold . '\'';
    if (!($dimdimusers = get_records_sql("SELECT u.id, cu.dimdimid, u.firstname, u.lastname\n                                        FROM {$CFG->prefix}dimdim_users as cu,\n                                             {$CFG->prefix}dimdim as ch,\n                                             {$CFG->prefix}user as u\n                                       WHERE cu.userid = u.id\n                                         AND cu.dimdimid = ch.id {$lastpingsearch}\n                                         AND ch.course = '{$course->id}'\n                                       ORDER BY cu.dimdimid ASC"))) {
        return false;
    }
    $isteacher = isteacher($course->id);
    $outputstarted = false;
    $current = 0;
    foreach ($dimdimusers as $dimdimuser) {
        if ($current != $dimdimuser->dimdimid) {
            if ($current) {
                echo '</ul></div>';
                // room
                $current = 0;
            }
            if ($dimdim = get_record('dimdim', 'id', $dimdimuser->dimdimid)) {
                if (!($isteacher or instance_is_visible('dimdim', $dimdim))) {
                    // dimdim hidden to students
                    continue;
                }
                if (!$outputstarted) {
                    print_headline(get_string('currentdimdims', 'dimdim') . ':');
                    $outputstarted = true;
                }
                echo '<div class="room"><p class="head"><a href="' . $CFG->wwwroot . '/mod/dimdim/view.php?c=' . $dimdim->id . '">' . format_string($dimdim->name, true) . '</a></p><ul>';
            }
            $current = $dimdimuser->dimdimid;
        }
        $fullname = fullname($dimdimuser, $isteacher);
        echo '<li class="info name">' . $fullname . '</li>';
    }
    if ($current) {
        echo '</ul></div>';
        // room
    }
    return true;
}
Class to generate an XML document from a mysql table. 
You define the database and table names and the xml tag names
to be used for each table field. Where clauses are also supported.
Updated to PHP4 and the PEAR DB Class.
Below is a little example script.
*/
require_once "../../../config.php";
// xml.inc.php is required, so the whole thing works.
require_once "classmysql2lom.php";
$cid = optional_param('cid', 0, PARAM_INT);
// Course Module ID
$loid = optional_param('loid', 0, PARAM_INT);
// metadatadc ID
require_login($course->id);
if (!(isteacher($course->id) or $course->showreports and $USER->id == $user->id)) {
    echo "<br><div ='center'><hr>";
    $unauthorized = get_string("Comment_student", "metadatalom");
    error('Opss! - ' . $unauthorized);
    echo "<br><hr></div>";
} else {
    $XMLGenerator = new XMLDefinition("{$CFG->dbhost}", "{$CFG->dbname}", "{$CFG->dbuser}", "{$CFG->dbpass}", "{$CFG->prefix}metadatalom", "lom", "resource", "{$cid}", "{$loid}", "{$CFG->dataroot}", "utf-8");
    /*
    Add Fields to select and which is added to the XML document.
    The parameters are:
    1. Field name in DB table.
    2. Tag name in the returned XML.
    */
    $XMLGenerator->AddNode("General_Identifier_Catalog", "<general>\r\n\t<identifier>\r\n\t\t<catalog>", "</catalog>");
    $XMLGenerator->AddNode("General_Identifier_Entry", "\r\n\t\t<entry>", "</entry>\r\n\t</identifier>");
    $XMLGenerator->AddNode("General_Title", "\r\n\t<title>\r\n\t\t<string language=\"pt\">", "</string>\r\n\t</title>");
if (!($game = get_record("game", "id", $attempt->gameid))) {
    error("The game with id {$attempt->gameid} belonging to attempt {$attempt} is missing");
}
game_compute_attempt_layout($game, $attempt);
if (!($course = get_record("course", "id", $game->course))) {
    error("The course with id {$game->course} that the game with id {$game->id} belongs to is missing");
}
if (!($cm = get_coursemodule_from_instance("game", $game->id, $course->id))) {
    error("The course module for the game with id {$game->id} is missing");
}
$grade = game_score_to_grade($attempt->score, $game);
$feedback = game_feedback_for_grade($grade, $attempt->gameid);
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$coursecontext = get_context_instance(CONTEXT_COURSE, $cm->course);
$isteacher = isteacher($game->course, $USER->id);
$options = game_get_reviewoptions($game, $attempt, $context);
$popup = $isteacher ? 0 : $game->popup;
// Controls whether this is shown in a javascript-protected window.
/*if (!has_capability('mod/game:viewreports', $context)) {
      if (!$attempt->timefinish) {
          redirect('attempt.php?q='.$game->id);
      }
      // If not even responses are to be shown in review then we
      // don't allow any review
      if (!($game->review & GAME_REVIEW_RESPONSES)) {
          if (empty($popup)) {
              redirect('view.php?q='.$game->id);
          } else {
              ?><script type="text/javascript">
              opener.document.location.reload();