diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index cc6ea91d..32878a2c 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -17,6 +17,7 @@ class BidsController < ApplicationController helper :watchers helper :attachments include AttachmentsHelper + include ApplicationHelper helper :projects helper :words def index @@ -723,24 +724,33 @@ class BidsController < ApplicationController if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) # homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id) # homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) - @homework = HomeworkAttach.new - @homework.safe_attributes = params[:homeworkattach] - @homework.bid_id = @bid.id - @homework.user_id = User.current.id - @homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@homework) - if @homework.save - @homework_flag = l(:label_bidding_homework_succeed) + + if hadcommittedhomework(User.current.id, @bid.id) == true + @homework_flag = l(:label_bidding_homework_committed) else - @homework_flag = l(:label_bidding_homework_failed) - end - if @homework.attachments.empty? - @homework.delete - flash[:error] = l(:no_attachmens_allowed) - @homework_flag = l(:no_attachmens_allowed) - # else - end + @homework = HomeworkAttach.new + @homework.safe_attributes = params[:homeworkattach] + @homework.bid_id = @bid.id + @homework.user_id = User.current.id + @homework.save_attachments(params[:attachments]) + + render_attachment_warning_if_needed(@homework) + + if @homework.save + @homework_flag = l(:label_bidding_homework_succeed) + else + @homework_flag = l(:label_bidding_homework_failed) + end + + if @homework.attachments.empty? + @homework.delete + #flash[:error] = l(:no_attachmens_allowed) + @homework_flag = l(:no_attachmens_allowed) + # else + end + end end + @homework_list = @bid.homeworks respond_to do |format| format.html{ diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 97e76a0c..28df9a28 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1489,4 +1489,14 @@ module ApplicationHelper obj2 = obj1 end end + + def hadcommittedhomework(cur,curb) + @attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})") + @attaches.each do |attach| + if attach.user_id == cur + return true + end + end + end + end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 0ba0f355..42186086 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -69,5 +69,14 @@ module AttachmentsHelper def deletable? container, user=User.current User.current.logged? && (container.author == user || user.admin?) end + + def hadcommittedhomework(cur,curb) + @attaches=HomeworkAttach.find_by_sql("select * from homework_attaches where(bid_id = #{curb})") + @attaches.each do |attach| + if attach.user_id == cur + retrun true + end + end + end end diff --git a/app/views/bids/_homework.html.erb b/app/views/bids/_homework.html.erb index 5094d0c0..eb6b9bbf 100644 --- a/app/views/bids/_homework.html.erb +++ b/app/views/bids/_homework.html.erb @@ -9,9 +9,7 @@ <%= render :partial => 'attachments/form' %>
- <%= submit_tag l(:button_create), - :onclick => "return true;" - %> + <%= submit_tag l(:button_create), :onclick => "return true" %> <% end %>