Index: ossp-pkg/sdb/sdb.cgi RCS File: /v/ossp/cvs/ossp-pkg/sdb/sdb.cgi,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/sdb/sdb.cgi,v' 2>/dev/null --- sdb.cgi 2003/05/29 11:03:04 1.1 +++ sdb.cgi 2003/05/29 18:52:55 1.2 @@ -192,7 +192,7 @@ # open DB environment my $db; ($db = DBI->connect("dbi:SQLite:dbname=sdb.db", "", "")) - || die "unable to SQLite database sdb.db"; + || die "unable to connect to SQLite database \"sdb.db\""; $db->{AutoCommit} = 1; $db->{RaiseError} = 1; @@ -266,7 +266,6 @@ ## _________________________________________________________________________ ## -# FIXME # determine default UI display my $page = undef; foreach my $p (keys(%{$ui})) { @@ -346,7 +345,8 @@ $html >> q{page}; # generate page contents -foreach my $page (sort(keys(%{$ui}))) { +foreach my $page (@ui_pages) { + next if (not defined($ui->{$page})); if ($ui->{$page}->{-is} =~ m/^(visible|hidden)$/) { my $found = 0; foreach my $sub ( @@ -364,14 +364,15 @@ } } -# insert html into output HTTP response body +# insert HTML into output HTTP response body $html->undivert(0); $body .= $html->string(); # optional debugging +$body .= "

\n"; $body .= "

\n";
 my @names = $cgi->param;
