summaryrefslogtreecommitdiff
path: root/GradeBook.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'GradeBook.tcl')
-rwxr-xr-xGradeBook.tcl41
1 files changed, 39 insertions, 2 deletions
diff --git a/GradeBook.tcl b/GradeBook.tcl
index ed845f5..70b7873 100755
--- a/GradeBook.tcl
+++ b/GradeBook.tcl
@@ -118,7 +118,7 @@ proc htmlDBout {db permission_list {sort_col {}}} {
foreach {act act_label} $action_list {
if { [info exist permission($act) ] } {
if { $permission($act) } {
- puts -nonewline "$separator<a href=$script_name?action=$act>$act_label</a>"
+ puts -nonewline "$separator<a href=$script_name?action=$act&columnname=[::ncgi::encode $col]>$act_label</a>"
}
}
}
@@ -252,7 +252,10 @@ proc ChoseAction {action permission_list user} {
htmlDefaultView $permission_list $user
}
addcolumnrequest { AddColumnRequest $permission_list $user }
- deletecolumn { }
+ deletecolumn {
+ DeleteColumn $permission_list $user;
+ htmlDefaultView $permission_list $user
+ }
renamecolumn { }
showcontrols { ShowControls $permission_list $user }
showgrades { htmlGradesTable db $permission_list $user }
@@ -262,6 +265,40 @@ proc ChoseAction {action permission_list user} {
}
}
+proc DeleteColumn { permission_list user } {
+ global script_name
+ set columnname [::ncgi::value columnname {}]
+ if { $columnname != "" } {
+ set eval_str [concat SELECT * FROM GradesTable ]
+ set err [catch {db eval $eval_str v {} } errStat]
+ set old_column_list $v(*)
+ # removing the column name to be deleted from total list
+ set new_column_list {}
+ foreach cname $old_column_list {
+ if { $cname ne $columnname } {
+ lappend new_column_list \"$cname\"
+ }
+ }
+ set sql_new_column_list [join $new_column_list ","]
+ set eval_str "BEGIN TRANSACTION;
+ CREATE TEMPORARY TABLE GradesTable_backup($sql_new_column_list);
+ INSERT INTO GradesTable_backup SELECT $sql_new_column_list FROM GradesTable;
+ DROP TABLE GradesTable;
+ CREATE TABLE GradesTable($sql_new_column_list);
+ INSERT INTO GradesTable SELECT $sql_new_column_list FROM GradesTable_backup;
+ DROP TABLE GradesTable_backup;
+ COMMIT;"
+ set err [catch {db eval $eval_str } errStat]
+ if { $err } {
+ puts "the following error happen: $errStat"
+ dbg "the following error happen: $errStat" 3
+ }
+ } else {
+ puts "error: empty column names are not permitted"
+ }
+}
+
+
proc AddColumn { permission_list user } {
global script_name
set columnname2add [::ncgi::value columnname2add {}]