From 68a1e8fbbad991284b8370a07357f94a2290c525 Mon Sep 17 00:00:00 2001 From: mark-nielsen Date: Sun, 10 Sep 2006 22:47:57 +0000 Subject: [PATCH] Started to rework the overall page editing interface for teachers. --- mod/lesson/edit.php | 564 +++++++++++++++++----------------------- mod/lesson/locallib.php | 258 ++++++++++++------ mod/lesson/styles.php | 6 +- mod/lesson/tabs.php | 1 + 4 files changed, 414 insertions(+), 415 deletions(-) diff --git a/mod/lesson/edit.php b/mod/lesson/edit.php index a51f7d9d7c..93c93e77fb 100644 --- a/mod/lesson/edit.php +++ b/mod/lesson/edit.php @@ -14,32 +14,34 @@ $id = required_param('id', PARAM_INT); // Course Module ID $display = optional_param('display', 0, PARAM_INT); $mode = optional_param('mode', get_user_preferences('lesson_view', 'collapsed'), PARAM_ALPHA); + $pageid = optional_param('pageid', 0, PARAM_INT); - set_user_preference('lesson_view', $mode); - - // set collapsed flag - if ($mode == 'collapsed') { - $collapsed = true; - } else { - $collapsed = false; + if ($mode != 'single') { + set_user_preference('lesson_view', $mode); } - + list($cm, $course, $lesson) = lesson_get_basics($id); - require_login($course->id, false, $cm); + if ($firstpage = get_record('lesson_pages', 'lessonid', $lesson->id, 'prevpageid', 0)) { + if (!$pages = get_records('lesson_pages', 'lessonid', $lesson->id)) { + error('Could not find lesson pages'); + } + } + if ($pageid) { + if (!$singlepage = get_record('lesson_pages', 'id', $pageid)) { + error('Could not find page ID: '.$pageid); + } + } + + require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('mod/lesson:manage'); lesson_print_header($cm, $course, $lesson, $mode); - - // get number of pages - $npages = count_records('lesson_pages', 'lessonid', $lesson->id); - if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { - // if there are no pages give teacher the option to create a new page or a new branch table - echo "
"; + if (empty($firstpage)) { + // There are no pages; give teacher some options if (has_capability('mod/lesson:edit', $context)) { print_simple_box( "\n
".get_string("whatdofirst", "lesson")."
". "id&pageid=0\">". @@ -49,344 +51,244 @@ "id&action=addbranchtable&pageid=0&firstpage=1\">". get_string("addabranchtable", "lesson")."
". "id&action=addpage&pageid=0&firstpage=1\">". - get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). - "
\n"); + get_string("addaquestionpage", "lesson"). + "\n", 'center'); } - echo '
'; } else { - // print the pages - echo "
wwwroot/mod/lesson/view.php\">\n"; - echo "id\" />\n"; - echo "\n"; - $branch = false; - $singlePage = false; - if($collapsed and !$display) { - echo "
\n"; - echo "
\n"; - lesson_print_tree($page->id, $lesson, $cm->id); - echo "
\n"; - echo "
\n"; - } else { - if($display) { - while(true) - { - if($page->id == $display && $page->qtype == LESSON_BRANCHTABLE) { - $branch = true; - $singlePage = false; - break; - } elseif($page->id == $display) { - $branch = false; - $singlePage = true; - break; - } elseif ($page->nextpageid) { - if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { - error("Teacher view: Next page not found!"); + + + // TODO: Check to make sure pages is set? + + // Set some standard variables + $pageid = $firstpage->id; + $prevpageid = 0; + $npages = count($pages); + + switch ($mode) { + case 'collapsed': + $table = new stdClass; + $table->head = array(get_string('pagetitle', 'lesson'), get_string('qtype', 'lesson'), get_string('jumps', 'lesson'), get_string('actions', 'lesson')); + $table->align = array('left', 'left', 'left', 'center'); + //$table->wrap = array(); + $table->width = '70%'; + $table->tablealign = 'center'; + $table->cellspacing = 0; + $table->cellpadding = '2px'; + $table->data = array(); + + while ($pageid != 0) { + $page = $pages[$pageid]; + + $jumps = array(); + if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid")) { + + foreach ($answers as $answer) { + $jumps[] = lesson_get_jump_name($answer->jumpto); } - } else { - // last page reached - break; } + + $table->data[] = array("wwwroot/mod/lesson/edit.php?id=$cm->id&mode=single&pageid=".$page->id."\">".format_string($pages[$pageid]->title,true).'', + lesson_get_qtype_name($page->qtype), + implode("
\n", $jumps), + lesson_print_page_actions($cm->id, $page->id, $npages, true) + ); + $pageid = $page->nextpageid; } - echo "\n"; - if (has_capability('mod/lesson:edit', $context)) { - echo "\n"; - } - } else { - echo "
id&pageid=$page->prevpageid\">". - get_string("importquestions", "lesson")." | ". - "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=$page->prevpageid\">". - get_string("addcluster", "lesson")." | ". - "id&sesskey=".$USER->sesskey."&action=addendofcluster&pageid=$page->prevpageid\">". - get_string("addendofcluster", "lesson")." | ". - "id&action=addbranchtable&pageid=$page->prevpageid\">". - get_string("addabranchtable", "lesson")." | ". - "id&action=addpage&pageid=$page->prevpageid\">". - get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). - "
\n"; - if (has_capability('mod/lesson:edit', $context)) { - echo "\n"; - } - } - /// end collapsed code (note, there is an "}" below for an else above) - while (true) { - echo "
id&pageid=0\">". - get_string("importquestions", "lesson")." | ". - "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=0\">". - get_string("addcluster", "lesson")." | ". - "id&action=addbranchtable&pageid=0\">". - get_string("addabranchtable", "lesson")." | ". - "id&action=addpage&pageid=0\">". - get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). - "
\n"; - echo "\n"; - echo "\n"; - // get the answers in a set order, the id order - if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { - echo "\n"; - $i = 1; - $n = 0; - foreach ($answers as $answer) { - switch ($page->qtype) { - case LESSON_MULTICHOICE: - case LESSON_TRUEFALSE: - case LESSON_SHORTANSWER: - case LESSON_NUMERICAL: - echo "\n"; - if (has_capability('mod/lesson:edit', $context)) { - echo "\n"; - } -// echo "
".format_string($page->title)."  \n"; - if (has_capability('mod/lesson:edit', $context)) { - if ($npages > 1) { - echo "id&action=move&pageid=$page->id\">\n". - "pixpath/t/move.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"move\" />\n"; - } - echo "id&action=editpage&pageid=$page->id\">\n". - "pixpath/t/edit.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"edit\" />\n". - "id&sesskey=".$USER->sesskey."&action=confirmdelete&pageid=$page->id\">\n". - "pixpath/t/delete.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"delete\" />\n"; - } - echo "
\n"; - $options = new stdClass; - $options->noclean = true; - print_simple_box(format_text($page->contents, FORMAT_MOODLE, $options), "center"); - echo "
\n"; - switch ($page->qtype) { - case LESSON_ESSAY : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - break; - case LESSON_SHORTANSWER : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - if ($page->qoption) { - echo " - ".get_string("casesensitive", "lesson"); - } - break; - case LESSON_MULTICHOICE : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - if ($page->qoption) { - echo " - ".get_string("multianswer", "lesson"); - } - break; - case LESSON_MATCHING : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - echo get_string("firstanswershould", "lesson"); - break; - case LESSON_TRUEFALSE : - case LESSON_NUMERICAL : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - break; - case LESSON_BRANCHTABLE : - echo get_string("branchtable", "lesson"); - break; - case LESSON_ENDOFBRANCH : - echo get_string("endofbranch", "lesson"); - break; - case LESSON_CLUSTER : - echo get_string("clustertitle", "lesson"); - break; - case LESSON_ENDOFCLUSTER : - echo get_string("endofclustertitle", "lesson"); - break; - } - echo "
\n"; - if ($lesson->custom) { - // if the score is > 0, then it is correct - if ($answer->score > 0) { - echo "".get_string("answer", "lesson")." $i: \n"; - } else { - echo "".get_string("answer", "lesson")." $i: \n"; + + print_table($table); + break; + case 'single': + // Only viewing a single page in full - change some variables to display just one + $prevpageid = $singlepage->prevpageid; + $pageid = $singlepage->id; + + $pages = array(); + $pages[$singlepage->id] = $singlepage; + case 'full': + echo ' + + + '; + + while ($pageid != 0) { + $page = $pages[$pageid]; + + echo "\n\n"; } - $i++; - } - // print_simple_box_end(); // not sure if i commented this out... hehe - echo "\n"; - } - echo "
'; + lesson_print_add_links($cm->id, $prevpageid); + echo '
\n"; + echo "\n"; + echo "\n"; + // get the answers in a set order, the id order + if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { + echo "\n"; - echo "\n"; - break; - case LESSON_MATCHING: - $options = new stdClass; - $options->noclean = true; - if ($n < 2) { - if ($answer->answer != NULL) { - if ($n == 0) { - echo "\n"; + break; + case LESSON_MATCHING : + echo get_string("firstanswershould", "lesson"); + break; + } + echo "\n"; + $i = 1; + $n = 0; + $options = new stdClass; + $options->noclean = true; + $options->para = false; + foreach ($answers as $answer) { + switch ($page->qtype) { + case LESSON_MULTICHOICE: + case LESSON_TRUEFALSE: + case LESSON_SHORTANSWER: + case LESSON_NUMERICAL: + echo "\n"; + echo "\n"; + break; + case LESSON_MATCHING: + if ($n < 2) { + if ($answer->answer != NULL) { + if ($n == 0) { + echo "\n"; + } else { + echo "\n"; + } + } + $n++; + $i--; + } else { + echo "\n"; + echo "\n"; } + break; + case LESSON_BRANCHTABLE: + echo "\n"; + break; + } + + $jumptitle = lesson_get_jump_name($answer->jumpto); + if ($page->qtype == LESSON_MATCHING) { + if ($i == 1) { + echo "\n"; + echo "\n"; + } elseif ($i == 2) { + echo "\n"; + echo "\n"; } - $n++; - $i--; } else { - echo "\n"; } - echo "\n"; - echo "\n"; + echo "\n"; } - break; - case LESSON_BRANCHTABLE: - $options = new stdClass; - $options->noclean = true; - echo "\n"; - break; - } - if ($answer->jumpto == 0) { - $jumptitle = get_string("thispage", "lesson"); - } elseif ($answer->jumpto == LESSON_NEXTPAGE) { - $jumptitle = get_string("nextpage", "lesson"); - } elseif ($answer->jumpto == LESSON_EOL) { - $jumptitle = get_string("endoflesson", "lesson"); - } elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) { - $jumptitle = get_string("unseenpageinbranch", "lesson"); - } elseif ($answer->jumpto == LESSON_PREVIOUSPAGE) { - $jumptitle = get_string("previouspage", "lesson"); - } elseif ($answer->jumpto == LESSON_RANDOMPAGE) { - $jumptitle = get_string("randompageinbranch", "lesson"); - } elseif ($answer->jumpto == LESSON_RANDOMBRANCH) { - $jumptitle = get_string("randombranch", "lesson"); - } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { - $jumptitle = get_string("clusterjump", "lesson"); - } else { - if (!$jumptitle = get_field("lesson_pages", "title", "id", $answer->jumpto)) { - $jumptitle = "".get_string("notdefined", "lesson").""; + $i++; } } - $jumptitle = format_string($jumptitle,true); - if ($page->qtype == LESSON_MATCHING) { - if ($i == 1) { - echo "\n"; - echo "\n"; - } elseif ($i == 2) { - echo "\n"; - echo "\n"; - } - } else { - if ($lesson->custom and - $page->qtype != LESSON_BRANCHTABLE and - $page->qtype != LESSON_ENDOFBRANCH and - $page->qtype != LESSON_CLUSTER and - $page->qtype != LESSON_ENDOFCLUSTER) { - echo "\n"; + echo "
".format_string($page->title)."  \n"; + lesson_print_page_actions($cm->id, $page->id, $npages); + echo "
\n"; + $options = new stdClass; + $options->noclean = true; + echo format_text($page->contents, FORMAT_MOODLE, $options); + echo "
\n"; + echo lesson_get_qtype_name($page->qtype); + switch ($page->qtype) { + case LESSON_SHORTANSWER : + if ($page->qoption) { + echo " - ".get_string("casesensitive", "lesson"); } - } else { - if (lesson_iscorrect($page->id, $answer->jumpto)) { - // underline correct answers - echo "".get_string("answer", "lesson")." $i: \n"; - } else { - echo "".get_string("answer", "lesson")." $i: \n"; + break; + case LESSON_MULTICHOICE : + if ($page->qoption) { + echo " - ".get_string("multianswer", "lesson"); } - } - $options = new stdClass; - $options->noclean = true; - echo "\n"; - echo format_text($answer->answer, FORMAT_MOODLE, $options); - echo "
".get_string("response", "lesson")." $i: \n"; - echo "\n"; - echo format_text($answer->response, FORMAT_MOODLE, $options); - echo "
".get_string("correctresponse", "lesson").": \n"; - echo "\n"; - echo format_text($answer->answer, FORMAT_MOODLE, $options); - echo "
\n"; + if ($lesson->custom) { + // if the score is > 0, then it is correct + if ($answer->score > 0) { + echo "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } } else { - echo "
".get_string("wrongresponse", "lesson").": \n"; + if (lesson_iscorrect($page->id, $answer->jumpto)) { + // underline correct answers + echo "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } + } + echo "\n"; + echo format_text($answer->answer, FORMAT_MOODLE, $options); + echo "
".get_string("response", "lesson")." $i: \n"; + echo "\n"; + echo format_text($answer->response, FORMAT_MOODLE, $options); + echo "
".get_string("correctresponse", "lesson").": \n"; + echo "\n"; + echo format_text($answer->answer, FORMAT_MOODLE, $options); + echo "
".get_string("wrongresponse", "lesson").": \n"; + echo "\n"; + echo format_text($answer->answer, FORMAT_MOODLE, $options); + echo "
\n"; + if ($lesson->custom) { + // if the score is > 0, then it is correct + if ($answer->score > 0) { + echo "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } + } else { + if (lesson_iscorrect($page->id, $answer->jumpto)) { + // underline correct answers + echo "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } + } + echo "\n"; + echo format_text($answer->answer, FORMAT_MOODLE, $options); + echo "
".get_string("matchesanswer", "lesson")." $i: \n"; echo "\n"; - echo format_text($answer->answer, FORMAT_MOODLE, $options); + echo format_text($answer->response, FORMAT_MOODLE, $options); echo "
\n"; + echo "".get_string("description", "lesson")." $i: \n"; + echo "\n"; + echo format_text($answer->answer, FORMAT_MOODLE, $options); + echo "
".get_string("correctanswerscore", "lesson").":"; + echo "\n"; + echo "$answer->score
".get_string("correctanswerjump", "lesson").":"; + echo "\n"; + echo "$jumptitle
".get_string("wronganswerscore", "lesson").":"; + echo "\n"; + echo "$answer->score
".get_string("wronganswerjump", "lesson").":"; + echo "\n"; + echo "$jumptitle
\n"; - if ($lesson->custom) { - // if the score is > 0, then it is correct - if ($answer->score > 0) { - echo "".get_string("answer", "lesson")." $i: \n"; - } else { - echo "".get_string("answer", "lesson")." $i: \n"; - } - } else { - if (lesson_iscorrect($page->id, $answer->jumpto)) { - // underline correct answers - echo "".get_string("answer", "lesson")." $i: \n"; - } else { - echo "".get_string("answer", "lesson")." $i: \n"; - } + if ($lesson->custom and + $page->qtype != LESSON_BRANCHTABLE and + $page->qtype != LESSON_ENDOFBRANCH and + $page->qtype != LESSON_CLUSTER and + $page->qtype != LESSON_ENDOFCLUSTER) { + echo "
".get_string("score", "lesson")." $i:"; + echo "\n"; + echo "$answer->score
\n"; - echo format_text($answer->answer, FORMAT_MOODLE, $options); - echo "
".get_string("matchesanswer", "lesson")." $i: \n"; - echo "\n"; - echo format_text($answer->response, FORMAT_MOODLE, $options); - echo "
".get_string("jump", "lesson")." $i:"; + echo "\n"; + echo "$jumptitle
\n"; - echo "".get_string("description", "lesson")." $i: \n"; - echo "\n"; - echo format_text($answer->answer, FORMAT_MOODLE, $options); - echo "
".get_string("correctanswerscore", "lesson").":"; - echo "\n"; - echo "$answer->score
".get_string("correctanswerjump", "lesson").":"; - echo "\n"; - echo "$jumptitle
".get_string("wronganswerscore", "lesson").":"; - echo "\n"; - echo "$answer->score
".get_string("wronganswerjump", "lesson").":"; - echo "\n"; - echo "$jumptitle
".get_string("score", "lesson")." $i:"; - echo "\n"; - echo "$answer->score
"; + lesson_print_add_links($cm->id, $page->id); + echo "
\n"; + // check the prev links - fix (silently) if necessary - there was a bug in + // versions 1 and 2 when add new pages. Not serious then as the backwards + // links were not used in those versions + if ($page->prevpageid != $prevpageid) { + // fix it + set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id); + if ($CFG->debug) { + echo "

***prevpageid of page $page->id set to $prevpageid***"; } - echo "

".get_string("jump", "lesson")." $i:"; - echo "\n"; - echo "$jumptitle
"; - if ($page->qtype != LESSON_ENDOFBRANCH) { - echo "qtype == LESSON_BRANCHTABLE) { - echo get_string("checkbranchtable", "lesson"); - } else { - echo get_string("checkquestion", "lesson"); - } - echo "\" onclick=\"document.lessonpages.pageid.value=$page->id;". - "document.lessonpages.submit();\" />"; - } - echo " 
id&pageid=$page->id\">". - get_string("importquestions", "lesson")." | ". - "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=$page->id\">". - get_string("addcluster", "lesson")." | ". - "id&sesskey=".$USER->sesskey."&action=addendofcluster&pageid=$page->id\">". - get_string("addendofcluster", "lesson")." | ". - "id&action=addbranchtable&pageid=$page->id\">". - get_string("addabranchtable", "lesson")."
"; - // the current page or the next page is an end of branch don't show EOB link - $nextqtype = 0; // set to anything else EOB - if ($page->nextpageid) { - $nextqtype = get_field("lesson_pages", "qtype", "id", $page->nextpageid); - } - if (($page->qtype != LESSON_ENDOFBRANCH) and ($nextqtype != LESSON_ENDOFBRANCH)) { - echo "id&sesskey=".$USER->sesskey."&action=addendofbranch&pageid=$page->id\">". - get_string("addanendofbranch", "lesson")." | "; - } - echo "id&action=addpage&pageid=$page->id\">". - get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). - "
\n"; - // check the prev links - fix (silently) if necessary - there was a bug in - // versions 1 and 2 when add new pages. Not serious then as the backwards - // links were not used in those versions - if (isset($prevpageid)) { - if ($page->prevpageid != $prevpageid) { - // fix it - set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id); - if ($CFG->debug) { - echo "

