<link rel="stylesheet" href="<{$xoops_url}>/modules/tadtools/jquery/themes/base/jquery-ui.css">
<script src="<{$xoops_url}>/modules/tadtools/jquery/ui/jquery-ui.js"></script>

  <link rel='stylesheet' type='text/css' href='<{$xoops_url}>/modules/tadtools/css/iconize.css' />
  <script type='text/javascript' src='<{$xoops_url}>/modules/tadtools/fancyBox/lib/jquery.mousewheel-3.0.6.pack.js'></script>
  <script type='text/javascript' language='javascript' src='<{$xoops_url}>/modules/tadtools/fancyBox/source/jquery.fancybox.js?v=2.1.4'></script>
  <link rel='stylesheet' href='<{$xoops_url}>/modules/tadtools/fancyBox/source/jquery.fancybox.css?v=2.1.4' type='text/css' media='screen' />
  <link rel='stylesheet' type='text/css' href='<{$xoops_url}>/modules/tadtools/fancyBox/source/helpers/jquery.fancybox-buttons.css?v=1.0.5' />
  <script type='text/javascript' src='<{$xoops_url}>/modules/tadtools/fancyBox/source/helpers/jquery.fancybox-buttons.js?v=1.0.5'></script>
  <link rel='stylesheet' type='text/css' href='<{$xoops_url}>/modules/tadtools/fancyBox/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7' />
  <script type='text/javascript' src='<{$xoops_url}>/modules/tadtools/fancyBox/source/helpers/jquery.fancybox-thumbs.js?v=1.0.7'></script>
  <script type='text/javascript' src='<{$xoops_url}>/modules/tadtools/fancyBox/source/helpers/jquery.fancybox-media.js?v=1.0.5'></script>

  <script src="../jquery.ya-enter2tab.js"></script>

<style type="text/css">
  .fancybox-nav {
     width: 20%;
   }
   </style>

  <script type='text/javascript'>
    $(document).ready(function(){
      $(".assignment_fancy_<{$assn}>").fancybox({
      <{if  ($data.ifram_show) }>
      openEffect: 'elastic',
      closeEffect: 'elastic',
      autoSize: true,
      'type' : 'iframe' ,
      'beforeClose': function() { window.location.reload() },
      'afterShow': function(){
          $('.fancybox-iframe').contents().find(".score").attr("tabindex",1).focus();
      } ,
      <{/if}>
      fitToView : true,
      width   : '90%',
      height    : '100%',
      padding : '30' ,
      autoSize  : true,
      closeClick  : false,

      });

    });



    function delete_func(asfsn ,stud_id){
      var sure = window.confirm('<{$smarty.const._TAD_DEL_CONFIRM}>');
      if (!sure)  return;
      location.href="score.php?op=delete_tad_assignment_file&assn=<{$assn}>&asfsn=" + asfsn   + "&stud_id=" + stud_id  ;
    }

    //
    function emp_job(assn ,class_id){
      var sure = window.confirm('這項是外部作業，會填入空作業紀錄，方便成績輸入用。');
      if (!sure)  return;
      location.href="score.php?op=emp_job&assn=<{$assn}>&stud_id=" + class_id  ;
    }

  </script>
    <{if ($exam_list) }>
<h2>主題</h2>

<div class="row">
  <select onChange="window.location.href='score.php?assn='+this.value" class="col-md-6">
    <option value=''><{$smarty.const._MD_TADASSIGN_SELECT_ASSN}></option>

    <{foreach from=$exam_list  item=exam_list}>
        <option value='<{$exam_list.assn}>' <{if $assn==$exam_list.assn}>selected<{/if}>> <{$class_list_c[$exam_list.class_id]}>  -- <{$exam_list.title}> (<{$exam_list.uid_name}>) </option>
      <{/foreach}>

  </select>

</div>
    <{ /if  }>

