coursefile="$_DATA/ical/$course"
attfile="$_DATA/mappings/attendance"
-action="$(POST action)"
-newfield="$(POST newfield |grep -m 1 -xE '[A-Z][A-Z0-9-]*')"
-
-if printf '%s\n' "$action" |grep -qxE 'addfield [A-Z][A-Z0-9]*'; then
- newfield="${action##* }"
- action=addfield
-fi
-
if ! tempfile="$(CHECK_SLOCK "$coursefile")"; then
SET_COOKIE 0 message="NO VALID FILE LOCK"
REDIRECT "/courses/?e=${course}"
| sed -E ':X;$!{N;bX}; s;\n;\;;g'
}
-course="$(pdi_load "$coursefile")"
+ics="$(pdi_load "$coursefile")"
tzid=$(cat /etc/timezone)
-course="$(pdi_update_attrib "$course" DTSTAMP 1 "TZID=${tzid}")"
-course="$(pdi_update_value "$course" DTSTAMP 1 "$(TZ="$tzid" date +%Y%m%dT%H%M%S)")"
+ics="$(pdi_update_attrib "$ics" DTSTAMP 1 "TZID=${tzid}")"
+ics="$(pdi_update_value "$ics" DTSTAMP 1 "$(TZ="$tzid" date +%Y%m%dT%H%M%S)")"
dts_year="$( POST DTS_YEAR |grep -m1 -xE '[0-9]{4}' || date +%Y)"
dts_month="$( POST DTS_MONTH |grep -m1 -xE '0[1-9]|1[012]' || date +%m)"
[ ${#dts_minute} -eq 1 ] && dts_minute="0$dts_minute"
DTSTART="${dts_year}${dts_month}${dts_day}T${dts_hour}${dts_minute}00"
-course="$(pdi_update_attrib "$course" DTSTART 1 "TZID=${tzid}")"
-course="$(pdi_update_value "$course" DTSTART 1 "$DTSTART")"
+ics="$(pdi_update_attrib "$ics" DTSTART 1 "TZID=${tzid}")"
+ics="$(pdi_update_value "$ics" DTSTART 1 "$DTSTART")"
rr_int=$( POST RRULE_INTERVAL |grep -m1 -xE '[0-9]+' || printf 1)
rr_count=$(POST RRULE_COUNT |grep -m1 -xE '[0-9]+' || printf 1)
ETERN|*) RRULE="FREQ=$rr_freq;INTERVAL=$rr_int";;
esac
-course="$(pdi_update_value "$course" RRULE 1 "$RRULE")"
+ics="$(pdi_update_value "$ics" RRULE 1 "$RRULE")"
for field in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*'); do
for cnt in $(seq 1 $(POST_COUNT "$field")); do
case "$field" in
*)
- course="$(pdi_update_value "$course" "$field" "$cnt" "$(vcf_escape "$(POST "$field" "$cnt")")")"
+ ics="$(pdi_update_value "$ics" "$field" "$cnt" "$(vcf_escape "$(POST "$field" "$cnt")")")"
;;
esac
done; done
delete_key="$(randomid)"
for delete in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*_delete_[0-9]+'); do
f="${delete%%_*}"; c="${delete##*_}";
- [ "$(POST "$delete")" = "true" ] && course="$(pdi_update_value "$course" "$f" "$c" "delete=${delete_key}")"
+ [ "$(POST "$delete")" = "true" ] && ics="$(pdi_update_value "$ics" "$f" "$c" "delete=${delete_key}")"
done
-course="$(printf '%s\n' "$course" |sed -E "/^[^:]+:delete=${delete_key}\$/d")"
+ics="$(printf '%s\n' "$ics" |sed -E "/^[^:]+:delete=${delete_key}\$/d")"
case "$(POST action)" in
addfield)
- course="$(pdi_update_value "$course" "$newfield" $(( $(pdi_count "$course" "$newfield") + 1 )) '')"
- printf '%s' "$course" |grep -vx '' >"$tempfile"
+ newfield="$(POST newfield |grep -m 1 -xE '[A-Z][A-Z0-9-]*')"
+ ics="$(pdi_update_value "$ics" "$newfield" $(( $(pdi_count "$ics" "$newfield") + 1 )) '')"
+ printf '%s' "$ics" |grep -vx '' >"$tempfile"
+ REDIRECT "/courses/?e=${course}"
+ ;;
+ addfield\ [A-Z]*)
+ newfield="$(POST action |sed -rn '1s;^addfield ([A-Z][A-Z0-9-]*)$;\1;p')"
+ ics="$(pdi_update_value "$ics" "$newfield" $(( $(pdi_count "$ics" "$newfield") + 1 )) '')"
+ printf '%s' "$ics" |grep -vx '' >"$tempfile"
REDIRECT "/courses/?e=${course}"
;;
update)
SET_COOKIE 0 message="COULD NOT UPDATE COURSE MAPPINGS"
fi
- printf '%s' "$course" |grep -vx '' >"${tempfile}.cp"
+ printf '%s' "$ics" |grep -vx '' >"${tempfile}.cp"
mv "${tempfile}.cp" "$coursefile"
RELEASE_SLOCK "$coursefile"
REDIRECT "/courses/#${course}"
RELEASE_SLOCK "$coursefile"
REDIRECT "/courses/"
;;
+ *)
+ printf '%s' "$ics" |grep -vx '' >"$tempfile"
+ REDIRECT "/courses/?e=${course}"
+ ;;
esac