diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-01-18 23:40:08 -0500 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2011-01-18 23:40:08 -0500 |
commit | 6526ed8ec7d6ef2f696fbced58aa6e7baa040537 (patch) | |
tree | 8beaf170bf2ce3dc8fd6a1e5923393071b58c70e | |
parent | 7930310d468ca44ff3e7b86820c0dafc5e81d693 (diff) | |
download | GradeBook-6526ed8ec7d6ef2f696fbced58aa6e7baa040537.tar.gz GradeBook-6526ed8ec7d6ef2f696fbced58aa6e7baa040537.zip |
added UpdateColumn procedure
Ignore-this: 4a3e617966e78ac66f8772dbbb7a5d55
darcs-hash:20110119044008-067c0-481f4747cf5ce49d1e044f7a34b541f51336b2d5.gz
-rwxr-xr-x | GradeBook.tcl | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/GradeBook.tcl b/GradeBook.tcl index 69154e6..921da17 100755 --- a/GradeBook.tcl +++ b/GradeBook.tcl @@ -284,7 +284,9 @@ proc ChoseAction {action permission_list user} { } renamecolumn { } changecolumn { ChangeColumn $permission_list $user } - updatecolumn { UpdateColumn $permission_list $user } + updatecolumn { UpdateColumn $permission_list $user + htmlDefaultView $permission_list $user + } showcontrols { ShowControls $permission_list $user } showgrades { htmlGradesTable db $permission_list $user } defaultview { htmlDefaultView $permission_list $user } @@ -359,6 +361,52 @@ proc ChangeColumn { permission_list user } { puts {</div>} } +proc UpdateColumn { permission_list user } { + set oldcolumnname [::ncgi::value oldcolumnname {}] + set newcolumnname [::ncgi::value newcolumnname {}] + set column_category [::ncgi::value category {}] + set maxpointpossible [::ncgi::value maxpointpossible {}] + + # first we update category and maxpointpossible values of the old columnname + set sql_str [concat UPDATE GradesTable SET \"$oldcolumnname\"=\'$column_category\' where UserName=\"_Col_Category_\"] + set err [catch {db eval $sql_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } + set sql_str [concat UPDATE GradesTable SET \"$oldcolumnname\"=\'$maxpointpossible\' where UserName=\"_Max_Points_\"] + set err [catch {db eval $sql_str } errStat] + if { $err } { + htmlErrorMsg $errStat + dbg "the following error happen: $errStat" 3 + } + if { $newcolumnname eq $oldcolumnname } { + # no need to mess with renaming + return + } + if { $newcolumnname == "" } { + htmlErrorMsg "empty column names are not permitted" + return + } + set eval_str [concat SELECT * FROM GradesTable ] + set err [catch {db eval $eval_str v {} } errStat] + set old_column_list $v(*) + # check if column with the suggested new name is already exist + foreach cname $old_column_list { + if { $cname eq $newcolumnname } { + htmlErrorMsg "The column name <b>$newcolumnname</b> is already exist" + return + } + } + # sqlite does not allow rename columns + # I will first create new column identical to the old one + AddColumnNonWeb $newcolumnname $column_category $maxpointpossible + set sql_str [concat UPDATE GradesTable SET \"$newcolumnname\"=\"$oldcolumnname\"] + set err [catch {db eval $sql_str } errStat] + # then delete the old one + DeleteColumnNonWeb $oldcolumnname +} + proc UpdateGrades { permission_list user } { global script_name set subaction [::ncgi::value subaction {}] |