|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 require_once("../../config.php"); 00004 require_once("lib.php"); 00005 00006 $id = required_param('id',PARAM_INT); // course 00007 00008 $PAGE->set_url('/mod/choice/index.php', array('id'=>$id)); 00009 00010 if (!$course = $DB->get_record('course', array('id'=>$id))) { 00011 print_error('invalidcourseid'); 00012 } 00013 00014 require_course_login($course); 00015 $PAGE->set_pagelayout('incourse'); 00016 00017 add_to_log($course->id, "choice", "view all", "index.php?id=$course->id", ""); 00018 00019 $strchoice = get_string("modulename", "choice"); 00020 $strchoices = get_string("modulenameplural", "choice"); 00021 $strsectionname = get_string('sectionname', 'format_'.$course->format); 00022 $PAGE->set_title($strchoices); 00023 $PAGE->set_heading($course->fullname); 00024 $PAGE->navbar->add($strchoices); 00025 echo $OUTPUT->header(); 00026 00027 if (! $choices = get_all_instances_in_course("choice", $course)) { 00028 notice(get_string('thereareno', 'moodle', $strchoices), "../../course/view.php?id=$course->id"); 00029 } 00030 00031 $usesections = course_format_uses_sections($course->format); 00032 if ($usesections) { 00033 $sections = get_all_sections($course->id); 00034 } 00035 00036 $sql = "SELECT cha.* 00037 FROM {choice} ch, {choice_answers} cha 00038 WHERE cha.choiceid = ch.id AND 00039 ch.course = ? AND cha.userid = ?"; 00040 00041 $answers = array () ; 00042 if (isloggedin() and !isguestuser() and $allanswers = $DB->get_records_sql($sql, array($course->id, $USER->id))) { 00043 foreach ($allanswers as $aa) { 00044 $answers[$aa->choiceid] = $aa; 00045 } 00046 unset($allanswers); 00047 } 00048 00049 00050 $timenow = time(); 00051 00052 $table = new html_table(); 00053 00054 if ($usesections) { 00055 $table->head = array ($strsectionname, get_string("question"), get_string("answer")); 00056 $table->align = array ("center", "left", "left"); 00057 } else { 00058 $table->head = array (get_string("question"), get_string("answer")); 00059 $table->align = array ("left", "left"); 00060 } 00061 00062 $currentsection = ""; 00063 00064 foreach ($choices as $choice) { 00065 if (!empty($answers[$choice->id])) { 00066 $answer = $answers[$choice->id]; 00067 } else { 00068 $answer = ""; 00069 } 00070 if (!empty($answer->optionid)) { 00071 $aa = format_string(choice_get_option_text($choice, $answer->optionid)); 00072 } else { 00073 $aa = ""; 00074 } 00075 if ($usesections) { 00076 $printsection = ""; 00077 if ($choice->section !== $currentsection) { 00078 if ($choice->section) { 00079 $printsection = get_section_name($course, $sections[$choice->section]); 00080 } 00081 if ($currentsection !== "") { 00082 $table->data[] = 'hr'; 00083 } 00084 $currentsection = $choice->section; 00085 } 00086 } 00087 00088 //Calculate the href 00089 if (!$choice->visible) { 00090 //Show dimmed if the mod is hidden 00091 $tt_href = "<a class=\"dimmed\" href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>"; 00092 } else { 00093 //Show normal if the mod is visible 00094 $tt_href = "<a href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>"; 00095 } 00096 if ($usesections) { 00097 $table->data[] = array ($printsection, $tt_href, $aa); 00098 } else { 00099 $table->data[] = array ($tt_href, $aa); 00100 } 00101 } 00102 echo "<br />"; 00103 echo html_writer::table($table); 00104 00105 echo $OUTPUT->footer(); 00106 00107