-foreach my $name (@names) {
+foreach my $name (sort(@names)) {
     my $value = $cgi->param($name);
     $body .= "  $name=\"$value\"\n";
 }
@@ -391,8 +392,8 @@
 sub ui_main_init {
     my ($my, $cgi, $db, $ui, $page) = @_;
 
-    $ui->{main}        = { -is => 'disable' };
-    $ui->{main}->{all} = { -is => 'disable' };
+    $ui->{main}        = { -is => 'disable', -with => 'default' };
+    $ui->{main}->{all} = { -is => 'disable', -with => 'default' };
 }
 
 sub ui_main_action {
@@ -440,19 +441,23 @@
 sub ui_person_init {
     my ($my, $cgi, $db, $ui, $page) = @_;
 
-    $ui->{person}           = { -is => 'disable' };
-    $ui->{person}->{select} = { -is => 'disable' };
-    $ui->{person}->{detail} = { -is => 'disable' };
-    $ui->{person}->{skill}  = { -is => 'disable' };
+    #   initialize person page
+    $ui->{person}           = { -is => 'disable', -with => 'default' };
+    $ui->{person}->{select} = { -is => 'disable', -with => 'default' };
+    $ui->{person}->{detail} = { -is => 'disable', -with => 'default' };
+    $ui->{person}->{skill}  = { -is => 'disable', -with => 'default' };
 }
 
 sub ui_person_action {
     my ($my, $cgi, $db, $ui, $page, $area, $elem) = @_;
 
+    #   recreate action string
+    my $action = "$page.$area.$elem";
+
     #   actions on select box
     if ($ui->{person}->{select}->{ADD}) {
         #   just open detail area for addition
-        $ui->{person}->{detail}->{id} = undef;
+        $ui->{person}->{detail}->{id}    = undef;
         $ui->{person}->{detail}->{-is}   = 'visible';
         $ui->{person}->{detail}->{-with} = 'add';
     }
@@ -572,98 +577,96 @@
     my $html = new String::Divert;
     $html->overload(1); 
 
-    if ($ui->{person}->{-is} eq 'visible') {
-        #   generate outer page CSS class
-        $html .= "\n";
-        $html .= "  "; $html *= q{person};
-        $html .= "\n";
-        $html >> q{person};
-
-        #   generate header
-        $html .= "

Persons

\n"; - $html .= "{URL}\">← Back to Main Menu"; - - # generate page canvas - # +-------+-------+ - # | area1 | area2 | - # +-------+-------+ - # | area3 | - # +---------------+ - $html .= "

\n"; - $html .= "\n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= "
\n"; - $html .= " "; $html *= q{area1}; - $html .= " \n"; - $html .= "   \n"; - $html .= " \n"; - $html .= " "; $html *= q{area2}; - $html .= "
\n"; - $html .= "  \n"; - $html .= "
\n"; - $html .= " "; $html *= q{area3}; - $html .= "
\n"; - } - else { - $html *= q{area1}; - $html *= q{area2}; - $html *= q{area3}; - } + # filter output according to visibility + $html->storage(($ui->{person}->{-is} eq 'visible' ? 'all' : 'fold')); + # generate outer page CSS class + $html .= "\n"; + $html .= " " . $cgi->hidden(-name => "person", -default => 1)."\n"; + $html .= " "; $html *= q{person}; + $html .= "\n"; + $html >> q{person}; + + # generate header + $html .= "

Persons

\n"; + $html .= "{URL}\">← Back to Main Menu"; + + # generate page canvas + # +-------+-------+ + # | area1 | area2 | + # +-------+-------+ + # | area3 | + # +---------------+ + $html .= "

\n"; + $html .= "\n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= "
\n"; + $html .= " "; $html *= q{area1}; + $html .= " \n"; + $html .= "   \n"; + $html .= " \n"; + $html .= " "; $html *= q{area2}; + $html .= "
\n"; + $html .= "  \n"; + $html .= "
\n"; + $html .= " "; $html *= q{area3}; + $html .= "
\n"; + + ## _____________________________________________________________________ ## ## generate area: Person Selection + ## _____________________________________________________________________ ## - if ($ui->{person}->{-is} eq 'visible') { - # force selection box to be always visible - # if whole area is visible - $ui->{person}->{select}->{-is} = 'visible'; + + # force selection box to be always visible if whole area is visible + $ui->{person}->{select}->{-is} = 'visible' + if ($ui->{person}->{-is} eq 'visible'); + + # generate CSS class + $html >> q{area1}; + $html .= "\n"; + $html .= " "; $html *= q{select}; + $html .= "\n"; + $html >> q{select}; + + # generate inner header + $html .= "

Select Person and Action

\n"; + + # generate inner canvas + $html .= "\n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= " \n"; + $html .= "
\n"; + $html .= " "; $html *= q{select-list}; + $html .= " \n"; + $html .= " "; $html *= q{select-buttons}; + $html .= "
\n"; + + # generate the selection list widget + $html >> q{select-list}; + my $rv = $db->selectall_arrayref( + "SELECT pe_id,pe_name FROM sdb_person ORDER BY pe_name;" + ); + my $pe_values = []; + my $pe_labels = {}; + foreach my $r (@{$rv}) { + push(@{$pe_values}, $r->[0]); + $pe_labels->{$r->[0]} = $r->[1]; } - #$html->storage($ui->{person}->{select}->{-is} eq 'visible' ? 1 : 0); + my $pe_default = $ui->{person}->{select}->{id} || $pe_values->[0]; if ($ui->{person}->{select}->{-is} eq 'visible') { - # generate CSS class - $html >> q{area1}; - $html .= "\n"; - $html .= " "; $html *= q{select}; - $html .= "\n"; - $html >> q{select}; - - # generate inner header - $html .= "

Select Person and Action

\n"; - - # generate inner canvas - $html .= "\n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= "
\n"; - $html .= " "; $html *= q{select-list}; - $html .= " \n"; - $html .= " "; $html *= q{select-buttons}; - $html .= "
\n"; - - # generate the selection list widget - $html >> q{select-list}; - my $rv = $db->selectall_arrayref( - "SELECT pe_id,pe_name FROM sdb_person ORDER BY pe_name;" - ); - my $pe_values = []; - my $pe_labels = {}; - foreach my $r (@{$rv}) { - push(@{$pe_values}, $r->[0]); - $pe_labels->{$r->[0]} = $r->[1]; - } - my $pe_default = $ui->{person}->{select}->{id} || $pe_values->[0]; if (@{$pe_values} > 0) { $html .= $cgi->scrolling_list( -override => 1, @@ -675,87 +678,111 @@ -class => 'id', ) . "\n"; } - $html << q{select-list}; + } + else { + $html .= $cgi->hidden( + -name => 'person.select.id', + -default => $pe_default + ); + } + $html << q{select-list}; - # generate the selection list attached buttons - $html >> "select-buttons"; + # generate the selection list attached buttons + $html >> "select-buttons"; + $html .= $cgi->submit( + -name => 'person.select.ADD', + -value => 'Add Person →', + -class => 'ADD' + ) . "
"; + if (@{$pe_values} > 0) { $html .= $cgi->submit( - -name => 'person.select.ADD', - -value => 'Add Person →', - -class => 'ADD' - ) . "
"; - if (@{$pe_values} > 0) { - $html .= $cgi->submit( - -name => 'person.select.VIEW', - -value => 'View Person →', - -class => 'VIEW' - ) . "
"; - $html .= $cgi->submit( - -name => 'person.select.EDIT', - -value => "Edit Person →", - -class => "EDIT" - ) . "
"; - $html .= $cgi->submit( - -name => 'person.select.DELETE', - -value => '← Delete Person', - -class => 'DELETE' - ) . "
"; - } - $html << q{select-buttons}; + -name => 'person.select.VIEW', + -value => 'View Person →', + -class => 'VIEW' + ) . "
"; + $html .= $cgi->submit( + -name => 'person.select.EDIT', + -value => "Edit Person →", + -class => "EDIT" + ) . "
"; + $html .= $cgi->submit( + -name => 'person.select.DELETE', + -value => '← Delete Person', + -class => 'DELETE' + ) . "
"; + } + $html << q{select-buttons}; + + # undivert from select area + $html << q{area1}; + + ## _____________________________________________________________________ + ## + ## generate area: Person Detail + ## _____________________________________________________________________ + ## - $html << q{area1}; + # generate CSS class + $html >> q{area2}; + $html .= "\n"; + $html .= " "; $html *= q{detail}; + $html .= "\n"; + $html >> q{detail}; + + # generate inner header + my $action = $ui->{person}->{detail}->{-with}; + $html .= "

".uc(substr($action,0,1)).substr($action,1)." Person

\n"; + $html .= "\n"; + $html .= " "; $html *= q{detail-sub}; + $html .= "\n"; + $html >> q{detail-sub}; + + # generate inner canvas + $html .= "\n"; + $html .= " "; $html *= q{detail-standard}; + $html .= " "; $html *= q{detail-membership}; + $html .= " "; $html *= q{detail-buttons}; + $html .= "
\n"; + + # fetch person details + my $pe = undef; + if ($action eq 'view' or $action eq 'edit') { + my $id = $ui->{person}->{select}->{id}; + if ($id eq '') { + die "no person selected"; + } + $pe = $db->selectrow_hashref(sprintf( + "SELECT pe_id AS id, pe_name AS name, pe_email AS email, pe_phone AS phone" . + " FROM sdb_person WHERE pe_id = %s;", + &sql_escape($id) + )); + if (not defined($pe)) { + die "person with id \"$id\" not found"; + } } else { - $html >> q{area1}; - $html << q{area1}; + $pe = { id => '', name => '', email => '', phone => '' }; } - # generate area: BEGIN PERSON DETAIL BOX - if ($ui->{person}->{detail}->{-is} eq 'visible') { - $html .= ""; - # determine content variant - my $action = $ui->{person}->{detail}->{-with}; - $html .= "

".uc(substr($action,0,1)).substr($action,1)." Person

"; - $html .= ""; - - # fetch person details - my $pe = undef; - if ($action eq 'view' or $action eq 'edit') { - my $id = $ui->{person}->{select}->{id}; - if ($id eq '') { - die "no person selected"; - } - $pe = $db->selectrow_hashref(sprintf( - "SELECT pe_id AS id, pe_name AS name, pe_email AS email, pe_phone AS phone" . - " FROM sdb_person WHERE pe_id = %s;", - &sql_escape($id) - )); - if (not defined($pe)) { - die "person with id \"$id\" not found"; - } + # display person details (standard) + $html >> q{detail-standard}; + my $label = { + 'name' => 'Person Name', + 'email' => 'Email Address', + 'phone' => 'Phone Number' + }; + my $i = 0; + foreach my $a (qw(name email phone)) { + $html .= "\n"; + $html .= " \n"; + $html .= " ".$label->{$a}.":"; + $html .= " \n"; + $html .= " \n"; + if ($action eq 'view') { + $html .= $pe->{$a}; } else { - $pe = { id => '', name => '', email => '', phone => '' }; - } - - # display person details - $html .= "\n"; - my $label = { - 'name' => 'Person Name', - 'email' => 'Email Address', - 'phone' => 'Phone Number' - }; - my $i = 0; - foreach my $a (qw(name email phone)) { - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $i = ($i + 1) % 2; - } - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - $html .= " \n"; - - $html .= " \n"; - $html .= " \n"; - $html .= " "; - $html .= " "; - $html .= "
\n"; - $html .= " ".$label->{$a}.":"; - $html .= " \n"; - if ($action eq 'view') { - $html .= $pe->{$a}; - } - else { + if ($ui->{person}->{detail}->{-is} eq 'visible') { $html .= $cgi->textfield( -override => 1, -name => "person.detail.$a", @@ -764,198 +791,142 @@ -maxlength => 80 ); } - $html .= "
Team Membership:\n"; - $html .= " \n"; - if ($action eq 'view') { - my $te_all = $db->selectcol_arrayref(sprintf( - "SELECT te_name FROM sdb_team,sdb_member" . - " WHERE te_id = ms_te_id AND ms_pe_id = %s" . - " ORDER BY te_name;", - &sql_escape($pe->{id}) - )); - if (@{$te_all} == 0) { - $html .= "-none-"; - } - else { - for (my $i = 0; $i < @{$te_all}; $i++) { - my $te_name = $te_all->[$i]; - $html .= ", " if ($i != 0); - $html .= $te_name; - } - } - } - else { - my $te_values = []; - my $te_labels = {}; - my $te_all = $db->selectall_arrayref( - "SELECT te_id, te_name FROM sdb_team ORDER BY te_name;" - ); - foreach my $r (@{$te_all}) { - push(@{$te_values}, $r->[0]); - $te_labels->{$r->[0]} = $r->[1]; - } - my $te_defaults = []; - if ($action eq 'edit') { - $te_defaults = $db->selectcol_arrayref(sprintf( - "SELECT ms_te_id FROM sdb_member WHERE ms_pe_id = %s;", - &sql_escape($pe->{id}) - )); - }; - if (@{$te_values} == 0) { - $html .= "-none-"; - } else { - $html .= $cgi->scrolling_list( - -override => 1, - -name => 'person.detail.membership+', - -values => $te_values, - -labels => $te_labels, - -default => $te_defaults, - -multiple => 'true', - -size => 10, - -class => 'membership', + $html .= $cgi->hidden( + -name => "person.detail.$a", + -default => $pe->{$a} ); } } - $html .= "
\n"; - - $html .= ""; - if ($action eq 'view') { - $html .= ""; - $html .= ""; - } - else { - $html .= ""; - $html .= ""; - $html .= ""; - } - $html .= "
" . $cgi->submit( - -name => 'person.detail.CLOSE', - -value => '← Close', - -class => 'CLOSE' - ) . "" . $cgi->submit( - -name => 'person.detail.SKILL-VIEW', - -value => 'View Skills ↓', - -class => 'SKILL-VIEW' - ) . "" . $cgi->submit( - -name => 'person.detail.CANCEL', - -value => '← Cancel', - -class => 'CANCEL' - ) . "" . $cgi->submit( - -name => 'person.detail.SAVE', - -value => '↑ Save', - -class => 'SAVE' - ) . "" . $cgi->submit( - -name => 'person.detail.SKILL-EDIT', - -value => 'Edit Skills ↓', - -class => 'SKILL-EDIT' - ) . "
"; - - $html .= "
\n"; - $html .= "
"; - $html .= "
"; - } - # END PERSON DETAIL BOX - - if ($edit eq 'rate' or $do eq 'view-skill') { - if ($edit eq 'rate') { - $html .= "

Edit Skills

"; + $html .= " \n"; + $html .= "\n"; + $i = ($i + 1) % 2; + } + $html << q{detail-standard}; + + # display person details (membership) + $html >> q{detail-membership}; + $html .= "\n"; + $html .= " \n"; + $html .= " Team Membership:\n"; + $html .= " \n"; + $html .= " \n"; + $html .= " "; $html *= q{detail-membership-sub}; + $html .= " \n"; + $html .= "\n"; + $html >> q{detail-membership-sub}; + if ($action eq 'view') { + my $te_all = $db->selectcol_arrayref(sprintf( + "SELECT te_name FROM sdb_team,sdb_member" . + " WHERE te_id = ms_te_id AND ms_pe_id = %s" . + " ORDER BY te_name;", + &sql_escape($pe->{id}) + )); + if (@{$te_all} == 0) { + $html .= "-none-"; } else { - $html .= "

View Skills

"; - } - - my $pe_id = $cgi->param('person.id'); - if ($pe_id eq '') { - die "no person selected"; + for (my $i = 0; $i < @{$te_all}; $i++) { + my $te_name = $te_all->[$i]; + $html .= ", " if ($i != 0); + $html .= $te_name; + } } - my $rv = $db->selectall_arrayref( - "SELECT sk_id,sk_name" . - " FROM sdb_skill " . - " ORDER BY sk_name;" - ); - my $deg = $db->selectall_hashref( - "SELECT sk_id,as_degree" . - " FROM sdb_skill,sdb_provide" . - " WHERE as_pe_id = '$pe_id' AND as_sk_id = sk_id;", - 'sk_id' + } + else { + my $te_values = []; + my $te_labels = {}; + my $te_all = $db->selectall_arrayref( + "SELECT te_id, te_name FROM sdb_team ORDER BY te_name;" ); - - $html .= "\n"; - $html .= ""; - $html .= ""; - $html .= "\n"; - $html .= "
"; - - $html .= "\n"; - my $i = 0; - my $n = 0; - my $med = sprintf("%d", ($#{$rv}+1)/2); - $html .= $cgi->hidden(-name => 'rate.pe_id', -default => $pe_id); - foreach my $sk (@{$rv}) { - if ($n == $med) { - $html .= "
"; - $html .= "
"; - $html .= "  "; - $html .= ""; - $html .= "\n"; - } - $html .= "\n"; - $html .= "\n"; - $html .= "\n"; - $html .= "\n"; - $i = ($i + 1) % 2; - $n++; - } - $html .= "\n"; - $html .= "
\n"; - $html .= $sk->[1]."  "; - $html .= "\n"; - my $default = $deg->{$sk->[0]}->{as_degree} || 0; - my $labels = { 0 => 'unknown', 1 => 'beginner', 2 => 'intermediate', 3 => 'advanced', 4 => 'expert' }; - if ($do eq 'view-skill') { - $html .= $labels->{$default}; - } - else { - $html .= $cgi->scrolling_list( - -name => "rate.$sk->[0]", - -values => [ 0, 1, 2, 3, 4 ], - -labels => $labels, - -default => $default, - -size => 1, - -class => "sdb-input-rate-$i", - -style => 'width: 100%;', - ); - } - $html .= "
\n"; - $html .= ""; - if ($do eq 'view-skill') { - $html .= ""; + foreach my $r (@{$te_all}) { + push(@{$te_values}, $r->[0]); + $te_labels->{$r->[0]} = $r->[1]; + } + my $te_defaults = []; + if ($action eq 'edit') { + $te_defaults = $db->selectcol_arrayref(sprintf( + "SELECT ms_te_id FROM sdb_member WHERE ms_pe_id = %s;", + &sql_escape($pe->{id}) + )); + }; + if (@{$te_values} == 0) { + $html .= "-none-"; } else { - $html .= ""; - $html .= ""; + $html .= $cgi->scrolling_list( + -override => 1, + -name => 'person.detail.membership+', + -values => $te_values, + -labels => $te_labels, + -default => $te_defaults, + -multiple => 'true', + -size => 10, + -class => 'membership', + ); } - $html .= "
".$cgi->submit(-name => 'do.close-skill', -value => "Close", -class => "sdb-button-view")."".$cgi->submit(-name => 'rate.save', -value => "Save", -class => "sdb-button-save")."".$cgi->submit(-name => 'rate.cancel', -value => "Cancel", -class => "sdb-button-cancel")."
"; - $html .= "
\n"; - - $html .= "
\n"; + } + $html << q{detail-membership}; + # generate attached buttons + $html >> q{detail-buttons}; + $html .= "\n"; + $html .= " \n"; + $html .= "  "; + $html .= " \n"; + $html .= " \n"; + $html .= " "; $html *= q{detail-buttons-sub1}; + $html .= " \n"; + $html .= "\n"; + $html >> q{detail-buttons-sub1}; + $html .= "\n"; + $html .= " \n"; + $html .= " "; $html *= q{detail-buttons-sub2}; + $html .= " \n"; + $html .= "
\n"; + $html >> q{detail-buttons-sub2}; + if ($action eq 'view') { + $html .= "" . $cgi->submit( + -name => 'person.detail.CLOSE', + -value => '← Close', + -class => 'CLOSE' + ) . ""; + $html .= "" . $cgi->submit( + -name => 'person.detail.SKILL-VIEW', + -value => 'View Skills ↓', + -class => 'SKILL-VIEW' + ) . ""; } + else { + $html .= "" . $cgi->submit( + -name => 'person.detail.CANCEL', + -value => '← Cancel', + -class => 'CANCEL' + ) . ""; + $html .= "" . $cgi->submit( + -name => 'person.detail.SAVE', + -value => '↑ Save', + -class => 'SAVE' + ) . ""; + $html .= "" . $cgi->submit( + -name => 'person.detail.SKILL-EDIT', + -value => 'Edit Skills ↓', + -class => 'SKILL-EDIT' + ) . ""; + } + $html << q{detail-buttons}; + + # undivert from detail area + $html << q{area2}; + ## _____________________________________________________________________ + ## + ## generate area: Person Rating + ## _____________________________________________________________________ + ## + + # return unfolded HTML $html->undivert(0); return $html->string(); } +