diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb
index 17c98e3b1..593d6bf53 100644
--- a/app/controllers/student_work_controller.rb
+++ b/app/controllers/student_work_controller.rb
@@ -42,9 +42,6 @@ class StudentWorkController < ApplicationController
 
         end
       end
-
-   
-
     
     render :json => resultObj
   end
@@ -165,24 +162,23 @@ class StudentWorkController < ApplicationController
 
   def create
     if params[:student_work]
-      stundet_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
-      stundet_work ||= StudentWork.new
-      stundet_work.name = params[:student_work][:name]
-      stundet_work.description = params[:student_work][:description]
-      stundet_work.project_id = params[:student_work][:project_id]
-      stundet_work.homework_common_id = @homework.id
-      stundet_work.user_id = User.current.id
-      stundet_work.save_attachments(params[:attachments])
+      student_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
+      student_work ||= StudentWork.new
+      student_work.name = params[:student_work][:name]
+      student_work.description = params[:student_work][:description]
+      student_work.project_id = params[:student_work][:project_id]
+      student_work.homework_common_id = @homework.id
+      student_work.user_id = User.current.id
+      student_work.save_attachments(params[:attachments])
       if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
-        stundet_work.late_penalty = @homework.late_penalty
+        student_work.late_penalty = @homework.late_penalty
         else
-        stundet_work.late_penalty = 0
+        student_work.late_penalty = 0
       end
-      render_attachment_warning_if_needed(stundet_work)
-      if stundet_work.save
-        if @homework.homework_type == 2 && @homework.homework_detail_programing       #编程作业,学生提交作品后计算系统得分
-         
-        end
+      render_attachment_warning_if_needed(student_work)
+
+      if student_work.save
+
         respond_to do |format|
           format.html {
             flash[:notice] = l(:notice_successful_create)
@@ -624,7 +620,7 @@ class StudentWorkController < ApplicationController
   end
 
   def find_or_save_student_work(is_test)
-    student_work = @homework.student_works.where(user_id: User.current.id).first
+    student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
     if student_work.nil?
       @homework.student_works.build(
         name: params[:title],
@@ -633,6 +629,7 @@ class StudentWorkController < ApplicationController
         is_test: is_test
         )
       unless @homework.save
+        logger.debug @homework.errors.full_messages
       else
         student_work = @homework.student_works.where(user_id: User.current.id).first
       end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 9c6492448..9b2d49f2d 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -300,6 +300,7 @@ class UsersController < ApplicationController
       @page = params[:page] ? params[:page].to_i + 1 : 0
       user_course_ids =  @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")"
       @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10)
+      @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)
       respond_to do |format|
         format.js
         format.html {render :layout => 'new_base_user'}
@@ -367,8 +368,15 @@ class UsersController < ApplicationController
   end
 
   def user_commit_homework
-    flash[:notice] = l(:notice_successful_create)
-    redirect_to student_work_index_url(:homework => params[:homework])
+    homework = HomeworkCommon.find(params[:homework])
+    student_work = homework.student_works.where(user_id: User.current.id).first
+    if student_work
+      student_work.save
+      flash[:notice] = l(:notice_successful_create)
+      redirect_to student_work_index_url(:homework => params[:homework])
+    else 
+      render_403
+    end
   end
 
   def user_new_homework
diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb
index b51de6c2c..0bff38558 100644
--- a/app/models/homework_common.rb
+++ b/app/models/homework_common.rb
@@ -56,6 +56,10 @@ class HomeworkCommon < ActiveRecord::Base
     Mailer.run.homework_added(self)
   end
 
+  def is_program_homework?
+    self.homework_type == 2 && self.homework_detail_programing
+  end
+
   delegate :language_name, :to => :homework_detail_programing
 
 end
diff --git a/app/models/student_work.rb b/app/models/student_work.rb
index d7287dcc4..0a5c1b65c 100644
--- a/app/models/student_work.rb
+++ b/app/models/student_work.rb
@@ -10,10 +10,32 @@ class StudentWork < ActiveRecord::Base
   has_many :student_work_tests, order: 'id desc'
 
   before_destroy :delete_praise
+  before_save :set_program_score, :set_src
 
   acts_as_attachable
 
   def delete_praise
     PraiseTread.where("praise_tread_object_id = #{self.id} AND praise_tread_object_type = 'StudentWork'").destroy_all
   end
