#!/usr/bin/env bash
-tmp=/tmp/$USER-dbq-vi-$$
-
-_main() {
- #exec echo $tmp
- dbq.php "$1/vi/$2.sh" > "$tmp" || return
-
- perl -i -pe 's/(\w+=".*?") /$1\n/g; s/;\s*$/\n/ ' "$tmp"
-
- md5=$(md5sum "$tmp")
-
- vi "$tmp"
- [ -s "$tmp" ] || return
- [ "$md5" == "$(md5sum "$tmp")" ] && return
- bash -f "$tmp" || return
- #echo $md5 " == $(md5sum "$tmp")"
-
- eval dbq.php $1/update/ format=yaml $(cat "$tmp")
-
-}
+tmp=/tmp/$USER-dbq-vi-$$.yaml
main() {
#exec echo $tmp
+ path="$1"
+ id="$2"
cat <<EOF > "$tmp"
#
# dbq-vi
#
EOF
- dbq.php "$1/vi/$2.yaml" >> "$tmp" || return
+ if [ -z "$id" ]
+ then
+ dbq.php "$path/add.yaml" >> "$tmp" || return
+ sed -i -e 's/"//g' "$tmp"
+ else
+ dbq.php "$path/vi/$id.yaml" >> "$tmp" || return
+ fi
md5=$(md5sum "$tmp")
vi "$tmp"
[ "$md5" == "$(md5sum "$tmp")" ] && return
#echo $md5 " == $(md5sum "$tmp")"
- dbq.php $1/update.yaml __YAML__="$tmp"
+ if [ -z "$id" ]
+ then
+ dbq.php $path/insert.yaml __YAML__="$tmp"
+ else
+ dbq.php $path/update.yaml __YAML__="$tmp"
+ fi
}
#debug([count($keys),$keys,count($values),$values]);
$values = array_combine($keys,$values);
+ if ($add and (0
+ or $this->params['format'] == 'yaml'
+ or $this->params['format'] == 'json'
+ )) {
+ foreach ($this->table->fields() as $field) {
+ $fields[$field->name] = '';
+ }
+ $this->db->out($fields);
+ return;
+
# Handle format for /vi
- if ($this->params['format'] != $this->format_html) {
+ } elseif ($this->params['format'] != $this->format_html) {
#debug($values);
$row = $this->db->query2h($this->table->html_edit_sql($values));