PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/course/format/weeks/format.php

https://github.com/bobpuffer/1.9.12-LAE1.3
PHP | 287 lines | 213 code | 62 blank | 12 comment | 44 complexity | 0d2a05f04f2bc95062e9e2c242ecd122 MD5 | raw file
  1. <?php // $Id: format.php 542 2011-04-20 16:55:45Z dlandau $
  2. // Display the whole course as "weeks" made of of modules
  3. // Included from "view.php"
  4. require_once($CFG->libdir.'/ajax/ajaxlib.php');
  5. $week = optional_param('week', -1, PARAM_INT);
  6. // Bounds for block widths
  7. // more flexible for theme designers taken from theme config.php
  8. $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
  9. $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
  10. $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
  11. $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
  12. define('BLOCK_L_MIN_WIDTH', $lmin);
  13. define('BLOCK_L_MAX_WIDTH', $lmax);
  14. define('BLOCK_R_MIN_WIDTH', $rmin);
  15. define('BLOCK_R_MAX_WIDTH', $rmax);
  16. $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
  17. BLOCK_L_MAX_WIDTH);
  18. $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
  19. BLOCK_R_MAX_WIDTH);
  20. if ($week != -1) {
  21. $displaysection = course_set_display($course->id, $week);
  22. } else {
  23. if (isset($USER->display[$course->id])) {
  24. $displaysection = $USER->display[$course->id];
  25. } else {
  26. $displaysection = course_set_display($course->id, 0);
  27. }
  28. }
  29. $streditsummary = get_string('editsummary');
  30. $stradd = get_string('add');
  31. $stractivities = get_string('activities');
  32. $strshowallweeks = get_string('showallweeks');
  33. $strweek = get_string('week');
  34. $strgroups = get_string('groups');
  35. $strgroupmy = get_string('groupmy');
  36. $editing = $PAGE->user_is_editing();
  37. if ($editing) {
  38. $strstudents = moodle_strtolower($course->students);
  39. $strweekhide = get_string('weekhide', '', $strstudents);
  40. $strweekshow = get_string('weekshow', '', $strstudents);
  41. $strmoveup = get_string('moveup');
  42. $strmovedown = get_string('movedown');
  43. }
  44. $context = get_context_instance(CONTEXT_COURSE, $course->id);
  45. /// Layout the whole page as three big columns.
  46. echo '<table id="layout-table" cellspacing="0" summary="'.get_string('layouttable').'"><tr>';
  47. $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
  48. foreach ($lt as $column) {
  49. switch ($column) {
  50. case 'left':
  51. /// The left column ...
  52. if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
  53. echo '<td style="width:'.$preferred_width_left.'px" id="left-column">';
  54. print_container_start();
  55. blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
  56. print_container_end();
  57. echo '</td>';
  58. }
  59. break;
  60. case 'middle':
  61. /// Start main column
  62. echo '<td id="middle-column">';
  63. print_container_start();
  64. echo skip_main_destination();
  65. print_heading_block(get_string('weeklyoutline'), 'outline');
  66. echo '<table class="weeks" width="100%" summary="'.get_string('layouttable').'">';
  67. /// If currently moving a file then show the current clipboard
  68. if (ismoving($course->id)) {
  69. $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
  70. $strcancel= get_string('cancel');
  71. echo '<tr class="clipboard">';
  72. echo '<td colspan="3">';
  73. echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
  74. echo '</td>';
  75. echo '</tr>';
  76. }
  77. /// Print Section 0 with general activities
  78. $section = 0;
  79. $thissection = $sections[$section];
  80. if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
  81. echo '<tr id="section-0" class="section main">';
  82. echo '<td id="sectionblock-0" class="left side">&nbsp;</td>';
  83. echo '<td class="content">';
  84. echo '<div class="summary">';
  85. $summaryformatoptions->noclean = true;
  86. echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
  87. if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
  88. echo '<a title="'.$streditsummary.'" '.
  89. ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
  90. 'class="iconsmall edit" alt="'.$streditsummary.'" /></a><br /><br />';
  91. }
  92. echo '</div>';
  93. print_section($course, $thissection, $mods, $modnamesused);
  94. if (isediting($course->id)) {
  95. print_section_add_menus($course, $section, $modnames);
  96. }
  97. echo '</td>';
  98. echo '<td class="right side">&nbsp;</td>';
  99. echo '</tr>';
  100. echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
  101. }
  102. /// Now all the normal modules by week
  103. /// Everything below uses "section" terminology - each "section" is a week.
  104. $timenow = time();
  105. $weekdate = $course->startdate; // this should be 0:00 Monday of that week
  106. $weekdate += 7200; // Add two hours to avoid possible DST problems
  107. $section = 1;
  108. $sectionmenu = array();
  109. $weekofseconds = 604800;
  110. $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
  111. $strftimedateshort = ' '.get_string('strftimedateshort');
  112. while ($weekdate < $course->enddate) {
  113. $nextweekdate = $weekdate + ($weekofseconds);
  114. $weekday = userdate($weekdate, $strftimedateshort);
  115. $endweekday = userdate($weekdate+518400, $strftimedateshort);
  116. if (!empty($sections[$section])) {
  117. $thissection = $sections[$section];
  118. } else {
  119. unset($thissection);
  120. $thissection->course = $course->id; // Create a new week structure
  121. $thissection->section = $section;
  122. $thissection->summary = '';
  123. $thissection->visible = 1;
  124. if (!$thissection->id = insert_record('course_sections', $thissection)) {
  125. notify('Error inserting new week!');
  126. }
  127. }
  128. $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
  129. if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
  130. if ($showsection) {
  131. $sectionmenu['week='.$section] = s("$strweek $section | $weekday - $endweekday");
  132. }
  133. $section++;
  134. $weekdate = $nextweekdate;
  135. continue;
  136. }
  137. if ($showsection) {
  138. $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
  139. $currenttext = '';
  140. if (!$thissection->visible) {
  141. $sectionstyle = ' hidden';
  142. } else if ($currentweek) {
  143. $sectionstyle = ' current';
  144. $currenttext = get_accesshide(get_string('currentweek','access'));
  145. } else {
  146. $sectionstyle = '';
  147. }
  148. echo '<tr id="section-'.$section.'" class="section main'.$sectionstyle.'">';
  149. echo '<td id="sectionblock-'.$section.'" class="left side">&nbsp;'.$currenttext.'</td>';
  150. $weekperiod = $weekday.' - '.$endweekday;
  151. echo '<td class="content">';
  152. if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
  153. print_heading($weekperiod.' ('.get_string('notavailable').')', null, 3, 'weekdates');
  154. } else {
  155. print_heading($weekperiod, null, 3, 'weekdates');
  156. echo '<div class="summary">';
  157. $summaryformatoptions->noclean = true;
  158. echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
  159. if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
  160. echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
  161. '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall edit" alt="'.$streditsummary.'" /></a><br /><br />';
  162. }
  163. echo '</div>';
  164. print_section($course, $thissection, $mods, $modnamesused);
  165. if (isediting($course->id)) {
  166. print_section_add_menus($course, $section, $modnames);
  167. }
  168. }
  169. echo '</td>';
  170. echo '<td class="right side">';
  171. if ($displaysection == $section) {
  172. echo '<a href="view.php?id='.$course->id.'&amp;week=0#section-'.$section.'" title="'.$strshowallweeks.'">'.
  173. '<img src="'.$CFG->pixpath.'/i/all.gif" class="icon wkall" alt="'.$strshowallweeks.'" /></a><br />';
  174. } else {
  175. $strshowonlyweek = get_string("showonlyweek", "", $section);
  176. echo '<a href="view.php?id='.$course->id.'&amp;week='.$section.'" title="'.$strshowonlyweek.'">'.
  177. '<img src="'.$CFG->pixpath.'/i/one.gif" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
  178. }
  179. if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
  180. if ($thissection->visible) { // Show the hide/show eye
  181. echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strweekhide.'">'.
  182. '<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
  183. } else {
  184. echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strweekshow.'">'.
  185. '<img src="'.$CFG->pixpath.'/i/show.gif" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
  186. }
  187. if ($section > 1) { // Add a arrow to move section up
  188. echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.$USER->sesskey.'#section-'.($section-1).'" title="'.$strmoveup.'">'.
  189. '<img src="'.$CFG->pixpath.'/t/up.gif" class="iconsmall up" alt="'.$strmoveup.'" /></a><br />';
  190. }
  191. if ($section < $course->numsections) { // Add a arrow to move section down
  192. echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.$USER->sesskey.'#section-'.($section+1).'" title="'.$strmovedown.'">'.
  193. '<img src="'.$CFG->pixpath.'/t/down.gif" class="iconsmall down" alt="'.$strmovedown.'" /></a><br />';
  194. }
  195. }
  196. echo '</td></tr>';
  197. echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
  198. }
  199. $section++;
  200. $weekdate = $nextweekdate;
  201. }
  202. echo '</table>';
  203. if (!empty($sectionmenu)) {
  204. echo '<div class="jumpmenu">';
  205. echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
  206. 'sectionmenu', '', get_string('jumpto'), '', '', true);
  207. echo '</div>';
  208. }
  209. print_container_end();
  210. echo '</td>';
  211. break;
  212. case 'right':
  213. // The right column
  214. if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
  215. echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
  216. print_container_start();
  217. blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
  218. print_container_end();
  219. echo '</td>';
  220. }
  221. break;
  222. }
  223. }
  224. echo '</tr></table>';
  225. ?>