+
+  def last_test
+    student_work_tests.order('id desc').first
+  end
+
+  private 
+  def set_program_score
+    if homework_common.is_program_homework?       #编程作业,学生提交作品后计算系统得分
+        #根据最后一次测试计算得分
+        unless last_test
+          self.system_score = 0
+        else
+          self.system_score = last_test.test_score
+        end
+    end
+
+  end
+  def set_src
+    self.description = last_test.src if last_test
+  end
+
 end
diff --git a/app/models/student_work_test.rb b/app/models/student_work_test.rb
index 96aa1d6c3..1cfb7f8b2 100644
--- a/app/models/student_work_test.rb
+++ b/app/models/student_work_test.rb
@@ -34,10 +34,19 @@ class StudentWorkTest < ActiveRecord::Base
 
   def test_score
     if self.status.to_i == 0
-      format("%.1f",100.0 / self.student_work.homework_common.homework_tests.count)
-    else
+      100
+    elsif self.results.empty?
       0
+    else 
+      get_success_count * 100 / self.results.count
     end
   end
 
+  private
+  def get_success_count
+    self.results.inject(0) do |sum, result|
+      sum += (result["status"].to_i == 0 ? 1 : 0)
+    end || 0
+  end
+
 end
diff --git a/app/views/users/_user_homework_form.html.erb b/app/views/users/_user_homework_form.html.erb
index 72ace3ba5..4af5742a9 100644
--- a/app/views/users/_user_homework_form.html.erb
+++ b/app/views/users/_user_homework_form.html.erb
@@ -45,7 +45,7 @@
 
 
     <div class="mt5">
-      <a href="javascript:void(0);" class="BlueCirBtnMini fr" onclick=" submit_comm_homework('new_homework_common');">发送</a>
+      <a href="javascript:void(0);" class="BlueCirBtnMini fr" onclick="submit_homework('new_homework_common');">发送</a>
       <span class="fr mr10 mt3">或</span>
       <a href="javascript:void(0);" class=" fr mr10 mt3" onclick="reset_homework();">取消</a>
       <div class="cl"></div>
@@ -89,7 +89,7 @@
                   </select>
             </div>
             <div class="mt10">
-              <textarea class="InputBox  W320 fl mr10" placeholder="测试输入"></textarea><textarea class="InputBox  W320  fl mr5" placeholder="测试输出"></textarea>
+              <textarea class="InputBox  W320 fl mr10" placeholder="测试输入" id="textarea_input_test"></textarea><textarea class="InputBox  W320  fl mr5" placeholder="测试输出"></textarea>
               <a href="javascript:void(0);" class=" fl icon_add" title="增加测试组"></a>
                 <div class="cl"></div>
             </div>
diff --git a/app/views/users/_user_homework_list.html.erb b/app/views/users/_user_homework_list.html.erb
index 1a24b1499..642373d58 100644
--- a/app/views/users/_user_homework_list.html.erb
+++ b/app/views/users/_user_homework_list.html.erb
@@ -35,8 +35,8 @@
             <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => homework_common.attachments} %>
             <div class="cl"></div>
           </div>
-          <%# if is_teacher%>
-          <% if false%>
+          <% if is_teacher%>
+          <%# if false%>
               <div class="homepagePostSetting">
                 <ul>
                   <li class="homepagePostSettingIcon">
diff --git a/app/views/users/user_homeworks.html.erb b/app/views/users/user_homeworks.html.erb
index e925ccd6b..b3aaf5ece 100644
--- a/app/views/users/user_homeworks.html.erb
+++ b/app/views/users/user_homeworks.html.erb
@@ -17,7 +17,7 @@
 </div>
 <div class="cl"></div>
 
-<% if User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)%>
+<% if @is_teacher%>
     <!-- 老师身份才可以发布作业 -->
     <div class="HomeWork mb10">
       <% homework = HomeworkCommon.new %>