***prevpageid of page $page->id set to $prevpageid***"; + + if (count($pages) == 1) { + break; } + + $prevpageid = $page->id; + $pageid = $page->nextpageid; } - } - $prevpageid = $page->id; - // move to next page - if($singlePage) { // this will make sure only one page is displayed if needed - break; - } elseif($branch && $page->qtype == LESSON_ENDOFBRANCH) { // this will display a branch table and its contents + echo "

"; break; - } elseif ($page->nextpageid) { - if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { - error("Teacher view: Next page not found!"); - } - } else { - // last page reached - break; - } } - } // end of else from above collapsed code!!! - - echo "
\n"; } print_footer($course); diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index f6e7dc7d49..a5e1753a8d 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -210,12 +210,13 @@ if (!defined("LESSON_RESPONSE_EDITOR")) { /** * Print the standard header for lesson module * + * @uses $CFG + * @uses $USER * @param object $cm Course module record object * @param object $course Couse record object * @param object $lesson Lesson module record object * @param string $currenttab Current tab for the lesson tabs - * @param boolean $printheading Print the a heading with the lesson name - * @return void + * @return boolean **/ function lesson_print_header($cm, $course, $lesson, $currenttab = '') { global $CFG, $USER; @@ -289,6 +290,8 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '') { } lesson_print_messages(); + + return true; } /** @@ -382,6 +385,13 @@ function lesson_print_messages() { * * If Javascript is disabled, then a regular submit button is printed * + * @param string $name Name of the link or button + * @param string $form The name of the form to be submitted + * @param string $align Alignment of the button + * @param string $class Class names to add to the div wrapper + * @param string $title Title for the link (Not used if javascript is disabled) + * @param string $id ID tag + * @param boolean $return Return flag * @return mixed boolean/html **/ function lesson_print_submit_link($name, $form, $align = 'center', $class='standardbutton', $title = '', $id = '', $return = false) { @@ -448,6 +458,169 @@ function lesson_print_time_remaining($starttime, $maxtime, $return = false) { } } +/** + * Prints the page action buttons + * + * Move/Edit/Preview/Delete + * + * @uses $CFG + * @param int $cmid Course Module ID + * @param int $pageid Page record ID for which the actions affect + * @param boolean $printmove Flag to print the move button or not + * @param boolean $return Return flag + * @return mixed boolean/string + **/ +function lesson_print_page_actions($cmid, $pageid, $printmove, $return = false) { + global $CFG; + + $context = get_context_instance(CONTEXT_MODULE, $cmid); + $actions = array(); + + if (has_capability('mod/lesson:edit', $context)) { + if ($printmove) { + $actions[] = "wwwroot/mod/lesson/lesson.php?id=$cmid&action=move&pageid=$pageid\"> + pixpath/t/move.gif\" height=\"11\" width=\"11\" alt=\"".get_string('move')."\" border=\"0\" />\n"; + } + $actions[] = "wwwroot/mod/lesson/lesson.php?id=$cmid&action=editpage&pageid=$pageid\"> + pixpath/t/edit.gif\" height=\"11\" width=\"11\" alt=\"".get_string('update')."\" border=\"0\" />\n"; + + $actions[] = "wwwroot/mod/lesson/view.php?id=$cmid&pageid=$pageid\"> + pixpath/t/preview.gif\" height=\"11\" width=\"11\" alt=\"".get_string('preview')."\" border=\"0\" />\n"; + + $actions[] = "wwwroot/mod/lesson/lesson.php?id=$cmid&sesskey=".sesskey()."&action=confirmdelete&pageid=$pageid\"> + pixpath/t/delete.gif\" height=\"11\" width=\"11\" alt=\"".get_string('delete')."\" border=\"0\" />\n"; + + } + + $actions = implode(' ', $actions); + + if ($return) { + return $actions; + } else { + echo $actions; + return false; + } +} + +/** + * Prints the add links in expanded view or single view when editing + * + * @uses $CFG + * @param int $cmid Course Module ID + * @param int $prevpageid Previous page id + * @param boolean $return Return flag + * @return mixed boolean/string + * @todo &pageid does not make sense, it is prevpageid + **/ +function lesson_print_add_links($cmid, $prevpageid, $return = false) { + global $CFG; + + $context = get_context_instance(CONTEXT_MODULE, $cmid); + + $links = ''; + if (has_capability('mod/lesson:edit', $context)) { + $links = array(); + $links[] = "wwwroot/mod/lesson/import.php?id=$cmid&pageid=$prevpageid\">". + get_string('importquestions', 'lesson').''; + + $links[] = "wwwroot/mod/lesson/lesson.php?id=$cmid&sesskey=".sesskey()."&action=addcluster&pageid=$prevpageid\">". + get_string('addcluster', 'lesson').''; + + if ($prevpageid != 0) { + $links[] = "wwwroot/mod/lesson/lesson.php?id=$cmid&sesskey=".sesskey()."&action=addendofcluster&pageid=$prevpageid\">". + get_string('addendofcluster', 'lesson').''; + } + $links[] = "wwwroot/mod/lesson/lesson.php?id=$cmid&action=addbranchtable&pageid=$prevpageid\">". + get_string('addabranchtable', 'lesson').''; + + if ($prevpageid != 0) { + $links[] = "wwwroot/mod/lesson/lesson.php?id=$cmid&sesskey=".sesskey()."&action=addendofbranch&pageid=$prevpageid\">". + get_string('addanendofbranch', 'lesson').''; + } + + $links[] = "wwwroot/mod/lesson/lesson.php?id=$cmid&action=addpage&pageid=$prevpageid\">". + get_string('addaquestionpagehere', 'lesson').''; + + $links = implode(" | \n", $links); + $links = "\n
\n$links\n
\n"; + } + + if ($return) { + return $links; + } else { + echo $links; + return true; + } +} + +/** + * Returns the string for a page type + * + * @uses $LESSON_QUESTION_TYPE + * @param int $qtype Page type + * @return string + **/ +function lesson_get_qtype_name($qtype) { + global $LESSON_QUESTION_TYPE; + switch ($qtype) { + case LESSON_ESSAY : + case LESSON_SHORTANSWER : + case LESSON_MULTICHOICE : + case LESSON_MATCHING : + case LESSON_TRUEFALSE : + case LESSON_NUMERICAL : + return $LESSON_QUESTION_TYPE[$qtype]; + break; + case LESSON_BRANCHTABLE : + return get_string("branchtable", "lesson"); + break; + case LESSON_ENDOFBRANCH : + return get_string("endofbranch", "lesson"); + break; + case LESSON_CLUSTER : + return get_string("clustertitle", "lesson"); + break; + case LESSON_ENDOFCLUSTER : + return get_string("endofclustertitle", "lesson"); + break; + default: + return ''; + break; + } +} + +/** + * Returns the string for a jump name + * + * @param int $jumpto Jump code or page ID + * @return string + **/ +function lesson_get_jump_name($jumpto) { + if ($jumpto == 0) { + $jumptitle = get_string('thispage', 'lesson'); + } elseif ($jumpto == LESSON_NEXTPAGE) { + $jumptitle = get_string('nextpage', 'lesson'); + } elseif ($jumpto == LESSON_EOL) { + $jumptitle = get_string('endoflesson', 'lesson'); + } elseif ($jumpto == LESSON_UNSEENBRANCHPAGE) { + $jumptitle = get_string('unseenpageinbranch', 'lesson'); + } elseif ($jumpto == LESSON_PREVIOUSPAGE) { + $jumptitle = get_string('previouspage', 'lesson'); + } elseif ($jumpto == LESSON_RANDOMPAGE) { + $jumptitle = get_string('randompageinbranch', 'lesson'); + } elseif ($jumpto == LESSON_RANDOMBRANCH) { + $jumptitle = get_string('randombranch', 'lesson'); + } elseif ($jumpto == LESSON_CLUSTERJUMP) { + $jumptitle = get_string('clusterjump', 'lesson'); + } else { + if (!$jumptitle = get_field('lesson_pages', 'title', 'id', $jumpto)) { + $jumptitle = ''.get_string('notdefined', 'lesson').''; + } + } + + return format_string($jumptitle,true); +} + /** * Given some question info and some data about the the answers * this function parses, organises and saves the question @@ -1362,85 +1535,6 @@ function lesson_print_tree_link_menu($page, $id, $showpages=false) { $output .= ""; echo $output; -} - -/** - * Prints out the tree view list. - * - * Each page in the lesson is printed out as a link. If the page is a branch table - * or an end of branch then the link color changes and the answer jumps are also printed - * alongside the links. Also, the editing buttons (move, update, delete) are printed - * next to the links. - * - * @uses $USER - * @uses $CFG - * @param int $pageid Page id of the first page of the lesson. - * @param object $lesson Object of the current lesson. - * @param int $cmid The course module id of the lesson. - * @param string $pixpath Path to the pictures. - * @todo $pageid does not need to be passed. Can be found in the function. - * This function is only called once. It should be removed and the code inside it moved to view.php - */ -function lesson_print_tree($pageid, $lesson, $cmid) { - global $USER, $CFG; - $context = get_context_instance(CONTEXT_MODULE, $cmid); - - if(!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) { - error("Error: could not find lesson pages"); - } - echo ""; - while ($pageid != 0) { - echo ""; - $pageid = $pages[$pageid]->nextpageid; - } - echo "
"; - if(($pages[$pageid]->qtype != LESSON_BRANCHTABLE) && ($pages[$pageid]->qtype != LESSON_ENDOFBRANCH)) { - $output = "wwwroot/mod/lesson/edit.php?id=$cmid&display=".$pages[$pageid]->id."\">".format_string($pages[$pageid]->title,true)."\n"; - } else { - $output = "wwwroot/mod/lesson/edit.php?id=$cmid&display=".$pages[$pageid]->id."\">".format_string($pages[$pageid]->title,true)."\n"; - - if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid")) { - $output .= "Jumps to: "; - $end = end($answers); - foreach ($answers as $answer) { - if ($answer->jumpto == 0) { - $output .= get_string("thispage", "lesson"); - } elseif ($answer->jumpto == LESSON_NEXTPAGE) { - $output .= get_string("nextpage", "lesson"); - } elseif ($answer->jumpto == LESSON_EOL) { - $output .= get_string("endoflesson", "lesson"); - } elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) { - $output .= get_string("unseenpageinbranch", "lesson"); - } elseif ($answer->jumpto == LESSON_PREVIOUSPAGE) { - $output .= get_string("previouspage", "lesson"); - } elseif ($answer->jumpto == LESSON_RANDOMPAGE) { - $output .= get_string("randompageinbranch", "lesson"); - } elseif ($answer->jumpto == LESSON_RANDOMBRANCH) { - $output .= get_string("randombranch", "lesson"); - } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { - $output .= get_string("clusterjump", "lesson"); - } else { - $output .= format_string($pages[$answer->jumpto]->title); - } - if ($answer->id != $end->id) { - $output .= ", "; - } - } - } - } - - echo $output; - if (has_capability('mod/lesson:edit', $context)) { - if (count($pages) > 1) { - echo "id."\">\n". - "pixpath/t/move.gif\" hspace=\"2\" height=11 width=11 alt=\"move\" border=0>\n"; - } - echo "id."\">\n". - "pixpath/t/edit.gif\" hspace=\"2\" height=11 width=11 alt=\"edit\" border=0>\n". - "sesskey."&action=confirmdelete&pageid=".$pages[$pageid]->id."\">\n". - "pixpath/t/delete.gif\" hspace=\"2\" height=11 width=11 alt=\"delete\" border=0>\n"; - } - echo "
"; } /** @@ -1654,7 +1748,6 @@ function lesson_check_nickname($name) { * @param object $lesson The lesson that the user is currently taking. * @param object $course The course that the to which the lesson belongs. * @return boolean The return is not significant as of yet. Will return true/false. - * @author Mark Nielsen **/ function lesson_print_progress_bar($lesson, $course) { global $CFG, $USER; @@ -1763,7 +1856,6 @@ function lesson_print_progress_bar($lesson, $course) { * * @param object $lesson Lesson object of the current lesson * @return boolean 0 if the user cannot see, or $lesson->displayleft to keep displayleft unchanged - * @author Mark Nielsen **/ function lesson_displayleftif($lesson) { global $CFG, $USER; diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php index e1606583ab..7d0ed743d5 100644 --- a/mod/lesson/styles.php +++ b/mod/lesson/styles.php @@ -1,11 +1,15 @@ /*** - *** Style for page contents (display to student) + *** General styles (scope: all of lesson) ***/ .mod-lesson .contents { text-align: left; } +.mod-lesson .addlinks { + font-size: .8em; +} + /*** *** Style for view.php ***/ diff --git a/mod/lesson/tabs.php b/mod/lesson/tabs.php index f13ff3a5aa..d25c58cc25 100644 --- a/mod/lesson/tabs.php +++ b/mod/lesson/tabs.php @@ -61,6 +61,7 @@ break; case 'collapsed': case 'full': + case 'single': /// sub tabs for edit view (collapsed and expanded aka full) $inactive[] = 'edit'; -- 2.39.5