diff options
Diffstat (limited to 'GradeBook.tcl')
-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 {}] |