<{if ($assn) }>
  <div class="row">
    <div class="col-md-5"><h3><{$class_list_c[$data.exam.class_id]}>   <{$data.exam.title}></h3></div>
    <div class="col-md-4">

    <{if  ( ($data.exam.upload_mode==0) and ($data.count_exams ==0) )}>
    <a href="javascript:emp_job(<{$assn}>,<{$data.exam.class_id}>);"  class="btn btn-danger"   title='書面(外部)作品，不上傳不展示，僅在此輸入成績使用。'>外部作品</a>
    <{/if}>
    <a class="btn btn-mono btn-success" href="export_score.php?op=class&class=<{$data.exam.class_id}>">本班學期成績</a>
    <a class="btn btn-mono btn-success" href="export_score.php?op=all">全部學期成績</a>
    </div>
    <div class="col-md-2 text-right">
      <button class="btn btn-warning" type="button" onClick="window.location.reload()" title='重新載入畫面'>重整</button>
       <{if    ($data.exam.upload_mode )  }>
      <a href="../index.php?assn=<{$assn}>" class="btn btn-primary"><{$smarty.const._MD_SAVE}></a>
      <{/if}>
    </div>
    <div class="col-md-10"><{$data.exam.note}></div>
  </div>

  <table class="table table-striped table-bordered table-hover" id="tscore">
  <tr>
  <th><{$smarty.const._MD_TADASSIGN_UP_TIME}></th>
  <th><{$smarty.const._MD_TADASSIGN_FILENAME}></th>
  <th><{$smarty.const._MD_TADASSIGN_AUTHOR}></th>
  <th>評語</th>
  <th>評分(啟始分<{$base_score}>，未交<{$score_lost}>)</th>
  <th><{$smarty.const._TAD_FUNCTION}></th>
  </tr>
  <tbody>
  <{if ($data.stud) }>
  <{assign var="ti" value="100"}>
  <{foreach from=$data.stud  item=all}>
    <tr>
      <td><{$all.up_time}></td>
      <td>
        <!--      bmp gif jpg jpeg png sb sb2 flash          -->
        <{if  ($data.ifram_show) }>

       <a href="show_file.php?assn=<{$all.assn}>&stud_id=<{$all.stud_id}>&asfsn=<{$all.asfsn}>&sub_name=<{$all.sub_name}>&score_bar=<{$all.score_bar}>&gv=1"  studfile='<{$smarty.const._TAD_ASSIGNMENT_UPLOAD_URL}><{$all.assn}>/<{$all.asfsn}>.<{$all.sub_name}>'  class="assignment_fancy_<{$assn}>" rel="group" title="<{$all.sit_id}>.<{$all.author}> (<{$all.up_time}>) <{$all.file_name}>"  target="show"><{$all.file_name}></a>
       <{else}>
       <a href="<{$smarty.const._TAD_ASSIGNMENT_UPLOAD_URL}><{$all.assn}>/<{$all.asfsn}>.<{$all.sub_name}>"  studfile='<{$smarty.const._TAD_ASSIGNMENT_UPLOAD_URL}><{$all.assn}>/<{$all.asfsn}>.<{$all.sub_name}>'  class="assignment_fancy_<{$assn}>" rel="group" title="<{$all.sit_id}>.<{$all.author}> (<{$all.up_time}>) <{$all.file_name}>"  target="show"><{$all.file_name}></a>
       <{/if}>
     	<div><{  $all.memo}></div>
      </td>

      <td><span class="badge badge-info"><{$all.sit_id}></span> <{$all.author}></td>
      <td><input class="form-control comment" type="text" onfocus="this.select()"   name="comment[<{$all.asfsn}>]"  id="comment_<{$all.asfsn}>"  data_ref="<{$all.asfsn}>" value="<{$all.comment}>" ></input>

      </td>
      <td>
      	<{*----     拉bar            ---- *}>
        <div claa="row">
        <div class="col-md-6">
            <div id="slider_<{$all.asfsn}>"  class="slider" data_ref="<{$all.asfsn}>" title="拉動指定成績，左右鍵微調"  style="background: #CCC" ></div>
 	        <script>$( "#slider_<{$all.asfsn}>" ).slider({value: <{$all.score_bar}>, min: 0,max: <{$bar_max}>}) ;
            </script>
        </div>
        <div class="col-md-3">
      		<input class="form-control score" type="text" onfocus="this.select()"   name="score[<{$all.asfsn}>]"  id="score_<{$all.asfsn}>"  data_ref="<{$all.asfsn}>"
      		<{if ($all.score)}> value="<{$all.score}>" <{/if}> tabindex="<{$ti++}>" title="整數成績,Enter 跳下一位">
             <i  class="icon-warning-sign" id="info_<{$all.asfsn}>" title='分數低於基本分' <{if ( ($all.score >= $base_score) or (!$all.score) )}>  style="display:none"  <{/if}>></i>
        </div>
    </div>
      	</td>
      <td>
        <a href="javascript:delete_func(<{$all.asfsn}>,<{$all.stud_id}>);" class="btn btn-mini btn-danger"><{$smarty.const._TAD_DEL}></a>
      </td>

    </tr>
  <{/foreach}>
  <{/if}>
  </tbody>
  </table>
  <div class="row">
  <h4>未上傳作業列表</h4>
  <{foreach from=$class_students  key=sit item=stud}>
  <{if (!$stud.in)  }>
 	<span class="col-md-2"><span class="badge badge-info"><{ $sit }></span> <{ $stud.name }>  </span>
  <{/if}>
   <{/foreach}>
