#!/usr/bin/perl # Copyright 2001-2010 Leslie Richardson # This file is part of Open Admin for Schools. # Open Admin for Schools is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # Metaedit.pl - edit meta table for formtype, default values. my %lex = ('Main' => 'Main', 'Eoy' => 'Eoy', 'Save Changes' => 'Save Changes', 'Edit Metadata' => 'Edit Metadata', 'Field Id' => 'Field Id', 'Field Name' => 'Field Name', 'Defaults' => 'Defaults', 'Form Type' => 'Form Type', 'View Size' => 'View Size', 'Reqd' => 'Reqd', 'Edit Table' => 'Edit Table', 'Your fields have been updated.' => 'Your fields have been updated.', 'Edit more records' => 'Edit more records', 'Please select table to edit.' => 'Please select table to edit.', 'Error' => 'Error', 'Table' => 'Table', 'Include Description' => 'Include Description', 'Description' => 'Description', ); $self = 'metaedit.pl'; $notes = 'The Defaults for Select Form Entry: Separate items with a space (First Second),
Join multiword entries with underscore character (which will be stripped)(First_One Second_One),
Items with leading tilde (~Choose_One~) will be ignored during student entry.
Textarea Boxes: put rows and cols in the viewsize field separated with an x (ie. 6x80)'; use DBI; use CGI; # Read config variables eval require "../../etc/admin.conf"; if ( $@ ) { print $lex{Error}. ": $@
\n"; die $lex{Error}. ": $@\n"; } my $q = new CGI; print $q->header( -charset, $charset ); my %arr = $q->Vars; my $dsn = "DBI:mysql:$dbase"; my $dbh = DBI->connect($dsn,$user,$password); $dbh->{mysql_enable_utf8} = 1; print "$doctype\n". $lex{'Edit Metadata'}. " \n"; print "[ ". $lex{Main}. " |\n"; print " ". $lex{Eoy}. " ]\n"; if ( not $arr{tableid} ) { # load and display table choices. showStartPage(); } if ( $arr{flag} ) { # write the updates updateTable(); } # Select table rows to update my $sth = $dbh->prepare("select id, fieldid, datatype, arrayidx, fieldname, defaultvalue, formtype,viewsize, required, description from meta where tableid = ? order by arrayidx"); $sth->execute( $arr{tableid} ); if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr;} # section header print "

". $lex{'Edit Metadata'}. "

\n"; print "
\n"; print "\n"; print "\n"; print "

", ucfirst($arr{tableid}), q{ }. $lex{Table}. "

\n"; print "\n"; print "\n"; print"\n"; print "\n"; while ( my ( $id, $fieldid, $datatype, $arrayidx, $fieldname, $default, $formtype, $viewsize, $required, $description ) = $sth->fetchrow){ print "\n\n"; print "\n"; my $checked; if ( $required ) { $checked= q{checked="checked"}; } print "\n\n"; if ( $arr{incldesc} ) { print "\n"; } } print "
$notes
". $lex{'Field Id'}. ""; print $lex{'Field Name'}. "". $lex{Defaults}. "". $lex{'Form Type'}; print "". $lex{'View Size'}. "". $lex{'Reqd'}. "
$fieldid [$datatype/$arrayidx]"; print ""; if ( length( $default ) > 45 ) { print "\n"; } else { print "\n"; } print "
". $lex{Description}; print " "; print "
\n"; print "
"; #---------------- sub showStartPage { # show tables, etc. to choose from #---------------- # Get the table choices my $sth = $dbh->prepare("select distinct tableid from meta order by tableid"); $sth->execute; if ($DBI::errstr){ print $DBI::errstr; die $DBI::errstr; } print "

". $lex{'Please select table to edit.'}. "

\n"; print "
\n"; while ( my $tableid = $sth->fetchrow ){ print "
\n"; print " $tableid
"; } print "
\n"; print "
"; print $lex{'Include Description'}; print "
\n
\n"; exit; } #-------------- sub updateTable { # write updates to meta table. #-------------- delete $arr{flag}; # no longer required. delete $arr{tableid}; # not required. foreach my $key ( keys %arr ) { my ( $id, $field ) = split /:/,$key; my $value = $arr{$key}; #print "K: $key ID: $id FIELD: $field VAL: $arr{$key}
\n"; # Update the field $sth = $dbh->prepare("update meta set $field = ? where id = ?"); $sth->execute( $value, $id ); if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; } # Check for Required Field deselected (since nothing sent when done). if ( $field eq 'fieldname' ) { my $testkey = "$id:required"; if ( not $arr{ $testkey } ) { $sth = $dbh->prepare("update meta set required = '' where id = ?"); $sth->execute( $id ); if ( $DBI::errstr ){ print $DBI::errstr; die $DBI::errstr; } } } } print "

". $lex{'Your fields have been updated.'}. "

\n"; print "[ ". $lex{'Edit more records'}. " ]"; print "\n"; exit; } # End of Update Table