diff --git a/app/controllers/exams_controller.rb b/app/controllers/exams_controller.rb index f69f7913..b7579fc5 100644 --- a/app/controllers/exams_controller.rb +++ b/app/controllers/exams_controller.rb @@ -142,6 +142,39 @@ def index end end + def destroy + exam_dir = 'public/examfiles/' + @exam = Exam.find(params[:id]) + exam_path = exam_dir+ @exam.filename + File.delete(exam_path) + @exam.destroy + redirect_to :back + + end + + def update_form + @exam = Exam.find_by_id(params[:id]) + end + + def update + exam_dir = 'public/examfiles/' + @exam = Exam.find_by_id(params[:id]) + exam_path = exam_dir+ @exam.filename + exam_file = params[:file_info] + + begin + f = File.open(exam_path, 'wb') + if @exam.valid? and not f.nil? + f.write(exam_file.read) + @exam.save + flash[:notice] = "Exam Reuploaded!" + redirect_to :back + end + ensure + f.close if f + end + end + def department @dept_name, @courses = Exam.get_dept_name_courses_tuples(params[:dept_abbr]) diff --git a/app/views/admin/studrel/index.html.erb b/app/views/admin/studrel/index.html.erb index 6ae47613..1676c81c 100644 --- a/app/views/admin/studrel/index.html.erb +++ b/app/views/admin/studrel/index.html.erb @@ -1,3 +1,10 @@

Studrel Admin

Add a new exam file

<%= button_to "New Exam File", exams_new_path, :method => :get %> +

Delete or Update an exam file

+
+ <%= form_tag(exams_search_path, :method => :get) do %> + <%= text_field_tag :q, params[:controller].eql?('exams') ? h(params[:q]) : '', :placeholder=>"Search Exams", :class=>"text autoclear", :id => "examfiles_q" %> + <%= submit_tag "Search", :name=>nil %> + <%- end -%> +
diff --git a/app/views/exams/course.html.erb b/app/views/exams/course.html.erb index e8f2994d..5ce7af1e 100644 --- a/app/views/exams/course.html.erb +++ b/app/views/exams/course.html.erb @@ -20,9 +20,15 @@ <%- ['mt1', 'mt2', 'mt3', 'f'].each do |short_type| -%> - <%- exam = exams[short_type] -%> - <%- sol = solutions[short_type] -%> + <%- exam = exams[short_type] -%> + <%- sol = solutions[short_type] -%> <%= (link_to "[#{exam.file_type}]", @exam_path+exam.filename) unless exam.nil?%><%= (link_to '[solution]', @exam_path+sol.filename) unless sol.nil? %> + <% if @auth["studrel"] %> + <%= (link_to '[Remove exam]', exams_destroy_path(exam.id) , :method => :delete, :confirm => 'Are you sure?') unless exam.nil?%> + <%= (link_to '[Update exam]', exams_update_form_path(exam.id), :method => :get) unless exam.nil?%> + <%= (link_to '[Remove solution]' , exams_destroy_path(sol.id) , :method => :delete, :confirm => 'Are you sure?') unless sol.nil?%> + <%= (link_to '[Update solution]' , exams_update_form_path(sol.id) , :method => :get) unless sol.nil?%> + <% end %> <%- end -%> diff --git a/app/views/exams/update_form.html.erb b/app/views/exams/update_form.html.erb new file mode 100644 index 00000000..af507c43 --- /dev/null +++ b/app/views/exams/update_form.html.erb @@ -0,0 +1,41 @@ +<% content_for :header do %> + <%= javascript_include_tag "jquery-autocomplete.min" %> + <%= stylesheet_link_tag "jquery-autocomplete" %> + + + + +<% end %> + +<%= form_for @exam, :url => :exams_update , :html => { :multipart => true , :method => :post } do |f| %> + +
+ +
+ <%= file_field_tag :file_info %> +
+ + <%= f.submit "Update Exam File" %> + +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 4f160584..906673ae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -338,6 +338,12 @@ :as => :exams_new post 'create' => "exams#create", :as => :exams_create + delete ':id/destroy' => "exams#destroy", + :as => :exams_destroy + get ':id/update_form' => "exams#update_form", + :as => :exams_update_form + post ':id/update' => "exams#update", + :as => :exams_update end #resources :exams