</div>

<script type='text/javascript'>

    //enter 2 tab  在 #tscore 內
    $("#tscore").enableEnterToTab({ captureTabKey: true });

  //分數拉條
  $(function() {
		$( ".slider" ).slider({
 			slide: function( event, ui ) {
 				var v_id= $(this).attr('data_ref')
				$( "#score_"+v_id ).val(  parseInt("<{$base_score}>", 10) + ui.value );
			}});

	});

 //離開才做動作寫入成績
  $(function() {
		$( ".slider" ).focusout(function(){

			var get_score =parseInt("<{$base_score}>", 10) +$(this).slider( "value" ) ;
			var v_id= $(this).attr('data_ref') ;

 			save_score('score', v_id ,  get_score    ) ;
			//alert(v_id +  get_score  );
		})		;

	});

//成績直接修改
$(function() {

	$(".score").change(function(){
		var v_id = $( this ).attr('data_ref') ;
              var get_score = $( this ).val();
              get_score = get_score.trim() ;
              $("#info_"+v_id).hide() ;
              if (get_score ) {
                  //>100 <0 歸0
                  if (  (get_score > 100) | (get_score<0)  | (! isInteger(get_score) ) ) {
                      alert (  '輸入分數有問題！') ;
                      $(this).val(0) ;
                      $(this).focus() ;
                      get_score= 0 ;
                      $("#info_"+v_id).show() ;
                  }else  {
                    // < 最低份，警告
                    if (  (get_score < parseInt("<{$base_score}>", 10) )  ) {
                        alert (  '輸入分數低於預設最低分：' + '<{$base_score}>' ) ;
                        $("#info_"+v_id).show() ;
                    }
                  }
              }
              save_score( 'score' ,v_id ,  get_score ) ;
	});
});

function isInteger(value) {
    return (value == parseInt(value));
}


//評語直接修改
$(function() {
	$(".comment").change(function(){
		var v_id = $( this ).attr('data_ref') ;
		var get_score = $( this ).val();
 		save_score( 'comment' ,v_id ,  get_score ) ;
	});
});

 //寫入成績、評語
 function save_score(do_mode ,tid , sdata )  {
  	$.ajax({
 		url: 'ajax_score_exam_data.php',
 		type: 'GET',
 		data: {do: do_mode , id:tid  , setdata :sdata    },
 	})
 	.done(function(data) {
 		console.log("success");
 		//alert(data) ;
 	})
 	.fail(function() {
 		console.log("error");

 	})
 	.always(function() {
 		console.log("complete");
 	});
  }


  </script>﻿


<{/if}>