diff --git a/public/images/homepage_icon2.png b/public/images/homepage_icon2.png
index 6cbde8f62..d39624a2e 100644
Binary files a/public/images/homepage_icon2.png and b/public/images/homepage_icon2.png differ
diff --git a/public/javascripts/homework.js b/public/javascripts/homework.js
index bebb8a973..c136029bf 100644
--- a/public/javascripts/homework.js
+++ b/public/javascripts/homework.js
@@ -99,30 +99,7 @@ $(function(){
     $('#program-src').focus(function(){
         $(this).css('height', '100px');
     });
-    var isProgramHomework = function(){
-        return !$(".advanced_option").is(":hidden");
-    }
-
-    var submit_comm_homework = function(id){
-        var valid = true;
-        if (isProgramHomework()) {
-            $.each($('.advanced_option textarea.InputBox'), function(i, val){
-                if ($(val).val().length<=0) {
-                    $(val).focus();
-                    valid = false;
-                    return false;
-                }
-            });
-            if (valid) {
-                $('input[name=homework_type]').val(2);
-            };
-        }
-        if (valid) {
-            submit_homework(id);    
-        }
-    }
-    window.submit_comm_homework = submit_comm_homework;
-
+    
     var datepickerOptions={dateFormat:'yy-mm-dd',firstDay:0,showWeek:true,showOtherMonths:true,selectOtherMonths:true};
 
     $('input.date-input').datepicker(datepickerOptions);
@@ -143,6 +120,7 @@ $(function(){
         $("a.CloseBtn").on('click', function(){
             $("#BluePopupBox" ).dialog("close");
         });
+        $('#textarea_input_test').focus();
 
         $("#BluePopupBox a.BlueCirBtn").on('click', function(){
             var test_numbers = 0;
@@ -180,8 +158,7 @@ $(function(){
                 var html=bt('t:program-input-list',data);
                 $("input[name=homework_type]").after(html);
                 $("#BluePopupBox" ).dialog( "close" );    
-            };
-
+            }
         });
     });
 
diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css
index 6817907c0..df6d4d632 100644
--- a/public/stylesheets/new_user.css
+++ b/public/stylesheets/new_user.css
@@ -499,8 +499,8 @@ a.coursesLineGrey:hover {color:#ffffff;}
 .homepageLeftMenuMore {height:18px;}
 .homepageLeftMenuMore:hover {background-color:#269ac9;}
 .homepageLeftMenuMoreIcon {background:url(../images/homepage_icon.png) -74px -240px no-repeat; display:block; height:18px;}
-.homepageMenuSetting {display:inline-block; background:url(../images/homepage_icon.png) -190px -365px no-repeat; width:15px; height:15px; margin-top: 16px; margin-right: 15px;}
-.homepageMenuSetting:hover {background:url(../images/homepage_icon.png) -190px -407px no-repeat;}
+.homepageMenuSetting {display:inline-block; background:url(../images/homepage_icon2.png) -190px -365px no-repeat; width:15px; height:15px; margin-top: 16px; margin-right: 15px;}
+.homepageMenuSetting:hover {background:url(../images/homepage_icon2.png) -190px -407px no-repeat;}
 a.homepageMenuText {color:#484848; font-size:16px; margin-left:20px;}
 .homepageLeftLabelContainer {width:238px; border:1px solid #dddddd; background-color:#ffffff; margin-top:10px;}
 .homepageLabelText {color:#484848; font-size:16px; margin-left:10px; margin-bottom:12px; display:block;}
@@ -905,8 +905,8 @@ a:hover.icon_remove{background:url(../images/course/icons.png) -20px -338px no-r
 .T_C{ text-align:center;}
 .SearchIcon{background:url(../images/homepage_icon.png) 676px -393px no-repeat; }
 .SearchIcon:hover{background:url(../images/homepage_icon.png) 676px -419px no-repeat; }
-a.link_file{ background:url(../images/course/pic_file.png) 0 2px no-repeat; padding-left:20px; }
-a:hover.link_file{ background:url(../images/course/pic_file.png) 0 -25px no-repeat; color:#3ca5c6;}
+a.link_file{ background:url(../images/pic_file.png) 0 2px no-repeat; padding-left:20px; }
+a:hover.link_file{ background:url(../images/pic_file.png) 0 -25px no-repeat; color:#3ca5c6;}
 a.FilesName{ max-width:540px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis; display:block;}
 a.FilesName02{ max-width:665px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis; display:block;}
 .ProResultUl span { display:block; float:left;}