summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2010-12-17 01:17:36 -0500
committerEugeniy Mikhailov <evgmik@gmail.com>2010-12-17 01:17:36 -0500
commit9edd0aa5d79512e7f3b00f79aad3da5f91a6ab58 (patch)
tree00b6fe6195b277ce991b8e438fcd4d561215f9ce
parent8a2513e79abd713eac1c1296b585aab173ead7e1 (diff)
downloadGradeBook-9edd0aa5d79512e7f3b00f79aad3da5f91a6ab58.tar.gz
GradeBook-9edd0aa5d79512e7f3b00f79aad3da5f91a6ab58.zip
deletion of the column added
darcs-hash:20101217061736-067c0-840e7635108a0a2af5cd95d9b9bd0ab749ec123c.gz
-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 {}]