Diff for /capa/capa51/GUITools/groupemail.tcl between versions 1.3 and 1.4

version 1.3, 2000/02/08 22:40:33 version 1.4, 2000/02/22 18:10:27
Line 1 Line 1
   #Copyright 2000 by Guy Albertelli
 proc runGroupEmail { capaConfigFile } {  proc runGroupEmail { capaConfigFile } {
     global gUniqueNumber gFile gWindowMenu gCT      global gUniqueNumber gFile gWindowMenu gCT
     set num [incr gUniqueNumber]      set num [incr gUniqueNumber]
Line 8  proc runGroupEmail { capaConfigFile } { Line 9  proc runGroupEmail { capaConfigFile } {
     set emailwin [toplevel .email$num]      set emailwin [toplevel .email$num]
     $gWindowMenu add command -label "Sending Email $gFile($num)" \      $gWindowMenu add command -label "Sending Email $gFile($num)" \
  -command "capaRaise \"$emailwin\""   -command "capaRaise \"$emailwin\""
     wm title $scorerWin $classDir      wm title $emailwin [file dirname $capaConfigFile]
           
     set fileFrame [frame $emailwin.file]      set fileFrame [frame $emailwin.file]
     set sentFrame [frame $emailwin.sent]      set sentFrame [frame $emailwin.sent]
     set buttonFrame [frame $emailwin.button]      set buttonFrame [frame $emailwin.button]
     pack $fileFrame $sentFrame $buttonFrame -side top      pack $fileFrame $sentFrame $buttonFrame -side top -anchor w
   
     label $fileFrame.label -text "Mail Template:"      label $fileFrame.label -text "Mail Template:"
     entry $fileFrame.file -textvariable gCT($num.template)      entry $fileFrame.file -textvariable gCT($num.template)
     button $fileFrame.select -text "Browse" \      button $fileFrame.select -text "Browse" \
  -command "set gCT($num.template) [tk_fileOpen]"   -command "set gCT($num.template) \[tk_getOpenFile\]"
     pack $fileFrame.label $fileFrame.file $fileFrame.select -side left      pack $fileFrame.label $fileFrame.file $fileFrame.select -side left
           
     label $sentFrame.text -text "Send To:"      label $sentFrame.text -text "Send To:"
     set classFrame [frame $sentFrame.class]      set classFrame [frame $sentFrame.class]
     set sectionFrame [frame $sentFrame.section]      set sectionFrame [frame $sentFrame.section]
     set studentFrame [frame $sentFrame.student]      set studentFrame [frame $sentFrame.student]
       #unpacked
     set scriptFrame [frame $sentFrame.script]      set scriptFrame [frame $sentFrame.script]
     pack $sentFrame.text $classFrame $sectionFrame $studentFrame $scriptFrame -side top      pack $sentFrame.text $classFrame $sectionFrame $studentFrame -side top -anchor w
           
     #class      #class
     radiobutton $classFrame.class -text "Whole Class" \      radiobutton $classFrame.class -text "Whole Class" \
Line 34  proc runGroupEmail { capaConfigFile } { Line 36  proc runGroupEmail { capaConfigFile } {
     pack $classFrame.class      pack $classFrame.class
   
     #sections      #sections
     radiobutton $sectionFrame.button -text "Sections" \      set gCT($num.emailsections) "None"
       set top [frame $sectionFrame.top]
       set bottom [frame $sectionFrame.bottom]
       pack $top $bottom -side top -anchor w
   
       radiobutton $top.button -text "Sections" \
  -variable gCT($num.emailtype) -value "Sections"   -variable gCT($num.emailtype) -value "Sections"
     message $sectionFrame.sections -textvariable gCt($num.sections)      button $top.select -text "Select Section" -command "emailSelectSections $num"
     button $sectionFrame.select -text "Select Section" -command emailSelectSections      message $bottom.sections -textvariable gCT($num.emailsections) \
     pack $sectionFrame.button $sectionFrame.sections $sectionFrame.select -side top   -relief groove -width 350
       frame $bottom.spacer -width 20
   
       pack $top.button $top.select -side left -anchor w
       pack $bottom.spacer $bottom.sections -anchor w -side left
       
     #student      #student
     radiobutton $studentFrame.specific -text "Specify the student by:" \      radiobutton $studentFrame.specific -text "Specify the student by:" \
     -value "Specific" -variable gCT($num.emailtype)      -value "Specific" -variable gCT($num.emailtype)
Line 71  proc runGroupEmail { capaConfigFile } { Line 82  proc runGroupEmail { capaConfigFile } {
  "fillInStudent gCT($num.studentName) gCT($num.studentNumber) 1"   "fillInStudent gCT($num.studentName) gCT($num.studentNumber) 1"
   
     #script      #script
     label $scriptFrame.label -text "Script Selection:"      radiobutton $scriptFrame.label -text "Script Selection:" -value "Script" \
     entry $scriptFrame.file -textvariable gCT($num.template)   -variable gCT($num.emailtype)
       entry $scriptFrame.file -textvariable gCT($num.emailscript)
     button $scriptFrame.select -text "Browse" \      button $scriptFrame.select -text "Browse" \
  -command "set gCT($num.template) [tk_fileOpen]"   -command "set gCT($num.template) \[tk_getOpenFile\]"
     pack $scriptFrame.label $scriptFrame.file $scriptFrame.select -side left      pack $scriptFrame.label $scriptFrame.file $scriptFrame.select -side left
   
     button $buttonFrame.send -text "Send" -command "emailSend $num"      button $buttonFrame.send -text "Send" -command "emailSend $num"
     button $buttonFrame.cancel -text "Cancel" -command "emailClose $num"      frame $buttonFrame.spacer -width 100
     pack $buttonFrame.send $buttonFrame.cancel -side top      button $buttonFrame.cancel -text "Close" -command "emailClose $num"
       pack $buttonFrame.send $buttonFrame.spacer $buttonFrame.cancel -side left
       Centre_Dialog $emailwin default
   }
   
   proc emailSelectSections { num } {
       global gCT gFile
       set pwd [pwd]; cd $gFile($num)
       set gCT($num.emailsections) [string trim [pickSections [getExistingSections] "Select Sections to send an email to:"]]
       cd $pwd
       if { $gCT($num.emailsections) != "" } { 
    set gCT($num.emailtype) Sections 
       } else {
    set gCT($num.emailsections) "None"
       }
 }  }
   
 proc emailSend { num } {  proc emailSend { num } {
     global gCT gFile      global gCT gFile
   
       if { [catch {set fileId [open $gCT($num.template) r]}]} {
    displayMessage "Unable to open $gCT($num.template)"
    return
       }
       set gCT($num.message) [read $fileId [file size $gCT($num.template)]]
       close $fileId
   
     if { "Cancel" == [emailConfirm $num]} { return }      if { "Cancel" == [emailConfirm $num]} { return }
     emailGetStudents $num      emailGetStudents $num
   
     foreach student gCT($num.studentlist) {      set max [llength $gCT($num.studentlist)]
       set i 0
       displayStatus "Sending Messages" both $num
       foreach student $gCT($num.studentlist) {
    incr i
 # foreach {email firstname lastname stunum} $student {break}  # foreach {email firstname lastname stunum} $student {break}
  set message [emailMessage $student]   set message [emailMessage $num $student]
  emailSendMessage $student $message   emailSendMessage $num $student $message
    updateStatusBar [expr $i/double($max)] $num
     }      }
       removeStatus $num
   }
   
   proc emailConfirm { num } {
       global gCT
       set msg "The message in $gCT($num.template) will be sent to"
       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)." }
    Script { 
       append msg " to the students generated by the script $gCT($num.emailscript)."
    }
       }
       append msg "\n\n Continue?"
       if { "Yes" == [makeSure $msg]} {
    return "Yes"
       } 
       return "Cancel"
 }  }
   
 proc emailGetStudents { num } {  proc emailGetStudents { num } {
     global gCT gFile      global gCT gFile
       
     switch gCT($num.emailtype) {      switch $gCT($num.emailtype) {
  Class { emailGetClass $num }   Class { emailGetClass $num }
  Sections { }    Sections { emailGetSections $num }
  Specific { }   Specific { }
  Script { }   Script { }
     }      }
Line 109  proc emailGetStudents { num } { Line 166  proc emailGetStudents { num } {
 proc emailGetClass { num } {  proc emailGetClass { num } {
     global gCT gFile      global gCT gFile
     set classlid [open [file join $gFile($num) classl] r]      set classlid [open [file join $gFile($num) classl] r]
   
     set aline [gets $classlid]      set aline [gets $classlid]
     while { ![eof $classlid] } {      while { ![eof $classlid] } {
  set email [string trim [string range $aline 60 99]]   set email [string trim [string range $aline 60 99]]
Line 118  proc emailGetClass { num } { Line 176  proc emailGetClass { num } {
  lappend gCT($num.studentlist) [list $email $firstname $lastname $stunum]   lappend gCT($num.studentlist) [list $email $firstname $lastname $stunum]
  set aline [gets $classlid]   set aline [gets $classlid]
     }      }
 }  
   
   }
   
   proc emailGetSections { num } {
       global gCT  gFile
       set classlid [open [file join $gFile($num) classl] r]
   
       set aline [gets $classlid]
       while { ![eof $classlid] } {
    set section [string trimleft [string trim [string range $aline 10 12]] "0"]
    if { [lsearch $gCT($num.emailsections) $section] == -1 } {
       set aline [gets $classlid]
       continue
    }
    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 stunum [string trim [string range $aline 14 22]]
    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 } {
       global gCT gFile gCapaConfig
       set message $gCT($num.message)
   
       regsub -all -- \\\$email $message [lindex $student 0] message
       regsub -all -- \\\$first_name $message [lindex $student 1] message
       regsub -all -- \\\$last_name $message [lindex $student 2] message
       regsub -all -- \\\$student_number $message [lindex $student 3] message
       set stunum [lindex $student 3]
       set section [lindex $student 4]
       while { [regexp {\$capaid\(([0-9all\.,]*)\)} $message match set] } {
    set capaid [getCapaID $set $stunum $section $gFile($num)]
    regsub -all -- \\\$capaid\\\($set\\\) $message $capaid message
       }
       while { [regexp {\$homework_score\(([0-9all\.,]*)\)} $message match set] } {
    if { [catch {set setmax [set max $gCapaConfig($num.homework_count)]}]} { 
       set max 99;set setmax 99
    }
    set scores [getScores $set $stunum $section $gFile($num) $max setmax]
    regsub -all -- \\\$homework_score\\\($set\\\) $message $scores message
    if { $set == "all" } { 
       set all(homework.score) $scores
       set all(setmax.homework.score) $setmax
    }
       }
       while { [regexp {\$homework_total\(([0-9all\.,]*)\)} $message match set] } {
    if { [catch {set setmax [set max $gCapaConfig($num.homework_count)]}]} { 
       set max 99;set setmax 99
    }
    set scores [getTotals $set $stunum $section $gFile($num) $max setmax]
    regsub -all -- \\\$homework_total\\\($set\\\) $message $scores message
    if { $set == "all" } { 
       set all(homework.total) $scores 
       set all(setmax.homework.total) $setmax
    }
       }
       foreach {path limit} {quiz quiz_count supp none others none correction \
         final_exam_set_number exam final_exam_set_number} {
    if {[catch {set gCapaConfig($num.[set path]_path)}]} {
       continue
    } else {
       if { ![file exists $gCapaConfig($num.[set path]_path)] } { continue }
    }
    if { [catch {set setmax [set max $gCapaConfig($num.$limit)]}]} { 
       set max 99 ; set setmax 99
    }
    foreach {type call} {score getScores total getTotals} {
       set exp {\$};append exp $path;append exp _$type
       append exp {\(([0-9all\.,]*)\)}
       while { [regexp $exp $message match set]} {
    set scores [$call $set $stunum $section \
    $gCapaConfig($num.[set path]_path) $max setmax]
    set replacexp {\$};append replacexp $path;append replacexp _$type
    append replacexp {\(};append replacexp $set;append replacexp {\)}
    regsub -all -- $replacexp $message $scores message
    if { $set == "all" } { 
       set all($path.$type) $scores 
       set all(setmax.$path.$type) $setmax
    }
       }
    }
       }
       if { [regexp {\$grade} $message match] } {
    #homework
    foreach {type func} {score getScores total getTotals} {
       if { [catch {set all(homework.$type)}]} {
    if { [catch {set setmax [set max $gCapaConfig($num.homework_count)]}]} { 
       set max 99;set setmax 99
    }
    set all(homework.$type) [$func "all" $stunum $section $gFile($num) \
        $max setmax]
   # set all(setmax.homework.$type) $setmax
       }
    }
    #quizzes
    foreach {type func} {score getScores total getTotals} {
       if { [catch {set all(quiz.$type)}]} {
    if { [catch {set setmax [set max $gCapaConfig($num.quiz_count)]}]} { 
       set max 99;set setmax 99
    }
    set all(quiz.$type) [$func "all" $stunum $section  \
    $gCapaConfig($num.quiz_path) $max setmax]
   # set all(setmax.quiz.$type) $setmax
       }
    }
    #exams and final
    if { [catch {set setmax [set max $gCapaConfig($num.final_exam_set_number)]}]} { 
       set max 99;set setmax 99
    }
    set finalset $setmax
    set lastexam [expr $finalset - 1]
    set totalexam 0
    for { set i 1 } { $i <= $lastexam } { incr i } {
       set exams [getScores $i $stunum $section $gCapaConfig($num.exam_path)]
       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 { $corr > $exam } {
    set totalexam [expr $totalexam + \
      [expr $exam + $gCapaConfig($num.correction_weight) \
    * ($corr - $exam)]]
       } else {
    set totalexam [expr $totalexam + $exam]
       }
    }
    set totalexam [expr $totalexam / ($i-1)]
    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))]
    set grade [expr $gCapaConfig($num.homework_weight)*$homework +\
          $gCapaConfig($num.quiz_weight)*$quiz +\
          $gCapaConfig($num.exam_weight)*$totalexam +\
          $gCapaConfig($num.final_weight)*$final]
    set grade [format "%2.1f" [expr $grade * 100 ]]
    regsub -all -- \\\$grade $message $grade message
       }
       return $message
   }
   
   proc emailSendMessage { num student message } {
       global gCT gCapaConfig
       exec echo $message | $gCapaConfig($num.mail_command) [lindex $student 0]
   }
   

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>