while (my $row = $sth2->fetchrow_hashref()) {
if ($main::form->{"gender_$i"} eq "f" ) {
- $mchecked = "";
- $fchecked = "checked";
+ $mchecked = "";
+ $fchecked = "checked";
} else {
- $mchecked = "checked";
- $fchecked = "";
+ $mchecked = "checked";
+ $fchecked = "";
};
$gender_table .= "<tr><input type=hidden name=\"cp_id_$i\" value=\"$row->{cp_id}\"> <td>$row->{cp_givenname}</td> <td>$row->{cp_name}</td> <td>$row->{cp_title} </td> <td>$row->{cp_greeting} </td><td> <input type=\"radio\" name=\"gender_$i\" value=\"m\" $mchecked> <input type=\"radio\" name=\"gender_$i\" value=\"f\" $fchecked></td></tr>\n";
print $main::form->parse_html_template("dbupgrade/cp_greeting_update_form");
}
+sub alter_schema_only {
+ my $sqlcode = <<SQL;
+ ALTER TABLE contacts ADD COLUMN cp_gender char(1);
+ ALTER TABLE contacts DROP COLUMN cp_greeting;
+SQL
+
+ $dbh->do($sqlcode);
+}
+
sub do_update {
# main function
+ # Do not ask the user anything if there are no entries in the
+ # contacts table.
+ my ($data_exists) = $dbh->selectrow_array("SELECT * FROM contacts LIMIT 1");
+ if (!$data_exists) {
+ alter_schema_only();
+ return 1;
+ }
+
# first of all check if gender.sql was already run and thus cp_gender exists
# if it exists there is no need for this update anymore, so return
# without doing anything