--- capa/capa51/GUITools/gradesubjective.tcl 1999/11/05 19:32:17 1.3 +++ capa/capa51/GUITools/gradesubjective.tcl 1999/11/18 17:55:24 1.4 @@ -52,7 +52,7 @@ proc createGradeSubjWindow {} { set gSubj(responseList) [listbox $msglist.list -width 40 -height 5 \ -yscrollcommand "$msglist.scroll set"] - scrollbar $msglist.scroll -command "$msglist.text yview" + scrollbar $msglist.scroll -command "$msglist.list yview" pack $gSubj(responseList) $msglist.scroll -side left pack configure $msglist.scroll -fill y @@ -214,6 +214,8 @@ proc subjRestore {} { set gSubj(seconds) [expr {[clock seconds] - $gSubj(sec)}] cd $gSubj(dir) incr gSubj(current) -1 + if { $gSubj(redoalllists) } { subjInitAllLists; set gSubj(redoalllists) 0 } + subjIndexResponse subjNext } @@ -222,7 +224,7 @@ proc subjSave {} { set file [file join $gSubj(dir) records set$gSubj(set) \ problem$gSubj(quest) gradingstatus] set fileId [open $file w] - puts $fileId "array set gSubj \"[array get gSubj]\"" + puts $fileId "array set gSubj \{[array get gSubj]\}" close $fileId } @@ -233,25 +235,39 @@ proc subjDone {} { destroy .gradesubjective } +proc subjInitAllLists {} { + global gSubj + puts "doing all lists" + set i 0 + catch {unset gSubj(allstunum)} + catch {unset gSubj(allname)} + catch {unset gSubj(allemail)} + set fileId [open classl r] + while { 1 } { + incr i + set aline [gets $fileId] + if { [eof $fileId]} {break} + lappend gSubj(allstunum) [string toupper [string range $aline 14 22]] + #lappend gSubj(allname) [string toupper [string range $aline 24 59]] + lappend gSubj(allname) [string range $aline 24 59] + lappend gSubj(allemail) [string range $aline 60 99] + } + puts "did $i lines" +} + proc subjInit {} { global gSubj set dir [file join $gSubj(dir) records set$gSubj(set) problem$gSubj(quest)] cd $dir + set gSubj(redoalllists) 0 if { [file exists gradingstatus] } { subjRestore } else { set gSubj(stunums) [lsort -dictionary [glob *]] cd $gSubj(dir) set gSubj(current) -1 set gSubj(totalsec) 0 set gSubj(seconds) [clock seconds] - set fileId [open classl r] - while { 1 } { - set aline [gets $fileId] - if { [eof $fileId]} {break} - lappend gSubj(allstunum) [string toupper [string range $aline 14 22]] -# lappend gSubj(allname) [string toupper [string range $aline 24 59]] - lappend gSubj(allname) [string range $aline 24 59] - } + subjInitAllLists set gSubj(togo) [llength $gSubj(stunums)] subjNext } @@ -678,6 +694,36 @@ proc subjGetOneStudent { window path idV ########################################################### proc subjSendResponse {} { global gSubj + + if { "" == [set which [$gSubj(responseList) curselection]]} { + displayMessage "Please select a message to send." + return + } + incr which + + set stuList [$gSubj(idlist) get 0 end] + foreach stu $stuList { + set stu [lindex $stu 0] + set index [lsearch $gSubj(allstunum) $stu] + set name [lindex $gSubj(allname) $index] + set email [lindex $gSubj(allemail) $index] + puts "$name:[split $name ,]:[lindex [split $name ,] 1]:[lindex [lindex [split $name ,] 1] 0]:$index:$stu" + puts [lsearch $gSubj(allemail) albertel@pilot.msu.edu] + set first_name [lindex [lindex [split $name ,] 1] 0] + set last_name [lindex [split $name , ] 0] + set score $gSubj(score) + regsub -all -- \\\$last_name $gSubj(response.$which) $last_name message + regsub -all -- \\\$first_name $message $first_name message + regsub -all -- \\\$score $message $score message +# set message [subst -nobackslashes -nocommands $gSubj(response.$which)] + if { [regexp -- (^Subject:\[^\n\]*)(\n)(.*) $message matchvar subjline newline messagebody] } { + set message "$subjline Class [file tail $gSubj(dir)], Set $gSubj(set), Question $gSubj(quest) \n$messagebody" + } else { + set message "Subject: Class [file tail $gSubj(dir)], Set $gSubj(set), Question $gSubj(quest) \n$message" + } + displayMessage "$message sent to $email" + exec echo $message | mail $email + } } ########################################################### @@ -692,8 +738,8 @@ proc subjIndexResponse {} { set i 0 foreach element [lsort -dictionary [array names gSubj "response.*"]] { - regsub -all -- "\n\r\t" [string range $gSubj($element) 0 30] " " head - $gSubj(responseList) insert end "[incr i]. $head" + regsub -all -- "\[\n\r\t\]+" [string range $gSubj($element) 0 37] " " head + $gSubj(responseList) insert end "[incr i].$head" } } @@ -706,9 +752,11 @@ proc subjSaveResponse {} { global gSubj set num [incr gSubj(numresponse)] - set gSubj(response.$num) [$gSubj(responseEdit) get 0.0 end] - destroy [winfo toplevel $gSubj(responseEdit)] + set gSubj(response.$num) [$gSubj(responseNew) get 0.0 end-1c] + destroy [winfo toplevel $gSubj(responseNew)] subjIndexResponse + $gSubj(responseList) selection set end + $gSubj(responseList) see end } ########################################################### @@ -731,7 +779,7 @@ proc subjNewResponse {} { set buttonFrame [frame $response.button] pack $textFrame $buttonFrame - set gSubj(responseEdit) [text $textFrame.text -yscrollcommand \ + set gSubj(responseNew) [text $textFrame.text -yscrollcommand \ "$textFrame.scroll set" -wrap char -height 15] scrollbar $textFrame.scroll -command "$textFrame.text yview" pack $textFrame.text $textFrame.scroll -side left -expand 1 @@ -749,6 +797,24 @@ proc subjNewResponse {} { ########################################################### proc subjDeleteResponse {} { global gSubj + if { [winfo exists .editresponse] } { + displayMessage "Please finish with editing the response, before deleting responses." + return + } + if { "" == [set which [$gSubj(responseList) curselection]]} { return } + incr which + if { [catch {unset gSubj(response.$which)}] } { + puts [array names gSubj response.*] + return + } + for {set i [expr $which + 1]} { [info exists gSubj(response.$i)] } {incr i} { + set j [expr $i - 1] + set gSubj(response.$j) $gSubj(response.$i) + unset gSubj(response.$i) + } + set gSubj(numresponse) [expr $i - 2] + subjIndexResponse + $gSubj(responseList) see [incr which -2] } ########################################################### @@ -757,7 +823,39 @@ proc subjDeleteResponse {} { ########################################################### ########################################################### proc subjEditResponse {} { - global gSubj + global gSubj gWindowMenu + + if { [winfo exists .editresponse] } { capaRaise .editresponse ; return } + if { "" == [set which [$gSubj(responseList) curselection]]} { return } + incr which + + set response [toplevel .editresponse ] + $gWindowMenu add command -label "EditingResponse" -command "capaRaise $response" + wm title $response "Editing a Response" + + set textFrame [frame $response.text] + set buttonFrame [frame $response.button] + pack $textFrame $buttonFrame + + set gSubj(responseEdit) [text $textFrame.text -yscrollcommand \ + "$textFrame.scroll set" -wrap char -height 15] + scrollbar $textFrame.scroll -command "$textFrame.text yview" + pack $textFrame.text $textFrame.scroll -side left -expand 1 + pack configure $textFrame.scroll -fill y + $gSubj(responseEdit) insert 0.0 $gSubj(response.$which) + + set gSubj(editresponsedone) 0 + button $buttonFrame.save -text Save -command "set gSubj(editresponsedone) 1" + button $buttonFrame.forget -text Cancel -command "set gSubj(editresponsedone) 0" + pack $buttonFrame.save $buttonFrame.forget -side left + vwait gSubj(editresponsedone) + if { $gSubj(editresponsedone) } { + set gSubj(response.$which) [$gSubj(responseEdit) get 0.0 end-1c] + subjIndexResponse + $gSubj(responseList) selection set $which + $gSubj(responseList) see $which + } + destroy $response } ########################################################### @@ -766,5 +864,28 @@ proc subjEditResponse {} { ########################################################### ########################################################### proc subjViewResponse {} { - global gSubj + global gSubj gUniqueNumber gWindowMenu + + if { "" == [set which [$gSubj(responseList) curselection]]} { return } + incr which + set num [incr gUniqueNumber] + + set response [toplevel .viewresponse$num ] + $gWindowMenu add command -label "ViewingResponse $which" \ + -command "capaRaise $response" + wm title $response "Viewing Response $which" + + set textFrame [frame $response.text] + set buttonFrame [frame $response.button] + pack $textFrame $buttonFrame + + text $textFrame.text -yscrollcommand "$textFrame.scroll set" -wrap char -height 15 + scrollbar $textFrame.scroll -command "$textFrame.text yview" + pack $textFrame.text $textFrame.scroll -side left -expand 1 + pack configure $textFrame.scroll -fill y + $textFrame.text insert 0.0 $gSubj(response.$which) + $textFrame.text configure -state disabled + + button $buttonFrame.forget -text Dismiss -command "destroy $response" + pack $buttonFrame.forget -side left }