done
}
+edit_item(){
+ local card="$1"
+ local item cnt c
+ shift 1
+
+ for item in $@; do
+ cnt="$(pdi_count "$card" "$item")"
+ [ $cnt -lt 1 ] && cnt=1
+
+ case $item in
+ N)if N="$(pdi_value "$card" N)"; then
+ IFS=\; read n1 n2 n3 n4 n5 <<-EOF
+ $(pdi_value "$card" N)
+ EOF
+ else
+ N="$(pdi_value "$card" FN |unescape)"
+ n1="${N%%[a-z]*}" n1="${N#$n1}"
+ [ "$n1" ] || n1="${N##* }"
+ n2="${N%$n1}"
+ fi
+ printf '
+ [h3 %s]
+ [input .item .N name="4N" placeholder="%s" value="%s"]
+ [input .item .N name="2N" placeholder="%s" value="%s"]
+ [input .item .N name="1N" placeholder="%s" value="%s"]
+ [input .item .N name="5N" placeholder="%s" value="%s"]
+ ' "$(l10n "$item")" \
+ "$(l10n n_pre)" "$(HTML "$n4")" \
+ "$(l10n n_first)" "$(HTML "$n2" "$n3")" \
+ "$(l10n n_last)" "$(HTML "$n1")" \
+ "$(l10n n_post)" "$(HTML "$n5")"
+ ;;
+ GENDER)
+ printf '
+ [select .item .GENDER name="GENDER"
+ [option value="" disabled="disabled" %s %s]
+ [option value="female" %s %s]
+ [option value="male" %s %s]
+ [option value="other" %s %s]
+ [option value="none" %s %s]
+ ]
+ ' \
+ "$([ "$(pdi_value "$card" GENDER)" = '' ] && printf 'selected="selected"')" \
+ "$(l10n GENDER)" \
+ "$([ "$(pdi_value "$card" GENDER)" = 'female' ] && printf 'selected="selected"')" \
+ "$(l10n gender_female)" \
+ "$([ "$(pdi_value "$card" GENDER)" = 'male' ] && printf 'selected="selected"')" \
+ "$(l10n gender_male)" \
+ "$([ "$(pdi_value "$card" GENDER)" = 'other' ] && printf 'selected="selected"')" \
+ "$(l10n gender_other)" \
+ "$([ "$(pdi_value "$card" GENDER)" = 'none' ] && printf 'selected="selected"')" \
+ "$(l10n gender_none)"
+ ;;
+ BDAY|X-ZACK-JOIDATE|X-ZACK-LEAVEDATE)
+ printf '[h3 %s]
+ [input .item .%s name="%s" value="%s" placeholder="YYYY-MM-DD"]
+ ' \
+ "$(l10n "$item")" "$item" "$item" "$(pdi_value "$card" "$item" |grep -xE '[0-9-]+')"
+ ;;
+ ADR|NOTE)
+ printf '[h3 %s]' "$(l10n "$item")"
+ seq 1 $cnt |while read c; do
+ printf '<textarea class="item %s" name="%s">%s</textarea>' \
+ "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)"
+ done
+ ;;
+ *) printf '[h3 %s]' "$(l10n "$item")"
+ seq 1 $cnt |while read c; do
+ printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
+ "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
+ done
+ ;;
+ esac
+ done
+}
+
+edit_card(){
+ local cardfile="$_DATA/vcard/$1"
+ local card="$(pdi_load "$cardfile")"
+
+ cat <<-EOF
+ [form .card #${cardfile##*/} action="/cards/update_card.sh" method="POST"
+ [div .section .basic $(
+ edit_item "$card" N GENDER
+ [ "$(pdi_count "$card" NICKNAME)" -gt 0 ] \
+ && edit_item "$card" NICKNAME
+ edit_item "$card" X-ZACK-JOINDATE
+ [ "$(pdi_count "$card" X-ZACK-LEAVEDATE)" -gt 0 ] \
+ && edit_item "$card" X-ZACK-LEAVEDATE
+ card_item "$card" SOUND PHOTO LOGO
+ )]
+ [div .section .phone $(edit_item "$card" TEL)]
+ [div .section .message $(
+ edit_item "$card" EMAIL
+ [ $(pdi_count "$card" IMPP) -gt 0 ] && edit_item "$card" IMPP
+ [ $(pdi_count "$card" URL ) -gt 0 ] && edit_item "$card" URL
+ )]
+ [div .section .address $(edit_item "$card" ADR)]
+ [div .section .note $(edit_item "$card" NOTE)]
+ [div .section .attendance
+ [h3 $(l10n course_attendance) ] $(
+ for course in "$_DATA"/ical/*.ics; do
+ printf '[label [input type="checkbox" name="attendance" value="%s" %s] %s]' \
+ "${course##*/}" \
+ "$(grep -qF "${course##*/} ${cardfile##*/}" "$_DATA/mappings/attendance" \
+ && printf 'checked="checked"'
+ )" \
+ "$(pdi_value "$(pdi_load "$course")" SUMMARY |unescape |HTML)"
+ done)
+ [h3 $(l10n CATEGORIES) ] $(
+ grep -xE '[^ ]+' "$_DATA"/mappings/categories |while read -r cat; do
+ printf '[label [input type="checkbox" name="attendance" value="%s" %s] %s]' \
+ "$(HTML "$cat")" \
+ "$(seq 1 $(pdi_count "$card" CATEGORIES) |while read c; do
+ pdi_value "$card" CATEGORIES $c |grep -qxF "$cat" \
+ && printf 'checked="checked"' && break
+ done)" \
+ "$(HTML "$cat")"
+ done)
+ ]
+ [div .control
+ [select .item name="newfield"
+ [option value="" disabled="disabled" selected="selected" $(l10n edit_addfieldtext)]
+ $(for f in ; do
+ printf '[option value="%s" %s] ' "$f" "$(l10n "$f")"
+ done)
+ ]
+ [button .item type="submit" name="action" value="addfield" $(l10n edit_addfield)]
+ [button .item type="submit" name="action" value="update" $(l10n edit_update)]
+ [input type="checkbox" #delete] [label .item for="delete" $(l10n edit_delete)]
+ [button .item type="submit" name="action" value="delete"]
+ [button .item type="submit" name="action" value="cancel" $(l10n edit_cancel)]
+ ]
+ [input type="hidden" name="UID" value="$(pdi_value "$card" UID |HTML)"]
+ [input type="hidden" name="card" value="${cardfile##*/}"]
+ ]
+ EOF
+}
+
print_card(){
local cardfile="$1"
local cachefile="${_DATA}/cache/${cardfile##*/}.cache"
$(card_item "$card" CATEGORIES)
]
[div .control
- [a .item href="/cards/${cardfile##*/}?action=edit" $(l10n edit)]
- [a .item href="/cards/${cardfile##*/}?action=export" $(l10n vcf_export)]
+ [a .item href="/cards/?e=${cardfile##*/}" $(l10n edit)]
+ [a .item href="/cards/?x=${cardfile##*/}" $(l10n vcf_export)]
]
]
EOF
local filter f fex='x;p;'
filter="$(printf %s "${filter}" \
- | sed -E 's;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\\\&;g;
+ | sed -E 's;[]\/\(\)\\\$\?\.\+\*\;\[\{\}];\\\\&;g;
'"$upcase"
)^"
list_cards(){
filter_cards \
| order_cards \
+ | grep -xvF "$edit" \
| while read cardfile; do
print_card "$cardfile"
done