// @Title 课程表视图
// @router /table [get]
func (this *ViewTeatherController) Table() {
	change, _ := this.GetBool("change")
	this.Data["change"] = change
	//	get the term list
	term_list, err := models.GetTermListByTeacherCourse(this.Data["teacher"].(*models.Teacher).Id)
	if err != nil {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	this.Data["term_list"] = models.RankingTerm(term_list)
	var term *models.Term
	xnd := this.GetString("xnd")
	if len(xnd) > 0 {
		xqd, _ := this.GetInt("xqd")
		arr := strings.Split(xnd, "-")
		if len(arr) != 2 {
			this.Redirect("/error", 302)
			this.StopRun()
		}
		startYear, _ := strconv.Atoi(arr[0])
		endYear, _ := strconv.Atoi(arr[1])
		term, err = models.SearchTerm(xqd, startYear, endYear)
		if err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	} else {
		//	get the now term
		term, err = models.GetTermByTimeNow()
		if err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	}
	this.Data["term"] = term
	// get the teacher course
	t_courses, err := models.GetTeacherCourseByTerm(term, this.Data["teacher"].(*models.Teacher).Id)
	if err != nil {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	this.Data["course_color"] = []string{"tb-red", "tb-dark-blue", "tb-grey", "tb-violet", "tb-origin", "tb-blue-green", "tb-blue", "tb-yellow",
		"tb-green", "tb-light-blue", "tb-brown", "tb-pink", "tb-light-green", "tb-dark-blue", "tb-rose-red"}
	this.Data["course_time"] = []string{"08:00-08:40", "08:50-09:30", "09:45-10:25", "10:35-11:15", "11:20-12:00",
		"12:50-13:30", "13:40-14:20", "14:30-15:10", "15:15-15:55", "16:10-16:50", "16:55-17:35", "18:45-19:25",
		"19:30-20:10", "20:15-20:55", "21:05-21:45"}
	this.Data["course_week"] = []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"}
	this.Data["t_courses"] = models.RangeToMapTeacherCourse(t_courses)
	this.Data["now_week"] = this.GetString("week")

	this.Layout = "teacher/base.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["Head_html"] = "teacher/head/table_head.html"
	this.LayoutSections["Scripts"] = "teacher/scripts/table_scripts.html"
	this.TplNames = "teacher/table.html"
}
// @Title 课程作业
// @router /courseHomework [get]
func (this *ViewTeatherController) CourseHomework() {
	//	get teacher course
	if t_course_id, err := this.GetInt64("course"); err == nil {
		if t_course, err := models.GetTeacherCourseById(t_course_id); err == nil {
			//	get teacher course homework list
			if homeworks, err := models.GetTeacherCourseHomeworkByTeacherCourse(t_course); err == nil {
				//	get student homework  by teacher course homework
				for k, _ := range homeworks {
					homeworks[k].StudentHomeworks, _ = models.GetUploadedStudentHomeworkByTeacherCourseHomework(homeworks[k])
				}
				t_course.Homeworks = homeworks
				this.Data["t_course"] = t_course
				//	get the term all teachercourse
				if t_courses, err := models.GetTeacherCourseByTerm(t_course.Term, this.Data["teacher"].(*models.Teacher).Id); err == nil {
					this.Data["t_courses"] = t_courses
				} else {
					this.Redirect("/error", 302)
					this.StopRun()
				}
			} else {
				this.Redirect("/error", 302)
				this.StopRun()
			}
		} else {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	} else {
		this.Redirect("/error", 302)
		this.StopRun()
	}

	//	get all term
	term_list, err := models.GetTermListByTeacherCourse(this.Data["teacher"].(*models.Teacher).Id)
	if err != nil {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	this.Data["term_list"] = models.RankingTerm(term_list)

	//	get week
	if week, _ := this.GetInt("week"); week > 0 {
		this.Data["now_week"] = week
	}

	this.Layout = "teacher/base.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["Head_html"] = "teacher/head/courseHomework_head.html"
	this.LayoutSections["Scripts"] = "teacher/scripts/courseHomework_scripts.html"
	this.TplNames = "teacher/courseHomework.html"
}
// @Title 查看课程点名记录
// @router /courseHistory [get]
func (this *ViewTeatherController) CourseHistory() {
	//	get week
	if week, _ := this.GetInt("week"); week > 0 {
		this.Data["now_week"] = week
	}

	if t_course_id, err := this.GetInt64("course"); err == nil {
		if t_course, err := models.GetTeacherCourseById(t_course_id); err == nil {
			//	get teacher course class and student list
			t_course.Classes, _ = models.GetClassesByTeacherCourse(t_course)
			students, _ := models.GetStudentsByTeacherCourse(t_course)
			week := 1
			if this.Data["now_week"] != nil {
				week = this.Data["now_week"].(int)
			}
			t_course.StudentChecks, _ = models.GetStudentChecksByTeacherCourseAndWeek(t_course, week)
			t_course.Orgs["students"] = students
			t_course.Orgs["s_checks"], _ = models.GetStudentChecksByTeacherCourse(t_course)
			this.Data["t_course"] = t_course
			if t_courses, err := models.GetTeacherCourseByTerm(t_course.Term, this.Data["teacher"].(*models.Teacher).Id); err == nil {
				this.Data["t_courses"] = t_courses
				this.Data["course_week"] = []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"}
			} else {
				this.Redirect("/error", 302)
				this.StopRun()
			}
		} else {
			this.Redirect("/error", 302)
			this.StopRun()
		}
	} else {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	//	get all term
	term_list, err := models.GetTermListByTeacherCourse(this.Data["teacher"].(*models.Teacher).Id)
	if err != nil {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	this.Data["term_list"] = models.RankingTerm(term_list)

	this.Layout = "teacher/base.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["Head_html"] = "teacher/head/courseHistory_head.html"
	this.LayoutSections["Scripts"] = "teacher/scripts/courseHistory_scripts.html"
	this.TplNames = "teacher/courseHistory.html"
}