2 /// This page prints all instances of attendance in a given course
3 error_reporting(E_ALL
);
4 require("../../config.php");
7 // if form is being submitted from generated form
8 if (isset($_POST["course"])) {
10 /// -----------------------------------------------------------------------------------
11 /// --------------------SECTION FOR PROCESSING THE FORM ON POST -----------------------
12 /// -----------------------------------------------------------------------------------
13 if (isset($SESSION->modform
)) { // Variables are stored in the session
14 $mod = $SESSION->modform
;
15 unset($SESSION->modform
);
17 $mod = (object)$_POST;
21 if (!empty($SESSION->returnpage
)) {
22 $return = $SESSION->returnpage
;
23 unset($SESSION->returnpage
);
26 redirect("view.php?id=$mod->course");
30 if (!isteacheredit($mod->course
)) {
31 error("You can't modify this course!");
35 if (file_exists($modlib)) {
36 include_once($modlib);
38 error("This module is missing important code! ($modlib)");
41 /* // set the information for the new instances
42 $attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
43 $attendance->day = make_timestamp($attendance->theyear,
44 $attendance->themonth, $attendance->theday);
45 $attendance->name=userdate($attendance->day, get_string("strftimedate"));
46 if ($attendance->notes) {
47 $attendance->name = $attendance->name . " - " . $attendance->notes;
50 $curdate = make_timestamp($mod->startyear
, $mod->startmonth
, $mod->startday
);
51 $stopdate = make_timestamp($mod->endyear
, $mod->endmonth
, $mod->endday
);
52 $enddate = $curdate +
$mod->numsections
* 604800;
53 if ($curdate > $stopdate) {
54 error(get_string("endbeforestart", "attendance"));
56 if ($enddate < $curdate) {
57 error(get_string("startafterend", "attendance"));
59 if ($stopdate > $enddate) {
60 // if stop date is after end of course, just move it to end of course
63 while ($curdate <= $stopdate) {
65 $mod->name
=userdate($mod->day
, get_string("strftimedate"));
66 if (isset($mod->notes
)) {$mod->name
= $mod->name
. " - " . $mod->notes
;}
67 switch(userdate($curdate, "%u")) {
68 case 1: if (!empty($mod->mon
)) {attendance_add_module($mod);}break;
69 case 2: if (!empty($mod->tue
)) {attendance_add_module($mod);}break;
70 case 3: if (!empty($mod->wed
)) {attendance_add_module($mod);}break;
71 case 4: if (!empty($mod->thu
)) {attendance_add_module($mod);}break;
72 case 5: if (!empty($mod->fri
)) {attendance_add_module($mod);}break;
73 case 6: if (!empty($mod->sat
)) {attendance_add_module($mod);}break;
74 case 7: if (!empty($mod->sun
)) {attendance_add_module($mod);}break;
76 $curdate = $curdate +
86400; // add one day to the date
79 if (!empty($SESSION->returnpage
)) {
80 $return = $SESSION->returnpage
;
81 unset($SESSION->returnpage
);
84 redirect("index.php?id=$mod->course");
89 /// -----------------------------------------------------------------------------------
90 /// ------------------ SECTION FOR MAKING THE FORM TO BE POSTED -----------------------
91 /// -----------------------------------------------------------------------------------
93 /// @include_once("$CFG->dirroot/mod/attendance/lib.php");
94 /// error_reporting(E_ALL);
96 require_variable($id);
97 require_variable($section);
99 if (! $course = get_record("course", "id", $id)) {
100 error("This course doesn't exist");
103 if (! $module = get_record("modules", "name", "attendance")) {
104 error("This module type doesn't exist");
107 $form->section
= $section; // The section number itself
108 $form->course
= $course->id
;
109 $form->module
= $module->id
;
110 $form->modulename
= $module->name
;
111 $form->instance
= "";
112 $form->coursemodule
= "";
115 $sectionname = get_string("name$course->format");
116 $fullmodulename = strtolower(get_string("modulename", $module->name
));
118 if ($form->section
) {
119 $heading->what
= $fullmodulename;
120 $heading->to
= "$sectionname $form->section";
121 $pageheading = get_string("addingmultiple", "attendance");
123 $pageheading = get_string("addingmultiple", "attendance");
126 if (!isteacheredit($course->id
)) {
127 error("You can't modify this course!");
130 $streditinga = get_string("editinga", "moodle", $fullmodulename);
131 $strmodulenameplural = get_string("modulenameplural", $module->name
);
133 if ($course->category
) {
134 print_header("$course->shortname: $streditinga", "$course->fullname",
135 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
136 <a href=\"$CFG->wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural</a> ->
137 $streditinga", "form.name", "", false);
139 print_header("$course->shortname: $streditinga", "$course->fullname",
140 "$streditinga", "form.name", "", false);
143 unset($SESSION->modform
); // Clear any old ones that may be hanging around.
146 $icon = "<img align=middle height=16 width=16 src=\"$CFG->modpixpath/$module->name/icon.gif\" alt=\"\" /> ";
148 print_heading_with_help($pageheading, "mods", $module->name
, $icon);
149 print_simple_box_start('center');
152 /// Print the main part of the page
154 // adaptation of mod code to view code needs this:
155 @include_once
("$CFG->dirroot/mod/attendance/lib.php");
156 //require_once("lib.php")
157 // determine the end date for the course based on the number of sections and the start date
158 $course->enddate
= $course->startdate +
$course->numsections
* 604800;
160 if (isset($CFG->attendance_dynsection
) && ($CFG->attendance_dynsection
== "1")) { $form->dynsection
= 1; }
161 if (isset($CFG->attendance_autoattend
) && ($CFG->attendance_autoattend
== "1")) { $form->autoattend
= 1; }
162 if (isset($CFG->attendance_grade
) && ($CFG->attendance_grade
== "1")) { $form->grade
= 1; }
163 $form->maxgrade
= isset($CFG->attendance_maxgrade
)?
$CFG->attendance_maxgrade
:0;
164 $form->hours
= isset($CFG->attendance_default_hours
)?
$CFG->attendance_default_hours
:1;
167 <form name
="form" method
="post" action
="add.php">
169 <input type
="submit" value
="<?php print_string("savechanges
") ?>" />
170 <input type
="submit" name
="cancel" value
="<?php print_string("cancel
") ?>" />
171 <table cellpadding
=5>
174 <td align
=right
><p
><b
><?php
print_string("startmulti", "attendance") ?
>:</b
></p
></td
>
175 <td colspan
="3"><?php
print_date_selector("startday", "startmonth", "startyear",$course->startdate
) ?
></td
>
178 <td align
=right
><p
><b
><?php
print_string("endmulti", "attendance") ?
>:</b
></p
></td
>
179 <td colspan
="3"><?php
print_date_selector("endday", "endmonth", "endyear",$course->enddate
) ?
></td
>
183 <td align
=right
><p
><b
><?php
print_string("choosedays", "attendance") ?
>:</b
></p
></td
>
185 <?php
print_string("sunday","attendance"); echo ":"; ?
>
186 <input type
="checkbox" name
="sun" />
187 <?php
print_string("monday","attendance"); echo ":"; ?
>
188 <input type
="checkbox" name
="mon" checked
="checked" />
189 <?php
print_string("tuesday","attendance"); echo ":"; ?
>
190 <input type
="checkbox" name
="tue" checked
="checked" />
191 <?php
print_string("wednesday","attendance"); echo ":"; ?
>
192 <input type
="checkbox" name
="wed" checked
="checked" />
193 <?php
print_string("thursday","attendance"); echo ":"; ?
>
194 <input type
="checkbox" name
="thu" checked
="checked" />
195 <?php
print_string("friday","attendance"); echo ":"; ?
>
196 <input type
="checkbox" name
="fri" checked
="checked" />
197 <?php
print_string("saturday","attendance"); echo ":"; ?
>
198 <input type
="checkbox" name
="sat" />
199 <?php
helpbutton("choosedays", get_string("choosedays","attendance"), "attendance");?
>
204 <td align
="right"><p
><b
><?php
print_string("dynamicsectionmulti", "attendance") ?
>:</b
></p
></td
>
208 $options[0] = get_string("no");
209 $options[1] = get_string("yes");
210 choose_from_menu($options, "dynsection", "", "");
211 helpbutton("dynsection", get_string("dynamicsectionmulti","attendance"), "attendance");
213 <!-- <input type
="checkbox" name
="dynsection" <?php
echo !empty($form->dynsection
) ?
'checked' : '' ?
> /> -->
217 <td align
="right"><p
><b
><?php
print_string("autoattendmulti", "attendance") ?
>:</b
></p
></td
>
221 $options[0] = get_string("no");
222 $options[1] = get_string("yes");
223 choose_from_menu($options, "autoattend", "", "");
224 helpbutton("autoattendmulti", get_string("autoattend","attendance"), "attendance");
228 <!-- <input type
="checkbox" name
="autoattend" <?php
echo !empty($form->autoattend
) ?
'checked' : '' ?
> /> -->
231 <?php
// starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
232 for ($i=2;$i<=24;$i++
){ $opt[$i] = $i; } ?
>
234 <td align
=right
><p
><b
><?php
print_string("hoursineachclass", "attendance") ?
>:</b
></p
></td
>
235 <td colspan
="3" align
="left"><?php
choose_from_menu($opt, "hours", $form->hours
, "1","","1") ?
>
236 <?php
helpbutton("hours", get_string("hoursinclass","attendance"), "attendance"); ?
>
241 <td align
="right"><p
><b
><?php
print_string("gradevaluemulti", "attendance") ?
>:</b
></p
></td
>
245 $options[0] = get_string("no");
246 $options[1] = get_string("yes");
247 choose_from_menu($options, "grade", "", "");
248 helpbutton("grade", get_string("gradevalue","attendance"), "attendance");
251 <!-- <input type
="checkbox" name
="grade" <?php
echo !empty($form->grade
) ?
'checked' : '' ?
> /> -->
254 <?php
// starting with 2 to allow for the nothing value in choose_from_menu to be the default of 1
255 for ($i=0;$i<=100;$i++
){ $opt2[$i] = $i; } ?
>
257 <td align
=right
><p
><b
><?php
print_string("maxgradevalue", "attendance") ?
>:</b
></p
></td
>
258 <td colspan
="3" align
="left"><?php
choose_from_menu($opt2, "maxgrade", $form->maxgrade
, "0","","0");
259 helpbutton("maxgrade", get_string("maxgradevalue","attendance"), "attendance");
265 <!-- These hidden variables are always the same
-->
266 <input type
="hidden" name
=course value
="<?php p($form->course) ?>" />
267 <input type
="hidden" name
=coursemodule value
="<?php p($form->coursemodule) ?>" />
268 <input type
="hidden" name
=section value
="<?php p($form->section) ?>" />
269 <input type
="hidden" name
=module value
="<?php p($form->module) ?>" />
270 <input type
="hidden" name
=modulename value
="<?php p($form->modulename) ?>" />
271 <input type
="hidden" name
=instance value
="<?php p($form->instance) ?>" />
272 <input type
="hidden" name
=mode value
="<?php p($form->mode) ?>" />
273 <input type
="hidden" name
=numsections value
="<?php p($course->numsections) ?>" />
275 <input type
="submit" value
="<?php print_string("savechanges
") ?>" />
276 <input type
="submit" name
="cancel" value
="<?php print_string("cancel
") ?>" />
281 print_simple_box_end();
283 print_footer($course);