/** * Function that can be used in various parts of the quiz code. * @param object $quiz * @param integer $cmid * @param object $question * @param string $returnurl url to return to after action is done. * @return string html for a number of icons linked to action pages for a * question - preview and edit / view icons depending on user capabilities. */ function qcreate_question_action_icons($cmid, $question, $returnurl) { global $CFG, $COURSE; static $stredit = null; static $strview = null; static $strpreview = null; static $strdelete = null; if ($stredit === null) { $stredit = get_string('edit'); $strview = get_string('view'); $strpreview = get_string('preview', 'quiz'); $strdelete = get_string("delete"); } $html = ''; if ($question->qtype != 'random') { if (question_has_capability_on($question, 'use', $question->cid)) { $html .= link_to_popup_window('/question/preview.php?id=' . $question->id . '&courseid=' . $COURSE->id, 'questionpreview', "<img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strpreview}\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS, true); } } $questionparams = array('returnurl' => $returnurl, 'cmid' => $cmid, 'id' => $question->id); $questionurl = new moodle_url("{$CFG->wwwroot}/question/question.php", $questionparams); if (question_has_capability_on($question, 'edit', $question->cid) || question_has_capability_on($question, 'move', $question->cid)) { $html .= "<a title=\"{$stredit}\" href=\"" . $questionurl->out() . "\">" . "<img src=\"{$CFG->pixpath}/t/edit.gif\" class=\"iconsmall\" alt=\"{$stredit}\" />" . "</a>"; } elseif (question_has_capability_on($question, 'view', $question->cid)) { $html .= "<a title=\"{$strview}\" href=\"" . $questionurl->out(false, array('id' => $question->id)) . "\">" . "<img src=\"{$CFG->pixpath}/i/info.gif\" alt=\"{$strview}\" />" . "</a>"; } if (question_has_capability_on($question, 'edit', $question->cid)) { $html .= "<a title=\"{$strdelete}\" href=\"" . $returnurl . "&delete={$question->id}\">" . "<img src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"{$strdelete}\" /></a>"; } return $html; }
function print_question(&$question, &$state, $number, $cmoptions, $options) { global $CFG; $isfinished = question_state_is_graded($state->last_graded) || $state->event == QUESTION_EVENTCLOSE; if (!empty($cmoptions->id)) { $cm = get_coursemodule_from_instance('quiz', $cmoptions->id); $cmorcourseid = '&cmid=' . $cm->id; } else { if (!empty($cmoptions->course)) { $cmorcourseid = '&courseid=' . $cmoptions->course; } else { error('Need to provide courseid or cmid to print_question.'); } } // For editing teachers print a link to an editing popup window $editlink = ''; if (question_has_capability_on($question, 'edit')) { $stredit = get_string('edit'); $linktext = '<img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . $stredit . '" />'; $editlink = link_to_popup_window('/question/question.php?id=' . $question->id . $cmorcourseid, $stredit, $linktext, 450, 550, $stredit, '', true); } $questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions); $image = get_question_image($question); $generalfeedback = ''; if ($isfinished && $options->generalfeedback) { $generalfeedback = $this->format_text($question->generalfeedback, $question->questiontextformat, $cmoptions); } include "{$CFG->dirroot}/question/type/description/question.html"; }
function block_exabis_eportfolio_print_extern_item($item, $access) { global $CFG; print_heading(format_string($item->name)); $box_content = ''; if ($item->type == 'link') { $link = clean_param($item->url, PARAM_URL); $link_js = str_replace('http://', '', $link); if ($link) { $box_content .= '<p><a href="#" onclick="window.open(\'http://' . addslashes_js($link_js) . '\',\'validate\',\'width=620,height=450,scrollbars=yes,status=yes,resizable=yes,menubar=yes,location=yes\');return true;">' . $link . '</a></p>'; } } elseif ($item->type == 'file') { if ($item->attachment) { $type = mimeinfo("type", $item->attachment); $ffurl = "{$CFG->wwwroot}/blocks/exabis_eportfolio/portfoliofile.php?access=" . $access . "&itemid=" . $item->id; if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links $box_content .= "<img width=\"100%\" src=\"{$ffurl}\" alt=\"" . format_string($item->name) . "\" /><br/>"; } else { $box_content .= "<p>" . link_to_popup_window("{$ffurl}", 'popup', "{$ffurl}", $height = 400, $width = 500, format_string($item->name), 'none', true) . "</p>"; } } } $box_content .= format_text($item->intro, FORMAT_HTML); print_box($box_content); }
function print_question(&$question, &$state, $number, $cmoptions, $options) { global $CFG; $isfinished = question_state_is_graded($state->last_graded) || $state->event == QUESTION_EVENTCLOSE; // For editing teachers print a link to an editing popup window $editlink = ''; if (has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $cmoptions->course))) { $stredit = get_string('edit'); $linktext = '<img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . $stredit . '" />'; $editlink = link_to_popup_window('/question/question.php?id=' . $question->id, $stredit, $linktext, 450, 550, $stredit, '', true); } $questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions); $image = get_question_image($question, $cmoptions->course); $generalfeedback = ''; if ($isfinished && $options->generalfeedback) { $generalfeedback = $this->format_text($question->generalfeedback, $question->questiontextformat, $cmoptions); } include "{$CFG->dirroot}/question/type/description/question.html"; }
function display($quiz, $cm, $course) { /// This function just displays the report global $CFG, $SESSION, $db, $QTYPES; $strnoquiz = get_string('noquiz', 'quiz'); $strnoattempts = get_string('noattempts', 'quiz'); /// Only print headers if not asked to download data $download = optional_param('download', NULL); if (!$download) { $this->print_header_and_tabs($cm, $course, $quiz, $reportmode = "analysis"); } /// Construct the table for this particular report if (!$quiz->questions) { print_heading($strnoattempts); return true; } /// Check to see if groups are being used in this quiz if ($groupmode = groupmode($course, $cm)) { // Groups are being used if (!$download) { $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&mode=analysis"); } else { $currentgroup = get_and_set_current_group($course, $groupmode); } } else { $currentgroup = get_and_set_current_group($course, $groupmode); } // set Table and Analysis stats options if (!isset($SESSION->quiz_analysis_table)) { $SESSION->quiz_analysis_table = array('attemptselection' => 0, 'lowmarklimit' => 0, 'pagesize' => 10); } foreach ($SESSION->quiz_analysis_table as $option => $value) { $urlparam = optional_param($option, NULL); if ($urlparam === NULL) { ${$option} = $value; } else { ${$option} = $SESSION->quiz_analysis_table[$option] = $urlparam; } } $scorelimit = $quiz->sumgrades * $lowmarklimit / 100; // ULPGC ecastro DEBUG this is here to allow for different SQL to select attempts switch ($attemptselection) { case QUIZ_ALLATTEMPTS: $limit = ''; $group = ''; break; case QUIZ_HIGHESTATTEMPT: $limit = ', max(qa.sumgrades) '; $group = ' GROUP BY qa.userid '; break; case QUIZ_FIRSTATTEMPT: $limit = ', min(qa.timemodified) '; $group = ' GROUP BY qa.userid '; break; case QUIZ_LASTATTEMPT: $limit = ', max(qa.timemodified) '; $group = ' GROUP BY qa.userid '; break; } if ($attemptselection != QUIZ_ALLATTEMPTS) { $sql = 'SELECT qa.userid ' . $limit . 'FROM ' . $CFG->prefix . 'user u LEFT JOIN ' . $CFG->prefix . 'quiz_attempts qa ON u.id = qa.userid ' . 'WHERE qa.quiz = ' . $quiz->id . ' AND qa.preview = 0 ' . $group; $usermax = get_records_sql_menu($sql); } $groupmembers = ''; $groupwhere = ''; //Add this to the SQL to show only group users if ($currentgroup) { $groupmembers = ', ' . groups_members_from_sql(); $groupwhere = ' AND ' . groups_members_where_sql($currentgroup, 'u.id'); } $sql = 'SELECT qa.* FROM ' . $CFG->prefix . 'quiz_attempts qa, ' . $CFG->prefix . 'user u ' . $groupmembers . 'WHERE u.id = qa.userid AND qa.quiz = ' . $quiz->id . ' AND qa.preview = 0 AND ( qa.sumgrades >= ' . $scorelimit . ' ) ' . $groupwhere; // ^^^^^^ es posible seleccionar aqu TODOS los quizzes, como quiere Jussi, // pero habra que llevar la cuenta ed cada quiz para restaura las preguntas (quizquestions, states) /// Fetch the attempts $attempts = get_records_sql($sql); if (empty($attempts)) { print_heading(get_string('nothingtodisplay')); $this->print_options_form($quiz, $cm, $attemptselection, $lowmarklimit, $pagesize); return true; } /// Here we rewiew all attempts and record data to construct the table $questions = array(); $statstable = array(); $questionarray = array(); foreach ($attempts as $attempt) { $questionarray[] = quiz_questions_in_quiz($attempt->layout); } $questionlist = quiz_questions_in_quiz(implode(",", $questionarray)); $questionarray = array_unique(explode(",", $questionlist)); $questionlist = implode(",", $questionarray); unset($questionarray); foreach ($attempts as $attempt) { switch ($attemptselection) { case QUIZ_ALLATTEMPTS: $userscore = 0; // can be anything, not used break; case QUIZ_HIGHESTATTEMPT: $userscore = $attempt->sumgrades; break; case QUIZ_FIRSTATTEMPT: $userscore = $attempt->timemodified; break; case QUIZ_LASTATTEMPT: $userscore = $attempt->timemodified; break; } if ($attemptselection == QUIZ_ALLATTEMPTS || $userscore == $usermax[$attempt->userid]) { $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance" . " FROM {$CFG->prefix}question q," . " {$CFG->prefix}quiz_question_instances i" . " WHERE i.quiz = '{$quiz->id}' AND q.id = i.question" . " AND q.id IN ({$questionlist})"; if (!($quizquestions = get_records_sql($sql))) { error('No questions found'); } // Load the question type specific information if (!get_question_options($quizquestions)) { error('Could not load question options'); } // Restore the question sessions to their most recent states // creating new sessions where required if (!($states = get_question_states($quizquestions, $quiz, $attempt))) { error('Could not restore question sessions'); } $numbers = explode(',', $questionlist); $statsrow = array(); foreach ($numbers as $i) { if (!isset($quizquestions[$i]) or !isset($states[$i])) { continue; } $qtype = $quizquestions[$i]->qtype == 'random' ? $states[$i]->options->question->qtype : $quizquestions[$i]->qtype; $q = get_question_responses($quizquestions[$i], $states[$i]); if (empty($q)) { continue; } $qid = $q->id; if (!isset($questions[$qid])) { $questions[$qid]['id'] = $qid; $questions[$qid]['qname'] = $quizquestions[$i]->name; foreach ($q->responses as $answer => $r) { $r->count = 0; $questions[$qid]['responses'][$answer] = $r->answer; $questions[$qid]['rcounts'][$answer] = 0; $questions[$qid]['credits'][$answer] = $r->credit; $statsrow[$qid] = 0; } } $responses = get_question_actual_response($quizquestions[$i], $states[$i]); foreach ($responses as $resp) { if ($resp) { if ($key = array_search($resp, $questions[$qid]['responses'])) { $questions[$qid]['rcounts'][$key]++; } else { $test = new stdClass(); $test->responses = $QTYPES[$quizquestions[$i]->qtype]->get_correct_responses($quizquestions[$i], $states[$i]); if ($key = $QTYPES[$quizquestions[$i]->qtype]->check_response($quizquestions[$i], $states[$i], $test)) { $questions[$qid]['rcounts'][$key]++; } else { $questions[$qid]['responses'][] = $resp; $questions[$qid]['rcounts'][] = 1; $questions[$qid]['credits'][] = 0; } } } } $statsrow[$qid] = get_question_fraction_grade($quizquestions[$i], $states[$i]); } $attemptscores[$attempt->id] = $attempt->sumgrades; $statstable[$attempt->id] = $statsrow; } } // Statistics Data table built unset($attempts); unset($quizquestions); unset($states); // now calculate statistics and set the values in the $questions array $top = max($attemptscores); $bottom = min($attemptscores); $gap = ($top - $bottom) / 3; $top -= $gap; $bottom += $gap; foreach ($questions as $qid => $q) { $questions[$qid] = $this->report_question_stats($q, $attemptscores, $statstable, $top, $bottom); } unset($attemptscores); unset($statstable); /// Now check if asked download of data if ($download = optional_param('download', NULL)) { $filename = clean_filename("{$course->shortname} " . format_string($quiz->name, true)); switch ($download) { case "Excel": $this->Export_Excel($questions, $filename); break; case "ODS": $this->Export_ODS($questions, $filename); break; case "CSV": $this->Export_CSV($questions, $filename); break; } } /// Construct the table for this particular report $tablecolumns = array('id', 'qname', 'responses', 'credits', 'rcounts', 'rpercent', 'facility', 'qsd', 'disc_index', 'disc_coeff'); $tableheaders = array(get_string('qidtitle', 'quiz_analysis'), get_string('qtexttitle', 'quiz_analysis'), get_string('responsestitle', 'quiz_analysis'), get_string('rfractiontitle', 'quiz_analysis'), get_string('rcounttitle', 'quiz_analysis'), get_string('rpercenttitle', 'quiz_analysis'), get_string('facilitytitle', 'quiz_analysis'), get_string('stddevtitle', 'quiz_analysis'), get_string('dicsindextitle', 'quiz_analysis'), get_string('disccoefftitle', 'quiz_analysis')); $table = new flexible_table('mod-quiz-report-itemanalysis'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/quiz/report.php?q=' . $quiz->id . '&mode=analysis'); $table->sortable(true); $table->no_sorting('rpercent'); $table->collapsible(true); $table->initialbars(false); $table->column_class('id', 'numcol'); $table->column_class('credits', 'numcol'); $table->column_class('rcounts', 'numcol'); $table->column_class('rpercent', 'numcol'); $table->column_class('facility', 'numcol'); $table->column_class('qsd', 'numcol'); $table->column_class('disc_index', 'numcol'); $table->column_class('disc_coeff', 'numcol'); $table->column_suppress('id'); $table->column_suppress('qname'); $table->column_suppress('facility'); $table->column_suppress('qsd'); $table->column_suppress('disc_index'); $table->column_suppress('disc_coeff'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'itemanalysis'); $table->set_attribute('class', 'generaltable generalbox'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); $tablesort = $table->get_sql_sort(); $sorts = explode(",", trim($tablesort)); if ($tablesort and is_array($sorts)) { $sortindex = array(); $sortorder = array(); foreach ($sorts as $sort) { $data = explode(" ", trim($sort)); $sortindex[] = trim($data[0]); $s = trim($data[1]); if ($s == "ASC") { $sortorder[] = SORT_ASC; } else { $sortorder[] = SORT_DESC; } } if (count($sortindex) > 0) { $sortindex[] = "id"; $sortorder[] = SORT_ASC; foreach ($questions as $qid => $row) { $index1[$qid] = $row[$sortindex[0]]; $index2[$qid] = $row[$sortindex[1]]; } array_multisort($index1, $sortorder[0], $index2, $sortorder[1], $questions); } } $format_options = new stdClass(); $format_options->para = false; $format_options->noclean = true; $format_options->newlines = false; // Now it is time to page the data, simply slice the keys in the array if (!isset($pagesize) || (int) $pagesize < 1) { $pagesize = 10; } $table->pagesize($pagesize, count($questions)); $start = $table->get_page_start(); $pagequestions = array_slice(array_keys($questions), $start, $pagesize); foreach ($pagequestions as $qnum) { $q = $questions[$qnum]; $qid = $q['id']; $question = get_record('question', 'id', $qid); if (has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $course->id))) { $qnumber = " (" . link_to_popup_window('/question/question.php?id=' . $qid, '&cmid=' . $cm->id . 'editquestion', $qid, 450, 550, get_string('edit'), 'none', true) . ") "; } else { $qnumber = $qid; } $qname = '<div class="qname">' . format_text($question->name . " : ", $question->questiontextformat, $format_options, $quiz->course) . '</div>'; $qicon = print_question_icon($question, true); $qreview = quiz_question_preview_button($quiz, $question); $qtext = format_text($question->questiontext, $question->questiontextformat, $format_options, $quiz->course); $qquestion = $qname . "\n" . $qtext . "\n"; $responses = array(); foreach ($q['responses'] as $aid => $resp) { $response = new stdClass(); if ($q['credits'][$aid] <= 0) { $qclass = 'uncorrect'; } elseif ($q['credits'][$aid] == 1) { $qclass = 'correct'; } else { $qclass = 'partialcorrect'; } $response->credit = '<span class="' . $qclass . '">(' . format_float($q['credits'][$aid], 2) . ') </span>'; $response->text = '<span class="' . $qclass . '">' . format_text($resp, FORMAT_MOODLE, $format_options, $quiz->course) . ' </span>'; $count = $q['rcounts'][$aid] . '/' . $q['count']; $response->rcount = $count; $response->rpercent = '(' . format_float($q['rcounts'][$aid] / $q['count'] * 100, 0) . '%)'; $responses[] = $response; } $facility = format_float($q['facility'] * 100, 0) . "%"; $qsd = format_float($q['qsd'], 3); $di = format_float($q['disc_index'], 2); $dc = format_float($q['disc_coeff'], 2); $response = array_shift($responses); $table->add_data(array($qnumber . "\n<br />" . $qicon . "\n " . $qreview, $qquestion, $response->text, $response->credit, $response->rcount, $response->rpercent, $facility, $qsd, $di, $dc)); foreach ($responses as $response) { $table->add_data(array('', '', $response->text, $response->credit, $response->rcount, $response->rpercent, '', '', '', '')); } } print_heading_with_help(get_string("analysistitle", "quiz_analysis"), "itemanalysis", "quiz"); echo '<div id="tablecontainer">'; $table->print_html(); echo '</div>'; $this->print_options_form($quiz, $cm, $attemptselection, $lowmarklimit, $pagesize); return true; }
function wiki_export_html(&$WS) { global $CFG; check_dir_exists("{$CFG->dataroot}/temp", true); check_dir_exists("{$CFG->dataroot}/temp/html", true); check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}", true); check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}", true); //export contents wiki_export_html_content($WS); //export attached files $flist = list_directories_and_files("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}"); if ($flist != null) { foreach ($flist as $fil) { $from_file = "{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}/{$fil}"; $to_file = "{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments/{$fil}"; copy($from_file, $to_file); } } //zip file name $times = time(); $name = $WS->dfwiki->name . '-' . $times . '.zip'; $cleanzipname = clean_filename($name); //List of files and directories $filelist = list_directories_and_files("{$CFG->dataroot}/temp/html"); //Convert them to full paths $files = array(); if ($filelist != null) { foreach ($filelist as $file) { $files[] = "{$CFG->dataroot}/temp/html/{$file}"; } } check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/exportedhtml", true); $destination = "{$CFG->dataroot}/{$WS->dfwiki->course}/exportedhtml/{$cleanzipname}"; $status = zip_files($files, $destination); //delete the folder created in temp $filelist2 = list_directories_and_files("{$CFG->dataroot}/temp/html"); if ($filelist2 != null) { $del = delete_dir_contents("{$CFG->dataroot}/temp/html"); } //show it all to be albe to download the file $prop = null; $prop->class = "textcenter"; wiki_div_start($prop); wiki_size_text(get_string("exporthtmlcorrectly", "wiki"), 2); wiki_div_end(); $prop = null; $prop->border = "0"; $prop->class = "boxaligncenter"; $prop->classtd = "nwikileftnow"; wiki_table_start($prop); $wdir = '/exportedhtml'; $fileurl = "{$wdir}/{$cleanzipname}"; $ffurl = "/file.php?file=/{$WS->cm->course}{$fileurl}"; $icon = mimeinfo("icon", $cleanzipname); link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" alt=\"File\" />", 480, 640); echo "\n" . ' '; link_to_popup_window($ffurl, "display", htmlspecialchars($cleanzipname), 480, 640); $prop = null; $prop->class = "nwikileftnow"; wiki_change_row($prop); echo ' '; wiki_table_end(); $prop = null; $prop->border = "0"; $prop->class = "boxaligncenter"; $prop->classtd = "nwikileftnow"; wiki_table_start($prop); $prop = null; $prop->id = "form"; $prop->method = "post"; $prop->action = '../xml/index.php?id=' . $WS->dfwiki->course . '&wdir=/exportedhtml'; wiki_form_start($prop); wiki_div_start(); $prop = null; $prop->name = "dfform[viewexported]"; $prop->value = get_string('viewexported', 'wiki'); wiki_input_submit($prop); wiki_div_end(); wiki_form_end(); wiki_change_column(); print_continue("{$CFG->wwwroot}/mod/wiki/view.php?id={$WS->cm->id}"); wiki_table_end(); }
function displaydir($wdir) { // $wdir == / or /a or /a/b/c/d etc global $basedir; global $usecheckboxes; global $id; global $USER, $CFG; $fullpath = $basedir . $wdir; $directory = opendir($fullpath); // Find all files while (false !== ($file = readdir($directory))) { if ($file == "." || $file == "..") { continue; } if (is_dir($fullpath . "/" . $file)) { $dirlist[] = $file; } else { $filelist[] = $file; } } closedir($directory); $strfile = get_string("file"); $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); $straction = get_string("action"); $strmakeafolder = get_string("makeafolder"); $struploadafile = get_string("uploadafile"); $strwithchosenfiles = get_string("withchosenfiles"); $strmovetoanotherfolder = get_string("movetoanotherfolder"); $strmovefilestohere = get_string("movefilestohere"); $strdeletecompletely = get_string("deletecompletely"); $strcreateziparchive = get_string("createziparchive"); $strrename = get_string("rename"); $stredit = get_string("edit"); $strunzip = get_string("unzip"); $strlist = get_string("list"); $strchoose = get_string("choose"); echo "<form action=\"coursefiles.php\" method=\"post\" name=\"dirform\">\n"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\">\n"; if ($wdir == "/") { $wdir = ""; } else { $bdir = str_replace("/" . basename($wdir), "", $wdir); if ($bdir == "/") { $bdir = ""; } print "<tr>\n<td colspan=\"5\">"; print "<a href=\"coursefiles.php?id={$id}&wdir={$bdir}&usecheckboxes={$usecheckboxes}\" onclick=\"return reset_value();\">"; print "<img src=\"{$CFG->wwwroot}/lib/editor/htmlarea/images/folderup.gif\" height=\"14\" width=\"24\" border=\"0\" alt=\"" . get_string('parentfolder') . "\" />"; print "</a></td>\n</tr>\n"; } $count = 0; if (!empty($dirlist)) { asort($dirlist); foreach ($dirlist as $dir) { $count++; $filename = $fullpath . "/" . $dir; $fileurl = $wdir . "/" . $dir; $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); echo "<tr>"; if ($usecheckboxes) { print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" onclick=\"return set_rename('{$dir}');\" />"); } print_cell("left", "<a href=\"coursefiles.php?id={$id}&wdir={$fileurl}\" onclick=\"return reset_value();\"><img src=\"{$CFG->pixpath}/f/folder.gif\" class=\"icon\" alt=\"" . get_string('folder') . "\" /></a> <a href=\"coursefiles.php?id={$id}&wdir={$fileurl}&usecheckboxes={$usecheckboxes}\" onclick=\"return reset_value();\">" . htmlspecialchars($dir) . "</a>"); print_cell("right", " "); print_cell("right", $filedate); echo "</tr>"; } } if (!empty($filelist)) { asort($filelist); foreach ($filelist as $file) { $icon = mimeinfo("icon", $file); $imgtype = mimeinfo("type", $file); $count++; $filename = $fullpath . "/" . $file; $fileurl = "{$wdir}/{$file}"; $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); $dimensions = get_image_size($filename); if ($dimensions) { $imgwidth = $dimensions[0]; $imgheight = $dimensions[1]; } else { $imgwidth = "Unknown"; $imgheight = "Unknown"; } unset($dimensions); echo "<tr>\n"; if ($usecheckboxes) { print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" onclick=\";return set_rename('{$file}');\" />"); } echo "<td align=\"left\" nowrap=\"nowrap\">"; $ffurl = get_file_url($id . $fileurl); link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />", 480, 640); $file_size = filesize($filename); echo "<a onclick=\"return set_value(info = {url: '" . $ffurl . "',"; echo " isize: '" . $file_size . "', itype: '" . $imgtype . "', iwidth: '" . $imgwidth . "',"; echo " iheight: '" . $imgheight . "', imodified: '" . $filedate . "' })\" href=\"#\">{$file}</a>"; echo "</td>\n"; if ($icon == "zip.gif") { $edittext = "<a href=\"coursefiles.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=unzip&sesskey={$USER->sesskey}\">{$strunzip}</a> "; $edittext .= "<a href=\"coursefiles.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=listzip&sesskey={$USER->sesskey}\">{$strlist}</a> "; } else { $edittext = " "; } print_cell("right", "{$edittext} "); print_cell("right", $filedate); echo "</tr>\n"; } } echo "</table>\n"; if (empty($wdir)) { $wdir = "/"; } echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n"; echo "<tr>\n<td>"; echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />\n"; echo "<input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n"; echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />\n"; $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}"); if (!empty($count)) { choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:getElementById('dirform').submit()"); } if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) { echo "<form action=\"coursefiles.php\" method=\"get\">\n"; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />\n"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />\n"; echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />\n"; echo " <input type=\"submit\" value=\"{$strmovefilestohere}\" />\n"; echo "</form>"; } echo "</td></tr>\n"; echo "</table>\n"; echo "</form>\n"; }
/** * Produces a list of links to the files uploaded by a user * * @param $userid int optional id of the user. If 0 then $USER->id is used. * @param $return boolean optional defaults to false. If true the list is returned rather than printed * @return string optional */ function print_user_files($userid = 0, $return = false) { global $CFG, $USER; if (!$userid) { if (!isloggedin()) { return ''; } $userid = $USER->id; } $filearea = $this->file_area_name($userid); $output = ''; if ($basedir = $this->file_area($userid)) { if ($files = get_directory_list($basedir)) { require_once $CFG->libdir . '/filelib.php'; foreach ($files as $key => $file) { $icon = mimeinfo('icon', $file); $ffurl = get_file_url("{$filearea}/{$file}", array('forcedownload' => 1)); // Syntax Highlighert source code $viewlink = link_to_popup_window('/mod/assignment/type/onlinejudge/source.php?id=' . $this->cm->id . '&userid=' . $userid . '&file=' . $file, $file . 'sourcecode', get_string('preview'), 500, 740, $file, 'none', true, 'button' . $userid); $output .= '<img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . '<a href="' . $ffurl . '" >' . $file . '</a> (' . $viewlink . ')<br />'; } } } $output = '<div class="files">' . $output . '</div>'; if ($return) { return $output; } echo $output; }
$original_theme = fullclone($THEME); foreach ($themes as $theme) { unset($THEME); if (!file_exists($CFG->themedir . '/' . $theme . '/config.php')) { // bad folder continue; } include $CFG->themedir . '/' . $theme . '/config.php'; $readme = ''; $screenshot = ''; $screenshotpath = ''; if (file_exists("{$theme}/README.html")) { $readme = "\t\t\t\t<li>" . link_to_popup_window($CFG->themewww . '/' . $theme . '/README.html', $theme, $strinfo, 400, 500, '', 'none', true) . "</li>\n"; } else { if (file_exists("{$theme}/README.txt")) { $readme = "\t\t\t\t<li>" . link_to_popup_window($CFG->themewww . '/' . $theme . '/README.txt', $theme, $strinfo, 400, 500, '', 'none', true) . "</li>\n"; } } if (file_exists("{$theme}/screenshot.png")) { $screenshotpath = "{$theme}/screenshot.png"; } else { if (file_exists("{$theme}/screenshot.jpg")) { $screenshotpath = "{$theme}/screenshot.jpg"; } } echo "\t<tr>\n"; // no point showing this if user is using screen reader if (!$USER->screenreader) { echo "\t\t<td align=\"center\">\n"; if ($screenshotpath) { $screenshot = "\t\t\t\t<li><a href=\"{$theme}/screenshot.jpg\">{$strscreenshot}</a></li>\n";
$abletomovecourses = true; } echo '</td>'; echo '<td align="center">'; echo '<input type="checkbox" name="c' . $acourse->id . '" />'; echo '</td>'; } else { echo '<td align="right">'; if (!empty($acourse->guest)) { echo '<a href="view.php?id=' . $acourse->id . '"><img title="' . $strallowguests . '" class="icon" src="' . $CFG->pixpath . '/i/user.gif" alt="' . $strallowguests . '" /></a>'; } if (!empty($acourse->password)) { echo '<a href="view.php?id=' . $acourse->id . '"><img title="' . $strrequireskey . '" class="icon" src="' . $CFG->pixpath . '/i/key.gif" alt="' . $strrequireskey . '" /></a>'; } if (!empty($acourse->summary)) { link_to_popup_window("/course/info.php?id={$acourse->id}", "courseinfo", '<img alt="' . get_string('info') . '" class="icon" src="' . $CFG->pixpath . '/i/info.gif" />', 400, 500, $strsummary); } echo "</td>"; } echo "</tr>"; } if ($abletomovecourses) { echo '<tr><td colspan="3" align="right">'; echo '<br />'; unset($displaylist[$category->id]); // loop and unset categories the user can't move into foreach ($displaylist as $did => $dlist) { if (!has_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $did))) { unset($displaylist[$did]); } }
<?php // $Id: index.php,v 1.4 2007/01/15 07:59:59 vyshane Exp $ require_once '../../../config.php'; require_once $CFG->dirroot . '/course/lib.php'; require_once $CFG->dirroot . '/course/report/log/lib.php'; require_once $CFG->libdir . '/adminlib.php'; $adminroot = admin_get_root(); admin_externalpage_setup('reportlog', $adminroot); admin_externalpage_print_header($adminroot); $course = get_site(); print_heading(get_string('chooselogs') . ':'); print_mnet_log_selector_form($CFG->mnet_localhost_id, $course); echo '<br />'; print_heading(get_string('chooselivelogs') . ':'); $heading = link_to_popup_window('/course/report/log/live.php?id=' . $course->id, 'livelog', get_string('livelogs'), 500, 800, '', 'none', true); print_heading($heading, 'center', 3); admin_externalpage_print_footer($adminroot);
function display() { global $CFG; /// Set up generic stuff first, including checking for access parent::display(); /// Set up some shorthand variables $cm = $this->cm; $course = $this->course; $resource = $this->resource; require_once $CFG->libdir . '/filelib.php'; $subdir = optional_param('subdir', '', PARAM_PATH); $resource->reference = clean_param($resource->reference, PARAM_PATH); $formatoptions = new object(); $formatoptions->noclean = true; $formatoptions->para = false; // MDL-12061, <p> in html editor breaks xhtml strict add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); if ($resource->reference) { $relativepath = "{$course->id}/{$resource->reference}"; } else { $relativepath = "{$course->id}"; } if ($subdir) { $relativepath = "{$relativepath}{$subdir}"; if (stripos($relativepath, 'backupdata') !== FALSE or stripos($relativepath, $CFG->moddata) !== FALSE) { error("Access not allowed!"); } $subs = explode('/', $subdir); array_shift($subs); $countsubs = count($subs); $count = 0; $backsub = ''; foreach ($subs as $sub) { $count++; if ($count < $countsubs) { $backsub .= "/{$sub}"; $this->navlinks[] = array('name' => $sub, 'link' => "view.php?id={$cm->id}", 'type' => 'title'); } else { $this->navlinks[] = array('name' => $sub, 'link' => '', 'type' => 'title'); } } } $pagetitle = strip_tags($course->shortname . ': ' . format_string($resource->name)); $update = update_module_button($cm->id, $course->id, $this->strresource); if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id))) { $options = array('id' => $course->id, 'wdir' => '/' . $resource->reference . $subdir); $editfiles = print_single_button("{$CFG->wwwroot}/files/index.php", $options, get_string("editfiles"), 'get', '', true); $update = $editfiles . $update; } $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, $update, navmenu($course, $cm)); if (trim(strip_tags($resource->summary))) { print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center"); print_spacer(10, 10); } $files = get_directory_list("{$CFG->dataroot}/{$relativepath}", array($CFG->moddata, 'backupdata'), false, true, true); if (!$files) { print_heading(get_string("nofilesyet")); print_footer($course); exit; } print_simple_box_start("center", "", "", '0'); $strftime = get_string('strftimedatetime'); $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); $strfolder = get_string("folder"); $strfile = get_string("file"); echo '<table cellpadding="4" cellspacing="1" class="files" summary="">'; echo "<tr><th class=\"header name\" scope=\"col\">{$strname}</th>" . "<th align=\"right\" colspan=\"2\" class=\"header size\" scope=\"col\">{$strsize}</th>" . "<th align=\"right\" class=\"header date\" scope=\"col\">{$strmodified}</th>" . "</tr>"; foreach ($files as $file) { if (is_dir("{$CFG->dataroot}/{$relativepath}/{$file}")) { // Must be a directory $icon = "folder.gif"; $relativeurl = "/view.php?blah"; $filesize = display_size(get_directory_size("{$CFG->dataroot}/{$relativepath}/{$file}")); } else { $icon = mimeinfo("icon", $file); $relativeurl = get_file_url("{$relativepath}/{$file}"); $filesize = display_size(filesize("{$CFG->dataroot}/{$relativepath}/{$file}")); } if ($icon == 'folder.gif') { echo '<tr class="folder">'; echo '<td class="name">'; echo "<a href=\"view.php?id={$cm->id}&subdir={$subdir}/{$file}\">"; echo "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfolder}\" /> {$file}</a>"; } else { echo '<tr class="file">'; echo '<td class="name">'; link_to_popup_window($relativeurl, "resourcedirectory{$resource->id}", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" /> {$file}", 450, 600, ''); } echo '</td>'; echo '<td> </td>'; echo '<td align="right" class="size">'; echo $filesize; echo '</td>'; echo '<td align="right" class="date">'; echo userdate(filemtime("{$CFG->dataroot}/{$relativepath}/{$file}"), $strftime); echo '</td>'; echo '</tr>'; } echo '</table>'; print_simple_box_end(); print_footer($course); }
print_box_start('generalbox', 'enterlink'); // users with screenreader set, will only see 1 link, to the manual refresh page // for better accessibility if (!empty($USER->screenreader)) { $chattarget = "/mod/chat/gui_basic/index.php?id={$chat->id}{$groupparam}"; } else { $chattarget = "/mod/chat/gui_{$CFG->chat_method}/index.php?id={$chat->id}{$groupparam}"; } echo '<p>'; link_to_popup_window($chattarget, "chat{$course->id}{$chat->id}{$groupparam}", "{$strenterchat}", 500, 700, get_string('modulename', 'chat')); echo '</p>'; // if user is using screen reader, then there is no need to display this link again if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) { // show frame/js-less alternative echo '<p>('; link_to_popup_window("/mod/chat/gui_basic/index.php?id={$chat->id}{$groupparam}", "chat{$course->id}{$chat->id}{$groupparam}", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat')); echo ')</p>'; } print_box_end(); if ($chat->chattime and $chat->schedule) { // A chat is scheduled echo "<p class=\"nextchatsession\">{$strnextsession}: " . userdate($chat->chattime) . ' (' . usertimezone($USER->timezone) . ')</p>'; } else { echo '<br />'; } if ($chat->intro) { print_box(format_text($chat->intro), 'generalbox', 'intro'); } chat_delete_old_users(); if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) { $timenow = time();
/** Make some text into a link to review the game, if that is appropriate. */ function make_review_link($linktext, $game, $attempt) { // If not even responses are to be shown in review then we don't allow any review if (!($game->review & GAME_REVIEW_RESPONSES)) { return $linktext; } // If the game is still open, are reviews allowed? if ((!$game->timeclose or time() < $game->timeclose) and !($game->review & GAME_REVIEW_OPEN)) { // If not, don't link. return $linktext; } // If the game is closed, are reviews allowed? if ($game->timeclose and time() > $game->timeclose and !($game->review & GAME_REVIEW_CLOSED)) { // If not, don't link. return $linktext; } // If the attempt is still open, don't link. if (!$attempt->timefinish) { return $linktext; } $url = "review.php?q={$game->id}&attempt={$attempt->id}"; if ($game->popup) { $windowoptions = "left=0, top=0, channelmode=yes, fullscreen=yes, scrollbars=yes, resizeable=no, directories=no, toolbar=no, titlebar=no, location=no, status=no, menubar=no"; return link_to_popup_window('/mod/game/' . $url, 'gamepopup', $linktext, '+window.screen.height+', '+window.screen.width+', '', $windowoptions, true); } else { return "<a href='{$url}'>{$linktext}</a>"; } }
function displaydir($wdir) { // $wdir == / or /a or /a/b/c/d etc global $basedir; global $usecheckboxes; global $id; global $USER, $CFG, $isteacher, $isstudent; $fullpath = $basedir . $wdir; $directory = opendir($fullpath); // Find all files while ($file = readdir($directory)) { if ($file == "." || $file == ".." || $file == "tmp") { continue; } if (is_dir($fullpath . "/" . $file)) { $dirlist[] = $file; } } $test = str_replace("/", "", $wdir); if (empty($test)) { $wdir = ""; } $images = netpublish_get_images($id, $wdir); /*print "<pre>"; print_r($images); print "</pre>"; exit;*/ $filelist = array(); if (!empty($images)) { $i = 0; foreach ($images as $img) { $filelist[$i]['id'] = $img->id; $filelist[$i]['course'] = $img->course; $filelist[$i]['name'] = $img->name; $filelist[$i]['mime'] = $img->mimetype; $filelist[$i]['size'] = $img->size; $filelist[$i]['dir'] = $img->dir; $filelist[$i]['filedate'] = userdate($img->timemodified, "%d %b %Y, %I:%M %p"); $filelist[$i]['width'] = $img->width; $filelist[$i]['height'] = $img->height; $filelist[$i]['owner'] = $img->owner; $i++; } } //closedir($directory); $strfile = get_string("file"); $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); $straction = get_string("action"); $strmakeafolder = get_string("makeafolder"); $struploadafile = get_string("uploadafile"); $strwithchosenfiles = get_string("withchosenfiles"); $strmovetoanotherfolder = get_string("movetoanotherfolder"); $strmovefilestohere = get_string("movefilestohere"); $strdeletecompletely = get_string("deletecompletely"); $strcreateziparchive = get_string("createziparchive"); $strrename = get_string("rename"); $stredit = get_string("edit"); $strunzip = get_string("unzip"); $strlist = get_string("list"); $strchoose = get_string("choose"); echo "<form action=\"imagebank.php\" method=\"post\" name=\"dirform\">\n"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" width=\"100%\">\n"; if (empty($wdir)) { $wdir = ""; } else { $bdir = str_replace("/" . basename($wdir), "", $wdir); if ($bdir == "/") { $bdir = ""; } print "<tr>\n<td colspan=\"5\">"; print "<a href=\"imagebank.php?id={$id}&wdir={$bdir}&usecheckboxes={$usecheckboxes}\" onclick=\"return reset_value();\">"; print "<img src=\"{$CFG->wwwroot}/lib/editor/images/folderup.gif\" height=\"14\" width=\"24\" border=\"0\" alt=\"Move up\" />"; print "</a></td>\n</tr>\n"; } $count = 0; if (!empty($dirlist)) { asort($dirlist); foreach ($dirlist as $dir) { $count++; $filename = $fullpath . "/" . $dir; $fileurl = rawurlencode($wdir . "/" . $dir); $filesafe = rawurlencode($dir); $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p"); echo "<tr>"; if ($usecheckboxes && $isteacher) { print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" onclick=\"return set_rename('{$filesafe}');\" />"); } else { print_cell("left"); } print_cell("left", "<a href=\"imagebank.php?id={$id}&wdir={$fileurl}\" onclick=\"return reset_value();\"><img src=\"{$CFG->pixpath}/f/folder.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"folder\" /></a> <a href=\"imagebank.php?id={$id}&wdir={$fileurl}&usecheckboxes={$usecheckboxes}\" onclick=\"return reset_value();\">" . htmlspecialchars($dir) . "</a>"); print_cell("right", " "); print_cell("right", $filedate); echo "</tr>"; } } if (!empty($filelist)) { foreach ($filelist as $file) { $icon = mimeinfo("icon", $file['name']); $imgtype = $file['mime']; $count++; //$filename = $fullpath."/".$file['name']; $fileurl = "/mod/netpublish/image.php?id={$file['id']}"; $filesafe = rawurlencode($file['name']); $fileurlsafe = rawurlencode($fileurl); $filedate = $file['filedate']; $imgwidth = $file['width']; $imgheight = $file['height']; echo "<tr>\n"; if ($usecheckboxes) { if (intval($file['owner']) == intval($USER->id) or $isteacher) { print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$file['id']}\" onclick=\"return set_rename('{$file['id']}');\" />"); } else { print_cell("left"); } } echo "<td align=\"left\" nowrap=\"nowrap\">"; if ($CFG->slasharguments) { $ffurl = $fileurl; } else { $ffurl = $fileurl; } link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" border=\"0\" align=\"middle\" alt=\"{$strfile}\" />", 480, 640); $file_size = $file['size']; echo "<a onclick=\"return set_value(info = {url: '" . $CFG->wwwroot . $ffurl . "',"; echo " isize: '" . $file_size . "', itype: '" . $imgtype . "', iwidth: '" . $imgwidth . "',"; echo " iheight: '" . $imgheight . "', imodified: '" . $filedate . "', ialt: '" . $file['name'] . "' })\" href=\"#\">{$file['name']}</a>"; echo "</td>\n"; if ($icon == "zip.gif") { $edittext = "<a href=\"imagebank.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=unzip&sesskey={$USER->sesskey}\">{$strunzip}</a> "; $edittext .= "<a href=\"imagebank.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=listzip&sesskey={$USER->sesskey}\">{$strlist}</a> "; } else { $edittext = " "; } print_cell("right", "{$edittext} "); print_cell("right", $filedate); echo "</tr>\n"; } } echo "</table>\n"; if (empty($wdir)) { $wdir = "/"; } echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n"; echo "<tr>\n<td>"; echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />\n"; echo "<input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n"; echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />\n"; $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}"); if (!empty($count)) { choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:document.dirform.submit()"); } if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) { echo "<form action=\"imagebank.php\" method=\"get\">\n"; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />\n"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />\n"; echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />\n"; echo " <input type=\"submit\" value=\"{$strmovefilestohere}\" />\n"; echo "</form>"; } echo "</td></tr>\n"; echo "</table>\n"; echo "</form>\n"; }
/** * Prints the table of questions in a category with interactions * * @param object $course The course object * @param int $categoryid The id of the question category to be displayed * @param int $cm The course module record if we are in the context of a particular module, 0 otherwise * @param int $recurse This is 1 if subcategories should be included, 0 otherwise * @param int $page The number of the page to be displayed * @param int $perpage Number of questions to show per page * @param boolean $showhidden True if also hidden questions should be displayed * @param boolean $showquestiontext whether the text of each question should be shown in the list */ function question_list($contexts, $pageurl, $categoryandcontext, $cm = null, $recurse = 1, $page = 0, $perpage = 100, $showhidden = false, $sortorder = 'typename', $sortorderdecoded = 'qtype, name ASC', $showquestiontext = false, $addcontexts = array()) { global $USER, $CFG, $THEME, $COURSE; $lastchangedid = optional_param('lastchanged', 0, PARAM_INT); list($categoryid, $contextid) = explode(',', $categoryandcontext); $qtypemenu = question_type_menu(); $strcategory = get_string("category", "quiz"); $strquestion = get_string("question", "quiz"); $straddquestions = get_string("addquestions", "quiz"); $strimportquestions = get_string("importquestions", "quiz"); $strexportquestions = get_string("exportquestions", "quiz"); $strnoquestions = get_string("noquestions", "quiz"); $strselect = get_string("select", "quiz"); $strselectall = get_string("selectall", "quiz"); $strselectnone = get_string("selectnone", "quiz"); $strcreatenewquestion = get_string("createnewquestion", "quiz"); $strquestionname = get_string("questionname", "quiz"); $strdelete = get_string("delete"); $stredit = get_string("edit"); $strmove = get_string('moveqtoanothercontext', 'question'); $strview = get_string("view"); $straction = get_string("action"); $strrestore = get_string('restore'); $strtype = get_string("type", "quiz"); $strcreatemultiple = get_string("createmultiple", "quiz"); $strpreview = get_string("preview", "quiz"); if (!$categoryid) { echo "<p style=\"text-align:center;\"><b>"; print_string("selectcategoryabove", "quiz"); echo "</b></p>"; return; } if (!($category = get_record('question_categories', 'id', $categoryid, 'contextid', $contextid))) { notify('Category not found!'); return; } $catcontext = get_context_instance_by_id($contextid); $canadd = has_capability('moodle/question:add', $catcontext); //check for capabilities on all questions in category, will also apply to sub cats. $caneditall = has_capability('moodle/question:editall', $catcontext); $canuseall = has_capability('moodle/question:useall', $catcontext); $canmoveall = has_capability('moodle/question:moveall', $catcontext); if ($cm and $cm->modname == 'quiz') { $quizid = $cm->instance; } else { $quizid = 0; } $returnurl = $pageurl->out(); $questionurl = new moodle_url("{$CFG->wwwroot}/question/question.php", array('returnurl' => $returnurl)); if ($cm !== null) { $questionurl->param('cmid', $cm->id); } else { $questionurl->param('courseid', $COURSE->id); } $questionmoveurl = new moodle_url("{$CFG->wwwroot}/question/contextmoveq.php", array('returnurl' => $returnurl)); if ($cm !== null) { $questionmoveurl->param('cmid', $cm->id); } else { $questionmoveurl->param('courseid', $COURSE->id); } echo '<div class="boxaligncenter">'; $formatoptions = new stdClass(); $formatoptions->noclean = true; echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $COURSE->id); echo '<table><tr>'; if ($canadd) { echo '<td valign="top" align="right">'; popup_form($questionurl->out(false, array('category' => $category->id)) . '&qtype=', $qtypemenu, "addquestion", "", "choose", "", "", false, "self", "<strong>{$strcreatenewquestion}</strong>"); echo '</td><td valign="top" align="right">'; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); echo '</td>'; } else { echo '<td>'; print_string('nopermissionadd', 'question'); echo '</td>'; } echo '</tr></table>'; echo '</div>'; $categorylist = $recurse ? question_categorylist($category->id) : $category->id; // hide-feature $showhidden = $showhidden ? '' : " AND hidden = '0'"; if (!($totalnumber = count_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}"))) { echo "<p style=\"text-align:center;\">"; print_string("noquestions", "quiz"); echo "</p>"; return; } if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorderdecoded, '*', $page * $perpage, $perpage))) { // There are no questions on the requested page. $page = 0; if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorderdecoded, '*', 0, $perpage))) { // There are no questions at all echo "<p style=\"text-align:center;\">"; print_string("noquestions", "quiz"); echo "</p>"; return; } } print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage'); echo question_sort_options($pageurl, $sortorder); echo '<form method="post" action="edit.php">'; echo '<fieldset class="invisiblefieldset" style="display: block;">'; echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />'; echo $pageurl->hidden_params_out(); echo '<table id="categoryquestions" style="width: 100%"><tr>'; echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$straction}</th>"; echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">{$strquestionname}</th>\n <th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">{$strtype}</th>"; echo "</tr>\n"; foreach ($questions as $question) { $nameclass = ''; $textclass = ''; if ($question->hidden) { $nameclass = 'dimmed_text'; $textclass = 'dimmed_text'; } if ($showquestiontext) { $nameclass .= ' header'; } if ($question->id == $lastchangedid) { $nameclass = 'highlight'; } if ($nameclass) { $nameclass = 'class="' . $nameclass . '"'; } if ($textclass) { $textclass = 'class="' . $textclass . '"'; } echo "<tr>\n<td style=\"white-space:nowrap;\" {$nameclass}>\n"; $canuseq = question_has_capability_on($question, 'use', $question->category); if (function_exists('module_specific_actions')) { echo module_specific_actions($pageurl, $question->id, $cm->id, $canuseq); } // preview if ($canuseq) { $quizorcourseid = $quizid ? '&quizid=' . $quizid : '&courseid=' . $COURSE->id; link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview', "<img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strpreview}\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS); } // edit, hide, delete question, using question capabilities, not quiz capabilieies if (question_has_capability_on($question, 'edit', $question->category) || question_has_capability_on($question, 'move', $question->category)) { echo "<a title=\"{$stredit}\" href=\"" . $questionurl->out(false, array('id' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/t/edit.gif\" alt=\"{$stredit}\" /></a> "; } elseif (question_has_capability_on($question, 'view', $question->category)) { echo "<a title=\"{$strview}\" href=\"" . $questionurl->out(false, array('id' => $question->id)) . "\"><img\n src=\"{$CFG->pixpath}/i/info.gif\" alt=\"{$strview}\" /></a> "; } if (question_has_capability_on($question, 'move', $question->category) && question_has_capability_on($question, 'view', $question->category)) { echo "<a title=\"{$strmove}\" href=\"" . $questionurl->out(false, array('id' => $question->id, 'movecontext' => 1)) . "\"><img\n src=\"{$CFG->pixpath}/t/move.gif\" alt=\"{$strmove}\" /></a> "; } if (question_has_capability_on($question, 'edit', $question->category)) { // hide-feature if ($question->hidden) { echo "<a title=\"{$strrestore}\" href=\"edit.php?" . $pageurl->get_query_string() . "&unhide={$question->id}&sesskey={$USER->sesskey}\"><img\n src=\"{$CFG->pixpath}/t/restore.gif\" alt=\"{$strrestore}\" /></a>"; } else { echo "<a title=\"{$strdelete}\" href=\"edit.php?" . $pageurl->get_query_string() . "&deleteselected={$question->id}&q{$question->id}=1\"><img\n src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"{$strdelete}\" /></a>"; } } if ($caneditall || $canmoveall || $canuseall) { echo " <input title=\"{$strselect}\" type=\"checkbox\" name=\"q{$question->id}\" value=\"1\" />"; } echo "</td>\n"; echo "<td {$nameclass}>" . format_string($question->name) . "</td>\n"; echo "<td {$nameclass} style='text-align: right'>\n"; print_question_icon($question); echo "</td>\n"; echo "</tr>\n"; if ($showquestiontext) { echo '<tr><td colspan="3" ' . $textclass . '>'; $formatoptions = new stdClass(); $formatoptions->noclean = true; $formatoptions->para = false; echo format_text($question->questiontext, $question->questiontextformat, $formatoptions, $COURSE->id); echo "</td></tr>\n"; } } echo "</table>\n"; $paging = print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage', false, true); if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) { if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) { $showall = '<a href="edit.php?' . $pageurl->get_query_string(array('qperpage' => 1000)) . '">' . get_string('showall', 'moodle', $totalnumber) . '</a>'; } else { $showall = '<a href="edit.php?' . $pageurl->get_query_string(array('qperpage' => DEFAULT_QUESTIONS_PER_PAGE)) . '">' . get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE) . '</a>'; } if ($paging) { $paging = substr($paging, 0, strrpos($paging, '</div>')); $paging .= "<br />{$showall}</div>"; } else { $paging = "<div class='paging'>{$showall}</div>"; } } echo $paging; if ($caneditall || $canmoveall || $canuseall) { echo '<a href="javascript:select_all_in(\'TABLE\',null,\'categoryquestions\');">' . $strselectall . '</a> /' . ' <a href="javascript:deselect_all_in(\'TABLE\',null,\'categoryquestions\');">' . $strselectnone . '</a>'; echo '<br />'; echo '<strong> ' . get_string('withselected', 'quiz') . ':</strong><br />'; if (function_exists('module_specific_buttons')) { echo module_specific_buttons($cm->id); } // print delete and move selected question if ($caneditall) { echo '<input type="submit" name="deleteselected" value="' . $strdelete . "\" />\n"; } if ($canmoveall && count($addcontexts)) { echo '<input type="submit" name="move" value="' . get_string('moveto', 'quiz') . "\" />\n"; question_category_select_menu($addcontexts, false, 0, "{$category->id},{$category->contextid}"); } if (function_exists('module_specific_controls') && $canuseall) { echo module_specific_controls($totalnumber, $recurse, $category, $cm->id); } } echo '</fieldset>'; echo "</form>\n"; }
/** * @desc Prints the questions buttons. * @param $question object The question object. * @param $state object The state object. * @param $cmoptions object The quizzes or other mods options * @param $options object The questions options. */ function print_question_submit_buttons(&$question, &$state, $cmoptions, $options) { $courseid = $cmoptions->course; $seed = $state->responses['seed']; $attempt = $state->attempt; echo "<table><tr><td>"; parent::print_question_submit_buttons($question, $state, $cmoptions, $options); echo "</td><td>"; if (!$options->readonly && $courseid != 1) { echo link_to_popup_window('/question/type/webwork/emailinstructor.php?qid=' . $question->id . '&aid=' . $attempt, 'emailinstructor', "<input type=\"button\" value=\"Email Instructor\" class=\"submit btn\">", 600, 700, "Email Instructor"); } echo "</td></tr></table>"; }
function displaydir($wdir) { // $wdir == / or /a or /a/b/c/d etc global $basedir; global $id; global $USER, $CFG; global $choose; $fullpath = $basedir . $wdir; $dirlist = array(); $directory = opendir($fullpath); // Find all files while (false !== ($file = readdir($directory))) { if ($file == "." || $file == "..") { continue; } if (is_dir($fullpath . "/" . $file)) { $dirlist[] = $file; } else { $filelist[] = $file; } } closedir($directory); $strname = get_string("name"); $strsize = get_string("size"); $strmodified = get_string("modified"); $straction = get_string("action"); $strmakeafolder = get_string("makeafolder"); $struploadafile = get_string("uploadafile"); $strselectall = get_string("selectall"); $strselectnone = get_string("deselectall"); $strwithchosenfiles = get_string("withchosenfiles"); $strmovetoanotherfolder = get_string("movetoanotherfolder"); $strmovefilestohere = get_string("movefilestohere"); $strdeletecompletely = get_string("deletecompletely"); $strcreateziparchive = get_string("createziparchive"); $strrename = get_string("rename"); $stredit = get_string("edit"); $strunzip = get_string("unzip"); $strlist = get_string("list"); $strrestore = get_string("restore"); $strchoose = get_string("choose"); $strfolder = get_string("folder"); $strfile = get_string("file"); echo "<form action=\"index.php\" method=\"post\" id=\"dirform\">"; echo "<div>"; echo '<input type="hidden" name="choose" value="' . $choose . '" />'; // echo "<hr align=\"center\" noshade=\"noshade\" size=\"1\" />"; echo "<hr/>"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">"; echo "<tr>"; echo "<th class=\"header\" scope=\"col\"></th>"; echo "<th class=\"header name\" scope=\"col\">{$strname}</th>"; echo "<th class=\"header size\" scope=\"col\">{$strsize}</th>"; echo "<th class=\"header date\" scope=\"col\">{$strmodified}</th>"; echo "<th class=\"header commands\" scope=\"col\">{$straction}</th>"; echo "</tr>\n"; if ($wdir != "/") { $dirlist[] = '..'; } $count = 0; if (!empty($dirlist)) { asort($dirlist); foreach ($dirlist as $dir) { echo "<tr class=\"folder\">"; if ($dir == '..') { $fileurl = rawurlencode(dirname($wdir)); print_cell(); // alt attribute intentionally empty to prevent repetition in screen reader print_cell('left', '<a href="index.php?id=' . $id . '&wdir=' . $fileurl . '&choose=' . $choose . '"><img src="' . $CFG->pixpath . '/f/parent.gif" class="icon" alt="" /> ' . get_string('parentfolder') . '</a>', 'name'); print_cell(); print_cell(); print_cell(); } else { $count++; $filename = $fullpath . "/" . $dir; $fileurl = rawurlencode($wdir . "/" . $dir); $filesafe = rawurlencode($dir); $filesize = display_size(get_directory_size("{$fullpath}/{$dir}")); $filedate = userdate(filemtime($filename), get_string("strftimedatetime")); if ($wdir . $dir === '/moddata') { print_cell(); } else { print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox'); } print_cell("left", "<a href=\"index.php?id={$id}&wdir={$fileurl}&choose={$choose}\"><img src=\"{$CFG->pixpath}/f/folder.gif\" class=\"icon\" alt=\"{$strfolder}\" /> " . htmlspecialchars($dir) . "</a>", 'name'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); if ($wdir . $dir === '/moddata') { print_cell(); } else { print_cell("right", "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$filesafe}&action=rename&choose={$choose}\">{$strrename}</a>", 'commands'); } } echo "</tr>"; } } if (!empty($filelist)) { asort($filelist); foreach ($filelist as $file) { $icon = mimeinfo("icon", $file); $count++; $filename = $fullpath . "/" . $file; $fileurl = trim($wdir, "/") . "/{$file}"; $filesafe = rawurlencode($file); $fileurlsafe = rawurlencode($fileurl); $filedate = userdate(filemtime($filename), get_string("strftimedatetime")); $selectfile = trim($fileurl, "/"); echo "<tr class=\"file\">"; print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox'); echo "<td align=\"left\" style=\"white-space:nowrap\" class=\"name\">"; $ffurl = get_file_url($id . '/' . $fileurl); link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" /> " . htmlspecialchars($file), 480, 640); echo "</td>"; $file_size = filesize($filename); print_cell("right", display_size($file_size), 'size'); print_cell("right", $filedate, 'date'); if ($choose) { $edittext = "<strong><a onclick=\"return set_value('{$selectfile}')\" href=\"#\">{$strchoose}</a></strong> "; } else { $edittext = ''; } if ($icon == "text.gif" || $icon == "html.gif") { $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=edit&choose={$choose}\">{$stredit}</a>"; } else { if ($icon == "zip.gif") { $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=unzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strunzip}</a> "; $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$fileurl}&action=listzip&sesskey={$USER->sesskey}&choose={$choose}\">{$strlist}</a> "; if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { $edittext .= "<a href=\"index.php?id={$id}&wdir={$wdir}&file={$filesafe}&action=restore&sesskey={$USER->sesskey}&choose={$choose}\">{$strrestore}</a> "; } } } print_cell("right", "{$edittext} <a href=\"index.php?id={$id}&wdir={$wdir}&file={$filesafe}&action=rename&choose={$choose}\">{$strrename}</a>", 'commands'); echo "</tr>"; } } echo "</table>"; echo "<hr />"; //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">"; echo "<tr><td>"; echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo '<input type="hidden" name="choose" value="' . $choose . '" />'; echo "<input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" /> "; echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />"; $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}"); if (!empty($count)) { choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:getElementById('dirform').submit()"); echo '<div id="noscriptgo" style="display: inline;">'; echo '<input type="submit" value="' . get_string('go') . '" />'; echo '<script type="text/javascript">' . "\n//<![CDATA[\n" . 'document.getElementById("noscriptgo").style.display = "none";' . "\n//]]>\n" . '</script>'; echo '</div>'; } echo "</td></tr></table>"; echo "</div>"; echo "</form>"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>"; echo "<td align=\"center\">"; if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) { echo "<form action=\"index.php\" method=\"get\">"; echo "<div>"; echo ' <input type="hidden" name="choose" value="' . $choose . '" />'; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />"; echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />"; echo " <input type=\"submit\" value=\"{$strmovefilestohere}\" />"; echo "</div>"; echo "</form>"; } echo "</td>"; echo "<td align=\"right\">"; echo "<form action=\"index.php\" method=\"get\">"; echo "<div>"; echo ' <input type="hidden" name="choose" value="' . $choose . '" />'; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />"; echo " <input type=\"submit\" value=\"{$strmakeafolder}\" />"; echo "</div>"; echo "</form>"; echo "</td>"; echo "<td align=\"right\">"; echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only echo "<fieldset class=\"invisiblefieldset\">"; echo " <input type=\"button\" value=\"{$strselectall}\" onclick=\"checkall();\" />"; echo " <input type=\"button\" value=\"{$strselectnone}\" onclick=\"uncheckall();\" />"; echo "</fieldset>"; echo "</form>"; echo "</td>"; echo "<td align=\"right\">"; echo "<form action=\"index.php\" method=\"get\">"; echo "<div>"; echo ' <input type="hidden" name="choose" value="' . $choose . '" />'; echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />"; echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />"; echo " <input type=\"submit\" value=\"{$struploadafile}\" />"; echo "</div>"; echo "</form>"; echo "</td></tr>"; echo "</table>"; echo "<hr/>"; //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />"; }
function history($question, $state, $number, $cmoptions, $options) { $history = ''; if (isset($options->history) and $options->history) { if ($options->history == 'all') { // show all states $states = get_records_select('question_states', "attempt = '{$state->attempt}' AND question = '{$question->id}' AND event > '0'", 'seq_number ASC'); } else { // show only graded states $states = get_records_select('question_states', "attempt = '{$state->attempt}' AND question = '{$question->id}' AND event IN (" . QUESTION_EVENTS_GRADED . ")", 'seq_number ASC'); } if (count($states) > 1) { $strreviewquestion = get_string('reviewresponse', 'quiz'); $table = new stdClass(); $table->width = '100%'; if ($options->scores) { $table->head = array(get_string('numberabbr', 'quiz'), get_string('action', 'quiz'), get_string('response', 'quiz'), get_string('time'), get_string('score', 'quiz'), get_string('grade', 'quiz')); } else { $table->head = array(get_string('numberabbr', 'quiz'), get_string('action', 'quiz'), get_string('response', 'quiz'), get_string('time')); } foreach ($states as $st) { $st->responses[''] = $st->answer; $this->restore_session_and_responses($question, $st); $b = $state->id == $st->id ? '<b>' : ''; $be = $state->id == $st->id ? '</b>' : ''; if ($state->id == $st->id) { $link = '<b>' . $st->seq_number . '</b>'; } else { if (isset($options->questionreviewlink)) { $link = link_to_popup_window($options->questionreviewlink . '?state=' . $st->id . '&number=' . $number, 'reviewquestion', $st->seq_number, 450, 650, $strreviewquestion, 'none', true); } else { $link = $st->seq_number; } } if ($options->scores) { $table->data[] = array($link, $b . get_string('event' . $st->event, 'quiz') . $be, $b . $this->response_summary($question, $st) . $be, $b . userdate($st->timestamp, get_string('timestr', 'quiz')) . $be, $b . round($st->raw_grade, $cmoptions->decimalpoints) . $be, $b . round($st->grade, $cmoptions->decimalpoints) . $be); } else { $table->data[] = array($link, $b . get_string('event' . $st->event, 'quiz') . $be, $b . $this->response_summary($question, $st) . $be, $b . userdate($st->timestamp, get_string('timestr', 'quiz')) . $be); } } $history = print_table($table, true); } } return $history; }
function print_student_answer($userid, $return = false) { global $CFG; $filearea = $this->file_area_name($userid); $submission = $this->get_submission($userid); $output = ''; if ($basedir = $this->file_area($userid)) { if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission)) { $output .= '<strong>' . get_string('draft', 'assignment') . ':</strong> '; } if ($this->notes_allowed() and !empty($submission->data1)) { $output .= link_to_popup_window('/mod/assignment/type/upload/notes.php?id=' . $this->cm->id . '&userid=' . $userid, 'notes' . $userid, get_string('notes', 'assignment'), 500, 780, get_string('notes', 'assignment'), 'none', true, 'notesbutton' . $userid); $output .= ' '; } if ($files = get_directory_list($basedir, 'responses')) { require_once $CFG->libdir . '/filelib.php'; foreach ($files as $key => $file) { $icon = mimeinfo('icon', $file); $ffurl = get_file_url("{$filearea}/{$file}"); $output .= '<a href="' . $ffurl . '" ><img class="icon" src="' . $CFG->pixpath . '/f/' . $icon . '" alt="' . $icon . '" />' . $file . '</a> '; } } } $output = '<div class="files">' . $output . '</div>'; $output .= '<br />'; return $output; }
/** * Prints the table of questions in a category with interactions * * @param object $course The course object * @param int $categoryid The id of the question category to be displayed * @param int $quizid The quiz id if we are in the context of a particular quiz, 0 otherwise * @param int $recurse This is 1 if subcategories should be included, 0 otherwise * @param int $page The number of the page to be displayed * @param int $perpage Number of questions to show per page * @param boolean $showhidden True if also hidden questions should be displayed * @param boolean $showquestiontext whether the text of each question should be shown in the list */ function question_list($course, $categoryid, $quizid = 0, $recurse = 1, $page = 0, $perpage = 100, $showhidden = false, $sortorder = 'qtype, name ASC', $showquestiontext = false) { global $USER, $CFG, $THEME; $qtypemenu = question_type_menu(); if ($rqp_types = get_records('question_rqp_types')) { foreach ($rqp_types as $type) { $qtypemenu['rqp_' . $type->id] = $type->name; } } $strcategory = get_string("category", "quiz"); $strquestion = get_string("question", "quiz"); $straddquestions = get_string("addquestions", "quiz"); $strimportquestions = get_string("importquestions", "quiz"); $strexportquestions = get_string("exportquestions", "quiz"); $strnoquestions = get_string("noquestions", "quiz"); $strselect = get_string("select", "quiz"); $strselectall = get_string("selectall", "quiz"); $strselectnone = get_string("selectnone", "quiz"); $strcreatenewquestion = get_string("createnewquestion", "quiz"); $strquestionname = get_string("questionname", "quiz"); $strdelete = get_string("delete"); $stredit = get_string("edit"); $straction = get_string("action"); $strrestore = get_string('restore'); $straddtoquiz = get_string("addtoquiz", "quiz"); $strtype = get_string("type", "quiz"); $strcreatemultiple = get_string("createmultiple", "quiz"); $strpreview = get_string("preview", "quiz"); if (!$categoryid) { echo "<p style=\"text-align:center;\"><b>"; print_string("selectcategoryabove", "quiz"); echo "</b></p>"; if ($quizid) { echo "<p>"; print_string("addingquestions", "quiz"); echo "</p>"; } return; } if (!($category = get_record('question_categories', 'id', $categoryid))) { notify('Category not found!'); return; } $canedit = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $category->course)); $editingquiz = false; if ($quizid) { $cm = get_coursemodule_from_instance('quiz', $quizid); $editingquiz = has_capability('mod/quiz:manage', get_context_instance(CONTEXT_MODULE, $cm->id)); } echo '<div class="boxaligncenter">'; $formatoptions = new stdClass(); $formatoptions->noclean = true; echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $course->id); echo '<table><tr>'; // check if editing questions in this category is allowed if ($canedit) { echo "<td valign=\"top\"><b>{$strcreatenewquestion}:</b></td>"; echo '<td valign="top" align="right">'; popup_form("{$CFG->wwwroot}/question/question.php?category={$category->id}&qtype=", $qtypemenu, "addquestion", "", "choose", "", "", false, "self"); echo '</td><td valign="top" align="right">'; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); echo '</td>'; } else { echo '<td>'; print_string("publishedit", "quiz"); echo '</td>'; } echo '</tr></table>'; echo '</div>'; $categorylist = $recurse ? question_categorylist($category->id) : $category->id; // hide-feature $showhidden = $showhidden ? '' : " AND hidden = '0'"; if (!($totalnumber = count_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}"))) { echo "<p style=\"text-align:center;\">"; print_string("noquestions", "quiz"); echo "</p>"; return; } if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorder, '*', $page * $perpage, $perpage))) { // There are no questions on the requested page. $page = 0; if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorder, '*', 0, $perpage))) { // There are no questions at all echo "<p style=\"text-align:center;\">"; print_string("noquestions", "quiz"); echo "</p>"; return; } } print_paging_bar($totalnumber, $page, $perpage, "edit.php?courseid={$course->id}&perpage={$perpage}&"); echo '<form method="post" action="edit.php?courseid=' . $course->id . '">'; echo '<fieldset class="invisiblefieldset" style="display: block;">'; echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />'; echo '<table id="categoryquestions" style="width: 100%"><tr>'; echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">{$straction}</th>"; $sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"), 'qtype, name ASC' => get_string("sorttypealpha", "quiz"), 'id ASC' => get_string("sortage", "quiz")); $orderselect = choose_from_menu($sortoptions, 'sortorder', $sortorder, false, 'this.form.submit();', '0', true); $orderselect .= '<noscript><div><input type="submit" value="' . get_string("sortsubmit", "quiz") . '" /></div></noscript>'; echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">{$strquestionname} {$orderselect}</th>\n <th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">{$strtype}</th>"; echo "</tr>\n"; foreach ($questions as $question) { $nameclass = ''; $textclass = ''; if ($question->hidden) { $nameclass = 'dimmed_text'; $textclass = 'dimmed_text'; } if ($showquestiontext) { $nameclass .= ' header'; } if ($nameclass) { $nameclass = 'class="' . $nameclass . '"'; } if ($textclass) { $textclass = 'class="' . $textclass . '"'; } echo "<tr>\n<td style=\"white-space:nowrap;\" {$nameclass}>\n"; // add to quiz if ($editingquiz) { echo "<a title=\"{$straddtoquiz}\" href=\"edit.php?addquestion={$question->id}&quizid={$quizid}&sesskey={$USER->sesskey}\"><img\n src=\"{$CFG->pixpath}/t/moveleft.gif\" alt=\"{$straddtoquiz}\" /></a> "; } // preview link_to_popup_window('/question/preview.php?id=' . $question->id . '&quizid=' . $quizid, 'questionpreview', "<img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strpreview}\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS); // edit, hide, delete question, using question capabilities, not quiz capabilieies if ($canedit) { echo "<a title=\"{$stredit}\" href=\"{$CFG->wwwroot}/question/question.php?id={$question->id}\"><img\n src=\"{$CFG->pixpath}/t/edit.gif\" alt=\"{$stredit}\" /></a> "; // hide-feature if ($question->hidden) { echo "<a title=\"{$strrestore}\" href=\"edit.php?courseid={$course->id}&unhide={$question->id}&sesskey={$USER->sesskey}\"><img\n src=\"{$CFG->pixpath}/t/restore.gif\" alt=\"{$strrestore}\" /></a>"; } else { echo "<a title=\"{$strdelete}\" href=\"edit.php?courseid={$course->id}&deleteselected={$question->id}&q{$question->id}=1\"><img\n src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"{$strdelete}\" /></a>"; } } echo " <input title=\"{$strselect}\" type=\"checkbox\" name=\"q{$question->id}\" value=\"1\" />"; echo "</td>\n"; echo "<td {$nameclass}>" . format_string($question->name) . "</td>\n"; echo "<td {$nameclass} style='text-align: right'>\n"; print_question_icon($question); echo "</td>\n"; echo "</tr>\n"; if ($showquestiontext) { echo '<tr><td colspan="3" ' . $textclass . '>'; $formatoptions = new stdClass(); $formatoptions->noclean = true; $formatoptions->para = false; echo format_text($question->questiontext, $question->questiontextformat, $formatoptions, $course->id); echo "</td></tr>\n"; } } echo "</table>\n"; $paging = print_paging_bar($totalnumber, $page, $perpage, "edit.php?courseid={$course->id}&perpage={$perpage}&", 'page', false, true); if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) { if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) { $showall = '<a href="edit.php?courseid=' . $course->id . '&perpage=1000">' . get_string('showall', 'moodle', $totalnumber) . '</a>'; } else { $showall = '<a href="edit.php?courseid=' . $course->id . '&perpage=' . DEFAULT_QUESTIONS_PER_PAGE . '">' . get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE) . '</a>'; } if ($paging) { $paging = substr($paging, 0, strrpos($paging, '</div>')); $paging .= "<br />{$showall}</div>"; } else { $paging = "<div class='paging'>{$showall}</div>"; } } echo $paging; echo '<table class="quiz-edit-selected"><tr><td colspan="2">'; echo '<a href="javascript:select_all_in(\'TABLE\',null,\'categoryquestions\');">' . $strselectall . '</a> /' . ' <a href="javascript:deselect_all_in(\'TABLE\',null,\'categoryquestions\');">' . $strselectnone . '</a>' . '</td><td align="right"><b> ' . get_string('withselected', 'quiz') . ':</b></td></tr><tr><td>'; if ($editingquiz) { echo "<input type=\"submit\" name=\"add\" value=\"{$THEME->larrow} {$straddtoquiz}\" />\n"; echo '</td><td>'; } // print delete and move selected question if ($canedit) { echo '<input type="submit" name="deleteselected" value="' . $strdelete . "\" /></td><td>\n"; echo '<input type="submit" name="move" value="' . get_string('moveto', 'quiz') . "\" />\n"; question_category_select_menu($course->id, false, true, $category->id); } echo "</td></tr></table>"; // add random question if ($editingquiz) { for ($i = 1; $i <= min(10, $totalnumber); $i++) { $randomcount[$i] = $i; } for ($i = 20; $i <= min(100, $totalnumber); $i += 10) { $randomcount[$i] = $i; } echo '<br />'; print_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true)); echo '<input type="hidden" name="recurse" value="' . $recurse . '" />'; echo "<input type=\"hidden\" name=\"categoryid\" value=\"{$category->id}\" />"; echo ' <input type="submit" name="addrandom" value="' . get_string('add') . '" />'; helpbutton('random', get_string('random', 'quiz'), 'quiz'); } echo '</fieldset>'; echo "</form>\n"; }
/** * Print a help button. * * @uses $CFG * @param string $page The keyword that defines a help page * @param string $title The title of links, rollover tips, alt tags etc * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped. * @param string $module Which module is the page defined in * @param mixed $image Use a help image for the link? (true/false/"both") * @param boolean $linktext If true, display the title next to the help icon. * @param string $text If defined then this text is used in the page, and * the $page variable is ignored. * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page. * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif * @return string * @todo Finish documenting this function */ function helpbutton($page, $title, $module = 'moodle', $image = true, $linktext = false, $text = '', $return = false, $imagetext = '') { global $CFG, $COURSE; //warning if ever $text parameter is used //$text option won't work properly because the text needs to be always cleaned and, // when cleaned... html tags always break, so it's unusable. if (isset($text) && $text != '') { debugging('Warning: it\'s not recommended to use $text parameter in helpbutton ($page=' . $page . ', $module=' . $module . ') function', DEBUG_DEVELOPER); } // Catch references to the old text.html and emoticons.html help files that // were renamed in MDL-13233. if (in_array($page, array('text', 'emoticons', 'richtext'))) { $oldname = $page; $page .= '2'; debugging("You are referring to the old help file '{$oldname}'. " . "This was renamed to '{$page}' becuase of MDL-13233. " . "Please update your code.", DEBUG_DEVELOPER); } if ($module == '') { $module = 'moodle'; } if ($title == '' && $linktext == '') { debugging('Error in call to helpbutton function: at least one of $title and $linktext is required'); } // Warn users about new window for Accessibility $tooltip = get_string('helpprefix2', '', trim($title, ". \t")) . ' (' . get_string('newwindow') . ')'; $linkobject = ''; if ($image) { if ($linktext) { // MDL-7469 If text link is displayed with help icon, change to alt to "help with this". $linkobject .= $title . ' '; $tooltip = get_string('helpwiththis'); } if ($imagetext) { $linkobject .= $imagetext; } else { $linkobject .= '<img class="iconhelp" alt="' . s(strip_tags($tooltip)) . '" src="' . $CFG->pixpath . '/help.gif" />'; } } else { $linkobject .= $tooltip; } // fix for MDL-7734 if ($text) { $url = '/help.php?text=' . s(urlencode($text)); } else { $url = '/help.php?module=' . $module . '&file=' . $page . '.html'; // fix for MDL-7734 if (!empty($COURSE->lang)) { $url .= '&forcelang=' . $COURSE->lang; } } $link = '<span class="helplink">' . link_to_popup_window($url, 'popup', $linkobject, 400, 500, $tooltip, 'none', true) . '</span>'; if ($return) { return $link; } else { echo $link; } }
} exit; case 'downloadasexcel': if (!print_log_xls($course, $user, $date, 'l.time DESC', $modname, $modid, $modaction, $group)) { notify("No logs found!"); print_footer($course); } exit; } } else { if ($hostid != $CFG->mnet_localhost_id || $hostid == $CFG->mnet_localhost_id && $course->id == SITEID) { $adminroot = admin_get_root(); admin_externalpage_setup('reportlog', $adminroot); admin_externalpage_print_header($adminroot); } else { print_header($course->shortname . ': ' . $strlogs, $course->fullname, "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> -> \n <a href=\"{$CFG->wwwroot}/course/report.php?id={$course->id}\">{$strreports}</a> ->\n {$strlogs}", ''); } print_heading(get_string('chooselogs') . ':'); print_log_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat); echo '<br />'; print_heading(get_string('chooselivelogs') . ':'); echo '<center><h3>'; link_to_popup_window('/course/report/log/live.php?id=' . $course->id, 'livelog', get_string('livelogs'), 500, 800); echo '</h3></center>'; } if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) { admin_externalpage_print_footer($adminroot); } else { print_footer($course); } exit;
/** * Display all the submissions ready for grading */ function display_submissions($message = '') { global $CFG, $db, $USER; require_once $CFG->libdir . '/gradelib.php'; /* first we check to see if the form has just been submitted * to request user_preference updates */ /*if (isset($_POST['updatepref'])){ $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = ($perpage <= 0) ? 10 : $perpage ; set_user_preference('problemstatement_perpage', $perpage); set_user_preference('problemstatement_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); }*/ /* next we get perpage and quickgrade (allow quick grade) params * from database */ $perpage = get_user_preferences('problemstatement_perpage', 10); $quickgrade = get_user_preferences('problemstatement_quickgrade', 0); $grading_info = grade_get_grades($this->course->id, 'mod', 'problemstatement', $this->problemstatement->id); if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { $uses_outcomes = true; } else { $uses_outcomes = false; } $page = optional_param('page', 0, PARAM_INT); $strsaveallfeedback = get_string('saveallfeedback', 'problemstatement'); /// Some shortcuts to make the code read better $course = $this->course; $problemstatement = $this->problemstatement; $cm = $this->cm; $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet add_to_log($course->id, 'problemstatement', 'view submission', 'submissions.php?id=' . $this->problemstatement->id, $this->problemstatement->id, $this->cm->id); $navigation = build_navigation($this->strsubmissions, $this->cm); print_header_simple(format_string($this->problemstatement->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strproblemstatement), navmenu($course, $cm)); $course_context = get_context_instance(CONTEXT_COURSE, $course->id); if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) { echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">' . get_string('seeallcoursegrades', 'grades') . '</a></div>'; } if (!empty($message)) { echo $message; // display messages here if any } $context = get_context_instance(CONTEXT_MODULE, $cm->id); /// Check to see if groups are being used in this problemstatement /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id); /// Get all ppl that are allowed to submit problemstatements if ($users = get_users_by_capability($context, 'mod/problemstatement:submit', 'u.id', '', '', '', $currentgroup, '', false)) { $users = array_keys($users); } // if groupmembersonly used, remove users who are not in any group if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) { if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { $users = array_intersect($users, array_keys($groupingusers)); } } $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); if ($uses_outcomes) { $tablecolumns[] = 'outcome'; // no sorting based on outcomes column } $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'problemstatement'), get_string('lastmodified') . ' (' . $course->student . ')', get_string('lastmodified') . ' (' . $course->teacher . ')', get_string('status'), get_string('finalgrade', 'grades')); if ($uses_outcomes) { $tableheaders[] = get_string('outcome', 'grades'); } require_once $CFG->libdir . '/tablelib.php'; $table = new flexible_table('mod-problemstatement-submissions'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/problemstatement/submissions.php?id=' . $this->cm->id . '&currentgroup=' . $currentgroup); $table->sortable(true, 'lastname'); //sorted by lastname by default $table->collapsible(true); $table->initialbars(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture'); $table->column_class('fullname', 'fullname'); $table->column_class('grade', 'grade'); $table->column_class('submissioncomment', 'comment'); $table->column_class('timemodified', 'timemodified'); $table->column_class('timemarked', 'timemarked'); $table->column_class('status', 'status'); $table->column_class('finalgrade', 'finalgrade'); if ($uses_outcomes) { $table->column_class('outcome', 'outcome'); } $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'submissions'); $table->set_attribute('width', '100%'); //$table->set_attribute('align', 'center'); $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); if (empty($users)) { print_heading(get_string('nosubmitusers', 'problemstatement')); return true; } /// Construct the SQL if ($where = $table->get_sql_where()) { $where .= ' AND '; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.processed, s.succeeded '; $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'problemstatement_submissions s ON u.id = s.userid AND s.problemstatement = ' . $this->problemstatement->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') '; $table->pagesize($perpage, count($users)); ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next $offset = $page * $perpage; $strupdate = get_string('update'); $strgrade = get_string('grade'); $grademenu = make_grades_menu($this->problemstatement->grade); //echo $select.$sql.$sort; if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) { $grading_info = grade_get_grades($this->course->id, 'mod', 'problemstatement', $this->problemstatement->id, array_keys($ausers)); foreach ($ausers as $auser) { $final_grade = $grading_info->items[0]->grades[$auser->id]; $grademax = $grading_info->items[0]->gradprocess_feedbackemax; $final_grade->formatted_grade = round($final_grade->grade, 2) . ' / ' . round($grademax, 2); $locked_overridden = 'locked'; if ($final_grade->overridden) { $locked_overridden = 'overridden'; } /// Calculate user status //$auser->status = $auser->status;//($auser->timemarked > 0) && ($auser->timemarked >= $auser->timemodified); $picture = print_user_picture($auser, $course->id, $auser->picture, false, true); if (empty($auser->submissionid)) { $auser->grade = -1; //no submission yet } if (!empty($auser->submissionid)) { ///Prints student answer and student modified date ///attach file or print link to student answer, depending on the type of the problemstatement. ///Refer to print_student_answer in inherited classes. if ($auser->timemodified > 0) { $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>'; } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; } ///Print grade, dropdown or text if ($auser->timemarked > 0) { $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>'; } else { if ($quickgrade) { $menu = choose_from_menu(make_grades_menu($this->problemstatement->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>'; } } } else { $teachermodified = '<div id="tt' . $auser->id . '"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>'; } else { if ($quickgrade) { $menu = choose_from_menu(make_grades_menu($this->problemstatement->grade), 'menprocess_feedbacku[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>'; } } } ///Print Comment if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($final_grade->str_feedback), 15) . '</div>'; } else { if ($quickgrade) { $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>'; } else { $msg = ""; $color = "#000000"; switch ($auser->processed) { case "0": $msg .= "unprocessed"; $color = "#AAAA00"; break; case "1": switch ($auser->succeeded) { case "4": //timeout //timeout case "6": //runtimeerror //runtimeerror case "2": //compilationerror //compilationerror case "5": //memoryout //memoryout case "0": $msg .= "failed"; $color = "#AA0000"; break; case "1": $msg .= "passed"; $color = "#00AA00"; break; case "3": $msg .= "internalerror"; $color = "#0000AA"; break; } break; case "2": $msg .= "waiting"; $color = "#00AAAA"; break; } //$comment='<div id="com'.$auser->id.'">'.shorten_text(strip_tags($auser->submissioncomment),15).'</div>'; $comment = '<div id="com' . $auser->id . '">' . '<div class="files"><font color="' . $color . '"><strong>' . $msg . '</strong></font></div>' . '</div>'; } } } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; $teachermodified = '<div id="tt' . $auser->id . '"> </div>'; $status = '<div id="st' . $auser->id . '"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '">' . $final_grade->formatted_grade . '</div>'; } else { if ($quickgrade) { // allow editing $menu = choose_from_menu(make_grades_menu($this->problemstatement->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">-</div>'; } } if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com' . $auser->id . '">' . $final_grade->str_feedback . '</div>'; } else { if ($quickgrade) { $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>'; } else { $comment = '<div id="com' . $auser->id . '"> </div>'; } } } if (empty($auser->processed)) { /// Confirm we have exclusively 0 or 1 //$auser->status = 0; } else { //$auser->status = 1; } $buttontext = $auser->processed == 1 ? $strupdate : $strgrade; ///No more buttons, we use popups ;-). $popup_url = '/mod/problemstatement/submissions.php?id=' . $this->cm->id . '&userid=' . $auser->id . '&mode=single' . '&offset=' . $offset++; $button = link_to_popup_window($popup_url, 'grade' . $auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'button' . $auser->id); $status = '<div id="up' . $auser->id . '" class="s' . $auser->processed . '">' . $button . '</div>'; $finalgrade = '<span id="finalgrade_' . $auser->id . '">' . $final_grade->str_grade . '</span>'; $outcomes = ''; if ($uses_outcomes) { foreach ($grading_info->outcomes as $n => $outcome) { $outcomes .= '<div class="outcome"><label>' . $outcome->name . '</label>'; $options = make_grades_menu(-$outcome->scaleid); if ($outcome->grades[$auser->id]->locked or !$quickgrade) { $options[0] = get_string('nooutcome', 'grades'); $outcomes .= ': <span id="outcome_' . $n . '_' . $auser->id . '">' . $options[$outcome->grades[$auser->id]->grade] . '</span>'; } else { $outcomes .= ' '; $outcomes .= choose_from_menu($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades'), '', 0, true, false, 0, 'outcome_' . $n . '_' . $auser->id); } $outcomes .= '</div>'; } } $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser) . '</a>'; $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade); if ($uses_outcomes) { $row[] = $outcomes; } $table->add_data($row); } } /// Print quickgrade form around the table if ($quickgrade) { echo '<form action="submissions.php" id="fastg" method="post">'; echo '<div>'; echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />'; echo '<input type="hidden" name="mode" value="fastgrade" />'; echo '<input type="hidden" name="page" value="' . $page . '" />'; echo '</div>'; } $table->print_html(); /// Print the whole table if ($quickgrade) { $lastmailinfo = get_user_preferences('problemstatement_mailinfo', 1) ? 'checked="checked"' : ''; echo '<div class="fgcontrols">'; echo '<div class="emailnotification">'; echo '<label for="mailinfo">' . get_string('enableemailnotification', 'problemstatement') . '</label>'; echo '<input type="hidden" name="mailinfo" value="0" />'; echo '<input type="checkbox" id="mailinfo" name="mailinfo" value="1" ' . $lastmailinfo . ' />'; helpbutton('emailnotification', get_string('enableemailnotification', 'problemstatement'), 'problemstatement') . '</p></div>'; echo '</div>'; echo '<div class="fastgbutton"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'problemstatement') . '" /></div>'; echo '</div>'; echo '</form>'; } /// End of fast grading form /// Mini form for setting user preference echo '<div class="qgprefs">'; echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post"><div>'; echo '<input type="hidden" name="updatepref" value="1" />'; echo '<table id="optiontable">'; echo '<tr><td>'; echo '<label for="perpage">' . get_string('pagesize', 'problemstatement') . '</label>'; echo '</td>'; echo '<td>'; echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />'; helpbutton('pagesize', get_string('pagesize', 'problemstatement'), 'problemstatement'); echo '</td></tr>'; echo '<tr><td>'; echo '<label for="quickgrade">' . get_string('quickgrade', 'problemstatement') . '</label>'; echo '</td>'; echo '<td>'; $checked = $quickgrade ? 'checked="checked"' : ''; echo '<input type="checkbox" id="quickgrade" name="quickgrade" value="1" ' . $checked . ' />'; helpbutton('quickgrade', get_string('quickgrade', 'problemstatement'), 'problemstatement') . '</p></div>'; echo '</td></tr>'; echo '<tr><td colspan="2">'; echo '<input type="submit" value="' . get_string('savepreferences') . '" />'; echo '</td></tr></table>'; echo '</div></form></div>'; ///End of mini form print_footer($this->course); }
/** * Display the file resource * * Displays a file resource embedded, in a frame, or in a popup. * Output depends on type of file resource. * * @param CFG global object */ function display() { global $CFG, $THEME, $USER; /// Set up generic stuff first, including checking for access parent::display(); /// Set up some shorthand variables $cm = $this->cm; $course = $this->course; $resource = $this->resource; $this->set_parameters(); // set the parameters array /////////////////////////////////////////////// /// Possible display modes are: /// File displayed in a frame in a normal window /// File displayed embedded in a normal page /// File displayed in a popup window /// File displayed emebedded in a popup window /// First, find out what sort of file we are dealing with. require_once $CFG->libdir . '/filelib.php'; $querystring = ''; $resourcetype = ''; $embedded = false; $mimetype = mimeinfo("type", $resource->reference); $pagetitle = strip_tags($course->shortname . ': ' . format_string($resource->name)); $formatoptions = new object(); $formatoptions->noclean = true; if ($resource->options != "bogusoption_usedtobe_frame") { // TODO nicolasconnault 14-03-07: This option should be renamed "embed" if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // It's an image $resourcetype = "image"; $embedded = true; } else { if ($mimetype == "audio/mp3") { // It's an MP3 audio file $resourcetype = "mp3"; $embedded = true; } else { if ($mimetype == "video/x-flv") { // It's a Flash video file $resourcetype = "flv"; $embedded = true; } else { if (substr($mimetype, 0, 10) == "video/x-ms") { // It's a Media Player file $resourcetype = "mediaplayer"; $embedded = true; } else { if ($mimetype == "video/quicktime") { // It's a Quicktime file $resourcetype = "quicktime"; $embedded = true; } else { if ($mimetype == "application/x-shockwave-flash") { // It's a Flash file $resourcetype = "flash"; $embedded = true; } else { if ($mimetype == "video/mpeg") { // It's a Mpeg file $resourcetype = "mpeg"; $embedded = true; } else { if ($mimetype == "text/html") { // It's a web page $resourcetype = "html"; } else { if ($mimetype == "application/zip") { // It's a zip archive $resourcetype = "zip"; $embedded = true; } else { if ($mimetype == 'application/pdf' || $mimetype == 'application/x-pdf') { $resourcetype = "pdf"; $embedded = true; } } } } } } } } } } } $isteamspeak = stripos($resource->reference, 'teamspeak://') === 0; /// Form the parse string if (!empty($resource->alltext)) { $querys = array(); $parray = explode(',', $resource->alltext); foreach ($parray as $fieldstring) { $field = explode('=', $fieldstring); $querys[] = urlencode($field[1]) . '=' . urlencode($this->parameters[$field[0]]['value']); } if ($isteamspeak) { $querystring = implode('?', $querys); } else { $querystring = implode('&', $querys); } } /// Set up some variables $inpopup = optional_param('inpopup', 0, PARAM_BOOL); if (resource_is_url($resource->reference)) { $fullurl = $resource->reference; if (!empty($querystring)) { $urlpieces = parse_url($resource->reference); if (empty($urlpieces['query']) or $isteamspeak) { $fullurl .= '?' . $querystring; } else { $fullurl .= '&' . $querystring; } } } else { if ($CFG->resource_allowlocalfiles and strpos($resource->reference, RESOURCE_LOCALPATH) === 0) { // Localpath $localpath = get_user_preferences('resource_localpath', 'D:'); $relativeurl = str_replace(RESOURCE_LOCALPATH, $localpath, $resource->reference); if ($querystring) { $relativeurl .= '?' . $querystring; } $relativeurl = str_replace('\\', '/', $relativeurl); $relativeurl = str_replace(' ', '%20', $relativeurl); $fullurl = 'file:///' . htmlentities($relativeurl); $localpath = true; } else { // Normal uploaded file if ($CFG->slasharguments) { $relativeurl = "/file.php/{$course->id}/{$resource->reference}"; if ($querystring) { $relativeurl .= '?' . $querystring; } } else { $relativeurl = "/file.php?file=/{$course->id}/{$resource->reference}"; if ($querystring) { $relativeurl .= '&' . $querystring; } } $fullurl = "{$CFG->wwwroot}{$relativeurl}"; } } /// Print a notice and redirect if we are trying to access a file on a local file system /// and the config setting has been disabled if (!$CFG->resource_allowlocalfiles and strpos($resource->reference, RESOURCE_LOCALPATH) === 0) { if ($inpopup) { print_header($pagetitle, $course->fullname); } else { $this->navlinks[] = array('name' => format_string($resource->name), 'link' => null, 'type' => 'misc'); $this->navigation = build_navigation($this->navlinks); print_header($pagetitle, $course->fullname, $this->navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); } notify(get_string('notallowedlocalfileaccess', 'resource', '')); if ($inpopup) { close_window_button(); } print_footer('none'); die; } /// Check whether this is supposed to be a popup, but was called directly if ($resource->popup and !$inpopup) { /// Make a page and a pop-up window $this->navlinks[] = array('name' => format_string($resource->name), 'link' => null, 'type' => 'misc'); $this->navigation = build_navigation($this->navlinks); print_header($pagetitle, $course->fullname, $this->navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); echo "\n<script type=\"text/javascript\">"; echo "\n<!--\n"; echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n"; echo "\n-->\n"; echo '</script>'; if (trim(strip_tags($resource->summary))) { print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center"); } $link = "<a href=\"{$CFG->wwwroot}/mod/resource/view.php?inpopup=true&id={$cm->id}\" " . "onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', " . "'resource{$resource->id}','{$resource->popup}');\">" . format_string($resource->name, true) . "</a>"; echo '<div class="popupnotice">'; print_string('popupresource', 'resource'); echo '<br />'; print_string('popupresourcelink', 'resource', $link); echo '</div>'; print_footer($course); exit; } /// Now check whether we need to display a frameset $frameset = optional_param('frameset', '', PARAM_ALPHA); if (empty($frameset) and !$embedded and !$inpopup and $resource->options == "frame" and empty($USER->screenreader)) { @header('Content-Type: text/html; charset=utf-8'); echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n"; echo "<html dir=\"ltr\">\n"; echo '<head>'; echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'; echo "<title>" . format_string($course->shortname) . ": " . strip_tags(format_string($resource->name, true)) . "</title></head>\n"; echo "<frameset rows=\"{$CFG->resource_framesize},*\">"; echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&frameset=top\" title=\"" . get_string('modulename', 'resource') . "\"/>"; if (!empty($localpath)) { // Show it like this so we interpose some HTML echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&inpopup=true\" title=\"" . get_string('modulename', 'resource') . "\"/>"; } else { echo "<frame src=\"{$fullurl}\" title=\"" . get_string('modulename', 'resource') . "\"/>"; } echo "</frameset>"; echo "</html>"; exit; } /// We can only get here once per resource, so add an entry to the log add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); /// If we are in a frameset, just print the top of it if (!empty($frameset) and $frameset == "top") { $this->navlinks[] = array('name' => format_string($resource->name), 'link' => null, 'type' => 'misc'); $this->navigation = build_navigation($this->navlinks); print_header($pagetitle, $course->fullname, $this->navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent")); $options = new object(); $options->para = false; echo '<div class="summary">' . format_text($resource->summary, FORMAT_HTML, $options) . '</div>'; if (!empty($localpath)) { // Show some help echo '<div align="right" class="helplink">'; link_to_popup_window('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp', 'resource'), 400, 500, get_string('localfilehelp', 'resource')); echo '</div>'; } echo '</div></div></body></html>'; exit; } /// Display the actual resource if ($embedded) { // Display resource embedded in page $strdirectlink = get_string("directlink", "resource"); if ($inpopup) { print_header($pagetitle); } else { $this->navlinks[] = array('name' => format_string($resource->name, true), 'link' => $fullurl, 'type' => 'misc'); $this->navigation = build_navigation($this->navlinks); print_header_simple($pagetitle, '', $this->navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "self")); } if ($resourcetype == "image") { echo '<div class="resourcecontent resourceimg">'; echo "<img title=\"" . strip_tags(format_string($resource->name, true)) . "\" class=\"resourceimage\" src=\"{$fullurl}\" alt=\"\" />"; echo '</div>'; } else { if ($resourcetype == "mp3") { if (!empty($THEME->resource_mp3player_colors)) { $c = $THEME->resource_mp3player_colors; // You can set this up in your theme/xxx/config.php } else { $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&' . 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&' . 'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes'; } $c .= '&volText=' . get_string('vol', 'resource') . '&panText=' . get_string('pan', 'resource'); $c = htmlentities($c); $id = 'filter_mp3_' . time(); //we need something unique because it might be stored in text cache $cleanurl = addslashes_js($fullurl); // If we have Javascript, use UFO to embed the MP3 player, otherwise depend on plugins echo '<div class="resourcecontent resourcemp3">'; echo '<span class="mediaplugin mediaplugin_mp3" id="' . $id . '"></span>' . '<script type="text/javascript">' . "\n" . '//<![CDATA[' . "\n" . 'var FO = { movie:"' . $CFG->wwwroot . '/lib/mp3player/mp3player.swf?src=' . $cleanurl . '",' . "\n" . 'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"' . $c . '", quality: "high" };' . "\n" . 'UFO.create(FO, "' . $id . '");' . "\n" . '//]]>' . "\n" . '</script>' . "\n"; echo '<noscript>'; echo "<object type=\"audio/mpeg\" data=\"{$fullurl}\" width=\"600\" height=\"70\">"; echo "<param name=\"src\" value=\"{$fullurl}\" />"; echo '<param name="quality" value="high" />'; echo '<param name="autoplay" value="true" />'; echo '<param name="autostart" value="true" />'; echo '</object>'; echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>'; echo '</noscript>'; echo '</div>'; } else { if ($resourcetype == "flv") { $id = 'filter_flv_' . time(); //we need something unique because it might be stored in text cache $cleanurl = addslashes_js($fullurl); // If we have Javascript, use UFO to embed the FLV player, otherwise depend on plugins echo '<div class="resourcecontent resourceflv">'; echo '<span class="mediaplugin mediaplugin_flv" id="' . $id . '"></span>' . '<script type="text/javascript">' . "\n" . '//<![CDATA[' . "\n" . 'var FO = { movie:"' . $CFG->wwwroot . '/filter/mediaplugin/flvplayer.swf?file=' . $cleanurl . '",' . "\n" . 'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", quality: "high" };' . "\n" . 'UFO.create(FO, "' . $id . '");' . "\n" . '//]]>' . "\n" . '</script>' . "\n"; echo '<noscript>'; echo "<object type=\"video/x-flv\" data=\"{$fullurl}\" width=\"600\" height=\"400\">"; echo "<param name=\"src\" value=\"{$fullurl}\" />"; echo '<param name="quality" value="high" />'; echo '<param name="autoplay" value="true" />'; echo '<param name="autostart" value="true" />'; echo '</object>'; echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>'; echo '</noscript>'; echo '</div>'; } else { if ($resourcetype == "mediaplayer") { echo '<div class="resourcecontent resourcewmv">'; echo '<object type="video/x-ms-wmv" data="' . $fullurl . '">'; echo '<param name="controller" value="true" />'; echo '<param name="autostart" value="true" />'; echo "<param name=\"src\" value=\"{$fullurl}\" />"; echo '<param name="scale" value="noScale" />'; echo "<a href=\"{$fullurl}\">{$fullurl}</a>"; echo '</object>'; echo '</div>'; } else { if ($resourcetype == "mpeg") { echo '<div class="resourcecontent resourcempeg">'; echo '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsm p2inf.cab#Version=5,1,52,701" type="application/x-oleobject">'; echo "<param name=\"fileName\" value=\"{$fullurl}\" />"; echo '<param name="autoStart" value="true" />'; echo '<param name="animationatStart" value="true" />'; echo '<param name="transparentatStart" value="true" />'; echo '<param name="showControls" value="true" />'; echo '<param name="Volume" value="-450" />'; echo '<!--[if !IE]>-->'; echo '<object type="video/mpeg" data="' . $fullurl . '">'; echo '<param name="controller" value="true" />'; echo '<param name="autostart" value="true" />'; echo "<param name=\"src\" value=\"{$fullurl}\" />"; echo "<a href=\"{$fullurl}\">{$fullurl}</a>"; echo '<!--<![endif]-->'; echo '<a href="' . $fullurl . '">' . $fullurl . '</a>'; echo '<!--[if !IE]>-->'; echo '</object>'; echo '<!--<![endif]-->'; echo '</object>'; echo '</div>'; } else { if ($resourcetype == "quicktime") { echo '<style type="text/css">'; echo '/* class to hide nested objects in IE */'; echo '/* hides the second object from all versions of IE */'; echo '* html object.hiddenObjectForIE { display: none; }'; echo '/* display the second object only for IE5 Mac */'; echo '/* IE Mac \\*//*/'; echo '* html object.hiddenObjectForIE { display: inline; }'; echo '/**/'; echo '</style>'; echo '<div class="resourcecontent resourceqt">'; echo '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"'; echo ' codebase="http://www.apple.com/qtactivex/qtplugin.cab">'; echo "<param name=\"src\" value=\"{$fullurl}\" />"; echo '<param name="autoplay" value="true" />'; echo '<param name="loop" value="true" />'; echo '<param name="controller" value="true" />'; echo '<param name="scale" value="aspect" />'; echo "<object class=\"hiddenObjectForIE\" type=\"video/quicktime\" data=\"{$fullurl}\">"; echo '<param name="controller" value="true" />'; echo '<param name="autoplay" value="true" />'; echo '<param name="loop" value="true" />'; echo '<param name="scale" value="aspect" />'; echo '</object>'; echo '<a href="' . $fullurl . '">' . $fullurl . '</a>'; echo '</object>'; echo '</div>'; } else { if ($resourcetype == "flash") { echo '<div class="resourcecontent resourceswf">'; echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">'; echo "<param name=\"movie\" value=\"{$fullurl}\" />"; echo '<param name="autoplay" value="true" />'; echo '<param name="loop" value="true" />'; echo '<param name="controller" value="true" />'; echo '<param name="scale" value="aspect" />'; echo '<!--[if !IE]>-->'; echo "<object type=\"application/x-shockwave-flash\" data=\"{$fullurl}\">"; echo '<param name="controller" value="true" />'; echo '<param name="autoplay" value="true" />'; echo '<param name="loop" value="true" />'; echo '<param name="scale" value="aspect" />'; echo '<!--<![endif]-->'; echo '<a href="' . $fullurl . '">' . $fullurl . '</a>'; echo '<!--[if !IE]>-->'; echo '</object>'; echo '<!--<![endif]-->'; echo '</object>'; echo '</div>'; } elseif ($resourcetype == 'zip') { echo '<div class="resourcepdf">'; echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name) . '</a>'; echo '</div>'; } elseif ($resourcetype == 'pdf') { echo '<div class="resourcepdf">'; echo '<object data="' . $fullurl . '" type="application/pdf">'; echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name) . '</a>'; echo '</object>'; echo '</div>'; } } } } } } } if (trim($resource->summary)) { print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center"); } if ($inpopup) { echo "<div class=\"popupnotice\">(<a href=\"{$fullurl}\">{$strdirectlink}</a>)</div>"; } else { print_spacer(20, 20); print_footer($course); } } else { // Display the resource on it's own if (!empty($localpath)) { // Show a link to help work around browser security echo '<div align="right" class="helplink">'; link_to_popup_window('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp', 'resource'), 400, 500, get_string('localfilehelp', 'resource')); echo '</div>'; echo "<div class=\"popupnotice\">(<a href=\"{$fullurl}\">{$fullurl}</a>)</div>"; } redirect($fullurl); } }
/** * Display the report. */ public function display($game, $cm, $course) { global $CFG, $SESSION, $DB; // Define some strings. $strreallydel = addslashes(get_string('deleteattemptcheck', 'game')); $strtimeformat = get_string('strftimedatetime'); $strreviewquestion = get_string('reviewresponse', 'quiz'); // Only print headers if not asked to download data. if (!($download = optional_param('download', null))) { $this->print_header_and_tabs($cm, $course, $game, $reportmode = "overview"); } // Deal with actions. $action = optional_param('action', '', PARAM_ACTION); switch ($action) { case 'delete': // Some attempts need to be deleted. $attemptids = optional_param('attemptid', array(), PARAM_INT); foreach ($attemptids as $attemptid) { if ($attemptid && ($todelete = get_record('game_attempts', 'id', $attemptid))) { delete_records('game_attempts', 'id', $attemptid); delete_records('game_queries', 'attemptid', $attemptid); // Search game_attempts for other instances by this user. // If none, then delete record for this game, this user from game_grades. // else recalculate best grade. $userid = $todelete->userid; if (!record_exists('game_attempts', 'userid', $userid, 'gameid', $game->id)) { delete_records('game_grades', 'userid', $userid, 'gameid', $game->id); } else { game_save_best_score($game, $userid); } } } break; } // Print information on the number of existing attempts. if (!$download) { // Do not print notices when downloading. if ($attemptnum = count_records('game_attempts', 'gameid', $game->id)) { $a = new stdClass(); $a->attemptnum = $attemptnum; $a->studentnum = count_records_select('game_attempts', "gameid = '{$game->id}' AND preview = '0'", 'COUNT(DISTINCT userid)'); $a->studentstring = $course->students; notify(get_string('numattempts', 'game', $a)); } } $context = get_context_instance(CONTEXT_MODULE, $cm->id); // Find out current groups mode. if ($groupmode = groupmode($course, $cm)) { // Groups are being used. if (!$download) { $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&mode=overview"); } else { $currentgroup = get_and_set_current_group($course, $groupmode); } } else { $currentgroup = get_and_set_current_group($course, $groupmode); } // Set table options. $noattempts = optional_param('noattempts', 0, PARAM_INT); $detailedmarks = optional_param('detailedmarks', 0, PARAM_INT); $pagesize = optional_param('pagesize', 10, PARAM_INT); $hasfeedback = game_has_feedback($game->id) && $game->grade > 1.0E-7; if ($pagesize < 1) { $pagesize = 10; } // Now check if asked download of data. if ($download) { $filename = clean_filename("{$course->shortname} " . format_string($game->name, true)); $sort = ''; } // Define table columns. $tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'timefinish', 'duration'); $tableheaders = array(null, '', get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game')); if ($game->grade) { $tablecolumns[] = 'grade'; $tableheaders[] = get_string('grade', 'game') . '/' . $game->grade; } if ($detailedmarks) { // We want to display marks for all questions. // Start by getting all questions. $questionlist = game_questions_in_game($game->questions); $questionids = explode(',', $questionlist); $sql = "SELECT q.*, i.score AS maxgrade, i.id AS instance" . " FROM {question} q," . " {game_queries} i" . " WHERE i.gameid = '{$game->id}' AND q.id = i.questionid" . " AND q.id IN ({$questionlist})"; if (!($questions = get_records_sql($sql))) { print_error('No questions found'); } $number = 1; foreach ($questionids as $key => $id) { if ($questions[$id]->length) { // Only print questions of non-zero length. $tablecolumns[] = '$' . $id; $tableheaders[] = '#' . $number; $questions[$id]->number = $number; $number += $questions[$id]->length; } else { // Get rid of zero length questions. unset($questions[$id]); unset($questionids[$key]); } } } if ($hasfeedback) { $tablecolumns[] = 'feedbacktext'; $tableheaders[] = get_string('feedback', 'game'); } if (!$download) { // Set up the table. $table = new flexible_table('mod-game-report-overview-report'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/game/report.php?mode=overview&id=' . $cm->id . '&noattempts=' . $noattempts . '&detailedmarks=' . $detailedmarks . '&pagesize=' . $pagesize); $table->sortable(true); $table->collapsible(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'generaltable generalbox'); // Start working -- this is necessary as soon as the niceties are over. $table->setup(); } else { if ($download == 'ODS') { require_once "{$CFG->libdir}/odslib.class.php"; $filename .= ".ods"; // Creating a workbook. $workbook = new MoodleODSWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. $sheettitle = get_string('reportoverview', 'game'); $myxls =& $workbook->add_worksheet($sheettitle); // Format types. $format =& $workbook->add_format(); $format->set_bold(0); $formatbc =& $workbook->add_format(); $formatbc->set_bold(1); $formatbc->set_align('center'); $formatb =& $workbook->add_format(); $formatb->set_bold(1); $formaty =& $workbook->add_format(); $formaty->set_bg_color('yellow'); $formatc =& $workbook->add_format(); $formatc->set_align('center'); $formatr =& $workbook->add_format(); $formatr->set_bold(1); $formatr->set_color('red'); $formatr->set_align('center'); $formatg =& $workbook->add_format(); $formatg->set_bold(1); $formatg->set_color('green'); $formatg->set_align('center'); // Here starts workshhet headers. $headers = array(get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game')); if ($game->grade) { $headers[] = get_string('grade', 'game') . '/' . $game->grade; } if ($detailedmarks) { foreach ($questionids as $id) { $headers[] = '#' . $questions[$id]->number; } } if ($hasfeedback) { $headers[] = get_string('feedback', 'game'); } $colnum = 0; foreach ($headers as $item) { $myxls->write(0, $colnum, $item, $formatbc); $colnum++; } $rownum = 1; } else { if ($download == 'Excel') { require_once "{$CFG->libdir}/excellib.class.php"; $filename .= ".xls"; // Creating a workbook. $workbook = new MoodleExcelWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. $sheettitle = get_string('reportoverview', 'game'); $myxls =& $workbook->add_worksheet($sheettitle); // Format types. $format =& $workbook->add_format(); $format->set_bold(0); $formatbc =& $workbook->add_format(); $formatbc->set_bold(1); $formatbc->set_align('center'); $formatb =& $workbook->add_format(); $formatb->set_bold(1); $formaty =& $workbook->add_format(); $formaty->set_bg_color('yellow'); $formatc =& $workbook->add_format(); $formatc->set_align('center'); $formatr =& $workbook->add_format(); $formatr->set_bold(1); $formatr->set_color('red'); $formatr->set_align('center'); $formatg =& $workbook->add_format(); $formatg->set_bold(1); $formatg->set_color('green'); $formatg->set_align('center'); // Here starts workshhet headers. $headers = array(get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game')); if ($game->grade) { $headers[] = get_string('grade', 'game') . '/' . $game->grade; } if ($detailedmarks) { foreach ($questionids as $id) { $headers[] = '#' . $questions[$id]->number; } } if ($hasfeedback) { $headers[] = get_string('feedback', 'game'); } $colnum = 0; foreach ($headers as $item) { $myxls->write(0, $colnum, $item, $formatbc); $colnum++; } $rownum = 1; } else { if ($download == 'CSV') { $filename .= ".txt"; header("Content-Type: application/download\n"); header("Content-Disposition: attachment; filename=\"{$filename}\""); header("Expires: 0"); header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); header("Pragma: public"); $headers = get_string('fullname') . "\t" . get_string('startedon', 'game') . "\t" . get_string('timecompleted', 'game') . "\t" . get_string('attemptduration', 'game'); if ($game->grade) { $headers .= "\t" . get_string('grade', 'game') . "/" . $game->grade; } if ($detailedmarks) { foreach ($questionids as $id) { $headers .= "\t#" . $questions[$id]->number; } } if ($hasfeedback) { $headers .= "\t" . get_string('feedback', 'game'); } echo $headers . " \n"; } } } } $contextlists = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $course->id)); // Construct the SQL. $select = 'SELECT qa.id,' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ' AS uniqueid, ' . 'qa.id as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, ' . 'qa.score, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration '; if ($course->id != SITEID) { // This is too complicated, so just do it for each of the four cases. if (!empty($currentgroup) && empty($noattempts)) { // We want a particular group and we only want to see students WITH attempts. // So join on groups_members and do an inner join on attempts. $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id ' . groups_members_join_sql() . 'JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = ' . $game->id; $where = ' WHERE ra.contextid ' . $contextlists . ' AND ' . groups_members_where_sql($currentgroup) . ' AND qa.preview = 0'; } else { if (!empty($currentgroup) && !empty($noattempts)) { // We want a particular group and we want to do something funky with attempts. // So join on groups_members and left join on attempts... $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id ' . groups_members_join_sql() . 'LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = ' . $game->id; $where = ' WHERE ra.contextid ' . $contextlists . ' AND ' . groups_members_where_sql($currentgroup); if ($noattempts == 1) { // Noattempts = 1 means only no attempts, so make the left join ask. // For only records where the right is null (no attempts). $where .= ' AND qa.userid IS NULL'; // Show ONLY no attempts. } else { // We are including attempts, so exclude previews. $where .= ' AND qa.preview = 0'; } } else { if (empty($currentgroup)) { // We don't care about group, and we to do something funky with attempts. // So do a left join on attempts. $from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id ' . ' LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = ' . $game->id; $where = " WHERE ra.contextid {$contextlists}"; if (empty($noattempts)) { // Show ONLY students with attempts. $where .= ' AND qa.userid IS NOT NULL AND qa.preview = 0'; } else { if ($noattempts == 1) { // The noattempts = 1 means only no attempts,. // So make the left join ask for only records where the right is null (no attempts). // Show ONLY students without attempts. $where .= ' AND qa.userid IS NULL'; } else { if ($noattempts == 3) { // We want all attempts. $from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid '; $where = ' WHERE qa.gameid = ' . $game->id . ' AND qa.preview = 0'; } } } // The noattempts = 2 means we want all students, with or without attempts. } } } $countsql = 'SELECT COUNT(DISTINCT(' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ')) ' . $from . $where; } else { if (empty($noattempts)) { $from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid '; $where = ' WHERE qa.gameid = ' . $game->id . ' AND qa.preview = 0'; $countsql = 'SELECT COUNT(DISTINCT(' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ')) ' . $from . $where; } } if (!$download) { // Add extra limits due to initials bar. if ($table->get_sql_where()) { $where .= ' AND ' . $table->get_sql_where(); } // Count the records NOW, before funky question grade sorting messes up $from. if (!empty($countsql)) { $totalinitials = count_records_sql($countsql); if ($table->get_sql_where()) { $countsql .= ' AND ' . $table->get_sql_where(); } $total = count_records_sql($countsql); } // Add extra limits due to sorting by question grade. if ($sort = $table->get_sql_sort()) { $sortparts = explode(',', $sort); $newsort = array(); $questionsort = false; foreach ($sortparts as $sortpart) { $sortpart = trim($sortpart); if (substr($sortpart, 0, 1) == '$') { if (!$questionsort) { $qid = intval(substr($sortpart, 1)); $select .= ', grade '; $from .= ' LEFT JOIN {question_sessions} qns ON qns.attemptid = qa.id ' . 'LEFT JOIN {question_states} qs ON qs.id = qns.newgraded '; $where .= ' AND (' . sql_isnull('qns.questionid') . ' OR qns.questionid = ' . $qid . ')'; $newsort[] = 'grade ' . (strpos($sortpart, 'ASC') ? 'ASC' : 'DESC'); $questionsort = true; } } else { $newsort[] = $sortpart; } } // Reconstruct the sort string. $sort = ' ORDER BY ' . implode(', ', $newsort); } // Fix some wired sorting. if (empty($sort)) { $sort = ' ORDER BY qa.id'; } $table->pagesize($pagesize, $total); } // If there is feedback, include it in the query. if ($hasfeedback) { $select .= ', qf.feedbacktext '; $from .= " JOIN {game_feedback} qf ON " . "qf.gameid = {$game->id} AND qf.mingrade <= qa.score * {$game->grade} AND qa.score * {$game->grade} < qf.maxgrade"; } // Fetch the attempts. if (!empty($from)) { // If we're in the site course and displaying no attempts, it makes no sense to do the query. if (!$download) { $attempts = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size()); } else { $attempts = get_records_sql($select . $from . $where . $sort); } } else { $attempts = array(); } // Build table rows. if (!$download) { $table->initialbars($totalinitials > 20); } if (!empty($attempts) || !empty($noattempts)) { if ($attempts) { foreach ($attempts as $attempt) { $picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true); /* Uncomment the commented lines below if you are choosing to show unenrolled users and * have uncommented the corresponding lines earlier in this script * if (in_array($attempt->userid, $unenrolledusers)) { * $userlink = '<a class="dimmed" href="'.$CFG->wwwroot. * '/user/view.php?id='.$attempt->userid.'&course='.$course->id.'">'.fullname($attempt).'</a>'; *} *else { * $userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='. * $attempt->userid.'&course='.$course->id.'">'.fullname($attempt).'</a>'; *} */ if (!$download) { $row = array('<input type="checkbox" name="attemptid[]" value="' . $attempt->attempt . '" />', $picture, $userlink, empty($attempt->attempt) ? '-' : '<a href="review.php?q=' . $game->id . '&attempt=' . $attempt->attempt . '">' . userdate($attempt->timestart, $strtimeformat) . '</a>', empty($attempt->timefinish) ? '-' : '<a href="review.php?q=' . $game->id . '&attempt=' . $attempt->attempt . '">' . userdate($attempt->timefinish, $strtimeformat) . '</a>', empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration))); } else { $row = array(fullname($attempt), empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat), empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish, $strtimeformat), empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration))); } if ($game->grade) { if (!$download) { $row[] = $attempt->score === null ? '-' : '<a href="review.php?q=' . $game->id . '&attempt=' . $attempt->attempt . '">' . round($attempt->score * $game->grade, $game->decimalpoints) . '</a>'; } else { $row[] = $attempt->score === null ? '-' : round($attempt->score * $game->grade, $game->decimalpoints); } } if ($detailedmarks) { if (empty($attempt->attempt)) { foreach ($questionids as $questionid) { $row[] = '-'; } } else { foreach ($questionids as $questionid) { if ($gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) { $grade = round(get_field('question_states', 'grade', 'id', $gradedstateid), $game->decimalpoints); } else { $grade = '--'; } if (!$download) { $row[] = link_to_popup_window('/mod/game/reviewquestion.php?state=' . $gradedstateid . '&number=' . $questions[$questionid]->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true); } else { $row[] = $grade; } } } } if ($hasfeedback) { if ($attempt->timefinish) { $row[] = $attempt->feedbacktext; } else { $row[] = '-'; } } if (!$download) { $table->add_data($row); } else { if ($download == 'Excel' or $download == 'ODS') { $colnum = 0; foreach ($row as $item) { $myxls->write($rownum, $colnum, $item, $format); $colnum++; } $rownum++; } else { if ($download == 'CSV') { $text = implode("\t", $row); echo $text . " \n"; } } } } } if (!$download) { // Start form. echo '<div id="tablecontainer">'; echo '<form id="attemptsform" method="post" action="report.php" ' . 'onsubmit="var menu = document.getElementById(\'menuaction\'); ' . 'return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\'' . $strreallydel . '\') : true);">'; echo '<div>'; echo '<input type="hidden" name="id" value="' . $cm->id . '" />'; echo '<input type="hidden" name="mode" value="overview" />'; // Print table. $table->print_html(); // Print "Select all" etc.. if (!empty($attempts)) { echo '<table id="commands">'; echo '<tr><td>'; echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectall', 'game') . '</a> / '; echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectnone', 'game') . '</a> '; echo ' '; $options = array('delete' => get_string('delete')); echo choose_from_menu($options, 'action', '', get_string('withselected', 'game'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true); echo '<noscript id="noscriptmenuaction" style="display: inline;"><div>'; echo '<input type="submit" value="' . get_string('go') . '" /></div></noscript>'; echo '<script type="text/javascript">' . "\n<!--\n" . 'document.getElementById("noscriptmenuaction").style.display = "none";' . "\n-->\n" . '</script>'; echo '</td></tr></table>'; } // Close form. echo '</div>'; echo '</form></div>'; if (!empty($attempts)) { echo '<table class="boxaligncenter"><tr>'; $options = array(); $options["id"] = "{$cm->id}"; $options["q"] = "{$game->id}"; $options["mode"] = "overview"; $options['sesskey'] = sesskey(); $options["noheader"] = "yes"; $options['noattempts'] = $noattempts; $options['detailedmarks'] = $detailedmarks; echo '<td>'; $options["download"] = "ODS"; print_single_button("report.php", $options, get_string("downloadods", 'game')); echo "</td>\n"; echo '<td>'; $options["download"] = "Excel"; print_single_button("report.php", $options, get_string("downloadexcel")); echo "</td>\n"; echo '<td>'; $options["download"] = "CSV"; print_single_button('report.php', $options, get_string("downloadtext")); echo "</td>\n"; echo "<td>"; helpbutton('overviewdownload', get_string('overviewdownload', 'quiz'), 'game'); echo "</td>\n"; echo '</tr></table>'; } } else { if ($download == 'Excel' or $download == 'ODS') { $workbook->close(); exit; } else { if ($download == 'CSV') { exit; } } } } else { if (!$download) { $table->print_html(); } } // Print display options. echo '<div class="controls">'; echo '<form id="options" action="report.php" method="get">'; echo '<div>'; echo '<p>' . get_string('displayoptions', 'game') . ': </p>'; echo '<input type="hidden" name="id" value="' . $cm->id . '" />'; echo '<input type="hidden" name="q" value="' . $game->id . '" />'; echo '<input type="hidden" name="mode" value="overview" />'; echo '<input type="hidden" name="noattempts" value="0" />'; echo '<input type="hidden" name="detailedmarks" value="0" />'; echo '<table id="overview-options" class="boxaligncenter">'; echo '<tr align="left">'; echo '<td><label for="pagesize">' . get_string('pagesize', 'game') . '</label></td>'; echo '<td><input type="text" id="pagesize" name="pagesize" size="3" value="' . $pagesize . '" /></td>'; echo '</tr>'; echo '<tr align="left">'; echo '<td colspan="2">'; $options = array(0 => get_string('attemptsonly', 'game', $course->students)); if ($course->id != SITEID) { $options[1] = get_string('noattemptsonly', 'game', $course->students); $options[2] = get_string('allstudents', 'game', $course->students); $options[3] = get_string('allattempts', 'game'); } choose_from_menu($options, 'noattempts', $noattempts, ''); echo '</td></tr>'; echo '<tr align="left">'; echo '<td colspan="2"><input type="checkbox" id="checkdetailedmarks" name="detailedmarks" ' . ($detailedmarks ? 'checked="checked" ' : '') . 'value="1" /> <label for="checkdetailedmarks">' . get_string('showdetailedmarks', 'game') . '</label> '; echo '</td></tr>'; echo '<tr><td colspan="2" align="center">'; echo '<input type="submit" value="' . get_string('go') . '" />'; echo '</td></tr></table>'; echo '</div>'; echo '</form>'; echo '</div>'; echo "\n"; return true; }
/** * Display all the submissions ready for grading */ function display_submissions($message = '') { global $CFG, $db, $USER; require_once $CFG->libdir . '/gradelib.php'; /* first we check to see if the form has just been submitted * to request user_preference updates */ if (isset($_POST['updatepref'])) { $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = $perpage <= 0 ? 10 : $perpage; set_user_preference('assignment_perpage', $perpage); set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); } /* next we get perpage and quickgrade (allow quick grade) params * from database */ $perpage = get_user_preferences('assignment_perpage', 10); $quickgrade = get_user_preferences('assignment_quickgrade', 0); $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id); if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { $uses_outcomes = true; } else { $uses_outcomes = false; } $teacherattempts = true; /// Temporary measure $page = optional_param('page', 0, PARAM_INT); $strsaveallfeedback = get_string('saveallfeedback', 'assignment'); /// Some shortcuts to make the code read better $course = $this->course; $assignment = $this->assignment; $cm = $this->cm; $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $navlinks = array(); $navlinks[] = array('name' => $this->strassignments, 'link' => "index.php?id={$course->id}", 'type' => 'activity'); $navlinks[] = array('name' => format_string($this->assignment->name, true), 'link' => "view.php?a={$this->assignment->id}", 'type' => 'activityinstance'); $navlinks[] = array('name' => $this->strsubmissions, 'link' => '', 'type' => 'title'); $navigation = build_navigation($navlinks); print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm)); if (!empty($message)) { echo $message; // display messages here if any } $context = get_context_instance(CONTEXT_MODULE, $cm->id); /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id); /// Get all ppl that are allowed to submit assignments $users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', $currentgroup, '', false); $users = array_keys($users); if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) { $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id'); $users = array_intersect($users, array_keys($groupingusers)); } $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); if ($uses_outcomes) { $tablecolumns[] = 'outcome'; // no sorting based on outcomes column } $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . $course->student . ')', get_string('lastmodified') . ' (' . $course->teacher . ')', get_string('status'), get_string('finalgrade', 'grades')); if ($uses_outcomes) { $tableheaders[] = get_string('outcome', 'grades'); } require_once $CFG->libdir . '/tablelib.php'; $table = new flexible_table('mod-assignment-submissions'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&currentgroup=' . $currentgroup); $table->sortable(true, 'lastname'); //sorted by lastname by default $table->collapsible(true); $table->initialbars(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture'); $table->column_class('fullname', 'fullname'); $table->column_class('grade', 'grade'); $table->column_class('submissioncomment', 'comment'); $table->column_class('timemodified', 'timemodified'); $table->column_class('timemarked', 'timemarked'); $table->column_class('status', 'status'); $table->column_class('finalgrade', 'finalgrade'); if ($uses_outcomes) { $table->column_class('outcome', 'outcome'); } $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'submissions'); $table->set_attribute('width', '90%'); //$table->set_attribute('align', 'center'); $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); /// Check to see if groups are being used in this assignment if (!$teacherattempts) { $teachers = get_course_teachers($course->id); if (!empty($teachers)) { $keys = array_keys($teachers); } foreach ($keys as $key) { unset($users[$key]); } } if (empty($users)) { print_heading(get_string('noattempts', 'assignment')); return true; } /// Construct the SQL if ($where = $table->get_sql_where()) { $where .= ' AND '; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status '; $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id = s.userid AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') '; $table->pagesize($perpage, count($users)); ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next $offset = $page * $perpage; $strupdate = get_string('update'); $strgrade = get_string('grade'); $grademenu = make_grades_menu($this->assignment->grade); if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) { $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers)); foreach ($ausers as $auser) { $final_grade = $grading_info->items[0]->grades[$auser->id]; /// Calculate user status $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified; $picture = print_user_picture($auser->id, $course->id, $auser->picture, false, true); if (empty($auser->submissionid)) { $auser->grade = -1; //no submission yet } if (!empty($auser->submissionid)) { ///Prints student answer and student modified date ///attach file or print link to student answer, depending on the type of the assignment. ///Refer to print_student_answer in inherited classes. if ($auser->timemodified > 0) { $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>'; } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; } ///Print grade, dropdown or text if ($auser->timemarked > 0) { $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>'; } else { if ($quickgrade) { $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>'; } } } else { $teachermodified = '<div id="tt' . $auser->id . '"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>'; } else { if ($quickgrade) { $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>'; } } } ///Print Comment if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($final_grade->str_feedback), 15) . '</div>'; } else { if ($quickgrade) { $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>'; } else { $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($auser->submissioncomment), 15) . '</div>'; } } } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; $teachermodified = '<div id="tt' . $auser->id . '"> </div>'; $status = '<div id="st' . $auser->id . '"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>'; } else { if ($quickgrade) { // allow editing $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">-</div>'; } } if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com' . $auser->id . '">' . $final_grade->str_feedback . '</div>'; } else { if ($quickgrade) { $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>'; } else { $comment = '<div id="com' . $auser->id . '"> </div>'; } } } if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1 $auser->status = 0; } else { $auser->status = 1; } $buttontext = $auser->status == 1 ? $strupdate : $strgrade; ///No more buttons, we use popups ;-). $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&userid=' . $auser->id . '&mode=single' . '&offset=' . $offset++; $button = link_to_popup_window($popup_url, 'grade' . $auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'button' . $auser->id); $status = '<div id="up' . $auser->id . '" class="s' . $auser->status . '">' . $button . '</div>'; $finalgrade = '<span id="finalgrade_' . $auser->id . '">' . $final_grade->str_grade . '</span>'; $outcomes = ''; if ($uses_outcomes) { foreach ($grading_info->outcomes as $n => $outcome) { $outcomes .= '<div class="outcome"><label>' . $outcome->name . '</label>'; $options = make_grades_menu(-$outcome->scaleid); if ($outcome->grades[$auser->id]->locked or !$quickgrade) { $options[0] = get_string('nooutcome', 'grades'); $outcomes .= ': <span id="outcome_' . $n . '_' . $auser->id . '">' . $options[$outcome->grades[$auser->id]->grade] . '</span>'; } else { $outcomes .= ' '; $outcomes .= choose_from_menu($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades'), '', 0, true, false, 0, 'outcome_' . $n . '_' . $auser->id); } $outcomes .= '</div>'; } } $row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade); if ($uses_outcomes) { $row[] = $outcomes; } $table->add_data($row); } } /// Print quickgrade form around the table if ($quickgrade) { echo '<form action="submissions.php" id="fastg" method="post">'; echo '<div>'; echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />'; echo '<input type="hidden" name="mode" value="fastgrade" />'; echo '<input type="hidden" name="page" value="' . $page . '" />'; echo '</div>'; //echo '<div style="text-align:center"><input type="submit" name="fastg" value="'.get_string('saveallfeedback', 'assignment').'" /></div>'; } $table->print_html(); /// Print the whole table if ($quickgrade) { echo '<div style="text-align:center"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'assignment') . '" /></div>'; echo '</form>'; } /// End of fast grading form /// Mini form for setting user preference echo '<br />'; echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post">'; echo '<div>'; echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />'; echo '<table id="optiontable" align="right">'; echo '<tr align="right"><td>'; echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>'; echo ':</td>'; echo '<td>'; echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />'; helpbutton('pagesize', get_string('pagesize', 'assignment'), 'assignment'); echo '</td></tr>'; echo '<tr align="right">'; echo '<td>'; print_string('quickgrade', 'assignment'); echo ':</td>'; echo '<td>'; if ($quickgrade) { echo '<input type="checkbox" name="quickgrade" value="1" checked="checked" />'; } else { echo '<input type="checkbox" name="quickgrade" value="1" />'; } helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment') . '</p></div>'; echo '</td></tr>'; echo '<tr>'; echo '<td colspan="2" align="right">'; echo '<input type="submit" value="' . get_string('savepreferences') . '" />'; echo '</td></tr></table>'; echo '</div>'; echo '</form>'; ///End of mini form print_footer($this->course); }
function print_user_files($userid, $return = false) { global $CFG; if (!($submission = $this->get_submission($userid))) { return ''; } $output = '<div class="files">' . '<img align="middle" src="' . $CFG->pixpath . '/f/html.gif" height="16" width="16" alt="html" />' . link_to_popup_window('/mod/assignment/type/online/file.php?id=' . $this->cm->id . '&userid=' . $submission->userid, 'file' . $userid, shorten_text(trim(strip_tags(format_text($submission->data1, $submission->data2))), 15), 450, 580, get_string('submission', 'assignment'), 'none', true) . '</div>'; ///Stolen code from file.php print_simple_box_start('center', '', '', 0, 'generalbox', 'wordcount'); /// Decide what to count if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) { echo ' (' . get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))) . ')'; } else { if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) { echo ' (' . get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))) . ')'; } } print_simple_box_end(); print_simple_box(format_text($submission->data1, $submission->data2), 'center', '100%'); ///End of stolen code from file.php if ($return) { //return $output; } //echo $output; }
/** * @param object $quiz the quiz * @param object $question the question * @return the HTML for a preview question icon. */ function quiz_question_preview_button($quiz, $question) { global $CFG, $COURSE; if (!question_has_capability_on($question, 'use', $question->category)) { return ''; } $strpreview = get_string('previewquestion', 'quiz'); $quizorcourseid = $quiz->id ? '&quizid=' . $quiz->id : '&courseid=' . $COURSE->id; return link_to_popup_window('/question/preview.php?id=' . $question->id . $quizorcourseid, 'questionpreview', "<img src=\"{$CFG->pixpath}/t/preview.gif\" class=\"iconsmall\" alt=\"{$strpreview}\" />", 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS, true); }
$ensrc = "{$CFG->dirroot}/{$origlocation}/{$origplugin}/lang/en_utf8/help/{$currentfile}"; } else { // core help file $ensrc = "{$enlangdir}/{$currentfile}"; } if (is_readable($ensrc)) { echo '<fieldset><legend>' . $strlangmasterenglish; helpbutton('langpackages', $strlangmasterenglish); echo '</legend>'; echo "<div align=\"center\">\n<textarea rows=\"{$fileeditorrows}\" cols=\"{$fileeditorcols}\" name=\"\">"; echo htmlspecialchars(file_get_contents($ensrc)); echo "</textarea>\n</div>\n"; $preview_url = lang_help_preview_url($currentfile, true, 'en_utf8'); // do not display en_utf8_local if ($preview_url) { link_to_popup_window($preview_url, 'popup', get_string('preview')); } echo '</fieldset>'; } echo '</div>'; // translator box error_reporting($CFG->debug); } if (false && $CFG->debugdisplay && debugging('', DEBUG_DEVELOPER)) { echo '<hr />'; print_heading('Debugging info'); echo '<pre class="notifytiny">'; print_r($dbg); print_r("\n\$currentfile = {$currentfile}"); print_r("\n\$enlangdir = {$enlangdir}"); print_r("\n\$langdir = {$langdir}");