コード例 #1
0
 function create_session_and_responses(&$question, &$state, $cmoptions, $attempt)
 {
     // Choose a random shortanswer question from the category:
     // We need to make sure that no question is used more than once in the
     // quiz. Therfore the following need to be excluded:
     // 1. All questions that are explicitly assigned to the quiz
     // 2. All random questions
     // 3. All questions that are already chosen by an other random question
     global $QTYPES;
     if (!isset($cmoptions->questionsinuse)) {
         $cmoptions->questionsinuse = $cmoptions->questions;
     }
     if ($question->options->subcats) {
         // recurse into subcategories
         $categorylist = question_categorylist($question->category);
     } else {
         $categorylist = $question->category;
     }
     $saquestions = $this->get_sa_candidates($categorylist, $cmoptions->questionsinuse);
     $count = count($saquestions);
     $wanted = $question->options->choose;
     $errorstr = '';
     if ($count < $wanted && isteacherinanycourse()) {
         if ($count >= 2) {
             $errorstr = "Error: could not get enough Short-Answer questions!\n                 Got {$count} Short-Answer questions, but wanted {$wanted}.\n                 Reducing number to choose from to {$count}!";
             $wanted = $question->options->choose = $count;
         } else {
             $errorstr = "Error: could not get enough Short-Answer questions!\n                 This can happen if all available Short-Answer questions are already\n                 taken up by other Random questions or Random Short-Answer question.\n                 Another possible cause for this error is that Short-Answer\n                 questions were deleted after this Random Short-Answer question was\n                 created.";
         }
         notify($errorstr);
         $errorstr = '<span class="notifyproblem">' . $errorstr . '</span>';
     }
     if ($count < $wanted) {
         $question->questiontext = "{$errorstr}<br /><br />Insufficient selection options are\n             available for this question, therefore it is not available in  this\n             quiz. Please inform your teacher.";
         // Treat this as a description from this point on
         $question->qtype = DESCRIPTION;
         return true;
     }
     $saquestions = draw_rand_array($saquestions, $question->options->choose);
     // from bug 1889
     foreach ($saquestions as $key => $wrappedquestion) {
         if (!$QTYPES[$wrappedquestion->qtype]->get_question_options($wrappedquestion)) {
             return false;
         }
         // Now we overwrite the $question->options->answers field to only
         // *one* (the first) correct answer. This loop can be deleted to
         // take all answers into account (i.e. put them all into the
         // drop-down menu.
         $foundcorrect = false;
         foreach ($wrappedquestion->options->answers as $answer) {
             if ($foundcorrect || $answer->fraction != 1.0) {
                 unset($wrappedquestion->options->answers[$answer->id]);
             } else {
                 if (!$foundcorrect) {
                     $foundcorrect = true;
                 }
             }
         }
         if (!$QTYPES[$wrappedquestion->qtype]->create_session_and_responses($wrappedquestion, $state, $cmoptions, $attempt)) {
             return false;
         }
         $wrappedquestion->name_prefix = $question->name_prefix;
         $wrappedquestion->maxgrade = $question->maxgrade;
         $cmoptions->questionsinuse .= ",{$wrappedquestion->id}";
         $state->options->subquestions[$key] = clone $wrappedquestion;
     }
     // Shuffle the answers (Do this always because this is a random question type)
     $subquestionids = array_values(array_map(create_function('$val', 'return $val->id;'), $state->options->subquestions));
     $subquestionids = swapshuffle($subquestionids);
     // Create empty responses
     foreach ($subquestionids as $val) {
         $state->responses[$val] = '';
     }
     return true;
 }
