--- capa/capa51/GUITools/groupemail.tcl 2000/02/22 18:10:27 1.4 +++ capa/capa51/GUITools/groupemail.tcl 2000/03/22 21:08:02 1.5 @@ -52,41 +52,19 @@ proc runGroupEmail { capaConfigFile } { pack $bottom.spacer $bottom.sections -anchor w -side left #student - radiobutton $studentFrame.specific -text "Specify the student by:" \ + radiobutton $studentFrame.specific -text "Students from file:" \ -value "Specific" -variable gCT($num.emailtype) - set studentNumber [frame $studentFrame.studentNumber] - set fullName [frame $studentFrame.fullName] - pack $studentFrame.specific $studentNumber $fullName -side top - pack configure $studentFrame.specific -anchor w - pack configure $studentNumber $fullName -anchor e - - radiobutton $sectionFrame.section - label $studentNumber.msg -text "Student Number: " - entry $studentNumber.entry -textvariable gCT($num.studentNumber) \ - -width 9 -validate key -validatecommand "limitEntry %W 9 any %P" - pack $studentNumber.msg $studentNumber.entry -side left - - label $fullName.msg -text "Student Name: " - entry $fullName.msg2 -textvariable gCT($num.studentName) -width 35 \ - -validate key -validatecommand "limitEntry %W 35 any %P" - pack $fullName.msg $fullName.msg2 -side left - - trace variable gCT($num.studentNumber) w \ - "global gCT; set gCT($num.emailtype) Specific ;#" - trace variable gCT($num.studentName) w \ - "global gCT; set gCT($num.emailtype) Specific ;#" - - bind $studentNumber.entry \ - "fillInStudent gCT($num.studentName) gCT($num.studentNumber) 0" - bind $fullName.msg2 \ - "fillInStudent gCT($num.studentName) gCT($num.studentNumber) 1" + entry $studentFrame.file -textvariable gCT($num.studentlist) + button $studentFrame.select -text "Browse" \ + -command "set gCT($num.studentlist) \[tk_getOpenFile\]" + pack $studentFrame.specific $studentFrame.file $studentFrame.select -side left #script radiobutton $scriptFrame.label -text "Script Selection:" -value "Script" \ -variable gCT($num.emailtype) entry $scriptFrame.file -textvariable gCT($num.emailscript) button $scriptFrame.select -text "Browse" \ - -command "set gCT($num.template) \[tk_getOpenFile\]" + -command "set gCT($num.emailscript) \[tk_getOpenFile\]" pack $scriptFrame.label $scriptFrame.file $scriptFrame.select -side left button $buttonFrame.send -text "Send" -command "emailSend $num" @@ -96,6 +74,12 @@ proc runGroupEmail { capaConfigFile } { Centre_Dialog $emailwin default } +proc emailClose { num } { + global gFile + destroy .email$num + removeWindowEntry "Sending Email $gFile($num)" +} + proc emailSelectSections { num } { global gCT gFile set pwd [pwd]; cd $gFile($num) @@ -127,8 +111,9 @@ proc emailSend { num } { foreach student $gCT($num.studentlist) { incr i # foreach {email firstname lastname stunum} $student {break} - set message [emailMessage $num $student] - emailSendMessage $num $student $message + set subject "" + set message [emailMessage $num $student subject] + emailSendMessage $num $student $message $subject updateStatusBar [expr $i/double($max)] $num } removeStatus $num @@ -140,7 +125,7 @@ proc emailConfirm { num } { switch $gCT($num.emailtype) { Class { append msg " the whole class." } Sections { append msg " the sections $gCT($num.emailsections)." } - Specific { append msg " to the students $gCT($num.emailstudents)." } + Specific { append msg " to the student numbers in $gCT($num.studentlist)." } Script { append msg " to the students generated by the script $gCT($num.emailscript)." } @@ -158,7 +143,7 @@ proc emailGetStudents { num } { switch $gCT($num.emailtype) { Class { emailGetClass $num } Sections { emailGetSections $num } - Specific { } + Specific { emailGetSpecific $num } Script { } } } @@ -199,8 +184,34 @@ proc emailGetSections { num } { } } -proc emailMessage { num student } { +proc emailGetSpecific { num } { + global gCT gFile + + set fileId [open $gCT($num.studentlist)] + set temp [split [read $fileId] "\n"] + set allids "" + foreach element $temp { if { $element != "" } { lappend allids $element } } + close $fileId + puts $allids + set classlid [open [file join $gFile($num) classl] r] + set aline [gets $classlid] + while { ![eof $classlid] } { + set stunum [string trim [string range $aline 14 22]] + if { [lsearch $allids $stunum] !=-1 } { + set section [string trimleft [string trim [string range $aline 10 12]] "0"] + set email [string trim [string range $aline 60 99]] + set firstname [string trim [lindex [lindex [split [string range $aline 24 59] ","] 1] 0]] + set lastname [string trim [lindex [split [string range $aline 24 59] ","] 0]] + set section [string trimleft [string trim [string range $aline 10 12] ] 0] + lappend gCT($num.studentlist) [list $email $firstname $lastname $stunum $section] + } + set aline [gets $classlid] + } +} + +proc emailMessage { num student subjectVar } { global gCT gFile gCapaConfig + upvar $subjectVar subject set message $gCT($num.message) regsub -all -- \\\$email $message [lindex $student 0] message @@ -296,8 +307,8 @@ proc emailMessage { num student } { set examt [getTotals $i $stunum $section $gCapaConfig($num.exam_path)] set corrs [getScores $i $stunum $section $gCapaConfig($num.exam_path)] set corrt [getTotals $i $stunum $section $gCapaConfig($num.exam_path)] - set exam [expr $exams/double($examt)] - set corr [expr $corrs/double($corrt)] + if { [catch {set exam [expr $exams/double($examt)]}] } { set exam 0 } + if { [catch {set corr [expr $corrs/double($corrt)]}] } { set corr 0 } if { $corr > $exam } { set totalexam [expr $totalexam + \ [expr $exam + $gCapaConfig($num.correction_weight) \ @@ -306,12 +317,12 @@ proc emailMessage { num student } { set totalexam [expr $totalexam + $exam] } } - set totalexam [expr $totalexam / ($i-1)] + if { [catch {set totalexam [expr $totalexam / ($i-1)]}] } { set totalexam 0 } set finals [getScores $finalset $stunum $section $gCapaConfig($num.exam_path)] set finalt [getTotals $finalset $stunum $section $gCapaConfig($num.exam_path)] - set final [expr $finals/double($finalt)] - set homework [expr $all(homework.score)/double($all(homework.total))] - set quiz [expr $all(quiz.score)/double($all(quiz.total))] + if { [catch {set final [expr $finals/double($finalt)]}]} {set final 0} + if { [catch {set homework [expr $all(homework.score)/double($all(homework.total))]}] } { set homework 0 } + if { [catch {set quiz [expr $all(quiz.score)/double($all(quiz.total))]}] } { set quiz 0 } set grade [expr $gCapaConfig($num.homework_weight)*$homework +\ $gCapaConfig($num.quiz_weight)*$quiz +\ $gCapaConfig($num.exam_weight)*$totalexam +\ @@ -319,11 +330,13 @@ proc emailMessage { num student } { set grade [format "%2.1f" [expr $grade * 100 ]] regsub -all -- \\\$grade $message $grade message } + regexp "^Subject:(\[^\n]*)" $message garbage subject + regsub "^Subject:(\[^\n]*)" $message {} message return $message } -proc emailSendMessage { num student message } { +proc emailSendMessage { num student message subject } { global gCT gCapaConfig - exec echo $message | $gCapaConfig($num.mail_command) [lindex $student 0] + exec echo $message | $gCapaConfig($num.mail_command) -s $subject [lindex $student 0] }