8 use Data::Dump qw(dump);
10 my $odt_file = 'contributions.odt';
12 my $xs = XML::Simple->new();
14 use OpenOffice::OODoc 2.101;
15 my $doc = odfDocument(file => $odt_file, create => 'text');
22 family => 'paragraph',
27 'fo:text-align' => 'justify'
33 #foreach my $file ( glob 'contributions/*.xml' ) {
36 open(my $fh, '<:encoding(utf-8)', 'contributions/all.xml');
43 #warn "---xml---", dump($xml), "---/xml---\n";
45 foreach my $xml ( split(/\Q<?xml\E/, $xml) ) {
49 $xml = '<?xml' . $xml;
53 $abstract = $xs->XMLin( $xml, ForceArray => qw(PrimaryAuthor) );
55 warn "# abstract = ", dump($abstract);
57 my $id = $abstract->{'Id'}->[0] || die "no Id in ",dump($abstract);
58 warn "# $id abstract = ", dump($abstract);
60 foreach my $k (qw( ContributionType )) {
61 push @{ $stat->{$k}->{ $abstract->{$k}->[0] } }, $id;
64 if ( $abstract->{'ContributionType'}->[0] eq 'Symposium proposal' ) {
65 my $t = $abstract->{Title}->[0];
66 push @{ $stat->{_symposium}->{ $t } }, -$id;
69 if ( my $s = $abstract->{Symposium_title} ) {
71 push @{ $stat->{_symposium}->{$s} }, $id;
74 if ( exists $abstract->{PrimaryAuthor}->[0]->{FamilyName} ) {
75 $stat->{_order_by}->{$id} = $abstract->{PrimaryAuthor}->[0]->{FamilyName}->[0];
78 $abstracts->{ $id } = $abstract;
82 #warn "# stat = ",dump($stat);
87 warn "# enc in ",Encode::is_utf8($b), dump($b);
89 # $b = Encode::decode('iso-8859-1',$b); # XXX doesn't work!
91 # Encode::from_to($b, 'iso-8859-1','utf-8');
92 # Encode::_utf8_on($b);
94 Encode::_utf8_off($b);
96 warn "# enc out ",Encode::is_utf8($b), dump($b);
101 #return 'FIXME ref ' . dump($l) if ref $l;
102 return undef if ref $l;
103 return enc($l) if $l =~ m/([\x{80}-\x{ff}])/;
112 my $abstract = $abstracts->{$id} || die "no $id in abstracts ",dump($abstracts);
114 my $t = $doc->appendParagraph(text => $abstract->{Title}->[0], style => 'Heading 1');
115 $doc->setPageBreak( $t, position => 'before', style => 'Heading 1');
117 foreach my $a ( @{ $abstract->{PrimaryAuthor} } ) {
119 $v->{$_} = l1($a->{$_}->[0]) foreach qw( FirstName FamilyName Affiliation Email );
120 $doc->appendParagraph(text => $v->{FirstName} . ' ' . $v->{FamilyName}, style => 'Heading 2');
121 $doc->appendParagraph(text => $v->{Affiliation}, style => 'Heading 3');
122 push @{ $stat->{_Affiliation}->{ $v->{Affiliation} } }, $id;
128 # $doc->appendParagraph(text => $abstract->{Content}->[0], style => 'Abstract');
129 foreach my $p ( split(/[\n\r]+/, $abstract->{Content}->[0] ) ) {
130 $doc->appendParagraph(text => $p, style => 'Abstract');
133 # $doc->appendParagraph(text => "\nTheme: " . $abstract->{Theme}->[0], style => 'Theme');
135 # $doc->appendParagraph(text => "\nContributionType: " . $abstract->{ContributionType}->[0], style => 'Quotations');
137 $doc->appendParagraph(text => "\nID: " . $abstract->{Id}->[0], style => 'Abstract');
139 warn "# added $id to document\n";
142 #foreach my $id ( keys %$abstracts ) {
146 foreach my $symposium ( keys %{ $stat->{'_symposium'} } ) {
148 my $t = $doc->appendParagraph(text => $symposium, style => 'Title');
149 $doc->setPageBreak( $t, position => 'before', style => 'Title');
150 $doc->appendParagraph(text => 'Symposium', style => 'Subtitle');
152 my @symposium_ids = sort @{ $stat->{'_symposium'}->{$symposium} };
153 warn "## [$symposium] symposium_ids ", dump( @symposium_ids );
155 my $proposal_id = shift @symposium_ids;
156 if ( $proposal_id < 0 ) {
157 $proposal_id = abs( $proposal_id );
159 warn "ERROR: symposium [$symposium] doesn't have proposal!";
162 # @symposium_ids = sort { $stat->{_order_by}->{$a} cmp $stat->{_order_by}->{$b} } @symposium_ids;
163 @symposium_ids = sort @symposium_ids;
164 unshift @symposium_ids, $proposal_id;
166 $stat->{_order_symposium}->{$symposium} = [ @symposium_ids ];
168 foreach my $id ( @symposium_ids ) {
174 foreach my $type ( 'Oral presentation', 'Poster presentation' ) {
176 my $t = $doc->appendParagraph(text => $type, style => 'Title');
177 $doc->setPageBreak( $t, position => 'before', style => 'Title');
179 my @order = sort { lc $stat->{_order_by}->{$a} cmp lc $stat->{_order_by}->{$b} }
180 @{ $stat->{'ContributionType'}->{$type} };
182 $stat->{ '_order_' . $type } = [ @order ];
184 foreach my $id ( @order ) {
190 warn "# stat = ",dump($stat);
195 open(my $fh, '>', 'affiliation.csv');
196 foreach my $a ( sort keys %{ $stat->{_Affiliation} } ) {
197 print $fh '"',$a,'","',dump( $stat->{_Affiliation}->{$a} ), '"', "\n";
202 open(my $authors_fh, '>', 'authors.html');
203 foreach my $a ( sort { $a->{FamilyName} cmp $b->{FamilyName} } @authors ) {
206 <b>$a->{FamilyName}, $a->{FirstName}</b><br>
207 $a->{Affiliation}<br>
210 print $authors_fh $html eq $last_html ? '<!-- dup -->' : $html;
217 "Symposium proposal" => 12,
218 "Symposium abstract" => 52,
219 "Oral presentation" => 141,
220 "Poster presentation" => 71,