コード例 #2
0
ファイル: view.php プロジェクト: r007/PMoodle
        redirect("{$CFG->wwwroot}/login/index.php");
    }
}
$strpersonalprofile = get_string('personalprofile');
$strparticipants = get_string("participants");
$struser = get_string("user");
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $coursecontext));
$navlinks = array();
if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
    $navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id={$course->id}", 'type' => 'misc');
}
/// If the user being shown is not ourselves, then make sure we are allowed to see them!
if (!$currentuser) {
    if ($course->id == SITEID) {
        // Reduce possibility of "browsing" userbase at site level
        if ($CFG->forceloginforprofiles and !isteacherinanycourse() and !isteacherinanycourse($user->id) and !has_capability('moodle/user:viewdetails', $usercontext)) {
            // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
            $navlinks[] = array('name' => $struser, 'link' => null, 'type' => 'misc');
            $navigation = build_navigation($navlinks);
            print_header("{$strpersonalprofile}: ", "{$strpersonalprofile}: ", $navigation, "", "", true, "&nbsp;", navmenu($course));
            print_heading(get_string('usernotavailable', 'error'));
            print_footer($course);
            exit;
        }
    } else {
        // Normal course
        // check capabilities
        if (!has_capability('moodle/user:viewdetails', $coursecontext) && !has_capability('moodle/user:viewdetails', $usercontext)) {
            print_error('cannotviewprofile');
        }
        if (!has_capability('moodle/course:view', $coursecontext, $user->id, false)) {
コード例 #3
0
ファイル: datalib.php プロジェクト: nicolasconnault/moodle2.0
/**
 * Returns an object with counts of failed login attempts
 *
 * Returns information about failed login attempts.  If the current user is
 * an admin, then two numbers are returned:  the number of attempts and the
 * number of accounts.  For non-admins, only the attempts on the given user
 * are shown.
 *
 * @param string $mode Either 'admin', 'teacher' or 'everybody'
 * @param string $username The username we are searching for
 * @param string $lastlogin The date from which we are searching
 * @return int
 */
function count_login_failures($mode, $username, $lastlogin)
{
    global $DB;
    $params = array('mode' => $mode, 'username' => $username, 'lastlogin' => $lastlogin);
    $select = "module='login' AND action='error' AND time > :lastlogin";
    $count = new object();
    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
        // Return information about all accounts
        if ($count->attempts = $DB->count_records_select('log', $select, $params)) {
            $count->accounts = $DB->count_records_select('log', $select, $params, 'COUNT(DISTINCT info)');
            return $count;
        }
    } else {
        if ($mode == 'everybody' or $mode == 'teacher' and isteacherinanycourse()) {
            if ($count->attempts = $DB->count_records_select('log', "{$select} AND info = :username", $params)) {
                return $count;
            }
        }
    }
    return NULL;
}
コード例 #4
0
function fm_print_share_course_members($id, $linkid = NULL, $type = 0, $groupid = 0)
{
    global $CFG, $USER;
    $fmdir = fm_get_root_dir();
    $table->align = array("center", "left", "left", "center");
    $table->width = "60%";
    $table->size = array("15%", "35%", "35%", "20%");
    $table->wrap = array(NULL, 'no', 'no', 'no');
    $table->data = array();
    $strcbx = "<input type=\"checkbox\" name=\"cbu[]\" value=\"0\" onClick=\"selectboxes(this, 1)\">&nbsp;" . get_string("selectall", 'block_file_manager');
    $strlastname = "<a href=\"{$CFG->wwwroot}/{$fmdir}/sharing.php?id={$id}&linkid={$linkid}&tsort=sortlast\">" . get_string("userlastname", 'block_file_manager') . "</a>";
    $strfirstname = "<a href=\"{$CFG->wwwroot}/{$fmdir}/sharing.php?id={$id}&linkid={$linkid}&tsort=sortfirst\">" . get_string("userfirstname", 'block_file_manager') . "</a>";
    $struserrole = "<a href=\"{$CFG->wwwroot}/{$fmdir}/sharing.php?id={$id}&linkid={$linkid}&tsort=sortrole\">" . get_string("userrole", 'block_file_manager') . "</a>";
    $table->head = array($strcbx, $strlastname, $strfirstname, $struserrole);
    if ($id == 1) {
        //adding this block to a site frontpage has been disabled - it's really bad performance wise!
        if (!($allusers = get_records_select("user", 'deleted=0', 'lastname', 'lastname, firstname, id'))) {
            $table->data[] = array("", "<center><i><b>" . get_string("msgnocourseusers", 'block_file_manager') . "</b></i></center>");
        } else {
            //echo "please choose a course, from which, to share resources";
            echo get_string('cannotsharefromsitelevel', 'block_file_manager');
            continue;
            // nadavkav . too much load on the server :-(
            // Prints all roles of user throughout site
            foreach ($allusers as $key => $au) {
                $allusers[$key]->role = NULL;
                if (has_capability('moodle/legacy:admin', get_context_instance(CONTEXT_SYSTEM), $au->id, false)) {
                    $allusers[$key]->role = "Admin ";
                    $allusers[$key]->userid = $au->id;
                }
                if (isteacherinanycourse($au->id, false)) {
                    if ($allusers[$key]->role) {
                        $slash = "/";
                    }
                    $allusers[$key]->role .= "{$slash} Teacher ";
                    $allusers[$key]->userid = $au->id;
                }
                if (record_exists('role_assignments', 'userid', $au->id)) {
                    $slash = "";
                    if ($allusers[$key]->role) {
                        $slash = "/";
                    }
                    $allusers[$key]->role .= "{$slash} Student ";
                    $allusers[$key]->userid = $au->id;
                }
            }
        }
    } else {
        // We try to select any user who is in this course, his name and his role
        // deprecated
        //       $sqltoexecute = "SELECT {$CFG->prefix}user.id, {$CFG->prefix}user.firstname, {$CFG->prefix}user.lastname, {$CFG->prefix}role.name
        //                         FROM {$CFG->prefix}user, {$CFG->prefix}course_display, {$CFG->prefix}role_assignments, {$CFG->prefix}role
        //                         WHERE (course = $id AND {$CFG->prefix}course_display.userid = {$CFG->prefix}user.id
        //                           AND {$CFG->prefix}user.id = {$CFG->prefix}role_assignments.userid
        //                           AND {$CFG->prefix}role_assignments.roleid = {$CFG->prefix}role.id)";
        //  a better way to get roles of users in a course , for Moodle v1.9.x (nadavkav patch)
        $sqltoexecute = "SELECT u.id, u.firstname, u.lastname, r.name\n                        FROM {$CFG->prefix}user u\n                        JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id\n                        JOIN {$CFG->prefix}role r ON ra.roleid = r.id\n                        JOIN {$CFG->prefix}context con ON ra.contextid = con.id\n                        JOIN {$CFG->prefix}course c ON c.id = con.instanceid AND con.contextlevel = 50\n                        WHERE (r.shortname = 'student' OR r.shortname = 'teacher' OR r.shortname = 'editingteacher') AND c.id = {$id}";
        //echo $sqltoexecute;
        // If there is nobody in this course, then print the message "no users in this course"
        if (!($allpersons = get_records_sql($sqltoexecute))) {
            $table->data[] = array("", "<center><i><b>" . get_string("msgnocourseusers", "block_file_manager") . "</b></i></center>");
        } else {
            // Gives all users their role in the course
            $allusers = array();
            if ($allpersons) {
                foreach ($allpersons as $key => $au) {
                    //$tmp = get_record("user", "id", $au->userid);
                    $allusers[$au->id]->role = $au->name;
                    $allusers[$au->id]->lastname = $au->lastname;
                    $allusers[$au->id]->firstname = $au->firstname;
                    $allusers[$au->id]->userid = $au->id;
                }
            }
        }
    }
    if ($allusers) {
        $sharetoall = false;
        // checks if file is shared to all
        if (count_records_sql("SELECT * FROM {$CFG->prefix}fmanager_shared WHERE owner = '{$USER->id}' AND course = '{$id}' AND userid = '0' AND sharedlink = '{$linkid}' AND type = '{$type}'")) {
            $sharetoall = true;
        }
        foreach ($allusers as $au) {
            if ($au->userid != $USER->id) {
                // Cant share to yourself
                if ($linkid != NULL) {
                    $thecount = 0;
                    if ($sharetoall) {
                        $thecount = 1;
                    } else {
                        if ($groupid != 0) {
                            $mysql = "SELECT * FROM {$CFG->prefix}fmanager_shared WHERE owner = '{$groupid}' AND course = '{$id}' AND userid = '{$au->userid}' AND sharedlink = '{$linkid}' AND type = '{$type}'";
                        } else {
                            $mysql = "SELECT * FROM {$CFG->prefix}fmanager_shared WHERE owner = '{$USER->id}' AND course = '{$id}' AND userid = '{$au->userid}' AND sharedlink = '{$linkid}' AND type = '{$type}'";
                        }
                        $thecount = count_records_sql($mysql);
                    }
                    if ($thecount > 0) {
                        $cbx = "<input type=\"checkbox\" name=\"cbu[]\" value=\"{$au->userid}\" checked>";
                    } else {
                        $cbx = "<input type=\"checkbox\" name=\"cbu[]\" value=\"{$au->userid}\">";
                    }
                } else {
                    $cbx = "<input type=\"checkbox\" name=\"cbu[]\" value=\"{$au->userid}\">";
                }
                $table->data[] = array($cbx, format_text($au->lastname, FORMAT_PLAIN), format_text($au->firstname, FORMAT_PLAIN), $au->role);
            }
        }
    }
    return $table;
}
コード例 #5
0
ファイル: datalib.php プロジェクト: r007/PMoodle
/**
 * Returns an object with counts of failed login attempts
 *
 * Returns information about failed login attempts.  If the current user is
 * an admin, then two numbers are returned:  the number of attempts and the
 * number of accounts.  For non-admins, only the attempts on the given user
 * are shown.
 *
 * @param string $mode Either 'admin', 'teacher' or 'everybody'
 * @param string $username The username we are searching for
 * @param string $lastlogin The date from which we are searching
 * @return int
 */
function count_login_failures($mode, $username, $lastlogin)
{
    $select = 'module=\'login\' AND action=\'error\' AND time > ' . $lastlogin;
    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
        // Return information about all accounts
        if ($count->attempts = count_records_select('log', $select)) {
            $count->accounts = count_records_select('log', $select, 'COUNT(DISTINCT info)');
            return $count;
        }
    } else {
        if ($mode == 'everybody' or $mode == 'teacher' and isteacherinanycourse()) {
            if ($count->attempts = count_records_select('log', $select . ' AND info = \'' . $username . '\'')) {
                return $count;
            }
        }
    }
    return NULL;
}
コード例 #6
0
/**
 * Prints an individual user box
 *
 * @param $user user object (contains the following fields: id, firstname, lastname and picture)
 * @param $return if true return html string
 */
function tag_print_user_box($user, $return = false)
{
    global $CFG;
    $textlib = textlib_get_instance();
    $usercontext = get_context_instance(CONTEXT_USER, $user->id);
    $profilelink = '';
    if (has_capability('moodle/user:viewdetails', $usercontext) || isteacherinanycourse($user->id)) {
        $profilelink = $CFG->wwwroot . '/user/view.php?id=' . $user->id;
    }
    $output = print_box_start('user-box', 'user' . $user->id, true);
    $fullname = fullname($user);
    $alt = '';
    if (!empty($profilelink)) {
        $output .= '<a href="' . $profilelink . '">';
        $alt = $fullname;
    }
    //print user image - if image is only content of link it needs ALT text!
    if ($user->picture) {
        $output .= '<img alt="' . $alt . '" class="user-image" src="' . $CFG->wwwroot . '/user/pix.php/' . $user->id . '/f1.jpg" />';
    } else {
        $output .= '<img alt="' . $alt . '" class="user-image" src="' . $CFG->wwwroot . '/pix/u/f1.png" />';
    }
    $output .= '<br />';
    if (!empty($profilelink)) {
        $output .= '</a>';
    }
    //truncate name if it's too big
    if ($textlib->strlen($fullname) > 26) {
        $fullname = $textlib->substr($fullname, 0, 26) . '...';
    }
    $output .= '<strong>' . $fullname . '</strong>';
    $output .= print_box_end(true);
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}
コード例 #7
0
/**
 * Get a list of recent recorded meetings based upon the user's system authority:
 *  - admins can see all recent meeting recordings
 *  - teachers see recent recordings in their courses
 *  - students see recent recordings they participated in
 *
 * The return array is of the format where each entry is an object that consists
 * of the following information:
 *
 *  $entry->name        = meeting name
 *  $entry->recordingid = recording ID
 *
 * @uses $USER
 * @param none
 * @return array An array of recorded meeting information.
 */
function elluminate_recent_recordings()
{
    global $USER;
    /*
        if (!$elmuser = get_record('elluminate_users', 'userid', $USER->id)) {
            return NULL;
        }
    */
    /// Get the five most recent recordings.
    if (!($recordings = get_records('elluminate_recordings', '', '', 'created DESC', '*', '', 5))) {
        return NULL;
    }
    $return = array();
    $type = 'student';
    if (isadmin($USER->id)) {
        $type = 'admin';
    } else {
        if (isteacherinanycourse($USER->id, false)) {
            $type = 'teacher';
        }
    }
    $rids = array();
    foreach ($recordings as $recording) {
        $meeting = get_record('elluminate', 'meetingid', $recording->meetingid);
        $meeting->name = stripslashes($meeting->name);
        if (in_array($meeting->id, $rids)) {
            continue;
        }
        if ($meeting->private == false) {
            $return[] = createRecordingEntry($meeting, $recording);
        } else {
            // ## REFACTOR THIS MESS!!!!
            switch ($type) {
                case 'admin':
                    $return[] = createRecordingEntry($meeting, $recording);
                    break;
                case 'teacher':
                    if (isteacher($meeting->course, $USER->id, false)) {
                        $return[] = createRecordingEntry($meeting, $recording);
                    }
                    break;
                case 'student':
                    if (elluminate_is_participant($recording->meetingid, $USER->id)) {
                        $return[] = createRecordingEntry($meeting, $recording);
                    }
                    break;
                default:
                    break;
            }
        }
    }
    return $return;
}
コード例 #8
0
$questionid = (int) array_shift($args);
$relativepath = implode('/', $args);
if (!($question = get_record('question', 'id', $questionid))) {
    error('No valid arguments supplied');
}
if (!($questioncategory = get_record('question_categories', 'id', $question->category))) {
    error('No valid arguments supplied');
}
/////////////////////////////////////
// Check access
/////////////////////////////////////
if ($quizid == 0) {
    // teacher doing preview during quiz creation
    if ($questioncategory->publish) {
        require_login();
        if (!isteacherinanycourse()) {
            error('No valid arguments supplied');
        }
    } else {
        require_login($questioncategory->course);
        $cm = get_coursemodule_from_instance('quiz', $quizid);
        require_capability('mod/quiz:preview', get_context_instance(CONTEXT_MODULE, $cm->id));
    }
} else {
    if (!($quiz = get_record('quiz', 'id', $quizid))) {
        error('No valid arguments supplied');
    }
    if (!($course = get_record('course', 'id', $quiz->course))) {
        error('No valid arguments supplied');
    }
    require_login($course->id);
コード例 #9
0
 function view_dates()
 {
     global $CFG, $USER;
     $rday = optional_param('rday', NULL, PARAM_INT);
     $rslot = optional_param('rslot', NULL, PARAM_INT);
     $delete = optional_param('delete', NULL, PARAM_INT);
     $resid = optional_param('resid', NULL, PARAM_INT);
     $uid = optional_param('uid', NULL, PARAM_INT);
     require_once "../../config.php";
     $cmid = $this->cm->id;
     if (!($course = get_record('course', 'id', $this->cm->course))) {
         error('Course is misconfigured');
     }
     $itemid = $this->bookings->itemid;
     $username = $USER->username;
     $UID = $USER->id;
     $firstname = $USER->firstname;
     $lastname = $USER->lastname;
     if ($firstname == '' or $lastname == '') {
         return "";
     }
     $html .= '<form name=myform id=myform method=post action="view.php?id=' . $cmid . '">';
     $proplist = bookings_item_properties($itemid);
     $days = explode(',', 'A,B,C,D,E,F');
     $daylimits = array();
     if (isset($proplist['days']) and $proplist['days'] != '') {
         $days = explode(',', $proplist['days']);
         $dag = 0;
         foreach ($days as $day) {
             list($dy, $lim) = explode(':', $day);
             // pick out optional size limit
             $days[$dag] = $dy;
             $daylimits[$dag] = (int) $lim;
             $dag++;
         }
     }
     $widthprcent = (int) (95 / count($days));
     // default width
     $slots = explode(',', '1,2,3,4,5,6');
     $slotlimits = array();
     if (isset($proplist['slots']) and $proplist['slots'] != '') {
         $slots = explode(',', $proplist['slots']);
         $slt = 0;
         foreach ($slots as $slot) {
             list($sl, $lim) = explode(':', $slot);
             // pick out optional size limit
             $slots[$slt] = $sl;
             $slotlimits[$slt] = (int) $lim;
             $slt++;
         }
     }
     $multiple = 0;
     if (isset($proplist['multiple'])) {
         $multiple = (int) $proplist['multiple'];
     }
     $exclusive = 'non';
     // many entries pr user
     if (isset($proplist['exclusive'])) {
         $exclusive = $proplist['exclusive'];
     }
     $can_edit = 1;
     // any user can make a booking
     if (isset($proplist['edit_group'])) {
         $can_edit = isadmin() ? 1 : 0;
         if ($proplist['edit_group'] == 'teachers' and isteacherinanycourse($USER->id)) {
             $can_edit = 1;
         } else {
             if ($proplist['edit_group'] == 'students') {
                 $can_edit = 1;
             } else {
                 $can_edit = isteacherinanycourse($USER->id) ? 1 : 0;
                 // default is teachers can make a booking
             }
         }
     }
     $privilege = isteacherinanycourse($USER->id) ? isadmin() ? 2 : 1 : 0;
     /// here we fetch out all reservations
     $sql = 'SELECT * FROM ' . $CFG->prefix . 'bookings_calendar 
             WHERE eventtype="reservation" 
             AND bookingid=' . $this->bookings->id;
     $reservation = array();
     $daycount = array();
     // count of reservations pr day (colcount)
     $slotcount = array();
     // count of reservations pr slot (rowcount)
     $total = 0;
     if ($res = get_records_sql($sql)) {
         foreach ($res as $re) {
             $reservation[$re->day][$re->slot][] = $re;
             $reservation[$re->day][$re->slot]->res = $re;
             $daycount[$re->day] += 1;
             $slotcount[$re->slot] += 1;
             $total++;
         }
     }
     /// this is where we make the reservation or delete reservations
     if ((isset($resid) and isset($uid) or isset($rday) and isset($rslot)) and $can_edit) {
         if (!isteacherinanycourse($USER->id) and !isadmin() and isset($reservation[$rday][$rslot])) {
             if ($uid != $UID) {
                 // return;  // assume an attempt to phreak the system with params
             }
         }
         /// exclusive decides if and how multiple bookings made by one user is handled
         /// default is that a user can book once in any available slot
         switch ($exclusive) {
             case 'row':
                 /// only one booking pr row
                 $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar WHERE eventtype="reservation" AND userid=' . $UID . ' AND slot=' . $rslot;
                 break;
             case 'rowcol':
                 /// only one booking in this row+col
                 $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar WHERE eventtype="reservation" AND userid=' . $UID . ' AND (day=' . $rday . ' OR slot=' . $rslot . ')';
                 break;
             case 'col':
                 /// only one booking pr col
                 $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar WHERE eventtype="reservation" AND userid=' . $UID . ' AND day=' . $rday;
                 break;
             case 'all':
                 /// only one booking
                 $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar WHERE eventtype="reservation" AND userid=' . $UID;
                 break;
             default:
                 $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar WHERE eventtype="reservation" AND slot=' . $rslot . ' AND day=' . $rday . ' AND userid=' . $UID;
         }
         execute_sql($sql, 0);
         /// this removes multiple bookings by one person for a given slot (or all bookings if exclusive)
         if (isset($resid)) {
             $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar WHERE id=' . $resid;
             execute_sql($sql, 0);
         }
         if (!isset($delete)) {
             $sql = 'INSERT INTO ' . $CFG->prefix . 'bookings_calendar (bookingid,name,value,userid,eventtype,slot,day) 
                 VALUES (' . $this->bookings->id . ',"' . $username . '","' . $username . '",' . $UID . ',"reservation",' . $rslot . ',' . $rday . ')';
             execute_sql($sql, 0);
         }
         // have to refetch data
         $sql = 'SELECT * FROM ' . $CFG->prefix . 'bookings_calendar 
             WHERE eventtype="reservation" 
             AND bookingid=' . $this->bookings->id;
         $reservation = array();
         $daycount = array();
         // count of reservations pr day (colcount)
         $slotcount = array();
         // count of reservations pr slot (rowcount)
         $total = 0;
         // total number of reservations
         if ($res = get_records_sql($sql)) {
             foreach ($res as $re) {
                 $reservation[$re->day][$re->slot][] = $re;
                 $daycount[$re->day] += 1;
                 $slotcount[$re->slot] += 1;
                 $total++;
             }
         }
     }
     $html .= '<div id="all">';
     // now we draw up the table
     $table = array();
     $lastrow = '';
     if ($can_edit) {
         $baselink = '<a href="view.php?id=' . $cmid;
     } else {
         $baselink = '';
     }
     $table[] = '<table border=1 width=100%>';
     $table[] = '<tr><th width=5%>&nbsp;</th>';
     $dag = 0;
     foreach ($days as $day) {
         if ($day == '') {
             continue;
         }
         $table[] = '<th>' . $day . '</th>';
         $lastrow .= "<td>" . $daycount[$dag] . "&nbsp;</td>\n";
         $dag++;
     }
     $table[] = '</tr>';
     $time = 0;
     foreach ($slots as $slottime) {
         $t = $time + 1;
         $table[] = "<tr><th class=\"number\"><span class=\"time\">{$slottime}</span></th>";
         $dag = 0;
         $scanedit = ($slotlimits[$time] == 0 or $slotlimits[$time] > $slotcount[$time]) ? $can_edit : 0;
         foreach ($days as $day) {
             $canedit = $scanedit;
             $class = 'normal';
             if ($day != '') {
                 $canedit = ($daylimits[$dag] == 0 or $daylimits[$dag] > $daycount[$dag]) ? $canedit : 0;
                 if ($tp[$dag][$time] == '') {
                     $class = 'free';
                     $tp[$dag][$time] = $canedit ? $baselink . '&rday=' . $dag . '&rslot=' . $time . '">' . get_string('free', 'bookings') . '</a>' : get_string('free', 'bookings');
                 }
                 if (isset($reservation[$dag][$time])) {
                     $tp[$dag][$time] = '';
                     foreach ($reservation[$dag][$time] as $myres) {
                         $class = 'reserved';
                         $linktext = 'Reserved ' . $myres->value;
                         if ($myres->userid == $UID) {
                             $linktext = 'M';
                         } else {
                             if (sizeof($reservation[$dag][$time] > 1)) {
                                 $linktext = isteacherinanycourse($myres->userid) ? 'T' : 'S';
                             }
                         }
                         // admin can override any, teacher can override student
                         if ($myres->userid == $UID or isadmin() or isteacherinanycourse($USER->id) and !isteacherinanycourse($myres->userid)) {
                             $tp[$dag][$time] .= $can_edit ? $baselink . '&delete=1&resid=' . $myres->id . '&uid=' . $myres->userid . '"
                         title="' . $myres->value . '" >' . $linktext . '</a> ' : $linktext . $myres->value;
                         } else {
                             $tp[$dag][$time] .= '<span title="' . $myres->value . '">' . $linktext . ' </span>';
                         }
                     }
                     if (isset($multiple) and $multiple > sizeof($reservation[$dag][$time])) {
                         /// $tp[$dag][$time] .= ' ' .$reservation[$dag][$time]->count . ' ';
                         $tp[$dag][$time] .= $canedit ? $baselink . '&rday=' . $dag . '&rslot=' . $time . '">' . get_string('free', 'bookings') . '</a>' : get_string('free', 'bookings');
                     }
                 }
                 $table[] = "<td width=\"{$widthprcent}%\" class=\"{$class}\" >" . $tp[$dag][$time] . "&nbsp;</td>\n";
             }
             $dag++;
         }
         if ($privilege > 0) {
             $table[] = "<td>" . $slotcount[$time] . "&nbsp;</td>\n";
         }
         $table[] = "</tr>\n";
         $idx++;
         $time += 1;
     }
     if ($privilege > 0) {
         $table[] = "<tr><td></td>" . $lastrow . "<td>{$total}</td></tr>";
     }
     $table[] = "</table>\n";
     $html .= implode("", $table);
     $html .= '<input type="hidden" name="itemid" value="' . $itemid . '">';
     $html .= '<input type="hidden" name="jday" value="' . $jday . '">';
     $html .= '</div>';
     // end div=all
     print $html;
     if ($privilege > 0) {
         unset($table);
         $table->head = array('&nbsp;', get_string('name'));
         $table->align = array('center', 'left');
         $table->wrap = array('nowrap', 'nowrap');
         $table->width = '100%';
         $table->size = array(10, '*');
         $table->head[] = get_string('email');
         $table->align[] = 'center';
         $table->wrap[] = 'nowrap';
         $table->size[] = '*';
         $table->head[] = get_string('reservation', 'bookings');
         $table->align[] = 'center';
         $table->wrap[] = 'nowrap';
         $table->size[] = '*';
         $table->head[] = get_string('choice', 'bookings');
         $table->align[] = 'center';
         $table->wrap[] = 'nowrap';
         $table->size[] = '*';
         // $books = get_records('calendar', 'bookingid', $this->bookings->id);
         if ($books = get_records_sql("SELECT r.*, u.firstname, u.lastname, u.picture, u.email\n                                FROM {$CFG->prefix}bookings_calendar r,\n                                    {$CFG->prefix}user u\n                                WHERE r.bookingid = '{$this->bookings->id}' \n                                AND r.userid = u.id ORDER BY r.day,r.slot")) {
             foreach ($books as $request) {
                 $row = array();
                 $row[] = print_user_picture($request->userid, $course->id, $request->picture, 0, true);
                 $row[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $request->userid . '&course=' . $course->id . '">' . $request->lastname . ' ' . $request->firstname . '</a>';
                 $row[] = obfuscate_mailto($request->email);
                 $row[] = $days[$request->day];
                 $row[] = $slots[$request->slot];
                 $table->data[] = $row;
             }
             print "<p>";
             print_table($table);
         }
     }
     print "</form>";
     return;
 }
コード例 #10
0
ファイル: preview.php プロジェクト: veritech/pare-project
if (!($questions = get_records('question', 'id', $id))) {
    error('Could not load question');
}
if ($maxgrade = get_field('quiz_question_instances', 'grade', 'quiz', $quiz->id, 'question', $id)) {
    $questions[$id]->maxgrade = $maxgrade;
} else {
    $questions[$id]->maxgrade = $questions[$id]->defaultgrade;
}
$quiz->id = 0;
// just for safety
$quiz->questions = $id;
if (!($category = get_record("question_categories", "id", $questions[$id]->category))) {
    error("This question doesn't belong to a valid category!");
}
$quiz->course = $category->course;
if (!(has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $category->course)) || $category->publish && isteacherinanycourse())) {
    error("You can't preview these questions!");
}
// Load the question type specific information
if (!get_question_options($questions)) {
    error(get_string('newattemptfail', 'quiz'));
}
// Create a dummy quiz attempt
// TODO: find out what of the following we really need. What is $attempt
//       really used for?
$timenow = time();
$attempt->quiz = $quiz->id;
$attempt->userid = $USER->id;
$attempt->attempt = 0;
$attempt->sumgrades = 0;
$attempt->timestart = $timenow;
コード例 #11
0
 function view_dates()
 {
     global $CFG, $USER;
     $showcombo = optional_param('showcombo', NULL, PARAM_INT);
     $komboroom = optional_param('komboroom', NULL, PARAM_ALPHAEXT);
     $jday = optional_param('jday', NULL, PARAM_INT);
     $subitemid = optional_param('subitemid', NULL, PARAM_INT);
     $tidx = optional_param('tidx', NULL, PARAM_INT);
     $delete = optional_param('delete', NULL, PARAM_INT);
     $edit = optional_param('edit', NULL, PARAM_INT);
     $save = optional_param('save', NULL, PARAM_INT);
     $restore = optional_param('restore', NULL, PARAM_INT);
     $resid = optional_param('resid', NULL, PARAM_INT);
     $uid = optional_param('uid', NULL, PARAM_INT);
     $value = optional_param('value');
     $cmid = $this->cm->id;
     $itemid = $this->bookings->itemid;
     $username = $USER->username;
     // $bookings = get_record('bookings', 'id', $this->bookings->id);
     /// get start and end julian day number
     list($ey, $em, $ed) = explode("/", strftime("%Y/%m/%d", $this->bookings->enddate));
     $ejday = 7 * (int) (gregoriantojd($em, $ed, $ey) / 7);
     list($ey, $em, $ed) = explode("/", strftime("%Y/%m/%d", $this->bookings->startdate));
     $sjday = 7 * (int) (gregoriantojd($em, $ed, $ey) / 7);
     $UID = $USER->id;
     $firstname = $USER->firstname;
     $lastname = $USER->lastname;
     if ($firstname == '' or $lastname == '') {
         return "";
     }
     print '<form name=myform id=myform method=post action="view.php?id=' . $cmid . '">';
     // fetch out data for this item
     $sql = 'SELECT id,name,type,parent
             FROM ' . $CFG->prefix . 'bookings_item i
             WHERE i.parent = ' . $itemid . '
             ORDER BY i.name';
     $idx = 0;
     $main_reservation = array();
     $iteminfo = array();
     $itemid_list = array();
     if (!($childlist = get_records_sql($sql))) {
         $sql = 'SELECT r.id,r.name,r.type,r.parent FROM ' . $CFG->prefix . 'bookings_item r WHERE r.id=' . $itemid;
         $childlist = get_records_sql($sql);
     }
     foreach ($childlist as $child) {
         // build array of props for this item (room)
         $itemid_list[] = $child->id;
         $proplist = bookings_item_properties($child->id);
         if (isset($proplist['image'])) {
             $childlist[$child->id]->image = '<br>' . '<img src="' . $proplist['image'] . '">';
         }
         /// here we fetch out all reservations
         $reservation = array();
         $sql = 'SELECT * FROM ' . $CFG->prefix . 'bookings_calendar 
                 WHERE eventtype="reservation" 
                 AND itemid=' . $child->id . '
                 AND julday >= ' . $sjday . '
                 AND julday <= ' . $ejday;
         if ($res = get_records_sql($sql)) {
             foreach ($res as $re) {
                 $reservation[7 * (int) ($re->julday / 7)] = $re;
             }
         }
         $childlist[$child->id]->proplist = $proplist;
         $main_reservation[$idx] = $reservation;
         $iteminfo[$idx] = $child;
         /// $childlist[$child->id]->reservation = $reservation;
         $idx++;
     }
     /// if there are children, then we must fetch out properties for parent
     /// these props decide if teachers or students can make bookings
     if ($idx > 1) {
         $proplist = bookings_item_properties($itemid);
     }
     // decide if user can edit timetable
     // 0 = view only, 1 = add items, delete/edit own, 2 add/delete/edit any
     $can_edit = isteacherinanycourse($USER->id) ? 1 : 0;
     // default is that teachers can edit
     $link2room = '';
     if (isset($proplist['edit_group'])) {
         $can_edit = 0;
         // default is no edit (that is: edit_group != teacher|student )
         if ($proplist['edit_group'] == 'teachers' and isteacherinanycourse($USER->id)) {
             $can_edit = 1;
             $link2room = ' <a href="itemeditor.php?id=' . $cmid . '&newid=' . $itemid . '">Edit Item</a>';
         } else {
             if ($proplist['edit_group'] == 'students') {
                 $can_edit = 1;
             }
         }
     }
     // intended to give edit-rights to named users
     // these users have admin rights, can delete/edit any booking
     if (isset($proplist['edit_list'])) {
         if (strstr($proplist['edit_list'], $username)) {
             $can_edit = 2;
         }
     }
     if (isadmin()) {
         /// no matter what, admin can edit - even past dates
         $can_edit = 2;
         $link2room = ' <a href="itemeditor.php?id=' . $cmid . '&newid=' . $itemid . '">Edit Item</a>';
     }
     /// this is where we make the reservation or delete reservations
     if (isset($subitemid) and $can_edit) {
         $orig_res = $main_reservation[$tidx][$jday];
         // print_r($orig_res);
         // print "UID = $UID<p>";
         $value = isset($value) ? $value : $username;
         if (isset($edit) and ($can_edit == 2 or $UID == $orig_res->userid)) {
             print "<table><tr><td>";
             print '<script type="text/javascript" src="http://localhost/moodle/lib/editor/htmlarea.php?id=3"></script>
             <script type="text/javascript" src="http://localhost/moodle/lib/editor/lang/en.php"></script>';
             helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
             echo "<br />";
             helpbutton("questions", get_string("helpquestions"), "moodle", true, true);
             echo "<br />";
             if ($usehtmleditor) {
                 helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
             } else {
                 emoticonhelpbutton("form", "description");
             }
             echo "</td><td>";
             print_textarea($usehtmleditor, 20, 60, 680, 400, "value", $orig_res->value);
             if ($usehtmleditor) {
                 echo '<input type="hidden" name="format" value="' . FORMAT_HTML . '" />';
             } else {
                 echo '<div align="right">';
                 helpbutton("textformat", get_string("formattexttype"));
                 print_string("formattexttype");
                 echo ':&nbsp;';
                 if (!$form->format) {
                     $form->format = $defaultformat;
                 }
                 choose_from_menu(format_text_menu(), "format", $form->format, "");
                 echo '</div>';
             }
             print "<script language=\"javascript\" type=\"text/javascript\" defer=\"defer\">\n                var config = new HTMLArea.Config();\n                config.pageStyle = \"body { background-color: #ffffff; font-family: Trebuchet MS,Verdana,Arial,Helvetica,sans-serif; }\";\n                config.killWordOnPaste = true;\n                config.fontname = {\n                \"Trebuchet\":    'Trebuchet MS,Verdana,Arial,Helvetica,sans-serif',\n                \"Arial\":    'arial,helvetica,sans-serif',\n                \"Courier New\":  'courier new,courier,monospace',\n                \"Georgia\":  'georgia,times new roman,times,serif',\n                \"Tahoma\":   'tahoma,arial,helvetica,sans-serif',\n                \"Times New Roman\":  'times new roman,times,serif',\n                \"Verdana\":  'verdana,arial,helvetica,sans-serif',\n                \"Impact\":   'impact',\n                \"Wingdings\":    'wingdings'};\n                HTMLArea.replaceAll(config);\n                </script>";
             print '<input type="submit" name="save" value="save" />';
             print "</td></tr></table>";
             print '<input type="hidden" name="subitemid" value="' . $subitemid . '" />';
             print '<input type="hidden" name="tidx" value="' . $tidx . '" />';
             print '<input type="hidden" name="jday" value="' . $jday . '" />';
             print '<input type="hidden" name="resid" value="' . $resid . '" />';
             print "</form>";
             return;
         }
         if (isset($resid) and ($orig_res->userid == $UID or $can_edit == 2)) {
             $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar 
                     WHERE id=' . $resid;
             execute_sql($sql, 0);
             unset($main_reservation[$tidx][$jday]);
         }
         unset($res);
         if (isset($restore)) {
             $res->start = 0;
             $value = $orig_res->value;
         }
         if (isset($delete) and ($orig_res->userid == $UID or $can_edit == 2)) {
             if ($orig_res->start != -1) {
                 $res->start = -1;
                 $value = $orig_res->value;
                 unset($delete);
             }
         }
         if (!isset($delete)) {
             $res->name = $username;
             $res->value = $value;
             $res->bookingid = $this->bookings->id;
             $res->userid = $UID;
             $res->eventtype = 'reservation';
             $res->itemid = $iteminfo[$tidx]->id;
             $res->julday = $jday;
             if ($returnid = insert_record("bookings_calendar", $res)) {
                 $res->id = $returnid;
                 $main_reservation[$tidx][$jday] = $res;
             }
         }
     }
     $html = $link2room;
     // now we draw up the table
     // print_r($childlist);
     $html .= '<table border=2><tr><th>' . get_string('week') . '</th>';
     foreach ($childlist as $child) {
         $html .= '<th>' . $child->name . ' ' . $child->image . '</th>';
     }
     $html .= '</tr>';
     $count = count($childlist);
     /// $widthprcent = (int)(95 / $count ) ;    // default width
     $julday = $sjday;
     $date = jdtogregorian($julday);
     list($m1, $d1, $y) = explode('/', $date);
     $time = mktime(12, 0, 0, $m1, $d1, $y);
     while ($julday < $ejday) {
         $baselink = '<a href="view.php?id=' . $cmid . '&jday=' . $julday;
         $date = jdtogregorian($julday);
         list($m, $d, $y) = explode('/', $date);
         $date = jdtogregorian($julday + 6);
         list($m1, $d1, $y) = explode('/', $date);
         $monthname = userdate($time, '%b');
         $date = sprintf("%02d.%02d-%02d.%02d", $d, $m, $d1, $m1);
         $html .= "<tr><th><a name=\"jd{$julday}\">" . bookings_week($julday) . "</a><div class='mod-bookings tiny'>{$monthname} {$date}<div></th>";
         for ($idx = 0; $idx < $count; $idx++) {
             if (isset($main_reservation[$idx][$julday])) {
                 $res = $main_reservation[$idx][$julday];
                 $class = 'reserved';
                 if ($can_edit and ($res->userid == $UID or $can_edit == 2)) {
                     // $linktext = $main_reservation[$idx][$julday]->value;
                     $resid = $res->id;
                     $link = $res->value . '<br>';
                     if ($res->start == -1) {
                         $class = 'deleted';
                         $link .= $baselink . '&tidx=' . $idx . '&subitemid=' . $iteminfo[$idx]->id . '&restore=1&resid=' . $resid . '#jd' . $julday . '" title="Restore" ><img src="' . $CFG->pixpath . '/i/restore.gif" ' . ' height="14" width="14" border="0" alt="Restore" /></a> ';
                     } else {
                         $link .= $baselink . '&tidx=' . $idx . '&subitemid=' . $iteminfo[$idx]->id . '&edit=1&resid=' . $resid . '#jd' . $julday . '" title="Edit" ><img src="' . $CFG->pixpath . '/t/edit.gif" ' . ' height="12" width="12" border="0" alt="Edit" /></a> ';
                     }
                     $link .= $baselink . '&tidx=' . $idx . '&subitemid=' . $iteminfo[$idx]->id . '&delete=1&resid=' . $resid . '#jd' . $julday . '" title="Delete" ><img src="' . $CFG->pixpath . '/t/delete.gif" ' . ' height="12" width="12" border="0" alt="Delete" /></a>';
                 } else {
                     $link = get_string('reserved', 'bookings');
                     if ($can_edit) {
                         $link = $res->value;
                     }
                 }
             } else {
                 $linktext = 'free';
                 $class = 'free';
                 $link = $can_edit ? $baselink . '&tidx=' . $idx . '&subitemid=' . $iteminfo[$idx]->id . '#jd' . $julday . '">' . get_string('free', 'bookings') . '</a>' : get_string('free', 'bookings');
             }
             $html .= "<td class='{$class}'>{$link}</td>\n";
         }
         $julday += 7;
         $time += WEEKSECS;
         $html .= "</tr>";
     }
     $html .= "</table>";
     $html .= '<input type="hidden" name="itemid" value="' . $itemid . '">';
     print $html;
     if ($can_edit > 0) {
         unset($table);
         $table->head = array('&nbsp;', get_string('bookedby', 'bookings'));
         $table->align = array('center', 'left');
         $table->wrap = array('nowrap', 'nowrap');
         $table->width = '100%';
         $table->size = array(10, '*');
         $table->head[] = get_string('week');
         $table->align[] = 'center';
         $table->wrap[] = 'nowrap';
         $table->size[] = '*';
         $table->head[] = get_string('date');
         $table->align[] = 'center';
         $table->wrap[] = 'nowrap';
         $table->size[] = '*';
         $table->head[] = get_string('reservation', 'bookings');
         $table->align[] = 'center';
         $table->wrap[] = 'nowrap';
         $table->size[] = '*';
         $table->head[] = get_string('item', 'bookings');
         $table->align[] = 'center';
         $table->wrap[] = 'nowrap';
         $table->size[] = '*';
         // $books = get_records('calendar', 'bookingid', $this->bookings->id);
         $itemid_list = implode(',', $itemid_list);
         /// WHERE r.bookingid = '{$this->bookings->id}'
         if ($books = get_records_sql("SELECT r.*, u.firstname, u.lastname, u.picture, u.email\n                                FROM {$CFG->prefix}bookings_calendar r,\n                                    {$CFG->prefix}user u\n                                WHERE r.itemid in ( {$itemid_list} )\n                                AND r.julday >= {$sjday}\n                                AND r.julday <= {$ejday}\n                                AND r.userid = u.id ORDER BY r.itemid,r.julday")) {
             foreach ($books as $request) {
                 $row = array();
                 $row[] = print_user_picture($request->userid, $course->id, $request->picture, 0, true);
                 $row[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $request->userid . '&course=' . $course->id . '">' . $request->lastname . ' ' . $request->firstname . '</a>';
                 $date = jdtogregorian($request->julday);
                 list($m1, $d1, $y) = explode('/', $date);
                 $time = mktime(12, 0, 0, $m1, $d1, $y);
                 $monthname = userdate($time, '%b');
                 $date = jdtogregorian($request->julday + 6);
                 list($m1, $d1, $y) = explode('/', $date);
                 $date = sprintf("%02d.%02d-%02d.%02d", $d, $m, $d1, $m1);
                 $row[] = get_string('week') . bookings_week($request->julday);
                 $row[] = " {$monthname} " . $date;
                 $row[] = $request->value;
                 $row[] = $childlist[$request->itemid]->name;
                 $table->data[] = $row;
             }
             print "<p>";
             print_table($table);
         }
     }
     print "</form>";
     return;
 }
コード例 #12
0
ファイル: pluginfile.php プロジェクト: ajv/Offline-Caching
         send_file_not_found();
     }
     session_get_instance()->write_close();
     // unlock session during fileserving
     send_stored_file($file, 60 * 60, 0, false);
     // TODO: change timeout?
 } else {
     if ($filearea === 'user_profile') {
         $userid = (int) array_shift($args);
         $usercontext = get_context_instance(CONTEXT_USER, $userid);
         if (!empty($CFG->forceloginforprofiles)) {
             require_login();
             if (isguestuser()) {
                 print_error('noguest');
             }
             if (!isteacherinanycourse() and !isteacherinanycourse($userid) and !has_capability('moodle/user:viewdetails', $usercontext)) {
                 print_error('usernotavailable');
             }
             if (!has_capability('moodle/user:viewdetails', $context) && !has_capability('moodle/user:viewdetails', $usercontext)) {
                 print_error('cannotviewprofile');
             }
             if (!has_capability('moodle/course:view', $context, $userid, false)) {
                 print_error('notenrolledprofile');
             }
             if (groups_get_course_groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
                 print_error('groupnotamember');
             }
         }
         $relativepath = '/' . implode('/', $args);
         $fullpath = $usercontext->id . 'user_profile0' . $relativepath;
         if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
コード例 #13
0
<?php

// $Id: export.php,v 1.11 2009/08/29 05:24:22 bdaloukas Exp $
/**
 * This page edits the bottom text of a game
 * 
 * @author  bdaloukas
 * @version $Id: export.php,v 1.11 2009/08/29 05:24:22 bdaloukas Exp $
 * @package game
 **/
require_once "../../config.php";
require_once "lib.php";
require_once "locallib.php";
require_once "exportjavame.php";
require_once "exporthtml.php";
if (!isteacherinanycourse($USER->id)) {
    error(get_string('only_teachers', 'game'));
}
if (array_key_exists('action', $_POST)) {
    $update = (int) $_POST['update'];
    $gameid = get_field_select("course_modules", "instance", "id={$update}");
    game_OnExport($gameid);
    die;
}
$update = (int) $_GET['update'];
$gameid = get_field_select("course_modules", "instance", "id={$update}");
$_GET['id'] = $update;
require_once "header.php";
echo '<form name="form" method="post" action="export.php">';
$game = get_record_select('game', "id={$gameid}", 'id,name,gamekind');
switch ($_GET['target']) {
コード例 #14
0
 /**
  * Standard block API function for initializing/preparing/changing block settings/variables
  * See block_course_summary.php for a good example
  *
  * @uses $COURSE
  * @uses $SITE
  * @return void
  */
 function specialization()
 {
     //At this point, $this->instance and $this->config are available
     //for use. We can now change the title, etc. to whatever we want. E.g.
     //$this->title = $this->config->variable_holding_the_title
     global $COURSE, $SITE;
     //Cr: $course replaced with $COURSE
     /// Need the bigger course object.
     if ($this->instance->pageid == SITEID) {
         //Cr: if this block appears on the front page which is course id # 1
         //and category # 0 in the course table,
         $this->course = $SITE;
         //start with $SITE which is initialized by get_site() in lib/setup.php
         //which normally returns 1
     } else {
         //Cr: else block appears on a course page, so start with this course
         $this->course = $COURSE;
         //Cr: $course replaced with $COURSE
         //Cr: According to MoodleDocs:Development:Blocks you could also use
         //$this->course = get_record('course', 'id', $this->instance->pageid);
     }
     $this->admin = false;
     //Cr: initialize local variables
     $this->teacher = false;
     $this->mycact = false;
     //Cr: do not show active courses, only for admins
     $this->mycinact = false;
     //Cr: do not show inactive courses, only for admins and teachers
     $this->mycmyc = true;
     //Cr: show myCourses, only for teachers and students
     if (isadmin()) {
         //Cr: admins see ALL courses and may choose to show/hide in the header of the block
         $this->set_admin_options();
         //Cr: to show/hide given courses for admins
         $this->admin = true;
     }
     if (isteacherinanycourse()) {
         //Cr: teachers see ONLY courses they teach in and may choose to show/hide in the header of the block
         $this->set_teacher_options();
         //Cr: to show/hide given courses for teachers
         $this->teacher = true;
         //Cr: changed name of member variable $this->marker to $this->teacher
         //to better reflect admin and teacher options
     }
     //Cr: we no longer use the next line because it is recommended to use only one title for the block.
     //We load it already in the init() function. If you need a more dynamic title it could be set here.
     //$this->title = get_string('displaytitle', 'block_myCourses');
 }
コード例 #15
0
ファイル: lib.php プロジェクト: nadavkav/MoodleTAO
function fm_get_user_int_type()
{
    $systemcontext = get_context_instance(CONTEXT_SYSTEM, 0);
    if (has_capability('moodle/site:doanything', $systemcontext)) {
        $usertype = 0;
    } else {
        if (isteacherinanycourse('0', false)) {
            $usertype = 1;
        } else {
            $usertype = 2;
        }
    }
    return $usertype;
}
コード例 #16
0
 function view_dates()
 {
     global $CFG, $USER;
     $showcombo = optional_param('showcombo', NULL, PARAM_INT);
     $komboroom = optional_param('komboroom', NULL, PARAM_ALPHAEXT);
     $prev = optional_param('prev', NULL, PARAM_ALPHAEXT);
     $next = optional_param('next', NULL, PARAM_ALPHAEXT);
     $jday = optional_param('jday', NULL, PARAM_INT);
     $rday = optional_param('rday', NULL, PARAM_INT);
     $rslot = optional_param('rslot', NULL, PARAM_INT);
     $delete = optional_param('delete', NULL, PARAM_INT);
     $resid = optional_param('resid', NULL, PARAM_INT);
     $uid = optional_param('uid', NULL, PARAM_INT);
     require_once "../../config.php";
     $cmid = $this->cm->id;
     /// require_once($CFG->dirroot.'/blocks/timetable/locallib.php');
     $itemid = $this->bookings->itemid;
     $username = $USER->username;
     $UID = $USER->id;
     $firstname = $USER->firstname;
     $lastname = $USER->lastname;
     ///$prover = mineprover();
     ///$fridager = Fridager();
     if ($firstname == '' or $lastname == '') {
         return "";
     }
     $html .= '<form name=myform id=myform method=post action="view.php?id=' . $cmid . '">';
     //// show combo is used if we don't already know which room/item is to be scheduled
     if (isset($showcombo)) {
         if (isset($komboroom)) {
             $itemid = $komboroom;
         }
         $sql = 'SELECT r.id, r.name
                 FROM ' . $CFG->prefix . 'bookings_item r,
                     ' . $CFG->prefix . 'bookings_item_property p
                 WHERE p.itemid = r.id
                     AND p.name="scheduled"
                     AND p.value="yes"
                 ORDER BY r.name';
         if ($roomlist = get_records_sql($sql)) {
             $kombo = "<select name=\"komboroom\" onchange=\"document.myform.reload.click()\">";
             $kombo .= "<option value=\" \"> -- Select -- </option>\n ";
             foreach ($roomlist as $room) {
                 $selected = "";
                 if ($room->id == $itemid) {
                     $selected = "selected";
                     $rname = $room->name;
                 }
                 $kombo .= '<option value="' . $room->id . '" ' . $selected . '>' . $room->name . '</option>' . "\n ";
             }
             $kombo .= '</select>' . "\n";
         }
         $html .= $kombo;
         $html .= '<input id="reload" type="submit" name="reload">';
         $html .= '<input type="hidden" name="showcombo" value="yes">';
     }
     ///////////////////////////
     // fetch out any timetable-data for this item
     $sql = 'SELECT r.id,r.name,r.type FROM ' . $CFG->prefix . 'bookings_item r WHERE r.id=' . $itemid;
     $r = get_record_sql($sql);
     $sql = "SELECT concat(c.id,t.day,t.slot),c.id,c.shortname, r.type, r.name, t.day, t.slot  \n                    FROM {$CFG->prefix}bookings_calendar t,\n                        {$CFG->prefix}bookings_item r left join\n                        {$CFG->prefix}course c  on c.id = t.courseid\n                WHERE r.id={$itemid}\n                    AND t.eventtype = 'timetable'\n                    AND r.id = t.itemid\n                ORDER BY day,slot";
     $tp = array();
     if ($tplan = get_records_sql($sql)) {
         foreach ($tplan as $tpelm) {
             $shortshortname = $tpelm->shortname;
             $tp[$tpelm->day][$tpelm->slot] = "<a href=\"/moodle/course/view.php?id={$tpelm->id}\">{$shortshortname}</a>";
         }
     }
     // build array of props for this item (room)
     $proplist = bookings_item_properties($itemid);
     $days = explode(',', 'Mon,Tue,Wed,Thu,Fri,,');
     if (isset($proplist['days'])) {
         $days = explode(',', $proplist['days']);
     }
     $widthprcent = (int) (95 / count($days));
     // default width
     $slots = array(8, 9, 10, 11, 12, 13, 14, 15, 16);
     if (isset($proplist['slots'])) {
         $slots = explode(',', $proplist['slots']);
     }
     $lookahead = 700;
     // limit on number of weeks you can move from present week (100 weeks +/-)
     if (isset($proplist['lookahead'])) {
         $lookahead = 7 * (int) $proplist['lookahead'];
     }
     // decide if user can edit timetable
     $can_edit = isteacherinanycourse($USER->id) ? 1 : 0;
     // default is that teachers can edit
     $link2room = '';
     if (isset($proplist['edit_group'])) {
         $can_edit = 0;
         // default is no edit (that is: edit_group != teacher|student )
         if ($proplist['edit_group'] == 'teachers' and isteacherinanycourse($USER->id)) {
             $can_edit = 1;
             $link2room = ' <a href="itemeditor.php?id=' . $cmid . '&newid=' . $itemid . '">' . get_string('edit') . ' ' . $r->type . '</a>';
         } else {
             if ($proplist['edit_group'] == 'students') {
                 $can_edit = 1;
             }
         }
     }
     // intended to give edit-rights to named students
     if (isset($proplist['edit_list'])) {
         if (strstr($proplist['edit_list'], $username)) {
             $can_edit = 1;
         }
     }
     // a multiple resource has a property that is counted down on each reservation
     // so long as number of resevations is less than this values, then user can make a
     // reservation
     if (isset($proplist['multiple'])) {
         $multiple = (int) $proplist['multiple'];
     }
     // calculate week and day
     list($ty, $tm, $td) = explode("/", strftime("%Y/%m/%d", time()));
     $tjday = gregoriantojd($tm, $td, $ty);
     $tweek = bookings_week($tjday);
     if (!isset($jday)) {
         $jday = $tjday;
     }
     // a list of days that isn't a week (7 days) or doesn't start on the first day of the week
     // should have this property, otherwise the schedule wont tile over the year
     list($ys, $ms, $ds) = explode(',', $proplist['startsched']);
     $start = gregoriantojd($ms, $ds, $ys) or 0;
     $jday = $start + sizeof($days) * (int) (($jday - $start) / sizeof($days));
     // $jday = 7 * (int)($jday/7);
     if (isset($prev) and $jday > $tjday - $lookahead) {
         $jday -= sizeof($days);
     }
     if (isset($next) and $jday < $tjday + $lookahead - 7) {
         $jday += sizeof($days);
     }
     list($ey, $em, $ed) = explode("/", strftime("%Y/%m/%d", $this->bookings->enddate));
     $ejday = gregoriantojd($em, $ed, $ey);
     if ($jday > $ejday) {
         $can_edit = 0;
     }
     if ($jday + sizeof($days) < $tjday) {
         $can_edit = 0;
     }
     if (isadmin()) {
         /// no matter what, admin can edit - even past dates
         $can_edit = 1;
         $link2room = ' <a href="itemeditor.php?id=' . $cmid . '&newid=' . $itemid . '">' . get_string('edit') . ' ' . $r->type . '</a>';
     }
     /// here we fetch out all reservations
     // list($m,$d,$y) = explode('/',jdtogregorian($jday));
     // $start = gmmktime(0, 0, 0, $m, $d, $y);
     // $stop = $start + 604800;   // weekofseconds
     $sql = 'SELECT * FROM ' . $CFG->prefix . 'bookings_calendar 
             WHERE eventtype="reservation" 
             AND itemid=' . $r->id . '
             AND julday >= ' . $jday . '
             AND julday <= ' . ($jday + sizeof($days) - 1);
     $reservation = array();
     if ($res = get_records_sql($sql)) {
         foreach ($res as $re) {
             $reservation[$re->day][$re->slot][] = $re;
             if ($res->userid == $UID) {
                 $reservation[$re->day][$re->slot]->res = $re;
             }
         }
     }
     /// this is where we make the reservation or delete reservations
     if ((isset($resid) and isset($uid) or isset($rday) and isset($rslot)) and $can_edit) {
         if (!isteacherinanycourse($USER->id) and !isadmin() and isset($reservation[$rday][$rslot])) {
             if ($uid != $UID) {
                 // return;  // assume an attempt to phreak the system with params
             }
         }
         $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar WHERE eventtype="reservation" AND slot=' . $rslot . ' AND day=' . $rday . ' AND julday=' . ($jday + $rday) . '
                     AND userid=' . $UID . ' AND itemid=' . $r->id;
         execute_sql($sql, 0);
         /// this removes multiple bookings by one person for a given slot
         if (isset($resid)) {
             $sql = 'DELETE FROM ' . $CFG->prefix . 'bookings_calendar WHERE id=' . $resid;
             execute_sql($sql, 0);
         }
         if (!isset($delete)) {
             $sql = 'INSERT INTO ' . $CFG->prefix . 'bookings_calendar (name,value,userid,eventtype,itemid,slot,day,julday) 
                 VALUES ("' . $r->name . '","' . $username . '",' . $UID . ',"reservation",' . $r->id . ',' . $rslot . ',' . $rday . ',' . ($jday + $rday) . ')';
             execute_sql($sql, 0);
         }
         // have to refetch data
         $sql = 'SELECT * FROM ' . $CFG->prefix . 'bookings_calendar 
             WHERE eventtype="reservation" 
             AND itemid=' . $r->id . '
             AND julday >= ' . $jday . '
             AND julday <= ' . ($jday + sizeof($days) - 1);
         $reservation = array();
         if ($res = get_records_sql($sql)) {
             foreach ($res as $re) {
                 $reservation[$re->day][$re->slot][] = $re;
             }
         }
     }
     // navigation (next/prev) week
     $week = bookings_week($jday);
     list($m, $d, $y) = explode("/", jdtogregorian($jday));
     list($m1, $d1, $y1) = explode("/", jdtogregorian($jday + sizeof($days) - 1));
     if (bookings_week($jday + sizeof($days) - 1) != $week) {
         $week .= '-' . bookings_week($jday + sizeof($days) - 1);
     }
     $html .= '<div id="all"><h2>' . $r->name . ' (' . $r->type . ')</h2>';
     $html .= '<div class="mod-bookings navigate" ><input type="submit"  name="prev" value="&lt;&lt;">';
     $html .= get_string('week') . " {$week} &nbsp; <span id=\"date\">{$d}.{$m} - {$d1}.{$m1} {$y}</span>";
     $html .= '<input type="submit" name="next" value="&gt;&gt;"></div>';
     $html .= $link2room;
     // now we draw up the table
     $table = array();
     if ($can_edit) {
         $baselink = '<a href="view.php?id=' . $cmid . '&jday=' . $jday . '&itemid=' . $itemid;
     } else {
         $baselink = '';
     }
     $table[] = '<table border=1 width=100%>';
     $table[] = '<tr><th width=5%>&nbsp;</th>';
     foreach ($days as $day) {
         if ($day == '') {
             continue;
         }
         $table[] = '<th>' . $day . '</th>';
     }
     $table[] = '</tr>';
     $time = 0;
     foreach ($slots as $slottime) {
         $t = $time + 1;
         $table[] = "<tr><th><span class=\"number\">{$slottime}</span></th>";
         $dag = 0;
         foreach ($days as $day) {
             $class = 'normal';
             if ($day != '') {
                 if ($tp[$dag][$time] == '') {
                     $class = 'free';
                     $tp[$dag][$time] = $can_edit ? $baselink . '&rday=' . $dag . '&rslot=' . $time . '">' . get_string('free', 'bookings') . '</a>' : get_string('free', 'bookings');
                 }
                 if (isset($reservation[$dag][$time])) {
                     $tp[$dag][$time] = '';
                     foreach ($reservation[$dag][$time] as $myres) {
                         $class = 'reserved';
                         $linktext = 'Reserved ' . $myres->value;
                         if ($myres->userid == $UID) {
                             $linktext = 'M';
                         } else {
                             if (sizeof($reservation[$dag][$time] > 1)) {
                                 $linktext = isteacherinanycourse($myres->userid) ? 'T' : 'S';
                             }
                         }
                         // admin can override any, teacher can override student
                         if ($myres->userid == $UID or isadmin() or isteacherinanycourse($USER->id) and !isteacherinanycourse($myres->userid)) {
                             $tp[$dag][$time] .= $can_edit ? $baselink . '&delete=1&resid=' . $myres->id . '&uid=' . $myres->userid . '"
                         title="' . $myres->value . '" >' . $linktext . '</a> ' : $linktext . $myres->value;
                         } else {
                             $tp[$dag][$time] .= '<span title="' . $myres->value . '">' . $linktext . ' </span>';
                         }
                     }
                     if (isset($multiple) and $multiple > sizeof($reservation[$dag][$time])) {
                         $tp[$dag][$time] .= ' ' . $reservation[$dag][$time]->count . ' ';
                         $tp[$dag][$time] .= $can_edit ? $baselink . '&rday=' . $dag . '&rslot=' . $time . '">' . get_string('free', 'bookings') . '</a>' : get_string('free', 'bookings');
                     }
                 }
                 $table[] = "<td width=\"{$widthprcent}%\" class=\"{$class}\" >" . $tp[$dag][$time] . "&nbsp;</td>\n";
             }
             $dag++;
         }
         $table[] = "</tr>\n";
         $idx++;
         $time += 1;
     }
     $table[] = "</table>\n";
     $html .= implode("", $table);
     $html .= '<input type="hidden" name="itemid" value="' . $itemid . '">';
     $html .= '<input type="hidden" name="jday" value="' . $jday . '">';
     $html .= '</div>';
     // end div=all
     print $html;
     print "</form>";
     return;
 }
コード例 #17
0
<?php

// $Id: enrol.php,v 1.50.2.1 2008/03/03 05:27:36 moodler Exp $
// Depending on the current enrolment method, this page
// presents the user with whatever they need to know when
// they try to enrol in a course.
require_once "../config.php";
require_once "lib.php";
require_once "{$CFG->dirroot}/enrol/enrol.class.php";
if (isloggedin() and !isguest()) {
    if (!iscreator() and !isteacherinanycourse()) {
        redirect($CFG->wwwroot . '/index.php');
    }
} else {
    redirect($CFG->wwwroot . '/index.php');
}
$id = required_param('id', PARAM_INT);
// Masoud Sadjadi: PARAM_ALPHANUM changed to PARAM_RAW to support emails being passed as user names.
// $username     = required_param('username', PARAM_ALPHANUM);
$username = required_param('username', PARAM_RAW);
$loginasguest = optional_param('loginasguest', 0, PARAM_BOOL);
// hmm, is this still needed?
if (!isloggedin()) {
    // do not use require_login here because we are usually comming from it
    redirect(get_login_url());
}
if (!($course = get_record('course', 'id', $id))) {
    print_error("That's an invalid course id");
}
if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
    print_error("That's an invalid course id");
コード例 #18
0
    // default is that teachers can edit
}
$roomid = NULL;
if (isset($komboroom)) {
    $roomid = $komboroom;
    // build array of props for this item (room)
    $proplist = array();
    $sql = 'SELECT p.id,p.name,p.value FROM ' . $CFG->prefix . 'bookings_item_property p WHERE p.itemid=' . $roomid;
    if ($p = get_records_sql($sql)) {
        foreach ($p as $prop) {
            $proplist[$prop->name] = $prop->value;
        }
    }
    if (isset($proplist['edit_group'])) {
        // $can_edit = 0;   // default is no edit (that is: edit_group != teacher|student )
        if ($proplist['edit_group'] == 'teacher' and isteacherinanycourse($USER->id)) {
            $can_edit = 1;
        } else {
            if ($proplist['edit_group'] == 'student') {
                $can_edit = 1;
            }
        }
    }
    if (isset($proplist['edit_list'])) {
        if (strstr($proplist['edit_list'], $username)) {
            $can_edit = 1;
        }
    }
}
if (isset($new)) {
    $item->name = 'ChangeMe';
コード例 #19
0
 /**
  *
  */
 function fm_get_user_int_type()
 {
     $systemcontext = get_context_instance(CONTEXT_SYSTEM, 0);
     $isadmin = has_capability('moodle/site:doanything', $systemcontext);
     if ($isadmin) {
         return 0;
     } else {
         if (isteacherinanycourse('0', false)) {
             return 1;
         } else {
             return 2;
         }
     }
 }
コード例 #20
0
ファイル: user.php プロジェクト: edwinphillips/moodle-485cb39
        $searchcourse = 0;
    } else {
        $searchcourse = SITEID;
    }
} else {
    // Search only for posts the user made in this course.
    $searchcourse = $course->id;
}
$posts = forum_search_posts($searchterms, $searchcourse, $page * $perpage, $perpage, $totalcount, $extrasql);
$hasposts = !empty($posts);
$iscurrentuser = $user->id == $USER->id;
$specificcourseprovided = !empty($searchcourse) && $searchcourse != SITEID;
if (!$hasposts && !$iscurrentuser && !$specificcourseprovided) {
    $mustlogin = !isloggedin() && $CFG->forceloginforprofiles;
    $canviewtheuser = isloggedin() && has_capability('moodle/user:viewdetails', $usercontext);
    if ($mustlogin || !isteacherinanycourse() && !isteacherinanycourse($user->id) && !$canviewtheuser) {
        // Best to assume that the current user cannot view the requested user
        // so we are careful not to give out any information.
        print_header();
        print_heading(get_string('noposts', 'forum'));
        print_footer();
        exit;
    } else {
        // Nothing to check here. If a course has been specified then require_course_login
        // has been called OR the current user is a parent of the requested user.
    }
}
add_to_log($course->id, "forum", "user report", "user.php?course={$course->id}&amp;id={$user->id}&amp;mode={$mode}", "{$user->id}");
$strforumposts = get_string('forumposts', 'forum');
$strparticipants = get_string('participants');
$strmode = get_string($mode, 'forum');