summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-06-04 14:30:07 +0200
committerYorhel <git@yorhel.nl>2020-06-04 14:30:09 +0200
commit946bed68c9376e4593bd6599000cab4d3d30a5cf (patch)
treeb1eaf5883c3fef5a6a3e94e65693e3a63ab516da
parent1b6d7fbb2eb4ba76d1d2c8844afaf8aa0fe4ab0a (diff)
Delete old character edit form
Not used anymore.
-rw-r--r--data/js/chartraits.js123
-rw-r--r--data/js/charvns.js194
-rw-r--r--data/js/main.js4
-rw-r--r--data/style.css19
-rw-r--r--lib/VNDB/DB/Chars.pm49
-rw-r--r--lib/VNDB/DB/Misc.pm1
-rw-r--r--lib/VNDB/Handler/Chars.pm228
-rw-r--r--lib/VNWeb/HTML.pm5
8 files changed, 1 insertions, 622 deletions
diff --git a/data/js/chartraits.js b/data/js/chartraits.js
deleted file mode 100644
index 968b68ee..00000000
--- a/data/js/chartraits.js
+++ /dev/null
@@ -1,123 +0,0 @@
-function ctrLoad() {
- // load current traits
- var l = byId('traits').value.split(' ');
- var v = {}; // tag id -> spoiler lookup table
- var q = []; // list of id=X parameters
- for(var i=0; i<l.length; i++) {
- if(l[i]) {
- var m = l[i].split(/-/);
- v[m[0]] = Math.floor(m[1]);
- q[i] = 'id='+m[0];
- }
- }
- if(q.length > 0)
- ajax('/xml/traits.xml?r=200;'+q.join(';'), function (ht) {
- var t = ht.responseXML.getElementsByTagName('item');
- for(var i=0; i<t.length; i++)
- ctrAdd(t[i], v[t[i].getAttribute('id')]);
- }, 1);
- else
- ctrEmpty();
-
- // dropdown
- dsInit(byId('trait_input'), '/xml/traits.xml?q=', function(item, tr) {
- var g = item.getAttribute('groupname');
- g = g ? g+' / ' : '';
- tr.appendChild(tag('td', { style: 'text-align: right; padding-right: 5px'}, 'i'+item.getAttribute('id')));
- tr.appendChild(tag('td',
- tag('b', {'class':'grayedout'}, g), item.firstChild.nodeValue,
- tag('b', {'class':'grayedout'}, item.getAttribute('applicable')=='no' ? 'not applicable' : '')));
- }, ctrFormAdd);
-}
-
-function ctrEmpty() {
- var x = byId('traits_loading');
- var t = byId('traits_tbl');
- if(x)
- t.removeChild(x);
- var l = byName(t, 'tr');
- var e = byId('traits_empty');
- if(e && l.length > 1)
- t.removeChild(e);
- else if(!e && l.length < 1)
- t.appendChild(tag('tr', {id:'traits_empty',colspan:3}, tag('td', 'No traits present yet.')));
-}
-
-function ctrAdd(item, spoil) {
- var id = item.getAttribute('id');
- var name = item.firstChild.nodeValue;
- var group = item.getAttribute('groupname');
- var sp = tag('td', {'class':'tc_spoil', onclick:ctrSpoilNext, ctr_spoil:spoil}, fmtspoil(spoil));
- ddInit(sp, 'left', ctrSpoilDD);
- byId('traits_tbl').appendChild(tag('tr', {ctr_id:id, ctr_spoiler:spoil},
- tag('td', {'class':'tc_name'},
- tag('b', {'class':'grayedout'}, group?group+' / ':''),
- tag('a', {'href':'/i'+id}, name)),
- sp,
- tag('td', {'class':'tc_del'}, tag('a', {href:'#', onclick:ctrDel}, 'remove'))
- ));
- ctrEmpty();
- ctrSerialize();
-}
-
-function ctrFormAdd(item) {
- var l = byName(byId('traits_tbl'), 'tr');
- for(var i=0; i<l.length; i++)
- if(l[i].ctr_id && l[i].ctr_id == item.getAttribute('id'))
- break;
- if(i < l.length)
- alert('Selected trait is already present.');
- else if(item.getAttribute('applicable') == 'no')
- alert('This trait can\'t be used here.');
- else
- ctrAdd(item, Math.floor(item.getAttribute('defaultspoil')));
- return '';
-}
-
-function ctrSpoilNext() {
- if(++this.ctr_spoil > 2)
- this.ctr_spoil = 0;
- setText(this, fmtspoil(this.ctr_spoil));
- ddRefresh();
- ctrSerialize();
-}
-
-function ctrSpoilDD(lnk) {
- var lst = tag('ul', null);
- for(var i=0; i<=2; i++)
- lst.appendChild(tag('li', i == lnk.ctr_spoil
- ? tag('i', fmtspoil(i))
- : tag('a', {href: '#', onclick:ctrSpoilSet, ctr_td:lnk, ctr_sp:i}, fmtspoil(i))
- ));
- return lst;
-}
-
-function ctrSpoilSet() {
- this.ctr_td.ctr_spoil = this.ctr_sp;
- setText(this.ctr_td, fmtspoil(this.ctr_sp));
- ddHide();
- ctrSerialize();
- return false;
-}
-
-function ctrDel() {
- var tr = this;
- while(tr.nodeName.toLowerCase() != 'tr')
- tr = tr.parentNode;
- tr.parentNode.removeChild(tr);
- ctrEmpty();
- ctrSerialize();
- return false
-}
-
-function ctrSerialize() {
- var l = byName(byId('traits_tbl'), 'tr');
- var v = [];
- for(var i=0; i<l.length; i++)
- if(l[i].ctr_id)
- v.push(l[i].ctr_id+'-'+byClass(l[i], 'tc_spoil')[0].ctr_spoil);
- byId('traits').value = v.join(' ');
-}
-
-if(byId('traits_tbl'))
- ctrLoad();
diff --git a/data/js/charvns.js b/data/js/charvns.js
deleted file mode 100644
index dcac2950..00000000
--- a/data/js/charvns.js
+++ /dev/null
@@ -1,194 +0,0 @@
-function cvnLoad() {
- // load current links
- var l = byId('vns').value.split(' ');
- var v = {}; // vid -> { rid: [ role, spoil ], .. }
- var q = []; // list of v=X parameters
- for(var i=0; i<l.length; i++) {
- if(!l[i])
- continue;
- var m = l[i].split(/-/); // vid, rid, spoil, role
- if(!v[m[0]]) {
- q.push('v='+m[0]);
- v[m[0]] = {};
- }
- v[m[0]][m[1]] = [ m[3], m[2] ];
- }
- if(q.length > 0)
- ajax('/xml/releases.xml?'+q.join(';'), function(hr) {
- var vns = byName(hr.responseXML, 'vn');
- for(var i=0; i<vns.length; i++) {
- var vid = vns[i].getAttribute('id');
- cvnVNAdd(vns[i]);
- var rels = byName(vns[i], 'release');
- for(var r=0; r<rels.length; r++) {
- var rid = rels[r].getAttribute('id');
- if(v[vid][rid])
- cvnRelAdd(vid, rid, v[vid][rid][0], v[vid][rid][1]);
- }
- if(v[vid][0])
- cvnRelAdd(vid, 0, v[vid][0][0], v[vid][0][1]);
- }
- cvnEmpty();
- }, 1);
- else
- cvnEmpty();
-
- // dropdown search
- dsInit(byId('vns_input'), '/xml/vn.xml?q=', function(item, tr) {
- tr.appendChild(tag('td', { style: 'text-align: right; padding-right: 5px'}, 'v'+item.getAttribute('id')));
- tr.appendChild(tag('td', shorten(item.firstChild.nodeValue, 40)));
- }, cvnFormAdd);
-}
-
-function cvnEmpty() {
- var x = byId('vns_loading');
- var t = byId('vns_tbl');
- if(x)
- t.removeChild(x);
- var l = byName(t, 'tr');
- var e = byId('vns_empty');
- if(e && l.length > 1)
- t.removeChild(e);
- else if(!e && l.length < 1)
- t.appendChild(tag('tr', {id:'vns_empty',colspan:3}, tag('td', 'No visual novels selected.')));
-}
-
-function cvnVNAdd(vn, rel) {
- var vid = vn.getAttribute('id');
- var rels = byName(vn, 'release');
- byId('vns_tbl').appendChild(tag('tr', {id:'cvn_v'+vid, cvn_vid:vid, cvn_rels:rels},
- tag('td', {'class':'tc_vn',colspan:4}, 'v'+vid+':',
- tag('a', {href:'/v'+vid}, vn.getAttribute('title')),
- tag('i', '(', tag('a', {href:'#', onclick:cvnRelNew}, 'add release'), ')')
- )
- ));
- if(rel)
- cvnRelAdd(vid, 0, 'primary', 0);
- cvnEmpty();
-}
-
-function cvnRelAdd(vid, rid, role, spoil) {
- var rels = byId('cvn_v'+vid).cvn_rels;
- var rsel = tag('select', {onchange:cvnRelChange}, tag('option', {value:0}, 'All / others'));
- for(var i=0; i<rels.length; i++) {
- var id = rels[i].getAttribute('id');
- rsel.appendChild(tag('option', {value: id, selected:id==rid},
- '['+rels[i].getAttribute('lang')+'] '+rels[i].firstChild.nodeValue+' (r'+id+')'));
- }
-
- var lsel = tag('select', {onchange:cvnSerialize});
- for(var i=0; i<VARS.char_roles.length; i++)
- lsel.appendChild(tag('option', {value: VARS.char_roles[i][0], selected:VARS.char_roles[i][0]==role}, VARS.char_roles[i][1]));
-
- var ssel = tag('select', {onchange:cvnSerialize});
- for(var i=0; i<3; i++)
- ssel.appendChild(tag('option', {value:i, selected:i==spoil}, fmtspoil(i)));
-
- var tbl = byId('vns_tbl');
- var l = byName(tbl, 'tr');
- var last = null;
- for(var i=1; i<l.length; i++)
- if(l[i-1].cvn_vid == vid && l[i].cvn_vid != vid)
- last = l[i-1];
- tbl.insertBefore(tag('tr', {id:'cvn_v'+vid+'r'+rid, cvn_vid:vid, cvn_rid:rid},
- tag('td', {'class':'tc_rel'}, rsel),
- tag('td', {'class':'tc_rol'}, lsel),
- tag('td', {'class':'tc_spl'}, ssel),
- tag('td', {'class':'tc_del'}, tag('a', {href:'#', onclick:cvnRelDel}, 'remove'))
- ), last);
-}
-
-function cvnRelChange() {
- // look for duplicates and disallow the change
- var val = this.options[this.selectedIndex].value;
- var tr = this;
- while(tr.nodeName.toLowerCase() != 'tr')
- tr = tr.parentNode;
- if(byId('cvn_v'+tr.cvn_vid+'r'+val)) {
- alert('Release already present.');
- for(var i=0; i<this.options.length; i++)
- this.options[i].selected = this.options[i].value == tr.cvn_rid;
- return;
- }
- // otherwise, 'rename' this entry
- tr.id = 'cvn_v'+tr.cvn_vid+'r'+val;
- tr.cvn_rid = val;
- cvnSerialize();
-}
-
-function cvnRelNew() {
- var tr = this;
- while(tr.nodeName.toLowerCase() != 'tr')
- tr = tr.parentNode;
- var id = 0;
- if(byId('cvn_v'+tr.cvn_vid+'r0')) {
- for(var i=0; i<tr.cvn_rels.length; i++) {
- id = tr.cvn_rels[i].getAttribute('id');
- if(!byId('cvn_v'+tr.cvn_vid+'r'+id))
- break;
- }
- if(i == tr.cvn_rels.length) {
- alert('All releases already selected.');
- return false;
- }
- }
- cvnRelAdd(tr.cvn_vid, id, 'primary', 0);
- cvnSerialize();
- return false;
-}
-
-function cvnRelDel() {
- var tbl = byId('vns_tbl');
- var tr = this;
- while(tr.nodeName.toLowerCase() != 'tr')
- tr = tr.parentNode;
- tbl.removeChild(tr);
- var l = byName(tbl, 'tr');
- var c = 0;
- for(var i=0; i<l.length; i++)
- if(l[i].cvn_vid == tr.cvn_vid)
- c++;
- if(c <= 1)
- tbl.removeChild(byId('cvn_v'+tr.cvn_vid));
- cvnSerialize();
- cvnEmpty();
- return false;
-}
-
-function cvnFormAdd(item) {
- var inpt = byId('vns_input');
- inpt.disabled = true;
-
- ajax('/xml/releases.xml?v='+item.getAttribute('id'), function(hr) {
- inpt.disabled = false;
- inpt.value = '';
-
- var items = byName(hr.responseXML, 'vn');
- if(items.length < 1) // shouldn't happen
- return alert('Oops! Error!');
-
- var id = items[0].getAttribute('id');
- if(byId('cvn_v'+id))
- return alert('VN already present.');
- cvnVNAdd(items[0], 1);
- cvnSerialize();
- }, 1);
- return 'Loading...';
-}
-
-function cvnSerialize() {
- var l = byName(byId('vns_tbl'), 'tr');
- var v = [];
- for(var i=0; i<l.length; i++)
- if(l[i].cvn_rid != null) {
- var rol = byName(byClass(l[i], 'tc_rol')[0], 'select')[0];
- var spl = byName(byClass(l[i], 'tc_spl')[0], 'select')[0];
- v.push(l[i].cvn_vid+'-'+l[i].cvn_rid+'-'+
- spl.options[spl.selectedIndex].value+'-'+
- rol.options[rol.selectedIndex].value);
- }
- byId('vns').value = v.join(' ');
-}
-
-if(byId('jt_box_chare_vns'))
- cvnLoad();
diff --git a/data/js/main.js b/data/js/main.js
index 042c18e8..91a09422 100644
--- a/data/js/main.js
+++ b/data/js/main.js
@@ -39,8 +39,4 @@ VARS = /*VARS*/;
// Producer editing (/p+/edit)
//include prodrel.js
-// Character editing (/c+/edit)
-//include chartraits.js
-//include charvns.js
-
// @license-end
diff --git a/data/style.css b/data/style.css
index 6eadbd92..dd4f8726 100644
--- a/data/style.css
+++ b/data/style.css
@@ -661,25 +661,6 @@ table.chare_traits .buts a { box-sizing: border-box; display: block; width: 1
table.chare_traits .buts a.s0 { border: none; background-color: #0f0 }
table.chare_traits .buts a.s1 { border: none; background-color: #f80 }
table.chare_traits .buts a.s2 { border: none; background-color: #f40 }
-#jt_box_chare_img div.img { float: left; height: 300px; padding-right: 20px; }
-#jt_box_chare_img h2 { margin: 0; }
-#jt_box_chare_traits table { margin-bottom: 10px; margin-left: 10px; }
-#jt_box_chare_traits h2 { margin: 0 0 3px 0px; }
-#jt_box_chare_traits td.tc_name { width: 200px }
-#jt_box_chare_traits td.tc_name input { width: 280px; }
-#jt_box_chare_traits td.tc_spoil { width: 80px; }
-#jt_box_chare_vns table { margin-bottom: 10px; margin-left: 10px; }
-#jt_box_chare_vns h2 { margin: 0 0 3px 0px; }
-#jt_box_chare_vns td.tc_vn { font-weight: bold; padding: 5px 0 3px 0 }
-#jt_box_chare_vns td.tc_vn i { font-weight: normal; padding-left: 5px; font-style: normal }
-#jt_box_chare_vns td.tc_rel { width: 340px; padding-left: 15px }
-#jt_box_chare_vns td.tc_rel select { width: 340px; }
-#jt_box_chare_vns td.tc_rol,
-#jt_box_chare_vns td.tc_rol select { width: 150px }
-#jt_box_chare_vns td.tc_spl,
-#jt_box_chare_vns td.tc_spl select { width: 100px }
-#jt_box_chare_vns td.tc_del { padding-left: 5px }
-#jt_box_chare_vns td.tc_vnadd input { width: 280px }
/***** Char browse *****/
diff --git a/lib/VNDB/DB/Chars.pm b/lib/VNDB/DB/Chars.pm
index 6f1463c1..0b159452 100644
--- a/lib/VNDB/DB/Chars.pm
+++ b/lib/VNDB/DB/Chars.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbCharFilters dbCharGet dbCharGetRev dbCharRevisionInsert|;
+our @EXPORT = qw|dbCharFilters dbCharGet|;
# Character filters shared by dbCharGet and dbVNGet
@@ -86,31 +86,6 @@ sub dbCharGet {
}
-sub dbCharGetRev {
- my $self = shift;
- my %o = (what => '', @_);
-
- $o{rev} ||= $self->dbRow('SELECT MAX(rev) AS rev FROM changes WHERE type = \'c\' AND itemid = ?', $o{id})->{rev};
-
- my $select = 'c.itemid AS id, ch.name, ch.original, ch.gender';
- $select .= ', extract(\'epoch\' from c.added) as added, c.comments, c.rev, c.ihid, c.ilock, '.VNWeb::DB::sql_user();
- $select .= ', c.id AS cid, NOT EXISTS(SELECT 1 FROM changes c2 WHERE c2.type = c.type AND c2.itemid = c.itemid AND c2.rev = c.rev+1) AS lastrev';
- $select .= ', ch.alias, ch.desc, coalesce(vndbid_num(ch.image), 0) as image, ch.b_month, ch.b_day, ch.s_bust, ch.s_waist, ch.s_hip, ch.height, ch.weight, ch.bloodt, ch.cup_size, ch.age, ch.main, ch.main_spoil, co.hidden, co.locked' if $o{what} =~ /extended/;
-
- my $r = $self->dbAll(q|
- SELECT !s
- FROM changes c
- JOIN chars co ON co.id = c.itemid
- JOIN chars_hist ch ON ch.chid = c.id
- JOIN users u ON u.id = c.requester
- WHERE c.type = 'c' AND c.itemid = ? AND c.rev = ?|,
- $select, $o{id}, $o{rev}
- );
-
- return _enrich($self, $r, 0, 1, $o{what});
-}
-
-
sub _enrich {
my($self, $r, $np, $rev, $what, $vid) = @_;
@@ -172,26 +147,4 @@ sub _enrich {
}
-# Updates the edit_* tables, used from dbItemEdit()
-# Arguments: { columns in chars_rev + traits + vns },
-sub dbCharRevisionInsert {
- my($self, $o) = @_;
-
- my %set = map exists($o->{$_}) ? (qq|"$_" = ?|, $o->{$_}) : (),
- qw|name original alias desc b_month b_day s_bust s_waist s_hip height weight bloodt cup_size age gender main main_spoil|;
- $set{'image = vndbid(\'ch\',?)'} = $o->{image}||undef if exists $o->{image};
- $self->dbExec('UPDATE edit_chars !H', \%set) if keys %set;
-
- if($o->{traits}) {
- $self->dbExec('DELETE FROM edit_chars_traits');
- $self->dbExec('INSERT INTO edit_chars_traits (tid, spoil) VALUES (?,?)', $_->[0],$_->[1]) for (@{$o->{traits}});
- }
- if($o->{vns}) {
- $self->dbExec('DELETE FROM edit_chars_vns');
- $self->dbExec('INSERT INTO edit_chars_vns (vid, rid, spoil, role) VALUES(!l)', $_) for (@{$o->{vns}});
- }
-}
-
-
1;
-
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
index e089f3fb..3921db3a 100644
--- a/lib/VNDB/DB/Misc.pm
+++ b/lib/VNDB/DB/Misc.pm
@@ -28,7 +28,6 @@ sub dbItemEdit {
$self->dbVNRevisionInsert( \%o) if $type eq 'v';
$self->dbProducerRevisionInsert(\%o) if $type eq 'p';
- $self->dbCharRevisionInsert( \%o) if $type eq 'c';
return $self->dbRow('SELECT * FROM edit_!s_commit()', $type);
}
diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm
index 55936775..353ee37f 100644
--- a/lib/VNDB/Handler/Chars.pm
+++ b/lib/VNDB/Handler/Chars.pm
@@ -11,238 +11,10 @@ use VNDB::Types;
our @EXPORT = ('charBrowseTable');
TUWF::register(
- qr{old/c(?:([1-9]\d*)(?:\.([1-9]\d*))?/(edit|copy)|/new)}
- => \&edit,
qr{c/([a-z0]|all)} => \&list,
);
-sub edit {
- my($self, $id, $rev, $copy) = @_;
-
- $copy = $rev && $rev eq 'copy' || $copy && $copy eq 'copy';
- $rev = undef if defined $rev && $rev !~ /^\d+$/;
-
- my $r = $id && $self->dbCharGetRev(id => $id, what => 'extended vns traits', $rev ? (rev => $rev) : ())->[0];
- return $self->resNotFound if $id && !$r->{id};
- $rev = undef if !$r || $r->{lastrev};
-
- return $self->htmlDenied if !$self->authCan('edit')
- || $id && (($r->{locked} || $r->{hidden}) && !$self->authCan('dbmod'));
-
- my %b4 = !$id ? () : (
- (map +($_ => $r->{$_}), qw|name original alias desc image ihid ilock s_bust s_waist s_hip height weight bloodt cup_size age gender main_spoil|),
- main => $r->{main}||0,
- bday => $r->{b_month} ? sprintf('%02d-%02d', $r->{b_month}, $r->{b_day}) : '',
- traits => join(' ', map sprintf('%d-%d', $_->{tid}, $_->{spoil}), sort { $a->{tid} <=> $b->{tid} } @{$r->{traits}}),
- vns => join(' ', map sprintf('%d-%d-%d-%s', $_->{vid}, $_->{rid}||0, $_->{spoil}, $_->{role}),
- sort { $a->{vid} <=> $b->{vid} || ($a->{rid}||0) <=> ($b->{rid}||0) } @{$r->{vns}}),
- );
- my $frm;
-
- if($self->reqMethod eq 'POST') {
- return if !$self->authCheckCode;
- $frm = $self->formValidate(
- { post => 'name', maxlength => 200 },
- { post => 'original', required => 0, maxlength => 200, default => '' },
- { post => 'alias', required => 0, maxlength => 500, default => '' },
- { post => 'desc', required => 0, maxlength => 5000, default => '' },
- { post => 'gender', required => 0, default => 'unknown', enum => [ keys %GENDER ] },
- { post => 'image', required => 0, default => 0, template => 'id' },
- { post => 'bday', required => 0, default => '', regex => [ qr/^(?:[01]?[0-9])-(?:[0123]?[0-9])$/, 'Birthday must be in MM-DD format.' ] },
- { post => 's_bust', required => 0, default => 0, template => 'uint', max => 32767 },
- { post => 's_waist', required => 0, default => 0, template => 'uint', max => 32767 },
- { post => 's_hip', required => 0, default => 0, template => 'uint', max => 32767 },
- { post => 'height', required => 0, default => 0, template => 'uint', max => 32767 },
- { post => 'weight', required => 0, default => undef, template => 'uint', max => 32767 },
- { post => 'bloodt', required => 0, default => 'unknown', enum => [ keys %BLOOD_TYPE ] },
- { post => 'cup_size', required => 0, default => '', enum => [ keys %CUP_SIZE ] },
- { post => 'age', required => 0, default => undef, template => 'uint', max => 32767 },
- { post => 'main', required => 0, default => 0, template => 'id' },
- { post => 'main_spoil', required => 0, default => 0, enum => [ 0..2 ] },
- { post => 'traits', required => 0, default => '', regex => [ qr/^(?:[1-9]\d*-[0-2])(?: +[1-9]\d*-[0-2])*$/, 'Incorrect trait format.' ] },
- { post => 'vns', required => 0, default => '', regex => [ qr/^(?:[1-9]\d*-\d+-[0-2]-[a-z]+)(?: +[1-9]\d*-\d+-[0-2]-[a-z]+)*$/, 'Incorrect VN format.' ] },
- { post => 'editsum', template => 'editsum' },
- { post => 'ihid', required => 0 },
- { post => 'ilock', required => 0 },
- );
- $frm->{original} = '' if $frm->{original} eq $frm->{name};
-
- # handle image upload
- $frm->{image} = _uploadimage($self, $frm);
-
- # validate main character
- if(!$frm->{_err} && $frm->{main}) {
- my $m = $self->dbCharGet(id => $frm->{main}, what => 'extended')->[0];
- push @{$frm->{_err}}, 'Invalid main character. Make sure the ID is correct,'
- .' that the main character itself is not an instance of an other character,'
- .' and that this entry is not used as a main character elsewhere.'
- if !$m || $m->{main} || $r && !$copy && ($m->{id} == $r->{id} || $self->dbCharGet(instance => $r->{id})->[0]);
- }
-
- my(@traits, @vns);
- if(!$frm->{_err}) {
- # parse and normalize
- @vns = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } map [split /-/], split / /, $frm->{vns};
- $frm->{vns} = join(' ', map sprintf('%d-%d-%d-%s', @$_), @vns);
- $frm->{ihid} = $frm->{ihid} ?1:0;
- $frm->{ilock} = $frm->{ilock}?1:0;
- $frm->{desc} = $self->bbSubstLinks($frm->{desc});
- $frm->{main_spoil} = 0 if !$frm->{main};
-
- @traits = sort { $a->[0] <=> $b->[0] } map /^(\d+)-(\d+)$/&&[$1,$2], split / /, $frm->{traits};
- my %traits = @traits ? map +($_->{id}, 1), @{$self->dbTraitGet(results => 500, state => 2, applicable => 1, id => [ map $_->[0], @traits ])} : ();
- @traits = grep $traits{$_->[0]}, @traits;
- $frm->{traits} = join(' ', map sprintf('%d-%d', @$_), @traits);
-
- # check for changes
- my $same = $id && !grep +($frm->{$_}//'') ne ($b4{$_}//''), keys %b4;
- return $self->resRedirect("/c$id", 'post') if !$copy && $same;
- $frm->{_err} = ["No changes, please don't create an entry that is fully identical to another"] if $copy && $same;
- }
-
- if(!$frm->{_err}) {
- # modify for dbCharRevisionInsert
- ($frm->{b_month}, $frm->{b_day}) = delete($frm->{bday}) =~ /^(\d{2})-(\d{2})$/ ? ($1, $2) : (0, 0);
- $frm->{main} ||= undef;
- $frm->{traits} = \@traits;
- $_->[1]||=undef for (@vns);
- $frm->{vns} = \@vns;
-
- my $nrev = $self->dbItemEdit(c => !$copy && $id ? ($r->{id}, $r->{rev}) : (undef, undef), %$frm);
- return $self->resRedirect("/c$nrev->{itemid}.$nrev->{rev}", 'post');
- }
- }
-
- if(!$id) {
- my $vid = $self->formValidate({ get => 'vid', required => 1, template => 'id'});
- $frm->{vns} //= "$vid->{vid}-0-0-primary" if !$vid->{_err};
- }
- $frm->{$_} //= $b4{$_} for keys %b4;
- $frm->{editsum} //= sprintf 'Reverted to revision c%d.%d', $id, $rev if !$copy && $rev;
- $frm->{editsum} = sprintf 'New character based on c%d.%d', $id, $r->{rev} if $copy;
-
- my $title = !$r ? 'Add new character' : $copy ? "Copy $r->{name}" : "Edit $r->{name}";
- $self->htmlHeader(title => $title, noindex => 1);
- $self->htmlMainTabs('c', $r, $copy ? 'copy' : 'edit') if $r;
- $self->htmlEditMessage('c', $r, $title, $copy);
- $self->htmlForm({ frm => $frm, action => $r ? "/old/c$id/".($copy ? 'copy' : 'edit') : '/old/c/new', editsum => 1, upload => 1 },
- chare_geninfo => [ 'General info',
- [ input => name => 'Name (romaji)', short => 'name' ],
- [ input => name => 'Original name', short => 'original' ],
- [ static => content => 'The original name of the character, leave blank if it is already in the Latin alphabet.' ],
- [ text => name => 'Aliases', short => 'alias', rows => 3 ],
- [ static => content => '(Un)official aliases, separated by a newline.' ],
- [ text => name => 'Description<br /><b class="standout">English please!</b>', short => 'desc', rows => 6 ],
- [ select => name => 'Sex', short => 'gender', options => [
- map [ $_, $GENDER{$_} ], keys %GENDER ] ],
- [ input => name => 'Birthday', short => 'bday', width => 100,post => ' MM-DD (e.g. "01-26" for the 26th of January)' ],
- [ input => name => 'Age', short => 'age', width => 50, post => ' years', allow0 => 1 ],
- [ input => name => 'Bust', short => 's_bust', width => 50, post => ' cm' ],
- [ input => name => 'Waist', short => 's_waist',width => 50, post => ' cm' ],
- [ input => name => 'Hips', short => 's_hip', width => 50, post => ' cm' ],
- [ input => name => 'Height', short => 'height', width => 50, post => ' cm' ],
- [ input => name => 'Weight', short => 'weight', width => 50, post => ' kg', allow0 => 1 ],
- [ select => name => 'Blood type',short => 'bloodt', options => [
- map [ $_, $BLOOD_TYPE{$_} ], keys %BLOOD_TYPE ] ],
- [ select => name => 'Cup size', short => 'cup_size', options => [
- map [ $_, $CUP_SIZE{$_} ], keys %CUP_SIZE ] ],
- [ static => content => '<br />' ],
- [ input => name => 'Instance of',short => 'main', width => 50, post => ' ID of the main character - the character of which this is an instance of.' ],
- [ select => name => 'Spoiler', short => 'main_spoil', options => [
- map [$_, fmtspoil $_], 0..2 ] ],
- ],
-
- chare_img => [ 'Image', [ static => nolabel => 1, content => sub {
- div class => 'img';
- p 'No image uploaded yet' if !$frm->{image};
- img src => imgurl(ch => $frm->{image}) if $frm->{image};
- end;
-
- div;
- h2 'Image ID';
- input type => 'text', class => 'text', name => 'image', id => 'image', value => $frm->{image}||'';
- p 'Use a character image that is already on the server. Set to \'0\' to remove the current image.';
- br; br;
-
- h2 'Upload new image';
- input type => 'file', class => 'text', name => 'img', id => 'img';
- p 'Image must be in JPEG or PNG format and at most 1MiB. Images larger than 256x300 will automatically be resized. Image must be safe for work!';
- end;
- }]],
-
- chare_traits => [ 'Traits',
- [ hidden => short => 'traits' ],
- [ static => nolabel => 1, content => sub {
- h2 'Current traits';
- table; tbody id => 'traits_tbl';
- Tr id => 'traits_loading'; td colspan => '3', 'Loading...'; end;
- end; end;
- h2 'Add trait';
- table; Tr;
- td class => 'tc_name'; input id => 'trait_input', type => 'text', class => 'text'; end;
- td colspan => 2, '';
- end; end 'table';
- }],
- ],
-
- chare_vns => [ 'Visual novels',
- [ hidden => short => 'vns' ],
- [ static => nolabel => 1, content => sub {
- h2 'Selected visual novels';
- table; tbody id => 'vns_tbl';
- Tr id => 'vns_loading'; td colspan => '4', 'Loading...'; end;
- end; end;
- h2 'Add visual novel';
- table; Tr;
- td class => 'tc_vnadd'; input id => 'vns_input', type => 'text', class => 'text'; end;
- td colspan => 3, '';
- end; end;
- }],
- ]);
- $self->htmlFooter;
-}
-
-
-sub _uploadimage {
- my($self, $frm) = @_;
-
- if($frm->{_err} || !$self->reqPost('img')) {
- return 0 if !$frm->{image};
- push @{$frm->{_err}}, 'No image with that ID' if !-s imgpath(ch => $frm->{image});
- return $frm->{image};
- }
-
- # perform some elementary checks
- my $imgdata = $self->reqUploadRaw('img');
- $frm->{_err} = [ 'Image must be in JPEG or PNG format' ] if $imgdata !~ /^(\xff\xd8|\x89\x50)/; # JPG or PNG headers
- $frm->{_err} = [ 'Image is too large, only 1MB allowed' ] if length($imgdata) > 1024*1024;
- return undef if $frm->{_err};
-
- # resize/compress
- my $im = Image::Magick->new;
- $im->BlobToImage($imgdata);
- my($ow, $oh) = ($im->Get('width'), $im->Get('height'));
- my($nw, $nh) = imgsize($ow, $oh, @{$self->{ch_size}});
- $im->Set(background => '#ffffff');
- $im->Set(alpha => 'Remove');
- if($ow != $nw || $oh != $nh) {
- $im->GaussianBlur(geometry => '0.5x0.5');
- $im->Resize(width => $nw, height => $nh);
- $im->UnsharpMask(radius => 0, sigma => 0.75, amount => 0.75, threshold => 0.008);
- }
- $im->Set(magick => 'JPEG', quality => 90);
-
- # Get ID and save
- my $imgid = $self->dbImageAdd(ch => $nw, $nh);
- my $fn = imgpath(ch => $imgid);
- $im->Write($fn);
- chmod 0666, $fn;
-
- return $imgid;
-}
-
-
sub list {
my($self, $fch) = @_;
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 25df6152..5ab3aff8 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -812,11 +812,6 @@ sub editmsg_ {
li_ 'Fields marked with (*) may cause other fields to become (un)available depending on the selection.' if $type eq 'r';
}
};
- p_ class => 'center', sub {
- txt_ "If you're having trouble using this new form, the ";
- a_ href => '/old'.($obj ? "/c$obj->{id}/".tuwf->capture('action') : '/c/new?vid='.tuwf->capture('id')), 'old form';
- txt_ ' is still available.';
- } if $type eq 'c' && tuwf->reqPath() !~ m{^/old/};
}
}