.newcard {
display: block;
border: solid 1px;
- border-radius: 0 0 4px 4px;
- margin: .25em 2em 1em 2em;
- padding: .25em 2ex .25em 2ex;
- background: #EFF;
+ margin: 1em 2em .5em 2em;
+ padding: .5em;
+ text-align: right;
+ background: #EEF;
+}
+.newcard button {
+ box-shadow: 0 0 .5ex #888;
}
.card {
height: 100%;
width: 20ex;
max-width: 33%;
- padding: .25em 1ex;
+ padding: .25em .5em;
}
.card .control .item {
display: inline-block;
display: inline-block;
vertical-align: top;
float: left;
- width: 20ex;
- min-width: 16.5%;
+ width: 16.625%;
+ min-width: 10em;
min-height: 6em;
margin: .125em 0 .5ex 0;
padding: 0 1ex .25em 1ex;
. "${_EXEC}"/pdiread.sh
-unescape() { [ $# = 0 ] && sed -E 's;\\(.);\1;g' || printf %s "$*" |sed -E 's;\\(.);\1;g'; }
-upcase=' y;abcdefghijklmnopqrstuvwxyzäöüé;ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉ;; '
-
-card_item(){
- local card="$1"
- local item cnt c
- shift 1
-
- for item in $@; do
- cnt="$(pdi_count "$card" "$item")"
-
- case $item in
- FN) printf '[h2 .item .FN ­%s]' "$(pdi_value "$card" FN |unescape |HTML)"
- ;;
- GENDER) printf '[span .item .GENDER ­%s]' "$(pdi_value "$card" GENDER |l10n)"
- ;;
- NICKNAME) seq 1 $cnt |while read c; do
- printf '[span .item .NICKNAME ­aka. "%s"]' \
- "$(pdi_value "$card" NICKNAME $c |unescape |HTML)"
- done
- ;;
- X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) if [ $cnt -gt 0 ]; then
- printf '[span .item .%s [b %s:] %s]' \
- "$item" "$(l10n "${item}_short")" \
- "$(pdi_value "$card" "$item" |HTML)"
- fi
- ;;
- BDAY)
- [ $cnt -gt 0 ] && printf '[span .item .BDAY [b *:] %s]' \
- "$(pdi_value "$card" BDAY |grep -xE '[0-9-]+')"
- ;;
- SOUND)
- [ $cnt -gt 0 ] && printf '[audio .item .SOUND controls="controls"
- [source type="audio/ogg" src="data:audio/ogg;base64,%s"]
- ]' \
- "$(pdi_value "$card" SOUND |grep -xE '[a-zA-Z0-9/+=]+')"
- ;;
- PHOTO|LOGO)
- [ $cnt -gt 0 ] && printf '[img .item .%s src="data:image/%s;base64,%s"]' "$item" \
- "$(pdi_attrib "$card" "$item" |sed -E 's;^(.*;)?TYPE="?(.+)"?(;.*)?$;\2;')" \
- "$(pdi_value "$card" "$item" |grep -xE '[a-zA-Z0-9/+=]+')"
- ;;
- EMAIL)
- [ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n EMAIL)"
- seq 1 $cnt |while read c; do
- printf '[a .item .EMAIL href="mailto:%s" ­%s]' \
- "$(pdi_value "$card" EMAIL $c |unescape |HTML)" \
- "$(pdi_value "$card" EMAIL $c |unescape |HTML)"
- done
- ;;
- TEL)
- [ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n TEL)"
- seq 1 $cnt |while read c; do
- teltype="$(pdi_attrib "$card" TEL $c TYPE)"
- [ "$teltype" ] \
- && printf '[span .item .TEL [span .type ­%s:] %s]' \
- "$(l10n "TYPE=$teltype" |HTML)" \
- "$(pdi_value "$card" TEL $c |unescape |HTML)" \
- || printf '[span .item .TEL ­%s]' \
- "$(pdi_value "$card" TEL $c |unescape |HTML)"
- done
- ;;
- *)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")"
- seq 1 $cnt |while read c; do
- printf '[span .item .%s ­%s]' "$item" \
- "$(pdi_value "$card" "$item" $c |unescape |HTML)"
- done
- ;;
- esac
- 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)N="$(pdi_value "$card" N)"
- if [ "$N" ]; then
- IFS=\; read n1 n2 n3 n4 n5 <<-EOF
- $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)
- gender="$(pdi_value "$card" 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]
- ]\n' \
- "$([ "$gender" = '' ] && printf 'selected="selected"')" "$(l10n GENDER)" \
- "$([ "$gender" = 'female' ] && printf 'selected="selected"')" "$(l10n gender_female)" \
- "$([ "$gender" = 'male' ] && printf 'selected="selected"')" "$(l10n gender_male)" \
- "$([ "$gender" = 'other' ] && printf 'selected="selected"')" "$(l10n gender_other)" \
- "$([ "$gender" = 'none' ] && printf 'selected="selected"')" "$(l10n gender_none)"
- ;;
- BDAY|X-ZACK-JOINDATE|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 '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
- "$item" $c "$item" $c "$item" $c "$(l10n delete)"
- printf '<textarea class="item %s" name="%s">%s</textarea>' \
- "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)"
- done
- printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
- ;;
- TEL) printf '[h3 %s]' "$(l10n "$item")"
- seq 1 $cnt |while read c; do
- printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
- "$item" $c "$item" $c "$item" $c "$(l10n delete)"
- teltype="$(pdi_attrib "$card" TEL $c TYPE)"
- printf '[select .item .teltype name="teltype"
- [option value="" disabled="disabled" %s %s]
- [option value="HOME" %s %s]
- [option value="WORK" %s %s]
- [option value="CELL" %s %s]
- [option value="FAX" %s %s]
- ]\n' \
- "$([ "$teltype" = '' ] && printf 'selected="selected"')" "$(l10n teltype)" \
- "$([ "$teltype" = 'HOME' ] && printf 'selected="selected"')" "$(l10n TYPE=HOME)" \
- "$([ "$teltype" = 'WORK' ] && printf 'selected="selected"')" "$(l10n TYPE=WORK)" \
- "$([ "$teltype" = 'CELL' ] && printf 'selected="selected"')" "$(l10n TYPE=CELL)" \
- "$([ "$teltype" = 'FAX' ] && printf 'selected="selected"')" "$(l10n TYPE=FAX)"
-
- printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
- "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
- done
- printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
- ;;
- *)printf '[h3 %s]' "$(l10n "$item")"
- seq 1 $cnt |while read c; do
- printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
- "$item" $c "$item" $c "$item" $c "$(l10n delete)"
- printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
- "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
- done
- printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
- ;;
- esac
- done
-}
-
edit_card(){
local cardfile="$_DATA/vcard/$1"
local tempfile card
. $_EXEC/cards/widgets.sh
. $_EXEC/cards/list.sh
+unescape() { [ $# = 0 ] && sed -E 's;\\(.);\1;g' || printf %s "$*" |sed -E 's;\\(.);\1;g'; }
+upcase=' y;abcdefghijklmnopqrstuvwxyzäöüé;ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉ;; '
+
filter="$(GET f)"
order="$(GET o)"
edit="$(GET e)"
{ w_filter_diag
printf '
- [form class="newcard" action="cards/new_card.sh" method="POST"
+ [form class="newcard" action="/cards/new_card.sh" method="POST"
[button type="submit" %s]
]' "$(l10n newcard)"
#!/bin/zsh
-# Copyright 2014 Paul Hänsch
+# Copyright 2014, 2019 Paul Hänsch
#
# This file is part of Confetti.
#
# You should have received a copy of the GNU Affero General Public License
# along with Confetti. If not, see <http://www.gnu.org/licenses/>.
-cgi_post
-cgi_refdata
+filter="$(REF f)"
+order="$(REF o)"
-filter="&filter=${_REF[filter]}"
-filtertype="&filtertype=${_REF[filtertype]}"
-order="&order=${_REF[order]}"
-
-uid=$(uuidgenerator)
+uid="$(timeid)$(randomid)" # 32 Octets UID, starting with timestamp
card="${uid}.vcf"
-tempfile="$_DATA/temp/$card"
-
-cat >"$tempfile" <<EOF
-BEGIN:VCARD
-VERSION:4.0
-N:;;;;
-BDAY:
-TEL:
-EMAIL:
-ADR:
-NOTE:
-UID:$uid
-END:VCARD
-EOF
+mkdir -p "${_DATA}/lock/vcard/"
+lockdir="${_DATA}/lock/vcard/${card}/"
+lockfile=${lockdir}/${SESSION_ID}
-echo -n "Location: ?p=cards${filter}${filtertype}${order}&edit=$card\n\n"
+if mkdir "$lockdir"; then
+ cat >"$lockfile" <<-EOF
+ BEGIN:VCARD
+ VERSION:4.0
+ N:;;;;
+ BDAY:
+ TEL:
+ EMAIL:
+ ADR:
+ NOTE:
+ UID:${uid}
+ END:VCARD
+ EOF
+ REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}"
+else
+ SET_COOKIE session message="EDITLOCK"
+ REDIRECT "/cards/?o=${order}&f=${filter}"
+fi
# ENDCARD
# done
+#!/bin/sh
+
+card_item(){
+ local card="$1"
+ local item cnt c
+ shift 1
+
+ for item in $@; do
+ cnt="$(pdi_count "$card" "$item")"
+
+ case $item in
+ FN) printf '[h2 .item .FN ­%s]' "$(pdi_value "$card" FN |unescape |HTML)"
+ ;;
+ GENDER) printf '[span .item .GENDER ­%s]' "$(pdi_value "$card" GENDER |l10n)"
+ ;;
+ NICKNAME) seq 1 $cnt |while read c; do
+ printf '[span .item .NICKNAME ­aka. "%s"]' \
+ "$(pdi_value "$card" NICKNAME $c |unescape |HTML)"
+ done
+ ;;
+ X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) if [ $cnt -gt 0 ]; then
+ printf '[span .item .%s [b %s:] %s]' \
+ "$item" "$(l10n "${item}_short")" \
+ "$(pdi_value "$card" "$item" |HTML)"
+ fi
+ ;;
+ BDAY)
+ [ $cnt -gt 0 ] && printf '[span .item .BDAY [b *:] %s]' \
+ "$(pdi_value "$card" BDAY |grep -xE '[0-9-]+')"
+ ;;
+ SOUND)
+ [ $cnt -gt 0 ] && printf '[audio .item .SOUND controls="controls"
+ [source type="audio/ogg" src="data:audio/ogg;base64,%s"]
+ ]' \
+ "$(pdi_value "$card" SOUND |grep -xE '[a-zA-Z0-9/+=]+')"
+ ;;
+ PHOTO|LOGO)
+ [ $cnt -gt 0 ] && printf '[img .item .%s src="data:image/%s;base64,%s"]' "$item" \
+ "$(pdi_attrib "$card" "$item" |sed -E 's;^(.*;)?TYPE="?(.+)"?(;.*)?$;\2;')" \
+ "$(pdi_value "$card" "$item" |grep -xE '[a-zA-Z0-9/+=]+')"
+ ;;
+ EMAIL)
+ [ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n EMAIL)"
+ seq 1 $cnt |while read c; do
+ printf '[a .item .EMAIL href="mailto:%s" ­%s]' \
+ "$(pdi_value "$card" EMAIL $c |unescape |HTML)" \
+ "$(pdi_value "$card" EMAIL $c |unescape |HTML)"
+ done
+ ;;
+ TEL)
+ [ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n TEL)"
+ seq 1 $cnt |while read c; do
+ teltype="$(pdi_attrib "$card" TEL $c TYPE)"
+ [ "$teltype" ] \
+ && printf '[span .item .TEL [span .type ­%s:] %s]' \
+ "$(l10n "TYPE=$teltype" |HTML)" \
+ "$(pdi_value "$card" TEL $c |unescape |HTML)" \
+ || printf '[span .item .TEL ­%s]' \
+ "$(pdi_value "$card" TEL $c |unescape |HTML)"
+ done
+ ;;
+ *)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")"
+ seq 1 $cnt |while read c; do
+ printf '[span .item .%s ­%s]' "$item" \
+ "$(pdi_value "$card" "$item" $c |unescape |HTML)"
+ done
+ ;;
+ esac
+ 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)N="$(pdi_value "$card" N)"
+ if [ "$N" ]; then
+ IFS=\; read n1 n2 n3 n4 n5 <<-EOF
+ $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)
+ gender="$(pdi_value "$card" 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]
+ ]\n' \
+ "$([ "$gender" = '' ] && printf 'selected="selected"')" "$(l10n GENDER)" \
+ "$([ "$gender" = 'female' ] && printf 'selected="selected"')" "$(l10n gender_female)" \
+ "$([ "$gender" = 'male' ] && printf 'selected="selected"')" "$(l10n gender_male)" \
+ "$([ "$gender" = 'other' ] && printf 'selected="selected"')" "$(l10n gender_other)" \
+ "$([ "$gender" = 'none' ] && printf 'selected="selected"')" "$(l10n gender_none)"
+ ;;
+ BDAY|X-ZACK-JOINDATE|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 '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
+ "$item" $c "$item" $c "$item" $c "$(l10n delete)"
+ printf '<textarea class="item %s" name="%s">%s</textarea>' \
+ "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)"
+ done
+ printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
+ ;;
+ TEL) printf '[h3 %s]' "$(l10n "$item")"
+ seq 1 $cnt |while read c; do
+ printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
+ "$item" $c "$item" $c "$item" $c "$(l10n delete)"
+ teltype="$(pdi_attrib "$card" TEL $c TYPE)"
+ printf '[select .item .teltype name="teltype"
+ [option value="" disabled="disabled" %s %s]
+ [option value="HOME" %s %s]
+ [option value="WORK" %s %s]
+ [option value="CELL" %s %s]
+ [option value="FAX" %s %s]
+ ]\n' \
+ "$([ "$teltype" = '' ] && printf 'selected="selected"')" "$(l10n teltype)" \
+ "$([ "$teltype" = 'HOME' ] && printf 'selected="selected"')" "$(l10n TYPE=HOME)" \
+ "$([ "$teltype" = 'WORK' ] && printf 'selected="selected"')" "$(l10n TYPE=WORK)" \
+ "$([ "$teltype" = 'CELL' ] && printf 'selected="selected"')" "$(l10n TYPE=CELL)" \
+ "$([ "$teltype" = 'FAX' ] && printf 'selected="selected"')" "$(l10n TYPE=FAX)"
+
+ printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
+ "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
+ done
+ printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
+ ;;
+ *)printf '[h3 %s]' "$(l10n "$item")"
+ seq 1 $cnt |while read c; do
+ printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \
+ "$item" $c "$item" $c "$item" $c "$(l10n delete)"
+ printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \
+ "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")"
+ done
+ printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)"
+ ;;
+ esac
+ done
+}