diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb
index 6066ef3d0..d4050da18 100644
--- a/app/controllers/exercise_controller.rb
+++ b/app/controllers/exercise_controller.rb
@@ -34,17 +34,24 @@ class ExerciseController < ApplicationController
render_403
return
end
- @can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin?
+ exercise_end = Time.parse(format_time(@exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S")
+ if @exercise.time == -1
+ @can_edit_excercise = exercise_end
+ else
+ @can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end) || User.current.admin?
+ end
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
# 学生点击的时候即创建关联,自动保存
#eu = ExerciseUser.create(:user_id => User.current, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
# 已提交问卷的用户不能再访问该界面
+=begin
if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?)
respond_to do |format|
format.html {render :layout => 'base_courses'}
end
else
+=end
if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id)
eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
@@ -55,7 +62,7 @@ class ExerciseController < ApplicationController
respond_to do |format|
format.html {render :layout => 'base_courses'}
end
- end
+ #end
end
def new
@@ -82,7 +89,7 @@ class ExerciseController < ApplicationController
exercise ||= Exercise.new
exercise.exercise_name = params[:exercise][:exercise_name]
exercise.exercise_description = params[:exercise][:exercise_description]
- exercise.end_time = params[:exercise][:end_time]
+ exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
exercise.publish_time = params[:exercise][:publish_time]
exercise.user_id = User.current.id
exercise.time = params[:exercise][:time]
@@ -107,7 +114,7 @@ class ExerciseController < ApplicationController
@exercise.exercise_name = params[:exercise][:exercise_name]
@exercise.exercise_description = params[:exercise][:exercise_description]
@exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time]
- @exercise.end_time = params[:exercise][:end_time]
+ @exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
@exercise.publish_time = params[:exercise][:publish_time]
@exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result]
if @exercise.save
@@ -351,8 +358,8 @@ class ExerciseController < ApplicationController
# 学生提交答卷,选中答案的过程中提交
def commit_answer
eq = ExerciseQuestion.find(params[:exercise_question_id])
- # 已提交过的则不允许答题
- if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?)
+ # 已提交过的且是限时的则不允许答题
+ if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1
render :json => {:text => "failure"}
return
end
diff --git a/app/views/exercise/_commit_alert.html.erb b/app/views/exercise/_commit_alert.html.erb
index d92ca51fb..a21dbd2a7 100644
--- a/app/views/exercise/_commit_alert.html.erb
+++ b/app/views/exercise/_commit_alert.html.erb
@@ -1,7 +1,10 @@
- <% if status == 0 %>
+ <% if status == 0 && exercise.time != -1 %>
提交成功!您的分数是:<%=@score %>分。
<%= link_to "确定", exercise_path(),:class => 'commit'%>
+ <% elsif status == 0 && Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S") %>
+
提交成功!
+ <%= link_to "确定", exercise_index_path(:course_id => @course.id),:class => 'commit'%>
<% elsif status == 1 %>
您还有尚未作答的题目请完成后再提交!
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>
diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb
index 91af83aee..db412672c 100644
--- a/app/views/exercise/_exercise.html.erb
+++ b/app/views/exercise/_exercise.html.erb
@@ -53,7 +53,7 @@
<%#else%>
- <%= link_to exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%>
+ <%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%>
<%#end%>
<% end%>
截止时间:<%= format_time(exercise.end_time.to_s)%>
diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb
index 8de4dac38..e283f8b0c 100644
--- a/app/views/exercise/_exercise_form.html.erb
+++ b/app/views/exercise/_exercise_form.html.erb
@@ -136,14 +136,14 @@
alert("测验标题不能为空");
} else if($.trim($("#exercise_end_time").val()) =="") {
alert("截止时间不能为空");
- } else if(Date.parse($("#exercise_end_time").val()) < Date.now()) {
+ } else if((Date.parse($("#exercise_end_time").val())+(24*60*60-1)*1000) < Date.now()) {
alert("截止时间不能小于当前时间");
} else if($.trim($("#exercise_time").val()) !="" && !/^[1-9][0-9]*$/.test($.trim($("#exercise_time").val()))) {
alert("测验时长必须为非零开头的数字");
} else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_publish_time").val()) < Date.now()) {
alert("发布时间不能小于当前时间");
- } else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_end_time").val()) <= Date.parse($("#exercise_publish_time").val())) {
- alert("截止时间必须大于发布时间");
+ } else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_end_time").val()) < Date.parse($("#exercise_publish_time").val())) {
+ alert("截止时间不能小于发布时间");
} else {
doc.parent().parent().parent().submit();
}
diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb
index 20b8a3d8c..7010407ce 100644
--- a/app/views/exercise/_exercise_student.html.erb
+++ b/app/views/exercise/_exercise_student.html.erb
@@ -3,6 +3,8 @@
$("#RSide").removeAttr("id");
$("#homework_page_right").css("min-height",$("#LSide").height()-30);
$("#Container").css("width","1000px");
+ end_time = <%=exercise.end_time.to_i%>
+ getTime(end_time);
/*start_time = new Date();
start_time.setFullYear(<%#=exercise_user.start_at.year%>);
start_time.setMonth(<%#=exercise_user.start_at.month%>);
@@ -17,11 +19,16 @@
function getTime(end_time) {
//alert(end_time);
now = new Date();
- var total_seconds = (now.getTime() - end_time)/1000;
+ var total_seconds = now.getTime()/1000 - end_time;
+ if (total_seconds < 0) {
+ $("#exercise_submit_btn").click();
+ return;
+ }
+ setTimeout("getTime("+end_time+");", 1000);
//start = new Date(start_time);
//end_time = start_time;
//var total_seconds = total_seconds - 1;
- var hours = total_seconds / 60 / 60;
+ /*var hours = total_seconds / 60 / 60;
var hoursRound = Math.floor(hours);
var minutes = total_seconds /60 - (60 * hoursRound);
var minutesRound = Math.floor(minutes);
@@ -29,9 +36,9 @@
var secondsRound = Math.round(seconds);
$("#rest_hours").html(hoursRound);
$("#rest_minutes").html(minutesRound);
- $("#rest_seconds").html(secondsRound);
+ $("#rest_seconds").html(secondsRound);*/
//if(total_seconds >0) {
- setTimeout("getTime("+end_time+");", 1000);
+ //setTimeout("getTime("+end_time+");", 1000);
//}
}
@@ -41,8 +48,8 @@
<%= exercise.exercise_name%>
<%=exercise_user.start_at %>
- 开始时间:<%=format_time(exercise_user.start_at.to_s)%>
- 截止时间:<%=format_time(exercise.end_time.to_s)%>
+ 开始时间:<%=Time.parse(h(exercise_user.start_at)).strftime("%Y-%m-%d %H:%M:%S")%>
+ 截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S")%>
<% unless exercise.time == -1 %>
测验时长:<%=exercise.time %>分钟
<% end %>
@@ -194,7 +201,7 @@
}
- >
+ >
@@ -202,7 +209,7 @@
<% end %>
- <%= link_to l(:button_submit),commit_exercise_exercise_path(exercise), :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %>
+ <%= link_to l(:button_submit),commit_exercise_exercise_path(exercise),:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %>
diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb
index 8f6ac0e54..3445d6986 100644
--- a/app/views/exercise/_exercise_student_result.html.erb
+++ b/app/views/exercise/_exercise_student_result.html.erb
@@ -10,8 +10,8 @@
<%= exercise.exercise_name%>
-
开始时间:<%=format_time(exercise_user.start_at.to_s) %>
-
截止时间:<%=format_time(exercise.end_time.to_s)%>
+
开始时间:<%=Time.parse(h(exercise_user.start_at)).strftime("%Y-%m-%d %H:%M:%S") %>
+
截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S")%>
<% unless exercise.time == -1 %>
测验时长:<%=exercise.time %>分钟
<% end %>
@@ -34,7 +34,7 @@
<% answer = get_user_answer(exercise_question, User.current)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%>
- <% if answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %>
+ <% if !answer.empty? && !standard_answer.empty? && answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %>
√
<% else %>
×
@@ -73,7 +73,7 @@
<% answer = get_user_answer(exercise_question, User.current)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%>
- <% if get_mulscore(exercise_question, User.current).to_i == standard_answer.first.exercise_choice_id %>
+ <% if !standard_answer.empty? && get_mulscore(exercise_question, User.current).to_i == standard_answer.first.exercise_choice_id %>
√
<% else %>
×
@@ -112,7 +112,7 @@
<% answer = get_user_answer(exercise_question, User.current)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%>
- <% if standard_answer.include?(answer.first.answer_text) %>
+ <% if !answer.empty? && !standard_answer.empty? && standard_answer.include?(answer.first.answer_text) %>
√
<% else %>
×
diff --git a/app/views/exercise/_exercise_teacher.html.erb b/app/views/exercise/_exercise_teacher.html.erb
index 0a96b782b..6e00fc41d 100644
--- a/app/views/exercise/_exercise_teacher.html.erb
+++ b/app/views/exercise/_exercise_teacher.html.erb
@@ -11,9 +11,9 @@
<%= exercise.exercise_name%>
<% unless exercise.publish_time.nil? %>
-
发布时间:<%=format_time(exercise.publish_time.to_s) %>
+
发布时间:<%=Time.parse(h(exercise.publish_time)).strftime("%Y-%m-%d %H:%M:%S") %>
<% end %>
-
截止时间:<%=format_time(exercise.end_time.to_s) %>
+
截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") %>
<% if exercise.time != -1 %>
测验时长:<%=exercise.time %>分钟
<% end %>
diff --git a/app/views/exercise/_show_head.html.erb b/app/views/exercise/_show_head.html.erb
index 16a572583..f385e58b8 100644
--- a/app/views/exercise/_show_head.html.erb
+++ b/app/views/exercise/_show_head.html.erb
@@ -4,9 +4,9 @@
<%= exercise.exercise_name%>
<% unless exercise.publish_time.nil? %>
- 发布时间:<%=Time.parse(format_time(exercise.publish_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.publish_time%>
+ 发布时间:<%=Time.parse(h(exercise.publish_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.publish_time%>
<% end %>
- 截止时间:<%=Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.end_time %>
+ 截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.end_time %>
<% if exercise.time != -1 %>
测验时长:<%= exercise.time %>分钟
<% end %>
diff --git a/app/views/exercise/commit_exercise.js.erb b/app/views/exercise/commit_exercise.js.erb
index 2a40df2a5..5ede8a951 100644
--- a/app/views/exercise/commit_exercise.js.erb
+++ b/app/views/exercise/commit_exercise.js.erb
@@ -1,4 +1,4 @@
-$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert',:locals => {:status => @status}) %>');
+$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert',:locals => {:status => @status,:exercise =>@exercise}) %>');
showModal('ajax-modal', '270px');
$('#ajax-modal').css('height','110px');
$('#ajax-modal').siblings().remove();
diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css
index b7a742994..17ed37e05 100644
--- a/public/stylesheets/courses.css
+++ b/public/stylesheets/courses.css
@@ -1166,4 +1166,5 @@ a:hover.testEdit{ background:url(images/icons.png) -21px -272px no-repeat;}
.questionEditContainer {border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px; margin-top:10px;}
.fillInput {border:1px solid #cbcbcb; padding-left:5px; background-color:#ffffff; width:693px; height:30px; color:#888888;}
.mr130 {margin-right:130px;}
+.mr100 {margin-right:100px;}
.ur_button_submit{ display:block; width:106px; height:31px; margin:0 auto; background:#15bccf; color:#fff; font-size:16px; text-align:center; padding-top:4px; margin-bottom:10px; }
\ No newline at end of file